X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FSystem.php;h=f94004a880ab10a047935c653432cb887cc25aab;hb=88b3effc180c5477bc8002b9d9ea8f3f628588dd;hp=0c1e499d939395ac82ec2c5a05451d9873da95a1;hpb=08ead524339a43f29c809ca63514e40cd24dee9c;p=friendica.git diff --git a/src/Core/System.php b/src/Core/System.php index 0c1e499d93..f94004a880 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,18 @@ 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 { - $content = @file_get_contents('/proc/loadavg'); - if (empty($content)) { - $content = shell_exec('cat /proc/loadavg'); + if ($get_processes && @is_readable('/proc/loadavg')) { + $content = @file_get_contents('/proc/loadavg'); + if (empty($content)) { + $content = shell_exec('uptime | sed "s/.*averages*: //" | sed "s/,//g"'); + } } + if (empty($content) || !preg_match("#([.\d]+)\s([.\d]+)\s([.\d]+)\s(\d+)/(\d+)#", $content, $matches)) { $load_arr = sys_getloadavg(); if (empty($load_arr)) { @@ -656,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; + } }