/www/application/modules/rss/rss.php

https://github.com/kelios/imshop · PHP · 135 lines · 87 code · 28 blank · 20 comment · 10 complexity · 7ef593a848cff5a7ae4998dc514f7ee3 MD5 · raw file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * Image CMS
  4. *
  5. * RSS Module
  6. */
  7. class Rss extends MY_Controller {
  8. private $settings = array();
  9. private $rss_header = '<?xml version="1.0" encoding="UTF-8"?>';
  10. private $cache_key = 'rss';
  11. function __construct()
  12. {
  13. parent::__construct();
  14. }
  15. public function index()
  16. {
  17. if (($content = $this->cache->fetch($this->cache_key)) !== FALSE)
  18. {
  19. // rss feed fetched from cache
  20. }
  21. else
  22. {
  23. $this->load->library('lib_category');
  24. $this->settings = $this->_load_settings();
  25. if ($this->settings['pages_count'] == 0)
  26. {
  27. $this->settings['pages_count'] = 10;
  28. }
  29. $pages = $this->get_pages();
  30. $cnt = count($pages);
  31. if ($cnt > 0)
  32. {
  33. for($i = 0; $i < $cnt; $i++)
  34. {
  35. $pages[$i]['prev_text'] = htmlspecialchars_decode($pages[$i]['prev_text']);
  36. if ($pages[$i]['category'] > 0)
  37. {
  38. $category = $this->lib_category->get_category($pages[$i]['category']);
  39. $pages[$i]['title'] = $category['name'] .' / '. $pages[$i]['title'];
  40. $pages[$i]['publish_date'] = gmdate('D, d M Y H:i:s', $pages[$i]['publish_date']).' GMT';
  41. }
  42. }
  43. }
  44. $tpl_data = array(
  45. 'header' => $this->rss_header,
  46. 'title' => $this->settings['title'],
  47. 'description' => $this->settings['description'],
  48. 'pub_date' => gmdate('D, d M Y H:i:s', time()).' GMT',
  49. 'items' => $pages,
  50. );
  51. $this->template->add_array($tpl_data);
  52. $content = $this->fetch_tpl('feed_theme');
  53. $this->cache->store($this->cache_key, $content, $this->settings['cache_ttl'] * 60);
  54. }
  55. echo $content;
  56. }
  57. /**
  58. * Load pages
  59. */
  60. private function get_pages()
  61. {
  62. $this->db->select('CONCAT_WS("", cat_url, url) as full_url, id, title, prev_text, publish_date, category, author', FALSE);
  63. $this->db->where('post_status', 'publish');
  64. $this->db->where('prev_text !=', 'null');
  65. $this->db->where('publish_date <=', time());
  66. if ( count($this->settings['categories']) > 0)
  67. {
  68. $this->db->where_in('category', $this->settings['categories']);
  69. }
  70. $this->db->order_by('publish_date', 'desc');
  71. $query = $this->db->get('content', $this->settings['pages_count']);
  72. return $query->result_array();
  73. }
  74. /**
  75. * Load rss settings
  76. */
  77. public function _load_settings()
  78. {
  79. $this->db->where('name', 'rss');
  80. $query = $this->db->get('components', 1)->row_array();
  81. return unserialize($query['settings']);
  82. }
  83. public function _install()
  84. {
  85. if( $this->dx_auth->is_admin() == FALSE) exit;
  86. // Enable module url access
  87. $this->db->where('name', 'rss');
  88. $this->db->update('components', array('enabled' => '1'));
  89. }
  90. /**
  91. * Display template file
  92. */
  93. private function display_tpl($file = '')
  94. {
  95. $file = realpath(dirname(__FILE__)).'/templates/public/'.$file.'.tpl';
  96. $this->template->display('file:'.$file);
  97. }
  98. /**
  99. * Fetch template file
  100. */
  101. private function fetch_tpl($file = '')
  102. {
  103. $file = realpath(dirname(__FILE__)).'/templates/public/'.$file.'.tpl';
  104. return $this->template->fetch('file:'.$file);
  105. }
  106. }
  107. /* End of file sample_module.php */