From 41333741b51dbe0eff4f40846e6b5709d40682e7 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Thu, 5 Apr 2018 11:53:59 -0500 Subject: [PATCH] Move get_all_php_files() to FileManage library as getAllPhpFiles() --- main/cron/lang/list_undefined_langvars.php | 28 +------------------ main/cron/lang/list_unused_langvars.php | 28 +------------------ main/inc/lib/fileManage.lib.php | 32 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 54 deletions(-) diff --git a/main/cron/lang/list_undefined_langvars.php b/main/cron/lang/list_undefined_langvars.php index 207d3a13a7..2fc3a2307a 100755 --- a/main/cron/lang/list_undefined_langvars.php +++ b/main/cron/lang/list_undefined_langvars.php @@ -29,7 +29,7 @@ $terms = null; // now get all terms found in all PHP files of Chamilo (this takes some time and memory) $undefined_terms = []; $l = strlen(api_get_path(SYS_PATH)); -$files = get_all_php_files(api_get_path(SYS_PATH)); +$files = getAllPhpFiles(api_get_path(SYS_PATH)); foreach ($files as $file) { //echo 'Analyzing '.$file."
"; $shortfile = substr($file, $l); @@ -73,29 +73,3 @@ foreach ($undefined_terms as $term => $file) { } echo "\n"; -function get_all_php_files($base_path) -{ - $list = scandir($base_path); - $files = []; - foreach ($list as $item) { - if (substr($item, 0, 1) == '.') { - continue; - } - $special_dirs = [api_get_path(SYS_TEST_PATH), api_get_path(SYS_COURSE_PATH), api_get_path(SYS_LANG_PATH), api_get_path(SYS_ARCHIVE_PATH)]; - if (in_array($base_path.$item.'/', $special_dirs)) { - continue; - } - if (is_dir($base_path.$item)) { - $files = array_merge($files, get_all_php_files($base_path.$item.'/')); - } else { - //only analyse php files - $sub = substr($item, -4); - if ($sub == '.php' or $sub == '.tpl') { - $files[] = $base_path.$item; - } - } - } - $list = null; - - return $files; -} diff --git a/main/cron/lang/list_unused_langvars.php b/main/cron/lang/list_unused_langvars.php index 6d2bee6e07..f72c673b30 100755 --- a/main/cron/lang/list_unused_langvars.php +++ b/main/cron/lang/list_unused_langvars.php @@ -31,7 +31,7 @@ echo count($defined_terms)." terms were found in language files
"; // time and memory) $usedTerms = []; $l = strlen(api_get_path(SYS_PATH)); -$files = get_all_php_files(api_get_path(SYS_PATH)); +$files = getAllPhpFget_iles(api_get_path(SYS_PATH)); // Browse files foreach ($files as $file) { //echo 'Analyzing '.$file."
"; @@ -86,29 +86,3 @@ foreach ($defined_terms as $term => $file) { } echo "\n"; -function get_all_php_files($base_path) -{ - $list = scandir($base_path); - $files = []; - foreach ($list as $item) { - if (substr($item, 0, 1) == '.') { - continue; - } - $special_dirs = [api_get_path(SYS_TEST_PATH), api_get_path(SYS_COURSE_PATH), api_get_path(SYS_LANG_PATH), api_get_path(SYS_ARCHIVE_PATH)]; - if (in_array($base_path.$item.'/', $special_dirs)) { - continue; - } - if (is_dir($base_path.$item)) { - $files = array_merge($files, get_all_php_files($base_path.$item.'/')); - } else { - //only analyse php files - $sub = substr($item, -4); - if ($sub == '.php' or $sub == '.tpl') { - $files[] = $base_path.$item; - } - } - } - $list = null; - - return $files; -} diff --git a/main/inc/lib/fileManage.lib.php b/main/inc/lib/fileManage.lib.php index eedfd91ca5..4c3ad77346 100755 --- a/main/inc/lib/fileManage.lib.php +++ b/main/inc/lib/fileManage.lib.php @@ -344,3 +344,35 @@ function getextension($filename) return [array_pop($bouts), implode('.', $bouts)]; } + +/** + * Get a list of all PHP (.php) files in a given directory. Includes .tpl files + * @param $base_path The base path in which to find the corresponding files + * @return array + */ +function getAllPhpFiles($base_path) +{ + $list = scandir($base_path); + $files = []; + foreach ($list as $item) { + if (substr($item, 0, 1) == '.') { + continue; + } + $special_dirs = [api_get_path(SYS_TEST_PATH), api_get_path(SYS_COURSE_PATH), api_get_path(SYS_LANG_PATH), api_get_path(SYS_ARCHIVE_PATH)]; + if (in_array($base_path.$item.'/', $special_dirs)) { + continue; + } + if (is_dir($base_path.$item)) { + $files = array_merge($files, get_all_php_files($base_path.$item.'/')); + } else { + //only analyse php files + $sub = substr($item, -4); + if ($sub == '.php' or $sub == '.tpl') { + $files[] = $base_path.$item; + } + } + } + $list = null; + + return $files; +} \ No newline at end of file