initial commit

This commit is contained in:
Ben Ramey
2017-03-02 21:32:16 -06:00
commit 194e0ca89e
399 changed files with 16444 additions and 0 deletions

View File

@@ -0,0 +1,150 @@
<?php
#################################################################################
# #
# written by benjamin ramey #
# bsr@rameydesign.net #
# #
# This file contains: #
# Functions that perform various filesystem tasks such as removing #
# unwanted types of files/folders from an array of files and folders #
# in a folder #
# #
#################################################################################
############################################# FUNCTION: filesys_get_folder_tree #
# returns: html of folder tree
# parameters: path to root folder
function filesys_get_folder_tree($path)
{
global $_DOC_ROOT,$_SCRIPT_FOLDER;
# variable that will hold all the HTML for the folder
$folderhtml = '';
# get folder contents in alphabetical order
$folder_contents = scandir($path);
# the url is used so that people can download/look at these files through
# the browser, a doc_root path wouldn't work, of course
$url = str_replace($_DOC_ROOT,"$_SCRIPT_FOLDER",$path);
# one by one, set $element to a file or folder inside the passed folder
foreach($folder_contents as $element)
{
# ignore current and parent folders
if( ($element != '.') and ($element != '..') )
{
# make sure each is_dir call is not using cached information
# from last is_dir check
clearstatcache();
# if $element is a folder, call this function recursively and
# create HTML for this subfolder
if( is_dir("$path/$element") )
{
$folderhtml .= "
<div class='folder_name' id='${element}_name'
onclick='ExpandFolder(this)'
onmouseover='ChangeFolderNameBG(this,0)'
onmouseout='ChangeFolderNameBG(this,1)'>
+ $element
</div>
<div class='sub_folder' id='${element}_folder'>";
$folderhtml .= filesys_get_folder_tree("$path/$element");
$folderhtml .= "
</div>\n\n";
}
else
{
# get the size of this file in kilobytes
$file_size_kb = intval(filesize($path.'/'.$element) / 1024);
$folderhtml .= "
+ <a href='/$url/$element'>$element</a>
($file_size_kb Kb)<br />\n";
}
}
}
return $folderhtml;
}
################################################ FUNCTION: filesys_dirs_present #
# returns: true or false
# parameters: path to directory to inspect, pattern to match directory name
# against
function filesys_dirs_present($path,$pattern = "/.*/")
{
# make sure the path passed here is really a directory we can't
# check anything but a directory, since only directory will contain
# other directories, duh
$handle = is_dir($path) ? opendir($path) : NULL ;
if(empty($handle))
{ return(NULL); }
# set through each child in this directory and see if the child
# is directory but not the parent or current directory
# readdir returns FALSE when no children are left to inspect
while($child = readdir($handle) and $child !== false)
{
# make sure each is_dir call is not using cached information
# from last is_dir check
clearstatcache();
# check if this child is directory and whether it
# matches the user given pattern or not
if(is_dir($path.'/'.$child)
and ($child !== '..')
and ($child !== '.')
and (preg_match($pattern,$child)) )
{
# we can return true with the first matching folder we find
# this is an OR operation
return(true);
}
}
# if we get here, no matching folders were found, so none exist
# so we return false
return(false);
}
######################################### FUNCTION: filesys_get_wanted_children #
# returns: array of wanted dir children
# parameters: 1) path to directory; 2) command to remove [files,folders]
# 3) a pattern to match folder/file names against
function filesys_get_wanted_children($path,$cmd,$pattern = "/.*/")
{
# the cmd can be passed as either all cap or not, so conform it
# here to lower case
$cmd = strtolower($cmd);
# fill an array full of the directory children, but only, of course if
# the passed path is really to a directory
$children = is_dir($path) ? scandir($path) : NULL ;
if(empty($children))
{ return(NULL); }
# remove the current and parent directories
$children = preg_grep("/^\.{1,2}$/",$children,PREG_GREP_INVERT);
# get only the children that match the pattern
$children = preg_grep($pattern,$children);
# if files are to be removed, remove them
if($cmd == 'files')
{
foreach($children as $child)
{
if(!is_dir($path.'/'.$child))
{ array_splice($children,array_search($child,$children),1); }
}
}
# if folders are to be removed, remove them
else if($cmd == 'folders')
{
foreach($children as $child)
{
if(is_dir($path.'/'.$child))
{ array_splice($children,array_search($child,$children),1); }
}
}
# return the array of directory children, free of the bad little ones
return($children);
}
?>

View File

@@ -0,0 +1,50 @@
<?php
#################################################################################
# #
# written by benjamin ramey #
# bsr@rameydesign.net #
# #
# This file contains: #
# Functions that govern various images process, such at #
# grabbing a random one from a give folder, etc #
# #
#################################################################################
################################################### FUNCTION: images_get_random #
function images_get_random($folders,$num = 1,$patt = "/.(jpg)|(JPG)/")
{
$images = array();
$folder_info = array();
$num_folders = count($folders);
# get the pictures for each folder
foreach($folders as $key => $value)
{
$folder_info[$key]['name'] = $value;
$folder_info[$key]['pictures'] = filesys_get_wanted_children($value,'folders',$patt);
}
# get pictures until we have enough!
for($k = 0; $k < $num; $k++)
{
$folder = $folder_info[array_rand($folder_info)];
$image = $folder['pictures'][array_rand($folder['pictures'])];
array_push($images,$folder['name'].'/'.$image);
}
return($images);
}
################################################# FUNCTION: images_print_strip #
function images_print_strip($images,$absPath)
{
print "<div id='image-strip'>\n";
foreach($images as $image)
{
$image = str_replace($absPath,'',$image);
print "<img src='$image' />\n";
}
print "</div>";
}
?>