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:  *
  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:     public function showAll() {
108:         global $cfg;
109: 
110:         $sHtml = "";
111:         if ($this->count() > 0) {
112:             $tpl = new cTemplate();
113: 
114:             $i = 1;
115:             foreach ($this->_aItems as $oItem) {
116:                 $sItemName = strlen($oItem->getDescription()) > 0 ? $oItem->getDescription() : ('debug item #' . $i);
117:                 $sItemValue = $this->_prepareValue($oItem->getValue());
118: 
119:                 $tpl->set("d", "DBG_ITEM_COUNT", $i);
120:                 $tpl->set("d", "DBG_ITEM_NAME", $sItemName);
121:                 $tpl->set("d", "DBG_ITEM_VALUE", $sItemValue);
122:                 $tpl->next();
123: 
124:                 ++$i;
125:             }
126:             $sHtml .= $tpl->generate($cfg['path']['contenido'] . $cfg["path"]["templates"] . $cfg['templates']['debug_visibleadv'], true);
127:         }
128: 
129:         $buffer = str_replace("\'", "\\'", $this->_buffer);
130:         $buffer = str_replace("\"", "\\\"", $buffer);
131:         $buffer = str_replace("\n", '\n', $buffer);
132:         $buffer = str_replace(chr(13), "", $buffer);
133: 
134:         // making sure that the working directory is right
135:         $dir = getcwd();
136:         chdir($cfg['path']['contenido']);
137: 
138:         $tpl = new cTemplate();
139:         $tpl->set("s", "DBG_MESSAGE_CONTENT", $buffer);
140:         $sHtml .= $tpl->generate($cfg["path"]["templates"] . $cfg["templates"]["debug_header"], true);
141: 
142:         // switching back to the old directory if needed
143:         chdir($dir);
144: 
145:         echo $sHtml;
146:     }
147: 
148:     /**
149:      * Prepares Debug item value for output as string representation.
150:      *
151:      * @param mixed $mValue
152:      *
153:      * @return string
154:      */
155:     private function _prepareValue($mValue) {
156:         $bTextarea = false;
157:         $bPlainText = false;
158:         $sReturn = '';
159:         if (is_array($mValue)) {
160:             if (sizeof($mValue) > 10) {
161:                 $bTextarea = true;
162:             } else {
163:                 $bPlainText = true;
164:             }
165:         }
166:         if (is_object($mValue)) {
167:             $bTextarea = true;
168:         }
169:         if (is_string($mValue)) {
170:             if (preg_match('/<(.*)>/', $mValue)) {
171:                 if (strlen($mValue) > 40) {
172:                     $bTextarea = true;
173:                 } else {
174:                     $bPlainText = true;
175:                     $mValue = conHtmlSpecialChars($mValue);
176:                 }
177:             } else {
178:                 $bPlainText = true;
179:             }
180:         }
181: 
182:         if ($bTextarea === true) {
183:             $sReturn .= '<textarea rows="14" cols="100">';
184:         } elseif ($bPlainText === true) {
185:             $sReturn .= '<pre>';
186:         } else {
187:             $sReturn .= '<pre>';
188:         }
189: 
190:         if (is_array($mValue)) {
191:             $sReturn .= print_r($mValue, true);
192:         } else {
193:             ob_start();
194:             var_dump($mValue);
195:             $sReturn .= ob_get_contents();
196:             ob_end_clean();
197:         }
198: 
199:         if ($bTextarea === true) {
200:             $sReturn .= '</textarea>';
201:         } elseif ($bPlainText === true) {
202:             $sReturn .= '</pre>';
203:         } else {
204:             $sReturn .= '</pre>';
205:         }
206: 
207:         return $sReturn;
208:     }
209: 
210:     /**
211:      * Implemenation of Countable interface
212:      *
213:      * @return int
214:      */
215:     public function count() {
216:         return sizeof($this->_aItems);
217:     }
218: 
219:     /**
220:      * Outputs contents of passed variable in a preformatted, readable way.
221:      *
222:      * @param mixed $mVariable
223:      *         The variable to be displayed.
224:      * @param string $sVariableDescription [optional]
225:      *         The variable's name or description.
226:      * @param bool $bExit [optional]
227:      *         If set to true, your app will die() after output of current var.
228:      */
229:     public function show($mVariable, $sVariableDescription = '', $bExit = false) {
230:         try {
231:             $oDbgVisible = cDebug::getDebugger(cDebug::DEBUGGER_VISIBLE);
232:         } catch (Exception $e) {
233:             // throw $e;
234:             echo $e->getMessage();
235:         }
236:         $oDbgVisible->show($mVariable, $sVariableDescription, $bExit);
237:     }
238: 
239: }
240: 
241: /**
242:  * An object representing one Debug item of a Debug_VisibleBlock.
243:  *
244:  * @package Core
245:  * @subpackage Debug
246:  */
247: class cDebugVisibleAdvItem {
248: 
249:     /**
250:      *
251:      * @var mixed
252:      */
253:     private $_mValue;
254: 
255:     /**
256:      *
257:      * @var string
258:      */
259:     private $_sDescription;
260: 
261:     /**
262:      * Get value of item
263:      *
264:      * @return mixed
265:      */
266:     public function getValue() {
267:         return $this->_mValue;
268:     }
269: 
270:     /**
271:      * Set value of item
272:      *
273:      * @param mixed $mValue
274:      */
275:     public function setValue($mValue) {
276:         $this->_mValue = $mValue;
277:     }
278: 
279:     /**
280:      * Get name/description of item
281:      *
282:      * @return string
283:      */
284:     public function getDescription() {
285:         return $this->_sDescription;
286:     }
287: 
288:     /**
289:      * Set name/description of item
290:      *
291:      * @param string $sDescription
292:      */
293:     public function setDescription($sDescription) {
294:         $this->_sDescription = $sDescription;
295:     }
296: 
297: }
298: 
CMS CONTENIDO 4.9.11 API documentation generated by ApiGen 2.8.0