// LocLister - Version 1.3 // Snippet by Henning Mersch // See http://www.henning-mersch.de/snippets.html // Open Source in terms of the GPLv2; see http://www.gnu.org/licenses/gpl.html // Lists entries of a LOC XML File. // LOC is a XML format of GPS-Locations. E.g. used by Geocachers (See http://www.geocaching.com) // example usage: [ [LocLister?locURL=example.loc] ] //configuration //will be set once before 1st entry $header = ''; //will be set once after last entry $footer = '
'; //and this is a very brief example template for demostrating the usage //$template = "Name: #name#". // "Id: #id#". // "Lat: #lat#". // "Lon: #lon#". // "Text: #text#". // "Link: #link#". // ""; $template = ' #id#:#name# (show in map)'; //and this is a brief example template for the seperator... $seperatorTemplate = ' - #index# - '; //The file location of the XML Loc file to parse $locurl = isset($locURL)?$locURL:'found.loc'; //should seperators (by starting letter of #name# be shown? $showSeperator = isset($showSeperator)?$showSeperator:0; //Sort function used later on for sorting the read XML file // Could be changed if reuired. // By default this sorts in ascending order by names. /////////////////////////////////////////////// $sortFunction = create_function('$a,$b', ' $aNameElements = $a->get_elements_by_tagname("name"); $aName = $aNameElements[0]->get_content(); $bNameElements = $b->get_elements_by_tagname("name"); $bName = $bNameElements[0]->get_content(); $return .= "comparing ".$aName." with ".$bName."
"; if ($aName == $bName) return 0; return ($aName < $bName) ? -1 : 1; '); //processing starts here, no changes should be required blow this ///////////////////////////////////////// $return = ""; $return .= $header; //$return .= "Called with url to read: ".$locurl."
"; $doc = domxml_open_file($locurl); $wpElements = $doc->get_elements_by_tagname('waypoint'); $lastLetter = ''; //uasort($wpElements, "locSort"); uasort($wpElements, $sortFunction); foreach($wpElements as $wpElement) { $nameElements = $wpElement->get_elements_by_tagname('name'); $name = str_replace("'","'",$nameElements[0]->get_content()); $id = $nameElements[0]->get_attribute('id'); $coordElements = $wpElement->get_elements_by_tagname('coord'); $lat = $coordElements[0]->get_attribute('lat'); $lon = $coordElements[0]->get_attribute('lon'); $linkElements = $wpElement->get_elements_by_tagname('link'); $text = $linkElements[0]->get_attribute('text'); $link = $linkElements[0]->get_content(); //determine the current letter $currentLetter = $name{0}; $currentLetter = preg_replace("/[0-9,W]/", "#", $currentLetter); //if number or strange char collect in '#' section if($showSeperator && $currentLetter != $lastLetter ) { $lastLetter = $currentLetter; $thisSeperatorTemplate = $seperatorTemplate; $thisSeperatorTemplate = str_replace("#index#", $currentLetter, $thisSeperatorTemplate); $return .= $thisSeperatorTemplate; } $thisTemplate = $template; $thisTemplate = str_replace("#name#", $name, $thisTemplate); $thisTemplate = str_replace("#id#", $id, $thisTemplate); $thisTemplate = str_replace("#lat#", $lat, $thisTemplate); $thisTemplate = str_replace("#lon#", $lon, $thisTemplate); $thisTemplate = str_replace("#text#", $text, $thisTemplate); $thisTemplate = str_replace("#link#", $link, $thisTemplate); $return .= "n"; $return .= $thisTemplate; } $return .= $footer; return $return;