コード例 #1
0
ファイル: search.php プロジェクト: ssunkari/mapshup
function toGeoJSON($resultFileURI)
{
    $doc = new DOMDocument();
    /*
     * Load error => return an empty GeoJSON
     */
    if (@$doc->load($resultFileURI) === false) {
        $geojson = array('type' => 'FeatureCollection', 'features' => array());
        return json_encode($geojson);
    }
    $entries = $doc->getElementsByTagname('entry');
    /*
     * No SearchResult => return an empty GeoJSON
     */
    if ($entries->item(0) == null) {
        /*
         * GeoJSON
         */
        $geojson = array('type' => 'FeatureCollection', 'features' => array());
        return json_encode($geojson);
    }
    /*
     * GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'features' => array());
    foreach ($entries as $entry) {
        /**
         * Add feature
         */
        $feature = array('type' => 'Feature', 'geometry' => pointToGeoJSONGeometry($entry->getElementsByTagname('lng')->item(0)->nodeValue, $entry->getElementsByTagname('lat')->item(0)->nodeValue), 'properties' => array('name' => $entry->getElementsByTagname('title')->item(0)->nodeValue, 'description' => $entry->getElementsByTagname('summary')->item(0)->nodeValue, 'url' => $entry->getElementsByTagname('wikipediaUrl')->item(0)->nodeValue, 'img_url' => $entry->getElementsByTagname('thumbnailImg')->item(0)->nodeValue));
        // Add feature array to feature collection array
        array_push($geojson['features'], $feature);
    }
    return json_encode($geojson);
}
コード例 #2
0
ファイル: games.php プロジェクト: Largin/TwineDoodler
 public function openGame($idx)
 {
     $file = $this->games[$idx]['name'];
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = true;
     $doc->formatOutput = true;
     // modify state
     $libxml_previous_state = libxml_use_internal_errors(true);
     // parse
     $doc->loadHTMLFile("Games/" . $file);
     // Usuwanie scriptow - bład z tagamiw scripcie
     $domNodeList = $doc->getElementsByTagname('script');
     $domElemsToRemove = array();
     foreach ($domNodeList as $domElement) {
         $domElemsToRemove[] = $domElement;
     }
     foreach ($domElemsToRemove as $domElement) {
         $domElement->parentNode->removeChild($domElement);
     }
     $xpath = new DomXpath($doc);
     // traverse all results
     foreach ($xpath->query('//div[@tiddler]') as $tid) {
         if ($tid->getAttribute('tiddler') != 'checkvars') {
             $this->tiddlers[$tid->getAttribute('tiddler')] = $tid->nodeValue;
         }
     }
     // handle errors
     libxml_clear_errors();
     // restore
     libxml_use_internal_errors($libxml_previous_state);
 }
コード例 #3
0
function outputToGeoJSON($theData)
{
    $doc = new DOMDocument();
    $doc->loadXML($theData);
    /*
     * Get the SearchResults object
     */
    $searchResults = $doc->getElementsByTagname('SearchResults');
    /*
     * No SearchResult => return an error
     */
    if ($searchResults->item(0) == null) {
        /*
         * Send an error
         */
        $geojson = array('error' => array('message' => urldecode($theData)));
        return json_encode($geojson);
    }
    /*
     * GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'totalResults' => $searchResults->item(0)->getAttribute('numberOfRecordsMatched'), 'features' => array());
    $dataObjects = $doc->getElementsByTagname('Record');
    $array = array("\r\n", "\n\r", "\n", "\r");
    foreach ($dataObjects as $dataObject) {
        /*
         * Footprint is processed from LowerCorner / UpperCorner properties
         * Order is Longitude Latitude
         * If no footprint is found, skip the data
         */
        if ($dataObject->getElementsByTagName('LowerCorner')->length > 0 && $dataObject->getElementsByTagName('UpperCorner')->length > 0) {
            $lowerCorner = explode(' ', $dataObject->getElementsByTagName('LowerCorner')->item(0)->nodeValue);
            $upperCorner = explode(' ', $dataObject->getElementsByTagName('UpperCorner')->item(0)->nodeValue);
            /*
             * Bug from INSPIRE catalog ?
             * Be sure that lowerCorner is lower right and not lower left
             */
            $lonmin = min(floatval($lowerCorner[0]), floatval($upperCorner[0]));
            $lonmax = max(floatval($lowerCorner[0]), floatval($upperCorner[0]));
            $latmin = min(floatval($lowerCorner[1]), floatval($upperCorner[1]));
            $latmax = max(floatval($lowerCorner[1]), floatval($upperCorner[1]));
        } else {
            /**
             * Footprint is null => skip data
             */
            continue;
        }
        /** Skip whole earth dataset */
        if ($lonmin == -180 && $lonmax == 180 && $latmin == -90 && $latmax == 90) {
            continue;
        }
        /**
         * Add feature
         */
        $feature = array('type' => 'Feature', 'geometry' => bboxToGeoJSONGeometry($lonmin, $latmin, $lonmax, $latmax), 'properties' => array('identifier' => $dataObject->getElementsByTagName('identifier')->length > 0 ? $dataObject->getElementsByTagName('identifier')->item(0)->nodeValue : "", 'modified' => $dataObject->getElementsByTagName('modified')->length > 0 ? $dataObject->getElementsByTagName('modified')->item(0)->nodeValue : "", 'title' => $dataObject->getElementsByTagName('title')->length > 0 ? $dataObject->getElementsByTagName('title')->item(0)->nodeValue : "", 'type' => $dataObject->getElementsByTagName('type')->length > 0 ? $dataObject->getElementsByTagName('type')->item(0)->nodeValue : "", 'subject' => $dataObject->getElementsByTagName('subject')->length > 0 ? $dataObject->getElementsByTagName('subject')->item(0)->nodeValue : "", 'format' => $dataObject->getElementsByTagName('format')->length > 0 ? $dataObject->getElementsByTagName('format')->item(0)->nodeValue : "", 'creator' => $dataObject->getElementsByTagName('creator')->length > 0 ? $dataObject->getElementsByTagName('creator')->item(0)->nodeValue : "", 'publisher' => $dataObject->getElementsByTagName('publisher')->length > 0 ? $dataObject->getElementsByTagName('publisher')->item(0)->nodeValue : "", 'abstract' => str_replace($array, "", $dataObject->getElementsByTagName('abstract')->length > 0 ? $dataObject->getElementsByTagName('abstract')->item(0)->nodeValue : ""), 'language' => $dataObject->getElementsByTagName('language')->length > 0 ? $dataObject->getElementsByTagName('language')->item(0)->nodeValue : "", 'thumbnail' => "", 'quicklook' => ""));
        // Add feature array to feature collection array
        array_push($geojson['features'], $feature);
    }
    return json_encode($geojson);
}
コード例 #4
0
ファイル: DocumenttypeParser.php プロジェクト: alexukua/opus4
 /**
  * Parsing the XML Doumenttype for elements named "field"!
  * Allocates the member variables currentElement, formElements.
  * Parses "field" for existing attributes, subfields and subelements like "default" and "required-if-fulltext".
  * At the end each found element is transformed to Zend_Element and stored in array.
  */
 public function parse()
 {
     //parse root node for tags named 'field'
     foreach ($this->dom->getElementsByTagname('field') as $field) {
         $currentElement = new Publish_Model_FormElement($this->form);
         $currentElement->setAdditionalFields($this->additionalFields);
         $this->_parseAttributes($field, $currentElement);
         $this->_parseSubFields($field, $currentElement);
         $this->_parseDefaultEntry($currentElement, $field);
         $this->_parseRequiredIfFulltext($field, $currentElement);
         $currentElement->setPostValues($this->postValues);
         $group = $currentElement->initGroup();
         $this->formElements[] = $group;
         if (!isset($group)) {
             $element = $currentElement->transform();
             $this->formElements[] = $element;
         }
     }
 }
