]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/SearchSub/SearchSubPlugin.php
SearchSub plugin: add management UI for subscribed searches
[quix0rs-gnu-social.git] / plugins / SearchSub / SearchSubPlugin.php
index 130600a41afd855cc1d666d759254596914be259..f7da8c44d9acf1ccffd0bf3e3ee80d326731dba0 100644 (file)
@@ -78,6 +78,7 @@ class SearchSubPlugin extends Plugin
             return false;
         case 'SearchsubAction':
         case 'SearchunsubAction':
+        case 'SearchsubsAction':
         case 'SearchSubForm':
         case 'SearchUnsubForm':
             include_once $dir.'/'.strtolower($cls).'.php';
@@ -103,6 +104,9 @@ class SearchSubPlugin extends Plugin
                     array('action' => 'searchunsub'),
                     array('search' => Router::REGEX_TAG));
 
+        $m->connect(':nickname/search-subscriptions',
+                    array('action' => 'searchsubs'),
+                    array('nickname' => Nickname::DISPLAY_FMT));
         return true;
     }
 
@@ -209,4 +213,60 @@ class SearchSubPlugin extends Plugin
         }
         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('searchsubs', array('nickname' => $action->user->nickname)),
+                          // TRANS: SearchSub plugin menu item on user settings page.
+                          _m('MENU', 'Searches'),
+                          // TRANS: SearchSub plugin tooltip for user settings menu item.
+                          _m('Configure search subscriptions'),
+                          $action_name == 'searchsubs' && $action->arg('nickname') == $action->user->nickname);
+
+        return true;
+    }
+
+    /**
+     * Add a count of mirrored feeds into a user's profile sidebar stats.
+     *
+     * @param Profile $profile
+     * @param array $stats
+     * @return boolean hook return value
+     */
+    function onProfileStats($profile, &$stats)
+    {
+        $cur = common_current_user();
+        if (!empty($cur) && $cur->id == $profile->id) {
+            $searchsub = new SearchSub();
+            $searchsub ->profile_id = $profile->id;
+            $entry = array(
+                'id' => 'searchsubs',
+                'label' => _m('Search subscriptions'),
+                'link' => common_local_url('searchsubs', array('nickname' => $profile->nickname)),
+                'value' => $searchsub->count(),
+            );
+
+            $insertAt = count($stats);
+            foreach ($stats as $i => $row) {
+                if ($row['id'] == 'groups') {
+                    // Slip us in after them.
+                    $insertAt = $i + 1;
+                    break;
+                }
+            }
+            array_splice($stats, $insertAt, 0, array($entry));
+        }
+        return true;
+    }
 }