PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/system/expressionengine/models/addons_model.php

https://bitbucket.org/tdevonshire/hoolux
PHP | 409 lines | 216 code | 65 blank | 128 comment | 45 complexity | e40d9c801a97852f642df3b64c63b360 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author EllisLab Dev Team
  7. * @copyright Copyright (c) 2003 - 2012, EllisLab, Inc.
  8. * @license http://ellislab.com/expressionengine/user-guide/license.html
  9. * @link http://ellislab.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine Admin Model
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Core
  19. * @category Model
  20. * @author EllisLab Dev Team
  21. * @link http://ellislab.com
  22. */
  23. class Addons_model extends CI_Model {
  24. /**
  25. * Get Plugin Formatting
  26. *
  27. * Used in various locations to list formatting options
  28. *
  29. * @access public
  30. * @param bool whether or not to include a "None" option
  31. * @return array
  32. */
  33. function get_plugin_formatting($include_none = FALSE)
  34. {
  35. $this->load->helper('directory');
  36. static $filelist = array();
  37. $exclude = array('auto_xhtml');
  38. $default = array('br' => $this->lang->line('auto_br'), 'xhtml' => 'Xhtml');
  39. if ($include_none === TRUE)
  40. {
  41. $default['none'] = $this->lang->line('none');
  42. }
  43. if ( ! count($filelist))
  44. {
  45. $ext_len = strlen('.php');
  46. // first party plugins
  47. if (($map = directory_map(PATH_PI, TRUE)) !== FALSE)
  48. {
  49. foreach ($map as $file)
  50. {
  51. if (strncasecmp($file, 'pi.', 3) == 0 &&
  52. substr($file, -$ext_len) == '.php' &&
  53. strlen($file) > strlen('pi..php'))
  54. {
  55. $file = substr($file, 3, -strlen('.php'));
  56. $filelist[$file] = ucwords(str_replace('_', ' ', $file));
  57. }
  58. }
  59. }
  60. // now third party add-ons, which are arranged in "packages"
  61. // only catch files that match the package name, as other files are merely assets
  62. if (($map = directory_map(PATH_THIRD, 2)) !== FALSE)
  63. {
  64. foreach ($map as $pkg_name => $files)
  65. {
  66. if ( ! is_array($files))
  67. {
  68. $files = array($files);
  69. }
  70. foreach ($files as $file)
  71. {
  72. if (is_array($file))
  73. {
  74. // we're only interested in the top level files for the addon
  75. continue;
  76. }
  77. // how abouts a plugin?
  78. elseif (strncasecmp($file, 'pi.', 3) == 0 &&
  79. substr($file, -$ext_len) == '.php' &&
  80. strlen($file) > strlen('pi..php'))
  81. {
  82. $file = substr($file, 3, -$ext_len);
  83. if ($file == $pkg_name)
  84. {
  85. $filelist[$pkg_name] = ucwords(str_replace('_', ' ', $pkg_name));
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. $return = $default + $filelist;
  93. ksort($return);
  94. return $return;
  95. }
  96. // --------------------------------------------------------------------
  97. /**
  98. * Get Plugins
  99. *
  100. * @access public
  101. * @return array
  102. */
  103. function get_plugins()
  104. {
  105. $this->load->helper('directory');
  106. $plugins = array();
  107. $info = array();
  108. $ext_len = strlen('.php');
  109. // first party plugins
  110. if (($map = directory_map(PATH_PI, TRUE)) !== FALSE)
  111. {
  112. foreach ($map as $file)
  113. {
  114. if (strncasecmp($file, 'pi.', 3) == 0 && substr($file, -$ext_len) == '.php' && strlen($file) > strlen('pi..php'))
  115. {
  116. if ( ! @include_once(PATH_PI.$file))
  117. {
  118. continue;
  119. }
  120. $name = substr($file, 3, -$ext_len);
  121. $plugins[] = $name;
  122. $info[$name] = array_unique($plugin_info);
  123. }
  124. }
  125. }
  126. // now third party add-ons, which are arranged in "packages"
  127. // only catch files that match the package name, as other files are merely assets
  128. if (($map = directory_map(PATH_THIRD, 2)) !== FALSE)
  129. {
  130. foreach ($map as $pkg_name => $files)
  131. {
  132. if ( ! is_array($files))
  133. {
  134. $files = array($files);
  135. }
  136. foreach ($files as $file)
  137. {
  138. if (is_array($file))
  139. {
  140. // we're only interested in the top level files for the addon
  141. continue;
  142. }
  143. elseif (strncasecmp($file, 'pi.', 3) == 0 &&
  144. substr($file, -$ext_len) == '.php' &&
  145. strlen($file) > strlen('pi..php'))
  146. {
  147. if ( ! class_exists(ucfirst($pkg_name)))
  148. {
  149. if ( ! @include_once(PATH_THIRD.$pkg_name.'/'.$file))
  150. {
  151. continue;
  152. }
  153. }
  154. $plugins[] = $pkg_name;
  155. $info[$pkg_name] = array_unique($plugin_info);
  156. }
  157. }
  158. }
  159. }
  160. return $info;
  161. }
  162. // --------------------------------------------------------------------
  163. /**
  164. * Get Installed Modules
  165. *
  166. * @access public
  167. * @return array
  168. */
  169. function get_installed_modules($has_cp = FALSE, $has_tab = FALSE)
  170. {
  171. $this->db->select('LOWER(module_name) AS module_name, module_version, has_cp_backend, module_id', FALSE);
  172. if ($has_cp === TRUE)
  173. {
  174. $this->db->where('has_cp_backend', 'y');
  175. }
  176. if ($has_tab === TRUE)
  177. {
  178. $this->db->where('has_publish_fields', 'y');
  179. }
  180. return $this->db->get('modules');
  181. }
  182. // --------------------------------------------------------------------
  183. /**
  184. * Get Installed Extensions
  185. *
  186. * @access public
  187. * @return array
  188. */
  189. function get_installed_extensions($enabled = TRUE)
  190. {
  191. $this->db->select('class, version');
  192. if ($enabled)
  193. {
  194. $this->db->where('enabled', 'y');
  195. }
  196. else
  197. {
  198. $this->db->select('enabled');
  199. }
  200. return $this->db->get('extensions');
  201. }
  202. // --------------------------------------------------------------------
  203. /**
  204. * Module installed
  205. *
  206. * Returns true if a module is installed, false if not
  207. *
  208. * @access public
  209. * @param string
  210. * @return boolean
  211. */
  212. function module_installed($module_name)
  213. {
  214. static $_installed = array();
  215. if ( ! isset($_installed[$module_name]))
  216. {
  217. $this->db->from("modules");
  218. $this->db->where("module_name", ucfirst(strtolower($module_name)));
  219. $_installed[$module_name] = ($this->db->count_all_results() > 0) ? TRUE : FALSE;
  220. }
  221. return $_installed[$module_name];
  222. }
  223. // --------------------------------------------------------------------
  224. /**
  225. * Accessory installed
  226. *
  227. * Returns true if an accessory is installed, false if not
  228. *
  229. * @access public
  230. * @param string
  231. * @return boolean
  232. */
  233. function accessory_installed($acc_name)
  234. {
  235. static $_installed = array();
  236. if ( ! isset($_installed[$acc_name]))
  237. {
  238. $this->db->from("accessories");
  239. $this->db->where("class", ucfirst(strtolower($acc_name.'_acc')));
  240. $_installed[$acc_name] = ($this->db->count_all_results() > 0) ? TRUE : FALSE;
  241. }
  242. return $_installed[$acc_name];
  243. }
  244. // --------------------------------------------------------------------
  245. /**
  246. * Extension installed
  247. *
  248. * Returns true if an extension is installed, false if not
  249. *
  250. * @access public
  251. * @param string
  252. * @return boolean
  253. */
  254. function extension_installed($ext_name)
  255. {
  256. static $_installed = array();
  257. if ( ! isset($_installed[$ext_name]))
  258. {
  259. $this->db->from("extensions");
  260. $this->db->where("class", ucfirst(strtolower($ext_name.'_ext')));
  261. $_installed[$ext_name] = ($this->db->count_all_results() > 0) ? TRUE : FALSE;
  262. }
  263. return $_installed[$ext_name];
  264. }
  265. // --------------------------------------------------------------------
  266. /**
  267. * Fieldtype installed
  268. *
  269. * Returns true if a fieldtype is installed, false if not
  270. *
  271. * @access public
  272. * @param string
  273. * @return boolean
  274. */
  275. function fieldtype_installed($ft_name)
  276. {
  277. static $_installed = array();
  278. if ( ! isset($_installed[$ft_name]))
  279. {
  280. $this->db->from("fieldtypes");
  281. $this->db->where("name", strtolower($ft_name));
  282. $_installed[$ft_name] = ($this->db->count_all_results() > 0) ? TRUE : FALSE;
  283. }
  284. return $_installed[$ft_name];
  285. }
  286. // --------------------------------------------------------------------
  287. /**
  288. * RTE Tool installed
  289. *
  290. * Returns true if a RTE tool is installed, false if not
  291. *
  292. * @access public
  293. * @param string
  294. * @return boolean
  295. */
  296. function rte_tool_installed($tool_name)
  297. {
  298. // Is the module even installed?
  299. if ( ! $this->db->table_exists('rte_tools'))
  300. {
  301. return FALSE;
  302. }
  303. static $_installed = array();
  304. if ( ! isset($_installed[$tool_name]))
  305. {
  306. $this->db->from("rte_tools");
  307. $this->db->where("name", ucfirst(strtolower(str_replace(' ', '_', $tool_name))));
  308. $_installed[$tool_name] = ($this->db->count_all_results() > 0) ? TRUE : FALSE;
  309. }
  310. return $_installed[$tool_name];
  311. }
  312. // --------------------------------------------------------------------
  313. /**
  314. * Update an Extension
  315. *
  316. * @access public
  317. * @return void
  318. */
  319. function update_extension($class, $data)
  320. {
  321. $this->db->set($data);
  322. $this->db->where('class', $class);
  323. $this->db->update('extensions');
  324. }
  325. // --------------------------------------------------------------------
  326. /**
  327. * Update Accessory Information
  328. *
  329. * @access public
  330. * @return void
  331. */
  332. function update_accessory($class, $data)
  333. {
  334. // allow either "class", or "class_acc" to be passed
  335. if (substr($class, -4) != '_acc')
  336. {
  337. $class = $class.'_acc';
  338. }
  339. $this->db->where('class', $class);
  340. $this->db->update('accessories', $data);
  341. }
  342. }
  343. /* End of file addons_model.php */
  344. /* Location: ./system/expressionengine/models/addons_model.php */