Overview

Packages

  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Datatype
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationMain
    • NavigationTop
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • 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:  * This file contains the visible adv debug class.
  4:  *
  5:  * @package    Core
  6:  * @subpackage Debug
  7:  * @version    SVN Revision $Rev:$
  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:     private static $_instance;
 35: 
 36:     private $_aItems;
 37: 
 38:     private $_buffer;
 39: 
 40:     /**
 41:      * Constructor
 42:      */
 43:     private function __construct() {
 44:         $this->_aItems = array();
 45:     }
 46: 
 47:     /**
 48:      * static
 49:      */
 50:     static public function getInstance() {
 51:         if (self::$_instance == NULL) {
 52:             self::$_instance = new cDebugVisibleAdv();
 53:         }
 54: 
 55:         return self::$_instance;
 56:     }
 57: 
 58:     /**
 59:      * Add a Debug item to internal collection.
 60:      *
 61:      * @param mixed  $mVariable
 62:      * @param string $sVariableDescription
 63:      */
 64:     public function add($mVariable, $sVariableDescription = '') {
 65:         $oItem = new cDebugVisibleAdvItem();
 66:         $oItem->setValue($mVariable);
 67:         $oItem->setDescription($sVariableDescription);
 68:         $this->_aItems[] = $oItem;
 69:     }
 70: 
 71:     /**
 72:      * Reset internal collection with Debug items.
 73:      */
 74:     public function reset() {
 75:         $this->_aItems = array();
 76:     }
 77: 
 78:     /**
 79:      * Writes a line
 80:      *
 81:      * @see interface.debug::out()
 82:      */
 83:     public function out($sText) {
 84:         $this->_buffer .= $sText . "\n";
 85:     }
 86: 
 87:     /**
 88:      * Outputs all Debug items in collection to screen in a HTML Box at left top
 89:      * of page.
 90:      */
 91:     public function showAll() {
 92:         global $cfg;
 93: 
 94:         $sHtml = "";
 95:         if ($this->count() > 0) {
 96:             $tpl = new cTemplate();
 97: 
 98:             $i = 1;
 99:             foreach ($this->_aItems as $oItem) {
100:                 $sItemName = strlen($oItem->getDescription()) > 0 ? $oItem->getDescription() : ('debug item #' . $i);
101:                 $sItemValue = $this->_prepareValue($oItem->getValue());
102: 
103:                 $tpl->set("d", "DBG_ITEM_COUNT", $i);
104:                 $tpl->set("d", "DBG_ITEM_NAME", $sItemName);
105:                 $tpl->set("d", "DBG_ITEM_VALUE", $sItemValue);
106:                 $tpl->next();
107: 
108:                 ++$i;
109:             }
110:             $sHtml .= $tpl->generate($cfg["path"]["templates"] . $cfg["template"]["debug_visibleadv"], true);
111:         }
112: 
113:         $buffer = str_replace("\'", "\\'", $this->_buffer);
114:         $buffer = str_replace("\"", "\\\"", $buffer);
115:         $buffer = str_replace("\n", '\n', $buffer);
116:         $buffer = str_replace(chr(13), "", $buffer);
117: 
118:         $tpl = new cTemplate();
119:         $tpl->set("s", "DBG_MESSAGE_CONTENT", $buffer);
120:         $sHtml .= $tpl->generate($cfg["path"]["templates"] . $cfg["templates"]["debug_header"], true);
121: 
122:         echo $sHtml;
123:     }
124: 
125:     /**
126:      * Prepares Debug item value for output as string representation.
127:      *
128:      * @param mixed $mValue
129:      *
130:      * @return string
131:      */
132:     private function _prepareValue($mValue) {
133:         $bTextarea = false;
134:         $bPlainText = false;
135:         $sReturn = '';
136:         if (is_array($mValue)) {
137:             if (sizeof($mValue) > 10) {
138:                 $bTextarea = true;
139:             } else {
140:                 $bPlainText = true;
141:             }
142:         }
143:         if (is_object($mValue)) {
144:             $bTextarea = true;
145:         }
146:         if (is_string($mValue)) {
147:             if (preg_match('/<(.*)>/', $mValue)) {
148:                 if (strlen($mValue) > 40) {
149:                     $bTextarea = true;
150:                 } else {
151:                     $bPlainText = true;
152:                     $mValue = conHtmlSpecialChars($mValue);
153:                 }
154:             } else {
155:                 $bPlainText = true;
156:             }
157:         }
158: 
159:         if ($bTextarea === true) {
160:             $sReturn .= '<textarea rows="14" cols="100">';
161:         } elseif ($bPlainText === true) {
162:             $sReturn .= '<pre>';
163:         } else {
164:             $sReturn .= '<pre>';
165:         }
166: 
167:         if (is_array($mValue)) {
168:             $sReturn .= print_r($mValue, true);
169:         } else {
170:             ob_start();
171:             var_dump($mValue);
172:             $sReturn .= ob_get_contents();
173:             ob_end_clean();
174:         }
175: 
176:         if ($bTextarea === true) {
177:             $sReturn .= '</textarea>';
178:         } elseif ($bPlainText === true) {
179:             $sReturn .= '</pre>';
180:         } else {
181:             $sReturn .= '</pre>';
182:         }
183: 
184:         return $sReturn;
185:     }
186: 
187:     /**
188:      * Implemenation of Countable interface
189:      *
190:      * @return int
191:      */
192:     public function count() {
193:         return sizeof($this->_aItems);
194:     }
195: 
196:     /**
197:      * Outputs contents of passed variable in a preformatted, readable way
198:      *
199:      * @param mixed   $mVariable            The variable to be displayed
200:      * @param string  $sVariableDescription The variable's name or description
201:      * @param boolean $bExit                If set to true, your app will die() after output of
202:      *                                      current var
203:      */
204:     public function show($mVariable, $sVariableDescription = '', $bExit = false) {
205:         try {
206:             $oDbgVisible = cDebug::getDebugger(cDebug::DEBUGGER_VISIBLE);
207:         } catch (Exception $e) {
208:             // throw $e;
209:             echo $e->getMessage();
210:         }
211:         $oDbgVisible->show($mVariable, $sVariableDescription, $bExit);
212:     }
213: 
214: }
215: 
216: /**
217:  * An object representing one Debug item of a Debug_VisibleBlock.
218:  * @package    Core
219:  * @subpackage Debug
220:  */
221: class cDebugVisibleAdvItem {
222: 
223:     private $_mValue;
224: 
225:     private $_sDescription;
226: 
227:     /**
228:      * Set value of item
229:      */
230:     public function setValue($mValue) {
231:         $this->_mValue = $mValue;
232:     }
233: 
234:     /**
235:      * Set name/description of item
236:      */
237:     public function setDescription($sDescription) {
238:         $this->_sDescription = $sDescription;
239:     }
240: 
241:     /**
242:      * Get value of item
243:      *
244:      * @return mixed
245:      */
246:     public function getValue() {
247:         return $this->_mValue;
248:     }
249: 
250:     /**
251:      * Get name/description of item
252:      *
253:      * @return string
254:      */
255:     public function getDescription() {
256:         return $this->_sDescription;
257:     }
258: }
CMS CONTENIDO 4.9.0 API documentation generated by ApiGen 2.8.0