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