MoFish |
06-02-2006 03:27 PM |
Help With Creating A Thread Please
hello, im wondering if anyone can point me in the right direction. im trying to create a page with a form. Once the user clicks the submit button on the form I want it to create a new thread in a specified area of my forum. I am running into trouble creating this script using some code I found lieing about the forum.
Is this the correct way to do things? because im getting an error "Parse error: parse error, unexpected $end"
here is the code im trying go get working.
Code:
<?php
// ############################## NOTES #################################
/**
* NOTE: user permissions are not checked in this example script and guest
* posting is allowed by default. Set the full path to your main forum
* directory, FTP to wherever, and call this script from your browser to
* test it out. Read the code for further details.
*/
// ########################### CONFIGURATION #############################
// set the full path to your main forum directory
define('FWD','H:\wamp\www\Forum');
// #################### PRE-CACHE TEMPLATES AND DATA #####################
$phrasegroups = array('cpglobal');
// ######################### REQUIRE BACK-END ############################
define('BWD', (($getcwd = getcwd()) ? $getcwd : '.'));
chdir(FWD);
require_once('./global.php');
chdir(BWD);
// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################
// use the default function parameters
//create_new_thread();
if (!isset($_POST['submit'])){
?>
<form name="form1" method="post" action="create_new_thread.php">
<input type="submit" name="submit" value="submit">
</form>
<?
}else{
// alternatively set the function parameters
$title = 'Hello There';
$message = 'Alternative Message';
$id = 4;
$guest = true;
create_new_thread($title, $message, $id, $guest);
}
// ###################### Start create_new_thread ########################
/**
* Creates new thread or gives error and then redirects user
*
* @param string Title of thread
* @param string Message of post
* @param integer ForumID for thread
* @param boolean Allow guest posts
*/
function create_new_thread($title = 'Default Title', $message = 'Default Message', $id = 2, $guest = true)
{
// set some globals
global $forumperms, $vbulletin, $vbphrase;
// init some variables
$fail = 0;
$errors = array();
$newpost = array();
// init post information
if ($guest AND $vbulletin->userinfo['userid'] == 0)
{
$newpost['username'] = $vbphrase['guest'];
}
$newpost['title'] = $title;
$newpost['message'] = $message;
$newpost['signature'] = '0';
if ($vbulletin->userinfo['signature'] != '')
{
$newpost['signature'] = '1';
}
$newpost['parseurl'] = '1';
$newpost['emailupdate'] = '9999';
// attempt thread create
$foruminfo = verify_id('forum', $id, 0, 1);
if (!$foruminfo['forumid'])
{
$fail = 1;
}
$forumperms = fetch_permissions($foruminfo['forumid']);
if (!function_exists('build_new_post'))
{
require_once(DIR . '/includes/functions_newpost.php');
}
build_new_post('thread', $foruminfo, array(), array(), $newpost, $errors);
if (sizeof($errors) > 0)
{
$fail = 1;
}
// do redirection
if (!$fail)
{
$vbulletin->url = $vbulletin->options['bburl'] . '/showthread.php?' . $vbulletin->session->vars['sessionurl'] . "p=".$newpost['postid']."#post".$newpost['postid'];
eval(print_standard_redirect('redirect_postthanks'));
}
else
{
$vbulletin->url = $vbulletin->options['bburl'];
eval(print_standard_redirect($vbphrase['error'].': '.$vbphrase['redirecting'],0,1));
}
}
?>
|