Changeset 18164


Ignore:
Timestamp:
09/23/12 11:34:30 (6 years ago)
Author:
mistic100
Message:

feature 2754: Add "Email" field for user comments + mandatory "Author"

Location:
trunk
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/configuration.php

    r17302 r18164  
    7474    'user_can_edit_comment', 
    7575    'email_admin_on_comment_edition', 
    76     'email_admin_on_comment_deletion' 
     76    'email_admin_on_comment_deletion', 
     77    'comments_author_mandatory', 
     78    'comments_email_mandatory', 
    7779  ); 
    7880 
  • trunk/admin/themes/default/template/configuration.tpl

    r17675 r18164  
    226226        <input type="checkbox" name="comments_validation" {if ($comments.comments_validation)}checked="checked"{/if}> 
    227227        {'Validation'|@translate} 
     228      </label> 
     229    </li> 
     230     
     231    <li> 
     232      <label> 
     233        <input type="checkbox" name="comments_author_mandatory" {if ($comments.comments_author_mandatory)}checked="checked"{/if}> 
     234        {'Username is mandatory'|@translate} 
     235      </label> 
     236    </li> 
     237     
     238    <li> 
     239      <label> 
     240        <input type="checkbox" name="comments_email_mandatory" {if ($comments.comments_email_mandatory)}checked="checked"{/if}> 
     241        {'Email address is mandatory'|@translate} 
    228242      </label> 
    229243    </li> 
  • trunk/comments.php

    r18063 r18164  
    384384       com.author, 
    385385       com.author_id, 
     386       u.'.$conf['user_fields']['email'].' AS user_email, 
     387       com.email, 
    386388       com.date, 
    387389       com.website_url, 
     
    474476        ) 
    475477      ); 
     478       
     479    $email = null; 
     480    if (!empty($comment['user_email'])) 
     481    { 
     482      $email = $comment['user_email']; 
     483    } 
     484    else if (!empty($comment['email'])) 
     485    { 
     486      $email = $comment['email']; 
     487    } 
    476488 
    477489    $tpl_comment = array( 
     
    485497      'CONTENT'=>trigger_event('render_comment_content',$comment['content']), 
    486498      ); 
     499       
     500    if (is_admin()) 
     501    { 
     502      $tpl_comment['EMAIL'] = $email; 
     503    } 
    487504 
    488505    if (can_manage_comment('delete', $comment['author_id'])) 
  • trunk/include/functions.inc.php

    r17748 r18164  
    17261726  } 
    17271727} 
     1728 
     1729/** 
     1730 * check email format 
     1731 */ 
     1732function email_check_format($mail_address) 
     1733{ 
     1734  if (version_compare(PHP_VERSION, '5.2.0') >= 0) 
     1735  { 
     1736    return filter_var($mail_address, FILTER_VALIDATE_EMAIL)!==false; 
     1737  } 
     1738  else 
     1739  { 
     1740    $atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // before  arobase 
     1741    $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name 
     1742    $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i'; 
     1743 
     1744    return (bool)preg_match($regex, $mail_address); 
     1745  } 
     1746} 
    17281747?> 
  • trunk/include/functions_comment.inc.php

    r17351 r18164  
    9292    if ( empty($comm['author']) ) 
    9393    { 
     94      if ($conf['comments_author_mandatory']) 
     95      { 
     96        array_push($infos, l10n('Username is mandatory') ); 
     97        $comment_action='reject'; 
     98      } 
    9499      $comm['author'] = 'guest'; 
    95100    } 
     
    129134   
    130135  // website 
    131   if ( !empty($comm['website_url']) and !preg_match('/^https?/i', $comm['website_url']) ) 
    132   { 
    133     $comm['website_url'] = 'http://'.$comm['website_url']; 
    134   } 
    135   if ( !empty($comm['website_url']) and !url_check_format($comm['website_url']) ) 
    136   { 
    137     array_push($infos, l10n('Your website URL is invalid')); 
     136  if (!empty($comm['website_url'])) 
     137  { 
     138    if (!preg_match('/^https?/i', $comm['website_url'])) 
     139    { 
     140      $comm['website_url'] = 'http://'.$comm['website_url']; 
     141    } 
     142    if (!url_check_format($comm['website_url'])) 
     143    { 
     144      array_push($infos, l10n('Your website URL is invalid')); 
     145      $comment_action='reject'; 
     146    } 
     147  } 
     148   
     149  // email 
     150  if (empty($comm['email'])) 
     151  { 
     152    if (!empty($user['email'])) 
     153    { 
     154      $comm['email'] = $user['email']; 
     155    } 
     156    else if ($conf['comments_email_mandatory']) 
     157    { 
     158      array_push($infos, l10n('Email address is missing. Please specify an email address.') ); 
     159      $comment_action='reject'; 
     160    } 
     161  } 
     162  else if (!email_check_format($comm['email'])) 
     163  { 
     164    array_push($infos, l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)')); 
    138165    $comment_action='reject'; 
    139166  } 
     
    180207    $query = ' 
    181208INSERT INTO '.COMMENTS_TABLE.' 
    182   (author, author_id, anonymous_id, content, date, validated, validation_date, image_id, website_url) 
     209  (author, author_id, anonymous_id, content, date, validated, validation_date, image_id, website_url, email) 
    183210  VALUES ( 
    184211    \''.$comm['author'].'\', 
     
    190217    '.($comment_action=='validate' ? 'NOW()':'NULL').', 
    191218    '.$comm['image_id'].', 
    192     '.(!empty($comm['website_url']) ? '\''.$comm['website_url'].'\'' : 'NULL').' 
     219    '.(!empty($comm['website_url']) ? '\''.$comm['website_url'].'\'' : 'NULL').', 
     220    '.(!empty($comm['email']) ? '\''.$comm['email'].'\'' : 'NULL').' 
    193221  ) 
    194222'; 
     
    208236      ( 
    209237        get_l10n_args('Author: %s', stripslashes($comm['author']) ), 
     238        get_l10n_args('Email: %s', stripslashes($comm['email']) ), 
    210239        get_l10n_args('Comment: %s', stripslashes($comm['content']) ), 
    211240        get_l10n_args('', ''), 
  • trunk/include/functions_user.inc.php

    r13240 r18164  
    4242  } 
    4343 
    44   $atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // before  arobase 
    45   $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name 
    46   $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i'; 
    47  
    48   if ( !preg_match( $regex, $mail_address ) ) 
     44  if ( !email_check_format($mail_address) ) 
    4945  { 
    5046    return l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'); 
     
    5450  { 
    5551    $query = ' 
    56 select count(*) 
    57 from '.USERS_TABLE.' 
    58 where upper('.$conf['user_fields']['email'].') = upper(\''.$mail_address.'\') 
    59 '.(is_numeric($user_id) ? 'and '.$conf['user_fields']['id'].' != \''.$user_id.'\'' : '').' 
     52SELECT count(*) 
     53FROM '.USERS_TABLE.' 
     54WHERE upper('.$conf['user_fields']['email'].') = upper(\''.$mail_address.'\') 
     55'.(is_numeric($user_id) ? 'AND '.$conf['user_fields']['id'].' != \''.$user_id.'\'' : '').' 
    6056;'; 
    6157    list($count) = pwg_db_fetch_row(pwg_query($query)); 
  • trunk/include/picture_comment.inc.php

    r17351 r18164  
    5050    'content' => trim( $_POST['content'] ), 
    5151    'website_url' => trim( $_POST['website_url'] ), 
     52    'email' => trim( @$_POST['email'] ), 
    5253    'image_id' => $page['image_id'], 
    5354   ); 
     
    5556  include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php'); 
    5657 
    57   $comment_action = insert_user_comment($comm, @$_POST['key'], $page['infos']); 
     58  $comment_action = insert_user_comment($comm, @$_POST['key'], $page['errors']); 
    5859 
    5960  switch ($comment_action) 
     
    144145    author, 
    145146    author_id, 
    146     '.$conf['user_fields']['username'].' AS username, 
     147    u.'.$conf['user_fields']['email'].' AS user_email, 
    147148    date, 
    148149    image_id, 
    149150    website_url, 
     151    com.email, 
    150152    content, 
    151153    validated 
     
    162164    while ($row = pwg_db_fetch_assoc($result)) 
    163165    { 
    164       if (!empty($row['author'])) 
    165       { 
    166         $author = $row['author']; 
    167         if ($author == 'guest') 
    168         { 
    169           $author = l10n('guest'); 
    170         } 
    171       } 
    172       else 
    173       { 
    174         $author = stripslashes($row['username']); 
     166      if ($row['author'] == 'guest') 
     167      { 
     168        $row['author'] = l10n('guest'); 
     169      } 
     170       
     171      $email = null; 
     172      if (!empty($row['user_email'])) 
     173      { 
     174        $email = $row['user_email']; 
     175      } 
     176      else if (!empty($row['email'])) 
     177      { 
     178        $email = $row['email']; 
    175179      } 
    176180 
     
    178182        array( 
    179183          'ID' => $row['id'], 
    180           'AUTHOR' => trigger_event('render_comment_author', $author), 
     184          'AUTHOR' => trigger_event('render_comment_author', $row['author']), 
    181185          'DATE' => format_date($row['date'], true), 
    182186          'CONTENT' => trigger_event('render_comment_content',$row['content']), 
     
    216220      if (is_admin()) 
    217221      { 
     222        $tpl_comment['EMAIL'] = $email; 
     223         
    218224        if ($row['validated'] != 'true') 
    219225        { 
     
    245251  { 
    246252    $key = get_ephemeral_key(3, $page['image_id']); 
    247     $content = $author = $website_url = ''; 
    248     if ('reject'===@$comment_action) 
    249     { 
    250       $content = htmlspecialchars( stripslashes($comm['content']) ); 
    251       $author = htmlspecialchars( stripslashes($comm['author']) ); 
    252       $website_url = htmlspecialchars( stripslashes($comm['website_url']) ); 
    253     } 
     253     
    254254    $template->assign('comment_add', 
    255255        array( 
    256           'F_ACTION' => $url_self, 
    257           'KEY' => $key, 
    258           'CONTENT' => $content, 
    259           'SHOW_AUTHOR' => !is_classic_user(), 
    260           'AUTHOR' => $author , 
    261           'WEBSITE_URL' => $website_url,  
     256          'F_ACTION' =>         $url_self, 
     257          'KEY' =>              $key, 
     258          'CONTENT' =>          stripslashes(@$_POST['content']), 
     259          'SHOW_AUTHOR' =>      !is_classic_user(), 
     260          'AUTHOR_MANDATORY' => $conf['comments_author_mandatory'], 
     261          'AUTHOR' =>           stripslashes(@$_POST['author']), 
     262          'WEBSITE_URL' =>      stripslashes(@$_POST['website_url']), 
     263          'SHOW_EMAIL' =>       !is_classic_user() or empty($user['email']), 
     264          'EMAIL_MANDATORY' =>  $conf['comments_email_mandatory'], 
     265          'EMAIL' =>            stripslashes(@$_POST['email']),  
    262266        )); 
    263267  } 
  • trunk/install/config.sql

    r15652 r18164  
    77INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_forall','false','even guest not registered can post comments'); 
    88INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_order','ASC','comments order on picture page and cie'); 
     9INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_author_mandatory','false'); 
     10INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_email_mandatory','false'); 
    911INSERT INTO piwigo_config (param,value,comment) VALUES ('user_can_delete_comment','false','administrators can allow user delete their own comments'); 
    1012INSERT INTO piwigo_config (param,value,comment) VALUES ('user_can_edit_comment','false','administrators can allow user edit their own comments'); 
  • trunk/install/piwigo_structure-mysql.sql

    r17351 r18164  
    5252  `date` datetime NOT NULL default '0000-00-00 00:00:00', 
    5353  `author` varchar(255) default NULL, 
     54  `email` varchar(255) default NULL, 
    5455  `author_id` smallint(5) DEFAULT NULL, 
    5556  `anonymous_id` varchar(45) NOT NULL, 
  • trunk/language/en_UK/common.lang.php

    r17509 r18164  
    166166$lang['Email address is missing. Please specify an email address.'] = "Email address is missing. Please specify an email address."; 
    167167$lang['Email address'] = "Email address"; 
     168$lang['Email address is mandatory'] = 'Email address is mandatory'; 
    168169$lang['Email: %s'] = "Email: %s"; 
    169170$lang['Empty query. No criteria has been entered.'] = 'Empty query. No criteria have been entered.'; 
     
    385386$lang['Username or email'] = 'Username or email'; 
    386387$lang['Username'] = "Username"; 
     388$lang['Username is mandatory'] = 'Username is mandatory'; 
    387389$lang['Username: %s'] = 'Username: %s'; 
    388390$lang['View in'] = 'View in'; 
     
    408410$lang['Your password has been reset'] = 'Your password has been reset'; 
    409411$lang['Your username has been successfully changed to : %s'] = 'Your username has been successfully changed to : %s'; 
     412$lang['mandatory'] = 'mandatory'; 
    410413?> 
  • trunk/language/fr_FR/common.lang.php

    r17509 r18164  
    408408$lang['Permalink for album not found'] = 'Permalink pour l\'album non trouvé'; 
    409409$lang['Requested tag does not exist'] = 'Le tag demandée n\'existe pas'; 
     410$lang['Username is mandatory'] = 'Nom d\'utilisateur obligatoire'; 
     411$lang['Email address is mandatory'] = 'Adresse email obligatoire'; 
     412$lang['mandatory'] = 'obligatoire'; 
    410413?> 
  • trunk/themes/default/template/comment_list.tpl

    r17351 r18164  
    5555                {/if} 
    5656 
    57                 <span class="commentAuthor">{if $comment.WEBSITE_URL}<a href="{$comment.WEBSITE_URL}" class="external" target="_blank">{$comment.AUTHOR}</a>{else}{$comment.AUTHOR}{/if}</span>  
     57                <span class="commentAuthor">{if $comment.WEBSITE_URL}<a href="{$comment.WEBSITE_URL}" class="external" target="_blank">{$comment.AUTHOR}</a>{else}{$comment.AUTHOR}{/if}</span> 
     58      {if $comment.EMAIL}- <a href="mailto:{$comment.EMAIL}">{$comment.EMAIL}</a>{/if} 
    5859      - <span class="commentDate">{$comment.DATE}</span> 
    5960                {if isset($comment.IN_EDIT)} 
  • trunk/themes/default/template/picture.tpl

    r17979 r18164  
    349349                        <form method="post" action="{$comment_add.F_ACTION}" id="addComment"> 
    350350                                {if $comment_add.SHOW_AUTHOR} 
    351                                         <p><label for="author">{'Author'|@translate} :</label></p> 
     351                                        <p><label for="author">{'Author'|@translate}{if $comment_add.AUTHOR_MANDATORY} ({'mandatory'|@translate}){/if} :</label></p> 
    352352                                        <p><input type="text" name="author" id="author" value="{$comment_add.AUTHOR}"></p> 
    353353                                {/if} 
    354         <p><label for="website_url">{'Website'|@translate} :</label></p> 
    355                           <p><input type="text" name="website_url" id="website_url" value="{$comment_add.WEBSITE_URL}"></p> 
    356                           <p><label for="contentid">{'Comment'|@translate} :</label></p> 
     354                                {if $comment_add.SHOW_EMAIL} 
     355                                        <p><label for="email">{'Email'|@translate}{if $comment_add.EMAIL_MANDATORY} ({'mandatory'|@translate}){/if} :</label></p> 
     356                                        <p><input type="text" name="email" id="email" value="{$comment_add.EMAIL}"></p> 
     357                                {/if} 
     358                                <p><label for="website_url">{'Website'|@translate} :</label></p> 
     359                                <p><input type="text" name="website_url" id="website_url" value="{$comment_add.WEBSITE_URL}"></p> 
     360                                <p><label for="contentid">{'Comment'|@translate} ({'mandatory'|@translate}) :</label></p> 
    357361                                <p><textarea name="content" id="contentid" rows="5" cols="50">{$comment_add.CONTENT}</textarea></p> 
    358362                                <p><input type="hidden" name="key" value="{$comment_add.KEY}"> 
Note: See TracChangeset for help on using the changeset viewer.