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

Last change on this file since 637 was 610, checked in by plg, 20 years ago
  • optimization : representative picture becomes mandatory for a non empty category. So, at each insertion in images table for a category, a new representative element is elected (by rand). This must be improved by not reelcting a random picture admin set an element as representative manually.
  • optimization : recent cats page only needs 2 queries instead of 3*N (N categories to display). The bad point is that it shows representative element of recent cat and not a random element among recently added.
  • optimization : empty cats page only needs 1 query per non empty sub category instead of... a lot. For each sub category, PhpWebGallery shows the representative element of a category chosen randomly in sub cats. Thus, get_non_empty_subcat_ids and get_first_non_empty_cat_id becomes obsolete.
  • new function get_cat_display_name_cache to show category names with a caching for all gallery categories names. This function, to the contrary of get_cat_display_name shows names in the correct order...
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-11-20 17:23:42 +0000 (Sat, 20 Nov 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 610 $
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 category.php to show thumbnails for recent_cats
30 * category
31 *
32 */
33
34// retrieving categories recently update, ie containing pictures added
35// recently. The calculated table field categories.date_last will be
36// easier to use
37$query = '
38SELECT c.id AS category_id,uppercats,representative_picture_id,path,file,tn_ext
39  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGES_TABLE.' AS i
40    ON i.id = c.representative_picture_id
41  WHERE date_last > SUBDATE(CURRENT_DATE
42                            ,INTERVAL '.$user['recent_period'].' DAY)';
43if ( $user['forbidden_categories'] != '' )
44{
45  $query.= '
46    AND id NOT IN ('.$user['forbidden_categories'].')';
47}
48$query.= '
49;';
50$result = pwg_query( $query );
51
52// template thumbnail initialization
53if (mysql_num_rows($result) > 0)
54{
55  $template->assign_block_vars('thumbnails', array());
56  // first line
57  $template->assign_block_vars('thumbnails.line', array());
58  // current row displayed
59  $row_number = 0;
60}
61
62// for each category, we have to search a recent picture to display and
63// the name to display
64while ( $row = mysql_fetch_array( $result ) )
65{
66  $name = get_cat_display_name_cache($row['uppercats'], '<br />', '', false);
67
68  $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
69 
70  $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['category_id'];
71 
72  $template->assign_block_vars(
73    'thumbnails.line.thumbnail',
74    array(
75      'IMAGE'                   => $thumbnail_src,
76      'IMAGE_ALT'               => $row['file'],
77      'IMAGE_TITLE'             => $lang['hint_category'],
78      'IMAGE_NAME'              => '['.$name.']',
79      'IMAGE_STYLE'             => 'thumb_category',
80       
81      'U_IMG_LINK'              => add_session_id($url_link)
82      )
83    );
84  $template->assign_block_vars('thumbnails.line.thumbnail.bullet',array());
85
86  // create a new line ?
87  if (++$row_number == $user['nb_image_line'])
88  {
89    $template->assign_block_vars('thumbnails.line', array());
90    $row_number = 0;
91  }
92}
93?>
Note: See TracBrowser for help on using the repository browser.