Beispiel #1
0
 /**
  * {@inheritDoc}
  */
 public function getGeocodedData($address, $boundingBox = null)
 {
     if (null === $this->apiKey) {
         throw new InvalidCredentialsException('No API Key provided');
     }
     // This API doesn't handle IPs
     if (filter_var($address, FILTER_VALIDATE_IP)) {
         throw new UnsupportedException('The IGNOpenLSProvider does not support IP addresses.');
     }
     $query = sprintf(self::ENDPOINT_URL, $this->apiKey) . urlencode(sprintf(self::ENDPOINT_QUERY, $address));
     $content = $this->getAdapter()->getContent($query);
     $data = (array) json_decode($content, true);
     if (empty($data) || null === $data['xml']) {
         throw new NoResultException(sprintf('Could not execute query %s', $query));
     }
     if (200 !== $data['http']['status'] || null !== $data['http']['error']) {
         throw new NoResultException(sprintf('Could not execute query %s', $query));
     }
     $xpath = new \SimpleXMLElement($data['xml']);
     $xpath->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
     $positions = $xpath->xpath('//gml:pos');
     $positions = explode(' ', $positions[0]);
     $xpath->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
     $zipcode = $xpath->xpath('//xls:PostalCode');
     $city = $xpath->xpath('//xls:Place[@type="Municipality"]');
     $streetNumber = $xpath->xpath('//xls:Building');
     $cityDistrict = $xpath->xpath('//xls:Street');
     return array_merge($this->getDefaults(), array('latitude' => isset($positions[0]) ? (double) $positions[0] : null, 'longitude' => isset($positions[1]) ? (double) $positions[1] : null, 'streetNumber' => isset($streetNumber[0]) ? (string) $streetNumber[0]->attributes() : null, 'streetName' => isset($cityDistrict[0]) ? (string) $cityDistrict[0] : null, 'city' => isset($city[0]) ? (string) $city[0] : null, 'zipcode' => isset($zipcode[0]) ? (string) $zipcode[0] : null, 'cityDistrict' => isset($cityDistrict[0]) ? (string) $cityDistrict[0] : null, 'country' => 'France', 'countryCode' => 'FR', 'timezone' => 'Europe/Paris'));
 }
 /**
  * @param Layout $layout
  * @return self
  */
 public static function parse(Layout $layout)
 {
     $svg = preg_replace('<%.+?%>', '', $layout->getSVG());
     $xml = new \SimpleXMLElement($svg);
     $xml->registerXPathNamespace('svg', 'http://www.w3.org/2000/svg');
     $xml->registerXPathNamespace('xlink', 'http://www.w3.org/1999/xlink');
     $items = [];
     foreach ($xml->g->children() as $element) {
         $attributes = (array) $element->attributes();
         $attributes = $attributes['@attributes'];
         switch ($attributes['class']) {
             case 's-text':
                 $text_lines = [];
                 foreach ($element->text as $text_line) {
                     $text_lines[] = $text_line;
                 }
                 $attributes['content'] = implode("\n", $text_lines);
                 break;
             case 's-image':
                 $attributes['xlink:href'] = (string) $element->attributes('xlink', true)['href'];
                 break;
         }
         $items[] = $attributes;
     }
     return new self($items);
 }
 /**
  * This method returns an object matching the description specified by the element.
  *
  * @access public
  * @param Spring\Object\Parser $parser                      a reference to the parser
  * @param \SimpleXMLElement $element                        the element to be parsed
  * @return mixed                                            an object matching the description
  *                                                          specified by the element
  * @throws Throwable\Parse\Exception                        indicates that a problem occurred
  *                                                          when parsing
  */
 public function getObject(Spring\Object\Parser $parser, \SimpleXMLElement $element)
 {
     $attributes = $element->attributes();
     $type = isset($attributes['type']) ? $parser->valueOf($attributes['type']) : '\\Unicity\\BT\\Task\\Semaphore';
     $element->registerXPathNamespace('spring-bt', BT\Task::NAMESPACE_URI);
     $children = $element->xpath('./spring-bt:blackboard');
     $blackboard = !empty($children) ? $parser->getObjectFromElement($children[0]) : null;
     $element->registerXPathNamespace('spring-bt', BT\Task::NAMESPACE_URI);
     $children = $element->xpath('./spring-bt:policy');
     $policy = !empty($children) ? $parser->getObjectFromElement($children[0]) : null;
     $object = new $type($blackboard, $policy);
     if (!$object instanceof BT\Task\Semaphore) {
         throw new Throwable\Parse\Exception('Invalid type defined. Expected a task semaphore, but got an element of type ":type" instead.', array(':type' => $type));
     }
     if (isset($attributes['title'])) {
         $object->setTitle($parser->valueOf($attributes['title']));
     }
     $element->registerXPathNamespace('spring-bt', BT\Task::NAMESPACE_URI);
     $children = $element->xpath('./spring-bt:tasks');
     if (!empty($children)) {
         foreach ($children as $child) {
             $object->addTasks($parser->getObjectFromElement($child));
         }
     }
     return $object;
 }
 /**
  * @param string $trackingNumber
  *
  * @return DeliveryEvent
  */
 public function getLastEvent($trackingNumber)
 {
     $fp = fopen(sprintf(self::BASE_URL, $trackingNumber), 'r');
     $xml = stream_get_contents($fp);
     fclose($fp);
     $xml = new \SimpleXMLElement($xml);
     /* Registering needed namespaces. See http://stackoverflow.com/questions/10322464/ */
     $xml->registerXPathNamespace('soap', 'http://schemas.xmlsoap.org/soap/envelope/');
     $xml->registerXPathNamespace('ns1', 'http://cxf.tracking.soap.chronopost.fr/');
     /** @var null | DeliveryEvent $lastEvent */
     $lastEvent = null;
     $events = $xml->xpath('//soap:Body/ns1:trackSkybillResponse/return/listEvents/events');
     if (empty($events)) {
         $this->throwDataNotFoundException();
     }
     /* XPathing on namespaced XMLs can't be relative */
     foreach ($events as $event) {
         if (isset($event->eventDate) && isset($event->code)) {
             $currentEvent = new DeliveryEvent($trackingNumber, new DateTime(trim($event->eventDate)), $this->getStateFromCode(trim($event->code)));
             if ($lastEvent === null || $lastEvent->getEventDate() < $currentEvent->getEventDate()) {
                 $lastEvent = $currentEvent;
             }
         }
     }
     return $lastEvent;
 }
 function toGeoJSON()
 {
     $rssDoc = new SimpleXMLElement($this->doc);
     $rssDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls');
     $rssDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml');
     $rssDoc->registerXPathNamespace('georss', 'http://www.georss.org/georss');
     #for ingrid - portalu georss
     $rssDoc->registerXPathNamespace('ingrid', 'http://www.portalu.de/opensearch/extension/1.0');
     // build feature collection
     $featureCollection = new FeatureCollection();
     // elements of rss document
     $rssItems = $rssDoc->xpath("//item");
     if (count($rssItems) > 0) {
         foreach ($rssItems as $item) {
             $rssItem_dom = dom_import_simplexml($item);
             $feature = new geoRSSItem();
             $feature->targetEPSG = $this->targetEPSG;
             $feature->parse($rssItem_dom, $this->importItems);
             if (isset($feature->geometry) && $feature->geometry !== false) {
                 $featureCollection->addFeature($feature);
             }
         }
         return $featureCollection->toGeoJSON();
     } else {
         return "{'errorMessage':'Kein Ergebnis'}";
     }
 }
