X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fconversation.php;h=ed9086307b4b4cb9f604f8452e17a55e070f1189;hb=cc5e5be931bc21e44d0cb26778e8cc15be924e41;hp=a4fe9c00e397a7f6053990ed2997a589b5248330;hpb=7de6e60328a6b5878f988f3421d5beabd0264d4a;p=friendica.git
diff --git a/include/conversation.php b/include/conversation.php
index a4fe9c00e3..ed9086307b 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -28,18 +28,19 @@ use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
+use Friendica\Core\Theme;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Profile;
use Friendica\Model\Tag;
+use Friendica\Model\Verb;
use Friendica\Object\Post;
use Friendica\Object\Thread;
use Friendica\Protocol\Activity;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
-use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
use Friendica\Util\XML;
@@ -315,7 +316,7 @@ function conv_get_blocklist()
return [];
}
- $str_blocked = DI::pConfig()->get(local_user(), 'system', 'blocked');
+ $str_blocked = str_replace(["\n", "\r"], ",", DI::pConfig()->get(local_user(), 'system', 'blocked'));
if (empty($str_blocked)) {
return [];
}
@@ -324,7 +325,7 @@ function conv_get_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, true, ['url' => trim($entry)]);
+ $cid = Contact::getIdForURL(trim($entry), 0, false, ['url' => trim($entry)]);
if (!empty($cid)) {
$blocklist[] = $cid;
}
@@ -354,6 +355,13 @@ function conv_get_blocklist()
*/
function conversation(App $a, array $items, $mode, $update, $preview = false, $order = 'commented', $uid = 0)
{
+ $page = DI::page();
+
+ $page->registerFooterScript(Theme::getPathForFile('asset/typeahead.js/dist/typeahead.bundle.js'));
+ $page->registerFooterScript(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.js'));
+ $page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput.css'));
+ $page->registerStylesheet(Theme::getPathForFile('js/friendica-tagsinput/friendica-tagsinput-typeahead.css'));
+
$ssl_state = (local_user() ? true : false);
$profile_owner = 0;
@@ -376,17 +384,17 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
. "\r\n";
}
@@ -512,10 +520,6 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
$threadsid++;
- $owner_url = '';
- $owner_name = '';
- $sparkle = '';
-
// prevent private email from leaking.
if ($item['network'] === Protocol::MAIL && local_user() != $item['uid']) {
continue;
@@ -532,14 +536,14 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
'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));
+ $location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
localize_item($item);
if ($mode === 'network-new') {
@@ -555,10 +559,6 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
'delete' => DI::l10n()->t('Delete'),
];
- $star = false;
- $isstarred = "unstarred";
-
- $lock = false;
$likebuttons = [
'like' => null,
'dislike' => null,
@@ -569,7 +569,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
unset($likebuttons['dislike']);
}
- $body = Item::prepareBody($item, true, $preview);
+ $body_html = Item::prepareBody($item, true, $preview);
list($categories, $folders) = DI::contentItem()->determineCategoriesTerms($item);
@@ -588,13 +588,13 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
'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(ProxyUtils::proxifyUrl($item['author-avatar'], false, ProxyUtils::SIZE_THUMB)),
+ 'lock' => false,
+ 'thumb' => DI::baseUrl()->remove($item['author-avatar']),
'title' => $title,
- 'body' => $body,
+ 'body_html' => $body_html,
'tags' => $tags['tags'],
'hashtags' => $tags['hashtags'],
'mentions' => $tags['mentions'],
@@ -605,23 +605,23 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
'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,
+ 'location_html' => $location_html,
'indent' => '',
- 'owner_name' => $owner_name,
- 'owner_url' => $owner_url,
- 'owner_photo' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($item['owner-avatar'], false, ProxyUtils::SIZE_THUMB)),
+ 'owner_name' => '',
+ 'owner_url' => '',
+ 'owner_photo' => DI::baseUrl()->remove($item['owner-avatar']),
'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'),
@@ -670,7 +670,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
$item['pagedrop'] = $page_dropping;
- if ($item['id'] == $item['parent']) {
+ if ($item['gravity'] == GRAVITY_PARENT) {
$item_object = new Post($item);
$conv->addParent($item_object);
}
@@ -710,17 +710,68 @@ function conversation_fetch_comments($thread_items, $pinned) {
$comments = [];
$parentlines = [];
$lineno = 0;
+ $direction = [];
$actor = [];
$received = '';
while ($row = Item::fetch($thread_items)) {
- if (($row['verb'] == Activity::ANNOUNCE) && !empty($row['contact-uid']) && ($row['received'] > $received) && ($row['thr-parent'] == $row['parent-uri'])) {
- $actor = ['link' => $row['author-link'], 'avatar' => $row['author-avatar'], 'name' => $row['author-name']];
+ 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 = '' . htmlentities($row['author-name']) . '';
+
+ $actor = ['url' => $url, 'link' => $row['author-link'], 'avatar' => $row['author-avatar'], 'name' => $row['author-name']];
$received = $row['received'];
}
- if ((($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && !in_array($row['network'], [Protocol::DIASPORA])) &&
- (empty($row['contact-uid']) || !in_array($row['network'], Protocol::NATIVE_SUPPORT))) {
+ 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'])];
+ }
+
+ switch ($row['post-type']) {
+ case Item::PT_TO:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'to')];
+ break;
+ case Item::PT_CC:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'cc')];
+ break;
+ case Item::PT_BTO:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bto')];
+ break;
+ case Item::PT_BCC:
+ $row['direction'] = ['direction' => 7, 'title' => DI::l10n()->t('You had been addressed (%s).', 'bcc')];
+ break;
+ case Item::PT_FOLLOWER:
+ $row['direction'] = ['direction' => 6, 'title' => DI::l10n()->t('You are following %s.', $row['author-name'])];
+ break;
+ case Item::PT_TAG:
+ $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')];
+ break;
+ case Item::PT_ANNOUNCEMENT:
+ $row['direction'] = ['direction' => 3, 'title' => DI::l10n()->t('Reshared')];
+ break;
+ case Item::PT_COMMENT:
+ $row['direction'] = ['direction' => 5, 'title' => DI::l10n()->t('%s is participating in this thread.', $row['author-name'])];
+ break;
+ case Item::PT_STORED:
+ $row['direction'] = ['direction' => 8, 'title' => DI::l10n()->t('Stored')];
+ break;
+ case Item::PT_GLOBAL:
+ $row['direction'] = ['direction' => 9, 'title' => DI::l10n()->t('Global')];
+ break;
+ default:
+ if ($row['uid'] == 0) {
+ $row['direction'] = ['direction' => 9, 'title' => DI::l10n()->t('Global')];
+ }
+ }
+
+ if (($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && ($row['author-id'] == $row['owner-id']) &&
+ !Contact::isSharing($row['author-id'], $row['uid'])) {
$parentlines[] = $lineno;
}
@@ -734,11 +785,17 @@ function conversation_fetch_comments($thread_items, $pinned) {
DBA::close($thread_items);
- if (!empty($actor)) {
+ if (!empty($direction)) {
foreach ($parentlines as $line) {
- $comments[$line]['owner-link'] = $actor['link'];
- $comments[$line]['owner-avatar'] = $actor['avatar'];
- $comments[$line]['owner-name'] = $actor['name'];
+ $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'];
+ }
+ }
}
}
return $comments;
@@ -759,9 +816,13 @@ function conversation_fetch_comments($thread_items, $pinned) {
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
function conversation_add_children(array $parents, $block_authors, $order, $uid) {
- $max_comments = DI::config()->get('system', 'max_comments', 100);
+ 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' => ['uid', 'commented' => true]];
+ $params = ['order' => ['gravity', 'uid', 'commented' => true]];
if ($max_comments > 0) {
$params['limit'] = $max_comments;
@@ -770,19 +831,9 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
$items = [];
foreach ($parents AS $parent) {
- $condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) ",
- $parent['uri'], $uid];
- if ($block_authors) {
- $condition[0] .= "AND NOT `author`.`hidden`";
- }
-
- $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity']), $condition, $params);
-
- $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false);
-
- if (count($comments) != 0) {
- $items = array_merge($items, $comments);
- }
+ $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);
}
foreach ($items as $index => $item) {
@@ -796,6 +847,31 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
return $items;
}
+/**
+ * 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`";
+ }
+
+ $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity', 'post-type']), $condition, $params);
+
+ $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false);
+
+ if (count($comments) != 0) {
+ $items = array_merge($items, $comments);
+ }
+ return $items;
+}
+
function item_photo_menu($item) {
$sub_link = '';
$poke_link = '';
@@ -807,7 +883,7 @@ function item_photo_menu($item) {
$block_link = '';
$ignore_link = '';
- if (local_user() && local_user() == $item['uid'] && $item['parent'] == $item['id'] && !$item['self']) {
+ if (local_user() && local_user() == $item['uid'] && $item['gravity'] == GRAVITY_PARENT && !$item['self']) {
$sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
}
@@ -817,7 +893,7 @@ function item_photo_menu($item) {
$sparkle = (strpos($profile_link, 'redir/') === 0);
$cid = 0;
- $pcid = Contact::getIdForURL($item['author-link'], 0, true);
+ $pcid = Contact::getIdForURL($item['author-link'], 0, false);
$network = '';
$rel = 0;
$condition = ['uid' => local_user(), 'nurl' => Strings::normaliseLink($item['author-link'])];
@@ -932,7 +1008,7 @@ function builtin_activity_puller($item, &$conv_responses) {
return;
}
- if (!empty($item['verb']) && DI::activity()->match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
+ 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']];
$url = Contact::magicLinkByContact($author);
@@ -1094,34 +1170,12 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
$jotplugins = '';
Hook::callAll('jot_tool', $jotplugins);
- // Private/public post links for the non-JS ACL form
- $private_post = 1;
- if (!empty($_REQUEST['public'])) {
- $private_post = 0;
- }
-
- $query_str = DI::args()->getQueryString();
- if (strpos($query_str, 'public=1') !== false) {
- $query_str = str_replace(['?public=1', '&public=1'], ['', ''], $query_str);
- }
-
- /*
- * I think $a->query_string may never have ? in it, but I could be wrong
- * It looks like it's from the index.php?q=[etc] rewrite that the web
- * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
- */
- if (strpos($query_str, '?') === false) {
- $public_post_link = '?public=1';
- } else {
- $public_post_link = '&public=1';
- }
-
// $tpl = Renderer::replaceMacros($tpl,array('$jotplugins' => $jotplugins));
$tpl = Renderer::getMarkupTemplate("jot.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...'),
@@ -1147,7 +1201,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
'$placeholdercategory' => Feature::isEnabled(local_user(), 'categories') ? DI::l10n()->t("Categories \x28comma-separated list\x29") : '',
'$wait' => DI::l10n()->t('Please wait'),
'$permset' => DI::l10n()->t('Permission settings'),
- '$shortpermset' => DI::l10n()->t('permissions'),
+ '$shortpermset' => DI::l10n()->t('Permissions'),
'$wall' => $notes_cid ? 0 : 1,
'$posttype' => $notes_cid ? Item::PT_PERSONAL_NOTE : Item::PT_ARTICLE,
'$content' => $x['content'] ?? '',
@@ -1169,11 +1223,6 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
// ACL permissions box
'$acl' => $x['acl'],
- '$group_perms' => DI::l10n()->t('Post to Groups'),
- '$contact_perms' => DI::l10n()->t('Post to Contacts'),
- '$private' => DI::l10n()->t('Private post'),
- '$is_private' => $private_post,
- '$public_link' => $public_post_link,
//jot nav tab (used in some themes)
'$message' => DI::l10n()->t('Message'),
@@ -1202,7 +1251,7 @@ function get_item_children(array &$item_list, array $parent, $recursive = true)
{
$children = [];
foreach ($item_list as $i => $item) {
- if ($item['id'] != $item['parent']) {
+ if ($item['gravity'] != GRAVITY_PARENT) {
if ($recursive) {
// Fallback to parent-uri if thr-parent is not set
$thr_parent = $item['thr-parent'];
@@ -1350,7 +1399,7 @@ function conv_sort(array $item_list, $order)
// Extract the top level items
foreach ($item_array as $item) {
- if ($item['id'] == $item['parent']) {
+ if ($item['gravity'] == GRAVITY_PARENT) {
$parents[] = $item;
}
}
@@ -1447,13 +1496,3 @@ function sort_thr_commented(array $a, array $b)
{
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'];
- }
-}