1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31:
32: class cDebugVisibleAdv implements cDebugInterface, Countable {
33:
34: 35: 36: 37: 38:
39: private static $_instance;
40:
41: 42: 43: 44:
45: private $_aItems;
46:
47: 48: 49: 50:
51: private $_buffer;
52:
53: 54: 55: 56: 57:
58: public static function getInstance() {
59: if (self::$_instance == NULL) {
60: self::$_instance = new cDebugVisibleAdv();
61: }
62:
63: return self::$_instance;
64: }
65:
66: 67: 68:
69: private function __construct() {
70: $this->_aItems = array();
71: }
72:
73: 74: 75: 76: 77: 78:
79: public function add($mVariable, $sVariableDescription = '') {
80: $oItem = new cDebugVisibleAdvItem();
81: $oItem->setValue($mVariable);
82: $oItem->setDescription($sVariableDescription);
83: $this->_aItems[] = $oItem;
84: }
85:
86: 87: 88:
89: public function reset() {
90: $this->_aItems = array();
91: }
92:
93: 94: 95: 96: 97: 98:
99: public function out($sText) {
100: $this->_buffer .= $sText . "\n";
101: }
102:
103: 104: 105: 106: 107: 108:
109: public function showAll() {
110: global $cfg;
111:
112: $sHtml = "";
113: if ($this->count() > 0) {
114: $tpl = new cTemplate();
115:
116: $i = 1;
117: foreach ($this->_aItems as $oItem) {
118: $sItemName = cString::getStringLength($oItem->getDescription()) > 0 ? $oItem->getDescription() : ('debug item #' . $i);
119: $sItemValue = $this->_prepareValue($oItem->getValue());
120:
121: $tpl->set("d", "DBG_ITEM_COUNT", $i);
122: $tpl->set("d", "DBG_ITEM_NAME", $sItemName);
123: $tpl->set("d", "DBG_ITEM_VALUE", $sItemValue);
124: $tpl->next();
125:
126: ++$i;
127: }
128: $sHtml .= $tpl->generate($cfg['path']['contenido'] . $cfg["path"]["templates"] . $cfg['templates']['debug_visibleadv'], true);
129: }
130:
131: $buffer = str_replace("\'", "\\'", $this->_buffer);
132: $buffer = str_replace("\"", "\\\"", $buffer);
133: $buffer = str_replace("\n", '\n', $buffer);
134: $buffer = str_replace("\r", '', $buffer);
135:
136:
137: $dir = getcwd();
138: chdir($cfg['path']['contenido']);
139:
140: $tpl = new cTemplate();
141: $tpl->set("s", "DBG_MESSAGE_CONTENT", $buffer);
142: $sHtml .= $tpl->generate($cfg["path"]["templates"] . $cfg["templates"]["debug_header"], true);
143:
144:
145: chdir($dir);
146:
147: echo $sHtml;
148: }
149:
150: 151: 152: 153: 154: 155: 156:
157: private function _prepareValue($mValue) {
158: $bTextarea = false;
159: $bPlainText = false;
160: $sReturn = '';
161: if (is_array($mValue)) {
162: if (sizeof($mValue) > 10) {
163: $bTextarea = true;
164: } else {
165: $bPlainText = true;
166: }
167: }
168: if (is_object($mValue)) {
169: $bTextarea = true;
170: }
171: if (is_string($mValue)) {
172: if (preg_match('/<(.*)>/', $mValue)) {
173: if (cString::getStringLength($mValue) > 40) {
174: $bTextarea = true;
175: } else {
176: $bPlainText = true;
177: $mValue = conHtmlSpecialChars($mValue);
178: }
179: } else {
180: $bPlainText = true;
181: }
182: }
183:
184: if ($bTextarea === true) {
185: $sReturn .= '<textarea rows="14" cols="100">';
186: } elseif ($bPlainText === true) {
187: $sReturn .= '<pre>';
188: } else {
189: $sReturn .= '<pre>';
190: }
191:
192: if (is_array($mValue)) {
193: $sReturn .= print_r($mValue, true);
194: } else {
195: ob_start();
196: var_dump($mValue);
197: $sReturn .= ob_get_contents();
198: ob_end_clean();
199: }
200:
201: if ($bTextarea === true) {
202: $sReturn .= '</textarea>';
203: } elseif ($bPlainText === true) {
204: $sReturn .= '</pre>';
205: } else {
206: $sReturn .= '</pre>';
207: }
208:
209: return $sReturn;
210: }
211:
212: 213: 214: 215: 216:
217: public function count() {
218: return sizeof($this->_aItems);
219: }
220:
221: 222: 223: 224: 225: 226: 227: 228: 229: 230:
231: public function show($mVariable, $sVariableDescription = '', $bExit = false) {
232: try {
233: $oDbgVisible = cDebug::getDebugger(cDebug::DEBUGGER_VISIBLE);
234: } catch (Exception $e) {
235:
236: echo $e->getMessage();
237: }
238: $oDbgVisible->show($mVariable, $sVariableDescription, $bExit);
239: }
240:
241: }
242:
243: 244: 245: 246: 247: 248:
249: class cDebugVisibleAdvItem {
250:
251: 252: 253: 254:
255: private $_mValue;
256:
257: 258: 259: 260:
261: private $_sDescription;
262:
263: 264: 265: 266: 267:
268: public function getValue() {
269: return $this->_mValue;
270: }
271:
272: 273: 274: 275: 276:
277: public function setValue($mValue) {
278: $this->_mValue = $mValue;
279: }
280:
281: 282: 283: 284: 285:
286: public function getDescription() {
287: return $this->_sDescription;
288: }
289:
290: 291: 292: 293: 294:
295: public function setDescription($sDescription) {
296: $this->_sDescription = $sDescription;
297: }
298:
299: }
300: