/** * Method to get the field input. * * @return string The field input. */ protected function getInput() { $attributes = ''; if ($v = (string) $this->element['onchange']) { $attributes .= ' onchange="' . $v . '"'; } if ($this->value == '_thirdparty') { $attributes .= ' class="' . (string) $this->element['class'] . ' iconlist-16-thirdparty"'; } elseif ($this->value == '_override') { $attributes .= ' class="' . (string) $this->element['class'] . ' iconlist-16-override"'; } else { $attributes .= ' class="' . (string) $this->element['class'] . '"'; } $options = array(); foreach ($this->element->children() as $option) { $options[] = JHtml::_('select.option', $option->attributes('value'), JText::_(trim($option)), array('option.attr' => 'attributes', 'attr' => '')); } $packages = LocaliseHelper::getPackages(); $packages_options = array(); foreach ($packages as $package) { $packages_options[] = JHtml::_('select.option', $package->name, JText::_($package->title), array('option.attr' => 'attributes', 'attr' => 'class="localise-icon" style="background-image: url(' . JURI::root(true) . $package->icon . ');"')); if ($this->value == $package->name) { $attributes .= ' style="background-image: url(' . JURI::root(true) . $package->icon . ');"'; } } $packages_options = JArrayHelper::sortObjects($packages_options, 'text'); $thirdparty = JHtml::_('select.option', '_thirdparty', JText::sprintf('COM_LOCALISE_OPTION_TRANSLATIONS_ORIGIN_THIRDPARTY'), array('option.attr' => 'attributes', 'attr' => 'class="iconlist-16-thirdparty"')); $override = JHtml::_('select.option', '_override', JText::sprintf('COM_LOCALISE_OPTION_TRANSLATIONS_ORIGIN_OVERRIDE'), array('option.attr' => 'attributes', 'attr' => 'class="iconlist-16-override"')); $return = JHtml::_('select.genericlist', array_merge($options, $packages_options, array($thirdparty), array($override)), $this->name, array('id' => $this->id, 'list.select' => $this->value, 'option.attr' => 'attributes', 'list.attr' => $attributes, 'group.items' => null)); return $return; }
protected function addToolbar() { $canDo = LocaliseHelper::getActions(); JToolBarHelper::title(JText::sprintf('COM_LOCALISE_HEADER_MANAGER', JText::_('COM_LOCALISE_HEADER_PACKAGES')), 'install'); if ($canDo->get('localise.create')) { JToolbarHelper::addNew('package.add'); } if ($canDo->get('localise.edit')) { JToolbarHelper::editList('package.edit'); } if ($canDo->get('localise.create') || $canDo->get('localise.edit')) { JToolbarHelper::divider(); } if ($canDo->get('localise.delete')) { JToolbarHelper::deleteList('COM_LOCALISE_MSG_PACKAGES_VALID_DELETE', 'packages.delete'); JToolBarHelper::divider(); } JToolBarHelper::custom('package.download', 'out.png', 'out.png', 'JTOOLBAR_EXPORT', true); JToolBarHelper::divider(); JToolBarHelper::custom('package.language', 'archive.png', 'archive.png', 'COM_LOCALISE_TOOLBAR_PACKAGES_LANGUAGE', true); JToolbarHelper::divider(); if ($canDo->get('package.batch')) { JToolBarHelper::custom('package.batch', 'refresh.png', 'refresh.png', 'COM_LOCALISE_TOOLBAR_PACKAGES_BATCH', true); JToolbarHelper::divider(); } if ($canDo->get('core.admin')) { JToolbarHelper::preferences('com_localise'); JToolbarHelper::divider(); } JToolBarHelper::help('screen.packages', true); }
/** * Method to get the field input markup. * * @return string The field input markup. */ protected function getInput() { $attributes = ''; // To avoid user's confusion, readonly="true" should imply disabled="true". if ((string) $this->element['readonly'] == 'true' || (string) $this->element['disabled'] == 'true') { $attributes .= ' disabled="disabled"'; } if ($v = (string) $this->element['onchange']) { $attributes .= ' onchange="' . $v . '"'; } $attributes .= ' class="' . (string) $this->element['class'] . ' iconlist-16-' . $this->value . '"'; $options = array(); foreach ($this->element->children() as $option) { $options[] = JHtml::_('select.option', $option->attributes('value'), JText::_(trim($option)), array('option.attr' => 'attributes', 'attr' => '')); } $options[] = JHtml::_('select.option', 'site', JText::_('COM_LOCALISE_OPTION_CLIENT_SITE'), array('option.attr' => 'attributes', 'attr' => 'class="iconlist-16-site"')); $options[] = JHtml::_('select.option', 'administrator', JText::_('COM_LOCALISE_OPTION_CLIENT_ADMINISTRATOR'), array('option.attr' => 'attributes', 'attr' => 'class="iconlist-16-administrator"')); if (LocaliseHelper::hasInstallation()) { $options[] = JHtml::_('select.option', 'installation', JText::_('COM_LOCALISE_OPTION_CLIENT_INSTALLATION'), array('option.attr' => 'attributes', 'attr' => 'class="iconlist-16-installation"')); } $return = array(); if ((string) $this->element['readonly'] == 'true') { $return[] = JHtml::_('select.genericlist', $options, '', array('id' => $this->id, 'list.select' => $this->value, 'option.attr' => 'attributes', 'list.attr' => $attributes)); $return[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>'; } else { $return[] = JHtml::_('select.genericlist', $options, $this->name, array('id' => $this->id, 'list.select' => $this->value, 'option.attr' => 'attributes', 'list.attr' => $attributes)); } return implode($return); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { $canDo = LocaliseHelper::getActions(); JToolbarHelper::title(JText::sprintf('COM_LOCALISE_HEADER_MANAGER', JText::_('COM_LOCALISE_HEADER_TRANSLATIONS')), 'comments-2 langmanager'); if ($canDo->get('core.admin')) { JToolbarHelper::preferences('com_localise'); JToolbarHelper::divider(); } JToolBarHelper::help('screen.translations', true); }
/** * Add the page title and toolbar. * * @since 1.6 */ protected function addToolbar() { $canDo = LocaliseHelper::getActions(); JToolbarHelper::title(JText::sprintf('COM_LOCALISE_HEADER_MANAGER', JText::_('COM_LOCALISE_HEADER_LANGUAGES')), 'comments-2 langmanager'); if ($canDo->get('localise.create')) { JToolbarHelper::addNew('language.add'); JToolbarHelper::divider(); } if ($canDo->get('core.admin')) { JToolbarHelper::preferences('com_localise'); JToolbarHelper::divider(); } JToolBarHelper::help('screen.languages', true); JHtmlSidebar::setAction('index.php?option=com_localise&view=languages'); }
/** * Display the view * * @return void */ function display($tpl = null) { // Get the data $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->state = $this->get('State'); $this->form = $this->get('Form'); LocaliseHelper::addSubmenu('languages'); // Check for errors. if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } // Set the toolbar $this->addToolbar(); $this->sidebar = JHtmlSidebar::render(); // Display the view parent::display($tpl); }
public function delete() { // Check for request forgeries. JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Initialise variables. $user = JFactory::getUser(); $ids = JRequest::getVar('cid', array(), '', 'array'); // Access checks. foreach ($ids as $i => $package) { $id = LocaliseHelper::getFileId(JPATH_ROOT . "/media/com_localise/packages/{$package}.xml"); $model = $this->getModel('Package'); $model->setState('package.id', $id); $item = $model->getItem(); if (!$item->standalone) { // Prune items that you can't delete. unset($ids[$i]); JError::raiseNotice(403, JText::_('COM_LOCALISE_ERROR_PACKAGES_DELETE')); } if (!$user->authorise('core.delete', 'com_localise.' . (int) $id)) { // Prune items that you can't delete. unset($ids[$i]); JError::raiseNotice(403, JText::_('JERROR_CORE_DELETE_NOT_PERMITTED')); } } if (empty($ids)) { $msg = JText::_('JERROR_NO_ITEMS_SELECTED'); $type = 'error'; } else { // Get the model. $model = $this->getModel(); // Remove the items. if (!$model->delete($ids)) { $msg = implode("<br />", $model->getErrors()); $type = 'error'; } else { $msg = JText::sprintf('JCONTROLLER_N_ITEMS_DELETED', count($ids)); $type = 'message'; } } $this->setRedirect(JRoute::_('index.php?option=com_localise&view=packages', false), $msg, $type); }
protected static function scanPackages() { self::$origins = array('site' => null, 'administrator' => null, 'installation' => null); $model = JModelLegacy::getInstance('Packages', 'LocaliseModel', array('ignore_request' => true)); $model->setState('list.start', 0); $model->setState('list.limit', 0); $packages = $model->getItems(); self::$packages = array(); foreach ($packages as $package) { self::$packages[$package->name] = $package; foreach ($package->administrator as $file) { self::$origins['administrator'][$file] = $package->name; } foreach ($package->site as $file) { self::$origins['site'][$file] = $package->name; } foreach ($package->installation as $file) { self::$origins['installation'][$file] = $package->name; } } }
private function _getPackages() { if (!isset($this->packages)) { $search = $this->getState('filter.search'); $this->packages = array(); $path = JPATH_COMPONENT_ADMINISTRATOR . '/packages'; if (JFolder::exists($path)) { $files = JFolder::files($path, '\\.xml$'); foreach ($files as $file) { $model = JModelLegacy::getInstance('Package', 'LocaliseModel', array('ignore_request' => true)); $id = LocaliseHelper::getFileId("{$path}/{$file}"); $model->setState('package.id', $id); $package = $model->getItem(); if (empty($search) || preg_match("/{$search}/i", $package->title)) { $this->packages[] = $package; } } } $ordering = $this->getState('list.ordering') ? $this->getState('list.ordering') : 'title'; JArrayHelper::sortObjects($this->packages, $ordering, $this->getState('list.direction') == 'desc' ? -1 : 1); } return $this->packages; }
/** * Get all languages (according to filters) * * @return array array of object items */ protected function getLanguages() { if (!isset($this->languages)) { $this->languages = array(); $client = $this->getState('filter.client'); $tag = $this->getState('filter.tag'); $search = $this->getState('filter.search'); if (empty($client)) { $clients = array('site', 'administrator'); if (LocaliseHelper::hasInstallation()) { $clients[] = 'installation'; } } else { $clients = array($client); } foreach ($clients as $client) { if (empty($tag)) { $folders = JFolder::folders(constant('LOCALISEPATH_' . strtoupper($client)) . '/language', '.', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides')); } else { $folders = JFolder::folders(constant('LOCALISEPATH_' . strtoupper($client)) . '/language', '^' . $tag . '$', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides')); } foreach ($folders as $folder) { //move to first $id = LocaliseHelper::getFileId(constant('LOCALISEPATH_' . strtoupper($client)) . "/language/{$folder}/{$folder}.xml"); //if it was not found a file. if ($id < 1) { continue; } $model = JModelLegacy::getInstance('Language', 'LocaliseModel', array('ignore_request' => true)); $model->setState('language.tag', $folder); $model->setState('language.client', $client); $model->setState('language.id', $id); $language = $model->getItem(); if (empty($search) || preg_match("/{$search}/i", $language->name)) { $this->languages[] = $language; } } } $ordering = $this->getState('list.ordering') ? $this->getState('list.ordering') : 'name'; JArrayHelper::sortObjects($this->languages, $ordering, $this->getState('list.direction') == 'desc' ? -1 : 1); } return $this->languages; }
/** * Get the parent asset id for the record * * @return int */ protected function _getAssetParentId(JTable $table = NULL, $id = NULL) { // Initialise variables. $db = $this->getDbo(); // Build the query to get the asset id for the parent category. $asset = JTable::getInstance('asset'); $name = basename($this->path); $relativePath = substr($this->path, strlen(JPATH_ROOT)); if (preg_match('/^([^.]*)\\..*\\.ini$/', $name, $matches) || preg_match('/^([^.]*)\\.ini$/', $name, $matches)) { $params = JComponentHelper::getParams('com_localise'); $installation_folder = $params->get('installation', 'installation'); $tag = $matches[1]; if (preg_match('#^/(administrator|plugins)#', $relativePath)) { $id = LocaliseHelper::getFileId(JPATH_ROOT . "/administrator/language/{$tag}/{$tag}.xml"); } elseif (preg_match('#^/' . $installation_folder . '#', $relativePath)) { $id = LocaliseHelper::getFileId(LOCALISEPATH_INSTALLATION . "/language/{$tag}/{$tag}.xml"); } else { $id = LocaliseHelper::getFileId(JPATH_ROOT . "/language/{$tag}/{$tag}.xml"); } $assetName = "com_localise.{$id}"; if (!$asset->loadByName($assetName)) { $component = JTable::getInstance('asset'); if (!$component->loadByName('com_localise')) { $root = JTable::getInstance('asset'); $root->rebuild(); $root->loadByName('root.1'); $component->name = 'com_localise'; $component->title = 'com_localise'; $component->setLocation($root->id, 'last-child'); if (!$component->check() || !$component->store()) { $this->setError($component->getError()); return false; } } $asset->name = "com_localise.{$id}"; $asset->title = $name; $asset->setLocation($component->id, 'last-child'); if (!$asset->check() || !$asset->store()) { $this->setError($asset->getError()); return false; } } } else { if (!$asset->loadByName('com_localise')) { $root = JTable::getInstance('asset'); $root->loadByName('root.1'); $asset->name = 'com_localise'; $asset->title = 'com_localise'; $asset->setLocation($root->id, 'last-child'); if (!$asset->check() || !$asset->store()) { $this->setError($asset->getError()); return false; } } } return $asset->id; }
/** * Todo: description missing * * @return void */ public function download() { // Redirect to the export view $app = JFactory::getApplication(); $name = $app->getUserState('com_localise.package.name'); $path = JPATH_COMPONENT_ADMINISTRATOR . '/packages/' . $name . '.xml'; $id = LocaliseHelper::getFileId($path); // Check if the package exists if (empty($id)) { $this->setRedirect(JRoute::_('index.php?option=' . $this->_option . '&view=packages', false), JText::sprintf('COM_LOCALISE_ERROR_DOWNLOADPACKAGE_UNEXISTING', $name), 'error'); } else { $model = $this->getModel(); $package = $model->getItem(); if (!$package->standalone) { $msg = JText::sprintf('COM_LOCALISE_NOTICE_DOWNLOADPACKAGE_NOTSTANDALONE', $name); $type = 'notice'; } else { $msg = ''; $type = 'message'; } setcookie(JApplicationHelper::getHash($this->_context . '.author'), $package->author, time() + 60 * 60 * 24 * 30); setcookie(JApplicationHelper::getHash($this->_context . '.copyright'), $package->copyright, time() + 60 * 60 * 24 * 30); setcookie(JApplicationHelper::getHash($this->_context . '.email'), $package->email, time() + 60 * 60 * 24 * 30); setcookie(JApplicationHelper::getHash($this->_context . '.url'), $package->url, time() + 60 * 60 * 24 * 30); setcookie(JApplicationHelper::getHash($this->_context . '.version'), $package->version, time() + 60 * 60 * 24 * 30); setcookie(JApplicationHelper::getHash($this->_context . '.license'), $package->license, time() + 60 * 60 * 24 * 30); $this->setRedirect(JRoute::_('index.php?option=com_localise&tmpl=component&view=downloadpackage&name=' . $name . '&standalone=' . $package->standalone, false), $msg, $type); } }
/** * Method to get a list of options for a list input. * * @return array An array of JHtml options. */ protected function getGroups() { // Remove '.ini' from values if (is_array($this->value)) { foreach ($this->value as $key => $val) { $this->value[$key] = substr($val, 0, -4); } } $package = (string) $this->element['package']; $groups = array('Site' => array(), 'Administrator' => array(), 'Installation' => array()); foreach (array('Site', 'Administrator', 'Installation') as $client) { $path = constant('LOCALISEPATH_' . strtoupper($client)) . '/language'; if (JFolder::exists($path)) { $tags = JFolder::folders($path, '.', false, false, array('overrides', '.svn', 'CVS', '.DS_Store', '__MACOSX')); if ($tags) { foreach ($tags as $tag) { $files = JFolder::files("{$path}/{$tag}", ".ini\$"); foreach ($files as $file) { $basename = substr($file, strlen($tag) + 1); if ($basename == 'ini') { $key = 'joomla'; $value = JText::_('COM_LOCALISE_TEXT_TRANSLATIONS_JOOMLA'); $origin = LocaliseHelper::getOrigin('', strtolower($client)); $disabled = $origin != $package && $origin != '_thirdparty'; } else { $key = substr($basename, 0, strlen($basename) - 4); $value = $key; $origin = LocaliseHelper::getOrigin($key, strtolower($client)); $disabled = $origin != $package && $origin != '_thirdparty'; } $groups[$client][$key] = JHtml::_('select.option', strtolower($client) . '_' . $key, $value, 'value', 'text', false); } } } } } $scans = LocaliseHelper::getScans(); foreach ($scans as $scan) { $prefix = $scan['prefix']; $suffix = $scan['suffix']; $type = $scan['type']; $client = ucfirst($scan['client']); $path = $scan['path']; $folder = $scan['folder']; $extensions = JFolder::folders($path); foreach ($extensions as $extension) { if (JFolder::exists("{$path}{$extension}{$folder}/language")) { // scan extensions folder $tags = JFolder::folders("{$path}{$extension}{$folder}/language"); foreach ($tags as $tag) { $file = "{$path}{$extension}{$folder}/language/{$tag}/{$tag}.{$prefix}{$extension}{$suffix}.ini"; if (JFile::exists($file)) { $origin = LocaliseHelper::getOrigin("{$prefix}{$extension}{$suffix}", strtolower($client)); $disabled = $origin != $package && $origin != '_thirdparty'; $groups[$client]["{$prefix}{$extension}{$suffix}"] = JHtml::_('select.option', strtolower($client) . '_' . "{$prefix}{$extension}{$suffix}", "{$prefix}{$extension}{$suffix}", 'value', 'text', $disabled); } } } } } foreach ($groups as $client => $extensions) { JArrayHelper::sortObjects($groups[$client], 'text'); } // Merge any additional options in the XML definition. $groups = array_merge(parent::getGroups(), $groups); return $groups; }
<?php echo JHtml::_('grid.id', $i, $item->name); ?> <?php } else { ?> <?php echo JHtml::_('jgrid.checkedout', $item->editor, $item->checked_out_time); ?> <?php } ?> </td> <td> <?php LocaliseHelper::loadLanguage($item->manifest, $item->client); ?> <span title="<?php echo JText::_($item->title); ?> ::<?php echo JText::_($item->description); ?> " class="hasTooltip localise-icon " style="background-image:url(<?php echo JURI::root(true) . '/' . $item->icon; ?> );"></span> <?php if (!$canAdmin) { ?> <span title="<?php
/** * Method to save data * * @param array the data to save * @return boolean success or failure */ public function save($data) { // Get the package name $name = $data['name']; // Get the package $package = $this->getItem(); $path = JPATH_COMPONENT_ADMINISTRATOR . "/packages/{$name}.xml"; $manifest = $package->manifest ? $package->manifest : 'fil_localise_package_' . $name; $client = $package->client ? $package->client : 'site'; if ($package->standalone) { $title = $package->title ? $package->title : 'fil_localise_package_' . $name; $description = $package->description ? $package->description : 'fil_localise_package_' . $name . '_desc'; // Prepare text to save for the xml package description $text = ''; $text .= '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; $text .= '<package>' . "\n"; $text .= '<title>' . $title . '</title>' . "\n"; $text .= '<description>' . $description . '</description>' . "\n"; $text .= '<manifest client="' . $client . '">' . $manifest . '</manifest>' . "\n"; $text .= '<icon>' . $data['icon'] . '</icon>' . "\n"; $text .= '<author>' . $data['author'] . '</author>' . "\n"; $text .= '<copyright>' . $data['copyright'] . '</copyright>' . "\n"; $text .= '<license>' . $data['license'] . '</license>' . "\n"; $administrator = array(); $site = array(); $installation = array(); foreach ($data['translations'] as $translation) { if (preg_match('/^site_(.*)$/', $translation, $matches)) { $site[] = $matches[1]; } if (preg_match('/^administrator_(.*)$/', $translation, $matches)) { $administrator[] = $matches[1]; } if (preg_match('/^installation_(.*)$/', $translation, $matches)) { $installation[] = $matches[1]; } } if (count($site)) { $text .= '<site>' . "\n"; foreach ($site as $translation) { $text .= '<filename>' . $translation . '.ini</filename>' . "\n"; } $text .= '</site>' . "\n"; } if (count($administrator)) { $text .= '<administrator>' . "\n"; foreach ($administrator as $translation) { $text .= '<filename>' . $translation . '.ini</filename>' . "\n"; } $text .= '</administrator>' . "\n"; } if (count($installation)) { $text .= '<installation>' . "\n"; foreach ($installation as $translation) { $text .= '<filename>' . $translation . '.ini</filename>' . "\n"; } $text .= '</installation>' . "\n"; } $text .= '</package>' . "\n"; // Set FTP credentials, if given. JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); // Try to make the file writeable. if ($exists && !$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0644')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_WRITABLE', $path)); return false; } $return = JFile::write($path, $text); // Try to make the file unwriteable. if (!$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0444')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_UNWRITABLE', $path)); return false; } else { if (!$return) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_FILESAVE', $path)); return false; } } } // Save the title and the description in the language file $translation_path = LocaliseHelper::findTranslationPath($client, JFactory::getLanguage()->getTag(), $manifest); $translation_id = LocaliseHelper::getFileId($translation_path); $translation_model = JModelLegacy::getInstance('Translation', 'LocaliseModel', array('ignore_request' => true)); if ($translation_model->checkout($translation_id)) { $translation_model->setState('translation.path', $translation_path); $translation_model->setState('translation.client', $client); $translation = $translation_model->getItem(); $sections = LocaliseHelper::parseSections($translation_path); } else { } $text = ''; $text .= strtoupper($title) . '="' . str_replace('"', '"_QQ_"', $data['title']) . "\"\n"; $text .= strtoupper($description) . '="' . str_replace('"', '"_QQ_"', $data['description']) . "\"\n"; $tag = JFactory::getLanguage()->getTag(); $languagePath = JPATH_SITE . "/language/{$tag}/{$tag}.{$manifest}.ini"; // Try to make the file writeable. if ($exists && !$ftp['enabled'] && JPath::isOwner($languagePath) && !JPath::setPermissions($languagePath, '0644')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_WRITABLE', $languagePath)); return false; } $return = JFile::write($languagePath, $text); // Try to make the file unwriteable. if (!$ftp['enabled'] && JPath::isOwner($languagePath) && !JPath::setPermissions($languagePath, '0444')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_UNWRITABLE', $languagePath)); return false; } else { if (!$return) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_PACKAGE_FILESAVE', $languagePath)); return false; } } $id = LocaliseHelper::getFileId($path); $this->setState('package.id', $id); // Bind the rules. $table = $this->getTable(); $table->load($id); if (isset($data['rules'])) { $rules = new JAccessRules($data['rules']); $table->setRules($rules); } // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } return true; }
/** * Get the item */ public function getItem() { // Get variables $packageName = $this->getState('exportpackage.name'); $packageAuthor = $this->getState('exportpackage.author'); $packageCopyright = $this->getState('exportpackage.copyright'); $packageAuthorEmail = $this->getState('exportpackage.email'); $packageAuthorUrl = $this->getState('exportpackage.url'); $packageVersion = $this->getState('exportpackage.version'); $packageLicense = $this->getState('exportpackage.license'); $path = JPATH_COMPONENT_ADMINISTRATOR . "/packages/{$packageName}.xml"; $id = LocaliseHelper::getFileId($path); // Check if the package exists if (empty($id)) { $this->setError('COM_LOCALISE_ERROR_EXPORT_UNEXISTING', $packageName); return false; } // Get the package model $model = JModelLegacy::getInstance('Package', 'LocaliseModel'); $model->setState('package.id', $id); $model->setState('package.name', $packageName); $package = $model->getItem(); var_dump($package); //jexit(); // Check if the package is correct if (count($package->getErrors())) { $this->setError(implode('<br />', $package->getErrors())); return false; } // Check if the manifest exists $manifest = JPATH_MANIFESTS . '/files/' . $package->manifest . '.xml'; if (is_file($manifest)) { // Get the key name and key description in the manifest $xml = simplexml_load_file($manifest); if ($xml) { $keyName = (string) $xml->name; $keyDescription = (string) $xml->description; $element = $package->manifest; } else { $this->setError('COM_LOCALISE_ERROR_EXPORT_MANIFEST', $manifest); return false; } } else { // Create the key name and key description $keyName = "fil_localise_package_{$packageName}"; $keyDescription = "fil_localise_package_{$packageName}_desc"; $element = "localise_package_{$packageName}"; } // Lookup for language files $tags = JFolder::folders(JPATH_SITE . '/language', '.', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides')); $files = array(); foreach ($tags as $i => $tag) { $langPath = "language/{$tag}/{$tag}.{$keyName}.ini"; if (is_file(JPATH_SITE . "/{$langPath}")) { $files[$tag] = array(); $files[$tag]['name'] = $langPath; $files[$tag]['data'] = file_get_contents(JPATH_SITE . "/{$langPath}"); $files[$tag]['time'] = time(); $files[$tag . '.manage'] = array(); $files[$tag . '.manage']['name'] = "language/{$tag}/{$tag}.{$keyName}.manage.ini"; $lang = JLanguage::getInstance($tag); $lang->load('com_localise', JPATH_ADMINISTRATOR, null, false, false) || $lang->load('com_localise', JPATH_ADMINISTRATOR . '/components/com_localise', null, false, false) || $lang->load('com_localise', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load('com_localise', JPATH_ADMINISTRATOR . '/components/com_localise', $lang->getDefault(), false, false); $files[$tag . '.manage']['data'] = strtoupper($keyName) . '="' . sprintf($lang->_('COM_LOCALISE_NAME_PACKAGE'), $lang->_($package->title)) . "\"\n"; $files[$tag . '.manage']['data'] .= strtoupper($keyDescription) . '="' . sprintf($lang->_('COM_LOCALISE_DESCRIPTION_PACKAGE'), $lang->_($package->title)) . "\"\n"; $files[$tag . '.manage']['time'] = time(); } else { unset($tags[$i]); } } $files['package'] = array(); $files['package']['name'] = "packages/{$packageName}.xml"; $files['package']['data'] = file_get_contents($path); $files['package']['time'] = time(); $files['manifest'] = array(); $files['manifest']['name'] = $element . '.xml'; $files['manifest']['data'] = '<?xml version="1.0" encoding="UTF-8"?> <extension type="file" version="3.1" method="upgrade"> <name>' . strtoupper($keyName) . '</name> <description>' . strtoupper($keyDescription) . '</description> <creationDate>' . JFactory::getDate()->format('F j, Y') . '</creationDate> <author>' . $packageAuthor . '</author> <copyright>' . $packageCopyright . '</copyright> <authorEmail>' . $packageAuthorEmail . '</authorEmail> <authorUrl>' . $packageAuthorUrl . '</authorUrl> <version>' . $packageVersion . '</version> <license>' . $packageLicense . '</license> <fileset> <files target="media/com_localise"> <file>packages/' . $packageName . '.xml</file> </files> </fileset> <languages>'; foreach ($tags as $tag) { $files['manifest']['data'] .= '<language tag="' . $tag . '">language/' . $tag . '/' . $tag . '.' . $keyName . '.ini</language>'; $files['manifest']['data'] .= '<language tag="' . $tag . '">language/' . $tag . '/' . $tag . '.' . $keyName . '.manage.ini</language> '; } $files['manifest']['data'] .= '</languages></extension>'; $files['manifest']['time'] = time(); $ziproot = JPATH_ROOT . '/tmp/' . uniqid('com_localise_') . '.zip'; // Delete old files $delete = JFolder::files(JPATH_ROOT . '/tmp/', 'com_localise_', false, true); if (!empty($delete)) { if (!JFile::delete($delete)) { // JFile::delete throws an error $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ZIPDELETE')); return false; } } // Run the packager if (!($packager = JArchive::getAdapter('zip'))) { $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ADAPTER')); return false; } else { if (!$packager->create($ziproot, $files)) { $this->setError(JText::_('COM_LOCALISE_ERROR_EXPORT_ZIPCREATE')); return false; } } // Create item $item = new JObject(); $item->filename = "fil_localise_{$packageName}_package" . ($packageVersion ? "-{$packageVersion}" : ''); $item->contents = file_get_contents($ziproot); return $item; }
private function _getTranslations() { if (!isset($this->translations)) { $filter_state = $this->getState('filter.state') ? $this->getState('filter.state') : '.'; $filter_tag = $this->getState('filter.tag') ? "^" . $this->getState('filter.tag') . "\$" : '.'; $cache_controller = JCacheController::getInstance(); $key = 'translation-' . ($this->getState('filter.client') ? $this->getState('filter.client') . '-' : '') . ($this->getState('filter.storage') ? $this->getState('filter.storage') . '-' : '') . ($this->getState('filter.tag') ? "^(" . $this->getState('translations.reference') . "|" . $this->getState('filter.tag') . ")\$" . '-' : '') . ($this->getState('filter.type') ? $this->getState('filter.type') . '-' : '') . ($this->getState('filter.search') ? $this->getState('filter.search') . '-' : '') . ($this->getState('filter.origin') ? $this->getState('filter.origin') . '-' : ''); $key = substr($key, 0, strlen($key) - 1); $this->translations = $cache_controller->get($key, 'localise'); if (!is_array($this->translations)) { $this->translations = array(); $this->_scanLocalTranslationsFolders(); $this->_scanGlobalTranslationsFolders(); $this->_scanReference(); $this->_scanOverride(); $cache_controller->store($this->translations, $key, 'localise'); } foreach ($this->translations as $key => $translation) { $model = JModelLegacy::getInstance('Translation', 'LocaliseModel', array('ignore_request' => true)); $model->setState('translation.id', LocaliseHelper::getFileId($translation->path)); $model->setState('translation.path', $translation->path); $model->setState('translation.refpath', $translation->refpath); $model->setState('translation.reference', $this->getState('translations.reference')); $model->setState('translation.client', $translation->client); $model->setState('translation.tag', $translation->tag); $model->setState('translation.filename', $translation->filename); $item = $model->getItem(); $state = count($item->error) ? 'error' : $translation->state; if (preg_match("/{$filter_state}/", $state) && preg_match("/{$filter_tag}/", $translation->tag)) { if (count($item->error)) { $item->state = 'error'; $item->completed = -count($item->error) - 1000; } elseif ($item->bom != 'UTF-8') { if ($translation->state == 'notinreference') { $item->completed = -500; } else { $item->completed = -400; } } elseif ($translation->state == 'notinreference') { $item->completed = -600; } elseif ($translation->type == 'override') { $item->completed = 101; } elseif ($translation->tag == $this->getState('translations.reference')) { $item->completed = 102; } elseif ($translation->state == 'unexisting') { $item->completed = -($item->total / ($item->total + 1)); } elseif ($item->complete) { $item->completed = 100; } $this->translations[$key]->setProperties($item->getProperties()); } else { unset($this->translations[$key]); } } JArrayHelper::sortObjects($this->translations, $this->getState('list.ordering', 'name'), $this->getState('list.direction') == 'asc' ? 1 : -1); $this->translations = array_values($this->translations); } return $this->translations; }
/** * Method to get the extensions. * * @access public * @return array array of component object * @since 1.6 */ public function &getExtensions() { $core = array(); $allfolders = array(); $clients = array('administrator', 'site'); $extensions = array(); $extensions['components'] = array(); $extensions['modules'] = array(); $extensions['plugins'] = array(); $extensions['templates'] = array(); foreach ($clients as $client) { $allfolders[$client] = array(); $core[$client] = array(); // 1. scan global folders $tags =& JFolder::folders(LocaliseHelper::getLanguagesPath($client), '.', false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'pdf_fonts', 'overrides')); foreach ($tags as $tag) { $path = 'language' . DS . $tag; if ($client == 'administrator') { $path = 'administrator' . DS . $path; } $allfolders[$client][] = $path; } // 2. scan extensions folders $extensions_folders = array('components', 'modules', 'templates'); $absolute = constant('JPATH_' . strtoupper($client)); foreach ($extensions_folders as $type) { $exts =& JFolder::folders($absolute . DS . $type, '.', false, false); foreach ($exts as $extension) { $folder = $absolute . DS . $type . DS . $extension . DS . 'language'; if (JFolder::exists($folder)) { $tags =& JFolder::folders($folder, '.', false, false); foreach ($tags as $tag) { $path = $type . DS . $extension . DS . 'language' . DS . $tag; if (JFolder::exists($path . DS . $tag . "." . $extension . ".ini") || JFolder::exists($path . DS . $tag . ".tpl_" . $extension . ".ini")) { if ($client == 'administrator') { $path = 'administrator' . DS . $path; } $allfolders[$client][] = $path; } } } } } } // 3. Scan plugin folders $groups =& JFolder::folders(JPATH_SITE . DS . 'plugins', '.', false, false); foreach ($groups as $group) { $plugins =& JFolder::folders(JPATH_SITE . DS . 'plugins' . DS . $group, '.', false, false); foreach ($plugins as $plugin) { $folder = JPATH_SITE . DS . 'plugins' . DS . $group . DS . $plugin . DS . 'language'; if (JFolder::exists($folder)) { $tags =& JFolder::folders($folder, '.', false, false); foreach ($tags as $tag) { $path = 'plugins' . DS . $group . DS . $plugin . DS . 'language' . DS . $tag; $allfolders['administrator'][] = $path; $allfolders['site'][] = $path; } } } } foreach ($allfolders as $client => $paths) { foreach ($paths as $path) { $files = JFolder::files(JPATH_SITE . DS . $path, '[^.]+\\.[^.]+\\.ini'); foreach ($files as $file) { preg_match('/([^.]+)\\.([^.]+)\\.ini/', $file, $matches); $name =& $matches[2]; if (!array_key_exists($name, $core[$client])) { $start = substr($name, 0, 3); switch ($start) { case 'com': $type = 'components'; break; case 'mod': $type = 'modules'; break; case 'plg': $type = 'plugins'; break; case 'tpl': $type = 'templates'; break; default: $type = 'error'; } if ($type != 'error') { $model = JModel::getInstance('Translation', 'LocaliseModel', array('ignore_request' => true)); $model->setState('path', $path . DS . $file); if ($model->getCore()) { $core[$client][$name] = $name; } if (array_key_exists($name, $core[$client])) { if (array_key_exists($name, $extensions[$type])) { $extensions[$type][$name]->{$client} = -2; $package_field = $client . "_package"; if ($extensions[$type][$name]->site < 0 && $extensions[$type][$name]->administrator < 0) { unset($extensions[$type][$name]); } } } else { if (!array_key_exists($name, $extensions[$type])) { $extensions[$type][$name] = new JObject(); $extensions[$type][$name]->administrator = -1; $extensions[$type][$name]->site = -1; } $extensions[$type][$name]->{$client} = 0; } } } } } } $filename = $this->getFilename(); if ($filename) { $this->_scanManifest(JPATH_ROOT . DS . 'media' . DS . 'com_localise' . DS . 'manifests' . DS . $filename . '.xml', $extensions); } $types = array('components', 'modules', 'plugins', 'templates'); foreach ($types as $type) { foreach ($extensions[$type] as $name => $object) { $object->site_packages = array('home' => array(), 'thirdparty' => array()); $object->administrator_packages = array('home' => array(), 'thirdparty' => array()); } } if (JFolder::exists(JPATH_ROOT . DS . 'media' . DS . 'com_localise' . DS . 'manifests')) { $packages = JFolder::files(JPATH_ROOT . DS . 'media' . DS . 'com_localise' . DS . 'manifests', '\\.*\\.xml', false, true, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html')); foreach ($packages as $package) { if (basename($package, '.xml') != $filename) { $this->_scanOtherManifest($package, $extensions, 'home'); } } } if (JFolder::exists(JPATH_SITE . DS . 'files' . DS . 'com_localise')) { $packages = JFolder::files(JPATH_SITE . DS . 'files' . DS . 'com_localise', '\\.*\\.xml', false, true, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html')); foreach ($packages as $package) { $this->_scanOtherManifest($package, $extensions, 'thirdparty'); } } foreach ($types as $type) { ksort($extensions[$type]); } return $extensions; }
/** * Method to allow derived classes to preprocess the form. * * @param object A form object. * @param mixed The data expected for the form. * @param string The name of the plugin group to import (defaults to "content"). * @throws Exception if there is an error in the form event. * @since 1.6 */ protected function preprocessForm(JForm $form, $item, $group = 'content') { // Initialize variables. $filename = $this->getState('translation.filename'); $client = $this->getState('translation.client'); $tag = $this->getState('translation.tag'); $origin = LocaliseHelper::getOrigin($filename, $client); $app = JFactory::getApplication(); $false = false; // Compute all known languages static $languages = array(); jimport('joomla.language.language'); if (!array_key_exists($client, $languages)) { $languages[$client] = JLanguage::getKnownLanguages(constant('LOCALISEPATH_' . strtoupper($client))); } if (is_object($item)) { $form->setFieldAttribute('legend', 'unchanged', $item->unchanged, 'legend'); $form->setFieldAttribute('legend', 'translated', $item->translated, 'legend'); $form->setFieldAttribute('legend', 'untranslated', $item->total - $item->translated - $item->unchanged, 'legend'); $form->setFieldAttribute('legend', 'extra', $item->extra, 'legend'); } if ($this->getState('translation.layout') != 'raw') { $path = $this->getState('translation.path'); $refpath = $this->getState('translation.refpath'); $sections = LocaliseHelper::parseSections($path); $refsections = LocaliseHelper::parseSections($refpath); $addform = new JXMLElement('<form />'); $group = $addform->addChild('fields'); $group->addAttribute('name', 'strings'); $fieldset = $group->addChild('fieldset'); $fieldset->addAttribute('name', 'Default'); $fieldset->addAttribute('label', 'Default'); if (JFile::exists($refpath)) { $stream = new JStream(); $stream->open($refpath); $header = true; $lineNumber = 0; while (!$stream->eof()) { $line = $stream->gets(); $lineNumber++; // Blank lines if (preg_match('/^\\s*$/', $line)) { $header = true; $field = $fieldset->addChild('field'); $field->addAttribute('label', ''); $field->addAttribute('type', 'spacer'); $field->addAttribute('class', 'text'); continue; } elseif (preg_match('/^\\[([^\\]]*)\\]\\s*$/', $line, $matches)) { $header = false; $form->load($addform, false); $section = $matches[1]; $addform = new JXMLElement('<form />'); $group = $addform->addChild('fields'); $group->addAttribute('name', 'strings'); $fieldset = $group->addChild('fieldset'); $fieldset->addAttribute('name', $section); $fieldset->addAttribute('label', $section); continue; } elseif (!$header && preg_match('/^;(.*)$/', $line, $matches)) { $key = $matches[1]; $field = $fieldset->addChild('field'); $field->addAttribute('label', $key); $field->addAttribute('type', 'spacer'); $field->addAttribute('class', 'text'); continue; } elseif (preg_match('/^([A-Z][A-Z0-9_\\-\\.]*)\\s*=/', $line, $matches)) { $header = false; $key = $matches[1]; $field = $fieldset->addChild('field'); $string = $refsections['keys'][$key]; $translated = isset($sections['keys'][$key]); $modified = $translated && $sections['keys'][$key] != $refsections['keys'][$key]; $status = $modified ? 'translated' : ($translated ? 'unchanged' : 'untranslated'); $default = $translated ? $sections['keys'][$key] : ''; $label = '<b>' . $key . '</b><br />' . htmlspecialchars($string, ENT_COMPAT, 'UTF-8'); $field->addAttribute('status', $status); $field->addAttribute('description', $string); if ($default) { $field->addAttribute('default', $default); } else { $field->addAttribute('default', $string); } $field->addAttribute('label', $label); $field->addAttribute('name', $key); $field->addAttribute('type', 'key'); $field->addAttribute('filter', 'raw'); continue; } elseif (!preg_match('/^(|(\\[[^\\]]*\\])|([A-Z][A-Z0-9_\\-\\.]*\\s*=(\\s*(("[^"]*")|(_QQ_)))+))\\s*(;.*)?$/', $line)) { $this->item->error[] = $lineNumber; } } $stream->close(); $newstrings = false; if (!empty($sections['keys'])) { foreach ($sections['keys'] as $key => $string) { if (!isset($refsections['keys'][$key])) { if (!$newstrings) { $newstrings = true; $form->load($addform, false); $section = 'New Strings'; $addform = new JXMLElement('<form />'); $group = $addform->addChild('fields'); $group->addAttribute('name', 'strings'); $fieldset = $group->addChild('fieldset'); $fieldset->addAttribute('name', $section); $fieldset->addAttribute('label', $section); } $field = $fieldset->addChild('field'); $status = 'extra'; $default = $string; $label = '<b>' . $key . '</b>'; $field->addAttribute('status', $status); $field->addAttribute('description', $string); if ($default) { $field->addAttribute('default', $default); } else { $field->addAttribute('default', $string); } $field->addAttribute('label', $label); $field->addAttribute('name', $key); $field->addAttribute('type', 'key'); $field->addAttribute('filter', 'raw'); } } } } $form->load($addform, false); } // Check the session for previously entered form data. $data = $app->getUserState('com_localise.edit.translation.data', array()); // Bind the form data if present. if (!empty($data)) { $form->bind($data); } if ($origin != '_thirdparty' && $origin != '_override') { $packages = LocaliseHelper::getPackages(); $package = $packages[$origin]; if (!empty($package->author)) { $form->setValue('author', $package->author); $form->setFieldAttribute('author', 'readonly', 'true'); } if (!empty($package->copyright)) { $form->setValue('maincopyright', $package->copyright); $form->setFieldAttribute('maincopyright', 'readonly', 'true'); } if (!empty($package->license)) { $form->setValue('license', $package->license); $form->setFieldAttribute('license', 'readonly', 'true'); } } if ($form->getValue('description') == '' && array_key_exists($tag, $languages[$client])) { $form->setValue('description', $filename . ' ' . $languages[$client][$tag]['name']); } return $form; }
<?php echo JHtml::_('jgrid.action', $i, '', array('tip' => true, 'inactive_title' => JText::sprintf('COM_LOCALISE_TOOLTIP_TRANSLATIONS_ERROR', substr($item->path, strlen(JPATH_ROOT)), implode(', ', $item->error)), 'inactive_class' => '16-error', 'enabled' => false, 'translate' => false)); ?> <?php echo $item->name; ?> <?php } ?> </td> <td dir="ltr"> <?php if ($item->writable && $canEdit) { ?> <a class="hasTooltip" href="<?php echo JRoute::_('index.php?option=com_localise&task=translation.edit&client=' . $item->client . '&tag=' . $item->tag . '&filename=' . $item->filename . '&storage=' . $item->storage . '&id=' . LocaliseHelper::getFileId(LocaliseHelper::getTranslationPath($item->client, $item->tag, $item->filename, $item->storage)) . '&layout=raw'); ?> " title="<?php echo JText::_('COM_LOCALISE_TOOLTIP_TRANSLATIONS_' . ($item->state == 'unexisting' ? 'NEWRAW' : 'EDITRAW')); ?> "> <?php echo substr($item->path, strlen(JPATH_ROOT)); ?> </a> <?php } else { ?> <?php echo substr($item->path, strlen(JPATH_ROOT)); ?>
public function save($data = array()) { $id = $this->getState('language.id'); $tag = $data['tag']; $client = $data['client']; $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/{$tag}/{$tag}.xml"; $exists = JFile::exists($path); if ($exists && !empty($id) || !$exists && empty($id)) { $text = ''; $text .= '<?xml version="1.0" encoding="utf-8"?>' . "\n"; $text .= '<metafile version="3.1" client="' . htmlspecialchars($client, ENT_COMPAT, 'UTF-8') . '">' . "\n"; $text .= "\t" . '<tag>' . htmlspecialchars($tag, ENT_COMPAT, 'UTF-8') . '</tag>' . "\n"; $text .= "\t" . '<name>' . htmlspecialchars($data['name'], ENT_COMPAT, 'UTF-8') . '</name>' . "\n"; $text .= "\t" . '<description>' . htmlspecialchars($data['description'], ENT_COMPAT, 'UTF-8') . '</description>' . "\n"; $text .= "\t" . '<version>' . htmlspecialchars($data['version'], ENT_COMPAT, 'UTF-8') . '</version>' . "\n"; $text .= "\t" . '<creationDate>' . htmlspecialchars($data['creationDate'], ENT_COMPAT, 'UTF-8') . '</creationDate>' . "\n"; $text .= "\t" . '<author>' . htmlspecialchars($data['author'], ENT_COMPAT, 'UTF-8') . '</author>' . "\n"; $text .= "\t" . '<authorEmail>' . htmlspecialchars($data['authorEmail'], ENT_COMPAT, 'UTF-8') . '</authorEmail>' . "\n"; $text .= "\t" . '<authorUrl>' . htmlspecialchars($data['authorUrl'], ENT_COMPAT, 'UTF-8') . '</authorUrl>' . "\n"; $text .= "\t" . '<copyright>' . htmlspecialchars($data['joomlacopyright'], ENT_COMPAT, 'UTF-8') . '</copyright>' . "\n"; $data['copyright'] = explode("\n", $data['copyright']); foreach ($data['copyright'] as $copyright) { if ($copyright) { $text .= "\t" . '<copyright>' . htmlspecialchars($copyright, ENT_COMPAT, 'UTF-8') . '</copyright>' . "\n"; } } $text .= "\t" . '<license>' . htmlspecialchars($data['license'], ENT_COMPAT, 'UTF-8') . '</license>' . "\n"; if ($tag == 'en-GB') { $text .= "\t" . '<files>' . "\n"; $xml = simplexml_load_file($path); foreach ($xml->files->children() as $file) { $text .= "\t\t" . '<filename>' . $file . '</filename>' . "\n"; } $text .= "\t" . '</files>' . "\n"; } else { $text .= "\t" . '<files>' . "\n"; $xml = simplexml_load_file(constant('LOCALISEPATH_' . strtoupper($client)) . "/language/en-GB/en-GB.xml"); foreach ($xml->files->children() as $file) { $text .= "\t\t" . '<filename>' . str_replace('en-GB', $tag, $file) . '</filename>' . "\n"; } $text .= "\t" . '</files>' . "\n"; } $text .= "\t" . '<metadata>' . "\n"; $text .= "\t\t" . '<name>' . htmlspecialchars($data['name'], ENT_COMPAT, 'UTF-8') . '</name>' . "\n"; $text .= "\t\t" . '<tag>' . htmlspecialchars($data['tag'], ENT_COMPAT, 'UTF-8') . '</tag>' . "\n"; $text .= "\t\t" . '<rtl>' . htmlspecialchars($data['rtl'], ENT_COMPAT, 'UTF-8') . '</rtl>' . "\n"; $text .= "\t\t" . '<locale>' . htmlspecialchars($data['locale'], ENT_COMPAT, 'UTF-8') . '</locale>' . "\n"; $text .= "\t\t" . '<firstDay>' . htmlspecialchars($data['firstDay'], ENT_COMPAT, 'UTF-8') . '</firstDay>' . "\n"; $text .= "\t" . '</metadata>' . "\n"; $text .= "\t" . '<params />' . "\n"; $text .= '</metafile>' . "\n"; // Set FTP credentials, if given. JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); // Try to make the file writeable. if ($exists && !$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, '0644')) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_WRITABLE', $path)); return false; } $return = JFile::write($path, $text); // Get the Localise parameters $params = JComponentHelper::getParams('com_localise'); // Get the file save permission $fileSavePermission = $params->get('filesavepermission', '0444'); // Try to make the template file unwriteable. if (!$ftp['enabled'] && JPath::isOwner($path) && !JPath::setPermissions($path, $fileSavePermission)) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_UNWRITABLE', $path)); return false; } else { if (!$return) { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_FILESAVE', $path)); return false; } } $id = LocaliseHelper::getFileId($path); $this->setState('language.id', $id); // Bind the rules. $table = $this->getTable(); $table->load($id); if (isset($data['rules'])) { $rules = new JAccessRules($data['rules']); $table->setRules($rules); } // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } return true; } else { $this->setError(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_FILERESET', $path)); return false; } }