aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2007-02-27 01:56:16 +0000
committerrvelices <rv-github@modusoptimus.com>2007-02-27 01:56:16 +0000
commit47512ce6a64fa356214c162a8313480c6aed41d2 (patch)
treea0e35e2f89ef789f380adc5b8951444c189de4e7 /include
parentbfb4b15d2f75835033d9bbb865edd77dcb282bb6 (diff)
- refactoring page['category'] before 1.7 release
page['category'] is not an id anymore, but an associative array of category info all of page['cat_xxx'] or page['uppercats'] merged into one simplifies calls to make_index_url give plugins a clean start for page variables for version 1.7 git-svn-id: http://piwigo.org/svn/trunk@1861 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/category_cats.inc.php12
-rw-r--r--include/category_default.inc.php2
-rw-r--r--include/functions.inc.php3
-rw-r--r--include/functions_calendar.inc.php12
-rw-r--r--include/functions_category.inc.php47
-rw-r--r--include/functions_html.inc.php59
-rw-r--r--include/functions_url.inc.php34
-rw-r--r--include/menubar.inc.php5
-rw-r--r--include/section_init.inc.php23
-rw-r--r--include/ws_functions.inc.php17
10 files changed, 91 insertions, 123 deletions
diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php
index 2acb05f13..e9549ba44 100644
--- a/include/category_cats.inc.php
+++ b/include/category_cats.inc.php
@@ -35,7 +35,7 @@ if ($page['section']=='recent_cats')
// $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
$query = '
SELECT
- id,name, representative_picture_id, comment, nb_images, uppercats,
+ id, name, representative_picture_id, comment, nb_images, uppercats,
date_last, max_date_last, count_images, count_categories, global_rank
FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
ON id = cat_id and user_id = '.$user['id'].'
@@ -57,12 +57,12 @@ else
// $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
$query = '
SELECT
- id,name, representative_picture_id, comment, nb_images,
+ id, name, representative_picture_id, comment, nb_images,
date_last, max_date_last, count_images, count_categories
FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
ON id = cat_id and user_id = '.$user['id'].'
WHERE id_uppercat '.
- (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
+ (!isset($page['category']) ? 'is NULL' : '= '.$page['category']['id']).'
'.get_sql_condition_FandF
(
array
@@ -206,8 +206,7 @@ if (count($categories) > 0)
'URL' => make_index_url(
array(
- 'category' => $category['id'],
- 'cat_name' => $category['name'],
+ 'category' => $category
)
),
'CAPTION_NB_IMAGES' => get_display_images_count
@@ -258,8 +257,7 @@ if (count($categories) > 0)
'U_IMG_LINK' => make_index_url(
array(
- 'category' => $category['id'],
- 'cat_name' => $category['name'],
+ 'category' => $category
)
),
'CLASS' => 'thumbCat',
diff --git a/include/category_default.inc.php b/include/category_default.inc.php
index bb6b5a089..1d8438d93 100644
--- a/include/category_default.inc.php
+++ b/include/category_default.inc.php
@@ -157,7 +157,7 @@ foreach ($pictures as $row)
if ($user['show_nb_comments']
and isset($page['category'])
- and $page['cat_commentable'])
+ and $page['category']['commentable'])
{
$query = '
SELECT COUNT(*) AS nb_comments
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 4666c0fcb..50f247a47 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -4,7 +4,6 @@
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
// | file : $Id$
// | last update : $Date$
// | last modifier : $Author$
@@ -482,7 +481,7 @@ INSERT INTO '.HISTORY_TABLE.'
'.$user['id'].',
\''.$_SERVER['REMOTE_ADDR'].'\',
'.(isset($page['section']) ? "'".$page['section']."'" : 'NULL').',
- '.(isset($page['category']) ? $page['category'] : 'NULL').',
+ '.(isset($page['category']) ? $page['category']['id'] : 'NULL').',
'.(isset($image_id) ? $image_id : 'NULL').',
'.(isset($image_id) ? "'".$image_type."'" : 'NULL').',
'.(isset($tags_string) ? "'".$tags_string."'" : 'NULL').'
diff --git a/include/functions_calendar.inc.php b/include/functions_calendar.inc.php
index a29536c71..86ef40837 100644
--- a/include/functions_calendar.inc.php
+++ b/include/functions_calendar.inc.php
@@ -1,10 +1,9 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
-// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
-// | file : $RCSfile$
+// | file : $Id$
// | last update : $Date$
// | last modifier : $Author$
// | revision : $Revision$
@@ -34,17 +33,16 @@ function initialize_calendar()
//------------------ initialize the condition on items to take into account ---
$inner_sql = ' FROM ' . IMAGES_TABLE;
- if ($page['section']=='categories' or
- ( isset($page['category']) and is_numeric($page['category']) ) )
+ if ($page['section']=='categories')
{ // we will regenerate the items by including subcats elements
$page['items'] = array();
$inner_sql .= '
INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id';
- if (isset($page['category']) and is_numeric($page['category']))
+ if ( isset($page['category']) )
{
$sub_ids = array_diff(
- get_subcat_ids(array($page['category'])),
+ get_subcat_ids(array($page['category']['id'])),
explode(',', $user['forbidden_categories'])
);
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 8ed10de3e..66b8865da 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -77,7 +77,7 @@ WHERE
(id_uppercat is NULL';
if (isset($page['category']))
{
- $query.= ' OR id_uppercat IN ('.$page['uppercats'].')';
+ $query.= ' OR id_uppercat IN ('.$page['category']['uppercats'].')';
}
$query.= ')';
}
@@ -111,7 +111,7 @@ WHERE
update_cats_with_filtered_data($cats);
}
- return get_html_menu_category($cats);
+ return get_html_menu_category($cats, @$page['category'] );
}
@@ -134,62 +134,48 @@ WHERE
*/
function get_cat_info( $id )
{
- $infos = array('nb_images','id_uppercat','comment','site_id'
- ,'dir','date_last','uploadable','status','visible'
- ,'representative_picture_id','uppercats','commentable'
- ,'image_order');
-
$query = '
-SELECT '.implode(',', $infos).'
+SELECT *
FROM '.CATEGORIES_TABLE.'
WHERE id = '.$id.'
;';
- $row = mysql_fetch_array(pwg_query($query));
- if (empty($row))
+ $cat = mysql_fetch_assoc(pwg_query($query));
+ if (empty($cat))
return null;
- $cat = array();
- foreach ($infos as $info)
+ foreach ($cat as $k => $v)
{
- if (isset($row[$info]))
- {
- $cat[$info] = $row[$info];
- }
- else
- {
- $cat[$info] = '';
- }
// If the field is true or false, the variable is transformed into a
// boolean value.
- if ($cat[$info] == 'true' or $cat[$info] == 'false')
+ if ($cat[$k] == 'true' or $cat[$k] == 'false')
{
- $cat[$info] = get_boolean( $cat[$info] );
+ $cat[$k] = get_boolean( $cat[$k] );
}
}
global $conf;
if ( !( $conf['allow_html_descriptions'] and
preg_match('/<(div|br|img|script).*>/i', $cat['comment']) ) )
{
- $cat['comment'] = nl2br($cat['comment']);
+ $cat['comment'] = nl2br(@$cat['comment']);
}
$names = array();
$query = '
-SELECT name,id
+SELECT id, name
FROM '.CATEGORIES_TABLE.'
WHERE id IN ('.$cat['uppercats'].')
;';
$result = pwg_query($query);
- while($row = mysql_fetch_array($result))
+ while($row = mysql_fetch_assoc($result))
{
- $names[$row['id']] = $row['name'];
+ $names[$row['id']] = $row;
}
// category names must be in the same order than uppercats list
- $cat['name'] = array();
+ $cat['upper_names'] = array();
foreach (explode(',', $cat['uppercats']) as $cat_id)
{
- $cat['name'][$cat_id] = $names[$cat_id];
+ $cat['upper_names'][$cat_id] = $names[$cat_id];
}
return $cat;
@@ -345,6 +331,11 @@ SELECT DISTINCT(id)
WHERE ';
foreach ($ids as $num => $category_id)
{
+ is_numeric($category_id)
+ or trigger_error(
+ 'get_subcat_ids expecting numeric, not '.gettype($category_id),
+ E_USER_WARNING
+ );
if ($num > 0)
{
$query.= '
diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php
index 60f26a45a..dcb42cdb1 100644
--- a/include/functions_html.inc.php
+++ b/include/functions_html.inc.php
@@ -235,7 +235,7 @@ function create_navigation_bar(
*
* categories string returned contains categories as given in the input
* array $cat_informations. $cat_informations array must be an association
- * of {category_id => category_name}. If url input parameter is null,
+ * of {category_id => array( id, name) }. If url input parameter is null,
* returns only the categories name without links.
*
* @param array cat_informations
@@ -251,8 +251,11 @@ function get_cat_display_name($cat_informations,
$output = '';
$is_first = true;
- foreach ($cat_informations as $id => $name)
+ foreach ($cat_informations as $id => $cat)
{
+ is_array($cat) or trigger_error(
+ 'get_cat_display_name wrong type for cat '.$id, E_USER_WARNING
+ );
if ($is_first)
{
$is_first = false;
@@ -264,24 +267,23 @@ function get_cat_display_name($cat_informations,
if ( !isset($url) )
{
- $output.= $name;
+ $output.= $cat['name'];
}
elseif ($url == '')
{
$output.= '<a href="'
.make_index_url(
array(
- 'category'=>$id,
- 'cat_name'=>$name
+ 'category' => $cat,
)
)
.'">';
- $output.= $name.'</a>';
+ $output.= $cat['name'].'</a>';
}
else
{
$output.= '<a href="'.PHPWG_ROOT_PATH.$url.$id.'">';
- $output.= $name.'</a>';
+ $output.= $cat['name'].'</a>';
}
}
if ($replace_space)
@@ -311,18 +313,18 @@ function get_cat_display_name_cache($uppercats,
$url = '',
$replace_space = true)
{
- global $cat_names, $conf;
+ global $cache, $conf;
- if (!isset($cat_names))
+ if (!isset($cache['cat_names']))
{
$query = '
-SELECT id,name
+SELECT id, name
FROM '.CATEGORIES_TABLE.'
;';
$result = pwg_query($query);
- while ($row = mysql_fetch_array($result))
+ while ($row = mysql_fetch_assoc($result))
{
- $cat_names[$row['id']] = $row['name'];
+ $cache['cat_names'][$row['id']] = $row;
}
}
@@ -330,7 +332,7 @@ SELECT id,name
$is_first = true;
foreach (explode(',', $uppercats) as $category_id)
{
- $name = $cat_names[$category_id];
+ $cat = $cache['cat_names'][$category_id];
if ($is_first)
{
@@ -343,7 +345,7 @@ SELECT id,name
if ( !isset($url) )
{
- $output.= $name;
+ $output.= $cat['name'];
}
elseif ($url == '')
{
@@ -351,16 +353,15 @@ SELECT id,name
<a href="'
.make_index_url(
array(
- 'category'=>$category_id,
- 'cat_name'=>$name
+ 'category' => $cat,
)
)
- .'">'.$name.'</a>';
+ .'">'.$cat['name'].'</a>';
}
else
{
$output.= '
-<a href="'.PHPWG_ROOT_PATH.$url.$category_id.'">'.$name.'</a>';
+<a href="'.PHPWG_ROOT_PATH.$url.$category_id.'">'.$cat['name'].'</a>';
}
}
if ($replace_space)
@@ -384,21 +385,14 @@ SELECT id,name
* @param array categories
* @return string
*/
-function get_html_menu_category($categories)
+function get_html_menu_category($categories, $selected_category)
{
- global $page, $lang;
+ global $lang;
$ref_level = 0;
$level = 0;
$menu = '';
- // $page_cat value remains 0 for special sections
- $page_cat = 0;
- if (isset($page['category']))
- {
- $page_cat = $page['category'];
- }
-
foreach ($categories as $category)
{
$level = substr_count($category['global_rank'], '.') + 1;
@@ -419,7 +413,7 @@ function get_html_menu_category($categories)
$ref_level = $level;
$menu.= "\n\n".'<li';
- if ($category['id'] == $page_cat)
+ if ($category['id'] == @$selected_category['id'])
{
$menu.= ' class="selected"';
}
@@ -427,14 +421,13 @@ function get_html_menu_category($categories)
$url = make_index_url(
array(
- 'category'=>$category['id'],
- 'cat_name'=>$category['name']
+ 'category' => $category
)
);
$menu.= "\n".'<a href="'.$url.'"';
- if ($page_cat != 0
- and $category['id'] == $page['cat_id_uppercat'])
+ if ($selected_category!=null
+ and $category['id'] == $selected_category['id_uppercat'])
{
$menu.= ' rel="up"';
}
@@ -509,7 +502,7 @@ function get_cat_display_name_from_id($cat_id,
$replace_space = true)
{
$cat_info = get_cat_info($cat_id);
- return get_cat_display_name($cat_info['name'], $url, $replace_space);
+ return get_cat_display_name($cat_info['upper_names'], $url, $replace_space);
}
/**
diff --git a/include/functions_url.inc.php b/include/functions_url.inc.php
index 4f9b15b4b..b96ed82b7 100644
--- a/include/functions_url.inc.php
+++ b/include/functions_url.inc.php
@@ -3,7 +3,6 @@
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
// | file : $Id$
// | last update : $Date$
// | last modifier : $Author$
@@ -133,9 +132,11 @@ function make_index_url($params = array())
* 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.
+ * duplicate_index_url( array(
+ * 'category' => array('id'=>12, 'name'=>'toto'),
+ * 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
@@ -325,19 +326,20 @@ function make_section_in_url($params)
}
else
{
- $section_string.= '/category/'.$params['category'];
- if ($conf['category_url_style']=='id-name' and isset($params['cat_name']) )
+ is_array($params['category']) or trigger_error(
+ 'make_section_in_url wrong type for category', E_USER_WARNING
+ );
+ is_numeric($params['category']['id']) or trigger_error(
+ 'make_section_in_url category id not numeric', E_USER_WARNING
+ );
+ isset($params['category']['name']) or trigger_error(
+ 'make_section_in_url category name not set', E_USER_WARNING
+ );
+
+ $section_string.= '/category/'.$params['category']['id'];
+ if ( $conf['category_url_style']=='id-name' )
{
- if ( is_string($params['cat_name']) )
- {
- $section_string.= '-'.str2url($params['cat_name']);
- }
- elseif ( is_array( $params['cat_name'] ) and
- isset( $params['cat_name'][$params['category']] ) )
- {
- $section_string.= '-'
- .str2url($params['cat_name'][$params['category']]);
- }
+ $section_string.= '-'.str2url($params['category']['name']);
}
}
diff --git a/include/menubar.inc.php b/include/menubar.inc.php
index d38290704..1ddc59882 100644
--- a/include/menubar.inc.php
+++ b/include/menubar.inc.php
@@ -4,7 +4,6 @@
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
// | file : $Id$
// | last update : $Date$
// | last modifier : $Author$
@@ -333,9 +332,9 @@ $template->assign_block_vars(
)
);
-if (isset($page['category']) and $page['cat_uploadable'] )
+if (isset($page['category']) and $page['category']['uploadable'] )
{ // upload a picture in the category
- $url = get_root_url().'upload.php?cat='.$page['category'];
+ $url = get_root_url().'upload.php?cat='.$page['category']['id'];
$template->assign_block_vars(
'upload',
array(
diff --git a/include/section_init.inc.php b/include/section_init.inc.php
index 4239ebd93..4434ec542 100644
--- a/include/section_init.inc.php
+++ b/include/section_init.inc.php
@@ -34,15 +34,14 @@
*
*/
-// "index.php?/category/12-foo/start-24&action=fill_caddie" or
-// "index.php/category/12-foo/start-24&action=fill_caddie"
+// "index.php?/category/12-foo/start-24" or
+// "index.php/category/12-foo/start-24"
// must return :
//
// array(
// 'section' => 'categories',
-// 'category' => 12,
+// 'category' => array('id'=>12, ...),
// 'start' => 24
-// 'action' => 'fill_caddie'
// );
$page['items'] = array();
@@ -87,7 +86,7 @@ if (script_basename() == 'picture') // basename without file extention
{// url compatibility with versions below 1.6
$url = make_picture_url( array(
'section' => 'categories',
- 'category' => $_GET['cat'],
+ 'category' => get_cat_info($_GET['cat']),
'image_id' => $_GET['image_id']
) );
redirect($url);
@@ -360,15 +359,9 @@ if ('categories' == $page['section'])
$page,
array(
'comment' => $result['comment'],
- 'cat_dir' => $result['dir'],
- 'cat_name' => $result['name'],
- 'cat_site_id' => $result['site_id'],
- 'cat_uploadable' => $result['uploadable'],
- 'cat_commentable' => $result['commentable'],
- 'cat_id_uppercat' => $result['id_uppercat'],
- 'uppercats' => $result['uppercats'],
+ 'category' => $result,
'title' =>
- get_cat_display_name($result['name'], '', false),
+ get_cat_display_name($result['upper_names'], '', false),
)
);
}
@@ -395,7 +388,7 @@ if ('categories' == $page['section'])
{// flat categories mode
if ( isset($page['category']) )
{
- $subcat_ids = get_subcat_ids( array($page['category']) );
+ $subcat_ids = get_subcat_ids( array($page['category']['id']) );
$where_sql = 'category_id IN ('.implode(',',$subcat_ids).')';
}
else
@@ -405,7 +398,7 @@ if ('categories' == $page['section'])
}
else
{// Normal mode
- $where_sql = 'category_id = '.$page['category'];
+ $where_sql = 'category_id = '.$page['category']['id'];
}
// Main query
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index e19966673..c8e2a0fe0 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -386,14 +386,12 @@ LIMIT '.$params['per_page']*$params['page'].','.$params['per_page'];
{
$url = make_index_url(
array(
- 'category' => $cat_id,
- 'cat_name' => $cats[$cat_id]['name'],
+ 'category' => $cats[$cat_id],
)
);
$page_url = make_picture_url(
array(
- 'category' => $cat_id,
- 'cat_name' => $cats[$cat_id]['name'],
+ 'category' => $cats[$cat_id],
'image_id' => $row['id'],
'image_file' => $row['file'],
)
@@ -484,8 +482,7 @@ ORDER BY global_rank';
{
$row['url'] = make_index_url(
array(
- 'category' => $row['id'],
- 'cat_name' => $row['name'],
+ 'category' => $row
)
);
foreach( array('id','nb_images','total_nb_images','nb_categories') as $key)
@@ -599,7 +596,7 @@ LIMIT 1;';
//-------------------------------------------------------- related categories
$query = '
-SELECT id,name,uppercats,global_rank,commentable
+SELECT id, name, uppercats, global_rank, commentable
FROM '.IMAGE_CATEGORY_TABLE.'
INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
WHERE image_id = '.$image_row['id'].'
@@ -617,8 +614,7 @@ SELECT id,name,uppercats,global_rank,commentable
unset($row['commentable']);
$row['url'] = make_index_url(
array(
- 'category' => $row['id'],
- 'cat_name' => $row['name'],
+ 'category' => $row
)
);
@@ -626,8 +622,7 @@ SELECT id,name,uppercats,global_rank,commentable
array(
'image_id' => $image_row['id'],
'image_file' => $image_row['file'],
- 'category' => $row['id'],
- 'cat_name' => $row['name'],
+ 'category' => $row
)
);
$row['id']=(int)$row['id'];