From 65c8f337549e502ed0d720dee33858fee14d3f76 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 16 Jan 2021 04:11:28 +0000 Subject: [PATCH] Post class introduced in "mod" and "include" --- include/api.php | 23 ++++++++++++----------- include/conversation.php | 11 ++++++----- include/enotify.php | 5 +++-- mod/display.php | 13 +++++++------ mod/events.php | 3 ++- mod/follow.php | 3 ++- mod/item.php | 12 ++++++------ mod/photos.php | 5 +++-- mod/share.php | 3 ++- mod/tagger.php | 3 ++- mod/tagrm.php | 5 +++-- mod/update_contact.php | 4 ++-- update.php | 3 ++- 13 files changed, 52 insertions(+), 41 deletions(-) diff --git a/include/api.php b/include/api.php index 5131c9574..26a377821 100644 --- a/include/api.php +++ b/include/api.php @@ -41,6 +41,7 @@ use Friendica\Model\Item; use Friendica\Model\Mail; use Friendica\Model\Notify; use Friendica\Model\Photo; +use Friendica\Model\Post; use Friendica\Model\User; use Friendica\Model\UserItem; use Friendica\Model\Verb; @@ -1365,7 +1366,7 @@ function api_get_last_status($ownerId, $uid) */ function api_get_item(array $condition) { - $item = Item::selectFirst(Item::DISPLAY_FIELDLIST, $condition, ['order' => ['id' => true]]); + $item = Post::selectFirst(Item::DISPLAY_FIELDLIST, $condition, ['order' => ['id' => true]]); return $item; } @@ -1673,7 +1674,7 @@ function api_statuses_home_timeline($type) } if (!empty($idarray)) { - $unseen = Item::exists(['unseen' => true, 'id' => $idarray]); + $unseen = Post::exists(['unseen' => true, 'id' => $idarray]); if ($unseen) { Item::update(['unseen' => false], ['unseen' => true, 'id' => $idarray]); } @@ -1880,12 +1881,12 @@ function api_statuses_show($type) $conversation = !empty($_REQUEST['conversation']); // try to fetch the item for the local user - or the public item, if there is no local one - $uri_item = Item::selectFirst(['uri'], ['id' => $id]); + $uri_item = Post::selectFirst(['uri'], ['id' => $id]); if (!DBA::isResult($uri_item)) { throw new BadRequestException("There is no status with this id."); } - $item = Item::selectFirst(['id'], ['uri' => $uri_item['uri'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]); + $item = Post::selectFirst(['id'], ['uri' => $uri_item['uri'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]); if (!DBA::isResult($item)) { throw new BadRequestException("There is no status with this id."); } @@ -1963,12 +1964,12 @@ function api_conversation_show($type) Logger::info(API_LOG_PREFIX . '{subaction}', ['module' => 'api', 'action' => 'conversation', 'subaction' => 'show', 'id' => $id]); // try to fetch the item for the local user - or the public item, if there is no local one - $item = Item::selectFirst(['parent-uri'], ['id' => $id]); + $item = Post::selectFirst(['parent-uri'], ['id' => $id]); if (!DBA::isResult($item)) { throw new BadRequestException("There is no status with this id."); } - $parent = Item::selectFirst(['id'], ['uri' => $item['parent-uri'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]); + $parent = Post::selectFirst(['id'], ['uri' => $item['parent-uri'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]); if (!DBA::isResult($parent)) { throw new BadRequestException("There is no status with this id."); } @@ -2040,7 +2041,7 @@ function api_statuses_repeat($type) Logger::log('API: api_statuses_repeat: '.$id); $fields = ['uri-id', 'network', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink']; - $item = Item::selectFirst($fields, ['id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]]); + $item = Post::selectFirst($fields, ['id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]]); if (DBA::isResult($item) && $item['body'] != "") { if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::TWITTER])) { @@ -4879,7 +4880,7 @@ function prepare_photo_data($type, $scale, $photo_id) // retrieve item element for getting activities (like, dislike etc.) related to photo $condition = ['uid' => api_user(), 'resource-id' => $photo_id, 'type' => 'photo']; - $item = Item::selectFirst(['id', 'uid', 'uri', 'parent', 'allow_cid', 'deny_cid', 'allow_gid', 'deny_gid'], $condition); + $item = Post::selectFirst(['id', 'uid', 'uri', 'parent', 'allow_cid', 'deny_cid', 'allow_gid', 'deny_gid'], $condition); if (!DBA::isResult($item)) { throw new NotFoundException('Photo-related item not found.'); } @@ -5075,7 +5076,7 @@ function api_share_as_retweet(&$item) } if (!empty($condition)) { - $original_item = Item::selectFirst([], $condition); + $original_item = Post::selectFirst([], $condition); if (DBA::isResult($original_item)) { $reshared_item = array_merge($reshared_item, $original_item); } @@ -5102,7 +5103,7 @@ function api_in_reply_to($item) $in_reply_to['screen_name'] = null; if (($item['thr-parent'] != $item['uri']) && ($item['gravity'] != GRAVITY_PARENT)) { - $parent = Item::selectFirst(['id'], ['uid' => $item['uid'], 'uri' => $item['thr-parent']]); + $parent = Post::selectFirst(['id'], ['uid' => $item['uid'], 'uri' => $item['thr-parent']]); if (DBA::isResult($parent)) { $in_reply_to['status_id'] = intval($parent['id']); } else { @@ -5112,7 +5113,7 @@ function api_in_reply_to($item) $in_reply_to['status_id_str'] = (string) intval($in_reply_to['status_id']); $fields = ['author-nick', 'author-name', 'author-id', 'author-link']; - $parent = Item::selectFirst($fields, ['id' => $in_reply_to['status_id']]); + $parent = Post::selectFirst($fields, ['id' => $in_reply_to['status_id']]); if (DBA::isResult($parent)) { $in_reply_to['screen_name'] = (($parent['author-nick']) ? $parent['author-nick'] : $parent['author-name']); diff --git a/include/conversation.php b/include/conversation.php index f681155a4..d269bc72a 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -33,10 +33,11 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Item; +use Friendica\Model\Post; use Friendica\Model\Profile; use Friendica\Model\Tag; use Friendica\Model\Verb; -use Friendica\Object\Post; +use Friendica\Object\Post as ObjectPost; use Friendica\Object\Thread; use Friendica\Protocol\Activity; use Friendica\Util\Crypto; @@ -201,7 +202,7 @@ function localize_item(&$item) if ($activity->match($item['verb'], Activity::TAG)) { $fields = ['author-id', 'author-link', 'author-name', 'author-network', 'verb', 'object-type', 'resource-id', 'body', 'plink']; - $obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]); + $obj = Post::selectFirst($fields, ['uri' => $item['parent-uri']]); if (!DBA::isResult($obj)) { return; } @@ -677,7 +678,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o $item['pagedrop'] = $page_dropping; if ($item['gravity'] == GRAVITY_PARENT) { - $item_object = new Post($item); + $item_object = new ObjectPost($item); $conv->addParent($item_object); } } @@ -871,7 +872,7 @@ function conversation_fetch_items(array $parent, array $items, array $condition, $condition[0] .= " AND NOT `author`.`hidden`"; } - $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity', 'post-type']), $condition, $params); + $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['pinned', 'contact-uid', 'gravity', 'post-type']), $condition, $params); $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false, $activity); @@ -1041,7 +1042,7 @@ function builtin_activity_puller(array $activity, array &$conv_responses) } // Skip when the causer of the parent is the same than the author of the announce - if (($verb == Activity::ANNOUNCE) && Item::exists(['uri' => $activity['thr-parent'], + if (($verb == Activity::ANNOUNCE) && Post::exists(['uri' => $activity['thr-parent'], 'uid' => $activity['uid'], 'causer-id' => $activity['author-id'], 'gravity' => GRAVITY_PARENT])) { continue; } diff --git a/include/enotify.php b/include/enotify.php index f09cbf29a..fc19d400f 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -30,6 +30,7 @@ use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\ItemContent; use Friendica\Model\Notify; +use Friendica\Model\Post; use Friendica\Model\User; use Friendica\Model\UserItem; use Friendica\Protocol\Activity; @@ -518,7 +519,7 @@ function notification($params) Logger::log('sending notification email'); if (isset($params['parent']) && (intval($params['parent']) != 0)) { - $parent = Item::selectFirst(['guid'], ['id' => $params['parent']]); + $parent = Post::selectFirst(['guid'], ['id' => $params['parent']]); $message_id = "<" . $parent['guid'] . "@" . gethostname() . ">"; // Is this the first email notification for this parent item and user? @@ -650,7 +651,7 @@ function check_item_notification($itemid, $uid, $notification_type) { // Special treatment for posts that had been shared via "announce" if ($item['gravity'] == GRAVITY_ACTIVITY) { - $parent_item = Item::selectFirst($fields, ['uri-id' => $item['thr-parent-id'], 'uid' => [$uid, 0]]); + $parent_item = Post::selectFirst($fields, ['uri-id' => $item['thr-parent-id'], 'uid' => [$uid, 0]]); if (DBA::isResult($parent_item)) { // Don't notify on own entries if (User::getIdForURL($parent_item['author-link']) == $uid) { diff --git a/mod/display.php b/mod/display.php index 81dce59e2..07289e013 100644 --- a/mod/display.php +++ b/mod/display.php @@ -32,6 +32,7 @@ use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Item; +use Friendica\Model\Post; use Friendica\Model\Profile; use Friendica\Module\Objects; use Friendica\Network\HTTPException; @@ -70,7 +71,7 @@ function display_init(App $a) // Is this item private but could be visible to the remove visitor? if (!DBA::isResult($item) && remote_user()) { - $item = Item::selectFirst($fields, ['guid' => $a->argv[1], 'private' => Item::PRIVATE, 'origin' => true]); + $item = Post::selectFirst($fields, ['guid' => $a->argv[1], 'private' => Item::PRIVATE, 'origin' => true]); if (DBA::isResult($item)) { if (!Contact::isFollower(remote_user(), $item['uid'])) { $item = null; @@ -187,7 +188,7 @@ function display_content(App $a, $update = false, $update_uid = 0) if ($update) { $item_id = $_REQUEST['item_id']; - $item = Item::selectFirst(['uid', 'parent', 'parent-uri', 'parent-uri-id'], ['id' => $item_id]); + $item = Post::selectFirst(['uid', 'parent', 'parent-uri', 'parent-uri-id'], ['id' => $item_id]); if ($item['uid'] != 0) { $a->profile = ['uid' => intval($item['uid'])]; } else { @@ -214,7 +215,7 @@ function display_content(App $a, $update = false, $update_uid = 0) } if (($item_parent == 0) && remote_user()) { - $item = Item::selectFirst($fields, ['guid' => $a->argv[1], 'private' => Item::PRIVATE, 'origin' => true]); + $item = Post::selectFirst($fields, ['guid' => $a->argv[1], 'private' => Item::PRIVATE, 'origin' => true]); if (DBA::isResult($item) && Contact::isFollower(remote_user(), $item['uid'])) { $item_id = $item['id']; $item_parent = $item['parent']; @@ -243,7 +244,7 @@ function display_content(App $a, $update = false, $update_uid = 0) } // We are displaying an "alternate" link if that post was public. See issue 2864 - $is_public = Item::exists(['id' => $item_id, 'private' => [Item::PUBLIC, Item::UNLISTED]]); + $is_public = Post::exists(['id' => $item_id, 'private' => [Item::PUBLIC, Item::UNLISTED]]); if ($is_public) { // For the atom feed the nickname doesn't matter at all, we only need the item id. $alternate = DI::baseUrl().'/display/feed-item/'.$item_id.'.atom'; @@ -262,7 +263,7 @@ function display_content(App $a, $update = false, $update_uid = 0) $parent = null; if (!empty($item_parent_uri)) { - $parent = Item::selectFirst(['uid'], ['uri' => $item_parent_uri, 'wall' => true]); + $parent = Post::selectFirst(['uid'], ['uri' => $item_parent_uri, 'wall' => true]); } if (DBA::isResult($parent)) { @@ -305,7 +306,7 @@ function display_content(App $a, $update = false, $update_uid = 0) if (local_user() && (local_user() == $a->profile['uid'])) { $condition = ['parent-uri' => $item_parent_uri, 'uid' => local_user(), 'unseen' => true]; - $unseen = Item::exists($condition); + $unseen = Post::exists($condition); } else { $unseen = false; } diff --git a/mod/events.php b/mod/events.php index 04a88e98b..291535df3 100644 --- a/mod/events.php +++ b/mod/events.php @@ -34,6 +34,7 @@ use Friendica\DI; use Friendica\Model\Conversation; use Friendica\Model\Event; use Friendica\Model\Item; +use Friendica\Model\Post; use Friendica\Model\User; use Friendica\Module\BaseProfile; use Friendica\Module\Security\Login; @@ -589,7 +590,7 @@ function events_content(App $a) Item::deleteForUser(['id' => $ev[0]['itemid']], local_user()); } - if (Item::exists(['id' => $ev[0]['itemid']])) { + if (Post::exists(['id' => $ev[0]['itemid']])) { notice(DI::l10n()->t('Failed to remove event')); } diff --git a/mod/follow.php b/mod/follow.php index b01395874..a1b9dba22 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -28,6 +28,7 @@ use Friendica\Model\Profile; use Friendica\Model\Item; use Friendica\Network\Probe; use Friendica\Database\DBA; +use Friendica\Model\Post; use Friendica\Model\User; use Friendica\Util\Strings; @@ -213,7 +214,7 @@ function follow_remote_item($url) } if (!empty($item_id)) { - $item = Item::selectFirst(['guid'], ['id' => $item_id]); + $item = Post::selectFirst(['guid'], ['id' => $item_id]); if (DBA::isResult($item)) { DI::baseUrl()->redirect('display/' . $item['guid']); } diff --git a/mod/item.php b/mod/item.php index 1ce1517a7..c00faf5dc 100644 --- a/mod/item.php +++ b/mod/item.php @@ -114,9 +114,9 @@ function item_post(App $a) { if ($parent_item_id || $thr_parent_uri) { if ($parent_item_id) { - $parent_item = Item::selectFirst([], ['id' => $parent_item_id]); + $parent_item = Post::selectFirst([], ['id' => $parent_item_id]); } elseif ($thr_parent_uri) { - $parent_item = Item::selectFirst([], ['uri' => $thr_parent_uri, 'uid' => $profile_uid]); + $parent_item = Post::selectFirst([], ['uri' => $thr_parent_uri, 'uid' => $profile_uid]); } // if this isn't the top-level parent of the conversation, find it @@ -126,7 +126,7 @@ function item_post(App $a) { $toplevel_item = $parent_item; if ($parent_item['gravity'] != GRAVITY_PARENT) { - $toplevel_item = Item::selectFirst([], ['id' => $toplevel_item['parent']]); + $toplevel_item = Post::selectFirst([], ['id' => $toplevel_item['parent']]); } } @@ -144,7 +144,7 @@ function item_post(App $a) { $stored = Item::storeForUserByUriId($toplevel_item['uri-id'], local_user()); Logger::info('Public item stored for user', ['uri-id' => $toplevel_item['uri-id'], 'uid' => $uid, 'stored' => $stored]); if ($stored) { - $toplevel_item = Item::selectFirst([], ['id' => $stored]); + $toplevel_item = Post::selectFirst([], ['id' => $stored]); } } @@ -193,7 +193,7 @@ function item_post(App $a) { // is this an edited post? if ($post_id > 0) { - $orig_post = Item::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); + $orig_post = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); } $user = User::getById($profile_uid, ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid']); @@ -728,7 +728,7 @@ function item_post(App $a) { throw new HTTPException\InternalServerErrorException(DI::l10n()->t('Item wasn\'t stored.')); } - $datarray = Item::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); + $datarray = Post::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]); if (!DBA::isResult($datarray)) { Logger::error('Item couldn\'t be fetched.', ['post_id' => $post_id]); diff --git a/mod/photos.php b/mod/photos.php index ca5b66abe..817e9fc53 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -36,6 +36,7 @@ use Friendica\DI; use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\Photo; +use Friendica\Model\Post; use Friendica\Model\Profile; use Friendica\Model\Tag; use Friendica\Model\User; @@ -427,7 +428,7 @@ function photos_post(App $a) } if ($item_id) { - $item = Item::selectFirst(['tag', 'inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]); + $item = Post::selectFirst(['tag', 'inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]); if (DBA::isResult($item)) { $old_inform = $item['inform']; @@ -1270,7 +1271,7 @@ function photos_content(App $a) ); if (DBA::isResult($linked_items)) { // This is a workaround to not being forced to rewrite the while $sql_extra handling - $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]); + $link_item = Post::selectFirst([], ['id' => $linked_items[0]['id']]); } if (!empty($link_item['parent']) && !empty($link_item['uid'])) { diff --git a/mod/share.php b/mod/share.php index a8ac3bd8b..b606c1a66 100644 --- a/mod/share.php +++ b/mod/share.php @@ -23,6 +23,7 @@ use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Database\DBA; use Friendica\Model\Item; +use Friendica\Model\Post; function share_init(App $a) { $post_id = (($a->argc > 1) ? intval($a->argv[1]) : 0); @@ -33,7 +34,7 @@ function share_init(App $a) { $fields = ['private', 'body', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink', 'title']; - $item = Item::selectFirst($fields, ['id' => $post_id]); + $item = Post::selectFirst($fields, ['id' => $post_id]); if (!DBA::isResult($item) || $item['private'] == Item::PRIVATE) { exit(); diff --git a/mod/tagger.php b/mod/tagger.php index 63e7f2ca8..38575a215 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -28,6 +28,7 @@ use Friendica\Core\Worker; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Item; +use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Protocol\Activity; use Friendica\Util\Strings; @@ -53,7 +54,7 @@ function tagger_content(App $a) { Logger::log('tagger: tag ' . $term . ' item ' . $item_id); - $item = Item::selectFirst([], ['id' => $item_id]); + $item = Post::selectFirst([], ['id' => $item_id]); if (!$item_id || !DBA::isResult($item)) { Logger::log('tagger: no item ' . $item_id); diff --git a/mod/tagrm.php b/mod/tagrm.php index 179276663..f376573fe 100644 --- a/mod/tagrm.php +++ b/mod/tagrm.php @@ -24,6 +24,7 @@ use Friendica\Content\Text\BBCode; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Item; +use Friendica\Model\Post; use Friendica\Model\Tag; use Friendica\Util\Strings; @@ -62,7 +63,7 @@ function update_tags($item_id, $tags) return; } - $item = Item::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => local_user()]); + $item = Post::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => local_user()]); if (!DBA::isResult($item)) { return; } @@ -96,7 +97,7 @@ function tagrm_content(App $a) // NOTREACHED } - $item = Item::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => local_user()]); + $item = Post::selectFirst(['uri-id'], ['id' => $item_id, 'uid' => local_user()]); if (!DBA::isResult($item)) { DI::baseUrl()->redirect($_SESSION['photo_return']); } diff --git a/mod/update_contact.php b/mod/update_contact.php index 9681e7c17..44bb4a36a 100644 --- a/mod/update_contact.php +++ b/mod/update_contact.php @@ -24,14 +24,14 @@ use Friendica\App; use Friendica\Core\System; use Friendica\DI; -use Friendica\Model\Item; +use Friendica\Model\Post; use Friendica\Module\Contact; function update_contact_content(App $a) { if (!empty($a->argv[1]) && (!empty($_GET['force']) || !DI::pConfig()->get(local_user(), 'system', 'no_auto_update'))) { if (!empty($_GET['item'])) { - $item = Item::selectFirst(['parent'], ['id' => $_GET['item']]); + $item = Post::selectFirst(['parent'], ['id' => $_GET['item']]); $parentid = $item['parent'] ?? 0; } else { $parentid = 0; diff --git a/update.php b/update.php index b5d178489..d8a281737 100644 --- a/update.php +++ b/update.php @@ -52,6 +52,7 @@ use Friendica\Model\Contact; use Friendica\Model\Item; use Friendica\Model\Notify; use Friendica\Model\Photo; +use Friendica\Model\Post; use Friendica\Model\User; use Friendica\Model\Storage; use Friendica\Util\DateTimeFormat; @@ -336,7 +337,7 @@ function update_1309() continue; } - $item = Item::selectFirst(['id', 'gravity'], ['uid' => $contact['uid'], 'guid' => $entry['guid']]); + $item = Post::selectFirst(['id', 'gravity'], ['uid' => $contact['uid'], 'guid' => $entry['guid']]); if (!DBA::isResult($item)) { continue; }