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 const VERSION = STATUSNET_VERSION;
52 /** provider name, one of:
53 'cloudmade', 'google', 'microsoft', 'openlayers', 'yahoo' */
54 public $provider = 'openlayers';
55 /** provider API key (or 'appid'), if required ('google' and 'yahoo' only) */
56 public $apikey = null;
61 * The way to register new actions from a plugin.
63 * @param Router $m reference to router
65 * @return boolean event handler return
68 function onRouterInitialized($m)
70 $m->connect(':nickname/all/map',
71 array('action' => 'allmap'),
72 array('nickname' => '['.NICKNAME_FMT.']{1,64}'));
73 $m->connect(':nickname/map',
74 array('action' => 'usermap'),
75 array('nickname' => '['.NICKNAME_FMT.']{1,64}'));
80 * Hook for autoloading classes
82 * This makes sure our classes get autoloaded from our directory
84 * @param string $cls name of class being used
86 * @return boolean event handler return
89 function onAutoload($cls)
96 include_once INSTALLDIR.'/plugins/Mapstraction/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
104 * Hook for adding extra JavaScript
106 * This makes sure our scripts get loaded for map-related pages
108 * @param Action $action Action object for the page
110 * @return boolean event handler return
113 function onEndShowScripts($action)
115 $actionName = $action->trimmed('action');
117 if (!in_array($actionName,
118 array('showstream', 'all', 'usermap', 'allmap'))) {
122 switch ($this->provider)
125 $action->script('http://tile.cloudmade.com/wml/0.2/web-maps-lite.js');
128 $action->script(sprintf('http://maps.google.com/maps?file=api&v=2&sensor=false&key=%s',
132 $action->script('http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6');
135 // XXX: is this not nice...?
136 $action->script('http://openlayers.org/api/OpenLayers.js');
139 $action->script(sprintf('http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=%s',
142 case 'geocommons': // don't support this yet
147 $action->script(sprintf('%s?(%s)',
148 common_path('plugins/Mapstraction/js/mxn.js'),
151 $action->script(common_path('plugins/Mapstraction/usermap.js'));
153 $action->inlineScript(sprintf('var _provider = "%s";', $this->provider));
155 // usermap and allmap handle this themselves
157 if (in_array($actionName,
158 array('showstream', 'all'))) {
159 $action->inlineScript('$(document).ready(function() { '.
160 ' var user = null; '.
161 (($actionName == 'showstream') ? ' user = scrapeUser(); ' : '') .
162 ' var notices = scrapeNotices(user); ' .
163 ' showMapstraction($("#map_canvas"), notices); '.
170 function onEndShowSections($action)
172 $actionName = $action->trimmed('action');
173 // These are the ones that have maps on 'em
174 if (!in_array($actionName,
175 array('showstream', 'all'))) {
179 $action->elementStart('div', array('id' => 'entity_map',
180 'class' => 'section'));
182 $action->element('h2', null, _m('Map'));
184 $action->element('div', array('id' => 'map_canvas',
185 'class' => 'gray smallmap',
186 'style' => "width: 100%; height: 240px"));
188 $mapAct = ($actionName == 'showstream') ? 'usermap' : 'allmap';
189 $mapUrl = common_local_url($mapAct,
190 array('nickname' => $action->trimmed('nickname')));
192 $action->element('a', array('href' => $mapUrl),
195 $action->elementEnd('div');
198 function onPluginVersion(&$versions)
200 $versions[] = array('name' => 'Mapstraction',
201 'version' => self::VERSION,
202 'author' => 'Evan Prodromou',
203 'homepage' => 'http://status.net/wiki/Plugin:Mapstraction',
205 _m('Show maps of users\' and friends\' notices '.
206 'with <a href="http://www.mapstraction.com/">Mapstraction</a> '.
207 'JavaScript library.'));