diff --git a/common.php b/common.php index 993fc342a..8a1e9ed65 100644 --- a/common.php +++ b/common.php @@ -18,6 +18,11 @@ header('X-Frame-Options: SAMEORIGIN'); // Get initial config 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 use Zend\Loader\StandardAutoloader; require(BB_ROOT . 'library/Zend/Loader/StandardAutoloader.php'); diff --git a/library/TorrentPier/Autoloader.php b/library/TorrentPier/Autoloader.php new file mode 100755 index 000000000..ec0167f3f --- /dev/null +++ b/library/TorrentPier/Autoloader.php @@ -0,0 +1,174 @@ +_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; + } +} \ No newline at end of file diff --git a/library/config.php b/library/config.php index 51bc9ee30..08fd62bf4 100644 --- a/library/config.php +++ b/library/config.php @@ -608,8 +608,8 @@ $bb_cfg['group_avatars'] = array( // Get a Google reCAPTCHA API Key: https://www.google.com/recaptcha/admin $bb_cfg['captcha'] = array( 'disabled' => false, - 'public_key' => '', // your public key - 'secret_key' => '', // your secret key + 'public_key' => '123', // your public key + 'secret_key' => '123', // your secret key 'theme' => 'light', // light or dark ); diff --git a/library/includes/functions.php b/library/includes/functions.php index 5a5c51c48..60d6aedfd 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -2568,7 +2568,7 @@ function bb_captcha ($mode, $callback = '') { 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']; $public = $bb_cfg['captcha']['public_key'];