Merge pull request #12609 from annando/mod-item
Code cleanup for mod/item.php
This commit is contained in:
commit
f37edc06e1
4 changed files with 539 additions and 733 deletions
834
mod/item.php
834
mod/item.php
|
@ -29,7 +29,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Friendica\App;
|
use Friendica\App;
|
||||||
use Friendica\Content\PageInfo;
|
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
|
@ -38,47 +37,30 @@ 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\Model\Attach;
|
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
use Friendica\Model\Conversation;
|
|
||||||
use Friendica\Model\FileTag;
|
|
||||||
use Friendica\Model\Item;
|
use Friendica\Model\Item;
|
||||||
use Friendica\Model\ItemURI;
|
use Friendica\Model\ItemURI;
|
||||||
use Friendica\Model\Notification;
|
|
||||||
use Friendica\Model\Photo;
|
use Friendica\Model\Photo;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
use Friendica\Model\Tag;
|
|
||||||
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\Security\Security;
|
|
||||||
use Friendica\Util\DateTimeFormat;
|
use Friendica\Util\DateTimeFormat;
|
||||||
use Friendica\Util\ParseUrl;
|
|
||||||
|
|
||||||
function item_post(App $a) {
|
function item_post(App $a) {
|
||||||
if (!DI::userSession()->isAuthenticated()) {
|
$uid = DI::userSession()->getLocalUserId();
|
||||||
|
|
||||||
|
if (!$uid) {
|
||||||
throw new HTTPException\ForbiddenException();
|
throw new HTTPException\ForbiddenException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$uid = DI::userSession()->getLocalUserId();
|
|
||||||
|
|
||||||
if (!empty($_REQUEST['dropitems'])) {
|
if (!empty($_REQUEST['dropitems'])) {
|
||||||
$arr_drop = explode(',', $_REQUEST['dropitems']);
|
item_drop($uid, $_REQUEST['dropitems']);
|
||||||
foreach ($arr_drop as $item) {
|
|
||||||
Item::deleteForUser(['id' => $item], $uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
$json = ['success' => 1];
|
|
||||||
System::jsonExit($json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Hook::callAll('post_local_start', $_REQUEST);
|
Hook::callAll('post_local_start', $_REQUEST);
|
||||||
|
|
||||||
Logger::debug('postvars', ['_REQUEST' => $_REQUEST]);
|
|
||||||
|
|
||||||
$return_path = $_REQUEST['return'] ?? '';
|
$return_path = $_REQUEST['return'] ?? '';
|
||||||
$preview = intval($_REQUEST['preview'] ?? 0);
|
$preview = intval($_REQUEST['preview'] ?? 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check for doubly-submitted posts, and reject duplicates
|
* Check for doubly-submitted posts, and reject duplicates
|
||||||
|
@ -86,48 +68,106 @@ function item_post(App $a) {
|
||||||
* after it's been previewed
|
* after it's been previewed
|
||||||
*/
|
*/
|
||||||
if (!$preview && !empty($_REQUEST['post_id_random'])) {
|
if (!$preview && !empty($_REQUEST['post_id_random'])) {
|
||||||
if (!empty($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) {
|
if (DI::session()->get('post-random') == $_REQUEST['post_id_random']) {
|
||||||
Logger::warning('duplicate post');
|
Logger::warning('duplicate post');
|
||||||
item_post_return(DI::baseUrl(), $return_path);
|
item_post_return(DI::baseUrl(), $return_path);
|
||||||
} else {
|
} else {
|
||||||
$_SESSION['post-random'] = $_REQUEST['post_id_random'];
|
DI::session()->set('post-random', $_REQUEST['post_id_random']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is this a reply to something?
|
if (empty($_REQUEST['post_id'])) {
|
||||||
$parent_item_id = intval($_REQUEST['parent'] ?? 0);
|
item_insert($uid, $_REQUEST, $preview, $return_path);
|
||||||
$thr_parent_uri = trim($_REQUEST['parent_uri'] ?? '');
|
} else {
|
||||||
|
item_edit($uid, $_REQUEST, $preview, $return_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$parent_item = null;
|
function item_drop(int $uid, string $dropitems)
|
||||||
$toplevel_item = null;
|
{
|
||||||
$toplevel_item_id = 0;
|
$arr_drop = explode(',', $dropitems);
|
||||||
$toplevel_user_id = null;
|
foreach ($arr_drop as $item) {
|
||||||
|
Item::deleteForUser(['id' => $item], $uid);
|
||||||
|
}
|
||||||
|
|
||||||
$objecttype = null;
|
System::jsonExit(['success' => 1]);
|
||||||
$profile_uid = DI::userSession()->getLocalUserId();
|
}
|
||||||
$posttype = ($_REQUEST['post_type'] ?? '') ?: Item::PT_ARTICLE;
|
|
||||||
|
|
||||||
if ($parent_item_id || $thr_parent_uri) {
|
function item_edit(int $uid, array $request, bool $preview, string $return_path)
|
||||||
if ($parent_item_id) {
|
{
|
||||||
$parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $parent_item_id]);
|
$post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $request['post_id'], 'uid' => $uid]);
|
||||||
} elseif ($thr_parent_uri) {
|
if (!DBA::isResult($post)) {
|
||||||
$parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['uri' => $thr_parent_uri, 'uid' => $profile_uid]);
|
if ($return_path) {
|
||||||
|
DI::sysmsg()->addNotice(DI::l10n()->t('Unable to locate original post.'));
|
||||||
|
DI::baseUrl()->redirect($return_path);
|
||||||
}
|
}
|
||||||
|
throw new HTTPException\NotFoundException(DI::l10n()->t('Unable to locate original post.'));
|
||||||
|
}
|
||||||
|
|
||||||
// if this isn't the top-level parent of the conversation, find it
|
$post['edit'] = $post;
|
||||||
if (DBA::isResult($parent_item)) {
|
$post['file'] = Post\Category::getTextByURIId($post['uri-id'], $post['uid']);
|
||||||
// The URI and the contact is taken from the direct parent which needn't to be the top parent
|
|
||||||
$thr_parent_uri = $parent_item['uri'];
|
|
||||||
$toplevel_item = $parent_item;
|
|
||||||
|
|
||||||
|
$post = item_process($post, $request, $preview, $return_path);
|
||||||
|
|
||||||
|
$fields = [
|
||||||
|
'title' => $post['title'],
|
||||||
|
'body' => $post['body'],
|
||||||
|
'attach' => $post['attach'],
|
||||||
|
'file' => $post['file'],
|
||||||
|
'location' => $post['location'],
|
||||||
|
'coord' => $post['coord'],
|
||||||
|
'edited' => 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::updateDisplayCache($post['uri-id']);
|
||||||
|
|
||||||
|
if ($return_path) {
|
||||||
|
DI::baseUrl()->redirect($return_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HTTPException\OKException(DI::l10n()->t('Post updated.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function item_insert(int $uid, array $request, bool $preview, string $return_path)
|
||||||
|
{
|
||||||
|
$post = ['uid' => $uid];
|
||||||
|
$post = DI::contentItem()->initializePost($post);
|
||||||
|
|
||||||
|
$post['edit'] = null;
|
||||||
|
$post['post-type'] = $request['post_type'] ?? '';
|
||||||
|
$post['wall'] = $request['wall'] ?? true;
|
||||||
|
$post['pubmail'] = $request['pubmail_enable'] ?? false;
|
||||||
|
$post['created'] = $request['created_at'] ?? DateTimeFormat::utcNow();
|
||||||
|
$post['edited'] = $post['changed'] = $post['commented'] = $post['created'];
|
||||||
|
$post['app'] = '';
|
||||||
|
$post['inform'] = '';
|
||||||
|
$post['postopts'] = '';
|
||||||
|
$post['file'] = '';
|
||||||
|
|
||||||
|
if (!empty($request['parent'])) {
|
||||||
|
$parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $request['parent']]);
|
||||||
|
if ($parent_item) {
|
||||||
|
// if this isn't the top-level parent of the conversation, find it
|
||||||
if ($parent_item['gravity'] != Item::GRAVITY_PARENT) {
|
if ($parent_item['gravity'] != Item::GRAVITY_PARENT) {
|
||||||
$toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $toplevel_item['parent']]);
|
$toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $parent_item['parent']]);
|
||||||
|
} else {
|
||||||
|
$toplevel_item = $parent_item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DBA::isResult($toplevel_item)) {
|
if (empty($toplevel_item)) {
|
||||||
DI::sysmsg()->addNotice(DI::l10n()->t('Unable to locate original post.'));
|
|
||||||
if ($return_path) {
|
if ($return_path) {
|
||||||
|
DI::sysmsg()->addNotice(DI::l10n()->t('Unable to locate original post.'));
|
||||||
DI::baseUrl()->redirect($return_path);
|
DI::baseUrl()->redirect($return_path);
|
||||||
}
|
}
|
||||||
throw new HTTPException\NotFoundException(DI::l10n()->t('Unable to locate original post.'));
|
throw new HTTPException\NotFoundException(DI::l10n()->t('Unable to locate original post.'));
|
||||||
|
@ -136,561 +176,37 @@ function item_post(App $a) {
|
||||||
// When commenting on a public post then store the post for the current user
|
// When commenting on a public post then store the post for the current user
|
||||||
// This enables interaction like starring and saving into folders
|
// This enables interaction like starring and saving into folders
|
||||||
if ($toplevel_item['uid'] == 0) {
|
if ($toplevel_item['uid'] == 0) {
|
||||||
$stored = Item::storeForUserByUriId($toplevel_item['uri-id'], DI::userSession()->getLocalUserId(), ['post-reason' => Item::PR_ACTIVITY]);
|
$stored = Item::storeForUserByUriId($toplevel_item['uri-id'], $post['uid'], ['post-reason' => Item::PR_ACTIVITY]);
|
||||||
Logger::info('Public item stored for user', ['uri-id' => $toplevel_item['uri-id'], 'uid' => $uid, 'stored' => $stored]);
|
Logger::info('Public item stored for user', ['uri-id' => $toplevel_item['uri-id'], 'uid' => $post['uid'], 'stored' => $stored]);
|
||||||
if ($stored) {
|
|
||||||
$toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $stored]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$toplevel_item_id = $toplevel_item['id'];
|
$post['gravity'] = Item::GRAVITY_COMMENT;
|
||||||
$toplevel_user_id = $toplevel_item['uid'];
|
$post['thr-parent'] = $parent_item['uri'];
|
||||||
|
$post['wall'] = $toplevel_item['wall'];
|
||||||
$objecttype = Activity\ObjectType::COMMENT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($toplevel_item_id) {
|
|
||||||
Logger::info('mod_item: item_post', ['parent' => $toplevel_item_id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$post_id = intval($_REQUEST['post_id'] ?? 0);
|
|
||||||
$app = strip_tags($_REQUEST['source'] ?? '');
|
|
||||||
$extid = strip_tags($_REQUEST['extid'] ?? '');
|
|
||||||
$object = $_REQUEST['object'] ?? '';
|
|
||||||
|
|
||||||
// Don't use "defaults" here. It would turn 0 to 1
|
|
||||||
if (!isset($_REQUEST['wall'])) {
|
|
||||||
$wall = 1;
|
|
||||||
} else {
|
} else {
|
||||||
$wall = $_REQUEST['wall'];
|
$parent_item = [];
|
||||||
|
$post['gravity'] = Item::GRAVITY_PARENT;
|
||||||
|
$post['thr-parent'] = $post['uri'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the user id in a thread always stay the same
|
$post = DI::contentItem()->getACL($post, $parent_item, $request);
|
||||||
if (!is_null($toplevel_user_id) && in_array($toplevel_user_id, [DI::userSession()->getLocalUserId(), 0])) {
|
|
||||||
$profile_uid = $toplevel_user_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow commenting if it is an answer to a public post
|
$post['pubmail'] = $post['pubmail'] && !$post['private'];
|
||||||
$allow_comment = DI::userSession()->getLocalUserId() && $toplevel_item_id && in_array($toplevel_item['private'], [Item::PUBLIC, Item::UNLISTED]) && in_array($toplevel_item['network'], Protocol::FEDERATED);
|
|
||||||
|
|
||||||
// Now check that valid personal details have been provided
|
$post = item_process($post, $request, $preview, $return_path);
|
||||||
if (!Security::canWriteToUserWall($profile_uid) && !$allow_comment) {
|
|
||||||
Logger::warning('Permission denied.', ['local' => DI::userSession()->getLocalUserId(), 'toplevel_item_id' => $toplevel_item_id, 'network' => $toplevel_item['network']]);
|
|
||||||
DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
|
|
||||||
if ($return_path) {
|
|
||||||
DI::baseUrl()->redirect($return_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init post instance
|
|
||||||
$orig_post = null;
|
|
||||||
|
|
||||||
// is this an edited post?
|
|
||||||
if ($post_id > 0) {
|
|
||||||
$orig_post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = User::getById($profile_uid, ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);
|
|
||||||
if (!DBA::isResult($user) && !$toplevel_item_id) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
$categories = '';
|
|
||||||
$postopts = '';
|
|
||||||
$emailcc = '';
|
|
||||||
$body = $_REQUEST['body'] ?? '';
|
|
||||||
$has_attachment = $_REQUEST['has_attachment'] ?? 0;
|
|
||||||
|
|
||||||
// If we have a speparate attachment, we need to add it to the body.
|
|
||||||
if (!empty($has_attachment)) {
|
|
||||||
$attachment_type = $_REQUEST['attachment_type'] ?? '';
|
|
||||||
$attachment_title = $_REQUEST['attachment_title'] ?? '';
|
|
||||||
$attachment_text = $_REQUEST['attachment_text'] ?? '';
|
|
||||||
|
|
||||||
$attachment_url = hex2bin($_REQUEST['attachment_url'] ?? '');
|
|
||||||
$attachment_img_src = hex2bin($_REQUEST['attachment_img_src'] ?? '');
|
|
||||||
|
|
||||||
$attachment_img_width = $_REQUEST['attachment_img_width'] ?? 0;
|
|
||||||
$attachment_img_height = $_REQUEST['attachment_img_height'] ?? 0;
|
|
||||||
|
|
||||||
// Fetch the basic attachment data
|
|
||||||
$attachment = ParseUrl::getSiteinfoCached($attachment_url);
|
|
||||||
unset($attachment['keywords']);
|
|
||||||
|
|
||||||
// Overwrite the basic data with possible changes from the frontend
|
|
||||||
$attachment['type'] = $attachment_type;
|
|
||||||
$attachment['title'] = $attachment_title;
|
|
||||||
$attachment['text'] = $attachment_text;
|
|
||||||
$attachment['url'] = $attachment_url;
|
|
||||||
|
|
||||||
if (!empty($attachment_img_src)) {
|
|
||||||
$attachment['images'] = [
|
|
||||||
0 => [
|
|
||||||
'src' => $attachment_img_src,
|
|
||||||
'width' => $attachment_img_width,
|
|
||||||
'height' => $attachment_img_height
|
|
||||||
]
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
unset($attachment['images']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$att_bbcode = "\n" . PageInfo::getFooterFromData($attachment);
|
|
||||||
$body .= $att_bbcode;
|
|
||||||
} elseif (preg_match("/\[attachment\](.*?)\[\/attachment\]/ism", $body, $matches)) {
|
|
||||||
$body = preg_replace("/\[attachment].*?\[\/attachment\]/ism", PageInfo::getFooterFromUrl($matches[1]), $body);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert links with empty descriptions to links without an explicit description
|
|
||||||
$body = preg_replace('#\[url=([^\]]*?)\]\[/url\]#ism', '[url]$1[/url]', $body);
|
|
||||||
|
|
||||||
if (!empty($orig_post)) {
|
|
||||||
$str_group_allow = $orig_post['allow_gid'];
|
|
||||||
$str_contact_allow = $orig_post['allow_cid'];
|
|
||||||
$str_group_deny = $orig_post['deny_gid'];
|
|
||||||
$str_contact_deny = $orig_post['deny_cid'];
|
|
||||||
$location = $orig_post['location'];
|
|
||||||
$coord = $orig_post['coord'];
|
|
||||||
$verb = $orig_post['verb'];
|
|
||||||
$objecttype = $orig_post['object-type'];
|
|
||||||
$app = $orig_post['app'];
|
|
||||||
$categories = Post\Category::getTextByURIId($orig_post['uri-id'], $orig_post['uid']);
|
|
||||||
$title = trim($_REQUEST['title'] ?? '');
|
|
||||||
$body = trim($body);
|
|
||||||
$private = $orig_post['private'];
|
|
||||||
$pubmail_enabled = $orig_post['pubmail'];
|
|
||||||
$network = $orig_post['network'];
|
|
||||||
$guid = $orig_post['guid'];
|
|
||||||
$extid = $orig_post['extid'];
|
|
||||||
} else {
|
|
||||||
$aclFormatter = DI::aclFormatter();
|
|
||||||
$str_contact_allow = isset($_REQUEST['contact_allow']) ? $aclFormatter->toString($_REQUEST['contact_allow']) : $user['allow_cid'] ?? '';
|
|
||||||
$str_group_allow = isset($_REQUEST['group_allow']) ? $aclFormatter->toString($_REQUEST['group_allow']) : $user['allow_gid'] ?? '';
|
|
||||||
$str_contact_deny = isset($_REQUEST['contact_deny']) ? $aclFormatter->toString($_REQUEST['contact_deny']) : $user['deny_cid'] ?? '';
|
|
||||||
$str_group_deny = isset($_REQUEST['group_deny']) ? $aclFormatter->toString($_REQUEST['group_deny']) : $user['deny_gid'] ?? '';
|
|
||||||
|
|
||||||
$visibility = $_REQUEST['visibility'] ?? '';
|
|
||||||
if ($visibility === 'public') {
|
|
||||||
// The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
|
|
||||||
$str_contact_allow = $str_group_allow = $str_contact_deny = $str_group_deny = '';
|
|
||||||
} else if ($visibility === 'custom') {
|
|
||||||
// Since we know from the visibility parameter the item should be private, we have to prevent the empty ACL
|
|
||||||
// case that would make it public. So we always append the author's contact id to the allowed contacts.
|
|
||||||
// See https://github.com/friendica/friendica/issues/9672
|
|
||||||
$str_contact_allow .= $aclFormatter->toString(Contact::getPublicIdByUserId($uid));
|
|
||||||
}
|
|
||||||
|
|
||||||
$title = trim($_REQUEST['title'] ?? '');
|
|
||||||
$location = trim($_REQUEST['location'] ?? '');
|
|
||||||
$coord = trim($_REQUEST['coord'] ?? '');
|
|
||||||
$verb = trim($_REQUEST['verb'] ?? '');
|
|
||||||
$emailcc = trim($_REQUEST['emailcc'] ?? '');
|
|
||||||
$body = trim($body);
|
|
||||||
$network = trim(($_REQUEST['network'] ?? '') ?: Protocol::DFRN);
|
|
||||||
$guid = System::createUUID();
|
|
||||||
|
|
||||||
$postopts = $_REQUEST['postopts'] ?? '';
|
|
||||||
|
|
||||||
if (strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) {
|
|
||||||
$private = Item::PRIVATE;
|
|
||||||
} elseif (DI::pConfig()->get($profile_uid, 'system', 'unlisted')) {
|
|
||||||
$private = Item::UNLISTED;
|
|
||||||
} else {
|
|
||||||
$private = Item::PUBLIC;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this is a comment, set the permissions from the parent.
|
|
||||||
|
|
||||||
if ($toplevel_item) {
|
|
||||||
// for non native networks use the network of the original post as network of the item
|
|
||||||
if (($toplevel_item['network'] != Protocol::DIASPORA)
|
|
||||||
&& ($toplevel_item['network'] != Protocol::OSTATUS)
|
|
||||||
&& ($network == '')) {
|
|
||||||
$network = $toplevel_item['network'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$str_contact_allow = $toplevel_item['allow_cid'] ?? '';
|
|
||||||
$str_group_allow = $toplevel_item['allow_gid'] ?? '';
|
|
||||||
$str_contact_deny = $toplevel_item['deny_cid'] ?? '';
|
|
||||||
$str_group_deny = $toplevel_item['deny_gid'] ?? '';
|
|
||||||
$private = $toplevel_item['private'];
|
|
||||||
|
|
||||||
$wall = $toplevel_item['wall'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$pubmail_enabled = ($_REQUEST['pubmail_enable'] ?? false) && !$private;
|
|
||||||
|
|
||||||
if (!strlen($body)) {
|
|
||||||
if ($preview) {
|
|
||||||
System::jsonExit(['preview' => '']);
|
|
||||||
}
|
|
||||||
|
|
||||||
DI::sysmsg()->addNotice(DI::l10n()->t('Empty post discarded.'));
|
|
||||||
if ($return_path) {
|
|
||||||
DI::baseUrl()->redirect($return_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new HTTPException\BadRequestException(DI::l10n()->t('Empty post discarded.'));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($categories)) {
|
|
||||||
// get the "fileas" tags for this post
|
|
||||||
$filedas = FileTag::fileToArray($categories);
|
|
||||||
}
|
|
||||||
|
|
||||||
$list_array = explode(',', trim($_REQUEST['category'] ?? ''));
|
|
||||||
$categories = FileTag::arrayToFile($list_array, 'category');
|
|
||||||
|
|
||||||
if (!empty($filedas) && is_array($filedas)) {
|
|
||||||
// append the fileas stuff to the new categories list
|
|
||||||
$categories .= FileTag::arrayToFile($filedas);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get contact info for poster
|
|
||||||
|
|
||||||
$author = null;
|
|
||||||
$self = false;
|
|
||||||
$contact_id = 0;
|
|
||||||
|
|
||||||
if (DI::userSession()->getLocalUserId() && ((DI::userSession()->getLocalUserId() == $profile_uid) || $allow_comment)) {
|
|
||||||
$self = true;
|
|
||||||
$author = DBA::selectFirst('contact', [], ['uid' => DI::userSession()->getLocalUserId(), 'self' => true]);
|
|
||||||
} elseif (!empty(DI::userSession()->getRemoteContactID($profile_uid))) {
|
|
||||||
$author = DBA::selectFirst('contact', [], ['id' => DI::userSession()->getRemoteContactID($profile_uid)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DBA::isResult($author)) {
|
|
||||||
$contact_id = $author['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// get contact info for owner
|
|
||||||
if ($profile_uid == DI::userSession()->getLocalUserId() || $allow_comment) {
|
|
||||||
$contact_record = $author ?: [];
|
|
||||||
} else {
|
|
||||||
$contact_record = DBA::selectFirst('contact', [], ['uid' => $profile_uid, 'self' => true]) ?: [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Personal notes must never be altered to a forum post.
|
|
||||||
if ($posttype != Item::PT_PERSONAL_NOTE) {
|
|
||||||
// Look for any tags and linkify them
|
|
||||||
$item = [
|
|
||||||
'uid' => DI::userSession()->getLocalUserId() ? DI::userSession()->getLocalUserId() : $profile_uid,
|
|
||||||
'gravity' => $toplevel_item_id ? Item::GRAVITY_COMMENT : Item::GRAVITY_PARENT,
|
|
||||||
'network' => $network,
|
|
||||||
'body' => $body,
|
|
||||||
'postopts' => $postopts,
|
|
||||||
'private' => $private,
|
|
||||||
'allow_cid' => $str_contact_allow,
|
|
||||||
'allow_gid' => $str_group_allow,
|
|
||||||
'deny_cid' => $str_contact_deny,
|
|
||||||
'deny_gid' => $str_group_deny,
|
|
||||||
];
|
|
||||||
|
|
||||||
$item = DI::contentItem()->expandTags($item);
|
|
||||||
|
|
||||||
$body = $item['body'];
|
|
||||||
$inform = $item['inform'];
|
|
||||||
$postopts = $item['postopts'];
|
|
||||||
$private = $item['private'];
|
|
||||||
$str_contact_allow = $item['allow_cid'];
|
|
||||||
$str_group_allow = $item['allow_gid'];
|
|
||||||
$str_contact_deny = $item['deny_cid'];
|
|
||||||
$str_group_deny = $item['deny_gid'];
|
|
||||||
} else {
|
|
||||||
$inform = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* When a photo was uploaded into the message using the (profile wall) ajax
|
|
||||||
* uploader, The permissions are initially set to disallow anybody but the
|
|
||||||
* owner from seeing it. This is because the permissions may not yet have been
|
|
||||||
* set for the post. If it's private, the photo permissions should be set
|
|
||||||
* appropriately. But we didn't know the final permissions on the post until
|
|
||||||
* now. So now we'll look for links of uploaded messages that are in the
|
|
||||||
* post and set them to the same permissions as the post itself.
|
|
||||||
*/
|
|
||||||
|
|
||||||
$match = null;
|
|
||||||
|
|
||||||
if (!$preview && Photo::setPermissionFromBody($body, $uid, $contact_id, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny)) {
|
|
||||||
$objecttype = Activity\ObjectType::IMAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Next link in any attachment references we find in the post.
|
|
||||||
*/
|
|
||||||
$match = [];
|
|
||||||
|
|
||||||
/// @todo these lines should be moved to Model/Attach (Once it exists)
|
|
||||||
if (!$preview && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/", $body, $match)) {
|
|
||||||
$attaches = $match[1];
|
|
||||||
if (count($attaches)) {
|
|
||||||
foreach ($attaches as $attach) {
|
|
||||||
// Ensure to only modify attachments that you own
|
|
||||||
$srch = '<' . intval($contact_id) . '>';
|
|
||||||
|
|
||||||
$condition = [
|
|
||||||
'allow_cid' => $srch,
|
|
||||||
'allow_gid' => '',
|
|
||||||
'deny_cid' => '',
|
|
||||||
'deny_gid' => '',
|
|
||||||
'id' => $attach,
|
|
||||||
];
|
|
||||||
if (!Attach::exists($condition)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$fields = ['allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow,
|
|
||||||
'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny];
|
|
||||||
$condition = ['id' => $attach];
|
|
||||||
Attach::update($fields, $condition);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// embedded bookmark or attachment in post? set bookmark flag
|
|
||||||
|
|
||||||
$data = BBCode::getAttachmentData($body);
|
|
||||||
$match = [];
|
|
||||||
if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) || isset($data['type']))
|
|
||||||
&& ($posttype != Item::PT_PERSONAL_NOTE)) {
|
|
||||||
$posttype = Item::PT_PAGE;
|
|
||||||
$objecttype = Activity\ObjectType::BOOKMARK;
|
|
||||||
}
|
|
||||||
|
|
||||||
$body = DI::bbCodeVideo()->transform($body);
|
|
||||||
|
|
||||||
$body = BBCode::scaleExternalImages($body);
|
|
||||||
|
|
||||||
// Setting the object type if not defined before
|
|
||||||
if (!$objecttype) {
|
|
||||||
$objecttype = Activity\ObjectType::NOTE; // Default value
|
|
||||||
$objectdata = BBCode::getAttachedData($body);
|
|
||||||
|
|
||||||
if ($objectdata['type'] == 'link') {
|
|
||||||
$objecttype = Activity\ObjectType::BOOKMARK;
|
|
||||||
} elseif ($objectdata['type'] == 'video') {
|
|
||||||
$objecttype = Activity\ObjectType::VIDEO;
|
|
||||||
} elseif ($objectdata['type'] == 'photo') {
|
|
||||||
$objecttype = Activity\ObjectType::IMAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$attachments = '';
|
|
||||||
$match = [];
|
|
||||||
|
|
||||||
if (preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$body,$match)) {
|
|
||||||
foreach ($match[2] as $mtch) {
|
|
||||||
$fields = ['id', 'filename', 'filesize', 'filetype'];
|
|
||||||
$attachment = Attach::selectFirst($fields, ['id' => $mtch]);
|
|
||||||
if ($attachment !== false) {
|
|
||||||
if (strlen($attachments)) {
|
|
||||||
$attachments .= ',';
|
|
||||||
}
|
|
||||||
$attachments .= Post\Media::getAttachElement(DI::baseUrl() . '/attach/' . $attachment['id'],
|
|
||||||
$attachment['filesize'], $attachment['filetype'], $attachment['filename'] ?? '');
|
|
||||||
}
|
|
||||||
$body = str_replace($match[1],'',$body);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strlen($verb)) {
|
|
||||||
$verb = Activity::POST;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($network == '') {
|
|
||||||
$network = Protocol::DFRN;
|
|
||||||
}
|
|
||||||
|
|
||||||
$gravity = ($toplevel_item_id ? Item::GRAVITY_COMMENT : Item::GRAVITY_PARENT);
|
|
||||||
|
|
||||||
// even if the post arrived via API we are considering that it
|
|
||||||
// originated on this site by default for determining relayability.
|
|
||||||
|
|
||||||
// Don't use "defaults" here. It would turn 0 to 1
|
|
||||||
if (!isset($_REQUEST['origin'])) {
|
|
||||||
$origin = 1;
|
|
||||||
} else {
|
|
||||||
$origin = $_REQUEST['origin'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$uri = Item::newURI($guid);
|
|
||||||
|
|
||||||
// Fallback so that we alway have a parent uri
|
|
||||||
if (!$thr_parent_uri || !$toplevel_item_id) {
|
|
||||||
$thr_parent_uri = $uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
$datarray = [
|
|
||||||
'uid' => $profile_uid,
|
|
||||||
'wall' => $wall,
|
|
||||||
'gravity' => $gravity,
|
|
||||||
'network' => $network,
|
|
||||||
'contact-id' => $contact_id,
|
|
||||||
'owner-name' => $contact_record['name'] ?? '',
|
|
||||||
'owner-link' => $contact_record['url'] ?? '',
|
|
||||||
'owner-avatar' => $contact_record['thumb'] ?? '',
|
|
||||||
'author-name' => $author['name'],
|
|
||||||
'author-link' => $author['url'],
|
|
||||||
'author-avatar' => $author['thumb'],
|
|
||||||
'created' => empty($_REQUEST['created_at']) ? DateTimeFormat::utcNow() : $_REQUEST['created_at'],
|
|
||||||
'received' => DateTimeFormat::utcNow(),
|
|
||||||
'extid' => $extid,
|
|
||||||
'guid' => $guid,
|
|
||||||
'uri' => $uri,
|
|
||||||
'title' => $title,
|
|
||||||
'body' => $body,
|
|
||||||
'app' => $app,
|
|
||||||
'location' => $location,
|
|
||||||
'coord' => $coord,
|
|
||||||
'file' => $categories,
|
|
||||||
'inform' => $inform,
|
|
||||||
'verb' => $verb,
|
|
||||||
'post-type' => $posttype,
|
|
||||||
'object-type' => $objecttype,
|
|
||||||
'allow_cid' => $str_contact_allow,
|
|
||||||
'allow_gid' => $str_group_allow,
|
|
||||||
'deny_cid' => $str_contact_deny,
|
|
||||||
'deny_gid' => $str_group_deny,
|
|
||||||
'private' => $private,
|
|
||||||
'pubmail' => $pubmail_enabled,
|
|
||||||
'attach' => $attachments,
|
|
||||||
'thr-parent' => $thr_parent_uri,
|
|
||||||
'postopts' => $postopts,
|
|
||||||
'origin' => $origin,
|
|
||||||
'object' => $object,
|
|
||||||
'attachments' => $_REQUEST['attachments'] ?? [],
|
|
||||||
/*
|
|
||||||
* These fields are for the convenience of addons...
|
|
||||||
* 'self' if true indicates the owner is posting on their own wall
|
|
||||||
* If parent is 0 it is a top-level post.
|
|
||||||
*/
|
|
||||||
'parent' => $toplevel_item_id,
|
|
||||||
'self' => $self,
|
|
||||||
// This triggers posts via API and the mirror functions
|
|
||||||
'api_source' => false,
|
|
||||||
// This field is for storing the raw conversation data
|
|
||||||
'protocol' => Conversation::PARCEL_DIRECT,
|
|
||||||
'direction' => Conversation::PUSH,
|
|
||||||
];
|
|
||||||
|
|
||||||
// These cannot be part of above initialization ...
|
|
||||||
$datarray['edited'] = $datarray['created'];
|
|
||||||
$datarray['commented'] = $datarray['created'];
|
|
||||||
$datarray['changed'] = $datarray['created'];
|
|
||||||
$datarray['owner-id'] = Contact::getIdForURL($datarray['owner-link']);
|
|
||||||
$datarray['author-id'] = Contact::getIdForURL($datarray['author-link']);
|
|
||||||
|
|
||||||
$datarray['edit'] = $orig_post;
|
|
||||||
|
|
||||||
// Check for hashtags in the body and repair or add hashtag links
|
|
||||||
if ($preview || $orig_post) {
|
|
||||||
$datarray['body'] = Item::setHashtags($datarray['body']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// preview mode - prepare the body for display and send it via json
|
|
||||||
if ($preview) {
|
|
||||||
// We set the datarray ID to -1 because in preview mode the dataray
|
|
||||||
// doesn't have an ID.
|
|
||||||
$datarray['id'] = -1;
|
|
||||||
$datarray['uri-id'] = -1;
|
|
||||||
$datarray['author-network'] = Protocol::DFRN;
|
|
||||||
$datarray['author-updated'] = '';
|
|
||||||
$datarray['author-gsid'] = 0;
|
|
||||||
$datarray['author-uri-id'] = ItemURI::getIdByURI($datarray['author-link']);
|
|
||||||
$datarray['owner-updated'] = '';
|
|
||||||
$datarray['has-media'] = false;
|
|
||||||
$datarray['quote-uri-id'] = Item::getQuoteUriId($datarray['body'], $datarray['uid']);
|
|
||||||
$datarray['body'] = BBCode::removeSharedData($datarray['body']);
|
|
||||||
|
|
||||||
$o = DI::conversation()->create([array_merge($contact_record, $datarray)], 'search', false, true);
|
|
||||||
|
|
||||||
System::jsonExit(['preview' => $o]);
|
|
||||||
}
|
|
||||||
|
|
||||||
Hook::callAll('post_local',$datarray);
|
|
||||||
|
|
||||||
if (!empty($_REQUEST['scheduled_at'])) {
|
|
||||||
$scheduled_at = DateTimeFormat::convert($_REQUEST['scheduled_at'], 'UTC', $a->getTimeZone());
|
|
||||||
if ($scheduled_at > DateTimeFormat::utcNow()) {
|
|
||||||
unset($datarray['created']);
|
|
||||||
unset($datarray['edited']);
|
|
||||||
unset($datarray['commented']);
|
|
||||||
unset($datarray['received']);
|
|
||||||
unset($datarray['changed']);
|
|
||||||
unset($datarray['edit']);
|
|
||||||
unset($datarray['self']);
|
|
||||||
unset($datarray['api_source']);
|
|
||||||
|
|
||||||
Post\Delayed::add($datarray['uri'], $datarray, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED_NO_HOOK, $scheduled_at);
|
|
||||||
item_post_return(DI::baseUrl(), $return_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($datarray['cancel'])) {
|
|
||||||
Logger::info('mod_item: post cancelled by addon.');
|
|
||||||
if ($return_path) {
|
|
||||||
DI::baseUrl()->redirect($return_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
$json = ['cancel' => 1];
|
|
||||||
if (!empty($_REQUEST['jsreload'])) {
|
|
||||||
$json['reload'] = DI::baseUrl() . '/' . $_REQUEST['jsreload'];
|
|
||||||
}
|
|
||||||
|
|
||||||
System::jsonExit($json);
|
|
||||||
}
|
|
||||||
|
|
||||||
$datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']);
|
|
||||||
|
|
||||||
$quote_uri_id = Item::getQuoteUriId($datarray['body'], $datarray['uid']);
|
|
||||||
if (!empty($quote_uri_id)) {
|
|
||||||
$datarray['quote-uri-id'] = $quote_uri_id;
|
|
||||||
$datarray['body'] = BBCode::removeSharedData($datarray['body']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($orig_post) {
|
|
||||||
$fields = [
|
|
||||||
'title' => $datarray['title'],
|
|
||||||
'body' => $datarray['body'],
|
|
||||||
'attach' => $datarray['attach'],
|
|
||||||
'file' => $datarray['file'],
|
|
||||||
'edited' => DateTimeFormat::utcNow(),
|
|
||||||
'changed' => DateTimeFormat::utcNow()
|
|
||||||
];
|
|
||||||
|
|
||||||
Item::update($fields, ['id' => $post_id]);
|
|
||||||
Item::updateDisplayCache($datarray['uri-id']);
|
|
||||||
|
|
||||||
if ($return_path) {
|
|
||||||
DI::baseUrl()->redirect($return_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new HTTPException\OKException(DI::l10n()->t('Post updated.'));
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($datarray['edit']);
|
|
||||||
unset($datarray['self']);
|
|
||||||
unset($datarray['api_source']);
|
|
||||||
|
|
||||||
$post_id = Item::insert($datarray);
|
|
||||||
|
|
||||||
|
$post_id = Item::insert($post);
|
||||||
if (!$post_id) {
|
if (!$post_id) {
|
||||||
DI::sysmsg()->addNotice(DI::l10n()->t('Item wasn\'t stored.'));
|
|
||||||
if ($return_path) {
|
if ($return_path) {
|
||||||
|
DI::sysmsg()->addNotice(DI::l10n()->t('Item wasn\'t stored.'));
|
||||||
DI::baseUrl()->redirect($return_path);
|
DI::baseUrl()->redirect($return_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item wasn\'t stored.'));
|
throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item wasn\'t stored.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$datarray = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]);
|
$post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]);
|
||||||
|
if (!$post) {
|
||||||
if (!DBA::isResult($datarray)) {
|
|
||||||
Logger::error('Item couldn\'t be fetched.', ['post_id' => $post_id]);
|
Logger::error('Item couldn\'t be fetched.', ['post_id' => $post_id]);
|
||||||
if ($return_path) {
|
if ($return_path) {
|
||||||
DI::baseUrl()->redirect($return_path);
|
DI::baseUrl()->redirect($return_path);
|
||||||
|
@ -699,52 +215,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.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
Tag::storeFromBody($datarray['uri-id'], $datarray['body']);
|
$recipients = explode(',', $request['emailcc'] ?? '');
|
||||||
|
|
||||||
if (!\Friendica\Content\Feature::isEnabled($uid, 'explicit_mentions') && ($datarray['gravity'] == Item::GRAVITY_COMMENT)) {
|
DI::contentItem()->postProcessPost($post, $recipients);
|
||||||
Tag::createImplicitMentions($datarray['uri-id'], $datarray['thr-parent-id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// These notifications are sent if someone else is commenting other your wall
|
|
||||||
if ($contact_record != $author) {
|
|
||||||
if ($toplevel_item_id) {
|
|
||||||
DI::notify()->createFromArray([
|
|
||||||
'type' => Notification\Type::COMMENT,
|
|
||||||
'otype' => Notification\ObjectType::ITEM,
|
|
||||||
'verb' => Activity::POST,
|
|
||||||
'uid' => $profile_uid,
|
|
||||||
'cid' => $datarray['author-id'],
|
|
||||||
'item' => $datarray,
|
|
||||||
'link' => DI::baseUrl() . '/display/' . urlencode($datarray['guid']),
|
|
||||||
]);
|
|
||||||
} elseif (empty($forum_contact)) {
|
|
||||||
DI::notify()->createFromArray([
|
|
||||||
'type' => Notification\Type::WALL,
|
|
||||||
'otype' => Notification\ObjectType::ITEM,
|
|
||||||
'verb' => Activity::POST,
|
|
||||||
'uid' => $profile_uid,
|
|
||||||
'cid' => $datarray['author-id'],
|
|
||||||
'item' => $datarray,
|
|
||||||
'link' => DI::baseUrl() . '/display/' . urlencode($datarray['guid']),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Hook::callAll('post_local_end', $datarray);
|
|
||||||
|
|
||||||
if (strlen($emailcc) && $profile_uid == DI::userSession()->getLocalUserId()) {
|
|
||||||
$recipients = explode(',', $emailcc);
|
|
||||||
if (count($recipients)) {
|
|
||||||
foreach ($recipients as $recipient) {
|
|
||||||
$address = trim($recipient);
|
|
||||||
if (!strlen($address)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
DI::emailer()->send(new ItemCCEMail(DI::app(), DI::l10n(), DI::baseUrl(),
|
|
||||||
$datarray, $address, $author['thumb'] ?? ''));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger::debug('post_complete');
|
Logger::debug('post_complete');
|
||||||
|
|
||||||
|
@ -752,6 +225,103 @@ function item_post(App $a) {
|
||||||
// NOTREACHED
|
// NOTREACHED
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function item_process(array $post, array $request, bool $preview, string $return_path): array
|
||||||
|
{
|
||||||
|
$post['self'] = true;
|
||||||
|
$post['api_source'] = false;
|
||||||
|
$post['attach'] = '';
|
||||||
|
$post['title'] = trim($request['title'] ?? '');
|
||||||
|
$post['body'] = $request['body'] ?? '';
|
||||||
|
$post['location'] = trim($request['location'] ?? '');
|
||||||
|
$post['coord'] = trim($request['coord'] ?? '');
|
||||||
|
|
||||||
|
$post = DI::contentItem()->addCategories($post, $request['category'] ?? '');
|
||||||
|
|
||||||
|
if (!$preview) {
|
||||||
|
if (Photo::setPermissionFromBody($post['body'], $post['uid'], $post['contact-id'], $post['allow_cid'], $post['allow_gid'], $post['deny_cid'], $post['deny_gid'])) {
|
||||||
|
$post['object-type'] = Activity\ObjectType::IMAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
$post = DI::contentItem()->moveAttachmentsFromBodyToAttach($post);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the attachment to the body.
|
||||||
|
if (!empty($request['has_attachment'])) {
|
||||||
|
$post['body'] .= DI::contentItem()->storeAttachmentFromRequest($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
$post = DI::contentItem()->finalizePost($post);
|
||||||
|
|
||||||
|
if (!strlen($post['body'])) {
|
||||||
|
if ($preview) {
|
||||||
|
System::jsonExit(['preview' => '']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($return_path) {
|
||||||
|
DI::sysmsg()->addNotice(DI::l10n()->t('Empty post discarded.'));
|
||||||
|
DI::baseUrl()->redirect($return_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HTTPException\BadRequestException(DI::l10n()->t('Empty post discarded.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// preview mode - prepare the body for display and send it via json
|
||||||
|
if ($preview) {
|
||||||
|
// We have to preset some fields, so that the conversation can be displayed
|
||||||
|
$post['id'] = -1;
|
||||||
|
$post['uri-id'] = -1;
|
||||||
|
$post['author-network'] = Protocol::DFRN;
|
||||||
|
$post['author-updated'] = '';
|
||||||
|
$post['author-gsid'] = 0;
|
||||||
|
$post['author-uri-id'] = ItemURI::getIdByURI($post['author-link']);
|
||||||
|
$post['owner-updated'] = '';
|
||||||
|
$post['has-media'] = false;
|
||||||
|
$post['quote-uri-id'] = Item::getQuoteUriId($post['body'], $post['uid']);
|
||||||
|
$post['body'] = BBCode::removeSharedData(Item::setHashtags($post['body']));
|
||||||
|
$post['writable'] = true;
|
||||||
|
|
||||||
|
$o = DI::conversation()->create([$post], 'search', false, true);
|
||||||
|
|
||||||
|
System::jsonExit(['preview' => $o]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Hook::callAll('post_local',$post);
|
||||||
|
|
||||||
|
unset($post['edit']);
|
||||||
|
unset($post['self']);
|
||||||
|
unset($post['api_source']);
|
||||||
|
|
||||||
|
if (!empty($request['scheduled_at'])) {
|
||||||
|
$scheduled_at = DateTimeFormat::convert($request['scheduled_at'], 'UTC', DI::app()->getTimeZone());
|
||||||
|
if ($scheduled_at > DateTimeFormat::utcNow()) {
|
||||||
|
unset($post['created']);
|
||||||
|
unset($post['edited']);
|
||||||
|
unset($post['commented']);
|
||||||
|
unset($post['received']);
|
||||||
|
unset($post['changed']);
|
||||||
|
|
||||||
|
Post\Delayed::add($post['uri'], $post, Worker::PRIORITY_HIGH, Post\Delayed::PREPARED_NO_HOOK, $scheduled_at);
|
||||||
|
item_post_return(DI::baseUrl(), $return_path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($post['cancel'])) {
|
||||||
|
Logger::info('mod_item: post cancelled by addon.');
|
||||||
|
if ($return_path) {
|
||||||
|
DI::baseUrl()->redirect($return_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = ['cancel' => 1];
|
||||||
|
if (!empty($request['jsreload'])) {
|
||||||
|
$json['reload'] = DI::baseUrl() . '/' . $request['jsreload'];
|
||||||
|
}
|
||||||
|
|
||||||
|
System::jsonExit($json);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
function item_post_return($baseurl, $return_path)
|
function item_post_return($baseurl, $return_path)
|
||||||
{
|
{
|
||||||
if ($return_path) {
|
if ($return_path) {
|
||||||
|
|
|
@ -21,22 +21,36 @@
|
||||||
|
|
||||||
namespace Friendica\Content;
|
namespace Friendica\Content;
|
||||||
|
|
||||||
|
use Friendica\App;
|
||||||
|
use Friendica\App\BaseURL;
|
||||||
use Friendica\Content\Text\BBCode;
|
use Friendica\Content\Text\BBCode;
|
||||||
|
use Friendica\Content\Text\BBCode\Video;
|
||||||
use Friendica\Content\Text\HTML;
|
use Friendica\Content\Text\HTML;
|
||||||
use Friendica\Core\Hook;
|
use Friendica\Core\Hook;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
|
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||||
use Friendica\Core\Protocol;
|
use Friendica\Core\Protocol;
|
||||||
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
use Friendica\Core\Session\Capability\IHandleUserSessions;
|
||||||
use Friendica\Core\System;
|
use Friendica\Core\System;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
use Friendica\Model\Attach;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Model\Conversation;
|
||||||
|
use Friendica\Model\FileTag;
|
||||||
use Friendica\Model\Group;
|
use Friendica\Model\Group;
|
||||||
use Friendica\Model\Item as ItemModel;
|
use Friendica\Model\Item as ItemModel;
|
||||||
use Friendica\Model\Photo;
|
use Friendica\Model\Photo;
|
||||||
use Friendica\Model\Tag;
|
use Friendica\Model\Tag;
|
||||||
use Friendica\Model\Post;
|
use Friendica\Model\Post;
|
||||||
|
use Friendica\Model\User;
|
||||||
|
use Friendica\Network\HTTPException;
|
||||||
|
use Friendica\Object\EMail\ItemCCEMail;
|
||||||
use Friendica\Protocol\Activity;
|
use Friendica\Protocol\Activity;
|
||||||
|
use Friendica\Util\ACLFormatter;
|
||||||
|
use Friendica\Util\DateTimeFormat;
|
||||||
|
use Friendica\Util\Emailer;
|
||||||
|
use Friendica\Util\ParseUrl;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use Friendica\Util\Proxy;
|
use Friendica\Util\Proxy;
|
||||||
use Friendica\Util\XML;
|
use Friendica\Util\XML;
|
||||||
|
@ -54,13 +68,31 @@ class Item
|
||||||
private $profiler;
|
private $profiler;
|
||||||
/** @var IHandleUserSessions */
|
/** @var IHandleUserSessions */
|
||||||
private $userSession;
|
private $userSession;
|
||||||
|
/** @var Video */
|
||||||
|
private $bbCodeVideo;
|
||||||
|
/** @var ACLFormatter */
|
||||||
|
private $aclFormatter;
|
||||||
|
/** @var IManagePersonalConfigValues */
|
||||||
|
private $pConfig;
|
||||||
|
/** @var BaseURL */
|
||||||
|
private $baseURL;
|
||||||
|
/** @var Emailer */
|
||||||
|
private $emailer;
|
||||||
|
/** @var App */
|
||||||
|
private $app;
|
||||||
|
|
||||||
public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession)
|
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;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
$this->userSession = $userSession;
|
$this->userSession = $userSession;
|
||||||
|
$this->bbCodeVideo = $bbCodeVideo;
|
||||||
|
$this->aclFormatter = $aclFormatter;
|
||||||
|
$this->baseURL = $baseURL;
|
||||||
|
$this->pConfig = $pConfig;
|
||||||
|
$this->emailer = $emailer;
|
||||||
|
$this->app = $app;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -756,4 +788,237 @@ class Item
|
||||||
|
|
||||||
return $body;
|
return $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function storeAttachmentFromRequest(array $request): string
|
||||||
|
{
|
||||||
|
$attachment_type = $request['attachment_type'] ?? '';
|
||||||
|
$attachment_title = $request['attachment_title'] ?? '';
|
||||||
|
$attachment_text = $request['attachment_text'] ?? '';
|
||||||
|
|
||||||
|
$attachment_url = hex2bin($request['attachment_url'] ?? '');
|
||||||
|
$attachment_img_src = hex2bin($request['attachment_img_src'] ?? '');
|
||||||
|
|
||||||
|
$attachment_img_width = $request['attachment_img_width'] ?? 0;
|
||||||
|
$attachment_img_height = $request['attachment_img_height'] ?? 0;
|
||||||
|
|
||||||
|
// Fetch the basic attachment data
|
||||||
|
$attachment = ParseUrl::getSiteinfoCached($attachment_url);
|
||||||
|
unset($attachment['keywords']);
|
||||||
|
|
||||||
|
// Overwrite the basic data with possible changes from the frontend
|
||||||
|
$attachment['type'] = $attachment_type;
|
||||||
|
$attachment['title'] = $attachment_title;
|
||||||
|
$attachment['text'] = $attachment_text;
|
||||||
|
$attachment['url'] = $attachment_url;
|
||||||
|
|
||||||
|
if (!empty($attachment_img_src)) {
|
||||||
|
$attachment['images'] = [
|
||||||
|
0 => [
|
||||||
|
'src' => $attachment_img_src,
|
||||||
|
'width' => $attachment_img_width,
|
||||||
|
'height' => $attachment_img_height
|
||||||
|
]
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
unset($attachment['images']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "\n" . PageInfo::getFooterFromData($attachment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addCategories(array $post, string $category): array
|
||||||
|
{
|
||||||
|
if (!empty($post['file'])) {
|
||||||
|
// get the "fileas" tags for this post
|
||||||
|
$filedas = FileTag::fileToArray($post['file']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$list_array = explode(',', trim($category));
|
||||||
|
$post['file'] = FileTag::arrayToFile($list_array, 'category');
|
||||||
|
|
||||||
|
if (!empty($filedas) && is_array($filedas)) {
|
||||||
|
// append the fileas stuff to the new categories list
|
||||||
|
$post['file'] .= FileTag::arrayToFile($filedas);
|
||||||
|
}
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getACL(array $post, array $toplevel_item, array $request): array
|
||||||
|
{
|
||||||
|
// If this is a comment, set the permissions from the parent.
|
||||||
|
if ($toplevel_item) {
|
||||||
|
$post['allow_cid'] = $toplevel_item['allow_cid'] ?? '';
|
||||||
|
$post['allow_gid'] = $toplevel_item['allow_gid'] ?? '';
|
||||||
|
$post['deny_cid'] = $toplevel_item['deny_cid'] ?? '';
|
||||||
|
$post['deny_gid'] = $toplevel_item['deny_gid'] ?? '';
|
||||||
|
$post['private'] = $toplevel_item['private'];
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = User::getById($post['uid'], ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']);
|
||||||
|
if (!$user) {
|
||||||
|
throw new HTTPException\NotFoundException($this->l10n->t('Unable to locate original post.'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$post['allow_cid'] = isset($request['contact_allow']) ? $this->aclFormatter->toString($request['contact_allow']) : $user['allow_cid'] ?? '';
|
||||||
|
$post['allow_gid'] = isset($request['group_allow']) ? $this->aclFormatter->toString($request['group_allow']) : $user['allow_gid'] ?? '';
|
||||||
|
$post['deny_cid'] = isset($request['contact_deny']) ? $this->aclFormatter->toString($request['contact_deny']) : $user['deny_cid'] ?? '';
|
||||||
|
$post['deny_gid'] = isset($request['group_deny']) ? $this->aclFormatter->toString($request['group_deny']) : $user['deny_gid'] ?? '';
|
||||||
|
|
||||||
|
$visibility = $request['visibility'] ?? '';
|
||||||
|
if ($visibility === 'public') {
|
||||||
|
// The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
|
||||||
|
$post['allow_cid'] = $post['allow_gid'] = $post['deny_cid'] = $post['deny_gid'] = '';
|
||||||
|
} else if ($visibility === 'custom') {
|
||||||
|
// Since we know from the visibility parameter the item should be private, we have to prevent the empty ACL
|
||||||
|
// case that would make it public. So we always append the author's contact id to the allowed contacts.
|
||||||
|
// See https://github.com/friendica/friendica/issues/9672
|
||||||
|
$post['allow_cid'] .= $this->aclFormatter->toString(Contact::getPublicIdByUserId($post['uid']));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($post['allow_gid'] || $post['allow_cid'] || $post['deny_gid'] || $post['deny_cid']) {
|
||||||
|
$post['private'] = ItemModel::PRIVATE;
|
||||||
|
} elseif ($this->pConfig->get($post['uid'], 'system', 'unlisted')) {
|
||||||
|
$post['private'] = ItemModel::UNLISTED;
|
||||||
|
} else {
|
||||||
|
$post['private'] = ItemModel::PUBLIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function moveAttachmentsFromBodyToAttach(array $post): array
|
||||||
|
{
|
||||||
|
if (!preg_match_all('/(\[attachment\]([0-9]+)\[\/attachment\])/',$post['body'], $match)) {
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($match[2] as $attachment_id) {
|
||||||
|
$attachment = Attach::selectFirst(['id', 'uid', 'filename', 'filesize', 'filetype'], ['id' => $attachment_id, 'uid' => $post['uid']]);
|
||||||
|
if (empty($attachment)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($post['attach']) {
|
||||||
|
$post['attach'] .= ',';
|
||||||
|
}
|
||||||
|
$post['attach'] .= Post\Media::getAttachElement($this->baseURL->get() . '/attach/' . $attachment['id'],
|
||||||
|
$attachment['filesize'], $attachment['filetype'], $attachment['filename'] ?? '');
|
||||||
|
|
||||||
|
$fields = ['allow_cid' => $post['allow_cid'], 'allow_gid' => $post['allow_gid'],
|
||||||
|
'deny_cid' => $post['deny_cid'], 'deny_gid' => $post['deny_gid']];
|
||||||
|
$condition = ['id' => $attachment_id];
|
||||||
|
Attach::update($fields, $condition);
|
||||||
|
}
|
||||||
|
|
||||||
|
$post['body'] = str_replace($match[1], '', $post['body']);
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setObjectType(array $post): array
|
||||||
|
{
|
||||||
|
if (empty($post['post-type'])) {
|
||||||
|
$post['post-type'] = empty($post['title']) ? ItemModel::PT_NOTE : ItemModel::PT_ARTICLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// embedded bookmark or attachment in post? set bookmark flag
|
||||||
|
$data = BBCode::getAttachmentData($post['body']);
|
||||||
|
if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $post['body'], $match, PREG_SET_ORDER) || isset($data['type']))
|
||||||
|
&& ($post['post-type'] != ItemModel::PT_PERSONAL_NOTE)) {
|
||||||
|
$post['post-type'] = ItemModel::PT_PAGE;
|
||||||
|
$post['object-type'] = Activity\ObjectType::BOOKMARK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting the object type if not defined before
|
||||||
|
if (empty($post['object-type'])) {
|
||||||
|
$post['object-type'] = ($post['gravity'] == ItemModel::GRAVITY_PARENT) ? Activity\ObjectType::NOTE : Activity\ObjectType::COMMENT;
|
||||||
|
|
||||||
|
$objectdata = BBCode::getAttachedData($post['body']);
|
||||||
|
|
||||||
|
if ($objectdata['type'] == 'link') {
|
||||||
|
$post['object-type'] = Activity\ObjectType::BOOKMARK;
|
||||||
|
} elseif ($objectdata['type'] == 'video') {
|
||||||
|
$post['object-type'] = Activity\ObjectType::VIDEO;
|
||||||
|
} elseif ($objectdata['type'] == 'photo') {
|
||||||
|
$post['object-type'] = Activity\ObjectType::IMAGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initializePost(array $post): array
|
||||||
|
{
|
||||||
|
$post['network'] = Protocol::DFRN;
|
||||||
|
$post['protocol'] = Conversation::PARCEL_DIRECT;
|
||||||
|
$post['direction'] = Conversation::PUSH;
|
||||||
|
$post['received'] = DateTimeFormat::utcNow();
|
||||||
|
$post['origin'] = true;
|
||||||
|
$post['wall'] = $post['wall'] ?? true;
|
||||||
|
$post['guid'] = $post['guid'] ?? System::createUUID();
|
||||||
|
$post['uri'] = $post['uri'] ?? ItemModel::newURI($post['guid']);
|
||||||
|
$post['verb'] = $post['verb'] ?? Activity::POST;
|
||||||
|
$owner = User::getOwnerDataById($post['uid']);
|
||||||
|
|
||||||
|
if (empty($post['contact-id'])) {
|
||||||
|
$post['contact-id'] = $owner['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($post['author-link']) && empty($post['author-id'])) {
|
||||||
|
$post['author-link'] = $owner['url'];
|
||||||
|
$post['author-id'] = Contact::getIdForURL($post['author-link']);
|
||||||
|
$post['author-name'] = $owner['name'];
|
||||||
|
$post['author-avatar'] = $owner['thumb'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($post['owner-link']) && empty($post['owner-id'])) {
|
||||||
|
$post['owner-link'] = $post['author-link'];
|
||||||
|
$post['owner-id'] = Contact::getIdForURL($post['owner-link']);
|
||||||
|
$post['owner-name'] = $post['author-name'];
|
||||||
|
$post['owner-avatar'] = $post['author-avatar'];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function finalizePost(array $post): array
|
||||||
|
{
|
||||||
|
if (preg_match("/\[attachment\](.*?)\[\/attachment\]/ism", $post['body'], $matches)) {
|
||||||
|
$post['body'] = preg_replace("/\[attachment].*?\[\/attachment\]/ism", PageInfo::getFooterFromUrl($matches[1]), $post['body']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert links with empty descriptions to links without an explicit description
|
||||||
|
$post['body'] = trim(preg_replace('#\[url=([^\]]*?)\]\[/url\]#ism', '[url]$1[/url]', $post['body']));
|
||||||
|
$post['body'] = $this->bbCodeVideo->transform($post['body']);
|
||||||
|
$post['body'] = BBCode::scaleExternalImages($post['body']);
|
||||||
|
$post = $this->setObjectType($post);
|
||||||
|
|
||||||
|
// Personal notes must never be altered to a forum post.
|
||||||
|
if ($post['post-type'] != ItemModel::PT_PERSONAL_NOTE) {
|
||||||
|
// Look for any tags and linkify them
|
||||||
|
$post = $this->expandTags($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 (!$address) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->emailer->send(new ItemCCEMail($this->app, $this->l10n, $this->baseURL,
|
||||||
|
$post, $address, $author['thumb'] ?? ''));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -819,43 +819,14 @@ class Item
|
||||||
|
|
||||||
private static function prepareOriginPost(array $item): array
|
private static function prepareOriginPost(array $item): array
|
||||||
{
|
{
|
||||||
$item['wall'] = 1;
|
$item = DI::contentItem()->initializePost($item);
|
||||||
$item['origin'] = 1;
|
|
||||||
$item['network'] = Protocol::DFRN;
|
|
||||||
$item['protocol'] = Conversation::PARCEL_DIRECT;
|
|
||||||
$item['direction'] = Conversation::PUSH;
|
|
||||||
|
|
||||||
$owner = User::getOwnerDataById($item['uid']);
|
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;
|
||||||
if (empty($item['contact-id'])) {
|
|
||||||
$item['contact-id'] = $owner['id'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($item['author-link']) && empty($item['author-id'])) {
|
$item = DI::contentItem()->moveAttachmentsFromBodyToAttach($item);
|
||||||
$item['author-link'] = $owner['url'];
|
$item = DI::contentItem()->finalizePost($item);
|
||||||
$item['author-name'] = $owner['name'];
|
|
||||||
$item['author-avatar'] = $owner['thumb'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($item['owner-link']) && empty($item['owner-id'])) {
|
|
||||||
$item['owner-link'] = $item['author-link'];
|
|
||||||
$item['owner-name'] = $item['author-name'];
|
|
||||||
$item['owner-avatar'] = $item['author-avatar'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setting the object type if not defined before
|
|
||||||
if (empty($item['object-type'])) {
|
|
||||||
$item['object-type'] = Activity\ObjectType::NOTE; // Default value
|
|
||||||
$objectdata = BBCode::getAttachedData($item['body']);
|
|
||||||
|
|
||||||
if ($objectdata['type'] == 'link') {
|
|
||||||
$item['object-type'] = Activity\ObjectType::BOOKMARK;
|
|
||||||
} elseif ($objectdata['type'] == 'video') {
|
|
||||||
$item['object-type'] = Activity\ObjectType::VIDEO;
|
|
||||||
} elseif ($objectdata['type'] == 'photo') {
|
|
||||||
$item['object-type'] = Activity\ObjectType::IMAGE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
@ -1336,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);
|
||||||
}
|
}
|
||||||
|
@ -3016,13 +2984,15 @@ class Item
|
||||||
$item['hashtags'] = $tags['hashtags'];
|
$item['hashtags'] = $tags['hashtags'];
|
||||||
$item['mentions'] = $tags['mentions'];
|
$item['mentions'] = $tags['mentions'];
|
||||||
|
|
||||||
$item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $item['body']);
|
|
||||||
|
|
||||||
if (!$is_preview) {
|
if (!$is_preview) {
|
||||||
|
$item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $item['body']);
|
||||||
$item['body'] = Post\Media::removeFromEndOfBody($item['body'] ?? '');
|
$item['body'] = Post\Media::removeFromEndOfBody($item['body'] ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
$body = $item['body'];
|
$body = $item['body'];
|
||||||
|
if ($is_preview) {
|
||||||
|
$item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $item['body']);
|
||||||
|
}
|
||||||
|
|
||||||
$fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network', 'has-media', 'quote-uri-id', 'post-type'];
|
$fields = ['uri-id', 'uri', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'network', 'has-media', 'quote-uri-id', 'post-type'];
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: 2023.03-dev\n"
|
"Project-Id-Version: 2023.03-dev\n"
|
||||||
"Report-Msgid-Bugs-To: \n"
|
"Report-Msgid-Bugs-To: \n"
|
||||||
"POT-Creation-Date: 2023-01-07 14:32+0000\n"
|
"POT-Creation-Date: 2023-01-07 17:15+0000\n"
|
||||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
@ -18,13 +18,36 @@ msgstr ""
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
||||||
|
|
||||||
#: mod/item.php:129 mod/item.php:133
|
#: mod/item.php:101 mod/item.php:105 mod/item.php:178 mod/item.php:182
|
||||||
|
#: src/Content/Item.php:860
|
||||||
msgid "Unable to locate original post."
|
msgid "Unable to locate original post."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: mod/item.php:179 mod/item.php:184 mod/item.php:855 mod/message.php:69
|
#: mod/item.php:139
|
||||||
#: mod/message.php:114 mod/notes.php:44 mod/photos.php:158 mod/photos.php:675
|
msgid "Post updated."
|
||||||
#: src/Model/Event.php:522 src/Module/Attach.php:55 src/Module/BaseApi.php:95
|
msgstr ""
|
||||||
|
|
||||||
|
#: mod/item.php:213 mod/item.php:218
|
||||||
|
msgid "Item wasn't stored."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: mod/item.php:228
|
||||||
|
msgid "Item couldn't be fetched."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: mod/item.php:273 mod/item.php:278
|
||||||
|
msgid "Empty post discarded."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: mod/item.php:414 src/Module/Admin/Themes/Details.php:39
|
||||||
|
#: src/Module/Admin/Themes/Index.php:59 src/Module/Debug/ItemBody.php:42
|
||||||
|
#: src/Module/Debug/ItemBody.php:57 src/Module/Item/Feed.php:80
|
||||||
|
msgid "Item not found."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: mod/item.php:438 mod/message.php:69 mod/message.php:114 mod/notes.php:44
|
||||||
|
#: mod/photos.php:158 mod/photos.php:675 src/Model/Event.php:522
|
||||||
|
#: src/Module/Attach.php:55 src/Module/BaseApi.php:95
|
||||||
#: src/Module/BaseNotifications.php:98 src/Module/BaseSettings.php:52
|
#: src/Module/BaseNotifications.php:98 src/Module/BaseSettings.php:52
|
||||||
#: src/Module/Calendar/Event/API.php:88 src/Module/Calendar/Event/Form.php:84
|
#: src/Module/Calendar/Event/API.php:88 src/Module/Calendar/Event/Form.php:84
|
||||||
#: src/Module/Calendar/Export.php:62 src/Module/Calendar/Show.php:82
|
#: src/Module/Calendar/Export.php:62 src/Module/Calendar/Show.php:82
|
||||||
|
@ -59,28 +82,6 @@ msgstr ""
|
||||||
msgid "Permission denied."
|
msgid "Permission denied."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: mod/item.php:330 mod/item.php:335
|
|
||||||
msgid "Empty post discarded."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: mod/item.php:673
|
|
||||||
msgid "Post updated."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: mod/item.php:683 mod/item.php:688
|
|
||||||
msgid "Item wasn't stored."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: mod/item.php:699
|
|
||||||
msgid "Item couldn't be fetched."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: mod/item.php:831 src/Module/Admin/Themes/Details.php:39
|
|
||||||
#: src/Module/Admin/Themes/Index.php:59 src/Module/Debug/ItemBody.php:42
|
|
||||||
#: src/Module/Debug/ItemBody.php:57 src/Module/Item/Feed.php:80
|
|
||||||
msgid "Item not found."
|
|
||||||
msgstr ""
|
|
||||||
|
|
||||||
#: mod/lostpass.php:40
|
#: mod/lostpass.php:40
|
||||||
msgid "No valid account found."
|
msgid "No valid account found."
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
@ -1516,58 +1517,58 @@ msgstr ""
|
||||||
msgid "show more"
|
msgid "show more"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:294 src/Model/Item.php:2925
|
#: src/Content/Item.php:326 src/Model/Item.php:2893
|
||||||
msgid "event"
|
msgid "event"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:297 src/Content/Item.php:307
|
#: src/Content/Item.php:329 src/Content/Item.php:339
|
||||||
#: src/Module/Post/Tag/Add.php:123
|
#: src/Module/Post/Tag/Add.php:123
|
||||||
msgid "status"
|
msgid "status"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:303 src/Model/Item.php:2927
|
#: src/Content/Item.php:335 src/Model/Item.php:2895
|
||||||
#: src/Module/Post/Tag/Add.php:123
|
#: src/Module/Post/Tag/Add.php:123
|
||||||
msgid "photo"
|
msgid "photo"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:317 src/Module/Post/Tag/Add.php:141
|
#: src/Content/Item.php:349 src/Module/Post/Tag/Add.php:141
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "%1$s tagged %2$s's %3$s with %4$s"
|
msgid "%1$s tagged %2$s's %3$s with %4$s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:386 view/theme/frio/theme.php:269
|
#: src/Content/Item.php:418 view/theme/frio/theme.php:269
|
||||||
msgid "Follow Thread"
|
msgid "Follow Thread"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:387 src/Model/Contact.php:1205
|
#: src/Content/Item.php:419 src/Model/Contact.php:1205
|
||||||
msgid "View Status"
|
msgid "View Status"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:388 src/Content/Item.php:406 src/Model/Contact.php:1149
|
#: src/Content/Item.php:420 src/Content/Item.php:438 src/Model/Contact.php:1149
|
||||||
#: src/Model/Contact.php:1197 src/Model/Contact.php:1206
|
#: src/Model/Contact.php:1197 src/Model/Contact.php:1206
|
||||||
#: src/Module/Directory.php:157 src/Module/Settings/Profile/Index.php:234
|
#: src/Module/Directory.php:157 src/Module/Settings/Profile/Index.php:234
|
||||||
msgid "View Profile"
|
msgid "View Profile"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:389 src/Model/Contact.php:1207
|
#: src/Content/Item.php:421 src/Model/Contact.php:1207
|
||||||
msgid "View Photos"
|
msgid "View Photos"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:390 src/Model/Contact.php:1198
|
#: src/Content/Item.php:422 src/Model/Contact.php:1198
|
||||||
#: src/Model/Contact.php:1208
|
#: src/Model/Contact.php:1208
|
||||||
msgid "Network Posts"
|
msgid "Network Posts"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:391 src/Model/Contact.php:1199
|
#: src/Content/Item.php:423 src/Model/Contact.php:1199
|
||||||
#: src/Model/Contact.php:1209
|
#: src/Model/Contact.php:1209
|
||||||
msgid "View Contact"
|
msgid "View Contact"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:392 src/Model/Contact.php:1210
|
#: src/Content/Item.php:424 src/Model/Contact.php:1210
|
||||||
msgid "Send PM"
|
msgid "Send PM"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:393 src/Module/Contact.php:409
|
#: src/Content/Item.php:425 src/Module/Contact.php:409
|
||||||
#: src/Module/Contact/Profile.php:348 src/Module/Contact/Profile.php:467
|
#: src/Module/Contact/Profile.php:348 src/Module/Contact/Profile.php:467
|
||||||
#: src/Module/Moderation/Blocklist/Contact.php:116
|
#: src/Module/Moderation/Blocklist/Contact.php:116
|
||||||
#: src/Module/Moderation/Users/Active.php:137
|
#: src/Module/Moderation/Users/Active.php:137
|
||||||
|
@ -1575,7 +1576,7 @@ msgstr ""
|
||||||
msgid "Block"
|
msgid "Block"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:394 src/Module/Contact.php:410
|
#: src/Content/Item.php:426 src/Module/Contact.php:410
|
||||||
#: src/Module/Contact/Profile.php:349 src/Module/Contact/Profile.php:475
|
#: src/Module/Contact/Profile.php:349 src/Module/Contact/Profile.php:475
|
||||||
#: src/Module/Notifications/Introductions.php:134
|
#: src/Module/Notifications/Introductions.php:134
|
||||||
#: src/Module/Notifications/Introductions.php:206
|
#: src/Module/Notifications/Introductions.php:206
|
||||||
|
@ -1583,11 +1584,11 @@ msgstr ""
|
||||||
msgid "Ignore"
|
msgid "Ignore"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:398 src/Object/Post.php:454
|
#: src/Content/Item.php:430 src/Object/Post.php:454
|
||||||
msgid "Languages"
|
msgid "Languages"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Item.php:403 src/Content/Widget.php:80
|
#: src/Content/Item.php:435 src/Content/Widget.php:80
|
||||||
#: src/Model/Contact.php:1200 src/Model/Contact.php:1211
|
#: src/Model/Contact.php:1200 src/Model/Contact.php:1211
|
||||||
#: src/Module/Contact/Follow.php:166 view/theme/vier/theme.php:196
|
#: src/Module/Contact/Follow.php:166 view/theme/vier/theme.php:196
|
||||||
msgid "Connect/Follow"
|
msgid "Connect/Follow"
|
||||||
|
@ -1920,8 +1921,8 @@ msgid ""
|
||||||
"<a href=\"%1$s\" target=\"_blank\" rel=\"noopener noreferrer\">%2$s</a> %3$s"
|
"<a href=\"%1$s\" target=\"_blank\" rel=\"noopener noreferrer\">%2$s</a> %3$s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Content/Text/BBCode.php:1257 src/Model/Item.php:3588
|
#: src/Content/Text/BBCode.php:1257 src/Model/Item.php:3558
|
||||||
#: src/Model/Item.php:3594 src/Model/Item.php:3595
|
#: src/Model/Item.php:3564 src/Model/Item.php:3565
|
||||||
msgid "Link to source"
|
msgid "Link to source"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -3090,66 +3091,66 @@ msgstr ""
|
||||||
msgid "Edit groups"
|
msgid "Edit groups"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Model/Item.php:2026
|
#: src/Model/Item.php:1994
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "Detected languages in this post:\\n%s"
|
msgid "Detected languages in this post:\\n%s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Model/Item.php:2929
|
#: src/Model/Item.php:2897
|
||||||
msgid "activity"
|
msgid "activity"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Model/Item.php:2931
|
#: src/Model/Item.php:2899
|
||||||
msgid "comment"
|
msgid "comment"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Model/Item.php:2934
|
#: src/Model/Item.php:2902
|
||||||
msgid "post"
|
msgid "post"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Model/Item.php:3082
|
#: src/Model/Item.php:3052
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "Content warning: %s"
|
msgid "Content warning: %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Model/Item.php:3500
|
#: src/Model/Item.php:3470
|
||||||
msgid "bytes"
|
msgid "bytes"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Model/Item.php:3531
|
#: src/Model/Item.php:3501
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "%2$s (%3$d%%, %1$d vote)"
|
msgid "%2$s (%3$d%%, %1$d vote)"
|
||||||
msgid_plural "%2$s (%3$d%%, %1$d votes)"
|
msgid_plural "%2$s (%3$d%%, %1$d votes)"
|
||||||
msgstr[0] ""
|
msgstr[0] ""
|
||||||
msgstr[1] ""
|
msgstr[1] ""
|
||||||
|
|
||||||
#: src/Model/Item.php:3533
|
#: src/Model/Item.php:3503
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "%2$s (%1$d vote)"
|
msgid "%2$s (%1$d vote)"
|
||||||
msgid_plural "%2$s (%1$d votes)"
|
msgid_plural "%2$s (%1$d votes)"
|
||||||
msgstr[0] ""
|
msgstr[0] ""
|
||||||
msgstr[1] ""
|
msgstr[1] ""
|
||||||
|
|
||||||
#: src/Model/Item.php:3538
|
#: src/Model/Item.php:3508
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "%d voter. Poll end: %s"
|
msgid "%d voter. Poll end: %s"
|
||||||
msgid_plural "%d voters. Poll end: %s"
|
msgid_plural "%d voters. Poll end: %s"
|
||||||
msgstr[0] ""
|
msgstr[0] ""
|
||||||
msgstr[1] ""
|
msgstr[1] ""
|
||||||
|
|
||||||
#: src/Model/Item.php:3540
|
#: src/Model/Item.php:3510
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "%d voter."
|
msgid "%d voter."
|
||||||
msgid_plural "%d voters."
|
msgid_plural "%d voters."
|
||||||
msgstr[0] ""
|
msgstr[0] ""
|
||||||
msgstr[1] ""
|
msgstr[1] ""
|
||||||
|
|
||||||
#: src/Model/Item.php:3542
|
#: src/Model/Item.php:3512
|
||||||
#, php-format
|
#, php-format
|
||||||
msgid "Poll end: %s"
|
msgid "Poll end: %s"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: src/Model/Item.php:3576 src/Model/Item.php:3577
|
#: src/Model/Item.php:3546 src/Model/Item.php:3547
|
||||||
msgid "View on separate page"
|
msgid "View on separate page"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue