You are here

protected function DrupalDefaultMetaTag::tidyValue in Metatag 7

Remove unwanted formatting from a meta tag.

Parameters

string $value: The meta tag value to be tidied up.

Return value

string The meta tag value after it has been tidied up.

4 calls to DrupalDefaultMetaTag::tidyValue()
DrupalDefaultMetaTag::getValue in ./metatag.inc
Get the string value of this meta tag.
DrupalListMetaTag::getValue in ./metatag.inc
Get the string value of this meta tag.
DrupalMaskIconMetaTag::getValue in metatag_favicons/metatag_favicons.mask-icon.class.inc
Get the string value of this meta tag.
DrupalTextMetaTag::getValue in ./metatag.inc
Get the string value of this meta tag.

File

./metatag.inc, line 222
Metatag primary classes.

Class

DrupalDefaultMetaTag
The default meta tag class from which all others inherit.

Code

protected function tidyValue($value) {

  // This shouldn't happen, but protect against tokens returning arrays.
  if (!is_string($value)) {
    return '';
  }

  // Check for Media strings from the WYSIWYG submodule.
  if (module_exists('media_wysiwyg') && strpos($value, '[[{') !== FALSE) {

    // In https://www.drupal.org/node/2129273 media_wysiwyg_filter() was
    // changed to require several additional arguments.
    $langcode = language_default('language');
    $value = media_wysiwyg_filter($value, NULL, NULL, $langcode, NULL, NULL);
  }

  // Specifically replace encoded spaces, because some WYSIWYG editors are
  // silly. Do this before decoding the other HTML entities so that the output
  // doesn't end up with a bunch of a-circumflex characters.
  $value = str_replace(' ', ' ', $value);

  // Decode HTML entities.
  $value = decode_entities($value);

  // First off, remove the <style> tag, because strip_tags() leaves the CSS
  // inline.
  $value = preg_replace('/<style\\b[^>]*>(.*?)<\\/style>/is', '', $value);

  // Ditto for JavaScript.
  $value = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', '', $value);

  // Remove any HTML code that might have been included.
  $value = strip_tags($value);

  // Strip errant whitespace.
  $value = str_replace(array(
    "\r\n",
    "\n",
    "\r",
    "\t",
  ), ' ', $value);
  $value = str_replace('  ', ' ', $value);
  $value = str_replace('  ', ' ', $value);
  $value = trim($value);
  return $value;
}