PDA

View Full Version : [vBulletin 4] Simple way of including an external PHP file


Crimm
05-12-2010, 10:00 PM
There are other articles out there on variables, templates, etc on vBulletin 4. This is a simple example of including an external PHP files like you used to be able to do here:

http://www.vbulletin.com/forum/showthread.php?173937-How-to-Include-a-PHP-or-HTML-File

Thanks to this Blog post by David IB http://www.vbulletin.com/forum/entry.php?2387-Pushing-your-variables-to-templates and this article by cellarius https://vborg.vbsupport.ru/showthread.php?t=228078

I have figured out it's only a simple extra step.

Step 1: Create a new plugin

Hook Location: What area of the forums you want this variable to appear. Don't know where? Use global_start
Title: Give it a title
Execution order: Your choice
Plugin PHP Code:


ob_start();
require_once('LOCATION OF EXTERNAL FILE');
$php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));


Step 2: You will have to figure out these two entries for yourself: LOCATION OF EXTERNAL FILE & Hook Location

To give you an example of what you should use is that if you want to display your external PHP file on your Forum's Home. Then replace these two with these values:

Hook Location with forumhome_start
TEMPLATE YOU ARE USING with FORUMHOME

Keep in mind that global_start will still be acceptable, but it's extra loading time where it's not needed. Therefore choosing the optimum hook location is better for your performance overall.

Step 3: Visit the Style Manager -> TEMPLATE YOU ARE USING and place the variable in your style where you want it. You will have to use the new format.

{vb:raw php_include}

That's it - Pretty simple; see? :)

Notes, If you want to:

Include this PHP file in multiple templates then preRegister it for the multiple templates:

vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));
vB_Template::preRegister('TEMPLATE YOU ARE USING 2',array('php_include' => $php_include));

Thanks to David IB (http://www.vbulletin.com/forum/entry.php?2387-Pushing-your-variables-to-templates) again.

I'm still learning as I go with vb4, but if I learn some more notes to add... I'll drop by here.

I hope that helps some one out there!

frostyx
05-27-2010, 06:07 PM
This is excellent, it works great on the forum and blog pages but it won't load on the home page for me. Any advice?

Crimm
05-28-2010, 09:18 AM
Helped someone else with the same problem. Globalstart isn't a hook on the home page.

I can't currently give you documentation, but if you use init_start it should work. For optimization reasons though I do not suggest that. I can offer more after the weekend is over if needed.

Thanks.

philwareham
07-06-2010, 04:36 PM
Hi,
Thanks for the tips. How would I use this idea to replicate a php 'echo file_get_contents' instead of a 'require_once'?
Cheers,
Phil

Crimm
07-09-2010, 05:00 PM
I'm not 100% sure. I haven't done that yet.

Stupid question, but have you tried swapping the two?

philwareham
07-12-2010, 03:31 PM
Yep, this works thanks...

// Textpattern External Output: body-social
ob_start();
echo file_get_contents('http://mydomain/?rah_external_output=body-social');
$php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('footer',array('txp_body_ social' => $php_include));


Cool, this will make vBulletin really easy to integrate with my CMS templates. Great stuff.

ragtek
07-12-2010, 05:45 PM
Yep, this works thanks...

// Textpattern External Output: body-social
ob_start();
echo file_get_contents('http://mydomain/?rah_external_output=body-social');
$php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('footer',array('txp_body_ social' => $php_include));


Cool, this will make vBulletin really easy to integrate with my CMS templates. Great stuff.
You don't need the output buffer!
$php_include = file_get_contents('...'); would also work;)

Centrix
07-14-2010, 01:30 PM
I tried this, but it made my forum crash miserably. I had to restore a database backup in order for it to work again.


ob_start();
require_once('LOCATION OF EXTERNAL FILE');
$php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));
[/LIST]

Step 2: You will have to figure out these two entries for yourself: LOCATION OF EXTERNAL FILE & Hook Location


I made a custom template and I dont know which hook location to use for this...? if I use global start my site and forum (site is linked to the forums) is just the contents of the php file im trying to include.

Triky
07-15-2010, 01:47 PM
When I create the plugin and I activate it, I get a blank page in my forum. This is the code I'm using in the plugin:

ob_start();
require_once('../includes/kbar.php');
$kbar = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('header',array('php_inclu de' => $php_include));And this is what I'm using on the template header:


{vb:raw kbar}


Why? Can you please help me?

Triky
07-20-2010, 11:48 AM
Can please somebody help me out?

philwareham
07-20-2010, 11:55 AM
Looks OK to me, have you made the plugin hook 'global_start'?

Maybe try a full server path for kbar.php?

Triky
07-20-2010, 11:21 PM
Yes, I'm using global_start. Using a full server path I can get the forum to work (previously I was getting a blank forum page).. but nothing is being included. And yes, I'm sure the file is where it is supposed to be.

This is strange.. please help me! :)

ragtek
07-21-2010, 04:18 AM
And that's the problem;)

There is no global_start hook anymore;)

Use global_bootstrap_init_start

philwareham
07-21-2010, 07:19 AM
There is no global_start hook anymore;)

Huh? I'm using it fine on my v4.0.5 install for hooks in the header and footer templates. Confused.

ragtek
07-21-2010, 07:47 AM
// Deprecated as of release 4.0.2, replaced by global_bootstrap_init_start
($hook = vBulletinHook::fetch_hook('global_start')) ? eval($hook) : false;

$bootstrap->load_style();

// legacy code needs this
$permissions = $vbulletin->userinfo['permissions'];

// Deprecated as of release 4.0.2, replaced by global_bootstrap_complete
($hook = vBulletinHook::fetch_hook('global_setup_complete') ) ? eval($hook) : false;

philwareham
07-21-2010, 08:13 AM
Ah OK thanks, I'll change all occurrences of 'global_start' to 'global_bootstrap_init_start' to futureproof the hooks.

Triky
07-21-2010, 12:16 PM
I was having problems both with the hook and the PHP code of the plugin. This is the correct code:

ob_start();
require_once('/path/to/public_html/includes/kbar.php');
$kbar = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('header',array('kbar' => $kbar));

Thank you!

southie
10-06-2010, 06:49 PM
i am having the same issue, did you ever find a solution to this problem Centrix ? or anybody else who could help ?

I tried this, but it made my forum crash miserably. I had to restore a database backup in order for it to work again.



I made a custom template and I dont know which hook location to use for this...? if I use global start my site and forum (site is linked to the forums) is just the contents of the php file im trying to include.

webmaster74
10-09-2010, 12:54 AM
vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));[/code]

Step 2: You will have to figure out these two entries for yourself: LOCATION OF EXTERNAL FILE & Hook Location

To give you an example of what you should use is that if you want to display your external PHP file on your Forum's Home. Then replace these two with these values:

Hook Location with forumhome_start
TEMPLATE YOU ARE USING with FORUMHOME

I created this plug-in and activated it.

ob_start();
include('/home/mydomain/public_html/php/includes/ineverypost.inc.php');
$includedineverypost = ob_get_contents();
ob_end_clean();


vB_Template::preRegister('postbit_display_complete ',array('includedineverypost' => $includedineverypost));

in vb 3.8.6, this was hooked to 'postbit_display_complete'

Now with VB4, there is no template for post_display_complete....

I tried "postbit" it did notwork. I tried other postbit related templates, this still did not work.

any help ??

hihello
11-19-2010, 06:23 PM
The included page shows up but it's showing on every page. I used the parse_template hook. Do I need to include anything else to only show one a specific page?

webmaster74
12-10-2010, 10:51 AM
I created this plug-in and activated it.

ob_start();
include('/home/mydomain/public_html/php/includes/ineverypost.inc.php');
$includedineverypost = ob_get_contents();
ob_end_clean();


vB_Template::preRegister('postbit_display_complete ',array('includedineverypost' => $includedineverypost));

in vb 3.8.6, this was hooked to 'postbit_display_complete'

Now with VB4, there is no template for post_display_complete....

I tried "postbit" it did notwork. I tried other postbit related templates, this still did not work.

any help ??


any generous person wants to share his knowledge ?

--------------- Added 11 Dec 2010 at 03:23 ---------------

would any kind person help with this ?

BirdOPrey5
12-22-2010, 01:32 AM
postbit_display_complete is a php code hook... not a template... the template is named postbit and it's the same in VB3 and VB4.

fluidswork
12-22-2010, 01:15 PM
Nice idea i will give this a try ..........

aileron79
12-22-2010, 02:24 PM
Hi everybody,
sorry in advance for me maybe talking rubbish, but I am completely new to developing plugin code for vbulletin. I am quite experienced in coding PHP, though. Boofo pointed me in the right direction (thanks for that), but, however, I am still facing the following problem:

I want to extend the list of online users (online.php) by another column. Information within that column is not extracted from the database but fetched from a third party. This has to be done for each user that shows up in the list of online users - but I have no idea which hook I may use.

At the moment, my plugin works pretty fine - but it is a bad mixture of source code hacking and template modifications. If any future upgrade replaces online.php, all my changes are gone. I added a very few lines of code in online.php (v4.1.0 PL2) starting from line 414, which basically adds another value to the $userinfo array which (as if this variable is registered) can be accessed from the whoisonlinebit template, where the output is generated from the additional value.

As mentioned before - so far, everything works fine but I truly hate source code modifications as they are gone after an update. Therefore, it would be great to know if there is another way of executing code (maybe in an external file) for each line in the result set. If I interpret the PHP source in online.php correctly, anything that should be executed for each user name should go inside the while loop on line 393. The instructions above explain how to use external files with hooks but I just can't figure out which hook to use in that case...

Is there a way to execute PHP code from templates without having a hook?

As I said, I am completely new to this stuff, please help...

BirdOPrey5
12-22-2010, 03:38 PM
There's a hook at the very end of the while loop:

($hook = vBulletinHook::fetch_hook('online_user')) ? eval($hook) : false;


So if you can use that hook, "online_user."

aileron79
12-22-2010, 04:33 PM
Indeed, I have found that hook and I thought it would be what I was looking for, but obviously this hook only affects spiders/guests, according to the comment on line 449:


while ($users = $db->fetch_array($allusers))
{
if ($users['userid'])
{ // Reg'd Member
...
}
else
{ // Guest or Spider..
$spider = '';
...

$guests["$count"]['count'] = $count + 1;
$guests["$count"]['useragent'] = htmlspecialchars_uni($users['useragent']);
$count++;

($hook = vBulletinHook::fetch_hook('online_user')) ? eval($hook) : false;
}
}


The hook is inside the else branch which obviously handles unregistered users, the code I have added is in the if branch... Did I misinterpret anything...?

BirdOPrey5
12-22-2010, 04:49 PM
Probably not... although it's of no use when releasing a mod to others you can add your own hooks to the code anywhere you want- so if it's just for you adding a 1 line hook and keeping the bulk of the code in a plugin will make life easier than keeping all edits in the files.

aileron79
12-22-2010, 08:48 PM
Thanks for replying to fast! Well, that of course would be possible and still, this is probably the best idea. I still could add instructions on how to create the custom hook in my install guide. However, I consider this hook a bug... I just can't believe it makes any sense in that position. But as mentioned before, I am quite new to this plugin system, probably I just do not understand enough...

But am I right that there is no way to achieve what I want without modifying the original vb source code?

BirdOPrey5
12-22-2010, 11:20 PM
But am I right that there is no way to achieve what I want without modifying the original vb source code?

Best I can tell if you really need that location you would have to manually edit the source code but I'm far from an 'expert' on this topic myself.

However if you're fetching data from an external source could you not just "run the loop" a second time and collect the data needed per user id, and put the data in an array who's keys are the userid's themselves so it's say $mydata[1] for userid 1, $mydata[200] for user 200, etc... then call it in the template where needed (after pre-registering it of course.)

robert garrett
12-30-2010, 12:43 PM
ob_start();
require_once('/home/echoca/public_html/news/journals1.php');
$php_journal = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('echo_journals',array('ph p_journal' => $php_journal));

tried also leaving custom_ out this is not working at all.

global bootstrap init start, is the hook I am using. I had some bugs in the code when I first included it, and it showed up as I worked the bugs out, and the code ran clean, it made it through the hook. Thats great. I clicked on the tab, that is linked to the template I added it to, and it just wont display Ideas anybody?

RG

robert garrett
01-02-2011, 03:45 PM
o.k. I got that to work, now how to get scripts that call the same page to work?

ehsanix
01-14-2011, 07:17 PM
woooooooooooooooooooooow
very nice
thanx
thanx man
gooood job :)
exelent

