]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TagSub/TagSubPlugin.php
Some cleanups:
[quix0rs-gnu-social.git] / plugins / TagSub / TagSubPlugin.php
index b43fcf32bae1270093e207c6c594639908330eeb..db142e608a9615049946ea97cedfa39a5655d557 100644 (file)
@@ -60,35 +60,6 @@ class TagSubPlugin extends Plugin
         return true;
     }
 
-    /**
-     * Load related modules when needed
-     *
-     * @param string $cls Name of the class to be loaded
-     *
-     * @return boolean hook value; true means continue processing, false means stop.
-     */
-    function onAutoload($cls)
-    {
-        $dir = dirname(__FILE__);
-
-        switch ($cls)
-        {
-        case 'TagsubAction':
-        case 'TagunsubAction':
-            include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
-            return false;
-        case 'TagSub':
-            include_once $dir.'/'.$cls.'.php';
-            return false;
-        case 'TagSubForm':
-        case 'TagUnsubForm':
-            include_once $dir.'/'.strtolower($cls).'.php';
-            return false;
-        default:
-            return true;
-        }
-    }
-
     /**
      * Map URLs to actions
      *
@@ -105,6 +76,9 @@ class TagSubPlugin extends Plugin
                     array('action' => 'tagunsub'),
                     array('tag' => Router::REGEX_TAG));
 
+        $m->connect(':nickname/tag-subscriptions',
+                    array('action' => 'tagsubs'),
+                    array('nickname' => Nickname::DISPLAY_FMT));
         return true;
     }
 
@@ -153,4 +127,74 @@ class TagSubPlugin extends Plugin
         }
         return true;
     }
+
+    /**
+     *
+     * @param TagAction $action
+     * @return boolean hook result
+     */
+    function onStartTagShowContent(TagAction $action)
+    {
+        $user = common_current_user();
+
+        if ($user instanceof User) {
+            $tag = $action->trimmed('tag');
+            $tagsub = TagSub::pkeyGet(array('tag' => $tag,
+                                            'profile_id' => $user->id));
+            if ($tagsub) {
+                $form = new TagUnsubForm($action, $tag);
+            } else {
+                $form = new TagSubForm($action, $tag);
+            }
+            $action->elementStart('div', 'entity_actions');
+            $action->elementStart('ul');
+            $action->elementStart('li', 'entity_subscribe');
+            $form->show();
+            $action->elementEnd('li');
+            $action->elementEnd('ul');
+            $action->elementEnd('div');
+        }
+
+        return true;
+    }
+
+    /**
+     * Menu item for personal subscriptions/groups area
+     *
+     * @param Widget $widget Widget being executed
+     *
+     * @return boolean hook return
+     */
+    function onEndSubGroupNav($widget)
+    {
+        $action = $widget->out;
+        $action_name = $action->trimmed('action');
+
+        $action->menuItem(common_local_url('tagsubs', array('nickname' => $action->user->nickname)),
+                          // TRANS: SubMirror plugin menu item on user settings page.
+                          _m('MENU', 'Tags'),
+                          // TRANS: SubMirror plugin tooltip for user settings menu item.
+                          _m('Configure tag subscriptions'),
+                          $action_name == 'tagsubs' && $action->arg('nickname') == $action->user->nickname);
+
+        return true;
+    }
+
+    function onEndDefaultLocalNav($menu, $user)
+    {
+        $user = common_current_user();
+
+        if (!empty($user)) {
+
+            $tags = TagSub::forProfile($user->getProfile());
+
+            if (!empty($tags) && count($tags) > 0) {
+                $tagSubMenu = new TagSubMenu($menu->out, $user, $tags);
+                // TRANS: Menu item text for tags submenu.
+                $menu->submenu(_m('Tags'), $tagSubMenu);
+            }
+        }
+
+        return true;
+    }
 }