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: public function showAll() {
108: global $cfg;
109:
110: $sHtml = "";
111: if ($this->count() > 0) {
112: $tpl = new cTemplate();
113:
114: $i = 1;
115: foreach ($this->_aItems as $oItem) {
116: $sItemName = strlen($oItem->getDescription()) > 0 ? $oItem->getDescription() : ('debug item #' . $i);
117: $sItemValue = $this->_prepareValue($oItem->getValue());
118:
119: $tpl->set("d", "DBG_ITEM_COUNT", $i);
120: $tpl->set("d", "DBG_ITEM_NAME", $sItemName);
121: $tpl->set("d", "DBG_ITEM_VALUE", $sItemValue);
122: $tpl->next();
123:
124: ++$i;
125: }
126: $sHtml .= $tpl->generate($cfg['path']['contenido'] . $cfg["path"]["templates"] . $cfg['templates']['debug_visibleadv'], true);
127: }
128:
129: $buffer = str_replace("\'", "\\'", $this->_buffer);
130: $buffer = str_replace("\"", "\\\"", $buffer);
131: $buffer = str_replace("\n", '\n', $buffer);
132: $buffer = str_replace(chr(13), "", $buffer);
133:
134:
135: $dir = getcwd();
136: chdir($cfg['path']['contenido']);
137:
138: $tpl = new cTemplate();
139: $tpl->set("s", "DBG_MESSAGE_CONTENT", $buffer);
140: $sHtml .= $tpl->generate($cfg["path"]["templates"] . $cfg["templates"]["debug_header"], true);
141:
142:
143: chdir($dir);
144:
145: echo $sHtml;
146: }
147:
148: 149: 150: 151: 152: 153: 154:
155: private function _prepareValue($mValue) {
156: $bTextarea = false;
157: $bPlainText = false;
158: $sReturn = '';
159: if (is_array($mValue)) {
160: if (sizeof($mValue) > 10) {
161: $bTextarea = true;
162: } else {
163: $bPlainText = true;
164: }
165: }
166: if (is_object($mValue)) {
167: $bTextarea = true;
168: }
169: if (is_string($mValue)) {
170: if (preg_match('/<(.*)>/', $mValue)) {
171: if (strlen($mValue) > 40) {
172: $bTextarea = true;
173: } else {
174: $bPlainText = true;
175: $mValue = conHtmlSpecialChars($mValue);
176: }
177: } else {
178: $bPlainText = true;
179: }
180: }
181:
182: if ($bTextarea === true) {
183: $sReturn .= '<textarea rows="14" cols="100">';
184: } elseif ($bPlainText === true) {
185: $sReturn .= '<pre>';
186: } else {
187: $sReturn .= '<pre>';
188: }
189:
190: if (is_array($mValue)) {
191: $sReturn .= print_r($mValue, true);
192: } else {
193: ob_start();
194: var_dump($mValue);
195: $sReturn .= ob_get_contents();
196: ob_end_clean();
197: }
198:
199: if ($bTextarea === true) {
200: $sReturn .= '</textarea>';
201: } elseif ($bPlainText === true) {
202: $sReturn .= '</pre>';
203: } else {
204: $sReturn .= '</pre>';
205: }
206:
207: return $sReturn;
208: }
209:
210: 211: 212: 213: 214:
215: public function count() {
216: return sizeof($this->_aItems);
217: }
218:
219: 220: 221: 222: 223: 224: 225: 226: 227: 228:
229: public function show($mVariable, $sVariableDescription = '', $bExit = false) {
230: try {
231: $oDbgVisible = cDebug::getDebugger(cDebug::DEBUGGER_VISIBLE);
232: } catch (Exception $e) {
233:
234: echo $e->getMessage();
235: }
236: $oDbgVisible->show($mVariable, $sVariableDescription, $bExit);
237: }
238:
239: }
240:
241: 242: 243: 244: 245: 246:
247: class cDebugVisibleAdvItem {
248:
249: 250: 251: 252:
253: private $_mValue;
254:
255: 256: 257: 258:
259: private $_sDescription;
260:
261: 262: 263: 264: 265:
266: public function getValue() {
267: return $this->_mValue;
268: }
269:
270: 271: 272: 273: 274:
275: public function setValue($mValue) {
276: $this->_mValue = $mValue;
277: }
278:
279: 280: 281: 282: 283:
284: public function getDescription() {
285: return $this->_sDescription;
286: }
287:
288: 289: 290: 291: 292:
293: public function setDescription($sDescription) {
294: $this->_sDescription = $sDescription;
295: }
296:
297: }
298: