X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fitem.php;h=e23e9fb4c4fa86814c4c4b367434c5de5ec49d6e;hb=e8420dcb7155af7fb8bd29fb63c79367125dd551;hp=799d1b8881765baf7c99b1928a4c45efa25091a7;hpb=d8fe8b1e8b008ee0b8d87fda7467b1d058a07e75;p=friendica.git diff --git a/mod/item.php b/mod/item.php index 799d1b8881..e23e9fb4c4 100644 --- a/mod/item.php +++ b/mod/item.php @@ -34,7 +34,6 @@ use Friendica\Content\Text\BBCode; use Friendica\Core\Hook; use Friendica\Core\Logger; use Friendica\Core\Protocol; -use Friendica\Core\Session; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; @@ -58,11 +57,11 @@ use Friendica\Util\DateTimeFormat; use Friendica\Util\ParseUrl; function item_post(App $a) { - if (!Session::isAuthenticated()) { + if (!DI::userSession()->isAuthenticated()) { throw new HTTPException\ForbiddenException(); } - $uid = local_user(); + $uid = DI::userSession()->getLocalUserId(); if (!empty($_REQUEST['dropitems'])) { $arr_drop = explode(',', $_REQUEST['dropitems']); @@ -78,8 +77,6 @@ function item_post(App $a) { Logger::debug('postvars', ['_REQUEST' => $_REQUEST]); - $api_source = $_REQUEST['api_source'] ?? false; - $return_path = $_REQUEST['return'] ?? ''; $preview = intval($_REQUEST['preview'] ?? 0); @@ -91,7 +88,7 @@ function item_post(App $a) { if (!$preview && !empty($_REQUEST['post_id_random'])) { if (!empty($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) { Logger::warning('duplicate post'); - item_post_return(DI::baseUrl(), $api_source, $return_path); + item_post_return(DI::baseUrl(), $return_path); } else { $_SESSION['post-random'] = $_REQUEST['post_id_random']; } @@ -107,7 +104,7 @@ function item_post(App $a) { $toplevel_user_id = null; $objecttype = null; - $profile_uid = ($_REQUEST['profile_uid'] ?? 0) ?: local_user(); + $profile_uid = DI::userSession()->getLocalUserId(); $posttype = ($_REQUEST['post_type'] ?? '') ?: Item::PT_ARTICLE; if ($parent_item_id || $thr_parent_uri) { @@ -139,7 +136,7 @@ function item_post(App $a) { // When commenting on a public post then store the post for the current user // This enables interaction like starring and saving into folders if ($toplevel_item['uid'] == 0) { - $stored = Item::storeForUserByUriId($toplevel_item['uri-id'], local_user(), ['post-reason' => Item::PR_ACTIVITY]); + $stored = Item::storeForUserByUriId($toplevel_item['uri-id'], DI::userSession()->getLocalUserId(), ['post-reason' => Item::PR_ACTIVITY]); Logger::info('Public item stored for user', ['uri-id' => $toplevel_item['uri-id'], 'uid' => $uid, 'stored' => $stored]); if ($stored) { $toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $stored]); @@ -169,16 +166,16 @@ function item_post(App $a) { } // Ensure that the user id in a thread always stay the same - if (!is_null($toplevel_user_id) && in_array($toplevel_user_id, [local_user(), 0])) { + 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 - $allow_comment = local_user() && $toplevel_item_id && in_array($toplevel_item['private'], [Item::PUBLIC, Item::UNLISTED]) && in_array($toplevel_item['network'], Protocol::FEDERATED); + $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 if (!Security::canWriteToUserWall($profile_uid) && !$allow_comment) { - Logger::warning('Permission denied.', ['local' => local_user(), 'profile_uid' => $profile_uid, 'toplevel_item_id' => $toplevel_item_id, 'network' => $toplevel_item['network']]); + 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); @@ -242,6 +239,8 @@ function item_post(App $a) { $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 @@ -323,13 +322,6 @@ function item_post(App $a) { $pubmail_enabled = ($_REQUEST['pubmail_enable'] ?? false) && !$private; - // if using the API, we won't see pubmail_enable - figure out if it should be set - if ($api_source && $profile_uid && $profile_uid == local_user() && !$private) { - if (function_exists('imap_open') && !DI::config()->get('system', 'imap_disabled')) { - $pubmail_enabled = DBA::exists('mailacct', ["`uid` = ? AND `server` != ? AND `pubmail`", local_user(), '']); - } - } - if (!strlen($body)) { if ($preview) { System::jsonExit(['preview' => '']); @@ -363,11 +355,11 @@ function item_post(App $a) { $self = false; $contact_id = 0; - if (local_user() && ((local_user() == $profile_uid) || $allow_comment)) { + if (DI::userSession()->getLocalUserId() && ((DI::userSession()->getLocalUserId() == $profile_uid) || $allow_comment)) { $self = true; - $author = DBA::selectFirst('contact', [], ['uid' => local_user(), 'self' => true]); - } elseif (!empty(Session::getRemoteContactID($profile_uid))) { - $author = DBA::selectFirst('contact', [], ['id' => Session::getRemoteContactID($profile_uid)]); + $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)) { @@ -375,7 +367,7 @@ function item_post(App $a) { } // get contact info for owner - if ($profile_uid == local_user() || $allow_comment) { + if ($profile_uid == DI::userSession()->getLocalUserId() || $allow_comment) { $contact_record = $author ?: []; } else { $contact_record = DBA::selectFirst('contact', [], ['uid' => $profile_uid, 'self' => true]) ?: []; @@ -385,7 +377,7 @@ function item_post(App $a) { if ($posttype != Item::PT_PERSONAL_NOTE) { // Look for any tags and linkify them $item = [ - 'uid' => local_user() ? local_user() : $profile_uid, + 'uid' => DI::userSession()->getLocalUserId() ? DI::userSession()->getLocalUserId() : $profile_uid, 'gravity' => $toplevel_item_id ? Item::GRAVITY_COMMENT : Item::GRAVITY_PARENT, 'network' => $network, 'body' => $body, @@ -580,7 +572,7 @@ function item_post(App $a) { 'parent' => $toplevel_item_id, 'self' => $self, // This triggers posts via API and the mirror functions - 'api_source' => $api_source, + 'api_source' => false, // This field is for storing the raw conversation data 'protocol' => Conversation::PARCEL_DIRECT, 'direction' => Conversation::PUSH, @@ -612,7 +604,8 @@ function item_post(App $a) { $datarray['author-uri-id'] = ItemURI::getIdByURI($datarray['author-link']); $datarray['owner-updated'] = ''; $datarray['has-media'] = false; - $datarray['body'] = Item::improveSharedDataInBody($datarray); + $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); @@ -634,7 +627,7 @@ function item_post(App $a) { 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(), $api_source, $return_path); + item_post_return(DI::baseUrl(), $return_path); } } @@ -653,7 +646,12 @@ function item_post(App $a) { } $datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']); - $datarray['body'] = Item::improveSharedDataInBody($datarray); + + $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 = [ @@ -734,7 +732,7 @@ function item_post(App $a) { Hook::callAll('post_local_end', $datarray); - if (strlen($emailcc) && $profile_uid == local_user()) { + if (strlen($emailcc) && $profile_uid == DI::userSession()->getLocalUserId()) { $recipients = explode(',', $emailcc); if (count($recipients)) { foreach ($recipients as $recipient) { @@ -750,20 +748,12 @@ function item_post(App $a) { Logger::debug('post_complete'); - if ($api_source) { - return $post_id; - } - - item_post_return(DI::baseUrl(), $api_source, $return_path); + item_post_return(DI::baseUrl(), $return_path); // NOTREACHED } -function item_post_return($baseurl, $api_source, $return_path) +function item_post_return($baseurl, $return_path) { - if ($api_source) { - return; - } - if ($return_path) { DI::baseUrl()->redirect($return_path); } @@ -780,7 +770,7 @@ function item_post_return($baseurl, $api_source, $return_path) function item_content(App $a) { - if (!Session::isAuthenticated()) { + if (!DI::userSession()->isAuthenticated()) { throw new HTTPException\UnauthorizedException(); } @@ -794,9 +784,9 @@ function item_content(App $a) switch ($args->get(1)) { case 'drop': if (DI::mode()->isAjax()) { - Item::deleteForUser(['id' => $args->get(2)], local_user()); + Item::deleteForUser(['id' => $args->get(2)], DI::userSession()->getLocalUserId()); // ajax return: [, 0 (no perm) | ] - System::jsonExit([intval($args->get(2)), local_user()]); + System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]); } else { if (!empty($args->get(3))) { $o = drop_item($args->get(2), $args->get(3)); @@ -807,16 +797,16 @@ function item_content(App $a) break; case 'block': - $item = Post::selectFirstForUser(local_user(), ['guid', 'author-id', 'parent', 'gravity'], ['id' => $args->get(2)]); + $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['guid', 'author-id', 'parent', 'gravity'], ['id' => $args->get(2)]); if (empty($item['author-id'])) { throw new HTTPException\NotFoundException('Item not found'); } - Contact\User::setBlocked($item['author-id'], local_user(), true); + Contact\User::setBlocked($item['author-id'], DI::userSession()->getLocalUserId(), true); if (DI::mode()->isAjax()) { // ajax return: [, 0 (no perm) | ] - System::jsonExit([intval($args->get(2)), local_user()]); + System::jsonExit([intval($args->get(2)), DI::userSession()->getLocalUserId()]); } else { item_redirect_after_action($item, $args->get(3)); } @@ -835,7 +825,7 @@ function item_content(App $a) function drop_item(int $id, string $return = ''): string { // Locate item to be deleted - $item = Post::selectFirstForUser(local_user(), ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent'], ['id' => $id]); + $item = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent'], ['id' => $id]); if (!DBA::isResult($item)) { DI::sysmsg()->addNotice(DI::l10n()->t('Item not found.')); @@ -850,18 +840,18 @@ function drop_item(int $id, string $return = ''): string $contact_id = 0; // check if logged in user is either the author or owner of this item - if (Session::getRemoteContactID($item['uid']) == $item['contact-id']) { + if (DI::userSession()->getRemoteContactID($item['uid']) == $item['contact-id']) { $contact_id = $item['contact-id']; } - if ((local_user() == $item['uid']) || $contact_id) { + if ((DI::userSession()->getLocalUserId() == $item['uid']) || $contact_id) { // delete the item - Item::deleteForUser(['id' => $item['id']], local_user()); + Item::deleteForUser(['id' => $item['id']], DI::userSession()->getLocalUserId()); item_redirect_after_action($item, $return); //NOTREACHED } else { - Logger::warning('Permission denied.', ['local' => local_user(), 'uid' => $item['uid'], 'cid' => $contact_id]); + Logger::warning('Permission denied.', ['local' => DI::userSession()->getLocalUserId(), 'uid' => $item['uid'], 'cid' => $contact_id]); DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.')); DI::baseUrl()->redirect('display/' . $item['guid']); //NOTREACHED @@ -880,7 +870,7 @@ function item_redirect_after_action(array $item, string $returnUrlHex) // Check if delete a comment if ($item['gravity'] == Item::GRAVITY_COMMENT) { if (!empty($item['parent'])) { - $parentitem = Post::selectFirstForUser(local_user(), ['guid'], ['id' => $item['parent']]); + $parentitem = Post::selectFirstForUser(DI::userSession()->getLocalUserId(), ['guid'], ['id' => $item['parent']]); } // Return to parent guid