0byt3m1n1
Path:
/
data
/
17
/
1
/
18
/
11
/
1670011
/
user
/
1801231
/
htdocs
/
marketting
/
system
/
application
/
models
/
[
Home
]
File: content_model.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); /* | ------------------------------------------------------------------------- | COPYRIGHT NOTICE | Copyright 2008 JROX Technologies, Inc. All Rights Reserved. | ------------------------------------------------------------------------- | This script may be only used and modified in accordance to the license | agreement attached (license.txt) except where expressly noted within | commented areas of the code body. This copyright notice and the | comments above and below must remain intact at all times. By using this | code you agree to indemnify JROX Technologies, Inc, its corporate agents | and affiliates from any liability that might arise from its use. | | Selling the code for this program without prior written consent is | expressly forbidden and in violation of Domestic and International | copyright laws. | | ------------------------------------------------------------------------- | FILENAME - content_model.php | ------------------------------------------------------------------------- | | This model handles the functions for managing content | */ class Content_Model extends Model { function _get_homepage() { $this->db->where('article_id', '1'); $query = $this->db->get('content_articles'); $row = $query->row_array(); if ($row['content_type'] == '3') { $this->load->helper('file'); $row['content_body'] = read_file($row['content_path']); } else { $row['content_body'] = html_entity_decode($row['content_body']); } $row['content_title_url'] = url_title($row['content_title']); return $row; } // ------------------------------------------------------------------------ function _get_content_notification() { $this->db->where('ping', '0'); $this->db->where('category_id !=', '5'); $this->db->where('category_id !=', '6'); $this->db->where('content_type', '1'); $this->db->where('status', '1'); $this->db->where('date_published <=', now()); $query = $this->db->get('content_articles'); if ($query->num_rows() > 0) { $fdate = explode(':', $this->config->item('sts_admin_date_format')); $a = array(); foreach ($query->result_array() as $row) { $row['date_published'] = date($fdate[1], $row['date_published']); //format url $row['url'] = _format_url(CONTENT_ROUTE . '/article', $row['article_id'], $row['content_title']); array_push($a, $row); } return $a; } return false; } // ------------------------------------------------------------------------ function _update_blog_id($cid = '', $blog_id = '') { $this->db->where('article_id', $cid); if ($this->db->update('content_articles', array('remote_blog_id' => $blog_id))) { return true; } return false; } // ------------------------------------------------------------------------ function _update_ping($id = '') { $data = array('ping' => '1'); $this->db->where('article_id', $id); $this->db->update('content_articles', $data); } // ------------------------------------------------------------------------ function _add_content_article($array = '') { $data = $this->db_validation_model->_clean_data($array); unset($data['publish_wordpress']); //format date $fdate = explode(':', $this->config->item('sts_admin_date_format')); switch ($fdate[0]) { case 'mm/dd/yyyy': if (!empty($data['date_published'])) { //format date $pub = explode('/', $data['date_published']); $data['date_published'] = mktime(date('H'),date('i'),date('s'), $pub[0], $pub[1], $pub[2]); } break; } //add modified by $data['modified_by'] = $this->session->userdata('username'); if ($this->config->item('content_enable_javascript_code') == true) { $data['content_body'] = $_POST['content_body']; } //insert into db if (!$this->db->insert('content_articles', $data)) { show_error($this->lang->line('could_not_add_content')); //log error log_message('error', 'Could not insert content into content table'); return false; } else { $data['article_id'] = $this->db->insert_id(); //log success log_message('info', 'content '. $data['article_id'] . ' inserted into content table'); } return $data; } // ------------------------------------------------------------------------ function _delete_content_article($id = '') { if ($id == 1) { return false; } //delete content $this->db->where('article_id', $id); if ($this->db->delete('content_articles')) { //log success log_message('info', 'content ID #' . $id . ' deleted successfully'); } else { show_error($this->lang->line('could_not_delete_content')); //log error log_message('error', 'content ID #' . $id . ' could not be deleted'); } return true; } // ------------------------------------------------------------------------ function _add_article_comment() { $data = $this->db_validation_model->_clean_data($_POST); //check article ID $article = $this->_get_content_article_details($data['article_id']); if ($article[0]['content_type'] != '1') { return false; } $data['date'] = _generate_timestamp(); $data['member_id'] = $this->session->userdata('userid'); $data['comment'] = $data['article_comment']; unset($data['article_comment']); $data['status'] = $this->config->item('sts_content_require_comment_moderation') == 1 ? '0' : '1'; //insert into db if (!$this->db->insert('content_comments', $data)) { show_error($this->lang->line('could_not_add_comment')); //log error log_message('error', 'Could not insert comments into content comments table'); return false; } else { $data['comment_id'] = $this->db->insert_id(); //log success log_message('info', 'content '. $data['comment_id'] . ' inserted into comment comments table'); } return $data['comment_id']; } // ------------------------------------------------------------------------ function _get_content_article_details($id = '') { //get the data from content table $this->db->where('article_id', $id); //$this->db->join('content_categories', 'content_articles.category_id=content_categories.category_id', 'left'); $query = $this->db->get('content_articles'); if ($query->num_rows() > 0) { return $query->result_array(); } else { return false; } } // ------------------------------------------------------------------------ function _get_article_details($id = '') { //get the data from content table if ($this->session->userdata('adminid')) { $sql = 'SELECT ' . $this->db->dbprefix('content_articles') . '.*, ' . $this->db->dbprefix('content_categories') . '.* FROM ' . $this->db->dbprefix('content_articles') . ' LEFT JOIN ' . $this->db->dbprefix('content_categories') . ' ON ' . $this->db->dbprefix('content_articles') . '.category_id = ' . $this->db->dbprefix('content_categories') . '.category_id WHERE ' . $this->db->dbprefix('content_articles') . '.article_id = ' . $id . ' GROUP BY ' . $this->db->dbprefix('content_articles') . '.article_id'; } else { $sql = 'SELECT ' . $this->db->dbprefix('content_articles') . '.*, ' . $this->db->dbprefix('content_categories') . '.* FROM ' . $this->db->dbprefix('content_articles') . ' LEFT JOIN ' . $this->db->dbprefix('content_categories') . ' ON ' . $this->db->dbprefix('content_articles') . '.category_id = ' . $this->db->dbprefix('content_categories') . '.category_id WHERE ' . $this->db->dbprefix('content_articles') . '.article_id = ' . $id . ' AND date_published <=' . now() . ' AND ' . $this->db->dbprefix('content_articles') . '.status = \'1\' GROUP BY ' . $this->db->dbprefix('content_articles') . '.article_id'; } $query = $this->db->query($sql); if ($query->num_rows() > 0) { $row = $query->row_array(); if ($row['content_type'] == '3') { $this->load->helper('file'); $row['content_body'] = read_file($row['content_path']); } else { $row['content_body'] = html_entity_decode($row['content_body']); $row['content_body'] = str_replace('{more}', '', $row['content_body']); //add content blocks $row['content_body'] = str_replace('{content_ad_block_1}', html_entity_decode($this->config->item('module_advertising_ad_block_content_ad_1')), $row['content_body']); $row['content_body'] = str_replace('{content_ad_block_2}', html_entity_decode($this->config->item('module_advertising_ad_block_content_ad_2')), $row['content_body']); } $row['content_title_url'] = url_title($row['content_title']); $row['content_date'] = _show_date($row['date_published']); //get comments $row['comments'] = array(); if ($this->config->item('sts_content_enable_comments') == 1) { $sql = 'SELECT ' . $this->db->dbprefix('content_comments') . '.*, (SELECT ' . $this->db->dbprefix('members') . '.fname from ' . $this->db->dbprefix('members') . ' WHERE ' . $this->db->dbprefix('content_comments') . '.member_id = ' . $this->db->dbprefix('members') . '.member_id) as name FROM ' . $this->db->dbprefix('content_comments') . ' WHERE article_id = \'' . $id . '\' AND status = \'1\' ORDER BY date ASC'; $query = $this->db->query($sql); if ($query->num_rows() > 0) { $i = 1; foreach ($query->result_array() as $srow) { $srow['date'] = _show_date($srow['date'], true); $srow['comment'] = nl2br($srow['comment']); $srow['comment_number'] = $i; array_push($row['comments'], $srow); $i++; } } } return $row; } return false; } // ------------------------------------------------------------------------ function _get_homepage_articles() { $this->load->helper('file'); $this->db->where('date_published <=', now()); $this->db->where('status', '1'); $this->db->where('category_id', '1'); $this->db->where('content_type' , '1'); $this->db->order_by('date_published', 'DESC'); $this->db->limit($this->config->item('sts_content_articles_home_page')); $query = $this->db->get('content_articles'); if ($query->num_rows() > 0) { $data = array(); foreach ($query->result_array() as $row) { if ($row['content_type'] == '3') { $row['content_body'] = read_file($row['content_path']); } //get the preview text $body = explode('{more}', $row['content_body']); $row['content_body'] = html_entity_decode($body[0]); $row['content_title_url'] = url_title($row['content_title']); array_push($data, $row); } return $data; } return false; } // ------------------------------------------------------------------------ function _get_dashboard_content($id = '') { $this->db->where('category_id', $id); $this->db->where('date_published <=', now()); $this->db->where('status', '1'); $this->db->order_by('date_published', 'DESC'); $this->db->limit($this->config->item('sts_content_members_dashboard_num_articles')); $query = $this->db->get('content_articles'); if ($query->num_rows() > 0) { $a = array(); foreach ($query->result_array() as $row) { $row['content_title_url'] = url_title($row['content_title']); if ($row['content_type'] == '3') { $row['content_body'] = read_file($row['content_path']); } //get the preview text $body = explode('{more}', $row['content_body']); $row['content_body'] = $this->init->_parse_member_data(html_entity_decode($body[0])); $row['content_title_url'] = url_title($row['content_title']); $row['content_date'] = _show_date($row['date_published']); array_push($a, $row); } return $a; } return false; } // ------------------------------------------------------------------------ function _check_perms($type = '', $cat_id = '') { switch ($type) { case 'members': return true; break; default: if ($cat_id == '5' || $cat_id == '6') { redirect(); exit(); } break; } return true; } // ------------------------------------------------------------------------ function _get_members_content($id = '', $limit = 25, $offset = 0, $sort_column = '', $sort_order = '') { //get all the admins from db for list view if (!$sort_order) $sort_order = $this->config->item('mem_dbs_cnt_order'); if (!$sort_column) $sort_column = $this->config->item('mem_dbs_cnt_column'); if ($this->session->userdata('adminid')) { $this->db->where('category_id', $id); $this->db->order_by($this->config->item('mem_dbs_cnt_column'), $this->config->item('mem_dbs_cnt_order')); $this->db->limit($limit, $offset); } else { $this->db->where('category_id', $id); $this->db->where('date_published <=', now()); $this->db->where('status', '1'); $this->db->order_by($this->config->item('mem_dbs_cnt_column'), $this->config->item('mem_dbs_cnt_order')); $this->db->limit($limit, $offset); } $query = $this->db->get('content_articles'); if ($query->num_rows() > 0) { $a['articles'] = array(); foreach ($query->result_array() as $row) { $row['content_title_url'] = url_title($row['content_title']); if ($row['content_type'] == '3') { $row['content_body'] = read_file($row['content_path']); } //get the preview text $body = explode('{more}', $row['content_body']); $row['content_body'] = $this->init->_parse_member_data(html_entity_decode($body[0])); $row['content_title_url'] = url_title($row['content_title']); $row['content_date'] = _show_date($row['date_published']); $row['row_style'] = alternator('jroxRowStyle1', 'jroxRowStyle2'); array_push($a['articles'], $row); } //get total rows $this->db->where('category_id', $id); $this->db->where('date_published <=', now()); $this->db->where('status', '1'); $this->db->from('content_articles'); $a['total_rows'] = $this->db->count_all_results(); return $a; } return false; } // ------------------------------------------------------------------------ function _get_content_categories($name = true) { $query = $this->db->get('content_categories'); if ($query->num_rows() > 0) { $cat = $query->result_array(); if ($name == true) { $a = format_array($cat, 'category_id', 'category_name'); return $a; } else { return $cat; } } return false; } // ------------------------------------------------------------------------ function _get_content_articles($limit = 25, $offset = 0, $sort_column = '', $sort_order = '') { //get all the admins from db for list view if (!$sort_order) $sort_order = $this->config->item('dbs_crt_order'); if (!$sort_column) $sort_column = $this->config->item('dbs_crt_column'); $sql = 'SELECT ' . $this->db->dbprefix('content_articles') . '.*, (SELECT ' . $this->db->dbprefix('content_categories') . '.category_name from ' . $this->db->dbprefix('content_categories') . ' WHERE ' . $this->db->dbprefix('content_articles') . '.category_id = ' . $this->db->dbprefix('content_categories') . '.category_id) as category FROM ' . $this->db->dbprefix('content_articles') . ' ORDER BY ' . $sort_column . ' ' . $sort_order . ' LIMIT ' . $offset. ', ' . $limit; $query = $this->db->query($sql); if ($query->num_rows() > 0) { return $query->result_array(); } return false; } // ------------------------------------------------------------------------ function _get_site_articles($limit = 25, $offset = 0, $sort_column = '', $sort_order = '', $type = '', $value = '', $cat_type = 'custom', $search = false) { //get all the admins from db for list view if (!$sort_order) $sort_order = $this->config->item('dbs_crt_order'); if (!$sort_column) $sort_column = $this->config->item('dbs_crt_column'); if ($search == true) { $sql = 'SELECT ' . $this->db->dbprefix('content_articles') . '.*, ' . $this->db->dbprefix('content_categories') . '.*, (SELECT COUNT(*) FROM ' . $this->db->dbprefix('content_comments') . ' WHERE ' . $this->db->dbprefix('content_articles') . '.article_id = ' . $this->db->dbprefix('content_comments') . '.article_id AND ' . $this->db->dbprefix('content_comments') . '.status = \'1\') as comments FROM ' . $this->db->dbprefix('content_articles') . ' LEFT JOIN ' . $this->db->dbprefix('content_categories') . ' ON ' . $this->db->dbprefix('content_articles') . '.category_id = ' . $this->db->dbprefix('content_categories') . '.category_id WHERE '. $this->db->dbprefix('content_articles') . '.status = \'1\' AND ' . $this->db->dbprefix('content_categories') . '.category_type = \'' . $cat_type . '\' AND date_published <=' . now() . ' AND ' . $this->db->dbprefix('content_articles') . '.content_type = \'1\' AND (' . $this->db->dbprefix('content_articles') . '.content_body LIKE \'%' . $value . '%\' OR ' . $this->db->dbprefix('content_articles') . '.content_title LIKE \'%' . $value . '%\' OR ' . $this->db->dbprefix('content_articles') . '.content_tags LIKE \'%' . $value . '%\') GROUP BY ' . $this->db->dbprefix('content_articles') . '.article_id ORDER BY ' . $this->db->dbprefix('content_articles') . '.' . $sort_column . ' ' . $sort_order . ' LIMIT ' . $offset. ', ' . $limit; } else { $sql = 'SELECT ' . $this->db->dbprefix('content_articles') . '.*, ' . $this->db->dbprefix('content_categories') . '.*, (SELECT COUNT(*) FROM ' . $this->db->dbprefix('content_comments') . ' WHERE ' . $this->db->dbprefix('content_articles') . '.article_id = ' . $this->db->dbprefix('content_comments') . '.article_id AND ' . $this->db->dbprefix('content_comments') . '.status = \'1\') as comments FROM ' . $this->db->dbprefix('content_articles') . ' LEFT JOIN ' . $this->db->dbprefix('content_categories') . ' ON ' . $this->db->dbprefix('content_articles') . '.category_id = ' . $this->db->dbprefix('content_categories') . '.category_id WHERE ' . $this->db->dbprefix('content_articles') . '.' . $type . ' = ' . $value . ' AND ' . $this->db->dbprefix('content_categories') . '.category_type = \'' . $cat_type . '\' AND date_published <=' . now() . ' AND ' . $this->db->dbprefix('content_articles') . '.status = \'1\' AND ' . $this->db->dbprefix('content_articles') . '.content_type = \'1\' GROUP BY ' . $this->db->dbprefix('content_articles') . '.article_id ORDER BY ' . $this->db->dbprefix('content_articles') . '.' . $sort_column . ' ' . $sort_order . ' LIMIT ' . $offset. ', ' . $limit; } $query = $this->db->query($sql); if ($query->num_rows() > 0) { if ($search == true) { $sql = 'SELECT ' . $this->db->dbprefix('content_articles') . '.*, ' . $this->db->dbprefix('content_categories') . '.* FROM ' . $this->db->dbprefix('content_articles') . ' LEFT JOIN ' . $this->db->dbprefix('content_categories') . ' ON ' . $this->db->dbprefix('content_articles') . '.category_id = ' . $this->db->dbprefix('content_categories') . '.category_id WHERE '. $this->db->dbprefix('content_articles') . '.status = \'1\' AND ' . $this->db->dbprefix('content_categories') . '.category_type = \'' . $cat_type . '\' AND date_published <=' . now() . ' AND ' . $this->db->dbprefix('content_articles') . '.content_type = \'1\' AND (' . $this->db->dbprefix('content_articles') . '.content_body LIKE \'%' . $value . '%\' OR ' . $this->db->dbprefix('content_articles') . '.content_title LIKE \'%' . $value . '%\' OR ' . $this->db->dbprefix('content_articles') . '.content_tags LIKE \'%' . $value . '%\') GROUP BY ' . $this->db->dbprefix('content_articles') . '.article_id'; } else { $sql = 'SELECT ' . $this->db->dbprefix('content_articles') . '.*, ' . $this->db->dbprefix('content_categories') . '.* FROM ' . $this->db->dbprefix('content_articles') . ' LEFT JOIN ' . $this->db->dbprefix('content_categories') . ' ON ' . $this->db->dbprefix('content_articles') . '.category_id = ' . $this->db->dbprefix('content_categories') . '.category_id WHERE ' . $this->db->dbprefix('content_articles') . '.' . $type . ' = ' . $value . ' AND ' . $this->db->dbprefix('content_categories') . '.category_type = \'' . $cat_type . '\' AND date_published <=' . now() . ' AND ' . $this->db->dbprefix('content_articles') . '.status = \'1\' AND ' . $this->db->dbprefix('content_articles') . '.content_type = \'1\' GROUP BY ' . $this->db->dbprefix('content_articles') . '.article_id'; } $squery = $this->db->query($sql); $data['total_rows'] = $squery->num_rows(); $data['rows'] = array(); $this->load->helper('file'); foreach ($query->result_array() as $row) { $row['content_title_url'] = url_title($row['content_title']); if ($row['content_type'] == '3') { $row['content_body'] = read_file($row['content_path']); } //get the preview text $body = explode('{more}', $row['content_body']); $row['content_body'] = html_entity_decode($body[0]); $row['content_title_url'] = url_title($row['content_title']); $row['content_date'] = _show_date($row['date_published']); $row['url_encoded'] = urlencode(_format_url(CONTENT_ROUTE .'/article', $row['article_id'], $row['content_title'])); if ($this->config->item('sts_content_enable_tweetmeme_code') == 1 || $this->config->item('sts_content_enable_facebook_share') == 1) { $row['fb_tweetmeme'] = '<div style="float:left; padding:1em;">'; if ($this->config->item('sts_content_enable_tweetmeme_code') == 1) { $row['fb_tweetmeme'] .= '<iframe scrolling="no" height="61" frameborder="0" width="50" src="http://api.tweetmeme.com/widget.js?url=' . _format_url(CONTENT_ROUTE .'/article', $row['article_id'], $row['content_title']) . '"></iframe>'; } if ($this->config->item('sts_content_enable_facebook_share') == 1) { $row['fb_tweetmeme'] .= ' <a href="javascript:void(window.open(\'http://www.facebook.com/share.php?u=' . $row['url_encoded'] . '\', \'popup\', \'width=850,height=500, location=no, menubar=no, status=no,toolbar=no, scrollbars=yes, resizable=yes\'))"><img src="' . _jrox_public_url() . '/images/misc/fb.png" /></a>'; } $row['fb_tweetmeme'] .= '</div>'; } else { $row['fb_tweetmeme'] = ''; } //check if comments are enabled if ($this->config->item('sts_content_enable_comments') == 1) { if ($this->config->item('sts_content_enable_disqus_form')) { $row['total_comments'] = $this->lang->line('comments'); } else { if ($row['comments'] == '0') { $row['total_comments'] = $this->lang->line('no_comments'); } elseif ($row['comments'] == '1') { $row['total_comments'] = $row['comments'] . ' ' . $this->lang->line('comment'); } else { $row['total_comments'] = $row['comments'] . ' ' . $this->lang->line('comments'); } } } else { $row['total_comments'] = ''; } array_push($data['rows'], $row); } return $data; } return false; } // ------------------------------------------------------------------------ function _update_content_article($id = '', $array = '') { //clean the data first $data = $this->db_validation_model->_clean_data($array); unset($data['publish_wordpress']); //format date $fdate = explode(':', $this->config->item('sts_admin_date_format')); switch ($fdate[0]) { case 'mm/dd/yyyy': if (!empty($data['date_published'])) { //format date $pub = explode('/', $data['date_published']); $data['date_published'] = mktime(date('H'),date('i'),date('s'), $pub[0], $pub[1], $pub[2]); } break; } //add modified by $data['modified_by'] = $this->session->userdata('username'); if ($this->config->item('content_enable_javascript_code') == true) { $data['content_body'] = $_POST['content_body']; } //update content data $this->db->where('article_id', $id); if (!$this->db->update('content_articles', $data)) { show_error($this->lang->line('could_not_update_content')); //log error log_message('error', 'Could not update content ID ' . $id . 'in content table'); return false; } else { //log success log_message('info', 'content ID '. $id . ' updated in content table'); } $data['article_id'] = $id; return $data; } // ------------------------------------------------------------------------ } ?>