PageRenderTime 62ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/administrator/components/com_virtuemart/classes/Log/display.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 221 lines | 105 code | 16 blank | 100 comment | 26 complexity | efa7f57dc7e1b35315341d7aa2a12532 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. *
  5. * @version $Id: display.php 1336 2008-03-31 17:06:23Z soeren_nb $
  6. * @package VirtueMart
  7. * @subpackage Log
  8. * @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  10. * VirtueMart is free software. This version may have been modified pursuant
  11. * to the GNU General Public License, and as distributed it includes or
  12. * is derivative of works licensed under the GNU General Public License or
  13. * other free or open source software licenses.
  14. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  15. *
  16. * http://virtuemart.net
  17. */
  18. /**
  19. * $Header$
  20. *
  21. * @version $ Revision: 1.8 $
  22. * @package Log
  23. */
  24. /**
  25. * The vmLog_display class is a concrete implementation of the Log::
  26. * abstract class which writes message into browser in usual PHP maner.
  27. * This may be useful because when you use PEAR::setErrorHandling in
  28. * PEAR_ERROR_CALLBACK mode error messages are not displayed by
  29. * PHP error handler.
  30. *
  31. * @author Paul Yanchenko <pusher@inaco.ru>
  32. * @since Log 1.8.0
  33. * @package Log
  34. *
  35. * @example display.php Using the display handler.
  36. */
  37. class vmLog_display extends vmLog
  38. {
  39. /**
  40. * String used to represent a line break.
  41. * @var string
  42. * @access private
  43. */
  44. var $_linebreak = "<br />\n";
  45. /**
  46. * Flag to enable or disable buffering.
  47. * @var boolean
  48. * @access private
  49. */
  50. var $_buffering = true;
  51. /**
  52. * Array to store messages when buffering is enabled
  53. *
  54. * @var array
  55. * @access private
  56. */
  57. var $_messages = array();
  58. /**
  59. * Counts messages in the message array
  60. * @var int
  61. */
  62. var $_count = 0;
  63. /**
  64. * Constructs a new vmLog_display object.
  65. *
  66. * @param string $name Ignored.
  67. * @param string $ident The identity string.
  68. * @param array $conf The configuration array.
  69. * @param int $level Log messages up to and including this level.
  70. * @access public
  71. */
  72. function vmLog_display($name = '', $ident = '', $conf = array(),
  73. $level = PEAR_LOG_TIP)
  74. {
  75. $this->_id = md5(microtime());
  76. $this->_ident = $ident;
  77. $this->_mask = vmLog::UPTO($level);
  78. if (isset($conf['linebreak'])) {
  79. $this->_linebreak = $conf['linebreak'];
  80. }
  81. if (isset($conf['buffering'])) {
  82. $this->_buffering = $conf['buffering'];
  83. }
  84. }
  85. /**
  86. * Writes $message to the text browser. Also, passes the message
  87. * along to any Log_observer instances that are observing this Log.
  88. *
  89. * @param mixed $message String or object containing the message to log.
  90. * @param string $priority The priority of the message. Valid
  91. * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  92. * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  93. * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  94. * @return boolean True on success or false on failure.
  95. * @access public
  96. */
  97. function log($message, $priority = null)
  98. {
  99. /* If a priority hasn't been specified, use the default value. */
  100. if ($priority === null) {
  101. $priority = $this->_priority;
  102. }
  103. /* Abort early if the priority is above the maximum logging level. */
  104. if (!$this->_isMasked($priority)) {
  105. return false;
  106. }
  107. /*@MWM1: Limit debugging by IP address, if enabled.*/
  108. if((VM_DEBUG_IP_ENABLED == '1') && (strcmp($_SERVER['REMOTE_ADDR'], VM_DEBUG_IP_ADDRESS) != 0))
  109. {
  110. /* Remote address is NOT our configured debug IP address
  111. (if enabled), so skip logging. */
  112. return false;
  113. }
  114. $this->_ticker++;
  115. if( $priority >= PEAR_LOG_ERR ) {
  116. defined( '_VM_LOG_ERRORS' ) or define( '_VM_LOG_ERRORS', 1);
  117. }
  118. /* Extract the string representation of the message. */
  119. $message = $this->_extractMessage($message);
  120. // Store the log message and its priority
  121. $this->_messages[$this->_count]['priority'] = $priority;
  122. $this->_messages[$this->_count]['message'] = $message;
  123. $this->_count++;
  124. if( !$this->_buffering ) {
  125. $this->printLog();
  126. }
  127. /* Notify observers about this log message. */
  128. $this->_announce(array('priority' => $priority, 'message' => $message));
  129. return true;
  130. }
  131. /**
  132. * Formats a message depending on its priority
  133. *
  134. * @param string $message
  135. * @param int $priority
  136. * @return formatted HTML code
  137. */
  138. function formatOutput( $message, $priority) {
  139. if( $priority >= PEAR_LOG_TIP) {
  140. return '<div class="shop_tip">'. $message . '</div>';
  141. }
  142. elseif( $priority >= PEAR_LOG_DEBUG) {
  143. return '<div class="shop_debug">'. $message . '</div>';
  144. }
  145. elseif( $priority >= PEAR_LOG_INFO) {
  146. return '<div class="shop_info">'. $message . '</div>';
  147. }
  148. elseif( $priority >= PEAR_LOG_WARNING ) {
  149. return '<div class="shop_warning">'. $message . '</div>';
  150. }
  151. elseif( $priority >= PEAR_LOG_ERR ) {
  152. return '<div class="shop_error">'. $message . '</div>';
  153. }
  154. elseif( $priority >= PEAR_LOG_CRIT ) {
  155. return '<div class="shop_critical">'. $message . '</div>';
  156. }
  157. }
  158. /**
  159. * Override function for printLog
  160. *
  161. * @param int $priority
  162. */
  163. function flush($priority=null) {
  164. $this->printLog($priority);
  165. }
  166. /**
  167. * Flush the _messages array and print all messages
  168. * @author Soeren Eberhardt
  169. */
  170. function printLog( $priority = null ) {
  171. if( $this->_count == 0 ) {
  172. return;
  173. }
  174. $output = '';
  175. $has_output = false;
  176. $i = 0;
  177. $message_tmp = '';
  178. foreach( $this->_messages as $message ) {
  179. if( ( $priority === null || $priority <= $message['priority'] )
  180. && $message['priority'] !== PEAR_LOG_DEBUG
  181. || ( $message['priority'] === PEAR_LOG_DEBUG && DEBUG == '1')) {
  182. $has_output= true;
  183. $message_tmp .= '<b>' . ucfirst($this->priorityToString($message['priority'])) . '</b>: '
  184. . nl2br(htmlspecialchars($message['message']))
  185. . $this->_linebreak;
  186. if( @$this->_messages[$i+1]['priority'] != $message['priority'] ) {
  187. $output .= $this->formatOutput( $message_tmp, $message['priority'] );
  188. $message_tmp = '';
  189. }
  190. }
  191. $i++;
  192. }
  193. $html = '<div ';
  194. if( $this->_count > 10 && DEBUG) {
  195. // Wrap the messages into a scrollable div field
  196. $html .= 'style="width:90%; overflow:auto; height:150px;"';
  197. }
  198. $html .= '>'. $output . '</div>';
  199. $this->_count = 0;
  200. $this->_messages = array();
  201. if( $output ) {
  202. echo $html;// . $this->_linebreak;
  203. }
  204. }
  205. }