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

Fix urls for groupmenu, fix next autoplay link media, a=chris

Chris Pollett [2020-06-25 18:Jun:th]
Fix urls for groupmenu, fix next autoplay link media, a=chris
Filename
src/index.php
src/views/elements/GroupbarElement.php
src/views/elements/GroupfeedElement.php
src/views/elements/GroupmenuElement.php
src/views/elements/WikiElement.php
src/views/helpers/OptionsHelper.php
diff --git a/src/index.php b/src/index.php
index 09c2635c0..e74896d97 100644
--- a/src/index.php
+++ b/src/index.php
@@ -317,7 +317,8 @@ function configureRewrites($web_site)
     }
 }
 /**
- *
+ * @param array $route_args
+ * @return bool
  */
 function routeAppFile($route_args)
 {
@@ -497,7 +498,7 @@ function routeFeeds($route_args)
             }
         }
         $_REQUEST['a'] = (isset($_REQUEST['a']) &&
-            $_REQUEST['a'] == 'wiki') ? $_REQUEST['a'] : "groupFeeds";
+            $_REQUEST['a'] == 'wiki') ? 'wiki' : "groupFeeds";
         $_REQUEST['route']['c'] = true;
         $_REQUEST['route']['a'] = true;
         $end = ($route_args[0] == 'thread') ? "" : "_id";
diff --git a/src/views/elements/GroupbarElement.php b/src/views/elements/GroupbarElement.php
index b528dc587..33761811c 100644
--- a/src/views/elements/GroupbarElement.php
+++ b/src/views/elements/GroupbarElement.php
@@ -87,9 +87,9 @@ class GroupbarElement extends Element
                     $page_name = tl('groupbar_element_page_list');
                     $is_page_list = true;
                 }
-                $wiki_main_page_url = htmlentities(B\wikiUrl(
+                $wiki_main_page_url = rtrim(htmlentities(B\wikiUrl(
                     "Main", true, $data['CONTROLLER'],
-                    $data["GROUP"]["GROUP_ID"])) . $token_string;?>
+                    $data["GROUP"]["GROUP_ID"])) . $token_string, "?");?>
                 <a href="<?=$wiki_main_page_url; ?>"><?=
                 $data['GROUP']['GROUP_NAME']?></a>:<?php
             } else {?>
diff --git a/src/views/elements/GroupfeedElement.php b/src/views/elements/GroupfeedElement.php
index a49eaddf5..263ad0501 100644
--- a/src/views/elements/GroupfeedElement.php
+++ b/src/views/elements/GroupfeedElement.php
@@ -310,13 +310,13 @@ class GroupfeedElement extends Element implements CrawlConstants
             <img class="feed-user-icon" src="<?=$page['USER_ICON'] ?>"
                 alt="<?=tl('groupfeed_element_usericon') ?>"/><br />
             <a class="feed-user-link echo-link" <?= $no_follow ?>
-                href="<?= htmlentities(B\feedsUrl("user", $page['USER_ID'],
-                    true, $data['CONTROLLER'])) . $token_string;
+                href="<?= $this->formatHref(B\feedsUrl("user", $page['USER_ID'],
+                    true, $data['CONTROLLER']) . $token_string);
                 ?>" ><?=$page['USER_NAME'] ?></a>
             </div>
             <div class="feed-item-body">
-            <h2><a href="<?= htmlentities(B\feedsUrl('thread',
-                $page['PARENT_ID'], true, $data['CONTROLLER'])) . $token_string
+            <h2><a href="<?= $this->formatHref(B\feedsUrl('thread',
+                $page['PARENT_ID'], true, $data['CONTROLLER']) . $token_string)
                 ?>" <?= $no_follow ?> <?=$title_class ?>
                 id='title<?=$page['ID']?>' <?php
                 if ($open_in_tabs) { ?> target="_blank" rel="noopener"<?php }
@@ -349,9 +349,10 @@ class GroupfeedElement extends Element implements CrawlConstants
                 }
                 ?>.
                 <?= "<span class='gray'> - $pub_date</span>" ?>
-                <b><a class="gray-link" <?= $no_follow ?> href="<?=htmlentities(
+                <b><a class="gray-link" <?= $no_follow ?> href="<?=
+                    $this->formatHref(
                     B\feedsUrl('group', $page['GROUP_ID'], true,
-                    $data['CONTROLLER'])). $token_string ?>" ><?php
+                    $data['CONTROLLER']). $token_string) ?>" ><?php
                     e($page[self::SOURCE_NAME]."</a></b>");
             }
             if (!isset($data['JUST_GROUP_ID']) &&
@@ -423,9 +424,9 @@ class GroupfeedElement extends Element implements CrawlConstants
                 $recent_date = $this->view->helper("feeds"
                     )->getPubdateString($time, $page['RECENT_DATE']);
                 e("<b>".tl('groupfeed_element_last_post_info')."</b> ".
-                    $recent_date." - <a href='" . B\feedsUrl('user',
-                    $page['LAST_POSTER_ID'], true, $data['CONTROLLER'] ).
-                    $token_string . "'>".
+                    $recent_date." - <a href='" . $this->formatHref(
+                    B\feedsUrl('user', $page['LAST_POSTER_ID'],
+                    true, $data['CONTROLLER'] ) . $token_string) . "'>".
                     $page['LAST_POSTER'] . "</a>");?>
                 </div>
             <?php
@@ -453,6 +454,13 @@ class GroupfeedElement extends Element implements CrawlConstants
         } //end foreach
         return $page;
     }
+    /**
+     *
+     */
+    public function formatHref($url)
+    {
+        return rtrim(html_entity_decode($url), '?');
+    }
     /**
      * Used to render the dropdown for paths within the top group feed
      * drop down
@@ -497,7 +505,7 @@ class GroupfeedElement extends Element implements CrawlConstants
             $options = array_merge($options, $feed_array);
             if ($aux_url) {
                 $options[$aux_url] = tl('groupfeed_element_wiki_name',
-                        $group_name);
+                    $group_name);
             }
             $options[$groups_url] = tl('groupfeed_element_mygroups');
         }
diff --git a/src/views/elements/GroupmenuElement.php b/src/views/elements/GroupmenuElement.php
index c4588f943..2111411eb 100644
--- a/src/views/elements/GroupmenuElement.php
+++ b/src/views/elements/GroupmenuElement.php
@@ -110,9 +110,6 @@ class GroupmenuElement extends Element implements CrawlConstants
                 } else {
                     $full_human_page_name = $human_page_name;
                 }
-                $wiki_base_url = htmlentities(B\wikiUrl(
-                        $data['PAGE_NAME'], true, $data['CONTROLLER'],
-                        $data["GROUP"]["GROUP_ID"])) . $token_string;
                 $options = [ tl('groupmenu_element_page_places',
                     $full_human_page_name, $data['GROUP']['GROUP_NAME']) => ""];
                 if ($data["MODE"] != 'pages') {
@@ -148,10 +145,9 @@ class GroupmenuElement extends Element implements CrawlConstants
                     if (!empty($data['DISCUSS_THREAD'])) {
                         $modes[htmlentities(B\feedsUrl("thread",
                             $data['DISCUSS_THREAD'], true,
-                            "group")) .
-                            $token_string] =
-                                tl('groupmenu_element_page_discuss',
-                                $human_page_name);
+                            "group")) . $token_string] =
+                            tl('groupmenu_element_page_discuss',
+                            $human_page_name);
                     }
                 }
                 $modes["pages"] = tl('groupmenu_element_page_list',
@@ -166,28 +162,35 @@ class GroupmenuElement extends Element implements CrawlConstants
                     $append = "";
                     $page_name = ($name == 'pages') ?
                         'pages' : $data['PAGE_NAME'];
-                    $arg = '&amp;arg=' . $name ;
+                    $amp = (empty($token_string)) ? "" : "&amp;";
                     if (in_array($name, ['history', 'relationships'])) {
                         $page_id = (empty($data['PAGE_ID'])) ? "" :
                             $data['PAGE_ID'];
-                        $append .= "&amp;page_id=" . $page_id;
+                        $append .= "{$amp}arg=$name&amp;page_id=" . $page_id;
+                        $amp = "&amp;";
+                    }
+                    if (in_array($name, ['source', 'edit'])) {
+                        $append .= "{$amp}arg=$name";
+                        $amp = "&amp;";
                     }
                     if (!empty($data['SUB_PATH'])) {
-                        $append .= "&amp;sf=".urlencode($data['SUB_PATH']);
+                        $append .= "{$amp}sf=".urlencode($data['SUB_PATH']);
+                        $amp = "&amp;";
                     }
                     if (isset($_REQUEST['noredirect'])) {
-                        $append .= '&amp;noredirect=true';
+                        $append .= "{$amp}noredirect=true";
+                        $amp = "&amp;";
                     }
                     if (isset($data['OTHER_BACK_URL'])) {
                         $append .= $data['OTHER_BACK_URL'];
                     }
-                    if (substr($name, 0, 4) != "http") {
+                    if (strpos($name, C\SHORT_BASE_URL) === false) {
                         $url = htmlentities(B\wikiUrl(
                             $page_name, true, $data['CONTROLLER'],
                             $data["GROUP"]["GROUP_ID"])) . $token_string .
-                            $arg . $append;
+                            $append;
                     } else {
-                        $url = $name . $arg . $append;
+                        $url = $name . $append;
                     }
                     if ($data["MODE"] == $name) {
                         $selected_url = $url;
@@ -253,6 +256,7 @@ class GroupmenuElement extends Element implements CrawlConstants
                 $groupfeed_group_url = htmlentities(B\feedsUrl("group",
                     $data['JUST_GROUP_ID'], true, "group")).
                     $token_string;
+                $amp = (empty($token_string)) ? "" : "&amp;";
                 $groupwiki_url = htmlentities(B\wikiUrl("Main", true,
                     $data['CONTROLLER'], $data['JUST_GROUP_ID'])).
                     $token_string;
@@ -261,7 +265,7 @@ class GroupmenuElement extends Element implements CrawlConstants
                 $paths = [
                     $groupfeed_url => tl("groupmenu_element_groupfeed",
                         $data['SUBTITLE']),
-                    $groupfeed_group_url."&amp;f=rss" =>
+                    $groupfeed_group_url . "{$amp}f=rss" =>
                         tl("groupmenu_element_rss", $data['SUBTITLE'])];
                 $this->view->element('groupfeed')->renderPath($data, $paths,
                     $groupwiki_url, $group_base_query, $data['SUBTITLE']
@@ -274,12 +278,13 @@ class GroupmenuElement extends Element implements CrawlConstants
                     $userfeed_url = htmlentities(B\feedsUrl("user",
                         $data['JUST_USER_ID'], true, $data['CONTROLLER'])).
                         $token_string;
+                    $amp = (empty($token_string)) ? "" : "&amp;";
                     $group_base_all = B\feedsUrl("", "", true,
                         $data['CONTROLLER']) . $token_string;
                     $paths = [
                         $userfeed_url => tl("groupmenu_element_userfeed",
                             $viewed_user_name),
-                        $userfeed_url."&amp;f=rss" =>
+                        $userfeed_url."{$amp}f=rss" =>
                             tl("groupmenu_element_userrss",
                             $viewed_user_name)];
                     $this->view->element('groupfeed')->renderPath($data, $paths,
diff --git a/src/views/elements/WikiElement.php b/src/views/elements/WikiElement.php
index fec432a78..f786daa62 100644
--- a/src/views/elements/WikiElement.php
+++ b/src/views/elements/WikiElement.php
@@ -268,8 +268,12 @@ class WikiElement extends Element implements CrawlConstants
                             } else {
                                 elt('next-link').style.display = 'none';
                             }
-                            source.setAttribute('src', media_prefix +
-                                '&n=' + next_resources[current_resource_index]);
+                            let old_src = source.getAttribute('src');
+                            let old_resource =
+                                next_resources[current_resource_index - 1];
+                            source.setAttribute('src', old_src.replace(
+                                old_resource,
+                                next_resources[current_resource_index]));
                             page_path_elt = elt('media-path');
                             page_path_elt.options[
                                 page_path_elt.selectedIndex].text =
@@ -1135,8 +1139,10 @@ class WikiElement extends Element implements CrawlConstants
                 $add_options = [tl('wiki_element_recent_pages') => ""];
                 $found_new = false;
                 foreach ($data['RECENT_PAGES'] as $page_name => $url) {
-                    if (empty($options[$url . $token_string])) {
-                        $add_options[$url . $token_string] = $page_name;
+                    $out_token = (strstr($url, C\CSRF_TOKEN) === false) ?
+                        $token_string : "";
+                    if (empty($options[$url . $out_token])) {
+                        $add_options[$url . $out_token] = $page_name;
                         $found_new = true;
                     }
                 }
@@ -1149,8 +1155,10 @@ class WikiElement extends Element implements CrawlConstants
                 $add_options = [tl('wiki_element_recent_groups') => ""];
                 $found_new = false;
                 foreach ($data['RECENT_GROUPS'] as $group_name => $url) {
-                    if (empty($options[$url . $token_string])) {
-                        $add_options[$url . $token_string] =
+                    $out_token = (strstr($url, C\CSRF_TOKEN) === false) ?
+                        $token_string : "";
+                    if (empty($options[$url . $out_token])) {
+                        $add_options[$url . $out_token] =
                             $group_name . "@Main";
                         $found_new = true;
                     }
diff --git a/src/views/helpers/OptionsHelper.php b/src/views/helpers/OptionsHelper.php
index 112253bbb..b27069391 100755
--- a/src/views/helpers/OptionsHelper.php
+++ b/src/views/helpers/OptionsHelper.php
@@ -92,7 +92,7 @@ class OptionsHelper extends Helper
             ?>
             <option value="<?= $value ?>" <?php
                 if (trim($value) == ((is_string($selected)) ? trim($selected) :
-                    $selected)) {
+                    $selected)) {
                     e('selected="selected"');
                 }
                 if (mb_strlen($text) > $word_wrap_len + 3) {
@@ -143,8 +143,9 @@ class OptionsHelper extends Helper
                         e("<ul class='square-list'>");
                         $started = true;
                     }
-                    $out_url = (substr($url, 0,4) == 'http') ? $url :
-                        $url_prefix . $url;
+                    $out_url = (strpos($url, C\SHORT_BASE_URL) === false) ?
+                        $url_prefix . $url : $url;
+                    $out_url = rtrim($out_url, "?");
                     if ($url == $selected) {
                         e("<li><b><a href='$out_url'>$option</a></b></li>");
                     } else {
ViewGit