Move get_all_php_files() to FileManage library as getAllPhpFiles()

pull/2487/head
Yannick Warnier 7 years ago
parent 7c306dc67f
commit 24b4dfc6fb
  1. 28
      main/cron/lang/list_undefined_langvars.php
  2. 28
      main/cron/lang/list_unused_langvars.php
  3. 32
      main/inc/lib/fileManage.lib.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."<br />";
$shortfile = substr($file, $l);
@ -73,29 +73,3 @@ foreach ($undefined_terms as $term => $file) {
}
echo "</table>\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;
}

@ -31,7 +31,7 @@ echo count($defined_terms)." terms were found in language files<br />";
// 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."<br />";
@ -86,29 +86,3 @@ foreach ($defined_terms as $term => $file) {
}
echo "</table>\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;
}

@ -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;
}
Loading…
Cancel
Save