You are here

function _insert_view_substitute_tags in Insert View 5

Same name and namespace in other branches
  1. 6.2 insert_view.module \_insert_view_substitute_tags()
  2. 6 insert_view.module \_insert_view_substitute_tags()
  3. 7.2 insert_view.module \_insert_view_substitute_tags()
1 call to _insert_view_substitute_tags()
insert_view_filter in ./insert_view.module

File

./insert_view.module, line 77

Code

function _insert_view_substitute_tags($text) {
  if (preg_match_all("/\\[view(_pager)?:([^=\\]]+)=?([^=\\]]+)?=?([^\\]]*)?\\]/i", $text, $match)) {
    foreach ($match[3] as $key => $value) {
      $match[1][$key] == '_pager' ? $pager = TRUE : ($pager = FALSE);
      $viewname = $match[2][$key];
      $limit = $match[3][$key];
      $view_args = $match[4][$key];
      $view = views_get_view($viewname);
      $replace = "";
      if ($view_args != NULL) {
        $view_args = explode(',', $view_args);
      }
      else {
        $view_args = array();
      }
      if ($view) {

        // set $view->url to current page so views with exposed filters submit back to the same page
        $view->url = drupal_get_path_alias($_GET['q']);
        if (is_numeric($limit)) {
          $replace = views_build_view('embed', $view, $view_args, $pager, $limit);
        }
        else {
          $replace = views_build_view('embed', $view, $view_args, FALSE, NULL);
        }
        $mtch[] = $match[0][$key];
        $repl[] = $replace;
      }
    }
    return str_replace($mtch, $repl, $text);
  }
  return $text;
}