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

Last change on this file since 2297 was 2297, checked in by plg, 16 years ago

Modification: new header on PHP files, PhpWebGallery renamed Piwigo.

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