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

Last change on this file since 1641 was 1641, checked in by rvelices, 17 years ago
  • remove #user_cache_categories.is_child_date_last
  • optimize code in get_icon
  • correct css font-wigth:italic to font-style:italic
  • aditionnal check on $confauthorize_remembering before allowing auto_login
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 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 1641 2006-12-07 23:21:54Z rvelices $
9// | last update   : $Date: 2006-12-07 23:21:54 +0000 (Thu, 07 Dec 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1641 $
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  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
37  $query = '
38SELECT
39  id,name, representative_picture_id, comment, nb_images, uppercats,
40  date_last, max_date_last, count_images, count_categories
41  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
42  ON id = cat_id and user_id = '.$user['id'].'
43  WHERE date_last > SUBDATE(
44    CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
45  );';
46}
47else
48{
49  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
50  $query = '
51SELECT
52  id,name, representative_picture_id, comment, nb_images,
53  date_last, max_date_last, count_images, count_categories
54  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
55  ON id = cat_id and user_id = '.$user['id'].'
56  WHERE id_uppercat '.
57  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
58  ORDER BY rank
59;';
60}
61
62$result = pwg_query($query);
63$categories = array();
64$image_ids = array();
65
66while ($row = mysql_fetch_assoc($result))
67{
68  $row['is_child_date_last'] = isset($row['date_last']) 
69      and $row['max_date_last']>$row['date_last'];
70
71  if (isset($row['representative_picture_id'])
72      and is_numeric($row['representative_picture_id']))
73  { // if a representative picture is set, it has priority
74    $image_id = $row['representative_picture_id'];
75  }
76  else if ($conf['allow_random_representative'])
77  {// searching a random representant among elements in sub-categories
78    $query = '
79SELECT image_id
80  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
81    ON ic.category_id = c.id
82  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
83    AND c.id NOT IN ('.$user['forbidden_categories'].')
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    }
92  }
93  else
94  { // searching a random representant among representant of sub-categories
95    $query = '
96SELECT representative_picture_id
97  FROM '.CATEGORIES_TABLE.'
98  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
99    AND id NOT IN ('.$user['forbidden_categories'].')
100    AND representative_picture_id IS NOT NULL
101  ORDER BY RAND()
102  LIMIT 0,1
103;';
104    $subresult = pwg_query($query);
105    if (mysql_num_rows($subresult) > 0)
106    {
107      list($image_id) = mysql_fetch_row($subresult);
108    }
109  }
110
111  if (isset($image_id))
112  {
113    $row['representative_picture_id'] = $image_id;
114    array_push($image_ids, $image_id);
115    array_push($categories, $row);
116  }
117  unset($image_id);
118}
119
120if (count($categories) > 0)
121{
122  $thumbnail_src_of = array();
123
124  $query = '
125SELECT id, path, tn_ext
126  FROM '.IMAGES_TABLE.'
127  WHERE id IN ('.implode(',', $image_ids).')
128;';
129  $result = pwg_query($query);
130  while ($row = mysql_fetch_assoc($result))
131  {
132    $thumbnail_src_of[$row['id']] = get_thumbnail_url($row);
133  }
134}
135
136if (count($categories) > 0)
137{
138  if ($conf['subcatify'])
139  {
140    $template->set_filenames(
141      array(
142        'mainpage_categories' => 'mainpage_categories.tpl',
143        )
144      );
145
146    foreach ($categories as $category)
147    {
148      $comment = strip_tags(@$category['comment'], '<a><br><p><b><i><small><strong><font>');
149      if ($page['section']=='recent_cats')
150      {
151        $name = get_cat_display_name_cache($category['uppercats'], null, false);
152      }
153      else
154      {
155        $name = $category['name'];
156      }
157
158      $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']);
159
160      $template->assign_block_vars(
161        'categories.category',
162        array(
163          'SRC'   => $thumbnail_src_of[$category['representative_picture_id']],
164          'ALT'   => $category['name'],
165          'TITLE' => $lang['hint_category'],
166          'ICON'  => $icon_ts,
167
168          'URL'   => make_index_url(
169            array(
170              'category' => $category['id'],
171              'cat_name' => $category['name'],
172              )
173            ),
174          'CAPTION_NB_IMAGES' => get_display_images_count
175                                  (
176                                    $category['nb_images'],
177                                    $category['count_images'],
178                                    $category['count_categories']
179                                  ),
180          'DESCRIPTION' => @$comment,
181          'NAME'  => $name,
182          )
183        );
184    }
185
186    $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories');
187  }
188  else
189  {
190    $template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
191    // first line
192    $template->assign_block_vars('thumbnails.line', array());
193    // current row displayed
194    $row_number = 0;
195
196    if ($page['section']=='recent_cats')
197    {
198      $old_level_separator = $conf['level_separator'];
199      $conf['level_separator'] = '<br />';
200    }
201
202    foreach ($categories as $category)
203    {
204      $template->assign_block_vars(
205        'thumbnails.line.thumbnail',
206        array(
207          'IMAGE'       => $thumbnail_src_of[ $category['representative_picture_id'] ],
208          'IMAGE_ALT'   => $category['name'],
209          'IMAGE_TITLE' => $lang['hint_category'],
210
211          'U_IMG_LINK'  => make_index_url(
212            array(
213              'category' => $category['id'],
214              'cat_name' => $category['name'],
215              )
216            ),
217          'CLASS'       => 'thumbCat',
218          )
219        );
220      if ($page['section']=='recent_cats')
221      {
222        $name = get_cat_display_name_cache($category['uppercats'], null, false);
223      }
224      else
225      {
226        $name = $category['name'];
227        $template->merge_block_vars(
228          'thumbnails.line.thumbnail',
229          array(
230            'IMAGE_TS'    => get_icon($category['max_date_last'], $category['is_child_date_last']),
231           )
232         );
233      }
234      $template->assign_block_vars(
235        'thumbnails.line.thumbnail.category_name',
236        array(
237          'NAME' => $name
238          )
239        );
240
241      // create a new line ?
242      if (++$row_number == $user['nb_image_line'])
243      {
244        $template->assign_block_vars('thumbnails.line', array());
245        $row_number = 0;
246      }
247    }
248
249    if ( isset($old_level_separator) )
250    {
251      $conf['level_separator']=$old_level_separator;
252    }
253
254    $template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
255  }
256}
257?>
Note: See TracBrowser for help on using the repository browser.