Nofollow
-
Hi all, I love this script and have been getting acquainted for a couple of hours… I noticed the following:
1. User can post html. If they drop a whole url it will print with a “nofollow” BUT if they actually write http://, then it will print without it. Is there a way to make it consistently “nofollow”?
2. I would like to make the link in members’ profiles a “dofollow” but I am afraid to touch the code and all of a sudden make all links drop by members like that. I would only want to switch it off in the profile area.
Thanks.
-
1. Haven’t looked into that yet, but it should definitely be nofollowed no matter how the link is formatted so this might be worth looking into/filing a trac for.
2. You run the risk of people spamming through their profile if they figure that out, but if you’re willing to take the risk, it’s not too difficult. Open up your templates profile.php, and add the following at the top of the page;
<?php $GLOBALS['bb_nofollow_off'] = TRUE; ?>
…then open bb-includes/backpress/functions.formatting.php and go to line 950 at the bottom of function _make_url_clickable_cb() and replace;
return $matches[1] . "<a href="$url" rel="nofollow">$url</a>";
with;
return (isset($GLOBALS['bb_nofollow_off'])) ? $matches[1] . "<a href="$url">$url</a>" : $matches[1] . "<a href="$url" rel="nofollow">$url</a>";
Note that if you have deep integration, you’ll have to change the above line in your WordPress version of the same function, not the bbPress one.
Thank you, mwaterous! This works perfectly.
Now, the profile link is “follow”, the url link in messages continues to be “nofollow” and the HTML link (<a) continues to be “follow”. So this will be the only issue… it is just too tempting.
As for spam, yes, I am walking on the razors edge. But the forum is by invitation/contribution only. Not for anyone that wants to register. As members contribute, I figure a real link is the least I can offer… as in gratitude.
How do I file a trac for #1 problem?
I wouldn’t yet, at least not until it can be reproduced. At this point, I can’t, though I might not be taking the same steps as you. I tried two links, one with http and one without, and they were both nofollowed.
What version of bbPress are you using?
Is this just for a regular post in a regular forum, or is there special circumstances?
Is it for links that are discovered by bbPress, or the ones that are explicitly declared by the poster with A tags?
Ah it seems if you explicity declare the link with A, they’re not discovered and nofollowed. Spammer loophole.
If you have a my_plugins.php (or something similar) in your bb-plugins/, you can add this there. Alternatively, you could add it to your themes functions.php file. It’s only stopgap though, it’s not bulletproof, I’m a little rusty on regular expressions since I’ve been developing themes more lately than I have been doing real programming;
function my_nofollow ( $ret ) {
return preg_replace('#(<a[^"]+"[^"]+")>([^<]+</a>)#', '$1 rel="nofollow">$2', $ret);
}
add_filter('pre_post', 'my_nofollow');I’m not sure if this would qualify for trac, considering it’s not so much of a bug as it is an oversight? Mods?
Turns out there is a
bb_rel_nofollow()
already, it’s just not hooked into anything (?).So you could just omit mine, and add the following;
add_filter('pre_post', 'bb_rel_nofollow');
Hi, mwaterous. That is FANTASTIC. Thank you!
I have to run some more tests but I think you nailed it. I tested:
Test.com
http://www.test.com (simply written www, no html)
http://test.com (http: but no html)
<a/ a tag)
Except for the 1st one, all were converted into a link and ALL carried the nofollow tag. This is for posting messages by members on regular threads.
I placed that last line anywhere inside /bb-includes/functions.bb-formatting.php, as I didn’t have any of the other files you mentioned. In case others need this, is it possible to stick this one up? When I researched this subject here I found a few topics with at least 7 or 8 members looking for an answer to this problem. But the only answer was provided by you today.
Still ONE MORE spammer alert: if a member places HTML in its signature (using the <a tag) this will escape your filter and the signature will go “follow”
On another subject, if I may…
1. Signatures: do they only appear in the first post made by the member? I believe so.
2. I messed up the .css and can’t refix it. The size of the font for the “textarea” where messages are entered is close to nothing and I have to glue my eyes to screen to read what I am writing. This is the only field where the font-size was nuked. Where and in which .css should I fix this?
Thanks!
If your theme doesn’t already have a functions.php, you can create one and add that code to it – it will automatically be found and run by bbPress, and it’s a lot safer than adding it to the core code (next time you upgrade, it will overwrite).
1. bbPress doesn’t have signatures by default, so I’m guessing you’re using a plugin for this? If you are, hopefully the designer has added a filter which you can hook into, but we’d have to take a look at the specific plugin you’re using.
2. You should have a style.css file in your bb-templates/yourthemename/ directory. Find that file, and do a search for ‘textarea’. It should possibly be under ‘.postform textarea’ to be more specific. Look and see if there’s a font-size attribute there, and up the size.
mwaterous, thank you again. Did I say thank you?
I followed your advise and created the file functions.php where I placed that line of code and incorporated it to the bbpress theme at the root. This worked equally well. The only url that wouldn’t get the “nofollow” is the one at the signature. Never thought about the upgrade issue
Correct, the signature corresponds to _ck_’s plugin. Never thought about that either. Perhaps I should contact him privately for adding a piece of code? (maybe I should read discussions on this topic too.)
Style sheet solved. Yes, it was an issue with the “textarea” field. Problem was actually “cache” on my browser that wouldn’t let me see the changes. So I flush the dns and all was working fine.
—
I have found another bug in another plugin “subscribe to topics” where after activation admin will only be able to logout from within the forum. Attempting to logout from the admin panel will result in a serious of errors:
Warning: Cannot modify header information – headers already sent by (output started at /home/skincare/public_html/bbpress/bb-includes/functions.bb-core.php:596) in /home/skincare/public_html/bbpress/bb-includes/backpress/class.wp-auth.php on line 292
Should I discuss the above 2 topics (signature and subscribe-to-topics) in the corresponding threads?
Look for the function add_signature_to_post in bb-signatures.php, line 78 should look like;
$text.='<div class="signature">'.nl2br($signature).'</div>';
Change it to
$signature = nl2br($signature);
$text.='<div class="signature">'.bb_rel_nofollow($signature).'</div>';Signatures problem most likely has to do with bb_send_headers(); on line 297, but I’d have to install it to find out for sure. If I can spare the time, I’ll let you know.
Found the solution for the “nofollow” in signatures, similar to the one you proposed for posts:
https://bbpress.org/plugins/topic/bbpress-signatures/page/2/#post-3179
Ooops, I think we posted at the same time. Ok, I tested it and it works so now all links in the message area are nofollow with no holes and the profile has the follow as I wanted. Very good Thank you, mwaterous.
- You must be logged in to reply to this topic.