These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @package Com_Localise |
||
4 | * @subpackage model |
||
5 | * |
||
6 | * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
||
7 | * @license GNU General Public License version 2 or later; see LICENSE.txt |
||
8 | */ |
||
9 | |||
10 | defined('_JEXEC') or die; |
||
11 | |||
12 | jimport('joomla.filesystem.folder'); |
||
13 | jimport('joomla.filesystem.file'); |
||
14 | use Joomla\Utilities\ArrayHelper; |
||
15 | |||
16 | /** |
||
17 | * Translations Model class for the Localise component |
||
18 | * |
||
19 | * @package Extensions.Components |
||
20 | * @subpackage Localise |
||
21 | * |
||
22 | * @since 1.0 |
||
23 | */ |
||
24 | class LocaliseModelTranslations extends JModelList |
||
25 | { |
||
26 | protected $context = 'com_localise.translations'; |
||
27 | |||
28 | protected $translations; |
||
29 | |||
30 | protected $items; |
||
31 | |||
32 | /** |
||
33 | * Constructor. |
||
34 | * |
||
35 | * @param array $config An optional associative array of configuration settings. |
||
36 | * |
||
37 | * @see JController |
||
38 | * @since 3.5 |
||
39 | */ |
||
40 | public function __construct($config = array()) |
||
41 | { |
||
42 | if (empty($config['filter_fields'])) |
||
43 | { |
||
44 | $config['filter_fields'] = array( |
||
45 | 'filename', |
||
46 | 'completed', |
||
47 | 'translated', |
||
48 | ); |
||
49 | } |
||
50 | |||
51 | parent::__construct($config); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Method to auto-populate the model state. |
||
56 | * |
||
57 | * Note. Calling getState in this method will result in recursion. |
||
58 | * |
||
59 | * @param string $ordering An optional ordering field. |
||
60 | * @param string $direction An optional direction (asc|desc). |
||
61 | * |
||
62 | * @return void |
||
63 | * |
||
64 | * @since 1.6 |
||
65 | */ |
||
66 | protected function populateState($ordering = null, $direction = null) |
||
67 | { |
||
68 | $app = JFactory::getApplication(); |
||
69 | $data = $app->input->get('filters', array(), 'array'); |
||
70 | |||
71 | View Code Duplication | if (empty($data)) |
|
0 ignored issues
–
show
|
|||
72 | { |
||
73 | $data = array(); |
||
74 | $data['select'] = $app->getUserState('com_localise.select'); |
||
75 | $data['search'] = $app->getUserState('com_localise.translations.search'); |
||
76 | } |
||
77 | else |
||
78 | { |
||
79 | $app->setUserState('com_localise.select', $data['select']); |
||
80 | $app->setUserState('com_localise.translations.search', isset($data['search']) ? $data['search'] : ''); |
||
81 | } |
||
82 | |||
83 | $this->setState( |
||
84 | 'filter.search', |
||
85 | isset($data['search']['expr']) ? $data['search']['expr'] : '' |
||
86 | ); |
||
87 | $this->setState( |
||
88 | 'filter.storage', |
||
89 | isset($data['select']['storage']) ? $data['select']['storage'] : '' |
||
90 | ); |
||
91 | $this->setState( |
||
92 | 'filter.origin', |
||
93 | isset($data['select']['origin']) ? $data['select']['origin'] : '' |
||
94 | ); |
||
95 | $this->setState( |
||
96 | 'filter.state', |
||
97 | isset($data['select']['state']) ? $data['select']['state'] : '' |
||
98 | ); |
||
99 | $this->setState( |
||
100 | 'filter.type', |
||
101 | isset($data['select']['type']) ? $data['select']['type'] : '' |
||
102 | ); |
||
103 | $this->setState( |
||
104 | 'filter.client', |
||
105 | isset($data['select']['client']) ? $data['select']['client'] : '' |
||
106 | ); |
||
107 | $this->setState( |
||
108 | 'filter.tag', |
||
109 | isset($data['select']['tag']) ? $data['select']['tag'] :'' |
||
110 | ); |
||
111 | $this->setState( |
||
112 | 'filter.develop', |
||
113 | isset($data['select']['develop']) ? $data['select']['develop'] :'' |
||
114 | ); |
||
115 | |||
116 | $params = JComponentHelper::getParams('com_localise'); |
||
117 | $this->setState('params', $params); |
||
118 | |||
119 | $reference = $params->get('reference', 'en-GB'); |
||
120 | |||
121 | $this->setState('translations.reference', $reference); |
||
122 | |||
123 | // Call auto-populate parent method |
||
124 | parent::populateState($ordering, $direction); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Method to get the row form. |
||
129 | * |
||
130 | * @return mixed JForm object on success, false on failure. |
||
131 | */ |
||
132 | View Code Duplication | public function getForm() |
|
133 | { |
||
134 | // Initialise variables. |
||
135 | $app = JFactory::getApplication(); |
||
136 | |||
137 | // Get the form. |
||
138 | jimport('joomla.form.form'); |
||
139 | JForm::addFormPath(JPATH_COMPONENT . '/models/forms'); |
||
140 | JForm::addFieldPath(JPATH_COMPONENT . '/models/fields'); |
||
141 | $form = JForm::getInstance('com_localise.translations', 'translations', array('control' => 'filters', 'event' => 'onPrepareForm')); |
||
142 | |||
143 | // Check for an error. |
||
144 | if (JError::isError($form)) |
||
145 | { |
||
146 | $this->setError($form->getMessage()); |
||
147 | |||
148 | return false; |
||
149 | } |
||
150 | |||
151 | // Check the session for previously entered form data. |
||
152 | $data = $app->getUserState('com_localise.select', array()); |
||
153 | |||
154 | // Bind the form data if present. |
||
155 | if (!empty($data)) |
||
156 | { |
||
157 | $form->bind(array('select' => $data)); |
||
158 | } |
||
159 | |||
160 | // Check the session for previously entered form data. |
||
161 | $data = $app->getUserState('com_localise.translations.search', array()); |
||
162 | |||
163 | // Bind the form data if present. |
||
164 | if (!empty($data)) |
||
165 | { |
||
166 | $form->bind(array('search' => $data)); |
||
167 | } |
||
168 | |||
169 | return $form; |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * todo: missing description |
||
174 | * |
||
175 | * @return void |
||
176 | */ |
||
177 | private function scanLocalTranslationsFolders() |
||
178 | { |
||
179 | $filter_storage = $this->getState('filter.storage'); |
||
180 | $filter_origin = $this->getState('filter.origin') ? $this->getState('filter.origin') : '.'; |
||
181 | $reftag = $this->getState('translations.reference'); |
||
182 | |||
183 | if ($filter_storage != 'global') |
||
184 | { |
||
185 | $filter_tag = $this->getState('filter.tag') ? ("^($reftag|" . $this->getState('filter.tag') . ")$") : '.'; |
||
186 | $filter_search = $this->getState('filter.search') ? $this->getState('filter.search') : '.'; |
||
187 | $scans = LocaliseHelper::getScans($this->getState('filter.client'), $this->getState('filter.type')); |
||
188 | |||
189 | foreach ($scans as $scan) |
||
190 | { |
||
191 | // For all scans |
||
192 | $prefix = $scan['prefix']; |
||
193 | $suffix = $scan['suffix']; |
||
194 | $type = $scan['type']; |
||
195 | $client = $scan['client']; |
||
196 | $path = $scan['path']; |
||
197 | $folder = $scan['folder']; |
||
0 ignored issues
–
show
$folder is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
198 | |||
199 | $extensions = JFolder::folders($path, $filter_search); |
||
200 | |||
201 | foreach ($extensions as $extension) |
||
202 | { |
||
203 | if (JFolder::exists("$path$extension/language")) |
||
204 | { |
||
205 | // Scan extensions folder |
||
206 | $tags = JFolder::folders("$path$extension/language", $filter_tag); |
||
207 | |||
208 | foreach ($tags as $tag) |
||
209 | { |
||
210 | $file = "$path$extension/language/$tag/$tag.$prefix$extension$suffix.ini"; |
||
211 | $origin = LocaliseHelper::getOrigin("$prefix$extension$suffix", $client); |
||
212 | |||
213 | if (JFile::exists($file) && preg_match("/$filter_origin/", $origin)) |
||
214 | { |
||
215 | $translation = new JObject( |
||
216 | array( |
||
217 | 'type' => $type, |
||
218 | 'tag' => $tag, |
||
219 | 'client' => $client, |
||
220 | 'storage' => 'local', |
||
221 | 'filename' => "$prefix$extension$suffix", |
||
222 | 'name' => "$prefix$extension$suffix", |
||
223 | 'refpath' => null, |
||
224 | 'path' => $file, |
||
225 | 'state' => $tag == $reftag ? 'inlanguage' : 'notinreference', |
||
226 | 'writable' => LocaliseHelper::isWritable($file), |
||
227 | 'origin' => $origin |
||
228 | ) |
||
229 | ); |
||
230 | $this->translations["$client|$tag|$prefix$extension$suffix"] = $translation; |
||
231 | } |
||
232 | } |
||
233 | } |
||
234 | } |
||
235 | } |
||
236 | } |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * todo: missing function description |
||
241 | * |
||
242 | * @return void |
||
243 | */ |
||
244 | private function scanGlobalTranslationsFolders() |
||
245 | { |
||
246 | $filter_storage = $this->getState('filter.storage'); |
||
247 | $reftag = $this->getState('translations.reference'); |
||
248 | |||
249 | if ($filter_storage != 'local') |
||
250 | { |
||
251 | // Scan global folder |
||
252 | $filter_client = $this->getState('filter.client'); |
||
253 | $filter_tag = $this->getState('filter.tag') ? ("^($reftag|" . $this->getState('filter.tag') . ")$") : '.'; |
||
254 | $filter_type = $this->getState('filter.type') ? $this->getState('filter.type') : '.'; |
||
255 | $filter_search = $this->getState('filter.search') ? $this->getState('filter.search') : '.'; |
||
256 | $filter_origin = $this->getState('filter.origin') ? $this->getState('filter.origin') : '.'; |
||
257 | |||
258 | View Code Duplication | if (empty($filter_client)) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
259 | { |
||
260 | $clients = array('site', 'administrator', 'installation'); |
||
261 | } |
||
262 | else |
||
263 | { |
||
264 | $clients = array($filter_client); |
||
265 | } |
||
266 | |||
267 | foreach ($clients as $client) |
||
268 | { |
||
269 | // For all selected clients |
||
270 | $path = constant('LOCALISEPATH_' . strtoupper($client)) . '/language'; |
||
271 | |||
272 | if (JFolder::exists($path)) |
||
273 | { |
||
274 | $tags = JFolder::folders($path, $filter_tag, false, false, array('overrides', '.svn', 'CVS', '.DS_Store', '__MACOSX')); |
||
275 | |||
276 | foreach ($tags as $tag) |
||
277 | { |
||
278 | if (JFile::exists($path . '/' . $tag . '/' . $tag . '.xml')) |
||
279 | { |
||
280 | // For all selected tags |
||
281 | $files = JFolder::files("$path/$tag", "$filter_search.*\.ini$"); |
||
282 | |||
283 | foreach ($files as $file) |
||
284 | { |
||
285 | $filename = substr($file, 1 + strlen($tag)); |
||
286 | |||
287 | if ($filename == 'ini') |
||
288 | { |
||
289 | $filename = ''; |
||
290 | } |
||
291 | else |
||
292 | { |
||
293 | $filename = substr($filename, 0, strlen($filename) - 4); |
||
294 | } |
||
295 | |||
296 | $origin = LocaliseHelper::getOrigin($filename, $client); |
||
297 | |||
298 | if (preg_match("/$filter_origin/", $origin)) |
||
299 | { |
||
300 | $prefix = substr($file, 0, 4 + strlen($tag)); |
||
301 | |||
302 | $translation = new JObject( |
||
303 | array( |
||
304 | 'tag' => $tag, |
||
305 | 'client' => $client, |
||
306 | 'storage' => 'global', |
||
307 | 'refpath' => null, |
||
308 | 'path' => "$path/$tag/$file", |
||
309 | 'state' => $tag == $reftag ? 'inlanguage' : 'notinreference', |
||
310 | 'writable' => LocaliseHelper::isWritable("$path/$tag/$file"), |
||
311 | 'origin' => $origin |
||
312 | ) |
||
313 | ); |
||
314 | |||
315 | if ($file == "$tag.ini" && preg_match("/$filter_type/", 'joomla')) |
||
316 | { |
||
317 | // Scan joomla ini file |
||
318 | $translation->setProperties(array('type' => 'joomla', 'filename' => 'joomla', 'name' => JText::_('COM_LOCALISE_TEXT_TRANSLATIONS_JOOMLA'))); |
||
319 | $this->translations["$client|$tag|joomla"] = $translation; |
||
320 | } |
||
321 | View Code Duplication | elseif ($file == "$tag.finder_cli.ini" && preg_match("/$filter_type/", 'file')) |
|
322 | { |
||
323 | $translation->setProperties(array('type' => 'file', 'filename' => $filename, 'name' => $filename)); |
||
324 | $this->translations["$client|$tag|$filename"] = $translation; |
||
325 | } |
||
326 | View Code Duplication | elseif ($file == "$tag.files_joomla.sys.ini" && preg_match("/$filter_type/", 'file')) |
|
327 | { |
||
328 | $translation->setProperties(array('type' => 'file', 'filename' => $filename, 'name' => $filename)); |
||
329 | $this->translations["$client|$tag|$filename"] = $translation; |
||
330 | } |
||
331 | View Code Duplication | elseif ($prefix == "$tag.com" && preg_match("/$filter_type/", 'component')) |
|
332 | { |
||
333 | // Scan component ini file |
||
334 | $translation->setProperties(array('type' => 'component', 'filename' => $filename, 'name' => $filename)); |
||
335 | $this->translations["$client|$tag|$filename"] = $translation; |
||
336 | } |
||
337 | View Code Duplication | elseif ($prefix == "$tag.mod" && preg_match("/$filter_type/", 'module')) |
|
338 | { |
||
339 | // Scan module ini file |
||
340 | $translation->setProperties(array('type' => 'module', 'filename' => $filename, 'name' => $filename)); |
||
341 | $this->translations["$client|$tag|$filename"] = $translation; |
||
342 | } |
||
343 | View Code Duplication | elseif ($prefix == "$tag.tpl" && preg_match("/$filter_type/", 'template')) |
|
344 | { |
||
345 | // Scan template ini file |
||
346 | $translation->setProperties(array('type' => 'template', 'filename' => $filename, 'name' => $filename)); |
||
347 | $this->translations["$client|$tag|$filename"] = $translation; |
||
348 | } |
||
349 | View Code Duplication | elseif ($prefix == "$tag.plg" && preg_match("/$filter_type/", 'plugin')) |
|
350 | { |
||
351 | // Scan plugin ini file |
||
352 | $translation->setProperties(array('type' => 'plugin', 'filename' => $filename, 'name' => $filename)); |
||
353 | $this->translations["$client|$tag|$filename"] = $translation; |
||
354 | } |
||
355 | View Code Duplication | elseif ($prefix == "$tag.pkg" && preg_match("/$filter_type/", 'package')) |
|
356 | { |
||
357 | // Scan package ini file |
||
358 | $translation->setProperties(array('type' => 'package', 'filename' => $filename, 'name' => $filename)); |
||
359 | $this->translations["$client|$tag|$filename"] = $translation; |
||
360 | } |
||
361 | View Code Duplication | elseif ($prefix == "$tag.lib" && preg_match("/$filter_type/", 'library')) |
|
362 | { |
||
363 | // Scan library ini file |
||
364 | $translation->setProperties(array('type' => 'library', 'filename' => $filename, 'name' => $filename)); |
||
365 | $this->translations["$client|$tag|$filename"] = $translation; |
||
366 | } |
||
367 | } |
||
368 | } |
||
369 | } |
||
370 | } |
||
371 | } |
||
372 | } |
||
373 | } |
||
374 | } |
||
375 | |||
376 | /** |
||
377 | * todo: missing function description |
||
378 | * |
||
379 | * @return void |
||
380 | */ |
||
381 | private function scanReference() |
||
382 | { |
||
383 | $reftag = $this->getState('translations.reference'); |
||
384 | $filter_tag = $this->getState('filter.tag') ? ("^($reftag|" . $this->getState('filter.tag') . ")$") : '.'; |
||
385 | $filter_search = $this->getState('filter.search') ? $this->getState('filter.search') : '.'; |
||
386 | $filter_storage = $this->getState('filter.storage'); |
||
387 | $filter_origin = $this->getState('filter.origin'); |
||
388 | $filter_client = $this->getState('filter.client'); |
||
389 | |||
390 | View Code Duplication | if (empty($filter_client)) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
391 | { |
||
392 | $clients = array('site', 'administrator', 'installation'); |
||
393 | } |
||
394 | else |
||
395 | { |
||
396 | $clients = array($filter_client); |
||
397 | } |
||
398 | |||
399 | foreach ($clients as $client) |
||
400 | { |
||
401 | $client_folder = constant('LOCALISEPATH_' . strtoupper($client)) . '/language'; |
||
402 | |||
403 | if (JFolder::exists($client_folder)) |
||
404 | { |
||
405 | // Scan joomla files |
||
406 | $tags = JFolder::folders($client_folder, $filter_tag, false, false, array('overrides', '.svn', 'CVS', '.DS_Store', '__MACOSX')); |
||
407 | |||
408 | foreach ($tags as $tag) |
||
409 | { |
||
410 | if (JFile::exists($client_folder . '/' . $tag . '/' . $tag . '.xml')) |
||
411 | { |
||
412 | if (array_key_exists("$client|$reftag|joomla", $this->translations)) |
||
413 | { |
||
414 | $reftranslation = $this->translations["$client|$reftag|joomla"]; |
||
415 | |||
416 | if (array_key_exists("$client|$tag|joomla", $this->translations)) |
||
417 | { |
||
418 | $this->translations["$client|$tag|joomla"]->setProperties(array('refpath' => $reftranslation->path, 'state' => 'inlanguage')); |
||
419 | } |
||
420 | elseif ($filter_storage != 'local') |
||
421 | { |
||
422 | $origin = LocaliseHelper::getOrigin("", $client); |
||
423 | |||
424 | $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/$tag/$tag.ini"; |
||
425 | |||
426 | $translation = new JObject( |
||
427 | array( |
||
428 | 'type' => 'joomla', |
||
429 | 'tag' => $tag, |
||
430 | 'client' => $client, |
||
431 | 'storage' => 'global', |
||
432 | 'filename' => 'joomla', |
||
433 | 'name' => JText::_('COM_LOCALISE_TEXT_TRANSLATIONS_JOOMLA'), |
||
434 | 'refpath' => $reftranslation->path, |
||
435 | 'path' => $path, |
||
436 | 'state' => 'unexisting', |
||
437 | 'writable' => LocaliseHelper::isWritable($path), |
||
438 | 'origin' => $origin |
||
439 | ) |
||
440 | ); |
||
441 | $this->translations["$client|$tag|joomla"] = $translation; |
||
442 | } |
||
443 | } |
||
444 | } |
||
445 | } |
||
446 | |||
447 | $files = JFolder::files("$client_folder/$reftag", "\.ini$"); |
||
448 | |||
449 | if ($files) |
||
450 | { |
||
451 | foreach ($files as $file) |
||
452 | { |
||
453 | $reftaglength = strlen($reftag); |
||
454 | |||
455 | $name = substr($file, 0, -4); |
||
456 | $name = substr($name, $reftaglength + 1); |
||
457 | |||
458 | $origin = LocaliseHelper::getOrigin($name, $client); |
||
0 ignored issues
–
show
$origin is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
459 | |||
460 | View Code Duplication | foreach ($tags as $tag) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
461 | { |
||
462 | if (JFile::exists($client_folder . '/' . $tag . '/' . $tag . '.xml')) |
||
463 | { |
||
464 | if (array_key_exists("$client|$reftag|$name", $this->translations)) |
||
465 | { |
||
466 | $reftranslation = $this->translations["$client|$reftag|$name"]; |
||
467 | |||
468 | if (array_key_exists("$client|$tag|$name", $this->translations)) |
||
469 | { |
||
470 | $this->translations["$client|$tag|$name"]->setProperties(array('refpath' => $reftranslation->path, 'state' => 'inlanguage')); |
||
471 | } |
||
472 | else |
||
473 | { |
||
474 | $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/$tag/$tag.$name.ini"; |
||
475 | $translation = new JObject( |
||
476 | array( |
||
477 | 'type' => '', |
||
478 | 'tag' => $tag, |
||
479 | 'client' => $client, |
||
480 | 'storage' => 'global', |
||
481 | 'filename' => $name, |
||
482 | 'name' => $name, |
||
483 | 'refpath' => $reftranslation->path, |
||
484 | 'path' => $path, |
||
485 | 'state' => 'unexisting', |
||
486 | 'writable' => LocaliseHelper::isWritable($path), |
||
487 | 'origin' => 'core' |
||
488 | ) |
||
489 | ); |
||
490 | $this->translations["$client|$tag|$name"] = $translation; |
||
491 | } |
||
492 | } |
||
493 | } |
||
494 | } |
||
495 | |||
496 | if (preg_match("/^$reftag\.(lib.*)\.ini$/", $file, $matches)) |
||
497 | { |
||
498 | $name = $matches[1]; |
||
499 | $origin = LocaliseHelper::getOrigin($name, $client); |
||
0 ignored issues
–
show
$origin is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
500 | |||
501 | View Code Duplication | foreach ($tags as $tag) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
502 | { |
||
503 | if (JFile::exists($client_folder . '/' . $tag . '/' . $tag . '.xml')) |
||
504 | { |
||
505 | if (array_key_exists("$client|$reftag|$name", $this->translations)) |
||
506 | { |
||
507 | $reftranslation = $this->translations["$client|$reftag|$name"]; |
||
508 | |||
509 | if (array_key_exists("$client|$tag|$name", $this->translations)) |
||
510 | { |
||
511 | $this->translations["$client|$tag|$name"]->setProperties(array('refpath' => $reftranslation->path, 'state' => 'inlanguage')); |
||
512 | } |
||
513 | else |
||
514 | { |
||
515 | $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/$tag/$tag.$name.ini"; |
||
516 | $translation = new JObject( |
||
517 | array( |
||
518 | 'type' => 'library', |
||
519 | 'tag' => $tag, |
||
520 | 'client' => $client, |
||
521 | 'storage' => 'global', |
||
522 | 'filename' => $name, |
||
523 | 'name' => $name, |
||
524 | 'refpath' => $reftranslation->path, |
||
525 | 'path' => $path, |
||
526 | 'state' => 'unexisting', |
||
527 | 'writable' => LocaliseHelper::isWritable($path), |
||
528 | 'origin' => '_thirdparty' |
||
529 | ) |
||
530 | ); |
||
531 | $this->translations["$client|$tag|$name"] = $translation; |
||
532 | } |
||
533 | } |
||
534 | } |
||
535 | } |
||
536 | } |
||
537 | elseif (preg_match("/^$reftag\.(pkg.*)\.ini$/", $file, $matches)) |
||
538 | { |
||
539 | $name = $matches[1]; |
||
540 | $origin = LocaliseHelper::getOrigin($name, $client); |
||
0 ignored issues
–
show
$origin is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
541 | |||
542 | View Code Duplication | foreach ($tags as $tag) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
543 | { |
||
544 | if (JFile::exists($client_folder . '/' . $tag . '/' . $tag . '.xml')) |
||
545 | { |
||
546 | if (array_key_exists("$client|$reftag|$name", $this->translations)) |
||
547 | { |
||
548 | $reftranslation = $this->translations["$client|$reftag|$name"]; |
||
549 | |||
550 | if (array_key_exists("$client|$tag|$name", $this->translations)) |
||
551 | { |
||
552 | $this->translations["$client|$tag|$name"]->setProperties(array('refpath' => $reftranslation->path, 'state' => 'inlanguage')); |
||
553 | } |
||
554 | else |
||
555 | { |
||
556 | $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/$tag/$tag.$name.ini"; |
||
557 | $translation = new JObject( |
||
558 | array( |
||
559 | 'type' => 'package', |
||
560 | 'tag' => $tag, |
||
561 | 'client' => $client, |
||
562 | 'storage' => 'global', |
||
563 | 'filename' => $name, |
||
564 | 'name' => $name, |
||
565 | 'refpath' => $reftranslation->path, |
||
566 | 'path' => $path, |
||
567 | 'state' => 'unexisting', |
||
568 | 'writable' => LocaliseHelper::isWritable($path), |
||
569 | 'origin' => '_thirdparty' |
||
570 | ) |
||
571 | ); |
||
572 | $this->translations["$client|$tag|$name"] = $translation; |
||
573 | } |
||
574 | } |
||
575 | } |
||
576 | } |
||
577 | } |
||
578 | elseif (preg_match("/^$reftag\.(finder_cli)\.ini$/", $file, $matches) |
||
579 | || preg_match("/^$reftag\.(files_joomla.sys)\.ini$/", $file, $matches) ) |
||
580 | { |
||
581 | $name = $matches[1]; |
||
582 | $origin = LocaliseHelper::getOrigin($name, $client); |
||
0 ignored issues
–
show
$origin is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
583 | |||
584 | foreach ($tags as $tag) |
||
585 | { |
||
586 | if (array_key_exists("$client|$reftag|$name", $this->translations)) |
||
587 | { |
||
588 | $reftranslation = $this->translations["$client|$reftag|$name"]; |
||
589 | |||
590 | if (array_key_exists("$client|$tag|$name", $this->translations)) |
||
591 | { |
||
592 | $this->translations["$client|$tag|$name"]->setProperties(array('refpath' => $reftranslation->path, 'state' => 'inlanguage')); |
||
593 | } |
||
594 | else |
||
595 | { |
||
596 | $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/$tag/$tag.$name.ini"; |
||
597 | $translation = new JObject( |
||
598 | array( |
||
599 | 'type' => 'file', |
||
600 | 'tag' => $tag, |
||
601 | 'client' => $client, |
||
602 | 'storage' => 'global', |
||
603 | 'filename' => $name, |
||
604 | 'name' => $name, |
||
605 | 'refpath' => $reftranslation->path, |
||
606 | 'path' => $path, |
||
607 | 'state' => 'unexisting', |
||
608 | 'writable' => LocaliseHelper::isWritable($path), |
||
609 | 'origin' => 'core' |
||
610 | ) |
||
611 | ); |
||
612 | $this->translations["$client|$tag|$name"] = $translation; |
||
613 | } |
||
614 | } |
||
615 | } |
||
616 | } |
||
617 | } |
||
618 | } |
||
619 | } |
||
620 | } |
||
621 | |||
622 | // Scan extension files |
||
623 | $scans = LocaliseHelper::getScans($this->getState('filter.client'), $this->getState('filter.type')); |
||
624 | |||
625 | foreach ($scans as $scan) |
||
626 | { |
||
627 | $prefix = $scan['prefix']; |
||
628 | $suffix = $scan['suffix']; |
||
629 | $type = $scan['type']; |
||
630 | $client = $scan['client']; |
||
631 | $path = $scan['path']; |
||
632 | $folder = $scan['folder']; |
||
0 ignored issues
–
show
$folder is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the
Loading history...
|
|||
633 | |||
634 | $extensions = JFolder::folders($path, $filter_search); |
||
635 | |||
636 | foreach ($extensions as $extension) |
||
637 | { |
||
638 | if (array_key_exists("$client|$reftag|$prefix$extension$suffix", $this->translations)) |
||
639 | { |
||
640 | $reftranslation = $this->translations["$client|$reftag|$prefix$extension$suffix"]; |
||
641 | $tags = JFolder::folders( |
||
642 | constant('LOCALISEPATH_' . strtoupper($client)) . '/language', |
||
643 | $filter_tag, |
||
644 | false, |
||
645 | false, |
||
646 | array('overrides', '.svn', 'CVS', '.DS_Store', '__MACOSX') |
||
647 | ); |
||
648 | |||
649 | foreach ($tags as $tag) |
||
650 | { |
||
651 | $origin = LocaliseHelper::getOrigin("$prefix$extension$suffix", $client); |
||
652 | |||
653 | if (JFile::exists($client_folder . '/' . $tag . '/' . $tag . '.xml')) |
||
654 | { |
||
655 | if (array_key_exists("$client|$tag|$prefix$extension$suffix", $this->translations)) |
||
656 | { |
||
657 | $this |
||
658 | ->translations["$client|$tag|$prefix$extension$suffix"] |
||
659 | ->setProperties(array('refpath' => $reftranslation->path, 'state' => 'inlanguage')); |
||
660 | } |
||
661 | elseif ($filter_storage != 'local' && ($filter_origin == '' || $filter_origin == $origin)) |
||
662 | { |
||
663 | $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/$tag/$tag.$prefix$extension$suffix.ini"; |
||
664 | $translation = new JObject( |
||
665 | array( |
||
666 | 'type' => $type, |
||
667 | 'tag' => $tag, |
||
668 | 'client' => $client, |
||
669 | 'storage' => 'global', |
||
670 | 'filename' => "$prefix$extension$suffix", |
||
671 | 'name' => "$prefix$extension$suffix", |
||
672 | 'refpath' => $reftranslation->path, |
||
673 | 'path' => $path, 'state' => 'unexisting', |
||
674 | 'writable' => LocaliseHelper::isWritable($path), |
||
675 | 'origin' => $origin |
||
676 | ) |
||
677 | ); |
||
678 | |||
679 | $this->translations["$client|$tag|$prefix$extension$suffix"] = $translation; |
||
680 | } |
||
681 | } |
||
682 | } |
||
683 | } |
||
684 | } |
||
685 | } |
||
686 | } |
||
687 | |||
688 | /** |
||
689 | * todo: missing function description |
||
690 | * |
||
691 | * @return void |
||
692 | */ |
||
693 | private function scanOverride() |
||
694 | { |
||
695 | // Scan overrides ini files |
||
696 | $reftag = $this->getState('translations.reference'); |
||
697 | $filter_client = $this->getState('filter.client'); |
||
698 | $filter_tag = $this->getState('filter.tag') ? ("^($reftag|" . $this->getState('filter.tag') . ")$") : '.'; |
||
699 | $filter_storage = $this->getState('filter.storage'); |
||
700 | $filter_type = $this->getState('filter.type'); |
||
701 | $filter_origin = $this->getState('filter.origin') ? $this->getState('filter.origin') : '.'; |
||
702 | $filter_search = $this->getState('filter.search') ? $this->getState('filter.search') : '.'; |
||
703 | |||
704 | if ((empty($filter_client) || $filter_client != 'installation') |
||
705 | && (empty($filter_storage) || $filter_storage == 'global') |
||
706 | && (empty($filter_type) || $filter_type == 'override') |
||
707 | && preg_match("/$filter_origin/", '_override') && preg_match("/$filter_search/i", 'override')) |
||
708 | { |
||
709 | View Code Duplication | if (empty($filter_client)) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
710 | { |
||
711 | $clients = array('site', 'administrator'); |
||
712 | } |
||
713 | else |
||
714 | { |
||
715 | $clients = array($filter_client); |
||
716 | } |
||
717 | |||
718 | foreach ($clients as $client) |
||
719 | { |
||
720 | $tags = JFolder::folders( |
||
721 | constant('LOCALISEPATH_' . strtoupper($client)) . '/language', |
||
722 | $filter_tag, |
||
723 | false, |
||
724 | false, |
||
725 | array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides') |
||
726 | ); |
||
727 | |||
728 | foreach ($tags as $tag) |
||
729 | { |
||
730 | $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/overrides/$tag.override.ini"; |
||
731 | $translation = new JObject( |
||
732 | array( |
||
733 | 'type' => 'override', |
||
734 | 'tag' => $tag, |
||
735 | 'client' => $client, |
||
736 | 'storage' => 'global', |
||
737 | 'filename' => 'override', |
||
738 | 'name' => 'override', |
||
739 | 'refpath' => $path, |
||
740 | 'path' => $path, |
||
741 | 'state' => 'inlanguage', |
||
742 | 'writable' => LocaliseHelper::isWritable($path), |
||
743 | 'origin' => '_override' |
||
744 | ) |
||
745 | ); |
||
746 | $this->translations["$client|$tag|override"] = $translation; |
||
747 | } |
||
748 | } |
||
749 | } |
||
750 | } |
||
751 | |||
752 | /** |
||
753 | * todo: missing function description |
||
754 | * |
||
755 | * @return array |
||
756 | */ |
||
757 | private function getTranslations() |
||
758 | { |
||
759 | if (!isset($this->translations)) |
||
760 | { |
||
761 | $filter_client = $this->getState('filter.client'); |
||
762 | $filter_tag = $this->getState('filter.tag'); |
||
763 | $filter_develop = $this->getState('filter.develop'); |
||
764 | |||
765 | // Don't try to find translations if filters not set for client and language. |
||
766 | if (empty($filter_client) || empty($filter_tag)) |
||
767 | { |
||
768 | JFactory::getApplication()->enqueueMessage(JText::_('COM_LOCALISE_ERROR_CHOOSE_LANG_CLIENT'), 'notice'); |
||
769 | $this->translations = array(); |
||
770 | |||
771 | return $this->translations; |
||
772 | } |
||
773 | |||
774 | $gh_data = array(); |
||
775 | $gh_data['github_client'] = $filter_client; |
||
776 | |||
777 | $get_github_files = LocaliseHelper::getTargetgithubfiles($gh_data); |
||
778 | $get_customised_ref = LocaliseHelper::getSourceGithubfiles($gh_data); |
||
779 | |||
780 | $filter_state = $this->getState('filter.state') ? $this->getState('filter.state') : '.'; |
||
781 | $filter_tag = $filter_tag ? ("^" . $filter_tag . "$") : '.'; |
||
782 | |||
783 | $cache_controller = JCacheController::getInstance(); |
||
784 | |||
785 | $key = 'translation-' |
||
786 | . ($this->getState('filter.client') ? $this->getState('filter.client') . '-' : '') |
||
787 | . ($this->getState('filter.storage') ? $this->getState('filter.storage') . '-' : '') |
||
788 | . ($this->getState('filter.tag') ? ("^(" . $this->getState('translations.reference') . "|" . $this->getState('filter.tag') . ")$") . '-' : '') |
||
789 | . ($this->getState('filter.type') ? $this->getState('filter.type') . '-' : '') |
||
790 | . ($this->getState('filter.search') ? $this->getState('filter.search') . '-' : '') |
||
791 | . ($this->getState('filter.origin') ? $this->getState('filter.origin') . '-' : ''); |
||
792 | |||
793 | $key = substr($key, 0, strlen($key) - 1); |
||
794 | |||
795 | $this->translations = $cache_controller->get($key, 'localise'); |
||
796 | |||
797 | if (!is_array($this->translations)) |
||
798 | { |
||
799 | $this->translations = array(); |
||
800 | $this->scanLocalTranslationsFolders(); |
||
801 | $this->scanGlobalTranslationsFolders(); |
||
802 | $this->scanReference(); |
||
803 | $this->scanOverride(); |
||
804 | |||
805 | $cache_controller->store($this->translations, $key, 'localise'); |
||
806 | } |
||
807 | |||
808 | foreach ($this->translations as $key => $translation) |
||
809 | { |
||
810 | $model = JModelLegacy::getInstance('Translation', 'LocaliseModel', array('ignore_request' => true)); |
||
811 | $model->setState('translation.id', LocaliseHelper::getFileId($translation->path)); |
||
812 | $model->setState('translation.path', $translation->path); |
||
813 | $model->setState('translation.refpath', $translation->refpath); |
||
814 | $model->setState('translation.reference', $this->getState('translations.reference')); |
||
815 | $model->setState('translation.client', $translation->client); |
||
816 | $model->setState('translation.tag', $translation->tag); |
||
817 | $model->setState('translation.filename', $translation->filename); |
||
818 | |||
819 | $item = $model->getItem(); |
||
820 | $state = count($item->error) ? 'error' : $translation->state; |
||
821 | |||
822 | if (preg_match("/$filter_state/", $state) && preg_match("/$filter_tag/", $translation->tag)) |
||
823 | { |
||
824 | $developdata = $item->developdata; |
||
825 | $untranslateds_amount = $item->untranslated; |
||
826 | $translated_news = $item->translatednews; |
||
827 | $unchanged_news = $item->unchangednews; |
||
828 | $extras_amount = 0; |
||
829 | $unrevised_changes = 0; |
||
830 | $have_develop = 0; |
||
831 | |||
832 | if (!empty($developdata)) |
||
833 | { |
||
834 | $extras_amount = $developdata['extra_keys']['amount']; |
||
835 | $unrevised_changes = $developdata['text_changes']['unrevised']; |
||
836 | } |
||
837 | |||
838 | if (($extras_amount > 0 && $extras_amount > $translated_news + $unchanged_news) || $unrevised_changes > 0 || $untranslateds_amount > 0) |
||
839 | { |
||
840 | $have_develop = 1; |
||
841 | $item->complete = 0; |
||
842 | } |
||
843 | |||
844 | if ($filter_develop == 'complete' && $item->complete == 0) |
||
845 | { |
||
846 | unset($this->translations[$key]); |
||
847 | continue; |
||
848 | } |
||
849 | elseif ($filter_develop == 'incomplete' && $item->complete) |
||
850 | { |
||
851 | unset($this->translations[$key]); |
||
852 | continue; |
||
853 | } |
||
854 | |||
855 | if (count($item->error)) |
||
856 | { |
||
857 | $item->state = 'error'; |
||
858 | $item->completed = - count($item->error) - 1000; |
||
859 | } |
||
860 | elseif ($item->bom != 'UTF-8') |
||
861 | { |
||
862 | if ($translation->state == 'notinreference') |
||
863 | { |
||
864 | $item->completed = - 500; |
||
865 | } |
||
866 | else |
||
867 | { |
||
868 | $item->completed = - 400; |
||
869 | } |
||
870 | } |
||
871 | elseif ($translation->state == 'notinreference') |
||
872 | { |
||
873 | $item->completed = - 600; |
||
874 | } |
||
875 | elseif ($translation->type == 'override') |
||
876 | { |
||
877 | $item->completed = 101; |
||
878 | } |
||
879 | elseif ($translation->tag == $this->getState('translations.reference')) |
||
880 | { |
||
881 | $item->completed = 102; |
||
882 | } |
||
883 | elseif ($translation->state == 'unexisting') |
||
884 | { |
||
885 | $item->completed = - ($item->total / ($item->total + 1)); |
||
886 | } |
||
887 | elseif ($item->complete) |
||
888 | { |
||
889 | $item->completed = 100; |
||
890 | } |
||
891 | |||
892 | $this->translations[$key]->setProperties($item->getProperties()); |
||
893 | } |
||
894 | else |
||
895 | { |
||
896 | unset($this->translations[$key]); |
||
897 | } |
||
898 | } |
||
899 | |||
900 | // Process ordering. |
||
901 | $listOrder = $this->getState('list.ordering', 'name'); |
||
902 | $listDirn = $this->getState('list.direction', 'ASC'); |
||
903 | $this->translations = ArrayHelper::sortObjects($this->translations, $listOrder, strtolower($listDirn) === 'desc' ? -1 : 1, true, true); |
||
904 | |||
905 | $this->translations = array_values($this->translations); |
||
906 | } |
||
907 | |||
908 | return $this->translations; |
||
909 | } |
||
910 | |||
911 | /** |
||
912 | * Get translations |
||
913 | * |
||
914 | * @return array|mixed |
||
915 | */ |
||
916 | View Code Duplication | public function getItems() |
|
917 | { |
||
918 | if (!isset($this->items)) |
||
919 | { |
||
920 | $translations = $this->getTranslations(); |
||
921 | $count = count($translations); |
||
922 | $start = $this->getState('list.start'); |
||
923 | $limit = $this->getState('list.limit'); |
||
924 | |||
925 | if ($start > $count) |
||
926 | { |
||
927 | $start = 0; |
||
928 | } |
||
929 | |||
930 | if ($limit == 0) |
||
931 | { |
||
932 | $start = 0; |
||
933 | $limit = null; |
||
934 | } |
||
935 | |||
936 | $this->items = array_slice($translations, $start, $limit); |
||
937 | } |
||
938 | |||
939 | return $this->items; |
||
940 | } |
||
941 | |||
942 | /** |
||
943 | * Get total number of translations |
||
944 | * |
||
945 | * @return int |
||
946 | */ |
||
947 | public function getTotal() |
||
948 | { |
||
949 | return count($this->getTranslations()); |
||
950 | } |
||
951 | |||
952 | /** |
||
953 | * todo: missing function description |
||
954 | * |
||
955 | * @return mixed |
||
956 | */ |
||
957 | public function getTotalExist() |
||
958 | { |
||
959 | if (!isset($this->_data->total_exist)) |
||
960 | { |
||
961 | if (!isset($this->_data)) |
||
962 | { |
||
963 | $this->_data = new stdClass; |
||
964 | } |
||
965 | |||
966 | $i = 0; |
||
967 | $translations = $this->getTranslations(); |
||
968 | |||
969 | foreach ($translations as $translation) |
||
970 | { |
||
971 | if ($translation->state != 'unexisting') |
||
972 | { |
||
973 | $i++; |
||
974 | } |
||
975 | } |
||
976 | |||
977 | $this->_data->total_exist = $i; |
||
978 | } |
||
979 | |||
980 | return $this->_data->total_exist; |
||
981 | } |
||
982 | } |
||
983 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.