X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FSystem.php;h=42f5ab36aef2c85e001dfe60ddbf337405648d9a;hb=da58b894a4239e95342524eeacb85af7bf6c5a9d;hp=dbf49b38db18af1971c7e2daee05f67cb4a5fabb;hpb=f66420815793015db113315f28c4ef1931c304bb;p=friendica.git diff --git a/src/Core/System.php b/src/Core/System.php index dbf49b38db..42f5ab36ae 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -1,6 +1,6 @@ setType(Response::TYPE_XML); - DI::apiResponse()->addContent(XML::fromArray(["result" => $result], $xml)); + DI::apiResponse()->addContent(XML::fromArray(['result' => $result])); DI::page()->exit(DI::apiResponse()->generate()); self::exit(); @@ -438,14 +440,15 @@ class System /** * Fetch the load and number of processes * + * @param bool $get_processes * @return array */ - public static function getLoadAvg(): array + public static function getLoadAvg(bool $get_processes = true): array { - if (@is_readable('/proc/loadavg')) { + if ($get_processes && @is_readable('/proc/loadavg')) { $content = @file_get_contents('/proc/loadavg'); if (empty($content)) { - $content = shell_exec('uptime | sed "s/.*e: //" | sed "s/,//"'); + $content = shell_exec('uptime | sed "s/.*averages*: //" | sed "s/,//g"'); } } @@ -659,4 +662,35 @@ class System // Reaching this point means that the operating system is configured badly. return ""; } + + /** + * Fetch the system rules + * @param bool $numeric_id If set to "true", the rules are returned with a numeric id as key. + * + * @return array + */ + public static function getRules(bool $numeric_id = false): array + { + $rules = []; + $id = 0; + + if (DI::config()->get('system', 'tosdisplay')) { + $rulelist = DI::config()->get('system', 'tosrules') ?: DI::config()->get('system', 'tostext'); + $html = BBCode::convert($rulelist, false, BBCode::EXTERNAL); + + $msg = HTML::toPlaintext($html, 0, true); + foreach (explode("\n", trim($msg)) as $line) { + $line = trim($line); + if ($line) { + if ($numeric_id) { + $rules[++$id] = $line; + } else { + $rules[] = ['id' => (string)++$id, 'text' => $line]; + } + } + } + } + + return $rules; + } }