Changeset 1873


Ignore:
Timestamp:
Mar 6, 2007, 3:07:15 AM (17 years ago)
Author:
rvelices
Message:

permalinks: admin fix on some tricky cases when setting a new permalinks.inc.php
permalinks: added ability to sort the permalink tables in the admin
added new action in category_cats.inc.php

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions_permalinks.php

    r1866 r1873  
    103103  $sanitized_permalink = preg_replace( '#[^a-zA-Z0-9_-]#', '' ,$permalink);
    104104  if ( $sanitized_permalink != $permalink
    105       or preg_match( '#^(\d)+-?#', $permalink) )
     105      or preg_match( '#^(\d)+(-.*)?$#', $permalink) )
    106106  {
    107107    $page['errors'][] = l10n('Permalink_name_rule');
     
    109109  }
    110110 
     111  // check if the new permalink is actively used
    111112  $existing_cat_id = get_cat_id_from_permalink( $permalink );
    112113  if ( isset($existing_cat_id) )
     
    127128  }
    128129
    129   if ($save)
     130  // check if the new permalink was historically used
     131  $old_cat_id = get_cat_id_from_old_permalink($permalink, false);
     132  if ( isset($old_cat_id) and $old_cat_id!=$cat_id )
    130133  {
    131     $old_cat_id = get_cat_id_from_old_permalink($permalink, false);
    132     if ( isset($old_cat_id) )
    133     {
    134       if ( $old_cat_id!=$cat_id )
    135       {
    136         $page['errors'][] =
    137           sprintf(
    138             l10n('Permalink_%s_histo_used_by_%s'),
    139             $permalink, $old_cat_id
    140           );
    141         return false;
    142       }
    143       else
    144       {
    145         $query = '
    146 DELETE FROM '.OLD_PERMALINKS_TABLE.'
    147   WHERE cat_id='.$cat_id.' AND permalink="'.$permalink.'"';
    148         pwg_query($query);
    149       }
    150     }
     134    $page['errors'][] =
     135      sprintf(
     136        l10n('Permalink_%s_histo_used_by_%s'),
     137        $permalink, $old_cat_id
     138      );
     139    return false;
    151140  }
    152  
     141
    153142  if ( !delete_cat_permalink($cat_id, $save ) )
    154143  {
     
    156145  }
    157146
     147  if ( isset($old_cat_id) )
     148  {// the new permalink must not be active and old at the same time
     149    assert( $old_cat_id==$cat_id );
     150    $query = '
     151DELETE FROM '.OLD_PERMALINKS_TABLE.'
     152  WHERE cat_id='.$old_cat_id.' AND permalink="'.$permalink.'"';
     153    pwg_query($query);
     154  }
     155 
    158156  $query = '
    159157UPDATE '.CATEGORIES_TABLE.'
  • trunk/admin/permalinks.php

    r1866 r1873  
    2323// | USA.                                                                  |
    2424// +-----------------------------------------------------------------------+
     25
     26function parse_sort_variables(
     27    $sortable_by, $default_field,
     28    $get_param, $get_rejects,
     29    $template_var )
     30{
     31  global $template;
     32 
     33  $url_components = parse_url( $_SERVER['REQUEST_URI'] );
     34
     35  $base_url = $url_components['path'];
     36 
     37  parse_str($url_components['query'], $vars);
     38  $is_first = true;
     39  foreach ($vars as $key => $value)
     40  {
     41    if (!in_array($key, $get_rejects) and $key!=$get_param)
     42    {
     43      $base_url .= $is_first ? '?' : '&';
     44      $is_first = false;
     45      $base_url .= $key.'='.urlencode($value);
     46    }
     47  }
     48
     49  $ret = array();
     50  foreach( $sortable_by as $field)
     51  {
     52    $url = $base_url;
     53    if ( $field !== @$_GET[$get_param] )
     54    {
     55      if ( !isset($default_field) or $default_field!=$field )
     56      { // the first should be the default
     57        $url = add_url_params($url, array($get_param=>$field) );
     58      }
     59      $disp = '⇓'; // TODO: an small image is better
     60    }
     61    else
     62    {
     63      array_push($ret, $field);
     64      $disp = '<em>&dArr;</em>'; // TODO: an small image is better
     65    }
     66    if ( isset($template_var) )
     67    {
     68      $template->assign_var( $template_var.strtoupper($field),
     69            '<a href="'.$url.'" title="'.l10n('Sort order').'">'.$disp.'</a>'
     70         );
     71    }
     72  }
     73  return $ret;
     74}
    2575
    2676if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     
    4999}
    50100
     101
    51102$template->set_filename('permalinks', 'admin/permalinks.tpl' );
    52103
     
    60111display_select_cat_wrapper( $query, $selected_cat, 'categories', false );
    61112
     113
     114// --- generate display of active permalinks -----------------------------------
     115$sort_by = parse_sort_variables(
     116    array('id', 'name', 'permalink'), 'name',
     117    'psf',
     118    array('delete_permanent'),
     119    'SORT_' );
     120
    62121$query = '
    63 SELECT id, name, permalink
     122SELECT id, permalink, uppercats, global_rank
    64123  FROM '.CATEGORIES_TABLE.'
    65   WHERE permalink IS NOT NULL';
     124  WHERE permalink IS NOT NULL
     125';
     126if ( count($sort_by) and
     127      ($sort_by[0]=='id' or $sort_by[0]=='permalink')
     128    )
     129{
     130  $query .= ' ORDER BY '.$sort_by[0];
     131}
     132$categories=array();
    66133$result=pwg_query($query);
    67134while ( $row=mysql_fetch_assoc($result) )
    68135{
    69   $display_name = get_cat_display_name( array($row) );
    70   $template->assign_block_vars( 'permalink',
    71     array(
    72       'CAT_ID' => $row['id'],
    73       'CAT' => $display_name,
    74       'PERMALINK' => $row['permalink'],
    75     )
    76     );
     136  $row['name'] = get_cat_display_name_cache( $row['uppercats'] );
     137  $categories[] = $row;
    77138}
    78139
     140if ( !count($sort_by) or $sort_by[0]='name')
     141{
     142  usort($categories, 'global_rank_compare');
     143}
     144foreach ($categories as $cat)
     145{
     146  $template->assign_block_vars( 'permalink', $cat );
     147}
     148
     149
     150// --- generate display of old permalinks --------------------------------------
     151
     152$sort_by = parse_sort_variables(
     153    array('cat_id','permalink','date_deleted','last_hit','hit'), null,
     154    'dpsf',
     155    array('delete_permanent'),
     156    'SORT_OLD_' );
     157
    79158$url_del_base = get_root_url().'admin.php?page=permalinks';
    80 
    81159$query = 'SELECT * FROM '.OLD_PERMALINKS_TABLE;
     160if ( count($sort_by) )
     161{
     162  $query .= ' ORDER BY '.$sort_by[0];
     163}
    82164$result = pwg_query($query);
    83165while ( $row=mysql_fetch_assoc($result) )
    84166{
    85   $row['display_name'] = get_cat_display_name_cache($row['cat_id']);
     167  $row['name'] = get_cat_display_name_cache($row['cat_id']);
    86168  $row['U_DELETE'] =
    87169      add_url_params(
  • trunk/include/category_cats.inc.php

    r1869 r1873  
    178178    update_cats_with_filtered_data($categories);
    179179  }
    180 
     180  trigger_action('loc_begin_index_categories');
    181181  if ($conf['subcatify'])
    182182  {
  • trunk/template/yoga/admin/permalinks.tpl

    r1866 r1873  
    66</div>
    77
    8 <form method="post">
     8<form method="post" action="{F_ACTION}">
    99<fieldset><legend>{lang:Add/delete a permalink}</legend>
    1010  <label>Category:
     
    3434<table class="table2">
    3535  <tr class="throw">
    36     <td>Id</td>
    37     <td>{lang:Category}</td>
    38     <td>{lang:Permalink}</td>
     36    <td>Id {SORT_ID}</td>
     37    <td>{lang:Category} {SORT_NAME}</td>
     38    <td>{lang:Permalink} {SORT_PERMALINK}</td>
    3939  </tr>
    4040<!-- BEGIN permalink -->
    4141  <tr>
    42     <td>{permalink.CAT_ID}</td>
    43     <td>{permalink.CAT}</td>
    44     <td>{permalink.PERMALINK}</td>
     42    <td>{permalink.id}</td>
     43    <td>{permalink.name}</td>
     44    <td>{permalink.permalink}</td>
    4545  </tr>
    4646<!-- END permalink -->
     
    5050<table class="table2">
    5151  <tr class="throw">
    52     <td>Id</td>
     52    <td>Id {SORT_OLD_CAT_ID}</td>
    5353    <td>{lang:Category}</td>
    54     <td>{lang:Permalink}</td>
    55     <td>Deleted on</td>
    56     <td>Last hit</td>
    57     <td>Hit</td>
     54    <td>{lang:Permalink} {SORT_OLD_PERMALINK}</td>
     55    <td>Deleted on {SORT_OLD_DATE_DELETED}</td>
     56    <td>Last hit {SORT_OLD_LAST_HIT}</td>
     57    <td>Hit {SORT_OLD_HIT}</td>
    5858    <td></td>
    5959  </tr>
     
    6161  <tr>
    6262    <td>{deleted_permalink.cat_id}</td>
    63     <td>{deleted_permalink.display_name}</td>
     63    <td>{deleted_permalink.name}</td>
    6464    <td>{deleted_permalink.permalink}</td>
    6565    <td>{deleted_permalink.date_deleted}</td>
Note: See TracChangeset for help on using the changeset viewer.