]> git.mxchange.org Git - friendica.git/commitdiff
Add PHP 5 compatible recursive dirname()
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 15 Dec 2018 07:46:08 +0000 (02:46 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 15 Dec 2018 07:46:08 +0000 (02:46 -0500)
boot.php
src/App.php

index 24e6912797d667cf5a37ba1f9ecd7299b09b16f9..222011f6b76d7dc0ad2bb440c328437daf61bb5e 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -854,3 +854,22 @@ function validate_include(&$file)
        // Simply return flag
        return $valid;
 }
+
+/**
+ * PHP 5 compatible dirname() with count parameter
+ *
+ * @see http://php.net/manual/en/function.dirname.php#113193
+ *
+ * @deprecated with PHP 7
+ * @param string $path
+ * @param int    $levels
+ * @return string
+ */
+function rdirname($path, $levels = 1)
+{
+       if ($levels > 1) {
+               return dirname(rdirname($path, --$levels));
+       } else {
+               return dirname($path);
+       }
+}
\ No newline at end of file
index 45d743b0d61d55e5899f3a88b8f26b66f7bb776a..261c3e74cb6f970701ae11281c929905470a3fbd 100644 (file)
@@ -523,7 +523,7 @@ class App
                if (!empty($relative_script_path)) {
                        // Module
                        if (!empty($_SERVER['QUERY_STRING'])) {
-                               $path = trim(dirname($relative_script_path, substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/');
+                               $path = trim(rdirname($relative_script_path, substr_count(trim($_SERVER['QUERY_STRING'], '/'), '/') + 1), '/');
                        } else {
                                // Root page
                                $path = trim($relative_script_path, '/');