[Beta] Hide posting text from guests

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Suggested Hosts
ILoveWHU
Registered User
Posts: 44
Joined: Sun Jul 06, 2008 9:58 pm

[Beta] Hide posting text from guests

Post by ILoveWHU » Sun Jul 06, 2008 10:07 pm

MOD Title: Hide Posting Text From Guests
MOD Description: This mod allows you to post information that can be hidden from guests. This is used when guests are allowed to read a forums topics but you would still like to hide certain information from them.


MOD Version: 0.0.3

MOD Download: Code and instructions currently shown below.

Demo Board: None at the moment.

Limitations: None. Works on all versions of PHP.

HowTo install:
In viewtopic.php
Find

Code: Select all

$rowset[$row['post_id']] = array(


Before Add

Code: Select all

// Mod for members bbcode
if ($user->data['user_id'] == ANONYMOUS)
    {

    $offset = 0;
    $newstring = $row['post_text'];
    $strpos = strpos($newstring ,'[members:', $offset);
    $strcnt = substr_count($newstring ,'[members:');
    
    while ($strcnt <> false):

          $endpos = strpos($newstring, '[/members', $offset);
          $strpos = $strpos + 18;
          $strlen = $endpos - $strpos;
          $newstring = substr_replace($newstring, 'You must be a Registered Member to view this content', $strpos, $strlen);
	        $offset = $strpos + 53;
	 
            if ($offset < strlen($newstring))
                {
								 $strrem = substr($newstring, $offset); 
								 $strcnt = substr_count($strrem ,'[members:');
                 $strpos = strpos($newstring, '[members:', $offset);
                }
            else
                  {
                   $strcnt = false;
                  }         
    endwhile;
    
    $row['post_text'] = $newstring;
    }
// End Mod for members bbcode
In ACP / Posting / BBcodes add the new bbcode
BBCode Useage

Code: Select all

[members]{TEXT}[/members]
HTML Replacement

Code: Select all

<div style="margin:20px; margin-top:5px"><div class="quotetitle"><b>Registered Members Only:</b> <input type="button" value="Show" style="width:45px;font-size:10px;margin:0px;padding:0px;" onclick="if (this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display != '') { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = '';        this.innerText = ''; this.value = 'Hide'; } else { this.parentNode.parentNode.getElementsByTagName('div')[1].getElementsByTagName('div')[0].style.display = 'none'; this.innerText = ''; this.value = 'Show'; }" /></div><div class="quotecontent"><div style="display: none;">{TEXT}</div></div></div>

Note: If you have Handyman's Ajax chat installed then also:
In shout.php
Find

Code: Select all

$template->assign_block_vars('chatrow', array(
Before Add

Code: Select all

// Mod for members bbcode
if ($user->data['user_id'] == ANONYMOUS)
    {

    $offset = 0;
    $newstring = $row['message'];
    $strpos = strpos($newstring ,'[members:', $offset);
    $strcnt = substr_count($newstring ,'[members:');
    
    while ($strcnt <> false):

          $endpos = strpos($newstring, '[/members', $offset);
          $strpos = $strpos + 18;
          $strlen = $endpos - $strpos;
          $newstring = substr_replace($newstring, 'You must be a Registered Member to view this content', $strpos, $strlen);
	        $offset = $strpos + 53;
	 
            if ($offset < strlen($newstring))
                {
								 $strrem = substr($newstring, $offset); 
								 $strcnt = substr_count($strrem ,'[members:');
                 $strpos = strpos($newstring, '[members:', $offset);
                }
            else
                  {
                   $strcnt = false;
                  }         
    endwhile;
    
    $row['message'] = $newstring;
    }

// End Mod for members bbcode


I'm sure that someone could write it in a better way but I needed it so wrote it the best way I knew how in self taught php. :grin:

Version 0.0.0
Initial Release

Version 0.0.1
Added check to enure that revised offset does not exceed new string length

Version 0.0.2
Changed to ensure it processes correctly when members bbcode is in 1st position of a post
Added code to support Handyman's Ajax chat mod

Version 0.0.3
Changed to ensure it processes correctly when multiple members bbcode are in the same post
Changed code to support all versions of PHP
Last edited by ILoveWHU on Tue Aug 19, 2008 1:00 pm, edited 7 times in total.

bouncybeatz
Registered User
Posts: 106
Joined: Fri Apr 11, 2008 10:35 pm
Location: Liverpool
Contact:

Re: [Dev] Hide posting text from guests

Post by bouncybeatz » Mon Jul 07, 2008 12:14 am

Works fine except guests can still see what you hide all they have to do click show.

ILoveWHU
Registered User
Posts: 44
Joined: Sun Jul 06, 2008 9:58 pm

Re: [Dev] Hide posting text from guests

Post by ILoveWHU » Mon Jul 07, 2008 12:41 am

For guests it replaces the text that was within each member bbcode tag with 'You must be a Registered Member to view this content' so when they click it that is the text they will see.

bouncybeatz
Registered User
Posts: 106
Joined: Fri Apr 11, 2008 10:35 pm
Location: Liverpool
Contact:

Re: [Dev] Hide posting text from guests

Post by bouncybeatz » Mon Jul 07, 2008 1:38 am

Well when im not logged in and i click show it shows me exacly what i wrote inbetween [members] text here [/members] Image

ILoveWHU
Registered User
Posts: 44
Joined: Sun Jul 06, 2008 9:58 pm

Re: [Dev] Hide posting text from guests

Post by ILoveWHU » Mon Jul 07, 2008 3:21 pm

Works fine on my board

Are you sure that you have applied the mod to the viewtopic.php module as well as creating the member bbcode? It is in viewtopic.php where the auto change of text is applied for guest.

Please note that a minor change was made to th viewtopic.php mod code that ensures the last strpos does not error when offset is greater than the resized posting text. That fix has nothing to do with your problem though.

viresh75
Registered User
Posts: 10
Joined: Mon Dec 31, 2007 1:41 pm

Re: [Dev] Hide posting text from guests

Post by viresh75 » Wed Jul 09, 2008 1:03 pm

I have installed this, but I have change the bbcode from [members]{text}[/members] to [rs]{text}[/rs].
But the show some code before the text no. Par example -->> http://viresh75.gethost.nl/viewtopic.php?f=20&t=34

Code: Select all

[b:3cJe moet geregistreerd zijn om de inhoud te kunnen bekijken.
That [b:3c Must away.

Sorry for my bad English. I'm from the Netherlands. I"m 14 years old. :P

ILoveWHU
Registered User
Posts: 44
Joined: Sun Jul 06, 2008 9:58 pm

Re: [Dev] Hide posting text from guests

Post by ILoveWHU » Wed Jul 09, 2008 1:17 pm

If you change the bbcode word from members to rs then you must change the viewtopic.php modification to

Code: Select all

if ($user->data['user_id'] == ANONYMOUS)
    {
     $offset = 0;
    $newstring = $row['post_text'];
    $strpos = strpos($newstring ,'[rs:', $offset);
    
    
    while ($strpos <> false):
            $endpos = strpos($newstring, '[/rs', $offset);
          $strpos = $strpos + 13;
          $strlen = $endpos - $strpos;
          $newstring = substr_replace($newstring, 'You must be a Registered Member to view this content', $strpos, $strlen);
          $offset = $endpos + 1;
            if ($offset < strlen($newstring))
                {
                 $strpos = strpos($newstring, '[rs:', $offset);
                }
            else
                  {
                   $strpos = false;
                  }         
    endwhile;
    
    $row['post_text'] = $newstring;
    }


Also change the wording of 'You must be a Registered Member to view this content' in the above to whatever you want it to be.

viresh75
Registered User
Posts: 10
Joined: Mon Dec 31, 2007 1:41 pm

Re: [Dev] Hide posting text from guests

Post by viresh75 » Wed Jul 09, 2008 2:15 pm

ILoveWHU wrote:If you change the bbcode word from members to rs then you must change the viewtopic.php modification to

Code: Select all

if ($user->data['user_id'] == ANONYMOUS)
    {
     $offset = 0;
    $newstring = $row['post_text'];
    $strpos = strpos($newstring ,'[rs:', $offset);
    
    
    while ($strpos <> false):
            $endpos = strpos($newstring, '[/rs', $offset);
          $strpos = $strpos + 13;
          $strlen = $endpos - $strpos;
          $newstring = substr_replace($newstring, 'You must be a Registered Member to view this content', $strpos, $strlen);
          $offset = $endpos + 1;
            if ($offset < strlen($newstring))
                {
                 $strpos = strpos($newstring, '[rs:', $offset);
                }
            else
                  {
                   $strpos = false;
                  }         
    endwhile;
    
    $row['post_text'] = $newstring;
    }


Also change the wording of 'You must be a Registered Member to view this content' in the above to whatever you want it to be.
Thnx man. It's works. Great mod.

User avatar
Sunka
Registered User
Posts: 566
Joined: Wed Mar 26, 2008 2:48 pm
Location: Croatia, Zvoneca
Contact:

Re: [Dev] Hide posting text from guests

Post by Sunka » Sun Jul 13, 2008 3:45 pm

Is this MOD working in v3.0.2?
www.pijanitvor.com

Gardening & Fishing - If you want, I will open english subforum for you ==> send me PM here ||

ILoveWHU
Registered User
Posts: 44
Joined: Sun Jul 06, 2008 9:58 pm

Re: [Dev] Hide posting text from guests

Post by ILoveWHU » Sun Jul 20, 2008 10:15 am

Sunka wrote:Is this MOD working in v3.0.2?
Yes. The modification is exactly the same for 3.0.0, 3.0.1 and 3.0.2

User avatar
^[GS]^
Registered User
Posts: 274
Joined: Sun Aug 06, 2006 10:59 pm
Location: Argentina
Contact:

Re: [Dev] Hide posting text from guests

Post by ^[GS]^ » Sun Jul 20, 2008 12:14 pm

:O! very very nice ^^

kiran_n444
Registered User
Posts: 115
Joined: Mon May 21, 2007 9:42 pm

Re: [Dev] Hide posting text from guests

Post by kiran_n444 » Tue Jul 22, 2008 9:08 pm

o dam dis is cool.

ILoveWHU
Registered User
Posts: 44
Joined: Sun Jul 06, 2008 9:58 pm

Re: [Beta] Hide posting text from guests

Post by ILoveWHU » Sat Aug 16, 2008 10:06 am

Version 0.0.2 code now in 1st post.

Changed to ensure it processes correctly when members bbcode is in 1st position of a post
Added code to support Handyman's Ajax chat mod

drankur
Registered User
Posts: 271
Joined: Sat Dec 22, 2007 4:16 am

Re: [Beta] Hide posting text from guests

Post by drankur » Sun Aug 17, 2008 6:55 am

all things are fine but i am getting double bb code display in quick reply:

Image

help plz

madtay
Registered User
Posts: 328
Joined: Tue Jun 27, 2006 10:27 pm
Contact:

Re: [Beta] Hide posting text from guests

Post by madtay » Sun Aug 17, 2008 12:03 pm

Great mod but i am recieving this error when viewing the forum as a guest:

Code: Select all

[phpBB Debug] PHP Notice: in file /viewtopic.php on line 965: Wrong parameter count for substr_count()
[phpBB Debug] PHP Notice: in file /viewtopic.php on line 965: Wrong parameter count for substr_count()
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3613: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2977)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3615: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2977)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3616: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2977)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 3617: Cannot modify header information - headers already sent by (output started at /includes/functions.php:2977)

Locked

Return to “[3.0.x] MODs in Development”

Who is online

Users browsing this forum: No registered users and 20 guests