vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3 Articles (https://vborg.vbsupport.ru/forumdisplay.php?f=187)
-   -   [How-To] Use Template Conditional in any Script (https://vborg.vbsupport.ru/showthread.php?t=148706)

harmor19 06-01-2007 10:00 PM

[How-To] Use Template Conditional in any Script
 
1 Attachment(s)
This tutorial will show you how to return data from a column you've created and parse template conditionals.

PHP Code:

<?php

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

// ##################### DEFINE IMPORTANT CONSTANTS #######################
define('THIS_SCRIPT''my_script'); 

// #################### 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();

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

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

//You must include this in order to parse HTML based conditionals 
require_once(DIR '/includes/adminfunctions_template.php');
// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

//First we need to query the table.
$sql $db->query_first("SELECT * FROM " TABLE_PREFIX "my_table WHERE column = 'X' ");

//Now we need to convert the HTML based conditionals to PHP based 
eval('$done = "' compile_template($sql['my_field']) . '" ;');

//Print the results to the screen
eval('print_output("' fetch_template('my template') . '");');

?>



For sake of this article let's say "$sql['my_field']" contains the following
HTML Code:

<if condition="is_member_of($bbuseruserinfo, 12)">
To access the arcade click on "Links" to access the menu.<br />
Within the menu choose "Arcade".
<else />
<if condition="!is_member_of($bbuseruserinfo, 12)">
To access the arcade you need a minimum of 1000 posts. Currently you only have $bbuserinfo[posts]
</if>
</if>




You'll need to take the variable "$done" and place it in "my_template".
HTML Code:

$stylevar[htmldoctype]
<html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
<head>
$headinclude
<title>$vboptions[bbtitle]</title>
</head>
<body>

$header
$navbar

<table class="tborder" cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" border="0" width="100%"

align="center">

<tr>
<td class="tcat">My Custom Page Title</td>
</tr>
<tr>
<td class="alt1">$done</td>
</tr>
</table>

$footer
</body>
</html>


View the attachment to see what the end result.


I have tested the security and it returns dangerous code as plain text. This means that no one can perform mischievous actions towards your forums.

Princeton 06-02-2007 03:11 PM

Can you explain in detail WHY you would want to create such a tool?

Many members won't understand; therefore, limiting the help that you are trying to achieve.

harmor19 06-02-2007 04:57 PM

I'm sorry Princeton but I'm not good at explaining how stuff works.

Antivirus 06-03-2007 04:59 PM

I would have never thought of using a template conditinal in that manner, very interesting. Thanks!

RedTyger 07-25-2007 10:52 AM

I had no idea this could be done, which is ridiculous since it's perfectly obvious now it's been pointed out. Thank you, I've made good use of it.


All times are GMT. The time now is 08:48 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.01136 seconds
  • Memory Usage 1,729KB
  • 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
  • (2)bbcode_html_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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