aboutsummaryrefslogtreecommitdiffstats
path: root/include/section_init.inc.php
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2007-02-28 03:07:12 +0000
committerrvelices <rv-github@modusoptimus.com>2007-02-28 03:07:12 +0000
commitea56d7b2ac1d41ea19b5fb45843c839e30a0b37b (patch)
tree5f55c108b1a808867d44db2b6ebcf0ad573874b6 /include/section_init.inc.php
parent30e259904cc38172b2b730455009455675f0d8f5 (diff)
feature 657: permalinks for categories
git-svn-id: http://piwigo.org/svn/trunk@1866 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include/section_init.inc.php')
-rw-r--r--include/section_init.inc.php73
1 files changed, 68 insertions, 5 deletions
diff --git a/include/section_init.inc.php b/include/section_init.inc.php
index 4434ec542..af633571a 100644
--- a/include/section_init.inc.php
+++ b/include/section_init.inc.php
@@ -107,7 +107,6 @@ if (script_basename() == 'picture') // basename without file extention
{
$page['image_file'] = $matches[2];
}
-
}
else
{
@@ -128,11 +127,39 @@ if (0 === strpos(@$tokens[$next_token], 'categor'))
$page['section'] = 'categories';
$next_token++;
- if (isset($tokens[$next_token])
- and preg_match('/^(\d+)/', $tokens[$next_token], $matches))
+ if (isset($tokens[$next_token]) )
{
- $page['category'] = $matches[1];
- $next_token++;
+ if (preg_match('/^(\d+)(?:-(.+))?$/', $tokens[$next_token], $matches))
+ {
+ if ( isset($matches[2]) )
+ $page['hit_by']['cat_url_name'] = $matches[2];
+ $page['category'] = $matches[1];
+ $next_token++;
+ }
+ else
+ {
+ if ( strpos($tokens[$next_token], 'created-')!==0
+ and strpos($tokens[$next_token], 'posted-')!==0
+ and $tokens[$next_token] != 'flat')
+ {// try a permalink
+ $cat_id = get_cat_id_from_permalink($tokens[$next_token]);
+ if ( !isset($cat_id) )
+ {//try old permalink
+ $cat_id = get_cat_id_from_old_permalink($tokens[$next_token], true);
+ }
+ if ( isset($cat_id) )
+ {
+ $page['category'] = $cat_id;
+ $page['hit_by']['cat_permalink'] = $tokens[$next_token];
+ }
+ else
+ {
+ page_not_found('Permalink for album not found');
+ }
+ unset($cat_id);
+ $next_token++;
+ }
+ }
}
}
else if (0 === strpos(@$tokens[$next_token], 'tag'))
@@ -690,5 +717,41 @@ if ( $filter['enabled'] )
$page['meta_robots']['noindex']=1;
}
+// see if we need a redirect because of a permalink
+if ( 'categories'==$page['section'] and isset($page['category']) )
+{
+ $need_redirect=false;
+ if ( empty($page['category']['permalink']) )
+ {
+ if ( $conf['category_url_style'] == 'id-name' and
+ @$page['hit_by']['cat_url_name'] !== str2url($page['category']['name']) )
+ {
+ $need_redirect=true;
+ }
+ }
+ else
+ {
+ if ( $page['category']['permalink'] !== @$page['hit_by']['cat_permalink'] )
+ {
+ $need_redirect=true;
+ }
+ }
+
+ if ($need_redirect)
+ {
+ $redirect_url = ( script_basename()=='picture'
+ ? duplicate_picture_url()
+ : duplicate_index_url()
+ );
+ if (!headers_sent())
+ { // this is a permanent redirection
+ set_status_header(302);
+ redirect_http( $redirect_url );
+ }
+ redirect( $redirect_url );
+ }
+ unset( $need_redirect, $page['hit_by'] );
+}
+
trigger_action('loc_end_section_init');
?> \ No newline at end of file