Beispiel #6
0
 protected function getXML()
 {
     $xml = new SimpleXMLElement($this->metadataXML);
     $xml->registerXPathNamespace('saml2', 'urn:oasis:names:tc:SAML:2.0:assertion');
     $xml->registerXPathNamespace('saml2p', 'urn:oasis:names:tc:SAML:2.0:protocol');
     $xml->registerXPathNamespace('md', 'urn:oasis:names:tc:SAML:2.0:metadata');
     return $xml;
 }
Beispiel #7
0
function getFormTitle($formId)
{
    $filename = getFormFilename($formId);
    $xml = new SimpleXMLElement(file_get_contents($filename));
    $xml->registerXPathNamespace('f', 'http://www.w3.org/2002/xforms');
    $xml->registerXPathNamespace('h', 'http://www.w3.org/1999/xhtml');
    $xml->registerXPathNamespace('ev', 'http://www.w3.org/2001/xml-events');
    $xml->registerXPathNamespace('xsd', 'http://www.w3.org/2001/XMLSchema');
    $xml->registerXPathNamespace('jr', 'http://openrosa.org/javarosa');
    list($title) = $xml->xpath('/h:html/h:head/h:title');
    return (string) $title;
}
 public function generateFeedForProducts($products, $params)
 {
     $params = $this->_prepareParams($params);
     $currency = Mage::app()->getStore(null)->getCurrentCurrency();
     $formatParams = array('display' => Zend_Currency::NO_SYMBOL);
     $helper = Mage::helper('catalog/image');
     $xml = new SimpleXMLElement('<rss xmlns:media="' . self::MEDIA_NS . '"' . 'xmlns:atom="' . self::ATOM_NS . '"/>');
     $xml->registerXPathNamespace('media', self::MEDIA_NS);
     $xml->registerXPathNamespace('atom', self::ATOM_NS);
     $xml->addAttribute('version', '2.0');
     $date = date('r', time());
     $channel = $xml->addChild('channel');
     $channel->title = $params['title'];
     $channel->link = $params['link'];
     $channel->addChild('description');
     $channel->pubDate = $date;
     $channel->lastBuildDate = $date;
     $channel->generator = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
     $link = $channel->addChild('link', null, self::ATOM_NS);
     $link->addAttribute('href', Mage::helper('core/url')->getCurrentUrl());
     $link->addAttribute('rel', 'self');
     $link->addAttribute('type', 'application/rss+xml');
     $author = Mage::getStoreConfig('trans_email/ident_general/email') . ' (' . Mage::getStoreConfig('trans_email/ident_general/name') . ')';
     foreach ($products as $product) {
         $name = $product->getName();
         $item = $channel->addChild('item');
         $item->title = $name;
         $item->link = $product->getProductUrl();
         $item->description = $this->_getProductAttributes($product);
         $item->pubDate = date('r', strtotime($product->getUpdatedAt()));
         $item->author = $author;
         $item->guid = $item->link;
         $item->addChild('title', htmlspecialchars($name), self::MEDIA_NS);
         foreach ($params['images'] as $tag => $data) {
             $child = $item->addChild($tag, '', self::MEDIA_NS);
             $url = $helper->init($product, 'small_image');
             if (count($data) == 2) {
                 $url->resize($data['width'], $data['height']);
                 foreach (array('width', 'height') as $p) {
                     if ($data[$p]) {
                         $child->addAttribute($p, $data[$p]);
                     }
                 }
             }
             $child->addAttribute('url', $url->__toString());
         }
         //We assume that current currency and base currency are same.
         //I.e. no currency convertion in the store
         $price = $currency->format($product->getPrice(), $formatParams, false);
         $item->addChild('price', '', self::MEDIA_NS)->addAttribute('price', $price);
     }
     return $this->formatXml($xml->asXML());
 }
 protected function getInfoFromXML(SimpleXMLElement $xml)
 {
     $xml->registerXPathNamespace('mb', 'http://musicbrainz.org/ns/mmd-2.0#');
     $xml->registerXPathNamespace('ext', 'http://musicbrainz.org/ns/ext#-2.0');
     // artist
     $xpaths = array('/mb:metadata/mb:artist[1]', '/mb:metadata/mb:artist-list/mb:artist[1]');
     // Run xpaths to extract artist elements
     foreach ($xpaths as $num => $xpath) {
         $artist = $xml->xpath($xpath);
         if ($artist === false || count($artist) == 0) {
             if ($num === count($xpaths) - 1) {
                 throw new Exception('Could not get info from MusicBrainz.');
             }
         } else {
             break;
         }
     }
     // Choose an artist from the results
     if (count($artist) == 1) {
         $artist = $artist[0];
     } else {
         // Iterate from beginning, ignoring Unknown types and hits with names that are <10% similar
         $selectedAHit = false;
         foreach ($artist as $artistHit) {
             if ($this->isCorrectArtist($artistHit)) {
                 $selectedAHit = true;
                 $artist = $artist[0];
                 break;
             }
         }
         if (!$selectedAHit) {
             $artist = $artist[0];
             // just take the first one
         }
     }
     // id
     $attr = $artist->attributes();
     $this->musicBrainzId = $attr['id'] . '';
     // type
     $this->type = $attr['type'] . '';
     // name
     $this->name = $artist->name . '';
     // disambiguation
     $this->disambiguation = $artist->disambiguation . '';
     // begin
     if ($artist->{'life-span'}) {
         $tmp = $artist->{'life-span'}->attributes();
         $this->begin = $tmp['begin'] . '';
         if (array_key_exists('end', $tmp)) {
             $this->end = $tmp['end'] . '';
         }
     }
 }
Beispiel #10
0
function buscarPorTag($tag)
{
    #Using the tag we complete the url
    $flickr = "https://api.flickr.com/services/feeds/photos_public.gne?tags=" . $tag;
    #With the complete url we obtain the xml content
    $xml = file_get_contents($flickr);
    #Create a simple xml element using the xml data obtained
    $entradas = new SimpleXMLElement($xml);
    #The namespace is registered for the xpath search
    $entradas->registerXPathNamespace("feed", "http://www.w3.org/2005/Atom");
    #Printing the header
    echo "<h1 align='center'>Últimas 10 fotos con la etiqueta " . $tag . "</h1><table>";
    #Declaring the string for the table creation beginning for the header
    $tabla = "<th colspan='2'>¿Quieres buscar por otra etiqueta?<br><pre>Para usar varias separar con coma(sin espacios)</pre><form method='get'>\t\t\t\n\t\t\t<input type='text'name='tag'><br><input type='submit' value='Aceptar'>\n\t\t\t</form><th>";
    #Getting links with xpath expression
    $links = $entradas->xpath("//feed:entry/feed:link[@rel='enclosure']/./@href");
    #We get through the result filling an array
    $indice = 0;
    foreach ($links as $imagen) {
        $array_links[$indice] = $imagen;
        $indice++;
    }
    #We make a loop for showing the results
    for ($i = 1; $i <= 10; $i++) {
        #we add the xml data to the table creation string, navigating through the document and using the previously created array
        $tabla = $tabla . "<tr><td><img src=" . $array_links[$i] . " width='500px'></td><td width='300px'><b>Título</b><br>" . $entradas->entry[$i]->title . "<br><b>Autor</b></br>" . $entradas->entry[$i]->author->name . "</td></tr>";
    }
    #Finally we print the complete table
    echo "<table align='center'bgcolor='#F2F2F2' cellpadding='20px'>" . $tabla . "</table>";
}
Beispiel #11
0
 /** 
  * Add tracking data to purchase log
  */
 public function bfg_display_tracking_link($purchase)
 {
     global $wp_version;
     if ($purchase['processed'] != 4) {
         // Do nothing if purchase status is unlike 'job_dispatched'
         return false;
     }
     if ($purchase['track_id'] != null) {
         $bhg_header_options = array('timeout' => 3, 'user-agent' => 'WordPress/' . $wp_version . '; WP e-Commerce/' . WPSC_PRESENTABLE_VERSION . '; ' . home_url('/'));
         $bfg_tracking_url_beta = "http://beta.bring.no/sporing/sporing.xml";
         $bfg_tracking_url = "http://sporing.bring.no/sporing.xml";
         $bfg_params = array('q' => $purchase['track_id']);
         $bfg_tracking_url_beta = add_query_arg($bfg_params, $bfg_tracking_url_beta);
         $bfg_results = wp_remote_get($bfg_tracking_url_beta, $bhg_header_options);
         $bfg_body = trim($bfg_results['body']);
         if ($bfg_body != "No shipments found") {
             $bfg_xml = new SimpleXMLElement($bfg_body);
             $bfg_xml->registerXPathNamespace("s", "http://www.bring.no/sporing/1.0");
             $bfg_status_description_xml = $bfg_xml->xpath('s:Consignment/s:PackageSet/s:Package/s:StatusDescription');
             $bfg_status_description = (string) $bfg_status_description_xml[0];
             printf(__('<strong class="form_group">Tracking ID:</strong> <a href="http://sporing.bring.no/sporing.html?q=%1$s" target="_blank">%2$s</a><br><br>', 'bfg'), $purchase['track_id'], $purchase['track_id']);
             printf(__('<strong class="form_group">Shipment Status:</strong> %1$s<br><br>', 'bfg'), $bfg_status_description);
         } else {
             _e('<strong class="form_group">Shipment Status: Shipment not found</strong><br><br>', 'bfg');
         }
     }
 }
Beispiel #12
0
 /**
  * This method retypes any objects matching either the type mappings or name mappings.
  *
  * @access public
  * @static
  * @param \SimpleXMLElement $xml                            the Spring XML to be processed
  * @param array $mappings                                   the type and name mappings
  */
 public static function retype(\SimpleXMLElement $xml, array $mappings)
 {
     if (!empty($mappings)) {
         $xml->registerXPathNamespace('spring', Spring\Data\XML::NAMESPACE_URI);
         $objects = $xml->xpath('//spring:object');
         array_walk($objects, function (\SimpleXMLElement &$object) use($mappings) {
             $attributes = $object->attributes();
             if (isset($attributes['type'])) {
                 $type = Spring\Data\XML::valueOf($attributes['type']);
                 if (isset($mappings['types'][$type])) {
                     $attributes['type'] = $mappings['types'][$type];
                 }
             }
             if (isset($attributes['name'])) {
                 $names = preg_split('/(,|;|\\s)+/', Spring\Data\XML::valueOf($attributes['name']));
                 foreach ($names as $name) {
                     if (isset($mappings['ids'][$name])) {
                         $attributes['type'] = $mappings['ids'][$name];
                     }
                 }
             }
             if (isset($attributes['id'])) {
                 $id = Spring\Data\XML::valueOf($attributes['id']);
                 if (isset($mappings['ids'][$id])) {
                     $attributes['type'] = $mappings['ids'][$id];
                 }
             }
         });
     }
 }
 /**
  * This extracts the fulltext data from ALTO XML
  *
  * @access	public
  *
  * @param	SimpleXMLElement		$xml: The XML to extract the metadata from
  *
  * @return	string			The raw unformatted fulltext
  */
 public static function getRawText(SimpleXMLElement $xml)
 {
     $xml->registerXPathNamespace('alto', 'http://www.loc.gov/standards/alto/ns-v2#');
     // Get all (presumed) words of the text.
     $words = $xml->xpath('./alto:Layout/alto:Page/alto:PrintSpace/alto:TextBlock/alto:TextLine/alto:String/@CONTENT');
     return implode(' ', $words);
 }
 function setIdentifier($form_values)
 {
     require_once drupal_get_path('module', 'Fedora_Repository') . '/ObjectHelper.php';
     require_once drupal_get_path('module', 'Fedora_Repository') . '/CollectionClass.php';
     $collectionHelper = new CollectionClass();
     $ppid = $_SESSION['pid'];
     $itqlquery = 'select $object from <#ri> where $object <fedora-rels-ext:isPartOf><info:fedora/' . $ppid . '> and $object <fedora-rels-ext:isMemberOfCollection><info:fedora/vre:mnpl-compounds>and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>';
     $relatedItems = $collectionHelper->getRelatedItems($this->pid, $itqlquery);
     $sxe = new SimpleXMLElement($relatedItems);
     $nmspace = $sxe->getNamespaces(true);
     $regspace = $sxe->registerXPathNamespace('ri', implode($nmspace));
     $link = $sxe->xpath('//@uri');
     $labid = $_SESSION['labid'];
     if (empty($link)) {
         $ident = $labid . '-C-0';
     } else {
         //loop through returns , trim to create identifier and increment highest value
         $xia = array();
         foreach ($link as $path) {
             $path1 = substr($path, '30');
             $path2 = strrchr($path1, "-");
             $path = str_replace($path2, '', $path1);
             $xi = ltrim($path2, "-");
             $xnew = array_push($xia, $xi);
         }
         $num = max($xia);
         $numinc = $num + 1;
         $ident = $labid . '-C-' . $numinc;
     }
     return $ident;
 }
 /**
  * Hook for the __construct() method of dlf/common/class.tx_dlf_document.php
  * When using Goobi.Production the record identifier is saved only in MODS, but not
  * in METS. To get it anyway, we have to do some magic.
  *
  * @access	public
  *
  * @param	SimpleXMLElement		&$xml: The XML object
  * @param	mixed		$record_id: The record identifier
  *
  * @return	void
  */
 public function construct_postProcessRecordId(SimpleXMLElement &$xml, &$record_id)
 {
     if (!$record_id) {
         $xml->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3');
         if ($divs = $xml->xpath('//mets:structMap[@TYPE="LOGICAL"]//mets:div[@DMDID]')) {
             $smLinks = $xml->xpath('//mets:structLink/mets:smLink');
             if ($smLinks) {
                 foreach ($smLinks as $smLink) {
                     $links[(string) $smLink->attributes('http://www.w3.org/1999/xlink')->from][] = (string) $smLink->attributes('http://www.w3.org/1999/xlink')->to;
                 }
                 foreach ($divs as $div) {
                     if (!empty($links[(string) $div['ID']])) {
                         $id = (string) $div['DMDID'];
                         break;
                     }
                 }
             }
             if (empty($id)) {
                 $id = (string) $divs[0]['DMDID'];
             }
             $recordIds = $xml->xpath('//mets:dmdSec[@ID="' . $id . '"]//mods:mods/mods:recordInfo/mods:recordIdentifier');
             if (!empty($recordIds[0])) {
                 $record_id = (string) $recordIds[0];
             }
         }
     }
 }
 /**
  * @param string $data
  * @param string $element
  * @return array Parsed data.
  */
 public function readFromVariable($data, $element = 'target')
 {
     $messages = array();
     $mangler = $this->group->getMangler();
     $reader = new SimpleXMLElement($data);
     $reader->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
     $items = array_merge($reader->xpath('//trans-unit'), $reader->xpath('//xliff:trans-unit'));
     foreach ($items as $item) {
         /** @var SimpleXMLElement $source */
         $source = $item->{$element};
         if (!$source) {
             continue;
         }
         $key = (string) $item['id'];
         /* In case there are tags inside the element, preserve
          * them. */
         $dom = new DOMDocument('1.0');
         $dom->loadXML($source->asXml());
         $value = self::getInnerXml($dom->documentElement);
         /* This might not be 100% according to the spec, but
          * for now if there is explicit approved=no, mark it
          * as fuzzy, but don't do that if the attribute is not
          * set */
         if ((string) $source['state'] === 'needs-l10n') {
             $value = TRANSLATE_FUZZY . $value;
         }
         // Strip CDATA if present
         $value = preg_replace('/<!\\[CDATA\\[(.*?)\\]\\]>/s', '\\1', $value);
         $messages[$key] = $value;
     }
     return array('MESSAGES' => $mangler->mangle($messages));
 }
 /**
  * Parses additional exception information from the response body
  *
  * @param \SimpleXMLElement $body The response body as XML
  * @param array             $data The current set of exception data
  */
 protected function parseBody(\SimpleXMLElement $body, array &$data)
 {
     $data['parsed'] = $body;
     $namespaces = $body->getDocNamespaces();
     if (isset($namespaces[''])) {
         // Account for the default namespace being defined and PHP not being able to handle it :(
         $body->registerXPathNamespace('ns', $namespaces['']);
         $prefix = 'ns:';
     } else {
         $prefix = '';
     }
     if ($tempXml = $body->xpath("//{$prefix}Code[1]")) {
         $data['code'] = (string) $tempXml[0];
     }
     if ($tempXml = $body->xpath("//{$prefix}Message[1]")) {
         $data['message'] = (string) $tempXml[0];
     }
     $tempXml = $body->xpath("//{$prefix}RequestId[1]");
     if (empty($tempXml)) {
         $tempXml = $body->xpath("//{$prefix}RequestID[1]");
     }
     if (isset($tempXml[0])) {
         $data['request_id'] = (string) $tempXml[0];
     }
 }
