<?php
 require_once("common_slug_functions.php"); // ✅ added 
require_once("db_conn_class2.php");
//echo 'Hello';
$blog_id         = 0;
$blog_title      = "";
$blog_desc       = "";
$written_by      = "";
$posting_dt      = "";
$blog_image_path = "";

$blogs = "";
$msg ="";
$flag = 0;
$no_of_blogs = 0;

if(isset($_GET['id']) && !empty($_GET['id'])) {
   $blog_id = $_GET['id'];
}

//creating object of database class
$dbh = new db_conn();
$dbh->set_conn();

//getting news id by explode function
$path = ltrim($_SERVER['REQUEST_URI'], '/');
//echo "path = ".$path;
$b = explode("/", $path);
$id = explode(".", $b[1]);
$b_url = explode("-", $id[0]);
$b_id = $b_url[0];

$blog_id = $b_id;

$blog_t = explode($blog_id,$path);
$blog_tt =  explode('blog.php',$blog_t[1]);
$blog_ttt = substr($blog_tt[0],1);
$blog_tttt = rtrim($blog_ttt, "- ");
$blog_f= str_replace("-"," ",$blog_tttt);
$blog_e= str_replace("_","-",$blog_f);
//echo $blog_e;
//return;
//==================================================================================================================
//fetching  blog from database
$sql_blogs = "select * from tbl_blogs ";
$sql_blogs = $sql_blogs . " where status = 'ACTIVE'  and blog_type = 'SEN-Intl' and deleted = 0 and blog_id = ".$blog_id;

//echo "sql_blogs=".$sql_blogs;
//return;
$result_blogs = mysqli_query($dbh->link,$sql_blogs);
$no_of_blogs = mysqli_num_rows($result_blogs);

if($no_of_blogs>0)
{
	
	$flag= 1;
	$rw_blogs = mysqli_fetch_array($result_blogs);
	
	$blog_id         = $rw_blogs['blog_id'];
	$blog_title      = $rw_blogs['blog_title'];
	$blog_pre_desc   = $rw_blogs['blog_pre_desc'];
	$blog_desc       = $rw_blogs['blog_desc'];
	$written_by      = $rw_blogs['written_by'];
	$posting_dt      = $rw_blogs['posting_dt'];
	$blog_image_path = $rw_blogs['blog_image_path'];
	$meta_title      = $rw_blogs['meta_title'];
	$meta_desc       = $rw_blogs['meta_desc'];
	$og_title        = $rw_blogs['og_title'];
	$og_desc         = $rw_blogs['og_desc'];
	
	//echo "blog_desc = ".$blog_desc;
	//return;
	//  $blog_title_url = str_replace(" ","-",$blog_title); 
	//  $blog_title_url = str_replace("&","-",$blog_title_url); 
	//  $blog_title_url = str_replace("(","",$blog_title_url); 
	//  $blog_title_url = str_replace(")","",$blog_title_url); 
	//  $blog_title_url = str_replace("?","",$blog_title_url);
	//  $blog_title_url = str_replace(":","",$blog_title_url);
	//  $blog_title_url = str_replace("'","",$blog_title_url);
	//  $blog_title_url = str_replace("!","",$blog_title_url);
	//  $blog_title_url = str_replace(";","",$blog_title_url);
	//  $blog_title_url = str_replace("_","",$blog_title_url);
	//  $blog_title_url = str_replace("–","",$blog_title_url);
	//  $blog_title_url = str_replace("/","",$blog_title_url);
	//  $blog_title_url = str_replace(",","",$blog_title_url);
	//  $blog_title_url = str_replace("’","",$blog_title_url);
	    $blog_title_url = createSlug($blog_title);
		
}
else
{
 $flag = 0;
 $msg = "No Blogs Found";	
}
//==================================================================================================================
//fetching latest blogs from database
$sql_blogs2 = "select * from tbl_blogs ";
$sql_blogs2 = $sql_blogs2 . " where status = 'ACTIVE' and blog_type = 'SEN-Intl' and deleted = 0 ";
//if($blogs != "")
//{
//	$sql_blogs2 = $sql_blogs2 . " and blog_title like '%".$blogs."%'";
//}
$sql_blogs2 = $sql_blogs2 . " order by posting_dt DESC, blog_id DESC ";
//echo "sql_blogs2=".$sql_blogs2;
$result_blogs2 = mysqli_query($dbh->link,$sql_blogs2);

if($result_blogs2)
{
	$no_of_blogs = mysqli_num_rows($result_blogs2);
	
	for($i=0; $i<$no_of_blogs; $i++)
	{
		$rw_blogs2 = mysqli_fetch_array($result_blogs2);
		
		$blog_id2[$i]         = $rw_blogs2['blog_id'];
		$blog_title2[$i]      = $rw_blogs2['blog_title'];
		
	}	
}

?>