You are here

function _nodewords_check_content in Nodewords: D6 Meta Tags 5

Remove any content from the $tag that is not allowed in a meta content attribute.

1 string reference to '_nodewords_check_content'
_nodewords_prepare in ./nodewords.module
Prepare the tags so they are ready for output. This includes:

File

./nodewords.module, line 873
Assign META tags to nodes, vocabularies, terms and pages.

Code

function _nodewords_check_content($text) {
  $settings = _nodewords_get_settings();
  $size = $settings['max_size'];
  if (function_exists('preg_replace')) {
    $pattern = '/<img\\s[^>]*alt=["\']([^"\']*)["\'][^>]*>/i';
    $replacement = '${1}';
    $text = preg_replace($pattern, $replacement, $text);
  }
  $text = strip_tags($text);
  $text = check_plain($text);
  $needles = array(
    '&nbsp;',
    "\r",
    "\n",
    '&#039;',
  );
  $replaces = array(
    ' ',
    ' ',
    ' ',
    "'",
  );
  $text = str_replace($needles, $replaces, $text);
  $text = trim($text);
  $text = preg_replace('/\\s+/', ' ', $text);
  if ($size > 0 && drupal_strlen($text) > $size) {
    $text = truncate_utf8($text, $size);
    $length = strrpos($text, ' ');

    //TODO: is this UTF safe?
    if (!is_bool($length)) {
      $text = substr($text, 0, $length);

      //TODO: is this UTF safe?
    }
  }

  // Do not index pager pages
  if (isset($_GET['page']) && is_numeric($_GET['page'])) {
    $text = preg_replace('!^index!', 'noindex', $text);
  }
  return $text;
}