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