PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/html/AppCode/expressionengine/libraries/addons/Addons_installer.php

https://github.com/w3bg/www.hsifin.com
PHP | 519 lines | 285 code | 89 blank | 145 comment | 42 complexity | 74960788c693c94548a34f1e1be87f94 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * ExpressionEngine - by EllisLab
  4. *
  5. * @package ExpressionEngine
  6. * @author ExpressionEngine Dev Team
  7. * @copyright Copyright (c) 2003 - 2010, EllisLab, Inc.
  8. * @license http://expressionengine.com/user_guide/license.html
  9. * @link http://expressionengine.com
  10. * @since Version 2.0
  11. * @filesource
  12. */
  13. // ------------------------------------------------------------------------
  14. /**
  15. * ExpressionEngine Core Addon Installer Class
  16. *
  17. * @package ExpressionEngine
  18. * @subpackage Core
  19. * @category Core
  20. * @author ExpressionEngine Dev Team
  21. * @link http://expressionengine.com
  22. */
  23. class Addons_installer {
  24. var $EE;
  25. /**
  26. * Constructor
  27. *
  28. * @access public
  29. */
  30. function Addons_installer()
  31. {
  32. $this->EE =& get_instance();
  33. $this->EE->load->library('api');
  34. $this->EE->load->library('addons');
  35. }
  36. // --------------------------------------------------------------------
  37. /**
  38. * Addon Installer
  39. *
  40. * @access private
  41. * @param string
  42. * @return void
  43. */
  44. function install($addon, $type = 'module', $check_package = TRUE)
  45. {
  46. $third_party = $this->EE->addons->is_package($addon);
  47. if (is_array($type))
  48. {
  49. foreach($type as $component)
  50. {
  51. $this->install($addon, $component, $check_package);
  52. }
  53. }
  54. elseif ($check_package && $this->EE->addons->is_package($addon))
  55. {
  56. if (count($this->EE->addons->_packages[$addon]) > 1)
  57. {
  58. $this->EE->functions->redirect(BASE.AMP.'C=addons'.AMP.'M=package_settings'.AMP.'package='.$addon.AMP.'return='.$_GET['C']);
  59. }
  60. $this->install($addon, key($this->EE->addons->_packages[$addon]), FALSE);
  61. }
  62. else
  63. {
  64. $method = 'install_'.$type;
  65. if (method_exists($this, $method))
  66. {
  67. if ($third_party)
  68. {
  69. $this->EE->load->add_package_path($this->EE->addons->_packages[$addon][$type]['path']);
  70. }
  71. $this->$method($addon);
  72. if ($third_party)
  73. {
  74. $this->EE->load->remove_package_path($this->EE->addons->_packages[$addon][$type]['path']);
  75. }
  76. }
  77. }
  78. return TRUE;
  79. }
  80. // --------------------------------------------------------------------
  81. /**
  82. * Addon Uninstaller
  83. *
  84. * Install one or more components
  85. *
  86. * @access private
  87. * @param string
  88. * @return void
  89. */
  90. function uninstall($addon, $type = 'module', $check_package = TRUE)
  91. {
  92. $third_party = $this->EE->addons->is_package($addon);
  93. if (is_array($type))
  94. {
  95. foreach($type as $component)
  96. {
  97. $this->uninstall($addon, $component, $check_package);
  98. }
  99. }
  100. elseif ($check_package && $this->EE->addons->is_package($addon))
  101. {
  102. if (count($this->EE->addons->_packages[$addon]) > 1)
  103. {
  104. $this->EE->functions->redirect(BASE.AMP.'C=addons'.AMP.'M=package_settings'.AMP.'package='.$addon.AMP.'return='.$_GET['C']);
  105. }
  106. $this->uninstall($addon, key($this->EE->addons->_packages[$addon]), FALSE);
  107. }
  108. else
  109. {
  110. $method = 'uninstall_'.$type;
  111. if (method_exists($this, $method))
  112. {
  113. if ($third_party)
  114. {
  115. $this->EE->load->add_package_path($this->EE->addons->_packages[$addon][$type]['path']);
  116. }
  117. $this->$method($addon);
  118. if ($third_party)
  119. {
  120. $this->EE->load->remove_package_path($this->EE->addons->_packages[$addon][$type]['path']);
  121. }
  122. }
  123. }
  124. return TRUE;
  125. }
  126. // --------------------------------------------------------------------
  127. /**
  128. * Module Installer
  129. *
  130. * @access private
  131. * @param string
  132. * @return void
  133. */
  134. function install_module($module)
  135. {
  136. $class = $this->_module_install_setup($module);
  137. $MOD = new $class();
  138. $MOD->_ee_path = APPPATH;
  139. if ($MOD->install() !== TRUE)
  140. {
  141. show_error($this->EE->lang->line('module_can_not_be_found'));
  142. }
  143. }
  144. // --------------------------------------------------------------------
  145. /**
  146. * Module Uninstaller
  147. *
  148. * @access private
  149. * @param string
  150. * @return void
  151. */
  152. function uninstall_module($module)
  153. {
  154. $class = $this->_module_install_setup($module);
  155. $MOD = new $class();
  156. $MOD->_ee_path = APPPATH;
  157. if ($MOD->uninstall() !== TRUE)
  158. {
  159. show_error($this->EE->lang->line('module_can_not_be_found'));
  160. }
  161. }
  162. // --------------------------------------------------------------------
  163. /**
  164. * Accessory Installer
  165. *
  166. * @access private
  167. * @param string
  168. * @return void
  169. */
  170. function install_accessory($accessory)
  171. {
  172. $class = $this->_accessory_install_setup($accessory);
  173. $ACC = new $class();
  174. if (method_exists($ACC, 'install'))
  175. {
  176. $ACC->install();
  177. }
  178. $this->EE->db->insert('accessories', array(
  179. 'class' => $class,
  180. 'accessory_version' => $ACC->version
  181. ));
  182. $this->EE->accessories->update_placement($class);
  183. }
  184. // --------------------------------------------------------------------
  185. /**
  186. * Accessory Uninstaller
  187. *
  188. * @access private
  189. * @param string
  190. * @return void
  191. */
  192. function uninstall_accessory($accessory)
  193. {
  194. $class = $this->_accessory_install_setup($accessory, FALSE);
  195. $ACC = new $class();
  196. if (method_exists($ACC, 'uninstall'))
  197. {
  198. $ACC->uninstall();
  199. }
  200. $this->EE->db->delete('accessories', array('class' => $class));
  201. }
  202. // --------------------------------------------------------------------
  203. /**
  204. * Extension Installer
  205. *
  206. * @access private
  207. * @param string
  208. * @return void
  209. */
  210. function install_extension($extension, $enable = FALSE)
  211. {
  212. $this->EE->load->model('addons_model');
  213. if ( ! $this->EE->addons_model->extension_installed($extension))
  214. {
  215. $EXT = $this->_extension_install_setup($extension);
  216. if (method_exists($EXT, 'activate_extension') === TRUE)
  217. {
  218. $activate = $EXT->activate_extension();
  219. }
  220. }
  221. else
  222. {
  223. $class = $this->_extension_install_setup($extension, FALSE);
  224. $this->EE->addons_model->update_extension($class, array('enabled' => 'y'));
  225. }
  226. }
  227. // --------------------------------------------------------------------
  228. /**
  229. * Extension Uninstaller
  230. *
  231. * @access private
  232. * @param string
  233. * @return void
  234. */
  235. function uninstall_extension($extension)
  236. {
  237. $this->EE->load->model('addons_model');
  238. $EXT = $this->_extension_install_setup($extension);
  239. $this->EE->addons_model->update_extension(ucfirst(get_class($EXT)), array('enabled' => 'n'));
  240. if (method_exists($EXT, 'disable_extension') === TRUE)
  241. {
  242. $disable = $EXT->disable_extension();
  243. }
  244. }
  245. // --------------------------------------------------------------------
  246. /**
  247. * Fieldtype Installer
  248. *
  249. * @access private
  250. * @param string
  251. * @return void
  252. */
  253. function install_fieldtype($fieldtype)
  254. {
  255. $this->EE->api->instantiate('channel_fields');
  256. if ($this->EE->api_channel_fields->include_handler($fieldtype))
  257. {
  258. $default_settings = array();
  259. $FT = $this->EE->api_channel_fields->setup_handler($fieldtype, TRUE);
  260. $default_settings = $FT->install();
  261. $this->EE->db->insert('fieldtypes', array(
  262. 'name' => $fieldtype,
  263. 'version' => $FT->info['version'],
  264. 'settings' => base64_encode(serialize($default_settings)),
  265. 'has_global_settings' => method_exists($FT, 'display_global_settings') ? 'y' : 'n'
  266. ));
  267. }
  268. }
  269. // --------------------------------------------------------------------
  270. /**
  271. * Fieldtype Uninstaller
  272. *
  273. * @access private
  274. * @param string
  275. * @return void
  276. */
  277. function uninstall_fieldtype($fieldtype)
  278. {
  279. $this->EE->api->instantiate('channel_fields');
  280. if ($this->EE->api_channel_fields->include_handler($fieldtype))
  281. {
  282. $this->EE->load->dbforge();
  283. // Drop columns
  284. $this->EE->db->select('channel_fields.field_id, channels.channel_id');
  285. $this->EE->db->from('channel_fields');
  286. $this->EE->db->join('channels', 'channels.field_group = channel_fields.group_id');
  287. $this->EE->db->where('channel_fields.field_type', $fieldtype);
  288. $query = $this->EE->db->get();
  289. $ids = array();
  290. $channel_ids = array();
  291. if ($query->num_rows() > 0)
  292. {
  293. foreach($query->result() as $row)
  294. {
  295. $ids[] = $row->field_id;
  296. $channel_ids[] = $row->channel_id;
  297. }
  298. }
  299. $ids = array_unique($ids);
  300. if (count($ids))
  301. {
  302. foreach($ids as $id)
  303. {
  304. $this->EE->dbforge->drop_column('channel_data', 'field_id_'.$id);
  305. $this->EE->dbforge->drop_column('channel_data', 'field_ft_'.$id);
  306. }
  307. // Remove from layouts
  308. $c_ids = array_unique($channel_ids[$id]);
  309. $this->EE->load->library('layout');
  310. $this->EE->layout->delete_layout_fields($id, $c_ids);
  311. $this->EE->db->where_in('field_id', $ids);
  312. $this->EE->db->delete(array('channel_fields', 'field_formatting'));
  313. }
  314. // Uninstall
  315. $FT = $this->EE->api_channel_fields->setup_handler($fieldtype, TRUE);
  316. $FT->uninstall();
  317. $this->EE->db->delete('fieldtypes', array('name' => $fieldtype));
  318. }
  319. }
  320. // --------------------------------------------------------------------
  321. /**
  322. * Module Install Setup
  323. *
  324. * Contains common code for install and uninstall routines
  325. *
  326. * @access private
  327. * @param string
  328. * @return void
  329. */
  330. function _module_install_setup($module)
  331. {
  332. if ( ! $this->EE->cp->allowed_group('can_admin_modules'))
  333. {
  334. show_error($this->EE->lang->line('unauthorized_access'));
  335. }
  336. if ($module == '')
  337. {
  338. show_error($this->EE->lang->line('module_can_not_be_found'));
  339. }
  340. if (in_array($module, $this->EE->core->native_modules))
  341. {
  342. $path = PATH_MOD.$module.'/upd.'.$module.EXT;
  343. }
  344. else
  345. {
  346. $path = PATH_THIRD.$module.'/upd.'.$module.EXT;
  347. }
  348. if ( ! is_file($path))
  349. {
  350. show_error($this->EE->lang->line('module_can_not_be_found'));
  351. }
  352. $class = ucfirst($module).'_upd';
  353. if ( ! class_exists($class))
  354. {
  355. require $path;
  356. }
  357. return $class;
  358. }
  359. // --------------------------------------------------------------------
  360. /**
  361. * Accessory Install Setup
  362. *
  363. * Contains common code for install and uninstall routines
  364. *
  365. * @access private
  366. * @param string
  367. * @return void
  368. */
  369. function _accessory_install_setup($accessory, $install = TRUE)
  370. {
  371. if ( ! $this->EE->cp->allowed_group('can_access_accessories'))
  372. {
  373. show_error($this->EE->lang->line('unauthorized_access'));
  374. }
  375. if ($accessory == '')
  376. {
  377. show_error($this->EE->lang->line('unauthorized_access'));
  378. }
  379. $class = ucfirst($accessory).'_acc';
  380. $count = $this->EE->super_model->count('accessories', array('class' => $class));
  381. if (($install && $count) OR ( ! $install && ! $count))
  382. {
  383. show_error($this->EE->lang->line('unauthorized_access'));
  384. }
  385. $this->EE->load->library('accessories');
  386. return $this->EE->accessories->_get_accessory_class($accessory);
  387. }
  388. // --------------------------------------------------------------------
  389. /**
  390. * Extension Install Setup
  391. *
  392. * Contains common code for install and uninstall routines
  393. *
  394. * @access private
  395. * @param string
  396. * @return void
  397. */
  398. function _extension_install_setup($extension, $instantiate = TRUE)
  399. {
  400. if ( ! $this->EE->cp->allowed_group('can_access_extensions'))
  401. {
  402. show_error($this->EE->lang->line('unauthorized_access'));
  403. }
  404. if ($extension == '')
  405. {
  406. show_error($this->EE->lang->line('no_extension_id'));
  407. }
  408. $class = ucfirst($extension).'_ext';
  409. if ( ! $instantiate)
  410. {
  411. return $class;
  412. }
  413. if ( ! class_exists($class))
  414. {
  415. if ($this->EE->addons->is_package($extension))
  416. {
  417. include(PATH_THIRD.$extension.'/ext.'.$extension.EXT);
  418. }
  419. else
  420. {
  421. include(PATH_EXT.'ext.'.$extension.EXT);
  422. }
  423. }
  424. return new $class();
  425. }
  426. // --------------------------------------------------------------------
  427. }
  428. // END Addons_installer class
  429. /* End of file Addons_installer.php */
  430. /* Location: ./system/expressionengine/libraries/addons/Addons_installer.php */