_user = $_SESSION['phpgw_info']['instant_messenger']['user'];
//$this->_user = 'niltonneto';//$_SESSION['phpgw_info']['instant_messenger']['user'];
//$this->_pass = 'nine59ever';//$_SESSION['phpgw_info']['instant_messenger']['passwd'];
//$this->_pass = 'senha';//$_SESSION['phpgw_info']['instant_messenger']['passwd'];
$this->_pass = $_SESSION['phpgw_info']['instant_messenger']['passwd'];
$this->_server = $_SESSION['phpgw_info']['instant_messenger']['name_jabber'];
$this->_port = '8883';//$_SESSION['phpgw_info']['instant_messenger']['port_jabber'];
$this->_resource = $_SESSION['phpgw_info']['instant_messenger']['resource_jabber'];
//$webjabber = 'im.pr.gov.br';//$_SESSION['phpgw_info']['instant_messenger']['webjabber'];
$webjabber = '10.15.22.236';//$_SESSION['phpgw_info']['instant_messenger']['webjabber'];
session_write_close();*/
try
{
if ( !file_exists(dirname(__FILE__) . '/../instant_messenger.define.php') )
throw new Exception(__CLASS__ . '[ ERROR #1 ] : Not found configuration file');
require_once dirname(__FILE__) . '/../instant_messenger.define.php';
if ( !(defined('JABBER_URL') && defined('JABBER_RESOURCE')) )
throw new Exception(__CLASS__ . '[ ERROR #2 ] : Jabber server is not cofigured');
if ( !(defined('WEBJABBER_URL') && defined('WEBJABBER_PORT')) )
throw new Exception(__CLASS__ . '[ ERROR #3 ] : Webabber server is not cofigured');
$this->_server = constant('JABBER_URL');
$this->_resource = constant('JABBER_RESOURCE');
$this->_port = constant('WEBJABBER_PORT');
session_start();
$this->_user = $_SESSION['phpgw_info']['instant_messenger']['user'];
$this->_pass = $_SESSION['phpgw_info']['instant_messenger']['passwd'];
session_write_close();
$access_string = $this->_user . '@' . $this->_server . '/' . $this->_resource . ':' . $this->_port;
$this->connected = false;
if ( $this->connect($access_string, $this->_pass, $pConnectionType, constant('WEBJABBER_URL')) )
$this->connected = true;
}
catch(Exception $e)
{
echo $e->getMessage();
}
}
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();
$buffer = '';
while ( ( connection_aborted() === 0 ) && time() - $init < 50 )
{
# read from server and write in the client
$xml = $this->readSocket();
//var_dump($xml);
if ( strlen($xml) && $xml != ' ' )
{
if ( $xml[strlen($xml) - 1 ] != '>' )
{
$buffer .= $xml;
$xml = '';
}
else
{
$xml = $buffer . $xml;
$buffer = '';
//var_dump($xml);
//strlen($xml);
//exit;
}
}
$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 .= "";
$xml .= $payload;
$xml .= "";
unset($id);
echo $xml;
$this->writeSocket($xml);
$this->close();
}
else
{
//$this->writeLog("ERROR: SendMessage() #2");
return false;
}
}
}
?>