2 /* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
3 and is published under the AGPL license. */
5 class IdxController extends Zend_Controller_Action
8 public function init() {
9 $this->_helper->SyjMedias->addScripts('idx');
10 $this->view->headLink()->appendStylesheet('css/olstyle.css', "all");
11 $this->view->headLink()->appendStylesheet('css/generic.css', "all");
12 $this->view->headLink()->appendStylesheet('css/syj.css', "all");
15 public function rawmode(Syj_Model_Path $path) {
16 $this->_helper->SyjReset->resetPlaceHolders();
17 $this->_helper->SyjMedias->addScripts('rawidx');
19 $this->view->headLink()->appendStylesheet('css/generic.css', 'all');
20 $this->view->headLink()->appendStylesheet('css/syjraw.css', 'all');
21 $this->view->headTitle($path->displayTitle);
23 $this->_jsRawLocaleStrings();
25 $this->view->jslocales['geomAttribution'] =
26 $this->view->translate('route by <strong>%s</strong>', (string)$path->creator->pseudo);
28 $jsgeom = new phptojs\JsObject('gInitialGeom', array('data' => (string) $path->geom));
29 $this->view->headScript()->prependScript((string) $jsgeom);
31 $this->view->rawmode = true;
32 $this->_helper->ViewRenderer->setViewScriptPathSpec(':controller/raw.:suffix');
35 public function indexAction() {
36 $url = $this->getRequest()->getUserParam('url');
38 $geomform = new Syj_Form_Geom(array('name' => 'geomform'));
39 $loginform = new Syj_Form_Login(array('name' => 'loginform', 'action' => 'login'));
40 $userform = new Syj_Form_User(array('name' => 'userform', 'action' => 'user'));
41 $newpwdform = new Syj_Form_Newpwd(array('name' => 'newpwdform', 'action' => 'newpwd'));
44 $pathMapper = new Syj_Model_PathMapper();
45 $path = new Syj_Model_Path();
46 if (!$pathMapper->findByUrl($url, $path)) {
47 if (is_numeric($url) and $pathMapper->hasexisted($url)) {
48 $this->view->message = $this->view->translate("route has been deleted");
49 throw new Syj_Exception_NotFound('Gone', 410);
51 $this->view->message = $this->view->translate("route does not exist");
52 throw new Syj_Exception_NotFound('Not Found', 404);
56 if ($this->getRequest()->getQuery('format') == 'raw') {
57 $this->rawmode($path);
61 $title = $path->displayTitle;
62 $this->view->path = $path;
63 $jsgeom = new phptojs\JsObject('gInitialGeom', array('data' => (string) $path->geom));
64 $this->view->headScript()->prependScript((string) $jsgeom);
65 $loginform->login_geom_id->setValue((string)$path->id);
66 $geomform->geom_title->setValue($path->title);
68 $geomform->setAction('path');
70 $lat = $this->getRequest()->getQuery('lat');
71 $lon = $this->getRequest()->getQuery('lon');
72 $zoom = $this->getRequest()->getQuery('zoom');
73 if (is_numeric ($lat) and is_numeric ($lon) and is_numeric ($zoom)) {
74 $initialpos = array('lat' => (float)$lat, 'lon' => (float)$lon, 'zoom' => (int)$zoom);
76 $initialpos = $this->_helper->syjGeoip($this->getRequest()->getClientIp(true));
79 $this->view->headScript()->prependScript((string) new phptojs\JsObject('gInitialPos', $initialpos));
80 $title = "Show your journey";
83 $this->_jsLoggedInfo(isset($url) ? $path: null);
84 $this->_jsLocaleStrings();
85 if (isset ($url) and $path->creator) {
86 $this->view->jslocales['geomAttribution'] =
87 $this->view->translate('route by <strong>%s</strong>', (string)$path->creator->pseudo);
89 $this->view->headTitle($title);
90 $this->view->headMeta()->appendName('description', $this->view->translate('website to share routes'));
91 $this->view->geomform = $geomform;
92 $this->view->loginform = $loginform;
93 $this->view->userform = $userform;
94 $this->view->newpwdform = $newpwdform;
95 $this->view->loggedUser = $this->_helper->SyjSession->user();
98 protected function _jsLoggedInfo(Syj_Model_Path $path = null) {
99 $loggedinfo = new phptojs\JsObject('gLoggedInfo', array('connections' => 0));
101 $user = $this->_helper->SyjSession->user();
103 $loggedinfo->logged = true;
105 $loggedinfo->logged = false;
109 $loggedinfo->iscreator = $path->isCreator($user);
110 $loggedinfo->pathid = (string)$path->id;
112 $loggedinfo->iscreator = true;
115 $this->view->headScript()->prependScript((string) $loggedinfo);
118 protected function _jsRawLocaleStrings() {
119 $this->view->jslocales = array(
120 'osmAttribution' => __("Map by <a href='http://openstreetmap.org/'>OpenStreetMap</a>"),
124 protected function _jsLocaleStrings() {
125 $this->view->jslocales = array(
126 'saveSuccess' => __("save took place successfully"),
127 'requestError' => __("server did not understood request. That's probably caused by a bug in SYJ"),
128 'gonePathError' => __("route not referenced on the server. It has probably been deleted."),
129 'uniquePathError' => __("similar path seems to already exist. Please do not create two exactly identical paths"),
130 'notReachedError' => __("server could not be reached"),
131 'serverError' => __("there was a server error"),
132 'unknownError' => __("there was an unknown error"),
133 'userEmptyWarn' => __("you must enter a login name"),
134 'loginSuccess' => __("Login correct"),
135 'loginFailure' => __("Wrong login/password"),
136 'passwordEmptyWarn' => __("you must enter a password"),
137 'passwordNoMatchWarn' => __("Password do not match"),
138 'acceptTermsofuseWarn' => __("You must accept terms of use"),
139 'emailEmptyWarn' => __("you must enter an email"),
140 'emailInvalidWarn' => __("invalid email"),
141 'uniqueEmailError' => __("an user is already registered with this email"),
142 'userSuccess' => __("Account created"),
143 'newpwdSuccess' => __("A link to reset your password has been emailed to you"),
144 'canResubmit' => __("Now, you can retry to save"),
145 'routeBy' => __("route by"),
146 'osmAttribution' => __("Map by <a href='http://openstreetmap.org/'>OpenStreetMap</a>"),
147 'pseudoChecking' => __("checking availibilty"),
148 'availablePseudo' => __("available pseudo"),
149 'unavailablePseudo' => __("unavailable pseudo"),
150 'editAction' => __("edit"),
151 'createAction' => __("create"),
152 'cloneAction' => __("duplicate"),
153 'unsavedConfirmExit' => __("You have an unsaved route"),
154 'notEmptyField' => __("Value is required"),
155 'noResult' => __("no result"),
156 'dragFileError' => __("could not analyze file content"),