2 // *************************CREATE FOLDER**********************************
\r
3 function createfolder($dir,$perm) {
\r
4 is_dir(dirname($dir)) || createfolder(dirname($dir), $perm);
\r
5 return is_dir($dir) || @mkdir($dir, $perm);
\r
8 // *************************VALIDATE FILE EXTENSIONS**********************************
\r
9 function validateExtension($extension, $types) {
\r
10 if(in_array($extension,$types)) return false; else return true;
\r
13 //*************************************Display Alert Notifications*********************************
\r
14 function alert(&$notify){
\r
15 $alert_num = count($notify['type']);
\r
16 for($i=0;$i<$alert_num;$i++)
\r
18 ?><div class="alert<?php echo $notify['type'][$i]; ?>"><?php echo $notify['message'][$i]; ?></div><br /><?php
\r
22 // *************************SORT FILE ARRAY BY SELECTED ORDER**********************************
\r
23 function sortfileorder(&$sortbynow,&$sortorder,&$file) {
\r
28 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
31 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
34 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
37 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
40 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
47 // **************************RESIZE IMAGE TO GIVEN SIZE*****************************************
\r
48 function resizeimage($im,$maxwidth,$maxheight,$urlandname,$comp,$imagetype){
\r
49 $width = imagesx($im);
\r
50 $height = imagesy($im);
\r
51 if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight))
\r
53 if($maxwidth && $width > $maxwidth)
\r
55 $widthratio = $maxwidth/$width;
\r
58 else $resizewidth=false;
\r
60 if($maxheight && $height > $maxheight)
\r
62 $heightratio = $maxheight/$height;
\r
65 else $resizeheight=false;
\r
67 if($resizewidth && $resizeheight)
\r
69 if($widthratio < $heightratio) $ratio = $widthratio;
\r
70 else $ratio = $heightratio;
\r
72 elseif($resizewidth)
\r
74 $ratio = $widthratio;
\r
76 elseif($resizeheight)
\r
78 $ratio = $heightratio;
\r
80 $newwidth = $width * $ratio;
\r
81 $newheight = $height * $ratio;
\r
82 if(function_exists('imagecopyresampled') && $imagetype !='image/gif')
\r
84 $newim = imagecreatetruecolor($newwidth, $newheight);
\r
88 $newim = imagecreate($newwidth, $newheight);
\r
91 // additional processing for png / gif transparencies (credit to Dirk Bohl)
\r
92 if($imagetype == 'image/x-png' || $imagetype == 'image/png')
\r
94 imagealphablending($newim, false);
\r
95 imagesavealpha($newim, true);
\r
97 elseif($imagetype == 'image/gif')
\r
99 $originaltransparentcolor = imagecolortransparent( $im );
\r
100 if($originaltransparentcolor >= 0 && $originaltransparentcolor < imagecolorstotal( $im ))
\r
102 $transparentcolor = imagecolorsforindex( $im, $originaltransparentcolor );
\r
103 $newtransparentcolor = imagecolorallocate($newim,$transparentcolor['red'],$transparentcolor['green'],$transparentcolor['blue']);
\r
104 imagefill( $newim, 0, 0, $newtransparentcolor );
\r
105 imagecolortransparent( $newim, $newtransparentcolor );
\r
109 imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
\r
111 if($imagetype == 'image/pjpeg' || $imagetype == 'image/jpeg')
\r
113 imagejpeg ($newim,$urlandname,$comp);
\r
115 elseif($imagetype == 'image/x-png' || $imagetype == 'image/png')
\r
117 imagepng ($newim,$urlandname,substr($comp,0,1));
\r
119 elseif($imagetype == 'image/gif')
\r
121 imagegif ($newim,$urlandname);
\r
123 imagedestroy ($newim);
\r
127 if($imagetype == 'image/pjpeg' || $imagetype == 'image/jpeg')
\r
129 imagejpeg ($im,$urlandname,$comp);
\r
131 elseif($imagetype == 'image/x-png' || $imagetype == 'image/png')
\r
133 imagepng ($im,$urlandname,substr($comp,0,1));
\r
135 elseif($imagetype == 'image/gif')
\r
137 imagegif ($im,$urlandname);
\r
142 // **************************CHECK IMAGE TYPE AND CONVERT TO TEMP TYPE*****************************
\r
143 function convert_image($imagetemp,$imagetype){
\r
145 if($imagetype == 'image/pjpeg' || $imagetype == 'image/jpeg')
\r
147 $cim1 = imagecreatefromjpeg($imagetemp);
\r
149 elseif($imagetype == 'image/x-png' || $imagetype == 'image/png')
\r
151 $cim1 = imagecreatefrompng($imagetemp);
\r
152 imagealphablending($cim1, false);
\r
153 imagesavealpha($cim1, true);
\r
155 elseif($imagetype == 'image/gif')
\r
157 $cim1 = imagecreatefromgif($imagetemp);
\r
162 // **************************GENERATE FORM OPEN*****************************
\r
163 function form_open($name,$class,$url,$parameters){
\r
164 ?><form name="<?php echo $name; ?>" class="<?php echo $class; ?>" method="post" action="<?php echo $url.$parameters; ?>">
\r
168 // **************************GENERATE FORM SELECT ELEMENT*****************************
\r
169 function form_select($options,$name,$label,$current,$auto){
\r
170 if ($label) {?><label for="<?php echo $name; ?>"><?php echo $label; ?></label><?php }
\r
171 ?><select name="<?php echo $name; ?>" <?php if ($auto) {?>onchange="this.form.submit();"<?php }?>>
\r
173 $loopnum = count($options);
\r
174 for($i=0;$i<$loopnum;$i++)
\r
176 $selected = ($options[$i][0] == $current ? ' selected' : '');
\r
177 echo '<option value="'.$options[$i][0].'"'.$selected.'>'.$options[$i][1].'</option>';
\r
182 // **************************GENERATE FORM HIDDEN ELEMENT*****************************
\r
183 function form_hidden_input($name,$value) {
\r
184 ?><input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>" />
\r
188 // **************************GENERATE FORM TEXT ELEMENT*****************************
\r
189 function form_text_input($name,$label,$value,$size,$maxlength) {
\r
190 if ($label) {?><label for="<?php echo $name; ?>"><?php echo $label; ?></label><?php } ?>
\r
191 <input type="text" name="<?php echo $name; ?>" size="<?php echo $size; ?>" maxlength="<?php echo $maxlength; ?>" value="<?php echo $value; ?>" /><?php
\r
194 // **************************GENERATE FORM SUBMIT BUTTON*****************************
\r
195 function form_submit_button($name,$label,$class) {
\r
196 ?><button <?php if ($class) {?>class="<?php echo $class; ?>"<?php } ?>type="submit" name="<?php echo $name; ?>"><?php echo $label; ?></button>
\r
201 //********************************Returns True if Number is Odd**************************************
\r
202 function IsOdd($num)
\r
204 return (1 - ($num & 1));
\r
207 //********************************Truncate Text to Given Length If Required***************************
\r
208 function truncate_text($textstring,$length){
\r
209 if (strlen($textstring) > $length)
\r
211 $textstring = substr($textstring,0,$length).'...';
\r
213 return $textstring;
\r
217 * Present a size (in bytes) as a human-readable value
\r
219 * @param int $size size (in bytes)
\r
220 * @param int $precision number of digits after the decimal point
\r
223 function bytestostring($size, $precision = 0) {
\r
224 $sizes = array('YB', 'ZB', 'EB', 'PB', 'TB', 'GB', 'MB', 'KB', 'B');
\r
225 $total = count($sizes);
\r
227 while($total-- && $size > 1024) $size /= 1024;
\r
228 return round($size, $precision).' '.$sizes[$total];
\r
231 //function to clean a filename string so it is a valid filename
\r
232 function clean_filename($filename){
\r
233 $filename = preg_replace('/^\W+|\W+$/', '', $filename); // remove all non-alphanumeric chars at begin & end of string
\r
234 $filename = preg_replace('/\s+/', '_', $filename); // compress internal whitespace and replace with _
\r
235 return strtolower(preg_replace('/\W-/', '', $filename)); // remove all non-alphanumeric chars except _ and -
\r
239 //********************************Return File MIME Type***************************
\r
240 function returnMIMEType($filename)
\r
242 preg_match("|\.([a-z0-9]{2,4})$|i", $filename, $fileSuffix);
\r
244 switch(strtolower($fileSuffix[1]))
\r
247 return 'application/x-javascript';
\r
250 return 'application/json';
\r
255 return 'image/jpg';
\r
261 return 'image/'.strtolower($fileSuffix[1]);
\r
267 return 'application/xml';
\r
271 return 'application/msword';
\r
281 return 'application/vnd.ms-excel';
\r
285 return 'application/vnd.ms-powerpoint';
\r
288 return 'application/rtf';
\r
291 return 'application/pdf';
\r
296 return 'text/html';
\r
299 return 'text/plain';
\r
304 return 'video/mpeg';
\r
307 return 'audio/mpeg3';
\r
310 return 'audio/wav';
\r
314 return 'audio/aiff';
\r
317 return 'video/msvideo';
\r
320 return 'video/x-ms-wmv';
\r
323 return 'video/quicktime';
\r
326 return 'application/zip';
\r
329 return 'application/x-tar';
\r
332 return 'application/x-shockwave-flash';
\r
335 if(function_exists('mime_content_type'))
\r
337 $fileSuffix = mime_content_type($filename);
\r
340 return 'unknown/' . trim($fileSuffix[0], '.');
\r
344 //************************Return Array of Directory Structure***************************
\r
345 function dirtree(&$alldirs,$types='*.*',$root='',$tree='',$branch='',$level=0) {
\r
347 // filter file types according to type
\r
348 $filetypes = explode(',',preg_replace('{[ \t]+}', '',$types));
\r
350 if($level==0 && is_dir($root.$tree.$branch))
\r
353 foreach($filetypes as $filetype)
\r
355 $filenum = $filenum + count(glob($root.$tree.$branch.sql_regcase($filetype),GLOB_NOSORT));
\r
357 $treeparts = explode('/',rtrim($tree,'/'));
\r
358 $topname = end($treeparts);
\r
359 $alldirs[] = array($branch,rtrim($topname,'/').' ('.$filenum.')',rtrim($topname,'/'),rtrim($topname,'/'),$filenum,filemtime($root.$tree.$branch));
\r
363 $dh = opendir($root.$tree.$branch);
\r
364 while (($dirname = readdir($dh)) !== false)
\r
366 if($dirname != '.' && $dirname != '..' && is_dir($root.$tree.$branch.$dirname) && $dirname != '_thumbs')
\r
369 foreach($filetypes as $filetype)
\r
371 $filenum = $filenum + count(glob($root.$tree.$branch.$dirname.'/'.sql_regcase($filetype),GLOB_NOSORT));
\r
374 for($i=0;$i<$level;$i++) { $indent .= ' '; }
\r
375 if(strlen($indent)>0) $indent .= '→ ';
\r
376 $alldirs[] = array(urlencode($branch.$dirname.'/'),$indent.$dirname.' ('.$filenum.')',$indent.$dirname,$dirname,$filenum,filemtime($root.$tree.$branch.$dirname));
\r
377 dirtree($alldirs,$types,$root,$tree,$branch.$dirname.'/',$level);
\r
384 /* user defined error handling function. */
\r
385 function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
\r
387 // timestamp for the error entry.
\r
388 $dt = date('Y-m-d H:i:s (T)');
\r
390 // define an assoc array of error string
\r
391 // in reality the only entries we should
\r
392 // consider are E_WARNING, E_NOTICE, E_USER_ERROR,
\r
393 // E_USER_WARNING and E_USER_NOTICE.
\r
394 $errortype = array (
\r
395 E_ERROR => 'Error',
\r
396 E_WARNING => 'Warning',
\r
397 E_PARSE => 'Parsing Error',
\r
398 E_NOTICE => 'Notice',
\r
399 E_CORE_ERROR => 'Core Error',
\r
400 E_CORE_WARNING => 'Core Warning',
\r
401 E_COMPILE_ERROR => 'Compile Error',
\r
402 E_COMPILE_WARNING => 'Compile Warning',
\r
403 E_USER_ERROR => 'User Error',
\r
404 E_USER_WARNING => 'User Warning',
\r
405 E_USER_NOTICE => 'User Notice',
\r
406 E_STRICT => 'Runtime Notice'
\r
408 // set of errors for which a var trace will be saved.
\r
409 $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
\r
411 if($errno != E_STRICT) // exclude Runtime Notices
\r
414 $err .= $errno.' '.$errortype[$errno]. "\t";
\r
415 $err .= $errmsg. "\t";
\r
416 $err .= 'File: '.basename($filename). "\t";
\r
417 $err .= 'Line: '.$linenum. "\t";
\r
419 if (in_array($errno, $user_errors))
\r
421 $err .= 'Trace: '.wddx_serialize_value($vars, 'Variables'). "\t";
\r
425 // save to the error log file, and e-mail me if there is a critical user error.
\r
426 error_log($err, 3, 'error.log');
\r
429 $old_error_handler = set_error_handler('userErrorHandler');
\r