123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class MapstractionPlugin extends Plugin
- {
- const VERSION = GNUSOCIAL_VERSION;
-
- public $provider = 'openlayers';
-
- public $apikey = null;
-
- function onRouterInitialized($m)
- {
- $m->connect(':nickname/all/map',
- array('action' => 'allmap'),
- array('nickname' => Nickname::DISPLAY_FMT));
- $m->connect(':nickname/map',
- array('action' => 'usermap'),
- array('nickname' => Nickname::DISPLAY_FMT));
- return true;
- }
-
- function onEndShowScripts($action)
- {
- $actionName = $action->trimmed('action');
- if (!in_array($actionName,
- array('showstream', 'all', 'usermap', 'allmap'))) {
- return true;
- }
- switch ($this->provider)
- {
- case 'cloudmade':
- $action->script('http://tile.cloudmade.com/wml/0.2/web-maps-lite.js');
- break;
- case 'google':
- $action->script(sprintf('http://maps.google.com/maps?file=api&v=2&sensor=false&key=%s',
- urlencode($this->apikey)));
- break;
- case 'microsoft':
- $action->script((GNUsocial::isHTTPS()?'https':'http') + '://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6');
- break;
- case 'openlayers':
-
- $action->script($this->path('OpenLayers/OpenLayers.js'));
- break;
- case 'yahoo':
- $action->script(sprintf('http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=%s',
- urlencode($this->apikey)));
- break;
- case 'geocommons':
- default:
- return true;
- }
- $action->script(sprintf('%s?(%s)',
- $this->path('js/mxn.js'),
- $this->provider));
- $action->script($this->path('usermap.js'));
- $action->inlineScript(sprintf('var _provider = "%s";', $this->provider));
-
- if (in_array($actionName,
- array('showstream', 'all'))) {
- $action->inlineScript('$(document).ready(function() { '.
- ' var user = null; '.
- (($actionName == 'showstream') ? ' user = scrapeUser(); ' : '') .
- ' var notices = scrapeNotices(user); ' .
- ' var canvas = $("#map_canvas")[0]; ' .
- ' if (typeof(canvas) != "undefined") { showMapstraction(canvas, notices); } '.
- '});');
- }
- return true;
- }
- function onEndShowSections(Action $action)
- {
- $actionName = $action->trimmed('action');
-
- if (!in_array($actionName,
- array('showstream', 'all'))) {
- return true;
- }
- $action->elementStart('div', array('id' => 'entity_map',
- 'class' => 'section'));
-
- $action->element('h2', null, _m('Map'));
- $action->element('div', array('id' => 'map_canvas',
- 'class' => 'gray smallmap',
- 'style' => "width: 100%; height: 240px"));
- $mapAct = ($actionName == 'showstream') ? 'usermap' : 'allmap';
- $mapUrl = common_local_url($mapAct,
- array('nickname' => $action->trimmed('nickname')));
- $action->element('a', array('href' => $mapUrl),
-
- _m('Full size'));
- $action->elementEnd('div');
- }
- function onPluginVersion(array &$versions)
- {
- $versions[] = array('name' => 'Mapstraction',
- 'version' => self::VERSION,
- 'author' => 'Evan Prodromou',
- 'homepage' => 'http://status.net/wiki/Plugin:Mapstraction',
- 'rawdescription' =>
-
- _m('Show maps of users\' and friends\' notices '.
- 'with <a href="http://www.mapstraction.com/">Mapstraction</a>.'));
- return true;
- }
- }
|