viewgit/inc/functions.php:22 Function utf8_encode() is deprecated [8192]

Fixes bugs in wiki page with feedback fixes bugs in edit and commeenting on combined feed, a=chris

Chris Pollett [2020-08-04 03:Aug:th]
Fixes bugs in wiki page with feedback fixes bugs in edit and commeenting on combined feed, a=chris
Filename
src/controllers/Controller.php
src/controllers/components/SocialComponent.php
src/views/elements/GroupfeedElement.php
diff --git a/src/controllers/Controller.php b/src/controllers/Controller.php
index b979538e2..72b7ab400 100755
--- a/src/controllers/Controller.php
+++ b/src/controllers/Controller.php
@@ -320,7 +320,7 @@ abstract class Controller
     {
         $default_fields = ["c", "a", C\CSRF_TOKEN, "just_thread",
             "just_group_id", "just_user_id", "group_id", "user_id", "role_id",
-            "limit", "num"];
+            "limit", "num", "v"];
         if ($copy_fields) {
             $copy_fields = array_merge($default_fields, $copy_fields);
         } else {
diff --git a/src/controllers/components/SocialComponent.php b/src/controllers/components/SocialComponent.php
index 384fd21e3..211faf893 100644
--- a/src/controllers/components/SocialComponent.php
+++ b/src/controllers/components/SocialComponent.php
@@ -1314,16 +1314,25 @@ class SocialComponent extends Component implements CrawlConstants
             in_array($_REQUEST['arg'], $possible_arguments)) {
             switch ($_REQUEST['arg']) {
                 case "addcomment":
+                    if (!empty($_REQUEST['page_type']) &&
+                         $_REQUEST['page_type'] == "page_and_feedback") {
+                         $_REQUEST['a'] = "wiki";
+                         unset($_REQUEST['just_thread']);
+                         unset($_REQUEST['limit']);
+                         unset($_REQUEST['num']);
+                    }
                     if (!isset($_REQUEST['parent_id'])
                         || !$_REQUEST['parent_id']
                         || !isset($_REQUEST['group_id'])
                         || !$_REQUEST['group_id']) {
                         return $parent->redirectWithMessage(
-                            tl('social_component_comment_error'));
+                            tl('social_component_comment_error'),
+                            ['page_name']);
                     }
                     if (!$description) {
                         return $parent->redirectWithMessage(
-                            tl('social_component_no_comment'));
+                            tl('social_component_no_comment'),
+                            ['page_name']);
                     }
                     $parent_id = $parent->clean($_REQUEST['parent_id'], "int");
                     $group_id = $parent->clean($_REQUEST['group_id'], "int");
@@ -1335,13 +1344,15 @@ class SocialComponent extends Component implements CrawlConstants
                         !in_array($group["MEMBER_ACCESS"], $read_comment) &&
                         $user_id != C\ROOT_ID)) {
                         return $parent->redirectWithMessage(
-                            tl('social_component_no_post_access'));
+                            tl('social_component_no_post_access'),
+                            ['page_name']);
                     }
                     if ($parent_id >= 0) {
                         $parent_item = $group_model->getGroupItem($parent_id);
                         if (!$parent_item) {
                             return $parent->redirectWithMessage(
-                                tl('social_component_no_post_access'));
+                                tl('social_component_no_post_access'),
+                                ['page_name']);
                         }
                     } else {
                         $parent_item = [
@@ -1400,7 +1411,7 @@ class SocialComponent extends Component implements CrawlConstants
                     $this->addAnyBotResponses($parent_item["ID"], $group_id,
                         $bots_called, $title, $post_parts);
                     return $parent->redirectWithMessage(
-                        tl('social_component_comment_added'));
+                        tl('social_component_comment_added'), ['page_name']);
                     break;
                 case "addgroup":
                     $register =
@@ -1433,9 +1444,14 @@ class SocialComponent extends Component implements CrawlConstants
                     }
                     break;
                 case "deletepost":
