source: trunk/include/category_recent_cats.inc.php @ 1145

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

merge r1144 from branch-1_6 into trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 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-11 03:55:51 +0000 (Tue, 11 Apr 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1145 $
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>');
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        'NB_IMAGES' => $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  if (mysql_num_rows($result) > 0)
114  {
115    $template->assign_block_vars('thumbnails', array());
116    // first line
117    $template->assign_block_vars('thumbnails.line', array());
118    // current row displayed
119    $row_number = 0;
120  }
121
122  $old_level_separator = $conf['level_separator'];
123  $conf['level_separator'] = '<br />';
124  // for each category, we have to search a recent picture to display and
125  // the name to display
126  while ( $row = mysql_fetch_array( $result ) )
127  {
128    $template->assign_block_vars(
129      'thumbnails.line.thumbnail',
130      array(
131        'IMAGE'       => get_thumbnail_src($row['path'], @$row['tn_ext']),
132        'IMAGE_ALT'   => $row['file'],
133        'IMAGE_TITLE' => $lang['hint_category'],
134
135        'U_IMG_LINK'  => make_index_url(
136          array(
137            'category' => $row['category_id'],
138            'cat_name' => $row['cat_name'],
139            )
140          ),
141        )
142      );
143
144    $template->assign_block_vars(
145      'thumbnails.line.thumbnail.category_name',
146      array(
147        'NAME' => get_cat_display_name_cache($row['uppercats'], null, false),
148        )
149      );
150
151    // create a new line ?
152    if (++$row_number == $user['nb_image_line'])
153    {
154      $template->assign_block_vars('thumbnails.line', array());
155      $row_number = 0;
156    }
157  }
158  $conf['level_separator'] = $old_level_separator;
159}
160?>
Note: See TracBrowser for help on using the repository browser.