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 05-08-2011, 12:43 AM
EWGF EWGF is offline
 
Join Date: May 2007
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How to use compile_template function?

I want to parse conditions with a custom databasetable, so according to vb.com I need to use the compile_template() function.

Code:
/**
* Processes a raw template for conditionals, phrases etc into PHP code for eval()
*
* @param	string	Template
*
* @return	string
*/
function compile_template($template, &$errors = array())
Besides including adminfunctions_template.php, I have NO idea how to use this in a .php file. Does anyone here know how to use this function?
Reply With Quote
  #2  
Old 05-08-2011, 12:45 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I do on vb 4.
Reply With Quote
  #3  
Old 05-09-2011, 12:15 PM
EWGF EWGF is offline
 
Join Date: May 2007
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've looked through some mods here on vb.org. Is it true you can only parse specific specified condition codes and not the template where you want to parse every possible code?
Reply With Quote
  #4  
Old 05-09-2011, 12:30 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure what you're asking. There is a set of php functions that you are allowed to use in an if condtion, if that's what you mean. Are you saying you want to compile a template without that restriction?
Reply With Quote
  #5  
Old 05-09-2011, 01:48 PM
EWGF EWGF is offline
 
Join Date: May 2007
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes. I have made a simple cms -for outside the forum directory- with some custom tables, but the content in those custom tables can't use conditions and other php functions (the codes show up unparsed in the HTML output). According to vb.com I need to use the compile_template() function for this to work and I'm having trouble to get this function working.

Database content:
PHP Code:
<if condition="$show[member]">Not viewable for guests</if> 
HTML output getting unparsed:
PHP Code:
<if condition="$show[member]">Not viewable for guests</if> 
Reply With Quote
  #6  
Old 05-09-2011, 02:11 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I did this short test by creating a plugin using hook misc_start:

Code:
if ($_REQUEST['do'] == 'compile')
{
    require_once("includes/adminfunctions_template.php");
    $template = '<if condition="$show[member]">Not viewable for guests</if>';
    echo compile_template($template);
    exit;
}

and the result is:

Code:
".(($show[member]) ? ("Not viewable for guests") : (""))."

so it seems like it's working, although I'm not sure how you're supposed to deal with the dots at the beginning and end, I guess when the function is used there are other strings added to the beginning and end.

Anyway, are you using the return value of compile_template()? I don't think it changes the parameter you pass.
Reply With Quote
  #7  
Old 05-09-2011, 09:12 PM
EWGF EWGF is offline
 
Join Date: May 2007
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yes. I also tried echoing and evaling the db->query or the template name.

But seeing your short test, it's not possible to process the custom db as a vBulletin template? If not, I might be able to wrap it up with some custom templates.
Reply With Quote
  #8  
Old 05-09-2011, 09:24 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry, I don't really understand what you are asking.

But in case it helps, I played with it a little more and got this:

Code:
if ($_REQUEST['do'] == 'compile')
{
    require_once("includes/adminfunctions_template.php");
    $show[member] = true;
    $template = '<if condition="$show[member]">Not viewable for guests</if>';
    eval ('$output = "' . compile_template($template) . '";');
    echo $output;
    exit;
}

and the output is

Code:
Not viewable for guests

but maybe this has nothing to do with your problem.
Reply With Quote
  #9  
Old 05-09-2011, 09:38 PM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Take a look at this mod. Bob uses compile_template for search and replace.

https://vborg.vbsupport.ru/misc.php?...mcategoryicons
Reply With Quote
  #10  
Old 05-11-2011, 05:57 PM
EWGF EWGF is offline
 
Join Date: May 2007
Posts: 183
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, I will look in it
Quote:
Originally Posted by kh99 View Post
Sorry, I don't really understand what you are asking.

But in case it helps, I played with it a little more and got this:

Code:
if ($_REQUEST['do'] == 'compile')
{
    require_once("includes/adminfunctions_template.php");
    $show[member] = true;
    $template = '<if condition="$show[member]">Not viewable for guests</if>';
    eval ('$output = "' . compile_template($template) . '";');
    echo $output;
    exit;
}

and the output is

Code:
Not viewable for guests

but maybe this has nothing to do with your problem.
I tested it too, it doesn't work correct with an else statement though

PHP Code:
<if condition="$show[member]">Not viewable for guests<else />Not viewable for members</if> 
HTML Code:
Not viewable for guestsNot viewable for members
I'm afraid there's no way in parsing a custom made database table as if it were a vB template
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 03:16 AM.


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.07097 seconds
  • Memory Usage 2,264KB
  • Queries Executed 13 (?)
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
  • (7)bbcode_code
  • (1)bbcode_html
  • (3)bbcode_php
  • (1)bbcode_quote
  • (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
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (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_postinfo_query
  • fetch_postinfo
  • 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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete