/**
* Method to parse through a languages element of the installation manifest and take appropriate
* action.
*
* @param \SimpleXMLElement $element The XML node to process
* @param integer $cid Application ID of application to install to
*
* @return boolean True on success
*
* @since 3.1
*/
public function parseLanguages(\SimpleXMLElement $element, $cid = 0)
{
// @todo: work out why the below line triggers 'node no longer exists' errors with files
if (!$element || !\count($element->children())) {
// Either the tag does not exist or has no children therefore we return zero files processed.
return 0;
}
$copyfiles = array();
// Get the client info
$client = ApplicationHelper::getClientInfo($cid);
// Here we set the folder we are going to copy the files to.
// 'languages' Files are copied to JPATH_BASE/language/ folder
$destination = $client->path . '/language';
/*
* Here we set the folder we are going to copy the files from.
*
* Does the element have a folder attribute?
*
* If so this indicates that the files are in a subdirectory of the source
* folder and we should append the folder attribute to the source path when
* copying files.
*/
$folder = (string) $element->attributes()->folder;
if ($folder && file_exists($this->getPath('source') . '/' . $folder)) {
$source = $this->getPath('source') . '/' . $folder;
} else {
$source = $this->getPath('source');
}
// Process each file in the $files array (children of $tagName).
foreach ($element->children() as $file) {
/*
* Language files go in a subfolder based on the language code, ie.
* <language tag="en-US">en-US.mycomponent.ini</language>
* would go in the en-US subdirectory of the language folder.
*/
// We will only install language files where a core language pack
// already exists.
if ((string) $file->attributes()->tag !== '') {
$path['src'] = $source . '/' . $file;
if ((string) $file->attributes()->client !== '') {
// Override the client
$langclient = ApplicationHelper::getClientInfo((string) $file->attributes()->client, true);
$path['dest'] = $langclient->path . '/language/' . $file->attributes()->tag . '/' . basename((string) $file);
} else {
// Use the default client
$path['dest'] = $destination . '/' . $file->attributes()->tag . '/' . basename((string) $file);
}
// If the language folder is not present, then the core pack hasn't been installed... ignore
if (!Folder::exists(\dirname($path['dest']))) {
continue;
}
} else {
$path['src'] = $source . '/' . $file;
$path['dest'] = $destination . '/' . $file;
}
/*
* Before we can add a file to the copyfiles array we need to ensure
* that the folder we are copying our file to exists and if it doesn't,
* we need to create it.
*/
if (basename($path['dest']) !== $path['dest']) {
$newdir = \dirname($path['dest']);
if (!Folder::create($newdir)) {
Log::add(Text::sprintf('JLIB_INSTALLER_ABORT_CREATE_DIRECTORY', Text::_('JLIB_INSTALLER_INSTALL'), $newdir), Log::WARNING, 'jerror');
return false;
}
}
// Add the file to the copyfiles array
$copyfiles[] = $path;
}
return $this->copyFiles($copyfiles);
}