Source code for file /joomla/installer/adapters/template.php
Documentation is available at template.php
* @version $Id: template.php 6138 2007-01-02 03:44:18Z eddiea $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* @package Joomla.Framework
* @param object $parent Parent object [JInstaller instance]
$this->parent =
& $parent;
* @return boolean True on success
// Get database connector object
$db =
& $this->parent->getDBO();
$manifest =
& $this->parent->getManifest();
$root =
& $manifest->document;
// Get the client application target
if ($cname =
$root->attributes('client')) {
// Attempt to map the client to a base path
jimport('joomla.application.helper');
$this->parent->abort('Template Install: '.
JText::_('Unknown client type').
' ['.
$cname.
']');
$basePath =
$client->path;
// No client attribute was found so we assume the site as the client
$name =
& $root->getElementByPath('name');
$this->set('name', $name->data());
// Set the template root path
* If the template directory already exists, then we will assume that the template is already
* installed or another template is using that directory.
if (file_exists($this->parent->getPath('extension_root')) &&
!$this->parent->getOverwrite()) {
JError::raiseWarning(100, 'Template Install: '.
JText::_('Another template is already using directory').
': "'.
$this->parent->getPath('extension_root').
'"');
// If the template directory does not exist, lets create it
if (!file_exists($this->parent->getPath('extension_root'))) {
if (!$created =
JFolder::create($this->parent->getPath('extension_root'))) {
$this->parent->abort('Template Install: '.
JText::_('Failed to create directory').
' "'.
$this->parent->getPath('extension_root').
'"');
// If we created the template directory and will want to remove it if we have to roll back
// the installation, lets add it to the installation step stack
$this->parent->pushStep(array ('type' =>
'folder', 'path' =>
$this->parent->getPath('extension_root')));
// Copy all the necessary files
if ($this->parent->parseFiles($root->getElementByPath('files'), -
1) ===
false) {
// Install failed, rollback changes
if ($this->parent->parseFiles($root->getElementByPath('images'), -
1) ===
false) {
// Install failed, rollback changes
if ($this->parent->parseFiles($root->getElementByPath('css'), -
1) ===
false) {
// Install failed, rollback changes
$this->parent->parseFiles($root->getElementByPath('media'), $clientId);
// Get the template description
$description =
& $root->getElementByPath('description');
if (is_a($description, 'JSimpleXMLElement')) {
$this->parent->set('message', $this->get('name').
'<p>'.
$description->data().
'</p>');
$this->parent->set('message', $this->get('name'));
// Lastly, we will copy the manifest file to its appropriate place.
if (!$this->parent->copyManifest(-
1)) {
// Install failed, rollback changes
$this->parent->abort('Template Install: '.
JText::_('Could not copy setup file'));
* Custom uninstall method
* @param int $path The template name
* @param int $clientId The id of the client
* @return boolean True on success
// For a template the id will be the template name which represents the subfolder of the templates folder that the template resides in.
// Get the template root path
$this->parent->setPath('extension_root', $client->path.
DS.
'templates'.
DS.
$name);
$this->parent->setPath('source', $this->parent->getPath('extension_root'));
$manifest =
& $this->parent->getManifest();
if (!is_a($manifest, 'JSimpleXML')) {
// Make sure we delete the folders
JError::raiseWarning(100, 'Template Uninstall: Package manifest file invalid or not found');
$root =
& $manifest->document;
$this->parent->removeFiles($root->getElementByPath('media'), $clientId);
// Delete the template directory
$retval =
JFolder::delete($this->parent->getPath('extension_root'));