Hook::add('dbstructure_definition' , __FILE__, 'advancedcontentfilter_dbstructure_definition');
DBStructure::performUpdate();
- Logger::notice("installed advancedcontentfilter");
+ Logger::notice('installed advancedcontentfilter');
}
/*
function advancedcontentfilter_dbstructure_definition(App $a, &$database)
{
- $database["advancedcontentfilter_rules"] = [
- "comment" => "Advancedcontentfilter addon rules",
- "fields" => [
- "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "Auto incremented rule id"],
- "uid" => ["type" => "int unsigned", "not null" => "1", "comment" => "Owner user id"],
- "name" => ["type" => "varchar(255)", "not null" => "1", "comment" => "Rule name"],
- "expression" => ["type" => "mediumtext" , "not null" => "1", "comment" => "Expression text"],
- "serialized" => ["type" => "mediumtext" , "not null" => "1", "comment" => "Serialized parsed expression"],
- "active" => ["type" => "boolean" , "not null" => "1", "default" => "1", "comment" => "Whether the rule is active or not"],
- "created" => ["type" => "datetime" , "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "Creation date"],
+ $database['advancedcontentfilter_rules'] = [
+ 'comment' => 'Advancedcontentfilter addon rules',
+ 'fields' => [
+ 'id' => ['type' => 'int unsigned', 'not null' => '1', 'extra' => 'auto_increment', 'primary' => '1', 'comment' => 'Auto incremented rule id'],
+ 'uid' => ['type' => 'int unsigned', 'not null' => '1', 'comment' => 'Owner user id'],
+ 'name' => ['type' => 'varchar(255)', 'not null' => '1', 'comment' => 'Rule name'],
+ 'expression' => ['type' => 'mediumtext' , 'not null' => '1', 'comment' => 'Expression text'],
+ 'serialized' => ['type' => 'mediumtext' , 'not null' => '1', 'comment' => 'Serialized parsed expression'],
+ 'active' => ['type' => 'boolean' , 'not null' => '1', 'default' => '1', 'comment' => 'Whether the rule is active or not'],
+ 'created' => ['type' => 'datetime' , 'not null' => '1', 'default' => DBA::NULL_DATETIME, 'comment' => 'Creation date'],
],
- "indexes" => [
- "PRIMARY" => ["id"],
- "uid_active" => ["uid", "active"],
+ 'indexes' => [
+ 'PRIMARY' => ['id'],
+ 'uid_active' => ['uid', 'active'],
]
];
}
$expressionLanguage = new ExpressionLanguage\ExpressionLanguage();
}
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
return;
}
$vars = advancedcontentfilter_get_filter_fields($hook_data['item']);
- $rules = DI::cache()->get('rules_' . local_user());
+ $rules = DI::cache()->get('rules_' . DI::userSession()->getLocalUserId());
if (!isset($rules)) {
$rules = DBA::toArray(DBA::select(
'advancedcontentfilter_rules',
['name', 'expression', 'serialized'],
- ['uid' => local_user(), 'active' => true]
+ ['uid' => DI::userSession()->getLocalUserId(), 'active' => true]
));
- DI::cache()->set('rules_' . local_user(), $rules);
+ DI::cache()->set('rules_' . DI::userSession()->getLocalUserId(), $rules);
}
if ($rules) {
function advancedcontentfilter_addon_settings(App $a, array &$data)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
return;
}
* Module
*/
+/**
+ * This is a statement rather than an actual function definition. The simple
+ * existence of this method is checked to figure out if the addon offers a
+ * module.
+ */
function advancedcontentfilter_module() {}
function advancedcontentfilter_init(App $a)
function advancedcontentfilter_content(App $a)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
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(DI::userSession()->getLocalUserId());
$lang = $user['language'];
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)", DI::userSession()->getLocalUserId()];
$params = ['order' => ['uid' => true]];
- $item_row = Post::selectFirstForUser(local_user(), [], $condition, $params);
+ $item_row = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), [], $condition, $params);
if (!DBA::isResult($item_row)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('This addon requires this node having at least one post'));
function advancedcontentfilter_get_rules()
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
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' => DI::userSession()->getLocalUserId()]));
return json_encode($rules);
}
function advancedcontentfilter_get_rules_id(ServerRequestInterface $request, ResponseInterface $response, $args)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
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' => DI::userSession()->getLocalUserId()]);
return json_encode($rule);
}
function advancedcontentfilter_post_rules(ServerRequestInterface $request)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this method'));
}
throw new HTTPException\BadRequestException(DI::l10n()->t('The rule name and expression are required.'));
}
- $fields['uid'] = local_user();
+ $fields['uid'] = DI::userSession()->getLocalUserId();
$fields['created'] = DateTimeFormat::utcNow();
if (!DBA::insert('advancedcontentfilter_rules', $fields)) {
$rule = DBA::selectFirst('advancedcontentfilter_rules', [], ['id' => DBA::lastInsertId()]);
- DI::cache()->delete('rules_' . local_user());
+ DI::cache()->delete('rules_' . DI::userSession()->getLocalUserId());
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 (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this method'));
}
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' => DI::userSession()->getLocalUserId()])) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Rule doesn\'t exist or doesn\'t belong to you.'));
}
throw new HTTPException\ServiceUnavailableException(DBA::errorMessage());
}
- DI::cache()->delete('rules_' . local_user());
+ DI::cache()->delete('rules_' . DI::userSession()->getLocalUserId());
return json_encode(['message' => DI::l10n()->t('Rule successfully updated')]);
}
function advancedcontentfilter_delete_rules_id(ServerRequestInterface $request, ResponseInterface $response, $args)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this method'));
}
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' => DI::userSession()->getLocalUserId()])) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Rule doesn\'t exist or doesn\'t belong to you.'));
}
throw new HTTPException\ServiceUnavailableException(DBA::errorMessage());
}
- DI::cache()->delete('rules_' . local_user());
+ DI::cache()->delete('rules_' . DI::userSession()->getLocalUserId());
return json_encode(['message' => DI::l10n()->t('Rule successfully deleted')]);
}
function advancedcontentfilter_get_variables_guid(ServerRequestInterface $request, ResponseInterface $response, $args)
{
- if (!local_user()) {
+ if (!DI::userSession()->getLocalUserId()) {
throw new HTTPException\UnauthorizedException(DI::l10n()->t('You must be logged in to use this method'));
}
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'], DI::userSession()->getLocalUserId()];
$params = ['order' => ['uid' => true]];
- $item_row = Post::selectFirstForUser(local_user(), [], $condition, $params);
+ $item_row = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), [], $condition, $params);
if (!DBA::isResult($item_row)) {
throw new HTTPException\NotFoundException(DI::l10n()->t('Unknown post with guid: %s', $args['guid']));
$item_row['tags'] = $tags['tags'];
$item_row['hashtags'] = $tags['hashtags'];
$item_row['mentions'] = $tags['mentions'];
- $item_row['attachments'] = Post\Media::splitAttachments($item_row['uri-id'], $item_row['guid'] ?? '');
+ $item_row['attachments'] = Post\Media::splitAttachments($item_row['uri-id']);
return $item_row;
}