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

Revision 216, 4.1 KB checked in by niltonneto, 16 years ago (diff)

Correções do módulo instant_messenger.
Ver WiKi? em: http://www.expressolivre.org/dev/wiki/messenger

  • 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                }
74        }
75
76        final function getContacts()
77        {
78                if ( !$this->isConnected() )
79                        return "disconnected";
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                                $this->writeSocket($this->iq('get', 'vCard', $jid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>"));
94                }
95                else
96                {
97                        $this->iq('get', 'vCard', $pJid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>");
98                }
99        }
100
101        final function newVcard($NewVcard)
102        {
103                $id = $this->_user;
104
105                if ( !$this->connected )
106                        echo "disconnected";
107                else
108                        $this->writeSocket($this->iq('set', $id, NULL, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'>".$NewVcard['vcard']."</vCard>"));
109        }
110
111        final function removeContact($pContact)
112        {
113                $delid  = 'deluser_' . time();
114                if ( !$this->isConnected() )
115                        return "disconnected";
116                       
117                if ( $this->writeSocket($this->iq('set',$delid,NULL,NULL,"jabber:iq:roster","<item jid='".$pContact['jid']."' subscription='remove'/>")) )
118                        if ( $this->subscription($pContact['jid'],"unsubscribed") )
119                                echo "OK";
120        }
121
122        final function subscription($pTo, $pType = false)
123        {
124                $jid = (is_array($pTo)) ? $pTo['jid'] : $pTo ;
125                $type = (is_array($pTo)) ? $pTo['type'] : $pType ;
126
127                if ( !$this->connected )
128                        return false;
129                else
130                {
131                        $this->writeSocket("<presence xmlns='jabber:client' from='".$this->_user."@".$this->_server."' type='".$type."' to='".$jid."'/>");
132                        return true;
133                }
134        }
135
136        final function setPresence($pPresence = false)
137        {
138                if ( !$this->isConnected() )
139                        return "disconnected";
140
141                if ( !$pPresence )
142                        $this->presence();
143
144                $type = ( isset($pPresence['type']) ) ? $pPresence['type'] : NULL;
145                $to = ( isset($pPresence['to']) ) ? $pPresence['to'] : NULL;
146                $show = ( isset($pPresence['show']) ) ? $pPresence['show'] : NULL;
147                $status = ( isset($pPresence['status']) ) ? $pPresence['status'] : NULL;
148                $priority = ( isset($pPresence['priority']) ) ? $pPresence['priority'] : NULL;
149
150                $this->presence($type, $to, $show, $status, $priority);
151        }
152
153        final function updateContact($pContact)
154        {
155                $jid   = $pContact['jid'];
156                $name  = $pContact['name'];
157                $group = $pContact['group'];
158
159                if ( $jid )
160                {
161                        $updatecontact  = "<item jid='$jid'";
162                        $updatecontact .= " name='" . $name . "'";
163                        $updatecontact .= "><group>" . $group . "</group></item>";
164                }
165
166                $upid = 'updateuser_' . time();
167                if ( !$this->connected )
168                        echo "disconnected";
169                else
170                {
171                        $this->writeSocket($this->iq('set', $upid, NULL, NULL, "jabber:iq:roster", $updatecontact));
172                        $this->getContacts();
173                        echo "OK";
174                }
175        }
176}
177?>
Note: See TracBrowser for help on using the repository browser.