I'll keep this idea as "Plan B".
In the meantime, I went on and created editor for user lists. This requires even more edits.
Step 0. Create a forum for stroing private threads and note its fid - you'll need it in step 6.
Step 3 (replaces the one before):
Find
// Get the thread details from the database.
$thread = get_thread($mybb->input['tid']);
Insert after:
$userlist = $thread['userlist'];
if ($userlist != '')
{
$ulist = explode(",", $thread['userlist']);
$confuserarr = array();
$canview = FALSE;
foreach ($ulist as $user)
{
if ($user == $mybb->user['uid'])
$canview = TRUE;
$dbuser = get_user($user);
$uname = format_name($dbuser['username'], $dbuser['usergroup'], $dbuser['displaygroup']);
$uuu = build_profile_link($uname, $user);
$confuserarr[] = $uuu;
}
if ($canview === FALSE)
error($lang->error_invalidthread);
$confusers = implode(', ', $confuserarr);
$confusers = '<tr><td colspan="2">This thread can be viewed by: '.$confusers." <a href=\"#\" onclick=\"MyBB.popupWindow('misc.php?action=editulist&tid=".$thread['tid']."', 'userList', 350, 380)\"><strong>[Edit]</strong></a></td></tr>";
}
else
{
$confusers = "<tr><td><div>This is a public thread</div></td></tr>";
}
Step 5. Create a new template
misc_editulist:
<html>
<head>
<title>Edit user list</title>
{$headerinclude}
<style type="text/css">
body {
text-align: left;
}
</style>
</head>
<body style="margin:0; padding: 4px; top: 0; left: 0;">
<table width="100%" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" border="0" align="center" class="tborder">
<tr>
<td class="thead">
<div class="float_right" style="margin-top: 3px;"><span class="smalltext"><a href="#" onclick="window.close();">{$lang->close}</a></span></div>
<div><strong>Edit user list</strong></div>
</td>
</tr>
<tr>
<td class="trow2">
<div style="overflow: auto; height: 300px;"><table class="post_author" style="border-style: dashed border-width: 1pt" width="100%">{$ulist}</table> </div>
</td>
</tr>
<tr>
<td>
<form method="get" action="misc.php" name="addusr">
<input type="hidden" name="action" value="editulist" />
<input type="hidden" name="tid" value="{$tid}" />
<select name="adduser">
{$allusers}
</select>
<input type="submit" value="Add" class="submit_button" name="do_add" />
</form>
</td>
</tr>
</table>
</body>
</html>
Step 6. Modify
misc.php:
Find
elseif($mybb->input['action'] == "whoposted")
Insert
before:
elseif($mybb->input['action'] == "editulist")
{
global $db;
$tid = $mybb->input['tid'];
$thread = get_thread($mybb->input['tid']);
if(($mybb->user['uid'] == 0) || ($thread['uid'] != $mybb->user['uid'] && !is_moderator($thread['fid'])))
{
error_no_permission();
}
if (!isset($mybb->input['tid']))
{
error("No tid");
}
if ($thread['fid'] != '3') //!!! Change 3 to fid from step 0
{
error("Wrong fid");
}
$ulist = $thread['userlist'];
$ulist_t = explode(",", $ulist);
foreach ($ulist_t as $key)
{
if ($key == $thread['uid'])
$ulist_a[$key] = 0;
else
$ulist_a[$key] = 1;
}
if($mybb->input['removeuser'])
{
if ($ulist_a[$mybb->input['removeuser']] === 1)
{
foreach($ulist_a as $uid => $flag)
{
if($uid == $mybb->input['removeuser'])
{
unset($ulist_a[$uid]);
$key = array_search($uid, $ulist_t);
unset($ulist_t[$key]);
}
}
$ulist = implode(',', $ulist_t);
$db->update_query("threads", array('userlist' => $ulist), "tid='".$tid."'");
}
}
if ($mybb->input['adduser'])
{
$inlist = isset($ulist_a[$mybb->input['adduser']]);
if ($inlist === FALSE)
{
$dbuser = get_user($mybb->input['adduser']);
if (isset($dbuser['username']))
{
$ulist_a[$mybb->input['adduser']] = 1;
$ulist_t[] = $mybb->input['adduser'];
}
$ulist = implode(',', $ulist_t);
$db->update_query("threads", array('userlist' => $ulist), "tid='".$tid."'");
}
}
$ulist = "<tr><th>Username</th><th>Remove</th></tr>";
foreach ($ulist_a as $user => $flag)
{
$dbuser = get_user($user);
if (!$dbuser['username'] || $flag == 0) //no such user -> skip
continue;
//format link
$uname = format_name($dbuser['username'], $dbuser['usergroup'], $dbuser['displaygroup']);
$uuu = build_profile_link($uname, $user);
$ulist = $ulist."<tr><td width=\"95%\">".$uuu."</td><td>";
if ($flag == 1)
$ulist = $ulist.'<a href="misc.php?action=editulist&tid='.$thread['tid'].'&removeuser='.$user.'">[X]</a>';
else
$ulist = $ulist.'[Owner]';
$ulist = $ulist.'</td></tr><br/>'."\n";
}
//Build list for select --> $allusers
$allulist = $db->simple_select('users', 'uid, username');
$allusers = "<option value=\"-1\">--- Select user ---</option> ";
while ($ulist_r = $db->fetch_array($allulist))
{
if (!is_banned_username($ulist_r['username']) && !isset($ulist_a[$ulist_r['uid']]))
$allusers = $allusers.'<option value="'.$ulist_r['uid'].'">'.$ulist_r['username'].'</option>\n';
}
eval("\$editulist = \"".$templates->get("misc_editulist")."\";");
output_page($editulist);
}
And here goes the last part: modifying newthread script to incorporate user lists.
Step 7. Modify template
newreply:
Find
</tr>
{$loginbox}
<tr>
Replace with
</tr>
{$loginbox}
{$ulistbox}
<tr>
Step 8. Create template
ulistbox:
<tr>
<td class="trow2"><strong>User access list (comma separated): </strong></td>
<td class="trow2"><input type="text" class="textbox" name="userlist" size="30" value="{$username}" /></td>
</tr>
Step 9. Modify
inc/datahandlers/post.php:
Find
if($draft_check)
{
$this->thread_insert_data = array(
"subject" => $db->escape_string($thread['subject']),
"icon" => intval($thread['icon']),
"username" => $db->escape_string($thread['username']),
"dateline" => intval($thread['dateline']),
"lastpost" => intval($thread['dateline']),
"lastposter" => $db->escape_string($thread['username']),
"visible" => $visible
);
$plugins->run_hooks_by_ref("datahandler_post_insert_thread", $this);
replace with
if($draft_check)
{
$this->thread_insert_data = array(
"subject" => $db->escape_string($thread['subject']),
"icon" => intval($thread['icon']),
"username" => $db->escape_string($thread['username']),
"dateline" => intval($thread['dateline']),
"lastpost" => intval($thread['dateline']),
"lastposter" => $db->escape_string($thread['username']),
"visible" => $visible,
"userlist" => $thread['userlist']
);
$plugins->run_hooks_by_ref("datahandler_post_insert_thread", $this);
Find
// Inserting a new thread into the database.
else
{
$this->thread_insert_data = array(
"fid" => $thread['fid'],
"subject" => $db->escape_string($thread['subject']),
"icon" => intval($thread['icon']),
"uid" => $thread['uid'],
"username" => $db->escape_string($thread['username']),
"dateline" => intval($thread['dateline']),
"lastpost" => intval($thread['dateline']),
"lastposter" => $db->escape_string($thread['username']),
"views" => 0,
"replies" => 0,
"visible" => $visible,
"notes" => ''
);
$plugins->run_hooks_by_ref("datahandler_post_insert_thread", $this);
replace with
$this->thread_insert_data = array(
"fid" => $thread['fid'],
"subject" => $db->escape_string($thread['subject']),
"icon" => intval($thread['icon']),
"uid" => $thread['uid'],
"username" => $db->escape_string($thread['username']),
"dateline" => intval($thread['dateline']),
"lastpost" => intval($thread['dateline']),
"lastposter" => $db->escape_string($thread['username']),
"views" => 0,
"replies" => 0,
"visible" => $visible,
"notes" => '',
"userlist" => $thread['userlist']
);
$plugins->run_hooks_by_ref("datahandler_post_insert_thread", $this);
Step 10. Modify
newthread.php:
Find
// Set the thread data that came from the input to the $thread array.
$new_thread = array(
"fid" => $forum['fid'],
"subject" => $mybb->input['subject'],
"icon" => $mybb->input['icon'],
"uid" => $uid,
"username" => $username,
"message" => $mybb->input['message'],
"ipaddress" => get_ip(),
"posthash" => $mybb->input['posthash']
);
insert after
//Build userlist
$unlist = trim($mybb->input['userlist'], ", ");
$unarr = explode(",", $unlist);
$uidarr = array($mybb->user['uid']);
foreach ($unarr as $uname)
{
$uname = trim($uname);
$q = $db->simple_select("users", "uid", "username = '".$uname."'", array ("limit_start" => 0, "limit" => 1));
$userid = $db->fetch_field($q, "uid");
if (isset($userid) && (array_search($userid, $uidarr) === FALSE))
$uidarr[] = $userid;
}
$uidlist = implode(",", $uidarr);
$new_thread['userlist'] = $uidlist;
Find
$plugins->run_hooks("newthread_start");
insert after:
if ($fid == 3) //!!!! Replace with one from Step 0
{
if (!isset($username))
{
$username = $mybb->user['username'];
eval("\$ulistbox = \"".$templates->get("ulistbox")."\";");
unset($username);
}
else
eval("\$ulistbox = \"".$templates->get("ulistbox")."\";");
}
else
$ulistbox = "";
So, if anyone can help me with:
a) showing only the threads to which the user has access
b) showing correct thread count
c) correct pagination
d) correct "last post/thread" and "has new msg" state
then this mod will be complete.