You are here

function _shortcode_parse_attrs in Shortcode 7.2

Same name and namespace in other branches
  1. 6 shortcode.module \_shortcode_parse_attrs()
  2. 7 shortcode.module \_shortcode_parse_attrs()

Retrieve all attributes from the ShortCodes tag.

The attributes list has the attribute name as the key and the value of the attribute as the value in the key/value pair. This allows for easier retrieval of the attributes, since all attributes have to be known.

Parameters

string $text: The ShortCode tag attribute line.

Return value

array List of attributes and their value.

1 call to _shortcode_parse_attrs()
_shortcode_process_tag in ./shortcode.module
Regular Expression callable for do_shortcode() for calling ShortCode hook.

File

./shortcode.module, line 390
Provides ShortCodes filter framework and API (like WP ShortCodes)

Code

function _shortcode_parse_attrs($text) {
  $attrs = 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);
  $text = html_entity_decode($text);
  if (preg_match_all($pattern, $text, $match, PREG_SET_ORDER)) {
    foreach ($match as $m) {
      if (!empty($m[1])) {
        $attrs[strtolower($m[1])] = stripcslashes($m[2]);
      }
      elseif (!empty($m[3])) {
        $attrs[strtolower($m[3])] = stripcslashes($m[4]);
      }
      elseif (!empty($m[5])) {
        $attrs[strtolower($m[5])] = stripcslashes($m[6]);
      }
      elseif (isset($m[7]) and strlen($m[7])) {
        $attrs[] = stripcslashes($m[7]);
      }
      elseif (isset($m[8])) {
        $attrs[] = stripcslashes($m[8]);
      }
    }
  }
  else {
    $attrs[] = ltrim($text);
  }
  return $attrs;
}