- Timestamp:
- 05/26/08 11:45:16 (16 years ago)
- Location:
- trunk/instant_messenger
- Files:
-
- 8 added
- 14 deleted
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/instant_messenger/controller.php
r261 r287 1 1 <?php 2 3 class Controller4 {5 const __CONTROLLER_SECURITY__ = 'controller-security';6 const __CONTROLLER_CONTENTES__ = 'controller-contentes';7 const __CONTROLLER_SECTIONS__ = 'controller-sections';8 9 const __STRING_ACCESS__ = 'string-access';10 const __STRING_DELIMITER__ = 'string-delimiter';11 12 const __CONTROLLER_CONTENTES_ITEM__ = 'item';13 const __CONTROLLER_CONTENTES_ITEM_PARAM__ = 'param';14 const __CONTROLLER_CONTENTES_ITEM_SECTION__ = 'section';15 16 const __CONTROLLER_SECTIONS_ITEM__ = 'item';17 18 public function __construct()19 {20 $this->dom = new DOMDocument;21 $this->dom->preserveWhiteSpace = FALSE;22 $this->dom->load('controller.xml');23 24 $this->controller_security = $this->dom->getElementsByTagName(self::__CONTROLLER_SECURITY__);25 ( $this->controller_security->length === (int)0 )26 and die(__CLASS__ . ' [ ERROR #0 ] :: the tag "' . self::__CONTROLLER_SECURITY__ . '" does not exist');27 ( $this->controller_security->length === (int)1 )28 or die(__CLASS__ . ' [ ERROR #1 ] :: exists more of a tag "' . self::__CONTROLLER_SECURITY__ . '"');29 30 $this->controller_contentes = $this->dom->getElementsByTagName(self::__CONTROLLER_CONTENTES__);31 ( $this->controller_contentes->length === (int)0 )32 and die(__CLASS__ . ' [ ERROR #2 ] :: the tag "' . self::__CONTROLLER_CONTENTES__ . '" does not exist');33 ( $this->controller_contentes->length === (int)1 )34 or die(__CLASS__ . ' [ ERROR #3 ] :: exists more of a tag "' . self::__CONTROLLER_CONTENTES__ . '"');35 $this->controller_contentes = $this->controller_contentes->item(0);36 37 $this->controller_sections = $this->dom->getElementsByTagName("controller-sections");38 ( $this->controller_sections->length === (int)0 )39 and die(__CLASS__ . ' [ ERROR #4 ] :: the tag "' . self::__CONTROLLER_SECTIONS__ . '" does not exist');40 ( $this->controller_sections->length === (int)1 )41 or die(__CLASS__ . ' [ ERROR #5 ] :: exists more of a tag "' . self::__CONTROLLER_SECTIONS__ . '"');42 $this->controller_sections = $this->controller_sections->item(0);43 44 $this->string_access = $this->controller_security->item(0)->getElementsByTagName(self::__STRING_ACCESS__);45 ( $this->string_access->length === (int)0 )46 and die(__CLASS__ . ' [ ERROR #6 ] :: the tag "' . self::__STRING_ACCESS__ . '" does not exist');47 ( $this->string_access->length === (int)1 )48 or die(__CLASS__ . ' [ ERROR #7 ] :: exists more of a tag "' . self::__STRING_ACCESS__ . '"');49 $this->string_access = $this->string_access->item(0)->nodeValue;50 51 $this->string_delimiter = $this->controller_security->item(0)->getElementsByTagName(self::__STRING_DELIMITER__);52 ( $this->string_delimiter->length === (int)0 )53 and die(__CLASS__ . ' [ ERROR #8 ] :: the tag "' . self::__STRING_DELIMITER__ . '" does not exist');54 ( $this->string_delimiter->length === (int)1 )55 or die(__CLASS__ . ' [ ERROR #9 ] :: exists more of a tag "' . self::__STRING_DELIMITER__ . '"');56 $this->string_delimiter = $this->string_delimiter->item(0)->nodeValue;57 }58 59 public function exec(array &$pRequest)60 {61 ( $pRequest[$this->string_access] )62 or die(__CLASS__ . ' [ ERROR #10 ] :: bad string action argument');63 64 list($section_name, $ref, $alias) = explode($this->string_delimiter, $pRequest[$this->string_access]);65 unset($pRequest[$this->string_access]);66 67 $contents_itens = $this->controller_contentes->getElementsByTagName(self::__CONTROLLER_CONTENTES_ITEM__);68 69 for ( $i = 0; $i < $contents_itens->length && $contents_itens->item($i)->getAttribute(self::__CONTROLLER_CONTENTES_ITEM_PARAM__) != $section_name; $i++ );70 ( !($i < $contents_itens->length) )71 and die(__CLASS__ . ' [ ERROR #11 ] :: invalid section "' . $section_name . '"');72 73 $section_name = $contents_itens->item($i)->getAttribute(self::__CONTROLLER_CONTENTES_ITEM_SECTION__);74 75 $section = $this->controller_sections->getElementsByTagName($section_name);76 ( $section->length === (int)0 )77 and die(__CLASS__ . ' [ ERROR #12 ] :: the tag "' . $section_name . '" does not exist');78 ( $section->length === (int)1 )79 or die(__CLASS__ . ' [ ERROR #13 ] :: exists more of a tag "' . $section_name . '"');80 $section = $section->item(0);81 82 $section_itens = $section->getElementsByTagName(self::__CONTROLLER_SECTIONS_ITEM__);83 84 if ( empty($alias) && $alias !== '0' )85 for ( $i = 0; $i < $section_itens->length && $section_itens->item($i)->getAttribute('ref') != $ref; $i++ );86 else87 for ( $i = 0; $i < $section_itens->length && ( $section_itens->item($i)->getAttribute('ref') != $ref || $section_itens->item($i)->getAttribute('alias') !== $alias); $i++ );88 89 ( !($i < $section_itens->length) )90 and die(__CLASS__ . ' [ ERROR #14 ] :: invalid reference "' . $ref . '"');91 92 $path = $section_itens->item($i)->getAttribute('path')93 or $path = $section->getAttribute('path')94 or die(__CLASS__ . ' [ ERROR #15 ] :: bad path argument');95 96 $prefix = $section_itens->item($i)->getAttribute('prefix')97 or $prefix = $section->getAttribute('prefix');98 99 $suffix = $section_itens->item($i)->getAttribute('suffix')100 or $suffix = $section->getAttribute('suffix')101 or die(__CLASS__ . ' [ ERROR #16 ] :: bad suffix argument');102 103 $this->$section_name(array("pSectionItem" => $section_itens->item($i), "pPath" => $path, "pPrefix" => $prefix, "pSuffix" => $suffix, "pRequest" => $pRequest));104 }105 106 private final function php()107 {108 $params = func_get_args();109 extract($params[0]);110 111 $class = $pSectionItem->getAttribute('class')112 and $method = $pSectionItem->getAttribute('method')113 or die(__CLASS__ . ' [ ERROR #17 ] :: bad class or method argument');114 115 $file = "{$pPath}/{$pPrefix}{$class}{$pSuffix}";116 117 file_exists($file)118 or die(__CLASS__ . ' [ ERROR #18 ] :: the file that has the class was not opened');119 120 require_once $file;121 122 $obj = new $class;123 124 if ( $pRequest )125 $result = $obj -> $method($pRequest);126 else127 $result = $obj -> $method();128 129 printf("%s", $result);130 }131 132 private final function js()133 {134 $params = func_get_args();135 extract($params[0]);136 137 $js = $pSectionItem->getAttribute('js')138 or die(__CLASS__ . ' [ ERROR #18 ] :: bad js argument');139 140 $file = "{$pPath}/{$pPrefix}{$js}{$pSuffix}";141 142 file_exists($file)143 or die(__CLASS__ . ' [ ERROR #19 ] :: the file that has the class was not opened');144 145 $packed_file = "{$pPath}/{$pPrefix}{$js}.packer{$pSuffix}";146 147 (148 file_exists($packed_file)149 and filemtime($packed_file) > filemtime($file)150 and $packed = file_get_contents($packed_file)151 )152 or153 (154 $packer = new JavaScriptPacker(file_get_contents($file), 'High ASCII', true, true)155 and $packed = $packer->pack()156 and file_put_contents($packed_file, $packed)157 );158 159 printf("%s", $packed);160 }161 }162 163 class JavaScriptPacker164 {165 const IGNORE = '$1';166 167 private $_script = '';168 private $_encoding = 62;169 private $_fastDecode = true;170 private $_specialChars = false;171 172 private $_parsers = array();173 174 private $LITERAL_ENCODING = array(175 'None' => 0,176 'Numeric' => 10,177 'Normal' => 62,178 'High ASCII' => 95179 );180 181 public function __construct ($pScript, $pEncoding = 62, $pFastDecode = true, $pSpecialChars = false)182 {183 $this->_script = $pScript . "\n";184 if ( array_key_exists($pEncoding, $this->LITERAL_ENCODING) )185 $pEncoding = $this->LITERAL_ENCODING[$pEncoding];186 187 $this->_encoding = min((int)$pEncoding, 95);188 $this->_fastDecode = $pFastDecode;189 $this->_specialChars = $pSpecialChars;190 }191 192 public function pack()193 {194 $this->_addParser('_basicCompression');195 196 if ( $this->_specialChars )197 $this->_addParser('_encodeSpecialChars');198 199 if ( $this->_encoding )200 $this->_addParser('_encodeKeywords');201 202 return $this->_pack($this->_script);203 }204 205 private function _pack($script)206 {207 for ( $i = 0; isset($this->_parsers[$i]); $i++ )208 $script = call_user_func(array(&$this,$this->_parsers[$i]), $script);209 210 return $script;211 }212 213 // keep a list of parsing functions, they'll be executed all at once214 private function _addParser($parser)215 {216 $this->_parsers[] = $parser;217 }218 219 // zero encoding - just removal of white space and comments220 private function _basicCompression($script)221 {222 $parser = new ParseMaster();223 // make safe224 $parser->escapeChar = '\\';225 // protect strings226 $parser->add('/\'[^\'\\n\\r]*\'/', self::IGNORE);227 $parser->add('/"[^"\\n\\r]*"/', self::IGNORE);228 // remove comments229 $parser->add('/\\/\\/[^\\n\\r]*[\\n\\r]/', ' ');230 $parser->add('/\\/\\*[^*]*\\*+([^\\/][^*]*\\*+)*\\//', ' ');231 // protect regular expressions232 $parser->add('/\\s+(\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?)/', '$2'); // IGNORE233 $parser->add('/[^\\w\\x24\\/\'"*)\\?:]\\/[^\\/\\n\\r\\*][^\\/\\n\\r]*\\/g?i?/', self::IGNORE);234 // remove: ;;; doSomething();235 if ($this->_specialChars) $parser->add('/;;;[^\\n\\r]+[\\n\\r]/');236 // remove redundant semi-colons237 $parser->add('/\\(;;\\)/', self::IGNORE); // protect for (;;) loops238 $parser->add('/;+\\s*([};])/', '$2');239 // apply the above240 $script = $parser->exec($script);241 242 // remove white-space243 $parser->add('/(\\b|\\x24)\\s+(\\b|\\x24)/', '$2 $3');244 $parser->add('/([+\\-])\\s+([+\\-])/', '$2 $3');245 $parser->add('/\\s+/', '');246 // done247 return $parser->exec($script);248 }249 250 private function _encodeSpecialChars($script)251 {252 $parser = new ParseMaster();253 // replace: $name -> n, $$name -> na254 $parser->add('/((\\x24+)([a-zA-Z$_]+))(\\d*)/',255 array('fn' => '_replace_name')256 );257 // replace: _name -> _0, double-underscore (__name) is ignored258 $regexp = '/\\b_[A-Za-z\\d]\\w*/';259 // build the word list260 $keywords = $this->_analyze($script, $regexp, '_encodePrivate');261 // quick ref262 $encoded = $keywords['encoded'];263 264 $parser->add($regexp,265 array(266 'fn' => '_replace_encoded',267 'data' => $encoded268 )269 );270 return $parser->exec($script);271 }272 273 private function _encodeKeywords($script) {274 // escape high-ascii values already in the script (i.e. in strings)275 if ($this->_encoding > 62)276 $script = $this->_escape95($script);277 // create the parser278 $parser = new ParseMaster();279 $encode = $this->_getEncoder($this->_encoding);280 // for high-ascii, don't encode single character low-ascii281 $regexp = ($this->_encoding > 62) ? '/\\w\\w+/' : '/\\w+/';282 // build the word list283 $keywords = $this->_analyze($script, $regexp, $encode);284 $encoded = $keywords['encoded'];285 286 // encode287 $parser->add($regexp,288 array(289 'fn' => '_replace_encoded',290 'data' => $encoded291 )292 );293 if (empty($script)) return $script;294 else {295 //$res = $parser->exec($script);296 //$res = $this->_bootStrap($res, $keywords);297 //return $res;298 return $this->_bootStrap($parser->exec($script), $keywords);299 }300 }301 302 private function _analyze($script, $regexp, $encode) {303 // analyse304 // retreive all words in the script305 $all = array();306 preg_match_all($regexp, $script, $all);307 $_sorted = array(); // list of words sorted by frequency308 $_encoded = array(); // dictionary of word->encoding309 $_protected = array(); // instances of "protected" words310 $all = $all[0]; // simulate the javascript comportement of global match311 if (!empty($all)) {312 $unsorted = array(); // same list, not sorted313 $protected = array(); // "protected" words (dictionary of word->"word")314 $value = array(); // dictionary of charCode->encoding (eg. 256->ff)315 $this->_count = array(); // word->count316 $i = count($all); $j = 0; //$word = null;317 // count the occurrences - used for sorting later318 do {319 --$i;320 $word = '$' . $all[$i];321 if (!isset($this->_count[$word])) {322 $this->_count[$word] = 0;323 $unsorted[$j] = $word;324 // make a dictionary of all of the protected words in this script325 // these are words that might be mistaken for encoding326 //if (is_string($encode) && method_exists($this, $encode))327 $values[$j] = call_user_func(array(&$this, $encode), $j);328 $protected['$' . $values[$j]] = $j++;329 }330 // increment the word counter331 $this->_count[$word]++;332 } while ($i > 0);333 // prepare to sort the word list, first we must protect334 // words that are also used as codes. we assign them a code335 // equivalent to the word itself.336 // e.g. if "do" falls within our encoding range337 // then we store keywords["do"] = "do";338 // this avoids problems when decoding339 $i = count($unsorted);340 do {341 $word = $unsorted[--$i];342 if (isset($protected[$word]) /*!= null*/) {343 $_sorted[$protected[$word]] = substr($word, 1);344 $_protected[$protected[$word]] = true;345 $this->_count[$word] = 0;346 }347 } while ($i);348 349 // sort the words by frequency350 // Note: the javascript and php version of sort can be different :351 // in php manual, usort :352 // " If two members compare as equal,353 // their order in the sorted array is undefined."354 // so the final packed script is different of the Dean's javascript version355 // but equivalent.356 // the ECMAscript standard does not guarantee this behaviour,357 // and thus not all browsers (e.g. Mozilla versions dating back to at358 // least 2003) respect this.359 usort($unsorted, array(&$this, '_sortWords'));360 $j = 0;361 // because there are "protected" words in the list362 // we must add the sorted words around them363 do {364 if (!isset($_sorted[$i]))365 $_sorted[$i] = substr($unsorted[$j++], 1);366 $_encoded[$_sorted[$i]] = $values[$i];367 } while (++$i < count($unsorted));368 }369 return array(370 'sorted' => $_sorted,371 'encoded' => $_encoded,372 'protected' => $_protected);373 }374 375 private $_count = array();376 private function _sortWords($match1, $match2) {377 return $this->_count[$match2] - $this->_count[$match1];378 }379 380 // build the boot function used for loading and decoding381 private function _bootStrap($packed, $keywords) {382 $ENCODE = $this->_safeRegExp('$encode\\($count\\)');383 384 // $packed: the packed script385 $packed = "'" . $this->_escape($packed) . "'";386 387 // $ascii: base for encoding388 $ascii = min(count($keywords['sorted']), $this->_encoding);389 if ($ascii == 0) $ascii = 1;390 391 // $count: number of words contained in the script392 $count = count($keywords['sorted']);393 394 // $keywords: list of words contained in the script395 foreach ($keywords['protected'] as $i=>$value) {396 $keywords['sorted'][$i] = '';397 }398 // convert from a string to an array399 ksort($keywords['sorted']);400 $keywords = "'" . implode('|',$keywords['sorted']) . "'.split('|')";401 402 $encode = ($this->_encoding > 62) ? '_encode95' : $this->_getEncoder($ascii);403 $encode = $this->_getJSFunction($encode);404 $encode = preg_replace('/_encoding/','$ascii', $encode);405 $encode = preg_replace('/arguments\\.callee/','$encode', $encode);406 $inline = '\\$count' . ($ascii > 10 ? '.toString(\\$ascii)' : '');407 408 // $decode: code snippet to speed up decoding409 if ($this->_fastDecode) {410 // create the decoder411 $decode = $this->_getJSFunction('_decodeBody');412 if ($this->_encoding > 62)413 $decode = preg_replace('/\\\\w/', '[\\xa1-\\xff]', $decode);414 // perform the encoding inline for lower ascii values415 elseif ($ascii < 36)416 $decode = preg_replace($ENCODE, $inline, $decode);417 // special case: when $count==0 there are no keywords. I want to keep418 // the basic shape of the unpacking funcion so i'll frig the code...419 if ($count == 0)420 $decode = preg_replace($this->_safeRegExp('($count)\\s*=\\s*1'), '$1=0', $decode, 1);421 }422 423 // boot function424 $unpack = $this->_getJSFunction('_unpack');425 if ($this->_fastDecode) {426 // insert the decoder427 $this->buffer = $decode;428 $unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastDecode'), $unpack, 1);429 }430 $unpack = preg_replace('/"/', "'", $unpack);431 if ($this->_encoding > 62) { // high-ascii432 // get rid of the word-boundaries for regexp matches433 $unpack = preg_replace('/\'\\\\\\\\b\'\s*\\+|\\+\s*\'\\\\\\\\b\'/', '', $unpack);434 }435 if ($ascii > 36 || $this->_encoding > 62 || $this->_fastDecode) {436 // insert the encode function437 $this->buffer = $encode;438 $unpack = preg_replace_callback('/\\{/', array(&$this, '_insertFastEncode'), $unpack, 1);439 } else {440 // perform the encoding inline441 $unpack = preg_replace($ENCODE, $inline, $unpack);442 }443 // pack the boot function too444 $unpackPacker = new JavaScriptPacker($unpack, 0, false, true);445 $unpack = $unpackPacker->pack();446 447 // arguments448 $params = array($packed, $ascii, $count, $keywords);449 if ($this->_fastDecode) {450 $params[] = 0;451 $params[] = '{}';452 }453 $params = implode(',', $params);454 455 // the whole thing456 return 'eval(' . $unpack . '(' . $params . "))\n";457 }458 459 private $buffer;460 private function _insertFastDecode($match) {461 return '{' . $this->buffer . ';';462 }463 private function _insertFastEncode($match) {464 return '{$encode=' . $this->buffer . ';';465 }466 467 // mmm.. ..which one do i need ??468 private function _getEncoder($ascii) {469 return $ascii > 10 ? $ascii > 36 ? $ascii > 62 ?470 '_encode95' : '_encode62' : '_encode36' : '_encode10';471 }472 473 // zero encoding474 // characters: 0123456789475 private function _encode10($charCode) {476 return $charCode;477 }478 479 // inherent base36 support480 // characters: 0123456789abcdefghijklmnopqrstuvwxyz481 private function _encode36($charCode) {482 return base_convert($charCode, 10, 36);483 }484 485 // hitch a ride on base36 and add the upper case alpha characters486 // characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ487 private function _encode62($charCode) {488 $res = '';489 if ($charCode >= $this->_encoding) {490 $res = $this->_encode62((int)($charCode / $this->_encoding));491 }492 $charCode = $charCode % $this->_encoding;493 494 if ($charCode > 35)495 return $res . chr($charCode + 29);496 else497 return $res . base_convert($charCode, 10, 36);498 }499 500 // use high-ascii values501 // characters: ¡¢£€¥Š§š©ª«¬Â®¯°±²³Žµ¶·ž¹º»ŒœŸ¿ÃÃÃÃÃÃ502 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃà áâãÀåÊçÚéêëìÃîïðñòóÎõö÷ÞùúûÌÜß503 private function _encode95($charCode) {504 $res = '';505 if ($charCode >= $this->_encoding)506 $res = $this->_encode95($charCode / $this->_encoding);507 508 return $res . chr(($charCode % $this->_encoding) + 161);509 }510 511 private function _safeRegExp($string) {512 return '/'.preg_replace('/\$/', '\\\$', $string).'/';513 }514 515 private function _encodePrivate($charCode) {516 return "_" . $charCode;517 }518 519 // protect characters used by the parser520 private function _escape($script) {521 return preg_replace('/([\\\\\'])/', '\\\$1', $script);522 }523 524 // protect high-ascii characters already in the script525 private function _escape95($script) {526 return preg_replace_callback(527 '/[\\xa1-\\xff]/',528 array(&$this, '_escape95Bis'),529 $script530 );531 }532 private function _escape95Bis($match) {533 return '\x'.((string)dechex(ord($match)));534 }535 536 537 private function _getJSFunction($aName) {538 if (defined('self::JSFUNCTION'.$aName))539 return constant('self::JSFUNCTION'.$aName);540 else541 return '';542 }543 544 // JavaScript Functions used.545 // Note : In Dean's version, these functions are converted546 // with 'String(aFunctionName);'.547 // This internal conversion complete the original code, ex :548 // 'while (aBool) anAction();' is converted to549 // 'while (aBool) { anAction(); }'.550 // The JavaScript functions below are corrected.551 552 // unpacking function - this is the boot strap function553 // data extracted from this packing routine is passed to554 // this function when decoded in the target555 // NOTE ! : without the ';' final.556 const JSFUNCTION_unpack =557 558 'function($packed, $ascii, $count, $keywords, $encode, $decode) {559 while ($count--) {560 if ($keywords[$count]) {561 $packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]);562 }563 }564 return $packed;565 }';566 /*567 'function($packed, $ascii, $count, $keywords, $encode, $decode) {568 while ($count--)569 if ($keywords[$count])570 $packed = $packed.replace(new RegExp(\'\\\\b\' + $encode($count) + \'\\\\b\', \'g\'), $keywords[$count]);571 return $packed;572 }';573 */574 575 // code-snippet inserted into the unpacker to speed up decoding576 const JSFUNCTION_decodeBody =577 //_decode = function() {578 // does the browser support String.replace where the579 // replacement value is a function?580 581 ' if (!\'\'.replace(/^/, String)) {582 // decode all the values we need583 while ($count--) {584 $decode[$encode($count)] = $keywords[$count] || $encode($count);585 }586 // global replacement function587 $keywords = [function ($encoded) {return $decode[$encoded]}];588 // generic match589 $encode = function () {return \'\\\\w+\'};590 // reset the loop counter - we are now doing a global replace591 $count = 1;592 }593 ';594 //};595 /*596 ' if (!\'\'.replace(/^/, String)) {597 // decode all the values we need598 while ($count--) $decode[$encode($count)] = $keywords[$count] || $encode($count);599 // global replacement function600 $keywords = [function ($encoded) {return $decode[$encoded]}];601 // generic match602 $encode = function () {return\'\\\\w+\'};603 // reset the loop counter - we are now doing a global replace604 $count = 1;605 }';606 */607 608 // zero encoding609 // characters: 0123456789610 const JSFUNCTION_encode10 =611 'function($charCode) {612 return $charCode;613 }';//;';614 615 // inherent base36 support616 // characters: 0123456789abcdefghijklmnopqrstuvwxyz617 const JSFUNCTION_encode36 =618 'function($charCode) {619 return $charCode.toString(36);620 }';//;';621 622 // hitch a ride on base36 and add the upper case alpha characters623 // characters: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ624 const JSFUNCTION_encode62 =625 'function($charCode) {626 return ($charCode < _encoding ? \'\' : arguments.callee(parseInt($charCode / _encoding))) +627 (($charCode = $charCode % _encoding) > 35 ? String.fromCharCode($charCode + 29) : $charCode.toString(36));628 }';629 630 // use high-ascii values631 // characters: ¡¢£€¥Š§š©ª«¬Â®¯°±²³Žµ¶·ž¹º»ŒœŸ¿ÃÃÃÃÃÃ632 ÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃà áâãÀåÊçÚéêëìÃîïðñòóÎõö÷ÞùúûÌÜß633 const JSFUNCTION_encode95 =634 'function($charCode) {635 return ($charCode < _encoding ? \'\' : arguments.callee($charCode / _encoding)) +636 String.fromCharCode($charCode % _encoding + 161);637 }';638 639 }640 641 642 class ParseMaster {643 public $ignoreCase = false;644 public $escapeChar = '';645 646 // constants647 const EXPRESSION = 0;648 const REPLACEMENT = 1;649 const LENGTH = 2;650 651 // used to determine nesting levels652 private $GROUPS = '/\\(/';//g653 private $SUB_REPLACE = '/\\$\\d/';654 private $INDEXED = '/^\\$\\d+$/';655 private $TRIM = '/([\'"])\\1\\.(.*)\\.\\1\\1$/';656 private $ESCAPE = '/\\\./';//g657 private $QUOTE = '/\'/';658 private $DELETED = '/\\x01[^\\x01]*\\x01/';//g659 660 public function add($expression, $replacement = '') {661 // count the number of sub-expressions662 // - add one because each pattern is itself a sub-expression663 $length = 1 + preg_match_all($this->GROUPS, $this->_internalEscape((string)$expression), $out);664 665 // treat only strings $replacement666 if (is_string($replacement)) {667 // does the pattern deal with sub-expressions?668 if (preg_match($this->SUB_REPLACE, $replacement)) {669 // a simple lookup? (e.g. "$2")670 if (preg_match($this->INDEXED, $replacement)) {671 // store the index (used for fast retrieval of matched strings)672 $replacement = (int)(substr($replacement, 1)) - 1;673 } else { // a complicated lookup (e.g. "Hello $2 $1")674 // build a function to do the lookup675 $quote = preg_match($this->QUOTE, $this->_internalEscape($replacement))676 ? '"' : "'";677 $replacement = array(678 'fn' => '_backReferences',679 'data' => array(680 'replacement' => $replacement,681 'length' => $length,682 'quote' => $quote683 )684 );685 }686 }687 }688 // pass the modified arguments689 if (!empty($expression)) $this->_add($expression, $replacement, $length);690 else $this->_add('/^$/', $replacement, $length);691 }692 693 public function exec($string) {694 // execute the global replacement695 $this->_escaped = array();696 697 // simulate the _patterns.toSTring of Dean698 $regexp = '/';699 foreach ($this->_patterns as $reg) {700 $regexp .= '(' . substr($reg[self::EXPRESSION], 1, -1) . ')|';701 }702 $regexp = substr($regexp, 0, -1) . '/';703 $regexp .= ($this->ignoreCase) ? 'i' : '';704 705 $string = $this->_escape($string, $this->escapeChar);706 $string = preg_replace_callback(707 $regexp,708 array(709 &$this,710 '_replacement'711 ),712 $string713 );714 $string = $this->_unescape($string, $this->escapeChar);715 716 return preg_replace($this->DELETED, '', $string);717 }718 719 public function reset() {720 // clear the patterns collection so that this object may be re-used721 $this->_patterns = array();722 }723 724 // private725 private $_escaped = array(); // escaped characters726 private $_patterns = array(); // patterns stored by index727 728 // create and add a new pattern to the patterns collection729 private function _add() {730 $arguments = func_get_args();731 $this->_patterns[] = $arguments;732 }733 734 // this is the global replace function (it's quite complicated)735 private function _replacement($arguments) {736 if (empty($arguments)) return '';737 738 $i = 1; $j = 0;739 // loop through the patterns740 while (isset($this->_patterns[$j])) {741 $pattern = $this->_patterns[$j++];742 // do we have a result?743 if (isset($arguments[$i]) && ($arguments[$i] != '')) {744 $replacement = $pattern[self::REPLACEMENT];745 746 if (is_array($replacement) && isset($replacement['fn'])) {747 748 if (isset($replacement['data'])) $this->buffer = $replacement['data'];749 return call_user_func(array(&$this, $replacement['fn']), $arguments, $i);750 751 } elseif (is_int($replacement)) {752 return $arguments[$replacement + $i];753 754 }755 $delete = ($this->escapeChar == '' ||756 strpos($arguments[$i], $this->escapeChar) === false)757 ? '' : "\x01" . $arguments[$i] . "\x01";758 return $delete . $replacement;759 760 // skip over references to sub-expressions761 } else {762 $i += $pattern[self::LENGTH];763 }764 }765 }766 767 private function _backReferences($match, $offset) {768 $replacement = $this->buffer['replacement'];769 $quote = $this->buffer['quote'];770 $i = $this->buffer['length'];771 while ($i) {772 $replacement = str_replace('$'.$i--, $match[$offset + $i], $replacement);773 }774 return $replacement;775 }776 777 private function _replace_name($match, $offset){778 $length = strlen($match[$offset + 2]);779 $start = $length - max($length - strlen($match[$offset + 3]), 0);780 return substr($match[$offset + 1], $start, $length) . $match[$offset + 4];781 }782 783 private function _replace_encoded($match, $offset) {784 return $this->buffer[$match[$offset]];785 }786 787 788 // php : we cannot pass additional data to preg_replace_callback,789 // and we cannot use &$this in create_function, so let's go to lower level790 private $buffer;791 792 // encode escaped characters793 private function _escape($string, $escapeChar) {794 if ($escapeChar) {795 $this->buffer = $escapeChar;796 return preg_replace_callback(797 '/\\' . $escapeChar . '(.)' .'/',798 array(&$this, '_escapeBis'),799 $string800 );801 802 } else {803 return $string;804 }805 }806 private function _escapeBis($match) {807 $this->_escaped[] = $match[1];808 return $this->buffer;809 }810 811 // decode escaped characters812 private function _unescape($string, $escapeChar) {813 if ($escapeChar) {814 $regexp = '/'.'\\'.$escapeChar.'/';815 $this->buffer = array('escapeChar'=> $escapeChar, 'i' => 0);816 return preg_replace_callback817 (818 $regexp,819 array(&$this, '_unescapeBis'),820 $string821 );822 823 } else {824 return $string;825 }826 }827 private function _unescapeBis() {828 if (!empty($this->_escaped[$this->buffer['i']])) {829 $temp = $this->_escaped[$this->buffer['i']];830 } else {831 $temp = '';832 }833 $this->buffer['i']++;834 return $this->buffer['escapeChar'] . $temp;835 }836 837 private function _internalEscape($string) {838 return preg_replace($this->ESCAPE, '', $string);839 }840 }841 2 842 3 $request_method = '_' . $_SERVER['REQUEST_METHOD']; … … 855 16 return false; 856 17 } 18 19 require_once dirname(__FILE__) . '/inc/Controller.class.php'; 20 857 21 $controller = new Controller; 858 $controller->exec($$request_method);22 printf("%s", $controller->exec($$request_method)); 859 23 860 24 exit(0); -
trunk/instant_messenger/inc/Jabber.abstract.php
r265 r287 79 79 } 80 80 81 protected function connect($pUser = false, $pPassword = false, $pConnectionType = false )81 protected function connect($pUser = false, $pPassword = false, $pConnectionType = false, $pWebjabber = false ) 82 82 { 83 83 try 84 84 { 85 $_connect = $this->_connect($pUser, $pPassword, $pConnectionType );85 $_connect = $this->_connect($pUser, $pPassword, $pConnectionType, $pWebjabber ); 86 86 87 87 if ( !$_connect ) -
trunk/instant_messenger/inc/Jabberd2.abstract.php
r275 r287 69 69 else 70 70 { 71 if ( $this-> writeSocket($this->iq('set', $addid, NULL, NULL, "jabber:iq:roster", $newcontact)) )71 if ( $this->iq('set', $addid, NULL, NULL, "jabber:iq:roster", $newcontact) ) 72 72 $this->getContacts(); 73 73 echo "OK"; 74 74 } 75 75 } … … 96 96 else 97 97 { 98 $this-> writeSocket($this->iq('get', $vcard, $jid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>"));98 $this->iq('get', $vcard, $jid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>"); 99 99 } 100 100 } … … 113 113 else 114 114 { 115 $this-> writeSocket($this->iq('set', $id, NULL, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'>".$NewVcard['vcard']."</vCard>"));115 $this->iq('set', $id, NULL, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'>".$NewVcard['vcard']."</vCard>"); 116 116 echo "OK"; 117 117 } … … 124 124 return "disconnected"; 125 125 126 if ( $this-> writeSocket($this->iq('set',$delid,NULL,NULL,"jabber:iq:roster","<item jid='".$pContact['jid']."' subscription='remove'/>")) )126 if ( $this->iq('set',$delid,NULL,NULL,"jabber:iq:roster","<item jid='".$pContact['jid']."' subscription='remove'/>") ) 127 127 if ( $this->subscription($pContact['jid'],"unsubscribed") ) 128 128 echo "OK"; … … 141 141 return true; 142 142 } 143 } 144 145 final function compression() 146 { 147 $compress = "<compress xmlns='http://jabber.org/protocol/compress'><method>zlib</method></compress>"; 148 $this->writeSocket($compress); 143 149 } 144 150 … … 164 170 $id = "last_time_user"; 165 171 $jid = ( trim($pUser['jid']) == "this" ) ? $this->_user . '@' . $this->_server : $pUser['jid']; 166 $this-> writeSocket($this->iq('get', $id, $jid, NULL, "jabber:iq:last"));172 $this->iq('get', $id, $jid, NULL, "jabber:iq:last"); 167 173 } 168 174 … … 191 197 else 192 198 { 193 $this-> writeSocket($this->iq('set', $upid, NULL, NULL, "jabber:iq:roster", $updatecontact));199 $this->iq('set', $upid, NULL, NULL, "jabber:iq:roster", $updatecontact); 194 200 $this->getContacts(); 195 201 echo "OK"; -
trunk/instant_messenger/inc/Socket.abstract.php
r260 r287 52 52 set_magic_quotes_runtime(0); 53 53 $return = @fread($pSocket, $pLength); 54 54 55 set_magic_quotes_runtime(get_magic_quotes_gpc()); 55 56 56 57 57 if ( $php_errormsg ) -
trunk/instant_messenger/inc/class.Ujabber.inc.php
r275 r287 7 7 private $set_presence; 8 8 9 public final function __construct( )9 public final function __construct($pConnectionType = 'write') 10 10 { 11 11 session_start(); 12 13 12 $this->_user = $_SESSION['phpgw_info']['instant_messenger']['user']; 14 13 $this->_pass = $_SESSION['phpgw_info']['instant_messenger']['passwd']; … … 17 16 $this->_resource = $_SESSION['phpgw_info']['instant_messenger']['resource_jabber']; 18 17 $webjabber = $_SESSION['phpgw_info']['instant_messenger']['webjabber']; 19 20 18 session_write_close(); 21 19 22 if ( $this->connect($this->_user . '@' . $this->_server . '/' . $this->_resource . ':' . $this->_port, $this->_pass, 'read/write', $webjabber) )20 if ( $this->connect($this->_user . '@' . $this->_server . '/' . $this->_resource . ':' . $this->_port, $this->_pass, $pConnectionType, $webjabber) ) 23 21 $this->connected = true; 24 22 else … … 61 59 while ( ( connection_aborted() === 0 ) && time() - $init < 50 ) 62 60 { 63 61 if( isset($xml) ) 62 unset($xml); 63 64 64 # read from server and write in the client 65 65 $xml = $this->readSocket(); 66 //var_dump($xml);67 66 $xml = ( strlen($xml) ) ? $xml : ' '; 67 //$xml = ( strlen($xml) ) ? $xml : '_##_'; 68 68 printf("%s", $xml); 69 69 ob_flush(); … … 74 74 } 75 75 76 77 76 public final function SendMessage($pSendMessage) 77 { 78 78 if ( !$this->isConnected() ) 79 79 return "disconnected"; … … 85 85 $pSendMessage['body'] = preg_replace($patterns, $replace, $pSendMessage['body']); 86 86 87 $_emotions = '/<img emotion="(\S+)?"[^>]+>/'; 87 $_emotions = '/<img[^>]*emotion="(\S+)?"[^>]*>/'; 88 88 $_emotions = preg_match_all($_emotions, $pSendMessage['body'], $emotions); 89 89 … … 134 134 135 135 //retirar a linha abaixo para voltar ao padrão conforme acima 136 $xml .= "<body> " . $content['body'] . "</body>";136 $xml .= "<body><![CDATA[" . htmlentities($content['body']) . "]]></body>"; 137 137 $xml .= $payload; 138 138 $xml .= "</message>"; -
trunk/instant_messenger/inc/class.db_im.inc.php
r260 r287 19 19 function db_im() 20 20 { 21 22 21 session_start(); 23 22 $this->db_name = $_SESSION['phpgw_info']['instant_messenger']['server']['db_name']; -
trunk/instant_messenger/inc/class.ldap_im.inc.php
r275 r287 13 13 session_start(); 14 14 $this->ldap_host = $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']; 15 $this->ldap_context = $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber'];15 $this->ldap_context = $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']; 16 16 $this->user = $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']; 17 17 $this->password = $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber']; 18 $this->jid 18 $this->jid = $_SESSION['phpgw_info']['instant_messenger']['user']; 19 19 $this->connect_ldap(true); 20 20 session_write_close(); -
trunk/instant_messenger/inc/im_acl.inc.php
r262 r287 1 1 <?php 2 2 3 $size_of_ ACL= sizeof($GLOBALS['phpgw_info']['user']['acl']);3 $size_of_acl = sizeof($GLOBALS['phpgw_info']['user']['acl']); 4 4 5 for ( $i = 0; $i < sizeof($GLOBALS['phpgw_info']['user']['acl']); $i++ ) 5 # percorre a ACL até o fim ou até encontrar a entrada para o módulo de mensagem instantânea 6 for ( $i = 0; $i < $size_of_acl && $GLOBALS['phpgw_info']['user']['acl'][$i]['appname'] != 'instant_messenger'; $i++ ); 7 8 # verifica se foi encontrada a permissão para o módulo de mensagem instantânea 9 if ( $GLOBALS['phpgw_info']['user']['acl'][$i]['appname'] == 'instant_messenger' ) 6 10 { 7 if ( $GLOBALS['phpgw_info']['user']['acl'][$i]['appname'] == 'instant_messenger') 8 { 9 $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url']; 10 $webserver_url = ( !empty($webserver_url) ) ? $webserver_url : '/'; 11 12 if ( strrpos($webserver_url, '/') === false || strrpos($webserver_url, '/') != (strlen($webserver_url)-1) ) 13 $webserver_url .= '/'; 14 15 $webserver_url = $webserver_url . 'instant_messenger/'; 16 17 session_start(); 18 require_once PHPGW_SERVER_ROOT . '/instant_messenger/inc/im_sessions.inc.php'; 19 require_once PHPGW_SERVER_ROOT . '/instant_messenger/inc/load_lang.php'; 20 $_user = $_SESSION['phpgw_info']['instant_messenger']['user']; 21 $_pass = $_SESSION['phpgw_info']['instant_messenger']['passwd']; 22 $_server = $_SESSION['phpgw_info']['instant_messenger']['name_jabber']; 23 $_port = $_SESSION['phpgw_info']['instant_messenger']['port_jabber']; 24 $_resource = $_SESSION['phpgw_info']['instant_messenger']['resource_jabber']; 25 session_write_close(); 26 27 $js = array( 28 'connector', 29 'xtools', 30 'jabber', 31 'client', 32 'images', 33 'dragdrop', 34 'build_win', 35 'templates', 36 'fcommon', 37 'menu_action', 38 'functions', 39 'images', 40 'cookies_im', 41 'load', 42 ); 43 44 print '<script type="text/javascript">var path_im = "'.$webserver_url.'";</script>'; 45 46 foreach ( $js as $key => $val ) 47 print '<script src="' . $webserver_url . 'controller.php?act=j.' . $val . '"></script>'; 48 49 print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/window.css">'; 50 print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/chat.css">'; 51 print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/common.css">'; 52 53 print '<script type="text/javascript">setTimeout("client()",2000);</script>'; 54 } 11 $webserver_url_im = $GLOBALS['phpgw_info']['server']['webserver_url']; 12 $webserver_url_im = ( !empty($webserver_url_im) ) ? $webserver_url_im : '/'; 13 14 if ( strrpos($webserver_url_im, '/') === false || strrpos($webserver_url_im, '/') != (strlen($webserver_url_im) - 1) ) 15 $webserver_url_im .= '/'; 16 17 $webserver_url_im = $webserver_url_im . 'instant_messenger/'; 18 19 require_once PHPGW_SERVER_ROOT . '/instant_messenger/inc/im_sessions.inc.php'; 20 require_once PHPGW_SERVER_ROOT . '/instant_messenger/inc/load_lang.php'; 21 22 $js = array( 23 'connector', 24 'jabber', 25 'xtools', 26 'client', 27 'images', 28 'dragdrop', 29 'build_win', 30 'templates', 31 'fcommon', 32 'menu_action', 33 'functions', 34 'images', 35 'cookies_im', 36 'load', 37 ); 38 39 print '<script type="text/javascript">var path_im = "'.$webserver_url_im.'";</script>'; 40 41 42 require_once dirname(__FILE__) . '/Controller.class.php'; 43 44 $controller = new Controller; 45 $script = ''; 46 foreach ( $js as $key => $val ) 47 { 48 $val = array('act' => 'j.' . $val); 49 $script .= $controller->exec($val); 50 } 51 52 printf("<script type=\"text/javascript\">%s</script>", $script); 53 54 print '<link rel="stylesheet" type="text/css" href="' . $webserver_url_im . 'templates/default/css/window.css">'; 55 print '<link rel="stylesheet" type="text/css" href="' . $webserver_url_im . 'templates/default/css/chat.css">'; 56 print '<link rel="stylesheet" type="text/css" href="' . $webserver_url_im . 'templates/default/css/common.css">'; 57 58 # trecho de código javascript utilizado para 59 # controle de possível erro no load do script 60 # feito acima e está sendo inserido via PHP 61 # pois é um complemento do procedimento acima 62 $init_client = '<script type="text/javascript">'; 63 $init_client .= ' function im_init(pTimes)'; 64 $init_client .= ' {'; 65 $init_client .= ' if ( !pTimes )'; 66 $init_client .= ' pTimes = 0;'; 67 $init_client .= ' if ( pTimes == 5 )'; 68 $init_client .= ' return false;'; 69 $init_client .= ' if ( window.client )'; 70 $init_client .= ' client();'; 71 $init_client .= ' else'; 72 $init_client .= ' setTimeout("im_init("+(++pTimes)+")", (pTimes + 1) * 2000);'; 73 $init_client .= ' }'; 74 $init_client .= ' im_init();'; 75 $init_client .= '</script>'; 76 printf("%s", $init_client); 55 77 } 56 78 ?> -
trunk/instant_messenger/inc/im_sessions.inc.php
r265 r287 1 1 <?php 2 2 3 3 $_SESSION['phpgw_info']['instant_messenger']['user'] = $GLOBALS['phpgw_info']['user']['account_lid']; 4 $_SESSION['phpgw_info']['instant_messenger']['user_id'] 4 $_SESSION['phpgw_info']['instant_messenger']['user_id'] = $GLOBALS['phpgw_info']['user']['account_id']; 5 5 $_SESSION['phpgw_info']['instant_messenger']['passwd'] = $GLOBALS['phpgw_info']['user']['passwd']; 6 6 $_SESSION['phpgw_info']['instant_messenger']['name_jabber'] = $GLOBALS['phpgw_info']['server']['name_jabber']; 7 7 $_SESSION['phpgw_info']['instant_messenger']['port_jabber'] = $GLOBALS['phpgw_info']['server']['port_jabber']; 8 8 $_SESSION['phpgw_info']['instant_messenger']['resource_jabber'] = $GLOBALS['phpgw_info']['server']['resource_jabber']; 9 $_SESSION['phpgw_info']['instant_messenger']['tls_jabber'] = $GLOBALS['phpgw_info']['server']['tls_jabber'];10 9 11 $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber'] 12 $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber'] 13 $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber'] 14 $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber'] 15 $_SESSION['phpgw_info']['instant_messenger']['webjabber'] = $GLOBALS['phpgw_info']['server']['wejabber'];10 $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber'] = $GLOBALS['phpgw_info']['server']['server_ldap_jabber']; 11 $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber'] = $GLOBALS['phpgw_info']['server']['context_ldap_jabber']; 12 $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber'] = $GLOBALS['phpgw_info']['server']['user_ldap_jabber']; 13 $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber'] = $GLOBALS['phpgw_info']['server']['password_ldap_jabber']; 14 $_SESSION['phpgw_info']['instant_messenger']['webjabber'] = $GLOBALS['phpgw_info']['server']['webjabber']; 16 15 17 16 $_SESSION['phpgw_info']['instant_messenger']['server']['db_name'] = $GLOBALS['phpgw_info']['server']['db_name']; … … 21 20 $_SESSION['phpgw_info']['instant_messenger']['server']['db_pass'] = $GLOBALS['phpgw_info']['server']['db_pass']; 22 21 $_SESSION['phpgw_info']['instant_messenger']['server']['db_type'] = $GLOBALS['phpgw_info']['server']['db_type']; 23 22 24 23 ?> -
trunk/instant_messenger/inc/load_lang.php
r260 r287 1 1 <? 2 if ( !isset($_SESSION['phpgw_info']['instant_messenger']['lang']) || !is_array($_SESSION['phpgw_info']['instant_messenger']['lang']) ) 3 4 5 6 7 8 9 $_SESSION['phpgw_info']['instant_messenger']['lang'][$message_id] = $content;10 11 12 2 3 if ( file_exists(($fn = dirname(__FILE__) . '/../setup/phpgw_pt-br.lang')) ) 4 if ( ($fp = fopen($fn,'r')) ) 5 { 6 while ($data = fgets($fp,16000)) 7 { 8 list($message_id, $app_name, $null, $content) = explode("\t",substr($data,0,-1)); 9 $LANG_IM[$message_id] = $content; 10 } 11 fclose($fp); 12 } 13 13 14 14 $script = '<script>'; 15 15 $script .= 'var lang_im = [];'; 16 16 17 foreach ( $ _SESSION['phpgw_info']['instant_messenger']['lang']as $key => $value )17 foreach ( $LANG_IM as $key => $value ) 18 18 $script .= "lang_im['" . strtolower(addslashes($key)) . "'] = '" . addslashes($value) . "';"; 19 20 #$_key = str_replace("'","\'",strtolower($key));21 #$_val = str_replace("'","\'",$value);22 19 23 20 $script .= '</script>'; 24 21 25 22 echo $script; 23 24 unset($LANG_IM); 26 25 ?> -
trunk/instant_messenger/js/build_win.js
r260 r287 87 87 "window_focus" : function(pElement) 88 88 { 89 pElement.style.zIndex = ++this.focus; 89 if (! templates.dontFocus) 90 pElement.style.zIndex = ++this.focus; 91 else 92 templates.dontFocus = false; 90 93 }, 91 94 … … 103 106 this.elementM(pId).style.width = window.screen.availWidth - 24; 104 107 this.elementM(pId).style.height = window.screen.availHeight - 60; 108 105 109 106 110 // _window_body … … 110 114 // _window_body_content 111 115 this.elementC(pId).style.height = '100%'; 116 var windowType = this.elementC(pId).firstChild.firstChild.className; 117 118 if (windowType == 'history') // message window 119 { 120 this.elementC(pId).firstChild.childNodes[0].style.height = '60%'; 121 this.elementC(pId).firstChild.childNodes[0].style.width = '100%'; 122 this.elementC(pId).firstChild.childNodes[1].style.width = '100%'; 123 this.elementC(pId).firstChild.childNodes[2].firstChild.style.width = '100%'; 124 } 125 else if (windowType == 'font_menu') // contacts window 126 { 127 this.elementC(pId).childNodes[1].style.height = '70%'; 128 } 129 112 130 }, 113 131 -
trunk/instant_messenger/js/client.js
r275 r287 1 var con = new IMConnector;1 var conn_im = new IMConnector; 2 2 var disconnected = false; 3 var validate_data = false; 4 var buffer_im = ''; 5 var xtools_im = null; 6 var count_im = 0; 7 var activate_timeOut = ''; 8 9 function clientConnectionIm() 10 { 11 if( count_im < 2 ) 12 { 13 if( buffer_im.length > 0 ) 14 activate_timeOut = setTimeout('clientConnectionIm()', 5000); 15 16 count_im++; 17 } 18 else 19 { 20 count_im = 0; 21 buffer_im = 0; 22 clientDisconnectIm(); 23 clearTimeout(activate_timeOut); 24 killConnIm(); 25 } 26 } 27 28 function clientDisconnectIm() 29 { 30 if( xtools_im == null ) 31 xtools_im = new XTools; 32 33 disconnected = true; 34 var XmlDoc = "<disconnected>" + 35 "<path>" + path_im + "</path>" + 36 "</disconnected>"; 37 38 im_window.load('__contacts_im_','instant_messenger_content','<title>.::Expresso Messenger::.</title>','window.xsl','190',true,true,false); 39 im_window.elementC('__contacts_im_').innerHTML = xtools_im.parse(XmlDoc,'disconnected.xsl'); 40 func.byId('im_status_src').src = im_unavailable.src; 41 im.status = 'type=unavailable'; 42 im.statusFlag = 'unavailable'; 43 44 function handler_presence_disconnected() 45 { 46 } 47 conn_im.go('$this.Ujabber.setPresence', {'request' : handler_presence_disconnected }, im.status); 48 } 49 50 function killConnIm() 51 { 52 var i; 53 disconnected = true; 54 55 for ( i in conn_im.__HTTP__ ) 56 conn_im.__HTTP__[i].abort(); 57 } 3 58 4 59 function client() 5 60 { 6 var jabber = new Jabber; 7 var buffer = ''; 8 var xtools = new XTools; 61 if( jabber == null ) 62 var jabber = new Jabber; 63 64 if( xtools_im == null ) 65 xtools_im = new XTools; 9 66 10 67 function request(data) … … 12 69 if ( !disconnected ) 13 70 { 14 con.go('$this.Ujabber.listen', {'stream':stream, 'request':request}); 71 conn_im.go('$this.Ujabber.listen', {'stream':stream, 'request':request}, 'classConstructor=read'); 72 } 73 else 74 { 75 clientDisconnectIm(); 76 return false; 15 77 } 16 78 } … … 22 84 return pData.replace(/^ +| +$/g, ''); 23 85 } 86 87 function retrim(pData) 88 { 89 return pData.replace(/(_##_)+\b/g, ''); 90 } 91 24 92 data = trim(data); 25 if ( data == 'disconnected' || data == '</stream:stream>') 93 94 if ( data == 'disconnected' || data == '</stream:stream>' ) 26 95 { 27 disconnected = true; 28 var XmlDoc = "<disconnected>" + 29 "<path>" + path_im + "</path>" + 30 "</disconnected>"; 31 32 im_window.load('__contacts_im_','instant_messenger_content','<title>.::Expresso Messenger::.</title>','window.xsl','',true,true,false); 33 im_window.elementC('__contacts_im_').innerHTML = xtools.parse(XmlDoc,'disconnected.xsl'); 34 func.byId('img_status_im').src = im_unavailable.src; 35 im.status = 'type=unavailable'; 36 im.statusFlag = 'unavailable'; 37 96 clientDisconnectIm(); 97 return false; 38 98 } 39 else if ( data.lastIndexOf('>') == data.length - 1 )99 else if ( data.lastIndexOf('>') == data.length - 1 && data.length > 0 ) 40 100 { 41 if ( buffer .length )101 if ( buffer_im.length ) 42 102 { 43 data = buffer + data;44 buffer = '';103 data = buffer_im + data; 104 buffer_im = ""; 45 105 } 46 106 … … 62 122 63 123 var node = xmlDoc.documentElement.firstChild; 64 124 65 125 while ( node ) 66 126 { 67 127 try 68 128 { 69 with ( node ) 70 { 71 jabber.doIt(nodeName, node); 72 } 129 jabber.doIt(node.nodeName, node); 73 130 node = node.nextSibling; 74 131 } 75 132 catch(e) 76 133 { 134 alert('erro : ' + e + "\n\n" + e.description); 77 135 node = node.nextSibling; 78 136 } … … 81 139 else 82 140 { 83 buffer += data; 141 data = data.replace(/^ +| +$/g, ''); 142 buffer_im += data + " "; 84 143 } 85 144 } … … 87 146 function contacts(data) 88 147 { 148 setTimeout('clientConnectionIm()', 3000); 89 149 } 90 150 request(); 91 setTimeout("con .go('$this.Ujabber.getContacts', {'request':"+contacts+"})", 3000);151 setTimeout("conn_im.go('$this.Ujabber.getContacts', {'request':"+contacts+"})", 3000); 92 152 } 93 153 … … 99 159 _bkp_onbeforeunload(); 100 160 101 disconnected = true; 102 var i; 103 for ( i in con.__HTTP__ ) 104 con.__HTTP__[i].abort(); 161 killConnIm(); 105 162 }; -
trunk/instant_messenger/js/functions.js
r275 r287 27 27 var content = get_Element(pJid); 28 28 content.innerHTML += "" + this.insertEmoticons(pEmotion); 29 var smileWindow = document.getElementById(pJid+"__button_dest"); 30 if (smileWindow.firstChild) 31 smileWindow.removeChild(smileWindow.firstChild); 29 32 }, 30 33 … … 88 91 } 89 92 var content = get_Element(pJid); 90 93 94 var colorWindow = document.getElementById(pJid+"__button_dest"); 95 if (colorWindow.firstChild) 96 colorWindow.removeChild(colorWindow.firstChild); 97 91 98 if( _font_color = _document.contentWindow.document.getElementById('colors_'+pJid) ) 92 99 content.innerHTML = "<span id='colors_"+pJid+"'style='color:"+pColor+"'>"+_font_color.innerHTML+"</span>"; … … 346 353 { 347 354 var data = eval(XmlData); 355 348 356 if( data ) 349 357 { 350 358 if( document.getElementById(pAvatar) != null ) 351 359 { 352 var photo_img = document.getElementById(pAvatar); 353 photo_img.src = ( path_im + "inc/class.ldap_im.inc.php?user="+uid ) ? path_im + "inc/class.ldap_im.inc.php?user="+uid : im_photo.src ; 360 if( document.getElementById(pAvatar).src ) 361 { 362 var photo_img = document.getElementById(pAvatar); 363 photo_img.src = ( path_im + "inc/class.ldap_im.inc.php?user="+uid ) ? path_im + "inc/class.ldap_im.inc.php?user="+uid : im_photo.src ; 364 } 365 else 366 { 367 var photo_img = document.getElementById(pAvatar); 368 photo_img.style.backgroundImage = 'url(' + path_im + 'inc/class.ldap_im.inc.php?user='+uid+')'; 369 } 354 370 } 355 371 } … … 361 377 }, 362 378 363 364 379 "newMessageNotification" : function() 380 { 365 381 if ( !focusFlag ) 366 382 { … … 455 471 { 456 472 if(imgStatus != null) 457 func.byId('im_status_src').src = eval('im_' + imgStatus + '.src'); 473 { 474 var img_status = document.getElementById('im_status_src'); 475 img_status.src = eval('im_' + imgStatus + '.src'); 476 } 458 477 } 459 478 this.conn.go('$this.Ujabber.setPresence', {'request' : handler_presence}, this.status); … … 462 481 "remove" : function(pJid) 463 482 { 483 if (pJid == -1) 484 return false; 464 485 if(confirm('Deseja excluir o contato ' + pJid + ' ?')) 465 486 { … … 488 509 if( func.byId(pElement).options[i].selected == true ) 489 510 Jid = func.byId(pElement).options[i].value; 490 491 if(confirm('Deseja excluir o contato ' + Jid + ' ?')) 492 { 493 if( Jid && Jid != -1 ) 494 { 511 if (Jid == -1) 512 return false; 513 else 514 if(confirm('Deseja excluir o contato ' + Jid + ' ?')) 515 { 516 if( Jid && Jid != -1 ) 517 { 495 518 function handler_remove(XmlData) 496 519 { … … 535 558 { 536 559 if( XmlData != "OK" ) 537 alert(' Vcard não cadastrado/atualizado !');560 alert('Erro: Vcard não cadastrado/atualizado !'); 538 561 else 539 562 alert('Vcard cadastrado/atualizado !'); 563 im_window.window_close('vcard_user_im'); 540 564 } 541 565 this.conn.go('$this.Ujabber.newVcard',{'request':handler_savevcard},"vcard="+xmlVcard); … … 571 595 im.off_line(); 572 596 alert('Preferências Salvas !'); 597 im_window.window_close('my_settings_im'); 573 598 } 574 599 } -
trunk/instant_messenger/js/images.js
r260 r287 29 29 var im_group_open = new Image(); 30 30 im_group_open.src = path_im + 'templates/default/images/group_open.gif'; 31 31 32 32 // Smiles 33 33 -
trunk/instant_messenger/js/jabber.js
r280 r287 121 121 var iframe = func.byId('iframe_' + from); 122 122 123 //if(func.byId('iframe_' + from) != null)124 //func.byId('iframe_' + from).parentNode.removeChild(func.byId('iframe_' + from));125 126 123 var win; 127 124 … … 142 139 var iframe = document.createElement('iframe'); 143 140 iframe.id = 'iframe_' + from; 144 iframe.style.width = '2 90px';145 iframe.style.height = ' 46px';141 iframe.style.width = '240px'; 142 iframe.style.height = '65px'; 146 143 iframe.style.border = '0'; 147 144 iframe.style.margin = '0'; … … 154 151 iframe.contentWindow.document.close(); 155 152 iframe.contentWindow.document.designMode = "On"; 153 154 function getEnter(e) 155 { 156 if ( !(e.shiftKey) && (e.keyCode == 13) ) 157 { 158 if ( e.type.indexOf('keydown') != -1 ) 159 im.SendMessage(from); 160 else 161 iframe.contentWindow.document.body.innerHTML = ''; 162 return false; 163 } 164 } 165 166 func.attachEvent(iframe.contentWindow, 'onkeydown', getEnter); 167 func.attachEvent(iframe.contentWindow, 'onkeyup', getEnter); 156 168 157 169 } … … 327 339 function readVcard(pVcard) 328 340 { 341 329 342 switch(pVcard.getAttribute('id')) 330 343 { … … 338 351 { 339 352 if(cc.firstChild.nodeValue) 340 func.byId('im_layer_nickname').innerHTML = cc.firstChild.nodeValue; 353 func.byId('im_layer_nickname').innerHTML = cc.firstChild.nodeValue; 341 354 } 342 355 cc = cc.nextSibling; -
trunk/instant_messenger/js/templates.js
r275 r287 5 5 this.documentMousedown = null; 6 6 this.jabber = new Jabber; 7 this.dontFocus = false; 7 8 } 8 9 … … 73 74 document.getElementById('fast_menu_im').style.position = "absolute"; 74 75 } 75 else76 alert('Aguarde carregando lista de contatos ....');77 76 78 77 }, … … 123 122 124 123 "options_button_left" : function(pJid) 125 { 124 { 126 125 var _this = this; 127 126 128 127 if(!(im.nickname_contacts[pJid])) 129 128 im.request_vcard(pJid, false); … … 133 132 im_window.load(pJid, 'instant_messenger_content', '<title>.:: Expresso Messenger ::.</title>', 'chat.xsl','310',true,true,true); 134 133 135 func.byId(pJid + '__avatar').src = path_im + "/templates/default/images/photo.png";136 134 137 135 if(func.byId('iframe_' + pJid) != null) … … 142 140 var iframe = document.createElement('iframe'); 143 141 iframe.id = 'iframe_' + pJid; 144 iframe.style.width = '2 90px';145 iframe.style.height = ' 46px';142 iframe.style.width = '240px'; 143 iframe.style.height = '65px'; 146 144 iframe.style.border = '0'; 147 145 iframe.style.margin = '0'; … … 153 151 iframe.contentWindow.document.write('<html><body id="' + pJid + '" style="margin:0px;padding:0px"></body></html>'); 154 152 iframe.contentWindow.document.close(); 153 155 154 iframe.contentWindow.document.designMode = "On"; 156 155 iframe.contentWindow.focus(); 156 this.dontFocus = true; 157 158 function getEnter(e) 159 { 160 if ( !(e.shiftKey) && (e.keyCode == 13) ) 161 { 162 if ( e.type.indexOf('keydown') != -1 ) 163 im.SendMessage(pJid); 164 else 165 iframe.contentWindow.document.body.innerHTML = ''; 166 return false; 167 } 168 } 169 func.attachEvent(iframe.contentWindow, 'onkeydown', getEnter); 170 func.attachEvent(iframe.contentWindow, 'onkeyup', getEnter); 157 171 158 172 im.ldap_photo(pJid + "__avatar"); -
trunk/instant_messenger/templates/default/css/chat.css
r268 r287 113 113 .messages 114 114 { 115 background: #fff; 115 background-color: #fff; 116 background-position:right !important; 117 background-repeat: no-repeat !important; 118 background-image: url(../images/photo.png); 116 119 border: 1px solid; 117 120 border-color: #b3b3b3 #cecece #cecece #b3b3b3; 118 width: auto; /*289px;*/119 height: 46px;120 121 cursor: text; 122 height: 65px; 123 padding-right:50px; 124 width: auto; 121 125 } 122 126 -
trunk/instant_messenger/webjabber/webjabber.c
r268 r287 817 817 bytes_rcvd_client = (int) NULL, 818 818 bytes_sent_client = (int) NULL, 819 i; 820 821 //syslog (LOG_INFO, "Reading(fd%d, fd%d)", in_fd, out_fd); 819 i, 820 do_auth = 0; 822 821 823 822 // @TODO: verificar alocacao buffer … … 828 827 { 829 828 bzero(buf_2_jabber, BUF_SIZE); 830 if ( (bytes_rcvd_client = recv (client_fd, buf_2_jabber, BUF_SIZE, 0)) != 0 && strlen(buf_2_client) > 0 ) 831 { 832 // descomentar para ver oq esta passado de informacao 833 //printf("(jabber/client[#%d])[%d]:\n{\n%s.......\n}\n", client_fd, strlen(buf_2_client), buf_2_client); 829 bytes_rcvd_client = recv (client_fd, buf_2_jabber, BUF_SIZE, 0); 830 if ( (bytes_rcvd_client != 0) && (strlen(buf_2_client) > 0) ) 831 { 834 832 for ( i = 0; i < bytes_rcvd_jabber; i += bytes_sent_client ) 835 833 { … … 840 838 } 841 839 } 840 if ( strlen(buf_2_jabber) > 0 ) 841 { 842 //printf("(client/jabber[#%d])[%d]:\n{\n%s.......\n}\n", jabber_fd, strlen(buf_2_jabber), buf_2_jabber); 843 if ( strstr(buf_2_jabber, "<?xml") != NULL ) 844 do_auth = 1; 845 } 842 846 843 847 bzero(buf_2_client, BUF_SIZE); 844 if ( (bytes_rcvd_jabber = recv (jabber_fd, buf_2_client, BUF_SIZE, 0)) != 0 && strlen(buf_2_jabber) > 0 ) 845 { 846 // descomentar para ver oq esta passado de informacao 847 //printf("(client/jabber[#%d])[%d]:\n{\n%s.......\n}\n", jabber_fd, strlen(buf_2_jabber), buf_2_jabber); 848 if ( do_auth || read->type == 1 ) 849 bytes_rcvd_jabber = recv (jabber_fd, buf_2_client, BUF_SIZE, 0); 850 else 851 bytes_rcvd_jabber = -1; 852 if ( (bytes_rcvd_jabber != 0) && (strlen(buf_2_jabber) > 0) ) 853 { 848 854 for ( i = 0; i < bytes_rcvd_client; i += bytes_sent_jabber ) 849 855 { … … 854 860 } 855 861 } 862 if ( strlen(buf_2_client) > 0 ) 863 { 864 //printf("(jabber/client[#%d])[%d]:\n{\n%s.......\n}\n", client_fd, strlen(buf_2_client), buf_2_client); 865 if ( do_auth && strstr(buf_2_jabber, "<iq xmlns='jabber:client'") != NULL ) 866 do_auth = 0; 867 } 856 868 857 869 usleep(500); 858 //sleep(2);859 870 } 860 871 while ( (bytes_rcvd_client != 0) && (bytes_rcvd_jabber != 0) ); -
trunk/instant_messenger/xsl/chat.xsl
r268 r287 25 25 <div id="{name}__window_body_content" class="content"> 26 26 <div style="margin:3px 3px;"> 27 <div class="history"> 28 <div class="avatar" style="margin: 2px; position: absolute; right: 30px; top: 30px;"> 29 <img id="{name}__avatar"/> 30 </div> 31 </div> 27 <div class="history"></div> 32 28 <div class="toolbar_buttons"> 33 29 <div id="{name}__button_bold" class="button_bold" onclick="javascript:im.conf_font('{name}','button_bold');"></div> … … 40 36 <div id="{name}__button_dest"></div> 41 37 </div> 42 <div class="messages"></div>38 <div id="{name}__avatar" class="messages"></div> 43 39 </div> 44 40 </div> -
trunk/instant_messenger/xsl/disconnected.xsl
r260 r287 5 5 <xsl:template match="/disconnected"> 6 6 <div class="disconnected"> 7 <img src="{path}templates/default/images/logo.png" align="bottom" style="margin:2px"/> 8 <font style="font-weight:bold;margin:5px">Expresso Messenger</font> 9 <br/> 10 <br/> 11 <font style="font-weight:bold;margin:5px"> Aviso : </font> 12 <br/> 13 <br/> 14 <div style="margin:5px"> 15 Sua conexão com o 7 <div style="background:url('{path}templates/default/images/logo.png');width:32px;height:32px;margin:2px"></div> 8 <font style="font-weight:bold;margin:5px"><center>Aviso</center> </font> 9 <div style="margin:5px; font-size: 8pt; font-family: Arial, Verdana, helvetica, sans;"> 10 Sua conexão com o Servidor parou. 16 11 <br/> 17 Servidor parou.12 Tente novamente ou entre em 18 13 <br/> 19 Tente novamente 20 <br/> 21 ou entre em contato 22 <br/> 23 com o Administrador. 14 contato com o Administrador. 24 15 </div> 25 16 <br/> 26 < br/>27 <img src="{path}templates/default/images/available.gif" />28 < a href="javascript:disconnected = false; client();"><font style="font-size:7pt;margin:2px">Reconectar ...</font></a>17 <div onclick="disconnected = false; client();" style="background:url('{path}templates/default/images/server_connect.png') no-repeat;padding-left:16px;height:16px;margin:3px;cursor:pointer"> 18 <font style="font-size:7pt;margin:2px">Reconectar ...</font> 19 </div> 29 20 </div> 30 21 </xsl:template>
Note: See TracChangeset
for help on using the changeset viewer.