aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2012-03-03 22:40:07 +0100
committerKevin Chabowski <kevin@kch42.de>2012-03-03 22:40:07 +0100
commit610a6cee5eca3ca433506b5dfea8d239d7cd1a50 (patch)
tree1cec5809d06c06eeee522ab4ef9db428812fb2cd
downloadkch42_gravatar-610a6cee5eca3ca433506b5dfea8d239d7cd1a50.tar.gz
kch42_gravatar-610a6cee5eca3ca433506b5dfea8d239d7cd1a50.tar.bz2
kch42_gravatar-610a6cee5eca3ca433506b5dfea8d239d7cd1a50.zip
Initial commit.
-rw-r--r--.gitignore1
-rw-r--r--COPYING18
-rw-r--r--README.md4
-rwxr-xr-xbuild.sh3
-rw-r--r--help.html55
-rw-r--r--plugin.php42
6 files changed, 123 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..07231e7
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+kch42_gravatar.rpk \ No newline at end of file
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..a74122e
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,18 @@
+kch42_gravatar: Copyright (c) 2012 Kevin Chabowski
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..a2ecd7f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,4 @@
+kch42_gravatar
+==============
+
+A Plugin for Ratatöskr that gives you [Gravatars](http://de.gravatar.com) for the comments. \ No newline at end of file
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..47d991c
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+r7r-plugin-packer --output=kch42_gravatar.rpk --codefile=plugin.php --classname=kch42_gravatar --pluginname=kch42_gravatar --author='Kevin Chabowski <kevin@kch42.de>' --versiontext="0.6" --versioncount=2 --api=5 --shortdesc="kch42_gravatar allows you to display [Gravatars](http://de.gravatar.com)" --helpfile=help.html --licensefile=COPYING
diff --git a/help.html b/help.html
new file mode 100644
index 0000000..74a0b56
--- /dev/null
+++ b/help.html
@@ -0,0 +1,55 @@
+<h2>kch42_gravatar</h2>
+
+<p>This Plugin gives you an STE tag, which will return the <a href="http://www.gravatar.com">Gravatar</a> of the person, who written a comment.</p>
+<p>This tag is: <code>&lt;ste:kch42_gravatar /&gt;</code>.</p>
+
+<h3>How to use this tag</h3>
+
+<p>The tag will return a HTML <code>&lt;img /&gt;</code> tag.</p>
+
+<p>The tag will accept these parameters:</p>
+
+<p>
+ <table>
+ <thead>
+ <tr>
+ <th>Parameter name</th>
+ <th>Mandatory?</th>
+ <th>Default value</th>
+ <th>Description</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>comment</code></td>
+ <td><strong>Yes</strong></td>
+ <td>&nbsp;</td>
+ <td>Name of a variable that contains information about a comment (usually generated by <code>&lt;ste:article_comments /&gt;</code>)</td>
+ </tr>
+ <tr>
+ <td><code>size</code></td>
+ <td>No</td>
+ <td>80</td>
+ <td>Size of image in pixels.</td>
+ </tr>
+ <tr>
+ <td><code>default</code></td>
+ <td>No</td>
+ <td>identicon</td>
+ <td>The default image, if no Gravatar is available. Can be a URL to an image or one of <a href="http://gravatar.com/site/implement/images/#default-image">Gravatar's default values</a>.</td>
+ </tr>
+ <tr>
+ <td><code>rating</code></td>
+ <td>No</td>
+ <td>g</td>
+ <td>One of <a href="http://gravatar.com/site/implement/images/#rating">Gravatar's rating values</a>.</td>
+ </tr>
+ <tr>
+ <td><code>style</code></td>
+ <td>No</td>
+ <td>&nbsp;</td>
+ <td>Additional (CSS) styles for the image.</td>
+ </tr>
+ </tbody>
+ </table>
+</p>
diff --git a/plugin.php b/plugin.php
new file mode 100644
index 0000000..d0a044f
--- /dev/null
+++ b/plugin.php
@@ -0,0 +1,42 @@
+<?php
+
+class kch42_gravatar extends RatatoeskrPlugin
+{
+ public function ste_tag_kch42_gravatar($ste, $params, $sub)
+ {
+ if(!isset($params["comment"]))
+ throw new \ste\RuntimeError("ste:kch42_gravatar needs the comment parameter.");
+
+ $ste_comment = $ste->get_var_by_name($params["comment"]);
+
+ if(isset($ste_comment["__obj"]))
+ $comment = $ste_comment["__obj"];
+ else
+ $comment = Comment::by_id($ste_comment["id"]);
+
+ $mail_hash = md5(strtolower(trim($comment->author_mail)));
+
+ $gravatar_args = array("default" => "identicon", "rating" => "g", "size" => "80");
+ $query_fragments = array();
+ foreach($gravatar_args as $key => &$value)
+ {
+ if(isset($params[$key]))
+ $value = $params[$key];
+ $value = htmlspecialchars(urlencode($value));
+ $query_fragments[] = "$key=$value";
+ }
+
+ $styles = "width: {$gravatar_args["size"]}px; height: {$gravatar_args["size"]}px;" . (isset($params["style"]) ? " " . $params["style"] : "");
+
+ $protocol = ((!empty($_SERVER["HTTPS"])) and ($_SERVER["HTTPS"] == "on")) ? "https" : "http";
+
+ return "<img src=\"$protocol://www.gravatar.com/avatar/$mail_hash?" . implode("&", $query_fragments) . "\" style=\"" . htmlspecialchars($styles) . "\" alt=\"\" />";
+ }
+
+ public function init()
+ {
+ $this->ste->register_tag("kch42_gravatar", array($this, "ste_tag_kch42_gravatar"));
+ }
+}
+
+?>