]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Replace dba::select(limit => 1) by dba::selectOne
[friendica.git] / include / conversation.php
index 0a565c68e343adb27cf23387aa05774e8d40a259..746a8a89134cd9970230874b8b4952eb3bca2f87 100644 (file)
@@ -3,6 +3,7 @@
  * @file include/conversation.php
  */
 use Friendica\App;
+use Friendica\Content\ContactSelector;
 use Friendica\Content\Feature;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
@@ -589,11 +590,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
 
        $page_dropping = ((local_user() && local_user() == $profile_owner) ? true : false);
 
-
-       if ($update) {
-               $return_url = $_SESSION['return_url'];
-       } else {
-               $return_url = $_SESSION['return_url'] = $a->query_string;
+       if (!$update) {
+               $_SESSION['return_url'] = $a->query_string;
        }
 
        $cb = array('items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview);
@@ -601,9 +599,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
 
        $items = $cb['items'];
 
-       $cmnt_tpl    = get_markup_template('comment_item.tpl');
-       $hide_comments_tpl = get_markup_template('hide_comments.tpl');
-
        $conv_responses = array(
                'like' => array('title' => t('Likes','title')), 'dislike' => array('title' => t('Dislikes','title')),
                'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
@@ -634,7 +629,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                        $writable = false;
                }
 
-               if ($mode === 'network-new' || $mode === 'search' || $community_readonly) {
+               if (in_array($mode, ['network-new', 'search', 'contact-posts']) || $community_readonly) {
 
                        /*
                         * "New Item View" on network page or search page results
@@ -759,7 +754,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
 
                                $lock = false;
                                $likebuttons = false;
-                               $shareable = false;
 
                                $body = prepare_body($item, true, $preview);
 
@@ -783,7 +777,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                                        'id' => (($preview) ? 'P0' : $item['item_id']),
                                        'guid' => (($preview) ? 'Q0' : $item['guid']),
                                        'network' => $item['item_network'],
-                                       'network_name' => network_to_name($item['item_network'], $profile_link),
+                                       'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link),
                                        'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
                                        'profile_url' => $profile_link,
                                        'item_photo_menu' => item_photo_menu($item),
@@ -844,9 +838,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                         * this shouldn't be needed, as we should have only them in our array
                         * But for now, this array respects the old style, just in case
                         */
-                       $threads = array();
                        foreach ($items as $item) {
-
                                if ($arr_blocked) {
                                        $blocked = false;
                                        foreach ($arr_blocked as $b) {
@@ -883,7 +875,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                        }
 
                        $threads = $conv->getTemplateData($conv_responses);
-
                        if (!$threads) {
                                logger('[ERROR] conversation : Failed to get template data.', LOGGER_DEBUG);
                                $threads = array();
@@ -929,6 +920,20 @@ function community_add_items($parents) {
                );
                $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 = array();
+                       }
+               }
 
                if (count($comments) == 0) {
                        $thread_items = dba::p(item_query()." AND `item`.`uid` = 0
@@ -963,9 +968,8 @@ function best_link_url($item, &$sparkle, $url = '') {
        $clean_url = normalise_link($item['author-link']);
 
        if (local_user()) {
-               $r = dba::select('contact', array('id'),
-                       array('network' => NETWORK_DFRN, 'uid' => local_user(), 'nurl' => normalise_link($clean_url), 'pending' => false),
-                       array('limit' => 1));
+               $r = dba::selectOne('contact', ['id'],
+                       ['network' => NETWORK_DFRN, 'uid' => local_user(), 'nurl' => normalise_link($clean_url), 'pending' => false]);
                if (DBM::is_result($r)) {
                        $best_url = 'redir/' . $r['id'];
                        $sparkle = true;
@@ -1001,7 +1005,6 @@ function item_photo_menu($item) {
        $status_link = '';
        $photos_link = '';
        $posts_link = '';
-       $network = '';
 
        if ((local_user()) && local_user() == $item['uid'] && $item['parent'] == $item['id'] && (! $item['self'])) {
                $sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
@@ -1016,7 +1019,7 @@ function item_photo_menu($item) {
        $cid = 0;
        $network = '';
        $rel = 0;
-       $r = dba::select('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])), array('limit' => 1));
+       $r = dba::selectOne('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])));
        if (DBM::is_result($r)) {
                $cid = $r['id'];
                $network = $r['network'];
@@ -1027,7 +1030,6 @@ function item_photo_menu($item) {
                $status_link = $profile_link . '?url=status';
                $photos_link = $profile_link . '?url=photos';
                $profile_link = $profile_link . '?url=profile';
-               $zurl = '';
        } else {
                $profile_link = zrl($profile_link);
        }
@@ -1114,7 +1116,6 @@ function builtin_activity_puller($item, &$conv_responses) {
                                break;
                        default:
                                return;
-                               break;
                }
 
                if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
@@ -1362,7 +1363,6 @@ function status_editor(App $a, $x, $notes_cid = 0, $popup = false)
 
                // ACL permissions box
                '$acl'           => $x['acl'],
-               '$acl_data'      => $x['acl_data'],
                '$group_perms'   => t('Post to Groups'),
                '$contact_perms' => t('Post to Contacts'),
                '$private'       => t('Private post'),
@@ -1657,22 +1657,25 @@ function get_responses($conv_responses, $response_verbs, $ob, $item) {
        return $ret;
 }
 
-function get_response_button_text($v, $count) {
+function get_response_button_text($v, $count)
+{
        switch ($v) {
                case 'like':
-                       return tt('Like', 'Likes', $count, 'noun');
+                       $return = tt('Like', 'Likes', $count);
                        break;
                case 'dislike':
-                       return tt('Dislike', 'Dislikes', $count, 'noun');
+                       $return = tt('Dislike', 'Dislikes', $count);
                        break;
                case 'attendyes':
-                       return tt('Attending', 'Attending', $count, 'noun');
+                       $return = tt('Attending', 'Attending', $count);
                        break;
                case 'attendno':
-                       return tt('Not Attending', 'Not Attending', $count, 'noun');
+                       $return = tt('Not Attending', 'Not Attending', $count);
                        break;
                case 'attendmaybe':
-                       return tt('Undecided', 'Undecided', $count, 'noun');
+                       $return = tt('Undecided', 'Undecided', $count);
                        break;
        }
+
+       return $return;
 }