source: branches/branch-1_6/include/category_recent_cats.inc.php @ 1133

Last change on this file since 1133 was 1132, checked in by plg, 19 years ago

modification: "subcatify" becomes optionnal. Enabled by default, easy to
revert to previous display.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 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-04-06 20:28:37 +0000 (Thu, 06 Apr 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1132 $
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  FROM '.CATEGORIES_TABLE.' AS c
50    INNER JOIN '.IMAGES_TABLE.' AS i ON i.id = c.representative_picture_id
51  WHERE date_last > SUBDATE(
52    CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
53  )';
54if ( $user['forbidden_categories'] != '' )
55{
56  $query.= '
57    AND c.id NOT IN ('.$user['forbidden_categories'].')';
58}
59$query.= '
60;';
61$result = pwg_query( $query );
62
63if ($conf['subcatify'])
64{
65  $template->set_filenames(
66    array(
67      'mainpage_categories' => 'mainpage_categories.tpl',
68      )
69    );
70 
71  // template thumbnail initialization
72  if (mysql_num_rows($result) > 0)
73  {
74    $template->assign_block_vars('categories', array());
75  }
76
77  // for each category, we have to search a recent picture to display and
78  // the name to display
79  while ( $row = mysql_fetch_array( $result ) )
80  {
81    $template->assign_block_vars(
82      'categories.category',
83      array(
84        'SRC'       => get_thumbnail_src($row['path'], @$row['tn_ext']),
85        'ALT'   => $row['file'],
86        'TITLE' => $lang['hint_category'],
87       
88        'URL'  => make_index_url(
89          array(
90            'category' => $row['category_id'],
91            )
92          ),
93        'NAME' => get_cat_display_name_cache($row['uppercats'], null, false),
94        'NB_IMAGES' => $row['nb_images'],
95        'DESCRIPTION' => @$row['comment'],
96        )
97      );
98  }
99
100  $template->assign_var_from_handle('CATEGORIES', 'mainpage_categories');
101}
102else
103{
104  // template thumbnail initialization
105  if (mysql_num_rows($result) > 0)
106  {
107    $template->assign_block_vars('thumbnails', array());
108    // first line
109    $template->assign_block_vars('thumbnails.line', array());
110    // current row displayed
111    $row_number = 0;
112  }
113 
114  $old_level_separator = $conf['level_separator'];
115  $conf['level_separator'] = '<br />';
116  // for each category, we have to search a recent picture to display and
117  // the name to display
118  while ( $row = mysql_fetch_array( $result ) )
119  {
120    $template->assign_block_vars(
121      'thumbnails.line.thumbnail',
122      array(
123        'IMAGE'       => get_thumbnail_src($row['path'], @$row['tn_ext']),
124        'IMAGE_ALT'   => $row['file'],
125        'IMAGE_TITLE' => $lang['hint_category'],
126       
127        'U_IMG_LINK'  => make_index_url(
128          array(
129            'category' => $row['category_id'],
130            )
131          ),
132        )
133      );
134
135    $template->assign_block_vars(
136      'thumbnails.line.thumbnail.category_name',
137      array(
138        'NAME' => get_cat_display_name_cache($row['uppercats'], null, false),
139        )
140      );
141
142    // create a new line ?
143    if (++$row_number == $user['nb_image_line'])
144    {
145      $template->assign_block_vars('thumbnails.line', array());
146      $row_number = 0;
147    }
148  }
149  $conf['level_separator'] = $old_level_separator;
150}
151?>
Note: See TracBrowser for help on using the repository browser.