add option to disable avatar loading
[phorkie.git] / src / phorkie / HtmlHelper.php
index ea21ab59cafa6706f37387543cbd4143535569cc..d23468547bbb98ab3726d87eff807437e3ee39aa 100644 (file)
@@ -3,6 +3,24 @@ namespace phorkie;
 
 class HtmlHelper
 {
+    public function getIconUrl($email, $size = 32)
+    {
+        if ($email == 'anonymous@phorkie'
+            || !$GLOBALS['phorkie']['cfg']['avatars']
+        ) {
+            return 'phorkie/anonymous.png';
+        }
+
+        $s = new \Services_Libravatar();
+        return $s->url(
+            $email,
+            array(
+                'size'    => $size,
+                'default' => Tools::fullUrl('phorkie/anonymous.png')
+            )
+        );
+    }
+
     public function getLanguageOptions(File $file = null)
     {
         $html = '<option value="_auto_">* automatic *</option>';
@@ -23,6 +41,38 @@ class HtmlHelper
         }
         return $html;
     }
+
+    public function getDomain($url)
+    {
+        return parse_url($url, PHP_URL_HOST);
+    }
+
+    public function fullUrl($path = '')
+    {
+        return Tools::fullUrl($path);
+    }
+
+    public function mayWriteLocally()
+    {
+        if ($GLOBALS['phorkie']['auth']['securityLevel'] == 0) {
+            //everyone may do everything
+            return true;
+        }
+
+        $logged_in = false;
+        if (!isset($_SESSION['identity'])) {
+            //not logged in
+        } else if ($GLOBALS['phorkie']['auth']['listedUsersOnly']) {
+            if (in_array($_SESSION['identity'], $GLOBALS['phorkie']['auth']['users'])) {
+                $logged_in = true;
+            }
+        } else {
+            //session identity exists, no special checks required
+            $logged_in = true;
+        }
+
+        return $logged_in;
+    }
 }
 
 ?>