source: branches/gettext/include/category_default.inc.php @ 15174

Last change on this file since 15174 was 5014, checked in by plg, 15 years ago

merge r5013 from branch 2.0 to trunk

feature 1448 added: ability to set the upload directory (for pwg.images.add
API method).

Warning: due to risk on img src construction, the upload_dir must be relative
to the Piwigo directory itself.

File size: 5.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24/**
25 * This file is included by the main page to show thumbnails for the default
26 * case
27 *
28 */
29
30$pictures = array();
31
32$selection = array_slice(
33  $page['items'],
34  $page['start'],
35  $page['nb_image_page']
36  );
37
38if (count($selection) > 0)
39{
40  $rank_of = array_flip($page['items']);
41
42  $query = '
43SELECT *
44  FROM '.IMAGES_TABLE.'
45  WHERE id IN ('.implode(',', $selection).')
46;';
47  $result = pwg_query($query);
48  while ($row = pwg_db_fetch_assoc($result))
49  {
50    $row['rank'] = $rank_of[ $row['id'] ];
51
52    array_push($pictures, $row);
53  }
54
55  usort($pictures, 'rank_compare');
56  unset($rank_of);
57}
58
59if (count($pictures) > 0)
60{
61  // define category slideshow url
62  $row = reset($pictures);
63  $page['cat_slideshow_url'] =
64    add_url_params(
65      duplicate_picture_url(
66        array(
67          'image_id' => $row['id'],
68          'image_file' => $row['file']
69        ),
70        array('start')
71      ),
72      array('slideshow' =>
73        (isset($_GET['slideshow']) ? $_GET['slideshow']
74                                   : '' ))
75    );
76
77  if ($user['show_nb_comments'])
78  {
79    $query = '
80SELECT image_id, COUNT(*) AS nb_comments
81  FROM '.COMMENTS_TABLE.'
82  WHERE validated = \'true\'
83    AND image_id IN ('.implode(',', $selection).')
84  GROUP BY image_id
85;';
86    $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments');
87  }
88}
89
90// template thumbnail initialization
91$template->set_filenames( array( 'index_thumbnails' => 'thumbnails.tpl',));
92
93trigger_action('loc_begin_index_thumbnails', $pictures);
94$tpl_thumbnails_var = array();
95
96foreach ($pictures as $row)
97{
98  // link on picture.php page
99  $url = duplicate_picture_url(
100        array(
101          'image_id' => $row['id'],
102          'image_file' => $row['file']
103        ),
104        array('start')
105      );
106
107  $tpl_var =
108    array(
109      'ID'        => $row['id'],
110      'TN_SRC'    => get_thumbnail_url($row),
111      'TN_ALT'    => $row['file'],
112      'TN_TITLE'  => get_thumbnail_title($row),
113      'icon_ts'   => get_icon($row['date_available']),
114      'URL'       => $url,
115
116   /* Fields for template-extension usage */
117      'FILE_PATH' => $row['path'],
118      'FILE_POSTED' => $row['date_available'],
119      'FILE_CREATED' => $row['date_creation'],
120      'FILE_DESC' => $row['comment'],
121      'FILE_AUTHOR' => $row['author'],
122      'FILE_HIT' => $row['hit'],
123      'FILE_SIZE' => $row['filesize'],
124      'FILE_WIDTH' => $row['width'],
125      'FILE_HEIGHT' => $row['height'],
126      'FILE_METADATE' => $row['date_metadata_update'],
127      'FILE_HAS_HD' => ($row['has_high'] and $user['enabled_high']=='true') ?
128                true:false, /* lack of include/functions_picture.inc.php */
129    );
130
131  if ($user['show_nb_hits'])
132  {
133    $tpl_var['NB_HITS'] = $row['hit'];
134  }
135
136  if ($conf['show_thumbnail_caption'])
137  {// name of the picture
138    if (isset($row['name']) and $row['name'] != '')
139    {
140      $name = $row['name'];
141    }
142    else
143    {
144      $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
145    }
146
147    switch ($page['section'])
148    {
149      case 'best_rated' :
150      {
151        $name = '('.$row['average_rate'].') '.$name;
152        break;
153      }
154      case 'most_visited' :
155      {
156        if ( !$user['show_nb_hits']) {
157          $name = '('.$row['hit'].') '.$name;
158        }
159        break;
160      }
161    }
162
163    $tpl_var['NAME'] = $name;
164  }
165
166  if ( isset($nb_comments_of) )
167  {
168    $tpl_var['NB_COMMENTS'] = (int)@$nb_comments_of[$row['id']];
169  }
170
171  $tpl_thumbnails_var[] = $tpl_var;
172}
173
174$tpl_thumbnails_var = trigger_event('loc_end_index_thumbnails', $tpl_thumbnails_var, $pictures);
175$template->assign('thumbnails', $tpl_thumbnails_var);
176
177$template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');
178
179pwg_debug('end include/category_default.inc.php');
180?>
Note: See TracBrowser for help on using the repository browser.