Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-22-2012, 12:37 AM
CoffeeLovesYou CoffeeLovesYou is offline
 
Join Date: Feb 2010
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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')
Reply With Quote
  #2  
Old 09-22-2012, 01:52 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you tried just copying it into the plugin?
Reply With Quote
Благодарность от:
CoffeeLovesYou
  #3  
Old 09-22-2012, 01:32 PM
CoffeeLovesYou CoffeeLovesYou is offline
 
Join Date: Feb 2010
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #4  
Old 09-22-2012, 02:40 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

All you would need is:

PHP Code:
php code here 
Reply With Quote
  #5  
Old 09-22-2012, 03:17 PM
CoffeeLovesYou CoffeeLovesYou is offline
 
Join Date: Feb 2010
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

how would I attach that to my template, then?
Reply With Quote
  #6  
Old 09-22-2012, 04:15 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 09-22-2012, 07:48 PM
CoffeeLovesYou CoffeeLovesYou is offline
 
Join Date: Feb 2010
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 09-22-2012, 09:34 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.");
Reply With Quote
  #9  
Old 09-23-2012, 03:51 AM
CoffeeLovesYou CoffeeLovesYou is offline
 
Join Date: Feb 2010
Posts: 176
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #10  
Old 09-23-2012, 10:37 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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).
Reply With Quote
Reply


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

Forum Jump


All times are GMT. The time now is 11:22 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04462 seconds
  • Memory Usage 2,262KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete