source: trunk/jabberit_messenger/inc/getphoto.php @ 417

Revision 417, 4.7 KB checked in by niltonneto, 16 years ago (diff)

Vide changelog do módulo.
http://www.expressolivre.org/dev/wiki/jabberit/changelog
Alterações feitas por Alexandre Correia
email: alexandrecorreia@…

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