You are here

function textactions_evaluate_text in ImageCache Actions 6

Same name and namespace in other branches
  1. 5.3 textactions.inc \textactions_evaluate_text()
  2. 5.2 textactions.inc \textactions_evaluate_text()

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.

2 calls to textactions_evaluate_text()
textactions_rendertext_image in ./textrender.inc
Place the text defined in the action onto the current background
textactions_text2canvas_image in ./textactions.inc
Place the source image on the current background

File

./imagecache_textactions.module, line 117

Code

function 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
  if (!empty($image->source)) {
    $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;
}