���� JFIF �� � ( %"1"%)+...383,7(-.-
![]() Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.20 System : Linux st2.domain.com 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 User : apache ( 48) PHP Version : 7.4.20 Disable Function : NONE Directory : /var/www/html/api-truyentranh/includes/ |
<?php class FUNC { var $textcount = 0; function show_alert($text,$type='error'){ if($type=='error'){ $txt_alert = 'toastr.error(\''.$text.'\')'; }else{ $txt_alert = 'toastr.success(\''.$text.'\')'; } return '<script> $(function() { var Toast = Swal.mixin({ toast: true, position: \'top-end\', showConfirmButton: false, timer: 3000 }); '.$txt_alert.' }); </script>'; } function checkMonday($timestamp=''){ if($timestamp==''){ $timestamp=time(); } if(date('D', $timestamp) === 'Mon') { return 1; }else{ return 0; } } function yes_no ( $bool,$t_name ){ if ($bool == 1 ){ $result = "Yes <input type='radio' name='{$t_name}' value='1' checked> <input type='radio' name='{$t_name}' value='0'> No"; }else{ $result = "Yes <input type='radio' name='{$t_name}' value='1' id='green'> <input type='radio' name='{$t_name}' value='0' checked id='red'> No"; } return $result; } function makebox ( $bool,$t_name ){ if ($bool == 1 ){ $result = "<input type='checkbox' name='{$t_name}[]' value='1' checked>"; }else{ $result = "<input type='checkbox' name='{$t_name}[]' value='0'>"; } return $result; } //uncovert (decode html code to textarea ) function unconvert($txt="", $code=1, $html=0) { $txt = str_replace( "<br>" , "\n", $txt ); $txt = str_replace( "<br />", "\n", $txt ); return trim(stripslashes($txt)); } //end uncovert function load_lang($langfile) { global $langArray; if(!empty($langfile)){ require ROOT_PATH."lang/".$langfile.".php"; }else{ return; } if(!empty($lang)){ foreach ($lang as $k => $v) { $langArray[$k] = stripslashes(html_entity_decode($v)); } } unset($lang); return $langArray; } function get_input() { global $_GET, $_POST, $REQUEST_METHOD, $REMOTE_ADDR, $HTTP_PROXY_USER, $HTTP_X_FORWARDED_FOR; $return = array(); if( is_array($_GET) ) { foreach ($_GET as $k=>$v){ if ( $k == 'INFO' ) { continue; } $return[$k] = $this->clean_value($v); } } // Overwrite GET data with post data if( is_array($_POST) ) { foreach ($_POST as $k=>$v){ $return[$k] = $this->clean_value($v); } } //---------------------------------------- // Sort out the accessing IP // (Thanks to Cosmos and schickb) //---------------------------------------- $addrs = array(); // Handle $HTTP_X_FORWARDED_FOR as a potential multi-level array if (is_array($HTTP_X_FORWARDED_FOR)) { $http_x_forwarded = $this->clean_value($HTTP_X_FORWARDED_FOR); // After cleaning, convert to string if needed for processing $forwarded_str = is_array($http_x_forwarded) ? implode(',', $http_x_forwarded) : $http_x_forwarded; } else { $forwarded_str = $HTTP_X_FORWARDED_FOR; } foreach( array_reverse( explode( ',', $forwarded_str ) ) as $x_f ) { $x_f = trim($x_f); if ( preg_match( '/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/', $x_f ) ) { $addrs[] = $x_f; } } $addrs[] = $_SERVER['REMOTE_ADDR']; // Handle $HTTP_PROXY_USER as a potential multi-level array if (is_array($HTTP_PROXY_USER)) { $proxy_user = $this->clean_value($HTTP_PROXY_USER); // After cleaning, convert to string if needed $addrs[] = is_array($proxy_user) ? implode(',', $proxy_user) : $proxy_user; } else { $addrs[] = $HTTP_PROXY_USER; } // Handle $REMOTE_ADDR as a potential multi-level array if (is_array($REMOTE_ADDR)) { $remote_addr = $this->clean_value($REMOTE_ADDR); // After cleaning, convert to string if needed $addrs[] = is_array($remote_addr) ? implode(',', $remote_addr) : $remote_addr; } else { $addrs[] = $REMOTE_ADDR; } $return['IP_ADDRESS'] = $this->select_var( $addrs ); // Make sure we take a valid IP address $return['IP_ADDRESS'] = preg_replace( "/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/", "\\1.\\2.\\3.\\4", $return['IP_ADDRESS'] ); // Handle $REQUEST_METHOD as a potential multi-level array if (is_array($REQUEST_METHOD)) { $req_method = $this->clean_value($REQUEST_METHOD); // After cleaning, convert to string if needed $method_str = is_array($req_method) ? implode(',', $req_method) : $req_method; $return['request_method'] = ( $_SERVER['REQUEST_METHOD'] != "" ) ? strtolower($_SERVER['REQUEST_METHOD']) : strtolower($method_str); } else { $return['request_method'] = ( $_SERVER['REQUEST_METHOD'] != "" ) ? strtolower($_SERVER['REQUEST_METHOD']) : strtolower($REQUEST_METHOD); } return $return; } /*------------------------------------------------------------------------- */ // Key Cleaner - ensures no funny business with form elements /*------------------------------------------------------------------------- */ function clean_key($key) { if ($key == "") { return ""; } $key = preg_replace( "/\.\./" , "" , $key ); $key = preg_replace( "/\_\_(.+?)\_\_/" , "" , $key ); $key = preg_replace( "/^([\w\.\-\_]+)$/", "$1", $key ); return $key; } function clean_string($string){ $kytu_loaibo = array("?","&",",","/",".","!","@","#","$","%","//",":","\"","\\","'","$","^","(",")","\"","=","_","__"); $kytu_thaythe= array(" "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "," "); $xuat = str_replace($kytu_loaibo,$kytu_thaythe,$string); //$outstr = $this->clean_value($outstr); return $xuat; } function clean_nhaydon($string){ $kytu_loaibo = array("'"); $kytu_thaythe= array("``"); $xuat = str_replace($kytu_loaibo,$kytu_thaythe,$string); //$outstr = $this->clean_value($outstr); return $xuat; } function convert_vi_to_en($str) { $str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str); $str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str); $str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str); $str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str); $str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str); $str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str); $str = preg_replace("/(đ)/", 'd', $str); $str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str); $str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str); $str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str); $str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str); $str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str); $str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str); $str = preg_replace("/(Đ)/", 'D', $str); return $str; } function bodau_normal2($str) { $chuCoDau=array('à','á','ạ','ả','ã','â','ầ','ấ','ậ','ẩ','ẫ','ă', 'ằ','ắ','ặ','ẳ','ẵ','è','é','ẹ','ẻ','ẽ','ê','ề' ,'ế','ệ','ể','ễ', 'ì','í','ị','ỉ','ĩ', 'ò','ó','ọ','ỏ','õ','ô','ồ','ố','ộ','ổ','ỗ','ơ' ,'ờ','ớ','ợ','ở','ỡ', 'ù','ú','ụ','ủ','ũ','ư','ừ','ứ','ự','ử','ữ', 'ỳ','ý','ỵ','ỷ','ỹ', 'đ', 'À','Á','Ạ','Ả','Ã','Â','Ầ','Ấ','Ậ','Ẩ','Ẫ','Ă' ,'Ằ','Ắ','Ặ','Ẳ','Ẵ', 'È','É','Ẹ','Ẻ','Ẽ','Ê','Ề','Ế','Ệ','Ể','Ễ', 'Ì','Í','Ị','Ỉ','Ĩ', 'Ò','Ó','Ọ','Ỏ','Õ','Ô','Ồ','Ố','Ộ','Ổ','Ỗ','Ơ' ,'Ờ','Ớ','Ợ','Ở','Ỡ', 'Ù','Ú','Ụ','Ủ','Ũ','Ư','Ừ','Ứ','Ự','Ử','Ữ', 'Ỳ','Ý','Ỵ','Ỷ','Ỹ'); $chuKoDau=array('a','a','a','a','a','a','a','a','a','a','a' ,'a','a','a','a','a','a', 'e','e','e','e','e','e','e','e','e','e','e', 'i','i','i','i','i', 'o','o','o','o','o','o','o','o','o','o','o','o' ,'o','o','o','o','o', 'u','u','u','u','u','u','u','u','u','u','u', 'y','y','y','y','y', 'd', 'A','A','A','A','A','A','A','A','A','A','A','A' ,'A','A','A','A','A', 'E','E','E','E','E','E','E','E','E','E','E', 'I','I','I','I','I', 'O','O','O','O','O','O','O','O','O','O','O','O' ,'O','O','O','O','O', 'U','U','U','U','U','U','U','U','U','U','U', 'Y','Y','Y','Y','Y'); $outstr = str_replace($chuCoDau,$chuKoDau,$str); return $outstr; } function bodau_normal($str) { $chuCoDau=array("à","á","ạ","ả","ã","â","ầ","ấ","ậ","ẩ","ẫ","ă", "ằ","ắ","ặ","ẳ","ẵ","è","é","ẹ","ẻ","ẽ","ê","ề" ,"ế","ệ","ể","ễ", "ì","í","ị","ỉ","ĩ", "ò","ó","ọ","ỏ","õ","ô","ồ","ố","ộ","ổ","ỗ","ơ" ,"ờ","ớ","ợ","ở","ỡ", "ù","ú","ụ","ủ","ũ","ư","ừ","ứ","ự","ử","ữ", "ỳ","ý","ỵ","ỷ","ỹ", "đ", "À","Á","Ạ","Ả","Ã","Â","Ầ","Ấ","Ậ","Ẩ","Ẫ","Ă" ,"Ằ","Ắ","Ặ","Ẳ","Ẵ", "È","É","Ẹ","Ẻ","Ẽ","Ê","Ề","Ế","Ệ","Ể","Ễ", "Ì","Í","Ị","Ỉ","Ĩ", "Ò","Ó","Ọ","Ỏ","Õ","Ô","Ồ","Ố","Ộ","Ổ","Ỗ","Ơ" ,"Ờ","Ớ","Ợ","Ở","Ỡ", "Ù","Ú","Ụ","Ủ","Ũ","Ư","Ừ","Ứ","Ự","Ử","Ữ", "Ỳ","Ý","Ỵ","Ỷ","Ỹ"); $chuKoDau=array("a","a","a","a","a","a","a","a","a","a","a" ,"a","a","a","a","a","a", "e","e","e","e","e","e","e","e","e","e","e", "i","i","i","i","i", "o","o","o","o","o","o","o","o","o","o","o","o" ,"o","o","o","o","o", "u","u","u","u","u","u","u","u","u","u","u", "y","y","y","y","y", "d", "A","A","A","A","A","A","A","A","A","A","A","A" ,"A","A","A","A","A", "E","E","E","E","E","E","E","E","E","E","E", "I","I","I","I","I", "O","O","O","O","O","O","O","O","O","O","O","O" ,"O","O","O","O","O", "U","U","U","U","U","U","U","U","U","U","U", "Y","Y","Y","Y","Y"); $outstr = str_replace($chuCoDau,$chuKoDau,$str); $outstr = strtolower(trim($outstr)); //$outstr = $this->clean_value($outstr); return $outstr; } function generateRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } function bodau($str='') { if(empty($str)){ return $this->generateRandomString(10); } $chuCoDau=array("à","á","ạ","ả","ã","â","ầ","ấ","ậ","ẩ","ẫ","ă", "ằ","ắ","ặ","ẳ","ẵ","è","é","ẹ","ẻ","ẽ","ê","ề" ,"ế","ệ","ể","ễ", "ì","í","ị","ỉ","ĩ", "ò","ó","ọ","ỏ","õ","ô","ồ","ố","ộ","ổ","ỗ","ơ" ,"ờ","ớ","ợ","ở","ỡ", "ù","ú","ụ","ủ","ũ","ư","ừ","ứ","ự","ử","ữ", "ỳ","ý","ỵ","ỷ","ỹ", "đ", "À","Á","Ạ","Ả","Ã","Â","Ầ","Ấ","Ậ","Ẩ","Ẫ","Ă" ,"Ằ","Ắ","Ặ","Ẳ","Ẵ", "È","É","Ẹ","Ẻ","Ẽ","Ê","Ề","Ế","Ệ","Ể","Ễ", "Ì","Í","Ị","Ỉ","Ĩ", "Ò","Ó","Ọ","Ỏ","Õ","Ô","Ồ","Ố","Ộ","Ổ","Ỗ","Ơ" ,"Ờ","Ớ","Ợ","Ở","Ỡ", "Ù","Ú","Ụ","Ủ","Ũ","Ư","Ừ","Ứ","Ự","Ử","Ữ", "Ỳ","Ý","Ỵ","Ỷ","Ỹ", "Đ","?","&",",","/",".","!","@","#","$","%","//",":","\"","\\","'","$","^","(",")","\"","=","_","__","\"","“","”","-"," - ","|","[","]"); $chuKoDau=array("a","a","a","a","a","a","a","a","a","a","a" ,"a","a","a","a","a","a", "e","e","e","e","e","e","e","e","e","e","e", "i","i","i","i","i", "o","o","o","o","o","o","o","o","o","o","o","o" ,"o","o","o","o","o", "u","u","u","u","u","u","u","u","u","u","u", "y","y","y","y","y", "d", "A","A","A","A","A","A","A","A","A","A","A","A" ,"A","A","A","A","A", "E","E","E","E","E","E","E","E","E","E","E", "I","I","I","I","I", "O","O","O","O","O","O","O","O","O","O","O","O" ,"O","O","O","O","O", "U","U","U","U","U","U","U","U","U","U","U", "Y","Y","Y","Y","Y", "D","","","","","","","","","","","","","","","","","","","","","","","","","","","",'-','','',''); $outstr = str_replace($chuCoDau,$chuKoDau,$str); $outstr = strtolower(trim($outstr)); //$outstr = $this->clean_value($outstr); return $outstr; } function format_string($str2){ $str = $this->bodau($str2); $str = preg_replace('/^[^\p{L}\p{Nd}]+/',' ', $str); $str = trim($str); $str = preg_replace('/\s+/', ' ', $str); $str = preg_replace('/\s+/', '-', $str); return empty($str)?str_replace(' ','-',$str2):strtolower($str); } function clean_value($val) { if ($val == "") { return ""; } if (is_array($val)) { $clean_val = array(); foreach ($val as $k => $v) { $clean_val[$k] = $this->clean_value($v); } return $clean_val; } $val = str_replace( " ", " ", $val ); $val = str_replace( chr(0xCA), "", $val ); //Remove sneaky spaces $val = str_replace( "&" , "&" , $val ); $val = str_replace( "<!--" , "<!--" , $val ); $val = str_replace( "-->" , "-->" , $val ); $val = preg_replace( "/<script/i" , "<script" , $val ); $val = str_replace( ">" , ">" , $val ); $val = str_replace( "<" , "<" , $val ); $val = str_replace( "\"" , """ , $val ); //$val = preg_replace( "/\n/" , "<br>" , $val ); // Convert literal newlines $val = preg_replace( "/\\\$/" , "$" , $val ); $val = preg_replace( "/\r/" , "" , $val ); // Remove literal carriage returns $val = str_replace( "!" , "!" , $val ); $val = str_replace( "'" , "'" , $val ); // IMPORTANT: It helps to increase sql query safety. // Ensure unicode chars are OK $val = preg_replace("/&#([0-9]+);/s", "&#\\1;", $val ); // Swop user inputted backslashes //$val = preg_replace( "/\\\(?!&#|\?#)/", "\", $val ); return $val; } function select_var($array) { if ( !is_array($array) ) return -1; ksort($array); $chosen = -1; // Ensure that we return zero if nothing else is available foreach ($array as $k => $v) { if (isset($v)) { $chosen = $v; break; } } return $chosen; } function drop_down_menu($name,$selected,$tablename,$choice_id,$choice_name,$extention="",$sname,$event="") { global $DB; $temp = $DB->query("SELECT $choice_id,$choice_name FROM $tablename $extention LIMIT 1"); $dab =""; if(!$DB->fetch_row ($temp)){ $dab = "disabled=\"disabled\""; } $html = "<select name='$name' id='$name' $dab $event>"; if($sname=="notchoice"){ $sname = "Không chọn(Danh mục root)..."; $html .=" <option value='0'>{$sname}</option>"; } $temp = $DB->query("SELECT $choice_id,$choice_name FROM $tablename $extention"); while ($row=$DB->fetch_row ($temp)){ if ($row[$choice_id]==$selected) $s = "selected"; else $s = ""; $html .=" <option value='{$row[$choice_id]}' {$s} >{$row[$choice_name]}</option>"; } $html .="</select>"; return $html ; } function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } function get_file_extension($file_name) { return substr(strrchr($file_name,'.'),1); } function make_password($number_char='') { if($number_char==''){ $number_char = 8; } $pass = ""; $chars = array( "1","2","3","4","5","6","7","8","9","0", "a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J", "k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T", "u","U","v","V","w","W","x","X","y","Y","z","Z"); $count = count($chars) - 1; srand((double)microtime()*1000000); for($i = 0; $i < $number_char; $i++) { $pass .= $chars[rand(0, $count)]; } return($pass); } function maketime(){ $today = time(); $tran = array( '1'=>'Thứ hai','2'=>'Thứ ba','3'=>'Thứ tư','4'=>'Thứ năm','5'=>'Thứ sáu','6'=>'Thứ 7','7'=>'Chủ nhật'); $date = $tran[date('w',$today)]; $day['thu'] = $date; $day['day'] = date('d',$today); $day['month'] = date('m',$today); $day['year'] = date('Y',$today); return ($day); } function encode($input) { return strtr(base64_encode($input), '+/=', '-_,'); } function decode($input) { return base64_decode(strtr($input, '-_,', '+/=')); } function lastchar($str){ //$str = 'Ok Y'; return $str[strlen($str)-1]; // $last = "y" } function remove_lastchar($str,$n)/*bo n ky tu cuoi trong chuoi str*/{ $new_str=substr($str,0,(strlen($str)-$n)); return $new_str; } function current_url() { $s = ''; if(!empty($_SERVER["HTTPS"]) and $_SERVER["HTTPS"] == 'on' ){ $s = 's'; } return 'http'.$s.'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; } function ope_max($str,$len){ if(strlen($str) < $len){ return $str; }else{ $str = substr($str,0,$len); $a_str = explode(' ',$str); unset($a_str[count($a_str)-1]); $str = implode(' ',$a_str); $str = $str.'...'; return $str; } } // Menu builder function, parentId 0 is the root function buildMenu($parent, $menu) { $html = ""; if (isset($menu['parents'][$parent])) { $html .= "<ul>"; foreach ($menu['parents'][$parent] as $itemId) { if(!isset($menu['parents'][$itemId])) { $html .= "<li><a href='".$menu['items'][$itemId]['ftitle']."'>".$menu['items'][$itemId]['title']."</a></li>"; } if(isset($menu['parents'][$itemId])) { $html .= " <li><a href='".$menu['items'][$itemId]['ftitle']."'>".$menu['items'][$itemId]['title']."</a>"; $html .= $this->buildMenu($itemId, $menu); $html .= "</li>"; } } $html .= "</ul>"; } return $html; } function get_id_youtube($url) { $v = ''; // get video ID from $_GET if (!isset($url)) { return 'Please enter a YouTube video URL.'; } else { $vid = stripslashes($url); $string = $vid; $url = parse_url($string); parse_str($url['query']); } return $v; } function str_encode($data,$pwd) { $x = 0; $a = 0; $j = 0; $Zcrypt = ''; $counter = array(); for ($ii = 0; $ii < 257; $ii++) { $counter[$ii] = ''; } $pwd_length = strlen($pwd); for ($i = 0; $i < 255; $i++) { $key[$i] = ord(substr($pwd, ($i % $pwd_length)+1, 1)); $counter[$i] = $i; } for ($i = 0; $i < 255; $i++) { $x = ($x + $counter[$i] + $key[$i]) % 256; $temp_swap = $counter[$i]; $counter[$i] = $counter[$x]; $counter[$x] = $temp_swap; } for ($i = 0; $i < strlen($data); $i++) { $a = ($a + 1) % 256; $j = ($j + $counter[$a]) % 256; $temp = $counter[$a]; $counter[$a] = $counter[$j]; $counter[$j] = $temp; $k = $counter[(($counter[$a] + $counter[$j]) % 256)]; $Zcipher = ord(substr($data, $i, 1)) ^ $k; $Zcrypt .= chr($Zcipher); } return $Zcrypt; } function hex2bin($hexdata) { $bindata = ''; for ($i=0;$i<strlen($hexdata);$i+=2) { $bindata .= chr(hexdec(substr($hexdata,$i,2))); } return $bindata; } //$encoded = bin2hex(str_encode($txt,$time)); //$decoded = str_encode(hex2bin($encoded),$time); function curl_func($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); $head[] = "Connection: keep-alive"; $head[] = "Keep-Alive: 300"; $head[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; $head[] = "Accept-Language: en-us,en;q=0.5"; curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36'); curl_setopt($ch, CURLOPT_HTTPHEADER, $head); //curl_setopt($ch, CURLOPT_REFERER, 'http://www.phimmoi.net'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); $page = curl_exec($ch); curl_close($ch); return $page; } function get_content_page($url,$referer) { $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,"; $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; $header[] = "Cache-Control: max-age=0"; $header[] = "Connection: keep-alive"; $header[] = "Keep-Alive: 300"; $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; $header[] = "Accept-Language: en-us,en;q=0.5"; $header[] = "Pragma: "; // browsers keep this blank. $process = curl_init($url); curl_setopt($process, CURLOPT_HTTPHEADER, $header); curl_setopt($process, CURLOPT_HEADER, 0); curl_setopt($process, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); //curl_setopt($process, CURLOPT_COOKIEFILE, dirname(__FILE__).'/'.'cookies_youtube.txt'); //curl_setopt($process, CURLOPT_COOKIEJAR, dirname(__FILE__).'/'.'cookies_youtube.txt'); curl_setopt($process, CURLOPT_REFERER, $referer); curl_setopt($process, CURLOPT_ENCODING, 'gzip,deflate'); //curl_setopt($process,CURLOPT_ENCODING , compression); curl_setopt($process, CURLOPT_TIMEOUT, 20); //if (proxy) curl_setopt($cUrl, CURLOPT_PROXY, 'proxy_ip:proxy_port'); curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); $return = curl_exec($process); curl_close($process); return $return; } function alphaID($in, $to_num = false, $pad_up = false, $pass_key = null) { $out = ''; $index = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $base = strlen($index); if ($pass_key !== null) { // Although this function's purpose is to just make the // ID short - and not so much secure, // with this patch by Simon Franz (http://blog.snaky.org/) // you can optionally supply a password to make it harder // to calculate the corresponding numeric ID for ($n = 0; $n < strlen($index); $n++) { $i[] = substr($index, $n, 1); } $pass_hash = hash('sha256',$pass_key); $pass_hash = (strlen($pass_hash) < strlen($index) ? hash('sha512', $pass_key) : $pass_hash); for ($n = 0; $n < strlen($index); $n++) { $p[] = substr($pass_hash, $n, 1); } array_multisort($p, SORT_DESC, $i); $index = implode($i); } if ($to_num) { // Digital number <<-- alphabet letter code $len = strlen($in) - 1; for ($t = $len; $t >= 0; $t--) { $bcp = bcpow($base, $len - $t); $out = $out + strpos($index, substr($in, $t, 1)) * $bcp; } if (is_numeric($pad_up)) { $pad_up--; if ($pad_up > 0) { $out -= pow($base, $pad_up); } } } else { // Digital number -->> alphabet letter code if (is_numeric($pad_up)) { $pad_up--; if ($pad_up > 0) { $in += pow($base, $pad_up); } } for ($t = ($in != 0 ? floor(log($in, $base)) : 0); $t >= 0; $t--) { $bcp = bcpow($base, $t); $a = floor($in / $bcp) % $base; $out = $out . substr($index, $a, 1); $in = $in - ($a * $bcp); } } return $out; /* Running: alphaID(9007199254740989); will return PpQXn7COf and: alphaID('PpQXn7COf', true); will return 9007199254740989 */ } function covtime($youtube_time) { preg_match_all('/(\d+)/',$youtube_time,$parts); // Put in zeros if we have less than 3 numbers. if (count($parts[0]) == 1) { array_unshift($parts[0], "0", "0"); } elseif (count($parts[0]) == 2) { array_unshift($parts[0], "0"); } $sec_init = $parts[0][2]; $seconds = $sec_init%60; $seconds_overflow = floor($sec_init/60); $min_init = $parts[0][1] + $seconds_overflow; $minutes = ($min_init)%60; $minutes_overflow = floor(($min_init)/60); $hours = $parts[0][0] + $minutes_overflow; if($hours != 0) return $hours.':'.$minutes.':'.$seconds; else return $minutes.':'.$seconds; } function encode_html($input) { $temp = ''; $length = strlen($input); for($i = 0; $i < $length; $i++) $temp .= '%' . bin2hex($input[$i]); return $temp; } function getCloud( $data = array(), $minFontSize = 12, $maxFontSize = 40 ) { $minimumCount = min( array_values( $data ) ); $maximumCount = max( array_values( $data ) ); $spread = $maximumCount - $minimumCount; $cloudTags = array(); $spread == 0 && $spread = 1; foreach( $data as $tag => $count ) { $size = $minFontSize + ( $count - $minimumCount ) * ( $maxFontSize - $minFontSize ) / $spread; $cloudTags[] = '<a style="font-size: ' . floor( $size ) . 'px' . '" class="tag_cloud" href="tags/'.$tag . '/" title="' . $tag . '">' . htmlspecialchars( stripslashes( $tag ) ) . '</a>'; } return implode( ", ", $cloudTags ); } function title_text($text){ return trim(strip_tags(str_replace('"','"',html_entity_decode($text)))); } function check_value_array_in_string($headline, $fields) { $field_values = array_values($fields); foreach ($field_values as $field_value) { if (strpos($headline, $field_value) !== false) { return true; // field value found in a string } } return false; // nothing found during the loop } function json_decode_nice($json, $assoc = TRUE){ $json = str_replace(array("\n","\r"),"\\n",$json); $json = preg_replace('/([{,]+)(\s*)([^"]+?)\s*:/','$1"$3":',$json); $json = preg_replace('/(,)\s*}$/','}',$json); return json_decode($json,$assoc); } function iso8601_duration($seconds) { $intervals = array('D' => 60*60*24, 'H' => 60*60, 'M' => 60, 'S' => 1); $pt = 'P'; $result = ''; foreach ($intervals as $tag => $divisor) { $qty = floor($seconds/$divisor); if ( !$qty && $result == '' ) { $pt = 'T'; continue; } $seconds -= $qty * $divisor; $result .= "$qty$tag"; } if ( $result=='' ) $result='0S'; return "$pt$result"; } function get_ip_address() { // check for shared internet/ISP IP if (!empty($_SERVER['HTTP_CLIENT_IP'])) { return $_SERVER['HTTP_CLIENT_IP']; } // check for IPs passing through proxies if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { return $_SERVER['HTTP_X_FORWARDED_FOR']; } if (!empty($_SERVER['HTTP_X_FORWARDED'])) { return $_SERVER['HTTP_X_FORWARDED']; } if (!empty($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) { return $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; } if (!empty($_SERVER['HTTP_FORWARDED_FOR'])) { return $_SERVER['HTTP_FORWARDED_FOR']; } if (!empty($_SERVER['HTTP_FORWARDED'])) { return $_SERVER['HTTP_FORWARDED']; } // return unreliable ip since all else failed return $_SERVER['REMOTE_ADDR']; } function tree_company($parentid,$arr,$sep){ foreach($arr as $key=>$v){ if($v['company_parentid'] == $parentid){ $arr[$key]['company_name'] = $sep.' '.$arr[$key]['company_name']; $arr = $this->tree_company($v['company_id'],$arr,$sep." + "); } } return $arr; } function get_pupil_real_name_flag($p_pupil_real_name){ $arr = explode("(",$p_pupil_real_name); if(sizeof($arr)==2){ return substr($arr[1],0,1); } return ""; } function convert_number_to_words($number) { $hyphen = ' '; $conjunction = ' '; $separator = ' '; $negative = 'âm '; $decimal = ' phẩy '; $dictionary = array( 0 => 'Không', 1 => 'Một', 2 => 'Hai', 3 => 'Ba', 4 => 'Bốn', 5 => 'Năm', 6 => 'Sáu', 7 => 'Bảy', 8 => 'Tám', 9 => 'Chín', 10 => 'Mười', 11 => 'Mười một', 12 => 'Mười hai', 13 => 'Mười ba', 14 => 'Mười bốn', 15 => 'Mười năm', 16 => 'Mười sáu', 17 => 'Mười bảy', 18 => 'Mười tám', 19 => 'Mười chín', 20 => 'Hai mươi', 30 => 'Ba mươi', 40 => 'Bốn mươi', 50 => 'Năm mươi', 60 => 'Sáu mươi', 70 => 'Bảy mươi', 80 => 'Tám mươi', 90 => 'Chín mươi', 100 => 'trăm', 1000 => 'ngàn', 1000000 => 'triệu', 1000000000 => 'tỷ', 1000000000000 => 'nghìn tỷ', 1000000000000000 => 'ngàn triệu triệu', 1000000000000000000 => 'tỷ tỷ' ); if( !is_numeric( $number ) ) { return false; } if( ($number >= 0 && (int)$number < 0) || (int)$number < 0 - PHP_INT_MAX ) { // overflow trigger_error( 'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX, E_USER_WARNING ); return false; } if( $number < 0 ) { return $negative . $this->convert_number_to_words( abs( $number ) ); } $string = $fraction = null; if( strpos( $number, '.' ) !== false ) { list( $number, $fraction ) = explode( '.', $number ); } switch (true) { case $number < 21: $string = $dictionary[$number]; break; case $number < 100: $tens = ((int)($number / 10)) * 10; $units = $number % 10; $string = $dictionary[$tens]; if( $units ) { $string .= $hyphen . $dictionary[$units]; } break; case $number < 1000: $hundreds = $number / 100; $remainder = $number % 100; $string = $dictionary[$hundreds] . ' ' . $dictionary[100]; if( $remainder ) { $string .= $conjunction . $this->convert_number_to_words( $remainder ); } break; default: $baseUnit = pow( 1000, floor( log( $number, 1000 ) ) ); $numBaseUnits = (int)($number / $baseUnit); $remainder = $number % $baseUnit; $string = $this->convert_number_to_words( $numBaseUnits ) . ' ' . $dictionary[$baseUnit]; if( $remainder ) { $string .= $remainder < 100 ? $conjunction : $separator; $string .= $this->convert_number_to_words( $remainder ); } break; } if( null !== $fraction && is_numeric( $fraction ) ) { $string .= $decimal; $words = array( ); foreach( str_split((string) $fraction) as $number ) { $words[] = $dictionary[$number]; } $string .= implode( ' ', $words ); } return $string; } function tinymce($name,$id,$data='',$row=5){ $txt = '<script type="text/javascript">'; $txt .= "tinymce.init({ selector: 'textarea#".$id."', height: 500, plugins: [ 'advlist', 'autolink', 'lists', 'link', 'image', 'charmap', 'preview', 'anchor', 'searchreplace', 'visualblocks', 'code', 'fullscreen', 'insertdatetime', 'media', 'table', 'wordcount' ], toolbar: 'undo redo | blocks | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat', images_upload_url: 'index.php?act=admin&code=tinymce_upload', content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:16px }' });"; $txt .= '</script>'; $txt .= '<textarea id="'.$id.'" name="'.$name.'" rows="'.$row.'">'.$data.'</textarea>'; return $txt; } function time_site($date){ $time = strtotime($date); if(time()-$time<=24*60*60){ return '<span class="text-danger">New</span>'; } return date('F j, Y',$time); } function time_ago($time_ago) { $cur_time = time(); $time_elapsed = $cur_time - $time_ago; $seconds = $time_elapsed ; $minutes = round($time_elapsed / 60 ); $hours = round($time_elapsed / 3600); $days = round($time_elapsed / 86400 ); $weeks = round($time_elapsed / 604800); $months = round($time_elapsed / 2600640 ); $years = round($time_elapsed / 31207680 ); // Seconds if($seconds <= 60){ return "just now"; } //Minutes else if($minutes <=60){ if($minutes==1){ return "one minute ago"; } else{ return "$minutes minutes ago"; } } //Hours else if($hours <=24){ if($hours==1){ return "an hour ago"; }else{ return "$hours hrs ago"; } } //Days else if($days <= 7){ if($days==1){ return "yesterday"; }else{ return "$days days ago"; } } //Weeks else if($weeks <= 4.3){ if($weeks==1){ return "a week ago"; }else{ return "$weeks weeks ago"; } } //Months else if($months <=12){ if($months==1){ return "a month ago"; }else{ return "$months months ago"; } } //Years else{ if($years==1){ return "one year ago"; }else{ return date('F j, Y',$time_ago); } } } }//end class ?>