|
Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/angkasapuraretail.com/public_html/application/modules/blog/controllers/ |
Upload File : |
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Blog extends Public_Controller {
public function __construct() {
parent::__construct();
}
public function frontpage() {
//get all blogs for frontpage
$this->db->select('blog, alias, publish_date, image1,image2, description')->from('blog')->where('status', '1')->order_by('publish_date', 'DESC')->limit(3);
$data['blogs'] = $this->db->get()->result();
$this->load->view("$this->theme_no/blog-landing", $data);
}
public function all() {
//get all blogs
$this->db->select('*')->from('blog')->where('status', '1')->order_by('publish_date', 'DESC');
$data['blogs'] = $this->db->get()->result();
$this->db->select('website_name, blog_landingpage_image')->from('configuration')->where('id_configuration', 1);
$website_name = $this->db->get()->row();
$data['banner'] = $website_name->blog_landingpage_image;
//get SEO
$this->data_header['browser_title'] = ucwords($website_name->website_name) . '- Blog';
$this->data_header['meta_description'] = ucwords($website_name->website_name) . '- Blog';
$this->load->view("themes/$this->theme_no/header", $this->data_header);
$this->load->view("$this->theme_no/blogs", $data);
$this->load->view("themes/$this->theme_no/footer", $this->data_footer);
}
public function category($type) {
//get all blogs
$this->db->select('*')->from('blog')->where('status', '1')->where('category', $type)->order_by('publish_date', 'DESC');
$data['blogs'] = $this->db->get()->result();
$this->db->select('website_name')->from('configuration')->where('id_configuration', 1);
$website_name = $this->db->get()->row();
//get SEO
$this->data_header['browser_title'] = ucwords($website_name->website_name) . '- News';
$this->data_header['meta_description'] = ucwords($website_name->website_name) . '- News';
$this->load->view("themes/$this->theme_no/header", $this->data_header);
$this->load->view("$this->theme_no/blog-landing", $data);
$this->load->view("themes/$this->theme_no/footer", $this->data_footer);
}
public function get($alias = NULL) {
if ($alias == NULL) { show_404(); }
//the script belows account if user share a link to outside user. to find the blog article in different language, to avoid 404 page not found in different language
if($this->session->userdata('site_lang') == 'english') {
//check if blog exist in english alias
$this->db->select('blog_en as blog, publish_date, image2, description_en as description')->from('blog')->where('alias_en', $alias)->where('status', 1);
$blog_en = $this->db->get()->row();
if(count($blog_en) == 0) {
//blog not exist in english alias. So check to indonesian
$this->db->select('blog, publish_date, image2, description')->from('blog')->where('alias', $alias)->where('status', 1);
$blog_id = $this->db->get()->row();
if(count($blog_id) == 0) {
show_404();
} else {
$data['blog'] = $blog_id;
//change the website session language to indonesian
$this->session->set_userdata('site_lang', 'indonesian');
$this->lang->load('blog','indonesian');
}
} else {
$data['blog'] = $blog_en;
//change the website session language to english
$this->session->set_userdata('site_lang', 'english');
$this->lang->load('blog','english');
}
} else {
//check if blog exist in indonesian alias
$this->db->select('blog, publish_date, image2, description')->from('blog')->where('alias', $alias)->where('status', 1);
$blog_id = $this->db->get()->row();
if(count($blog_id) == 0) {
//blog not exist in indonesian alias. So check to english
$this->db->select('blog_en as blog, publish_date, image2, description_en as description')->from('blog')->where('alias_en', $alias)->where('status', 1);
$blog_en = $this->db->get()->row();
if(count($blog_en) == 0) {
show_404();
} else {
//blog exist in english. get blog parameter
$data['blog'] = $blog_en;
$this->lang->load('blog','english');
}
} else {
//blog exist in indonesian alias. get blog parameter
$data['blog'] = $blog_id;
$this->lang->load('blog','indonesian');
}
}
//get all blogs with limit to 10 blogs for the side coloumn
$this->db->select('*')->from('blog')->where('status', '1')->order_by('publish_date', 'DESC')->limit(10);
$data['blogs'] = $this->db->get()->result();
//get recent articles
$this->db->select('*')->from('blog')->where('status', '1')->order_by('publish_date', 'DESC')->limit(5);
$data['recent_articles'] = $this->db->get()->result();
//get featured articles
$this->db->select('*')->from('blog')->where('status', '1')->where('featured', 'yes')->order_by('publish_date', 'DESC');
$data['featured_blogs'] = $this->db->get()->result();
/*get archive*/
$this->db->select('*')->from('blog')->where('status', '1')->order_by('publish_date','DESC');
$archive = $this->db->get()->result();
$final_name_archive = array();
foreach ($archive as $item) {
$month_year = date("F Y", strtotime($item->publish_date));
$count = 1;
foreach ($archive as $item1) {
if($item1->id_blog != $item->id_blog){
$current_month = date("F Y", strtotime($item->publish_date));
$month = date("F Y", strtotime($item1->publish_date));
if($current_month == $month){
$count = $count + 1;
}
}
}
$final_count = " (".$count.")";
$final_string = $month_year.$final_count;
if(!in_array($final_string, $final_name_archive)){
$final_name_archive[]= $final_string;
$final_archive[] = array(
'link' => date("Y", strtotime($item->publish_date)).'/'.date("m", strtotime($item->publish_date)),
'name' => $final_string,
);
}
}
$data['archive'] = $final_archive;
//get SEO
$this->data_header['browser_title'] = 'News - ' . ucwords($data['blog']->blog);
$this->data_header['meta_description'] = 'News - ' . ucwords($data['blog']->blog);
$this->load->view("themes/$this->theme_no/header", $this->data_header);
$this->load->view("$this->theme_no/blog_detail", $data);
$this->load->view("themes/$this->theme_no/footer", $this->data_footer);
}
public function archive($years = null, $month = null) {
if(($years == null) || ($month == null)){
redirect('blog/all');
}
$publish_date_search = $years.'-'.$month;
//get all blogs
$this->db->select('*')->from('blog')->where('status', '1')->like('publish_date',$publish_date_search)->order_by('publish_date', 'DESC');
$data['blogs'] = $this->db->get()->result();
//get featured articles
$this->db->select('*')->from('blog')->where('status', '1')->where('featured', 'yes')->order_by('publish_date', 'DESC');
$data['featured_blogs'] = $this->db->get()->result();
//get recent articles
$this->db->select('*')->from('blog')->where('status', '1')->order_by('publish_date', 'DESC')->limit(5);
$data['recent_articles'] = $this->db->get()->result();
/*get archive*/
$this->db->select('*')->from('blog')->where('status', '1')->order_by('publish_date','DESC');
$archive = $this->db->get()->result();
$final_name_archive = array();
foreach ($archive as $item) {
$month_year = date("F Y", strtotime($item->publish_date));
$count = 1;
foreach ($archive as $item1) {
if($item1->id_blog != $item->id_blog){
$current_month = date("F Y", strtotime($item->publish_date));
$month = date("F Y", strtotime($item1->publish_date));
if($current_month == $month){
$count = $count + 1;
}
}
}
$final_count = " (".$count.")";
$final_string = $month_year.$final_count;
if(!in_array($final_string, $final_name_archive)){
$final_name_archive[]= $final_string;
$final_archive[] = array(
'link' => date("Y", strtotime($item->publish_date)).'/'.date("m", strtotime($item->publish_date)),
'name' => $final_string,
);
}
}
$data['archive'] = $final_archive;
//get blog promotion banners
$this->db->select('*')->from('promo_banners')->where('status', 'yes')->order_by('priority', 'ASC');
$data['banners'] = $this->db->get()->result();
//get SEO
$this->db->select('website_name')->from('configuration')->where('id_configuration', 1);
$website_name = $this->db->get()->row();
$this->data_header['browser_title'] = ucwords($website_name->website_name) . '- Blog';
$this->data_header['meta_description'] = ucwords($website_name->website_name) . '- Blog';
$this->load->view("themes/$this->theme_no/header", $this->data_header);
$this->load->view("$this->theme_no/blog-landing", $data);
$this->load->view("themes/$this->theme_no/footer", $this->data_footer);
}
}