X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fconversation.php;h=324b53b5a880410584f5695a48b15c4798f17188;hb=4f8530070b0a27762a41218bd8f376166c54df97;hp=b262ee4c828b498734a7e9b7e2e96c903674318b;hpb=a64e7a988c54512a905faab10ec16f01ce08db2c;p=friendica.git diff --git a/include/conversation.php b/include/conversation.php index b262ee4c82..324b53b5a8 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -21,8 +21,6 @@ use Friendica\Util\DateTimeFormat; use Friendica\Util\Temporal; use Friendica\Util\XML; -require_once "include/acl_selectors.php"; - function item_extract_images($body) { $saved_image = []; @@ -38,7 +36,7 @@ function item_extract_images($body) { $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:')) { + 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)); @@ -213,7 +211,7 @@ function localize_item(&$item) { } if (stristr($item['verb'], ACTIVITY_POKE)) { $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1)); - if (! $verb) { + if (!$verb) { return; } if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) { @@ -338,7 +336,7 @@ function localize_item(&$item) { $matches = null; if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) { foreach ($matches as $mtch) { - if (! strpos($mtch[1], 'zrl=')) { + if (!strpos($mtch[1], 'zrl=')) { $item['body'] = str_replace($mtch[0], '@[url=' . Profile::zrl($mtch[1]) . ']', $item['body']); } } @@ -373,7 +371,7 @@ function count_descendants($item) { if ($total > 0) { foreach ($item['children'] as $child) { - if (! visible_activity($child)) { + if (!visible_activity($child)) { $total --; } $total += count_descendants($child); @@ -397,7 +395,7 @@ function visible_activity($item) { } if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) { - if (! (($item['self']) && ($item['uid'] == local_user()))) { + if (!($item['self'] && ($item['uid'] == local_user()))) { return false; } } @@ -435,7 +433,6 @@ These Fields are not added below (yet). They are here to for bug search. `item`.`bookmark`, `item`.`unseen`, `item`.`deleted`, -`item`.`origin`, `item`.`forum_mode`, `item`.`mention`, `item`.`global`, @@ -445,10 +442,10 @@ These Fields are not added below (yet). They are here to for bug search. return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`, `item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`, `item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`, - `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, + `item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`content-warning`, `item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`, `item`.`verb`, `item`.`object-type`, `item`.`postopts`, `item`.`plink`, - `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`, + `item`.`guid`, `item`.`wall`, `item`.`private`, `item`.`starred`, `item`.`origin`, `item`.`title`, `item`.`body`, `item`.`file`, `item`.`event-id`, `item`.`location`, `item`.`coord`, `item`.`app`, `item`.`attach`, `item`.`rendered-hash`, `item`.`rendered-html`, `item`.`object`, @@ -472,11 +469,15 @@ These Fields are not added below (yet). They are here to for bug search. * @brief SQL join for contacts that are needed for displaying items */ function item_joins() { - return "STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND - (NOT `contact`.`blocked` OR `contact`.`pending`) - LEFT JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` - LEFT JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id` - LEFT JOIN `event` ON `event-id` = `event`.`id`"; + return sprintf("STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + AND NOT `contact`.`blocked` + AND ((NOT `contact`.`readonly` AND NOT `contact`.`pending` AND (`contact`.`rel` IN (%s, %s))) + OR `contact`.`self` OR (`item`.`id` != `item`.`parent`) OR `contact`.`uid` = 0) + INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` AND NOT `author`.`blocked` + INNER JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id` AND NOT `owner`.`blocked` + LEFT JOIN `event` ON `event-id` = `event`.`id`", + CONTACT_IS_SHARING, CONTACT_IS_FRIEND + ); } /** @@ -636,6 +637,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = foreach ($items as $item) { + if (!visible_activity($item)) { + continue; + } + if ($arr_blocked) { $blocked = false; foreach ($arr_blocked as $b) { @@ -661,38 +666,12 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = continue; } - $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']); - if ($item['author-link'] && (! $item['author-name'])) { + $profile_name = (strlen($item['author-name']) ? $item['author-name'] : $item['name']); + if ($item['author-link'] && !$item['author-name']) { $profile_name = $item['author-link']; } - $tags = []; - $hashtags = []; - $mentions = []; - - $searchpath = System::baseUrl()."/search?tag="; - - $taglist = dba::select('term', ['type', 'term', 'url'], - ["`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION], - ['order' => ['tid']]); - - while ($tag = dba::fetch($taglist)) { - if ($tag["url"] == "") { - $tag["url"] = $searchpath . strtolower($tag["term"]); - } - - $tag["url"] = best_link_url($item, $sp, $tag["url"]); - - if ($tag["type"] == TERM_HASHTAG) { - $hashtags[] = "#" . $tag["term"] . ""; - $prefix = "#"; - } elseif ($tag["type"] == TERM_MENTION) { - $mentions[] = "@" . $tag["term"] . ""; - $prefix = "@"; - } - $tags[] = $prefix."" . $tag["term"] . ""; - } - dba::close($taglist); + $tags = \Friendica\Model\Term::populateTagsFromItem($item); $sp = false; $profile_link = best_link_url($item, $sp); @@ -754,11 +733,17 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = list($categories, $folders) = get_cats_and_terms($item); $profile_name_e = $profile_name; - $item['title_e'] = $item['title']; + + if (!empty($item['content-warning']) && PConfig::get(local_user(), 'system', 'disable_cw', false)) { + $title_e = ucfirst($item['content-warning']); + } else { + $title_e = $item['title']; + } + $body_e = $body; - $tags_e = $tags; - $hashtags_e = $hashtags; - $mentions_e = $mentions; + $tags_e = $tags['tags']; + $hashtags_e = $tags['hashtags']; + $mentions_e = $tags['mentions']; $location_e = $location; $owner_name_e = $owner_name; @@ -779,7 +764,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = 'sparkle' => $sparkle, 'lock' => $lock, 'thumb' => System::removedBaseUrl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)), - 'title' => $item['title_e'], + 'title' => $title_e, 'body' => $body_e, 'tags' => $tags_e, 'hashtags' => $hashtags_e, @@ -854,7 +839,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = continue; } - if (! visible_activity($item)) { + if (!visible_activity($item)) { continue; } @@ -901,44 +886,25 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = * @return array items with parents and comments */ function conversation_add_children($parents, $block_authors, $order) { - $max_comments = Config::get("system", "max_comments", 100); + $max_comments = Config::get('system', 'max_comments', 100); + + if ($max_comments > 0) { + $limit = ' LIMIT '.intval($max_comments + 1); + } else { + $limit = ''; + } $items = []; $block_sql = $block_authors ? "AND NOT `author`.`hidden` AND NOT `author`.`blocked`" : ""; foreach ($parents AS $parent) { - $thread_items = dba::p(item_query()." AND `item`.`uid` = ? - AND `item`.`parent-uri` = ? $block_sql - ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1), - local_user(), - $parent['uri'] - ); - $comments = dba::inArray($thread_items); - - // Check if the original item is in the result. - // When commenting from the community page there can be incomplete threads - if (count($comments) > 0) { - $parent_found = false; - foreach ($comments as $comment) { - if ($comment['uri'] == $comment['parent-uri']) { - $parent_found = true; - break; - } - } - if (!$parent_found) { - $comments = []; - } - } + $thread_items = dba::p(item_query()."AND `item`.`parent-uri` = ? + AND `item`.`uid` IN (0, ?) $block_sql + ORDER BY `item`.`uid` ASC, `item`.`commented` DESC" . $limit, + $parent['uri'], local_user()); - if (count($comments) == 0) { - $thread_items = dba::p(item_query()." AND `item`.`uid` = 0 - AND `item`.`parent-uri` = ? - ORDER BY `item`.`commented` DESC LIMIT ".intval($max_comments + 1), - $parent['uri'] - ); - $comments = dba::inArray($thread_items); - } + $comments = dba::inArray($thread_items); if (count($comments) != 0) { $items = array_merge($items, $comments); @@ -984,7 +950,7 @@ function best_link_url($item, &$sparkle, $url = '') { } } } - if (! $best_url) { + if (!$best_url) { if ($url != '') { $best_url = $url; } elseif (strlen($item['author-link'])) { @@ -1007,7 +973,7 @@ function item_photo_menu($item) { $photos_link = ''; $posts_link = ''; - if ((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) { + if (local_user() && local_user() == $item['uid'] && $item['parent'] == $item['id'] && !$item['self']) { $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;'; } @@ -1120,9 +1086,9 @@ function builtin_activity_puller($item, &$conv_responses) { return; } - if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) { + if (activity_match($item['verb'], $verb) && ($item['id'] != $item['parent'])) { $url = $item['author-link']; - if ((local_user()) && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && (! $item['self']) && (link_compare($item['author-link'], $item['url']))) { + if (local_user() && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && !$item['self'] && link_compare($item['author-link'], $item['url'])) { $url = 'redir/' . $item['contact-id']; $sparkle = ' class="sparkle" '; } else { @@ -1131,12 +1097,12 @@ function builtin_activity_puller($item, &$conv_responses) { $url = '' . htmlentities($item['author-name']) . ''; - if (! $item['thr-parent']) { + if (!$item['thr-parent']) { $item['thr-parent'] = $item['parent-uri']; } - if (! ((isset($conv_responses[$mode][$item['thr-parent'] . '-l'])) - && (is_array($conv_responses[$mode][$item['thr-parent'] . '-l'])))) { + 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'] = []; } @@ -1145,7 +1111,7 @@ function builtin_activity_puller($item, &$conv_responses) { continue; } - if (! isset($conv_responses[$mode][$item['thr-parent']])) { + if (!isset($conv_responses[$mode][$item['thr-parent']])) { $conv_responses[$mode][$item['thr-parent']] = 1; } else { $conv_responses[$mode][$item['thr-parent']] ++; @@ -1237,7 +1203,7 @@ function format_like($cnt, array $arr, $type, $id) { break; case 'attendmaybe': $phrase = L10n::t('%2$d people attend maybe', $spanatts, $cnt); - $explikers = L10n::t('%s anttend maybe.', $likers); + $explikers = L10n::t('%s attend maybe.', $likers); break; } @@ -1321,6 +1287,7 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false) $tpl = get_markup_template("jot.tpl"); $o .= replace_macros($tpl,[ + '$new_post' => L10n::t('New Post'), '$return_path' => $query_str, '$action' => 'item', '$share' => defaults($x, 'button', L10n::t('Share')), @@ -1472,7 +1439,7 @@ function add_children_to_list(array $children, array &$item_list) */ function smart_flatten_conversation(array $parent) { - if (! isset($parent['children']) || count($parent['children']) == 0) { + if (!isset($parent['children']) || count($parent['children']) == 0) { return $parent; } @@ -1635,7 +1602,7 @@ function get_responses($conv_responses, $response_verbs, $ob, $item) { foreach ($response_verbs as $v) { $ret[$v] = []; $ret[$v]['count'] = defaults($conv_responses[$v], $item['uri'], ''); - $ret[$v]['list'] = defaults($conv_responses[$v], $item['uri'] . '-l', ''); + $ret[$v]['list'] = defaults($conv_responses[$v], $item['uri'] . '-l', []); $ret[$v]['self'] = defaults($conv_responses[$v], $item['uri'] . '-self', '0'); if (count($ret[$v]['list']) > MAX_LIKERS) { $ret[$v]['list_part'] = array_slice($ret[$v]['list'], 0, MAX_LIKERS);