You are here

function nd_eval in Node displays 6

Wrapper function around PHP eval(). We don't use drupal_eval because custom fields might need properties from the current node object.

Parameters

string $code The code to evaluate from the custom field.:

stdClass $node The current node object.:

Return value

string $output The output from eval.

1 call to nd_eval()
nd_eval_code in ./nd.module
Evaluate custom code.

File

./nd.module, line 399
Main node displays file.

Code

function nd_eval($code, $node) {
  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);
  }
  ob_start();
  print eval('?>' . $code);
  $output = ob_get_contents();
  ob_end_clean();

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