<?php
function errorMsg($error_text){
echo '<b><font color="red">ERROR :</font> '.$error_text.'</b>';
exit();
}
function requirement_checker(){
if(!is_writable('data/')){ errorMsg('Oh no! You have make a boo boo...! Please make sure the "data" directory is writable. Click <a href="http://ifoto.ireans.com/faq" target="_blank">here</a> for more info.'); }
if(function_exists("gd_info")){ $info=gd_info();
if(!strstr($info['GD Version'],"2.")){errorMsg('Please make sure you PHP compiled with GD2. Click <a href="http://ifoto.ireans.com/faq" target="_blank">here</a> for more information.');}
}else{
errorMsg('Please make sure you PHP compiled with GD2. Click <a href="http://ifoto.ireans.com/faq" target="_blank">here</a> for more information.');
}
}
function get_param($get_param){
if(@$return_filtered = $_GET[$get_param]){
$return_filtered = str_replace('<','',$return_filtered);
$return_filtered = str_replace('>','',$return_filtered);
$return_filtered = str_replace('"','',$return_filtered);
$return_filtered = str_replace("'",'',$return_filtered);
$return_filtered = str_replace(";",' ',$return_filtered);
$return_filtered = str_replace(":",' ',$return_filtered);
$return_filtered = stripslashes($return_filtered);
return $return_filtered;
}else{
return false;
}
}
function post_param($get_param){
if(@$return_filtered = $_POST[$get_param]){
$return_filtered = str_replace('<','',$return_filtered);
$return_filtered = str_replace('>','',$return_filtered);
$return_filtered = str_replace('"','',$return_filtered);
$return_filtered = str_replace("'",'',$return_filtered);
$return_filtered = str_replace(";",' ',$return_filtered);
$return_filtered = str_replace(":",' ',$return_filtered);
$return_filtered = stripslashes($return_filtered);
return $return_filtered;
}else{
return false;
}
}
function ClearDirectory($path){
if($dir_handle = opendir($path)){
while($file = readdir($dir_handle)){
if($file == "." || $file == ".."){
if(!@unlink($path."/".$file)){
continue;
}
}else{
@unlink($path."/".$file);
}
}
closedir($dir_handle);
return true;
// all files deleted
}else{
return false;
// directory doesn?t exist
}
}
function RemoveDirectory($path){
if(ClearDirectory($path)){
if(rmdir($path)){
return true;
// directory removed
}else{
return false;
// directory couldn?t removed
}
}else{
return false;
// no empty directory
}
}
function directoryToArray($directory, $recursive) {
$array_items = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($directory. "/" . $file)) {
if($recursive) {
$array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive));
}
$file = $directory . "/" . $file;
$array_items[] = preg_replace("/\/\//si", "/", $file);
} else {
$file = $directory . "/" . $file;
$array_items[] = preg_replace("/\/\//si", "/", $file);
}
}
}
closedir($handle);
}
return $array_items;
}
function readDirectory($current_dir = '', $exclude_dir = false){
$image_list_arr = array();
$opendir = 'gallery/'.$current_dir;
if ($handle = opendir($opendir)) {
while (false !== ($file = readdir($handle))) {
if (($file != '.' AND $file != '..') AND ((substr(strtolower($file),-3) == 'jpg' || substr(strtolower($file),-3) == 'gif' || substr(strtolower($file),-3) == 'png') OR (is_dir($opendir . '/' . $file) AND !$exclude_dir) )) {
$file_original_name = $file;
if(is_dir($opendir . '/' . $file_original_name)){
$item_type = 'dir';
$file_title_return = $file_original_name;
$file = $file_original_name;
$file_width = '';
$file_height = '';
$the_thumbnail = '';
$file_size = '';
$file_modified = '';
}else{
$item_type = 'image';
$file_title = substr($file,0,-4);
list($file_width, $file_height, $type, $attr) = getimagesize('gallery/'.$current_dir.'/'.$file);
if(is_file('data/thumbdata_'.base64_encode($current_dir . ']|[' . $file . ']|[' . filectime('gallery/'.$current_dir.'/'.$file)).'.jpg')){
$the_thumbnail = 'data/thumbdata_'.base64_encode($current_dir . ']|[' . $file . ']|[' . filectime('gallery/'.$current_dir.'/'.$file)).'.jpg';
}else{
$the_thumbnail = 'img_holder.jpg';
}
if(STRIP_SORT_NUMBER AND (is_numeric(substr($file_title,0,1))) AND (substr($file_title,1,1) == '_')){
$file_title_return = substr($file_title,2);
}else{
$file_title_return = $file_title;
}
$file_title_return = str_replace('_', ' ', $file_title_return);
$file_size = filesize('gallery/'.$current_dir.'/'.$file);
$file_modified = filectime('gallery/'.$current_dir.'/'.$file);
}
$image_list_arr[] = array(
'id' => md5($current_dir.$file.time()),
'dir' => $current_dir,
'filename' => $file,
'title' => $file_title_return,
'thumb' => $the_thumbnail,
'width'=> $file_width,
'height' => $file_height,
'filesize' => $file_size,
'modified' => $file_modified,
'item_type' => $item_type);
}
}
closedir($handle);
return $image_list_arr;
}else{
return false;
}
}
function multi_array_sort($array='', $key='', $order='asc')
{
if($array AND $key){
foreach ($array as $i => $k) {
$sort_values[$i] = $array[$i][$key];
}
if($order == 'desc'){
rsort ($sort_values);
}else{
asort ($sort_values);
}
reset ($sort_values);
while (list ($arr_key, $arr_val) = each ($sort_values)) {
$sorted_arr[] = $array[$arr_key];
}
return $sorted_arr;
}else{
return false;
}
}
function multi_array_search($search_value, $the_array)
{
if (is_array($the_array))
{
foreach ($the_array as $key => $value)
{
$result = multi_array_search($search_value, $value);
if (is_array($result))
{
$return = $result;
array_unshift($return, $key);
return $return;
}
elseif ($result == true)
{
$return[] = $key;
return $return;
}
}
return false;
}
else
{
if ($search_value == $the_array)
{
return true;
}
else return false;
}
}
/* for debug purpose */
function pre($sting_to_pre = ''){
if($sting_to_pre){
echo '<pre>';
print_r($sting_to_pre);
echo '</pre>';
}
}
?>