PageRenderTime 25ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/libraries/joomla/installer/adapters/template.php

https://gitlab.com/endomorphosis/OLAAaction
PHP | 200 lines | 107 code | 21 blank | 72 comment | 19 complexity | 1a152c5edb90a485a83df5116ab709dd MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id:template.php 6961 2007-03-15 16:06:53Z tcp $
  4. * @package Joomla.Framework
  5. * @subpackage Installer
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. 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. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. // Check to ensure this file is within the rest of the framework
  15. defined('JPATH_BASE') or die();
  16. /**
  17. * Template installer
  18. *
  19. * @package Joomla.Framework
  20. * @subpackage Installer
  21. * @since 1.5
  22. */
  23. class JInstallerTemplate extends JObject
  24. {
  25. /**
  26. * Constructor
  27. *
  28. * @access protected
  29. * @param object $parent Parent object [JInstaller instance]
  30. * @return void
  31. * @since 1.5
  32. */
  33. function __construct(&$parent)
  34. {
  35. $this->parent =& $parent;
  36. }
  37. /**
  38. * Custom install method
  39. *
  40. * @access public
  41. * @return boolean True on success
  42. * @since 1.5
  43. */
  44. function install()
  45. {
  46. // Get database connector object
  47. $db =& $this->parent->getDBO();
  48. $manifest =& $this->parent->getManifest();
  49. $root =& $manifest->document;
  50. // Get the client application target
  51. if ($cname = $root->attributes('client')) {
  52. // Attempt to map the client to a base path
  53. jimport('joomla.application.helper');
  54. $client =& JApplicationHelper::getClientInfo($cname, true);
  55. if ($client === false) {
  56. $this->parent->abort(JText::_('Template').' '.JText::_('Install').': '.JText::_('Unknown client type').' ['.$cname.']');
  57. return false;
  58. }
  59. $basePath = $client->path;
  60. $clientId = $client->id;
  61. } else {
  62. // No client attribute was found so we assume the site as the client
  63. $cname = 'site';
  64. $basePath = JPATH_SITE;
  65. $clientId = 0;
  66. }
  67. // Set the extensions name
  68. $name =& $root->getElementByPath('name');
  69. $name = JFilterInput::clean($name->data(), 'cmd');
  70. $this->set('name', $name);
  71. // Set the template root path
  72. $this->parent->setPath('extension_root', $basePath.DS.'templates'.DS.strtolower(str_replace(" ", "_", $this->get('name'))));
  73. /*
  74. * If the template directory already exists, then we will assume that the template is already
  75. * installed or another template is using that directory.
  76. */
  77. if (file_exists($this->parent->getPath('extension_root')) && !$this->parent->getOverwrite()) {
  78. JError::raiseWarning(100, JText::_('Template').' '.JText::_('Install').': '.JText::_('Another template is already using directory').': "'.$this->parent->getPath('extension_root').'"');
  79. return false;
  80. }
  81. // If the template directory does not exist, lets create it
  82. $created = false;
  83. if (!file_exists($this->parent->getPath('extension_root'))) {
  84. if (!$created = JFolder::create($this->parent->getPath('extension_root'))) {
  85. $this->parent->abort(JText::_('Template').' '.JText::_('Install').': '.JText::_('Failed to create directory').' "'.$this->parent->getPath('extension_root').'"');
  86. return false;
  87. }
  88. }
  89. // If we created the template directory and will want to remove it if we have to roll back
  90. // the installation, lets add it to the installation step stack
  91. if ($created) {
  92. $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
  93. }
  94. // Copy all the necessary files
  95. if ($this->parent->parseFiles($root->getElementByPath('files'), -1) === false) {
  96. // Install failed, rollback changes
  97. $this->parent->abort();
  98. return false;
  99. }
  100. if ($this->parent->parseFiles($root->getElementByPath('images'), -1) === false) {
  101. // Install failed, rollback changes
  102. $this->parent->abort();
  103. return false;
  104. }
  105. if ($this->parent->parseFiles($root->getElementByPath('css'), -1) === false) {
  106. // Install failed, rollback changes
  107. $this->parent->abort();
  108. return false;
  109. }
  110. // Parse optional tags
  111. $this->parent->parseFiles($root->getElementByPath('media'), $clientId);
  112. $this->parent->parseLanguages($root->getElementByPath('languages'));
  113. $this->parent->parseLanguages($root->getElementByPath('administration/languages'), 1);
  114. // Get the template description
  115. $description = & $root->getElementByPath('description');
  116. if (is_a($description, 'JSimpleXMLElement')) {
  117. $this->parent->set('message', $description->data());
  118. } else {
  119. $this->parent->set('message', '' );
  120. }
  121. // Lastly, we will copy the manifest file to its appropriate place.
  122. if (!$this->parent->copyManifest(-1)) {
  123. // Install failed, rollback changes
  124. $this->parent->abort(JText::_('Template').' '.JText::_('Install').': '.JText::_('Could not copy setup file'));
  125. return false;
  126. }
  127. // Load template language file
  128. $lang =& JFactory::getLanguage();
  129. $lang->load('tpl_'.$name);
  130. return true;
  131. }
  132. /**
  133. * Custom uninstall method
  134. *
  135. * @access public
  136. * @param int $path The template name
  137. * @param int $clientId The id of the client
  138. * @return boolean True on success
  139. * @since 1.5
  140. */
  141. function uninstall( $name, $clientId )
  142. {
  143. // Initialize variables
  144. $retval = true;
  145. // For a template the id will be the template name which represents the subfolder of the templates folder that the template resides in.
  146. if (!$name) {
  147. JError::raiseWarning(100, JText::_('Template').' '.JText::_('Uninstall').': '.JText::_('Template id is empty, cannot uninstall files'));
  148. return false;
  149. }
  150. // Get the template root path
  151. $client =& JApplicationHelper::getClientInfo( $clientId );
  152. if (!$client) {
  153. JError::raiseWarning(100, JText::_('Template').' '.JText::_('Uninstall').': '.JText::_('Invalid application'));
  154. return false;
  155. }
  156. $this->parent->setPath('extension_root', $client->path.DS.'templates'.DS.$name);
  157. $this->parent->setPath('source', $this->parent->getPath('extension_root'));
  158. $manifest =& $this->parent->getManifest();
  159. if (!is_a($manifest, 'JSimpleXML')) {
  160. // Make sure we delete the folders
  161. JFolder::delete($this->parent->getPath('extension_root'));
  162. JError::raiseWarning(100, JTEXT::_('Template').' '.JTEXT::_('Uninstall').': '.JTEXT::_('Package manifest file invalid or not found'));
  163. return false;
  164. }
  165. $root =& $manifest->document;
  166. // Remove files
  167. $this->parent->removeFiles($root->getElementByPath('media'), $clientId);
  168. $this->parent->removeFiles($root->getElementByPath('languages'));
  169. $this->parent->removeFiles($root->getElementByPath('administration/languages'), 1);
  170. // Delete the template directory
  171. if (JFolder::exists($this->parent->getPath('extension_root'))) {
  172. $retval = JFolder::delete($this->parent->getPath('extension_root'));
  173. } else {
  174. JError::raiseWarning(100, JText::_('Template').' '.JText::_('Uninstall').': '.JText::_('Directory does not exist, cannot remove files'));
  175. $retval = false;
  176. }
  177. return $retval;
  178. }
  179. }