File manager - Edit - /home/autoph/public_html/connectv1/lms/app/controllers/utility.php
Back
<?php class Utility{ function debug(){ echo "Hello Wotrld"; } function generate_uuid($db){ return $db -> select("SELECT UUID_SHORT()"); } function isValidEmail($email){ return (filter_var($email, FILTER_VALIDATE_EMAIL)); } function isPostMethod($request){ if ($request != "POST") { return false; } return true; } function isJson($string) { json_decode($string); return json_last_error() === JSON_ERROR_NONE; } function getGenderID($gender){ $gender = strtolower($gender); $gender_id = "0"; if($this->isNotEmpty($gender)){ if(substr($gender,0,1) == "m" ){ $gender_id = "1"; }else if(substr($gender,0,1) == "f" ){ $gender_id = "2"; } } return $gender_id; } function isGetMethod($request){ if ($request != "GET") { return false; } return true; } function implodeQoutation(array $data){ if(count($data) <= 0){ return ''; } return implode(",",array_map(array($this, 'quoteString'), $data)); } function quoteString($string) { return sprintf("'%s'", $string); } function time_elapsed_string($datetime, $full = false) { $now = new DateTime; $ago = new DateTime($datetime); $diff = $now->diff($ago); $diff->w = floor($diff->d / 7); $diff->d -= $diff->w * 7; $string = array( 'y' => 'year', 'm' => 'month', 'w' => 'week', 'd' => 'day', 'h' => 'hour', 'i' => 'minute', 's' => 'second', ); foreach ($string as $k => &$v) { if ($diff->$k) { $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : ''); } else { unset($string[$k]); } } if (!$full) $string = array_slice($string, 0, 1); return $string ? implode(', ', $string) . '' : 'just now'; } function toArrayInt($array_data){ $array_data = array_map( function($value) { return (int)$value; }, $array_data ); return $array_data; } function isNotEmpty($data){ return preg_match('/\S/', $data); } function convert_sql_date($data,$current_format){ if($current_format == 'mm/dd/yyyy'){ $parts = explode('/',$data); $yyyy_mm_dd = $parts[2] . '-' . $parts[0] . '-' . $parts[1]; return $yyyy_mm_dd; }else if($current_format == 'dd/mm/yyyy'){ $date = str_replace('/', '-', $data); return date('Y-m-d', strtotime($date)); }else{ return ""; } } function alphaNumericOnly($s){ return preg_replace("/[^a-zA-Z0-9]+/", "", $s); } function fix_date($data,$format,$utility){ if($utility->isNotEmpty($data)){ $fix_date = ""; if(count(explode("/",$data)) == 3){ $fix_date = $data; }else{ if($utility->isNotEmpty(strtotime($data))){ $fix_date = date("m/d/Y",strtotime($data)); //aha word date } } if($utility->isNotEmpty($fix_date)){ // 01/23/2020 false // 23/01/2020 true $array_date = explode("/",explode(" ",$fix_date)[0]); if($format){ //if format == true swap index 0 and 1 $return_date = $array_date[2].'-'.$array_date[1].'-'.$array_date[0]; }else{ $return_date = $array_date[2].'-'.$array_date[0].'-'.$array_date[1]; } $return_date = date("Y-m-d", strtotime($return_date)); if($this->validateDate($return_date)){ return $return_date; } } } return ""; } function upperCaseNestedArray($value) { if (is_array($value)) { return array_map(array($this, 'upperCaseNestedArray'), $value); } return trim(mb_strtoupper($value)); } // function removeEmptyValueArray($value) { // if (is_array($value)) { // return array_map(array($this, 'removeEmptyValueArray'), $value); // } // if($this->isNotEmpty()){ // } // return trim(strtoupper($value)); // } function lowerCaseNestedArray($value) { if (is_array($value)) { return array_map(array($this, 'lowerCaseNestedArray'), $value); } return trim(strtolower($value)); } function convert_sql_date_to_date_picker($value) { if(trim($value) == ''){ return ''; } return date("m/d/Y", strtotime($value)); } function convert_sql_time_to_time_picker($value) { if(trim($value) == ''){ return ''; } return date("H:i a", strtotime($value)); } function fix_mobile_format($data){ if(strlen($data) < 5){ return ""; } $final_data = ""; //if area code equal to 639xx it will change to 09xxxxxxxxx if(substr($data,0,2) === "09"){ $final_data = "+639".substr($data,2,strlen($data)); }else if(substr($data,0,3) === "639"){ $final_data = "+639".substr($data,3,strlen($data)); }else if(substr($data,0,1) === "9" && strlen($data) == 10){ $final_data = "+639".substr($data,1,strlen($data)); }else{ $final_data = $data; } //if number start with 09xxx, check the length, if length is not 11 return blank, if not 09xxx return it if(substr($final_data,0,4) === "+639"){ if(strlen($final_data) == 13){ return $final_data; }else{ return (strlen($final_data) > 13) ? substr($final_data,0,13) : $final_data ; } } return $final_data; } function remove_non_numeric($data){ return preg_replace("/[^0-9]/","",$data); } function cleanStr($string) { $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens. return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars. } function mask($str, $first, $last) { $str = $this->cleanStr($str); $len = strlen($str); $toShow = $first + $last; return substr($str, 0, $len <= $toShow ? 0 : $first).str_repeat("*", $len - ($len <= $toShow ? 0 : $toShow)).substr($str, $len - $last, $len <= $toShow ? 0 : $last); } function mask_email($email) { if(!$this->isNotEmpty($email)){ return ""; } $mail_parts = explode("@", $email); $domain_parts = explode('.', $mail_parts[1]); $mail_parts[0] = $this->mask($mail_parts[0], 2, 1); // show first 2 letters and last 1 letter $mail_parts[1] = implode('.', $domain_parts); return implode("@", $mail_parts); } function make_thumb($src, $dest, $desired_width) { /* read the source image */ $imgInfo = getimagesize($src); $mime = $imgInfo['mime']; // Create a new image from file switch($mime){ case 'image/jpeg': $source_image = imagecreatefromjpeg($src); break; case 'image/png': $source_image = imagecreatefrompng($src); break; case 'image/gif': $source_image = imagecreatefromgif($src); break; default: $source_image = imagecreatefromjpeg($src); } $width = imagesx($source_image); $height = imagesy($source_image); /* find the "desired height" of this thumbnail, relative to the desired width */ $desired_height = floor($height * ($desired_width / $width)); /* create a new, "virtual" image */ $virtual_image = imagecreatetruecolor($desired_width, $desired_height); /* copy source image at a resized size */ imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height); /* create the physical thumbnail image to its destination */ switch($mime){ case 'image/jpeg': imagejpeg($virtual_image, $dest); break; case 'image/png': imagepng($virtual_image, $dest); break; case 'image/gif': imagegif($virtual_image, $dest); break; default: imagejpeg($virtual_image, $dest); } } function curl_me($url,$params,$method){ $method = strtoupper($method); $ch = curl_init(); switch($method){ case 'POST': curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($params)); break; case 'GET': break; default: curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($params)); } curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = curl_exec($ch); curl_close ($ch); return $server_output; } function validateDate($date, $format = 'Y-m-d') { $d = DateTime::createFromFormat($format, $date); // The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue. return $d && $d->format($format) === $date; } function toSqlDate($date){ if($this -> isNotEmpty($date)){ $date_formatted = DateTime::createFromFormat('m/d/Y', $date); return $date_formatted->format('Y-m-d'); } return ''; } function toSqlTime($time){ if($this -> isNotEmpty($time)){ $time_formatted = DateTime::createFromFormat('h:i A', $time); return $time_formatted->format('H:i:s'); } return ''; } function toSqlDateTime($date_time){ if($this -> isNotEmpty($date_time)){ $time_formatted = DateTime::createFromFormat('m/d/Y h:i A', $date_time); return $time_formatted->format('Y-m-d H:i:s'); } return ''; } function stringStartsWith($haystack,$needle,$case=true) { if ($case){ return strpos($haystack, $needle, 0) === 0; } return stripos($haystack, $needle, 0) === 0; } function stringEndsWith($haystack,$needle,$case=true) { $expectedPosition = strlen($haystack) - strlen($needle); if ($case){ return strrpos($haystack, $needle, 0) === $expectedPosition; } return strripos($haystack, $needle, 0) === $expectedPosition; } } ?>
| ver. 1.4 |
.
| PHP 7.3.33 | Generation time: 0 |
proxy
|
phpinfo
|
Settings