コード例 #5
0
ファイル: template.php プロジェクト: kveldalf/prometheus
function atlas_preprocess_menu_tree(&$variables)
{
    $tree = new DOMDocument();
    @$tree->loadHTML($variables['tree']);
    $links = $tree->getElementsByTagname('li');
    $parent = '';
    foreach ($links as $link) {
        $parent = $link->getAttribute('data-menu-parent');
        break;
    }
    $variables['menu_parent'] = $parent;
}
コード例 #6
0
ファイル: Helper.php プロジェクト: bellodox/jsolr
 public static function getTags(&$article, $tags)
 {
     $dom = new DOMDocument();
     $dom->preserveWhiteSpace = false;
     @$dom->loadHTML(strip_tags($article->summary . " " . $article->body, implode("", $tags)));
     $text = array();
     foreach ($tags as $tag) {
         $content = $dom->getElementsByTagname(str_replace(array('<', '>'), '', $tag));
         foreach ($content as $item) {
             $text[] = $item->nodeValue;
         }
     }
     return $text;
 }
コード例 #7
0
ファイル: api.php プロジェクト: vahizan/ArgosTask
 function get_xml_values()
 {
     //echo "In Get_XML_VALUES";
     $url = 'http://api.hotukdeals.com/rest_api/v2/?key=a253c459cfb0f079712de5f2ec54df03&merchant=argos&online_offline=online&order=hot&forum=deals&results_per_page=30';
     $const_string = array('title', 'deal_link', 'deal_image', 'description', 'submit_time', 'temperature', 'price', 'expired');
     $arr = array();
     try {
         $dom = new DOMDocument(1.0);
         $file = file_get_contents($url);
         $dom->loadXML($file);
         //Obtains all the necessary details from Hot UK deals
         $api_response = $dom->getElementsByTagname('api_response');
         //echo ($api_response->item(0)->hasChildNodes());
         if ($api_response->item(0)->hasChildNodes()) {
             $deal_node = $api_response->item(0)->getElementsByTagname('deals')->item(0);
             //echo '\n'.$deal_node->nodeName;
             if ($deal_node->hasChildNodes()) {
                 $count = get_node_count($deal_node);
                 //echo $count;
                 //$incr =0;
                 //echo '<\br>'.$deal_node->childNodes->item(0)->nodeName;
                 foreach ($deal_node->childNodes as $values) {
                     $item_array = array();
                     //deal_node is <deals>
                     //children of deal_node are <api_item>'s
                     foreach ($values->childNodes as $item) {
                         //Loop through each node/element/item in <api_items>
                         for ($i = 0; $i < count($const_string); $i++) {
                             if (strcmp($item->nodeName, $const_string[$i]) == 0) {
                                 if (strcmp($const_string[$i], 'deal_image') == 0) {
                                     $item_array[$const_string[$i]] = $item->nodeValue;
                                     $result = array();
                                     $image_id = preg_match_all("/[\\d-_]+/", $item_array[$const_string[$i]], $result);
                                     //$image_id = preg_match_all("/((?:[Tt]hreads\/)([\w\d-_]+))/", $item_array[$const_string[$i]], $result);
                                     $item_array['link'] = "http://www.hotukdeals.com/visit?m=5&q=" . $result[0][0] . ".jpg";
                                 }
                                 $item_array[$const_string[$i]] = $item->nodeValue;
                                 break;
                             }
                         }
                     }
                     $arr[] = $item_array;
                 }
             }
         }
     } catch (exception $e) {
         echo 'Exception Message: ', $e->getMessage(), '\\n';
     }
     return $arr;
 }
コード例 #8
0
ファイル: code.php プロジェクト: plepe/OpenStreetBrowser
function search($param) {
  $ret=array();
  $search_str=$param['value'];
  $add_param=array();

  $search_str=urlencode($search_str);
  $add_param[]="q=$search_str";

  if($param['shown'])
    $add_param[]="exclude_place_ids={$param['shown']}";

  if($param['viewbox'])
    $add_param[]="viewbox={$param['viewbox']}";

  $add_param[]="format=xml";

  $res=file_get_contents("http://nominatim.openstreetmap.org/search?".
                         implode("&", $add_param));

  $resdom=new DOMDocument();
  $resdom->loadXML($res);

  $obl=$resdom->getElementsByTagname("place");
  for($i=0; $i<$obl->length; $i++) {
    $ob=$obl->item($i);

    $type=$ob->getAttribute("osm_type");
    if($type=="relation")
      $type="rel";
    $id=$ob->getAttribute("osm_id");

    $nominatim_id=$ob->getAttribute("place_id");

    $ret_ob=array(
      'osm_id'   =>"{$type}_{$id}",
      'osm_tags' =>array(),
    );

    $ret_ob['osm_tags']['name']=$ob->getAttribute("display_name");
    $ret_ob['osm_tags']['nominatim_id']=$nominatim_id;
    $ret_ob['osm_tags']['lat']=$ob->getAttribute("lat");
    $ret_ob['osm_tags']['lon']=$ob->getAttribute("lon");

    $ret[]=$ret_ob;
  }

  return $ret;
}
コード例 #9
0
/**
 * Get first link from the post content
 */
function knacc_get_content_link()
{
    $dom = new DOMDocument();
    $dom->loadHTML(apply_filters('the_content', get_the_content('')));
    $link = $dom->getElementsByTagname('a');
    if ($link->item(0)) {
        foreach ($link->item(0)->attributes as $attribute) {
            if ($attribute->name == 'href') {
                $link = $attribute->value;
            }
        }
        return $link;
    } else {
        return false;
    }
}
コード例 #10
0
ファイル: relink.php プロジェクト: mybo/com_lts
 /**
  * Scan the component directory and get some useful info
  * @return type 
  */
 private function _scanComponent()
 {
     $path = $this->_root . '/component';
     // Find the XML files
     foreach (new DirectoryIterator($path) as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         if (!$fileInfo->isFile()) {
             continue;
         }
         $fname = $fileInfo->getFilename();
         if (substr($fname, -4) != '.xml') {
             continue;
         }
         $xmlDoc = new DOMDocument();
         $xmlDoc->load($path . '/' . $fname, LIBXML_NOBLANKS | LIBXML_NOCDATA | LIBXML_NOENT | LIBXML_NONET);
         $rootNodes = $xmlDoc->getElementsByTagname('install');
         $altRootNodes = $xmlDoc->getElementsByTagname('extension');
         if ($altRootNodes->length >= 1) {
             unset($rootNodes);
             $rootNodes = $altRootNodes;
         }
         if ($rootNodes->length < 1) {
             unset($xmlDoc);
             continue;
         }
         $root = $rootNodes->item(0);
         if (!$root->hasAttributes()) {
             unset($xmlDoc);
             continue;
         }
         if ($root->getAttribute('type') != 'component') {
             unset($xmlDoc);
             continue;
         }
         // Get the component name
         $component = strtolower($xmlDoc->getElementsByTagName('name')->item(0)->textContent);
         if (substr($component, 0, 4) != 'com_') {
             $component = 'com_' . $component;
         }
         // Get the <files> tags for front and back-end
         $siteFolder = $path;
         $allFilesTags = $xmlDoc->getElementsByTagName('files');
         $nodePath0 = $allFilesTags->item(0)->getNodePath();
         $nodePath1 = $allFilesTags->item(1)->getNodePath();
         if (in_array($nodePath0, array('/install/files', '/extension/files'))) {
             $siteFilesTag = $allFilesTags->item(0);
             $adminFilesTag = $allFilesTags->item(1);
         } else {
             $siteFilesTag = $allFilesTags->item(1);
             $adminFilesTag = $allFilesTags->item(0);
         }
         // Get the site and admin folders
         if ($siteFilesTag->hasAttribute('folder')) {
             $siteFolder = $path . '/' . $siteFilesTag->getAttribute('folder');
         }
         if ($adminFilesTag->hasAttribute('folder')) {
             $adminFolder = $path . '/' . $adminFilesTag->getAttribute('folder');
         }
         // Get the media folder
         $mediaFolder = null;
         $allMediaTags = $xmlDoc->getElementsByTagName('media');
         if ($allMediaTags->length >= 1) {
             $mediaFolder = $path . '/' . $allMediaTags->item(0)->getAttribute('folder');
         }
         // Do we have a CLI folder
         $cliFolder = $path . '/cli';
         if (!is_dir($cliFolder)) {
             $cliFolder = '';
         }
         // Get the <languages> tags for front and back-end
         $langFolderSite = $path;
         $langFolderAdmin = $path;
         $allLanguagesTags = $xmlDoc->getElementsByTagName('languages');
         $nodePath0 = $allLanguagesTags->item(0)->getNodePath();
         $nodePath1 = $allLanguagesTags->item(1)->getNodePath();
         if (in_array($nodePath0, array('/install/languages', '/extension/languages'))) {
             $siteLanguagesTag = $allLanguagesTags->item(0);
             $adminLanguagesTag = $allLanguagesTags->item(1);
         } else {
             $siteLanguagesTag = $allLanguagesTags->item(1);
             $adminLanguagesTag = $allLanguagesTags->item(0);
         }
         // Get the site and admin language folders
         if ($siteLanguagesTag->hasAttribute('folder')) {
             $langFolderSite = $path . '/' . $siteLanguagesTag->getAttribute('folder');
         }
         if ($adminLanguagesTag->hasAttribute('folder')) {
             $langFolderAdmin = $path . '/' . $adminLanguagesTag->getAttribute('folder');
         }
         // Get the frontend languages
         $langFilesSite = array();
         if ($siteLanguagesTag->hasChildNodes()) {
             foreach ($siteLanguagesTag->childNodes as $langFile) {
                 if (!$langFile instanceof DOMElement) {
                     continue;
                 }
                 $tag = $langFile->getAttribute('tag');
                 $langFilesSite[$tag][] = $langFolderSite . '/' . $langFile->textContent;
             }
         }
         // Get the backend languages
         $langFilesAdmin = array();
         if ($adminLanguagesTag->hasChildNodes()) {
             foreach ($adminLanguagesTag->childNodes as $langFile) {
                 if (!$langFile instanceof DOMElement) {
                     continue;
                 }
                 $tag = $langFile->getAttribute('tag');
                 $langFilesAdmin[$tag][] = $langFolderAdmin . '/' . $langFile->textContent;
             }
         }
         if (empty($component)) {
             unset($xmlDoc);
             continue;
         }
         $this->_component = array('component' => $component, 'siteFolder' => $siteFolder, 'adminFolder' => $adminFolder, 'mediaFolder' => $mediaFolder, 'cliFolder' => $cliFolder, 'siteLangPath' => $langFolderSite, 'siteLangFiles' => $langFilesSite, 'adminLangPath' => $langFolderAdmin, 'adminLangFiles' => $langFilesAdmin);
         unset($xmlDoc);
         return;
     }
 }
コード例 #11
0
ファイル: ingest.php プロジェクト: ssunkari/mapshup
    echo "\n    Usage : " . $_SERVER['argv'][0] . " path_to_product.xml" . "\n\n";
    exit;
}
/*
 * Input xml product must exist
 */
if (!file_exists($file)) {
    echo "\n    ERROR : " . $file . " does not exists" . "\n\n";
    exit;
}
/*
 * Input xml product descriptor must exist and be a valid XML document
 */
$doc = new DOMDocument();
$doc->load($file);
if ($doc->getElementsByTagname('OTBProduct')->item(0) == NULL) {
    echo "\n    ERROR : " . $file . " is not a valid jeotb product descriptor" . "\n\n";
    exit;
}
/**
 * Database connection
 */
$dbh = pg_connect("host=localhost dbname=jeotb user=otb password=otb00") or die("Database connection error");
/**
 * Insert new entry within logger table
 * and return newly created astext(center) within
 * the $result variable
 */
