source: trunk/comments.php @ 1430

Last change on this file since 1430 was 1092, checked in by rvelices, 19 years ago

URL rewriting: capable of fully working with urls without ?

URL rewriting: works with image file instead of image id (change
make_picture_url to generate urls with file name instead of image id)

URL rewriting: completely works with category/best_rated and
picture/best_rated/534 (change 'category.php?' to 'category' in make_index_url
and 'picture.php?' to 'picture' in make_picture_url to see it)

fix: picture category display in upper bar

fix: function rate_picture variables and use of the new user type

fix: caddie icon appears now on category page

fix: admin element_set sql query was using storage_category_id column
(column has moved to #image_categories)

fix: replaced some old $_GET[xxx] with $page[xxx]

fix: pictures have metadata url (use ? parameter - might change later)

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