ehsanix
01-15-2011, 10:58 PM
How can I php file in my Sidebar include?
help :(

MMODisneyForums
01-27-2011, 01:47 AM
This is a nice tutorial you have, I have read many, but this one is very clear and simple. But from all the tutorials I've tried, I can never get this to work. I want to have a php file output into the postbit_legacy template. So I made a plugin following this tutorial, using this:

Hook Location: global_start
Title: Testing
Execution Order: 5
And the PHP Code:ob_start();
require_once('http://**********/creds.php');
$php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('postbit_legacy',array('p hp_include' => $php_include))

Then in the postbit_legacy template I added in {vb:raw php_include} where it should go. Nothing shows up, and I get an error at the top of the page:
Parse error: syntax error, unexpected $end in /home/****/public_html/forums/global.php(29) : eval()'d code on line 7

I get that error on pages that have posts on it. On the forum homepage, nothing shows up except:

Parse error: syntax error, unexpected $end in /home/mmodis/public_html/forums/global.php(29) : eval()'d code on line 7

Fatal error: Call to undefined function print_portal_output() in /home/mmodis/public_html/index.php on line 46

If anyone can help me with this thanks, I have had problems with using plugins to include php files in the templates for too long. It always worked perfectly fine for me in vB 3.4. Thankyou for your time.

Note: Where the "****" are, just for posting the code here, I put those in to censor where the files are, just to be safe. I really do have the correct paths in the files uploaded to the site.

risestar
01-29-2011, 02:52 AM
Well global_start hook location is now obsolete as of 4.0.3+ and 4.1. You should probably use the global_bootstrap_init_start hook instead if you are using a recent version. Also using $php_include as your variable might be causing problems so rename it to something unique. Your plugin code should probably be more like this




ob_start();
require_once('http://www.xxxxxxx.com/creds.php');
$creds = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('postbit_legacy',array('c reds' => $creds));





and of course the call in the postbit_legacy template {vb:raw creds}


The parse error in your code is due to your missing the ";" at the end of your statement


This is a nice tutorial you have, I have read many, but this one is very clear and simple. But from all the tutorials I've tried, I can never get this to work. I want to have a php file output into the postbit_legacy template. So I made a plugin following this tutorial, using this:

Hook Location: global_start
Title: Testing
Execution Order: 5
And the PHP Code:ob_start();
require_once('http://**********/creds.php');
$php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('postbit_legacy',array('p hp_include' => $php_include))

Then in the postbit_legacy template I added in {vb:raw php_include} where it should go. Nothing shows up, and I get an error at the top of the page:
Parse error: syntax error, unexpected $end in /home/****/public_html/forums/global.php(29) : eval()'d code on line 7

I get that error on pages that have posts on it. On the forum homepage, nothing shows up except:

Parse error: syntax error, unexpected $end in /home/mmodis/public_html/forums/global.php(29) : eval()'d code on line 7

Fatal error: Call to undefined function print_portal_output() in /home/mmodis/public_html/index.php on line 46

If anyone can help me with this thanks, I have had problems with using plugins to include php files in the templates for too long. It always worked perfectly fine for me in vB 3.4. Thankyou for your time.

Note: Where the "****" are, just for posting the code here, I put those in to censor where the files are, just to be safe. I really do have the correct paths in the files uploaded to the site.

MMODisneyForums
01-31-2011, 05:54 PM
Thanks for the help. I tried all of that, and now every page in the forum is completely blank when I turn the plugin on. If I turn it off the forums are back. Is there any reason for this?

Boofo
01-31-2011, 06:46 PM
I still don't understand why you guys just don't use the require_once to include the file in the php hook right before the code you want to use it with. You are taking the long way around doing it this way. Unless you need the included file for every page, it makes no sense to put it in the global hook.

risestar
01-31-2011, 07:36 PM
What version of vbulletin are you using?

If you type in the script location directly from your browser, does it work? If not, then its a problem with your script.

Also, your php.ini might be set to disallow http php include calls, if you so need to enable it, or use the path call instead


ob_start();
require_once('/path/to/your/website/creds.php');
$creds = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('postbit_legacy',array('c reds' => $creds));


Otherwise, its a typo, if you are using this code, make sure you cut and paste it, have the path/url correct



Thanks for the help. I tried all of that, and now every page in the forum is completely blank when I turn the plugin on. If I turn it off the forums are back. Is there any reason for this?

MMODisneyForums
01-31-2011, 08:31 PM
I'm using version 4.1.0. I tried changing my creds.php file to just simply echo "Test", and I still just get a plain white page on the forums. If I open the php file in my browser it correctly says Test. Should I change the hook location? Is there a better location for postbit_legacy? And I have copy pasted that code exactly in, and replaced the URL. What could be going wrong here? Thanks

Edit: I have noticed something else that is interesting. If I remove the {vb:raw creds} from the postbit_legacy template, there is still a blank page. If the plugin is on, theres a blank page, even if its not being called from the template. Hope this helps.

risestar
02-02-2011, 02:48 AM
The plugin is fairly straight forward, as long as you have a valid script that you are calling and your plugin code is valid, you should be good to go.

you might have a php.ini config issue going on.

Create a new file in your forum root, call it test.php

Insert this

<?php include ("/server/path/to/your/test.php"); ?>

<?php include ("http://www.yoursite.com/forum/test.php"); ?>

/insert this

Then open the test.php in your browser

If they BOTH work, you should have your echoed text inserted twice. If only ONE works, or you get a php error, you have a php.ini config issue to work out.

MMODisneyForums
02-02-2011, 03:22 AM
Ok, I tried that out. The first one did indeed echo, but the second one didn't. So this means I need to go into the php.ini config file and change something? I can't seem to find this php.ini. Should I be looking somewhere?

Edit: It works now! Before in my plugin I was putting the entire path in (http://www.yoursite.com/forum/test.php). So I just changed it to "../forum/test.php" and it works! So it must be a problem with the php.ini. I looked around and it sounds like it is a real huge pain to mess with. Unless it is simple, I will just remember to not put the full path in.

risestar
02-02-2011, 07:06 PM
Yes, theres a setting in php.ini to allow scripts to be passed over http

I'm not sure exactly where it is, but I had to do the same before some of my scripts would run properly on my server

You need to set php to include through HTTP , ie: allowing remote files to be included

Some info is available here. http://www.php.net/manual/en/features.remote-files.php

BirdOPrey5
02-02-2011, 07:57 PM
You can't include a php file using it's remote (http) address EVER. It will never work that way. PHP files are executed when viewed by http, the code is never shown or known to the browser. You can include using full or relative paths on your server, examples:


/includes/myfile.php
or
/home/yoursite/public_html/forums/includes/myfile.php

MMODisneyForums
02-04-2011, 04:25 AM
Thank you guys so much for all the help, everything is working like a charm now! :D

Schoelle
02-08-2011, 07:46 PM
Ok i need your help please!

I have created four pages according to this How-To:
https://vborg.vbsupport.ru/showthread.php?t=228112

I have also 4 external php scripts that i want to include.
I have created 4 templates and 4 plugins.

I have change the php_include to
php_include_1 to php_include_4 and also changed this accordingly in the templates.


ob_start();
require_once('../vbtest/test_1.php');
$php_include_1 = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('template_1',array('php_i nclude_1' => $php_include_1));


It works als long as i only activate 1 of those 4 plugins.
As soon as i activate 2,3 or 4 plugins i get this:

Warnung: require_once(../vbtest/test_1.php) [function.require-once]: failed to open stream: No such file or directory in [path]/includes/class_bootstrap.php(122) : eval()'d code (Zeile 7)

Fatal error: require_once() [function.require]: Failed opening required '../vbtest/test_1.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/b/b0000009/weball/vbtest/includes/class_bootstrap.php(122) : eval()'d code on line 7

The file which is mentioned as missing here is there and it is producing output as long as i only activate 1 of the modules!

I guess it maybe is because of the hook i've chosen?
As i was not sure which one, and most of the ones i expected to be the right ones did not work at all i've chosen 'global_bootstrap_init_complete'

Any ideas? Which would be the correct hook?
Thanks for any help,

regards,
Matthias

Boofo
02-14-2011, 08:37 AM
Where are you wanting the info to show up at? Every page?

Schoelle
02-14-2011, 01:24 PM
Ok, i'll explain what i want to achieve, and hopefully you guys can help me.
I'm very new to vBulletin and my knowledge of php is also not 'the' best :)

I have a php script that is creating a linklist from files within a directory.
At the end of the script i have an echo statement to display the list.

What i want is to have this showing up inside a vbulletin page.
The only thing i have achieved so far is including this script in the new page i have created according to this: https://vborg.vbsupport.ru/showthread.php?t=228112

I have put
require_once('./script.php');
This end up in showing the created list above the forum header!


So what i want to achive is:
Including the output of several php scripts in several vbulletin pages.
www.mysite.com/script1.php > www.mysite.com/page1.php
www.mysite.com/script2.php > www.mysite.com/page2.php
and so forth.

Boofo
02-14-2011, 03:34 PM
Of course you will see the created list if you use echo in the file. You need to use the function from the file to show the listing formatted to whatever template you set up for it.

Schoelle
02-15-2011, 02:43 PM
Ok, lack of vbulletin knowledge + only very basic php knowledge = fail :)

I have now changed my script.php file so that the output is now a function.
When i include the script.php in a simple php script like this it works. So no problem in the script.
<?php
require_once('script.php');
myfunction();
?>

Now let's include this not in the simple script but in a vbulletin page!

I have a page.php file and a matching template.
These i have created after reading this tutorial:
https://vborg.vbsupport.ru/showthread.php?t=228112

In the page.php file i include script.php after global.php
require_once('./global.php');
require_once('./script.php');

What i still don't understand is where i now have to put "myfunction();" to show the output in a vbulletin page.
In the template? In a plugin?

Thanks for your help! Really appreciated!


Schoelle

cric2k
03-01-2011, 03:59 PM
I'm using this and it works, only I want to pass a variable (GLOBALS.foruminfo.title_clean) from my template to my PHP script.

I am attempting to pass the current Forum title and with my own PHP generate CSS to have a specific image for that forum in the background.

My Plugin code:

ob_start();
$stringPath = "/var/www/vhosts/***/httpdocs/includes/getForumImage.php";
$PageTitle = $GLOBALS.foruminfo.title_clean;
require_once($stringPath);
$php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('headinclude',array('php_ include' => $php_include));


My problem is that $PageTitle = $GLOBALS.foruminfo.title_clean; doesn't populate in this place, I need to populate it in the template 'headinclude' any ideas?

--------------- Added 1299018239 at 1299018239 ---------------

figured it out, didnt have to use the global variable - just used foruminfo[title_clean] which worked instead.

drjamescook
03-05-2011, 06:43 PM
I am using this hack to include a few php pages as it is intended. Everything works great, other than I cannot get form submits to work. I get a "Your submission could not be processed because a security token was missing."

I've looked around on the forum trying to find an answer, but I can't seem to find one. How can I correct this? Thanks.

Baylyns
03-12-2011, 09:28 AM
Hello,

I'm on 4.1.2 and I used the code mentioned above to vb 4

ob_start();
include('/var/www/eo/www/dix_dernieres.php');
$includedphp_main = ob_get_contents();
ob_end_clean();

$preRegister['includedphp_main'] = $includedphp_main;
vB_Template:: PreRegister('navbar', $preRegister);

in the navbar template I added:

{vb:raw includedphp_main}

By activating the module, I get a blank page.
Or is the problem?

Thank you

nick_h
03-14-2011, 05:47 PM
Can i put a VB variable in that php file such as {vb:raw totalthreads} ? I tried but not sucess

BirdOPrey5
03-14-2011, 06:48 PM
Can i put a VB variable in that php file such as {vb:raw totalthreads} ? I tried but not sucess

In a plugin or php file it would be $totalthreads. The {vb:raw ...} is only for use when displaying contents in a template.

Muffin89
03-28-2011, 10:23 AM
I could also use some help on including php file into a template.

I have a template with an header, a navbar, the forum/content, footer and a fixed right bar. I wan't to insert this php code(for now) into the right bar:

userbox.php
<?php
echo '<a href="login.php?$session[sessionurl]do=logout&amp;logouthash=$bbuserinfo[logouthash]">Logga ut</a>';
?>

userbox plugin:
ob_start();
include('userbox.php');
$userboxinsert= ob_get_contents();
ob_end_clean();
vB_Template::preRegister('footer',array('php_inclu de' => $php_include));

Inside the footer template I have made a div that is fixed and I call the plugin with this code:
{vb:raw userboxinsert}

But it doesn't output my desired string.

The HOOK is parse_templates.

When i in the plugin write echo $userboxinsert; the userbox get's inserted but at the top of the screen, so the link works.

Would be very happy if someone could help me with this problem!

karlm
04-07-2011, 06:20 AM
Total programming n00b here... asking for help :)


I just came here find out how to get a php-script to run, and was really glad to see you guys already had a page on the issue.

My idea is fairly simple:

I picked up a rotator script (php) and will upload to it's own directory (/rotator). I intend to have several copies (e.g. games.php, religion.php, cars.php, gadgets.php) and each script points to a different sub-directory, e.g. /games, /religion, /cars, /gadgets, etc.)

From there, in the last post of every thread I want to call it but will use an IF THEN to dictate which version it calls.

(e.g. IF forum=12 then call cars.php, else if forum=15 then call gadgets.php)
<vb:if condition="$GLOBALS['forumid'] == 63 OR $GLOBALS['forumid'] == 54 OR $GLOBALS['forumid'] == 56">
[not sure what to put here in order to call 'games.php']
<vb:if>
<vb:if condition="$GLOBALS['forumid'] == 3">
[not sure what to put here to call 'cars.php']
<vb:if>

This in turn should then reflect relevant files for specific forum content.

I suspect the IF THEN will be placed in the template 'ad_thread_last_post_content' (or via the Advertising/Manage Ads script within ACP).

I'm uncertain what hook I could use for this (these would only show on SHOWTHREAD templates - or is postbit_legacy as it's only in the last post?). I will later be adding a similar function to the bottom of specific forums to show different rotator scripts (different sized affiliates).


Any chance of a bit advice for getting this off the ground?

BirdOPrey5
04-07-2011, 10:17 AM
When you say "call" do you mean "display"? Is cars.php a page you can view with content if you browse to it?

If so I think what you are looking for is an IFRAME... the basic syntax would be:

<IFRAME SRC="http://domain.com/rotator/cars/cars.php" WIDTH="100%" HEIGHT="50"></IFRAME>

That would embed the output from the php file into your existing page.

You can search google for more options on the IFRAME tag.

karlm
04-07-2011, 11:20 AM
Although an iframe would suffice (thanks, I hadn't even given it a thought), I was under the impression I could an external php file from within a template..?

I'd prefer to do it as a display/call than within an iframe (which would not show to some browsers).

In worst case scenario though, i'll go with an iframe. :)

BirdOPrey5
04-07-2011, 11:44 AM
I just don't know what you mean by "call" a php file then... You can't do that from a template. You could do it from a plugin but again you're not "calling" a file. You can call a function in a file, but if you want to display output from the php file in a specific location you need to make a template for that file.

karlm
04-07-2011, 08:10 PM
I just don't know what you mean by "call" a php file then... You can't do that from a template. You could do it from a plugin but again you're not "calling" a file. You can call a function in a file, but if you want to display output from the php file in a specific location you need to make a template for that file.
I may be using wrong terminology when i say "call"... I'm thinking old BASIC programming when you would call a subroutine.

Anyway, my idea is to:
1) breakdown forum into separate categories (e.g. religion, cars, games, etc.)

2) in the last post, 'refer to' a specific script.
2a) e.g. religion forum would refer to a script renamed as 'religion.php'
2b) cars forum would refer to a script renamed as 'cars.php'

3) the scripts within each above file would be the same, but refer to different text files.

4) the cars forum & script would then extract data from the text file for cars, which would ultimately show to the end-user as a affiliate image/link specific to cars.
4b) exactly the same as 4) but with religion context instead, so 'christian stuff' would show up in the religion forum (and other religions too).

so when a guest comes to my forum and visits the car section, they'll see links and/or images in the final post which will be pertinent to cars... if they swap over to the religion forum (or games or anything else) they will see the last post giving links/images relevant to those forums too.

BirdOPrey5
04-07-2011, 11:26 PM
What I'm not understanding is why you would make several different php files when you could do the same with a single plugin or really even just template conditionals?

Can you give an example of the HTML code you want displayed from a php file?

karlm
04-08-2011, 10:46 AM
OK, I'm doing it this way because I'm not a PHP guru... I'm doing it in a way I can understand.

So what I've done now is in the 'manage ads' area of the ACP, i've enabled a 'last post only' ad-spot.

While testing, it shows only to admins (once it goes live, i'll change this to show only to guests instead).

The content of this ad-code is:


<style type="text/css">
<!--
#adspot {
width: 358px;
height: 268px;
border: none;
}
-->
</style>

<table style="text-align: left; width: 100%;" border="0" cellpadding="4"
cellspacing="4">
<tbody>
<tr align="center">
<td style="vertical-align: middle; text-align: center;">

<!-- GAMETAP // UNDER 'PLAY ARCADE GAMES HERE' FORUM-->
<vb:if condition="$GLOBALS['forumid'] == 63 OR $GLOBALS['forumid'] == 54 OR $GLOBALS['forumid'] == 56">
<iframe src="/ads/gaming/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe>
</vb:if>


<!-- CHRISTIAN STORE random sizes // UNDER 'Religion & spirituality' FORUM-->
<vb:if condition="$GLOBALS['forumid'] == 3">
<iframe src="/ads/religion/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe>
</vb:if>


<!-- MUSIC STORE random sizes // UNDER 'music' FORUM-->
<vb:if condition="$GLOBALS['forumid'] == 52">
<iframe src="/ads/music/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe>
</vb:if>

<!-- SPORTS STORE random sizes // UNDER 'sports' FORUM-->
<vb:if condition="$GLOBALS['forumid'] == 55">
<iframe src="/ads/sports/rotate.php" frameborder="0" align="center" name="adspot" id="adspot" marginheight="0"><p>Your browser does not support iframes.</p></iframe>
</vb:if>
</td>
</tr>
<tr align="center">
<td style="vertical-align: top;"><small><small><span
style="font-weight: bold;">Please <a href="/register.php" target="_parent">register</a> or sign in to remove these
advertisements.</span></small></small><br>
</td>
</tr>
</tbody>
</table>


In each directory is a series of text files with affiliate codes and the rotator picks a random file each time a viewer reads a thread.

I'm sure I could somehow move the /rotate.php file into the parent directory and have it refer to different sub-directories according to what forumID is being viewed... I have no doubt that can be done.

But - I don't know how to. So I'm trying to keep things simple for myself.

BirdOPrey5
04-09-2011, 12:32 AM
Yeah I honestly can't see it getting any better than an IFRAME as you have it without making life A LOT for difficult.

In the unlikely event someone has a browser that doesn't allow IFRAMEs is there some static content you can put between the <IFRAME> and </IFRAME> tags besides "your browser does not support iframes" ? Maybe pick one of the codes you'll be randomizing so it's better than nothing?

karlm
04-10-2011, 01:07 PM
Just wanted to add, as I said previously, I'm not guru where coding is concerned... However, after a quick flick through the vbmanual, I've managed to condense my code using <vb:else if xyz /> statements and an additional <vb:else />. This means, now, it will check to see if viewer is in forum x,y,z and show appropriate php files - otherwise (if not in the above mentioned forums) it will show a google-adsense post instead.

WIN!

iwpg
04-17-2011, 05:02 AM
I am planning on getting my entire site converted to take adbantage VB 4. I have more than 50,000 pages, so basically, I cannot use the global_start hook, since I would have hundreds of files / scripts loading on every page. This would not be good...

I thought about using global_start with one product (php master file), and then using conditionals within the script to decide which file to load. But decided to wait until I get some advice on this. One thing I did notice: If you have a php file loaded with global_start, every VB page may or may not use those variables. For example, I created a PHP script that looked for the last 5 forum posts, used a variable called $threadid. It happens to be that $threadid is also used within VB. So the last threadid that was called within my custom script forced VB to use that variable! All links on the forum loaded my own script's variable $threadid. Is this normal behavior? I did change my variable name to something unique, but I'm getting a little paranoid about this, because I may have more than this variable that is also used by VB.

This is what I plan... Any feedback would be great.

Product Example:

ob_start();
include('Masterfile.php');
$masterfile = ob_get_contents();
ob_end_clean();

vB_Template::preRegister('customfiletemplate',arra y('loadexternalscripts' => $masterfile));

----------------------------------

Masterfile.php Example:

if ($_GET['file']=='aboutus'){
include_once "aboutus.html";
}
elseif ($_GET['file']=='otherpage'){
include_once "otherpage.php";
}

----------------------------------
Template:
{vb: raw loadexternalscripts}

The files would then be loaded like customfilepage.php?file=aboutus and Mod-rewrite would do the trick with bringing basic filenames to the request.

BirdOPrey5
04-17-2011, 03:42 PM
I'm pretty sure I've heard the global_start hook isn't called on CMS pages anyway. They were going to remove that hook but kept it to keep compatibility with older mods, but didn't add it to the "new" parts of VB4.

I really can't image trying to work on 50,000 pages... good luck with that.

But using the same variable names is a concern. Not only should you avoid the variable names used by vBulletin but also names other people have used in mods you have installed. When I make a mod I'll usually call my variables $bop_post or $bop_thread for example to know I'm not changing data used elsewhere.

iwpg
04-18-2011, 02:56 AM
Thanks for the info Joe, do you think the method that I plan would work? This way, only one hook is created and loaded, waiting for $_GET instructions to fire off scripts.

BirdOPrey5
04-18-2011, 03:25 AM
Thanks for the info Joe, do you think the method that I plan would work? This way, only one hook is created and loaded, waiting for $_GET instructions to fire off scripts.

I'm really not understanding what you are really doing... surely you don't plan to write a php elseif statement with 50,000 options... :confused:

iwpg
04-19-2011, 03:55 AM
I am using VB to include 1 PHP file that is open to requests. These requests load the appropriate files if that's the page being requested. So, this allows a hook to be placed in global_start without actually loading a script and consuming enormous amounts of system resources. The 50,000+ pages are generated from about 10 scripts/programs.

In other words, I am using this script as a hook on global_start with a custom template that has the vb raw variable.

This is my PHP code (Master.php). Seems to work very well so far.
<?php
global $fnuser,$fnuserid,$msxtotal;
$csl = $_GET['csl']; // Custom Script Location - Single Files with no directories. Mod rewrite on
if ($csl=='About-Us') {
require "C/about.shtml";
$fglink = "About Us";
$fgptitle = "About Our Business";
}
elseif ($csl=='Sitemap') {
require "C/sitemap.php";
$fglink = "Sitemap";
$fgptitle = "Website Sitemap";
}

mysql_select_db(vb);//Want to select back to VB database just in case another database was selected
?>

Included script on the hook (M.php):
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT', 'Master');
define('CSRF_PROTECTION', true);
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('CustomMaster',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');

// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######
$navbits = construct_navbits(array('' => $fglink));
$navbar = render_navbar_template($navbits);

$templater = vB_Template::create('CustomMaster');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $fgptitle);
$templater->register('sidebarext', $sidebarext);
$templater->register('sidebaropen', $sidebaropen);
print_output($templater->render());

?>


Mod-Rewrite Code:
RewriteRule ^C/([^/]+).php$ /FN/M.php?csl=$1 [QSA,L]

Then call it like M.php?csl=About-Us
Mod-Rewrite generates About-Us.php and you're done.

angelcosta
08-06-2011, 08:55 PM
Thank you so freakin much!

The file get contents worked!

absofts
12-23-2011, 09:09 AM
I include a file but its showing me this error

Fatal error: Call to a member function query_read_slave() on a non-object in /home/content/i/c/o/icompany/html/forum/verified.php on line 4

--------------- Added 1324635016 at 1324635016 ---------------

My file code is

<?php
require_once('includes/class_paid_subscription.php');

$susers = $db->query_read_slave("
SELECT *
FROM " . TABLE_PREFIX . "subscriptionlog
WHERE status = 1
AND userid = " . $vbulletin->userinfo['userid']
);
$isPremium = $db->num_rows($susers);
if ($isPremium != 0){
$st = '1';
}else{
$st = '0';
}
echo $st;

?>

iwpg
12-23-2011, 06:13 PM
I''m not sure where query_read_slave is loaded. Did you try loading the hook in global_start?

BirdOPrey5
12-23-2011, 06:17 PM
You should be using $vbulletin->db... to access queries, data, and the like... try this code:


<?php
global $vbulletin;

require_once('includes/class_paid_subscription.php');

