function universalFetchElement($name, $value, &$node) { $n = new JSimpleXML(); $n->loadString(method_exists($node, 'toString') ? $node->toString() : $node->asXML()); $params = new OfflajnJParameter(''); $params->setXML($n->document); $attr = $node->attributes(); if (!isset($attr['position']) || $attr['position'] != 'first') { $attr['position'] = 'last'; } if (!version_compare(JVERSION, '1.6.0', 'ge')) { // Joomla 1.5 < preg_match('/(.*)\\[([a-zA-Z0-9]*)\\]$/', $name, $out); $control = $out[1]; $name = $out[2]; $params->bind($this->_parent->_raw); $params->_raw =& $this->_parent->_raw; } else { // Joomla 1.7 > $control = $name; if ($value != '') { $params->bind($value); } } plgSystemOfflajnParams::addNewTab($this->generateId($name), parent::getLabel(), $params->render($control), (string) $attr['position']); return ''; }
/** * Testing loadString(). * * @param string The XML document structure. * @param boolean The expected return from the function. * @param array The error information array generated by the JError stub. * * @return void * @dataProvider casesLoadString */ public function testLoadString( $xml, $expected, $error ) { $this->assertThat( $this->object->loadString($xml), $this->equalTo($expected) ); $this->assertThat( JSimpleXMLTest::$actualError, $this->equalTo($error) ); }
function universalfetchElement($name, $value, &$node) { $this->_node =& $node; $this->_googlefonts = array(); $this->_google = array(); $this->_googleName = array(); $this->init(); $html = ""; $attrs = $node->attributes(); $alpha = isset($attrs['alpha']) ? $attrs['alpha'] : 0; $tabs = explode('|', $attrs['tabs']); $s = json_decode($value); if (isset($attrs['tabs']) && $attrs['tabs'] != "") { @($def = (array) $s->{$tabs[0]}); } $elements = array(); $stack =& JsStack::getInstance(); $stack->startStack(); // TABS $elements['tab']['name'] = $name . 'tab'; $elements['tab']['id'] = $this->generateId($elements['tab']['name']); $tabxml = new JSimpleXML(); $tabxml->loadString('<param/>'); $tabxml = $tabxml->document; $tabxml->addAttribute('name', $elements['tab']['name']); $tabxml->addAttribute('type', 'offlajnradio'); $tabxml->addAttribute('mode', 'button'); foreach ($tabs as $t) { $tabxml->addChild('option', array('value' => $t))->setData($t); } $tab = new JElementOfflajnRadio(); $tab->id = $elements['tab']['id']; $elements['tab']['html'] = $tab->universalfetchElement($elements['tab']['name'], $tabs[0], $tabxml); // END TABS // TYPE $elements['type']['name'] = $name . 'type'; $elements['type']['id'] = $this->generateId($elements['type']['name']); $typexml = new JSimpleXML(); $typexml->loadString('<param/>'); $typexml = $typexml->document; $typexml->addAttribute('name', $elements['type']['name']); $typexml->addAttribute('type', 'offlajnlist'); $typexml->addChild('option', array('value' => '0'))->setData('Alternative fonts'); foreach ($this->_google as $t) { $typexml->addChild('option', array('value' => $t))->setData($t); $stack->startStack(); // FAMILY $elements['type'][$t]['name'] = $name . 'family'; $elements['type'][$t]['id'] = $this->generateId($elements['type'][$t]['name']); $familyxml = new JSimpleXML(); $familyxml->loadString('<param/>'); $familyxml = $familyxml->document; $familyxml->addAttribute('name', $elements['type'][$t]['name']); $familyxml->addAttribute('type', 'offlajnlist'); $familyxml->addAttribute('height', '10'); $familyxml->addAttribute('fireshow', '1'); foreach ($this->_googlefonts[$t] as $f) { if (strlen($f) > 0) { $familyxml->addChild('option', array('value' => $f))->setData($f); } } $family = new JElementOfflajnList(); $family->id = $elements['type'][$t]['id']; $elements['type'][$t]['html'] = $family->universalfetchElement($elements['type'][$t]['name'], isset($def['family']) ? $def['family'] : 'Open Sans', $familyxml); $elements['type'][$t]['script'] = $stack->endStack(true); // print_r($elements['type'][$t]['script']); // print_r($elements['type'][$t]['html']);exit; // END FAMILY } $type = new JElementOfflajnList(); $type->id = $elements['type']['id']; $elements['type']['html'] = $type->universalfetchElement($elements['type']['name'], isset($def['type']) ? $def['type'] : '0', $typexml); // END TYPE // SIZE $elements['size']['name'] = $name . 'size'; $elements['size']['id'] = $this->generateId($elements['size']['name']); $sizexml = new JSimpleXML(); $sizexml->loadString('<param size="1" validation="int" mode="increment" scale="1" allowminus="0"><unit value="px" imsrc="">px</unit><unit value="em" imsrc="">em</unit></param>'); $sizexml = $sizexml->document; $sizexml->addAttribute('name', $elements['size']['name']); $sizexml->addAttribute('type', 'offlajntext'); $size = new JElementOfflajnText(); $size->id = $elements['size']['id']; $elements['size']['html'] = $size->universalfetchElement($elements['size']['name'], isset($def['size']) ? $def['size'] : '14||px', $sizexml); // END SIZE // COLOR $elements['color']['name'] = $name . 'color'; $elements['color']['id'] = $this->generateId($elements['color']['name']); $colorxml = new JSimpleXML(); $colorxml->loadString('<param/>'); $colorxml = $colorxml->document; $colorxml->addAttribute('name', $elements['color']['name']); $colorxml->addAttribute('type', 'offlajncolor'); //$colorxml->addAttribute('alpha', $alpha); $color = new JElementOfflajnColor(); $color->id = $elements['color']['id']; $elements['color']['html'] = $color->universalfetchElement($elements['color']['name'], isset($def['color']) ? $def['color'] : '000000', $colorxml); // END COLOR // TEXT-DECORATION // $stack->startStack(); $elements['textdecor']['name'] = $name . 'textdecor'; $elements['textdecor']['id'] = $this->generateId($elements['textdecor']['name']); $textdecorxml = new JSimpleXML(); $textdecorxml->loadString('<param/>'); $textdecorxml = $textdecorxml->document; $textdecorxml->addAttribute('name', $elements['textdecor']['name']); $textdecorxml->addAttribute('type', 'offlajnlist'); $textdecorxml->addAttribute('height', '4'); $textdecorxml->addAttribute('fireshow', '0'); $textdecorxml->addChild('option', array('value' => '200'))->setData('extralight'); $textdecorxml->addChild('option', array('value' => '300'))->setData('lighter'); $textdecorxml->addChild('option', array('value' => '400'))->setData('normal'); $textdecorxml->addChild('option', array('value' => '600'))->setData('bold'); $textdecorxml->addChild('option', array('value' => '700'))->setData('bolder'); $textdecorxml->addChild('option', array('value' => '800'))->setData('extrabold'); $textd = new JElementOfflajnList(); $textd->id = $elements['textdecor']['id']; $elements['textdecor']['html'] = $textd->universalfetchElement($elements['textdecor']['name'], isset($def['textdecor']) ? $def['textdecor'] : 'Normal', $textdecorxml); // $elements['textdecor']['script'] = $stack->endStack(true); // END TEXT-DECORATION /* // bold $elements['bold']['name'] = $name.'bold'; $elements['bold']['id'] = $this->generateId($elements['bold']['name']); $boldxml = new JSimpleXML(); $boldxml->loadString('<param mode="button" imsrc="bold.png" actsrc="bold_act.png" description=""/>'); $boldxml = $boldxml->document; $boldxml->addAttribute('name', $elements['bold']['name']); $bold = new JElementofflajnonoff(); $bold->id = $elements['bold']['id']; $elements['bold']['html'] = $bold->universalfetchElement($elements['bold']['name'], isset($def['bold'])?$def['bold']:0, $boldxml);*/ // END bold // italic $elements['italic']['name'] = $name . 'italic'; $elements['italic']['id'] = $this->generateId($elements['italic']['name']); $italicxml = new JSimpleXML(); $italicxml->loadString('<param mode="button" imsrc="italic.png" actsrc="italic_act.png" description=""/>'); $italicxml = $italicxml->document; $italicxml->addAttribute('name', $elements['italic']['name']); $italic = new JElementofflajnonoff(); $italic->id = $elements['italic']['id']; $elements['italic']['html'] = $italic->universalfetchElement($elements['italic']['name'], isset($def['italic']) ? $def['italic'] : 0, $italicxml); // END italic // underline $elements['underline']['name'] = $name . 'underline'; $elements['underline']['id'] = $this->generateId($elements['underline']['name']); $underlinexml = new JSimpleXML(); $underlinexml->loadString('<param mode="button" imsrc="underline.png" actsrc="underline_act.png" description=""/>'); $underlinexml = $underlinexml->document; $underlinexml->addAttribute('name', $elements['underline']['name']); $underline = new JElementofflajnonoff(); $underline->id = $elements['underline']['id']; $elements['underline']['html'] = $underline->universalfetchElement($elements['underline']['name'], isset($def['underline']) ? $def['underline'] : 0, $underlinexml); // END underline // ALIGN $elements['align']['name'] = $name . 'align'; $elements['align']['id'] = $this->generateId($elements['align']['name']); $alignxml = new JSimpleXML(); $tsxml = <<<EOD <param type="offlajnradio" mode="image"> <option value="left" imsrc="left_align.png"></option> <option value="center" imsrc="center_align.png"></option> <option value="right" imsrc="right_align.png"></option> </param> EOD; $alignxml->loadString($tsxml); $alignxml = $alignxml->document; $alignxml->addAttribute('name', $elements['align']['name']); $align = new JElementOfflajnRadio(); $align->id = $elements['align']['id']; $elements['align']['html'] = $align->universalfetchElement($elements['align']['name'], isset($def['align']) ? $def['align'] : 'left', $alignxml); // ALIGN // Alternative font $elements['afont']['name'] = $name . 'afont'; $elements['afont']['id'] = $this->generateId($elements['afont']['name']); $afontxml = new JSimpleXML(); $afontxml->loadString('<param onoff="1"><unit value="1" imsrc="">ON</unit><unit value="0" imsrc="">OFF</unit></param>'); $afontxml = $afontxml->document; $afontxml->addAttribute('name', $elements['afont']['name']); $afontxml->addAttribute('type', 'offlajntext'); $afontxml->addAttribute('size', '10'); $afont = new JElementOfflajnText(); $afont->id = $elements['afont']['id']; $elements['afont']['html'] = $afont->universalfetchElement($elements['afont']['name'], isset($def['afont']) ? $def['afont'] : 'Arial||1', $afontxml); // END Alternative font // TEXT SHADOW $elements['tshadow']['name'] = $name . 'tshadow'; $elements['tshadow']['id'] = $this->generateId($elements['tshadow']['name']); $tshadowxml = new JSimpleXML(); $tsxml = <<<EOD <param> <param size="1" validation="float" type="offlajntext"><unit value="px" imsrc="">px</unit></param> <param size="1" validation="float" type="offlajntext"><unit value="px" imsrc="">px</unit></param> <param size="1" validation="float" type="offlajntext"><unit value="px" imsrc="">px</unit></param> <param type="offlajncolor" alpha="{$alpha}"/> <param type="offlajnswitcher" onoff="1"><unit value="1" imsrc="">ON</unit><unit value="0" imsrc="">OFF</unit></param> </param> EOD; $tshadowxml->loadString($tsxml); $tshadowxml = $tshadowxml->document; $tshadowxml->addAttribute('name', $elements['tshadow']['name']); $tshadowxml->addAttribute('type', 'offlajncombine'); $tshadow = new JElementOfflajnCombine(); $tshadow->id = $elements['tshadow']['id']; $elements['tshadow']['html'] = $tshadow->universalfetchElement($elements['tshadow']['name'], isset($def['tshadow']) ? $def['tshadow'] : '0|*|0|*|0|*|000000|*|0', $tshadowxml); // TEXT SHADOW // LINE HEIGHT $elements['lineheight']['name'] = $name . 'lineheight'; $elements['lineheight']['id'] = $this->generateId($elements['lineheight']['name']); $lineheightxml = new JSimpleXML(); $lineheightxml->loadString('<param></param>'); $lineheightxml = $lineheightxml->document; $lineheightxml->addAttribute('name', $elements['lineheight']['name']); $lineheightxml->addAttribute('type', 'offlajntext'); $lineheightxml->addAttribute('size', '5'); $lineheight = new JElementOfflajnText(); $lineheight->id = $elements['lineheight']['id']; $elements['lineheight']['html'] = $lineheight->universalfetchElement($elements['lineheight']['name'], isset($def['lineheight']) ? $def['lineheight'] : 'normal', $lineheightxml); // END LINE HEIGHT $this->loadFiles(); $id = $this->generateId($name); $script = $stack->endStack(true); $settings = array(); if ($value == '' || $value[0] != '{') { foreach ($tabs as $t) { $settings[$t] = new StdClass(); } $settings = json_encode($settings); } else { $settings = $value; } $document = JFactory::getDocument(); DojoLoader::addScript(' new FontConfigurator({ id: "' . $this->id . '", defaultTab: "' . $tabs[0] . '", origsettings: ' . $settings . ', elements: ' . json_encode($elements) . ', script: ' . json_encode($script) . ' }); '); $html .= "<a style='float: left;' id='" . $id . "change' href='#' class='font_select'></a> "; if ($this->_parent->get('admindebug', 0) == 1) { $html .= '<span>Raw font data: </span><input type="text" name="' . $name . '" id="' . $id . '" value="' . str_replace('"', "'", $value) . '" />'; } else { if ($value != "") { if ($value[0] != '{') { $value = $settings; } } $html .= '<input type="hidden" name="' . $name . '" id="' . $id . '" value=\'' . str_replace("'", '"', $value) . '\' />'; } return $html; }
public function getUpdate() { // This can also be overwritten using config file $serverXML = 'http://www.offiria.com/releases.xml'; $app = JFactory::getApplication(); $defaultFile = JPATH_ROOT . DS . 'offiria.xml'; $objXml = new JSimpleXML(); $objXml->loadFile($defaultFile); $children = $objXml->document->children(); $localversion = $children[0]->attributes('number'); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $serverXML); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); curl_close($curl); $objXml2 = new JSimpleXML(); $objXml2->loadString($result); $renderData = new stdClass(); $renderData->data = array(); $renderData->current_version = $localversion; if (isset($objXml2->document) && isset($objXml2->document->releases)) { $releases = $objXml2->document->releases[0]; try { // Always assume the first child is the latest $latestversion = $releases->version[0]->attributes('number'); if (trim($localversion) == trim($latestversion)) { $renderData->msg = 'No new updates available.'; } else { $renderData->msg = 'New updates available.'; $notMet = true; foreach ($releases->version as $version) { if (trim($localversion) == trim($version->attributes('number'))) { // found break; } else { $index = count($renderData->data); $renderData->data[$index] = new stdClass(); $renderData->data[$index]->version = $version->attributes('number'); $renderData->data[$index]->package_url = $version->package[0]->attributes('url'); $renderData->data[$index]->change_log = $version->changelog[0]->data(); } } } } catch (Exception $ex) { $renderData->msg = 'Unable to retrieve update logs.'; } } else { $renderData->msg = 'Unable to retrieve update logs.'; } require_once JPATH_ROOT . DS . 'components' . DS . 'com_account' . DS . 'views' . DS . 'update' . DS . 'view.html.php'; $view = new AccountViewUpdate($renderData); $view->display($renderData); }
function &getXML($type, &$params, $decorator) { static $xmls; if (!isset($xmls[$type])) { $cache =& JFactory::getCache('mod_icemegamenu'); $string = $cache->call(array('modIceMegamenuHelper', 'buildXML'), $params); $xmls[$type] = $string; } // Get document require_once JPATH_BASE . DS . "modules" . DS . "mod_icemegamenu" . DS . "libs" . DS . "simplexml.php"; $xml = new JSimpleXML(); $xml->loadString($xmls[$type]); $doc =& $xml->document; $menu =& JSite::getMenu(); $active = $menu->getActive(); $start = $params->get('startLevel'); $end = $params->get('endLevel'); $sChild = $params->get('showAllChildren'); $path = array(); // Get subtree if ($doc && is_callable($decorator)) { $doc->map($decorator, array('end' => $end, 'children' => $sChild)); } return $doc; }
function universalfetchElement($name, $value, &$node) { define("OFFLAJNADMIN", "1"); $this->loadFiles(); $this->loadFiles('legacy', 'offlajndashboard'); $j17 = 0; if (version_compare(JVERSION, '1.6.0', 'ge')) { $j17 = 1; } $style = ""; $opened_ids = json_decode(stripslashes(@$_COOKIE[$this->_moduleName . "lastState"])); if ($opened_ids) { foreach ($opened_ids as $id) { $style .= '#content-box #' . $id . ' div.content{' . 'opacity: 1;' . 'height: 100%;' . '}'; } } $document =& JFactory::getDocument(); $document->addStyleDeclaration($style); DojoLoader::r('dojo.uacss'); DojoLoader::addScript(' var offlajnParams = new OfflajnParams({ joomla17 : ' . $j17 . ', moduleName : "' . $this->_moduleName . '" }); '); $lang =& JFactory::getLanguage(); $lang->load($this->_moduleName, dirname(__FILE__) . DS . '..' . DS . '..'); $xml = dirname(__FILE__) . DS . '../../' . $this->_moduleName . '.xml'; if (!file_exists($xml)) { $xml = dirname(__FILE__) . DS . '../../install.xml'; if (!file_exists($xml)) { return; } } if (version_compare(JVERSION, '3.0', 'ge')) { $xmlo = JFactory::getXML($xml); $xmld = $xmlo; } else { jimport('joomla.utilities.simplexml'); $xmlo = JFactory::getXMLParser('Simple'); $xmlo->loadFile($xml); $xmld = $xmlo->document; } if (isset($xmld->hash) && (string) $xmld->hash) { if (version_compare(JVERSION, '3.0', 'ge')) { $hash = (string) $xmld->hash[0]; } else { $hash = (string) $xmld->hash[0]->data(); } } $this->attr = $node->attributes(); if (!isset($hash)) { $this->generalInfo = '<iframe src="http://offlajn.com/index2.php?option=com_offlajn_update_info&v=' . (version_compare(JVERSION, '3.0', 'ge') ? (string) $xmld->version : $xmld->version[0]->data()) . '" frameborder="no" style="border: 0;" width="100%"></iframe>'; $this->relatedNews = '<iframe id="related-news-iframe" src="http://offlajn.com/index2.php?option=com_offlajn_related_news&tag=' . @$this->attr['blogtags'] . '" frameborder="no" style="border: 0;" width="100%" ></iframe>'; } else { $this->generalInfo = '<iframe src="http://offlajn.com/index2.php?option=com_offlajn_update_info&hash=' . base64_url_encode($hash) . '&v=' . (version_compare(JVERSION, '3.0', 'ge') ? (string) $xmld->version : $xmld->version[0]->data()) . '&u=' . JURI::root() . '" frameborder="no" style="border: 0;" width="100%"></iframe>'; $this->relatedNews = '<iframe id="related-news-iframe" src="http://offlajn.com/index2.php?option=com_offlajn_related_news&tag=' . @$this->attr['blogtags'] . '" frameborder="no" style="border: 0;" width="100%" ></iframe>'; } $this->loadDashboard(); if (!version_compare(JVERSION, '1.6.0', 'ge')) { preg_match('/(.*)\\[([a-zA-Z0-9]*)\\]$/', $name, $out); @($control = $out[1]); $x = file_get_contents($xml); preg_match('/<fieldset.*?>(.*)<\\/fieldset>/ms', $x, $out); $params = str_replace(array('<field', '</field'), array('<param', '</param'), $out[0]); $n = new JSimpleXML(); $n->loadString($params); $attrs = $n->document->attributes(); if ($_REQUEST['option'] == 'com_modules' || $_REQUEST['option'] == 'com_advancedmodules') { $n->document->removeChild($n->document->param[0]); $params = new OfflajnJParameter(''); $params->setXML($n->document); $params->_raw =& $this->_parent->_raw; $params->bind($this->_parent->_raw); echo $params->render($control); } } if (!isset($hash) || $hash == '') { return; } return ""; }
/** * Pull weather information for 'location' passed in * If enable_cache = true, data is cached and refreshed every hour * Weather data is returned in an associative array * * @param string $location * @return array */ function get_weather_data($location = ''){ $return_array = array(); $this->location = $location; $lang = $_SERVER['HTTP_ACCEPT_LANGUAGE']; list($lang) = explode(",", $lang); list($lang) = explode("-", $lang); if (!isset($lang) || $lang=="") $lang="en"; if ($this->enable_cache && !empty($this->cache_path)){ $this->cache_file = $this->cache_path . '/' . $this->filename_safe($this->location."_".$lang); if (strlen($this->location)>0 && file_exists($this->cache_file)){ $cached_data = $this->load_from_cache(); if($cached_data) return $cached_data; } } // portoguese fix if ($lang == 'pt') { $this->gweather_api_url = str_replace(".com", ".pt", $this->gweather_api_url); $hl = ""; } else $hl = "&hl=" . urlencode($lang); // build the url $this->gweather_api_url = $this->gweather_api_url . urlencode($this->location) . $hl; if ($this->make_request()){ $xml = new JSimpleXML(); $xml->loadString($this->raw_data); if (isset($xml->document->weather[0]->problem_cause) || !isset($xml->document->weather[0]->forecast_information)) { $return_array['error'] = "invalid location provided"; return $return_array; } $forecast_information = $xml->document->weather[0]->forecast_information[0]; $current_conditions = $xml->document->weather[0]->current_conditions[0]; $forecast_conditions = $xml->document->weather[0]->forecast_conditions; $return_array['forecast_info']['city'] = $forecast_information->city[0]->attributes('data'); $return_array['forecast_info']['zip'] = $forecast_information->postal_code[0]->attributes('data'); $return_array['forecast_info']['date'] = $forecast_information->forecast_date[0]->attributes('data'); $return_array['forecast_info']['date_time'] = $forecast_information->current_date_time[0]->attributes('data'); $return_array['forecast_info']['units'] = $forecast_information->unit_system[0]->attributes('data'); $return_array['current_conditions']['condition'] = $current_conditions->condition[0]->attributes('data'); $return_array['current_conditions']['temp_f'] = $current_conditions->temp_f[0]->attributes('data'); $return_array['current_conditions']['temp_c'] = $current_conditions->temp_c[0]->attributes('data'); $return_array['current_conditions']['humidity'] = $current_conditions->humidity[0]->attributes('data'); $return_array['current_conditions']['icon'] = $this->fix_icon($current_conditions->icon[0]->attributes('data')); $return_array['current_conditions']['wind'] = $current_conditions->wind_condition[0]->attributes('data'); for ($i = 0; $i < count($forecast_conditions); $i++){ $data = $forecast_conditions[$i]; $return_array['forecast'][$i]['day_of_week'] = $data->day_of_week[0]->attributes('data'); $return_array['forecast'][$i]['low'] = $data->low[0]->attributes('data'); $return_array['forecast'][$i]['high'] = $data->high[0]->attributes('data'); $return_array['forecast'][$i]['icon'] = $this->fix_icon($data->icon[0]->attributes('data')); $return_array['forecast'][$i]['condition'] = $data->condition[0]->attributes('data'); } } if (count($return_array)>1 && $this->enable_cache && !empty($this->cache_path)){ $this->write_to_cache($return_array); } return $return_array; }
private function parseXml($xml) { $res = new JSimpleXML(); $res->loadString($xml); return $res; }