source: sandbox/filemanager/inc/class.bofilemanager.inc.php @ 1506

Revision 1506, 5.6 KB checked in by amuller, 15 years ago (diff)

Ticket #597 - Adicionando código do filemanager compatível com expresso

  • Property svn:executable set to *
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
113                        $rstring = $left . round($size/1024) . 'KB' . $right;
114
115                        return ($this->eor ($rstring, $return));
116                }
117
118                ###
119                # Check for and return the first unwanted character
120                ###
121
122                function bad_chars ($string, $all = True, $return = 0)
123                {
124                        if ($all)
125                        {
126                                if (preg_match("-([\\/<>\'\"\&])-", $string, $badchars))
127                                $rstring = $badchars[1];
128                        }
129                        else
130                        {
131                                if (preg_match("-([\\/<>])-", $string, $badchars))
132                                $rstring = $badchars[1];
133                        }
134
135                        return trim (($this->eor ($rstring, $return)));
136                }
137
138                ###
139                # Match character in string using ord ().
140                ###
141
142                function ord_match ($string, $charnum)
143                {
144                        for ($i = 0; $i < strlen ($string); $i++)
145                        {
146                                $character = ord (substr ($string, $i, 1));
147
148                                if ($character == $charnum)
149                                {
150                                        return True;
151                                }
152                        }
153
154                        return False;
155                }
156
157                ###
158                # Decide whether to echo or return.  Used by HTML functions
159                ###
160
161                function eor ($rstring, $return)
162                {
163                        if ($return)
164                        return ($rstring);
165                        else
166                        {
167                                $this->html_text ($rstring . "\n");
168                                return (0);
169                        }
170                }
171               
172                function html_text ($string, $times = 1, $return = 0, $lang = 0)
173                {
174                        if ($lang)
175                        $string = lang($string);
176
177                        if ($times == NULL)
178                        $times = 1;
179                        for ($i = 0; $i != $times; $i++)
180                        {
181                                if ($return)
182                                $rstring .= $string;
183                                else
184                                echo $string;
185                        }
186                        if ($return)
187                        return ($rstring);
188                }
189
190                ###
191                # URL encode a string
192                # First check if its a query string, then if its just a URL, then just encodes it all
193                # Note: this is a hack.  It was made to work with form actions, form values, and links only,
194                # but should be able to handle any normal query string or URL
195                ###
196
197                function string_encode ($string, $return = False)
198                {
199                        //var_dump($string);
200                        if (preg_match ("/=(.*)(&|$)/U", $string))
201                        {
202                                $rstring = $string;
203
204                                preg_match_all ("/=(.*)(&|$)/U", $string, $matches, PREG_SET_ORDER);//FIXME matches not defined
205
206                                reset ($matches);//FIXME matches not defined
207
208                                while (list (,$match_array) = each ($matches))//FIXME matches not defined
209
210                                {
211                                        $var_encoded = rawurlencode (base64_encode ($match_array[1]));
212                                        $rstring = str_replace ($match_array[0], '=' . $var_encoded . $match_array[2], $rstring);
213                                }
214                        }
215                        elseif ($this->hostname != "" && ereg('^'.$this->hostname, $string))
216//                      elseif (ereg ('^'.$this->hostname, $string))
217                        {
218                                $rstring = ereg_replace ('^'.$this->hostname.'/', '', $string);
219                                $rstring = preg_replace ("/(.*)(\/|$)/Ue", "rawurlencode (base64_encode ('\\1')) . '\\2'", $rstring);
220                                $rstring = $this->hostname.'/'.$rstring;
221                        }
222                        else
223                        {
224                                $rstring = rawurlencode ($string);
225
226                                /* Terrible hack, decodes all /'s back to normal */ 
227                                $rstring = preg_replace ("/%2F/", '/', $rstring);
228                        }
229
230                        return ($this->eor ($rstring, $return));
231                }
232
233                function string_decode ($string, $return = False)
234                {
235                        $rstring = rawurldecode ($string);
236
237                        return ($this->eor ($rstring, $return));
238                }
239
240                ###
241                # HTML encode a string
242                # This should be used with anything in an HTML tag that might contain < or >
243                ###
244
245                function html_encode ($string, $return)
246                {
247                        $rstring = htmlspecialchars ($string);
248
249                        return ($this->eor ($rstring, $return));
250                }
251        }
252        ?>
Note: See TracBrowser for help on using the repository browser.