[PLUGIN API] Bug fixes and improvements

This commit is contained in:
Diogo Cordeiro 2019-08-12 15:03:18 +01:00
parent 55d049b1e8
commit b6e7b18c7b
23 changed files with 340 additions and 456 deletions

View File

@ -1,36 +1,20 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
*
* Plugin enable action.
*
* 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/>.
*
* 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/
*/
// 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/>.
if (!defined('STATUSNET')) {
exit(1);
}
defined('STATUSNET') || die();
/**
* Plugin enable action.
@ -52,7 +36,7 @@ if (!defined('STATUSNET')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/
*/
class PluginDisableAction extends PluginEnableAction
class PlugindisableAction extends PluginenableAction
{
/**
* Value to save into $config['plugins']['disable-<name>']
@ -70,6 +54,6 @@ class PluginDisableAction extends PluginEnableAction
protected function successNextForm()
{
return new EnablePluginForm($this, $this->plugin);
return new PluginEnableForm($this, $this->plugin);
}
}

View File

@ -1,36 +1,20 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, Inc.
*
* Plugin enable action.
*
* 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/>.
*
* 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/
*/
// 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/>.
if (!defined('STATUSNET')) {
exit(1);
}
defined('STATUSNET') || die();
/**
* Plugin enable action.
@ -41,7 +25,7 @@ if (!defined('STATUSNET')) {
*
* - plugin: plugin name
* - 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.
*
@ -52,7 +36,7 @@ if (!defined('STATUSNET')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/
*/
class PluginEnableAction extends Action
class PluginenableAction extends Action
{
var $user;
var $plugin;
@ -60,11 +44,12 @@ class PluginEnableAction extends Action
/**
* 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);
@ -117,9 +102,8 @@ class PluginEnableAction extends Action
*
* Does the subscription and returns results.
*
* @param Array $args unused.
*
* @return void
* @throws ClientException
*/
function handle()
{
@ -159,6 +143,6 @@ class PluginEnableAction extends Action
protected function successNextForm()
{
return new DisablePluginForm($this, $this->plugin);
return new PluginDisableForm($this, $this->plugin);
}
}

View File

@ -1,41 +1,26 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Plugins administration panel
*
* 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 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/
*/
// 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/>.
if (!defined('STATUSNET')) {
exit(1);
}
defined('STATUSNET') || die();
/**
* Plugins settings
*
* @category Admin
* @package StatusNet
* @package GNUsocial
* @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
* @link http://status.net/
@ -46,6 +31,7 @@ class PluginsadminpanelAction extends AdminPanelAction
* Returns the page title
*
* @return string page title
* @throws Exception
*/
function title()
{
@ -62,7 +48,7 @@ class PluginsadminpanelAction extends AdminPanelAction
{
// TRANS: Instructions at top of plugin admin page.
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.');
}
@ -76,7 +62,7 @@ class PluginsadminpanelAction extends AdminPanelAction
$this->elementStart('fieldset', array('id' => 'settings_plugins_default'));
// TRANS: Admin form section header
$this->element('legend', null, _('Default plugins'), 'default');
$this->element('legend', null, _('Default plugins'));
$this->showDefaultPlugins();

View File

@ -1,33 +1,20 @@
<?php
/**
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008-2011, StatusNet, Inc.
*
* Show version information for this software and plugins
*
* PHP version 5
*
* 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 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/
*/
// 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/>.
if (!defined('GNUSOCIAL')) { exit(1); }
defined('STATUSNET') || die();
/**
* Version info page
@ -46,14 +33,14 @@ if (!defined('GNUSOCIAL')) { exit(1); }
*/
class VersionAction extends Action
{
var $pluginVersions = array();
var $pluginVersions = [];
/**
* Return true since we're read-only.
*
* @param array $args other arguments
*
* @return boolean is read only action?
* @return bool is read only action?
*/
function isReadOnly($args)
{
@ -79,9 +66,9 @@ class VersionAction extends Action
*
* @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);
@ -130,7 +117,8 @@ class VersionAction extends Action
*
* @return void
*/
function showPageTitle() {
function showPageTitle()
{
$this->element('h1', array('class' => 'entry-title'), $this->title());
}

View File

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

View File

@ -78,7 +78,7 @@ class Event {
* @param string $name Name of the event that's happening
* @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.
*/
@ -104,7 +104,7 @@ class Event {
* @param string $name Name of the event 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());
}

View File

@ -23,46 +23,45 @@ global $config, $_server, $_path;
*/
class GNUsocial
{
protected static $config_files = array();
protected static $config_files = [];
protected static $have_config;
protected static $is_api;
protected static $is_ajax;
protected static $plugins = array();
protected static $plugins = [];
/**
* Configure and instantiate a plugin (or a core module) into the current configuration.
* Class definitions will be loaded from standard paths if necessary.
* Note that initialization events won't be fired until later.
*
* @param string $name class name & plugin file/subdir name
* @param array $attrs key/value pairs of public attributes to set on plugin instance
* @param string $name class name & module file/subdir name
* @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);
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.
// Försten till kvarn får mala.
return true;
}
$pluginclass = "{$name}Plugin";
$moduleclass = "{$name}Plugin";
if (!class_exists($pluginclass)) {
if (!class_exists($moduleclass)) {
$files = [
"local/plugins/{$pluginclass}.php",
"local/plugins/{$name}/{$pluginclass}.php",
"local/{$pluginclass}.php",
"local/{$name}/{$pluginclass}.php",
"modules/{$pluginclass}.php",
"modules/{$name}/{$pluginclass}.php",
"plugins/{$pluginclass}.php",
"plugins/{$name}/{$pluginclass}.php"
"local/plugins/{$moduleclass}.php",
"local/plugins/{$name}/{$moduleclass}.php",
"modules/{$moduleclass}.php",
"modules/{$name}/{$moduleclass}.php",
"plugins/{$moduleclass}.php",
"plugins/{$name}/{$moduleclass}.php"
];
foreach ($files as $file) {
@ -72,19 +71,19 @@ class GNUsocial
break;
}
}
if (!class_exists($pluginclass)) {
if (!class_exists($moduleclass)) {
throw new ServerException("Plugin $name not found.", 500);
}
}
// Doesn't this $inst risk being garbage collected or something?
// TODO: put into a static array that makes sure $inst isn't lost.
$inst = new $pluginclass();
$inst = new $moduleclass();
foreach ($attrs as $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;
return true;
@ -92,7 +91,7 @@ class GNUsocial
public static function delPlugin($name)
{
// Remove our plugin if it was previously loaded
// Remove our module if it was previously loaded
$name = ucfirst($name);
if (isset(self::$plugins[$name])) {
unset(self::$plugins[$name]);
@ -105,7 +104,7 @@ class GNUsocial
}
/**
* 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
*/
public static function getActivePlugins()
@ -115,7 +114,7 @@ class GNUsocial
/**
* Initialize, or re-initialize, GNU social global configuration
* and plugins.
* and modules.
*
* If switching site configurations during script execution, be
* careful when working with leftover objects -- global settings
@ -125,7 +124,9 @@ class GNUsocial
* @param $path optional URL path for picking config
* @param $conffile optional configuration file path
*
* @throws ConfigException
* @throws NoConfigException if config file can't be found
* @throws ServerException
*/
public static function init($server = null, $path = null, $conffile = null)
{
@ -165,6 +166,10 @@ class GNUsocial
* site is missing or configured incorrectly.
*
* @param string $nickname
* @return bool
* @throws ConfigException
* @throws NoConfigException
* @throws ServerException
*/
public static function switchSite($nickname)
{
@ -175,7 +180,7 @@ class GNUsocial
$sn = Status_network::getKV('nickname', $nickname);
if (empty($sn)) {
return false;
throw new Exception("No such site nickname '$nickname'");
//throw new Exception("No such site nickname '$nickname'");
}
$server = $sn->getServerName();
@ -191,7 +196,7 @@ class GNUsocial
*/
public static function findAllSites()
{
$sites = array();
$sites = [];
$sn = new Status_network();
$sn->find();
while ($sn->fetch()) {
@ -205,11 +210,11 @@ class GNUsocial
*/
protected static function initPlugins()
{
// User config may have already added some of these plugins, with
// maybe configured parameters. The self::addPlugin function will
// User config may have already added some of these modules, with
// maybe configured parameters. The self::addModule function will
// ignore the new call if it has already been instantiated.
// Load core plugins
// Load core modules
foreach (common_config('plugins', 'core') as $name => $params) {
call_user_func('self::addPlugin', $name, $params);
}
@ -221,11 +226,6 @@ class GNUsocial
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) {
self::addPlugin($name);
} 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') {
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');
}
@ -311,7 +310,7 @@ class GNUsocial
global $_server, $_path, $config, $_PEAR;
Event::clearHandlers();
self::$plugins = array();
self::$plugins = [];
// try to figure out where we are. $server and $path
// can be set by including module, else we guess based
@ -366,9 +365,10 @@ class GNUsocial
/**
* Load the default or specified configuration file.
* Modifies global $config and may establish plugins.
* Modifies global $config and may establish modules.
*
* @throws NoConfigException
* @throws ServerException
*/
protected static function loadConfigFile($conffile = null)
{
@ -379,10 +379,10 @@ class GNUsocial
// finally for a dir (usually only need one of the last two).
if (isset($conffile)) {
$config_files = array($conffile);
$config_files = [$conffile];
} else {
$config_files = array('/etc/gnusocial/config.php',
'/etc/gnusocial/config.d/'.$_server.'.php');
$config_files = ['/etc/gnusocial/config.php',
'/etc/gnusocial/config.d/' . $_server . '.php'];
if (strlen($_path) > 0) {
$config_files[] = '/etc/gnusocial/config.d/' . $_server . '_' . $_path . '.php';
@ -500,7 +500,8 @@ class NoConfigException extends Exception
{
public $configFiles;
function __construct($msg, $configFiles) {
function __construct($msg, $configFiles)
{
parent::__construct($msg);
$this->configFiles = $configFiles;
}

View File

@ -23,7 +23,7 @@ if (!defined('GNUSOCIAL')) { exit(1); }
* @package Activity
* @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)
{

View File

@ -32,8 +32,8 @@ if (!defined('GNUSOCIAL')) { exit(1); }
/**
* Superclass for plugins that do authentication
*
* @category Plugin
* @package StatusNet
* @category Module
* @package GNUsocial
* @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
* @link http://status.net/

View File

@ -34,8 +34,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
/**
* Superclass for plugins that do authorization
*
* @category Plugin
* @package StatusNet
* @category Module
* @package GNUsocial
* @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
* @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
* IO manager is used
*
* @category Plugin
* @package StatusNet
* @category Module
* @package GNUsocial
* @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
* @link http://status.net/

View File

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

View File

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

View File

@ -33,8 +33,8 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
/**
* Superclass for plugins that do URL shortening
*
* @category Plugin
* @package StatusNet
* @category Module
* @package GNUsocial
* @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
* @link http://status.net/

View File

@ -1,34 +1,20 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Form for enabling/disabling plugins
*
* 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 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/
*/
// 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/>.
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
defined('STATUSNET') || die();
/**
* Form for joining a group
@ -41,7 +27,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
*
* @see PluginEnableForm
*/
class PluginDisableForm extends PluginEnableForm
{
/**
@ -50,7 +35,7 @@ class PluginDisableForm extends PluginEnableForm
* @return string ID of the form
*/
function id()
public function id()
{
return 'plugin-disable-' . $this->plugin;
}
@ -61,7 +46,7 @@ class PluginDisableForm extends PluginEnableForm
* @return string of the form class
*/
function formClass()
public function formClass()
{
return 'form_plugin_disable';
}
@ -72,22 +57,24 @@ class PluginDisableForm extends PluginEnableForm
* @return string URL of the action
*/
function action()
public function action()
{
return common_local_url('plugindisable',
array('plugin' => $this->plugin));
return common_local_url(
'plugindisable',
['plugin' => $this->plugin]
);
}
/**
* Action elements
*
* @return void
* @throws Exception
*/
function formActions()
public function formActions()
{
// TRANS: Plugin admin panel controls
$this->out->submit('submit', _m('plugin', 'Disable'));
}
}

View File

@ -1,34 +1,20 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Form for enabling/disabling plugins
*
* 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 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/
*/
// 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/>.
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
defined('STATUSNET') || die();
require_once INSTALLDIR . '/lib/form.php';
@ -43,14 +29,13 @@ require_once INSTALLDIR.'/lib/form.php';
*
* @see PluginDisableForm
*/
class PluginEnableForm extends Form
{
/**
* Plugin to enable/disable
*/
var $plugin = null;
public $plugin = null;
/**
* Constructor
@ -59,7 +44,7 @@ class PluginEnableForm extends Form
* @param string $plugin plugin to enable/disable
*/
function __construct($out=null, $plugin=null)
public function __construct($out = null, $plugin = null)
{
parent::__construct($out);
@ -72,7 +57,7 @@ class PluginEnableForm extends Form
* @return string ID of the form
*/
function id()
public function id()
{
return 'plugin-enable-' . $this->plugin;
}
@ -83,7 +68,7 @@ class PluginEnableForm extends Form
* @return string of the form class
*/
function formClass()
public function formClass()
{
return 'form_plugin_enable';
}
@ -94,19 +79,22 @@ class PluginEnableForm extends Form
* @return string URL of the action
*/
function action()
public function action()
{
return common_local_url('pluginenable',
array('plugin' => $this->plugin));
return common_local_url(
'pluginenable',
['plugin' => $this->plugin]
);
}
/**
* Action elements
*
* @return void
* @throws Exception
*/
function formActions()
public function formActions()
{
// TRANS: Plugin admin panel controls
$this->out->submit('submit', _m('plugin', 'Enable'));

View File

@ -1,35 +1,20 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Plugins administration panel
*
* 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 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/
*/
// 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/>.
if (!defined('STATUSNET')) {
exit(1);
}
defined('STATUSNET') || die();
require INSTALLDIR . "/lib/pluginenableform.php";
require INSTALLDIR . "/lib/plugindisableform.php";
@ -38,39 +23,39 @@ require INSTALLDIR . "/lib/plugindisableform.php";
* Plugin list
*
* @category Admin
* @package StatusNet
* @package GNUsocial
* @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
* @link http://status.net/
*/
class PluginList extends Widget
{
var $plugins = array();
public $plugins = [];
function __construct($plugins, $out)
public function __construct($plugins, $out)
{
parent::__construct($out);
$this->plugins = $plugins;
}
function show()
public function show()
{
$this->startList();
$this->showPlugins();
$this->endList();
}
function startList()
public function startList()
{
$this->out->elementStart('table', 'plugin_list');
}
function endList()
public function endList()
{
$this->out->elementEnd('table');
}
function showPlugins()
public function showPlugins()
{
foreach ($this->plugins as $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);
}
@ -87,18 +72,18 @@ class PluginList extends Widget
class PluginListItem extends Widget
{
/** Current plugin. */
var $plugin = null;
public $plugin = null;
/** Local cache for plugin version info */
protected static $versions = false;
function __construct($plugin, $out)
public function __construct($plugin, $out)
{
parent::__construct($out);
$this->plugin = $plugin;
}
function show()
public function show()
{
$meta = $this->metaInfo();
@ -139,6 +124,8 @@ class PluginListItem extends Widget
$this->out->elementStart('td');
if (!empty($meta['rawdescription'])) {
$this->out->raw($meta['rawdescription']);
} elseif (!empty($meta['description'])) {
$this->out->raw($meta['description']);
}
$this->out->elementEnd('td');
@ -168,18 +155,19 @@ class PluginListItem extends Widget
*
* @fixme pull structured data from plugin source
*/
function metaInfo()
public function metaInfo()
{
$versions = self::getPluginVersions();
$found = false;
foreach ($versions as $info) {
// hack for URL shorteners... "LilUrl (ur1.ca)" etc
list($name, ) = explode(' ', $info['name']);
// We need a proper name for comparison, that is, without spaces nor the `(section)`
// 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) {
// hack for URL shorteners...
$found['rawdescription'] .= "<br />\n" . $info['rawdescription'];
} else {
$found = $info;
@ -190,9 +178,9 @@ class PluginListItem extends Widget
if ($found) {
return $found;
} else {
return array('name' => $this->plugin,
return ['name' => $this->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()
{
if (!is_array(self::$versions)) {
$versions = array();
Event::handle('PluginVersion', array(&$versions));
$versions = [];
Event::handle('ModuleVersion', [&$versions]);
self::$versions = $versions;
}
return self::$versions;

View File

@ -1,35 +1,32 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2008, 2009, 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/>.
*/
// 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('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.
*
* This gives plugins a chance to do background processing without
* actually registering their own queue and ensuring that things
* 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
* their notices get enqueued when they need them.
*/

View File

@ -294,7 +294,7 @@ abstract class QueueManager extends IoManager
$this->connect('actmove', 'ActivityMover');
// For compat with old plugins not registering their own handlers.
$this->connect('plugin', 'PluginQueueHandler');
$this->connect('Module', 'ModuleQueueHandler');
}
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';
}
if (Event::hasHandler('HandleQueuedNotice')) {
$transports[] = 'plugin';
$transports[] = 'Module';
}
// We can skip these for gatewayed notices.