2003-10-24 22:33:34 +02:00
|
|
|
<?php
|
2005-10-14 12:41:15 +02:00
|
|
|
/**************************************************************************\
|
|
|
|
* eGroupWare - Filemanager *
|
|
|
|
* http://www.egroupware.org *
|
|
|
|
* ------------------------------------------------------------------------ *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
2003-10-24 22:33:34 +02:00
|
|
|
|
|
|
|
class bofilemanager
|
|
|
|
{
|
2004-03-02 01:39:52 +01:00
|
|
|
// used
|
|
|
|
|
2003-10-24 22:33:34 +02:00
|
|
|
var $so;
|
|
|
|
var $vfs;
|
2003-11-22 04:05:00 +01:00
|
|
|
|
2003-10-24 22:33:34 +02:00
|
|
|
var $rootdir;
|
|
|
|
var $fakebase;
|
|
|
|
var $appname;
|
|
|
|
var $filesdir;
|
|
|
|
var $hostname;
|
|
|
|
var $userinfo = Array();
|
|
|
|
var $homedir;
|
2004-03-02 01:39:52 +01:00
|
|
|
var $sep;
|
|
|
|
var $file_attributes;
|
|
|
|
|
|
|
|
var $matches;//FIXME matches not defined
|
2003-10-24 22:33:34 +02:00
|
|
|
|
|
|
|
var $debug = False;
|
|
|
|
|
|
|
|
function bofilemanager()
|
|
|
|
{
|
2005-10-14 12:41:15 +02:00
|
|
|
$this->so =& CreateObject('filemanager.sofilemanager');
|
2003-11-22 04:05:00 +01:00
|
|
|
$this->so->db_init();
|
|
|
|
|
2005-10-14 12:41:15 +02:00
|
|
|
$this->vfs =& CreateObject('phpgwapi.vfs');
|
2003-10-24 22:33:34 +02:00
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
error_reporting(4);
|
2003-10-24 22:33:34 +02:00
|
|
|
|
|
|
|
### Start Configuration Options ###
|
2005-09-14 03:58:20 +02:00
|
|
|
### These are automatically set in eGW - do not edit ###
|
2003-10-24 22:33:34 +02:00
|
|
|
|
|
|
|
$this->sep = SEP;
|
2004-03-02 01:39:52 +01:00
|
|
|
$this->rootdir = $this->vfs->basedir;
|
|
|
|
$this->fakebase = $this->vfs->fakebase;
|
2005-09-14 03:58:20 +02:00
|
|
|
$this->appname = $GLOBALS['egw_info']['flags']['currentapp'];
|
|
|
|
|
|
|
|
if(stristr($this->rootdir, EGW_SERVER_ROOT))
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
$this->filesdir = substr($this->rootdir, strlen(EGW_SERVER_ROOT));
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
unset($this->filesdir);
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
$this->hostname = $GLOBALS['egw_info']['server']['webserver_url'] . $this->filesdir;
|
2003-10-24 22:33:34 +02:00
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
// die($this->hostname);
|
2003-10-24 22:33:34 +02:00
|
|
|
###
|
|
|
|
# Note that $userinfo["username"] is actually the id number, not the login name
|
|
|
|
###
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
$this->userinfo['username'] = $GLOBALS['egw_info']['user']['account_id'];
|
|
|
|
$this->userinfo['account_lid'] = $GLOBALS['egw']->accounts->id2name($this->userinfo['username']);
|
2004-03-02 01:39:52 +01:00
|
|
|
$this->userinfo['hdspace'] = 10000000000; // to settings
|
|
|
|
$this->homedir = $this->fakebase.'/'.$this->userinfo['account_lid'];
|
2003-10-24 22:33:34 +02:00
|
|
|
|
|
|
|
### End Configuration Options ###
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
if(!defined('NULL'))
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
define('NULL', '');
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
###
|
|
|
|
# Define the list of file attributes. Format is "internal_name" => "Displayed name"
|
|
|
|
# This is used both by internally and externally for things like preferences
|
|
|
|
###
|
|
|
|
|
|
|
|
$this->file_attributes = Array(
|
|
|
|
'name' => lang('File Name'),
|
|
|
|
'mime_type' => lang('MIME Type'),
|
|
|
|
'size' => lang('Size'),
|
|
|
|
'created' => lang('Created'),
|
|
|
|
'modified' => lang('Modified'),
|
|
|
|
'owner' => lang('Owner'),
|
|
|
|
'createdby_id' => lang('Created by'),
|
|
|
|
'modifiedby_id' => lang('Created by'),
|
|
|
|
'modifiedby_id' => lang('Modified by'),
|
|
|
|
'app' => lang('Application'),
|
|
|
|
'comment' => lang('Comment'),
|
|
|
|
'version' => lang('Version')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
###
|
|
|
|
# Calculate and display B or KB
|
|
|
|
# And yes, that first if is strange,
|
|
|
|
# but it does do something
|
|
|
|
###
|
|
|
|
function borkb($size, $enclosed = NULL, $return = 1)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
if(!$size)
|
|
|
|
{
|
|
|
|
$size = 0;
|
|
|
|
}
|
2003-10-24 22:33:34 +02:00
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
if($enclosed)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
|
|
|
$left = '(';
|
|
|
|
$right = ')';
|
|
|
|
}
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
if($size < 1024)
|
|
|
|
{
|
|
|
|
$rstring = $left . $size . 'B' . $right;
|
|
|
|
}
|
2003-10-24 22:33:34 +02:00
|
|
|
else
|
2005-09-14 03:58:20 +02:00
|
|
|
{
|
|
|
|
$rstring = $left . round($size/1024) . 'KB' . $right;
|
|
|
|
}
|
2003-10-24 22:33:34 +02:00
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
return($this->eor($rstring, $return));
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
###
|
|
|
|
# Check for and return the first unwanted character
|
|
|
|
###
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
function bad_chars($string, $all = True, $return = 0)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
if($all)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
if(preg_match("-([\\/<>\'\"\&])-", $string, $badchars))
|
|
|
|
{
|
|
|
|
$rstring = $badchars[1];
|
|
|
|
}
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
if(preg_match("-([\\/<>])-", $string, $badchars))
|
|
|
|
{
|
|
|
|
$rstring = $badchars[1];
|
|
|
|
}
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
return trim(($this->eor($rstring, $return)));
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
###
|
2005-09-14 03:58:20 +02:00
|
|
|
# Match character in string using ord().
|
2003-10-24 22:33:34 +02:00
|
|
|
###
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
function ord_match($string, $charnum)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
for($i = 0; $i < strlen($string); $i++)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
$character = ord(substr($string, $i, 1));
|
2003-10-24 22:33:34 +02:00
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
if($character == $charnum)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return False;
|
|
|
|
}
|
|
|
|
|
|
|
|
###
|
|
|
|
# Decide whether to echo or return. Used by HTML functions
|
|
|
|
###
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
function eor($rstring, $return)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
if($return)
|
|
|
|
{
|
|
|
|
return($rstring);
|
|
|
|
}
|
2003-10-24 22:33:34 +02:00
|
|
|
else
|
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
$this->html_text($rstring . "\n");
|
|
|
|
return(0);
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
}
|
2005-09-14 03:58:20 +02:00
|
|
|
|
|
|
|
function html_text($string, $times = 1, $return = 0, $lang = 0)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
if($lang)
|
|
|
|
{
|
|
|
|
$string = lang($string);
|
|
|
|
}
|
2003-10-24 22:33:34 +02:00
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
if($times == NULL)
|
|
|
|
{
|
|
|
|
$times = 1;
|
|
|
|
}
|
|
|
|
for($i = 0; $i != $times; $i++)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
if($return)
|
|
|
|
{
|
|
|
|
$rstring .= $string;
|
|
|
|
}
|
2003-10-24 22:33:34 +02:00
|
|
|
else
|
2005-09-14 03:58:20 +02:00
|
|
|
{
|
|
|
|
echo $string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($return)
|
|
|
|
{
|
|
|
|
return($rstring);
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
###
|
|
|
|
# URL encode a string
|
|
|
|
# First check if its a query string, then if its just a URL, then just encodes it all
|
|
|
|
# Note: this is a hack. It was made to work with form actions, form values, and links only,
|
|
|
|
# but should be able to handle any normal query string or URL
|
|
|
|
###
|
2005-09-14 03:58:20 +02:00
|
|
|
function string_encode($string, $return = False)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2003-11-22 04:05:00 +01:00
|
|
|
//var_dump($string);
|
2005-09-14 03:58:20 +02:00
|
|
|
if(preg_match("/=(.*)(&|$)/U", $string))
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
|
|
|
$rstring = $string;
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
preg_match_all("/=(.*)(&|$)/U", $string, $matches, PREG_SET_ORDER);//FIXME matches not defined
|
2004-03-02 01:39:52 +01:00
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
reset($matches);//FIXME matches not defined
|
2003-10-24 22:33:34 +02:00
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
while(list(,$match_array) = each($matches))//FIXME matches not defined
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
$var_encoded = rawurlencode(base64_encode($match_array[1]));
|
|
|
|
$rstring = str_replace($match_array[0], '=' . $var_encoded . $match_array[2], $rstring);
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
}
|
2005-09-14 03:58:20 +02:00
|
|
|
elseif($this->hostname != "" && ereg('^'.$this->hostname, $string))
|
|
|
|
// elseif(ereg('^'.$this->hostname, $string))
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
$rstring = ereg_replace('^'.$this->hostname.'/', '', $string);
|
|
|
|
$rstring = preg_replace("/(.*)(\/|$)/Ue", "rawurlencode(base64_encode('\\1')) . '\\2'", $rstring);
|
2004-03-02 01:39:52 +01:00
|
|
|
$rstring = $this->hostname.'/'.$rstring;
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
$rstring = rawurlencode($string);
|
2003-10-24 22:33:34 +02:00
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
/* Terrible hack, decodes all /'s back to normal */
|
|
|
|
$rstring = preg_replace("/%2F/", '/', $rstring);
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
return($this->eor($rstring, $return));
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
function string_decode($string, $return = False)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
$rstring = rawurldecode($string);
|
2003-10-24 22:33:34 +02:00
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
return($this->eor($rstring, $return));
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
###
|
|
|
|
# HTML encode a string
|
|
|
|
# This should be used with anything in an HTML tag that might contain < or >
|
|
|
|
###
|
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
function html_encode($string, $return)
|
2003-10-24 22:33:34 +02:00
|
|
|
{
|
2005-09-14 03:58:20 +02:00
|
|
|
$rstring = htmlspecialchars($string);
|
2003-10-24 22:33:34 +02:00
|
|
|
|
2005-09-14 03:58:20 +02:00
|
|
|
return($this->eor($rstring, $return));
|
2003-10-24 22:33:34 +02:00
|
|
|
}
|
|
|
|
}
|
2005-09-14 03:58:20 +02:00
|
|
|
?>
|