X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fconversation.php;h=21b700f2fe0e42de4f0c9477ecd12b462454b8a1;hb=e0ecbd0b95454ed2ff4b0082b41d388d2938e3ae;hp=97be7e9aa984436725c748be807553e14a06e574;hpb=af39296f0640bc40e58f51ec47c4e5aa53a24316;p=friendica.git diff --git a/include/conversation.php b/include/conversation.php index 97be7e9aa9..21b700f2fe 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -110,14 +110,21 @@ function item_redir_and_replace_images($body, $images, $cid) { /** * Render actions localized */ -function localize_item(&$item) { - +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 Separted ??? + /* + heluecht 2018-06-19: from my point of view this whole code part is useless. + It just renders the body message of technical posts (Like, dislike, ...). + But: The body isn't visible at all. So we do this stuff just because we can. + Even if these messages were visible, this would only mean that something went wrong. + During the further steps of the database restructuring I would like to address this issue. + */ + $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; if (activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE) @@ -125,15 +132,11 @@ function localize_item(&$item) { || activity_match($item['verb'], ACTIVITY_ATTENDNO) || activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) { - /// @TODO may hurt performance - $r = q("SELECT * FROM `item`, `contact` - WHERE `item`.`contact-id`=`contact`.`id` - AND `item`.`uri`='%s'", - dbesc($item['parent-uri'])); - if (!DBM::is_result($r)) { + $fields = ['author-link', 'author-name', 'verb', 'object-type', 'resource-id', 'body', 'plink']; + $obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]); + if (!DBM::is_result($obj)) { return; } - $obj = $r[0]; $author = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]'; $objauthor = '[url=' . $obj['author-link'] . ']' . $obj['author-name'] . '[/url]'; @@ -189,7 +192,8 @@ function localize_item(&$item) { $links = XML::parseString($xmlhead."".unxmlify($obj->link).""); $Bname = $obj->title; - $Blink = ""; $Bphoto = ""; + $Blink = ""; + $Bphoto = ""; foreach ($links->link as $l) { $atts = $l->attributes(); switch ($atts['rel']) { @@ -249,7 +253,7 @@ function localize_item(&$item) { // now translate the verb $poked_t = trim(sprintf($txt, "", "")); - $txt = str_replace( $poked_t, L10n::t($verb), $txt); + $txt = str_replace($poked_t, L10n::t($verb), $txt); // then do the sprintf on the translation string @@ -258,20 +262,20 @@ function localize_item(&$item) { } if (activity_match($item['verb'], ACTIVITY_TAG)) { - /// @TODO may hurt performance "joining" two tables + asterisk - $r = q("SELECT * FROM `item`, `contact` - WHERE `item`.`contact-id`=`contact`.`id` - AND `item`.`uri`='%s'", - dbesc($item['parent-uri'])); - - if (!DBM::is_result($r)) { + $fields = ['author-id', 'author-link', 'author-name', 'author-network', + 'verb', 'object-type', 'resource-id', 'body', 'plink']; + $obj = Item::selectFirst($fields, ['uri' => $item['parent-uri']]); + if (!DBM::is_result($obj)) { return; } - $obj = $r[0]; + $author_arr = ['uid' => 0, 'id' => $item['author-id'], + 'network' => $item['author-network'], 'url' => $item['author-link']]; + $author = '[url=' . Contact::magicLinkByContact($author_arr) . ']' . $item['author-name'] . '[/url]'; - $author = '[url=' . Contact::magicLinkById($item['author-id']) . ']' . $item['author-name'] . '[/url]'; - $objauthor = '[url=' . Contact::magicLinkById($obj['author-id']) . ']' . $obj['author-name'] . '[/url]'; + $author_arr = ['uid' => 0, 'id' => $obj['author-id'], + 'network' => $obj['author-network'], 'url' => $obj['author-link']]; + $objauthor = '[url=' . Contact::magicLinkByContact($author_arr) . ']' . $obj['author-name'] . '[/url]'; switch ($obj['verb']) { case ACTIVITY_POST: @@ -299,8 +303,7 @@ function localize_item(&$item) { $parsedobj = XML::parseString($xmlhead.$item['object']); $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content); - $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag ); - + $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag); } if (activity_match($item['verb'], ACTIVITY_FAVORITE)) { @@ -315,13 +318,9 @@ function localize_item(&$item) { $obj = XML::parseString($xmlhead.$item['object']); if (strlen($obj->id)) { - $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", - dbesc($obj->id), - intval($item['uid']) - ); - - if (DBM::is_result($r) && $r[0]['plink']) { - $target = $r[0]; + $fields = ['author-link', 'author-name', 'plink']; + $target = Item::selectFirst($fields, ['uri' => $obj->id, 'uid' => $item['uid']]); + if (DBM::is_result($target) && $target['plink']) { $Bname = $target['author-name']; $Blink = $target['author-link']; $A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]'; @@ -348,7 +347,12 @@ function localize_item(&$item) { } // add sparkle links to appropriate permalinks - $item['plink'] = Contact::magicLinkById($item['author-id'], $item['plink']); + $author = ['uid' => 0, 'id' => $item['author-id'], + 'network' => $item['author-network'], 'url' => $item['author-link']]; + + if (!empty($item['plink'])) { + $item['plink'] = Contact::magicLinkbyContact($author, $item['plink']); + } } /** @@ -401,7 +405,7 @@ function visible_activity($item) { * that are based on unique features of the calling module. * */ -function conversation(App $a, $items, $mode, $update, $preview = false, $order = 'commented', $uid = 0) { +function conversation(App $a, array $items, $mode, $update, $preview = false, $order = 'commented', $uid = 0) { require_once 'mod/proxy.php'; $ssl_state = ((local_user()) ? true : false); @@ -481,7 +485,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = $profile_owner = $a->profile['uid']; if (!$update) { $live_update_div = '
' . "\r\n" - . ""; } } elseif ($mode === 'community') { @@ -569,21 +573,16 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = continue; } - if ($item['network'] == NETWORK_FEED) { - $item['author-avatar'] = $item['contact-avatar']; - $item['author-name'] = $item['contact-name']; - $item['owner-avatar'] = $item['contact-avatar']; - $item['owner-name'] = $item['contact-name']; - } - - $profile_name = (strlen($item['author-name']) ? $item['author-name'] : $item['name']); - if ($item['author-link'] && !$item['author-name']) { + $profile_name = $item['author-name']; + if (!empty($item['author-link']) && empty($item['author-name'])) { $profile_name = $item['author-link']; } $tags = \Friendica\Model\Term::populateTagsFromItem($item); - $profile_link = Contact::magicLinkbyId($item['author-id']); + $author = ['uid' => 0, 'id' => $item['author-id'], + 'network' => $item['author-network'], 'url' => $item['author-link']]; + $profile_link = Contact::magicLinkbyContact($author); if (strpos($profile_link, 'redir/') === 0) { $sparkle = ' sparkle'; @@ -633,16 +632,12 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = $location_e = $location; $owner_name_e = $owner_name; - if ($item['item_network'] == "") { - $item['item_network'] = $item['network']; - } - $tmp_item = [ 'template' => $tpl, - 'id' => (($preview) ? 'P0' : $item['item_id']), - 'guid' => (($preview) ? 'Q0' : $item['guid']), - 'network' => $item['item_network'], - 'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link), + 'id' => ($preview ? 'P0' : $item['id']), + 'guid' => ($preview ? 'Q0' : $item['guid']), + 'network' => $item['network'], + 'network_name' => ContactSelector::networkToName($item['network'], $profile_link), 'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, $item['author-link']), 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), @@ -687,8 +682,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = $arr = ['item' => $item, 'output' => $tmp_item]; Addon::callHooks('display_item', $arr); - $threads[$threadsid]['id'] = $item['item_id']; - $threads[$threadsid]['network'] = $item['item_network']; + $threads[$threadsid]['id'] = $item['id']; + $threads[$threadsid]['network'] = $item['network']; $threads[$threadsid]['items'] = [$arr['output']]; } @@ -729,6 +724,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order = continue; } + /// @todo Check if this call is needed or not + $arr = ['item' => $item]; Addon::callHooks('display_item', $arr); $item['pagedrop'] = $page_dropping; @@ -771,7 +768,7 @@ 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, $uid) { +function conversation_add_children(array $parents, $block_authors, $order, $uid) { $max_comments = Config::get('system', 'max_comments', 100); $params = ['order' => ['uid', 'commented' => true]]; @@ -790,7 +787,7 @@ function conversation_add_children($parents, $block_authors, $order, $uid) { } $thread_items = Item::selectForUser(local_user(), [], $condition, $params); - $comments = dba::inArray($thread_items); + $comments = Item::inArray($thread_items); if (count($comments) != 0) { $items = array_merge($items, $comments); @@ -821,7 +818,9 @@ function item_photo_menu($item) { $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;'; } - $profile_link = Contact::magicLinkById($item['author-id']); + $author = ['uid' => 0, 'id' => $item['author-id'], + 'network' => $item['author-network'], 'url' => $item['author-link']]; + $profile_link = Contact::magicLinkbyContact($author); $sparkle = (strpos($profile_link, 'redir/') === 0); $cid = 0; @@ -926,7 +925,9 @@ function builtin_activity_puller($item, &$conv_responses) { } if (activity_match($item['verb'], $verb) && ($item['id'] != $item['parent'])) { - $url = Contact::MagicLinkbyId($item['author-id']); + $author = ['uid' => 0, 'id' => $item['author-id'], + 'network' => $item['author-network'], 'url' => $item['author-link']]; + $url = Contact::magicLinkbyContact($author); if (strpos($url, 'redir/') === 0) { $sparkle = ' class="sparkle" '; } @@ -1013,7 +1014,7 @@ function format_like($cnt, array $arr, $type, $id) { } if ($total >= MAX_LIKERS) { $str = implode(', ', $arr); - $str .= L10n::t('and %d other people', $total - MAX_LIKERS ); + $str .= L10n::t('and %d other people', $total - MAX_LIKERS); } $likers = $str;