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 01-16-2008, 03:53 AM
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP API code in template, php file, or somewhere else?

I have the following PHP code:
Code:
<?
require_once('./api/class.api.php');
require_once('./api/class.charselect.php');
$api = new Api();
$api->debug(false);
$api->cache(false);
$api->setCredentials($apiuser,$apipass);
$uchars = $api->getCharacters();
$chars = CharSelect::getCharacters($uchars);
$apichar = $chars[0]['charname'];
$api->setCredentials($apiuser,$apipass,$apichar);
?>
I need to use this, and several more $api->getSomeInfo calls, in a new template I've created. I've got the template and php file and a link to it in the footer bar all working, I just need to know where to put this code, so that it will run when the page is accessed and so I can call the $api functions as needed from the template. Or should I run this in the php file itself and grab everything it might need, then just have the template display the requested parts? Also, if will need <if condition=$bbuserinfo[fieldX]> stuff, and I've read that doesn't work well outside of the template. Does that mean that I _can't_ put the code into the php file?
Reply With Quote
  #2  
Old 01-16-2008, 04:00 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You will need to create a plugin at the appropriate location as you cannot run PHP code in templates directly.
Reply With Quote
  #3  
Old 01-16-2008, 02:45 PM
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This will need to be called many times with different settings. Do I need a seperate plugin for each call ($359api_chars, $359api_tree, etc) or can the plugin be used as an array? I followed the instructions from https://vborg.vbsupport.ru/showthrea...ghlight=plugin, but when I put $359eveit[1][charname] in the display template, it actually shows the variable name, rather than nothing. Considering it should be a blank variable, it should display nothing, right?
Reply With Quote
  #4  
Old 01-16-2008, 03:34 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP variable names cannot begin with a number.
Reply With Quote
  #5  
Old 01-16-2008, 04:03 PM
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you, having all these problems and never thought of that

Alright, I've changed everything around so it is now $eveit359. Plugin output is now getting to the template, as long as it's plain HTML. When I try to make $eveit359 into an array (store a value into $eveit359[1], and put that in the template, I get output like "p[charname]". I am completely lost trying to figure out what the heck the template/plugin tutorials are saying with variable renaming or whatever it is they're talking about. I need to have several arrays of data accessible to the template, preferably in one big array $eveit359[1][charname], $eveit359[1][charid], $eveit359[1][tree][current], $eveit359[1][tree][time], etc.
Reply With Quote
  #6  
Old 01-16-2008, 05:20 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I don't know might be something to do with your script. Arrays start from 0 not 1. I don't know why you are storing it in arrays you can store it as a variable normally. If it makes it easier to use arrays then use arrays. If you have multidimension arrays consider surrounding it in brackets. Like in your template have:
PHP Code:
{$eveit359[1][tree][time]} 
If you run this at the end of your plugin it will give you a dump of all the information stored in the variable.
PHP Code:
var_dump($eveit359); 
Reply With Quote
  #7  
Old 01-16-2008, 05:40 PM
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

My current plugin template content:
PHP Code:
<?php
require_once('./eveitapi/class.api.php');
require_once(
'./eveitapi/class.charselect.php');
$api359 = new Api();
$api359->debug(false);
$api359->cache(true);
$api359->setCredentials($apiuser359,$apipass359);
$uchars359 $api359->getCharacters();
$chars359 CharSelect::getCharacters($uchars359);
$eveit359 $chars359[0][charname];
var_dump($eveit359);
?>
On the display template, rather than showing the contents of $eveit359 (as I would expect it to from var_dump), it outputs the php script as plain text.

I tried changing the plugin template to a simple
PHP Code:
<?php
$eveit359 
"Hello";
var_dump($eveit359);
?>
and got no output.
PHP Code:
<?php
echo "Hello";
?>
also produces no output.

Not sure if what you meant was to use another variable in the plugin and display templates, but I tried
PHP Code:
<?php $testing359="test"?>
and $testing359 in the display template got no output.

Could the Api functions be causing a problem? The plain text script output starts with "debug(false); $api359->cache(true);" as if that first "->" is a problem.

--------------- Added [DATE]1200517434[/DATE] at [TIME]1200517434[/TIME] ---------------

I just tried
PHP Code:
<?php
echo "<font color=white>Hello</font>";
?>
as the plugin template, and now the display template outputs the following in view source:
HTML Code:
<?php
echo \"<font color=white>Hello</font>\";
?>
On the page it appears as Hello\"; ?>

If I change the double quotes to single quotes, output is blank.
Reply With Quote
  #8  
Old 01-17-2008, 03:13 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You don't need to have <?php and ?> in plugins, as the code is evaluated (using eval()).
Reply With Quote
  #9  
Old 01-17-2008, 02:28 PM
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
Posts: 57
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

New plugin template:
PHP Code:
require_once('./eveitapi/class.api.php');
require_once(
'./eveitapi/class.charselect.php');
$api359 = new Api();
$api359->debug(false); // enable debugging
$api359->cache(false); // do not use a cache-file, if one exists
$api359->setCredentials($bbuserinfo[field6],$bbuserinfo[field7]);
$uchars359 $api359->getCharacters();
$chars359 CharSelect::getCharacters($uchars359);
$eveitapi $chars359[0][charname];
$charblahtest "Hello";
echo 
"Hello"
New output:
Code:
require_once('./eveitapi/class.api.php'); require_once('./eveitapi/class.charselect.php'); = new Api(); (false); // enable debugging (false); // do not use a cache-file, if one exists (1188020,RDQiA46jtGtzMUEFVtgbtJ2CfhTCIPGkD0JeUz22NomPeQWCx552fwe0gwkSi4bh); = (); = CharSelect::getCharacters(); = [charname]; = "Hello"; echo "Hello";
It's still pretending it's plain text rather than executing the PHP code.

The above is using the "eval" plugin and "array_merge" cache plugin.

When I use the method from this post I get the following output. Still doesn't parse it, but at least this way it's not evaluating the variables.

Code:
require_once('./eveitapi/class.api.php'); require_once('./eveitapi/class.charselect.php'); $api359 = new Api(); $api359->debug(false); // enable debugging $api359->cache(false); // do not use a cache-file, if one exists $api359->setCredentials(" . $GLOBALS['vbulletin']->userinfo['field6'] . "," . $GLOBALS['vbulletin']->userinfo['field7'] . "); $uchars359 = $api359->getCharacters(); $chars359 = CharSelect::getCharacters($uchars359); $eveitapi = $chars359[0][charname]; $charblahtest = \"Hello\"; echo \"Hello\";
Would it be easier to just build the variables and/or array in eveit.php itself, rather than using another template, since the API part won't be displaying anything, just storing information?
Reply With Quote
  #10  
Old 01-17-2008, 02:47 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

What editor are you using? Looks like all linebreaks are removed.
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 05:07 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.13700 seconds
  • Memory Usage 2,282KB
  • Queries Executed 13 (?)
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
  • (3)bbcode_code
  • (1)bbcode_html
  • (8)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_postinfo_query
  • fetch_postinfo
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete