[20] | 1 | <?php |
---|
| 2 | |
---|
[151] | 3 | require_once 'Jabberd2.abstract.php'; |
---|
| 4 | |
---|
| 5 | class Ujabber extends Jabberd2 |
---|
[20] | 6 | { |
---|
[151] | 7 | public final function __construct() |
---|
| 8 | { |
---|
| 9 | session_start(); |
---|
[64] | 10 | |
---|
[151] | 11 | $_user = $_SESSION['phpgw_info']['instant_messenger']['user']; |
---|
| 12 | $_pass = $_SESSION['phpgw_info']['instant_messenger']['passwd']; |
---|
| 13 | $_server = $_SESSION['phpgw_info']['instant_messenger']['name_jabber']; |
---|
| 14 | $_port = $_SESSION['phpgw_info']['instant_messenger']['port_jabber']; |
---|
| 15 | $_resource = $_SESSION['phpgw_info']['instant_messenger']['resource_jabber']; |
---|
[73] | 16 | |
---|
[151] | 17 | session_write_close(); |
---|
[64] | 18 | |
---|
[151] | 19 | if ( $this->connect($_user . '@' . $_server . '/' . $_resource . ':' . $_port, $_pass) ) |
---|
| 20 | $this->connected = true; |
---|
| 21 | else |
---|
| 22 | $this->connected = false; |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | } |
---|
[41] | 26 | |
---|
[151] | 27 | public final function __destruct() |
---|
| 28 | { |
---|
| 29 | $this->closeSocket(); |
---|
| 30 | } |
---|
[41] | 31 | |
---|
[151] | 32 | public final function listen() |
---|
| 33 | { |
---|
| 34 | if ( !$this->connected ) |
---|
| 35 | return "disconnected"; |
---|
[41] | 36 | |
---|
[151] | 37 | if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) |
---|
[72] | 38 | { |
---|
[151] | 39 | sleep(1); |
---|
| 40 | $xml = $this->readSocket(); |
---|
| 41 | printf("%s", $xml); |
---|
[72] | 42 | } |
---|
| 43 | else |
---|
[151] | 44 | { |
---|
| 45 | ob_end_clean(); |
---|
| 46 | ignore_user_abort(true); |
---|
| 47 | ob_start(); |
---|
[41] | 48 | |
---|
[151] | 49 | $init = time(); |
---|
[41] | 50 | |
---|
[151] | 51 | while ( !connection_aborted() && time() - $init < 10 ) |
---|
| 52 | { |
---|
| 53 | # read from server and write in the client |
---|
| 54 | $xml = $this->readSocket(); |
---|
| 55 | $xml = ( strlen($xml) ) ? $xml : ' '; |
---|
| 56 | printf("%s", $xml ); |
---|
[20] | 57 | |
---|
[151] | 58 | ob_flush(); |
---|
| 59 | flush(); |
---|
| 60 | usleep(6000); |
---|
| 61 | } |
---|
[41] | 62 | |
---|
[151] | 63 | ob_end_flush(); |
---|
| 64 | } |
---|
| 65 | } |
---|
[41] | 66 | |
---|
[151] | 67 | public final function SendMessage($pSendMessage) |
---|
| 68 | { |
---|
| 69 | $pSendMessage['body'] = stripslashes($pSendMessage['body']); |
---|
[41] | 70 | |
---|
[151] | 71 | $patterns = array('/ | +/i', '/<br[^>]*>/i'); |
---|
| 72 | $replace = array(' ', '<br />'); |
---|
| 73 | $pSendMessage['body'] = preg_replace($patterns, $replace, $pSendMessage['body']); |
---|
[41] | 74 | |
---|
[151] | 75 | $_emotions = '/<img emotion="(\S+)?"[^>]+>/'; |
---|
| 76 | $_emotions = preg_match_all($_emotions, $pSendMessage['body'], $emotions); |
---|
[41] | 77 | |
---|
[151] | 78 | foreach ( $emotions[0] as $key => $val ) |
---|
| 79 | $emotions[0][$key] = '/' . addcslashes($val, './()[]{}^$*&?') . '/i'; |
---|
[20] | 80 | |
---|
[151] | 81 | $pSendMessage['body'] = preg_replace($emotions[0], $emotions[1], $pSendMessage['body']); |
---|
[41] | 82 | |
---|
[151] | 83 | $to = $pSendMessage['to']; |
---|
| 84 | $type = "chat"; |
---|
| 85 | $id = ""; |
---|
| 86 | $content = array( |
---|
| 87 | "subject" => $pSendMessage['subject'] ? $pSendMessage['subject'] : "", |
---|
| 88 | "thread" => $pSendMessage['thread'] ? $pSendMessage['thread'] : "", |
---|
| 89 | "body" => $pSendMessage['body'] ? $pSendMessage['body'] : "" |
---|
| 90 | ); |
---|
[20] | 91 | |
---|
[151] | 92 | $payload = ""; |
---|
[41] | 93 | |
---|
[151] | 94 | if ($to && is_array($content)) |
---|
| 95 | { |
---|
| 96 | if (!$id) |
---|
| 97 | { |
---|
| 98 | $id = $type . "_" . time(); |
---|
| 99 | } |
---|
[41] | 100 | |
---|
[151] | 101 | $xml = "<message to='$to' type='$type' id='$id'>"; |
---|
[41] | 102 | |
---|
[151] | 103 | if ($content['subject']) |
---|
| 104 | { |
---|
| 105 | $xml .= "<subject>" . $content['subject'] . "</subject>"; |
---|
| 106 | } |
---|
[41] | 107 | |
---|
[151] | 108 | if ($content['thread']) |
---|
| 109 | { |
---|
| 110 | $xml .= "<thread>" . $content['thread'] . "</thread>"; |
---|
| 111 | } |
---|
[41] | 112 | |
---|
[151] | 113 | //Linha abaixo dentro do padrão xmpp, entretanto clientes como |
---|
| 114 | //o PSI não seguem o padrão assim ocorre problemas de comunicação |
---|
| 115 | //descomentar e retirar a seguinte para voltar ao padrão assim |
---|
| 116 | //que possÃvel |
---|
| 117 | //24/10/2007 - problema verificado por usuários do SERPRO na |
---|
| 118 | //plataforma Windows ocorrendo também no cliente Linux |
---|
| 119 | //por Alexandre e Rodrigo |
---|
[41] | 120 | |
---|
[151] | 121 | //$xml .= "<html><body>" . $content['body'] . "</body></html>"; |
---|
[41] | 122 | |
---|
[151] | 123 | //retirar a linha abaixo para voltar ao padrão conforme acima |
---|
| 124 | $xml .= "<body>" . $content['body'] . "</body>"; |
---|
| 125 | $xml .= $payload; |
---|
| 126 | $xml .= "</message>"; |
---|
| 127 | unset($id); |
---|
[41] | 128 | |
---|
[151] | 129 | echo $xml; |
---|
| 130 | $this->writeSocket($xml); |
---|
| 131 | $this->close(); |
---|
| 132 | } |
---|
| 133 | else |
---|
| 134 | { |
---|
| 135 | //$this->writeLog("ERROR: SendMessage() #2"); |
---|
| 136 | return false; |
---|
| 137 | } |
---|
| 138 | } |
---|
[20] | 139 | } |
---|
| 140 | ?> |
---|