diff options
-rw-r--r-- | application/models/file_mod.php | 14 | ||||
-rwxr-xr-x | scripts/ansi2html | 20 |
2 files changed, 30 insertions, 4 deletions
diff --git a/application/models/file_mod.php b/application/models/file_mod.php index 2ba44f551..a1ad73b92 100644 --- a/application/models/file_mod.php +++ b/application/models/file_mod.php @@ -247,12 +247,14 @@ class File_mod extends CI_Model { exit(); } + + $special_modes = array("ascii"); // directly download the file - if (!$mode // user didn't specify a mode/didn't enable autodetection + if (!in_array($mode, $special_modes) && (!$mode // user didn't specify a mode/didn't enable autodetection || !$this->mime2extension($type) // file can't be highlighted || $mode == "plain" // user wants to the the plain file || filesize($file) > $this->config->item('upload_max_text_size') - ) { + )) { if ($mode == 'plain') { $type = "text/plain"; } @@ -283,8 +285,12 @@ class File_mod extends CI_Model { if (! $cached = $this->memcachelibrary->get($filedata['hash'].'_'.$mode)) { ob_start(); if ($mode == "rmd") { - echo '<td class="markdownrender">'."\n"; - passthru('/usr/bin/perl /usr/bin/perlbin/vendor/Markdown.pl '.escapeshellarg($file)); + echo '<td class="markdownrender">'."\n"; + passthru('/usr/bin/perl /usr/bin/vendor_perl/vendor/Markdown.pl '.escapeshellarg($file)); + } elseif ($mode == "ascii") { + echo '<td class="code"><pre class="text">'."\n"; + passthru('/usr/bin/perl '.FCPATH.'scripts/ansi2html '.escapeshellarg($file)); + echo "</pre>\n"; } else { echo '<td class="numbers"><pre>'; // generate line numbers (links) diff --git a/scripts/ansi2html b/scripts/ansi2html new file mode 100755 index 000000000..e33e24630 --- /dev/null +++ b/scripts/ansi2html @@ -0,0 +1,20 @@ +#!/usr/bin/perl +use strict; +use HTML::FromANSI (); + +my $h = HTML::FromANSI->new( + fill_cols => 0, + font_face => "", + style => "", + tt => 0 +); + +open IN, "<", $ARGV[0] or die "cannot read $ARGV[0]: $!"; + +$h->add_text(<IN>); +my $html = $h->html; +$html =~ s/background: black; //g; +$html =~ s/color: white; /color: black /g; +$html =~ s/<br>/\n/g; + +print $html; |