You are here

function oembed_parse_attr in oEmbed 7.0

Same name and namespace in other branches
  1. 7 oembed.filter.inc \oembed_parse_attr()

Retrieve all attributes from the shortcodes tag.

Parameters

string $text:

Return value

array List of attributes and their value.

See also

shortcode_parse_atts in WordPress 3.1.3.

2 calls to oembed_parse_attr()
oembed_filter_oembed_process in ./oembed.filter.inc
Implements hook_filter_FILTER_process().
oembed_preg_tag_replace in ./oembed.filter.inc
PREG replace callback finds [embed] shortcodes, URLs and request options.

File

./oembed.filter.inc, line 221
Input filter that enhances oEmbed enabled URLs with extra content

Code

function oembed_parse_attr($text) {
  $attributes = array();
  $pattern = '/(\\w+)\\s*=\\s*"([^"]*)"(?:\\s|$)|(\\w+)\\s*=\\s*\'([^\']*)\'(?:\\s|$)|(\\w+)\\s*=\\s*([^\\s\'"]+)(?:\\s|$)|"([^"]*)"(?:\\s|$)|(\\S+)(?:\\s|$)/';
  $text = preg_replace("/[\\x{00a0}\\x{200b}]+/u", " ", $text);
  if (preg_match_all($pattern, $text, $matches, PREG_SET_ORDER)) {
    foreach ($matches as $match) {
      if (!empty($match[1])) {
        $attributes[strtolower($match[1])] = stripcslashes($match[2]);
      }
      elseif (!empty($match[3])) {
        $attributes[strtolower($match[3])] = stripcslashes($match[4]);
      }
      elseif (!empty($match[5])) {
        $attributes[strtolower($match[5])] = stripcslashes($match[6]);
      }
      elseif (isset($match[7]) and strlen($match[7])) {
        $attributes[] = stripcslashes($match[7]);
      }
      elseif (isset($match[8])) {
        $attributes[] = stripcslashes($match[8]);
      }
    }
  }
  else {
    $attributes = ltrim($text);
  }
  return $attributes;
}