$fields = "(identifier,acquisition,archive,creation,description,location,metadata,title,type,wms_layer,wms_url,footprint)";
$values = "'" . pg_escape_string($doc->getElementsByTagName('identifier')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('acquisition')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('archive')->item(0)->nodeValue) . "','" . date('Y-m-d\\TH:i:s\\Z', $_SERVER["REQUEST_TIME"]) . "','" . pg_escape_string($doc->getElementsByTagName('description')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('town')->item(0)->nodeValue) . ", " . $doc->getElementsByTagName('country')->item(0)->nodeValue . "','" . pg_escape_string($doc->getElementsByTagName('metadata')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('title')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('type')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('layer')->item(0)->nodeValue) . "','" . pg_escape_string($doc->getElementsByTagName('url')->item(0)->nodeValue) . "'," . "GeomFromText('" . $doc->getElementsByTagName('footprint')->item(0)->nodeValue . "',4326)";
$query = "INSERT INTO products " . $fields . " VALUES (" . $values . ")";
コード例 #12
0
ファイル: addlink.php プロジェクト: johannes/linkblog
    if (!empty($_GET['tags'])) {
        $tags = explode(',', $_GET['tags']);
    }
}
error_reporting(E_ALL);
$filename = 'feed.xml';
$dom = new DOMDocument();
$dom->formatOutput = true;
$dom->load($filename);
$xpath = new DOMXPath($dom);
$xpath->registerNamespace('foo', 'http://www.w3.org/2005/Atom');
$entries = $xpath->query('//foo:entry/foo:id[. = "' . $url . '"]/..');
if ($entries->length != 0) {
    die("URL already added.");
}
$dom->getElementsByTagname('updated')->item(0)->nodeValue = date(DateTime::RFC3339);
$first_entry = $dom->getElementsByTagname('entry')->item(0);
$new_entry = new AtomEntryNode($dom);
$new_entry->setFromURL($url);
$dom->documentElement->insertBefore($new_entry->get(), $first_entry);
$dom->save($filename);
const SILENT = 1;
include './create.index.php';
#header('Location: ./');
################
class AtomEntryNode
{
    protected $dom;
    protected $content = null;
    protected $inner;
    public function __construct(DOMDocument $dom)
コード例 #13
0
ファイル: plugins.php プロジェクト: cbsistem/nexos
$xml = BASEDIR . 'cache/plugins_xml.php';
if (file_exists($xml)) {
    $xmllastmod = filemtime($xml);
}
$xml = get_fileinfo('http://dragonflycms.org/plugins.php', false, true, $xmllastmod);
if ($xml['modified'] === true) {
    Cache::array_save('xml', 'plugins', $xml);
} else {
    Cache::array_load('xml', 'plugins', true);
}
//$xml['data'] = decode_bb_all($xml['data'], 0 , true);
$xmlDOM = new DOMDocument();
$xmlDOM->preserveWhiteSpace = false;
$xmlDOM->loadXML($xml['data']);
$data = array();
$items = $xmlDOM->getElementsByTagname('item');
foreach ($items as $item) {
    $tmp = array();
    $nodes = $item->childNodes;
    for ($n = 0; $n < $nodes->length; ++$n) {
        $tmp[$nodes->item($n)->nodeName] = $nodes->item($n)->nodeValue;
    }
    $data[$item->parentNode->nodeName][] = $tmp;
}
unset($xmlDOM, $xml, $items, $item, $nodes, $tmp);
function array_key_prefix(&$array, $prefix)
{
    $ret = array();
    foreach ($array as $key => $value) {
        $ret[$prefix . $key] = $value;
        array_shift($array);
コード例 #14
0
ファイル: ViewReview.php プロジェクト: Tjorriemorrie/app
 /**
  * Highlighter method for PHP source code
  *
  * The source code is highlighted by PHP native method.
  * Afterwords a DOMDocument will be generated with each
  * line in a seperate node.
  *
  * @param String $sourceCode The PHP source code
  *
  * @return DOMDocument
  */
 protected function _highlightPhpCode($sourceCode)
 {
     $code = highlight_string($sourceCode, true);
     $sourceDom = new DOMDocument();
     $sourceDom->loadHTML($code);
     //fetch <code>-><span>->children from php generated html
     $sourceElements = $sourceDom->getElementsByTagname('code')->item(0)->childNodes->item(0)->childNodes;
     //create target dom
     $targetDom = new DOMDocument();
     $targetNode = $targetDom->createElement('ol');
     $targetNode->setAttribute('class', 'code');
     $targetDom->appendChild($targetNode);
     $li = $targetDom->createElement('li');
     $targetNode->appendChild($li);
     // iterate through all <span> elements
     foreach ($sourceElements as $sourceElement) {
         if (!$sourceElement instanceof DOMElement) {
             $span = $targetDom->createElement('span');
             $span->nodeValue = htmlspecialchars($sourceElement->wholeText);
             $li->appendChild($span);
             continue;
         }
         if ('br' === $sourceElement->tagName) {
             // create new li and new line
             $li = $targetDom->createElement('li');
             $targetNode->appendChild($li);
             continue;
         }
         $elementClass = $this->_mapPhpColors($sourceElement->getAttribute('style'));
         foreach ($sourceElement->childNodes as $sourceChildElement) {
             if ($sourceChildElement instanceof DOMElement && 'br' === $sourceChildElement->tagName) {
                 // create new li and new line
                 $li = $targetDom->createElement('li');
                 $targetNode->appendChild($li);
             } else {
                 // apend content to current li element
                 // apend content to urrent li element
                 $span = $targetDom->createElement('span');
                 $span->nodeValue = htmlspecialchars($sourceChildElement->wholeText);
                 $span->setAttribute('class', $elementClass);
                 $li->appendChild($span);
             }
         }
     }
     return $targetDom;
 }
コード例 #15
0
#!/usr/bin/php
<?
$sql=pg_connect("dbname=gis");// user=www password=cityrunner host=localhost");

$dom=new DOMDocument();
$dom->load("/osm/skunkosm/render/overlay_ch.xml");

//$box=array(1823787.494884305,6138504.867525934,1825010.487336868,6139727.859978498);
$box=array(1813797.75987783, 6130153.02441634, 1834395.04941202, 6151816.81425115);

$layers=$dom->getElementsByTagname("Layer");
foreach($layers as $l) {
  print "* Layer, class ".$l->getAttribute("name")."\n";
  $params=$l->getElementsByTagname("Parameter");
  foreach($params as $p) {
    if($p->getAttribute("name")=="table") {
      $time=time();
      $res=pg_query("select * from {$p->firstChild->data} where way && setSRID('BOX3D($box[0] $box[1],$box[2] $box[3])'::box3d,900913)");
      print "Time: ".(time()-$time)."s\n";
      print "Rows: ".pg_num_rows($res)."\n";
    }
  }
}
コード例 #16
0
ファイル: functions.php プロジェクト: ORNChurch/ornchurch.org
function get_blockquote()
{
    $dom = new DOMDocument();
    $dom->loadHTML(apply_filters('the_content', get_the_content('')));
    $blockquotes = $dom->getElementsByTagname('blockquote');
    if ($blockquotes->length > 0) {
        // First blockquote
        $blockquote = $blockquotes->item(0);
        $cite = $blockquote->getElementsByTagName('cite')->item(0);
        $p = $blockquote->getElementsByTagName('p');
        $cite_content = '';
        if ($cite && $p) {
            // Remove the cite from the paragraph
            foreach ($p as $paragraph) {
                try {
                    $paragraph->removeChild($cite);
                } catch (Exception $e) {
                }
            }
            $cite_content = $dom->saveXML($cite);
        }
        $blockquote_content = '';
        foreach ($p as $paragraph) {
            if (strlen(trim($paragraph->nodeValue)) > 0) {
                $blockquote_content .= $dom->saveXML($paragraph);
            } else {
                $paragraph->parentNode->removeChild($paragraph);
            }
            $blockquote->parentNode->removeChild($blockquote);
            $remaining_content = $dom->saveXML();
        }
        return $blockquote_content;
        // $cite_content or $remaining_content
    }
}
コード例 #17
0
ファイル: parse.php プロジェクト: xiaobudongzhang/lib
<?php

$sx = simplexml_load_file('./test.xml');
//print_r($sx->title);
foreach ($sx as $y) {
    //print($y->nodeValue);
    //print_r($y->nodeType);
    //print_r($y->__toString());
}
$dom = new DOMDocument();
$dom->load('./test.xml');
foreach ($dom->getElementsByTagname('title') as $title) {
    print_r($title->nodeValue);
}
コード例 #18
0
ファイル: getActivations.php プロジェクト: ssunkari/mapshup
function xmlToGeoJSON($theData)
{
    $doc = new DOMDocument();
    $doc->loadXML($theData);
    /*
     * Initialiaze GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'totalResults' => 0, 'features' => array());
    /*
     * Number of objects returned
     */
    $disasters = $doc->getElementsByTagname('disaster');
    if ($disasters->item(0) == null) {
        return json_encode($geojson);
    }
    $count = 0;
    /*
     * Process all RegistryPackages
     */
    foreach ($disasters as $disaster) {
        // Get longitude and latitude coordinates
        $lonlat = explode(" ", $disaster->getElementsByTagname('pos')->item(0)->nodeValue);
        /*
         * Automatic correction of incorrect disasters
         * 
         * Possible values
         *  EARTHQUAKE
         *  FLOOD
         *  FIRE
         *  ICE
         *  LANDSLIDE
         *  OCEAN_STORM (CYCLONE, HURRICANE, TYPHOON)
         *  OIL_SPILL
         *  OCEAN_WAVE (TSUNAMI)
         *  VOLCANIC_ERUPTION
         *  OTHER (INDUSTRIAL_ACCIDENT, WIND_STORM, TORNADO...)
         * 
         */
        $title = $disaster->getElementsByTagname('title')->item(0)->nodeValue;
        $type = $disaster->getElementsByTagname('type')->item(0)->nodeValue;
        if ($type == "OTHER") {
            /*
             * Check for disaster type within title
             * Hypothesis is that disaster type is the first word within the title
             */
            $words = explode(' ', $title);
            foreach ($words as $word) {
                $word = strtolower(str_replace(",", "", trim($word)));
                if (in_array($word, array('flood', 'flooding', 'floods'))) {
                    $type = 'FLOOD';
                    break;
                } else {
                    if (in_array($word, array('ocean', 'tsunami', 'huricane', 'hurricane-force'))) {
                        $type = 'CYCLONE';
                        break;
                    } else {
                        if (in_array($word, array('landslide', 'landslides'))) {
                            $type = 'LANDSLIDE';
                            break;
                        } else {
                            if (in_array($word, array('earthquake'))) {
                                $type = 'EARTHQUAKE';
                                break;
                            }
                        }
                    }
                }
                /*
                                else if (in_array($first, ['snow','ice'])) {
                                    $type = '';
                                    break;
                                }
                                else if (in_array($first, ['debris'])) {
                                    $type = '';
                                    break;
                                }*/
            }
        }
        /*
         * Add feature array to feature collection array
         */
        array_push($geojson['features'], array('type' => 'Feature', 'geometry' => pointToGeoJSONGeometry(floatval($lonlat[1]), floatval($lonlat[0])), 'properties' => array('title' => $title, 'date' => $disaster->getElementsByTagname('date')->item(0)->nodeValue, 'call-id' => $disaster->getElementsByTagname('call-id')->item(0)->nodeValue, 'type' => $type, 'description' => $disaster->getElementsByTagname('description')->item(0)->nodeValue, 'link' => $disaster->getElementsByTagname('link')->item(0)->nodeValue)));
        $count++;
    }
    // Update totalResults
    $geojson["totalResults"] = $count;
    return json_encode($geojson);
}
コード例 #19
0
ファイル: search.php プロジェクト: ssunkari/mapshup
function toGeoJSON($resultFileURI)
{
    $doc = new DOMDocument();
    /*
     * Load error => return an empty GeoJSON
     */
    if (@$doc->load($resultFileURI) === false) {
        $geojson = array('type' => 'FeatureCollection', 'features' => array());
        return json_encode($geojson);
    }
    $entries = $doc->getElementsByTagname('entry');
    /*
     * No SearchResult => return an empty GeoJSON
     */
    if ($entries->item(0) == null) {
        $geojson = array('type' => 'FeatureCollection', 'features' => array());
        return json_encode($geojson);
    }
    /*
     * GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'features' => array());
    foreach ($entries as $entry) {
        $pos = $entry->getElementsByTagName('pos')->item(0)->nodeValue;
        if ($pos) {
            /**
             * Order of $coord = lat,lon
             */
            $coords = explode(" ", $pos);
            /**
             * Add feature
             */
            $feature = array('type' => 'Feature', 'geometry' => pointToGeoJSONGeometry($coords[1], $coords[0]), 'properties' => array('name' => $entry->getElementsByTagName('title')->item(0)->nodeValue, 'description' => $entry->getElementsByTagName('description')->item(0)->nodeValue, 'url' => $entry->getElementsByTagName('player')->item(0)->getAttribute('url'), 'thumbnail' => $entry->getElementsByTagName('thumbnail')->item(0)->getAttribute('url')));
            // Add feature array to feature collection array
            array_push($geojson['features'], $feature);
        }
    }
    return json_encode($geojson);
}
コード例 #20
0
ファイル: search.php プロジェクト: ssunkari/mapshup
 *      <ra>10.68469</ra>
 *      <dec>41.26904</dec>
 *      <time>524</time>
 *  </result>
 * 
 */
$doc = new DOMDocument();
if ($doc->loadXML(getRemoteData($url, null, false))) {
    /*
     * Initialiaze GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'features' => array());
    /*
     * Parse result and populate geojson result
     */
    $result = $doc->getElementsByTagname('result')->item(0);
    if ($result != null) {
        $ra = $result->getElementsByTagname('ra')->item(0)->nodeValue;
        $dec = $result->getElementsByTagname('dec')->item(0)->nodeValue;
        /*
         * Only exploitable results are processed
         */
        if ($ra && $dec) {
            /*
             * Galactic to Equatorial coordinates transformation
             */
            $pos = array($ra, $dec);
            if ($r === "e") {
                /* Important : see geometry.php */
                $pos = spheric2proj($pos);
            } else {
コード例 #21
0
ファイル: oai_harvest.php プロジェクト: horaciod/oai_harvest
function writexml($dom, $url)
{
    global $arrArgs, $arrArgs2, $targetdir, $logHandle, $errorhandle;
    echo 'writexml for ' . $url . "\n";
    if ($arrArgs['verb'] == 'ListRecords') {
        $recordList = $dom->getElementsByTagname('record');
        echo 'writexml: record list: ' . $recordList->length . " elements\n";
        if (!$recordList->length) {
            message('no records found for ' . $url, true);
            return;
        }
        foreach ($recordList as $record) {
            // create new file
            $oaiID = $record->getElementsByTagname('identifier')->item(0)->nodeValue;
            $fileName = strtr(trim($oaiID), '/:', '_-');
            $i = 0;
            $theSets = array();
            while ($newSet = $record->getElementsByTagname('setSpec')->item($i)) {
                array_push($theSets, $newSet->nodeValue);
                $i++;
            }
            $theFileName = getFolder($theSets);
            $theFileName .= $fileName . '.xml';
            echo 'New file: ' . $theFileName . "\n";
            if (is_file($theFileName)) {
                continue;
            }
            printMetadata($record, $theFileName, $oaiID);
            unset($theFileName);
            unset($oaiID);
        }
        return;
    }
    if ($arrArgs['verb'] == 'ListIdentifiers') {
        $idList = $dom->getElementsByTagname('identifier');
        if (!$idList->length) {
            return;
        }
        $urlBase = $arrArgs['oaiURL'] . '?verb=GetRecord&metadataPrefix=' . $arrArgs2['metadataPrefix'] . '&identifier=';
        foreach ($idList as $id) {
            $theFileName = $targetdir . strtr(trim($id->nodeValue), '/:', '_-') . '.xml';
            if (is_file($theFileName)) {
                continue;
            }
            $recordxml = getXML($urlBase . trim($id->nodeValue));
            $record = new DOMDocument();
            $record->loadXML($recordxml);
            $metadataList = $record->getElementsByTagname('metadata');
            if ($metadataList->length) {
                $metadata = $metadataList->item(0);
                printMetadata($metadata, $theFileName, $id->nodeValue);
                unset($metadata);
            } else {
                message('no record found ' . $id->nodeValue, true);
            }
        }
    }
}
コード例 #22
0
 public function parseMultiXML($xml, $ccnum)
 {
     if ($this->getDebug()) {
         $writer = new Zend_Log_Writer_Stream($this->getLogPath());
         $logger = new Zend_Log($writer);
         $logger->info("MultiParseXML...");
     }
     $ccnum = 'XXXX' . substr($ccnum, -4, 4);
     $pos = strpos($xml, "<?xml version=");
     $fixedXML = substr($xml, $pos);
     $fixedXML = preg_replace('/xmlns="(.+?)"/', '', $fixedXML);
     $dom = new DOMDocument();
     $dom->loadXML($fixedXML);
     //print_r($dom);
     $profileID = array();
     $CardNo = array();
     $ProfileIDs = $dom->getElementsByTagname('customerPaymentProfileId');
     $index = 0;
     foreach ($ProfileIDs as $Profile) {
         $value = $Profile->nodeValue;
         $profileID[] = $value;
         $index++;
     }
     //print_r($profileID);
     $Cards = $dom->getElementsByTagname('cardNumber');
     foreach ($Cards as $Card) {
         $value = $Card->nodeValue;
         $CardNo[] = $value;
     }
     //print_r($CardNo);
     for ($iindex = 0; $iindex < $index; $iindex++) {
         if ($this->getDebug()) {
             $logger->info(" Payment: " . $profileID[$iindex]);
             $logger->info(" Card Number: " . $CardNo[$iindex]);
         }
         if ($CardNo[$iindex] == $ccnum) {
             $returnvalue = $profileID[$iindex];
             break;
         }
         $returnvalue = $profileID[0];
     }
     return $returnvalue;
 }
コード例 #23
0
ファイル: search.php プロジェクト: ssunkari/mapshup
function outputToGeoJSON($theData, $nbOfResults)
{
    // Load the GetFeature result document
    $doc = new DOMDocument();
    $doc->loadXML($theData);
    /*
     * Initialiaze GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'totalResults' => $nbOfResults, 'features' => array());
    // Check root element
    if ($doc->getElementsByTagname('FeatureCollection')->item(0) === null) {
        /*
         * Send an error
         */
        $geojson = array('error' => array('message' => "Invalid response from server"));
        return json_encode($geojson);
    }
    // Get the DataStrip root element
    $dataObjects = $doc->getElementsByTagname('DataStrip');
    // Roll over each feature
    foreach ($dataObjects as $dataObject) {
        // Initialize empty properties array
        $properties = array();
        $properties["identifier"] = $dataObject->getElementsByTagName('identifier')->item(0)->nodeValue;
        $properties["startDate"] = $dataObject->getElementsByTagName('startDate')->item(0)->nodeValue;
        $properties["completionDate"] = $dataObject->getElementsByTagName('completionDate')->item(0)->nodeValue;
        $properties["acquisitionSubType"] = $dataObject->getElementsByTagName('acquisitionSubType')->item(0)->nodeValue;
        $properties["serialIdentifier"] = $dataObject->getElementsByTagName('serialIdentifier')->item(0)->nodeValue;
        $properties["orbitNumber"] = $dataObject->getElementsByTagName('orbitNumber')->item(0)->nodeValue;
        $properties["cloudCoverPercentage"] = $dataObject->getElementsByTagName('cloudCoverPercentage')->item(0)->nodeValue;
        $properties["archivingCenter"] = $dataObject->getElementsByTagName('archivingCenter')->item(0)->nodeValue;
        $posList = $dataObject->getElementsByTagName('posList')->item(0)->nodeValue;
        // Album, quicklook and thumbnails
        $browses = $dataObject->getElementsByTagName('BrowseInformation');
        foreach ($browses as $browse) {
            $type = $browse->getElementsByTagName('type')->item(0)->nodeValue;
            $properties[strtolower($type)] = $browse->getElementsByTagName('fileName')->item(0)->nodeValue;
        }
        // Masks
        $masks = $dataObject->getElementsByTagName('MaskInformation');
        foreach ($masks as $mask) {
            $type = $mask->getElementsByTagName('type')->item(0)->nodeValue;
            if ($mask->getElementsByTagName('referenceSystemIdentifier')->item(0)->nodeValue === "4326") {
                $properties[strtolower($type)] = $mask->getElementsByTagName('fileName')->item(0)->nodeValue;
            }
        }
        /*
         * Add feature
         */
        $feature = array('type' => 'Feature', 'geometry' => posListToGeoJSONGeometry($posList, LATLON), 'properties' => $properties);
        /*
         * Add feature array to feature collection array
         */
        array_push($geojson['features'], $feature);
    }
    return json_encode($geojson);
}
コード例 #24
0
<?php

$dom = new DOMDocument();
$dom->load(__DIR__ . '/address-book.xml');
foreach ($dom->getElementsByTagname('person') as $person) {
    $firstname = $person->getElementsByTagname('firstname');
    $firstname_text_value = $firstname->item(0)->firstChild->nodeValue;
    $lastname = $person->getElementsByTagname('lastname');
    $lastname_text_value = $lastname->item(0)->firstChild->nodeValue;
    print "{$firstname_text_value} {$lastname_text_value}\n";
}
コード例 #25
0
ファイル: create.index.php プロジェクト: johannes/linkblog
<?php

require_once './helper.php';
$template = new DOMDocument();
$template->loadHTMLFile('template.html');
$feed = new DOMDocument();
$feed->load('feed.xml');
$list = $template->getElementById('linklist');
$i = 0;
foreach ($feed->getElementsByTagname('entry') as $entry) {
    $li = $template->createElement('li');
    $list->appendChild($li);
    createNode($template, $li, $entry, !defined('EDIT') && $i++ < 15);
    if (defined('EDIT')) {
        $tags = '';
        $taglist = $entry->getElementsByTagname('category');
        foreach ($taglist as $tagtag) {
            $tags .= $tagtag->firstChild->nodeValue . ', ';
        }
        $div = $template->createElement('div');
        $form = $template->createElement('form');
        $input = $template->createElement('input');
        $input->setAttribute('style', 'width: 400px');
        $input->setAttribute('value', $tags);
        $form->appendChild($input);
        $div->appendChild($form);
        $li->appendChild($div);
    }
}
$container = $template->getElementById('tagcloud');
$list = $feed->getElementsByTagName('category');
コード例 #26
0
function outputToGeoJSON($theData)
{
    $doc = new DOMDocument();
    $doc->loadXML($theData);
    /*
     * Get the SearchResults object
     */
    $searchResults = $doc->getElementsByTagname('SearchResults');
    /*
     * No SearchResult => return an error
     */
    if ($searchResults->item(0) == null) {
        /*
         * Send an error
         */
        $geojson = array('error' => array('message' => urldecode($theData)));
        return json_encode($geojson);
    }
    /*
     * GeoJSON
     */
    $geojson = array('type' => 'FeatureCollection', 'totalResults' => $searchResults->item(0)->getAttribute('numberOfRecordsMatched'), 'features' => array());
    $dataObjects = $doc->getElementsByTagname('Record');
    $array = array("\r\n", "\n\r", "\n", "\r");
    foreach ($dataObjects as $dataObject) {
        /*
         * Footprint is processed from LowerCorner / UpperCorner properties
         * Order is Longitude Latitude
         * If no footprint is found, skip the data
         */
        if ($dataObject->getElementsByTagName('LowerCorner')->length > 0 && $dataObject->getElementsByTagName('UpperCorner')->length > 0) {
            $lowerCorner = explode(' ', $dataObject->getElementsByTagName('LowerCorner')->item(0)->nodeValue);
            $upperCorner = explode(' ', $dataObject->getElementsByTagName('UpperCorner')->item(0)->nodeValue);
            /*
             * Bug from INSPIRE catalog ?
             * Be sure that lowerCorner is lower left
             */
            $lonmin = min(floatval($lowerCorner[0]), floatval($upperCorner[0]));
            $lonmax = max(floatval($lowerCorner[0]), floatval($upperCorner[0]));
            $latmin = min(floatval($lowerCorner[1]), floatval($upperCorner[1]));
            $latmax = max(floatval($lowerCorner[1]), floatval($upperCorner[1]));
        } else {
            /**
             * Footprint is null => skip data
             */
            continue;
        }
        /* Skip whole earth dataset
           if ($lonmin == -180 && $lonmax == 180 && $latmin == -90 && $latmax == 90) {
               continue;
           }
           */
        /*
         * Subject is a repeatable element
         */
        $subjects = array();
        if ($dataObject->getElementsByTagName('subject')->length > 0) {
            foreach ($dataObject->getElementsByTagName('subject') as $subject) {
                array_push($subjects, $subject->nodeValue);
            }
        }
        /**
         * Add feature
         */
        $feature = array('type' => 'Feature', 'geometry' => bboxToGeoJSONGeometry($lonmin, $latmin, $lonmax, $latmax), 'properties' => array('identifier' => $dataObject->getElementsByTagName('identifier')->length > 0 ? $dataObject->getElementsByTagName('identifier')->item(0)->nodeValue : NULL, 'modified' => $dataObject->getElementsByTagName('modified')->length > 0 ? $dataObject->getElementsByTagName('modified')->item(0)->nodeValue : NULL, 'title' => $dataObject->getElementsByTagName('title')->length > 0 ? $dataObject->getElementsByTagName('title')->item(0)->nodeValue : NULL, 'type' => $dataObject->getElementsByTagName('type')->length > 0 ? $dataObject->getElementsByTagName('type')->item(0)->nodeValue : NULL, 'subject' => $subjects, 'source' => $dataObject->getElementsByTagName('source')->length > 0 ? $dataObject->getElementsByTagName('source')->item(0)->nodeValue : NULL, 'format' => $dataObject->getElementsByTagName('format')->length > 0 ? $dataObject->getElementsByTagName('format')->item(0)->nodeValue : NULL, 'creator' => $dataObject->getElementsByTagName('creator')->length > 0 ? $dataObject->getElementsByTagName('creator')->item(0)->nodeValue : NULL, 'publisher' => $dataObject->getElementsByTagName('publisher')->length > 0 ? $dataObject->getElementsByTagName('publisher')->item(0)->nodeValue : NULL, 'abstract' => str_replace($array, "", $dataObject->getElementsByTagName('abstract')->length > 0 ? $dataObject->getElementsByTagName('abstract')->item(0)->nodeValue : NULL), 'language' => $dataObject->getElementsByTagName('language')->length > 0 ? $dataObject->getElementsByTagName('language')->item(0)->nodeValue : NULL));
        /**
         * This part is specific to CWIC ISO catalog
         */
        $url = null;
        $references = $dataObject->getElementsByTagName('references');
        foreach ($references as $reference) {
            $attr = $reference->getAttribute('scheme');
            if ($attr == "urn:x-cwic:Onlink:MimeType:application/x-hdfeos") {
                $url = $reference->nodeValue;
                if (!isset($feature['properties']['services'])) {
                    $feature['properties']['services'] = array();
                }
                if (!isset($feature['properties']['services']['download'])) {
                    $feature['properties']['services']['download'] = array();
                }
                $feature['properties']['services']['download'] = array('url' => $reference->nodeValue);
            } else {
                if ($attr == "urn:x-cwic:Browse") {
                    $feature['properties']['thumbnail'] = $reference->nodeValue;
                    $feature['properties']['quicklook'] = $reference->nodeValue;
                }
            }
            if (!empty($feature['properties']['thumbnail']) && !empty($url)) {
                break;
            }
        }
        /*
         * This part is specific to I4D ISO catalog (Airbus Defense and Space)
         * 
         * <dc:URI protocol="OGC:WMS" name="products" description="ORT_SPOT6_20140620_101138400_000">...</dc:URI>
         * <dc:URI protocol="CDRDMC" name="">ORT_SPOT6_20140620_101138400_0002015-01-14T15:41:54</dc:URI>
         * <dc:URI protocol="WWW:DOWNLOAD-1.0-http--download" name="ORT_SPOT6_20140620_101138400_000.zip">...</dc:URI>
         * <dc:URI name="thumbnail">...</dc:URI>
         * <dc:URI name="large_thumbnail">...</dc:URI>
         */
        $uris = $dataObject->getElementsByTagName('URI');
        foreach ($uris as $uri) {
            $name = $uri->getAttribute('name');
            $protocol = $uri->getAttribute('protocol');
            if (!empty($name)) {
                if ($name === "thumbnail") {
                    $feature['properties']['thumbnail'] = $uri->nodeValue;
                } else {
                    if ($name === "large_thumbnail") {
                        $feature['properties']['quicklook'] = $uri->nodeValue;
                    }
                }
            }
            if (!empty($protocol)) {
                if ($protocol === "WWW:DOWNLOAD-1.0-http--download") {
                    if (!isset($feature['properties']['services'])) {
                        $feature['properties']['services'] = array();
                    }
                    if (!isset($feature['properties']['services']['download'])) {
                        $feature['properties']['services']['download'] = array();
                    }
                    $feature['properties']['services']['download'] = array('url' => $uri->nodeValue);
                } else {
                    if ($protocol === "OGC:WMS") {
                        if (!isset($feature['properties']['services'])) {
                            $feature['properties']['services'] = array();
                        }
                        if (!isset($feature['properties']['services']['browse'])) {
                            $feature['properties']['services']['browse'] = array();
                        }
                        $feature['properties']['services']['browse'] = array('layer' => array('type' => 'WMS', 'title' => $uri->getAttribute('description'), 'url' => $uri->nodeValue . '?dim_product=' . $uri->getAttribute('description'), 'layers' => 'products'));
                    }
                }
            }
        }
        // Add feature array to feature collection array
        array_push($geojson['features'], $feature);
    }
    return json_encode($geojson);
}
コード例 #27
0
ファイル: uploadExcel.php プロジェクト: abelhii/timeMap
/** If you want to store the file somewhere on the server:
//stores the file somewhere and sets the target path of the timetable
$target_path  = "../../timeMap/excelFiles/" . trim($timetable_name, " "); 

if(move_uploaded_file($timetable_tmp, $target_path)) 
{
    echo "The file ". $timetable_name . " has been uploaded to " . $target_path;
    $_SESSION['timetable']  = $target_path;
}
**/
//initiialise variables:
$timetable = new DOMDocument();
$timetable->preserveWhiteSpace = FALSE;
//$timetable->loadHTMLFile($target_path);
$timetable->loadHTMLFile($timetable_tmp_dir);
$lectures = $timetable->getElementsByTagname('tr');
$lecture = array();
$sem1 = array();
$sem2 = array();
$timetable_arr = array();
$x = 0;
//convert from DOM to array
foreach ($lectures as $tag) {
    $timetable_arr[$x] = $tag->nodeValue;
    ++$x;
}
/*** MAIN PART TO SORT/SPLIT THE TIMETABLE: ***/
//Â == chr(194)
//chr(160) == &nbsp;        chr(93) == ]
//replacing 't' with &nbsp, ']' with ']t' and :00 with :00t to split the string evenly
// so i can get position 1 - 5 when i preg_split to match mon - fri
コード例 #28
0
 /**
  * Highlighter method for PHP source code
  *
  * The source code is highlighted by PHP native method.
  * Afterwords a DOMDocument will be generated with each
  * line in a seperate node.
  *
  * @param String $sourceCode The PHP source code
  *
  * @return DOMDocument
  */
 protected function _highlightPhpCode($sourceCode)
 {
     $code = highlight_string($sourceCode, true);
     if (extension_loaded('mbstring') && !mb_check_encoding($code, 'UTF-8')) {
         $detectOrder = mb_detect_order();
         $detectOrder[] = 'iso-8859-1';
         $encoding = mb_detect_encoding($code, $detectOrder, true);
         if ($encoding === false) {
             error_log('Error detecting file encoding');
         }
         $code = mb_convert_encoding($code, 'UTF-8', $encoding);
     }
     $sourceDom = new DOMDocument();
     $sourceDom->loadHTML('<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>' . $code);
     //fetch <code>-><span>->children from php generated html
     $sourceElements = $sourceDom->getElementsByTagname('code')->item(0)->childNodes->item(0)->childNodes;
     //create target dom
     $targetDom = new DOMDocument();
     $targetNode = $targetDom->createElement('ol');
     $targetNode->setAttribute('class', 'code');
     $targetDom->appendChild($targetNode);
     $li = $targetDom->createElement('li');
     $targetNode->appendChild($li);
     // iterate through all <span> elements
     foreach ($sourceElements as $sourceElement) {
         if (!$sourceElement instanceof DOMElement) {
             $span = $targetDom->createElement('span');
             $span->nodeValue = htmlspecialchars($sourceElement->wholeText);
             $li->appendChild($span);
             continue;
         }
         if ('br' === $sourceElement->tagName) {
             // create new li and new line
             $li = $targetDom->createElement('li');
             $targetNode->appendChild($li);
             continue;
         }
         $elementClass = $this->_mapPhpColors($sourceElement->getAttribute('style'));
         foreach ($sourceElement->childNodes as $sourceChildElement) {
             if ($sourceChildElement instanceof DOMElement && 'br' === $sourceChildElement->tagName) {
                 // create new li and new line
                 $li = $targetDom->createElement('li');
                 $targetNode->appendChild($li);
             } else {
                 // apend content to current li element
                 // apend content to urrent li element
                 $span = $targetDom->createElement('span');
                 $span->nodeValue = htmlspecialchars($sourceChildElement->wholeText);
                 $span->setAttribute('class', $elementClass);
                 $li->appendChild($span);
             }
         }
     }
     return $targetDom;
 }
コード例 #29
0
/**
 * Implements template_preprocess_menu_tree()
 * 1. Pick the data attributes for menu name and depth,
 *    save them as elements in the $variables array
 *    then the template_menu_tree hook can add them as CSS classes
 */
function bear_skin_preprocess_menu_tree(&$variables)
{
    $tree = new DOMDocument();
    @$tree->loadHTML($variables['tree']);
    $links = $tree->getElementsByTagname('li');
    $menu_name = '';
    $menu_depth = '';
    foreach ($links as $link) {
        // get the attributes and save them
        $menu_name = $link->getAttribute('data-menu-name');
        $menu_depth = $link->getAttribute('data-menu-depth');
        break;
    }
    $variables['menu_name'] = $menu_name;
    $variables['menu_depth'] = $menu_depth;
}
コード例 #30
0
ファイル: class-pb-epub3.php プロジェクト: cumi/pressbooks
 /**
  * Check for existence of scripting elements
  *
  * @param string $html
  *
  * @return bool
  */
 protected function isScripted($html)
 {
     if (preg_match('/<script[^>]*>.*?<\\/script>/is', $html)) {
         return true;
     }
     try {
         $doc = new \DOMDocument();
         $doc->loadHTML($html);
         foreach ($doc->getElementsByTagname('*') as $element) {
             foreach (iterator_to_array($element->attributes) as $name => $attribute) {
                 if (in_array($name, $this->javaScriptEvents)) {
                     return true;
                 }
             }
         }
     } catch (\Exception $e) {
         // Do nothing
     }
     return false;
 }