Commit de55d8f8 authored by mmn's avatar mmn

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).
parent b6cfcfbc
......@@ -79,6 +79,49 @@ class Plugin
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.
* Gettext localizations can be called via the _m() helper function.
......
......@@ -40,19 +40,6 @@ class AccountManagerPlugin extends Plugin
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.
*
......
......@@ -57,24 +57,6 @@ class ActivityPlugin extends Plugin
public $StartLike = 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)
{
// Only do this if config is enabled
......
......@@ -92,38 +92,6 @@ class ActivitySpamPlugin extends Plugin
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
*
......
......@@ -174,20 +174,6 @@ class AdsensePlugin extends UAPPlugin
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) {
if (AdminPanelAction::canAdmin('adsense')) {
// TRANS: Menu item title/tooltip
......
......@@ -96,15 +96,9 @@ class AimPlugin extends ImPlugin
case 'Aim':
require_once(INSTALLDIR.'/plugins/Aim/extlib/phptoclib/aimclassw.php');
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)
......
......@@ -100,31 +100,6 @@ class AnonymousFavePlugin extends Plugin
$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)
{
$m->connect('main/anonfavor', array('action' => 'AnonFavor'));
......
......@@ -67,3 +67,4 @@ class AnonDisfavorForm extends DisFavorForm
return common_local_url('AnonDisFavor');
}
}
......@@ -67,3 +67,4 @@ class AnonFavorForm extends FavorForm
return common_local_url('AnonFavor');
}
}
......@@ -39,16 +39,6 @@ class AutocompletePlugin extends Plugin
parent::__construct();
}
function onAutoload($cls)
{
switch ($cls)
{
case 'AutocompleteAction':
require_once(INSTALLDIR.'/plugins/Autocomplete/autocomplete.php');
return false;
}
}
function onEndShowScripts($action){
if (common_logged_in()) {
$action->element('span', array('id' => 'autocomplete-api',
......
......@@ -205,27 +205,6 @@ class BitlyUrlPlugin extends UrlShortenerPlugin
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
* the admin form knows if we have a fallback or not.
......
......@@ -284,30 +284,6 @@ class BlacklistPlugin extends Plugin
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
*
......
......@@ -67,35 +67,6 @@ class BlogPlugin extends MicroAppPlugin
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
*
......
......@@ -135,44 +135,6 @@ class BookmarkPlugin extends MicroAppPlugin
$action->script($this->path('js/bookmark.js'));
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
......
......@@ -35,7 +35,6 @@ if (!defined('STATUSNET')) {
}
require_once INSTALLDIR.'/lib/apibareauth.php';
require_once 'bookmarksnoticestream.php';
/**
* Returns the 20 most recent favorite notices for the authenticating user or user
......
......@@ -31,8 +31,6 @@ if (!defined('STATUSNET')) {
exit(1);
}
require_once 'bookmarksnoticestream.php';
/**
* List currently logged-in user's bookmakrs
*
......
......@@ -33,7 +33,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
}
require_once INSTALLDIR.'/lib/rssaction.php';
require_once 'bookmarksnoticestream.php';
/**
* RSS feed for user bookmarks action class.
......
......@@ -54,10 +54,10 @@ class CasAuthenticationPlugin extends AuthenticationPlugin
case 'phpCAS':
require_once(INSTALLDIR.'/plugins/CasAuthentication/extlib/CAS.php');
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)
......
......@@ -31,8 +31,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
require_once(INSTALLDIR.'/plugins/ClientSideShorten/shorten.php');
class ClientSideShortenPlugin extends Plugin
{
function __construct()
......@@ -40,16 +38,6 @@ class ClientSideShortenPlugin extends Plugin
parent::__construct();
}
function onAutoload($cls)
{
switch ($cls)
{
case 'ShortenAction':
require_once(INSTALLDIR.'/plugins/ClientSideShorten/shorten.php');
return false;
}
}
function onEndShowScripts($action){
if (common_logged_in()) {
$user = common_current_user();
......
......@@ -68,41 +68,6 @@ class DirectoryPlugin extends Plugin
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
*
......
......@@ -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)
{
$parts = explode('@', $raw);
......
......@@ -48,32 +48,6 @@ if (!defined('STATUSNET')) {
*/