Move get_all_php_files() to FileManage library as getAllPhpFiles() - part 2/2

pull/2487/head
Yannick Warnier 7 years ago
parent 24b4dfc6fb
commit c0e2f91f29
  1. 13
      main/inc/lib/fileManage.lib.php
  2. 35
      tests/scripts/img/list_unused_img.php
  3. 23
      tests/scripts/img/list_used_img.php

@ -348,12 +348,19 @@ function getextension($filename)
/**
* 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
* @param $includeStatic Include static .html, .htm and .css files
* @return array
*/
function getAllPhpFiles($base_path)
function getAllPhpFiles($base_path, $includeStatic = false)
{
$list = scandir($base_path);
$files = [];
$extensionsArray = ['.php', '.tpl'];
if ($includeStatic) {
$extensionsArray[] = 'html';
$extensionsArray[] = '.htm';
$extensionsArray[] = '.css';
}
foreach ($list as $item) {
if (substr($item, 0, 1) == '.') {
continue;
@ -363,11 +370,11 @@ function getAllPhpFiles($base_path)
continue;
}
if (is_dir($base_path.$item)) {
$files = array_merge($files, get_all_php_files($base_path.$item.'/'));
$files = array_merge($files, getAllPhpFiles($base_path.$item.'/', $includeStatic));
} else {
//only analyse php files
$sub = substr($item, -4);
if ($sub == '.php' or $sub == '.tpl') {
if (in_array($sub, $extensionsArray)) {
$files[] = $base_path.$item;
}
}

@ -64,41 +64,6 @@ foreach ($unused as $term => $path) {
}
echo "</table>\n";
/**
* @param $base_path
* @return array
*/
function get_all_php_files($base_path)
{
$list = scandir($base_path);
$files = array();
foreach ($list as $item) {
if (substr($item, 0, 1)=='.') {
continue;
}
$special_dirs = array(
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
$ext = substr($item, -4);
if (in_array($ext, array('.php', 'html', '.htm', '.css'))) {
$files[] = $base_path.$item;
}
}
}
$list = null;
return $files;
}
/**
* Get the list of available images
* @param string $path The path to start the scan from

@ -19,7 +19,7 @@ $found_img = get_img_files($path);
// now get all terms found in all PHP files of Chamilo (this takes some time and memory)
$unexisting_img = array();
$l = strlen(api_get_path(SYS_PATH));
$files = get_all_php_files(api_get_path(SYS_PATH));
$files = getAllPhpFiles(api_get_path(SYS_PATH), true);
$counter = 0;
foreach ($files as $file) {
$shortfile = substr($file,$l);
@ -77,27 +77,6 @@ echo "</table>\n";
echo "Analysed files:<br />\n";
print_r($files);
function get_all_php_files($base_path) {
$list = scandir($base_path);
$files = array();
foreach ($list as $item) {
if (substr($item,0,1)=='.') {continue;}
$special_dirs = array(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
$ext = substr($item,-4);
if (in_array($ext,array('.php','html','.htm','.css'))) {
$files[] = $base_path.$item;
}
}
}
$list = null;
return $files;
}
function get_img_files($path) {
$files = array();
//We know there are max 3 levels

Loading…
Cancel
Save