示例#1
0
 /**
  * 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;
 }
示例#2
0
 private function _scanReference()
 {
     $reftag = $this->getState('translations.reference');
     $filter_tag = $this->getState('filter.tag') ? "^({$reftag}|" . $this->getState('filter.tag') . ")\$" : '.';
     $filter_search = $this->getState('filter.search') ? $this->getState('filter.search') : '.';
     $filter_storage = $this->getState('filter.storage');
     $filter_origin = $this->getState('filter.origin');
     $filter_client = $this->getState('filter.client');
     if (empty($filter_client)) {
         $clients = array('site', 'administrator', 'installation');
     } else {
         $clients = array($filter_client);
     }
     foreach ($clients as $client) {
         $client_folder = constant('LOCALISEPATH_' . strtoupper($client)) . '/language';
         if (JFolder::exists($client_folder)) {
             // Scan joomla files
             $tags = JFolder::folders($client_folder, $filter_tag, false, false, array('overrides', '.svn', 'CVS', '.DS_Store', '__MACOSX'));
             foreach ($tags as $tag) {
                 if (array_key_exists("{$client}|{$reftag}|joomla", $this->translations)) {
                     $reftranslation = $this->translations["{$client}|{$reftag}|joomla"];
                     if (array_key_exists("{$client}|{$tag}|joomla", $this->translations)) {
                         $this->translations["{$client}|{$tag}|joomla"]->setProperties(array('refpath' => $reftranslation->path, 'state' => 'inlanguage'));
                     } elseif ($filter_storage != 'local') {
                         $origin = LocaliseHelper::getOrigin("", $client);
                         if ($filter_origin == $origin) {
                             $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/{$tag}/{$tag}.ini";
                             $translation = new JObject(array('type' => 'joomla', 'tag' => $tag, 'client' => $client, 'storage' => 'global', 'filename' => 'joomla', 'name' => JText::_('COM_LOCALISE_TEXT_TRANSLATIONS_JOOMLA'), 'refpath' => $reftranslation->path, 'path' => $path, 'state' => 'unexisting', 'writable' => LocaliseHelper::isWritable($path), 'origin' => $origin));
                             $this->translations["{$client}|{$tag}|joomla"] = $translation;
                         }
                     }
                 }
             }
             $files = JFolder::files("{$client_folder}/{$reftag}", "\\.ini\$");
             if ($files) {
                 foreach ($files as $file) {
                     if (preg_match("/^{$reftag}\\.(lib.*)\\.ini\$/", $file, $matches)) {
                         $name = $matches[1];
                         $origin = LocaliseHelper::getOrigin($name, $client);
                         foreach ($tags as $tag) {
                             if (array_key_exists("{$client}|{$reftag}|{$name}", $this->translations)) {
                                 $reftranslation = $this->translations["{$client}|{$reftag}|{$name}"];
                                 if (array_key_exists("{$client}|{$tag}|{$name}", $this->translations)) {
                                     $this->translations["{$client}|{$tag}|{$name}"]->setProperties(array('refpath' => $reftranslation->path, 'state' => 'inlanguage'));
                                 } else {
                                     $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/{$tag}/{$tag}.{$name}.ini";
                                     $translation = new JObject(array('type' => 'library', 'tag' => $tag, 'client' => $client, 'storage' => 'global', 'filename' => $name, 'name' => $name, 'refpath' => $reftranslation->path, 'path' => $path, 'state' => 'unexisting', 'writable' => LocaliseHelper::isWritable($path), 'origin' => '_thirdparty'));
                                     $this->translations["{$client}|{$tag}|{$name}"] = $translation;
                                 }
                             }
                         }
                     } elseif (preg_match("/^{$reftag}\\.(pkg.*)\\.ini\$/", $file, $matches)) {
                         $name = $matches[1];
                         $origin = LocaliseHelper::getOrigin($name, $client);
                         foreach ($tags as $tag) {
                             if (array_key_exists("{$client}|{$reftag}|{$name}", $this->translations)) {
                                 $reftranslation = $this->translations["{$client}|{$reftag}|{$name}"];
                                 if (array_key_exists("{$client}|{$tag}|{$name}", $this->translations)) {
                                     $this->translations["{$client}|{$tag}|{$name}"]->setProperties(array('refpath' => $reftranslation->path, 'state' => 'inlanguage'));
                                 } else {
                                     $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/{$tag}/{$tag}.{$name}.ini";
                                     $translation = new JObject(array('type' => 'package', 'tag' => $tag, 'client' => $client, 'storage' => 'global', 'filename' => $name, 'name' => $name, 'refpath' => $reftranslation->path, 'path' => $path, 'state' => 'unexisting', 'writable' => LocaliseHelper::isWritable($path), 'origin' => '_thirdparty'));
                                     $this->translations["{$client}|{$tag}|{$name}"] = $translation;
                                 }
                             }
                         }
                     } elseif (preg_match("/^{$reftag}\\.(fil.*)\\.ini\$/", $file, $matches)) {
                         $name = $matches[1];
                         $origin = LocaliseHelper::getOrigin($name, $client);
                         foreach ($tags as $tag) {
                             if (array_key_exists("{$client}|{$reftag}|{$name}", $this->translations)) {
                                 $reftranslation = $this->translations["{$client}|{$reftag}|{$name}"];
                                 if (array_key_exists("{$client}|{$tag}|{$name}", $this->translations)) {
                                     $this->translations["{$client}|{$tag}|{$name}"]->setProperties(array('refpath' => $reftranslation->path, 'state' => 'inlanguage'));
                                 } else {
                                     $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/{$tag}/{$tag}.{$name}.ini";
                                     $translation = new JObject(array('type' => 'file', 'tag' => $tag, 'client' => $client, 'storage' => 'global', 'filename' => $name, 'name' => $name, 'refpath' => $reftranslation->path, 'path' => $path, 'state' => 'unexisting', 'writable' => LocaliseHelper::isWritable($path), 'origin' => '_thirdparty'));
                                     $this->translations["{$client}|{$tag}|{$name}"] = $translation;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // Scan extension files
     $scans = LocaliseHelper::getScans($this->getState('filter.client'), $this->getState('filter.type'));
     foreach ($scans as $scan) {
         $prefix = $scan['prefix'];
         $suffix = $scan['suffix'];
         $type = $scan['type'];
         $client = $scan['client'];
         $path = $scan['path'];
         $folder = $scan['folder'];
         $extensions = JFolder::folders($path, $filter_search);
         foreach ($extensions as $extension) {
             if (array_key_exists("{$client}|{$reftag}|{$prefix}{$extension}{$suffix}", $this->translations)) {
                 $reftranslation = $this->translations["{$client}|{$reftag}|{$prefix}{$extension}{$suffix}"];
                 $tags = JFolder::folders(constant('LOCALISEPATH_' . strtoupper($client)) . '/language', $filter_tag, false, false, array('overrides', '.svn', 'CVS', '.DS_Store', '__MACOSX'));
                 foreach ($tags as $tag) {
                     $origin = LocaliseHelper::getOrigin("{$prefix}{$extension}{$suffix}", $client);
                     if (array_key_exists("{$client}|{$tag}|{$prefix}{$extension}{$suffix}", $this->translations)) {
                         $this->translations["{$client}|{$tag}|{$prefix}{$extension}{$suffix}"]->setProperties(array('refpath' => $reftranslation->path, 'state' => 'inlanguage'));
                     } elseif ($filter_storage != 'local' && ($filter_origin == '' || $filter_origin == $origin)) {
                         $path = constant('LOCALISEPATH_' . strtoupper($client)) . "/language/{$tag}/{$tag}.{$prefix}{$extension}{$suffix}.ini";
                         $translation = new JObject(array('type' => $type, 'tag' => $tag, 'client' => $client, 'storage' => 'global', 'filename' => "{$prefix}{$extension}{$suffix}", 'name' => "{$prefix}{$extension}{$suffix}", 'refpath' => $reftranslation->path, 'path' => $path, 'state' => 'unexisting', 'writable' => LocaliseHelper::isWritable($path), 'origin' => $origin));
                         $this->translations["{$client}|{$tag}|{$prefix}{$extension}{$suffix}"] = $translation;
                     }
                 }
             }
         }
     }
 }
示例#3
0
 /**
  * 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;
 }