PDA

View Full Version : code to post a thread


renlok
12-10-2009, 10:06 PM
im building a mod and one of the features i need is for it to automatically make threads but i cant seem to get it to work this the code ive got atm ive taken it from the newthread.php file but it doesnt work or give me any information as to why.

$result = $db->query_read_slave(
"SELECT * FROM " . TABLE_PREFIX . "mods WHERE id = " . intval($_REQUEST['id']));

$mod = $db->fetch_array($result);

// set arrays
$foruminfo = array();
$newpost = array();
$errors = array();
require_once(DIR . '/includes/functions_newpost.php');
//...
$foruminfo['forumid'] = 2;
$newpost['message'] = ' . ']Link to mod (http://localhost:8888/forum/mods.php?do=view&id=' . $mod['id')
' . $mod['description'];
$newpost['title'] = $mod['title'];
$newpost['username'] = $mod['username'];
$newpost['poststarttime'] = time();
$newpost['rating'] = 0;
// trick it
$tmp_id = $vbulletin->userinfo['userid'];
$vbulletin->userinfo['userid'] = $mod['userid'];
build_new_post('thread', $foruminfo, array(), array(), $newpost, $errors);
$vbulletin->userinfo['userid'] = $tmp_id;
print_r($errors);

anyone got any ideas? :)

renlok
12-13-2009, 01:50 AM
ok it sort of works now . now atleast something happens but it returns
That username is already in use or does not meet the administrator's standards. If you are racken and you have forgotten your password, click here.

in the error parameter which doesnt make any sense surly that would be a registration error?

Lynne
12-13-2009, 03:04 AM
I don't know exactly what you are trying to do, but I am guessing the problem lies where you are reassigning the userid. That is the area I would be looking into.

And what does this mean - "If you are racken and" - racken?

renlok
12-13-2009, 11:18 AM
because the thread im trying to create i want to be posted under a different user so that user can edit it so if i run that script logged into an account renlok i was trying to make a thread posted by racken

Lynne
12-13-2009, 02:19 PM
I understand that. What I'm saying is that it seems to me that that is the area that has problems so that is the area I would focus on. Try posting the thread without switching the userid - does it work then? How about manually putting in a userid - like '5' (use a valid userid) - does it work then? Typical debug stuff to do.

renlok
12-14-2009, 12:14 PM
finally got it to work :D
thanks

BBR-APBT
12-14-2009, 12:23 PM
Do you want a new thread or a new post? It looks to me like you are using a new post method for a new thread.

You should be using the datamanager built in to vbulletin to post threads.

My suggestion would be to go and download my Welcome Thread mod and look how I did it.
https://vborg.vbsupport.ru/showthread.php?t=229473

Lynne
12-14-2009, 01:56 PM
finally got it to work :D
thanks
Out of curiosity, what was the problem?

renlok
12-14-2009, 04:21 PM
it was trying to set the userid as 0 so it was trying to make the post as a guest which was why i was getting that error message. but it works now apart from it times out after making the post which is annoying but i dont mind.