You are here

function asset_get_macros in Asset 5.2

Same name and namespace in other branches
  1. 5 asset.module \asset_get_macros()
  2. 6 asset.module \asset_get_macros()

Return all macros as an array.

Related topics

3 calls to asset_get_macros()
asset_filter in ./asset.module
Implementation of hook_filter().
asset_wizard_menu in ./asset_wizard.module
Implementation of hook_menu().
asset_wizard_preview in ./asset_wizard.module
Step 4: Display a preview of the formatted asset

File

./asset.module, line 1096
Main module.

Code

function asset_get_macros($text) {
  $m = array();
  preg_match_all('/ \\[ ( [^\\[\\]]+ )* \\] /x', $text, $matches);
  $tag_match = (array) array_unique($matches[1]);

  // Don't process duplicates.
  foreach ($tag_match as $macro) {
    $current_macro = '[' . $macro . ']';
    $param = array_map('trim', explode('|', $macro));
    $func_name = array_shift($param);

    // The first macro param is assumed to be the function name.

    //$num_params = count($param); // Get the number of parameters
    if ($func_name == 'asset') {
      $vars = array();
      foreach ($param as $p) {
        $pos = strpos($p, '=');
        $varname = substr($p, 0, $pos);
        $varvalue = substr($p, $pos + 1);
        $vars[$varname] = $varvalue;
      }

      // the full unaltered filter string is the key for the array of filter attributes
      $m[$current_macro] = $vars;
    }
  }
  return $m;
}