xref: /dokuwiki/vendor/openpsa/universalfeedcreator/lib/Creator/GPXCreator.php (revision e43cd7e11322648414daef21f777734a2cafc5c8)
1*572dd708SAndreas Gohr<?php
2*572dd708SAndreas Gohr
3*572dd708SAndreas Gohr/**
4*572dd708SAndreas Gohr * GPXCreator is a FeedCreator that implements a GPX output, suitable for a GIS packages
5*572dd708SAndreas Gohr *
6*572dd708SAndreas Gohr * @since   1.7.6
7*572dd708SAndreas Gohr * @author  Barry Hunter <geo@barryhunter.co.uk>
8*572dd708SAndreas Gohr */
9*572dd708SAndreas Gohrclass GPXCreator extends FeedCreator
10*572dd708SAndreas Gohr{
11*572dd708SAndreas Gohr
12*572dd708SAndreas Gohr    /**
13*572dd708SAndreas Gohr     * GPXCreator constructor.
14*572dd708SAndreas Gohr     */
15*572dd708SAndreas Gohr    public function __construct()
16*572dd708SAndreas Gohr    {
17*572dd708SAndreas Gohr        $this->contentType = "text/xml";
18*572dd708SAndreas Gohr        $this->encoding = "utf-8";
19*572dd708SAndreas Gohr    }
20*572dd708SAndreas Gohr
21*572dd708SAndreas Gohr    /** @inheritdoc */
22*572dd708SAndreas Gohr    public function createFeed()
23*572dd708SAndreas Gohr    {
24*572dd708SAndreas Gohr        $feed = "<?xml version=\"1.0\" encoding=\"".$this->encoding."\"?>\n";
25*572dd708SAndreas Gohr        $feed .= $this->_createStylesheetReferences();
26*572dd708SAndreas Gohr        $feed .= "<gpx xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.0\"
27*572dd708SAndreas Gohr        creator=\"".FEEDCREATOR_VERSION."\"
28*572dd708SAndreas Gohr        xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\" xmlns=\"http://www.topografix.com/GPX/1/0\">\n";
29*572dd708SAndreas Gohr
30*572dd708SAndreas Gohr        $now = new FeedDate();
31*572dd708SAndreas Gohr        $feed .= "<desc>".FeedCreator::iTrunc(htmlspecialchars($this->title), 100)."</desc>
32*572dd708SAndreas Gohr        <author>{$http_host}</author>
33*572dd708SAndreas Gohr        <url>".htmlspecialchars($this->link)."</url>
34*572dd708SAndreas Gohr        <time>".htmlspecialchars($now->iso8601())."</time>
35*572dd708SAndreas Gohr        \n";
36*572dd708SAndreas Gohr
37*572dd708SAndreas Gohr        for ($i = 0; $i < count($this->items); $i++) {
38*572dd708SAndreas Gohr            $feed .= "<wpt lat=\"".$this->items[$i]->lat."\" lon=\"".$this->items[$i]->long."\">
39*572dd708SAndreas Gohr            <name>".substr(htmlspecialchars(strip_tags($this->items[$i]->title)), 0, 6)."</name>
40*572dd708SAndreas Gohr                <desc>".htmlspecialchars(strip_tags($this->items[$i]->title))."</desc>
41*572dd708SAndreas Gohr                    <src>".htmlspecialchars($this->items[$i]->author)."</src>
42*572dd708SAndreas Gohr                        <url>".htmlspecialchars($this->items[$i]->link)."</url>
43*572dd708SAndreas Gohr        </wpt>\n";
44*572dd708SAndreas Gohr        }
45*572dd708SAndreas Gohr        $feed .= "</gpx>\n";
46*572dd708SAndreas Gohr
47*572dd708SAndreas Gohr        return $feed;
48*572dd708SAndreas Gohr    }
49*572dd708SAndreas Gohr}
50