Replace all functions from boot.php

This commit is contained in:
Michael 2022-10-18 20:42:46 +00:00 committed by Hypolite Petovan
parent 5f1028a535
commit 5d8129600d
45 changed files with 577 additions and 535 deletions

View file

@ -39,6 +39,7 @@ use Friendica\Content\Text\Markdown;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\DI;
@ -123,21 +124,21 @@ function advancedcontentfilter_prepare_body_content_filter(App $a, &$hook_data)
$expressionLanguage = new ExpressionLanguage\ExpressionLanguage();
}
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
$vars = advancedcontentfilter_get_filter_fields($hook_data['item']);
$rules = DI::cache()->get('rules_' . local_user());
$rules = DI::cache()->get('rules_' . Session::getLocalUser());
if (!isset($rules)) {
$rules = DBA::toArray(DBA::select(
'advancedcontentfilter_rules',
['name', 'expression', 'serialized'],
['uid' => local_user(), 'active' => true]
['uid' => Session::getLocalUser(), 'active' => true]
));
DI::cache()->set('rules_' . local_user(), $rules);
DI::cache()->set('rules_' . Session::getLocalUser(), $rules);
}
if ($rules) {
@ -165,7 +166,7 @@ function advancedcontentfilter_prepare_body_content_filter(App $a, &$hook_data)
function advancedcontentfilter_addon_settings(App $a, array &$data)
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return;
}
@ -203,12 +204,12 @@ function advancedcontentfilter_init(App $a)
function advancedcontentfilter_content(App $a)
{
if (!local_user()) {
if (!Session::getLocalUser()) {
return Login::form('/' . implode('/', DI::args()->getArgv()));
}
if (DI::args()->getArgc() > 1 && DI::args()->getArgv()[1] == 'help') {
$user = User::getById(local_user());
$user = User::getById(Session::getLocalUser());
$lang = $user['language'];
@ -272,9 +273,9 @@ function advancedcontentfilter_build_fields($data)
if (!empty($data['expression'])) {
// Using a dummy item to validate the field existence
$condition = ["(`uid` = ? OR `uid` = 0)", local_user()];
$condition = ["(`uid` = ? OR `uid` = 0)", Session::getLocalUser()];
$params = ['order' => ['uid' => true]];
$item_row = Post::selectFirstForUser(local_user(), [], $condition, $params);
$item_row = Post::selectFirstForUser(Session::getLocalUser(), [], $condition, $params);
if (!DBA::isResult($item_row)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('This addon requires this node having at least one post'));
@ -307,29 +308,29 @@ function advancedcontentfilter_build_fields($data)
function advancedcontentfilter_get_rules()
{
if (!local_user()) {
if (!Session::getLocalUser()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this method'));
}
$rules = DBA::toArray(DBA::select('advancedcontentfilter_rules', [], ['uid' => local_user()]));
$rules = DBA::toArray(DBA::select('advancedcontentfilter_rules', [], ['uid' => Session::getLocalUser()]));
return json_encode($rules);
}
function advancedcontentfilter_get_rules_id(ServerRequestInterface $request, ResponseInterface $response, $args)
{
if (!local_user()) {
if (!Session::getLocalUser()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this method'));
}
$rule = DBA::selectFirst('advancedcontentfilter_rules', [], ['id' => $args['id'], 'uid' => local_user()]);
$rule = DBA::selectFirst('advancedcontentfilter_rules', [], ['id' => $args['id'], 'uid' => Session::getLocalUser()]);
return json_encode($rule);
}
function advancedcontentfilter_post_rules(ServerRequestInterface $request)
{
if (!local_user()) {
if (!Session::getLocalUser()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this method'));
}
@ -349,7 +350,7 @@ function advancedcontentfilter_post_rules(ServerRequestInterface $request)
throw new HTTPException\BadRequestException(DI::l10n()->t('The rule name and expression are required.'));
}
$fields['uid'] = local_user();
$fields['uid'] = Session::getLocalUser();
$fields['created'] = DateTimeFormat::utcNow();
if (!DBA::insert('advancedcontentfilter_rules', $fields)) {
@ -358,14 +359,14 @@ function advancedcontentfilter_post_rules(ServerRequestInterface $request)
$rule = DBA::selectFirst('advancedcontentfilter_rules', [], ['id' => DBA::lastInsertId()]);
DI::cache()->delete('rules_' . local_user());
DI::cache()->delete('rules_' . Session::getLocalUser());
return json_encode(['message' => DI::l10n()->t('Rule successfully added'), 'rule' => $rule]);
}
function advancedcontentfilter_put_rules_id(ServerRequestInterface $request, ResponseInterface $response, $args)
{
if (!local_user()) {
if (!Session::getLocalUser()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this method'));
}
@ -373,7 +374,7 @@ function advancedcontentfilter_put_rules_id(ServerRequestInterface $request, Res
throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid form security token, please refresh the page.'));
}
if (!DBA::exists('advancedcontentfilter_rules', ['id' => $args['id'], 'uid' => local_user()])) {
if (!DBA::exists('advancedcontentfilter_rules', ['id' => $args['id'], 'uid' => Session::getLocalUser()])) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Rule doesn\'t exist or doesn\'t belong to you.'));
}
@ -389,14 +390,14 @@ function advancedcontentfilter_put_rules_id(ServerRequestInterface $request, Res
throw new HTTPException\ServiceUnavailableException(DBA::errorMessage());
}
DI::cache()->delete('rules_' . local_user());
DI::cache()->delete('rules_' . Session::getLocalUser());
return json_encode(['message' => DI::l10n()->t('Rule successfully updated')]);
}
function advancedcontentfilter_delete_rules_id(ServerRequestInterface $request, ResponseInterface $response, $args)
{
if (!local_user()) {
if (!Session::getLocalUser()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this method'));
}
@ -404,7 +405,7 @@ function advancedcontentfilter_delete_rules_id(ServerRequestInterface $request,
throw new HTTPException\BadRequestException(DI::l10n()->t('Invalid form security token, please refresh the page.'));
}
if (!DBA::exists('advancedcontentfilter_rules', ['id' => $args['id'], 'uid' => local_user()])) {
if (!DBA::exists('advancedcontentfilter_rules', ['id' => $args['id'], 'uid' => Session::getLocalUser()])) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Rule doesn\'t exist or doesn\'t belong to you.'));
}
@ -412,14 +413,14 @@ function advancedcontentfilter_delete_rules_id(ServerRequestInterface $request,
throw new HTTPException\ServiceUnavailableException(DBA::errorMessage());
}
DI::cache()->delete('rules_' . local_user());
DI::cache()->delete('rules_' . Session::getLocalUser());
return json_encode(['message' => DI::l10n()->t('Rule successfully deleted')]);
}
function advancedcontentfilter_get_variables_guid(ServerRequestInterface $request, ResponseInterface $response, $args)
{
if (!local_user()) {
if (!Session::getLocalUser()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this method'));
}
@ -427,9 +428,9 @@ function advancedcontentfilter_get_variables_guid(ServerRequestInterface $reques
throw new HTTPException\BadRequestException(DI::l10n()->t('Missing argument: guid.'));
}
$condition = ["`guid` = ? AND (`uid` = ? OR `uid` = 0)", $args['guid'], local_user()];
$condition = ["`guid` = ? AND (`uid` = ? OR `uid` = 0)", $args['guid'], Session::getLocalUser()];
$params = ['order' => ['uid' => true]];
$item_row = Post::selectFirstForUser(local_user(), [], $condition, $params);
$item_row = Post::selectFirstForUser(Session::getLocalUser(), [], $condition, $params);
if (!DBA::isResult($item_row)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Unknown post with guid: %s', $args['guid']));