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

Last change on this file since 1053 was 1053, checked in by plg, 18 years ago

modification: DAY() MySQL function replaced by DAYOFMONTH() to improve
backward compatibility (this function was added in MySQL 4.1)

bug fixed: with chronology mode, PWG displays thumbnails on main page if
even if no category (which will soon be called "section") is set. This was
producing warnings on category.php from include/category_default.inc.php.

refactoring: on include/calendar_base.class.php and
include/functions_calendar.inc.php. Unix file format, coding guidelines,
etc. While trying to understand the code, I've made some presentation
modification to clarify variable names and so on.

  • Property svn:eol-style set to native
  • 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-02-23 16:53:11 +0000 (Thu, 23 Feb 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1053 $
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 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;';
51  $result = pwg_query($query);
52  while ($row = mysql_fetch_array($result))
53  {
54    $row['rank'] = $page['rank_of'][ $row['id'] ];
55   
56    array_push($pictures, $row);
57  }
58
59  usort($pictures, 'rank_compare');
60}
61
62// template thumbnail initialization
63if (count($pictures) > 0)
64{
65  $template->assign_block_vars('thumbnails', array());
66  // first line
67  $template->assign_block_vars('thumbnails.line', array());
68  // current row displayed
69  $row_number = 0;
70}
71
72foreach ($pictures as $row)
73{
74  $thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
75 
76  // message in title for the thumbnail
77  $thumbnail_title = $row['file'];
78  if (isset($row['filesize']))
79  {
80    $thumbnail_title .= ' : '.$row['filesize'].' KB';
81  }
82 
83  // url link on picture.php page
84  $url_link = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id'];
85
86  if (isset($page['cat']))
87  {
88    $url_link.= 'cat='.$page['cat'].'&amp;';
89
90    if ($page['cat'] == 'search')
91    {
92      $url_link.= '&amp;search='.$_GET['search'];
93    }
94    else if ($page['cat'] == 'list')
95    {
96      $url_link.= '&amp;list='.$_GET['list'];
97    }
98  }
99 
100  if (isset($_GET['calendar']))
101  {
102    $url_link.= '&amp;calendar='.$_GET['calendar'];
103  }
104   
105  $template->assign_block_vars(
106    'thumbnails.line.thumbnail',
107    array(
108      'IMAGE'              => $thumbnail_url,
109      'IMAGE_ALT'          => $row['file'],
110      'IMAGE_TITLE'        => $thumbnail_title,
111      'IMAGE_TS'           => get_icon($row['date_available']),
112     
113      'U_IMG_LINK'         => $url_link
114      )
115    );
116
117  if ($conf['show_thumbnail_caption'])
118  {
119    // name of the picture
120    if (isset($row['name']) and $row['name'] != '')
121    {
122      $name = $row['name'];
123    }
124    else
125    {
126      $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
127    }
128    if ($page['cat'] == 'best_rated')
129    {
130      $name = '('.$row['average_rate'].') '.$name;
131    }
132    else
133    if ($page['cat'] == 'most_visited')
134    {
135      $name = '('.$row['hit'].') '.$name;
136    }
137   
138    if ($page['cat'] == 'search')
139    {
140      $name = replace_search($name, $_GET['search']);
141    }
142 
143    $template->assign_block_vars(
144      'thumbnails.line.thumbnail.element_name',
145      array(
146        'NAME' => $name
147        )
148      );
149  }
150   
151  if ($user['show_nb_comments']
152      and is_numeric($page['cat'])
153      and $page['cat_commentable'])
154  {
155    $query = '
156SELECT COUNT(*) AS nb_comments
157  FROM '.COMMENTS_TABLE.'
158  WHERE image_id = '.$row['id'].'
159    AND validated = \'true\'
160;';
161    $row = mysql_fetch_array(pwg_query($query));
162    $template->assign_block_vars(
163      'thumbnails.line.thumbnail.nb_comments',
164      array('NB_COMMENTS'=>$row['nb_comments']));
165  }
166
167  // create a new line ?
168  if (++$row_number == $user['nb_image_line'])
169  {
170    $template->assign_block_vars('thumbnails.line', array());
171    $row_number = 0;
172  }
173}
174
175pwg_debug('end include/category_default.inc.php');
176?>
Note: See TracBrowser for help on using the repository browser.