Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Php
Maybe chs_cookie can help achieve what you’re trying to do with out PHP. It looks like there is a thread about doing something similar.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Php
Here is the code:
<txp:php>
$warned = isset($_COOKIE['warned']) ? $_COOKIE['warned'] : $_GET['warned'];
if(strpos($_SERVER["HTTP_USER_AGENT"], "WebKit") && $warned != 'true'){
echo <<<BLOCK_ONE
<html>
<head>
<title></title>
</head>
<body>
This site is not fully compatible with Internet Explorer! But, if you want to <a href="">go in anyway</a>, be our guest.
</body>
</html>
BLOCK_ONE;
}else{
if(!isset($_COOKIE['warned'])){
setcookie('warned', 'true');
}
echo <<<BLOCK_TWO
<txp:output_form form="html_head" />
<txp:output_form form="header" />
<div id="container">
<div id="teaser">
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("/media/swf/index.swf", "Index", "980", "450", "9", "101010");
so.addVariable("flashVarText", "this is passed in via FlashVars for example only");
so.addParam("menu", "false");
so.addParam("scale", "noscale");
so.write("teaser");
// ]]>
</script>
</div>
<div id="body">
<div id="index">
<div class="box">
<div class="box-inside">
<h3>Latest <span>Articles</span></h3>
<h4>from the weblog</h4>
<a title="RSS Feed" href="http://simplecandy.com/rss/?section=weblog" id="feed"></a>
<ul class="newslink">
<txp:article_custom section="weblog" limit="3" form="articlelist" />
</ul>
</div><!--//box-inside-->
</div><!--//box-->
<div class="box">
<div class="box-inside">
</div><!--//box-inside-->
</div><!--//box-->
<div class="box lastchild">
<div class="box-inside">
<h3>About <span>( SC )</span></h3>
<h4>Learn About The Company</h4>
<p style="text-align:justify;margin:0;">Hello there! We build <a href="http://www.panic.com/coda/">hand-coded</a>, <a href="http://www.webstandards.org/">standards-based</a> websites. We really love working with Textpattern. Feel free to take a look around. Have a nice day. x</p>
</div><!--//box-inside-->
</div><!--//box-->
</div><!--//index-->
</div><!--//body-->
<txp:output_form form="footer" />
BLOCK_TWO;
}
</txp:php>
It is still not working though! I really don’t like the fact I’m having to do this, why can’t I use blocks of PHP? Why can’t Textpattern work with it? It’s PHP based :S
It actually just breaks my site: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/driz/public_html/admin/publish/taghandlers.php(2804) : eval()’d code on line 15
Last edited by driz (2008-12-01 22:31:34)
~ Cameron
Offline
Re: Php
The closing BLOCK_ONE; should be left-aligned or it’ll never get out of the first echo statement.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#19 2008-12-01 22:37:46
- Neko
- Member

