PDA

View Full Version : Create Posts


fly
07 Dec 2005, 13:46
require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_threadpost.php');

$postdm = new vB_DataManager_Post($vbulletin, ERRTYPE_STANDARD);

$postthreadid = '4473';
$postusername = 'admin';
// Use $postusername if posting as a guest, use $postuserid if posting as a user
//$postuserid = '1';
$postpagetext = 'Hi mom!';

$threadinfo = fetch_threadinfo($postthreadid);
$foruminfo = fetch_foruminfo($threadinfo['forumid']);

$postdm->set_info('forum', $foruminfo);
$postdm->set_info('thread', $threadinfo);
$postdm->set('threadid', $postthreadid);
$postdm->set('username', $postusername);
// Use $postusername if posting as a guest, use $postuserid if posting as a user
//$postdm->set('userid', $postuserid);
$postdm->set('pagetext', $postpagetext);
$postdm->set('allowsmilie', 1);
$postdm->set('visible', 1);
$postdm->set('dateline', TIMENOW);
$postdm->save();
unset($postdm);

Rich
21 Dec 2005, 00:24
Hello,

I am a pretty crafty fellow and can figure out most things but I am a tad confused here. As a tutorial, I would expect this to tell me what it does and how to implement it.

(I am guessing it creates a thread that reads"Hi mom!")

All I see is some code but what I would do with this code and what it would do for me I am at a loss for. Is there any chance you could expand on this for us not so knowledgeable individuals. lol

Paul M
21 Dec 2005, 00:49
I thought the title pretty much gave it away > [How To] Create Posts

That is the code to create a post in an existing thread.

Daniel
21 Dec 2005, 04:39
Wouldn't it be easier to just use the "Create Thread" button and call it Hi Mom?

Code Monkey
21 Dec 2005, 05:51
Wouldn't it be easier to just use the "Create Thread" button and call it Hi Mom?

Yes, but that's not as fun as doing it with the Data Manager. ;)

fly
21 Dec 2005, 13:12
Hello,

I am a pretty crafty fellow and can figure out most things but I am a tad confused here. As a tutorial, I would expect this to tell me what it does and how to implement it.

(I am guessing it creates a thread that reads"Hi mom!")

All I see is some code but what I would do with this code and what it would do for me I am at a loss for. Is there any chance you could expand on this for us not so knowledgeable individuals. lol
As stated, this is code you would use in a hack to reply to a certain thread. What else do you want to know?

Razz
08 Jan 2006, 00:52
I tried this out but it doesn't seem to update the view and reply counters when it creates the new post or did I miss something?

laddil
11 Jan 2006, 21:36
I have a quick question about using this method to put in a post...

Does it take into account user preferances (i.e., emoticons, smilies, etc.) and forum security settings (vBcode, raw HTML, etc.)?

The modification I'm writing needs to add posts to a specific forum, but I have consern about the potential of this bypassing security and causing mischief.

grana
10 Apr 2006, 12:15
I have a question: if I create a post in this way, does vb send the "update notification emails" to the subscribed users?
If not, how can I trigger this?

Thanks!

Cloud Strife
18 Apr 2006, 00:27
edit

Wild-Wing
24 Apr 2006, 16:47
how can this be used to edit a post already posted?

fly
25 Apr 2006, 13:43
afaik, it can't. :D

Evercraft
26 Apr 2006, 11:53
You need to add the following code, after the post has been created, to update forum counters and last post index etc.

require_once(DIR . '/includes/functions_databuild.php');
build_forum_counters($threadinfo['forumid']);

I have a quick question about using this method to put in a post...

Does it take into account user preferances (i.e., emoticons, smilies, etc.) and forum security settings (vBcode, raw HTML, etc.)?

The modification I'm writing needs to add posts to a specific forum, but I have consern about the potential of this bypassing security and causing mischief.

It doesn't check permissions.

nj_vb
22 Jul 2006, 21:28
This doesn't work with 3.5.x for me...

It's saying "the user is already logged in, if you have lost your pw click here" or something to that effect. Any ideas?

Atakan KOC
24 Jul 2006, 06:52
3.5.x


$rforuminfo = fetch_foruminfo($Feed['forumid']);
$newpost = array(
'emailupdate' => 9999,
'userid' => 'Userid',
'username' => 'Username',
'title' => 'Title',
'message' => 'Message',
'thread' => 'threadid'
);
$threadinfo['threadid'] = 'threadid';
build_new_post('Post', $rforuminfo, $threadinfo, array(), $newpost, $errors);

fly
24 Jul 2006, 13:32
This doesn't work with 3.5.x for me...

It's saying "the user is already logged in, if you have lost your pw click here" or something to that effect. Any ideas?
I remember that happening to me as well. iirc, you populated BOTH the username and userid. Only fill in one.

ragtek
25 Aug 2006, 19:24
i've created a hook :
if ($forumid==7)
{$newpost = array(
'emailupdate' => 9999,
'userid' => '120',
'username' => 'Informationsminister',
'title' => 'Info',
'message' => 'folge dem weißn wolf
:P oder wähle folgende nummer',
'thread' => '$threadid'
);
$threadinfo['threadid'] = 'threadid';
build_new_post('Post', '7', $threadinfo, array(), $newpost, $errors);}
the start is newpost_complete
i want to make a automatic answer on every thread that someone creates in forum=7 but it doesn do that

FreekBoy
29 Aug 2006, 03:35
Is there a way like this to create forums?

Derschizo
04 Oct 2006, 15:53
What if you put it in the function_new reply and you want it to be a auto second post, what would you put for the threadid?
b/c
$threadinfo['threadid'] = 'threadid'; doesn't seem to work.

I want it in the same thread.

ruinernix
07 Oct 2006, 05:03
3.5.x


