【php开源代码栏目提醒】:网学会员在php开源代码频道为大家收集整理了commom_functions.php提供大家参考,希望对大家有所帮助!
<?
// get a list of messages in a especified folder (file.eml)
if (!isset($f_pass))
$f_user="";
if (!isset($f_user))
$f_pass="";
if(strlen($f_user) > 0 && strlen($f_pass) > 0) {
if($allow_user_change) {
if($lng != "") $lid = $lng;
else { $lid = $default_language; }
} else
$lid = $default_language;
}
function build_local_list($folder) {
$md = new mime_decode();
$i = 0;
$msglist = Array();
$d = dir($folder);
$dirsize = 0;
while($entry=$d->read()) {
$fullpath = "$folder/$entry";
if( is_file($fullpath)) {
$thismail = read_file($fullpath);
$thismail = $md->fetch_structure($thismail);
$thisheader = $thismail["header"];
$mail_info = $md->get_mail_info($thisheader);
$decoded_headers = $md->decode_header($thisheader);
$msglist[$i]["id"] = $i+1;
$msglist[$i]["msg"] = $i;
$msglist[$i]["size"] = filesize($fullpath);
$msglist[$i]["date"] = $mail_info["date"];
$msglist[$i]["subject"] = $mail_info["subject"];
$msglist[$i]["message-id"] = $mail_info["message-id"];
$msglist[$i]["from"] = $mail_info["from"];
$msglist[$i]["to"] = $mail_info["to"];
$msglist[$i]["cc"] = $mail_info["cc"];
$msglist[$i]["headers"] = $header;
$msglist[$i]["attach"] = (eregi("(multipart/mixed|multipart/related|application)",$mail_info["content-type"]))?1:0;
$msglist[$i]["localname"] = $fullpath;
$msglist[$i]["read"] = ($decoded_headers["status"] == "N")?0:1;
$i++;
}
}
$d->close();
return $msglist;
}
function get_usage_graphic($used,$aval) {
if($used >= $aval) {
$redsize = 100;
$graph = "<img src=images/red.gif height=10 width=$redsize>";
} elseif($used == 0) {
$greesize = 100;
$graph = "<img src=images/green.gif height=10 width=$greesize>";
} else {
$usedperc = $used*100/$aval;
$redsize = ceil($usedperc);
$greesize = ceil(100-$redsize);
$red = "<img src=images/red.gif height=10 width=$redsize>";
$green = "<img src=images/green.gif height=10 width=$greesize>";
$graph = $red.$green;
}
return $graph;
}
function get_total_used_size() {
global $userfolder;
$d = dir($userfolder);
$totalused = 0;
while($entry=$d->read()) {
$thiss = $userfolder.$entry;
if(is_dir($thiss) &&
$entry != ".." &&
substr($entry,0,1) != "_" &&
$entry != ".") {
$totalused += get_folder_size($entry);
}
}
return $totalused;
}
function get_folder_size($folder) {
global $sess,$userfolder;
$dirsize = 0;
if ($folder == "inbox") {
$thisbox = $sess["headers"];
for($i=0;$i<count($thisbox);$i++)
$dirsize += $thisbox[$i]["size"];
} else {
$dir = $userfolder.$folder;
$d = dir($dir);
while($entry=$d->read()) {
$fullpath = "$dir/$entry";
if( is_file($fullpath))
$dirsize += filesize($fullpath);
}
$d->close();
unset($d);
}
//echo($folder . " " . $dirsize."<br>");
return $dirsize;
}
// remove dirs recursivelly
function RmdirR($location) {
if (substr($location,-1) <> "/") $location = $location."/";
$all=opendir($location);
while ($file=readdir($all)) {
if (is_dir($location.$file) && $file <> ".." && $file <> ".") {
RmdirR($location.$file);
unset($file);
} elseif (!is_dir($location.$file)) {
unlink($location.$file);
unset($file);
}
}
closedir($all);
unset($all);
rmdir($location);
}
// sort an multidimension array
function array_qsort2 (&$array, $column=0, $order="ASC", $first=0, $last= -2) {
if($last == -2) $last = count($array) - 1;
if($last > $first) {
$alpha = $first;
$omega = $last;
$guess = $array[$alpha][$column];
while($omega >= $alpha) {
if($order == "ASC") {
while(strtolower($array[$alpha][$column]) < strtolower($guess)) $alpha++;
while(strtolower($array[$omega][$column]) > strtolower($guess)) $omega--;
} else {
while(strtolower($array[$alpha][$column]) > strtolower($guess)) $alpha++;
while(strtolower($array[$omega][$column]) < strtolower($guess)) $omega--;
}
if(strtolower($alpha) > strtolower($omega)) break;
$temporary = $array[$alpha];
$array[$alpha++] = $array[$omega];
$array[$omega--] = $temporary;
}
array_qsort2 ($array, $column, $order, $first, $omega);
array_qsort2 ($array, $column, $order, $alpha, $last);
}
}
// load session info
function load_session() {
global $temporary_directory,$sid;
$sessionfile = $temporary_directory."_sessions/$sid.usf";
$result = Array();
i