From: Reini U. <ru...@us...> - 2004-05-14 15:56:27
|
Update of /cvsroot/phpwiki/phpwiki/lib/plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29511/lib/plugin Modified Files: SyntaxHighlighter.php Log Message: protect color argument, more error handling, added default css Index: SyntaxHighlighter.php =================================================================== RCS file: /cvsroot/phpwiki/phpwiki/lib/plugin/SyntaxHighlighter.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -2 -b -p -d -r1.1 -r1.2 --- SyntaxHighlighter.php 14 May 2004 14:55:52 -0000 1.1 +++ SyntaxHighlighter.php 14 May 2004 15:56:16 -0000 1.2 @@ -30,5 +30,5 @@ rcs_id('$Id$'); * style = ["ansi", "gnu", "kr", "java", "linux"] -<?plugin SyntaxHighlighter syntax=c style=kr +<?plugin SyntaxHighlighter syntax=c style=kr color=emacs #include <stdio.h> @@ -52,4 +52,6 @@ define('HIGHLIGHT_EXE','highlight'); // highlight requires two subdirs themes and langDefs somewhere. +// Best by highlight.conf in $HOME, but the webserver user usually +// doesn't have a $HOME if (isWindows()) define('HIGHLIGHT_DATA_DIR','f:\cygnus\usr\local\share\highlight'); @@ -75,7 +77,7 @@ extends WikiPlugin function getDefaultArguments() { return array( - 'syntax' => null, - 'style' => null, - 'color' => null, + 'syntax' => null, // required argument + 'style' => null, // optional argument ["ansi", "gnu", "kr", "java", "linux"] + 'color' => null, // optional, see highlight/themes 'number' => 0, 'wrap' => 0, @@ -153,5 +155,10 @@ extends WikiPlugin if ($number != 0) $args .= " -l"; if ($wrap != 0) $args .= " -V"; - if (!empty($color)) $args .= " --style $color -c ".FindFile("uploads")."/highlight.css"; + $html = HTML(); + if (!empty($color) and !preg_match('/^[\w-]+$/',$color)) { + $html->pushContent($this->error(fmt("invalid %s ignored",'color'))); + $color = false; + } + if (!empty($color)) $args .= " --style $color -c ".FindFile("uploads")."/highlight-$color.css"; if (!empty($style)) $args .= " -F $style"; $commandLine = HIGHLIGHT_EXE . "$args -q -X -f -S $syntax"; @@ -162,12 +169,11 @@ extends WikiPlugin if (empty($code)) return $this->error(fmt("Couldn't start commandline '%s'",$commandLine)); - $html = HTML::pre(HTML::raw($code)); - - global $Theme; - $html->setAttr('class','tightenable top bottom'); - $css = $Theme->_CSSlink('',empty($color) ? 'highlight.css' : 'uploads/highlight.css',''); + $pre = HTML::pre(HTML::raw($code)); + $pre->setAttr('class','tightenable top bottom'); + $html->pushContent($pre); + $css = $GLOBALS['Theme']->_CSSlink('',empty($color) ? 'highlight.css' : "uploads/highlight-$color.css",''); return HTML($css,$html); } else { - return $this->error(_("empty source")); + return $this->error(fmt("empty source")); } } @@ -175,4 +181,7 @@ extends WikiPlugin // $Log$ +// Revision 1.2 2004/05/14 15:56:16 rurban +// protect color argument, more error handling, added default css +// // Revision 1.1 2004/05/14 14:55:52 rurban // Alec Thomas original plugin, which comes with highlight http://www.andre-simon.de/, |