aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2007-06-28 02:16:03 +0000
committerrvelices <rv-github@modusoptimus.com>2007-06-28 02:16:03 +0000
commit12af0a00794d4624c4804eeef74fd207f474b002 (patch)
tree53aa23bc197f399f7d6069766630af02e213cdf2 /include
parent009970bb9250bd72936beb000d1a578897287153 (diff)
feature 713: allow permalinks to contain the slash ("/") character
git-svn-id: http://piwigo.org/svn/trunk@2047 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/functions_category.inc.php65
-rw-r--r--include/functions_url.inc.php39
2 files changed, 61 insertions, 43 deletions
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 5d1679e5c..2c1150321 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -364,48 +364,51 @@ SELECT DISTINCT(id)
return $subcats;
}
-/** returns a category id that corresponds to the given permalink (or null)
- * @param string permalink
+/** finds a matching category id from a potential list of permalinks
+ * @param array permalinks example: holiday holiday/france holiday/france/paris
+ * @param int idx - output of the index in $permalinks that matches
+ * return category id or null if no match
*/
-function get_cat_id_from_permalink( $permalink )
+function get_cat_id_from_permalinks( $permalinks, &$idx )
{
- $query ='
-SELECT id FROM '.CATEGORIES_TABLE.'
- WHERE permalink="'.$permalink.'"';
- $ids = array_from_query($query, 'id');
- if (!empty($ids))
+ $in = '';
+ foreach($permalinks as $permalink)
{
- return $ids[0];
+ if ( !empty($in) ) $in.=', ';
+ $in .= '"'.$permalink.'"';
}
- return null;
-}
-
-/** returns a category id that has used before this permalink (or null)
- * @param string permalink
- * @param boolean is_hit if true update the usage counters on the old permalinks
- */
-function get_cat_id_from_old_permalink($permalink, $is_hit)
-{
- $query='
-SELECT c.id
+ $query ='
+SELECT c.id, op.permalink, 1 AS is_old
FROM '.OLD_PERMALINKS_TABLE.' op INNER JOIN '.CATEGORIES_TABLE.' c
ON op.cat_id=c.id
- WHERE op.permalink="'.$permalink.'"
- LIMIT 1';
- $result = pwg_query($query);
- $cat_id = null;
- if ( mysql_num_rows($result) )
- list( $cat_id ) = mysql_fetch_array($result);
+ WHERE op.permalink IN ('.$in.')
+UNION
+SELECT id, permalink, 0 AS is_old
+ FROM '.CATEGORIES_TABLE.'
+ WHERE permalink IN ('.$in.')
+;';
+ $perma_hash = hash_from_query($query, 'permalink');
- if ( isset($cat_id) and $is_hit )
+ if ( empty($perma_hash) )
+ return null;
+ for ($i=count($permalinks)-1; $i>=0; $i--)
{
- $query='
+ if ( isset( $perma_hash[ $permalinks[$i] ] ) )
+ {
+ $idx = $i;
+ $cat_id = $perma_hash[ $permalinks[$i] ]['id'];
+ if ($perma_hash[ $permalinks[$i] ]['is_old'])
+ {
+ $query='
UPDATE '.OLD_PERMALINKS_TABLE.' SET last_hit=NOW(), hit=hit+1
- WHERE permalink="'.$permalink.'" AND cat_id='.$cat_id.'
+ WHERE permalink="'.$permalinks[$i].'" AND cat_id='.$cat_id.'
LIMIT 1';
- pwg_query($query);
+ pwg_query($query);
+ }
+ return $cat_id;
+ }
}
- return $cat_id;
+ return null;
}
function global_rank_compare($a, $b)
diff --git a/include/functions_url.inc.php b/include/functions_url.inc.php
index 3c0138136..9e81a72cf 100644
--- a/include/functions_url.inc.php
+++ b/include/functions_url.inc.php
@@ -457,29 +457,44 @@ function parse_section_url( $tokens, &$next_token)
$next_token++;
}
else
- {
- if ( strpos($tokens[$next_token], 'created-')!==0
- and strpos($tokens[$next_token], 'posted-')!==0
+ {// try a permalink
+ $maybe_permalinks = array();
+ $current_token = $next_token;
+ while ( isset($tokens[$current_token])
+ and strpos($tokens[$current_token], 'created-')!==0
+ and strpos($tokens[$current_token], 'posted-')!==0
and strpos($tokens[$next_token], 'start-')!==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);
+ and $tokens[$current_token] != 'flat')
+ {
+ if (empty($maybe_permalinks))
+ {
+ array_push($maybe_permalinks, $tokens[$current_token]);
+ }
+ else
+ {
+ array_push($maybe_permalinks,
+ $maybe_permalinks[count($maybe_permalinks)-1]
+ . '/' . $tokens[$current_token]
+ );
}
+ $current_token++;
+ }
+
+ if ( count($maybe_permalinks) )
+ {
+ $cat_id = get_cat_id_from_permalinks($maybe_permalinks, $perma_index);
if ( isset($cat_id) )
{
+ $next_token += $perma_index+1;
$page['category'] = $cat_id;
- $page['hit_by']['cat_permalink'] = $tokens[$next_token];
+ $page['hit_by']['cat_permalink'] = $maybe_permalinks[$perma_index];
}
else
{
page_not_found('Permalink for album not found');
}
- $next_token++;
}
- }
+ }
}
if (isset($page['category']))