/** * 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; }
/** * 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 /** * @package Joomla.Administrator * @subpackage com_localise * * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; $app = JFactory::getApplication('administrator'); $params = JComponentHelper::getParams('com_localise'); $reference = $params->get('reference', 'en-GB'); $packages = LocaliseHelper::getPackages(); $user = JFactory::getUser(); $lang = JFactory::getLanguage(); foreach ($this->items as $i => $item) { $canEdit = $user->authorise('localise.edit', 'com_localise' . (isset($item->id) ? '.' . $item->id : '')); ?> <tr class="<?php echo $item->state; ?> row<?php echo $i % 2; ?> "> <td width="20" class="center hidden-phone"><?php echo $i + 1; ?> </td> <td width="120" class="center hidden-phone">