vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Include PHP in an advert (https://vborg.vbsupport.ru/showthread.php?t=296881)

eviljoker7075 04-05-2013 11:29 AM

Include PHP in an advert
 
Hey I asked the following question over at vBulletin.com:
Quote:

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

kh99 04-05-2013 12:08 PM

You should be able to do something like this: create a plugin using hook location parse_templates, and code like this:

Code:

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

{vb:raw included_html}

What am I missing?

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

Ok, I can see my ad code should probably be:
Code:

{vb:raw included_file}
But even when I make that change nothing is showing up...

kh99 04-06-2013 10:08 AM

Quote:

Originally Posted by eviljoker7075 (Post 2414674)
Ok, I can see my ad code should probably be:
Code:

{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?

kh99 04-06-2013 10:31 AM

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:

Code:

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!

kh99 04-06-2013 11:15 AM

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. :)


All times are GMT. The time now is 09:11 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.01014 seconds
  • Memory Usage 1,731KB
  • 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
  • (6)bbcode_code_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)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