source: branches/1.7/include/picture_comment.inc.php @ 4636

Last change on this file since 4636 was 2154, checked in by rvelices, 17 years ago
  • send status code 403 when attempt to enter a comment, but comments are disabled
  • added trigger wether we should increment hit count
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: picture_comment.inc.php 2154 2007-10-29 23:10:31Z rvelices $
8// | last update   : $Date: 2007-10-29 23:10:31 +0000 (Mon, 29 Oct 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2154 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27/**
28 * This file is included by the picture page to manage user comments
29 *
30 */
31
32// the picture is commentable if it belongs at least to one category which
33// is commentable
34$page['show_comments'] = false;
35foreach ($related_categories as $category)
36{
37  if ($category['commentable'] == 'true')
38  {
39    $page['show_comments'] = true;
40    break;
41  }
42}
43
44if ( $page['show_comments'] and isset( $_POST['content'] ) )
45{
46  if ( $user['is_the_guest'] and !$conf['comments_forall'] )
47  {
48    die ('Session expired');
49  }
50
51  $comm = array(
52    'author' => trim( stripslashes(@$_POST['author']) ),
53    'content' => trim( stripslashes($_POST['content']) ),
54    'image_id' => $page['image_id'],
55   );
56
57  include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
58
59  $comment_action = insert_user_comment($comm, @$_POST['key'], $infos );
60
61  switch ($comment_action)
62  {
63    case 'moderate':
64      array_push( $infos, $lang['comment_to_validate'] );
65    case 'validate':
66      array_push( $infos, $lang['comment_added']);
67      break;
68    case 'reject':
69      set_status_header(403);
70      array_push($infos, l10n('comment_not_added') );
71      break;
72    default:
73      trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
74  }
75
76  foreach ($infos as $info)
77  {
78    $template->assign_block_vars(
79        'information',
80        array( 'INFORMATION'=>$info )
81      );
82  }
83
84  // allow plugins to notify what's going on
85  trigger_action( 'user_comment_insertion',
86      array_merge($comm, array('action'=>$comment_action) )
87    );
88}
89elseif ( isset($_POST['content']) )
90{
91  set_status_header(403);
92  die('ugly spammer');
93}
94
95if ($page['show_comments'])
96{
97  // number of comment for this picture
98  $query = 'SELECT COUNT(*) AS nb_comments';
99  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$page['image_id'];
100  $query.= " AND validated = 'true'";
101  $query.= ';';
102  $row = mysql_fetch_array( pwg_query( $query ) );
103
104  // navigation bar creation
105  if (!isset($page['start']))
106  {
107    $page['start'] = 0;
108  }
109
110  $page['navigation_bar'] = create_navigation_bar(
111    duplicate_picture_url(array(), array('start')),
112    $row['nb_comments'],
113    $page['start'],
114    $conf['nb_comment_page'],
115    true // We want a clean URL
116    );
117
118  $template->assign_block_vars(
119    'comments',
120    array(
121      'NB_COMMENT' => $row['nb_comments'],
122      'NAV_BAR' => $page['navigation_bar'],
123      )
124    );
125
126  if ($row['nb_comments'] > 0)
127  {
128    $query = '
129SELECT id,author,date,image_id,content
130  FROM '.COMMENTS_TABLE.'
131  WHERE image_id = '.$page['image_id'].'
132    AND validated = \'true\'
133  ORDER BY date ASC
134  LIMIT '.$page['start'].', '.$conf['nb_comment_page'].'
135;';
136    $result = pwg_query( $query );
137
138    while ($row = mysql_fetch_array($result))
139    {
140      $template->assign_block_vars(
141        'comments.comment',
142        array(
143          'COMMENT_AUTHOR' => trigger_event('render_comment_author',
144            empty($row['author'])
145            ? $lang['guest']
146            : $row['author']),
147
148          'COMMENT_DATE' => format_date(
149            $row['date'],
150            'mysql_datetime',
151            true),
152
153          'COMMENT' => trigger_event('render_comment_content',$row['content']),
154          )
155        );
156
157      if (is_admin())
158      {
159        $template->assign_block_vars(
160          'comments.comment.delete',
161          array(
162            'U_COMMENT_DELETE' =>
163              add_url_params(
164                    $url_self,
165                    array(
166                      'action'=>'delete_comment',
167                      'comment_to_delete'=>$row['id']
168                    )
169                )
170            )
171          );
172      }
173    }
174  }
175
176  if (!$user['is_the_guest']
177      or ($user['is_the_guest'] and $conf['comments_forall']))
178  {
179    include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
180    $key = get_comment_post_key($page['image_id']);
181    $content = '';
182    if ('reject'===@$comment_action)
183    {
184      $content = htmlspecialchars($comm['content']);
185    }
186    $template->assign_block_vars('comments.add_comment',
187        array(
188          'KEY' => $key,
189          'CONTENT' => $content
190        ));
191    // display author field if the user is not logged in
192    if ($user['is_the_guest'])
193    {
194      $template->assign_block_vars(
195        'comments.add_comment.author_field', array()
196        );
197    }
198  }
199}
200
201?>
Note: See TracBrowser for help on using the repository browser.