MyBB Community Forums

Full Version: Private Threads
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
(2012-10-18, 03:27 AM)imakecodmaps Wrote: [ -> ]http://mods.mybb.com/view/private-threads
Would require slight tweaks
Your images are broken, please reupload them
(2012-10-18, 03:27 AM)imakecodmaps Wrote: [ -> ]http://mods.mybb.com/view/private-threads

This method is not workable, and defeats the purpose of private threads.

You can let certain usergroups never post sure, but it should be up to the threads author to select who is allowed to post.
Not the admin, that's the goal of a private thread. That users can self moderate their thread to not allow certain groups.
(2012-10-18, 12:31 PM)anori Wrote: [ -> ]
(2012-10-18, 03:27 AM)imakecodmaps Wrote: [ -> ]http://mods.mybb.com/view/private-threads

This method is not workable, and defeats the purpose of private threads.

You can let certain usergroups never post sure, but it should be up to the threads author to select who is allowed to post.
Not the admin, that's the goal of a private thread. That users can self moderate their thread to not allow certain groups.
You can use it as a base, it already has part of the functionality, you just need to tweak it to your purpose...
I think that a possible approach is to make a postbit button that only appears on first thread in a forum you specify. That button to open a popup window/form similar to the report or reputation forms. In the form is the auto-complete to grab user names, that then defines who can reply. The hard bit is making the check against that list run without hitting the db every time, as that data should be cached and I suck at caching.

I would suggest taking a look at report.php and memberlist.php. Report php would help with the how to get popup window, memberlist would help with how to get the autocomplete. G33k's thank you like plugin is a good source for how to add to postbit, define forum and first post only.
(2012-10-18, 12:40 PM)Leefish Wrote: [ -> ]I think that a possible approach is to make a postbit button that only appears on first thread in a forum you specify. That button to open a popup window/form similar to the report or reputation forms. In the form is the auto-complete to grab user names, that then defines who can reply. The hard bit is making the check against that list run without hitting the db every time, as that data should be cached and I suck at caching.

I would suggest taking a look at report.php and memberlist.php. Report php would help with the how to get popup window, memberlist would help with how to get the autocomplete.
That's a good suggestion,
I would recommend looking at other plugins to see how they cache data, I learned how to:
- make settings
- make css files, and
- make templates
because of looking at plugin code Big Grin
Hmm, I know that Aniruddh, I learnt a lot looking at code too.

Have you ever heard the phrase "teaching your grandmother how to suck eggs"?

If not, I suggest you look it up Wink

* Leefish returns to enjoying her egg
(2012-10-18, 12:40 PM)Leefish Wrote: [ -> ]I think that a possible approach is to make a postbit button that only appears on first thread in a forum you specify. That button to open a popup window/form similar to the report or reputation forms. In the form is the auto-complete to grab user names, that then defines who can reply. The hard bit is making the check against that list run without hitting the db every time, as that data should be cached and I suck at caching.

I would suggest taking a look at report.php and memberlist.php. Report php would help with the how to get popup window, memberlist would help with how to get the autocomplete. G33k's thank you like plugin is a good source for how to add to postbit, define forum and first post only.

Have actually been thinking that myself..
Since what i am currently trying to do:

<?php
/*
*   ~~~~~ PRIVATE THREADS  ~~~~~~
*
* Allow users to create private threads.
* 
* Copyright 2012 Anori
*/

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

//Add hooks needed
$plugins->add_hook("newthread_start", "private_thread_newthread");
$plugins->add_hook("newthread_do_newthread_start", "private_thread_newthread_do");
$plugins->add_hook("datahandler_post_insert_thread_post", "private_thread_newthread_insert");

function private_thread_info()
{
	return array(
		"name" => "Private threads",
		"description" => "Lets users create Private threads",
		"website" => "http://community.mybb.com/user-59864.html",
		"author" => "Anori",
		"authorsite" => "http://community.mybb.com/user-59864.html",
		"version" => "1.0.0",
		"compatibility" => "16*"
	);
}

