You are here

function asset_get_macros in Asset 5

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

Return all macros as an array.

3 calls to asset_get_macros()
asset_filter in ./asset.module
Implementation of hook_filter().
asset_nodeapi in ./asset.module
Implementation of hook_nodeapi() This is where we build the asset_node records.
asset_wizard_form in ./asset_wizard.inc
Main form builder function for the asset wizard.

File

./asset.module, line 441

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;
}