|
| 1 | +<?php |
| 2 | + |
| 3 | + |
| 4 | +namespace FormTools\Modules\SystemCheck; |
| 5 | + |
| 6 | +use FormTools\Core; |
| 7 | +use FormTools\Themes; |
| 8 | + |
| 9 | + |
| 10 | +class Files |
| 11 | +{ |
| 12 | + /** |
| 13 | + * Helper function to return a list of files that are missing from the Core. |
| 14 | + * |
| 15 | + * @return array |
| 16 | + */ |
| 17 | + public static function checkCoreFiles() |
| 18 | + { |
| 19 | + $root_dir = Core::getRootDir(); |
| 20 | + |
| 21 | + if (!is_file("$root_dir/global/misc/config_core.php")) { |
| 22 | + return array(); |
| 23 | + } |
| 24 | + |
| 25 | + require_once("$root_dir/global/misc/config_core.php"); |
| 26 | + |
| 27 | + if (!isset($FILES)) { |
| 28 | + return array(); |
| 29 | + } |
| 30 | + |
| 31 | + $missing_files = array(); |
| 32 | + foreach ($FILES as $file) { |
| 33 | + // ignore the install/ folder folder + files |
| 34 | + if (preg_match("/^install/", $file)) { |
| 35 | + continue; |
| 36 | + } |
| 37 | + |
| 38 | + if (!is_file("$root_dir/$file") && !is_dir("$root_dir/$file")) { |
| 39 | + $missing_files[] = $file; |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + return $missing_files; |
| 44 | + } |
| 45 | + |
| 46 | + |
| 47 | + /** |
| 48 | + * Helper function to look at all installed themes and see which are compatible with the File Verification |
| 49 | + * test (i.e. which have a theme_config.php file defined in the root). |
| 50 | + */ |
| 51 | + public static function getCompatibleThemes() |
| 52 | + { |
| 53 | + $root_dir = Core::getRootDir(); |
| 54 | + $themes = Themes::getList(); |
| 55 | + |
| 56 | + $compatible_themes = array(); |
| 57 | + foreach ($themes as $theme_info) { |
| 58 | + $theme_folder = $theme_info["theme_folder"]; |
| 59 | + |
| 60 | + if (is_file("$root_dir/themes/$theme_folder/theme_config.php")) { |
| 61 | + $compatible_themes[] = $theme_info; |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + return $compatible_themes; |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + public static function checkModuleFiles($module_folder) |
| 70 | + { |
| 71 | + $root_dir = Core::getRootDir(); |
| 72 | + $file = "$root_dir/modules/$module_folder/module_config.php"; |
| 73 | + if (!is_file($file)) { |
| 74 | + return array(); |
| 75 | + } |
| 76 | + |
| 77 | + require_once($file); |
| 78 | + |
| 79 | + if (!isset($FILES)) { |
| 80 | + return array(); |
| 81 | + } |
| 82 | + |
| 83 | + $missing_files = array(); |
| 84 | + $root = "modules/$module_folder"; |
| 85 | + foreach ($FILES as $file) { |
| 86 | + if (!is_file("$root_dir/$root/$file") && !is_dir("$root_dir/$root/$file")) { |
| 87 | + $missing_files[] = "$root/$file"; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + return $missing_files; |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + public static function checkThemeFiles($theme_folder) |
| 96 | + { |
| 97 | + $root_dir = Core::getRootDir(); |
| 98 | + $file = "$root_dir/themes/$theme_folder/theme_config.php"; |
| 99 | + if (!is_file($file)) { |
| 100 | + return array(); |
| 101 | + } |
| 102 | + |
| 103 | + require_once($file); |
| 104 | + |
| 105 | + if (!isset($FILES)) { |
| 106 | + return array(); |
| 107 | + } |
| 108 | + |
| 109 | + $missing_files = array(); |
| 110 | + $root = "themes/$theme_folder"; |
| 111 | + foreach ($FILES as $file) { |
| 112 | + if (!is_file("$root_dir/$root/$file") && !is_dir("$root_dir/$root/$file")) { |
| 113 | + $missing_files[] = "$root/$file"; |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + return $missing_files; |
| 118 | + } |
| 119 | + |
| 120 | +} |
0 commit comments