Tip/Trick: Redirection confirmation for boards that redirect to a web address

Started by GL700Wing, February 02, 2021, 03:26:53 AM

Previous topic - Next topic

GL700Wing

I'm currently in the process of merging two forums for a business and one of the forums had a board that redirected to an owner community Facebook group that is not owned or managed by the business. 

The business has decided they are happy for the redirection board to be retained on the merged forum but they want forum members to be made aware they are being redirected to a web address that the company does not own or manage and to confirm that this is what they want to do.

I love a challenge and after a couple of hours it was a case of mission accomplished!


Important: You must add following columns to the 'smf_boards' table in order for this tip/trick to work!

Name: redirect_confirm
Type: tinyint
Default: 0

Name: redirect_confirm_text
Type: text


In ./Sources/ManageBoards.php

Find:
            'redirect' => '',
Add After:
            'redirect_confirm' => 0,
            'redirect_confirm_text' => '',

Find:
        // Are they doing redirection?
        $boardOptions['redirect'] = !empty($_POST['redirect_enable']) && isset($_POST['redirect_address']) && trim($_POST['redirect_address']) != '' ? trim($_POST['redirect_address']) : '';

Add After:
        $boardOptions['redirect_confirm'] = isset($_POST['redirect_confirm']);
        $boardOptions['redirect_confirm_text'] = isset($_POST['redirect_confirm_text']) ? trim($_POST['redirect_confirm_text']) : '';


In ./Sources/Subs-BoardIndex.php

Find:
AS is_redirect,
Add After:
b.redirect_confirm, b.redirect_confirm_text,
Find:
                    'is_redirect' => $row_board['is_redirect'],
Add After:
                    'redirect_confirm' => $row_board['redirect_confirm'],
                    'redirect_confirm_text' => $row_board['redirect_confirm_text'],

Find:
                'is_redirect' => $row_board['is_redirect'],
Add After:
                'redirect_confirm' => $row_board['redirect_confirm'],
                'redirect_confirm_text' => $row_board['redirect_confirm_text'],


In ./Sources/Subs-Boards.php

Find:
    if (isset($boardOptions['redirect']))
    {
        $boardUpdates[] = 'redirect = {string:redirect}';
        $boardUpdateParameters['redirect'] = $boardOptions['redirect'];
    }

Add After:

    if (isset($boardOptions['redirect_confirm']))
    {
        $boardUpdates[] = 'redirect_confirm = {int:redirect_confirm}';
        $boardUpdateParameters['redirect_confirm'] = (int) $boardOptions['redirect_confirm'];
    }

    if (isset($boardOptions['redirect_confirm_text']))
    {
        $boardUpdates[] = 'redirect_confirm_text = {string:redirect_confirm_text}';
        $boardUpdateParameters['redirect_confirm_text'] = $boardOptions['redirect_confirm_text'];
    }

Find:
'redirect' => 'string',
Add After:
'redirect_confirm' => 'int', 'redirect_confirm_text' => 'string',
Find:
b.redirect,
Add After:
b.redirect_confirm, b.redirect_confirm_text,
Find:
                'redirect' => $row['redirect'],
Add After:
                'redirect_confirm' => $row['redirect_confirm'],
                'redirect_confirm_text' => $row['redirect_confirm_text'],


In ./Themes/default/BoardIndex.template.php

Note:  The following code update opens all redirected boards in a new window - if you don't want this behaviour delete the target="_blank" attribute.

