123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- <?php
- if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
- class SubMirrorPlugin extends Plugin
- {
- const PLUGIN_VERSION = '2.0.0';
-
- public function onRouterInitialized(URLMapper $m)
- {
- $m->connect('settings/mirror',
- ['action' => 'mirrorsettings']);
- $m->connect('settings/mirror/add/:provider',
- ['action' => 'mirrorsettings'],
- ['provider' => '[A-Za-z0-9_-]+']);
- $m->connect('settings/mirror/add',
- ['action' => 'addmirror']);
- $m->connect('settings/mirror/edit',
- ['action' => 'editmirror']);
- return true;
- }
- function handle($notice) : bool
- {
-
- $mirror = new SubMirror();
- $mirror->subscribed = $notice->profile_id;
- if ($mirror->find()) {
- while ($mirror->fetch()) {
- $mirror->repeat($notice);
- }
- }
- }
- public function onPluginVersion(array &$versions): bool
- {
- $versions[] = array('name' => 'SubMirror',
- 'version' => self::PLUGIN_VERSION,
- 'author' => 'Brion Vibber',
- 'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/SubMirror',
- 'rawdescription' =>
-
- _m('Pull feeds into your timeline!'));
- return true;
- }
-
- function onEndAccountSettingsNav($action)
- {
- $action_name = $action->trimmed('action');
- common_debug("ACTION NAME = " . $action_name);
- $action->menuItem(common_local_url('mirrorsettings'),
-
- _m('MENU', 'Mirroring'),
-
- _m('Configure mirroring of posts from other feeds'),
- $action_name === 'mirrorsettings');
- return true;
- }
- function onCheckSchema()
- {
- $schema = Schema::get();
- $schema->ensureTable('submirror', SubMirror::schemaDef());
-
- SubMirror::fixIndexes($schema);
- return true;
- }
-
- function onEndInitializeQueueManager(QueueManager $qm)
- {
-
- $qm->connect('mirror', 'MirrorQueueHandler');
- return true;
- }
- function onStartEnqueueNotice($notice, &$transports)
- {
- $transports[] = 'mirror';
- }
-
- function onOstatus_profileSubscriberCount(Ostatus_profile $oprofile, &$count)
- {
- try {
- $profile = $oprofile->localProfile();
- $mirror = new SubMirror();
- $mirror->subscribed = $profile->id;
- if ($mirror->find()) {
- while ($mirror->fetch()) {
- $count++;
- }
- }
- } catch (NoProfileException $e) {
-
-
- }
- return true;
- }
-
- 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',
-
- 'label' => _m('Mirrored feeds'),
- 'link' => common_local_url('mirrorsettings'),
- 'value' => $mirror->count(),
- );
- $insertAt = count($stats);
- foreach ($stats as $i => $row) {
- if ($row['id'] == 'groups') {
-
- $insertAt = $i + 1;
- break;
- }
- }
- array_splice($stats, $insertAt, 0, array($entry));
- }
- return true;
- }
- }
|