MyBB Community Forums

Full Version: Anonymous Posting mod [RELEASE]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
If anyone is interested in a code modification (no plugin, sorry)
to allow anonymous posting (without enabling guest posting), here it is :

Create a new registered user (in the admin cp) that will be used as sock puppet.
Take note of the User ID.

HINT : I suggest to set the options for the sock puppet to disallow users to send PM and eMails, etc

Edit the following templates :

newreply
newthread

Find :
<label><input type="checkbox" class="checkbox" name="postoptions[signature]" value="1" tabindex="6"{$postoptionschecked['signature']} /> {$lang->options_sig}</label>

Add :
<label><input type="checkbox" class="checkbox" name="postoptions[anonymous]" value="1" tabindex="6" /> Anonymously</label>

Edit the following PHPs in the forum root
newreply.php
newthread.php

Find in newreply.php:
	$post = array(
		"tid" => $mybb->input['tid'],
		"replyto" => $mybb->input['replyto'],
		"fid" => $thread['fid'],
		"subject" => $mybb->input['subject'],
		"icon" => $mybb->input['icon'],
		"uid" => $uid,
		"username" => $username,
		"message" => $mybb->input['message'],
		"ipaddress" => get_ip(),
		"posthash" => $mybb->input['posthash']
	);

Add BELOW it
	if ($mybb->input['postoptions']['anonymous']  == 1)
	{
	$post = array(
		"tid" => $mybb->input['tid'],
		"replyto" => $mybb->input['replyto'],
		"fid" => $thread['fid'],
		"subject" => $mybb->input['subject'],
		"icon" => $mybb->input['icon'],
		"uid" => XXXX,
		"username" => 'Anonymous',
		"message" => $mybb->input['message'],
		"ipaddress" => get_ip(),
		"posthash" => $mybb->input['posthash']
	);
	}

Replace XXXX with the plain user id of the created sock puppet.

You have to do this twice in the script. (just search it)

Now edit newthread.php

Find :
	
$new_thread = array(
		"fid" => $forum['fid'],
		"subject" => $mybb->input['subject'],
		"prefix" => $mybb->input['threadprefix'],
		"icon" => $mybb->input['icon'],
		"uid" => $uid,
		"username" => $username,
		"message" => $mybb->input['message'],
		"ipaddress" => get_ip(),
		"posthash" => $mybb->input['posthash']
	);

Add BELOW it :
	if($mybb->input['postoptions']['anonymous'] == 1)
	{
	$new_thread = array(
		"fid" => $forum['fid'],
		"subject" => $mybb->input['subject'],
		"prefix" => $mybb->input['threadprefix'],
		"icon" => $mybb->input['icon'],
		"uid" => XXXX,
		"username" => 'Anonymous',
		"message" => $mybb->input['message'],
		"ipaddress" => get_ip(),
		"posthash" => $mybb->input['posthash']
	);
	}	

Again, replace XXXX with the userid of the sock puppet
And again : do it twice in the php file.


DONE!
Cool

Addition :
If you want to hide that sock puppet from the member list, hack the memberlist.php file
Look for :
	$query = $db->query("

Add right before it :
	
        $search_query .= " AND u.uid <> XXXX ";
	$search_query .= " AND u.username <> 'Anonymous'";

Again, replace XXXX with the User ID from the sock puppet.

I use this mod myself. It should work.
Is there any way to make this Usergroup specific? like 3,4,6 and 8

Ok I answered my own question - for those of you who would like to use this for certain Usergroups:

Find in both:
newthread 
newreply templates:
<label><input type="checkbox" class="checkbox" name="postoptions[anonymous]" value="1" tabindex="6" /> Anonymously</label>
Right before it add:
<if is_member('2,3,4,6,8') then>
and right after add:
</if>


It will look something like this:
<if is_member('2,3,4,6,8') then><label><input type="checkbox" class="checkbox" name="postoptions[anonymous]" value="1" tabindex="6" /> Anonymously</label></if>

Do that for both NewReply and NewThread templates and also don't forget to make sure that inc/plugins/phptpl_allowed_funcs.txt contains the is_member function (add it if it's not there).
http://community.mybb.com/thread-169386-...pid1152250

You may need to have Template Conditionals installed, but the above worked for me.

The ONLY problem i'm having with the whole thing is when I go to the IP Address: Logged to check, there's no info about who posted via anon mode - it's just :

IP Address:
Hostname:
(if resolvable) N/A (Unable to resolve)

and I don't know what settings or changes to make to fix it...  Any Suggestions?

Quote:The ONLY problem i'm having with the whole thing is when I go to the IP Address: Logged to check, there's no info about who posted via anon mode - it's just :

IP Address:
Hostname:
(if resolvable) N/A (Unable to resolve)

and I don't know what settings or changes to make to fix it...  Any Suggestions?

Ok in the newreply and newthread PHP you need to find twice:
"ipaddress" => get_ip(),

and replace it with this:
"ipaddress" => $session->packedip,

Also, I am using MyBB 1.8.7 so your mileage may vary...
Hi KillerCat,

Thanks for your cool mod!

I'm running the latest 1.8.22 MyBB but can't find this in my newreply or newthread templates! Sad

<label><input type="checkbox" class="checkbox" name="postoptions[signature]" value="1" tabindex="6"{$postoptionschecked['signature']} /> {$lang->options_sig}</label>



My newreply template:

<html>
<head>
<title>{$lang->post_reply_to}</title>
{$headerinclude}
{$post_javascript}
</head>
<body>
{$header}
{$preview}
{$maximageserror}
{$attacherror}
{$reply_errors}
{$moderation_notice}
<form action="newreply.php?tid={$tid}&amp;processed=1" method="post" enctype="multipart/form-data" name="input">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
<tr>
<td class="thead" colspan="2"><strong>{$lang->post_new_reply}</strong></td>
</tr>
<tr>
<td class="tcat" colspan="2"><span class="smalltext"><strong>{$lang->reply_to}</strong></span></td>
</tr>
{$loginbox}
<tr>
<td class="trow2" width="20%"><strong>{$lang->post_subject}</strong></td>
<td class="trow2"><input type="text" class="textbox" name="subject" size="40" maxlength="85" value="{$subject}" tabindex="1" /></td>
</tr>
{$posticons}
<tr>
<td class="trow2" valign="top"><strong>{$lang->your_message}</strong><br />{$smilieinserter}</td>
<td class="trow2">
<textarea id="message" name="message" rows="20" cols="70" tabindex="2" >{$message}</textarea>
{$codebuttons}
{$multiquote_external}
</td>
</tr>
{$postoptions}
{$modoptions}
{$subscriptionmethod}
{$captcha}
</table>
{$attachbox}
<br />
<div align="center"><input type="submit" class="button" name="submit" value="{$lang->post_reply}" tabindex="3" accesskey="s" />  <input type="submit" class="button" name="previewpost" value="{$lang->preview_post}" tabindex="4" />{$savedraftbutton}</div>
<input type="hidden" name="action" value="do_newreply" />
<input type="hidden" name="replyto" value="{$replyto}" />
<input type="hidden" name="posthash" value="{$posthash}" />
<input type="hidden" name="attachmentaid" value="" />
<input type="hidden" name="attachmentact" value="" />
<input type="hidden" name="quoted_ids" value="{$quoted_ids}" />
<input type="hidden" name="tid" value="{$tid}" />
{$editdraftpid}
</form>
{$forumrules}
{$threadreview}
{$footer}
</body>
</html>


My newthread template:

<html>
<head>
<title>{$lang->newthread_in}</title>
{$headerinclude}
{$post_javascript}
</head>
<body>
{$header}
{$preview}
{$thread_errors}
{$attacherror}
{$moderation_notice}
<form action="newthread.php?fid={$fid}&amp;processed=1" method="post" enctype="multipart/form-data" name="input">
<input type="hidden" name="my_post_key" value="{$mybb->post_code}" />
<table border="0" cellspacing="{$theme['borderwidth']}" cellpadding="{$theme['tablespace']}" class="tborder">
<tr>
<td class="thead" colspan="2"><strong>{$lang->post_new_thread}</strong></td>
</tr>
{$loginbox}
<tr>
<td class="trow2" width="20%"><strong>{$lang->thread_subject}</strong></td>
<td class="trow2">{$prefixselect}<input type="text" class="textbox" name="subject" size="40" maxlength="85" value="{$subject}" tabindex="1" /></td>
</tr>
{$posticons}
<tr>
<td class="trow2" valign="top"><strong>{$lang->your_message}</strong>{$smilieinserter}</td>
<td class="trow2">
<textarea name="message" id="message" rows="20" cols="70" tabindex="2">{$message}</textarea>
{$codebuttons}
{$multiquote_external}
</td>
</tr>
{$postoptions}
{$modoptions}
{$subscriptionmethod}
{$pollbox}
{$captcha}
</table>
{$attachbox}
<br />
<div style="text-align:center"><input type="submit" class="button" name="submit" value="{$lang->post_thread}" tabindex="4" accesskey="s" />  <input type="submit" class="button" name="previewpost" value="{$lang->preview_post}" tabindex="5" />{$savedraftbutton}</div>
<input type="hidden" name="action" value="do_newthread" />
<input type="hidden" name="posthash" value="{$posthash}" />
<input type="hidden" name="attachmentaid" value="" />
<input type="hidden" name="attachmentact" value="" />
<input type="hidden" name="quoted_ids" value="{$quoted_ids}" />
<input type="hidden" name="tid" value="{$tid}" />
{$editdraftpid}
</form>
{$forumrules}
{$footer}
</body>
</html>

Where should I put it in mine?


Kind regards,

Jason
^ you can add after {$postoptions} on both templates
or
add in newthread_signature & newpost_signature templates
(2020-05-03, 03:20 PM).m. Wrote: [ -> ]^ you can add after {$postoptions} on both templates
or
add in newthread_signature & newpost_signature templates

Thanks so much .m. ...that worked for me! Smile

Another newbie question... using an if condition I have set it to only work in certain forums and it's working fine. Do you know how to construct more than one if statement to also check for usergroup permissions e.g. $mybb->user['usergroup'] == '20' as well as the fid?


Kind regards,

Jason
you can combine 2 conditions with && [AND operator]
<if condition 1 && condition 2 then>
required code 
</if>
Thanks .m. - very much appreciated!
Nice one, didn't test though but looks good. However the code can be optimized further, for example, this part:

Add BELOW it :
if($mybb->input['postoptions']['anonymous'])
{
    $new_thread['uid'] = $puppet_id;
    $new_thread['username'] = 'Anonymous';
}
... does the same thing. No need to redefine entire array.

Also, if it is anonymous (truly), then why you are logging IP address?