support embedding in application/xhtml+xml pages
[phorkie.git] / src / phorkie / HtmlHelper.php
index efde7149048d38af172f4a5a003196ea084812ff..0a8b926888fca70554bbd56f0d3c2da47957aeca 100644 (file)
@@ -5,11 +5,14 @@ class HtmlHelper
 {
     public function getIconUrl($email, $size = 32)
     {
-        if ($email == 'anonymous@phorkie') {
+        if ($email == 'anonymous@phorkie'
+            || !$GLOBALS['phorkie']['cfg']['avatars']
+        ) {
             return 'phorkie/anonymous.png';
         }
 
         $s = new \Services_Libravatar();
+        $s->detectHttps();
         return $s->url(
             $email,
             array(
@@ -40,10 +43,44 @@ 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;
+    }
+
+    public function getRepositoryEmbedCode(Repository $repo)
+    {
+        return '<script src="' . $repo->getLink('embed', null, true) . '"'
+            . ' id="phork-script-' . $repo->id . '"'
+            . ' type="text/javascript"></script>';
+    }
 }
 
 ?>