Current time: 07-24-2014, 04:22 AM Hello There, Guest! (LoginRegister)


Post Reply 
Post handler
03-05-2012, 12:46 PM
Post: #1
Post handler
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]
Find all posts by this user
Quote this message in a reply
03-05-2012, 12:58 PM
Post: #2
RE: Post handler
you may trace a couple of plugins related to automatic posting .. eg. welcome topic , advanced reports ..
Find all posts by this user
Quote this message in a reply
03-05-2012, 03:58 PM
Post: #3
RE: Post handler
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();
?>

Visit this user's website Find all posts by this user
Quote this message in a reply
03-06-2012, 03:47 AM
Post: #4
RE: Post handler
(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
Find all posts by this user
Quote this message in a reply
03-06-2012, 05:12 AM (This post was last modified: 03-06-2012 05:13 AM by Beardy.)
Post: #5
RE: Post handler
(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.
Find all posts by this user
Quote this message in a reply
03-07-2012, 06:53 AM
Post: #6
RE: Post handler
"...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
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

Contact Us | MyBB | Return to Top | Return to Content | Lite (Archive) Mode | RSS Syndication