source: trunk/comments.php @ 579

Last change on this file since 579 was 579, checked in by z0rglub, 20 years ago
  • refactoring of comments.php
  • creation of function get_thumbnail_src used everywhere a thumbnail must be displayed
  • creation of function parse_comment_content (used in comments.php and picture.php)
  • concerning undefined index on arrays retrieved in database, instead of testing possibly unset values, use of @ operator (smarter...)
  • add pre tag in default.css stylesheet for debugging purpose (need to have left aligned text)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.8 KB
RevLine 
[166]1<?php
[354]2// +-----------------------------------------------------------------------+
[362]3// |                             comments.php                              |
[354]4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
[362]6// | branch        : BSF (Best So Far)                                     |
[354]7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-10-23 17:56:46 +0000 (Sat, 23 Oct 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 579 $
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// +-----------------------------------------------------------------------+
[166]27
[579]28// +-----------------------------------------------------------------------+
29// |                           initialization                              |
30// +-----------------------------------------------------------------------+
[393]31if (!defined('IN_ADMIN'))
32{
33  define('PHPWG_ROOT_PATH','./');
[579]34  include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
[393]35}
[345]36
[579]37if (isset($_GET['last_days']))
[393]38{
[579]39  define('MAX_DAYS', $_GET['last_days']);
[393]40}
[579]41else
[393]42{
[579]43  define('MAX_DAYS', 0);
[393]44}
[579]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  mysql_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  mysql_query($query);
67}
68// +-----------------------------------------------------------------------+
69// |                       page header and options                         |
70// +-----------------------------------------------------------------------+
[393]71if (!defined('IN_ADMIN'))
72{
73  $title= $lang['title_comments'];
74  include(PHPWG_ROOT_PATH.'include/page_header.php');
75}
[355]76
[579]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  );
[355]89
[579]90foreach ($conf['last_days'] as $option)
91{
[420]92  $url = $_SERVER['PHP_SELF'].'?last_days='.($option - 1);
[579]93  if (defined('IN_ADMIN'))
94  {
95    $url.= '&amp;page=comments';
96  }
[420]97  $template->assign_block_vars(
98    'last_day_option',
99    array(
100      'OPTION'=>$option,
[579]101      'T_STYLE'=>(($option == MAX_DAYS + 1)?'text-decoration:underline;':''),
102      'U_OPTION'=>add_session_id($url)
[420]103      )
104    );
[355]105}
[579]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'));
[355]111
[579]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')
[166]118{
[579]119  $query.= "
120    AND validated = 'true'";
[393]121  // we must not show pictures of a forbidden category
[579]122  if ($user['forbidden_categories'] != '')
[393]123  {
[579]124    $query.= '
125    AND category_id NOT IN ('.$user['forbidden_categories'].')';
[393]126  }
[355]127}
[579]128$query.= '
129  ORDER BY ic.image_id DESC
130;';
131$result = mysql_query($query);
132if ($user['status'] == 'admin')
[393]133{
134  $template->assign_block_vars('validation', array());
135}
[579]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
144  FROM '.IMAGES_TABLE.'
145  WHERE id = '.$row['image_id'].'
146;';
147  $subresult = mysql_query($query);
148  $subrow = mysql_fetch_array($subresult);
149
150  if (!isset($array_cat_names[$subrow['cat_id']]))
[166]151  {
[579]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['file'],
170                                     $subrow['cat_id'],
171                                     @$subrow['tn_ext']);
172  // link to the full size picture
173  $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id;
174  $url.= '&amp;image_id='.$row['image_id'];
175   
176  $template->assign_block_vars(
177    'picture',
178    array(
179      'TITLE_IMG'=>$name,
180      'I_THUMB'=>$thumbnail_src,
181      'U_THUMB'=>add_session_id($url)
182      ));
183   
184  // for each picture, retrieving all comments
185  $query = '
186SELECT *
187  FROM '.COMMENTS_TABLE.'
188  WHERE image_id = '.$row['image_id'].'
189    AND date >= \''.$maxdate.'\'';
190  if ($user['status'] != 'admin')
191  {
192    $query.= '
193    AND validated = \'true\'';
194  }
195  $query.= '
196  ORDER BY date DESC
197;';
198  $handleresult = mysql_query($query);
199  while ($subrow = mysql_fetch_array($handleresult))
200  {
201    $author = $subrow['author'];
202    if (empty($subrow['author']))
[166]203    {
[579]204      $author = $lang['guest'];
[166]205    }
206
[464]207    $template->assign_block_vars(
[579]208      'picture.comment',
[464]209      array(
[579]210        'COMMENT_AUTHOR'=>$author,
211        'COMMENT_DATE'=>format_date($subrow['date'],'mysql_datetime',true),
212        'COMMENT'=>parse_comment_content($subrow['content']),
[464]213        ));
214   
[579]215    if ($user['status'] == 'admin')
[393]216    {
[420]217      $template->assign_block_vars(
[579]218        'picture.comment.validation',
219        array(
220          'ID'=> $subrow['id'],
221          'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': ''
[420]222          ));
[166]223    }
224  }
[579]225}
226// +-----------------------------------------------------------------------+
227// |                           html code display                           |
228// +-----------------------------------------------------------------------+
[393]229if (defined('IN_ADMIN'))
230{
231  $template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
232}
233else
234{
235  $template->assign_block_vars('title',array());
236  $template->pparse('comments');
237  include(PHPWG_ROOT_PATH.'include/page_tail.php');
238}
[362]239?>
Note: See TracBrowser for help on using the repository browser.