2004-06-25 22:27:09 +02:00
|
|
|
<?php
|
|
|
|
// +-----------------------------------------------------------------------+
|
2011-01-18 01:02:52 +01:00
|
|
|
// | Piwigo - a PHP based photo gallery |
|
2008-04-05 00:57:23 +02:00
|
|
|
// +-----------------------------------------------------------------------+
|
2012-01-17 23:48:36 +01:00
|
|
|
// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
|
2008-04-05 00:57:23 +02:00
|
|
|
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
|
|
|
|
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | 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 |
|
2004-06-25 22:27:09 +02:00
|
|
|
// | 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. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
|
|
|
/**
|
2012-09-23 13:19:26 +02:00
|
|
|
* This file is included by the main page to show subcategories of a category
|
|
|
|
* or to show recent categories or main page categories list
|
2006-04-06 04:23:54 +02:00
|
|
|
*
|
2004-06-25 22:27:09 +02:00
|
|
|
*/
|
|
|
|
|
2012-09-23 13:19:26 +02:00
|
|
|
$selection = array_slice(
|
|
|
|
$page['categories'],
|
|
|
|
$page['starta'],
|
|
|
|
$conf['nb_categories_page']
|
|
|
|
);
|
|
|
|
|
|
|
|
$selection = trigger_event('loc_index_categories_selection', $selection);
|
|
|
|
|
2011-01-20 14:32:34 +01:00
|
|
|
// $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
|
|
|
|
$query = '
|
2006-12-02 00:31:19 +01:00
|
|
|
SELECT
|
2011-01-20 14:32:34 +01:00
|
|
|
c.*,
|
|
|
|
user_representative_picture_id,
|
|
|
|
nb_images,
|
|
|
|
date_last,
|
|
|
|
max_date_last,
|
|
|
|
count_images,
|
|
|
|
count_categories
|
|
|
|
FROM '.CATEGORIES_TABLE.' c
|
2012-09-23 13:19:26 +02:00
|
|
|
INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.' ucc
|
|
|
|
ON id = cat_id
|
|
|
|
AND user_id = '.$user['id'].'
|
|
|
|
WHERE c.id IN('.implode(',', $selection).')';
|
|
|
|
|
2011-01-20 14:32:34 +01:00
|
|
|
if ('recent_cats' != $page['section'])
|
|
|
|
{
|
|
|
|
$query.= '
|
|
|
|
ORDER BY rank';
|
2006-11-08 04:01:28 +01:00
|
|
|
}
|
2005-08-14 01:09:54 +02:00
|
|
|
|
2011-01-20 14:32:34 +01:00
|
|
|
$query.= '
|
|
|
|
;';
|
|
|
|
|
2006-11-08 04:01:28 +01:00
|
|
|
$result = pwg_query($query);
|
2006-04-06 22:28:37 +02:00
|
|
|
$categories = array();
|
2007-04-22 15:11:56 +02:00
|
|
|
$category_ids = array();
|
2006-04-06 22:28:37 +02:00
|
|
|
$image_ids = array();
|
2011-01-20 14:32:34 +01:00
|
|
|
$user_representative_updates_for = array();
|
2004-10-30 17:42:29 +02:00
|
|
|
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2004-06-25 22:27:09 +02:00
|
|
|
{
|
2006-12-08 01:12:44 +01:00
|
|
|
$row['is_child_date_last'] = @$row['max_date_last']>@$row['date_last'];
|
2006-12-02 00:31:19 +01:00
|
|
|
|
2011-01-20 14:32:34 +01:00
|
|
|
if (!empty($row['user_representative_picture_id']))
|
|
|
|
{
|
|
|
|
$image_id = $row['user_representative_picture_id'];
|
|
|
|
}
|
|
|
|
else if (!empty($row['representative_picture_id']))
|
2006-11-08 04:01:28 +01:00
|
|
|
{ // if a representative picture is set, it has priority
|
2005-08-14 01:09:54 +02:00
|
|
|
$image_id = $row['representative_picture_id'];
|
2004-12-27 15:30:49 +01:00
|
|
|
}
|
2005-08-14 01:09:54 +02:00
|
|
|
else if ($conf['allow_random_representative'])
|
2011-01-20 14:32:34 +01:00
|
|
|
{
|
|
|
|
// searching a random representant among elements in sub-categories
|
|
|
|
$image_id = get_random_image_in_category($row);
|
2005-08-14 01:09:54 +02:00
|
|
|
}
|
|
|
|
else
|
2006-11-08 04:01:28 +01:00
|
|
|
{ // searching a random representant among representant of sub-categories
|
2008-07-06 00:13:28 +02:00
|
|
|
if ($row['count_categories']>0 and $row['count_images']>0)
|
2005-08-14 01:09:54 +02:00
|
|
|
{
|
2008-07-06 00:13:28 +02:00
|
|
|
$query = '
|
|
|
|
SELECT representative_picture_id
|
|
|
|
FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
|
|
|
|
ON id = cat_id and user_id = '.$user['id'].'
|
|
|
|
WHERE uppercats LIKE \''.$row['uppercats'].',%\'
|
|
|
|
AND representative_picture_id IS NOT NULL'
|
|
|
|
.get_sql_condition_FandF
|
|
|
|
(
|
|
|
|
array
|
|
|
|
(
|
|
|
|
'visible_categories' => 'id',
|
|
|
|
),
|
|
|
|
"\n AND"
|
|
|
|
).'
|
2009-11-25 20:02:57 +01:00
|
|
|
ORDER BY '.DB_RANDOM_FUNCTION.'()
|
2009-11-21 20:52:50 +01:00
|
|
|
LIMIT 1
|
2008-07-06 00:13:28 +02:00
|
|
|
;';
|
|
|
|
$subresult = pwg_query($query);
|
2009-11-20 15:17:04 +01:00
|
|
|
if (pwg_db_num_rows($subresult) > 0)
|
2008-07-06 00:13:28 +02:00
|
|
|
{
|
2009-11-20 15:17:04 +01:00
|
|
|
list($image_id) = pwg_db_fetch_row($subresult);
|
2008-07-06 00:13:28 +02:00
|
|
|
}
|
2005-08-14 01:09:54 +02:00
|
|
|
}
|
2004-06-25 22:27:09 +02:00
|
|
|
}
|
|
|
|
|
2005-08-14 01:09:54 +02:00
|
|
|
if (isset($image_id))
|
|
|
|
{
|
2011-07-14 00:03:36 +02:00
|
|
|
if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id)
|
2011-01-20 14:32:34 +01:00
|
|
|
{
|
|
|
|
$user_representative_updates_for[ $user['id'].'#'.$row['id'] ] = $image_id;
|
|
|
|
}
|
|
|
|
|
2006-11-08 04:01:28 +01:00
|
|
|
$row['representative_picture_id'] = $image_id;
|
2006-04-06 22:28:37 +02:00
|
|
|
array_push($image_ids, $image_id);
|
2006-11-08 04:01:28 +01:00
|
|
|
array_push($categories, $row);
|
2007-04-22 15:11:56 +02:00
|
|
|
array_push($category_ids, $row['id']);
|
2005-08-14 01:09:54 +02:00
|
|
|
}
|
|
|
|
unset($image_id);
|
|
|
|
}
|
2004-06-25 22:27:09 +02:00
|
|
|
|
2007-04-22 15:11:56 +02:00
|
|
|
if ($conf['display_fromto'])
|
|
|
|
{
|
|
|
|
$dates_of_category = array();
|
|
|
|
if (count($category_ids) > 0)
|
|
|
|
{
|
|
|
|
$query = '
|
|
|
|
SELECT
|
|
|
|
category_id,
|
|
|
|
MIN(date_creation) AS date_creation_min,
|
|
|
|
MAX(date_creation) AS date_creation_max
|
|
|
|
FROM '.IMAGE_CATEGORY_TABLE.'
|
|
|
|
INNER JOIN '.IMAGES_TABLE.' ON image_id = id
|
2007-09-14 01:30:46 +02:00
|
|
|
WHERE category_id IN ('.implode(',', $category_ids).')
|
2007-04-22 18:19:16 +02:00
|
|
|
'.get_sql_condition_FandF
|
|
|
|
(
|
|
|
|
array
|
|
|
|
(
|
|
|
|
'visible_categories' => 'category_id',
|
2007-09-14 01:30:46 +02:00
|
|
|
'visible_images' => 'id'
|
2007-04-22 18:19:16 +02:00
|
|
|
),
|
|
|
|
'AND'
|
|
|
|
).'
|
2007-04-22 15:11:56 +02:00
|
|
|
GROUP BY category_id
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2007-04-22 15:11:56 +02:00
|
|
|
{
|
|
|
|
$dates_of_category[ $row['category_id'] ] = array(
|
|
|
|
'from' => $row['date_creation_min'],
|
|
|
|
'to' => $row['date_creation_max'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-13 04:13:40 +01:00
|
|
|
if ($page['section']=='recent_cats')
|
|
|
|
{
|
|
|
|
usort($categories, 'global_rank_compare');
|
|
|
|
}
|
2006-11-08 04:01:28 +01:00
|
|
|
if (count($categories) > 0)
|
2005-08-14 01:09:54 +02:00
|
|
|
{
|
2011-11-05 00:54:12 +01:00
|
|
|
$infos_of_image = array();
|
2011-01-20 14:32:34 +01:00
|
|
|
$new_image_ids = array();
|
2005-03-26 23:35:07 +01:00
|
|
|
|
2005-08-14 01:09:54 +02:00
|
|
|
$query = '
|
2011-11-05 00:54:12 +01:00
|
|
|
SELECT *
|
2005-08-14 01:09:54 +02:00
|
|
|
FROM '.IMAGES_TABLE.'
|
2006-04-06 22:28:37 +02:00
|
|
|
WHERE id IN ('.implode(',', $image_ids).')
|
2005-08-14 01:09:54 +02:00
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
2009-11-20 15:17:04 +01:00
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
2005-08-14 01:09:54 +02:00
|
|
|
{
|
2011-01-20 14:32:34 +01:00
|
|
|
if ($row['level'] <= $user['level'])
|
|
|
|
{
|
2011-11-05 00:54:12 +01:00
|
|
|
$infos_of_image[$row['id']] = $row;
|
2011-01-20 14:32:34 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// problem: we must not display the thumbnail of a photo which has a
|
|
|
|
// higher privacy level than user privacy level
|
|
|
|
//
|
|
|
|
// * what is the represented category?
|
|
|
|
// * find a random photo matching user permissions
|
|
|
|
// * register it at user_representative_picture_id
|
|
|
|
// * set it as the representative_picture_id for the category
|
|
|
|
|
|
|
|
foreach ($categories as &$category)
|
|
|
|
{
|
|
|
|
if ($row['id'] == $category['representative_picture_id'])
|
|
|
|
{
|
2011-02-24 12:30:30 +01:00
|
|
|
// searching a random representant among elements in sub-categories
|
|
|
|
$image_id = get_random_image_in_category($category);
|
2011-01-20 14:32:34 +01:00
|
|
|
|
2011-02-24 12:30:30 +01:00
|
|
|
if (isset($image_id) and !in_array($image_id, $image_ids))
|
|
|
|
{
|
|
|
|
array_push($new_image_ids, $image_id);
|
2011-01-20 14:32:34 +01:00
|
|
|
}
|
2011-07-14 00:03:36 +02:00
|
|
|
|
|
|
|
if ($conf['representative_cache_on_level'])
|
|
|
|
{
|
|
|
|
$user_representative_updates_for[ $user['id'].'#'.$category['id'] ] = $image_id;
|
|
|
|
}
|
2011-02-24 12:30:30 +01:00
|
|
|
|
|
|
|
$category['representative_picture_id'] = $image_id;
|
2011-01-20 14:32:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
unset($category);
|
|
|
|
}
|
2005-08-14 01:09:54 +02:00
|
|
|
}
|
2011-01-20 14:32:34 +01:00
|
|
|
|
|
|
|
if (count($new_image_ids) > 0)
|
|
|
|
{
|
|
|
|
$query = '
|
2011-11-05 00:54:12 +01:00
|
|
|
SELECT *
|
2011-01-20 14:32:34 +01:00
|
|
|
FROM '.IMAGES_TABLE.'
|
|
|
|
WHERE id IN ('.implode(',', $new_image_ids).')
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
while ($row = pwg_db_fetch_assoc($result))
|
|
|
|
{
|
2011-11-05 00:54:12 +01:00
|
|
|
$infos_of_image[$row['id']] = $row;
|
2011-01-20 14:32:34 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-17 22:58:18 +01:00
|
|
|
|
|
|
|
foreach ($infos_of_image as &$info)
|
|
|
|
{
|
|
|
|
$info['src_image'] = new SrcImage($info);
|
|
|
|
}
|
|
|
|
unset($info);
|
2011-01-20 14:32:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count($user_representative_updates_for))
|
|
|
|
{
|
|
|
|
$updates = array();
|
|
|
|
|
|
|
|
foreach ($user_representative_updates_for as $user_cat => $image_id)
|
|
|
|
{
|
|
|
|
list($user_id, $cat_id) = explode('#', $user_cat);
|
|
|
|
|
|
|
|
array_push(
|
|
|
|
$updates,
|
|
|
|
array(
|
|
|
|
'user_id' => $user_id,
|
|
|
|
'cat_id' => $cat_id,
|
|
|
|
'user_representative_picture_id' => $image_id,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
mass_updates(
|
|
|
|
USER_CACHE_CATEGORIES_TABLE,
|
|
|
|
array(
|
|
|
|
'primary' => array('user_id', 'cat_id'),
|
|
|
|
'update' => array('user_representative_picture_id')
|
|
|
|
),
|
|
|
|
$updates
|
|
|
|
);
|
2006-11-08 04:01:28 +01:00
|
|
|
}
|
2006-04-08 21:42:11 +02:00
|
|
|
|
2006-11-08 04:01:28 +01:00
|
|
|
if (count($categories) > 0)
|
|
|
|
{
|
2006-12-21 22:38:20 +01:00
|
|
|
// Update filtered data
|
2007-01-15 01:09:14 +01:00
|
|
|
if (function_exists('update_cats_with_filtered_data'))
|
|
|
|
{
|
|
|
|
update_cats_with_filtered_data($categories);
|
|
|
|
}
|
2007-08-26 01:10:12 +02:00
|
|
|
|
2008-03-11 03:04:27 +01:00
|
|
|
$template->set_filename('index_category_thumbnails', 'mainpage_categories.tpl');
|
|
|
|
|
2007-03-08 02:55:49 +01:00
|
|
|
trigger_action('loc_begin_index_category_thumbnails', $categories);
|
2006-04-06 22:28:37 +02:00
|
|
|
|
2009-02-05 03:28:37 +01:00
|
|
|
$tpl_thumbnails_var = array();
|
|
|
|
|
2008-03-11 03:04:27 +01:00
|
|
|
foreach ($categories as $category)
|
|
|
|
{
|
2011-02-24 12:30:30 +01:00
|
|
|
if (0 == $category['count_images'])
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-07-12 16:57:24 +02:00
|
|
|
$category['name'] = trigger_event(
|
|
|
|
'render_category_name',
|
|
|
|
$category['name'],
|
|
|
|
'subcatify_category_name'
|
|
|
|
);
|
|
|
|
|
2008-03-11 03:04:27 +01:00
|
|
|
if ($page['section']=='recent_cats')
|
2006-04-06 22:28:37 +02:00
|
|
|
{
|
2008-03-11 03:04:27 +01:00
|
|
|
$name = get_cat_display_name_cache($category['uppercats'], null, false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$name = $category['name'];
|
|
|
|
}
|
2006-11-08 04:01:28 +01:00
|
|
|
|
2011-11-05 00:54:12 +01:00
|
|
|
$representative_infos = $infos_of_image[ $category['representative_picture_id'] ];
|
|
|
|
|
2008-03-11 03:04:27 +01:00
|
|
|
$tpl_var =
|
2006-04-06 22:28:37 +02:00
|
|
|
array(
|
2008-03-01 14:12:07 +01:00
|
|
|
'ID' => $category['id'],
|
2012-01-17 22:58:18 +01:00
|
|
|
'representative' => $representative_infos,
|
2008-09-10 03:16:13 +02:00
|
|
|
'TN_ALT' => strip_tags($category['name']),
|
2006-04-08 21:42:11 +02:00
|
|
|
|
2006-11-08 04:01:28 +01:00
|
|
|
'URL' => make_index_url(
|
2006-04-06 22:28:37 +02:00
|
|
|
array(
|
2007-02-27 02:56:16 +01:00
|
|
|
'category' => $category
|
2006-04-06 22:28:37 +02:00
|
|
|
)
|
|
|
|
),
|
2006-12-02 00:31:19 +01:00
|
|
|
'CAPTION_NB_IMAGES' => get_display_images_count
|
|
|
|
(
|
|
|
|
$category['nb_images'],
|
|
|
|
$category['count_images'],
|
2007-02-22 21:20:30 +01:00
|
|
|
$category['count_categories'],
|
|
|
|
true,
|
2009-03-09 20:41:45 +01:00
|
|
|
'<br>'
|
2006-12-02 00:31:19 +01:00
|
|
|
),
|
2007-08-26 01:10:12 +02:00
|
|
|
'DESCRIPTION' =>
|
2007-09-14 01:30:46 +02:00
|
|
|
trigger_event('render_category_literal_description',
|
|
|
|
trigger_event('render_category_description',
|
2007-11-29 14:08:38 +01:00
|
|
|
@$category['comment'],
|
|
|
|
'subcatify_category_description')),
|
2006-11-08 04:01:28 +01:00
|
|
|
'NAME' => $name,
|
2008-03-11 03:04:27 +01:00
|
|
|
);
|
2011-06-09 22:34:48 +02:00
|
|
|
if ($conf['index_new_icon'])
|
|
|
|
{
|
2011-07-01 23:14:04 +02:00
|
|
|
$tpl_var['icon_ts'] = get_icon($category['max_date_last'], $category['is_child_date_last']);
|
2011-06-09 22:34:48 +02:00
|
|
|
}
|
2007-04-22 15:11:56 +02:00
|
|
|
|
2008-03-11 03:04:27 +01:00
|
|
|
if ($conf['display_fromto'])
|
|
|
|
{
|
|
|
|
if (isset($dates_of_category[ $category['id'] ]))
|
2007-04-22 15:11:56 +02:00
|
|
|
{
|
2008-03-11 03:04:27 +01:00
|
|
|
$from = $dates_of_category[ $category['id'] ]['from'];
|
|
|
|
$to = $dates_of_category[ $category['id'] ]['to'];
|
|
|
|
|
|
|
|
if (!empty($from))
|
2007-04-22 15:11:56 +02:00
|
|
|
{
|
2008-03-11 03:04:27 +01:00
|
|
|
$info = '';
|
2007-09-14 01:30:46 +02:00
|
|
|
|
2008-03-11 03:04:27 +01:00
|
|
|
if ($from == $to)
|
2007-04-22 15:11:56 +02:00
|
|
|
{
|
2008-03-11 03:04:27 +01:00
|
|
|
$info = format_date($from);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$info = sprintf(
|
|
|
|
l10n('from %s to %s'),
|
|
|
|
format_date($from),
|
|
|
|
format_date($to)
|
|
|
|
);
|
2007-04-22 15:11:56 +02:00
|
|
|
}
|
2008-03-11 03:04:27 +01:00
|
|
|
$tpl_var['INFO_DATES'] = $info;
|
2007-04-22 15:11:56 +02:00
|
|
|
}
|
2006-11-08 04:01:28 +01:00
|
|
|
}
|
2008-03-11 03:04:27 +01:00
|
|
|
}//fromto
|
2006-04-08 21:42:11 +02:00
|
|
|
|
2009-02-05 03:28:37 +01:00
|
|
|
$tpl_thumbnails_var[] = $tpl_var;
|
2004-06-25 22:27:09 +02:00
|
|
|
}
|
2008-03-11 03:04:27 +01:00
|
|
|
|
2012-01-20 06:36:58 +01:00
|
|
|
$derivative_params = trigger_event('get_index_album_derivative_params', ImageStdParams::get_by_type(IMG_THUMB) );
|
2009-02-05 03:28:37 +01:00
|
|
|
$tpl_thumbnails_var = trigger_event('loc_end_index_category_thumbnails', $tpl_thumbnails_var, $categories);
|
2012-01-17 22:58:18 +01:00
|
|
|
$template->assign( array(
|
|
|
|
'category_thumbnails' => $tpl_thumbnails_var,
|
|
|
|
'derivative_params' => $derivative_params,
|
|
|
|
) );
|
2009-02-05 03:28:37 +01:00
|
|
|
|
2008-03-11 03:04:27 +01:00
|
|
|
$template->assign_var_from_handle('CATEGORIES', 'index_category_thumbnails');
|
2004-06-25 22:27:09 +02:00
|
|
|
}
|
2009-02-05 03:28:37 +01:00
|
|
|
pwg_debug('end include/category_cats.inc.php');
|
|
|
|
?>
|