Post handler
#1
How do I create a post with the post handler located in inc/datahandlers/post.php

Is there a documentation or something?

Thanks Smile
[Image: banner_728.png]
Reply
#2
you may trace a couple of plugins related to automatic posting .. eg. welcome topic , advanced reports ..
Reply
#3
Something along this sort of lines ought to work, though I haven't tested it:

PHP Code:
<?php
require_once MYBB_ROOT."inc/datahandlers/post.php";
$posthandler = new PostDataHandler("insert");

$post = array(
    
"tid" => 0// Thread ID
    
"replyto" => 0// Reply to ID
    
"fid" => 0// Forum ID
    
"subject" => ''// Post subject
    
"icon" => ''// Post icon
    
"uid" => 1// User ID
    
"username" => ''// Username
    
"message" => ''// Message
    
"ipaddress" => get_ip(),
);


$post['options'] = array(
    
"signature" => 1,
    
"subscriptionmethod" => 1,
    
"disablesmilies" => 0
);

$posthandler->set_data($post);

$valid_post $posthandler->validate_post();

$post_errors = array();

if(!
$valid_post)
{
    
$post_errors $posthandler->get_friendly_errors();
}

$posthandler->insert_post();
?>
Reply
#4
(03-05-2012, 03:58 PM)euantor Wrote:  Something along this sort of lines ought to work, though I haven't tested it:
.......

I will test it ASAP, thank you euantor.
If you ever find the time, could you please post similar code for a new thread?

#
MyBB is the best forum software! Exclamation

Reply
#5
(03-06-2012, 03:47 AM)seeker Wrote:  [...] could you please post similar code for a new thread?

Code for inserting a new thread is a lot similar to the code for inserting a new post (pieced together from newthread.php, also untested):

PHP Code:
<?php
require_once MYBB_ROOT."inc/datahandlers/post.php";
$posthandler = new PostDataHandler("insert");
$posthandler->action "thread";

$new_thread = array(
    
"fid" => 0// Forum ID to create thread
    
"subject" => ''// Subject
    
"prefix" => ''// Thread prefix
    
"icon" => ''// Thread Icon
    
"uid" => 0// Poster ID
    
"username" => ''// Poster Username
    
"message" => ''// Post message
    
"ipaddress" => get_ip(), 
);


$new_thread['options'] = array(
    
"signature" => 1,
    
"subscriptionmethod" => 1,
    
"disablesmilies" => 0
);

$posthandler->set_data($new_thread);

$valid_thread $posthandler->validate_post();

$post_errors = array();

if(!
$valid_thread)
{
    
$post_errors $posthandler->get_friendly_errors();
}

if(
count($post_errors) > 0)
{
    
$thread_errors inline_error($post_errors);
    
$mybb->input['action'] = "newthread";        

else 
{
    
$posthandler->insert_thread();
}
?>

Also, for future reference, if you have a program that is able to search across multiple files (like Notepad++'s find in files feature), you can search for a function and see how it has been used across the mybb core or in other plugins.

In this case, searching for something like '$posthandler->insert_' would show up both cases where the $posthandler was used to insert new posts and threads.
Reply
#6
"...a program that is able to search across multiple files..."
I've searched through the code many times, but having both these here is a good way to save time.
Thanks Beardy.
#
MyBB is the best forum software! Exclamation

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)