3 * StatusNet, the distributed open-source microblogging tool
5 * Plugin to provide map visualization of location data
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Evan Prodromou <evan@status.net>
25 * @copyright 2009 StatusNet Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
35 * Plugin to provide map visualization of location data
37 * This plugin uses the Mapstraction JavaScript library to
41 * @author Evan Prodromou <evan@status.net>
42 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
43 * @link http://status.net/
48 class MapstractionPlugin extends Plugin
50 /** provider name, one of:
51 'cloudmade', 'google', 'microsoft', 'openlayers', 'yahoo' */
52 public $provider = 'openlayers';
53 /** provider API key (or 'appid'), if required ('google' and 'yahoo' only) */
54 public $apikey = null;
59 * The way to register new actions from a plugin.
61 * @param Router &$m reference to router
63 * @return boolean event handler return
66 function onRouterInitialized(&$m)
68 $m->connect(':nickname/all/map',
69 array('action' => 'allmap'),
70 array('nickname' => '['.NICKNAME_FMT.']{1,64}'));
71 $m->connect(':nickname/map',
72 array('action' => 'usermap'),
73 array('nickname' => '['.NICKNAME_FMT.']{1,64}'));
78 * Hook for autoloading classes
80 * This makes sure our classes get autoloaded from our directory
82 * @param string $cls name of class being used
84 * @return boolean event handler return
87 function onAutoload($cls)
93 include_once INSTALLDIR.'/plugins/Mapstraction/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
101 * Hook for adding extra JavaScript
103 * This makes sure our scripts get loaded for map-related pages
105 * @param Action $action Action object for the page
107 * @return boolean event handler return
110 function onEndShowScripts($action)
112 $actionName = $action->trimmed('action');
114 switch ($this->provider)
117 $action->script('http://tile.cloudmade.com/wml/0.2/web-maps-lite.js');
120 $action->script(sprintf('http://maps.google.com/maps?file=api&v=2&sensor=false&key=%s',
124 $action->script('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6');
127 // XXX: is this not nice...?
128 $action->script('http://openlayers.org/api/OpenLayers.js');
131 $action->script(sprintf('http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=%s',
134 case 'geocommons': // don't support this yet
139 $action->script(sprintf('%s?(%s)',
140 common_path('plugins/Mapstraction/js/mxn.js'),
143 $action->script(common_path('plugins/Mapstraction/usermap.js'));
145 $action->elementStart('script', array('type' => 'text/javascript'));
146 $action->raw(sprintf('var _provider = "%s";', $this->provider));
147 $action->elementEnd('script');
152 function onEndShowSections($action)
154 $actionName = $action->trimmed('action');
155 // These are the ones that have maps on 'em
156 if (!in_array($actionName,
157 array('showstream', 'all'))) {
161 $action->elementStart('div', array('id' => 'entity_map',
162 'class' => 'section'));
164 $action->element('h2', null, _('Map'));
166 $action->element('div', array('id' => 'map_canvas',
167 'class' => 'gray smallmap',
168 'style' => "width: 100%; height: 240px"));
170 $mapAct = ($actionName == 'showstream') ? 'usermap' : 'allmap';
171 $mapUrl = common_local_url($mapAct,
172 array('nickname' => $action->trimmed('nickname')));
174 $action->element('a', array('href' => $mapUrl),
177 $action->elementEnd('div');