+                    if (!empty($_REQUEST['page_type']) &&
+                        $_REQUEST['page_type'] == "page_and_feedback") {
+                        $_REQUEST['a'] = "wiki";
+                    }
                     if (!isset($_REQUEST['post_id'])) {
                         return $parent->redirectWithMessage(
-                            tl('social_component_delete_error'));
+                            tl('social_component_delete_error'),
+                            ['page_name']);
                         break;
                     }
                     $post_id = $parent->clean($_REQUEST['post_id'], "int");
@@ -1450,7 +1466,8 @@ class SocialComponent extends Component implements CrawlConstants
                         $user_id, -1);
                     if (!empty($_REQUEST['page_type']) &&
                          $_REQUEST['page_type'] == "page_and_feedback") {
-                        $_REQUEST['a'] = "wiki";
+                         unset($_REQUEST['just_thread']);
+                         $_REQUEST['group_id'] = $group_item['GROUP_ID'];
                     }
                     if ($success) {
                         $group_model->deleteResources($group_item["GROUP_ID"],
@@ -1459,10 +1476,12 @@ class SocialComponent extends Component implements CrawlConstants
                             unset($_REQUEST['just_thread']);
                         }
                         return $parent->redirectWithMessage(
-                            tl('social_component_item_deleted'));
+                            tl('social_component_item_deleted'),
+                            ['page_name']);
                     } else {
                         return $parent->redirectWithMessage(
-                            tl('social_component_no_item_deleted'));
+                            tl('social_component_no_item_deleted'),
+                            ['page_name']);
                     }
                     break;
                 case "downvote":
@@ -1576,19 +1595,28 @@ class SocialComponent extends Component implements CrawlConstants
                         $_REQUEST['feed_time'], "int");
                     break;
                 case "updatepost":
+                    if (!empty($_REQUEST['page_type']) &&
+                         $_REQUEST['page_type'] == "page_and_feedback") {
+                         $_REQUEST['a'] = "wiki";
+                         unset($_REQUEST['limit']);
+                         unset($_REQUEST['num']);
+                    }
                     if (!isset($_REQUEST['post_id'])) {
                         return $parent->redirectWithMessage(
-                            tl('social_component_comment_error'));
+                            tl('social_component_comment_error'),
+                            ['page_name']);
                     }
                     if (!$description || !$title) {
                         return $parent->redirectWithMessage(
-                            tl('social_component_need_title_description'));
+                            tl('social_component_need_title_description'),
+                            ['page_name']);
                     }
-                    $post_id =$parent->clean($_REQUEST['post_id'], "int");
+                    $post_id = $parent->clean($_REQUEST['post_id'], "int");
                     $action = "updatepost" . $post_id;
                     if (!$parent->checkCSRFTime(C\CSRF_TOKEN, $action)) {
                         return $parent->redirectWithMessage(
-                            tl('social_component_post_edited_elsewhere'));
+                            tl('social_component_post_edited_elsewhere'),
+                            ['page_name']);
                     }
                     $items = $group_model->getGroupItems(0, 1,
                         [["post_id", "=", $post_id, ""]], $user_id);
@@ -1596,20 +1624,30 @@ class SocialComponent extends Component implements CrawlConstants
                         $item = $items[0];
                     } else {
                         return $parent->redirectWithMessage(
-                            tl('social_component_no_update_access'));
+                            tl('social_component_no_update_access'),
+                            ['page_name']);
                     }
                     $group_id = $item['GROUP_ID'];
