aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions.inc.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2006-03-15 22:44:35 +0000
committerplegall <plg@piwigo.org>2006-03-15 22:44:35 +0000
commit114ae324452ac88fe7b672338cba931d838ee2a4 (patch)
tree2ccc8e920a04fae1f97732f6490fa7c67594c05e /include/functions.inc.php
parent88e3b36e2f805404e0bfd56d865e317495e9c973 (diff)
new: cleaner URL. Instead of category.php?cat=search&search=123&start=42,
you now have category.php?/search/123/start-42. Functions make_index_url and make_picture_url build these new URLs. Functions duplicate_picture_url and duplicate_index_url provide shortcuts to URL creation. The current main page page is still category.php but this can be modified easily in make_index_url function. In this first version, no backward compatibility. Calendar definition in URL must be discussed with rvelices. improvement: picture.php redesigned. First actions like "set as representative" or "delete a comment" which all lead to a redirection. Then the page (the big mess) and includes of new sub pages to manage specific parts of the page (metadata, user comments, rates). new: with the cleaner URL comes a new terminology. $page['cat'] doesn't exist anymore. $page['section'] is among 'categories', 'tags' (TODO), 'list', 'most_seen'... And sub parameters are set : $page['category'] if $page['section'] is "categories". See URL analyse in include/section_init.inc.php for details. git-svn-id: http://piwigo.org/svn/trunk@1082 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/functions.inc.php229
1 files changed, 225 insertions, 4 deletions
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 205b61a70..9b628a93c 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -582,10 +582,12 @@ function get_thumbnail_src($path, $tn_ext = '')
if ($tn_ext != '')
{
- $src = substr_replace(get_filename_wo_extension($path),
- '/thumbnail/'.$conf['prefix_thumbnail'],
- strrpos($path,'/'),
- 1);
+ $src = substr_replace(
+ get_filename_wo_extension($path),
+ '/thumbnail/'.$conf['prefix_thumbnail'],
+ strrpos($path,'/'),
+ 1
+ );
$src.= '.'.$tn_ext;
}
else
@@ -1000,4 +1002,223 @@ function get_available_upgrade_ids()
return $available_upgrade_ids;
}
+
+/**
+ * build an index URL for a specific section
+ *
+ * @param array
+ * @return string
+ */
+function make_index_URL($params = array())
+{
+ $url =
+ PHPWG_ROOT_PATH.'category.php?'
+ .'/'.make_section_in_URL($params)
+ ;
+
+ if (isset($params['start']) and $params['start'] > 0)
+ {
+ $url.= '/start-'.$params['start'];
+ }
+
+ return $url;
+}
+
+/**
+ * build an index URL with current page parameters, but with redefinitions
+ * and removes.
+ *
+ * duplicate_index_URL(array('category' => 12), array('start')) will create
+ * an index URL on the current section (categories), but on a redefined
+ * category and without the start URL parameter.
+ *
+ * @param array redefined keys
+ * @param array removed keys
+ * @return string
+ */
+function duplicate_index_URL($redefined = array(), $removed = array())
+{
+ return make_index_URL(
+ params_for_duplication($redefined, $removed)
+ );
+}
+
+/**
+ * returns $page global array with key redefined and key removed
+ *
+ * @param array redefined keys
+ * @param array removed keys
+ * @return array
+ */
+function params_for_duplication($redefined, $removed)
+{
+ global $page;
+
+ if (count($removed) > 0)
+ {
+ $params = array();
+
+ foreach ($page as $page_item_key => $page_item_value)
+ {
+ if (!in_array($page_item_key, $removed))
+ {
+ $params[$page_item_key] = $page_item_value;
+ }
+ }
+ }
+ else
+ {
+ $params = $page;
+ }
+
+ foreach ($redefined as $redefined_param => $redefined_value)
+ {
+ $params[$redefined_param] = $redefined_value;
+ }
+
+ return $params;
+}
+
+/**
+ * create a picture URL with current page parameters, but with redefinitions
+ * and removes. See duplicate_index_URL.
+ *
+ * @param array redefined keys
+ * @param array removed keys
+ * @return string
+ */
+function duplicate_picture_URL($redefined = array(), $removed = array())
+{
+ return make_picture_URL(
+ params_for_duplication($redefined, $removed)
+ );
+}
+
+/**
+ * create a picture URL on a specific section for a specific picture
+ *
+ * @param array
+ * @return string
+ */
+function make_picture_URL($params)
+{
+ if (!isset($params['image_id']))
+ {
+ die('make_picture_URL: image_id is a required parameter');
+ }
+
+ $url =
+ PHPWG_ROOT_PATH.'picture.php?'
+ .'/'.$params['image_id']
+ .'/'.make_section_in_URL($params)
+ ;
+
+ // first comment to start on
+ if (isset($params['start']) and $params['start'] > 0)
+ {
+ $url.= '/start-'.$params['start'];
+ }
+
+ return $url;
+}
+
+/**
+ * return the section token of an index or picture URL.
+ *
+ * Depending on section, other parameters are required (see function code
+ * for details)
+ *
+ * @param array
+ * @return string
+ */
+function make_section_in_URL($params)
+{
+ $section_string = '';
+
+ if (!isset($params['section']))
+ {
+ if (isset($params['section']))
+ {
+ $params['section'] = 'categories';
+ }
+ else if (isset($params['tags']))
+ {
+ $params['section'] = 'tags';
+ }
+ else if (isset($params['list']))
+ {
+ $params['section'] = 'list';
+ }
+ else if (isset($params['search']))
+ {
+ $params['section'] = 'search';
+ }
+ }
+
+ if (!isset($params['section']))
+ {
+ $params['section'] = 'categories';
+ }
+
+ switch($params['section'])
+ {
+ case 'categories' :
+ {
+ if (!isset($params['category']))
+ {
+ $section_string.= 'categories';
+ }
+ else
+ {
+ $section_string.= 'category/'.$params['category'];
+ }
+
+ break;
+ }
+ case 'tags' :
+ {
+ if (!isset($params['tags']) or count($params['tags']) == 0)
+ {
+ die('make_section_in_URL: require at least one tag');
+ }
+
+ $section_string.= 'tags';
+
+ foreach ($params['tags'] as $tag)
+ {
+ $section_string.= '/'.$tag;
+ }
+
+ break;
+ }
+ case 'search' :
+ {
+ if (!isset($params['search']))
+ {
+ die('make_section_in_URL: require a search identifier');
+ }
+
+ $section_string.= 'search/'.$params['search'];
+
+ break;
+ }
+ case 'list' :
+ {
+ if (!isset($params['list']))
+ {
+ die('make_section_in_URL: require a list of items');
+ }
+
+ $section_string.= 'list/'.implode(',', $params['list']);
+
+ break;
+ }
+ default :
+ {
+ $section_string.= $params['section'];
+ }
+ }
+
+ return $section_string;
+}
?>