Change content of page from module
Posted: Tue Oct 24, 2006 10:15 pm
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:
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.
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;
}
}
}
}
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.