mirror of
https://github.com/friendica/friendica
synced 2025-03-03 20:28:26 +00:00
Merge pull request #14799 from Art4/replace-hooks-with-eventdispatcher
Replace Hooks with EventDispatcher Part 2
This commit is contained in:
commit
afcc5a9205
34 changed files with 1044 additions and 446 deletions
|
@ -661,7 +661,7 @@ Called when a custom storage is used (e.g. webdav_storage)
|
||||||
|
|
||||||
Hook data:
|
Hook data:
|
||||||
- **name** (input): the name of the used storage backend
|
- **name** (input): the name of the used storage backend
|
||||||
- **data['storage']** (output): the storage instance to use (**must** implement `\Friendica\Core\Storage\IWritableStorage`)
|
- **data['storage']** (output): the storage instance to use (**must** implement `\Friendica\Core\Storage\IWritableStorage`)
|
||||||
|
|
||||||
### storage_config
|
### storage_config
|
||||||
|
|
||||||
|
@ -876,7 +876,7 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep-
|
||||||
|
|
||||||
### src/Content/ContactBlock.php
|
### src/Content/ContactBlock.php
|
||||||
|
|
||||||
Hook::callAll('contact_block_end', $arr);
|
Hook::callAll('contact_block_end', $text);
|
||||||
|
|
||||||
### src/Content/Text/BBCode.php
|
### src/Content/Text/BBCode.php
|
||||||
|
|
||||||
|
|
|
@ -359,10 +359,10 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap
|
||||||
|
|
||||||
Hook::callAll('register_account', $uid);
|
Hook::callAll('register_account', $uid);
|
||||||
Hook::callAll('remove_user', $user);
|
Hook::callAll('remove_user', $user);
|
||||||
|
|
||||||
### src/Content/ContactBlock.php
|
### src/Content/ContactBlock.php
|
||||||
|
|
||||||
Hook::callAll('contact_block_end', $arr);
|
Hook::callAll('contact_block_end', $text);
|
||||||
|
|
||||||
### src/Content/Text/BBCode.php
|
### src/Content/Text/BBCode.php
|
||||||
|
|
||||||
|
|
14
mod/item.php
14
mod/item.php
|
@ -18,12 +18,12 @@
|
||||||
|
|
||||||
use Friendica\Content\Conversation;
|
use Friendica\Content\Conversation;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\ItemURI;
|
use Friendica\Model\ItemURI;
|
||||||
|
@ -43,7 +43,11 @@ function item_post()
|
||||||
item_drop($uid, $_REQUEST['dropitems']);
|
item_drop($uid, $_REQUEST['dropitems']);
|
||||||
}
|
}
|
||||||
|
|
||||||
Hook::callAll('post_local_start', $_REQUEST);
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
$_REQUEST = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL_START, $_REQUEST)
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
$return_path = $_REQUEST['return'] ?? '';
|
$return_path = $_REQUEST['return'] ?? '';
|
||||||
$preview = intval($_REQUEST['preview'] ?? 0);
|
$preview = intval($_REQUEST['preview'] ?? 0);
|
||||||
|
@ -275,7 +279,11 @@ function item_process(array $post, array $request, bool $preview, string $return
|
||||||
System::jsonExit(['preview' => $o]);
|
System::jsonExit(['preview' => $o]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Hook::callAll('post_local', $post);
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
$post = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL, $post)
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
unset($post['edit']);
|
unset($post['edit']);
|
||||||
unset($post['self']);
|
unset($post['self']);
|
||||||
|
|
|
@ -11,12 +11,12 @@ use Friendica\Content\Nav;
|
||||||
use Friendica\Content\Pager;
|
use Friendica\Content\Pager;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Core\ACL;
|
use Friendica\Core\ACL;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\Database\DBStructure;
|
use Friendica\Database\DBStructure;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\Photo;
|
use Friendica\Model\Photo;
|
||||||
|
@ -647,7 +647,11 @@ function photos_content()
|
||||||
'default_upload' => true
|
'default_upload' => true
|
||||||
];
|
];
|
||||||
|
|
||||||
Hook::callAll('photo_upload_form', $ret);
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
$eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::PHOTO_UPLOAD_FORM, $ret)
|
||||||
|
);
|
||||||
|
|
||||||
$default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
|
$default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
|
||||||
$default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
|
$default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
|
||||||
|
|
|
@ -19,6 +19,7 @@ use Friendica\Core\Hook;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Lock\Capability\ICanLock;
|
use Friendica\Core\Lock\Capability\ICanLock;
|
||||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
|
use Friendica\Event\CollectRoutesEvent;
|
||||||
use Friendica\LegacyModule;
|
use Friendica\LegacyModule;
|
||||||
use Friendica\Module\HTTPException\MethodNotAllowed;
|
use Friendica\Module\HTTPException\MethodNotAllowed;
|
||||||
use Friendica\Module\HTTPException\PageNotFound;
|
use Friendica\Module\HTTPException\PageNotFound;
|
||||||
|
@ -28,6 +29,7 @@ use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Network\HTTPException\MethodNotAllowedException;
|
use Friendica\Network\HTTPException\MethodNotAllowedException;
|
||||||
use Friendica\Network\HTTPException\NotFoundException;
|
use Friendica\Network\HTTPException\NotFoundException;
|
||||||
use Friendica\Util\Router\FriendicaGroupCountBased;
|
use Friendica\Util\Router\FriendicaGroupCountBased;
|
||||||
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,6 +86,8 @@ class Router
|
||||||
/** @var LoggerInterface */
|
/** @var LoggerInterface */
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
|
private EventDispatcherInterface $eventDispatcher;
|
||||||
|
|
||||||
private AddonHelper $addonHelper;
|
private AddonHelper $addonHelper;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
|
@ -110,7 +114,7 @@ class Router
|
||||||
* @param IHandleUserSessions $userSession
|
* @param IHandleUserSessions $userSession
|
||||||
* @param RouteCollector|null $routeCollector
|
* @param RouteCollector|null $routeCollector
|
||||||
*/
|
*/
|
||||||
public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, IManageConfigValues $config, Arguments $args, LoggerInterface $logger, AddonHelper $addonHelper, IHandleUserSessions $userSession, RouteCollector $routeCollector = null)
|
public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, IManageConfigValues $config, Arguments $args, LoggerInterface $logger, EventDispatcherInterface $eventDispatcher, AddonHelper $addonHelper, IHandleUserSessions $userSession, RouteCollector $routeCollector = null)
|
||||||
{
|
{
|
||||||
$this->baseRoutesFilepath = $baseRoutesFilepath;
|
$this->baseRoutesFilepath = $baseRoutesFilepath;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
|
@ -120,6 +124,7 @@ class Router
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->server = $server;
|
$this->server = $server;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
$this->addonHelper = $addonHelper;
|
$this->addonHelper = $addonHelper;
|
||||||
$this->isLocalUser = !empty($userSession->getLocalUserId());
|
$this->isLocalUser = !empty($userSession->getLocalUserId());
|
||||||
|
|
||||||
|
@ -148,10 +153,12 @@ class Router
|
||||||
|
|
||||||
$this->addRoutes($routeCollector, $routes);
|
$this->addRoutes($routeCollector, $routes);
|
||||||
|
|
||||||
$this->routeCollector = $routeCollector;
|
|
||||||
|
|
||||||
// Add routes from addons
|
// Add routes from addons
|
||||||
Hook::callAll('route_collection', $this->routeCollector);
|
$routeCollector = $this->eventDispatcher->dispatch(
|
||||||
|
new CollectRoutesEvent(CollectRoutesEvent::COLLECT_ROUTES, $routeCollector),
|
||||||
|
)->getRouteCollector();
|
||||||
|
|
||||||
|
$this->routeCollector = $routeCollector;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
|
|
||||||
namespace Friendica\Content;
|
namespace Friendica\Content;
|
||||||
|
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,8 +24,8 @@ class ContactSelector
|
||||||
const SVG_COLOR_WHITE = 2;
|
const SVG_COLOR_WHITE = 2;
|
||||||
const SVG_WHITE = 3;
|
const SVG_WHITE = 3;
|
||||||
|
|
||||||
static $serverdata = [];
|
public static $serverdata = [];
|
||||||
static $server_id = [];
|
public static $server_id = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $current current
|
* @param string $current current
|
||||||
|
@ -35,7 +35,7 @@ class ContactSelector
|
||||||
public static function pollInterval(string $current, bool $disabled = false): string
|
public static function pollInterval(string $current, bool $disabled = false): string
|
||||||
{
|
{
|
||||||
$dis = (($disabled) ? ' disabled="disabled" ' : '');
|
$dis = (($disabled) ? ' disabled="disabled" ' : '');
|
||||||
$o = '';
|
$o = '';
|
||||||
$o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
|
$o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
|
||||||
|
|
||||||
$rep = [
|
$rep = [
|
||||||
|
@ -113,29 +113,33 @@ class ContactSelector
|
||||||
*/
|
*/
|
||||||
public static function networkToName(string $network, string $protocol = '', int $gsid = null): string
|
public static function networkToName(string $network, string $protocol = '', int $gsid = null): string
|
||||||
{
|
{
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
$nets = [
|
$nets = [
|
||||||
Protocol::DFRN => DI::l10n()->t('DFRN'),
|
Protocol::DFRN => DI::l10n()->t('DFRN'),
|
||||||
Protocol::OSTATUS => DI::l10n()->t('OStatus'),
|
Protocol::OSTATUS => DI::l10n()->t('OStatus'),
|
||||||
Protocol::FEED => DI::l10n()->t('RSS/Atom'),
|
Protocol::FEED => DI::l10n()->t('RSS/Atom'),
|
||||||
Protocol::MAIL => DI::l10n()->t('Email'),
|
Protocol::MAIL => DI::l10n()->t('Email'),
|
||||||
Protocol::DIASPORA => DI::l10n()->t('Diaspora'),
|
Protocol::DIASPORA => DI::l10n()->t('Diaspora'),
|
||||||
Protocol::ZOT => DI::l10n()->t('Zot!'),
|
Protocol::ZOT => DI::l10n()->t('Zot!'),
|
||||||
Protocol::LINKEDIN => DI::l10n()->t('LinkedIn'),
|
Protocol::LINKEDIN => DI::l10n()->t('LinkedIn'),
|
||||||
Protocol::XMPP => DI::l10n()->t('XMPP/IM'),
|
Protocol::XMPP => DI::l10n()->t('XMPP/IM'),
|
||||||
Protocol::MYSPACE => DI::l10n()->t('MySpace'),
|
Protocol::MYSPACE => DI::l10n()->t('MySpace'),
|
||||||
Protocol::GPLUS => DI::l10n()->t('Google+'),
|
Protocol::GPLUS => DI::l10n()->t('Google+'),
|
||||||
Protocol::PUMPIO => DI::l10n()->t('pump.io'),
|
Protocol::PUMPIO => DI::l10n()->t('pump.io'),
|
||||||
Protocol::TWITTER => DI::l10n()->t('Twitter'),
|
Protocol::TWITTER => DI::l10n()->t('Twitter'),
|
||||||
Protocol::DISCOURSE => DI::l10n()->t('Discourse'),
|
Protocol::DISCOURSE => DI::l10n()->t('Discourse'),
|
||||||
Protocol::DIASPORA2 => DI::l10n()->t('Diaspora Connector'),
|
Protocol::DIASPORA2 => DI::l10n()->t('Diaspora Connector'),
|
||||||
Protocol::STATUSNET => DI::l10n()->t('GNU Social Connector'),
|
Protocol::STATUSNET => DI::l10n()->t('GNU Social Connector'),
|
||||||
Protocol::ACTIVITYPUB => DI::l10n()->t('ActivityPub'),
|
Protocol::ACTIVITYPUB => DI::l10n()->t('ActivityPub'),
|
||||||
Protocol::PNUT => DI::l10n()->t('pnut'),
|
Protocol::PNUT => DI::l10n()->t('pnut'),
|
||||||
Protocol::TUMBLR => DI::l10n()->t('Tumblr'),
|
Protocol::TUMBLR => DI::l10n()->t('Tumblr'),
|
||||||
Protocol::BLUESKY => DI::l10n()->t('Bluesky'),
|
Protocol::BLUESKY => DI::l10n()->t('Bluesky'),
|
||||||
];
|
];
|
||||||
|
|
||||||
Hook::callAll('network_to_name', $nets);
|
$nets = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::NETWORK_TO_NAME, $nets),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
$search = array_keys($nets);
|
$search = array_keys($nets);
|
||||||
$replace = array_values($nets);
|
$replace = array_values($nets);
|
||||||
|
@ -212,7 +216,7 @@ class ContactSelector
|
||||||
$network_svg = str_replace($search, $replace, $network);
|
$network_svg = str_replace($search, $replace, $network);
|
||||||
|
|
||||||
if (in_array($network, Protocol::FEDERATED) && !empty($gsid)) {
|
if (in_array($network, Protocol::FEDERATED) && !empty($gsid)) {
|
||||||
$gserver = self::getServerForId($gsid);
|
$gserver = self::getServerForId($gsid);
|
||||||
$platform = $gserver['platform'];
|
$platform = $gserver['platform'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,7 +237,7 @@ class ContactSelector
|
||||||
'takahē', 'takesama', 'threads', 'tumblr', 'vernissage', 'vervis', 'vidzy', 'vocata', 'wafrn',
|
'takahē', 'takesama', 'threads', 'tumblr', 'vernissage', 'vervis', 'vidzy', 'vocata', 'wafrn',
|
||||||
'wildebeest', 'wordpress', 'write.as', 'writefreely', 'wxwclub', 'xwiki', 'zap'];
|
'wildebeest', 'wordpress', 'write.as', 'writefreely', 'wxwclub', 'xwiki', 'zap'];
|
||||||
|
|
||||||
if (in_array($platform_icon_style,[self::SVG_WHITE, self::SVG_COLOR_WHITE])) {
|
if (in_array($platform_icon_style, [self::SVG_WHITE, self::SVG_COLOR_WHITE])) {
|
||||||
$svg = ['activitypub', 'akkoma', 'andstatus', 'bluesky', 'bonfire', 'bookwyrm', 'bridgy_fed',
|
$svg = ['activitypub', 'akkoma', 'andstatus', 'bluesky', 'bonfire', 'bookwyrm', 'bridgy_fed',
|
||||||
'calckey', 'castopod', 'diaspora', 'discourse', 'dolphin', 'drupal', 'email', 'firefish',
|
'calckey', 'castopod', 'diaspora', 'discourse', 'dolphin', 'drupal', 'email', 'firefish',
|
||||||
'flipboard', 'flohmarkt', 'forgejo', 'friendica', 'funkwhale', 'ghost', 'gitlab',
|
'flipboard', 'flohmarkt', 'forgejo', 'friendica', 'funkwhale', 'ghost', 'gitlab',
|
||||||
|
|
|
@ -11,11 +11,9 @@ use Friendica\App\Arguments;
|
||||||
use Friendica\App\BaseURL;
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\App\Mode;
|
use Friendica\App\Mode;
|
||||||
use Friendica\App\Page;
|
use Friendica\App\Page;
|
||||||
use Friendica\AppHelper;
|
|
||||||
use Friendica\BaseModule;
|
use Friendica\BaseModule;
|
||||||
use Friendica\Core\ACL;
|
use Friendica\Core\ACL;
|
||||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
|
@ -23,6 +21,8 @@ use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
use Friendica\Core\Theme;
|
use Friendica\Core\Theme;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
|
use Friendica\Event\HtmlFilterEvent;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Item as ItemModel;
|
use Friendica\Model\Item as ItemModel;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
|
@ -42,6 +42,7 @@ use Friendica\Util\Profiler;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Util\Temporal;
|
use Friendica\Util\Temporal;
|
||||||
use ImagickException;
|
use ImagickException;
|
||||||
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Conversation
|
class Conversation
|
||||||
|
@ -75,8 +76,6 @@ class Conversation
|
||||||
private $baseURL;
|
private $baseURL;
|
||||||
/** @var IManageConfigValues */
|
/** @var IManageConfigValues */
|
||||||
private $config;
|
private $config;
|
||||||
/** @var AppHelper */
|
|
||||||
private $appHelper;
|
|
||||||
/** @var Page */
|
/** @var Page */
|
||||||
private $page;
|
private $page;
|
||||||
/** @var Mode */
|
/** @var Mode */
|
||||||
|
@ -85,23 +84,24 @@ class Conversation
|
||||||
private $session;
|
private $session;
|
||||||
/** @var UserGServerRepository */
|
/** @var UserGServerRepository */
|
||||||
private $userGServer;
|
private $userGServer;
|
||||||
|
private EventDispatcherInterface $eventDispatcher;
|
||||||
|
|
||||||
public function __construct(UserGServerRepository $userGServer, LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, Page $page, Mode $mode, AppHelper $appHelper, IHandleUserSessions $session)
|
public function __construct(UserGServerRepository $userGServer, LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, Page $page, Mode $mode, EventDispatcherInterface $eventDispatcher, IHandleUserSessions $session)
|
||||||
{
|
{
|
||||||
$this->activity = $activity;
|
$this->activity = $activity;
|
||||||
$this->item = $item;
|
$this->item = $item;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->mode = $mode;
|
$this->mode = $mode;
|
||||||
$this->baseURL = $baseURL;
|
$this->baseURL = $baseURL;
|
||||||
$this->profiler = $profiler;
|
$this->profiler = $profiler;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
$this->args = $args;
|
$this->args = $args;
|
||||||
$this->pConfig = $pConfig;
|
$this->pConfig = $pConfig;
|
||||||
$this->page = $page;
|
$this->page = $page;
|
||||||
$this->appHelper = $appHelper;
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
$this->userGServer = $userGServer;
|
$this->userGServer = $userGServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -332,8 +332,9 @@ class Conversation
|
||||||
'$is_mobile' => $this->mode->isMobile(),
|
'$is_mobile' => $this->mode->isMobile(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$jotplugins = '';
|
$jotplugins = $this->eventDispatcher->dispatch(
|
||||||
Hook::callAll('jot_tool', $jotplugins);
|
new HtmlFilterEvent(HtmlFilterEvent::JOT_TOOL, ''),
|
||||||
|
)->getHtml();
|
||||||
|
|
||||||
if ($this->config->get('system', 'set_creation_date')) {
|
if ($this->config->get('system', 'set_creation_date')) {
|
||||||
$created_at = Temporal::getDateTimeField(
|
$created_at = Temporal::getDateTimeField(
|
||||||
|
@ -563,7 +564,10 @@ class Conversation
|
||||||
}
|
}
|
||||||
|
|
||||||
$cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
|
$cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
|
||||||
Hook::callAll('conversation_start', $cb);
|
|
||||||
|
$cb = $this->eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::CONVERSATION_START, $cb),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
$items = $cb['items'];
|
$items = $cb['items'];
|
||||||
|
|
||||||
|
@ -654,10 +658,6 @@ class Conversation
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @todo Check if this call is needed or not
|
|
||||||
$arr = ['item' => $item];
|
|
||||||
Hook::callAll('display_item', $arr);
|
|
||||||
|
|
||||||
$item['pagedrop'] = $pagedrop;
|
$item['pagedrop'] = $pagedrop;
|
||||||
|
|
||||||
if ($item['gravity'] == ItemModel::GRAVITY_PARENT) {
|
if ($item['gravity'] == ItemModel::GRAVITY_PARENT) {
|
||||||
|
@ -1471,7 +1471,11 @@ class Conversation
|
||||||
}
|
}
|
||||||
|
|
||||||
$locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
|
$locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
|
||||||
Hook::callAll('render_location', $locate);
|
|
||||||
|
$locate = $this->eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::RENDER_LOCATION, $locate),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
$location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
|
$location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
|
||||||
|
|
||||||
$this->item->localize($item);
|
$this->item->localize($item);
|
||||||
|
@ -1567,7 +1571,10 @@ class Conversation
|
||||||
];
|
];
|
||||||
|
|
||||||
$arr = ['item' => $item, 'output' => $tmp_item];
|
$arr = ['item' => $item, 'output' => $tmp_item];
|
||||||
Hook::callAll('display_item', $arr);
|
|
||||||
|
$arr = $this->eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::DISPLAY_ITEM, $arr),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
$threads[] = [
|
$threads[] = [
|
||||||
'id' => $item['id'],
|
'id' => $item['id'],
|
||||||
|
|
|
@ -12,7 +12,6 @@ use Friendica\AppHelper;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Content\Text\BBCode\Video;
|
use Friendica\Content\Text\BBCode\Video;
|
||||||
use Friendica\Content\Text\HTML;
|
use Friendica\Content\Text\HTML;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
|
@ -20,6 +19,7 @@ use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Model\Attach;
|
use Friendica\Model\Attach;
|
||||||
use Friendica\Model\Circle;
|
use Friendica\Model\Circle;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
|
@ -43,6 +43,7 @@ use Friendica\Util\Proxy;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
use GuzzleHttp\Psr7\Uri;
|
use GuzzleHttp\Psr7\Uri;
|
||||||
use ImagickException;
|
use ImagickException;
|
||||||
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A content helper class for displaying items
|
* A content helper class for displaying items
|
||||||
|
@ -69,19 +70,21 @@ class Item
|
||||||
private $emailer;
|
private $emailer;
|
||||||
/** @var AppHelper */
|
/** @var AppHelper */
|
||||||
private $appHelper;
|
private $appHelper;
|
||||||
|
private EventDispatcherInterface $eventDispatcher;
|
||||||
|
|
||||||
public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession, Video $bbCodeVideo, ACLFormatter $aclFormatter, IManagePersonalConfigValues $pConfig, BaseURL $baseURL, Emailer $emailer, AppHelper $appHelper)
|
public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession, Video $bbCodeVideo, ACLFormatter $aclFormatter, IManagePersonalConfigValues $pConfig, BaseURL $baseURL, Emailer $emailer, AppHelper $appHelper, EventDispatcherInterface $eventDispatcher)
|
||||||
{
|
{
|
||||||
$this->profiler = $profiler;
|
$this->profiler = $profiler;
|
||||||
$this->activity = $activity;
|
$this->activity = $activity;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
$this->userSession = $userSession;
|
$this->userSession = $userSession;
|
||||||
$this->bbCodeVideo = $bbCodeVideo;
|
$this->bbCodeVideo = $bbCodeVideo;
|
||||||
$this->aclFormatter = $aclFormatter;
|
$this->aclFormatter = $aclFormatter;
|
||||||
$this->baseURL = $baseURL;
|
$this->baseURL = $baseURL;
|
||||||
$this->pConfig = $pConfig;
|
$this->pConfig = $pConfig;
|
||||||
$this->emailer = $emailer;
|
$this->emailer = $emailer;
|
||||||
$this->appHelper = $appHelper;
|
$this->appHelper = $appHelper;
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -445,7 +448,9 @@ class Item
|
||||||
|
|
||||||
$args = ['item' => $item, 'menu' => $menu];
|
$args = ['item' => $item, 'menu' => $menu];
|
||||||
|
|
||||||
Hook::callAll('item_photo_menu', $args);
|
$args = $this->eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::ITEM_PHOTO_MENU, $args),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
$menu = $args['menu'];
|
$menu = $args['menu'];
|
||||||
|
|
||||||
|
@ -1006,7 +1011,9 @@ class Item
|
||||||
Tag::createImplicitMentions($post['uri-id'], $post['thr-parent-id']);
|
Tag::createImplicitMentions($post['uri-id'], $post['thr-parent-id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
Hook::callAll('post_local_end', $post);
|
$post = $this->eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL_END, $post)
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
$author = DBA::selectFirst('contact', ['thumb'], ['uid' => $post['uid'], 'self' => true]);
|
$author = DBA::selectFirst('contact', ['thumb'], ['uid' => $post['uid'], 'self' => true]);
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,11 @@ use DOMXPath;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Core\Cache\Enum\Duration;
|
use Friendica\Core\Cache\Enum\Duration;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
|
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
|
||||||
|
@ -53,7 +53,7 @@ class OEmbed
|
||||||
|
|
||||||
$cache_key = 'oembed:' . $appHelper->getThemeInfoValue('videowidth') . ':' . $embedurl;
|
$cache_key = 'oembed:' . $appHelper->getThemeInfoValue('videowidth') . ':' . $embedurl;
|
||||||
|
|
||||||
$condition = ['url' => Strings::normaliseLink($embedurl), 'maxwidth' => $appHelper->getThemeInfoValue('videowidth')];
|
$condition = ['url' => Strings::normaliseLink($embedurl), 'maxwidth' => $appHelper->getThemeInfoValue('videowidth')];
|
||||||
$oembed_record = DBA::selectFirst('oembed', ['content'], $condition);
|
$oembed_record = DBA::selectFirst('oembed', ['content'], $condition);
|
||||||
if (DBA::isResult($oembed_record)) {
|
if (DBA::isResult($oembed_record)) {
|
||||||
$json_string = $oembed_record['content'];
|
$json_string = $oembed_record['content'];
|
||||||
|
@ -64,7 +64,7 @@ class OEmbed
|
||||||
// These media files should now be caught in bbcode.php
|
// These media files should now be caught in bbcode.php
|
||||||
// left here as a fallback in case this is called from another source
|
// left here as a fallback in case this is called from another source
|
||||||
$noexts = ['mp3', 'mp4', 'ogg', 'ogv', 'oga', 'ogm', 'webm'];
|
$noexts = ['mp3', 'mp4', 'ogg', 'ogv', 'oga', 'ogm', 'webm'];
|
||||||
$ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION);
|
$ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION);
|
||||||
|
|
||||||
$oembed = new \Friendica\Object\OEmbed($embedurl);
|
$oembed = new \Friendica\Object\OEmbed($embedurl);
|
||||||
|
|
||||||
|
@ -81,15 +81,17 @@ class OEmbed
|
||||||
if (@$dom->loadHTML($html_text)) {
|
if (@$dom->loadHTML($html_text)) {
|
||||||
$xpath = new DOMXPath($dom);
|
$xpath = new DOMXPath($dom);
|
||||||
foreach (
|
foreach (
|
||||||
$xpath->query("//link[@type='application/json+oembed'] | //link[@type='text/json+oembed']")
|
$xpath->query("//link[@type='application/json+oembed'] | //link[@type='text/json+oembed']") as $link
|
||||||
as $link)
|
) {
|
||||||
{
|
|
||||||
/** @var DOMElement $link */
|
/** @var DOMElement $link */
|
||||||
$href = $link->getAttributeNode('href')->nodeValue;
|
$href = $link->getAttributeNode('href')->nodeValue;
|
||||||
// Both Youtube and Vimeo output OEmbed endpoint URL with HTTP
|
// Both Youtube and Vimeo output OEmbed endpoint URL with HTTP
|
||||||
// but their OEmbed endpoint is only accessible by HTTPS ¯\_(ツ)_/¯
|
// but their OEmbed endpoint is only accessible by HTTPS ¯\_(ツ)_/¯
|
||||||
$href = str_replace(['http://www.youtube.com/', 'http://player.vimeo.com/'],
|
$href = str_replace(
|
||||||
['https://www.youtube.com/', 'https://player.vimeo.com/'], $href);
|
['http://www.youtube.com/', 'http://player.vimeo.com/'],
|
||||||
|
['https://www.youtube.com/', 'https://player.vimeo.com/'],
|
||||||
|
$href
|
||||||
|
);
|
||||||
$result = DI::httpClient()->get($href . '&maxwidth=' . $appHelper->getThemeInfoValue('videowidth'), HttpClientAccept::DEFAULT, [HttpClientOptions::REQUEST => HttpClientRequest::SITEINFO]);
|
$result = DI::httpClient()->get($href . '&maxwidth=' . $appHelper->getThemeInfoValue('videowidth'), HttpClientAccept::DEFAULT, [HttpClientOptions::REQUEST => HttpClientRequest::SITEINFO]);
|
||||||
if ($result->isSuccess()) {
|
if ($result->isSuccess()) {
|
||||||
$json_string = $result->getBodyString();
|
$json_string = $result->getBodyString();
|
||||||
|
@ -110,10 +112,10 @@ class OEmbed
|
||||||
|
|
||||||
if (!empty($oembed->type) && $oembed->type != 'error') {
|
if (!empty($oembed->type) && $oembed->type != 'error') {
|
||||||
DBA::insert('oembed', [
|
DBA::insert('oembed', [
|
||||||
'url' => Strings::normaliseLink($embedurl),
|
'url' => Strings::normaliseLink($embedurl),
|
||||||
'maxwidth' => $appHelper->getThemeInfoValue('videowidth'),
|
'maxwidth' => $appHelper->getThemeInfoValue('videowidth'),
|
||||||
'content' => $json_string,
|
'content' => $json_string,
|
||||||
'created' => DateTimeFormat::utcNow()
|
'created' => DateTimeFormat::utcNow()
|
||||||
], Database::INSERT_UPDATE);
|
], Database::INSERT_UPDATE);
|
||||||
$cache_ttl = Duration::DAY;
|
$cache_ttl = Duration::DAY;
|
||||||
} else {
|
} else {
|
||||||
|
@ -141,8 +143,8 @@ class OEmbed
|
||||||
|
|
||||||
if ($oembed->type == 'photo') {
|
if ($oembed->type == 'photo') {
|
||||||
if (!empty($data['images'])) {
|
if (!empty($data['images'])) {
|
||||||
$oembed->url = $data['images'][0]['src'];
|
$oembed->url = $data['images'][0]['src'];
|
||||||
$oembed->width = $data['images'][0]['width'];
|
$oembed->width = $data['images'][0]['width'];
|
||||||
$oembed->height = $data['images'][0]['height'];
|
$oembed->height = $data['images'][0]['height'];
|
||||||
} else {
|
} else {
|
||||||
$oembed->type = 'link';
|
$oembed->type = 'link';
|
||||||
|
@ -175,14 +177,20 @@ class OEmbed
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($data['images']) && ($oembed->type != 'photo')) {
|
if (!empty($data['images']) && ($oembed->type != 'photo')) {
|
||||||
$oembed->thumbnail_url = $data['images'][0]['src'];
|
$oembed->thumbnail_url = $data['images'][0]['src'];
|
||||||
$oembed->thumbnail_width = $data['images'][0]['width'];
|
$oembed->thumbnail_width = $data['images'][0]['width'];
|
||||||
$oembed->thumbnail_height = $data['images'][0]['height'];
|
$oembed->thumbnail_height = $data['images'][0]['height'];
|
||||||
}
|
}
|
||||||
|
|
||||||
Hook::callAll('oembed_fetch_url', $embedurl);
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
return $oembed;
|
$oembed_data = ['url' => $embedurl];
|
||||||
|
|
||||||
|
$oembed_data = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::OEMBED_FETCH_END, $oembed_data),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
|
return $oembed_data['url'] ?? $embedurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -204,15 +212,15 @@ class OEmbed
|
||||||
// make sure we don't attempt divide by zero, fallback is a 1:1 ratio
|
// make sure we don't attempt divide by zero, fallback is a 1:1 ratio
|
||||||
$tr = (($th) ? $tw / $th : 1);
|
$tr = (($th) ? $tw / $th : 1);
|
||||||
|
|
||||||
$th = 120;
|
$th = 120;
|
||||||
$tw = $th * $tr;
|
$tw = $th * $tr;
|
||||||
$tpl = Renderer::getMarkupTemplate('oembed_video.tpl');
|
$tpl = Renderer::getMarkupTemplate('oembed_video.tpl');
|
||||||
$ret .= Renderer::replaceMacros($tpl, [
|
$ret .= Renderer::replaceMacros($tpl, [
|
||||||
'$embedurl' => $oembed->embed_url,
|
'$embedurl' => $oembed->embed_url,
|
||||||
'$escapedhtml' => base64_encode($oembed->html),
|
'$escapedhtml' => base64_encode($oembed->html),
|
||||||
'$tw' => $tw,
|
'$tw' => $tw,
|
||||||
'$th' => $th,
|
'$th' => $th,
|
||||||
'$turl' => BBCode::proxyUrl($oembed->thumbnail_url, BBCode::INTERNAL, $uriid, Proxy::SIZE_SMALL),
|
'$turl' => BBCode::proxyUrl($oembed->thumbnail_url, BBCode::INTERNAL, $uriid, Proxy::SIZE_SMALL),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
$ret .= Proxy::proxifyHtml($oembed->html, $uriid);
|
$ret .= Proxy::proxifyHtml($oembed->html, $uriid);
|
||||||
|
@ -274,12 +282,11 @@ class OEmbed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (!strpos($oembed->html, $oembed->embed_url)) {
|
} elseif (!strpos($oembed->html, $oembed->embed_url)) {
|
||||||
// add <a> for html2bbcode conversion
|
// add <a> for html to bbcode conversion
|
||||||
$ret .= '<a href="' . $oembed->embed_url . '" rel="oembed">' . $oembed->title . '</a>';
|
$ret .= '<a href="' . $oembed->embed_url . '" rel="oembed">' . $oembed->title . '</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret .= '</div>';
|
$ret .= '</div>';
|
||||||
$test = Proxy::proxifyHtml($ret, $uriid);
|
|
||||||
|
|
||||||
return str_replace("\n", "", $ret);
|
return str_replace("\n", "", $ret);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@
|
||||||
|
|
||||||
namespace Friendica\Content;
|
namespace Friendica\Content;
|
||||||
|
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\ParseUrl;
|
use Friendica\Util\ParseUrl;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
@ -90,7 +90,11 @@ class PageInfo
|
||||||
*/
|
*/
|
||||||
public static function getFooterFromData(array $data, bool $no_photos = false): string
|
public static function getFooterFromData(array $data, bool $no_photos = false): string
|
||||||
{
|
{
|
||||||
Hook::callAll('page_info_data', $data);
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
$data = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::PAGE_INFO, $data),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
if (empty($data['type'])) {
|
if (empty($data['type'])) {
|
||||||
return '';
|
return '';
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
namespace Friendica\Content;
|
namespace Friendica\Content;
|
||||||
|
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -93,48 +93,53 @@ class Smilies
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$baseUrl = (string)DI::baseUrl();
|
$baseUrl = (string) DI::baseUrl();
|
||||||
|
|
||||||
$icons = [
|
$icons = [
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-heart.gif" alt="<3" title="<3" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-heart.gif" alt="<3" title="<3" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-brokenheart.gif" alt="</3" title="</3" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-brokenheart.gif" alt="</3" title="</3" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-brokenheart.gif" alt="<\\3" title="<\\3" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-brokenheart.gif" alt="<\\3" title="<\\3" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-smile.gif" alt=":-)" title=":-)" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-smile.gif" alt=":-)" title=":-)" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-wink.gif" alt=";-)" title=";-)" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-wink.gif" alt=";-)" title=";-)" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-frown.gif" alt=":-(" title=":-(" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-frown.gif" alt=":-(" title=":-(" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-tongue-out.gif" alt=":-P" title=":-P" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-tongue-out.gif" alt=":-P" title=":-P" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-tongue-out.gif" alt=":-p" title=":-P" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-tongue-out.gif" alt=":-p" title=":-P" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-kiss.gif" alt=":-\" title=":-\" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-kiss.gif" alt=":-x" title=":-x" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-kiss.gif" alt=":-x" title=":-x" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-kiss.gif" alt=":-X" title=":-X" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-kiss.gif" alt=":-X" title=":-X" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-laughing.gif" alt=":-D" title=":-D" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-laughing.gif" alt=":-D" title=":-D" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-surprised.gif" alt="8-|" title="8-|" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-surprised.gif" alt="8-|" title="8-|" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-surprised.gif" alt="8-O" title="8-O" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-surprised.gif" alt="8-O" title="8-O" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-surprised.gif" alt=":-O" title="8-O" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-surprised.gif" alt=":-O" title="8-O" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-thumbsup.gif" alt="\\o/" title="\\o/" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-thumbsup.gif" alt="\\o/" title="\\o/" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-Oo.gif" alt="o.O" title="o.O" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-Oo.gif" alt="o.O" title="o.O" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-Oo.gif" alt="O.o" title="O.o" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-Oo.gif" alt="O.o" title="O.o" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-Oo.gif" alt="o_O" title="o_O" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-Oo.gif" alt="o_O" title="o_O" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-Oo.gif" alt="O_o" title="O_o" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-Oo.gif" alt="O_o" title="O_o" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-cry.gif" alt=":\'(" title=":\'("/>',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-cry.gif" alt=":\'(" title=":\'("/>',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-foot-in-mouth.gif" alt=":-!" title=":-!" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-foot-in-mouth.gif" alt=":-!" title=":-!" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-undecided.gif" alt=":-/" title=":-/" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-undecided.gif" alt=":-/" title=":-/" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-embarrassed.gif" alt=":-[" title=":-[" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-embarrassed.gif" alt=":-[" title=":-[" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-cool.gif" alt="8-)" title="8-)" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-cool.gif" alt="8-)" title="8-)" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/beer_mug.gif" alt=":beer" title=":beer" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/beer_mug.gif" alt=":beer" title=":beer" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/beer_mug.gif" alt=":homebrew" title=":homebrew" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/beer_mug.gif" alt=":homebrew" title=":homebrew" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/coffee.gif" alt=":coffee" title=":coffee" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/coffee.gif" alt=":coffee" title=":coffee" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/smiley-facepalm.gif" alt=":facepalm" title=":facepalm" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/smiley-facepalm.gif" alt=":facepalm" title=":facepalm" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/like.gif" alt=":like" title=":like" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/like.gif" alt=":like" title=":like" />',
|
||||||
'<img class="smiley" src="' . $baseUrl . '/images/dislike.gif" alt=":dislike" title=":dislike" />',
|
'<img class="smiley" src="' . $baseUrl . '/images/dislike.gif" alt=":dislike" title=":dislike" />',
|
||||||
'<a href="https://friendi.ca">~friendica <img class="smiley" width="16" height="16" src="' . $baseUrl . '/images/friendica.svg" alt="~friendica" title="~friendica" /></a>',
|
'<a href="https://friendi.ca">~friendica <img class="smiley" width="16" height="16" src="' . $baseUrl . '/images/friendica.svg" alt="~friendica" title="~friendica" /></a>',
|
||||||
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . $baseUrl . '/images/rm-16.png" alt="red#" title="red#" />matrix</a>',
|
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . $baseUrl . '/images/rm-16.png" alt="red#" title="red#" />matrix</a>',
|
||||||
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . $baseUrl . '/images/rm-16.png" alt="red#matrix" title="red#matrix" />matrix</a>'
|
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . $baseUrl . '/images/rm-16.png" alt="red#matrix" title="red#matrix" />matrix</a>'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
$params = ['texts' => $texts, 'icons' => $icons];
|
$params = ['texts' => $texts, 'icons' => $icons];
|
||||||
Hook::callAll('smilie', $params);
|
|
||||||
|
$params = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::SMILEY_LIST, $params),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
return $params;
|
return $params;
|
||||||
}
|
}
|
||||||
|
@ -155,12 +160,12 @@ class Smilies
|
||||||
if (strpos($text, '[nosmile]') !== false || self::noSmilies()) {
|
if (strpos($text, '[nosmile]') !== false || self::noSmilies()) {
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
$smilies = self::getList();
|
$smilies = self::getList();
|
||||||
$normalized = [];
|
$normalized = [];
|
||||||
return self::performForEachWordMatch(
|
return self::performForEachWordMatch(
|
||||||
array_combine($smilies['texts'], $smilies['icons']),
|
array_combine($smilies['texts'], $smilies['icons']),
|
||||||
$text,
|
$text,
|
||||||
function (string $name, string $image) use($normalized, &$emojis) {
|
function (string $name, string $image) use ($normalized, &$emojis) {
|
||||||
if (array_key_exists($name, $normalized)) {
|
if (array_key_exists($name, $normalized)) {
|
||||||
return $normalized[$name];
|
return $normalized[$name];
|
||||||
}
|
}
|
||||||
|
@ -176,9 +181,9 @@ class Smilies
|
||||||
$norm = 'smiley' . count($normalized);
|
$norm = 'smiley' . count($normalized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$shortcode = ':' . $norm . ':';
|
$shortcode = ':' . $norm . ':';
|
||||||
$normalized[$name] = $shortcode;
|
$normalized[$name] = $shortcode;
|
||||||
$emojis[$norm] = $url;
|
$emojis[$norm] = $url;
|
||||||
return $shortcode;
|
return $shortcode;
|
||||||
} else {
|
} else {
|
||||||
$normalized[$name] = $image;
|
$normalized[$name] = $image;
|
||||||
|
@ -205,7 +210,7 @@ class Smilies
|
||||||
{
|
{
|
||||||
$ord1_bitset = 0;
|
$ord1_bitset = 0;
|
||||||
$ord2_bitset = 0;
|
$ord2_bitset = 0;
|
||||||
$prefixes = [];
|
$prefixes = [];
|
||||||
foreach ($words as $word => $_) {
|
foreach ($words as $word => $_) {
|
||||||
if (strlen($word) < 2) {
|
if (strlen($word) < 2) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -225,7 +230,7 @@ class Smilies
|
||||||
}
|
}
|
||||||
|
|
||||||
$slength = strlen($subject);
|
$slength = strlen($subject);
|
||||||
$result = '';
|
$result = '';
|
||||||
// $processed is used to delay string concatenation since appending a char every loop is inefficient.
|
// $processed is used to delay string concatenation since appending a char every loop is inefficient.
|
||||||
$processed = 0;
|
$processed = 0;
|
||||||
// Find possible starting points for smilies.
|
// Find possible starting points for smilies.
|
||||||
|
@ -311,7 +316,8 @@ class Smilies
|
||||||
return $s;
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function noSmilies(): bool {
|
private static function noSmilies(): bool
|
||||||
|
{
|
||||||
return (intval(DI::config()->get('system', 'no_smilies')) ||
|
return (intval(DI::config()->get('system', 'no_smilies')) ||
|
||||||
(DI::userSession()->getLocalUserId() &&
|
(DI::userSession()->getLocalUserId() &&
|
||||||
intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'no_smilies'))));
|
intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'no_smilies'))));
|
||||||
|
@ -339,7 +345,7 @@ class Smilies
|
||||||
|
|
||||||
if ($no_images) {
|
if ($no_images) {
|
||||||
$cleaned = ['texts' => [], 'icons' => []];
|
$cleaned = ['texts' => [], 'icons' => []];
|
||||||
$icons = $smilies['icons'];
|
$icons = $smilies['icons'];
|
||||||
foreach ($icons as $key => $icon) {
|
foreach ($icons as $key => $icon) {
|
||||||
if (!strstr($icon, '<img ')) {
|
if (!strstr($icon, '<img ')) {
|
||||||
$cleaned['texts'][] = $smilies['texts'][$key];
|
$cleaned['texts'][] = $smilies['texts'][$key];
|
||||||
|
|
|
@ -15,10 +15,10 @@ use Friendica\Content\Item;
|
||||||
use Friendica\Content\OEmbed;
|
use Friendica\Content\OEmbed;
|
||||||
use Friendica\Content\PageInfo;
|
use Friendica\Content\PageInfo;
|
||||||
use Friendica\Content\Smilies;
|
use Friendica\Content\Smilies;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Event;
|
use Friendica\Model\Event;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
|
@ -1297,7 +1297,15 @@ class BBCode
|
||||||
|
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
|
|
||||||
Hook::callAll('bbcode', $text);
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
$text_data = ['bbcode2html' => $text];
|
||||||
|
|
||||||
|
$text_data = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::BBCODE_TO_HTML_START, $text_data),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
|
$text = $text_data['bbcode2html'] ?? $text;
|
||||||
|
|
||||||
$ev = Event::fromBBCode($text);
|
$ev = Event::fromBBCode($text);
|
||||||
|
|
||||||
|
@ -2375,9 +2383,18 @@ class BBCode
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Hook::callAll('bb2diaspora', $text);
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
$text_data = ['bbcode2markdown' => $text];
|
||||||
|
|
||||||
|
$text_data = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::BBCODE_TO_MARKDOWN_END, $text_data),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
|
$text = $text_data['bbcode2markdown'] ?? $text;
|
||||||
|
|
||||||
DI::profiler()->stopRecording();
|
DI::profiler()->stopRecording();
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,10 @@ namespace Friendica\Content\Text;
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
use DOMXPath;
|
use DOMXPath;
|
||||||
use Friendica\Protocol\HTTP\MediaType;
|
use Friendica\Protocol\HTTP\MediaType;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Search;
|
use Friendica\Core\Search;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Util\Strings;
|
use Friendica\Util\Strings;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
@ -51,7 +51,7 @@ class HTML
|
||||||
private static function tagToBBCodeSub(DOMDocument $doc, string $tag, array $attributes, string $startbb, string $endbb, bool $ignoreChildren = false): bool
|
private static function tagToBBCodeSub(DOMDocument $doc, string $tag, array $attributes, string $startbb, string $endbb, bool $ignoreChildren = false): bool
|
||||||
{
|
{
|
||||||
$savestart = str_replace('$', '\x01', $startbb);
|
$savestart = str_replace('$', '\x01', $startbb);
|
||||||
$replace = false;
|
$replace = false;
|
||||||
|
|
||||||
$xpath = new DOMXPath($doc);
|
$xpath = new DOMXPath($doc);
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class HTML
|
||||||
|
|
||||||
if ($replace) {
|
if ($replace) {
|
||||||
$StartCode = $doc->createTextNode($startbb);
|
$StartCode = $doc->createTextNode($startbb);
|
||||||
$EndCode = $doc->createTextNode($endbb);
|
$EndCode = $doc->createTextNode($endbb);
|
||||||
|
|
||||||
$node->parentNode->insertBefore($StartCode, $node);
|
$node->parentNode->insertBefore($StartCode, $node);
|
||||||
|
|
||||||
|
@ -141,7 +141,9 @@ class HTML
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$message = str_replace("\r", "", $message);
|
$message = str_replace("\r", "", $message);
|
||||||
|
|
||||||
$message = Strings::performWithEscapedBlocks($message, '#<pre><code.*</code></pre>#iUs', function ($message) {
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
$message = Strings::performWithEscapedBlocks($message, '#<pre><code.*</code></pre>#iUs', function ($message) use ($eventDispatcher) {
|
||||||
$message = str_replace(
|
$message = str_replace(
|
||||||
[
|
[
|
||||||
"<li><p>",
|
"<li><p>",
|
||||||
|
@ -158,7 +160,7 @@ class HTML
|
||||||
$message = preg_replace('=<(\w+):(.+?)>=', '<removeme>', $message);
|
$message = preg_replace('=<(\w+):(.+?)>=', '<removeme>', $message);
|
||||||
$message = preg_replace('=</(\w+):(.+?)>=', '</removeme>', $message);
|
$message = preg_replace('=</(\w+):(.+?)>=', '</removeme>', $message);
|
||||||
|
|
||||||
$doc = new DOMDocument();
|
$doc = new DOMDocument();
|
||||||
$doc->preserveWhiteSpace = false;
|
$doc->preserveWhiteSpace = false;
|
||||||
|
|
||||||
$message = mb_convert_encoding($message, 'HTML-ENTITIES', "UTF-8");
|
$message = mb_convert_encoding($message, 'HTML-ENTITIES', "UTF-8");
|
||||||
|
@ -177,10 +179,10 @@ class HTML
|
||||||
XML::deleteNode($doc, 'removeme');
|
XML::deleteNode($doc, 'removeme');
|
||||||
|
|
||||||
$xpath = new DomXPath($doc);
|
$xpath = new DomXPath($doc);
|
||||||
$list = $xpath->query("//pre");
|
$list = $xpath->query("//pre");
|
||||||
foreach ($list as $node) {
|
foreach ($list as $node) {
|
||||||
// Ensure to escape unescaped & - they will otherwise raise a warning
|
// Ensure to escape unescaped & - they will otherwise raise a warning
|
||||||
$safe_value = preg_replace('/&(?!\w+;)/', '&', $node->nodeValue);
|
$safe_value = preg_replace('/&(?!\w+;)/', '&', $node->nodeValue);
|
||||||
$node->nodeValue = str_replace("\n", "\r", $safe_value);
|
$node->nodeValue = str_replace("\n", "\r", $safe_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,7 +316,13 @@ class HTML
|
||||||
$message = preg_replace('=\r *\r=i', "\n", $message);
|
$message = preg_replace('=\r *\r=i', "\n", $message);
|
||||||
$message = str_replace("\r", "\n", $message);
|
$message = str_replace("\r", "\n", $message);
|
||||||
|
|
||||||
Hook::callAll('html2bbcode', $message);
|
$message_data = ['html2bbcode' => $message];
|
||||||
|
|
||||||
|
$message_data = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::HTML_TO_BBCODE_END, $message_data),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
|
$message = $message_data['html2bbcode'] ?? $message;
|
||||||
|
|
||||||
$message = strip_tags($message);
|
$message = strip_tags($message);
|
||||||
|
|
||||||
|
@ -328,12 +336,12 @@ class HTML
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$oldmessage = $message;
|
$oldmessage = $message;
|
||||||
$message = str_replace("\n \n", "\n\n", $message);
|
$message = str_replace("\n \n", "\n\n", $message);
|
||||||
} while ($oldmessage != $message);
|
} while ($oldmessage != $message);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$oldmessage = $message;
|
$oldmessage = $message;
|
||||||
$message = str_replace("\n\n\n", "\n\n", $message);
|
$message = str_replace("\n\n\n", "\n\n", $message);
|
||||||
} while ($oldmessage != $message);
|
} while ($oldmessage != $message);
|
||||||
|
|
||||||
$message = str_replace(
|
$message = str_replace(
|
||||||
|
@ -386,14 +394,14 @@ class HTML
|
||||||
unset($base['fragment']);
|
unset($base['fragment']);
|
||||||
|
|
||||||
$link = $matches[0];
|
$link = $matches[0];
|
||||||
$url = $matches[1];
|
$url = $matches[1];
|
||||||
|
|
||||||
if (empty($url) || empty(parse_url($url))) {
|
if (empty($url) || empty(parse_url($url))) {
|
||||||
return $matches[0];
|
return $matches[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
$parts = array_merge($base, parse_url($url));
|
$parts = array_merge($base, parse_url($url));
|
||||||
$url2 = (string)Uri::fromParts((array)$parts);
|
$url2 = (string)Uri::fromParts((array)$parts);
|
||||||
|
|
||||||
return str_replace($url, $url2, $link);
|
return str_replace($url, $url2, $link);
|
||||||
}
|
}
|
||||||
|
@ -461,7 +469,7 @@ class HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
$newlines[] = $newline . " ";
|
$newlines[] = $newline . " ";
|
||||||
$line = substr($line, $pos + 1);
|
$line = substr($line, $pos + 1);
|
||||||
}
|
}
|
||||||
} while ((strlen($line) > $wraplen) && !($oldline == $line));
|
} while ((strlen($line) > $wraplen) && !($oldline == $line));
|
||||||
|
|
||||||
|
@ -479,14 +487,14 @@ class HTML
|
||||||
$lines = explode("\n", $message);
|
$lines = explode("\n", $message);
|
||||||
|
|
||||||
$newlines = [];
|
$newlines = [];
|
||||||
$level = 0;
|
$level = 0;
|
||||||
foreach ($lines as $line) {
|
foreach ($lines as $line) {
|
||||||
$line = trim($line);
|
$line = trim($line);
|
||||||
$startquote = false;
|
$startquote = false;
|
||||||
while (strpos("*" . $line, '[quote]') > 0) {
|
while (strpos("*" . $line, '[quote]') > 0) {
|
||||||
$level++;
|
$level++;
|
||||||
$pos = strpos($line, '[quote]');
|
$pos = strpos($line, '[quote]');
|
||||||
$line = substr($line, 0, $pos) . substr($line, $pos + 7);
|
$line = substr($line, 0, $pos) . substr($line, $pos + 7);
|
||||||
$startquote = true;
|
$startquote = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,7 +506,7 @@ class HTML
|
||||||
$level = 0;
|
$level = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pos = strpos($line, '[/quote]');
|
$pos = strpos($line, '[/quote]');
|
||||||
$line = substr($line, 0, $pos) . substr($line, $pos + 8);
|
$line = substr($line, 0, $pos) . substr($line, $pos + 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -563,7 +571,7 @@ class HTML
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$message = str_replace("\r", "", $html);
|
$message = str_replace("\r", "", $html);
|
||||||
|
|
||||||
$doc = new DOMDocument();
|
$doc = new DOMDocument();
|
||||||
$doc->preserveWhiteSpace = false;
|
$doc->preserveWhiteSpace = false;
|
||||||
|
|
||||||
$message = mb_convert_encoding($message, 'HTML-ENTITIES', "UTF-8");
|
$message = mb_convert_encoding($message, 'HTML-ENTITIES', "UTF-8");
|
||||||
|
@ -662,7 +670,7 @@ class HTML
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$oldmessage = $message;
|
$oldmessage = $message;
|
||||||
$message = str_replace("\n\n\n", "\n\n", $message);
|
$message = str_replace("\n\n\n", "\n\n", $message);
|
||||||
} while ($oldmessage != $message);
|
} while ($oldmessage != $message);
|
||||||
|
|
||||||
$message = self::quoteLevel(trim($message), $wraplength);
|
$message = self::quoteLevel(trim($message), $wraplength);
|
||||||
|
@ -682,7 +690,7 @@ class HTML
|
||||||
{
|
{
|
||||||
DI::profiler()->startRecording('rendering');
|
DI::profiler()->startRecording('rendering');
|
||||||
$converter = new HtmlConverter(['hard_break' => true]);
|
$converter = new HtmlConverter(['hard_break' => true]);
|
||||||
$markdown = $converter->convert($html);
|
$markdown = $converter->convert($html);
|
||||||
|
|
||||||
DI::profiler()->stopRecording();
|
DI::profiler()->stopRecording();
|
||||||
return $markdown;
|
return $markdown;
|
||||||
|
@ -737,20 +745,20 @@ class HTML
|
||||||
// Replace links
|
// Replace links
|
||||||
$pattern = "/<a([^>]*) href=\"(?!http|https|\/)([^\"]*)\"/";
|
$pattern = "/<a([^>]*) href=\"(?!http|https|\/)([^\"]*)\"/";
|
||||||
$replace = "<a\${1} href=\"" . $base2 . "\${2}\"";
|
$replace = "<a\${1} href=\"" . $base2 . "\${2}\"";
|
||||||
$text = preg_replace($pattern, $replace, $text);
|
$text = preg_replace($pattern, $replace, $text);
|
||||||
|
|
||||||
$pattern = "/<a([^>]*) href=\"(?!http|https)([^\"]*)\"/";
|
$pattern = "/<a([^>]*) href=\"(?!http|https)([^\"]*)\"/";
|
||||||
$replace = "<a\${1} href=\"" . $base . "\${2}\"";
|
$replace = "<a\${1} href=\"" . $base . "\${2}\"";
|
||||||
$text = preg_replace($pattern, $replace, $text);
|
$text = preg_replace($pattern, $replace, $text);
|
||||||
|
|
||||||
// Replace images
|
// Replace images
|
||||||
$pattern = "/<img([^>]*) src=\"(?!http|https|\/)([^\"]*)\"/";
|
$pattern = "/<img([^>]*) src=\"(?!http|https|\/)([^\"]*)\"/";
|
||||||
$replace = "<img\${1} src=\"" . $base2 . "\${2}\"";
|
$replace = "<img\${1} src=\"" . $base2 . "\${2}\"";
|
||||||
$text = preg_replace($pattern, $replace, $text);
|
$text = preg_replace($pattern, $replace, $text);
|
||||||
|
|
||||||
$pattern = "/<img([^>]*) src=\"(?!http|https)([^\"]*)\"/";
|
$pattern = "/<img([^>]*) src=\"(?!http|https)([^\"]*)\"/";
|
||||||
$replace = "<img\${1} src=\"" . $base . "\${2}\"";
|
$replace = "<img\${1} src=\"" . $base . "\${2}\"";
|
||||||
$text = preg_replace($pattern, $replace, $text);
|
$text = preg_replace($pattern, $replace, $text);
|
||||||
|
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
|
@ -768,7 +776,7 @@ class HTML
|
||||||
$tpl = Renderer::getMarkupTemplate("scroll_loader.tpl");
|
$tpl = Renderer::getMarkupTemplate("scroll_loader.tpl");
|
||||||
return Renderer::replaceMacros($tpl, [
|
return Renderer::replaceMacros($tpl, [
|
||||||
'wait' => DI::l10n()->t('Loading more entries...'),
|
'wait' => DI::l10n()->t('Loading more entries...'),
|
||||||
'end' => DI::l10n()->t('The end')
|
'end' => DI::l10n()->t('The end')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -799,9 +807,9 @@ class HTML
|
||||||
$contact["addr"] = $contact["url"];
|
$contact["addr"] = $contact["url"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$url = $contact['url'];
|
$url = $contact['url'];
|
||||||
$sparkle = '';
|
$sparkle = '';
|
||||||
$redir = false;
|
$redir = false;
|
||||||
|
|
||||||
if ($redirect) {
|
if ($redirect) {
|
||||||
$url = Contact::magicLinkByContact($contact);
|
$url = Contact::magicLinkByContact($contact);
|
||||||
|
@ -816,14 +824,14 @@ class HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
return Renderer::replaceMacros(Renderer::getMarkupTemplate($textmode ? 'micropro_txt.tpl' : 'micropro_img.tpl'), [
|
return Renderer::replaceMacros(Renderer::getMarkupTemplate($textmode ? 'micropro_txt.tpl' : 'micropro_img.tpl'), [
|
||||||
'$click' => $contact['click'] ?? '',
|
'$click' => $contact['click'] ?? '',
|
||||||
'$class' => $class,
|
'$class' => $class,
|
||||||
'$url' => $url,
|
'$url' => $url,
|
||||||
'$photo' => Contact::getThumb($contact),
|
'$photo' => Contact::getThumb($contact),
|
||||||
'$name' => $contact['name'],
|
'$name' => $contact['name'],
|
||||||
'title' => $contact['name'] . ' [' . $contact['addr'] . ']',
|
'title' => $contact['name'] . ' [' . $contact['addr'] . ']',
|
||||||
'$parkle' => $sparkle,
|
'$parkle' => $sparkle,
|
||||||
'$redir' => $redir
|
'$redir' => $redir
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -885,7 +893,7 @@ class HTML
|
||||||
public static function applyContentFilter(string $html, array $reasons): string
|
public static function applyContentFilter(string $html, array $reasons): string
|
||||||
{
|
{
|
||||||
if (count($reasons)) {
|
if (count($reasons)) {
|
||||||
$tpl = Renderer::getMarkupTemplate('wall/content_filter.tpl');
|
$tpl = Renderer::getMarkupTemplate('wall/content_filter.tpl');
|
||||||
$html = Renderer::replaceMacros($tpl, [
|
$html = Renderer::replaceMacros($tpl, [
|
||||||
'$reasons' => $reasons,
|
'$reasons' => $reasons,
|
||||||
'$rnd' => Strings::getRandomHex(8),
|
'$rnd' => Strings::getRandomHex(8),
|
||||||
|
@ -943,8 +951,8 @@ class HTML
|
||||||
|
|
||||||
$config->set('Attr.AllowedRel', [
|
$config->set('Attr.AllowedRel', [
|
||||||
'noreferrer' => true,
|
'noreferrer' => true,
|
||||||
'noopener' => true,
|
'noopener' => true,
|
||||||
'tag' => true,
|
'tag' => true,
|
||||||
]);
|
]);
|
||||||
$config->set('Attr.AllowedFrameTargets', [
|
$config->set('Attr.AllowedFrameTargets', [
|
||||||
'_blank' => true,
|
'_blank' => true,
|
||||||
|
@ -1038,7 +1046,7 @@ class HTML
|
||||||
// This expression looks for a meta tag with the http-equiv attribute set to "content-type" ignoring case
|
// This expression looks for a meta tag with the http-equiv attribute set to "content-type" ignoring case
|
||||||
// whose content attribute contains a "charset" string and returns its value
|
// whose content attribute contains a "charset" string and returns its value
|
||||||
$expression = "string(//meta[@http-equiv][translate(@http-equiv, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'content-type'][contains(translate(@content, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'charset')]/@content)";
|
$expression = "string(//meta[@http-equiv][translate(@http-equiv, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'content-type'][contains(translate(@content, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'charset')]/@content)";
|
||||||
$mediaType = MediaType::fromContentType($xpath->evaluate($expression));
|
$mediaType = MediaType::fromContentType($xpath->evaluate($expression));
|
||||||
if (isset($mediaType->parameters['charset'])) {
|
if (isset($mediaType->parameters['charset'])) {
|
||||||
return strtolower($mediaType->parameters['charset']);
|
return strtolower($mediaType->parameters['charset']);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
namespace Friendica\Content\Widget;
|
namespace Friendica\Content\Widget;
|
||||||
|
|
||||||
use Friendica\Content\Text\HTML;
|
use Friendica\Content\Text\HTML;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\HtmlFilterEvent;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ class ContactBlock
|
||||||
/**
|
/**
|
||||||
* Get HTML for contact block
|
* Get HTML for contact block
|
||||||
*
|
*
|
||||||
* @hook contact_block_end (contacts=>array, output=>string)
|
|
||||||
* @return string Formatted HTML code or empty string
|
* @return string Formatted HTML code or empty string
|
||||||
*/
|
*/
|
||||||
public static function getHTML(array $profile, int $visitor_uid = null): string
|
public static function getHTML(array $profile, int $visitor_uid = null): string
|
||||||
|
@ -93,7 +92,7 @@ class ContactBlock
|
||||||
|
|
||||||
if (DBA::isResult($contacts_stmt)) {
|
if (DBA::isResult($contacts_stmt)) {
|
||||||
$contacts_title = DI::l10n()->tt('%d Contact', '%d Contacts', $total);
|
$contacts_title = DI::l10n()->tt('%d Contact', '%d Contacts', $total);
|
||||||
$micropro = [];
|
$micropro = [];
|
||||||
|
|
||||||
while ($contact = DBA::fetch($contacts_stmt)) {
|
while ($contact = DBA::fetch($contacts_stmt)) {
|
||||||
$contacts[] = $contact;
|
$contacts[] = $contact;
|
||||||
|
@ -106,16 +105,18 @@ class ContactBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('widget/contacts.tpl');
|
$tpl = Renderer::getMarkupTemplate('widget/contacts.tpl');
|
||||||
$o = Renderer::replaceMacros($tpl, [
|
$o = Renderer::replaceMacros($tpl, [
|
||||||
'$contacts' => $contacts_title,
|
'$contacts' => $contacts_title,
|
||||||
'$nickname' => $profile['nickname'],
|
'$nickname' => $profile['nickname'],
|
||||||
'$viewcontacts' => DI::l10n()->t('View Contacts'),
|
'$viewcontacts' => DI::l10n()->t('View Contacts'),
|
||||||
'$micropro' => $micropro,
|
'$micropro' => $micropro,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$arr = ['contacts' => $contacts, 'output' => $o];
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
Hook::callAll('contact_block_end', $arr);
|
$o = $eventDispatcher->dispatch(
|
||||||
|
new HtmlFilterEvent(HtmlFilterEvent::CONTACT_BLOCK_END, $o),
|
||||||
|
)->getHtml();
|
||||||
|
|
||||||
return $o;
|
return $o;
|
||||||
}
|
}
|
||||||
|
|
106
src/Core/ACL.php
106
src/Core/ACL.php
|
@ -11,6 +11,7 @@ use Exception;
|
||||||
use Friendica\App\Page;
|
use Friendica\App\Page;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Circle;
|
use Friendica\Model\Circle;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
|
@ -52,7 +53,7 @@ class ACL
|
||||||
$contacts = self::getValidMessageRecipientsForUser(DI::userSession()->getLocalUserId());
|
$contacts = self::getValidMessageRecipientsForUser(DI::userSession()->getLocalUserId());
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('acl/message_recipient.tpl');
|
$tpl = Renderer::getMarkupTemplate('acl/message_recipient.tpl');
|
||||||
$o = Renderer::replaceMacros($tpl, [
|
$o = Renderer::replaceMacros($tpl, [
|
||||||
'$contacts' => $contacts,
|
'$contacts' => $contacts,
|
||||||
'$contacts_json' => json_encode($contacts),
|
'$contacts_json' => json_encode($contacts),
|
||||||
'$selected' => $selected,
|
'$selected' => $selected,
|
||||||
|
@ -95,9 +96,9 @@ class ACL
|
||||||
$selfPublicContactId = Contact::getPublicIdByUserId($localUserId);
|
$selfPublicContactId = Contact::getPublicIdByUserId($localUserId);
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('acl/self_only.tpl');
|
$tpl = Renderer::getMarkupTemplate('acl/self_only.tpl');
|
||||||
$o = Renderer::replaceMacros($tpl, [
|
$o = Renderer::replaceMacros($tpl, [
|
||||||
'$selfPublicContactId' => $selfPublicContactId,
|
'$selfPublicContactId' => $selfPublicContactId,
|
||||||
'$explanation' => $explanation,
|
'$explanation' => $explanation,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $o;
|
return $o;
|
||||||
|
@ -117,8 +118,8 @@ class ACL
|
||||||
return [
|
return [
|
||||||
'allow_cid' => Contact::pruneUnavailable($aclFormatter->expand($user['allow_cid'] ?? '')),
|
'allow_cid' => Contact::pruneUnavailable($aclFormatter->expand($user['allow_cid'] ?? '')),
|
||||||
'allow_gid' => $aclFormatter->expand($user['allow_gid'] ?? ''),
|
'allow_gid' => $aclFormatter->expand($user['allow_gid'] ?? ''),
|
||||||
'deny_cid' => $aclFormatter->expand($user['deny_cid'] ?? ''),
|
'deny_cid' => $aclFormatter->expand($user['deny_cid'] ?? ''),
|
||||||
'deny_gid' => $aclFormatter->expand($user['deny_gid'] ?? ''),
|
'deny_gid' => $aclFormatter->expand($user['deny_gid'] ?? ''),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,31 +133,33 @@ class ACL
|
||||||
*/
|
*/
|
||||||
public static function getContactListByUserId(int $user_id, array $condition = [])
|
public static function getContactListByUserId(int $user_id, array $condition = [])
|
||||||
{
|
{
|
||||||
$fields = ['id', 'name', 'addr', 'micro'];
|
$fields = ['id', 'name', 'addr', 'micro'];
|
||||||
$params = ['order' => ['name']];
|
$params = ['order' => ['name']];
|
||||||
$acl_contacts = Contact::selectToArray(
|
$acl_contacts = Contact::selectToArray(
|
||||||
$fields,
|
$fields,
|
||||||
array_merge([
|
array_merge([
|
||||||
'uid' => $user_id,
|
'uid' => $user_id,
|
||||||
'self' => false,
|
'self' => false,
|
||||||
'blocked' => false,
|
'blocked' => false,
|
||||||
'archive' => false,
|
'archive' => false,
|
||||||
'deleted' => false,
|
'deleted' => false,
|
||||||
'pending' => false,
|
'pending' => false,
|
||||||
'network' => Protocol::FEDERATED,
|
'network' => Protocol::FEDERATED,
|
||||||
'rel' => [Contact::FOLLOWER, Contact::FRIEND]
|
'rel' => [Contact::FOLLOWER, Contact::FRIEND]
|
||||||
], $condition),
|
], $condition),
|
||||||
$params
|
$params
|
||||||
);
|
);
|
||||||
|
|
||||||
$acl_yourself = Contact::selectFirst($fields, ['uid' => $user_id, 'self' => true]);
|
$acl_yourself = Contact::selectFirst($fields, ['uid' => $user_id, 'self' => true]);
|
||||||
$acl_yourself['name'] = DI::l10n()->t('Yourself');
|
$acl_yourself['name'] = DI::l10n()->t('Yourself');
|
||||||
|
|
||||||
$acl_contacts[] = $acl_yourself;
|
$acl_contacts[] = $acl_yourself;
|
||||||
|
|
||||||
$acl_groups = Contact::selectToArray($fields,
|
$acl_groups = Contact::selectToArray(
|
||||||
['uid' => $user_id, 'self' => false, 'blocked' => false, 'archive' => false, 'deleted' => false,
|
$fields,
|
||||||
'network' => Protocol::FEDERATED, 'pending' => false, 'contact-type' => Contact::TYPE_COMMUNITY], $params
|
['uid' => $user_id, 'self' => false, 'blocked' => false, 'archive' => false, 'deleted' => false,
|
||||||
|
'network' => Protocol::FEDERATED, 'pending' => false, 'contact-type' => Contact::TYPE_COMMUNITY],
|
||||||
|
$params
|
||||||
);
|
);
|
||||||
|
|
||||||
$acl_contacts = array_merge($acl_groups, $acl_contacts);
|
$acl_contacts = array_merge($acl_groups, $acl_contacts);
|
||||||
|
@ -178,27 +181,27 @@ class ACL
|
||||||
{
|
{
|
||||||
$acl_circles = [
|
$acl_circles = [
|
||||||
[
|
[
|
||||||
'id' => Circle::FOLLOWERS,
|
'id' => Circle::FOLLOWERS,
|
||||||
'name' => DI::l10n()->t('Followers'),
|
'name' => DI::l10n()->t('Followers'),
|
||||||
'addr' => '',
|
'addr' => '',
|
||||||
'micro' => 'images/twopeople.png',
|
'micro' => 'images/twopeople.png',
|
||||||
'type' => 'circle',
|
'type' => 'circle',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'id' => Circle::MUTUALS,
|
'id' => Circle::MUTUALS,
|
||||||
'name' => DI::l10n()->t('Mutuals'),
|
'name' => DI::l10n()->t('Mutuals'),
|
||||||
'addr' => '',
|
'addr' => '',
|
||||||
'micro' => 'images/twopeople.png',
|
'micro' => 'images/twopeople.png',
|
||||||
'type' => 'circle',
|
'type' => 'circle',
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
foreach (Circle::getByUserId($user_id) as $circle) {
|
foreach (Circle::getByUserId($user_id) as $circle) {
|
||||||
$acl_circles[] = [
|
$acl_circles[] = [
|
||||||
'id' => $circle['id'],
|
'id' => $circle['id'],
|
||||||
'name' => $circle['name'],
|
'name' => $circle['name'],
|
||||||
'addr' => '',
|
'addr' => '',
|
||||||
'micro' => 'images/twopeople.png',
|
'micro' => 'images/twopeople.png',
|
||||||
'type' => 'circle',
|
'type' => 'circle',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +278,7 @@ class ACL
|
||||||
$mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', $user['uid']]);
|
$mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', $user['uid']]);
|
||||||
if (DBA::isResult($mailacct)) {
|
if (DBA::isResult($mailacct)) {
|
||||||
$jotnets_fields[] = [
|
$jotnets_fields[] = [
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'field' => [
|
'field' => [
|
||||||
'pubmail_enable',
|
'pubmail_enable',
|
||||||
DI::l10n()->t('Post to Email'),
|
DI::l10n()->t('Post to Email'),
|
||||||
|
@ -285,7 +288,12 @@ class ACL
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Hook::callAll('jot_networks', $jotnets_fields);
|
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
$jotnets_fields = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::JOT_NETWORKS, $jotnets_fields),
|
||||||
|
)->getArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
$acl_contacts = self::getContactListByUserId($user['uid'], $condition);
|
$acl_contacts = self::getContactListByUserId($user['uid'], $condition);
|
||||||
|
@ -304,28 +312,28 @@ class ACL
|
||||||
];
|
];
|
||||||
|
|
||||||
$tpl = Renderer::getMarkupTemplate('acl/full_selector.tpl');
|
$tpl = Renderer::getMarkupTemplate('acl/full_selector.tpl');
|
||||||
$o = Renderer::replaceMacros($tpl, [
|
$o = Renderer::replaceMacros($tpl, [
|
||||||
'$public_title' => DI::l10n()->t('Public'),
|
'$public_title' => DI::l10n()->t('Public'),
|
||||||
'$public_desc' => DI::l10n()->t('This content will be shown to all your followers and can be seen in the community pages and by anyone with its link.'),
|
'$public_desc' => DI::l10n()->t('This content will be shown to all your followers and can be seen in the community pages and by anyone with its link.'),
|
||||||
'$custom_title' => DI::l10n()->t('Limited/Private'),
|
'$custom_title' => DI::l10n()->t('Limited/Private'),
|
||||||
'$custom_desc' => DI::l10n()->t('This content will be shown only to the people in the first box, to the exception of the people mentioned in the second box. It won\'t appear anywhere public.') . DI::l10n()->t('Start typing the name of a contact or a circle to show a filtered list. You can also mention the special circles "Followers" and "Mutuals".'),
|
'$custom_desc' => DI::l10n()->t('This content will be shown only to the people in the first box, to the exception of the people mentioned in the second box. It won\'t appear anywhere public.') . DI::l10n()->t('Start typing the name of a contact or a circle to show a filtered list. You can also mention the special circles "Followers" and "Mutuals".'),
|
||||||
'$allow_label' => DI::l10n()->t('Show to:'),
|
'$allow_label' => DI::l10n()->t('Show to:'),
|
||||||
'$deny_label' => DI::l10n()->t('Except to:'),
|
'$deny_label' => DI::l10n()->t('Except to:'),
|
||||||
'$emailcc' => DI::l10n()->t('CC: email addresses'),
|
'$emailcc' => DI::l10n()->t('CC: email addresses'),
|
||||||
'$emtitle' => DI::l10n()->t('Example: bob@example.com, mary@example.com'),
|
'$emtitle' => DI::l10n()->t('Example: bob@example.com, mary@example.com'),
|
||||||
'$jotnets_summary' => DI::l10n()->t('Connectors'),
|
'$jotnets_summary' => DI::l10n()->t('Connectors'),
|
||||||
'$visibility' => $visibility,
|
'$visibility' => $visibility,
|
||||||
'$acl_contacts' => json_encode($acl_contacts),
|
'$acl_contacts' => json_encode($acl_contacts),
|
||||||
'$acl_circles' => json_encode($acl_circles),
|
'$acl_circles' => json_encode($acl_circles),
|
||||||
'$acl_list' => json_encode($acl_list),
|
'$acl_list' => json_encode($acl_list),
|
||||||
'$contact_allow' => implode(',', $default_permissions['allow_cid']),
|
'$contact_allow' => implode(',', $default_permissions['allow_cid']),
|
||||||
'$circle_allow' => implode(',', $default_permissions['allow_gid']),
|
'$circle_allow' => implode(',', $default_permissions['allow_gid']),
|
||||||
'$contact_deny' => implode(',', $default_permissions['deny_cid']),
|
'$contact_deny' => implode(',', $default_permissions['deny_cid']),
|
||||||
'$circle_deny' => implode(',', $default_permissions['deny_gid']),
|
'$circle_deny' => implode(',', $default_permissions['deny_gid']),
|
||||||
'$for_federation' => $for_federation,
|
'$for_federation' => $for_federation,
|
||||||
'$jotnets_fields' => $jotnets_fields,
|
'$jotnets_fields' => $jotnets_fields,
|
||||||
'$input_names' => $input_names,
|
'$input_names' => $input_names,
|
||||||
'$input_group_id' => $input_group_id,
|
'$input_group_id' => $input_group_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $o;
|
return $o;
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace Friendica\Core\Hooks;
|
||||||
|
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
use Friendica\Event\ArrayFilterEvent;
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
|
use Friendica\Event\CollectRoutesEvent;
|
||||||
use Friendica\Event\ConfigLoadedEvent;
|
use Friendica\Event\ConfigLoadedEvent;
|
||||||
use Friendica\Event\Event;
|
use Friendica\Event\Event;
|
||||||
use Friendica\Event\HtmlFilterEvent;
|
use Friendica\Event\HtmlFilterEvent;
|
||||||
|
@ -34,17 +35,40 @@ final class HookEventBridge
|
||||||
* This maps the new event names to the legacy Hook names.
|
* This maps the new event names to the legacy Hook names.
|
||||||
*/
|
*/
|
||||||
private static array $eventMapper = [
|
private static array $eventMapper = [
|
||||||
Event::INIT => 'init_1',
|
Event::INIT => 'init_1',
|
||||||
ConfigLoadedEvent::CONFIG_LOADED => 'load_config',
|
Event::HOME_INIT => 'home_init',
|
||||||
ArrayFilterEvent::APP_MENU => 'app_menu',
|
ConfigLoadedEvent::CONFIG_LOADED => 'load_config',
|
||||||
ArrayFilterEvent::NAV_INFO => 'nav_info',
|
CollectRoutesEvent::COLLECT_ROUTES => 'route_collection',
|
||||||
ArrayFilterEvent::FEATURE_ENABLED => 'isEnabled',
|
ArrayFilterEvent::APP_MENU => 'app_menu',
|
||||||
ArrayFilterEvent::FEATURE_GET => 'get',
|
ArrayFilterEvent::NAV_INFO => 'nav_info',
|
||||||
HtmlFilterEvent::HEAD => 'head',
|
ArrayFilterEvent::FEATURE_ENABLED => 'isEnabled',
|
||||||
HtmlFilterEvent::FOOTER => 'footer',
|
ArrayFilterEvent::FEATURE_GET => 'get',
|
||||||
HtmlFilterEvent::PAGE_HEADER => 'page_header',
|
ArrayFilterEvent::POST_LOCAL_START => 'post_local_start',
|
||||||
HtmlFilterEvent::PAGE_CONTENT_TOP => 'page_content_top',
|
ArrayFilterEvent::POST_LOCAL => 'post_local',
|
||||||
HtmlFilterEvent::PAGE_END => 'page_end',
|
ArrayFilterEvent::POST_LOCAL_END => 'post_local_end',
|
||||||
|
ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'photo_upload_form',
|
||||||
|
ArrayFilterEvent::NETWORK_TO_NAME => 'network_to_name',
|
||||||
|
ArrayFilterEvent::CONVERSATION_START => 'conversation_start',
|
||||||
|
ArrayFilterEvent::DISPLAY_ITEM => 'display_item',
|
||||||
|
ArrayFilterEvent::RENDER_LOCATION => 'render_location',
|
||||||
|
ArrayFilterEvent::ITEM_PHOTO_MENU => 'item_photo_menu',
|
||||||
|
ArrayFilterEvent::OEMBED_FETCH_END => 'oembed_fetch_url',
|
||||||
|
ArrayFilterEvent::PAGE_INFO => 'page_info_data',
|
||||||
|
ArrayFilterEvent::SMILEY_LIST => 'smilie',
|
||||||
|
ArrayFilterEvent::BBCODE_TO_HTML_START => 'bbcode',
|
||||||
|
ArrayFilterEvent::HTML_TO_BBCODE_END => 'html2bbcode',
|
||||||
|
ArrayFilterEvent::BBCODE_TO_MARKDOWN_END => 'bb2diaspora',
|
||||||
|
ArrayFilterEvent::JOT_NETWORKS => 'jot_networks',
|
||||||
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'support_follow',
|
||||||
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'support_revoke_follow',
|
||||||
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE => 'support_probe',
|
||||||
|
HtmlFilterEvent::HEAD => 'head',
|
||||||
|
HtmlFilterEvent::FOOTER => 'footer',
|
||||||
|
HtmlFilterEvent::PAGE_HEADER => 'page_header',
|
||||||
|
HtmlFilterEvent::PAGE_CONTENT_TOP => 'page_content_top',
|
||||||
|
HtmlFilterEvent::PAGE_END => 'page_end',
|
||||||
|
HtmlFilterEvent::JOT_TOOL => 'jot_tool',
|
||||||
|
HtmlFilterEvent::CONTACT_BLOCK_END => 'contact_block_end',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,17 +77,40 @@ final class HookEventBridge
|
||||||
public static function getStaticSubscribedEvents(): array
|
public static function getStaticSubscribedEvents(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Event::INIT => 'onNamedEvent',
|
Event::INIT => 'onNamedEvent',
|
||||||
ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
|
Event::HOME_INIT => 'onNamedEvent',
|
||||||
ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
|
ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
|
||||||
ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
|
CollectRoutesEvent::COLLECT_ROUTES => 'onCollectRoutesEvent',
|
||||||
ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
|
ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
|
||||||
ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
|
ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
|
||||||
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
|
ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
|
||||||
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
|
||||||
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
ArrayFilterEvent::POST_LOCAL_START => 'onArrayFilterEvent',
|
||||||
HtmlFilterEvent::PAGE_CONTENT_TOP => 'onHtmlFilterEvent',
|
ArrayFilterEvent::POST_LOCAL => 'onArrayFilterEvent',
|
||||||
HtmlFilterEvent::PAGE_END => 'onHtmlFilterEvent',
|
ArrayFilterEvent::POST_LOCAL_END => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::DISPLAY_ITEM => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::RENDER_LOCATION => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::ITEM_PHOTO_MENU => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::OEMBED_FETCH_END => 'onOembedFetchEndEvent',
|
||||||
|
ArrayFilterEvent::PAGE_INFO => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::SMILEY_LIST => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::BBCODE_TO_HTML_START => 'onBbcodeToHtmlEvent',
|
||||||
|
ArrayFilterEvent::HTML_TO_BBCODE_END => 'onHtmlToBbcodeEvent',
|
||||||
|
ArrayFilterEvent::BBCODE_TO_MARKDOWN_END => 'onBbcodeToMarkdownEvent',
|
||||||
|
ArrayFilterEvent::JOT_NETWORKS => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE => 'onArrayFilterEvent',
|
||||||
|
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::PAGE_CONTENT_TOP => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::PAGE_END => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::JOT_TOOL => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::CONTACT_BLOCK_END => 'onHtmlFilterEvent',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +124,69 @@ final class HookEventBridge
|
||||||
static::callHook($event->getName(), $event->getConfig());
|
static::callHook($event->getName(), $event->getConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function onCollectRoutesEvent(CollectRoutesEvent $event): void
|
||||||
|
{
|
||||||
|
$event->setRouteCollector(
|
||||||
|
static::callHook($event->getName(), $event->getRouteCollector())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map the OEMBED_FETCH_END event to `oembed_fetch_url` hook
|
||||||
|
*/
|
||||||
|
public static function onOembedFetchEndEvent(ArrayFilterEvent $event): void
|
||||||
|
{
|
||||||
|
$data = $event->getArray();
|
||||||
|
|
||||||
|
$url = (string) $data['url'] ?? '';
|
||||||
|
|
||||||
|
$data['url'] = static::callHook($event->getName(), $url);
|
||||||
|
|
||||||
|
$event->setArray($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map the BBCODE_TO_HTML_START event to `bbcode` hook
|
||||||
|
*/
|
||||||
|
public static function onBbcodeToHtmlEvent(ArrayFilterEvent $event): void
|
||||||
|
{
|
||||||
|
$data = $event->getArray();
|
||||||
|
|
||||||
|
$bbcode2html = (string) $data['bbcode2html'] ?? '';
|
||||||
|
|
||||||
|
$data['bbcode2html'] = static::callHook($event->getName(), $bbcode2html);
|
||||||
|
|
||||||
|
$event->setArray($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map the HTML_TO_BBCODE_END event to `html2bbcode` hook
|
||||||
|
*/
|
||||||
|
public static function onHtmlToBbcodeEvent(ArrayFilterEvent $event): void
|
||||||
|
{
|
||||||
|
$data = $event->getArray();
|
||||||
|
|
||||||
|
$html2bbcode = (string) $data['html2bbcode'] ?? '';
|
||||||
|
|
||||||
|
$data['html2bbcode'] = static::callHook($event->getName(), $html2bbcode);
|
||||||
|
|
||||||
|
$event->setArray($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map the BBCODE_TO_MARKDOWN_END event to `bb2diaspora` hook
|
||||||
|
*/
|
||||||
|
public static function onBbcodeToMarkdownEvent(ArrayFilterEvent $event): void
|
||||||
|
{
|
||||||
|
$data = $event->getArray();
|
||||||
|
|
||||||
|
$bbcode2markdown = (string) $data['bbcode2markdown'] ?? '';
|
||||||
|
|
||||||
|
$data['bbcode2markdown'] = static::callHook($event->getName(), $bbcode2markdown);
|
||||||
|
|
||||||
|
$event->setArray($data);
|
||||||
|
}
|
||||||
|
|
||||||
public static function onArrayFilterEvent(ArrayFilterEvent $event): void
|
public static function onArrayFilterEvent(ArrayFilterEvent $event): void
|
||||||
{
|
{
|
||||||
$event->setArray(
|
$event->setArray(
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace Friendica\Core;
|
||||||
|
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
|
@ -76,7 +77,12 @@ class Protocol
|
||||||
'protocol' => $protocol,
|
'protocol' => $protocol,
|
||||||
'result' => null
|
'result' => null
|
||||||
];
|
];
|
||||||
Hook::callAll('support_follow', $hook_data);
|
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
$hook_data = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, $hook_data),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
return $hook_data['result'] === true;
|
return $hook_data['result'] === true;
|
||||||
}
|
}
|
||||||
|
@ -98,7 +104,12 @@ class Protocol
|
||||||
'protocol' => $protocol,
|
'protocol' => $protocol,
|
||||||
'result' => null
|
'result' => null
|
||||||
];
|
];
|
||||||
Hook::callAll('support_revoke_follow', $hook_data);
|
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
$hook_data = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, $hook_data),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
return $hook_data['result'] === true;
|
return $hook_data['result'] === true;
|
||||||
}
|
}
|
||||||
|
@ -311,7 +322,12 @@ class Protocol
|
||||||
'protocol' => $protocol,
|
'protocol' => $protocol,
|
||||||
'result' => null
|
'result' => null
|
||||||
];
|
];
|
||||||
Hook::callAll('support_probe', $hook_data);
|
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
$hook_data = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, $hook_data),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
return $hook_data['result'] === true;
|
return $hook_data['result'] === true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,44 @@ final class ArrayFilterEvent extends Event
|
||||||
|
|
||||||
public const FEATURE_GET = 'friendica.data.feature_get';
|
public const FEATURE_GET = 'friendica.data.feature_get';
|
||||||
|
|
||||||
|
public const POST_LOCAL_START = 'friendica.data.post_local_start';
|
||||||
|
|
||||||
|
public const POST_LOCAL = 'friendica.data.post_local';
|
||||||
|
|
||||||
|
public const POST_LOCAL_END = 'friendica.data.post_local_end';
|
||||||
|
|
||||||
|
public const PHOTO_UPLOAD_FORM = 'friendica.data.photo_upload_form';
|
||||||
|
|
||||||
|
public const NETWORK_TO_NAME = 'friendica.data.network_to_name';
|
||||||
|
|
||||||
|
public const CONVERSATION_START = 'friendica.data.conversation_start';
|
||||||
|
|
||||||
|
public const DISPLAY_ITEM = 'friendica.data.display_item';
|
||||||
|
|
||||||
|
public const RENDER_LOCATION = 'friendica.data.render_location';
|
||||||
|
|
||||||
|
public const ITEM_PHOTO_MENU = 'friendica.data.item_photo_menu';
|
||||||
|
|
||||||
|
public const OEMBED_FETCH_END = 'friendica.data.oembed_fetch_end';
|
||||||
|
|
||||||
|
public const PAGE_INFO = 'friendica.data.page_info';
|
||||||
|
|
||||||
|
public const SMILEY_LIST = 'friendica.data.smiley_list';
|
||||||
|
|
||||||
|
public const BBCODE_TO_HTML_START = 'friendica.data.bbcode_to_html_start';
|
||||||
|
|
||||||
|
public const HTML_TO_BBCODE_END = 'friendica.data.html_to_bbcode_end';
|
||||||
|
|
||||||
|
public const BBCODE_TO_MARKDOWN_END = 'friendica.data.bbcode_to_markdown_end';
|
||||||
|
|
||||||
|
public const JOT_NETWORKS = 'friendica.data.jot_networks';
|
||||||
|
|
||||||
|
public const PROTOCOL_SUPPORTS_FOLLOW = 'friendica.data.protocol_supports_follow';
|
||||||
|
|
||||||
|
public const PROTOCOL_SUPPORTS_REVOKE_FOLLOW = 'friendica.data.protocol_supports_revoke_follow';
|
||||||
|
|
||||||
|
public const PROTOCOL_SUPPORTS_PROBE = 'friendica.data.protocol_supports_probe';
|
||||||
|
|
||||||
private array $array;
|
private array $array;
|
||||||
|
|
||||||
public function __construct(string $name, array $array)
|
public function __construct(string $name, array $array)
|
||||||
|
|
41
src/Event/CollectRoutesEvent.php
Normal file
41
src/Event/CollectRoutesEvent.php
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Copyright (C) 2010-2024, the Friendica project
|
||||||
|
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Friendica\Event;
|
||||||
|
|
||||||
|
use FastRoute\RouteCollector;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow addons to collect routes.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
final class CollectRoutesEvent extends Event
|
||||||
|
{
|
||||||
|
public const COLLECT_ROUTES = 'friendica.collect_routes';
|
||||||
|
|
||||||
|
private RouteCollector $routeCollector;
|
||||||
|
|
||||||
|
public function __construct(string $name, RouteCollector $routeCollector)
|
||||||
|
{
|
||||||
|
parent::__construct($name);
|
||||||
|
|
||||||
|
$this->routeCollector = $routeCollector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRouteCollector(): RouteCollector
|
||||||
|
{
|
||||||
|
return $this->routeCollector;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRouteCollector(RouteCollector $routeCollector): void
|
||||||
|
{
|
||||||
|
$this->routeCollector = $routeCollector;
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,8 @@ class Event implements NamedEvent
|
||||||
*/
|
*/
|
||||||
public const INIT = 'friendica.init';
|
public const INIT = 'friendica.init';
|
||||||
|
|
||||||
|
public const HOME_INIT = 'friendica.home_init';
|
||||||
|
|
||||||
private string $name;
|
private string $name;
|
||||||
|
|
||||||
public function __construct(string $name)
|
public function __construct(string $name)
|
||||||
|
|
|
@ -26,6 +26,10 @@ final class HtmlFilterEvent extends Event
|
||||||
|
|
||||||
public const PAGE_END = 'friendica.html.page_end';
|
public const PAGE_END = 'friendica.html.page_end';
|
||||||
|
|
||||||
|
public const JOT_TOOL = 'friendica.html.jot_tool';
|
||||||
|
|
||||||
|
public const CONTACT_BLOCK_END = 'friendica.html.contact_block_end';
|
||||||
|
|
||||||
private string $html;
|
private string $html;
|
||||||
|
|
||||||
public function __construct(string $name, string $html)
|
public function __construct(string $name, string $html)
|
||||||
|
|
|
@ -22,6 +22,7 @@ use Friendica\Core\System;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Model\Post\Category;
|
use Friendica\Model\Post\Category;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
|
||||||
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
|
||||||
|
@ -825,6 +826,8 @@ class Item
|
||||||
$item['private'] = self::PRIVATE;
|
$item['private'] = self::PRIVATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
if ($notify && $post_local) {
|
if ($notify && $post_local) {
|
||||||
$item['edit'] = false;
|
$item['edit'] = false;
|
||||||
$item['parent'] = $parent_id;
|
$item['parent'] = $parent_id;
|
||||||
|
@ -843,7 +846,9 @@ class Item
|
||||||
$dummy_session = false;
|
$dummy_session = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hook::callAll('post_local', $item);
|
$item = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL, $item)
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
if ($dummy_session) {
|
if ($dummy_session) {
|
||||||
unset($_SESSION['authenticated']);
|
unset($_SESSION['authenticated']);
|
||||||
|
@ -943,7 +948,9 @@ class Item
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($item['event-id'])) {
|
if (empty($item['event-id'])) {
|
||||||
unset($item['event-id']);
|
if (array_key_exists('event-id', $item)) {
|
||||||
|
unset($item['event-id']);
|
||||||
|
}
|
||||||
|
|
||||||
$ev = Event::fromBBCode($item['body']);
|
$ev = Event::fromBBCode($item['body']);
|
||||||
if ((!empty($ev['desc']) || !empty($ev['summary'])) && !empty($ev['start'])) {
|
if ((!empty($ev['desc']) || !empty($ev['summary'])) && !empty($ev['start'])) {
|
||||||
|
@ -2694,9 +2701,6 @@ class Item
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
* @hook 'post_local_end'
|
|
||||||
* array $arr
|
|
||||||
* 'post_id' => ID of posted item
|
|
||||||
*/
|
*/
|
||||||
public static function performActivity(int $item_id, string $verb, int $uid, string $allow_cid = null, string $allow_gid = null, string $deny_cid = null, string $deny_gid = null): bool
|
public static function performActivity(int $item_id, string $verb, int $uid, string $allow_cid = null, string $allow_gid = null, string $deny_cid = null, string $deny_gid = null): bool
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,6 +11,7 @@ use Friendica\BaseModule;
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\Event;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Module\Security\Login;
|
use Friendica\Module\Security\Login;
|
||||||
use Friendica\Protocol\ActivityPub;
|
use Friendica\Protocol\ActivityPub;
|
||||||
|
@ -32,13 +33,13 @@ class Home extends BaseModule
|
||||||
|
|
||||||
protected function content(array $request = []): string
|
protected function content(array $request = []): string
|
||||||
{
|
{
|
||||||
$basePath = DI::appHelper()->getBasePath();
|
$basePath = DI::appHelper()->getBasePath();
|
||||||
$config = DI::config();
|
$config = DI::config();
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
// currently no returned data is used
|
$eventDispatcher->dispatch(
|
||||||
$ret = [];
|
new Event(Event::HOME_INIT)
|
||||||
|
);
|
||||||
Hook::callAll('home_init', $ret);
|
|
||||||
|
|
||||||
if (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserNickname())) {
|
if (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserNickname())) {
|
||||||
DI::baseUrl()->redirect('network');
|
DI::baseUrl()->redirect('network');
|
||||||
|
@ -48,11 +49,11 @@ class Home extends BaseModule
|
||||||
DI::baseUrl()->redirect('/profile/' . $config->get('system', 'singleuser'));
|
DI::baseUrl()->redirect('/profile/' . $config->get('system', 'singleuser'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$customHome = '';
|
$customHome = '';
|
||||||
$defaultHeader = ($config->get('config', 'sitename') ? DI::l10n()->t('Welcome to %s', $config->get('config', 'sitename')) : '');
|
$defaultHeader = ($config->get('config', 'sitename') ? DI::l10n()->t('Welcome to %s', $config->get('config', 'sitename')) : '');
|
||||||
|
|
||||||
$homeFilePath = $basePath . '/home.html';
|
$homeFilePath = $basePath . '/home.html';
|
||||||
$cssFilePath = $basePath . '/home.css';
|
$cssFilePath = $basePath . '/home.css';
|
||||||
|
|
||||||
if (file_exists($homeFilePath)) {
|
if (file_exists($homeFilePath)) {
|
||||||
$customHome = $homeFilePath;
|
$customHome = $homeFilePath;
|
||||||
|
|
|
@ -16,13 +16,13 @@ use Friendica\BaseModule;
|
||||||
use Friendica\Content\Feature;
|
use Friendica\Content\Feature;
|
||||||
use Friendica\Core\ACL;
|
use Friendica\Core\ACL;
|
||||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Session\Model\UserSession;
|
use Friendica\Core\Session\Model\UserSession;
|
||||||
use Friendica\Core\Theme;
|
use Friendica\Core\Theme;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\Event\HtmlFilterEvent;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
|
@ -34,6 +34,7 @@ use Friendica\Util\ACLFormatter;
|
||||||
use Friendica\Util\Crypto;
|
use Friendica\Util\Crypto;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use Friendica\Util\Temporal;
|
use Friendica\Util\Temporal;
|
||||||
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class Compose extends BaseModule
|
class Compose extends BaseModule
|
||||||
|
@ -59,18 +60,20 @@ class Compose extends BaseModule
|
||||||
/** @var AppHelper */
|
/** @var AppHelper */
|
||||||
private $appHelper;
|
private $appHelper;
|
||||||
|
|
||||||
|
private EventDispatcherInterface $eventDispatcher;
|
||||||
|
|
||||||
public function __construct(AppHelper $appHelper, UserSession $session, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, Page $page, ACLFormatter $ACLFormatter, SystemMessages $systemMessages, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
public function __construct(EventDispatcherInterface $eventDispatcher, AppHelper $appHelper, UserSession $session, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, Page $page, ACLFormatter $ACLFormatter, SystemMessages $systemMessages, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||||
{
|
{
|
||||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||||
|
|
||||||
$this->systemMessages = $systemMessages;
|
$this->systemMessages = $systemMessages;
|
||||||
$this->ACLFormatter = $ACLFormatter;
|
$this->ACLFormatter = $ACLFormatter;
|
||||||
$this->page = $page;
|
$this->page = $page;
|
||||||
$this->pConfig = $pConfig;
|
$this->pConfig = $pConfig;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
$this->appHelper = $appHelper;
|
$this->appHelper = $appHelper;
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function post(array $request = [])
|
protected function post(array $request = [])
|
||||||
|
@ -115,29 +118,28 @@ class Compose extends BaseModule
|
||||||
|
|
||||||
switch ($posttype) {
|
switch ($posttype) {
|
||||||
case Item::PT_PERSONAL_NOTE:
|
case Item::PT_PERSONAL_NOTE:
|
||||||
$compose_title = $this->l10n->t('Compose new personal note');
|
$compose_title = $this->l10n->t('Compose new personal note');
|
||||||
$type = 'note';
|
$type = 'note';
|
||||||
$doesFederate = false;
|
$doesFederate = false;
|
||||||
$contact_allow_list = [$this->appHelper->getContactId()];
|
$contact_allow_list = [$this->appHelper->getContactId()];
|
||||||
$circle_allow_list = [];
|
$circle_allow_list = [];
|
||||||
$contact_deny_list = [];
|
$contact_deny_list = [];
|
||||||
$circle_deny_list = [];
|
$circle_deny_list = [];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$compose_title = $this->l10n->t('Compose new post');
|
$compose_title = $this->l10n->t('Compose new post');
|
||||||
$type = 'post';
|
$type = 'post';
|
||||||
$doesFederate = true;
|
$doesFederate = true;
|
||||||
|
|
||||||
$contact_allow = $_REQUEST['contact_allow'] ?? '';
|
$contact_allow = $_REQUEST['contact_allow'] ?? '';
|
||||||
$circle_allow = $_REQUEST['circle_allow'] ?? '';
|
$circle_allow = $_REQUEST['circle_allow'] ?? '';
|
||||||
$contact_deny = $_REQUEST['contact_deny'] ?? '';
|
$contact_deny = $_REQUEST['contact_deny'] ?? '';
|
||||||
$circle_deny = $_REQUEST['circle_deny'] ?? '';
|
$circle_deny = $_REQUEST['circle_deny'] ?? '';
|
||||||
|
|
||||||
if ($contact_allow
|
if ($contact_allow
|
||||||
. $circle_allow
|
. $circle_allow
|
||||||
. $contact_deny
|
. $contact_deny
|
||||||
. $circle_deny)
|
. $circle_deny) {
|
||||||
{
|
|
||||||
$contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
|
$contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
|
||||||
$circle_allow_list = $circle_allow ? explode(',', $circle_allow) : [];
|
$circle_allow_list = $circle_allow ? explode(',', $circle_allow) : [];
|
||||||
$contact_deny_list = $contact_deny ? explode(',', $contact_deny) : [];
|
$contact_deny_list = $contact_deny ? explode(',', $contact_deny) : [];
|
||||||
|
@ -147,14 +149,15 @@ class Compose extends BaseModule
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = $_REQUEST['title'] ?? '';
|
$title = $_REQUEST['title'] ?? '';
|
||||||
$category = $_REQUEST['category'] ?? '';
|
$category = $_REQUEST['category'] ?? '';
|
||||||
$body = $_REQUEST['body'] ?? '';
|
$body = $_REQUEST['body'] ?? '';
|
||||||
$location = $_REQUEST['location'] ?? $user['default-location'];
|
$location = $_REQUEST['location'] ?? $user['default-location'];
|
||||||
$wall = $_REQUEST['wall'] ?? $type == 'post';
|
$wall = $_REQUEST['wall'] ?? $type == 'post';
|
||||||
|
|
||||||
$jotplugins = '';
|
$jotplugins = $this->eventDispatcher->dispatch(
|
||||||
Hook::callAll('jot_tool', $jotplugins);
|
new HtmlFilterEvent(HtmlFilterEvent::JOT_TOOL, ''),
|
||||||
|
)->getHtml();
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
$this->page->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
|
$this->page->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
|
||||||
|
@ -202,8 +205,12 @@ class Compose extends BaseModule
|
||||||
'wait' => $this->l10n->t('Please wait'),
|
'wait' => $this->l10n->t('Please wait'),
|
||||||
'placeholdertitle' => $this->l10n->t('Set title'),
|
'placeholdertitle' => $this->l10n->t('Set title'),
|
||||||
'placeholdercategory' => Feature::isEnabled($this->session->getLocalUserId(), Feature::CATEGORIES) ? $this->l10n->t('Categories (comma-separated list)') : '',
|
'placeholdercategory' => Feature::isEnabled($this->session->getLocalUserId(), Feature::CATEGORIES) ? $this->l10n->t('Categories (comma-separated list)') : '',
|
||||||
'always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose',
|
'always_open_compose' => $this->pConfig->get(
|
||||||
$this->config->get('frio', 'always_open_compose', false)) ? '' :
|
$this->session->getLocalUserId(),
|
||||||
|
'frio',
|
||||||
|
'always_open_compose',
|
||||||
|
$this->config->get('frio', 'always_open_compose', false)
|
||||||
|
) ? '' :
|
||||||
$this->l10n->t('You can make this page always open when you use the New Post button in the <a href="/settings/display">Theme Customization settings</a>.'),
|
$this->l10n->t('You can make this page always open when you use the New Post button in the <a href="/settings/display">Theme Customization settings</a>.'),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
@ -220,11 +227,11 @@ class Compose extends BaseModule
|
||||||
$this->l10n->t('Scheduled at'),
|
$this->l10n->t('Scheduled at'),
|
||||||
'scheduled_at'
|
'scheduled_at'
|
||||||
),
|
),
|
||||||
'$created_at' => $created_at,
|
'$created_at' => $created_at,
|
||||||
'$title' => $title,
|
'$title' => $title,
|
||||||
'$category' => $category,
|
'$category' => $category,
|
||||||
'$body' => $body,
|
'$body' => $body,
|
||||||
'$location' => $location,
|
'$location' => $location,
|
||||||
|
|
||||||
'$contact_allow' => implode(',', $contact_allow_list),
|
'$contact_allow' => implode(',', $contact_allow_list),
|
||||||
'$circle_allow' => implode(',', $circle_allow_list),
|
'$circle_allow' => implode(',', $circle_allow_list),
|
||||||
|
@ -233,7 +240,7 @@ class Compose extends BaseModule
|
||||||
|
|
||||||
'$jotplugins' => $jotplugins,
|
'$jotplugins' => $jotplugins,
|
||||||
'$rand_num' => Crypto::randomDigits(12),
|
'$rand_num' => Crypto::randomDigits(12),
|
||||||
'$acl_selector' => ACL::getFullSelectorHTML($this->page, $this->session->getLocalUserId(), $doesFederate, [
|
'$acl_selector' => ACL::getFullSelectorHTML($this->page, $this->session->getLocalUserId(), $doesFederate, [
|
||||||
'allow_cid' => $contact_allow_list,
|
'allow_cid' => $contact_allow_list,
|
||||||
'allow_gid' => $circle_allow_list,
|
'allow_gid' => $circle_allow_list,
|
||||||
'deny_cid' => $contact_deny_list,
|
'deny_cid' => $contact_deny_list,
|
||||||
|
|
|
@ -15,10 +15,10 @@ use Friendica\App\Page;
|
||||||
use Friendica\AppHelper;
|
use Friendica\AppHelper;
|
||||||
use Friendica\BaseModule;
|
use Friendica\BaseModule;
|
||||||
use Friendica\Content\Feature;
|
use Friendica\Content\Feature;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
|
use Friendica\Event\HtmlFilterEvent;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
|
@ -27,6 +27,7 @@ use Friendica\Navigation\SystemMessages;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Util\Crypto;
|
use Friendica\Util\Crypto;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,18 +45,22 @@ class Edit extends BaseModule
|
||||||
protected $mode;
|
protected $mode;
|
||||||
/** @var AppHelper */
|
/** @var AppHelper */
|
||||||
protected $appHelper;
|
protected $appHelper;
|
||||||
|
|
||||||
|
private EventDispatcherInterface $eventDispatcher;
|
||||||
|
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $isModal = false;
|
protected $isModal = false;
|
||||||
|
|
||||||
public function __construct(L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, Page $page, Mode $mode, AppHelper $appHelper, array $server, array $parameters = [])
|
public function __construct(L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, Page $page, Mode $mode, AppHelper $appHelper, EventDispatcherInterface $eventDispatcher, array $server, array $parameters = [])
|
||||||
{
|
{
|
||||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||||
|
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
$this->sysMessages = $sysMessages;
|
$this->sysMessages = $sysMessages;
|
||||||
$this->page = $page;
|
$this->page = $page;
|
||||||
$this->mode = $mode;
|
$this->mode = $mode;
|
||||||
$this->appHelper = $appHelper;
|
$this->appHelper = $appHelper;
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,11 +112,11 @@ class Edit extends BaseModule
|
||||||
}
|
}
|
||||||
|
|
||||||
$item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
|
$item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
|
||||||
$item = Post\Media::addHTMLAttachmentToItem($item);
|
$item = Post\Media::addHTMLAttachmentToItem($item);
|
||||||
|
|
||||||
$jotplugins = '';
|
$jotplugins = $this->eventDispatcher->dispatch(
|
||||||
|
new HtmlFilterEvent(HtmlFilterEvent::JOT_TOOL, ''),
|
||||||
Hook::callAll('jot_tool', $jotplugins);
|
)->getHtml();
|
||||||
|
|
||||||
$output .= Renderer::replaceMacros(Renderer::getMarkupTemplate('jot.tpl'), [
|
$output .= Renderer::replaceMacros(Renderer::getMarkupTemplate('jot.tpl'), [
|
||||||
'$is_edit' => true,
|
'$is_edit' => true,
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
namespace Friendica\Module\Post\Tag;
|
namespace Friendica\Module\Post\Tag;
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Core\Worker;
|
use Friendica\Core\Worker;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
|
@ -22,6 +22,7 @@ use Friendica\Protocol\Activity;
|
||||||
use Friendica\Protocol\Delivery;
|
use Friendica\Protocol\Delivery;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,12 +32,14 @@ class Add extends \Friendica\BaseModule
|
||||||
{
|
{
|
||||||
/** @var IHandleUserSessions */
|
/** @var IHandleUserSessions */
|
||||||
private $session;
|
private $session;
|
||||||
|
private EventDispatcherInterface $eventDispatcher;
|
||||||
|
|
||||||
public function __construct(IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
public function __construct(IHandleUserSessions $session, EventDispatcherInterface $eventDispatcher, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||||
{
|
{
|
||||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||||
|
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function post(array $request = [])
|
protected function post(array $request = [])
|
||||||
|
@ -149,7 +152,10 @@ EOT;
|
||||||
Tag::store($item['uri-id'], Tag::HASHTAG, $term);
|
Tag::store($item['uri-id'], Tag::HASHTAG, $term);
|
||||||
|
|
||||||
$post['id'] = $post_id;
|
$post['id'] = $post_id;
|
||||||
Hook::callAll('post_local_end', $post);
|
|
||||||
|
$post = $this->eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL_END, $post)
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
$post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]);
|
$post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]);
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,11 @@ use Friendica\App\BaseURL;
|
||||||
use Friendica\AppHelper;
|
use Friendica\AppHelper;
|
||||||
use Friendica\BaseModule;
|
use Friendica\BaseModule;
|
||||||
use Friendica\Contact\Introduction\Repository\Introduction;
|
use Friendica\Contact\Introduction\Repository\Introduction;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
use Friendica\Database\Database;
|
use Friendica\Database\Database;
|
||||||
|
use Friendica\Event\Event;
|
||||||
use Friendica\Model\Notification;
|
use Friendica\Model\Notification;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Module\Response;
|
use Friendica\Module\Response;
|
||||||
|
@ -25,6 +25,7 @@ use Friendica\Navigation\SystemMessages;
|
||||||
use Friendica\Network\HTTPException\ForbiddenException;
|
use Friendica\Network\HTTPException\ForbiddenException;
|
||||||
use Friendica\Security\Authentication;
|
use Friendica\Security\Authentication;
|
||||||
use Friendica\Util;
|
use Friendica\Util;
|
||||||
|
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,18 +47,20 @@ class Delegation extends BaseModule
|
||||||
private $intro;
|
private $intro;
|
||||||
/** @var AppHelper */
|
/** @var AppHelper */
|
||||||
private $appHelper;
|
private $appHelper;
|
||||||
|
private EventDispatcherInterface $eventDispatcher;
|
||||||
|
|
||||||
public function __construct(AppHelper $appHelper, Introduction $intro, Notify $notify, SystemMessages $systemMessages, Authentication $auth, Database $db, IHandleUserSessions $session, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
|
public function __construct(EventDispatcherInterface $eventDispatcher, AppHelper $appHelper, Introduction $intro, Notify $notify, SystemMessages $systemMessages, Authentication $auth, Database $db, IHandleUserSessions $session, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
|
||||||
{
|
{
|
||||||
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
|
||||||
|
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
$this->db = $db;
|
$this->db = $db;
|
||||||
$this->auth = $auth;
|
$this->auth = $auth;
|
||||||
$this->systemMessages = $systemMessages;
|
$this->systemMessages = $systemMessages;
|
||||||
$this->notify = $notify;
|
$this->notify = $notify;
|
||||||
$this->intro = $intro;
|
$this->intro = $intro;
|
||||||
$this->appHelper = $appHelper;
|
$this->appHelper = $appHelper;
|
||||||
|
$this->eventDispatcher = $eventDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function post(array $request = [])
|
protected function post(array $request = [])
|
||||||
|
@ -128,8 +131,9 @@ class Delegation extends BaseModule
|
||||||
$this->session->setSubManagedUserId($original_id);
|
$this->session->setSubManagedUserId($original_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = [];
|
$this->eventDispatcher->dispatch(
|
||||||
Hook::callAll('home_init', $ret);
|
new Event(Event::HOME_INIT)
|
||||||
|
);
|
||||||
|
|
||||||
$this->systemMessages->addNotice($this->t('You are now logged in as %s', $user['username']));
|
$this->systemMessages->addNotice($this->t('You are now logged in as %s', $user['username']));
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,10 @@ namespace Friendica\Object;
|
||||||
use Friendica\Content\ContactSelector;
|
use Friendica\Content\ContactSelector;
|
||||||
use Friendica\Content\Feature;
|
use Friendica\Content\Feature;
|
||||||
use Friendica\Core\Addon;
|
use Friendica\Core\Addon;
|
||||||
use Friendica\Core\Hook;
|
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Conversation;
|
use Friendica\Model\Conversation;
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
|
@ -314,8 +314,14 @@ class Post
|
||||||
$sparkle = ' sparkle';
|
$sparkle = ' sparkle';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
$locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
|
$locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
|
||||||
Hook::callAll('render_location', $locate);
|
|
||||||
|
$locate = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::RENDER_LOCATION, $locate),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
$location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
|
$location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
|
||||||
|
|
||||||
// process action responses - e.g. like/dislike/attend/agree/whatever
|
// process action responses - e.g. like/dislike/attend/agree/whatever
|
||||||
|
@ -631,7 +637,10 @@ class Post
|
||||||
];
|
];
|
||||||
|
|
||||||
$arr = ['item' => $item, 'output' => $tmp_item];
|
$arr = ['item' => $item, 'output' => $tmp_item];
|
||||||
Hook::callAll('display_item', $arr);
|
|
||||||
|
$arr = $eventDispatcher->dispatch(
|
||||||
|
new ArrayFilterEvent(ArrayFilterEvent::DISPLAY_ITEM, $arr),
|
||||||
|
)->getArray();
|
||||||
|
|
||||||
$result = $arr['output'];
|
$result = $arr['output'];
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,11 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Friendica\Test\Unit\Core\Hooks;
|
namespace Friendica\Test\Unit\Core\Hooks;
|
||||||
|
|
||||||
|
use FastRoute\RouteCollector;
|
||||||
use Friendica\Core\Config\Util\ConfigFileManager;
|
use Friendica\Core\Config\Util\ConfigFileManager;
|
||||||
use Friendica\Core\Hooks\HookEventBridge;
|
use Friendica\Core\Hooks\HookEventBridge;
|
||||||
use Friendica\Event\ArrayFilterEvent;
|
use Friendica\Event\ArrayFilterEvent;
|
||||||
|
use Friendica\Event\CollectRoutesEvent;
|
||||||
use Friendica\Event\ConfigLoadedEvent;
|
use Friendica\Event\ConfigLoadedEvent;
|
||||||
use Friendica\Event\Event;
|
use Friendica\Event\Event;
|
||||||
use Friendica\Event\HtmlFilterEvent;
|
use Friendica\Event\HtmlFilterEvent;
|
||||||
|
@ -22,17 +24,40 @@ class HookEventBridgeTest extends TestCase
|
||||||
public function testGetStaticSubscribedEventsReturnsStaticMethods(): void
|
public function testGetStaticSubscribedEventsReturnsStaticMethods(): void
|
||||||
{
|
{
|
||||||
$expected = [
|
$expected = [
|
||||||
Event::INIT => 'onNamedEvent',
|
Event::INIT => 'onNamedEvent',
|
||||||
ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
|
Event::HOME_INIT => 'onNamedEvent',
|
||||||
ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
|
ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
|
||||||
ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
|
CollectRoutesEvent::COLLECT_ROUTES => 'onCollectRoutesEvent',
|
||||||
ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
|
ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
|
||||||
ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
|
ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
|
||||||
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
|
ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
|
||||||
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
|
||||||
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
ArrayFilterEvent::POST_LOCAL_START => 'onArrayFilterEvent',
|
||||||
HtmlFilterEvent::PAGE_CONTENT_TOP => 'onHtmlFilterEvent',
|
ArrayFilterEvent::POST_LOCAL => 'onArrayFilterEvent',
|
||||||
HtmlFilterEvent::PAGE_END => 'onHtmlFilterEvent',
|
ArrayFilterEvent::POST_LOCAL_END => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::DISPLAY_ITEM => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::RENDER_LOCATION => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::ITEM_PHOTO_MENU => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::OEMBED_FETCH_END => 'onOembedFetchEndEvent',
|
||||||
|
ArrayFilterEvent::PAGE_INFO => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::SMILEY_LIST => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::BBCODE_TO_HTML_START => 'onBbcodeToHtmlEvent',
|
||||||
|
ArrayFilterEvent::HTML_TO_BBCODE_END => 'onHtmlToBbcodeEvent',
|
||||||
|
ArrayFilterEvent::BBCODE_TO_MARKDOWN_END => 'onBbcodeToMarkdownEvent',
|
||||||
|
ArrayFilterEvent::JOT_NETWORKS => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'onArrayFilterEvent',
|
||||||
|
ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE => 'onArrayFilterEvent',
|
||||||
|
HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::PAGE_CONTENT_TOP => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::PAGE_END => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::JOT_TOOL => 'onHtmlFilterEvent',
|
||||||
|
HtmlFilterEvent::CONTACT_BLOCK_END => 'onHtmlFilterEvent',
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
|
@ -58,6 +83,7 @@ class HookEventBridgeTest extends TestCase
|
||||||
return [
|
return [
|
||||||
['test', 'test'],
|
['test', 'test'],
|
||||||
[Event::INIT, 'init_1'],
|
[Event::INIT, 'init_1'],
|
||||||
|
[Event::HOME_INIT, 'home_init'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,6 +137,124 @@ class HookEventBridgeTest extends TestCase
|
||||||
HookEventBridge::onConfigLoadedEvent($event);
|
HookEventBridge::onConfigLoadedEvent($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getCollectRoutesEventData(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['test', 'test'],
|
||||||
|
[CollectRoutesEvent::COLLECT_ROUTES, 'route_collection'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getCollectRoutesEventData
|
||||||
|
*/
|
||||||
|
public function testOnCollectRoutesEventCallsHookWithCorrectValue($name, $expected): void
|
||||||
|
{
|
||||||
|
$routeCollector = $this->createStub(RouteCollector::class);
|
||||||
|
|
||||||
|
$event = new CollectRoutesEvent($name, $routeCollector);
|
||||||
|
|
||||||
|
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
|
||||||
|
$reflectionProperty->setAccessible(true);
|
||||||
|
|
||||||
|
$reflectionProperty->setValue(null, function (string $name, $data) use ($expected, $routeCollector) {
|
||||||
|
$this->assertSame($expected, $name);
|
||||||
|
$this->assertSame($routeCollector, $data);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
});
|
||||||
|
|
||||||
|
HookEventBridge::onCollectRoutesEvent($event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOnOembedFetchEndEventCallsHookWithCorrectValue(): void
|
||||||
|
{
|
||||||
|
$event = new ArrayFilterEvent(ArrayFilterEvent::OEMBED_FETCH_END, ['url' => 'original_url']);
|
||||||
|
|
||||||
|
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
|
||||||
|
$reflectionProperty->setAccessible(true);
|
||||||
|
|
||||||
|
$reflectionProperty->setValue(null, function (string $name, string $data): string {
|
||||||
|
$this->assertSame('oembed_fetch_url', $name);
|
||||||
|
$this->assertSame('original_url', $data);
|
||||||
|
|
||||||
|
return 'changed_url';
|
||||||
|
});
|
||||||
|
|
||||||
|
HookEventBridge::onOembedFetchEndEvent($event);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
['url' => 'changed_url'],
|
||||||
|
$event->getArray(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOnBbcodeToHtmlEventCallsHookWithCorrectValue(): void
|
||||||
|
{
|
||||||
|
$event = new ArrayFilterEvent(ArrayFilterEvent::BBCODE_TO_HTML_START, ['bbcode2html' => '[b]original[/b]']);
|
||||||
|
|
||||||
|
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
|
||||||
|
$reflectionProperty->setAccessible(true);
|
||||||
|
|
||||||
|
$reflectionProperty->setValue(null, function (string $name, string $data): string {
|
||||||
|
$this->assertSame('bbcode', $name);
|
||||||
|
$this->assertSame('[b]original[/b]', $data);
|
||||||
|
|
||||||
|
return '<b>changed</b>';
|
||||||
|
});
|
||||||
|
|
||||||
|
HookEventBridge::onBbcodeToHtmlEvent($event);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
['bbcode2html' => '<b>changed</b>'],
|
||||||
|
$event->getArray(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOnHtmlToBbcodeEventCallsHookWithCorrectValue(): void
|
||||||
|
{
|
||||||
|
$event = new ArrayFilterEvent(ArrayFilterEvent::HTML_TO_BBCODE_END, ['html2bbcode' => '<b>original</b>']);
|
||||||
|
|
||||||
|
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
|
||||||
|
$reflectionProperty->setAccessible(true);
|
||||||
|
|
||||||
|
$reflectionProperty->setValue(null, function (string $name, string $data): string {
|
||||||
|
$this->assertSame('html2bbcode', $name);
|
||||||
|
$this->assertSame('<b>original</b>', $data);
|
||||||
|
|
||||||
|
return '[b]changed[/b]';
|
||||||
|
});
|
||||||
|
|
||||||
|
HookEventBridge::onHtmlToBbcodeEvent($event);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
['html2bbcode' => '[b]changed[/b]'],
|
||||||
|
$event->getArray(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testOnBbcodeToMarkdownEventCallsHookWithCorrectValue(): void
|
||||||
|
{
|
||||||
|
$event = new ArrayFilterEvent(ArrayFilterEvent::BBCODE_TO_MARKDOWN_END, ['bbcode2markdown' => '[b]original[/b]']);
|
||||||
|
|
||||||
|
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
|
||||||
|
$reflectionProperty->setAccessible(true);
|
||||||
|
|
||||||
|
$reflectionProperty->setValue(null, function (string $name, string $data): string {
|
||||||
|
$this->assertSame('bb2diaspora', $name);
|
||||||
|
$this->assertSame('[b]original[/b]', $data);
|
||||||
|
|
||||||
|
return '**changed**';
|
||||||
|
});
|
||||||
|
|
||||||
|
HookEventBridge::onBbcodeToMarkdownEvent($event);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
['bbcode2markdown' => '**changed**'],
|
||||||
|
$event->getArray(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public static function getArrayFilterEventData(): array
|
public static function getArrayFilterEventData(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
@ -119,6 +263,21 @@ class HookEventBridgeTest extends TestCase
|
||||||
[ArrayFilterEvent::NAV_INFO, 'nav_info'],
|
[ArrayFilterEvent::NAV_INFO, 'nav_info'],
|
||||||
[ArrayFilterEvent::FEATURE_ENABLED, 'isEnabled'],
|
[ArrayFilterEvent::FEATURE_ENABLED, 'isEnabled'],
|
||||||
[ArrayFilterEvent::FEATURE_GET, 'get'],
|
[ArrayFilterEvent::FEATURE_GET, 'get'],
|
||||||
|
[ArrayFilterEvent::POST_LOCAL_START, 'post_local_start'],
|
||||||
|
[ArrayFilterEvent::POST_LOCAL, 'post_local'],
|
||||||
|
[ArrayFilterEvent::POST_LOCAL_END, 'post_local_end'],
|
||||||
|
[ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'photo_upload_form'],
|
||||||
|
[ArrayFilterEvent::NETWORK_TO_NAME, 'network_to_name'],
|
||||||
|
[ArrayFilterEvent::CONVERSATION_START, 'conversation_start'],
|
||||||
|
[ArrayFilterEvent::DISPLAY_ITEM, 'display_item'],
|
||||||
|
[ArrayFilterEvent::RENDER_LOCATION, 'render_location'],
|
||||||
|
[ArrayFilterEvent::ITEM_PHOTO_MENU, 'item_photo_menu'],
|
||||||
|
[ArrayFilterEvent::PAGE_INFO, 'page_info_data'],
|
||||||
|
[ArrayFilterEvent::SMILEY_LIST, 'smilie'],
|
||||||
|
[ArrayFilterEvent::JOT_NETWORKS, 'jot_networks'],
|
||||||
|
[ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'support_follow'],
|
||||||
|
[ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'support_revoke_follow'],
|
||||||
|
[ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, 'support_probe'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,6 +310,8 @@ class HookEventBridgeTest extends TestCase
|
||||||
[HtmlFilterEvent::PAGE_HEADER, 'page_header'],
|
[HtmlFilterEvent::PAGE_HEADER, 'page_header'],
|
||||||
[HtmlFilterEvent::PAGE_CONTENT_TOP, 'page_content_top'],
|
[HtmlFilterEvent::PAGE_CONTENT_TOP, 'page_content_top'],
|
||||||
[HtmlFilterEvent::PAGE_END, 'page_end'],
|
[HtmlFilterEvent::PAGE_END, 'page_end'],
|
||||||
|
[HtmlFilterEvent::JOT_TOOL, 'jot_tool'],
|
||||||
|
[HtmlFilterEvent::CONTACT_BLOCK_END, 'contact_block_end'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,27 @@ class ArrayFilterEventTest extends TestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[ArrayFilterEvent::APP_MENU, 'friendica.data.app_menu'],
|
[ArrayFilterEvent::APP_MENU, 'friendica.data.app_menu'],
|
||||||
|
[ArrayFilterEvent::NAV_INFO, 'friendica.data.nav_info'],
|
||||||
|
[ArrayFilterEvent::FEATURE_ENABLED, 'friendica.data.feature_enabled'],
|
||||||
|
[ArrayFilterEvent::FEATURE_GET, 'friendica.data.feature_get'],
|
||||||
|
[ArrayFilterEvent::POST_LOCAL_START, 'friendica.data.post_local_start'],
|
||||||
|
[ArrayFilterEvent::POST_LOCAL, 'friendica.data.post_local'],
|
||||||
|
[ArrayFilterEvent::POST_LOCAL_END, 'friendica.data.post_local_end'],
|
||||||
|
[ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'friendica.data.photo_upload_form'],
|
||||||
|
[ArrayFilterEvent::NETWORK_TO_NAME, 'friendica.data.network_to_name'],
|
||||||
|
[ArrayFilterEvent::CONVERSATION_START, 'friendica.data.conversation_start'],
|
||||||
|
[ArrayFilterEvent::DISPLAY_ITEM, 'friendica.data.display_item'],
|
||||||
|
[ArrayFilterEvent::RENDER_LOCATION, 'friendica.data.render_location'],
|
||||||
|
[ArrayFilterEvent::ITEM_PHOTO_MENU, 'friendica.data.item_photo_menu'],
|
||||||
|
[ArrayFilterEvent::OEMBED_FETCH_END, 'friendica.data.oembed_fetch_end'],
|
||||||
|
[ArrayFilterEvent::PAGE_INFO, 'friendica.data.page_info'],
|
||||||
|
[ArrayFilterEvent::SMILEY_LIST, 'friendica.data.smiley_list'],
|
||||||
|
[ArrayFilterEvent::BBCODE_TO_HTML_START, 'friendica.data.bbcode_to_html_start'],
|
||||||
|
[ArrayFilterEvent::BBCODE_TO_MARKDOWN_END, 'friendica.data.bbcode_to_markdown_end'],
|
||||||
|
[ArrayFilterEvent::JOT_NETWORKS, 'friendica.data.jot_networks'],
|
||||||
|
[ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'friendica.data.protocol_supports_follow'],
|
||||||
|
[ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'friendica.data.protocol_supports_revoke_follow'],
|
||||||
|
[ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, 'friendica.data.protocol_supports_probe'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
67
tests/Unit/Event/CollectRoutesEventTest.php
Normal file
67
tests/Unit/Event/CollectRoutesEventTest.php
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Copyright (C) 2010-2024, the Friendica project
|
||||||
|
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Friendica\Test\Unit\Event;
|
||||||
|
|
||||||
|
use FastRoute\RouteCollector;
|
||||||
|
use Friendica\Event\CollectRoutesEvent;
|
||||||
|
use Friendica\Event\NamedEvent;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class CollectRoutesEventTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testImplementationOfInstances(): void
|
||||||
|
{
|
||||||
|
$event = new CollectRoutesEvent('test', $this->createStub(RouteCollector::class));
|
||||||
|
|
||||||
|
$this->assertInstanceOf(NamedEvent::class, $event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPublicConstants(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[CollectRoutesEvent::COLLECT_ROUTES, 'friendica.collect_routes'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getPublicConstants
|
||||||
|
*/
|
||||||
|
public function testPublicConstantsAreAvailable($value, $expected): void
|
||||||
|
{
|
||||||
|
$this->assertSame($expected, $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetNameReturnsName(): void
|
||||||
|
{
|
||||||
|
$event = new CollectRoutesEvent('test', $this->createStub(RouteCollector::class));
|
||||||
|
|
||||||
|
$this->assertSame('test', $event->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetRouteCollectorReturnsCorrectString(): void
|
||||||
|
{
|
||||||
|
$routeCollector = $this->createStub(RouteCollector::class);
|
||||||
|
|
||||||
|
$event = new CollectRoutesEvent('test', $routeCollector);
|
||||||
|
|
||||||
|
$this->assertSame($routeCollector, $event->getRouteCollector());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSetRouteCollector(): void
|
||||||
|
{
|
||||||
|
$event = new CollectRoutesEvent('test', $this->createStub(RouteCollector::class));
|
||||||
|
|
||||||
|
$routeCollector = $this->createStub(RouteCollector::class);
|
||||||
|
|
||||||
|
$event->setRouteCollector($routeCollector);
|
||||||
|
|
||||||
|
$this->assertSame($routeCollector, $event->getRouteCollector());
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ namespace Friendica\Test\src\Content;
|
||||||
|
|
||||||
use Friendica\Content\Smilies;
|
use Friendica\Content\Smilies;
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
|
use Friendica\Core\Hooks\HookEventBridge;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||||
use Friendica\Test\FixtureTestCase;
|
use Friendica\Test\FixtureTestCase;
|
||||||
|
@ -21,22 +22,29 @@ class SmiliesTest extends FixtureTestCase
|
||||||
|
|
||||||
DI::config()->set('system', 'no_smilies', false);
|
DI::config()->set('system', 'no_smilies', false);
|
||||||
|
|
||||||
|
/** @var \Friendica\Event\EventDispatcher */
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
foreach (HookEventBridge::getStaticSubscribedEvents() as $eventName => $methodName) {
|
||||||
|
$eventDispatcher->addListener($eventName, [HookEventBridge::class, $methodName]);
|
||||||
|
}
|
||||||
|
|
||||||
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
|
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
|
||||||
Hook::loadHooks();
|
Hook::loadHooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataLinks()
|
public function dataLinks(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
/** @see https://github.com/friendica/friendica/pull/6933 */
|
/** @see https://github.com/friendica/friendica/pull/6933 */
|
||||||
'bug-6933-1' => [
|
'bug-6933-1' => [
|
||||||
'data' => '<code>/</code>',
|
'data' => '<code>/</code>',
|
||||||
'smilies' => ['texts' => [], 'icons' => []],
|
'smilies' => ['texts' => [], 'icons' => []],
|
||||||
'expected' => '<code>/</code>',
|
'expected' => '<code>/</code>',
|
||||||
],
|
],
|
||||||
'bug-6933-2' => [
|
'bug-6933-2' => [
|
||||||
'data' => '<code>code</code>',
|
'data' => '<code>code</code>',
|
||||||
'smilies' => ['texts' => [], 'icons' => []],
|
'smilies' => ['texts' => [], 'icons' => []],
|
||||||
'expected' => '<code>code</code>',
|
'expected' => '<code>code</code>',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
@ -53,7 +61,7 @@ class SmiliesTest extends FixtureTestCase
|
||||||
*
|
*
|
||||||
* @throws InternalServerErrorException
|
* @throws InternalServerErrorException
|
||||||
*/
|
*/
|
||||||
public function testReplaceFromArray(string $text, array $smilies, string $expected)
|
public function testReplaceFromArray(string $text, array $smilies, string $expected): void
|
||||||
{
|
{
|
||||||
$output = Smilies::replaceFromArray($text, $smilies);
|
$output = Smilies::replaceFromArray($text, $smilies);
|
||||||
self::assertEquals($expected, $output);
|
self::assertEquals($expected, $output);
|
||||||
|
@ -64,141 +72,137 @@ class SmiliesTest extends FixtureTestCase
|
||||||
return [
|
return [
|
||||||
'emoji' => [
|
'emoji' => [
|
||||||
'expected' => true,
|
'expected' => true,
|
||||||
'body' => '👀',
|
'body' => '👀',
|
||||||
],
|
],
|
||||||
'emojis' => [
|
'emojis' => [
|
||||||
'expected' => true,
|
'expected' => true,
|
||||||
'body' => '👀🤷',
|
'body' => '👀🤷',
|
||||||
],
|
],
|
||||||
'emoji+whitespace' => [
|
'emoji+whitespace' => [
|
||||||
'expected' => true,
|
'expected' => true,
|
||||||
'body' => ' 👀 ',
|
'body' => ' 👀 ',
|
||||||
],
|
],
|
||||||
'empty' => [
|
'empty' => [
|
||||||
'expected' => false,
|
'expected' => false,
|
||||||
'body' => '',
|
'body' => '',
|
||||||
],
|
],
|
||||||
'whitespace' => [
|
'whitespace' => [
|
||||||
'expected' => false,
|
'expected' => false,
|
||||||
'body' => '
|
'body' => '
|
||||||
',
|
',
|
||||||
],
|
],
|
||||||
'emoji+ASCII' => [
|
'emoji+ASCII' => [
|
||||||
'expected' => false,
|
'expected' => false,
|
||||||
'body' => '🤷a',
|
'body' => '🤷a',
|
||||||
],
|
],
|
||||||
'HTML entity whitespace' => [
|
'HTML entity whitespace' => [
|
||||||
'expected' => false,
|
'expected' => false,
|
||||||
'body' => ' ',
|
'body' => ' ',
|
||||||
],
|
],
|
||||||
'HTML entity else' => [
|
'HTML entity else' => [
|
||||||
'expected' => false,
|
'expected' => false,
|
||||||
'body' => '°',
|
'body' => '°',
|
||||||
],
|
],
|
||||||
'emojis+HTML whitespace' => [
|
'emojis+HTML whitespace' => [
|
||||||
'expected' => true,
|
'expected' => true,
|
||||||
'body' => '👀 🤷',
|
'body' => '👀 🤷',
|
||||||
],
|
],
|
||||||
'emojis+HTML else' => [
|
'emojis+HTML else' => [
|
||||||
'expected' => false,
|
'expected' => false,
|
||||||
'body' => '👀<🤷',
|
'body' => '👀<🤷',
|
||||||
],
|
],
|
||||||
'zwj' => [
|
'zwj' => [
|
||||||
'expected' => true,
|
'expected' => true,
|
||||||
'body' => '👨👨👧',
|
'body' => '👨👨👧',
|
||||||
],
|
],
|
||||||
'zwj+whitespace' => [
|
'zwj+whitespace' => [
|
||||||
'expected' => true,
|
'expected' => true,
|
||||||
'body' => ' 👨👨👧 ',
|
'body' => ' 👨👨👧 ',
|
||||||
],
|
],
|
||||||
'zwj+HTML whitespace' => [
|
'zwj+HTML whitespace' => [
|
||||||
'expected' => true,
|
'expected' => true,
|
||||||
'body' => ' 👨👨👧 ',
|
'body' => ' 👨👨👧 ',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataIsEmojiPost
|
* @dataProvider dataIsEmojiPost
|
||||||
*
|
|
||||||
* @param bool $expected
|
|
||||||
* @param string $body
|
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function testIsEmojiPost(bool $expected, string $body)
|
public function testIsEmojiPost(bool $expected, string $body): void
|
||||||
{
|
{
|
||||||
$this->assertEquals($expected, Smilies::isEmojiPost($body));
|
$this->assertEquals($expected, Smilies::isEmojiPost($body));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function dataReplace(): array
|
public function dataReplace(): array
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'simple-1' => [
|
'simple-1' => [
|
||||||
'expected' => 'alt=":-p"',
|
'expected' => 'alt=":-p"',
|
||||||
'body' => ':-p',
|
'body' => ':-p',
|
||||||
],
|
],
|
||||||
'simple-1' => [
|
'simple-2' => [
|
||||||
'expected' => 'alt=":-p"',
|
'expected' => 'alt=":-p"',
|
||||||
'body' => ' :-p ',
|
'body' => ' :-p ',
|
||||||
],
|
],
|
||||||
'word-boundary-1' => [
|
'word-boundary-1' => [
|
||||||
'expected' => ':-pppp',
|
'expected' => ':-pppp',
|
||||||
'body' => ':-pppp',
|
'body' => ':-pppp',
|
||||||
],
|
],
|
||||||
'word-boundary-2' => [
|
'word-boundary-2' => [
|
||||||
'expected' => '~friendicaca',
|
'expected' => '~friendicaca',
|
||||||
'body' => '~friendicaca',
|
'body' => '~friendicaca',
|
||||||
],
|
],
|
||||||
'symbol-boundary-1' => [
|
'symbol-boundary-1' => [
|
||||||
'expected' => 'alt=":-p"',
|
'expected' => 'alt=":-p"',
|
||||||
'body' => '(:-p)',
|
'body' => '(:-p)',
|
||||||
],
|
],
|
||||||
'hearts-1' => [
|
'hearts-1' => [
|
||||||
'expected' => '❤ (❤) ❤',
|
'expected' => '❤ (❤) ❤',
|
||||||
'body' => '<3 (<3) <3',
|
'body' => '<3 (<3) <3',
|
||||||
],
|
],
|
||||||
'hearts-8' => [
|
'hearts-8' => [
|
||||||
'expected' => '(❤❤❤❤❤❤❤❤)',
|
'expected' => '(❤❤❤❤❤❤❤❤)',
|
||||||
'body' => '(<33333333)',
|
'body' => '(<33333333)',
|
||||||
],
|
],
|
||||||
'no-hearts-1' => [
|
'no-hearts-1' => [
|
||||||
'expected' => '(<30)',
|
'expected' => '(<30)',
|
||||||
'body' => '(<30)',
|
'body' => '(<30)',
|
||||||
],
|
],
|
||||||
'no-hearts-2' => [
|
'no-hearts-2' => [
|
||||||
'expected' => '(3<33)',
|
'expected' => '(3<33)',
|
||||||
'body' => '(3<33)',
|
'body' => '(3<33)',
|
||||||
],
|
],
|
||||||
'space' => [
|
'space' => [
|
||||||
'expected' => 'alt="smiley-heart"',
|
'expected' => 'alt="smiley-heart"',
|
||||||
'body' => ':smiley heart 333:',
|
'body' => ':smiley heart 333:',
|
||||||
],
|
],
|
||||||
'substitution-1' => [
|
'substitution-1' => [
|
||||||
'expected' => '🔥',
|
'expected' => '🔥',
|
||||||
'body' => '⽕',
|
'body' => '⽕',
|
||||||
],
|
],
|
||||||
'substitution-2' => [
|
'substitution-2' => [
|
||||||
'expected' => '🤗',
|
'expected' => '🤗',
|
||||||
'body' => ':hugging face:',
|
'body' => ':hugging face:',
|
||||||
],
|
],
|
||||||
'substitution-3' => [
|
'substitution-3' => [
|
||||||
'expected' => '🤭',
|
'expected' => '🤭',
|
||||||
'body' => ':face with hand over mouth:',
|
'body' => ':face with hand over mouth:',
|
||||||
],
|
],
|
||||||
'mixed' => [
|
'mixed' => [
|
||||||
'expected' => '🔥 🤭 invalid:hugging face: 🤗',
|
'expected' => '🔥 🤭 invalid:hugging face: 🤗',
|
||||||
'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
|
'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ([':-[', ':-D', 'o.O'] as $emoji) {
|
foreach ([':-[', ':-D', 'o.O'] as $emoji) {
|
||||||
foreach (['A', '_', ':', '-'] as $prefix) {
|
foreach (['A', '_', ':', '-'] as $prefix) {
|
||||||
foreach (['', ' ', 'A', ':', '-'] as $suffix) {
|
foreach (['', ' ', 'A', ':', '-'] as $suffix) {
|
||||||
$no_smile = ($prefix !== '' && ctype_alnum($prefix)) || ($suffix !== '' && ctype_alnum($suffix));
|
$no_smile = ($prefix !== '' && ctype_alnum($prefix)) || ($suffix !== '' && ctype_alnum($suffix));
|
||||||
$s = $prefix . $emoji . $suffix;
|
$s = $prefix . $emoji . $suffix;
|
||||||
$data[] = [
|
$data[] = [
|
||||||
'expected' => $no_smile ? $s : 'alt="' . $emoji . '"',
|
'expected' => $no_smile ? $s : 'alt="' . $emoji . '"',
|
||||||
'body' => $s,
|
'body' => $s,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,11 +212,8 @@ class SmiliesTest extends FixtureTestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataReplace
|
* @dataProvider dataReplace
|
||||||
*
|
|
||||||
* @param string $expected
|
|
||||||
* @param string $body
|
|
||||||
*/
|
*/
|
||||||
public function testReplace(string $expected, string $body)
|
public function testReplace(string $expected, string $body): void
|
||||||
{
|
{
|
||||||
$result = Smilies::replace($body);
|
$result = Smilies::replace($body);
|
||||||
$this->assertStringContainsString($expected, $result);
|
$this->assertStringContainsString($expected, $result);
|
||||||
|
@ -222,58 +223,58 @@ class SmiliesTest extends FixtureTestCase
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'symbols' => [
|
'symbols' => [
|
||||||
'expected' => ['p', 'heart', 'embarrassed', 'kiss'],
|
'expected' => ['p', 'heart', 'embarrassed', 'kiss'],
|
||||||
'body' => ':-p <3 ":-[:-"',
|
'body' => ':-p <3 ":-[:-"',
|
||||||
'normalized' => ':p: :heart: ":embarrassed::kiss:',
|
'normalized' => ':p: :heart: ":embarrassed::kiss:',
|
||||||
],
|
],
|
||||||
'single-smiley' => [
|
'single-smiley' => [
|
||||||
'expected' => ['like'],
|
'expected' => ['like'],
|
||||||
'body' => ':like',
|
'body' => ':like',
|
||||||
'normalized' => ':like:',
|
'normalized' => ':like:',
|
||||||
],
|
],
|
||||||
'multiple-smilies' => [
|
'multiple-smilies' => [
|
||||||
'expected' => ['like', 'dislike'],
|
'expected' => ['like', 'dislike'],
|
||||||
'body' => ':like :dislike',
|
'body' => ':like :dislike',
|
||||||
'normalized' => ':like: :dislike:',
|
'normalized' => ':like: :dislike:',
|
||||||
],
|
],
|
||||||
'nosmile' => [
|
'nosmile' => [
|
||||||
'expected' => [],
|
'expected' => [],
|
||||||
'body' => '[nosmile] :like :like',
|
'body' => '[nosmile] :like :like',
|
||||||
'normalized' => '[nosmile] :like :like'
|
'normalized' => '[nosmile] :like :like'
|
||||||
],
|
],
|
||||||
'in-code' => [
|
'in-code' => [
|
||||||
'expected' => [],
|
'expected' => [],
|
||||||
'body' => '[code]:like :like :like[/code]',
|
'body' => '[code]:like :like :like[/code]',
|
||||||
'normalized' => '[code]:like :like :like[/code]'
|
'normalized' => '[code]:like :like :like[/code]'
|
||||||
],
|
],
|
||||||
'~friendica' => [
|
'~friendica' => [
|
||||||
'expected' => ['friendica'],
|
'expected' => ['friendica'],
|
||||||
'body' => '~friendica',
|
'body' => '~friendica',
|
||||||
'normalized' => ':friendica:'
|
'normalized' => ':friendica:'
|
||||||
],
|
],
|
||||||
'space' => [
|
'space' => [
|
||||||
'expected' => ['smileyheart333'],
|
'expected' => ['smileyheart333'],
|
||||||
'body' => ':smiley heart 333:',
|
'body' => ':smiley heart 333:',
|
||||||
'normalized' => ':smileyheart333:'
|
'normalized' => ':smileyheart333:'
|
||||||
],
|
],
|
||||||
'substitution-1' => [
|
'substitution-1' => [
|
||||||
'expected' => [],
|
'expected' => [],
|
||||||
'body' => '⽕',
|
'body' => '⽕',
|
||||||
'normalized' => '🔥',
|
'normalized' => '🔥',
|
||||||
],
|
],
|
||||||
'substitution-2' => [
|
'substitution-2' => [
|
||||||
'expected' => [],
|
'expected' => [],
|
||||||
'body' => ':hugging face:',
|
'body' => ':hugging face:',
|
||||||
'normalized' => '🤗',
|
'normalized' => '🤗',
|
||||||
],
|
],
|
||||||
'substitution-3' => [
|
'substitution-3' => [
|
||||||
'expected' => [],
|
'expected' => [],
|
||||||
'body' => ':face with hand over mouth:',
|
'body' => ':face with hand over mouth:',
|
||||||
'normalized' => '🤭',
|
'normalized' => '🤭',
|
||||||
],
|
],
|
||||||
'mixed' => [
|
'mixed' => [
|
||||||
'expected' => [],
|
'expected' => [],
|
||||||
'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
|
'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
|
||||||
'normalized' => '🔥 🤭 invalid:hugging face: 🤗',
|
'normalized' => '🔥 🤭 invalid:hugging face: 🤗',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
@ -281,15 +282,11 @@ class SmiliesTest extends FixtureTestCase
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider dataExtractUsedSmilies
|
* @dataProvider dataExtractUsedSmilies
|
||||||
*
|
|
||||||
* @param array $expected
|
|
||||||
* @param string $body
|
|
||||||
* @param stirng $normalized
|
|
||||||
*/
|
*/
|
||||||
public function testExtractUsedSmilies(array $expected, string $body, string $normalized)
|
public function testExtractUsedSmilies(array $expected, string $body, string $normalized): void
|
||||||
{
|
{
|
||||||
$extracted = Smilies::extractUsedSmilies($body, $converted);
|
$extracted = Smilies::extractUsedSmilies($body, $converted);
|
||||||
$expected = array_fill_keys($expected, true);
|
$expected = array_fill_keys($expected, true);
|
||||||
$this->assertEquals($normalized, $converted);
|
$this->assertEquals($normalized, $converted);
|
||||||
foreach (array_keys($extracted) as $shortcode) {
|
foreach (array_keys($extracted) as $shortcode) {
|
||||||
$this->assertArrayHasKey($shortcode, $expected);
|
$this->assertArrayHasKey($shortcode, $expected);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Friendica\Test\src\Factory\Api\Mastodon;
|
namespace Friendica\Test\src\Factory\Api\Mastodon;
|
||||||
|
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
|
use Friendica\Core\Hooks\HookEventBridge;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Test\FixtureTestCase;
|
use Friendica\Test\FixtureTestCase;
|
||||||
|
@ -21,13 +22,21 @@ class StatusTest extends FixtureTestCase
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
DI::config()->set('system', 'no_smilies', false);
|
DI::config()->set('system', 'no_smilies', false);
|
||||||
|
|
||||||
$this->status = DI::mstdnStatus();
|
$this->status = DI::mstdnStatus();
|
||||||
|
|
||||||
|
/** @var \Friendica\Event\EventDispatcher */
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
foreach (HookEventBridge::getStaticSubscribedEvents() as $eventName => $methodName) {
|
||||||
|
$eventDispatcher->addListener($eventName, [HookEventBridge::class, $methodName]);
|
||||||
|
}
|
||||||
|
|
||||||
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
|
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
|
||||||
Hook::loadHooks();
|
Hook::loadHooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleStatus()
|
public function testSimpleStatus(): void
|
||||||
{
|
{
|
||||||
$post = Post::selectFirst([], ['id' => 13]);
|
$post = Post::selectFirst([], ['id' => 13]);
|
||||||
$this->assertNotNull($post);
|
$this->assertNotNull($post);
|
||||||
|
@ -35,7 +44,7 @@ class StatusTest extends FixtureTestCase
|
||||||
$this->assertNotNull($result);
|
$this->assertNotNull($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSimpleEmojiStatus()
|
public function testSimpleEmojiStatus(): void
|
||||||
{
|
{
|
||||||
$post = Post::selectFirst([], ['id' => 14]);
|
$post = Post::selectFirst([], ['id' => 14]);
|
||||||
$this->assertNotNull($post);
|
$this->assertNotNull($post);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Friendica\Test\src\Protocol\ActivityPub;
|
namespace Friendica\Test\src\Protocol\ActivityPub;
|
||||||
|
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
|
use Friendica\Core\Hooks\HookEventBridge;
|
||||||
use Friendica\DI;
|
use Friendica\DI;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Protocol\ActivityPub\Transmitter;
|
use Friendica\Protocol\ActivityPub\Transmitter;
|
||||||
|
@ -21,11 +22,18 @@ class TransmitterTest extends FixtureTestCase
|
||||||
|
|
||||||
DI::config()->set('system', 'no_smilies', false);
|
DI::config()->set('system', 'no_smilies', false);
|
||||||
|
|
||||||
|
/** @var \Friendica\Event\EventDispatcher */
|
||||||
|
$eventDispatcher = DI::eventDispatcher();
|
||||||
|
|
||||||
|
foreach (HookEventBridge::getStaticSubscribedEvents() as $eventName => $methodName) {
|
||||||
|
$eventDispatcher->addListener($eventName, [HookEventBridge::class, $methodName]);
|
||||||
|
}
|
||||||
|
|
||||||
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
|
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
|
||||||
Hook::loadHooks();
|
Hook::loadHooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEmojiPost()
|
public function testEmojiPost(): void
|
||||||
{
|
{
|
||||||
$post = Post::selectFirst([], ['id' => 14]);
|
$post = Post::selectFirst([], ['id' => 14]);
|
||||||
$this->assertNotNull($post);
|
$this->assertNotNull($post);
|
||||||
|
|
Loading…
Add table
Reference in a new issue