vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Putting a variable in a hook (https://vborg.vbsupport.ru/showthread.php?t=214499)

David Regimbal 05-25-2009 01:20 PM

Putting a variable in a hook
 
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:

PHP Code:

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

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

PHP Code:

$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

Quote:

Originally Posted by David Regimbal (Post 1816823)
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:

PHP Code:

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

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

PHP Code:

$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:

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:
PHP Code:

$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:

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 />"

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:

PHP Code:

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

Below the
PHP Code:

require_once('./global.php'); 

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

PHP Code:

// ######################### 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:
PHP Code:

eval('print_output("' fetch_template('custom_1') . '");'); 

or assign the results to a variable to use like this:
PHP Code:

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.

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 [DATE]1243297579[/DATE] at [TIME]1243297579[/TIME] ---------------

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

PHP Code:

echo "Example: " $xml->PresenceInfo->ExampleText "<br />"

so I don't keep getting a Content Encoding Error?


All times are GMT. The time now is 08:38 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01187 seconds
  • Memory Usage 1,762KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (13)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete