function universalfetchElement($name, $value, &$node) { $attrs = $node->attributes(); $this->loadFiles(); $listnode = new JSimpleXMLElement('list'); $datas = array(); $listnode->addChild('option', array('value' => 'custom'))->setData(ucfirst('Custom')); foreach ($node->children() as $default) { if (!isset($this->_parent->theme)) { $this->_parent->theme = "default"; } $listnode->addChild('option', array('value' => $this->_parent->theme . '_' . $default->name()))->setData(ucfirst($default->name())); $datas[$this->_parent->theme . '_' . $default->name()] = array(); foreach ($default->_children as $c) { $datas[$this->_parent->theme . '_' . $default->name()][$c->name()] = $c->data(); } } preg_match('/(.*)\\[([a-zA-Z0-9]*)\\]$/', $name, $out); $control = $out[1]; $orig_name = $out[2]; $value = 'custom'; $html = parent::universalfetchElement($name, $value, $listnode); DojoLoader::addScript("\n window." . $orig_name . " = new OfflajnSkin({\n name: " . json_encode($orig_name) . ",\n id: " . json_encode($this->id) . ",\n data: " . json_encode($datas) . ",\n control: " . json_encode($control) . ",\n dependency: '" . (isset($attrs['dependency']) ? $attrs['dependency'] : "") . "'\n });\n "); return $html; }
function display($tpl = null) { // Get data from the model require_once JPATH_COMPONENT . '/models/ajaxvote.php'; $model = new MijopollsModelAjaxvote(); $vote = $model->getVoted(); $data = $model->getData(); $total = $model->getTotal(); $poll_id = JRequest::getInt('id', 0, 'post'); if (MijopollsHelper::is15()) { // create root node $xml = new JSimpleXMLElement('poll', array('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', array('id' => $data[$i]->id, 'percentage' => self::_toPercent($data[$i]->votes, $sum), 'votes' => $data[$i]->votes, 'color' => $data[$i]->color)); $text = $option->addChild('text'); $text->setData($data[$i]->text); $number_voters += $data[$i]->votes; } $voters = $xml->addChild('voters'); $voters->setData($number_voters); $this->assign('xml', $xml->toString()); } else { // 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); }
/** * Test Add/Remove Children * * @param string Name of child node to add and check * @param array Key=>Value array of attributes for child node. * * @return void * @dataProvider casesChildren */ function testAddAndRemoveChildren($name, $options) { $this->assertThat($this->object->children(), $this->equalTo(array())); $child = $this->object->addChild($name, $options); $this->assertThat($child, $this->isInstanceOf('JSimpleXMLElement')); $this->assertThat($child->attributes(), $this->equalTo($options)); $this->object->removeChild($child); $this->assertThat($this->object->children(), $this->equalTo(array())); }
function createXML($params) { // Create Element - <cu3er> $node = new JSimpleXMLElement('cu3er'); // Create Element - <cu3er>.<settings> $nodeL1 =& $node->addChild('settings'); // Create Element - <cu3er>.<settings>.<general> $nodeL2 =& modVinaoraCu3erHelper::createGeneral($nodeL1, $params); // Create Element - <cu3er>.<settings>.<debug> if ($params->get('enable_debug')) { $nodeL2 =& modVinaoraCu3erHelper::createDebug($nodeL1, $params); } // Create Element - <cu3er>.<settings>.<auto_play> if ($params->get('enable_auto_play')) { $nodeL2 =& modVinaoraCu3erHelper::createAutoPlay($nodeL1, $params); } // Create Element - <cu3er>.<settings>.<pre_button> if ($params->get('enable_prev_button')) { $nodeL2 =& modVinaoraCu3erHelper::createPreviousButton($nodeL1, $params); } // Create Element - <cu3er>.<settings>.<pre_symbol> if ($params->get('enable_prev_symbol')) { $nodeL2 =& modVinaoraCu3erHelper::createPreviousSymbol($nodeL1, $params); } // Create Element - <cu3er>.<settings>.<next_button> if ($params->get('enable_next_button')) { $nodeL2 =& modVinaoraCu3erHelper::createNextButton($nodeL1, $params); } // Create Element - <cu3er>.<settings>.<next_symbol> if ($params->get('enable_next_symbol')) { $nodeL2 =& modVinaoraCu3erHelper::createNextSymbol($nodeL1, $params); } // Create Element - <cu3er>.<settings>.<preloader> if ($params->get('enable_preloader')) { $nodeL2 =& modVinaoraCu3erHelper::createPreloader($nodeL1, $params); } // Create Element - <cu3er>.<settings>.<description> if ($params->get('enable_description_box')) { $nodeL2 =& modVinaoraCu3erHelper::createDescriptionBox($nodeL1, $params); } // Create Element - <cu3er>.<settings>.<transitions> if ($params->get('transition_type') == 'first') { $nodeL2 =& modVinaoraCu3erHelper::createTransitions($nodeL1, $params); } // Create Element - <cu3er>.<slides> $nodeL2 =& modVinaoraCu3erHelper::createSlides($node, $params); $string = '<?xml version="1.0" encoding="utf-8"?>'; $string .= $node->toString(true); modVinaoraCu3erHelper::replaceTweenName($string); return $string; }
/** * Compiles information to add or edit a module * @param string The current GET/POST option * @param integer The unique id of the record to edit */ function edit() { // Initialize some variables $db =& JFactory::getDBO(); $user =& JFactory::getUser(); $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); $module = JRequest::getVar('module', '', '', 'cmd'); $id = JRequest::getVar('id', 0, 'method', 'int'); $cid = JRequest::getVar('cid', array($id), 'method', 'array'); JArrayHelper::toInteger($cid, array(0)); $model =& $this->getModel('module'); $model->setState('id', $cid['0']); $model->setState('clientId', $client->id); $lists = array(); $row =& JTable::getInstance('module'); // load the row from the db table $row->load((int) $cid['0']); // fail if checked out not by 'me' if ($row->isCheckedOut($user->get('id'))) { $this->setRedirect('index.php?option=com_advancedmodules&client=' . $client->id); return JError::raiseWarning(500, JText::sprintf('DESCBEINGEDITTED', JText::_('The module'), $row->title)); } $row->content = htmlspecialchars($row->content, ENT_COMPAT, 'UTF-8'); if ($cid['0']) { $row->checkout($user->get('id')); } // if a new record we must still prime the JTableModel object with a default // position and the order; also add an extra item to the order list to // place the 'new' record in last position if desired if ($cid['0'] == 0) { $row->position = 'left'; $row->showtitle = true; $row->published = 1; //$row->ordering = $l; $row->module = $module; } if ($client->id == 1) { $where = 'client_id = 1'; $lists['client_id'] = 1; $path = 'mod1_xml'; } else { $where = 'client_id = 0'; $lists['client_id'] = 0; $path = 'mod0_xml'; } $query = 'SELECT position, ordering, showtitle, title' . ' FROM #__modules' . ' WHERE ' . $where . ' ORDER BY ordering'; $db->setQuery($query); $orders = $db->loadObjectList(); if ($db->getErrorNum()) { echo $db->stderr(); return false; } $orders2 = array(); $l = 0; $r = 0; for ($i = 0, $n = count($orders); $i < $n; $i++) { $ord = 0; if (array_key_exists($orders[$i]->position, $orders2)) { $ord = count(array_keys($orders2[$orders[$i]->position])) + 1; } $orders2[$orders[$i]->position][] = JHTML::_('select.option', $ord, $ord . '::' . htmlspecialchars($orders[$i]->title)); } $color = 'FFFFFF'; if ($client->id != 1) { $parameters =& NNParameters::getParameters(); $config = JComponentHelper::getParams('com_advancedmodules'); $config = $parameters->getParams($config->_raw, JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_advancedmodules' . DS . 'config.xml'); $advanced_params = new stdClass(); $xmlfile = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_advancedmodules' . DS . 'assignments.xml'; if (!$cid['0']) { $lists['assignments'] = new JParameter('', $xmlfile); // hide if empty $lists['hideempty'] = JHTML::_('select.booleanlist', 'advancedparams[hideempty]', 'class="inputbox"', 0, 'yes', 'no', 'advancedparamshideempty'); // tooltip $lists['tooltip'] = '<textarea class="text_area" rows="3" cols="40" name="advancedparams[tooltip]" id="advancedparamstooltip"></textarea>'; } else { // advanced params $query = 'SELECT params' . ' FROM #__advancedmodules' . ' WHERE moduleid = ' . (int) $row->id; $db->setQuery($query); $advanced_params = $db->loadResult(); if (!$advanced_params || strpos($advanced_params, 'assignto_') === false) { $advanced_params = $this->updateParams($row->id, $advanced_params); } $lists['assignments'] = new JParameter($advanced_params, $xmlfile); $advanced_params = $parameters->getParams($advanced_params); // hide if empty $lists['hideempty'] = JHTML::_('select.booleanlist', 'advancedparams[hideempty]', 'class="inputbox"', isset($advanced_params->hideempty) ? $advanced_params->hideempty : 0, 'yes', 'no', 'advancedparamshideempty'); // tooltip $lists['tooltip'] = '<textarea class="text_area" rows="3" cols="40" name="advancedparams[tooltip]" id="advancedparamstooltip">' . (isset($advanced_params->tooltip) ? $advanced_params->tooltip : '') . '</textarea>'; if (isset($advanced_params->color)) { $color = strtoupper(preg_replace('#[^a-z0-9]#si', '', $advanced_params->color)); } } require_once JPATH_SITE . DS . 'plugins' . DS . 'system' . DS . 'nonumberelements' . DS . 'elements' . DS . 'colorpicker.php'; $cp = new JElementColorPicker(); $node = new JSimpleXMLElement(''); $lists['color'] = $cp->fetchElement('color', $color, $node, 'advancedparams'); $lists['extra'] = ''; if ($config->show_extra) { if ($config->extra1) { $xml = new JSimpleXMLElement('extra', array()); $extraparams = array(); for ($i = 1; $i <= 5; $i++) { $var = 'extra' . $i; if ($config->{$var}) { $a = array(); $a['name'] = $var; $a['type'] = 'text'; $label = explode('\\|', $config->{$var}, 2); $a['label'] = $label['0']; if (isset($label['1'])) { $a['description'] = $label['1']; } $xml->addChild('extra1', $a); } if (isset($advanced_params->{$var})) { $extraparams[] = $var . '=' . $advanced_params->{$var}; } } $p = new JParameter(implode("\n", $extraparams)); $p->setXML($xml); if ($p->getNumParams()) { $lists['extra'] = $p->render('advancedparams'); } } } } if ($row->access == 99 || $row->client_id == 1 || $lists['client_id']) { $lists['access'] = 'Administrator'; $lists['showtitle'] = 'N/A <input type="hidden" name="showtitle" value="1" />'; $lists['selections'] = 'N/A'; } else { if ($client->id == '1') { $lists['access'] = 'N/A'; } else { $lists['access'] = JHTML::_('list.accesslevel', $row); } $lists['showtitle'] = JHTML::_('select.booleanlist', 'showtitle', 'class="inputbox"', $row->showtitle); } // build the html select list for published $lists['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $row->published); $row->description = ''; $lang =& JFactory::getLanguage(); if ($client->id != '1') { $lang->load(trim($row->module), JPATH_SITE); } else { $lang->load(trim($row->module)); } // xml file for module if ($row->module == 'custom') { $xmlfile = JApplicationHelper::getPath($path, 'mod_custom'); } else { $xmlfile = JApplicationHelper::getPath($path, $row->module); } $data = JApplicationHelper::parseXMLInstallFile($xmlfile); if ($data) { foreach ($data as $key => $value) { $row->{$key} = $value; } } // get params definitions $params = new JParameter($row->params, $xmlfile, 'module'); require_once JApplicationHelper::getPath('admin_html'); HTML_modules::edit($model, $row, $orders2, $lists, $params, $client); }
/** * Prepare an xml file content holding * a standard record for returning result * of an ajax request * * @param JView $view the view handling the request */ public static function prepareAjaxResponse($view) { // use Joomla wml object jimport('joomla.utilities.simplexml'); // create a root node $xml = new JSimpleXMLElement('item', array('id' => 'shajax-response')); // add children : status, message, message code, task $status =& $xml->addChild('status'); $message =& $xml->addChild('message'); $messagecode =& $xml->addChild('messagecode'); $taskexecuted =& $xml->addChild('taskexecuted'); // set default values $status->setData('_'); $message->setData('_'); $messagecode->setData('_'); $taskexecuted->setData('_'); // set their respective values $vErrors = $view->getErrors(); if (empty($vErrors)) { // retrieve messagecode and task if (empty($view->messagecode)) { $view->assign('messagecode', 'COM_SH404SEF_OPERATION_COMPLETED'); } if (empty($view->taskexecuted)) { $view->assign('taskexecuted', ''); } // either a success or a redirect if (empty($view->redirectTo)) { // no error $status->setData('success'); $msg = empty($view->message) ? JText16::_('COM_SH404SEF_OPERATION_COMPLETED') : $view->message; $message->setData('<ul>' . $msg . '</ul>'); $messagecode->setData($view->messagecode); } else { $status->setData('redirect'); $glue = strpos($view->redirectTo, '?') === false ? '?' : '&'; $message->setData($view->redirectTo . $glue . 'sh404sefMsg=' . $view->messagecode); } $taskexecuted->setData($view->taskexecuted); } else { $status->setData('failure'); $messageTxt = ''; foreach ($vErrors as $error) { $messageTxt .= '<li>' . $error . '</li>'; } $message->setData('<ul>' . $messageTxt . '</ul>'); } // output resulting text, no need for a layout file I think $output = '<?xml version="1.0" encoding="UTF-8" ?>' . "\n"; $output .= $xml->toString(); return $output; }