PDA

View Full Version : Adding custom php/sql script into custom vb page


netstormx
01-14-2008, 06:08 PM
I've used the instructions found on this thread (https://vborg.vbsupport.ru/showthread.php?t=98009) 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

<?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

$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 (https://vborg.vbsupport.ru/showthread.php?t=124576).

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:

// 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 1201307122 at 1201307122 ---------------

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.