diff -Naur ../blockanonymouslinks/blockanonymouslinks.module ./blockanonymouslinks.module --- ../blockanonymouslinks/blockanonymouslinks.module 2008-03-15 01:13:38.000000000 +1000 +++ ./blockanonymouslinks.module 2009-09-09 19:41:24.000000000 +1000 @@ -13,14 +13,83 @@ global $user; switch ($op) { - case "validate": - //check if anonymous user + 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", $a1["comment"]) || preg_match("@(www\.[a-zA-Z0-9\@:%_+*~#?&=.,/;-]*[a-zA-Z0-9\@:%_+~#\&=/;-])+@se", $a1["comment"])) { - form_set_error("comment", t("You have to be logged in to post links. This is an anti-spam measure.")); + //the checks are derived from the filter module > _filter_url method + preg_match_all("@(http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)+@se", $a1["comment"], $matchs1, PREG_OFFSET_CAPTURE); + preg_match_all("@([^/]|^)(www\.[a-zA-Z0-9\@:%_+*~#?&=.,/;-]*[a-zA-Z0-9\@:%_+~#\&=/;-])+@se", $a1["comment"], $matchs2, PREG_OFFSET_CAPTURE); + $allowed = variable_get('blockanonymouslinks_maximum_allowed', 0); + $cm1 = count($matchs1[0]); + $cm2 = count($matchs2[0]); + $usedlinks = $cm1 + $cm2; + if ($usedlinks > $allowed) { + form_set_error("comment", t("Your message contains too many clickable links. You have to be logged in to post that many links. This is an anti-spam measure.")); } + //drupal_set_message("Links $cm1 $cm2 $allowed links."); } - break; + break; } -} \ No newline at end of file +} + + +/** + * Implementation of hook_help(). + */ +function blockanonymouslinks_help($path, $args) { + $output = ''; + + switch ($path) { + case "admin/help#blockanonymouslinks": + $output = '
'. t("Allows you to block anonymous comments that contain too many URLs"). '
'; + break; + } + + return $output; +} + + +/** + * Administration page for blockanonymouslinks. + */ +function blockanonymouslinks_admin() { + + $form['blockanonymouslinks_maximum_allowed'] = array( + '#type' => 'textfield', + '#title' => t('Maximum links allowed in anonymous comments'), + '#default_value' => variable_get('blockanonymouslinks_maximum_allowed', 0), + '#size' => 2, + '#maxlength' => 2, + '#description' => t('The maximum number of links permitted in a comment by an anonymous user. Enter 0 to ban such links entirely.'), + ); + + return system_settings_form($form); +} + + +/** + * Implementation of hook_perm(). + */ +function blockanonymouslinks_perm() { + return array('administer blockanonymouslinks configuration'); +} + + +/** + * Implementation of hook_menu(). + */ +function blockanonymouslinks_menu() { + + $items = array(); + + $items['admin/settings/blockanonymouslinks'] = array( + 'title' => t('Block anonymous links'), + 'description' => t('Control settings for blocking links in anonymous comments.'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('blockanonymouslinks_admin'), + 'access arguments' => array('administer blockanonymouslinks configuration'), + 'type' => MENU_NORMAL_ITEM, + ); + + return $items; +} diff -Naur ../blockanonymouslinks/README.txt ./README.txt --- ../blockanonymouslinks/README.txt 2007-09-13 23:20:24.000000000 +1000 +++ ./README.txt 2009-09-09 20:07:58.000000000 +1000 @@ -1,4 +1,5 @@ -BlockAnonymousLinks is a simple module which blocks comments from anonymous users that contain links. +BlockAnonymousLinks is a simple module which blocksallows you to +restrict links in comments from anonymous users. Goal ---- @@ -6,19 +7,36 @@ Idea ---- -It relies on the fact that most spam messages contain links and also on the fact that (for now) (most) spambots don't register on the sites they want to spam. +It relies on the fact that most spam messages contain links and also +on the fact that (for now) (most) spambots don't register on the +sites they want to spam. Use case -------- -This comes out handy when you want to allow anonymous comments on your site and you want to prevent most of the spam messages from being submitted. If you let users register, they still can post comments with links, IF they are logged in. - -If an anonymous user tries to post a comment which contains a link, he/she will get a message explaining why the comment has been blocked. +This comes out handy when you want to allow anonymous comments on +your site and you want to prevent most of the spam messages from +being submitted. You can specify how many links are permitted in a +comment by an anonymous user (default zero). If you let users +register, logged in users can post comments with unrestricted links. + +If an anonymous user tries to post a comment which contains too many +links, he/she will get a message explaining why the comment has been +blocked. Install ------- -The installation is as simple as uploading the module and enabling it in Drupal. +------- +The installation is as simple as uploading the module and enabling +it in Drupal. To specify other than the default zero permitted +links, you need to enable 'administer blockanonymouslinks +configuration' for your site admin user role. Then select "Block +anonymous links" from the Site configuration menu. Specify the +number of links permitted in an anonymous comment. It is useful to +allow a small number (2, 4, whatever) because smappers usually try +to load comments with dozens of links. Customization ------------- -The default warning is: "You have to be logged in to post links. This is an anti-spam measure." -You can customize this warning using the translation features of Drupal. \ No newline at end of file +The default warning is: "Your message contains too many clickable +links. You have to be logged in to post that many links. This is an +anti-spam measure." You can customize this warning using the +translation features of Drupal.