View Full Version : Include PHP in an advert
eviljoker7075
04-05-2013, 11:29 AM
Hey I asked the following question over at vBulletin.com:
I am using the ad management system in vBulletin (Admin CP> Advertising> Manage Ads). I would like to place an include to a php file in one of my ads. Is that possible?
They responded saying that I should ask at vbulletin.org and that it might be possible with a plugin... Can anyone help me out with that?
Basically, all I need to do is place an include to one php file in an advert. I don't mind hard coding the reference into the remplate if necessary, rather than going through the ad system.
Thanks
You should be able to do something like this: create a plugin using hook location parse_templates, and code like this:
ob_start();
include "path/included_file.php";
$included_file = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('template_name', array('included_file' => $included_file));
And then in the ad template, use {vb:raw included_file}. Of oucrse you need to use the actual path and file name, use the right template name for the ad location, and you can change 'included_html' to comething else if you want.
eviljoker7075
04-06-2013, 08:44 AM
Thanks for the suggestion, I've given it a go but it doesn't seem to work. Would you be able to sanity check what I've done?
1. I setup a new plugin with the following details:
Product: vBulletin
Location: parse_templates
Name: included_html
Code:
ob_start();
include "/path/to/file.php";
$included_file = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('navbar', array('included_file' => $included_file));
2. Created an add
Location: Below Navbar
Ad HTML:
{vb:raw included_html}
What am I missing?
--------------- Added 1365242536 at 1365242536 ---------------
Ok, I can see my ad code should probably be:
{vb:raw included_file}
But even when I make that change nothing is showing up...
Ok, I can see my ad code should probably be:
{vb:raw included_file}
Yeah, sorry, that was a mistake in my post.
Try using 'ad_navbar_below' as the template name (in place of 'navbar').
eviljoker7075
04-06-2013, 10:21 AM
No worries. It's still not working though :-/
Am I asking for an extra level of complexity here, I don't mind putting the variable directly into the template, would that be easier?
You could certainly try that. So then you *would* use 'navbar' for the template name.
If that doesn't work, try temporarily adding a line to the plugin, like this:
ob_start();
include "/path/to/file.php";
$included_file = ob_get_contents();
ob_end_clean();
$included_file = "Included File";
vB_Template::preRegister('navbar', array('included_file' => $included_file));
and see if that shows up.
eviljoker7075
04-06-2013, 10:56 AM
So I switched the template to 'navbar' and added in the {vb:raw included_file} line to the template directly and that worked!
I also tried your debug code (while using the ad too), but it had no effect.
I think I'll stick to putting the code directly into the template - but if you have any more suggestions why the original attempt failed I'd be interested in learning more.
Thanks!
I don't see why it didn't work - I'd have to run some tests. But if you have it working, I guess it doesn't really matter which template you had to edit. :)
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.