To enable this, I wrote the following PHP to a file referenced by the link on the front page and from the navigation menus throughout the web site.
Code: Select all
<?php
require_once( '../include.php' );
// The following script redirects to the most
// most recently created active review.
global $gCms;
$db = &$gCms->db;
$result = array();
$cms_db_prefix = cms_db_prefix();
$query = "SELECT " . $cms_db_prefix . "content.* " .
"FROM " . $cms_db_prefix . "content, " .
$cms_db_prefix . "templates " .
"WHERE " . $cms_db_prefix . "content.type = 'content' " .
"AND " . $cms_db_prefix . "content.active = 1 " .
"AND " . $cms_db_prefix . "content.template_id = " .
$cms_db_prefix . "templates.template_id ".
"AND " . $cms_db_prefix . "templates.template_name = 'Review' " .
"ORDER BY create_date DESC LIMIT 1";
$dbresult = $db->Execute( $query );
$location = 'Location: http://' . $_SERVER[ 'HTTP_HOST' ];
if ( $dbresult && $dbresult->RecordCount() > 0 )
{
$newest_review_alias = '';
while ( $row = $dbresult->FetchRow() )
{
$newest_review_alias = $row[ 'content_alias' ];
$location .= rtrim( dirname( $_SERVER[ 'PHP_SELF' ] ), '/\\' ) .
'/' .
$newest_review_alias .
'/';
}
}
else
{
// Punt back to the home page if the
// review has disappeared.
$location .= '/';
}
header( $location );
?>
To use the CMSMS menu system to manage site naviagtion, I added a "Link" content item using the "Add New Content" function in the admin panel specifying the relative URL to the PHP file.
While this is working well, is there some other method that should be used for adding dynamic pages like this to CMSMS? I suppose that simple helper functions should be added as "User Defined Tags", but it does not seem that the PHP above should be in a user defined tag that is then referenced from a "Content" page in CMSMS. On the other hand, that appears to be the way to have the code stored in the database and managed by CMSMS rather that simply uploaded to the web server document tree file system. Any comments or suggestions?
This implementation is derived from latest articles plugin.