add image renderer
authorChristian Weiske <cweiske@cweiske.de>
Sun, 15 Apr 2012 11:13:23 +0000 (13:13 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sun, 15 Apr 2012 11:13:23 +0000 (13:13 +0200)
data/config.default.php
data/templates/display-file.htm
src/phorkie/File.php
src/phorkie/Renderer/Image.php [new file with mode: 0644]
src/phorkie/Renderer/Unknown.php [new file with mode: 0644]

index b07f042c76ef4a0fce229449ddba0c36202fa5af..c08d4014fb3da06961fccaf48a64edb32ebb34c5 100644 (file)
@@ -36,6 +36,11 @@ $GLOBALS['phorkie']['languages'] = array(
         'geshi' => 'xml',
         'show'  => false
     ),
         'geshi' => 'xml',
         'show'  => false
     ),
+    'jpg' => array(
+        'title' => 'JPEG image',
+        'mime'  => 'image/jpeg',
+        'show'  => false
+    ),
     'js' => array(
         'title' => 'Javascript',
         'mime'  => 'application/javascript',
     'js' => array(
         'title' => 'Javascript',
         'mime'  => 'application/javascript',
@@ -51,6 +56,11 @@ $GLOBALS['phorkie']['languages'] = array(
         'mime'  => 'text/x-php',
         'geshi' => 'php'
     ),
         'mime'  => 'text/x-php',
         'geshi' => 'php'
     ),
+    'png' => array(
+        'title' => 'PNG image',
+        'mime'  => 'image/png',
+        'show'  => false
+    ),
     'rst' => array(
         'title' => 'reStructuredText',
         'mime'  => 'text/x-rst',
     'rst' => array(
         'title' => 'reStructuredText',
         'mime'  => 'text/x-rst',
@@ -67,6 +77,11 @@ $GLOBALS['phorkie']['languages'] = array(
         'mime'  => 'text/x-sql',
         'geshi' => 'sql'
     ),
         'mime'  => 'text/x-sql',
         'geshi' => 'sql'
     ),
+    'svg' => array(
+        'title' => 'SVG image',
+        'mime'  => 'image/svg+xml',
+        'show'  => false
+    ),
     'ts' => array(
         'title' => 'TypoScript',
         'mime'  => 'text/plain',/* TODO: correct type */
     'ts' => array(
         'title' => 'TypoScript',
         'mime'  => 'text/plain',/* TODO: correct type */
index 1049abb23896246c7143d85006552fd5bd1de206..a768b7c2b03e0449da62805a43fcc28b48c17e6d 100644 (file)
@@ -7,6 +7,6 @@
   <h3 id="{{file.getFilename}}">{{file.getFilename}}<a class="anchorlink" href="#{{file.getFilename}}"></a></h3>
  </div>
  <div class="code">
   <h3 id="{{file.getFilename}}">{{file.getFilename}}<a class="anchorlink" href="#{{file.getFilename}}"></a></h3>
  </div>
  <div class="code">
-  {{file.getHighlightedContent(toolres)|raw}}
+  {{file.getRenderedContent(toolres)|raw}}
  </div>
 </div>
  </div>
 </div>
index de8bde0f1eca272fe4704236dbf961380f7cc206..519413d565411db7d45356fdf4979d11f364d5ab 100644 (file)
@@ -58,14 +58,22 @@ class File
         return file_get_contents($this->path);
     }
 
         return file_get_contents($this->path);
     }
 
-    public function getHighlightedContent(Tool_Result $res = null)
+    public function getRenderedContent(Tool_Result $res = null)
     {
     {
-        $ext = $this->getExt();
+        $ext   = $this->getExt();
+        $class = '\\phorkie\\Renderer_Unknown';
+
         if (isset($GLOBALS['phorkie']['languages'][$ext]['renderer'])) {
             $class = $GLOBALS['phorkie']['languages'][$ext]['renderer'];
         if (isset($GLOBALS['phorkie']['languages'][$ext]['renderer'])) {
             $class = $GLOBALS['phorkie']['languages'][$ext]['renderer'];
-        } else {
-            $class = '\\phorkie\\Renderer_Geshi';
+        } else if (isset($GLOBALS['phorkie']['languages'][$ext]['mime'])) {
+            $type = $GLOBALS['phorkie']['languages'][$ext]['mime'];
+            if (substr($type, 0, 5) == 'text/') {
+                $class = '\\phorkie\\Renderer_Geshi';
+            } else if (substr($type, 0, 6) == 'image/') {
+                $class = '\\phorkie\\Renderer_Image';
+            }
         }
         }
+
         $rend = new $class();
         return $rend->toHtml($this, $res);
     }
         $rend = new $class();
         return $rend->toHtml($this, $res);
     }
diff --git a/src/phorkie/Renderer/Image.php b/src/phorkie/Renderer/Image.php
new file mode 100644 (file)
index 0000000..9425646
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+namespace phorkie;
+
+class Renderer_Image
+{
+    /**
+     * Converts the code to HTML
+     *
+     * @param File        $file File to render
+     * @param Tool_Result $res  Tool result to integrate
+     *
+     * @return string HTML
+     */
+    public function toHtml(File $file, Tool_Result $res = null)
+    {
+        return '<div class="image">'
+            . '<img'
+            . ' src="' . htmlspecialchars($file->getLink('raw')) . '"'
+            . ' alt="' . htmlspecialchars($file->getFilename()) . '"'
+            . '/>'
+            . '</div>';
+    }
+}
+?>
diff --git a/src/phorkie/Renderer/Unknown.php b/src/phorkie/Renderer/Unknown.php
new file mode 100644 (file)
index 0000000..da593cb
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+namespace phorkie;
+
+class Renderer_Unknown
+{
+    /**
+     * Converts the code to HTML
+     *
+     * @param File        $file File to render
+     * @param Tool_Result $res  Tool result to integrate
+     *
+     * @return string HTML
+     */
+    public function toHtml(File $file, Tool_Result $res = null)
+    {
+        return '<div class="alert alert-error">'
+            . 'No idea how to display this file'
+            . '</div>';
+    }
+}
+?>