Smarties? UDT? /////on//CSS Style Switcher

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
JeremyBASS

Smarties? UDT? /////on//CSS Style Switcher

Post by JeremyBASS »

Hello, sorry i was being dumb and delete my post... so i'll start over.. I'm try to get a grab on the limits of UDT and tags... i am trying to write a simple CSS switcher... but it's not working and i'm stuck... am i allowed to use one UDT in another?

here is what i'm doing...
3 UDTs

styleswitcher_php

Code: Select all

// SET COOKIE FOR 1 YEAR
if(isset($_REQUEST["SETSTYLE"])){
 if(setcookie("testcookie",true)){
  setcookie("STYLE",$_REQUEST["SETSTYLE"],time()+31622400);
 }else{
  $_SESSION["STYLE"]=$_REQUEST["SETSTYLE"];
 }
}
// RETURN TO CALLER PAGE
header("Location: ".$_SERVER["HTTP_REFERER"]);
switch_Stylesheet_Links

Code: Select all

$smarty = &$gCms->GetSmarty();
$styleswitcher_php = "{styleswitcher_php}";
// WRITE OUT SWITCHER LINKS
while(list($key, $val) = each($styleSheets)){
 echo "<a href='".$styleswitcher_php."?SETSTYLE=".$key."' title='".$val["title"]."'>".$val["text"]."</a>";
}
stylearray

Code: Select all

$styleSheets = array();

// DEFINE STYLESHEETS
$styleSheets[0]["text"]='Style 1 Version';
$styleSheets[0]["title"]='Click here to set Style 1';
$styleSheets[0]["sheet"]='<link href="/TMPALT/1.css" rel="stylesheet" type="text/css" />';

$styleSheets[1]["text"]='Style 2 Version';
$styleSheets[1]["title"]='Click here to set Style 2';
$styleSheets[1]["sheet"]='<link href="/TMPALT/2.css" rel="stylesheet" type="text/css" />';

// DEFAULT STYLESHEET
$defaultStyleSheet=0;

// SET STYLESHEET
if(!isset($_COOKIE["STYLE"])){
 if(isset($_SESSION["STYLE"])){
  echo $styleSheets[$_SESSION["STYLE"]]["sheet"];
 }else{
  echo $styleSheets[$defaultStyleSheet]["sheet"];
 }
}else{
 echo $styleSheets[$_COOKIE["STYLE"]]["sheet"];
}
then in a content page i put

Code: Select all

{stylearray}
{switch_Stylesheet_Links}

<p>test text<p>
but all i got was
Fatal error: Call to a member function on a non-object in /home/content/j/e/r/jeremyleebass3/html/Resale/WebSales/lib/content.functions.php(669) : eval()'d code on line 1
???? am i not alowed to use a UDT in a UDT? thanks
alby

Re: Smarties? UDT? /////on//CSS Style Switcher

Post by alby »

JeremyBASS wrote: ???? am i not alowed to use a UDT in a UDT? thanks
Yes, but not so!
And I can say that if works (I do not believe that you can call header at this point, better redirect function) see an infinite reload

However, why not make a single UDT?
Maybe (UNTESTED and NO CHECK):

Code: Select all

$styleSheets = array();

// DEFINE STYLESHEETS
$styleSheets[0]["text"]='Style 1 Version';
$styleSheets[0]["title"]='Click here to set Style 1';
$styleSheets[0]["sheet"]='<link href="/TMPALT/1.css" rel="stylesheet" type="text/css" />';

$styleSheets[1]["text"]='Style 2 Version';
$styleSheets[1]["title"]='Click here to set Style 2';
$styleSheets[1]["sheet"]='<link href="/TMPALT/2.css" rel="stylesheet" type="text/css" />';

// DEFAULT STYLESHEET
$defaultStyleSheet=0;

// SET STYLESHEET
if(!isset($_COOKIE["STYLE"])){
 if(isset($_SESSION["STYLE"])){
  echo $styleSheets[$_SESSION["STYLE"]]["sheet"];
 }else{
  echo $styleSheets[$defaultStyleSheet]["sheet"];
 }
}else{
 echo $styleSheets[$_COOKIE["STYLE"]]["sheet"];
}

global $gCms;
$smarty =& $gCms->GetSmarty();
$page_alias = $smarty->get_template_vars('page_alias');

while(list($key, $val) = each($styleSheets)){
 echo "<a href='index.php?page=".$page_alias."&SETSTYLE=".$key."' title='".$val["title"]."'>".$val["text"]."</a>";
}

// SET COOKIE FOR 1 YEAR
if(isset($_REQUEST["SETSTYLE"])){
 if(setcookie("testcookie",true)){
  setcookie("STYLE",$_REQUEST["SETSTYLE"],time()+31622400);
 }else{
  $_SESSION["STYLE"]=$_REQUEST["SETSTYLE"];
 }
}
Alby
JeremyBASS

Re: Smarties? UDT? /////on//CSS Style Switcher

Post by JeremyBASS »

Rock on that works mostly... I think i'm understanding now... all most... but the when i click the links the css cbages at random... i truned off the catch and nothing happened.. so would that be what you were taking about on the header issues...  :) i'll work it out and post up what i get... thanks
JeremyBASS

Re: Smarties? UDT? /////on//CSS Style Switcher

Post by JeremyBASS »

ok so i'v been round and round... now it's time to ask... am i even one the right track...? i keep geting
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/content/j/e/r/jeremyleebass3/html/Resale/WebSales/admin/edituserplugin.php(102) : eval()'d code on line 30
i'm still a newbe at php so trying to mix the smarties and php is hitting me were it hurts lol...

any ideas...???

Code: Select all

// DEFINE STYLESHEETS
$styleSheets[0]["text"]='Style 1 Version';
$styleSheets[0]["title"]='Click here to set Style 1';
$styleSheets[0]["sheet"]='<link href="TMPALT/1.css" rel="stylesheet" type="text/css" />';

$styleSheets[1]["text"]='Style 2 Version';
$styleSheets[1]["title"]='Click here to set Style 2';
$styleSheets[1]["sheet"]='<link href="TMPALT/2.css" rel="stylesheet" type="text/css" />';

// DEFAULT STYLESHEET
$defaultStyleSheet=0;

// SET STYLESHEET
if(!isset($_COOKIE["STYLE"])){
 if(isset($_SESSION["STYLE"])){
  echo $styleSheets[$_SESSION["STYLE"]]["sheet"];
 }else{
  echo $styleSheets[$defaultStyleSheet]["sheet"];
 }
}else{
 echo $styleSheets[$_COOKIE["STYLE"]]["sheet"];
}

global $gCms;
$smarty =& $gCms->GetSmarty();
$page_alias = $smarty->get_template_vars('page_alias');

while(list($key, $val) = each($styleSheets)){
 echo "<a href='"."
$do_redirect('index.php?page=".$page_alias."&SETSTYLE=".$key','LOCATION');
"."' title='".$val["title"]."'>".$val["text"]."</a>";
}


// SET COOKIE FOR 1 YEAR
if(isset($_REQUEST["SETSTYLE"])){
 if(setcookie("testcookie",true)){
  setcookie("STYLE",$_REQUEST["SETSTYLE"],time()+31622400,"/");
 }else{
  $_SESSION["STYLE"]=$_REQUEST["SETSTYLE"];
 }
}
function do_redirect($url,$mode)
{
    if (strncmp('http:',$url,5) && strncmp('https:',$url,6)) {
        $starturl = ($_SERVER["HTTPS"] == 'on' ? 'https' : 'http') . '://'.
        (empty($_SERVER['HTTP_HOST'])? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST']);
        if ($url[0] != '/') $starturl .= dirname($_SERVER['PHP_SELF']).'/';
        $url = "$starturl$url";
    }
    switch($mode) {
        case 'LOCATION':
        header("Location: $url");
        exit;
        case 'REFRESH':
        header("Refresh: 0; URL="$url"");
        exit;
        case 'META':
        exit;
        default:
        ?><__script__ type="text/javascript">
        window.location.href='<?=$url?>';
        </__script><?
    }
    exit;
}
miss_d_bus
Forum Members
Forum Members
Posts: 121
Joined: Sun May 01, 2005 4:27 pm

Re: Smarties? UDT? /////on//CSS Style Switcher

Post by miss_d_bus »

Anyone got any further with this? It would be great to see this working.
JeremyBASS

Re: Smarties? UDT? /////on//CSS Style Switcher

Post by JeremyBASS »

Nope i didn't get any farther... things came up and this was just testing at this point... are you looking for a CSS switcher?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Smarties? UDT? /////on//CSS Style Switcher

Post by calguy1000 »

For stylesheet switching capabilities, have you checked out the Template Manager module?

It supports primary and alternate stylesheets, re-ordering stylesheets, and a primitive embedded switcher.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Locked

Return to “CMSMS Core”