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 | { |
---|
9 | final function connect($pUser = false, $pPassword = false, $pConnectionType = false, $pWebjabber = false ) |
---|
10 | { |
---|
11 | try |
---|
12 | { |
---|
13 | if ( $pUser && $pPassword && $pConnectionType ) |
---|
14 | if ( $_connect = parent::connect($pUser, $pPassword, $pConnectionType, $pWebjabber) ) |
---|
15 | return $_connect; |
---|
16 | |
---|
17 | return false; |
---|
18 | } |
---|
19 | catch(Exception $e) |
---|
20 | { |
---|
21 | $this->writeLog('ERROR', $e->getMessage()); |
---|
22 | return false; |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | function closeSocket() |
---|
27 | { |
---|
28 | $this->close($this->_socket); |
---|
29 | } |
---|
30 | |
---|
31 | function disconnect() |
---|
32 | { |
---|
33 | $this->_disconnect(); |
---|
34 | } |
---|
35 | |
---|
36 | final function readSocket() |
---|
37 | { |
---|
38 | return $this->read(); |
---|
39 | } |
---|
40 | |
---|
41 | final function writeSocket($pData) |
---|
42 | { |
---|
43 | return $this->write($pData); |
---|
44 | } |
---|
45 | |
---|
46 | /* |
---|
47 | * Jabber - Functions |
---|
48 | */ |
---|
49 | |
---|
50 | final function addRoster($pRoster) |
---|
51 | { |
---|
52 | if ( !$this->connected ) |
---|
53 | return "disconnected"; |
---|
54 | |
---|
55 | if ( trim($pRoster['uid']) ) |
---|
56 | { |
---|
57 | $jid = $pRoster['uid'] . "@" . $this->_server; |
---|
58 | |
---|
59 | $newroster = "<item jid='" . $jid . "'"; |
---|
60 | $newroster .= " name='" . $pRoster['name'] . "'"; |
---|
61 | $newroster .= "><group>" . $pRoster['group'] . "</group></item>"; |
---|
62 | |
---|
63 | if ( $this->iq('set', "addroster_" . time(), NULL, NULL, "jabber:iq:roster", $newroster) ) |
---|
64 | { |
---|
65 | $this->getContacts(); |
---|
66 | return true; |
---|
67 | } |
---|
68 | } |
---|
69 | return false; |
---|
70 | } |
---|
71 | |
---|
72 | final function addContact($pContact) |
---|
73 | { |
---|
74 | $this->addRoster($pContact); |
---|
75 | $this->subscription($pContact['uid'] . "@" . $this->_server, 'subscribe'); |
---|
76 | } |
---|
77 | |
---|
78 | final function getContacts() |
---|
79 | { |
---|
80 | if ( !$this->isConnected() ) |
---|
81 | return "disconnected"; |
---|
82 | |
---|
83 | $this->iq('get', 'contacts', NULL, NULL, 'jabber:iq:roster'); |
---|
84 | } |
---|
85 | |
---|
86 | final function getVcard($pJid) |
---|
87 | { |
---|
88 | if ( is_array($pJid) ) |
---|
89 | { |
---|
90 | $jid = ( trim($pJid['jid']) == "this" ) ? $this->_user . '@' . $this->_server : $pJid['jid']; |
---|
91 | $vcard = (trim($pJid['jid']) == "this") ? 'vCard_user' : 'vCard'; |
---|
92 | |
---|
93 | if ( !$this->connected ) |
---|
94 | { |
---|
95 | echo "disconnected"; |
---|
96 | } |
---|
97 | else |
---|
98 | { |
---|
99 | $this->iq('get', $vcard, $jid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>"); |
---|
100 | } |
---|
101 | } |
---|
102 | else |
---|
103 | { |
---|
104 | $this->iq('get', 'vCard', $pJid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>"); |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | final function newVcard($NewVcard) |
---|
109 | { |
---|
110 | $id = $this->_user; |
---|
111 | |
---|
112 | if ( !$this->connected ) |
---|
113 | echo "disconnected"; |
---|
114 | else |
---|
115 | { |
---|
116 | $this->iq('set', $id, NULL, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'>".$NewVcard['vcard']."</vCard>"); |
---|
117 | echo "OK"; |
---|
118 | } |
---|
119 | } |
---|
120 | |
---|
121 | final function removeContact($pContact) |
---|
122 | { |
---|
123 | if ( !$this->isConnected() ) |
---|
124 | return "disconnected"; |
---|
125 | |
---|
126 | if ( $this->iq('set', 'delroster_' . time(), NULL, NULL, 'jabber:iq:roster',"<item jid='".$pContact['jid']."' subscription='remove'/>") ) |
---|
127 | { |
---|
128 | $this->getContacts(); |
---|
129 | return true; |
---|
130 | } |
---|
131 | return false; |
---|
132 | } |
---|
133 | |
---|
134 | function allowContact($pRoster) |
---|
135 | { |
---|
136 | $this->addRoster($pRoster); |
---|
137 | $jid = $pRoster['uid'] . "@" . $this->_server; |
---|
138 | $this->subscription($jid, 'subscribed'); |
---|
139 | $this->subscription($jid, 'subscribe'); |
---|
140 | } |
---|
141 | |
---|
142 | final function subscription($pTo, $pType = false) |
---|
143 | { |
---|
144 | $jid = (is_array($pTo)) ? $pTo['jid'] : $pTo ; |
---|
145 | $type = (is_array($pTo)) ? $pTo['type'] : $pType ; |
---|
146 | |
---|
147 | if ( !$this->connected ) |
---|
148 | return false; |
---|
149 | else |
---|
150 | { |
---|
151 | $this->writeSocket("<presence xmlns='jabber:client' from='".$this->_user."@".$this->_server."' type='".$type."' to='".$jid."'/>"); |
---|
152 | return true; |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | final function setPresence($pPresence = false) |
---|
157 | { |
---|
158 | if ( !$this->isConnected() ) |
---|
159 | return "disconnected"; |
---|
160 | |
---|
161 | if ( !$pPresence ) |
---|
162 | $this->presence(); |
---|
163 | else |
---|
164 | { |
---|
165 | $type = ( isset($pPresence['type']) ) ? $pPresence['type'] : NULL; |
---|
166 | $to = ( isset($pPresence['to']) ) ? $pPresence['to'] : NULL; |
---|
167 | $show = ( isset($pPresence['show']) ) ? $pPresence['show'] : NULL; |
---|
168 | $status = ( isset($pPresence['status']) ) ? $pPresence['status'] : NULL; |
---|
169 | $priority = ( isset($pPresence['priority']) ) ? $pPresence['priority'] : NULL; |
---|
170 | |
---|
171 | $this->presence($type, $to, $show, $status, $priority); |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | final function get_last_access_user($pUser = array("jid" => "this")) |
---|
176 | { |
---|
177 | $id = "last_time_user"; |
---|
178 | $jid = ( trim($pUser['jid']) == "this" ) ? $this->_user . '@' . $this->_server : $pUser['jid']; |
---|
179 | $this->iq('get', $id, $jid, NULL, "jabber:iq:last"); |
---|
180 | } |
---|
181 | |
---|
182 | final function setStatus() |
---|
183 | { |
---|
184 | $this->setPresence(array("type" => "unavailable")); |
---|
185 | $this->setPresence(array("type" => "available")); |
---|
186 | } |
---|
187 | |
---|
188 | final function updateContact($pContact) |
---|
189 | { |
---|
190 | $jid = $pContact['jid']; |
---|
191 | $name = $pContact['name']; |
---|
192 | $group = $pContact['group']; |
---|
193 | |
---|
194 | if ( $jid ) |
---|
195 | { |
---|
196 | $updatecontact = "<item jid='$jid'"; |
---|
197 | $updatecontact .= " name='" . $name . "'"; |
---|
198 | $updatecontact .= "><group>" . $group . "</group></item>"; |
---|
199 | } |
---|
200 | |
---|
201 | $upid = 'updateuser_' . time(); |
---|
202 | if ( !$this->connected ) |
---|
203 | echo "disconnected"; |
---|
204 | else |
---|
205 | { |
---|
206 | $this->iq('set', $upid, NULL, NULL, "jabber:iq:roster", $updatecontact); |
---|
207 | $this->getContacts(); |
---|
208 | echo "OK"; |
---|
209 | } |
---|
210 | } |
---|
211 | } |
---|
212 | ?> |
---|