Find:
            foreach ($category['boards'] as $board)
            {
Add After:
                if ($board['is_redirect'] && $board['redirect_confirm'])
                {
                    $confirmText = (isset($board['redirect_confirm_text']) ? $board['redirect_confirm_text'] : $txt['mboards_redirect_confirm_text']);
                    $confirmText .= '\r\n\r\n' . $txt['mboards_redirect_confirm_okCancel'];
                    $onClick = ' onclick="return confirm(\'' . $confirmText . '\');" target="_blank"';
                }
                else
                    $onClick = ' target="_blank"';

Find:
<a href="', ($board['is_redirect'] || $context['user']['is_guest'] ? $board['href'] : $scripturl . '?action=unread;board=' . $board['id'] . '.0;children'), '">';
Replace With:
<a href="', ($board['is_redirect'] || $context['user']['is_guest'] ? $board['href'] : $scripturl . '?action=unread;board=' . $board['id'] . '.0;children'), '"', $onClick, '>';
Find:
<a class="subject" href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>';
Replace With:
<a class="subject" href="', $board['href'], '" name="b', $board['id'], '"', $onClick, '>', $board['name'], '</a>';

In ./Themes/default/ManageBoards.template.php

Find:
                            <dt>
                                <strong>', $txt['mboards_redirect_url'], ':</strong><br />
                                <span class="smalltext">', $txt['mboards_redirect_url_desc'], '</span><br />
                            </dt>
                            <dd>
                                <input type="text" name="redirect_address" value="', $context['board']['redirect'], '" size="40" class="input_text" />
                            </dd>

Add After:
                            <dt>
                                <strong>', $txt['mboards_redirect_confirm'], ':</strong><br />
                                <span class="smalltext">', $txt['mboards_redirect_confirm_desc'], '</span><br />
                            </dt>
                            <dd>
                                <input type="checkbox" id="redirect_confirm" name="redirect_confirm"', $context['board']['redirect_confirm'] == 1 ? ' checked="checked"' : '', ' class="input_check" />
                            </dd>
                            <dt>
                                <strong>', $txt['mboards_redirect_confirm_text'], ':</strong><br /><br />
                            </dt>
                            <dd>
                                <input type="text" name="redirect_confirm_text" value="', $context['board']['redirect_confirm_text'], '" size="40" class="input_text" />
                            </dd>


In ./Themes/default/languages/ManageBoards.english.php
Add to end of file:
$txt['mboards_redirect_confirm'] = 'Confirm redirection to a web address';
$txt['mboards_redirect_confirm_desc'] = 'If this option is enabled a popup will be displayed with the text below (or default text if the field below is empty) advisig the user they will be redirected to a web address if they click on OK.';
$txt['mboards_redirect_confirm_text'] = 'Text to be displayed for confirmation of redirection to a web address';


In ./Themes/default/languages/index.english.php
Add to end of file:
$txt['mboards_redirect_confirm_text_default'] = 'Note: You are about to be redirected to a web address.';
$txt['mboards_redirect_confirm_okCancel'] = 'Click OK to continue or click Cancel to cancel this request.';
Life doesn't have to be perfect to be wonderful ...

Steve

This seems a little more comprehensive than just a 'Tip/Trick' imo ... but since I'm not a coder I'll leave this to the others that are.
Please do not PM me for support.

Diego Andrés


SMF Tricks - Free & Premium Responsive Themes for SMF.

GigaWatt

Quote from: Steve on February 02, 2021, 08:40:18 AM
This seems a little more comprehensive than just a 'Tip/Trick' imo ... but since I'm not a coder I'll leave this to the others that are.

Agree. Not a coder too, but IMO a bit complicated for a tip/trick.

In any case, thanks for sharing GL700 ;).
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

shadav

Nice, I was looking for something like this myself a while ago, just hadn't gotten around to requesting it, put on the back burner...maybe instead of a popup it loads a new page/tab, as most adblocks and such restrict popups

shadav

so I finally got around to testing this out...it half way works  ;D

need to also edit the

/Themes/default/MessageIndex.template.php

