diff --git a/indefero/src/IDF/FileUtil.php b/indefero/src/IDF/FileUtil.php index e81eead..42b359c 100644 --- a/indefero/src/IDF/FileUtil.php +++ b/indefero/src/IDF/FileUtil.php @@ -38,6 +38,8 @@ class IDF_FileUtil 'skin', 'sln', 'svc', 'vala', 'vb', 'vbproj', 'vbs', 'wsdl', 'xhtml', 'xml', 'xsd', 'xsl', 'xslt'); + public static $imageExtensions = ["png", "gif", "jpeg", "jpg"]; + public static $map = array("cxx" => "cpp", "h" => "cpp", "hpp" => "cpp", "rc"=>"text", "sh"=>"bash", "cs"=>"csharp"); public static $syntaxhighlightext = array("html", "as3", "cf", "cpp", "c", "css", "pas", "diff", "patch", "erl", "java", "jfx", "js", "pl", "php", "py", "rb", "sass", "scss", "scala", "sql", "vb", ); @@ -62,34 +64,46 @@ class IDF_FileUtil * @param string the content of the file * @return string */ - public static function highLight($fileinfo, $content) + public static function highLight($fileinfo, $content, $url) { - $pretty = ''; - if (self::isSupportedExtension($fileinfo[2])) { - $pretty = ' prettyprint'; + + if (self::isText($fileinfo)) { + $pretty = ''; + if (self::isSupportedExtension($fileinfo[2])) { + $pretty = ' prettyprint'; + } + + $table = array(); + $i = 1; + /*foreach (self::splitIntoLines($content) as $line) { + $table[] = ''.$i.'' + .''.self::emphasizeControlCharacters(Pluf_esc($line)).''; + $i++; + } + return Pluf_Template::markSafe(implode("\n", $table));*/ + //var_dump($fileinfo); + $ext = ""; + if (in_array($fileinfo[2], self::$syntaxhighlightext)) + $ext = $fileinfo[2]; + elseif (array_key_exists($fileinfo[2], self::$map)) + $ext = self::$map[$fileinfo[2]]; + else + $ext = "text"; + if ($ext == "php" || $ext == "html" || $ext == "htm" || $ext == "js") + $content = '
' . str_replace("<", "<", $content) . '
'; + else + $content = '
'; + } - $table = array(); - $i = 1; - /*foreach (self::splitIntoLines($content) as $line) { - $table[] = ''.$i.'' - .''.self::emphasizeControlCharacters(Pluf_esc($line)).''; - $i++; + + if (self::isImage($fileinfo)) { + $content = ''; + $content .= '' . $fileinfo[1] . ''; } - return Pluf_Template::markSafe(implode("\n", $table));*/ - //var_dump($fileinfo); - $ext = ""; - if (in_array($fileinfo[2], self::$syntaxhighlightext)) - $ext = $fileinfo[2]; - elseif (array_key_exists($fileinfo[2], self::$map)) - $ext = self::$map[$fileinfo[2]]; - else - $ext = "text"; - if ($ext == "php" || $ext == "html" || $ext == "htm" || $ext == "js") - $content = '
' . str_replace("<", "<", $content)  . '
'; - else - $content = '
'; - return Pluf_Template::markSafe($content); + + return Pluf_Template::markSafe($content); + } /** @@ -242,4 +256,12 @@ class IDF_FileUtil $ext = array_merge(self::$supportedExtenstions, explode(' ' , $ext)); return (in_array($fileinfo[2], $ext)); } + + public static function isImage($fileinfo) { + if (0 === strpos($fileinfo[0], 'image/')) { + return true; + } + + return false; + } } diff --git a/indefero/src/IDF/Views/Source.php b/indefero/src/IDF/Views/Source.php index fc7c088..abb584a 100644 --- a/indefero/src/IDF/Views/Source.php +++ b/indefero/src/IDF/Views/Source.php @@ -211,13 +211,13 @@ class IDF_Views_Source if ($request_file_info->type != 'tree') { $info = self::getRequestedFileMimeType($request_file_info, $commit, $scm); - if (!IDF_FileUtil::isText($info)) { + if (!IDF_FileUtil::isText($info) && !IDF_FileUtil::isImage($info)) { $rep = new Pluf_HTTP_Response($scm->getFile($request_file_info), $info[0]); $rep->headers['Content-Disposition'] = 'attachment; filename="'.$info[1].'"'; return $rep; } else { - // We want to display the content of the file as text + // We want to display the content of the file $extra = array('branches' => $branches, 'tags' => $tags, 'commit' => $commit, @@ -358,6 +358,7 @@ class IDF_Views_Source */ public function viewFile($request, $match, $extra) { + $project = $request->project; $title = sprintf(__('%1$s %2$s Source Tree'), (string) $request->project, $this->getScmType($request)); $scm = IDF_Scm::get($request->project); @@ -377,13 +378,8 @@ class IDF_Views_Source $previous = substr($request_file, 0, -strlen($l.' ')); $scmConf = $request->conf->getVal('scm', 'git'); $props = $scm->getProperties($commit, $request_file); - $cache = Pluf_Cache::factory(); - $key = sha1($request_file.$commit); - $content = IDF_FileUtil::highLight($extra['mime'], $scm->getFile($request_file_info)); - /*if (null === ($content=$cache->get($key))) { - - $cache->set($key, $content); - }*/ + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Source::getFile', [$project->shortname, $commit, $request_file]); + $content = IDF_FileUtil::highLight($extra['mime'], $scm->getFile($request_file_info), $url); return Pluf_Shortcuts_RenderToResponse('idf/source/'.$scmConf.'/file.html', array( 'page_title' => $page_title,