[PLUGIN API] Bug fixes and improvements

This commit is contained in:
Diogo Cordeiro 2019-08-12 15:03:18 +01:00 committed by Diogo Peralta Cordeiro
parent 99fe3e5a52
commit 3821d2317e
23 changed files with 340 additions and 456 deletions

View File

@ -1,36 +1,20 @@
<?php <?php
/** // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2010, StatusNet, Inc. // 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
* Plugin enable action. // the Free Software Foundation, either version 3 of the License, or
* // (at your option) any later version.
* 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 // GNU social is distributed in the hope that it will be useful,
* the Free Software Foundation, either version 3 of the License, or // but WITHOUT ANY WARRANTY; without even the implied warranty of
* (at your option) any later version. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* // GNU Affero General Public License for more details.
* This program is distributed in the hope that it will be useful, //
* but WITHOUT ANY WARRANTY; without even the implied warranty of // You should have received a copy of the GNU Affero General Public License
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* 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/>.
*
* PHP version 5
*
* @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/
*/
if (!defined('STATUSNET')) { defined('STATUSNET') || die();
exit(1);
}
/** /**
* Plugin enable action. * Plugin enable action.
@ -52,7 +36,7 @@ if (!defined('STATUSNET')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/ * @link http://status.net/
*/ */
class PluginDisableAction extends PluginEnableAction class PlugindisableAction extends PluginenableAction
{ {
/** /**
* Value to save into $config['plugins']['disable-<name>'] * Value to save into $config['plugins']['disable-<name>']
@ -70,6 +54,6 @@ class PluginDisableAction extends PluginEnableAction
protected function successNextForm() protected function successNextForm()
{ {
return new EnablePluginForm($this, $this->plugin); return new PluginEnableForm($this, $this->plugin);
} }
} }

View File

@ -1,36 +1,20 @@
<?php <?php
/** // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2010, StatusNet, Inc. // 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
* Plugin enable action. // the Free Software Foundation, either version 3 of the License, or
* // (at your option) any later version.
* 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 // GNU social is distributed in the hope that it will be useful,
* the Free Software Foundation, either version 3 of the License, or // but WITHOUT ANY WARRANTY; without even the implied warranty of
* (at your option) any later version. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* // GNU Affero General Public License for more details.
* This program is distributed in the hope that it will be useful, //
* but WITHOUT ANY WARRANTY; without even the implied warranty of // You should have received a copy of the GNU Affero General Public License
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* 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/>.
*
* PHP version 5
*
* @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/
*/
if (!defined('STATUSNET')) { defined('STATUSNET') || die();
exit(1);
}
/** /**
* Plugin enable action. * Plugin enable action.
@ -41,7 +25,7 @@ if (!defined('STATUSNET')) {
* *
* - plugin: plugin name * - plugin: plugin name
* - token: session token to prevent CSRF attacks * - token: session token to prevent CSRF attacks
* - ajax: boolean; whether to return Ajax or full-browser results * - ajax: bool; whether to return Ajax or full-browser results
* *
* Only works if the current user is logged in. * Only works if the current user is logged in.
* *
@ -52,7 +36,7 @@ if (!defined('STATUSNET')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/ * @link http://status.net/
*/ */
class PluginEnableAction extends Action class PluginenableAction extends Action
{ {
var $user; var $user;
var $plugin; var $plugin;
@ -60,11 +44,12 @@ class PluginEnableAction extends Action
/** /**
* Check pre-requisites and instantiate attributes * Check pre-requisites and instantiate attributes
* *
* @param Array $args array of arguments (URL, GET, POST) * @param array $args array of arguments (URL, GET, POST)
* *
* @return boolean success flag * @return bool success flag
* @throws ClientException
*/ */
function prepare(array $args = array()) function prepare(array $args = [])
{ {
parent::prepare($args); parent::prepare($args);
@ -117,9 +102,8 @@ class PluginEnableAction extends Action
* *
* Does the subscription and returns results. * Does the subscription and returns results.
* *
* @param Array $args unused.
*
* @return void * @return void
* @throws ClientException
*/ */
function handle() function handle()
{ {
@ -159,6 +143,6 @@ class PluginEnableAction extends Action
protected function successNextForm() protected function successNextForm()
{ {
return new DisablePluginForm($this, $this->plugin); return new PluginDisableForm($this, $this->plugin);
} }
} }

View File

@ -1,41 +1,26 @@
<?php <?php
/** // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet, the distributed open-source microblogging tool //
* // GNU social is free software: you can redistribute it and/or modify
* Plugins administration panel // 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
* PHP version 5 // (at your option) any later version.
* //
* LICENCE: This program is free software: you can redistribute it and/or modify // GNU social is distributed in the hope that it will be useful,
* it under the terms of the GNU Affero General Public License as published by // but WITHOUT ANY WARRANTY; without even the implied warranty of
* the Free Software Foundation, either version 3 of the License, or // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* (at your option) any later version. // GNU Affero General Public License for more details.
* //
* This program is distributed in the hope that it will be useful, // You should have received a copy of the GNU Affero General Public License
* but WITHOUT ANY WARRANTY; without even the implied warranty of // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* 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 Brion Vibber <brion@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) { defined('STATUSNET') || die();
exit(1);
}
/** /**
* Plugins settings * Plugins settings
* *
* @category Admin * @category Admin
* @package StatusNet * @package GNUsocial
* @author Brion Vibber <brion@status.net> * @author Brion Vibber <brion@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/
@ -46,6 +31,7 @@ class PluginsadminpanelAction extends AdminPanelAction
* Returns the page title * Returns the page title
* *
* @return string page title * @return string page title
* @throws Exception
*/ */
function title() function title()
{ {
@ -62,7 +48,7 @@ class PluginsadminpanelAction extends AdminPanelAction
{ {
// TRANS: Instructions at top of plugin admin page. // TRANS: Instructions at top of plugin admin page.
return _('Additional plugins can be enabled and configured manually. ' . return _('Additional plugins can be enabled and configured manually. ' .
'See the <a href="https://git.gnu.io/gnu/gnu-social/blob/master/plugins/README.md">online plugin ' . 'See the <a href="https://notabug.org/diogo/gnu-social/src/nightly/plugins/README.md">online plugin ' .
'documentation</a> for more details.'); 'documentation</a> for more details.');
} }
@ -76,7 +62,7 @@ class PluginsadminpanelAction extends AdminPanelAction
$this->elementStart('fieldset', array('id' => 'settings_plugins_default')); $this->elementStart('fieldset', array('id' => 'settings_plugins_default'));
// TRANS: Admin form section header // TRANS: Admin form section header
$this->element('legend', null, _('Default plugins'), 'default'); $this->element('legend', null, _('Default plugins'));
$this->showDefaultPlugins(); $this->showDefaultPlugins();

View File

@ -1,33 +1,20 @@
<?php <?php
/** // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2008-2011, StatusNet, Inc. // 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
* Show version information for this software and plugins // the Free Software Foundation, either version 3 of the License, or
* // (at your option) any later version.
* PHP version 5 //
* // GNU social is distributed in the hope that it will be useful,
* This program is free software: you can redistribute it and/or modify // but WITHOUT ANY WARRANTY; without even the implied warranty of
* it under the terms of the GNU Affero General Public License as published by // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* the Free Software Foundation, either version 3 of the License, or // GNU Affero General Public License for more details.
* (at your option) any later version. //
* // You should have received a copy of the GNU Affero General Public License
* This program is distributed in the hope that it will be useful, // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* 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 Info
* @package GNUsocial
* @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/
*/
if (!defined('GNUSOCIAL')) { exit(1); } defined('STATUSNET') || die();
/** /**
* Version info page * Version info page
@ -46,14 +33,14 @@ if (!defined('GNUSOCIAL')) { exit(1); }
*/ */
class VersionAction extends Action class VersionAction extends Action
{ {
var $pluginVersions = array(); var $pluginVersions = [];
/** /**
* Return true since we're read-only. * Return true since we're read-only.
* *
* @param array $args other arguments * @param array $args other arguments
* *
* @return boolean is read only action? * @return bool is read only action?
*/ */
function isReadOnly($args) function isReadOnly($args)
{ {
@ -79,9 +66,9 @@ class VersionAction extends Action
* *
* @param array $args array misc. arguments * @param array $args array misc. arguments
* *
* @return boolean true * @return bool true
*/ */
protected function prepare(array $args=array()) protected function prepare(array $args = [])
{ {
parent::prepare($args); parent::prepare($args);
@ -130,7 +117,8 @@ class VersionAction extends Action
* *
* @return void * @return void
*/ */
function showPageTitle() { function showPageTitle()
{
$this->element('h1', array('class' => 'entry-title'), $this->title()); $this->element('h1', array('class' => 'entry-title'), $this->title());
} }
@ -146,7 +134,7 @@ class VersionAction extends Action
// TRANS: Content part of engine version page. // TRANS: Content part of engine version page.
// TRANS: %1$s is the engine name (GNU social) and %2$s is the GNU social version. // TRANS: %1$s is the engine name (GNU social) and %2$s is the GNU social version.
$this->raw(sprintf(_('This site is powered by %1$s version %2$s, '. $this->raw(sprintf(_('This site is powered by %1$s version %2$s, ' .
'Copyright 2010 Free Software Foundation, Inc.'), 'Copyright 2010 Free Software Foundation, Inc.'),
XMLStringer::estring('a', array('href' => GNUSOCIAL_ENGINE_URL), XMLStringer::estring('a', array('href' => GNUSOCIAL_ENGINE_URL),
// TRANS: Engine name. // TRANS: Engine name.
@ -168,22 +156,22 @@ class VersionAction extends Action
$this->element('p', null, $this->element('p', null,
// TRANS: Content part of engine software version page. %1s is engine name // TRANS: Content part of engine software version page. %1s is engine name
sprintf(_('%1$s is free software: you can redistribute it and/or modify '. sprintf(_('%1$s is free software: you can redistribute it and/or modify ' .
'it under the terms of the GNU Affero General Public License as published by '. '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 '. 'the Free Software Foundation, either version 3 of the License, or ' .
'(at your option) any later version.'), GNUSOCIAL_ENGINE)); '(at your option) any later version.'), GNUSOCIAL_ENGINE));
$this->element('p', null, $this->element('p', null,
// TRANS: Content part of engine software version page. // TRANS: Content part of engine software version page.
_('This program is distributed in the hope that it will be useful, '. _('This program is distributed in the hope that it will be useful, ' .
'but WITHOUT ANY WARRANTY; without even the implied warranty of '. 'but WITHOUT ANY WARRANTY; without even the implied warranty of ' .
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the '. 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' .
'GNU Affero General Public License for more details.')); 'GNU Affero General Public License for more details.'));
$this->elementStart('p'); $this->elementStart('p');
// TRANS: Content part of engine version page. // TRANS: Content part of engine version page.
// TRANS: %s is a link to the AGPL license with link description "http://www.gnu.org/licenses/agpl.html". // TRANS: %s is a link to the AGPL license with link description "http://www.gnu.org/licenses/agpl.html".
$this->raw(sprintf(_('You should have received a copy of the GNU Affero General Public License '. $this->raw(sprintf(_('You should have received a copy of the GNU Affero General Public License ' .
'along with this program. If not, see %s.'), 'along with this program. If not, see %s.'),
XMLStringer::estring('a', array('href' => 'https://www.gnu.org/licenses/agpl.html'), XMLStringer::estring('a', array('href' => 'https://www.gnu.org/licenses/agpl.html'),
'https://www.gnu.org/licenses/agpl.html'))); 'https://www.gnu.org/licenses/agpl.html')));
@ -200,13 +188,13 @@ class VersionAction extends Action
$this->elementStart('thead'); $this->elementStart('thead');
$this->elementStart('tr'); $this->elementStart('tr');
// TRANS: Column header for plugins table on version page. // TRANS: Column header for plugins table on version page.
$this->element('th', array('id' => 'plugin_name'), _m('HEADER','Name')); $this->element('th', array('id' => 'plugin_name'), _m('HEADER', 'Name'));
// TRANS: Column header for plugins table on version page. // TRANS: Column header for plugins table on version page.
$this->element('th', array('id' => 'plugin_version'), _m('HEADER','Version')); $this->element('th', array('id' => 'plugin_version'), _m('HEADER', 'Version'));
// TRANS: Column header for plugins table on version page. // TRANS: Column header for plugins table on version page.
$this->element('th', array('id' => 'plugin_authors'), _m('HEADER','Author(s)')); $this->element('th', array('id' => 'plugin_authors'), _m('HEADER', 'Author(s)'));
// TRANS: Column header for plugins table on version page. // TRANS: Column header for plugins table on version page.
$this->element('th', array('id' => 'plugin_description'), _m('HEADER','Description')); $this->element('th', array('id' => 'plugin_description'), _m('HEADER', 'Description'));
$this->elementEnd('tr'); $this->elementEnd('tr');
$this->elementEnd('thead'); $this->elementEnd('thead');

View File

@ -124,9 +124,9 @@ class Cache
if (empty($prefix)) { if (empty($prefix)) {
$names = array(); $names = [];
foreach (GNUsocial::getActivePlugins() as $plugin=>$attrs) { foreach (GNUsocial::getActiveModules() as $plugin => $attrs) {
$names[] = $plugin; $names[] = $plugin;
} }

View File

@ -78,7 +78,7 @@ class Event {
* @param string $name Name of the event that's happening * @param string $name Name of the event that's happening
* @param array $args Arguments for handlers * @param array $args Arguments for handlers
* *
* @return boolean flag saying whether to continue processing, based * @return bool flag saying whether to continue processing, based
* on results of handlers. * on results of handlers.
*/ */
@ -104,7 +104,7 @@ class Event {
* @param string $name Name of the event to look for * @param string $name Name of the event to look for
* @param string $plugin Optional name of the plugin class to look for * @param string $plugin Optional name of the plugin class to look for
* *
* @return boolean flag saying whether such a handler exists * @return bool flag saying whether such a handler exists
* *
*/ */

View File

@ -197,4 +197,3 @@ function PEAR_ErrorToPEAR_Exception(PEAR_Error $err)
} }
throw new PEAR_Exception($err->getMessage()); throw new PEAR_Exception($err->getMessage());
} }

View File

@ -23,68 +23,67 @@ global $config, $_server, $_path;
*/ */
class GNUsocial class GNUsocial
{ {
protected static $config_files = array(); protected static $config_files = [];
protected static $have_config; protected static $have_config;
protected static $is_api; protected static $is_api;
protected static $is_ajax; protected static $is_ajax;
protected static $plugins = array(); protected static $plugins = [];
/** /**
* Configure and instantiate a plugin (or a core module) into the current configuration. * Configure and instantiate a plugin (or a core module) into the current configuration.
* Class definitions will be loaded from standard paths if necessary. * Class definitions will be loaded from standard paths if necessary.
* Note that initialization events won't be fired until later. * Note that initialization events won't be fired until later.
* *
* @param string $name class name & plugin file/subdir name * @param string $name class name & module file/subdir name
* @param array $attrs key/value pairs of public attributes to set on plugin instance * @param array $attrs key/value pairs of public attributes to set on module instance
* *
* @throws ServerException if plugin can't be found * @return bool
* @throws ServerException if module can't be found
*/ */
public static function addPlugin($name, array $attrs = []) public static function addPlugin(string $name, array $attrs = [])
{ {
$name = ucfirst($name); $name = ucfirst($name);
if (isset(self::$plugins[$name])) { if (isset(self::$plugins[$name])) {
// We have already loaded this plugin. Don't try to // We have already loaded this module. Don't try to
// do it again with (possibly) different values. // do it again with (possibly) different values.
// Försten till kvarn får mala. // Försten till kvarn får mala.
return true; return true;
} }
$pluginclass = "{$name}Plugin"; $moduleclass = "{$name}Plugin";
if (!class_exists($pluginclass)) { if (!class_exists($moduleclass)) {
$files = [ $files = [
"local/plugins/{$pluginclass}.php", "local/plugins/{$moduleclass}.php",
"local/plugins/{$name}/{$pluginclass}.php", "local/plugins/{$name}/{$moduleclass}.php",
"local/{$pluginclass}.php", "modules/{$moduleclass}.php",
"local/{$name}/{$pluginclass}.php", "modules/{$name}/{$moduleclass}.php",
"modules/{$pluginclass}.php", "plugins/{$moduleclass}.php",
"modules/{$name}/{$pluginclass}.php", "plugins/{$name}/{$moduleclass}.php"
"plugins/{$pluginclass}.php",
"plugins/{$name}/{$pluginclass}.php"
]; ];
foreach ($files as $file) { foreach ($files as $file) {
$fullpath = INSTALLDIR.'/'.$file; $fullpath = INSTALLDIR . '/' . $file;
if (@file_exists($fullpath)) { if (@file_exists($fullpath)) {
include_once($fullpath); include_once($fullpath);
break; break;
} }
} }
if (!class_exists($pluginclass)) { if (!class_exists($moduleclass)) {
throw new ServerException("Plugin $name not found.", 500); throw new ServerException("Plugin $name not found.", 500);
} }
} }
// Doesn't this $inst risk being garbage collected or something? // Doesn't this $inst risk being garbage collected or something?
// TODO: put into a static array that makes sure $inst isn't lost. // TODO: put into a static array that makes sure $inst isn't lost.
$inst = new $pluginclass(); $inst = new $moduleclass();
foreach ($attrs as $aname => $avalue) { foreach ($attrs as $aname => $avalue) {
$inst->$aname = $avalue; $inst->$aname = $avalue;
} }
// Record activated plugins for later display/config dump // Record activated modules for later display/config dump
self::$plugins[$name] = $attrs; self::$plugins[$name] = $attrs;
return true; return true;
@ -92,20 +91,20 @@ class GNUsocial
public static function delPlugin($name) public static function delPlugin($name)
{ {
// Remove our plugin if it was previously loaded // Remove our module if it was previously loaded
$name = ucfirst($name); $name = ucfirst($name);
if (isset(self::$plugins[$name])) { if (isset(self::$plugins[$name])) {
unset(self::$plugins[$name]); unset(self::$plugins[$name]);
} }
// make sure initPlugins will avoid this // make sure initPlugins will avoid this
common_config_set('plugins', 'disable-'.$name, true); common_config_set('plugins', 'disable-' . $name, true);
return true; return true;
} }
/** /**
* Get a list of activated plugins in this process. * Get a list of activated modules in this process.
* @return array of (string $name, array $args) pairs * @return array of (string $name, array $args) pairs
*/ */
public static function getActivePlugins() public static function getActivePlugins()
@ -115,7 +114,7 @@ class GNUsocial
/** /**
* Initialize, or re-initialize, GNU social global configuration * Initialize, or re-initialize, GNU social global configuration
* and plugins. * and modules.
* *
* If switching site configurations during script execution, be * If switching site configurations during script execution, be
* careful when working with leftover objects -- global settings * careful when working with leftover objects -- global settings
@ -125,9 +124,11 @@ class GNUsocial
* @param $path optional URL path for picking config * @param $path optional URL path for picking config
* @param $conffile optional configuration file path * @param $conffile optional configuration file path
* *
* @throws ConfigException
* @throws NoConfigException if config file can't be found * @throws NoConfigException if config file can't be found
* @throws ServerException
*/ */
public static function init($server=null, $path=null, $conffile=null) public static function init($server = null, $path = null, $conffile = null)
{ {
Router::clear(); Router::clear();
@ -165,6 +166,10 @@ class GNUsocial
* site is missing or configured incorrectly. * site is missing or configured incorrectly.
* *
* @param string $nickname * @param string $nickname
* @return bool
* @throws ConfigException
* @throws NoConfigException
* @throws ServerException
*/ */
public static function switchSite($nickname) public static function switchSite($nickname)
{ {
@ -175,7 +180,7 @@ class GNUsocial
$sn = Status_network::getKV('nickname', $nickname); $sn = Status_network::getKV('nickname', $nickname);
if (empty($sn)) { if (empty($sn)) {
return false; return false;
throw new Exception("No such site nickname '$nickname'"); //throw new Exception("No such site nickname '$nickname'");
} }
$server = $sn->getServerName(); $server = $sn->getServerName();
@ -191,7 +196,7 @@ class GNUsocial
*/ */
public static function findAllSites() public static function findAllSites()
{ {
$sites = array(); $sites = [];
$sn = new Status_network(); $sn = new Status_network();
$sn->find(); $sn->find();
while ($sn->fetch()) { while ($sn->fetch()) {
@ -205,11 +210,11 @@ class GNUsocial
*/ */
protected static function initPlugins() protected static function initPlugins()
{ {
// User config may have already added some of these plugins, with // User config may have already added some of these modules, with
// maybe configured parameters. The self::addPlugin function will // maybe configured parameters. The self::addModule function will
// ignore the new call if it has already been instantiated. // ignore the new call if it has already been instantiated.
// Load core plugins // Load core modules
foreach (common_config('plugins', 'core') as $name => $params) { foreach (common_config('plugins', 'core') as $name => $params) {
call_user_func('self::addPlugin', $name, $params); call_user_func('self::addPlugin', $name, $params);
} }
@ -221,11 +226,6 @@ class GNUsocial
continue; continue;
} }
// TODO: We should be able to avoid this is_null and assume $params
// is an array, since that's how it is typed in addPlugin
if (is_null($params)) {
self::addPlugin($name);
} else if (is_array($params)) {
if (count($params) == 0) { if (count($params) == 0) {
self::addPlugin($name); self::addPlugin($name);
} else { } else {
@ -239,14 +239,13 @@ class GNUsocial
} }
} }
} }
}
// XXX: if plugins should check the schema at runtime, do that here. // XXX: if modules should check the schema at runtime, do that here.
if (common_config('db', 'schemacheck') == 'runtime') { if (common_config('db', 'schemacheck') == 'runtime') {
Event::handle('CheckSchema'); Event::handle('CheckSchema');
} }
// Give plugins a chance to initialize in a fully-prepared environment // Give modules a chance to initialize in a fully-prepared environment
Event::handle('InitializePlugin'); Event::handle('InitializePlugin');
} }
@ -298,7 +297,7 @@ class GNUsocial
protected static function defaultConfig() protected static function defaultConfig()
{ {
global $_server, $_path; global $_server, $_path;
require(INSTALLDIR.'/lib/default.php'); require(INSTALLDIR . '/lib/default.php');
return $default; return $default;
} }
@ -311,7 +310,7 @@ class GNUsocial
global $_server, $_path, $config, $_PEAR; global $_server, $_path, $config, $_PEAR;
Event::clearHandlers(); Event::clearHandlers();
self::$plugins = array(); self::$plugins = [];
// try to figure out where we are. $server and $path // try to figure out where we are. $server and $path
// can be set by including module, else we guess based // can be set by including module, else we guess based
@ -340,7 +339,7 @@ class GNUsocial
// default configuration, overwritten in config.php // default configuration, overwritten in config.php
// Keep DB_DataObject's db config synced to ours... // Keep DB_DataObject's db config synced to ours...
$config['db'] = &$_PEAR->getStaticProperty('DB_DataObject','options'); $config['db'] = &$_PEAR->getStaticProperty('DB_DataObject', 'options');
$config['db'] = $default['db']; $config['db'] = $default['db'];
} }
@ -366,11 +365,12 @@ class GNUsocial
/** /**
* Load the default or specified configuration file. * Load the default or specified configuration file.
* Modifies global $config and may establish plugins. * Modifies global $config and may establish modules.
* *
* @throws NoConfigException * @throws NoConfigException
* @throws ServerException
*/ */
protected static function loadConfigFile($conffile=null) protected static function loadConfigFile($conffile = null)
{ {
global $_server, $_path, $config; global $_server, $_path, $config;
@ -379,16 +379,16 @@ class GNUsocial
// finally for a dir (usually only need one of the last two). // finally for a dir (usually only need one of the last two).
if (isset($conffile)) { if (isset($conffile)) {
$config_files = array($conffile); $config_files = [$conffile];
} else { } else {
$config_files = array('/etc/gnusocial/config.php', $config_files = ['/etc/gnusocial/config.php',
'/etc/gnusocial/config.d/'.$_server.'.php'); '/etc/gnusocial/config.d/' . $_server . '.php'];
if (strlen($_path) > 0) { if (strlen($_path) > 0) {
$config_files[] = '/etc/gnusocial/config.d/'.$_server.'_'.$_path.'.php'; $config_files[] = '/etc/gnusocial/config.d/' . $_server . '_' . $_path . '.php';
} }
$config_files[] = INSTALLDIR.'/config.php'; $config_files[] = INSTALLDIR . '/config.php';
} }
self::$have_config = false; self::$have_config = false;
@ -449,15 +449,15 @@ class GNUsocial
} }
// try to create those that are not directories // try to create those that are not directories
foreach ($mkdirs as $dir=>$description) { foreach ($mkdirs as $dir => $description) {
if (is_file($dir)) { if (is_file($dir)) {
throw new ConfigException('Expected directory for '._ve($description).' is a file!'); throw new ConfigException('Expected directory for ' . _ve($description) . ' is a file!');
} }
if (!mkdir($dir)) { if (!mkdir($dir)) {
throw new ConfigException('Could not create directory for '._ve($description).': '._ve($dir)); throw new ConfigException('Could not create directory for ' . _ve($description) . ': ' . _ve($dir));
} }
if (!chmod($dir, 0775)) { if (!chmod($dir, 0775)) {
common_log(LOG_WARNING, 'Could not chmod 0775 on directory for '._ve($description).': '._ve($dir)); common_log(LOG_WARNING, 'Could not chmod 0775 on directory for ' . _ve($description) . ': ' . _ve($dir));
} }
} }
@ -500,7 +500,8 @@ class NoConfigException extends Exception
{ {
public $configFiles; public $configFiles;
function __construct($msg, $configFiles) { function __construct($msg, $configFiles)
{
parent::__construct($msg); parent::__construct($msg);
$this->configFiles = $configFiles; $this->configFiles = $configFiles;
} }

View File

@ -23,7 +23,7 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* @package Activity * @package Activity
* @maintainer Mikael Nordfeldth <mmn@hethane.se> * @maintainer Mikael Nordfeldth <mmn@hethane.se>
*/ */
abstract class ActivityVerbHandlerPlugin extends ActivityHandlerPlugin abstract class ActivityVerbHandlerModule extends ActivityHandlerPlugin
{ {
public function onActivityVerbTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped, &$title) public function onActivityVerbTitle(ManagedAction $action, $verb, Notice $target, Profile $scoped, &$title)
{ {

View File

@ -32,8 +32,8 @@ if (!defined('GNUSOCIAL')) { exit(1); }
/** /**
* Superclass for plugins that do authentication * Superclass for plugins that do authentication
* *
* @category Plugin * @category Module
* @package StatusNet * @package GNUsocial
* @author Craig Andrews <candrews@integralblue.com> * @author Craig Andrews <candrews@integralblue.com>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/

View File

@ -34,8 +34,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
/** /**
* Superclass for plugins that do authorization * Superclass for plugins that do authorization
* *
* @category Plugin * @category Module
* @package StatusNet * @package GNUsocial
* @author Craig Andrews <candrews@integralblue.com> * @author Craig Andrews <candrews@integralblue.com>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/

View File

@ -36,8 +36,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
* Implementations will likely want to override onStartIoManagerClasses() so that their * Implementations will likely want to override onStartIoManagerClasses() so that their
* IO manager is used * IO manager is used
* *
* @category Plugin * @category Module
* @package StatusNet * @package GNUsocial
* @author Craig Andrews <candrews@integralblue.com> * @author Craig Andrews <candrews@integralblue.com>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/

View File

@ -42,13 +42,13 @@ if (!defined('STATUSNET')) {
* The applications work more-or-less like other * The applications work more-or-less like other
* *
* @category Microapp * @category Microapp
* @package StatusNet * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2011 StatusNet, Inc. * @copyright 2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
abstract class MicroAppPlugin extends ActivityHandlerPlugin abstract class MicroAppModule extends ActivityHandlerPlugin
{ {
/** /**
* Returns a localized string which represents this micro-app, * Returns a localized string which represents this micro-app,

View File

@ -17,7 +17,7 @@
defined('GNUSOCIAL') || die(); defined('GNUSOCIAL') || die();
/** /**
* Base class for plugins * Base class for modules
* *
* A base class for GNU social modules. Mostly a light wrapper around * A base class for GNU social modules. Mostly a light wrapper around
* the Event framework. * the Event framework.
@ -29,8 +29,8 @@ defined('GNUSOCIAL') || die();
* They will also automatically handle the InitializePlugin and CleanupPlugin with the * They will also automatically handle the InitializePlugin and CleanupPlugin with the
* initialize() and cleanup() methods, respectively. * initialize() and cleanup() methods, respectively.
* *
* @category Plugin * @category Module
* @package GNU social * @package GNUsocial
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @copyright 2010-2019 Free Software Foundation, Inc http://www.fsf.org * @copyright 2010-2019 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
@ -39,10 +39,10 @@ defined('GNUSOCIAL') || die();
*/ */
class Plugin class Plugin
{ {
function __construct() public function __construct()
{ {
Event::addHandler('InitializePlugin', array($this, 'initialize')); Event::addHandler('InitializePlugin', [$this, 'initialize']);
Event::addHandler('CleanupPlugin', array($this, 'cleanup')); Event::addHandler('CleanupPlugin', [$this, 'cleanup']);
foreach (get_class_methods($this) as $method) { foreach (get_class_methods($this) as $method) {
if (mb_substr($method, 0, 2) == 'on') { if (mb_substr($method, 0, 2) == 'on') {
@ -53,12 +53,12 @@ class Plugin
$this->setupGettext(); $this->setupGettext();
} }
function initialize() public function initialize()
{ {
return true; return true;
} }
function cleanup() public function cleanup()
{ {
return true; return true;
} }
@ -81,7 +81,8 @@ class Plugin
* *
* @return bool hook value; true means continue processing, false means stop. * @return bool hook value; true means continue processing, false means stop.
*/ */
public function onAutoload($cls) { public function onAutoload($cls)
{
$cls = basename($cls); $cls = basename($cls);
$basedir = INSTALLDIR . '/local/plugins/' . mb_substr(get_called_class(), 0, -6); $basedir = INSTALLDIR . '/local/plugins/' . mb_substr(get_called_class(), 0, -6);
if (!file_exists($basedir)) { if (!file_exists($basedir)) {
@ -124,7 +125,7 @@ class Plugin
protected function setupGettext() protected function setupGettext()
{ {
$class = get_class($this); $class = get_class($this);
if (substr($class, -6) == 'Plugin') { if (substr($class, -6) == 'Module') {
$name = substr($class, 0, -6); $name = substr($class, 0, -6);
$path = common_config('plugins', 'locale_path'); $path = common_config('plugins', 'locale_path');
if (!$path) { if (!$path) {
@ -147,7 +148,7 @@ class Plugin
protected function log($level, $msg) protected function log($level, $msg)
{ {
common_log($level, get_class($this) . ': '.$msg); common_log($level, get_class($this) . ': ' . $msg);
} }
protected function debug($msg) protected function debug($msg)
@ -166,12 +167,13 @@ class Plugin
return GNUSOCIAL_VERSION; return GNUSOCIAL_VERSION;
} }
protected function userAgent() { protected function userAgent()
{
return HTTPClient::userAgent() return HTTPClient::userAgent()
. ' (' . get_class($this) . ' v' . $this->version() . ')'; . ' (' . get_class($this) . ' v' . $this->version() . ')';
} }
function onPluginVersion(array &$versions) public function onModuleVersion(array &$versions)
{ {
$name = $this->name(); $name = $this->name();
@ -182,12 +184,12 @@ class Plugin
return true; return true;
} }
function path($relative) public function path($relative)
{ {
return self::staticPath($this->name(), $relative); return self::staticPath($this->name(), $relative);
} }
static function staticPath($plugin, $relative) public static function staticPath($module, $relative)
{ {
if (GNUsocial::useHTTPS()) { if (GNUsocial::useHTTPS()) {
$server = common_config('plugins', 'sslserver'); $server = common_config('plugins', 'sslserver');
@ -212,25 +214,25 @@ class Plugin
if (empty($path)) { if (empty($path)) {
// XXX: extra stat(). // XXX: extra stat().
if (@file_exists(PUBLICDIR . '/local/plugins/' . $plugin . '/' . $relative)) { if (@file_exists(PUBLICDIR . '/local/plugins/' . $module . '/' . $relative)) {
$path = common_config('site', 'path') . '/local/plugins/'; $path = common_config('site', 'path') . '/local/plugins/';
} elseif (@file_exists(PUBLICDIR . '/modules/' . $plugin . '/' . $relative)) { } elseif (@file_exists(PUBLICDIR . '/modules/' . $module . '/' . $relative)) {
$path = common_config('site', 'path') . '/modules/'; $path = common_config('site', 'path') . '/modules/';
} else { } else {
$path = common_config('site', 'path') . '/plugins/'; $path = common_config('site', 'path') . '/plugins/';
} }
} }
if ($path[strlen($path)-1] != '/') { if ($path[strlen($path) - 1] != '/') {
$path .= '/'; $path .= '/';
} }
if ($path[0] != '/') { if ($path[0] != '/') {
$path = '/'.$path; $path = '/' . $path;
} }
$protocol = GNUsocial::useHTTPS() ? 'https' : 'http'; $protocol = GNUsocial::useHTTPS() ? 'https' : 'http';
return $protocol.'://'.$server.$path.$plugin.'/'.$relative; return $protocol . '://' . $server . $path . $module . '/' . $relative;
} }
} }

View File

@ -44,8 +44,8 @@ if (!defined('STATUSNET')) {
* Leaderboard 728x90 * Leaderboard 728x90
* Wide Skyscraper 160x600 * Wide Skyscraper 160x600
* *
* @category Plugin * @category Module
* @package StatusNet * @package GNUsocial
* @author Sarven Capadisli <csarven@status.net> * @author Sarven Capadisli <csarven@status.net>
* @author Evan Prodromou <evan@status.net> * @author Evan Prodromou <evan@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0

View File

@ -33,8 +33,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
/** /**
* Superclass for plugins that do URL shortening * Superclass for plugins that do URL shortening
* *
* @category Plugin * @category Module
* @package StatusNet * @package GNUsocial
* @author Craig Andrews <candrews@integralblue.com> * @author Craig Andrews <candrews@integralblue.com>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/

View File

@ -1,34 +1,20 @@
<?php <?php
/** // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet, the distributed open-source microblogging tool //
* // GNU social is free software: you can redistribute it and/or modify
* Form for enabling/disabling plugins // 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
* PHP version 5 // (at your option) any later version.
* //
* LICENCE: This program is free software: you can redistribute it and/or modify // GNU social is distributed in the hope that it will be useful,
* it under the terms of the GNU Affero General Public License as published by // but WITHOUT ANY WARRANTY; without even the implied warranty of
* the Free Software Foundation, either version 3 of the License, or // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* (at your option) any later version. // GNU Affero General Public License for more details.
* //
* This program is distributed in the hope that it will be useful, // You should have received a copy of the GNU Affero General Public License
* but WITHOUT ANY WARRANTY; without even the implied warranty of // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* 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 Form
* @package StatusNet
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET') && !defined('LACONICA')) { defined('STATUSNET') || die();
exit(1);
}
/** /**
* Form for joining a group * Form for joining a group
@ -41,7 +27,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
* *
* @see PluginEnableForm * @see PluginEnableForm
*/ */
class PluginDisableForm extends PluginEnableForm class PluginDisableForm extends PluginEnableForm
{ {
/** /**
@ -50,7 +35,7 @@ class PluginDisableForm extends PluginEnableForm
* @return string ID of the form * @return string ID of the form
*/ */
function id() public function id()
{ {
return 'plugin-disable-' . $this->plugin; return 'plugin-disable-' . $this->plugin;
} }
@ -61,7 +46,7 @@ class PluginDisableForm extends PluginEnableForm
* @return string of the form class * @return string of the form class
*/ */
function formClass() public function formClass()
{ {
return 'form_plugin_disable'; return 'form_plugin_disable';
} }
@ -72,22 +57,24 @@ class PluginDisableForm extends PluginEnableForm
* @return string URL of the action * @return string URL of the action
*/ */
function action() public function action()
{ {
return common_local_url('plugindisable', return common_local_url(
array('plugin' => $this->plugin)); 'plugindisable',
['plugin' => $this->plugin]
);
} }
/** /**
* Action elements * Action elements
* *
* @return void * @return void
* @throws Exception
*/ */
function formActions() public function formActions()
{ {
// TRANS: Plugin admin panel controls // TRANS: Plugin admin panel controls
$this->out->submit('submit', _m('plugin', 'Disable')); $this->out->submit('submit', _m('plugin', 'Disable'));
} }
} }

View File

@ -1,36 +1,22 @@
<?php <?php
/** // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet, the distributed open-source microblogging tool //
* // GNU social is free software: you can redistribute it and/or modify
* Form for enabling/disabling plugins // 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
* PHP version 5 // (at your option) any later version.
* //
* LICENCE: This program is free software: you can redistribute it and/or modify // GNU social is distributed in the hope that it will be useful,
* it under the terms of the GNU Affero General Public License as published by // but WITHOUT ANY WARRANTY; without even the implied warranty of
* the Free Software Foundation, either version 3 of the License, or // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* (at your option) any later version. // GNU Affero General Public License for more details.
* //
* This program is distributed in the hope that it will be useful, // You should have received a copy of the GNU Affero General Public License
* but WITHOUT ANY WARRANTY; without even the implied warranty of // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* 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 Form
* @package StatusNet
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET') && !defined('LACONICA')) { defined('STATUSNET') || die();
exit(1);
}
require_once INSTALLDIR.'/lib/form.php'; require_once INSTALLDIR . '/lib/form.php';
/** /**
* Form for joining a group * Form for joining a group
@ -43,14 +29,13 @@ require_once INSTALLDIR.'/lib/form.php';
* *
* @see PluginDisableForm * @see PluginDisableForm
*/ */
class PluginEnableForm extends Form class PluginEnableForm extends Form
{ {
/** /**
* Plugin to enable/disable * Plugin to enable/disable
*/ */
var $plugin = null; public $plugin = null;
/** /**
* Constructor * Constructor
@ -59,7 +44,7 @@ class PluginEnableForm extends Form
* @param string $plugin plugin to enable/disable * @param string $plugin plugin to enable/disable
*/ */
function __construct($out=null, $plugin=null) public function __construct($out = null, $plugin = null)
{ {
parent::__construct($out); parent::__construct($out);
@ -72,7 +57,7 @@ class PluginEnableForm extends Form
* @return string ID of the form * @return string ID of the form
*/ */
function id() public function id()
{ {
return 'plugin-enable-' . $this->plugin; return 'plugin-enable-' . $this->plugin;
} }
@ -83,7 +68,7 @@ class PluginEnableForm extends Form
* @return string of the form class * @return string of the form class
*/ */
function formClass() public function formClass()
{ {
return 'form_plugin_enable'; return 'form_plugin_enable';
} }
@ -94,19 +79,22 @@ class PluginEnableForm extends Form
* @return string URL of the action * @return string URL of the action
*/ */
function action() public function action()
{ {
return common_local_url('pluginenable', return common_local_url(
array('plugin' => $this->plugin)); 'pluginenable',
['plugin' => $this->plugin]
);
} }
/** /**
* Action elements * Action elements
* *
* @return void * @return void
* @throws Exception
*/ */
function formActions() public function formActions()
{ {
// TRANS: Plugin admin panel controls // TRANS: Plugin admin panel controls
$this->out->submit('submit', _m('plugin', 'Enable')); $this->out->submit('submit', _m('plugin', 'Enable'));

View File

@ -1,35 +1,20 @@
<?php <?php
/** // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet, the distributed open-source microblogging tool //
* // GNU social is free software: you can redistribute it and/or modify
* Plugins administration panel // 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
* PHP version 5 // (at your option) any later version.
* //
* LICENCE: This program is free software: you can redistribute it and/or modify // GNU social is distributed in the hope that it will be useful,
* it under the terms of the GNU Affero General Public License as published by // but WITHOUT ANY WARRANTY; without even the implied warranty of
* the Free Software Foundation, either version 3 of the License, or // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* (at your option) any later version. // GNU Affero General Public License for more details.
* //
* This program is distributed in the hope that it will be useful, // You should have received a copy of the GNU Affero General Public License
* but WITHOUT ANY WARRANTY; without even the implied warranty of // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
* 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 Brion Vibber <brion@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET')) { defined('STATUSNET') || die();
exit(1);
}
require INSTALLDIR . "/lib/pluginenableform.php"; require INSTALLDIR . "/lib/pluginenableform.php";
require INSTALLDIR . "/lib/plugindisableform.php"; require INSTALLDIR . "/lib/plugindisableform.php";
@ -38,39 +23,39 @@ require INSTALLDIR . "/lib/plugindisableform.php";
* Plugin list * Plugin list
* *
* @category Admin * @category Admin
* @package StatusNet * @package GNUsocial
* @author Brion Vibber <brion@status.net> * @author Brion Vibber <brion@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class PluginList extends Widget class PluginList extends Widget
{ {
var $plugins = array(); public $plugins = [];
function __construct($plugins, $out) public function __construct($plugins, $out)
{ {
parent::__construct($out); parent::__construct($out);
$this->plugins = $plugins; $this->plugins = $plugins;
} }
function show() public function show()
{ {
$this->startList(); $this->startList();
$this->showPlugins(); $this->showPlugins();
$this->endList(); $this->endList();
} }
function startList() public function startList()
{ {
$this->out->elementStart('table', 'plugin_list'); $this->out->elementStart('table', 'plugin_list');
} }
function endList() public function endList()
{ {
$this->out->elementEnd('table'); $this->out->elementEnd('table');
} }
function showPlugins() public function showPlugins()
{ {
foreach ($this->plugins as $plugin) { foreach ($this->plugins as $plugin) {
$pli = $this->newListItem($plugin); $pli = $this->newListItem($plugin);
@ -78,7 +63,7 @@ class PluginList extends Widget
} }
} }
function newListItem($plugin) public function newListItem($plugin)
{ {
return new PluginListItem($plugin, $this->out); return new PluginListItem($plugin, $this->out);
} }
@ -87,18 +72,18 @@ class PluginList extends Widget
class PluginListItem extends Widget class PluginListItem extends Widget
{ {
/** Current plugin. */ /** Current plugin. */
var $plugin = null; public $plugin = null;
/** Local cache for plugin version info */ /** Local cache for plugin version info */
protected static $versions = false; protected static $versions = false;
function __construct($plugin, $out) public function __construct($plugin, $out)
{ {
parent::__construct($out); parent::__construct($out);
$this->plugin = $plugin; $this->plugin = $plugin;
} }
function show() public function show()
{ {
$meta = $this->metaInfo(); $meta = $this->metaInfo();
@ -139,6 +124,8 @@ class PluginListItem extends Widget
$this->out->elementStart('td'); $this->out->elementStart('td');
if (!empty($meta['rawdescription'])) { if (!empty($meta['rawdescription'])) {
$this->out->raw($meta['rawdescription']); $this->out->raw($meta['rawdescription']);
} elseif (!empty($meta['description'])) {
$this->out->raw($meta['description']);
} }
$this->out->elementEnd('td'); $this->out->elementEnd('td');
@ -168,18 +155,19 @@ class PluginListItem extends Widget
* *
* @fixme pull structured data from plugin source * @fixme pull structured data from plugin source
*/ */
function metaInfo() public function metaInfo()
{ {
$versions = self::getPluginVersions(); $versions = self::getPluginVersions();
$found = false; $found = false;
foreach ($versions as $info) { foreach ($versions as $info) {
// hack for URL shorteners... "LilUrl (ur1.ca)" etc // We need a proper name for comparison, that is, without spaces nor the `(section)`
list($name, ) = explode(' ', $info['name']); // Therefore, a plugin named "Diogo Cordeiro (diogo@fc.up.pt)" becomes "DiogoCordeiro"
$name_without_spaces = str_replace(' ', '', $info['name']);
$name_without_spaces_nor_parentheses_section = substr($name_without_spaces, 0, strpos($name_without_spaces.'(', '('));
if ($name == $this->plugin) { if (strtolower($name_without_spaces_nor_parentheses_section) == strtolower($this->plugin)) {
if ($found) { if ($found) {
// hack for URL shorteners...
$found['rawdescription'] .= "<br />\n" . $info['rawdescription']; $found['rawdescription'] .= "<br />\n" . $info['rawdescription'];
} else { } else {
$found = $info; $found = $info;
@ -190,9 +178,9 @@ class PluginListItem extends Widget
if ($found) { if ($found) {
return $found; return $found;
} else { } else {
return array('name' => $this->plugin, return ['name' => $this->plugin,
// TRANS: Plugin description for a disabled plugin. // TRANS: Plugin description for a disabled plugin.
'rawdescription' => _m('plugin-description','(The plugin description is unavailable when a plugin has been disabled.)')); 'rawdescription' => _m('plugin-description', '(The plugin description is unavailable when a plugin has been disabled.)')];
} }
} }
@ -203,8 +191,8 @@ class PluginListItem extends Widget
protected static function getPluginVersions() protected static function getPluginVersions()
{ {
if (!is_array(self::$versions)) { if (!is_array(self::$versions)) {
$versions = array(); $versions = [];
Event::handle('PluginVersion', array(&$versions)); Event::handle('ModuleVersion', [&$versions]);
self::$versions = $versions; self::$versions = $versions;
} }
return self::$versions; return self::$versions;

View File

@ -1,35 +1,32 @@
<?php <?php
/* // This file is part of GNU social - https://www.gnu.org/software/social
* StatusNet - the distributed open-source microblogging tool //
* Copyright (C) 2008, 2009, StatusNet, Inc. // 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
* This program is free software: you can redistribute it and/or modify // the Free Software Foundation, either version 3 of the License, or
* it under the terms of the GNU Affero General Public License as published by // (at your option) any later version.
* 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
* This program is distributed in the hope that it will be useful, // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* but WITHOUT ANY WARRANTY; without even the implied warranty of // GNU Affero General Public License for more details.
* 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/>.
* 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/>.
*/
defined('GNUSOCIAL') || die(); defined('GNUSOCIAL') || die();
/** /**
* Queue handler for letting plugins handle stuff. * Queue handler for letting modules handle stuff.
* *
* The plugin queue handler accepts notices over the "plugin" queue * The module queue handler accepts notices over the "module" queue
* and simply passes them through the "HandleQueuedNotice" event. * and simply passes them through the "HandleQueuedNotice" event.
* *
* This gives plugins a chance to do background processing without * This gives plugins a chance to do background processing without
* actually registering their own queue and ensuring that things * actually registering their own queue and ensuring that things
* are queued into it. * are queued into it.
* *
* Fancier plugins may wish to instead hook the 'GetQueueHandlerClass' * Fancier modules may wish to instead hook the 'GetQueueHandlerClass'
* event with their own class, in which case they must ensure that * event with their own class, in which case they must ensure that
* their notices get enqueued when they need them. * their notices get enqueued when they need them.
*/ */
@ -40,7 +37,7 @@ class PluginQueueHandler extends QueueHandler
return 'plugin'; return 'plugin';
} }
function handle($notice) : bool function handle($notice): bool
{ {
if (!($notice instanceof Notice)) { if (!($notice instanceof Notice)) {
common_log(LOG_ERR, "Got a bogus notice, not broadcasting"); common_log(LOG_ERR, "Got a bogus notice, not broadcasting");

View File

@ -294,7 +294,7 @@ abstract class QueueManager extends IoManager
$this->connect('actmove', 'ActivityMover'); $this->connect('actmove', 'ActivityMover');
// For compat with old plugins not registering their own handlers. // For compat with old plugins not registering their own handlers.
$this->connect('plugin', 'PluginQueueHandler'); $this->connect('Module', 'ModuleQueueHandler');
} }
Event::handle('EndInitializeQueueManager', array($this)); Event::handle('EndInitializeQueueManager', array($this));
} }

View File

@ -1,20 +0,0 @@
<?php
if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Backwards compatible class for plugins for GNU social <1.2
* and thus only have the class StatusNet defined.
*/
class StatusNet
{
public static function getActivePlugins()
{
return GNUsocial::getActivePlugins();
}
public static function isHTTPS()
{
return GNUsocial::isHTTPS();
}
}

View File

@ -1678,7 +1678,7 @@ function common_enqueue_notice($notice)
$transports[] = 'sms'; $transports[] = 'sms';
} }
if (Event::hasHandler('HandleQueuedNotice')) { if (Event::hasHandler('HandleQueuedNotice')) {
$transports[] = 'plugin'; $transports[] = 'Module';
} }
// We can skip these for gatewayed notices. // We can skip these for gatewayed notices.