SimplePortal

Customization => Custom Coding => Topic started by: ccbtimewiz on October 05, 2011, 03:36:00 PM

Title: [SMF 2.0] Allow guests to use the Shoutbox
Post by: ccbtimewiz on October 05, 2011, 03:36:00 PM
The following edits allow guests to shout in the shoutbox.

SMF version: 2.0 series
SP version: 2.3 series

(http://i.imgur.com/2AAtQ.png)

Open ./Sources/PortalShoutbox.php

Find:
Code: [Select]
function sportal_create_shout($shoutbox, $shout)
{
global $smcFunc, $user_info;

Replace with:
Code: [Select]
function sportal_create_shout($shoutbox, $shout)
{
global $txt, $smcFunc, $user_info;

Find:
Code: [Select]
if (trim(strip_tags(parse_bbc($shout, false), '<img>')) === '')
return false;

Replace with:
Code: [Select]
if (trim(strip_tags(parse_bbc($shout, false), '<img>')) === '')
return false;

if ($user_info['is_guest'])
{
if (!isset($_SESSION['guest_has_shouted']))
{
$_SESSION['guest_has_shouted'] = rand(10, 1000);
$user_info['name'] = $txt['guest'] . $_SESSION['guest_has_shouted'];
$user_info['id'] = 0;
}
else
$user_info['name'] = $txt['guest'] . (!empty($_SESSION['guest_has_shouted']) ? $_SESSION['guest_has_shouted'] : rand(10, 1000));
}

Find:
Code: [Select]
if (!empty($_REQUEST['shout']))
{
checkSession('request');

is_not_guest();

Replace with:
Code: [Select]
if (!empty($_REQUEST['shout']))
{
checkSession('request');

//is_not_guest();


Open ./Sources/Subs-Portal.php

Find:
Code: [Select]
if ($user_info['is_guest'])
return false;

Replace with:
Code: [Select]
//if ($user_info['is_guest'])
//return false;

Find:
Code: [Select]
'name' => $row['member_name'],
Replace with:
Code: [Select]
'name' => (!empty($row['member_name']) ? $row['member_name'] : $txt['guest']),
Find:
Code: [Select]
'link' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" title="' . $txt['on'] . ' ' . strip_tags(timeformat($row['log_time'])) . '"' . (!empty($online_color) ? ' style="color: ' . $online_color . ';"' : '') . '>' . $row['member_name'] . '</a>') : $row['member_name'],
Replace with:
Code: [Select]
'link' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" title="' . $txt['on'] . ' ' . strip_tags(timeformat($row['log_time'])) . '"' . (!empty($online_color) ? ' style="color: ' . $online_color . ';"' : '') . '>' . $row['member_name'] . '</a>') : (!empty($row['member_name']) ? $row['member_name'] : $txt['guest']),


Open ./Sources/PortalBlocks.php

Find:
Code: [Select]
if (!empty($_POST['new_shout']) && !empty($_POST['submit_shout']) && !empty($_POST['shoutbox_id']) && $_POST['shoutbox_id'] == $shoutbox['id'])
{
checkSession();

is_not_guest();

Replace with:
Code: [Select]
if (!empty($_POST['new_shout']) && !empty($_POST['submit_shout']) && !empty($_POST['shoutbox_id']) && $_POST['shoutbox_id'] == $shoutbox['id'])
{
checkSession();

//is_not_guest();


Open ./Themes/default/Portal.template.php

Find:
Code: [Select]
if ($context['can_shout'])
echo '
<div class="shoutbox_input smalltext">
<input type="text" name="new_shout" id="new_shout_', $shoutbox['id'], '" class="shoutbox_input sp_float_left input_text"', $context['browser']['is_ie'] ? ' onkeypress="if (sp_catch_enter(event)) { sp_submit_shout(' . $shoutbox['id'] . ', \'' . $context['session_var'] . '\', \'' . $context['session_id'] . '\'); return false; }"' : '', ' />
<input type="submit" name="submit_shout" value="', $txt['sp_shoutbox_button'], '" class="sp_float_right button_submit" onclick="sp_submit_shout(', $shoutbox['id'], ', \'', $context['session_var'], '\', \'', $context['session_id'], '\'); return false;" />
</div>';

Replace with:
Code: [Select]
if ($context['can_shout'] || $context['user']['is_guest'])
echo '
<div class="shoutbox_input smalltext">
<input type="text" name="new_shout" id="new_shout_', $shoutbox['id'], '" class="shoutbox_input sp_float_left input_text"', $context['browser']['is_ie'] ? ' onkeypress="if (sp_catch_enter(event)) { sp_submit_shout(' . $shoutbox['id'] . ', \'' . $context['session_var'] . '\', \'' . $context['session_id'] . '\'); return false; }"' : '', ' />
<input type="submit" name="submit_shout" value="', $txt['sp_shoutbox_button'], '" class="sp_float_right button_submit" onclick="sp_submit_shout(', $shoutbox['id'], ', \'', $context['session_var'], '\', \'', $context['session_id'], '\'); return false;" />
</div>';

Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: Shadow Queen on October 05, 2011, 04:23:50 PM
Can I see a screen shoot?
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: ccbtimewiz on October 05, 2011, 06:08:12 PM
(http://i.imgur.com/1W5IZ.png)
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: Old Fossil on October 05, 2011, 06:35:17 PM
People may want to think about this.

Is a good way for a shoutbox to be spammed.
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: ccbtimewiz on October 05, 2011, 06:45:55 PM
Well, the shoutbox by default doesn't have a really good anti-spam mechanism in the first place.

I might add my own mechanism when I update this code.
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: ccbtimewiz on October 05, 2011, 06:54:35 PM
Also, I made it so each guest has their own random ID when they comment, so you can tell them apart if you have multiple guests.

After performing my instructions in the first post, do this as well..

(note that I now include this in my post)

Open ./Sources/Subs-Portal.php

Find:
Code: [Select]
if (trim(strip_tags(parse_bbc($shout, false), '<img>')) === '')
return false;

Replace with:
Code: [Select]
if (trim(strip_tags(parse_bbc($shout, false), '<img>')) === '')
return false;

if ($user_info['is_guest'])
{
if (!isset($_SESSION['guest_has_shouted']))
{
$_SESSION['guest_has_shouted'] = rand(10, 1000);
$user_info['name'] = $txt['guest'] . $_SESSION['guest_has_shouted'];
$user_info['id'] = 0;
}
else
$user_info['name'] = $txt['guest'] . (!empty($_SESSION['guest_has_shouted']) ? $_SESSION['guest_has_shouted'] : rand(10, 1000));
}

(http://i.imgur.com/2AAtQ.png)
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: Shadow Queen on October 06, 2011, 12:55:40 AM
The screen shoots of this code you made. Look neat.

I have a Q for you. If you have few shout boxer that code will input all them? If you have one shout box hidden from guests and other have guests and members?

I'm so sorry If I get the words in the wrong order. Please forgive me
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: ccbtimewiz on October 06, 2011, 01:36:26 AM
All permissions are respected. If a guest cannot view a particular shoutbox, they cannot use it. However, if guests can see the shoutbox, they can use it no matter what other settings you have. If you want to make a read-only shoutbox to guests, then it's best not to use this code adaption.
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: Shadow Queen on October 06, 2011, 01:52:31 AM
I'm just making sure. Because I am thinking to use this code on my forum.

I do thank you!
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: ccbtimewiz on October 06, 2011, 02:00:16 AM
I can write exceptions for you if you really need to make it so you have a shoutbox visible to guests but they can't use that particular one. Just let me know, it's fairly easy to hardcode in.

I'm open for other block requests or modifications to blocks via PM too if anyone has some ideas, though note that everything I write is mine, and I reserve the right to post it in public or reuse it as I see fit. I might be making an edit to the Who's Online that groups it.
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: Tarissa on January 31, 2012, 12:23:37 PM
I would really, really, like to utilize this function, but it doesn't appear to be compatible with SMF 2.0.2

Is there a way to get a version for the newest SMF?
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: velorooms on March 28, 2012, 10:24:11 AM
any idea how to do this in 2.3.4

looked at the code and it is completely different
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: Old Fossil on March 28, 2012, 12:10:38 PM
any idea how to do this in 2.3.4

looked at the code and it is completely different

Don't you mean 2.3.5?
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: MESSIAH on May 15, 2012, 03:37:18 PM
Yes that would be preety well if any one change this code to 2.3.5 version.
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: phantomm on May 16, 2012, 06:56:23 AM
I don't know if I can post this as Package, so here is update for SP 2.3.5 :)

Open: $sourcedir/PortalShoutbox.php

Code: (Find) [Select]
if (!empty($_REQUEST['shout']))
{
checkSession('request');

is_not_guest();
Code: (Replace with) [Select]
if (!empty($_REQUEST['shout']))
{
checkSession('request');

//is_not_guest();

Open: $sourcedir/Subs-Portal.php

Code: (Find) [Select]
function sportal_create_shout($shoutbox, $shout)
{
global $smcFunc, $user_info;
Code: (Replace with) [Select]
function sportal_create_shout($shoutbox, $shout)
{
global $smcFunc, $user_info, $txt;


Code: (Find) [Select]
if (trim(strip_tags(parse_bbc($shout, false), '<img>')) === '')
return false;
Code: (Replace with) [Select]
if (trim(strip_tags(parse_bbc($shout, false), '<img>')) === '')
return false;


if ($user_info['is_guest'])
{
if (!isset($_SESSION['guest_has_shouted']))
{
$_SESSION['guest_has_shouted'] = rand(10, 1000);
$user_info['name'] = $txt['guest'] . $_SESSION['guest_has_shouted'];
$user_info['id'] = 0;
}
else
$user_info['name'] = $txt['guest'] . (!empty($_SESSION['guest_has_shouted']) ? $_SESSION['guest_has_shouted'] : rand(10, 1000));
}



Code: (Find) [Select]
if ($user_info['is_guest'])
return false;
Code: (Replace with) [Select]
//if ($user_info['is_guest'])
//return false;
      

Code: (Find) [Select]
'name' => $row['member_name'],
Code: (Replace with) [Select]
'name' => (!empty($row['member_name']) ? $row['member_name'] : $txt['guest']),


Code: (Find) [Select]
'link' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" title="' . $txt['on'] . ' ' . strip_tags(timeformat($row['log_time'])) . '"' . (!empty($online_color) ? ' style="color: ' . $online_color . ';"' : '') . '>' . $row['member_name'] . '</a>') : $row['member_name'],
Code: (Replace with) [Select]
'link' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" title="' . $txt['on'] . ' ' . strip_tags(timeformat($row['log_time'])) . '"' . (!empty($online_color) ? ' style="color: ' . $online_color . ';"' : '') . '>' . $row['member_name'] . '</a>') : (!empty($row['member_name']) ? $row['member_name'] : $txt['guest']),

Open: $sourcedir/PortalBlocks.php

Code: (Find) [Select]
if (!empty($_POST['new_shout']) && !empty($_POST['submit_shout']) && !empty($_POST['shoutbox_id']) && $_POST['shoutbox_id'] == $shoutbox['id'])
{
checkSession();

is_not_guest();
Code: (Replace with) [Select]
if (!empty($_POST['new_shout']) && !empty($_POST['submit_shout']) && !empty($_POST['shoutbox_id']) && $_POST['shoutbox_id'] == $shoutbox['id'])
{
checkSession();

//is_not_guest();

Open: $themedir/PortalShoutbox.template.php

Code: (Find) [Select]
if ($context['can_shout'])
echo '
<div class="shoutbox_input smalltext">
<input type="text" name="new_shout" id="new_shout_', $shoutbox['id'], '" class="shoutbox_input sp_float_left input_text"', $context['browser']['is_ie'] ? ' onkeypress="if (sp_catch_enter(event)) { sp_submit_shout(' . $shoutbox['id'] . ', \'' . $context['session_var'] . '\', \'' . $context['session_id'] . '\'); return false; }"' : '', ' />
<input type="submit" name="submit_shout" value="', $txt['sp_shoutbox_button'], '" class="sp_float_right button_submit" onclick="sp_submit_shout(', $shoutbox['id'], ', \'', $context['session_var'], '\', \'', $context['session_id'], '\'); return false;" />
</div>';
Code: (Replace with) [Select]
if ($context['can_shout'] || $context['user']['is_guest'])
echo '
<div class="shoutbox_input smalltext">
<input type="text" name="new_shout" id="new_shout_', $shoutbox['id'], '" class="shoutbox_input sp_float_left input_text"', $context['browser']['is_ie'] ? ' onkeypress="if (sp_catch_enter(event)) { sp_submit_shout(' . $shoutbox['id'] . ', \'' . $context['session_var'] . '\', \'' . $context['session_id'] . '\'); return false; }"' : '', ' />
<input type="submit" name="submit_shout" value="', $txt['sp_shoutbox_button'], '" class="sp_float_right button_submit" onclick="sp_submit_shout(', $shoutbox['id'], ', \'', $context['session_var'], '\', \'', $context['session_id'], '\'); return false;" />
</div>';
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: KnightRaider on May 25, 2012, 02:34:26 AM
Isn't a little bit silly to allow guests to chat in the first place? Cause then you'll get spammers and idiot's flooding the shoutbox? No offense.
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: phantomm on May 25, 2012, 03:43:54 AM
I'm sure that if someone wants to make this edits knows what is he doing :)

But if I remember correctly, there is mod (at SMF Mod Site) for blocking bots before they enter site? Then maybe this can be used as some kind of 'anti-spam'  :E
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: Cal on May 25, 2012, 09:37:32 AM
Isn't a little bit silly to allow guests to chat in the first place? Cause then you'll get spammers and idiot's flooding the shoutbox? No offense.

It depends on what your board is for.  In the RP community, guests expect to be able to interact with a site before they decide to join, so guest shouts are incredibly important.  It's not the best option in every situation, but I think it's up to the admin to make that choice.  :)
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: velorooms on February 04, 2013, 12:46:17 PM
its something that site owners will or wont use. We are discussing it as we have shoutboxes dedicated to races when they happen, that always have a moderator present so are looking if its a viable option to bring in new members who hopefully then register.

but its not without its pitfalls.

Useful for specific events with a dedicated shoutbox and moderation, total clustermess for unmoderated shoutboxes.
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: [SiNaN] on August 14, 2013, 02:33:03 PM
Hi
Just reopening the old issue of the shoutbox -I  need help
I need to allow guests to see the shoutbox activity without ability of shouting
By me guests can not see the shoutbox
Any advice is appreciated.
Regards
Ilya

You just need to give permission to guests too (both for the shoutbox and block) and they will be able to see the shoutbox but they won't be able to shout. (like we have here)
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: fapencio on April 17, 2014, 03:59:49 PM
phantomm you are nice!  thanks for share!  :applause: :thumbsup:
Title: Re: [SMF 2.0] Allow guests to use the Shoutbox
Post by: Ron-KK4HGY on August 07, 2014, 11:40:58 AM
Has anything new been done about this?  Ideally, I would like to see a package for this mod and an easy way to deny access to the shout box by guest if we start getting a lot of spam.
SimplePortal 2.3.8 © 2008-2024, SimplePortal