source: trunk/comments.php @ 1814

Last change on this file since 1814 was 1814, checked in by rvelices, 17 years ago
  • thumbnails creation for all local sites (not only site id 1)
  • urls for images in notification (rss & mail) is now correct
  • removed "Recent pictures" from title in when the flat view is in effect
  • removed unnecessary class="" from comments.tpl
  • english language correction
  • removed unused web service files
  • set rating star button left & right margin to 0 (javascript)
  • admin menu - put site manager and synchronize together
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.3 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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $Id: comments.php 1814 2007-02-14 00:36:34Z rvelices $
9// | last update   : $Date: 2007-02-14 00:36:34 +0000 (Wed, 14 Feb 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1814 $
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// +-----------------------------------------------------------------------+
31define('PHPWG_ROOT_PATH','./');
32include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
33
34// +-----------------------------------------------------------------------+
35// | Check Access and exit when user status is not ok                      |
36// +-----------------------------------------------------------------------+
37check_status(ACCESS_GUEST);
38
39$sort_order = array(
40  'descending' => 'DESC',
41  'ascending' => 'ASC'
42  );
43
44// sort_by : database fields proposed for sorting comments list
45$sort_by = array(
46  'date' => 'comment date',
47  'image_id' => 'picture'
48  );
49
50// items_number : list of number of items to display per page
51$items_number = array(5,10,20,50,'all');
52
53// since when display comments ?
54//
55$since_options = array(
56  1 => array('label' => l10n('today'),
57             'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 1 DAY)'),
58  2 => array('label' => sprintf(l10n('last %d days'), 7),
59             'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 7 DAY)'),
60  3 => array('label' => sprintf(l10n('last %d days'), 30),
61             'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 30 DAY)'),
62  4 => array('label' => l10n('the beginning'),
63             'clause' => '1=1') // stupid but generic
64  );
65
66$page['since'] = isset($_GET['since']) ? $_GET['since'] : 4;
67
68// on which field sorting
69//
70$page['sort_by'] = 'date';
71// if the form was submitted, it overloads default behaviour
72if (isset($_GET['sort_by']))
73{
74  $page['sort_by'] = $_GET['sort_by'];
75}
76
77// order to sort
78//
79$page['sort_order'] = $sort_order['descending'];
80// if the form was submitted, it overloads default behaviour
81if (isset($_GET['sort_order']))
82{
83  $page['sort_order'] = $sort_order[$_GET['sort_order']];
84}
85
86// number of items to display
87//
88$page['items_number'] = 10;
89if (isset($_GET['items_number']))
90{
91  $page['items_number'] = $_GET['items_number'];
92}
93
94$page['where_clauses'] = array();
95
96// which category to filter on ?
97if (isset($_GET['cat']) and 0 != $_GET['cat'])
98{
99  $page['where_clauses'][] =
100    'category_id IN ('.implode(',', get_subcat_ids(array($_GET['cat']))).')';
101}
102
103// search a particular author
104if (isset($_GET['author']) and !empty($_GET['author']))
105{
106  $page['where_clauses'][] = 'com.author = \''.$_GET['author'].'\'';
107}
108
109// search a substring among comments content
110if (isset($_GET['keyword']) and !empty($_GET['keyword']))
111{
112  // fors some odd reason comment content is htmlspecialchars in the database
113  $keyword = addslashes( 
114      htmlspecialchars( stripslashes($_GET['keyword']), ENT_QUOTES) 
115    );
116  $page['where_clauses'][] =
117    '('.
118    implode(' AND ',
119            array_map(
120              create_function(
121                '$s',
122                'return "content LIKE \'%$s%\'";'
123                ),
124              preg_split('/[\s,;]+/', $keyword)
125              )
126      ).
127    ')';
128}
129
130$page['where_clauses'][] = $since_options[$page['since']]['clause'];
131
132// which status to filter on ?
133if ( !is_admin() )
134{
135  $page['where_clauses'][] = 'validated="true"';
136}
137
138$page['where_clauses'][] = get_sql_condition_FandF
139  (
140    array
141      (
142        'forbidden_categories' => 'category_id',
143        'visible_categories' => 'category_id',
144        'visible_images' => 'ic.image_id'
145      ),
146    '', true
147  );
148
149// +-----------------------------------------------------------------------+
150// |                         comments management                           |
151// +-----------------------------------------------------------------------+
152if (isset($_GET['delete']) and is_numeric($_GET['delete'])
153      and !is_adviser() )
154{// comments deletion
155  check_status(ACCESS_ADMINISTRATOR);
156  $query = '
157DELETE FROM '.COMMENTS_TABLE.'
158  WHERE id='.$_GET['delete'].'
159;';
160  pwg_query($query);
161}
162
163if (isset($_GET['validate']) and is_numeric($_GET['validate'])
164      and !is_adviser() )
165{  // comments validation
166  check_status(ACCESS_ADMINISTRATOR);
167  $query = '
168UPDATE '.COMMENTS_TABLE.'
169  SET validated = \'true\'
170  , validation_date = NOW()
171  WHERE id='.$_GET['validate'].'
172;';
173  pwg_query($query);
174}
175
176// +-----------------------------------------------------------------------+
177// |                       page header and options                         |
178// +-----------------------------------------------------------------------+
179
180$title= l10n('title_comments');
181$page['body_id'] = 'theCommentsPage';
182include(PHPWG_ROOT_PATH.'include/page_header.php');
183
184$template->set_filenames(array('comments'=>'comments.tpl'));
185$template->assign_vars(
186  array(
187    'L_COMMENT_TITLE' => $title,
188
189    'F_ACTION'=>PHPWG_ROOT_PATH.'comments.php',
190    'F_KEYWORD'=>@htmlentities(stripslashes($_GET['keyword'])),
191    'F_AUTHOR'=>@htmlentities(stripslashes($_GET['author'])),
192
193    'U_HOME' => make_index_url(),
194    )
195  );
196
197// +-----------------------------------------------------------------------+
198// |                          form construction                            |
199// +-----------------------------------------------------------------------+
200
201// Search in a particular category
202$blockname = 'category';
203
204$template->assign_block_vars(
205  $blockname,
206  array('SELECTED' => '',
207        'VALUE'=> 0,
208        'OPTION' => '------------'
209    ));
210
211$query = '
212SELECT id,name,uppercats,global_rank
213  FROM '.CATEGORIES_TABLE.'
214'.get_sql_condition_FandF
215  (
216    array
217      (
218        'forbidden_categories' => 'id',
219        'visible_categories' => 'id'
220      ),
221    'WHERE'
222  ).'
223;';
224display_select_cat_wrapper($query, array(@$_GET['cat']), $blockname, true);
225
226// Filter on recent comments...
227$blockname = 'since_option';
228
229foreach ($since_options as $id => $option)
230{
231  $selected = ($id == $page['since']) ? 'selected="selected"' : '';
232
233  $template->assign_block_vars(
234    $blockname,
235    array('SELECTED' => $selected,
236          'VALUE'=> $id,
237          'CONTENT' => $option['label']
238      ));
239}
240
241// Sort by
242$blockname = 'sort_by_option';
243
244foreach ($sort_by as $key => $value)
245{
246  $selected = ($key == $page['sort_by']) ? 'selected="selected"' : '';
247
248  $template->assign_block_vars(
249    $blockname,
250    array('SELECTED' => $selected,
251          'VALUE'=> $key,
252          'CONTENT' => l10n($value)
253      ));
254}
255
256// Sorting order
257$blockname = 'sort_order_option';
258
259foreach (array_keys($sort_order) as $option)
260{
261  $selected = ($option == $page['sort_order']) ? 'selected="selected"' : '';
262
263  $template->assign_block_vars(
264    $blockname,
265    array('SELECTED' => $selected,
266          'VALUE'=> $option,
267          'CONTENT' => l10n($option)
268      ));
269}
270
271// Number of items
272$blockname = 'items_number_option';
273
274foreach ($items_number as $option)
275{
276  $selected = ($option == $page['items_number']) ? 'selected="selected"' : '';
277
278  $template->assign_block_vars(
279    $blockname,
280    array('SELECTED' => $selected,
281          'VALUE'=> $option,
282          'CONTENT' => is_numeric($option) ? $option : l10n($option)
283      ));
284}
285
286// +-----------------------------------------------------------------------+
287// |                            navigation bar                             |
288// +-----------------------------------------------------------------------+
289
290if (isset($_GET['start']) and is_numeric($_GET['start']))
291{
292  $start = $_GET['start'];
293}
294else
295{
296  $start = 0;
297}
298
299$query = '
300SELECT COUNT(DISTINCT(id))
301  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
302    INNER JOIN '.COMMENTS_TABLE.' AS com
303    ON ic.image_id = com.image_id
304  WHERE '.implode('
305    AND ', $page['where_clauses']).'
306;';
307list($counter) = mysql_fetch_row(pwg_query($query));
308
309$url = PHPWG_ROOT_PATH
310    .'comments.php'
311    .get_query_string_diff(array('start','delete','validate'));
312
313$navbar = create_navigation_bar($url,
314                                $counter,
315                                $start,
316                                $page['items_number'],
317                                '');
318
319$template->assign_vars(array('NAVBAR' => $navbar));
320
321// +-----------------------------------------------------------------------+
322// |                        last comments display                          |
323// +-----------------------------------------------------------------------+
324
325$comments = array();
326$element_ids = array();
327$category_ids = array();
328
329$query = '
330SELECT com.id AS comment_id
331     , com.image_id
332     , ic.category_id
333     , com.author
334     , com.date
335     , com.content
336     , com.id AS comment_id
337     , com.validated
338  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
339    INNER JOIN '.COMMENTS_TABLE.' AS com
340    ON ic.image_id = com.image_id
341  WHERE '.implode('
342    AND ', $page['where_clauses']).'
343  GROUP BY comment_id
344  ORDER BY '.$page['sort_by'].' '.$page['sort_order'];
345if ('all' != $page['items_number'])
346{
347  $query.= '
348  LIMIT '.$start.','.$page['items_number'];
349}
350$query.= '
351;';
352$result = pwg_query($query);
353while ($row = mysql_fetch_assoc($result))
354{
355  array_push($comments, $row);
356  array_push($element_ids, $row['image_id']);
357  array_push($category_ids, $row['category_id']);
358}
359
360if (count($comments) > 0)
361{
362  // retrieving element informations
363  $elements = array();
364  $query = '
365SELECT id, name, file, path, tn_ext
366  FROM '.IMAGES_TABLE.'
367  WHERE id IN ('.implode(',', $element_ids).')
368;';
369  $result = pwg_query($query);
370  while ($row = mysql_fetch_assoc($result))
371  {
372    $elements[$row['id']] = $row;
373  }
374
375  // retrieving category informations
376  $categories = array();
377  $query = '
378SELECT id, name, uppercats
379  FROM '.CATEGORIES_TABLE.'
380  WHERE id IN ('.implode(',', $category_ids).')
381;';
382  $result = pwg_query($query);
383  while ($row = mysql_fetch_assoc($result))
384  {
385    $categories[$row['id']] = $row;
386  }
387
388  foreach ($comments as $comment)
389  {
390    if (!empty($elements[$comment['image_id']]['name']))
391    {
392      $name=$elements[$comment['image_id']]['name'];
393    }
394    else
395    {
396      $name=get_name_from_file($elements[$comment['image_id']]['file']);
397    }
398
399    // source of the thumbnail picture
400    $thumbnail_src = get_thumbnail_url( $elements[$comment['image_id']] );
401
402    // link to the full size picture
403    $url = make_picture_url(
404            array(
405              'category' => $comment['category_id'],
406              'cat_name' => $categories[ $comment['category_id']] ['name'],
407              'image_id' => $comment['image_id'],
408              'image_file' => $elements[$comment['image_id']]['file'],
409            )
410          );
411
412    $author = $comment['author'];
413    if (empty($comment['author']))
414    {
415      $author = l10n('guest');
416    }
417
418    $template->assign_block_vars(
419      'comment',
420      array(
421        'U_PICTURE' => $url,
422        'TN_SRC' => $thumbnail_src,
423        'ALT' => $name,
424        'AUTHOR' => $author,
425        'DATE'=>format_date($comment['date'],'mysql_datetime',true),
426        'CONTENT'=>trigger_event('render_comment_content',$comment['content']),
427        ));
428
429    if ( is_admin() )
430    {
431      $url = get_root_url().'comments.php'.get_query_string_diff(array('delete','validate'));
432      $template->assign_block_vars(
433        'comment.action_delete',
434        array(
435          'U_DELETE' => add_url_params($url,
436                          array('delete'=>$comment['comment_id'])
437                         ),
438          ));
439      if ($comment['validated'] != 'true')
440      {
441        $template->assign_block_vars(
442          'comment.action_validate',
443          array(
444            'U_VALIDATE' => add_url_params($url,
445                            array('validate'=>$comment['comment_id'])
446                           ),
447            ));
448      }
449    }
450  }
451}
452// +-----------------------------------------------------------------------+
453// |                           html code display                           |
454// +-----------------------------------------------------------------------+
455$template->assign_block_vars('title',array());
456$template->parse('comments');
457include(PHPWG_ROOT_PATH.'include/page_tail.php');
458?>
Note: See TracBrowser for help on using the repository browser.