From 73d6d76ec4d1c8bc9fce9ba1a1dcf8fa6735f621 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Sat, 22 Jun 2013 18:34:24 +0200 Subject: mfile: extension -> lexer mapping; mark some functions public Also assure that autodetect_lexer always returns false if the file can't be highlit. Signed-off-by: Florian Pritz --- application/models/mfile.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'application/models') diff --git a/application/models/mfile.php b/application/models/mfile.php index 27f05e46b..0a97da5a6 100644 --- a/application/models/mfile.php +++ b/application/models/mfile.php @@ -244,7 +244,7 @@ class Mfile extends CI_Model { return $lexers; } - function should_highlight($type) + public function should_highlight($type) { if ($this->mime2lexer($type)) return true; @@ -252,7 +252,7 @@ class Mfile extends CI_Model { } // Allow certain types to be highlight without doing it automatically - function can_highlight($type) + public function can_highlight($type) { $typearray = array( 'image/svg+xml', @@ -265,8 +265,12 @@ class Mfile extends CI_Model { } // Return the lexer that should be used for highlighting - function autodetect_lexer($type, $filename) + public function autodetect_lexer($type, $filename) { + if (!$this->can_highlight($type)) { + return false; + } + $lexer = $this->mime2lexer($type); // filename lexers overwrite mime type mappings @@ -351,11 +355,23 @@ class Mfile extends CI_Model { ); if (array_key_exists($name, $namearray)) return $namearray[$name]; + + if (strpos($name, ".") !== false) { + $extension = substr($name, strrpos($name, ".") + 1); + + $extensionarray = array( + 'ml' => 'ocaml', + 'tcl' => 'tcl', + 'tex' => 'tex', + ); + if (array_key_exists($extension, $extensionarray)) return $extensionarray[$extension]; + } + return false; } // Handle lexer aliases - function resolve_lexer_alias($alias) + public function resolve_lexer_alias($alias) { if ($alias === false) return false; $aliasarray = array( -- cgit v1.2.3-24-g4f1b