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/language.php

Documentation is available at language.php

  1. <?php
  2. /**
  3.  * @version        $Id: language.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.  * Language installer
  20.  *
  21.  * @author        Louis Landry <[email protected]>
  22.  * @package        Joomla.Framework
  23.  * @subpackage    Installer
  24.  * @since        1.5
  25.  */
  26. class JInstallerLanguage extends JObject
  27. {
  28.     /**
  29.      * Core language pack flag
  30.      * @access    private
  31.      * @var        boolean 
  32.      */
  33.     var $_core false;
  34.  
  35.     /**
  36.      * Constructor
  37.      *
  38.      * @access    protected
  39.      * @param    object    $parent    Parent object [JInstaller instance]
  40.      * @return    void 
  41.      * @since    1.5
  42.      */
  43.     function __construct(&$parent)
  44.     {
  45.         $this->parent =$parent;
  46.     }
  47.  
  48.     /**
  49.      * Custom install method
  50.      *
  51.      * @access    public
  52.      * @return    boolean    True on success
  53.      * @since    1.5
  54.      */
  55.     function install()
  56.     {
  57.         // Get database connector object
  58.         $db =$this->parent->getDBO();
  59.         $manifest =$this->parent->getManifest();
  60.         $root =$manifest->document;
  61.  
  62.         // Get the client application target
  63.         if ($cname $root->attributes('client')) {
  64.             // Attempt to map the client to a base path
  65.             jimport('joomla.application.helper');
  66.             $client JApplicationHelper::getClientInfo($cnametrue);
  67.             if ($client === false{
  68.                 $this->parent->abort('Language Install: '.JText::_('Unknown client type').' ['.$cname.']');
  69.                 return false;
  70.             }
  71.             $basePath $client->path;
  72.             $clientId $client->id;
  73.         else {
  74.             // No client attribute was found so we assume the site as the client
  75.             $cname 'site';
  76.             $basePath JPATH_SITE;
  77.             $clientId 0;
  78.         }
  79.  
  80.         // Get the language name
  81.         $name =$root->getElementByPath('name');
  82.         $this->set('name'$name->data());
  83.  
  84.         // Get the Language tag [ISO tag, eg. en-GB]
  85.         $tag =$root->getElementByPath('tag');
  86.         $this->set('tag'$tag->data());
  87.         $folder $tag->data();
  88.  
  89.         // Set the language installation path
  90.         $this->parent->setPath('extension_site'$basePath.DS."language".DS.$this->get('tag'));
  91.  
  92.         // Do we have a meta file in the file list?  In other words... is this a core language pack?
  93.         $element =$root->getElementByPath('files');
  94.         if (is_a($element'JSimpleXMLElement'&& count($element->children())) {
  95.             $files $element->children();
  96.             foreach ($files as $file{
  97.                 if ($file->attributes('file'== 'meta'{
  98.                     $this->_core true;
  99.                     break;
  100.                 }
  101.             }
  102.         }
  103.  
  104.         // Either we are installing a core pack or a core pack must exist for the language we are installing.
  105.         if (!$this->_core{
  106.             if (!JFile::exists($this->parent->getPath('extension_site').DS.$this->get('tag').'.xml')) {
  107.                 $this->parent->abort('Language Install: '.JText::_('No core pack exists for the language').' :'.$this->get('tag'));
  108.                 return false;
  109.             }
  110.         }
  111.  
  112.         // If the language directory does not exist, lets create it
  113.         $created false;
  114.         if (!file_exists($this->parent->getPath('extension_site'))) {
  115.             if (!$created JFolder::create($this->parent->getPath('extension_site'))) {
  116.                 $this->parent->abort('Language Install: '.JText::_('Failed to create directory').' "'.$this->parent->getPath('extension_site').'"');
  117.                 return false;
  118.             }
  119.         }
  120.  
  121.         /*
  122.          * If we created the language directory and will want to remove it if we
  123.          * have to roll back the installation, lets add it to the installation
  124.          * step stack
  125.          */
  126.         if ($created{
  127.             $this->parent->pushStep(array ('type' => 'folder''path' => $this->parent->getPath('extension_site')));
  128.         }
  129.  
  130.         // Copy all the necessary files
  131.         if ($this->parent->parseFiles($element=== false{
  132.             // Install failed, rollback changes
  133.             $this->parent->abort();
  134.             return false;
  135.         }
  136.  
  137.         // Copy all the necessary font files to the common pdf_fonts directory
  138.         $this->parent->setPath('extension_site'$basePath.DS."language".DS.'pdf_fonts');
  139.         $overwrite $this->parent->setOverwrite(true);
  140.         if ($this->parent->parseFiles($root->getElementByPath('fonts')) === false{
  141.             // Install failed, rollback changes
  142.             $this->parent->abort();
  143.             return false;
  144.         }
  145.         $this->parent->setOverwrite($overwrite);
  146.  
  147.         // Get the language description
  148.         $description $root->getElementByPath('description');
  149.         if (is_a($description'JSimpleXMLElement')) {
  150.             $this->parent->set('message'$this->get('name').'<p>'.$description->data().'</p>');
  151.         else {
  152.             $this->parent->set('message'$this->get('name'));
  153.         }
  154.         return true;
  155.     }
  156.  
  157.     /**
  158.      * Custom uninstall method
  159.      *
  160.      * @access    public
  161.      * @param    string    $tag        The tag of the language to uninstall
  162.      * @param    int        $clientId    The id of the client (unused)
  163.      * @return    mixed    Return value for uninstall method in component uninstall file
  164.      * @since    1.5
  165.      */
  166.     function uninstall($tag$clientId)
  167.     {
  168.         $path trim($tag);
  169.         if (!JFolder::exists($path)) {
  170.             JError::raiseWarning(100'Language Uninstall: '.JText::_('Language path is empty, cannot uninstall files'));
  171.             return false;
  172.         }
  173.  
  174.         if (!JFolder::delete($path)) {
  175.             JError::raiseWarning(100'Language Uninstall: '.JText::_('Unable to remove language directory'));
  176.             return false;
  177.         }
  178.         return true;
  179.     }
  180. }
  181. ?>

Documentation generated on Mon, 05 Mar 2007 21:09:02 +0000 by phpDocumentor 1.3.1