Elgg  Version 4.3
Reports.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Diagnostics;
4 
6 
10 class Reports {
11 
19  public static function getBasic(\Elgg\Hook $hook) {
20  return $hook->getValue() . elgg_echo('diagnostics:report:basic', [elgg_get_release(), elgg_get_version()]);
21  }
22 
30  protected static function md5dir($dir) {
31  $dir = Paths::sanitize($dir);
32  $extensions_allowed = ['php', 'js', 'css'];
33 
34  if (!is_dir($dir)) {
35  return '';
36  }
37 
38  $buffer = '';
39 
40  $dh = new \DirectoryIterator($dir);
41  foreach ($dh as $fileinfo) {
42  if ($fileinfo->isDot()) {
43  continue;
44  }
45 
46  if ($fileinfo->isDir()) {
47  $buffer .= self::md5dir($fileinfo->getPathname());
48  }
49 
50  if (!in_array($fileinfo->getExtension(), $extensions_allowed)) {
51  continue;
52  }
53 
54  $filename = Paths::sanitize($fileinfo->getPathname(), false);
55  $buffer .= md5_file($filename) . " {$filename}" . PHP_EOL;
56  }
57 
58  return $buffer;
59  }
60 
68  public static function getSigs(\Elgg\Hook $hook) {
69  return $hook->getValue() . elgg_echo('diagnostics:report:md5', [self::md5dir(elgg_get_root_path())]);
70  }
71 
79  public static function getPHPInfo(\Elgg\Hook $hook) {
80 
81  ob_start();
82  phpinfo();
83  $phpinfo = ['phpinfo' => []];
84 
85  $matches = [];
86  if (preg_match_all('#(?:<h2>(?:<a name=".*?">)?(.*?)(?:</a>)?</h2>)|(?:<tr(?: class=".*?")?><t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>(?:<t[hd](?: class=".*?")?>(.*?)\s*</t[hd]>)?)?</tr>)#s', ob_get_clean(), $matches, PREG_SET_ORDER)) {
87  foreach ($matches as $match) {
88  if (elgg_strlen($match[1])) {
89  $phpinfo[$match[1]] = [];
90  } else if (isset($match[3])) {
91  $phpinfo[end(array_keys($phpinfo))][$match[2]] = isset($match[4]) ? [$match[3], $match[4]] : $match[3];
92  } else {
93  $phpinfo[end(array_keys($phpinfo))][] = $match[2];
94  }
95  }
96  }
97 
98  return $hook->getValue() . elgg_echo('diagnostics:report:php', [print_r($phpinfo, true)]);
99  }
100 
108  public static function getGlobals(\Elgg\Hook $hook) {
109 
110  $output = str_replace(elgg_get_config('dbpass'), '<<DBPASS>>', print_r($GLOBALS, true));
111  return $hook->getValue() . elgg_echo('diagnostics:report:globals', [$output]);
112  }
113 }
elgg_get_release()
Get the current Elgg release.
static getSigs(\Elgg\Hook $hook)
Get some information about the files installed on a system.
Definition: Reports.php:68
static getGlobals(\Elgg\Hook $hook)
Get global variables.
Definition: Reports.php:108
elgg_echo($message_key, array $args=[], $language="")
Elgg language module Functions to manage language and translations.
Definition: languages.php:18
static md5dir($dir)
Recursively list through a directory tree producing a hash of all installed files.
Definition: Reports.php:30
elgg_strlen()
Wrapper function for mb_strlen().
Definition: mb_wrapper.php:52
static getBasic(\Elgg\Hook $hook)
Generate a basic report.
Definition: Reports.php:19
Models an event passed to hook handlers.
Definition: Hook.php:11
Plugin hook handlers for Developers plugin.
Definition: Reports.php:10
elgg_get_root_path()
Get the project path (where composer is installed), ending with slash.
static getPHPInfo(\Elgg\Hook $hook)
Get some information about the php install.
Definition: Reports.php:79
$filename
static sanitize($path, $append_slash=true)
Sanitize file paths ensuring that they begin and end with slashes etc.
Definition: Paths.php:76
elgg_get_version($human_readable=false)
Bundle all functions which have been deprecated in Elgg 4.1.
$output
Definition: download.php:9
elgg_get_config($name, $default=null)
Get an Elgg configuration value.