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
    • 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:     /**
 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
 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
 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 interface.debug::out()
 97:      */
 98:     public function out($sText) {
 99:         $this->_buffer .= $sText . "\n";
100:     }
101: 
102:     /**
103:      * Outputs all Debug items in collection to screen in a HTML Box at left top
104:      * of page.
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:         $tpl = new cTemplate();
134:         $tpl->set("s", "DBG_MESSAGE_CONTENT", $buffer);
135:         $sHtml .= $tpl->generate($cfg["path"]["templates"] . $cfg["templates"]["debug_header"], true);
136: 
137:         echo $sHtml;
138:     }
139: 
140:     /**
141:      * Prepares Debug item value for output as string representation.
142:      *
143:      * @param mixed $mValue
144:      *
145:      * @return string
146:      */
147:     private function _prepareValue($mValue) {
148:         $bTextarea = false;
149:         $bPlainText = false;
150:         $sReturn = '';
151:         if (is_array($mValue)) {
152:             if (sizeof($mValue) > 10) {
153:                 $bTextarea = true;
154:             } else {
155:                 $bPlainText = true;
156:             }
157:         }
158:         if (is_object($mValue)) {
159:             $bTextarea = true;
160:         }
161:         if (is_string($mValue)) {
162:             if (preg_match('/<(.*)>/', $mValue)) {
163:                 if (strlen($mValue) > 40) {
164:                     $bTextarea = true;
165:                 } else {
166:                     $bPlainText = true;
167:                     $mValue = conHtmlSpecialChars($mValue);
168:                 }
169:             } else {
170:                 $bPlainText = true;
171:             }
172:         }
173: 
174:         if ($bTextarea === true) {
175:             $sReturn .= '<textarea rows="14" cols="100">';
176:         } elseif ($bPlainText === true) {
177:             $sReturn .= '<pre>';
178:         } else {
179:             $sReturn .= '<pre>';
180:         }
181: 
182:         if (is_array($mValue)) {
183:             $sReturn .= print_r($mValue, true);
184:         } else {
185:             ob_start();
186:             var_dump($mValue);
187:             $sReturn .= ob_get_contents();
188:             ob_end_clean();
189:         }
190: 
191:         if ($bTextarea === true) {
192:             $sReturn .= '</textarea>';
193:         } elseif ($bPlainText === true) {
194:             $sReturn .= '</pre>';
195:         } else {
196:             $sReturn .= '</pre>';
197:         }
198: 
199:         return $sReturn;
200:     }
201: 
202:     /**
203:      * Implemenation of Countable interface
204:      *
205:      * @return int
206:      */
207:     public function count() {
208:         return sizeof($this->_aItems);
209:     }
210: 
211:     /**
212:      * Outputs contents of passed variable in a preformatted, readable way
213:      *
214:      * @param mixed $mVariable The variable to be displayed
215:      * @param string $sVariableDescription The variable's name or description
216:      * @param boolean $bExit If set to true, your app will die() after output of
217:      *        current var
218:      */
219:     public function show($mVariable, $sVariableDescription = '', $bExit = false) {
220:         try {
221:             $oDbgVisible = cDebug::getDebugger(cDebug::DEBUGGER_VISIBLE);
222:         } catch (Exception $e) {
223:             // throw $e;
224:             echo $e->getMessage();
225:         }
226:         $oDbgVisible->show($mVariable, $sVariableDescription, $bExit);
227:     }
228: }
229: 
230: /**
231:  * An object representing one Debug item of a Debug_VisibleBlock.
232:  *
233:  * @package Core
234:  * @subpackage Debug
235:  */
236: class cDebugVisibleAdvItem {
237: 
238:     /**
239:      *
240:      * @var mixed
241:      */
242:     private $_mValue;
243: 
244:     /**
245:      *
246:      * @var string
247:      */
248:     private $_sDescription;
249: 
250:     /**
251:      * Get value of item
252:      *
253:      * @return mixed
254:      */
255:     public function getValue() {
256:         return $this->_mValue;
257:     }
258: 
259:     /**
260:      * Set value of item
261:      *
262:      * @param mixed $mValue
263:      */
264:     public function setValue($mValue) {
265:         $this->_mValue = $mValue;
266:     }
267: 
268:     /**
269:      * Get name/description of item
270:      *
271:      * @return string
272:      */
273:     public function getDescription() {
274:         return $this->_sDescription;
275:     }
276: 
277:     /**
278:      * Set name/description of item
279:      *
280:      * @param string $sDescription
281:      */
282:     public function setDescription($sDescription) {
283:         $this->_sDescription = $sDescription;
284:     }
285: }
CMS CONTENIDO 4.9.1 API documentation generated by ApiGen 2.8.0