Skip to content

Instantly share code, notes, and snippets.

@mrclay mrclay/elgg-included-files.php Secret
Last active Aug 29, 2015

Embed
What would you like to do?
Elgg: in HTML pages, logs the PHP included file paths to the JS console
<?php
// Don't use in production!
// Does not cover shutdown event activities.
elgg_register_plugin_hook_handler('output', 'page', function ($h, $t, $html, $p) {
if (false === strpos($html, '</body>')) {
return;
}
$root = elgg_get_root_path();
$root_len = strlen($root);
$data_root = elgg_get_data_path();
$data_root_len = strlen($data_root);
$stats = [];
// does not include non-include file reads
foreach (get_included_files() as $file) {
// rewrite paths
if (0 === strpos($file, $root)) {
$file = "<elgg>/" . substr($file, $root_len);
} elseif (0 === strpos($file, $data_root)) {
$file = "<data>/" . substr($file, $data_root_len);
}
// build stats
$stats['all'][] = $file;
if (0 === strpos($file, '<elgg>/views/') || preg_match('~^<elgg>/mod/[^/]+/views/~', $file)) {
$stats['view files'][] = $file;
} elseif (0 === strpos($file, '<elgg>/engine/classes/')) {
$stats['core classes'][] = substr($file, strlen('<elgg>/engine/classes/'));
} elseif (0 === strpos($file, '<elgg>/engine/')) {
$stats['core others'][] = substr($file, strlen('<elgg>/engine/'));
} elseif (preg_match('~<elgg>/vendor/([^/]+/[^/]+)/~', $file, $m)) {
$stats['vendor'][$m[1]][] = substr($file, strlen($m[0]));
} elseif (0 === strpos($file, '<elgg>/mod/')) {
$stats['plugin files'][] = substr($file, strlen('<elgg>/mod/'));
} else {
$stats['others'][] = $file;
}
}
$script = "<script>console.log('PHP include()s:', " . json_encode($stats) . ");</script>";
$html = str_replace('</body>', "$script</body>", $html);
return $html;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.