aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--admin/include/functions_permalinks.php44
-rw-r--r--admin/permalinks.php106
-rw-r--r--include/category_cats.inc.php2
-rw-r--r--template/yoga/admin/permalinks.tpl26
4 files changed, 129 insertions, 49 deletions
diff --git a/admin/include/functions_permalinks.php b/admin/include/functions_permalinks.php
index 9a36ccf3d..1f10b4379 100644
--- a/admin/include/functions_permalinks.php
+++ b/admin/include/functions_permalinks.php
@@ -102,12 +102,13 @@ function set_cat_permalink( $cat_id, $permalink, $save )
$sanitized_permalink = preg_replace( '#[^a-zA-Z0-9_-]#', '' ,$permalink);
if ( $sanitized_permalink != $permalink
- or preg_match( '#^(\d)+-?#', $permalink) )
+ or preg_match( '#^(\d)+(-.*)?$#', $permalink) )
{
$page['errors'][] = l10n('Permalink_name_rule');
return false;
}
+ // check if the new permalink is actively used
$existing_cat_id = get_cat_id_from_permalink( $permalink );
if ( isset($existing_cat_id) )
{
@@ -126,35 +127,32 @@ function set_cat_permalink( $cat_id, $permalink, $save )
}
}
- if ($save)
+ // check if the new permalink was historically used
+ $old_cat_id = get_cat_id_from_old_permalink($permalink, false);
+ if ( isset($old_cat_id) and $old_cat_id!=$cat_id )
{
- $old_cat_id = get_cat_id_from_old_permalink($permalink, false);
- if ( isset($old_cat_id) )
- {
- if ( $old_cat_id!=$cat_id )
- {
- $page['errors'][] =
- sprintf(
- l10n('Permalink_%s_histo_used_by_%s'),
- $permalink, $old_cat_id
- );
- return false;
- }
- else
- {
- $query = '
-DELETE FROM '.OLD_PERMALINKS_TABLE.'
- WHERE cat_id='.$cat_id.' AND permalink="'.$permalink.'"';
- pwg_query($query);
- }
- }
+ $page['errors'][] =
+ sprintf(
+ l10n('Permalink_%s_histo_used_by_%s'),
+ $permalink, $old_cat_id
+ );
+ return false;
}
-
+
if ( !delete_cat_permalink($cat_id, $save ) )
{
return false;
}
+ if ( isset($old_cat_id) )
+ {// the new permalink must not be active and old at the same time
+ assert( $old_cat_id==$cat_id );
+ $query = '
+DELETE FROM '.OLD_PERMALINKS_TABLE.'
+ WHERE cat_id='.$old_cat_id.' AND permalink="'.$permalink.'"';
+ pwg_query($query);
+ }
+
$query = '
UPDATE '.CATEGORIES_TABLE.'
SET permalink="'.$permalink.'"
diff --git a/admin/permalinks.php b/admin/permalinks.php
index d00770dd9..d5aa99463 100644
--- a/admin/permalinks.php
+++ b/admin/permalinks.php
@@ -23,6 +23,56 @@
// | USA. |
// +-----------------------------------------------------------------------+
+function parse_sort_variables(
+ $sortable_by, $default_field,
+ $get_param, $get_rejects,
+ $template_var )
+{
+ global $template;
+
+ $url_components = parse_url( $_SERVER['REQUEST_URI'] );
+
+ $base_url = $url_components['path'];
+
+ parse_str($url_components['query'], $vars);
+ $is_first = true;
+ foreach ($vars as $key => $value)
+ {
+ if (!in_array($key, $get_rejects) and $key!=$get_param)
+ {
+ $base_url .= $is_first ? '?' : '&';
+ $is_first = false;
+ $base_url .= $key.'='.urlencode($value);
+ }
+ }
+
+ $ret = array();
+ foreach( $sortable_by as $field)
+ {
+ $url = $base_url;
+ if ( $field !== @$_GET[$get_param] )
+ {
+ if ( !isset($default_field) or $default_field!=$field )
+ { // the first should be the default
+ $url = add_url_params($url, array($get_param=>$field) );
+ }
+ $disp = '⇓'; // TODO: an small image is better
+ }
+ else
+ {
+ array_push($ret, $field);
+ $disp = '<em>&dArr;</em>'; // TODO: an small image is better
+ }
+ if ( isset($template_var) )
+ {
+ $template->assign_var( $template_var.strtoupper($field),
+ '<a href="'.$url.'" title="'.l10n('Sort order').'">'.$disp.'</a>'
+ );
+ }
+ }
+ return $ret;
+}
+
if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
include_once(PHPWG_ROOT_PATH.'admin/include/functions_permalinks.php');
@@ -48,6 +98,7 @@ DELETE FROM '.OLD_PERMALINKS_TABLE.'
array_push($page['errors'], 'Cannot delete the old permalink !');
}
+
$template->set_filename('permalinks', 'admin/permalinks.tpl' );
$query = '
@@ -59,30 +110,61 @@ FROM '.CATEGORIES_TABLE;
display_select_cat_wrapper( $query, $selected_cat, 'categories', false );
+
+// --- generate display of active permalinks -----------------------------------
+$sort_by = parse_sort_variables(
+ array('id', 'name', 'permalink'), 'name',
+ 'psf',
+ array('delete_permanent'),
+ 'SORT_' );
+
$query = '
-SELECT id, name, permalink
+SELECT id, permalink, uppercats, global_rank
FROM '.CATEGORIES_TABLE.'
- WHERE permalink IS NOT NULL';
+ WHERE permalink IS NOT NULL
+';
+if ( count($sort_by) and
+ ($sort_by[0]=='id' or $sort_by[0]=='permalink')
+ )
+{
+ $query .= ' ORDER BY '.$sort_by[0];
+}
+$categories=array();
$result=pwg_query($query);
while ( $row=mysql_fetch_assoc($result) )
{
- $display_name = get_cat_display_name( array($row) );
- $template->assign_block_vars( 'permalink',
- array(
- 'CAT_ID' => $row['id'],
- 'CAT' => $display_name,
- 'PERMALINK' => $row['permalink'],
- )
- );
+ $row['name'] = get_cat_display_name_cache( $row['uppercats'] );
+ $categories[] = $row;
+}
+
+if ( !count($sort_by) or $sort_by[0]='name')
+{
+ usort($categories, 'global_rank_compare');
+}
+foreach ($categories as $cat)
+{
+ $template->assign_block_vars( 'permalink', $cat );
}
-$url_del_base = get_root_url().'admin.php?page=permalinks';
+// --- generate display of old permalinks --------------------------------------
+
+$sort_by = parse_sort_variables(
+ array('cat_id','permalink','date_deleted','last_hit','hit'), null,
+ 'dpsf',
+ array('delete_permanent'),
+ 'SORT_OLD_' );
+
+$url_del_base = get_root_url().'admin.php?page=permalinks';
$query = 'SELECT * FROM '.OLD_PERMALINKS_TABLE;
+if ( count($sort_by) )
+{
+ $query .= ' ORDER BY '.$sort_by[0];
+}
$result = pwg_query($query);
while ( $row=mysql_fetch_assoc($result) )
{
- $row['display_name'] = get_cat_display_name_cache($row['cat_id']);
+ $row['name'] = get_cat_display_name_cache($row['cat_id']);
$row['U_DELETE'] =
add_url_params(
$url_del_base,
diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php
index 9c0327362..cfdd8db66 100644
--- a/include/category_cats.inc.php
+++ b/include/category_cats.inc.php
@@ -177,7 +177,7 @@ if (count($categories) > 0)
{
update_cats_with_filtered_data($categories);
}
-
+ trigger_action('loc_begin_index_categories');
if ($conf['subcatify'])
{
$template->set_filename('mainpage_categories', 'mainpage_categories.tpl');
diff --git a/template/yoga/admin/permalinks.tpl b/template/yoga/admin/permalinks.tpl
index 508cf66a9..dbbe4827f 100644
--- a/template/yoga/admin/permalinks.tpl
+++ b/template/yoga/admin/permalinks.tpl
@@ -5,7 +5,7 @@
<h2>{lang:Permalinks}</h2>
</div>
-<form method="post">
+<form method="post" action="{F_ACTION}">
<fieldset><legend>{lang:Add/delete a permalink}</legend>
<label>Category:
<select name="cat_id">
@@ -33,15 +33,15 @@
<h3>{lang:Permalinks}</h3>
<table class="table2">
<tr class="throw">
- <td>Id</td>
- <td>{lang:Category}</td>
- <td>{lang:Permalink}</td>
+ <td>Id {SORT_ID}</td>
+ <td>{lang:Category} {SORT_NAME}</td>
+ <td>{lang:Permalink} {SORT_PERMALINK}</td>
</tr>
<!-- BEGIN permalink -->
<tr>
- <td>{permalink.CAT_ID}</td>
- <td>{permalink.CAT}</td>
- <td>{permalink.PERMALINK}</td>
+ <td>{permalink.id}</td>
+ <td>{permalink.name}</td>
+ <td>{permalink.permalink}</td>
</tr>
<!-- END permalink -->
</table>
@@ -49,18 +49,18 @@
<h3>{lang:Permalink history}</h3>
<table class="table2">
<tr class="throw">
- <td>Id</td>
+ <td>Id {SORT_OLD_CAT_ID}</td>
<td>{lang:Category}</td>
- <td>{lang:Permalink}</td>
- <td>Deleted on</td>
- <td>Last hit</td>
- <td>Hit</td>
+ <td>{lang:Permalink} {SORT_OLD_PERMALINK}</td>
+ <td>Deleted on {SORT_OLD_DATE_DELETED}</td>
+ <td>Last hit {SORT_OLD_LAST_HIT}</td>
+ <td>Hit {SORT_OLD_HIT}</td>
<td></td>
</tr>
<!-- BEGIN deleted_permalink -->
<tr>
<td>{deleted_permalink.cat_id}</td>
- <td>{deleted_permalink.display_name}</td>
+ <td>{deleted_permalink.name}</td>
<td>{deleted_permalink.permalink}</td>
<td>{deleted_permalink.date_deleted}</td>
<td>{deleted_permalink.last_hit}</td>