You are here

function views_customfield_handler_field_phpcode_eval in Views Custom Field 5

Evaluate a string of PHP code. Mostly copied from drupal_eval().

Parameters

string $code:

mixed $static:

array $data:

Return value

string

1 call to views_customfield_handler_field_phpcode_eval()
views_customfield_handler_field_phpcode in ./views_customfield.module
Views field handler: Display row-specific custom text using PHP.

File

./views_customfield.module, line 154

Code

function views_customfield_handler_field_phpcode_eval($code, &$static, $data) {
  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;
}