2 /* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class GeomController extends Zend_Controller_Action
8 public function indexAction() {
9 $request = $this->getRequest();
10 $response = $this->getResponse();
14 $pathMapper = new Syj_Model_PathMapper();
15 $path = new Syj_Model_Path();
17 $api = $this->_helper->SyjApi;
20 $parts = explode('.', $idx);
21 if (count($parts) >= 2) {
23 if (in_array($ext, array('kml', 'gpx', 'json'))) {
24 $idx = implode('.', explode('.', $idx, -1));
30 if (!$pathMapper->find($idx, $path)) {
31 if ($pathMapper->hasexisted($idx)) {
54 protected function kml(Syj_Model_Path $path) {
55 $data = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL; // <? <-- vim syntax goes crazy
56 $data .= '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">';
57 $data .= '<Placemark>';
59 $data .= '<atom:author><atom:name>'
60 . htmlspecialchars($path->creator->pseudo, ENT_COMPAT, "UTF-8")
61 . '</atom:name></atom:author>';
63 $data .= '<name>' . htmlspecialchars($path->displayTitle, ENT_COMPAT, "UTF-8") . '</name>';
64 $data .= $path->geom->toKML();
65 $data .= '</Placemark>';
68 $api = $this->_helper->SyjApi;
69 $api->setCheckIfNoneMatch(true)->setContentType('application/vnd.google-earth.kml+xml')->setBody($data);
72 protected function gpx(Syj_Model_Path $path) {
73 $data = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL; // <? <-- vim syntax goes crazy
74 $data .= '<gpx creator="syj" version="1.0" xmlns="http://www.topografix.com/GPX/1/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">';
77 $data .= '<author>' . htmlspecialchars($path->creator->pseudo, ENT_COMPAT, "UTF-8") . '</author>';
79 $data .= '<name>' . htmlspecialchars($path->displayTitle, ENT_COMPAT, "UTF-8") . '</name>';
80 $data .= $path->geom->toGPX();
84 $api = $this->_helper->SyjApi;
85 $api->setCheckIfNoneMatch(true)->setContentType('application/gpx+xml')->setBody($data);
88 protected function json(Syj_Model_Path $path) {
89 $data = json_decode($path->geom->toGeoJSON());
90 $data->title = (string)$path->displayTitle;
92 $data->creator = (string)$path->creator->pseudo;
94 $api = $this->_helper->SyjApi;
95 $api->setCheckIfNoneMatch(true)->setBodyJson($data);