+++ /dev/null
-<?php\r
-// *************************CREATE FOLDER**********************************\r
-function createfolder($dir,$perm) {\r
-is_dir(dirname($dir)) || createfolder(dirname($dir), $perm);\r
- return is_dir($dir) || @mkdir($dir, $perm);\r
-}\r
-\r
-// *************************VALIDATE FILE EXTENSIONS**********************************\r
-function validateExtension($extension, $types) {\r
-if(in_array($extension,$types)) return false; else return true;\r
-}\r
-\r
-//*************************************Display Alert Notifications*********************************\r
-function alert(&$notify){\r
-$alert_num = count($notify['type']);\r
-for($i=0;$i<$alert_num;$i++)\r
- {\r
- ?><div class="alert<?php echo $notify['type'][$i]; ?>"><?php echo $notify['message'][$i]; ?></div><br /><?php\r
- }\r
-}\r
-\r
-// *************************SORT FILE ARRAY BY SELECTED ORDER**********************************\r
-function sortfileorder(&$sortbynow,&$sortorder,&$file) {\r
-\r
-switch($sortbynow) \r
- {\r
- case 'name':\r
- array_multisort($file['sortname'], $sortorder, $file['name'], $sortorder, $file['type'], $sortorder, $file['modified'], $sortorder, $file['size'], $sortorder, $file['dimensions'], $sortorder, $file['width'], $sortorder, $file['height'], $sortorder);\r
- break;\r
- case 'size':\r
- array_multisort($file['size'], $sortorder, $file['sortname'], SORT_ASC, $file['name'], SORT_ASC, $file['type'], $sortorder, $file['modified'], $sortorder, $file['dimensions'], $sortorder, $file['width'], $sortorder, $file['height'], $sortorder);\r
- break;\r
- case 'type':\r
- array_multisort($file['type'], $sortorder, $file['sortname'], SORT_ASC, $file['name'], SORT_ASC, $file['size'], $sortorder, $file['modified'], $sortorder, $file['dimensions'], $sortorder, $file['width'], $sortorder, $file['height'], $sortorder);\r
- break;\r
- case 'modified':\r
- array_multisort($file['modified'], $sortorder, $file['name'], $sortorder, $file['name'], $sortorder, $file['type'], $sortorder, $file['size'], $sortorder, $file['dimensions'], $sortorder, $file['width'], $sortorder, $file['height'], $sortorder);\r
- break;\r
- case 'dimensions':\r
- array_multisort($file['dimensions'], $sortorder, $file['width'], $sortorder, $file['sortname'], SORT_ASC, $file['name'], SORT_ASC, $file['modified'], $sortorder, $file['type'], $sortorder, $file['size'], $sortorder, $file['height'], $sortorder);\r
- break;\r
- default:\r
- // do nothing\r
- }\r
-}\r
-\r
-// **************************RESIZE IMAGE TO GIVEN SIZE*****************************************\r
-function resizeimage($im,$maxwidth,$maxheight,$urlandname,$comp,$imagetype){\r
-$width = imagesx($im);\r
-$height = imagesy($im);\r
-if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight))\r
- {\r
- if($maxwidth && $width > $maxwidth)\r
- {\r
- $widthratio = $maxwidth/$width;\r
- $resizewidth=true;\r
- } \r
- else $resizewidth=false;\r
-\r
- if($maxheight && $height > $maxheight)\r
- {\r
- $heightratio = $maxheight/$height;\r
- $resizeheight=true;\r
- } \r
- else $resizeheight=false;\r
-\r
- if($resizewidth && $resizeheight)\r
- {\r
- if($widthratio < $heightratio) $ratio = $widthratio;\r
- else $ratio = $heightratio;\r
- }\r
- elseif($resizewidth)\r
- {\r
- $ratio = $widthratio;\r
- }\r
- elseif($resizeheight)\r
- {\r
- $ratio = $heightratio;\r
- }\r
- $newwidth = $width * $ratio;\r
- $newheight = $height * $ratio;\r
- if(function_exists('imagecopyresampled') && $imagetype !='image/gif')\r
- {\r
- $newim = imagecreatetruecolor($newwidth, $newheight);\r
- }\r
- else\r
- {\r
- $newim = imagecreate($newwidth, $newheight);\r
- }\r
-\r
- // additional processing for png / gif transparencies (credit to Dirk Bohl)\r
- if($imagetype == 'image/x-png' || $imagetype == 'image/png')\r
- {\r
- imagealphablending($newim, false);\r
- imagesavealpha($newim, true);\r
- }\r
- elseif($imagetype == 'image/gif')\r
- {\r
- $originaltransparentcolor = imagecolortransparent( $im );\r
- if($originaltransparentcolor >= 0 && $originaltransparentcolor < imagecolorstotal( $im ))\r
- {\r
- $transparentcolor = imagecolorsforindex( $im, $originaltransparentcolor );\r
- $newtransparentcolor = imagecolorallocate($newim,$transparentcolor['red'],$transparentcolor['green'],$transparentcolor['blue']);\r
- imagefill( $newim, 0, 0, $newtransparentcolor );\r
- imagecolortransparent( $newim, $newtransparentcolor );\r
- }\r
- }\r
-\r
- imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);\r
- \r
- if($imagetype == 'image/pjpeg' || $imagetype == 'image/jpeg')\r
- {\r
- imagejpeg ($newim,$urlandname,$comp);\r
- }\r
- elseif($imagetype == 'image/x-png' || $imagetype == 'image/png')\r
- {\r
- imagepng ($newim,$urlandname,substr($comp,0,1));\r
- }\r
- elseif($imagetype == 'image/gif')\r
- {\r
- imagegif ($newim,$urlandname);\r
- }\r
- imagedestroy ($newim);\r
- }\r
-else\r
- {\r
- if($imagetype == 'image/pjpeg' || $imagetype == 'image/jpeg')\r
- {\r
- imagejpeg ($im,$urlandname,$comp);\r
- }\r
- elseif($imagetype == 'image/x-png' || $imagetype == 'image/png')\r
- {\r
- imagepng ($im,$urlandname,substr($comp,0,1));\r
- }\r
- elseif($imagetype == 'image/gif')\r
- {\r
- imagegif ($im,$urlandname);\r
- }\r
- }\r
-}\r
-\r
-// **************************CHECK IMAGE TYPE AND CONVERT TO TEMP TYPE*****************************\r
-function convert_image($imagetemp,$imagetype){\r
-\r
-if($imagetype == 'image/pjpeg' || $imagetype == 'image/jpeg')\r
- {\r
- $cim1 = imagecreatefromjpeg($imagetemp);\r
- }\r
-elseif($imagetype == 'image/x-png' || $imagetype == 'image/png')\r
- {\r
- $cim1 = imagecreatefrompng($imagetemp);\r
- imagealphablending($cim1, false);\r
- imagesavealpha($cim1, true);\r
- }\r
-elseif($imagetype == 'image/gif')\r
- {\r
- $cim1 = imagecreatefromgif($imagetemp);\r
- }\r
-return $cim1;\r
-}\r
-\r
-// **************************GENERATE FORM OPEN*****************************\r
-function form_open($name,$class,$url,$parameters){\r
-?><form name="<?php echo $name; ?>" class="<?php echo $class; ?>" method="post" action="<?php echo $url.$parameters; ?>">\r
-<?php\r
-}\r
-\r
-// **************************GENERATE FORM SELECT ELEMENT*****************************\r
-function form_select($options,$name,$label,$current,$auto){\r
-if ($label) {?><label for="<?php echo $name; ?>"><?php echo $label; ?></label><?php } \r
-?><select name="<?php echo $name; ?>" <?php if ($auto) {?>onchange="this.form.submit();"<?php }?>>\r
-<?php\r
-$loopnum = count($options); \r
-for($i=0;$i<$loopnum;$i++)\r
- {\r
- $selected = ($options[$i][0] == $current ? ' selected' : ''); \r
- echo '<option value="'.$options[$i][0].'"'.$selected.'>'.$options[$i][1].'</option>';\r
- }\r
-?></select><?php\r
-}\r
-\r
-// **************************GENERATE FORM HIDDEN ELEMENT*****************************\r
-function form_hidden_input($name,$value) {\r
-?><input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>" />\r
-<?php\r
-}\r
-\r
-// **************************GENERATE FORM TEXT ELEMENT*****************************\r
-function form_text_input($name,$label,$value,$size,$maxlength) {\r
-if ($label) {?><label for="<?php echo $name; ?>"><?php echo $label; ?></label><?php } ?>\r
-<input type="text" name="<?php echo $name; ?>" size="<?php echo $size; ?>" maxlength="<?php echo $maxlength; ?>" value="<?php echo $value; ?>" /><?php\r
-}\r
-\r
-// **************************GENERATE FORM SUBMIT BUTTON*****************************\r
-function form_submit_button($name,$label,$class) {\r
-?><button <?php if ($class) {?>class="<?php echo $class; ?>"<?php } ?>type="submit" name="<?php echo $name; ?>"><?php echo $label; ?></button>\r
-</form>\r
-<?php\r
-}\r
-\r
-//********************************Returns True if Number is Odd**************************************\r
-function IsOdd($num)\r
-{\r
-return (1 - ($num & 1));\r
-}\r
-\r
-//********************************Truncate Text to Given Length If Required***************************\r
-function truncate_text($textstring,$length){\r
- if (strlen($textstring) > $length)\r
- {\r
- $textstring = substr($textstring,0,$length).'...';\r
- }\r
- return $textstring;\r
-}\r
-\r
-/**\r
- * Present a size (in bytes) as a human-readable value\r
- * \r
- * @param int $size size (in bytes)\r
- * @param int $precision number of digits after the decimal point\r
- * @return string\r
- */\r
-function bytestostring($size, $precision = 0) {\r
- $sizes = array('YB', 'ZB', 'EB', 'PB', 'TB', 'GB', 'MB', 'KB', 'B');\r
- $total = count($sizes);\r
-\r
- while($total-- && $size > 1024) $size /= 1024;\r
- return round($size, $precision).' '.$sizes[$total];\r
-}\r
-\r
-//function to clean a filename string so it is a valid filename\r
-function clean_filename($filename){\r
- $filename = preg_replace('/^\W+|\W+$/', '', $filename); // remove all non-alphanumeric chars at begin & end of string\r
- $filename = preg_replace('/\s+/', '_', $filename); // compress internal whitespace and replace with _\r
- return strtolower(preg_replace('/\W-/', '', $filename)); // remove all non-alphanumeric chars except _ and -\r
-\r
-}\r
-\r
-//********************************Return File MIME Type***************************\r
-function returnMIMEType($filename)\r
- {\r
- preg_match("|\.([a-z0-9]{2,4})$|i", $filename, $fileSuffix);\r
-\r
- switch(strtolower($fileSuffix[1]))\r
- {\r
- case 'js' :\r
- return 'application/x-javascript';\r
-\r
- case 'json' :\r
- return 'application/json';\r
-\r
- case 'jpg' :\r
- case 'jpeg' :\r
- case 'jpe' :\r
- return 'image/jpg';\r
-\r
- case 'png' :\r
- case 'gif' :\r
- case 'bmp' :\r
- case 'tiff' :\r
- return 'image/'.strtolower($fileSuffix[1]);\r
-\r
- case 'css' :\r
- return 'text/css';\r
-\r
- case 'xml' :\r
- return 'application/xml';\r
-\r
- case 'doc' :\r
- case 'docx' :\r
- return 'application/msword';\r
-\r
- case 'xls' :\r
- case 'xlt' :\r
- case 'xlm' :\r
- case 'xld' :\r
- case 'xla' :\r
- case 'xlc' :\r
- case 'xlw' :\r
- case 'xll' :\r
- return 'application/vnd.ms-excel';\r
-\r
- case 'ppt' :\r
- case 'pps' :\r
- return 'application/vnd.ms-powerpoint';\r
-\r
- case 'rtf' :\r
- return 'application/rtf';\r
-\r
- case 'pdf' :\r
- return 'application/pdf';\r
-\r
- case 'html' :\r
- case 'htm' :\r
- case 'php' :\r
- return 'text/html';\r
-\r
- case 'txt' :\r
- return 'text/plain';\r
-\r
- case 'mpeg' :\r
- case 'mpg' :\r
- case 'mpe' :\r
- return 'video/mpeg';\r
-\r
- case 'mp3' :\r
- return 'audio/mpeg3';\r
-\r
- case 'wav' :\r
- return 'audio/wav';\r
-\r
- case 'aiff' :\r
- case 'aif' :\r
- return 'audio/aiff';\r
-\r
- case 'avi' :\r
- return 'video/msvideo';\r
-\r
- case 'wmv' :\r
- return 'video/x-ms-wmv';\r
-\r
- case 'mov' :\r
- return 'video/quicktime';\r
-\r
- case 'zip' :\r
- return 'application/zip';\r
-\r
- case 'tar' :\r
- return 'application/x-tar';\r
-\r
- case 'swf' :\r
- return 'application/x-shockwave-flash';\r
-\r
- default :\r
- if(function_exists('mime_content_type'))\r
- {\r
- $fileSuffix = mime_content_type($filename);\r
- }\r
-\r
- return 'unknown/' . trim($fileSuffix[0], '.');\r
- }\r
- }\r
-\r
-//************************Return Array of Directory Structure***************************\r
-function dirtree(&$alldirs,$types='*.*',$root='',$tree='',$branch='',$level=0) {\r
-\r
-// filter file types according to type\r
-$filetypes = explode(',',preg_replace('{[ \t]+}', '',$types));\r
-\r
-if($level==0 && is_dir($root.$tree.$branch))\r
- {\r
- $filenum=0;\r
- foreach($filetypes as $filetype)\r
- {\r
- $filenum = $filenum + count(glob($root.$tree.$branch.sql_regcase($filetype),GLOB_NOSORT));\r
- }\r
- $treeparts = explode('/',rtrim($tree,'/'));\r
- $topname = end($treeparts);\r
- $alldirs[] = array($branch,rtrim($topname,'/').' ('.$filenum.')',rtrim($topname,'/'),rtrim($topname,'/'),$filenum,filemtime($root.$tree.$branch));\r
- }\r
-$level++;\r
-\r
-$dh = opendir($root.$tree.$branch);\r
-while (($dirname = readdir($dh)) !== false)\r
- {\r
- if($dirname != '.' && $dirname != '..' && is_dir($root.$tree.$branch.$dirname) && $dirname != '_thumbs')\r
- {\r
- $filenum=0;\r
- foreach($filetypes as $filetype)\r
- {\r
- $filenum = $filenum + count(glob($root.$tree.$branch.$dirname.'/'.sql_regcase($filetype),GLOB_NOSORT));\r
- }\r
- $indent = '';\r
- for($i=0;$i<$level;$i++) { $indent .= ' '; }\r
- if(strlen($indent)>0) $indent .= '→ ';\r
- $alldirs[] = array(urlencode($branch.$dirname.'/'),$indent.$dirname.' ('.$filenum.')',$indent.$dirname,$dirname,$filenum,filemtime($root.$tree.$branch.$dirname));\r
- dirtree($alldirs,$types,$root,$tree,$branch.$dirname.'/',$level);\r
- }\r
- }\r
-closedir($dh);\r
-$level--;\r
-}\r
-\r
-/* user defined error handling function. */\r
-function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)\r
-{\r
- // timestamp for the error entry.\r
- $dt = date('Y-m-d H:i:s (T)');\r
-\r
- // define an assoc array of error string\r
- // in reality the only entries we should\r
- // consider are E_WARNING, E_NOTICE, E_USER_ERROR,\r
- // E_USER_WARNING and E_USER_NOTICE.\r
- $errortype = array (\r
- E_ERROR => 'Error',\r
- E_WARNING => 'Warning',\r
- E_PARSE => 'Parsing Error',\r
- E_NOTICE => 'Notice',\r
- E_CORE_ERROR => 'Core Error',\r
- E_CORE_WARNING => 'Core Warning',\r
- E_COMPILE_ERROR => 'Compile Error',\r
- E_COMPILE_WARNING => 'Compile Warning',\r
- E_USER_ERROR => 'User Error',\r
- E_USER_WARNING => 'User Warning',\r
- E_USER_NOTICE => 'User Notice',\r
- E_STRICT => 'Runtime Notice'\r
- );\r
- // set of errors for which a var trace will be saved.\r
- $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);\r
-\r
- if($errno != E_STRICT) // exclude Runtime Notices\r
- {\r
- $err = $dt. "\t";\r
- $err .= $errno.' '.$errortype[$errno]. "\t";\r
- $err .= $errmsg. "\t";\r
- $err .= 'File: '.basename($filename). "\t";\r
- $err .= 'Line: '.$linenum. "\t";\r
-\r
- if (in_array($errno, $user_errors))\r
- {\r
- $err .= 'Trace: '.wddx_serialize_value($vars, 'Variables'). "\t";\r
- }\r
- $err .= "\n";\r
-\r
- // save to the error log file, and e-mail me if there is a critical user error.\r
- error_log($err, 3, 'error.log');\r
- }\r
-}\r
-$old_error_handler = set_error_handler('userErrorHandler');\r
-\r
-?>\r