]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Mapstraction/MapstractionPlugin.php
Added missing position paramater
[quix0rs-gnu-social.git] / plugins / Mapstraction / MapstractionPlugin.php
index 4b80ff979d49dfc925f6257a9c04a45a0c86e6a8..868933fd432461a887c0697c1d1681a1ab6d4a6e 100644 (file)
@@ -47,6 +47,8 @@ if (!defined('STATUSNET')) {
 
 class MapstractionPlugin extends Plugin
 {
+    const VERSION = STATUSNET_VERSION;
+
     /** provider name, one of:
      'cloudmade', 'google', 'microsoft', 'openlayers', 'yahoo' */
     public $provider = 'openlayers';
@@ -58,12 +60,12 @@ class MapstractionPlugin extends Plugin
      *
      * The way to register new actions from a plugin.
      *
-     * @param Router &$m reference to router
+     * @param Router $m reference to router
      *
      * @return boolean event handler return
      */
 
-    function onRouterInitialized(&$m)
+    function onRouterInitialized($m)
     {
         $m->connect(':nickname/all/map',
                     array('action' => 'allmap'),
@@ -90,6 +92,7 @@ class MapstractionPlugin extends Plugin
         {
         case 'AllmapAction':
         case 'UsermapAction':
+        case 'MapAction':
             include_once INSTALLDIR.'/plugins/Mapstraction/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
             return false;
         default:
@@ -109,9 +112,10 @@ class MapstractionPlugin extends Plugin
 
     function onEndShowScripts($action)
     {
-        // These are the ones that have maps on 'em
-        if (!in_array($action->trimmed('action'),
-                      array('showstream', 'all', 'allmap', 'usermap'))) {
+        $actionName = $action->trimmed('action');
+
+        if (!in_array($actionName,
+                      array('showstream', 'all', 'usermap', 'allmap'))) {
             return true;
         }
 
@@ -144,10 +148,63 @@ class MapstractionPlugin extends Plugin
                                 common_path('plugins/Mapstraction/js/mxn.js'),
                                 $this->provider));
 
-        $action->elementStart('script', array('type' => 'text/javascript'));
-        $action->raw(sprintf('var _provider = "%s";', $this->provider));
-        $action->elementEnd('script');
+        $action->script(common_path('plugins/Mapstraction/usermap.js'));
+
+        $action->inlineScript(sprintf('var _provider = "%s";', $this->provider));
+
+        // usermap and allmap handle this themselves
+
+        if (in_array($actionName,
+                     array('showstream', 'all'))) {
+            $action->inlineScript('$(document).ready(function() { '.
+                                  ' var user = null; '.
+                                  (($actionName == 'showstream') ? ' user = scrapeUser(); ' : '') .
+                                  ' var notices = scrapeNotices(user); ' .
+                                  ' showMapstraction($("#map_canvas"), notices); '.
+                                  '});');
+        }
+
+        return true;
+    }
 
+    function onEndShowSections($action)
+    {
+        $actionName = $action->trimmed('action');
+        // These are the ones that have maps on 'em
+        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(&$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> '.
+                               'JavaScript library.'));
         return true;
     }
 }