source: branches/1.6/include/category_recent_cats.inc.php @ 16715

Last change on this file since 16715 was 1406, checked in by rvelices, 18 years ago

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: 5.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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-06-27 00:37:18 +0000 (Tue, 27 Jun 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1406 $
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 recent_cats
30 * category
31 *
32 */
33
34// FIXME: categories having no representant
35// ($conf['allow_random_representative'] = true) are not displayed :-/
36
37// retrieving categories recently update, ie containing pictures added
38// recently. The calculated table field categories.date_last will be
39// easier to use
40$query = '
41SELECT c.id AS category_id
42       , uppercats
43       , representative_picture_id
44       , path
45       , file
46       , c.comment
47       , tn_ext
48       , nb_images
49       , c.name AS cat_name
50  FROM '.CATEGORIES_TABLE.' AS c
51    INNER JOIN '.IMAGES_TABLE.' AS i ON i.id = c.representative_picture_id
52  WHERE date_last > SUBDATE(
53    CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
54  )';
55if ( $user['forbidden_categories'] != '' )
56{
57  $query.= '
58    AND c.id NOT IN ('.$user['forbidden_categories'].')';
59}
60$query.= '
61;';
62$result = pwg_query( $query );
63
64if ($conf['subcatify'])
65{
66  $template->set_filenames(
67    array(
68      'mainpage_categories' => 'mainpage_categories.tpl',
69      )
70    );
71
72  // template thumbnail initialization
73  if (mysql_num_rows($result) > 0)
74  {
75    $template->assign_block_vars('categories', array());
76  }
77
78  $comment = null;
79  if (isset($row['comment']))
80  {
81    $comment = strip_tags($row['comment'], '<a><br><p><b><i><small><strong><font>');
82  }
83
84  // for each category, we have to search a recent picture to display and
85  // the name to display
86  while ( $row = mysql_fetch_array( $result ) )
87  {
88    $template->assign_block_vars(
89      'categories.category',
90      array(
91        'SRC'       => get_thumbnail_src($row['path'], @$row['tn_ext']),
92        'ALT'   => $row['file'],
93        'TITLE' => $lang['hint_category'],
94
95        'URL'  => make_index_url(
96          array(
97            'category' => $row['category_id'],
98            'cat_name' => $row['cat_name'],
99            )
100          ),
101        'NAME' => get_cat_display_name_cache($row['uppercats'], null, false),
102        'CAPTION_NB_IMAGES' => (($row['nb_images'] == 0) ? '' : sprintf("%d ".l10n('pictures'), $row['nb_images'])),
103        'DESCRIPTION' => $comment,
104        )
105      );
106  }
107
108  $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories');
109}
110else
111{
112  // template thumbnail initialization
113  $template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
114  if (mysql_num_rows($result) > 0)
115  {
116    $template->assign_block_vars('thumbnails', array());
117    // first line
118    $template->assign_block_vars('thumbnails.line', array());
119    // current row displayed
120    $row_number = 0;
121  }
122
123  $old_level_separator = $conf['level_separator'];
124  $conf['level_separator'] = '<br />';
125  // for each category, we have to search a recent picture to display and
126  // the name to display
127  while ( $row = mysql_fetch_array( $result ) )
128  {
129    $template->assign_block_vars(
130      'thumbnails.line.thumbnail',
131      array(
132        'IMAGE'       => get_thumbnail_src($row['path'], @$row['tn_ext']),
133        'IMAGE_ALT'   => $row['file'],
134        'IMAGE_TITLE' => $lang['hint_category'],
135
136        'U_IMG_LINK'  => make_index_url(
137          array(
138            'category' => $row['category_id'],
139            'cat_name' => $row['cat_name'],
140            )
141          ),
142        )
143      );
144
145    $template->assign_block_vars(
146      'thumbnails.line.thumbnail.category_name',
147      array(
148        'NAME' => get_cat_display_name_cache($row['uppercats'], null, false),
149        )
150      );
151
152    // create a new line ?
153    if (++$row_number == $user['nb_image_line'])
154    {
155      $template->assign_block_vars('thumbnails.line', array());
156      $row_number = 0;
157    }
158  }
159  $conf['level_separator'] = $old_level_separator;
160  $template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
161}
162?>
Note: See TracBrowser for help on using the repository browser.