blog data
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user