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

Revision 227, 4.3 KB checked in by niltonneto, 16 years ago (diff)
  • Property svn:eol-style set to native
  • Property svn:executable set to *
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)
10        {
11                try
12                {
13                        if ( $pUser && $pPassword && $pConnectionType )
14                                if ( $_connect = parent::connect($pUser, $pPassword, $pConnectionType) )
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 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                {
71                        if ( $this->writeSocket($this->iq('set', $addid, NULL, NULL, "jabber:iq:roster", $newcontact)) )
72                                $this->getContacts();
73                                echo "OK";
74                }
75        }
76
77        final function getContacts()
78        {
79                if ( !$this->isConnected() )
80                        return "disconnected";
81
82                $this->iq('get', 'contacts', NULL, NULL, 'jabber:iq:roster');
83        }
84
85        final function getVcard($pJid)
86        {
87                if ( is_array($pJid) )
88                {
89                        $jid = ( trim($pJid['jid']) == "this" ) ? $this->_user . '@' . $this->_server : $pJid['jid'];
90                        $vcard = (trim($pJid['jid']) == "this") ? 'vCard_user' : 'vCard';
91                       
92                        if ( !$this->connected )
93                        {
94                                echo "disconnected";
95                        }
96                        else
97                        {
98                                $this->writeSocket($this->iq('get', $vcard, $jid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>"));
99                        }
100                }
101                else
102                {
103                        $this->iq('get', 'vCard', $pJid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>");
104                }
105        }
106
107        final function newVcard($NewVcard)
108        {
109                $id = $this->_user;
110
111                if ( !$this->connected )
112                        echo "disconnected";
113                else
114                {
115                        $this->writeSocket($this->iq('set', $id, NULL, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'>".$NewVcard['vcard']."</vCard>"));
116                        echo "OK";
117                }
118        }
119
120        final function removeContact($pContact)
121        {
122                $delid  = 'deluser_' . time();
123                if ( !$this->isConnected() )
124                        return "disconnected";
125                       
126                if ( $this->writeSocket($this->iq('set',$delid,NULL,NULL,"jabber:iq:roster","<item jid='".$pContact['jid']."' subscription='remove'/>")) )
127                        if ( $this->subscription($pContact['jid'],"unsubscribed") )
128                                echo "OK";
129        }
130
131        final function subscription($pTo, $pType = false)
132        {
133                $jid = (is_array($pTo)) ? $pTo['jid'] : $pTo ;
134                $type = (is_array($pTo)) ? $pTo['type'] : $pType ;
135
136                if ( !$this->connected )
137                        return false;
138                else
139                {
140                        $this->writeSocket("<presence xmlns='jabber:client' from='".$this->_user."@".$this->_server."' type='".$type."' to='".$jid."'/>");
141                        return true;
142                }
143        }
144
145        final function setPresence($pPresence = false)
146        {
147                if ( !$this->isConnected() )
148                        return "disconnected";
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        final function setStatus()
163        {
164                $this->setPresence(array("type" => "unavailable"));
165                $this->setPresence(array("type" => "available"));       
166        }
167
168        final function updateContact($pContact)
169        {
170                $jid   = $pContact['jid'];
171                $name  = $pContact['name'];
172                $group = $pContact['group'];
173
174                if ( $jid )
175                {
176                        $updatecontact  = "<item jid='$jid'";
177                        $updatecontact .= " name='" . $name . "'";
178                        $updatecontact .= "><group>" . $group . "</group></item>";
179                }
180
181                $upid = 'updateuser_' . time();
182                if ( !$this->connected )
183                        echo "disconnected";
184                else
185                {
186                        $this->writeSocket($this->iq('set', $upid, NULL, NULL, "jabber:iq:roster", $updatecontact));
187                        $this->getContacts();
188                        echo "OK";
189                }
190        }
191}
192?>
Note: See TracBrowser for help on using the repository browser.