238 lines
7.6 KiB
PHP
238 lines
7.6 KiB
PHP
<?php
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
class FloatUserWeb extends BaseController
|
|
{
|
|
use ResponseTrait;
|
|
|
|
protected $db;
|
|
|
|
|
|
public $con_name = 'float_blog';
|
|
private function apiData() {
|
|
$this->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;
|
|
}
|
|
|
|
|
|
} |