~dantrevino/ubuntu-us-florida-website/main

« back to all changes in this revision

Viewing changes to administrator/components/com_installer/models/languages.php

  • Committer: Dan Trevnio
  • Date: 2009-03-24 20:37:18 UTC
  • Revision ID: dantrevino@gmail.com-20090324203718-pg0e3lp4ztjjku9o
initialĀ siteĀ import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * @version             $Id: languages.php 11213 2008-10-25 12:43:11Z pasamio $
 
4
 * @package             Joomla
 
5
 * @subpackage  Menus
 
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
 
12
 * details.
 
13
 */
 
14
 
 
15
// Import library dependencies
 
16
require_once(dirname(__FILE__).DS.'extension.php');
 
17
jimport( 'joomla.filesystem.folder' );
 
18
 
 
19
/**
 
20
 * Installer Languages Model
 
21
 *
 
22
 * @package             Joomla
 
23
 * @subpackage  Installer
 
24
 * @since               1.5
 
25
 */
 
26
class InstallerModelLanguages extends InstallerModel
 
27
{
 
28
        /**
 
29
         * Extension Type
 
30
         * @var string
 
31
         */
 
32
        var $_type = 'language';
 
33
 
 
34
        /**
 
35
         * Overridden constructor
 
36
         * @access      protected
 
37
         */
 
38
        function __construct()
 
39
        {
 
40
                global $mainframe;
 
41
 
 
42
                // Call the parent constructor
 
43
                parent::__construct();
 
44
 
 
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' ));
 
48
        }
 
49
 
 
50
        function _loadItems()
 
51
        {
 
52
                global $mainframe, $option;
 
53
 
 
54
                $db = &JFactory::getDBO();
 
55
 
 
56
                if ($this->_state->get('filter.client') < 0) {
 
57
                        $client = 'all';
 
58
                        // Get the site languages
 
59
                        $langBDir = JLanguage::getLanguagePath(JPATH_SITE);
 
60
                        $langDirs = JFolder::folders($langBDir);
 
61
 
 
62
                        for ($i=0; $i < count($langDirs); $i++)
 
63
                        {
 
64
                                $lang = new stdClass();
 
65
                                $lang->folder = $langDirs[$i];
 
66
                                $lang->client = 0;
 
67
                                $lang->baseDir = $langBDir;
 
68
                                $languages[] = $lang;
 
69
                        }
 
70
                        // Get the admin languages
 
71
                        $langBDir = JLanguage::getLanguagePath(JPATH_ADMINISTRATOR);
 
72
                        $langDirs = JFolder::folders($langBDir);
 
73
 
 
74
                        for ($i=0; $i < count($langDirs); $i++)
 
75
                        {
 
76
                                $lang = new stdClass();
 
77
                                $lang->folder = $langDirs[$i];
 
78
                                $lang->client = 1;
 
79
                                $lang->baseDir = $langBDir;
 
80
                                $languages[] = $lang;
 
81
                        }
 
82
                }
 
83
                else
 
84
                {
 
85
                        $clientInfo =& JApplicationHelper::getClientInfo($this->_state->get('filter.client'));
 
86
                        $client = $clientInfo->name;
 
87
                        $langBDir = JLanguage::getLanguagePath($clientInfo->path);
 
88
                        $langDirs = JFolder::folders($langBDir);
 
89
 
 
90
                        for ($i=0, $n=count($langDirs); $i < $n; $i++)
 
91
                        {
 
92
                                $lang = new stdClass();
 
93
                                $lang->folder = $langDirs[$i];
 
94
                                $lang->client = $clientInfo->id;
 
95
                                $lang->baseDir = $langBDir;
 
96
 
 
97
                                if ($this->_state->get('filter.string')) {
 
98
                                        if (strpos($lang->folder, $this->_state->get('filter.string')) !== false) {
 
99
                                                $languages[] = $lang;
 
100
                                        }
 
101
                                } else {
 
102
                                        $languages[] = $lang;
 
103
                                }
 
104
                        }
 
105
                }
 
106
 
 
107
                $rows = array();
 
108
                $rowid = 0;
 
109
                foreach ($languages as $language)
 
110
                {
 
111
                        $files = JFolder::files( $language->baseDir.DS.$language->folder, '^([-_A-Za-z]*)\.xml$' );
 
112
                        foreach ($files as $file)
 
113
                        {
 
114
                                $data = JApplicationHelper::parseXMLLangMetaFile($language->baseDir.DS.$language->folder.DS.$file);
 
115
 
 
116
                                $row                    = new StdClass();
 
117
                                $row->id                = $rowid;
 
118
                                $row->client_id = $language->client;
 
119
                                $row->language  = $language->baseDir.DS.$language->folder;
 
120
 
 
121
                                // If we didn't get valid data from the xml file, move on...
 
122
                                if (!is_array($data)) {
 
123
                                        continue;
 
124
                                }
 
125
 
 
126
                                // Populate the row from the xml meta file
 
127
                                foreach($data as $key => $value) {
 
128
                                        $row->$key = $value;
 
129
                                }
 
130
 
 
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 ) ) {
 
135
                                        $row->published = 1;
 
136
                                } else {
 
137
                                        $row->published = 0;
 
138
                                }
 
139
 
 
140
                                $row->checked_out = 0;
 
141
                                $row->jname = JString::strtolower( str_replace( " ", "_", $row->name ) );
 
142
                                $rows[] = $row;
 
143
                                $rowid++;
 
144
                        }
 
145
                }
 
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);
 
