function.php 3.8 KB

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