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