PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/TNX_Family/modules/Rss/controllers/admin/rss.php

https://gitlab.com/BGCX261/zillatek-project-svn-to-git
PHP | 238 lines | 126 code | 39 blank | 73 comment | 18 complexity | 0cc1063927ef176fdb87bb01c33f8178 MD5 | raw file
Possible License(s): MIT
  1. <?php if( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * Rss admin controller
  4. *
  5. * The controller that handles actions
  6. * related to Rss module admin.
  7. *
  8. * @author Ionize Dev Team
  9. */
  10. class Rss extends Module_Admin
  11. {
  12. /**
  13. * Constructor
  14. *
  15. * @access public
  16. * @return void
  17. */
  18. function construct()
  19. {
  20. // Article Model : Needed by Rss model to extend Article_model
  21. $this->load->model('article_model', '', TRUE);
  22. $this->load->model('rss_model');
  23. }
  24. /**
  25. * Admin panel
  26. * Called from the modules list.
  27. *
  28. * @access public
  29. * @return parsed view
  30. */
  31. function index()
  32. {
  33. // Get the modules config file
  34. include APPPATH . 'config/modules.php';
  35. // Get the module URI segment
  36. $this->template['uri'] = 'rss';
  37. foreach($modules as $segment => $f)
  38. {
  39. if($f == 'Rss')
  40. $this->template['uri'] = $segment;
  41. }
  42. $this->output('admin/rss');
  43. }
  44. /**
  45. * Saves the config.php settings
  46. *
  47. * @access public
  48. * @return mixed
  49. */
  50. function save_config()
  51. {
  52. // Model used to write config.php
  53. $this->load->model('config_model', '', TRUE);
  54. // Settings to save
  55. $settings = array('module_rss_feed_title', 'module_rss_feed_description', 'module_rss_feed_author');
  56. foreach($settings as $field)
  57. {
  58. $setting = '';
  59. // Set settings only if not FALSE
  60. if($this->input->post($field))
  61. {
  62. $setting = $this->input->post($field);
  63. }
  64. // Try to change the setting
  65. if($this->config_model->change('config.php', $field, addslashes($setting), 'Rss') == FALSE)
  66. {
  67. // Error message
  68. $this->error(lang('module_rss_error_writing_config_file'));
  69. die();
  70. }
  71. }
  72. // Answer
  73. $this->success(lang('ionize_message_operation_ok'));
  74. }
  75. /**
  76. * Returns pages used for Rss
  77. * Used to display pages list.
  78. *
  79. * @access public
  80. * @return parsed view
  81. */
  82. function get_pages()
  83. {
  84. // Page model
  85. $this->load->model('page_model', '', TRUE);
  86. // Rss pages ID
  87. $pages_id = explode(',', config_item('module_rss_pages'));
  88. // All pages
  89. $pages = $this->page_model->get_lang_list(FALSE, Settings::get_lang('default'));
  90. // Used Rss pages (empty array)
  91. $rss_pages = array();
  92. // Get the real used pages
  93. foreach($pages_id as $id)
  94. {
  95. foreach($pages as $page)
  96. {
  97. if($id == $page['id_page'])
  98. {
  99. $rss_pages[] = $page;
  100. }
  101. }
  102. }
  103. // Send Rss pages to template
  104. $this->template['pages'] = $rss_pages;
  105. $this->output('admin/rss_pages');
  106. }
  107. /**
  108. * Add one page to the Rss Feed
  109. * Called when the Admin drags a page to the Rss pages list.
  110. *
  111. * @access public
  112. * @return mixed
  113. */
  114. function add_page()
  115. {
  116. // Model used to write config.php
  117. $this->load->model('config_model', '', TRUE);
  118. // Already linked Rss Pages ID
  119. $pages_id = array();
  120. if(config_item('module_rss_pages') !== '')
  121. $pages_id = explode(',', config_item('module_rss_pages'));
  122. $id_page = $this->input->post('id_page');
  123. if( ! in_array($id_page, $pages_id))
  124. {
  125. $pages_id[] = $id_page;
  126. $pages_id = (count($pages_id) > 1) ? implode(',', $pages_id) : array_shift($pages_id);
  127. if($this->config_model->change('config.php', 'module_rss_pages', $pages_id, 'Rss') == FALSE)
  128. {
  129. // Error message
  130. $this->error(lang('module_rss_error_writing_config_file'));
  131. die();
  132. }
  133. else
  134. {
  135. $this->callback = array(
  136. array(
  137. 'fn' => 'ION.HTML',
  138. 'args' => array(admin_url() . 'module/rss/rss/get_pages', '', array('update' => 'rssPagesContainer'))
  139. ),
  140. array(
  141. 'fn' => 'ION.notification',
  142. 'args' => array('success', lang('ionize_message_operation_ok'))
  143. )
  144. );
  145. $this->response();
  146. }
  147. }
  148. }
  149. /**
  150. * Removes one page from the Rss Feed
  151. * Called when the Admin unlinks a page from the Rss pages list.
  152. *
  153. * @access public
  154. * @return mixed
  155. *
  156. */
  157. function remove_page()
  158. {
  159. // Model used to write config.php
  160. $this->load->model('config_model', '', TRUE);
  161. // Already linked Rss Pages ID
  162. $pages_id = explode(',', config_item('module_rss_pages'));
  163. // The page ID to remove
  164. $id_page = $this->input->post('id_page');
  165. if(in_array($id_page, $pages_id))
  166. {
  167. $new_array = array();
  168. foreach($pages_id as $id)
  169. {
  170. if($id !== $id_page)
  171. $new_array[] = $id;
  172. }
  173. $pages_id = (count($new_array) > 1) ? implode(',', $new_array) : array_shift($new_array);
  174. if($pages_id == FALSE) $pages_id = '';
  175. if($this->config_model->change('config.php', 'module_rss_pages', $pages_id, 'Rss') == FALSE)
  176. {
  177. // Error message
  178. $this->error(lang('module_rss_error_writing_config_file'));
  179. die();
  180. }
  181. else
  182. {
  183. $this->callback = array(
  184. array(
  185. 'fn' => 'ION.HTML',
  186. 'args' => array(admin_url() . 'module/rss/rss/get_pages', '', array('update' => 'rssPagesContainer'))
  187. ),
  188. array(
  189. 'fn' => 'ION.notification',
  190. 'args' => array('success', lang('ionize_message_operation_ok'))
  191. )
  192. );
  193. $this->response();
  194. }
  195. }
  196. }
  197. }
  198. /* End of file rss.php */
  199. /* Location: /modules/Rss/controllers/admin/rss.php */