PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_jckman/models/import.php

https://gitlab.com/che234/adn
PHP | 189 lines | 103 code | 37 blank | 49 comment | 11 complexity | faa2676281608516d461b143c8eff80b MD5 | raw file
  1. <?php
  2. /*------------------------------------------------------------------------
  3. # Copyright (C) 2005-2012 WebxSolution Ltd. All Rights Reserved.
  4. # @license - GPLv2.0
  5. # Author: WebxSolution Ltd
  6. # Websites: http://www.webxsolution.com
  7. # Terms of Use: An extension that is derived from the JoomlaCK editor will only be allowed under the following conditions: http://joomlackeditor.com/terms-of-use
  8. # ------------------------------------------------------------------------*/
  9. // no direct access
  10. defined( '_JEXEC' ) or die();
  11. //jimport( 'joomla.installer.installer' );
  12. jimport('joomla.installer.helper');
  13. class JCKManModelImport extends JModelLegacy
  14. {
  15. /** @var object JTable object */
  16. var $_table = null;
  17. /** @var object JTable object */
  18. var $_url = null;
  19. /**
  20. * Overridden constructor
  21. * @access protected
  22. */
  23. function __construct()
  24. {
  25. parent::__construct();
  26. }
  27. function getForm( $data = array(), $loadData = true )
  28. {
  29. // J3.0 workaround
  30. }
  31. function import()
  32. {
  33. $mainframe = JFactory::getApplication();
  34. $this->setState('action', 'install');
  35. switch(JRequest::getWord('installtype'))
  36. {
  37. case 'folder':
  38. $package = $this->_getPackageFromFolder();
  39. break;
  40. case 'upload':
  41. $package = $this->_getPackageFromUpload();
  42. break;
  43. default:
  44. $this->setState('message', 'No Install Type Found');
  45. return false;
  46. break;
  47. }
  48. // Was the package unpacked?
  49. if (!$package) {
  50. $this->setState('message', 'Unable to find install package');
  51. return false;
  52. }
  53. // Get a database connector
  54. //$db = & JFactory::getDBO();
  55. // Get an installer instance
  56. require_once( JPATH_COMPONENT .DS. 'helpers' .DS.'restorer.php' );
  57. $installer = JCKRestorer::getInstance();
  58. // Install the package
  59. if (!$installer->install($package['dir'])) {
  60. // There was an error installing the package
  61. $msg = JText::sprintf('COM_INSTALLER_INSTALL_ERROR', JText::_('COM_INSTALLER_TYPE_TYPE_'.strtoupper($package['type'])));
  62. $result = false;
  63. } else {
  64. // Package installed sucessfully
  65. $msg = JText::sprintf('COM_INSTALLER_INSTALL_SUCCESS', JText::_('COM_INSTALLER_TYPE_TYPE_'.strtoupper($package['type'])));
  66. $result = true;
  67. }
  68. // Set some model state values
  69. $mainframe->enqueueMessage($msg);
  70. $this->setState('name', $installer->get('name'));
  71. $this->setState('result', $result);
  72. $this->setState('message', $installer->message);
  73. $this->setState('extension.message', $installer->get('extension.message'));
  74. // Cleanup the install files
  75. if (!is_file($package['packagefile'])) {
  76. $config = JFactory::getConfig();
  77. $package['packagefile'] = $config->get('config.tmp_path').DS.$package['packagefile'];
  78. }
  79. JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']);
  80. return $result;
  81. }
  82. /**
  83. * Works out an installation package from a HTTP upload
  84. *
  85. * @return package definition or false on failure
  86. */
  87. protected function _getPackageFromUpload()
  88. {
  89. // Get the uploaded file information
  90. $userfile = JRequest::getVar('install_package', null, 'files', 'array');
  91. // Make sure that file uploads are enabled in php
  92. if (!(bool) ini_get('file_uploads')) {
  93. JCKHelper::error( JText::_('COM_INSTALLER_MSG_INSTALL_WARNINSTALLFILE'));
  94. return false;
  95. }
  96. // Make sure that zlib is loaded so that the package can be unpacked
  97. if (!extension_loaded('zlib')) {
  98. JCKHelper::error( JText::_('COM_INSTALLER_MSG_INSTALL_WARNINSTALLZLIB'));
  99. return false;
  100. }
  101. // If there is no uploaded file, we have a problem...
  102. if (!is_array($userfile)) {
  103. JCKHelper::error( JText::_('COM_INSTALLER_MSG_INSTALL_NO_FILE_SELECTED'));
  104. return false;
  105. }
  106. // Check if there was a problem uploading the file.
  107. if ($userfile['error'] || $userfile['size'] < 1) {
  108. JCKHelper::error( JText::_('COM_INSTALLER_MSG_INSTALL_WARNINSTALLUPLOADERROR'));
  109. return false;
  110. }
  111. // Build the appropriate paths
  112. $config = JFactory::getConfig();
  113. $tmp_dest = $config->get('tmp_path').DS.$userfile['name'];
  114. $tmp_src = $userfile['tmp_name'];
  115. // Move uploaded file
  116. jimport('joomla.filesystem.file');
  117. $uploaded = JFile::upload($tmp_src, $tmp_dest);
  118. // Unpack the downloaded package file
  119. $package = JInstallerHelper::unpack($tmp_dest);
  120. return $package;
  121. }
  122. /**
  123. * Install an extension from a directory
  124. *
  125. * @static
  126. * @return boolean True on success
  127. * @since 1.0
  128. */
  129. protected function _getPackageFromFolder()
  130. {
  131. // Get the path to the package to install
  132. $p_dir = JRequest::getString('install_directory');
  133. $p_dir = JPath::clean($p_dir);
  134. // Did you give us a valid directory?
  135. if (!is_dir($p_dir)) {
  136. JCKHelper::error( JText::_('COM_INSTALLER_MSG_INSTALL_PLEASE_ENTER_A_PACKAGE_DIRECTORY'));
  137. return false;
  138. }
  139. // Detect the package type
  140. $type = JInstallerHelper::detectType($p_dir);
  141. // Did you give us a valid package?
  142. if (!$type) {
  143. JCKHelper::error( JText::_('COM_INSTALLER_MSG_INSTALL_PATH_DOES_NOT_HAVE_A_VALID_PACKAGE'));
  144. return false;
  145. }
  146. $package['packagefile'] = null;
  147. $package['extractdir'] = null;
  148. $package['dir'] = $p_dir;
  149. $package['type'] = $type;
  150. return $package;
  151. }
  152. }