diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2012-04-15 13:13:23 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2012-04-15 13:13:23 +0200 |
| commit | 6977145fa62346b35db60da018e699b7f1967e90 (patch) | |
| tree | 506d5dfde75e18a40d318cbc3bc2ae487619fd7a /src | |
| parent | b9ffa6b92277d3dc8a4eca77119ea098e20f36f0 (diff) | |
| download | phorkie-6977145fa62346b35db60da018e699b7f1967e90.tar.gz phorkie-6977145fa62346b35db60da018e699b7f1967e90.zip | |
add image renderer
Diffstat (limited to 'src')
| -rw-r--r-- | src/phorkie/File.php | 16 | ||||
| -rw-r--r-- | src/phorkie/Renderer/Image.php | 24 | ||||
| -rw-r--r-- | src/phorkie/Renderer/Unknown.php | 21 |
3 files changed, 57 insertions, 4 deletions
diff --git a/src/phorkie/File.php b/src/phorkie/File.php index de8bde0..519413d 100644 --- a/src/phorkie/File.php +++ b/src/phorkie/File.php @@ -58,14 +58,22 @@ class File 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']; - } 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); } diff --git a/src/phorkie/Renderer/Image.php b/src/phorkie/Renderer/Image.php new file mode 100644 index 0000000..9425646 --- /dev/null +++ b/src/phorkie/Renderer/Image.php @@ -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 index 0000000..da593cb --- /dev/null +++ b/src/phorkie/Renderer/Unknown.php @@ -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>'; + } +} +?> |
