SimpleXMLElement PHP Class Code Examples

This page contains top rated real world PHP examples of class SimpleXMLElement extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: helper.php Project: bobozhangshao/HeartCare
1
 /**
  * @param string $url
  * @param string $file
  * @param int $duration
  * @return SimpleXMLElement|null
  */
 public static function getFeedXML($url, $file, $duration = 12)
 {
     global $_CB_framework;
     cbimport('cb.snoopy');
     $cache = $_CB_framework->getCfg('absolute_path') . '/cache/' . $file;
     $xml = null;
     if (file_exists($cache)) {
         if (!$duration || intval(($_CB_framework->now() - filemtime($cache)) / 3600) > $duration) {
             $request = true;
         } else {
             $xml = new SimpleXMLElement(trim(file_get_contents($cache)));
             $request = false;
         }
     } else {
         $request = true;
     }
     if ($request) {
         $s = new CBSnoopy();
         $s->read_timeout = 30;
         $s->referer = $_CB_framework->getCfg('live_site');
         @$s->fetch($url);
         if ((int) $s->status == 200) {
             try {
                 $xml = new SimpleXMLElement($s->results);
                 $xml->saveXML($cache);
             } catch (Exception $e) {
             }
         }
     }
     return $xml;
 }
Example #2
Show file File: AdiantiMenuBuilder.php Project: edurbs/sobcontrole
0
 public static function parse($file, $theme)
 {
     switch ($theme) {
         case 'theme1':
             ob_start();
             $callback = array('SystemPermission', 'checkPermission');
             $menu = TMenuBar::newFromXML('menu.xml', $callback);
             $menu->show();
             $menu_string = ob_get_clean();
             return $menu_string;
             break;
         case 'theme2':
             ob_start();
             $callback = array('SystemPermission', 'checkPermission');
             $xml = new SimpleXMLElement(file_get_contents('menu.xml'));
             $menu = new TMenu($xml, $callback, 1, 'nav collapse', '');
             $menu->class = 'nav';
             $menu->id = 'side-menu';
             $menu->show();
             $menu_string = ob_get_clean();
             return $menu_string;
             break;
         case 'theme3':
             ob_start();
             $callback = array('SystemPermission', 'checkPermission');
             $xml = new SimpleXMLElement(file_get_contents('menu.xml'));
             $menu = new TMenu($xml, $callback, 1, 'treeview-menu', 'treeview', '');
             $menu->class = 'sidebar-menu';
             $menu->id = 'side-menu';
             $menu->show();
             $menu_string = ob_get_clean();
             return $menu_string;
             break;
     }
 }
Example #3
Show file File: SimpleXMLElementTest.php Project: lucidphp/xml
0
 /** @test */
 public function itShouldAppendCdataSections()
 {
     $xml = new SimpleXMLElement('<node></node>');
     $xml->addCDATASection('string');
     $this->assertXmlStringEqualsXmlString('<node><![CDATA[string]]></node>', $xml->asXML());
     if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.7', '<')) {
         $this->markTestIncomplete('HHVM segmentation fault.');
     }
     $xml = new SimpleXMLElement('<node></node>');
     $xml->addCDATASection(new SimpleXML('<data>string</data>'));
     $this->assertXmlStringEqualsXmlString('<node><![CDATA[<data>string</data>]]></node>', $xml->asXML());
     $xml = new SimpleXMLElement('<node></node>');
     $dom = new DOM();
     $dom->loadXML('<data>string</data>');
     $xml->addCDATASection($dom);
     $this->assertXmlStringEqualsXmlString('<node><![CDATA[<data>string</data>]]></node>', $xml->asXML());
     $xml = new SimpleXMLElement('<node></node>');
     $dom = new DOMDocument();
     $dom->loadXML('<root><data>string</data></root>');
     $xml->addCDATASection($dom->xpath('data')->item(0));
     $this->assertXmlStringEqualsXmlString('<node><![CDATA[<data>string</data>]]></node>', $xml->asXML());
     $xml = new SimpleXMLElement('<node></node>');
     try {
         $xml->addCDATASection([]);
     } catch (\InvalidArgumentException $e) {
         return $this->assertTrue(true);
     }
 }