Beispiel #18
0
 /**
  * Registers found doc namespaces to xpath for being able to access
  * elements via xpath
  *
  * @param \SimpleXMLElement $doc
  */
 protected function registerXPathNamespaces(\SimpleXMLElement $doc)
 {
     foreach ($doc->getDocNamespaces() as $strPrefix => $strNamespace) {
         if (strlen($strPrefix) == 0) {
             $strPrefix = $strNamespace;
         }
         $doc->registerXPathNamespace($strPrefix, $strNamespace);
     }
 }
Beispiel #19
0
 /**
  * Convert raw currency data to array of currencies
  * @param  string $raw_data currency data in XML format
  * @return array            currencies
  */
 public function convert_to_array($raw_data)
 {
     $xml = new \SimpleXMLElement($raw_data);
     $xml->registerXPathNamespace(self::XML_NAMESPACE, self::XML_NAMESPACE_URL);
     $data = $xml->xpath(self::XPATH_CURRENCY);
     $currencies = array();
     foreach ($data as $currency) {
         $currencies[(string) $currency->attributes()->currency] = (string) $currency->attributes()->rate;
     }
     return $currencies;
 }
 public function testSimpleXmlElement()
 {
     $dom = new \SimpleXMLElement('<?xml version="1.0"?>
         <record xmlns="http://www.loc.gov/MARC21/slim">
           <leader>99999 ai a22999997c 4500</leader>
         </record>');
     $dom->registerXPathNamespace('marc', 'http://www.loc.gov/MARC21/slim');
     $parser = new Parser();
     $out = $parser->parse($dom);
     $this->assertInstanceOf('Scriptotek\\SimpleMarcParser\\BibliographicRecord', $out);
 }
 public static function getClipDetailByIdentifier($id)
 {
     $video = new stdClass();
     # XML data URL
     $file_data = 'http://video.google.com/videofeed?docid=' . $id;
     $video->xml_url = $file_data;
     # XML
     $xml = new SimpleXMLElement(utf8_encode(file_get_contents($file_data)));
     $xml->registerXPathNamespace('media', 'http://search.yahoo.com/mrss/');
     # Title
     $title_query = $xml->xpath('/rss/channel/item/title');
     $video->title = $title_query ? strval($title_query[0]) : null;
     # Description
     $description_query = $xml->xpath('/rss/channel/item/media:group/media:description');
     $video->description = $description_query ? strval(trim($description_query[0])) : null;
     # Tags
     $video->tags = null;
     # Duration
     $duration_query = $xml->xpath('/rss/channel/item/media:group/media:content/@duration');
     $video->duration = $duration_query ? intval($duration_query[0]) : null;
     # Author & author URL
     // TODO: WTF?
     // $author_query = $xml->xpath('/rss/channel/item/author');
     // $video->author = $author_query ? strval($author_query[0]) : false;
     $video->author = null;
     $video->author_url = null;
     # Publication date
     $date_published_query = $xml->xpath('/rss/channel/item/pubDate');
     $video->date_published = $date_published_query ? new DateTime($date_published_query[0]) : null;
     # Last update date
     $video->date_updated = null;
     # Thumbnails
     $thumbnails_query = $xml->xpath('/rss/channel/item/media:group/media:thumbnail');
     $thumbnails_query = $thumbnails_query[0]->attributes();
     $thumbnail = new stdClass();
     $thumbnail->url = strval(preg_replace('#&amp;#', '&', $thumbnails_query['url']));
     $thumbnail->width = intval($thumbnails_query['width']);
     $thumbnail->height = intval($thumbnails_query['height']);
     $video->thumbnails[] = $thumbnail;
     # Player URL
     $player_url_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="application/x-shockwave-flash"]/@url');
     $video->player_url = $player_url_query ? strval($player_url_query[0]) : null;
     # AVI file URL
     $avi_url_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="video/x-msvideo"]/@url');
     $video->files['video/x-msvideo'] = $avi_url_query ? preg_replace('#&amp;#', '&', $avi_url_query[0]) : null;
     # FLV file URL
     $flv_url_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="video/x-flv"]/@url');
     $video->files['video/x-flv'] = $flv_url_query ? strval($flv_url_query[0]) : null;
     # MP4 file URL
     $mp4_url_query = $xml->xpath('/rss/channel/item/media:group/media:content[@type="video/mp4"]/@url');
     $video->files['video/mp4'] = $mp4_url_query ? preg_replace('#&amp;#', '&', $mp4_url_query[0]) : null;
     return $video;
 }
 public function getBillingAgreementDetailsStatus($response)
 {
     $data = new \SimpleXMLElement($response);
     $namespaces = $data->getNamespaces(true);
     foreach ($namespaces as $key => $value) {
         $namespace = $value;
     }
     $data->registerXPathNamespace('GetBA', $namespace);
     foreach ($data->xpath('//GetBA:BillingAgreementStatus') as $value) {
         $baStatus = json_decode(json_encode((array) $value), TRUE);
     }
     return $baStatus;
 }
