diff options
| author | Michael Save <savetheinternet@tinyboard.org> | 2012-03-14 21:44:41 +1100 |
|---|---|---|
| committer | Michael Save <savetheinternet@tinyboard.org> | 2012-03-14 21:48:31 +1100 |
| commit | 2a760de2896a02af98caa013537166b5d3fcc717 (patch) | |
| tree | 1fccf2193f881239a0424fdd5fdb67f9e320a033 /inc/contrib/minify/Minify/CommentPreserver.php | |
| parent | 60aab92f47e651b214f0b993aab03d08e033134e (diff) | |
Multiple changes.
Added $config['minify_js'] to compress Javascript with minify
Added $config['additional_javascript_compile'] to put all Javascript files/addons into one file.
Moved delete/report post controls to a shared template.
Ability to have different Javascript files between boards.
Diffstat (limited to 'inc/contrib/minify/Minify/CommentPreserver.php')
| -rwxr-xr-x | inc/contrib/minify/Minify/CommentPreserver.php | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/inc/contrib/minify/Minify/CommentPreserver.php b/inc/contrib/minify/Minify/CommentPreserver.php new file mode 100755 index 00000000..7a359bf9 --- /dev/null +++ b/inc/contrib/minify/Minify/CommentPreserver.php @@ -0,0 +1,89 @@ +<?php +/** + * Class Minify_CommentPreserver + * @package Minify + */ + +/** + * Process a string in pieces preserving C-style comments that begin with "/*!" + * + * @package Minify + * @author Stephen Clay <steve@mrclay.org> + */ +class Minify_CommentPreserver { + + /** + * String to be prepended to each preserved comment + * + * @var string + */ + public static $prepend = "\n"; + + /** + * String to be appended to each preserved comment + * + * @var string + */ + public static $append = "\n"; + + /** + * Process a string outside of C-style comments that begin with "/*!" + * + * On each non-empty string outside these comments, the given processor + * function will be called. The comments will be surrounded by + * Minify_CommentPreserver::$preprend and Minify_CommentPreserver::$append. + * + * @param string $content + * @param callback $processor function + * @param array $args array of extra arguments to pass to the processor + * function (default = array()) + * @return string + */ + public static function process($content, $processor, $args = array()) + { + $ret = ''; + while (true) { + list($beforeComment, $comment, $afterComment) = self::_nextComment($content); + if ('' !== $beforeComment) { + $callArgs = $args; + array_unshift($callArgs, $beforeComment); + $ret .= call_user_func_array($processor, $callArgs); + } + if (false === $comment) { + break; + } + $ret .= $comment; + $content = $afterComment; + } + return $ret; + } + + /** + * Extract comments that YUI Compressor preserves. + * + * @param string $in input + * + * @return array 3 elements are returned. If a YUI comment is found, the + * 2nd element is the comment and the 1st and 3rd are the surrounding + * strings. If no comment is found, the entire string is returned as the + * 1st element and the other two are false. + */ + private static function _nextComment($in) + { + if ( + false === ($start = strpos($in, '/*!')) + || false === ($end = strpos($in, '*/', $start + 3)) + ) { + return array($in, false, false); + } + $ret = array( + substr($in, 0, $start) + ,self::$prepend . '/*!' . substr($in, $start + 3, $end - $start - 1) . self::$append + ); + $endChars = (strlen($in) - $end - 2); + $ret[] = (0 === $endChars) + ? '' + : substr($in, -$endChars); + return $ret; + } +} |
