From c9f9f4ac7e7280e1c66c443afc1d26d0b20ae2d5 Mon Sep 17 00:00:00 2001 From: beaver-dev Date: Sun, 21 Feb 2016 23:23:06 +0100 Subject: [PATCH 1/6] Display proper error when CSRF check fails --- featherbb/Middleware/Csrf.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/featherbb/Middleware/Csrf.php b/featherbb/Middleware/Csrf.php index a94a94df..81c5c320 100644 --- a/featherbb/Middleware/Csrf.php +++ b/featherbb/Middleware/Csrf.php @@ -8,6 +8,7 @@ use RuntimeException; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; +use FeatherBB\Core\Error; /** * CSRF protection middleware. @@ -317,9 +318,7 @@ public function getFailureCallable() { if (is_null($this->failureCallable)) { $this->failureCallable = function (ServerRequestInterface $request, ResponseInterface $response, $next) { - $body = new \Slim\Http\Body(fopen('php://temp', 'r+')); - $body->write('Failed CSRF check!'); - return $response->withStatus(400)->withHeader('Content-type', 'text/plain')->withBody($body); + throw new Error('Failed CSRF check!', 500); }; } return $this->failureCallable; From 41b7cba1fb40a5b1f9fdbaffb62478d39e9fe42f Mon Sep 17 00:00:00 2001 From: adaur Date: Mon, 22 Feb 2016 14:19:15 +0100 Subject: [PATCH 2/6] Fix cache not refreshing --- featherbb/Model/Profile.php | 4 +- featherbb/Model/Register.php | 13 +- plugins/test/bootstrap.php | 5 - plugins/test/composer.json | 7 - plugins/test/featherbb.json | 9 - plugins/test/src/Test.php | 27 -- plugins/test/vendor/autoload.php | 7 - plugins/test/vendor/composer/ClassLoader.php | 413 ------------------ plugins/test/vendor/composer/LICENSE | 21 - .../vendor/composer/autoload_classmap.php | 9 - .../vendor/composer/autoload_namespaces.php | 9 - .../test/vendor/composer/autoload_psr4.php | 10 - .../test/vendor/composer/autoload_real.php | 50 --- plugins/test/vendor/composer/installed.json | 1 - 14 files changed, 4 insertions(+), 581 deletions(-) delete mode 100644 plugins/test/bootstrap.php delete mode 100644 plugins/test/composer.json delete mode 100644 plugins/test/featherbb.json delete mode 100644 plugins/test/src/Test.php delete mode 100644 plugins/test/vendor/autoload.php delete mode 100644 plugins/test/vendor/composer/ClassLoader.php delete mode 100644 plugins/test/vendor/composer/LICENSE delete mode 100644 plugins/test/vendor/composer/autoload_classmap.php delete mode 100644 plugins/test/vendor/composer/autoload_namespaces.php delete mode 100644 plugins/test/vendor/composer/autoload_psr4.php delete mode 100644 plugins/test/vendor/composer/autoload_real.php delete mode 100644 plugins/test/vendor/composer/installed.json diff --git a/featherbb/Model/Profile.php b/featherbb/Model/Profile.php index 80d4950c..36ace231 100644 --- a/featherbb/Model/Profile.php +++ b/featherbb/Model/Profile.php @@ -729,9 +729,7 @@ public function delete_user($id) $this->delete_avatar($id); // Regenerate the users info cache - if (!Container::get('cache')->isCached('users_info')) { - Container::get('cache')->store('users_info', Cache::get_users_info()); - } + Container::get('cache')->store('users_info', Cache::get_users_info()); $stats = Container::get('cache')->retrieve('users_info'); diff --git a/featherbb/Model/Register.php b/featherbb/Model/Register.php index c5e93079..196efc93 100644 --- a/featherbb/Model/Register.php +++ b/featherbb/Model/Register.php @@ -156,16 +156,6 @@ public function insert_user($user) $new_uid = DB::get_db()->lastInsertId(ForumSettings::get('db_prefix').'users'); - - if (ForumSettings::get('o_regs_verify') == '0') { - // Regenerate the users info cache - if (!Container::get('cache')->isCached('users_info')) { - Container::get('cache')->store('users_info', Cache::get_users_info()); - } - - $stats = Container::get('cache')->retrieve('users_info'); - } - // If the mailing list isn't empty, we may need to send out some alerts if (ForumSettings::get('o_mailing_list') != '') { // If we previously found out that the email was banned @@ -265,6 +255,9 @@ public function insert_user($user) $jwt = AuthModel::generate_jwt($user_object, $expire); AuthModel::feather_setcookie('Bearer '.$jwt, $expire); + // Refresh cache + Container::get('cache')->store('users_info', Cache::get_users_info()); + Container::get('hooks')->fire('model.register.insert_user'); return Router::redirect(Router::pathFor('home'), __('Reg complete')); diff --git a/plugins/test/bootstrap.php b/plugins/test/bootstrap.php deleted file mode 100644 index 1b122146..00000000 --- a/plugins/test/bootstrap.php +++ /dev/null @@ -1,5 +0,0 @@ -bind('model.index.get_forum_actions', [$this, 'addMarkRead']); - } - - public function addMarkRead($forum_actions) - { - $forum_actions[] = 'Test1'; - $forum_actions[] = 'Test2'; - return $forum_actions; - } -} diff --git a/plugins/test/vendor/autoload.php b/plugins/test/vendor/autoload.php deleted file mode 100644 index 37a72436..00000000 --- a/plugins/test/vendor/autoload.php +++ /dev/null @@ -1,7 +0,0 @@ - - * Jordi Boggiano - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Composer\Autoload; - -/** - * ClassLoader implements a PSR-0 class loader - * - * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md - * - * $loader = new \Composer\Autoload\ClassLoader(); - * - * // register classes with namespaces - * $loader->add('Symfony\Component', __DIR__.'/component'); - * $loader->add('Symfony', __DIR__.'/framework'); - * - * // activate the autoloader - * $loader->register(); - * - * // to enable searching the include path (eg. for PEAR packages) - * $loader->setUseIncludePath(true); - * - * In this example, if you try to use a class in the Symfony\Component - * namespace or one of its children (Symfony\Component\Console for instance), - * the autoloader will first look for the class under the component/ - * directory, and it will then fallback to the framework/ directory if not - * found before giving up. - * - * This class is loosely based on the Symfony UniversalClassLoader. - * - * @author Fabien Potencier - * @author Jordi Boggiano - */ -class ClassLoader -{ - // PSR-4 - private $prefixLengthsPsr4 = array(); - private $prefixDirsPsr4 = array(); - private $fallbackDirsPsr4 = array(); - - // PSR-0 - private $prefixesPsr0 = array(); - private $fallbackDirsPsr0 = array(); - - private $useIncludePath = false; - private $classMap = array(); - - private $classMapAuthoritative = false; - - public function getPrefixes() - { - if (!empty($this->prefixesPsr0)) { - return call_user_func_array('array_merge', $this->prefixesPsr0); - } - - return array(); - } - - public function getPrefixesPsr4() - { - return $this->prefixDirsPsr4; - } - - public function getFallbackDirs() - { - return $this->fallbackDirsPsr0; - } - - public function getFallbackDirsPsr4() - { - return $this->fallbackDirsPsr4; - } - - public function getClassMap() - { - return $this->classMap; - } - - /** - * @param array $classMap Class to filename map - */ - public function addClassMap(array $classMap) - { - if ($this->classMap) { - $this->classMap = array_merge($this->classMap, $classMap); - } else { - $this->classMap = $classMap; - } - } - - /** - * Registers a set of PSR-0 directories for a given prefix, either - * appending or prepending to the ones previously set for this prefix. - * - * @param string $prefix The prefix - * @param array|string $paths The PSR-0 root directories - * @param bool $prepend Whether to prepend the directories - */ - public function add($prefix, $paths, $prepend = false) - { - if (!$prefix) { - if ($prepend) { - $this->fallbackDirsPsr0 = array_merge( - (array) $paths, - $this->fallbackDirsPsr0 - ); - } else { - $this->fallbackDirsPsr0 = array_merge( - $this->fallbackDirsPsr0, - (array) $paths - ); - } - - return; - } - - $first = $prefix[0]; - if (!isset($this->prefixesPsr0[$first][$prefix])) { - $this->prefixesPsr0[$first][$prefix] = (array) $paths; - - return; - } - if ($prepend) { - $this->prefixesPsr0[$first][$prefix] = array_merge( - (array) $paths, - $this->prefixesPsr0[$first][$prefix] - ); - } else { - $this->prefixesPsr0[$first][$prefix] = array_merge( - $this->prefixesPsr0[$first][$prefix], - (array) $paths - ); - } - } - - /** - * Registers a set of PSR-4 directories for a given namespace, either - * appending or prepending to the ones previously set for this namespace. - * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param array|string $paths The PSR-0 base directories - * @param bool $prepend Whether to prepend the directories - * - * @throws \InvalidArgumentException - */ - public function addPsr4($prefix, $paths, $prepend = false) - { - if (!$prefix) { - // Register directories for the root namespace. - if ($prepend) { - $this->fallbackDirsPsr4 = array_merge( - (array) $paths, - $this->fallbackDirsPsr4 - ); - } else { - $this->fallbackDirsPsr4 = array_merge( - $this->fallbackDirsPsr4, - (array) $paths - ); - } - } elseif (!isset($this->prefixDirsPsr4[$prefix])) { - // Register directories for a new namespace. - $length = strlen($prefix); - if ('\\' !== $prefix[$length - 1]) { - throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); - } - $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; - $this->prefixDirsPsr4[$prefix] = (array) $paths; - } elseif ($prepend) { - // Prepend directories for an already registered namespace. - $this->prefixDirsPsr4[$prefix] = array_merge( - (array) $paths, - $this->prefixDirsPsr4[$prefix] - ); - } else { - // Append directories for an already registered namespace. - $this->prefixDirsPsr4[$prefix] = array_merge( - $this->prefixDirsPsr4[$prefix], - (array) $paths - ); - } - } - - /** - * Registers a set of PSR-0 directories for a given prefix, - * replacing any others previously set for this prefix. - * - * @param string $prefix The prefix - * @param array|string $paths The PSR-0 base directories - */ - public function set($prefix, $paths) - { - if (!$prefix) { - $this->fallbackDirsPsr0 = (array) $paths; - } else { - $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; - } - } - - /** - * Registers a set of PSR-4 directories for a given namespace, - * replacing any others previously set for this namespace. - * - * @param string $prefix The prefix/namespace, with trailing '\\' - * @param array|string $paths The PSR-4 base directories - * - * @throws \InvalidArgumentException - */ - public function setPsr4($prefix, $paths) - { - if (!$prefix) { - $this->fallbackDirsPsr4 = (array) $paths; - } else { - $length = strlen($prefix); - if ('\\' !== $prefix[$length - 1]) { - throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); - } - $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; - $this->prefixDirsPsr4[$prefix] = (array) $paths; - } - } - - /** - * Turns on searching the include path for class files. - * - * @param bool $useIncludePath - */ - public function setUseIncludePath($useIncludePath) - { - $this->useIncludePath = $useIncludePath; - } - - /** - * Can be used to check if the autoloader uses the include path to check - * for classes. - * - * @return bool - */ - public function getUseIncludePath() - { - return $this->useIncludePath; - } - - /** - * Turns off searching the prefix and fallback directories for classes - * that have not been registered with the class map. - * - * @param bool $classMapAuthoritative - */ - public function setClassMapAuthoritative($classMapAuthoritative) - { - $this->classMapAuthoritative = $classMapAuthoritative; - } - - /** - * Should class lookup fail if not found in the current class map? - * - * @return bool - */ - public function isClassMapAuthoritative() - { - return $this->classMapAuthoritative; - } - - /** - * Registers this instance as an autoloader. - * - * @param bool $prepend Whether to prepend the autoloader or not - */ - public function register($prepend = false) - { - spl_autoload_register(array($this, 'loadClass'), true, $prepend); - } - - /** - * Unregisters this instance as an autoloader. - */ - public function unregister() - { - spl_autoload_unregister(array($this, 'loadClass')); - } - - /** - * Loads the given class or interface. - * - * @param string $class The name of the class - * @return bool|null True if loaded, null otherwise - */ - public function loadClass($class) - { - if ($file = $this->findFile($class)) { - includeFile($file); - - return true; - } - } - - /** - * Finds the path to the file where the class is defined. - * - * @param string $class The name of the class - * - * @return string|false The path if found, false otherwise - */ - public function findFile($class) - { - // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 - if ('\\' == $class[0]) { - $class = substr($class, 1); - } - - // class map lookup - if (isset($this->classMap[$class])) { - return $this->classMap[$class]; - } - if ($this->classMapAuthoritative) { - return false; - } - - $file = $this->findFileWithExtension($class, '.php'); - - // Search for Hack files if we are running on HHVM - if ($file === null && defined('HHVM_VERSION')) { - $file = $this->findFileWithExtension($class, '.hh'); - } - - if ($file === null) { - // Remember that this class does not exist. - return $this->classMap[$class] = false; - } - - return $file; - } - - private function findFileWithExtension($class, $ext) - { - // PSR-4 lookup - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; - - $first = $class[0]; - if (isset($this->prefixLengthsPsr4[$first])) { - foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { - if (0 === strpos($class, $prefix)) { - foreach ($this->prefixDirsPsr4[$prefix] as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { - return $file; - } - } - } - } - } - - // PSR-4 fallback dirs - foreach ($this->fallbackDirsPsr4 as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { - return $file; - } - } - - // PSR-0 lookup - if (false !== $pos = strrpos($class, '\\')) { - // namespaced class name - $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) - . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); - } else { - // PEAR-like class name - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; - } - - if (isset($this->prefixesPsr0[$first])) { - foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { - if (0 === strpos($class, $prefix)) { - foreach ($dirs as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { - return $file; - } - } - } - } - } - - // PSR-0 fallback dirs - foreach ($this->fallbackDirsPsr0 as $dir) { - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { - return $file; - } - } - - // PSR-0 include paths. - if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { - return $file; - } - } -} - -/** - * Scope isolated include. - * - * Prevents access to $this/self from included files. - */ -function includeFile($file) -{ - include $file; -} diff --git a/plugins/test/vendor/composer/LICENSE b/plugins/test/vendor/composer/LICENSE deleted file mode 100644 index c8d57af8..00000000 --- a/plugins/test/vendor/composer/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ - -Copyright (c) 2015 Nils Adermann, Jordi Boggiano - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is furnished -to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - diff --git a/plugins/test/vendor/composer/autoload_classmap.php b/plugins/test/vendor/composer/autoload_classmap.php deleted file mode 100644 index 7a91153b..00000000 --- a/plugins/test/vendor/composer/autoload_classmap.php +++ /dev/null @@ -1,9 +0,0 @@ - array($baseDir . '/src'), -); diff --git a/plugins/test/vendor/composer/autoload_real.php b/plugins/test/vendor/composer/autoload_real.php deleted file mode 100644 index 38af767a..00000000 --- a/plugins/test/vendor/composer/autoload_real.php +++ /dev/null @@ -1,50 +0,0 @@ - $path) { - $loader->set($namespace, $path); - } - - $map = require __DIR__ . '/autoload_psr4.php'; - foreach ($map as $namespace => $path) { - $loader->setPsr4($namespace, $path); - } - - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); - } - - $loader->register(true); - - return $loader; - } -} - -function composerRequirec204b6b3f64b0fff63ff500918413ad3($file) -{ - require $file; -} diff --git a/plugins/test/vendor/composer/installed.json b/plugins/test/vendor/composer/installed.json deleted file mode 100644 index fe51488c..00000000 --- a/plugins/test/vendor/composer/installed.json +++ /dev/null @@ -1 +0,0 @@ -[] From ade579ff72e2c6906548177ca2623c3cd7a908d2 Mon Sep 17 00:00:00 2001 From: adaur Date: Mon, 22 Feb 2016 14:21:41 +0100 Subject: [PATCH 3/6] Restore test plugin --- plugins/test/bootstrap.php | 5 + plugins/test/composer.json | 7 + plugins/test/featherbb.json | 9 + plugins/test/src/Test.php | 27 ++ plugins/test/vendor/autoload.php | 7 + plugins/test/vendor/composer/ClassLoader.php | 413 ++++++++++++++++++ plugins/test/vendor/composer/LICENSE | 21 + .../vendor/composer/autoload_classmap.php | 9 + .../vendor/composer/autoload_namespaces.php | 9 + .../test/vendor/composer/autoload_psr4.php | 10 + .../test/vendor/composer/autoload_real.php | 50 +++ plugins/test/vendor/composer/installed.json | 1 + 12 files changed, 568 insertions(+) create mode 100644 plugins/test/bootstrap.php create mode 100644 plugins/test/composer.json create mode 100644 plugins/test/featherbb.json create mode 100644 plugins/test/src/Test.php create mode 100644 plugins/test/vendor/autoload.php create mode 100644 plugins/test/vendor/composer/ClassLoader.php create mode 100644 plugins/test/vendor/composer/LICENSE create mode 100644 plugins/test/vendor/composer/autoload_classmap.php create mode 100644 plugins/test/vendor/composer/autoload_namespaces.php create mode 100644 plugins/test/vendor/composer/autoload_psr4.php create mode 100644 plugins/test/vendor/composer/autoload_real.php create mode 100644 plugins/test/vendor/composer/installed.json diff --git a/plugins/test/bootstrap.php b/plugins/test/bootstrap.php new file mode 100644 index 00000000..55ab4b13 --- /dev/null +++ b/plugins/test/bootstrap.php @@ -0,0 +1,5 @@ +bind('model.index.get_forum_actions', [$this, 'addMarkRead']); + } + + public function addMarkRead($forum_actions) + { + $forum_actions[] = 'Test1'; + $forum_actions[] = 'Test2'; + return $forum_actions; + } +} diff --git a/plugins/test/vendor/autoload.php b/plugins/test/vendor/autoload.php new file mode 100644 index 00000000..37a72436 --- /dev/null +++ b/plugins/test/vendor/autoload.php @@ -0,0 +1,7 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Autoload; + +/** + * ClassLoader implements a PSR-0 class loader + * + * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md + * + * $loader = new \Composer\Autoload\ClassLoader(); + * + * // register classes with namespaces + * $loader->add('Symfony\Component', __DIR__.'/component'); + * $loader->add('Symfony', __DIR__.'/framework'); + * + * // activate the autoloader + * $loader->register(); + * + * // to enable searching the include path (eg. for PEAR packages) + * $loader->setUseIncludePath(true); + * + * In this example, if you try to use a class in the Symfony\Component + * namespace or one of its children (Symfony\Component\Console for instance), + * the autoloader will first look for the class under the component/ + * directory, and it will then fallback to the framework/ directory if not + * found before giving up. + * + * This class is loosely based on the Symfony UniversalClassLoader. + * + * @author Fabien Potencier + * @author Jordi Boggiano + */ +class ClassLoader +{ + // PSR-4 + private $prefixLengthsPsr4 = array(); + private $prefixDirsPsr4 = array(); + private $fallbackDirsPsr4 = array(); + + // PSR-0 + private $prefixesPsr0 = array(); + private $fallbackDirsPsr0 = array(); + + private $useIncludePath = false; + private $classMap = array(); + + private $classMapAuthoritative = false; + + public function getPrefixes() + { + if (!empty($this->prefixesPsr0)) { + return call_user_func_array('array_merge', $this->prefixesPsr0); + } + + return array(); + } + + public function getPrefixesPsr4() + { + return $this->prefixDirsPsr4; + } + + public function getFallbackDirs() + { + return $this->fallbackDirsPsr0; + } + + public function getFallbackDirsPsr4() + { + return $this->fallbackDirsPsr4; + } + + public function getClassMap() + { + return $this->classMap; + } + + /** + * @param array $classMap Class to filename map + */ + public function addClassMap(array $classMap) + { + if ($this->classMap) { + $this->classMap = array_merge($this->classMap, $classMap); + } else { + $this->classMap = $classMap; + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, either + * appending or prepending to the ones previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 root directories + * @param bool $prepend Whether to prepend the directories + */ + public function add($prefix, $paths, $prepend = false) + { + if (!$prefix) { + if ($prepend) { + $this->fallbackDirsPsr0 = array_merge( + (array) $paths, + $this->fallbackDirsPsr0 + ); + } else { + $this->fallbackDirsPsr0 = array_merge( + $this->fallbackDirsPsr0, + (array) $paths + ); + } + + return; + } + + $first = $prefix[0]; + if (!isset($this->prefixesPsr0[$first][$prefix])) { + $this->prefixesPsr0[$first][$prefix] = (array) $paths; + + return; + } + if ($prepend) { + $this->prefixesPsr0[$first][$prefix] = array_merge( + (array) $paths, + $this->prefixesPsr0[$first][$prefix] + ); + } else { + $this->prefixesPsr0[$first][$prefix] = array_merge( + $this->prefixesPsr0[$first][$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, either + * appending or prepending to the ones previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-0 base directories + * @param bool $prepend Whether to prepend the directories + * + * @throws \InvalidArgumentException + */ + public function addPsr4($prefix, $paths, $prepend = false) + { + if (!$prefix) { + // Register directories for the root namespace. + if ($prepend) { + $this->fallbackDirsPsr4 = array_merge( + (array) $paths, + $this->fallbackDirsPsr4 + ); + } else { + $this->fallbackDirsPsr4 = array_merge( + $this->fallbackDirsPsr4, + (array) $paths + ); + } + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { + // Register directories for a new namespace. + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } elseif ($prepend) { + // Prepend directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + (array) $paths, + $this->prefixDirsPsr4[$prefix] + ); + } else { + // Append directories for an already registered namespace. + $this->prefixDirsPsr4[$prefix] = array_merge( + $this->prefixDirsPsr4[$prefix], + (array) $paths + ); + } + } + + /** + * Registers a set of PSR-0 directories for a given prefix, + * replacing any others previously set for this prefix. + * + * @param string $prefix The prefix + * @param array|string $paths The PSR-0 base directories + */ + public function set($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr0 = (array) $paths; + } else { + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; + } + } + + /** + * Registers a set of PSR-4 directories for a given namespace, + * replacing any others previously set for this namespace. + * + * @param string $prefix The prefix/namespace, with trailing '\\' + * @param array|string $paths The PSR-4 base directories + * + * @throws \InvalidArgumentException + */ + public function setPsr4($prefix, $paths) + { + if (!$prefix) { + $this->fallbackDirsPsr4 = (array) $paths; + } else { + $length = strlen($prefix); + if ('\\' !== $prefix[$length - 1]) { + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); + } + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; + $this->prefixDirsPsr4[$prefix] = (array) $paths; + } + } + + /** + * Turns on searching the include path for class files. + * + * @param bool $useIncludePath + */ + public function setUseIncludePath($useIncludePath) + { + $this->useIncludePath = $useIncludePath; + } + + /** + * Can be used to check if the autoloader uses the include path to check + * for classes. + * + * @return bool + */ + public function getUseIncludePath() + { + return $this->useIncludePath; + } + + /** + * Turns off searching the prefix and fallback directories for classes + * that have not been registered with the class map. + * + * @param bool $classMapAuthoritative + */ + public function setClassMapAuthoritative($classMapAuthoritative) + { + $this->classMapAuthoritative = $classMapAuthoritative; + } + + /** + * Should class lookup fail if not found in the current class map? + * + * @return bool + */ + public function isClassMapAuthoritative() + { + return $this->classMapAuthoritative; + } + + /** + * Registers this instance as an autoloader. + * + * @param bool $prepend Whether to prepend the autoloader or not + */ + public function register($prepend = false) + { + spl_autoload_register(array($this, 'loadClass'), true, $prepend); + } + + /** + * Unregisters this instance as an autoloader. + */ + public function unregister() + { + spl_autoload_unregister(array($this, 'loadClass')); + } + + /** + * Loads the given class or interface. + * + * @param string $class The name of the class + * @return bool|null True if loaded, null otherwise + */ + public function loadClass($class) + { + if ($file = $this->findFile($class)) { + includeFile($file); + + return true; + } + } + + /** + * Finds the path to the file where the class is defined. + * + * @param string $class The name of the class + * + * @return string|false The path if found, false otherwise + */ + public function findFile($class) + { + // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 + if ('\\' == $class[0]) { + $class = substr($class, 1); + } + + // class map lookup + if (isset($this->classMap[$class])) { + return $this->classMap[$class]; + } + if ($this->classMapAuthoritative) { + return false; + } + + $file = $this->findFileWithExtension($class, '.php'); + + // Search for Hack files if we are running on HHVM + if ($file === null && defined('HHVM_VERSION')) { + $file = $this->findFileWithExtension($class, '.hh'); + } + + if ($file === null) { + // Remember that this class does not exist. + return $this->classMap[$class] = false; + } + + return $file; + } + + private function findFileWithExtension($class, $ext) + { + // PSR-4 lookup + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; + + $first = $class[0]; + if (isset($this->prefixLengthsPsr4[$first])) { + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { + if (0 === strpos($class, $prefix)) { + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { + return $file; + } + } + } + } + } + + // PSR-4 fallback dirs + foreach ($this->fallbackDirsPsr4 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { + return $file; + } + } + + // PSR-0 lookup + if (false !== $pos = strrpos($class, '\\')) { + // namespaced class name + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); + } else { + // PEAR-like class name + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; + } + + if (isset($this->prefixesPsr0[$first])) { + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { + if (0 === strpos($class, $prefix)) { + foreach ($dirs as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + } + } + } + + // PSR-0 fallback dirs + foreach ($this->fallbackDirsPsr0 as $dir) { + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { + return $file; + } + } + + // PSR-0 include paths. + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { + return $file; + } + } +} + +/** + * Scope isolated include. + * + * Prevents access to $this/self from included files. + */ +function includeFile($file) +{ + include $file; +} diff --git a/plugins/test/vendor/composer/LICENSE b/plugins/test/vendor/composer/LICENSE new file mode 100644 index 00000000..c8d57af8 --- /dev/null +++ b/plugins/test/vendor/composer/LICENSE @@ -0,0 +1,21 @@ + +Copyright (c) 2015 Nils Adermann, Jordi Boggiano + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/plugins/test/vendor/composer/autoload_classmap.php b/plugins/test/vendor/composer/autoload_classmap.php new file mode 100644 index 00000000..7a91153b --- /dev/null +++ b/plugins/test/vendor/composer/autoload_classmap.php @@ -0,0 +1,9 @@ + array($baseDir . '/src'), +); diff --git a/plugins/test/vendor/composer/autoload_real.php b/plugins/test/vendor/composer/autoload_real.php new file mode 100644 index 00000000..38af767a --- /dev/null +++ b/plugins/test/vendor/composer/autoload_real.php @@ -0,0 +1,50 @@ + $path) { + $loader->set($namespace, $path); + } + + $map = require __DIR__ . '/autoload_psr4.php'; + foreach ($map as $namespace => $path) { + $loader->setPsr4($namespace, $path); + } + + $classMap = require __DIR__ . '/autoload_classmap.php'; + if ($classMap) { + $loader->addClassMap($classMap); + } + + $loader->register(true); + + return $loader; + } +} + +function composerRequirec204b6b3f64b0fff63ff500918413ad3($file) +{ + require $file; +} diff --git a/plugins/test/vendor/composer/installed.json b/plugins/test/vendor/composer/installed.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/plugins/test/vendor/composer/installed.json @@ -0,0 +1 @@ +[] From c99506baed819a42266afd221c281478304a5b59 Mon Sep 17 00:00:00 2001 From: adaur Date: Mon, 22 Feb 2016 14:24:26 +0100 Subject: [PATCH 4/6] Fix user deletion --- featherbb/Controller/Profile.php | 21 ++++++++++----------- featherbb/routes.php | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/featherbb/Controller/Profile.php b/featherbb/Controller/Profile.php index cf71e0fe..a7c87ce2 100644 --- a/featherbb/Controller/Profile.php +++ b/featherbb/Controller/Profile.php @@ -57,17 +57,16 @@ public function display($req, $res, $args) throw new Error(__('No permission'), 403); } - return $this->model->delete_user($args['id']); - - View::setPageInfo(array( - 'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Confirm delete user')), - 'active_page' => 'profile', - 'username' => $this->model->get_username($args['id']), - 'id' => $args['id'], - )); - - View::addTemplate('profile/delete_user.php')->display(); - + if (Input::post('delete_user_comply')) { + return $this->model->delete_user($args['id']); + } else { + View::setPageInfo(array( + 'title' => array(Utils::escape(ForumSettings::get('o_board_title')), __('Profile'), __('Confirm delete user')), + 'active_page' => 'profile', + 'username' => $this->model->get_username($args['id']), + 'id' => $args['id'], + ))->addTemplate('profile/delete_user.php')->display(); + } } elseif (Input::post('form_sent')) { // Fetch the user group of the user we are editing diff --git a/featherbb/routes.php b/featherbb/routes.php index 99d5021e..eb6cdcf7 100644 --- a/featherbb/routes.php +++ b/featherbb/routes.php @@ -88,7 +88,7 @@ // Profile routes Route::group('/user', function() { - Route::get('/{id:[0-9]+}', '\FeatherBB\Controller\Profile:display')->setName('userProfile'); + Route::map(['GET', 'POST'], '/{id:[0-9]+}', '\FeatherBB\Controller\Profile:display')->setName('userProfile'); Route::map(['GET', 'POST'], '/{id:[0-9]+}/section/{section}', '\FeatherBB\Controller\Profile:display')->setName('profileSection'); Route::map(['GET', 'POST'], '/{id:[0-9]+}/action/{action}', '\FeatherBB\Controller\Profile:action')->setName('profileAction'); // TODO: Move to another route for non-authed users Route::map(['GET', 'POST'], '/email/{id:[0-9]+}', '\FeatherBB\Controller\Profile:email')->setName('email'); From 137bcfb4b3df1dea3870c86052cb6354f3998fa0 Mon Sep 17 00:00:00 2001 From: adaur Date: Mon, 22 Feb 2016 14:30:33 +0100 Subject: [PATCH 5/6] Reduce "Moderated by" size --- style/themes/FeatherBB/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/style/themes/FeatherBB/style.css b/style/themes/FeatherBB/style.css index 08698ae3..0c4e0ef0 100644 --- a/style/themes/FeatherBB/style.css +++ b/style/themes/FeatherBB/style.css @@ -458,7 +458,7 @@ section .blocktable .box table tbody tr .tcl .tclcon h3 .newtext a:hover { text-decoration: underline; color: #2a6496 } -section .blocktable .box table tbody tr .tcl .tclcon .forumdesc { +section .blocktable .box table tbody tr .tcl .tclcon .forumdesc, .modlist { font-size: 12px } section .blocktable .box table tbody tr .tcr { From bdab1ad15a3b2518b22262e2195ad97950658391 Mon Sep 17 00:00:00 2001 From: adaur Date: Mon, 22 Feb 2016 18:38:46 +0100 Subject: [PATCH 6/6] Fix installer --- featherbb/Controller/Install.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/featherbb/Controller/Install.php b/featherbb/Controller/Install.php index e5bd6ee5..1dca18ae 100644 --- a/featherbb/Controller/Install.php +++ b/featherbb/Controller/Install.php @@ -12,6 +12,7 @@ use FeatherBB\Core\Lister; use FeatherBB\Core\Random; use FeatherBB\Core\Utils; +use FeatherBB\Core\Url; use FeatherBB\Middleware\Core; class Install @@ -49,7 +50,7 @@ public function run() $csrf = new \FeatherBB\Middleware\Csrf(); $csrf->generateNewToken(Container::get('request')); - translate(ForumEnv::get('install', 'featherbb', $this->install_lang)); + translate('install', 'featherbb', $this->install_lang); if (Request::isPost() && empty(Input::getParsedBodyParam('choose_lang'))) { $missing_fields = array(); @@ -137,7 +138,7 @@ public function run() return $this->create_config($data); } } else { - $base_url = str_replace('index.php', '', URL::base()); + $base_url = str_replace('index.php', '', Url::base()); $data = array('title' => __('My FeatherBB Forum'), 'description' => __('Description'), 'base_url' => $base_url, @@ -187,7 +188,7 @@ public function create_db(array $data) // Init DB Core::init_db($data); // Load appropriate language - translate(ForumEnv::get('install', 'featherbb', $data['default_lang'])); + translate('install', 'featherbb', $data['default_lang']); // Create tables foreach ($this->model->get_database_scheme() as $table => $sql) {