View Single Post
  #1  
Old 10-13-2004, 01:56 PM
  minorgod's Avatar 
minorgod minorgod is offline
 

X-Adept
  
Join Date: Sep 2002
Location: Arivaca, AZ
Posts: 402
 

Default Making the Skin Swap mod more temporary...

The CartLab skinswap mod is very useful for changing the look of your site by triggering the skin swap with a variable in your URL. However, since it uses a cookie, you have trouble with the swapped skin showing up the next time your users visit your web site, regardless of whether the skinswap variable is in your URL. Instead, it would be nice if the SkinSwap did not use cookies with specific expiration dates, but instead had cookies that expired whenever the user closes his browser window, so that the next time he visits the site he will see the default skin unless it's specifically swapped again via another variable in the URL. I tried several methods of messing with the cookie expiration times and then realized how much easier it would be to do this using sessions instead of cookies. All you have to do is take the Skin Swap version of your smarty.php file and make the following changes.
Replace this:
Code:
if($allow_skin_swap_mod=="Y") { if($HTTP_GET_VARS[$value_to_swap_with]) { if(!is_dir(BASEDIR.DIRECTORY_SEPARATOR.$skin_swap_repository.$HTTP_GET_VARS[$value_to_swap_with])) { $skinswap_found_dir = false; $skinswap = $default_skin; } if($skinswap_found_dir) { $skinswap = $HTTP_GET_VARS[$value_to_swap_with]; setcookie ("skinswap", "", time()-31536000); setcookie ("skinswap", $HTTP_GET_VARS[$value_to_swap_with], time()+60); } } elseif($HTTP_COOKIE_VARS["skinswap"] && !$HTTP_GET_VARS[$value_to_swap_with]) { $skinswap = $HTTP_COOKIE_VARS["skinswap"]; } elseif(!$HTTP_COOKIE_VARS["skinswap"] or !$HTTP_GET_VARS[$value_to_swap_with]) { $skinswap = $default_skin; } } else { $skinswap = $default_skin; }
with this:
Code:
if($allow_skin_swap_mod=="Y") { //here we start a session just to keep track of the skinswap info. //This uses standard PHP sessions in files and is later ignored by //x-cart's custom session handlers which will replace this session //with new data after this session is read. session_start(); if($_GET[$value_to_swap_with]) { if(!is_dir(BASEDIR.DIRECTORY_SEPARATOR.$skin_swap_repository.$_GET[$value_to_swap_with])) { $skinswap_found_dir = false; $skinswap = $default_skin; } if($skinswap_found_dir) { $skinswap = $_GET[$value_to_swap_with]; $_SESSION['skinswap']=$_GET[$value_to_swap_with]; } } elseif($_SESSION["skinswap"] && !$_GET[$value_to_swap_with]) { $skinswap = $_SESSION["skinswap"]; } elseif(!$_SESSION["skinswap"] or !$_GET[$value_to_swap_with]) { $skinswap = $default_skin; } } else { $skinswap = $default_skin; }

Since there's no expiration set for the session, it expires automagically when the browser window is closed or after the default PHP session expiration time, depending in which happens first. Notice that we're using basic PHP session handling here because we do not have access to the xcart sessions until later in the x-cart code since x-cart sessions are started way after the smarty.php file is included and we need access to sessions before that happens. That's why I've simply started a new session so we can use that skinswap data before the x-cart sessions overwrite the skinswap session data in memory. Oh, and I also replaced the crusty old $HTTP_GET_VARS syntax with shiny new $_GET superglobal syntax because I'm cool like that.
Enjoy.
__________________
www.brettbrewer.com
Getting back into x-cart dev after a long hiatus. Modded lots of x-carts from version 3.1.x to 4.1.x. Developer of ImageScaler mod, Pre-login per user coupon mod, Wordpress feed mod, DigitalSubscriptions mod, Phonetic bulk download keys addon for DownloadExpander mod, Serial Number Generator for ESD products, Custom CMS/LMS integrations, external products mod, and more.
Reply With Quote