Merge pull request #12322 from annando/api-rules

API: Central way to fetch the system rules
This commit is contained in:
Hypolite Petovan 2022-12-03 17:24:52 -05:00 committed by GitHub
commit 22e2578b23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 172 additions and 123 deletions

View file

@ -21,6 +21,8 @@
namespace Friendica\Core;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\DI;
use Friendica\Module\Response;
@ -660,4 +662,30 @@ class System
// Reaching this point means that the operating system is configured badly.
return "";
}
/**
* Fetch the system rules
*
* @return array
*/
public static function getRules(): 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", $msg) as $line) {
$line = trim($line);
if ($line) {
$rules[] = ['id' => (string)++$id, 'text' => $line];
}
}
}
return $rules;
}
}