<?php
/*
* Thread Protected By Password for MyBB 1.2.9
* By: LeX-
* Website: http://www.thingiej.be
* Version: 1.0
*/
// ADD HOOK FOR NEW THREAD [SHOWING PASSWORDBOX]
$plugins->add_hook('newthread_start', 'tp');
// ADD HOOK FOR NEW THREAD [INSERT NEW THREAD]
$plugins->add_hook('newthread_do_newthread_end', 'tp_thread');
// ADD HOOK FOR SHOW THREAD [CHECK PASSWORD]
$plugins->add_hook('showthread_start', 'tp_show');
// ADD HOOK FOR EDITPOST [SHOWING PASSWORDBOX]
$plugins->add_hook('editpost_start', 'tp_edit');
// ADD HOOK FOR EDITPOST [UPDATING PASSWORD]
$plugins->add_hook('editpost_do_editpost_end', 'tp_do_edit');
function tp_info()
{
return array(
'name' => 'Thread Protected By Password v1.0',
'description' => 'Makes It Possible So Certain UserGroups Can Enter A Thread Protecting Password.',
'website' => 'http://www.thingiej.be/',
'author' => 'LeX-',
'authorsite' => 'http://www.thingiej.be/',
'version' => '1.0',
);
}
function tp_activate()
{
global $db, $mybb;
// SETTINGS
$tp_group = array(
"gid" => "NULL",
"name" => "tp_options",
"title" =>"ThreadPassword Settings",
"description" => "Settings for the TP Plugin.",
"disporder" => "3",
"isdefault" => "no",
);
$db->insert_query("settinggroups", $tp_group);
$gid = $db->insert_id();
$new_setting = array(
'name' => 'tp_status',
'title' => 'ThreadPassword__ Status',
'description' => 'Makes It Possible So Certain UserGroups Can Enter A Thread Protecting Password.',
'optionscode' => 'yesno',
'value' => 'yes',
'disporder' => '1',
'gid' => intval($gid),
);
$db->insert_query('settings', $new_setting);
$new_setting2 = array(
'name' => 'tp_groups',
'title' => 'ThreadPassword__ Groups',
'description' => 'Which Groups Can Enter A Password For ThreadProtection. [Seperate By Comma]',
'optionscode' => 'text',
'value' => '',
'disporder' => '2',
'gid' => intval($gid),
);
$db->insert_query('settings', $new_setting2);
$new_setting3 = array(
'name' => 'tp_excludes',
'title' => 'ThreadPassword__ Excludes',
'description' => 'Which Groups Dont Need A Check When Trying To View A Thread. [Seperate By Comma]',
'optionscode' => 'text',
'value' => '',
'disporder' => '3',
'gid' => intval($gid),
);
$db->insert_query('settings', $new_setting3);
rebuildsettings();
// ALTERING
//$db->query("ALTER TABLE `".TABLE_PREFIX."threads` ADD `password` VARCHAR(20) NOT NULL;");
// TEMPLATES
$tp_template = array(
"tid" => NULL,
"title" => 'newthread_tp',
"template" => $db->escape_string('<tr>
<td class="trow2" width="20%"><strong>Password:</strong></td>
<td class="trow2"><input type="text" class="textbox" id="password" name="password" size="40" value="{$password}" tabindex="1" /><span class=\"smalltext\"> [ Password Length :: Min. 3; Max. 20 ]</span></td>
</tr>'),
"sid" => "-1",
"version" => "1.0",
"dateline" => "1148741714",
);
$db->insert_query("templates", $tp_template);
require MYBB_ROOT.'/inc/adminfunctions_templates.php';
// ADD TPBOX [ NEWTHREAD ]
find_replace_templatesets("newthread", '#{\$posticons}#', "{\$tp}{\$posticons}");
// ADD TPBOX [ EDITPOST ]
find_replace_templatesets("editpost", '#{\$posticons}#', "{\$tp}{\$posticons}");
}
function tp_deactivate()
{
global $db, $mybb;
// SETTINGS
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='tp_status'");
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='tp_groups'");
$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name='tp_excludes'");
$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='tp_options'");
rebuildsettings();
// ALTERING
//$db->query("ALTER TABLE `"."threads` DROP `password`;");
// TEMPLATES
$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title = 'newthread_tp'");
// TEMPLATECHANGES
require MYBB_ROOT.'/inc/adminfunctions_templates.php';
// REMOVE PASSWORDBOX [ NEWTHREAD ]
find_replace_templatesets("newthread", '#'.preg_quote('{$tp}').'#', '',0);
// REMOVE PASSWORDBOX [ EDITPOST ]
find_replace_templatesets("editpost", '#'.preg_quote('{$tp}').'#', '',0);
}
function tp()
{
global $db, $mybb, $templates, $tp, $status;
$status = '';
if($mybb->settings['tp_status'] != "no")
{
if($mybb->settings['tp_groups'] != "")
{
// EXPLODE
$groups = explode(",", $mybb->settings['tp_groups']);
// USERGROUP
$usergroup = $mybb->user['usergroup'];
// CHECK
if(in_array($usergroup, $groups) || $usergroup == 4 || $usergroup == 3 || $usergroup == 6)
{
$status = "ok";
}
}
else if($mybb->user['usergroup'] == 4)
{
$status = "ok";
}
else if($mybb->user['usergroup'] == 3)
{
$status = "ok";
}
else if($mybb->user['usergroup'] == 6)
{
$status = "ok";
}
if($status == "ok")
{
eval("\$tp = \"".$templates->get("newthread_tp")."\";");
}
}
}
function tp_thread()
{
global $db, $mybb, $thread_info;
// INCOMING
$password = $db->escape_string($mybb->input['password']);
// LENGTH
$length = my_strlen($password);
// CHECK
if($password && $length >= 3 && $length < 20)
{
// TID
$tid = intval($thread_info['tid']);
// ENTER PASSWORD IN DB
$update = array(
"password" => $password
);
$u_check = $db->update_query("threads", $update, "tid='".$tid."'");
if(!$u_check)
{
error("Error While Tryin' To Enter The Password Into The Database", "Thread Protection System");
}
// SET COOKIE
my_setcookie("threadpass[$tid]", md5($mybb->user['uid'].$password), null, true);
}
/*
else
{
error("Thread Has Been Made But Is Not Protected Because The Password Didn't Meet The Standards", "Thread Protection System");
}
*/
}
function tp_show()
{
global $db, $mybb, $thread, $status;
$status = '';
if($mybb->settings['tp_status'] != "no")
{
if($mybb->settings['tp_excludes'] != "")
{
// EXPLODE
$groups = explode(",", $mybb->settings['tp_excludes']);
// USERGROUP
$usergroup = $mybb->user['usergroup'];
// CHECK
if(in_array($usergroup, $groups) || $usergroup == 4 || $usergroup == 3 || $usergroup == 6)
{
$status = "ok";
}
else if($mybb->user['usergroup'] == 4)
{
$status = "ok";
}
else if($mybb->user['usergroup'] == 3)
{
$status = "ok";
}
else if($mybb->user['usergroup'] == 6)
{
$status = "ok";
}
if($status == "")
{
$password = $thread['password'];
check_thread_password($thread['tid'], $password);
}
}
else
{
$password = $thread['password'];
check_thread_password($thread['tid'], $password);
}
}
}
function tp_edit()
{
global $db, $mybb, $templates, $tp, $status;
$status = '';
if($mybb->settings['tp_status'] != "no")
{
// CHECK IF THERE WAS A PASSWORD SET
// INCOMING
$pid = intval($mybb->input['pid']);
$query = $db->query("
SELECT t.password, p.tid
FROM ".TABLE_PREFIX."posts p
LEFT JOIN ".TABLE_PREFIX."threads t ON (p.tid=t.tid)
WHERE t.firstpost = {$pid}
");
$password = $db->fetch_field($query, "password");
if($password != "")
{
if($mybb->settings['tp_groups'] != "")
{
// EXPLODE
$groups = explode(",", $mybb->settings['tp_groups']);
// USERGROUP
$usergroup = $mybb->user['usergroup'];
// CHECK
if(in_array($usergroup, $groups) || $usergroup == 4 || $usergroup == 3 || $usergroup == 6)
{
$status = "ok";
}
}
else if($mybb->user['usergroup'] == 4)
{
$status = "ok";
}
else if($mybb->user['usergroup'] == 3)
{
$status = "ok";
}
else if($mybb->user['usergroup'] == 6)
{
$status = "ok";
}
}
if($status == "ok")
{
eval("\$tp = \"".$templates->get("newthread_tp")."\";");
}
}
}
function tp_do_edit()
{
global $db, $mybb, $templates, $tp, $tid;
//INCOMING
$password = $db->escape_string($mybb->input['password']);
// LENGTH
$length = my_strlen($password);
// CHECK
if($password && $length >= 3 && $length < 20)
{
// ENTER PASSWORD IN DB
$update = array(
"password" => $password
);
$u_check = $db->update_query("threads", $update, "tid='".$tid."'");
if(!$u_check)
{
error("Error While Tryin' To Enter The Password Into The Database", "Thread Protection System");
}
// SET COOKIE
my_setcookie("threadpass[$tid]", md5($mybb->user['uid'].$password), null, true);
}
}
function check_thread_password($tid, $password="")
{
global $mybb, $header, $footer, $headerinclude, $theme, $templates, $lang;
$showform = 1;
if($password)
{
if($mybb->input['pwverify'])
{
if($password == $mybb->input['pwverify'])
{
my_setcookie("threadpass[$tid]", md5($mybb->user['uid'].$mybb->input['pwverify']), null, true);
$showform = 0;
}
else
{
eval("\$pwnote = \"".$templates->get("forumdisplay_password_wrongpass")."\";");
$showform = 1;
}
}
else
{
if(!$_COOKIE['threadpass'][$tid] || ($_COOKIE['threadpass'][$tid] && md5($mybb->user['uid'].$password) != $_COOKIE['threadpass'][$tid]))
{
$showform = 1;
}
else
{
$showform = 0;
}
}
}
else
{
$showform = 0;
}
if($showform)
{
$_SERVER['REQUEST_URI'] = htmlspecialchars_uni($_SERVER['REQUEST_URI']);
eval("\$pwform = \"".$templates->get("forumdisplay_password")."\";");
output_page($pwform);
exit;
}
}
?>