Beispiel #23
0
 /**
  * @param string $query
  *
  * @return array
  */
 protected function executeQuery($query)
 {
     $content = $this->getAdapter()->getContent($query);
     $doc = new \DOMDocument();
     if (!@$doc->loadXML($content)) {
         throw new NoResultException(sprintf('Could not execute query %s', $query));
     }
     $xpath = new \SimpleXMLElement($content);
     $xpath->registerXPathNamespace('geo', 'http://www.w3.org/2003/01/geo/wgs84_pos#');
     $lat = $xpath->xpath('//geo:lat');
     $long = $xpath->xpath('//geo:long');
     return array_merge($this->getDefaults(), array('latitude' => isset($lat[0]) ? (double) $lat[0] : null, 'longitude' => isset($long[0]) ? (double) $long[0] : null));
 }
 private function getStatus($type, $path, $response)
 {
     $data = new \SimpleXMLElement($response);
     $namespaces = $data->getNamespaces(true);
     foreach ($namespaces as $key => $value) {
         $namespace = $value;
     }
     $data->registerXPathNamespace($type, $namespace);
     foreach ($data->xpath($path) as $value) {
         $status = json_decode(json_encode((array) $value), TRUE);
     }
     return $status;
 }
Beispiel #25
0
 public function gmail()
 {
     if (isset($_GET["error"]) && $_GET["error"] == 'access_denied') {
         echo "<script>window.close();</script>";
         return;
     }
     $client_id = Mage::getStoreConfig('socialapi/gmail/clientid');
     $client_secret = Mage::getStoreConfig('socialapi/gmail/clientsecret');
     $redirect_uri = Mage::getStoreConfig('socialapi/gmail/redirecturi');
     $max_results = 5000;
     $auth_code = $_GET["code"];
     $fields = array('code' => urlencode($auth_code), 'client_id' => urlencode($client_id), 'client_secret' => urlencode($client_secret), 'redirect_uri' => urlencode($redirect_uri), 'grant_type' => urlencode('authorization_code'));
     $post = '';
     foreach ($fields as $key => $value) {
         $post .= $key . '=' . $value . '&';
     }
     $post = rtrim($post, '&');
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, 'https://accounts.google.com/o/oauth2/token');
     curl_setopt($curl, CURLOPT_POST, 5);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
     $result = curl_exec($curl);
     curl_close($curl);
     $response = json_decode($result);
     $accesstoken = $response->access_token;
     $url = 'https://www.google.com/m8/feeds/contacts/default/full?max-results=' . $max_results . '&oauth_token=' . $accesstoken;
     $xmlresponse = $this->curl_file_get_contents($url);
     if (strlen(stristr($xmlresponse, 'Authorization required')) > 0 && strlen(stristr($xmlresponse, 'Error ')) > 0) {
         echo "<h2>OOPS !! Something went wrong. Please try reloading the page.</h2>";
         exit;
     }
     $xml = new SimpleXMLElement($xmlresponse);
     $xml->registerXPathNamespace('c', 'http://www.w3.org/2005/Atom');
     $result = $xml->xpath('//c:entry');
     $gmail_contacts = array();
     foreach ($result as $value) {
         $email = $value->children("http://schemas.google.com/g/2005")->attributes()->address;
         $title = $value->title;
         $json = json_encode($email);
         $array_email = json_decode($json, TRUE);
         $json = json_encode($title);
         $array_title = json_decode($json, TRUE);
         $gmail_contacts[$array_email['0']] = empty($array_title['0']) ? $array_email['0'] : $array_title['0'];
     }
     return $gmail_contacts;
 }
