From cfaec347cfb81ed738efefad3b5edf2c7aa9c348 Mon Sep 17 00:00:00 2001 From: "DESKTOP-GBA0BK8\\Admin" Date: Mon, 10 Apr 2023 13:04:33 -0400 Subject: [PATCH] Image path --- app/Config/Routes.php | 6 +- app/Controllers/FloatFleetWeb.php | 240 ++++++++++++++++++++++++++++++ app/Controllers/FloatUserWeb.php | 238 +++++++++++++++++++++++++++++ app/Controllers/FloatWeb.php | 1 + 4 files changed, 482 insertions(+), 3 deletions(-) create mode 100644 app/Controllers/FloatFleetWeb.php create mode 100644 app/Controllers/FloatUserWeb.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 4436ac6..01b08f3 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -43,10 +43,10 @@ $routes->get('/en/floatweb/api/v1/blogdata/(:any)', 'FloatWeb::website/$1'); $routes->get('/en/floatweb/api/v1/faq', 'FloatWeb::website'); $routes->post('/en/floatweb/api/v1/contact', 'FloatWeb::website'); +$routes->post('/en/userweb/api/v1/login', 'FloatUserWeb::user'); +$routes->post('/en/fleetweb/api/v1/login', 'FloatFleetWeb::fleet'); + -//CHIEFSOFT WEBSITE -$routes->get('/chiefsoft/site/blogdata', 'Chiefsoft::blogdata'); // when no limit is sent -$routes->post('/chiefsoft/site/contact', 'Chiefsoft::contact'); //MERMS MYFIT NO SESSION DATA $routes->get('/en/desktop/api/v2/myfit/country', 'Myfit::country'); diff --git a/app/Controllers/FloatFleetWeb.php b/app/Controllers/FloatFleetWeb.php new file mode 100644 index 0000000..16effe0 --- /dev/null +++ b/app/Controllers/FloatFleetWeb.php @@ -0,0 +1,240 @@ +db = \Config\Database::connect($this->con_name); + $data = array(); + + try { + $mysql = "SELECT id, post_title, post_content,post_date,comment_count FROM wp_posts WHERE post_type='post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 9"; + $mysql = "SELECT p1.id AS id, p1.*, wm2.meta_value FROM wp_posts p1 LEFT JOIN wp_postmeta wm1 + ON (wm1.post_id = p1.id AND wm1.meta_value IS NOT NULL AND wm1.meta_key = '_thumbnail_id' ) + LEFT JOIN + wp_postmeta wm2 + ON (wm1.meta_value = wm2.post_id AND wm2.meta_key = '_wp_attached_file' AND wm2.meta_value IS NOT NULL ) + WHERE + p1.post_status='publish' + AND p1.post_type='post' + ORDER BY p1.post_date DESC LIMIT 30"; + +//echo $mysql; + + $query = $this->db->query($mysql); + + // $row = $query->result_array(); + + // $data["blog_array"] = $row; + $data['payload']['blogdata'] = $query->getResult('array'); + $data['payload']['featured'] = []; + } catch (Exception $ex) { + + } + + // featured +// try { +// $mysql = "SELECT id, post_title, post_content,post_date,comment_count +// FROM wp_posts WHERE post_type='post' AND post_status = 'publish' AND id = 263"; +// $query = $this->db->query($mysql); +// +// $rowF = $query->result_array(); +// // print_r( $rowF ); +// // $r = $this->db->query($mysql); +// $data["blog_featured"] = $rowF[0]; +// } catch (Exception $ex) { +// +// } + + // $this->renderSitePage('blog', $data); + // return $this->response->setJson($data); + return $data; + } + + + public function blogData($endpoint,$raw_array) + { + /* + $rawData = $this->apiData(); + // $res1= $rawData[0]['payload']; + $res1= $rawData; //[0]['payload']; + $this->saveCache('blogdata',$res1['payload']); + */ + + $res1 = $this->getCache($endpoint); + if (count($res1)==0){ + $rawData = $this->apiData(); + $res1= $rawData['payload']; //[0]['payload']; + $this->saveCache($endpoint,$res1); + } + //$resJson = $this->response->setJson($res1); + return $res1; + } + + public function index() + { + + } + public function fleet() + { + //$request = service('request'); + header('Access-Control-Allow-Origin: *'); + //header("Access-Control-Allow-Origin: http://localhost:9057 "); + header('Access-Control-Expose-Headers: Access-Control-Allow-Origin'); + //header('Access-Control-Allow-Credentials: true '); + //header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With"); + header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); + header('Content-type: application/json'); + + // what is the endpoint + $uri = urldecode(current_url(true)); + $findme = '?'; + $pos = strpos($uri, $findme); + if ($pos > 5) { + $uri = substr($uri, 0, $pos); + } + + $pieces = explode('/', $uri); + $psc = count($pieces); + + $endpoint = $psc > 0 ? $pieces[$psc - 1] : ''; + log_message('critical', "Enpoint-> ".$endpoint ); + + $endpoints = [ + 'faq' => ['GET'], + 'blogdata' => ['GET'], + 'contact' => ['POST'] + ]; + + $res1 = []; + if (array_key_exists($endpoint, $endpoints)) { + } else { + http_response_code(404); + // tell the user product does not exist + echo json_encode([ + 'message' => 'Endpoint not found.', + 'URI' => $uri, + ]); + } + // echo "EXYTACT INPUT DATA HERE"; + $raw_json = file_get_contents('php://input'); + $raw_array = json_decode($raw_json, true); + + if ($_SERVER['REQUEST_METHOD'] == 'GET') { + log_message('critical', "Enpoint LOC2 HERE -> ".$endpoint ); + $get_param = $_GET['reqData'] ?? null; + $raw_array = ($get_param!=null) ? json_decode($get_param, true):[]; + } + + // $raw_array['fff'] = json_decode($this->request->getJSON(), true); + log_message('critical', "Enpoint LOC2-> ".$endpoint ); + switch ($endpoint) { + case 'faq': + $res1 = (new \App\Models\faqData())->getSiteFaq([]); + break; + case 'blogdata': + $res1 = $this->blogData($endpoint,$raw_array); + break; + case 'contact': + $res1 = $this->contact($raw_array); + break; + + } + + return $this->response->setJson($res1); + } + + //this is dummy function to establish the endpoints before real implementations + private function dummyData($raw_array) + { + return [ + 'msg' => 'Not implemented yet', + 'raw_data' => $raw_array, + ]; + } + + private function contact($raw_array) + { + /*$inx = array( + 'name' => $this->post('name'), + 'email' => $this->post('email'), + 'country' => $this->post('country'), + 'phone' => $this->post('phone'), + 'message' => $this->post('message') + ); + $something = $this->request->getVar('name'); + */ +// header('Access-Control-Allow-Origin: * '); +// //header("Access-Control-Allow-Origin: http://localhost:9057 "); +// header('Access-Control-Expose-Headers: Access-Control-Allow-Origin'); +// header('Access-Control-Allow-Credentials: true '); +// //header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With"); +// header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); +// header('Content-type: application/json'); + $startInsert = false; + $status = 0; + $message_id = ''; +// $raw_json = file_get_contents('php://input'); +// $raw_array = json_decode($raw_json, true); +// $something = $raw_array['name']; + + $db = \Config\Database::connect('float_site'); + if ( + $raw_array['country'] != '' && + $raw_array['email'] != '' && + $raw_array['name'] != '' && + $raw_array['message'] != '' && + $raw_array['phone'] != '' + ) { + $startInsert = true; + } + else{ + $status = -2; + $message_id = 'Parameters not recieved'; + } + $data = [ + 'country' => $raw_array['country'], + 'email' => $raw_array['email'], + 'name' => $raw_array['name'], + 'message' => $raw_array['message'], + 'phone' => $raw_array['phone'], + ]; + + if ($startInsert) { + try { + $db->table('myfit_contact')->insert($data); + // $insert_id = $db->affectedRows(); + $insert_id = $db->insertId(); + $query = $db->query( + 'SELECT uuid, id FROM myfit_contact WHERE id = ' . + $insert_id + ); + $row = $query->getRow(); + $message_id = $row->uuid; + $status = $row->id; + } catch (Exception $e) { + $status = -1; + $message_id = ''; + } + } + + $inx = [ + 'message_id' => $message_id, + 'status' => $status, + ]; + return $inx; + } + + +} \ No newline at end of file diff --git a/app/Controllers/FloatUserWeb.php b/app/Controllers/FloatUserWeb.php new file mode 100644 index 0000000..f3ed2cd --- /dev/null +++ b/app/Controllers/FloatUserWeb.php @@ -0,0 +1,238 @@ +db = \Config\Database::connect($this->con_name); + $data = array(); + + try { + $mysql = "SELECT id, post_title, post_content,post_date,comment_count FROM wp_posts WHERE post_type='post' AND post_status = 'publish' ORDER BY post_date DESC LIMIT 9"; + $mysql = "SELECT p1.id AS id, p1.*, wm2.meta_value FROM wp_posts p1 LEFT JOIN wp_postmeta wm1 + ON (wm1.post_id = p1.id AND wm1.meta_value IS NOT NULL AND wm1.meta_key = '_thumbnail_id' ) + LEFT JOIN + wp_postmeta wm2 + ON (wm1.meta_value = wm2.post_id AND wm2.meta_key = '_wp_attached_file' AND wm2.meta_value IS NOT NULL ) + WHERE + p1.post_status='publish' + AND p1.post_type='post' + ORDER BY p1.post_date DESC LIMIT 30"; + +//echo $mysql; + + $query = $this->db->query($mysql); + + // $row = $query->result_array(); + + // $data["blog_array"] = $row; + $data['payload']['blogdata'] = $query->getResult('array'); + $data['payload']['featured'] = []; + } catch (Exception $ex) { + + } + + // featured +// try { +// $mysql = "SELECT id, post_title, post_content,post_date,comment_count +// FROM wp_posts WHERE post_type='post' AND post_status = 'publish' AND id = 263"; +// $query = $this->db->query($mysql); +// +// $rowF = $query->result_array(); +// // print_r( $rowF ); +// // $r = $this->db->query($mysql); +// $data["blog_featured"] = $rowF[0]; +// } catch (Exception $ex) { +// +// } + + // $this->renderSitePage('blog', $data); + // return $this->response->setJson($data); + return $data; + } + + + public function blogData($endpoint,$raw_array) + { + /* + $rawData = $this->apiData(); + // $res1= $rawData[0]['payload']; + $res1= $rawData; //[0]['payload']; + $this->saveCache('blogdata',$res1['payload']); + */ + + $res1 = $this->getCache($endpoint); + if (count($res1)==0){ + $rawData = $this->apiData(); + $res1= $rawData['payload']; //[0]['payload']; + $this->saveCache($endpoint,$res1); + } + //$resJson = $this->response->setJson($res1); + return $res1; + } + + public function index() + { + + } + public function user() + { + //$request = service('request'); + header('Access-Control-Allow-Origin: *'); + //header("Access-Control-Allow-Origin: http://localhost:9057 "); + header('Access-Control-Expose-Headers: Access-Control-Allow-Origin'); + //header('Access-Control-Allow-Credentials: true '); + //header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With"); + header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); + header('Content-type: application/json'); + + // what is the endpoint + $uri = urldecode(current_url(true)); + $findme = '?'; + $pos = strpos($uri, $findme); + if ($pos > 5) { + $uri = substr($uri, 0, $pos); + } + + $pieces = explode('/', $uri); + $psc = count($pieces); + + $endpoint = $psc > 0 ? $pieces[$psc - 1] : ''; + log_message('critical', "Enpoint-> ".$endpoint ); + + $endpoints = [ + 'login' => ['POST'] + ]; + + $res1 = []; + if (array_key_exists($endpoint, $endpoints)) { + } else { + http_response_code(404); + // tell the user product does not exist + echo json_encode([ + 'message' => 'Endpoint not found.', + 'URI' => $uri, + ]); + } + // echo "EXYTACT INPUT DATA HERE"; + $raw_json = file_get_contents('php://input'); + $raw_array = json_decode($raw_json, true); + + if ($_SERVER['REQUEST_METHOD'] == 'GET') { + log_message('critical', "Enpoint LOC2 HERE -> ".$endpoint ); + $get_param = $_GET['reqData'] ?? null; + $raw_array = ($get_param!=null) ? json_decode($get_param, true):[]; + } + + // $raw_array['fff'] = json_decode($this->request->getJSON(), true); + log_message('critical', "Enpoint LOC2-> ".$endpoint ); + switch ($endpoint) { + case 'faq': + $res1 = (new \App\Models\faqData())->getSiteFaq([]); + break; + case 'blogdata': + $res1 = $this->blogData($endpoint,$raw_array); + break; + case 'contact': + $res1 = $this->contact($raw_array); + break; + + } + + return $this->response->setJson($res1); + } + + //this is dummy function to establish the endpoints before real implementations + private function dummyData($raw_array) + { + return [ + 'msg' => 'Not implemented yet', + 'raw_data' => $raw_array, + ]; + } + + private function contact($raw_array) + { + /*$inx = array( + 'name' => $this->post('name'), + 'email' => $this->post('email'), + 'country' => $this->post('country'), + 'phone' => $this->post('phone'), + 'message' => $this->post('message') + ); + $something = $this->request->getVar('name'); + */ +// header('Access-Control-Allow-Origin: * '); +// //header("Access-Control-Allow-Origin: http://localhost:9057 "); +// header('Access-Control-Expose-Headers: Access-Control-Allow-Origin'); +// header('Access-Control-Allow-Credentials: true '); +// //header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With"); +// header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS'); +// header('Content-type: application/json'); + $startInsert = false; + $status = 0; + $message_id = ''; +// $raw_json = file_get_contents('php://input'); +// $raw_array = json_decode($raw_json, true); +// $something = $raw_array['name']; + + $db = \Config\Database::connect('float_site'); + if ( + $raw_array['country'] != '' && + $raw_array['email'] != '' && + $raw_array['name'] != '' && + $raw_array['message'] != '' && + $raw_array['phone'] != '' + ) { + $startInsert = true; + } + else{ + $status = -2; + $message_id = 'Parameters not recieved'; + } + $data = [ + 'country' => $raw_array['country'], + 'email' => $raw_array['email'], + 'name' => $raw_array['name'], + 'message' => $raw_array['message'], + 'phone' => $raw_array['phone'], + ]; + + if ($startInsert) { + try { + $db->table('myfit_contact')->insert($data); + // $insert_id = $db->affectedRows(); + $insert_id = $db->insertId(); + $query = $db->query( + 'SELECT uuid, id FROM myfit_contact WHERE id = ' . + $insert_id + ); + $row = $query->getRow(); + $message_id = $row->uuid; + $status = $row->id; + } catch (Exception $e) { + $status = -1; + $message_id = ''; + } + } + + $inx = [ + 'message_id' => $message_id, + 'status' => $status, + ]; + return $inx; + } + + +} \ No newline at end of file diff --git a/app/Controllers/FloatWeb.php b/app/Controllers/FloatWeb.php index ef54c95..c5a8552 100644 --- a/app/Controllers/FloatWeb.php +++ b/app/Controllers/FloatWeb.php @@ -39,6 +39,7 @@ class FloatWeb extends BaseController // $data["blog_array"] = $row; $data['payload']['blogdata'] = $query->getResult('array'); $data['payload']['featured'] = []; + $data['payload']['image_url'] = 'https://blog.float.sg/wp-content/uploads/'; } catch (Exception $ex) { }