aboutsummaryrefslogtreecommitdiff
path: root/plugin.php
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 /plugin.php
downloadkch42_gravatar-610a6cee5eca3ca433506b5dfea8d239d7cd1a50.tar.gz
kch42_gravatar-610a6cee5eca3ca433506b5dfea8d239d7cd1a50.tar.bz2
kch42_gravatar-610a6cee5eca3ca433506b5dfea8d239d7cd1a50.zip
Initial commit.
Diffstat (limited to 'plugin.php')
-rw-r--r--plugin.php42
1 files changed, 42 insertions, 0 deletions
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"));
+ }
+}
+
+?>