IRRITATED BY HIGHER CASE TEXT? Has anybody considered making a filter for it?

Comments

Steven’s picture

function uppercase_filter($op, $delta = 0, $format = -1, $text = '') {
  switch ($op) {
    case 'list':
      return array(0 => t('Uppercase filter'));
    case 'process':
      return preg_replace('/[A-Z,.?! ]{8,}/e', 'strtolower("$0")', $text);
    default:
      return $text;
  }
}

Will only do ASCII. Name it uppercase.module, and enable it. Untested.

--
If you have a problem, please search before posting a question.

ñull’s picture

I did use search also Google, but we foreigners, sometimes use one word wrong (higher vs. upper) and don't find it anymore. Very kind you answered anyhow!

I will try to work on it and post back.

ñull’s picture

The filter works like "capital" punishment, which is OK in some communities to keep people in line. Now I have seen how easy it is to include a filter, I will have a look for a filter that can also do uppercase letters with tildes. I found an alternative method on the CVS attic and updated it to present day filters:

 function noshout_filter($op, $delta = 0, $format = -1, $text = '') {
  switch ($op) {
    case 'list':
      return array(0 => t('Enable to convert text with too many uppercase characters to lowercase.'));
    case 'process':
    $no_blanks = preg_replace("/\W|[0-9]/", "", $text);
    $lower = strtolower($no_blanks);
    $nolower = preg_replace("/[a-z]/", "", $no_blanks);

    if (strlen($lower) > 10 && strlen($nolower) > strlen($lower)*0.4) {
      return strtolower($text);
    }
    else {
      return $text;
    }
	    default:
      return $text;
  }
}
jferjan’s picture

Nice one ...thx for the code!

Any ideas how to modify this code to also change node title to lowercase?

jferjan’s picture

Ok, i got it. Now i just have to figure out how to execute this code only when the filter is active.

// Filter node title in the same manner as the rest of the content.
function noshout_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
  if ($op == 'validate') {
    $form = $teaser; //messy
    $no_blanks = preg_replace("/\W|[0-9]/", "", $node->title);
    $lower = strtolower($no_blanks);
    $nolower = preg_replace("/[a-z]/", "", $no_blanks);

    if (strlen($lower) > 10 && strlen($nolower) > strlen($lower)*0.4) {
    form_set_value($form['title'], strtolower($node->title));
    }
  }
} 
clairem’s picture

It's not a problem for me, but then I run a website with only four authorised contributors. I guess that if you have a wider pool of contributors it might be more of an issue.

However, it would be a little risky to deploy a crude one. Consider the following:

These are international organisations:

  • EU, WEU, EFTA, UN, UNICEF, WTO, ASEAN, ECOMOG, NAFTA, UNIDIR, UNIFIL, WHO, WAO, IOC, UNRWA, UNHCR, UNISDR, ICTR, OHCHR, UNEP, UNDP, WMO, INO, WIPO, ITU, ICAO, UNESCO

What would such a filter do with the bulleted paragraph, which is legitimately all upercase?

I suspect that the best that any such filter could do would be to detect posts with more than a given threshold of uppercase words, and hold them back for moderation.