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:         // making sure that the working directory is right
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:         // switching back to the old directory if needed
142:         chdir($dir);
143: 
144:         echo $sHtml;
145:     }
146: 
147:     /**
148:      * Prepares Debug item value for output as string representation.
149:      *
150:      * @param mixed $mValue
151:      *
152:      * @return string
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:      * Implemenation of Countable interface
211:      *
212:      * @return int
213:      */
214:     public function count() {
215:         return sizeof($this->_aItems);
216:     }
217: 
218:     /**
219:      * Outputs contents of passed variable in a preformatted, readable way
220:      *
221:      * @param mixed $mVariable The variable to be displayed
222:      * @param string $sVariableDescription The variable's name or description
223:      * @param bool $bExit If set to true, your app will die() after output of
224:      *        current var
225:      */
226:     public function show($mVariable, $sVariableDescription = '', $bExit = false) {
227:         try {
228:             $oDbgVisible = cDebug::getDebugger(cDebug::DEBUGGER_VISIBLE);
229:         } catch (Exception $e) {
230:             // throw $e;
231:             echo $e->getMessage();
232:         }
233:         $oDbgVisible->show($mVariable, $sVariableDescription, $bExit);
234:     }
235: 
236: }
237: 
238: /**
239:  * An object representing one Debug item of a Debug_VisibleBlock.
240:  *
241:  * @package Core
242:  * @subpackage Debug
243:  */
244: class cDebugVisibleAdvItem {
245: 
246:     /**
247:      *
248:      * @var mixed
249:      */
250:     private $_mValue;
251: 
252:     /**
253:      *
254:      * @var string
255:      */
256:     private $_sDescription;
257: 
258:     /**
259:      * Get value of item
260:      *
261:      * @return mixed
262:      */
263:     public function getValue() {
264:         return $this->_mValue;
265:     }
266: 
267:     /**
268:      * Set value of item
269:      *
270:      * @param mixed $mValue
271:      */
272:     public function setValue($mValue) {
273:         $this->_mValue = $mValue;
274:     }
275: 
276:     /**
277:      * Get name/description of item
278:      *
279:      * @return string
280:      */
281:     public function getDescription() {
282:         return $this->_sDescription;
283:     }
284: 
285:     /**
286:      * Set name/description of item
287:      *
288:      * @param string $sDescription
289:      */
290:     public function setDescription($sDescription) {
291:         $this->_sDescription = $sDescription;
292:     }
293: 
294: }
CMS CONTENIDO 4.9.5 API documentation generated by ApiGen 2.8.0