3
* @version $Id: languages.php 11213 2008-10-25 12:43:11Z pasamio $
6
* @copyright Copyright (C) 2005 - 2008 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 to the
9
* GNU General Public License, and as distributed it includes or is derivative
10
* of works licensed under the GNU General Public License or other free or open
11
* source software licenses. See COPYRIGHT.php for copyright notices and
15
// Import library dependencies
16
require_once(dirname(__FILE__).DS.'extension.php');
17
jimport( 'joomla.filesystem.folder' );
20
* Installer Languages Model
23
* @subpackage Installer
26
class InstallerModelLanguages extends InstallerModel
32
var $_type = 'language';
35
* Overridden constructor
38
function __construct()
42
// Call the parent constructor
43
parent::__construct();
45
// Set state variables from the request
46
$this->setState('filter.string', $mainframe->getUserStateFromRequest( "com_installer.languages.string", 'filter', '', 'string' ));
47
$this->setState('filter.client', $mainframe->getUserStateFromRequest( "com_installer.languages.client", 'client', -1, 'int' ));
52
global $mainframe, $option;
54
$db = &JFactory::getDBO();
56
if ($this->_state->get('filter.client') < 0) {
58
// Get the site languages
59
$langBDir = JLanguage::getLanguagePath(JPATH_SITE);
60
$langDirs = JFolder::folders($langBDir);
62
for ($i=0; $i < count($langDirs); $i++)
64
$lang = new stdClass();
65
$lang->folder = $langDirs[$i];
67
$lang->baseDir = $langBDir;
70
// Get the admin languages
71
$langBDir = JLanguage::getLanguagePath(JPATH_ADMINISTRATOR);
72
$langDirs = JFolder::folders($langBDir);
74
for ($i=0; $i < count($langDirs); $i++)
76
$lang = new stdClass();
77
$lang->folder = $langDirs[$i];
79
$lang->baseDir = $langBDir;
85
$clientInfo =& JApplicationHelper::getClientInfo($this->_state->get('filter.client'));
86
$client = $clientInfo->name;
87
$langBDir = JLanguage::getLanguagePath($clientInfo->path);
88
$langDirs = JFolder::folders($langBDir);
90
for ($i=0, $n=count($langDirs); $i < $n; $i++)
92
$lang = new stdClass();
93
$lang->folder = $langDirs[$i];
94
$lang->client = $clientInfo->id;
95
$lang->baseDir = $langBDir;
97
if ($this->_state->get('filter.string')) {
98
if (strpos($lang->folder, $this->_state->get('filter.string')) !== false) {
102
$languages[] = $lang;
109
foreach ($languages as $language)
111
$files = JFolder::files( $language->baseDir.DS.$language->folder, '^([-_A-Za-z]*)\.xml$' );
112
foreach ($files as $file)
114
$data = JApplicationHelper::parseXMLLangMetaFile($language->baseDir.DS.$language->folder.DS.$file);
116
$row = new StdClass();
118
$row->client_id = $language->client;
119
$row->language = $language->baseDir.DS.$language->folder;
121
// If we didn't get valid data from the xml file, move on...
122
if (!is_array($data)) {
126
// Populate the row from the xml meta file
127
foreach($data as $key => $value) {
131
// if current than set published
132
$clientVals =& JApplicationHelper::getClientInfo($row->client_id);
133
$lang = JComponentHelper::getParams('com_languages');
134
if ( $lang->get($clientVals->name, 'en-GB') == basename( $row->language ) ) {
140
$row->checked_out = 0;
141
$row->jname = JString::strtolower( str_replace( " ", "_", $row->name ) );
146
$this->setState('pagination.total', count($rows));
147
// if the offset is greater than the total, then can the offset
148
if($this->_state->get('pagination.offset') > $this->_state->get('pagination.total')) {
149
$this->setState('pagination.offset',0);
152
if($this->_state->get('pagination.limit') > 0) {
153
$this->_items = array_slice( $rows, $this->_state->get('pagination.offset'), $this->_state->get('pagination.limit') );
155
$this->_items = $rows;
160
* Remove (uninstall) an extension
163
* @return boolean True on success
166
function remove($eid=array())
170
$lang =& JFactory::getLanguage();
171
$lang->load('com_installer');
173
// Initialize variables
177
* Ensure eid is an array of extension ids
178
* TODO: If it isn't an array do we want to set an error and fail?
180
if (!is_array($eid)) {
183
// construct the list of all language
186
// Get a database connector
187
$db =& JFactory::getDBO();
189
// Get an installer object for the extension type
190
jimport('joomla.installer.installer');
191
$installer =& JInstaller::getInstance($db, $this->_type);
193
// Uninstall the chosen extensions
194
foreach ($eid as $id)
196
$item = $this->_items[$id];
198
// Get client information
199
$client =& JApplicationHelper::getClientInfo($item->client_id);
201
// Don't delete a default ( published language )
202
$params = JComponentHelper::getParams('com_languages');
203
$tag = basename($item->language);
204
if ( $params->get($client->name, 'en-GB') == $tag ) {
206
JError::raiseWarning('', JText::_('UNINSTALLLANGPUBLISHEDALREADY'));
210
$result = $installer->uninstall( 'language', $item->language );
212
// Build an array of extensions that failed to uninstall
213
if ($result === false) {
218
if (count($failed)) {
219
// There was an error in uninstalling the package
220
$msg = JText::sprintf('UNINSTALLEXT', JText::_($this->_type), JText::_('Error'));
223
// Package uninstalled sucessfully
224
$msg = JText::sprintf('UNINSTALLEXT', JText::_($this->_type), JText::_('Success'));
228
$mainframe->enqueueMessage($msg);
229
$this->setState('action', 'remove');
230
$this->setState('message', $installer->message);
231
// re-construct the list of all language
b'\\ No newline at end of file'