Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-25-2009, 01:20 PM
David Regimbal David Regimbal is offline
 
Join Date: May 2009
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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?
Reply With Quote
  #2  
Old 05-25-2009, 01:59 PM
EnIgMa1234 EnIgMa1234 is offline
 
Join Date: Mar 2006
Location: .:: Ireland ::.
Posts: 1,306
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by David Regimbal View Post
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];
Reply With Quote
  #3  
Old 05-25-2009, 02:43 PM
David Regimbal David Regimbal is offline
 
Join Date: May 2009
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 />"
Reply With Quote
  #4  
Old 05-25-2009, 03:37 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$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.
Reply With Quote
  #5  
Old 05-25-2009, 04:23 PM
David Regimbal David Regimbal is offline
 
Join Date: May 2009
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 )
Reply With Quote
  #6  
Old 05-25-2009, 04:50 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 05-25-2009, 06:00 PM
David Regimbal David Regimbal is offline
 
Join Date: May 2009
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:43 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.04094 seconds
  • Memory Usage 2,255KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (13)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete