source: trunk/admin/comments.php @ 25744

Last change on this file since 25744 was 25744, checked in by plg, 7 years ago

feature 2920: add a navigation bar for long list of comments

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