source: trunk/jabberit_messenger/inc/webservice.php @ 948

Revision 948, 7.6 KB checked in by niltonneto, 15 years ago (diff)

Ticket #505 - Corrigido erro quando contato está conectado com clienteIM (recurso junto no jid).

  • Property svn:executable set to *
Line 
1<?php
2  /***************************************************************************\
3  *  Expresso - Expresso Messenger                                            *
4  *     - Alexandre Correia / Rodrigo Souza                                                               *
5  *     - JETI - http://jeti-im.org/                                                                              *
6  * ------------------------------------------------------------------------- *
7  *  This program is free software; you can redistribute it and/or modify it  *
8  *  under the terms of the GNU General Public License as published by the    *
9  *  Free Software Foundation; either version 2 of the License, or (at your   *
10  *  option) any later version.                                               *
11  \***************************************************************************/
12
13class webService
14{
15        private $conn;
16        private $contextLdap;
17        private $userDn;       
18        private $jabberName;
19        private $passwd;
20        private $photo_user = array();
21        private $refer;
22        private $serverLdap;
23       
24        function __construct()
25        {
26                require_once('confLDAPInternal.php');
27                $handle   = unserialize(base64_decode($LDAP_INTERNAL));
28
29                $this->jabberName       = $handle['jabberName'];
30                $this->serverLdap       = $handle['serverLdap'];
31                $this->contextLdap      = $handle['contextLdap'];
32                $this->userDn           = $handle['user'];
33                $this->passwd           = $handle['password'];
34               
35                $this->refer    = true;
36                $this->version3 = true;
37        }
38       
39        private final function ldapConnect()
40        {
41                if(!function_exists('ldap_connect'))
42                        return False;
43               
44                if(!$this->conn = ldap_connect($this->serverLdap))
45                        return False;
46
47                if( $this->version3 )
48                        if( !ldap_set_option($this->conn,LDAP_OPT_PROTOCOL_VERSION,3) )
49                                $this->version = false;
50
51                ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $this->refer);
52
53                // Bind as Admin
54                if($this->userDn && $this->passwd && !ldap_bind($this->conn, $this->userDn, $this->passwd))
55                        return False;
56               
57                // Bind as Anonymous
58                if(!$this->userDn && !$this->passwd && !@ldap_bind($this->conn))
59                        return False;
60        }
61
62        private final function ldapConnectExternal($pHostJabber)
63        {
64                require_once('confLDAPExternal.php');
65                $handle   = unserialize(base64_decode($LDAP_EXTERNAL));
66
67                foreach($handle as $itens)
68                        if(trim($pHostJabber) == $itens['jabberName'])
69                        {
70                                $this->jabberName       = $itens['jabberName'];
71                                $this->serverLdap       = $itens['serverLdap'];
72                                $this->contextLdap      = $itens['contextLdap'];
73                                $this->userDn           = $itens['user'];
74                                $this->passwd           = $itens['password'];
75                        }               
76
77                $this->refer    = true;
78                $this->version3 = true;
79               
80                $this->ldapConnect();
81        }
82       
83        public final function getNameOrganization($pJid, $pCharset)
84        {
85                $uid = substr($pJid, 0, strpos($pJid,"@"));
86               
87                if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 )))
88                {
89                        $this->ldapConnect();
90                       
91                        if( $this->conn )
92                        {
93                                $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
94                                $justthese = array("uid","cn","dn");
95                                $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese);
96                                $entry = ldap_get_entries($this->conn,$search);
97                                $cn = $entry[0]['cn'][0];
98                                $ou = explode("dc=", $entry[0]['dn']);
99                                $ou = explode("ou=",$ou[0]);
100                                $ou = array_pop($ou);
101                                $dn = strtoupper(substr($ou,0,strlen($ou)-1));
102       
103                                $return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn);
104                        }
105                }
106                else
107                {
108                        $this->ldapConnectExternal(substr($pJid, strpos($pJid, "@") + 1 ));
109
110                        if( $this->conn )
111                        {
112                                $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
113                                $justthese = array("uid","cn","dn");
114                                $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese);
115                                $entry = ldap_get_entries($this->conn,$search);
116                                $cn = $entry[0]['cn'][0];
117                                $ou = explode("dc=", $entry[0]['dn']);
118                                $ou = explode("ou=",$ou[0]);
119                                $ou = array_pop($ou);
120                                $dn = strtoupper(substr($ou,0,strlen($ou)-1));
121       
122                                $return = utf8_encode("Nome : " . $cn . ";Organização : " . $dn);
123                        }
124                }
125
126                if( $pCharset === "1" )
127                        return $return;
128                else
129                        return mb_convert_encoding($return, "ISO-8859-1", "UTF-8");
130
131                $return = utf8_encode("Nome : Não Identificado ;Organização : Não Identificado");                       
132
133                if( $pCharset === 1 )
134                        return $return;
135                else
136                        return mb_convert_encoding($return, "ISO-8859-1", "UTF-8");
137
138        }
139       
140        public final function getPhotoLdap($pJid)
141        {
142                $uid = substr($pJid, 0, strpos($pJid,"@"));
143               
144                if( $this->jabberName == (substr($pJid, strpos($pJid, "@") + 1 )))
145                {
146                        $this->ldapConnect();
147                       
148                        if( $this->conn )
149                        {
150                                $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
151                                $justthese = array("uid","jpegPhoto");
152                               
153                                $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese);
154                                $entry1 = ldap_get_entries($this->conn,$search);
155                                $entry = ldap_first_entry( $this->conn, $search );
156                                if( $entry1['count'] > 0 )
157                                {
158                                        $i = 0;
159                                        $photo = "";
160                                        $return_photo = "";
161                                        $photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto');
162
163                                        if ($photo)
164                                                $return_photo = $photo[0];                                                             
165                                        return $return_photo;
166                                }
167                        }
168                }
169                else
170                {                                       
171                        $jabberName = substr($pJid, strpos($pJid, "@") + 1 );
172                       
173                        if( strpos($jabberName, "/") )
174                                $jabberName = substr($jabberName, 0, strpos($jabberName, "/"));
175
176                        $this->ldapConnectExternal($jabberName);
177
178                        if( $this->conn )
179                        {
180                                $filter = "(&(phpgwaccounttype=u)(uid=".$uid.")(!(phpgwaccountvisible=-1)))";
181                                $justthese = array("uid","jpegPhoto");
182                                $search = ldap_search($this->conn,$this->contextLdap,$filter,$justthese);
183                                $entry1 = ldap_get_entries($this->conn,$search);
184                                $entry = ldap_first_entry( $this->conn, $search );
185                                if( $entry1['count'] > 0 )
186                                {
187                                        $i = 0;
188                                        $photo = "";
189                                        $return_photo = "";
190                                        $photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto');
191                                        if ($photo)
192                                                $return_photo = $photo[0];                                                             
193                                        return $return_photo;
194                                }
195                        }
196                }
197                                       
198                return false;
199        }
200       
201        public final function getPhotoSession($pUid, $pOu)
202        {
203                $uid = $pUid;
204                if( strpos($pUid, "@") )
205                        $uid = substr($pUid, 0, strpos($pUid, "@"));
206               
207                if( isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]) )
208                {
209                        $photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
210
211                        header("Content-Type: image/jpeg");
212                        $width = imagesx($photo);
213                        $height = imagesy($photo);
214                        $twidth = 60;
215                        $theight = 80;
216                        $small_photo = imagecreatetruecolor ($twidth, $theight);
217                        imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
218                        imagejpeg($small_photo,'',100);
219
220                        unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
221
222                        return;
223                }
224        }
225}
226
227if(trim($_REQUEST['javaPhoto']) != "" )
228{
229        $obj = new webService();
230        $jid = $_REQUEST['javaPhoto'];
231        $jid = strpos($jid, "/") ? substr($jid, 0, strpos($jid, "/")) : $jid;
232       
233        $photo = $obj->getPhotoLdap($jid);
234        $photoWidth = 70;
235        $photoHeight = 90;
236        $newImage = imagecreatetruecolor($photoWidth,$photoHeight);             
237
238        if( $photo )
239        {
240                $photo = imagecreatefromstring($photo);
241                imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
242        }
243        else
244        {
245                $photo = @imagecreatefrompng("../templates/default/images/photo.png");
246                imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
247        }
248       
249        ob_start();
250        imagepng($newImage);
251        $imagePhoto = ob_get_contents();
252        imagedestroy($newImage);
253        ob_end_clean();
254        printf("%s",base64_encode($imagePhoto));
255       
256}
257
258if(trim($_POST['jid']) != "")
259{
260        $jid = trim($_POST['jid']);
261        $charset = trim($_POST['charset']);
262        $obj = new webService();
263       
264        printf("%s",$obj->getNameOrganization($jid, $charset));
265}
266
267if(trim($_REQUEST['phpPhoto']) != "")
268{
269        $obj = new webservice();
270        $ou = $_REQUEST['phpOu'];
271        $jid = $_REQUEST['phpPhoto'];
272       
273        $obj->getPhotoSession($jid, $ou);
274}
275
276?>
Note: See TracBrowser for help on using the repository browser.