<?php
/***************************************************************************
*
* Dice roller plugin (/inc/plugins/diceroll.php)
* Author: Shadows
* Copyright: © 2009-2010 Shadows
*
* Website: http://geekhelps.net
* License: inside readme
*
* Adds the option to roll a dice in a certain posts
*
***************************************************************************/
if(!defined("IN_MYBB"))
die("This file cannot be accessed directly.");
// add hooks
$plugins->add_hook("newreply_end", "diceroll_replies");
$plugins->add_hook("newreply_do_newreply_end", "diceroll_roll");
$plugins->add_hook("postbit", "diceroll_show");
$plugins->add_hook("showthread_end", "diceroll_quick");
function diceroll_info()
{
return array(
"name" => "MyDiceroller",
"description" => "Adds the option to roll a dice in certain forums for certain usergroups",
"website" => "http://geekhelps.net",
"author" => "Shadows",
"authorsite" => "http://geekhelps.net",
"version" => "1.10",
"guid" => "d69a9792246d9dcd25a2d8e391513077",
"compatibility" => "14*"
);
}
function diceroll_activate()
{
global $db, $lang;
// create settings group
$insertarray = array(
'name' => 'myroll',
'title' => 'Dice roller',
'description' => "A MyBB plugin to roll dices in posts",
'disporder' => 1,
'isdefault' => 0
);
$gid = $db->insert_query("settinggroups", $insertarray);
// add settings
$setting0 = array(
"sid" => NULL,
"name" => "maxfaces",
"title" => "Amount of dices to roll",
"description" => "Please enter a number (Usually 2)",
"optionscode" => "text",
"value" => "2",
"disporder" => 1,
"gid" => $gid
);
$db->insert_query("settings", $setting0);
$setting1 = array(
"sid" => NULL,
"name" => "diceroll_groups",
"title" => "Usergroup IDs allowed to roll dices",
"description" => "Seperate them by commas. - 0 for none",
"optionscode" => "text",
"value" => "2, 3, 4, 5, 6",
"disporder" => 1,
"gid" => $gid
);
$db->insert_query("settings", $setting1);
$setting2 = array(
"sid" => NULL,
"name" => "diceroll_forums",
"title" => "In which forum IDs, are users(depending on above setting) allowed to roll dices?",
"description" => "Seperate them by commas.",
"optionscode" => "text",
"value" => "1",
"disporder" => 1,
"gid" => $gid
);
$db->insert_query("settings", $setting2);
rebuild_settings();
// add templates
require "../inc/adminfunctions_templates.php";
find_replace_templatesets("newreply", '#'.preg_quote('{$lang->options_sig}</label>').'#', '{$lang->options_sig}</label>{$rolldice}');
find_replace_templatesets("postbit", '#'.preg_quote('{$post[\'user_details\']}').'#', '{$post[\'user_details\']}<!-- dice -->{$post[\'diceroll\']}<!-- end dice -->');
find_replace_templatesets("postbit_classic", '#'.preg_quote('{$post[\'user_details\']}').'#', '{$post[\'user_details\']}<!-- dice -->{$post[\'diceroll\']}<!-- end dice -->');
find_replace_templatesets("showthread_quickreply", '#'.preg_quote('{$lang->message_note}<br /><br />').'#', '{$lang->message_note}<br /><br /><!--quickrolling-->');
$db->query('ALTER TABLE ' . TABLE_PREFIX . 'posts ADD rolldice VARCHAR(1000) NOT NULL');
}
function diceroll_deactivate()
{
global $db, $mybb;
// delete settings group
$db->delete_query("settinggroups", "name = 'myroll'");
// remove settings
$db->delete_query('settings', 'name IN ( \'maxfaces\')');
rebuild_settings();
require "../inc/adminfunctions_templates.php";
find_replace_templatesets("newreply", '#'.preg_quote('{$rolldice}').'#', "",0);
find_replace_templatesets("postbit", '#'.preg_quote('<!-- dice -->{$post[\'diceroll\']}<!-- end dice -->').'#', "",0);
find_replace_templatesets("postbit_classic", '#'.preg_quote('<!-- dice -->{$post[\'diceroll\']}<!-- end dice -->').'#', "",0);
find_replace_templatesets("showthread_quickreply", '#'.preg_quote('<!--quickrolling-->').'#', "",0);
$db->query('ALTER TABLE ' . TABLE_PREFIX . 'posts DROP rolldice');
}
function diceroll_show(&$post)
{
global $mybb, $db, $fid, $roll, $lang;
$lang->load("mydiceroller");
//wrong forum? don't show it then!
//= 0? then he didn't roll the dice, don't show it then!
if($post['rolldice'] == 'not' || $post['rolldice'] == '')
{
return false;
//DID NOT ROLL DICES..
}
$forums = explode(",",$mybb->settings['diceroll_forums']);
if(!in_array($fid, $forums))
{
return false;
}
//$roll = $post['rolldice'];
$roll = unserialize($post['rolldice']);
$post['diceroll'] = "<br />";
$post['diceroll'] .= "<b>" . $lang->rolled . " </b>";
foreach($roll as $key => $nr)
{
//$post['diceroll'] .= "$value |";
$post['diceroll'] .= "<img src=\"images/dice/". $nr.".png\" alt=\"dice - " . $nr . "\" hspace=\"1\" />";
}
return $post;
}
function diceroll_roll()
{
global $mybb, $rolled, $rolldice, $rolldices, $pid, $db, $fid, $roll, $ser;
//is he the right user in the right forum?
if($mybb->input['myroll'] == false)
{
//DO NOT ROLL DICE
return false;
}
$groups = explode(",",$mybb->settings['diceroll_groups']);
$forums = explode(",",$mybb->settings['diceroll_forums']);
if(!in_array($fid, $forums))
{
return false;
}
if($mybb->settings['diceroll_groups'] == '')
{
return false;
}
if(!in_array($mybb->user['usergroup'], $groups))
{
$additional = explode(',', $mybb->user['additionalgroups']);
if ($additional)
{
if(!array_intersect($additional, $groups))
{
return false;
}
}
else
return false;
}
for ($counter = 1; $counter <= $mybb->settings['maxfaces']; $counter++)
{
$roll[] = mt_rand(1,6);
}
$ser = serialize($roll);
//$rolled = mt_rand(1,6);
$rolldices = array(
"rolldice" => $ser,
);
$db->update_query("posts", $rolldices, "pid='{$pid}'");
}
function diceroll_replies()
{
//for the newreply template..
global $mybb, $db, $rolldice, $fid, $lang;
$lang->load("mydiceroller");
//is he the right user in the right forum?
$groups = explode(",",$mybb->settings['diceroll_groups']);
$forums = explode(",",$mybb->settings['diceroll_forums']);
if(!in_array($fid, $forums))
{
return false;
}
if($mybb->settings['diceroll_groups'] == '')
{
return false;
}
if(!in_array($mybb->user['usergroup'], $groups))
{
$additional = explode(',', $mybb->user['additionalgroups']);
if ($additional)
{
if(!array_intersect($additional, $groups))
{
return false;
}
}
else
return false;
}
$rolldice = '<br /><label><input type="checkbox" class="checkbox" name="myroll" id="myroll"/> ' . $lang->checkbox . '</label>';
}
function diceroll_quick()
{
global $mybb, $db, $showthread, $fid, $lang;
$lang->load("mydiceroller");
//is he the right user in the right forum?
$groups = explode(",",$mybb->settings['diceroll_groups']);
$forums = explode(",",$mybb->settings['diceroll_forums']);
if(!in_array($fid, $forums))
{
return false;
}
if($mybb->settings['diceroll_groups'] == '')
{
return false;
}
if(!in_array($mybb->user['usergroup'], $groups))
{
$additional = explode(',', $mybb->user['additionalgroups']);
if ($additional)
{
if(!array_intersect($additional, $groups))
{
return false;
}
}
else
return false;
}
$checkbox = '<label><input type="checkbox" class="checkbox" name="myroll" id="myroll"/> <strong>' . $lang->quick . '</strong></label><br /> ';
$showthread = str_replace('<!--quickrolling-->', $checkbox, $showthread);
return $showthread;
}
?>