Change content of page from module

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
Christophe Lambrechts

Change content of page from module

Post by Christophe Lambrechts »

Hello devs,

I have a problem and I discussed it several times on IRC, but there is no solution. Let me explain the problem, its bit complicated even Ted has difficlties with it.

I'm working on MovedPage module. There is a handeling for the 301 and 410. It uses the 404 Custom error handeling of CMSMS core. Just place a module call on top of the template and there you go. It checks every time the page is vallid, if not there is send a header with 410 or 301 code. For 301 there is no problem because you are redirected. But for a 410 it puts some code on top of the page and changes te header, but as expected it doesn't look nice. http://www.bloemenstad.be//?loc=/home/a ... itnodiging I want to have it like a 404 error with the right header. The problem is how to change the {content}?

We have the following code for the moment:

Code: Select all

if (-1 == $gCms->variables['content_id'])
  {
    $nonexistant_page_uri = rawurldecode($_SERVER['REQUEST_URI']);
    // Strip first slash
    $nonexistant_page_uri = ltrim($nonexistant_page_uri, "/");
    
    // Check if the page has been permanently moved.
    // Also test to URL in DB that not start with a slash
    $query = 'SELECT * FROM '.cms_db_prefix().'module_movedpages WHERE old_uri = ? OR old_uri = ?';
    $dbresult = $db->Execute($query, array($nonexistant_page_uri, "/" . $nonexistant_page_uri));
    
    // If the URI is not in the list of permanently moved pages
    if ($dbresult->RecordCount() != 0)
    {
	$moved_page = $dbresult->FetchRow();
	switch ($moved_page['code']) {
	case 410:
	  {
	    // The page has been permanently deleted
	    header('HTTP/1.1 410 Gone');
	    
	    // Change content
	   $new_content = '<div class="error">'.$this->Lang('page_permanently_gone').'</div>';
	   $this->ContentPostRender($new_content);
	    
	    // echo '<div class="error">'.$this->Lang('page_permanently_gone').'</div>';
	    echo '<div>Nonexistant page uri = ' . $nonexistant_page_uri . '</div>'; 
	    // Log the 410 error to the database
	    
	    //exit();
	    break;
	  }
	case 301:
	  {
	    // Redirect the user to the new page URI
	    header('HTTP/1.1 301 Moved Permanently');
	    header('Location: '.$moved_page['new_uri']);
	    exit();
	    break;
	  }
	default:
	  {
	    echo $this->ShowErrors($lang['incorrect_code']);
	    break;
	  }
	}
      }
  }
Problem is that the ContentPostRender is not working the way I want. I need something like changeContent(). Ted told me that this the idea is of ContentPostRender, but I think that the 404 custom error is overwriting this because of the -1 page ID.

I hope the problem is clearly explained, if not: ask more information.

Greats Christophe

PS: I discussed also that there must come an event for pagenotfound, but the problem of changing the content still exist than in my opinion.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Change content of page from module

Post by calguy1000 »

if you've got it 1/2 working, and only need to change {content}, why not just change the page-id, and have some mechanism of identifying your custom 404 page.  A preference or something.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Christophe Lambrechts

Re: Change content of page from module

Post by Christophe Lambrechts »

How to change the pageID?
Locked

Return to “Modules/Add-Ons”