$rforuminfo = fetch_foruminfo($Feed['forumid']);
$newpost = array(
'emailupdate' => 9999,
'userid' => 'Userid',
'username' => 'Username',
'title' => 'Title',
'message' => 'Message',
'thread' => 'threadid'
);
$threadinfo['threadid'] = 'threadid';
build_new_post('Post', $rforuminfo, $threadinfo, array(), $newpost, $errors);


This works, but all messages created end up in a moderation queue even though the forum is not set to moderate posts/threads. I tried adding 'visible'=>'1' but it doesn't make a difference. Any clues? I suppose it's because I'm running this from an outside script, that isn't really logged into VB. I made a modification to functions_newpost.php

Replaced:
// see if post has to be moderated or if poster in a mod
if (
((
With:
// see if post has to be moderated or if poster in a mod
if ( ($post['visible'] == 0) AND
((


It does the job, but I'd like to understand why it's not working properly..

I also added build_forum_counters($forumid); after posting, otherwise the lastthread info doesn't get updated in the forum list.

What if you put it in the function_new reply and you want it to be a auto second post, what would you put for the threadid?
b/c
$threadinfo['threadid'] = 'threadid'; doesn't seem to work.

I want it in the same thread.

You should be using

$threadinfo['threadid'] = 3310; (ie: 3310 is the thread id)

ks_work
22 Nov 2006, 16:24
i'm with 3.6.3 now.
How do I update existing post ?

thanks

amcd
23 Nov 2006, 05:52
i'm with 3.6.3 now.
How do I update existing post ?

thanks
this is how we do it on 3.6.1 . i think the same is valid for 3.6.3 as well

$vbulletin->db->query_write("UPDATE post SET pagetext = '$message' WHERE postid=$postid");
$vbulletin->db->query_write("DELETE FROM postparsed WHERE postid=$postid");

ks_work
23 Nov 2006, 14:37
thanks a lot !
I'll try it.
Meanwhile this code did the job for me (i apologize for it's messiness):

<?php

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

// #################### DEFINE IMPORTANT CONSTANTS #######################
//define('GET_EDIT_TEMPLATES', true);

define('SKIP_SESSIONCREATE', 1);
define('DIE_QUIETLY', 1);
define('THIS_SCRIPT', 'editpost');

// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_newpost.php');
require_once(DIR . '/includes/functions_bigthree.php');
require_once(DIR . '/includes/functions_editor.php');
require_once(DIR . '/includes/functions_log_error.php');

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

// ### STANDARD INITIALIZATIONS ###
$checked = array();
$edit = array();
$postattach = array();



############################ start input from tt_news

$k_postid=$_REQUEST["k_postid"];
$k_threadid=$_REQUEST['k_threadid'];
$k_title=$_REQUEST['k_title'];
$k_pagetext=$_REQUEST['k_pagetext'];
$k_hidden_visible=$_REQUEST['k_hidden_visible'];

############################ end input from tt_news



$threadinfo['forumid']=55;
$threadinfo['threadid']=$k_threadid;
$threadinfo['firstpostid']= $k_postid;

$foruminfo = fetch_foruminfo($threadinfo['forumid'], false);
//print"<P>forum: <pre>".print_r($foruminfo,1);print"<P>thread :<pre>".print_r($threadinfo,1);
$postinfo['postid'] = $k_postid;
$postinfo['threadid'] =$threadinfo['threadid'];
$postinfo['parentid'] = $k_postid;
$postinfo['username'] = 'administrator';
$postinfo['userid'] = 1;
$postinfo['title'] = $k_title;
$postinfo['dateline'] = '';
$postinfo['pagetext'] =$k_pagetext;
$postinfo['allowsmilie'] = 1;
$postinfo['showsignature'] = 0;
$postinfo['ipaddress'] = '206.223.168.166';
$postinfo['iconid'] = 0;

if( isset($_REQUEST["k_hidden_visible"]))//
{
if($_REQUEST["k_hidden_visible"]==0)// hidden
{
$visible_val=0;
}
else //
{
$visible_val=1;
}
}
else //
{
$visible_val=0;

}

$postinfo['visible'] = $visible_val;
$postinfo['attach'] = 0;
$postinfo['infraction'] = 0;
$postinfo['reportthreadid'] = 0;
$postinfo['isdeleted'] = 0;
$postinfo['edit_userid'] = '';
$postinfo['edit_dateline'] = '';
$postinfo['edit_reason'] ='' ;


$threadinfo['visible']=$visible_val;
///print"<P>post <pre>".print_r($postinfo,1);
$aaa=1;

// need to get last post-type information
cache_ordered_forums(1);

// ############################### start update post ###############################
if ($aaa ==1)
{
// Variables reused in templates
$posthash = $vbulletin->input->clean_gpc('p', 'posthash', TYPE_NOHTML);
$poststarttime = $vbulletin->input->clean_gpc('p', 'poststarttime', TYPE_UINT);

$vbulletin->input->clean_array_gpc('p', array(
'stickunstick' => TYPE_BOOL,
'openclose' => TYPE_BOOL,
'wysiwyg' => TYPE_BOOL,
'message' => TYPE_STR,
'title' => TYPE_STR,
'iconid' => TYPE_UINT,
'parseurl' => TYPE_BOOL,
'signature' => TYPE_BOOL,
'disablesmilies' => TYPE_BOOL,
'reason' => TYPE_NOHTML,
'preview' => TYPE_STR,
'folderid' => TYPE_UINT,
'emailupdate' => TYPE_UINT,
'ajax' => TYPE_BOOL,
'advanced' => TYPE_BOOL,
'postcount' => TYPE_UINT,
'podcasturl' => TYPE_STR,
'podcastsize' => TYPE_UINT,
'podcastexplicit' => TYPE_BOOL,
'podcastkeywords' => TYPE_STR,
'podcastsubtitle' => TYPE_STR,
'podcastauthor' => TYPE_STR,
));

// ### PREP INPUT ###

$edit['message'] =$k_pagetext;
$edit['iconid'] =& $vbulletin->GPC['iconid'];
$edit['title'] =$k_title;
$edit['podcasturl'] =& $vbulletin->GPC['podcasturl'];
$edit['podcastsize'] =& $vbulletin->GPC['podcastsize'];
$edit['podcastexplicit'] =& $vbulletin->GPC['podcastexplicit'];
$edit['podcastkeywords'] =& $vbulletin->GPC['podcastkeywords'];
$edit['podcastsubtitle'] =& $vbulletin->GPC['podcastsubtitle'];
$edit['podcastauthor'] =& $vbulletin->GPC['podcastauthor'];
$edit['signature'] =& $vbulletin->GPC['signature'];
$edit['disablesmilies'] =& $vbulletin->GPC['disablesmilies'];
$edit['enablesmilies'] = $edit['allowsmilie'] = ($edit['disablesmilies']) ? 0 : 1;
$edit['stickunstick'] =& $vbulletin->GPC['stickunstick'];
$edit['openclose'] =& $vbulletin->GPC['openclose'];
$edit['visible'] = $visible_val;

$edit['reason'] = fetch_censored_text($vbulletin->GPC['reason']);
$edit['preview'] =& $vbulletin->GPC['preview'];
$edit['folderid'] =& $vbulletin->GPC['folderid'];

$dataman =& datamanager_init('Post', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$dataman->set_existing($postinfo);
//print"<P>edit:<pre>".print_r($edit,1);
// set info
$dataman->set_info('parseurl', ($foruminfo['allowbbcode'] AND $edit['parseurl']));
$dataman->set_info('posthash', $posthash);
$dataman->set_info('forum', $foruminfo);
$dataman->set_info('visible', $visible_val);
$dataman->set_info('thread', $threadinfo);
$dataman->set_info('show_title_error', true);
$dataman->set_info('podcasturl', $edit['podcasturl']);
$dataman->set_info('podcastsize', $edit['podcastsize']);
$dataman->set_info('podcastexplicit', $edit['podcastexplicit']);
$dataman->set_info('podcastkeywords', $edit['podcastkeywords']);
$dataman->set_info('podcastsubtitle', $edit['podcastsubtitle']);
$dataman->set_info('podcastauthor', $edit['podcastauthor']);
if ($postinfo['userid'] == $vbulletin->userinfo['userid'])
{
$dataman->set_info('user', $vbulletin->userinfo);
}
//print"<P>userinfo:<pre>".print_r($vbulletin->userinfo,1);


// set options
$dataman->setr('showsignature', $edit['signature']);
$dataman->setr('allowsmilie', $edit['enablesmilies']);

// set data
/*$dataman->setr('userid', $vbulletin->userinfo['userid']);
if ($vbulletin->userinfo['userid'] == 0)
{
$dataman->setr('username', $post['username']);
}*/
$dataman->setr('title', $edit['title']);
$dataman->setr('visible', $edit['visible']);
$dataman->setr('pagetext', $edit['message']);
if ($postinfo['userid'] != $vbulletin->userinfo['userid'])
{
$dataman->setr('iconid', $edit['iconid'], true, false);
}
else
{
$dataman->setr('iconid', $edit['iconid']);
}

$dataman->pre_save();
if ($dataman->errors)
{
$errors = $dataman->errors;
}

if (sizeof($errors) > 0)
{
// ### POST HAS ERRORS ###
print"<P>ERRORS:<pre>".print_r($errors,1);

}
else
{
// ### POST HAS NO ERRORS ###

print"<P>No errors so far !";
print"<P>edit:<pre>".print_r($edit,1);

print "<P>result is :".$dataman->save();

$date = vbdate($vbulletin->options['dateformat'], TIMENOW);
$time = vbdate($vbulletin->options['timeformat'], TIMENOW);

// initialize thread / forum update clauses
$forumupdate = false;

$threadman =& datamanager_init('Thread', $vbulletin, ERRTYPE_SILENT, 'threadpost');
$threadman->set_existing($threadinfo);

if ($edit['title'] != '' )
{
// need to update thread title and iconid
$threadman->set_info('skip_first_post_update', false);
$threadman->set('title', unhtmlspecialchars($edit['title']));
$threadman->set('visible', $edit['visible']);
$threadman->set('iconid', $edit['iconid']);

// do we need to update the forum counters?
$forumupdate = ($foruminfo['lastthreadid'] == $threadinfo['threadid']) ? true : false;
}
else{
print "<P> line 237 not update thread";
}

$threadman->save();

require_once(DIR . '/includes/functions_databuild.php');

// do forum update if necessary
if ($forumupdate)
{
build_forum_counters($threadinfo['forumid']);
}

$cansubscribe = true;

// $vbulletin->url = 'showthread.php?' . $vbulletin->session->vars['sessionurl'] . "p=$postinfo[postid]#post$postinfo[postid]";
}
}
?>

Derschizo
04 Dec 2006, 01:23
That looks interesting can you show me how to implement and make it fully work completely. I'm not sure exactly where you put the code and what each section completely means. I'm assuming it goes to the function_newpost .

amcd
04 Dec 2006, 05:18
That depends on what you want to achieve. In vbulletin 3.5 or higher, editing the original php files is discouraged and its better to add plugins.

jj
09 Dec 2006, 17:10
Hi guys, I'm creating/posting/modifying posts/thread out of some custom software I wrote. Now is there a way of bypassing the post-time limit with the datamanager-method when doing it?

BOLT
21 Dec 2006, 17:38
I dont understand. Where do you enter this code? And how do you make the post, time, thread, etc. be what exactly you want?

liquidx
27 May 2007, 05:36
Can someone help here?

I'm trying to create new posts, I've tried both the dataman and build_new_post methods, here's my problems:

Dataman method:
How do I handle errors? When I get an error (like posting anonymously with a user name that is already in use) it directly echos out a full error page! I don't want this, I want just the error message..

build_new_post method:
When posting anonymous, the new posts are moderated, even though the forum allows anonymous posting and is not moderated.. I can't figure out how to stop this from happening.


I've searched all over the forums for both these issues but came up empty, anyone?

quitsmoking
05 Jul 2007, 00:26
And what if I want to add a new thread (not a post in an existing thread)?

fly
05 Jul 2007, 13:49
Then you'd find the thread about HowTo Create Threads. ;)

quitsmoking
07 Jul 2007, 23:44
Thank you. Your advice worked :) I found one and it worked like charm.

Ranma2k
30 Aug 2007, 13:47
I have a Q

can we use the vb post class / data manager to store the posts in different table other the the default table Posts ?
If yes can you please explain ?

ragtek
31 Aug 2007, 18:52
what do you realy want?:D
you could "inherit" the class i think

Ranma2k
01 Sep 2007, 08:36
well basically i want to use the post class to process the Comments and store it in the comment table

toucan42
21 Sep 2007, 15:48
I thought the title pretty much gave it away > [How To] Create Posts

That is the code to create a post in an existing thread.

I am struggling to get my mind wrapped around the datamanager - if i want code to create a new thread is it the vB_DataManager_Thread_FirstPost I am looking for?

Any decent examples of using the DM?

rootnik
29 Sep 2007, 19:54
Then you'd find the thread about HowTo Create Threads. ;)

There is no such thread anymore. I am needing to do this as well.

fly
29 Sep 2007, 21:12
There is no such thread anymore. I am needing to do this as well.

I'll try to write one up this weekend then, if no one else does. Dunno why it got removed...

Thibaut
21 Oct 2007, 22:23
There is no such thread anymore. I am needing to do this as well.

I would need that too, thanks.

ragtek
21 Oct 2007, 22:42
with this code:
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');

$forumid = $vbulletin->GPC['fid']; // can also be a number ;) $forumdid= 12;

$foruminfo = fetch_foruminfo($forumid);
$threaddm->set_info('forum', $foruminfo);

$threaddm->set('forumid', $foruminfo['forumid']);
$threaddm->set('userid', 1234);
$threaddm->set('title', 'Testtitle');
$threaddm->set('pagetext', 'a little test');
$threaddm->set('allowsmilie', 1);
$threaddm->set('visible', 1);
$threaddm->set('dateline', TIMENOW);
$threaddm->save();

if you need the threadid save it with
$id = $threaddm->save();

Thibaut
22 Oct 2007, 10:06
Thanks ;)

Thibaut
23 Oct 2007, 17:43
How can I get the id of the thread ?
Thanks

zytzagoo
24 Oct 2007, 08:23
How can I get the id of the thread ?
Thanks
$thread_id = $threaddm->save();

Thibaut
24 Oct 2007, 09:08
Thanks ! :)

Tinh.Nhi
21 Nov 2007, 11:01
how to use the code like thank please ?

paolo.capitani
21 Dec 2007, 16:42
thanks for the thread!
how can I add a break line in the content of the just added post?

TCooper
24 Dec 2007, 18:57
I was able to make a script that posts a new thread to a user defined forum but not able to make it post a reply to a current thread. I tried using the example in the first post and it didnt work, can someone please help with a new post to current thread.

amcd
24 Dec 2007, 19:32
$postdm = new vB_DataManager_Post($vbulletin, ERRTYPE_STANDARD);

$timenow = TIMENOW ;
$threadinfo = fetch_threadinfo($threadid);
$foruminfo = fetch_foruminfo($forumid);

$postdm->set_info('forum', $foruminfo);
$postdm->set_info('thread', $threadinfo);
$postdm->set('threadid', $threadid);
$postdm->set('title', $symid);
$postdm->set('userid', $userid);
$postdm->set('pagetext', $message);
$postdm->set('allowsmilie', 1);
$postdm->set('visible', 1);
$postdm->set('dateline', $timenow);
$postdm->save();
unset($postdm);

this works.

sonata
12 Apr 2008, 15:43
This works, but all messages created end up in a moderation queue even though the forum is not set to moderate posts/threads. I tried adding 'visible'=>'1' but it doesn't make a difference. Any clues? I suppose it's because I'm running this from an outside script, that isn't really logged into VB. I made a modification to functions_newpost.php

Replaced:
// see if post has to be moderated or if poster in a mod
if (
((
With:
// see if post has to be moderated or if poster in a mod
if ( ($post['visible'] == 0) AND
((


It does the job, but I'd like to understand why it's not working properly..



Any solution for this? I still encounter this problem when I use build_new_post function. Right now, I have to execute SQL queries to delete it from moderation table and set the visible flag to one. Any better solution?

amcd
12 Apr 2008, 15:58
build_new_post assumes that you are adding a post for the same user who is logged in. use the data manager.

silly rabbit
23 May 2008, 16:53
Then you'd find the thread about HowTo Create Threads. ;) Cute! flypaper, a somewhat related question to the topic at hand, creating posts . . .

. . . if editing an existing post I'd like to have a simple "check box" in the editor that would flag/include the updated post into the "New Posts" search engine for everyone to review, see. Ever seen such a hack before? Easily possible?

Great Thread, thx Rabbit

amcd
24 May 2008, 09:44
Cute! flypaper, a somewhat related question to the topic at hand, creating posts . . .

. . . if editing an existing post I'd like to have a simple "check box" in the editor that would flag/include the updated post into the "New Posts" search engine for everyone to review, see. Ever seen such a hack before? Easily possible?

Great Thread, thx Rabbit
Not a good idea. To accomplish this, the time of the post would have to be edited, and that would move the post to the end of the thread.

The thread's last updated time can be updated, and that would bump the thread, but it will not solve your purpose. A 10 page thread may have a post on page 4 edited, and users will be wondering why the thread is on top of the forum when the last post is 3 months ago.

silly rabbit
25 May 2008, 03:19
Not a good idea. To accomplish this, the time of the post would have to be edited, and that would move the post to the end of the thread.
Thanks amcd! Yer right, moving the post by adjusting the time is not what I would have had in mind but at least now I have a better understanding of the problem at hand . . .

If I come up with another amicable solution myself I'll certainly post it here.

Hare says ThankYou & Cheers!

LoRdGd
10 Jun 2008, 02:26
Hello,
Can anybody help me with this one?

$postdm = new vB_DataManager_Post($vbulletin, ERRTYPE_STANDARD);

$timenow = TIMENOW ;
$threadinfo = fetch_threadinfo($threadid);
$foruminfo = fetch_foruminfo($forumid);
$threadid = '19987';
$userid = '1500';
$symid='90000';

$postdm->set_info('forum', $foruminfo);
$postdm->set_info('thread', $threadinfo);
$postdm->set('threadid', $threadid);
$postdm->set('title', $symid);
$postdm->set('userid', $userid);
$postdm->set('pagetext', $wiadomosc);
$postdm->set('allowsmilie', 1);
$postdm->set('visible', 1);
$postdm->set('dateline', $timenow);
$postdm->save();
unset($postdm);

Im trying to posing messages from FORM in my joomla based site... but nothing happens on the board :(
This form is in other dfrent directory, but im totaly newbie in php and i don`t know how to set a directory here.


Im using vB 3.7.1

Essencee
13 Jul 2008, 14:26
with this code:
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');

$forumid = $vbulletin->GPC['fid']; // can also be a number ;) $forumdid= 12;

$foruminfo = fetch_foruminfo($forumid);
$threaddm->set_info('forum', $foruminfo);

$threaddm->set('forumid', $foruminfo['forumid']);
$threaddm->set('userid', 1234);
$threaddm->set('title', 'Testtitle');
$threaddm->set('pagetext', 'a little test');
$threaddm->set('allowsmilie', 1);
$threaddm->set('visible', 1);
$threaddm->set('dateline', TIMENOW);
$threaddm->save();
Thank you!
How can I get the post id after sending?

ragtek
13 Jul 2008, 14:32
you have to save it with $yourid = $threaddm->save();
thant it's stored in $yourid

hth

Essencee
13 Jul 2008, 15:16
you have to save it with $yourid = $threaddm->save();
thant it's stored in $yourid

hth
Thank you my dear :)

dlitec
16 Jul 2008, 15:25
hey there
i tryed this too.. but i get back an error.. now first the code:
$forumid = 50;
$userid = 1077;
$title = '$PRODUCTS_MODEL - $PRODUCTS_NAME';
$pagetext = 'Tatatatatestpost....';

$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');

$foruminfo = fetch_foruminfo($forumid);
$threaddm->set_info('forum', $foruminfo);

$threaddm->set('forumid', $forumid);
$threaddm->set('userid', $userid);
$threaddm->set('user', 'Onlineshop Kommentar');
$threaddm->set('title', $title);
$threaddm->set('pagetext', $pagetext);
$threaddm->set('allowsmilie', 1);
$threaddm->set('visible', 1);
$threaddm->set('dateline', TIMENOW);
$threaddm->save();

looks good to me.. but i'll recieve this:
"Fatal error: Call to a member function query_first_slave() on a non-object in /var/www/de/shop/www/htdocs/community/includes/functions.php on line 1303"

anyone has an idea what could be wrong? using 3.7.2 currently

LoRdGd
16 Jul 2008, 15:49
I`m not good in php, but i have make it some weeks ago.
Look at my thread in vbulletin.com: http://www.vbulletin.com/forum/showthread.php?t=275195

Maybe you will see something interesting :)

dlitec
16 Jul 2008, 16:32
thx lord.. but my code was correct

it was a problem between xtcommerce and this script.. no i'm handling it on another way ;)

dlitec
22 Jul 2008, 15:02
hmm sorry its me again

i wonder if its possible to vote threads with this too?!

i tried this:
$postdm->set('votetotal', $voted);
but recieved the standard error:
Field votetotal is not defined in $validfields in class vB_DataManager_Post in [path]/includes/class_dm.php

anyone has a clue?

edit:
extending in class_dm.php with this variable works.. no error anymore, but the voting is not transfered. do i really have to write into the DB directly? or is there a way?

fly
22 Jul 2008, 20:53
hmm sorry its me again

i wonder if its possible to vote threads with this too?!

i tried this:
$postdm->set('votetotal', $voted);
but recieved the standard error:
Field votetotal is not defined in $validfields in class vB_DataManager_Post in [path]/includes/class_dm.php

anyone has a clue?

edit:
extending in class_dm.php with this variable works.. no error anymore, but the voting is not transfered. do i really have to write into the DB directly? or is there a way?

This is really offtopic for this thread, but if you want to rate threads, I'd check out class_dm_threadrate.php. If you want to vote in polls, class_dm_pollvote.php probably has what you need.

edit:
http://members.vbulletin.com/api/vBulletin/_includes---class_dm_threadrate.php.html
http://members.vbulletin.com/api/vBulletin/_includes---class_dm_pollvote.php.html

dlitec
23 Jul 2008, 08:34
thanks for your advice.. i now solved it with direct db-query's ... i dont like the datamanager :(

i think next time i'll stay straight with php and mysql.

Hereward
24 Jul 2008, 08:44
Hi there,

I am trying to work out how to perform an update as opposed to an insert on the text of the first post of a thread.

I currently have the following which works fine for inserts:

$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$forumid = 36; //$vbulletin->GPC['fid']; // can also be a number ;) $forumdid= 12;
$foruminfo = fetch_foruminfo($forumid);
$threaddm->set_info('forum', $foruminfo);
$threaddm->set('forumid', $foruminfo['forumid']);
$threaddm->set('userid', 1);
$threaddm->set('title', $title);
$threaddm->set('pagetext', $body);
$threaddm->set('allowsmilie', 1);
$threaddm->set('visible', 1);
$threaddm->set('dateline', TIMENOW);
$threadid = $threaddm->save();

Is there a way to change this from an insert to an update, by passsing in the threadid for example?

I tried this, which generated a 503 error:
$threaddm->set('threadid', $threadid);

Hereward
26 Jul 2008, 14:20
I have spent many hours now trying to solve the humble little problem stated above with no success.

this is heartbreaking.

I tried to set the post id using this:

$postid = $postdm->fetch_field('firstpostid');
$postdm->set('postid', $postid);


didn't work

fly
26 Jul 2008, 15:48
I have spent many hours now trying to solve the humble little problem stated above with no success.

this is heartbreaking.

I tried to set the post id using this:

$postid = $postdm->fetch_field('firstpostid');
$postdm->set('postid', $postid);


didn't work

Do it with a SQL query then...

Hereward
27 Jul 2008, 05:01
yeah that's exactly what I am going to do, but it seems wrong when there is an API which supposedly can do all this - but since I do not understand how it works and cannot find a working example or documentation other than the comments in the code itself it doesn;t seem likely that I am going to work it out without a miracle.

amcd
27 Jul 2008, 07:52
There is no miracle needed. The vbulletin code is very well organized and commented.

I guess there must be a way of telling the thread data manager to pre-load itself with the thread. Then change whatever you want to and tell it to save. That should do an update.

Read the data manager class in the includes directory. Or else read any of the default vb scripts which o an update, such as the edit thread function from thread tools dropdown.

Hereward
27 Jul 2008, 14:38
"well documented" ..? you gotta be joking

but I have figured it out now:
In order to force the save command to do an update instead of an insert you need to use
set_existing:

$existing = array('userid' => $userid,'threadid'=>$threadid);
$threaddm->set_existing($existing);

This works (: (:

amcd
27 Jul 2008, 14:54
"well documented" ..? you gotta be joking

It is. You haven't seen the bad stuff. There are a huge number of scripts out there which are not even indented properly and are being sold for $400 and above.

nuk3
30 Jul 2008, 06:08
"well documented" ..? you gotta be joking

Setting the existing data (if necessary)
If you are using the data managers to insert a new record into the database, you do not need to perform this step. However, if you are updating an existing record (eg, editing a post), this step is mandatory.

To set the existing data, you must call the set_existing method of the data manager object.

set_existing(&$existing)

The $existing is an array of data that is currently stored in the database. It should include all the fields this data manager handles as keys. *snip*

http://www.vbulletin.com/docs/html/data_manager_programming

How you could've not checked and/or found that documentation in the first place is seriously beyond me, being the first result on google for vbulletin datamanager and all. It explains everything you could need to know and also has relevant real world examples provided too. So take your ignorant minded "well documented" attack and shove it.

vrinteractive
20 Sep 2008, 00:39
is there a setting i need to configure in admincp? I'm trying to add a forum thread useing the datamanger_init, and save is returning a new id, but when i try to visit the thread i get a permissions error. it's on 3.7.2

fly
20 Sep 2008, 01:28
is there a setting i need to configure in admincp? I'm trying to add a forum thread useing the datamanger_init, and save is returning a new id, but when i try to visit the thread i get a permissions error. it's on 3.7.2

I think there is another thread on how to create threads. It may be more ontopic there. Otherwise, I think we'd need to see your code...

LoRdGd
20 Sep 2008, 13:53
Read my topic on vbulletin.com:
http://www.vbulletin.com/forum/showthread.php?p=1578823#post1578823

Mutt
03 May 2009, 18:07
with this code:
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');

$forumid = $vbulletin->GPC['fid']; // can also be a number ;) $forumdid= 12;

$foruminfo = fetch_foruminfo($forumid);
$threaddm->set_info('forum', $foruminfo);

$threaddm->set('forumid', $foruminfo['forumid']);
$threaddm->set('userid', 1234);
$threaddm->set('title', 'Testtitle');
$threaddm->set('pagetext', 'a little test');
$threaddm->set('allowsmilie', 1);
$threaddm->set('visible', 1);
$threaddm->set('dateline', TIMENOW);
$threaddm->save();

if you need the threadid save it with
$id = $threaddm->save();



this works but how can I also set the prefix? added a prefix line returns an error

--------------- Added 1241372989 at 1241372989 ---------------

found it. you have to use "prefixid" & you set it to the prefix var. like this

$threaddm->set('prefixid', 'report');

I'm using this for our mod forum so alerted posts or pms have prefixes

ULFSoft
02 Jun 2009, 22:41
how can i attach file when i want to create a thread with data manager?
i think that i must use class_dm_attachment.php but how?
can anyone help me?
(i am new to vb programming!)

todd73nj
01 Sep 2009, 03:07
I was wondering if someone could tell me what is wrong with my script. All I am trying to do is post a new message in an existing thread. When I put this script in a php page and hit it from my browser, I don't get any error, but I also don't get a message posted. I don't even see the "save returned" message in my browser. If I change some things (like the path to class_dm_threadpost), I get an error, so I know it is running something.

As for the echo not working, it seems like as soon as I put those require_once at the top of my file, I can't echo any messages anymore. But I only have those echos in there because the message isn't being posted to my thread.

<?php
require_once('global.php');
require_once('./includes/class_dm_threadpost.php');

$postdm = new vB_DataManager_Post($vbulletin, ERRTYPE_STANDARD);

$threadid=1565;
$forumid=5;
$symid='asdf';
$userid=2;
$message="Testing.Testing.Testing.Testing.Testing.";

$timenow = TIMENOW;
$threadinfo = fetch_threadinfo($threadid);
$foruminfo = fetch_foruminfo($forumid);

$postdm->set_info('forum', $foruminfo);
$postdm->set_info('thread', $threadinfo);
$postdm->set('threadid', $threadid);
$postdm->set('title', $symid);
$postdm->set('userid', $userid);
$postdm->set('pagetext', $message);
$postdm->set('allowsmilie', 1);
$postdm->set('visible', 1);
$postdm->set('dateline', $timenow);
$xxx = $postdm->save();
unset($postdm);
echo "save returned:";
echo $xxx;

?>

amcd
01 Sep 2009, 09:28
Do you have access to php.ini and/or PHP error log? Check the error log.

If echo does not work, try the PHP error_log() function. You may also find the var_export() function useful.

I have almost the same code working with vb 3.6.1. What is your version?

todd73nj
01 Sep 2009, 15:12
I am running 3.7.4 PL1.

If I start with an empty php file and just put an echo statement, I see the message when I hit the page. Anything I echo before the line that includes class_dm_threadpost.php I see output, but anything after I don't. For example:


<?php
require_once('global.php');
require_once('./includes/class_dm_threadpost.php');

echo "Hello world.";
?>


Shows nothing in the page. But

<?php
require_once('global.php');
echo "Hello world.";
require_once('./includes/class_dm_threadpost.php');

?>


Shows "Hello world." on the page.

I am using godaddy, so I don't know how I can access the php error file. I tried using an set_error_handler as described on this page: http://us3.php.net/set-error-handler , to catch any errors, but still I got no output. It is bizarre. It is like including that class_dm_threadpost is killing everything. I have not modified any of my vbulletin files, so it should be whatever came with 3.7.4.

var_export() behaves the same way as echo. Before that require_once line it works, after it, I see nothing.

--------------- Added 1251815891 at 1251815891 ---------------

Doh. I figured it out. I have to include another file as well (class_dm.php). It seems like without it, something in the class_dm_threadpost was unhappy.

This works:


<?php
require_once('global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_threadpost.php');

$threadid=1565;
$forumid=5;
$symid='asdf';
$userid=2;
$message="Testing.Testing.Testing.Testing.Testing.";

$timenow = TIMENOW;
$threadinfo = fetch_threadinfo($threadid);
$foruminfo = fetch_foruminfo($forumid);

$postdm = new vB_DataManager_Post($vbulletin, ERRTYPE_STANDARD);
$postdm->set_info('forum', $foruminfo);
$postdm->set_info('thread', $threadinfo);
$postdm->set('threadid', $threadid);
$postdm->set('title', $symid);
$postdm->set('userid', $userid);
$postdm->set('pagetext', $message);
$postdm->set('allowsmilie', 1);
$postdm->set('visible', 1);
$postdm->set('dateline', $timenow);
$xxx = $postdm->save();
unset($postdm);
echo 'save returned:';
echo $xxx;
?>

ewelin
07 Oct 2009, 21:12
You need to add the following code, after the post has been created, to update forum counters and last post index etc.

require_once(DIR . '/includes/functions_databuild.php');
build_forum_counters($threadinfo['forumid']);
I have a slight problem.... My code is inserting the post perfectly and everything is working in that respect. The problem is that the last post field is not being updated. I know this has something to do with the timestamp, but I'm not sure why the issue is happening. I'm importing a chat transcript and putting each chat post as a forum post. The import script runs every 5 minutes and uses the chat post's timestamp as the forum post time stamp. The forum posts appear just as they were posted within the chat and the time is dead on... Even with the above code included at the end, it only updates the forum counters, it doesn't update the last post index. Now if I swap the timestamp from the actual chat post time to TIMENOW
it's updated. Anyone have any ideas on how I can resolve this.

amcd
08 Oct 2009, 10:50
Did you try build_thread_counters?

ewelin
08 Oct 2009, 11:48
I have not, I'm assuming I pass it the thread id correct?

--------------- Added 1255013971 at 1255013971 ---------------

Did you try build_thread_counters?
That did the trick!!! Thanks!!!

CarcaBot
01 Dec 2009, 14:32
Someone tried to do this in version 4 ?

Because i can't build thread information and forum information .

It post the thread but i can see only title without content. How can i build thread information?

Lynne
01 Dec 2009, 16:14
Someone tried to do this in version 4 ?

Because i can't build thread information and forum information .

It post the thread but i can see only title without content. How can i build thread information?
I just ran it just fine as a quick cron job on my site using the code here - http://www.vbulletin.org/forum/showpost.php?p=1365393&postcount=39

ragtek
01 Dec 2009, 16:28
Edit:

It's working for me.
Strange that it first didn't work

Lynne
01 Dec 2009, 16:41
He's right.
In vB4 it's not working this way.
The post is created, but with my code i can't see it in the recent posts widget and also i can't see it in the thread^^
I don't have the cms installed on the site I just tested it on, so I don't know about the recent posts widget thing, but I can definitely see the thread/post on my site and it has the content from the code in it.

ragtek
01 Dec 2009, 16:59
Here's a codesnippat how it's working for me
http://ragtek.org/blog/vbulletin/vbulletin4-vbulletin/threads-posts-automatisch-erstellen/

CarcaBot
01 Dec 2009, 20:22
@Lynne, i tried all posibilities and no way to work like old coe.
@ragtek i will try this soon, but let me know how to get ID of new thread , if work your code.

thanks.

ragtek
01 Dec 2009, 20:46
Strange.
Now it's also working with the damanager:D

CarcaBot
01 Dec 2009, 20:58
;) interesting..
i tried with this code:

<?
require_once('./global.php');
require_once('./includes/class_dm.php');
require_once('./includes/class_dm_threadpost.php');
require_once('./includes/functions_databuild.php');

$forumid = "44";

$threadinfo = array();
$foruminfo = fetch_foruminfo($forumid);
$threaddm =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$threaddm->set('forumid', $forumid);
$threaddm->set('userid', "1");
$threaddm->set('pagetext', 'textul meu');
$threaddm->set('title', 'titlul meu');
$threaddm->set('allowsmilie', '1');
$threaddm->set('visible', '1');
$threaddm->set_info('forum', $foruminfo);
$threadid = $threaddm->save();
build_forum_counters($forumid);




?>


It make a thread on that forumid but i can't see the content.
The content is also showed in alt tag of link but in thread nothing.

--------------- Added 1259749240 at 1259749240 ---------------

awesome :)) now is working...
I don't understand why not yesterday ;)

ilbianconiglio
13 Jul 2010, 15:28
I'm not using the script into the forum root. I'm using it outside in my site.

Someone can tell me which are the files and defines required to run this script?

ThorstenA
22 Aug 2010, 14:27
...
That works fine on vbulletin 4.x ! Thanks!

leitel
12 Nov 2010, 13:15
Can I use this approach to add articles to vB CMS?

av8or1
24 Apr 2011, 20:22
how can i attach file when i want to create a thread with data manager?
i think that i must use class_dm_attachment.php but how?
can anyone help me?
(i am new to vb programming!)

Hi-

Did you figure out how to add a post with attachments? Thanks!

rey maximo
05 Dec 2012, 01:42
Hello, sorry for my English, I use translator :)

I made a script to insert answers in the test environment I worked perfect (was with vb4.11), but to pass it to the production environment (vb4.2) throws an error on the line where does this:
new vB_DataManager_Post ($vbulletin, ERRTYPE_STANDARD);
If I comment the line, the script continues, so that's the problem, the error is this:
Fatal error: Registry object is not an object in front of it class_dm.php and a large array of data. I do not understand it may be going, or if I change something in the latest version of vBulletin. Please let me help,
thank you very much

bravura
05 Dec 2013, 15:31
Hello, thanks for all these helpful posts. But i have a couple question, i want to know about the Mobile API needed for showing all posts and Mobile API needed for creating new posts. Also if i can get the definition of these API that will be very much helpful for me. Thanks.

Lynne
05 Dec 2013, 17:55
You are talking about the Mobile Suite for 3.x and the API that you download from the members area in order to run the Mobile Suite? (This is the 3.x article forum.)

bravura
06 Dec 2013, 14:28
Hello,

I am doing Integration of my App with vBulletin Mobile API.
Can anyone suggest me what is the API method and what are the parameters needed for Creating Posts ?

tbworld
06 Dec 2013, 14:52
Hello,

I am doing Integration of my App with vBulletin Mobile API.
Can anyone suggest me what is the API method and what are the parameters needed for Creating Posts ?

OOPS - I did it again, this is for VB4, Sorry!

I can give you a few links that helped me out when I was going through the code. You may have already looked at them.

vBulletin Mobile API code directory:
/includes/api/6Early documentation post about the API
http://www.vbulletin.com/vbcms/content.php/334-mobile-api

Thread from vBulletin.com about the mobile API
http://www.vbulletin.com/forum/forum/vbulletin-4/vbulletin-mobile-suite/3945830-mobile-api-documentation

bravura
06 Dec 2013, 14:53
You are talking about the Mobile Suite for 3.x and the API that you download from the members area in order to run the Mobile Suite? (This is the 3.x article forum.)

Thank you for your response.
I am not talking about the Mobile Suite for 3.x and i have not downloaded the API from the members area.
I am trying to integrate with vBulletin 4.2 using the REST Interface.




Thanks

--------------- Added 1386343340 at 1386343340 ---------------

OOPS - I did it again, this is for VB4, Sorry!

I can give you a few links that helped me out when I was going through the code. You may have already looked at them.

vBulletin Mobile API code directory:
/includes/api/6Early documentation post about the API
http://www.vbulletin.com/vbcms/content.php/334-mobile-api

Thread from vBulletin.com about the mobile API
http://www.vbulletin.com/forum/forum/vbulletin-4/vbulletin-mobile-suite/3945830-mobile-api-documentation

Thank you for your response.
Yes I have already looked at them. But i couldn't able to figure out which API method is needed for Creating new Posts.
Also the following link doesn't say anything about the Parameters, required for the API method.
http://www.vbulletin.com/vbcms/content.php/352-Method-List

I have logged in by calling the API method login_login and then registered the client by calling the API method api_init.
Now I have the Sessionhash, Accesstoken, clientid and Secret but i don't know Which API method i should call and what parameters i need to pass.


Thanks
Debashis

ZUCCO
06 Dec 2013, 16:13
Using codes :D . Just click on create new thread

bravura
06 Dec 2013, 16:14
OOPS - I did it again, this is for VB4, Sorry!

I can give you a few links that helped me out when I was going through the code. You may have already looked at them.

vBulletin Mobile API code directory:
/includes/api/6Early documentation post about the API
http://www.vbulletin.com/vbcms/content.php/334-mobile-api

Thread from vBulletin.com about the mobile API
http://www.vbulletin.com/forum/forum/vbulletin-4/vbulletin-mobile-suite/3945830-mobile-api-documentation

Thank you for your response.
I have not downloaded any Mobile API code. I just wanted to Integrate using the REST Interface.
If downloading the Mobile API code will help then can you please suggest me How can i download it and from where ?


Thanks

tbworld
06 Dec 2013, 16:40
You posted to a vBulletin3 thread, my post regarded vBulletin4. Unfortunately, I am not the right person to ask about vBulletin3.

The mobile templates and API are already included in vBulletin 4. :)

Lynne
06 Dec 2013, 18:00
Thank you for your response.
I am not talking about the Mobile Suite for 3.x and i have not downloaded the API from the members area.
I am trying to integrate with vBulletin 4.2 using the REST Interface.


Then you are posting in the wrong place. This is an article about vB3, not vB4.

bravura
06 Dec 2013, 19:45
You posted to a vBulletin3 thread, my post regarded vBulletin4. Unfortunately, I am not the right person to ask about vBulletin3.

The mobile templates and API are already included in vBulletin 4. :)

Thanks a lot for your help.
If the mobile templates and API are already included in vBulletin 4 can you please tell me from where i can get those APIs so that i can Integrate my Mobile App with them.



Thanks
Debashis

--------------- Added 1386359237 at 1386359237 ---------------

Then you are posting in the wrong place. This is an article about vB3, not vB4.

Ok :)

Thank you for the help.