+                    $_REQUEST['group_id'] = $group_id;
                     $group = $group_model->getGroupById($group_id, $user_id,
                         true);
                     $update_thread = [C\GROUP_READ_WRITE, C\GROUP_READ_WIKI];
                     if ($post_id != $item['PARENT_ID'] && $post_id > 0) {
                         $update_thread[] = C\GROUP_READ_COMMENT;
+                        $parent_items = $group_model->getGroupItems(0, 1,
+                            [["post_id", "=", $item['PARENT_ID'], ""]],
+                            $user_id);
+                        if (!empty($parent_items[0])) {
+                            $parent_item = $parent_items[0];
+                            $title = "-- " . $parent_item['TITLE'];
+                        }
                     }
                     if (!$group || ($group["OWNER_ID"] != $user_id &&
                         !in_array($group["MEMBER_ACCESS"], $update_thread) &&
                         $user_id != ROOT_ID)) {
                         return $parent->redirectWithMessage(
-                            tl('social_component_no_update_access'));
+                            tl('social_component_no_update_access'),
+                            ['page_name']);
                         break;
                     }
                     $group_model->updateGroupItem($post_id, $title,
@@ -1618,10 +1656,12 @@ class SocialComponent extends Component implements CrawlConstants
                         $group_id, "post" . $post_id);
                     if ($result == self::UPLOAD_FAILED) {
                         return $parent->redirectWithMessage(
-                            tl('social_component_upload_error'));
+                            tl('social_component_upload_error'),
+                            ['page_name']);
                     }
                     return $parent->redirectWithMessage(
-                        tl('social_component_post_updated'));
+                        tl('social_component_post_updated'),
+                        ['page_name']);
                     break;
                 case "upvote":
                     if (!isset($_REQUEST['group_id']) || !$_REQUEST['group_id']
@@ -2083,8 +2123,11 @@ class SocialComponent extends Component implements CrawlConstants
             $for_group);
         $updatable = false;
         if (!empty($data["JUST_THREAD"]) && $data["JUST_THREAD"] >= 0) {
-            if ($_SESSION['DISPLAY_MESSAGE'] ?? "" ==
-                tl('social_component_comment_added')) {
+            $display_message = $_SESSION['DISPLAY_MESSAGE'] ?? "";
+            $is_wiki = !empty($data["HEAD"]['page_type']) &&
+                $data["HEAD"]['page_type'] == 'page_and_feedback';
+            if (!$is_wiki &&
+                $display_message == tl('social_component_comment_added')) {
                 $limit = floor($item_count / $results_per_page) *
                     $results_per_page;
             }
@@ -2132,7 +2175,7 @@ class SocialComponent extends Component implements CrawlConstants
             for ($i = 0; $i < $num_matches; $i++) {
                 $match = preg_quote($matches[0][$i], "@");
                 $match = str_replace("@","\@", $match);
-                $replace = "<a href='?c=admin&amp;a=mixCrawls".
+                $replace = "<a href='?c=admin&amp;a=mixCrawls" .
                     "&amp;arg=importmix&amp;".C\CSRF_TOKEN."=".
                     $parent->generateCSRFToken($user_id).
                     "&amp;timestamp={$matches[2][$i]}'>".
@@ -3079,12 +3122,16 @@ EOD;
             $data['LIMIT'] = $limit;
             $data['RESULTS_PER_PAGE'] = $results_per_page;
             $data['PAGES'] = $pages;
-            $data[C\CSRF_TOKEN] =
-                $parent->generateCSRFToken($user_id);
+            $data[C\CSRF_TOKEN] = $parent->generateCSRFToken($user_id);
             $data['PAGING_QUERY'] = htmlentities(B\wikiUrl($data['PAGE_NAME'],
                 true, $data['CONTROLLER'], $group_id)) .
                 C\CSRF_TOKEN . '='. $data[C\CSRF_TOKEN] .
                 "&amp;page_type=page_and_feedback";
+            $data['WIKI_FEED_BASE'] = C\BASE_URL . "?c=". $data['CONTROLLER'] .
+                "&amp;a=groupFeeds&amp;just_thread=".$data['DISCUSS_THREAD'] .
+                "&amp;". C\CSRF_TOKEN . '='. $data[C\CSRF_TOKEN] .
+                "&amp;page_type=page_and_feedback&amp;page_name=" .
+                $data['PAGE_NAME'];
             if ($data['VIEW'] != 'api') {
                 $data['SCRIPT'] .= " let nextPage = initNextResultsPage(" .
                     "$limit, {$data['TOTAL_ROWS']}, $results_per_page, ".
diff --git a/src/views/elements/GroupfeedElement.php b/src/views/elements/GroupfeedElement.php
index ff65d1afe..70905f440 100644
--- a/src/views/elements/GroupfeedElement.php
+++ b/src/views/elements/GroupfeedElement.php
@@ -89,12 +89,14 @@ class GroupfeedElement extends Element implements CrawlConstants
         if (isset($data['MODE']) && $data['MODE'] == 'grouped') {
             $this->renderGroupedView($paging_query, $data);
         } else {
+            $data['MODE'] = "ungrouped";
             $this->renderUngroupedView($logged_in, $base_query,
                 $paging_query, $data);
         }
-        if (!$is_api && !$is_status) {?>
+        if (!$is_api && !$is_status) {
+            $thread_type = intval($data['JUST_THREAD'] ?? 0); ?>
             </div><?php
-            $this->renderScripts($data, ($data['JUST_THREAD'] ?? 0) > 0);
+            $this->renderScripts($data);
         }
     }
     /**
@@ -194,6 +196,7 @@ class GroupfeedElement extends Element implements CrawlConstants
             if ($is_group && in_array($member_access, $start_thread)) {
                 $this->drawStartThreadForm($data['JUST_GROUP_ID'], $data);
             } else if ($is_page_with_comments) {
+                $data['page_type'] = 'page_and_feedback';
                 $this->drawCommentForm($parent_id, $group_id, $data);
             }
         }
@@ -206,13 +209,13 @@ class GroupfeedElement extends Element implements CrawlConstants
             <div class="button-group-result red medium-font" ><?=
                 tl('groupfeed_element_no_posts_yet') ?></div>
             <?php
-            if ($is_thread) {
+            if ($is_thread && !$is_page_with_comments) {
                 $this->drawCommentForm($parent_id, $group_id, $data);
             }
         }
         if (!$is_api && !$is_status) {?>
             <div id='results-container' data-time="<?=time() ?>"><?php
-            if ($data['LIMIT'] > 0) {
+            if ($data['LIMIT'] > 0 && !$is_page_with_comments) {
                 $this->view->helper("pagination")->singleButtonPagination(
                     $paging_query, $data['LIMIT'], $data['RESULTS_PER_PAGE'],
                     $data['TOTAL_ROWS'], false, $logged_in, true);
@@ -314,9 +317,11 @@ class GroupfeedElement extends Element implements CrawlConstants
                         </script><?php
                     }
                 }
+                $delete_url = (empty($data['WIKI_FEED_BASE'])) ?
+                    $paging_query : $data['WIKI_FEED_BASE'];
                 ?>
-                [<a href="<?=$paging_query.'&amp;arg=deletepost&amp;'.
-                    "post_id=".$page['ID'] ?>" title="<?=
+                [<a href="<?= $delete_url .'&amp;arg=deletepost&amp;'.
+                    "post_id=" . $page['ID'] ?>" title="<?=
                     tl('groupfeed_element_delete') ?>">X</a>]
                 </div><?php
             }
@@ -452,7 +457,7 @@ class GroupfeedElement extends Element implements CrawlConstants
     private function drawStartThreadForm($group_id, $data)
     {
         $just_fields = ["LIMIT" => "limit", "RESULTS_PER_PAGE" => "num",
-            "JUST_GROUP_ID" => "just_group_id"];
+            "JUST_GROUP_ID" => "just_group_id", 'MODE' => 'v'];
         $hidden_form = "\n";
         foreach ($just_fields as $field => $form_field) {
             if (isset($data[$field])) {
@@ -541,7 +546,9 @@ class GroupfeedElement extends Element implements CrawlConstants
     private function drawCommentForm($thread_id, $group_id, $data)
     {
         $just_fields = ["LIMIT" => "limit", "RESULTS_PER_PAGE" => "num",
-            "JUST_THREAD" => 'just_thread'];
+            "JUST_THREAD" => 'just_thread', 'page_type' => 'page_type',
+            "PAGE_NAME" => 'page_name', 'MODE' => 'v'
+        ];
         $hidden_form = "\n";
         foreach ($just_fields as $field => $form_field) {
             if (isset($data[$field])) {
@@ -710,7 +717,8 @@ class GroupfeedElement extends Element implements CrawlConstants
         }
         $just_fields = ["LIMIT" => "limit", "RESULTS_PER_PAGE" => "num",
             "JUST_THREAD" => 'just_thread', "JUST_USER_ID" => "just_user_id",
-            "JUST_GROUP_ID" => "just_group_id"];
+            "JUST_GROUP_ID" => "just_group_id", 'page_type' => 'page_type',
+            "PAGE_NAME" => 'page_name', 'MODE' => 'v'];
         $hidden_form = "\n";
         foreach ($just_fields as $field => $form_field) {
             if (isset($data[$field])) {
@@ -729,7 +737,9 @@ class GroupfeedElement extends Element implements CrawlConstants
             $drag_above_text = tl('groupfeed_element_drag_textarea');
             $click_link_text = tl('groupfeed_element_click_textarea');
         ?>
-        let feed_update_id = null;
+        if (typeof feed_update_id === 'undefined') {
+            let feed_update_id = null;
+        }
         function commentForm(id, parent_id, group_id)
         {
             tmp = '<div class="post<?= $clear ?>"></div>';
@@ -737,7 +747,8 @@ class GroupfeedElement extends Element implements CrawlConstants
             if (start_elt != tmp) {
                 elt(id).innerHTML =
                     tmp +
-                    '<form method="post" >' + <?= $hidden_form ?>
+                    '<form method="post" action="<?=C\SHORT_BASE_URL?>">' +
+                    <?= $hidden_form ?>
                     '<input type="hidden" name="c" value="<?=
                         $data['CONTROLLER'] ?>" />' +
                     '<input type="hidden" name="a" value="groupFeeds" />' +
@@ -779,11 +790,18 @@ class GroupfeedElement extends Element implements CrawlConstants
         }
         function updatePostForm(id)
         {
-            clearInterval(feed_update_id);
+            if (typeof feed_update_id !== 'undefined' && feed_update_id) {
+                clearInterval(feed_update_id);
+            }
             let title_elt = elt('title' + id);
             let title = null;
+            let title_disabled = "";
+
             if (title_elt) {
                 title = elt('title' + id).innerHTML;
+                if (title.substr(0, 2) == "--") {
+                    title_disabled = "disabled='disabled'";
+                }
             }
             let description = elt('old-description'+id).innerHTML;
             let tmp = '<div class="post<?= $clear ?>"></div>';
@@ -791,7 +809,8 @@ class GroupfeedElement extends Element implements CrawlConstants
             if (start_elt != tmp) {
                 setDisplay('result-' + id, false);
                 tmp +=
-                    '<form method="post" >' + <?= $hidden_form ?>
+                    '<form method="post"  action="<?=C\SHORT_BASE_URL?>">' +
+                    <?= $hidden_form ?>
                     '<input type="hidden" name="c" value="<?=
                         $data['CONTROLLER'] ?>" />' +
                     '<input type="hidden" name="a" value="groupFeeds" />' +
@@ -809,7 +828,7 @@ class GroupfeedElement extends Element implements CrawlConstants
                         ?></label></b></p>' +
                         '<p <?= $hide_title
                         ?>><input type="text" name="title" value="'+title+'" '+
-                        ' maxlength="<?= C\TITLE_LEN
+                        ' ' + title_disabled + ' maxlength="<?= C\TITLE_LEN
                         ?>" class="wide-field"/></p>';
                     } else {
                         let hidden_title = elt('hidden-title' + id);
@@ -894,6 +913,10 @@ class GroupfeedElement extends Element implements CrawlConstants
                     feed_update_time * sec);
                 setTimeout("clearUpdate()", 20 * minute + sec);
             }<?php
+        } else {?>
+            function doUpdate()
+            {
+            }<?php
         }?>
         </script>
         <?php
ViewGit