You are here

function extract_php in Custom Breadcrumbs 6.2

Same name and namespace in other branches
  1. 7.2 custom_breadcrumbs.module \extract_php()

Determines if a text string is php code and if it is, evaluate it.

Parameters

$text: A potential code snippet to evaluate.

$objs: An optional array of objects to make available to the php code snippet.

Return value

If the text string contains a php code snippet, it will be evaluated, and if the result is an array, it will be returned. Otherwise nothing is returned.

1 call to extract_php()
_custom_breadcrumbs_get_breadcrumb in ./custom_breadcrumbs.module
Gets the custom breadcrumb.

File

./custom_breadcrumbs.module, line 1140
Provide custom breadcrumbs for node-type pages and base functionality for submodules to add custom breadcrumbs for other types of pages.

Code

function extract_php($text, $objs = array()) {
  if (drupal_substr(trim($text), 0, 5) == '<?php') {

    // Strip php tags.
    $text = str_replace(array(
      '<?php',
      '?>',
    ), '', $text);
    foreach ($objs as $key => $obj) {
      ${$key} = is_object($obj) ? drupal_clone($obj) : $obj;
    }
    ob_start();
    $output = eval($text);
    ob_end_clean();
    return is_array($output) ? $output : NULL;
  }
}