Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /joomla/installer/adapters/template.php

Documentation is available at template.php

  1. <?php
  2. /**
  3. @version        $Id: template.php 6138 2007-01-02 03:44:18Z eddiea $
  4. @package        Joomla.Framework
  5. @subpackage    Installer
  6. @copyright    Copyright (C) 2005 - 2007 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($cnametrue);
  59.             if ($client === false{
  60.                 $this->parent->abort('Template 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.         // Get the template name
  73.         $name =$root->getElementByPath('name');
  74.         $this->set('name'$name->data());
  75.  
  76.         // Set the template root path
  77.         $this->parent->setPath('extension_root'$basePath.DS.'templates'.DS.strtolower(str_replace(" ""_"$this->get('name'))));
  78.  
  79.         /*
  80.          * If the template directory already exists, then we will assume that the template is already
  81.          * installed or another template is using that directory.
  82.          */
  83.         if (file_exists($this->parent->getPath('extension_root')) && !$this->parent->getOverwrite()) {
  84.             JError::raiseWarning(100'Template Install: '.JText::_('Another template is already using directory').': "'.$this->parent->getPath('extension_root').'"');
  85.             return false;
  86.         }
  87.  
  88.         // If the template directory does not exist, lets create it
  89.         $created false;
  90.         if (!file_exists($this->parent->getPath('extension_root'))) {
  91.             if (!$created JFolder::create($this->parent->getPath('extension_root'))) {
  92.                 $this->parent->abort('Template Install: '.JText::_('Failed to create directory').' "'.$this->parent->getPath('extension_root').'"');
  93.                 return false;
  94.             }
  95.         }
  96.  
  97.         // If we created the template directory and will want to remove it if we have to roll back
  98.         // the installation, lets add it to the installation step stack
  99.         if ($created{
  100.             $this->parent->pushStep(array ('type' => 'folder''path' => $this->parent->getPath('extension_root')));
  101.         }
  102.  
  103.         // Copy all the necessary files
  104.         if ($this->parent->parseFiles($root->getElementByPath('files')-1=== false{
  105.             // Install failed, rollback changes
  106.             $this->parent->abort();
  107.             return false;
  108.         }
  109.         if ($this->parent->parseFiles($root->getElementByPath('images')-1=== false{
  110.             // Install failed, rollback changes
  111.             $this->parent->abort();
  112.             return false;
  113.         }
  114.         if ($this->parent->parseFiles($root->getElementByPath('css')-1=== false{
  115.             // Install failed, rollback changes
  116.             $this->parent->abort();
  117.             return false;
  118.         }
  119.  
  120.         // Copy media files
  121.         $this->parent->parseFiles($root->getElementByPath('media')$clientId);
  122.  
  123.         // Get the template description
  124.         $description $root->getElementByPath('description');
  125.         if (is_a($description'JSimpleXMLElement')) {
  126.             $this->parent->set('message'$this->get('name').'<p>'.$description->data().'</p>');
  127.         else {
  128.             $this->parent->set('message'$this->get('name'));
  129.         }
  130.  
  131.         // Lastly, we will copy the manifest file to its appropriate place.
  132.         if (!$this->parent->copyManifest(-1)) {
  133.             // Install failed, rollback changes
  134.             $this->parent->abort('Template Install: '.JText::_('Could not copy setup file'));
  135.             return false;
  136.         }
  137.         return true;
  138.     }
  139.  
  140.     /**
  141.      * Custom uninstall method
  142.      *
  143.      * @access    public
  144.      * @param    int        $path        The template name
  145.      * @param    int        $clientId    The id of the client
  146.      * @return    boolean    True on success
  147.      * @since    1.5
  148.      */
  149.     function uninstall$name$clientId )
  150.     {
  151.         // Initialize variables
  152.         $retval    true;
  153.  
  154.         // For a template the id will be the template name which represents the subfolder of the templates folder that the template resides in.
  155.         if (!$name{
  156.             JError::raiseWarning(100'Template Uninstall: '.JText::_('Template id is empty, cannot uninstall files'));
  157.             return false;
  158.         }
  159.  
  160.         // Get the template root path
  161.         $client JApplicationHelper::getClientInfo$clientId );
  162.         if (!$client{
  163.             JError::raiseWarning(100'Template Uninstall: '.JText::_('Invalid application'));
  164.             return false;
  165.         }
  166.         $this->parent->setPath('extension_root'$client->path.DS.'templates'.DS.$name);
  167.         $this->parent->setPath('source'$this->parent->getPath('extension_root'));
  168.  
  169.         $manifest =$this->parent->getManifest();
  170.         if (!is_a($manifest'JSimpleXML')) {
  171.             // Make sure we delete the folders
  172.             JFolder::delete($this->parent->getPath('extension_root'));
  173.             JError::raiseWarning(100'Template Uninstall: Package manifest file invalid or not found');
  174.             return false;
  175.         }
  176.         $root =$manifest->document;
  177.  
  178.         // Remove files
  179.         $this->parent->removeFiles($root->getElementByPath('media')$clientId);
  180.  
  181.         // Delete the template directory
  182.         if (JFolder::exists($this->parent->getPath('extension_root'))) {
  183.             $retval JFolder::delete($this->parent->getPath('extension_root'));
  184.         else {
  185.             JError::raiseWarning(100'Template Uninstall: '.JText::_('Directory does not exist, cannot remove files'));
  186.             $retval false;
  187.         }
  188.         return $retval;
  189.     }
  190. }
  191. ?>

Documentation generated on Mon, 05 Mar 2007 21:29:12 +0000 by phpDocumentor 1.3.1