- Registered: 2004-03-18
- Posts: 458
Re: Php
driz wrote:
It is still not working though! I really don’t like the fact I’m having to do this, why can’t I use blocks of PHP? Why can’t Textpattern work with it? It’s PHP based :S
Well, you can use raw PHP without the proper TXP tags. Just enable it in Advanced Preferences
It actually just breaks my site: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/driz/public_html/admin/publish/taghandlers.php(2804) : eval()’d code on line 15
Maybe you forgot to type a few ; after your echos?
Last edited by Neko (2008-12-01 22:37:57)
Offline
Re: Php
Okies finally cracked it and it works perfect, although it gets ugly backend!
I didn’t want to use JS because its front-end, I want most of my stuff to happen back-end so people can’t see it!
I like the sound of this plugin though, but I can’t make much sense of it, how exactly would I be able to achieve what I have done here using that plugin? Thanks. x
~ Cameron
Offline
Re: Php
You can do this using chs_cookie and smd_if
<txp:chs_set_cookie cookie="simplecandy_warned" value="warned" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<body>
<txp:smd_if field="svrvar:HTTP_USER_AGENT"
operator="contains"
value="WebKit">
This is a good browser
<txp:else/>
<txp:chs_cookie_default cookie="simplecandy_warned" value="warned">
Warning Message
<li><form action="<txp:permlink />" method="get" accept-charset="utf-8">
<input type="submit" value="Continue →" />
</form> </li></ul>
</txp:chs_cookie_default>
<txp:chs_if_cookie cookie="simplecandy_warned" value="warned">
Ok to see content.
</txp:chs_if_cookie>
</txp:smd_if>
</body>
</html>
Thrown together but could be tweaked to perfection
Last edited by MattD (2008-12-01 22:53:46)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Php
Seems to me it says if you have WebKit say they have browser, else show the form, and then see the content?
Would the user see the Good browser statement AND the content, or just the statement? Looks like three different blocks of content to me!!!
Basically why is the content before the else statement! We have ‘Good Browser’, The Form, and ‘Okay Content’
Thats three separate bits, wouldn’t it be just if no cookie show form, if cookie, show content? just two bits :S
Last edited by driz (2008-12-01 23:07:37)
~ Cameron
Offline
Re: Php
I think the content would have to be in the template twice.
<txp:chs_set_cookie cookie="simplecandy_warned" value="warned" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<body>
<txp:smd_if field="svrvar:HTTP_USER_AGENT"
operator="contains"
value="MSIE">
<!-- IE is being used. Display the warning -->
<txp:chs_cookie_default cookie="simplecandy_warned" value="warned">
Warning Message
<li><form action="<txp:permlink />" method="get" accept-charset="utf-8">
<input type="submit" value="Continue →" />
</form> </li></ul>
</txp:chs_cookie_default>
<txp:chs_if_cookie cookie="simplecandy_warned" value="warned">
<!-- IE is being used and warning has already been displayed -->
Ok to see content.
</txp:chs_if_cookie>
<txp:else/>
<!-- IE is not being used -->
Also Ok to see content.
</txp:smd_if>
</body>
</html>
EDIT: The best way around that would be to have your content in a seperate form so both content blocks could just have a <txp:form form="myContent"/> line
Last edited by MattD (2008-12-01 23:07:25)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Php
Ah, I think i missed the point, so you see the content if your with WebKit, if not see the warning, and then go to the content, the only issue is the duplicate content, I DONT want to put my content inside a form, because thats the whole site, and well thats messy!
Isn’t their someway to just say one or the other, so basically if no cookie show form, if cookie, show content? just two bits :S
~ Cameron
Offline
Re: Php
driz wrote:
Isn’t their someway to just say one or the other, so basically if no cookie show form, if cookie, show content? just two bits :S
That’s not what you want though right? You only want the cookie stuff if their using IE right? Maybe Stef will peek in and tell us if theres a better way but I’m not sure you can make it just one if statement with both conditions. I believe his plugin can do that but I don’t believe it deals with cookie variables.
What you need is a way to get to the cookie variable in smd_if then you could do…
<txp:smd_if field="svrvar:HTTP_USER_AGENT, cookievar:simplecandy_warned"
operator="contains, eq"
value="MSIE, warned">
But I don’t think that’s possible. If you could get the cookie value into a txp:variable then smd_if should have access to it but I’ve not used txp:variable enough to help there.
I think we need Stef’s input.
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Php
That’s correct I only want the cookie if they are using IE, but in my PHP I get only two parts, a warning and the content! Depending on which browser they are using they get one or the other, that’s the functionality I’m trying to replicate!
Also for the warning, I’m planning on using a txp form, because I want to use different code, to that of my default site, hence why in my PHP it had the html tags twice!!! I don’t know if this makes our problem easier or harder? :)
~ Cameron
Offline
Re: Php
MattD wrote:
Isn’t their someway to just say one or the other, so basically if no cookie show form, if cookie, show content? just two bits :S
Well, as Mattd says, you can use smd_if to do both tests at once if you’ve already set the cookie up beforehand. I haven’t employed cookies directly in smd_if (why?! *note to self: add this*) but you can do it in 4.0.7 with the shiny new parser:
<txp:smd_if field='svrvar:HTTP_USER_AGENT, <txp:chs_echo_cookie cookie="simplecandy_warned" />'
operator="contains, not"
value="MSIE, warned">
// This is IE and we have not accepted the warning, so show it
<txp:else />
// erm.... see below
</txp:smd_if>
but you still have the problem of what to do next. I think your layout implies tertiary logic — as MattD said — so you probably need another smd_if in the <txp:else /> to distinguish the two cases:
- if IE AND cookie set
- if any other browser
EDIT: hmmm, or maybe that does work as it is… because if the browser is NOT IE, it ignores the cookie regardless so you might get away with it if you can find a way of setting the cookie somewhere higher up the page. That might require a separate smd_if to check the browser and the status of the urlvar warned and set the cookie if they both match.
Last edited by Bloke (2008-12-01 23:46:08)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Php
So what’s the conclusion then? Does your idea work? You post felt more like a discussion with yourself about a theory rather than an actual solution :P
Thanks
~ Cameron
Offline
Re: Php
I hadn’t noticed chs_echo_cookie as the help text was garbled but I was just about to post a solution where for some reason I set a txp:variable using chs_echo_cookie and then checked that in smd_if. Of course that’s not needed.
This should work
<txp:chs_set_cookie cookie="simplecandy_warned" value="warned" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<body>
<txp:smd_if field='svrvar:HTTP_USER_AGENT, <txp:chs_echo_cookie cookie="simplecandy_warned" />'
operator="contains, not"
value="MSIE, warned">
Warning Message
<li><form action="<txp:permlink />" method="get" accept-charset="utf-8">
<input type="submit" value="Continue →" />
</form> </li></ul>
<txp:else/>
Ok to see content.
</txp:smd_if>
</body>
</html>
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Php
MattD wrote:
I hadn’t noticed chs_echo_cookie as the help text was garbled but I was just about to post a solution where for some reason I set a txp:variable using chs_echo_cookie and then checked that in smd_if. Of course that’s not needed.
This should work
<txp:chs_set_cookie cookie="simplecandy_warned" value="warned" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<body>
<txp:smd_if field='svrvar:HTTP_USER_AGENT, <txp:chs_echo_cookie cookie="simplecandy_warned" />'
operator="contains, not"
value="MSIE, warned">
Warning Message
<li><form action="<txp:permlink />" method="get" accept-charset="utf-8">
<input type="submit" value="Continue →" />
</form> </li></ul>
<txp:else/>
Ok to see content.
</txp:smd_if>
</body>
</html>
doesn’t work, outputs all the content and form
im testing it here: http://simplecandy.com/about/
see
~ Cameron
Offline