source: trunk/comments.php @ 606

Last change on this file since 606 was 606, checked in by plg, 19 years ago
  • images.path column added to reduce database access
  • function mass_inserts moved from admin/remote_sites.php to admin/include/function.php
  • function mass_inserts used in admin/update.php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 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-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-11-16 23:38:34 +0000 (Tue, 16 Nov 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 606 $
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['return_main_page'],
83    'L_DELETE' =>$lang['delete'],
84    'L_VALIDATE'=>$lang['submit'],
85   
86    'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php')
87    )
88  );
89
90foreach ($conf['last_days'] as $option)
91{
92  $url = $_SERVER['PHP_SELF'].'?last_days='.($option - 1);
93  if (defined('IN_ADMIN'))
94  {
95    $url.= '&amp;page=comments';
96  }
97  $template->assign_block_vars(
98    'last_day_option',
99    array(
100      'OPTION'=>$option,
101      'T_STYLE'=>(($option == MAX_DAYS + 1)?'text-decoration:underline;':''),
102      'U_OPTION'=>add_session_id($url)
103      )
104    );
105}
106// +-----------------------------------------------------------------------+
107// |                        last comments display                          |
108// +-----------------------------------------------------------------------+
109// 1. retrieving picture ids which have comments recently added
110$maxdate = date('Y-m-d', strtotime('-'.MAX_DAYS.' day'));
111
112$query = '
113SELECT DISTINCT(ic.image_id) AS image_id,(ic.category_id) AS category_id
114  FROM '.COMMENTS_TABLE.' AS c, '.IMAGE_CATEGORY_TABLE.' AS ic
115  WHERE c.image_id = ic.image_id
116    AND date >= \''.$maxdate.'\'';
117if ($user['status'] != 'admin')
118{
119  $query.= "
120    AND validated = 'true'";
121  // we must not show pictures of a forbidden category
122  if ($user['forbidden_categories'] != '')
123  {
124    $query.= '
125    AND category_id NOT IN ('.$user['forbidden_categories'].')';
126  }
127}
128$query.= '
129  ORDER BY ic.image_id DESC
130;';
131$result = pwg_query($query);
132if ($user['status'] == 'admin')
133{
134  $template->assign_block_vars('validation', array());
135}
136while ($row = mysql_fetch_array($result))
137{
138  $category_id = $row['category_id'];
139 
140  // for each picture, getting informations for displaying thumbnail and
141  // link to the full size picture
142  $query = '
143SELECT name,file,storage_category_id as cat_id,tn_ext,path
144  FROM '.IMAGES_TABLE.'
145  WHERE id = '.$row['image_id'].'
146;';
147  $subresult = pwg_query($query);
148  $subrow = mysql_fetch_array($subresult);
149
150  if (!isset($array_cat_names[$subrow['cat_id']]))
151  {
152    $cat_result = get_cat_info($subrow['cat_id']);
153    $array_cat_names[$subrow['cat_id']] =
154      get_cat_display_name($cat_result['name'], ' &gt; ', '');
155  }
156 
157  // name of the picture
158  $name = $array_cat_names[$category_id].' &gt; ';
159  if (!empty($subrow['name']))
160  {
161    $name.= $subrow['name'];
162  }
163  else
164  {
165    $name.= str_replace('_',' ',get_filename_wo_extension($subrow['file']));
166  }
167  $name.= ' [ '.$subrow['file'].' ]';
168  // source of the thumbnail picture
169  $thumbnail_src = get_thumbnail_src($subrow['path'], @$subrow['tn_ext']);
170  // link to the full size picture
171  $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id;
172  $url.= '&amp;image_id='.$row['image_id'];
173   
174  $template->assign_block_vars(
175    'picture',
176    array(
177      'TITLE_IMG'=>$name,
178      'I_THUMB'=>$thumbnail_src,
179      'U_THUMB'=>add_session_id($url)
180      ));
181   
182  // for each picture, retrieving all comments
183  $query = '
184SELECT *
185  FROM '.COMMENTS_TABLE.'
186  WHERE image_id = '.$row['image_id'].'
187    AND date >= \''.$maxdate.'\'';
188  if ($user['status'] != 'admin')
189  {
190    $query.= '
191    AND validated = \'true\'';
192  }
193  $query.= '
194  ORDER BY date DESC
195;';
196  $handleresult = pwg_query($query);
197  while ($subrow = mysql_fetch_array($handleresult))
198  {
199    $author = $subrow['author'];
200    if (empty($subrow['author']))
201    {
202      $author = $lang['guest'];
203    }
204
205    $template->assign_block_vars(
206      'picture.comment',
207      array(
208        'COMMENT_AUTHOR'=>$author,
209        'COMMENT_DATE'=>format_date($subrow['date'],'mysql_datetime',true),
210        'COMMENT'=>parse_comment_content($subrow['content']),
211        ));
212   
213    if ($user['status'] == 'admin')
214    {
215      $template->assign_block_vars(
216        'picture.comment.validation',
217        array(
218          'ID'=> $subrow['id'],
219          'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': ''
220          ));
221    }
222  }
223}
224// +-----------------------------------------------------------------------+
225// |                           html code display                           |
226// +-----------------------------------------------------------------------+
227if (defined('IN_ADMIN'))
228{
229  $template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
230}
231else
232{
233  $template->assign_block_vars('title',array());
234  $template->pparse('comments');
235  include(PHPWG_ROOT_PATH.'include/page_tail.php');
236}
237?>
Note: See TracBrowser for help on using the repository browser.