Elgg  Version 6.0
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\Event $event) {
20  return $event->getValue() . elgg_echo('diagnostics:report:basic', [elgg_get_release()]);
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\Event $event) {
69  return $event->getValue() . elgg_echo('diagnostics:report:md5', [self::md5dir(elgg_get_root_path())]);
70  }
71 
79  public static function getPHPInfo(\Elgg\Event $event) {
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 $event->getValue() . elgg_echo('diagnostics:report:php', [print_r($phpinfo, true)]);
99  }
100 
108  public static function getGlobals(\Elgg\Event $event) {
109 
110  $output = str_replace(elgg_get_config('dbpass'), '<<DBPASS>>', print_r($GLOBALS, true));
111  return $event->getValue() . elgg_echo('diagnostics:report:globals', [$output]);
112  }
113 }
elgg_get_release()
Get the current Elgg release.
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
static getPHPInfo(\Elgg\Event $event)
Get some information about the php install.
Definition: Reports.php:79
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
static getSigs(\Elgg\Event $event)
Get some information about the files installed on a system.
Definition: Reports.php:68
static getBasic(\Elgg\Event $event)
Generate a basic report.
Definition: Reports.php:19
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:53
static getGlobals(\Elgg\Event $event)
Get global variables.
Definition: Reports.php:108
Event handlers for Developers plugin.
Definition: Reports.php:10
elgg_get_root_path()
Get the project path (where composer is installed), ending with slash.
static sanitize($path, $append_slash=true)
Sanitize file paths ensuring that they begin and end with slashes etc.
Definition: Paths.php:76
$output
Definition: download.php:9
Models an event passed to event handlers.
Definition: Event.php:11