From 5f4c17cd28c12ae8929454fa121af934161e03fc Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Sat, 7 Sep 2024 06:24:53 -0400 Subject: [PATCH] blog data --- app/Config/Routes.php | 3 ++ app/Controllers/BlogData.php | 102 ++++++++++++++++++++++++++++++++++- 2 files changed, 104 insertions(+), 1 deletion(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index fcac8ce..587287e 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -9,3 +9,6 @@ $routes->get('/', 'Home::index'); $routes->get('/en/wrench/api/v1/blogdata/wrenchboard', 'BlogData::website'); $routes->get('/en/wrench/api/v1/blogdata/wrenchboard/(:any)', 'BlogData::blogLimitedData/$1'); + +$routes->get('/blogdata/wrenchboard', 'BlogData::website'); +$routes->get('/blogdata/(:any)', 'BlogData::anyBlogData/$1'); diff --git a/app/Controllers/BlogData.php b/app/Controllers/BlogData.php index 2506390..d07eeef 100644 --- a/app/Controllers/BlogData.php +++ b/app/Controllers/BlogData.php @@ -120,10 +120,110 @@ class BlogData extends BaseController return $this->response->setJson($res1); } - public function index() + public function anyBlogData($blogName) { + log_message('critical', "anyBlogData DATA CALL ********* ".$blogName ); + $blogsArray = ['chiefsoft', + 'blackfaces', + 'mermsemr', + 'myfit', + 'dorcastore', + 'sanyaameye', + 'oluameye_www', + 'automedsys', + 'tokslaw', + 'oluameye', + 'coregrade', + 'wrenchboard', + 'tokslaw_blog', + 'modupeameye']; + + $custom = [ + 'DSN' => '', + 'hostname' => '10.10.10.35', + 'username' => 'bloguser', + 'password' => 'bloguserF22!', + 'database' => $blogName, + 'DBDriver' => 'MySQLi', + 'DBPrefix' => '', + 'pConnect' => false, + 'DBDebug' => (ENVIRONMENT !== 'production'), + 'charset' => 'utf8', + 'DBCollat' => 'utf8_general_ci', + 'swapPre' => '', + 'encrypt' => false, + 'compress' => false, + 'strictOn' => false, + 'failover' => [], + 'port' => 3307, + ]; + $dbConnection = \Config\Database::connect($custom); + + // var_dump( $general_blog ); + $raw_json = file_get_contents('php://input'); + $in = json_decode($raw_json, true); + log_message('critical', "anyBlogData DATA CALL ********* ".serialize($in) ); + + $out = $this->apiBlogData($dbConnection, 0); + + +//var_dump($out); + + $out['blogconfig'] = [ + "media_url" => "https://blog.wrenchboard.com/wp-content/uploads", + "site_url" => "https://blog.wrenchboard.com", + "other_cofig2" => "NONE", + ]; + return $this->response->setJson($out); } + private function apiBlogData($dbConnection, $blog_id=0) { + $this->db = \Config\Database::connect($this->con_name); + $data = array(); + $extra_filter = ""; + if ($blog_id > 0 ){ + $extra_filter = " AND p1.id = $blog_id "; + } + + 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' $extra_filter + ORDER BY p1.post_date DESC LIMIT 2000"; + + $query =$dbConnection->query($mysql); + + $data['payload']['blogdata'] = $query->getResult('array'); + $totalCount = count( $data['payload']['blogdata'] ); + + $randomIndex = rand(1, $totalCount); + + $siteConfig = $this->blogConfigData($dbConnection); + $siteUrl = $siteConfig[0]["option_value"]; + + //var_dump($siteConfig); + + $data['payload']['featured'] = $data['payload']['blogdata'][$randomIndex ]; + $data['payload']['image_url'] = $siteUrl.'wp-content/uploads/'; + $data['payload']['blog_url'] = $siteUrl; //https://blog.wrenchboard.com/'; + $data['payload']['total'] = $totalCount; + } catch (Exception $ex) { + + } + return $data; + } + + private function blogConfigData($dbConnection){ + $opSql ="SELECT * FROM `wp_options` WHERE option_name='siteurl'"; + $query =$dbConnection->query($opSql); + return $query->getResult('array'); + } } \ No newline at end of file