vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   How to include PHP in a template via Plugins (https://vborg.vbsupport.ru/showthread.php?t=288141)

CoffeeLovesYou 09-22-2012 12:37 AM

How to include PHP in a template via Plugins
 
Hi,
Currently, I have this.

PHP Code:

ob_start();
   include(
'table.php');
   
$includedphp ob_get_contents();
ob_end_clean(); 

and in my template, it has $includedphp to call the PHP file over.

How can I - instead of using table.php, put the PHP code that is already IN table.php in the actual plugin and still use $includedphp in the template? If someone gets the link to table.php, they will be able to see info I don't want them to see -- the table.php is literally just PHP/MySQL table code, I have it calling it to a template to look nicer and in the template, I have it so only Staff usergroup ids can see it, but I can't make it that way for the table.php, since it isn't part of vBulletin. Hope this was clear. Just trying to put the PHP code inside of the Plugin instead of using include('table.php')

Lynne 09-22-2012 01:52 AM

Have you tried just copying it into the plugin?

CoffeeLovesYou 09-22-2012 01:32 PM

Yes but I'm not sure where to put it.
For example, would it be..

PHP Code:

ob_start();
   include(
'my
php
code
here'
);
   
$includedphp ob_get_contents();
ob_end_clean(); 

or would it be like..
PHP Code:

ob_start();
my
php
code
here
   $includedphp 
ob_get_contents();
ob_end_clean(); 

Can you help me as to where to place it?

Lynne 09-22-2012 02:40 PM

All you would need is:

PHP Code:

php code here 


CoffeeLovesYou 09-22-2012 03:17 PM

how would I attach that to my template, then?

kh99 09-22-2012 04:15 PM

I think it's the second example you posted above, since the code in table.php probably outputs html and you'd still need to capture it, unless you rewrite the code so that the output is saved in a string.

CoffeeLovesYou 09-22-2012 07:48 PM

I've tried the second example, but I get thrown a compile_template error all over my forum.
I have tried putting the actual PHP code in the template, doesn't work. I have tried including the php file in the plugin then calling it in the template with $includedphp but if someone got the link to the php file in the plugin, they could see the form that only staff are supposed to see. I don't want that.

kh99 09-22-2012 09:34 PM

OK, if this works:
Code:

ob_start();
  include('table.php');
  $includedphp = ob_get_contents();
ob_end_clean();


Then you should be able to do this:
Code:

ob_start();
  // code from table.php here
  $includedphp = ob_get_contents();
ob_end_clean();


but you have to remove <?php from the begininng, and ?> from the end (if it's there).


If what you're saying is that you're worried about someone going directly to table.php, then you could put a check at the beginning of table.php (after the <?php) like:
Code:

if (!defined('THIS_SCRIPT')) die("permission denied.");

CoffeeLovesYou 09-23-2012 03:51 AM

I get this when I try to put the code instead of including the PHP file

Fatal error: Call to undefined function compile_template() in my root forums/global.php(607) : eval()'d code on line 651

The plugin hook is global_start

kh99 09-23-2012 10:37 AM

Hmm...the error looks like the code in table.php is trying to use the function compile_template() and isn't finding it, but I don't see why moving the code from table.php to the plugin would do that. It seems like you should be getting the same error if you include the file like you show in the first post. Also, I'm curious what the code is doing where it would need to call compile_template() - that seems a little strange for a plugin using global_start. That's really an adminCP function (unless it's trying to call a non-vbulletin function of the same name).


All times are GMT. The time now is 03:55 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.01293 seconds
  • Memory Usage 1,735KB
  • 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
  • (3)bbcode_code_printable
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete