Your ultimate PunBB resource!
You are not logged in.
Within the handle_url_tag function in parser.php, this works great for me to hide post links from guests
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
thank!
Offline
I would do something like so:
Edit viewtopic.php and find
$cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
Change to
$cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies'], $cur_post['id']);
Now open include/parser.php and find
function parse_message($text, $hide_smilies)
Change to
function parse_message($text, $hide_smilies, $pid = 0)
Find (in parse_message function)
$text = do_clickable($text);
Change to
$text = do_clickable($text, $pid = 0);
Find
function do_clickable($text)
Change to
function do_clickable($text, $pid = 0)
Find (in do_clickable function)
$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
$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
function handle_url_tag($url, $link = '')
Change to
function handle_url_tag($url, $link = '', $pid = 0)
A few lines down change
global $pun_user;
To
global $pun_user, $db;
Then edit the code you pasted above to:
$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
Offhand, you can simplify that very last part:
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:
//
// 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).' … '.substr($url, -10) : $url) : stripslashes($link);
return '<a href="'.$full_url.'">'.$link.'</a>';
}Last edited by guardian34 (2007-01-16 14:24:15)
Offline
ahhhh I was looking for an easier way to get the forum ID. Looks like $cur_topic was it!
Offline
So has the hide by forum filter been tested on 1.2.14? I guess I'll go ahead and try it out.
Offline