Changeset 1598 for trunk/comments.php


Ignore:
Timestamp:
Nov 8, 2006, 5:28:30 AM (17 years ago)
Author:
rvelices
Message:
  • comments.php improvements:
    • unvalidated comments are shown only for administrators
    • added delete/validate icons for admins
    • removed some unused code
  • display of comment content performed through an event
  • replace some get_thumbnail_src with get_thumbnail_url
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/comments.php

    r1563 r1598  
    66// +-----------------------------------------------------------------------+
    77// | branch        : BSF (Best So Far)
    8 // | file          : $RCSfile$
     8// | file          : $Id$
    99// | last update   : $Date$
    1010// | last modifier : $Author$
     
    2929// |                           initialization                              |
    3030// +-----------------------------------------------------------------------+
    31 if (!defined('IN_ADMIN'))
    32 {
    33   define('PHPWG_ROOT_PATH','./');
    34   include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
    35 }
     31define('PHPWG_ROOT_PATH','./');
     32include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
    3633
    3734// +-----------------------------------------------------------------------+
     
    145142}
    146143
     144// which status to filter on ?
     145if ( is_admin() )
     146{
     147  $page['status_clause'] = '1=1';
     148}
     149else
     150{
     151  $page['status_clause'] = 'validated="true"';
     152}
     153
     154
    147155// +-----------------------------------------------------------------------+
    148156// |                         comments management                           |
    149157// +-----------------------------------------------------------------------+
    150 // comments deletion
    151 if (isset($_POST['delete']) and count($_POST['comment_id']) > 0 and is_admin())
    152 {
    153   $_POST['comment_id'] = array_map('intval', $_POST['comment_id']);
    154   $query = '
     158if (is_admin() and !is_adviser() )
     159{
     160  if (isset($_GET['delete']) and is_numeric($_GET['delete']) )
     161  {// comments deletion
     162    $query = '
    155163DELETE FROM '.COMMENTS_TABLE.'
    156   WHERE id IN ('.implode(',', $_POST['comment_id']).')
    157 ;';
    158   pwg_query($query);
    159 }
    160 // comments validation
    161 if (isset($_POST['validate']) and count($_POST['comment_id']) > 0
    162    and is_admin())
    163 {
    164   $_POST['comment_id'] = array_map('intval', $_POST['comment_id']);
    165   $query = '
     164  WHERE id='.$_GET['delete'].'
     165;';
     166    pwg_query($query);
     167  }
     168
     169  if (isset($_GET['validate']) and is_numeric($_GET['validate']) )
     170  {  // comments validation
     171    $query = '
    166172UPDATE '.COMMENTS_TABLE.'
    167173  SET validated = \'true\'
    168174    , validation_date = NOW()
    169   WHERE id IN ('.implode(',', $_POST['comment_id']).')
    170 ;';
    171   pwg_query($query);
     175  WHERE id='.$_GET['validate'].'
     176;';
     177    pwg_query($query);
     178  }
    172179}
    173180// +-----------------------------------------------------------------------+
     
    299306    AND '.$page['cat_clause'].'
    300307    AND '.$page['author_clause'].'
    301     AND '.$page['keyword_clause'];
     308    AND '.$page['keyword_clause'].'
     309    AND '.$page['status_clause'];
    302310if ($user['forbidden_categories'] != '')
    303311{
     
    309317list($counter) = mysql_fetch_row(pwg_query($query));
    310318
    311 $url = PHPWG_ROOT_PATH.'comments.php'.get_query_string_diff(array('start'));
     319$url = PHPWG_ROOT_PATH
     320    .'comments.php'
     321    .get_query_string_diff(array('start','delete','validate'));
    312322
    313323$navbar = create_navigation_bar($url,
     
    335345     , com.content
    336346     , com.id AS comment_id
     347     , com.validated
    337348  FROM '.IMAGE_CATEGORY_TABLE.' AS ic
    338349    INNER JOIN '.COMMENTS_TABLE.' AS com
     
    341352    AND '.$page['cat_clause'].'
    342353    AND '.$page['author_clause'].'
    343     AND '.$page['keyword_clause'];
     354    AND '.$page['keyword_clause'].'
     355    AND '.$page['status_clause'];
    344356if ($user['forbidden_categories'] != '')
    345357{
     
    358370;';
    359371$result = pwg_query($query);
    360 while ($row = mysql_fetch_array($result))
     372while ($row = mysql_fetch_assoc($result))
    361373{
    362374  array_push($comments, $row);
     
    375387;';
    376388  $result = pwg_query($query);
    377   while ($row = mysql_fetch_array($result))
     389  while ($row = mysql_fetch_assoc($result))
    378390  {
    379391    $elements[$row['id']] = $row;
     
    388400;';
    389401  $result = pwg_query($query);
    390   while ($row = mysql_fetch_array($result))
     402  while ($row = mysql_fetch_assoc($result))
    391403  {
    392404    $categories[$row['id']] = $row;
     
    395407  foreach ($comments as $comment)
    396408  {
    397     // name of the picture
    398     $name = get_cat_display_name_cache(
    399       $categories[$comment['category_id']]['uppercats'], null, false);
    400     $name.= $conf['level_separator'];
    401409    if (!empty($elements[$comment['image_id']]['name']))
    402410    {
    403       $name.= $elements[$comment['image_id']]['name'];
     411      $name=$elements[$comment['image_id']]['name'];
    404412    }
    405413    else
    406414    {
    407       $name.= get_name_from_file($elements[$comment['image_id']]['file']);
     415      $name=get_name_from_file($elements[$comment['image_id']]['file']);
    408416    }
    409417
    410418    // source of the thumbnail picture
    411     $thumbnail_src = get_thumbnail_src(
    412       $elements[$comment['image_id']]['path'],
    413       @$elements[$comment['image_id']]['tn_ext']
    414       );
     419    $thumbnail_src = get_thumbnail_url( $elements[$comment['image_id']] );
    415420
    416421    // link to the full size picture
     
    424429          );
    425430
    426     $template->assign_block_vars(
    427       'picture',
    428       array(
    429         'TITLE_IMG'=>$name,
    430         'I_THUMB'=>$thumbnail_src,
    431         'U_THUMB'=>$url
    432         ));
    433 
    434431    $author = $comment['author'];
    435432    if (empty($comment['author']))
     
    443440        'U_PICTURE' => $url,
    444441        'TN_SRC' => $thumbnail_src,
     442        'ALT' => $name,
    445443        'AUTHOR' => $author,
    446444        'DATE'=>format_date($comment['date'],'mysql_datetime',true),
    447         'CONTENT'=>parse_comment_content($comment['content']),
     445        'CONTENT'=>trigger_event('render_comment_content',$comment['content']),
    448446        ));
     447
     448    if ( is_admin() )
     449    {
     450      $url = get_root_url().'comments.php'.get_query_string_diff(array('delete','validate'));
     451      $template->assign_block_vars(
     452        'comment.action_delete',
     453        array(
     454          'U_DELETE' => add_url_params($url,
     455                          array('delete'=>$comment['comment_id'])
     456                         ),
     457          ));
     458      if ($comment['validated'] != 'true')
     459      {
     460        $template->assign_block_vars(
     461          'comment.action_validate',
     462          array(
     463            'U_VALIDATE' => add_url_params($url,
     464                            array('validate'=>$comment['comment_id'])
     465                           ),
     466            ));
     467      }
     468    }
    449469  }
    450470}
     
    452472// |                           html code display                           |
    453473// +-----------------------------------------------------------------------+
    454 if (defined('IN_ADMIN'))
    455 {
    456   $template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
    457 }
    458 else
    459 {
    460   $template->assign_block_vars('title',array());
    461   $template->parse('comments');
    462   include(PHPWG_ROOT_PATH.'include/page_tail.php');
    463 }
     474$template->assign_block_vars('title',array());
     475$template->parse('comments');
     476include(PHPWG_ROOT_PATH.'include/page_tail.php');
    464477?>
Note: See TracChangeset for help on using the changeset viewer.