You are here

function _insert_view_substitute_tags in Insert View 7.2

Same name and namespace in other branches
  1. 5 insert_view.module \_insert_view_substitute_tags()
  2. 6.2 insert_view.module \_insert_view_substitute_tags()
  3. 6 insert_view.module \_insert_view_substitute_tags()

Helper function to replace the tag syntax with the actual view.

1 string reference to '_insert_view_substitute_tags'
insert_view_filter_info in ./insert_view.module
Implements hook_filter_info().

File

./insert_view.module, line 51
Insert view.

Code

function _insert_view_substitute_tags($text) {
  if (preg_match_all("/\\[view:([^=\\]]+)=?([^=\\]]+)?=?([^\\]]*)?\\]/i", $text, $match)) {
    $search = $replace = array();
    foreach ($match[0] as $key => $value) {
      $view_name = $match[1][$key];
      $display_id = $match[2][$key] && !is_numeric($match[2][$key]) ? $match[2][$key] : 'default';
      $args = $match[3][$key];
      $view_output = insert_view($view_name, $display_id, $args);
      $search[] = $value;
      $replace[] = !empty($view_output) ? $view_output : '';
    }
    return str_replace($search, $replace, $text);
  }
  return $text;
}