Beispiel #26
0
 public static function getSchemaParser(\SimpleXMLElement $sx)
 {
     $sx->registerXPathNamespace('dx0.5', 'http://www.concrete5.org/doctrine-xml/0.5');
     if ($sx->xpath('/dx0.5:schema')) {
         $parser = new \Concrete\Core\Database\Schema\Parser\DoctrineXml05($sx);
     } else {
         switch ($sx['version']) {
             case '0.3':
                 $parser = new \Concrete\Core\Database\Schema\Parser\Axmls($sx);
                 break;
             default:
                 throw new \Exception(t('Invalid schema version found. Expecting 0.3'));
         }
     }
     return $parser;
 }
Beispiel #27
0
 public function testeResultadoXml()
 {
     $this->nfe = new MakeNFe();
     $chave = '32160600445335300113550990000007921962533314';
     $tpAmb = '2';
     $finNFe = '1';
     $indFinal = '0';
     $indPres = '9';
     $procEmi = '0';
     $verProc = '4.0.43';
     $dhCont = '';
     $xJust = '';
     $versao = '3.10';
     $CNPJ = '02544316000170';
     $CPF = '';
     $xNome = '';
     $xFant = '';
     $IE = '';
     $IEST = '';
     $IM = '';
     $CNAE = '';
     $CRT = '';
     $cUF = '52';
     $cNF = '00000010';
     $natOp = 'Venda de Produto';
     $indPag = '1';
     $mod = '55';
     $serie = '1';
     $nNF = '10';
     $dhEmi = date("Y-m-d\\TH:i:sP");
     $dhSaiEnt = date("Y-m-d\\TH:i:sP");
     $tpNF = '1';
     $idDest = '1';
     $cMunFG = '5200258';
     $tpImp = '1';
     $tpEmis = '1';
     $cDV = substr($chave, -1);
     $this->nfe->tagide($cUF, $cNF, $natOp, $indPag, $mod, $serie, $nNF, $dhEmi, $dhSaiEnt, $tpNF, $idDest, $cMunFG, $tpImp, $tpEmis, $cDV, $tpAmb, $finNFe, $indFinal, $indPres, $procEmi, $verProc, $dhCont, $xJust);
     $resp = $this->nfe->taginfNFe($chave, $versao);
     $resp = $this->nfe->tagemit($CNPJ, $CPF, $xNome, $xFant, $IE, $IEST, $IM, $CNAE, $CRT);
     $this->nfe->montaNFE();
     $xmlResult = $this->nfe->getXML();
     $xml = new \SimpleXMLElement($xmlResult);
     $xml->registerXPathNamespace('c', 'http://www.portalfiscal.inf.br/nfe');
     $this->assertEquals('02544316000170', $xml->xpath('//c:CNPJ')[0]->__toString());
 }
