From 7397c8d4c23533e2e33caae273da83ada3970b23 Mon Sep 17 00:00:00 2001 From: rvelices Date: Thu, 11 Jan 2007 05:10:16 +0000 Subject: - better code in filter.inc.php (remove unused code + filter is not reseted when going to an unfiltered page) - removed unnecessary filtered pages from config_default (especially admin !!!) - removed flat recent category icon from irrelevant pages - mysterious code comment appeared in picture.php git-svn-id: http://piwigo.org/svn/trunk@1711 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/config_default.inc.php | 6 +- include/filter.inc.php | 247 ++++++++++++++++++------------------- include/functions_metadata.inc.php | 8 +- include/section_init.inc.php | 49 +++----- include/ws_functions.inc.php | 64 ++++++---- index.php | 6 +- picture.php | 2 +- 7 files changed, 180 insertions(+), 202 deletions(-) diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 2f61f5584..497c2d4f1 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -573,10 +573,8 @@ $conf['enable_plugins']=true; // Array of basename without file extention $conf['filter_pages'] = array ( - 'about', 'action', 'admin', 'comments', - 'index', 'picture', 'popuphelp', 'profile', - 'qsearch', 'random', 'register', 'search', - 'search_rules', 'tags', 'upload' + 'comments', 'index', 'picture', 'qsearch', + 'random', 'search', 'tags', 'upload' ); ?> diff --git a/include/filter.inc.php b/include/filter.inc.php index f5ea3cd4f..46edd3039 100644 --- a/include/filter.inc.php +++ b/include/filter.inc.php @@ -1,130 +1,117 @@ - SUBDATE( - CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'; - - $filter['visible_images'] = implode(',', array_from_query($query, 'image_id')); - - if (empty($filter['visible_images'])) - { - // Must be not empty - $filter['visible_images'] = -1; - } - - } - else - { - // Read only data - $filter['check_key'] = pwg_get_session_var('filter_check_key', ''); - $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array()))); - $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', ''); - $filter['visible_images'] = pwg_get_session_var('filter_visible_images', ''); - } - - $header_notes[] = l10n_dec('note_filter_day', 'note_filter_days', $user['recent_period']); -} -else -{ - $filter['check_key'] = ''; - $filter['categories'] = array(); - $filter['visible_categories'] = ''; - $filter['visible_images'] = ''; -} - -pwg_set_session_var('filter_enabled', $filter['enabled']); -pwg_set_session_var('filter_check_key', $filter['check_key']); -pwg_set_session_var('filter_categories', serialize($filter['categories'])); -pwg_set_session_var('filter_visible_categories', $filter['visible_categories']); -pwg_set_session_var('filter_visible_images', $filter['visible_images']); - -?> + SUBDATE( + CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)'; + + $filter['visible_images'] = implode(',', array_from_query($query, 'image_id')); + + if (empty($filter['visible_images'])) + { + // Must be not empty + $filter['visible_images'] = -1; + } + + pwg_set_session_var('filter_enabled', $filter['enabled']); + pwg_set_session_var('filter_check_key', $filter['check_key']); + pwg_set_session_var('filter_categories', serialize($filter['categories'])); + pwg_set_session_var('filter_visible_categories', $filter['visible_categories']); + pwg_set_session_var('filter_visible_images', $filter['visible_images']); + } + else + { + // Read only data + $filter['check_key'] = pwg_get_session_var('filter_check_key', ''); + $filter['categories'] = unserialize(pwg_get_session_var('filter_categories', serialize(array()))); + $filter['visible_categories'] = pwg_get_session_var('filter_visible_categories', ''); + $filter['visible_images'] = pwg_get_session_var('filter_visible_images', ''); + } + $header_notes[] = l10n_dec('note_filter_day', 'note_filter_days', $user['recent_period']); + } // end if filter enabled +} // end if script_basename ... +?> \ No newline at end of file diff --git a/include/functions_metadata.inc.php b/include/functions_metadata.inc.php index 4a655c37c..aa162e14b 100644 --- a/include/functions_metadata.inc.php +++ b/include/functions_metadata.inc.php @@ -36,11 +36,11 @@ function get_iptc_data($filename, $map) { $result = array(); - // Read IPTC data - $iptc = array(); - $imginfo = array(); - getimagesize($filename, $imginfo); + if (false == @getimagesize($filename, $imginfo) ) + { + return $result; + } if (isset($imginfo['APP13'])) { diff --git a/include/section_init.inc.php b/include/section_init.inc.php index 3e2e39187..cb963f3e1 100644 --- a/include/section_init.inc.php +++ b/include/section_init.inc.php @@ -278,7 +278,8 @@ while (isset($tokens[$i])) $page['start'] = $matches[1]; } - if (preg_match('/^flat_recent_cat-(\d+)/', $tokens[$i], $matches)) + if ('categories'==$page['section'] and + preg_match('/^flat_recent_cat-(\d+)/', $tokens[$i], $matches)) { // indicate a special list of images $page['flat_recent_cat'] = $matches[1]; @@ -326,6 +327,16 @@ if (pwg_get_session_var('image_order',0) > 0) $page['super_order_by'] = true; } +$forbidden = get_sql_condition_FandF( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'image_id' + ), + 'AND' + ); + // +-----------------------------------------------------------------------+ // | category | // +-----------------------------------------------------------------------+ @@ -401,16 +412,7 @@ WHERE CURRENT_DATE,INTERVAL '.$page['flat_recent_cat'].' DAY)'. (isset($page['category']) ? ' AND uppercats REGEXP \'(^|,)'.$page['category'].'(,|$)\'' : '' ).' -'.get_sql_condition_FandF - ( - array - ( - 'forbidden_categories' => 'category_id', - 'visible_categories' => 'category_id', - 'visible_images' => 'image_id' - ), - 'AND' - ).' +'.$forbidden.' ;'; $where_sql = array_from_query($query, 'image_id'); @@ -429,21 +431,12 @@ WHERE { // Main query $query = ' -SELECT distinct image_id +SELECT DISTINCT(image_id) FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON id = image_id WHERE '.$where_sql.' -'.get_sql_condition_FandF - ( - array - ( - 'forbidden_categories' => 'category_id', - 'visible_categories' => 'category_id', - 'visible_images' => 'image_id' - ), - 'AND' - ).' +'.$forbidden.' '.$conf['order_by'].' ;'; @@ -458,18 +451,6 @@ SELECT distinct image_id // special sections else { - $forbidden = - get_sql_condition_FandF - ( - array - ( - 'forbidden_categories' => 'category_id', - 'visible_categories' => 'category_id', - 'visible_images' => 'image_id' - ), - 'AND' - ); - // +-----------------------------------------------------------------------+ // | tags section | // +-----------------------------------------------------------------------+ diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php index 7e1f1a1ba..849407ef2 100644 --- a/include/ws_functions.inc.php +++ b/include/ws_functions.inc.php @@ -4,10 +4,10 @@ // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | // +-----------------------------------------------------------------------+ // | branch : BSF (Best So Far) -// | file : $URL: svn+ssh://rvelices@svn.gna.org/svn/phpwebgallery/trunk/action.php $ -// | last update : $Date: 2006-12-21 18:49:12 -0500 (Thu, 21 Dec 2006) $ -// | last modifier : $Author: rvelices $ -// | revision : $Rev: 1678 $ +// | file : $Id$ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Rev$ // +-----------------------------------------------------------------------+ // | 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 | @@ -28,8 +28,8 @@ /** * returns a "standard" (for our web service) array of sql where clauses that - * filters the images (images table only) - */ + * filters the images (images table only) + */ function ws_std_image_sql_filter( $params, $tbl_name='' ) { $clauses = array(); @@ -82,7 +82,7 @@ function ws_std_image_sql_filter( $params, $tbl_name='' ) /** * returns a "standard" (for our web service) ORDER BY sql clause for images - */ + */ function ws_std_image_sql_order( $params, $tbl_name='' ) { $ret = ''; @@ -104,7 +104,7 @@ function ws_std_image_sql_order( $params, $tbl_name='' ) case 'rand': case 'random': $matches[1][$i] = 'RAND()'; break; } - $sortable_fields = array('id', 'file', 'name', 'hit', 'average_rate', + $sortable_fields = array('id', 'file', 'name', 'hit', 'average_rate', 'date_creation', 'date_available', 'RAND()' ); if ( in_array($matches[1][$i], $sortable_fields) ) { @@ -124,11 +124,11 @@ function ws_std_image_sql_order( $params, $tbl_name='' ) /** * returns an array map of urls (thumb/element) for image_row - to be returned * in a standard way by different web service methods - */ + */ function ws_std_get_urls($image_row) { $ret = array( - 'tn_url' => get_thumbnail_url($image_row), + 'tn_url' => get_thumbnail_url($image_row), 'element_url' => get_element_url($image_row) ); global $user; @@ -147,7 +147,7 @@ function ws_getVersion($params, &$service) /** * returns images per category (wb service method) - */ + */ function ws_categories_getImages($params, &$service) { @include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php'); @@ -278,7 +278,7 @@ LIMIT '.$params['per_page']*$params['page'].','.$params['per_page']; 'per_page' => $params['per_page'], 'count' => count($images) ), - WS_XML_CONTENT => new PwgNamedArray($images, 'image', + WS_XML_CONTENT => new PwgNamedArray($images, 'image', array('id', 'tn_url', 'element_url', 'file','width','height','hit') ) ) ); @@ -290,12 +290,6 @@ LIMIT '.$params['per_page']*$params['page'].','.$params['per_page']; function ws_categories_getList($params, &$service) { global $user; - - $query = ' -SELECT id, name, uppercats, global_rank, - max_date_last, count_images AS nb_images, count_categories AS nb_categories - FROM '.CATEGORIES_TABLE.' - INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ON id=cat_id'; $where = array(); $where[]= 'user_id='.$user['id']; @@ -317,13 +311,18 @@ SELECT id, name, uppercats, global_rank, if ($params['public']) { $where[] = 'status = "public"'; + $where[] = 'visible = "true"'; } else { $where[] = 'id NOT IN ('.$user['forbidden_categories'].')'; } - $query .= ' + $query = ' +SELECT id, name, uppercats, global_rank, + max_date_last, count_images AS nb_images, count_categories AS nb_categories + FROM '.CATEGORIES_TABLE.' + INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ON id=cat_id WHERE '. implode(' AND ', $where); $query .= ' @@ -349,7 +348,7 @@ ORDER BY global_rank'; usort($cats, 'global_rank_compare'); return array( 'categories' => - new PwgNamedArray($cats,'category', + new PwgNamedArray($cats,'category', array('id','url','nb_images','nb_categories','max_date_last') ) ); @@ -366,8 +365,13 @@ function ws_images_getInfo($params, &$service) } $query=' SELECT * FROM '.IMAGES_TABLE.' - WHERE id='.$params['image_id'].' + WHERE id='.$params['image_id']. + get_sql_condition_FandF( + array('visible_images' => 'id'), + ' AND' + ).' LIMIT 1'; + $image_row = mysql_fetch_assoc(pwg_query($query)); if ($image_row==null) { @@ -539,7 +543,7 @@ function ws_session_getStatus($params, &$service) function ws_tags_getList($params, &$service) { global $user; - $tags = get_available_tags(explode(',', $user['forbidden_categories'])); + $tags = get_available_tags(); if ($params['sort_by_counter']) { usort($tags, create_function('$a,$b', 'return -$a["counter"]+$b["counter"];') ); @@ -631,7 +635,15 @@ SELECT image_id, GROUP_CONCAT(tag_id) tag_ids if ( !empty($image_ids)) { $where_clauses = ws_std_image_sql_filter($params); - $where_clauses[] = 'category_id NOT IN ('.$user['forbidden_categories'].')'; + $where_clauses[] = get_sql_condition_FandF( + array + ( + 'forbidden_categories' => 'category_id', + 'visible_categories' => 'category_id', + 'visible_images' => 'i.id' + ), + '', true + ); $where_clauses[] = 'id IN ('.implode(',',$image_ids).')'; $order_by = ws_std_image_sql_order($params); if (empty($order_by)) @@ -692,8 +704,8 @@ LIMIT '.$params['per_page']*$params['page'].','.$params['per_page']; ) ); } - $image['tags'] = new PwgNamedArray($image_tags, 'tag', - array('id','url_name','url','page_url') + $image['tags'] = new PwgNamedArray($image_tags, 'tag', + array('id','url_name','url','page_url') ); array_push($images, $image); } @@ -707,7 +719,7 @@ LIMIT '.$params['per_page']*$params['page'].','.$params['per_page']; 'per_page' => $params['per_page'], 'count' => count($images) ), - WS_XML_CONTENT => new PwgNamedArray($images, 'image', + WS_XML_CONTENT => new PwgNamedArray($images, 'image', array('id', 'tn_url', 'element_url', 'file','width','height','hit') ) ) ); diff --git a/index.php b/index.php index c87f62da2..48e309633 100644 --- a/index.php +++ b/index.php @@ -2,10 +2,10 @@ // +-----------------------------------------------------------------------+ // | 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$ @@ -116,7 +116,7 @@ if (isset($page['flat_recent_cat']) or isset($page['chronology_field'])) ); } -if (!isset($page['flat_recent_cat'])) +if (!isset($page['flat_recent_cat']) and 'categories'==$page['section']) { $template->assign_block_vars( 'flat_recent_cat', diff --git a/picture.php b/picture.php index d08a2779d..61f913ceb 100644 --- a/picture.php +++ b/picture.php @@ -784,7 +784,7 @@ if (isset($_GET['slideshow'])) include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php'); include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php'); -//if ($metadata_showable and isset($_GET['metadata'])) +if ($metadata_showable and isset($_GET['metadata'])) { include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php'); } -- cgit v1.2.3