Пример #1
0
 function display($tpl = null)
 {
     // Get data from the model
     require_once JPATH_COMPONENT . '/models/ajaxvote.php';
     $model = new AcepollsModelAjaxvote();
     $vote = $model->getVoted();
     $data = $model->getData();
     $total = $model->getTotal();
     $poll_id = JRequest::getInt('id', 0, 'post');
     // create root node
     $xml = new JXMLElement('<poll></poll>');
     $xml->addAttribute('id', $poll_id);
     //get total votes
     $sum = 0;
     foreach ($data as $row) {
         $sum += $row->votes;
     }
     $number_voters = 0;
     $options =& $xml->addChild('options');
     for ($i = 0; $i < $total; $i++) {
         $option =& $options->addChild('option');
         $option->addAttribute('id', $data[$i]->id);
         $option->addAttribute('percentage', self::_toPercent($data[$i]->votes, $sum));
         $option->addAttribute('color', $data[$i]->color);
         $option->addChild('text', $data[$i]->text);
         $number_voters += $data[$i]->votes;
     }
     $xml->addChild('voters', $number_voters);
     $this->assign('xml', $xml->asFormattedXML());
     $this->setLayout('raw');
     parent::display($tpl);
 }
Пример #2
0
 public function getField($type, $attributes = array(), $field_value = '')
 {
     static $types = null;
     $defaults = array('name' => '', 'id' => '');
     if (!$types) {
         jimport('joomla.form.helper');
         $types = array();
     }
     if (!in_array($type, $types)) {
         JFormHelper::loadFieldClass($type);
     }
     try {
         $attributes = array_merge($defaults, $attributes);
         $xml = new JXMLElement('<?xml version="1.0" encoding="utf-8"?><field />');
         foreach ($attributes as $key => $value) {
             if ('_options' == $key) {
                 foreach ($value as $_opt_value) {
                     $xml->addChild('option', $_opt_value->text)->addAttribute('value', $_opt_value->value);
                 }
                 continue;
             }
             $xml->addAttribute($key, $value);
         }
         $class = 'JFormField' . $type;
         $field = new $class();
         $field->setup($xml, $field_value);
         return $field;
     } catch (Exception $e) {
         return false;
     }
 }
