You are here

function drupalforfirebug_get_php_exec in Drupal For Firebug 7

Same name and namespace in other branches
  1. 5 drupalforfirebug.module \drupalforfirebug_get_php_exec()
  2. 6 drupalforfirebug.module \drupalforfirebug_get_php_exec()
  3. 7.2 drupalforfirebug.module \drupalforfirebug_get_php_exec()
1 call to drupalforfirebug_get_php_exec()
drupalforfirebug_get_exec_php_callback in ./drupalforfirebug.module
Outputs a Execute PHP Form

File

./drupalforfirebug.module, line 284

Code

function drupalforfirebug_get_php_exec($code = NULL, $token = NULL) {
  $output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
  $output .= '<html><head><title>Execute PHP Code</title>';
  $output .= drupal_get_js();
  $output .= '</head><body>';
  $output .= '<fieldset>';
  if (!user_access('Execute Firebug PHP') || !is_null($code) && !drupal_valid_token($token)) {
    $output .= '<legend>' . t('Execute Firebug PHP') . '</legend>';
    $output .= t('You do not have the proper permissions to use this functionality.');
    $output .= '</fieldset></body></html>';
    print $output;
    exit;
  }
  else {
    if (!$code) {
      $output .= '<legend>' . t('Execute Firebug PHP') . '</legend>';
      $dff_exec_form = drupal_get_form('drupalforfirebug_execute_form');
      $output .= drupal_render($dff_exec_form);
      $output .= '</fieldset></body></html>';
      print $output;
      exit;
    }
    else {
      $output = '<legend>' . t('PHP Code Execution Results') . '</legend>';

      // Run the PHP command, get output in variable
      ob_start();
      eval($code);
      $eval_result = ob_get_contents();
      ob_end_clean();
      $output .= '<PRE>' . $eval_result . '</PRE>';
      $output .= '</fieldset></body></html>';
      print $output;
      exit;
    }
  }
}