Advertisement:

Author Topic: Option to post Anonymously on topics  (Read 2806 times)

Offline machinenoob

  • Semi-Newbie
  • *
  • Posts: 46
Option to post Anonymously on topics
« on: July 11, 2015, 10:21:14 PM »
Recently I was building a forum for a work project and the users must be able to post anonymously when they want.  I saw the anonymous board mod, but I didn't want to make the whole board anonymous, just the actual topic/post.  I took the code and modified it a little so that users can post the topic anonymously if they want.  More could be added and a mod with permissions could be made, but for now here is the solution.  Thanks to the original coders/developers.

In Modifications.english.php (located in Themes\Default\languages)

At the bottom BEFORE
Code: [Select]
?>
Paste this
Code: [Select]
$txt['post_anon'] = 'Post message anonymously';
In Post.template.php (located in Themes\Default)

AFTER this
Code: [Select]
// Finally, the submit buttons.
Paste this
Code: [Select]
echo '<br>'. $txt['post_anon'] .' <input type="checkbox" name="post_anon" />';
In Display.template.php (located in Themes\Default)

AFTER this
Code: [Select]
// Is visual verification enabled?
if ($context['require_verification'])
echo '
<strong>', $txt['verification'], ':</strong>', template_control_verification($context['visual_verification_id'], 'quick_reply'), '<br />';

echo '
<div class="quickReplyContent">
<textarea cols="600" rows="7" name="message" tabindex="', $context['tabindex']++, '"></textarea>
</div>

Paste this
Code: [Select]
<br>'. $txt['post_anon'] .' <input type="checkbox" name="post_anon" />

In Post.php (located in Sources)


AFTER this
Code: [Select]
// No errors as yet.
$post_errors = array();

Paste this
Code: [Select]
if (isset($_POST['post_anon']))
{
// Destroy the identifing user data
$user_info['username'] = 'Anonymous';
$user_info['name'] = 'Anonymous';
$user_info['email'] = '';
$user_info['id'] = 0;
}

//didn't try it, but if you change the $user_info['id'] = # to another number corresponding to a users number then it SHOULD take over the post.  So if you actually created an Anonymous account with a picture/profile and the ID (hover over a users name and you should see u=#) then that will show up so you dont' have a plain jane looking Guest post..hopefully 

Offline dougiefresh

  • Sophist Member
  • *****
  • Posts: 1,180
    • XPtsp.com Community
Re: Option to post Anonymously on topics
« Reply #1 on: July 27, 2015, 01:33:01 PM »
I'd like to create a mod using this concept/code, if you don't mind....

Offline Kindred

  • The Mean One
  • Project Manager
  • SMF Master
  • *
  • Posts: 47,183
  • Gender: Male
    • wagner999 on Facebook
    • Kindred-999 on GitHub
    • wdwagner on LinkedIn
    • @Kindred_999 on Twitter
Re: Option to post Anonymously on topics
« Reply #2 on: July 27, 2015, 01:42:47 PM »
I did have a mod -- which allowed configuration of the setting per board - I handed it off a while back...

I am not certain it is still supported.... but it was an open license, so, please feel free to fork it
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support forums.  Thank you.

Offline machinenoob

  • Semi-Newbie
  • *
  • Posts: 46
Re: Option to post Anonymously on topics
« Reply #3 on: August 02, 2015, 12:41:56 PM »
after all this I figured that if i changed the Original MOD just a little it works the same and added some code.. however in the original MOD there is a FIX that needs to be implemented because it doesn't install it correctly.

Refer to the  original mod last page I stated the fix still needs to be done, I hope DougieFresh can do it... properly..

Thanks Dougie...

Code: [Select]
<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">

<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>JMV290:AnonymousBoard</id>
<version>1.1</version>

