| 1 |
<?php defined('ABSPATH') or die('Unauthorized Access'); ?> |
| 2 |
|
| 3 |
<div id="phpinfo-info"> |
| 4 |
|
| 5 |
<div class="phpinfowp-toolbar"> |
| 6 |
<div style="position:relative;flex:1;max-width:420px"> |
| 7 |
<input type="text" id="phpinfowp-search" |
| 8 |
placeholder="<?php echo esc_attr__('Search directives, values, modules… (e.g. memory_limit)', 'phpinfo-wp'); ?>" |
| 9 |
class="regular-text" |
| 10 |
style="width:100%;padding-right:32px" |
| 11 |
autocomplete="off" spellcheck="false"> |
| 12 |
<button type="button" id="phpinfowp-search-clear" |
| 13 |
style="display:none;position:absolute;right:6px;top:50%;transform:translateY(-50%);background:none;border:none;cursor:pointer;color:#999;font-size:18px;line-height:1;padding:0" |
| 14 |
title="<?php echo esc_attr__('Clear search', 'phpinfo-wp'); ?>">×</button> |
| 15 |
</div> |
| 16 |
<span id="phpinfowp-search-count" style="font-size:12px;color:#666;white-space:nowrap"></span> |
| 17 |
|
| 18 |
<select id="phpinfowp-section-jump" style="max-width:240px" title="<?php echo esc_attr__('Jump to section', 'phpinfo-wp'); ?>"> |
| 19 |
<option value=""><?php _e('Jump to section…', 'phpinfo-wp'); ?></option> |
| 20 |
</select> |
| 21 |
</div> |
| 22 |
|
| 23 |
<div id="phpinfo-WP"> |
| 24 |
<?php |
| 25 |
ob_start(); |
| 26 |
phpinfo(INFO_ALL & ~INFO_LICENSE & ~INFO_CREDITS); |
| 27 |
$phpinfo_raw = ob_get_clean(); |
| 28 |
|
| 29 |
// Extract body content |
| 30 |
$phpinfo_body = preg_replace('%^.*<body>(.*)</body>.*$%ms', '$1', $phpinfo_raw); |
| 31 |
|
| 32 |
// Strip phpinfo's own <style> block — we replace it with our own |
| 33 |
$phpinfo_body = preg_replace('/<style[^>]*>.*?<\/style>/si', '', $phpinfo_body); |
| 34 |
|
| 35 |
// Fix Zend optimizer module name |
| 36 |
$phpinfo_body = str_replace('module_Zend Optimizer', 'module_Zend_Optimizer', $phpinfo_body); |
| 37 |
|
| 38 |
echo $phpinfo_body; |
| 39 |
Phpinfo_wp::thankyou(); |
| 40 |
?> |
| 41 |
<button id="topButton-phpinfo-WP" title="<?php echo esc_attr__('Go to top', 'phpinfo-wp'); ?>" style="display:none"> |
| 42 |
<img src="<?php echo esc_url(plugin_dir_url(__FILE__) . '../assets/images/top.png'); ?>" |
| 43 |
alt="<?php echo esc_attr__('Top', 'phpinfo-wp'); ?>" id="topButtonImage-phpinfo-WP"> |
| 44 |
</button> |
| 45 |
</div> |
| 46 |
</div> |
| 47 |
|
| 48 |
<script> |
| 49 |
(function () { |
| 50 |
var container = document.getElementById('phpinfo-WP'); |
| 51 |
var searchInput = document.getElementById('phpinfowp-search'); |
| 52 |
var countEl = document.getElementById('phpinfowp-search-count'); |
| 53 |
var clearBtn = document.getElementById('phpinfowp-search-clear'); |
| 54 |
var jumpSelect = document.getElementById('phpinfowp-section-jump'); |
| 55 |
|
| 56 |
if (!container) return; |
| 57 |
|
| 58 |
// ── Build section jump list from <h2> anchors ────────────────────── |
| 59 |
var sections = Array.from(container.querySelectorAll('h2')); |
| 60 |
sections.forEach(function (h2) { |
| 61 |
var anchor = h2.querySelector('a[name]'); |
| 62 |
var id = anchor ? anchor.getAttribute('name') : ''; |
| 63 |
var label = h2.textContent.trim(); |
| 64 |
if (!label) return; |
| 65 |
if (id) h2.id = id; // promote anchor name to h2 id for scrolling |
| 66 |
var opt = document.createElement('option'); |
| 67 |
opt.value = id || label; |
| 68 |
opt.textContent = label; |
| 69 |
opt.dataset.el = id || ''; |
| 70 |
jumpSelect.appendChild(opt); |
| 71 |
}); |
| 72 |
|
| 73 |
jumpSelect.addEventListener('change', function () { |
| 74 |
var id = this.value; |
| 75 |
var target = id ? document.getElementById(id) : null; |
| 76 |
if (target) { |
| 77 |
target.scrollIntoView({ behavior: 'smooth', block: 'start' }); |
| 78 |
// Brief highlight |
| 79 |
target.style.transition = 'background .2s'; |
| 80 |
target.style.background = '#f0f4ff'; |
| 81 |
setTimeout(function () { target.style.background = ''; }, 1200); |
| 82 |
} |
| 83 |
this.value = ''; |
| 84 |
}); |
| 85 |
|
| 86 |
// ── Pre-index all data rows ──────────────────────────────────────── |
| 87 |
var allTables = Array.from(container.querySelectorAll('table')); |
| 88 |
|
| 89 |
allTables.forEach(function (table) { |
| 90 |
Array.from(table.querySelectorAll('tr')).forEach(function (row) { |
| 91 |
if (!row.classList.contains('h')) { |
| 92 |
row._searchText = row.textContent.toLowerCase(); |
| 93 |
} |
| 94 |
}); |
| 95 |
}); |
| 96 |
|
| 97 |
// Map each table → its preceding h2 (for show/hide) |
| 98 |
var tableH2Map = new Map(); |
| 99 |
sections.forEach(function (h2) { |
| 100 |
var next = h2.nextElementSibling; |
| 101 |
while (next && next.tagName !== 'TABLE') next = next.nextElementSibling; |
| 102 |
if (next) tableH2Map.set(next, h2); |
| 103 |
}); |
| 104 |
|
| 105 |
// ── Search ───────────────────────────────────────────────────────── |
| 106 |
var currentHL = []; |
| 107 |
|
| 108 |
var langRowsMatched = <?php echo json_encode(__( 'rows matched', 'phpinfo-wp' )); ?>; |
| 109 |
var langRowMatched = <?php echo json_encode(__( 'row matched', 'phpinfo-wp' )); ?>; |
| 110 |
var langNoResults = <?php echo json_encode(__( 'No results', 'phpinfo-wp' )); ?>; |
| 111 |
|
| 112 |
function applySearch(q) { |
| 113 |
q = q.trim().toLowerCase(); |
| 114 |
clearBtn.style.display = q ? '' : 'none'; |
| 115 |
|
| 116 |
// Remove previous row highlights |
| 117 |
currentHL.forEach(function (row) { row.classList.remove('phpinfowp-row-hl'); }); |
| 118 |
currentHL = []; |
| 119 |
|
| 120 |
if (!q) { |
| 121 |
// Show everything |
| 122 |
allTables.forEach(function (t) { |
| 123 |
t.style.display = ''; |
| 124 |
Array.from(t.querySelectorAll('tr')).forEach(function (r) { r.style.display = ''; }); |
| 125 |
}); |
| 126 |
sections.forEach(function (h) { h.style.display = ''; }); |
| 127 |
countEl.textContent = ''; |
| 128 |
return; |
| 129 |
} |
| 130 |
|
| 131 |
var totalMatches = 0; |
| 132 |
|
| 133 |
allTables.forEach(function (table) { |
| 134 |
var rows = Array.from(table.querySelectorAll('tr')); |
| 135 |
var hasMatch = false; |
| 136 |
|
| 137 |
rows.forEach(function (row) { |
| 138 |
if (row.classList.contains('h')) { |
| 139 |
// Always show header row if table is shown |
| 140 |
row.style.display = ''; |
| 141 |
return; |
| 142 |
} |
| 143 |
if (row._searchText && row._searchText.includes(q)) { |
| 144 |
row.style.display = ''; |
| 145 |
row.classList.add('phpinfowp-row-hl'); |
| 146 |
currentHL.push(row); |
| 147 |
hasMatch = true; |
| 148 |
totalMatches++; |
| 149 |
} else { |
| 150 |
row.style.display = 'none'; |
| 151 |
} |
| 152 |
}); |
| 153 |
|
| 154 |
table.style.display = hasMatch ? '' : 'none'; |
| 155 |
var h2 = tableH2Map.get(table); |
| 156 |
if (h2) h2.style.display = hasMatch ? '' : 'none'; |
| 157 |
}); |
| 158 |
|
| 159 |
countEl.textContent = totalMatches |
| 160 |
? totalMatches + ' ' + (totalMatches !== 1 ? langRowsMatched : langRowMatched) |
| 161 |
: langNoResults; |
| 162 |
|
| 163 |
// Scroll first match into view |
| 164 |
if (currentHL[0]) { |
| 165 |
currentHL[0].scrollIntoView({ behavior: 'smooth', block: 'center' }); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
searchInput.addEventListener('input', function () { applySearch(this.value); }); |
| 170 |
searchInput.addEventListener('keydown', function (e) { |
| 171 |
if (e.key === 'Escape') { searchInput.value = ''; applySearch(''); } |
| 172 |
}); |
| 173 |
clearBtn.addEventListener('click', function () { |
| 174 |
searchInput.value = ''; |
| 175 |
applySearch(''); |
| 176 |
searchInput.focus(); |
| 177 |
}); |
| 178 |
|
| 179 |
// Global access |
| 180 |
window.phpinfowpSearch = applySearch; |
| 181 |
window.phpinfowpClearSearch = function () { searchInput.value = ''; applySearch(''); searchInput.focus(); }; |
| 182 |
})(); |
| 183 |
</script> |