Allow users to opt out of sending linkbacks

This commit is contained in:
Stephen Paul Weber 2015-10-18 21:28:55 +00:00
parent c7e08195e4
commit 677f0ac479
2 changed files with 118 additions and 3 deletions

View File

@ -65,9 +65,14 @@ class LinkbackPlugin extends Plugin
// notice content
$c = $notice->content;
$this->notice = $notice;
// Ignoring results
common_replace_urls_callback($c,
array($this, 'linkbackUrl'));
if(!$notice->getProfile()->
getPref("linkbackplugin", "disable_linkbacks")
) {
// Ignoring results
common_replace_urls_callback($c,
array($this, 'linkbackUrl'));
}
if($notice->isRepeat()) {
$repeat = Notice::getByID($notice->repeat_of);
@ -315,4 +320,23 @@ class LinkbackPlugin extends Plugin
'or <a href="http://www.movabletype.org/docs/mttrackback.html">Trackback</a> protocols.'));
return true;
}
public function onStartInitializeRouter(URLMapper $m)
{
$m->connect('settings/linkback', array('action' => 'linkbacksettings'));
return true;
}
function onEndAccountSettingsNav($action)
{
$action_name = $action->trimmed('action');
$action->menuItem(common_local_url('linkbacksettings'),
// TRANS: OpenID plugin menu item on user settings page.
_m('MENU', 'Send Linkbacks'),
// TRANS: OpenID plugin tooltip for user settings menu item.
_m('Opt-out of sending linkbacks.'),
$action_name === 'linkbacksettings');
return true;
}
}

View File

@ -0,0 +1,91 @@
<?php
/**
* Settings for Linkback
*
* PHP version 5
*
* LICENCE: 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/>.
*
* @category Settings
* @package StatusNet
* @author Stephen Paul Weber <singpolyma@singpolyma.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
*/
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Settings for Linkback
*
* Lets users opt out of sending linkbacks
*
* @category Settings
* @author Stephen Paul Weber <singpolyma@singpolyma.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
*/
class LinkbacksettingsAction extends SettingsAction
{
/**
* Title of the page
*
* @return string Page title
*/
function title()
{
// TRANS: Title of Linkback settings page for a user.
return _m('TITLE','Linkback settings');
}
/**
* Instructions for use
*
* @return string Instructions for use
*/
function getInstructions()
{
// TRANS: Form instructions for Linkback settings.
return _m('Linkbacks inform post authors when you link to them. ' .
'You can disable this feature here.');
}
function showContent()
{
$this->elementStart('form', array('method' => 'post',
'class' => 'form_settings',
'action' =>
common_local_url('linkbacksettings')));
$this->hidden('token', common_session_token());
$this->elementStart('fieldset');
$this->element('legend', null, _m('LEGEND','Preferences'));
$this->checkbox('disable_linkbacks', "Opt out of sending linkbacks for URLs you post", $this->scoped->getPref("linkbackplugin", "disable_linkbacks"));
// TRANS: Button text to save OpenID prefs
$this->submit('settings_linkback_prefs_save', _m('BUTTON','Save'), 'submit', 'save_prefs');
$this->elementEnd('fieldset');
$this->elementEnd('form');
}
/**
* Handle a POST request
*
* @return void
*/
protected function doPost()
{
$x = $this->scoped->setPref("linkbackplugin", "disable_linkbacks", $this->boolean('disable_linkbacks'));
return _m('Linkback preferences saved.');
}
}