2010-08-06 05:37:47 +09: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-19 05:31:41 +09:00
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
|
|
|
|
2010-08-06 05:37:47 +09:00
|
|
|
/**
|
|
|
|
* @package SubMirrorPlugin
|
|
|
|
* @maintainer Brion Vibber <brion@status.net>
|
|
|
|
*/
|
|
|
|
class SubMirrorPlugin extends Plugin
|
|
|
|
{
|
2019-06-03 09:56:52 +09:00
|
|
|
const PLUGIN_VERSION = '2.0.0';
|
|
|
|
|
2010-08-06 05:37:47 +09:00
|
|
|
/**
|
|
|
|
* Hook for RouterInitialized event.
|
|
|
|
*
|
2014-11-07 23:24:05 +09:00
|
|
|
* @param URLMapper $m path-to-action mapper
|
2010-08-06 05:37:47 +09:00
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2014-11-07 23:24:05 +09:00
|
|
|
public function onRouterInitialized(URLMapper $m)
|
2010-08-06 05:37:47 +09:00
|
|
|
{
|
|
|
|
$m->connect('settings/mirror',
|
|
|
|
array('action' => 'mirrorsettings'));
|
2011-01-19 11:01:57 +09:00
|
|
|
$m->connect('settings/mirror/add/:provider',
|
|
|
|
array('action' => 'mirrorsettings'),
|
|
|
|
array('provider' => '[A-Za-z0-9_-]+'));
|
2010-08-06 05:37:47 +09:00
|
|
|
$m->connect('settings/mirror/add',
|
|
|
|
array('action' => 'addmirror'));
|
|
|
|
$m->connect('settings/mirror/edit',
|
|
|
|
array('action' => 'editmirror'));
|
|
|
|
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-07 05:04:01 +09:00
|
|
|
function onPluginVersion(array &$versions)
|
2010-08-06 05:37:47 +09:00
|
|
|
{
|
|
|
|
$versions[] = array('name' => 'SubMirror',
|
2019-06-03 09:56:52 +09:00
|
|
|
'version' => self::PLUGIN_VERSION,
|
2010-08-06 05:37:47 +09:00
|
|
|
'author' => 'Brion Vibber',
|
2016-01-23 01:38:42 +09:00
|
|
|
'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/SubMirror',
|
2010-08-06 05:37:47 +09:00
|
|
|
'rawdescription' =>
|
2011-06-06 07:38:38 +09:00
|
|
|
// TRANS: Plugin description.
|
2010-08-06 05:37:47 +09:00
|
|
|
_m('Pull feeds into your timeline!'));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-01-19 05:34:04 +09:00
|
|
|
* Menu item for personal subscriptions/groups area
|
2010-08-06 05:37:47 +09:00
|
|
|
*
|
2011-09-29 16:58:52 +09:00
|
|
|
* @param Action $action action being executed
|
2010-08-06 05:37:47 +09:00
|
|
|
*
|
|
|
|
* @return boolean hook return
|
|
|
|
*/
|
2011-09-29 16:58:52 +09:00
|
|
|
function onEndAccountSettingsNav($action)
|
2010-08-06 05:37:47 +09:00
|
|
|
{
|
|
|
|
$action_name = $action->trimmed('action');
|
|
|
|
|
2011-09-29 16:58:52 +09:00
|
|
|
common_debug("ACTION NAME = " . $action_name);
|
|
|
|
|
2010-08-06 05:37:47 +09: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-11 03:45:34 +09:00
|
|
|
|
|
|
|
// @hack until key definition support is merged
|
|
|
|
SubMirror::fixIndexes($schema);
|
2010-08-06 05:37:47 +09: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-07 02:56:18 +09: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-20 00:58:05 +09:00
|
|
|
function onOstatus_profileSubscriberCount(Ostatus_profile $oprofile, &$count)
|
2010-08-07 02:56:18 +09:00
|
|
|
{
|
2014-05-20 00:58:05 +09:00
|
|
|
try {
|
|
|
|
$profile = $oprofile->localProfile();
|
2010-08-07 02:56:18 +09:00
|
|
|
$mirror = new SubMirror();
|
2014-05-20 00:58:05 +09:00
|
|
|
$mirror->subscribed = $profile->id;
|
2010-08-07 02:56:18 +09:00
|
|
|
if ($mirror->find()) {
|
|
|
|
while ($mirror->fetch()) {
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
2014-05-20 00:58:05 +09:00
|
|
|
} catch (NoProfileException $e) {
|
|
|
|
// We can't handle this kind of Ostatus_profile since it has no
|
|
|
|
// local profile
|
2010-08-07 02:56:18 +09:00
|
|
|
}
|
2012-01-28 05:27:46 +09:00
|
|
|
|
2010-08-07 02:56:18 +09:00
|
|
|
return true;
|
|
|
|
}
|
2011-01-19 06:32:12 +09: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-06 07:38:38 +09:00
|
|
|
// TRANS: Label in profile statistics section, followed by a count.
|
2011-01-19 06:32:12 +09: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-06 05:37:47 +09:00
|
|
|
}
|