Changeset 1667


Ignore:
Timestamp:
11/18/09 14:32:20 (14 years ago)
Author:
alexandrecorreia
Message:

Ticket #764 - Corrigo caminho absoluto para relativo .

Location:
trunk/jabberit_messenger/inc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/jabberit_messenger/inc/Controller.class.php

    r459 r1667  
    175175                $result = $method->invoke($obj, $pRequest); 
    176176 
    177                 #$obj = new $class; 
    178  
    179                 #if ( $pRequest ) 
    180                 #       $result = $obj -> $method($pRequest); 
    181                 #else 
    182                 #       $result = $obj -> $method(); 
    183  
    184177                return $result; 
    185178        } 
     
    199192 
    200193                $debug = $pSectionItem->parentNode->getAttribute('debug'); 
    201                 if ( $debug && ($debug === 'true') ) 
    202                         return file_get_contents($file); 
    203  
    204                 $packed_file = "{$pPath}/.packer.{$pPrefix}{$js}{$pSuffix}"; 
    205  
    206                 ( 
    207                         file_exists($packed_file) 
    208                         and filemtime($packed_file) > filemtime($file) 
    209                         and $packed = file_get_contents($packed_file) 
    210                 ) 
    211                 or 
    212                 ( 
    213                         $packer = new JavaScriptPacker(file_get_contents($file), 'High ASCII', true, true) 
    214                         and $packed = $packer->pack() 
    215                         and file_put_contents($packed_file, $packed) 
    216                 ); 
    217  
    218                 return $packed; 
     194                 
     195                return file_get_contents($file); 
     196 
    219197        } 
    220198} 
    221199 
    222 class JavaScriptPacker 
    223 { 
    224         const IGNORE = '$1'; 
    225  
    226         private $_script = ''; 
    227         private $_encoding = 62; 
    228         private $_fastDecode = true; 
    229         private $_specialChars = false; 
    230  
    231         private $_parsers = array(); 
    232  
    233         private $LITERAL_ENCODING = array( 
    234                 'None' => 0, 
    235                 'Numeric' => 10, 
    236                 'Normal' => 62, 
    237                 'High ASCII' => 95 
    238         ); 
    239  
    240         public function __construct ($pScript, $pEncoding = 62, $pFastDecode = true, $pSpecialChars = false) 
    241         { 
    242                 $this->_script = $pScript . "\n"; 
    243                 if ( array_key_exists($pEncoding, $this->LITERAL_ENCODING) ) 
    244                         $pEncoding = $this->LITERAL_ENCODING[$pEncoding]; 
    245  
    246                 $this->_encoding = min((int)$pEncoding, 95); 
    247                 $this->_fastDecode = $pFastDecode; 
    248                 $this->_specialChars = $pSpecialChars; 
    249         } 
    250  
    251         public function pack() 
    252         { 
    253                 $this->_addParser('_basicCompression'); 
    254  
    255                 if ( $this->_specialChars ) 
    256                         $this->_addParser('_encodeSpecialChars'); 
    257  
    258                 if ( $this->_encoding ) 
    259                         $this->_addParser('_encodeKeywords'); 
    260  
    261                 return $this->_pack($this->_script); 
    262         } 
    263  
    264         private function _pack($script) 
    265         { 
    266                 for ( $i = 0; isset($this->_parsers[$i]); $i++ ) 
    267                         $script = call_user_func(array(&$this,$this->_parsers[$i]), $script); 
    268  
    269                 return $script; 
    270         } 
    271  
    272         // keep a list of parsing functions, they'll be executed all at once 
    273         private function _addParser($parser) 
    274         { 
    275                 $this->_parsers[] = $parser; 
    276         } 
    277  
    278         // zero encoding - just removal of white space and comments 
    279         private function _basicCompression($script) 
    280         { 
    281                 $parser = new ParseMaster(); 
    282                 // make safe 
    283                 $parser->escapeChar = '\\'; 
    284                 // protect strings 
    285                 $parser->add('/\'[^\'\\n\\r]*\'/', self::IGNORE); 
    286                 $parser->add('/"[^"\\n\\r]*"/', self::IGNORE); 
    287                 // remove comments 
    288                 $parser->add('/\\/\\/[^\\n\\r]*[\\n\\r]/', ' '); 
    289                 $parser->add('/\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\//', ' '); 
    290                 // protect regular expressions 
    291                 $parser->add('/\\s+(\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?)/', '$2'); // IGNORE 
    292                 $parser->add('/[^\\w\\x24\\/\'"*)\\?:]\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?/', self::IGNORE); 
    293                 // remove: ;;; doSomething(); 
    294                 if ($this->_specialChars) $parser->add('/;;;[^\\n\\r]+[\\n\\r]/'); 
    295                 // remove redundant semi-colons 
    296                 $parser->add('/\\(;;\\)/', self::IGNORE); // protect for (;;) loops 
    297                 $parser->add('/;+\\s*([};])/', '$2'); 
    298                 // apply the above 
    299                 $script = $parser->exec($script); 
    300  
    301                 // remove white-space 
    302                 $parser->add('/(\\b|\\x24)\\s+(\\b|\\x24)/', '$2 $3'); 
    303                 $parser->add('/([+\\-])\\s+([+\\-])/', '$2 $3'); 
    304                 $parser->add('/\\s+/', ''); 
    305                 // done 
    306                 return $parser->exec($script); 
    307         } 
    308  
    309         private function _encodeSpecialChars($script) 
    310         { 
    311                 $parser = new ParseMaster(); 
    312                 // replace: $name -> n, $$name -> na 
    313                 $parser->add('/((\\x24+)([a-zA-Z$_]+))(\\d*)/', 
    314                                          array('fn' => '_replace_name') 
    315                 ); 
    316                 // replace: _name -> _0, double-underscore (__name) is ignored 
    317                 $regexp = '/\\b_[A-Za-z\\d]\\w*/'; 
    318                 // build the word list 
    319                 $keywords = $this->_analyze($script, $regexp, '_encodePrivate'); 
    320                 // quick ref 
    321                 $encoded = $keywords['encoded']; 
    322  
    323                 $parser->add($regexp, 
    324                         array( 
    325                                 'fn' => '_replace_encoded', 
    326                                 'data' => $encoded 
    327                         ) 
    328                 ); 
    329                 return $parser->exec($script); 
    330         } 
    331  
    332         private function _encodeKeywords($script) { 
    333                 // escape high-ascii values already in the script (i.e. in strings) 
    334                 if ($this->_encoding > 62) 
    335                         $script = $this->_escape95($script); 
    336                 // create the parser 
    337                 $parser = new ParseMaster(); 
    338                 $encode = $this->_getEncoder($this->_encoding); 
    339                 // for high-ascii, don't encode single character low-ascii 
    340                 $regexp = ($this->_encoding > 62) ? '/\\w\\w+/' : '/\\w+/'; 
    341                 // build the word list 
    342                 $keywords = $this->_analyze($script, $regexp, $encode); 
    343                 $encoded = $keywords['encoded']; 
    344  
    345                 // encode 
    346                 $parser->add($regexp, 
    347                         array( 
    348                                 'fn' => '_replace_encoded', 
    349                                 'data' => $encoded 
    350                         ) 
    351                 ); 
    352                 if (empty($script)) return $script; 
    353                 else { 
    354                         //$res = $parser->exec($script); 
    355                         //$res = $this->_bootStrap($res, $keywords); 
    356                         //return $res; 
    357                         return $this->_bootStrap($parser->exec($script), $keywords); 
    358                 } 
    359         } 
    360  
    361         private function _analyze($script, $regexp, $encode) { 
    362                 // analyse 
    363                 // retreive all words in the script 
    364                 $all = array(); 
    365                 preg_match_all($regexp, $script, $all); 
    366                 $_sorted = array(); // list of words sorted by frequency 
    367                 $_encoded = array(); // dictionary of word->encoding 
    368                 $_protected = array(); // instances of "protected" words 
    369                 $all = $all[0]; // simulate the javascript comportement of global match 
    370                 if (!empty($all)) { 
    371                         $unsorted = array(); // same list, not sorted 
    372                         $protected = array(); // "protected" words (dictionary of word->"word") 
    373                         $value = array(); // dictionary of charCode->encoding (eg. 256->ff) 
    374                         $this->_count = array(); // word->count 
    375                         $i = count($all); $j = 0; //$word = null; 
    376                         // count the occurrences - used for sorting later 
    377                         do { 
    378                                 --$i; 
    379                                 $word = '$' . $all[$i]; 
    380                                 if (!isset($this->_count[$word])) { 
    381                                         $this->_count[$word] = 0; 
    382                                         $unsorted[$j] = $word; 
    383                                         // make a dictionary of all of the protected words in this script 
    384                                         //  these are words that might be mistaken for encoding 
    385                                         //if (is_string($encode) && method_exists($this, $encode)) 
    386                                         $values[$j] = call_user_func(array(&$this, $encode), $j); 
    387                                         $protected['$' . $values[$j]] = $j++; 
    388                                 } 
    389                                 // increment the word counter 
    390                                 $this->_count[$word]++; 
    391                         } while ($i > 0); 
    392                         // prepare to sort the word list, first we must protect 
    393                         //  words that are also used as codes. we assign them a code 
    394                         //  equivalent to the word itself. 
    395                         // e.g. if "do" falls within our encoding range 
    396                         //      then we store keywords["do"] = "do"; 
    397                         // this avoids problems when decoding 
    398                         $i = count($unsorted); 
    399                         do { 
    400                                 $word = $unsorted[--$i]; 
    401                                 if (isset($protected[$word]) /*!= null*/) { 
    402                                         $_sorted[$protected[$word]] = substr($word, 1); 
    403                                         $_protected[$protected[$word]] = true; 
    404                                         $this->_count[$word] = 0; 
    405                                 } 
    406                         } while ($i); 
    407  
    408                         // sort the words by frequency 
    409                         // Note: the javascript and php version of sort can be different : 
    410                         // in php manual, usort : 
    411                         // " If two members compare as equal, 
    412                         // their order in the sorted array is undefined." 
    413                         // so the final packed script is different of the Dean's javascript version 
    414                         // but equivalent. 
    415                         // the ECMAscript standard does not guarantee this behaviour, 
    416                         // and thus not all browsers (e.g. Mozilla versions dating back to at 
    417                         // least 2003) respect this. 
    418                         usort($unsorted, array(&$this, '_sortWords')); 
    419                         $j = 0; 
    420                         // because there are "protected" words in the list 
    421                         //  we must add the sorted words around them 
    422                         do { 
    423                                 if (!isset($_sorted[$i])) 
    424                                         $_sorted[$i] = substr($unsorted[$j++], 1); 
    425                                 $_encoded[$_sorted[$i]] = $values[$i]; 
    426                         } while (++$i < count($unsorted)); 
    427                 } 
    428                 return array( 
    429                         'sorted'  => $_sorted, 
    430                         'encoded' => $_encoded, 
    431                         'protected' => $_protected); 
    432         } 
    433  
    434         private $_count = array(); 
    435         private function _sortWords($match1, $match2) { 
    436                 return $this->_count[$match2] - $this->_count[$match1]; 
    437         } 
    438  
    439         // build the boot function used for loading and decoding 
    440         private function _bootStrap($packed, $keywords) { 
    441                 $ENCODE = $this->_safeRegExp('$encode\\($count\\)'); 
    442  
    443                 // $packed: the packed script 
    444                 $packed = "'" . $this->_escape($packed) . "'"; 
    445  
    446                 // $ascii: base for encoding 
    447                 $ascii = min(count($keywords['sorted']), $this->_encoding); 
    448                 if ($ascii == 0) $ascii = 1; 
    449  
    450                 // $count: number of words contained in the script 
    451                 $count = count($keywords['sorted']); 
    452  
    453                 // $keywords: list of words contained in the script 
    454                 foreach ($keywords['protected'] as $i=>$value) { 
    455                         $keywords['sorted'][$i] = ''; 
    456                 } 
    457                 // convert from a string to an array 
    458                 ksort($keywords['sorted']); 
    459                 $keywords = "'" . implode('|',$keywords['sorted']) . "'.split('|')"; 
    460  
    461                 $encode = ($this->_encoding > 62) ? '_encode95' : $this->_getEncoder($ascii); 
    462                 $encode = $this->_getJSFunction($encode); 
    463                 $encode = preg_replace('/_encoding/','$ascii', $encode); 
    464                 $encode = preg_replace('/arguments\\.callee/','$encode', $encode); 
    465                 $inline = '\\$count' . ($ascii > 10 ? '.toString(\\$ascii)' : ''); 
    466  
    467                 // $decode: code snippet to speed up decoding 
    468                 if ($this->_fastDecode) { 
    469                         // create the decoder 
    470                         $decode = $this->_getJSFunction('_decodeBody'); 
    471                         if ($this->_encoding > 62) 
    472                                 $decode = preg_replace('/\\\\w/', '[\\xa1-\\xff]', $decode); 
    473                         // perform the encoding inline for lower ascii values 
    474                         elseif ($ascii < 36) 
    475                                 $decode = preg_replace($ENCODE, $inline, $decode); 
    476                         // special case: when $count==0 there are no keywords. I want to keep 
    477                         //  the basic shape of the unpacking funcion so i'll frig the code... 
    478                         if ($count == 0) 
    479                                 $decode = preg_replace($this->_safeRegExp('($count)\\s*=\\s*1'), '$1=0', $decode, 1); 
    480                 } 
    481  
    482                 // boot function 
    483                 $unpack = $this->_getJSFunction('_unpack'); 
    484                 if ($this->_fastDecode) { 
    485                         // insert the decoder 
    486                         $this->buffer = $decode; 
    487                         $unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastDecode'), $unpack, 1); 
    488                 } 
    489                 $unpack = preg_replace('/"/', "'", $unpack); 
    490                 if ($this->_encoding > 62) { // high-ascii 
    491                         // get rid of the word-boundaries for regexp matches 
    492                         $unpack = preg_replace('/\'\\\\\\\\b\'\s*\\+|\\+\s*\'\\\\\\\\b\'/', '', $unpack); 
    493                 } 
    494                 if ($ascii > 36 || $this->_encoding > 62 || $this->_fastDecode) { 
    495                         // insert the encode function 
    496                         $this->buffer = $encode; 
    497                         $unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastEncode'), $unpack, 1); 
    498                 } else { 
    499                         // perform the encoding inline 
    500                         $unpack = preg_replace($ENCODE, $inline, $unpack); 
    501                 } 
    502                 // pack the boot function too 
    503                 $unpackPacker = new JavaScriptPacker($unpack, 0, false, true); 
    504                 $unpack = $unpackPacker->pack(); 
    505  
    506                 // arguments 
    507                 $params = array($packed, $ascii, $count, $keywords); 
    508                 if ($this->_fastDecode) { 
    509                         $params[] = 0; 
    510                         $params[] = '{}'; 
    511                 } 
    512                 $params = implode(',', $params); 
    513  
    514                 // the whole thing 
    515                 return 'eval(' . $unpack . '(' . $params . "))\n"; 
    516         } 
    517  
    518         private $buffer; 
    519         private function _insertFastDecode($match) { 
    520                 return '{' . $this->buffer . ';'; 
    521         } 
    522         private function _insertFastEncode($match) { 
    523                 return '{$encode=' . $this->buffer . ';'; 
    524         } 
    525  
    526         // mmm.. ..which one do i need ?? 
    527         private function _getEncoder($ascii) { 
    528                 return $ascii > 10 ? $ascii > 36 ? $ascii > 62 ? 
    529                        '_encode95' : '_encode62' : '_encode36' : '_encode10'; 
    530         } 
    531  
    532         // zero encoding 
    533         // characters: 0123456789 
    534         private function _encode10($charCode) { 
    535                 return $charCode; 
    536         } 
    537  
    538         // inherent base36 support 
    539         // characters: 0123456789abcdefghijklmnopqrstuvwxyz 
    540         private function _encode36($charCode) { 
    541                 return base_convert($charCode, 10, 36); 
    542         } 
    543  
    544         // hitch a ride on base36 and add the upper case alpha characters 
    545         // characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 
    546         private function _encode62($charCode) { 
    547                 $res = ''; 
    548                 if ($charCode >= $this->_encoding) { 
    549                         $res = $this->_encode62((int)($charCode / $this->_encoding)); 
    550                 } 
    551                 $charCode = $charCode % $this->_encoding; 
    552  
    553                 if ($charCode > 35) 
    554                         return $res . chr($charCode + 29); 
    555                 else 
    556                         return $res . base_convert($charCode, 10, 36); 
    557         } 
    558  
    559         // use high-ascii values 
    560         // characters: ¡¢£€¥Š§š©ª«¬­®¯°±²³Žµ¶·ž¹º»ŒœŸ¿ÀÁÂÃÄà
    561 Ã†Ã‡ÃˆÃ‰ÃŠÃ‹ÃŒÃÃŽÃÃÃ‘ÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãÀåÊçÚéêëìíîïðñòóÎõö÷ÞùúûÌÜß 
    562         private function _encode95($charCode) { 
    563                 $res = ''; 
    564                 if ($charCode >= $this->_encoding) 
    565                         $res = $this->_encode95($charCode / $this->_encoding); 
    566  
    567                 return $res . chr(($charCode % $this->_encoding) + 161); 
    568         } 
    569  
    570         private function _safeRegExp($string) { 
    571                 return '/'.preg_replace('/\$/', '\\\$', $string).'/'; 
    572         } 
    573  
    574         private function _encodePrivate($charCode) { 
    575                 return "_" . $charCode; 
    576         } 
    577  
    578         // protect characters used by the parser 
    579         private function _escape($script) { 
    580                 return preg_replace('/([\\\\\'])/', '\\\$1', $script); 
    581         } 
    582  
    583         // protect high-ascii characters already in the script 
    584         private function _escape95($script) { 
    585                 return preg_replace_callback( 
    586                         '/[\\xa1-\\xff]/', 
    587                         array(&$this, '_escape95Bis'), 
    588                         $script 
    589                 ); 
    590         } 
    591         private function _escape95Bis($match) { 
    592                 return '\x'.((string)dechex(ord($match))); 
    593         } 
    594  
    595  
    596         private function _getJSFunction($aName) { 
    597                 if (defined('self::JSFUNCTION'.$aName)) 
    598                         return constant('self::JSFUNCTION'.$aName); 
    599                 else 
    600                         return ''; 
    601         } 
    602  
    603         // JavaScript Functions used. 
    604         // Note : In Dean's version, these functions are converted 
    605         // with 'String(aFunctionName);'. 
    606         // This internal conversion complete the original code, ex : 
    607         // 'while (aBool) anAction();' is converted to 
    608         // 'while (aBool) { anAction(); }'. 
    609         // The JavaScript functions below are corrected. 
    610  
    611         // unpacking function - this is the boot strap function 
    612         //  data extracted from this packing routine is passed to 
    613         //  this function when decoded in the target 
    614         // NOTE ! : without the ';' final. 
    615         const JSFUNCTION_unpack = 
    616  
    617 'function($packed, $ascii, $count, $keywords, $encode, $decode) { 
    618     while ($count--) { 
    619         if ($keywords[$count]) { 
    620             $packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]); 
    621         } 
    622     } 
    623     return $packed; 
    624 }'; 
    625 /* 
    626 'function($packed, $ascii, $count, $keywords, $encode, $decode) { 
    627     while ($count--) 
    628         if ($keywords[$count]) 
    629             $packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]); 
    630     return $packed; 
    631 }'; 
    632 */ 
    633  
    634         // code-snippet inserted into the unpacker to speed up decoding 
    635         const JSFUNCTION_decodeBody = 
    636 //_decode = function() { 
    637 // does the browser support String.replace where the 
    638 //  replacement value is a function? 
    639  
    640 '    if (!\'\'.replace(/^/, String)) { 
    641         // decode all the values we need 
    642         while ($count--) { 
    643             $decode[$encode($count)] = $keywords[$count] || $encode($count); 
    644         } 
    645         // global replacement function 
    646         $keywords = [function ($encoded) {return $decode[$encoded]}]; 
    647         // generic match 
    648         $encode = function () {return \'\\\\w+\'}; 
    649         // reset the loop counter -  we are now doing a global replace 
    650         $count = 1; 
    651     } 
    652 '; 
    653 //}; 
    654 /* 
    655 '       if (!\'\'.replace(/^/, String)) { 
    656         // decode all the values we need 
    657         while ($count--) $decode[$encode($count)] = $keywords[$count] || $encode($count); 
    658         // global replacement function 
    659         $keywords = [function ($encoded) {return $decode[$encoded]}]; 
    660         // generic match 
    661         $encode = function () {return\'\\\\w+\'}; 
    662         // reset the loop counter -  we are now doing a global replace 
    663         $count = 1; 
    664     }'; 
    665 */ 
    666  
    667          // zero encoding 
    668          // characters: 0123456789 
    669          const JSFUNCTION_encode10 = 
    670 'function($charCode) { 
    671     return $charCode; 
    672 }';//;'; 
    673  
    674          // inherent base36 support 
    675          // characters: 0123456789abcdefghijklmnopqrstuvwxyz 
    676          const JSFUNCTION_encode36 = 
    677 'function($charCode) { 
    678     return $charCode.toString(36); 
    679 }';//;'; 
    680  
    681         // hitch a ride on base36 and add the upper case alpha characters 
    682         // characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 
    683         const JSFUNCTION_encode62 = 
    684 'function($charCode) { 
    685     return ($charCode < _encoding ? \'\' : arguments.callee(parseInt($charCode / _encoding))) + 
    686     (($charCode = $charCode % _encoding) > 35 ? String.fromCharCode($charCode + 29) : $charCode.toString(36)); 
    687 }'; 
    688  
    689         // use high-ascii values 
    690         // characters: ¡¢£€¥Š§š©ª«¬­®¯°±²³Žµ¶·ž¹º»ŒœŸ¿ÀÁÂÃÄà
    691 Ã†Ã‡ÃˆÃ‰ÃŠÃ‹ÃŒÃÃŽÃÃÃ‘ÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãÀåÊçÚéêëìíîïðñòóÎõö÷ÞùúûÌÜß 
    692         const JSFUNCTION_encode95 = 
    693 'function($charCode) { 
    694     return ($charCode < _encoding ? \'\' : arguments.callee($charCode / _encoding)) + 
    695         String.fromCharCode($charCode % _encoding + 161); 
    696 }'; 
    697  
    698 } 
    699  
    700  
    701 class ParseMaster { 
    702         public $ignoreCase = false; 
    703         public $escapeChar = ''; 
    704  
    705         // constants 
    706         const EXPRESSION = 0; 
    707         const REPLACEMENT = 1; 
    708         const LENGTH = 2; 
    709  
    710         // used to determine nesting levels 
    711         private $GROUPS = '/\\(/';//g 
    712         private $SUB_REPLACE = '/\\$\\d/'; 
    713         private $INDEXED = '/^\\$\\d+$/'; 
    714         private $TRIM = '/([\'"])\\1\\.(.*)\\.\\1\\1$/'; 
    715         private $ESCAPE = '/\\\./';//g 
    716         private $QUOTE = '/\'/'; 
    717         private $DELETED = '/\\x01[^\\x01]*\\x01/';//g 
    718  
    719         public function add($expression, $replacement = '') { 
    720                 // count the number of sub-expressions 
    721                 //  - add one because each pattern is itself a sub-expression 
    722                 $length = 1 + preg_match_all($this->GROUPS, $this->_internalEscape((string)$expression), $out); 
    723  
    724                 // treat only strings $replacement 
    725                 if (is_string($replacement)) { 
    726                         // does the pattern deal with sub-expressions? 
    727                         if (preg_match($this->SUB_REPLACE, $replacement)) { 
    728                                 // a simple lookup? (e.g. "$2") 
    729                                 if (preg_match($this->INDEXED, $replacement)) { 
    730                                         // store the index (used for fast retrieval of matched strings) 
    731                                         $replacement = (int)(substr($replacement, 1)) - 1; 
    732                                 } else { // a complicated lookup (e.g. "Hello $2 $1") 
    733                                         // build a function to do the lookup 
    734                                         $quote = preg_match($this->QUOTE, $this->_internalEscape($replacement)) 
    735                                                  ? '"' : "'"; 
    736                                         $replacement = array( 
    737                                                 'fn' => '_backReferences', 
    738                                                 'data' => array( 
    739                                                         'replacement' => $replacement, 
    740                                                         'length' => $length, 
    741                                                         'quote' => $quote 
    742                                                 ) 
    743                                         ); 
    744                                 } 
    745                         } 
    746                 } 
    747                 // pass the modified arguments 
    748                 if (!empty($expression)) $this->_add($expression, $replacement, $length); 
    749                 else $this->_add('/^$/', $replacement, $length); 
    750         } 
    751  
    752         public function exec($string) { 
    753                 // execute the global replacement 
    754                 $this->_escaped = array(); 
    755  
    756                 // simulate the _patterns.toSTring of Dean 
    757                 $regexp = '/'; 
    758                 foreach ($this->_patterns as $reg) { 
    759                         $regexp .= '(' . substr($reg[self::EXPRESSION], 1, -1) . ')|'; 
    760                 } 
    761                 $regexp = substr($regexp, 0, -1) . '/'; 
    762                 $regexp .= ($this->ignoreCase) ? 'i' : ''; 
    763  
    764                 $string = $this->_escape($string, $this->escapeChar); 
    765                 $string = preg_replace_callback( 
    766                         $regexp, 
    767                         array( 
    768                                 &$this, 
    769                                 '_replacement' 
    770                         ), 
    771                         $string 
    772                 ); 
    773                 $string = $this->_unescape($string, $this->escapeChar); 
    774  
    775                 return preg_replace($this->DELETED, '', $string); 
    776         } 
    777  
    778         public function reset() { 
    779                 // clear the patterns collection so that this object may be re-used 
    780                 $this->_patterns = array(); 
    781         } 
    782  
    783         // private 
    784         private $_escaped = array();  // escaped characters 
    785         private $_patterns = array(); // patterns stored by index 
    786  
    787         // create and add a new pattern to the patterns collection 
    788         private function _add() { 
    789                 $arguments = func_get_args(); 
    790                 $this->_patterns[] = $arguments; 
    791         } 
    792  
    793         // this is the global replace function (it's quite complicated) 
    794         private function _replacement($arguments) { 
    795                 if (empty($arguments)) return ''; 
    796  
    797                 $i = 1; $j = 0; 
    798                 // loop through the patterns 
    799                 while (isset($this->_patterns[$j])) { 
    800                         $pattern = $this->_patterns[$j++]; 
    801                         // do we have a result? 
    802                         if (isset($arguments[$i]) && ($arguments[$i] != '')) { 
    803                                 $replacement = $pattern[self::REPLACEMENT]; 
    804  
    805                                 if (is_array($replacement) && isset($replacement['fn'])) { 
    806  
    807                                         if (isset($replacement['data'])) $this->buffer = $replacement['data']; 
    808                                         return call_user_func(array(&$this, $replacement['fn']), $arguments, $i); 
    809  
    810                                 } elseif (is_int($replacement)) { 
    811                                         return $arguments[$replacement + $i]; 
    812  
    813                                 } 
    814                                 $delete = ($this->escapeChar == '' || 
    815                                            strpos($arguments[$i], $this->escapeChar) === false) 
    816                                         ? '' : "\x01" . $arguments[$i] . "\x01"; 
    817                                 return $delete . $replacement; 
    818  
    819                         // skip over references to sub-expressions 
    820                         } else { 
    821                                 $i += $pattern[self::LENGTH]; 
    822                         } 
    823                 } 
    824         } 
    825  
    826         private function _backReferences($match, $offset) { 
    827                 $replacement = $this->buffer['replacement']; 
    828                 $quote = $this->buffer['quote']; 
    829                 $i = $this->buffer['length']; 
    830                 while ($i) { 
    831                         $replacement = str_replace('$'.$i--, $match[$offset + $i], $replacement); 
    832                 } 
    833                 return $replacement; 
    834         } 
    835  
    836         private function _replace_name($match, $offset){ 
    837                 $length = strlen($match[$offset + 2]); 
    838                 $start = $length - max($length - strlen($match[$offset + 3]), 0); 
    839                 return substr($match[$offset + 1], $start, $length) . $match[$offset + 4]; 
    840         } 
    841  
    842         private function _replace_encoded($match, $offset) { 
    843                 return $this->buffer[$match[$offset]]; 
    844         } 
    845  
    846  
    847         // php : we cannot pass additional data to preg_replace_callback, 
    848         // and we cannot use &$this in create_function, so let's go to lower level 
    849         private $buffer; 
    850  
    851         // encode escaped characters 
    852         private function _escape($string, $escapeChar) { 
    853                 if ($escapeChar) { 
    854                         $this->buffer = $escapeChar; 
    855                         return preg_replace_callback( 
    856                                 '/\\' . $escapeChar . '(.)' .'/', 
    857                                 array(&$this, '_escapeBis'), 
    858                                 $string 
    859                         ); 
    860  
    861                 } else { 
    862                         return $string; 
    863                 } 
    864         } 
    865         private function _escapeBis($match) { 
    866                 $this->_escaped[] = $match[1]; 
    867                 return $this->buffer; 
    868         } 
    869  
    870         // decode escaped characters 
    871         private function _unescape($string, $escapeChar) { 
    872                 if ($escapeChar) { 
    873                         $regexp = '/'.'\\'.$escapeChar.'/'; 
    874                         $this->buffer = array('escapeChar'=> $escapeChar, 'i' => 0); 
    875                         return preg_replace_callback 
    876                         ( 
    877                                 $regexp, 
    878                                 array(&$this, '_unescapeBis'), 
    879                                 $string 
    880                         ); 
    881  
    882                 } else { 
    883                         return $string; 
    884                 } 
    885         } 
    886         private function _unescapeBis() { 
    887                 if (!empty($this->_escaped[$this->buffer['i']])) { 
    888                          $temp = $this->_escaped[$this->buffer['i']]; 
    889                 } else { 
    890                         $temp = ''; 
    891                 } 
    892                 $this->buffer['i']++; 
    893                 return $this->buffer['escapeChar'] . $temp; 
    894         } 
    895  
    896         private function _internalEscape($string) { 
    897                 return preg_replace($this->ESCAPE, '', $string); 
    898         } 
    899 } 
    900  
    901200?> 
  • trunk/jabberit_messenger/inc/controller.xml

    r1530 r1667  
    1717        <controller-sections> 
    1818                <css></css> 
    19                 <js path="/var/www/expresso/jabberit_messenger/js" suffix=".js" debug="true"> 
     19                <js path="js" suffix=".js"> 
    2020                        <item ref="connector" js="connector" /> 
    2121                        <item ref="editSelect" js="editSelect" /> 
     
    2525                        <item ref="load" js="load" /> 
    2626                        <item ref="show_hidden" js="show_hidden" /> 
    27                         <item ref="setup" js="setup" path="/var/www/expresso/jabberit_messenger/templates/default" /> 
     27                        <item ref="setup" js="setup"/> 
    2828                        <item ref="xtools" js="xtools" /> 
    2929                        <item ref="jsloader" js="jsloader" /> 
    3030                        <item ref="makeW" js="makeW" /> 
    3131                </js> 
    32                 <php path="/var/www/expresso/jabberit_messenger/inc" suffix=".class.php"> 
     32                <php path="inc" suffix=".class.php"> 
    3333                        <item ref="contacts_im" alias="getParticipantsExternal" class="contacts_im" method="getParticipantsExternal" prefix="class." suffix=".inc.php"/> 
    3434                        <item ref="contacts_im" alias="list_contacts" class="contacts_im" method="list_contacts" prefix="class." suffix=".inc.php"/> 
Note: See TracChangeset for help on using the changeset viewer.