diff --git a/classes/Config.php b/classes/Config.php index 2c2cd4d65..e6e19ba09 100644 --- a/classes/Config.php +++ b/classes/Config.php @@ -319,7 +319,7 @@ class Config { * @return array|string */ private function _get_version(bool $as_string = true) { - $root_dir = dirname(__DIR__); + $root_dir = self::get_self_dir(); if (empty($this->version)) { $this->version["status"] = -1; @@ -413,7 +413,7 @@ class Config { private function _get_migrations() : Db_Migrations { if (empty($this->migrations)) { $this->migrations = new Db_Migrations(); - $this->migrations->initialize(dirname(__DIR__) . "/sql", "ttrss_version", true, self::SCHEMA_VERSION); + $this->migrations->initialize(self::get_self_dir() . "/sql", "ttrss_version", true, self::SCHEMA_VERSION); } return $this->migrations; @@ -703,4 +703,9 @@ class Config { static function get_user_agent(): string { return sprintf(self::get(self::HTTP_USER_AGENT), self::get_version()); } + + static function get_self_dir() : string { + return dirname(__DIR__); # we're in classes/Config.php + } + } diff --git a/classes/PluginHost.php b/classes/PluginHost.php index 7778c008f..700e0e8f5 100644 --- a/classes/PluginHost.php +++ b/classes/PluginHost.php @@ -459,10 +459,10 @@ class PluginHost { $span->addEvent("$class_file: load"); // try system plugin directory first - $file = dirname(__DIR__) . "/plugins/$class_file/init.php"; + $file = Config::get_self_dir() . "/plugins/$class_file/init.php"; if (!file_exists($file)) { - $file = dirname(__DIR__) . "/plugins.local/$class_file/init.php"; + $file = Config::get_self_dir() . "/plugins.local/$class_file/init.php"; if (!file_exists($file)) { continue; diff --git a/classes/Pref_Prefs.php b/classes/Pref_Prefs.php index da0ee54f7..5aa2382dd 100644 --- a/classes/Pref_Prefs.php +++ b/classes/Pref_Prefs.php @@ -1061,7 +1061,7 @@ class Pref_Prefs extends Handler_Protected { * @return array */ static function _get_updated_plugins(): array { - $root_dir = dirname(dirname(__DIR__)); # we're in classes/pref/ + $root_dir = Config::get_self_dir(); $plugin_dirs = array_filter(glob("$root_dir/plugins.local/*"), "is_dir"); $rv = []; @@ -1185,7 +1185,7 @@ class Pref_Prefs extends Handler_Protected { $plugin_name = basename(clean($_REQUEST['plugin'])); $status = 0; - $plugin_dir = dirname(dirname(__DIR__)) . "/plugins.local/$plugin_name"; + $plugin_dir = Config::get_self_dir() . "/plugins.local/$plugin_name"; if (is_dir($plugin_dir)) { $status = $this->_recursive_rmdir($plugin_dir); @@ -1199,7 +1199,7 @@ class Pref_Prefs extends Handler_Protected { if ($_SESSION["access_level"] >= UserHelper::ACCESS_LEVEL_ADMIN && Config::get(Config::ENABLE_PLUGIN_INSTALLER)) { $plugin_name = basename(clean($_REQUEST['plugin'])); $all_plugins = $this->_get_available_plugins(); - $plugin_dir = dirname(dirname(__DIR__)) . "/plugins.local"; + $plugin_dir = Config::get_self_dir() . "/plugins.local"; $work_dir = "$plugin_dir/plugin-installer"; @@ -1306,7 +1306,7 @@ class Pref_Prefs extends Handler_Protected { function checkForPluginUpdates(): void { if ($_SESSION["access_level"] >= UserHelper::ACCESS_LEVEL_ADMIN && Config::get(Config::CHECK_FOR_UPDATES) && Config::get(Config::CHECK_FOR_PLUGIN_UPDATES)) { $plugin_name = $_REQUEST["name"] ?? ""; - $root_dir = dirname(dirname(__DIR__)); # we're in classes/pref/ + $root_dir = Config::get_self_dir(); $rv = empty($plugin_name) ? self::_get_updated_plugins() : [ ["plugin" => $plugin_name, "rv" => self::_plugin_needs_update($root_dir, $plugin_name)], @@ -1324,8 +1324,7 @@ class Pref_Prefs extends Handler_Protected { $plugins = array_filter($plugins, 'strlen'); } - # we're in classes/pref/ - $root_dir = dirname(dirname(__DIR__)); + $root_dir = Config::get_self_dir(); $rv = []; diff --git a/tests/SelfDirTest.php b/tests/SelfDirTest.php new file mode 100644 index 000000000..5b7396a66 --- /dev/null +++ b/tests/SelfDirTest.php @@ -0,0 +1,12 @@ +assertEquals( + dirname(__DIR__), # we're in (app)/tests/ + Config::get_self_dir() + ); + } +}