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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • 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: /**
  4:  * This file contains the visible adv debug class.
  5:  *
  6:  * @package Core
  7:  * @subpackage Debug
  8:  * @version SVN Revision $Rev:$
  9:  *
 10:  * @author Rudi Bieller
 11:  * @copyright four for business AG <www.4fb.de>
 12:  * @license http://www.contenido.org/license/LIZENZ.txt
 13:  * @link http://www.4fb.de
 14:  * @link http://www.contenido.org
 15:  */
 16: 
 17: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 18: 
 19: /**
 20:  * Debug object to show info on screen in a box / HTML Block at the top of page.
 21:  * Instead of doing the output immediately using method show, values can be
 22:  * collected and printed to screen in one go.
 23:  * Therefore there's a box positioned at the left top of the page that can be
 24:  * toggled and hidden.
 25:  *
 26:  * Please note:
 27:  * When using method Debug_VisibleAdv::showAll() you'll produce invalid HTML
 28:  * when having an XHTML doctype.
 29:  *
 30:  * @package Core
 31:  * @subpackage Debug
 32:  */
 33: class cDebugVisibleAdv implements cDebugInterface, Countable {
 34: 
 35:     /**
 36:      * Singleton instance
 37:      *
 38:      * @var cDebugVisibleAdv
 39:      */
 40:     private static $_instance;
 41: 
 42:     /**
 43:      *
 44:      * @var array
 45:      */
 46:     private $_aItems;
 47: 
 48:     /**
 49:      *
 50:      * @var string
 51:      */
 52:     private $_buffer;
 53: 
 54:     /**
 55:      * Return singleton instance.
 56:      *
 57:      * @return cDebugVisibleAdv
 58:      */
 59:     public static function getInstance() {
 60:         if (self::$_instance == NULL) {
 61:             self::$_instance = new cDebugVisibleAdv();
 62:         }
 63: 
 64:         return self::$_instance;
 65:     }
 66: 
 67:     /**
 68:      * Constructor
 69:      */
 70:     private function __construct() {
 71:         $this->_aItems = array();
 72:     }
 73: 
 74:     /**
 75:      * Add a Debug item to internal collection.
 76:      *
 77:      * @param mixed $mVariable
 78:      * @param string $sVariableDescription [optional]
 79:      */
 80:     public function add($mVariable, $sVariableDescription = '') {
 81:         $oItem = new cDebugVisibleAdvItem();
 82:         $oItem->setValue($mVariable);
 83:         $oItem->setDescription($sVariableDescription);
 84:         $this->_aItems[] = $oItem;
 85:     }
 86: 
 87:     /**
 88:      * Reset internal collection with Debug items.
 89:      */
 90:     public function reset() {
 91:         $this->_aItems = array();
 92:     }
 93: 
 94:     /**
 95:      * Writes a line.
 96:      *
 97:      * @see cDebugInterface::out()
 98:      * @param string $sText
 99:      */
100:     public function out($sText) {
101:         $this->_buffer .= $sText . "\n";
102:     }
103: 
104:     /**
105:      * Outputs all Debug items in collection to screen in a HTML Box at left top
106:      * of page.
107:      */
108:     public function showAll() {
109:         global $cfg;
110: 
111:         $sHtml = "";
112:         if ($this->count() > 0) {
113:             $tpl = new cTemplate();
114: 
115:             $i = 1;
116:             foreach ($this->_aItems as $oItem) {
117:                 $sItemName = strlen($oItem->getDescription()) > 0 ? $oItem->getDescription() : ('debug item #' . $i);
118:                 $sItemValue = $this->_prepareValue($oItem->getValue());
119: 
120:                 $tpl->set("d", "DBG_ITEM_COUNT", $i);
121:                 $tpl->set("d", "DBG_ITEM_NAME", $sItemName);
122:                 $tpl->set("d", "DBG_ITEM_VALUE", $sItemValue);
123:                 $tpl->next();
124: 
125:                 ++$i;
126:             }
127:             $sHtml .= $tpl->generate($cfg['path']['contenido'] . $cfg["path"]["templates"] . $cfg['templates']['debug_visibleadv'], true);
128:         }
129: 
130:         $buffer = str_replace("\'", "\\'", $this->_buffer);
131:         $buffer = str_replace("\"", "\\\"", $buffer);
132:         $buffer = str_replace("\n", '\n', $buffer);
133:         $buffer = str_replace(chr(13), "", $buffer);
134: 
135:         // making sure that the working directory is right
136:         $dir = getcwd();
137:         chdir($cfg['path']['contenido']);
138: 
139:         $tpl = new cTemplate();
140:         $tpl->set("s", "DBG_MESSAGE_CONTENT", $buffer);
141:         $sHtml .= $tpl->generate($cfg["path"]["templates"] . $cfg["templates"]["debug_header"], true);
142: 
143:         // switching back to the old directory if needed
144:         chdir($dir);
145: 
146:         echo $sHtml;
147:     }
148: 
149:     /**
150:      * Prepares Debug item value for output as string representation.
151:      *
152:      * @param mixed $mValue
153:      *
154:      * @return string
155:      */
156:     private function _prepareValue($mValue) {
157:         $bTextarea = false;
158:         $bPlainText = false;
159:         $sReturn = '';
160:         if (is_array($mValue)) {
161:             if (sizeof($mValue) > 10) {
162:                 $bTextarea = true;
163:             } else {
164:                 $bPlainText = true;
165:             }
166:         }
167:         if (is_object($mValue)) {
168:             $bTextarea = true;
169:         }
170:         if (is_string($mValue)) {
171:             if (preg_match('/<(.*)>/', $mValue)) {
172:                 if (strlen($mValue) > 40) {
173:                     $bTextarea = true;
174:                 } else {
175:                     $bPlainText = true;
176:                     $mValue = conHtmlSpecialChars($mValue);
177:                 }
178:             } else {
179:                 $bPlainText = true;
180:             }
181:         }
182: 
183:         if ($bTextarea === true) {
184:             $sReturn .= '<textarea rows="14" cols="100">';
185:         } elseif ($bPlainText === true) {
186:             $sReturn .= '<pre>';
187:         } else {
188:             $sReturn .= '<pre>';
189:         }
190: 
191:         if (is_array($mValue)) {
192:             $sReturn .= print_r($mValue, true);
193:         } else {
194:             ob_start();
195:             var_dump($mValue);
196:             $sReturn .= ob_get_contents();
197:             ob_end_clean();
198:         }
199: 
200:         if ($bTextarea === true) {
201:             $sReturn .= '</textarea>';
202:         } elseif ($bPlainText === true) {
203:             $sReturn .= '</pre>';
204:         } else {
205:             $sReturn .= '</pre>';
206:         }
207: 
208:         return $sReturn;
209:     }
210: 
211:     /**
212:      * Implemenation of Countable interface
213:      *
214:      * @return int
215:      */
216:     public function count() {
217:         return sizeof($this->_aItems);
218:     }
219: 
220:     /**
221:      * Outputs contents of passed variable in a preformatted, readable way.
222:      *
223:      * @param mixed $mVariable
224:      *         The variable to be displayed.
225:      * @param string $sVariableDescription [optional]
226:      *         The variable's name or description.
227:      * @param bool $bExit [optional]
228:      *         If set to true, your app will die() after output of current var.
229:      */
230:     public function show($mVariable, $sVariableDescription = '', $bExit = false) {
231:         try {
232:             $oDbgVisible = cDebug::getDebugger(cDebug::DEBUGGER_VISIBLE);
233:         } catch (Exception $e) {
234:             // throw $e;
235:             echo $e->getMessage();
236:         }
237:         $oDbgVisible->show($mVariable, $sVariableDescription, $bExit);
238:     }
239: 
240: }
241: 
242: /**
243:  * An object representing one Debug item of a Debug_VisibleBlock.
244:  *
245:  * @package Core
246:  * @subpackage Debug
247:  */
248: class cDebugVisibleAdvItem {
249: 
250:     /**
251:      *
252:      * @var mixed
253:      */
254:     private $_mValue;
255: 
256:     /**
257:      *
258:      * @var string
259:      */
260:     private $_sDescription;
261: 
262:     /**
263:      * Get value of item
264:      *
265:      * @return mixed
266:      */
267:     public function getValue() {
268:         return $this->_mValue;
269:     }
270: 
271:     /**
272:      * Set value of item
273:      *
274:      * @param mixed $mValue
275:      */
276:     public function setValue($mValue) {
277:         $this->_mValue = $mValue;
278:     }
279: 
280:     /**
281:      * Get name/description of item
282:      *
283:      * @return string
284:      */
285:     public function getDescription() {
286:         return $this->_sDescription;
287:     }
288: 
289:     /**
290:      * Set name/description of item
291:      *
292:      * @param string $sDescription
293:      */
294:     public function setDescription($sDescription) {
295:         $this->_sDescription = $sDescription;
296:     }
297: 
298: }
299: 
CMS CONTENIDO 4.9.8 API documentation generated by ApiGen 2.8.0