| Server IP : 103.48.194.25 / Your IP : 216.73.217.98 Web Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux VMHostDefault 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 User : sieuthimay ( 1016) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/zomuaban.com/public_html/site/controllers/frontend/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Post extends MY_Controller {
public $intro;
public function __construct() {
parent::__construct();
$this->load->model('post_model');
$this->load->helper('post_helper');
loadlang('blog');
$this->intro = lang('blog_intro');
}
public function index($cate = null) {
if (isset($cate))$cate = $this->post_model->get_cate_from_alias($cate);
# DANH MỤC :: Lấy các post trong một cate
if (isset($cate) && $cate!=false ) {
$posts = $this->post_model->get_post_by_cate($cate->id, 20);
$this->data['posts'] = [];
foreach($posts as $post) {
array_push($this->data['posts'],$post);
}
$this->data['curtag'] = $cate;
$this->data['curcate'] = $cate;
#TITLE and DESCRIPTION
$this->data['title'] = $cate->name .' – '. siteConf('siteName').'.com';
$this->data['description'] = $cate->desc;
}
# TRANG HOM :: Lấy tất cả bài post
else {
$this->data['posts'] = $this->post_model->get_all_post();
#TITLE and DESCRIPTION
$this->data['title'] = 'Blog – '.siteConf('siteName').'.com';
$this->data['description'] = $this->intro;
}
$this->data['fbmeta'] = array( 'title' => $this->data['title'],
'url' => $this->data['canonical'],
'image' => drive_host('assets/blog/banner.jpg'),
'description' => $this->data['description']
);
#loadlang();
$this->render('', 'post');
}
public function post_in_tag($tag = null) {
if (!isset($tag)) redirect(url_post());
$tags = $this->post_model->get_post_by_tags($tag, 20);
if($tags){
$this->data['posts'] = $tags;
$this->data['curtag'] = get_tag_by_alias($tag);
$this->data['curcate'] = get_blog_cate_by_id($this->data['curtag']->cate);
$this->data['title'] = $this->data['curtag']->name .' – '.siteConf('siteName').'.com';
}else {
$this->data['posts'] = array();
$this->data['title'] = $tag .' – '.siteConf('siteName').'.com';
}
$this->data['fbmeta'] = array(
'title' => $this->data['title'],
'image' => drive_host('assets/blog/banner.jpg'),
);
#loadlang();
$this->render('post', 'post');
}
public function create() {
# redirect sang trang chinh
if (!allow_post()) redirect(url_post());
$post = new stdClass;
$post->id = '';
$post->title = '';
$post->desc = '';
$post->thumb = 'https://googledrive.com/host/_ID_cua_hinh_tren_drive';
$post->allowCmt = 1;
$post->active = 0;
$post->pined = 0;
$post->cate = get_blog_cate_by_id(0);
$post->tags = '';
$post->content = '<small>Nội dung bài viết</small><br/><br/><br/><br/><br/>';
$this->data['post'] = $post;
$this->render('', 'post');
}
public function detail($postId){
$post = $this->post_model->get_post_by_id($postId);
if (!$post) redirect(url_post());
$this->data['post'] = $post;
# Tìm những bài viết đã xem trong ngày & cập nhật view cho bài post luôn
$readed_postIds = $this->post_model->update_viewed_post($post->id);
#Tìm những bài viết cùng tag
$this->data['relate'] = $this->post_model->get_post_by_tags($post->tags);
# SET META
$this->data['title'] = $post->title .' – ' . siteConf('siteName').'.com';
$this->data['description'] = $post->desc;
$this->data['meta'] = array( array('name' => 'description', 'content' =>$post->desc));
$this->data['fbmeta'] = array( 'title' => $post->title,
'url' => $post->alias,
'image' => $post->thumb = !empty($post->thumb) ? $post->thumb : blog_banner(),
'description' => $post->desc
);
#$this->data['curtag'] = $post->tags;
$this->data['curcate'] = $post->cate;
$this->render('', 'post');
}
# URL chỉnh sửa tin đăng > render cùng giao diện với tin mới
public function edit($postId) {
# Không có quyền > redirect về trang HOME BLOGS
if (!allow_post()) redirect(url_post());
# Kiểm tra bài post có tồn tại
$post = $this->post_model->get_post_by_id($postId);
$post->thumb = !empty($post->thumb) ? $post->thumb : 'https://googledrive.com/host/_ID_cua_hinh_tren_drive';
if ($post) {
$this->data['post'] = $post;
$this->render('post_create', 'post');
}else {
redirect(url_post());
}
}
public function ajax_create_post() {
$pData = ajax_safe_get();
if (!allow_post()) {
$this->setErr('Không có quyền đăng tin');
echo json_encode($this->getState());
}
# Xác định short description
$pData->desc = empty($pData->desc) ? item_short_desc($pData->content) : $pData->desc;
# Cập nhật lần cuối
$pData->lastestUpdate = now();
# Làm mới bài viết
if($pData->renew){
$pData->create_time = now();
}
unset($pData->renew); # Xóa giá trị này
#Chèn tag alias
$tags = explode(',', $pData->tags);
$pData->tags = '';
foreach($tags as $tg){
$pData->tags .= $pData->tags == '' ? alias($tg) : ','.alias($tg);
}
#Update bài viết
if ($pData->id) {
$this->db->update(tableConf('blog'), $pData, array('id' => $pData->id));
# TODO:Check owner hoặc Admin
$this->setMsg(url_post_detail($pData));
}
# Đăng bài viết mới
else {
# xác định thời gian
$pData->create_time = now();
# Tác giả bài viết
$pData->author = mine()->name;
$this->db->insert(tableConf('blog'), $pData);
$pData->id = $this->db->insert_id();
if ($pData->id > 0) {
$this->setMsg(url_post_detail($pData));
}else {
$this->setErr('Lỗi khi đăng tin');
}
}
echo json_encode($this->getState());
}
# Gọi Ajax update lại view cho post
public function ajax_update_post_view(){
$pData = ajax_safe_get();
$this->db->set('totalView', 'totalView+1',FALSE);
$this->db->where('id', $pData->id);
$this->db->update(tableConf('blog'));
$this->setMsg('updated post view');
echo json_encode($this->getState());
}
# Gọi Ajax update lại view cho post
public function ajax_get_tag_ahead(){
$pData = ajax_safe_get();
# Chia thành nhiều từ nhỏ
$words = alias($pData->keyword);
$words = explode(' ', $words);
$this->db->like('alias', alias($pData->keyword));
/*foreach($words as $w){
if(!empty($w))$this->db->or_like('alias', $w);
} */
$this->db->select('name as name, alias as value');
$query= $this->db->get(tableConf('blogtags'));
echo json_encode($query->result());
}
# Gọi Ajax để tạo thêm một tag
public function ajax_create_tag(){
$pData = ajax_safe_get();
# Xóa hết kí tự đặt biệt, khoảng trắng ...
$pData->name = vn_clear_string($pData->name);
# Tạo alias (lọc tiếng việt, thay khoảng trắng bằng - )
$pData->alias = alias($pData->name);
# Xem đã tồn tại chưa
$this->db->where('alias', $pData->alias);
$q = $this->db->get(tableConf('blogtags'));
# Nếu chưa thì insert
if ($q->num_rows() == 0) {
$this->db->insert(tableConf('blogtags'), array( 'name' => $pData->name,
'alias' => $pData->alias,
'cate' => $pData->cate
)
);
$this->setMsg('done');
}else{
$this->setErr('exist');
}
echo json_encode($this->getState());
}
}