PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / root-boot / ShortcodeAndIntegrity.php

ShortcodeAndIntegrity.php in 404 Solution trunk, at includes/root-boot/ShortcodeAndIntegrity.php

119 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) {
3 exit;
4 }
5
6 /**
7 * Page-suggestions shortcode handler and runtime file-integrity verification.
8 *
9 * abj404_shortCodeListener() renders the [abj404_solution_page_suggestions]
10 * shortcode (loading the plugin lazily). abj404_verify_runtime_integrity()
11 * reports which required plugin files are missing, using the canonical
12 * required-files list that abj404_get_required_runtime_files() builds from the
13 * external data file includes/data/required-runtime-files.php.
14 *
15 * The add_shortcode() registration stays in 404-solution.php; this file only
16 * defines the callback and the integrity-check helpers.
17 */
18 // allow-no-test-found: boot-time global functions (shortcode handler + runtime integrity helpers) wired via add_shortcode in 404-solution.php; no same-named unit file. abj404_get_required_runtime_files and abj404_verify_runtime_integrity are exercised in SqlFileIntegrityListCompletenessTest.
19
20 if (!function_exists('abj404_get_required_runtime_files')) {
21 /**
22 * Files required for a healthy runtime/plugin package.
23 * Covers boot-critical PHP files and essential SQL templates.
24 *
25 * The static lists are DATA, loaded from
26 * includes/data/required-runtime-files.php; the dynamic classmap file list
27 * is merged in here at runtime.
28 *
29 * @return array<int, string>
30 */
31 function abj404_get_required_runtime_files() {
32 $inc = ABJ404_PATH . 'includes/';
33 $classmapFile = $inc . 'classmap.php';
34 if (!file_exists($classmapFile)) {
35 $classmapFile = dirname(__DIR__) . '/classmap.php';
36 }
37 $classmapFiles = array();
38 if (file_exists($classmapFile)) {
39 $classmap = require $classmapFile;
40 if (is_array($classmap)) {
41 foreach ($classmap as $classmapPath) {
42 if (is_string($classmapPath)) {
43 $classmapFiles[] = $classmapPath;
44 }
45 }
46 }
47 }
48
49 $dataFile = dirname(__DIR__) . '/data/required-runtime-files.php';
50 $lists = file_exists($dataFile) ? require $dataFile : array();
51 if (!is_array($lists)) {
52 $lists = array();
53 }
54 $bootRelative = isset($lists['boot']) && is_array($lists['boot']) ? $lists['boot'] : array();
55 $sqlRelative = isset($lists['sql']) && is_array($lists['sql']) ? $lists['sql'] : array();
56 $rootRelative = isset($lists['root']) && is_array($lists['root']) ? $lists['root'] : array();
57
58 $bootFiles = array();
59 foreach ($bootRelative as $relative) {
60 if (is_string($relative)) {
61 $bootFiles[] = $inc . $relative;
62 }
63 }
64 $sqlFiles = array();
65 foreach ($sqlRelative as $relative) {
66 if (is_string($relative)) {
67 $sqlFiles[] = $inc . $relative;
68 }
69 }
70 $rootFiles = array();
71 foreach ($rootRelative as $relative) {
72 if (is_string($relative)) {
73 $rootFiles[] = ABJ404_PATH . $relative;
74 }
75 }
76
77 return array_values(array_unique(array_merge(
78 $bootFiles,
79 $rootFiles,
80 $classmapFiles,
81 $sqlFiles
82 )));
83 }
84 }
85
86 if (!function_exists('abj404_shortCodeListener')) {
87 /**
88 * @param array<string, mixed>|string $atts
89 * @return string
90 */
91 function abj404_shortCodeListener($atts) {
92 if (!$GLOBALS['abj404_boot_ok']) {
93 return '';
94 }
95 abj404_load_textdomain_if_needed();
96 require_once(plugin_dir_path( ABJ404_FILE ) . "includes/Loader.php");
97 /** @var array<string, mixed> $safeAtts */
98 $safeAtts = is_array($atts) ? $atts : array();
99 return ABJ_404_Solution_ShortCode::shortcodePageSuggestions($safeAtts);
100 }
101 }
102
103 if (!function_exists('abj404_verify_runtime_integrity')) {
104 /**
105 * Validate that required plugin files are present.
106 *
107 * @return array<int, string> Missing file paths.
108 */
109 function abj404_verify_runtime_integrity() {
110 $missing = array();
111 foreach (abj404_get_required_runtime_files() as $path) {
112 if (!file_exists($path)) {
113 $missing[] = $path;
114 }
115 }
116 return $missing;
117 }
118 }
119