aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2006-03-28 02:16:34 +0000
committerrvelices <rv-github@modusoptimus.com>2006-03-28 02:16:34 +0000
commit8b3328e7ed8ae8936ce816b2eed69b422381d30b (patch)
tree3d708e73b9435a37edf1e307f4586db35eea04b3
parent2ea96d5a96abfdacec319836051070f9016d7b95 (diff)
moved category.php to index.php
split url functions from functions.inc.php to functions_url.inc.php git-svn-id: http://piwigo.org/svn/trunk@1109 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--include/calendar_monthly.class.php2
-rw-r--r--include/functions.inc.php309
-rw-r--r--include/functions_calendar.inc.php2
-rw-r--r--include/functions_url.inc.php347
-rw-r--r--include/section_init.inc.php32
-rw-r--r--index.php (renamed from category.php)4
-rw-r--r--template/yoga/index.tpl (renamed from template/yoga/category.tpl)0
7 files changed, 372 insertions, 324 deletions
diff --git a/include/calendar_monthly.class.php b/include/calendar_monthly.class.php
index 1f26e1275..5c55dbe5d 100644
--- a/include/calendar_monthly.class.php
+++ b/include/calendar_monthly.class.php
@@ -1,4 +1,4 @@
- <?php
+<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 47eed7c7c..520f8d52a 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
-// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
+// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
@@ -31,6 +31,7 @@ include_once( PHPWG_ROOT_PATH .'include/functions_category.inc.php' );
include_once( PHPWG_ROOT_PATH .'include/functions_xml.inc.php' );
include_once( PHPWG_ROOT_PATH .'include/functions_group.inc.php' );
include_once( PHPWG_ROOT_PATH .'include/functions_html.inc.php' );
+include_once( PHPWG_ROOT_PATH .'include/functions_url.inc.php' );
//----------------------------------------------------------- generic functions
@@ -1019,310 +1020,4 @@ function get_available_upgrade_ids()
return $available_upgrade_ids;
}
-/**
- * returns a prefix for each url link on displayed page
- * @return string
- */
-function get_root_url()
-{
- global $page;
- if ( isset($page['root_path']) )
- {
- return $page['root_path'];
- }
- return PHPWG_ROOT_PATH;
-}
-
-/**
- * adds one or more _GET style parameters to an url
- * example: add_url_params('/x', array('a'=>'b')) returns /x?a=b
- * add_url_params('/x?cat_id=10', array('a'=>'b')) returns /x?cat_id=10&amp;a=b
- * @param string url
- * @param array params
- * @return string
- */
-function add_url_params($url, $params)
-{
- if ( !empty($params) )
- {
- assert( is_array($params) );
- $is_first = true;
- foreach($params as $param=>$val)
- {
- if ($is_first)
- {
- $is_first = false;
- $url .= ( strstr($url, '?')===false ) ? '?' :'&amp;';
- }
- else
- {
- $url .= '&amp;';
- }
- $url .= $param;
- if (isset($val))
- {
- $url .= '='.$val;
- }
- }
- }
- return $url;
-}
-
-/**
- * build an index URL for a specific section
- *
- * @param array
- * @return string
- */
-function make_index_URL($params = array())
-{
- global $conf;
- $url = get_root_url().'category';
- if ($conf['php_extension_in_urls'])
- {
- $url .= '.php';
- }
- if ($conf['question_mark_in_urls'])
- {
- $url .= '?';
- }
- $url.= make_section_in_URL($params);
- $url = add_well_known_params_in_url($url, $params);
- 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)
-{
- global $conf;
- if (!isset($params['image_id']))
- {
- die('make_picture_URL: image_id is a required parameter');
- }
-
- $url = get_root_url().'picture';
- if ($conf['php_extension_in_urls'])
- {
- $url .= '.php';
- }
- if ($conf['question_mark_in_urls'])
- {
- $url .= '?';
- }
- $url .= make_section_in_URL($params);
- $url = add_well_known_params_in_url($url, $params);
- $url.= '/';
- switch ( $conf['picture_url_style'] )
- {
- case 'id-file':
- $url .= $params['image_id'].'-';
- case 'file':
- $url .= get_filename_wo_extension($params['image_file']).'.htm';
- break;
- default:
- $url .= $params['image_id'];
- }
- return $url;
-}
-
-/**
- *adds to the url the chronology and start parameters
-*/
-function add_well_known_params_in_url($url, $params)
-{
- if ( isset($params['chronology_field']) )
- {
- $url .= '/'. $params['chronology_field'];
- $url .= '-'. $params['chronology_style'];
- if ( isset($params['chronology_view']) )
- {
- $url .= '-'. $params['chronology_view'];
- }
- if ( !empty($params['chronology_date']) )
- {
- $url .= '-'. implode('-', $params['chronology_date'] );
- }
- }
-
- 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['category']))
- {
- $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;
-}
?>
diff --git a/include/functions_calendar.inc.php b/include/functions_calendar.inc.php
index 962086bce..f8bec93e0 100644
--- a/include/functions_calendar.inc.php
+++ b/include/functions_calendar.inc.php
@@ -178,7 +178,7 @@ WHERE id IN (' . implode(',',$page['items']) .')';
//echo ('<pre>'. var_export($calendar, true) . '</pre>');
$must_show_list = true; // true until calendar generates its own display
- if (basename($_SERVER['SCRIPT_FILENAME']) == 'category.php')
+ if (basename($_SERVER['SCRIPT_FILENAME']) != 'picture.php')
{
$template->assign_block_vars('calendar', array());
diff --git a/include/functions_url.inc.php b/include/functions_url.inc.php
new file mode 100644
index 000000000..0e0583872
--- /dev/null
+++ b/include/functions_url.inc.php
@@ -0,0 +1,347 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery |
+// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | branch : BSF (Best So Far)
+// | file : $RCSfile$
+// | last update : $Date$
+// | last modifier : $Author$
+// | revision : $Revision$
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+
+/**
+ * returns a prefix for each url link on displayed page
+ * @return string
+ */
+function get_root_url()
+{
+ global $page;
+ if ( isset($page['root_path']) )
+ {
+ return $page['root_path'];
+ }
+ return PHPWG_ROOT_PATH;
+}
+
+/**
+ * adds one or more _GET style parameters to an url
+ * example: add_url_params('/x', array('a'=>'b')) returns /x?a=b
+ * add_url_params('/x?cat_id=10', array('a'=>'b')) returns /x?cat_id=10&amp;a=b
+ * @param string url
+ * @param array params
+ * @return string
+ */
+function add_url_params($url, $params)
+{
+ if ( !empty($params) )
+ {
+ assert( is_array($params) );
+ $is_first = true;
+ foreach($params as $param=>$val)
+ {
+ if ($is_first)
+ {
+ $is_first = false;
+ $url .= ( strstr($url, '?')===false ) ? '?' :'&amp;';
+ }
+ else
+ {
+ $url .= '&amp;';
+ }
+ $url .= $param;
+ if (isset($val))
+ {
+ $url .= '='.$val;
+ }
+ }
+ }
+ return $url;
+}
+
+/**
+ * build an index URL for a specific section
+ *
+ * @param array
+ * @return string
+ */
+function make_index_URL($params = array())
+{
+ global $conf;
+ $url = get_root_url().'index';
+ if ($conf['php_extension_in_urls'])
+ {
+ $url .= '.php';
+ }
+ if ($conf['question_mark_in_urls'])
+ {
+ $url .= '?';
+ }
+ $url.= make_section_in_URL($params);
+ $url = add_well_known_params_in_url($url, $params);
+ 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)
+{
+ global $conf;
+ if (!isset($params['image_id']))
+ {
+ die('make_picture_URL: image_id is a required parameter');
+ }
+
+ $url = get_root_url().'picture';
+ if ($conf['php_extension_in_urls'])
+ {
+ $url .= '.php';
+ }
+ if ($conf['question_mark_in_urls'])
+ {
+ $url .= '?';
+ }
+ $url.= '/';
+ switch ( $conf['picture_url_style'] )
+ {
+ case 'id-file':
+ $url .= $params['image_id'];
+ if ( isset($params['image_file']) )
+ {
+ $url .= '-'.get_filename_wo_extension($params['image_file']);
+ }
+ break;
+ case 'file':
+ if ( isset($params['image_file'])
+ and !is_numeric($params['image_file']) )
+ {
+ $url .= get_filename_wo_extension($params['image_file']);
+ }
+ else
+ {
+ $url .= $params['image_id'];
+ }
+ break;
+ default:
+ $url .= $params['image_id'];
+ }
+ $url .= make_section_in_URL($params);
+ $url = add_well_known_params_in_url($url, $params);
+ return $url;
+}
+
+/**
+ *adds to the url the chronology and start parameters
+*/
+function add_well_known_params_in_url($url, $params)
+{
+ if ( isset($params['chronology_field']) )
+ {
+ $url .= '/'. $params['chronology_field'];
+ $url .= '-'. $params['chronology_style'];
+ if ( isset($params['chronology_view']) )
+ {
+ $url .= '-'. $params['chronology_view'];
+ }
+ if ( !empty($params['chronology_date']) )
+ {
+ $url .= '-'. implode('-', $params['chronology_date'] );
+ }
+ }
+
+ 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['category']))
+ {
+ $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;
+}
+?> \ No newline at end of file
diff --git a/include/section_init.inc.php b/include/section_init.inc.php
index 73f11105d..12e720d2d 100644
--- a/include/section_init.inc.php
+++ b/include/section_init.inc.php
@@ -84,29 +84,40 @@ $tokens = explode(
$next_token = 0;
if (basename($_SERVER['SCRIPT_FILENAME']) == 'picture.php')
-{ // the last token must be the identifier for the picture
- $token = array_pop($tokens);
+{ // the first token must be the identifier for the picture
+ if ( isset($_GET['image_id'])
+ and isset($_GET['cat']) and is_numeric($_GET['cat']) )
+ {// url compatibility with versions below 1.6
+ $url = make_picture_url( array(
+ 'section' => 'categories',
+ 'category' => $_GET['cat'],
+ 'image_id' => $_GET['image_id']
+ ) );
+ redirect($url);
+ }
+ $token = $tokens[$next_token];
+ $next_token++;
if ( is_numeric($token) )
{
$page['image_id'] = $token;
}
else
{
- preg_match('/^(\d+-)?((.*)[_\.]html?)?$/', $token, $matches);
+ preg_match('/^(\d+-)?(.*)?$/', $token, $matches);
if (isset($matches[1]) and is_numeric($matches[1]=rtrim($matches[1],'-')) )
{
$page['image_id'] = $matches[1];
- if ( !empty($matches[3]) )
+ if ( !empty($matches[2]) )
{
- $page['image_file'] = $matches[3];
+ $page['image_file'] = $matches[2];
}
}
else
{
- if ( !empty($matches[3]) )
+ if ( !empty($matches[2]) )
{
- $page['image_file'] = $matches[3];
+ $page['image_file'] = $matches[2];
}
else
{
@@ -116,7 +127,7 @@ if (basename($_SERVER['SCRIPT_FILENAME']) == 'picture.php')
}
}
-if (0 === strpos($tokens[$next_token], 'cat'))
+if (0 === strpos($tokens[$next_token], 'categor'))
{
$page['section'] = 'categories';
$next_token++;
@@ -213,11 +224,6 @@ else if ('list' == $tokens[$next_token])
}
$next_token++;
}
-else
-{
- $page['section'] = 'categories';
- $next_token++;
-}
for ($i = $next_token; ; $i++)
{
diff --git a/category.php b/index.php
index 36e039bed..937cff75a 100644
--- a/category.php
+++ b/index.php
@@ -108,7 +108,7 @@ $title = $page['title'];
$page['body_id'] = 'theCategoryPage';
include(PHPWG_ROOT_PATH.'include/page_header.php');
-$template->set_filenames( array('category'=>'category.tpl') );
+$template->set_filenames( array('index'=>'index.tpl') );
//-------------------------------------------------------------- category title
if (isset($page['category']))
{
@@ -482,6 +482,6 @@ if (isset($page['category']))
//------------------------------------------------------------ log informations
pwg_log('category', $page['title']);
-$template->parse('category');
+$template->parse('index');
include(PHPWG_ROOT_PATH.'include/page_tail.php');
?>
diff --git a/template/yoga/category.tpl b/template/yoga/index.tpl
index df6e4d249..df6e4d249 100644
--- a/template/yoga/category.tpl
+++ b/template/yoga/index.tpl