]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/SubMirror/SubMirrorPlugin.php
initialize fave, sub, and membership URIs
[quix0rs-gnu-social.git] / plugins / SubMirror / SubMirrorPlugin.php
index 00c04ad0b6493074a2217125f05538abbcbaae20..ccb32b4a49d68a02ef16fe6780a4c35476be25a4 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
+
 /**
  * @package SubMirrorPlugin
  * @maintainer Brion Vibber <brion@status.net>
  */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
-
-
 class SubMirrorPlugin extends Plugin
 {
     /**
@@ -37,6 +35,9 @@ class SubMirrorPlugin extends Plugin
     {
         $m->connect('settings/mirror',
                     array('action' => 'mirrorsettings'));
+        $m->connect('settings/mirror/add/:provider',
+                    array('action' => 'mirrorsettings'),
+                    array('provider' => '[A-Za-z0-9_-]+'));
         $m->connect('settings/mirror/add',
                     array('action' => 'addmirror'));
         $m->connect('settings/mirror/edit',
@@ -89,21 +90,22 @@ class SubMirrorPlugin extends Plugin
                             'author' => 'Brion Vibber',
                             'homepage' => 'http://status.net/wiki/Plugin:SubMirror',
                             'rawdescription' =>
+                            // TRANS: Plugin description.
                             _m('Pull feeds into your timeline!'));
 
         return true;
     }
 
     /**
-     * Menu item for settings
+     * Menu item for personal subscriptions/groups area
      *
-     * @param Action &$action Action being executed
+     * @param Widget $widget Widget being executed
      *
      * @return boolean hook return
      */
-
-    function onEndAccountSettingsNav(&$action)
+    function onEndSubGroupNav($widget)
     {
+        $action = $widget->out;
         $action_name = $action->trimmed('action');
 
         $action->menuItem(common_local_url('mirrorsettings'),
@@ -120,6 +122,9 @@ class SubMirrorPlugin extends Plugin
     {
         $schema = Schema::get();
         $schema->ensureTable('submirror', SubMirror::schemaDef());
+
+        // @hack until key definition support is merged
+        SubMirror::fixIndexes($schema);
         return true;
     }
 
@@ -140,13 +145,6 @@ class SubMirrorPlugin extends Plugin
         $transports[] = 'mirror';
     }
 
-    function onStartShowSubscriptionsContent($action)
-    {
-        $action->element('a',
-                         array('href' => common_local_url('mirrorsettings')),
-                         _m('Set up mirroring options...'));
-    }
-
     /**
      * Let the OStatus subscription garbage collection know if we're
      * making use of a remote feed, so it doesn't get dropped out
@@ -169,4 +167,38 @@ class SubMirrorPlugin extends Plugin
         }
         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) {
+            $mirror = new SubMirror();
+            $mirror->subscriber = $profile->id;
+            $entry = array(
+                'id' => 'mirrors',
+                // TRANS: Label in profile statistics section, followed by a count.
+                'label' => _m('Mirrored feeds'),
+                'link' => common_local_url('mirrorsettings'),
+                'value' => $mirror->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;
+    }
 }