PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/Quản lý công ty du lịch khách sạn PHP/sgncnew/administrator/components/com_jce/install.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 229 lines | 159 code | 35 blank | 35 comment | 17 complexity | d6da8960593a6bd5b3f32fb78a44bda6 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: install.php 115 2009-06-23 11:31:41Z happynoodleboy $
  4. * @package JCE Admin Component
  5. * @copyright Copyright (C) 2006 - 2009 Ryan Demmmer. All rights reserved.
  6. * @license GNU/GPL
  7. * JCE is free software. This version may have been modified pursuant
  8. * to the GNU General Public License, and as distributed it includes or
  9. * is derivative of works licensed under the GNU General Public License or
  10. * other free or open source software licenses.
  11. */
  12. defined('_JEXEC') or die ('Restricted access');
  13. /**
  14. * Installer function
  15. * @return
  16. */
  17. function com_install()
  18. {
  19. global $mainframe;
  20. $db = & JFactory::getDBO();
  21. jimport('joomla.filesystem.folder');
  22. jimport('joomla.filesystem.file');
  23. $path = JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jce';
  24. // Remove legacy file
  25. if (file_exists($path.DS.'admin.jce.php')) {
  26. @JFile::delete($path.DS.'admin.jce.php');
  27. }
  28. // Load updater class
  29. require_once ($path.DS.'updater.php');
  30. $updater = & JCEUpdater::getInstance();
  31. // Install Plugins data
  32. $updater->installPlugins(true);
  33. // Install Groups data
  34. $updater->installGroups(true);
  35. // Install editor plugin
  36. jimport('joomla.installer.installer');
  37. $installer = & JInstaller::getInstance();
  38. $source = $installer->getPath('source');
  39. $packages = $source.DS.'packages';
  40. // Get editor and plugin packages
  41. if(is_dir($packages)) {
  42. $editor = JFolder::files($packages, 'plg_jce_15\d+?\.zip', false, true);
  43. $plugins = JFolder::files($packages, 'jce_\w+_15\d+?\.zip', false, true);
  44. }
  45. $language = & JFactory::getLanguage();
  46. $language->load('com_jce', JPATH_ADMINISTRATOR);
  47. $img_path = JURI::root().'/administrator/components/com_jce/img/';
  48. $out = '<table class="adminlist" style="width:50%;">';
  49. $out .= '<tr><th class="title" style="width:65%">'.JText::_('Extension').'</th><th class="title" style="width:30%">'.JText::_('Version').'</th><th class="title" style="width:5%">&nbsp;</th></tr>';
  50. $editor_img = 'delete.png';
  51. $editor_result = JText::_('Error');
  52. $plugin_out = '';
  53. if (! empty($editor)) {
  54. if (is_file($editor[0])) {
  55. $config = & JFactory::getConfig();
  56. $tmp = $config->getValue('config.tmp_path').DS.uniqid('install_').DS.basename($editor[0], '.zip');
  57. if (!JArchive::extract($editor[0], $tmp)) {
  58. $mainframe->enqueueMessage(JText::_('EDITOR EXTRACT ERROR'), 'error');
  59. } else {
  60. $query = 'SELECT id, params'
  61. .' FROM #__components'
  62. .' WHERE link = '.$db->Quote('option=com_jce')
  63. ;
  64. $db->setQuery($query);
  65. $component = $db->loadObject();
  66. $params = explode("\n", $component->params);
  67. $installer = & JInstaller::getInstance();
  68. $c_manifest = & $installer->getManifest();
  69. $c_root = & $c_manifest->document;
  70. $version = & $c_root->getElementByPath('version');
  71. $component_version = $version->data();
  72. // Store Component values
  73. $component_paths = array (
  74. 'source'=>$installer->getPath('source'),
  75. 'manifest'=>$installer->getPath('manifest'),
  76. 'extension_site'=>$installer->getPath('extension_site'),
  77. 'extension_administrator'=>$installer->getPath('extension_administrator')
  78. );
  79. $component_vars = array (
  80. 'name'=>$installer->get('name'),
  81. 'result'=>$installer->get('result'),
  82. 'message'=>$installer->message
  83. );
  84. $editor_version = preg_replace('/\D+/', '', basename($editor[0]));
  85. // Add JTable include path
  86. JTable::addIncludePath(JPATH_LIBRARIES.DS.'joomla'.DS.'database'.DS.'table');
  87. // Editor Plugin installed proceed with plugins
  88. if ($installer->install($tmp)) {
  89. $manifest = & $installer->getManifest();
  90. $root = & $manifest->document;
  91. $name = & $root->getElementByPath('name');
  92. $version = & $root->getElementByPath('version');
  93. $editor_version = $version->data();
  94. $language->load('plg_editors_jce', JPATH_ADMINISTRATOR);
  95. $editor_img = 'tick.png';
  96. $editor_result = JText::_('Success');
  97. $query = 'UPDATE #__plugins'
  98. . ' SET name = '.$db->Quote($name->data())
  99. . ' WHERE folder = '.$db->Quote('editors')
  100. . ' AND element = '.$db->Quote('jce')
  101. ;
  102. $db->setQuery($query);
  103. $db->query();
  104. $params[] = 'package=1';
  105. // Include installer class
  106. if (! empty($plugins)) {
  107. require_once ($path.DS.'installer'.DS.'installer.php');
  108. $jce_installer = & JCEInstaller::getInstance();
  109. $plugin_out = '<tr><th class="title" style="width:65%">'.JText::_('Plugin').'</th><th class="title" style="width:30%">'.JText::_('Version').'</th><th class="title" style="width:5%">&nbsp;</th></tr>';
  110. foreach ($plugins as $plugin) {
  111. // Create unique tmp dir name
  112. $tmp = $config->getValue('config.tmp_path').DS.uniqid('install_').DS.basename($plugin, '.zip');
  113. // Extract to tmp dir
  114. if (JArchive::extract($plugin, $tmp)) {
  115. // Install plugin
  116. if (!$jce_installer->install($tmp)) {
  117. $plugin_img = 'delete.png';
  118. $plugin_result = JText::_('Error');
  119. $plugin_name = basename($plugin);
  120. } else {
  121. $manifest = & $jce_installer->getManifest();
  122. $root = & $manifest->document;
  123. $name = & $root->getElementByPath('name');
  124. $language->load('com_jce_'.trim($root->attributes('plugin')));
  125. $plugin_img = 'tick.png';
  126. $plugin_result = JText::_('Success');
  127. $plugin_name = $name->data();
  128. }
  129. $plugin_out .= '<tr><td>'.$plugin_name.'</td><td>'.preg_replace('/\D+/', '', basename($plugin)).'</td><td style="text-align:center;">'.JHTML::image($img_path.$plugin_img, $plugin_result).'</td></tr>';
  130. if ($jce_installer->get('extension.message')) {
  131. $plugin_out .= '<tr><td colspan="3">'.JText::_($jce_installer->get('extension.message')).'</td></tr>';
  132. }
  133. // Cleanup
  134. if (is_dir($tmp)) {
  135. @JFolder::delete($tmp);
  136. }
  137. }
  138. }
  139. }
  140. } else {
  141. $editor_img = 'delete.png';
  142. $editor_result = JText::_('Error');
  143. $params[] = 'package=0';
  144. }
  145. $editor_message = JText::_($installer->message);
  146. // Return Component Paths
  147. foreach ($component_paths as $k=>$v) {
  148. $installer->setPath($k, $v);
  149. }
  150. // Return Component Vars
  151. foreach ($component_vars as $k=>$v) {
  152. $installer->set($k, $v);
  153. }
  154. if (is_dir($tmp)) {
  155. @JFolder::delete($tmp);
  156. }
  157. $manifest = & $installer->getManifest();
  158. $root = & $manifest->document;
  159. $version = & $root->getElementByPath('version');
  160. $out .= '<tr><td>'.JText::_('JCE ADMIN TITLE').'</td><td>'.$component_version.'</td><td class="title" style="text-align:center;">'.JHTML::image($img_path.'tick.png', JText::_('Success')).'</td></tr>';
  161. $out .= '<tr><td colspan="3">'.JText::_($installer->message).'</td></tr>';
  162. $out .= '<tr><td>'.JText::_('JCE EDITOR TITLE').'</td><td>'.$editor_version.'</td><td class="title" style="text-align:center;">'.JHTML::image($img_path.$editor_img, $editor_result).'</td></tr>';
  163. $out .= '<tr><td colspan="3">'.$editor_message.'</td></tr>';
  164. $out .= $plugin_out;
  165. $out .= '</table>';
  166. $installer->set('message', JText::_('JCE INSTALL SUMMARY'));
  167. $installer->set('extension.message', $out);
  168. $row = & JTable::getInstance('component');
  169. $row->load($component->id);
  170. $row->params = implode("\n", $params);
  171. $row->store();
  172. }
  173. }
  174. }
  175. if (is_dir($packages)) {
  176. // Delete packages folder
  177. @JFolder::delete($packages);
  178. }
  179. }
  180. /**
  181. * Uninstall function
  182. * @return
  183. */
  184. function com_uninstall()
  185. {
  186. require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_jce'.DS.'updater.php');
  187. $updater = & JCEUpdater::getInstance();
  188. $updater->cleanupDB();
  189. $params = & JComponentHelper::getParams('com_jce');
  190. if ($params->get('package')) {
  191. $updater->removeEditor();
  192. }
  193. }
  194. ?>