source: trunk/include/category_default.inc.php @ 1648

Last change on this file since 1648 was 1648, checked in by rub, 17 years ago

Feature Issue ID 0000601: Filter all public pages with only recent elements

It's a draft of the feature witch allows to show only recent elements.
Development are not finished.
Queries and special pages (best rates, tags, etc.) are not modified.
Only main php files about images and categories are ok.

Before to continue, I prefer to determinate a solution between modify cache implementation or hide counters.

Go to http://forum.phpwebgallery.net/viewtopic.php?pid=50015#p50015

  • 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-12-10 22:48:32 +0000 (Sun, 10 Dec 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1648 $
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 the default
30 * case
31 *
32 */
33
34$page['rank_of'] = array_flip($page['items']);
35
36$pictures = array();
37
38$selection = array_slice(
39  $page['items'],
40  $page['start'],
41  $page['nb_image_page']
42  );
43
44if (count($selection) > 0)
45{
46  $query = '
47SELECT *
48  FROM '.IMAGES_TABLE.'
49  WHERE id IN ('.implode(',', $selection).')';
50  if ($page['filter_mode'])
51  {
52    $query.= '
53    AND date_available  > SUBDATE(
54      CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY)';
55  }
56  $query.= ';';
57  $result = pwg_query($query);
58  while ($row = mysql_fetch_assoc($result))
59  {
60    $row['rank'] = $page['rank_of'][ $row['id'] ];
61
62    array_push($pictures, $row);
63  }
64
65  usort($pictures, 'rank_compare');
66}
67
68// template thumbnail initialization
69$template->set_filenames( array( 'thumbnails' => 'thumbnails.tpl',));
70if (count($pictures) > 0)
71{
72  // first line
73  $template->assign_block_vars('thumbnails.line', array());
74  // current row displayed
75  $row_number = 0;
76}
77
78trigger_action('loc_begin_index_thumbnails', $pictures);
79
80foreach ($pictures as $row)
81{
82  $thumbnail_url = get_thumbnail_url($row);
83
84  // message in title for the thumbnail
85  $thumbnail_title = $row['file'];
86  if (isset($row['filesize']))
87  {
88    $thumbnail_title .= ' : '.$row['filesize'].' KB';
89  }
90
91  // link on picture.php page
92  $url = duplicate_picture_url(
93        array(
94          'image_id' => $row['id'],
95          'image_file' => $row['file']
96        ),
97        array('start')
98      );
99
100  $template->assign_block_vars(
101    'thumbnails.line.thumbnail',
102    array(
103      'IMAGE'              => $thumbnail_url,
104      'IMAGE_ALT'          => $row['file'],
105      'IMAGE_TITLE'        => $thumbnail_title,
106      'IMAGE_TS'           => get_icon($row['date_available']),
107
108      'U_IMG_LINK'         => $url,
109
110      'CLASS'              => 'thumbElmt',
111      )
112    );
113
114  if ($conf['show_thumbnail_caption'])
115  {
116    // name of the picture
117    if (isset($row['name']) and $row['name'] != '')
118    {
119      $name = $row['name'];
120    }
121    else
122    {
123      $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
124    }
125
126    switch ($page['section'])
127    {
128      case 'best_rated' :
129      {
130        $name = '('.$row['average_rate'].') '.$name;
131        break;
132      }
133      case 'most_visited' :
134      {
135        $name = '('.$row['hit'].') '.$name;
136        break;
137      }
138      case 'search' :
139      {
140        $name = replace_search($name, $page['search']);
141        break;
142      }
143    }
144
145    $template->assign_block_vars(
146      'thumbnails.line.thumbnail.element_name',
147      array(
148        'NAME' => $name
149        )
150      );
151  }
152
153  if ($user['show_nb_comments']
154      and isset($page['category'])
155      and $page['cat_commentable'])
156  {
157    $query = '
158SELECT COUNT(*) AS nb_comments
159  FROM '.COMMENTS_TABLE.'
160  WHERE image_id = '.$row['id'].'
161    AND validated = \'true\'
162;';
163    $row = mysql_fetch_array(pwg_query($query));
164    $template->assign_block_vars(
165      'thumbnails.line.thumbnail.nb_comments',
166      array('NB_COMMENTS'=>$row['nb_comments']));
167  }
168
169  //plugins need to add/modify sth in this loop ?
170  trigger_action('loc_index_thumbnail', $row, 'thumbnails.line.thumbnail' );
171
172  // create a new line ?
173  if (++$row_number == $user['nb_image_line'])
174  {
175    $template->assign_block_vars('thumbnails.line', array());
176    $row_number = 0;
177  }
178}
179
180trigger_action('loc_end_index_thumbnails', $pictures);
181$template->assign_var_from_handle('THUMBNAILS', 'thumbnails');
182
183pwg_debug('end include/category_default.inc.php');
184?>
Note: See TracBrowser for help on using the repository browser.