Andrew Dolgov 8 months ago
commit
fbb4bb0e57
4 changed files with 76 additions and 0 deletions
  1. 9 0
      README.md
  2. 9 0
      init.css
  3. 12 0
      init.js
  4. 46 0
      init.php

+ 9 - 0
README.md

@@ -0,0 +1,9 @@
+UI Gravatar
+===========
+
+Shows your globally recognized avatar in the overflow menu button of
+main tt-rss UI. Needs your email address to be set in tt-rss preferences.
+
+Git clone to ``plugins.local/ui_gravatar``.
+
+See https://gravatar.com/ for more information.

+ 9 - 0
init.css

@@ -0,0 +1,9 @@
+body.ttrss_main .action-chooser .action-button .dijitArrowButtonInner {
+    display : inline ! important;
+}
+
+body.ttrss_main .action-chooser .userpic-gravatar {
+    width : 21px;
+    height : 21px;
+    border-radius: 50% 50%;
+}

+ 12 - 0
init.js

@@ -0,0 +1,12 @@
+require(['dojo/_base/kernel', 'dojo/ready'], function  (dojo, ready) {
+    ready(function() {
+        PluginHost.register(PluginHost.HOOK_INIT_COMPLETE, () => {
+            const btn = document.querySelector(".action-chooser .dijitButtonText");
+
+            if (btn)
+                btn.innerHTML = "<img referrerpolicy='no-referrer' class='userpic-gravatar' src=\"https://secure.gravatar.com/avatar/%GRAVATAR_HASH%?s=96\">";
+
+            return true;
+        });
+    });
+});

+ 46 - 0
init.php

@@ -0,0 +1,46 @@
+<?php
+class UI_Gravatar extends Plugin {
+	private $host;
+	private $gravatar_hash = "";
+
+	function about() {
+		return array(1.0,
+			"Shows your globally recognized avatar (Gravatar) in the UI",
+			"fox");
+	}
+
+	function init($host) {
+		$this->host = $host;
+
+		$sth = $this->pdo->prepare("SELECT email FROM ttrss_users WHERE id = ?");
+		$sth->execute([$_SESSION['uid']]);
+
+		if ($row = $sth->fetch()) {
+			$this->gravatar_hash = md5(trim($row['email']));
+		}
+
+		//$host->add_hook($host::HOOK_PREFS_TAB, $this);
+	}
+
+	function get_js() {
+		if ($this->gravatar_hash) {
+			return str_replace("%GRAVATAR_HASH%", $this->gravatar_hash,
+				file_get_contents(__DIR__ . "/init.js"));
+		} else {
+			return "";
+		}
+	}
+
+	function get_css() {
+		if ($this->gravatar_hash) {
+			return file_get_contents(__DIR__ . "/init.css");
+		} else {
+			return "";
+		}
+	}
+
+	function api_version() {
+		return 2;
+	}
+
+}