From 47512ce6a64fa356214c162a8313480c6aed41d2 Mon Sep 17 00:00:00 2001 From: rvelices Date: Tue, 27 Feb 2007 01:56:16 +0000 Subject: - 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 --- include/category_cats.inc.php | 12 ++++---- include/category_default.inc.php | 2 +- include/functions.inc.php | 3 +- include/functions_calendar.inc.php | 12 ++++---- include/functions_category.inc.php | 47 ++++++++++++------------------ include/functions_html.inc.php | 59 +++++++++++++++++--------------------- include/functions_url.inc.php | 34 +++++++++++----------- include/menubar.inc.php | 5 ++-- include/section_init.inc.php | 23 ++++++--------- include/ws_functions.inc.php | 17 ++++------- 10 files changed, 91 insertions(+), 123 deletions(-) (limited to 'include') 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 @@ $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.= ''; - $output.= $name.''; + $output.= $cat['name'].''; } else { $output.= ''; - $output.= $name.''; + $output.= $cat['name'].''; } } 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 '.$name.''; + .'">'.$cat['name'].''; } else { $output.= ' -'.$name.''; +'.$cat['name'].''; } } 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".'$category['id'], - 'cat_name'=>$category['name'] + 'category' => $category ) ); $menu.= "\n".' 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']; -- cgit v1.2.3