[55] | 1 | <?php |
---|
| 2 | |
---|
| 3 | ini_set('include_path', $_SERVER['DOCUMENT_ROOT'] . '/instant_messenger/inc/'); |
---|
| 4 | |
---|
| 5 | require_once 'Jabber.abstract.php'; |
---|
| 6 | |
---|
| 7 | class Jabberd2 extends Jabber |
---|
| 8 | { |
---|
[164] | 9 | final function connect($pUser = false, $pPassword = false, $pConnectionType = false) |
---|
[151] | 10 | { |
---|
| 11 | try |
---|
| 12 | { |
---|
[164] | 13 | if ( $pUser && $pPassword && $pConnectionType ) |
---|
| 14 | if ( $_connect = parent::connect($pUser, $pPassword, $pConnectionType) ) |
---|
| 15 | return $_connect; |
---|
[55] | 16 | |
---|
[151] | 17 | return false; |
---|
| 18 | } |
---|
| 19 | catch(Exception $e) |
---|
| 20 | { |
---|
| 21 | $this->writeLog('ERROR', $e->getMessage()); |
---|
| 22 | return false; |
---|
| 23 | } |
---|
| 24 | } |
---|
[55] | 25 | |
---|
[151] | 26 | function closeSocket() |
---|
| 27 | { |
---|
| 28 | $this->close($this->_socket); |
---|
| 29 | } |
---|
[55] | 30 | |
---|
[151] | 31 | function disconnect() |
---|
| 32 | { |
---|
| 33 | $this->_disconnect(); |
---|
| 34 | } |
---|
[55] | 35 | |
---|
[151] | 36 | final function readSocket() |
---|
[55] | 37 | { |
---|
[151] | 38 | return $this->read(); |
---|
[55] | 39 | } |
---|
| 40 | |
---|
[151] | 41 | final function writeSocket($pData) |
---|
| 42 | { |
---|
| 43 | return $this->write($pData); |
---|
| 44 | } |
---|
[55] | 45 | |
---|
| 46 | /* |
---|
[151] | 47 | * Jabber - Functions |
---|
[55] | 48 | */ |
---|
| 49 | |
---|
[151] | 50 | final function addContacts($pContact) |
---|
| 51 | { |
---|
| 52 | $jid = explode("@",$pContact['email']); |
---|
| 53 | $jid = $jid[0]."@".$this->_server; |
---|
| 54 | $name = $pContact['name']; |
---|
| 55 | $group = $pContact['group']; |
---|
| 56 | |
---|
| 57 | if(trim($jid[0]) != trim($this->_user)) |
---|
| 58 | { |
---|
| 59 | if ( $jid ) |
---|
| 60 | { |
---|
| 61 | $newcontact = "<item jid='".$jid."'"; |
---|
| 62 | $newcontact .= " name='" . $name . "'"; |
---|
| 63 | $newcontact .= "><group>" . $group . "</group></item>"; |
---|
| 64 | } |
---|
| 65 | } |
---|
| 66 | $addid = "adduser_" . time(); |
---|
| 67 | if ( !$this->connected ) |
---|
| 68 | echo "disconnected"; |
---|
| 69 | else |
---|
| 70 | { |
---|
[164] | 71 | if ( $this->writeSocket($this->iq('set', $addid, NULL, NULL, "jabber:iq:roster", $newcontact)) ) |
---|
[151] | 72 | $this->getContacts(); |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | final function getContacts() |
---|
| 77 | { |
---|
[55] | 78 | $this->iq('get', 'contacts', NULL, NULL, 'jabber:iq:roster'); |
---|
[151] | 79 | } |
---|
| 80 | |
---|
| 81 | final function getVcard($pJid) |
---|
[55] | 82 | { |
---|
[164] | 83 | if ( is_array($pJid) ) |
---|
[151] | 84 | { |
---|
[164] | 85 | $jid = ( trim($pJid['jid']) == "this" ) ? $this->_user . '@' . $this->_server : $pJid['jid']; |
---|
[151] | 86 | |
---|
| 87 | if ( !$this->connected ) |
---|
| 88 | echo "disconnected"; |
---|
| 89 | else |
---|
| 90 | $this->writeSocket($this->iq('get', 'vCard', $jid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>")); |
---|
| 91 | } |
---|
| 92 | else |
---|
| 93 | { |
---|
| 94 | $this->iq('get', 'vCard', $pJid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>"); |
---|
| 95 | } |
---|
[55] | 96 | } |
---|
| 97 | |
---|
[151] | 98 | final function newVcard($NewVcard) |
---|
[55] | 99 | { |
---|
[151] | 100 | $id = $this->_user; |
---|
| 101 | |
---|
| 102 | if ( !$this->connected ) |
---|
| 103 | echo "disconnected"; |
---|
| 104 | else |
---|
| 105 | $this->writeSocket($this->iq('set', $id, NULL, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'>".$NewVcard['vcard']."</vCard>")); |
---|
[55] | 106 | } |
---|
[164] | 107 | |
---|
[151] | 108 | final function removeContact($pContact) |
---|
| 109 | { |
---|
| 110 | $delid = 'deluser_' . time(); |
---|
[164] | 111 | if ( !$this->connected ) |
---|
[151] | 112 | echo "disconnected"; |
---|
| 113 | else |
---|
| 114 | { |
---|
[164] | 115 | if ( $this->writeSocket($this->iq('set',$delid,NULL,NULL,"jabber:iq:roster","<item jid='".$pContact['jid']."' subscription='remove'/>")) ) |
---|
| 116 | if ( $this->subscription($pContact['jid'],"unsubscribed") ) |
---|
| 117 | echo "OK"; |
---|
[151] | 118 | } |
---|
| 119 | } |
---|
[55] | 120 | |
---|
[151] | 121 | final function subscription($pTo, $pType = false) |
---|
[55] | 122 | { |
---|
[151] | 123 | $jid = (is_array($pTo)) ? $pTo['jid'] : $pTo ; |
---|
| 124 | $type = (is_array($pTo)) ? $pTo['type'] : $pType ; |
---|
| 125 | |
---|
| 126 | if ( !$this->connected ) |
---|
| 127 | return false; |
---|
| 128 | else |
---|
| 129 | { |
---|
| 130 | $this->writeSocket("<presence xmlns='jabber:client' from='".$this->_user."@".$this->_server."' type='".$type."' to='".$jid."'/>"); |
---|
[164] | 131 | return true; |
---|
[151] | 132 | } |
---|
[55] | 133 | } |
---|
| 134 | |
---|
[151] | 135 | final function setPresence($pPresence = false) |
---|
[55] | 136 | { |
---|
[151] | 137 | if ( !$pPresence ) |
---|
| 138 | $this->presence(); |
---|
| 139 | |
---|
| 140 | $type = ( isset($pPresence['type']) ) ? $pPresence['type'] : NULL; |
---|
| 141 | $to = ( isset($pPresence['to']) ) ? $pPresence['to'] : NULL; |
---|
| 142 | $show = ( isset($pPresence['show']) ) ? $pPresence['show'] : NULL; |
---|
| 143 | $status = ( isset($pPresence['status']) ) ? $pPresence['status'] : NULL; |
---|
| 144 | $priority = ( isset($pPresence['priority']) ) ? $pPresence['priority'] : NULL; |
---|
| 145 | |
---|
| 146 | $this->presence($type, $to, $show, $status, $priority); |
---|
[55] | 147 | } |
---|
[151] | 148 | |
---|
| 149 | final function updateContact($pContact) |
---|
| 150 | { |
---|
| 151 | $jid = $pContact['jid']; |
---|
| 152 | $name = $pContact['name']; |
---|
| 153 | $group = $pContact['group']; |
---|
| 154 | |
---|
| 155 | if ( $jid ) |
---|
| 156 | { |
---|
| 157 | $updatecontact = "<item jid='$jid'"; |
---|
| 158 | $updatecontact .= " name='" . $name . "'"; |
---|
| 159 | $updatecontact .= "><group>" . $group . "</group></item>"; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | $upid = 'updateuser_' . time(); |
---|
| 163 | if ( !$this->connected ) |
---|
| 164 | echo "disconnected"; |
---|
| 165 | else |
---|
| 166 | { |
---|
| 167 | $this->writeSocket($this->iq('set', $upid, NULL, NULL, "jabber:iq:roster", $updatecontact)); |
---|
| 168 | $this->getContacts(); |
---|
| 169 | echo "OK"; |
---|
| 170 | } |
---|
| 171 | } |
---|
[55] | 172 | } |
---|
| 173 | ?> |
---|