<file name="$themedir/ManageBoards.template.php">
<operation>
<search position="before"><![CDATA[ <div id="count_posts_div">
<dl class="settings">
<dt>
<strong>', $txt['mboards_count_posts'], ':</strong><br />
<span class="smalltext">', $txt['mboards_count_posts_desc'], '</span><br />
</dt>
<dd>
<input type="checkbox" name="count" ', $context['board']['count_posts'] ? ' checked="checked"' : '', ' class="input_check" />
</dd>
</dl>
</div>';
]]></search>
<add><![CDATA[
//Anonymous Board Mod
echo '
<div id="anon_board_div">
<dl class="settings">
<dt>
<strong>', $txt['makeBoard_anonymous'], ':</strong><br />
<span class="smalltext">', $txt['mboards_anon_board_desc'], '</span><br />
</dt>
<dd>
<input type="checkbox" name="anonymous_board" ', $context['board']['anonymous_board'] ? ' checked="checked"' : '', ' class="input_check" />
</dd>
</dl>
</div>';

]]></add>
</operation>
</file>

<file name="$themedir/languages/Modifications.english.php">
<operation>
<search position="after"><![CDATA[?>]]></search>
<add><![CDATA[
$txt['makeBoard_anonymous']='Allow this board the option to post anonymous.';
$txt['Post_anonymous'] = '<b>Post anonymously</b>';
$txt['mboards_anon_board_desc'] = 'New replies and topics will be posted anonymously by default';

]]></add>
</operation>
</file>

<file name="$sourcedir/ManageBoards.php">
<operation>
<search position="before"><![CDATA[
'theme' => 0,
'profile' => 1,
'override_theme' => 0,
]]></search>
<add><![CDATA[
'anonymous_board' => 0,
]]></add>
</operation>
<operation>
<search position="before"><![CDATA[
$boardOptions['posts_count'] = isset($_POST['count']);
$boardOptions['override_theme'] = isset($_POST['override_theme']);
]]></search>
<add><![CDATA[
$boardOptions['anonymous_board'] = isset($_POST['anonymous_board']);
]]></add>
</operation>
</file>

<file name="$sourcedir/Subs-Boards.php">
<operation>
<search position="before"><![CDATA[
// Should the board theme override the user preferred theme?
if (isset($boardOptions['override_theme']))
{
$boardUpdates[] = 'override_theme = {int:override_theme}';
$boardUpdateParameters['override_theme'] = $boardOptions['override_theme'] ? 1 : 0;
}

]]></search>
<add><![CDATA[
  // Should the board allow anonymous posts?
if (isset($boardOptions['anonymous_board']))
{
$boardUpdates[] = 'anonymous_board = {int:anonymous_board}';
$boardUpdateParameters['anonymous_board'] = $boardOptions['anonymous_board'] ? 1 : 0;
}

]]></add>
</operation>
<operation>
<search position="before"><![CDATA[
b.num_posts, b.num_topics, c.id_cat, c.name AS cat_name, c.cat_order, c.can_collapse
]]></search>
<add><![CDATA[
, b.anonymous_board
]]></add>
</operation>
<operation>
<search position="after"><![CDATA[
'prev_board' => $prevBoard
]]></search>
<add><![CDATA[
'anonymous_board' => $row['anonymous_board'],
]]></add>
</operation>
</file>

<file name="$sourcedir/Load.php">
<operation>
<search position="before"><![CDATA[
c.id_cat, b.name AS bname, b.description, b.num_topics, b.member_groups,
]]></search>
<add><![CDATA[
 b.anonymous_board,
]]></add>
</operation>
<operation>
<search position="after"><![CDATA[
// Load the membergroups allowed, and check permissions.
$board_info['groups'] = $row['member_groups'] == '' ? array() : explode(',', $row['member_groups']);
]]></search>
<add><![CDATA[
$context['anonymous_board'] = $row['anonymous_board'];

]]></add>
</operation>
</file>

<file name="$themedir/Post.template.php">
<operation>
<search position="after"><![CDATA[
// Finally, the submit buttons.
]]></search>
<add><![CDATA[
// anonymous board mod
if ( $context['anonymous_board'] )
echo '<br>'. $txt['Post_anonymous'] .' <input type="checkbox" name="post_anon" />';

]]></add>
</operation>
</file>

