You are here

function MOVED_textactions_evaluate_text in ImageCache Actions 6

Generate the dynamic text for this image. Was textactions caption - now merged as an option of text2canvas

TODO further code review for safety etc

Parameters

$image object, as provided by imageapi:

$action definition:

Return value

$text Plain or code string to be placed on the imagecache process.

File

./textactions.inc, line 247
Helper functions for imagecache_textactions

Code

function MOVED_textactions_evaluate_text($image, $action) {

  // HOOK_metadata from file attempts to glean info from any direction possible - EXIF, XMP, DB, description.txt
  // @see the meta_* project
  $meta = module_invoke_all('metadata_from_file', $image->source);
  $file_data = (object) $meta;

  // Try to load the attached node - if any
  static $panic;

  #This can trigger recursion! build-load-build-etc
  if ($panic) {
    return;
  }
  $panic = TRUE;
  $node = imagecache_actions_node_from_filepath($image->source, $file_data);
  $panic = FALSE;

  // Process the php using drupal_eval (rather than eval),
  // but with GLOBAL variables, so they can be passed successfully
  $GLOBALS['image'] = $image;
  $GLOBALS['node'] = $node;
  $GLOBALS['file_data'] = $file_data;
  $text = @drupal_eval('<' . '?php global $node; global $image; global $file_data; ' . $action['text'] . ' ?' . '>');

  // Warn about errors in the php code if I can
  if (empty($text) && function_exists('error_get_last') && ($last_error = error_get_last())) {
    drupal_set_message("Problem evaluating dynamic text. <br/><code>{$action['text']}</code><br/> " . $last_error['message'], 'error');
  }
  return $text;
}