srchub

srchub Commit Details


Date:2016-03-19 19:08:15 (8 years 9 months ago)
Author:Natalie Adams
Branch:master
Commit:957111d6adf5f74754ae6ef59f29331b0a4dc8f2
Parents: 24cf41de2b9aadd6c9e6546a9f1e6d27e40a4ce2
Message:Issue 143: Add preview for image files

Changes:

File differences

indefero/src/IDF/FileUtil.php
3838
3939
4040
41
42
4143
4244
4345
......
6264
6365
6466
65
67
6668
6769
68
69
70
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
7198
72
73
74
75
76
77
99
100
101
102
78103
79
80
81
82
83
84
85
86
87
88
89
90
91
92
104
105
106
93107
94108
95109
......
242256
243257
244258
259
260
261
262
263
264
265
266
245267
'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", );
* @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[] = '<tr class="c-line"><td class="code-lc" id="L'.$i.'"><a href="#L'.$i.'">'.$i.'</a></td>'
.'<td class="code mono'.$pretty.'">'.self::emphasizeControlCharacters(Pluf_esc($line)).'</td></tr>';
$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 = '<div id="highlight"><pre class="brush: ' . $ext . '">' . str_replace("<", "&lt;", $content) . '</pre></div>';
else
$content = '<div id="highlight"><script type="syntaxhighlighter" class="brush: ' . $ext . '">' . $content . '</script></div>';
}
$table = array();
$i = 1;
/*foreach (self::splitIntoLines($content) as $line) {
$table[] = '<tr class="c-line"><td class="code-lc" id="L'.$i.'"><a href="#L'.$i.'">'.$i.'</a></td>'
.'<td class="code mono'.$pretty.'">'.self::emphasizeControlCharacters(Pluf_esc($line)).'</td></tr>';
$i++;
if (self::isImage($fileinfo)) {
$content = '<tr style="border: 0 !important;"><td style="border: 0 !important;">';
$content .= '<img src="' . $url . '" download="' . $fileinfo[1] . '" alt="' . $fileinfo[1] . '"></a></td></tr>';
}
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 = '<div id="highlight"><pre class="brush: ' . $ext . '">' . str_replace("<", "&lt;", $content) . '</pre></div>';
else
$content = '<div id="highlight"><script type="syntaxhighlighter" class="brush: ' . $ext . '">' . $content . '</script></div>';
return Pluf_Template::markSafe($content);
return Pluf_Template::markSafe($content);
}
/**
$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;
}
}
indefero/src/IDF/Views/Source.php
211211
212212
213213
214
214
215215
216216
217217
218218
219219
220
220
221221
222222
223223
......
358358
359359
360360
361
361362
362363
363364
......
377378
378379
379380
380
381
382
383
384
385
386
381
382
387383
388384
389385
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,
*/
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);
$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,

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.08814s using 20 queries.