function private_thread_install()
{
	global $db, $mybb;
	
	$db->write_query = "CREATE TABLE IF NOT EXISTS `mybb_privatethread` (
			`id` int(11) unsigned NOT NULL auto_increment,
			`passw` varchar(255) NOT NULL default '',
			`uidname` varchar(255) NOT NULL default '',
			`tid` int(10) NOT NULL default '',
			PRIMARY KEY  (`id`)
			) ENGINE=MyISAM  DEFAULT CHARSET=utf8";
	
	$insert_array = array(
        'title'        => 'private_thread_no_permission',
        'template'    => $db->escape_string('<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
	<td class="thead" colspan="2"><span class="smalltext"><strong>You are not able to reply to this thread!</strong></span></td>
</tr>
<tr>
	<td class="trow1">
	<strong>This can because one of the following reasons:</strong></br>
	<ol>
		<li>The threads author has specified this to be a private thread. <br />
			You can ask the original author of the thread for the password if specified, or to be added to the users able to post.</li>
		<li>You inputted the wrong password when trying to reply to this thread. <br />
			Go back and try again, by using the correct password.<br />
			If the problem presist please contact the thread author for the correct password.<br />
			Otherwise contact the forum admin or a moderator</li>
		<li>You are by default not allowed to post and or reply in these sections.</li>
	</ol><br />
	<td class="trow1">
	<strong>
</tr>
</table>
<br />'),
        'sid'        => '-1',
        'version'    => '',
        'dateline'    => TIME_NOW
    );
	$db->insert_query("templates", $insert_array);
	
	$insert_array2 = array(
		'title'        => 'private_thread_thread_input',
        'template'    => $db->escape_string('<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
	<td class="thead" colspan="3"><strong>Private Thread settings</strong></td>
</tr>
<tr>
	<td class="tcat smalltext" colspan="3">Here you can add a password and/or username-uid to limit the people who can post in your thread.</td>
</tr>
{$pt_password}
{$pt_uidname}
</table>'),
		'sid'        => '-1',
        'version'    => '',
        'dateline'    => TIME_NOW
	);
	$db->insert_query("templates", $insert_array2);

	$insert_array3 = array(
		'title'        => 'private_thread_reply_input',
        'template'    => $db->escape_string('<tr>
<td class="trow2" width="20%"><strong>Thread password</strong></td>
<td class="trow2"><input type="text" class="textbox" name="ptu_password" size="40" maxlength="85" value="" tabindex="1" /></td>
</tr>'),
		'sid'        => '-1',
        'version'    => '',
        'dateline'    => TIME_NOW
	);
	$db->insert_query("templates", $insert_array3); 	
	
	$gid = $db->insert_query('settinggroups', array(
        'name' => 'privatethread',
        'title' => 'Private Threads',
        'description' => "Allow users to create private threads",
        'disporder' => 1,
        'isdefault' => 0
    ));
    $db->insert_query('settings', array(
        'name' => 'privatethread_enable',
        'title' => 'Enable or Disable Plugin',
        'description' => 'Enable or disable the plugin',
        'optionscode' => 'onoff',
        'value' => '1',
        'disporder' => 1,
        'gid' => $gid
    ));
    $db->insert_query('settings', array(
        'name' => 'privatethread_groups',
        'title' => 'Select the user groups',
        'description' => 'Select which user groups are allowed to create private threads.',
        'optionscode' => 'text',
        'value' => '1',
        'disporder' => 2,
        'gid' => $gid
    ));
	$db->insert_query('settings', array(
        'name' => 'privatethread_forums',
        'title' => 'Select the forums',
        'description' => 'Select in which forums users should be able to create private threads.',
        'optionscode' => 'text',
        'value' => '1',
        'disporder' => 3,
        'gid' => $gid
    ));
	$db->insert_query('settings', array(
        'name' => 'privatethread_protection',
        'title' => 'Select thread security',
        'description' => 'Select how users can protect their thread and make it private. Either through password, by username/uid or even by both',
        'optionscode' => 'radio
passw=Password
uidname=Username or UID
both=Both password and username UID',
        'value' => 'passw',
        'disporder' => 4,
        'gid' => $gid
    ));
    rebuild_settings();
}
function private_thread_is_installed()
{
	global $mybb, $db;
	
	$query = $db->simple_select("settinggroups", "name", "name = 'privatethread'");
	$result = $db->fetch_array($query);
	if($result)
	{
		return true;
	}
	else 
	{
		return false;
	}
}
function private_thread_activate()
{
	global $db, $mybb;
	require_once MYBB_ROOT.'/inc/adminfunctions_templates.php';
	
	find_replace_templatesets('editpost','#{\$attachbox}#','{\$pt_thread}\n{\$attachbox}');
	find_replace_templatesets('newthread','#{\$attachbox}#','{\$pt_thread}\n{\$attachbox}');
	
	find_replace_templatesets('newreply','#{\$posticons}#','{\$pt_reply}\n{\$posticons}');
	find_replace_templatesets('newthread','#{\$captcha}#','{\$pt_reply}\n{\$captcha}');
}
function private_thread_deactivate()
{
	global $db, $mybb;
	require_once MYBB_ROOT.'/inc/adminfunctions_templates.php';
	
	find_replace_templatesets('editpost','#{\$pt_thread}#','');
	find_replace_templatesets('newthread','#{\$pt_thread}#','');
	
	find_replace_templatesets('newreply','#{\$pt_reply}#','');
	find_replace_templatesets('newthread','#{\$pt_reply}#','');
}
function private_thread_uninstall()
{
	global $db, $mybb;
    
	$db->write_query("DROP TABLE mybb_privatethread");
	
	$db->delete_query("templates", "title IN ('private_thread_no_permission')");
	$db->delete_query("templates", "title IN ('private_thread_thread_input')");
	$db->delete_query("templates", "title IN ('private_thread_reply_input')");
	
    $db->delete_query("settinggroups", "name = ('privatethread')");
    $db->delete_query("settings", "name IN ('privatethread_enable')");
    $db->delete_query("settings", "name IN ('privatethread_groups')");
    $db->delete_query("settings", "name IN ('privatethread_forums')");
	$db->delete_query("settings", "name IN ('privatethread_protection')");
}

// Plugin functions. 

function private_thread_newthread()
{
	global $db, $mybb, $templates, $pt_password, $pt_uidname;
	
	$pt_password = '';
	$pt_uidname = '';
	
	$fid = intval($mybb->input['fid']);
	$gip = $mybb->user['usergroup'];
	$prot = $mybb->settings['privatethread_protection'];
	$forums = explode(',',$mybb->settings['privatethread_forums']);
	$groups = explode(',',$mybb->settings['privatethread_groups']);	
	if(in_array($fid,$forums))
	{
		if(in_array($gip,$groups))
		{
			if($prot == 'passw')
			{
				$pt_password = '<tr>
<td class="trow2" width="20%"><strong>Thread password</strong></td>
<td class="trow2"><input type="text" class="textbox" name="pta_password" size="40" maxlength="85" value="" tabindex="1" /></td>
</tr>';
				$pt_uidname = '<input type="hidden" name="pta_uidname" value="" />';
			}
			elseif ($prot == 'uidname')
			{
				$pt_password = '<input type="hidden" name="pta_password" value="" />';
				$pt_uidname = '<tr>
<td class="trow2" width="20%"><strong>Thread Username / UID</strong></td>
<td class="trow2"><textarea name="pta_uidname" cols="40" rows="5"></textarea></td>
</tr>';
			}
			elseif ($prot == 'both')
			{
				$pt_password = '<tr>
<td class="trow2" width="20%"><strong>Thread password</strong></td>
<td class="trow2"><input type="text" class="textbox" name="pta_password" size="40" maxlength="85" value="" tabindex="1" /></td>
</tr>';
				$pt_uidname = '<tr>
<td class="trow2" width="20%"><strong>Thread Username / UID</strong></td>
<td class="trow2"><textarea name="pta_uidname" cols="40" rows="5"></textarea></td>
</tr>';
			}
		}
	}
	eval("\$pt_thread = \"".$templates->get("private_thread_thread_input")."\";");
}
function private_thread_newthread_do()
{
	global $mybb, $db, $cache;
	$check = private_thread_check_fid();
	if($check == true)
	{
		$cache->update("pta_password_".$mybb->user['uid']."", $db->escape_string($mybb->input['pta_password']));
		$cache->update("pta_uidname_".$mybb->user['uid']."", $db->escape_string($mybb->input['pta_uidname']));
	}
}
function private_thread_newthread_insert(&$insert)
{
	global $db, $mybb, $cache;
	
	$check = private_thread_check_fid();
	if($check == true)
	{	
		$passw = $cache->read("pta_password_".$mybb->user['uid']."");
		$uidname = $cache->read("pta_uidname_".$mybb->user['uid']."");
		$tid = $insert->tid;
		
		if($passw != '' && $uidname != '')
		{
			$db->insert_query('privatethread', array('passw' => $passw, 'uidname' => $uidname, 'tid' => $tid));
		}
		elseif($uidname != '')
		{
			$db->insert_query('privatethread', array('passw' => $passw, 'uidname' => $uidname, 'tid' => $tid));
		}
		elseif($passw != '')
		{
			$db->insert_query('privatethread', array('passw' => $passw, 'uidname' => $uidname, 'tid' => $tid));
		}
		$db->query("DELETE FROM ".TABLE_PREFIX."datacache WHERE title='pta_password_".$mybb->user['uid']."'");
		$db->query("DELETE FROM ".TABLE_PREFIX."datacache WHERE title='pta_uidname_".$mybb->user['uid']."'");
	}
}
function private_thread_newreply()
{
	global $db, $mybb;
	
	$prot = $mybb->settings['privatethread_protection'];
	$check = private_thread_check_fid();
	if($check == true)
	{
		if($prot == 'passw')
		{
			eval("\$pt_reply = \"".$templates->get("private_thread_reply_input")."\";");
		}
		elseif($prot == 'uidname')
		{
			$pt_reply = '<input type="hidden" name="ptu_password" value="" />';
		}
		elseif($prot == 'both')
		{
			eval("\$pt_reply = \"".$templates->get("private_thread_reply_input")."\";");
		}
	}
}
function private_thread_quickreply()
{
	global $db, $mybb;
	
	$prot = $mybb->settings['privatethread_protection'];
	$check = private_thread_check_fid();
	if($check == true)
	{
		if($prot == 'passw')
		{
			$pta_password = $db->escape_string($mybb->input['pta_password']);
			if($pta_password != '')
			{
				eval("\$pt_reply = \"".$templates->get("private_thread_reply_input")."\";");
			}
		}
		elseif($prot == 'uidname')
		{
			$pta_uidname = $db->escape_string($mybb->input['pta_uidname']);
			if($pta_uidname != '')
			{
				$pt_reply = '<input type="hidden" name="ptu_password" value="" />';
			}
		}
		elseif($prot == 'both')
		{
			$pta_password = $db->escape_string($mybb->input['pta_password']);
			$pta_uidname = $db->escape_string($mybb->input['pta_uidname']);
			if($pta_password != '')
			{
				eval("\$pt_reply = \"".$templates->get("private_thread_reply_input")."\";");
			}
		}
	}
}
function private_thread_reply_do()
{
	global $mybb, $db;
	$check = private_thread_check_fid();
	if($check == true)
	{
		if($prot == 'passw')
		{
			$ptu_password = $db->escape_string($mybb->input['ptu_password']);
			$pta_password = $db->escape_string($mybb->input['pta_password']);
			if($pta_password != '')
			{
				if($pta_password != $ptu_password)
				{
					eval("\$private_thread_no_permission = \"".$templates->get("private_thread_no_permission")."\";");
					error($private_thread_no_permission);
				}
			}
		}
		elseif($prot == 'uidname')
		{
			$uid = $mybb->user['uid'];
			$pta_uidname = explode(',',$db->escape_string($mybb->input['pta_uidname']));
			if($mybb->input['pta_uidname'] != '')
			{
				if( ! in_array($uid, $pta_uidname)
				{
					eval("\$private_thread_no_permission = \"".$templates->get("private_thread_no_permission")."\";");
					error($private_thread_no_permission);
				}
			}
		}
		elseif($prot == 'both')
		{
			$uid = $mybb->user['uid'];
			$ptu_password = $db->escape_string($mybb->input['ptu_password']);
			
			$pta_password = $db->escape_string($mybb->input['pta_password']);
			$pta_uidname = explode(',',$db->escape_string($mybb->input['pta_uidname']));
			if($mybb->input['pta_uidname'] != '')
			{
				if( ! in_array($uid, $pta_uidname)
				{
					eval("\$private_thread_no_permission = \"".$templates->get("private_thread_no_permission")."\";");
					error($private_thread_no_permission);
				}
			}
			elseif($pta_password != '')
			{
				if($pta_password != $ptu_password)
				{
					eval("\$private_thread_no_permission = \"".$templates->get("private_thread_no_permission")."\";");
					error($private_thread_no_permission);
				}
			}
			elseif($mybb->input['pta_uidname'] != '' && $pta_password != '')
			{
				if( ! in_array($uid, $pta_uidname)
				{
					eval("\$private_thread_no_permission = \"".$templates->get("private_thread_no_permission")."\";");
					error($private_thread_no_permission);
				}
				if($pta_password != $ptu_password)
				{
					eval("\$private_thread_no_permission = \"".$templates->get("private_thread_no_permission")."\";");
					error($private_thread_no_permission);
				}				
			}
		}		
	}
}

// in above still have to add query stuff

function private_thread_edit()
{
}
function private_thread_edit_do()
{
}

function private_thread_check_fid()
{
	global $db, $mybb;
	$fid = intval($mybb->input['fid']);
	$forums = explode(',',$mybb->settings['privatethread_forums']);
	
	if(in_array($fid,$forums))
	{
		return true;
	}
	return false;
}

Above code is not done! and not functional!

Is starting to give me a headache.
Honestly after trying so many things now i think i will try the following:

- remove the quickreply and replace it with a message. And remove the new reply buttons.
- if somebody does manage to get to the new reply page i will simply error out an error page.
- and remove the option for passwords simply leave it at user IDs and names.

One thing i am still wondering about is if their is a way to auto complete username inputs.
Memberlist.php uses the autocomplete function - that should do it. I am NOT sure if that is a scriptaculous thing though Toungue
Pages: 1 2 3 4