source: trunk/comments.php @ 848

Last change on this file since 848 was 848, checked in by plg, 19 years ago
  • modification : adaptation of template variables and blocks in comments page to display comment by comment instead of picture by picture.
  • [template cclear] comments.tpl copied and adapted from template default. Return to home new icon. As asked by chrisaga, special id #commentsPage in comments.tpl to set the #content margin-left to 0 (since no #menubar to display).
  • [template cclear] FORM.filter rules taken from template default (these rules have been written some time ago by yoDan.
  • [template cclear] bug fixed on #theImage : display:block must be used only on IMG and not on the P>A (yes, in BSF you can have HTML in picture and categories descriptions)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.8 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-08-21 21:23:17 +0000 (Sun, 21 Aug 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 848 $
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
37$sort_order = array(
38  'descending' => 'DESC',
39  'ascending' => 'ASC'
40  );
41
42// sort_by : database fields proposed for sorting comments list
43$sort_by = array(
44  'date' => 'comment date',
45  'image_id' => 'image'
46  );
47
48// items_number : list of number of items to display per page
49$items_number = array(5,10,20,50,'all');
50
51// since when display comments ?
52//
53$since_options = array(
54  1 => array('label' => l10n('today'),
55             'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 1 DAY)'),
56  2 => array('label' => sprintf(l10n('last %d days'), 7),
57             'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 7 DAY)'),
58  3 => array('label' => sprintf(l10n('last %d days'), 30),
59             'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 30 DAY)'),
60  4 => array('label' => l10n('the beginning'),
61             'clause' => '1=1') // stupid but generic
62  );
63
64$page['since'] = isset($_GET['since']) ? $_GET['since'] : 1;
65
66// on which field sorting
67//
68$page['sort_by'] = 'date';
69// if the form was submitted, it overloads default behaviour
70if (isset($_GET['sort_by']))
71{
72  $page['sort_by'] = $_GET['sort_by'];
73}
74
75// order to sort
76//
77$page['sort_order'] = $sort_order['descending'];
78// if the form was submitted, it overloads default behaviour
79if (isset($_GET['sort_order']))
80{
81  $page['sort_order'] = $sort_order[$_GET['sort_order']];
82}
83
84// number of items to display
85//
86$page['items_number'] = 5;
87if (isset($_GET['items_number']))
88{
89  $page['items_number'] = $_GET['items_number'];
90}
91
92// which category to filter on ?
93$page['cat_clause'] = '1=1';
94if (isset($_GET['cat']) and 0 != $_GET['cat'])
95{
96  $page['cat_clause'] =
97    'category_id IN ('.implode(',', get_subcat_ids(array($_GET['cat']))).')';
98}
99
100// search a particular author
101$page['author_clause'] = '1=1';
102if (isset($_GET['author']) and !empty($_GET['author']))
103{
104  if (function_exists('mysql_real_escape_string'))
105  {
106    $author = mysql_real_escape_string($_GET['author']);
107  }
108  else
109  {
110    $author = mysql_escape_string($_GET['author']);
111  }
112
113  $page['author_clause'] = 'author = \''.$author.'\'';
114}
115
116// search a substring among comments content
117$page['keyword_clause'] = '1=1';
118if (isset($_GET['keyword']) and !empty($_GET['keyword']))
119{
120  if (function_exists('mysql_real_escape_string'))
121  {
122    $keyword = mysql_real_escape_string($_GET['keyword']);
123  }
124  else
125  {
126    $keyword = mysql_escape_string($_GET['keyword']);
127  }
128  $page['keyword_clause'] =
129    '('.
130    implode(' AND ',
131            array_map(
132              create_function(
133                '$s',
134                'return "content LIKE \'%$s%\'";'
135                ),
136              preg_split('/[\s,;]+/', $keyword)
137              )
138      ).
139    ')';
140}
141
142// +-----------------------------------------------------------------------+
143// |                         comments management                           |
144// +-----------------------------------------------------------------------+
145// comments deletion
146if (isset($_POST['delete']) and count($_POST['comment_id']) > 0)
147{
148  $query = '
149DELETE FROM '.COMMENTS_TABLE.'
150  WHERE id IN ('.implode(',', $_POST['comment_id']).')
151;';
152  pwg_query($query);
153}
154// comments validation
155if (isset($_POST['validate']) and count($_POST['comment_id']) > 0)
156{
157  $query = '
158UPDATE '.COMMENTS_TABLE.'
159  SET validated = \'true\'
160    , validation_date = NOW()
161  WHERE id IN ('.implode(',', $_POST['comment_id']).')
162;';
163  pwg_query($query);
164}
165// +-----------------------------------------------------------------------+
166// |                       page header and options                         |
167// +-----------------------------------------------------------------------+
168if (!defined('IN_ADMIN'))
169{
170  $title= l10n('title_comments');
171  include(PHPWG_ROOT_PATH.'include/page_header.php');
172}
173
174$template->set_filenames(array('comments'=>'comments.tpl'));
175$template->assign_vars(
176  array(
177    'L_COMMENT_TITLE' => $title,
178
179    'F_ACTION'=>PHPWG_ROOT_PATH.'comments.php',
180    'F_KEYWORD'=>@$_GET['keyword'],
181    'F_AUTHOR'=>@$_GET['author'],
182   
183    'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php')
184    )
185  );
186
187// +-----------------------------------------------------------------------+
188// |                          form construction                            |
189// +-----------------------------------------------------------------------+
190
191// Search in a particular category
192$blockname = 'category';
193
194$template->assign_block_vars(
195  $blockname,
196  array('SELECTED' => '',
197        'VALUE'=> 0,
198        'OPTION' => '------------'
199    ));
200
201$query = '
202SELECT id,name,uppercats,global_rank
203  FROM '.CATEGORIES_TABLE;
204if ($user['forbidden_categories'] != '')
205{
206  $query.= '
207    WHERE id NOT IN ('.$user['forbidden_categories'].')';
208}
209$query.= '
210;';
211display_select_cat_wrapper($query, array(@$_GET['cat']), $blockname, true);
212
213// Filter on recent comments...
214$blockname = 'since_option';
215
216foreach ($since_options as $id => $option)
217{
218  $selected = ($id == $page['since']) ? 'selected="selected"' : '';
219 
220  $template->assign_block_vars(
221    $blockname,
222    array('SELECTED' => $selected,
223          'VALUE'=> $id,
224          'CONTENT' => $option['label']
225      ));
226}
227
228// Sort by
229$blockname = 'sort_by_option';
230
231foreach ($sort_by as $key => $value)
232{
233  $selected = ($key == $page['sort_by']) ? 'selected="selected"' : '';
234
235  $template->assign_block_vars(
236    $blockname,
237    array('SELECTED' => $selected,
238          'VALUE'=> $key,
239          'CONTENT' => l10n($value)
240      ));
241}
242
243// Sorting order
244$blockname = 'sort_order_option';
245
246foreach (array_keys($sort_order) as $option)
247{
248  $selected = ($option == $page['sort_order']) ? 'selected="selected"' : '';
249
250  $template->assign_block_vars(
251    $blockname,
252    array('SELECTED' => $selected,
253          'VALUE'=> $option,
254          'CONTENT' => l10n($option)
255      ));
256}
257
258// Number of items
259$blockname = 'items_number_option';
260
261foreach ($items_number as $option)
262{
263  $selected = ($option == $page['items_number']) ? 'selected="selected"' : '';
264
265  $template->assign_block_vars(
266    $blockname,
267    array('SELECTED' => $selected,
268          'VALUE'=> $option,
269          'CONTENT' => is_numeric($option) ? $option : l10n($option)
270      ));
271}
272
273// +-----------------------------------------------------------------------+
274// |                            navigation bar                             |
275// +-----------------------------------------------------------------------+
276
277if (isset($_GET['start']) and is_numeric($_GET['start']))
278{
279  $start = $_GET['start'];
280}
281else
282{
283  $start = 0;
284}
285
286$query = '
287SELECT COUNT(DISTINCT(id))
288  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
289    INNER JOIN '.COMMENTS_TABLE.' AS com
290    ON ic.image_id = com.image_id
291  WHERE '.$since_options[$page['since']]['clause'].'
292    AND '.$page['cat_clause'].'
293    AND '.$page['author_clause'].'
294    AND '.$page['keyword_clause'];
295if ($user['forbidden_categories'] != '')
296{
297  $query.= '
298    AND category_id NOT IN ('.$user['forbidden_categories'].')';
299}
300$query.= '
301;';
302list($counter) = mysql_fetch_row(pwg_query($query));
303
304$url = PHPWG_ROOT_PATH.'comments.php?t=1'.get_query_string_diff(array('start'));
305
306$navbar = create_navigation_bar($url,
307                                $counter,
308                                $start,
309                                $page['items_number'],
310                                '');
311
312$template->assign_vars(array('NAVBAR' => $navbar));
313
314// +-----------------------------------------------------------------------+
315// |                        last comments display                          |
316// +-----------------------------------------------------------------------+
317
318$comments = array();
319$element_ids = array();
320$category_ids = array();
321
322$query = '
323SELECT com.id AS comment_id
324     , com.image_id
325     , ic.category_id
326     , com.author
327     , com.date
328     , com.content
329     , com.id AS comment_id
330  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
331    INNER JOIN '.COMMENTS_TABLE.' AS com
332    ON ic.image_id = com.image_id
333  WHERE '.$since_options[$page['since']]['clause'].'
334    AND '.$page['cat_clause'].'
335    AND '.$page['author_clause'].'
336    AND '.$page['keyword_clause'];
337if ($user['forbidden_categories'] != '')
338{
339  $query.= '
340    AND category_id NOT IN ('.$user['forbidden_categories'].')';
341}
342$query.= '
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_array($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_array($result))
371  {
372    $elements[$row['id']] = $row;
373  }
374
375  // retrieving category informations
376  $categories = array();
377  $query = '
378SELECT id, uppercats
379  FROM '.CATEGORIES_TABLE.'
380  WHERE id IN ('.implode(',', $category_ids).')
381;';
382  $result = pwg_query($query);
383  while ($row = mysql_fetch_array($result))
384  {
385    $categories[$row['id']] = $row;
386  }
387
388  foreach ($comments as $comment)
389  {
390    // name of the picture
391    $name = get_cat_display_name_cache(
392      $categories[$comment['category_id']]['uppercats'], '', false);
393    $name.= $conf['level_separator'];
394    if (!empty($elements[$comment['image_id']]['name']))
395    {
396      $name.= $elements[$comment['image_id']]['name'];
397    }
398    else
399    {
400      $name.= get_name_from_file($elements[$comment['image_id']]['file']);
401    }
402   
403    // source of the thumbnail picture
404    $thumbnail_src = get_thumbnail_src(
405      $elements[$comment['image_id']]['path'],
406      @$elements[$comment['image_id']]['tn_ext']
407      );
408 
409    // link to the full size picture
410    $url = PHPWG_ROOT_PATH.'picture.php?cat='.$comment['category_id'];
411    $url.= '&amp;image_id='.$comment['image_id'];
412   
413    $template->assign_block_vars(
414      'picture',
415      array(
416        'TITLE_IMG'=>$name,
417        'I_THUMB'=>$thumbnail_src,
418        'U_THUMB'=>add_session_id($url)
419        ));
420   
421    $author = $comment['author'];
422    if (empty($comment['author']))
423    {
424      $author = l10n('guest');
425    }
426   
427    $template->assign_block_vars(
428      'comment',
429      array(
430        'U_PICTURE' => add_session_id($url),
431        'TN_SRC' => $thumbnail_src,
432        'AUTHOR' => $author,
433        'DATE'=>format_date($comment['date'],'mysql_datetime',true),
434        'CONTENT'=>parse_comment_content($comment['content']),
435        ));
436  }
437}
438// +-----------------------------------------------------------------------+
439// |                           html code display                           |
440// +-----------------------------------------------------------------------+
441if (defined('IN_ADMIN'))
442{
443  $template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
444}
445else
446{
447  $template->assign_block_vars('title',array());
448  $template->parse('comments');
449  include(PHPWG_ROOT_PATH.'include/page_tail.php');
450}
451?>
Note: See TracBrowser for help on using the repository browser.