first commit
This commit is contained in:
59
application/models/Category_model.php
Executable file
59
application/models/Category_model.php
Executable file
@@ -0,0 +1,59 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
|
||||
class Category_model extends MY_Model
|
||||
{
|
||||
private $table = 'cm_category';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getOne($categoryId)
|
||||
{
|
||||
return get_instance()->db->where_in('categoryID', $categoryId)->get('cm_category')->row();
|
||||
}
|
||||
|
||||
public function getAll($categoryId)
|
||||
{
|
||||
$categoryId = is_array($categoryId) ? $categoryId : [$categoryId];
|
||||
return get_instance()->db->where_in('categoryID', $categoryId)->get('cm_category')->result();
|
||||
}
|
||||
|
||||
public function getSubcategoriesByCategoryId(int $categoryId) {
|
||||
return $this->db->where('parentID', $categoryId)->get('cm_category')->result();
|
||||
}
|
||||
|
||||
public function getTableCategoryTitle(&$rows)
|
||||
{
|
||||
$categories = get_instance()->db->get('cm_category')->result();
|
||||
array_map(function ($r) use (&$rows, $categories) {
|
||||
foreach ($rows as $k => $row) {
|
||||
if ($row['postID'] == $r->postID) {
|
||||
$rows[$k]['categoryID'] = $r->categoryID;
|
||||
$rows[$k]['categories'][] = $r->categoryID;
|
||||
foreach ($categories as $c) {
|
||||
if ($c->categoryID == $r->categoryID) {
|
||||
$rows[$k]['categoryTitle'] = (empty($rows[$k]['categoryTitle']) ? '' : $rows[$k]['categoryTitle'] . ', ') . $c->categoryTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, $this->getPostCategoryByPostIdIn(array_column($rows, 'postID')));
|
||||
}
|
||||
|
||||
private function getPostCategoryByPostIdIn($postIds)
|
||||
{
|
||||
if (count($postIds) == 0) return [];
|
||||
return $this->db->from('cm_post_category pc')->where_in('pc.postID', $postIds)->get()->result();
|
||||
}
|
||||
|
||||
public function getCategoriesBySlug($slug) {
|
||||
$slug = is_array($slug) ? $slug : [$slug];
|
||||
return $this->db->where_in('categorySlug', $slug)->from($this->table);
|
||||
}
|
||||
|
||||
}
|
||||
332
application/models/Cmap_model.php
Executable file
332
application/models/Cmap_model.php
Executable file
@@ -0,0 +1,332 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/Hoosk_model.php';
|
||||
|
||||
class Cmap_model extends Hoosk_model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/* * *************************** */
|
||||
/* * ** Setting Role Querys ************ */
|
||||
/* * *************************** */
|
||||
public function countRoles()
|
||||
{
|
||||
return $this->db->count_all('cm_setting_roles');
|
||||
}
|
||||
|
||||
public function getRoles($limit, $offset = 0)
|
||||
{
|
||||
// Get a list of all user accounts
|
||||
$query = $this->db->order_by("created_at", "desc")
|
||||
->limit($limit, $offset)->get('cm_setting_roles');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getRole($id)
|
||||
{
|
||||
// Get the user details
|
||||
$query = $this->db->where("roleID", $id)->get('cm_setting_roles');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function createRole()
|
||||
{
|
||||
// Create the user account
|
||||
$data = array(
|
||||
'name' => $this->input->post('name'),
|
||||
'slug' => $this->input->post('slug')
|
||||
);
|
||||
$this->db->insert('cm_setting_roles', $data);
|
||||
}
|
||||
|
||||
public function updateRole($id)
|
||||
{
|
||||
// update the user account
|
||||
$data = array(
|
||||
'name' => $this->input->post('name'),
|
||||
'slug' => $this->input->post('slug')
|
||||
);
|
||||
$this->db->where('roleID', $id);
|
||||
$this->db->update('cm_setting_roles', $data);
|
||||
}
|
||||
|
||||
public function removeRole($id)
|
||||
{
|
||||
// Delete a user account
|
||||
$this->db->delete('cm_setting_roles', array('roleID' => $id));
|
||||
}
|
||||
|
||||
function roleSearch($term)
|
||||
{
|
||||
$this->db->select("*");
|
||||
$this->db->like("name", $term);
|
||||
// $this->db->limit($limit, $offset);
|
||||
$query = $this->db->get('cm_setting_roles');
|
||||
if ($term == "") {
|
||||
$this->db->limit(15);
|
||||
}
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $r) :
|
||||
echo '<tr>';
|
||||
echo '<td>' . $r['name'] . '</td>';
|
||||
echo '<td>' . $r['slug'] . '</td>';
|
||||
echo '<td>' . $r['created_at'] . '</td>';
|
||||
echo '<td class="td-actions"><a href="' . BASE_URL . '/admin/settings/roles/edit/' . $r['roleID']
|
||||
. '" class="btn btn-small btn-success"><i class="fa fa-pencil"> '
|
||||
. '</i></a> <a data-toggle="modal" data-target="#ajaxModal" class="btn btn-danger btn-small" href="'
|
||||
. BASE_URL . '/admin/settings/roles/delete/' . $r['roleID'] . '"><i class="fa fa-remove"> </i></a></td>';
|
||||
echo '</tr>';
|
||||
echo '</tr>';
|
||||
endforeach;
|
||||
} else {
|
||||
echo "<tr><td colspan='5'><p>" . $this->lang->line('no_results') . "</p></td></tr>";
|
||||
}
|
||||
}
|
||||
|
||||
public function categorySearch($term)
|
||||
{
|
||||
$this->load->helper('sql_search');
|
||||
$this->db->from('cm_category');
|
||||
$this->db->select("*");
|
||||
$this->db->like("categoryTitle", $term);
|
||||
$query = $this->db->query($this->db->get_compiled_select() . ' or ' . getSqlCho('categoryTitle', $term));
|
||||
if ($term == "") {
|
||||
$this->db->limit(15);
|
||||
}
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $p) :
|
||||
echo '<tr>';
|
||||
echo '<td>' . $p['categoryTitle'] . '</td>';
|
||||
echo '<td class="td-actions"><a href="' . BASE_URL . '/admin/posts/categories/edit/' . $p['categoryID'] . '" class="btn btn-small btn-success"><i class="fa fa-pencil"> </i></a> <a data-toggle="modal" data-target="#ajaxModal" class="btn btn-danger btn-small" href="' . BASE_URL . '/admin/posts/categories/delete/' . $p['categoryID'] . '"><i class="fa fa-remove"></i></a></td>';
|
||||
echo '</tr>';
|
||||
endforeach;
|
||||
} else {
|
||||
echo "<tr><td colspan='5'><p>" . $this->lang->line('no_results') . "</p></td></tr>";
|
||||
}
|
||||
}
|
||||
|
||||
public function countUsers()
|
||||
{
|
||||
$term = getSearchTerm();
|
||||
return $this->db->from('cm_user u')->select("userName, r.name groupName, email, userID")
|
||||
->join('cm_setting_roles r', 'u.roleID = r.roleID', 'left')
|
||||
->like("userName", $term)
|
||||
->or_like('r.name', $term)->count_all_results();
|
||||
}
|
||||
|
||||
public function getUsers($limit, $offset = 0)
|
||||
{
|
||||
// Get a list of all user accounts
|
||||
$term = getSearchTerm();
|
||||
$this->load->helper('sql_search');
|
||||
$query = $this->db->from('cm_user u')->select("userName, if(r.name is Null, 'None', r.name) groupName, email, userID")
|
||||
->join('cm_setting_roles r', 'u.roleID = r.roleID', 'left')
|
||||
->like("userName", $term)
|
||||
->or_like('r.name', $term);
|
||||
$query = $this->db->query($this->db->get_compiled_select() . ($term ? ' or ' . getSqlCho('userName', $term) : '') . ' order by u.dateUpdated desc');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function userSearch($term)
|
||||
{
|
||||
$this->load->helper('sql_search');
|
||||
$query = $this->db->from('cm_user u')->select("userName, r.name groupName, email, userID")
|
||||
->join('cm_setting_roles r', 'u.roleID = r.roleID', 'left')
|
||||
->like("userName", $term)
|
||||
->or_like('r.name', $term);
|
||||
$query = $this->db->query($this->db->get_compiled_select() . ($term ? ' or ' . getSqlCho('userName', $term) : '') . ' order by u.dateUpdated desc');
|
||||
if ($term == "") {
|
||||
$this->db->limit(15);
|
||||
}
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u) :
|
||||
echo '<tr>';
|
||||
echo '<td>' . $u['userName'] . '</td>';
|
||||
echo '<td>' . $u['groupName'] . '</td>';
|
||||
echo '<td>' . $u['email'] . '</td>';
|
||||
echo '<td class="td-actions"><a href="' . BASE_URL . '/admin/users/edit/' . $u['userID'] . '" class="btn btn-small btn-success"><i class="fa fa-pencil"> </i></a> <a data-toggle="modal" data-target="#ajaxModal" class="btn btn-danger btn-small" href="' . BASE_URL . '/admin/users/delete/' . $u['userID'] . '"><i class="fa fa-remove"> </i></a></td>';
|
||||
echo '</tr>';
|
||||
endforeach;
|
||||
} else {
|
||||
echo "<tr><td colspan='5'><p>" . $this->lang->line('no_results') . "</p></td></tr>";
|
||||
}
|
||||
}
|
||||
|
||||
protected function addPostCategory($postID, $categories)
|
||||
{
|
||||
$tmp = [];
|
||||
$this->db->where('postID', $postID)->delete('cm_post_category');
|
||||
if (count($categories)) {
|
||||
return $this->db->insert_batch('cm_post_category', array_filter(array_map(function ($category) use ($postID) {
|
||||
return ['postID' => $postID, 'categoryID' => $category];
|
||||
}, $categories), function ($c) use (&$tmp) {
|
||||
$isDup = $c['categoryID'] ? false : true;
|
||||
if (!$isDup) {
|
||||
foreach ($tmp as $t) {
|
||||
if ($t['categoryID'] == $c['categoryID']) {
|
||||
$isDup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
array_push($tmp, $c);
|
||||
if (!$isDup) {
|
||||
return $c;
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
protected function addPostPage($postID, $pages)
|
||||
{
|
||||
$tmp = [];
|
||||
$this->db->where('postID', $postID)->delete('cm_post_page');
|
||||
if (count($pages)) {
|
||||
return $this->db->insert_batch('cm_post_page', array_filter(array_map(function ($page) use ($postID) {
|
||||
return ['postID' => $postID, 'pageID' => $page];
|
||||
}, $pages), function ($c) use (&$tmp) {
|
||||
$isDup = $c['pageID'] ? false : true;
|
||||
if (!$isDup) {
|
||||
foreach ($tmp as $t) {
|
||||
if ($t['pageID'] == $c['pageID']) {
|
||||
$isDup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
array_push($tmp, $c);
|
||||
if (!$isDup) {
|
||||
return $c;
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public function getPostByCategoryId($categoryID, $limit = 15, $offset = 0)
|
||||
{
|
||||
$rows = [];
|
||||
$this->db->select("cm_post.*, cm_category.categoryTitle");
|
||||
$this->db->where("cm_category.categoryID", $categoryID);
|
||||
$this->db->join('cm_category', 'cm_category.categoryID = cm_post.categoryID or cm_post.categoryID = 0', 'left');
|
||||
$this->db->order_by("cm_post.postID", "desc");
|
||||
$this->db->limit($limit, $offset);
|
||||
return $this->db->get('cm_post')->result();
|
||||
}
|
||||
|
||||
public function getPostByPageId($pageID, $limit = 15, $offset = 0)
|
||||
{
|
||||
$rows = [];
|
||||
$this->db->select("cm_post.*, cm_category.categoryTitle");
|
||||
if (is_array($pageID)) {
|
||||
$this->db->where_in('cm_post.pageID', $pageID);
|
||||
} else {
|
||||
$this->db->where('cm_post.pageID', $pageID);
|
||||
}
|
||||
$this->db->join('cm_category', 'cm_category.categoryID = cm_post.categoryID or cm_post.categoryID = 0', 'left');
|
||||
$this->db->order_by("cm_post.postID", "desc");
|
||||
$this->db->group_by("cm_post.postID");
|
||||
$this->db->limit($limit, $offset);
|
||||
return $this->db->get('cm_post')->result();
|
||||
}
|
||||
|
||||
public function createUser()
|
||||
{
|
||||
// Create the user account
|
||||
$data = array(
|
||||
'userName' => $this->input->post('username'),
|
||||
'email' => $this->input->post('email'),
|
||||
'password' => md5($this->input->post('password') . SALT),
|
||||
'roleID' => $this->input->post('role'),
|
||||
'name' => $this->input->post('name'),
|
||||
'gender' => $this->input->post('gender'),
|
||||
'mobile' => $this->input->post('mobile')
|
||||
);
|
||||
$this->db->insert('cm_user', $data);
|
||||
}
|
||||
|
||||
public function updateUser($id)
|
||||
{
|
||||
// update the user account
|
||||
$data = array(
|
||||
'email' => $this->input->post('email'),
|
||||
'email' => $this->input->post('email'),
|
||||
'roleID' => $this->input->post('role'),
|
||||
'name' => $this->input->post('name'),
|
||||
'gender' => $this->input->post('gender'),
|
||||
'mobile' => $this->input->post('mobile')
|
||||
);
|
||||
|
||||
if ($this->input->post('password')) {
|
||||
$data['password'] = md5($this->input->post('password') . SALT);
|
||||
}
|
||||
|
||||
$this->db->where('userID', $id);
|
||||
$this->db->update('cm_user', $data);
|
||||
}
|
||||
|
||||
public function createPost()
|
||||
{
|
||||
$categoryID = 0;
|
||||
$data = array(
|
||||
'postTitle' => $this->input->post('postTitle'),
|
||||
'categoryID' => $categoryID,
|
||||
// 'postURL' => $this->input->post('postURL'),
|
||||
// 'postContent' => $this->input->post('content'),
|
||||
'postContentHTML' => $this->input->post('content'),
|
||||
'postExcerpt' => $this->input->post('postExcerpt'),
|
||||
'published' => $this->input->post('published'),
|
||||
'datePosted' => date('Y-m-d H:i:s', strtotime($this->input->post('datePosted'))),
|
||||
'dateUpdated' => date('Y-m-d H:i:s'),
|
||||
'unixStamp' => $this->input->post('unixStamp'),
|
||||
);
|
||||
if ($this->input->post('postImage') != "") {
|
||||
$data['postImage'] = $this->input->post('postImage');
|
||||
}
|
||||
$this->db->insert('cm_post', $data);
|
||||
$insertID = $this->db->insert_id();
|
||||
|
||||
$this->addPostCategory($insertID, $this->input->post('categories') ? explode(',', $this->input->post('categories')) : []);
|
||||
$this->addPostPage($insertID, $this->input->post('pages') ? explode(',', $this->input->post('pages')) : []);
|
||||
$this->db->where('postID', $insertID)->update('cm_post', array('postURL' => $insertID));
|
||||
}
|
||||
|
||||
|
||||
public function updatePost($id)
|
||||
{
|
||||
$categoryID = 0;
|
||||
$this->addPostCategory($id, $this->input->post('categories') ? explode(',', $this->input->post('categories')) : []);
|
||||
$this->addPostPage($id, $this->input->post('pages') ? explode(',', $this->input->post('pages')) : []);
|
||||
|
||||
$data = array(
|
||||
'postTitle' => $this->input->post('postTitle'),
|
||||
'categoryID' => $categoryID,
|
||||
// 'postURL' => $this->input->post('postURL'),
|
||||
'postContentHTML' => $this->input->post('content'),
|
||||
'postExcerpt' => $this->input->post('postExcerpt'),
|
||||
'published' => $this->input->post('published'),
|
||||
'datePosted' => date('Y-m-d H:i:s', strtotime($this->input->post('datePosted'))),
|
||||
'dateUpdated' => date('Y-m-d H:i:s'),
|
||||
'unixStamp' => $this->input->post('unixStamp'),
|
||||
);
|
||||
if ($this->input->post('postImage') != "") {
|
||||
$data['postImage'] = $this->input->post('postImage');
|
||||
}
|
||||
$this->db->where("postID", $id);
|
||||
$this->db->update('cm_post', $data);
|
||||
}
|
||||
}
|
||||
270
application/models/Cmap_page_model.php
Executable file
270
application/models/Cmap_page_model.php
Executable file
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/Hoosk_page_model.php';
|
||||
|
||||
class Cmap_page_model extends Hoosk_page_model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getPageDelivery($pageID)
|
||||
{
|
||||
$this->db->join('cm_page_attributes', 'cm_page_attributes.pageID=cm_delivery.pageID');
|
||||
return $this->db->where('cm_page_attributes.pageID', $pageID)->get('cm_delivery')->result();
|
||||
}
|
||||
|
||||
public function getPostByParentCategoryId($parentID, $limit = 10, $offset = 0)
|
||||
{
|
||||
$rows = $this->db
|
||||
->select('p.*,c.categorySlug')
|
||||
->join('cm_category c', 'p.categoryID=c.categoryID', 'left')
|
||||
->where('c.parentID', $parentID)
|
||||
// ->where('p.published', 1)
|
||||
->limit($limit)->offset($offset)
|
||||
->order_by('p.datePosted', 'desc')
|
||||
->get('cm_post p')->result();
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public function getPagePostByParentCategoryId($parentID, $limit = 10, $offset = 0, $popular = '')
|
||||
{
|
||||
if (!empty($popular)) {
|
||||
$this->db->join('cm_post_ranking pr', "p.postID=pr.postID and pr.title='$popular'", 'left')->order_by('pr.rating');
|
||||
} else {
|
||||
$this->db->order_by('p.dateUpdated', 'desc');
|
||||
}
|
||||
return $this->db
|
||||
->select('p.*, pc.*, pa.pageURL, pc.pageTitle, pa.pageIcon')
|
||||
->join('cm_category c', 'c.categoryID=p.categoryID or p.categoryID=0', 'left')
|
||||
->join('cm_page_attributes pa', 'c.categoryID=pa.categoryID and p.pageID=pa.pageID', 'left')
|
||||
->join('cm_page_content pc', 'pa.pageID=pc.pageID', 'left')
|
||||
->where("pa.pagePublished", 1)
|
||||
->where('p.published', 1)
|
||||
->group_by('p.pageID')
|
||||
->limit($limit)->offset($offset)
|
||||
->get('cm_post p')->result();
|
||||
}
|
||||
|
||||
public function getReporterByPostId($postId)
|
||||
{
|
||||
return $this->db->where('postID', $postId)->select('r.*, p.press_name, p.logo_img, p.homepage')
|
||||
->join('cm_press p', 'r.pressID=p.pressID', 'left')
|
||||
->get('cm_post_reporter r')->row();
|
||||
}
|
||||
|
||||
public function getRankingByPostId($postId)
|
||||
{
|
||||
$ranking = ['V' => 0, 'R' => 0, 'L' => 0];
|
||||
$rows = $this->db->where('postID', $postId)
|
||||
->get('cm_post_ranking')->result();
|
||||
foreach ($rows as $row) {
|
||||
foreach ($ranking as $k => $r) {
|
||||
if ($row->title == $k) {
|
||||
$ranking[$k] = $row->rating;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ranking;
|
||||
}
|
||||
|
||||
public function getPagePostByCategoryId($categoryID)
|
||||
{
|
||||
$posts = [];
|
||||
$recentUpdatedPosts = $this->db->where('categoryID', $categoryID)->get('cm_page_attributes')->result();
|
||||
foreach ($recentUpdatedPosts as $p) {
|
||||
array_push($posts, $this->db
|
||||
->select('p.*, pc.*, pa.pageURL, pc.pageTitle, pa.pageIcon')
|
||||
->join('cm_page_attributes pa', 'p.pageID=pa.pageID', 'left')
|
||||
->join('cm_page_content pc', 'pa.pageID=pc.pageID', 'left')
|
||||
->where("pa.pagePublished", 1)
|
||||
->where('p.pageID', $p->pageID)->where('p.published', 1)->limit(4)->order_by('p.dateUpdated', 'desc')
|
||||
->get('cm_post p')->result());
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
public function getColumn($limit = 2, $offset = 0)
|
||||
{
|
||||
return $this->db->limit($limit)->join('cm_user u', 'u.userID = p.userID', 'left')
|
||||
->join('cm_user_group g', 'u.groupID = g.groupID', 'left')->where('g.groupID', 7)
|
||||
->order_by('datePosted', 'desc')->get('cm_post p')->result();
|
||||
}
|
||||
|
||||
public function getToonSeries($seriesURL)
|
||||
{
|
||||
return $this->db->select("cm_post.*, cm_user.name")
|
||||
->join(
|
||||
'cm_post_category',
|
||||
'cm_post.postID = cm_post_category.postID',
|
||||
'inner'
|
||||
)
|
||||
->where('cm_post_category.categoryID', $seriesURL)
|
||||
->get('cm_post')->result();
|
||||
}
|
||||
|
||||
public function getPostRanking($title = 'V', $categoryID = 0, $exception = [], $limit = 8, $series = 0, $parentID = 0, $isPostCategoryRequired = false)
|
||||
{
|
||||
$this->db->select("cm_post.*, cm_user.name, cm_page_content.pageTitle,
|
||||
UNIX_TIMESTAMP(datePosted) postedTimestamp, cm_post_ranking.rating, cm_category.categorySlug")
|
||||
->join(
|
||||
'cm_post_category',
|
||||
'cm_post.postID = cm_post_category.postID',
|
||||
'left'
|
||||
)
|
||||
->join(
|
||||
'cm_post_ranking',
|
||||
'cm_post.postID = cm_post_ranking.postID',
|
||||
'left'
|
||||
)
|
||||
->join(
|
||||
'cm_user',
|
||||
'cm_post.userID = cm_user.userID',
|
||||
'left'
|
||||
)
|
||||
->join(
|
||||
'cm_page_content',
|
||||
'cm_post.pageID = cm_page_content.pageID',
|
||||
'left'
|
||||
)
|
||||
->group_by('cm_post.postID')
|
||||
->order_by('cm_post.datePosted', 'desc')
|
||||
->order_by('cm_post_ranking.rating', 'desc')
|
||||
->limit($limit);
|
||||
if (count($exception)) {
|
||||
$this->db->where_not_in('cm_post.postID', $exception);
|
||||
}
|
||||
if (!is_null($title)) {
|
||||
$this->db->where('cm_post_ranking.title', $title);
|
||||
}
|
||||
if ($categoryID) {
|
||||
$this->db->where('cm_category.categoryID', $categoryID);
|
||||
}
|
||||
if ($parentID) {
|
||||
$this->db->where('cm_category.parentID', $parentID);
|
||||
}
|
||||
if ($isPostCategoryRequired) {
|
||||
$this->db->join(
|
||||
'cm_category',
|
||||
'cm_post_category.categoryID = cm_category.categoryID',
|
||||
'inner'
|
||||
);
|
||||
} else {
|
||||
$this->db->join(
|
||||
'cm_category',
|
||||
'cm_post.categoryID = cm_category.categoryID',
|
||||
'left'
|
||||
);
|
||||
}
|
||||
return $this->db->get('cm_post')->result();
|
||||
}
|
||||
|
||||
public function getCategoryByParentId($parentID)
|
||||
{
|
||||
$rows = $this->db->where_in('cm_category.parentID', $parentID)->get('cm_category')->result();
|
||||
return array_column($rows, 'categoryID');
|
||||
}
|
||||
|
||||
public function getPostRecommend($categoryID = 0, $exception = [], $limit = 8)
|
||||
{
|
||||
if ($categoryID > 0) {
|
||||
$categories = $this->getCategoryByParentId($categoryID);
|
||||
$this->db->where_in('cm_category.categoryID', $categories);
|
||||
}
|
||||
if (count($exception)) {
|
||||
$this->db->where_not_in('cm_post.postID', $exception);
|
||||
}
|
||||
return $this->db->select("cm_post.*, cm_user.name, count(cm_post_recommend.postID) recomCnt, cm_page_content.img")
|
||||
->join(
|
||||
'cm_category',
|
||||
'cm_post.categoryID = cm_category.categoryID',
|
||||
'inner'
|
||||
)
|
||||
->join(
|
||||
'cm_post_recommend',
|
||||
'cm_post.postID = cm_post_recommend.postID',
|
||||
'left'
|
||||
)
|
||||
->join(
|
||||
'cm_user',
|
||||
'cm_post.userID = cm_user.userID',
|
||||
'left'
|
||||
)
|
||||
->join(
|
||||
'cm_page_content',
|
||||
'cm_post.pageID = cm_page_content.pageID',
|
||||
'left'
|
||||
)
|
||||
->group_by('cm_post.postID')
|
||||
->order_by('cm_post.datePosted', 'desc')
|
||||
->limit($limit)->get('cm_post')->result();
|
||||
}
|
||||
|
||||
public function getPostRecent($categoryID = 0, $exception = [], $limit = 8, $isUniqueAuthor = true)
|
||||
{
|
||||
if ($categoryID > 0) {
|
||||
$categories = $this->getCategoryByParentId($categoryID);
|
||||
$this->db->where_in('cm_post_category.categoryID', $categories);
|
||||
}
|
||||
if (count($exception)) {
|
||||
$this->db->where_not_in('cm_post.postID', $exception);
|
||||
}
|
||||
if ($isUniqueAuthor) {
|
||||
$this->db->group_by('cm_user.userID');
|
||||
} else {
|
||||
$this->db->group_by('cm_post.postID');
|
||||
}
|
||||
return $this->db->select("cm_post.*, cm_user.name, cm_page_content.pageTitle")
|
||||
->join(
|
||||
'cm_post_category',
|
||||
'cm_post.postID = cm_post_category.postID',
|
||||
'inner'
|
||||
)
|
||||
->join(
|
||||
'cm_user',
|
||||
'cm_post.userID = cm_user.userID',
|
||||
'left'
|
||||
)
|
||||
->join(
|
||||
'cm_page_content',
|
||||
'cm_post.pageID = cm_page_content.pageID',
|
||||
'left'
|
||||
)
|
||||
->order_by('cm_post.datePosted', 'desc')
|
||||
->where('cm_post.published', 1)
|
||||
->limit($limit)->get('cm_post')->result();
|
||||
}
|
||||
|
||||
|
||||
function getArticle($postURL)
|
||||
{
|
||||
// Get article
|
||||
$this->db->select("*");
|
||||
$this->db->where("postURL", $postURL);
|
||||
$this->db->where("published", 1);
|
||||
|
||||
$query = getPostActiveQuery()->where('p.postURL', $postURL)->get();
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u) {
|
||||
$category = array(
|
||||
'pageID' => $u['pageID'],
|
||||
'postID' => $u['postID'],
|
||||
'postTitle' => $u['postTitle'],
|
||||
'pageKeywords' => '',
|
||||
'pageDescription' => $u['postExcerpt'],
|
||||
'postContent' => empty($u['postContentHTML']) ? $this->getJsonToPostContent($u['postContent'], $u['categoryID']) : $u['postContentHTML'],
|
||||
'datePosted' => $u['datePosted'],
|
||||
'categoryTitle' => $u['categoryTitle'],
|
||||
'categorySlug' => $u['categorySlug'],
|
||||
'categoryID' => $u['categoryID'],
|
||||
'parentID' => $u['parentID'],
|
||||
'postExcerpt' => $u['postExcerpt'],
|
||||
);
|
||||
}
|
||||
return $category;
|
||||
}
|
||||
return array('postID' => "");
|
||||
}
|
||||
}
|
||||
155
application/models/Comment_model.php
Executable file
155
application/models/Comment_model.php
Executable file
@@ -0,0 +1,155 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
|
||||
class Comment_model extends MY_Model
|
||||
{
|
||||
|
||||
private $table = 'cm_comment';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getPaging($limit, $offset = 0)
|
||||
{
|
||||
if (!isAdminSite()) {
|
||||
$this->db->where('dateDeleted', '0000-00-00 00:00:00')->where('parentID', 0);
|
||||
}
|
||||
return $this->db->from($this->table . ' c')
|
||||
->select("c.*, if(u.nickname = '' or u.nickname is null, u.userName, u.nickName) as nickname")
|
||||
->join('cm_user u', 'c.userID=u.userID', 'left')
|
||||
->order_by('datePosted', 'desc')
|
||||
->limit($limit)->offset($offset);
|
||||
}
|
||||
|
||||
public function getCountPaging()
|
||||
{
|
||||
if (!isAdminSite()) {
|
||||
$this->db->where('dateDeleted', '0000-00-00 00:00:00');
|
||||
}
|
||||
return $this->db->from($this->table)
|
||||
->count_all_results();
|
||||
}
|
||||
|
||||
public function getOne($commentId)
|
||||
{
|
||||
return $this->db->where('commentID', $commentId)->get($this->table)->row();
|
||||
}
|
||||
|
||||
public function getAll($commentId)
|
||||
{
|
||||
$commentId = is_array($commentId) ? $commentId : [$commentId];
|
||||
return $this->db->where_in('commentId', $commentId)->get($this->table)->result();
|
||||
}
|
||||
|
||||
public function getByParentId(int $parentID)
|
||||
{
|
||||
return $this->db->where('parentID', $parentID)->get($this->table)->result();
|
||||
}
|
||||
|
||||
public function getByPostId($postId)
|
||||
{
|
||||
$postId = is_array($postId) ? $postId : [$postId];
|
||||
return $this->db->where_in('postID', $postId)
|
||||
->where('dateDeleted', '0000-00-00 00:00:00')
|
||||
->order_by('datePosted', 'desc')->from($this->table);
|
||||
}
|
||||
|
||||
public function getRepliesByCommentId($commentId)
|
||||
{
|
||||
$commentId = is_array($commentId) ? $commentId : [$commentId];
|
||||
return $this->db->where_in('parentID', $commentId)
|
||||
->where('dateDeleted', '0000-00-00 00:00:00')
|
||||
->order_by('datePosted', 'desc')->from($this->table);
|
||||
}
|
||||
|
||||
public function getCountByPostId($postId)
|
||||
{
|
||||
$postId = is_array($postId) ? $postId : [$postId];
|
||||
return $this->db->where_in('postID', $postId)
|
||||
->where('dateDeleted !=', '0000-00-00 00:00:00')
|
||||
->group_by('postID')->select('count(postID) as cnt, postID')
|
||||
->from($this->table);
|
||||
}
|
||||
|
||||
public function save($data)
|
||||
{
|
||||
$this->db->insert($this->table, $data);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function update($commentId)
|
||||
{
|
||||
$data = [
|
||||
'comment' => $this->input->post('comment'),
|
||||
'dateUpdated' => date('Y-m-d H:i:s')
|
||||
];
|
||||
$this->db->where('commentID', $commentId)
|
||||
->where('userID', $this->session->userdata('userID'))
|
||||
->update($this->table, $data);
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
|
||||
public function delete($commentId)
|
||||
{
|
||||
if (isAdminSite()) {
|
||||
return $this->db->where('commentID', $commentId)->delete($this->table);
|
||||
} else {
|
||||
$data = [
|
||||
'dateDeleted' => date('Y-m-d H:i:s')
|
||||
];
|
||||
$this->db->where('commentID', $commentId)->update($this->table, $data);
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
}
|
||||
|
||||
public function rating($data)
|
||||
{
|
||||
$this->db->insert('cm_comment_ranking', $data);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function getCountRatingByCommentIdAndTitle($commentId, $title)
|
||||
{
|
||||
return $this->db->where('title', $title)
|
||||
->where('commentID', $commentId)
|
||||
->count_all_results('cm_comment_ranking');
|
||||
}
|
||||
|
||||
public function getCommentRatingsByCommentId($commentId)
|
||||
{
|
||||
$commentId = is_array($commentId) ? $commentId : [$commentId];
|
||||
return $this->db
|
||||
->where_in('commentID', $commentId)
|
||||
->get('cm_comment_ranking')->result();
|
||||
}
|
||||
|
||||
public function getRepliesAndRankings(&$comments)
|
||||
{
|
||||
if (count($comments)) {
|
||||
array_map(function ($rating) use (&$comments) {
|
||||
foreach ($comments as $k => $v) {
|
||||
if ($v->commentID == $rating->commentID) {
|
||||
if ($rating->title == 1) {
|
||||
$comments[$k]->like++;
|
||||
} else {
|
||||
$comments[$k]->bad++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, $this->getCommentRatingsByCommentId(array_column($comments, 'commentID')));
|
||||
|
||||
array_map(function ($reply) use (&$comments) {
|
||||
foreach ($comments as $k => $v) {
|
||||
if ($v->commentID == $reply->parentID) {
|
||||
$comments[$k]->replies = $reply->replies;
|
||||
}
|
||||
}
|
||||
}, $this->getRepliesByCommentId(array_column($comments, 'commentID'))
|
||||
->select('count(commentID) replies, parentID')->group_by('parentID')->get()->result());
|
||||
}
|
||||
}
|
||||
}
|
||||
894
application/models/Hoosk_model.php
Executable file
894
application/models/Hoosk_model.php
Executable file
@@ -0,0 +1,894 @@
|
||||
<?php
|
||||
|
||||
class Hoosk_model extends MY_Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
// Call the Model constructor
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
}
|
||||
|
||||
/* * *************************** */
|
||||
/* * ** Dash Querys ************ */
|
||||
/* * *************************** */
|
||||
public function getSiteName()
|
||||
{
|
||||
$this->db->select("*");
|
||||
$this->db->where("siteID", 0);
|
||||
$query = $this->db->get('cm_settings');
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u) :
|
||||
return $u['siteTitle'];
|
||||
endforeach;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
public function checkMaintenance()
|
||||
{
|
||||
$this->db->select("*");
|
||||
$this->db->where("siteID", 0);
|
||||
$query = $this->db->get('cm_settings');
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u) :
|
||||
return $u['siteMaintenance'];
|
||||
endforeach;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
public function getTheme()
|
||||
{
|
||||
// Get Theme
|
||||
$this->db->select("*");
|
||||
$this->db->where("siteID", 0);
|
||||
$query = $this->db->get('cm_settings');
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u) :
|
||||
return $u['siteTheme'];
|
||||
endforeach;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
public function getLang()
|
||||
{
|
||||
// Get Theme
|
||||
$this->db->select("*");
|
||||
$this->db->where("siteID", 0);
|
||||
$query = $this->db->get('cm_settings');
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u) :
|
||||
return $u['siteLang'];
|
||||
endforeach;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
public function getUpdatedPages()
|
||||
{
|
||||
// Get most recently updated pages
|
||||
$this->db->select("pageTitle, cm_page_attributes.pageID, pageUpdated, pageContentHTML");
|
||||
$this->db->join('cm_page_content', 'cm_page_content.pageID = cm_page_attributes.pageID');
|
||||
$this->db->join('cm_page_meta', 'cm_page_meta.pageID = cm_page_attributes.pageID');
|
||||
$this->db->order_by("pageUpdated", "desc");
|
||||
$this->db->limit(5);
|
||||
$query = $this->db->get('cm_page_attributes');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
/* * *************************** */
|
||||
/* * ** User Querys ************ */
|
||||
/* * *************************** */
|
||||
public function countUsers()
|
||||
{
|
||||
return $this->db->count_all('cm_user');
|
||||
}
|
||||
|
||||
public function getUsers($limit, $offset = 0)
|
||||
{
|
||||
// Get a list of all user accounts
|
||||
$this->db->select("userName, g.name groupName, email, userID")->join('cm_user_group g', 'u.groupID = g.groupID', 'left');
|
||||
$this->db->order_by("userName", "asc");
|
||||
$this->db->limit($limit, $offset);
|
||||
$query = $this->db->get('cm_user u');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getUser($id)
|
||||
{
|
||||
// Get the user details
|
||||
$this->db->select("*");
|
||||
$this->db->where("userID", $id);
|
||||
$query = $this->db->get('cm_user');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getUserEmail($id)
|
||||
{
|
||||
// Get the user email address
|
||||
$this->db->select("email");
|
||||
$this->db->where("userID", $id);
|
||||
$query = $this->db->get('cm_user');
|
||||
if ($query->num_rows() > 0) {
|
||||
foreach ($query->result() as $rows) {
|
||||
$email = $rows->email;
|
||||
return $email;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function createUser()
|
||||
{
|
||||
// Create the user account
|
||||
$data = array(
|
||||
'userName' => $this->input->post('username'),
|
||||
'email' => $this->input->post('email'),
|
||||
'password' => md5($this->input->post('password') . SALT),
|
||||
);
|
||||
$this->db->insert('cm_user', $data);
|
||||
}
|
||||
|
||||
public function updateUser($id)
|
||||
{
|
||||
// update the user account
|
||||
$data = array(
|
||||
'email' => $this->input->post('email'),
|
||||
'password' => md5($this->input->post('password') . SALT),
|
||||
);
|
||||
$this->db->where('userID', $id);
|
||||
$this->db->update('cm_user', $data);
|
||||
}
|
||||
|
||||
public function removeUser($id)
|
||||
{
|
||||
// Delete a user account
|
||||
$this->db->delete('cm_user', array('userID' => $id));
|
||||
}
|
||||
|
||||
public function login($username, $password)
|
||||
{
|
||||
$this->db->select("*");
|
||||
$this->db->where("userName", $username);
|
||||
$this->db->where("password", $password);
|
||||
$query = $this->db->get("cm_user");
|
||||
if ($query->num_rows() > 0) {
|
||||
foreach ($query->result() as $rows) {
|
||||
$data = array(
|
||||
'userID' => $rows->userID,
|
||||
'userName' => $rows->userName,
|
||||
'logged_in' => true,
|
||||
);
|
||||
|
||||
$this->session->set_userdata($data);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* * *************************** */
|
||||
/* * ** Page Querys ************ */
|
||||
/* * *************************** */
|
||||
public function pageSearch($term)
|
||||
{
|
||||
$this->db->select("*");
|
||||
$this->db->like("pageTitle", $term)->or_like('categoryTitle', $term)->or_like('pageURL', $term);
|
||||
$this->db->join('cm_page_content', 'cm_page_content.pageID = cm_page_attributes.pageID', 'left')->group_by('cm_page_attributes.pageID');
|
||||
$this->db->join('cm_category', 'cm_page_attributes.categoryID=cm_category.categoryID or cm_page_attributes.categoryID = 0', 'left');
|
||||
// $this->db->limit($limit, $offset);
|
||||
$query = $this->db->get('cm_page_attributes');
|
||||
if ($term == "") {
|
||||
$this->db->limit(15);
|
||||
}
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $p) :
|
||||
echo '<tr>';
|
||||
echo '<td>' . $p['navTitle'] . '</td>';
|
||||
echo '<td>' . $p['categoryTitle'] . '</td>';
|
||||
echo '<td>' . $p['pageCreated'] . '</td>';
|
||||
echo '<td>' . ($p['pagePublished'] ? '<span class="fa fa-2x fa-check-circle"></span>' : '<span class="fa fa-2x fa-times-circle"></span>') . '</td>';
|
||||
echo '<td class="td-actions"><a href="' . BASE_URL . '/admin/pages/jumbo/' . $p['pageID'] . '" class="btn btn-small btn-primary">' . $this->lang->line('btn_jumbotron') . '</a> <a href="' . BASE_URL . '/admin/pages/edit/' . $p['pageID'] . '" class="btn btn-small btn-success"><i class="fa fa-pencil"> </i></a> <a data-toggle="modal" data-target="#ajaxModal" class="btn btn-danger btn-small" href="' . BASE_URL . '/admin/pages/delete/' . $p['pageID'] . '"><i class="fa fa-remove"> </i></a></td>';
|
||||
echo '</tr>';
|
||||
endforeach;
|
||||
} else {
|
||||
echo "<tr><td colspan='5'><p>" . $this->lang->line('no_results') . "</p></td></tr>";
|
||||
}
|
||||
}
|
||||
public function countPages()
|
||||
{
|
||||
return $this->db->count_all('cm_page_attributes');
|
||||
}
|
||||
public function getPages($limit, $offset = 0)
|
||||
{
|
||||
// Get a list of all pages
|
||||
$this->db->select("*, cm_category.categoryTitle");
|
||||
$this->db->join('cm_page_content', 'cm_page_content.pageID = cm_page_attributes.pageID');
|
||||
$this->db->join('cm_page_meta', 'cm_page_meta.pageID = cm_page_attributes.pageID');
|
||||
$this->db->join('cm_category', 'cm_page_attributes.categoryID=cm_category.categoryID');
|
||||
$this->db->limit($limit, $offset);
|
||||
$query = $this->db->get('cm_page_attributes');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
public function getPagesAll()
|
||||
{
|
||||
// Get a list of all pages
|
||||
$this->db->select("*");
|
||||
$this->db->join('cm_page_content', 'cm_page_content.pageID = cm_page_attributes.pageID');
|
||||
$this->db->join('cm_page_meta', 'cm_page_meta.pageID = cm_page_attributes.pageID');
|
||||
$query = $this->db->get('cm_page_attributes');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
public function createPage()
|
||||
{
|
||||
// Create the page
|
||||
$data = array(
|
||||
'pagePublished' => $this->input->post('pagePublished'),
|
||||
'pageTemplate' => $this->input->post('pageTemplate'),
|
||||
'pageURL' => $this->input->post('pageURL'),
|
||||
);
|
||||
$this->db->insert('cm_page_attributes', $data);
|
||||
if ($this->input->post('content') != "") {
|
||||
$sirTrevorInput = $this->input->post('content');
|
||||
$converter = new Converter();
|
||||
$HTMLContent = $converter->toHtml($sirTrevorInput);
|
||||
} else {
|
||||
$HTMLContent = "";
|
||||
}
|
||||
|
||||
$this->db->select("*");
|
||||
$this->db->where("pageURL", $this->input->post('pageURL'));
|
||||
$query = $this->db->get("cm_page_attributes");
|
||||
if ($query->num_rows() > 0) {
|
||||
foreach ($query->result() as $rows) {
|
||||
$contentdata = array(
|
||||
'pageID' => $rows->pageID,
|
||||
'pageTitle' => $this->input->post('pageTitle'),
|
||||
'navTitle' => $this->input->post('navTitle'),
|
||||
'pageContent' => $this->input->post('content'),
|
||||
'pageContentHTML' => $HTMLContent,
|
||||
);
|
||||
$this->db->insert('cm_page_content', $contentdata);
|
||||
$metadata = array(
|
||||
'pageID' => $rows->pageID,
|
||||
'pageKeywords' => $this->input->post('pageKeywords'),
|
||||
'pageDescription' => $this->input->post('pageDescription'),
|
||||
);
|
||||
$this->db->insert('cm_page_meta', $metadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getPage($id)
|
||||
{
|
||||
// Get the page details
|
||||
$this->db->select("*");
|
||||
$this->db->where("cm_page_attributes.pageID", $id)->or_where("cm_page_attributes.pageURL", $id);
|
||||
$this->db->join('cm_page_content', 'cm_page_content.pageID = cm_page_attributes.pageID');
|
||||
$this->db->join('cm_page_meta', 'cm_page_meta.pageID = cm_page_attributes.pageID');
|
||||
$query = $this->db->get('cm_page_attributes');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getPageBanners($id)
|
||||
{
|
||||
// Get the page banners
|
||||
$this->db->select("*");
|
||||
$this->db->where("pageID", $id);
|
||||
$this->db->order_by("slideOrder ASC");
|
||||
$query = $this->db->get('cm_banner');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function removePage($id)
|
||||
{
|
||||
// Delete a page
|
||||
$this->db->delete('cm_page_content', array('pageID' => $id));
|
||||
$this->db->delete('cm_page_meta', array('pageID' => $id));
|
||||
$this->db->delete('cm_page_attributes', array('pageID' => $id));
|
||||
}
|
||||
|
||||
public function getPageURL($id)
|
||||
{
|
||||
// Get the page URL
|
||||
$this->db->select("pageURL");
|
||||
$this->db->where("pageID", $id);
|
||||
$query = $this->db->get('cm_page_attributes');
|
||||
if ($query->num_rows() > 0) {
|
||||
foreach ($query->result() as $rows) {
|
||||
$pageURL = $rows->pageURL;
|
||||
return $pageURL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updatePage($id)
|
||||
{
|
||||
// Update the page
|
||||
|
||||
if ($this->input->post('content') != "") {
|
||||
$sirTrevorInput = $this->input->post('content');
|
||||
$converter = new Converter();
|
||||
$HTMLContent = $converter->toHtml($sirTrevorInput);
|
||||
} else {
|
||||
$HTMLContent = "";
|
||||
}
|
||||
|
||||
if ($id != 1) {
|
||||
$data = array(
|
||||
'pagePublished' => $this->input->post('pagePublished'),
|
||||
'pageURL' => $this->input->post('pageURL'),
|
||||
'pageTemplate' => $this->input->post('pageTemplate'),
|
||||
);
|
||||
} else {
|
||||
$data = array(
|
||||
'pagePublished' => $this->input->post('pagePublished'),
|
||||
'pageTemplate' => $this->input->post('pageTemplate'),
|
||||
);
|
||||
}
|
||||
$this->db->where("pageID", $id);
|
||||
$this->db->update('cm_page_attributes', $data);
|
||||
$contentdata = array(
|
||||
'pageTitle' => $this->input->post('pageTitle'),
|
||||
'navTitle' => $this->input->post('navTitle'),
|
||||
'pageContent' => $this->input->post('content'),
|
||||
'pageContentHTML' => $HTMLContent,
|
||||
);
|
||||
$this->db->where("pageID", $id);
|
||||
$this->db->update('cm_page_content', $contentdata);
|
||||
$metadata = array(
|
||||
'pageKeywords' => $this->input->post('pageKeywords'),
|
||||
'pageDescription' => $this->input->post('pageDescription'),
|
||||
);
|
||||
$this->db->where("pageID", $id);
|
||||
$this->db->update('cm_page_meta', $metadata);
|
||||
}
|
||||
|
||||
public function updateJumbotron($id)
|
||||
{
|
||||
// Update the jumbotron
|
||||
if ($this->input->post('jumbotron') != "") {
|
||||
$sirTrevorInput = $this->input->post('jumbotron');
|
||||
$converter = new Converter();
|
||||
$HTMLContent = $converter->toHtml($sirTrevorInput);
|
||||
} else {
|
||||
$HTMLContent = "";
|
||||
}
|
||||
$data = array(
|
||||
'enableJumbotron' => $this->input->post('enableJumbotron'),
|
||||
'enableSlider' => $this->input->post('enableSlider'),
|
||||
);
|
||||
|
||||
$this->db->where("pageID", $id);
|
||||
$this->db->update('cm_page_attributes', $data);
|
||||
$contentdata = array(
|
||||
'jumbotron' => $this->input->post('jumbotron'),
|
||||
'jumbotronHTML' => $HTMLContent,
|
||||
);
|
||||
$this->db->where("pageID", $id);
|
||||
$this->db->update('cm_page_content', $contentdata);
|
||||
|
||||
// Clear the sliders
|
||||
$this->db->delete('cm_banner', array('pageID' => $id));
|
||||
|
||||
/*for($i=0;$i<=$_POST['total_upload_pics'];$i++)
|
||||
{
|
||||
if(isset($_POST['slide' . $i]))
|
||||
{
|
||||
$slidedata = array(
|
||||
'pageID' => $id,
|
||||
'slideImage' => $this->input->post('slide'.$i),
|
||||
'slideLink' => $this->input->post('link'.$i),
|
||||
'slideOrder' => $i,
|
||||
);
|
||||
$this->db->insert('hoosk_banner', $slidedata));
|
||||
}
|
||||
}*/
|
||||
|
||||
$sliders = explode('{', $this->input->post('pics'));
|
||||
|
||||
for ($i = 1; $i < count($sliders); $i++) {
|
||||
$div = explode('|', $sliders[$i]);
|
||||
|
||||
$slidedata = array(
|
||||
'pageID' => $id,
|
||||
'slideImage' => $div[0],
|
||||
'slideLink' => $div[1],
|
||||
'slideAlt' => substr($div[2], 0, -1),
|
||||
'slideOrder' => $i - 1,
|
||||
);
|
||||
|
||||
$this->db->insert('cm_banner', $slidedata);
|
||||
}
|
||||
}
|
||||
|
||||
/* * *************************** */
|
||||
/* * ** Navigation Querys ****** */
|
||||
/* * *************************** */
|
||||
public function countNavigation()
|
||||
{
|
||||
return $this->db->count_all('cm_navigation');
|
||||
}
|
||||
|
||||
public function getAllNav($limit, $offset = 0)
|
||||
{
|
||||
// Get a list of all pages
|
||||
$this->db->select("*");
|
||||
$this->db->limit($limit, $offset);
|
||||
$query = $this->db->get('cm_navigation');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getNav($id)
|
||||
{
|
||||
// Get a list of all pages
|
||||
$this->db->select("*");
|
||||
$this->db->where("navSlug", $id);
|
||||
$query = $this->db->get('cm_navigation');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
//Get page details for building nav
|
||||
public function getPageNav($url)
|
||||
{
|
||||
// Get the page details
|
||||
$this->db->select("*");
|
||||
$this->db->where("cm_page_attributes.pageURL", $url);
|
||||
$this->db->join('cm_page_content', 'cm_page_content.pageID = cm_page_attributes.pageID');
|
||||
$this->db->join('cm_page_meta', 'cm_page_meta.pageID = cm_page_attributes.pageID');
|
||||
$query = $this->db->get('cm_page_attributes');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function insertNav()
|
||||
{
|
||||
$navigationHTML = $this->input->post('convertedNav');
|
||||
$navigationHTML = str_replace("<ul></ul>", "", $navigationHTML);
|
||||
$navigationEdit = $this->input->post('seriaNav');
|
||||
$navigationEdit = str_replace('<button data-action="collapse" type="button">Collapse</button><button style="display: none;" data-action="expand" type="button">Expand</button>', "", $navigationEdit);
|
||||
|
||||
$data = array(
|
||||
'navSlug' => $this->input->post('navSlug'),
|
||||
'navTitle' => $this->input->post('navTitle'),
|
||||
'navEdit' => $navigationEdit,
|
||||
'navHTML' => $navigationHTML,
|
||||
);
|
||||
$this->db->insert('cm_navigation', $data);
|
||||
}
|
||||
|
||||
public function updateNav($id)
|
||||
{
|
||||
$navigationHTML = $this->input->post('convertedNav');
|
||||
$navigationHTML = str_replace("<ul></ul>", "", $navigationHTML);
|
||||
$navigationEdit = $this->input->post('seriaNav');
|
||||
$navigationEdit = str_replace('<button data-action="collapse" type="button">Collapse</button><button style="display: none;" data-action="expand" type="button">Expand</button>', "", $navigationEdit);
|
||||
|
||||
$data = array(
|
||||
'navTitle' => $this->input->post('navTitle'),
|
||||
'navEdit' => $navigationEdit,
|
||||
'navHTML' => $navigationHTML,
|
||||
);
|
||||
$this->db->where("navSlug", $id);
|
||||
$this->db->update('cm_navigation', $data);
|
||||
}
|
||||
|
||||
public function removeNav($id)
|
||||
{
|
||||
// Delete a nav
|
||||
$this->db->delete('cm_navigation', array('navSlug' => $id));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getSettings()
|
||||
{
|
||||
// Get the settings
|
||||
$this->db->select("*");
|
||||
$this->db->where("siteID", 0);
|
||||
$query = $this->db->get('cm_settings');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
public function updateSettings()
|
||||
{
|
||||
$data = array(
|
||||
'siteTheme' => $this->input->post('siteTheme'),
|
||||
'siteLang' => $this->input->post('siteLang'),
|
||||
'siteFooter' => $this->input->post('siteFooter'),
|
||||
'siteMaintenance' => $this->input->post('siteMaintenance'),
|
||||
'siteMaintenanceHeading' => $this->input->post('siteMaintenanceHeading'),
|
||||
'siteMaintenanceMeta' => $this->input->post('siteMaintenanceMeta'),
|
||||
'siteMaintenanceContent' => $this->input->post('siteMaintenanceContent'),
|
||||
'siteAdditionalJS' => $this->input->post('siteAdditionalJS'),
|
||||
|
||||
|
||||
'webmaster_name' => $this->input->post('webmaster_name'),
|
||||
'webmaster_email' => $this->input->post('webmaster_email'),
|
||||
'banned_word' => $this->input->post('banned_word'),
|
||||
'legal_terms' => str_replace('\r\n','<br />',$this->input->post('legal_terms')),
|
||||
'legal_privacy' => str_replace('\r\n','<br />', $this->input->post('legal_privacy')),
|
||||
'legal_privatedata' => str_replace('\r\n','<br />', $this->input->post('legal_privatedata')),
|
||||
|
||||
);
|
||||
|
||||
if ($this->input->post('siteTitle') != "") {
|
||||
$data['siteTitle'] = $this->input->post('siteTitle');
|
||||
}
|
||||
|
||||
if ($this->input->post('siteLogo') != "") {
|
||||
$data['siteLogo'] = $this->input->post('siteLogo');
|
||||
}
|
||||
if ($this->input->post('siteFavicon') != "") {
|
||||
$data['siteFavicon'] = $this->input->post('siteFavicon');
|
||||
}
|
||||
$this->db->where("siteID", 0);
|
||||
$this->db->update('cm_settings', $data);
|
||||
}
|
||||
|
||||
|
||||
/* * *************************** */
|
||||
/* * ** Post Querys ************ */
|
||||
/* * *************************** */
|
||||
public function postSearch($term)
|
||||
{
|
||||
$this->db->select("cm_post.*, cm_user.userName, cm_category.categoryTitle");
|
||||
$this->db->like("postTitle", $term)->or_like("postExcerpt", $term)->or_like("cm_category.categoryTitle", $term)->or_where('cm_post.postID', $term);
|
||||
$this->db->join('cm_category', 'cm_category.categoryID = cm_post.categoryID or cm_post.categoryID = 0', 'left');
|
||||
$this->db->join('cm_post_category', 'cm_post.postID = cm_post_category.postID', 'left');
|
||||
$this->db->join('cm_user', 'cm_post.userID = cm_user.userID', 'left');
|
||||
$this->db->order_by("unixStamp", "desc");
|
||||
if ($term == "") {
|
||||
$this->db->limit(15);
|
||||
}
|
||||
$query = $this->db->get('cm_post');
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $p) :
|
||||
echo '<tr>';
|
||||
echo '<td>' . $p['postTitle'] . '</td>';
|
||||
echo '<td>' . $p['categoryTitle'] . '</td>';
|
||||
echo '<td>' . $p['userName'] . '</td>';
|
||||
echo '<td>' . $p['datePosted'] . '</td>';
|
||||
echo '<td>' . ($p['published'] ? '<span class="fa fa-2x fa-check-circle"></span>' : '<span class="fa fa-2x fa-times-circle"></span>') . '</td>';
|
||||
echo '<td class="td-actions"><a href="' . BASE_URL . '/admin/posts/edit/' . $p['postID'] . '" class="btn btn-small btn-success"><i class="fa fa-pencil"> </i></a> <a data-toggle="modal" data-target="#ajaxModal" class="btn btn-danger btn-small" href="' . BASE_URL . '/admin/posts/delete/' . $p['postID'] . '"><i class="fa fa-remove"> </i></a></td>';
|
||||
echo '</tr>';
|
||||
endforeach;
|
||||
} else {
|
||||
echo "<tr><td colspan='5'><p>" . $this->lang->line('no_results') . "</p></td></tr>";
|
||||
}
|
||||
}
|
||||
public function countPosts()
|
||||
{
|
||||
if ($term = getSearchTerm()) {
|
||||
$this->db->join('cm_category', 'cm_category.categoryID = cm_post.categoryID', 'left');
|
||||
$this->db->join('cm_post_category', 'cm_category.categoryID = cm_post_category.categoryID and cm_post_category.postID=cm_post.postID', 'left');
|
||||
$this->db->like("postTitle", $term)->or_like("postExcerpt", $term)->or_like("cm_category.categoryTitle", $term)->or_where('cm_post.postID', $term);
|
||||
}
|
||||
return $this->db->count_all_results('cm_post');
|
||||
}
|
||||
public function getPosts($limit, $offset = 0, $categoryID = 0, $parentID = 0, $exceptions = [], $isCount = false)
|
||||
{
|
||||
$rows = [];
|
||||
if (!$isCount) {
|
||||
$this->db->select("cm_post.*, cm_user.userName, cm_category.categoryTitle, cm_category.categorySlug");
|
||||
$this->db->limit($limit, $offset);
|
||||
$this->db->order_by("dateUpdated", "desc");
|
||||
}
|
||||
if ($term = getSearchTerm()) {
|
||||
$this->db->like("postTitle", $term)->or_like("postExcerpt", $term)
|
||||
->or_like("cm_category.categoryTitle", $term)->or_where('cm_post.postID', $term)
|
||||
->or_like('cm_page_content.pageTitle', $term)
|
||||
->join('cm_post_page', 'cm_post.postID=cm_post_page.postID', 'left')
|
||||
->join('cm_page_content', 'cm_post_page.pageID=cm_page_content.pageID', 'left');
|
||||
}
|
||||
$this->db->join('cm_post_category', 'cm_post_category.postID=cm_post.postID', 'left');
|
||||
$this->db->join('cm_category', 'cm_post_category.categoryID = cm_category.categoryID', 'left');
|
||||
$this->db->join('cm_user', 'cm_post.userID = cm_user.userID', 'left');
|
||||
$this->db->group_by('cm_post.postID');
|
||||
|
||||
if ($categoryID > 0) {
|
||||
$this->db->where("cm_post.categoryID", $categoryID);
|
||||
}
|
||||
if ($parentID > 0) {
|
||||
$this->db->where('cm_category.parentID', $parentID);
|
||||
}
|
||||
if (count($exceptions) > 0) {
|
||||
$this->db->where_not_in('cm_post.postID', $exceptions);
|
||||
}
|
||||
if ($isCount) {
|
||||
return $this->db->from('cm_post')->count_all_results();
|
||||
} else {
|
||||
$query = $this->db->get('cm_post');
|
||||
if ($query->num_rows() > 0) {
|
||||
$rows = $query->result_array();
|
||||
$this->getMultipleCategory($rows);
|
||||
$this->getMultiplePage($rows);
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
|
||||
protected function getMultiplePage(&$rows)
|
||||
{
|
||||
$this->load->model('page_model');
|
||||
$pages = $this->db->from('cm_page_content')->join('cm_post_page', 'cm_page_content.pageID=cm_post_page.pageID', 'left')
|
||||
->where_in('cm_post_page.postID', array_column($rows, 'postID'))->get()->result();
|
||||
foreach ($pages as $r) {
|
||||
foreach ($rows as $k => $row) {
|
||||
$rows[$k]['pageTitle'] = empty($rows[$k]['pageTitle']) ? '' : $rows[$k]['pageTitle'];
|
||||
if ($row['postID'] == $r->postID) {
|
||||
$rows[$k]['pages'][] = $r->pageID;
|
||||
$rows[$k]['pageTitle'] = (empty($rows[$k]['pageTitle']) ? '' : $rows[$k]['pageTitle'] . ', ') . $r->pageTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getMultipleCategory(&$rows)
|
||||
{
|
||||
$categories = $this->getCategories();
|
||||
array_map(function ($r) use (&$rows, $categories) {
|
||||
foreach ($rows as $k => $row) {
|
||||
if ($row['postID'] == $r->postID) {
|
||||
$rows[$k]['categoryID'] = $r->categoryID;
|
||||
$rows[$k]['categories'][] = $r->categoryID;
|
||||
foreach ($categories as $c) {
|
||||
if ($c['categoryID'] == $r->categoryID) {
|
||||
$rows[$k]['categoryTitle'] = (empty($rows[$k]['categoryTitle']) ? '' : $rows[$k]['categoryTitle'] . ', ') . $c['categoryTitle'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, $this->getPostCategoryByPostIdIn(array_column(array_filter($rows, function ($row) {
|
||||
return $row['categoryID'] == 0;
|
||||
}), 'postID')));
|
||||
}
|
||||
|
||||
public function createPost()
|
||||
{
|
||||
// Create the post
|
||||
// if ($this->input->post('content') != "") {
|
||||
// $sirTrevorInput = $this->input->post('content');
|
||||
// $converter = new Converter();
|
||||
// $HTMLContent = $converter->toHtml($sirTrevorInput);
|
||||
// } else {
|
||||
// $HTMLContent = "";
|
||||
// }
|
||||
|
||||
$categoryID = 0;
|
||||
$categories = explode(',', $this->input->post('categories'));
|
||||
if (count($categories) == 1) {
|
||||
$categoryID = $categories[0];
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'postTitle' => $this->input->post('postTitle'),
|
||||
'categoryID' => $categoryID,
|
||||
// 'postURL' => $this->input->post('postURL'),
|
||||
// 'postContent' => $this->input->post('content'),
|
||||
'postContentHTML' => $this->input->post('content'),
|
||||
'postExcerpt' => $this->input->post('postExcerpt'),
|
||||
'published' => $this->input->post('published'),
|
||||
'datePosted' => $this->input->post('datePosted'),
|
||||
'unixStamp' => $this->input->post('unixStamp'),
|
||||
);
|
||||
if ($this->input->post('postImage') != "") {
|
||||
$data['postImage'] = $this->input->post('postImage');
|
||||
}
|
||||
$this->db->insert('cm_post', $data);
|
||||
$insertID = $this->db->insert_id();
|
||||
if (count($categories) > 1) {
|
||||
$this->addPostCategory($insertID, $categories);
|
||||
}
|
||||
$this->db->where('postID', $insertID)->update('cm_post', array('postURL' => $insertID));
|
||||
}
|
||||
|
||||
public function getPost($id)
|
||||
{
|
||||
// Get the post details
|
||||
$this->db->select("*");
|
||||
$this->db->where("postID", $id);
|
||||
$this->db->join('cm_category', 'cm_category.categoryID = cm_post.categoryID', 'left');
|
||||
$query = $this->db->get('cm_post');
|
||||
if ($query->num_rows() > 0) {
|
||||
$rows = $query->result_array();
|
||||
$this->getMultipleCategory($rows);
|
||||
return $rows;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function removePost($id)
|
||||
{
|
||||
// Delete a post
|
||||
$this->db->delete('cm_post', array('postID' => $id));
|
||||
}
|
||||
|
||||
public function updatePost($id)
|
||||
{
|
||||
// Update the post
|
||||
|
||||
// if ($this->input->post('content') != "") {
|
||||
// $sirTrevorInput = $this->input->post('content');
|
||||
// $converter = new Converter();
|
||||
// $HTMLContent = $converter->toHtml($sirTrevorInput);
|
||||
// } else {
|
||||
// $HTMLContent = "";
|
||||
// }
|
||||
|
||||
$categoryID = 0;
|
||||
$categories = explode(',', $this->input->post('categories'));
|
||||
if (count($categories) > 1) {
|
||||
$this->addPostCategory($id, $categories);
|
||||
} else {
|
||||
$categoryID = $categories[0];
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'postTitle' => $this->input->post('postTitle'),
|
||||
'categoryID' => $categoryID,
|
||||
// 'postURL' => $this->input->post('postURL'),
|
||||
'postContentHTML' => $this->input->post('content'),
|
||||
'postExcerpt' => $this->input->post('postExcerpt'),
|
||||
'published' => $this->input->post('published'),
|
||||
'datePosted' => $this->input->post('datePosted'),
|
||||
'unixStamp' => $this->input->post('unixStamp'),
|
||||
);
|
||||
if ($this->input->post('postImage') != "") {
|
||||
$data['postImage'] = $this->input->post('postImage');
|
||||
}
|
||||
$this->db->where("postID", $id);
|
||||
$this->db->update('cm_post', $data);
|
||||
}
|
||||
|
||||
|
||||
/* * *************************** */
|
||||
/* * ** Category Querys ******** */
|
||||
/* * *************************** */
|
||||
public function countCategories()
|
||||
{
|
||||
return $this->db->count_all('cm_category');
|
||||
}
|
||||
public function getCategories()
|
||||
{
|
||||
// Get a list of all categories
|
||||
$this->db->select("*");
|
||||
$query = $this->db->get('cm_category');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getPostCategoryByPostIdIn($postIds)
|
||||
{
|
||||
if (count($postIds) == 0) return [];
|
||||
return $this->db->from('cm_post_category pc')->where_in('pc.postID', $postIds)->get()->result();
|
||||
}
|
||||
|
||||
|
||||
public function getCategoriesAll($limit, $offset = 0)
|
||||
{
|
||||
// Get a list of all categories
|
||||
$this->db->select("*");
|
||||
$this->db->limit($limit, $offset);
|
||||
$query = $this->db->get('cm_category');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
public function createCategory()
|
||||
{
|
||||
// Create the category
|
||||
|
||||
$data = array(
|
||||
'categoryTitle' => $this->input->post('categoryTitle'),
|
||||
'categorySlug' => $this->input->post('categorySlug'),
|
||||
'categoryDescription' => $this->input->post('categoryDescription')
|
||||
);
|
||||
|
||||
$this->db->insert('cm_category', $data);
|
||||
}
|
||||
|
||||
public function getCategory($id)
|
||||
{
|
||||
// Get the category details
|
||||
$this->db->select("*");
|
||||
$this->db->where("categoryID", $id);
|
||||
$query = $this->db->get('cm_category');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function removeCategory($id)
|
||||
{
|
||||
// Delete a category
|
||||
$this->db->delete('cm_category', array('categoryID' => $id));
|
||||
}
|
||||
|
||||
public function updateCategory($id)
|
||||
{
|
||||
// Update the category
|
||||
$data = array(
|
||||
'categoryTitle' => $this->input->post('categoryTitle'),
|
||||
'categorySlug' => $this->input->post('categorySlug'),
|
||||
'categoryDescription' => $this->input->post('categoryDescription')
|
||||
);
|
||||
|
||||
$this->db->where("categoryID", $id);
|
||||
$this->db->update('cm_category', $data);
|
||||
}
|
||||
|
||||
/* * *************************** */
|
||||
/* * ** Social Querys ********** */
|
||||
/* * *************************** */
|
||||
|
||||
public function getSocial()
|
||||
{
|
||||
$this->db->select("*");
|
||||
$query = $this->db->get('cm_social');
|
||||
if ($query->num_rows() > 0) {
|
||||
return $query->result_array();
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
public function updateSocial()
|
||||
{
|
||||
$this->db->select("*");
|
||||
$query = $this->db->get("cm_social");
|
||||
if ($query->num_rows() > 0) {
|
||||
foreach ($query->result() as $rows) {
|
||||
$data = array();
|
||||
$data['socialLink'] = $this->input->post($rows->socialName);
|
||||
if (isset($_POST['checkbox' . $rows->socialName])) {
|
||||
$data['socialEnabled'] = $this->input->post('checkbox' . $rows->socialName);
|
||||
} else {
|
||||
$data['socialEnabled'] = 0;
|
||||
}
|
||||
$this->db->where("socialName", $rows->socialName);
|
||||
$this->db->update('cm_social', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
168
application/models/Hoosk_page_model.php
Executable file
168
application/models/Hoosk_page_model.php
Executable file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
class Hoosk_page_model extends MY_Model {
|
||||
|
||||
function __construct() {
|
||||
// Call the Model constructor
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
}
|
||||
|
||||
|
||||
/* * *************************** */
|
||||
/* * ** Page Querys ************ */
|
||||
/* * *************************** */
|
||||
/*function getSiteName() {
|
||||
// Get Theme
|
||||
$this->db->select("*");
|
||||
$this->db->where("siteID", 0);
|
||||
$query = $this->db->get('cm_settings');
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u):
|
||||
return $u['siteTitle'];
|
||||
endforeach;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
function getTheme() {
|
||||
// Get Theme
|
||||
$this->db->select("*");
|
||||
$this->db->where("siteID", 0);
|
||||
$query = $this->db->get('cm_settings');
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u):
|
||||
return $u['siteTheme'];
|
||||
endforeach;
|
||||
}
|
||||
return array();
|
||||
}*/
|
||||
|
||||
function getPage($pageURL) {
|
||||
// Get page
|
||||
$this->db->select("*");
|
||||
$this->db->join('cm_page_content', 'cm_page_content.pageID = cm_page_attributes.pageID');
|
||||
$this->db->join('cm_page_meta', 'cm_page_meta.pageID = cm_page_attributes.pageID');
|
||||
$this->db->where("pagePublished", 1);
|
||||
$this->db->where("pageURL", $pageURL);
|
||||
$query = $this->db->get('cm_page_attributes');
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u):
|
||||
$page = array(
|
||||
'pageID' => $u['pageID'],
|
||||
'categoryID' => $u['categoryID'],
|
||||
'pageTitle' => $u['pageTitle'],
|
||||
'pageIntro' => $u['intro'],
|
||||
'pageIcon' => $u['pageIcon'],
|
||||
'pageImg' => $u['img'],
|
||||
'pageKeywords' => $u['pageKeywords'],
|
||||
'pageDescription' => $u['pageDescription'],
|
||||
'pageContentHTML' => $u['pageContentHTML'],
|
||||
'pageTemplate' => $u['pageTemplate'],
|
||||
'enableJumbotron' => $u['enableJumbotron'],
|
||||
'enableSlider' => $u['enableSlider'],
|
||||
'jumbotronHTML' => $u['jumbotronHTML'],
|
||||
);
|
||||
endforeach;
|
||||
return $page;
|
||||
|
||||
}
|
||||
return array('pageID' => "",'pageTemplate' => "");
|
||||
}
|
||||
function getCategory($catSlug) {
|
||||
// Get category
|
||||
$this->db->select("*");
|
||||
$this->db->where("categorySlug", $catSlug);
|
||||
$query = $this->db->get('cm_category');
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u):
|
||||
$category = array(
|
||||
'pageID' => $u['categoryID'],
|
||||
'categoryID' => $u['categoryID'],
|
||||
'pageTitle' => $u['categoryTitle'],
|
||||
'pageKeywords' => '',
|
||||
'pageDescription' => $u['categoryDescription'],
|
||||
);
|
||||
endforeach;
|
||||
return $category;
|
||||
|
||||
}
|
||||
return array('categoryID' => "");
|
||||
}
|
||||
|
||||
function getArticle($postURL) {
|
||||
// Get article
|
||||
$this->db->select("*");
|
||||
$this->db->where("postURL", $postURL);
|
||||
// $this->db->where("published", 1);
|
||||
$this->db->join('cm_category', 'cm_category.categoryID = cm_post.categoryID or cm_post.categoryID=0', 'left');
|
||||
$query = $this->db->get('cm_post');
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u) {
|
||||
$category = array(
|
||||
'pageID' => $u['postID'],
|
||||
'postID' => $u['postID'],
|
||||
'postTitle' => $u['postTitle'],
|
||||
'pageKeywords' => '',
|
||||
'pageDescription' => $u['postExcerpt'],
|
||||
'postContent' => empty($u['postContentHTML']) ? $this->getJsonToPostContent($u['postContent'], $u['categoryID']) : $u['postContentHTML'],
|
||||
'datePosted' => $u['datePosted'],
|
||||
'categoryTitle' => $u['categoryTitle'],
|
||||
'categorySlug' => $u['categorySlug'],
|
||||
'categoryID' => $u['categoryID'],
|
||||
'parentID' => $u['parentID'],
|
||||
'postExcerpt' => $u['postExcerpt'],
|
||||
);
|
||||
}
|
||||
return $category;
|
||||
|
||||
}
|
||||
return array('postID' => "");
|
||||
}
|
||||
|
||||
|
||||
protected function getJsonToPostContent($content, $categoryID) {
|
||||
$html = '';
|
||||
$c = json_decode($content);
|
||||
foreach($c as $url) {
|
||||
$html .= '<img src="http://crossmap.co.kr'.$url.'">';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
function getSettings() {
|
||||
// Get settings
|
||||
$this->db->select("*");
|
||||
$this->db->where("siteID", 0);
|
||||
$query = $this->db->get('cm_settings');
|
||||
if ($query->num_rows() > 0) {
|
||||
$results = $query->result_array();
|
||||
foreach ($results as $u):
|
||||
$page = array(
|
||||
'siteLogo' => $u['siteLogo'],
|
||||
'siteFavicon' => $u['siteFavicon'],
|
||||
'siteTitle' => $u['siteTitle'],
|
||||
'siteTheme' => $u['siteTheme'],
|
||||
'siteFooter' => $u['siteFooter'],
|
||||
'siteMaintenanceHeading' => $u['siteMaintenanceHeading'],
|
||||
'siteMaintenanceMeta' => $u['siteMaintenanceMeta'],
|
||||
'siteMaintenanceContent' => $u['siteMaintenanceContent'],
|
||||
'siteMaintenance' => $u['siteMaintenance'],
|
||||
'siteAdditionalJS' => $u['siteAdditionalJS'],
|
||||
);
|
||||
endforeach;
|
||||
return $page;
|
||||
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
51
application/models/Page_model.php
Executable file
51
application/models/Page_model.php
Executable file
@@ -0,0 +1,51 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
|
||||
class Page_model extends MY_Model
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
private static function init()
|
||||
{
|
||||
return get_instance()->db->from('cm_page_attributes')
|
||||
->join('cm_page_content', 'cm_page_content.pageID = cm_page_attributes.pageID')
|
||||
->join('cm_page_meta', 'cm_page_meta.pageID = cm_page_attributes.pageID')
|
||||
->where("pagePublished", 1);
|
||||
}
|
||||
|
||||
public function getOne($pageUrl)
|
||||
{
|
||||
$pageUrl = is_array($pageUrl) ? $pageUrl : [$pageUrl];
|
||||
return self::init()->where_in("cm_page_content.pageID", $pageUrl)->get()->row();
|
||||
}
|
||||
|
||||
public function getPageDelivery($pageID)
|
||||
{
|
||||
$this->db->join('cm_page_attributes', 'cm_page_attributes.pageID=cm_delivery.pageID');
|
||||
return $this->db->where('cm_page_attributes.pageID', $pageID)->get('cm_delivery')->result();
|
||||
}
|
||||
|
||||
public function getTablePageTitle(&$rows)
|
||||
{
|
||||
if (count($rows)) {
|
||||
$pages = get_instance()->db
|
||||
->join('cm_post_page', 'cm_page_content.pageID=cm_post_page.pageID', 'left')
|
||||
->where_in('cm_post_page.postID', array_column($rows, 'postID'))->get('cm_page_content')->result();
|
||||
foreach ($rows as $k => $row) {
|
||||
$rows[$k]['pages'] = [];
|
||||
foreach ($pages as $r) {
|
||||
if ($row['postID'] == $r->postID) {
|
||||
$rows[$k]['pages'][] = $r->pageID;
|
||||
$rows[$k]['pageTitle'] = (empty($rows[$k]['pageTitle']) ? '' : $rows[$k]['pageTitle'] . ', ') . $r->pageTitle;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
313
application/models/Post_model.php
Executable file
313
application/models/Post_model.php
Executable file
@@ -0,0 +1,313 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
|
||||
class Post_model extends MY_Model
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getPostQuery()
|
||||
{
|
||||
get_instance()->load->library('session');
|
||||
get_instance()->db->from('cm_post p')
|
||||
->join('cm_post_category pc', 'p.postID=pc.postID', 'left')
|
||||
->join('cm_category c', 'pc.categoryID=c.categoryID', 'left')
|
||||
->join('cm_post_page pp', 'p.postID=pp.postID', 'left');
|
||||
if (!isAdminSite() && !get_instance()->session->userdata('userName')) {
|
||||
get_instance()->db->where('p.published', 1);
|
||||
}
|
||||
return get_instance()->db;
|
||||
}
|
||||
|
||||
public function getPostsByCategoryId($categories, $limit, $offset = 0)
|
||||
{
|
||||
$categories = is_array($categories) ? $categories : [$categories];
|
||||
return $this->getPostQuery()
|
||||
->where_in('c.categoryID', $categories)
|
||||
->limit($limit)->order_by('datePosted', 'desc')
|
||||
->offset($offset)
|
||||
->select('*, p.postID postSeq');
|
||||
}
|
||||
|
||||
public function getPagePostsByCategoryId($categories, $limit, $offset = 0)
|
||||
{
|
||||
$categories = is_array($categories) ? $categories : [$categories];
|
||||
return $this->getPostQuery()
|
||||
->join('cm_page_content co', 'pp.pageID=co.pageID', 'left')
|
||||
->where_in('c.categoryID', $categories)
|
||||
->limit($limit)->order_by('datePosted', 'desc')
|
||||
->offset($offset);
|
||||
}
|
||||
|
||||
public function getPagePostsByPageId($PageId, $limit = 0, $offset = 0)
|
||||
{
|
||||
$PageId = is_array($PageId) ? $PageId : [$PageId];
|
||||
return $this->getPostQuery()
|
||||
->join('cm_page_content co', 'pp.pageID=co.pageID', 'left')
|
||||
->join('cm_page_attributes pa', 'pp.pageID=pa.pageID', 'left')
|
||||
->where_in('pp.pageID', $PageId)
|
||||
->limit($limit)->order_by('datePosted', 'desc')
|
||||
->offset($offset)
|
||||
->select('*, p.postID postSeq')
|
||||
->group_by('p.postID');
|
||||
}
|
||||
|
||||
public function getCountPostsByCategoryId($categories)
|
||||
{
|
||||
$categories = is_array($categories) ? $categories : [$categories];
|
||||
return $this->getPostQuery()
|
||||
->where_in('c.categoryID', $categories)
|
||||
->count_all_results();
|
||||
}
|
||||
|
||||
public function getCountPostsByPageId($pageId)
|
||||
{
|
||||
$pageId = is_array($pageId) ? $pageId : [$pageId];
|
||||
return $this->getPostQuery()
|
||||
->where_in('pp.pageID', $pageId)
|
||||
->count_all_results();
|
||||
}
|
||||
|
||||
public function getPostsByPageId($pageId, $limit)
|
||||
{
|
||||
$pageId = is_array($pageId) ? $pageId : [$pageId];
|
||||
return $this->getPostQuery()
|
||||
->where_in('pp.pageID', $pageId)
|
||||
->limit($limit)->order_by('datePosted', 'desc')
|
||||
->select('*, p.postID postSeq')
|
||||
->group_by('p.postID');
|
||||
}
|
||||
|
||||
public function getPostsRatingByPageId($pageId, $limit)
|
||||
{
|
||||
$pageId = is_array($pageId) ? $pageId : [$pageId];
|
||||
return $this->getPostQuery()
|
||||
->join('cm_post_ranking pr', "p.postID=pr.postID", 'left')
|
||||
->where_in('pp.pageID', $pageId)
|
||||
->limit($limit)
|
||||
->group_by('p.postID')
|
||||
->select('*, p.postID postSeq');
|
||||
}
|
||||
|
||||
public function getPostsByPageIdAndCategoryId($pageId, $categoryId, $limit)
|
||||
{
|
||||
$pageId = is_array($pageId) ? $pageId : [$pageId];
|
||||
$categoryId = is_array($categoryId) ? $categoryId : [$categoryId];
|
||||
return $this->getPostQuery()
|
||||
->where_in('c.categoryID', $categoryId)
|
||||
->where_in('pp.pageID', $pageId)
|
||||
->limit($limit)->order_by('datePosted', 'desc');
|
||||
}
|
||||
|
||||
public function getCountPostsByPageIdAndCategoryId($pageId, $categoryId)
|
||||
{
|
||||
$pageId = is_array($pageId) ? $pageId : [$pageId];
|
||||
$categoryId = is_array($categoryId) ? $categoryId : [$categoryId];
|
||||
return $this->getPostQuery()
|
||||
->where_in('c.categoryID', $categoryId)
|
||||
->where_in('pp.pageID', $pageId)
|
||||
->order_by('datePosted', 'desc')->count_all_results();
|
||||
}
|
||||
|
||||
public function getPostsRankingByRankTypeAndCategoryId($rankType, $categoryId, $limit)
|
||||
{
|
||||
$categoryId = is_array($categoryId) ? $categoryId : [$categoryId];
|
||||
return $this->getPostQuery()
|
||||
->join('cm_post_ranking pr', "p.postID=pr.postID and pr.title='$rankType'", 'left')
|
||||
->where_in('c.categoryID', $categoryId)
|
||||
->group_by('p.postID')
|
||||
->limit($limit)->order_by('datePosted', 'desc')
|
||||
->select('*, p.postID postSeq');
|
||||
}
|
||||
|
||||
public function getPost($postURL)
|
||||
{
|
||||
return isAdminSite() ? (function () use ($postURL) {
|
||||
return $this->getPostQuery()
|
||||
->join('cm_post_thumb t', 'p.postID=t.postID', 'left')
|
||||
->join('cm_post_schedule s', 'p.postID=s.postID', 'left')
|
||||
->where('p.postID', $postURL)
|
||||
->select('p.*, c.*, t.thumb postThumb, s.run_at dateReserved')->group_by('p.postID');
|
||||
})() : $this->getPostQuery()->where('p.postURL', $postURL)->select('*, p.postID postSeq')->get()->row();
|
||||
}
|
||||
|
||||
public function getPosts($limit, $offset)
|
||||
{
|
||||
if (isAdminSite()) {
|
||||
if ($term = getSearchTerm()) {
|
||||
$this->db->like("p.postTitle", $term)->or_like("p.postExcerpt", $term)
|
||||
->or_like("c.categoryTitle", $term)->or_where('p.postID', $term)
|
||||
->or_like('pcn.pageTitle', $term);
|
||||
}
|
||||
return $this->getPostQuery()
|
||||
->join('cm_user u', 'p.userID = u.userID', 'left')
|
||||
->join('cm_page_content pcn', 'pp.pageID=pcn.pageID', 'left')
|
||||
->group_by('p.postID')->order_by('dateUpdated', 'desc')
|
||||
->limit($limit)->offset($offset);
|
||||
}
|
||||
}
|
||||
|
||||
public function getPostsRankingByPostId($postId)
|
||||
{
|
||||
return $this->db->where_in('postID', $postId)->from('cm_post_ranking');
|
||||
}
|
||||
|
||||
public function getPostsScheduled()
|
||||
{
|
||||
return get_instance()->db->where('done', 'N')->get('cm_post_schedule')->result();
|
||||
}
|
||||
|
||||
public function publishPosts($postIds)
|
||||
{
|
||||
get_instance()->db->where_in('postID', $postIds)->update('cm_post', ['published' => 1]);
|
||||
get_instance()->db->where_in('postID', $postIds)->update('cm_post_schedule', ['done' => 'Y']);
|
||||
return get_instance()->db->affected_rows();
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$categoryID = 0;
|
||||
$data = array(
|
||||
'postTitle' => $this->input->post('postTitle'),
|
||||
'postSubTitle' => $this->input->post('postSubTitle'),
|
||||
'categoryID' => $categoryID,
|
||||
// 'postURL' => $this->input->post('postURL'),
|
||||
// 'postContent' => $this->input->post('content'),
|
||||
'postContentHTML' => $this->input->post('content'),
|
||||
'postExcerpt' => $this->input->post('postExcerpt'),
|
||||
'published' => $this->input->post('published'),
|
||||
'datePosted' => date('Y-m-d H:i:s'),
|
||||
'dateUpdated' => date('Y-m-d H:i:s'),
|
||||
'unixStamp' => $this->input->post('unixStamp'),
|
||||
);
|
||||
if ($this->input->post('postImage') != "") {
|
||||
$data['postImage'] = $this->input->post('postImage');
|
||||
}
|
||||
$this->db->insert('cm_post', $data);
|
||||
$insertID = $this->db->insert_id();
|
||||
|
||||
if ($this->input->post('postTag')) {
|
||||
$this->db->where('postID', $insertID)->delete('cm_post_tag');
|
||||
$this->db->insert('cm_post_tag', ['postID' => $insertID, 'tag' => $this->input->post('postTag')]);
|
||||
}
|
||||
|
||||
$this->postThumbnail($insertID, $this->input->post('postThumb'));
|
||||
$this->addPostCategory($insertID, $this->input->post('categories') ? explode(',', $this->input->post('categories')) : []);
|
||||
$this->addPostPage($insertID, $this->input->post('pages') ? explode(',', $this->input->post('pages')) : []);
|
||||
$this->db->where('postID', $insertID)->update('cm_post', array('postURL' => $insertID));
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$categoryID = 0;
|
||||
$this->addPostCategory($id, $this->input->post('categories') ? explode(',', $this->input->post('categories')) : []);
|
||||
$this->addPostPage($id, $this->input->post('pages') ? explode(',', $this->input->post('pages')) : []);
|
||||
|
||||
if ($this->input->post('video')) {
|
||||
$this->db->where('postID', $id)->update('cm_post_video', ['videoURL' => '']);
|
||||
}
|
||||
|
||||
if ($this->input->post('postTag')) {
|
||||
$this->db->where('postID', $id)->delete('cm_post_tag');
|
||||
$this->db->insert('cm_post_tag', ['postID' => $id, 'tag' => $this->input->post('postTag')]);
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'postTitle' => $this->input->post('postTitle'),
|
||||
'postSubTitle' => $this->input->post('postSubTitle'),
|
||||
'categoryID' => $categoryID,
|
||||
// 'postURL' => $this->input->post('postURL'),
|
||||
'postContentHTML' => $this->input->post('content'),
|
||||
'postExcerpt' => $this->input->post('postExcerpt'),
|
||||
'published' => $this->input->post('published'),
|
||||
'dateUpdated' => date('Y-m-d H:i:s'),
|
||||
'unixStamp' => $this->input->post('unixStamp'),
|
||||
'userID' => $this->input->post('userID')
|
||||
);
|
||||
if ($this->input->post('postImage')) {
|
||||
$data['postImage'] = '/images/' . date('Y/m/d/') . $this->input->post('postImage');
|
||||
}
|
||||
$this->postThumbnail($id, $this->input->post('postThumb'));
|
||||
$this->db->where("postID", $id);
|
||||
$this->db->update('cm_post', $data);
|
||||
}
|
||||
|
||||
private function postThumbnail($postId, $thumb)
|
||||
{
|
||||
if ($thumb) {
|
||||
$thumb = '/thumbs/' . date('Y/m/d/') . $thumb;
|
||||
$this->db->where('postID', $postId)->delete('cm_post_thumb');
|
||||
$this->db->insert('cm_post_thumb', ['postID' => $postId, 'thumb' => $thumb]);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
}
|
||||
|
||||
public function addPostCategory($postID, $categories)
|
||||
{
|
||||
$tmp = [];
|
||||
$this->db->where('postID', $postID)->delete('cm_post_category');
|
||||
if (count($categories)) {
|
||||
return $this->db->insert_batch('cm_post_category', array_filter(array_map(function ($category) use ($postID) {
|
||||
return ['postID' => $postID, 'categoryID' => $category];
|
||||
}, $categories), function ($c) use (&$tmp) {
|
||||
$isDup = $c['categoryID'] ? false : true;
|
||||
if (!$isDup) {
|
||||
foreach ($tmp as $t) {
|
||||
if ($t['categoryID'] == $c['categoryID']) {
|
||||
$isDup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
array_push($tmp, $c);
|
||||
if (!$isDup) {
|
||||
return $c;
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public function addPostPage($postID, $pages)
|
||||
{
|
||||
$tmp = [];
|
||||
$this->db->where('postID', $postID)->delete('cm_post_page');
|
||||
if (count($pages)) {
|
||||
return $this->db->insert_batch('cm_post_page', array_filter(array_map(function ($page) use ($postID) {
|
||||
return ['postID' => $postID, 'pageID' => $page];
|
||||
}, $pages), function ($c) use (&$tmp) {
|
||||
$isDup = $c['pageID'] ? false : true;
|
||||
if (!$isDup) {
|
||||
foreach ($tmp as $t) {
|
||||
if ($t['pageID'] == $c['pageID']) {
|
||||
$isDup = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
array_push($tmp, $c);
|
||||
if (!$isDup) {
|
||||
return $c;
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public function getPostVideo($postId)
|
||||
{
|
||||
return $this->db->where('postID', $postId)->get('cm_post_video')->row();
|
||||
}
|
||||
|
||||
public function getPostTag($postId)
|
||||
{
|
||||
$query = $this->db->where('postID', $postId)->get('cm_post_tag');
|
||||
return $query->num_rows() ? array_map(function ($row) {
|
||||
$row['tag'] = explode(strpos($row['tag'], ',') ? ',':' ', $row['tag']);
|
||||
return $row;
|
||||
}, $query->result_array())[0] : ['tag' => []];
|
||||
}
|
||||
}
|
||||
106
application/models/Pray_model.php
Executable file
106
application/models/Pray_model.php
Executable file
@@ -0,0 +1,106 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
|
||||
class Pray_model extends MY_Model
|
||||
{
|
||||
|
||||
private $table = 'cm_pray';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getPrayQuery()
|
||||
{
|
||||
return $this->db->from($this->table)->order_by('dateUpdated', 'desc');
|
||||
}
|
||||
|
||||
public function getPaging($limit, $offset = 0)
|
||||
{
|
||||
if (!isAdminSite()) {
|
||||
$this->db->where('dateDeleted is null');
|
||||
}
|
||||
return $this->db->from($this->table . ' py')
|
||||
->select("py.*, if(u.nickname = '' or u.nickname is null, u.userName, u.nickName) as nickname")
|
||||
->join('cm_user u', 'py.userID=u.userID', 'left')
|
||||
->order_by('dateUpdated', 'desc')
|
||||
->limit($limit)->offset($offset);
|
||||
}
|
||||
|
||||
public function getCountPaging()
|
||||
{
|
||||
if (!isAdminSite()) {
|
||||
$this->db->where('dateDeleted is null');
|
||||
}
|
||||
return $this->db->from($this->table)
|
||||
->count_all_results();
|
||||
}
|
||||
|
||||
public function getAll($limit, $offiset)
|
||||
{
|
||||
return $this->getPostQuery()->limit($limit)->offset($offiset);
|
||||
}
|
||||
|
||||
public function getOne($prayId)
|
||||
{
|
||||
return $this->db->where('prayID', $prayId)->get($this->table)->row();
|
||||
}
|
||||
|
||||
public function save($data)
|
||||
{
|
||||
$this->db->insert($this->table, $data);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function update($prayId, $data)
|
||||
{
|
||||
$this->db->where('prayID', $prayId)->update($this->table, $data);
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
|
||||
public function delete($prayId)
|
||||
{
|
||||
return $this->db->where('prayID', $prayId)->delete($this->table);
|
||||
}
|
||||
|
||||
public function bookmark($data)
|
||||
{
|
||||
$this->db->insert('cm_pray_ranking', $data);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function getBookmarksAndRankings(&$prayers)
|
||||
{
|
||||
if (count($prayers)) {
|
||||
$userID = getSessionUser()->is ? getSessionUser()->userID : 0;
|
||||
array_map(function ($rating) use (&$prayers, $userID) {
|
||||
foreach ($prayers as $k => $v) {
|
||||
if ($v->prayID == $rating->prayID) {
|
||||
if ($rating->title == 1) {
|
||||
$prayers[$k]->like++;
|
||||
} else if($rating->title == 3){
|
||||
if($rating->userID == $userID) {
|
||||
$prayers[$k]->bookmark = 1;
|
||||
}
|
||||
$prayers[$k]->bookmarks++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, $this->getRankingsByPrayId(array_column($prayers, 'prayID')));
|
||||
}
|
||||
}
|
||||
|
||||
private function getRankingsByPrayId($prayId)
|
||||
{
|
||||
$prayId = is_array($prayId) ? $prayId : [$prayId];
|
||||
return $this->db->where_in('prayID', $prayId)
|
||||
->get('cm_pray_ranking')->result();
|
||||
}
|
||||
|
||||
public function getPrayRankingCountByTitle($prayId, $title) {
|
||||
return $this->db->where('prayID', $prayId)->where('title', $title)->count_all_results('cm_pray_ranking');
|
||||
}
|
||||
}
|
||||
15
application/models/Settings_model.php
Executable file
15
application/models/Settings_model.php
Executable file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
class Settings_model extends MY_Model {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function findBySiteID(int $siteID) {
|
||||
return $this->db->where("siteID", $siteID)
|
||||
->get('cm_settings')
|
||||
->row();
|
||||
}
|
||||
}
|
||||
49
application/models/User_model.php
Executable file
49
application/models/User_model.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
|
||||
class User_model extends MY_Model
|
||||
{
|
||||
|
||||
private $db;
|
||||
private $table = 'cm_user';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db = &get_instance()->db;
|
||||
}
|
||||
|
||||
private function init()
|
||||
{
|
||||
return $this->db->from('cm_user');
|
||||
}
|
||||
|
||||
public function getOne($seq)
|
||||
{
|
||||
return self::init()->where_in("seq", $seq)->get()->row();
|
||||
}
|
||||
|
||||
public function findByUserName($userName)
|
||||
{
|
||||
return $this->init()->where('userName', $userName)
|
||||
->get()->result();
|
||||
}
|
||||
|
||||
public function findByEmail($email)
|
||||
{
|
||||
return $this->init()->where('email', $email)
|
||||
->get()->result();
|
||||
}
|
||||
|
||||
public function save($data)
|
||||
{
|
||||
return $this->db->insert_batch('cm_user', is_array($data) ? $data : [$data]);
|
||||
}
|
||||
|
||||
public function getAdminSiteUsers()
|
||||
{
|
||||
return $this->db->where_in('roleID', [2, 5, 7])->get($this->table)->result();
|
||||
}
|
||||
}
|
||||
10
application/models/index.html
Executable file
10
application/models/index.html
Executable file
@@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user