Ignore:
Timestamp:
Dec 21, 2013, 5:33:24 PM (10 years ago)
Author:
mistic100
Message:

update for Piwigo 2.6 + code clean

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/GuestBook/include/functions_comment.inc.php

    r25786 r26065  
    11<?php
    2 if (!defined('GUESTBOOK_PATH')) die('Hacking attempt!');
     2defined('GUESTBOOK_PATH') or die('Hacking attempt!');
    33
    44include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
    5 add_event_handler('user_comment_check_guestbook', 'user_comment_check',
    6   EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
     5
    76
    87function insert_user_comment_guestbook( &$comm, $key )
     
    109  global $conf, $user, $page;
    1110
    12   $comm = array_merge( $comm,
     11  $comm = array_merge($comm,
    1312    array(
    1413      'ip' => $_SERVER['REMOTE_ADDR'],
     
    1918  if (!$conf['guestbook']['comments_validation'] or is_admin())
    2019  {
    21     $comment_action='validate'; //one of validate, moderate, reject
    22   }
    23   else
    24   {
    25     $comment_action='moderate'; //one of validate, moderate, reject
    26   }
    27 
    28   // display author field if the user status is guest or generic
     20    $comment_action='validate';
     21  }
     22  else
     23  {
     24    $comment_action='moderate';
     25  }
     26
     27  // author
    2928  if (!is_classic_user())
    3029  {
    31     if ( empty($comm['author']) )
    32     {
    33       array_push($page['errors'], l10n('Please enter your username'));
     30    if (empty($comm['author']))
     31    {
     32      $page['errors'][] = l10n('Please enter your username');
    3433      $comment_action='reject';
    3534    }
     
    3736    {
    3837      $comm['author_id'] = $conf['guest_id'];
    39       // if a guest try to use the name of an already existing user, he must be
    40       // rejected
     38      // if a guest try to use the name of an already existing user,
     39      // he must be rejected
    4140      $query = '
    4241SELECT COUNT(*) AS user_exists
    4342  FROM '.USERS_TABLE.'
    44   WHERE '.$conf['user_fields']['username']." = '".addslashes($comm['author'])."'";
    45       $row = pwg_db_fetch_assoc( pwg_query( $query ) );
     43  WHERE '.$conf['user_fields']['username']." = '".addslashes($comm['author'])."'
     44;";
     45      $row = pwg_db_fetch_assoc(pwg_query($query));
    4646     
    47       if ( $row['user_exists'] == 1 )
     47      if ($row['user_exists'] == 1)
    4848      {
    49         array_push($page['errors'], l10n('This login is already used by another user') );
     49        $page['errors'][] = l10n('This login is already used by another user');
    5050        $comment_action='reject';
    5151      }
     
    5858  }
    5959
    60   if ( empty($comm['content']) )
    61   { // empty comment content
    62     $comment_action='reject';
    63   }
    64 
    65   if ( !verify_ephemeral_key(@$key) )
     60  // content
     61  if (empty($comm['content']))
     62  {
     63    $comment_action='reject';
     64  }
     65
     66  // key
     67  if (!verify_ephemeral_key(@$key))
    6668  {
    6769    $comment_action='reject';
     
    7072 
    7173  // email
    72   if ( empty($comm['email']) and is_classic_user() and !empty($user['email']) )
     74  if (empty($comm['email']) and is_classic_user() and !empty($user['email']))
    7375  {
    7476    $comm['email'] = $user['email'];
    7577  }
    76   else if ( empty($comm['email']) and $conf['comments_email_mandatory'] )
    77   {
    78     array_push($page['errors'], l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'));
    79     $comment_action='reject';
    80   }
    81   else if ( !empty($comm['email']) and !email_check_format($comm['email']) )
    82   {
    83     array_push($page['errors'], l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'));
     78  else if (empty($comm['email']) and $conf['comments_email_mandatory'])
     79  {
     80    $page['errors'][] = l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)');
     81    $comment_action='reject';
     82  }
     83  else if (!empty($comm['email']) and !email_check_format($comm['email']))
     84  {
     85    $page['errors'][] = l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)');
    8486    $comment_action='reject';
    8587  }
    8688 
    8789  // website
    88   if ( !empty($comm['website']) and !preg_match('/^(https?:\/\/)/i', $comm['website']) )
     90  if (!empty($comm['website']) and !preg_match('/^(https?:\/\/)/i', $comm['website']))
    8991  {
    9092    $comm['website'] = 'http://'.$comm['website'];
    9193  }
    92   if ( !empty($comm['website']) and !url_check_format($comm['website']) )
    93   {
    94     array_push($page['errors'], l10n('invalid website address'));
     94  if (!empty($comm['website']) and !url_check_format($comm['website']))
     95  {
     96    $page['errors'][] = l10n('invalid website address');
    9597    $comment_action='reject';
    9698  }
     
    125127    if ($counter > 0)
    126128    {
    127       array_push($page['errors'], l10n('Anti-flood system : please wait for a moment before trying to post another comment') );
     129      $page['errors'][] = l10n('Anti-flood system : please wait for a moment before trying to post another comment');
    128130      $comment_action='reject';
    129131    }
     
    131133 
    132134  // perform more spam check
    133   $comment_action = trigger_event('user_comment_check_guestbook',
    134       $comment_action, $comm
    135     );
    136 
    137   if ( $comment_action!='reject' )
     135  $comment_action = trigger_event('user_comment_check', $comment_action, $comm);
     136
     137  if ($comment_action!='reject')
    138138  {
    139139    $query = '
     
    175175      $comment_url = add_url_params(GUESTBOOK_URL, array('comment_id'=>$comm['id']));
    176176
    177       $keyargs_content = array
    178       (
     177      $keyargs_content = array(
    179178        get_l10n_args('Author: %s', stripslashes($comm['author']) ),
    180179        get_l10n_args('Comment: %s', stripslashes($comm['content']) ),
     
    189188      }
    190189
    191       pwg_mail_notification_admins
    192       (
     190      pwg_mail_notification_admins(
    193191        get_l10n_args('Comment by %s', stripslashes($comm['author']) ),
    194192        $keyargs_content
     
    196194    }
    197195  }
     196 
    198197  return $comment_action;
    199198}
     
    205204  $comment_action = 'validate';
    206205
    207   if ( !verify_ephemeral_key($post_key) )
    208   {
    209     $comment_action='reject';
    210   }
    211   elseif (!$conf['guestbook']['comments_validation'] or is_admin()) // should the updated comment must be validated
    212   {
    213     $comment_action='validate'; //one of validate, moderate, reject
    214   }
    215   else
    216   {
    217     $comment_action='moderate'; //one of validate, moderate, reject
    218   }
    219 
    220   if ( $comment_action!='reject' )
     206  if (!verify_ephemeral_key($post_key))
     207  {
     208    $comment_action='reject';
     209  }
     210  else if (!$conf['guestbook']['comments_validation'] or is_admin()) // should the updated comment must be validated
     211  {
     212    $comment_action='validate';
     213  }
     214  else
     215  {
     216    $comment_action='moderate';
     217  }
     218
     219  if ($comment_action!='reject')
    221220  {
    222221    $user_where_clause = '';
     
    244243      $comment_url = add_url_params(GUESTBOOK_URL, array('comment_id'=>$comm['id']));
    245244
    246       $keyargs_content = array
    247       (
     245      $keyargs_content = array(
    248246        get_l10n_args('Author: %s', stripslashes($GLOBALS['user']['username']) ),
    249247        get_l10n_args('Comment: %s', stripslashes($comment['content']) ),
     
    254252      );
    255253
    256       pwg_mail_notification_admins
    257       (
     254      pwg_mail_notification_admins(
    258255        get_l10n_args('Comment by %s', stripslashes($GLOBALS['user']['username']) ),
    259256        $keyargs_content
     
    274271;';
    275272  $result = pwg_query($query);
     273
    276274  if (pwg_db_num_rows($result) == 0)
    277275  {
     
    296294  if (!is_admin())
    297295  {
    298     $user_where_clause = '   AND author_id = \''.$GLOBALS['user']['id'].'\'';
     296    $user_where_clause = ' AND author_id = \''.$GLOBALS['user']['id'].'\'';
    299297  }
    300298 
    301299  if (is_array($comment_id))
     300  {
    302301    $where_clause = 'id IN('.implode(',', $comment_id).')';
    303   else
     302  }
     303  else
     304  {
    304305    $where_clause = 'id = '.$comment_id;
     306  }
    305307   
    306308  $query = '
     
    315317{
    316318  if (is_array($comment_id))
     319  {
    317320    $where_clause = 'id IN('.implode(',', $comment_id).')';
    318   else
     321  }
     322  else
     323  {
    319324    $where_clause = 'id = '.$comment_id;
     325  }
    320326   
    321327  $query = '
Note: See TracChangeset for help on using the changeset viewer.