You are here

function finder_eval in Finder 7

Same name and namespace in other branches
  1. 6 finder.module \finder_eval()
  2. 7.2 includes/build.inc \finder_eval()

Evaluate a string of PHP code.

This is a wrapper around PHP's eval(). It uses output buffering to capture both returned value and printed text. Allows to use variables with the given code. Using this wrapper also ensures that the PHP code which is evaluated can not overwrite any variables in the calling code, unlike a regular eval() call. In other words, we evaluate the code with independent variable scope.

Parameters

$code: The code to evaluate.

$variables: Variables to import to local variable scope.

Return value

A string containing the printed output of the code, followed by the returned output of the code.

3 calls to finder_eval()
finder_optionwidgets_finder_element in modules/finder_optionwidgets/finder_optionwidgets.module
Implements hook_finder_element().
finder_results in ./finder.module
Create finder results output.
finder_views_get_args in modules/finder_views/finder_views.module
Convert finder arguments text field entry to an array of arguments.

File

./finder.module, line 1591
The finder module.

Code

function finder_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);
  }
  extract($variables);
  ob_start();
  print eval('?>' . $code);
  $output = ob_get_contents();
  ob_end_clean();

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