Changeset 10097


Ignore:
Timestamp:
Apr 6, 2011, 10:55:40 AM (10 years ago)
Author:
mistic100
Message:

bug:2152 Comments revalidation when modified

Location:
trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/configuration.php

    r9544 r10097  
    6464    'comments_forall',
    6565    'comments_validation',
     66    'comments_update_validation',
    6667    'email_admin_on_comment',
    6768    'email_admin_on_comment_validation',
  • trunk/admin/themes/default/template/configuration.tpl

    r8723 r10097  
    142142        <span class="property">{'Validation'|@translate}</span>
    143143        <input type="checkbox" name="comments_validation" {if ($comments.comments_validation)}checked="checked"{/if}>
     144      </label>
     145    </li>
     146   
     147    <li>
     148      <label>
     149        <span class="property">{'Update Validation'|@translate}</span>
     150        <input type="checkbox" name="comments_update_validation" {if ($comments.comments_update_validation)}checked="checked"{/if}>
    144151      </label>
    145152    </li>
  • trunk/include/functions_comment.inc.php

    r8728 r10097  
    264264        $GLOBALS['user']['id'].'\'';
    265265    }
     266   
     267    // should the updated comment must be validated
     268    if (!$conf['comments_update_validation'] or is_admin())
     269    {
     270      $comment_action='validate'; //one of validate, moderate, reject
     271    }
     272    else
     273    {
     274      $comment_action='moderate'; //one of validate, moderate, reject
     275    }
     276
    266277    $query = '
    267278UPDATE '.COMMENTS_TABLE.'
    268279  SET content = \''.$comment['content'].'\',
    269       validation_date = now()
     280      validated = \''.($comment_action=='validate' ? 'true':'false').'\',
     281      validation_date = '.($comment_action=='validate' ? 'NOW()':'NULL').'
    270282  WHERE id = '.$comment['comment_id'].
    271283$user_where_clause.'
    272284;';
    273285    $result = pwg_query($query);
    274     if ($result) {
     286   
     287    // mail admin and ask to validate the comment
     288    if ($result and $conf['email_admin_on_comment_validation'] and 'moderate' == $comment_action)
     289    {
     290      include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
     291
     292      $comment_url = get_absolute_root_url().'comments.php?comment_id='.$comment['comment_id'];
     293
     294      $keyargs_content = array
     295      (
     296        get_l10n_args('Author: %s', stripslashes($GLOBALS['user']['username']) ),
     297        get_l10n_args('Comment: %s', stripslashes($comment['content']) ),
     298        get_l10n_args('', ''),
     299        get_l10n_args('Manage this user comment: %s', $comment_url),
     300        get_l10n_args('', ''),
     301        get_l10n_args('(!) This comment requires validation', ''),
     302      );
     303
     304      pwg_mail_notification_admins
     305      (
     306        get_l10n_args('Comment by %s', stripslashes($GLOBALS['user']['username']) ),
     307        $keyargs_content
     308      );
     309    }
     310    // just mail admin
     311    else if ($result)
     312    {
    275313      email_admin('edit', array('author' => $GLOBALS['user']['username'],
    276314                                'content' => stripslashes($comment['content'])) );
    277315    }
    278316  }
     317 
     318  return $comment_action;
    279319}
    280320
  • trunk/include/picture_comment.inc.php

    r8728 r10097  
    3939}
    4040
    41 if ( $page['show_comments'] and isset( $_POST['content'] ) )
     41if (!isset($comment_action))
    4242{
    43   if ( is_a_guest() and !$conf['comments_forall'] )
    44   {
    45     die ('Session expired');
    46   }
    47 
    48   $comm = array(
    49     'author' => trim( @$_POST['author'] ),
    50     'content' => trim( $_POST['content'] ),
    51     'image_id' => $page['image_id'],
    52    );
    53 
    54   include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
    55 
    56   $comment_action = insert_user_comment($comm, @$_POST['key'], $infos );
    57 
    58   switch ($comment_action)
    59   {
    60     case 'moderate':
    61       array_push( $infos, l10n('An administrator must authorize your comment before it is visible.') );
    62     case 'validate':
    63       array_push( $infos, l10n('Your comment has been registered'));
    64       break;
    65     case 'reject':
    66       set_status_header(403);
    67       array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules') );
    68       break;
    69     default:
    70       trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
    71   }
    72 
    73   $template->assign(
    74       ($comment_action=='reject') ? 'errors' : 'infos',
    75       $infos
    76     );
    77 
    78   // allow plugins to notify what's going on
    79   trigger_action( 'user_comment_insertion',
    80       array_merge($comm, array('action'=>$comment_action) )
    81     );
    82 }
    83 elseif ( isset($_POST['content']) )
    84 {
    85   set_status_header(403);
    86   die('ugly spammer');
     43  if ( $page['show_comments'] and isset( $_POST['content'] ) )
     44  {
     45    if ( is_a_guest() and !$conf['comments_forall'] )
     46    {
     47      die ('Session expired');
     48    }
     49
     50    $comm = array(
     51      'author' => trim( @$_POST['author'] ),
     52      'content' => trim( $_POST['content'] ),
     53      'image_id' => $page['image_id'],
     54     );
     55
     56    include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
     57
     58    $comment_action = insert_user_comment($comm, @$_POST['key'], $infos );
     59
     60    switch ($comment_action)
     61    {
     62      case 'moderate':
     63        array_push( $infos, l10n('An administrator must authorize your comment before it is visible.') );
     64      case 'validate':
     65        array_push( $infos, l10n('Your comment has been registered'));
     66        break;
     67      case 'reject':
     68        set_status_header(403);
     69        array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules') );
     70        break;
     71      default:
     72        trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
     73    }
     74
     75    $template->assign(
     76        ($comment_action=='reject') ? 'errors' : 'infos',
     77        $infos
     78      );
     79
     80    // allow plugins to notify what's going on
     81    trigger_action( 'user_comment_insertion',
     82        array_merge($comm, array('action'=>$comment_action) )
     83      );
     84  }
     85  elseif ( isset($_POST['content']) )
     86  {
     87    set_status_header(403);
     88    die('ugly spammer');
     89  }
    8790}
    8891
  • trunk/install/config.sql

    r8759 r10097  
    44INSERT INTO piwigo_config (param,value,comment) VALUES ('log','true','keep an history of visits on your website');
    55INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_validation','false','administrators validate users comments before becoming visible');
     6INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_update_validation','false','administrators validate users updated comments before becoming visible');
    67INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_forall','false','even guest not registered can post comments');
    78INSERT INTO piwigo_config (param,value,comment) VALUES ('user_can_delete_comment','false','administrators can allow user delete their own comments');
  • trunk/language/en_UK/admin.lang.php

    r9936 r10097  
    730730$lang['Validate'] = "Validate";
    731731$lang['Validation'] = "Validation";
     732$lang['Update Validation'] = "Validation when a comment is modified";
    732733$lang['Version of create_listing_file.php on the remote site and Piwigo must be the same'] = "Versions of create_listing_file.php on the remote site and Piwigo must be the same";
    733734$lang['Version'] = "Version";
  • trunk/language/fr_FR/admin.lang.php

    r10039 r10097  
    170170$lang['Validate'] = "Valider";
    171171$lang['Validation'] = "Validation";
     172$lang['Update Validation'] = "Validation quand un commentaire est modifié";
    172173$lang['Version'] = "Version";
    173174$lang['Virtual albums to move'] = 'Albums virtuels à déplacer';
  • trunk/picture.php

    r9073 r10097  
    190190// +-----------------------------------------------------------------------+
    191191
     192$infos = array();
     193
    192194// caching first_rank, last_rank, current_rank in the displayed
    193195// section. This should also help in readability.
     
    332334        if (!empty($_POST['content']))
    333335        {
    334           update_user_comment(
     336          $comment_action = update_user_comment(
    335337            array(
    336338              'comment_id' => $_GET['comment_to_edit'],
     
    341343            );
    342344
    343           redirect($url_self);
     345          switch ($comment_action)
     346          {
     347            case 'moderate':
     348              array_push($infos, l10n('An administrator must authorize your comment before it is visible.'));
     349            case 'validate':
     350              array_push($infos, l10n('Your comment has been registered'));
     351              break;
     352            case 'reject':
     353              set_status_header(403);
     354              array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules'));
     355              break;
     356            default:
     357              trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
     358          }
     359         
     360          $template->assign(
     361              ($comment_action=='reject') ? 'errors' : 'infos',
     362              $infos
     363            );
     364           
     365          break;
    344366        }
    345367        else
     
    835857}
    836858
    837 $infos = array();
    838 
    839859// author
    840860if (!empty($picture['current']['author']))
Note: See TracChangeset for help on using the changeset viewer.