From bf061651c165f73b275bfef778471837307239fd Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 16 Aug 2010 15:35:19 +0200 Subject: use pygmentize for txt too fixes issues with HTML pastes Signed-off-by: Florian Pritz --- system/application/models/file_mod.php | 38 ++++++++++++++-------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'system') diff --git a/system/application/models/file_mod.php b/system/application/models/file_mod.php index 0acf52ccf..cd45f335c 100644 --- a/system/application/models/file_mod.php +++ b/system/application/models/file_mod.php @@ -198,23 +198,15 @@ class File_mod extends Model { // count(file($file)); isn't passthru('/usr/bin/perl -ne \'print "$.\n"\' '.escapeshellarg($file)); echo '
'."\n";
-            if ($mode == 'txt') {
-              $fp = fopen($file,"r");
-              while (!feof($fp)) {
-                echo fread($fp,4096);
-              }
-              fclose($fp);
-            } else {
-              $this->load->library("MemcacheLibrary");
-              if (! $cached = $this->memcachelibrary->get($filedata['hash'].'_'.$mode)) {
-                ob_start();
-                passthru('/usr/bin/pygmentize -l '.$mode.' -f html '.escapeshellarg($file));
-                $cached = ob_get_contents();
-                ob_end_clean();
-                $this->memcachelibrary->set($filedata['hash'].'_'.$mode, $cached, 100);
-              }
-              echo $cached;
+            $this->load->library("MemcacheLibrary");
+            if (! $cached = $this->memcachelibrary->get($filedata['hash'].'_'.$mode)) {
+              ob_start();
+              passthru('/usr/bin/pygmentize -l '.$mode.' -f html '.escapeshellarg($file));
+              $cached = ob_get_contents();
+              ob_end_clean();
+              $this->memcachelibrary->set($filedata['hash'].'_'.$mode, $cached, 100);
             }
+            echo $cached;
             echo '
'; } echo $this->load->view('file/html_footer', $data, true); @@ -317,7 +309,7 @@ class File_mod extends Model { function mime2extension($type) { $typearray = array( - 'text/plain' => 'txt', + 'text/plain' => 'text', 'text/x-python' => 'py', 'text/x-csrc' => 'c', 'text/x-chdr' => 'h', @@ -333,24 +325,24 @@ class File_mod extends Model { #'text/x-log' => 'log', 'text/html' => 'html', 'text/css' => 'css', - 'message/rfc822' => 'txt', + 'message/rfc822' => 'text', #'image/svg+xml' => 'xml', 'application/x-perl' => 'pl', 'application/xml' => 'xml', 'application/javascript' => 'js', - 'application/x-desktop' => 'txt', - 'application/x-m4' => 'txt', + 'application/x-desktop' => 'text', + 'application/x-m4' => 'text', 'application/x-awk' => 'awk', 'application/x-java' => 'java', 'application/x-php' => 'php', 'application/x-ruby' => 'rb', 'application/x-shellscript' => 'sh', - 'application/x-x509-ca-cert' => 'txt', - 'application/mbox' => 'txt' + 'application/x-x509-ca-cert' => 'text', + 'application/mbox' => 'text' ); if (array_key_exists($type, $typearray)) return $typearray[$type]; - if (strpos($type, 'text/') === 0) return 'txt'; + if (strpos($type, 'text/') === 0) return 'text'; # default return false; -- cgit v1.2.3-24-g4f1b