PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/system/application/views/admin/static/js/tiny_mce/plugins/tinybrowser/fns_tinybrowser.php

https://github.com/ibnoe/Microweber
PHP | 432 lines | 340 code | 58 blank | 34 comment | 77 complexity | d1da184c1ddd617439692eb35024f887 MD5 | raw file
  1. <?php
  2. // *************************CREATE FOLDER**********************************
  3. function createfolder($dir,$perm) {
  4. is_dir(dirname($dir)) || createfolder(dirname($dir), $perm);
  5. return is_dir($dir) || @mkdir($dir, $perm);
  6. }
  7. // *************************VALIDATE FILE EXTENSIONS**********************************
  8. function validateExtension($extension, $types) {
  9. if(in_array($extension,$types)) return false; else return true;
  10. }
  11. //*************************************Display Alert Notifications*********************************
  12. function alert(&$notify){
  13. $alert_num = count($notify['type']);
  14. for($i=0;$i<$alert_num;$i++)
  15. {
  16. ?><div class="alert<?php echo $notify['type'][$i]; ?>"><?php echo $notify['message'][$i]; ?></div><br /><?php
  17. }
  18. }
  19. // *************************SORT FILE ARRAY BY SELECTED ORDER**********************************
  20. function sortfileorder(&$sortbynow,&$sortorder,&$file) {
  21. switch($sortbynow)
  22. {
  23. case 'name':
  24. 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);
  25. break;
  26. case 'size':
  27. 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);
  28. break;
  29. case 'type':
  30. 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);
  31. break;
  32. case 'modified':
  33. 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);
  34. break;
  35. case 'dimensions':
  36. 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);
  37. break;
  38. default:
  39. // do nothing
  40. }
  41. }
  42. // **************************RESIZE IMAGE TO GIVEN SIZE*****************************************
  43. function resizeimage($im,$maxwidth,$maxheight,$urlandname,$comp,$imagetype){
  44. $width = imagesx($im);
  45. $height = imagesy($im);
  46. if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight))
  47. {
  48. if($maxwidth && $width > $maxwidth)
  49. {
  50. $widthratio = $maxwidth/$width;
  51. $resizewidth=true;
  52. }
  53. else $resizewidth=false;
  54. if($maxheight && $height > $maxheight)
  55. {
  56. $heightratio = $maxheight/$height;
  57. $resizeheight=true;
  58. }
  59. else $resizeheight=false;
  60. if($resizewidth && $resizeheight)
  61. {
  62. if($widthratio < $heightratio) $ratio = $widthratio;
  63. else $ratio = $heightratio;
  64. }
  65. elseif($resizewidth)
  66. {
  67. $ratio = $widthratio;
  68. }
  69. elseif($resizeheight)
  70. {
  71. $ratio = $heightratio;
  72. }
  73. $newwidth = $width * $ratio;
  74. $newheight = $height * $ratio;
  75. if(function_exists('imagecopyresampled') && $imagetype !='image/gif')
  76. {
  77. $newim = imagecreatetruecolor($newwidth, $newheight);
  78. }
  79. else
  80. {
  81. $newim = imagecreate($newwidth, $newheight);
  82. }
  83. // additional processing for png / gif transparencies (credit to Dirk Bohl)
  84. if($imagetype == 'image/x-png' || $imagetype == 'image/png')
  85. {
  86. imagealphablending($newim, false);
  87. imagesavealpha($newim, true);
  88. }
  89. elseif($imagetype == 'image/gif')
  90. {
  91. $originaltransparentcolor = imagecolortransparent( $im );
  92. if($originaltransparentcolor >= 0 && $originaltransparentcolor < imagecolorstotal( $im ))
  93. {
  94. $transparentcolor = imagecolorsforindex( $im, $originaltransparentcolor );
  95. $newtransparentcolor = imagecolorallocate($newim,$transparentcolor['red'],$transparentcolor['green'],$transparentcolor['blue']);
  96. imagefill( $newim, 0, 0, $newtransparentcolor );
  97. imagecolortransparent( $newim, $newtransparentcolor );
  98. }
  99. }
  100. imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  101. if($imagetype == 'image/pjpeg' || $imagetype == 'image/jpeg')
  102. {
  103. imagejpeg ($newim,$urlandname,$comp);
  104. }
  105. elseif($imagetype == 'image/x-png' || $imagetype == 'image/png')
  106. {
  107. imagepng ($newim,$urlandname,substr($comp,0,1));
  108. }
  109. elseif($imagetype == 'image/gif')
  110. {
  111. imagegif ($newim,$urlandname);
  112. }
  113. imagedestroy ($newim);
  114. }
  115. else
  116. {
  117. if($imagetype == 'image/pjpeg' || $imagetype == 'image/jpeg')
  118. {
  119. imagejpeg ($im,$urlandname,$comp);
  120. }
  121. elseif($imagetype == 'image/x-png' || $imagetype == 'image/png')
  122. {
  123. imagepng ($im,$urlandname,substr($comp,0,1));
  124. }
  125. elseif($imagetype == 'image/gif')
  126. {
  127. imagegif ($im,$urlandname);
  128. }
  129. }
  130. }
  131. // **************************CHECK IMAGE TYPE AND CONVERT TO TEMP TYPE*****************************
  132. function convert_image($imagetemp,$imagetype){
  133. if($imagetype == 'image/pjpeg' || $imagetype == 'image/jpeg')
  134. {
  135. $cim1 = imagecreatefromjpeg($imagetemp);
  136. }
  137. elseif($imagetype == 'image/x-png' || $imagetype == 'image/png')
  138. {
  139. $cim1 = imagecreatefrompng($imagetemp);
  140. imagealphablending($cim1, false);
  141. imagesavealpha($cim1, true);
  142. }
  143. elseif($imagetype == 'image/gif')
  144. {
  145. $cim1 = imagecreatefromgif($imagetemp);
  146. }
  147. return $cim1;
  148. }
  149. // **************************GENERATE FORM OPEN*****************************
  150. if (!function_exists('form_open')) {
  151. function form_open($name,$class,$url,$parameters){
  152. ?><form name="<?php echo $name; ?>" class="<?php echo $class; ?>" method="post" action="<?php echo $url.$parameters; ?>">
  153. <?php
  154. }
  155. }
  156. // **************************GENERATE FORM SELECT ELEMENT*****************************
  157. function form_select($options,$name,$label,$current,$auto){
  158. if ($label) {?><label for="<?php echo $name; ?>"><?php echo $label; ?></label><?php }
  159. ?><select name="<?php echo $name; ?>" <?php if ($auto) {?>onchange="this.form.submit();"<?php }?>>
  160. <?php
  161. $loopnum = count($options);
  162. for($i=0;$i<$loopnum;$i++)
  163. {
  164. $selected = ($options[$i][0] == $current ? ' selected' : '');
  165. echo '<option value="'.$options[$i][0].'"'.$selected.'>'.$options[$i][1].'</option>';
  166. }
  167. ?></select><?php
  168. }
  169. // **************************GENERATE FORM HIDDEN ELEMENT*****************************
  170. function form_hidden_input($name,$value) {
  171. ?><input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>" />
  172. <?php
  173. }
  174. // **************************GENERATE FORM TEXT ELEMENT*****************************
  175. function form_text_input($name,$label,$value,$size,$maxlength) {
  176. if ($label) {?><label for="<?php echo $name; ?>"><?php echo $label; ?></label><?php } ?>
  177. <input type="text" name="<?php echo $name; ?>" size="<?php echo $size; ?>" maxlength="<?php echo $maxlength; ?>" value="<?php echo $value; ?>" /><?php
  178. }
  179. // **************************GENERATE FORM SUBMIT BUTTON*****************************
  180. function form_submit_button($name,$label,$class) {
  181. ?><button <?php if ($class) {?>class="<?php echo $class; ?>"<?php } ?>type="submit" name="<?php echo $name; ?>"><?php echo $label; ?></button>
  182. </form>
  183. <?php
  184. }
  185. //********************************Returns True if Number is Odd**************************************
  186. function IsOdd($num)
  187. {
  188. return (1 - ($num & 1));
  189. }
  190. //********************************Truncate Text to Given Length If Required***************************
  191. function truncate_text($textstring,$length){
  192. if (strlen($textstring) > $length)
  193. {
  194. $textstring = substr($textstring,0,$length).'...';
  195. }
  196. return $textstring;
  197. }
  198. /**
  199. * Present a size (in bytes) as a human-readable value
  200. *
  201. * @param int $size size (in bytes)
  202. * @param int $precision number of digits after the decimal point
  203. * @return string
  204. */
  205. function bytestostring($size, $precision = 0) {
  206. $sizes = array('YB', 'ZB', 'EB', 'PB', 'TB', 'GB', 'MB', 'KB', 'B');
  207. $total = count($sizes);
  208. while($total-- && $size > 1024) $size /= 1024;
  209. return round($size, $precision).' '.$sizes[$total];
  210. }
  211. //function to clean a filename string so it is a valid filename
  212. function clean_filename($filename){
  213. $filename = preg_replace('/^\W+|\W+$/', '', $filename); // remove all non-alphanumeric chars at begin & end of string
  214. $filename = preg_replace('/\s+/', '_', $filename); // compress internal whitespace and replace with _
  215. return strtolower(preg_replace('/\W-/', '', $filename)); // remove all non-alphanumeric chars except _ and -
  216. }
  217. //********************************Return File MIME Type***************************
  218. function returnMIMEType($filename)
  219. {
  220. preg_match("|\.([a-z0-9]{2,4})$|i", $filename, $fileSuffix);
  221. switch(strtolower($fileSuffix[1]))
  222. {
  223. case 'js' :
  224. return 'application/x-javascript';
  225. case 'json' :
  226. return 'application/json';
  227. case 'jpg' :
  228. case 'jpeg' :
  229. case 'jpe' :
  230. return 'image/jpg';
  231. case 'png' :
  232. case 'gif' :
  233. case 'bmp' :
  234. case 'tiff' :
  235. return 'image/'.strtolower($fileSuffix[1]);
  236. case 'css' :
  237. return 'text/css';
  238. case 'xml' :
  239. return 'application/xml';
  240. case 'doc' :
  241. case 'docx' :
  242. return 'application/msword';
  243. case 'xls' :
  244. case 'xlt' :
  245. case 'xlm' :
  246. case 'xld' :
  247. case 'xla' :
  248. case 'xlc' :
  249. case 'xlw' :
  250. case 'xll' :
  251. return 'application/vnd.ms-excel';
  252. case 'ppt' :
  253. case 'pps' :
  254. return 'application/vnd.ms-powerpoint';
  255. case 'rtf' :
  256. return 'application/rtf';
  257. case 'pdf' :
  258. return 'application/pdf';
  259. case 'html' :
  260. case 'htm' :
  261. case 'php' :
  262. return 'text/html';
  263. case 'txt' :
  264. return 'text/plain';
  265. case 'mpeg' :
  266. case 'mpg' :
  267. case 'mpe' :
  268. return 'video/mpeg';
  269. case 'mp3' :
  270. return 'audio/mpeg3';
  271. case 'wav' :
  272. return 'audio/wav';
  273. case 'aiff' :
  274. case 'aif' :
  275. return 'audio/aiff';
  276. case 'avi' :
  277. return 'video/msvideo';
  278. case 'wmv' :
  279. return 'video/x-ms-wmv';
  280. case 'mov' :
  281. return 'video/quicktime';
  282. case 'zip' :
  283. return 'application/zip';
  284. case 'tar' :
  285. return 'application/x-tar';
  286. case 'swf' :
  287. return 'application/x-shockwave-flash';
  288. default :
  289. if(function_exists('mime_content_type'))
  290. {
  291. $fileSuffix = mime_content_type($filename);
  292. }
  293. return 'unknown/' . trim($fileSuffix[0], '.');
  294. }
  295. }
  296. //************************Return Array of Directory Structure***************************
  297. function dirtree(&$alldirs,$types='*.*',$root='',$tree='',$branch='',$level=0) {
  298. // filter file types according to type
  299. $filetypes = explode(',',preg_replace('{[ \t]+}', '',$types));
  300. if($level==0 && is_dir($root.$tree.$branch))
  301. {
  302. $filenum=0;
  303. foreach($filetypes as $filetype)
  304. {
  305. $filenum = $filenum + count(glob($root.$tree.$branch.sql_regcase($filetype),GLOB_NOSORT));
  306. }
  307. $treeparts = explode('/',rtrim($tree,'/'));
  308. $topname = end($treeparts);
  309. $alldirs[] = array($branch,rtrim($topname,'/').' ('.$filenum.')',rtrim($topname,'/'),rtrim($topname,'/'),$filenum,filemtime($root.$tree.$branch));
  310. }
  311. $level++;
  312. $dh = opendir($root.$tree.$branch);
  313. while (($dirname = readdir($dh)) !== false)
  314. {
  315. if($dirname != '.' && $dirname != '..' && is_dir($root.$tree.$branch.$dirname) && $dirname != '_thumbs')
  316. {
  317. $filenum=0;
  318. foreach($filetypes as $filetype)
  319. {
  320. $filenum = $filenum + count(glob($root.$tree.$branch.$dirname.'/'.sql_regcase($filetype),GLOB_NOSORT));
  321. }
  322. $indent = '';
  323. for($i=0;$i<$level;$i++) { $indent .= ' &nbsp; '; }
  324. if(strlen($indent)>0) $indent .= '&rarr; ';
  325. $alldirs[] = array(urlencode($branch.$dirname.'/'),$indent.$dirname.' ('.$filenum.')',$indent.$dirname,$dirname,$filenum,filemtime($root.$tree.$branch.$dirname));
  326. dirtree($alldirs,$types,$root,$tree,$branch.$dirname.'/',$level);
  327. }
  328. }
  329. closedir($dh);
  330. $level--;
  331. }
  332. /* user defined error handling function. */
  333. function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
  334. {
  335. // timestamp for the error entry.
  336. $dt = date('Y-m-d H:i:s (T)');
  337. // define an assoc array of error string
  338. // in reality the only entries we should
  339. // consider are E_WARNING, E_NOTICE, E_USER_ERROR,
  340. // E_USER_WARNING and E_USER_NOTICE.
  341. $errortype = array (
  342. E_ERROR => 'Error',
  343. E_WARNING => 'Warning',
  344. E_PARSE => 'Parsing Error',
  345. E_NOTICE => 'Notice',
  346. E_CORE_ERROR => 'Core Error',
  347. E_CORE_WARNING => 'Core Warning',
  348. E_COMPILE_ERROR => 'Compile Error',
  349. E_COMPILE_WARNING => 'Compile Warning',
  350. E_USER_ERROR => 'User Error',
  351. E_USER_WARNING => 'User Warning',
  352. E_USER_NOTICE => 'User Notice',
  353. E_STRICT => 'Runtime Notice'
  354. );
  355. // set of errors for which a var trace will be saved.
  356. $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
  357. if($errno != E_STRICT) // exclude Runtime Notices
  358. {
  359. $err = $dt. "\t";
  360. $err .= $errno.' '.$errortype[$errno]. "\t";
  361. $err .= $errmsg. "\t";
  362. $err .= 'File: '.basename($filename). "\t";
  363. $err .= 'Line: '.$linenum. "\t";
  364. if (in_array($errno, $user_errors))
  365. {
  366. $err .= 'Trace: '.wddx_serialize_value($vars, 'Variables'). "\t";
  367. }
  368. $err .= "\n";
  369. // save to the error log file, and e-mail me if there is a critical user error.
  370. error_log($err, 3, 'error.log');
  371. }
  372. }
  373. $old_error_handler = set_error_handler('userErrorHandler');
  374. ?>