2010-03-16 21:18:37 +00:00
|
|
|
<?php
|
2019-08-12 15:03:18 +01:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social 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.
|
|
|
|
//
|
|
|
|
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
defined('STATUSNET') || die();
|
2010-03-16 21:18:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin enable action.
|
|
|
|
*
|
|
|
|
* (Re)-enables a plugin from the default plugins list.
|
|
|
|
*
|
|
|
|
* Takes parameters:
|
|
|
|
*
|
|
|
|
* - plugin: plugin name
|
|
|
|
* - token: session token to prevent CSRF attacks
|
2019-08-12 15:03:18 +01:00
|
|
|
* - ajax: bool; whether to return Ajax or full-browser results
|
2010-03-16 21:18:37 +00:00
|
|
|
*
|
|
|
|
* Only works if the current user is logged in.
|
|
|
|
*
|
|
|
|
* @category Action
|
|
|
|
* @package StatusNet
|
|
|
|
* @author Brion Vibber <brion@status.net>
|
|
|
|
* @copyright 2010 StatusNet, Inc.
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
|
|
|
|
* @link http://status.net/
|
|
|
|
*/
|
2019-08-12 15:03:18 +01:00
|
|
|
class PluginenableAction extends Action
|
2010-03-16 21:18:37 +00:00
|
|
|
{
|
|
|
|
var $user;
|
|
|
|
var $plugin;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check pre-requisites and instantiate attributes
|
|
|
|
*
|
2019-08-12 15:03:18 +01:00
|
|
|
* @param array $args array of arguments (URL, GET, POST)
|
2010-03-16 21:18:37 +00:00
|
|
|
*
|
2019-08-12 15:03:18 +01:00
|
|
|
* @return bool success flag
|
|
|
|
* @throws ClientException
|
2010-03-16 21:18:37 +00:00
|
|
|
*/
|
2019-08-12 15:03:18 +01:00
|
|
|
function prepare(array $args = [])
|
2010-03-16 21:18:37 +00:00
|
|
|
{
|
|
|
|
parent::prepare($args);
|
|
|
|
|
|
|
|
// @fixme these are pretty common, should a parent class factor these out?
|
|
|
|
|
|
|
|
// Only allow POST requests
|
|
|
|
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
2011-03-11 16:07:27 +00:00
|
|
|
// TRANS: Client error displayed when trying to use another method than POST.
|
|
|
|
// TRANS: Do not translate POST.
|
2010-03-16 21:18:37 +00:00
|
|
|
$this->clientError(_('This action only accepts POST requests.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSRF protection
|
|
|
|
|
|
|
|
$token = $this->trimmed('token');
|
|
|
|
|
|
|
|
if (!$token || $token != common_session_token()) {
|
2011-04-03 22:47:46 +01:00
|
|
|
// TRANS: Client error displayed when the session token does not match or is not given.
|
2010-03-16 21:18:37 +00:00
|
|
|
$this->clientError(_('There was a problem with your session token.'.
|
|
|
|
' Try again, please.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only for logged-in users
|
|
|
|
|
|
|
|
$this->user = common_current_user();
|
|
|
|
|
|
|
|
if (empty($this->user)) {
|
2011-04-03 23:41:21 +01:00
|
|
|
// TRANS: Error message displayed when trying to perform an action that requires a logged in user.
|
2010-03-16 21:18:37 +00:00
|
|
|
$this->clientError(_('Not logged in.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!AdminPanelAction::canAdmin('plugins')) {
|
2011-03-11 16:07:27 +00:00
|
|
|
// TRANS: Client error displayed when trying to enable or disable a plugin without access rights.
|
2010-03-16 21:18:37 +00:00
|
|
|
$this->clientError(_('You cannot administer plugins.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->plugin = $this->arg('plugin');
|
|
|
|
$defaultPlugins = common_config('plugins', 'default');
|
|
|
|
if (!array_key_exists($this->plugin, $defaultPlugins)) {
|
2011-03-11 16:07:27 +00:00
|
|
|
// TRANS: Client error displayed when trying to enable or disable a non-existing plugin.
|
2010-03-16 21:18:37 +00:00
|
|
|
$this->clientError(_('No such plugin.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle request
|
|
|
|
*
|
|
|
|
* Does the subscription and returns results.
|
|
|
|
*
|
|
|
|
* @return void
|
2019-08-12 15:03:18 +01:00
|
|
|
* @throws ClientException
|
2010-03-16 21:18:37 +00:00
|
|
|
*/
|
2016-06-01 03:05:11 +01:00
|
|
|
function handle()
|
2010-03-16 21:18:37 +00:00
|
|
|
{
|
|
|
|
$key = 'disable-' . $this->plugin;
|
|
|
|
Config::save('plugins', $key, $this->overrideValue());
|
|
|
|
|
|
|
|
// @fixme this is a pretty common pattern and should be refactored down
|
|
|
|
if ($this->boolean('ajax')) {
|
|
|
|
$this->startHTML('text/xml;charset=utf-8');
|
|
|
|
$this->elementStart('head');
|
|
|
|
$this->element('title', null, $this->successShortTitle());
|
|
|
|
$this->elementEnd('head');
|
|
|
|
$this->elementStart('body');
|
|
|
|
$form = $this->successNextForm();
|
|
|
|
$form->show();
|
|
|
|
$this->elementEnd('body');
|
2013-09-24 01:32:17 +01:00
|
|
|
$this->endHTML();
|
2010-03-16 21:18:37 +00:00
|
|
|
} else {
|
|
|
|
$url = common_local_url('pluginsadminpanel');
|
|
|
|
common_redirect($url, 303);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Value to save into $config['plugins']['disable-<name>']
|
|
|
|
*/
|
|
|
|
protected function overrideValue()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function successShortTitle()
|
|
|
|
{
|
|
|
|
// TRANS: Page title for AJAX form return when enabling a plugin.
|
|
|
|
return _m('plugin', 'Enabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function successNextForm()
|
|
|
|
{
|
2019-08-12 15:03:18 +01:00
|
|
|
return new PluginDisableForm($this, $this->plugin);
|
2010-03-16 21:18:37 +00:00
|
|
|
}
|
|
|
|
}
|