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

Revision 13088, 7.4 KB checked in by mistic100, 8 years ago (diff)

feature 2379: change captions for comment ordering

  • Property svn:eol-style set to LF
RevLine 
[1082]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[12922]5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[1082]23
24/**
25 * This file is included by the picture page to manage user comments
[1090]26 *
[1082]27 */
[1737]28
[1610]29// the picture is commentable if it belongs at least to one category which
30// is commentable
31$page['show_comments'] = false;
32foreach ($related_categories as $category)
[1082]33{
[11839]34  if ($category['commentable'])
[1082]35  {
[1610]36    $page['show_comments'] = true;
37    break;
38  }
39}
40
[10122]41if ( $page['show_comments'] and isset( $_POST['content'] ) )
[1610]42{
[10122]43  if ( is_a_guest() and !$conf['comments_forall'] )
[1610]44  {
[10122]45    die ('Session expired');
46  }
[1610]47
[10122]48  $comm = array(
49    'author' => trim( @$_POST['author'] ),
50    'content' => trim( $_POST['content'] ),
51    'image_id' => $page['image_id'],
52   );
[1610]53
[10122]54  include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
[2101]55
[12764]56  $comment_action = insert_user_comment($comm, @$_POST['key'], $page['infos']);
[1082]57
[10122]58  switch ($comment_action)
[1610]59  {
[10122]60    case 'moderate':
[12764]61      array_push($page['infos'], l10n('An administrator must authorize your comment before it is visible.') );
[10122]62    case 'validate':
[12764]63      array_push($page['infos'], l10n('Your comment has been registered'));
[10122]64      break;
65    case 'reject':
66      set_status_header(403);
[12764]67      array_push($page['errors'], l10n('Your comment has NOT been registered because it did not pass the validation rules') );
[10122]68      break;
69    default:
70      trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
[1849]71  }
[10122]72
73  // allow plugins to notify what's going on
74  trigger_action( 'user_comment_insertion',
75      array_merge($comm, array('action'=>$comment_action) )
76    );
[1082]77}
[10122]78elseif ( isset($_POST['content']) )
79{
80  set_status_header(403);
81  die('ugly spammer');
82}
[1082]83
84if ($page['show_comments'])
85{
[5654]86  if ( !is_admin() )
87  {
88    $validated_clause = '  AND validated = \'true\'';
89  }
90  else
91  {
92    $validated_clause = '';
93  }
94
[3145]95  // number of comments for this picture
96  $query = '
[5654]97SELECT
98    COUNT(*) AS nb_comments
[3145]99  FROM '.COMMENTS_TABLE.'
[5654]100  WHERE image_id = '.$page['image_id']
101  .$validated_clause.'
102;';
[4325]103  $row = pwg_db_fetch_assoc( pwg_query( $query ) );
[1082]104
105  // navigation bar creation
[1084]106  if (!isset($page['start']))
[1082]107  {
108    $page['start'] = 0;
109  }
[1090]110
[2227]111  $navigation_bar = create_navigation_bar(
[1503]112    duplicate_picture_url(array(), array('start')),
[1082]113    $row['nb_comments'],
114    $page['start'],
115    $conf['nb_comment_page'],
[1084]116    true // We want a clean URL
[1082]117    );
[1090]118
[2227]119  $template->assign(
[1082]120    array(
[2227]121      'COMMENT_COUNT' => $row['nb_comments'],
[3172]122      'navbar' => $navigation_bar,
[1082]123      )
124    );
125
126  if ($row['nb_comments'] > 0)
127  {
[12894]128    // comments order (get, session, conf)
[13021]129    if (!empty($_GET['comments_order']) && in_array(strtoupper($_GET['comments_order']), array('ASC', 'DESC')))
[12894]130    {
[13021]131      pwg_set_session_var('comments_order', $_GET['comments_order']);
[12894]132    }
[13021]133    $comments_order = pwg_get_session_var('comments_order', $conf['comments_order']);
134
[12894]135    $template->assign(array(
136      'COMMENTS_ORDER_URL' => duplicate_picture_url().'&amp;comments_order='.($comments_order == 'ASC' ? 'DESC' : 'ASC'),
[13088]137      'COMMENTS_ORDER_TITLE' => $comments_order == 'ASC' ? l10n('old &rarr; new') : l10n('new &rarr; old'),
[12894]138      ));
139       
[1082]140    $query = '
[5654]141SELECT
142    com.id,
143    author,
144    author_id,
145    '.$conf['user_fields']['username'].' AS username,
146    date,
147    image_id,
148    content,
149    validated
[3450]150  FROM '.COMMENTS_TABLE.' AS com
151  LEFT JOIN '.USERS_TABLE.' AS u
[3452]152    ON u.'.$conf['user_fields']['id'].' = author_id
[5654]153  WHERE image_id = '.$page['image_id'].'
154    '.$validated_clause.'
[12894]155  ORDER BY date '.$comments_order.'
[4607]156  LIMIT '.$conf['nb_comment_page'].' OFFSET '.$page['start'].'
[1082]157;';
158    $result = pwg_query( $query );
159
[4325]160    while ($row = pwg_db_fetch_assoc($result))
[1082]161    {
[3488]162      if (!empty($row['author']))
[3450]163      {
164        $author = $row['author'];
165        if ($author == 'guest')
166        {
167          $author = l10n('guest');
168        }
169      }
170      else
171      {
[4304]172        $author = stripslashes($row['username']);
[3450]173      }
174
[3122]175      $tpl_comment =
[1082]176        array(
[11236]177          'ID' => $row['id'],
[3450]178          'AUTHOR' => trigger_event('render_comment_author', $author),
[11236]179          'DATE' => format_date($row['date'], true),
[2227]180          'CONTENT' => trigger_event('render_comment_content',$row['content']),
[1082]181        );
182
[3450]183      if (can_manage_comment('delete', $row['author_id']))
[3445]184      {
[5195]185        $tpl_comment['U_DELETE'] = add_url_params(
186          $url_self,
187          array(
188            'action'=>'delete_comment',
189            'comment_to_delete'=>$row['id'],
190            'pwg_token' => get_pwg_token(),
191            )
192          );
[3445]193      }
[3450]194      if (can_manage_comment('edit', $row['author_id']))
[3445]195      {
[8600]196        $tpl_comment['U_EDIT'] = add_url_params(
[5195]197          $url_self,
198          array(
199            'action'=>'edit_comment',
200            'comment_to_edit'=>$row['id'],
201            'pwg_token' => get_pwg_token(),
202            )
203          );
[8600]204          if (isset($edit_comment) and ($row['id'] == $edit_comment))
205          {
206            $tpl_comment['IN_EDIT'] = true;
207            $key = get_ephemeral_key(2, $page['image_id']);
208            $tpl_comment['KEY'] = $key;
209            $tpl_comment['CONTENT'] = $row['content'];
210          }
[3445]211      }
[1082]212      if (is_admin())
213      {
[8600]214        if ($row['validated'] != 'true')
215        {
216          $tpl_comment['U_VALIDATE'] = add_url_params(
217                  $url_self,
218                  array(
219                    'action' => 'validate_comment',
220                    'comment_to_validate' => $row['id'],
221                    'pwg_token' => get_pwg_token(),
222                    )
223                  );
224        }
[1082]225      }
[2227]226      $template->append('comments', $tpl_comment);
[1082]227    }
228  }
229
[5649]230  $show_add_comment_form = true;
231  if (isset($edit_comment))
[1082]232  {
[5649]233    $show_add_comment_form = false;
234  }
235  if (is_a_guest() and !$conf['comments_forall'])
236  {
237    $show_add_comment_form = false;
238  }
239
240  if ($show_add_comment_form)
241  {
[7495]242    $key = get_ephemeral_key(3, $page['image_id']);
[2227]243    $template->assign('comment_add',
[1737]244        array(
[2227]245          'F_ACTION' => $url_self,
[1744]246          'KEY' => $key,
[12767]247          'CONTENT' => null,
[2227]248          'SHOW_AUTHOR' => !is_classic_user()
[1737]249        ));
[1082]250  }
251}
252
253?>
Note: See TracBrowser for help on using the repository browser.