source: trunk/instant_messenger/inc/Jabberd2.abstract.php @ 311

Revision 311, 4.7 KB checked in by niltonneto, 16 years ago (diff)

Correções críticas para funcionalidades já existentes.

Line 
1<?php
2
3ini_set('include_path', $_SERVER['DOCUMENT_ROOT'] . '/instant_messenger/inc/');
4
5require_once 'Jabber.abstract.php';
6
7class 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
164                $type = ( isset($pPresence['type']) ) ? $pPresence['type'] : NULL;
165                $to = ( isset($pPresence['to']) ) ? $pPresence['to'] : NULL;
166                $show = ( isset($pPresence['show']) ) ? $pPresence['show'] : NULL;
167                $status = ( isset($pPresence['status']) ) ? $pPresence['status'] : NULL;
168                $priority = ( isset($pPresence['priority']) ) ? $pPresence['priority'] : NULL;
169
170                $this->presence($type, $to, $show, $status, $priority);
171        }
172
173        final function get_last_access_user($pUser)
174        {
175                $id = "last_time_user";
176                $jid = ( trim($pUser['jid']) == "this" ) ? $this->_user . '@' . $this->_server : $pUser['jid'];
177                $this->iq('get', $id, $jid, NULL, "jabber:iq:last");
178        }
179
180        final function setStatus()
181        {
182                $this->setPresence(array("type" => "unavailable"));
183                $this->setPresence(array("type" => "available"));
184        }
185
186        final function updateContact($pContact)
187        {
188                $jid   = $pContact['jid'];
189                $name  = $pContact['name'];
190                $group = $pContact['group'];
191
192                if ( $jid )
193                {
194                        $updatecontact  = "<item jid='$jid'";
195                        $updatecontact .= " name='" . $name . "'";
196                        $updatecontact .= "><group>" . $group . "</group></item>";
197                }
198
199                $upid = 'updateuser_' . time();
200                if ( !$this->connected )
201                        echo "disconnected";
202                else
203                {
204                        $this->iq('set', $upid, NULL, NULL, "jabber:iq:roster", $updatecontact);
205                        $this->getContacts();
206                        echo "OK";
207                }
208        }
209}
210?>
Note: See TracBrowser for help on using the repository browser.