mirror of
https://github.com/friendica/friendica
synced 2025-04-26 19:10:11 +00:00
Merge pull request #12322 from annando/api-rules
API: Central way to fetch the system rules
This commit is contained in:
commit
22e2578b23
9 changed files with 172 additions and 123 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue