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

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