Extend module to block links in nodes!

CompShack - October 10, 2008 - 23:44
Project:Block anonymous links
Version:6.x-1.0
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

Me again :)

I have a forum on my site http://www.CompShack.com/forum where guests can ask questions without the need to register. I get some span on there every now and then (not much due to the CAPTCHA module). Do you think you can extend the "guest" link blocking to include nodes as well and not just comments?

Again, this is such an important module to my site and would love to see this feature in the future. Thanks for your time!

#1

CompShack - October 12, 2008 - 02:32

Hi again,

I've added the below hook to the .module file to do the above. Can you please provide your feedback on this? The preg_match though doesn't seem to check for a url that looks like samplewebsite.com - do you think you can help me add that to be checked also? For example, if the url doesn't start with http then it passes.

<?php
/**
* Implementation of hook_nodeapi().
*/
function blockanonymouslinks_nodeapi (&$node, $op, $a3 = NULL, $a4 = NULL) {

    global
$user;
    switch (
$op) {
      case
"validate":
      
//check if anonymous user
     
if (!$user->uid) {
         
//the checks are derived from the filter module > _filter_url method
       
if (preg_match("@(http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)+@se", $node->body) || preg_match("@(www\.[a-zA-Z0-9\@:%_+*~#?&=.,/;-]*[a-zA-Z0-9\@:%_+~#\&=/;-])+@se", $node->body)) {
         
form_set_error("node", t("You have to be logged in to post links. This is an anti-spam measure."));
     
      }
     
      }
     break;
     }
}
?>

#2

PieterDC - October 14, 2008 - 10:07

Technically spoken, this is probably possible.

But, as (the standard link-convertor-rule of) Drupal doesn't convert samplewebsite.com into a clickable link (when it's shown), there's no gain for spammers to have their link unclickable (read as: not followed by Search Engine Crawlers) on your website.

So, personally, I wouldn't really mind.

Pls correct me if I misunderstood something ;-)

#3

CompShack - October 14, 2008 - 23:45

I agree with you.

I have modified your module to extend its functionality to nodes as well (and already in production at http://www.CompShack.com ) :) - I don't have all the fancy admin interface to pick and choose what node type to activate this one yet. Might do that but not yet.

I'm also working on adding the following feature http://drupal.org/node/278023

If you are interested in expanding the module, I can provide a patch for you to look at, if not then that's ok too :)- Its something That I needed and willing to share if you think it will be of a value to the module!

Thanks!

#4

PieterDC - October 26, 2008 - 23:11

I'm interested in expanding the functionality of this module in this way.
An admin interface to define which content types and/or comments have to be checked, would be handy.

If someone provides a patch .. I'll test it and include it in a new official release.

The patch would need to:
- provide an admin menu-item
- limit access to site-admins (or define a custom right)
- give a list of checkboxes, build from the list of node types (http://api.drupal.org/api/function/node_get_types/6). and add a checkbox for comments
- save the values of the checked checkboxes in a drupal system variable/preference/setting
- when checking for links (in hook_nodeapi, ...) the chosen prefences have to be respected.
So far, my rapid thinking. Gotta get back to work now.

Greetings,
Pieter

#5

Flying Drupalist - October 23, 2008 - 23:33

Thank you, very interested in this feature. I'll be trying CompShack's edit. Thanks a lot.

#6

Flying Drupalist - September 25, 2009 - 17:11

Works fine by the way, any interest in committing it?

 
 

Drupal is a registered trademark of Dries Buytaert.