Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cDebug
  • cDebugDevNull
  • cDebugFile
  • cDebugFileAndVisAdv
  • cDebugHidden
  • cDebugVisible
  • cDebugVisibleAdv
  • cDebugVisibleAdvItem

Interfaces

  • cDebugInterface
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * This file contains the visible adv debug class.
  5:  *
  6:  * @package Core
  7:  * @subpackage Debug
  8:  *
  9:  * @author Rudi Bieller
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * Debug object to show info on screen in a box / HTML Block at the top of page.
 20:  * Instead of doing the output immediately using method show, values can be
 21:  * collected and printed to screen in one go.
 22:  * Therefore there's a box positioned at the left top of the page that can be
 23:  * toggled and hidden.
 24:  *
 25:  * Please note:
 26:  * When using method Debug_VisibleAdv::showAll() you'll produce invalid HTML
 27:  * when having an XHTML doctype.
 28:  *
 29:  * @package Core
 30:  * @subpackage Debug
 31:  */
 32: class cDebugVisibleAdv implements cDebugInterface, Countable {
 33: 
 34:     /**
 35:      * Singleton instance
 36:      *
 37:      * @var cDebugVisibleAdv
 38:      */
 39:     private static $_instance;
 40: 
 41:     /**
 42:      *
 43:      * @var array
 44:      */
 45:     private $_aItems;
 46: 
 47:     /**
 48:      *
 49:      * @var string
 50:      */
 51:     private $_buffer;
 52: 
 53:     /**
 54:      * Return singleton instance.
 55:      *
 56:      * @return cDebugVisibleAdv
 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:      * Constructor to create an instance of this class.
 68:      */
 69:     private function __construct() {
 70:         $this->_aItems = array();
 71:     }
 72: 
 73:     /**
 74:      * Add a Debug item to internal collection.
 75:      *
 76:      * @param mixed $mVariable
 77:      * @param string $sVariableDescription [optional]
 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:      * Reset internal collection with Debug items.
 88:      */
 89:     public function reset() {
 90:         $this->_aItems = array();
 91:     }
 92: 
 93:     /**
 94:      * Writes a line.
 95:      *
 96:      * @see cDebugInterface::out()
 97:      * @param string $sText
 98:      */
 99:     public function out($sText) {
100:         $this->_buffer .= $sText . "\n";
101:     }
102: 
103:     /**
104:      * Outputs all Debug items in collection to screen in a HTML Box at left top
105:      * of page.
106:      *
107:      * @throws cInvalidArgumentException
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:         // making sure that the working directory is right
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:         // switching back to the old directory if needed
145:         chdir($dir);
146: 
147:         echo $sHtml;
148:     }
149: 
150:     /**
151:      * Prepares Debug item value for output as string representation.
152:      *
153:      * @param mixed $mValue
154:      *
155:      * @return string
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:      * Implemenation of Countable interface
214:      *
215:      * @return int
216:      */
217:     public function count() {
218:         return sizeof($this->_aItems);
219:     }
220: 
221:     /**
222:      * Outputs contents of passed variable in a preformatted, readable way.
223:      *
224:      * @param mixed $mVariable
225:      *         The variable to be displayed.
226:      * @param string $sVariableDescription [optional]
227:      *         The variable's name or description.
228:      * @param bool $bExit [optional]
229:      *         If set to true, your app will die() after output of current var.
230:      */
231:     public function show($mVariable, $sVariableDescription = '', $bExit = false) {
232:         try {
233:             $oDbgVisible = cDebug::getDebugger(cDebug::DEBUGGER_VISIBLE);
234:         } catch (Exception $e) {
235:             // throw $e;
236:             echo $e->getMessage();
237:         }
238:         $oDbgVisible->show($mVariable, $sVariableDescription, $bExit);
239:     }
240: 
241: }
242: 
243: /**
244:  * An object representing one Debug item of a Debug_VisibleBlock.
245:  *
246:  * @package Core
247:  * @subpackage Debug
248:  */
249: class cDebugVisibleAdvItem {
250: 
251:     /**
252:      *
253:      * @var mixed
254:      */
255:     private $_mValue;
256: 
257:     /**
258:      *
259:      * @var string
260:      */
261:     private $_sDescription;
262: 
263:     /**
264:      * Get value of item
265:      *
266:      * @return mixed
267:      */
268:     public function getValue() {
269:         return $this->_mValue;
270:     }
271: 
272:     /**
273:      * Set value of item
274:      *
275:      * @param mixed $mValue
276:      */
277:     public function setValue($mValue) {
278:         $this->_mValue = $mValue;
279:     }
280: 
281:     /**
282:      * Get name/description of item
283:      *
284:      * @return string
285:      */
286:     public function getDescription() {
287:         return $this->_sDescription;
288:     }
289: 
290:     /**
291:      * Set name/description of item
292:      *
293:      * @param string $sDescription
294:      */
295:     public function setDescription($sDescription) {
296:         $this->_sDescription = $sDescription;
297:     }
298: 
299: }
300: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0