Show
Ignore:
Timestamp:
01/21/2008 06:56:39 AM (10 months ago)
Author:
Geert
Message:

Cleaning up tons of whitespace:

  • Use tabs for indenting
  • Use spaces for aligning
  • Avoid whitespace at the end of a line
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/media/libraries/JavaScriptPacker.php

    r1641 r1766  
    7373        private $_fastDecode = true; 
    7474        private $_specialChars = false; 
    75          
     75 
    7676        private $LITERAL_ENCODING = array( 
    7777                'None' => 0, 
     
    8080                'High ASCII' => 95 
    8181        ); 
    82          
     82 
    8383        public function __construct($_script, $_encoding = 62, $_fastDecode = true, $_specialChars = false) 
    8484        { 
     
    9090                $this->_specialChars = $_specialChars; 
    9191        } 
    92          
     92 
    9393        public function pack() { 
    9494                $this->_addParser('_basicCompression'); 
     
    9797                if ($this->_encoding) 
    9898                        $this->_addParser('_encodeKeywords'); 
    99                  
     99 
    100100                // go! 
    101101                return $this->_pack($this->_script); 
    102102        } 
    103          
     103 
    104104        // apply all parsing routines 
    105105        private function _pack($script) { 
     
    109109                return $script; 
    110110        } 
    111          
     111 
    112112        // keep a list of parsing functions, they'll be executed all at once 
    113113        private $_parsers = array(); 
     
    115115                $this->_parsers[] = $parser; 
    116116        } 
    117          
     117 
    118118        // zero encoding - just removal of white space and comments 
    119119        private function _basicCompression($script) { 
     
    145145                return $parser->exec($script); 
    146146        } 
    147          
     147 
    148148        private function _encodeSpecialChars($script) { 
    149149                $parser = new ParseMaster(); 
     
    158158                // quick ref 
    159159                $encoded = $keywords['encoded']; 
    160                  
     160 
    161161                $parser->add($regexp, 
    162162                        array( 
     
    167167                return $parser->exec($script); 
    168168        } 
    169          
     169 
    170170        private function _encodeKeywords($script) { 
    171171                // escape high-ascii values already in the script (i.e. in strings) 
     
    180180                $keywords = $this->_analyze($script, $regexp, $encode); 
    181181                $encoded = $keywords['encoded']; 
    182                  
     182 
    183183                // encode 
    184184                $parser->add($regexp, 
     
    196196                } 
    197197        } 
    198          
     198 
    199199        private function _analyze($script, $regexp, $encode) { 
    200200                // analyse 
     
    243243                                } 
    244244                        } while ($i); 
    245                          
     245 
    246246                        // sort the words by frequency 
    247247                        // Note: the javascript and php version of sort can be different : 
     
    269269                        'protected' => $_protected); 
    270270        } 
    271          
     271 
    272272        private $_count = array(); 
    273273        private function _sortWords($match1, $match2) { 
    274274                return $this->_count[$match2] - $this->_count[$match1]; 
    275275        } 
    276          
     276 
    277277        // build the boot function used for loading and decoding 
    278278        private function _bootStrap($packed, $keywords) { 
     
    341341                $unpackPacker = new JavaScriptPacker($unpack, 0, false, true); 
    342342                $unpack = $unpackPacker->pack(); 
    343                  
     343 
    344344                // arguments 
    345345                $params = array($packed, $ascii, $count, $keywords); 
     
    349349                } 
    350350                $params = implode(',', $params); 
    351                  
     351 
    352352                // the whole thing 
    353353                return 'eval(' . $unpack . '(' . $params . "))\n"; 
    354354        } 
    355          
     355 
    356356        private $buffer; 
    357357        private function _insertFastDecode($match) { 
     
    361361                return '{$encode=' . $this->buffer . ';'; 
    362362        } 
    363          
     363 
    364364        // mmm.. ..which one do i need ?? 
    365365        private function _getEncoder($ascii) { 
     
    367367                       '_encode95' : '_encode62' : '_encode36' : '_encode10'; 
    368368        } 
    369          
     369 
    370370        // zero encoding 
    371371        // characters: 0123456789 
     
    373373                return $charCode; 
    374374        } 
    375          
     375 
    376376        // inherent base36 support 
    377377        // characters: 0123456789abcdefghijklmnopqrstuvwxyz 
     
    379379                return base_convert($charCode, 10, 36); 
    380380        } 
    381          
     381 
    382382        // hitch a ride on base36 and add the upper case alpha characters 
    383383        // characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 
     
    388388                } 
    389389                $charCode = $charCode % $this->_encoding; 
    390                  
     390 
    391391                if ($charCode > 35) 
    392392                        return $res . chr($charCode + 29); 
     
    394394                        return $res . base_convert($charCode, 10, 36); 
    395395        } 
    396          
     396 
    397397        // use high-ascii values 
    398398        // characters: ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ 
     
    401401                if ($charCode >= $this->_encoding) 
    402402                        $res = $this->_encode95($charCode / $this->_encoding); 
    403                  
     403 
    404404                return $res . chr(($charCode % $this->_encoding) + 161); 
    405405        } 
    406          
     406 
    407407        private function _safeRegExp($string) { 
    408408                return '/'.preg_replace('/\$/', '\\\$', $string).'/'; 
    409409        } 
    410          
     410 
    411411        private function _encodePrivate($charCode) { 
    412412                return "_" . $charCode; 
    413413        } 
    414          
     414 
    415415        // protect characters used by the parser 
    416416        private function _escape($script) { 
    417417                return preg_replace('/([\\\\\'])/', '\\\$1', $script); 
    418418        } 
    419          
     419 
    420420        // protect high-ascii characters already in the script 
    421421        private function _escape95($script) { 
     
    429429                return '\x'.((string)dechex(ord($match))); 
    430430        } 
    431          
    432          
     431 
     432 
    433433        private function _getJSFunction($aName) { 
    434434                if (defined('self::JSFUNCTION'.$aName)) 
     
    437437                        return ''; 
    438438        } 
    439          
     439 
    440440        // JavaScript Functions used. 
    441441        // Note : In Dean's version, these functions are converted 
     
    445445        // 'while (aBool) { anAction(); }'. 
    446446        // The JavaScript functions below are corrected. 
    447          
     447 
    448448        // unpacking function - this is the boot strap function 
    449449        //  data extracted from this packing routine is passed to 
     
    468468}'; 
    469469*/ 
    470          
     470 
    471471        // code-snippet inserted into the unpacker to speed up decoding 
    472472        const JSFUNCTION_decodeBody = 
     
    501501    }'; 
    502502*/ 
    503          
     503 
    504504         // zero encoding 
    505505         // characters: 0123456789 
     
    508508    return $charCode; 
    509509}';//;'; 
    510          
     510 
    511511         // inherent base36 support 
    512512         // characters: 0123456789abcdefghijklmnopqrstuvwxyz 
     
    515515    return $charCode.toString(36); 
    516516}';//;'; 
    517          
     517 
    518518        // hitch a ride on base36 and add the upper case alpha characters 
    519519        // characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 
     
    523523    (($charCode = $charCode % _encoding) > 35 ? String.fromCharCode($charCode + 29) : $charCode.toString(36)); 
    524524}'; 
    525          
     525 
    526526        // use high-ascii values 
    527527        // characters: ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþ 
     
    531531        String.fromCharCode($charCode % _encoding + 161); 
    532532}';  
    533          
     533 
    534534} 
    535535 
     
    538538        public $ignoreCase = false; 
    539539        public $escapeChar = ''; 
    540          
     540 
    541541        // constants 
    542542        const EXPRESSION = 0; 
    543543        const REPLACEMENT = 1; 
    544544        const LENGTH = 2; 
    545          
     545 
    546546        // used to determine nesting levels 
    547547        private $GROUPS = '/\\(/';//g 
     
    552552        private $QUOTE = '/\'/'; 
    553553        private $DELETED = '/\\x01[^\\x01]*\\x01/';//g 
    554          
     554 
    555555        public function add($expression, $replacement = '') { 
    556556                // count the number of sub-expressions 
    557557                //  - add one because each pattern is itself a sub-expression 
    558558                $length = 1 + preg_match_all($this->GROUPS, $this->_internalEscape((string)$expression), $out); 
    559                  
     559 
    560560                // treat only strings $replacement 
    561561                if (is_string($replacement)) { 
     
    585585                else $this->_add('/^$/', $replacement, $length); 
    586586        } 
    587          
     587 
    588588        public function exec($string) { 
    589589                // execute the global replacement 
    590590                $this->_escaped = array(); 
    591                  
     591 
    592592                // simulate the _patterns.toSTring of Dean 
    593593                $regexp = '/'; 
     
    597597                $regexp = substr($regexp, 0, -1) . '/'; 
    598598                $regexp .= ($this->ignoreCase) ? 'i' : ''; 
    599                  
     599 
    600600                $string = $this->_escape($string, $this->escapeChar); 
    601601                $string = preg_replace_callback( 
     
    608608                ); 
    609609                $string = $this->_unescape($string, $this->escapeChar); 
    610                  
     610 
    611611                return preg_replace($this->DELETED, '', $string); 
    612612        } 
    613                  
     613 
    614614        public function reset() { 
    615615                // clear the patterns collection so that this object may be re-used 
     
    620620        private $_escaped = array();  // escaped characters 
    621621        private $_patterns = array(); // patterns stored by index 
    622          
     622 
    623623        // create and add a new pattern to the patterns collection 
    624624        private function _add() { 
     
    626626                $this->_patterns[] = $arguments; 
    627627        } 
    628          
     628 
    629629        // this is the global replace function (it's quite complicated) 
    630630        private function _replacement($arguments) { 
    631631                if (empty($arguments)) return ''; 
    632                  
     632 
    633633                $i = 1; $j = 0; 
    634634                // loop through the patterns 
     
    638638                        if (isset($arguments[$i]) && ($arguments[$i] != '')) { 
    639639                                $replacement = $pattern[self::REPLACEMENT]; 
    640                                  
     640 
    641641                                if (is_array($replacement) && isset($replacement['fn'])) { 
    642                                          
     642 
    643643                                        if (isset($replacement['data'])) $this->buffer = $replacement['data']; 
    644644                                        return call_user_func(array(&$this, $replacement['fn']), $arguments, $i); 
    645                                          
     645 
    646646                                } elseif (is_int($replacement)) { 
    647647                                        return $arguments[$replacement + $i]; 
    648                                  
     648 
    649649                                } 
    650650                                $delete = ($this->escapeChar == '' || 
     
    652652                                        ? '' : "\x01" . $arguments[$i] . "\x01"; 
    653653                                return $delete . $replacement; 
    654                          
     654 
    655655                        // skip over references to sub-expressions 
    656656                        } else { 
     
    659659                } 
    660660        } 
    661          
     661 
    662662        private function _backReferences($match, $offset) { 
    663663                $replacement = $this->buffer['replacement']; 
     
    669669                return $replacement; 
    670670        } 
    671          
     671 
    672672        private function _replace_name($match, $offset){ 
    673673                $length = strlen($match[$offset + 2]); 
     
    675675                return substr($match[$offset + 1], $start, $length) . $match[$offset + 4]; 
    676676        } 
    677          
     677 
    678678        private function _replace_encoded($match, $offset) { 
    679679                return $this->buffer[$match[$offset]]; 
    680680        } 
    681          
    682          
     681 
     682 
    683683        // php : we cannot pass additional data to preg_replace_callback, 
    684684        // and we cannot use &$this in create_function, so let's go to lower level 
    685685        private $buffer; 
    686          
     686 
    687687        // encode escaped characters 
    688688        private function _escape($string, $escapeChar) { 
     
    694694                                $string 
    695695                        ); 
    696                          
     696 
    697697                } else { 
    698698                        return $string; 
     
    703703                return $this->buffer; 
    704704        } 
    705          
     705 
    706706        // decode escaped characters 
    707707        private function _unescape($string, $escapeChar) { 
     
    715715                                $string 
    716716                        ); 
    717                          
     717 
    718718                } else { 
    719719                        return $string; 
     
    729729                return $this->buffer['escapeChar'] . $temp; 
    730730        } 
    731          
     731 
    732732        private function _internalEscape($string) { 
    733733                return preg_replace($this->ESCAPE, '', $string);