Merge pull request #52 from gordonbanderson/ISSUE8

Addition of Gravatars
This commit is contained in:
Will Rossiter 2013-03-06 01:27:20 -08:00
commit ee3da5b38e
4 changed files with 31 additions and 1 deletions

View File

@ -26,6 +26,8 @@ class Commenting {
'require_login' => false, // boolean, whether a user needs to login
'required_permission' => false, // required permission to comment (or array of permissions)
'use_ajax_commenting' => true, // use ajax to post comments.
'use_gravatar' => false, // set to true to show gravatar icons,
'gravatar_size' => 80, // size of gravatar in pixels. This is the same as the standard default
'show_comments_when_disabled' => false, // when comments are disabled should we show older comments (if available)
'order_comments_by' => "\"Created\" DESC",
'comments_per_page' => 10,

View File

@ -394,4 +394,19 @@ class Comment extends DataObject {
$config->set('URI.DisableExternalResources', true);
return new HTMLPurifier($config);
}
/*
Calcualate the gravatar link from the email address
*/
public function Gravatar() {
$gravatar = '';
$use_gravatar = Commenting::get_config_value($this->BaseClass, 'use_gravatar');
if ($use_gravatar) {
$gravatar = "http://www.gravatar.com/avatar/" . md5( strtolower(trim($this->Email)));
$gravatarsize = Commenting::get_config_value($this->BaseClass, 'gravatar_size');
$gravatar.= "?s=".$gravatarsize."&d=mm";
}
return $gravatar;
}
}

View File

@ -18,7 +18,9 @@ The module provides a number of built in configuration settings below are the de
'require_moderation' => false,
'html_allowed' => false, // allow for sanitized HTML in comments
'html_allowed_elements' => array('a', 'img', 'i', 'b'),
'use_preview' => false, // preview formatted comment (when allowing HTML)
'use_preview' => false, // preview formatted comment (when allowing HTML),
'use_gravatar' => false,
'gravatar_size' => 80
);
If you want to customize any of the configuration options after you have added the extension (or
@ -48,3 +50,13 @@ The easiest way to do this is through [Composer](http://getcomposer.org).
**Important**: Rendering user-provided HTML on your website always risks
exposing your users to cross-site scripting (XSS) attacks, if the HTML
isn't properly sanitized. Don't allow tags like `<script>` or arbitrary attributes.
## Gravatars
Gravatars can be turned on by adding this to your mysite/_config.php file
Commenting::set_config_value('SiteTree', 'use_gravatar', true);
The default size is 80 pixels, as per the gravatar site if the 's' parameter is omitted. To change this add the following (again to mysite/_config.php):
Commenting::set_config_value('SiteTree', 'gravatar_size', 40);

View File

@ -1,4 +1,5 @@
<div class="comment" id="<% if isPreview %>comment-preview<% else %>$Permalink<% end_if %>">
<% if $Gravatar %><img class="gravatar" src="$Gravatar" alt="Gravatar for $Name" title="Gravatar for $Name" /><% end_if %>
$EscapedComment
</div>