Example #4
Show file File: TMenuBar.class.php Project: enieber/adianti
0
 /**
  * Build a MenuBar from a XML file
  * @param $xml_file path for the file
  */
 public static function newFromXML($xml_file)
 {
     //TPage::include_js('lib/bootstrap/js/bootstrap-dropdown.js');
     if (file_exists($xml_file)) {
         $menu_string = file_get_contents($xml_file);
         if (utf8_encode(utf8_decode($menu_string)) == $menu_string) {
             $xml = new SimpleXMLElement($menu_string);
         } else {
             $xml = new SimpleXMLElement(utf8_encode($menu_string));
         }
         $menubar = new TMenuBar();
         foreach ($xml as $xmlElement) {
             $atts = $xmlElement->attributes();
             $label = (string) $atts['label'];
             $action = (string) $xmlElement->action;
             $icon = (string) $xmlElement->icon;
             $button_div = new TElement('div');
             $button_div->{'class'} = 'btn-group';
             $button = new TElement('button');
             $button->{'data-toggle'} = 'dropdown';
             $button->{'class'} = 'btn dropdown-toggle';
             $button->add($label);
             $span = new TElement('span');
             $span->{'class'} = 'caret';
             $span->add('');
             $button->add($span);
             $menu = new TMenu($xmlElement->menu->menuitem);
             $button_div->add($button);
             $button_div->add($menu);
             $menubar->add($button_div);
         }
         return $menubar;
     }
 }
Example #5
Show file File: XmlResultObject.php Project: pankajshoffex/shoffex_prestashop
0
 /**
  * @param SimpleXMLElement $new
  * @param SimpleXMLElement $old
  *
  * @return SimpleXMLElement
  */
 public function replaceChild(SimpleXMLElement $new, SimpleXMLElement $old)
 {
     $tmp = dom_import_simplexml($this);
     $new = $tmp->ownerDocument->importNode(dom_import_simplexml($new), true);
     $node = $tmp->replaceChild($new, dom_import_simplexml($old));
     return simplexml_import_dom($node, get_class($this));
 }
Example #6
Show file File: ImageCollection.php Project: myindexlike/MODX.snippets
0
 /**
  * Constructs an ImageCollection object from the Picasa XML feed.
  *
  * @param string $url    A query URL constructed according to the Picasa API documentation hosted by
  *                       Google at {@link http://code.google.com/apis/picasaweb/gdata.html#Add_Album_Manual_Web}.
  * @param SimpleXMLElement $albums  XML describing a Picasa image collection.  This can be left blank as long as a URL is 
  *                                  specified in the url parameter that returns valid XML for a Picasa image collection.  If both 
  *                                  are null, a {@link Picasa_Exception} is thrown.
  * @param array $contextArray       An array that can be passed to stream_context_create() to generate
  *                                  a PHP context.  See 
  *                                  {@link http://us2.php.net/manual/en/function.stream-context-create.php}
  * @param boolean $useCache  You can decide not to cache a specific request by passing false here.  You may
  *                           want to do this, for instance, if you're requesting a private feed.
  * @throws {@link Picasa_Exception} If the XML suppled through either parameter does not contain valid XML.
  */
 public function __construct($url = null, SimpleXMLElement $collectionXml = null, $contextArray = null, $useCache = true)
 {
     if ($url != null) {
         Picasa_Logger::getLogger()->logIfEnabled('Request string: ' . $url);
         $context = null;
         $xmldata = false;
         if ($contextArray != null) {
             $context = stream_context_create($contextArray);
         }
         if ($useCache === true) {
             $xmldata = Picasa_Cache::getCache()->getIfCached($url);
         }
         if ($xmldata === false) {
             Picasa_Logger::getLogger()->logIfEnabled("Not using cached entry for " . $url);
             $xmldata = @file_get_contents($url, false, $context);
             if ($xmldata != false) {
                 Picasa_Cache::getCache()->setInCache($url, $xmldata);
             }
         }
         if ($xmldata === false) {
             throw Picasa::getExceptionFromInvalidQuery($url, $contextArray);
         }
         //print $xmldata;
         try {
             // Load the XML file into a SimpleXMLElement
             $albums = new SimpleXMLElement($xmldata);
         } catch (Exception $e) {
             throw new Picasa_Exception($e->getMessage(), null, $url);
         }
     }
     $namespaces = $albums->getNamespaces(true);
     if (array_key_exists("openSearch", $namespaces)) {
         $os_ns = $albums->children($namespaces["openSearch"]);
         $this->totalResults = $os_ns->totalResults;
         $this->startIndex = $os_ns->startIndex;
         $this->itemsPerPage = $os_ns->itemsPerPage;
     } else {
         $this->totalResults = null;
         $this->startIndex = null;
         $this->itemsPerPage = null;
     }
     $this->id = $albums->id;
     $this->title = $albums->title;
     $this->updated = $albums->updated;
     $this->icon = $albums->icon;
     $this->subtitle = $albums->subtitle;
     if ($albums->author != null && $albums->author != "") {
         $this->picasaAuthor = new Picasa_Author($albums->author);
         $this->author = $albums->author->name;
     } else {
         $this->picasaAuthor = null;
         $this->author = null;
     }
     $this->images = array();
     $i = 0;
     foreach ($albums->entry as $images) {
         $this->images[$i] = new Picasa_Image(null, $images);
         $i++;
     }
 }
