Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/minify/lib/Minify/Lines.php
Go to the documentation of this file.
00001 <?php
00014 class Minify_Lines {
00015 
00037     public static function minify($content, $options = array()) 
00038     {
00039         $id = (isset($options['id']) && $options['id'])
00040             ? $options['id']
00041             : '';
00042         $content = str_replace("\r\n", "\n", $content);
00043         $lines = explode("\n", $content);
00044         $numLines = count($lines);
00045         // determine left padding
00046         $padTo = strlen($numLines);
00047         $inComment = false;
00048         $i = 0;
00049         $newLines = array();
00050         while (null !== ($line = array_shift($lines))) {
00051             if (('' !== $id) && (0 == $i % 50)) {
00052                 array_push($newLines, '', "/* {$id} */", '');
00053             }
00054             ++$i;
00055             $newLines[] = self::_addNote($line, $i, $inComment, $padTo);
00056             $inComment = self::_eolInComment($line, $inComment);
00057         }
00058         $content = implode("\n", $newLines) . "\n";
00059         
00060         // check for desired URI rewriting
00061         if (isset($options['currentDir'])) {
00062             require_once 'Minify/CSS/UriRewriter.php';
00063             Minify_CSS_UriRewriter::$debugText = '';
00064             $content = Minify_CSS_UriRewriter::rewrite(
00065                  $content
00066                 ,$options['currentDir']
00067                 ,isset($options['docRoot']) ? $options['docRoot'] : $_SERVER['DOCUMENT_ROOT']
00068                 ,isset($options['symlinks']) ? $options['symlinks'] : array()
00069             );
00070             $content = "/* Minify_CSS_UriRewriter::\$debugText\n\n" 
00071                      . Minify_CSS_UriRewriter::$debugText . "*/\n"
00072                      . $content;
00073         }
00074         
00075         return $content;
00076     }
00077     
00088     private static function _eolInComment($line, $inComment)
00089     {
00090         while (strlen($line)) {
00091             $search = $inComment
00092                 ? '*/'
00093                 : '/*';
00094             $pos = strpos($line, $search);
00095             if (false === $pos) {
00096                 return $inComment;
00097             } else {
00098                 if ($pos == 0
00099                     || ($inComment
00100                         ? substr($line, $pos, 3)
00101                         : substr($line, $pos-1, 3)) != '*/*')
00102                 {
00103                         $inComment = ! $inComment;
00104                 }
00105                 $line = substr($line, $pos + 2);
00106             }
00107         }
00108         return $inComment;
00109     }
00110     
00125     private static function _addNote($line, $note, $inComment, $padTo)
00126     {
00127         return $inComment
00128             ? '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' *| ' . $line
00129             : '/* ' . str_pad($note, $padTo, ' ', STR_PAD_RIGHT) . ' */ ' . $line;
00130     }
00131 }
 All Data Structures Namespaces Files Functions Variables Enumerations