blog filter added

This commit is contained in:
CHIEFSOFT\ameye
2023-07-24 08:17:52 -04:00
parent 0f6c834c26
commit bcc8841a0b
+24 -9
View File
@@ -12,9 +12,13 @@ class WrenchBlog extends BaseController
protected $db; protected $db;
public $con_name = 'wrench_blog'; public $con_name = 'wrench_blog';
private function apiData() { private function apiData($blog_id) {
$this->db = \Config\Database::connect($this->con_name); $this->db = \Config\Database::connect($this->con_name);
$data = array(); $data = array();
$extra_filter = "";
if ($blog_id > 0 ){
$extra_filter = " AND p1.id = $blog_id ";
}
try { 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 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";
@@ -25,7 +29,7 @@ class WrenchBlog extends BaseController
ON (wm1.meta_value = wm2.post_id AND wm2.meta_key = '_wp_attached_file' AND wm2.meta_value IS NOT NULL ) ON (wm1.meta_value = wm2.post_id AND wm2.meta_key = '_wp_attached_file' AND wm2.meta_value IS NOT NULL )
WHERE WHERE
p1.post_status='publish' p1.post_status='publish'
AND p1.post_type='post' AND p1.post_type='post' $extra_filter
ORDER BY p1.post_date DESC LIMIT 2000"; ORDER BY p1.post_date DESC LIMIT 2000";
$query = $this->db->query($mysql); $query = $this->db->query($mysql);
@@ -67,21 +71,32 @@ class WrenchBlog extends BaseController
public function website(){ public function website(){
$blog_id = 0;
// echo "EXYTACT INPUT DATA HERE"; // echo "EXYTACT INPUT DATA HERE";
$raw_json = file_get_contents('php://input'); $raw_json = file_get_contents('php://input');
$in = json_decode($raw_json, true); $in = json_decode($raw_json, true);
log_message('critical', "BLOG DATA CALL ********* ".serialize($in) ); log_message('critical', "BLOG DATA CALL ********* ".serialize($in) );
if (isset($in['blog_id'])){
$endpoint = "WRENCH_BLOG_DATA"; $blog_id = (int) $in['blog_id'];
$res1 = $this->getCache($endpoint);
if (count($res1)==0){
$rawData = $this->apiData();
$res1= $rawData['payload']; //[0]['payload'];
$this->saveCache($endpoint,$res1);
} }
if ($blog_id > 0 ){
$rawData = $this->apiData($blog_id);
$res1= $rawData['payload']; //[0]['payload'];
}
else{
$endpoint = "WRENCH_BLOG_DATA";
$res1 = $this->getCache($endpoint);
if (count($res1)==0){
$rawData = $this->apiData($blog_id);
$res1= $rawData['payload']; //[0]['payload'];
$this->saveCache($endpoint,$res1);
}
}
$limit = isset($in['limit']) ? $in['limit']: 0; $limit = isset($in['limit']) ? $in['limit']: 0;
if ($limit> 0){ if ($limit> 0){
$res1['blogdata'] = array_slice($res1['blogdata'], 0, $limit); $res1['blogdata'] = array_slice($res1['blogdata'], 0, $limit);