My solution, which is somewhat tedious, is:
1. Put ssl in Extra1 of all the pages that need SSL.
2. Copy the plugin function.cms_selflink.php and make a new one called function.cms_selflink_ssl.php which has the following modification starting around line 78:
Code: Select all
# check if the page exists in the db
$manager =& $gCms->GetHierarchyManager();
$node =& $manager->sureGetNodeByAlias($page);
if (!isset($node)) return;
$content =& $node->GetContent();
if ($content !== FALSE)
{
$pageid = $content->Id();
$alias = $content->Alias();
$name = $content->Name(); //mbv - 21-06-2005
$url = $content->GetUrl();
$menu_text = $content->MenuText();
$titleattr = $content->TitleAttribute();
$ssl = $content->extra1(); // This line added by KENDO451
}
/* Mod by KENDO451 */
/* Mod by KGriffith */
$parts = explode( ':' , $url );
if ( ''!=$ssl )
{
$parts[0] = 'https';
}
else
{
$parts[0] = 'http';
}
$url = '';
foreach ($parts as $part)
{
$url.= $part;
}
3. Modify my menu calls to include the parameter loadprops=1
4. Add the following block of code to my menu templates right after {foreach from=$nodelist item=node}
Code: Select all
{* If extra 1 is set make the url https, else make it http *}
{if isset($node->extra1)}
{https url=$node->url assign='nodeurl'}
{else}
{http url=$node->url assign='nodeurl'}
{/if}
5. Create user defined tags {https} and {http} that change the url to fit the requirement for the menu.
6. Create a plugin function to check the URL and re-direct if it is not set to http or https.
Code: Select all
<?php
# {checkpageurl} should be in <head> of template to generate canonical tag
#
# use {checkpageurl redirect=true} for 301 redirect
#
function smarty_cms_function_checkpageurl($params, &$smarty)
{
global $gCms;
$redirect = false;
$stripExt = '';
$ignoreModSubPage = false;
$config = &$gCms->config;
if(isset($config["page_extension"]) && !empty($config["page_extension"])) {
$stripExt = $config["page_extension"];
}
$manager = &$gCms->GetHierarchyManager();
$thispage = $gCms->variables['content_id'];
$cgsimple = $smarty->get_template_vars('cgsimple');
$ssl = $cgsimple->get_page_content($thispage, 'extra1');
$trail = "";
#Check if user has specified a redirect to proper url, otherwise use default
if (isset($params['redirect'])) {
$redirect = $params['redirect'];
} else {
$redirect = false;
}
$endNode = &$manager->sureGetNodeById($thispage);
if (isset($endNode))
{
$content =& $endNode->getContent();
$contentURL = $content->getURL();
// Content url defaults to http. If extra 1 has been set, change $contentURL to https
// Do this by taking the url apart and putting it back together
if ("" != $ssl && "" != $contentURL) {
$urlparts = explode(":", $contentURL);
$contentURL = "https:";
foreach($urlparts as $key => $part) {
if ($key != 0) {
$contentURL .= $part;
}
}
}
$currentURL = curPageURL();
if ($contentURL != "") {
if($redirect && $contentURL != $currentURL && strpos($currentURL,$contentURL)===false) {
# 3rd check strpos - prevents redirect if parameters on url
// There is one last check we should do... let's strip the config-mandated extension
// from the URL and see if the current page is a sub-page that's module-generated (ex: glossary module definitions)
if(!empty($stripExt)) {
$cleanedURL = str_replace($stripExt, '', $contentURL).'/';
if(!empty($cleanedURL) && $cleanedURL != $currentURL && strpos($currentURL, $cleanedURL) !== false) {
// this page is likely a module generated page
$ignoreModSubPage = true;
}
}
if(!$ignoreModSubPage) {
# output header redirect
header('Location: '.$contentURL,TRUE,301);
}
// Check to see if current URL is https
elseif("" != $ssl && strpos("https",$currentURL)===false) {
$urlparts = explode(":",$currentURL);
$contentURL = "https:";
foreach($urlparts as $key => $part) {
if (0!=$key) {
$contentURL .= $part;
}
}
# output header redirect
header('Location: '.$contentURL,TRUE,301);
}
}
if(!$ignoreModSubPage) {
$trail = '<link rel="canonical" href="'.$contentURL.'" />';
}
}
}
return $trail;
}
function smarty_cms_help_function_checkpageurl() {
echo "Func to output current page URL and redirect if not correct (needs redirect=true parameter)";
}
function smarty_cms_about_function_checkpageurl() {
echo "Func to output current page URL and redirect if not correct (needs redirect=true parameter)";
}
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
?>
Thanks,
Ken