source: trunk/filemanager/inc/class.bofilemanager.inc.php @ 7655

Revision 7655, 6.5 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Melhorias de performance no codigo do Expresso.

Line 
1<?php
2                /***************************************************************************
3                * Expresso Livre                                                           *
4                * http://www.expressolivre.org                                             *
5                * --------------------------------------------                             *
6                *  This program is free software; you can redistribute it and/or modify it *
7                *  under the terms of the GNU General Public License as published by the   *
8                *  Free Software Foundation; either version 2 of the License, or (at your  *
9                *  option) any later version.                                              *
10                \**************************************************************************/
11               
12        class bofilemanager
13        {
14
15                // used
16
17                var $so;
18                var $vfs;
19
20                var $rootdir;
21                var $fakebase;
22                var $appname;
23                var $filesdir;
24                var $hostname;
25                var $userinfo = Array();
26                var $homedir;
27                var $sep;
28                var $file_attributes;
29
30                var $matches;//FIXME matches not defined
31
32                var $debug = False;
33
34                function bofilemanager()
35                {
36                        $this->so = CreateObject('filemanager.sofilemanager');
37                        $this->so->db_init();
38
39                        $this->vfs = CreateObject('phpgwapi.vfs');
40
41                        error_reporting (4);
42
43                        ### Start Configuration Options ###
44                        ### These are automatically set in phpGW - do not edit ###
45
46                        $this->sep = SEP;
47                        $this->rootdir = $this->vfs->basedir;
48                        $this->fakebase = $this->vfs->fakebase;
49                        $this->appname = $GLOBALS['phpgw_info']['flags']['currentapp'];
50               
51                        if (stristr ($this->rootdir, PHPGW_SERVER_ROOT))
52                        {
53                                $this->filesdir = substr ($this->rootdir, strlen (PHPGW_SERVER_ROOT));
54                        }
55                        else
56                        {
57                                unset ($this->filesdir);
58                        }
59
60                        $this->hostname = $GLOBALS['phpgw_info']['server']['webserver_url'] . $this->filesdir;
61
62//                      die($this->hostname);
63                        ###
64                        # Note that $userinfo["username"] is actually the id number, not the login name
65                        ###
66
67                        $this->userinfo['username'] = $GLOBALS['phpgw_info']['user']['account_id'];
68                        $this->userinfo['account_lid'] = $GLOBALS['phpgw']->accounts->id2name ($this->userinfo['username']);
69                        $this->userinfo['hdspace'] = 10000000000; // to settings
70                        $this->homedir = $this->fakebase.'/'.$this->userinfo['account_lid'];
71
72                        ### End Configuration Options ###
73
74                        if (!defined ('NULL'))
75                        {
76                                define ('NULL', '');
77                        }
78
79                        ###
80                        # Define the list of file attributes.  Format is "internal_name" => "Displayed name"
81                        # This is used both by internally and externally for things like preferences
82                        ###
83
84                        $this->file_attributes = Array(
85                                'name' => lang('File Name'),
86                                'mime_type' => lang('MIME Type'),
87                                'size' => lang('Size'),
88                                'created' => lang('Created'),
89                                'modified' => lang('Modified'),
90                                'owner' => lang('Owner'),
91                                'createdby_id' => lang('Created by'),
92                                'modifiedby_id' => lang('Created by'),
93                                'modifiedby_id' => lang('Modified by'),
94                                'app' => lang('Application'),
95                                'comment' => lang('Comment'),
96                                'version' => lang('Version')
97                        );
98
99                        ###
100                        # Calculate and display B or KB
101                        # And yes, that first if is strange,
102                        # but it does do something
103                        ###
104
105                }
106
107
108                function borkb ($size, $enclosed = NULL, $return = 1)
109                {
110                        if (!$size)
111                        $size = 0;
112
113                        if ($enclosed)
114                        {
115                                $left = '(';
116                                $right = ')';
117                        }
118
119                        if ($size < 1024)
120                        $rstring = $left . $size . 'B' . $right;
121                        else if ($size < 1048576)
122                                $rstring = $left . round($size/1024) . 'KB' . $right;
123                        else if ($size < 1073741824)
124                                $rstring = $left . round($size/1024/1024) . 'MB' . $right;
125                        else
126                                $rstring = $left . round($size/1024/1024/1024) . 'GB' . $right;
127
128
129                        return ($this->eor ($rstring, $return));
130                }
131
132                ###
133                # Check for and return the first unwanted character
134                ###
135
136                function bad_chars ($string, $all = True, $return = 0)
137                {
138                        if ($all)
139                        {
140                                if (preg_match('/-([\\/<>\|\'\"\&])-/', $string, $badchars))
141                                $rstring = $badchars[1];
142                        }
143                        else
144                        {
145                                if (preg_match('/-([\\/<>])-/', $string, $badchars))
146                                $rstring = $badchars[1];
147                        }
148
149                        return trim (($this->eor ($rstring, $return)));
150                }
151
152                ###
153                # Match character in string using ord ().
154                ###
155
156                function ord_match ($string, $charnum)
157                {
158                        for ($i = 0; $i < strlen ($string); ++$i)
159                        {
160                                $character = ord (substr ($string, $i, 1));
161
162                                if ($character == $charnum)
163                                {
164                                        return True;
165                                }
166                        }
167
168                        return False;
169                }
170
171                ###
172                # Decide whether to echo or return.  Used by HTML functions
173                ###
174
175                function eor ($rstring, $return)
176                {
177                        if ($return)
178                        return ($rstring);
179                        else
180                        {
181                                $this->html_text ($rstring . "\n");
182                                return (0);
183                        }
184                }
185               
186                function html_text ($string, $times = 1, $return = 0, $lang = 0)
187                {
188                        if ($lang)
189                        $string = lang($string);
190
191                        if ($times == NULL)
192                        $times = 1;
193                        for ($i = 0; $i != $times; ++$i)
194                        {
195                                if ($return)
196                                $rstring .= $string;
197                                else
198                                echo $string;
199                        }
200                        if ($return)
201                        return ($rstring);
202                }
203
204                ###
205                # URL encode a string
206                # First check if its a query string, then if its just a URL, then just encodes it all
207                # Note: this is a hack.  It was made to work with form actions, form values, and links only,
208                # but should be able to handle any normal query string or URL
209                ###
210
211                function string_encode ($string, $return = False)
212                {
213                        //var_dump($string);
214                        if (preg_match('/\/=(.*)(&|$)\/U/', $string))
215                        {
216                                $rstring = $string;
217
218                                preg_match_all ("/=(.*)(&|$)/U", $string, $matches, PREG_SET_ORDER);//FIXME matches not defined
219
220                                reset ($matches);//FIXME matches not defined
221
222                                while (list (,$match_array) = each ($matches))//FIXME matches not defined
223
224                                {
225                                        $var_encoded = rawurlencode (base64_encode ($match_array[1]));
226                                        $rstring = str_replace ($match_array[0], '=' . $var_encoded . $match_array[2], $rstring);
227                                }
228                        }
229                        elseif ($this->hostname != "" && preg_match("/^$this->hostname/", $string))
230//                      elseif (preg_match ("/^$this->hostname/", $string))
231                        {
232                                $rstring = preg_replace("/^$this->hostname\//", '', $string);
233                                $rstring = preg_replace("/(.*)(\/|$)/Ue", "rawurlencode (base64_encode ('\\1')) . '\\2'", $rstring);
234                                $rstring = $this->hostname.'/'.$rstring;
235                        }
236                        else
237                        {
238                                $rstring = rawurlencode ($string);
239
240                                /* Terrible hack, decodes all /'s back to normal */ 
241                                $rstring = preg_replace('/%2F/', '/', $rstring);
242                        }
243
244                        return ($this->eor ($rstring, $return));
245                }
246
247                function string_decode ($string, $return = False)
248                {
249                        $rstring = rawurldecode ($string);
250
251                        return ($this->eor ($rstring, $return));
252                }
253
254                ###
255                # HTML encode a string
256                # This should be used with anything in an HTML tag that might contain < or >
257                ###
258
259                function html_encode ($string, $return)
260                {
261                        $rstring = htmlspecialchars ($string);
262
263                        return ($this->eor ($rstring, $return));
264                }
265        }
266        ?>
Note: See TracBrowser for help on using the repository browser.