$susers = $vbulletin->db->query_read_slave("
SELECT *
FROM " . TABLE_PREFIX . "subscriptionlog
WHERE status = 1
AND userid = " . $vbulletin->userinfo['userid']
);
$isPremium = $vbulletin->db->num_rows($susers);
if ($isPremium != 0){
$st = '1';
}else{
$st = '0';
}
echo $st;

?>

iiFragyyHD
03-18-2012, 09:30 PM
Can I add 2 plugins like this?

--------------- Added 1332106295 at 1332106295 ---------------

Nevermind, got it. All you have to do is change bot $php_include variables and the array name to the same thing.

zero477
03-21-2012, 02:05 AM
Thanks it works perfectly, they should update or make more clear the vBulletin manual...

--------------- Added 1332297428 at 1332297428 ---------------

Hello Crimm,

Thanks very much for your post about including PHP files ... It was much more clear than in the manual.

I followed your instructions and everything works fine for the forum, but in the CMS the PHP file is not included.

I tried to fix it by adding:

ob_start();
require_once('plugins/rightsidebar.php');
$php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('footer',array('php_inclu de' => $php_include));


To global_start of the CMS. But it still does not work... Can you help me?

zero477
06-26-2012, 03:18 PM
Hello,

If would like to use many PHP files on URL can we do something like:


ob_start();
require_once('LOCATION OF EXTERNAL FILE');
$php_include = ob_get_contents();

require_once('LOCATION OF EXTERNAL OF SECOND FILE');
$php_include_SECOND_FILE = ob_get_contents();

ob_end_clean();
vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));
vB_Template::preRegister('TEMPLATE YOU ARE USING FOR SECOND FILE',array('php_include' => $$php_include_SECOND_FILE));






??????????

kh99
06-26-2012, 05:21 PM
You should be able to do this (use ob_get_clean() instead of ob_get_contents()):

ob_start();
require_once('LOCATION OF EXTERNAL FILE');
$php_include = ob_get_clean();

require_once('LOCATION OF EXTERNAL OF SECOND FILE');
$php_include_SECOND_FILE = ob_get_clean();

ob_end_clean();
vB_Template::preRegister('TEMPLATE YOU ARE USING',array('php_include' => $php_include));
vB_Template::preRegister('TEMPLATE YOU ARE USING FOR SECOND FILE',array('php_include' => $$php_include_SECOND_FILE));



I think if you want you could also put a preRegister call after each call to ob_get_clean() so you wouldn't need a bunch of different variables.

RivaCom
06-29-2012, 07:54 PM
I've tried the following code. But whenever you click a user thread, no matter what thread you click, it always brings us to the same thread.

ob_start();
require_once('/home/ihatejob/revenantgaming.com/forum/modules/slidermodule.php');
$php_include = ob_get_clean();

ob_end_clean();
vB_Template::preRegister('adv_portal',array('php_i nclude' => $php_include));

any help?

zero477
06-29-2012, 08:11 PM
Hello guys,

I finally achieved it!! I did a small tutorial about making External PHP files that can be used as Widgets in vBulletin CMS.

I do not know if I can post links here ... but here is the tutorial ... I think someone might find it useful in the future.

http://www.hyperlinkbuilding.org/content/160-vBulletin-Widget-Tutorial

Greetings,
Eddie

--------------- Added 1341004474 at 1341004474 ---------------

I have to say something else ... Thanks a lot for trying helping me!! I will help others whenever I can.

hqlman
07-23-2012, 12:58 PM
I am helping a friend out to try and display his wordpress header above his vb forums header, im using the code below in the plugin and calling it in the header template:

ob_start();
require_once('http://al-hussain.co.uk/wp-
content/themes/Karma/header.php');
$php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('Test',array('php_include ' => $php_include));

but get the following errors:

Warning: require_once() [function.require-once]: http:// wrapper is disabled in the server configuration by allow_url_include=0 in [path]/includes/class_bootstrap.php(106) : eval()'d code on line 3

Warning: require_once(http://al-hussain.co.uk/wp- content/themes/Karma/header.php) [function.require-once]: failed to open stream: no suitable wrapper could be found in [path]/includes/class_bootstrap.php(106) : eval()'d code on line 3

Fatal error: require_once() [function.require]: Failed opening required 'http://al-hussain.co.uk/wp- content/themes/Karma/header.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/alhussai/public_html/forum/includes/class_bootstrap.php(106) : eval()'d code on line 3

Im running Wordpress 3.4.1 and vb 4.1.12, any ideas how to solve this?

zero477
07-23-2012, 03:11 PM
check your php.ini and server configurarion ... I think you cannot require_once an URL ....

hqlman
07-23-2012, 04:14 PM
Ive set allow_url_include=1 in php.ini now that gets rid of the first error, still the other two errors:


Warning: require_once(http://al-hussain.co.uk/wp- content/themes/Karma/header.php) [function.require-once]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in [path]/includes/class_bootstrap.php(106) : eval()'d code on line 3

Fatal error: require_once() [function.require]: Failed opening required 'http://al-hussain.co.uk/wp- content/themes/Karma/header.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/alhussai/public_html/forum/includes/class_bootstrap.php(106) : eval()'d code on line 3


Any ideas guys?

zero477
07-23-2012, 05:50 PM
Sorry, i have no idea... but i think it has to do with the streams or paths ...

BirdOPrey5
07-24-2012, 12:34 AM
You can't do a require_once on an http:// URL... you can only require (or include) on a local file on your server and it has to be by a local path.

hqlman
07-24-2012, 12:00 PM
You can't do a require_once on an http:// URL... you can only require (or include) on a local file on your server and it has to be by a local path.

Even with that as below im getting the exact same error messages:

ob_start();
require_once('/home/alhussai/public_html/wp-
content/themes/Karma/header.php');
$php_include = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('Test',array('php_include ' => $php_include));

I just dont want to have to copy the html and css manually into vbulletin :(

kh99
07-24-2012, 12:34 PM
I noticed in the error message above and in the one you posted on vbulletin.com that there's a space between wp- and content. It should be all one word, so maybe try taking out whatever character that is (so it reads require_once('/home/alhussai/public_html/wp-content/themes/Karma/header.php', all on one line).

hqlman
07-26-2012, 01:39 PM
Thanks for the reply the error seem to have gone and now its giving just this:

Fatal error: Call to undefined function language_attributes() in /home/alhussai/public_html/wp-content/themes/Karma/header.php on line 2

--------------- Added 1343317885 at 1343317885 ---------------

Removed language_attributes() from header.php now just a blank page now errors :/

kh99
07-26-2012, 05:43 PM
I think the header.php is depending on some Wordpress functions that you aren't including.

cultd3ad
12-29-2012, 10:22 AM
Hello,
am a new Owner of vb4.2 and would like to add an echo Script.
Unfortunately, this does not in the Templates, the Output will always appear at the top left.
What can I do? I use the Standart Style! Please help me..

I have add a Plugin:

ob_start();
include('/var/www/virtual/htdocs/echo.php');
return $back;
ob_end_clean();


and add this in a Template

{vb:raw back}

still not Work, all other Sample here in Forum not Work.

The same Script tested in the Customer Sidebar, thats Works fine ;)

kh99
12-29-2012, 02:05 PM
Try this:

ob_start();
include('/var/www/virtual/htdocs/echo.php');
echo $back;
$output = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('template',array('back' => $output));


but change 'template' to the name of the template where you want to include the output.


(you may not need the ob_get_contents(), but I'm not sure if the echo script creates any output other than the $back value).

cultd3ad
12-29-2012, 05:27 PM
Hi kh99,

thx to Replay and help me....

Your Info not Work! :(

I have a failure in the Config or ?
I use the php in the Sidebar Adden and this work fine! Why nothing Work in a Template? I have Read all howto and change some Codes, all not Work

acast
12-29-2012, 09:21 PM
Hi. I am having a problem, i registered two variables which are in the vbtrade_main template, and i want it to see it only in the php page vbtrade.php, but i see it in all pages! The forum also dissapears.

This is the code i put in the
Hook Location with global_bootstrap_init_start

ob_start();

require_once('vbtrade.php');
$stocktable = ob_get_contents();

ob_end_clean();

require_once('vbtrade.php');
$preview = ob_get_contents();

ob_end_clean();

vB_Template::preRegister('vbtrade_main',array('sto cktable' => $stocktable));

vB_Template::preRegister('vbtrade_main',array('pre view' => $preview));

What i am doing wrong?

Thanks for your help.

kh99
12-29-2012, 11:30 PM
Hi kh99,

thx to Replay and help me....

Your Info not Work! :(

I have a failure in the Config or ?
I use the php in the Sidebar Adden and this work fine! Why nothing Work in a Template? I have Read all howto and change some Codes, all not Work

I'm sorry, but I don't understand. I understand that what I posted didn't work, but I don't understand the rest. Did you put that code in a template? It shouldn't go in a template, it needs to go in a plugin.

kh99
12-29-2012, 11:33 PM
What i am doing wrong?

Thanks for your help.


It might only be that you're missing an ob_start() call. If you want to include two files separately, you would need to call ob_start() again after the first call to ob_end_clean().

acast
12-30-2012, 08:13 AM
It might only be that you're missing an ob_start() call. If you want to include two files separately, you would need to call ob_start() again after the first call to ob_end_clean().

Still the same with that modification:

ob_start();

require_once('vbtrade.php');
$stocktable = ob_get_contents();

ob_end_clean();

ob_start();

require_once('vbtrade.php');
$preview = ob_get_contents();

ob_end_clean();

vB_Template::preRegister('vbtrade_main',array('sto cktable' => $stocktable));

vB_Template::preRegister('vbtrade_main',array('pre view' => $preview));

It appears in all pages, and the forum dissapears.

The vbtrade_main template:

{vb:stylevar htmldoctype}
<html dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode} id="vbulletin_html">

<head>
<title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
<script type="text/javascript" src="clientscript/vbulletin_ajax_stocktrader.js"></script>
{vb:raw headinclude}

</head>
<body>
{vb:raw header}
{vb:raw navbar}
<br>

<div id="pagetitle">
<h1>{vb:raw pagetitle}</h1>
</div>

<vb:if condition="$stocktable != null">
{vb:raw stocktable}

<br>
</vb:if>

<!-- purchase preview -->
<vb:if condition="$preview != null">
{vb:raw preview}

<br>
</vb:if>
<!-- /purchase preview -->

<!-- stock lookup table -->
<form onsubmit="handle_stock_lookup(document.getElementById('lusym bol').value);return false;">
<table class='tborder' cellpadding='{vb:stylevar cellpadding}' cellspacing='{vb:stylevar cellspacing}' border='0' width='100%' align='center'>
<tr><td class='tcat' colspan=99>Get Stock Quote</td></tr>
<tr><td colspan=99 class=alt1><input type=text id='lusymbol' maxlength=10>&nbsp;<input class=button type=button onclick="handle_stock_lookup(document.getElementById('lusym bol').value);" value='Search'></td></tr>
</table>
</form>
<div id='lookup_table'></div>
<!-- /stock lookup table -->

<br>

<!-- buying table -->
<table class="tborder" cellpadding="{vb:stylevar cellpadding}" cellspacing="{vb:stylevar cellspacing}" border="0" width="100%" align="center">
<tr>
<td class="tcat" colspan=3>
<a name="options" style="float:{vb:stylevar right}" href="#top" onclick="return toggle_collapse('newpost_options')"><img id="collapseimg_newpost_options" src="{vb:stylevar imgdir_button}/collapse_tcat$vbcollapse['collapseimg_newpost_options'].gif}" alt="" border="0" /></a>
{vb:rawphrase ambst_buy}
</td>
</tr>

<tbody id="collapseobj_newpost_options" style="$vbcollapse['collapseobj_newpost_options']">
<form action="vbtrade.php?do=previewpurchase" method="post" name="purchaseform">
<tr valign="top" class=alt1>
<td>
<b>{vb:rawphrase ambst_cashonhand} </b> {vb:raw cashonhand}
</td>
<td colspan=2>
<vb:if condition="$vboptions['vbst_xchgrate']!=1">
<b>{vb:rawphrase ambst_usdonhand} </b>: \{vb:raw usdonhand}
</vb:if>
</td>
</tr>
<tr valign="top" class=alt2>
<td>
{vb:rawphrase ambst_symbol} &nbsp;<input type="text" class="bginput" name="symbol" size="10" maxlength="10"/>
</td>
<td>
{vb:rawphrase ambst_shares} &nbsp;<input type="text" class="bginput" name="shares" size="10" maxlength="10"/>
</td>
<td>
<input type="submit" class="button" name="sbutton" value="{vb:rawphrase ambst_previewpurchase} " accesskey="s" tabindex="1" />
</td>
</tr>
</form>
</tbody>
</table>
<!-- /buying table -->


{vb:raw footer}
</body>
</html>

kh99
12-30-2012, 12:27 PM
That looks right, but it may have to do with what's in the scripts you're trying to include. For instance if they call exit() or die(), then that may be why the forum is disappearing. (If vbtrade.php is a vbulletin "powered" page that calls print_output() at the end, that would also do it). If that's the case, then maybe you can use an iframe instead.

Also I just noticed that you're including the same file twice - even if it worked, you'd probably get the same output for both.

acast
12-30-2012, 12:35 PM
That looks right, but it may have to do with what's in the scripts you're trying to include. For instance if they call exit() or die(), then that may be why the forum is disappearing. (If vbtrade.php is a vbulletin "powered" page that calls print_output() at the end, that would also do it). If that's the case, then maybe you can use an iframe instead.

Also I just noticed that you're including the same file twice - even if it worked, you'd probably get the same output for both.

The same file twice where?

This is the end of the vbtrade.php
print_output($templater->render());

How can i use an iframe? Is a tutorial or something here? I never heard that.

Thanks for your answers!


EDIT: An iframe is a bbcode. Do you mean i don't have to put the code in a new plugin, but in the new bbcode? The same code i put in the plugin?

kh99
12-30-2012, 12:55 PM
The same file twice where?


Both of your 'require_once' lines have the same file name.


This is the end of the vbtrade.php
print_output($templater->render());

How can i use an iframe? Is a tutorial or something here? I never heard that.

iframe is an html tag (you don't need to create a bbocde to use one in a template).

To be honest I'm not sure what you're trying to do. It looks like you're trying to use the method in this article to include output from an external file (vbtrade.php), but you also have a template. What are you using that template for, and what output do you expect from vbtrade.php? And where are you trying to include it?

acast
12-30-2012, 01:06 PM
Both of your 'require_once' lines have the same file name.




iframe is an html tag (you don't need to create a bbocde to use one in a template).

To be honest I'm not sure what you're trying to do. It looks like you're trying to use the method in this article to include output from an external file (vbtrade.php), but you also have a template. What are you using that template for, and what output do you expect from vbtrade.php? And where are you trying to include it?

Ok, i'll explain, because perhaps i am wrong.

I am trying to make work a vb3 plugin in vb4, and i see in the template this lines:

<vb:if condition="[B]$stocktable != null">
{vb:raw stocktable}

<br>
</vb:if>

<!-- purchase preview -->
<vb:if condition="$preview != null">
{vb:raw preview}

<br>
</vb:if>

And i read that in vb4 you have to register the variables to make it work, so i thought that i have to register the variables stocktable and preview to make it work. Am i wrong?

kh99
12-30-2012, 01:16 PM
And i read that in vb4 you have to register the variables to make it work, so i thought that i have to register the variables stocktable and preview to make it work. Am i wrong?


So far that all looks OK. Edit: but I guess the issue is, where are those variables coming from?

acast
12-30-2012, 01:24 PM
So far that all looks OK.So, i have to make a plugin to register those two variables or what? I am little bit missing right now.

kh99
12-30-2012, 01:26 PM
Well, right, you'd have to do that in php, which means a plugin or modifying a script. But the issue seems to be where those variables are coming from. The code you posted looks like you're trying to capture the entire output of vbtrade.php into each of those variables, which won't work. But I'm not sure what to tell you to do instead of that.

Edit: I'm thinking now that you don't need this "include external files" thing at all. If you're trying to modify vbtrade.php to work with vb4, then you probably want to edit that script and change the way the templates are rendered.

acast
12-30-2012, 03:02 PM
Well, right, you'd have to do that in php, which means a plugin or modifying a script. But the issue seems to be where those variables are coming from. The code you posted looks like you're trying to capture the entire output of vbtrade.php into each of those variables, which won't work. But I'm not sure what to tell you to do instead of that.

Edit: I'm thinking now that you don't need this "include external files" thing at all. If you're trying to modify vbtrade.php to work with vb4, then you probably want to edit that script and change the way the templates are rendered.

You mean the end of my vbtrade.php?

$templater = vB_Template::create('forumdisplay_sortarrow');
$templater->register_page_templates();
$templater = vB_Template::create('vbtrade_main');
$templater->register_page_templates();
$templater->register('pagetitle', $pagetitle);
$templater->register('alt', $alt);
$templater->register('stocktable', $stocktable);
$templater->register('preview', $preview);



print_output($templater->render());


How can i change the way the templates are rendered?

kh99
12-30-2012, 03:10 PM
OK, that's already written for vb4, so it doesn't need to be changed. Sorry, I probably just misunderstood what you're trying to do.

You said you're trying to modify a vb3 plugin for vb4, so you were right, if it involved using variables in a template, you might have to register them. Is your vb3 plugin code calling fetch_template() then eval()?

Edit: OK, I just noticed that the code you posted above from vbtrade.php is rendering the vbtrade_main template and already registers $stocktable and $preview, so I'm lost. What does the plugin do?

acast
01-09-2013, 12:28 PM
OK, that's already written for vb4, so it doesn't need to be changed. Sorry, I probably just misunderstood what you're trying to do.

You said you're trying to modify a vb3 plugin for vb4, so you were right, if it involved using variables in a template, you might have to register them. Is your vb3 plugin code calling fetch_template() then eval()?

Edit: OK, I just noticed that the code you posted above from vbtrade.php is rendering the vbtrade_main template and already registers $stocktable and $preview, so I'm lost. What does the plugin do?

Sorry for asking again, friend, but i'm still working on this, and there is no way. I still don't understand if i have to register in plugins, the variables that appear in the "if" in the templates, or if it will work because there are registered in the php.

TheSupportForum
05-04-2013, 03:14 PM
is there anyway to get this to work in an Iframe

i try

<iframe src="{vb:raw perm}" width="530" height="600" frameBorder="0" class="leftColumn"></iframe>and the page ends up blank and not including it

this is the plugin i use

ob_start();
require_once('url/perm/perm.php');
$perm = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('citizens',array('perm' => $perm));

BirdOPrey5
05-06-2013, 12:19 AM
If what you want is the output of $perm in the iframe simply make the iframe src="url/perm/perm.php"

TheSupportForum
05-06-2013, 07:42 AM
If what you want is the output of $perm in the iframe simply make the iframe src="url/perm/perm.php"

thats what i am having to do right now, its easy to include perm.php as a {vb:raw perm} once i setup a plugin to include it in 1 template but i have no idea why i can't just use

<iframe src="{vb:raw perm}" width="530" height="600" frameBorder="0" class="leftColumn"></iframe>
<iframe src="{vb:raw temp}" width="530" height="600" frameBorder="0" class="leftColumn"></iframe>


which is the ideal scenario i want as both these files connect to tables in phpmysql

BirdOPrey5
05-06-2013, 09:30 AM
From the code you posted above, $perm = ob_get_contents();

That means $perm is the contents of the output buffer or the output (presumably) of the perm.php page. NOT a URL.

But the iframe SRC is looking for a URL ONLY. You can't put iframe content in the src= attribute.

Actually, it appears HTML5 does allow you to specify the code in the iframe but it uses the srcdoc attribute - http://www.w3schools.com/tags/tag_iframe.asp

Impromptu
12-18-2013, 03:37 AM
Hi there,

For some reason I can include the PHP file, but my header and navbar goes funny.

I know it's the plugin in as when I turn the plugin off, the header and navbar works fine. The header and navbar works fine, but it changes to:

My navbar/headers are #vbtab_form# $tab_mdu1_245 and #vbflink_pms# #vbmenu_community# and I'm missing some of my footer menu links.

Very odd that it works but my css stuffs up.

Thank you for your help.

Cheers

emits
12-06-2014, 05:12 PM
Can someone help me ? When I run plugins everywhere are white pages...

kh99
12-06-2014, 07:14 PM
Can someone help me ? When I run plugins everywhere are white pages...

It's hard to say without seeing exactly what you're doing, but it sounds like there's an error in the plugin you're trying to run. Have you checked the error logs (if you have them available)?

emits
12-09-2014, 08:26 AM
I have msg

Warning: require_once(/szatek/vb/nowosci.php): failed to open stream: No such file or directory in ..../includes/class_bootstrap.php(103) : eval()'d code on line 2
Fatal error: require_once(): Failed opening required '/szatek/vb/nowosci.php' (include_path='.:/usr/local/lib/php') in /home/p2y/domains/p2y.eu/public_html/szatek/vb/includes/class_bootstrap.php(103) : eval()'d code on line 2

Crimm
12-10-2014, 12:23 PM
I have msg

Warning: require_once(/szatek/vb/nowosci.php): failed to open stream: No such file or directory in ..../includes/class_bootstrap.php(103) : eval()'d code on line 2
Fatal error: require_once(): Failed opening required '/szatek/vb/nowosci.php' (include_path='.:/usr/local/lib/php') in /home/p2y/domains/p2y.eu/public_html/szatek/vb/includes/class_bootstrap.php(103) : eval()'d code on line 2

It appears this file is missing or doesn't have the correct permissions: /szatek/vb/nowosci.php

Thr33
03-19-2017, 09:41 AM
Ive tried all the suggestions in all 8 pages and im still not getting an output at all, even when using and ECHO message. Any suggestions?

Product: vBulletin
Hook Location: global_bootstrap_init_start
Title: Shoucast Stats
Execution Order: 1
ob_start();
require_once('http://literecords.com/user/s/stats.php');
$scstats = ob_get_contents();
ob_end_clean();
echo "PLUGIN WORKS: "
vB_Template::preRegister('FORUMHOME',array('scstat s' => $scstats));

In template: FORUMHOME
{vb:raw header}
{vb:raw navbar}
{vb:raw scstats}
<div>

The file exists and shows output but no via the plugin.

Mattwhf
06-18-2017, 07:57 AM
This way can affect to the loading of web page?