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

git-svn-id: http://piwigo.org/svn/trunk@18164 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
mistic100 2012-09-23 09:34:30 +00:00
parent b6d2db8600
commit 7e33b84e77
14 changed files with 182 additions and 46 deletions

View file

@ -73,7 +73,9 @@ $comments_checkboxes = array(
'user_can_delete_comment', 'user_can_delete_comment',
'user_can_edit_comment', 'user_can_edit_comment',
'email_admin_on_comment_edition', 'email_admin_on_comment_edition',
'email_admin_on_comment_deletion' 'email_admin_on_comment_deletion',
'comments_author_mandatory',
'comments_email_mandatory',
); );
$display_checkboxes = array( $display_checkboxes = array(

View file

@ -227,6 +227,20 @@ jQuery(document).ready(function () {
{'Validation'|@translate} {'Validation'|@translate}
</label> </label>
</li> </li>
<li>
<label>
<input type="checkbox" name="comments_author_mandatory" {if ($comments.comments_author_mandatory)}checked="checked"{/if}>
{'Username is mandatory'|@translate}
</label>
</li>
<li>
<label>
<input type="checkbox" name="comments_email_mandatory" {if ($comments.comments_email_mandatory)}checked="checked"{/if}>
{'Email address is mandatory'|@translate}
</label>
</li>
<li> <li>
<label> <label>

View file

@ -383,6 +383,8 @@ SELECT com.id AS comment_id,
com.image_id, com.image_id,
com.author, com.author,
com.author_id, com.author_id,
u.'.$conf['user_fields']['email'].' AS user_email,
com.email,
com.date, com.date,
com.website_url, com.website_url,
com.content, com.content,
@ -473,6 +475,16 @@ SELECT c.id, name, permalink, uppercats, com.id as comment_id
'image_file' => $elements[$comment['image_id']]['file'], 'image_file' => $elements[$comment['image_id']]['file'],
) )
); );
$email = null;
if (!empty($comment['user_email']))
{
$email = $comment['user_email'];
}
else if (!empty($comment['email']))
{
$email = $comment['email'];
}
$tpl_comment = array( $tpl_comment = array(
'ID' => $comment['comment_id'], 'ID' => $comment['comment_id'],
@ -484,6 +496,11 @@ SELECT c.id, name, permalink, uppercats, com.id as comment_id
'DATE'=>format_date($comment['date'], true), 'DATE'=>format_date($comment['date'], true),
'CONTENT'=>trigger_event('render_comment_content',$comment['content']), 'CONTENT'=>trigger_event('render_comment_content',$comment['content']),
); );
if (is_admin())
{
$tpl_comment['EMAIL'] = $email;
}
if (can_manage_comment('delete', $comment['author_id'])) if (can_manage_comment('delete', $comment['author_id']))
{ {

View file

@ -1725,4 +1725,23 @@ function url_check_format($url)
return (bool)preg_match('@^https?://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?$@iS', $url); return (bool)preg_match('@^https?://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?$@iS', $url);
} }
} }
/**
* check email format
*/
function email_check_format($mail_address)
{
if (version_compare(PHP_VERSION, '5.2.0') >= 0)
{
return filter_var($mail_address, FILTER_VALIDATE_EMAIL)!==false;
}
else
{
$atom = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]'; // before arobase
$domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name
$regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i';
return (bool)preg_match($regex, $mail_address);
}
}
?> ?>

View file

