source: sandbox/2.3-MailArchiver/filemanager/inc/class.bofilemanager.inc.php @ 6779

Revision 6779, 5.8 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

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