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

/administrator/components/com_jce/classes/installer.php

https://github.com/cavila/Astica
PHP | 1083 lines | 694 code | 193 blank | 196 comment | 115 complexity | de94b71efae813c0a1de0037fc4560d0 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. /**
  3. * @version $Id: installer.php 255 2011-06-29 18:10:57Z happy_noodle_boy $
  4. * @package JCE
  5. * @copyright Copyright © 2009-2011 Ryan Demmer. All rights reserved.
  6. * @copyright Copyright © 2005 - 2007 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL 2 or later
  8. * This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. */
  13. // Do not allow direct access
  14. defined('_JEXEC') or die('RESTRICTED');
  15. class WFInstaller extends JObject
  16. {
  17. var $version = '2.0.12';
  18. /**
  19. * @var Boolean Profiles table exists
  20. */
  21. var $profiles;
  22. /**
  23. * @var Boolean Profiles / Plugins tables exist
  24. */
  25. var $tables;
  26. /**
  27. * Constructor activating the default information of the class
  28. *
  29. * @access protected
  30. */
  31. function __construct()
  32. {
  33. $language = JFactory::getLanguage();
  34. $language->load('com_jce', JPATH_ADMINISTRATOR);
  35. JTable::addIncludePath(dirname(dirname(__FILE__)) . DS . 'tables');
  36. }
  37. /**
  38. * Returns a reference to a editor object
  39. *
  40. * This method must be invoked as:
  41. * <pre> $browser =JContentEditor::getInstance();</pre>
  42. *
  43. * @access public
  44. * @return WF_The editor object.
  45. * @since 1.5
  46. */
  47. function &getInstance()
  48. {
  49. static $instance;
  50. if (!is_object($instance)) {
  51. $instance = new WFInstaller();
  52. }
  53. return $instance;
  54. }
  55. /**
  56. * Check upgrade / database status
  57. */
  58. function check()
  59. {
  60. $this->profiles = $this->checkTable('#__wf_profiles');
  61. if ($this->profiles) {
  62. $this->profiles = $this->checkTableContents('#__wf_profiles');
  63. }
  64. if (!$this->checkComponent()) {
  65. return $this->install(true);
  66. }
  67. // Check Profiles DB
  68. if (!$this->profiles) {
  69. return $this->redirect();
  70. }
  71. // Check Editor is installed
  72. if (!$this->checkEditor()) {
  73. $link = JHTML::link('index.php?option=com_jce&amp;task=repair&amp;type=editor', WFText::_('WF_EDITOR_INSTALL'));
  74. return $this->redirect(WFText::_('WF_EDITOR_INSTALLED_MANUAL_ERROR') . ' - ' . $link, 'error');
  75. }
  76. // Check Editor is enabled
  77. if (!$this->checkEditorEnabled()) {
  78. return $this->redirect(WFText::_('WF_EDITOR_ENABLED_ERROR'), 'error');
  79. }
  80. }
  81. function log($msg)
  82. {
  83. jimport('joomla.error.log');
  84. $log = JLog::getInstance('upgrade.txt');
  85. $log->addEntry(array(
  86. 'comment' => 'LOG: ' . $msg
  87. ));
  88. }
  89. /**
  90. * Repair an installation
  91. */
  92. function repair()
  93. {
  94. $type = JRequest::getWord('type', 'tables');
  95. switch ($type) {
  96. case 'tables':
  97. return $this->repairTables();
  98. break;
  99. case 'editor':
  100. $source = dirname(dirname(__FILE__)) . DS . 'plugin';
  101. if (is_dir($source)) {
  102. return $this->installEditor($source);
  103. }
  104. break;
  105. }
  106. }
  107. /**
  108. * Redirect with message
  109. * @param object $msg[optional] Message to display
  110. * @param object $state[optional] Message type
  111. */
  112. function redirect($msg = '', $state = '')
  113. {
  114. $mainframe = JFactory::getApplication();
  115. if ($msg) {
  116. $mainframe->enqueueMessage($msg, $state);
  117. }
  118. JRequest::setVar('view', 'cpanel');
  119. JRequest::setVar('task', '');
  120. return false;
  121. }
  122. /**
  123. * Upgrade database tables and remove legacy folders
  124. * @return Boolean
  125. */
  126. function upgrade($version)
  127. {
  128. $mainframe = JFactory::getApplication();
  129. $db = JFactory::getDBO();
  130. wfimport('admin.helpers.parameter');
  131. wfimport('admin.helpers.xml');
  132. $base = dirname(dirname(__FILE__));
  133. // cleanup javascript and css files moved to site
  134. if (version_compare($version, '2.0.10', '<')) {
  135. $path = dirname(dirname(__FILE__)) . DS . 'media';
  136. $scripts = array('colorpicker.js', 'help.js', 'html5.js', 'select.js', 'tips.js');
  137. foreach($scripts as $script) {
  138. if (is_file($path . DS . 'js' . DS . $script)) {
  139. @JFile::delete($path . DS . 'js' . DS . $script);
  140. }
  141. }
  142. if (is_dir($path . DS . 'js' . DS . 'jquery')) {
  143. @JFolder::delete($path . DS . 'js' . DS . 'jquery');
  144. }
  145. $styles = array('help.css', 'select.css', 'tips.css');
  146. foreach($styles as $style) {
  147. if (is_file($path . DS . 'css' . DS . $style)) {
  148. @JFile::delete($path . DS . 'css' . DS . $style);
  149. }
  150. }
  151. // delete jquery
  152. if (is_dir($path . DS . 'css' . DS . 'jquery')) {
  153. @JFolder::delete($path . DS . 'css' . DS . 'jquery');
  154. }
  155. // remove popup controller
  156. if (is_dir(JPATH_SITE . DS . 'components' . DS . 'com_jce' . DS . 'controller')) {
  157. @JFolder::delete(JPATH_SITE . DS . 'components' . DS . 'com_jce' . DS . 'controller');
  158. }
  159. }
  160. if (version_compare($version, '2.0.0beta2', '<')) {
  161. if ($this->checkTable('#__jce_profiles')) {
  162. // get all groups data
  163. $query = 'SELECT * FROM #__jce_profiles';
  164. $db->setQuery($query);
  165. $profiles = $db->loadObjectList();
  166. if ($this->createProfilesTable()) {
  167. $row = JTable::getInstance('profiles', 'WFTable');
  168. foreach ($profiles as $profile) {
  169. $row->bind($profile);
  170. $row->store();
  171. }
  172. }
  173. // Drop tables
  174. $query = 'DROP TABLE IF EXISTS #__jce_profiles';
  175. $db->setQuery($query);
  176. $db->query();
  177. }
  178. }
  179. // upgrade from 1.5.x to 2.0.0 (only in Joomla! 1.5)
  180. if (version_compare($version, '2.0.0', '<') && WF_JOOMLA15) {
  181. // check for groups table / data
  182. if ($this->checkTable('#__jce_groups') && $this->checkTableContents('#__jce_groups')) {
  183. // get plugin
  184. $plugin = JPluginHelper::getPlugin('editors', 'jce');
  185. // get JCE component
  186. $table = JTable::getInstance('component');
  187. $table->loadByOption('com_jce');
  188. // process params to JSON string
  189. $params = WFParameterHelper::toObject($table->params);
  190. // set params
  191. $table->params = json_encode(array('editor' => $params));
  192. // store
  193. $table->store();
  194. // get all groups data
  195. $query = 'SELECT * FROM #__jce_groups';
  196. $db->setQuery($query);
  197. $groups = $db->loadObjectList();
  198. // get all plugin data
  199. $query = 'SELECT id, name, icon FROM #__jce_plugins';
  200. $db->setQuery($query);
  201. $plugins = $db->loadAssocList('id');
  202. if ($this->createProfilesTable()) {
  203. foreach ($groups as $group) {
  204. $row = JTable::getInstance('profiles', 'WFTable');
  205. // transfer row ids to names
  206. foreach (explode(';', $group->rows) as $item) {
  207. $icons = array();
  208. foreach (explode(',', $item) as $id) {
  209. // spacer
  210. if ($id == '00') {
  211. $icons[] = 'spacer';
  212. } else {
  213. if (isset($plugins[$id])) {
  214. $icons[] = $plugins[$id]['icon'];
  215. }
  216. }
  217. }
  218. $rows[] = implode(',', $icons);
  219. }
  220. $group->rows = implode(';', $rows);
  221. $names = array();
  222. // transfer plugin ids to names
  223. foreach (explode(',', $group->plugins) as $id) {
  224. if (isset($plugins[$id])) {
  225. $items[] = $plugins[$id]['name'];
  226. }
  227. }
  228. $group->plugins = implode(',', $names);
  229. // convert params to JSON
  230. $params = WFParameterHelper::toObject($group->params);
  231. $data = new StdClass();
  232. foreach($params as $key => $value) {
  233. $parts = explode('_', $key);
  234. $node = array_shift($parts);
  235. // special consideration for imgmanager_ext!!
  236. if (strpos($key, 'imgmanager_ext_') !== false) {
  237. $node = $node . '_' . array_shift($parts);
  238. }
  239. // convert some keys
  240. if ($key == 'advlink') {
  241. $key = 'link';
  242. }
  243. $key = implode('_', $parts);
  244. if ($value !== '') {
  245. if (isset($data->$node) && is_object($data->$node)) {
  246. $data->$node->$key = $value;
  247. } else {
  248. $data->$node = new StdClass();
  249. $data->$node->$key = $value;
  250. }
  251. }
  252. }
  253. $group->params = json_encode($data);
  254. // bind data
  255. $row->bind($group);
  256. // add area data
  257. if ($row->name == 'Default') {
  258. $row->area = 0;
  259. }
  260. if ($row->name == 'Front End') {
  261. $row->area = 1;
  262. }
  263. if (!$row->store()) {
  264. $mainframe->enqueueMessage('Conversion of group data failed : ' . $row->name, 'error');
  265. }
  266. }
  267. // Drop tables
  268. $query = 'DROP TABLE IF EXISTS #__jce_groups';
  269. $db->setQuery($query);
  270. $db->query();
  271. // If profiles table empty due to error, install profiles data
  272. if (!$this->checkTableContents('#__wf_profiles')) {
  273. $this->installProfiles(true);
  274. }
  275. } else {
  276. return false;
  277. }
  278. // Install profiles
  279. } else {
  280. $this->installProfiles(true);
  281. }
  282. // Drop tables
  283. $query = 'DROP TABLE IF EXISTS #__jce_plugins';
  284. $db->setQuery($query);
  285. $db->query();
  286. // Drop tables
  287. $query = 'DROP TABLE IF EXISTS #__jce_extensions';
  288. $db->setQuery($query);
  289. $db->query();
  290. // Remove Plugins menu item
  291. $query = 'DELETE FROM #__components' . ' WHERE admin_menu_link = ' . $db->Quote('option=com_jce&type=plugins');
  292. $db->setQuery($query);
  293. $db->query();
  294. // Update Component Name
  295. $query = 'UPDATE #__components' . ' SET name = ' . $db->Quote('COM_JCE') . ' WHERE ' . $db->Quote('option') . '=' . $db->Quote('com_jce') . ' AND parent = 0';
  296. $db->setQuery($query);
  297. $db->query();
  298. // Fix links for other views and edit names
  299. $menus = array(
  300. 'install' => 'installer',
  301. 'group' => 'profiles',
  302. 'groups' => 'profiles',
  303. 'config' => 'config'
  304. );
  305. $row = JTable::getInstance('component');
  306. foreach ($menus as $k => $v) {
  307. $query = 'SELECT id FROM #__components' . ' WHERE admin_menu_link = ' . $db->Quote('option=com_jce&type=' . $k);
  308. $db->setQuery($query);
  309. $id = $db->loadObject();
  310. if ($id) {
  311. $row->load($id);
  312. $row->name = $v;
  313. $row->admin_menu_link = 'option=com_jce&view=' . $v;
  314. if (!$row->store()) {
  315. $mainframe->enqueueMessage('Unable to update Component Links for view : ' . strtoupper($v), 'error');
  316. }
  317. }
  318. }
  319. $folders = JFolder::folders(JPATH_ADMINISTRATOR . DS . 'language', '.', false, true, array('.svn', 'CVS', 'en-GB'));
  320. // remove old admin language files
  321. foreach($folders as $folder) {
  322. $name = basename($folder);
  323. $files = array($name . '.com_jce.ini', $name . '.com_jce.menu.ini', $name . '.com_jce.xml');
  324. foreach($files as $file) {
  325. if (is_file($folder . DS . $file)) {
  326. @JFile::delete($folder . DS . $file);
  327. }
  328. }
  329. }
  330. $folders = JFolder::folders(JPATH_SITE . DS . 'language', '.', false, true, array('.svn', 'CVS', 'en-GB'));
  331. // remove old site language files
  332. foreach($folders as $folder) {
  333. $files = JFolder::files($folder, '^' . basename($folder) . '\.com_jce([_a-z0-9]+)?\.(ini|xml)$', false, true);
  334. @JFile::delete($files);
  335. }
  336. } // end JCE 1.5 upgrade
  337. return true;
  338. }
  339. /**
  340. * Install Editor and Plugin packages
  341. * @return
  342. */
  343. function install($manual = false)
  344. {
  345. jimport('joomla.installer.installer');
  346. jimport('joomla.installer.helper');
  347. $mainframe = JFactory::getApplication();
  348. $db = JFactory::getDBO();
  349. $installer = JInstaller::getInstance();
  350. // set base path
  351. $base = dirname(dirname(__FILE__));
  352. $state = false;
  353. // Install the Administration Component
  354. if ($manual) {
  355. if (!$this->installComponent()) {
  356. $mainframe->enqueueMessage(WFText::_('WF_COMPONENT_MANUAL_INSTALL_FAIL'), 'error');
  357. $mainframe->redirect('index.php');
  358. } else {
  359. $mainframe->enqueueMessage(WFText::_('WF_COMPONENT_MANUAL_INSTALL_SUCCESS'));
  360. }
  361. }
  362. $upgrade = false;
  363. $version = $this->version;
  364. // check for upgrade
  365. $xml_file = $base . DS . 'jce.xml';
  366. if (is_file($xml_file)) {
  367. $xml = JApplicationHelper::parseXMLInstallFile($xml_file);
  368. if (preg_match('/([0-9\.]+)(beta|rc|dev|alpha)?([0-9]+?)/i', $xml['version'])) {
  369. // component version is less than current
  370. if (version_compare($xml['version'], $this->version, '<')) {
  371. $upgrade = true;
  372. $version = $xml['version'];
  373. }
  374. // invalid component version, check for groups table
  375. } else {
  376. // check for old tables
  377. if ($this->checkTable('#__jce_groups')) {
  378. $version = '1.5.0';
  379. }
  380. // check for old tables
  381. if ($this->checkTable('#__jce_profiles')) {
  382. $version = '2.0.0beta1';
  383. }
  384. }
  385. } else {
  386. // check for old tables
  387. if ($this->checkTable('#__jce_groups')) {
  388. $version = '1.5.0';
  389. }
  390. }
  391. // perform upgrade
  392. if (version_compare($version, $this->version, '<')) {
  393. $state = $this->upgrade($version);
  394. } else {
  395. // install plugins first
  396. $state = $this->installProfiles(true);
  397. }
  398. if ($state) {
  399. if ($manual) {
  400. $mainframe->redirect('index.php?option=com_jce');
  401. }
  402. $source = $installer->getPath('source');
  403. $packages = $source . DS . 'packages';
  404. $backup = $source . DS . 'backup';
  405. $language = JFactory::getLanguage();
  406. $language->load('com_jce', JPATH_ADMINISTRATOR);
  407. $manifest = $installer->getPath('manifest');
  408. $version = $this->version;
  409. // Component data
  410. if ($xml = JApplicationHelper::parseXMLInstallFile($manifest)) {
  411. $version = $xml['version'];
  412. }
  413. $message = '<table class="adminlist">' . '<thead><th colspan="3">' . WFText::_('WF_INSTALL_SUMMARY') . '</th>' . '<thead><th class="title" style="width:65%">' . WFText::_('WF_INSTALLER_EXTENSION') . '</th><th class="title" style="width:30%">' . WFText::_('WF_ADMIN_VERSION') . '</th><th class="title" style="width:5%">&nbsp;</th></thead>' . '<tr><td>' . WFText::_('WF_ADMIN_TITLE') . '</td><td>' . $version . '</td><td class="title" style="text-align:center;">' . JHTML::image(JURI::root() . 'administrator/components/com_jce/media/img/tick.png', WFText::_('WF_ADMIN_SUCCESS')) . '</td></tr>' . '<tr><td colspan="3">' . WFText::_('WF_ADMIN_DESC') . '</td></tr>';
  414. // legacy cleanup
  415. if (get_parent_class($installer) == 'JAdapter') {
  416. $this->_legacyCleanup();
  417. }
  418. // set editor plugin package dir
  419. $editor = $base . DS . 'plugin';
  420. // install editor plugin
  421. if (is_dir($editor) && is_file($editor . DS . 'jce.php') && is_file($editor . DS . 'jce.xml')) {
  422. $xml = JApplicationHelper::parseXMLInstallFile($editor . DS . 'jce.xml');
  423. if ($result = $this->installEditor($editor, true)) {
  424. $message .= $result;
  425. } else {
  426. $message .= '<tr><td>' . WFText::_('WF_EDITOR_TITLE') . '</td><td>' . $xml['version'] . '</td><td class="title" style="text-align:center;">' . JHTML::image(JURI::root() . 'administrator/components/com_jce/media/img/error.png', WFText::_('WF_LABEL_ERROR')) . '</td></tr>';
  427. }
  428. }
  429. $message .= '</table>';
  430. $installer->set('message', $message);
  431. // post-install
  432. $this->addIndexfiles();
  433. } else {
  434. $installer->abort();
  435. }
  436. }
  437. function addIndexfiles()
  438. {
  439. jimport('joomla.filesystem.folder');
  440. jimport('joomla.filesystem.file');
  441. // get the base file
  442. $file = dirname(dirname(__FILE__)) . DS . 'index.html';
  443. if (is_file($file)) {
  444. // admin component
  445. $folders = JFolder::folders(dirname($file), '.', true, true);
  446. foreach ($folders as $folder) {
  447. JFile::copy($file, $folder . DS . basename($file));
  448. }
  449. // site component
  450. $site = JPATH_SITE . DS . 'components' . DS . 'com_jce';
  451. if (is_dir($site)) {
  452. $folders = JFolder::folders($site, '.', true, true);
  453. foreach ($folders as $folder) {
  454. JFile::copy($file, $folder . DS . basename($file));
  455. }
  456. }
  457. // plugin
  458. $plugin = JPATH_PLUGINS . DS . 'jce';
  459. // only needed for Joomla! 1.6+
  460. if (is_dir($plugin)) {
  461. JFile::copy($file, $plugin . DS . basename($file));
  462. }
  463. }
  464. }
  465. function uninstall()
  466. {
  467. // remove profiles table if empty
  468. if (!$this->checkTableContents('#__wf_profiles')) {
  469. $this->removeTable('#__wf_profiles');
  470. }
  471. $this->removeEditor();
  472. }
  473. function _legacyCleanup()
  474. {
  475. $path = JPATH_PLUGINS . DS . 'editors';
  476. // cleanup old installation
  477. if (is_file($path . DS . 'jce.php')) {
  478. @JFile::delete($path . DS . 'jce.php');
  479. }
  480. if (is_file($path . DS . 'jce.xml')) {
  481. @JFile::delete($path . DS . 'jce.xml');
  482. }
  483. if (is_dir($path . DS . 'jce')) {
  484. @JFolder::delete($path . DS . 'jce');
  485. }
  486. $db = JFactory::getDBO();
  487. // Drop tables
  488. $query = 'DROP TABLE IF EXISTS #__jce_groups';
  489. $db->setQuery($query);
  490. $db->query();
  491. // Drop tables
  492. $query = 'DROP TABLE IF EXISTS #__jce_plugins';
  493. $db->setQuery($query);
  494. $db->query();
  495. // remove menu items so they are re-installed to prevent errors in Joomla! 1.6
  496. $this->_removeMenus();
  497. }
  498. function _removeMenus()
  499. {
  500. $db = JFactory::getDBO();
  501. $query = 'SELECT id FROM #__menu'
  502. . ' WHERE client_id = 1'
  503. . ' AND type = ' . $db->Quote('component')
  504. . ' AND path = ' . $db->Quote('jce')
  505. . ' AND component_id = 0'
  506. ;
  507. $db->setQuery($query);
  508. $id = $db->loadResult();
  509. if ($id) {
  510. $query = 'SELECT id FROM #__menu'
  511. . ' WHERE client_id = 1'
  512. . ' AND parent_id = ' . (int) $id
  513. ;
  514. $db->setQuery($query);
  515. $ids = $db->loadResultArray();
  516. $menu = JTable::getInstance('menu');
  517. if (count($ids)) {
  518. // Iterate the items to delete each one.
  519. foreach($ids as $menuid){
  520. if (!$menu->delete((int) $menuid)) {
  521. $this->setError($menu->getError());
  522. return false;
  523. }
  524. }
  525. }
  526. // remove parent
  527. if (!$menu->delete((int) $id)) {
  528. $this->setError($menu->getError());
  529. return false;
  530. }
  531. // Rebuild the whole tree
  532. $menu->rebuild();
  533. }
  534. }
  535. /* TODO : */
  536. function installFromBackup()
  537. {
  538. return true;
  539. }
  540. /**
  541. * Remove a table
  542. * @return boolean
  543. * @param string $table Table to remove
  544. */
  545. function removeTable($table)
  546. {
  547. $db = JFactory::getDBO();
  548. $query = 'DROP TABLE IF EXISTS #__jce_' . $table;
  549. $db->setQuery($query);
  550. return $db->query();
  551. }
  552. /**
  553. * Check whether the component is installed
  554. * @return
  555. */
  556. function checkComponent()
  557. {
  558. $component = JComponentHelper::getComponent('com_jce', true);
  559. return $component->enabled;
  560. }
  561. /**
  562. * Check whether a table exists
  563. * @return boolean
  564. * @param string $table Table name
  565. */
  566. function checkTable($table)
  567. {
  568. $db = JFactory::getDBO();
  569. $tables = $db->getTableList();
  570. if (!empty($tables)) {
  571. // swap array values with keys, convert to lowercase and return array keys as values
  572. $tables = array_keys(array_change_key_case(array_flip($tables)));
  573. $app = JFactory::getApplication();
  574. $match = str_replace('#__', strtolower($app->getCfg('dbprefix', '')), $table);
  575. return in_array($match, $tables);
  576. }
  577. // try with query
  578. $query = 'SELECT COUNT(id) FROM ' . $table;
  579. $db->setQuery($query);
  580. return $db->query();
  581. }
  582. /**
  583. * Check table contents
  584. * @return boolean
  585. * @param string $table Table name
  586. */
  587. function checkTableContents($table)
  588. {
  589. $db = JFactory::getDBO();
  590. $query = 'SELECT COUNT(id) FROM ' . $table;
  591. $db->setQuery($query);
  592. return $db->loadResult();
  593. }
  594. /**
  595. * Check whether a field exists
  596. * @return boolean
  597. * @param string $table Table name
  598. */
  599. function checkField($table, $field)
  600. {
  601. $db = JFactory::getDBO();
  602. $fields = $db->getTableFields($table);
  603. return array_key_exists($field, $fields[$table]);
  604. }
  605. /**
  606. * Remove all tables
  607. */
  608. function removeTables($uninstall = false)
  609. {
  610. $mainframe = JFactory::getApplication();
  611. $db = JFactory::getDBO();
  612. $tables = array(
  613. 'plugins',
  614. 'extensions',
  615. 'groups',
  616. 'profiles'
  617. );
  618. foreach ($tables as $table) {
  619. if (!$this->removeTable($table)) {
  620. $msg = JText::sprintf('WF_DB_REMOVE_ERROR', ucfirst($table));
  621. $state = 'error';
  622. } else {
  623. $msg = JText::sprintf('WF_DB_REMOVE_SUCCESS', ucfirst($table));
  624. $state = '';
  625. }
  626. $mainframe->enqueueMessage($msg, $state);
  627. }
  628. if (!$uninstall) {
  629. $mainframe->redirect('index.php?option=com_jce');
  630. }
  631. }
  632. function repairTables()
  633. {
  634. $table = JRequest::getString('table');
  635. if ($table) {
  636. $method = 'install' . ucfirst($table);
  637. if (method_exists($this, $method)) {
  638. return $this->$method();
  639. }
  640. }
  641. }
  642. /**
  643. * Check if all tables exist
  644. * @return boolean
  645. */
  646. function checkTables()
  647. {
  648. $ret = false;
  649. $tables = array(
  650. 'plugins',
  651. 'profiles'
  652. );
  653. foreach ($tables as $table) {
  654. $ret = $this->checkTable($table);
  655. }
  656. return $ret;
  657. }
  658. /**
  659. * Remove all backup tables
  660. */
  661. function cleanupDB()
  662. {
  663. $db = JFactory::getDBO();
  664. $tables = array(
  665. 'plugins',
  666. 'profiles',
  667. 'groups',
  668. 'extensions'
  669. );
  670. foreach ($tables as $table) {
  671. $query = 'DROP TABLE IF EXISTS #__jce_' . $table . '_tmp';
  672. $db->setQuery($query);
  673. $db->query();
  674. }
  675. }
  676. /**
  677. * Check whether the editor is installed
  678. * @return boolean
  679. */
  680. function checkEditor()
  681. {
  682. require_once(JPATH_LIBRARIES . DS . 'joomla' . DS . 'plugin' . DS . 'helper.php');
  683. return JPluginHelper::getPlugin('editors', 'jce');
  684. }
  685. /**
  686. * Check for existence of editor files and folder
  687. * @return boolean
  688. */
  689. function checkEditorFiles()
  690. {
  691. $path = WF_JOOMLA15 ? JPATH_PLUGINS . DS . 'editors' : JPATH_PLUGINS . DS . 'editors' . DS . 'jce';
  692. // Check for JCE plugin files
  693. return file_exists($path . DS . 'jce.php') && file_exists($path . DS . 'jce.xml');
  694. }
  695. /**
  696. * Check if the editor is enabled
  697. * @return boolean
  698. */
  699. function checkEditorEnabled()
  700. {
  701. return true;
  702. }
  703. /**
  704. * Check the installed component version
  705. * @return Version message
  706. */
  707. function checkEditorVersion()
  708. {
  709. jimport('joomla.filesystem.file');
  710. $file = WF_JOOMLA15 ? JPATH_PLUGINS . DS . 'editors' . DS . 'jce.xml' : JPATH_PLUGINS . DS . 'editors' . DS . 'jce' . DS . 'jce.xml';
  711. if (!JFile::exists($file)) {
  712. JError::raiseNotice('SOME ERROR CODE', WFText::_('WF_EDITOR_VERSION_ERROR'));
  713. return false;
  714. } else {
  715. if ($xml = JApplicationHelper::parseXMLInstallFile($file)) {
  716. $version = $xml['version'];
  717. // Development version
  718. if (strpos($this->version, '2.0.12') !== false || strpos($version, '2.0.12') !== false) {
  719. return true;
  720. }
  721. if (version_compare($version, $this->version, '<')) {
  722. JError::raiseNotice('SOME ERROR CODE', JText::sprintf('WF_EDITOR_VERSION_ERROR', $this->version));
  723. return false;
  724. }
  725. }
  726. }
  727. }
  728. /**
  729. * Create the Profiles table
  730. * @return boolean
  731. */
  732. function createProfilesTable()
  733. {
  734. $mainframe = JFactory::getApplication();
  735. $db = JFactory::getDBO();
  736. $query = "CREATE TABLE IF NOT EXISTS `#__wf_profiles` (
  737. `id` int(11) NOT NULL AUTO_INCREMENT,
  738. `name` varchar(255) NOT NULL,
  739. `description` varchar(255) NOT NULL,
  740. `users` text NOT NULL,
  741. `types` varchar(255) NOT NULL,
  742. `components` text NOT NULL,
  743. `area` tinyint(3) NOT NULL,
  744. `rows` text NOT NULL,
  745. `plugins` text NOT NULL,
  746. `published` tinyint(3) NOT NULL,
  747. `ordering` int(11) NOT NULL,
  748. `checked_out` tinyint(3) NOT NULL,
  749. `checked_out_time` datetime NOT NULL,
  750. `params` text NOT NULL,
  751. PRIMARY KEY (`id`)
  752. );";
  753. $db->setQuery($query);
  754. if (!$db->query()) {
  755. $mainframe->enqueueMessage(WFText::_('WF_INSTALL_TABLE_PROFILES_ERROR') . $db->stdErr(), 'error');
  756. return false;
  757. } else {
  758. return true;
  759. }
  760. }
  761. /**
  762. * Install Profiles
  763. * @return boolean
  764. * @param object $install[optional]
  765. */
  766. function installProfiles($install = false)
  767. {
  768. $mainframe = JFactory::getApplication();
  769. $db = JFactory::getDBO();
  770. $ret = false;
  771. JTable::addIncludePath(dirname(dirname(__FILE__)) . DS . 'profiles');
  772. if ($this->createProfilesTable()) {
  773. $ret = true;
  774. $query = 'SELECT count(id) FROM #__wf_profiles';
  775. $db->setQuery($query);
  776. $profiles = array(
  777. 'Default' => false,
  778. 'Front End' => false
  779. );
  780. // No Profiles table data
  781. if (!$db->loadResult()) {
  782. $path = dirname(dirname(__FILE__)) . DS . 'models';
  783. JModel::addIncludePath($path);
  784. $model = JModel::getInstance('profiles', 'WFModel');
  785. $xml = $path . 'profiles.xml';
  786. // try root profiles.xml first
  787. if (!is_file($xml)) {
  788. $xml = $path . DS . 'profiles.xml';
  789. }
  790. if (is_file($xml)) {
  791. if (!$model->processImport($xml, true)) {
  792. $mainframe->enqueueMessage(WFText::_('WF_INSTALL_PROFILES_ERROR'), 'error');
  793. }
  794. } else {
  795. $mainframe->enqueueMessage(WFText::_('WF_INSTALL_PROFILES_NOFILE_ERROR'), 'error');
  796. }
  797. }
  798. }
  799. if (!$install) {
  800. //$this->redirect();
  801. $mainframe->redirect('index.php?option=com_jce');
  802. }
  803. return $ret;
  804. }
  805. /**
  806. * Install the editor package
  807. * @return Array or false
  808. * @param object $path[optional] Path to package folder
  809. */
  810. function installEditor($source, $install = false)
  811. {
  812. jimport('joomla.installer.installer');
  813. $mainframe = JFactory::getApplication();
  814. $db = JFactory::getDBO();
  815. $result = '';
  816. JTable::addIncludePath(JPATH_LIBRARIES . DS . 'joomla' . DS . 'database' . DS . 'table');
  817. $version = '';
  818. $name = '';
  819. if ($xml = JApplicationHelper::parseXMLInstallFile($source . DS . 'jce.xml')) {
  820. $version = $xml['version'];
  821. $name = $xml['name'];
  822. }
  823. $installer = new JInstaller();
  824. if ($installer->install($source)) {
  825. if ($install) {
  826. $language = JFactory::getLanguage();
  827. $language->load('plg_editors_jce', JPATH_ADMINISTRATOR);
  828. $result = '<tr><td>' . WFText::_('WF_EDITOR_TITLE') . '</td><td>' . $version . '</td><td class="title" style="text-align:center;">' . JHTML::image(JURI::root() . 'administrator/components/com_jce/media/img/tick.png', WFText::_('WF_ADMIN_SUCCESS')) . '</td></tr>';
  829. if ($installer->message) {
  830. $result .= '<tr><td colspan="3">' . WFText::_($installer->message, $installer->message) . '</td></tr>';
  831. }
  832. } else {
  833. $mainframe->enqueueMessage(WFText::_('WF_EDITOR_INSTALL_SUCCESS'));
  834. }
  835. } else {
  836. if (!$install) {
  837. $mainframe->enqueueMessage(WFText::_('WF_EDITOR_INSTALL_FAILED'));
  838. }
  839. }
  840. if (!$install) {
  841. $mainframe->redirect('index.php?option=com_jce');
  842. }
  843. return $result;
  844. }
  845. /**
  846. * Install the Editor Component
  847. * @return boolean
  848. */
  849. function installComponent()
  850. {
  851. $mainframe = JFactory::getApplication();
  852. $db = JFactory::getDBO();
  853. jimport('joomla.installer.installer');
  854. require_once(JPATH_LIBRARIES . DS . 'joomla' . DS . 'installer' . DS . 'adapters' . DS . 'component.php');
  855. $installer = JInstaller::getInstance();
  856. $installer->setPath('source', dirname(dirname(__FILE__)));
  857. $component = new JInstallerComponent($installer, $db);
  858. $component->install();
  859. return $this->checkComponent();
  860. }
  861. /**
  862. * Uninstall the editor
  863. * @return boolean
  864. */
  865. function removeEditor()
  866. {
  867. $mainframe = JFactory::getApplication();
  868. $db = JFactory::getDBO();
  869. // load extension helper
  870. require_once(dirname(dirname(__FILE__)) . DS . 'helpers' . DS . 'extension.php');
  871. $plugin = WFExtensionHelper::getPlugin();
  872. if (isset($plugin->id)) {
  873. jimport('joomla.installer.installer');
  874. $installer = new JInstaller();
  875. if (!$installer->uninstall('plugin', $plugin->id)) {
  876. $mainframe->enqueueMessage(WFText::_('WF_EDITOR_REMOVE_ERROR'));
  877. return false;
  878. } else {
  879. $mainframe->enqueueMessage(WFText::_('WF_EDITOR_REMOVE_SUCCESS'));
  880. return true;
  881. }
  882. $mainframe->enqueueMessage($msg);
  883. return $ret;
  884. } else {
  885. $mainframe->enqueueMessage(WFText::_('WF_EDITOR_REMOVE_NOT_FOUND'), 'error');
  886. return false;
  887. }
  888. }
  889. }
  890. ?>