2010-08-05 21:37:47 +01:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2009-2010, StatusNet, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-09-18 21:31:41 +01:00
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
|
|
|
|
2010-08-05 21:37:47 +01:00
|
|
|
/**
|
|
|
|
* @package SubMirrorPlugin
|
|
|
|
* @maintainer Brion Vibber <brion@status.net>
|
|
|
|
*/
|
|
|
|
class SubMirrorPlugin extends Plugin
|
|
|
|
{
|
2019-06-03 01:56:52 +01:00
|
|
|
const PLUGIN_VERSION = '2.0.0';
|
|
|
|
|
2010-08-05 21:37:47 +01:00
|
|
|
/**
|
|
|
|
* Hook for RouterInitialized event.
|
|
|
|
*
|
2014-11-07 14:24:05 +00:00
|
|
|
* @param URLMapper $m path-to-action mapper
|
2010-08-05 21:37:47 +01:00
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2014-11-07 14:24:05 +00:00
|
|
|
public function onRouterInitialized(URLMapper $m)
|
2010-08-05 21:37:47 +01:00
|
|
|
{
|
|
|
|
$m->connect('settings/mirror',
|
2019-07-11 19:14:03 +01:00
|
|
|
['action' => 'mirrorsettings']);
|
2011-01-19 02:01:57 +00:00
|
|
|
$m->connect('settings/mirror/add/:provider',
|
2019-07-11 19:14:03 +01:00
|
|
|
['action' => 'mirrorsettings'],
|
|
|
|
['provider' => '[A-Za-z0-9_-]+']);
|
2010-08-05 21:37:47 +01:00
|
|
|
$m->connect('settings/mirror/add',
|
2019-07-11 19:14:03 +01:00
|
|
|
['action' => 'addmirror']);
|
2010-08-05 21:37:47 +01:00
|
|
|
$m->connect('settings/mirror/edit',
|
2019-07-11 19:14:03 +01:00
|
|
|
['action' => 'editmirror']);
|
2010-08-05 21:37:47 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function handle($notice)
|
|
|
|
{
|
|
|
|
// Is anybody mirroring?
|
|
|
|
$mirror = new SubMirror();
|
|
|
|
$mirror->subscribed = $notice->profile_id;
|
|
|
|
if ($mirror->find()) {
|
|
|
|
while ($mirror->fetch()) {
|
|
|
|
$mirror->repeat($notice);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 21:04:01 +01:00
|
|
|
function onPluginVersion(array &$versions)
|
2010-08-05 21:37:47 +01:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'SubMirror',
|
2019-06-03 01:56:52 +01:00
|
|
|
'version' => self::PLUGIN_VERSION,
|
2010-08-05 21:37:47 +01:00
|
|
|
'author' => 'Brion Vibber',
|
2016-01-22 16:38:42 +00:00
|
|
|
'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/SubMirror',
|
2010-08-05 21:37:47 +01:00
|
|
|
'rawdescription' =>
|
2011-06-05 23:38:38 +01:00
|
|
|
// TRANS: Plugin description.
|
2010-08-05 21:37:47 +01:00
|
|
|
_m('Pull feeds into your timeline!'));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-01-18 20:34:04 +00:00
|
|
|
* Menu item for personal subscriptions/groups area
|
2010-08-05 21:37:47 +01:00
|
|
|
*
|
2011-09-29 08:58:52 +01:00
|
|
|
* @param Action $action action being executed
|
2010-08-05 21:37:47 +01:00
|
|
|
*
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2011-09-29 08:58:52 +01:00
|
|
|
function onEndAccountSettingsNav($action)
|
2010-08-05 21:37:47 +01:00
|
|
|
{
|
|
|
|
$action_name = $action->trimmed('action');
|
|
|
|
|
2011-09-29 08:58:52 +01:00
|
|
|
common_debug("ACTION NAME = " . $action_name);
|
|
|
|
|
2010-08-05 21:37:47 +01:00
|
|
|
$action->menuItem(common_local_url('mirrorsettings'),
|
|
|
|
// TRANS: SubMirror plugin menu item on user settings page.
|
|
|
|
_m('MENU', 'Mirroring'),
|
|
|
|
// TRANS: SubMirror plugin tooltip for user settings menu item.
|
|
|
|
_m('Configure mirroring of posts from other feeds'),
|
|
|
|
$action_name === 'mirrorsettings');
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onCheckSchema()
|
|
|
|
{
|
|
|
|
$schema = Schema::get();
|
|
|
|
$schema->ensureTable('submirror', SubMirror::schemaDef());
|
2010-08-10 19:45:34 +01:00
|
|
|
|
|
|
|
// @hack until key definition support is merged
|
|
|
|
SubMirror::fixIndexes($schema);
|
2010-08-05 21:37:47 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up queue handlers for outgoing hub pushes
|
|
|
|
* @param QueueManager $qm
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
|
|
|
function onEndInitializeQueueManager(QueueManager $qm)
|
|
|
|
{
|
|
|
|
// After each notice save, check if there's any repeat mirrors.
|
|
|
|
$qm->connect('mirror', 'MirrorQueueHandler');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function onStartEnqueueNotice($notice, &$transports)
|
|
|
|
{
|
|
|
|
$transports[] = 'mirror';
|
|
|
|
}
|
|
|
|
|
2010-08-06 18:56:18 +01:00
|
|
|
/**
|
|
|
|
* Let the OStatus subscription garbage collection know if we're
|
|
|
|
* making use of a remote feed, so it doesn't get dropped out
|
|
|
|
* from under us.
|
|
|
|
*
|
|
|
|
* @param Ostatus_profile $oprofile
|
|
|
|
* @param int $count in/out
|
|
|
|
* @return mixed hook return value
|
|
|
|
*/
|
2014-05-19 16:58:05 +01:00
|
|
|
function onOstatus_profileSubscriberCount(Ostatus_profile $oprofile, &$count)
|
2010-08-06 18:56:18 +01:00
|
|
|
{
|
2014-05-19 16:58:05 +01:00
|
|
|
try {
|
|
|
|
$profile = $oprofile->localProfile();
|
2010-08-06 18:56:18 +01:00
|
|
|
$mirror = new SubMirror();
|
2014-05-19 16:58:05 +01:00
|
|
|
$mirror->subscribed = $profile->id;
|
2010-08-06 18:56:18 +01:00
|
|
|
if ($mirror->find()) {
|
|
|
|
while ($mirror->fetch()) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
2014-05-19 16:58:05 +01:00
|
|
|
} catch (NoProfileException $e) {
|
|
|
|
// We can't handle this kind of Ostatus_profile since it has no
|
|
|
|
// local profile
|
2010-08-06 18:56:18 +01:00
|
|
|
}
|
2012-01-27 20:27:46 +00:00
|
|
|
|
2010-08-06 18:56:18 +01:00
|
|
|
return true;
|
|
|
|
}
|
2011-01-18 21:32:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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',
|
2011-06-05 23:38:38 +01:00
|
|
|
// TRANS: Label in profile statistics section, followed by a count.
|
2011-01-18 21:32:12 +00:00
|
|
|
'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;
|
|
|
|
}
|
2010-08-05 21:37:47 +01:00
|
|
|
}
|