e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
321 stars 213 forks source link

[newforumposts] Clicking on a subject bring us to the first page #4246

Open ericc-dream opened 3 years ago

ericc-dream commented 3 years ago

Bug Description

The old "New Forum Post" plug-in is now integrated into the Forum plug-in. Sound logic, and with some small corrections, we can have more or less the same visual and functionalities However, there is one annoying problem When we click on one topic, and if this one have several pages, it bring us to the first page instead of the last one as it was the case with the previous version !!

How to Reproduce

set your site to display the "newforumposts" and configure it as "Main" (don't know if it's important, but this how mine is set) find a topic with more than 1 page click on this topic into the table, it open the first page ... obliging you to go down to the bottom of the page where the pages numbers are and go to the last one

Expected Behavior

just directly go to the last page of the topic

Linux master 4.15.0-117-generic #118-Ubuntu SMP Fri Sep 4 20:02:41 UTC 2020 x86_64 e107 Version 2.2.1

ericc-dream commented 3 years ago

I found a solution. It's certainly not perfect as I'm not confident with e107's code , but it works for me I created a new function in ~/e107_plugins/forum/shortcodes/batch/view_shortcodes.php, because I wasn't sure if the existing function sc_topic_url, wasn't used elsewhere :

        /* Generate an URL to send user to the last page of a topic */
        function sc_topic_url_last()
        {
            // retreive the number of replies for the topic/thread
            $rep = ($this->var['thread_total_replies']) ? $this->var['thread_total_replies'] : '0';
            // assume 10 messages per page and calculate the number of page which is also the number of the last one
            $nbpage = ceil($rep/10);
            // build the URL
            $url = e107::url('forum', 'topic', $this->var);
            $url .= "&p=".$nbpage;
            return $url;
        }

And then, in the template ~/e107_themes//templates/forum/newforumposts_menu_template.php, in variable $NEWFORUMPOSTS_MENU_TEMPLATE['main']['item'], I replaced {TOPIC_URL} by {TOPIC_URL_LAST}

What I'm missing is a way to retrieve the parameter "postspage" from the configuration of the forum plugin Can you help me with this, please ?

Is it good enough to be integrated in the plugin for the next release ? (I mean once corrected the value "posts per page")

ericc

Jimmi08 commented 2 years ago

@Moc I can't simulate this one. It is redirecting to the last page for me (default, minimal, main version tested)

2.3.1 version