PluginProbe
CSS & JavaScript Toolbox / 11.4
CSS & JavaScript Toolbox v11.4
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / framework / php / evaluator / evaluator.inc.php

evaluator.inc.php in CSS & JavaScript Toolbox 11.4, at framework/php/evaluator/evaluator.inc.php

98 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 /**
7 *
8 */
9 class CJTPHPCodeEvaluator {
10
11 /**
12 * put your comment there...
13 *
14 * @var mixed
15 */
16 private $block = null;
17
18 /**
19 * put your comment there...
20 *
21 * @var mixed
22 */
23 private $output = null;
24
25 /**
26 * put your comment there...
27 *
28 * @param mixed $code
29 * @param stdClass Block object!
30 * @return CJTPHPCodeEvaluator
31 */
32 public function __construct(& $block) {
33 // Hold Block code!
34 $this->block = $block;
35 }
36
37 /**
38 * put your comment there...
39 *
40 * @param mixed $stack
41 */
42 public function exec($stack = array()) {
43 $block =& $this->block;
44 $code =& $block->code;
45 // Make all stack variables available to the local scope.
46 extract($stack);
47 // Evaluate PHP codes!
48 ob_start();
49 // Evaluate PHP code and save the result!
50 $beforeEvalError = error_get_last();
51 $unusedResult = eval("?>{$code}");
52 $afterEvalError = error_get_last();
53 $evalOBuffer = ob_get_clean();
54 $showError = ini_get('display_errors') && WP_DEBUG;
55 $isError = $afterEvalError && ($beforeEvalError != $afterEvalError);
56 // Handling errors!
57 if ($isError && $showError) {
58 $this->output = 'CJT PHP Code Error detected for the following block: <br><br>';
59 $this->output .= "Name: {$block->name}<br>";
60 $this->output .= "ID: #{$block->id}<br><br>";
61 if ($evalOBuffer) {
62 $this->output .= "PHP Error message:<br>";
63 $this->output .= $evalOBuffer;
64 }
65 $this->output .= "PHP Error tech Details:<br>";
66 $this->output .= print_r($afterEvalError, true);
67 }
68 else { // Get evaludated code result!
69 $this->output .= $evalOBuffer;
70 }
71 return $this;
72 }
73
74 /**
75 * put your comment there...
76 *
77 */
78 public function getBlock() {
79 return $this->block;
80 }
81
82 /**
83 * put your comment there...
84 *
85 * @param mixed $code
86 */
87 public static function getInstance($code) {
88 return new CJTPHPCodeEvaluator($code);
89 }
90
91 /**
92 * put your comment there...
93 *
94 */
95 public function getOutput() {
96 return $this->output;
97 }
98 } // End class.