source: branches/2.7/admin/comments.php @ 30973

Revision 30973, 7.1 KB checked in by plg, 4 years ago (diff)

merge r30972 from trunk to branch 2.7

bug 3203 fixed: for IE, explicit the url even for staying on the same page

  • Property svn:eol-style set to LF
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2014 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$my_base_url = get_root_url().'admin.php?page=';
102
103$tabsheet = new tabsheet();
104$tabsheet->set_id('comments');
105$tabsheet->select('');
106$tabsheet->assign();
107
108// +-----------------------------------------------------------------------+
109// |                           comments display                            |
110// +-----------------------------------------------------------------------+
111
112$nb_total = 0;
113$nb_pending = 0;
114
115$query = '
116SELECT
117    COUNT(*) AS counter,
118    validated
119  FROM '.COMMENTS_TABLE.'
120  GROUP BY validated
121;';
122$result = pwg_query($query);
123while ($row = pwg_db_fetch_assoc($result))
124{
125  $nb_total+= $row['counter'];
126
127  if ('false' == $row['validated'])
128  {
129    $nb_pending = $row['counter'];
130  }
131}
132
133if (!isset($_GET['filter']) and $nb_pending > 0)
134{
135  $page['filter'] = 'pending';
136}
137else
138{
139  $page['filter'] = 'all';
140}
141
142if (isset($_GET['filter']) and 'pending' == $_GET['filter'])
143{
144  $page['filter'] = $_GET['filter'];
145}
146
147$template->assign(
148  array(
149    'nb_total' => $nb_total,
150    'nb_pending' => $nb_pending,
151    'filter' => $page['filter'],
152    )
153  );
154
155$where_clauses = array('1=1');
156
157if ('pending' == $page['filter'])
158{
159  $where_clauses[] = 'validated=\'false\'';
160}
161
162$query = '
163SELECT
164    c.id,
165    c.image_id,
166    c.date,
167    c.author,
168    '.$conf['user_fields']['username'].' AS username,
169    c.content,
170    i.path,
171    i.representative_ext,
172    validated,
173    c.anonymous_id
174  FROM '.COMMENTS_TABLE.' AS c
175    INNER JOIN '.IMAGES_TABLE.' AS i
176      ON i.id = c.image_id
177    LEFT JOIN '.USERS_TABLE.' AS u
178      ON u.'.$conf['user_fields']['id'].' = c.author_id
179  WHERE '.implode(' AND ', $where_clauses).'
180  ORDER BY c.date DESC
181  LIMIT '.$page['start'].', '.$conf['comments_page_nb_comments'].'
182;';
183$result = pwg_query($query);
184while ($row = pwg_db_fetch_assoc($result))
185{
186  $thumb = DerivativeImage::thumb_url(
187      array(
188        'id'=>$row['image_id'],
189        'path'=>$row['path'],
190        )
191     );
192  if (empty($row['author_id']))
193  {
194    $author_name = $row['author'];
195  }
196  else
197  {
198    $author_name = stripslashes($row['username']);
199  }
200  $template->append(
201    'comments',
202    array(
203      'U_PICTURE' => get_root_url().'admin.php?page=photo-'.$row['image_id'],
204      'ID' => $row['id'],
205      'TN_SRC' => $thumb,
206      'AUTHOR' => trigger_change('render_comment_author', $author_name),
207      'DATE' => format_date($row['date'], array('day_name','day','month','year','time')),
208      'CONTENT' => trigger_change('render_comment_content',$row['content']),
209      'IS_PENDING' => ('false' == $row['validated']),
210      'IP' => $row['anonymous_id'],
211      )
212    );
213
214  $list[] = $row['id'];
215}
216
217// +-----------------------------------------------------------------------+
218// |                            navigation bar                             |
219// +-----------------------------------------------------------------------+
220
221$navbar = create_navigation_bar(
222  get_root_url().'admin.php'.get_query_string_diff(array('start')),
223  ('pending' == $page['filter'] ? $nb_pending : $nb_total),
224  $page['start'],
225  $conf['comments_page_nb_comments']
226  );
227
228$template->assign('navbar', $navbar);
229
230// +-----------------------------------------------------------------------+
231// |                           sending html code                           |
232// +-----------------------------------------------------------------------+
233
234$template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
235
236?>
Note: See TracBrowser for help on using the repository browser.