= 1073741824) {
$size = round($size / 1073741824 * 100) / 100 . " GB";
} elseif($size >= 1048576) {
$size = round($size / 1048576 * 100) / 100 . " MB";
} elseif($size >= 1024) {
$size = round($size / 1024 * 100) / 100 . " KB";
} else $size = $size . " Bytes";
if($size==0) $size="-";
return $size;
}
//------------------------------------------------------------------------------
function get_file_date($dir, $item) { // file date
return @filemtime(get_abs_item($dir, $item));
}
//------------------------------------------------------------------------------
function parse_file_date($date) { // parsed file date
return @date($GLOBALS["date_fmt"],$date);
}
//------------------------------------------------------------------------------
function get_is_image($dir, $item) { // is this file an image?
if(!get_is_file($dir, $item)) return false;
return @eregi($GLOBALS["images_ext"], $item);
}
//-----------------------------------------------------------------------------
function get_is_editable($dir, $item) { // is this file editable?
if(!get_is_file($dir, $item)) return false;
foreach($GLOBALS["editable_ext"] as $pat) if(@eregi($pat,$item)) return true;
return strpos( $item, "." ) ? false : true;
}
//-----------------------------------------------------------------------------
function get_mime_type($dir, $item, $query) { // get file's mimetype
if(get_is_dir($dir, $item)) { // directory
$mime_type = $GLOBALS["super_mimes"]["dir"][0];
$image = $GLOBALS["super_mimes"]["dir"][1];
if($query=="img") return $image;
else return $mime_type;
}
// mime_type
foreach($GLOBALS["used_mime_types"] as $mime) {
list($desc,$img,$ext) = $mime;
if(@eregi($ext,$item)) {
$mime_type = $desc;
$image = $img;
if($query=="img") return $image;
else return $mime_type;
}
}
$mime_type = $GLOBALS["super_mimes"]["file"][0];
$image = $GLOBALS["super_mimes"]["file"][1];
if($query=="img")
return $image;
else
return $mime_type;
}
//------------------------------------------------------------------------------
function get_show_item($dir, $item) { // show this file?
if($item == "." || $item == ".." ||
(substr($item,0,1)=="." && $GLOBALS["show_hidden"]==false)) return false;
if($GLOBALS["no_access"]!="" && @eregi($GLOBALS["no_access"],$item)) return false;
if($GLOBALS["show_hidden"]==false) {
$dirs=explode("/",$dir);
foreach($dirs as $i) if(substr($i,0,1)==".") return false;
}
return true;
}
//------------------------------------------------------------------------------
function copy_dir($source,$dest) { // copy dir
$ok = true;
if(!@mkdir($dest,0777)) return false;
if(($handle=@opendir($source))===false)
show_error(basename($source).": ".$GLOBALS["error_msg"]["opendir"]);
while(($file=readdir($handle))!==false) {
if(($file==".." || $file==".")) continue;
$new_source = $source."/".$file;
$new_dest = $dest."/".$file;
if(@is_dir($new_source)) {
$ok=copy_dir($new_source,$new_dest);
} else {
$ok=@copy($new_source,$new_dest);
}
}
closedir($handle);
return $ok;
}
//------------------------------------------------------------------------------
function remove($item) { // remove file / dir
$item = realpath($item);
$ok = true;
if( is_link($item) || is_file($item))
$ok = unlink($item);
elseif( is_dir($item)) {
if(($handle= opendir($item))===false)
show_error(basename($item).": ".$GLOBALS["error_msg"]["opendir"]);
while(($file=readdir($handle))!==false) {
if(($file==".." || $file==".")) continue;
$new_item = $item."/".$file;
if(!file_exists($new_item))
show_error(basename($item).": ".$GLOBALS["error_msg"]["readdir"]);
//if(!get_show_item($item, $new_item)) continue;
if( is_dir($new_item)) {
$ok=remove($new_item);
} else {
$ok= unlink($new_item);
}
}
closedir($handle);
$ok=@rmdir($item);
}
return $ok;
}
function chmod_recursive($item, $mode) { // chmod file / dir
$ok = true;
if(@is_link($item) || @is_file($item))
$ok=@chmod( $item, $mode );
elseif(@is_dir($item)) {
if(($handle=@opendir($item))===false) show_error(basename($item).": ".$GLOBALS["error_msg"]["opendir"]);
while(($file=readdir($handle))!==false) {
if(($file==".." || $file==".")) continue;
$new_item = $item."/".$file;
if(!@file_exists($new_item)) show_error(basename($item).": ".$GLOBALS["error_msg"]["readdir"]);
//if(!get_show_item($item, $new_item)) continue;
if(@is_dir($new_item)) {
$ok=chmod_recursive($new_item, $mode);
} else {
$ok=@chmod($new_item, $mode);
}
}
closedir($handle);
$ok=@chmod( $item, $mode );
}
return $ok;
}
//------------------------------------------------------------------------------
function get_max_file_size() { // get php max_upload_file_size
$max = ini_get("upload_max_filesize");
if(@eregi("G$",$max)) {
$max = substr($max,0,-1);
$max = round($max*1073741824);
} elseif(@eregi("M$",$max)) {
$max = substr($max,0,-1);
$max = round($max*1048576);
} elseif(@eregi("K$",$max)) {
$max = substr($max,0,-1);
$max = round($max*1024);
}
return $max;
}
//------------------------------------------------------------------------------
function down_home($abs_dir) { // dir deeper than home?
$real_home = @realpath($GLOBALS["home_dir"]);
$real_dir = @realpath($abs_dir);
if($real_home===false || $real_dir===false) {
if(@eregi("\\.\\.",$abs_dir)) return false;
} else if(strcmp($real_home,@substr($real_dir,0,strlen($real_home)))) {
return false;
}
return true;
}
//------------------------------------------------------------------------------
function id_browser() {
$browser=$GLOBALS['__SERVER']['HTTP_USER_AGENT'];
if(ereg('Opera(/| )([0-9].[0-9]{1,2})', $browser)) {
return 'OPERA';
} else if(ereg('MSIE ([0-9].[0-9]{1,2})', $browser)) {
return 'IE';
} else if(ereg('OmniWeb/([0-9].[0-9]{1,2})', $browser)) {
return 'OMNIWEB';
} else if(ereg('(Konqueror/)(.*)', $browser)) {
return 'KONQUEROR';
} else if(ereg('Mozilla/([0-9].[0-9]{1,2})', $browser)) {
return 'MOZILLA';
} else {
return 'OTHER';
}
}
function is_archive( $file ) {
$file_info = pathinfo($file);
if (isset($file_info["extension"])) {
$ext = @$file_info["extension"];
if( $ext == "tar" || $ext == "gz" || $ext == "zip" || $ext == "bzip2" || $ext == "bz2" || $ext == "tbz") {
return true;
}
}
return false;
}
function posix_my_geteuid($ow) {
if( !(function_exists('posix_geteuid'))) {
return $ow;
} else {
$ini_val = ini_get("disable_functions");
$pos = strpos($ini_val,"posix_geteuid");
if ($pos === false) {
return posix_geteuid();
} else {
return $ow;
}
}
}
function gettwgmyuid($ow) {
$ini_val = ini_get("disable_functions");
$pos = strpos($ini_val,"getmyuid");
if ($pos !== false) {
return @getmyuid();
} else {
return $ow;
}
}
/**
* determines if the safemode is on and if a directory has a problem
* because of the owner
*
* @param string $dir The full path to the file
* @return boolean
*/
function has_safemode_problem( $file ) {
$owner = fileowner($file);
if(ini_get('safe_mode') == 1 && (gettwgmyuid($owner) != $owner)) {
return true;
}
return false;
}
function has_safemode_problem_global() {
global $isWindows;
$no_cgi = true;
if (isset($_SERVER["SERVER_SOFTWARE"])) {
$mystring = $_SERVER["SERVER_SOFTWARE"];
$pos = strpos ($mystring, "CGI");
if ($pos === false) {
// nicht gefunden...
} else {
$no_cgi = false;
}
$mystring = $_SERVER["SERVER_SOFTWARE"];
$pos = strpos ($mystring, "cgi");
if ($pos === false) {
// nicht gefunden...
} else {
$no_cgi = false;
}
}
if(ini_get('safe_mode') == 1 && $no_cgi && !$isWindows) {
return true;
}
return false;
}
/**
* determines if a file is deletable based on directory ownership, permissions,
* and php safemode.
*
* @param string $dir The full path to the file
* @return boolean
*/
function is_deletable( $file ) {
global $isWindows;
$owner = fileowner($file);
// if dir owner not same as effective uid of this process, then perms must be full 777.
// No other perms combo seems reliable across system implementations
if(!$isWindows && posix_my_geteuid($owner) !== $owner) {
return (substr(decoct(@fileperms($file)),-3) == '777' || @is_writable(dirname($file)) );
}
if($isWindows && (gettwgmyuid($owner) != $owner)) {
return (substr(decoct(fileperms($file)),-3) == '777');
}
// otherwise if this process owns the directory, we can chmod it ourselves to delete it
return is_writable(dirname($file));
}
function is_chmodable( $file ) {
global $isWindows;
if( $isWindows ) {
return true;
}
$owner = fileowner($file);
if( @fileowner( $file ) == posix_my_geteuid($owner)) {
return true;
}
return false;
}
//------------------------------------------------------------------------------
/**
* Utility function to provide ToolTips
* @param string ToolTip text
* @param string Box title
* @returns HTML code for ToolTip
*/
function toolTip( $tooltip, $title='', $width='', $image='help.gif', $text='', $href='#', $link=1 ) {
global $mosConfig_live_site;
if ( $width ) {
$width = ', WIDTH, \''.$width .'\'';
}
if ( $title ) {
$title = ', CAPTION, \''.$title .'\'';
}
if ( !$text ) {
$image = '_img/'. $image;
$text = '';
}
$style = 'style="text-decoration: none; color: #333;"';
if ( $href ) {
$style = '';
}
else{ $href = "#"; }
if ( $link ) {
$tip = "". $text ."";
} else {
$tip = "". $text ."";
}
return $tip;
}
/**
* Utility function to return a value from a named array or a specified default
*/
define( "_MOS_NOTRIM", 0x0001 );
define( "_MOS_ALLOWHTML", 0x0002 );
function mosGetParam( &$arr, $name, $def=null, $mask=0 ) {
$return = null;
if (isset( $arr[$name] )) {
if (is_string( $arr[$name] )) {
if (!($mask&_MOS_NOTRIM)) {
$arr[$name] = trim( $arr[$name] );
}
if (!($mask&_MOS_ALLOWHTML)) {
$arr[$name] = strip_tags( $arr[$name] );
}
if (!get_magic_quotes_gpc()) {
$arr[$name] = addslashes( $arr[$name] );
}
}
return $arr[$name];
} else {
return $def;
}
}
/*
*
* New for TWG
*
*/
function check_explorer_image_extension($image)
{
return preg_match("/.*\.(j|J)(p|P)(e|E){0,1}(g|G)$/", $image) ||
preg_match("/.*\.(g|G)(i|I)(f|F)$/", $image) ||
preg_match("/.*\.(p|P)(n|N)(g|G)$/", $image);
}
function check_jpg_extension($image)
{
return preg_match("/.*\.(j|J)(p|P)(e|E){0,1}(g|G)$/", $image);
}
/*
* Returns the album part of the path - false if it is no twg path
* This function is not very save! - it asumes that the pictures folder is
* unique below the TWG structure (and it is normally ;))
*/
function get_twg_album($dir) {
global $basedir;
$dir = get_abs_dir_tfu($dir);
if (strrchr ($basedir, ".")) {
return false; // we have a . in the path - most likely ../ means pictures dir in somewhere outside of TWG and Admin would lead to a wrong position!
} else {
$workdir = $basedir;
}
$position = strpos ($dir, $workdir . "/");
if ($position === false) {
return false;
} else {
return substr($dir, $position + strlen($workdir . "/") );
}
}
function get_php_setting($val) {
$r = (ini_get($val) == '1' ? 1 : 0);
return $r ? 'ON' : 'OFF';
}
function get_php_setting_val($val) {
$r = ini_get($val);
return $r;
}
function return_bytes($val) {
if ($val) {
$val = trim($val);
$last = strtolower($val{strlen($val)-1});
switch($last) {
case 'm':
$val *= 1024;
}
}
return $val;
}
/*
resizes a file and stores it back to the original location
*/
function resize_file($image, $size, $compression) {
$srcx = 0;
$srcy = 0;
if (file_exists($image)) {
$oldsize = getimagesize($image);
$oldsizex = $oldsize[0];
$oldsizey = $oldsize[1];
if (($oldsizex<$size) && ($oldsizey<$size)) {
return false;
}
if ($oldsizex > $oldsizey) { // querformat - this keeps the dimension between horzonal and vertical
$width = $size;
$height = ($width / $oldsizex) * $oldsizey;
} else { // hochformat - this keeps the dimension between horzonal an vertical
$height = $size;
$width = ($height / $oldsizey) * $oldsizex;
}
$src = imagecreatefromjpeg($image);
if (gd_version() >= 2) {
$dst = ImageCreateTrueColor($width, $height);
} else {
$dst = imagecreate ($width, $height);
imageJPEG($dst, $small . '256');
$dst = @imagecreatefromjpeg($small . '256');
}
if (gd_version() >= 2) {
// center clipped images ! - but only the vertical ones - horizontal are mainly images of people and there the upper part should be shown
imagecopyresampled($dst, $src, 0, 0, $srcx, $srcy , $width, $height, $oldsizex, $oldsizey);
} else {
ImageCopyResized($dst, $src, 0, 0, 0, 0, $width, $height, $oldsizex, $oldsizey);
}
if (imagejpeg($dst, $image, $compression)) {
@imagedestroy($dst);
return true;
} else {
debug('cannot save: ' . $image);
@imagedestroy($src);
return false;
}
} else
return false;
}
/**
can only be called from the administration !!
*/
function delete_image_cache() {
global $cachedir;
delete_image_cache_body($cachedir);
}
function delete_image_cache_body($dir)
{
global $extension_slideshow,$extension_small,$extension_thumb;
if (file_exists($dir)) {
$d = opendir($dir);
$i = 0;
while (false !== ($entry = readdir($d))) {
$path = $dir . "/" . $entry;
if ($entry != "." && $entry != ".." && is_dir($path)) {
delete_image_cache_body($path);
rmdir($path); // should be empty now.
} else if (stristr($entry, $extension_slideshow) || stristr($entry, $extension_small)
|| stristr($entry, $extension_thumb ) || stristr($entry, ".tmp" )) {
unlink($path);
}
}
closedir($d);
} else {
echo 'Cannot find the cache directory at ' . $dir . ' - please check your configuration.';
}
}
/**
can only be called from the administration !!
*/
function delete_rotation_cache()
{
global $cachedir;
if (file_exists( $cachedir)) {
$d = opendir( $cachedir);
$i = 0;
while (false !== ($entry = readdir($d))) {
if (stristr($entry, ".rot")) {
unlink( $cachedir . "/" . $entry);
}
}
closedir($d);
} else {
echo 'Cannot find the cache directory at ' . $cachedir . ' - please check your configuration.';
}
}
/**
can only be called from the administration !!
*/
function delete_tmp_cache()
{
global $cachedir;
if (file_exists($cachedir)) {
$d = opendir( $cachedir);
$i = 0;
while (false !== ($entry = readdir($d))) {
if (stristr($entry, ".tmp")) {
unlink( $cachedir . "/" . $entry);
}
}
closedir($d);
} else {
echo 'Cannot find the cache directory at ' . $cachedir . ' - please check your configuration.';
}
}
function invalidateSession() {
global $cachedir;
set_error_handler("on_error_no_output");// @does not work
@session_start();
@session_destroy();
remove_tmp_files();
@session_start();
set_error_handler("on_error");
}
function show_message() {
if (isset($_SESSION["user_msg"])) {
if (isset($_SESSION["user_msg_counter"])) {
unset ($_SESSION["user_msg_counter"]);
} else {
echo "