PageRenderTime 57ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/js/tiny_mce/plugins/tinybrowser/fns_tinybrowser.php

https://gitlab.com/ilya.webcity/anna
PHP | 431 lines | 338 code | 59 blank | 34 comment | 76 complexity | 32b60b6cf3cb98e274ec28bbd9be1ab8 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. function form_open($name,$class,$url,$parameters){
  151. ?><form name="<?php echo $name; ?>" class="<?php echo $class; ?>" method="post" action="<?php echo $url.$parameters; ?>">
  152. <?php
  153. }
  154. // **************************GENERATE FORM SELECT ELEMENT*****************************
  155. function form_select($options,$name,$label,$current,$auto){
  156. if ($label) {?><label for="<?php echo $name; ?>"><?php echo $label; ?></label><?php }
  157. ?><select name="<?php echo $name; ?>" <?php if ($auto) {?>onchange="this.form.submit();"<?php }?>>
  158. <?php
  159. $loopnum = count($options);
  160. for($i=0;$i<$loopnum;$i++)
  161. {
  162. $selected = ($options[$i][0] == $current ? ' selected' : '');
  163. echo '<option value="'.$options[$i][0].'"'.$selected.'>'.$options[$i][1].'</option>';
  164. }
  165. ?></select><?php
  166. }
  167. // **************************GENERATE FORM HIDDEN ELEMENT*****************************
  168. function form_hidden_input($name,$value) {
  169. ?><input type="hidden" name="<?php echo $name; ?>" value="<?php echo $value; ?>" />
  170. <?php
  171. }
  172. // **************************GENERATE FORM TEXT ELEMENT*****************************
  173. function form_text_input($name,$label,$value,$size,$maxlength) {
  174. if ($label) {?><label for="<?php echo $name; ?>"><?php echo $label; ?></label><?php } ?>
  175. <input type="text" name="<?php echo $name; ?>" size="<?php echo $size; ?>" maxlength="<?php echo $maxlength; ?>" value="<?php echo $value; ?>" /><?php
  176. }
  177. // **************************GENERATE FORM SUBMIT BUTTON*****************************
  178. function form_submit_button($name,$label,$class) {
  179. ?><button <?php if ($class) {?>class="<?php echo $class; ?>"<?php } ?>type="submit" name="<?php echo $name; ?>"><?php echo $label; ?></button>
  180. </form>
  181. <?php
  182. }
  183. //********************************Returns True if Number is Odd**************************************
  184. function IsOdd($num)
  185. {
  186. return (1 - ($num & 1));
  187. }
  188. //********************************Truncate Text to Given Length If Required***************************
  189. function truncate_text($textstring,$length){
  190. if (strlen($textstring) > $length)
  191. {
  192. $textstring = substr($textstring,0,$length).'...';
  193. }
  194. return $textstring;
  195. }
  196. /**
  197. * Present a size (in bytes) as a human-readable value
  198. *
  199. * @param int $size size (in bytes)
  200. * @param int $precision number of digits after the decimal point
  201. * @return string
  202. */
  203. function bytestostring($size, $precision = 0) {
  204. $sizes = array('YB', 'ZB', 'EB', 'PB', 'TB', 'GB', 'MB', 'KB', 'B');
  205. $total = count($sizes);
  206. while($total-- && $size > 1024) $size /= 1024;
  207. return round($size, $precision).' '.$sizes[$total];
  208. }
  209. //function to clean a filename string so it is a valid filename
  210. function clean_filename($filename){
  211. $filename = preg_replace('/^\W+|\W+$/', '', $filename); // remove all non-alphanumeric chars at begin & end of string
  212. $filename = preg_replace('/\s+/', '_', $filename); // compress internal whitespace and replace with _
  213. return strtolower(preg_replace('/\W-/', '', $filename)); // remove all non-alphanumeric chars except _ and -
  214. }
  215. //********************************Return File MIME Type***************************
  216. function returnMIMEType($filename)
  217. {
  218. preg_match("|\.([a-z0-9]{2,4})$|i", $filename, $fileSuffix);
  219. switch(strtolower($fileSuffix[1]))
  220. {
  221. case 'js' :
  222. return 'application/x-javascript';
  223. case 'json' :
  224. return 'application/json';
  225. case 'jpg' :
  226. case 'jpeg' :
  227. case 'jpe' :
  228. return 'image/jpg';
  229. case 'png' :
  230. case 'gif' :
  231. case 'bmp' :
  232. case 'tiff' :
  233. return 'image/'.strtolower($fileSuffix[1]);
  234. case 'css' :
  235. return 'text/css';
  236. case 'xml' :
  237. return 'application/xml';
  238. case 'doc' :
  239. case 'docx' :
  240. return 'application/msword';
  241. case 'xls' :
  242. case 'xlt' :
  243. case 'xlm' :
  244. case 'xld' :
  245. case 'xla' :
  246. case 'xlc' :
  247. case 'xlw' :
  248. case 'xll' :
  249. return 'application/vnd.ms-excel';
  250. case 'ppt' :
  251. case 'pps' :
  252. return 'application/vnd.ms-powerpoint';
  253. case 'rtf' :
  254. return 'application/rtf';
  255. case 'pdf' :
  256. return 'application/pdf';
  257. case 'html' :
  258. case 'htm' :
  259. case 'php' :
  260. return 'text/html';
  261. case 'txt' :
  262. return 'text/plain';
  263. case 'mpeg' :
  264. case 'mpg' :
  265. case 'mpe' :
  266. return 'video/mpeg';
  267. case 'mp3' :
  268. return 'audio/mpeg3';
  269. case 'wav' :
  270. return 'audio/wav';
  271. case 'aiff' :
  272. case 'aif' :
  273. return 'audio/aiff';
  274. case 'avi' :
  275. return 'video/msvideo';
  276. case 'wmv' :
  277. return 'video/x-ms-wmv';
  278. case 'mov' :
  279. return 'video/quicktime';
  280. case 'zip' :
  281. return 'application/zip';
  282. case 'tar' :
  283. return 'application/x-tar';
  284. case 'swf' :
  285. return 'application/x-shockwave-flash';
  286. default :
  287. if(function_exists('mime_content_type'))
  288. {
  289. $fileSuffix = mime_content_type($filename);
  290. }
  291. return 'unknown/' . trim($fileSuffix[0], '.');
  292. }
  293. }
  294. //************************Return Array of Directory Structure***************************
  295. function dirtree(&$alldirs,$types='*.*',$root='',$tree='',$branch='',$level=0) {
  296. // filter file types according to type
  297. $filetypes = explode(',',preg_replace('{[ \t]+}', '',$types));
  298. if($level==0 && is_dir($root.$tree.$branch))
  299. {
  300. $filenum=0;
  301. foreach($filetypes as $filetype)
  302. {
  303. $filenum = $filenum + count(glob($root.$tree.$branch.sql_regcase($filetype),GLOB_NOSORT));
  304. }
  305. $treeparts = explode('/',rtrim($tree,'/'));
  306. $topname = end($treeparts);
  307. $alldirs[] = array($branch,rtrim($topname,'/').' ('.$filenum.')',rtrim($topname,'/'),rtrim($topname,'/'),$filenum,filemtime($root.$tree.$branch));
  308. }
  309. $level++;
  310. $dh = opendir($root.$tree.$branch);
  311. while (($dirname = readdir($dh)) !== false)
  312. {
  313. if($dirname != '.' && $dirname != '..' && is_dir($root.$tree.$branch.$dirname) && $dirname != '_thumbs')
  314. {
  315. $filenum=0;
  316. foreach($filetypes as $filetype)
  317. {
  318. $filenum = $filenum + count(glob($root.$tree.$branch.$dirname.'/'.sql_regcase($filetype),GLOB_NOSORT));
  319. }
  320. $indent = '';
  321. for($i=0;$i<$level;$i++) { $indent .= ' &nbsp; '; }
  322. if(strlen($indent)>0) $indent .= '&rarr; ';
  323. $alldirs[] = array(urlencode($branch.$dirname.'/'),$indent.$dirname.' ('.$filenum.')',$indent.$dirname,$dirname,$filenum,filemtime($root.$tree.$branch.$dirname));
  324. dirtree($alldirs,$types,$root,$tree,$branch.$dirname.'/',$level);
  325. }
  326. }
  327. closedir($dh);
  328. $level--;
  329. }
  330. /* user defined error handling function. */
  331. function userErrorHandler($errno, $errmsg, $filename, $linenum, $vars)
  332. {
  333. // timestamp for the error entry.
  334. $dt = date('Y-m-d H:i:s (T)');
  335. // define an assoc array of error string
  336. // in reality the only entries we should
  337. // consider are E_WARNING, E_NOTICE, E_USER_ERROR,
  338. // E_USER_WARNING and E_USER_NOTICE.
  339. $errortype = array (
  340. E_ERROR => 'Error',
  341. E_WARNING => 'Warning',
  342. E_PARSE => 'Parsing Error',
  343. E_NOTICE => 'Notice',
  344. E_CORE_ERROR => 'Core Error',
  345. E_CORE_WARNING => 'Core Warning',
  346. E_COMPILE_ERROR => 'Compile Error',
  347. E_COMPILE_WARNING => 'Compile Warning',
  348. E_USER_ERROR => 'User Error',
  349. E_USER_WARNING => 'User Warning',
  350. E_USER_NOTICE => 'User Notice',
  351. E_STRICT => 'Runtime Notice'
  352. );
  353. // set of errors for which a var trace will be saved.
  354. $user_errors = array(E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE);
  355. if($errno != E_STRICT) // exclude Runtime Notices
  356. {
  357. $err = $dt. "\t";
  358. $err .= $errno.' '.$errortype[$errno]. "\t";
  359. $err .= $errmsg. "\t";
  360. $err .= 'File: '.basename($filename). "\t";
  361. $err .= 'Line: '.$linenum. "\t";
  362. if (in_array($errno, $user_errors))
  363. {
  364. $err .= 'Trace: '.wddx_serialize_value($vars, 'Variables'). "\t";
  365. }
  366. $err .= "\n";
  367. // save to the error log file, and e-mail me if there is a critical user error.
  368. error_log($err, 3, 'error.log');
  369. }
  370. }
  371. $old_error_handler = set_error_handler('userErrorHandler');
  372. ?>