function.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 imageResize($image,$w,$h){
  53. $resource = imagecreatefromstring(file_get_contents($image));
  54. $size = getimagesize($image);
  55. $h = (($size[1] * (($w)/$size[0])));
  56. $thumbnail = imagecreatetruecolor($w , $h);
  57. imagecopyresampled($thumbnail ,$resource, 0,0, 0,0, $w, $h, $size[0],$size[1]);
  58. imagedestroy($resource);
  59. imagejpeg($thumbnail , $image, 100);
  60. }
  61. ?>