PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/www/wp-content/plugins/ithemes-exchange/lib/classes/it-error.php

https://github.com/ArzuA/gitwordpress
PHP | 197 lines | 127 code | 45 blank | 25 comment | 16 complexity | 8403dc25e75338a2d49338da9af76693 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. Written by Chris Jean for iThemes.com
  4. Version 2.0.4
  5. Version History
  6. 2.0.0 - 2012-07-05 - Chris Jean
  7. Significant rewrite.
  8. Moved some functionality to files in the it-error directory.
  9. Made error reporting much more robust.
  10. Error message reporting now is conditional on either:
  11. The user is logged in
  12. The request has a non-empty GET variable named it_classes_show_errors
  13. The IT_CLASSES_SHOW_ERRORS define is set and is truthy
  14. 2.0.1 - 2012-07-06 - Chris Jean
  15. Added support for IT_CLASSES_EXPAND_ERRORS define. When truthy, it shows the error box expanded by default
  16. Added support for IT_CLASSES_DISABLE_ERRORS. When truthy, it disables the error handler comletely
  17. 2.0.2 - 2013-05-21 - Chris Jean
  18. Removed assign by reference.
  19. 2.0.3 - 2013-06-25 - Chris Jean
  20. Changed function declarations to "public static".
  21. 2.0.4 - 2013-11-25 - Chris Jean
  22. Fixed the improper adding of "public static" in front of the Javascript functions.
  23. */
  24. if ( ! class_exists( 'ITError' ) ) {
  25. class ITError {
  26. public static function fatal( $code, $message ) {
  27. ob_start();
  28. ?>
  29. <table style="font-size:12px;padding:0;margin:0;">
  30. <tr><td style="font-weight:bold;">Error Code:</td>
  31. <td><?php echo $code; ?></td>
  32. </tr>
  33. <tr><td style="font-weight:bold;">Message:</td>
  34. <td><?php echo $message; ?></td>
  35. </tr>
  36. </table>
  37. <br />
  38. <?php
  39. ITError::show_fatal_error_message( ob_get_clean() );
  40. }
  41. public static function show_fatal_error_message( $message ) {
  42. $message_toggle = ( defined( 'IT_CLASSES_EXPAND_ERRORS' ) && IT_CLASSES_EXPAND_ERRORS ) ? 'hide details' : 'show details';
  43. $message_display_style = ( defined( 'IT_CLASSES_EXPAND_ERRORS' ) && IT_CLASSES_EXPAND_ERRORS ) ? 'block' : 'none';
  44. ?>
  45. <div id="it-fatal-error-message-container" style="background:white;border:3px double red;padding:10px;margin:10px;position:absolute;top:0;left:0;z-index:100000;max-width:780px">
  46. <style scoped>
  47. h1, h2, table, div, pre, code { color: black; line-height: 1.3; font-size: 13px; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; margin: 0; padding: 0; text-shadow: none; }
  48. h1 { color: red; font-weight: bold; font-size: 20px; margin-right: 10px; display: inline; }
  49. h2 { margin: 2em 0 1em; }
  50. a { color: blue; text-decoration: underline; }
  51. p { margin: 1em 0; }
  52. code, pre { font-family: monospace; white-space: normal; }
  53. code { margin: 0 5px; padding: 0 5px; background: #EEE; }
  54. table { border-collapse: collapse; margin: 0 0 0 25px; }
  55. table, tr, th, td { background: none !important; }
  56. table code { margin: 0; padding: 0; background: none; }
  57. th, td { border: 1px solid #CCC; padding: 5px; text-align: left; vertical-align: top; }
  58. ul { margin: 0; padding: 0 0 0 25px; }
  59. li { padding: 5px 0; margin: 0; list-style-type: circle; }
  60. #it-fatal-error-message :last-child { margin-bottom: 0; }
  61. </style>
  62. <div>
  63. <h1>Fatal Error</h1>
  64. <span id="it-fatal-error-message-links" style="display:none;">
  65. (<a id="it-fatal-error-message-toggle-link" href="javascript:it_fatal_error_toggle_message()"><?php echo $message_toggle; ?></a>)
  66. (<a href="javascript:it_fatal_error_remove_message()">remove</a>)
  67. </span>
  68. </div>
  69. <div id="it-fatal-error-message">
  70. <p>The site encountered a problem that it cannot recover from. Please use the following information to try to resolve the problem.</p>
  71. <?php echo $message; ?>
  72. <br />
  73. <p>Note that this message is generated by iThemes.com products when an error is encountered on the site. While an iThemes product is generating this message, it is not necessarily the cause of the problem.</p>
  74. </div>
  75. </div>
  76. <script>
  77. document.getElementById('it-fatal-error-message').style.display = '<?php echo $message_display_style; ?>';
  78. document.getElementById('it-fatal-error-message-links').style.display = 'inline';
  79. function it_fatal_error_toggle_message() {
  80. var container = document.getElementById('it-fatal-error-message');
  81. var link = document.getElementById('it-fatal-error-message-toggle-link');
  82. if('block' === container.style.display) {
  83. container.style.display = 'none';
  84. link.innerHTML = 'show details';
  85. }
  86. else {
  87. container.style.display = 'block';
  88. link.innerHTML = 'hide details';
  89. }
  90. }
  91. function it_fatal_error_remove_message() {
  92. document.getElementById('it-fatal-error-message-container').style.display = 'none';
  93. }
  94. </script>
  95. <?php
  96. exit;
  97. }
  98. public static function admin_warn( $code, $message, $capability = 'switch_themes' ) {
  99. if ( current_user_can( $capability ) || ! empty( $_GET['show_it_error_messages'] ) )
  100. ITUtility::show_error_message( $message );
  101. }
  102. public static function warn( $code, $message ) {
  103. ITUtility::show_error_message( $message );
  104. }
  105. public static function developer_warn( $message, $show_backtrace = true ) {
  106. if ( ! WP_DEBUG )
  107. return;
  108. it_classes_load( 'it-debug.php' );
  109. $backtrace = ITDebug::get_backtrace( array( 'offset' => 2, 'remove_abspath' => false ) );
  110. echo "<pre style='color:black;background:white;padding:15px;font-family:\"Courier New\",Courier,monospace;font-size:12px;text-align:left;max-width:100%;'>";
  111. echo "<strong>Developer Notice</strong>\n";
  112. echo " $message\n\n";
  113. echo "<strong>Stack Backtrace</strong>\n";
  114. foreach ( $backtrace as $trace )
  115. echo ' ' . ITDebug::get_backtrace_description( $trace ) . "\n";
  116. echo "</pre>\n";
  117. }
  118. public static function log( $code, $message, $type = 'warning' ) {
  119. it_classes_load( 'it-storage.php' );
  120. if ( ! preg_match( '/^(warning|error|fatal)$/', $type ) )
  121. $type = 'warning';
  122. $store = new ITStorage2( 'it-error', array( 'version' => '1.0.0', 'autoload' => 'no' ) );
  123. $data = $store->load();
  124. $log = ITError::get_debug_data( $code );
  125. $log['message'] = $message;
  126. $data[] = $log;
  127. $store->save( $data );
  128. }
  129. public static function get_debug_data( $code ) {
  130. $data = array();
  131. // Implement this at some time... Add info about timestamp, theme, files, permissions, debug_backtrace, etc
  132. return $data;
  133. }
  134. public static function upgrade_storage( $data ) {
  135. if ( version_compare( $data['storage_version'], '1.0.0', '<' ) )
  136. $data = ITError::_upgrade_storage_1_0_0( $data );
  137. return $data;
  138. }
  139. public static function _upgrade_storage_1_0_0( $data ) {
  140. $store = new ITStorage( 'ITError', true );
  141. $data = $store->load( false );
  142. $store->remove();
  143. $data['storage_version'] = '1.0.0';
  144. return $data;
  145. }
  146. }
  147. add_filter( 'it_storage_upgrade_it-error', array( 'ITError', 'upgrade_storage' ) );
  148. if ( ( is_user_logged_in() || ! empty( $_GET['it_classes_show_errors'] ) || ( defined( 'IT_CLASSES_SHOW_ERRORS' ) && IT_CLASSES_SHOW_ERRORS ) ) && ( ! defined( 'IT_CLASSES_DISABLE_ERRORS' ) || ! IT_CLASSES_DISABLE_ERRORS ) ) {
  149. require_once( dirname( __FILE__ ) . '/it-error/class-it-classes-fatal-error-handler.php' );
  150. }
  151. }