@ -91,6 +91,11 @@ function insert_user_comment( &$comm, $key, &$infos )
{ {
if ( empty($comm['author']) ) if ( empty($comm['author']) )
{ {
if ($conf['comments_author_mandatory'])
{
array_push($infos, l10n('Username is mandatory') );
$comment_action='reject';
}
$comm['author'] = 'guest'; $comm['author'] = 'guest';
} }
$comm['author_id'] = $conf['guest_id']; $comm['author_id'] = $conf['guest_id'];
@ -128,13 +133,35 @@ SELECT COUNT(*) AS user_exists
} }
// website // website
if ( !empty($comm['website_url']) and !preg_match('/^https?/i', $comm['website_url']) ) if (!empty($comm['website_url']))
{ {
$comm['website_url'] = 'http://'.$comm['website_url']; if (!preg_match('/^https?/i', $comm['website_url']))
{
$comm['website_url'] = 'http://'.$comm['website_url'];
}
if (!url_check_format($comm['website_url']))
{
array_push($infos, l10n('Your website URL is invalid'));
$comment_action='reject';
}
} }
if ( !empty($comm['website_url']) and !url_check_format($comm['website_url']) )
// email
if (empty($comm['email']))
{ {
array_push($infos, l10n('Your website URL is invalid')); if (!empty($user['email']))
{
$comm['email'] = $user['email'];
}
else if ($conf['comments_email_mandatory'])
{
array_push($infos, l10n('Email address is missing. Please specify an email address.') );
$comment_action='reject';
}
}
else if (!email_check_format($comm['email']))
{
array_push($infos, l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'));
$comment_action='reject'; $comment_action='reject';
} }
@ -179,7 +206,7 @@ SELECT count(1) FROM '.COMMENTS_TABLE.'
{ {
$query = ' $query = '
INSERT INTO '.COMMENTS_TABLE.' INSERT INTO '.COMMENTS_TABLE.'
(author, author_id, anonymous_id, content, date, validated, validation_date, image_id, website_url) (author, author_id, anonymous_id, content, date, validated, validation_date, image_id, website_url, email)
VALUES ( VALUES (
\''.$comm['author'].'\', \''.$comm['author'].'\',
'.$comm['author_id'].', '.$comm['author_id'].',
@ -189,7 +216,8 @@ INSERT INTO '.COMMENTS_TABLE.'
\''.($comment_action=='validate' ? 'true':'false').'\', \''.($comment_action=='validate' ? 'true':'false').'\',
'.($comment_action=='validate' ? 'NOW()':'NULL').', '.($comment_action=='validate' ? 'NOW()':'NULL').',
'.$comm['image_id'].', '.$comm['image_id'].',
'.(!empty($comm['website_url']) ? '\''.$comm['website_url'].'\'' : 'NULL').' '.(!empty($comm['website_url']) ? '\''.$comm['website_url'].'\'' : 'NULL').',
'.(!empty($comm['email']) ? '\''.$comm['email'].'\'' : 'NULL').'
) )
'; ';
@ -207,6 +235,7 @@ INSERT INTO '.COMMENTS_TABLE.'
$keyargs_content = array $keyargs_content = array
( (
get_l10n_args('Author: %s', stripslashes($comm['author']) ), get_l10n_args('Author: %s', stripslashes($comm['author']) ),
get_l10n_args('Email: %s', stripslashes($comm['email']) ),
get_l10n_args('Comment: %s', stripslashes($comm['content']) ), get_l10n_args('Comment: %s', stripslashes($comm['content']) ),
get_l10n_args('', ''), get_l10n_args('', ''),
get_l10n_args('Manage this user comment: %s', $comment_url) get_l10n_args('Manage this user comment: %s', $comment_url)

View file

@ -41,11 +41,7 @@ function validate_mail_address($user_id, $mail_address)
return ''; return '';
} }
$atom = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]'; // before arobase if ( !email_check_format($mail_address) )
$domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name
$regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i';
if ( !preg_match( $regex, $mail_address ) )
{ {
return l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'); return l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)');
} }
@ -53,10 +49,10 @@ function validate_mail_address($user_id, $mail_address)
if (defined("PHPWG_INSTALLED") and !empty($mail_address)) if (defined("PHPWG_INSTALLED") and !empty($mail_address))
{ {
$query = ' $query = '
select count(*) SELECT count(*)
from '.USERS_TABLE.' FROM '.USERS_TABLE.'
where upper('.$conf['user_fields']['email'].') = upper(\''.$mail_address.'\') WHERE upper('.$conf['user_fields']['email'].') = upper(\''.$mail_address.'\')
'.(is_numeric($user_id) ? 'and '.$conf['user_fields']['id'].' != \''.$user_id.'\'' : '').' '.(is_numeric($user_id) ? 'AND '.$conf['user_fields']['id'].' != \''.$user_id.'\'' : '').'
;'; ;';
list($count) = pwg_db_fetch_row(pwg_query($query)); list($count) = pwg_db_fetch_row(pwg_query($query));
if ($count != 0) if ($count != 0)

View file

@ -49,12 +49,13 @@ if ( $page['show_comments'] and isset( $_POST['content'] ) )
'author' => trim( @$_POST['author'] ), 'author' => trim( @$_POST['author'] ),
'content' => trim( $_POST['content'] ), 'content' => trim( $_POST['content'] ),
'website_url' => trim( $_POST['website_url'] ), 'website_url' => trim( $_POST['website_url'] ),
'email' => trim( @$_POST['email'] ),
'image_id' => $page['image_id'], 'image_id' => $page['image_id'],
); );
include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php'); include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
$comment_action = insert_user_comment($comm, @$_POST['key'], $page['infos']); $comment_action = insert_user_comment($comm, @$_POST['key'], $page['errors']);
switch ($comment_action) switch ($comment_action)
{ {
@ -143,10 +144,11 @@ SELECT
com.id, com.id,
author, author,
author_id, author_id,
'.$conf['user_fields']['username'].' AS username, u.'.$conf['user_fields']['email'].' AS user_email,
date, date,
image_id, image_id,
website_url, website_url,
com.email,
content, content,
validated validated
FROM '.COMMENTS_TABLE.' AS com FROM '.COMMENTS_TABLE.' AS com
@ -161,23 +163,25 @@ SELECT
while ($row = pwg_db_fetch_assoc($result)) while ($row = pwg_db_fetch_assoc($result))
{ {
if (!empty($row['author'])) if ($row['author'] == 'guest')
{ {
$author = $row['author']; $row['author'] = l10n('guest');
if ($author == 'guest')
{
$author = l10n('guest');
}
} }
else
$email = null;
if (!empty($row['user_email']))
{ {
$author = stripslashes($row['username']); $email = $row['user_email'];
}
else if (!empty($row['email']))
{
$email = $row['email'];
} }
$tpl_comment = $tpl_comment =
array( array(
'ID' => $row['id'], 'ID' => $row['id'],
'AUTHOR' => trigger_event('render_comment_author', $author), 'AUTHOR' => trigger_event('render_comment_author', $row['author']),
'DATE' => format_date($row['date'], true), 'DATE' => format_date($row['date'], true),
'CONTENT' => trigger_event('render_comment_content',$row['content']), 'CONTENT' => trigger_event('render_comment_content',$row['content']),
'WEBSITE_URL' => $row['website_url'], 'WEBSITE_URL' => $row['website_url'],
@ -215,6 +219,8 @@ SELECT
} }
if (is_admin()) if (is_admin())
{ {
$tpl_comment['EMAIL'] = $email;
if ($row['validated'] != 'true') if ($row['validated'] != 'true')
{ {
$tpl_comment['U_VALIDATE'] = add_url_params( $tpl_comment['U_VALIDATE'] = add_url_params(
@ -244,21 +250,19 @@ SELECT
if ($show_add_comment_form) if ($show_add_comment_form)
{ {
$key = get_ephemeral_key(3, $page['image_id']); $key = get_ephemeral_key(3, $page['image_id']);
$content = $author = $website_url = '';
if ('reject'===@$comment_action)
{
$content = htmlspecialchars( stripslashes($comm['content']) );
$author = htmlspecialchars( stripslashes($comm['author']) );
$website_url = htmlspecialchars( stripslashes($comm['website_url']) );
}
$template->assign('comment_add', $template->assign('comment_add',
array( array(
'F_ACTION' => $url_self, 'F_ACTION' => $url_self,
'KEY' => $key, 'KEY' => $key,
'CONTENT' => $content, 'CONTENT' => stripslashes(@$_POST['content']),
'SHOW_AUTHOR' => !is_classic_user(), 'SHOW_AUTHOR' => !is_classic_user(),
'AUTHOR' => $author , 'AUTHOR_MANDATORY' => $conf['comments_author_mandatory'],
'WEBSITE_URL' => $website_url, 'AUTHOR' => stripslashes(@$_POST['author']),
'WEBSITE_URL' => stripslashes(@$_POST['website_url']),
'SHOW_EMAIL' => !is_classic_user() or empty($user['email']),
'EMAIL_MANDATORY' => $conf['comments_email_mandatory'],
'EMAIL' => stripslashes(@$_POST['email']),
)); ));
} }
} }

View file

@ -6,6 +6,8 @@ INSERT INTO piwigo_config (param,value,comment) VALUES ('log','true','keep an hi
INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_validation','false','administrators validate users comments before becoming visible'); INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_validation','false','administrators validate users comments before becoming visible');
INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_forall','false','even guest not registered can post comments'); INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_forall','false','even guest not registered can post comments');
INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_order','ASC','comments order on picture page and cie'); INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_order','ASC','comments order on picture page and cie');
INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_author_mandatory','false');
INSERT INTO piwigo_config (param,value,comment) VALUES ('comments_email_mandatory','false');
INSERT INTO piwigo_config (param,value,comment) VALUES ('user_can_delete_comment','false','administrators can allow user delete their own comments'); INSERT INTO piwigo_config (param,value,comment) VALUES ('user_can_delete_comment','false','administrators can allow user delete their own comments');
INSERT INTO piwigo_config (param,value,comment) VALUES ('user_can_edit_comment','false','administrators can allow user edit their own comments'); INSERT INTO piwigo_config (param,value,comment) VALUES ('user_can_edit_comment','false','administrators can allow user edit their own comments');
INSERT INTO piwigo_config (param,value,comment) VALUES ('email_admin_on_comment_edition','false','Send an email to the administrators when a comment is modified'); INSERT INTO piwigo_config (param,value,comment) VALUES ('email_admin_on_comment_edition','false','Send an email to the administrators when a comment is modified');

View file

@ -0,0 +1,41 @@
<?php
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH'))
{
die('Hacking attempt!');
}
$upgrade_description = 'add "email" field in comments table';
include_once(PHPWG_ROOT_PATH.'include/constants.php');
$query = 'ALTER TABLE `'.COMMENTS_TABLE.'` ADD `email` varchar(255) default NULL;';
pwg_query($query);
conf_update_param('comments_author_mandatory', 'false');
conf_update_param('comments_email_mandatory', 'false');
echo "\n".$upgrade_description."\n";
?>

View file

@ -51,6 +51,7 @@ CREATE TABLE `piwigo_comments` (
`image_id` mediumint(8) unsigned NOT NULL default '0', `image_id` mediumint(8) unsigned NOT NULL default '0',
`date` datetime NOT NULL default '0000-00-00 00:00:00', `date` datetime NOT NULL default '0000-00-00 00:00:00',
`author` varchar(255) default NULL, `author` varchar(255) default NULL,
`email` varchar(255) default NULL,
`author_id` smallint(5) DEFAULT NULL, `author_id` smallint(5) DEFAULT NULL,
`anonymous_id` varchar(45) NOT NULL, `anonymous_id` varchar(45) NOT NULL,
`website_url` varchar(255) DEFAULT NULL, `website_url` varchar(255) DEFAULT NULL,

View file

@ -165,6 +165,7 @@ $lang['edit'] = "edit"; //TO remove
$lang['Edit'] = 'Edit'; $lang['Edit'] = 'Edit';
$lang['Email address is missing. Please specify an email address.'] = "Email address is missing. Please specify an email address."; $lang['Email address is missing. Please specify an email address.'] = "Email address is missing. Please specify an email address.";
$lang['Email address'] = "Email address"; $lang['Email address'] = "Email address";
$lang['Email address is mandatory'] = 'Email address is mandatory';
$lang['Email: %s'] = "Email: %s"; $lang['Email: %s'] = "Email: %s";
$lang['Empty query. No criteria has been entered.'] = 'Empty query. No criteria have been entered.'; $lang['Empty query. No criteria has been entered.'] = 'Empty query. No criteria have been entered.';
$lang['End-Date'] = "End date"; $lang['End-Date'] = "End date";
@ -384,6 +385,7 @@ $lang['Username "%s" on gallery %s'] = 'Username "%s" on gallery %s';
$lang['Username modification'] = 'Username modification'; $lang['Username modification'] = 'Username modification';
$lang['Username or email'] = 'Username or email'; $lang['Username or email'] = 'Username or email';
$lang['Username'] = "Username"; $lang['Username'] = "Username";
$lang['Username is mandatory'] = 'Username is mandatory';
$lang['Username: %s'] = 'Username: %s'; $lang['Username: %s'] = 'Username: %s';
$lang['View in'] = 'View in'; $lang['View in'] = 'View in';
$lang['View'] = "View"; $lang['View'] = "View";
@ -407,4 +409,5 @@ $lang['Your favorites'] = "Your favorites";
$lang['Your Gallery Customization'] = "Your gallery customization"; $lang['Your Gallery Customization'] = "Your gallery customization";
$lang['Your password has been reset'] = 'Your password has been reset'; $lang['Your password has been reset'] = 'Your password has been reset';
$lang['Your username has been successfully changed to : %s'] = 'Your username has been successfully changed to : %s'; $lang['Your username has been successfully changed to : %s'] = 'Your username has been successfully changed to : %s';
$lang['mandatory'] = 'mandatory';
?> ?>

View file

@ -407,4 +407,7 @@ $lang['Piwigo encountered a non recoverable error'] = 'Piwigo a rencontré une e
$lang['Requested album does not exist'] = 'L\'album demandé n\'existe pas'; $lang['Requested album does not exist'] = 'L\'album demandé n\'existe pas';
$lang['Permalink for album not found'] = 'Permalink pour l\'album non trouvé'; $lang['Permalink for album not found'] = 'Permalink pour l\'album non trouvé';
$lang['Requested tag does not exist'] = 'Le tag demandée n\'existe pas'; $lang['Requested tag does not exist'] = 'Le tag demandée n\'existe pas';
?> $lang['Username is mandatory'] = 'Nom d\'utilisateur obligatoire';
$lang['Email address is mandatory'] = 'Adresse email obligatoire';
$lang['mandatory'] = 'obligatoire';
?>

View file

@ -54,7 +54,8 @@
</div> </div>
{/if} {/if}
<span class="commentAuthor">{if $comment.WEBSITE_URL}<a href="{$comment.WEBSITE_URL}" class="external" target="_blank">{$comment.AUTHOR}</a>{else}{$comment.AUTHOR}{/if}</span> <span class="commentAuthor">{if $comment.WEBSITE_URL}<a href="{$comment.WEBSITE_URL}" class="external" target="_blank">{$comment.AUTHOR}</a>{else}{$comment.AUTHOR}{/if}</span>
{if $comment.EMAIL}- <a href="mailto:{$comment.EMAIL}">{$comment.EMAIL}</a>{/if}
- <span class="commentDate">{$comment.DATE}</span> - <span class="commentDate">{$comment.DATE}</span>
{if isset($comment.IN_EDIT)} {if isset($comment.IN_EDIT)}
<a name="edit_comment"></a> <a name="edit_comment"></a>

View file

@ -348,12 +348,16 @@ function togglePrivacyLevelBox()
<h4>{'Add a comment'|@translate}</h4> <h4>{'Add a comment'|@translate}</h4>
<form method="post" action="{$comment_add.F_ACTION}" id="addComment"> <form method="post" action="{$comment_add.F_ACTION}" id="addComment">
{if $comment_add.SHOW_AUTHOR} {if $comment_add.SHOW_AUTHOR}
<p><label for="author">{'Author'|@translate} :</label></p> <p><label for="author">{'Author'|@translate}{if $comment_add.AUTHOR_MANDATORY} ({'mandatory'|@translate}){/if} :</label></p>
<p><input type="text" name="author" id="author" value="{$comment_add.AUTHOR}"></p> <p><input type="text" name="author" id="author" value="{$comment_add.AUTHOR}"></p>
{/if} {/if}
<p><label for="website_url">{'Website'|@translate} :</label></p> {if $comment_add.SHOW_EMAIL}
<p><input type="text" name="website_url" id="website_url" value="{$comment_add.WEBSITE_URL}"></p> <p><label for="email">{'Email'|@translate}{if $comment_add.EMAIL_MANDATORY} ({'mandatory'|@translate}){/if} :</label></p>
<p><label for="contentid">{'Comment'|@translate} :</label></p> <p><input type="text" name="email" id="email" value="{$comment_add.EMAIL}"></p>
{/if}
<p><label for="website_url">{'Website'|@translate} :</label></p>
<p><input type="text" name="website_url" id="website_url" value="{$comment_add.WEBSITE_URL}"></p>
<p><label for="contentid">{'Comment'|@translate} ({'mandatory'|@translate}) :</label></p>
<p><textarea name="content" id="contentid" rows="5" cols="50">{$comment_add.CONTENT}</textarea></p> <p><textarea name="content" id="contentid" rows="5" cols="50">{$comment_add.CONTENT}</textarea></p>
<p><input type="hidden" name="key" value="{$comment_add.KEY}"> <p><input type="hidden" name="key" value="{$comment_add.KEY}">
<input type="submit" value="{'Submit'|@translate}"></p> <input type="submit" value="{'Submit'|@translate}"></p>