'geshi' => 'xml',
'show' => false
),
+ 'jpg' => array(
+ 'title' => 'JPEG image',
+ 'mime' => 'image/jpeg',
+ 'show' => false
+ ),
'js' => array(
'title' => 'Javascript',
'mime' => 'application/javascript',
'mime' => 'text/x-php',
'geshi' => 'php'
),
+ 'png' => array(
+ 'title' => 'PNG image',
+ 'mime' => 'image/png',
+ 'show' => false
+ ),
'rst' => array(
'title' => 'reStructuredText',
'mime' => 'text/x-rst',
'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 */
<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>
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);
}
--- /dev/null
+<?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>';
+ }
+}
+?>
--- /dev/null
+<?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>';
+ }
+}
+?>