2003-05-09 14:42:42 +02:00
|
|
|
<?php
|
2004-02-12 00:20:38 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-06 22:12:59 +01:00
|
|
|
// | PhpWebGallery - a PHP based picture gallery |
|
|
|
|
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
|
2005-01-08 00:10:51 +01:00
|
|
|
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
|
2004-02-12 00:20:38 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-06 22:12:59 +01:00
|
|
|
// | branch : BSF (Best So Far)
|
2004-02-12 00:20:38 +01:00
|
|
|
// | file : $RCSfile$
|
|
|
|
// | 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. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2003-07-01 11:27:20 +02:00
|
|
|
|
2004-05-28 23:56:07 +02:00
|
|
|
/**
|
|
|
|
* Provides functions to handle categories.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Is the category accessible to the connected user ?
|
|
|
|
*
|
|
|
|
* Note : if the user is not authorized to see this category, page creation
|
|
|
|
* ends (exit command in this function)
|
|
|
|
*
|
|
|
|
* @param int category id to verify
|
|
|
|
* @return void
|
|
|
|
*/
|
2005-08-08 22:52:19 +02:00
|
|
|
function check_restrictions($category_id)
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2005-08-08 22:52:19 +02:00
|
|
|
global $user, $lang;
|
2003-05-09 14:42:42 +02:00
|
|
|
|
2005-08-08 22:52:19 +02:00
|
|
|
if (in_array($category_id, explode(',', $user['forbidden_categories'])))
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
|
|
|
echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
|
2006-01-15 14:45:42 +01:00
|
|
|
echo '<a href="./category.php">';
|
2003-05-09 14:42:42 +02:00
|
|
|
echo $lang['thumbnails'].'</a></div>';
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
2004-02-02 01:55:18 +01:00
|
|
|
|
2004-05-28 23:56:07 +02:00
|
|
|
/**
|
|
|
|
* Checks whether the argument is a right parameter category id
|
|
|
|
*
|
|
|
|
* The argument is a right parameter if corresponds to one of these :
|
|
|
|
*
|
|
|
|
* - is numeric and corresponds to a category in the database
|
2004-06-15 22:02:03 +02:00
|
|
|
* - equals 'fav' (for favorites)
|
|
|
|
* - equals 'search' (when the result of a search is displayed)
|
|
|
|
* - equals 'most_visited'
|
|
|
|
* - equals 'best_rated'
|
2004-06-19 01:24:40 +02:00
|
|
|
* - equals 'recent_pics'
|
|
|
|
* - equals 'recent_cats'
|
2004-09-01 23:39:29 +02:00
|
|
|
* - equals 'calendar'
|
2004-11-16 00:13:24 +01:00
|
|
|
* - equals 'list'
|
2004-05-28 23:56:07 +02:00
|
|
|
*
|
|
|
|
* The function fills the global var $page['cat'] and returns nothing
|
|
|
|
*
|
|
|
|
* @param mixed category id or special category name
|
|
|
|
* @return void
|
|
|
|
*/
|
2003-05-09 14:42:42 +02:00
|
|
|
function check_cat_id( $cat )
|
|
|
|
{
|
2003-05-17 13:42:03 +02:00
|
|
|
global $page;
|
|
|
|
|
2003-05-09 14:42:42 +02:00
|
|
|
unset( $page['cat'] );
|
|
|
|
if ( isset( $cat ) )
|
|
|
|
{
|
2004-02-02 01:55:18 +01:00
|
|
|
if ( isset( $page['plain_structure'][$cat] ) )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2004-02-02 01:55:18 +01:00
|
|
|
$page['cat'] = $cat;
|
2003-07-21 21:47:14 +02:00
|
|
|
}
|
|
|
|
else if ( is_numeric( $cat ) )
|
|
|
|
{
|
|
|
|
$query = 'SELECT id';
|
2004-02-02 01:55:18 +01:00
|
|
|
$query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$cat.';';
|
2004-10-30 17:42:29 +02:00
|
|
|
$result = pwg_query( $query );
|
2003-05-09 14:42:42 +02:00
|
|
|
if ( mysql_num_rows( $result ) != 0 )
|
|
|
|
{
|
|
|
|
$page['cat'] = $cat;
|
|
|
|
}
|
|
|
|
}
|
2003-07-21 21:47:14 +02:00
|
|
|
if ( $cat == 'fav'
|
|
|
|
or $cat == 'most_visited'
|
|
|
|
or $cat == 'best_rated'
|
2004-06-16 22:36:24 +02:00
|
|
|
or $cat == 'recent_pics'
|
2004-06-19 01:24:40 +02:00
|
|
|
or $cat == 'recent_cats'
|
2004-11-16 00:13:24 +01:00
|
|
|
or $cat == 'calendar' )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
|
|
|
$page['cat'] = $cat;
|
|
|
|
}
|
2006-01-20 15:34:37 +01:00
|
|
|
if ($cat == 'search'
|
|
|
|
and isset($_GET['search'])
|
|
|
|
and is_numeric($_GET['search']))
|
2004-07-26 22:45:12 +02:00
|
|
|
{
|
|
|
|
$page['cat'] = $cat;
|
|
|
|
}
|
2004-11-16 00:13:24 +01:00
|
|
|
if ($cat == 'list'
|
|
|
|
and isset($_GET['list'])
|
|
|
|
and preg_match('/^\d+(,\d+)*$/', $_GET['list']))
|
|
|
|
{
|
|
|
|
$page['cat'] = 'list';
|
|
|
|
}
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-23 23:31:24 +01:00
|
|
|
function get_categories_menu()
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2004-02-02 01:55:18 +01:00
|
|
|
global $page,$user;
|
|
|
|
|
2004-11-23 23:31:24 +01:00
|
|
|
$infos = array('');
|
2003-05-09 14:42:42 +02:00
|
|
|
|
2004-11-01 16:01:28 +01:00
|
|
|
$query = '
|
2004-11-23 23:31:24 +01:00
|
|
|
SELECT name,id,date_last,nb_images,global_rank
|
2004-11-01 16:01:28 +01:00
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE 1 = 1'; // stupid but permit using AND after it !
|
|
|
|
if (!$user['expand'])
|
2004-02-02 01:55:18 +01:00
|
|
|
{
|
2004-11-01 16:01:28 +01:00
|
|
|
$query.= '
|
|
|
|
AND (id_uppercat is NULL';
|
|
|
|
if (isset ($page['tab_expand']) and count($page['tab_expand']) > 0)
|
2004-02-02 01:55:18 +01:00
|
|
|
{
|
2004-03-05 23:55:04 +01:00
|
|
|
$query.= ' OR id_uppercat IN ('.implode(',',$page['tab_expand']).')';
|
2004-02-02 01:55:18 +01:00
|
|
|
}
|
|
|
|
$query.= ')';
|
|
|
|
}
|
2004-11-01 16:01:28 +01:00
|
|
|
if ($user['forbidden_categories'] != '')
|
2004-02-02 01:55:18 +01:00
|
|
|
{
|
2004-11-01 16:01:28 +01:00
|
|
|
$query.= '
|
|
|
|
AND id NOT IN ('.$user['forbidden_categories'].')';
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2004-11-01 16:01:28 +01:00
|
|
|
$query.= '
|
|
|
|
;';
|
2003-07-21 21:47:14 +02:00
|
|
|
|
2004-11-01 16:01:28 +01:00
|
|
|
$result = pwg_query($query);
|
2004-11-23 23:31:24 +01:00
|
|
|
$cats = array();
|
2004-11-01 16:01:28 +01:00
|
|
|
while ($row = mysql_fetch_array($result))
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2004-11-23 23:31:24 +01:00
|
|
|
array_push($cats, $row);
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2004-11-23 23:31:24 +01:00
|
|
|
usort($cats, 'global_rank_compare');
|
2003-07-21 21:47:14 +02:00
|
|
|
|
2004-11-23 23:31:24 +01:00
|
|
|
return get_html_menu_category($cats);
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
|
|
|
|
2005-03-31 23:53:24 +02:00
|
|
|
/**
|
|
|
|
* returns the total number of elements viewable in the gallery by the
|
|
|
|
* connected user
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2004-02-02 01:55:18 +01:00
|
|
|
function count_user_total_images()
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
|
2005-03-31 23:53:24 +02:00
|
|
|
$query = '
|
|
|
|
SELECT COUNT(DISTINCT(image_id)) as total
|
2005-08-08 22:52:19 +02:00
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
WHERE category_id NOT IN ('.$user['forbidden_categories'].')
|
2005-03-31 23:53:24 +02:00
|
|
|
;';
|
2005-08-08 22:52:19 +02:00
|
|
|
list($total) = mysql_fetch_array(pwg_query($query));
|
|
|
|
|
|
|
|
return $total;
|
2004-02-02 01:55:18 +01:00
|
|
|
}
|
|
|
|
|
2004-05-28 23:56:07 +02:00
|
|
|
/**
|
|
|
|
* Retrieve informations about a category in the database
|
|
|
|
*
|
|
|
|
* Returns an array with following keys :
|
|
|
|
*
|
|
|
|
* - comment
|
|
|
|
* - dir : directory, might be empty for virtual categories
|
|
|
|
* - name : an array with indexes from 0 (lowest cat name) to n (most
|
|
|
|
* uppercat name findable)
|
|
|
|
* - nb_images
|
|
|
|
* - id_uppercat
|
|
|
|
* - site_id
|
|
|
|
* -
|
|
|
|
*
|
|
|
|
* @param int category id
|
|
|
|
* @return array
|
|
|
|
*/
|
2003-05-09 14:42:42 +02:00
|
|
|
function get_cat_info( $id )
|
|
|
|
{
|
2004-11-15 22:42:08 +01:00
|
|
|
$infos = array('nb_images','id_uppercat','comment','site_id'
|
|
|
|
,'dir','date_last','uploadable','status','visible'
|
|
|
|
,'representative_picture_id','uppercats','commentable');
|
|
|
|
|
|
|
|
$query = '
|
|
|
|
SELECT '.implode(',', $infos).'
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE id = '.$id.'
|
|
|
|
;';
|
|
|
|
$row = mysql_fetch_array(pwg_query($query));
|
2003-07-25 23:33:41 +02:00
|
|
|
|
2004-02-02 01:55:18 +01:00
|
|
|
$cat = array();
|
2004-11-15 22:42:08 +01:00
|
|
|
foreach ($infos as $info)
|
|
|
|
{
|
|
|
|
if (isset($row[$info]))
|
|
|
|
{
|
|
|
|
$cat[$info] = $row[$info];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$cat[$info] = '';
|
|
|
|
}
|
2004-02-02 01:55:18 +01:00
|
|
|
// If the field is true or false, the variable is transformed into a
|
|
|
|
// boolean value.
|
2004-11-15 22:42:08 +01:00
|
|
|
if ($cat[$info] == 'true' or $cat[$info] == 'false')
|
2004-02-02 01:55:18 +01:00
|
|
|
{
|
|
|
|
$cat[$info] = get_boolean( $cat[$info] );
|
|
|
|
}
|
|
|
|
}
|
2004-11-15 22:42:08 +01:00
|
|
|
$cat['comment'] = nl2br($cat['comment']);
|
2003-09-06 09:22:59 +02:00
|
|
|
|
2005-01-06 23:16:21 +01:00
|
|
|
$names = array();
|
2004-11-15 22:42:08 +01:00
|
|
|
$query = '
|
|
|
|
SELECT name,id
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE id IN ('.$cat['uppercats'].')
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
while($row = mysql_fetch_array($result))
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2005-01-06 23:16:21 +01:00
|
|
|
$names[$row['id']] = $row['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// category names must be in the same order than uppercats list
|
|
|
|
$cat['name'] = array();
|
|
|
|
foreach (explode(',', $cat['uppercats']) as $cat_id)
|
|
|
|
{
|
|
|
|
$cat['name'][$cat_id] = $names[$cat_id];
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2004-02-02 01:55:18 +01:00
|
|
|
|
2003-05-09 14:42:42 +02:00
|
|
|
return $cat;
|
|
|
|
}
|
2003-08-30 17:54:37 +02:00
|
|
|
|
|
|
|
// get_complete_dir returns the concatenation of get_site_url and
|
|
|
|
// get_local_dir
|
|
|
|
// Example : "pets > rex > 1_year_old" is on the the same site as the
|
|
|
|
// PhpWebGallery files and this category has 22 for identifier
|
|
|
|
// get_complete_dir(22) returns "./galleries/pets/rex/1_year_old/"
|
|
|
|
function get_complete_dir( $category_id )
|
|
|
|
{
|
2004-10-23 19:56:46 +02:00
|
|
|
return get_site_url($category_id).get_local_dir($category_id);
|
2003-08-30 17:54:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// get_local_dir returns an array with complete path without the site url
|
|
|
|
// Example : "pets > rex > 1_year_old" is on the the same site as the
|
|
|
|
// PhpWebGallery files and this category has 22 for identifier
|
|
|
|
// get_local_dir(22) returns "pets/rex/1_year_old/"
|
|
|
|
function get_local_dir( $category_id )
|
|
|
|
{
|
|
|
|
global $page;
|
|
|
|
|
2004-02-02 01:55:18 +01:00
|
|
|
$uppercats = '';
|
|
|
|
$local_dir = '';
|
|
|
|
|
|
|
|
if ( isset( $page['plain_structure'][$category_id]['uppercats'] ) )
|
|
|
|
{
|
|
|
|
$uppercats = $page['plain_structure'][$category_id]['uppercats'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$query = 'SELECT uppercats';
|
|
|
|
$query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$category_id;
|
|
|
|
$query.= ';';
|
2004-10-30 17:42:29 +02:00
|
|
|
$row = mysql_fetch_array( pwg_query( $query ) );
|
2004-02-02 01:55:18 +01:00
|
|
|
$uppercats = $row['uppercats'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$upper_array = explode( ',', $uppercats );
|
|
|
|
|
|
|
|
$database_dirs = array();
|
|
|
|
$query = 'SELECT id,dir';
|
|
|
|
$query.= ' FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$uppercats.')';
|
|
|
|
$query.= ';';
|
2004-10-30 17:42:29 +02:00
|
|
|
$result = pwg_query( $query );
|
2004-02-02 01:55:18 +01:00
|
|
|
while( $row = mysql_fetch_array( $result ) )
|
2003-08-30 17:54:37 +02:00
|
|
|
{
|
2004-02-02 01:55:18 +01:00
|
|
|
$database_dirs[$row['id']] = $row['dir'];
|
|
|
|
}
|
2004-10-23 19:56:46 +02:00
|
|
|
foreach ($upper_array as $id)
|
|
|
|
{
|
2004-02-02 01:55:18 +01:00
|
|
|
$local_dir.= $database_dirs[$id].'/';
|
2003-08-30 17:54:37 +02:00
|
|
|
}
|
2004-02-02 01:55:18 +01:00
|
|
|
|
|
|
|
return $local_dir;
|
2003-08-30 17:54:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// retrieving the site url : "http://domain.com/gallery/" or
|
|
|
|
// simply "./galleries/"
|
2004-10-23 19:56:46 +02:00
|
|
|
function get_site_url($category_id)
|
2003-08-30 17:54:37 +02:00
|
|
|
{
|
|
|
|
global $page;
|
|
|
|
|
2004-10-23 19:56:46 +02:00
|
|
|
$query = '
|
|
|
|
SELECT galleries_url
|
|
|
|
FROM '.SITES_TABLE.' AS s,'.CATEGORIES_TABLE.' AS c
|
|
|
|
WHERE s.id = c.site_id
|
|
|
|
AND c.id = '.$category_id.'
|
|
|
|
;';
|
2004-10-30 17:42:29 +02:00
|
|
|
$row = mysql_fetch_array(pwg_query($query));
|
2003-08-30 17:54:37 +02:00
|
|
|
return $row['galleries_url'];
|
|
|
|
}
|
|
|
|
|
2006-02-01 03:46:26 +01:00
|
|
|
// returns an array of image orders available for users/visitors
|
|
|
|
function get_category_preferred_image_orders()
|
|
|
|
{
|
2006-02-08 02:17:07 +01:00
|
|
|
global $conf;
|
2006-02-01 03:46:26 +01:00
|
|
|
return array(
|
|
|
|
array('Default', '', true),
|
2006-02-08 02:17:07 +01:00
|
|
|
array(get_lang('best_rated_cat'), 'average_rate DESC', $conf['rate']),
|
|
|
|
array(get_lang('most_visited_cat'), 'hit DESC', true),
|
|
|
|
array(get_lang('Creation date'), 'date_creation DESC', true),
|
|
|
|
array(get_lang('Availability date'), 'date_available DESC', true),
|
|
|
|
array(get_lang('File name'), 'file ASC', true)
|
2006-02-01 03:46:26 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-09 14:42:42 +02:00
|
|
|
// initialize_category initializes ;-) the variables in relation
|
|
|
|
// with category :
|
|
|
|
// 1. calculation of the number of pictures in the category
|
|
|
|
// 2. determination of the SQL query part to ask to find the right category
|
|
|
|
// $page['where'] is not the same if we are in
|
|
|
|
// - simple category
|
|
|
|
// - search result
|
|
|
|
// - favorites displaying
|
|
|
|
// - most visited pictures
|
|
|
|
// - best rated pictures
|
|
|
|
// - recent pictures
|
2004-11-16 00:13:24 +01:00
|
|
|
// - defined list (used for random)
|
2003-05-09 14:42:42 +02:00
|
|
|
// 3. determination of the title of the page
|
|
|
|
// 4. creation of the navigation bar
|
|
|
|
function initialize_category( $calling_page = 'category' )
|
|
|
|
{
|
2004-02-02 01:55:18 +01:00
|
|
|
pwg_debug( 'start initialize_category' );
|
2003-05-17 13:42:03 +02:00
|
|
|
global $page,$lang,$user,$conf;
|
2003-07-25 23:33:41 +02:00
|
|
|
|
2003-05-09 14:42:42 +02:00
|
|
|
if ( isset( $page['cat'] ) )
|
|
|
|
{
|
|
|
|
// $page['nb_image_page'] is the number of picture to display on this page
|
|
|
|
// By default, it is the same as the $user['nb_image_page']
|
|
|
|
$page['nb_image_page'] = $user['nb_image_page'];
|
|
|
|
// $url is used to create the navigation bar
|
2004-11-25 15:12:33 +01:00
|
|
|
$url = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'];
|
2004-02-02 01:55:18 +01:00
|
|
|
if ( isset($page['expand']) ) $url.= '&expand='.$page['expand'];
|
2003-05-09 14:42:42 +02:00
|
|
|
// simple category
|
|
|
|
if ( is_numeric( $page['cat'] ) )
|
|
|
|
{
|
|
|
|
$result = get_cat_info( $page['cat'] );
|
2003-07-25 23:33:41 +02:00
|
|
|
$page['comment'] = $result['comment'];
|
|
|
|
$page['cat_dir'] = $result['dir'];
|
|
|
|
$page['cat_name'] = $result['name'];
|
|
|
|
$page['cat_nb_images'] = $result['nb_images'];
|
|
|
|
$page['cat_site_id'] = $result['site_id'];
|
|
|
|
$page['cat_uploadable'] = $result['uploadable'];
|
2004-11-13 14:43:53 +01:00
|
|
|
$page['cat_commentable'] = $result['commentable'];
|
2004-02-02 01:55:18 +01:00
|
|
|
$page['uppercats'] = $result['uppercats'];
|
2004-12-07 00:49:58 +01:00
|
|
|
$page['title'] =
|
|
|
|
get_cat_display_name($page['cat_name'],
|
2004-12-23 13:30:03 +01:00
|
|
|
'',
|
2004-12-07 00:49:58 +01:00
|
|
|
false);
|
2003-08-30 17:54:37 +02:00
|
|
|
$page['where'] = ' WHERE category_id = '.$page['cat'];
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-11-16 00:13:24 +01:00
|
|
|
if ($page['cat'] == 'search'
|
|
|
|
or $page['cat'] == 'most_visited'
|
|
|
|
or $page['cat'] == 'recent_pics'
|
|
|
|
or $page['cat'] == 'recent_cats'
|
|
|
|
or $page['cat'] == 'best_rated'
|
|
|
|
or $page['cat'] == 'calendar'
|
|
|
|
or $page['cat'] == 'list')
|
2003-05-25 10:31:39 +02:00
|
|
|
{
|
|
|
|
// we must not show pictures of a forbidden category
|
2004-02-02 01:55:18 +01:00
|
|
|
if ( $user['forbidden_categories'] != '' )
|
2003-09-06 09:22:59 +02:00
|
|
|
{
|
2004-02-02 01:55:18 +01:00
|
|
|
$forbidden = ' category_id NOT IN ';
|
|
|
|
$forbidden.= '('.$user['forbidden_categories'].')';
|
2003-05-25 10:31:39 +02:00
|
|
|
}
|
|
|
|
}
|
2003-05-09 14:42:42 +02:00
|
|
|
// search result
|
|
|
|
if ( $page['cat'] == 'search' )
|
|
|
|
{
|
|
|
|
$page['title'] = $lang['search_result'];
|
|
|
|
if ( $calling_page == 'picture' )
|
|
|
|
{
|
|
|
|
$page['title'].= ' : <span style="font-style:italic;">';
|
|
|
|
$page['title'].= $_GET['search']."</span>";
|
|
|
|
}
|
2003-05-25 10:31:39 +02:00
|
|
|
|
2006-01-20 15:34:37 +01:00
|
|
|
$page['where'] = 'WHERE '.get_sql_search_clause($_GET['search']);
|
2004-12-05 12:47:40 +01:00
|
|
|
|
2006-01-20 15:34:37 +01:00
|
|
|
if (isset($forbidden))
|
2005-01-20 00:52:59 +01:00
|
|
|
{
|
2006-01-20 15:34:37 +01:00
|
|
|
$page['where'].= "\n AND ".$forbidden;
|
2005-01-20 00:52:59 +01:00
|
|
|
}
|
2004-12-05 12:47:40 +01:00
|
|
|
|
2004-07-26 22:45:12 +02:00
|
|
|
$query = '
|
|
|
|
SELECT COUNT(DISTINCT(id)) AS nb_total_images
|
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
|
|
|
|
'.$page['where'].'
|
|
|
|
;';
|
|
|
|
$url.= '&search='.$_GET['search'];
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
|
|
|
// favorites displaying
|
|
|
|
else if ( $page['cat'] == 'fav' )
|
|
|
|
{
|
2004-12-18 23:05:30 +01:00
|
|
|
check_user_favorites();
|
|
|
|
|
2003-05-09 14:42:42 +02:00
|
|
|
$page['title'] = $lang['favorites'];
|
|
|
|
|
2004-02-02 01:55:18 +01:00
|
|
|
$page['where'] = ', '.FAVORITES_TABLE.' AS fav';
|
2003-05-21 23:45:46 +02:00
|
|
|
$page['where'].= ' WHERE user_id = '.$user['id'];
|
2003-09-05 21:27:45 +02:00
|
|
|
$page['where'].= ' AND fav.image_id = id';
|
2003-05-09 14:42:42 +02:00
|
|
|
|
2003-05-21 23:45:46 +02:00
|
|
|
$query = 'SELECT COUNT(*) AS nb_total_images';
|
2004-02-02 01:55:18 +01:00
|
|
|
$query.= ' FROM '.FAVORITES_TABLE;
|
2003-05-21 23:45:46 +02:00
|
|
|
$query.= ' WHERE user_id = '.$user['id'];
|
2003-05-09 14:42:42 +02:00
|
|
|
$query.= ';';
|
|
|
|
}
|
|
|
|
// pictures within the short period
|
2004-06-16 22:36:24 +02:00
|
|
|
else if ( $page['cat'] == 'recent_pics' )
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2004-08-26 00:25:58 +02:00
|
|
|
$page['title'] = $lang['recent_pics_cat'];
|
2003-05-09 14:42:42 +02:00
|
|
|
// We must find the date corresponding to :
|
|
|
|
// today - $conf['periode_courte']
|
2004-07-27 08:36:42 +02:00
|
|
|
$date = time() - 60*60*24*$user['recent_period'];
|
2003-05-21 23:45:46 +02:00
|
|
|
$page['where'] = " WHERE date_available > '";
|
2003-05-09 14:42:42 +02:00
|
|
|
$page['where'].= date( 'Y-m-d', $date )."'";
|
2004-02-02 01:55:18 +01:00
|
|
|
if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden;
|
2003-05-09 14:42:42 +02:00
|
|
|
|
2004-12-05 22:35:04 +01:00
|
|
|
$query = '
|
|
|
|
SELECT COUNT(DISTINCT(id)) AS nb_total_images
|
|
|
|
FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
|
|
|
|
ON id = ic.image_id
|
|
|
|
'.$page['where'].'
|
|
|
|
;';
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2004-06-19 01:24:40 +02:00
|
|
|
// categories containing recent pictures
|
|
|
|
else if ( $page['cat'] == 'recent_cats' )
|
|
|
|
{
|
2004-08-26 00:25:58 +02:00
|
|
|
$page['title'] = $lang['recent_cats_cat'];
|
2004-06-19 01:24:40 +02:00
|
|
|
$page['cat_nb_images'] = 0;
|
|
|
|
}
|
2003-05-09 14:42:42 +02:00
|
|
|
// most visited pictures
|
|
|
|
else if ( $page['cat'] == 'most_visited' )
|
|
|
|
{
|
|
|
|
$page['title'] = $conf['top_number'].' '.$lang['most_visited_cat'];
|
2004-10-30 17:42:29 +02:00
|
|
|
|
|
|
|
$page['where'] = 'WHERE hit > 0';
|
|
|
|
if (isset($forbidden))
|
|
|
|
{
|
|
|
|
$page['where'] = "\n".' AND '.$forbidden;
|
|
|
|
}
|
|
|
|
|
2003-05-21 23:45:46 +02:00
|
|
|
$conf['order_by'] = ' ORDER BY hit DESC, file ASC';
|
2005-01-15 12:16:46 +01:00
|
|
|
|
|
|
|
// $page['cat_nb_images'] equals $conf['top_number'] unless there
|
|
|
|
// are less visited items
|
|
|
|
$query ='
|
|
|
|
SELECT COUNT(DISTINCT(id)) AS count
|
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
|
|
|
|
'.$page['where'].'
|
|
|
|
;';
|
|
|
|
$row = mysql_fetch_array(pwg_query($query));
|
|
|
|
if ($row['count'] < $conf['top_number'])
|
|
|
|
{
|
|
|
|
$page['cat_nb_images'] = $row['count'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$page['cat_nb_images'] = $conf['top_number'];
|
|
|
|
}
|
|
|
|
unset($query);
|
|
|
|
|
2004-02-02 01:55:18 +01:00
|
|
|
if ( isset( $page['start'] )
|
|
|
|
and ($page['start']+$user['nb_image_page']>=$conf['top_number']))
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
|
|
|
$page['nb_image_page'] = $conf['top_number'] - $page['start'];
|
|
|
|
}
|
|
|
|
}
|
2004-06-15 22:02:03 +02:00
|
|
|
else if ( $page['cat'] == 'calendar' )
|
|
|
|
{
|
|
|
|
$page['cat_nb_images'] = 0;
|
|
|
|
$page['title'] = $lang['calendar'];
|
2004-06-25 22:31:48 +02:00
|
|
|
if (isset($_GET['year'])
|
|
|
|
and preg_match('/^\d+$/', $_GET['year']))
|
2004-06-15 22:02:03 +02:00
|
|
|
{
|
|
|
|
$page['calendar_year'] = (int)$_GET['year'];
|
|
|
|
}
|
2004-06-25 22:31:48 +02:00
|
|
|
if (isset($_GET['month'])
|
|
|
|
and preg_match('/^(\d+)\.(\d{2})$/', $_GET['month'], $matches))
|
2004-06-15 22:02:03 +02:00
|
|
|
{
|
|
|
|
$page['calendar_year'] = (int)$matches[1];
|
|
|
|
$page['calendar_month'] = (int)$matches[2];
|
|
|
|
}
|
2004-06-25 22:31:48 +02:00
|
|
|
if (isset($_GET['day'])
|
|
|
|
and preg_match('/^(\d+)\.(\d{2})\.(\d{2})$/',
|
|
|
|
$_GET['day'],
|
|
|
|
$matches))
|
|
|
|
{
|
|
|
|
$page['calendar_year'] = (int)$matches[1];
|
|
|
|
$page['calendar_month'] = (int)$matches[2];
|
|
|
|
$page['calendar_day'] = (int)$matches[3];
|
|
|
|
}
|
|
|
|
if (isset($page['calendar_year']))
|
2004-06-15 22:02:03 +02:00
|
|
|
{
|
|
|
|
$page['title'] .= ' (';
|
2004-06-25 22:31:48 +02:00
|
|
|
if (isset($page['calendar_day']))
|
|
|
|
{
|
2005-01-16 18:28:19 +01:00
|
|
|
if ($page['calendar_year'] >= 1970)
|
|
|
|
{
|
|
|
|
$unixdate = mktime(0,0,0,
|
|
|
|
$page['calendar_month'],
|
|
|
|
$page['calendar_day'],
|
|
|
|
$page['calendar_year']);
|
|
|
|
$page['title'].= $lang['day'][date("w", $unixdate)];
|
|
|
|
}
|
2004-06-25 22:31:48 +02:00
|
|
|
$page['title'].= ' '.$page['calendar_day'].', ';
|
|
|
|
}
|
|
|
|
if (isset($page['calendar_month']))
|
2004-06-15 22:02:03 +02:00
|
|
|
{
|
|
|
|
$page['title'] .= $lang['month'][$page['calendar_month']].' ';
|
|
|
|
}
|
|
|
|
$page['title'] .= $page['calendar_year'];
|
|
|
|
$page['title'] .= ')';
|
|
|
|
}
|
2004-08-27 01:00:28 +02:00
|
|
|
|
|
|
|
$page['where'] = 'WHERE '.$conf['calendar_datefield'].' IS NOT NULL';
|
2004-06-25 22:31:48 +02:00
|
|
|
if (isset($forbidden))
|
2004-06-15 22:02:03 +02:00
|
|
|
{
|
2004-08-27 01:00:28 +02:00
|
|
|
$page['where'].= ' AND '.$forbidden;
|
2004-06-15 22:02:03 +02:00
|
|
|
}
|
|
|
|
}
|
2004-08-31 00:00:46 +02:00
|
|
|
else if ($page['cat'] == 'best_rated')
|
|
|
|
{
|
|
|
|
$page['title'] = $conf['top_number'].' '.$lang['best_rated_cat'];
|
|
|
|
|
|
|
|
$page['where'] = ' WHERE average_rate IS NOT NULL';
|
|
|
|
|
|
|
|
if (isset($forbidden))
|
|
|
|
{
|
2004-09-01 23:39:29 +02:00
|
|
|
$page['where'].= ' AND '.$forbidden;
|
2004-08-31 00:00:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$conf['order_by'] = ' ORDER BY average_rate DESC, id ASC';
|
|
|
|
|
|
|
|
// $page['cat_nb_images'] equals $conf['top_number'] unless there
|
|
|
|
// are less rated items
|
|
|
|
$query ='
|
2005-01-08 00:51:48 +01:00
|
|
|
SELECT COUNT(DISTINCT(id)) AS count
|
2004-08-31 00:00:46 +02:00
|
|
|
FROM '.IMAGES_TABLE.'
|
2004-12-20 23:25:05 +01:00
|
|
|
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
|
2004-08-31 00:00:46 +02:00
|
|
|
'.$page['where'].'
|
|
|
|
;';
|
2004-10-30 17:42:29 +02:00
|
|
|
$row = mysql_fetch_array(pwg_query($query));
|
2004-08-31 00:00:46 +02:00
|
|
|
if ($row['count'] < $conf['top_number'])
|
|
|
|
{
|
|
|
|
$page['cat_nb_images'] = $row['count'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$page['cat_nb_images'] = $conf['top_number'];
|
|
|
|
}
|
|
|
|
unset($query);
|
|
|
|
|
|
|
|
|
|
|
|
if (isset($page['start'])
|
|
|
|
and ($page['start']+$user['nb_image_page']>=$conf['top_number']))
|
|
|
|
{
|
|
|
|
$page['nb_image_page'] = $conf['top_number'] - $page['start'];
|
|
|
|
}
|
|
|
|
}
|
2004-11-16 00:13:24 +01:00
|
|
|
else if ($page['cat'] == 'list')
|
2004-09-01 23:39:29 +02:00
|
|
|
{
|
|
|
|
$page['title'] = $lang['random_cat'];
|
|
|
|
|
2004-11-16 00:13:24 +01:00
|
|
|
$page['where'] = 'WHERE 1=1';
|
2004-09-01 23:39:29 +02:00
|
|
|
if (isset($forbidden))
|
|
|
|
{
|
2004-11-16 00:13:24 +01:00
|
|
|
$page['where'].= ' AND '.$forbidden;
|
2004-09-01 23:39:29 +02:00
|
|
|
}
|
2004-11-16 00:13:24 +01:00
|
|
|
$page['where'].= ' AND image_id IN ('.$_GET['list'].')';
|
|
|
|
$page['cat_nb_images'] = count(explode(',', $_GET['list']));
|
2004-11-24 22:27:01 +01:00
|
|
|
|
|
|
|
$url.= '&list='.$_GET['list'];
|
2004-09-01 23:39:29 +02:00
|
|
|
}
|
2003-09-06 09:22:59 +02:00
|
|
|
|
2004-06-25 22:31:48 +02:00
|
|
|
if (isset($query))
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2004-10-30 17:42:29 +02:00
|
|
|
$result = pwg_query( $query );
|
2003-05-09 14:42:42 +02:00
|
|
|
$row = mysql_fetch_array( $result );
|
|
|
|
$page['cat_nb_images'] = $row['nb_total_images'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $calling_page == 'category' )
|
|
|
|
{
|
|
|
|
$page['navigation_bar'] =
|
|
|
|
create_navigation_bar( $url, $page['cat_nb_images'], $page['start'],
|
|
|
|
$user['nb_image_page'], 'back' );
|
|
|
|
}
|
2006-02-01 23:56:17 +01:00
|
|
|
|
2006-02-01 03:46:26 +01:00
|
|
|
if ($page['cat'] != 'most_visited' and $page['cat'] != 'best_rated')
|
|
|
|
{
|
|
|
|
$available_image_orders = get_category_preferred_image_orders();
|
2006-02-01 23:56:17 +01:00
|
|
|
|
2006-02-01 03:46:26 +01:00
|
|
|
$order_idx=0;
|
2006-02-01 23:56:17 +01:00
|
|
|
if ( isset($_COOKIE['pwg_image_order']) )
|
2006-02-01 03:46:26 +01:00
|
|
|
{
|
|
|
|
$order_idx = $_COOKIE['pwg_image_order'];
|
|
|
|
}
|
2006-02-01 23:56:17 +01:00
|
|
|
|
2006-02-01 03:46:26 +01:00
|
|
|
if ( $order_idx > 0 )
|
|
|
|
{
|
|
|
|
$order = $available_image_orders[$order_idx][1];
|
|
|
|
$conf['order_by'] = str_replace('ORDER BY ', 'ORDER BY '.$order.',',
|
|
|
|
$conf['order_by'] );
|
|
|
|
}
|
|
|
|
}
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-12-25 20:33:36 +01:00
|
|
|
$page['title'] = $lang['no_category'];
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2004-02-02 01:55:18 +01:00
|
|
|
pwg_debug( 'end initialize_category' );
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2003-05-21 23:45:46 +02:00
|
|
|
|
2004-11-01 16:01:28 +01:00
|
|
|
function display_select_categories($categories,
|
|
|
|
$selecteds,
|
2004-11-13 14:43:53 +01:00
|
|
|
$blockname,
|
2004-11-23 23:31:24 +01:00
|
|
|
$fullname = true)
|
2004-11-01 16:01:28 +01:00
|
|
|
{
|
2004-11-23 23:31:24 +01:00
|
|
|
global $template;
|
2004-11-01 16:01:28 +01:00
|
|
|
|
|
|
|
foreach ($categories as $category)
|
|
|
|
{
|
2004-11-23 23:31:24 +01:00
|
|
|
$selected = '';
|
|
|
|
if (in_array($category['id'], $selecteds))
|
2004-11-01 16:01:28 +01:00
|
|
|
{
|
2004-11-23 23:31:24 +01:00
|
|
|
$selected = ' selected="selected"';
|
|
|
|
}
|
2004-11-13 14:43:53 +01:00
|
|
|
|
2004-11-23 23:31:24 +01:00
|
|
|
if ($fullname)
|
|
|
|
{
|
|
|
|
$option = get_cat_display_name_cache($category['uppercats'],
|
|
|
|
'',
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$option = str_repeat(' ',
|
|
|
|
(3 * substr_count($category['global_rank'], '.')));
|
|
|
|
$option.= '- '.$category['name'];
|
2004-11-01 16:01:28 +01:00
|
|
|
}
|
2004-11-23 23:31:24 +01:00
|
|
|
|
|
|
|
$template->assign_block_vars(
|
|
|
|
$blockname,
|
|
|
|
array('SELECTED'=>$selected,
|
|
|
|
'VALUE'=>$category['id'],
|
|
|
|
'OPTION'=>$option
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function display_select_cat_wrapper($query, $selecteds, $blockname,
|
|
|
|
$fullname = true)
|
|
|
|
{
|
|
|
|
$result = pwg_query($query);
|
|
|
|
$categories = array();
|
2004-12-23 15:59:37 +01:00
|
|
|
if (!empty($result))
|
|
|
|
{
|
2004-12-25 20:33:36 +01:00
|
|
|
while ($row = mysql_fetch_array($result))
|
|
|
|
{
|
|
|
|
array_push($categories, $row);
|
|
|
|
}
|
2004-12-23 15:59:37 +01:00
|
|
|
}
|
2004-11-23 23:31:24 +01:00
|
|
|
usort($categories, 'global_rank_compare');
|
|
|
|
display_select_categories($categories, $selecteds, $blockname, $fullname);
|
2004-11-01 16:01:28 +01:00
|
|
|
}
|
2004-11-15 22:42:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* returns all subcategory identifiers of given category ids
|
|
|
|
*
|
|
|
|
* @param array ids
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function get_subcat_ids($ids)
|
|
|
|
{
|
|
|
|
$query = '
|
|
|
|
SELECT DISTINCT(id)
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE ';
|
|
|
|
foreach ($ids as $num => $category_id)
|
|
|
|
{
|
|
|
|
if ($num > 0)
|
|
|
|
{
|
|
|
|
$query.= '
|
|
|
|
OR ';
|
|
|
|
}
|
|
|
|
$query.= 'uppercats REGEXP \'(^|,)'.$category_id.'(,|$)\'';
|
|
|
|
}
|
|
|
|
$query.= '
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
|
|
|
|
$subcats = array();
|
|
|
|
while ($row = mysql_fetch_array($result))
|
|
|
|
{
|
|
|
|
array_push($subcats, $row['id']);
|
|
|
|
}
|
|
|
|
return $subcats;
|
|
|
|
}
|
2004-11-23 23:31:24 +01:00
|
|
|
|
|
|
|
function global_rank_compare($a, $b)
|
|
|
|
{
|
|
|
|
return strnatcasecmp($a['global_rank'], $b['global_rank']);
|
|
|
|
}
|
2004-02-12 00:20:38 +01:00
|
|
|
?>
|