150
                }
 
151
 
 
152
                if($this->_state->get('pagination.limit') > 0) {
 
153
                        $this->_items = array_slice( $rows, $this->_state->get('pagination.offset'), $this->_state->get('pagination.limit') );
 
154
                } else {
 
155
                        $this->_items = $rows;
 
156
                }
 
157
        }
 
158
 
 
159
        /**
 
160
         * Remove (uninstall) an extension
 
161
         *
 
162
         * @static
 
163
         * @return boolean True on success
 
164
         * @since 1.0
 
165
         */
 
166
        function remove($eid=array())
 
167
        {
 
168
                global $mainframe;
 
169
 
 
170
                $lang =& JFactory::getLanguage();
 
171
                $lang->load('com_installer');
 
172
 
 
173
                // Initialize variables
 
174
                $failed = array ();
 
175
 
 
176
                /*
 
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?
 
179
                 */
 
180
                if (!is_array($eid)) {
 
181
                        $eid = array ($eid);
 
182
                }
 
183
                // construct the list of all language
 
184
                $this->_loadItems();
 
185
 
 
186
                // Get a database connector
 
187
                $db =& JFactory::getDBO();
 
188
 
 
189
                // Get an installer object for the extension type
 
190
                jimport('joomla.installer.installer');
 
191
                $installer      =& JInstaller::getInstance($db, $this->_type);
 
192
 
 
193
                // Uninstall the chosen extensions
 
194
                foreach ($eid as $id)
 
195
                {
 
196
                        $item = $this->_items[$id];
 
197
 
 
198
                        // Get client information
 
199
                        $client =& JApplicationHelper::getClientInfo($item->client_id);
 
200
 
 
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 ) {
 
205
                                $failed[]       = $id;
 
206
                                JError::raiseWarning('', JText::_('UNINSTALLLANGPUBLISHEDALREADY'));
 
207
                                return;
 
208
                        }
 
209
 
 
210
                        $result = $installer->uninstall( 'language', $item->language );
 
211
 
 
212
                        // Build an array of extensions that failed to uninstall
 
213
                        if ($result === false) {
 
214
                                $failed[] = $id;
 
215
                        }
 
216
                }
 
217
 
 
218
                if (count($failed)) {
 
219
                        // There was an error in uninstalling the package
 
220
                        $msg = JText::sprintf('UNINSTALLEXT', JText::_($this->_type), JText::_('Error'));
 
221
                        $result = false;
 
222
                } else {
 
223
                        // Package uninstalled sucessfully
 
224
                        $msg = JText::sprintf('UNINSTALLEXT', JText::_($this->_type), JText::_('Success'));
 
225
                        $result = true;
 
226
                }
 
227
 
 
228
                $mainframe->enqueueMessage($msg);
 
229
                $this->setState('action', 'remove');
 
230
                $this->setState('message', $installer->message);
 
231
                // re-construct the list of all language
 
232
                $this->_loadItems();
 
233
 
 
234
                return $result;
 
235
        }
 
236
}
 
 
b'\\ No newline at end of file'