Hi everyone I’ve developed a quick hack for a project. What it does is simple. It enables any user (guest) to change the site template.
Well, I know the usage of such an extesion is a little bit limited but it helps if you offer alternative templates/views for the entire site.
Ayways, I want to convert this hack into an extesion so that I can avoid pssible problems when installing future EE updates. I need a bit help. I can’t decide which hook to use. Maybe a plugin or a module is a better idea rather than an extension.. Anyhow, if you have any thoughts I need your input.
My current hack, although not necessary, makes use of $global_vars. In addition to that I use cookies to redirect the user to a correct template group.
Just for you to get a better idea about what I’m trying to do here is the hack.
The code is inserted right after this line in index.php:
require 'path'.$ext;The code checks the URI. If URI is empty it tries to read the cookie’s value. If no cookie is set it creates a new cookie with the default template group name as stated by user in path.php.
If a cookie is set, then the code redirects the user to its previously selected template group as stored in cookie.
If URI has the template group name then the code renews the cookie with the URI stated template group name.
/**
* ADDED BY BIBER LTD. AT 11.09.2009
*
* This hack is used to handle TEMPLATE SWITCHING
*/
if($uri == ''){
if(!isset($_COOKIE['current_tpl_group'])){
$global_vars['current_tpl_group'] = $global_vars['default_tpl_group'];
setcookie('current_tpl_group', $global_vars['default_tpl_group'], '', time() -1);
setcookie('current_tpl_group', $global_vars['default_tpl_group']);
}
else{
if($_COOKIE['current_tpl_group'] != $global_vars['default_tpl_group']){
$global_vars['current_tpl_group'] = $_COOKIE['current_tpl_group'];
header('Location: http://photographyforsoul.com/'.$_COOKIE['current_tpl_group']);
}
}
}
else{
$uri_parts = explode('/', $uri);
if($uri_parts[0] != ''){
$uri_tpl_group = $uri_parts[0];
$global_vars['current_tpl_group'] = $uri_tpl_group;
setcookie('current_tpl_group', '', time() -1);
setcookie('current_tpl_group', $uri_tpl_group);
}
}
/** **************************** */Well, that’s that. Some stuff are manual now, but if I can wrap this hack into an extension, module, or plugin I’ll try to make it all dynamic…
Cheers! Can Berkol
p.s. having annoying issues with my keyboard - sorry for typos.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.