mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-22 22:33:55 -07:00
autoload TorrentPier classes
This commit is contained in:
parent
8a708b1c0b
commit
ad3990f9bb
4 changed files with 182 additions and 3 deletions
|
@ -18,6 +18,11 @@ header('X-Frame-Options: SAMEORIGIN');
|
||||||
// Get initial config
|
// Get initial config
|
||||||
require(BB_ROOT . 'library/config.php');
|
require(BB_ROOT . 'library/config.php');
|
||||||
|
|
||||||
|
$fileDir = dirname(__FILE__);
|
||||||
|
|
||||||
|
require($fileDir . '/library/TorrentPier/Autoloader.php');
|
||||||
|
TorrentPier_Autoloader::getInstance()->setupAutoloader($fileDir . '/library/TorrentPier');
|
||||||
|
|
||||||
// Load Zend Framework
|
// Load Zend Framework
|
||||||
use Zend\Loader\StandardAutoloader;
|
use Zend\Loader\StandardAutoloader;
|
||||||
require(BB_ROOT . 'library/Zend/Loader/StandardAutoloader.php');
|
require(BB_ROOT . 'library/Zend/Loader/StandardAutoloader.php');
|
||||||
|
|
174
library/TorrentPier/Autoloader.php
Executable file
174
library/TorrentPier/Autoloader.php
Executable file
|
@ -0,0 +1,174 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A constant that must be made available for any other XenForo class to be included.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
define('XENFORO_AUTOLOADER_SETUP', true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base XenForo autoloader class. This must be the first class loaded and setup as the
|
||||||
|
* application/registry depends on it for loading classes.
|
||||||
|
*
|
||||||
|
* @package XenForo_Core
|
||||||
|
*/
|
||||||
|
class TorrentPier_Autoloader
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Instance manager.
|
||||||
|
*
|
||||||
|
* @var TorrentPier_Autoloader
|
||||||
|
*/
|
||||||
|
protected static $_instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Path to directory containing the application's library.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $_rootDir = '.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores whether the autoloader has been setup yet.
|
||||||
|
*
|
||||||
|
* @var boolean
|
||||||
|
*/
|
||||||
|
protected $_setup = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Protected constructor. Use {@link getInstance()} instead.
|
||||||
|
*/
|
||||||
|
protected function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup the autoloader. This causes the environment to be setup as necessary.
|
||||||
|
*
|
||||||
|
* @param string Path to application library directory. See {@link $_rootDir}
|
||||||
|
*/
|
||||||
|
public function setupAutoloader($rootDir)
|
||||||
|
{
|
||||||
|
if ($this->_setup)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_rootDir = $rootDir;
|
||||||
|
$this->_setupAutoloader();
|
||||||
|
|
||||||
|
$this->_setup = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal method that actually applies the autoloader. See {@link setupAutoloader()}
|
||||||
|
* for external usage.
|
||||||
|
*/
|
||||||
|
protected function _setupAutoloader()
|
||||||
|
{
|
||||||
|
if (@ini_get('open_basedir'))
|
||||||
|
{
|
||||||
|
// many servers don't seem to set include_path correctly with open_basedir, so don't use it
|
||||||
|
set_include_path($this->_rootDir . PATH_SEPARATOR . '.');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
set_include_path($this->_rootDir . PATH_SEPARATOR . '.' . PATH_SEPARATOR . get_include_path());
|
||||||
|
}
|
||||||
|
|
||||||
|
spl_autoload_register([$this, 'autoload']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Autoload the specified class.
|
||||||
|
*
|
||||||
|
* @param $class
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function autoload($class)
|
||||||
|
{
|
||||||
|
if (class_exists($class, false) || interface_exists($class, false))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($class == 'utf8_entity_decoder')
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($class, 0, 5) == 'XFCP_')
|
||||||
|
{
|
||||||
|
throw new Exception('Cannot load class using XFCP. Load the class using the correct loader first.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$filename = $this->autoloaderClassToFile($class);
|
||||||
|
if (!$filename)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file_exists($filename))
|
||||||
|
{
|
||||||
|
include($filename);
|
||||||
|
return (class_exists($class, false) || interface_exists($class, false));
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves a class name to an autoload path.
|
||||||
|
*
|
||||||
|
* @param string Name of class to autoload
|
||||||
|
*
|
||||||
|
* @return string|false False if the class contains invalid characters.
|
||||||
|
*/
|
||||||
|
public function autoloaderClassToFile($class)
|
||||||
|
{
|
||||||
|
if (preg_match('#[^a-zA-Z0-9_\\\\]#', $class))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_rootDir . '/' . str_replace(['_', '\\'], '/', $class) . '.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the autoloader's root directory.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getRootDir()
|
||||||
|
{
|
||||||
|
return $this->_rootDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the autoloader instance.
|
||||||
|
*
|
||||||
|
* @return TorrentPier_Autoloader
|
||||||
|
*/
|
||||||
|
public static final function getInstance()
|
||||||
|
{
|
||||||
|
if (!self::$_instance)
|
||||||
|
{
|
||||||
|
self::$_instance = new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manually sets the autoloader instance. Use this to inject a modified version.
|
||||||
|
*
|
||||||
|
* @param TorrentPier_Autoloader|null
|
||||||
|
*/
|
||||||
|
public static function setInstance(TorrentPier_Autoloader $loader = null)
|
||||||
|
{
|
||||||
|
self::$_instance = $loader;
|
||||||
|
}
|
||||||
|
}
|
|
@ -608,8 +608,8 @@ $bb_cfg['group_avatars'] = array(
|
||||||
// Get a Google reCAPTCHA API Key: https://www.google.com/recaptcha/admin
|
// Get a Google reCAPTCHA API Key: https://www.google.com/recaptcha/admin
|
||||||
$bb_cfg['captcha'] = array(
|
$bb_cfg['captcha'] = array(
|
||||||
'disabled' => false,
|
'disabled' => false,
|
||||||
'public_key' => '', // your public key
|
'public_key' => '123', // your public key
|
||||||
'secret_key' => '', // your secret key
|
'secret_key' => '123', // your secret key
|
||||||
'theme' => 'light', // light or dark
|
'theme' => 'light', // light or dark
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -2568,7 +2568,7 @@ function bb_captcha ($mode, $callback = '')
|
||||||
{
|
{
|
||||||
global $bb_cfg, $lang, $userdata;
|
global $bb_cfg, $lang, $userdata;
|
||||||
|
|
||||||
require_once(TP_AUTO_DIR . 'ReCaptcha/ReCaptcha.php');
|
//require_once(TP_AUTO_DIR . 'ReCaptcha/ReCaptcha.php');
|
||||||
|
|
||||||
$secret = $bb_cfg['captcha']['secret_key'];
|
$secret = $bb_cfg['captcha']['secret_key'];
|
||||||
$public = $bb_cfg['captcha']['public_key'];
|
$public = $bb_cfg['captcha']['public_key'];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue