GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 85b535...144fe2 )
by
unknown
10s
created

LocaliseModelLanguage::save()   F

Complexity

Conditions 29
Paths 220

Size

Total Lines 183
Code Lines 88

Duplication

Lines 29
Ratio 15.85 %

Importance

Changes 0
Metric Value
dl 29
loc 183
rs 3.9283
c 0
b 0
f 0
cc 29
eloc 88
nc 220
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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.file');
13
jimport('joomla.client.helper');
14
jimport('joomla.access.rules');
15
16
/**
17
 * Language model.
18
 *
19
 * @since  1.0
20
 */
21
class LocaliseModelLanguage extends JModelAdmin
22
{
23
	protected $context = 'com_localise.language';
24
25
	/**
26
	 * Method to auto-populate the model state.
27
	 *
28
	 * @return  void
29
	 */
30
	protected function populateState()
31
	{
32
		$jinput = JFactory::getApplication()->input;
33
34
		$client = $jinput->get('client', 'site', 'cmd');
35
		$tag    = $jinput->get('tag', '', 'cmd');
36
		$id     = $jinput->get('id', '0', 'int');
37
38
		$this->setState('language.client', $client);
39
		$this->setState('language.tag', $tag);
40
		$this->setState('language.id', $id);
41
42
		parent::populateState();
43
	}
44
45
	/**
46
	 * Returns a Table object, always creating it.
47
	 *
48
	 * @param   string  $type    The table type to instantiate
49
	 * @param   string  $prefix  A prefix for the table class name. Optional.
50
	 * @param   array   $config  Configuration array for model. Optional.
51
	 *
52
	 * @return  JTable              A database object
53
	 */
54
	public function getTable($type = 'Localise', $prefix = 'LocaliseTable', $config = array())
55
	{
56
		return JTable::getInstance($type, $prefix, $config);
57
	}
58
59
	/**
60
	 * Method to get the record form.
61
	 *
62
	 * @param   array    $data      Data for the form.
63
	 * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
64
	 *
65
	 * @return  mixed               A JForm object on success, false on failure
66
	 */
67
	public function getForm($data = array(), $loadData = true)
68
	{
69
		// Get the form.
70
		$form = $this->loadForm('com_localise.language', 'language', array('control'   => 'jform', 'load_data' => $loadData));
71
72
		// Make Client field readonly when the file exists
73
		if ($this->getState('language.id'))
74
		{
75
			$form->setFieldAttribute('client', 'readonly', 'true');
76
77
			$client = $form->getValue('client');
78
79
			if ($client == "installation")
80
			{
81
				$form->setFieldAttribute('locale', 'required', 'false');
82
				$form->setFieldAttribute('locale', 'disabled', 'true');
83
84
				$form->setFieldAttribute('weekEnd', 'disabled', 'true');
85
86
				$form->setFieldAttribute('firstDay', 'required', 'false');
87
				$form->setFieldAttribute('firstDay', 'disabled', 'true');
88
89
				$form->setFieldAttribute('calendar', 'required', 'false');
90
				$form->setFieldAttribute('calendar', 'disabled', 'true');
91
92
				$form->setFieldAttribute('authorEmail', 'disabled', 'true');
93
				$form->setFieldAttribute('authorUrl', 'disabled', 'true');
94
				$form->setFieldAttribute('copyright', 'disabled', 'true');
95
			}
96
		}
97
98
		// Calendar and Native Name fields are new in 3.7.x
99
		if (version_compare(JVERSION, '3.7', 'lt'))
100
		{
101
			$form->setFieldAttribute('calendar', 'required', 'false');
102
			$form->setFieldAttribute('calendar', 'disabled', 'true');
103
104
			$form->setFieldAttribute('nativeName', 'required', 'false');
105
			$form->setFieldAttribute('nativeName', 'disabled', 'true');
106
		}
107
108
		return $form;
109
	}
110
111
	/**
112
	 * Method to get the data that should be injected in the form.
113
	 *
114
	 * @return   JObject  The data for the form.
115
	 */
116
	protected function loadFormData()
117
	{
118
		// Check the session for previously entered form data.
119
		$data = JFactory::getApplication()->getUserState('com_localise.edit.language.data', array());
120
121
		// Get the language data.
122
		$data = empty($data) ? $this->getItem() : new JObject($data);
123
124
		$data->joomlacopyright = sprintf("Copyright (C) 2005 - %s Open Source Matters. All rights reserved.", JFactory::getDate()->format('Y'));
125
126
		return $data;
127
	}
128
129
	/**
130
	 * Method to get the ftp form.
131
	 *
132
	 * @return  mixed  A JForm object on success, false on failure or not ftp
133
	 */
134 View Code Duplication
	public function getFormFtp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
135
	{
136
		// Get the form.
137
		$form = $this->loadForm('com_localise.ftp', 'ftp');
138
139
		if (empty($form))
140
		{
141
			return false;
142
		}
143
144
		// Check for an error.
145
		if (JError::isError($form))
146
		{
147
			$this->setError($form->getMessage());
148
149
			return false;
150
		}
151
152
		return $form;
153
	}
154
155
	/**
156
	 * Method to get the language.
157
	 *
158
	 * @param   integer  $pk  The ID of the primary key.
159
	 *
160
	 * @return JObject
161
	 */
162
	public function getItem($pk = null)
163
	{
164
		$id     = $this->getState('language.id');
165
		$client = $this->getState('language.client');
166
		$tag    = $this->getState('language.tag');
167
168
		$language = new JObject;
169
170
		$language->id          = $id;
171
		$language->client      = $client;
172
		$language->tag         = $tag;
173
		$language->checked_out = 0;
174
175
		$params = JComponentHelper::getParams('com_localise');
176
		$language->author      = isset($language->author)
177
			? $language->author
178
			: $params->get('author');
179
		$language->authorEmail = isset($language->authorEmail)
180
			? $language->authorEmail
181
			: $params->get('authorEmail');
182
		$language->authorUrl   = isset($language->authorUrl)
183
			? $language->authorUrl
184
			: $params->get('authorUrl');
185
		$language->copyright   = isset($language->copyright)
186
			? $language->copyright
187
			: $params->get('copyright');
188
		$language->license     = isset($language->license)
189
			? $language->license
190
			: $params->get('license');
191
192
		if (!empty($id))
193
		{
194
			$table = $this->getTable();
195
			$table->load($id);
196
197
			$user = JFactory::getUser($table->checked_out);
198
199
			$language->setProperties($table->getProperties());
200
201
			if ($language->checked_out == JFactory::getUser()->id)
202
			{
203
				$language->checked_out = 0;
204
			}
205
206
			$language->editor   = JText::sprintf('COM_LOCALISE_TEXT_LANGUAGE_EDITOR', $user->name, $user->username);
207
			$language->writable = LocaliseHelper::isWritable($language->path);
208
209
			if (JFile::exists($language->path))
210
			{
211
				$xml = simplexml_load_file($language->path);
212
213
				if ($xml)
214
				{
215
					foreach ($xml->children() as $node)
216
					{
217
						if ($node->getName() == 'metadata')
218
						{
219
							// Metadata nodes
220
							foreach ($node->children() as $subnode)
221
							{
222
								$property            = $subnode->getName();
223
								$language->$property = (string) $subnode;
224
							}
225
						}
226
						else
227
						{
228
							// Main nodes
229
							$property = $node->getName();
230
231
							if ($property == 'copyright')
232
							{
233
								if (isset($language->joomlacopyright))
234
								{
235
									$language->copyright[] = (string) $node;
236
								}
237
								else
238
								{
239
									$language->copyright       = array();
240
									$language->joomlacopyright = (string) $node;
241
								}
242
							}
243
							else
244
							{
245
								$language->$property = (string) $node;
246
							}
247
						}
248
					}
249
250
					$language->copyright = implode('<br/>', $language->copyright);
251
				}
252
				else
253
				{
254
					$this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_FILEEDIT', $language->path));
255
				}
256
			}
257
		}
258
259
		return $language;
260
	}
261
262
	/**
263
	 * Method to validate the form data.
264
	 *
265
	 * @param   JForm   $form   The form to validate against.
266
	 * @param   array   $data   The data to validate.
267
	 * @param   string  $group  The name of the field group to validate.
268
	 *
269
	 * @return  mixed  Array of filtered data if valid, false otherwise.
270
	 *
271
	 * @see     JFormRule
272
	 * @see     JFilterInput
273
	 * @since   12.2
274
	 */
275
	public function validate($form, $data, $group = null)
276
	{
277
		if ($data['client'] == "installation")
278
		{
279
			$form->setFieldAttribute('locale', 'required', 'false');
280
281
			$form->setFieldAttribute('firstDay', 'required', 'false');
282
283
			$form->setFieldAttribute('calendar', 'required', 'false');
284
		}
285
286
		return parent::validate($form, $data, $group);
287
	}
288
289
	/**
290
	 * Saves a language
291
	 *
292
	 * @param   array  $data  Language data
293
	 *
294
	 * @return bool
295
	 */
296
	public function save($data = array())
297
	{
298
		$id = $this->getState('language.id');
299
		$tag    = $data['tag'];
300
301
		// Trim whitespace in $tag
302
		$tag = JFilterInput::getInstance()->clean($tag, 'TRIM');
303
304
		// Check tag is correct
305
		if (strpos($tag, '-') == false)
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($tag, '-') of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
306
		{
307
			$this->setError(JText::_('COM_LOCALISE_ERROR_LANGUAGE_TAG'));
308
309
			return false;
310
		}
311
312
		$partstag = explode('-', $tag);
313
314
		if (strlen($partstag[1]) > 2 || strtoupper($partstag[1]) != $partstag[1]
315
			|| strlen($partstag[0]) > 3 || strtolower($partstag[0]) != $partstag[0])
316
		{
317
			$this->setError(JText::_('COM_LOCALISE_ERROR_LANGUAGE_TAG'));
318
319
			return false;
320
		}
321
322
		// Checks that a custom language name has been entered
323
		if ($data['name'] == "[Name of language] ([Country name])")
324
		{
325
			$this->setError(JText::_('COM_LOCALISE_ERROR_LANGUAGE_NAME'));
326
327
			return false;
328
		}
329
330
		$client = $data['client'];
331
		$path   = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/$tag/$tag.xml";
332
		$exists = JFile::exists($path);
333
		$parts = explode('.', $data['version']);
334
		$small_version = implode('.', array($parts[0],$parts[1]));
335
336
		if ($exists && !empty($id) || !$exists && empty($id))
337
		{
338
			$text = '';
339
			$text .= '<?xml version="1.0" encoding="utf-8"?>' . "\n";
340
			$text .= '<metafile version="' . $small_version . '" client="' . htmlspecialchars($client, ENT_COMPAT, 'UTF-8') . '">' . "\n";
341
			$text .= "\t" . '<tag>' . htmlspecialchars($tag, ENT_COMPAT, 'UTF-8') . '</tag>' . "\n";
342
			$text .= "\t" . '<name>' . htmlspecialchars($data['name'], ENT_COMPAT, 'UTF-8') . '</name>' . "\n";
343
			$text .= "\t" . '<version>' . htmlspecialchars($data['version'], ENT_COMPAT, 'UTF-8') . '</version>' . "\n";
344
			$text .= "\t" . '<creationDate>' . htmlspecialchars($data['creationDate'], ENT_COMPAT, 'UTF-8') . '</creationDate>' . "\n";
345
			$text .= "\t" . '<author>' . htmlspecialchars($data['author'], ENT_COMPAT, 'UTF-8') . '</author>' . "\n";
346
347
			// AuthorEmail, authorURL are not used in the installation
348
			if ($client != "installation")
349
			{
350
				$text .= "\t" . '<authorEmail>' . htmlspecialchars($data['authorEmail'], ENT_COMPAT, 'UTF-8') . '</authorEmail>' . "\n";
351
				$text .= "\t" . '<authorUrl>' . htmlspecialchars($data['authorUrl'], ENT_COMPAT, 'UTF-8') . '</authorUrl>' . "\n";
352
			}
353
354
			$text .= "\t" . '<copyright>' . htmlspecialchars($data['joomlacopyright'], ENT_COMPAT, 'UTF-8') . '</copyright>' . "\n";
355
356
			// Author copyright is not used in installation. It is present in CREDITS file
357
			if ($client != "installation")
358
			{
359
				$data['copyright'] = explode("\n", $data['copyright']);
360
361
				foreach ($data['copyright'] as $copyright)
362
				{
363
					if ($copyright)
364
					{
365
						$text .= "\t" . '<copyright>' . htmlspecialchars($copyright, ENT_COMPAT, 'UTF-8') . '</copyright>' . "\n";
366
					}
367
				}
368
			}
369
370
			$text .= "\t" . '<license>' . htmlspecialchars($data['license'], ENT_COMPAT, 'UTF-8') . '</license>' . "\n";
371
			$text .= "\t" . '<description>' . htmlspecialchars($data['description'], ENT_COMPAT, 'UTF-8') . '</description>' . "\n";
372
			$text .= "\t" . '<metadata>' . "\n";
373
			$text .= "\t\t" . '<name>' . htmlspecialchars($data['name'], ENT_COMPAT, 'UTF-8') . '</name>' . "\n";
374
375 View Code Duplication
			if (version_compare(JVERSION, '3.7', 'ge'))
0 ignored issues
show
Duplication introduced by
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...
376
			{
377
				$text .= "\t\t" . '<nativeName>' . htmlspecialchars($data['nativeName'], ENT_COMPAT, 'UTF-8') . '</nativeName>' . "\n";
378
			}
379
380
			$text .= "\t\t" . '<tag>' . htmlspecialchars($data['tag'], ENT_COMPAT, 'UTF-8') . '</tag>' . "\n";
381
			$text .= "\t\t" . '<rtl>' . htmlspecialchars($data['rtl'], ENT_COMPAT, 'UTF-8') . '</rtl>' . "\n";
382
383
			// Locale, firstDay and weekEnd are not used in the installation
384
			if ($client != "installation")
385
			{
386
				$text .= "\t\t" . '<locale>' . htmlspecialchars($data['locale'], ENT_COMPAT, 'UTF-8') . '</locale>' . "\n";
387
				$text .= "\t\t" . '<firstDay>' . htmlspecialchars($data['firstDay'], ENT_COMPAT, 'UTF-8') . '</firstDay>' . "\n";
388
				$text .= "\t\t" . '<weekEnd>' . htmlspecialchars($data['weekEnd'], ENT_COMPAT, 'UTF-8') . '</weekEnd>' . "\n";
389
390 View Code Duplication
				if (version_compare(JVERSION, '3.7', 'ge'))
0 ignored issues
show
Duplication introduced by
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
					$text .= "\t\t" . '<calendar>' . htmlspecialchars($data['calendar'], ENT_COMPAT, 'UTF-8') . '</calendar>' . "\n";
393
				}
394
			}
395
396
			$text .= "\t" . '</metadata>' . "\n";
397
			$text .= "\t" . '<params />' . "\n";
398
			$text .= '</metafile>' . "\n";
399
400
			// Set FTP credentials, if given.
401
			JClientHelper::setCredentialsFromRequest('ftp');
402
			$ftp = JClientHelper::getCredentials('ftp');
403
404
			// Try to make the file writeable.
405 View Code Duplication
			if ($exists && !$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0644'))
0 ignored issues
show
Duplication introduced by
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...
406
			{
407
				$this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_WRITABLE', $path));
408
409
				return false;
410
			}
411
412
			$return = JFile::write($path, $text);
413
414
			// Get the Localise parameters
415
			$params = JComponentHelper::getParams('com_localise');
416
417
			// Get the file save permission
418
			$fileSavePermission = $params->get('filesavepermission', '0444');
419
420
			// Try to make the template file unwriteable.
421 View Code Duplication
			if (!$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, $fileSavePermission))
0 ignored issues
show
Duplication introduced by
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...
422
			{
423
				$this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_UNWRITABLE', $path));
424
425
				return false;
426
			}
427
			else
428
			{
429
				if (!$return)
430
				{
431
					$this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_FILESAVE', $path));
432
433
					return false;
434
				}
435
			}
436
437
			$id = LocaliseHelper::getFileId($path);
438
439
			// Dummy call to populate state
440
			$this->getState('language.id');
441
442
			$this->setState('language.id', $id);
443
444
			// Bind the rules.
445
			$table = $this->getTable();
446
			$table->load($id);
447
448
			if (isset($data['rules']))
449
			{
450
				$rules = new JAccessRules($data['rules']);
451
				$table->setRules($rules);
452
			}
453
454
			// Check the data.
455
			if (!$table->check())
456
			{
457
				$this->setError($table->getError());
458
459
				return false;
460
			}
461
462
			// Store the data.
463
			if (!$table->store())
464
			{
465
				$this->setError($table->getError());
466
467
				return false;
468
			}
469
470
			return true;
471
		}
472
		else
473
		{
474
			$this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_FILERESET', $path));
475
476
			return false;
477
		}
478
	}
479
480
	/**
481
	 * Remove languages
482
	 *
483
	 * @param   array  &$pks  An array of item ids.
484
	 *
485
	 * @return  boolean  true for success, false for failure
486
	 */
487
	public function delete(&$pks = null)
488
	{
489
		$params  = JComponentHelper::getParams('com_languages');
490
		$id      = $this->getState('language.id');
491
		$tag     = $this->getState('language.tag');
492
		$client  = $this->getState('language.client');
493
		$default = $params->get($client, 'en-GB');
494
		$path    = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/$tag";
495
496
		if ($tag == $default)
497
		{
498
			$this->setError(JText::sprintf('COM_LOCALISE_CANNOT_REMOVE_DEFAULT_LANGUAGE', $path));
499
500
			return false;
501
		}
502
503
		// Check we're not trying to remove an installed langauge pack
504
		$db = JFactory::getDbo();
505
		$query = $db->getQuery(true)
506
			->select($db->quoteName('name'))
507
			->from($db->quoteName('#__extensions'))
508
			->where($db->quoteName('type') . ' = ' . $db->quote('package'))
509
			->where($db->quoteName('state') . ' = 0')
510
			->where($db->quoteName('element') . ' = "pkg_' . $tag . '"');
511
		$db->setQuery($query);
512
		$installedPack = $db->loadResult('name');
513
514
		if ($installedPack != null)
515
		{
516
			$this->setError(JText::sprintf('COM_LOCALISE_CANNOT_REMOVE_INSTALLED_LANGUAGE', $tag));
517
518
			return false;
519
		}
520
521
		if ($tag == 'en-GB')
522
		{
523
			$this->setError(JText::_('COM_LOCALISE_CANNOT_REMOVE_ENGLISH_LANGUAGE'));
524
525
			return false;
526
		}
527
528
		if (!JFactory::getUser()->authorise('localise.delete', $this->option . '.' . $id))
529
		{
530
			$this->setError(JText::_('COM_LOCALISE_CANNOT_REMOVE_LANGUAGE'));
531
532
			return false;
533
		}
534
535
		if (!JFolder::delete($path))
536
		{
537
			$this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGES_REMOVE', "$path"));
538
539
			return false;
540
		}
541
542
		// Clear UserState for select.tag if the language deleted is selected in the filter.
543
		$app = JFactory::getApplication();
544
		$data = $app->getUserState('com_localise.select');
545
546
		if ($data['tag'] == $tag)
547
		{
548
			$data['tag'] = '';
549
			$app->setUserState('com_localise.select', $data);
550
		}
551
552
		$pks = array($id);
553
554
		return parent::delete($pks);
555
	}
556
557
	/**
558
	 * Method to copy the files from the reference lang to the translation language
559
	 *
560
	 * @return  boolean   true if copy is fine, false otherwise
561
	 *
562
	 * @since	4.0.17
563
	 */
564
	public function copy()
565
	{
566
		$app     = JFactory::getApplication();
567
		$params  = JComponentHelper::getParams('com_localise');
568
		$data    = $app->input->get('jform', array(), 'array');
569
570
		$id      = $app->getUserState('com_localise.edit.language.id');
0 ignored issues
show
Unused Code introduced by
$id 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
571
		$ref_tag = $params->get('reference', 'en-GB');
572
		$tag     = $data['tag'];
573
		$client  = $data['client'];
574
575
		$fromPath = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/$ref_tag/";
576
		$toPath   = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/$tag/";
577
578
		// Make sure new language and reference language are different
579
		// en-GB should be left alone
580
		if ($tag == $ref_tag || $tag == 'en-GB')
581
		{
582
			$app->enqueueMessage(JText::_('COM_LOCALISE_ERROR_LANGUAGE_COPY_FILES_NOT_PERMITTED'), 'error');
583
584
			return false;
585
		}
586
587
		// Are there already ini files in the destination folder?
588
		$inifiles = JFolder::files($toPath, ".ini$");
589
590
		if (!empty($inifiles))
591
		{
592
			$app->enqueueMessage(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_NOT_ONLY_XML', $client, $tag), 'error');
593
594
			return false;
595
		}
596
597
		$refFiles = JFolder::files($fromPath);
598
599
		foreach ($refFiles as $file)
600
		{
601
			$ext = JFile::getExt($file);
602
603
			// We do not want to copy existing xmls
604
			if ($ext !== 'xml')
605
			{
606
				// Changing prefix for the copied files
607
				$destFile = str_replace($ref_tag, $tag, $file);
608
609
				if (!JFile::copy($fromPath . $file, $toPath . $destFile))
610
				{
611
					$app->enqueueMessage(JText::Sprintf('COM_LOCALISE_ERROR_LANGUAGE_COULD_NOT_COPY_FILES', $client, $ref_tag, $tag), 'error');
612
613
					return false;
614
				}
615
			}
616
		}
617
618
		// Modify localise.php to fit new tag
619
		$refclassname	= str_replace('-', '_', $ref_tag);
620
		$refclassname	= ucfirst($refclassname);
621
		$langclassname	= str_replace('-', '_', $tag);
622
		$langclassname	= ucfirst($langclassname);
623
		$refComment     = "* " . $ref_tag . " localise class";
624
		$langComment    = "* " . $tag . " localise class";
625
626
		$localisephpPath = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/$tag/$tag.localise.php";
627
628
		if (JFile::exists($localisephpPath))
629
		{
630
			$language_data = file_get_contents($localisephpPath);
631
			$language_data = str_replace($refclassname, $langclassname, $language_data);
632
			$language_data = str_replace($refComment, $langComment, $language_data);
633
			JFile::write($localisephpPath, $language_data);
634
		}
635
636
		return true;
637
	}
638
}
639