diff --git a/docs/docs/configuration/client.rst b/docs/docs/configuration/client.rst index ea7487a..37d32ea 100644 --- a/docs/docs/configuration/client.rst +++ b/docs/docs/configuration/client.rst @@ -106,6 +106,14 @@ scheme is based in `this color palette `_. Multiple colors must be separated by space. If you use less than eight colors and not a multiple of 2, the color distribution is not even. +data-isso-gravatar +------------------ + +Uses gravatar images instead of generating svg images. You have to set +"data-isso-avatar" to **false** when you want to use this. Otherwise +both the gravatar and avatar svg image will show up. Please also set +option "gravatar" to **true** in the server configuration... + data-isso-vote -------------- diff --git a/docs/docs/configuration/server.rst b/docs/docs/configuration/server.rst index cb39ccd..9cd11e7 100644 --- a/docs/docs/configuration/server.rst +++ b/docs/docs/configuration/server.rst @@ -91,6 +91,18 @@ notify log-file Log console messages to file instead of standard out. +gravatar + When set to ``true`` this will add the property "gravatar_image" + containing the link to a gravatar image to every comment. If a comment + does not contain an email address, gravatar will render a random icon. + This is only true when using the default value for "gravatar-url" + which contains the query string param ``d=identicon`` ... + +gravatar-url + Url for gravatar images. The "{}" is where the email hash will be placed. + Defaults to "https://www.gravatar.com/avatar/{}?d=identicon" + + .. _CORS: https://developer.mozilla.org/en/docs/HTTP/Access_control_CORS diff --git a/isso/js/app/config.js b/isso/js/app/config.js index 952d588..2a4cde1 100644 --- a/isso/js/app/config.js +++ b/isso/js/app/config.js @@ -10,6 +10,7 @@ define(function() { "max-comments-top": "inf", "max-comments-nested": 5, "reveal-on-click": 5, + "gravatar": false, "avatar": true, "avatar-bg": "#f0f0f0", "avatar-fg": ["#9abf88", "#5698c4", "#e279a3", "#9163b6", diff --git a/isso/js/app/isso.js b/isso/js/app/isso.js index 0523e9b..7b908a1 100644 --- a/isso/js/app/isso.js +++ b/isso/js/app/isso.js @@ -228,7 +228,7 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n", $("a.edit", footer).toggle("click", function(toggler) { var edit = $("a.edit", footer); - var avatar = config["avatar"] ? $(".avatar", el, false)[0] : null; + var avatar = config["avatar"] || config["gravatar"] ? $(".avatar", el, false)[0] : null; edit.textContent = i18n.translate("comment-save"); edit.insertAfter($.new("a.cancel", i18n.translate("comment-cancel"))).on("click", function() { @@ -256,7 +256,7 @@ define(["app/dom", "app/utils", "app/config", "app/api", "app/jade", "app/i18n", }, function(toggler) { var textarea = $(".textarea", text); - var avatar = config["avatar"] ? $(".avatar", el, false)[0] : null; + var avatar = config["avatar"] || config["gravatar"] ? $(".avatar", el, false)[0] : null; if (! toggler.canceled && textarea !== null) { if (utils.text(textarea.innerHTML).length < 3) { diff --git a/isso/js/app/text/comment.jade b/isso/js/app/text/comment.jade index 4884bf7..1d97499 100644 --- a/isso/js/app/text/comment.jade +++ b/isso/js/app/text/comment.jade @@ -1,4 +1,7 @@ div(class='isso-comment' id='isso-#{comment.id}') + if conf.gravatar + div(class='avatar') + img(src='#{comment.gravatar_image}') if conf.avatar div(class='avatar') svg(data-hash='#{comment.hash}') diff --git a/isso/utils/hash.py b/isso/utils/hash.py index 0e93a1a..2ade078 100644 --- a/isso/utils/hash.py +++ b/isso/utils/hash.py @@ -109,4 +109,5 @@ def new(conf): return Hash(salt, algorithm) -sha1 = Hash(func="sha1").uhash \ No newline at end of file +sha1 = Hash(func="sha1").uhash +md5 = Hash(func="md5").uhash diff --git a/isso/views/comments.py b/isso/views/comments.py index d328305..1be4831 100644 --- a/isso/views/comments.py +++ b/isso/views/comments.py @@ -22,6 +22,7 @@ from isso import utils, local from isso.utils import http, parse, JSONResponse as JSON from isso.views import requires from isso.utils.hash import sha1 +from isso.utils.hash import md5 # from Django appearently, looks good to me *duck* __url_re = re.compile( @@ -72,7 +73,7 @@ def xhr(func): class API(object): FIELDS = set(['id', 'parent', 'text', 'author', 'website', - 'mode', 'created', 'modified', 'likes', 'dislikes', 'hash']) + 'mode', 'created', 'modified', 'likes', 'dislikes', 'hash', 'gravatar_image']) # comment fields, that can be submitted ACCEPT = set(['text', 'author', 'website', 'email', 'parent', 'title']) @@ -206,6 +207,8 @@ class API(object): self.cache.set('hash', (rv['email'] or rv['remote_addr']).encode('utf-8'), rv['hash']) + rv = self._add_gravatar_image(rv) + for key in set(rv.keys()) - API.FIELDS: rv.pop(key) @@ -426,7 +429,17 @@ class API(object): comment['replies'] = self._process_fetched_list(replies, plain) return JSON(rv, 200) + def _add_gravatar_image(self, item): + if not self.conf.getboolean('gravatar'): + return item + email = item['email'] or "" + email_md5_hash = md5(email) + + gravatar_url = self.conf.get('gravatar-url') + item['gravatar_image'] = gravatar_url.format(email_md5_hash) + + return item def _process_fetched_list(self, fetched_list, plain=False): for item in fetched_list: @@ -439,6 +452,8 @@ class API(object): item['hash'] = val + item = self._add_gravatar_image(item) + for key in set(item.keys()) - API.FIELDS: item.pop(key) diff --git a/share/isso.conf b/share/isso.conf index 7c275ac..4bb3ef3 100644 --- a/share/isso.conf +++ b/share/isso.conf @@ -46,6 +46,13 @@ notify = stdout # Log console messages to file instead of standard out. log-file = +# adds property "gravatar_image" to json response when true +# will automatically build md5 hash by email and use "gravatar_url" to build +# the url to the gravatar image +gravatar = false + +# default url for gravatar. {} is where the hash will be placed +gravatar-url = https://www.gravatar.com/avatar/{}?d=identicon [moderation] # enable comment moderation queue. This option only affects new comments.