diff options
author | Florian Pritz <bluewind@xinu.at> | 2011-12-17 23:18:18 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2011-12-17 23:18:18 +0100 |
commit | 1104ea8fea5098ff0ef5e6388d5fdf353784f679 (patch) | |
tree | 6e247c3b1f29d07dc3385728143018b74bff8f67 | |
parent | fa869698c592c9d7d0f33b64c8fba409ebf5d75f (diff) |
use perl from PATH and copy markdown.pl to scripts/
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | application/controllers/file.php | 3 | ||||
-rw-r--r-- | application/models/file_mod.php | 11 | ||||
-rwxr-xr-x | scripts/Markdown.pl | 147 |
3 files changed, 155 insertions, 6 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php index 470383504..de2ce314b 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -18,6 +18,9 @@ class File extends CI_Controller { show_error($this->migration->error_string()); } + $old_path = getenv("PATH"); + putenv("PATH=$old_path:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"); + mb_internal_encoding('UTF-8'); $this->load->helper(array('form', 'filebin')); $this->load->model('file_mod'); diff --git a/application/models/file_mod.php b/application/models/file_mod.php index f6ad6d8f4..f2a1b21f6 100644 --- a/application/models/file_mod.php +++ b/application/models/file_mod.php @@ -12,7 +12,6 @@ class File_mod extends CI_Model { function __construct() { parent::__construct(); - putenv("PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"); } // Returns an unused ID @@ -96,7 +95,7 @@ class File_mod extends CI_Model { // TODO: Should only update not insert; see new_id() function add_file($hash, $id, $filename) { - $mimetype = exec("/usr/bin/perl ".FCPATH.'scripts/mimetype '.escapeshellarg($filename).' '.escapeshellarg($this->file($hash))); + $mimetype = exec("perl ".FCPATH.'scripts/mimetype '.escapeshellarg($filename).' '.escapeshellarg($this->file($hash))); $query = $this->db->query(' INSERT INTO `files` (`hash`, `id`, `filename`, `password`, `date`, `mimetype`) VALUES (?, ?, ?, ?, ?, ?)', @@ -246,7 +245,7 @@ class File_mod extends CI_Model { if ($mode == "qr") { header("Content-disposition: inline; filename=\"".$id."_qr.png\"\n"); header("Content-Type: image/png\n"); - passthru('/usr/bin/qrencode -s 10 -o - '.escapeshellarg(site_url($id).'/')); + passthru('qrencode -s 10 -o - '.escapeshellarg(site_url($id).'/')); exit(); } @@ -291,15 +290,15 @@ class File_mod extends CI_Model { ob_start(); if ($mode == "rmd") { echo '<td class="markdownrender">'."\n"; - passthru('/usr/bin/perl /usr/bin/vendor_perl/Markdown.pl '.escapeshellarg($file)); + passthru('perl '.FCPATH.'scripts/Markdown.pl '.escapeshellarg($file)); } elseif ($mode == "ascii") { echo '<td class="code"><pre class="text">'."\n"; - passthru('/usr/bin/perl '.FCPATH.'scripts/ansi2html '.escapeshellarg($file)); + passthru('perl '.FCPATH.'scripts/ansi2html '.escapeshellarg($file)); echo "</pre>\n"; } else { echo '<td class="numbers"><pre>'; // generate line numbers (links) - passthru('/usr/bin/perl -ne \'print "<a href=\"#n$.\" class=\"no\" id=\"n$.\">$.</a>\n"\' '.escapeshellarg($file)); + passthru('perl -ne \'print "<a href=\"#n$.\" class=\"no\" id=\"n$.\">$.</a>\n"\' '.escapeshellarg($file)); echo '</pre></td><td class="code">'."\n"; $this->load->library('geshi'); $this->geshi->initialize(array('set_language' => $mode, 'set_source' => file_get_contents($file), 'enable_classes' => 'true')); diff --git a/scripts/Markdown.pl b/scripts/Markdown.pl new file mode 100755 index 000000000..169b15fed --- /dev/null +++ b/scripts/Markdown.pl @@ -0,0 +1,147 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Text::Markdown qw(markdown); + +=head1 NAME + +Markdown.pl - Convert Markdown syntax to (X)HTML + +=head1 DESCRIPTION + +This program is distributed as part of Perl's Text::Markdown module, +illustrating sample usage. + +Markdown can be invoked on any file containing Markdown-syntax, and +will produce the corresponding (X)HTML on STDOUT: + + $ cat file.txt + This is a *test*. + + Absolutely _nothing_ to see here. _Just a **test**_! + + * test + * Yup, test. + $ Markdown.pl file.txt + <p>This is a <em>test</em>.</p> + + <p>Absolutely <em>nothing</em> to see here. <em>Just a <strong>test</strong></em>!</p> + + <ul> + <li>test</li> + <li>Yup, test.</li> + </ul> + +If no file is specified, it will expect its input from STDIN: + + $ echo "A **simple** test" | markdown + <p>A <strong>simple</strong> test</p> + +=head1 OPTIONS + +=over + +=item version + +Shows the full information for this version + +=item shortversion + +Shows only the version number + +=item html4tags + +Produce HTML 4-style tags instead of XHTML - XHTML requires elements +that do not wrap a block (i.e. the C<hr> tag) to state they will not +be closed, by closing with C</E<gt>>. HTML 4-style will plainly output +the tag as it comes: + + $ echo '---' | markdown + <hr /> + $ echo '---' | markdown --html4tags + <hr> + +=item help + +Shows this documentation + +=back + +=head1 AUTHOR + +Copyright 2004 John Gruber + +Copyright 2008 Tomas Doran + +The manpage was written by Gunnar Wolf <gwolf@debian.org> for its use +in Debian systems, but can be freely used elsewhere. + +For full licensing information, please refer to +L<Text::Markdown.pm>'s full documentation. + +=head1 SEE ALSO + +L<Text::Markdown>, L<http://daringfireball.net/projects/markdown/> + +=cut + +#### Check for command-line switches: ################# +my %cli_opts; +use Getopt::Long; +Getopt::Long::Configure('pass_through'); +GetOptions(\%cli_opts, + 'version', + 'shortversion', + 'html4tags', + 'help', +); +if ($cli_opts{'version'}) { # Version info + print "\nThis is Markdown, version $Text::Markdown::VERSION.\n"; + print "Copyright 2004 John Gruber\n"; + print "Copyright 2008 Tomas Doran\n"; + print "Parts contributed by several other people."; + print "http://daringfireball.net/projects/markdown/\n\n"; + exit 0; +} +if ($cli_opts{'shortversion'}) { # Just the version number string. + print $Text::Markdown::VERSION; + exit 0; +} +if ($cli_opts{'help'}) { + for my $dir (split m/:/, $ENV{PATH}) { + my $cmd = "$dir/perldoc"; + exec($cmd, $0) if (-f $cmd and -x $cmd); + } + die "perldoc could not be found in your path - Cannot show help, sorry\n"; +} +my $m; +if ($cli_opts{'html4tags'}) { # Use HTML tag style instead of XHTML + $m = Text::Markdown->new(empty_element_suffix => '>'); +} +else { + $m = Text::Markdown->new; +} + +sub main { + my (@fns) = @_; + + my $f; + if (scalar @fns) { + foreach my $fn (@fns) { + die("Cannot find file $fn") unless (-r $fn); + + my $fh; + open($fh, '<', $fn) or die; + $f = join('', <$fh>); + close($fh) or die; + } + } + else { # STDIN + local $/; # Slurp the whole file + $f = <>; + } + + return $m->markdown($f); +} + +print main(@ARGV) unless caller(); |