View Full Version : Plugin not parsing variables
Simon Lloyd
05-30-2011, 12:23 AM
Hi, i've created a plugin with the following code$template_hook[postbit_user_popup].='<if condition="in_array($post[usergroupid], array( 1,2,3,4,5,6,7,8,9,10,11,12,13,14))"> <if condition="is_member_of($vbulletin->userinfo, array( 5,6,7))">
<tr><td class="vbmenu_option"><a href="iptest.php?domain=$post[ip]">WhoisIP for $post[username]: $post[ip]</a></td></tr>
</if></if>';However the $username and $post[ip] stay exactly like that, they're not getting parsed?
I am using postbit_display_complete as the hook location (and i've tried others) so i don't understand why those aren't getting the data, if i code it by hand in the postbit template it works fine?
Any suggestions would be welcome.
A template hook has to be html, it doesn't get processed like a template. (I believe you would see the if tags unprocessed if you viewed the page source). And your vars didn't get processed because you have the string in single quotes.
So you could do this:
if (in_array($post[usergroupid], array( 1,2,3,4,5,6,7,8,9,10,11,12,13,14)) AND is_member_of($vbulletin->userinfo, array( 5,6,7)))
{
$template_hook[postbit_user_popup].= "<tr><td class=\"vbmenu_option\"><a href=\"iptest.php?domain=$post[ip]\">WhoisIP for $post[username]: $post[ip]</a></td></tr>";
}
assuming the values of $post are set at that point in the code.
Simon Lloyd
05-30-2011, 12:58 AM
Thanks for the code and the info, would the AND be correct? the first IF is which groups the item can be seen/used on the second gives the permission for who can see and use it.
EDIT:
Your code gives:
Parse error: syntax error, unexpected T_STRING in /home/thecodec/public_html/testforum/includes/class_postbit.php(294) : eval()'d code on line 3
Thanks for the code and the info, would the AND be correct? the first IF is which groups the item can be seen/used on the second gives the permission for who can see and use it.
You can change it back to the two ifs if you want, it amounts to the same thing if there's nothing else inside the outer if.
EDIT:
Your code gives:
Parse error: syntax error, unexpected T_STRING in /home/thecodec/public_html/testforum/includes/class_postbit.php(294) : eval()'d code on line 3
Oops - now I see why you had it in single quotes. I fixed the above code by adding backslashes to escape the double quotes. You could also do $str = 'part 1 ' . $post['userid'] . 'part 2, etc'; if you prefer that.
Simon Lloyd
05-30-2011, 02:01 AM
Err, wish i knew what you meant there!, using your amended code the item doesn't display in the postbit userinfo dropdown.
Thanks for your help here :)
--------------- Added 1306724900 at 1306724900 ---------------
This works but im sure i've lost control over it somewhere as i should be able to choose which usergroups it will be available for then which ones can actually use itif (in_array($post[usergroupid], array( 1,2,3,4,5,6,7,8,9,10,11,12,13,14)))
{
$template_hook[postbit_user_popup].= "<tr><td class='vbmenu_option'><a href='iptest.php?domain=$post[ip]'>WhoisIP for $post[username]: $post[ip]</a></td></tr>";
}
Err, wish i knew what you meant there!,
Just that there's more than one way to address that issue, but it doesn't matter.
..using your amended code the item doesn't display in the postbit userinfo dropdown.
It looks like $vbulletin is not defined at that hook location, so try changing it to $this->registry->userinfo in the is_member_of() call.
Simon Lloyd
05-30-2011, 02:30 AM
I tried thisif (in_array($post[usergroupid], array( 1,2,3,4,5,6,7,8,9,10,11,12,13,14)) AND $this->registry->userinfo in the is_member_of(5,6,7)))
{
$template_hook[postbit_user_popup].= "<tr><td class=\"vbmenu_option\"><a href=\"iptest.php?domain=$post[ip]\">WhoisIP for $post[username]: $post[ip]</a></td></tr>
</if></if>";
}but it's giving Eval errors, one other thing, do we need the two </if>'s?
--------------- Added 1306726547 at 1306726547 ---------------
Lol, it's 4:30am here and i wasn't reading it properly, this worksif (in_array($post[usergroupid], array( 1,2,3,4,5,6,7,8,9,10,11,12,13,14)) AND is_member_of($this->registry->userinfo, array( 5,6,7)))
{
$template_hook[postbit_user_popup].= "<tr><td class=\"vbmenu_option\"><a href=\"iptest.php?domain=$post[ip]\">WhoisIP for $post[username]: $post[ip]</a></td></tr>
</if></if>";
}thanks for your help :)
I tried this...
Sorry, i meant like this:
if (in_array($post[usergroupid], array( 1,2,3,4,5,6,7,8,9,10,11,12,13,14)) AND is_member_of($this->registry->userinfo, array(5,6,7)))
{
$template_hook[postbit_user_popup].= "<tr><td class=\"vbmenu_option\"><a href=\"iptest.php?domain=$post[ip]\">WhoisIP for $post[username]: $post[ip]</a></td></tr>";
}
... one other thing, do we need the two </if>'s?
Oh, good call - I missed those. You're right, you don't need them.
Simon Lloyd
05-30-2011, 02:50 AM
Brilliant thanks, i can now complete my very first product, so im going to update my vb3.8.x Add-on https://vborg.vbsupport.ru/showthread.php?t=264283 and make it easier for folk rather than template edits, i'll add that in the next 5 mins or so, fancy giving it a go for me?
I tried it and it works, nice job! However there's a slight problem with the xml file, something to do with the version check url on line 8. I just deleted that from the xml to test it, I'm sure it's something minor.
Simon Lloyd
05-30-2011, 03:16 AM
Can you explain please? as i don't know what you mean there.
--------------- Added 1306729501 at 1306729501 ---------------
Should be sorted now, i had 1.00 as the version in vb.org and 1.0.0 in the xml, can you give it another go?
When I import the product xml file I get an error that says:
XML Error: EntityRef: expecting ';' at Line 8
When I tried it the first time I just deleted that whole line.
Looking at another product file, I think your versioncheckurl should look like this:
<versioncheckurl><![CDATA[https://vborg.vbsupport.ru/misc.php?do=producthelp&pid=whoisip_002]]></versioncheckurl>
I think maybe it's the '&' char that's causing a problem without the CDATA tags. Maybe using &pid= in place of &pid= would also work.
Simon Lloyd
05-30-2011, 04:04 AM
You were right with the chkurl, thanks!, i do have a problem though, the xml and everything work fine on my test forum but importing to my live forum and it doesn't show, i suspect that the hook that i tag my code on to is already being replaced by another mod - would that sound feasible?
It's possible - you used ".=" to append to the template hook (as you should), but it could be that another mod just used "=". If you have any other mods that add to the dropdown, you could disable them to see if it makes a difference.
Simon Lloyd
05-30-2011, 04:18 AM
Hmmm, they don't add a dropdown but do add to it in the same place.
--------------- Added 1306733804 at 1306733804 ---------------
I'm going to do those tests later, i'm off home to bed shortly - thanks for the help again, i'll report back here on my findings tonight.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.