diff --git a/admin/cat_list.php b/admin/cat_list.php index 82a272639..c34754f87 100644 --- a/admin/cat_list.php +++ b/admin/cat_list.php @@ -2,10 +2,9 @@ // +-----------------------------------------------------------------------+ // | 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-2007 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ -// | branch : BSF (Best So Far) -// | file : $RCSfile$ +// | file : $Id$ // | last update : $Date$ // | last modifier : $Author$ // | revision : $Revision$ @@ -172,10 +171,8 @@ if (isset($_GET['parent_id'])) { $navigation.= $conf['level_separator']; - $current_category = get_cat_info($_GET['parent_id']); - - $navigation.= get_cat_display_name( - $current_category['name'], + $navigation.= get_cat_display_name_from_id( + $_GET['parent_id'], $base_url.'&parent_id=', false ); @@ -277,8 +274,7 @@ foreach ($categories as $category) 'U_JUMPTO' => make_index_url( array( - 'category' => $category['id'], - 'cat_name' => $category['name'], + 'category' => $category ) ), diff --git a/admin/cat_modify.php b/admin/cat_modify.php index e87a6aee5..065983070 100644 --- a/admin/cat_modify.php +++ b/admin/cat_modify.php @@ -2,10 +2,9 @@ // +-----------------------------------------------------------------------+ // | PhpWebGallery - a PHP based picture gallery | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | -// | 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$ @@ -279,8 +278,7 @@ $template->assign_vars( 'U_JUMPTO' => make_index_url( array( - 'category' => $category['id'], - 'cat_name' => $category['name'], + 'category' => $category ) ), diff --git a/admin/element_set.php b/admin/element_set.php index ee9884e31..fe005ee44 100644 --- a/admin/element_set.php +++ b/admin/element_set.php @@ -2,10 +2,9 @@ // +-----------------------------------------------------------------------+ // | 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-2007 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ -// | branch : BSF (Best So Far) -// | file : $RCSfile$ +// | file : $Id$ // | last update : $Date$ // | last modifier : $Author$ // | revision : $Revision$ @@ -109,10 +108,9 @@ DELETE if (is_numeric($_GET['cat'])) { - $cat_infos = get_cat_info($_GET['cat']); $page['title'] = - get_cat_display_name( - $cat_infos['name'], + get_cat_display_name_from_id( + $_GET['cat'], PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id=', false ); diff --git a/admin/picture_modify.php b/admin/picture_modify.php index 9f6877167..0dd6a237b 100644 --- a/admin/picture_modify.php +++ b/admin/picture_modify.php @@ -253,8 +253,8 @@ $template->assign_vars( 'TAG_SELECTION' => $tag_selection, 'DESCRIPTION' => - isset($_POST['description']) ? - stripslashes($_POST['description']) : @$row['comment'], + htmlspecialchars( isset($_POST['description']) ? + stripslashes($_POST['description']) : @$row['comment'] ), 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php' @@ -347,7 +347,7 @@ if (isset($_GET['cat_id']) array( 'image_id' => $_GET['image_id'], 'image_file' => $image_file, - 'category' => $_GET['cat_id'], + 'category' => $cache['cat_names'][ $_GET['cat_id'] ], ) ); } @@ -359,7 +359,7 @@ else array( 'image_id' => $_GET['image_id'], 'image_file' => $image_file, - 'category' => $category, + 'category' => $cache['cat_names'][ $category ], ) ); break; diff --git a/admin/waiting.php b/admin/waiting.php index 8a63ac17a..30bd6f37c 100644 --- a/admin/waiting.php +++ b/admin/waiting.php @@ -2,10 +2,9 @@ // +-----------------------------------------------------------------------+ // | 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-2007 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ -// | branch : BSF (Best So Far) -// | file : $RCSfile$ +// | file : $Id$ // | last update : $Date$ // | last modifier : $Author$ // | revision : $Revision$ @@ -161,7 +160,7 @@ while ( $row = mysql_fetch_array( $result ) ) $cat_names[$row['storage_category_id']]['dir'] = PHPWG_ROOT_PATH.get_complete_dir( $row['storage_category_id'] ); $cat_names[$row['storage_category_id']]['display_name'] = - get_cat_display_name($cat['name']); + get_cat_display_name($cat['upper_names']); } $preview_url = PHPWG_ROOT_PATH.$cat_names[$row['storage_category_id']]['dir'].$row['file']; $class='row1'; diff --git a/category.php b/category.php index 8b0ade406..16d7a127e 100644 --- a/category.php +++ b/category.php @@ -38,10 +38,11 @@ if ( isset($_GET['cat']) ) if ( is_numeric($_GET['cat']) ) { $url_params['section'] = 'categories'; - $url_params['category'] = $_GET['cat']; - $result = get_cat_info($url_params['category']); + $result = get_cat_info( $_GET['cat'] ); if ( !empty($result) ) - $url_params['cat_name'] = $result['name']; + { + $url_params['category'] = $result; + } } elseif ( in_array($_GET['cat'], array('best_rated','most_visited','recent_pics','recent_cats') diff --git a/comments.php b/comments.php index 0c0735447..9a41dcb2b 100644 --- a/comments.php +++ b/comments.php @@ -205,7 +205,7 @@ $template->assign_block_vars( )); $query = ' -SELECT id,name,uppercats,global_rank +SELECT id, name, uppercats, global_rank FROM '.CATEGORIES_TABLE.' '.get_sql_condition_FandF ( @@ -398,8 +398,7 @@ SELECT id, name, uppercats // link to the full size picture $url = make_picture_url( array( - 'category' => $comment['category_id'], - 'cat_name' => $categories[ $comment['category_id']] ['name'], + 'category' => $categories[ $comment['category_id'] ], 'image_id' => $comment['image_id'], 'image_file' => $elements[$comment['image_id']]['file'], ) 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".'