Forums / Cotonti / Support / Co-template Question / bug ???

ez
#1 2012-05-06 20:56

Version : Genoa 0.6.22


I have on my website 2 languages, which I would like to select.
Inside my index.tpl is the following part.
 

                <!-- IF {PHP.usr.lang} == "en" -->
                    <h2>About My website</h2>
                    {PAGE_TEXT_ID_23}
                <!-- ENDIF -->
                <!-- IF {PHP.usr.lang} == "nl" -->
                    <h2>Over mijn website</h2>
                    {PAGE_TEXT_ID_22}                    
                <!-- ENDIF -->
 

Where it goes wrong is when i have two {PAGE_TEXT_ID_xx} in there....
Then the index times out...


The PAGETEXTBYIDN plugin does something like this:

It starts something like this:

$currenttpl = file_get_contents($mskin);
if (strpos($currenttpl, "{PAGE_TEXT_ID_")==true)// if tag exist on page
{
    unset($p_match);
    preg_match_all("#\{(PAGE_TEXT_ID_(\d*?))\}#", $currenttpl, $p_match);

 

It ends like this inside a loop that loops through all found tags:

        // Assign tag
        $t->assign($p_tag, $page_html);
 

My best guess:

I am guessing it goes wrong with the assign inside the Template...
I think because I use an conditional TAG based on language <!-- IF {PHP.usr.lang} == "en" -->
and the fact that this plugin uses file_get_contents($mskin) to get the tags.... (which do not care about IF THEN statements)

How do I fix this ??????????????

 

==- I say: Keep it EZ -==
GHengeveld
#2 2012-05-07 07:36

Several things are wrong with this code (pagetextbyidn.code.php). Try this code:

<?php
if (!defined('SED_CODE')){die('Wrong URL.'); }

$currenttpl = file_get_contents($mskin);
if (mb_strpos($currenttpl, "{PAGE_TEXT_ID_") !== false)// if tag exist on page
{
	$matches = array();
	preg_match_all("#{(?P<tag>PAGE_TEXT_ID_(?P<id>[0-9]+))}#", $currenttpl, $matches, PREG_SET_ORDER);
	foreach ($matches as $match){
		$p_tag = $match['tag'];
		$p_id = $match['id'];

etc...

Update: fixed the regex

This post was edited by GHengeveld (2012-05-07 22:21, 11 years ago)
ez
#3 2012-05-07 09:45

OK, i will check your code..

I never had trouble with this PAGETEXTBYIDN plugin... This is the first time it is giving me troubles...

Thanks for responding, and ill try that and post the results here..

==- I say: Keep it EZ -==
GHengeveld
#4 2012-05-07 11:32

Small mistake in the regex, the braces should be outside of the tag.

"#(?P<tag>{PAGE_TEXT_ID_(?P<id>[0-9]+)})#"

should be 

"#{(?P<tag>PAGE_TEXT_ID_(?P<id>[0-9]+))}#"

Your tpl IF block should work just fine.

ez
#5 2012-05-07 19:38

Thanks, this solution works fine..

I never would suspected the regex ..

Your fix should be standard in the download for this plugin :)

I was trying to thank you through the thanks plugin.... but am I doing something wrong ???? (i cannot thank you)

==- I say: Keep it EZ -==
Trustmaster
#6 2012-05-07 20:06

What browser do you use and is javascript enabled? Does it emit any error messages?

May the Source be with you!
ez
#7 2012-05-07 20:17

no console messages what so ever... and off course i have JS enabled.

i just go to... http://www.cotonti.com/thanks?user=68
and see nothing happening.. only a list off ppl

==- I say: Keep it EZ -==
Twiebie
#8 2012-05-07 20:24

http://www.cotonti.com/thanks?user=68 is a list of  "Thanks" a user has received.

You need to click on 'Thank You' above the post. Should have a link such as: http://www.cotonti.com/thanks?a=thank&ext=forums&item=34231

ez
#9 2012-05-07 20:25

DAMN... i am getting blind.... i think.... sorry about that

==- I say: Keep it EZ -==
Twiebie
#10 2012-05-07 20:30

:)

GHengeveld
#11 2012-05-07 22:18

Patched version of pagetextbyidn.code.php is here: https://gist.github.com/2630919

I posted a comment on the plugin page with a link to the patch.

Thanks for the thanks.

BTW, love it when code I didn't even try just works :)

ez
#12 2012-05-08 05:27

wink me too

==- I say: Keep it EZ -==