source: trunk/comments.php @ 688

Last change on this file since 688 was 688, checked in by plg, 19 years ago
  • use template->parse instead of pparse. (exceptions for install.php and upgrade.php)
  • bug fixed : queries time and count were not displayed on a redirection
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 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: 2005-01-13 10:18:49 +0000 (Thu, 13 Jan 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 688 $
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// |                           initialization                              |
30// +-----------------------------------------------------------------------+
31if (!defined('IN_ADMIN'))
32{
33  define('PHPWG_ROOT_PATH','./');
34  include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
35}
36
37if (isset($_GET['last_days']))
38{
39  define('MAX_DAYS', $_GET['last_days']);
40}
41else
42{
43  define('MAX_DAYS', 0);
44}
45$array_cat_names = array();
46// +-----------------------------------------------------------------------+
47// |                         comments management                           |
48// +-----------------------------------------------------------------------+
49// comments deletion
50if (isset($_POST['delete']) and count($_POST['comment_id']) > 0)
51{
52  $query = '
53DELETE FROM '.COMMENTS_TABLE.'
54  WHERE id IN ('.implode(',', $_POST['comment_id']).')
55;';
56  pwg_query($query);
57}
58// comments validation
59if (isset($_POST['validate']) and count($_POST['comment_id']) > 0)
60{
61  $query = '
62UPDATE '.COMMENTS_TABLE.'
63  SET validated = \'true\'
64  WHERE id IN ('.implode(',', $_POST['comment_id']).')
65;';
66  pwg_query($query);
67}
68// +-----------------------------------------------------------------------+
69// |                       page header and options                         |
70// +-----------------------------------------------------------------------+
71if (!defined('IN_ADMIN'))
72{
73  $title= $lang['title_comments'];
74  include(PHPWG_ROOT_PATH.'include/page_header.php');
75}
76
77$template->set_filenames(array('comments'=>'comments.tpl'));
78$template->assign_vars(
79  array(
80    'L_COMMENT_TITLE' => $title,
81    'L_COMMENT_STATS' => $lang['stats_last_days'],
82    'L_COMMENT_RETURN' => $lang['home'],
83        'L_COMMENT_RETURN_HINT' => $lang['home_hint'],
84    'L_DELETE' =>$lang['delete'],
85    'L_VALIDATE'=>$lang['submit'],
86   
87    'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php')
88    )
89  );
90
91foreach ($conf['last_days'] as $option)
92{
93  $url = $_SERVER['PHP_SELF'].'?last_days='.($option - 1);
94  if (defined('IN_ADMIN'))
95  {
96    $url.= '&amp;page=comments';
97  }
98  $template->assign_block_vars(
99    'last_day_option',
100    array(
101      'OPTION'=>$option,
102      'T_STYLE'=>(($option == MAX_DAYS + 1)?'text-decoration:underline;':''),
103      'U_OPTION'=>add_session_id($url)
104      )
105    );
106}
107// +-----------------------------------------------------------------------+
108// |                        last comments display                          |
109// +-----------------------------------------------------------------------+
110// 1. retrieving picture ids which have comments recently added
111$maxdate = date('Y-m-d', strtotime('-'.MAX_DAYS.' day'));
112
113$query = '
114SELECT DISTINCT(ic.image_id) AS image_id,(ic.category_id) AS category_id
115  FROM '.COMMENTS_TABLE.' AS c, '.IMAGE_CATEGORY_TABLE.' AS ic
116  WHERE c.image_id = ic.image_id
117    AND date >= \''.$maxdate.'\'';
118if ($user['status'] != 'admin')
119{
120  $query.= "
121    AND validated = 'true'";
122  // we must not show pictures of a forbidden category
123  if ($user['forbidden_categories'] != '')
124  {
125    $query.= '
126    AND category_id NOT IN ('.$user['forbidden_categories'].')';
127  }
128}
129$query.= '
130  ORDER BY ic.image_id DESC
131;';
132$result = pwg_query($query);
133if ($user['status'] == 'admin')
134{
135  $template->assign_block_vars('validation', array());
136}
137while ($row = mysql_fetch_array($result))
138{
139  $category_id = $row['category_id'];
140 
141  // for each picture, getting informations for displaying thumbnail and
142  // link to the full size picture
143  $query = '
144SELECT name,file,storage_category_id as cat_id,tn_ext,path
145  FROM '.IMAGES_TABLE.'
146  WHERE id = '.$row['image_id'].'
147;';
148  $subresult = pwg_query($query);
149  $subrow = mysql_fetch_array($subresult);
150
151  if (!isset($array_cat_names[$subrow['cat_id']]))
152  {
153    $cat_result = get_cat_info($subrow['cat_id']);
154    $array_cat_names[$subrow['cat_id']] =
155      get_cat_display_name($cat_result['name'], '');
156  }
157 
158  // name of the picture
159  $name = $array_cat_names[$category_id].' &gt; ';
160  if (!empty($subrow['name']))
161  {
162    $name.= $subrow['name'];
163  }
164  else
165  {
166    $name.= str_replace('_',' ',get_filename_wo_extension($subrow['file']));
167  }
168  $name.= ' [ '.$subrow['file'].' ]';
169  // source of the thumbnail picture
170  $thumbnail_src = get_thumbnail_src($subrow['path'], @$subrow['tn_ext']);
171  // link to the full size picture
172  $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id;
173  $url.= '&amp;image_id='.$row['image_id'];
174   
175  $template->assign_block_vars(
176    'picture',
177    array(
178      'TITLE_IMG'=>$name,
179      'I_THUMB'=>$thumbnail_src,
180      'U_THUMB'=>add_session_id($url)
181      ));
182   
183  // for each picture, retrieving all comments
184  $query = '
185SELECT *
186  FROM '.COMMENTS_TABLE.'
187  WHERE image_id = '.$row['image_id'].'
188    AND date >= \''.$maxdate.'\'';
189  if ($user['status'] != 'admin')
190  {
191    $query.= '
192    AND validated = \'true\'';
193  }
194  $query.= '
195  ORDER BY date DESC
196;';
197  $handleresult = pwg_query($query);
198  while ($subrow = mysql_fetch_array($handleresult))
199  {
200    $author = $subrow['author'];
201    if (empty($subrow['author']))
202    {
203      $author = $lang['guest'];
204    }
205
206    $template->assign_block_vars(
207      'picture.comment',
208      array(
209        'COMMENT_AUTHOR'=>$author,
210        'COMMENT_DATE'=>format_date($subrow['date'],'mysql_datetime',true),
211        'COMMENT'=>parse_comment_content($subrow['content']),
212        ));
213   
214    if ($user['status'] == 'admin')
215    {
216      $template->assign_block_vars(
217        'picture.comment.validation',
218        array(
219          'ID'=> $subrow['id'],
220          'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': ''
221          ));
222    }
223  }
224}
225// +-----------------------------------------------------------------------+
226// |                           html code display                           |
227// +-----------------------------------------------------------------------+
228if (defined('IN_ADMIN'))
229{
230  $template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
231}
232else
233{
234  $template->assign_block_vars('title',array());
235  $template->parse('comments');
236  include(PHPWG_ROOT_PATH.'include/page_tail.php');
237}
238?>
Note: See TracBrowser for help on using the repository browser.