_user = $_SESSION['phpgw_info']['instant_messenger']['user']; $this->_pass = $_SESSION['phpgw_info']['instant_messenger']['passwd']; $this->_server = $_SESSION['phpgw_info']['instant_messenger']['name_jabber']; $this->_port = $_SESSION['phpgw_info']['instant_messenger']['port_jabber']; $this->_resource = $_SESSION['phpgw_info']['instant_messenger']['resource_jabber']; session_write_close(); if ( $this->connect($this->_user . '@' . $this->_server . '/' . $this->_resource . ':' . $this->_port, $this->_pass, 'read/write') ) $this->connected = true; else $this->connected = false; } public final function __destruct() { $this->closeSocket(); ob_end_flush(); flush(); } public final function isConnected() { return $this->connected; } public final function listen() { if ( !$this->isConnected() ) return "disconnected"; if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) { sleep(1); $xml = $this->readSocket(); printf("%s", $xml); } else { ob_end_clean(); ignore_user_abort(true); ob_start(); $init = time(); while ( !connection_aborted() && time() - $init < 50 ) { # read from server and write in the client $xml = $this->readSocket(); //var_dump($xml); $xml = ( strlen($xml) ) ? $xml : ' '; printf("%s", $xml); ob_flush(); flush(); usleep(6000); } } } public final function SendMessage($pSendMessage) { if ( !$this->isConnected() ) return "disconnected"; $pSendMessage['body'] = stripslashes($pSendMessage['body']); $patterns = array('/ | +/i', '/]*>/i'); $replace = array(' ', '
'); $pSendMessage['body'] = preg_replace($patterns, $replace, $pSendMessage['body']); $_emotions = '/]+>/'; $_emotions = preg_match_all($_emotions, $pSendMessage['body'], $emotions); foreach ( $emotions[0] as $key => $val ) $emotions[0][$key] = '/' . addcslashes($val, './()[]{}^$*&?') . '/i'; $pSendMessage['body'] = preg_replace($emotions[0], $emotions[1], $pSendMessage['body']); $to = $pSendMessage['to']; $type = "chat"; $id = ""; $content = array( "subject" => $pSendMessage['subject'] ? $pSendMessage['subject'] : "", "thread" => $pSendMessage['thread'] ? $pSendMessage['thread'] : "", "body" => $pSendMessage['body'] ? $pSendMessage['body'] : "" ); $payload = ""; if ($to && is_array($content)) { if (!$id) { $id = $type . "_" . time(); } $xml = ""; if ($content['subject']) { $xml .= "" . $content['subject'] . ""; } if ($content['thread']) { $xml .= "" . $content['thread'] . ""; } //Linha abaixo dentro do padrão xmpp, entretanto clientes como //o PSI não seguem o padrão assim ocorre problemas de comunicação //descomentar e retirar a seguinte para voltar ao padrão assim //que possível //24/10/2007 - problema verificado por usuários do SERPRO na //plataforma Windows ocorrendo também no cliente Linux //por Alexandre e Rodrigo //$xml .= "" . $content['body'] . ""; //retirar a linha abaixo para voltar ao padrão conforme acima $xml .= "" . $content['body'] . ""; $xml .= $payload; $xml .= ""; unset($id); echo $xml; $this->writeSocket($xml); $this->close(); } else { //$this->writeLog("ERROR: SendMessage() #2"); return false; } } } ?>