This file is indexed.

/usr/share/zoph/www/php/track.inc.php is in zoph 0.9.4-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/**
 * A track is a collection of points, which are used for geotagging
 *
 * Zoph is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Zoph is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Zoph; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @author Jeroen Roos
 * @package Zoph
 */

use db\delete;
use db\param;
use db\clause;

/**
 * A track is a collection of points, which are used for geotagging
 *
 * @author Jeroen Roos
 * @package Zoph
 */
class track extends zophTable {
    /** @var string The name of the database table */
    protected static $tableName="track";
    /** @var array List of primary keys */
    protected static $primaryKeys=array("track_id");
    /** @var array Fields that may not be empty */
    protected static $notNull=array("name");
    /** @var bool keep keys with insert. In most cases the keys are set by
                  the db with auto_increment */
    protected static $keepKeys = false;
    /** @var string URL for this class */
    protected static $url="track.php?track_id=";

    private $points=array();

    /**
     * Create a track object
     *
     * Calling this function without an id, will create a new track, setting
     * the id will make it possible to lookup an existing track from the db
     * @see lookup
     */

    /**
     * Insert a track into the database
     */
    public function insert() {
        parent::insert();
        $this->updatePoints();
        $this->insertPoints();
    }

    /**
     * Lookup a track in the database.
     *
     * This will fill the object with the info already in the db
     */
    public function lookup() {
        $result=parent::lookup();
        $this->points=$this->getPoints();
        return $result;
    }

    /**
     * Deletes a track
     *
     * Also deletes all point in the track
     * @see point
     */
    public function delete() {
        if (!$this->getId()) {
            return;
        }
        parent::delete();

        $qry=new delete(array("pt" => "point"));
        $qry->where(new clause("track_id=:trackid"));
        $qry->addParam(new param(":trackid", (int) $this->getId(), PDO::PARAM_INT));

        $qry->execute();
    }

    /**
     * Add a new point to a track
     */
    public function addPoint(point $point) {
        $point->set("track_id", $this->get("track_id"));
        $this->points[]=$point;
    }

    /**
     * This sets the track_id on all points in this track
     */
    private function updatePoints() {
        foreach ($this->points as $point) {
            $point->set("track_id", $this->get("track_id"));
        }
    }

    /**
     * Insert points into database
     */
    private function insertPoints() {
        foreach ($this->points as $point) {
            $point->insert();
        }
    }

    /**
     * Read a GPX file and create track & point objects from there
     */
    public static function getFromGPX($file) {
        $track = new track;
        if (class_exists("XMLReader")) {
            $xml=new XMLReader();
            $xml->open($file);

            $track->set("name", substr($file, strrpos($file, "/") + 1, strrpos($file, ".")));

            $xml->read();
            if ($xml->name != "gpx") {
                die("Not a gpx file");
            } else {
                $stack[]="gpx";
            }
            while ($xml->read()) {
                if ($xml->nodeType==XMLReader::ELEMENT) {
                    // Keep track of the current open tags
                    if (!$xml->isEmptyElement) {
                        $stack[]=$xml->name;
                    }
                    switch ($xml->name) {
                    case "name":
                        $current=$stack[count($stack) - 2];
                        if ($current=="gpx") {
                            // only set the name if we're in <gpx>
                            $xml->read();
                            $track->set("name", $xml->value);
                        }
                        break;
                    case "wpt":
                        // not (yet?) supported
                        break;
                    case "trkpt":
                        // For now we are ignoring multiple tracks or segments
                        // in the same file and we simply look at the points
                        $xml_point=$xml->readOuterXML();
                        $point=point::readFromXML($xml_point);
                        $track->addpoint($point);
                        break;
                    }
                } else if ($xml->nodeType==XMLReader::END_ELEMENT) {
                    $element=array_pop($stack);
                    if ($element!=$xml->name) {
                        die("GPX not well formed: expected &lt;$element&gt;, " .
                            "found &lt;$xml->name&gt;");
                    }
                }
            }
            return $track;
        }
    }

    /**
     * Get all points for this track
     * @return array Array of all points in this track.
     */
    public function getPoints() {
        return point::getRecords("datetime", array("track_id" => $this->get("track_id")));
    }

    /**
     * Get the first point from a track
     * @return point first point
     */
    public function getFirstPoint() {
        $points=point::getRecords("datetime", array("track_id" => (int) $this->getId()));
        $first=$points[0];
        if (($first instanceof point)) {
            return $first;
        } else {
            return new point;
        }
    }

    /**
     * Get the last point from a track
     * @return point last point
     */
    public function getLastPoint() {
        $points=point::getRecords("datetime", array("track_id" => (int) $this->getId()));
        $last=array_pop($points);
        if (($last instanceof point)) {
            return $last;
        } else {
            return new point;
        }
    }

    /**
     * Get the number of points in a track
     * @return int count
     */
    public function getPointCount() {
        $points=$this->getPoints();
        return count($points);
    }

    /**
     * Get array that can be used to generate view for this track
     * @return array Display array
     */
    public function getDisplayArray() {
        $first=$this->getFirstPoint();
        $last=$this->getLastPoint();
        $count=$this->getPointCount();

        $return[translate("name")] = $this->get("name");
        $return[translate("time of first point")] = $first->get("datetime") . " UTC";
        $return[translate("time of last point")] = $last->get("datetime") . " UTC";
        $return[translate("number of points")] = $count;

        return $return;
    }

}
?>