aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/category_default.inc.php48
-rw-r--r--include/common.inc.php20
-rw-r--r--include/functions_category.inc.php388
-rw-r--r--include/functions_html.inc.php6
-rw-r--r--include/functions_user.inc.php23
-rw-r--r--include/section_init.inc.php400
-rw-r--r--include/user.inc.php9
7 files changed, 470 insertions, 424 deletions
diff --git a/include/category_default.inc.php b/include/category_default.inc.php
index fd04181e9..009d9ef14 100644
--- a/include/category_default.inc.php
+++ b/include/category_default.inc.php
@@ -31,26 +31,36 @@
*
*/
-/**
- * $array_cat_directories is a cache hash associating category id with their
- * complete directory
- */
-$array_cat_directories = array();
-
-$query = '
-SELECT DISTINCT(id),path,file,date_available
- ,tn_ext,name,filesize,storage_category_id,average_rate,hit
- FROM '.IMAGES_TABLE.' AS i
- INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id=ic.image_id
- '.$page['where'].'
- '.$conf['order_by'].'
- LIMIT '.$page['start'].','.$page['nb_image_page'].'
+$page['rank_of'] = array_flip($page['items']);
+
+$pictures = array();
+
+$selection = array_slice(
+ $page['items'],
+ $page['start'],
+ $page['nb_image_page']
+ );
+
+if (count($selection) > 0)
+{
+ $query = '
+SELECT *
+ FROM '.IMAGES_TABLE.'
+ WHERE id IN ('.implode(',', $selection).')
;';
-//echo '<pre>'.$query.'</pre>';
-$result = pwg_query($query);
+ $result = pwg_query($query);
+ while ($row = mysql_fetch_array($result))
+ {
+ $row['rank'] = $page['rank_of'][ $row['id'] ];
+
+ array_push($pictures, $row);
+ }
+
+ usort($pictures, 'rank_compare');
+}
// template thumbnail initialization
-if ( mysql_num_rows($result) > 0 )
+if (count($pictures) > 0)
{
$template->assign_block_vars('thumbnails', array());
// first line
@@ -59,7 +69,7 @@ if ( mysql_num_rows($result) > 0 )
$row_number = 0;
}
-while ($row = mysql_fetch_array($result))
+foreach ($pictures as $row)
{
$thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
@@ -150,4 +160,6 @@ SELECT COUNT(*) AS nb_comments
$row_number = 0;
}
}
+
+pwg_debug('end include/category_default.inc.php');
?> \ No newline at end of file
diff --git a/include/common.inc.php b/include/common.inc.php
index 83e1bf30d..b89258df1 100644
--- a/include/common.inc.php
+++ b/include/common.inc.php
@@ -198,6 +198,19 @@ if (defined('IN_ADMIN') and IN_ADMIN)
include_once(get_language_filepath('admin.lang.php'));
}
+if ($conf['gallery_locked'])
+{
+ echo
+ '<div style="text-align:center;">'
+ .$lang['gallery_locked_message']
+ .'</div>';
+
+ if ($user['status'] != 'admin')
+ {
+ exit();
+ }
+}
+
// only now we can set the localized username of the guest user (and not in
// include/user.inc.php)
if ($user['is_the_guest'])
@@ -209,7 +222,12 @@ if ($user['is_the_guest'])
list($user['template'], $user['theme']) = explode('/', $user['template']);
// TODO : replace initial $user['template'] by $user['layout']
-include(PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/'.$user['theme'].'/themeconf.inc.php');
+include(
+ PHPWG_ROOT_PATH
+ .'template/'.$user['template']
+ .'/theme/'.$user['theme']
+ .'/themeconf.inc.php'
+ );
// template instance
$template = new Template(PHPWG_ROOT_PATH.'template/'.$user['template']);
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 351fa1007..30f91dd65 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -53,71 +53,6 @@ function check_restrictions($category_id)
}
}
-/**
- * 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
- * - equals 'fav' (for favorites)
- * - equals 'search' (when the result of a search is displayed)
- * - equals 'most_visited'
- * - equals 'best_rated'
- * - equals 'recent_pics'
- * - equals 'recent_cats'
- * - equals 'calendar'
- * - equals 'list'
- *
- * The function fills the global var $page['cat'] and returns nothing
- *
- * @param mixed category id or special category name
- * @return void
- */
-function check_cat_id( $cat )
-{
- global $page;
-
- unset( $page['cat'] );
- if ( isset( $cat ) )
- {
- if ( isset( $page['plain_structure'][$cat] ) )
- {
- $page['cat'] = $cat;
- }
- else if ( is_numeric( $cat ) )
- {
- $query = 'SELECT id';
- $query.= ' FROM '.CATEGORIES_TABLE.' WHERE id = '.$cat.';';
- $result = pwg_query( $query );
- if ( mysql_num_rows( $result ) != 0 )
- {
- $page['cat'] = $cat;
- }
- }
- if ( $cat == 'fav'
- or $cat == 'most_visited'
- or $cat == 'best_rated'
- or $cat == 'recent_pics'
- or $cat == 'recent_cats'
- or $cat == 'calendar' )
- {
- $page['cat'] = $cat;
- }
- if ($cat == 'search'
- and isset($_GET['search'])
- and is_numeric($_GET['search']))
- {
- $page['cat'] = $cat;
- }
- if ($cat == 'list'
- and isset($_GET['list'])
- and preg_match('/^\d+(,\d+)*$/', $_GET['list']))
- {
- $page['cat'] = 'list';
- }
- }
-}
-
function get_categories_menu()
{
global $page,$user;
@@ -332,319 +267,6 @@ function get_category_preferred_image_orders()
);
}
-
-// 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
-// - defined list (used for random)
-// 3. determination of the title of the page
-// 4. creation of the navigation bar
-function initialize_category( $calling_page = 'category' )
-{
- pwg_debug( 'start initialize_category' );
- global $page,$lang,$user,$conf;
-
- 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
- $url = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'];
- if ( isset($page['expand']) ) $url.= '&amp;expand='.$page['expand'];
- // simple category
- if ( is_numeric( $page['cat'] ) )
- {
- $result = get_cat_info( $page['cat'] );
- $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'];
- $page['cat_commentable'] = $result['commentable'];
- $page['cat_id_uppercat'] = $result['id_uppercat'];
- $page['uppercats'] = $result['uppercats'];
- $page['title'] =
- get_cat_display_name($page['cat_name'],
- '',
- false);
- $page['where'] = ' WHERE category_id = '.$page['cat'];
- }
- else
- {
- 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')
- {
- // we must not show pictures of a forbidden category
- if ( $user['forbidden_categories'] != '' )
- {
- $forbidden = ' category_id NOT IN ';
- $forbidden.= '('.$user['forbidden_categories'].')';
- }
- }
- // 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>";
- }
-
- $page['where'] = 'WHERE '.get_sql_search_clause($_GET['search']);
-
- if (isset($forbidden))
- {
- $page['where'].= "\n AND ".$forbidden;
- }
-
- $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.= '&amp;search='.$_GET['search'];
- }
- // favorites displaying
- else if ( $page['cat'] == 'fav' )
- {
- check_user_favorites();
-
- $page['title'] = $lang['favorites'];
-
- $page['where'] = ', '.FAVORITES_TABLE.' AS fav';
- $page['where'].= ' WHERE user_id = '.$user['id'];
- $page['where'].= ' AND fav.image_id = id';
-
- $query = 'SELECT COUNT(*) AS nb_total_images';
- $query.= ' FROM '.FAVORITES_TABLE;
- $query.= ' WHERE user_id = '.$user['id'];
- $query.= ';';
- }
- // pictures within the short period
- else if ( $page['cat'] == 'recent_pics' )
- {
- $page['title'] = $lang['recent_pics_cat'];
- // We must find the date corresponding to :
- // today - $conf['periode_courte']
- $date = time() - 60*60*24*$user['recent_period'];
- $page['where'] = " WHERE date_available > '";
- $page['where'].= date( 'Y-m-d', $date )."'";
- if ( isset( $forbidden ) ) $page['where'].= ' AND '.$forbidden;
-
- $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'].'
-;';
- }
- // categories containing recent pictures
- else if ( $page['cat'] == 'recent_cats' )
- {
- $page['title'] = $lang['recent_cats_cat'];
- $page['cat_nb_images'] = 0;
- }
- // most visited pictures
- else if ( $page['cat'] == 'most_visited' )
- {
- $page['title'] = $conf['top_number'].' '.$lang['most_visited_cat'];
-
- $page['where'] = 'WHERE hit > 0';
- if (isset($forbidden))
- {
- $page['where'] .= "\n".' AND '.$forbidden;
- }
-
- $conf['order_by'] = ' ORDER BY hit DESC, file ASC';
-
- // $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);
-
- if ( isset( $page['start'] )
- and ($page['start']+$user['nb_image_page']>=$conf['top_number']))
- {
- $page['nb_image_page'] = $conf['top_number'] - $page['start'];
- }
- }
- else if ( $page['cat'] == 'calendar' )
- {
- $page['cat_nb_images'] = 0;
- $page['title'] = $lang['calendar'];
- if (isset($_GET['year'])
- and preg_match('/^\d+$/', $_GET['year']))
- {
- $page['calendar_year'] = (int)$_GET['year'];
- }
- if (isset($_GET['month'])
- and preg_match('/^(\d+)\.(\d{2})$/', $_GET['month'], $matches))
- {
- $page['calendar_year'] = (int)$matches[1];
- $page['calendar_month'] = (int)$matches[2];
- }
- 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']))
- {
- $page['title'] .= ' (';
- if (isset($page['calendar_day']))
- {
- 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)];
- }
- $page['title'].= ' '.$page['calendar_day'].', ';
- }
- if (isset($page['calendar_month']))
- {
- $page['title'] .= $lang['month'][$page['calendar_month']].' ';
- }
- $page['title'] .= $page['calendar_year'];
- $page['title'] .= ')';
- }
-
- $page['where'] = 'WHERE '.$conf['calendar_datefield'].' IS NOT NULL';
- if (isset($forbidden))
- {
- $page['where'].= ' AND '.$forbidden;
- }
- }
- 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))
- {
- $page['where'].= ' AND '.$forbidden;
- }
-
- $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 ='
-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);
-
-
- if (isset($page['start'])
- and ($page['start']+$user['nb_image_page']>=$conf['top_number']))
- {
- $page['nb_image_page'] = $conf['top_number'] - $page['start'];
- }
- }
- else if ($page['cat'] == 'list')
- {
- $page['title'] = $lang['random_cat'];
-
- $page['where'] = 'WHERE 1=1';
- if (isset($forbidden))
- {
- $page['where'].= ' AND '.$forbidden;
- }
- $page['where'].= ' AND image_id IN ('.$_GET['list'].')';
- $page['cat_nb_images'] = count(explode(',', $_GET['list']));
-
- $url.= '&amp;list='.$_GET['list'];
- }
-
- if (isset($query))
- {
- $result = pwg_query( $query );
- $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' );
- }
-
- if ($page['cat'] != 'most_visited' and $page['cat'] != 'best_rated')
- {
- $available_image_orders = get_category_preferred_image_orders();
-
- $order_idx=0;
- if ( isset($_COOKIE['pwg_image_order']) )
- {
- $order_idx = $_COOKIE['pwg_image_order'];
- }
-
- if ( $order_idx > 0 )
- {
- $order = $available_image_orders[$order_idx][1];
- $conf['order_by'] = str_replace('ORDER BY ', 'ORDER BY '.$order.',',
- $conf['order_by'] );
- }
- }
- }
- else
- {
- $page['title'] = $lang['no_category'];
- }
- pwg_debug( 'end initialize_category' );
-}
-
function display_select_categories($categories,
$selecteds,
$blockname,
@@ -735,4 +357,14 @@ function global_rank_compare($a, $b)
{
return strnatcasecmp($a['global_rank'], $b['global_rank']);
}
+
+function rank_compare($a, $b)
+{
+ if ($a['rank'] == $b['rank'])
+ {
+ return 0;
+ }
+
+ return ($a['rank'] < $b['rank']) ? -1 : 1;
+}
?>
diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php
index e53e5e2f1..e23a2e3b2 100644
--- a/include/functions_html.inc.php
+++ b/include/functions_html.inc.php
@@ -349,7 +349,8 @@ function get_html_menu_category($categories)
$ref_level = 0;
$level = 0;
$menu = '';
-
+
+ // $page_cat value remains 0 for special sections
$page_cat = 0;
if (isset($page['cat']) and is_numeric($page['cat']) )
{
@@ -383,7 +384,8 @@ function get_html_menu_category($categories)
$url = PHPWG_ROOT_PATH.'category.php?cat='.$category['id'];
$menu.= "\n".'<a href="'.$url.'"';
- if ($category['id'] == $page['cat_id_uppercat'])
+ if ($page_cat != 0
+ and $category['id'] == $page['cat_id_uppercat'])
{
$menu.= ' rel="up"';
}
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index 8c02f3324..ec4480bfd 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -100,29 +100,6 @@ SELECT MAX('.$conf['user_fields']['id'].') + 1
return $errors;
}
-function check_login_authorization($guest_allowed = true)
-{
- global $user,$lang,$conf,$template;
-
- if ($user['is_the_guest'] and !$guest_allowed)
- {
- echo '<div style="text-align:center;">'.$lang['only_members'].'<br />';
- echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>';
- exit();
- }
-
- if ($conf['gallery_locked'])
- {
- echo '<div style="text-align:center;">';
- echo $lang['gallery_locked_message'];
- echo '</div>';
- if ($user['status'] != 'admin')
- {
- exit();
- }
- }
-}
-
function setup_style($style)
{
return new Template(PHPWG_ROOT_PATH.'template/'.$style);
diff --git a/include/section_init.inc.php b/include/section_init.inc.php
new file mode 100644
index 000000000..e54b050a0
--- /dev/null
+++ b/include/section_init.inc.php
@@ -0,0 +1,400 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | 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 |
+// +-----------------------------------------------------------------------+
+// | branch : BSF (Best So Far)
+// | file : $RCSfile$
+// | last update : $Date: 2006-01-27 02:11:43 +0100 (ven, 27 jan 2006) $
+// | last modifier : $Author: rvelices $
+// | revision : $Revision: 1014 $
+// +-----------------------------------------------------------------------+
+// | 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. |
+// +-----------------------------------------------------------------------+
+
+/**
+ * This included page checks section related parameter and provides
+ * following informations:
+ *
+ * - $page['title']
+ *
+ * - $page['items']: ordered list of items to display
+ *
+ * - $page['cat_nb_images']: number of items in the section (should be equal
+ * to count($page['items']))
+ *
+ * - $page['thumbnails_include']: include page managing thumbnails to
+ * display
+ */
+
+unset($page['cat']);
+
+if (isset($_GET['cat']))
+{
+ if (is_numeric($_GET['cat']))
+ {
+ $page['cat'] = $_GET['cat'];
+ }
+ else if ($_GET['cat'] == 'fav'
+ or $_GET['cat'] == 'most_visited'
+ or $_GET['cat'] == 'best_rated'
+ or $_GET['cat'] == 'recent_pics'
+ or $_GET['cat'] == 'recent_cats'
+ or $_GET['cat'] == 'calendar')
+ {
+ $page['cat'] = $_GET['cat'];
+ }
+ else if ($_GET['cat'] == 'search')
+ {
+ if (!isset($_GET['search']))
+ {
+ die('search GET parameter is missing');
+ }
+ else if (!is_numeric($_GET['search']))
+ {
+ die('wrong format on search GET parameter');
+ }
+ else
+ {
+ $page['cat'] = 'search';
+ }
+ }
+ else if ($_GET['cat'] == 'list')
+ {
+ if (!isset($_GET['list']))
+ {
+ die('list GET parameter is missing');
+ }
+ else if (!preg_match('/^\d+(,\d+)*$/', $_GET['list']))
+ {
+ die('wrong format on list GET parameter');
+ }
+ else
+ {
+ $page['cat'] = 'list';
+ }
+ }
+ else
+ {
+ die('unknown cat GET parameter value');
+ }
+}
+
+
+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'];
+
+ if ($page['cat'] != 'most_visited' and $page['cat'] != 'best_rated')
+ {
+ if (isset($_COOKIE['pwg_image_order'])
+ and is_numeric($_COOKIE['pwg_image_order'])
+ and $_COOKIE['pwg_image_order'] > 0)
+ {
+ $orders = get_category_preferred_image_orders();
+
+ $conf['order_by'] = str_replace(
+ 'ORDER BY ',
+ 'ORDER BY '.$orders[ $_COOKIE['pwg_image_order'] ][1].',',
+ $conf['order_by']
+ );
+ }
+ }
+
+// +-----------------------------------------------------------------------+
+// | category |
+// +-----------------------------------------------------------------------+
+ if (is_numeric($page['cat']))
+ {
+ $query = '
+SELECT image_id
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ INNER JOIN '.IMAGES_TABLE.' ON id = image_id
+ WHERE category_id = '.$page['cat'].'
+ '.$conf['order_by'].'
+;';
+
+ $result = get_cat_info($page['cat']);
+
+ $page = array_merge(
+ $page,
+ array(
+ 'comment' => $result['comment'],
+ 'cat_dir' => $result['dir'],
+ 'cat_name' => $result['name'],
+ 'cat_nb_images' => $result['nb_images'],
+ 'cat_site_id' => $result['site_id'],
+ 'cat_uploadable' => $result['uploadable'],
+ 'cat_commentable' => $result['commentable'],
+ 'cat_id_uppercat' => $result['id_uppercat'],
+ 'uppercats' => $result['uppercats'],
+
+ 'title' => get_cat_display_name($result['name'], '', false),
+ 'items' => array_from_query($query, 'image_id'),
+ 'thumbnails_include' =>
+ $result['nb_images'] > 0
+ ? 'include/category_default.inc.php'
+ : 'include/category_subcats.inc.php',
+ )
+ );
+ }
+ // special section
+ else
+ {
+ if (!empty($user['forbidden_categories']))
+ {
+ $forbidden =
+ ' category_id NOT IN ('.$user['forbidden_categories'].')';
+ }
+ else
+ {
+ $forbidden = ' 1=1';
+ }
+
+// +-----------------------------------------------------------------------+
+// | search section |
+// +-----------------------------------------------------------------------+
+ if ( $page['cat'] == 'search' )
+ {
+ $query = '
+SELECT DISTINCT(id)
+ FROM '.IMAGES_TABLE.'
+ INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
+ WHERE '.get_sql_search_clause($_GET['search']).'
+ AND '.$forbidden.'
+ '.$conf['order_by'].'
+;';
+
+ $page = array_merge(
+ $page,
+ array(
+ 'title' => $lang['search_result'],
+ 'items' => array_from_query($query, 'id'),
+ 'thumbnails_include' => 'include/category_default.inc.php',
+ )
+ );
+ }
+// +-----------------------------------------------------------------------+
+// | favorite section |
+// +-----------------------------------------------------------------------+
+ else if ($page['cat'] == 'fav')
+ {
+ check_user_favorites();
+
+ $query = '
+SELECT image_id
+ FROM '.FAVORITES_TABLE.'
+ INNER JOIN '.IMAGES_TABLE.' ON image_id = id
+ WHERE user_id = '.$user['id'].'
+ '.$conf['order_by'].'
+;';
+
+ $page = array_merge(
+ $page,
+ array(
+ 'title' => $lang['favorites'],
+ 'items' => array_from_query($query, 'id'),
+ 'thumbnails_include' => 'include/category_default.inc.php',
+ )
+ );
+ }
+// +-----------------------------------------------------------------------+
+// | recent pictures section |
+// +-----------------------------------------------------------------------+
+ else if ($page['cat'] == 'recent_pics')
+ {
+ $query = '
+SELECT DISTINCT(id)
+ FROM '.IMAGES_TABLE.'
+ INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
+ WHERE date_available > \''.
+ date('Y-m-d', time() - 60*60*24*$user['recent_period']).'\'
+ AND '.$forbidden.'
+ '.$conf['order_by'].'
+;';
+
+ $page = array_merge(
+ $page,
+ array(
+ 'title' => $lang['recent_pics_cat'],
+ 'items' => array_from_query($query, 'id'),
+ 'thumbnails_include' => 'include/category_default.inc.php',
+ )
+ );
+ }
+// +-----------------------------------------------------------------------+
+// | recently updated categories section |
+// +-----------------------------------------------------------------------+
+ else if ($page['cat'] == 'recent_cats')
+ {
+ $page = array_merge(
+ $page,
+ array(
+ 'title' => $lang['recent_cats_cat'],
+ 'cat_nb_images' => 0,
+ 'thumbnails_include' => 'include/category_recent_cats.inc.php',
+ )
+ );
+ }
+// +-----------------------------------------------------------------------+
+// | most visited section |
+// +-----------------------------------------------------------------------+
+ else if ($page['cat'] == 'most_visited')
+ {
+ $query = '
+SELECT DISTINCT(id)
+ FROM '.IMAGES_TABLE.'
+ INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
+ WHERE hit > 0
+ AND '.$forbidden.'
+ ORDER BY hit DESC, file ASC
+ LIMIT 0, '.$conf['top_number'].'
+;';
+
+ $page = array_merge(
+ $page,
+ array(
+ 'title' => $conf['top_number'].' '.$lang['most_visited_cat'],
+ 'items' => array_from_query($query, 'id'),
+ 'thumbnails_include' => 'include/category_default.inc.php',
+ )
+ );
+ }
+// +-----------------------------------------------------------------------+
+// | calendar section |
+// +-----------------------------------------------------------------------+
+ else if ($page['cat'] == 'calendar')
+ {
+ $page['cat_nb_images'] = 0;
+ $page['title'] = $lang['calendar'];
+ if (isset($_GET['year'])
+ and preg_match('/^\d+$/', $_GET['year']))
+ {
+ $page['calendar_year'] = (int)$_GET['year'];
+ }
+ if (isset($_GET['month'])
+ and preg_match('/^(\d+)\.(\d{2})$/', $_GET['month'], $matches))
+ {
+ $page['calendar_year'] = (int)$matches[1];
+ $page['calendar_month'] = (int)$matches[2];
+ }
+ 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']))
+ {
+ $page['title'] .= ' (';
+ if (isset($page['calendar_day']))
+ {
+ 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)];
+ }
+ $page['title'].= ' '.$page['calendar_day'].', ';
+ }
+ if (isset($page['calendar_month']))
+ {
+ $page['title'] .= $lang['month'][$page['calendar_month']].' ';
+ }
+ $page['title'] .= $page['calendar_year'];
+ $page['title'] .= ')';
+ }
+
+ $page['where'] = 'WHERE '.$conf['calendar_datefield'].' IS NOT NULL';
+ if (isset($forbidden))
+ {
+ $page['where'].= ' AND '.$forbidden;
+ }
+
+ $page['thumbnails_include'] = 'include/category_calendar.inc.php';
+ }
+// +-----------------------------------------------------------------------+
+// | best rated section |
+// +-----------------------------------------------------------------------+
+ else if ($page['cat'] == 'best_rated')
+ {
+ $query ='
+SELECT DISTINCT(id)
+ FROM '.IMAGES_TABLE.'
+ INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
+ WHERE average_rate IS NOT NULL
+ AND '.$forbidden.'
+ ORDER BY average_rate DESC, id ASC
+ LIMIT 0, '.$conf['top_number'].'
+;';
+ $page = array_merge(
+ $page,
+ array(
+ 'title' => $conf['top_number'].' '.$lang['best_rated_cat'],
+ 'items' => array_from_query($query, 'id'),
+ 'thumbnails_include' => 'include/category_default.inc.php',
+ )
+ );
+ }
+// +-----------------------------------------------------------------------+
+// | list section |
+// +-----------------------------------------------------------------------+
+ else if ($page['cat'] == 'list')
+ {
+ $query ='
+SELECT DISTINCT(id)
+ FROM '.IMAGES_TABLE.'
+ INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
+ WHERE image_id IN ('.$_GET['list'].')
+ AND '.$forbidden.'
+ '.$conf['order_by'].'
+;';
+ $page = array_merge(
+ $page,
+ array(
+ 'title' => $lang['random_cat'],
+ 'items' => array_from_query($query, 'id'),
+ 'thumbnails_include' => 'include/category_default.inc.php',
+ )
+ );
+ }
+
+ if (!isset($page['cat_nb_images']))
+ {
+ $page['cat_nb_images'] = count($page['items']);
+ }
+ }
+}
+// +-----------------------------------------------------------------------+
+// | root category |
+// +-----------------------------------------------------------------------+
+else
+{
+ $page['title'] = $lang['no_category'];
+ $page['thumbnails_include'] = 'include/category_subcats.inc.php';
+}
+?> \ No newline at end of file
diff --git a/include/user.inc.php b/include/user.inc.php
index ad58b3f92..c22f4b369 100644
--- a/include/user.inc.php
+++ b/include/user.inc.php
@@ -59,8 +59,13 @@ if ($conf['apache_authentication'] and isset($_SERVER['REMOTE_USER']))
$user['is_the_guest'] = false;
}
-$use_cache = (defined('IN_ADMIN') and IN_ADMIN) ? false : true;
-$user = array_merge($user, getuserdata($user['id'], $use_cache));
+$user = array_merge(
+ $user,
+ getuserdata(
+ $user['id'],
+ defined('IN_ADMIN') and IN_ADMIN ? false : true // use cache ?
+ )
+ );
// properties of user guest are found in the configuration
if ($user['is_the_guest'])