add image renderer
[phorkie.git] / src / phorkie / File.php
index 87c38512a0cea0a45bcdb37c6ce7869129fd491d..519413d565411db7d45356fdf4979d11f364d5ab 100644 (file)
@@ -58,16 +58,24 @@ class File
         return file_get_contents($this->path);
     }
 
-    public function getHighlightedContent()
+    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'];
-        } 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);
+        return $rend->toHtml($this, $res);
     }
 
     /**
@@ -75,14 +83,17 @@ class File
      *
      * @param string $type Link type. Supported are:
      *                     - "raw"
-     *                     - "display"
+     *                     - "tool"
+     * @param string $option
      *
      * @return string
      */
-    public function getLink($type)
+    public function getLink($type, $option = null)
     {
         if ($type == 'raw') {
             return '/' . $this->repo->id . '/raw/' . $this->getFilename();
+        } else if ($type == 'tool') {
+            return '/' . $this->repo->id . '/tool/' . $option . '/' . $this->getFilename();
         }
         throw new Exception('Unknown type');
     }
@@ -95,6 +106,15 @@ class File
         }
         return $GLOBALS['phorkie']['languages'][$ext]['mime'];
     }
+
+    /**
+     * @return array Array of Tool_Info objects
+     */
+    public function getToolInfos()
+    {
+        $tm = new Tool_Manager();
+        return $tm->getSuitable($this);
+    }
 }
 
 ?>
\ No newline at end of file