Skip to main content
added 2 characters in body
Source Link
Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182

Note: to make a list of words, the most straight forward way to do so is via the RegEx expressions (in which you could also use the lexapro"lexapro" word of course, which would make the first 2 Rules Conditions obsolete).

Note: to make a list of words, the most straight forward way to do so is via the RegEx expressions (in which you could also use the lexapro word of course, which would make the first 2 Rules Conditions obsolete).

Note: to make a list of words, the most straight forward way to do so is via the RegEx expressions (in which you could also use the "lexapro" word of course, which would make the first 2 Rules Conditions obsolete).

Refine rule
Source Link
Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182
{ "rules_block_specific_words_in_node_body" : {
    "LABEL" : "Block specific words in node body",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave" : [] },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "1""2" : "1""2" } }
        }
      },
      { "OR" : [
          { "text_matches" : { "text" : [ "node-unchanged:title" ], "match" : "lexapro" } },
          { "text_matches" : { "text" : [ "node:body:value" ], "match" : "lexapro" } },
          { "text_matches" : {
              "text" : [ "node-unchanged:title" ],
              "match" : "ANotAllowedTextStringInTitle",
              "operation" : "regex"
            }
          },
          { "text_matches" : {
              "text" : [ "node:body:value" ],
              "match" : "AnotherTextStringThatIsNotAllowed""ANotAllowedTextStringInBody",
              "operation" : "regex"
            }
          }
        ]
      }
    ],
    "DO" : [
      { "redirect" : { "url" : "no_spammers_allowed" } },
      { "node_unpublish" : { "node" : [ "node" ] } }
    ]
  }
}
  • itIt only applies to anonymousauthenticated users (adapt and/or remove that Rules condition as needed).
  • itIt includes 2 types of4 verifications about the title or the actual body text (eitherat least 1 one of these 4 Rules Conditions must be satisfied, as per the "OR" in these Rules conditionsas per the "OR" in these Rules conditions), ie:
    • an exact match (equal to) of either the title or the content of the body which is (just) "lexapro".
    • using a regular expression (regex) related to the string (in the title) AnotherTextStringThatIsNotAllowedANotAllowedTextStringInTitle or (in the body) ANotAllowedTextStringInBody (use any regex that may fit your needs).
  • ifIf the combination of Rules conditions is satisfied (ie the role matches AND eitherat least 1 of the 4 of the text comparisons are satisfied), then the rules Action is to issue a redirect "before saving the content" (which is thethese 2 Rules Event) to a page with a path like no_spammers_allowed.Actions are triggered:
    • issue a redirect "before saving the content" (which is the Rules Event) to a page with a path like no_spammers_allowed.
    • the node is unpublished.

Note: to make a list of words, the most straight forward way to do so is via the RegEx expressions (in which you could also use the lexapro word of course, which would make the first 2 Rules Conditions obsolete).

{ "rules_block_specific_words_in_node_body" : {
    "LABEL" : "Block specific words in node body",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave" : [] },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "1" : "1" } }
        }
      },
      { "OR" : [
          { "text_matches" : { "text" : [ "node-unchanged:body:value" ], "match" : "lexapro" } },
          { "text_matches" : {
              "text" : [ "node-unchanged:body:value" ],
              "match" : "AnotherTextStringThatIsNotAllowed",
              "operation" : "regex"
            }
          }
        ]
      }
    ],
    "DO" : [ { "redirect" : { "url" : "no_spammers_allowed" } } ]
  }
}
  • it only applies to anonymous users (adapt and/or remove that Rules condition as needed).
  • it includes 2 types of verifications about the actual body text (either one of these Rules Conditions must be satisfied, as per the "OR" in these Rules conditions), ie:
    • an exact match (equal to) of the content of the body which is (just) "lexapro".
    • using a regular expression (regex) related to the string AnotherTextStringThatIsNotAllowed (use any regex that may fit your needs).
  • if the combination of Rules conditions is satisfied (ie the role matches AND either of the text comparisons are satisfied), then the rules Action is to issue a redirect "before saving the content" (which is the Rules Event) to a page with a path like no_spammers_allowed.
{ "rules_block_specific_words_in_node_body" : {
    "LABEL" : "Block specific words in node body",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave" : [] },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "2" : "2" } }
        }
      },
      { "OR" : [
          { "text_matches" : { "text" : [ "node:title" ], "match" : "lexapro" } },
          { "text_matches" : { "text" : [ "node:body:value" ], "match" : "lexapro" } },
          { "text_matches" : {
              "text" : [ "node:title" ],
              "match" : "ANotAllowedTextStringInTitle",
              "operation" : "regex"
            }
          },
          { "text_matches" : {
              "text" : [ "node:body:value" ],
              "match" : "ANotAllowedTextStringInBody",
              "operation" : "regex"
            }
          }
        ]
      }
    ],
    "DO" : [
      { "redirect" : { "url" : "no_spammers_allowed" } },
      { "node_unpublish" : { "node" : [ "node" ] } }
    ]
  }
}
  • It only applies to authenticated users (adapt and/or remove that Rules condition as needed).
  • It includes 4 verifications about the title or the actual body text (at least 1 one of these 4 Rules Conditions must be satisfied, as per the "OR" in these Rules conditions), ie:
    • an exact match (equal to) of either the title or the content of the body which is (just) "lexapro".
    • using a regular expression (regex) related to the string (in the title) ANotAllowedTextStringInTitle or (in the body) ANotAllowedTextStringInBody (use any regex that may fit your needs).
  • If the combination of Rules conditions is satisfied (ie the role matches AND at least 1 of the 4 of the text comparisons are satisfied), then these 2 Rules Actions are triggered:
    • issue a redirect "before saving the content" (which is the Rules Event) to a page with a path like no_spammers_allowed.
    • the node is unpublished.

Note: to make a list of words, the most straight forward way to do so is via the RegEx expressions (in which you could also use the lexapro word of course, which would make the first 2 Rules Conditions obsolete).

Source Link
Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182

Have a look at this rule (in Rules export format):

{ "rules_block_specific_words_in_node_body" : {
    "LABEL" : "Block specific words in node body",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave" : [] },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "1" : "1" } }
        }
      },
      { "OR" : [
          { "text_matches" : { "text" : [ "node-unchanged:body:value" ], "match" : "lexapro" } },
          { "text_matches" : {
              "text" : [ "node-unchanged:body:value" ],
              "match" : "AnotherTextStringThatIsNotAllowed",
              "operation" : "regex"
            }
          }
        ]
      }
    ],
    "DO" : [ { "redirect" : { "url" : "no_spammers_allowed" } } ]
  }
}

Just import it in your own site (using the Rules UI) to experiment with it, and make it fit your needs.

Some more details about the logic included in the above sample:

  • it only applies to anonymous users (adapt and/or remove that Rules condition as needed).
  • it includes 2 types of verifications about the actual body text (either one of these Rules Conditions must be satisfied, as per the "OR" in these Rules conditions), ie:
    • an exact match (equal to) of the content of the body which is (just) "lexapro".
    • using a regular expression (regex) related to the string AnotherTextStringThatIsNotAllowed (use any regex that may fit your needs).
  • if the combination of Rules conditions is satisfied (ie the role matches AND either of the text comparisons are satisfied), then the rules Action is to issue a redirect "before saving the content" (which is the Rules Event) to a page with a path like no_spammers_allowed.