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/
47 class MapstractionPlugin extends Plugin
49 const VERSION = STATUSNET_VERSION;
51 /** provider name, one of:
52 'cloudmade', 'google', 'microsoft', 'openlayers', 'yahoo' */
53 public $provider = 'openlayers';
54 /** provider API key (or 'appid'), if required ('google' and 'yahoo' only) */
55 public $apikey = null;
60 * The way to register new actions from a plugin.
62 * @param Router $m reference to router
64 * @return boolean event handler return
66 function onRouterInitialized($m)
68 $m->connect(':nickname/all/map',
69 array('action' => 'allmap'),
70 array('nickname' => Nickname::DISPLAY_FMT));
71 $m->connect(':nickname/map',
72 array('action' => 'usermap'),
73 array('nickname' => Nickname::DISPLAY_FMT));
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
86 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
109 function onEndShowScripts($action)
111 $actionName = $action->trimmed('action');
113 if (!in_array($actionName,
114 array('showstream', 'all', 'usermap', 'allmap'))) {
118 switch ($this->provider)
121 $action->script('http://tile.cloudmade.com/wml/0.2/web-maps-lite.js');
124 $action->script(sprintf('http://maps.google.com/maps?file=api&v=2&sensor=false&key=%s',
125 urlencode($this->apikey)));
128 $action->script((StatusNet::isHTTPS()?'https':'http') + '://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6');
131 // Use our included stripped & minified OpenLayers.
132 $action->script($this->path('OpenLayers/OpenLayers.js'));
135 $action->script(sprintf('http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=%s',
136 urlencode($this->apikey)));
138 case 'geocommons': // don't support this yet
143 if ($this->provider == 'openlayers') {
144 // We have an optimized path for our default case.
146 // Note that OpenLayers.js needs to be separate, or it won't
147 // be able to find its UI images and styles.
148 $action->script($this->path('usermap-mxn-openlayers.min.js'));
150 $action->script(sprintf('%s?(%s)',
151 $this->path('js/mxn.js'),
154 $action->script($this->path('usermap.js'));
157 $action->inlineScript(sprintf('var _provider = "%s";', $this->provider));
159 // usermap and allmap handle this themselves
161 if (in_array($actionName,
162 array('showstream', 'all'))) {
163 $action->inlineScript('$(document).ready(function() { '.
164 ' var user = null; '.
165 (($actionName == 'showstream') ? ' user = scrapeUser(); ' : '') .
166 ' var notices = scrapeNotices(user); ' .
167 ' var canvas = $("#map_canvas")[0]; ' .
168 ' if (typeof(canvas) != "undefined") { showMapstraction(canvas, notices); } '.
175 function onEndShowSections($action)
177 $actionName = $action->trimmed('action');
178 // These are the ones that have maps on 'em
179 if (!in_array($actionName,
180 array('showstream', 'all'))) {
184 $action->elementStart('div', array('id' => 'entity_map',
185 'class' => 'section'));
187 // TRANS: Header for Map widget that displays a map with geodata for notices.
188 $action->element('h2', null, _m('Map'));
190 $action->element('div', array('id' => 'map_canvas',
191 'class' => 'gray smallmap',
192 'style' => "width: 100%; height: 240px"));
194 $mapAct = ($actionName == 'showstream') ? 'usermap' : 'allmap';
195 $mapUrl = common_local_url($mapAct,
196 array('nickname' => $action->trimmed('nickname')));
198 $action->element('a', array('href' => $mapUrl),
199 // TRANS: Clickable item to allow opening the map in full size.
202 $action->elementEnd('div');
205 function onPluginVersion(&$versions)
207 $versions[] = array('name' => 'Mapstraction',
208 'version' => self::VERSION,
209 'author' => 'Evan Prodromou',
210 'homepage' => 'http://status.net/wiki/Plugin:Mapstraction',
212 // TRANS: Plugin description.
213 _m('Show maps of users\' and friends\' notices '.
214 'with <a href="http://www.mapstraction.com/">Mapstraction</a>.'));