diff options
Diffstat (limited to '')
-rw-r--r-- | admin/configuration.php | 4 | ||||
-rw-r--r-- | admin/themes/default/template/configuration.tpl | 14 | ||||
-rw-r--r-- | comments.php | 17 | ||||
-rw-r--r-- | include/functions.inc.php | 19 | ||||
-rw-r--r-- | include/functions_comment.inc.php | 41 | ||||
-rw-r--r-- | include/functions_user.inc.php | 14 | ||||
-rw-r--r-- | include/picture_comment.inc.php | 52 | ||||
-rw-r--r-- | install/config.sql | 2 | ||||
-rw-r--r-- | install/db/130-database.php | 41 | ||||
-rw-r--r-- | install/piwigo_structure-mysql.sql | 1 | ||||
-rw-r--r-- | language/en_UK/common.lang.php | 3 | ||||
-rw-r--r-- | language/fr_FR/common.lang.php | 5 | ||||
-rw-r--r-- | themes/default/template/comment_list.tpl | 3 | ||||
-rw-r--r-- | themes/default/template/picture.tpl | 12 |
14 files changed, 182 insertions, 46 deletions
diff --git a/admin/configuration.php b/admin/configuration.php index 6132c7806..c615d64f1 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -73,7 +73,9 @@ $comments_checkboxes = array( 'user_can_delete_comment', 'user_can_edit_comment', 'email_admin_on_comment_edition', - 'email_admin_on_comment_deletion' + 'email_admin_on_comment_deletion', + 'comments_author_mandatory', + 'comments_email_mandatory', ); $display_checkboxes = array( diff --git a/admin/themes/default/template/configuration.tpl b/admin/themes/default/template/configuration.tpl index 651df8eba..388e26d0d 100644 --- a/admin/themes/default/template/configuration.tpl +++ b/admin/themes/default/template/configuration.tpl @@ -227,6 +227,20 @@ jQuery(document).ready(function () { {'Validation'|@translate} </label> </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> <label> diff --git a/comments.php b/comments.php index f695cebaa..1cd19890d 100644 --- a/comments.php +++ b/comments.php @@ -383,6 +383,8 @@ SELECT com.id AS comment_id, com.image_id, com.author, com.author_id, + u.'.$conf['user_fields']['email'].' AS user_email, + com.email, com.date, com.website_url, com.content, @@ -473,6 +475,16 @@ SELECT c.id, name, permalink, uppercats, com.id as comment_id '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( '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), 'CONTENT'=>trigger_event('render_comment_content',$comment['content']), ); + + if (is_admin()) + { + $tpl_comment['EMAIL'] = $email; + } if (can_manage_comment('delete', $comment['author_id'])) { diff --git a/include/functions.inc.php b/include/functions.inc.php index f94aad480..0be5ec9ef 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -1725,4 +1725,23 @@ function url_check_format($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); + } +} ?>
\ No newline at end of file diff --git a/include/functions_comment.inc.php b/include/functions_comment.inc.php index e812a1c6f..67716216c 100644 --- a/include/functions_comment.inc.php +++ b/include/functions_comment.inc.php @@ -91,6 +91,11 @@ function insert_user_comment( &$comm, $key, &$infos ) { if ( empty($comm['author']) ) { + if ($conf['comments_author_mandatory']) + { + array_push($infos, l10n('Username is mandatory') ); + $comment_action='reject'; + } $comm['author'] = 'guest'; } $comm['author_id'] = $conf['guest_id']; @@ -128,13 +133,35 @@ SELECT COUNT(*) AS user_exists } // website - if ( !empty($comm['website_url']) and !preg_match('/^https?/i', $comm['website_url']) ) + if (!empty($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'; + } + } + + // email + if (empty($comm['email'])) { - $comm['website_url'] = 'http://'.$comm['website_url']; + 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'; + } } - if ( !empty($comm['website_url']) and !url_check_format($comm['website_url']) ) + else if (!email_check_format($comm['email'])) { - array_push($infos, l10n('Your website URL is invalid')); + array_push($infos, l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)')); $comment_action='reject'; } @@ -179,7 +206,7 @@ SELECT count(1) FROM '.COMMENTS_TABLE.' { $query = ' 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 ( \''.$comm['author'].'\', '.$comm['author_id'].', @@ -189,7 +216,8 @@ INSERT INTO '.COMMENTS_TABLE.' \''.($comment_action=='validate' ? 'true':'false').'\', '.($comment_action=='validate' ? 'NOW()':'NULL').', '.$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 ( 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('', ''), get_l10n_args('Manage this user comment: %s', $comment_url) diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php index f0006a55e..e6bbe57f8 100644 --- a/include/functions_user.inc.php +++ b/include/functions_user.inc.php @@ -41,11 +41,7 @@ function validate_mail_address($user_id, $mail_address) return ''; } - $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'; - - if ( !preg_match( $regex, $mail_address ) ) + if ( !email_check_format($mail_address) ) { 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)) { $query = ' -select count(*) -from '.USERS_TABLE.' -where upper('.$conf['user_fields']['email'].') = upper(\''.$mail_address.'\') -'.(is_numeric($user_id) ? 'and '.$conf['user_fields']['id'].' != \''.$user_id.'\'' : '').' +SELECT count(*) +FROM '.USERS_TABLE.' +WHERE upper('.$conf['user_fields']['email'].') = upper(\''.$mail_address.'\') +'.(is_numeric($user_id) ? 'AND '.$conf['user_fields']['id'].' != \''.$user_id.'\'' : '').' ;'; list($count) = pwg_db_fetch_row(pwg_query($query)); if ($count != 0) diff --git a/include/picture_comment.inc.php b/include/picture_comment.inc.php index 631f85596..5d007d4ea 100644 --- a/include/picture_comment.inc.php +++ b/include/picture_comment.inc.php @@ -49,12 +49,13 @@ if ( $page['show_comments'] and isset( $_POST['content'] ) ) 'author' => trim( @$_POST['author'] ), 'content' => trim( $_POST['content'] ), 'website_url' => trim( $_POST['website_url'] ), + 'email' => trim( @$_POST['email'] ), 'image_id' => $page['image_id'], ); 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) { @@ -143,10 +144,11 @@ SELECT com.id, author, author_id, - '.$conf['user_fields']['username'].' AS username, + u.'.$conf['user_fields']['email'].' AS user_email, date, image_id, website_url, + com.email, content, validated FROM '.COMMENTS_TABLE.' AS com @@ -161,23 +163,25 @@ SELECT while ($row = pwg_db_fetch_assoc($result)) { - if (!empty($row['author'])) + if ($row['author'] == 'guest') { - $author = $row['author']; - if ($author == 'guest') - { - $author = l10n('guest'); - } + $row['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 = array( 'ID' => $row['id'], - 'AUTHOR' => trigger_event('render_comment_author', $author), + 'AUTHOR' => trigger_event('render_comment_author', $row['author']), 'DATE' => format_date($row['date'], true), 'CONTENT' => trigger_event('render_comment_content',$row['content']), 'WEBSITE_URL' => $row['website_url'], @@ -215,6 +219,8 @@ SELECT } if (is_admin()) { + $tpl_comment['EMAIL'] = $email; + if ($row['validated'] != 'true') { $tpl_comment['U_VALIDATE'] = add_url_params( @@ -244,21 +250,19 @@ SELECT if ($show_add_comment_form) { $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', array( - 'F_ACTION' => $url_self, - 'KEY' => $key, - 'CONTENT' => $content, - 'SHOW_AUTHOR' => !is_classic_user(), - 'AUTHOR' => $author , - 'WEBSITE_URL' => $website_url, + 'F_ACTION' => $url_self, + 'KEY' => $key, + 'CONTENT' => stripslashes(@$_POST['content']), + 'SHOW_AUTHOR' => !is_classic_user(), + 'AUTHOR_MANDATORY' => $conf['comments_author_mandatory'], + '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']), )); } } diff --git a/install/config.sql b/install/config.sql index b88607856..b68af137a 100644 --- a/install/config.sql +++ b/install/config.sql @@ -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_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_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_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'); diff --git a/install/db/130-database.php b/install/db/130-database.php new file mode 100644 index 000000000..109cb3441 --- /dev/null +++ b/install/db/130-database.php @@ -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"; + +?>
\ No newline at end of file diff --git a/install/piwigo_structure-mysql.sql b/install/piwigo_structure-mysql.sql index c8b4b10b9..c75dbaae3 100644 --- a/install/piwigo_structure-mysql.sql +++ b/install/piwigo_structure-mysql.sql @@ -51,6 +51,7 @@ CREATE TABLE `piwigo_comments` ( `image_id` mediumint(8) unsigned NOT NULL default '0', `date` datetime NOT NULL default '0000-00-00 00:00:00', `author` varchar(255) default NULL, + `email` varchar(255) default NULL, `author_id` smallint(5) DEFAULT NULL, `anonymous_id` varchar(45) NOT NULL, `website_url` varchar(255) DEFAULT NULL, diff --git a/language/en_UK/common.lang.php b/language/en_UK/common.lang.php index 43fb5be4b..54b221e4b 100644 --- a/language/en_UK/common.lang.php +++ b/language/en_UK/common.lang.php @@ -165,6 +165,7 @@ $lang['edit'] = "edit"; //TO remove $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'] = "Email address"; +$lang['Email address is mandatory'] = 'Email address is mandatory'; $lang['Email: %s'] = "Email: %s"; $lang['Empty query. No criteria has been entered.'] = 'Empty query. No criteria have been entered.'; $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 or email'] = 'Username or email'; $lang['Username'] = "Username"; +$lang['Username is mandatory'] = 'Username is mandatory'; $lang['Username: %s'] = 'Username: %s'; $lang['View in'] = 'View in'; $lang['View'] = "View"; @@ -407,4 +409,5 @@ $lang['Your favorites'] = "Your favorites"; $lang['Your Gallery Customization'] = "Your gallery customization"; $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['mandatory'] = 'mandatory'; ?>
\ No newline at end of file diff --git a/language/fr_FR/common.lang.php b/language/fr_FR/common.lang.php index f59cc3560..bd278d927 100644 --- a/language/fr_FR/common.lang.php +++ b/language/fr_FR/common.lang.php @@ -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['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['Username is mandatory'] = 'Nom d\'utilisateur obligatoire'; +$lang['Email address is mandatory'] = 'Adresse email obligatoire'; +$lang['mandatory'] = 'obligatoire'; +?>
\ No newline at end of file diff --git a/themes/default/template/comment_list.tpl b/themes/default/template/comment_list.tpl index ec27111ef..daa1b835c 100644 --- a/themes/default/template/comment_list.tpl +++ b/themes/default/template/comment_list.tpl @@ -54,7 +54,8 @@ </div> {/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> {if isset($comment.IN_EDIT)} <a name="edit_comment"></a> diff --git a/themes/default/template/picture.tpl b/themes/default/template/picture.tpl index 616be3d5c..7e4c95dce 100644 --- a/themes/default/template/picture.tpl +++ b/themes/default/template/picture.tpl @@ -348,12 +348,16 @@ function togglePrivacyLevelBox() <h4>{'Add a comment'|@translate}</h4> <form method="post" action="{$comment_add.F_ACTION}" id="addComment"> {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> {/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} :</label></p> + {if $comment_add.SHOW_EMAIL} + <p><label for="email">{'Email'|@translate}{if $comment_add.EMAIL_MANDATORY} ({'mandatory'|@translate}){/if} :</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><input type="hidden" name="key" value="{$comment_add.KEY}"> <input type="submit" value="{'Submit'|@translate}"></p> |