Linux lhjmq-records 5.15.0-118-generic #128-Ubuntu SMP Fri Jul 5 09:28:59 UTC 2024 x86_64
Your IP : 18.223.170.253
<?php
//************************************************************
// * Navigation File Caching System Function Library
// * Use this library to manipulate de cache folders and files
//************************************************************
function navcache_folder_list($mysql_link, $folderpath){
$results = mysql_query('SELECT * FROM navigator_files WHERE path = "' . mysql_escape_string($folderpath) . '"', $mysql_link);
$items = array();
while($item = mysql_fetch_assoc($results)){
if($item[contenttype] == 'system/folder'){
$items['0-'.$item['filename']] = $item;
}else{
$items['1-'.$item['filename']] = $item;
}
}
ksort($items);
return $items;
}
function navcache_get_item($mysql_link, $fullpath){
return mysql_fetch_assoc(mysql_query($sql = 'SELECT * FROM navigator_files WHERE CONCAT(path, "/", filename) = "' . mysql_escape_string($fullpath) . '"', $mysql_link));
}
function navcache_folder_exists($mysql_link, $folderpath, $foldername){
$mysql_rescnt = mysql_num_rows(mysql_query($sql = 'SELECT * FROM navigator_files WHERE filename = "' . mysql_escape_string($foldername) . '" AND path = "' . mysql_escape_string($folderpath) . '"', $mysql_link));
if($mysql_rescnt == 0){
return false;
}else{
return true;
}
}
function navcache_file_exists($mysql_link, $folderpath, $filename){
$mysql_rescnt = mysql_num_rows(mysql_query('SELECT * FROM navigator_files WHERE filename = "' . mysql_escape_string($filename) . '" AND path = "' . mysql_escape_string($folderpath) . '"', $mysql_link));
if($mysql_rescnt == 0){
return false;
}else{
return true;
}
}
function navcache_folder_create($mysql_link, $folderpath, $foldername){
mysql_query($sql = 'INSERT INTO navigator_files (filename, path, contenttype, creationdate, owner) VALUES("' . mysql_escape_string($foldername) . '", "' . mysql_escape_string($folderpath) . '", "system/folder", "' . date("Y-m-d G:i:s") . '", "' . mysql_escape_string($_SESSION['session_username']) . '")', $mysql_link);
}
function navcache_file_create($mysql_link, $folderpath, $filename, $data, $contenttype){
mysql_query($sql='INSERT INTO navigator_files (filename, path, contenttype, systemsorter, creationdate, owner, data) VALUES("' . mysql_escape_string($filename) . '", "' . mysql_escape_string($folderpath) . '", "' . $contenttype . '", 1, "' . date("Y-m-d G:i:s") . '", "' . mysql_escape_string($_SESSION['session_username']) . '", 0x' . bin2hex($data) . ')', $mysql_link);
assert (mysql_affected_rows($mysql_link) == 1);
return mysql_affected_rows($mysql_link);
}
function navcache_folder_validate($foldername){
if(substr($foldername, strlen($foldername) - 5) == '.mime'){
return false;
}elseif(ereg('[^a-zA-Z0-9_]+', $foldername)){
return false;
}
return true;
}
function navcache_file_validate($filename){
if(substr($filename, strlen($filename) - 5) == '.mime'){
return false;
}elseif(ereg('[^a-zA-Z0-9_()-.]+', $filename)){
return false;
}
return true;
}
function navcache_deletefolder($mysql_link, $folderpath, $foldername, $path_to_cache){
global $mysql_link;
//Get all the sub items
$items = navcache_folder_list($mysql_link, $folderpath . '/' . $foldername);
foreach($items as $item){
//Check if it's a file or folder
if($item[contenttype] == 'system/folder'){
navcache_deletefolder($mysql_link, $item['path'], $item['filename'], $path_to_cache);
}else{
navcache_deletefile($mysql_link, $item['path'], $item['filename'], $path_to_cache);
}
}
//Delete the current item
if(is_dir($path_to_cache . $folderpath . '/' . $foldername)){
rmdir($path_to_cache . $folderpath . '/' . $foldername);
}
mysql_query('DELETE FROM navigator_files WHERE path = "' . mysql_escape_string($folderpath) . '" AND filename = "' . mysql_escape_string($foldername) . '"', $mysql_link);
}
function navcache_deletefile($mysql_link, $folderpath, $filename, $path_to_cache){
global $mysql_link;
//File delete
if(is_file($path_to_cache . $folderpath . "/" . $filename)){
unlink($path_to_cache . $folderpath . "/" . $filename);
}
if(is_file($path_to_cache . $folderpath . "/" . $filename.'.mime')){
unlink($path_to_cache . $folderpath . "/" . $filename.'.mime');
}
mysql_query('DELETE FROM navigator_files WHERE path = "' . mysql_escape_string($folderpath) . '" AND filename = "' . mysql_escape_string($filename) . '"', $mysql_link);
}
//Requires a path with filename
function path_extract_filename($path){
return substr($path, strrpos($path, '/')+1);
}
//Requires a path with filename
function path_extract_path($path){
return substr($path, 0, strrpos($path, '/')-1);
}
//Requires a path without filename
function path_split_to_tree($path){
while($path[0] == '/'){$path = substr($path, 1);}
while($path[strlen($path)-1] == '/'){$path = substr($path, 0, strlen($path)-1);}
$exploded = explode('/', $path);
$tree = array();
$topnode = &$tree;
foreach($exploded as $node){
$tree[$node] = array();
$tree = &$tree[$node];
}
return $topnode;
}
//Requires a tree path
function path_create_tree($tree, $path_to_cache, $basepath){
if(is_array($tree)){
foreach($tree as $tree_node => $sub_nodes){
//Build it if not existent
if(!file_exists($path_to_cache . $basepath . '/' . $tree_node)){
mkdir($path_to_cache . $basepath . '/' . $tree_node, 0775);
}
//Check if array, if so pop down that tree
if(is_array($sub_nodes)){
path_create_tree($sub_nodes, $path_to_cache, $basepath.'/'.$tree_node);
}
}}
}
//Requires a file name that will be normalized
function file_name_normalize($filename){
$filename = ereg_replace('[^a-zA-Z0-9()_.]', '_', $filename);
while(strpos($filename, '__')){
$filename = str_replace('__', '_', $filename);
}
return $filename;
}
?>
|