2004-06-25 20:27:09 +00:00
|
|
|
<?php
|
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-06 21:12:59 +00:00
|
|
|
// | PhpWebGallery - a PHP based picture gallery |
|
|
|
|
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
|
2005-01-07 23:10:51 +00:00
|
|
|
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
|
2004-06-25 20:27:09 +00:00
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-06 21:12:59 +00:00
|
|
|
// | branch : BSF (Best So Far)
|
2004-06-25 20:27:09 +00: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. |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
|
|
|
|
/**
|
2006-03-15 22:44:35 +00:00
|
|
|
* This file is included by the main page to show thumbnails for a category
|
2004-06-25 20:27:09 +00:00
|
|
|
* that have only subcategories
|
2006-04-06 02:23:54 +00:00
|
|
|
*
|
2004-06-25 20:27:09 +00:00
|
|
|
*/
|
|
|
|
|
2004-11-20 17:23:42 +00:00
|
|
|
$query = '
|
2006-04-05 23:08:37 +00:00
|
|
|
SELECT id, name, date_last, representative_picture_id, comment, nb_images
|
2004-11-20 17:23:42 +00:00
|
|
|
FROM '.CATEGORIES_TABLE.'
|
2006-03-15 22:44:35 +00:00
|
|
|
WHERE id_uppercat '.
|
|
|
|
(!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
|
2005-08-13 23:09:54 +00:00
|
|
|
AND id NOT IN ('.$user['forbidden_categories'].')
|
2004-11-20 17:23:42 +00:00
|
|
|
ORDER BY rank
|
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
2004-06-25 20:27:09 +00:00
|
|
|
|
2005-08-13 23:09:54 +00:00
|
|
|
// $conf['allow_random_representative']
|
|
|
|
|
2006-04-06 20:28:37 +00:00
|
|
|
$categories = array();
|
|
|
|
$image_ids = array();
|
2004-10-30 15:42:29 +00:00
|
|
|
|
2004-11-20 17:23:42 +00:00
|
|
|
while ($row = mysql_fetch_array($result))
|
2004-06-25 20:27:09 +00:00
|
|
|
{
|
2005-08-13 23:09:54 +00:00
|
|
|
if (isset($row['representative_picture_id'])
|
|
|
|
and is_numeric($row['representative_picture_id']))
|
2004-12-27 14:30:49 +00:00
|
|
|
{
|
2005-08-13 23:09:54 +00:00
|
|
|
// if a representative picture is set, it has priority
|
|
|
|
$image_id = $row['representative_picture_id'];
|
2004-12-27 14:30:49 +00:00
|
|
|
}
|
2005-08-13 23:09:54 +00:00
|
|
|
else if ($conf['allow_random_representative'])
|
|
|
|
{
|
|
|
|
// searching a random representant among elements in sub-categories
|
|
|
|
$query = '
|
|
|
|
SELECT image_id
|
|
|
|
FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
|
|
|
|
ON ic.category_id = c.id
|
|
|
|
WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
|
|
|
|
AND c.id NOT IN ('.$user['forbidden_categories'].')
|
2004-11-20 17:23:42 +00:00
|
|
|
ORDER BY RAND()
|
|
|
|
LIMIT 0,1
|
2004-06-25 20:27:09 +00:00
|
|
|
;';
|
2005-08-13 23:09:54 +00:00
|
|
|
$subresult = pwg_query($query);
|
|
|
|
if (mysql_num_rows($result) > 0)
|
|
|
|
{
|
|
|
|
list($image_id) = mysql_fetch_row($subresult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2004-06-25 20:27:09 +00:00
|
|
|
{
|
2005-08-13 23:09:54 +00:00
|
|
|
// searching a random representant among representant of sub-categories
|
|
|
|
$query = '
|
|
|
|
SELECT representative_picture_id
|
|
|
|
FROM '.CATEGORIES_TABLE.'
|
|
|
|
WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
|
|
|
|
AND id NOT IN ('.$user['forbidden_categories'].')
|
|
|
|
AND representative_picture_id IS NOT NULL
|
|
|
|
ORDER BY RAND()
|
|
|
|
LIMIT 0,1
|
|
|
|
;';
|
|
|
|
$subresult = pwg_query($query);
|
|
|
|
if (mysql_num_rows($subresult) > 0)
|
|
|
|
{
|
|
|
|
list($image_id) = mysql_fetch_row($subresult);
|
|
|
|
}
|
2004-06-25 20:27:09 +00:00
|
|
|
}
|
|
|
|
|
2006-04-06 02:23:54 +00:00
|
|
|
$comment = null;
|
2006-04-06 20:28:37 +00:00
|
|
|
if (isset($row['comment']))
|
2006-04-06 02:23:54 +00:00
|
|
|
{
|
2006-06-14 00:56:22 +00:00
|
|
|
$comment = strip_tags($row['comment'], '<a><br><p><b><i><small><strong><font>');
|
2006-04-06 02:23:54 +00:00
|
|
|
}
|
|
|
|
|
2005-08-13 23:09:54 +00:00
|
|
|
if (isset($image_id))
|
|
|
|
{
|
|
|
|
array_push(
|
2006-04-06 20:28:37 +00:00
|
|
|
$categories,
|
2005-08-13 23:09:54 +00:00
|
|
|
array(
|
2006-04-06 20:28:37 +00:00
|
|
|
'category' => $row['id'],
|
|
|
|
'picture' => $image_id,
|
|
|
|
'name' => $row['name'],
|
|
|
|
'date_last' => @$row['date_last'],
|
|
|
|
'comment' => $comment,
|
|
|
|
'nb_images' => $row['nb_images'],
|
2005-08-13 23:09:54 +00:00
|
|
|
)
|
|
|
|
);
|
2006-04-06 20:28:37 +00:00
|
|
|
|
|
|
|
array_push($image_ids, $image_id);
|
2005-08-13 23:09:54 +00:00
|
|
|
}
|
2004-06-25 20:27:09 +00:00
|
|
|
|
2005-08-13 23:09:54 +00:00
|
|
|
unset($image_id);
|
|
|
|
}
|
2004-06-25 20:27:09 +00:00
|
|
|
|
2006-04-06 20:28:37 +00:00
|
|
|
if (count($image_ids) > 0)
|
2005-08-13 23:09:54 +00:00
|
|
|
{
|
2006-04-06 20:28:37 +00:00
|
|
|
$thumbnail_src_of = array();
|
2005-03-26 22:35:07 +00:00
|
|
|
|
2005-08-13 23:09:54 +00:00
|
|
|
$query = '
|
|
|
|
SELECT id, path, tn_ext
|
|
|
|
FROM '.IMAGES_TABLE.'
|
2006-04-06 20:28:37 +00:00
|
|
|
WHERE id IN ('.implode(',', $image_ids).')
|
2005-08-13 23:09:54 +00:00
|
|
|
;';
|
|
|
|
$result = pwg_query($query);
|
|
|
|
while ($row = mysql_fetch_array($result))
|
|
|
|
{
|
2006-04-06 20:28:37 +00:00
|
|
|
$thumbnail_src_of[$row['id']] =
|
|
|
|
get_thumbnail_src($row['path'], @$row['tn_ext']);
|
2005-08-13 23:09:54 +00:00
|
|
|
}
|
2006-04-08 19:42:11 +00:00
|
|
|
|
2006-04-06 20:28:37 +00:00
|
|
|
if ($conf['subcatify'])
|
2004-06-25 20:27:09 +00:00
|
|
|
{
|
2006-04-06 20:28:37 +00:00
|
|
|
$template->set_filenames(
|
2005-08-13 23:09:54 +00:00
|
|
|
array(
|
2006-04-06 20:28:37 +00:00
|
|
|
'mainpage_categories' => 'mainpage_categories.tpl',
|
2005-08-13 23:09:54 +00:00
|
|
|
)
|
|
|
|
);
|
2006-04-06 20:28:37 +00:00
|
|
|
|
|
|
|
$template->assign_block_vars('categories', array());
|
2006-04-08 19:42:11 +00:00
|
|
|
|
2006-04-06 20:28:37 +00:00
|
|
|
foreach ($categories as $category)
|
|
|
|
{
|
|
|
|
$template->assign_block_vars(
|
|
|
|
'categories.category',
|
|
|
|
array(
|
|
|
|
'SRC' => $thumbnail_src_of[ $category['picture'] ],
|
2006-04-29 10:29:32 +00:00
|
|
|
'ALT' => $category['name'],
|
2006-04-06 20:28:37 +00:00
|
|
|
'TITLE' => $lang['hint_category'],
|
|
|
|
'ICON' => get_icon(@$category['date_last']),
|
2006-04-08 19:42:11 +00:00
|
|
|
|
2006-04-06 20:28:37 +00:00
|
|
|
'URL' => make_index_url(
|
|
|
|
array(
|
|
|
|
'category' => $category['category'],
|
|
|
|
'cat_name' => $category['name'],
|
|
|
|
)
|
|
|
|
),
|
2006-04-29 10:29:32 +00:00
|
|
|
'NAME' => $category['name'],
|
2006-04-14 21:11:56 +00:00
|
|
|
'CAPTION_NB_IMAGES' => (($category['nb_images'] == 0) ? '' : sprintf("%d ".l10n('pictures'), $category['nb_images'])),
|
2006-04-26 01:56:35 +00:00
|
|
|
'DESCRIPTION' => @$category['comment'],
|
2006-04-06 20:28:37 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2006-04-08 19:42:11 +00:00
|
|
|
|
2006-04-06 20:28:37 +00:00
|
|
|
$template->assign_var_from_handle('CATEGORIES', 'mainpage_categories');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-27 00:38:19 +00:00
|
|
|
$template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
|
2006-04-06 20:28:37 +00:00
|
|
|
$template->assign_block_vars('thumbnails', array());
|
|
|
|
// first line
|
|
|
|
$template->assign_block_vars('thumbnails.line', array());
|
|
|
|
// current row displayed
|
|
|
|
$row_number = 0;
|
2006-04-08 19:42:11 +00:00
|
|
|
|
2006-04-06 20:28:37 +00:00
|
|
|
foreach ($categories as $category)
|
|
|
|
{
|
|
|
|
$template->assign_block_vars(
|
|
|
|
'thumbnails.line.thumbnail',
|
|
|
|
array(
|
|
|
|
'IMAGE' => $thumbnail_src_of[ $category['picture'] ],
|
|
|
|
'IMAGE_ALT' => $category['name'],
|
|
|
|
'IMAGE_TITLE' => $lang['hint_category'],
|
|
|
|
'IMAGE_TS' => get_icon(@$category['date_last']),
|
2006-04-08 19:42:11 +00:00
|
|
|
|
2006-04-06 20:28:37 +00:00
|
|
|
'U_IMG_LINK' => make_index_url(
|
|
|
|
array(
|
|
|
|
'category' => $category['category'],
|
2006-04-08 19:42:11 +00:00
|
|
|
'cat_name' => $category['name'],
|
2006-04-06 20:28:37 +00:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'CLASS' => 'thumbCat',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$template->assign_block_vars(
|
|
|
|
'thumbnails.line.thumbnail.category_name',
|
|
|
|
array(
|
|
|
|
'NAME' => $category['name']
|
|
|
|
)
|
|
|
|
);
|
2006-04-08 19:42:11 +00:00
|
|
|
|
2006-04-06 20:28:37 +00:00
|
|
|
// create a new line ?
|
|
|
|
if (++$row_number == $user['nb_image_line'])
|
|
|
|
{
|
|
|
|
$template->assign_block_vars('thumbnails.line', array());
|
|
|
|
$row_number = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-06-27 00:38:19 +00:00
|
|
|
$template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
|
2004-06-25 20:27:09 +00:00
|
|
|
}
|
|
|
|
}
|
2006-04-22 15:25:59 +00:00
|
|
|
?>
|