diff options
author | rvelices <rv-github@modusoptimus.com> | 2007-01-11 05:10:16 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2007-01-11 05:10:16 +0000 |
commit | 7397c8d4c23533e2e33caae273da83ada3970b23 (patch) | |
tree | 570f3cfbdb659899f26d957ffeceaf0615524c37 /include | |
parent | 2a9c48225dc8e065de71a9b077b1e935e10aa077 (diff) |
- 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
Diffstat (limited to 'include')
-rw-r--r-- | include/config_default.inc.php | 6 | ||||
-rw-r--r-- | include/filter.inc.php | 247 | ||||
-rw-r--r-- | include/functions_metadata.inc.php | 8 | ||||
-rw-r--r-- | include/section_init.inc.php | 49 | ||||
-rw-r--r-- | include/ws_functions.inc.php | 64 |
5 files changed, 176 insertions, 198 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 @@ -<?php
-// +-----------------------------------------------------------------------+
-// | PhpWebGallery - a PHP based picture gallery |
-// | Copyright (C) 2006-2007 PhpWebGallery Team - http://phpwebgallery.net |
-// +-----------------------------------------------------------------------+
-// | branch : BSF (Best So Far)
-// | file : $Id: filter.inc.php 1651 2006-12-13 00:05:16Z rub $
-// | last update : $Date: 2006-12-13 01:05:16 +0100 (mer., 13 déc. 2006) $
-// | last modifier : $Author: rub $
-// | revision : $Revision: 1651 $
-// +-----------------------------------------------------------------------+
-// | 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. |
-// +-----------------------------------------------------------------------+
-
-// global variable for filter
-$filter = array();
-
-// $filter['enabled']: Filter is enabled
-// $filter['categories']: Computed data of filtered categories
-// $filter['visible_categories']: List of visible categories (count(visible) < count(forbidden) more often)
-// $filter['visible_images']: List of visible images
-
-
-$filter['enabled'] =
- (in_array(script_basename(), $conf['filter_pages'])) and
- (
- (isset($_GET['filter']) and ($_GET['filter'] == 'start')) or
- pwg_get_session_var('filter_enabled', false)
- );
-
-if (in_array(script_basename(), $conf['filter_pages']))
-{
- if (isset($_GET['filter']))
- {
- $filter['enabled'] = ($_GET['filter'] == 'start');
- }
- else
- {
- $filter['enabled'] = pwg_get_session_var('filter_enabled', false);
- }
-}
-else
-{
- $filter['enabled'] = false;
-}
-
-if ($filter['enabled'])
-{
- if (
- // New filter
- !pwg_get_session_var('filter_enabled', false) or
- // Cache data updated
- $user['need_update_done'] or
- // Date, period, user are changed
- (pwg_get_session_var('filter_check_key', '') != get_filter_check_key())
- )
- {
- // Need to compute dats
- $filter['check_key'] = get_filter_check_key();
- $filter['categories'] = get_computed_categories($user['id'], $user['forbidden_categories'], true, $user['recent_period']);
-
- $filter['visible_categories'] = implode(',', array_keys($filter['categories']));
- if (empty($filter['visible_categories']))
- {
- // Must be not empty
- $filter['visible_categories'] = -1;
- }
-
- $query ='
-SELECT
- distinct image_id
-FROM '.
- IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id
-WHERE ';
- if (!empty($filter['visible_categories']))
- {
- $query.= '
- category_id IN ('.$filter['visible_categories'].') and';
- }
- $query.= '
- date_available > 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']);
-
-?>
+<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2006-2007 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $Id$ +// | 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. | +// +-----------------------------------------------------------------------+ + +// global variable for filter +$filter = array(); + +// $filter['enabled']: Filter is enabled +// $filter['categories']: Computed data of filtered categories +// $filter['visible_categories']: List of visible categories (count(visible) < count(forbidden) more often) +// $filter['visible_images']: List of visible images + +$filter['enabled'] = false; + +if (in_array(script_basename(), $conf['filter_pages'])) +{ // valid only on certain pages + if (isset($_GET['filter'])) + { + $filter['enabled'] = ($_GET['filter'] == 'start'); + if ( !$filter['enabled'] ) + { + pwg_unset_session_var('filter_enabled'); + pwg_unset_session_var('filter_check_key'); + pwg_unset_session_var('filter_categories'); + pwg_unset_session_var('filter_visible_categories'); + pwg_unset_session_var('filter_visible_images'); + } + } + else + { + $filter['enabled'] = pwg_get_session_var('filter_enabled', false); + } + + if ($filter['enabled']) + { + if ( + // New filter + !pwg_get_session_var('filter_enabled', false) or + // Cache data updated + $user['need_update_done'] or + // Date, period, user are changed + (pwg_get_session_var('filter_check_key', '') != get_filter_check_key()) + ) + { + // Need to compute dats + $filter['check_key'] = get_filter_check_key(); + $filter['categories'] = get_computed_categories($user['id'], $user['forbidden_categories'], true, $user['recent_period']); + + $filter['visible_categories'] = implode(',', array_keys($filter['categories'])); + if (empty($filter['visible_categories'])) + { + // Must be not empty + $filter['visible_categories'] = -1; + } + + $query =' +SELECT DISTINCT(image_id) + FROM '. + IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id = id + WHERE '; + if (!empty($filter['visible_categories'])) + { + $query.= ' + category_id IN ('.$filter['visible_categories'].') AND'; + } + $query.= ' + date_available > 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') ) ) ); |