50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace OCA\GpxEdit\Helper;
|
||
|
|
||
|
/**
|
||
|
* 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;
|
||
|
}
|