function add_mods_namespace(SimpleXMLElement &$mods)
{
    static $used_namespace = NULL;
    static $mods_namespace = 'http://www.loc.gov/mods/v3';
    $namespaces = $mods->getNamespaces();
    if (is_null($used_namespace)) {
        if (array_search($mods_namespace, $namespaces) !== FALSE) {
            //The namespace is there; possibly default, though
            $used_namespace = $mods_namespace;
        } else {
            $used_namespace = '';
        }
    }
    if (array_key_exists('mods', $namespaces) === FALSE) {
        $mods->registerXPathNamespace('mods', $used_namespace);
    }
}
Beispiel #29
0
 public function test_send_authn_request_profile()
 {
     $buildContainer = $this->getBuildContainer();
     $idpEntityId = 'https://localhost/lightSAML/lightSAML-IDP';
     $builder = new \LightSaml\Builder\Profile\WebBrowserSso\Sp\SsoSpSendAuthnRequestProfileBuilder($buildContainer, $idpEntityId);
     $context = $builder->buildContext();
     $action = $builder->buildAction();
     $action->execute($context);
     $html = $context->getHttpResponseContext()->getResponse()->getContent();
     $crawler = new Crawler($html);
     $code = $crawler->filter('body form input[name="SAMLRequest"]')->first()->attr('value');
     $xml = base64_decode($code);
     $root = new \SimpleXMLElement($xml);
     $root->registerXPathNamespace('saml', SamlConstants::NS_ASSERTION);
     $this->assertEquals('AuthnRequest', $root->getName());
     $this->assertEquals(self::OWN_ENTITY_ID, (string) $root->children('saml', true)->Issuer);
     $this->assertEquals('https://localhost/lightsaml/lightSAML-IDP/web/idp/login.php', $root['Destination']);
 }
Beispiel #30
0
 /**
  * replace global parameters in config section
  * @param \SimpleXMLElement $pSection
  * @return \SimpleXMLElement
  */
 public static function replaceGlobalParams(\SimpleXMLElement $pSimpleXml)
 {
     $pSimpleXml->registerXPathNamespace('savant', 'http://localhost/savant');
     print_r($pSimpleXml->xpath('//savant:var'));
     /*$myConf = self::getClassConfig(__CLASS__,  CBootstrap::$EXECUTE_STATE);
       if(!self::hasChilds($myConf))
       {
           return;
       }
       else
       {
           foreach($myConf as $var => $val)
           {
               $pSection = \str_replace('<'.$var.'/>', eval('return '.$val.';'), $pSection);
           }
       }
       return $pSection;*/
 }