mirror of
https://github.com/friendica/friendica
synced 2025-05-18 01:44:12 +02:00
create event for parse_link hook
This commit is contained in:
parent
a9b36f55c9
commit
27e474c83c
5 changed files with 24 additions and 7 deletions
|
@ -54,6 +54,7 @@ final class HookEventBridge
|
|||
ArrayFilterEvent::PREPARE_POST_END => 'prepare_body_final',
|
||||
ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'photo_upload_form',
|
||||
ArrayFilterEvent::NETWORK_TO_NAME => 'network_to_name',
|
||||
ArrayFilterEvent::PARSE_LINK => 'parse_link',
|
||||
ArrayFilterEvent::CONVERSATION_START => 'conversation_start',
|
||||
ArrayFilterEvent::FETCH_ITEM_BY_LINK => 'item_by_link',
|
||||
ArrayFilterEvent::ITEM_TAGGED => 'tagged',
|
||||
|
@ -130,6 +131,7 @@ final class HookEventBridge
|
|||
ArrayFilterEvent::PREPARE_POST_END => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::PARSE_LINK => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::FETCH_ITEM_BY_LINK => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::ITEM_TAGGED => 'onArrayFilterEvent',
|
||||
|
|
|
@ -58,6 +58,8 @@ final class ArrayFilterEvent extends Event
|
|||
|
||||
public const NETWORK_TO_NAME = 'friendica.data.network_to_name';
|
||||
|
||||
public const PARSE_LINK = 'friendica.data.parse_link';
|
||||
|
||||
public const CONVERSATION_START = 'friendica.data.conversation_start';
|
||||
|
||||
public const FETCH_ITEM_BY_LINK = 'friendica.data.fetch_item_by_link';
|
||||
|
|
|
@ -11,12 +11,13 @@ use Friendica\App\Arguments;
|
|||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||
use Friendica\Event\ArrayFilterEvent;
|
||||
use Friendica\Network\HTTPException\BadRequestException;
|
||||
use Friendica\Util;
|
||||
use Friendica\Util\Profiler;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ParseUrl extends BaseModule
|
||||
|
@ -24,11 +25,14 @@ class ParseUrl extends BaseModule
|
|||
/** @var IHandleUserSessions */
|
||||
protected $userSession;
|
||||
|
||||
public function __construct(L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $userSession, $server, array $parameters = [])
|
||||
private EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
public function __construct(L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $userSession, EventDispatcherInterface $eventDispatcher, $server, array $parameters = [])
|
||||
{
|
||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||
|
||||
$this->userSession = $userSession;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
protected function rawContent(array $request = [])
|
||||
|
@ -80,15 +84,21 @@ class ParseUrl extends BaseModule
|
|||
}
|
||||
}
|
||||
|
||||
$arr = ['url' => $url, 'format' => $format, 'text' => null];
|
||||
$hook_data = [
|
||||
'url' => $url,
|
||||
'format' => $format,
|
||||
'text' => null,
|
||||
];
|
||||
|
||||
Hook::callAll('parse_link', $arr);
|
||||
$hook_data = $this->eventDispatcher->dispatch(
|
||||
new ArrayFilterEvent(ArrayFilterEvent::PARSE_LINK, $hook_data),
|
||||
)->getArray();
|
||||
|
||||
if ($arr['text']) {
|
||||
if ($hook_data['text']) {
|
||||
if ($format == 'json') {
|
||||
$this->jsonExit($arr['text']);
|
||||
$this->jsonExit($hook_data['text']);
|
||||
} else {
|
||||
$this->httpExit($arr['text']);
|
||||
$this->httpExit($hook_data['text']);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ class HookEventBridgeTest extends TestCase
|
|||
ArrayFilterEvent::PREPARE_POST_END => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::PARSE_LINK => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::FETCH_ITEM_BY_LINK => 'onArrayFilterEvent',
|
||||
ArrayFilterEvent::ITEM_TAGGED => 'onArrayFilterEvent',
|
||||
|
@ -460,6 +461,7 @@ class HookEventBridgeTest extends TestCase
|
|||
[ArrayFilterEvent::PREPARE_POST_END, 'prepare_body_final'],
|
||||
[ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'photo_upload_form'],
|
||||
[ArrayFilterEvent::NETWORK_TO_NAME, 'network_to_name'],
|
||||
[ArrayFilterEvent::PARSE_LINK, 'parse_link'],
|
||||
[ArrayFilterEvent::CONVERSATION_START, 'conversation_start'],
|
||||
[ArrayFilterEvent::FETCH_ITEM_BY_LINK, 'item_by_link'],
|
||||
[ArrayFilterEvent::ITEM_TAGGED, 'tagged'],
|
||||
|
|
|
@ -40,6 +40,7 @@ class ArrayFilterEventTest extends TestCase
|
|||
[ArrayFilterEvent::PREPARE_POST_END, 'friendica.data.prepare_post_end'],
|
||||
[ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'friendica.data.photo_upload_form'],
|
||||
[ArrayFilterEvent::NETWORK_TO_NAME, 'friendica.data.network_to_name'],
|
||||
[ArrayFilterEvent::PARSE_LINK, 'friendica.data.parse_link'],
|
||||
[ArrayFilterEvent::CONVERSATION_START, 'friendica.data.conversation_start'],
|
||||
[ArrayFilterEvent::FETCH_ITEM_BY_LINK, 'friendica.data.fetch_item_by_link'],
|
||||
[ArrayFilterEvent::ITEM_TAGGED, 'friendica.data.item_tagged'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue