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

Last change on this file since 2274 was 2274, checked in by rvelices, 16 years ago
  • remove $confsubcatify (it was my reqquest to Pierrick when plugins were not available; now it can be done through plugin)
  • optimization when show_nb_comments true (1 sql query per page instead of 1 query per element)
  • some cleanup & more standard trigger names
  • Property svn:eol-style set to LF
  • 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-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: category_default.inc.php 2274 2008-03-11 02:04:27Z rvelices $
8// | last update   : $Date: 2008-03-11 02:04:27 +0000 (Tue, 11 Mar 2008) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2274 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27/**
28 * This file is included by the main page to show thumbnails for the default
29 * case
30 *
31 */
32
33$page['rank_of'] = array_flip($page['items']);
34
35$pictures = array();
36
37$selection = array_slice(
38  $page['items'],
39  $page['start'],
40  $page['nb_image_page']
41  );
42
43if (count($selection) > 0)
44{
45  $query = '
46SELECT *
47  FROM '.IMAGES_TABLE.'
48  WHERE id IN ('.implode(',', $selection).')
49;';
50  $result = pwg_query($query);
51  while ($row = mysql_fetch_assoc($result))
52  {
53    $row['rank'] = $page['rank_of'][ $row['id'] ];
54
55    array_push($pictures, $row);
56  }
57
58  usort($pictures, 'rank_compare');
59}
60
61if (count($pictures) > 0)
62{
63  // define category slideshow url
64  $row = reset($pictures);
65  $page['cat_slideshow_url'] =
66    add_url_params(
67      duplicate_picture_url(
68        array(
69          'image_id' => $row['id'],
70          'image_file' => $row['file']
71        ),
72        array('start')
73      ),
74      array('slideshow' =>
75        (isset($_GET['slideshow']) ? $_GET['slideshow']
76                                   : '' ))
77    );
78
79  if ($user['show_nb_comments'])
80  {
81    $query = '
82SELECT image_id, COUNT(*) AS nb_comments
83  FROM '.COMMENTS_TABLE.'
84  WHERE validated = \'true\'
85    AND image_id IN ('.implode(',', $selection).')
86  GROUP BY image_id
87;';
88    $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments');
89  }
90}
91
92// template thumbnail initialization
93$template->set_filenames( array( 'index_thumbnails' => 'thumbnails.tpl',));
94
95trigger_action('loc_begin_index_thumbnails', $pictures);
96
97foreach ($pictures as $row)
98{
99  $thumbnail_url = get_thumbnail_url($row);
100
101  // link on picture.php page
102  $url = duplicate_picture_url(
103        array(
104          'image_id' => $row['id'],
105          'image_file' => $row['file']
106        ),
107        array('start')
108      );
109
110  $tpl_var =
111    array(
112      'ID'            => $row['id'],
113      'IMAGE'         => $thumbnail_url,
114      'IMAGE_ALT'     => $row['file'],
115      'IMAGE_TITLE'   => get_thumbnail_title($row),
116      'IMAGE_TS'      => get_icon($row['date_available']),
117      'U_IMG_LINK'    => $url,
118    );
119
120  if ($user['show_nb_hits'])
121  {
122    $tpl_var['NB_HITS'] = $row['hit'];
123  }
124
125  if ($conf['show_thumbnail_caption'])
126  {
127    // name of the picture
128    if (isset($row['name']) and $row['name'] != '')
129    {
130      $name = $row['name'];
131    }
132    else
133    {
134      $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
135    }
136
137    switch ($page['section'])
138    {
139      case 'best_rated' :
140      {
141        $name = '('.$row['average_rate'].') '.$name;
142        break;
143      }
144      case 'most_visited' :
145      {
146        if ( !$user['show_nb_hits']) {
147          $name = '('.$row['hit'].') '.$name;
148        }
149        break;
150      }
151    }
152
153    $tpl_var['ELEMENT_NAME'] = $name;
154  }
155
156  if ( isset($nb_comments_of) )
157  {
158    $row['nb_comments'] = isset($nb_comments_of[$row['id']])
159        ? (int)$nb_comments_of[$row['id']] : 0;
160    $tpl_var['NB_COMMENTS'] = $row['nb_comments'];
161  }
162
163  //plugins need to add/modify sth in this loop ?
164  $tpl_var = trigger_event('loc_index_thumbnail', $tpl_var, $row);
165
166  $template->append('thumbnails', $tpl_var);
167}
168
169trigger_action('loc_end_index_thumbnails', $pictures);
170$template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');
171
172pwg_debug('end include/category_default.inc.php');
173?>
Note: See TracBrowser for help on using the repository browser.