This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

My URLs for the pages slightly changed, can Commentics register that update?
#1

On my site, the page's URL address is determined by its place in the available list of pages.

Recently, I've added a couple of pages at the beginning of the list, and it turns out it now kinda broke the URLs used for permalinks to the comments on these pages (both in the frontend interface and in things like e-mail notifications) - they still use old URLs, and following them gets you to a different page (Thankfully it didn't broke the comment threads themselves, since I used factual static ID of the page from the database as identifier). 
Looks like Commentics looks for the URL of the thread only once, when it creates it, correct?

I was wondering if it is possible to regenerate those URLs somehow? Or I'm stuck with the majority of my threads having wrong permalink URLs now?
Reply
#2

Yes if you open /system/library/page.php, after this:

Code:
$this->form_enabled = $page['is_form_enabled'];

Add this:

Code:
if (!$this->request->isAjax()) {
    $this->db->query("UPDATE `" . CMTX_DB_PREFIX . "pages` SET `url` = '" . $this->db->escape($this->url->getPageUrl()) . "' WHERE `id` = '" . (int) $page['id'] . "'");
}

Have you completed the interview?
Reply
#3

The reason it doesn't keep the URLs up-to-date is because it would make the URLs open to abuse.

For example someone could add arbitrary parameters to the URL (which everyone would see when receiving an email).

Have you completed the interview?
Reply
#4

(13-Mar-2025, 04:25 PM)Steven Wrote:  The reason it doesn't keep the URLs up-to-date is because it would make the URLs open to abuse.

For example someone could add arbitrary parameters to the URL (which everyone would see when receiving an email).

Ah, thanks! So, I make changes, visit each page, and then undo the changes back, yes?

...Hm, I think the fix for that URL abuse can be made by adding the same condition to that if statement that checks that I'm the admin? Then only Admins visiting would trigger an update of URL.
Reply
#5

Would this work?
Code:
                if (!$this->request->isAjax() && isset($this->session->data['cmtx_admin_id'])) {
                    $this->db->query("UPDATE `" . CMTX_DB_PREFIX . "pages` SET `url` = '" . $this->db->escape($this->url->getPageUrl()) . "' WHERE `id` = '" . (int) $page['id'] . "'");
                }
Reply
#6

The "edit reply" button is gone again... Dodgy

...So I was pulling my hairs as to why on some pages the edited section chose to blatantly ignore the $cmtx_url variable and write a wrong URL into the DB, until I noticed that $this->page_url gets owerwritten right before the edit in the OG code ($this->url->getPageUrl() didn't respect $cmtx_url either), for some reason, so I had to preserve the URL I want into a new variable.

This is the code I ended up with, if anybody's interested, and yeah, using the admin cookie works.:
Code:
            if ($page) {
                $this->id = $page['id'];
                $neededURL = $this->page_url;
                $this->page_url = $page['url'];
                $this->form_enabled = $page['is_form_enabled'];
                if (!$this->request->isAjax() && isset($this->session->data['cmtx_admin_id'])) {
                    $cleanURL = $this->db->escape($neededURL);
                    $this->db->query("UPDATE `" . CMTX_DB_PREFIX . "pages` SET `url` = '" . $cleanURL . "' WHERE `id` = '" . (int) $page['id'] . "'");
                }
            }
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by Steven
06-Aug-2021, 06:50 PM
Last Post by gongong
18-Feb-2017, 04:16 AM
Last Post by Steven
07-Jul-2015, 05:57 PM
Last Post by Steven
29-May-2015, 08:51 PM
Last Post by masonbarge
12-Jan-2014, 06:31 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)