find
        foreach ($context['boards'] as $board)
        {


after add
                if ($board['is_redirect'] && $board['redirect_confirm'])
                {
                    $confirmText = (isset($board['redirect_confirm_text']) ? $board['redirect_confirm_text'] : $txt['mboards_redirect_confirm_text']);
                    $confirmText .= '\r\n\r\n' . $txt['mboards_redirect_confirm_okCancel'];
                    $onClick = ' onclick="return confirm(\'' . $confirmText . '\');" target="_blank"';
                }
                else
                    $onClick = ' target="_blank"';

find
<a href="', ($board['is_redirect'] || $context['user']['is_guest'] ? $board['href'] : $scripturl . '?action=unread;board=' . $board['id'] . '.0;children'), '">';
replace
<a href="', ($board['is_redirect'] || $context['user']['is_guest'] ? $board['href'] : $scripturl . '?action=unread;board=' . $board['id'] . '.0;children'), '"', $onClick, '>';
find
<a class="subject" href="', $board['href'], '" name="b', $board['id'], '">', $board['name'], '</a>
replace
<a class="subject" href="', $board['href'], '" name="b', $board['id'], '"', $onClick, '>', $board['name'], '</a>
the only issue i'm having with this is now EVERY board opens in a new tab  :laugh:

and now I need to figure out how to get this to work with the Childboards as Dropdown mod as well as stop every board from opening in a new tab hehehehe

[edit]
lol um ok then...apparently using an ' in the Text to be displayed for confirmation of redirection to a web address: box breaks the confirmation and it just goes directly to the link

shadav

ok so figured out the issue with EVERY board opening in a new tab  :P

in
/Themes/default/BoardIndex.template.php
and in
/Themes/default/MessageIndex.template.php

find
                    $onClick = ' target="_blank"';
replace with
                    $onClick = '';
now only the redirected boards will open in new tabs and not all boards

now just to figure out how to make this work with the childboards dropdown mod and i'm all set

and how to not break it using ' in the text would be nice but not a big issue

thanks again @GL700Wing for this

Shades.

ShadesWeb.com - Custom Logos - My Themes on SMF | My Themes on ShadesWeb
https://shadesweb.com

BikerHound.com - Sniffing out the road ahead
https://bikerhound.com

Dream as if you'll live forever; Live as if you'll die today. - James Dean

shadav

Quote from: Shades. on May 12, 2022, 07:47:14 PMThis mod does similar to what you are describing! ;)
not quite
what you linked to is for posts with links in it

what this tip/trick does is for boards themselves not posts
it changes the redirection boards (admin > forum > boards > create/modify boards make a board redirect to a url)
to not only open in a new link but to also add a confirmation that "hey you are leaving the site, are you sure you want to do that?" kind of thing

though I would like to see something like this for links in posts as well :D

GL700Wing

Quote from: shadav on May 12, 2022, 06:28:11 PMok so figured out the issue with EVERY board opening in a new tab
Hmm - not sure why I thought that was a good idea - definitely annoying ...

Methinks I should make this into a mod for SMF 2.0 and SMF 2.1 (I really didn't have time to do that last year which is why I posted it as a tip/trick) ...
Life doesn't have to be perfect to be wonderful ...

Steve

I think that's a good idea because I believe this goes beyond being just a tip/trick.
Please do not PM me for support.

GL700Wing

Quote from: Steve on May 13, 2022, 10:15:11 AMI think that's a good idea because I believe this goes beyond being just a tip/trick.
Pre-release version for SMF 2.0 and 2.1 finished yesterday - just getting some final testing/checking done ...
Life doesn't have to be perfect to be wonderful ...

Steve

Please do not PM me for support.

Antechinus

Can one of the team please fix the typo in this topic's title?
It bugs me every time I see it on the unred pge. :P
Sources code: making easy front end changes difficult since 1873 :P

Mods & Themes | Revamped theme for this site | Dark theme for this site | GitHub for n00bz

GL700Wing

Quote from: Antechinus on May 14, 2022, 05:22:57 PMCan one of the team please fix the typo in this topic's title?
It bugs me every time I see it on the unred pge. :P
Agreed and apologies for that - by the time I realised it was there not long after I posted the topic it was too late for me to change it ...
Life doesn't have to be perfect to be wonderful ...

Antechinus

The edit time limit on this site frequently gets up my nose too. :D
Sources code: making easy front end changes difficult since 1873 :P

Mods & Themes | Revamped theme for this site | Dark theme for this site | GitHub for n00bz

shadav


Antechinus

Sources code: making easy front end changes difficult since 1873 :P

Mods & Themes | Revamped theme for this site | Dark theme for this site | GitHub for n00bz

Steve

We certainly don't want Ant going crazier than he already is.  :P
Please do not PM me for support.

Advertisement: