Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 16 Jan 2008, 04:53
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
PHP API code in template, php file, or somewhere else?

I have the following PHP code:
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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 16 Jan 2008, 05:00
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Real name: Hanson
You will need to create a plugin at the appropriate location as you cannot run PHP code in templates directly.
__________________
Former vBulletin.org Staff Member

View My Modifications
29 Releases and Counting... Latest Modification: dmActivityStream - vBookie Integration (4.x)

Please do not PM me to ask for support - please use the relevant thread or forum.
Reply With Quote
  #3  
Old 16 Jan 2008, 15:45
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
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 http://www.vbulletin.org/forum/showt...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 16 Jan 2008, 16:34
Opserty Opserty is offline
 
Join Date: Apr 2007
PHP variable names cannot begin with a number.
Reply With Quote
  #5  
Old 16 Jan 2008, 17:03
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
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.

Last edited by petteyg359; 16 Jan 2008 at 18:02.
Reply With Quote
  #6  
Old 16 Jan 2008, 18:20
Opserty Opserty is offline
 
Join Date: Apr 2007
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:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

If you run this at the end of your plugin it will give you a dump of all the information stored in the variable.

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #7  
Old 16 Jan 2008, 18:40
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
My current plugin template content:
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

and got no output.
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

also produces no output.

Not sure if what you meant was to use another variable in the plugin and display templates, but I tried
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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 16 Jan 2008 at 20:03 ---------------

I just tried
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

as the plugin template, and now the display template outputs the following in view source:
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

On the page it appears as Hello\"; ?>

If I change the double quotes to single quotes, output is blank.

Last edited by petteyg359; 16 Jan 2008 at 20:04. Reason: Auto-Merged DoublePost
Reply With Quote
  #8  
Old 17 Jan 2008, 04:13
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Real name: Hanson
You don't need to have <?php and ?> in plugins, as the code is evaluated (using eval()).
__________________
Former vBulletin.org Staff Member

View My Modifications
29 Releases and Counting... Latest Modification: dmActivityStream - vBookie Integration (4.x)

Please do not PM me to ask for support - please use the relevant thread or forum.
Reply With Quote
  #9  
Old 17 Jan 2008, 15:28
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
New plugin template:
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

New output:
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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.


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

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?

Last edited by petteyg359; 17 Jan 2008 at 15:43.
Reply With Quote
  #10  
Old 17 Jan 2008, 15:47
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
What editor are you using? Looks like all linebreaks are removed.
__________________
Marco van Herwaarden
Ex vBulletin.org Coordinator
Reply With Quote
  #11  
Old 17 Jan 2008, 15:49
Opserty Opserty is offline
 
Join Date: Apr 2007
Just to clarify you are placing this code in a PLUGIN correct? (AdminCP > Plugins and Products > Add New Plugin)

And not a TEMPLATE? (AdminCP > Style Manger....)

You keep saying plugin template its confusing as to what you mean exactly as they are two different things.
Reply With Quote
  #12  
Old 17 Jan 2008, 15:58
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
The plugin article said a plugin is a variable that display the contents of another template. I've been putting the code in this second template. Should the code be in the plugin itself? The plugin code is currently
Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So if I put all the PHP in the plugin itself, I should be able to use the defined variables on any template (since the plugin is in global_start)? When I said plugin template I was referring to the template the plugin calls. When I said display template I was referring to the template that had $eveitapi where I wanted the plugin stuff to display.
Reply With Quote
  #13  
Old 17 Jan 2008, 16:02
Opserty Opserty is offline
 
Join Date: Apr 2007
I'm not sure what article you were reading but a Plugin is a peice of PHP Code that is excuted at a certain location (the hook location) by vBulletin. You PHP Code must go inside a Plugin.

You can use a Plugin to fetch a template, a template is front-end HTML that is displayed to the user. You can use variables in your template that get their values from the PHP code, but you cannot execute PHP code inside templates.

Think of it like this (this is just a demonstration of how the system works you do not need to use this code at all!):

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Reply With Quote
  #14  
Old 17 Jan 2008, 16:26
petteyg359 petteyg359 is offline
 
Join Date: Dec 2007
I tried putting the code in a plugin with hook global_start but variables weren't available to the template. When I put the code directly in the php file things work. Are there any security issues with putting the code directly in the php file?
Reply With Quote
  #15  
Old 17 Jan 2008, 16:51
Opserty Opserty is offline
 
Join Date: Apr 2007
What template was it? and make sure you checked that the variables actually had some data in them. Also make sure you eval()'d the template like this (if you are using a custom one)


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Then you would place $somevar in a normal vBulletin template and it would display your code there.

I doesn't make much difference if you place your code in Plugins or PHP files, but the plugin system is there so you don't have to mess with Files.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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


New To Site? Need Help?

All times are GMT. The time now is 20:03.

Layout Options | Width: Wide Color: