PluginProbe
FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager / 1.2.1
FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager v1.2.1
10.56 1.2.1 10 10.1 10.2 10.3 10.31 10.32 10.33 10.34 10.50 10.51 10.52 10.53 10.55 9.0 9.0.1 9.4 trunk 1.0.0 1.1 1.2
easy-code-manager / framework / php / evaluator / evaluator.inc.php

evaluator.inc.php in FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager 1.2.1, 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.