Ignore:
Timestamp:
Dec 22, 2013, 8:30:51 PM (10 years ago)
Author:
mistic100
Message:

update for 2.6 + clean

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Comments_on_Albums/trunk/include/coa_albums.php

    r21347 r26089  
    11<?php
    22/* Code adapted from include/picture_comment.inc.php and picture.php */
    3 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    4 
    5 global $conf, $user;
     3defined('COA_ID') or die('Hacking attempt!');
     4
     5global $template, $page, $conf, $pwg_loaded_plugins, $user;
    66
    77// +-----------------------------------------------------------------------+
     
    1212$url_self = duplicate_index_url(array(
    1313  'category' => array(
    14     'id' => $category['id'], 
    15     'name' => $category['name'], 
     14    'id' => $category['id'],
     15    'name' => $category['name'],
    1616    'permalink' => $category['permalink']
    17     ), 
     17    ),
    1818  array('start')
    1919  ));
     
    2323// |                                actions                                |
    2424// +-----------------------------------------------------------------------+
    25 if (isset($_GET['action'])) 
     25if (isset($_GET['action']))
    2626{
    27   switch ($_GET['action']) 
    28   {
    29     case 'edit_comment' : 
    30     {
    31       include_once(COA_PATH.'include/functions_comment.inc.php'); // custom fonctions
     27  switch ($_GET['action'])
     28  {
     29    case 'edit_comment' :
     30    {
     31      include_once(COA_PATH.'include/functions_comment.inc.php');
    3232      check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID);
    3333      $author_id = get_comment_author_id_albums($_GET['comment_to_edit']);
    3434
    35       if (can_manage_comment('edit', $author_id)) 
    36       {
    37         if (!empty($_POST['content'])) 
     35      if (can_manage_comment('edit', $author_id))
     36      {
     37        if (!empty($_POST['content']))
    3838        {
    3939          check_pwg_token();
     
    4242              'comment_id' => $_GET['comment_to_edit'],
    4343              'category_id' => $category['id'],
    44               'content' => $_POST['content']
     44              'content' => $_POST['content'],
     45              'website_url' => @$_POST['website_url'],
    4546              ),
    4647            $_POST['key']
    4748            );
    48          
     49
    4950          $perform_redirect = false;
    5051          switch ($comment_action)
     
    6970          }
    7071          unset($_POST['content']);
    71         } 
    72         else 
     72        }
     73        else
    7374        {
    7475          $edit_comment = $_GET['comment_to_edit'];
    7576        }
     77
     78        $template->assign('DISPLAY_COMMENTS_BLOCK', true);
    7679        break;
    7780      }
    7881    }
    79     case 'delete_comment' : 
     82    case 'delete_comment' :
    8083    {
    8184      check_pwg_token();
    82      
    83       include_once(COA_PATH.'include/functions_comment.inc.php'); // custom fonctions
    84      
     85
     86      include_once(COA_PATH.'include/functions_comment.inc.php');
     87
    8588      check_input_parameter('comment_to_delete', $_GET, false, PATTERN_ID);
    86      
     89
    8790      $author_id = get_comment_author_id_albums($_GET['comment_to_delete']);
    8891
    89       if (can_manage_comment('delete', $author_id)) 
     92      if (can_manage_comment('delete', $author_id))
    9093      {
    9194        delete_user_comment_albums($_GET['comment_to_delete']);
     
    9497      redirect($url_self);
    9598    }
    96     case 'validate_comment' : 
     99    case 'validate_comment' :
    97100    {
    98101      check_pwg_token();
    99      
    100       include_once(COA_PATH.'include/functions_comment.inc.php'); // custom fonctions
    101      
     102
     103      include_once(COA_PATH.'include/functions_comment.inc.php');
     104
    102105      check_input_parameter('comment_to_validate', $_GET, false, PATTERN_ID);
    103      
     106
    104107      $author_id = get_comment_author_id_albums($_GET['comment_to_validate']);
    105108
    106       if (can_manage_comment('validate', $author_id)) 
     109      if (can_manage_comment('validate', $author_id))
    107110      {
    108111        validate_user_comment_albums($_GET['comment_to_validate']);
     
    118121// |                            insert comment                             |
    119122// +-----------------------------------------------------------------------+
    120 if ($category['commentable'] and isset($_POST['content'])) 
     123if ($category['commentable'] and isset($_POST['content']))
    121124{
    122   if (is_a_guest() and !$conf['comments_forall']) 
     125  if (is_a_guest() and !$conf['comments_forall'])
    123126  {
    124127    die('Session expired');
    125128  }
    126  
     129
    127130  $comm = array(
    128131    'author' => trim( @$_POST['author'] ),
     
    133136   );
    134137
    135   include_once(COA_PATH.'include/functions_comment.inc.php'); // custom fonctions
    136  
     138  include_once(COA_PATH.'include/functions_comment.inc.php');
     139
    137140  $comment_action = insert_user_comment_albums($comm, @$_POST['key'], $page['errors']);
    138141
    139   switch ($comment_action) 
     142  switch ($comment_action)
    140143  {
    141144    case 'moderate':
    142       array_push($page['infos'], l10n('An administrator must authorize your comment before it is visible.'));
     145      $page['infos'][] = l10n('An administrator must authorize your comment before it is visible.');
    143146    case 'validate':
    144       array_push($page['infos'], l10n('Your comment has been registered'));
     147      $page['infos'][] = l10n('Your comment has been registered');
    145148      break;
    146149    case 'reject':
    147150      set_status_header(403);
    148       array_push($page['errors'], l10n('Your comment has NOT been registered because it did not pass the validation rules'));
     151      $page['errors'][] = l10n('Your comment has NOT been registered because it did not pass the validation rules');
    149152      break;
    150153    default:
    151154      trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
    152155  }
    153    
     156
    154157  // allow plugins to notify what's going on
    155158  trigger_action( 'user_comment_insertion',
    156159      array_merge($comm, array('action'=>$comment_action) )
    157160    );
    158    
     161
    159162  $template->assign('DISPLAY_COMMENTS_BLOCK', true);
    160 } 
    161 else if (isset($_POST['content'])) 
     163}
     164else if (isset($_POST['content']))
    162165{
    163166  set_status_header(403);
     
    169172// |                           display comments                            |
    170173// +-----------------------------------------------------------------------+
    171 if ($category['commentable']) 
     174if ($category['commentable'])
    172175{
    173   if (!is_admin())
     176  if (isset($_GET['coa_open']))
     177  {
     178    $template->assign('DISPLAY_COMMENTS_BLOCK', true);
     179  }
     180
     181  if (!is_admin())
    174182  {
    175183    $validated_clause = " AND validated = 'true'";
    176   } 
    177   else 
     184  }
     185  else
    178186  {
    179187    $validated_clause = null;
     
    182190  // number of comments for this category
    183191  $query = '
    184 SELECT 
     192SELECT
    185193    COUNT(*) AS nb_comments
    186194  FROM '.COA_TABLE.'
     
    190198  $row = pwg_db_fetch_assoc(pwg_query($query));
    191199
    192   // navigation bar creation, can't use $_GET['start'] because used by thumbnails navigation bar
    193   if (isset($_GET['start_comments']))
     200  // navigation bar creation
     201  // can't use $_GET['start'] because used by thumbnails navigation bar
     202  if (isset($_GET['start_comments']))
    194203  {
    195204    $page['start_comments'] = $_GET['start_comments'];
    196   } 
    197   else 
     205  }
     206  else
    198207  {
    199208    $page['start_comments'] = 0;
    200209  }
    201   include_once(COA_PATH.'include/functions.inc.php'); // custom fonctions
    202 
    203   $navigation_bar = create_comment_navigation_bar(
    204     duplicate_index_url(array(), array('start')),
     210
     211  $navigation_bar = create_navigation_bar(
     212    add_url_params(duplicate_index_url(array(), array('start_comments')), array('coa_open'=>null)),
    205213    $row['nb_comments'],
    206214    $page['start_comments'],
    207     $conf['nb_comment_page']
     215    $conf['nb_comment_page'],
     216    false,
     217    'start_comments'
    208218    );
    209219
     
    215225    );
    216226
    217   if ($row['nb_comments'] > 0) 
     227  if ($row['nb_comments'] > 0)
    218228  {
    219229    // comments order (get, session, conf)
     
    225235
    226236    $template->assign(array(
    227       'COMMENTS_ORDER_URL' => add_url_params( duplicate_index_url(), array('comments_order'=> ($comments_order == 'ASC' ? 'DESC' : 'ASC') ) ),
     237      'COMMENTS_ORDER_URL' => add_url_params(duplicate_index_url(), array('comments_order'=> ($comments_order == 'ASC' ? 'DESC' : 'ASC'), 'coa_open'=>null ) ),
    228238      'COMMENTS_ORDER_TITLE' => $comments_order == 'ASC' ? l10n('Show latest comments first') : l10n('Show oldest comments first'),
    229239      ));
    230      
     240
    231241    // get comments
    232242    $query = '
     
    235245    com.author,
    236246    com.author_id,
    237     u.'.$conf['user_fields']['username'].' AS username,
    238247    u.'.$conf['user_fields']['email'].' AS user_email,
     248    com.date,
     249    com.category_id,
     250    com.website_url,
    239251    com.email,
    240     com.date,
    241     com.website_url,
    242     com.category_id,
    243252    com.content,
    244253    com.validated
     
    253262    $result = pwg_query($query);
    254263
    255     while ($row = pwg_db_fetch_assoc($result)) 
     264    while ($row = pwg_db_fetch_assoc($result))
    256265    {
    257266      if ($row['author'] == 'guest')
     
    259268        $row['author'] = l10n('guest');
    260269      }
    261      
     270
    262271      $email = null;
    263272      if (!empty($row['user_email']))
     
    269278        $email = $row['email'];
    270279      }
    271      
     280
    272281      // comment content
    273282      $tpl_comment = array(
     
    275284        'AUTHOR' => trigger_event('render_comment_author', $row['author']),
    276285        'DATE' => format_date($row['date'], true),
     286        'CONTENT' => trigger_event('render_comment_content', $row['content'], 'album'),
    277287        'WEBSITE_URL' => $row['website_url'],
    278         'CONTENT' => trigger_event('render_comment_content', $row['content'], 'album'),
    279288        );
    280      
     289
    281290      // rights
    282       if (can_manage_comment('delete', $row['author_id'])) 
     291      if (can_manage_comment('delete', $row['author_id']))
    283292      {
    284293        $tpl_comment['U_DELETE'] = add_url_params(
    285           $url_self, 
     294          $url_self,
    286295          array(
    287296            'action' => 'delete_comment',
     
    291300          );
    292301      }
    293       if (can_manage_comment('edit', $row['author_id'])) 
     302      if (can_manage_comment('edit', $row['author_id']))
    294303      {
    295304        $tpl_comment['U_EDIT'] = add_url_params(
    296           $url_self, 
     305          $url_self,
    297306          array(
    298307            'action' => 'edit_comment',
     
    300309            )
    301310          );
    302         if (isset($edit_comment) and ($row['id'] == $edit_comment)) 
     311        if (isset($edit_comment) and ($row['id'] == $edit_comment))
    303312        {
    304313          $tpl_comment['IN_EDIT'] = true;
     
    307316          $tpl_comment['CONTENT'] = $row['content'];
    308317          $tpl_comment['PWG_TOKEN'] = get_pwg_token();
     318          $tpl_comment['U_CANCEL'] = $url_self;
    309319        }
    310320      }
     
    312322      {
    313323        $tpl_comment['EMAIL'] = $email;
    314        
    315         if ($row['validated'] != 'true') 
     324
     325        if ($row['validated'] != 'true')
    316326        {
    317327          $tpl_comment['U_VALIDATE'] = add_url_params(
    318             $url_self, 
     328            $url_self,
    319329            array(
    320330              'action' => 'validate_comment',
     
    325335        }
    326336      }
    327      
     337
    328338      $template->append('comments', $tpl_comment);
    329339    }
     
    332342  // comment form
    333343  $show_add_comment_form = true;
    334   if (isset($edit_comment)) 
     344  if (isset($edit_comment))
    335345  {
    336346    $show_add_comment_form = false;
    337347  }
    338   if (is_a_guest() and !$conf['comments_forall']) 
     348  if (is_a_guest() and !$conf['comments_forall'])
    339349  {
    340350    $show_add_comment_form = false;
    341351  }
    342352
    343   if ($show_add_comment_form) 
     353  if ($show_add_comment_form)
    344354  {
    345355    $key = get_ephemeral_key(3, $category['id']);
    346    
    347     $template->assign('comment_add',
    348       array(
     356
     357    $tpl_var = array(
    349358        'F_ACTION' =>         $url_self,
    350359        'KEY' =>              $key,
    351         'CONTENT' =>          stripslashes(@$_POST['content']),
     360        'CONTENT' =>          '',
    352361        'SHOW_AUTHOR' =>      !is_classic_user(),
    353362        'AUTHOR_MANDATORY' => $conf['comments_author_mandatory'],
    354         'AUTHOR' =>           stripslashes(@$_POST['author']),
    355         'WEBSITE_URL' =>      stripslashes(@$_POST['website_url']),
     363        'AUTHOR' =>           '',
     364        'WEBSITE_URL' =>      '',
    356365        'SHOW_EMAIL' =>       !is_classic_user() or empty($user['email']),
    357366        'EMAIL_MANDATORY' =>  $conf['comments_email_mandatory'],
    358         'EMAIL' =>            stripslashes(@$_POST['email']),
    359         )
    360       );
    361   }
    362  
     367        'EMAIL' =>            '',
     368        );
     369
     370    if ('reject'==@$comment_action)
     371    {
     372      foreach (array('content', 'author', 'website_url', 'email') as $k)
     373      {
     374        $tpl_var[strtoupper($k)] = htmlspecialchars( stripslashes(@$_POST[$k]) );
     375      }
     376    }
     377    $template->assign('comment_add', $tpl_var);
     378  }
     379
    363380  // template
    364381  $template->assign(array(
    365     'COA_PATH' => COA_PATH, // for css
    366     'COA_ABSOLUTE_PATH' => dirname(__FILE__) .'/../', // for template
     382    'COA_PATH' => COA_PATH,
     383    'COA_ABSOLUTE_PATH' => realpath(COA_PATH) . '/',
    367384    ));
    368  
    369   $template->set_filename('comments_on_albums', dirname(__FILE__) .'/../template/albums.tpl');
    370   if (isset($pwg_loaded_plugins['rv_tscroller']) AND count($page['navigation_bar']) != 0)
     385
     386  $template->set_filename('comments_on_albums', realpath(COA_PATH . 'template/albums.tpl'));
     387
     388  if (isset($pwg_loaded_plugins['rv_tscroller']) and count($page['navigation_bar']) != 0)
    371389  {
    372390    $template->assign('COMMENTS_ON_TOP', true);
     
    378396  }
    379397}
    380 
    381 ?>
Note: See TracChangeset for help on using the changeset viewer.