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