PDA

View Full Version : Putting a variable in a hook


David Regimbal
05-25-2009, 01:20 PM
Hi everyone,

This is my first post, so I hope I'm asking this question in the right place.

Im trying to add a plugin with a variable $bbuserinfo[field#], I have been doing a lot of research and cant seem to get it to work :(

In the PHP Code for the plugin, the variable is attached to the end of a URL. Below would be an example of how it looks:

$file = "http://www.example.com/example.xml=$bbuserinfo[field#]";

Im also using the above to call data from an xml file, like this:

$xml = simplexml_load_file($file) or die ("Unable to load XML file!");

I have tried $vbulletin->bbuserinfo[field#], but that wont work either.

Can anyone help me?

EnIgMa1234
05-25-2009, 01:59 PM
Hi everyone,

This is my first post, so I hope I'm asking this question in the right place.

Im trying to add a plugin with a variable $bbuserinfo[field#], I have been doing a lot of research and cant seem to get it to work :(

In the PHP Code for the plugin, the variable is attached to the end of a URL. Below would be an example of how it looks:

$file = "http://www.example.com/example.xml=$bbuserinfo[field#]";

Im also using the above to call data from an xml file, like this:

$xml = simplexml_load_file($file) or die ("Unable to load XML file!");

I have tried $vbulletin->bbuserinfo[field#], but that wont work either.

Can anyone help me?
What are you trying to do?
Which hook are you using?
Also shouldn't the url have something like example.xml?do=".$bbuserinfo[fieldx];

David Regimbal
05-25-2009, 02:43 PM
Hi EnIgMa1234,

Im trying to gather information from an xml file. I created a custom hook called $template_hook[custom_1]. I placed that in a custom page called test.php which has the hook inside the php as well (So, that's all set up right, I think?). And for the url, I'm not sure, I only tried what I posted above :(

Below would be an example of what is inside the PHP Code:

// set name of XML file
$file = "http://example.com/example.ashx?GamerTag=$bbuserinfo[field#]";

// load file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");

// access XML data
echo "Example 2: " . $xml->PresenceInfo->Example2 . "<br />";
echo "Example:" . $xml->PresenceInfo->Example . "<br />";

Lynne
05-25-2009, 03:37 PM
$template_hooks are to be used in templates and thus you may only put html in them. If you have php, then you need to put it in your custom page and then assign the output to a variable which you spit out in a template. In your php page, don't use echo, use something like this:
$my_variable = "Example 2: " . $xml->PresenceInfo->Example2 . "<br />";And then put $my_variable in the template.

David Regimbal
05-25-2009, 04:23 PM
Hi Lynne,

I'm a little confused :(

I created a plugin and inserted this is the PHP Code box:

// set name of XML file
$file = "http://example.com/example.ashx?GamerTag=$bbuserinfo[field#]";

// load file
$xml = simplexml_load_file($file) or die ("Unable to load XML file!");

// access XML data
echo "Example 2: " . $xml->PresenceInfo->Example2 . "<br />";
echo "Example:" . $xml->PresenceInfo->Example . "<br />";

Then for the hook location I put the one I made "custom_1". Inside the test template I just have the hook and on the test.php I have:

($hook = vBulletinHook::fetch_hook('custom_1')) ? eval($hook) : false;

Below the require_once('./global.php');

So, the test.php file would look like this at the bottom:

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once('./includes/class_bbcode.php');

// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################

$navbits = array();
$navbits[$parent] = 'test';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('test') . '");');
($hook = vBulletinHook::fetch_hook('custom_1')) ? eval($hook) : false;

?>

Unless what you are saying is put the php I have in the php code box in the php file and then put the variable in the php code box and have the hook in the php file? (Sorry if it sounds all mixed up :()

Lynne
05-25-2009, 04:50 PM
Since you are creating your own php page, you really don't need to use any plugins. You should put all your php in your test page right after the START MAIN SCRIPT lines (before $navbits). Put all the php there. Then, to eval your template, you would go:
eval('print_output("' . fetch_template('custom_1') . '");'); or assign the results to a variable to use like this:
eval('$my_variable = "' . fetch_template('custom_1') . '";'); And you would want to put that before you eval the test template. Once you eval with print_output, that is the end. So that should be your last statement in regards to templates.


You also need lines at the top of the page to 'include' the template.

This should help - [How-To] vBulletin API Basics: Creating Custom Pages & Misc. (https://vborg.vbsupport.ru/showthread.php?t=98009)

David Regimbal
05-25-2009, 06:00 PM
It works! Thank you very very much Lynne!

I have one more quick question :) Would it be possible to then also have this in peoples profiles?


So far I have test.php with the variable
But, to make it so you can view other peoples (I am not sure :()

--------------- Added 1243297579 at 1243297579 ---------------

I am just about to get the above to work, though I dont know how I can convert this:


echo "Example: " . $xml->PresenceInfo->ExampleText . "<br />";
so I don't keep getting a Content Encoding Error?