abstract class Model { public function get_logo() { $data = []; $data['active'] = 1; $rsList=Model::curl("logo/get", $data); $rLists = json_decode(json_encode($rsList->data->data), true); $rLogo = $rLists[0]; return $rLogo['image']; } public function aspect_ratio($maxWidth, $maxHeight, $width, $height, $return) { if($width > $maxWidth) { $ratio = $maxWidth / $width; // get ratio for scaling image $height = $height * $ratio; // Reset height to match scaled image $width = $width * $ratio; // Reset width to match scaled image } if($height > $maxHeight) { $ratio = $maxHeight / $height; // get ratio for scaling image $width = $width * $ratio; // Reset width to match scaled image $height = $height * $ratio; // Reset height to match scaled image } if($return =='width') return $width; if($return =='height') return $height; } public function get_data_name($table, $id) { $data=[]; $data['table']=$table; $data['id']=$id; $rs = Model::curl("common/get_data_name", $data); $r = json_decode(json_encode($rs->data->data), true); $rData=$r[0]; return $rData['name']; } public function get_admin_val($fld) { $data=[]; $data['id']=1; $rs = Model::curl("admin/get", $data); $r = json_decode(json_encode($rs->data->data), true); $rData=$r[0]; return $rData[$fld]; } function replace_apos($str) { return str_replace('"','`',str_replace("'","`",$str)); } function getYoutubeVideoID($video) { $imageid=""; $arr=explode("http://www.youtube.com/watch?v=",$video); $arr1=explode("&",$arr[1]); $imageid=$arr1[0]; if($imageid=="") { $arr=explode("http://youtu.be/",$video); $arr1=$arr[1]; $imageid=$arr1; } if($imageid=="") { $arr=explode("https://www.youtube.com/watch?v=",$video); $arr1=explode("&",$arr[1]); $imageid=$arr1[0]; } return $imageid; } function getYoutubeVideoImage($video) { $imageid=""; $arr=explode("http://www.youtube.com/watch?v=",$video); $arr1=explode("&",$arr[1]); $imageid=$arr1[0]; if($imageid=="") { $arr=explode("http://youtu.be/",$video); $arr1=$arr[1]; $imageid=$arr1; } if($imageid=="") { $arr=explode("https://www.youtube.com/watch?v=",$video); $arr1=explode("&",$arr[1]); $imageid=$arr1[0]; } /*if(Model::checkRemoteFile("http://img.youtube.com/vi/".$imageid."/maxresdefault.jpg")=="yes") return "http://img.youtube.com/vi/".$imageid."/maxresdefault.jpg"; else if(Model::checkRemoteFile("http://img.youtube.com/vi/".$imageid."/hqdefault.jpg")=="yes") return "http://img.youtube.com/vi/".$imageid."/hqdefault.jpg"; else*/ return "http://img.youtube.com/vi/".$imageid."/hqdefault.jpg"; } function goPaypal( $data) { define( 'SSL_URL', 'https://www.paypal.com/cgi-bin/webscr' ); define( 'SSL_SAND_URL', 'https://www.sandbox.paypal.com/cgi-bin/webscr' ); $action = ''; //Is this a test transaction? $action = ($data['paypal_mode']) ? SSL_SAND_URL : SSL_URL; $form = ''; $form .= '
'; return $form; } function make_links_clickable($text) { return preg_replace('!(((f|ht)tp(s)?://)[-a-zA-Z?-??-?()0-9@:%_+.~#?&;//=]+)!i', '$1', $text); } public function create_params($param) { $params = ""; foreach ($param as $key => $value) { $params .= $key . "=" . $value . "&"; } $params = rtrim($params, "&"); return $params; } public function curl($url, $param,$decode=true) { $params = Model::create_params($param); $url = API_PATH . $url; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); // Receive server response ... curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); //print_r($result); //die(); curl_close($ch); if($decode) { return json_decode($result); }else { return ($result); } } public function curl_with_token($urls, $param,$decode=true) { $url = API_PATH . $urls; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Accept: application/json", "Content-Type" => "multipart/form-data", "Authorization: Bearer " . $_COOKIE['token'], )); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $param); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $results = curl_exec($ch); //print_r($results); curl_close($ch); $result = json_decode($results); if ($result->status == "false" && $result->err == "expire token") { $token = Model::get_new_token(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Accept: application/json", "Authorization: Bearer " . $token, )); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $param); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $results = curl_exec($ch); curl_close($ch); } if($decode) { return json_decode($results); }else { return ($results); } } public function get_new_token() { $url = API_PATH . "token/getToken"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Accept: application/json", "Authorization: Bearer " . $_COOKIE['token'], )); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $result = curl_exec($ch); curl_close($ch); $result = json_decode($result); setcookie("token", $result->data, time() + (86400 * 365), "/", URL_Domain, false, true); // 86400 = 1 day return $result->data; } public function user_authentication() { if(!isset($_SESSION['user_id'])) Router::redirect("login"); } public function admin_authentication() { if(!isset($_SESSION['admin_id'])) Router::redirect("admin"); } function backup_tables($file_name,$db,$host,$user,$pass,$name='',$tables = '*') { $file='apis/uploads/backup/'.$file_name; $link = mysqli_connect($host,$user,$pass); mysqli_select_db($db,$link); //get all of the tables if($tables == '*') { $tables = array(); $result = mysqli_query('SHOW TABLES'); while($row = mysqli_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } //cycle through foreach($tables as $table) { $result = mysqli_query('SELECT * FROM '.$table); $num_fields = mysqli_num_fields($result); $return.= 'DROP TABLE '.$table.';'; $row2 = mysqli_fetch_row(mysqli_query('SHOW CREATE TABLE '.$table)); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while($row = mysqli_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j < $num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = ereg_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j < ($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } //save file $handle = fopen($file,'w+'); fwrite($handle,$return); fclose($handle); } }/// Class End ?>