]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Merge pull request #4183 from MrPetovan/bug/4173-fix-oembed-iframe-url
[friendica.git] / include / conversation.php
index 958d507d78d979223c71c9c773ebbf73c15d3154..472896ffec2e45c3d342e8d11cd036bd1c2a8f05 100644 (file)
@@ -490,7 +490,6 @@ function item_condition() {
  *
  */
 function conversation(App $a, $items, $mode, $update, $preview = false) {
-
        require_once 'include/bbcode.php';
        require_once 'mod/proxy.php';
 
@@ -575,10 +574,14 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                                . " var profile_page = 1; </script>";
                }
        } elseif ($mode === 'community') {
+               if (!$community_readonly) {
+                       $items = community_add_items($items);
+               }
                $profile_owner = 0;
                if (!$update) {
                        $live_update_div = '<div id="live-community"></div>' . "\r\n"
-                               . "<script> var profile_uid = -1; var netargs = '/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
+                               . "<script> var profile_uid = -1; var netargs = '" . substr($a->cmd, 10)
+                               ."/?f='; var profile_page = " . $a->pager['page'] . "; </script>\r\n";
                }
        } elseif ($mode === 'search') {
                $live_update_div = '<div id="live-search"></div>' . "\r\n";
@@ -586,11 +589,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);
@@ -598,9 +598,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'))
@@ -613,14 +610,25 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
        $page_template = get_markup_template("conversation.tpl");
 
        if ($items && count($items)) {
+               $community_readonly = ($mode === 'community');
+
                // Currently behind a config value. This allows the commenting and sharing of every public item.
-               if (Config::get('system', 'comment_public') && local_user()) {
-                       $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], array(NETWORK_OSTATUS, NETWORK_DIASPORA));
+               if (Config::get('system', 'comment_public')) {
+                       if ($mode === 'community') {
+                               $community_readonly = false;
+                               $writable = true;
+                       } else {
+                               $writable = ($items[0]['uid'] == 0) && in_array($items[0]['network'], array(NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN));
+                       }
                } else {
                        $writable = false;
                }
 
-               if ($mode === 'network-new' || $mode === 'search' || $mode === 'community') {
+               if (!local_user()) {
+                       $writable = false;
+               }
+
+               if (in_array($mode, ['network-new', 'search', 'contact-posts']) || $community_readonly) {
 
                        /*
                         * "New Item View" on network page or search page results
@@ -745,7 +753,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
 
                                $lock = false;
                                $likebuttons = false;
-                               $shareable = false;
 
                                $body = prepare_body($item, true, $preview);
 
@@ -830,9 +837,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) {
@@ -869,7 +874,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();
@@ -891,6 +895,70 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
        return $o;
 }
 
+/**
+ * @brief Add comments to top level entries that had been fetched before
+ *
+ * The system will fetch the comments for the local user whenever possible.
+ * This behaviour is currently needed to allow commenting on Friendica posts.
+ *
+ * @param array $parents Parent items
+ *
+ * @return array items with parents and comments
+ */
+function community_add_items($parents) {
+       $max_comments = Config::get("system", "max_comments", 100);
+
+       $items = array();
+
+       foreach ($parents AS $parent) {
+               $thread_items = dba::p(item_query()." AND `item`.`uid` = ?
+                       AND `item`.`parent-uri` = ?
+                       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 = array();
+                       }
+               }
+
+               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);
+               }
+
+               if (count($comments) != 0) {
+                       $items = array_merge($items, $comments);
+               }
+       }
+
+       foreach ($items as $index => $item) {
+               if ($item['uid'] == 0) {
+                       $items[$index]['writable'] = in_array($item['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA, NETWORK_DFRN]);
+               }
+       }
+
+       $items = conv_sort($items, "`commented`");
+
+       return $items;
+}
+
 function best_link_url($item, &$sparkle, $url = '') {
 
        $best_url = '';
@@ -937,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;';
@@ -963,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);
        }
@@ -1050,7 +1116,6 @@ function builtin_activity_puller($item, &$conv_responses) {
                                break;
                        default:
                                return;
-                               break;
                }
 
                if ((activity_match($item['verb'], $verb)) && ($item['id'] != $item['parent'])) {
@@ -1298,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'),
@@ -1593,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;
 }