[151] | 1 | <?php |
---|
| 2 | |
---|
| 3 | class Ujabber |
---|
| 4 | { |
---|
| 5 | /* |
---|
| 6 | * Listen |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | final function listen() |
---|
| 10 | { |
---|
| 11 | $return = null; |
---|
| 12 | |
---|
| 13 | if($_SESSION['phpgw_info']['instant_messenger']['IM_disconnect']) |
---|
| 14 | { |
---|
| 15 | $_SESSION['phpgw_info']['instant_messenger']['IM_disconnect'] = false; |
---|
| 16 | return "disconnected"; |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | $_SESSION['phpgw_info']['instant_messenger']['timeClient'] = time(); |
---|
| 20 | $_SESSION['phpgw_info']['instant_messenger']['socket']['block'] = true; |
---|
| 21 | $xml = $_SESSION['phpgw_info']['instant_messenger']['socket']['in']; |
---|
| 22 | |
---|
| 23 | unset($_SESSION['phpgw_info']['instant_messenger']['socket']['in']); |
---|
| 24 | $_SESSION['phpgw_info']['instant_messenger']['socket']['block'] = false; |
---|
| 25 | |
---|
| 26 | ### Arranjo Tecnico ### |
---|
| 27 | $vkrd = $xml; |
---|
| 28 | |
---|
| 29 | if(isset($_SESSION['phpgw_info']['instant_messenger']['contacts'])) |
---|
| 30 | unset($_SESSION['phpgw_info']['instant_messenger']['contacts']); |
---|
| 31 | |
---|
| 32 | ### - messages - ### |
---|
| 33 | $_messages = "/<message[^>]+from='(\S+)'[^>]*>(?(?=.*?<composing |.*?<paused ).*?<(composing|paused) )(?(?=.*?<html).*?<html[^>]*><body[^>]*>(.*?)<\/body><\/html>).*?<\/message>/s"; |
---|
| 34 | $_messages = preg_match_all($_messages, $xml, $messages); |
---|
| 35 | if ( $_messages !== false && $_messages > 0 ) |
---|
| 36 | { |
---|
| 37 | $xml = preg_replace("/<message.*?<\/message>/", "", $xml); |
---|
| 38 | $return .= $this->getMessages($messages); |
---|
| 39 | } |
---|
| 40 | ### - Fim messages - ### |
---|
| 41 | |
---|
| 42 | ### - contacts - ### |
---|
| 43 | $_contacts = "/<iq[^>]+id='contacts'[^>]*>.*?<\/iq>/"; |
---|
| 44 | $_contacts = preg_match_all($_contacts, $xml, $_xml); |
---|
| 45 | |
---|
| 46 | $_contacts = "/<item.*?(?(?=[^>]+name)[^>]+name='(.*?)')[^>]+subscription='(.*?)'[^>]+jid='(.*?)'"; |
---|
| 47 | $_contacts .= "(?(?=[^>]*\/>)[^>]*\/>|[^>]*><group>(.*?)<\/group><\/item>)/"; |
---|
| 48 | $_contacts = preg_match_all($_contacts, $_xml[0][0], $contacts); |
---|
| 49 | if ( $_contacts !== false && $_contacts > 0 ) |
---|
| 50 | { |
---|
| 51 | $xml = preg_replace("/<iq[^>]+id='contacts'[^>]*>.*?<\/iq>/", "", $xml); |
---|
| 52 | $return .= rawurldecode(urldecode($this->getContacts($contacts))); |
---|
| 53 | } |
---|
| 54 | ### - Fim contacts - ### |
---|
| 55 | |
---|
| 56 | ### - presence - ### |
---|
| 57 | $xml = $_SESSION['phpgw_info']['instant_messenger']['presences'] . $xml; |
---|
| 58 | |
---|
| 59 | $_presence = "/<presence(?(?=[^>]+\/>)[^>]+\/>|[^>]+>.*?<\/presence>)/"; |
---|
| 60 | $_presence = preg_match_all($_presence, $xml, $presence); |
---|
| 61 | |
---|
| 62 | $patterns[0] = '/<priority>[^<]*<\/priority>|<(\S) (?(?=[^>]*\/>)[^>]*\/>|[^>]*>.*?<\/\1>)/'; |
---|
| 63 | $patterns[1] = '/ xmlns=\'.*?\'| to=\'.*?\'/'; |
---|
| 64 | $patterns[2] = '/> +</'; |
---|
| 65 | $replacements[0] = ''; |
---|
| 66 | $replacements[1] = ''; |
---|
| 67 | $replacements[2] = '><'; |
---|
| 68 | $_xml = preg_replace($patterns, $replacements, implode('', $presence[0])); |
---|
| 69 | |
---|
| 70 | $_presence = "/<presence[^>]+from='(\S+)'[^>]*type='(unavailable)'(?(?=[^>]*\/>)[^>]*\/>|[^>]*>.*?<\/presence>)|"; |
---|
| 71 | $_presence .= "<presence[^>]+from='(\S+)'(?(?=[^>]+type)[^>]+type='(\S+)')[^>]*"; |
---|
| 72 | $_presence .= "(?(?=\/>)\/>|>"; |
---|
| 73 | $_presence .= "(?(?=<s[^>]*?>)<s[^>]*?>(.*?)<\/s[^>]*?>(?(?=<s[^>]*?>)<s[^>]*?>(.*?)<\/s[^>]*?>))"; |
---|
| 74 | $_presence .= "<\/presence>)/"; |
---|
| 75 | $_presence = preg_match_all($_presence, $_xml, $presence); |
---|
| 76 | if ( $_presence !== false && $_presence > 0 ) |
---|
| 77 | { |
---|
| 78 | foreach ( $presence[5] as $key => $val ) |
---|
| 79 | { |
---|
| 80 | if ( !empty($presence[1][$key]) && (strpos($presence[1][$key], '/') !== false) ) |
---|
| 81 | $presence[1][$key] = substr($presence[1][$key], 0, strpos($presence[1][$key], '/')); |
---|
| 82 | |
---|
| 83 | if ( !empty($presence[3][$key]) && strpos($presence[3][$key], '/') !== false ) |
---|
| 84 | $presence[3][$key] = substr($presence[3][$key], 0, strpos($presence[3][$key], '/')); |
---|
| 85 | |
---|
| 86 | if ( !empty($val) && !preg_match("/^(away|chat|dnd|xa)$/", $val) ) |
---|
| 87 | if ( preg_match("/^(away|chat|dnd|xa)$/", $presence[6][$key]) ) |
---|
| 88 | { |
---|
| 89 | $aux = $presence[5][$key]; |
---|
| 90 | $presence[5][$key] = $presence[6][$key]; |
---|
| 91 | $presence[6][$key] = $aux; |
---|
| 92 | } |
---|
| 93 | else |
---|
| 94 | { |
---|
| 95 | if ( empty($presence[6][$key]) ) |
---|
| 96 | $presence[6][$key] = $presence[5][$key]; |
---|
| 97 | $presence[5][$key] = ''; |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | $xml = preg_replace("/<presence[^>]\/?>|<presence[^>]>.*?<\/presence>/", "", $xml); |
---|
| 101 | |
---|
| 102 | $return .= $this->getPresence($presence); |
---|
| 103 | } |
---|
| 104 | ### - Fim presence - ### |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | ### - vcard - ### |
---|
| 108 | ### - Arranjo Tecnico - ### |
---|
| 109 | $_xml = $vkrd; |
---|
| 110 | $_vcard = "/<iq.*? id='(.*?)' .*?(<vCard [^>]+\/>|<vCard.*?<\/vCard>)<\/iq>/"; |
---|
| 111 | $_vcard = preg_match_all($_vcard, $_xml, $vcard); |
---|
| 112 | if( $_vcard !== false && $_vcard > 0) |
---|
| 113 | { |
---|
| 114 | $xml = preg_replace("/<iq.*?<vCard.*?<\/iq>/", "", $xml); |
---|
| 115 | $return .= urldecode($this->getVcard($vcard)); |
---|
| 116 | } |
---|
| 117 | ### - Fim vcard - ### |
---|
| 118 | ## Final do Listen; |
---|
| 119 | |
---|
| 120 | return $return; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | function reconnect() |
---|
| 124 | { |
---|
| 125 | require_once("IMConfigure.php"); |
---|
| 126 | |
---|
| 127 | $_transport = TRANSPORT_NON_SECURITY; |
---|
| 128 | $_port = PORT_NON_SECURITY; |
---|
| 129 | |
---|
| 130 | $SERVER = "127.0.0.1"; |
---|
| 131 | |
---|
| 132 | $fp = ""; |
---|
| 133 | @$fp = stream_socket_client($_transport . "://" . $SERVER . ":" . $_port, $errno, $errstr, 10); |
---|
| 134 | |
---|
| 135 | if ( $fp ) |
---|
| 136 | { |
---|
| 137 | fwrite($fp, "GET /" . CONNECT . ";" . session_id() . " HTTP/1.1\r\nHost: " . $SERVER . ":" . $_port . "\r\nAccept: */*\r\n\r\n"); |
---|
| 138 | return 'true'; |
---|
| 139 | } |
---|
| 140 | else |
---|
| 141 | return 'false'; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | /* |
---|
| 145 | * Contacts |
---|
| 146 | */ |
---|
| 147 | |
---|
| 148 | function getContacts(array $pContacts) |
---|
| 149 | { |
---|
| 150 | $_group = array(); |
---|
| 151 | $return = NULL; |
---|
| 152 | $jid = array_unique($pContacts[3]); |
---|
| 153 | |
---|
| 154 | foreach ( $jid as $key => $val ) |
---|
| 155 | { |
---|
| 156 | $_SESSION['phpgw_info']['instant_messenger']['contacts'][] = $val; |
---|
| 157 | |
---|
| 158 | $item = NULL; |
---|
| 159 | $item .= '<item name="' . (( !empty($pContacts[1][$key]) ) ? $pContacts[1][$key] : $val); |
---|
| 160 | $item .= '" jid="' . $val; |
---|
| 161 | $item .= '" subscription="' . $pContacts[2][$key]; |
---|
| 162 | $item .= '" />'; |
---|
| 163 | |
---|
| 164 | $_group[utf8_decode(strtolower(!empty($pContacts[4][$key]) ? $pContacts[4][$key] : 'default'))][] = $item; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | ksort($_group); |
---|
| 168 | |
---|
| 169 | foreach ( $_group as $key => $val ) |
---|
| 170 | $return .= '<group name="' . $key . '">' . implode('', $val) . '</group>'; |
---|
| 171 | |
---|
| 172 | return '<contacts>' . $return . '</contacts>'; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | function requireContacts() |
---|
| 176 | { |
---|
| 177 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['getContacts'] = NULL; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | /* |
---|
| 181 | * Presence |
---|
| 182 | */ |
---|
| 183 | |
---|
| 184 | function setPresence($pPresence) |
---|
| 185 | { |
---|
| 186 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['setPresence'] = $pPresence; |
---|
| 187 | foreach($pPresence as $key=>$presence) |
---|
| 188 | if($key == 'show' || $key == 'type') |
---|
| 189 | { |
---|
| 190 | $_SESSION['phpgw_info']['instant_messenger']['MyPresence'] = $presence; |
---|
| 191 | } |
---|
| 192 | } |
---|
| 193 | |
---|
| 194 | function MyPresence() |
---|
| 195 | { |
---|
| 196 | if(isset($_SESSION['phpgw_info']['instant_messenger']['MyPresence'])) |
---|
| 197 | return $_SESSION['phpgw_info']['instant_messenger']['MyPresence']; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | function getPresence(array $pPresence) |
---|
| 201 | { |
---|
| 202 | $offline = array(); |
---|
| 203 | foreach ( $pPresence[1] as $key => $val ) |
---|
| 204 | { |
---|
| 205 | if ( empty($val) ) |
---|
| 206 | continue; |
---|
| 207 | |
---|
| 208 | $_offline = true; |
---|
| 209 | for ( $i = $key; $i < sizeof($pPresence[1]); $i++ ) |
---|
| 210 | if ( $pPresence[1][$key] == $pPresence[3][$i] || $pPresence[1][$key] == $pPresence[5][$i] ) |
---|
| 211 | $_offline = false; |
---|
| 212 | |
---|
| 213 | if ( $_offline ) |
---|
| 214 | $offline[$key] = $val; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | $online = array(); |
---|
| 218 | foreach ( $pPresence[3] as $key => $val ) |
---|
| 219 | { |
---|
| 220 | if ( empty($val) ) |
---|
| 221 | continue; |
---|
| 222 | |
---|
| 223 | $_online = true; |
---|
| 224 | for ( $i = ($key + 1); $i < sizeof($pPresence[3]); $i++ ) |
---|
| 225 | if ( in_array($val, $offline) || $pPresence[3][$key] == $pPresence[3][$i] ) |
---|
| 226 | $_online = false; |
---|
| 227 | |
---|
| 228 | if ( $_online ) |
---|
| 229 | $online[$key] = $val; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | $return = NULL; |
---|
| 233 | |
---|
| 234 | foreach ( $offline as $key => $val ) |
---|
| 235 | { |
---|
| 236 | $val = ( strpos($val, '/') ) ? substr($val, 0, strpos($val, '/')) : $val; |
---|
| 237 | $return .= "<presence from='" . $val . "' type='unavailable' />"; |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | foreach ( $online as $key => $val ) |
---|
| 241 | { |
---|
| 242 | $val = ( strpos($val, '/') ) ? substr($val, 0, strpos($val, '/')) : $val; |
---|
| 243 | |
---|
| 244 | if ( empty($pPresence[4][$key]) ) |
---|
| 245 | $pPresence[4][$key] = ( empty($pPresence[5][$key]) ) ? |
---|
| 246 | 'available' : $pPresence[5][$key]; |
---|
| 247 | |
---|
| 248 | $return .= "<presence from='" . $val . "' type='" . $pPresence[4][$key]; |
---|
| 249 | if ( empty($pPresence[6][$key]) ) |
---|
| 250 | $return .= "' />"; |
---|
| 251 | else |
---|
| 252 | $return .= "'>" . $pPresence[6][$key] . "</presence>"; |
---|
| 253 | |
---|
| 254 | if ( strpos($pPresence[4][$key], 'subscribe') === false ) |
---|
| 255 | { |
---|
| 256 | $session .= "<presence from='" . $val . "'><show>" . $pPresence[4][$key] . "</show>"; |
---|
| 257 | if ( !empty($pPresence[6][$key]) ) |
---|
| 258 | $session .= "<status>" . $pPresence[6][$key] . "</status>"; |
---|
| 259 | $session .= "</presence>"; |
---|
| 260 | } |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | $_SESSION['phpgw_info']['instant_messenger']['presences'] = $session; |
---|
| 264 | |
---|
| 265 | return $return; |
---|
| 266 | } |
---|
| 267 | |
---|
| 268 | /* |
---|
| 269 | * GetMessage |
---|
| 270 | */ |
---|
| 271 | |
---|
| 272 | function getMessages(array $pMessages) |
---|
| 273 | { |
---|
| 274 | $_messages = array(); |
---|
| 275 | $return = NULL; |
---|
| 276 | |
---|
| 277 | foreach ( $pMessages[1] as $key => $val ) |
---|
| 278 | { |
---|
| 279 | trim($pMessages[3][$key]); |
---|
| 280 | if ( !empty($pMessages[3][$key]) ) |
---|
| 281 | $_messages[$val][] = $pMessages[3][$key]; |
---|
| 282 | |
---|
| 283 | if ( !empty($pMessages[2][$key]) ) |
---|
| 284 | { |
---|
| 285 | $return .= '<' . $pMessages[2][$key] . ' from="'; |
---|
| 286 | $return .= ( strpos($val, '/') ) ? substr($val, 0, strpos($val, '/')) : $val; |
---|
| 287 | $return .= '" />'; |
---|
| 288 | } |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | foreach ( $_messages as $key => $val ) |
---|
| 292 | { |
---|
| 293 | $return .= '<messages from="' . $key . '">'; |
---|
| 294 | foreach ( $val as $msg ) |
---|
| 295 | $return .= '<message>' . $msg . '</message>'; |
---|
| 296 | $return .= '</messages>'; |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | return $return; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | /* |
---|
| 303 | * SendMessage |
---|
| 304 | */ |
---|
| 305 | |
---|
| 306 | function SendMessage($pSendMessage) |
---|
| 307 | { |
---|
| 308 | $pSendMessage['body'] = stripslashes($pSendMessage['body']); |
---|
| 309 | $_emotions = '/<img emotion="(\S+)?"[^>]+>/'; |
---|
| 310 | $_emotions = preg_match_all($_emotions, $pSendMessage['body'], $emotions); |
---|
| 311 | |
---|
| 312 | foreach ( $emotions[0] as $key => $val ) |
---|
| 313 | $emotions[0][$key] = '/' . addcslashes($val, './()[]{}^$*&?') . '/i'; |
---|
| 314 | |
---|
| 315 | $pSendMessage['body'] = preg_replace($emotions[0], $emotions[1], $pSendMessage['body']); |
---|
| 316 | |
---|
| 317 | $to = $pSendMessage['to']; |
---|
| 318 | $type = "normal"; |
---|
| 319 | $id = ""; |
---|
| 320 | $content = array( |
---|
| 321 | "subject" => $pSendMessage['subject'] ? $pSendMessage['subject'] : "", |
---|
| 322 | "thread" => $pSendMessage['thread'] ? $pSendMessage['thread'] : "", |
---|
| 323 | "body" => $pSendMessage['body'] ? $pSendMessage['body'] : "" |
---|
| 324 | ); |
---|
| 325 | |
---|
| 326 | $payload = ""; |
---|
| 327 | |
---|
| 328 | if ($to && is_array($content)) |
---|
| 329 | { |
---|
| 330 | if (!$id) |
---|
| 331 | { |
---|
| 332 | $id = $type . "_" . time(); |
---|
| 333 | } |
---|
| 334 | |
---|
| 335 | $xml = "<message to='$to' type='$type' id='$id'>"; |
---|
| 336 | |
---|
| 337 | if ($content['subject']) |
---|
| 338 | { |
---|
| 339 | $xml .= "<subject>" . $content['subject'] . "</subject>"; |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | if ($content['thread']) |
---|
| 343 | { |
---|
| 344 | $xml .= "<thread>" . $content['thread'] . "</thread>"; |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | $xml .= "<html><body>" . $content['body'] . "</body></html>"; |
---|
| 348 | $xml .= $payload; |
---|
| 349 | $xml .= "</message>"; |
---|
| 350 | unset($id); |
---|
| 351 | |
---|
| 352 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['message'] .= $xml; |
---|
| 353 | } |
---|
| 354 | else |
---|
| 355 | { |
---|
| 356 | $this->writeLog("ERROR: SendMessage() #2"); |
---|
| 357 | return FALSE; |
---|
| 358 | } |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | /* |
---|
| 362 | * Composing / Paused Message |
---|
| 363 | */ |
---|
| 364 | |
---|
| 365 | function composingMessage($pComposing) |
---|
| 366 | { |
---|
| 367 | |
---|
| 368 | $xml = "<message xmlns='jabber:client' to='".$pComposing['to']."' id='".time()."' type='chat'>"; |
---|
| 369 | $xml .= "<x xmlns='jabber:x:event'>"; |
---|
| 370 | $xml .= "<composing/>"; |
---|
| 371 | $xml .= "</x>"; |
---|
| 372 | $xml .= "<composing xmlns='http://jabber.org/protocol/chatstates'/>"; |
---|
| 373 | $xml .= "</message>"; |
---|
| 374 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['message'] .= $xml; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | function pausedMessage($pComposing) |
---|
| 378 | { |
---|
| 379 | $xml = "<message xmlns='jabber:client' to='".$pComposing['to']."' id='".time()."' type='chat'>"; |
---|
| 380 | $xml .= "<x xmlns='jabber:x:event'/>"; |
---|
| 381 | $xml .= "<paused xmlns='http://jabber.org/protocol/chatstates'/>"; |
---|
| 382 | $xml .= "</message>"; |
---|
| 383 | |
---|
| 384 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['message'] .= $xml; |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | /* |
---|
| 388 | * UpdateContact |
---|
| 389 | */ |
---|
| 390 | |
---|
| 391 | function updateContact($pUser) |
---|
| 392 | { |
---|
| 393 | $jid = $pUser['jid']; |
---|
| 394 | $name = $pUser['name']; |
---|
| 395 | $group = $pUser['group']; |
---|
| 396 | |
---|
| 397 | if ( $jid ) |
---|
| 398 | { |
---|
| 399 | $updatecontact = "<item jid='$jid'"; |
---|
| 400 | $updatecontact .= " name='" . $name . "'"; |
---|
| 401 | $updatecontact .= "><group>" . $group . "</group></item>"; |
---|
| 402 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['updateContact'] = $updatecontact; |
---|
| 403 | } |
---|
| 404 | $this->requireContacts(); |
---|
| 405 | } |
---|
| 406 | |
---|
| 407 | /* |
---|
| 408 | * AddContact |
---|
| 409 | */ |
---|
| 410 | |
---|
| 411 | function addContacts($pUser) |
---|
| 412 | { |
---|
| 413 | $jid = explode("@",$pUser['email']); |
---|
| 414 | $pJid = $jid[0]."@".$_SESSION['phpgw_info']['instant_messenger']['name_jabber']; |
---|
| 415 | $pName = $pUser['name']; |
---|
| 416 | $pGroup = $pUser['group']; |
---|
| 417 | |
---|
| 418 | if(trim($jid[0]) != trim($this->username)) |
---|
| 419 | { |
---|
| 420 | if ( $pJid ) |
---|
| 421 | { |
---|
| 422 | $newcontact = "<item jid='$pJid'"; |
---|
| 423 | $newcontact .= " name='" . $pName . "'"; |
---|
| 424 | $newcontact .= "><group>" . $pGroup . "</group></item>"; |
---|
| 425 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['addContacts'] = $newcontact; |
---|
| 426 | $this->subscribe($pJid); |
---|
| 427 | $this->requireContacts(); |
---|
| 428 | } |
---|
| 429 | } |
---|
| 430 | } |
---|
| 431 | |
---|
| 432 | /* |
---|
| 433 | * RemoveContact |
---|
| 434 | */ |
---|
| 435 | |
---|
| 436 | function removeContact($pUser) |
---|
| 437 | { |
---|
| 438 | $pJid = $pUser['jid']; |
---|
| 439 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['removeContact'] = $pJid; |
---|
| 440 | $this->unsubscribed($pJid); |
---|
| 441 | $this->requireContacts(); |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | /* |
---|
| 445 | * Vcard |
---|
| 446 | */ |
---|
| 447 | |
---|
| 448 | function newVcard($pVcardUser) |
---|
| 449 | { |
---|
| 450 | $pVcard = explode("_vkrd_", $pVcardUser['vcard']); |
---|
| 451 | |
---|
| 452 | $xmlVcard = "<FN>".$pVcard[0]."</FN>"; |
---|
| 453 | $xmlVcard .= "<NICKNAME>".$pVcard[1]."</NICKNAME>"; |
---|
| 454 | $xmlVcard .= "<ORG>"; |
---|
| 455 | $xmlVcard .= "<ORGNAME>".$pVcard[2]."</ORGNAME>"; |
---|
| 456 | $xmlVcard .= "<ORGUNIT>".$pVcard[3]."</ORGUNIT>"; |
---|
| 457 | $xmlVcard .= "</ORG>"; |
---|
| 458 | $xmlVcard .= "<ROLE>".$pVcard[4]."</ROLE>"; |
---|
| 459 | $xmlVcard .= "<BDAY>".$pVcard[5]."</BDAY>"; |
---|
| 460 | $xmlVcard .= "<DESC>".$pVcard[6]."</DESC>"; |
---|
| 461 | |
---|
| 462 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['newVcard'] = $xmlVcard; |
---|
| 463 | |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | function getVcard(array $Vcard) |
---|
| 467 | { |
---|
| 468 | $div = ""; |
---|
| 469 | $_expr = "/<[^<vCard xmlns=\'vcard\-temp\'>].*[^<\/vCard>]>/"; |
---|
| 470 | array_shift($Vcard); |
---|
| 471 | $div = '<vcard>'; |
---|
| 472 | $jid_user = $_SESSION['phpgw_info']['instant_messenger']['user']; |
---|
| 473 | $jid_user .= "@" . $_SESSION['phpgw_info']['instant_messenger']['name_jabber']; |
---|
| 474 | for($i = 0 ; $i < count($Vcard[0]) ; $i++) |
---|
| 475 | { |
---|
| 476 | preg_match($_expr,$Vcard[1][$i],$div_vcard); |
---|
| 477 | $div_new[] = $div_vcard; |
---|
| 478 | |
---|
| 479 | if ( $jid_user == $Vcard[0][$i] ) |
---|
| 480 | $_SESSION['phpgw_info']['instant_messenger']['vcard'] = $div_new[$i][0]; |
---|
| 481 | |
---|
| 482 | $div .= '<div id="vcard_'.$Vcard[0][$i].'">'.urldecode($div_new[$i][0]).'</div>'; |
---|
| 483 | } |
---|
| 484 | $div .= '</vcard>'; |
---|
| 485 | |
---|
| 486 | return $div; |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | function Vcard() |
---|
| 490 | { |
---|
| 491 | $contacts = array(); |
---|
| 492 | $contacts = $_SESSION['phpgw_info']['instant_messenger']['contacts']; |
---|
| 493 | $jid_user = $this->getJid(); |
---|
| 494 | |
---|
| 495 | if( count($contacts) > 0 ) |
---|
| 496 | { |
---|
| 497 | array_unshift($contacts,$jid_user); |
---|
| 498 | |
---|
| 499 | foreach($contacts as $user) |
---|
| 500 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['vcard'][] = $user; |
---|
| 501 | return "true"; |
---|
| 502 | }else{ |
---|
| 503 | return "false"; |
---|
| 504 | } |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | function VcardUser() |
---|
| 508 | { |
---|
| 509 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['vcard'][] = $this->getJid();; |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | function getJid() |
---|
| 513 | { |
---|
| 514 | $jid = $_SESSION['phpgw_info']['instant_messenger']['user'] . "@" . $_SESSION['phpgw_info']['instant_messenger']['name_jabber']; |
---|
| 515 | return $jid; |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | function subscribe($pJid) |
---|
| 519 | { |
---|
| 520 | $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; |
---|
| 521 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['Subscribe'] = $jid; |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | function subscribed($pJid) |
---|
| 525 | { |
---|
| 526 | $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; |
---|
| 527 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['SubscriptionAcceptRequest'] = $jid; |
---|
| 528 | } |
---|
| 529 | |
---|
| 530 | function unsubscribe($pJid) |
---|
| 531 | { |
---|
| 532 | $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; |
---|
| 533 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['Unsubscribe'] = $jid; |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | function unsubscribed($pJid) |
---|
| 537 | { |
---|
| 538 | $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; |
---|
| 539 | $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['SubscriptionDenyRequest'] = $jid; |
---|
| 540 | } |
---|
| 541 | } |
---|
| 542 | ?> |
---|