Example #7
Show file File: update_eu_taxrulegroups.php Project: sowerr/PrestaShop
0
function addTaxRule(SimpleXMLElement $taxRulesGroup, SimpleXMLElement $tax, $iso_code_country)
{
    $taxRule = $taxRulesGroup->addChild('taxRule');
    $taxRule->addAttribute('iso_code_country', $iso_code_country);
    $taxRule->addAttribute('id_tax', (string) $tax['id']);
    return $taxRule;
}
Example #8
Show file File: XML.class.php Project: Superbeest/Core
0
 /**
  * Appends the given $element node to the given $to element.
  * This is added directly to the $to element.
  * @param \SimpleXMLElement The element to be mutated and expanded
  * @param \SimpleXMLElement The element to add to the target element
  */
 public static final function appendToXML(\SimpleXMLElement $to, \SimpleXMLElement $element)
 {
     $toDom = dom_import_simplexml($to);
     $dom1 = $toDom->ownerDocument;
     $fromDom = dom_import_simplexml($element);
     $toDom->appendChild($dom1->importNode($fromDom, true));
 }
Example #9
Show file File: xmlrpcserver.php Project: wwxgitcat/habari
0
 /**
  * Handle all incoming XMLRPC requests.
  */
 public function act_xmlrpc_call()
 {
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $exception = new XMLRPCException(1);
         $exception->output_fault_xml();
         // dies here
     }
     $input = file_get_contents('php://input');
     $xml = new SimpleXMLElement($input);
     $function = $xml->methodName;
     $params = array();
     $found_params = $xml->xpath('//params/param/value');
     if (is_array($found_params)) {
         foreach ($found_params as $param) {
             $params[] = XMLRPCUtils::decode_args($param);
         }
     }
     $returnvalue = false;
     Plugins::register(array($this, 'system_listMethods'), 'xmlrpc', 'system.listMethods');
     $returnvalue = Plugins::xmlrpc("{$function}", $returnvalue, $params, $this);
     $response = new SimpleXMLElement('<?xml version="1.0"?' . '><methodResponse><params><param></param></params></methodResponse>');
     XMLRPCUtils::encode_arg($response->params->param, $returnvalue);
     ob_end_clean();
     header('Content-Type: text/xml;charset=utf-8');
     echo trim($response->asXML());
     exit;
 }
Example #10
Show file File: ChangesetValueTextXMLExporter.class.php Project: pombredanne/tuleap
0
 public function export(SimpleXMLElement $artifact_xml, SimpleXMLElement $changeset_xml, Tracker_Artifact $artifact, Tracker_Artifact_ChangesetValue $changeset_value)
 {
     $field_change = $this->createFieldChangeNodeInChangesetNode($changeset_value, $changeset_xml);
     $cdata_factory = new XML_SimpleXMLCDATAFactory();
     $cdata_factory->insert($field_change, 'value', $changeset_value->getText());
     $field_change->value['format'] = $changeset_value->getFormat();
 }
