source: trunk/include/picture_comment.inc.php @ 1082

Last change on this file since 1082 was 1082, checked in by plg, 18 years ago

new: cleaner URL. Instead of category.php?cat=search&search=123&start=42,
you now have category.php?/search/123/start-42. Functions make_index_url and
make_picture_url build these new URLs. Functions duplicate_picture_url and
duplicate_index_url provide shortcuts to URL creation. The current main page
page is still category.php but this can be modified easily in make_index_url
function. In this first version, no backward compatibility. Calendar
definition in URL must be discussed with rvelices.

improvement: picture.php redesigned. First actions like "set as
representative" or "delete a comment" which all lead to a redirection. Then
the page (the big mess) and includes of new sub pages to manage specific
parts of the page (metadata, user comments, rates).

new: with the cleaner URL comes a new terminology. $pagecat doesn't
exist anymore. $pagesection is among 'categories', 'tags' (TODO),
'list', 'most_seen'... And sub parameters are set : $pagecategory if
$pagesection is "categories". See URL analyse in
include/section_init.inc.php for details.

File size: 6.9 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-09 00:14:53 +0100 (jeu, 09 mar 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1070 $
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 * This file is included by the picture page to manage user comments
30 *
31 */
32
33if ( isset( $_POST['content'] ) && !empty($_POST['content']) )
34{
35  $register_comment = true;
36  $author = !empty($_POST['author'])?$_POST['author']:$lang['guest'];
37  // if a guest try to use the name of an already existing user, he must be
38  // rejected
39  if ( $author != $user['username'] )
40  {
41    $query = 'SELECT COUNT(*) AS user_exists';
42    $query.= ' FROM '.USERS_TABLE;
43    $query.= ' WHERE '.$conf['user_fields']['username']." = '".$author."'";
44    $query.= ';';
45    $row = mysql_fetch_array( pwg_query( $query ) );
46    if ( $row['user_exists'] == 1 )
47    {
48      $template->assign_block_vars(
49        'information',
50        array('INFORMATION'=>$lang['comment_user_exists']));
51      $register_comment = false;
52    }
53  }
54
55  if ( $register_comment )
56  {
57    // anti-flood system
58    $reference_date = time() - $conf['anti-flood_time'];
59    $query = 'SELECT id FROM '.COMMENTS_TABLE;
60    $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')';
61    $query.= " AND author = '".$author."'";
62    $query.= ';';
63    if ( mysql_num_rows( pwg_query( $query ) ) == 0
64         or $conf['anti-flood_time'] == 0 )
65    {
66      list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
67
68      $data = array();
69      $data{'author'} = $author;
70      $data{'date'} = $dbnow;
71      $data{'image_id'} = $page['image_id'];
72      $data{'content'} = htmlspecialchars( $_POST['content'], ENT_QUOTES);
73
74      if (!$conf['comments_validation'] or is_admin())
75      {
76        $data{'validated'} = 'true';
77        $data{'validation_date'} = $dbnow;
78      }
79      else
80      {
81        $data{'validated'} = 'false';
82      }
83
84      include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
85      $fields = array('author', 'date', 'image_id', 'content', 'validated',
86                      'validation_date');
87      mass_inserts(COMMENTS_TABLE, $fields, array($data));
88
89      // information message
90      $message = $lang['comment_added'];
91
92      if (!$conf['comments_validation'] or is_admin())
93
94      if ( $conf['comments_validation'] and !is_admin() )
95      {
96        $message.= '<br />'.$lang['comment_to_validate'];
97      }
98      $template->assign_block_vars('information',
99                                   array('INFORMATION'=>$message));
100    }
101    else
102    {
103      // information message
104      $template->assign_block_vars(
105        'information',
106        array('INFORMATION'=>$lang['comment_anti-flood']));
107    }
108  }
109}
110
111// the picture is commentable if it belongs at least to one category which
112// is commentable
113$page['show_comments'] = false;
114foreach ($related_categories as $category)
115{
116  if ($category['commentable'] == 'true')
117  {
118    $page['show_comments'] = true;
119  }
120}
121
122if ($page['show_comments'])
123{
124  // number of comment for this picture
125  $query = 'SELECT COUNT(*) AS nb_comments';
126  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$page['image_id'];
127  $query.= " AND validated = 'true'";
128  $query.= ';';
129  $row = mysql_fetch_array( pwg_query( $query ) );
130
131  // navigation bar creation
132  $url = PHPWG_ROOT_PATH.'picture.php';
133  $url.= get_query_string_diff(array('add_fav','start'));
134
135//   $url = duplicate_picture_URL(
136//     array(),
137//     array('start')
138//     );
139
140  if (!isset($_GET['start'])
141      or !is_numeric($_GET['start'])
142      or (is_numeric($_GET['start']) and $_GET['start'] < 0))
143  {
144    $page['start'] = 0;
145  }
146  else
147  {
148    $page['start'] = $_GET['start'];
149  }
150  $page['navigation_bar'] = create_navigation_bar(
151    $url,
152    $row['nb_comments'],
153    $page['start'],
154    $conf['nb_comment_page'],
155    ''
156    );
157 
158  $template->assign_block_vars(
159    'comments',
160    array(
161      'NB_COMMENT' => $row['nb_comments'],
162      'NAV_BAR' => $page['navigation_bar'],
163      )
164    );
165
166  if ($row['nb_comments'] > 0)
167  {
168    $query = '
169SELECT id,author,date,image_id,content
170  FROM '.COMMENTS_TABLE.'
171  WHERE image_id = '.$page['image_id'].'
172    AND validated = \'true\'
173  ORDER BY date ASC
174  LIMIT '.$page['start'].', '.$conf['nb_comment_page'].'
175;';
176    $result = pwg_query( $query );
177
178    while ($row = mysql_fetch_array($result))
179    {
180      $template->assign_block_vars(
181        'comments.comment',
182        array(
183          'COMMENT_AUTHOR' => empty($row['author'])
184            ? $lang['guest']
185            : $row['author'],
186         
187          'COMMENT_DATE' => format_date(
188            $row['date'],
189            'mysql_datetime',
190            true),
191         
192          'COMMENT' => parse_comment_content($row['content']),
193          )
194        );
195
196      if (is_admin())
197      {
198        $template->assign_block_vars(
199          'comments.comment.delete',
200          array(
201            'U_COMMENT_DELETE' => $url.'&amp;del='.$row['id']
202            )
203          );
204      }
205    }
206  }
207
208  if (!$user['is_the_guest']
209      or ($user['is_the_guest'] and $conf['comments_forall']))
210  {
211    $template->assign_block_vars('comments.add_comment', array());
212    // display author field if the user is not logged in
213    if (!$user['is_the_guest'])
214    {
215      $template->assign_block_vars(
216        'comments.add_comment.author_known',
217        array('KNOWN_AUTHOR'=>$user['username'])
218        );
219    }
220    else
221    {
222      $template->assign_block_vars(
223        'comments.add_comment.author_field', array()
224        );
225    }
226  }
227}
228
229?>
Note: See TracBrowser for help on using the repository browser.