X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FSystem.php;h=f94004a880ab10a047935c653432cb887cc25aab;hb=88b3effc180c5477bc8002b9d9ea8f3f628588dd;hp=aa2d81d8959e03c32fd182947418522eef6de235;hpb=9f03622841fb7caccbe471d7c0e1bec9812bf162;p=friendica.git diff --git a/src/Core/System.php b/src/Core/System.php index aa2d81d895..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(); @@ -660,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; + } }