MyBB Community Forums

Full Version: [TuT]: Auto Post Warn
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Works With 1.6.x
Original Author: thebod

First of all you have to find this in warnings.php (line 248):
$db->insert_query("warnings", $new_warning);

Add below:
$plugins->run_hooks("warnings_do_warn_insert");

Then create a file named 'warnpost.php' in inc/plugins with the following content:

<?php

/*
    Warn Post Extension
    
    Version 0.1
    
    Autor: thebod
    Homepage: http://www.b-ike.de/
    
    Erstellt bei Userverwarnungen einen Thread.
    
    Alpha-Testversion, bitte anpassen!
    
    Lizenz: Ihr dürft alles machen, lasst nur meinen Namen bitte drin ;)
*/

if(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
global $into_fid;

/*********** CHANGE HERE ***********/

$into_fid = 2;  // Foren ID

/***********************************/

$plugins->add_hook("warnings_do_warn_insert", "warnpost_doAction");

function warnpost_info()
{
    return array(
        "name"            => "Warn Post",
        "description"    => "Erstellt einen Thread beim Verwarnungen von Userns",
        "website"        => "http://www.schwarzernorden.de/",
        "author"        => "thebod",
        "authorsite"    => "http://www.b-ike.de/",
        "version"        => "0.1",
        "guid"             => "",
        "compatibility" => "*"
    );
}

function warnpost_doAction()
{
    global $mybb, $new_warning, $into_fid;
    
    require_once MYBB_ROOT."inc/datahandlers/post.php";
    $posthandler = new PostDataHandler("insert");
    $posthandler->action = "thread";
    
    $user = get_user($new_warning['uid']);
    
    $pmNotice = false;
    if($mybb->input['send_pm'] == 1 && $group_permissions['canusepms']  != 0 && $user['receivepms'] != 0 && $mybb->settings['enablepms'] != 0)
        $pmNotice = true;
    
    $new_thread = array(
        "fid" => $into_fid,
        "subject" => "Warning User " . $user['username'],
        "prefix" => '',
        "icon" => 0,
        "uid" => $mybb->user['uid'],
        "username" => $mybb->user['username'],
        "message" =>"Warning User " . $user['username']."\n".
                    "Notiz:[QUOTE]" . $new_warning['notes'] . "[/QUOTE]\n".
                    "Punkte: " . $new_warning['points'] . "\n".
                    ($pmNotice ? "Der User wurde per PM benachrichtigt.\n" : ''),
        "ipaddress" => get_ip(),
        "posthash" => $mybb->input['posthash']
    );
    
    $posthandler->set_data($new_thread);
    
    $posthandler->validate_thread();
    
    $posthandler->insert_thread();
}

You only have to change "$into_fid". That's the Forums ID.
It's a German Tutorial. Therefore, it is "Punkte" for "Points" and "Notiz" for "Notice".
You can change it for yourself.
Then you have to activate it in ACP. That is! Wink
so when a user is warned, it automatically posts a new thread about it ... fine Smile
^ well, this topic actually provides the plug-in code ; however it needs a core file edit !!
Right. Smile
warnpost.php is the code for a plugin. If you create the file you have a plugin. Wink
But where i can get forums id? Now it post into the first forum.
On your fourm index click on you chosen forum and in the address bar there should be fid=X (X will be the forum ID).
Thank you Jordan.
Your welcome.
What does this do? Any picture or explanation?
As stated above, a few screenshots would be great.
It would also be awesome if you we're able to choose which usergroup would be able to see the posts.