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 799f94d669757ef33b6339c8342f64f493b2f517..6c75eaa51c00e885e7f70b5ccd4d40c759da07b5 100644 (file)
@@ -24,5 +24,6 @@
 {% endblock %}
 
 {% block sidebar %}
+ {% include 'display-sidebar-owner.htm' %}
  {% include 'display-sidebar-history.htm' %}
 {% endblock %}
index ea21ab59cafa6706f37387543cbd4143535569cc..fd04d831e217cb74f931e97f1ffacfff98a27104 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 0cc279b7472f0b66442a47d2ad77633c6f4394c6..ba3079acbb6c955ee854e8515e1fc783dd0184e9 100644 (file)
@@ -235,6 +235,27 @@ class Repository
         file_put_contents($this->gitDir . '/description', $description);
     }
 
+    /**
+     * @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
      *
index 1ac8cc5cce40788a526446f40578ecf9b51112cd..1afc151af68b5105b3c517c12d045d2145f1f7b4 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 ffc978629c3ddc293d3227ceec5132f92b18af12..ae29b8788ee967a3995d99a0919b775648897346 100644 (file)
@@ -14,6 +14,7 @@ render(
     array(
         'repo' => $repo,
         'dh'   => new \Date_HumanDiff(),
+        'htmlhelper' => new HtmlHelper(),
     )
 );
 ?>