function.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. function secondToTime($seconds) {
  3. $t = round($seconds);
  4. return sprintf('%02d:%02d:%02d', ($t/3600),($t/60%60), $t%60);
  5. }
  6. function app_autoloader($class_name) {
  7. require_once('class/'.$class_name.'.class.php');
  8. }
  9. function errorToException( $errno, $errstr, $errfile, $errline, $errcontext)
  10. {
  11. if(strpos($errstr,'disk_')!==false) return;
  12. throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
  13. }
  14. function slugify($text)
  15. {
  16. // replace non letter or digits by -
  17. $text = preg_replace('~[^\\pL\.\d]+~u', '-', $text);
  18. // trim
  19. $text = trim($text, '-');
  20. // transliterate
  21. $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
  22. // lowercase
  23. $text = strtolower($text);
  24. // remove unwanted characters
  25. $text = preg_replace('~[^-\.\w]+~', '', $text);
  26. if (empty($text))
  27. return 'n-a';
  28. return $text;
  29. }
  30. function secure_user_vars($var){
  31. if(is_array($var)){
  32. $array = array();
  33. foreach($var as $key=>$value):
  34. $array[secure_user_vars($key)] = secure_user_vars($value);
  35. endforeach;
  36. return $array;
  37. }else{
  38. return htmlspecialchars($var, ENT_NOQUOTES, "UTF-8");
  39. }
  40. }
  41. function base64_to_image($base64_string, $output_file) {
  42. $ifp = fopen($output_file, "wb");
  43. $data = explode(',', $base64_string);
  44. fwrite($ifp, base64_decode($data[1]));
  45. fclose($ifp);
  46. return $output_file;
  47. }
  48. function getExt($file){
  49. $ext = explode('.',$file);
  50. return strtolower(array_pop($ext));
  51. }
  52. function getExtIcon($ext){
  53. $icon = '';
  54. switch($ext){
  55. case '7z':
  56. case 'rar':
  57. case 'gz':
  58. case 'zip':
  59. $icon = 'fa-file-archive-o';
  60. break;
  61. case 'php':
  62. case 'js':
  63. case 'py':
  64. case 'c':
  65. case 'cpp':
  66. case 'css':
  67. case 'h':
  68. case 'hpp':
  69. case 'html':
  70. case 'htm':
  71. case 'asp':
  72. case 'jsp':
  73. $icon = 'fa-file-code-o';
  74. break;
  75. case 'xls':
  76. case 'xlsx':
  77. case 'csv':
  78. $icon = 'fa-file-excel-o';
  79. break;
  80. case 'bmp':
  81. case 'jpg':
  82. case 'jpeg':
  83. case 'ico':
  84. case 'gif':
  85. case 'png':
  86. case 'svg':
  87. $icon = 'fa-file-image-o';
  88. break;
  89. case 'pdf':
  90. $icon = 'fa-file-pdf-o';
  91. break;
  92. case 'ppt':
  93. case 'pptx':
  94. $icon = 'fa-file-powerpoint-o';
  95. break;
  96. case 'txt':
  97. case 'htaccess':
  98. case 'md':
  99. $icon = 'fa-file-text-o';
  100. break;
  101. case 'doc':
  102. case 'docx':
  103. case 'word':
  104. $icon = 'fa-file-word-o';
  105. break;
  106. case 'avi':
  107. case 'wmv':
  108. case 'mov':
  109. case 'divx':
  110. case 'xvid':
  111. case 'mkv':
  112. case 'flv':
  113. case 'mpeg':
  114. case 'h264':
  115. case 'rmvb':
  116. case 'mp4':
  117. $icon = 'fa-file-movie-o';
  118. break;
  119. case 'wav':
  120. case 'ogg':
  121. case 'ogv':
  122. case 'ogx':
  123. case 'oga':
  124. case 'riff':
  125. case 'bwf':
  126. case 'wma':
  127. case 'flac':
  128. case 'aac':
  129. case 'mp3':
  130. $icon = 'fa-file-audio-o';
  131. break;
  132. default:
  133. $icon = 'fa-file-o';
  134. break;
  135. }
  136. return $icon;
  137. };
  138. function imageResize($image,$w,$h){
  139. $resource = imagecreatefromstring(file_get_contents($image));
  140. $size = getimagesize($image);
  141. $h = (($size[1] * (($w)/$size[0])));
  142. $thumbnail = imagecreatetruecolor($w , $h);
  143. imagecopyresampled($thumbnail ,$resource, 0,0, 0,0, $w, $h, $size[0],$size[1]);
  144. imagedestroy($resource);
  145. imagejpeg($thumbnail , $image, 100);
  146. }
  147. ?>