Webmastersite.net
Register Log In

Using template variables in php not working

Comments on Using template variables in php not working

nelgin


Usergroup: Customer
Joined: Jul 17, 2003

Total Topics: 39
Total Comments: 100
nelgin
Using template variables in php not working
Posted Sep 30, 2012 - 9:09 PM:

<?php
$mybb_nav="{NAVIGATION}";
?>


This stops execution. I need to do this do this then encode the string to pass through to the iframe. Then I can parse this for the navigation to match MyBB.

According to the following page, I can mix template variables and php.

scripts.webmastersite.net/w...k.php?action=detail&id=311

Thanks,
Nigel
Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7867
Paul
Posted Oct 01, 2012 - 3:21 PM:

Any template variable you insert will be be replaced with the content of that variable before PHP execution (which of course is what you need for it to be useful), and {NAVIGATION} thus gets replaced by a bunch of HTML, and HTML contains quotes. Thus you have a bunch of mismatched quotes creating parse errors. So this isn't a bug, it's just how it goes when you try to quote quotes. Added a warning message to the knowledge base article.
nelgin


Usergroup: Customer
Joined: Jul 17, 2003

Total Topics: 39
Total Comments: 100
nelgin
Posted Oct 01, 2012 - 4:05 PM:

...except that I stuck it through urlencode beforehand.

Or maybe I didn't, because I'm guessing this wont work:

<iframe src="http://www.british-expats.com/wsnheader.php?nav=<?php echo urlencode({NAVIGATION}); ?> style="frameBorder: 0; width: 100%; height: 285px; border: 0; overflow: hidden;"></iframe>

That's maybe not exactly what I had, I tried a couple of things. How would you suggest I get the navigation links into the iframe so I can parse them to display properly?

Thanks,
Nigel
nelgin


Usergroup: Customer
Joined: Jul 17, 2003

Total Topics: 39
Total Comments: 100
nelgin
Posted Oct 01, 2012 - 4:32 PM:

I guess to answer my own question, I would need to escape either " or ' then pass it through urlencode...I'll give that a try once the admin bit is working. That's really a show stopper for me right now.
Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7867
Paul
Posted Oct 02, 2012 - 4:22 AM:

urlencode("{NAVIGATION}") logically translates to a bunch of mismatched quotes the same way as before, as does addslashes("{NAVIGATION}") or any other escape attempt you might make. Any attempt to quote "{NAVIGATION}" will have the same result. You might have better luck with single quotes, but there are likely to be times when an apostrophe is used in the navigation too and it'll break. So you really shouldn't use template variables for unknown text strings in PHP, just for numbers and things where you have a good idea of what characters they'll contain.

Since it's in the iframe {NAVIGATION} actually a mybb template variable and not a WSN template variable? The iframe is mybb.
nelgin


Usergroup: Customer
Joined: Jul 17, 2003

Total Topics: 39
Total Comments: 100
nelgin
Posted Oct 02, 2012 - 9:04 AM:

I added the following code into wrapper.tpl

<?php
$nav = urlencode('{NAVIGATION}');
?>


Which works on categories that have single quotes in them. When I look at how {NAVIGATION} is displayed it's showing the apostrophe is encoded...

You Know You've Been Living There Too Long When....

As long as you don't change that, then I'll be fine. That's how it is stored in the database, so I guess you're encoding apostrophes before writing them to the database to save confusion with SQL statements. I guess a bit of serendipity there.

Now I can do this with my iframe


<iframe target="me1" src="http://www.british-expats.com/wsnheader.php?nav=<?php echo $nav; ?>" style="frameBorder: 0; width: 100%; border: 0;"></iframe>


(I'm using target to make use of some iframe resizing javascript that I needed).

Now, once I pass the data to the wsnheader.php script I juse assign _GET['nav'] to a variable then I can parse away from there to suit. Since it is all encoded still, I can split out the different layers accordingly.

My php isn't very good so the parsing looks terrible and I'm missing a / at some point, but I'll get there eventually. If it was PERL I'd have done it yesterday lol.

Thanks again for your help and insight. I'm learning much through this project.

Regards
Nigel

Paul
developer

Usergroup: Administrator
Joined: Dec 20, 2001
Location: Diamond Springs, California

Total Topics: 61
Total Comments: 7867
Paul
Posted Oct 03, 2012 - 12:49 PM:

Ah yeah it'd use the HTML entity &#39;. Can't promise it'll always do that but it has since 2003 or so and I'm unlikely to rewrite it unless it causes a bug.
Search thread for
Download thread as
  • 0/5
  • 1
  • 2
  • 3
  • 4
  • 5



Sorry, you don't have permission to post posts. Log in, or register if you haven't yet.