Пример #1
1
 /**
  * Display the view.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise an Error object.
  */
 public function display($tpl = null)
 {
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->state = $this->get('State');
     $section = $this->state->get('category.section') ? $this->state->get('category.section') . '.' : '';
     $this->canDo = JHelperContent::getActions($this->state->get('category.component'), $section . 'category', $this->item->id);
     $this->assoc = $this->get('Assoc');
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     // Check for tag type
     $this->checkTags = JHelperTags::getTypes('objectList', array($this->state->get('category.extension') . '.category'), true);
     JFactory::getApplication()->input->set('hidemainmenu', true);
     if ($this->getLayout() == 'modal') {
         // If we are forcing a language in modal (used for associations).
         if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
             // Set the language field to the forcedLanguage and disable changing it.
             $this->form->setValue('language', null, $forcedLanguage);
             $this->form->setFieldAttribute('language', 'readonly', 'true');
             // Only allow to select categories with All language or with the forced language.
             $this->form->setFieldAttribute('parent_id', 'language', '*,' . $forcedLanguage);
             // Only allow to select tags with All language or with the forced language.
             $this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
         }
     } elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
         $this->form->setFieldAttribute('language', 'readonly', 'true');
     }
     $this->addToolbar();
     return parent::display($tpl);
 }
Пример #2
0
 /**
  * Display the view.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise an Error object.
  */
 public function display($tpl = null)
 {
     // Initialise variables.
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->state = $this->get('State');
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     if ($this->getLayout() == 'modal') {
         // If we are forcing a language in modal (used for associations).
         if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
             // Set the language field to the forcedLanguage and disable changing it.
             $this->form->setValue('language', null, $forcedLanguage);
             $this->form->setFieldAttribute('language', 'readonly', 'true');
             // Only allow to select categories with All language or with the forced language.
             $this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage);
             // Only allow to select tags with All language or with the forced language.
             $this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
         }
     } elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
         $this->form->setFieldAttribute('language', 'readonly', 'true');
     }
     $this->addToolbar();
     return parent::display($tpl);
 }
Пример #3
0
 /**
  * Display the view
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  void
  *
  * @since   1.6
  */
 public function display($tpl = null)
 {
     $user = JFactory::getUser();
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->modules = $this->get('Modules');
     $this->levels = $this->get('ViewLevels');
     $this->state = $this->get('State');
     $this->canDo = JHelperContent::getActions('com_menus', 'menu', (int) $this->state->get('item.menutypeid'));
     // Check if we're allowed to edit this item
     // No need to check for create, because then the moduletype select is empty
     if (!empty($this->item->id) && !$this->canDo->get('core.edit')) {
         throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 403);
     }
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     if ($this->getLayout() == 'modal') {
         // If we are forcing a language in modal (used for associations).
         if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
             // Set the language field to the forcedLanguage and disable changing it.
             $this->form->setValue('language', null, $forcedLanguage);
             $this->form->setFieldAttribute('language', 'readonly', 'true');
             // Only allow to select categories with All language or with the forced language.
             $this->form->setFieldAttribute('parent_id', 'language', '*,' . $forcedLanguage);
         }
     } elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
         $this->form->setFieldAttribute('language', 'readonly', 'true');
     }
     parent::display($tpl);
     $this->addToolbar();
 }
Пример #4
0
 /**
  * Method to test whether a record can be deleted.
  *
  * @param JForm $record a record object.
  * @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component.
  */
 protected function canEditState($record)
 {
     if (!empty($record)) {
         if ($record instanceof JForm) {
             return JoomDOCAccessDocument::editState($record->getValue('id'), $record->getValue('checked_out'), $record->getValue('path'));
         } else {
             return JoomDOCAccessDocument::editState($record->id, $record->checked_out, $record->path);
         }
     }
     return parent::canEditState($record);
 }
Пример #5
0
 /**
  * Display date form field. If field value equal database null date reset to empty string.
  *
  * @param string $field form field name
  * @return string field form html
  */
 public function date($field)
 {
     static $nullDate;
     if (empty($nullDate)) {
         $db = JFactory::getDbo();
         /* @var $db JDatabaseMySQL */
         $nullDate = $db->getNullDate();
     }
     if ($this->form->getValue($field) == $nullDate) {
         $this->form->setValue($field, null, '');
     }
     return $this->form->getInput($field);
 }
Пример #6
0
 /**
  * Execute and display a template script.
  *
  * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  *
  * @return  mixed  A string if successful, otherwise an Error object.
  *
  * @since   1.6
  */
 public function display($tpl = null)
 {
     if ($this->getLayout() == 'pagebreak') {
         // TODO: This is really dogy - should change this one day.
         $eName = JFactory::getApplication()->input->getCmd('e_name');
         $eName = preg_replace('#[^A-Z0-9\\-\\_\\[\\]]#i', '', $eName);
         $this->document->setTitle(JText::_('COM_CONTENT_PAGEBREAK_DOC_TITLE'));
         $this->eName =& $eName;
         return parent::display($tpl);
     }
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->state = $this->get('State');
     $this->canDo = JHelperContent::getActions('com_content', 'article', $this->item->id);
     // Check for errors.
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     if ($this->getLayout() == 'modal') {
         // If we are forcing a language in modal (used for associations).
         if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) {
             // Set the language field to the forcedLanguage and disable changing it.
             $this->form->setValue('language', null, $forcedLanguage);
             $this->form->setFieldAttribute('language', 'readonly', 'true');
             // Only allow to select categories with All language or with the forced language.
             $this->form->setFieldAttribute('catid', 'language', '*,' . $forcedLanguage);
             // Only allow to select tags with All language or with the forced language.
             $this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage);
         }
     } elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled() && count($this->item->associations) > 0) {
         $this->form->setFieldAttribute('language', 'readonly', 'true');
     }
     $this->addToolbar();
     return parent::display($tpl);
 }
Пример #7
0
 /**
  * Method to test the username for uniqueness.
  *
  * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  * @param   mixed             $value    The form field value to validate.
  * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  *                                      For example if the field has name="foo" and the group value is set to "bar" then the
  *                                      full field name would end up being "bar[foo]".
  * @param   JRegistry         $input    An optional JRegistry object with the entire data set to validate against the entire form.
  * @param   JForm             $form     The form object for which the field is being tested.
  *
  * @return  boolean  True if the value is valid, false otherwise.
  *
  * @since   11.1
  */
 public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
 {
     // Get the database object and a new query object.
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     // Build the query.
     $query->select('COUNT(*)')->from('#__users')->where('username = '******'id') : '';
     $query->where($db->quoteName('id') . ' <> ' . (int) $userId);
     // Set and query the database.
     $db->setQuery($query);
     $duplicate = (bool) $db->loadResult();
     if ($duplicate) {
         return false;
     }
     return true;
 }
Пример #8
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;
 }
Пример #9
0
 /**
  * Compare form data and session data.
  *
  * @param   object  $form   JForm object with populated input values.
  * @param   array   $data  An associative array of form values.
  *
  * @return  boolean 
  *
  * @since   2.5
  */
 private function _dataCompare(JForm $form, $data)
 {
     foreach ($data as $key => $value) {
         if ($form->getValue($key) != $value) {
             return false;
         }
     }
     return true;
 }