PunBB Resource

Your ultimate PunBB resource!

Keywords:

    (Extended)

You are not logged in.


Login to move these ads to the bottom of the page

#1 2006-12-15 18:53:08

rawrhythms
Member
From: Massachusetts, USA
Registered: 2006-12-02
Posts: 19

moding parser.php to hide links for guests

Within the handle_url_tag function in parser.php, this works great for me to hide post links from guests

Code:

    if ($pun_user['is_guest'] )
    return ' <span class="members-only">[Members only link, sorry Guests]</span>';
    else
    return '<a href="'.$full_url.'" onclick="window.open(this.href); return false;">'.$link.'</a>';

My only problem is I don't want to hide links in all forums from guests.
I'm not a programmer really, can anyone show me what to do for
if guest and if forum id's then parse text only for links?

If I can get this fixed my forum is almost ready for release.

If you'd like to see my forum email me through this site I'll give you the url & password. It's a forum for Reggaeton & Latin Music.

Offline

 

#2 2007-01-16 11:01:17

trongha
Member
Registered: 2006-05-25
Posts: 51

Re: moding parser.php to hide links for guests

thank!


I'm sorry! I speak english very bad.

Offline

 

#3 2007-01-16 13:46:06

ngharo
Member
Registered: 2006-12-21
Posts: 53

Re: moding parser.php to hide links for guests

I would do something like so:

Edit viewtopic.php and find

Code:

$cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);

Change to

Code:

$cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies'], $cur_post['id']);

Now open include/parser.php and find

Code:

function parse_message($text, $hide_smilies)

Change to

Code:

function parse_message($text, $hide_smilies, $pid = 0)

Find (in parse_message function)

Code:

$text = do_clickable($text);

Change to

Code:

$text = do_clickable($text, $pid = 0);

Find

Code:

function do_clickable($text)

Change to

Code:

function do_clickable($text, $pid = 0)

Find (in do_clickable function)

Code:

$text = preg_replace('#([\s\(\)])(https?|ftp|news){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.handle_url_tag(\'$2://$3\')', $text);
  $text = preg_replace('#([\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.handle_url_tag(\'$2.$3\', \'$2.$3\')', $text);

Change to

Code:

$text = preg_replace('#([\s\(\)])(https?|ftp|news){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.handle_url_tag(\'$2://$3\', \'\', '.$pid.')', $text);
  $text = preg_replace('#([\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^"\s\(\)<\[]*)?)#ie', '\'$1\'.handle_url_tag(\'$2.$3\', \'$2.$3\', '.$pid.')', $text);

Find

Code:

function handle_url_tag($url, $link = '')

Change to

Code:

function handle_url_tag($url, $link = '', $pid = 0)

A few lines down change

Code:

global $pun_user;

To

Code:

global $pun_user, $db;

Then edit the code you pasted above to:

Code:

  $guestRestrictLinkForums = Array(1,4,5,10); // Forum IDs to restrict guest links
  $fid = $db->result($db->query("SELECT topics.forum_id FROM topics,posts WHERE posts.id = $pid AND posts.topic_id = topics.id"));
  if ($pun_user['is_guest']) {
    if(in_array($fid, $guestRestrictLinkForums)) {
      return ' <span class="members-only">[Members only link, sorry Guests]</span>';
    }
  }

Sorry i don't have time to test.  I think it will work if my query is correct.

Last edited by ngharo (2007-01-16 13:47:36)

Offline

 

#4 2007-01-16 13:57:21

guardian34
Member
Registered: 2006-06-03
Posts: 124

Re: moding parser.php to hide links for guests

Offhand, you can simplify that very last part:

Code:

if ($pun_user['is_guest'] && in_array($fid, $guestRestrictLinkForums))
    return ' <span class="members-only">[Members only link, sorry Guests]</span>';

Edit: I haven't tested it, but I think you can just change the `handle_url_tag` function:

Code:

//
// Truncate URL if longer than 55 characters (add http:// or ftp:// if missing)
//
function handle_url_tag($url, $link = '')
{
    global $pun_user, $cur_topic;

    // mod: Hide links for guests in certain forums
    $guests_restricted = array(1,4,5,10); // Restricted forum IDs
    if ($pun_user['is_guest'] && in_array($cur_topic['forum_id'], $guests_restricted))
        return '<span class="members-only">[Members only link, sorry Guests]</span>';

    $full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url);
    if (strpos($url, 'www.') === 0)            // If it starts with www, we add http://
        $full_url = 'http://'.$full_url;
    else if (strpos($url, 'ftp.') === 0)    // Else if it starts with ftp, we add ftp://
        $full_url = 'ftp://'.$full_url;
    else if (!preg_match('#^([a-z0-9]{3,6})://#', $url, $bah))     // Else if it doesn't start with abcdef://, we add http://
        $full_url = 'http://'.$full_url;

    // Ok, not very pretty :-)
    $link = ($link == '' || $link == $url) ? ((strlen($url) > 55) ? substr($url, 0 , 39).' &hellip; '.substr($url, -10) : $url) : stripslashes($link);

    return '<a href="'.$full_url.'">'.$link.'</a>';
}

Last edited by guardian34 (2007-01-16 14:24:15)

Offline

 

#5 2007-01-16 14:44:05

ngharo
Member
Registered: 2006-12-21
Posts: 53

Re: moding parser.php to hide links for guests

ahhhh I was looking for an easier way to get the forum ID.  Looks like $cur_topic was it!

Offline

 

#6 2007-01-21 09:44:15

rawrhythms
Member
From: Massachusetts, USA
Registered: 2006-12-02
Posts: 19

Re: moding parser.php to hide links for guests

So has the hide by forum filter been tested on 1.2.14? I guess I'll go ahead and try it out.

Offline

 

Board footer

Based on PunBB
© Copyright 2002–2005 Rickard Andersson

© Copyright 2004–2006 Kristoffer Jansson

User contributed files are property of their respective owners.