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