mirror of
https://github.com/klaussilveira/gitlist.git
synced 2025-11-18 03:30:55 +01:00
simplify file type detection, fix phpdoc
This commit is contained in:
@@ -11,6 +11,88 @@ class Utils
|
|||||||
{
|
{
|
||||||
protected $app;
|
protected $app;
|
||||||
|
|
||||||
|
protected $defaultFileTypes = array(
|
||||||
|
'php' => 'php',
|
||||||
|
'c' => 'clike',
|
||||||
|
'h' => 'clike',
|
||||||
|
'cpp' => 'clike',
|
||||||
|
'm' => 'clike',
|
||||||
|
'mm' => 'clike',
|
||||||
|
'cs' => 'csharp',
|
||||||
|
'java' => 'java',
|
||||||
|
'clj' => 'clojure',
|
||||||
|
'coffee' => 'coffeescript',
|
||||||
|
'css' => 'css',
|
||||||
|
'diff' => 'diff',
|
||||||
|
'ecl' => 'ecl',
|
||||||
|
'el' => 'erlang',
|
||||||
|
'go' => 'go',
|
||||||
|
'groovy' => 'groovy',
|
||||||
|
'hs' => 'haskell',
|
||||||
|
'lhs' => 'haskell',
|
||||||
|
'jsp' => 'htmlembedded',
|
||||||
|
'asp' => 'htmlembedded',
|
||||||
|
'aspx' => 'htmlembedded',
|
||||||
|
'html' => 'htmlmixed',
|
||||||
|
'tpl' => 'htmlmixed',
|
||||||
|
'js' => 'javascript',
|
||||||
|
'json' => 'javascript',
|
||||||
|
'less' => 'less',
|
||||||
|
'lua' => 'lua',
|
||||||
|
'md' => 'markdown',
|
||||||
|
'markdown' => 'markdown',
|
||||||
|
'sql' => 'mysql',
|
||||||
|
'pl' => 'perl',
|
||||||
|
'pm' => 'perl',
|
||||||
|
'pas' => 'pascal',
|
||||||
|
'ini' => 'properties',
|
||||||
|
'cfg' => 'properties',
|
||||||
|
'nt' => 'ntriples',
|
||||||
|
'py' => 'python',
|
||||||
|
'rb' => 'ruby',
|
||||||
|
'rst' => 'rst',
|
||||||
|
'r' => 'r',
|
||||||
|
'sh' => 'shell',
|
||||||
|
'ss' => 'scheme',
|
||||||
|
'scm' => 'scheme',
|
||||||
|
'sls' => 'scheme',
|
||||||
|
'sps' => 'scheme',
|
||||||
|
'rs' => 'rust',
|
||||||
|
'st' => 'smalltalk',
|
||||||
|
'tex' => 'stex',
|
||||||
|
'vbs' => 'vbscript',
|
||||||
|
'v' => 'verilog',
|
||||||
|
'xml' => 'xml',
|
||||||
|
'xsd' => 'xml',
|
||||||
|
'xsl' => 'xml',
|
||||||
|
'xul' => 'xml',
|
||||||
|
'xlf' => 'xml',
|
||||||
|
'xliff' => 'xml',
|
||||||
|
'xaml' => 'xml',
|
||||||
|
'wxs' => 'xml',
|
||||||
|
'wxl' => 'xml',
|
||||||
|
'wxi' => 'xml',
|
||||||
|
'wsdl' => 'xml',
|
||||||
|
'svg' => 'xml',
|
||||||
|
'rss' => 'xml',
|
||||||
|
'rdf' => 'xml',
|
||||||
|
'plist' => 'xml',
|
||||||
|
'mxml' => 'xml',
|
||||||
|
'kml' => 'xml',
|
||||||
|
'glade' => 'xml',
|
||||||
|
'xq' => 'xquery',
|
||||||
|
'xqm' => 'xquery',
|
||||||
|
'xquery' => 'xquery',
|
||||||
|
'xqy' => 'xquery',
|
||||||
|
'yml' => 'yaml',
|
||||||
|
'yaml' => 'yaml',
|
||||||
|
'png' => 'image',
|
||||||
|
'jpg' => 'image',
|
||||||
|
'gif' => 'image',
|
||||||
|
'jpeg' => 'image',
|
||||||
|
'bmp' => 'image',
|
||||||
|
);
|
||||||
|
|
||||||
public function __construct(Application $app)
|
public function __construct(Application $app)
|
||||||
{
|
{
|
||||||
$this->app = $app;
|
$this->app = $app;
|
||||||
@@ -46,8 +128,9 @@ class Utils
|
|||||||
* The file type is used by CodeMirror, a Javascript-based IDE implemented in
|
* The file type is used by CodeMirror, a Javascript-based IDE implemented in
|
||||||
* GitList, to properly highlight the blob syntax (if it's a source-code)
|
* GitList, to properly highlight the blob syntax (if it's a source-code)
|
||||||
*
|
*
|
||||||
* @param string $spec File name
|
* @param string $file File name
|
||||||
* @return string File type
|
*
|
||||||
|
* @return null|string File type
|
||||||
*/
|
*/
|
||||||
public function getFileType($file)
|
public function getFileType($file)
|
||||||
{
|
{
|
||||||
@@ -57,174 +140,17 @@ class Utils
|
|||||||
return 'text';
|
return 'text';
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($fileType) {
|
if (isset($this->defaultFileTypes[$fileType])) {
|
||||||
case 'php':
|
return $this->defaultFileTypes[$fileType];
|
||||||
return 'php';
|
|
||||||
case 'c':
|
|
||||||
return 'clike';
|
|
||||||
case 'h':
|
|
||||||
return 'clike';
|
|
||||||
case 'cpp':
|
|
||||||
return 'clike';
|
|
||||||
case 'cs':
|
|
||||||
return 'csharp';
|
|
||||||
case 'm':
|
|
||||||
return 'clike';
|
|
||||||
case 'mm':
|
|
||||||
return 'clike';
|
|
||||||
case 'java':
|
|
||||||
return 'java';
|
|
||||||
case 'clj':
|
|
||||||
return 'clojure';
|
|
||||||
case 'coffee':
|
|
||||||
return 'coffeescript';
|
|
||||||
case 'css':
|
|
||||||
return 'css';
|
|
||||||
case 'diff':
|
|
||||||
return 'diff';
|
|
||||||
case 'ecl':
|
|
||||||
return 'ecl';
|
|
||||||
case 'el':
|
|
||||||
return 'erlang';
|
|
||||||
case 'go':
|
|
||||||
return 'go';
|
|
||||||
case 'groovy':
|
|
||||||
return 'groovy';
|
|
||||||
case 'hs':
|
|
||||||
return 'haskell';
|
|
||||||
case 'lhs':
|
|
||||||
return 'haskell';
|
|
||||||
case 'jsp':
|
|
||||||
return 'htmlembedded';
|
|
||||||
case 'asp':
|
|
||||||
return 'htmlembedded';
|
|
||||||
case 'aspx':
|
|
||||||
return 'htmlembedded';
|
|
||||||
case 'html':
|
|
||||||
return 'htmlmixed';
|
|
||||||
case 'tpl':
|
|
||||||
return 'htmlmixed';
|
|
||||||
case 'js':
|
|
||||||
return 'javascript';
|
|
||||||
case 'json':
|
|
||||||
return 'javascript';
|
|
||||||
case 'less':
|
|
||||||
return 'less';
|
|
||||||
case 'lua':
|
|
||||||
return 'lua';
|
|
||||||
case 'md':
|
|
||||||
return 'markdown';
|
|
||||||
case 'markdown':
|
|
||||||
return 'markdown';
|
|
||||||
case 'sql':
|
|
||||||
return 'mysql';
|
|
||||||
case 'pl':
|
|
||||||
return 'perl';
|
|
||||||
case 'pm':
|
|
||||||
return 'perl';
|
|
||||||
case 'pas':
|
|
||||||
return 'pascal';
|
|
||||||
case 'ini':
|
|
||||||
return 'properties';
|
|
||||||
case 'cfg':
|
|
||||||
return 'properties';
|
|
||||||
case 'nt':
|
|
||||||
return 'ntriples';
|
|
||||||
case 'py':
|
|
||||||
return 'python';
|
|
||||||
case 'rb':
|
|
||||||
return 'ruby';
|
|
||||||
case 'rst':
|
|
||||||
return 'rst';
|
|
||||||
case 'r':
|
|
||||||
return 'r';
|
|
||||||
case 'sh':
|
|
||||||
return 'shell';
|
|
||||||
case 'ss':
|
|
||||||
return 'scheme';
|
|
||||||
case 'scm':
|
|
||||||
return 'scheme';
|
|
||||||
case 'sls':
|
|
||||||
return 'scheme';
|
|
||||||
case 'sps':
|
|
||||||
return 'scheme';
|
|
||||||
case 'rs':
|
|
||||||
return 'rust';
|
|
||||||
case 'st':
|
|
||||||
return 'smalltalk';
|
|
||||||
case 'tex':
|
|
||||||
return 'stex';
|
|
||||||
case 'vbs':
|
|
||||||
return 'vbscript';
|
|
||||||
case 'v':
|
|
||||||
return 'verilog';
|
|
||||||
case 'xml':
|
|
||||||
return 'xml';
|
|
||||||
case 'xsd':
|
|
||||||
return 'xml';
|
|
||||||
case 'xsl':
|
|
||||||
return 'xml';
|
|
||||||
case 'xul':
|
|
||||||
return 'xml';
|
|
||||||
case 'xlf':
|
|
||||||
return 'xml';
|
|
||||||
case 'xliff':
|
|
||||||
return 'xml';
|
|
||||||
case 'xaml':
|
|
||||||
return 'xml';
|
|
||||||
case 'wxs':
|
|
||||||
return 'xml';
|
|
||||||
case 'wxl':
|
|
||||||
return 'xml';
|
|
||||||
case 'wxi':
|
|
||||||
return 'xml';
|
|
||||||
case 'wsdl':
|
|
||||||
return 'xml';
|
|
||||||
case 'svg':
|
|
||||||
return 'xml';
|
|
||||||
case 'rss':
|
|
||||||
return 'xml';
|
|
||||||
case 'rdf':
|
|
||||||
return 'xml';
|
|
||||||
case 'plist':
|
|
||||||
return 'xml';
|
|
||||||
case 'mxml':
|
|
||||||
return 'xml';
|
|
||||||
case 'kml':
|
|
||||||
return 'xml';
|
|
||||||
case 'glade':
|
|
||||||
return 'xml';
|
|
||||||
case 'xq':
|
|
||||||
return 'xquery';
|
|
||||||
case 'xqm':
|
|
||||||
return 'xquery';
|
|
||||||
case 'xquery':
|
|
||||||
return 'xquery';
|
|
||||||
case 'xqy':
|
|
||||||
return 'xquery';
|
|
||||||
case 'yml':
|
|
||||||
return 'yaml';
|
|
||||||
case 'yaml':
|
|
||||||
return 'yaml';
|
|
||||||
case 'png':
|
|
||||||
return 'image';
|
|
||||||
case 'jpg':
|
|
||||||
return 'image';
|
|
||||||
case 'gif':
|
|
||||||
return 'image';
|
|
||||||
case 'jpeg':
|
|
||||||
return 'image';
|
|
||||||
case 'bmp':
|
|
||||||
return 'image';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($this->app['filetypes'])) {
|
if (!empty($this->app['filetypes'])) {
|
||||||
foreach ($this->app['filetypes'] as $ext => $type) {
|
if (isset($this->app['filetypes'][$fileType])) {
|
||||||
if ($fileType == $ext) {
|
return $this->app['filetypes'][$fileType];
|
||||||
return $type;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPager($pageNumber, $totalCommits)
|
public function getPager($pageNumber, $totalCommits)
|
||||||
@@ -251,7 +177,10 @@ class Utils
|
|||||||
|
|
||||||
foreach ($files as $fileInfo)
|
foreach ($files as $fileInfo)
|
||||||
if (preg_match('/^readme*/i', $fileInfo['name'])) {
|
if (preg_match('/^readme*/i', $fileInfo['name'])) {
|
||||||
return array('filename' => $fileInfo['name'], 'content' => $repository->getBlob("$branch:'".$fileInfo['name']."'")->output());
|
return array(
|
||||||
|
'filename' => $fileInfo['name'],
|
||||||
|
'content' => $repository->getBlob("$branch:'".$fileInfo['name']."'")->output()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user