_server = constant('IM_NAME_JABBER');
$this->_resource = constant('IM_RESOURCE_JABBER');
$this->_port = constant('IM_PORT_JABBER');
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('IM_SERVER_WEBJABBER')) )
$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";
$this->get_last_access_user();
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 = '';
$send_last_access = time();
while ( (connection_aborted() === 0) && (time() - $init < 50) )
{
if ( (time() - $send_last_access) > 15 )
{
$this->get_last_access_user();
$send_last_access = time();
}
# 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 update()
{
$presence = $_COOKIE['IM_presence'];
if ( !$presence )
$presence = 'available';
switch ( $presence )
{
case 'away':
case 'dnd':
case 'xa':
$presence = array('show' => $presence);
break;
case 'available':
case 'unavailable':
$presence = array('type' => $presence);
break;
}
$this->getContacts();
$this->setPresence(array('type'=>'unavailable'));
$this->setPresence($presence);
print_r($presence);
}
public final function Composing($pJid)
{
$pJid = $pJid['jid'];
$id = 'chat' . "_" . time();
$xml = "";
$this->writeSocket($xml);
}
public final function Paused($pJid)
{
$pJid = $pJid['jid'];
$id = 'chat' . "_" . time();
$xml = "";
$this->writeSocket($xml);
}
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;
}
}
}
?>