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