Пример #3
0
 /**
  * @param	object	$form	A form object.
  * @param	mixed	$data	The data expected for the form.
  *
  * @return	void
  * @since	1.6
  * @throws	Exception if there is an error in the form event.
  */
 protected function preprocessForm(JForm $form, $data, $group = 'content')
 {
     // Initialise variables.
     $link = $this->getState('item.link');
     $type = $this->getState('item.type');
     $formFile = false;
     // Initialise form with component view params if available.
     if ($type == 'component') {
         $link = htmlspecialchars_decode($link);
         // Parse the link arguments.
         $args = array();
         parse_str(parse_url(htmlspecialchars_decode($link), PHP_URL_QUERY), $args);
         // Confirm that the option is defined.
         $option = '';
         $base = '';
         if (isset($args['option'])) {
             // The option determines the base path to work with.
             $option = $args['option'];
             $base = JPATH_SITE . '/components/' . $option;
         }
         // Confirm a view is defined.
         $formFile = false;
         if (isset($args['view'])) {
             $view = $args['view'];
             // Determine the layout to search for.
             if (isset($args['layout'])) {
                 $layout = $args['layout'];
             } else {
                 $layout = 'default';
             }
             $formFile = false;
             // Check for the layout XML file. Use standard xml file if it exists.
             $path = JPath::clean($base . '/views/' . $view . '/tmpl/' . $layout . '.xml');
             if (JFile::exists($path)) {
                 $formFile = $path;
             }
             // if custom layout, get the xml file from the template folder
             // template folder is first part of file name -- template:folder
             if (!$formFile && strpos($layout, ':') > 0) {
                 $temp = explode(':', $layout);
                 $templatePath = JPATH::clean(JPATH_SITE . '/templates/' . $temp[0] . '/html/' . $option . '/' . $view . '/' . $temp[1] . '.xml');
                 if (JFile::exists($templatePath)) {
                     $formFile = $templatePath;
                 }
             }
         }
         //Now check for a view manifest file
         if (!$formFile) {
             if (isset($view) && JFile::exists($path = JPath::clean($base . '/views/' . $view . '/metadata.xml'))) {
                 $formFile = $path;
             } else {
                 //Now check for a component manifest file
                 $path = JPath::clean($base . '/metadata.xml');
                 if (JFile::exists($path)) {
                     $formFile = $path;
                 }
             }
         }
     }
     if ($formFile) {
         // If an XML file was found in the component, load it first.
         // We need to qualify the full path to avoid collisions with component file names.
         if ($form->loadFile($formFile, true, '/metadata') == false) {
             throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
         }
         // Attempt to load the xml file.
         if (!($xml = simplexml_load_file($formFile))) {
             throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
         }
         // Get the help data from the XML file if present.
         $help = $xml->xpath('/metadata/layout/help');
         if (!empty($help)) {
             $helpKey = trim((string) $help[0]['key']);
             $helpURL = trim((string) $help[0]['url']);
             $helpLoc = trim((string) $help[0]['local']);
             $this->helpKey = $helpKey ? $helpKey : $this->helpKey;
             $this->helpURL = $helpURL ? $helpURL : $this->helpURL;
             $this->helpLocal = $helpLoc == 'true' || $helpLoc == '1' || $helpLoc == 'local' ? true : false;
         }
     }
     // Now load the component params.
     // TODO: Work out why 'fixing' this breaks JForm
     if ($isNew = false) {
         $path = JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $option . '/config.xml');
     } else {
         $path = 'null';
     }
     if (JFile::exists($path)) {
         // Add the component params last of all to the existing form.
         if (!$form->load($path, true, '/config')) {
             throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
         }
     }
     // Load the specific type file
     if (!$form->loadFile('item_' . $type, false, false)) {
         throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
     }
     // Association menu items
     if (JFactory::getApplication()->get('menu_associations', 0)) {
         $languages = JLanguageHelper::getLanguages('lang_code');
         $addform = new JXMLElement('<form />');
         $fields = $addform->addChild('fields');
         $fields->addAttribute('name', 'associations');
         $fieldset = $fields->addChild('fieldset');
         $fieldset->addAttribute('name', 'item_associations');
         $fieldset->addAttribute('description', 'COM_MENUS_ITEM_ASSOCIATIONS_FIELDSET_DESC');
         $add = false;
         foreach ($languages as $tag => $language) {
             if ($tag != $data['language']) {
                 $add = true;
                 $field = $fieldset->addChild('field');
                 $field->addAttribute('name', $tag);
                 $field->addAttribute('type', 'menuitem');
                 $field->addAttribute('language', $tag);
                 $field->addAttribute('label', $language->title);
                 $field->addAttribute('translate_label', 'false');
                 $option = $field->addChild('option', 'COM_MENUS_ITEM_FIELD_ASSOCIATION_NO_VALUE');
                 $option->addAttribute('value', '');
             }
         }
         if ($add) {
             $form->load($addform, false);
         }
     }
     // Trigger the default form events.
     parent::preprocessForm($form, $data);
 }
 /**
  * Method to get the field input markup.
  *
  * @return  string  The field input markup.
  * @since   11.1
  */
 protected function getInput()
 {
     // Initialize variables.
     $html = array();
     // Initialize some field attributes.
     $class = $this->element['class'] ? ' class="checkboxes ' . (string) $this->element['class'] . '"' : ' class="checkboxes"';
     // get extensions installed
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('element AS value, name AS text, params');
     $query->from('#__extensions AS a');
     $query->where('type = "component" AND protected = 0 AND enabled = 1');
     $query->order('a.name');
     // Get the options.
     $db->setQuery($query);
     $options = $db->loadObjectList();
     // get plan params
     $id = JRequest::getVar('id');
     $query = $db->getQuery(true);
     $query->select('*');
     $query->from('#__jms_plans');
     $query->where('id = ' . (int) $id);
     // Get param values.
     $db->setQuery($query);
     $row = $db->loadObject();
     $params = new JRegistry();
     if (isset($row->params)) {
         $params->loadString($row->params);
     }
     // Start the checkbox field output.
     $html[] = '<fieldset id="' . $this->id . '"' . $class . '>';
     // Build the checkbox field output.
     $html[] = '<div>';
     // make 2 columns for the div
     $extensions = $options;
     $cols = 2;
     $count = count($extensions);
     if ($count % $cols > 0) {
         for ($e = 0; $e < $cols - $count % $cols; $e++) {
             $extensions[] = '&nbsp;';
         }
     }
     //print_r($count);
     $addform = new JXMLElement('<form />');
     $fields = $addform->addChild('fields');
     $fields->addAttribute('name', 'params');
     $fieldset = $fields->addChild('fieldset');
     $fieldset->addAttribute('name', 'item_associations');
     $fieldset->addAttribute('description', 'COM_MENUS_ITEM_ASSOCIATIONS_FIELDSET_DESC');
     foreach ($options as $i => $option) {
         // Initialize some option attributes.
         $checked = in_array((string) $option->value, (array) $this->value) ? ' checked="checked"' : '';
         $class = !empty($option->class) ? ' class="' . $option->class . '"' : '';
         $disabled = !empty($option->disable) ? ' disabled="disabled"' : '';
         // Initialize some JavaScript option attributes.
         // onclick="jmsShowComParams('component_name', 'component_name[]')
         if ($i % $cols == 0) {
             $html[] = '<div class="jmsblock">';
         }
         $html[] = '<div class="col-' . ($i % $cols + 1) . '">';
         $onclick = " onclick=\"jmsShowComParams('" . $option->value . "', '" . $option->value . "');\"";
         $html[] = '<div class="label-pad">';
         $html[] = '<input type="checkbox" id="check_' . $option->value . '" name="' . $this->name . '"' . ' value="' . htmlspecialchars($option->value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $class . $onclick . $disabled . '/>';
         $html[] = '<label for="' . $this->id . $i . '"' . $class . '>' . JText::_($option->text) . '</label>';
         $html[] = '<div class="clr"></div>';
         $html[] = '</div>';
         if (!in_array($option->value, $options) && !$checked) {
             $html[] = '<div id="params_' . $option->value . '" class="jmsblockhide">';
         } else {
             $html[] = '<div id="params_' . $option->value . '" class="jmsblockshow">';
         }
         $html[] = '<div class="jmsblockshow-pad">';
         $html[] = '<table class="admintable" cellpadding="0" cellspacing="0">';
         $html[] = '<tr>';
         $html[] = '<td class="key" align="right" width="100">';
         $html[] = JText::_('URL Variable 1:');
         $html[] = '</td>';
         $html[] = '<td>';
         $html[] = '<input class="inputbox" type="text" name="task_' . $option->value . '1" value="' . $params->get($option->value . '_task1') . '" size="30" />';
         $html[] = '</td>';
         $html[] = '</tr>';
         $html[] = '<tr>';
         $html[] = '<td class="key" nowrap="" align="right" width="100">';
         $html[] = JText::_('Variable Value 1:');
         $html[] = '</td>';
         $html[] = '<td>';
         $html[] = '<input class="inputbox" type="text" name="value_' . $option->value . '1" value="' . $params->get($option->value . '_value1') . '" size="30" />';
         $html[] = '</td>';
         $html[] = '</tr>';
         $html[] = '</table>';
         $html[] = '<strong>AND</strong>';
         $html[] = '<table class="admintable" cellpadding="0" cellspacing="0">';
         $html[] = '<tr>';
         $html[] = '<td class="key" align="right" width="100">';
         $html[] = JText::_('URL Variable 2:');
         $html[] = '</td>';
         $html[] = '<td>';
         $html[] = '<input class="inputbox" type="text" name="task_' . $option->value . '2" value="' . $params->get($option->value . '_task2') . '" size="30" />';
         $html[] = '</td>';
         $html[] = '</tr>';
         $html[] = '<tr>';
         $html[] = '<td class="key" nowrap="" align="right" width="100">';
         $html[] = JText::_('Variable Value 2:');
         $html[] = '</td>';
         $html[] = '<td>';
         $html[] = '<input class="inputbox" type="text" name="value_' . $option->value . '2" value="' . $params->get($option->value . '_value2') . '" size="30" />';
         $html[] = '</td>';
         $html[] = '</tr>';
         $html[] = '</table>';
         $html[] = '</div>';
         $html[] = '<strong>OR</strong>';
         $html[] = '<div class="jmsblockshow-pad">';
         $html[] = '<table class="admintable" cellpadding="0" cellspacing="0">';
         $html[] = '<tr>';
         $html[] = '<td class="key" align="right" width="100">';
         $html[] = JText::_('URL Variable 1:');
         $html[] = '</td>';
         $html[] = '<td>';
         $html[] = '<input class="inputbox" type="text" name="task_' . $option->value . '3" value="' . $params->get($option->value . '_task3') . '" size="30" />';
         $html[] = '</td>';
         $html[] = '</tr>';
         $html[] = '<tr>';
         $html[] = '<td class="key" nowrap="" align="right" width="100">';
         $html[] = JText::_('Variable Value 1:');
         $html[] = '</td>';
         $html[] = '<td>';
         $html[] = '<input class="inputbox" type="text" name="value_' . $option->value . '3" value="' . $params->get($option->value . '_value3') . '" size="30" />';
         $html[] = '</td>';
         $html[] = '</tr>';
         $html[] = '</table>';
         $html[] = '<strong>AND</strong>';
         $html[] = '<table class="admintable" cellpadding="0" cellspacing="0">';
         $html[] = '<tr>';
         $html[] = '<td class="key" align="right" width="100">';
         $html[] = JText::_('URL Variable 2:');
         $html[] = '</td>';
         $html[] = '<td>';
         $html[] = '<input class="inputbox" type="text" name="task_' . $option->value . '4" value="' . $params->get($option->value . '_task4') . '" size="30" />';
         $html[] = '</td>';
         $html[] = '</tr>';
         $html[] = '<tr>';
         $html[] = '<td class="key" nowrap="" align="right" width="100">';
         $html[] = JText::_('Variable Value 2:');
         $html[] = '</td>';
         $html[] = '<td>';
         $html[] = '<input class="inputbox" type="text" name="value_' . $option->value . '4" value="' . $params->get($option->value . '_value4') . '" size="30" />';
         $html[] = '</td>';
         $html[] = '</tr>';
         $html[] = '</table>';
         $html[] = '</div><!-- pad -->';
         $html[] = '</div><!-- jmsblockhide-show -->';
         $html[] = '</div><!-- col div -->';
         if ($i % $cols == $cols - 1) {
             $html[] = '</div><!-- block div -->';
             $html[] = '<div class="clr"></div>';
         }
     }
     $html[] = '</div>';
     // End the checkbox field output.
     $html[] = '</fieldset>';
     return implode($html);
 }
Пример #5
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;
 }