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