mirror of
https://github.com/friendica/friendica
synced 2024-11-18 03:03:41 +00:00
Post processing centralized
This commit is contained in:
parent
0d56f156f7
commit
d1a951f0ac
3 changed files with 92 additions and 89 deletions
64
mod/item.php
64
mod/item.php
|
@ -42,9 +42,7 @@ use Friendica\Model\Item;
|
||||||
use Friendica\Model\ItemURI;
|
use Friendica\Model\ItemURI;
|
||||||
use Friendica\Model\Photo;
|
use Friendica\Model\Photo;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\Tag;
|
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
use Friendica\Object\EMail\ItemCCEMail;
|
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
|
||||||
|
@ -99,14 +97,13 @@ function item_post(App $a) {
|
||||||
|
|
||||||
$post = DI::contentItem()->initializePost($post);
|
$post = DI::contentItem()->initializePost($post);
|
||||||
|
|
||||||
|
$post['edit'] = $orig_post;
|
||||||
$post['self'] = true;
|
$post['self'] = true;
|
||||||
$post['api_source'] = false;
|
$post['api_source'] = false;
|
||||||
$post['edit'] = $orig_post;
|
|
||||||
$post['file'] = '';
|
$post['file'] = '';
|
||||||
$post['attach'] = '';
|
$post['attach'] = '';
|
||||||
$post['inform'] = '';
|
$post['inform'] = '';
|
||||||
$post['postopts'] = '';
|
$post['postopts'] = '';
|
||||||
|
|
||||||
$post['wall'] = $_REQUEST['wall'] ?? true;
|
$post['wall'] = $_REQUEST['wall'] ?? true;
|
||||||
$post['post-type'] = $_REQUEST['post_type'] ?? '';
|
$post['post-type'] = $_REQUEST['post_type'] ?? '';
|
||||||
$post['title'] = trim($_REQUEST['title'] ?? '');
|
$post['title'] = trim($_REQUEST['title'] ?? '');
|
||||||
|
@ -168,7 +165,6 @@ function item_post(App $a) {
|
||||||
$post['pubmail'] = $post['pubmail'] && !$post['private'];
|
$post['pubmail'] = $post['pubmail'] && !$post['private'];
|
||||||
|
|
||||||
if (!empty($orig_post)) {
|
if (!empty($orig_post)) {
|
||||||
$post['uri'] = $orig_post['uri'];
|
|
||||||
$post['file'] = Post\Category::getTextByURIId($orig_post['uri-id'], $orig_post['uid']);
|
$post['file'] = Post\Category::getTextByURIId($orig_post['uri-id'], $orig_post['uid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,15 +198,9 @@ function item_post(App $a) {
|
||||||
throw new HTTPException\BadRequestException(DI::l10n()->t('Empty post discarded.'));
|
throw new HTTPException\BadRequestException(DI::l10n()->t('Empty post discarded.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for hashtags in the body and repair or add hashtag links
|
|
||||||
if ($preview || $orig_post) {
|
|
||||||
$post['body'] = Item::setHashtags($post['body']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// preview mode - prepare the body for display and send it via json
|
// preview mode - prepare the body for display and send it via json
|
||||||
if ($preview) {
|
if ($preview) {
|
||||||
// We set the datarray ID to -1 because in preview mode the dataray
|
// We have to preset some fields, so that the conversation can be displayed
|
||||||
// doesn't have an ID.
|
|
||||||
$post['id'] = -1;
|
$post['id'] = -1;
|
||||||
$post['uri-id'] = -1;
|
$post['uri-id'] = -1;
|
||||||
$post['author-network'] = Protocol::DFRN;
|
$post['author-network'] = Protocol::DFRN;
|
||||||
|
@ -220,7 +210,7 @@ function item_post(App $a) {
|
||||||
$post['owner-updated'] = '';
|
$post['owner-updated'] = '';
|
||||||
$post['has-media'] = false;
|
$post['has-media'] = false;
|
||||||
$post['quote-uri-id'] = Item::getQuoteUriId($post['body'], $post['uid']);
|
$post['quote-uri-id'] = Item::getQuoteUriId($post['body'], $post['uid']);
|
||||||
$post['body'] = BBCode::removeSharedData($post['body']);
|
$post['body'] = BBCode::removeSharedData(Item::setHashtags($post['body']));
|
||||||
$post['writable'] = true;
|
$post['writable'] = true;
|
||||||
|
|
||||||
$o = DI::conversation()->create([$post], 'search', false, true);
|
$o = DI::conversation()->create([$post], 'search', false, true);
|
||||||
|
@ -230,6 +220,10 @@ function item_post(App $a) {
|
||||||
|
|
||||||
Hook::callAll('post_local',$post);
|
Hook::callAll('post_local',$post);
|
||||||
|
|
||||||
|
unset($post['edit']);
|
||||||
|
unset($post['self']);
|
||||||
|
unset($post['api_source']);
|
||||||
|
|
||||||
if (!empty($_REQUEST['scheduled_at'])) {
|
if (!empty($_REQUEST['scheduled_at'])) {
|
||||||
$scheduled_at = DateTimeFormat::convert($_REQUEST['scheduled_at'], 'UTC', $a->getTimeZone());
|
$scheduled_at = DateTimeFormat::convert($_REQUEST['scheduled_at'], 'UTC', $a->getTimeZone());
|
||||||
if ($scheduled_at > DateTimeFormat::utcNow()) {
|
if ($scheduled_at > DateTimeFormat::utcNow()) {
|
||||||
|
@ -238,9 +232,6 @@ function item_post(App $a) {
|
||||||
unset($post['commented']);
|
unset($post['commented']);
|
||||||
unset($post['received']);
|
unset($post['received']);
|
||||||
unset($post['changed']);
|
unset($post['changed']);
|
||||||
unset($post['edit']);
|
|
||||||
unset($post['self']);
|
|
||||||
unset($post['api_source']);
|
|
||||||
|
|
||||||
Post\Delayed::add($post['uri'], $post, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED_NO_HOOK, $scheduled_at);
|
Post\Delayed::add($post['uri'], $post, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED_NO_HOOK, $scheduled_at);
|
||||||
item_post_return(DI::baseUrl(), $return_path);
|
item_post_return(DI::baseUrl(), $return_path);
|
||||||
|
@ -261,14 +252,6 @@ function item_post(App $a) {
|
||||||
System::jsonExit($json);
|
System::jsonExit($json);
|
||||||
}
|
}
|
||||||
|
|
||||||
$post['uri-id'] = ItemURI::getIdByURI($post['uri']);
|
|
||||||
|
|
||||||
$quote_uri_id = Item::getQuoteUriId($post['body'], $post['uid']);
|
|
||||||
if (!empty($quote_uri_id)) {
|
|
||||||
$post['quote-uri-id'] = $quote_uri_id;
|
|
||||||
$post['body'] = BBCode::removeSharedData($post['body']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($orig_post) {
|
if ($orig_post) {
|
||||||
$fields = [
|
$fields = [
|
||||||
'title' => $post['title'],
|
'title' => $post['title'],
|
||||||
|
@ -279,8 +262,16 @@ function item_post(App $a) {
|
||||||
'changed' => DateTimeFormat::utcNow()
|
'changed' => DateTimeFormat::utcNow()
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$fields['body'] = Item::setHashtags($fields['body']);
|
||||||
|
|
||||||
|
$quote_uri_id = Item::getQuoteUriId($fields['body'], $post['uid']);
|
||||||
|
if (!empty($quote_uri_id)) {
|
||||||
|
$fields['quote-uri-id'] = $quote_uri_id;
|
||||||
|
$fields['body'] = BBCode::removeSharedData($post['body']);
|
||||||
|
}
|
||||||
|
|
||||||
Item::update($fields, ['id' => $post_id]);
|
Item::update($fields, ['id' => $post_id]);
|
||||||
Item::updateDisplayCache($post['uri-id']);
|
Item::updateDisplayCache($orig_post['uri-id']);
|
||||||
|
|
||||||
if ($return_path) {
|
if ($return_path) {
|
||||||
DI::baseUrl()->redirect($return_path);
|
DI::baseUrl()->redirect($return_path);
|
||||||
|
@ -289,10 +280,6 @@ function item_post(App $a) {
|
||||||
throw new HTTPException\OKException(DI::l10n()->t('Post updated.'));
|
throw new HTTPException\OKException(DI::l10n()->t('Post updated.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($post['edit']);
|
|
||||||
unset($post['self']);
|
|
||||||
unset($post['api_source']);
|
|
||||||
|
|
||||||
$post_id = Item::insert($post);
|
$post_id = Item::insert($post);
|
||||||
if (!$post_id) {
|
if (!$post_id) {
|
||||||
DI::sysmsg()->addNotice(DI::l10n()->t('Item wasn\'t stored.'));
|
DI::sysmsg()->addNotice(DI::l10n()->t('Item wasn\'t stored.'));
|
||||||
|
@ -313,26 +300,9 @@ function item_post(App $a) {
|
||||||
throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item couldn\'t be fetched.'));
|
throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item couldn\'t be fetched.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!\Friendica\Content\Feature::isEnabled($post['uid'], 'explicit_mentions') && ($post['gravity'] == Item::GRAVITY_COMMENT)) {
|
|
||||||
Tag::createImplicitMentions($post['uri-id'], $post['thr-parent-id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
Hook::callAll('post_local_end', $post);
|
|
||||||
|
|
||||||
$recipients = explode(',', $emailcc);
|
$recipients = explode(',', $emailcc);
|
||||||
if (count($recipients)) {
|
|
||||||
foreach ($recipients as $recipient) {
|
|
||||||
$address = trim($recipient);
|
|
||||||
if (!strlen($address)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$author = DBA::selectFirst('contact', ['thumb'], ['uid' => $uid, 'self' => true]);
|
DI::contentItem()->postProcessPost($post, $recipients);
|
||||||
|
|
||||||
DI::emailer()->send(new ItemCCEMail(DI::app(), DI::l10n(), DI::baseUrl(),
|
|
||||||
$post, $address, $author['thumb'] ?? ''));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger::debug('post_complete');
|
Logger::debug('post_complete');
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
namespace Friendica\Content;
|
namespace Friendica\Content;
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
use Friendica\App\BaseURL;
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Content\Text\BBCode\Video;
|
use Friendica\Content\Text\BBCode\Video;
|
||||||
|
@ -44,9 +45,11 @@ use Friendica\Model\Tag;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Network\HTTPException;
|
use Friendica\Network\HTTPException;
|
||||||
|
use Friendica\Object\EMail\ItemCCEMail;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
use Friendica\Util\ACLFormatter;
|
use Friendica\Util\ACLFormatter;
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
use Friendica\Util\Emailer;
|
||||||
use Friendica\Util\ParseUrl;
|
use Friendica\Util\ParseUrl;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use Friendica\Util\Proxy;
|
use Friendica\Util\Proxy;
|
||||||
|
@ -73,8 +76,12 @@ class Item
|
||||||
private $pConfig;
|
private $pConfig;
|
||||||
/** @var BaseURL */
|
/** @var BaseURL */
|
||||||
private $baseURL;
|
private $baseURL;
|
||||||
|
/** @var Emailer */
|
||||||
|
private $emailer;
|
||||||
|
/** @var App */
|
||||||
|
private $app;
|
||||||
|
|
||||||
public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession, Video $bbCodeVideo, ACLFormatter $aclFormatter, IManagePersonalConfigValues $pConfig, BaseURL $baseURL)
|
public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession, Video $bbCodeVideo, ACLFormatter $aclFormatter, IManagePersonalConfigValues $pConfig, BaseURL $baseURL, Emailer $emailer, App $app)
|
||||||
{
|
{
|
||||||
$this->profiler = $profiler;
|
$this->profiler = $profiler;
|
||||||
$this->activity = $activity;
|
$this->activity = $activity;
|
||||||
|
@ -84,6 +91,8 @@ class Item
|
||||||
$this->aclFormatter = $aclFormatter;
|
$this->aclFormatter = $aclFormatter;
|
||||||
$this->baseURL = $baseURL;
|
$this->baseURL = $baseURL;
|
||||||
$this->pConfig = $pConfig;
|
$this->pConfig = $pConfig;
|
||||||
|
$this->emailer = $emailer;
|
||||||
|
$this->app = $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -991,4 +1000,25 @@ class Item
|
||||||
|
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function postProcessPost(array $post, array $recipients = [])
|
||||||
|
{
|
||||||
|
if (!\Friendica\Content\Feature::isEnabled($post['uid'], 'explicit_mentions') && ($post['gravity'] == ItemModel::GRAVITY_COMMENT)) {
|
||||||
|
Tag::createImplicitMentions($post['uri-id'], $post['thr-parent-id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
Hook::callAll('post_local_end', $post);
|
||||||
|
|
||||||
|
$author = DBA::selectFirst('contact', ['thumb'], ['uid' => $post['uid'], 'self' => true]);
|
||||||
|
|
||||||
|
foreach ($recipients as $recipient) {
|
||||||
|
$address = trim($recipient);
|
||||||
|
if (!strlen($address)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->emailer->send(new ItemCCEMail($this->app, $this->l10n, $this->baseURL,
|
||||||
|
$post, $address, $author['thumb'] ?? ''));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -820,6 +820,12 @@ class Item
|
||||||
private static function prepareOriginPost(array $item): array
|
private static function prepareOriginPost(array $item): array
|
||||||
{
|
{
|
||||||
$item = DI::contentItem()->initializePost($item);
|
$item = DI::contentItem()->initializePost($item);
|
||||||
|
|
||||||
|
if (Photo::setPermissionFromBody($item['body'], $item['uid'], $item['contact-id'], $item['allow_cid'], $item['allow_gid'], $item['deny_cid'], $item['deny_gid'])) {
|
||||||
|
$item['object-type'] = Activity\ObjectType::IMAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$item = DI::contentItem()->moveAttachmentsFromBodyToAttach($item);
|
||||||
$item = DI::contentItem()->finalizePost($item);
|
$item = DI::contentItem()->finalizePost($item);
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
|
@ -1301,10 +1307,7 @@ class Item
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($notify) {
|
if ($notify) {
|
||||||
if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == self::GRAVITY_COMMENT)) {
|
DI::contentItem()->postProcessPost($posted_item);
|
||||||
Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']);
|
|
||||||
}
|
|
||||||
Hook::callAll('post_local_end', $posted_item);
|
|
||||||
} else {
|
} else {
|
||||||
Hook::callAll('post_remote_end', $posted_item);
|
Hook::callAll('post_remote_end', $posted_item);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue