From a52f6894c05bd2695a75b9e88f471f5a861e957b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Thu, 7 Aug 2014 13:47:26 +0200 Subject: [PATCH] proper check for .php plugin files --- application/core/Files/FileUtil.php | 11 +++++++++++ application/core/Plugins/PluginManager.php | 9 +++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/application/core/Files/FileUtil.php b/application/core/Files/FileUtil.php index 34fc0506..f96dfcdd 100644 --- a/application/core/Files/FileUtil.php +++ b/application/core/Files/FileUtil.php @@ -196,4 +196,15 @@ abstract class FileUtil { } return $path; } + + /** + * Check whether the given file name is a PHP file + * + * @param string $fileName + * @return bool + */ + public static function isPhpFileName($fileName) { + $extension = substr($fileName, -4); + return (strtolower($extension) === '.php'); + } } diff --git a/application/core/Plugins/PluginManager.php b/application/core/Plugins/PluginManager.php index 0e9662ff..7342e635 100644 --- a/application/core/Plugins/PluginManager.php +++ b/application/core/Plugins/PluginManager.php @@ -5,6 +5,7 @@ namespace ManiaControl\Plugins; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Commands\CommandListener; +use ManiaControl\Files\FileUtil; use ManiaControl\Logger; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkPageAnswerListener; @@ -294,7 +295,7 @@ class PluginManager { $filePath = $directory . $pluginFile; if (is_file($filePath)) { - if (!stripos($pluginFile, '.php')) { + if (!FileUtil::isPhpFileName($pluginFile)) { continue; } $success = include_once $filePath; @@ -478,8 +479,8 @@ class PluginManager { $url = ManiaControl::URL_WEBSERVICE . 'plugins'; $this->maniaControl->getFileReader() ->loadFile($url, function ($dataJson, $error) use (&$function) { - $data = json_decode($dataJson); - call_user_func($function, $data, $error); - }); + $data = json_decode($dataJson); + call_user_func($function, $data, $error); + }); } }