PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/includes/application/controllers/admin/modules.php

http://68kb.googlecode.com/
PHP | 197 lines | 94 code | 21 blank | 82 comment | 14 complexity | 45430d0708379b9188fa15ac5a4a1820 MD5 | raw file
Possible License(s): CC0-1.0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * 68KB
  4. *
  5. * An open source knowledge base script
  6. *
  7. * @package 68kb
  8. * @author 68kb Dev Team
  9. * @copyright Copyright (c) 2009, 68 Designs, LLC
  10. * @license http://68kb.com/user_guide/license.html
  11. * @link http://68kb.com
  12. * @since Version 1.0
  13. */
  14. // ------------------------------------------------------------------------
  15. /**
  16. * Admin Modules Controller
  17. *
  18. * Handles the modules. Please see the developer module for a brief
  19. * overview or read the documentation.
  20. *
  21. * @package 68kb
  22. * @subpackage Admin_Controllers
  23. * @category Admin_Controllers
  24. * @author 68kb Dev Team
  25. * @link http://68kb.com/user_guide/developer/modules.html
  26. * @version $Id: modules.php 172 2009-12-11 16:18:32Z suzkaw68 $
  27. */
  28. class Modules extends controller
  29. {
  30. var $modules;
  31. function __construct()
  32. {
  33. parent::__construct();
  34. $this->load->model('init_model');
  35. $this->load->model('modules_model');
  36. $this->load->helper('cookie');
  37. $this->load->library('auth');
  38. $this->auth->restrict();
  39. }
  40. // ------------------------------------------------------------------------
  41. /**
  42. * Index controller
  43. *
  44. * Redirects to the Modules->manage()
  45. *
  46. * @access public
  47. */
  48. function index()
  49. {
  50. redirect('admin/modules/manage/');
  51. }
  52. // ------------------------------------------------------------------------
  53. /**
  54. * List all modules
  55. *
  56. * @access public
  57. */
  58. function manage()
  59. {
  60. $data['nav'] = 'settings';
  61. if ( ! $this->auth->check_level(1))
  62. {
  63. $data['not_allowed'] = TRUE;
  64. $this->init_model->display_template('content', $data, 'admin');
  65. return FALSE;
  66. }
  67. $id = (int) $this->uri->segment(4, 0);
  68. $action = $this->uri->segment(5,0);
  69. if ($id > 0 && ($action == 'activate' OR $action == 'deactivate' OR $action = 'upgrade' OR $action == 'delete'))
  70. {
  71. $data['msg'] = $this->modules_model->init_module($id, $action);
  72. }
  73. $data['modules'] = $this->modules_model->load_active();
  74. $data['unactive'] = $this->modules_model->load_unactive();
  75. $this->init_model->display_template('modules/managemodules', $data, 'admin');
  76. }
  77. // ------------------------------------------------------------------------
  78. /**
  79. * Activate a module
  80. *
  81. * @access public
  82. */
  83. function activate($module)
  84. {
  85. $this->modules_model->activate($module);
  86. $this->session->set_flashdata('msg', lang('kb_activated'));
  87. redirect('admin/modules/manage/');
  88. }
  89. // ------------------------------------------------------------------------
  90. /**
  91. * Upgrade a module
  92. *
  93. * @access public
  94. */
  95. function upgrade($id)
  96. {
  97. $this->modules_model->init_module($id, 'upgrade');
  98. $this->session->set_flashdata('msg', lang('kb_upgraded'));
  99. redirect('admin/modules/manage/');
  100. }
  101. /**
  102. * Show a modules admin file.
  103. *
  104. * This is used so you can have module files that are included in the
  105. * theme that is in use. This same method is used for both the front
  106. * end and the administration.
  107. *
  108. * @access public
  109. */
  110. function show()
  111. {
  112. $nav = $this->core_events->trigger('admin/modules/show/nav');
  113. $data['nav'] = ( empty($nav) ) ? 'settings': $nav;
  114. $name = $this->uri->segment(4, 0);
  115. $file = $this->modules_model->show_module($name);
  116. if ($file !== FALSE)
  117. {
  118. $data['file'] = $file;
  119. $this->init_model->display_template('modules/show', $data, 'admin');
  120. }
  121. else
  122. {
  123. redirect('admin');
  124. }
  125. }
  126. // ------------------------------------------------------------------------
  127. /**
  128. * Get Module
  129. *
  130. * Get a single module
  131. *
  132. * @access public
  133. * @param int the module id
  134. * @return bool
  135. */
  136. function get_module($id)
  137. {
  138. $this->db->select('id,name,description,directory,version,active')->from('modules')->where('id', $id);
  139. $query = $this->db->get();
  140. $data = $query->row();
  141. $query->free_result();
  142. return $data;
  143. }
  144. // ------------------------------------------------------------------------
  145. /**
  146. * Try to remove the module directory
  147. *
  148. * @access private
  149. * @param int the module id
  150. * @return bool
  151. */
  152. function _remove_dir($id)
  153. {
  154. $this->db->select('name')->from('modules')->where('id', $id);
  155. $query = $this->db->get();
  156. $data = $query->row();
  157. $name = $data->name;
  158. $query->free_result();
  159. if (file_exists(KBPATH .'my-modules/'.$name.'/config.php'))
  160. {
  161. $opendir = opendir(KBPATH .'my-modules/'.$name);
  162. while (false !== ($module = readdir($opendir)))
  163. {
  164. // Ignores . and .. that opendir displays
  165. if ($module != '.' && $module != '..')
  166. {
  167. @unlink(KBPATH .'my-modules/'.$name.'/'.$module);
  168. }
  169. }
  170. closedir($opendir);
  171. @rmdir(KBPATH .'my-modules/'.$name);
  172. }
  173. }
  174. }
  175. /* End of file modules.php */
  176. /* Location: ./upload/includes/application/controllers/admin/modules.php */