Part of #35: show paste owner
authorChristian Weiske <cweiske@cweiske.de>
Wed, 24 Oct 2012 20:19:34 +0000 (22:19 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 24 Oct 2012 20:19:34 +0000 (22:19 +0200)
data/templates/display-sidebar-owner.htm [new file with mode: 0644]
data/templates/display.htm
src/phorkie/HtmlHelper.php
src/phorkie/Repository.php
src/phorkie/Repository/Commit.php
www/display.php

diff --git a/data/templates/display-sidebar-owner.htm b/data/templates/display-sidebar-owner.htm
new file mode 100644 (file)
index 0000000..f84a5fa
--- /dev/null
@@ -0,0 +1,9 @@
+{% set owner = repo.getOwner %}
+<div class="well well-small vcard">
+ <img src="{{htmlhelper.getIconUrl(owner.email, 48)}}" alt="{{owner.name}}"
+      width="48" height="48" class="photo"
+      style="float: left; padding-right: 1ex;"/>
+ <span class="fn">{{owner.name}}</span>
+ <br/><span class="muted">owner</span>
+ <span class="clearfix"/>
+</div>
\ No newline at end of file
index 799f94d..6c75eaa 100644 (file)
@@ -24,5 +24,6 @@
 {% endblock %}
 
 {% block sidebar %}
+ {% include 'display-sidebar-owner.htm' %}
  {% include 'display-sidebar-history.htm' %}
 {% endblock %}
index ea21ab5..fd04d83 100644 (file)
@@ -3,6 +3,22 @@ namespace phorkie;
 
 class HtmlHelper
 {
+    public function getIconUrl($email, $size = 32)
+    {
+        if ($email == 'anonymous@phorkie') {
+            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>';
index 0cc279b..ba3079a 100644 (file)
@@ -236,6 +236,27 @@ class Repository
     }
 
     /**
+     * @return array Array with keys "email" and "name"
+     */
+    public function getOwner()
+    {
+        try {
+            $name = $this->getVc()->getCommand('config')
+                ->addArgument('owner.name')->execute();
+        } catch (\VersionControl_Git_Exception $e) {
+            $name = $GLOBALS['phorkie']['auth']['anonymousName'];
+        }
+        try {
+            $email = $this->getVc()->getCommand('config')
+                ->addArgument('owner.email')->execute();
+        } catch (\VersionControl_Git_Exception $e) {
+            $email = $GLOBALS['phorkie']['auth']['anonymousEmail'];
+        }
+
+        return array('name' => trim($name), 'email' => trim($email));
+    }
+
+    /**
      * Get a link to the repository
      *
      * @param string $type   Link type. Supported are:
index 1ac8cc5..1afc151 100644 (file)
@@ -16,18 +16,8 @@ class Repository_Commit
 
     public function getIconUrl()
     {
-        if ($this->committerEmail == 'anonymous@phorkie') {
-            return '/phorkie/anonymous.png';
-        }
-
-        $s = new \Services_Libravatar();
-        return $s->url(
-            $this->committerEmail,
-            array(
-                'size'    => 32,
-                'default' => Tools::fullUrl('/phorkie/anonymous.png')
-            )
-        );
+        $hh = new HtmlHelper();
+        return $hh->getIconUrl($this->committerEmail);
     }
 
     /**
index ffc9786..ae29b87 100644 (file)
@@ -14,6 +14,7 @@ render(
     array(
         'repo' => $repo,
         'dh'   => new \Date_HumanDiff(),
+        'htmlhelper' => new HtmlHelper(),
     )
 );
 ?>