source: companies/serpro/jabberit_messenger/inc/getphoto.php @ 903

Revision 903, 4.8 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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 ldapPhoto
14{
15        private $host;
16        private $dn;
17        private $passwd;
18        private $refer;
19        private $user_referral;
20        private $password_referral;
21        private $conn;
22        private $context;
23        private $photo_user = array();
24        private $handle;
25
26
27        function __construct()
28        {
29                require_once('conf_Ldap_Photos.php');
30                $this->handle   = unserialize(base64_decode($CONF_SERVER));
31               
32                $this->host             = $this->handle['host'];
33                $this->context  = $this->handle['context'];
34                $this->dn               = $this->handle['dn'];
35                $this->passwd   = $this->handle['passwd'];
36               
37                $this->refer    = false;
38                $this->version3 = true;
39        }
40
41        private final function ldap_rebind($ldap_connection, $ldap_url)
42        {
43                @ldap_bind($ldap_connection, $this->user_referral, $this->password_referral);
44        }
45
46        private final function ldapConnect()
47        {
48                if(!function_exists('ldap_connect'))
49                {
50                        printf("<b>Erro : Ldap Não suportado %s</b><br>" , $this->host);
51                        return False;
52                }
53               
54                if(!$this->conn = ldap_connect($this->host))
55                {
56                        printf("<b>Erro: não pode conectar no servidor ldap %s!</b><br>", $this->host);
57                        return False;
58                }
59                if( $this->version3 )
60                {
61                        if( !ldap_set_option($this->conn,LDAP_OPT_PROTOCOL_VERSION,3) )
62                                $this->version = false;
63                }
64                ldap_set_option($this->conn, LDAP_OPT_REFERRALS, $this->refer);
65                // verifica refer
66                if( $this->refer )
67                {
68                        $this->user_referral = $this->dn;
69                        $this->password_referral = $this->passwd;
70                        @ldap_set_rebind_proc($this->conn, $this->ldap_rebind);
71                }
72               
73                // bind as admin
74                if($this->dn && $this->passwd && !ldap_bind($this->conn, $this->dn, $this->passwd)){
75                        echo "<center><b>ExpressoLivre indisponível no momento</b></center>";
76                        return False;
77                }
78                // bind as anonymous
79                if(!$this->dn && !$this->passwd && !@ldap_bind($this->conn))
80                {
81                        echo "<center><b>ExpressoLivre indisponível no momento</b></center>";
82                        return False;
83                }                                               
84        }
85       
86        public final function getPhotoLdap($uid)
87        {
88                $this->ldapConnect();
89                if( $this->conn )
90                {
91                        $filter = "(&(phpgwaccounttype=u)(uid=".$uid."))";
92                        $justthese = array("uid","phpgwAccountVisible","jpegPhoto");
93                        $search = ldap_search($this->conn,$this->context,$filter,$justthese);
94                        $entry1 = ldap_get_entries($this->conn,$search);
95                        $entry = ldap_first_entry( $this->conn, $search );
96
97                        if( $entry1['count'] > 0 )
98                        {
99                                $i = 0;
100                                $photo = "";
101                                $return_photo = "";
102       
103                               
104                                if ( $entry1[$i]['phpgwaccountvisible'][0] != '-1' )
105                                {
106                                        $photo = @ldap_get_values_len($this->conn, $entry, 'jpegphoto');
107       
108                                        if ( $photo )
109                                                $return_photo = $photo[0];
110                                }                               
111                                return $return_photo;
112                        }
113                }
114                return false;
115        }
116       
117        public final function getPhotoSession($pUid)
118        {
119                if(isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid]))
120                {
121                        $photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid]);
122                       
123                        header("Content-Type: image/jpeg");
124                        $width = imagesx($photo);
125                        $height = imagesy($photo);
126                        $twidth = 60;
127                        $theight = 80;
128                        $small_photo = imagecreatetruecolor ($twidth, $theight);
129                        imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
130                        imagejpeg($small_photo,'',100);
131                       
132                        unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pUid]);   
133                        return;
134                }
135        }
136}
137
138if(trim($_REQUEST['uid']) != "")
139{
140        $uid = trim($_REQUEST['uid']);
141        $a = new ldapPhoto();
142       
143        if( strpos($uid,"@"))
144        {
145                $uid = substr($uid, 0, strpos($uid,"@"));       
146                $photo = $a->getPhotoLdap($uid);
147                $photoWidth = 70;
148                $photoHeight = 90;
149                $newImage = imagecreatetruecolor($photoWidth,$photoHeight);             
150               
151                if($photo)
152                {
153                        $photo = imagecreatefromstring($photo);
154                        $trans = imagecolortransparent($photo);
155                        imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
156                        imagepng($newImage);
157                        imagedestroy($newImage);
158                }
159                else
160                {
161                        $photo = @imagecreatefrompng("../templates/default/images/photo.png");
162                        $trans = imagecolortransparent($photo);
163                        imagecopyresized($newImage,$photo,0,0,0,0,$photoWidth,$photoHeight,imagesx($photo),imagesy($photo));
164                        imagepng($newImage);
165                        imagedestroy($newImage);
166                }
167        }
168        else
169        {
170                $a->getPhotoSession($uid);
171        }
172}
173
174?>
Note: See TracBrowser for help on using the repository browser.