egroupware_official/filemanager/inc/main.inc.php

189 lines
4.1 KiB
PHP
Raw Normal View History

<?php
2001-05-21 03:09:20 +02:00
### Start Configuration Options ###
### These are automatically set in phpGW - do not edit ###
$sep = $phpgw_info["server"]["dir_separator"];
$rootdir = $phpgw->vfs->basedir;
$fakebase = $phpgw->vfs->fakebase;
$hostname = $phpgw_info["server"]["webserver_url"] . $filesdir;
$appname = $phpgw_info["flags"]["currentapp"];
$settings = $phpgw_info["user"]["preferences"][$appname];
2001-06-04 00:47:46 +02:00
if (stristr ($rootdir, PHPGW_SERVER_ROOT))
{
$filesdir = substr ($rootdir, strlen (PHPGW_SERVER_ROOT));
}
else
{
unset ($filesdir);
}
2001-05-21 03:09:20 +02:00
### End Configuration Options ###
define ("NULL", "");
require ("./inc/db.inc.php");
/* Set up any initial db settings */
db_init ();
###
# Get user settings from database
###
/* We have to define these by hand in phpGW, or rely on it's templates */
define ('HTML_TABLE_FILES_HEADER_BG_COLOR', "");
define ('HTML_TABLE_FILES_HEADER_TEXT_COLOR', "maroon");
define ('HTML_TABLE_FILES_COLUMN_HEADER_BG_COLOR', "");
define ('HTML_TABLE_FILES_COLUMN_HEADER_TEXT_COLOR', "maroon");
define ('HTML_TABLE_FILES_BG_COLOR', "");
define ('HTML_TABLE_FILES_TEXT_COLOR', "maroon");
define ('HTML_TEXT_ERROR_COLOR', "red");
define ('HTML_TEXT_NAVIGATION_BACK_TO_USER', "Back to file manager");
###
# Need to include this here so they recognize the settings
###
require ("./inc/html.inc.php");
###
# Define the list of file attributes. Format is "internal_name" => "Displayed name"
# This is used both by internally and externally for things like preferences
###
$file_attributes = array ("name" => "Filename", "mime_type" => "MIME Type", "size" => "Size", "created" => "Created", "modified" => "Modified", "owner" => "Owner", "createdby_id" => "Created by", "modifiedby_id" => "Created by", "modifiedby_id" => "Modified by", "app" => "Application", "comment" => "Comment");
###
# Calculate and display B or KB
# And yes, that first if is strange,
# but it does do something
###
function borkb ($size, $enclosed = NULL, $return = 0)
{
if (!$size)
$size = 0;
if ($enclosed)
{
$left = "(";
$right = ")";
}
if ($size < 1024)
$rstring = $left . $size . "B" . $right;
else
$rstring = $left . round($size/1024) . "KB" . $right;
return (eor ($rstring, $return));
}
###
# Check for and return the first unwanted character
###
function bad_chars ($string, $return = 0)
{
2001-06-25 23:14:52 +02:00
if (preg_match("-([\\/<>\"])-", $string, $badchars))
2001-05-21 03:09:20 +02:00
$rstring = $badchars[1];
return trim ((eor ($rstring, $return)));
}
###
# Match character in string using ord ().
2001-05-21 03:09:20 +02:00
###
function ord_match ($string, $charnum)
2001-05-21 03:09:20 +02:00
{
for ($i = 0; $i < strlen ($string); $i++)
{
$character = ord (substr ($string, $i, 1));
2001-05-21 03:09:20 +02:00
if ($character == $charnum)
{
return True;
}
}
return False;
2001-05-21 03:09:20 +02:00
}
###
# Decide whether to echo or return. Used by HTML functions
###
function eor ($rstring, $return)
{
if ($return)
return ($rstring);
else
{
html_text ($rstring . "\n");
return (0);
}
}
###
# 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
###
function string_encode ($string, $return)
{
global $hostname;
if (preg_match ("/=(.*)(&|$)/U", $string))
2001-06-04 00:47:46 +02:00
{
2001-05-21 03:09:20 +02:00
$rstring = preg_replace ("/=(.*)(&|$)/Ue", "'=' . rawurlencode ('\\1') . '\\2'", $string);
2001-06-04 00:47:46 +02:00
}
2001-05-21 03:09:20 +02:00
elseif (ereg ("^$hostname", $string))
{
$rstring = ereg_replace ("^$hostname/", "", $string);
$rstring = preg_replace ("/(.*)(\/|$)/Ue", "rawurlencode ('\\1') . '\\2'", $rstring);
$rstring = "$hostname/$rstring";
}
else
{
$rstring = rawurlencode ($string);
/* Terrible hack, decodes all /'s back to normal */
$rstring = preg_replace ("/%2F/", "/", $rstring);
}
return (eor ($rstring, $return));
}
function string_decode ($string, $return)
{
2001-06-24 11:17:01 +02:00
$rstring = rawurldecode ($string);
2001-05-21 03:09:20 +02:00
return (eor ($rstring, $return));
}
2001-06-19 00:04:45 +02:00
###
# HTML encode a string
# This should be used with anything in an HTML tag that might contain < or >
###
function html_encode ($string, $return)
{
$rstring = htmlspecialchars ($string);
return (eor ($rstring, $return));
}
2001-05-21 03:09:20 +02:00
function translate ($text)
{
global $phpgw;
return ($phpgw->lang ($text));
}
?>