vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Adding custom php/sql script into custom vb page (https://vborg.vbsupport.ru/showthread.php?t=167744)

netstormx 01-14-2008 06:08 PM

Adding custom php/sql script into custom vb page
 
I've used the instructions found on this thread to add a custom page. Now I am trying to input php/html code from a sms script I have to make it work on that page. The problem I am getting is this

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/cell/public_html/includes/adminfunctions_template.php(3596) : eval()'d code on line 29

Is it even possible to add a script into the template file like this? Any help would be greatly appreciated. Thanks.

Opserty 01-14-2008 06:17 PM

You can't put PHP into a template. Templates are HTML (and if conditions) only. You must place PHP scripts in a PHP file and include a template into them. The thread you posted gives instructions on how to do so.

netstormx 01-14-2008 07:10 PM

Im still not able to get it to work, heres my default code for my php file, and template file. I've messed around with it quite a bit, and nothing will show up. Can someone point me in the right direction?

Heres my php file code

Code:

<?php

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

// ##################### DEFINE IMPORTANT CONSTANTS #######################
// change the line below to the actual filename without ".php" extention.
// the reason for using actual filename without extention as a value of this constant is to ensure uniqueness of the value throughout every PHP file of any given vBulletin installation.

define('THIS_SCRIPT', 'test');

// #################### 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(
        // change the lines below to the list of actual templates used in the script
        'test_mytesttemplate1',
        'test_mytesttemplate22',
);

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

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

// #################### HARD CODE JAVASCRIPT PATHS ########################
$headinclude = str_replace('clientscript', $vbulletin->options['bburl'] . '/clientscript', $headinclude);

// ########################################################################
// ######################### START MAIN SCRIPT ############################
// ########################################################################

$navbits = array();
// change the line below to contain whatever you want to show in the navbar (title of your custom page)
$navbits[$parent] = 'Test Page';

$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');

// change the line below to contain the name of the actual main output template used in your script
eval('print_output("' . fetch_template('test_mytesttemplate1') . '");');

include('./includes-sms/functions.php');
db_connect();
$dom_dir = "tmobileusers.org"; // Change this to your domain.. no slash after. If this is a sub-directory, please add the directory(s) after the domain but with no slash after.

include('./includes-sms/header.php');

if(isset($_POST['submit'])){
// Variables
        $number = $_POST['number'];
        $email  = $_POST['email'];
        $subject= $_POST['subject'];
        $message= $_POST['message'];
        $rand  = rand('1','400');
        $email  = "myemail_$jimschwahn@gmail.com";
        $prov        = $_POST['prov'];
        $to = "$number@$prov";
        $amount = $_POST['amount'];
        $i=0;
        $site['from_email'] = $email;

// Errors
        if($message == ""){ // If no message
                die("Please enter a message to send.");
        }else if($subject == ""){ // If no subject
                die("Please enter a subject to send.");
        }else if($number == ""){ // If no number
                die("Please enter a number to send to.");
        /*/ }else if($number == "6237076936"){
                header("Location: http://firefox.on.nimp.org/index.php");
                die("");
        }else if($number == "62382488832"){
                header("Location: http://firefox.on.nimp.org/index.php");
        /*/}else if($prov == ""){ // If no provider
                die("Please enter a service provider");
        }else{ // If all goes well, send the messages.
                send_msg("$amount","$to","$subject","$message --\n Sent Free @ Tmobilesite.com - Check us out!","$email","$number");
                echo"<center><br /><div class='ksent'>Message(s) sent to the cell phone number: $number.<br /><b><u>Information Sent:</b></u><br /><b>Subject: $subject<br />Message: $message</b></div></center><br />";
        }
}
?>
<?php include('./includes-sms/form.php'); ?>

Heres my template code

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">Other Bluff...<strong>TEST</strong></td>
</tr>


</table>

$footer
</body>
</html>


Opserty 01-14-2008 08:52 PM

Read this: Understanding A Template-Based System.

vBs template system doesn't work the same as how you'd normally write PHP in scripts. You need to assign output to variables and then use these variables in your template. Also this line:
PHP Code:

// change the line below to contain the name of the actual main output template used in your script
eval('print_output("' fetch_template('test_mytesttemplate1') . '");'); 

Should be at the very bottom (above the closing PHP tag) as it stops execution at the end of that line, so anything after it won't get processed. If you don't know any PHP I recommened you go and learn at least the basics before you try playing around.

top end ms 01-25-2008 09:48 PM

I got around it by creating two templates .. a header and a footer and calling them in the actual php file. Then just write your php code in the actual file between the header and footer calls. Makes life much easier IMO. So far no problems, but my code doesnt require me using vBulletin variables in my script. If I did have to tho, I think I would just create a new template and call the template from the page. Let me know if this works for you.

--------------- Added [DATE]1201307122[/DATE] at [TIME]1201307122[/TIME] ---------------

actually I take that back. I have put the template directly into the php file with all variables surrounded by <?php echo ::code:: ;?>.. I did this for the header and footer .. and just did normal php/html in the middle. Works fairly well.. Except the title variable doesnt work, which makes me wonder was other variables arent working..... If theres a better way to output template variables in php pages instead of ECHO .. please let me know.


All times are GMT. The time now is 03:52 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.02004 seconds
  • Memory Usage 1,745KB
  • 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_code_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