Post class introduced in "mod" and "include"

This commit is contained in:
Michael 2021-01-16 04:11:28 +00:00
parent 3ab4e20fe6
commit 65c8f33754
13 changed files with 52 additions and 41 deletions

View file

@ -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']);

View file

@ -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;
}

View file

@ -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) {

View file

@ -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;
}

View file

@ -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'));
}

View file

@ -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']);
}

View file

@ -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]);

View file

@ -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'])) {

View file

@ -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();

View file

@ -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);

View file

@ -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']);
}

View file

@ -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;

View file

@ -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;
}