plugins onAutoload now only overloads if necessary (extlibs etc.)

lib/plugin.php now has a parent onAutoload function that finds most common
files that are used in plugins (actions, dataobjects, forms, libs etc.) if
they are put in the standardised directories ('actions', 'classes', 'forms',
'lib' and perhaps some others in the future).
This commit is contained in:
Mikael Nordfeldth 2013-08-28 15:54:26 +02:00
parent b6cfcfbcaa
commit de55d8f83b
282 changed files with 227 additions and 1423 deletions

View File

@ -79,6 +79,49 @@ class Plugin
return true; return true;
} }
/**
* Load related modules when needed
*
* Most non-trivial plugins will require extra modules to do their work. Typically
* these include data classes, action classes, widget classes, or external libraries.
*
* This method receives a class name and loads the PHP file related to that class. By
* tradition, action classes typically have files named for the action, all lower-case.
* Data classes are in files with the data class name, initial letter capitalized.
*
* Note that this method will be called for *all* overloaded classes, not just ones
* in this plugin! So, make sure to return true by default to let other plugins, and
* the core code, get a chance.
*
* @param string $cls Name of the class to be loaded
*
* @return boolean hook value; true means continue processing, false means stop.
*/
public function onAutoload($cls) {
$cls = basename($cls);
$basedir = INSTALLDIR . '/plugins/' . mb_substr(get_called_class(), 0, -6);
$file = null;
if (preg_match('/^(\w+)(Action|Form)$/', $cls, $type)) {
$type = array_map('strtolower', $type);
$file = "$basedir/{$type[2]}s/{$type[1]}.php";
} else {
$file = "$basedir/classes/{$cls}.php";
if (!file_exists($file)) {
$type = strtolower($cls);
$file = "$basedir/lib/{$type}.php";
}
}
if (!is_null($file) && file_exists($file)) {
require_once($file);
return false;
}
return true;
}
/** /**
* Checks if this plugin has localization that needs to be set up. * Checks if this plugin has localization that needs to be set up.
* Gettext localizations can be called via the _m() helper function. * Gettext localizations can be called via the _m() helper function.

View File

@ -40,19 +40,6 @@ class AccountManagerPlugin extends Plugin
parent::__construct(); parent::__construct();
} }
function onAutoload($cls)
{
switch ($cls)
{
case 'AccountManagementControlDocumentAction':
require_once(INSTALLDIR.'/plugins/AccountManager/AccountManagementControlDocumentAction.php');
return false;
case 'AccountManagementSessionStatusAction':
require_once(INSTALLDIR.'/plugins/AccountManager/AccountManagementSessionStatusAction.php');
return false;
}
}
/** /**
* Hook for RouterInitialized event. * Hook for RouterInitialized event.
* *

View File

@ -57,24 +57,6 @@ class ActivityPlugin extends Plugin
public $StartLike = false; public $StartLike = false;
public $StopLike = false; public $StopLike = false;
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch ($cls)
{
case 'JoinListItem':
case 'LeaveListItem':
case 'FollowListItem':
case 'UnfollowListItem':
case 'SystemListItem':
include_once $dir . '/'.strtolower($cls).'.php';
return false;
default:
return true;
}
}
function onEndSubscribe($subscriber, $other) function onEndSubscribe($subscriber, $other)
{ {
// Only do this if config is enabled // Only do this if config is enabled

View File

@ -92,38 +92,6 @@ class ActivitySpamPlugin extends Plugin
return true; return true;
} }
/**
* Load related modules when needed
*
* @param string $cls Name of the class to be loaded
*
* @return boolean hook value; true means continue processing, false means stop.
*/
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch ($cls)
{
case 'TrainAction':
case 'SpamAction':
include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'Spam_score':
include_once $dir . '/'.$cls.'.php';
return false;
case 'SpamFilter':
case 'SpamNoticeStream':
case 'TrainSpamForm':
case 'TrainHamForm':
include_once $dir . '/'.strtolower($cls).'.php';
return false;
default:
return true;
}
}
/** /**
* When a notice is saved, check its spam score * When a notice is saved, check its spam score
* *

View File

@ -174,20 +174,6 @@ class AdsensePlugin extends UAPPlugin
return true; return true;
} }
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch ($cls)
{
case 'AdsenseadminpanelAction':
require_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
default:
return true;
}
}
function onEndAdminPanelNav($menu) { function onEndAdminPanelNav($menu) {
if (AdminPanelAction::canAdmin('adsense')) { if (AdminPanelAction::canAdmin('adsense')) {
// TRANS: Menu item title/tooltip // TRANS: Menu item title/tooltip

View File

@ -96,15 +96,9 @@ class AimPlugin extends ImPlugin
case 'Aim': case 'Aim':
require_once(INSTALLDIR.'/plugins/Aim/extlib/phptoclib/aimclassw.php'); require_once(INSTALLDIR.'/plugins/Aim/extlib/phptoclib/aimclassw.php');
return false; return false;
case 'AimManager':
include_once $dir . '/'.strtolower($cls).'.php';
return false;
case 'Fake_Aim':
include_once $dir . '/'. $cls .'.php';
return false;
default:
return true;
} }
return parent::onAutoload($cls);
} }
function onStartImDaemonIoManagers(&$classes) function onStartImDaemonIoManagers(&$classes)

View File

@ -100,31 +100,6 @@ class AnonymousFavePlugin extends Plugin
$action->inlineScript('SN.U.NoticeFavor();'); $action->inlineScript('SN.U.NoticeFavor();');
} }
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch ($cls) {
case 'Fave_tally':
include_once $dir . '/' . $cls . '.php';
return false;
case 'AnonFavorAction':
include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'AnonDisFavorAction':
include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'AnonFavorForm':
include_once $dir . '/anonfavorform.php';
return false;
case 'AnonDisFavorForm':
include_once $dir . '/anondisfavorform.php';
return false;
default:
return true;
}
}
function onStartInitializeRouter($m) function onStartInitializeRouter($m)
{ {
$m->connect('main/anonfavor', array('action' => 'AnonFavor')); $m->connect('main/anonfavor', array('action' => 'AnonFavor'));

View File

@ -67,3 +67,4 @@ class AnonDisfavorForm extends DisFavorForm
return common_local_url('AnonDisFavor'); return common_local_url('AnonDisFavor');
} }
} }

View File

@ -67,3 +67,4 @@ class AnonFavorForm extends FavorForm
return common_local_url('AnonFavor'); return common_local_url('AnonFavor');
} }
} }

View File

@ -39,16 +39,6 @@ class AutocompletePlugin extends Plugin
parent::__construct(); parent::__construct();
} }
function onAutoload($cls)
{
switch ($cls)
{
case 'AutocompleteAction':
require_once(INSTALLDIR.'/plugins/Autocomplete/autocomplete.php');
return false;
}
}
function onEndShowScripts($action){ function onEndShowScripts($action){
if (common_logged_in()) { if (common_logged_in()) {
$action->element('span', array('id' => 'autocomplete-api', $action->element('span', array('id' => 'autocomplete-api',

View File

@ -205,27 +205,6 @@ class BitlyUrlPlugin extends UrlShortenerPlugin
return true; return true;
} }
/**
* Automatically load the actions and libraries used by the plugin
*
* @param Class $cls the class
*
* @return boolean hook return
*
*/
function onAutoload($cls)
{
$base = dirname(__FILE__);
$lower = strtolower($cls);
switch ($lower) {
case 'bitlyadminpanelaction':
require_once "$base/$lower.php";
return false;
default:
return true;
}
}
/** /**
* Internal hook point to check the default global credentials so * Internal hook point to check the default global credentials so
* the admin form knows if we have a fallback or not. * the admin form knows if we have a fallback or not.

View File

@ -284,30 +284,6 @@ class BlacklistPlugin extends Plugin
return true; return true;
} }
/**
* Auto-load our classes if called
*
* @param string $cls Class to load
*
* @return boolean hook return
*/
function onAutoload($cls)
{
switch (strtolower($cls))
{
case 'nickname_blacklist':
case 'homepage_blacklist':
include_once INSTALLDIR.'/plugins/Blacklist/'.ucfirst($cls).'.php';
return false;
case 'blacklistadminpanelaction':
$base = strtolower(mb_substr($cls, 0, -6));
include_once INSTALLDIR.'/plugins/Blacklist/'.$base.'.php';
return false;
default:
return true;
}
}
/** /**
* Plugin version data * Plugin version data
* *

View File

@ -67,35 +67,6 @@ class BlogPlugin extends MicroAppPlugin
return true; return true;
} }
/**
* Load related modules when needed
*
* @param string $cls Name of the class to be loaded
*
* @return boolean hook value; true means continue processing, false means stop.
*/
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch ($cls)
{
case 'NewblogentryAction':
case 'ShowblogentryAction':
include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'BlogEntryForm':
case 'BlogEntryListItem':
include_once $dir . '/'.strtolower($cls).'.php';
return false;
case 'Blog_entry':
include_once $dir . '/'.$cls.'.php';
return false;
default:
return true;
}
}
/** /**
* Map URLs to actions * Map URLs to actions
* *

View File

@ -135,44 +135,6 @@ class BookmarkPlugin extends MicroAppPlugin
$action->script($this->path('js/bookmark.js')); $action->script($this->path('js/bookmark.js'));
return true; return true;
} }
/**
* Load related modules when needed
*
* @param string $cls Name of the class to be loaded
*
* @return boolean hook value; true means continue processing, false means stop.
*/
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch ($cls)
{
case 'BookmarksAction':
case 'BookmarksrssAction':
case 'ApiTimelineBookmarksAction':
case 'ShowbookmarkAction':
case 'NewbookmarkAction':
case 'BookmarkpopupAction':
case 'NoticebyurlAction':
case 'BookmarkforurlAction':
case 'ImportdeliciousAction':
include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'Bookmark':
include_once $dir.'/'.$cls.'.php';
return false;
case 'BookmarkListItem':
case 'BookmarkForm':
case 'InitialBookmarkForm':
case 'DeliciousBackupImporter':
case 'DeliciousBookmarkImporter':
include_once $dir.'/'.strtolower($cls).'.php';
return false;
default:
return true;
}
}
/** /**
* Map URLs to actions * Map URLs to actions

View File

@ -35,7 +35,6 @@ if (!defined('STATUSNET')) {
} }
require_once INSTALLDIR.'/lib/apibareauth.php'; require_once INSTALLDIR.'/lib/apibareauth.php';
require_once 'bookmarksnoticestream.php';
/** /**
* Returns the 20 most recent favorite notices for the authenticating user or user * Returns the 20 most recent favorite notices for the authenticating user or user

View File

@ -31,8 +31,6 @@ if (!defined('STATUSNET')) {
exit(1); exit(1);
} }
require_once 'bookmarksnoticestream.php';
/** /**
* List currently logged-in user's bookmakrs * List currently logged-in user's bookmakrs
* *

View File

@ -33,7 +33,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
} }
require_once INSTALLDIR.'/lib/rssaction.php'; require_once INSTALLDIR.'/lib/rssaction.php';
require_once 'bookmarksnoticestream.php';
/** /**
* RSS feed for user bookmarks action class. * RSS feed for user bookmarks action class.

View File

@ -54,10 +54,10 @@ class CasAuthenticationPlugin extends AuthenticationPlugin
case 'phpCAS': case 'phpCAS':
require_once(INSTALLDIR.'/plugins/CasAuthentication/extlib/CAS.php'); require_once(INSTALLDIR.'/plugins/CasAuthentication/extlib/CAS.php');
return false; return false;
case 'CasloginAction':
require_once(INSTALLDIR.'/plugins/CasAuthentication/' . strtolower(mb_substr($cls, 0, -6)) . '.php');
return false;
} }
// if it's not our exception, try standard places
return parent::onAutoload($cls);
} }
function onArgsInitialize(&$args) function onArgsInitialize(&$args)

View File

@ -31,8 +31,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1); exit(1);
} }
require_once(INSTALLDIR.'/plugins/ClientSideShorten/shorten.php');
class ClientSideShortenPlugin extends Plugin class ClientSideShortenPlugin extends Plugin
{ {
function __construct() function __construct()
@ -40,16 +38,6 @@ class ClientSideShortenPlugin extends Plugin
parent::__construct(); parent::__construct();
} }
function onAutoload($cls)
{
switch ($cls)
{
case 'ShortenAction':
require_once(INSTALLDIR.'/plugins/ClientSideShorten/shorten.php');
return false;
}
}
function onEndShowScripts($action){ function onEndShowScripts($action){
if (common_logged_in()) { if (common_logged_in()) {
$user = common_current_user(); $user = common_current_user();

View File

@ -68,41 +68,6 @@ class DirectoryPlugin extends Plugin
return true; return true;
} }
/**
* Load related modules when needed
*
* @param string $cls Name of the class to be loaded
*
* @return boolean hook value; true means continue processing,
* false means stop.
*/
function onAutoload($cls)
{
// common_debug("class = $cls");
$dir = dirname(__FILE__);
switch ($cls)
{
case 'UserdirectoryAction':
case 'GroupdirectoryAction':
include_once $dir
. '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'AlphaNav':
include_once $dir
. '/lib/' . strtolower($cls) . '.php';
return false;
case 'SortableSubscriptionList':
case 'SortableGroupList':
include_once $dir
. '/lib/' . strtolower($cls) . '.php';
return false;
default:
return true;
}
}
/** /**
* Map URLs to actions * Map URLs to actions
* *

View File

@ -91,27 +91,6 @@ class DomainStatusNetworkPlugin extends Plugin
} }
} }
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch ($cls)
{
case 'GlobalregisterAction':
case 'GloballoginAction':
case 'GlobalrecoverAction':
include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'DomainStatusNetworkInstaller':
case 'GlobalApiAction':
case 'FreeEmail':
include_once $dir . '/lib/' . strtolower($cls) . '.php';
return false;
default:
return true;
}
}
static function toDomain($raw) static function toDomain($raw)
{ {
$parts = explode('@', $raw); $parts = explode('@', $raw);

View File

@ -48,32 +48,6 @@ if (!defined('STATUSNET')) {
*/ */
class DomainWhitelistPlugin extends Plugin class DomainWhitelistPlugin extends Plugin
{ {
/**
* Load related modules when needed
*
* @param string $cls Name of the class to be loaded
*
* @return boolean hook value; true means continue processing, false
* means stop.
*/
function onAutoload($cls) {
$base = dirname(__FILE__);
$lower = strtolower($cls);
$files = array("$base/classes/$cls.php",
"$base/lib/$lower.php");
if (substr($lower, -6) == 'action') {
$files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
}
foreach ($files as $file) {
if (file_exists($file)) {
include_once $file;
return false;
}
}
return true;
}
/** /**
* Get the path to the plugin's installation directory. Used * Get the path to the plugin's installation directory. Used
* to link in js files and whatnot. * to link in js files and whatnot.

View File

@ -49,24 +49,6 @@ class EmailRegistrationPlugin extends Plugin
{ {
const CONFIRMTYPE = 'register'; const CONFIRMTYPE = 'register';
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch ($cls)
{
case 'EmailregisterAction':
include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'EmailRegistrationForm':
case 'ConfirmRegistrationForm':
include_once $dir . '/' . strtolower($cls) . '.php';
return false;
default:
return true;
}
}
function onArgsInitialize(&$args) function onArgsInitialize(&$args)
{ {
if (array_key_exists('action', $args) && $args['action'] == 'register') { if (array_key_exists('action', $args) && $args['action'] == 'register') {

View File

@ -61,32 +61,6 @@ class EmailReminderPlugin extends Plugin
return true; return true;
} }
/**
* Load related modules when needed
*
* @param string $cls Name of the class to be loaded
*
* @return boolean hook value; true means continue processing, false
* means stop.
*/
function onAutoload($cls) {
$base = dirname(__FILE__);
$lower = strtolower($cls);
$files = array("$base/classes/$cls.php",
"$base/lib/$lower.php");
if (substr($lower, -6) == 'action') {
$files[] = "$base/actions/" . substr($lower, 0, -6) . ".php";
}
foreach ($files as $file) {
if (file_exists($file)) {
include_once $file;
return false;
}
}
return true;
}
/** /**
* Register our queue handlers * Register our queue handlers
* *

View File

@ -59,32 +59,6 @@ class EmailSummaryPlugin extends Plugin
return true; return true;
} }
/**
* Load related modules when needed
*
* @param string $cls Name of the class to be loaded
*
* @return boolean hook value; true means continue processing, false means stop.
*
*/
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch ($cls)
{
case 'SiteEmailSummaryHandler':
case 'UserEmailSummaryHandler':
include_once $dir . '/'.strtolower($cls).'.php';
return false;
case 'Email_summary_status':
include_once $dir . '/'.$cls.'.php';
return false;
default:
return true;
}
}
/** /**
* Version info for this plugin * Version info for this plugin
* *

View File

@ -64,44 +64,6 @@ class EventPlugin extends MicroappPlugin
return true; return true;
} }
/**
* Load related modules when needed
*
* @param string $cls Name of the class to be loaded
*
* @return boolean hook value; true means continue processing, false means stop.
*/
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch ($cls)
{
case 'NeweventAction':
case 'NewrsvpAction':
case 'CancelrsvpAction':
case 'ShoweventAction':
case 'ShowrsvpAction':
case 'TimelistAction':
include_once $dir . '/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'EventListItem':
case 'RSVPListItem':
case 'EventForm':
case 'RSVPForm':
case 'CancelRSVPForm':
case 'EventTimeList':
include_once $dir . '/'.strtolower($cls).'.php';
break;
case 'Happening':
case 'RSVP':
include_once $dir . '/'.$cls.'.php';
return false;
default:
return true;
}
}
/** /**
* Map URLs to actions * Map URLs to actions
* *

View File

@ -43,42 +43,6 @@ class ExtendedProfilePlugin extends Plugin
return true; return true;
} }
/**
* Autoloader
*
* Loads our classes if they're requested.
*
* @param string $cls Class requested
*
* @return boolean hook return
*/
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch (strtolower($cls))
{
case 'profiledetailaction':
case 'profiledetailsettingsaction':
case 'userautocompleteaction':
include_once $dir . '/actions/'
. strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
break; // Safety first!
case 'extendedprofile':
case 'extendedprofilewidget':
include_once $dir . '/lib/' . strtolower($cls) . '.php';
return false;
break;
case 'profile_detail':
include_once $dir . '/classes/' . ucfirst($cls) . '.php';
return false;
break;
default:
return true;
}
}
/** /**
* Add paths to the router table * Add paths to the router table
* *

View File

@ -109,23 +109,9 @@ class FacebookBridgePlugin extends Plugin
include_once $dir . '/extlib/base_facebook.php'; include_once $dir . '/extlib/base_facebook.php';
include_once $dir . '/extlib/facebook.php'; include_once $dir . '/extlib/facebook.php';
return false; return false;
case 'FacebookloginAction':
case 'FacebookfinishloginAction':
case 'FacebookadminpanelAction':
case 'FacebooksettingsAction':
case 'FacebookdeauthorizeAction':
include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
return false;
case 'Facebookclient':
case 'FacebookQueueHandler':
include_once $dir . '/lib/' . strtolower($cls) . '.php';
return false;
case 'Notice_to_item':
include_once $dir . '/classes/' . $cls . '.php';
return false;
default:
return true;
} }
return parent::onAutoload($cls);
} }
/** /**

View File

@ -119,27 +119,6 @@ class FollowEveryonePlugin extends Plugin
return true; return true;
} }
/**
* Load related modules when needed
*
* @param string $cls Name of the class to be loaded
*
* @return boolean hook value; true means continue processing, false means stop.
*/
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch ($cls)
{
case 'User_followeveryone_prefs':
include_once $dir . '/'.$cls.'.php';
return false;
default:
return true;
}
}
/** /**
* Show a checkbox on the profile form to ask whether to follow everyone * Show a checkbox on the profile form to ask whether to follow everyone
* *

View File

@ -42,26 +42,6 @@ class GNUsocialPhotoPlugin extends MicroAppPlugin
return true; return true;
} }
function onAutoload($cls)
{
$dir = dirname(__FILE__);
switch($cls)
{
case 'Photo':
include_once $dir . '/Photo.php';
break;
case 'NewPhotoForm':
include_once $dir . '/newphotoform.php';
break;
case 'NewphotoAction':
include_once $dir . '/newphoto.php';
break;
default:
break;
}
return true;
}
function onRouterInitialized($m) function onRouterInitialized($m)
{ {
$m->connect('main/photo/new', array('action' => 'newphoto')); $m->connect('main/photo/new', array('action' => 'newphoto'));

Some files were not shown because too many files have changed in this diff Show More