<?php
/**
- * @copyright Copyright (C) 2020, Friendica
+ * @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\App;
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
-use Friendica\Content\Text\BBCode;
+use Friendica\Core\ACL;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
-use Friendica\Model\Profile;
+use Friendica\Model\Post;
use Friendica\Model\Tag;
+use Friendica\Model\User;
use Friendica\Model\Verb;
-use Friendica\Object\Post;
+use Friendica\Object\Post as PostObject;
use Friendica\Object\Thread;
use Friendica\Protocol\Activity;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Proxy;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
use Friendica\Util\XML;
-function item_extract_images($body) {
-
- $saved_image = [];
- $orig_body = $body;
- $new_body = '';
-
- $cnt = 0;
- $img_start = strpos($orig_body, '[img');
- $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
- $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
- while (($img_st_close !== false) && ($img_end !== false)) {
-
- $img_st_close++; // make it point to AFTER the closing bracket
- $img_end += $img_start;
-
- if (!strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
- // This is an embedded image
-
- $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
- $new_body = $new_body . substr($orig_body, 0, $img_start) . '[!#saved_image' . $cnt . '#!]';
-
- $cnt++;
- } else {
- $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
- }
-
- $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
-
- if ($orig_body === false) {
- // in case the body ends on a closing image tag
- $orig_body = '';
- }
-
- $img_start = strpos($orig_body, '[img');
- $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
- $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
- }
-
- $new_body = $new_body . $orig_body;
-
- return ['body' => $new_body, 'images' => $saved_image];
-}
-
-function item_redir_and_replace_images($body, $images, $cid) {
-
- $origbody = $body;
- $newbody = '';
-
- $cnt = 1;
- $pos = BBCode::getTagPosition($origbody, 'url', 0);
- while ($pos !== false && $cnt < 1000) {
-
- $search = '/\[url\=(.*?)\]\[!#saved_image([0-9]*)#!\]\[\/url\]' . '/is';
- $replace = '[url=' . DI::baseUrl() . '/redir/' . $cid
- . '?url=' . '$1' . '][!#saved_image' . '$2' .'#!][/url]';
-
- $newbody .= substr($origbody, 0, $pos['start']['open']);
- $subject = substr($origbody, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
- $origbody = substr($origbody, $pos['end']['close']);
- if ($origbody === false) {
- $origbody = '';
- }
-
- $subject = preg_replace($search, $replace, $subject);
- $newbody .= $subject;
-
- $cnt++;
- // Isn't this supposed to use $cnt value for $occurrences? - @MrPetovan
- $pos = BBCode::getTagPosition($origbody, 'url', 0);
- }
- $newbody .= $origbody;
-
- $cnt = 0;
- foreach ($images as $image) {
- /*
- * We're depending on the property of 'foreach' (specified on the PHP website) that
- * it loops over the array starting from the first element and going sequentially
- * to the last element.
- */
- $newbody = str_replace('[!#saved_image' . $cnt . '#!]', '[img]' . $image . '[/img]', $newbody);
- $cnt++;
- }
- return $newbody;
-}
-
/**
* Render actions localized
*
*/
function localize_item(&$item)
{
- $extracted = item_extract_images($item['body']);
- if ($extracted['images']) {
- $item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
- }
-
- /// @todo The following functionality needs to be cleaned up.
+ DI::profiler()->startRecording('rendering');
+ /// @todo The following functionality needs to be cleaned up.
if (!empty($item['verb'])) {
$activity = DI::activity();
if (stristr($item['verb'], Activity::POKE)) {
$verb = urldecode(substr($item['verb'], strpos($item['verb'],'#') + 1));
if (!$verb) {
+ DI::profiler()->stopRecording();
return;
}
if ($item['object-type'] == "" || $item['object-type'] !== Activity\ObjectType::PERSON) {
+ DI::profiler()->stopRecording();
return;
}
- $Aname = $item['author-name'];
- $Alink = $item['author-link'];
-
$obj = XML::parseString($xmlhead . $item['object']);
$Bname = $obj->title;
}
}
- $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
- $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
- if ($Bphoto != "") {
+ $author = ['uid' => 0, 'id' => $item['author-id'],
+ 'network' => $item['author-network'], 'url' => $item['author-link']];
+ $A = '[url=' . Contact::magicLinkByContact($author) . ']' . $item['author-name'] . '[/url]';
+
+ if (!empty($Blink)) {
+ $B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
+ } else {
+ $B = '';
+ }
+
+ if ($Bphoto != "" && !empty($Blink)) {
$Bphoto = '[url=' . Contact::magicLink($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
}
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)) {
+ DI::profiler()->stopRecording();
return;
}
}
}
- // add zrl's to public images
- $photo_pattern = "/\[url=(.*?)\/photos\/(.*?)\/image\/(.*?)\]\[img(.*?)\]h(.*?)\[\/img\]\[\/url\]/is";
- if (preg_match($photo_pattern, $item['body'])) {
- $photo_replace = '[url=' . Profile::zrl('$1' . '/photos/' . '$2' . '/image/' . '$3' ,true) . '][img' . '$4' . ']h' . '$5' . '[/img][/url]';
- $item['body'] = BBCode::pregReplaceInTag($photo_pattern, $photo_replace, 'url', $item['body']);
- }
-
// add sparkle links to appropriate permalinks
- $author = ['uid' => 0, 'id' => $item['author-id'],
- 'network' => $item['author-network'], 'url' => $item['author-link']];
-
// Only create a redirection to a magic link when logged in
if (!empty($item['plink']) && Session::isAuthenticated()) {
+ $author = ['uid' => 0, 'id' => $item['author-id'],
+ 'network' => $item['author-network'], 'url' => $item['author-link']];
$item['plink'] = Contact::magicLinkByContact($author, $item['plink']);
}
+ DI::profiler()->stopRecording();
}
/**
$blocklist = [];
foreach (explode(',', $str_blocked) as $entry) {
- // The 4th parameter guarantees that there always will be a public contact entry
- $cid = Contact::getIdForURL(trim($entry), 0, false, ['url' => trim($entry)]);
+ $cid = Contact::getIdForURL(trim($entry), 0, false);
if (!empty($cid)) {
$blocklist[] = $cid;
}
*/
function conversation(App $a, array $items, $mode, $update, $preview = false, $order = 'commented', $uid = 0)
{
+ DI::profiler()->startRecording('rendering');
$page = DI::page();
$page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
$ssl_state = (local_user() ? true : false);
- $profile_owner = 0;
$live_update_div = '';
$blocklist = conv_get_blocklist();
if ($mode === 'network') {
$items = conversation_add_children($items, false, $order, $uid);
- $profile_owner = local_user();
if (!$update) {
/*
* The special div is needed for liveUpdate to kick in for this page.
}
} elseif ($mode === 'profile') {
$items = conversation_add_children($items, false, $order, $uid);
- $profile_owner = $a->profile['uid'];
if (!$update) {
$tab = 'posts';
*/
$live_update_div = '<div id="live-profile"></div>' . "\r\n"
- . "<script> var profile_uid = " . $a->profile['uid']
+ . "<script> var profile_uid = " . $uid
. "; var netargs = '?f='; </script>\r\n";
}
}
} elseif ($mode === 'notes') {
$items = conversation_add_children($items, false, $order, local_user());
- $profile_owner = local_user();
if (!$update) {
$live_update_div = '<div id="live-notes"></div>' . "\r\n"
}
} elseif ($mode === 'display') {
$items = conversation_add_children($items, false, $order, $uid);
- $profile_owner = $a->profile['uid'];
if (!$update) {
$live_update_div = '<div id="live-display"></div>' . "\r\n"
}
} elseif ($mode === 'community') {
$items = conversation_add_children($items, true, $order, $uid);
- $profile_owner = 0;
if (!$update) {
$live_update_div = '<div id="live-community"></div>' . "\r\n"
. "<script> var profile_uid = -1; var netargs = '" . substr(DI::args()->getCommand(), 10)
- ."/?f='; </script>\r\n";
+ . '?f='
+ . (!empty($_GET['no_sharer']) ? '&no_sharer=' . rawurlencode($_GET['no_sharer']) : '')
+ . "'; </script>\r\n";
}
} elseif ($mode === 'contacts') {
$items = conversation_add_children($items, false, $order, $uid);
- $profile_owner = 0;
if (!$update) {
- $live_update_div = '<div id="live-contacts"></div>' . "\r\n"
- . "<script> var profile_uid = -1; var netargs = '" . substr(DI::args()->getCommand(), 9)
+ $live_update_div = '<div id="live-contact"></div>' . "\r\n"
+ . "<script> var profile_uid = -1; var netargs = '" . substr(DI::args()->getCommand(), 8)
."/?f='; </script>\r\n";
}
} elseif ($mode === 'search') {
$live_update_div = '<div id="live-search"></div>' . "\r\n";
}
- $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
+ $page_dropping = ((local_user() && local_user() == $uid) ? true : false);
if (!$update) {
$_SESSION['return_path'] = DI::args()->getQueryString();
}
$cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
- Hook::callAll('conversation_start',$cb);
+ Hook::callAll('conversation_start', $cb);
$items = $cb['items'];
'attendyes' => [],
'attendno' => [],
'attendmaybe' => [],
- 'announce' => [],
+ 'announce' => [],
];
if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
$writable = false;
}
- if (in_array($mode, ['network-new', 'search', 'contact-posts'])) {
+ if (in_array($mode, ['filed', 'search', 'contact-posts'])) {
/*
* "New Item View" on network page or search page results
$threadsid++;
- $owner_url = '';
- $owner_name = '';
- $sparkle = '';
-
// prevent private email from leaking.
if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
continue;
'network' => $item['author-network'], 'url' => $item['author-link']];
$profile_link = Contact::magicLinkByContact($author);
+ $sparkle = '';
if (strpos($profile_link, 'redir/') === 0) {
$sparkle = ' sparkle';
}
$locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
- Hook::callAll('render_location',$locate);
-
- $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
+ Hook::callAll('render_location', $locate);
+ $location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
localize_item($item);
- if ($mode === 'network-new') {
+ if ($mode === 'filed') {
$dropping = true;
} else {
$dropping = false;
'delete' => DI::l10n()->t('Delete'),
];
- $star = false;
- $isstarred = "unstarred";
-
- $lock = false;
$likebuttons = [
- 'like' => null,
- 'dislike' => null,
- 'share' => null,
+ 'like' => null,
+ 'dislike' => null,
+ 'share' => null,
+ 'announce' => null,
];
if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
unset($likebuttons['dislike']);
}
- $body = Item::prepareBody($item, true, $preview);
+ $body_html = Item::prepareBody($item, true, $preview);
- list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item);
+ list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item, local_user());
if (!empty($item['content-warning']) && DI::pConfig()->get(local_user(), 'system', 'disable_cw', false)) {
$title = ucfirst($item['content-warning']);
'template' => $tpl,
'id' => ($preview ? 'P0' : $item['id']),
'guid' => ($preview ? 'Q0' : $item['guid']),
+ 'commented' => $item['commented'],
+ 'received' => $item['received'],
+ 'created_date' => $item['created'],
+ 'uriid' => $item['uri-id'],
'network' => $item['network'],
'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']),
'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']),
'linktitle' => DI::l10n()->t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
'profile_url' => $profile_link,
- 'item_photo_menu' => item_photo_menu($item),
+ 'item_photo_menu_html' => item_photo_menu($item),
'name' => $profile_name,
'sparkle' => $sparkle,
- 'lock' => $lock,
- 'thumb' => DI::baseUrl()->remove($item['author-avatar']),
+ 'lock' => false,
+ 'thumb' => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['author-link'], $item['uid'], Proxy::SIZE_THUMB)),
'title' => $title,
- 'body' => $body,
+ 'body_html' => $body_html,
'tags' => $tags['tags'],
'hashtags' => $tags['hashtags'],
'mentions' => $tags['mentions'],
'has_folders' => ((count($folders)) ? 'true' : ''),
'categories' => $categories,
'folders' => $folders,
- 'text' => strip_tags($body),
+ 'text' => strip_tags($body_html),
'localtime' => DateTimeFormat::local($item['created'], 'r'),
- 'ago' => (($item['app']) ? DI::l10n()->t('%s from %s', Temporal::getRelativeDate($item['created']),$item['app']) : Temporal::getRelativeDate($item['created'])),
- 'location' => $location,
+ 'ago' => (($item['app']) ? DI::l10n()->t('%s from %s', Temporal::getRelativeDate($item['created']), $item['app']) : Temporal::getRelativeDate($item['created'])),
+ 'location_html' => $location_html,
'indent' => '',
- 'owner_name' => $owner_name,
- 'owner_url' => $owner_url,
- 'owner_photo' => DI::baseUrl()->remove($item['owner-avatar']),
+ 'owner_name' => '',
+ 'owner_url' => '',
+ 'owner_photo' => DI::baseUrl()->remove(Contact::getAvatarUrlForUrl($item['owner-link'], $item['uid'], Proxy::SIZE_THUMB)),
'plink' => Item::getPlink($item),
'edpost' => false,
- 'isstarred' => $isstarred,
- 'star' => $star,
+ 'isstarred' => 'unstarred',
+ 'star' => false,
'drop' => $drop,
'vote' => $likebuttons,
- 'like' => '',
- 'dislike' => '',
- 'comment' => '',
+ 'like_html' => '',
+ 'dislike_html' => '',
+ 'comment_html' => '',
'conv' => (($preview) ? '' : ['href'=> 'display/'.$item['guid'], 'title'=> DI::l10n()->t('View in context')]),
'previewing' => $previewing,
'wait' => DI::l10n()->t('Please wait'),
$item['pagedrop'] = $page_dropping;
if ($item['gravity'] == GRAVITY_PARENT) {
- $item_object = new Post($item);
+ $item_object = new PostObject($item);
$conv->addParent($item_object);
}
}
'$live_update' => $live_update_div,
'$remove' => DI::l10n()->t('remove'),
'$mode' => $mode,
- '$user' => $a->user,
+ '$update' => $update,
'$threads' => $threads,
'$dropping' => ($page_dropping ? DI::l10n()->t('Delete Selected Items') : False),
]);
+ DI::profiler()->stopRecording();
return $o;
}
/**
- * Fetch all comments from a query. Additionally set the newest resharer as thread owner.
+ * Adds some information (Causer, post reason, direction) to the fetched post row.
*
- * @param mixed $thread_items Database statement with thread posts
- * @param boolean $pinned Is the item pinned?
+ * @param array $row Post row
+ * @param array $activity Contact data of the resharer
*
* @return array items with parents and comments
*/
-function conversation_fetch_comments($thread_items, $pinned) {
- $comments = [];
- $parentlines = [];
- $lineno = 0;
- $direction = [];
- $actor = [];
- $received = '';
-
- while ($row = Item::fetch($thread_items)) {
- if (!empty($parentlines) && ($row['verb'] == Activity::ANNOUNCE)
- && ($row['thr-parent'] == $row['parent-uri']) && ($row['received'] > $received)
- && Contact::isSharing($row['author-id'], $row['uid'])) {
- $direction = ['direction' => 3, 'title' => DI::l10n()->t('%s reshared this.', $row['author-name'])];
-
- $author = ['uid' => 0, 'id' => $row['author-id'],
- 'network' => $row['author-network'], 'url' => $row['author-link']];
- $url = '<a href="'. htmlentities(Contact::magicLinkByContact($author)) .'">' . htmlentities($row['author-name']) . '</a>';
-
- $actor = ['url' => $url, 'link' => $row['author-link'], 'avatar' => $row['author-avatar'], 'name' => $row['author-name']];
- $received = $row['received'];
- }
+function conversation_add_row_information(array $row, array $activity) {
+ DI::profiler()->startRecording('rendering');
- if (!empty($parentlines) && empty($direction) && ($row['gravity'] == GRAVITY_COMMENT)
- && Contact::isSharing($row['author-id'], $row['uid'])) {
- $direction = ['direction' => 5, 'title' => DI::l10n()->t('%s commented on this.', $row['author-name'])];
- }
-
- if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id'])
- && !Contact::isSharing($row['author-id'], $row['uid'])) {
- if ($row['post-type'] == Item::PT_TAG) {
- $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')];
- }
-
- $parentlines[] = $lineno;
- }
+ if ($row['uid'] == 0) {
+ $row['writable'] = in_array($row['network'], Protocol::FEDERATED);
+ }
- if ($row['gravity'] == GRAVITY_PARENT) {
- $row['pinned'] = $pinned;
+ if (!empty($activity)) {
+ if (($row['gravity'] == GRAVITY_PARENT)) {
+ $row['post-reason'] = Item::PR_ANNOUNCEMENT;
+ $row = array_merge($row, $activity);
+ $contact = Contact::getById($activity['causer-id'], ['url', 'name', 'thumb']);
+ $row['causer-link'] = $contact['url'];
+ $row['causer-avatar'] = $contact['thumb'];
+ $row['causer-name'] = $contact['name'];
+ } elseif (($row['gravity'] == GRAVITY_ACTIVITY) && ($row['verb'] == Activity::ANNOUNCE) &&
+ ($row['author-id'] == $activity['causer-id'])) {
+ return $row;
}
-
- $comments[] = $row;
- $lineno++;
}
- DBA::close($thread_items);
+ switch ($row['post-reason']) {
+ case Item::PR_TO:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'to')];
+ break;
+ case Item::PR_CC:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'cc')];
+ break;
+ case Item::PR_BTO:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bto')];
+ break;
+ case Item::PR_BCC:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bcc')];
+ break;
+ case Item::PR_FOLLOWER:
+ $row['direction'] = ['direction' => 6, 'title' => DI::l10n()->t('You are following %s.', $row['author-name'])];
+ break;
+ case Item::PR_TAG:
+ $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')];
+ break;
+ case Item::PR_ANNOUNCEMENT:
+ if (!empty($row['causer-id']) && DI::pConfig()->get(local_user(), 'system', 'display_resharer')) {
+ $row['owner-id'] = $row['causer-id'];
+ $row['owner-link'] = $row['causer-link'];
+ $row['owner-avatar'] = $row['causer-avatar'];
+ $row['owner-name'] = $row['causer-name'];
+ }
- if (!empty($direction)) {
- foreach ($parentlines as $line) {
- $comments[$line]['direction'] = $direction;
- if (!empty($actor)) {
- $comments[$line]['reshared'] = DI::l10n()->t('%s reshared this.', $actor['url']);
- if (DI::pConfig()->get(local_user(), 'system', 'display_resharer') ) {
- $comments[$line]['owner-link'] = $actor['link'];
- $comments[$line]['owner-avatar'] = $actor['avatar'];
- $comments[$line]['owner-name'] = $actor['name'];
- }
+ if (($row['gravity'] == GRAVITY_PARENT) && !empty($row['causer-id'])) {
+ $causer = ['uid' => 0, 'id' => $row['causer-id'],
+ 'network' => $row['causer-network'], 'url' => $row['causer-link']];
+ $row['reshared'] = DI::l10n()->t('%s reshared this.', '<a href="'. htmlentities(Contact::magicLinkByContact($causer)) .'">' . htmlentities($row['causer-name']) . '</a>');
}
- }
+ $row['direction'] = ['direction' => 3, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Reshared') : DI::l10n()->t('Reshared by %s <%s>', $row['causer-name'], $row['causer-link']))];
+ break;
+ case Item::PR_COMMENT:
+ $row['direction'] = ['direction' => 5, 'title' => DI::l10n()->t('%s is participating in this thread.', $row['author-name'])];
+ break;
+ case Item::PR_STORED:
+ $row['direction'] = ['direction' => 8, 'title' => DI::l10n()->t('Stored')];
+ break;
+ case Item::PR_GLOBAL:
+ $row['direction'] = ['direction' => 9, 'title' => DI::l10n()->t('Global')];
+ break;
+ case Item::PR_RELAY:
+ $row['direction'] = ['direction' => 10, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Relayed') : DI::l10n()->t('Relayed by %s <%s>', $row['causer-name'], $row['causer-link']))];
+ break;
+ case Item::PR_FETCHED:
+ $row['direction'] = ['direction' => 2, 'title' => (empty($row['causer-id']) ? DI::l10n()->t('Fetched') : DI::l10n()->t('Fetched because of %s <%s>', $row['causer-name'], $row['causer-link']))];
+ break;
}
- return $comments;
+
+ DI::profiler()->stopRecording();
+ return $row;
}
/**
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
function conversation_add_children(array $parents, $block_authors, $order, $uid) {
+ DI::profiler()->startRecording('rendering');
if (count($parents) > 1) {
$max_comments = DI::config()->get('system', 'max_comments', 100);
} else {
$max_comments = DI::config()->get('system', 'max_display_comments', 1000);
}
- $params = ['order' => ['gravity', 'uid', 'commented' => true]];
-
- if ($max_comments > 0) {
- $params['limit'] = $max_comments;
- }
+ $params = ['order' => ['uri-id' => true, 'uid' => true]];
- $items = [];
+ $activities = [];
+ $uriids = [];
+ $commentcounter = [];
+ $activitycounter = [];
foreach ($parents AS $parent) {
- $condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)",
- $parent['uri'], $uid, Verb::getID(Activity::FOLLOW)];
- $items = conversation_fetch_items($parent, $items, $condition, $block_authors, $params);
+ if (!empty($parent['thr-parent-id']) && !empty($parent['gravity']) && ($parent['gravity'] == GRAVITY_ACTIVITY)) {
+ $uriid = $parent['thr-parent-id'];
+ if (!empty($parent['author-id'])) {
+ $activities[$uriid] = ['causer-id' => $parent['author-id']];
+ foreach (['commented', 'received', 'created'] as $orderfields) {
+ if (!empty($parent[$orderfields])) {
+ $activities[$uriid][$orderfields] = $parent[$orderfields];
+ }
+ }
+ }
+ } else {
+ $uriid = $parent['uri-id'];
+ }
+ $uriids[] = $uriid;
+
+ $commentcounter[$uriid] = 0;
+ $activitycounter[$uriid] = 0;
}
- foreach ($items as $index => $item) {
- if ($item['uid'] == 0) {
- $items[$index]['writable'] = in_array($item['network'], Protocol::FEDERATED);
- }
+ $condition = ['parent-uri-id' => $uriids];
+ if ($block_authors) {
+ $condition['author-hidden'] = false;
}
- $items = conv_sort($items, $order);
+ $condition = DBA::mergeConditions($condition,
+ ["`uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)", $uid, Verb::getID(Activity::FOLLOW)]);
- return $items;
-}
+ $thread_items = Post::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['pinned', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params);
-/**
- * Fetch conversation items
- *
- * @param array $parent
- * @param array $items
- * @param array $condition
- * @param boolean $block_authors
- * @param array $params
- * @return array
- */
-function conversation_fetch_items(array $parent, array $items, array $condition, bool $block_authors, array $params) {
- if ($block_authors) {
- $condition[0] .= " AND NOT `author`.`hidden`";
+ $items = [];
+
+ while ($row = Post::fetch($thread_items)) {
+ if (!empty($items[$row['uri-id']]) && ($row['uid'] == 0)) {
+ continue;
+ }
+
+ if ($max_comments > 0) {
+ if (($row['gravity'] == GRAVITY_COMMENT) && (++$commentcounter[$row['parent-uri-id']] > $max_comments)) {
+ continue;
+ }
+ if (($row['gravity'] == GRAVITY_ACTIVITY) && (++$activitycounter[$row['parent-uri-id']] > $max_comments)) {
+ continue;
+ }
+ }
+ $items[$row['uri-id']] = conversation_add_row_information($row, $activities[$row['uri-id']] ?? []);
}
- $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity', 'post-type']), $condition, $params);
+ DBA::close($thread_items);
- $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false);
+ $items = conv_sort($items, $order);
- if (count($comments) != 0) {
- $items = array_merge($items, $comments);
- }
+ DI::profiler()->stopRecording();
return $items;
}
-function item_photo_menu($item) {
+function item_photo_menu($item)
+{
+ DI::profiler()->startRecording('rendering');
$sub_link = '';
$poke_link = '';
$contact_url = '';
$block_link = '';
$ignore_link = '';
- if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self']) {
- $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
+ if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self'] && !$item['mention']) {
+ $sub_link = 'javascript:doFollowThread(' . $item['id'] . '); return false;';
}
$author = ['uid' => 0, 'id' => $item['author-id'],
$sparkle = (strpos($profile_link, 'redir/') === 0);
$cid = 0;
- $pcid = Contact::getIdForURL($item['author-link'], 0, false);
+ $pcid = $item['author-id'];
$network = '';
$rel = 0;
$condition = ['uid' => local_user(), 'nurl' => Strings::normaliseLink($item['author-link'])];
if (!empty($pcid)) {
$contact_url = 'contact/' . $pcid;
$posts_link = $contact_url . '/posts';
- $block_link = $contact_url . '/block';
- $ignore_link = $contact_url . '/ignore';
+ $block_link = $item['self'] ? '' : $contact_url . '/block';
+ $ignore_link = $item['self'] ? '' : $contact_url . '/ignore';
}
if ($cid && !$item['self']) {
DI::l10n()->t('Ignore') => $ignore_link
];
+ if (!empty($item['language'])) {
+ $menu[DI::l10n()->t('Languages')] = 'javascript:alert(\'' . Item::getLanguageMessage($item) . '\');';
+ }
+
if ($network == Protocol::DFRN) {
$menu[DI::l10n()->t("Poke")] = $poke_link;
}
if ((($cid == 0) || ($rel == Contact::FOLLOWER)) &&
in_array($item['network'], Protocol::FEDERATED)) {
- $menu[DI::l10n()->t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']);
+ $menu[DI::l10n()->t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']) . '&auto=1';
}
} else {
$menu = [DI::l10n()->t('View Profile') => $item['author-link']];
if (strpos($v, 'javascript:') === 0) {
$v = substr($v, 11);
$o .= '<li role="menuitem"><a onclick="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
- } elseif ($v!='') {
+ } elseif ($v) {
$o .= '<li role="menuitem"><a href="' . $v . '">' . $k . '</a></li>' . PHP_EOL;
}
}
+ DI::profiler()->stopRecording();
return $o;
}
*
* Increments the count of each matching activity and adds a link to the author as needed.
*
- * @param array $item
+ * @param array $activity
* @param array &$conv_responses (already created with builtin activity structure)
* @return void
* @throws ImagickException
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
-function builtin_activity_puller($item, &$conv_responses) {
+function builtin_activity_puller(array $activity, array &$conv_responses)
+{
foreach ($conv_responses as $mode => $v) {
$sparkle = '';
return;
}
- if (!empty($item['verb']) && DI::activity()->match($item['verb'], $verb) && ($item['gravity'] != GRAVITY_PARENT)) {
- $author = ['uid' => 0, 'id' => $item['author-id'],
- 'network' => $item['author-network'], 'url' => $item['author-link']];
+ if (!empty($activity['verb']) && DI::activity()->match($activity['verb'], $verb) && ($activity['gravity'] != GRAVITY_PARENT)) {
+ $author = [
+ 'uid' => 0,
+ 'id' => $activity['author-id'],
+ 'network' => $activity['author-network'],
+ 'url' => $activity['author-link']
+ ];
$url = Contact::magicLinkByContact($author);
if (strpos($url, 'redir/') === 0) {
$sparkle = ' class="sparkle" ';
}
- $url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
+ $link = '<a href="' . $url . '"' . $sparkle . '>' . htmlentities($activity['author-name']) . '</a>';
- if (empty($item['thr-parent'])) {
- $item['thr-parent'] = $item['parent-uri'];
+ if (empty($activity['thr-parent-id'])) {
+ $activity['thr-parent-id'] = $activity['parent-uri-id'];
}
- if (!(isset($conv_responses[$mode][$item['thr-parent'] . '-l'])
- && is_array($conv_responses[$mode][$item['thr-parent'] . '-l']))) {
- $conv_responses[$mode][$item['thr-parent'] . '-l'] = [];
- }
-
- // only list each unique author once
- if (in_array($url,$conv_responses[$mode][$item['thr-parent'] . '-l'])) {
+ // Skip when the causer of the parent is the same than the author of the announce
+ if (($verb == Activity::ANNOUNCE) && Post::exists(['uri-id' => $activity['thr-parent-id'],
+ 'uid' => $activity['uid'], 'causer-id' => $activity['author-id'], 'gravity' => GRAVITY_PARENT])) {
continue;
}
- if (!isset($conv_responses[$mode][$item['thr-parent']])) {
- $conv_responses[$mode][$item['thr-parent']] = 1;
- } else {
- $conv_responses[$mode][$item['thr-parent']] ++;
+ if (!isset($conv_responses[$mode][$activity['thr-parent-id']])) {
+ $conv_responses[$mode][$activity['thr-parent-id']] = [
+ 'links' => [],
+ 'self' => 0,
+ ];
+ } elseif (in_array($link, $conv_responses[$mode][$activity['thr-parent-id']]['links'])) {
+ // only list each unique author once
+ continue;
}
- if (public_contact() == $item['author-id']) {
- $conv_responses[$mode][$item['thr-parent'] . '-self'] = 1;
+ if (public_contact() == $activity['author-id']) {
+ $conv_responses[$mode][$activity['thr-parent-id']]['self'] = 1;
}
- $conv_responses[$mode][$item['thr-parent'] . '-l'][] = $url;
+ $conv_responses[$mode][$activity['thr-parent-id']]['links'][] = $link;
// there can only be one activity verb per item so if we found anything, we can stop looking
return;
}
/**
- * Format the vote text for a profile item
+ * Format the activity text for an item/photo/video
*
- * @param int $cnt = number of people who vote the item
- * @param array $arr = array of pre-linked names of likers/dislikers
- * @param string $type = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
- * @param int $id = item id
+ * @param array $links = array of pre-linked names of actors
+ * @param string $verb = one of 'like, 'dislike', 'attendyes', 'attendno', 'attendmaybe'
+ * @param int $id = item id
* @return string formatted text
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
-function format_like($cnt, array $arr, $type, $id) {
+function format_activity(array $links, $verb, $id) {
+ DI::profiler()->startRecording('rendering');
$o = '';
$expanded = '';
$phrase = '';
- if ($cnt == 1) {
- $likers = $arr[0];
+ $total = count($links);
+ if ($total == 1) {
+ $likers = $links[0];
// Phrase if there is only one liker. In other cases it will be uses for the expanded
// list which show all likers
- switch ($type) {
+ switch ($verb) {
case 'like' :
$phrase = DI::l10n()->t('%s likes this.', $likers);
break;
$phrase = DI::l10n()->t('%s reshared this.', $likers);
break;
}
- }
-
- if ($cnt > 1) {
- $total = count($arr);
+ } elseif ($total > 1) {
if ($total < MAX_LIKERS) {
- $last = DI::l10n()->t('and') . ' ' . $arr[count($arr)-1];
- $arr2 = array_slice($arr, 0, -1);
- $likers = implode(', ', $arr2) . ' ' . $last;
+ $likers = implode(', ', array_slice($links, 0, -1));
+ $likers .= ' ' . DI::l10n()->t('and') . ' ' . $links[count($links)-1];
} else {
- $arr = array_slice($arr, 0, MAX_LIKERS - 1);
- $likers = implode(', ', $arr);
- $likers .= DI::l10n()->t('and %d other people', $total - MAX_LIKERS);
+ $likers = implode(', ', array_slice($links, 0, MAX_LIKERS - 1));
+ $likers .= ' ' . DI::l10n()->t('and %d other people', $total - MAX_LIKERS);
}
- $spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
+ $spanatts = "class=\"fakelink\" onclick=\"openClose('{$verb}list-$id');\"";
$explikers = '';
- switch ($type) {
+ switch ($verb) {
case 'like':
- $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> like this', $spanatts, $cnt);
+ $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> like this', $spanatts, $total);
$explikers = DI::l10n()->t('%s like this.', $likers);
break;
case 'dislike':
- $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> don\'t like this', $spanatts, $cnt);
+ $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> don\'t like this', $spanatts, $total);
$explikers = DI::l10n()->t('%s don\'t like this.', $likers);
break;
case 'attendyes':
- $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> attend', $spanatts, $cnt);
+ $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> attend', $spanatts, $total);
$explikers = DI::l10n()->t('%s attend.', $likers);
break;
case 'attendno':
- $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> don\'t attend', $spanatts, $cnt);
+ $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> don\'t attend', $spanatts, $total);
$explikers = DI::l10n()->t('%s don\'t attend.', $likers);
break;
case 'attendmaybe':
- $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> attend maybe', $spanatts, $cnt);
+ $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> attend maybe', $spanatts, $total);
$explikers = DI::l10n()->t('%s attend maybe.', $likers);
break;
case 'announce':
- $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> reshared this', $spanatts, $cnt);
+ $phrase = DI::l10n()->t('<span %1$s>%2$d people</span> reshared this', $spanatts, $total);
$explikers = DI::l10n()->t('%s reshared this.', $likers);
break;
}
- $expanded .= "\t" . '<p class="wall-item-' . $type . '-expanded" id="' . $type . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</p>';
+ $expanded .= "\t" . '<p class="wall-item-' . $verb . '-expanded" id="' . $verb . 'list-' . $id . '" style="display: none;" >' . $explikers . EOL . '</p>';
}
$o .= Renderer::replaceMacros(Renderer::getMarkupTemplate('voting_fakelink.tpl'), [
'$phrase' => $phrase,
- '$type' => $type,
+ '$type' => $verb,
'$id' => $id
]);
$o .= $expanded;
+ DI::profiler()->stopRecording();
return $o;
}
-function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
+function status_editor(App $a, array $x = [], $notes_cid = 0, $popup = false)
{
+ $user = User::getById($a->getLoggedInUserId(), ['uid', 'nickname', 'allow_location', 'default-location']);
+ if (empty($user['uid'])) {
+ return '';
+ }
+
+ DI::profiler()->startRecording('rendering');
$o = '';
+ $x['allow_location'] = $x['allow_location'] ?? $user['allow_location'];
+ $x['default_location'] = $x['default_location'] ?? $user['default-location'];
+ $x['nickname'] = $x['nickname'] ?? $user['nickname'];
+ $x['lockstate'] = $x['lockstate'] ?? ACL::getLockstateForUserId($user['uid']) ? 'lock' : 'unlock';
+ $x['acl'] = $x['acl'] ?? ACL::getFullSelectorHTML(DI::page(), $user['uid'], true);
+ $x['bang'] = $x['bang'] ?? '';
+ $x['visitor'] = $x['visitor'] ?? 'block';
+ $x['is_owner'] = $x['is_owner'] ?? true;
+ $x['profile_uid'] = $x['profile_uid'] ?? local_user();
+
+
$geotag = !empty($x['allow_location']) ? Renderer::replaceMacros(Renderer::getMarkupTemplate('jot_geotag.tpl'), []) : '';
$tpl = Renderer::getMarkupTemplate('jot-header.tpl');
'$term' => DI::l10n()->t('Tag term:'),
'$fileas' => DI::l10n()->t('Save to Folder:'),
'$whereareu' => DI::l10n()->t('Where are you right now?'),
- '$delitems' => DI::l10n()->t("Delete item\x28s\x29?")
+ '$delitems' => DI::l10n()->t("Delete item\x28s\x29?"),
+ '$is_mobile' => DI::mode()->isMobile(),
]);
$jotplugins = '';
Hook::callAll('jot_tool', $jotplugins);
- $query_str = DI::args()->getQueryString();
- if (strpos($query_str, 'public=1') !== false) {
- $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str);
- }
-
- // $tpl = Renderer::replaceMacros($tpl,array('$jotplugins' => $jotplugins));
$tpl = Renderer::getMarkupTemplate("jot.tpl");
- $o .= Renderer::replaceMacros($tpl,[
+ $o .= Renderer::replaceMacros($tpl, [
'$new_post' => DI::l10n()->t('New Post'),
- '$return_path' => $query_str,
+ '$return_path' => DI::args()->getQueryString(),
'$action' => 'item',
'$share' => ($x['button'] ?? '') ?: DI::l10n()->t('Share'),
'$loading' => DI::l10n()->t('Loading...'),
'$edimg' => DI::l10n()->t('Image'),
'$edurl' => DI::l10n()->t('Link'),
'$edattach' => DI::l10n()->t('Link or Media'),
+ '$edvideo' => DI::l10n()->t('Video'),
'$setloc' => DI::l10n()->t('Set your location'),
'$shortsetloc' => DI::l10n()->t('set location'),
'$noloc' => DI::l10n()->t('Clear browser location'),
'$placeholdertitle' => DI::l10n()->t('Set title'),
'$category' => $x['category'] ?? '',
'$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? DI::l10n()->t("Categories \x28comma-separated list\x29") : '',
+ '$scheduled_at' => Temporal::getDateTimeField(
+ new DateTime(),
+ DateTime::createFromFormat(DateTimeFormat::MYSQL, DateTimeFormat::local('now + 6 months')),
+ null,
+ DI::l10n()->t('Scheduled at'),
+ 'scheduled_at',
+ ),
'$wait' => DI::l10n()->t('Please wait'),
'$permset' => DI::l10n()->t('Permission settings'),
'$shortpermset' => DI::l10n()->t('Permissions'),
'$preview' => DI::l10n()->t('Preview'),
'$jotplugins' => $jotplugins,
'$notes_cid' => $notes_cid,
- '$sourceapp' => DI::l10n()->t($a->sourcename),
'$cancel' => DI::l10n()->t('Cancel'),
'$rand_num' => Crypto::randomDigits(12),
$o = '<div id="jot-popup" style="display: none;">' . $o . '</div>';
}
+ DI::profiler()->stopRecording();
return $o;
}
*/
function get_item_children(array &$item_list, array $parent, $recursive = true)
{
+ DI::profiler()->startRecording('rendering');
$children = [];
foreach ($item_list as $i => $item) {
if ($item['gravity'] != GRAVITY_PARENT) {
if ($recursive) {
// Fallback to parent-uri if thr-parent is not set
- $thr_parent = $item['thr-parent'];
+ $thr_parent = $item['thr-parent-id'];
if ($thr_parent == '') {
- $thr_parent = $item['parent-uri'];
+ $thr_parent = $item['parent-uri-id'];
}
- if ($thr_parent == $parent['uri']) {
+ if ($thr_parent == $parent['uri-id']) {
$item['children'] = get_item_children($item_list, $item);
$children[] = $item;
unset($item_list[$i]);
}
- } elseif ($item['parent'] == $parent['id']) {
+ } elseif ($item['parent-uri-id'] == $parent['uri-id']) {
$children[] = $item;
unset($item_list[$i]);
}
}
}
+ DI::profiler()->stopRecording();
return $children;
}
*/
function sort_item_children(array $items)
{
+ DI::profiler()->startRecording('rendering');
$result = $items;
usort($result, 'sort_thr_received_rev');
foreach ($result as $k => $i) {
$result[$k]['children'] = sort_item_children($result[$k]['children']);
}
}
+ DI::profiler()->stopRecording();
return $result;
}
*/
function smart_flatten_conversation(array $parent)
{
+ DI::profiler()->startRecording('rendering');
if (!isset($parent['children']) || count($parent['children']) == 0) {
+ DI::profiler()->stopRecording();
return $parent;
}
if (isset($child['children']) && count($child['children'])) {
// This helps counting only the regular posts
$count_post_closure = function($var) {
+ DI::profiler()->stopRecording();
return $var['verb'] === Activity::POST;
};
}
}
+ DI::profiler()->stopRecording();
return $parent;
}
*/
function conv_sort(array $item_list, $order)
{
+ DI::profiler()->startRecording('rendering');
$parents = [];
if (!(is_array($item_list) && count($item_list))) {
+ DI::profiler()->stopRecording();
return $parents;
}
continue;
}
- $item_array[$item['uri']] = $item;
+ $item_array[$item['uri-id']] = $item;
}
// Extract the top level items
}
}
+ DI::profiler()->stopRecording();
return $parents;
}
{
return strcmp($b['commented'], $a['commented']);
}
-
-function render_location_dummy(array $item) {
- if (!empty($item['location']) && !empty($item['location'])) {
- return $item['location'];
- }
-
- if (!empty($item['coord']) && !empty($item['coord'])) {
- return $item['coord'];
- }
-}