Files
cm-web/application/models/Hoosk_model.php
pakerpale b5f92c5127 dfgfdg
2020-11-08 18:34:31 +09:00

895 lines
34 KiB
PHP
Executable File

<?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);
}
}
}
}