source: trunk/include/category_subcats.inc.php @ 1479

Last change on this file since 1479 was 1407, checked in by rvelices, 18 years ago

merge -r1046 from branch-1_6 to trunk
bug 436: Category thumbnail display not ok if subcatify is false

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
RevLine 
[440]1<?php
2// +-----------------------------------------------------------------------+
[593]3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[675]5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
[440]6// +-----------------------------------------------------------------------+
[593]7// | branch        : BSF (Best So Far)
[440]8// | file          : $RCSfile$
9// | last update   : $Date: 2006-06-27 00:38:19 +0000 (Tue, 27 Jun 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1407 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28/**
[1082]29 * This file is included by the main page to show thumbnails for a category
[440]30 * that have only subcategories
[1131]31 *
[440]32 */
33
[610]34$query = '
[1130]35SELECT id, name, date_last, representative_picture_id, comment, nb_images
[610]36  FROM '.CATEGORIES_TABLE.'
[1082]37  WHERE id_uppercat '.
38  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
[809]39    AND id NOT IN ('.$user['forbidden_categories'].')
[610]40  ORDER BY rank
41;';
42$result = pwg_query($query);
[440]43
[809]44// $conf['allow_random_representative']
[587]45
[1132]46$categories = array();
47$image_ids = array();
[809]48
[610]49while ($row = mysql_fetch_array($result))
[440]50{
[809]51  if (isset($row['representative_picture_id'])
52      and is_numeric($row['representative_picture_id']))
[659]53  {
[809]54    // if a representative picture is set, it has priority
55    $image_id = $row['representative_picture_id'];
[659]56  }
[809]57  else if ($conf['allow_random_representative'])
58  {
59    // searching a random representant among elements in sub-categories
60    $query = '
61SELECT image_id
62  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
63    ON ic.category_id = c.id
64  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
65    AND c.id NOT IN ('.$user['forbidden_categories'].')
[610]66  ORDER BY RAND()
67  LIMIT 0,1
[440]68;';
[809]69    $subresult = pwg_query($query);
70    if (mysql_num_rows($result) > 0)
71    {
72      list($image_id) = mysql_fetch_row($subresult);
73    }
74  }
75  else
[440]76  {
[809]77    // searching a random representant among representant of sub-categories
78    $query = '
79SELECT representative_picture_id
80  FROM '.CATEGORIES_TABLE.'
81  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
82    AND id NOT IN ('.$user['forbidden_categories'].')
83    AND representative_picture_id IS NOT NULL
84  ORDER BY RAND()
85  LIMIT 0,1
86;';
87    $subresult = pwg_query($query);
88    if (mysql_num_rows($subresult) > 0)
89    {
90      list($image_id) = mysql_fetch_row($subresult);
91    }
[440]92  }
93
[1131]94  $comment = null;
[1132]95  if (isset($row['comment']))
[1131]96  {
[1354]97    $comment = strip_tags($row['comment'], '<a><br><p><b><i><small><strong><font>');
[1131]98  }
99
[809]100  if (isset($image_id))
101  {
102    array_push(
[1132]103      $categories,
[809]104      array(
[1132]105        'category'    => $row['id'],
106        'picture'     => $image_id,
107        'name'        => $row['name'],
108        'date_last'   => @$row['date_last'],
109        'comment'     => $comment,
110        'nb_images'   => $row['nb_images'],
[809]111        )
112      );
[1132]113
114    array_push($image_ids, $image_id);
[809]115  }
[440]116
[809]117  unset($image_id);
118}
[440]119
[1132]120if (count($image_ids) > 0)
[809]121{
[1132]122  $thumbnail_src_of = array();
[1131]123
[809]124  $query = '
125SELECT id, path, tn_ext
126  FROM '.IMAGES_TABLE.'
[1132]127  WHERE id IN ('.implode(',', $image_ids).')
[809]128;';
129  $result = pwg_query($query);
130  while ($row = mysql_fetch_array($result))
131  {
[1132]132    $thumbnail_src_of[$row['id']] =
133      get_thumbnail_src($row['path'], @$row['tn_ext']);
[809]134  }
[1135]135
[1132]136  if ($conf['subcatify'])
[809]137  {
[1132]138    $template->set_filenames(
[809]139      array(
[1132]140        'mainpage_categories' => 'mainpage_categories.tpl',
[809]141        )
142      );
[1132]143
144    $template->assign_block_vars('categories', array());
[1135]145
[1132]146    foreach ($categories as $category)
147    {
148      $template->assign_block_vars(
149        'categories.category',
150        array(
151          'SRC'   => $thumbnail_src_of[ $category['picture'] ],
[1290]152          'ALT'   => $category['name'],
[1132]153          'TITLE' => $lang['hint_category'],
154          'ICON'  => get_icon(@$category['date_last']),
[1135]155
[1132]156          'URL' => make_index_url(
157            array(
158              'category' => $category['category'],
159              'cat_name' => $category['name'],
160              )
161            ),
[1290]162          'NAME' => $category['name'],
[1172]163          'CAPTION_NB_IMAGES' => (($category['nb_images'] == 0) ? '' : sprintf("%d ".l10n('pictures'), $category['nb_images'])),
[1274]164          'DESCRIPTION' => @$category['comment'],
[1132]165          )
166        );
167    }
[1135]168
[1132]169    $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories');
[440]170  }
[1132]171  else
172  {
[1407]173    $template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
[1132]174    $template->assign_block_vars('thumbnails', array());
175    // first line
176    $template->assign_block_vars('thumbnails.line', array());
177    // current row displayed
178    $row_number = 0;
[1135]179
[1132]180    foreach ($categories as $category)
181    {
182      $template->assign_block_vars(
183        'thumbnails.line.thumbnail',
184        array(
185          'IMAGE'       => $thumbnail_src_of[ $category['picture'] ],
186          'IMAGE_ALT'   => $category['name'],
187          'IMAGE_TITLE' => $lang['hint_category'],
188          'IMAGE_TS'    => get_icon(@$category['date_last']),
[1135]189
[1132]190          'U_IMG_LINK'  => make_index_url(
191            array(
192              'category' => $category['category'],
[1135]193              'cat_name' => $category['name'],
[1132]194              )
195            ),
196          'CLASS'       => 'thumbCat',
197          )
198        );
199
200      $template->assign_block_vars(
201        'thumbnails.line.thumbnail.category_name',
202        array(
203          'NAME' => $category['name']
204          )
205        );
[1135]206
[1132]207      // create a new line ?
208      if (++$row_number == $user['nb_image_line'])
209      {
210        $template->assign_block_vars('thumbnails.line', array());
211        $row_number = 0;
212      }
213    }
[1407]214    $template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
[1132]215  }
[440]216}
[1259]217?>
Note: See TracBrowser for help on using the repository browser.