Example #11
Show file File: ChangesetValuesXMLExporter.class.php Project: pombredanne/tuleap
0
 public function exportChangedFields(SimpleXMLElement $artifact_xml, SimpleXMLElement $changeset_xml, Tracker_Artifact $artifact, array $changeset_values)
 {
     $params = array(self::ARTIFACT_KEY => $artifact, self::ARTIFACT_XML_KEY => $artifact_xml, self::CHANGESET_XML_KEY => $changeset_xml, self::EXPORT_MODE_KEY => self::EXPORT_CHANGES);
     foreach ($changeset_values as $changeset_value) {
         $this->exportValue($changeset_value, $params);
     }
 }
Example #12
Show file File: TXMLBreadCrumb.class.php Project: jhonleandres/pecommerce
0
 /**
  * Handle paths from a XML file
  * @param $xml_file path for the file
  */
 public function __construct($xml_file, $controller)
 {
     parent::__construct();
     $path = array();
     if (file_exists($xml_file)) {
         $menu_string = file_get_contents($xml_file);
         if (utf8_encode(utf8_decode($menu_string)) == $menu_string) {
             $xml = new SimpleXMLElement($menu_string);
         } else {
             $xml = new SimpleXMLElement(utf8_encode($menu_string));
         }
         foreach ($xml as $xmlElement) {
             $atts = $xmlElement->attributes();
             $label = (string) $atts['label'];
             $action = (string) $xmlElement->action;
             $icon = (string) $xmlElement->icon;
             $this->parse($xmlElement->menu->menuitem, array($label));
         }
         if (isset($this->paths[$controller]) and $this->paths[$controller]) {
             $total = count($this->paths[$controller]);
             parent::addHome($path);
             $count = 1;
             foreach ($this->paths[$controller] as $path) {
                 parent::addItem($path, $count == $total);
                 $count++;
             }
         } else {
             throw new Exception(TAdiantiCoreTranslator::translate('Class ^1 not found in ^2', $controller, $xml_file));
         }
     } else {
         throw new Exception(TAdiantiCoreTranslator::translate('File not found') . ': ' . $xml_file);
     }
 }
Example #13
Show file File: BuildStatusController.php Project: DavidGarciaCat/PHPCI
0
 /**
  * Displays projects information in ccmenu format
  *
  * @param $projectId
  * @return bool
  * @throws \Exception
  * @throws b8\Exception\HttpException
  */
 public function ccxml($projectId)
 {
     /* @var Project $project */
     $project = $this->projectStore->getById($projectId);
     $xml = new \SimpleXMLElement('<Projects/>');
     if (!$project instanceof Project || !$project->getAllowPublicStatus()) {
         return $this->renderXml($xml);
     }
     try {
         $branchList = $this->buildStore->getBuildBranches($projectId);
         if (!$branchList) {
             $branchList = array($project->getBranch());
         }
         foreach ($branchList as $branch) {
             $buildStatusService = new BuildStatusService($branch, $project, $project->getLatestBuild($branch));
             if ($attributes = $buildStatusService->toArray()) {
                 $projectXml = $xml->addChild('Project');
                 foreach ($attributes as $attributeKey => $attributeValue) {
                     $projectXml->addAttribute($attributeKey, $attributeValue);
                 }
             }
         }
     } catch (\Exception $e) {
         $xml = new \SimpleXMLElement('<projects/>');
     }
     return $this->renderXml($xml);
 }
Example #14
Show file File: form.php Project: vanie3/appland
0
 protected static function mergeNodes(SimpleXMLElement $source, SimpleXMLElement $new)
 {
     // The assumption is that the inputs are at the same relative level.
     // So we just have to scan the children and deal with them.
     // Update the attributes of the child node.
     foreach ($new->attributes() as $name => $value) {
         if (isset($source[$name])) {
             $source[$name] = (string) $value;
         } else {
             $source->addAttribute($name, $value);
         }
     }
     foreach ($new->children() as $child) {
         $type = $child->getName();
         $name = $child['name'];
         // Does this node exist?
         $fields = $source->xpath($type . '[@name="' . $name . '"]');
         if (empty($fields)) {
             // This node does not exist, so add it.
             self::addNode($source, $child);
         } else {
             // This node does exist.
             switch ($type) {
                 case 'field':
                     self::mergeNode($fields[0], $child);
                     break;
                 default:
                     self::mergeNodes($fields[0], $child);
                     break;
             }
         }
     }
 }