From 0d56f156f7103ca15221d97fefb67696b837e33c Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 4 Jan 2023 05:44:52 +0000 Subject: [PATCH 01/10] Code cleanup for mod/item.php --- mod/item.php | 676 +++++++++---------------------------------- src/Content/Item.php | 245 +++++++++++++++- src/Model/Item.php | 39 +-- 3 files changed, 374 insertions(+), 586 deletions(-) diff --git a/mod/item.php b/mod/item.php index 7be92a73f..808641132 100644 --- a/mod/item.php +++ b/mod/item.php @@ -29,7 +29,6 @@ */ use Friendica\App; -use Friendica\Content\PageInfo; use Friendica\Content\Text\BBCode; use Friendica\Core\Hook; use Friendica\Core\Logger; @@ -38,31 +37,24 @@ use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; -use Friendica\Model\Attach; use Friendica\Model\Contact; -use Friendica\Model\Conversation; -use Friendica\Model\FileTag; use Friendica\Model\Item; use Friendica\Model\ItemURI; -use Friendica\Model\Notification; use Friendica\Model\Photo; use Friendica\Model\Post; use Friendica\Model\Tag; -use Friendica\Model\User; use Friendica\Network\HTTPException; use Friendica\Object\EMail\ItemCCEMail; use Friendica\Protocol\Activity; -use Friendica\Security\Security; use Friendica\Util\DateTimeFormat; -use Friendica\Util\ParseUrl; function item_post(App $a) { - if (!DI::userSession()->isAuthenticated()) { + $uid = DI::userSession()->getLocalUserId(); + + if (!DI::userSession()->isAuthenticated() || !$uid) { throw new HTTPException\ForbiddenException(); } - $uid = DI::userSession()->getLocalUserId(); - if (!empty($_REQUEST['dropitems'])) { $arr_drop = explode(',', $_REQUEST['dropitems']); foreach ($arr_drop as $item) { @@ -75,10 +67,8 @@ function item_post(App $a) { Hook::callAll('post_local_start', $_REQUEST); - Logger::debug('postvars', ['_REQUEST' => $_REQUEST]); - $return_path = $_REQUEST['return'] ?? ''; - $preview = intval($_REQUEST['preview'] ?? 0); + $preview = intval($_REQUEST['preview'] ?? 0); /* * Check for doubly-submitted posts, and reject duplicates @@ -94,30 +84,50 @@ function item_post(App $a) { } } - // Is this a reply to something? - $parent_item_id = intval($_REQUEST['parent'] ?? 0); - $thr_parent_uri = trim($_REQUEST['parent_uri'] ?? ''); + $post_id = intval($_REQUEST['post_id'] ?? 0); - $parent_item = null; - $toplevel_item = null; - $toplevel_item_id = 0; - $toplevel_user_id = null; + // is this an edited post? + if ($post_id > 0) { + $orig_post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); + } else { + $orig_post = null; + } - $objecttype = null; - $profile_uid = DI::userSession()->getLocalUserId(); - $posttype = ($_REQUEST['post_type'] ?? '') ?: Item::PT_ARTICLE; + $emailcc = trim($_REQUEST['emailcc'] ?? ''); - if ($parent_item_id || $thr_parent_uri) { - if ($parent_item_id) { - $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $parent_item_id]); - } elseif ($thr_parent_uri) { - $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['uri' => $thr_parent_uri, 'uid' => $profile_uid]); + $post = ['uid' => $uid]; + + $post = DI::contentItem()->initializePost($post); + + $post['self'] = true; + $post['api_source'] = false; + $post['edit'] = $orig_post; + $post['file'] = ''; + $post['attach'] = ''; + $post['inform'] = ''; + $post['postopts'] = ''; + + $post['wall'] = $_REQUEST['wall'] ?? true; + $post['post-type'] = $_REQUEST['post_type'] ?? ''; + $post['title'] = trim($_REQUEST['title'] ?? ''); + $post['body'] = $_REQUEST['body'] ?? ''; + $post['location'] = trim($_REQUEST['location'] ?? ''); + $post['coord'] = trim($_REQUEST['coord'] ?? ''); + $post['parent'] = intval($_REQUEST['parent'] ?? 0); + $post['pubmail'] = $_REQUEST['pubmail_enable'] ?? false; + $post['created'] = $_REQUEST['created_at'] ?? DateTimeFormat::utcNow(); + $post['edited'] = $post['changed'] = $post['commented'] = $post['created']; + $post['app'] = ''; + + if ($post['parent']) { + if ($post['parent']) { + $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post['parent']]); } // if this isn't the top-level parent of the conversation, find it if (DBA::isResult($parent_item)) { // 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']; + $post['thr-parent'] = $parent_item['uri']; $toplevel_item = $parent_item; if ($parent_item['gravity'] != Item::GRAVITY_PARENT) { @@ -136,502 +146,108 @@ 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'], 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]); + $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' => $post['uid'], 'stored' => $stored]); if ($stored) { $toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $stored]); } } - $toplevel_item_id = $toplevel_item['id']; - $toplevel_user_id = $toplevel_item['uid']; - - $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; + $post['parent'] = $toplevel_item['id']; + $post['gravity'] = Item::GRAVITY_COMMENT; + $post['wall'] = $toplevel_item['wall']; } else { - $wall = $_REQUEST['wall']; + $parent_item = []; + $post['parent'] = 0; + $post['gravity'] = Item::GRAVITY_PARENT; + $post['thr-parent'] = $post['uri']; } - // Ensure that the user id in a thread always stay the same - if (!is_null($toplevel_user_id) && in_array($toplevel_user_id, [DI::userSession()->getLocalUserId(), 0])) { - $profile_uid = $toplevel_user_id; + $post = DI::contentItem()->getACL($post, $parent_item, $_REQUEST); + + $post['pubmail'] = $post['pubmail'] && !$post['private']; + + if (!empty($orig_post)) { + $post['uri'] = $orig_post['uri']; + $post['file'] = Post\Category::getTextByURIId($orig_post['uri-id'], $orig_post['uid']); } - // Allow commenting if it is an answer to a public post - $allow_comment = DI::userSession()->getLocalUserId() && $toplevel_item_id && in_array($toplevel_item['private'], [Item::PUBLIC, Item::UNLISTED]) && in_array($toplevel_item['network'], Protocol::FEDERATED); + $post = DI::contentItem()->addCategories($post, $_REQUEST['category'] ?? ''); - // Now check that valid personal details have been provided - 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 (!$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' => '']); + } + + DI::sysmsg()->addNotice(DI::l10n()->t('Empty post discarded.')); if ($return_path) { DI::baseUrl()->redirect($return_path); } - throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.')); + throw new HTTPException\BadRequestException(DI::l10n()->t('Empty post discarded.')); } - // 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']); + $post['body'] = Item::setHashtags($post['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']); + $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($post['body']); + $post['writable'] = true; - $o = DI::conversation()->create([array_merge($contact_record, $datarray)], 'search', false, true); + $o = DI::conversation()->create([$post], 'search', false, true); System::jsonExit(['preview' => $o]); } - Hook::callAll('post_local',$datarray); + Hook::callAll('post_local',$post); 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']); + unset($post['created']); + unset($post['edited']); + unset($post['commented']); + unset($post['received']); + unset($post['changed']); + unset($post['edit']); + unset($post['self']); + unset($post['api_source']); - Post\Delayed::add($datarray['uri'], $datarray, 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); } } - if (!empty($datarray['cancel'])) { + if (!empty($post['cancel'])) { Logger::info('mod_item: post cancelled by addon.'); if ($return_path) { DI::baseUrl()->redirect($return_path); @@ -645,26 +261,26 @@ function item_post(App $a) { System::jsonExit($json); } - $datarray['uri-id'] = ItemURI::getIdByURI($datarray['uri']); + $post['uri-id'] = ItemURI::getIdByURI($post['uri']); - $quote_uri_id = Item::getQuoteUriId($datarray['body'], $datarray['uid']); + $quote_uri_id = Item::getQuoteUriId($post['body'], $post['uid']); if (!empty($quote_uri_id)) { - $datarray['quote-uri-id'] = $quote_uri_id; - $datarray['body'] = BBCode::removeSharedData($datarray['body']); + $post['quote-uri-id'] = $quote_uri_id; + $post['body'] = BBCode::removeSharedData($post['body']); } if ($orig_post) { $fields = [ - 'title' => $datarray['title'], - 'body' => $datarray['body'], - 'attach' => $datarray['attach'], - 'file' => $datarray['file'], + 'title' => $post['title'], + 'body' => $post['body'], + 'attach' => $post['attach'], + 'file' => $post['file'], 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow() ]; Item::update($fields, ['id' => $post_id]); - Item::updateDisplayCache($datarray['uri-id']); + Item::updateDisplayCache($post['uri-id']); if ($return_path) { DI::baseUrl()->redirect($return_path); @@ -673,12 +289,11 @@ function item_post(App $a) { throw new HTTPException\OKException(DI::l10n()->t('Post updated.')); } - unset($datarray['edit']); - unset($datarray['self']); - unset($datarray['api_source']); - - $post_id = Item::insert($datarray); + unset($post['edit']); + unset($post['self']); + unset($post['api_source']); + $post_id = Item::insert($post); if (!$post_id) { DI::sysmsg()->addNotice(DI::l10n()->t('Item wasn\'t stored.')); if ($return_path) { @@ -688,9 +303,8 @@ function item_post(App $a) { throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item wasn\'t stored.')); } - $datarray = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); - - if (!DBA::isResult($datarray)) { + $post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); + if (!DBA::isResult($post)) { Logger::error('Item couldn\'t be fetched.', ['post_id' => $post_id]); if ($return_path) { DI::baseUrl()->redirect($return_path); @@ -699,50 +313,24 @@ function item_post(App $a) { throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item couldn\'t be fetched.')); } - Tag::storeFromBody($datarray['uri-id'], $datarray['body']); - - if (!\Friendica\Content\Feature::isEnabled($uid, 'explicit_mentions') && ($datarray['gravity'] == Item::GRAVITY_COMMENT)) { - Tag::createImplicitMentions($datarray['uri-id'], $datarray['thr-parent-id']); + if (!\Friendica\Content\Feature::isEnabled($post['uid'], 'explicit_mentions') && ($post['gravity'] == Item::GRAVITY_COMMENT)) { + Tag::createImplicitMentions($post['uri-id'], $post['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', $post); - 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'] ?? '')); + $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::emailer()->send(new ItemCCEMail(DI::app(), DI::l10n(), DI::baseUrl(), + $post, $address, $author['thumb'] ?? '')); } } diff --git a/src/Content/Item.php b/src/Content/Item.php index 2cccf722a..76a3a1f4a 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -21,22 +21,33 @@ namespace Friendica\Content; +use Friendica\App\BaseURL; use Friendica\Content\Text\BBCode; +use Friendica\Content\Text\BBCode\Video; use Friendica\Content\Text\HTML; use Friendica\Core\Hook; use Friendica\Core\L10n; use Friendica\Core\Logger; +use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Protocol; use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\Model\Attach; use Friendica\Model\Contact; +use Friendica\Model\Conversation; +use Friendica\Model\FileTag; use Friendica\Model\Group; use Friendica\Model\Item as ItemModel; use Friendica\Model\Photo; use Friendica\Model\Tag; use Friendica\Model\Post; +use Friendica\Model\User; +use Friendica\Network\HTTPException; use Friendica\Protocol\Activity; +use Friendica\Util\ACLFormatter; +use Friendica\Util\DateTimeFormat; +use Friendica\Util\ParseUrl; use Friendica\Util\Profiler; use Friendica\Util\Proxy; use Friendica\Util\XML; @@ -54,13 +65,25 @@ class Item private $profiler; /** @var IHandleUserSessions */ private $userSession; + /** @var Video */ + private $bbCodeVideo; + /** @var ACLFormatter */ + private $aclFormatter; + /** @var IManagePersonalConfigValues */ + private $pConfig; + /** @var BaseURL */ + private $baseURL; - 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) { - $this->profiler = $profiler; - $this->activity = $activity; - $this->l10n = $l10n; - $this->userSession = $userSession; + $this->profiler = $profiler; + $this->activity = $activity; + $this->l10n = $l10n; + $this->userSession = $userSession; + $this->bbCodeVideo = $bbCodeVideo; + $this->aclFormatter = $aclFormatter; + $this->baseURL = $baseURL; + $this->pConfig = $pConfig; } /** @@ -756,4 +779,216 @@ class Item 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 (!DBA::isResult($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 (strlen($post['allow_gid']) || strlen($post['allow_cid']) || strlen($post['deny_gid']) || strlen($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 (strlen($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['wall'] = true; + $post['origin'] = true; + $post['network'] = Protocol::DFRN; + $post['protocol'] = Conversation::PARCEL_DIRECT; + $post['direction'] = Conversation::PUSH; + $post['guid'] = System::createUUID(); + $post['uri'] = ItemModel::newURI($post['guid']); + $post['verb'] = Activity::POST; + $post['received'] = DateTimeFormat::utcNow(); + $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; + } } diff --git a/src/Model/Item.php b/src/Model/Item.php index 039a106e7..d5a72c73e 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -819,43 +819,8 @@ class Item private static function prepareOriginPost(array $item): array { - $item['wall'] = 1; - $item['origin'] = 1; - $item['network'] = Protocol::DFRN; - $item['protocol'] = Conversation::PARCEL_DIRECT; - $item['direction'] = Conversation::PUSH; - - $owner = User::getOwnerDataById($item['uid']); - - if (empty($item['contact-id'])) { - $item['contact-id'] = $owner['id']; - } - - if (empty($item['author-link']) && empty($item['author-id'])) { - $item['author-link'] = $owner['url']; - $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; - } - } + $item = DI::contentItem()->initializePost($item); + $item = DI::contentItem()->finalizePost($item); return $item; } From d1a951f0acbfacf0280da38e6f0aba9b7d32eedb Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 4 Jan 2023 06:52:40 +0000 Subject: [PATCH 02/10] Post processing centralized --- mod/item.php | 126 +++++++++++++++++-------------------------- src/Content/Item.php | 44 ++++++++++++--- src/Model/Item.php | 11 ++-- 3 files changed, 92 insertions(+), 89 deletions(-) diff --git a/mod/item.php b/mod/item.php index 808641132..5b40a67de 100644 --- a/mod/item.php +++ b/mod/item.php @@ -42,9 +42,7 @@ use Friendica\Model\Item; use Friendica\Model\ItemURI; use Friendica\Model\Photo; use Friendica\Model\Post; -use Friendica\Model\Tag; use Friendica\Network\HTTPException; -use Friendica\Object\EMail\ItemCCEMail; use Friendica\Protocol\Activity; use Friendica\Util\DateTimeFormat; @@ -99,25 +97,24 @@ function item_post(App $a) { $post = DI::contentItem()->initializePost($post); - $post['self'] = true; - $post['api_source'] = false; - $post['edit'] = $orig_post; - $post['file'] = ''; - $post['attach'] = ''; - $post['inform'] = ''; - $post['postopts'] = ''; - - $post['wall'] = $_REQUEST['wall'] ?? true; - $post['post-type'] = $_REQUEST['post_type'] ?? ''; - $post['title'] = trim($_REQUEST['title'] ?? ''); - $post['body'] = $_REQUEST['body'] ?? ''; - $post['location'] = trim($_REQUEST['location'] ?? ''); - $post['coord'] = trim($_REQUEST['coord'] ?? ''); - $post['parent'] = intval($_REQUEST['parent'] ?? 0); - $post['pubmail'] = $_REQUEST['pubmail_enable'] ?? false; - $post['created'] = $_REQUEST['created_at'] ?? DateTimeFormat::utcNow(); - $post['edited'] = $post['changed'] = $post['commented'] = $post['created']; - $post['app'] = ''; + $post['edit'] = $orig_post; + $post['self'] = true; + $post['api_source'] = false; + $post['file'] = ''; + $post['attach'] = ''; + $post['inform'] = ''; + $post['postopts'] = ''; + $post['wall'] = $_REQUEST['wall'] ?? true; + $post['post-type'] = $_REQUEST['post_type'] ?? ''; + $post['title'] = trim($_REQUEST['title'] ?? ''); + $post['body'] = $_REQUEST['body'] ?? ''; + $post['location'] = trim($_REQUEST['location'] ?? ''); + $post['coord'] = trim($_REQUEST['coord'] ?? ''); + $post['parent'] = intval($_REQUEST['parent'] ?? 0); + $post['pubmail'] = $_REQUEST['pubmail_enable'] ?? false; + $post['created'] = $_REQUEST['created_at'] ?? DateTimeFormat::utcNow(); + $post['edited'] = $post['changed'] = $post['commented'] = $post['created']; + $post['app'] = ''; if ($post['parent']) { if ($post['parent']) { @@ -168,7 +165,6 @@ function item_post(App $a) { $post['pubmail'] = $post['pubmail'] && !$post['private']; if (!empty($orig_post)) { - $post['uri'] = $orig_post['uri']; $post['file'] = Post\Category::getTextByURIId($orig_post['uri-id'], $orig_post['uid']); } @@ -202,26 +198,20 @@ function item_post(App $a) { 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 if ($preview) { - // We set the datarray ID to -1 because in preview mode the dataray - // doesn't have an ID. - $post['id'] = -1; - $post['uri-id'] = -1; + // 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($post['body']); - $post['writable'] = true; + $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); @@ -230,6 +220,10 @@ function item_post(App $a) { 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', $a->getTimeZone()); if ($scheduled_at > DateTimeFormat::utcNow()) { @@ -238,9 +232,6 @@ function item_post(App $a) { unset($post['commented']); unset($post['received']); 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); item_post_return(DI::baseUrl(), $return_path); @@ -261,26 +252,26 @@ function item_post(App $a) { 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) { $fields = [ - 'title' => $post['title'], - 'body' => $post['body'], - 'attach' => $post['attach'], - 'file' => $post['file'], - 'edited' => DateTimeFormat::utcNow(), - 'changed' => DateTimeFormat::utcNow() + 'title' => $post['title'], + 'body' => $post['body'], + 'attach' => $post['attach'], + 'file' => $post['file'], + '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']); + Item::updateDisplayCache($orig_post['uri-id']); if ($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.')); } - unset($post['edit']); - unset($post['self']); - unset($post['api_source']); - $post_id = Item::insert($post); if (!$post_id) { 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.')); } - 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); - if (count($recipients)) { - foreach ($recipients as $recipient) { - $address = trim($recipient); - if (!strlen($address)) { - continue; - } - $author = DBA::selectFirst('contact', ['thumb'], ['uid' => $uid, 'self' => true]); - - DI::emailer()->send(new ItemCCEMail(DI::app(), DI::l10n(), DI::baseUrl(), - $post, $address, $author['thumb'] ?? '')); - } - } + DI::contentItem()->postProcessPost($post, $recipients); Logger::debug('post_complete'); diff --git a/src/Content/Item.php b/src/Content/Item.php index 76a3a1f4a..c4af86e6b 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -21,6 +21,7 @@ namespace Friendica\Content; +use Friendica\App; use Friendica\App\BaseURL; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\BBCode\Video; @@ -44,9 +45,11 @@ use Friendica\Model\Tag; use Friendica\Model\Post; use Friendica\Model\User; use Friendica\Network\HTTPException; +use Friendica\Object\EMail\ItemCCEMail; 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\Proxy; @@ -73,8 +76,12 @@ class Item 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, 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->activity = $activity; @@ -84,6 +91,8 @@ class Item $this->aclFormatter = $aclFormatter; $this->baseURL = $baseURL; $this->pConfig = $pConfig; + $this->emailer = $emailer; + $this->app = $app; } /** @@ -823,10 +832,10 @@ class Item // 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); @@ -850,12 +859,12 @@ class Item if (!DBA::isResult($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 @@ -874,7 +883,7 @@ class Item } else { $post['private'] = ItemModel::PUBLIC; } - + return $post; } @@ -947,7 +956,7 @@ class Item $post['guid'] = System::createUUID(); $post['uri'] = ItemModel::newURI($post['guid']); $post['verb'] = Activity::POST; - $post['received'] = DateTimeFormat::utcNow(); + $post['received'] = DateTimeFormat::utcNow(); $owner = User::getOwnerDataById($post['uid']); if (empty($post['contact-id'])) { @@ -991,4 +1000,25 @@ class Item 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'] ?? '')); + } + } } diff --git a/src/Model/Item.php b/src/Model/Item.php index d5a72c73e..f4bcb56e0 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -820,6 +820,12 @@ class Item private static function prepareOriginPost(array $item): array { $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); return $item; @@ -1301,10 +1307,7 @@ class Item } if ($notify) { - if (!\Friendica\Content\Feature::isEnabled($posted_item['uid'], 'explicit_mentions') && ($posted_item['gravity'] == self::GRAVITY_COMMENT)) { - Tag::createImplicitMentions($posted_item['uri-id'], $posted_item['thr-parent-id']); - } - Hook::callAll('post_local_end', $posted_item); + DI::contentItem()->postProcessPost($posted_item); } else { Hook::callAll('post_remote_end', $posted_item); } From 09f46b20f117dc2450d7486749cc60f9c048ee2e Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 4 Jan 2023 10:59:28 +0000 Subject: [PATCH 03/10] Functionality is split --- mod/item.php | 223 ++++++++++++---------- view/lang/C/messages.po | 411 ++++++++++++++++++++-------------------- 2 files changed, 330 insertions(+), 304 deletions(-) diff --git a/mod/item.php b/mod/item.php index 5b40a67de..b7ae4d212 100644 --- a/mod/item.php +++ b/mod/item.php @@ -54,13 +54,7 @@ function item_post(App $a) { } if (!empty($_REQUEST['dropitems'])) { - $arr_drop = explode(',', $_REQUEST['dropitems']); - foreach ($arr_drop as $item) { - Item::deleteForUser(['id' => $item], $uid); - } - - $json = ['success' => 1]; - System::jsonExit($json); + item_drop($uid, $_REQUEST['dropitems']); } Hook::callAll('post_local_start', $_REQUEST); @@ -82,39 +76,87 @@ function item_post(App $a) { } } - $post_id = intval($_REQUEST['post_id'] ?? 0); - - // is this an edited post? - if ($post_id > 0) { - $orig_post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); + if (empty($_REQUEST['post_id'])) { + item_insert($uid, $_REQUEST, $preview, $return_path); } else { - $orig_post = null; + item_edit($uid, $_REQUEST, $preview, $return_path); + } +} + +function item_drop(int $uid, string $dropitems) +{ + $arr_drop = explode(',', $dropitems); + foreach ($arr_drop as $item) { + Item::deleteForUser(['id' => $item], $uid); } - $emailcc = trim($_REQUEST['emailcc'] ?? ''); + $json = ['success' => 1]; + System::jsonExit($json); +} + +function item_edit(int $uid, array $request, bool $preview, string $return_path) +{ + $post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $request['post_id'], 'uid' => $uid]); + if (!DBA::isResult($post)) { + DI::sysmsg()->addNotice(DI::l10n()->t('Unable to locate original post.')); + if ($return_path) { + DI::baseUrl()->redirect($return_path); + } + throw new HTTPException\NotFoundException(DI::l10n()->t('Unable to locate original post.')); + } + + $post['edit'] = $post; + $post['file'] = Post\Category::getTextByURIId($post['uri-id'], $post['uid']); + + $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) +{ + $emailcc = trim($request['emailcc'] ?? ''); $post = ['uid' => $uid]; - $post = DI::contentItem()->initializePost($post); - $post['edit'] = $orig_post; - $post['self'] = true; - $post['api_source'] = false; - $post['file'] = ''; - $post['attach'] = ''; - $post['inform'] = ''; - $post['postopts'] = ''; - $post['wall'] = $_REQUEST['wall'] ?? true; - $post['post-type'] = $_REQUEST['post_type'] ?? ''; - $post['title'] = trim($_REQUEST['title'] ?? ''); - $post['body'] = $_REQUEST['body'] ?? ''; - $post['location'] = trim($_REQUEST['location'] ?? ''); - $post['coord'] = trim($_REQUEST['coord'] ?? ''); - $post['parent'] = intval($_REQUEST['parent'] ?? 0); - $post['pubmail'] = $_REQUEST['pubmail_enable'] ?? false; - $post['created'] = $_REQUEST['created_at'] ?? DateTimeFormat::utcNow(); - $post['edited'] = $post['changed'] = $post['commented'] = $post['created']; - $post['app'] = ''; + $post['edit'] = null; + $post['post-type'] = $request['post_type'] ?? ''; + $post['wall'] = $request['wall'] ?? true; + $post['parent'] = intval($request['parent'] ?? 0); + $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 ($post['parent']) { if ($post['parent']) { @@ -160,15 +202,53 @@ function item_post(App $a) { $post['thr-parent'] = $post['uri']; } - $post = DI::contentItem()->getACL($post, $parent_item, $_REQUEST); + $post = DI::contentItem()->getACL($post, $parent_item, $request); $post['pubmail'] = $post['pubmail'] && !$post['private']; - if (!empty($orig_post)) { - $post['file'] = Post\Category::getTextByURIId($orig_post['uri-id'], $orig_post['uid']); + $post = item_process($post, $request, $preview, $return_path); + + $post_id = Item::insert($post); + if (!$post_id) { + DI::sysmsg()->addNotice(DI::l10n()->t('Item wasn\'t stored.')); + if ($return_path) { + DI::baseUrl()->redirect($return_path); + } + + throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item wasn\'t stored.')); } - $post = DI::contentItem()->addCategories($post, $_REQUEST['category'] ?? ''); + $post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); + if (!DBA::isResult($post)) { + Logger::error('Item couldn\'t be fetched.', ['post_id' => $post_id]); + if ($return_path) { + DI::baseUrl()->redirect($return_path); + } + + throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item couldn\'t be fetched.')); + } + + $recipients = explode(',', $emailcc); + + DI::contentItem()->postProcessPost($post, $recipients); + + Logger::debug('post_complete'); + + item_post_return(DI::baseUrl(), $return_path); + // 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'])) { @@ -179,8 +259,8 @@ function item_post(App $a) { } // Add the attachment to the body. - if (!empty($_REQUEST['has_attachment'])) { - $post['body'] .= DI::contentItem()->storeAttachmentFromRequest($_REQUEST); + if (!empty($request['has_attachment'])) { + $post['body'] .= DI::contentItem()->storeAttachmentFromRequest($request); } $post = DI::contentItem()->finalizePost($post); @@ -224,8 +304,8 @@ function item_post(App $a) { unset($post['self']); unset($post['api_source']); - if (!empty($_REQUEST['scheduled_at'])) { - $scheduled_at = DateTimeFormat::convert($_REQUEST['scheduled_at'], 'UTC', $a->getTimeZone()); + 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']); @@ -245,69 +325,14 @@ function item_post(App $a) { } $json = ['cancel' => 1]; - if (!empty($_REQUEST['jsreload'])) { - $json['reload'] = DI::baseUrl() . '/' . $_REQUEST['jsreload']; + if (!empty($request['jsreload'])) { + $json['reload'] = DI::baseUrl() . '/' . $request['jsreload']; } System::jsonExit($json); } - if ($orig_post) { - $fields = [ - 'title' => $post['title'], - 'body' => $post['body'], - 'attach' => $post['attach'], - 'file' => $post['file'], - '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($orig_post['uri-id']); - - if ($return_path) { - DI::baseUrl()->redirect($return_path); - } - - throw new HTTPException\OKException(DI::l10n()->t('Post updated.')); - } - - $post_id = Item::insert($post); - if (!$post_id) { - DI::sysmsg()->addNotice(DI::l10n()->t('Item wasn\'t stored.')); - if ($return_path) { - DI::baseUrl()->redirect($return_path); - } - - throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item wasn\'t stored.')); - } - - $post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); - if (!DBA::isResult($post)) { - Logger::error('Item couldn\'t be fetched.', ['post_id' => $post_id]); - if ($return_path) { - DI::baseUrl()->redirect($return_path); - } - - throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item couldn\'t be fetched.')); - } - - $recipients = explode(',', $emailcc); - - DI::contentItem()->postProcessPost($post, $recipients); - - Logger::debug('post_complete'); - - item_post_return(DI::baseUrl(), $return_path); - // NOTREACHED + return $post; } function item_post_return($baseurl, $return_path) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 1872ad586..c885fa362 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -1,5 +1,5 @@ # FRIENDICA Distributed Social Network -# Copyright (C) 2010-2022, the Friendica project +# Copyright (C) 2010-2023, the Friendica project # This file is distributed under the same license as the Friendica package. # Mike Macgirvin, 2010 # @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2023.03-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-12-29 20:29+0000\n" +"POT-Creation-Date: 2023-01-04 10:58+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -18,13 +18,36 @@ msgstr "" "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." msgstr "" -#: mod/item.php:179 mod/item.php:184 mod/item.php:855 mod/message.php:69 -#: mod/message.php:114 mod/notes.php:44 mod/photos.php:157 mod/photos.php:674 -#: src/Model/Event.php:522 src/Module/Attach.php:55 src/Module/BaseApi.php:95 +#: mod/item.php:139 +msgid "Post updated." +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/Calendar/Event/API.php:88 src/Module/Calendar/Event/Form.php:84 #: src/Module/Calendar/Export.php:62 src/Module/Calendar/Show.php:82 @@ -59,28 +82,6 @@ msgstr "" msgid "Permission denied." 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 msgid "No valid account found." msgstr "" @@ -291,16 +292,16 @@ msgstr "" msgid "Insert web link" msgstr "" -#: mod/message.php:203 mod/message.php:360 mod/photos.php:1290 +#: mod/message.php:203 mod/message.php:360 mod/photos.php:1291 #: src/Content/Conversation.php:371 src/Content/Conversation.php:717 #: src/Module/Item/Compose.php:204 src/Module/Post/Edit.php:142 #: src/Module/Profile/UnkMail.php:155 src/Object/Post.php:537 msgid "Please wait" msgstr "" -#: mod/message.php:204 mod/message.php:359 mod/photos.php:707 -#: mod/photos.php:824 mod/photos.php:1096 mod/photos.php:1137 -#: mod/photos.php:1193 mod/photos.php:1267 +#: mod/message.php:204 mod/message.php:359 mod/photos.php:708 +#: mod/photos.php:825 mod/photos.php:1097 mod/photos.php:1138 +#: mod/photos.php:1194 mod/photos.php:1268 #: src/Module/Calendar/Event/Form.php:250 src/Module/Contact/Advanced.php:132 #: src/Module/Contact/Profile.php:327 #: src/Module/Debug/ActivityPubConversion.php:140 @@ -383,7 +384,7 @@ msgstr "" msgid "Save" msgstr "" -#: mod/photos.php:66 mod/photos.php:137 mod/photos.php:582 +#: mod/photos.php:67 mod/photos.php:138 mod/photos.php:583 #: src/Model/Event.php:514 src/Model/Profile.php:234 #: src/Module/Calendar/Export.php:67 src/Module/Calendar/Show.php:74 #: src/Module/DFRN/Poll.php:43 src/Module/Feed.php:65 src/Module/HCard.php:51 @@ -395,100 +396,100 @@ msgstr "" msgid "User not found." msgstr "" -#: mod/photos.php:105 src/Module/BaseProfile.php:68 +#: mod/photos.php:106 src/Module/BaseProfile.php:68 #: src/Module/Profile/Photos.php:399 msgid "Photo Albums" msgstr "" -#: mod/photos.php:106 src/Module/Profile/Photos.php:400 +#: mod/photos.php:107 src/Module/Profile/Photos.php:400 #: src/Module/Profile/Photos.php:420 msgid "Recent Photos" msgstr "" -#: mod/photos.php:108 mod/photos.php:872 src/Module/Profile/Photos.php:402 +#: mod/photos.php:109 mod/photos.php:873 src/Module/Profile/Photos.php:402 #: src/Module/Profile/Photos.php:422 msgid "Upload New Photos" msgstr "" -#: mod/photos.php:126 src/Module/BaseSettings.php:74 +#: mod/photos.php:127 src/Module/BaseSettings.php:74 #: src/Module/Profile/Photos.php:383 msgid "everybody" msgstr "" -#: mod/photos.php:164 +#: mod/photos.php:165 msgid "Contact information unavailable" msgstr "" -#: mod/photos.php:193 +#: mod/photos.php:194 msgid "Album not found." msgstr "" -#: mod/photos.php:247 +#: mod/photos.php:248 msgid "Album successfully deleted" msgstr "" -#: mod/photos.php:249 +#: mod/photos.php:250 msgid "Album was empty." msgstr "" -#: mod/photos.php:281 +#: mod/photos.php:282 msgid "Failed to delete the photo." msgstr "" -#: mod/photos.php:549 +#: mod/photos.php:550 msgid "a photo" msgstr "" -#: mod/photos.php:549 +#: mod/photos.php:550 #, php-format msgid "%1$s was tagged in %2$s by %3$s" msgstr "" -#: mod/photos.php:586 src/Module/Conversation/Community.php:187 +#: mod/photos.php:587 src/Module/Conversation/Community.php:187 #: src/Module/Directory.php:48 src/Module/Profile/Photos.php:315 #: src/Module/Search/Index.php:64 msgid "Public access denied." msgstr "" -#: mod/photos.php:591 +#: mod/photos.php:592 msgid "No photos selected" msgstr "" -#: mod/photos.php:723 +#: mod/photos.php:724 #, php-format msgid "The maximum accepted image size is %s" msgstr "" -#: mod/photos.php:730 +#: mod/photos.php:731 msgid "Upload Photos" msgstr "" -#: mod/photos.php:734 mod/photos.php:820 +#: mod/photos.php:735 mod/photos.php:821 msgid "New album name: " msgstr "" -#: mod/photos.php:735 +#: mod/photos.php:736 msgid "or select existing album:" msgstr "" -#: mod/photos.php:736 +#: mod/photos.php:737 msgid "Do not show a status post for this upload" msgstr "" -#: mod/photos.php:738 mod/photos.php:1092 src/Content/Conversation.php:373 +#: mod/photos.php:739 mod/photos.php:1093 src/Content/Conversation.php:373 #: src/Module/Calendar/Event/Form.php:253 src/Module/Post/Edit.php:179 msgid "Permissions" msgstr "" -#: mod/photos.php:801 +#: mod/photos.php:802 msgid "Do you really want to delete this photo album and all its photos?" msgstr "" -#: mod/photos.php:802 mod/photos.php:825 +#: mod/photos.php:803 mod/photos.php:826 msgid "Delete Album" msgstr "" -#: mod/photos.php:803 mod/photos.php:904 src/Content/Conversation.php:389 +#: mod/photos.php:804 mod/photos.php:905 src/Content/Conversation.php:389 #: src/Module/Contact/Follow.php:172 src/Module/Contact/Revoke.php:109 #: src/Module/Contact/Unfollow.php:126 #: src/Module/Media/Attachment/Browser.php:77 @@ -498,130 +499,130 @@ msgstr "" msgid "Cancel" msgstr "" -#: mod/photos.php:829 +#: mod/photos.php:830 msgid "Edit Album" msgstr "" -#: mod/photos.php:830 +#: mod/photos.php:831 msgid "Drop Album" msgstr "" -#: mod/photos.php:834 +#: mod/photos.php:835 msgid "Show Newest First" msgstr "" -#: mod/photos.php:836 +#: mod/photos.php:837 msgid "Show Oldest First" msgstr "" -#: mod/photos.php:857 src/Module/Profile/Photos.php:370 +#: mod/photos.php:858 src/Module/Profile/Photos.php:370 msgid "View Photo" msgstr "" -#: mod/photos.php:890 +#: mod/photos.php:891 msgid "Permission denied. Access to this item may be restricted." msgstr "" -#: mod/photos.php:892 +#: mod/photos.php:893 msgid "Photo not available" msgstr "" -#: mod/photos.php:902 +#: mod/photos.php:903 msgid "Do you really want to delete this photo?" msgstr "" -#: mod/photos.php:903 mod/photos.php:1097 +#: mod/photos.php:904 mod/photos.php:1098 msgid "Delete Photo" msgstr "" -#: mod/photos.php:995 +#: mod/photos.php:996 msgid "View photo" msgstr "" -#: mod/photos.php:997 +#: mod/photos.php:998 msgid "Edit photo" msgstr "" -#: mod/photos.php:998 +#: mod/photos.php:999 msgid "Delete photo" msgstr "" -#: mod/photos.php:999 +#: mod/photos.php:1000 msgid "Use as profile photo" msgstr "" -#: mod/photos.php:1006 +#: mod/photos.php:1007 msgid "Private Photo" msgstr "" -#: mod/photos.php:1012 +#: mod/photos.php:1013 msgid "View Full Size" msgstr "" -#: mod/photos.php:1065 +#: mod/photos.php:1066 msgid "Tags: " msgstr "" -#: mod/photos.php:1068 +#: mod/photos.php:1069 msgid "[Select tags to remove]" msgstr "" -#: mod/photos.php:1083 +#: mod/photos.php:1084 msgid "New album name" msgstr "" -#: mod/photos.php:1084 +#: mod/photos.php:1085 msgid "Caption" msgstr "" -#: mod/photos.php:1085 +#: mod/photos.php:1086 msgid "Add a Tag" msgstr "" -#: mod/photos.php:1085 +#: mod/photos.php:1086 msgid "Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping" msgstr "" -#: mod/photos.php:1086 +#: mod/photos.php:1087 msgid "Do not rotate" msgstr "" -#: mod/photos.php:1087 +#: mod/photos.php:1088 msgid "Rotate CW (right)" msgstr "" -#: mod/photos.php:1088 +#: mod/photos.php:1089 msgid "Rotate CCW (left)" msgstr "" -#: mod/photos.php:1134 mod/photos.php:1190 mod/photos.php:1264 -#: src/Module/Contact.php:550 src/Module/Item/Compose.php:188 +#: mod/photos.php:1135 mod/photos.php:1191 mod/photos.php:1265 +#: src/Module/Contact.php:557 src/Module/Item/Compose.php:188 #: src/Object/Post.php:983 msgid "This is you" msgstr "" -#: mod/photos.php:1136 mod/photos.php:1192 mod/photos.php:1266 +#: mod/photos.php:1137 mod/photos.php:1193 mod/photos.php:1267 #: src/Object/Post.php:531 src/Object/Post.php:985 msgid "Comment" msgstr "" -#: mod/photos.php:1138 mod/photos.php:1194 mod/photos.php:1268 +#: mod/photos.php:1139 mod/photos.php:1195 mod/photos.php:1269 #: src/Content/Conversation.php:386 src/Module/Calendar/Event/Form.php:248 #: src/Module/Item/Compose.php:199 src/Module/Post/Edit.php:162 #: src/Object/Post.php:997 msgid "Preview" msgstr "" -#: mod/photos.php:1139 src/Content/Conversation.php:341 +#: mod/photos.php:1140 src/Content/Conversation.php:341 #: src/Module/Post/Edit.php:127 src/Object/Post.php:987 msgid "Loading..." msgstr "" -#: mod/photos.php:1225 src/Content/Conversation.php:633 src/Object/Post.php:255 +#: mod/photos.php:1226 src/Content/Conversation.php:633 src/Object/Post.php:255 msgid "Select" msgstr "" -#: mod/photos.php:1226 src/Content/Conversation.php:634 +#: mod/photos.php:1227 src/Content/Conversation.php:634 #: src/Module/Moderation/Users/Active.php:136 #: src/Module/Moderation/Users/Blocked.php:136 #: src/Module/Moderation/Users/Index.php:151 @@ -629,23 +630,23 @@ msgstr "" msgid "Delete" msgstr "" -#: mod/photos.php:1287 src/Object/Post.php:378 +#: mod/photos.php:1288 src/Object/Post.php:378 msgid "Like" msgstr "" -#: mod/photos.php:1288 src/Object/Post.php:378 +#: mod/photos.php:1289 src/Object/Post.php:378 msgid "I like this (toggle)" msgstr "" -#: mod/photos.php:1289 src/Object/Post.php:379 +#: mod/photos.php:1290 src/Object/Post.php:379 msgid "Dislike" msgstr "" -#: mod/photos.php:1291 src/Object/Post.php:379 +#: mod/photos.php:1292 src/Object/Post.php:379 msgid "I don't like this (toggle)" msgstr "" -#: mod/photos.php:1313 +#: mod/photos.php:1314 msgid "Map" msgstr "" @@ -695,16 +696,16 @@ msgid "All contacts" msgstr "" #: src/BaseModule.php:432 src/Content/Widget.php:235 src/Core/ACL.php:194 -#: src/Module/Contact.php:371 src/Module/PermissionTooltip.php:122 +#: src/Module/Contact.php:378 src/Module/PermissionTooltip.php:122 #: src/Module/PermissionTooltip.php:144 msgid "Followers" msgstr "" -#: src/BaseModule.php:437 src/Content/Widget.php:236 src/Module/Contact.php:372 +#: src/BaseModule.php:437 src/Content/Widget.php:236 src/Module/Contact.php:379 msgid "Following" msgstr "" -#: src/BaseModule.php:442 src/Content/Widget.php:237 src/Module/Contact.php:373 +#: src/BaseModule.php:442 src/Content/Widget.php:237 src/Module/Contact.php:380 msgid "Mutual friends" msgstr "" @@ -1516,58 +1517,58 @@ msgstr "" msgid "show more" msgstr "" -#: src/Content/Item.php:294 src/Model/Item.php:2925 +#: src/Content/Item.php:326 src/Model/Item.php:2893 msgid "event" 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 msgid "status" 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 msgid "photo" 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 msgid "%1$s tagged %2$s's %3$s with %4$s" 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" msgstr "" -#: src/Content/Item.php:387 src/Model/Contact.php:1200 +#: src/Content/Item.php:419 src/Model/Contact.php:1205 msgid "View Status" msgstr "" -#: src/Content/Item.php:388 src/Content/Item.php:406 src/Model/Contact.php:1144 -#: src/Model/Contact.php:1192 src/Model/Contact.php:1201 +#: 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/Module/Directory.php:157 src/Module/Settings/Profile/Index.php:234 msgid "View Profile" msgstr "" -#: src/Content/Item.php:389 src/Model/Contact.php:1202 +#: src/Content/Item.php:421 src/Model/Contact.php:1207 msgid "View Photos" msgstr "" -#: src/Content/Item.php:390 src/Model/Contact.php:1193 -#: src/Model/Contact.php:1203 +#: src/Content/Item.php:422 src/Model/Contact.php:1198 +#: src/Model/Contact.php:1208 msgid "Network Posts" msgstr "" -#: src/Content/Item.php:391 src/Model/Contact.php:1194 -#: src/Model/Contact.php:1204 +#: src/Content/Item.php:423 src/Model/Contact.php:1199 +#: src/Model/Contact.php:1209 msgid "View Contact" msgstr "" -#: src/Content/Item.php:392 src/Model/Contact.php:1205 +#: src/Content/Item.php:424 src/Model/Contact.php:1210 msgid "Send PM" msgstr "" -#: src/Content/Item.php:393 src/Module/Contact.php:402 +#: src/Content/Item.php:425 src/Module/Contact.php:409 #: src/Module/Contact/Profile.php:348 src/Module/Contact/Profile.php:467 #: src/Module/Moderation/Blocklist/Contact.php:116 #: src/Module/Moderation/Users/Active.php:137 @@ -1575,7 +1576,7 @@ msgstr "" msgid "Block" msgstr "" -#: src/Content/Item.php:394 src/Module/Contact.php:403 +#: src/Content/Item.php:426 src/Module/Contact.php:410 #: src/Module/Contact/Profile.php:349 src/Module/Contact/Profile.php:475 #: src/Module/Notifications/Introductions.php:134 #: src/Module/Notifications/Introductions.php:206 @@ -1583,12 +1584,12 @@ msgstr "" msgid "Ignore" msgstr "" -#: src/Content/Item.php:398 src/Object/Post.php:454 +#: src/Content/Item.php:430 src/Object/Post.php:454 msgid "Languages" msgstr "" -#: src/Content/Item.php:403 src/Content/Widget.php:80 -#: src/Model/Contact.php:1195 src/Model/Contact.php:1206 +#: src/Content/Item.php:435 src/Content/Widget.php:80 +#: src/Model/Contact.php:1200 src/Model/Contact.php:1211 #: src/Module/Contact/Follow.php:166 view/theme/vier/theme.php:196 msgid "Connect/Follow" msgstr "" @@ -1627,7 +1628,7 @@ msgid "Sign in" msgstr "" #: src/Content/Nav.php:193 src/Module/BaseProfile.php:57 -#: src/Module/Contact.php:437 src/Module/Contact/Profile.php:380 +#: src/Module/Contact.php:444 src/Module/Contact/Profile.php:380 #: src/Module/Settings/TwoFactor/Index.php:119 view/theme/frio/theme.php:236 msgid "Status" msgstr "" @@ -1638,7 +1639,7 @@ msgid "Your posts and conversations" msgstr "" #: src/Content/Nav.php:194 src/Module/BaseProfile.php:49 -#: src/Module/BaseSettings.php:100 src/Module/Contact.php:461 +#: src/Module/BaseSettings.php:100 src/Module/Contact.php:468 #: src/Module/Contact/Profile.php:382 src/Module/Profile/Profile.php:268 #: src/Module/Welcome.php:57 view/theme/frio/theme.php:237 msgid "Profile" @@ -1658,7 +1659,7 @@ msgid "Your photos" msgstr "" #: src/Content/Nav.php:196 src/Module/BaseProfile.php:73 -#: src/Module/BaseProfile.php:76 src/Module/Contact.php:453 +#: src/Module/BaseProfile.php:76 src/Module/Contact.php:460 #: view/theme/frio/theme.php:242 msgid "Media" msgstr "" @@ -1744,8 +1745,8 @@ msgstr "" #: src/Content/Nav.php:238 src/Content/Nav.php:293 #: src/Content/Text/HTML.php:900 src/Module/BaseProfile.php:127 -#: src/Module/BaseProfile.php:130 src/Module/Contact.php:374 -#: src/Module/Contact.php:468 view/theme/frio/theme.php:250 +#: src/Module/BaseProfile.php:130 src/Module/Contact.php:381 +#: src/Module/Contact.php:475 view/theme/frio/theme.php:250 msgid "Contacts" msgstr "" @@ -1920,8 +1921,8 @@ msgid "" "%2$s %3$s" msgstr "" -#: src/Content/Text/BBCode.php:1257 src/Model/Item.php:3586 -#: src/Model/Item.php:3592 src/Model/Item.php:3593 +#: src/Content/Text/BBCode.php:1257 src/Model/Item.php:3556 +#: src/Model/Item.php:3562 src/Model/Item.php:3563 msgid "Link to source" msgstr "" @@ -1993,7 +1994,7 @@ msgstr "" msgid "Examples: Robert Morgenstein, Fishing" msgstr "" -#: src/Content/Widget.php:82 src/Module/Contact.php:395 +#: src/Content/Widget.php:82 src/Module/Contact.php:402 #: src/Module/Directory.php:96 view/theme/vier/theme.php:198 msgid "Find" msgstr "" @@ -2025,7 +2026,7 @@ msgid "Local Directory" msgstr "" #: src/Content/Widget.php:211 src/Model/Group.php:587 -#: src/Module/Contact.php:358 src/Module/Welcome.php:76 +#: src/Module/Contact.php:365 src/Module/Welcome.php:76 msgid "Groups" msgstr "" @@ -2037,7 +2038,7 @@ msgstr "" msgid "Relationships" msgstr "" -#: src/Content/Widget.php:244 src/Module/Contact.php:310 +#: src/Content/Widget.php:244 src/Module/Contact.php:317 #: src/Module/Group.php:291 msgid "All Contacts" msgstr "" @@ -2081,7 +2082,7 @@ msgstr "" msgid "Organisations" msgstr "" -#: src/Content/Widget.php:523 src/Model/Contact.php:1648 +#: src/Content/Widget.php:523 src/Model/Contact.php:1657 msgid "News" msgstr "" @@ -2162,8 +2163,8 @@ msgstr "" msgid "Network:" msgstr "" -#: src/Content/Widget/VCard.php:111 src/Model/Contact.php:1196 -#: src/Model/Contact.php:1207 src/Model/Profile.php:465 +#: src/Content/Widget/VCard.php:111 src/Model/Contact.php:1201 +#: src/Model/Contact.php:1212 src/Model/Profile.php:465 #: src/Module/Contact/Profile.php:419 msgid "Unfollow" msgstr "" @@ -2866,82 +2867,82 @@ msgstr "" msgid "Legacy module file not found: %s" msgstr "" -#: src/Model/Contact.php:1213 src/Module/Moderation/Users/Pending.php:102 +#: src/Model/Contact.php:1218 src/Module/Moderation/Users/Pending.php:102 #: src/Module/Notifications/Introductions.php:132 #: src/Module/Notifications/Introductions.php:204 msgid "Approve" msgstr "" -#: src/Model/Contact.php:1644 +#: src/Model/Contact.php:1653 msgid "Organisation" msgstr "" -#: src/Model/Contact.php:1652 +#: src/Model/Contact.php:1661 msgid "Forum" msgstr "" -#: src/Model/Contact.php:2919 +#: src/Model/Contact.php:2928 msgid "Disallowed profile URL." msgstr "" -#: src/Model/Contact.php:2924 src/Module/Friendica.php:82 +#: src/Model/Contact.php:2933 src/Module/Friendica.php:83 msgid "Blocked domain" msgstr "" -#: src/Model/Contact.php:2929 +#: src/Model/Contact.php:2938 msgid "Connect URL missing." msgstr "" -#: src/Model/Contact.php:2938 +#: src/Model/Contact.php:2947 msgid "" "The contact could not be added. Please check the relevant network " "credentials in your Settings -> Social Networks page." msgstr "" -#: src/Model/Contact.php:2956 +#: src/Model/Contact.php:2965 #, php-format msgid "Expected network %s does not match actual network %s" msgstr "" -#: src/Model/Contact.php:2973 +#: src/Model/Contact.php:2982 msgid "The profile address specified does not provide adequate information." msgstr "" -#: src/Model/Contact.php:2975 +#: src/Model/Contact.php:2984 msgid "No compatible communication protocols or feeds were discovered." msgstr "" -#: src/Model/Contact.php:2978 +#: src/Model/Contact.php:2987 msgid "An author or name was not found." msgstr "" -#: src/Model/Contact.php:2981 +#: src/Model/Contact.php:2990 msgid "No browser URL could be matched to this address." msgstr "" -#: src/Model/Contact.php:2984 +#: src/Model/Contact.php:2993 msgid "" "Unable to match @-style Identity Address with a known protocol or email " "contact." msgstr "" -#: src/Model/Contact.php:2985 +#: src/Model/Contact.php:2994 msgid "Use mailto: in front of address to force email check." msgstr "" -#: src/Model/Contact.php:2991 +#: src/Model/Contact.php:3000 msgid "" "The profile address specified belongs to a network which has been disabled " "on this site." msgstr "" -#: src/Model/Contact.php:2996 +#: src/Model/Contact.php:3005 msgid "" "Limited profile. This person will be unable to receive direct/personal " "notifications from you." msgstr "" -#: src/Model/Contact.php:3061 +#: src/Model/Contact.php:3070 msgid "Unable to retrieve contact information." msgstr "" @@ -3090,66 +3091,66 @@ msgstr "" msgid "Edit groups" msgstr "" -#: src/Model/Item.php:2026 +#: src/Model/Item.php:1994 #, php-format msgid "Detected languages in this post:\\n%s" msgstr "" -#: src/Model/Item.php:2929 +#: src/Model/Item.php:2897 msgid "activity" msgstr "" -#: src/Model/Item.php:2931 +#: src/Model/Item.php:2899 msgid "comment" msgstr "" -#: src/Model/Item.php:2934 +#: src/Model/Item.php:2902 msgid "post" msgstr "" -#: src/Model/Item.php:3082 +#: src/Model/Item.php:3050 #, php-format msgid "Content warning: %s" msgstr "" -#: src/Model/Item.php:3498 +#: src/Model/Item.php:3468 msgid "bytes" msgstr "" -#: src/Model/Item.php:3529 +#: src/Model/Item.php:3499 #, php-format msgid "%2$s (%3$d%%, %1$d vote)" msgid_plural "%2$s (%3$d%%, %1$d votes)" msgstr[0] "" msgstr[1] "" -#: src/Model/Item.php:3531 +#: src/Model/Item.php:3501 #, php-format msgid "%2$s (%1$d vote)" msgid_plural "%2$s (%1$d votes)" msgstr[0] "" msgstr[1] "" -#: src/Model/Item.php:3536 +#: src/Model/Item.php:3506 #, php-format msgid "%d voter. Poll end: %s" msgid_plural "%d voters. Poll end: %s" msgstr[0] "" msgstr[1] "" -#: src/Model/Item.php:3538 +#: src/Model/Item.php:3508 #, php-format msgid "%d voter." msgid_plural "%d voters." msgstr[0] "" msgstr[1] "" -#: src/Model/Item.php:3540 +#: src/Model/Item.php:3510 #, php-format msgid "Poll end: %s" msgstr "" -#: src/Model/Item.php:3574 src/Model/Item.php:3575 +#: src/Model/Item.php:3544 src/Model/Item.php:3545 msgid "View on separate page" msgstr "" @@ -4093,7 +4094,7 @@ msgid "Policies" msgstr "" #: src/Module/Admin/Site.php:441 src/Module/Calendar/Event/Form.php:252 -#: src/Module/Contact.php:478 src/Module/Profile/Profile.php:276 +#: src/Module/Contact.php:485 src/Module/Profile/Profile.php:276 msgid "Advanced" msgstr "" @@ -5392,11 +5393,11 @@ msgstr "" msgid "Item Source" msgstr "" -#: src/Module/BaseProfile.php:52 src/Module/Contact.php:464 +#: src/Module/BaseProfile.php:52 src/Module/Contact.php:471 msgid "Profile Details" msgstr "" -#: src/Module/BaseProfile.php:60 src/Module/Contact.php:448 +#: src/Module/BaseProfile.php:60 src/Module/Contact.php:455 #: src/Module/Contact/Follow.php:191 src/Module/Contact/Unfollow.php:138 msgid "Status Messages and Posts" msgstr "" @@ -5584,78 +5585,78 @@ msgstr "" msgid "list" msgstr "" -#: src/Module/Contact.php:89 +#: src/Module/Contact.php:92 #, php-format msgid "%d contact edited." msgid_plural "%d contacts edited." msgstr[0] "" msgstr[1] "" -#: src/Module/Contact.php:313 +#: src/Module/Contact.php:320 msgid "Show all contacts" msgstr "" -#: src/Module/Contact.php:318 src/Module/Contact.php:378 +#: src/Module/Contact.php:325 src/Module/Contact.php:385 #: src/Module/Moderation/BaseUsers.php:85 msgid "Pending" msgstr "" -#: src/Module/Contact.php:321 +#: src/Module/Contact.php:328 msgid "Only show pending contacts" msgstr "" -#: src/Module/Contact.php:326 src/Module/Contact.php:379 +#: src/Module/Contact.php:333 src/Module/Contact.php:386 #: src/Module/Moderation/BaseUsers.php:93 msgid "Blocked" msgstr "" -#: src/Module/Contact.php:329 +#: src/Module/Contact.php:336 msgid "Only show blocked contacts" msgstr "" -#: src/Module/Contact.php:334 src/Module/Contact.php:381 +#: src/Module/Contact.php:341 src/Module/Contact.php:388 #: src/Object/Post.php:338 msgid "Ignored" msgstr "" -#: src/Module/Contact.php:337 +#: src/Module/Contact.php:344 msgid "Only show ignored contacts" msgstr "" -#: src/Module/Contact.php:342 src/Module/Contact.php:382 +#: src/Module/Contact.php:349 src/Module/Contact.php:389 msgid "Archived" msgstr "" -#: src/Module/Contact.php:345 +#: src/Module/Contact.php:352 msgid "Only show archived contacts" msgstr "" -#: src/Module/Contact.php:350 src/Module/Contact.php:380 +#: src/Module/Contact.php:357 src/Module/Contact.php:387 msgid "Hidden" msgstr "" -#: src/Module/Contact.php:353 +#: src/Module/Contact.php:360 msgid "Only show hidden contacts" msgstr "" -#: src/Module/Contact.php:361 +#: src/Module/Contact.php:368 msgid "Organize your contact groups" msgstr "" -#: src/Module/Contact.php:393 +#: src/Module/Contact.php:400 msgid "Search your contacts" msgstr "" -#: src/Module/Contact.php:394 src/Module/Search/Index.php:206 +#: src/Module/Contact.php:401 src/Module/Search/Index.php:206 #, php-format msgid "Results for: %s" msgstr "" -#: src/Module/Contact.php:401 +#: src/Module/Contact.php:408 msgid "Update" msgstr "" -#: src/Module/Contact.php:402 src/Module/Contact/Profile.php:348 +#: src/Module/Contact.php:409 src/Module/Contact/Profile.php:348 #: src/Module/Contact/Profile.php:467 #: src/Module/Moderation/Blocklist/Contact.php:117 #: src/Module/Moderation/Users/Blocked.php:138 @@ -5663,56 +5664,56 @@ msgstr "" msgid "Unblock" msgstr "" -#: src/Module/Contact.php:403 src/Module/Contact/Profile.php:349 +#: src/Module/Contact.php:410 src/Module/Contact/Profile.php:349 #: src/Module/Contact/Profile.php:475 msgid "Unignore" msgstr "" -#: src/Module/Contact.php:405 +#: src/Module/Contact.php:412 msgid "Batch Actions" msgstr "" -#: src/Module/Contact.php:440 +#: src/Module/Contact.php:447 msgid "Conversations started by this contact" msgstr "" -#: src/Module/Contact.php:445 +#: src/Module/Contact.php:452 msgid "Posts and Comments" msgstr "" -#: src/Module/Contact.php:456 +#: src/Module/Contact.php:463 msgid "Posts containing media objects" msgstr "" -#: src/Module/Contact.php:471 +#: src/Module/Contact.php:478 msgid "View all known contacts" msgstr "" -#: src/Module/Contact.php:481 +#: src/Module/Contact.php:488 msgid "Advanced Contact Settings" msgstr "" -#: src/Module/Contact.php:517 +#: src/Module/Contact.php:524 msgid "Mutual Friendship" msgstr "" -#: src/Module/Contact.php:521 +#: src/Module/Contact.php:528 msgid "is a fan of yours" msgstr "" -#: src/Module/Contact.php:525 +#: src/Module/Contact.php:532 msgid "you are a fan of" msgstr "" -#: src/Module/Contact.php:543 +#: src/Module/Contact.php:550 msgid "Pending outgoing contact request" msgstr "" -#: src/Module/Contact.php:545 +#: src/Module/Contact.php:552 msgid "Pending incoming contact request" msgstr "" -#: src/Module/Contact.php:558 src/Module/Contact/Profile.php:334 +#: src/Module/Contact.php:565 src/Module/Contact/Profile.php:334 #, php-format msgid "Visit %s's profile [%s]" msgstr "" @@ -6633,55 +6634,55 @@ msgstr "" msgid "Suggest a friend for %s" msgstr "" -#: src/Module/Friendica.php:63 +#: src/Module/Friendica.php:64 msgid "Installed addons/apps:" msgstr "" -#: src/Module/Friendica.php:68 +#: src/Module/Friendica.php:69 msgid "No installed addons/apps" msgstr "" -#: src/Module/Friendica.php:73 +#: src/Module/Friendica.php:74 #, php-format msgid "Read about the Terms of Service of this node." msgstr "" -#: src/Module/Friendica.php:80 +#: src/Module/Friendica.php:81 msgid "On this server the following remote servers are blocked." msgstr "" -#: src/Module/Friendica.php:83 +#: src/Module/Friendica.php:84 #: src/Module/Moderation/Blocklist/Server/Index.php:84 #: src/Module/Moderation/Blocklist/Server/Index.php:108 msgid "Reason for the block" msgstr "" -#: src/Module/Friendica.php:85 +#: src/Module/Friendica.php:86 msgid "Download this list in CSV format" msgstr "" -#: src/Module/Friendica.php:99 +#: src/Module/Friendica.php:100 #, php-format msgid "" "This is Friendica, version %s that is running at the web location %s. The " "database version is %s, the post update version is %s." msgstr "" -#: src/Module/Friendica.php:104 +#: src/Module/Friendica.php:105 msgid "" "Please visit Friendi.ca to learn more " "about the Friendica project." msgstr "" -#: src/Module/Friendica.php:105 +#: src/Module/Friendica.php:106 msgid "Bug reports and issues: please visit" msgstr "" -#: src/Module/Friendica.php:105 +#: src/Module/Friendica.php:106 msgid "the bugtracker at github" msgstr "" -#: src/Module/Friendica.php:106 +#: src/Module/Friendica.php:107 msgid "" "Suggestions, praise, etc. - please email \"info\" at \"friendi - dot - ca" msgstr "" @@ -8123,21 +8124,21 @@ msgstr "" msgid "BCC: %s
" msgstr "" -#: src/Module/Photo.php:128 +#: src/Module/Photo.php:129 msgid "The Photo is not available." msgstr "" -#: src/Module/Photo.php:141 +#: src/Module/Photo.php:142 #, php-format msgid "The Photo with id %s is not available." msgstr "" -#: src/Module/Photo.php:178 +#: src/Module/Photo.php:179 #, php-format msgid "Invalid external resource with url %s." msgstr "" -#: src/Module/Photo.php:180 +#: src/Module/Photo.php:181 #, php-format msgid "Invalid photo with id %s." msgstr "" @@ -8546,7 +8547,7 @@ msgstr "" msgid "Your registration is pending approval by the site owner." msgstr "" -#: src/Module/Search/Acl.php:55 +#: src/Module/Search/Acl.php:73 msgid "You must be logged in to use this module." msgstr "" @@ -11247,7 +11248,7 @@ msgstr "" msgid "Show fewer" msgstr "" -#: src/Protocol/Delivery.php:535 +#: src/Protocol/Delivery.php:547 msgid "(no subject)" msgstr "" From 9a1a406c038e21ca1de124a7271372a977ea0d7e Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 4 Jan 2023 21:52:02 +0000 Subject: [PATCH 04/10] Preview of attached links work again --- src/Content/Item.php | 18 +++++++++--------- src/Model/Item.php | 6 ++++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Content/Item.php b/src/Content/Item.php index c4af86e6b..968509dee 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -948,15 +948,15 @@ class Item public function initializePost(array $post): array { - $post['wall'] = true; - $post['origin'] = true; - $post['network'] = Protocol::DFRN; - $post['protocol'] = Conversation::PARCEL_DIRECT; - $post['direction'] = Conversation::PUSH; - $post['guid'] = System::createUUID(); - $post['uri'] = ItemModel::newURI($post['guid']); - $post['verb'] = Activity::POST; - $post['received'] = DateTimeFormat::utcNow(); + $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'])) { diff --git a/src/Model/Item.php b/src/Model/Item.php index f4bcb56e0..1eaa7cff2 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -2984,13 +2984,15 @@ class Item $item['hashtags'] = $tags['hashtags']; $item['mentions'] = $tags['mentions']; - $item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $item['body']); - if (!$is_preview) { + $item['body'] = preg_replace("#\s*\[attachment .*?].*?\[/attachment]\s*#ism", "\n", $item['body']); $item['body'] = Post\Media::removeFromEndOfBody($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']; From d22712956baa99bb22b01ecdf4400c238ba78dca Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 7 Jan 2023 17:16:44 +0000 Subject: [PATCH 05/10] Updated messages.po --- view/lang/C/messages.po | 68 +++++++++++++++++++++++++++-------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 253c85334..ab6101923 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2023.03-dev\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" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -23,9 +23,31 @@ msgstr "" msgid "Unable to locate original post." msgstr "" -#: mod/item.php:179 mod/item.php:184 mod/item.php:855 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 +#: mod/item.php:139 +msgid "Post updated." +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/Calendar/Event/API.php:88 src/Module/Calendar/Event/Form.php:84 #: src/Module/Calendar/Export.php:62 src/Module/Calendar/Show.php:82 @@ -1518,35 +1540,35 @@ msgstr "" msgid "Follow Thread" msgstr "" -#: src/Content/Item.php:387 src/Model/Contact.php:1205 +#: src/Content/Item.php:419 src/Model/Contact.php:1205 msgid "View Status" 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/Module/Directory.php:157 src/Module/Settings/Profile/Index.php:234 msgid "View Profile" msgstr "" -#: src/Content/Item.php:389 src/Model/Contact.php:1207 +#: src/Content/Item.php:421 src/Model/Contact.php:1207 msgid "View Photos" 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 msgid "Network Posts" 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 msgid "View Contact" msgstr "" -#: src/Content/Item.php:392 src/Model/Contact.php:1210 +#: src/Content/Item.php:424 src/Model/Contact.php:1210 msgid "Send PM" 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/Moderation/Blocklist/Contact.php:116 #: src/Module/Moderation/Users/Active.php:137 @@ -1554,7 +1576,7 @@ msgstr "" msgid "Block" 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/Notifications/Introductions.php:134 #: src/Module/Notifications/Introductions.php:206 @@ -1566,7 +1588,7 @@ msgstr "" msgid "Languages" 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/Module/Contact/Follow.php:166 view/theme/vier/theme.php:196 msgid "Connect/Follow" @@ -1899,8 +1921,8 @@ msgid "" "%2$s %3$s" msgstr "" -#: src/Content/Text/BBCode.php:1257 src/Model/Item.php:3588 -#: src/Model/Item.php:3594 src/Model/Item.php:3595 +#: src/Content/Text/BBCode.php:1257 src/Model/Item.php:3558 +#: src/Model/Item.php:3564 src/Model/Item.php:3565 msgid "Link to source" msgstr "" @@ -3086,49 +3108,49 @@ msgstr "" msgid "post" msgstr "" -#: src/Model/Item.php:3050 +#: src/Model/Item.php:3052 #, php-format msgid "Content warning: %s" msgstr "" -#: src/Model/Item.php:3500 +#: src/Model/Item.php:3470 msgid "bytes" msgstr "" -#: src/Model/Item.php:3531 +#: src/Model/Item.php:3501 #, php-format msgid "%2$s (%3$d%%, %1$d vote)" msgid_plural "%2$s (%3$d%%, %1$d votes)" msgstr[0] "" msgstr[1] "" -#: src/Model/Item.php:3533 +#: src/Model/Item.php:3503 #, php-format msgid "%2$s (%1$d vote)" msgid_plural "%2$s (%1$d votes)" msgstr[0] "" msgstr[1] "" -#: src/Model/Item.php:3538 +#: src/Model/Item.php:3508 #, php-format msgid "%d voter. Poll end: %s" msgid_plural "%d voters. Poll end: %s" msgstr[0] "" msgstr[1] "" -#: src/Model/Item.php:3540 +#: src/Model/Item.php:3510 #, php-format msgid "%d voter." msgid_plural "%d voters." msgstr[0] "" msgstr[1] "" -#: src/Model/Item.php:3542 +#: src/Model/Item.php:3512 #, php-format msgid "Poll end: %s" 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" msgstr "" From 8654b39e986481155aaed297dc090f4ca7589e4c Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 7 Jan 2023 18:07:54 +0000 Subject: [PATCH 06/10] Simplified code --- mod/item.php | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/mod/item.php b/mod/item.php index b7ae4d212..9a9b5e8db 100644 --- a/mod/item.php +++ b/mod/item.php @@ -141,7 +141,8 @@ function item_edit(int $uid, array $request, bool $preview, string $return_path) function item_insert(int $uid, array $request, bool $preview, string $return_path) { - $emailcc = trim($request['emailcc'] ?? ''); + $emailcc = trim($request['emailcc'] ?? ''); + $parent_id = intval($request['parent'] ?? 0); $post = ['uid' => $uid]; $post = DI::contentItem()->initializePost($post); @@ -149,7 +150,6 @@ function item_insert(int $uid, array $request, bool $preview, string $return_pat $post['edit'] = null; $post['post-type'] = $request['post_type'] ?? ''; $post['wall'] = $request['wall'] ?? true; - $post['parent'] = intval($request['parent'] ?? 0); $post['pubmail'] = $request['pubmail_enable'] ?? false; $post['created'] = $request['created_at'] ?? DateTimeFormat::utcNow(); $post['edited'] = $post['changed'] = $post['commented'] = $post['created']; @@ -158,23 +158,18 @@ function item_insert(int $uid, array $request, bool $preview, string $return_pat $post['postopts'] = ''; $post['file'] = ''; - if ($post['parent']) { - if ($post['parent']) { - $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post['parent']]); - } - - // if this isn't the top-level parent of the conversation, find it + if ($parent_id) { + $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $parent_id]); if (DBA::isResult($parent_item)) { - // The URI and the contact is taken from the direct parent which needn't to be the top parent - $post['thr-parent'] = $parent_item['uri']; - $toplevel_item = $parent_item; - + // if this isn't the top-level parent of the conversation, find it 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) { DI::baseUrl()->redirect($return_path); @@ -187,17 +182,13 @@ function item_insert(int $uid, array $request, bool $preview, string $return_pat if ($toplevel_item['uid'] == 0) { $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' => $post['uid'], 'stored' => $stored]); - if ($stored) { - $toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $stored]); - } } - $post['parent'] = $toplevel_item['id']; $post['gravity'] = Item::GRAVITY_COMMENT; + $post['thr-parent'] = $parent_item['uri']; $post['wall'] = $toplevel_item['wall']; } else { $parent_item = []; - $post['parent'] = 0; $post['gravity'] = Item::GRAVITY_PARENT; $post['thr-parent'] = $post['uri']; } From 6a0a13855f503849c244d48183e86d8dfa069b50 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 7 Jan 2023 18:19:04 +0000 Subject: [PATCH 07/10] More simplifications --- mod/item.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mod/item.php b/mod/item.php index 9a9b5e8db..8eb1403f3 100644 --- a/mod/item.php +++ b/mod/item.php @@ -141,9 +141,6 @@ function item_edit(int $uid, array $request, bool $preview, string $return_path) function item_insert(int $uid, array $request, bool $preview, string $return_path) { - $emailcc = trim($request['emailcc'] ?? ''); - $parent_id = intval($request['parent'] ?? 0); - $post = ['uid' => $uid]; $post = DI::contentItem()->initializePost($post); @@ -158,8 +155,8 @@ function item_insert(int $uid, array $request, bool $preview, string $return_pat $post['postopts'] = ''; $post['file'] = ''; - if ($parent_id) { - $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $parent_id]); + if (!empty($request['parent'])) { + $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $request['parent']]); if (DBA::isResult($parent_item)) { // if this isn't the top-level parent of the conversation, find it if ($parent_item['gravity'] != Item::GRAVITY_PARENT) { @@ -219,7 +216,7 @@ function item_insert(int $uid, array $request, bool $preview, string $return_pat throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item couldn\'t be fetched.')); } - $recipients = explode(',', $emailcc); + $recipients = explode(',', $request['emailcc'] ?? ''); DI::contentItem()->postProcessPost($post, $recipients); From 900e0d46d3c979a543366f7e6df8fc65c58d41a3 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 7 Jan 2023 18:46:10 +0000 Subject: [PATCH 08/10] Changes after review --- mod/item.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mod/item.php b/mod/item.php index 8eb1403f3..ca97f4e00 100644 --- a/mod/item.php +++ b/mod/item.php @@ -49,7 +49,7 @@ use Friendica\Util\DateTimeFormat; function item_post(App $a) { $uid = DI::userSession()->getLocalUserId(); - if (!DI::userSession()->isAuthenticated() || !$uid) { + if (!$uid) { throw new HTTPException\ForbiddenException(); } @@ -68,11 +68,11 @@ function item_post(App $a) { * after it's been previewed */ 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'); item_post_return(DI::baseUrl(), $return_path); } else { - $_SESSION['post-random'] = $_REQUEST['post_id_random']; + DI::session()->set('post-random', $_REQUEST['post_id_random']); } } @@ -90,16 +90,15 @@ function item_drop(int $uid, string $dropitems) Item::deleteForUser(['id' => $item], $uid); } - $json = ['success' => 1]; - System::jsonExit($json); + System::jsonExit(['success' => 1]); } function item_edit(int $uid, array $request, bool $preview, string $return_path) { $post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $request['post_id'], 'uid' => $uid]); if (!DBA::isResult($post)) { - DI::sysmsg()->addNotice(DI::l10n()->t('Unable to locate original post.')); 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.')); @@ -167,8 +166,8 @@ function item_insert(int $uid, array $request, bool $preview, string $return_pat } if (empty($toplevel_item)) { - DI::sysmsg()->addNotice(DI::l10n()->t('Unable to locate original post.')); 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.')); @@ -198,8 +197,8 @@ function item_insert(int $uid, array $request, bool $preview, string $return_pat $post_id = Item::insert($post); if (!$post_id) { - DI::sysmsg()->addNotice(DI::l10n()->t('Item wasn\'t stored.')); if ($return_path) { + DI::sysmsg()->addNotice(DI::l10n()->t('Item wasn\'t stored.')); DI::baseUrl()->redirect($return_path); } @@ -258,8 +257,8 @@ function item_process(array $post, array $request, bool $preview, string $return System::jsonExit(['preview' => '']); } - DI::sysmsg()->addNotice(DI::l10n()->t('Empty post discarded.')); if ($return_path) { + DI::sysmsg()->addNotice(DI::l10n()->t('Empty post discarded.')); DI::baseUrl()->redirect($return_path); } From f5fd99f7ea3cb397c71846742868c22893298d65 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 7 Jan 2023 18:51:28 +0000 Subject: [PATCH 09/10] Unbneeded strlen removed --- src/Content/Item.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Content/Item.php b/src/Content/Item.php index 968509dee..2518f4d31 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -876,7 +876,7 @@ class Item $post['allow_cid'] .= $this->aclFormatter->toString(Contact::getPublicIdByUserId($post['uid'])); } - if (strlen($post['allow_gid']) || strlen($post['allow_cid']) || strlen($post['deny_gid']) || strlen($post['deny_cid'])) { + 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; @@ -898,7 +898,7 @@ class Item if (empty($attachment)) { continue; } - if (strlen($post['attach'])) { + if ($post['attach']) { $post['attach'] .= ','; } $post['attach'] .= Post\Media::getAttachElement($this->baseURL->get() . '/attach/' . $attachment['id'], @@ -1013,7 +1013,7 @@ class Item foreach ($recipients as $recipient) { $address = trim($recipient); - if (!strlen($address)) { + if (!$address) { continue; } From d5bc6d00060841a92cb5ca542b535c74f058976a Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 7 Jan 2023 19:54:13 +0100 Subject: [PATCH 10/10] Apply suggestions from code review Co-authored-by: Hypolite Petovan --- mod/item.php | 4 ++-- src/Content/Item.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mod/item.php b/mod/item.php index ca97f4e00..f43e78e6b 100644 --- a/mod/item.php +++ b/mod/item.php @@ -156,7 +156,7 @@ function item_insert(int $uid, array $request, bool $preview, string $return_pat if (!empty($request['parent'])) { $parent_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $request['parent']]); - if (DBA::isResult($parent_item)) { + if ($parent_item) { // if this isn't the top-level parent of the conversation, find it if ($parent_item['gravity'] != Item::GRAVITY_PARENT) { $toplevel_item = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $parent_item['parent']]); @@ -206,7 +206,7 @@ function item_insert(int $uid, array $request, bool $preview, string $return_pat } $post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); - if (!DBA::isResult($post)) { + if (!$post) { Logger::error('Item couldn\'t be fetched.', ['post_id' => $post_id]); if ($return_path) { DI::baseUrl()->redirect($return_path); diff --git a/src/Content/Item.php b/src/Content/Item.php index 2518f4d31..a60b12663 100644 --- a/src/Content/Item.php +++ b/src/Content/Item.php @@ -856,7 +856,7 @@ class Item } $user = User::getById($post['uid'], ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']); - if (!DBA::isResult($user)) { + if (!$user) { throw new HTTPException\NotFoundException($this->l10n->t('Unable to locate original post.')); }