/** * Retrieves the settings from the entry view * * @since 5.0 * @access public * @param string * @return */ public function getManifest($file, $hasInherit = true) { $parser = JFactory::getXml($file); $fieldsets = array(); foreach ($parser->fields as $field) { foreach ($field->fieldset as $row) { $fieldset = new stdClass(); $attributes = $row->attributes(); $fieldset->name = (string) $attributes['name']; $fieldset->info = (string) $attributes['info']; $fieldset->label = (string) $attributes['label']; $fieldset->fields = array(); // Skip anything without a label. if (!$fieldset->label) { continue; } // Go through each of the fields foreach ($row->field as $fieldItem) { $field = new stdClass(); $field->attributes = new stdClass(); $field->options = array(); foreach ($fieldItem->attributes() as $key => $value) { $field->attributes->{$key} = (string) $value; } // If user wants to skip this option altogether. if (isset($field->attributes->globals) && !$field->attributes->globals) { continue; } foreach ($fieldItem->option as $optionItem) { $option = new stdClass(); $option->label = (string) $optionItem; foreach ($optionItem->attributes() as $optionKey => $optionValue) { $option->{$optionKey} = (string) $optionValue; $field->options[] = $option; } } // If the xml file contains such attributes, we assume that the user wants to render a boolean field // This is only applicable if the field has maximum of 2 option if ($field->attributes->type == 'radio' && $field->attributes->class == 'btn-group') { $field->attributes->type = 'boolean'; } $fieldset->fields[] = $field; } $fieldsets[] = $fieldset; } } return $fieldsets; }
/** * Retrieves the settings from the entry view * * @since 5.0 * @access public * @param string * @return */ public function getManifest($file) { $parser = JFactory::getXml($file); $fieldsets = array(); foreach ($parser->fields as $field) { foreach ($field->fieldset as $row) { $fieldset = new stdClass(); $attributes = $row->attributes(); $fieldset->name = (string) $attributes['name']; $fieldset->info = (string) $attributes['info']; $fieldset->label = (string) $attributes['label']; $fieldset->fields = array(); // Skip anything without a label. if (!$fieldset->label) { continue; } foreach ($row->field as $fieldItem) { $field = new stdClass(); $field->attributes = new stdClass(); $field->options = array(); foreach ($fieldItem->attributes() as $key => $value) { $field->attributes->{$key} = (string) $value; } foreach ($fieldItem->option as $optionItem) { $option = new stdClass(); $option->label = (string) $optionItem; foreach ($optionItem->attributes() as $optionKey => $optionValue) { $option->{$optionKey} = (string) $optionValue; $field->options[] = $option; } } $fieldset->fields[] = $field; } $fieldsets[] = $fieldset; } } return $fieldsets; }
private function getModulesList($path, $tmp) { $info = $this->getInfo(); $zip = $path . '/modules.zip'; $state = JArchive::extract($zip, $tmp); // @TODO: Return errors if (!$state) { return false; } // Get a list of modules $items = JFolder::folders($tmp, '.', false, true); $modules = array(); foreach ($items as $item) { $element = basename($item); $manifest = $item . '/' . $element . '.xml'; // Read the xml file $parser = JFactory::getXml($manifest); $module = new stdClass(); $module->title = (string) $parser->name; $module->version = (string) $parser->version; $module->description = (string) $parser->description; $module->description = trim($module->description); $module->element = $element; $modules[] = $module; } return $modules; }
/** * Tests the JFactory::getXML method. * * @return void * * @since 12.2 */ public function testGetXml() { $xml = JFactory::getXml('<foo />', false); $this->assertInstanceOf('SimpleXMLElement', $xml, 'Line: ' . __LINE__); }
/** * Test the JForm::load method for cases of unexpected or bad input. * * This method can load an XML data object, or parse an XML string. */ public function testLoad_BadInput() { $form = new JFormInspector('form1'); $this->assertThat($form->load(123), $this->isFalse(), 'Line:' . __LINE__ . ' A non-string should return false.'); $this->assertThat($form->load('junk'), $this->isFalse(), 'Line:' . __LINE__ . ' An invalid string should return false.'); $this->assertThat($form->getXml(), $this->isNull(), 'Line:' . __LINE__ . ' The internal XML should be false as returned from simplexml_load_string.'); $this->assertThat($form->load('<notform><test /></notform>'), $this->isTrue(), 'Line:' . __LINE__ . ' Invalid root node name from string should still load.'); $this->assertThat($form->getXml()->getName(), $this->equalTo('form'), 'Line:' . __LINE__ . ' The internal XML should still be named "form".'); // Test for irregular object input. $form = new JFormInspector('form1'); $this->assertThat($form->load(JFactory::getXml('<notform><test /></notform>', false)), $this->isTrue(), 'Line:' . __LINE__ . ' Invalid root node name from XML object should still load.'); $this->assertThat($form->getXml()->getName(), $this->equalTo('form'), 'Line:' . __LINE__ . ' The internal XML should still be named "form".'); }
public static function getPobocky(&$params, $cache = true) { if (isset(self::$pobocky_cache)) { return self::$pobocky_cache; } jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $retfalse = new stdClass(); $document = JFactory::getDocument(); if ($cache) { if (!file_exists(JPATH_ROOT . DS . 'cache' . DS . 'ulozenka')) { if (@JFolder::create(JPATH_ROOT . DS . 'cache' . DS . 'ulozenka') === false) { return $retfalse; } } } $ts_filename = JPATH_ROOT . DS . 'cache' . DS . 'ulozenka' . DS . 'timestamp.txt'; $filename = JPATH_ROOT . DS . 'cache' . DS . 'ulozenka' . DS . 'pobocky.xml'; $url = 'http://www.ulozenka.cz/partner/pobocky.php?key=' . $params->key . '&partners=' . $params->partners; $time = time(); if (!$cache) { require_once dirname(__FILE__) . DS . 'api.php'; $request = new ulozenkaApi($params); $data = $request->getPobocky(); } else { /* if (file_exists(JPATH_CACHE.DS.'ulozenka'.DS.'ulozenkaobj.php')) //include(JPATH_CACHE.DS.'ulozenka'.DS.'ulozenkaobj.php'); $data = file_get_contents(JPATH_CACHE.DS.'ulozenka'.DS.'ulozenkaobj.php'); if (eval('?>'.$data.'<?php')!==false) { if (!empty($retObj)) return $retObj; } */ if (file_exists($filename)) { } else { require_once dirname(__FILE__) . DS . 'api.php'; $request = new ulozenkaApi($params); $data = $request->getPobocky(); if (!empty($data)) { JFile::write($filename, $data); JFile::write($ts_filename, $time); } } } if ($cache) { if (!JFile::exists($filename)) { return $retfalse; } } if (!function_exists('simplexml_load_file')) { return $retfalse; } if ($cache) { $xml = JFactory::getXml($filename); //$xml = simplexml_load_file($filename, "SimpleXMLElement", true); if (empty($xml)) { JFile::delete($ts_filename); JFile::delete($filename); return $retfalse; } } else { if (empty($data)) { $retfalse->error = $request->error; return $retfalse; } //$xml = simplexml_load_string($data, "SimpleXMLElement", true); $xml = JFactory::getXml($data, false); } if (empty($xml)) { $xml = new stdClass(); } $copy = new stdClass(); $copy->pobocky = array(); $copy->branch = $xml->branch; if (isset($request->error)) { $copy->error = (string) $request->error; } if (isset($xml->branch)) { foreach ($xml->branch as $p) { self::br2p($copy->pobocky, $p); } self::$pobocky_cache = $copy; if ($cache) { self::saveObj($copy); } return $copy; } // if (isset($xml->body)) $copy->body = (string)$xml->error; if (isset($xml->pobocky)) { if (count($xml->pobocky)) { foreach ($xml->pobocky as $pobocka) { $newpobocka = new stdClass(); $ac = (array) $pobocka; foreach ($ac as $key => $val) { $newpobocka->{$key} = $val; } $copy->pobocky[] = $newpobocka; } if (isset($xml->error)) { $copy->error = (string) $xml->error; } if (isset($xml->body)) { $copy->body = (string) $xml->error; } self::$pobocky_cache = $copy; if ($cache) { //self::saveObj($copy); return $copy; } } } self::$pobocky_cache = $xml; return $xml; }