source: trunk/include/category_cats.inc.php @ 1609

Last change on this file since 1609 was 1597, checked in by rvelices, 18 years ago
  • merge category_recent_cats and category_subcats into category_cats (a lot

of common code,and now representative selection works for recent cats...)

  • some replacements of get_thumbnail_src with get_thumbnail_url
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $Id: category_cats.inc.php 1597 2006-11-08 03:01:28Z rvelices $
9// | last update   : $Date: 2006-11-08 03:01:28 +0000 (Wed, 08 Nov 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1597 $
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/**
29 * This file is included by the main page to show thumbnails for a category
30 * that have only subcategories or to show recent categories
31 *
32 */
33
34if ($page['section']=='recent_cats')
35{
36  $query = '
37SELECT id,name,date_last,representative_picture_id,comment,nb_images,uppercats
38  FROM '.CATEGORIES_TABLE.'
39  WHERE date_last > SUBDATE(
40    CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
41  )
42  AND id NOT IN ('.$user['forbidden_categories'].')';
43}
44else
45{
46  $query = '
47SELECT id,name,date_last,representative_picture_id,comment,nb_images
48  FROM '.CATEGORIES_TABLE.'
49  WHERE id_uppercat '.
50  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
51    AND id NOT IN ('.$user['forbidden_categories'].')
52  ORDER BY rank
53;';
54}
55
56$result = pwg_query($query);
57$categories = array();
58$image_ids = array();
59
60while ($row = mysql_fetch_assoc($result))
61{
62  if (isset($row['representative_picture_id'])
63      and is_numeric($row['representative_picture_id']))
64  { // if a representative picture is set, it has priority
65    $image_id = $row['representative_picture_id'];
66  }
67  else if ($conf['allow_random_representative'])
68  {// searching a random representant among elements in sub-categories
69    $query = '
70SELECT image_id
71  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
72    ON ic.category_id = c.id
73  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
74    AND c.id NOT IN ('.$user['forbidden_categories'].')
75  ORDER BY RAND()
76  LIMIT 0,1
77;';
78    $subresult = pwg_query($query);
79    if (mysql_num_rows($subresult) > 0)
80    {
81      list($image_id) = mysql_fetch_row($subresult);
82    }
83  }
84  else
85  { // searching a random representant among representant of sub-categories
86    $query = '
87SELECT representative_picture_id
88  FROM '.CATEGORIES_TABLE.'
89  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
90    AND id NOT IN ('.$user['forbidden_categories'].')
91    AND representative_picture_id IS NOT NULL
92  ORDER BY RAND()
93  LIMIT 0,1
94;';
95    $subresult = pwg_query($query);
96    if (mysql_num_rows($subresult) > 0)
97    {
98      list($image_id) = mysql_fetch_row($subresult);
99    }
100  }
101
102  if (isset($image_id))
103  {
104    $row['representative_picture_id'] = $image_id;
105    array_push($image_ids, $image_id);
106    array_push($categories, $row);
107  }
108  unset($image_id);
109}
110
111if (count($categories) > 0)
112{
113  $thumbnail_src_of = array();
114
115  $query = '
116SELECT id, path, tn_ext
117  FROM '.IMAGES_TABLE.'
118  WHERE id IN ('.implode(',', $image_ids).')
119;';
120  $result = pwg_query($query);
121  while ($row = mysql_fetch_assoc($result))
122  {
123    $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
124  }
125}
126
127if (count($categories) > 0)
128{
129  if ($conf['subcatify'])
130  {
131    $template->set_filenames(
132      array(
133        'mainpage_categories' => 'mainpage_categories.tpl',
134        )
135      );
136
137    foreach ($categories as $category)
138    {
139      $comment = strip_tags(@$category['comment'], '<a><br><p><b><i><small><strong><font>');
140      if ($page['section']=='recent_cats')
141      {
142        $name = get_cat_display_name_cache($category['uppercats'], null, false);
143        $icon_ts = '';
144      }
145      else
146      {
147        $name = $category['name'];
148        $icon_ts = get_icon(@$category['date_last']);
149      }
150
151      $template->assign_block_vars(
152        'categories.category',
153        array(
154          'SRC'   => $thumbnail_src_of[$category['representative_picture_id']],
155          'ALT'   => $category['name'],
156          'TITLE' => $lang['hint_category'],
157          'ICON'  => $icon_ts,
158
159          'URL'   => make_index_url(
160            array(
161              'category' => $category['id'],
162              'cat_name' => $category['name'],
163              )
164            ),
165          'CAPTION_NB_IMAGES' => (($category['nb_images'] == 0) ? '' : sprintf("%d ".l10n('pictures'), $category['nb_images'])),
166          'DESCRIPTION' => @$comment,
167          'NAME'  => $name,
168          )
169        );
170    }
171
172    $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories');
173  }
174  else
175  {
176    $template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
177    // first line
178    $template->assign_block_vars('thumbnails.line', array());
179    // current row displayed
180    $row_number = 0;
181
182    if ($page['section']=='recent_cats')
183    {
184      $old_level_separator = $conf['level_separator'];
185      $conf['level_separator'] = '<br />';
186    }
187
188    foreach ($categories as $category)
189    {
190      $template->assign_block_vars(
191        'thumbnails.line.thumbnail',
192        array(
193          'IMAGE'       => $thumbnail_src_of[ $category['representative_picture_id'] ],
194          'IMAGE_ALT'   => $category['name'],
195          'IMAGE_TITLE' => $lang['hint_category'],
196
197          'U_IMG_LINK'  => make_index_url(
198            array(
199              'category' => $category['id'],
200              'cat_name' => $category['name'],
201              )
202            ),
203          'CLASS'       => 'thumbCat',
204          )
205        );
206      if ($page['section']=='recent_cats')
207      {
208        $name = get_cat_display_name_cache($category['uppercats'], null, false);
209      }
210      else
211      {
212        $name = $category['name'];
213        $template->merge_block_vars(
214          'thumbnails.line.thumbnail',
215          array(
216            'IMAGE_TS'    => get_icon(@$category['date_last']),
217           )
218         );
219      }
220      $template->assign_block_vars(
221        'thumbnails.line.thumbnail.category_name',
222        array(
223          'NAME' => $name
224          )
225        );
226
227      // create a new line ?
228      if (++$row_number == $user['nb_image_line'])
229      {
230        $template->assign_block_vars('thumbnails.line', array());
231        $row_number = 0;
232      }
233    }
234
235    if ( isset($old_level_separator) )
236    {
237      $conf['level_separator']=$old_level_separator;
238    }
239
240    $template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
241  }
242}
243?>
Note: See TracBrowser for help on using the repository browser.