source: trunk/admin/comments.php @ 25084

Last change on this file since 25084 was 25084, checked in by plg, 11 years ago

feature 2920 added: change admin screen "pending comments" to "all comments".
Now the administrator can filter on "all" or "pending" with a single click.

In the admin menu, we display the number of pending comments.

  • Property svn:eol-style set to LF
File size: 6.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 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
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die ("Hacking attempt!");
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
36// +-----------------------------------------------------------------------+
37// |                                actions                                |
38// +-----------------------------------------------------------------------+
39
40if (!empty($_POST))
41{
42  if (empty($_POST['comments']))
43  {
44    $page['errors'][] = l10n('Select at least one comment');
45  }
46  else
47  {
48    include_once( PHPWG_ROOT_PATH .'include/functions_comment.inc.php' );
49    check_input_parameter('comments', $_POST, true, PATTERN_ID);
50   
51    if (isset($_POST['validate']))
52    {
53      validate_user_comment($_POST['comments']);
54
55      $page['infos'][] = l10n_dec(
56        '%d user comment validated', '%d user comments validated',
57        count($_POST['comments'])
58        );
59    }
60
61    if (isset($_POST['reject']))
62    {
63      delete_user_comment($_POST['comments']);
64
65      $page['infos'][] = l10n_dec(
66        '%d user comment rejected', '%d user comments rejected',
67        count($_POST['comments'])
68        );
69    }
70  }
71}
72
73// +-----------------------------------------------------------------------+
74// |                             template init                             |
75// +-----------------------------------------------------------------------+
76
77$template->set_filenames(array('comments'=>'comments.tpl'));
78
79$template->assign(
80  array(
81    'F_ACTION' => get_root_url().'admin.php?page=comments'
82    )
83  );
84
85// +-----------------------------------------------------------------------+
86// | Tabs                                                                  |
87// +-----------------------------------------------------------------------+
88
89include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
90
91$tabsheet = new tabsheet();
92$tabsheet->set_id('comments');
93$tabsheet->select('');
94$tabsheet->assign();
95
96// +-----------------------------------------------------------------------+
97// |                           comments display                            |
98// +-----------------------------------------------------------------------+
99
100$nb_total = 0;
101$nb_pending = 0;
102
103$query = '
104SELECT
105    COUNT(*) AS counter,
106    validated
107  FROM '.COMMENTS_TABLE.'
108  GROUP BY validated
109;';
110$result = pwg_query($query);
111while ($row = pwg_db_fetch_assoc($result))
112{
113  $nb_total+= $row['counter'];
114
115  if ('false' == $row['validated'])
116  {
117    $nb_pending = $row['counter'];
118  }
119}
120
121if (!isset($_GET['filter']) and $nb_pending > 0)
122{
123  $page['filter'] = 'pending';
124}
125else
126{
127  $page['filter'] = 'all';
128}
129
130if (isset($_GET['filter']) and 'pending' == $_GET['filter'])
131{
132  $page['filter'] = $_GET['filter'];
133}
134
135$template->assign(
136  array(
137    'nb_total' => $nb_total,
138    'nb_pending' => $nb_pending,
139    'filter' => $page['filter'],
140    )
141  );
142
143$where_clauses = array('1=1');
144
145if ('pending' == $page['filter'])
146{
147  $where_clauses[] = 'validated=\'false\'';
148}
149
150$query = '
151SELECT
152    c.id,
153    c.image_id,
154    c.date,
155    c.author,
156    '.$conf['user_fields']['username'].' AS username,
157    c.content,
158    i.path,
159    i.representative_ext,
160    validated
161  FROM '.COMMENTS_TABLE.' AS c
162    INNER JOIN '.IMAGES_TABLE.' AS i
163      ON i.id = c.image_id
164    LEFT JOIN '.USERS_TABLE.' AS u
165      ON u.'.$conf['user_fields']['id'].' = c.author_id
166  WHERE '.implode(' AND ', $where_clauses).'
167  ORDER BY c.date DESC
168;';
169$result = pwg_query($query);
170while ($row = pwg_db_fetch_assoc($result))
171{
172  $thumb = DerivativeImage::thumb_url(
173      array(
174        'id'=>$row['image_id'],
175        'path'=>$row['path'],
176        )
177     );
178  if (empty($row['author_id'])) 
179  {
180    $author_name = $row['author'];
181  }
182  else
183  {
184    $author_name = stripslashes($row['username']);
185  }
186  $template->append(
187    'comments',
188    array(
189      'U_PICTURE' => get_root_url().'admin.php?page=photo-'.$row['image_id'],
190      'ID' => $row['id'],
191      'TN_SRC' => $thumb,
192      'AUTHOR' => trigger_event('render_comment_author', $author_name),
193      'DATE' => format_date($row['date'], true),
194      'CONTENT' => trigger_event('render_comment_content',$row['content']),
195      'IS_PENDING' => ('false' == $row['validated']),
196      )
197    );
198
199  $list[] = $row['id'];
200}
201
202// +-----------------------------------------------------------------------+
203// |                           sending html code                           |
204// +-----------------------------------------------------------------------+
205
206$template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
207
208?>
Note: See TracBrowser for help on using the repository browser.