<file name="$sourcedir/Post.php">
<operation>
<search position="before"><![CDATA[
// No errors as yet.
$post_errors = array();
]]></search>
<add><![CDATA[
// Anonymous board mod
if ( $context['anonymous_board'] && isset($_POST['post_anon']) )
{
// Destroy the identifing user data
$user_info['username'] = 'Anonymous';
$user_info['name'] = 'Anonymous';
$user_info['email'] = '';
$user_info['id'] = 0;
}

]]></add>
</operation>
</file>
<file name="$sourcedir/Who.php">
<operation>
<search position="before"><![CDATA[
if (!empty($board_ids))
{
$result = $smcFunc['db_query']('', '
SELECT b.id_board, b.name
FROM {db_prefix}boards AS b
WHERE {query_see_board}
AND b.id_board IN ({array_int:board_list})
]]></search>
<add><![CDATA[
AND b.anonymous_board = 0
]]></add>
</operation>
<operation>
<search position="before"><![CDATA[
if (!empty($topic_ids))
{
$result = $smcFunc['db_query']('', '
SELECT t.id_topic, m.subject
FROM {db_prefix}topics AS t
INNER JOIN {db_prefix}boards AS b ON (b.id_board = t.id_board)
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
WHERE {query_see_board}
]]></search>
<add><![CDATA[
AND b.anonymous_board = 0
]]></add>
</operation>
</file>
<file name="$themedir/Display.template.php">
<operation>
<search position="before"><![CDATA[ <div class="quickReplyContent">
<textarea cols="600" rows="7" name="message" tabindex="', $context['tabindex']++, '"></textarea>
</div>
]]></search>
<add><![CDATA[';

if ( $context['anonymous_board'] )
echo '<br>'. $txt['Post_anonymous'] .' <input type="checkbox" name="post_anon" />';

echo '
]]></add>
</operation>
</file>

</modification>

here is the CACHE fix for it, I give all credit to the original modder.

http://www.simplemachines.org/community/index.php?topic=204149.msg3380492#msg3380492

Thanks

Offline samk2824

  • Newbie
  • *
  • Posts: 7
Re: Option to post Anonymously on topics
« Reply #4 on: August 18, 2015, 10:28:41 AM »
Thank you for sharing this amazing trick Over Here. May I know Any how it would be applied on facebook too or not ? 8)

Offline Kindred

  • The Mean One
  • Project Manager
  • SMF Master
  • *
  • Posts: 47,183
  • Gender: Male
    • wagner999 on Facebook
    • Kindred-999 on GitHub
    • wdwagner on LinkedIn
    • @Kindred_999 on Twitter
Re: Option to post Anonymously on topics
« Reply #5 on: August 18, 2015, 12:10:22 PM »
??? ??? ???


What?


What does this thread have to do with facebook in any way, shape or form?
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support forums.  Thank you.

Offline Antes

  • Evil Black Cat
  • Marketing
  • SMF Hero
  • *
  • Posts: 7,005
  • Gender: Male
  • Black cat rulz!
    • Antes on GitHub
    • merta on LinkedIn
    • @antesistan on Twitter
    • MMOBrowser
Re: Option to post Anonymously on topics
« Reply #6 on: August 18, 2015, 12:59:21 PM »
??? ??? ???


What?


What does this thread have to do with facebook in any way, shape or form?

Spam ?
- Solutions for everyone, It's that simple.

( ͡° ͜◯ ͡°) CLOWN FIESTA ( ͡° ͜◯ ͡°)

Offline dougiefresh

  • Sophist Member
  • *****
  • Posts: 1,180
    • XPtsp.com Community
Re: Option to post Anonymously on topics
« Reply #7 on: August 18, 2015, 06:24:14 PM »
Thank you for sharing this amazing trick Over Here. May I know Any how it would be applied on facebook too or not ? 8)
I'm going to answer this INCREDIBLY STUPID question....  Facebook is not a forum, so no, this cannot be applied to Facebook in any form or fashion.