From 60a32057f82d4261ac7696cc6abaae0dac187d75 Mon Sep 17 00:00:00 2001 From: RPJosh Date: Sun, 7 Jul 2024 12:48:12 +0200 Subject: [PATCH] Add compatibility to nc 29 --- appinfo/info.xml | 2 +- composer.json | 5 +++ lib/Controller/PageController.php | 52 +++--------------------------- lib/Controller/UtilsController.php | 49 ++-------------------------- lib/Helper/Functions.php | 50 ++++++++++++++++++++++++++++ lib/Settings/Admin.php | 23 +------------ 6 files changed, 65 insertions(+), 116 deletions(-) create mode 100644 lib/Helper/Functions.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 86604f1..bcac061 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -23,7 +23,7 @@ pgsql sqlite mysql - + OCA\GpxEdit\Settings\Admin diff --git a/composer.json b/composer.json index 18e83db..89a9939 100644 --- a/composer.json +++ b/composer.json @@ -17,5 +17,10 @@ "psr-4": { "OCP\\": "vendor/nextcloud/ocp/OCP" } + }, + "autoload": { + "files": [ + "lib/Helper/Functions.php" + ] } } \ No newline at end of file diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 2758e8b..282b2f9 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -27,6 +27,11 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Controller; +require_once(__DIR__ . '/../Helper/Functions.php'); +use function OCA\GpxEdit\Helper\globRecursive; +use function OCA\GpxEdit\Helper\getProgramPath; +use function OCA\GpxEdit\Helper\endswith; + require_once('Conversion.php'); function delTree($dir) { @@ -37,53 +42,6 @@ function delTree($dir) { return rmdir($dir); } -/** - * Recursive find files from name pattern - */ -function globRecursive($path, $find, $recursive=True) { - $result = Array(); - $dh = opendir($path); - while (($file = readdir($dh)) !== false) { - if (substr($file, 0, 1) === '.') continue; - $rfile = "{$path}/{$file}"; - if (is_dir($rfile) and $recursive) { - foreach (globRecursive($rfile, $find) as $ret) { - array_push($result, $ret); - } - } else { - if (fnmatch($find, $file)){ - array_push($result, $rfile); - } - } - } - closedir($dh); - return $result; -} - -/* - * search into all directories in PATH environment variable - * to find a program and return it if found - */ -function getProgramPath($progname){ - $path_ar = explode(':',getenv('path')); - $path_ar = array_merge($path_ar, explode(':',getenv('PATH'))); - foreach ($path_ar as $path){ - $supposed_gpath = $path.'/'.$progname; - if (file_exists($supposed_gpath) and - is_executable($supposed_gpath)){ - return $supposed_gpath; - } - } - return null; -} - -function endswith($string, $test) { - $strlen = strlen($string); - $testlen = strlen($test); - if ($testlen > $strlen) return false; - return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0; -} - class PageController extends Controller { private $userId; diff --git a/lib/Controller/UtilsController.php b/lib/Controller/UtilsController.php index 2e8fa27..c611f05 100644 --- a/lib/Controller/UtilsController.php +++ b/lib/Controller/UtilsController.php @@ -29,52 +29,9 @@ use OCP\AppFramework\Controller; use function OCP\Log\logger; -/** - * Recursive find files from name pattern - */ -function globRecursive($path, $find, $recursive=True) { - $result = Array(); - $dh = opendir($path); - while (($file = readdir($dh)) !== false) { - if (substr($file, 0, 1) === '.') continue; - $rfile = "{$path}/{$file}"; - if (is_dir($rfile) and $recursive) { - foreach (globRecursive($rfile, $find) as $ret) { - array_push($result, $ret); - } - } else { - if (fnmatch($find, $file)){ - array_push($result, $rfile); - } - } - } - closedir($dh); - return $result; -} - -/* - * search into all directories in PATH environment variable - * to find a program and return it if found - */ -function getProgramPath($progname){ - $path_ar = explode(':',getenv('path')); - $path_ar = array_merge($path_ar, explode(':',getenv('PATH'))); - foreach ($path_ar as $path){ - $supposed_gpath = $path.'/'.$progname; - if (file_exists($supposed_gpath) and - is_executable($supposed_gpath)){ - return $supposed_gpath; - } - } - return null; -} - -function endswith($string, $test) { - $strlen = strlen($string); - $testlen = strlen($test); - if ($testlen > $strlen) return false; - return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0; -} +use function OCA\GpxEdit\Helper\globRecursive; +use function OCA\GpxEdit\Helper\getProgramPath; +use function OCA\GpxEdit\Helper\endswith; class UtilsController extends Controller { diff --git a/lib/Helper/Functions.php b/lib/Helper/Functions.php new file mode 100644 index 0000000..22a4ce6 --- /dev/null +++ b/lib/Helper/Functions.php @@ -0,0 +1,50 @@ + $strlen) return false; + return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0; +} \ No newline at end of file diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 7e4d7f8..227fb52 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -10,28 +10,7 @@ use OCP\Settings\ISettings; use OCP\Util; use OCP\IURLGenerator; -/** - * Recursive find files from name pattern - */ -function globRecursive($path, $find, $recursive=True) { - $result = Array(); - $dh = opendir($path); - while (($file = readdir($dh)) !== false) { - if (substr($file, 0, 1) === '.') continue; - $rfile = "{$path}/{$file}"; - if (is_dir($rfile) and $recursive) { - foreach (globRecursive($rfile, $find) as $ret) { - array_push($result, $ret); - } - } else { - if (fnmatch($find, $file)){ - array_push($result, $rfile); - } - } - } - closedir($dh); - return $result; -} +use function OCA\GpxEdit\Helper\globRecursive; class Admin implements ISettings {