You are here

function viewreference_eval in View reference 7.3

Same name and namespace in other branches
  1. 6.3 viewreference.module \viewreference_eval()
  2. 6.2 viewreference.module \viewreference_eval()

A version of php_eval() that allows passing of variables.

1 call to viewreference_eval()
viewreference_get_element_args in ./viewreference.module
Convert arguments text field entry to an array of arguments.

File

./viewreference.module, line 880
Defines a field type for referencing a view from a node.

Code

function viewreference_eval($code, $variables = array()) {
  global $theme_path, $theme_info, $conf;

  // Store current theme path.
  $old_theme_path = $theme_path;

  // Restore theme_path to the theme, as long as drupal_eval() executes,
  // so code evaluted will not see the caller module as the current theme.
  // If theme info is not initialized get the path from theme_default.
  if (!isset($theme_info)) {
    $theme_path = drupal_get_path('theme', $conf['theme_default']);
  }
  else {
    $theme_path = dirname($theme_info->filename);
  }
  foreach ((array) $variables as $key => $value) {
    ${$key} = $value;
  }
  ob_start();
  print eval('?>' . $code);
  $output = ob_get_contents();
  ob_end_clean();

  // Recover original theme path.
  $theme_path = $old_theme_path;
  return $output;
}