PageRenderTime 23ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_jckman/helpers/installer.php

https://gitlab.com/che234/adn
PHP | 211 lines | 110 code | 32 blank | 69 comment | 27 complexity | 8bb0e300fe63e09eb7679a65db922574 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. defined( '_JEXEC' ) or die;
  10. defined('JPATH_BASE') or die();
  11. jimport('joomla.installer.installer');
  12. class JCKInstaller extends JInstaller
  13. {
  14. /**
  15. * Returns a reference to the global Installer object, only creating it
  16. * if it doesn't already exist.
  17. *
  18. * @static
  19. * @return object An installer object
  20. * @since 1.5
  21. */
  22. public static function &getInstance()
  23. {
  24. static $instance;
  25. if (!isset ($instance)) {
  26. $instance = new JCKInstaller();
  27. }
  28. return $instance;
  29. }
  30. /**
  31. * Set an installer adapter by name
  32. *
  33. * @access public
  34. * @param string $name Adapter name
  35. * @param object $adapter Installer adapter object
  36. * @return boolean True if successful
  37. * @since 1.5
  38. */
  39. public function setAdapter($name, &$adapter = null,$options = Array())
  40. {
  41. // Check if valid extension type
  42. if( $name == 'plugin' || $name == 'language' || $name == 'skin'){
  43. if (!is_object($adapter))
  44. {
  45. // Try to load the adapter object
  46. require_once(dirname(__FILE__).DS. '..'.DS.'adapters'.DS.strtolower($name).'.php');
  47. $class = 'JCKInstaller'.ucfirst($name);
  48. if (!class_exists($class)) {
  49. return false;
  50. }
  51. $adapter = new $class($this);
  52. $adapter->parent =& $this;
  53. }
  54. $this->_adapters[$name] = $adapter;
  55. return true;
  56. }else{
  57. $this->abort(JText::_('Incorrect version!'));
  58. }
  59. }
  60. public function loadAdapter($adapter, $options = array())
  61. {
  62. $class = 'JCKInstaller' . ucfirst($adapter);
  63. if( !($adapter == 'plugin' || $adapter == 'language'))
  64. {
  65. throw new InvalidArgumentException(sprintf('The %s install adapter does not exist.', $adapter));
  66. }
  67. if (!class_exists($class))
  68. {
  69. // @deprecated 4.0 - The adapter should be autoloaded or manually included by the caller
  70. $path = dirname(__FILE__) . '/../adapters/' . $adapter . '.php';
  71. // Try to load the adapter object
  72. if (!file_exists($path))
  73. {
  74. throw new InvalidArgumentException(sprintf('The %s install adapter does not exist.', $adapter));
  75. }
  76. // Try once more to find the class
  77. require_once $path;
  78. if (!class_exists($class))
  79. {
  80. throw new InvalidArgumentException(sprintf('The %s install adapter does not exist.', $adapter));
  81. }
  82. }
  83. // Ensure the adapter type is part of the options array
  84. $options['type'] = $adapter;
  85. return new $class($this, $this->getDBO(), $options);
  86. }
  87. /**
  88. * Is the XML file a valid Joomla installation manifest file.
  89. *
  90. * @param string $file An xmlfile path to check
  91. *
  92. * @return mixed A JXMLElement, or null if the file failed to parse
  93. *
  94. * @since 11.1
  95. */
  96. public function isManifest($file)
  97. {
  98. // Initialise variables.
  99. $xml = JFactory::getXML($file);
  100. // If we cannot load the XML file return null
  101. if (!$xml)
  102. {
  103. return null;
  104. }
  105. // Check for a valid XML root tag.
  106. // @todo: Remove backwards compatibility in a future version
  107. // Should be 'extension', but for backward compatibility we will accept 'extension' or 'install'.
  108. // 1.5 uses 'install'
  109. // 1.6 uses 'extension'
  110. if ($xml->getName() != 'install' && $xml->getName() != 'extension')
  111. {
  112. return null;
  113. }
  114. // Valid manifest file return the object
  115. return $xml;
  116. }
  117. /**
  118. * Tries to find the package manifest file
  119. *
  120. * @return boolean True on success, False on error
  121. *
  122. * @since 11.1
  123. */
  124. public function findManifest()
  125. {
  126. // Get an array of all the XML files from the installation directory
  127. $xmlfiles = JFolder::files($this->getPath('source'), '.xml$', 1, true);
  128. // If at least one XML file exists
  129. if (!empty($xmlfiles))
  130. {
  131. foreach ($xmlfiles as $file)
  132. {
  133. // Is it a valid Joomla installation manifest file?
  134. $manifest = $this->isManifest($file);
  135. if (!is_null($manifest))
  136. {
  137. // If the root method attribute is set to upgrade, allow file overwrite
  138. if ((string) $manifest->attributes()->method == 'upgrade')
  139. {
  140. $this->upgrade = true;
  141. $this->overwrite = true;
  142. }
  143. // If the overwrite option is set, allow file overwriting
  144. if ((string) $manifest->attributes()->overwrite == 'true')
  145. {
  146. $this->overwrite = true;
  147. }
  148. // Set the manifest object and path
  149. $this->manifest = $manifest;
  150. $this->setPath('manifest', $file);
  151. // Set the installation source path to that of the manifest file
  152. $this->setPath('source', dirname($file));
  153. return true;
  154. }
  155. }
  156. // None of the XML files found were valid install files
  157. JCKHelper::error(JText::_('JLIB_INSTALLER_ERROR_NOTFINDJOOMLAXMLSETUPFILE'));
  158. return false;
  159. }
  160. else
  161. {
  162. // No XML files were found in the install folder
  163. JCKHelper::error(JText::_('JLIB_INSTALLER_ERROR_NOTFINDXMLSETUPFILE'));
  164. return false;
  165. }
  166. }
  167. }
  168. //dummy class that does nothing
  169. class InstallerHelper
  170. {
  171. /**
  172. * Configure the Linkbar.
  173. *
  174. * @param string The name of the active view.
  175. */
  176. public static function addSubmenu($vName = 'install')
  177. {
  178. }
  179. }