| @@ -13,852 +13,824 @@ | ||
| 13 | 13 | * Class MainWP_Logger |
| 14 | 14 | * |
| 15 | 15 | * @package MainWP\Dashboard |
| 16 | 16 | */ |
| 17 | -class MainWP_Logger { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. | |
| 17 | +class MainWP_Logger { | |
| 18 | 18 | |
| 19 | - // phpcs:disable WordPress.WP.AlternativeFunctions -- for custom read/write logging file. | |
| 19 | + // phpcs:disable WordPress.WP.AlternativeFunctions -- for custom read/write logging file. | |
| 20 | 20 | |
| 21 | - const UPDATE_CHECK_LOG_PRIORITY = 10; | |
| 22 | - const EXECUTION_TIME_LOG_PRIORITY = 15; | |
| 23 | - const LOGS_AUTO_PURGE_LOG_PRIORITY = 16; | |
| 24 | - const COST_TRACKER_LOG_PRIORITY = 20230112; | |
| 25 | - const API_BACKUPS_LOG_PRIORITY = 20240130; | |
| 21 | + const UPDATE_CHECK_LOG_PRIORITY = 10; | |
| 22 | + const EXECUTION_TIME_LOG_PRIORITY = 15; | |
| 26 | 23 | |
| 27 | - const DISABLED = - 1; | |
| 28 | - const LOG = 0; | |
| 29 | - const WARNING = 1; | |
| 30 | - const INFO = 2; | |
| 31 | - const DEBUG = 3; | |
| 32 | 24 | |
| 33 | - const LOG_COLOR = '#999999'; | |
| 34 | - const DEBUG_COLOR = '#666666'; | |
| 35 | - const INFO_COLOR = '#276f86'; | |
| 36 | - const WARNING_COLOR = '#9f3a38;'; | |
| 25 | + const DISABLED = - 1; | |
| 26 | + const LOG = 0; | |
| 27 | + const WARNING = 1; | |
| 28 | + const INFO = 2; | |
| 29 | + const DEBUG = 3; | |
| 37 | 30 | |
| 38 | - /** | |
| 39 | - * Private variable to hold time start. | |
| 40 | - * | |
| 41 | - * @var int | |
| 42 | - */ | |
| 43 | - private static $time_start = null; | |
| 31 | + const LOG_COLOR = '#999999'; | |
| 32 | + const DEBUG_COLOR = '#666666'; | |
| 33 | + const INFO_COLOR = '#276f86'; | |
| 34 | + const WARNING_COLOR = '#9f3a38;'; | |
| 44 | 35 | |
| 45 | - /** | |
| 46 | - * Private varibale to hold the log file prefix. | |
| 47 | - * | |
| 48 | - * @var string Default 'mainwp' | |
| 49 | - */ | |
| 50 | - private $logFileNamePrefix = 'mainwp'; | |
| 36 | + /** | |
| 37 | + * Private variable to hold time start. | |
| 38 | + * | |
| 39 | + * @var int | |
| 40 | + */ | |
| 41 | + private static $time_start = null; | |
| 51 | 42 | |
| 52 | - /** | |
| 53 | - * Private varibale to hold the log file suffix. | |
| 54 | - * | |
| 55 | - * @var string Default '.log' | |
| 56 | - */ | |
| 57 | - private $logFileNameSuffix = '.log'; | |
| 43 | + /** | |
| 44 | + * Private varibale to hold the log file prefix. | |
| 45 | + * | |
| 46 | + * @var string Default 'mainwp' | |
| 47 | + */ | |
| 48 | + private $logFileNamePrefix = 'mainwp'; | |
| 58 | 49 | |
| 59 | - /** | |
| 60 | - * Private varibale to hold the log file max size. | |
| 61 | - * | |
| 62 | - * @var int Default 0.5 | |
| 63 | - */ | |
| 64 | - private $logMaxMB = 0.5; | |
| 50 | + /** | |
| 51 | + * Private varibale to hold the log file suffix. | |
| 52 | + * | |
| 53 | + * @var string Default '.log' | |
| 54 | + */ | |
| 55 | + private $logFileNameSuffix = '.log'; | |
| 65 | 56 | |
| 66 | - /** | |
| 67 | - * Private varibale to hold the log file date format. | |
| 68 | - * | |
| 69 | - * @var string Default 'Y-m-d H:i:s' | |
| 70 | - */ | |
| 71 | - private $logDateFormat = 'Y-m-d H:i:s'; | |
| 57 | + /** | |
| 58 | + * Private varibale to hold the log file max size. | |
| 59 | + * | |
| 60 | + * @var int Default 0.5 | |
| 61 | + */ | |
| 62 | + private $logMaxMB = 0.5; | |
| 72 | 63 | |
| 73 | - /** | |
| 74 | - * Private varibale to hold the log file output directory. | |
| 75 | - * | |
| 76 | - * @var mixed Default null | |
| 77 | - */ | |
| 78 | - private $logDirectory = null; | |
| 64 | + /** | |
| 65 | + * Private varibale to hold the log file date format. | |
| 66 | + * | |
| 67 | + * @var string Default 'Y-m-d H:i:s' | |
| 68 | + */ | |
| 69 | + private $logDateFormat = 'Y-m-d H:i:s'; | |
| 79 | 70 | |
| 80 | - /** | |
| 81 | - * Private varibale to hold the log file priotrity. | |
| 82 | - * | |
| 83 | - * @var string Disabled | |
| 84 | - */ | |
| 85 | - private $logPriority = self::DISABLED; | |
| 71 | + /** | |
| 72 | + * Private varibale to hold the log file output directory. | |
| 73 | + * | |
| 74 | + * @var mixed Default null | |
| 75 | + */ | |
| 76 | + private $logDirectory = null; | |
| 86 | 77 | |
| 87 | - /** | |
| 88 | - * Private varibale to hold the log Specific priotrity. | |
| 89 | - * | |
| 90 | - * @var string Disabled | |
| 91 | - */ | |
| 92 | - private $logSpecific = 0; | |
| 78 | + /** | |
| 79 | + * Private varibale to hold the log file priotrity. | |
| 80 | + * | |
| 81 | + * @var string Disabled | |
| 82 | + */ | |
| 83 | + private $logPriority = self::DISABLED; | |
| 93 | 84 | |
| 85 | + /** | |
| 86 | + * Private varibale to hold the log Specific priotrity. | |
| 87 | + * | |
| 88 | + * @var string Disabled | |
| 89 | + */ | |
| 90 | + private $logSpecific = 0; | |
| 94 | 91 | |
| 95 | - /** | |
| 96 | - * Private static varibale to hold the instance. | |
| 97 | - * | |
| 98 | - * @var mixed Default null | |
| 99 | - */ | |
| 100 | - private static $instance = null; | |
| 101 | 92 | |
| 102 | - /** | |
| 103 | - * Method instance() | |
| 104 | - * | |
| 105 | - * Returns new MainWP_Logger instance. | |
| 106 | - * | |
| 107 | - * @return self MainWP_Logger | |
| 108 | - * | |
| 109 | - * @uses \MainWP\Dashboard\MainWP_Logger | |
| 110 | - */ | |
| 111 | - public static function instance() { | |
| 112 | - if ( null === static::$instance ) { | |
| 113 | - static::$instance = new self(); | |
| 114 | - } | |
| 115 | - return static::$instance; | |
| 116 | - } | |
| 93 | + /** | |
| 94 | + * Private static varibale to hold the instance. | |
| 95 | + * | |
| 96 | + * @var mixed Default null | |
| 97 | + */ | |
| 98 | + private static $instance = null; | |
| 117 | 99 | |
| 118 | - /** | |
| 119 | - * MainWP_Logger constructor. | |
| 120 | - * | |
| 121 | - * Run each time the class is called. | |
| 122 | - * | |
| 123 | - * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_dir() | |
| 124 | - */ | |
| 125 | - private function __construct() { | |
| 100 | + /** | |
| 101 | + * Method instance() | |
| 102 | + * | |
| 103 | + * Returns new MainWP_Logger instance. | |
| 104 | + * | |
| 105 | + * @return self MainWP_Logger | |
| 106 | + * | |
| 107 | + * @uses \MainWP\Dashboard\MainWP_Logger | |
| 108 | + */ | |
| 109 | + public static function instance() { | |
| 110 | + if ( null == self::$instance ) { | |
| 111 | + self::$instance = new MainWP_Logger(); | |
| 112 | + } | |
| 126 | 113 | |
| 127 | - $enabled = $this->get_log_status(); | |
| 128 | - $specific = $this->get_log_specific(); | |
| 114 | + return self::$instance; | |
| 115 | + } | |
| 129 | 116 | |
| 130 | - $enabled = apply_filters( 'mainwp_log_status', $enabled ); | |
| 131 | - $specific = apply_filters( 'mainwp_log_specific', $specific ); | |
| 117 | + /** | |
| 118 | + * MainWP_Logger constructor. | |
| 119 | + * | |
| 120 | + * Run each time the class is called. | |
| 121 | + * | |
| 122 | + * @uses \MainWP\Dashboard\MainWP_System_Utility::get_mainwp_dir() | |
| 123 | + */ | |
| 124 | + private function __construct() { | |
| 132 | 125 | |
| 133 | - $this->set_log_priority( $enabled, $specific ); | |
| 134 | - } | |
| 126 | + $enabled = $this->get_log_status(); | |
| 127 | + $specific = $this->get_log_specific(); | |
| 135 | 128 | |
| 136 | - /** | |
| 137 | - * Method set_log_priority() | |
| 138 | - * | |
| 139 | - * Sets the log priority. | |
| 140 | - * | |
| 141 | - * @param mixed $logPriority Log priority value. | |
| 142 | - * @param mixed $spec_log Specific log. | |
| 143 | - */ | |
| 144 | - public function set_log_priority( $logPriority, $spec_log = 0 ) { | |
| 145 | - $this->logPriority = (int) $logPriority; | |
| 146 | - $this->logSpecific = (int) $spec_log; // 1 - specific log, 0 - not specific log. | |
| 147 | - } | |
| 129 | + $enabled = apply_filters( 'mainwp_log_status', $enabled ); | |
| 130 | + $specific = apply_filters( 'mainwp_log_specific', $specific ); | |
| 148 | 131 | |
| 149 | - /** | |
| 150 | - * Method get_log_status() | |
| 151 | - * | |
| 152 | - * Get log status. | |
| 153 | - * | |
| 154 | - * @return mixed $enabled log status. | |
| 155 | - */ | |
| 156 | - public function get_log_status() { | |
| 157 | - $enabled = get_option( 'mainwp_actionlogs' ); | |
| 132 | + $this->set_log_priority( $enabled, $specific ); | |
| 133 | + } | |
| 158 | 134 | |
| 159 | - if ( false === $enabled ) { | |
| 160 | - $sites_count = MainWP_DB::instance()->get_websites_count(); | |
| 161 | - if ( empty( $sites_count ) ) { | |
| 162 | - $enabled = self::DEBUG; | |
| 163 | - set_transient( 'mainwp_transient_action_logs', true, 2 * WEEK_IN_SECONDS ); | |
| 164 | - } elseif ( get_transient( 'mainwp_transient_action_logs' ) ) { | |
| 165 | - $enabled = self::DEBUG; | |
| 166 | - } else { | |
| 167 | - $enabled = static::DISABLED; | |
| 168 | - } | |
| 169 | - } | |
| 170 | - return $enabled; | |
| 171 | - } | |
| 135 | + /** | |
| 136 | + * Method set_log_priority() | |
| 137 | + * | |
| 138 | + * Sets the log priority. | |
| 139 | + * | |
| 140 | + * @param mixed $logPriority Log priority value. | |
| 141 | + * @param mixed $spec_log Specific log. | |
| 142 | + */ | |
| 143 | + public function set_log_priority( $logPriority, $spec_log = 0 ) { | |
| 144 | + $this->logPriority = $logPriority; | |
| 145 | + $this->logSpecific = $spec_log; // 1 - specific log, 0 - not specific log. | |
| 146 | + } | |
| 172 | 147 | |
| 148 | + /** | |
| 149 | + * Method get_log_status() | |
| 150 | + * | |
| 151 | + * Get log status. | |
| 152 | + * | |
| 153 | + * @return mixed $enabled log status. | |
| 154 | + */ | |
| 155 | + public function get_log_status() { | |
| 156 | + $enabled = get_option( 'mainwp_actionlogs' ); | |
| 173 | 157 | |
| 174 | - /** | |
| 175 | - * Method get_log_specific() | |
| 176 | - * | |
| 177 | - * Get log specific status. | |
| 178 | - * | |
| 179 | - * @return mixed $enabled log status. | |
| 180 | - */ | |
| 181 | - public function get_log_specific() { | |
| 182 | - return get_option( 'mainwp_specific_logs', 0 ); | |
| 183 | - } | |
| 158 | + if ( false === $enabled ) { | |
| 159 | + $sites_count = MainWP_DB::instance()->get_websites_count(); | |
| 160 | + if ( 0 == $sites_count ) { | |
| 161 | + $enabled = self::DEBUG; | |
| 162 | + set_transient( 'mainwp_transient_action_logs', true, 2 * WEEK_IN_SECONDS ); | |
| 163 | + } elseif ( get_transient( 'mainwp_transient_action_logs' ) ) { | |
| 164 | + $enabled = self::DEBUG; | |
| 165 | + } else { | |
| 166 | + $enabled = self::DISABLED; | |
| 167 | + } | |
| 168 | + } | |
| 184 | 169 | |
| 185 | - /** | |
| 186 | - * Method get_log_type_info() | |
| 187 | - * | |
| 188 | - * Get log type info. | |
| 189 | - * | |
| 190 | - * @param int $type Log type value. | |
| 191 | - * @param int $logcolor Log color value. | |
| 192 | - * | |
| 193 | - * @return int $currentColor log color code. | |
| 194 | - */ | |
| 195 | - public function get_log_type_info( $type, $logcolor ) { | |
| 196 | - $currentColor = ''; | |
| 197 | - $prefix = ''; | |
| 198 | - if ( static::DEBUG === $type || static::DEBUG === $logcolor ) { | |
| 199 | - $currentColor = static::DEBUG_COLOR; | |
| 200 | - $prefix = '[DEBUG]'; | |
| 201 | - } elseif ( static::INFO === $type || static::INFO === $logcolor ) { | |
| 202 | - $currentColor = static::INFO_COLOR; | |
| 203 | - $prefix = '[INFO]'; | |
| 204 | - } elseif ( static::WARNING === $type || static::WARNING === $logcolor ) { | |
| 205 | - $currentColor = static::WARNING_COLOR; | |
| 206 | - $prefix = '[WARNING]'; | |
| 207 | - } elseif ( static::LOG === $type || static::LOG === $logcolor ) { | |
| 208 | - $currentColor = static::LOG_COLOR; | |
| 209 | - $prefix = '[LOG]'; | |
| 210 | - } | |
| 211 | - return array( | |
| 212 | - 'log_color' => $currentColor, | |
| 213 | - 'log_prefix' => $prefix, | |
| 214 | - ); | |
| 215 | - } | |
| 170 | + return $enabled; | |
| 171 | + } | |
| 216 | 172 | |
| 217 | - /** | |
| 218 | - * Method debug() | |
| 219 | - * | |
| 220 | - * Grab debug. | |
| 221 | - * | |
| 222 | - * @param string $text Debug message text. | |
| 223 | - * | |
| 224 | - * @return string Log debug message. | |
| 225 | - */ | |
| 226 | - public function debug( $text ) { | |
| 227 | - return $this->log( $text, static::DEBUG ); | |
| 228 | - } | |
| 229 | 173 | |
| 230 | - /** | |
| 231 | - * Method info() | |
| 232 | - * | |
| 233 | - * Grab info. | |
| 234 | - * | |
| 235 | - * @param string $text Info message text. | |
| 236 | - * | |
| 237 | - * @return string Log info message. | |
| 238 | - */ | |
| 239 | - public function info( $text ) { | |
| 240 | - return $this->log( $text, static::INFO ); | |
| 241 | - } | |
| 174 | + /** | |
| 175 | + * Method get_log_specific() | |
| 176 | + * | |
| 177 | + * Get log specific status. | |
| 178 | + * | |
| 179 | + * @return mixed $enabled log status. | |
| 180 | + */ | |
| 181 | + public function get_log_specific() { | |
| 182 | + return get_option( 'mainwp_specific_logs', 0 ); | |
| 183 | + } | |
| 242 | 184 | |
| 243 | - /** | |
| 244 | - * Method warning() | |
| 245 | - * | |
| 246 | - * Grab warning information. | |
| 247 | - * | |
| 248 | - * @param string $text Warning message text. | |
| 249 | - * | |
| 250 | - * @return string Log warning message. | |
| 251 | - */ | |
| 252 | - public function warning( $text ) { | |
| 253 | - return $this->log( $text, static::WARNING ); | |
| 254 | - } | |
| 185 | + /** | |
| 186 | + * Method get_log_type_info() | |
| 187 | + * | |
| 188 | + * Get log type info. | |
| 189 | + * | |
| 190 | + * @param int $type Log type value. | |
| 191 | + * @param int $logcolor Log color value. | |
| 192 | + * | |
| 193 | + * @return int $currentColor log color code. | |
| 194 | + */ | |
| 195 | + public function get_log_type_info( $type, $logcolor ) { | |
| 196 | + $currentColor = ''; | |
| 197 | + $prefix = ''; | |
| 198 | + if ( self::DEBUG == $type || self::DEBUG == $logcolor ) { | |
| 199 | + $currentColor = self::DEBUG_COLOR; | |
| 200 | + $prefix = '[DEBUG]'; | |
| 201 | + } elseif ( self::INFO == $type || self::INFO == $logcolor ) { | |
| 202 | + $currentColor = self::INFO_COLOR; | |
| 203 | + $prefix = '[INFO]'; | |
| 204 | + } elseif ( self::WARNING == $type || self::WARNING == $logcolor ) { | |
| 205 | + $currentColor = self::WARNING_COLOR; | |
| 206 | + $prefix = '[WARNING]'; | |
| 207 | + } elseif ( self::LOG == $type || self::LOG == $logcolor ) { | |
| 208 | + $currentColor = self::LOG_COLOR; | |
| 209 | + $prefix = '[LOG]'; | |
| 210 | + } | |
| 211 | + return array( | |
| 212 | + 'log_color' => $currentColor, | |
| 213 | + 'log_prefix' => $prefix, | |
| 214 | + ); | |
| 215 | + } | |
| 255 | 216 | |
| 256 | - /** | |
| 257 | - * Method actions() | |
| 258 | - * | |
| 259 | - * Grab actions information. | |
| 260 | - * | |
| 261 | - * @param string $text Warning message text. | |
| 262 | - * @param int $priority priority message. | |
| 263 | - * @param int $log_color Set color: 0 - LOG, 1 - WARNING, 2 - INFO, 3- DEBUG. | |
| 264 | - * @param bool $forced forced logging. | |
| 265 | - * | |
| 266 | - * @return string Log warning message. | |
| 267 | - */ | |
| 268 | - public function log_action( $text, $priority, $log_color = 0, $forced = false ) { | |
| 269 | - return $this->log( $text, $priority, $log_color, $forced ); | |
| 270 | - } | |
| 217 | + /** | |
| 218 | + * Method debug() | |
| 219 | + * | |
| 220 | + * Grab debug. | |
| 221 | + * | |
| 222 | + * @param string $text Debug message text. | |
| 223 | + * | |
| 224 | + * @return string Log debug message. | |
| 225 | + */ | |
| 226 | + public function debug( $text ) { | |
| 227 | + return $this->log( $text, self::DEBUG ); | |
| 228 | + } | |
| 271 | 229 | |
| 230 | + /** | |
| 231 | + * Method info() | |
| 232 | + * | |
| 233 | + * Grab info. | |
| 234 | + * | |
| 235 | + * @param string $text Info message text. | |
| 236 | + * | |
| 237 | + * @return string Log info message. | |
| 238 | + */ | |
| 239 | + public function info( $text ) { | |
| 240 | + return $this->log( $text, self::INFO ); | |
| 241 | + } | |
| 272 | 242 | |
| 273 | - /** | |
| 274 | - * Method log_update_check(). | |
| 275 | - * | |
| 276 | - * @param string $text Log update check. | |
| 277 | - */ | |
| 278 | - public function log_update_check( $text = '' ) { | |
| 279 | - $this->log_action( $text, static::UPDATE_CHECK_LOG_PRIORITY ); | |
| 280 | - } | |
| 243 | + /** | |
| 244 | + * Method warning() | |
| 245 | + * | |
| 246 | + * Grab warning information. | |
| 247 | + * | |
| 248 | + * @param string $text Warning message text. | |
| 249 | + * | |
| 250 | + * @return string Log warning message. | |
| 251 | + */ | |
| 252 | + public function warning( $text ) { | |
| 253 | + return $this->log( $text, self::WARNING ); | |
| 254 | + } | |
| 281 | 255 | |
| 282 | - /** | |
| 283 | - * Method debug_for_website() | |
| 284 | - * | |
| 285 | - * Grab website debug and info. | |
| 286 | - * | |
| 287 | - * @param object $website Child site object. | |
| 288 | - * @param string $action Performed action. | |
| 289 | - * @param string $message Debug message. | |
| 290 | - * | |
| 291 | - * @return mixed Website debug info. | |
| 292 | - * | |
| 293 | - * @uses \MainWP\Dashboard\MainWP_Utility::get_nice_url() | |
| 294 | - */ | |
| 295 | - public function debug_for_website( $website, $action, $message ) { | |
| 296 | - if ( empty( $website ) ) { | |
| 297 | - return $this->log( '[-] [-] ::' . $action . ':: ' . $message, static::DEBUG ); | |
| 298 | - } | |
| 256 | + /** | |
| 257 | + * Method actions() | |
| 258 | + * | |
| 259 | + * Grab actions information. | |
| 260 | + * | |
| 261 | + * @param string $text Warning message text. | |
| 262 | + * @param int $priority priority message. | |
| 263 | + * @param int $log_color Set color: 0 - LOG, 1 - WARNING, 2 - INFO, 3- DEBUG. | |
| 264 | + * @param bool $forced forced logging. | |
| 265 | + * | |
| 266 | + * @return string Log warning message. | |
| 267 | + */ | |
| 268 | + public function log_action( $text, $priority, $log_color = 0, $forced = false ) { | |
| 269 | + return $this->log( $text, $priority, $log_color, $forced ); | |
| 270 | + } | |
| 299 | 271 | |
| 300 | - return $this->log( '[' . $website->name . '] [' . MainWP_Utility::get_nice_url( $website->url ) . '] ::' . $action . ':: ' . $message, static::DEBUG, 0, false, $website ); | |
| 301 | - } | |
| 272 | + /** | |
| 273 | + * Method log_execution_time(). | |
| 274 | + * | |
| 275 | + * @param string $text Log record text. | |
| 276 | + * | |
| 277 | + * Log the execution time value. | |
| 278 | + */ | |
| 279 | + public function log_execution_time( $text = '' ) { | |
| 280 | + $exec_time = self::get_execution_time(); | |
| 281 | + self::instance()->log_action( 'execution time (sec) :: ' . ( ! empty( $text ) ? (string) $text . ' :: ' : '' ) . $exec_time, self::EXECUTION_TIME_LOG_PRIORITY ); | |
| 282 | + } | |
| 302 | 283 | |
| 303 | - /** | |
| 304 | - * Method info_for_website() | |
| 305 | - * | |
| 306 | - * Grab Website Info. | |
| 307 | - * | |
| 308 | - * @param object $website Child site object. | |
| 309 | - * @param string $action Performed action. | |
| 310 | - * @param string $message Info message. | |
| 311 | - * | |
| 312 | - * @return mixed Website Info. | |
| 313 | - * | |
| 314 | - * @uses \MainWP\Dashboard\MainWP_Utility::get_nice_url() | |
| 315 | - */ | |
| 316 | - public function info_for_website( $website, $action, $message ) { | |
| 317 | - if ( empty( $website ) ) { | |
| 318 | - return $this->log( '[-] [-] ::' . $action . ':: ' . $message, static::INFO ); | |
| 319 | - } | |
| 284 | + /** | |
| 285 | + * Method log_update_check(). | |
| 286 | + * | |
| 287 | + * @param string $text Log update check. | |
| 288 | + */ | |
| 289 | + public function log_update_check( $text = '' ) { | |
| 290 | + self::instance()->log_action( $text, self::UPDATE_CHECK_LOG_PRIORITY ); | |
| 291 | + } | |
| 320 | 292 | |
| 321 | - return $this->log( '[' . $website->name . '] [' . MainWP_Utility::get_nice_url( $website->url ) . '] ::' . $action . ':: ' . $message, static::INFO ); | |
| 322 | - } | |
| 293 | + /** | |
| 294 | + * Method debug_for_website() | |
| 295 | + * | |
| 296 | + * Grab website debug and info. | |
| 297 | + * | |
| 298 | + * @param object $website Child site object. | |
| 299 | + * @param string $action Performed action. | |
| 300 | + * @param string $message Debug message. | |
| 301 | + * | |
| 302 | + * @return mixed Website debug info. | |
| 303 | + * | |
| 304 | + * @uses \MainWP\Dashboard\MainWP_Utility::get_nice_url() | |
| 305 | + */ | |
| 306 | + public function debug_for_website( $website, $action, $message ) { | |
| 307 | + if ( empty( $website ) ) { | |
| 308 | + return $this->log( '[-] [-] ::' . $action . ':: ' . $message, self::DEBUG ); | |
| 309 | + } | |
| 323 | 310 | |
| 324 | - /** | |
| 325 | - * Method warning_for_website() | |
| 326 | - * | |
| 327 | - * Grab Website Warnings. | |
| 328 | - * | |
| 329 | - * @param object $website Child site object. | |
| 330 | - * @param string $action Performed action. | |
| 331 | - * @param string $message Warning message. | |
| 332 | - * @param bool $addStackTrace Add or Don't add stack trace. | |
| 333 | - * | |
| 334 | - * @return string Website warnings. | |
| 335 | - */ | |
| 336 | - public function warning_for_website( $website, $action, $message, $addStackTrace = true ) { | |
| 337 | - $stackTrace = ''; | |
| 338 | - if ( $addStackTrace ) { | |
| 339 | - ob_start(); | |
| 340 | - // phpcs:ignore -- for debugging. | |
| 341 | - debug_print_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); | |
| 342 | - $stackTrace = "\n" . ob_get_clean(); | |
| 343 | - } | |
| 344 | - if ( empty( $website ) ) { | |
| 345 | - return $this->log( '[-] [-] :: ' . $action . ' :: ' . $message . $stackTrace, static::WARNING ); | |
| 346 | - } | |
| 311 | + return $this->log( '[' . $website->name . '] [' . MainWP_Utility::get_nice_url( $website->url ) . '] ::' . $action . ':: ' . $message, self::DEBUG ); | |
| 312 | + } | |
| 347 | 313 | |
| 348 | - return $this->log( '[' . $website->name . '] [' . MainWP_Utility::get_nice_url( $website->url ) . '] ::' . $action . ':: ' . $message . $stackTrace, static::WARNING ); | |
| 349 | - } | |
| 314 | + /** | |
| 315 | + * Method info_for_website() | |
| 316 | + * | |
| 317 | + * Grab Website Info. | |
| 318 | + * | |
| 319 | + * @param object $website Child site object. | |
| 320 | + * @param string $action Performed action. | |
| 321 | + * @param string $message Info message. | |
| 322 | + * | |
| 323 | + * @return mixed Website Info. | |
| 324 | + * | |
| 325 | + * @uses \MainWP\Dashboard\MainWP_Utility::get_nice_url() | |
| 326 | + */ | |
| 327 | + public function info_for_website( $website, $action, $message ) { | |
| 328 | + if ( empty( $website ) ) { | |
| 329 | + return $this->log( '[-] [-] ::' . $action . ':: ' . $message, self::INFO ); | |
| 330 | + } | |
| 350 | 331 | |
| 351 | - /** | |
| 352 | - * Method log_to_db() | |
| 353 | - * | |
| 354 | - * Log to database. | |
| 355 | - * | |
| 356 | - * @param string $text Log record text. | |
| 357 | - * @param int $priority Set priority. | |
| 358 | - * @param int $log_color Set color. | |
| 359 | - * @param bool $forced forced logging. | |
| 360 | - * @param mixed $website website object. | |
| 361 | - * | |
| 362 | - * @return bool true|false Default is False. | |
| 363 | - */ | |
| 364 | - private function log_to_db( $text, $priority, $log_color = 0, $forced = false, $website = false ) { | |
| 332 | + return $this->log( '[' . $website->name . '] [' . MainWP_Utility::get_nice_url( $website->url ) . '] ::' . $action . ':: ' . $message, self::INFO ); | |
| 333 | + } | |
| 365 | 334 | |
| 366 | - if ( static::DISABLED === $this->logPriority ) { | |
| 367 | - return false; | |
| 368 | - } | |
| 335 | + /** | |
| 336 | + * Method warning_for_website() | |
| 337 | + * | |
| 338 | + * Grab Website Warnings. | |
| 339 | + * | |
| 340 | + * @param object $website Child site object. | |
| 341 | + * @param string $action Performed action. | |
| 342 | + * @param string $message Warning message. | |
| 343 | + * @param bool $addStackTrace Add or Don't add stack trace. | |
| 344 | + * | |
| 345 | + * @return string Website warnings. | |
| 346 | + */ | |
| 347 | + public function warning_for_website( $website, $action, $message, $addStackTrace = true ) { | |
| 348 | + $stackTrace = ''; | |
| 349 | + if ( $addStackTrace ) { | |
| 350 | + ob_start(); | |
| 351 | + // phpcs:ignore -- for debugging. | |
| 352 | + debug_print_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); | |
| 353 | + $stackTrace = "\n" . ob_get_clean(); | |
| 354 | + } | |
| 355 | + if ( empty( $website ) ) { | |
| 356 | + return $this->log( '[-] [-] ::' . $action . ':: ' . $message . $stackTrace, self::WARNING ); | |
| 357 | + } | |
| 369 | 358 | |
| 370 | - $priority = (int) apply_filters( 'mainwp_log_to_db_priority', $priority, $website ); | |
| 359 | + return $this->log( '[' . $website->name . '] [' . MainWP_Utility::get_nice_url( $website->url ) . '] ::' . $action . ':: ' . $message . $stackTrace, self::WARNING ); | |
| 360 | + } | |
| 371 | 361 | |
| 372 | - $do_log = false; | |
| 362 | + /** | |
| 363 | + * Method log_to_db() | |
| 364 | + * | |
| 365 | + * Log to database. | |
| 366 | + * | |
| 367 | + * @param string $text Log record text. | |
| 368 | + * @param int $priority Set priority. | |
| 369 | + * @param int $log_color Set color. | |
| 370 | + * @param bool $forced forced logging. | |
| 371 | + * | |
| 372 | + * @return bool true|false Default is False. | |
| 373 | + */ | |
| 374 | + private function log_to_db( $text, $priority, $log_color = 0, $forced = false ) { | |
| 373 | 375 | |
| 374 | - if ( 1 === $this->logSpecific ) { // 1 - specific log, 0 - not specific log. | |
| 375 | - if ( $this->logPriority === $priority ) { // specific priority number saved setting. | |
| 376 | - $do_log = true; | |
| 377 | - } | |
| 378 | - } elseif ( $this->logPriority >= $priority ) { | |
| 379 | - $do_log = true; | |
| 380 | - } | |
| 376 | + if ( self::DISABLED === $this->logPriority ) { | |
| 377 | + return; | |
| 378 | + } | |
| 381 | 379 | |
| 382 | - $do_log = apply_filters( 'mainwp_log_do_to_db', $do_log, $website ); | |
| 380 | + $priority = apply_filters( 'mainwp_log_to_db_priority', $priority ); | |
| 383 | 381 | |
| 384 | - $text = $this->prepare_log_info( $text ); | |
| 382 | + $do_log = false; | |
| 385 | 383 | |
| 386 | - do_action( 'mainwp_before_log_data', $text, $priority, $log_color ); | |
| 384 | + if ( 1 == $this->logSpecific ) { // 1 - specific log, 0 - not specific log. | |
| 385 | + if ( $this->logPriority == $priority ) { // specific priority number saved setting. | |
| 386 | + $do_log = true; | |
| 387 | + } | |
| 388 | + } elseif ( $this->logPriority >= $priority ) { | |
| 389 | + $do_log = true; | |
| 390 | + } | |
| 387 | 391 | |
| 388 | - if ( defined( 'DOING_CRON' ) && DOING_CRON && 'CRON' !== strtoupper( substr( $text, 0, 4 ) ) ) { | |
| 389 | - $text = 'CRON :: ' . $text; | |
| 390 | - } | |
| 392 | + $text = $this->prepare_log_info( $text ); | |
| 391 | 393 | |
| 392 | - if ( $forced || $do_log ) { | |
| 394 | + if ( $forced || $do_log ) { | |
| 393 | 395 | |
| 394 | - /** | |
| 395 | - * Current user global. | |
| 396 | - * | |
| 397 | - * @global string | |
| 398 | - */ | |
| 399 | - global $current_user; | |
| 396 | + $time = gmdate( $this->logDateFormat ); | |
| 400 | 397 | |
| 401 | - $user = ''; | |
| 402 | - if ( ! empty( $current_user ) && ! empty( $current_user->user_login ) ) { | |
| 403 | - $user = $current_user->user_login; | |
| 404 | - } elseif ( defined( 'WP_CLI' ) ) { | |
| 405 | - $user = 'WP_CLI'; | |
| 406 | - } elseif ( defined( 'DOING_CRON' ) ) { | |
| 407 | - $user = 'DOING_CRON'; | |
| 408 | - } | |
| 398 | + /** | |
| 399 | + * Current user global. | |
| 400 | + * | |
| 401 | + * @global string | |
| 402 | + */ | |
| 403 | + global $current_user; | |
| 409 | 404 | |
| 410 | - $data = array(); | |
| 405 | + $user = ''; | |
| 406 | + if ( ! empty( $current_user ) && ! empty( $current_user->user_login ) ) { | |
| 407 | + $user = $current_user->user_login; | |
| 408 | + } elseif ( defined( 'WP_CLI' ) ) { | |
| 409 | + $user = 'WP_CLI'; | |
| 410 | + } elseif ( defined( 'DOING_CRON' ) ) { | |
| 411 | + $user = 'DOING_CRON'; | |
| 412 | + } | |
| 411 | 413 | |
| 412 | - $data['log_content'] = $text; | |
| 413 | - $data['log_user'] = $user; | |
| 414 | - $data['log_type'] = $priority; | |
| 415 | - $data['log_color'] = intval( $log_color ); | |
| 416 | - $data['log_timestamp'] = time(); | |
| 414 | + $data = array(); | |
| 417 | 415 | |
| 418 | - $data = apply_filters( 'mainwp_log_to_db_data', $data ); | |
| 416 | + $data['log_content'] = $text; | |
| 417 | + $data['log_user'] = $user; | |
| 418 | + $data['log_type'] = $priority; | |
| 419 | + $data['log_color'] = intval( $log_color ); | |
| 420 | + $data['log_timestamp'] = time(); | |
| 419 | 421 | |
| 420 | - MainWP_DB_Common::instance()->insert_action_log( $data ); | |
| 422 | + $data = apply_filters( 'mainwp_log_to_db_data', $data ); | |
| 421 | 423 | |
| 422 | - return true; | |
| 423 | - } | |
| 424 | - return false; | |
| 425 | - } | |
| 424 | + MainWP_DB_Common::instance()->insert_action_log( $data ); | |
| 426 | 425 | |
| 427 | - /** | |
| 428 | - * Method log() | |
| 429 | - * | |
| 430 | - * Create Log File. | |
| 431 | - * | |
| 432 | - * @param string $text Log record text. | |
| 433 | - * @param int $priority Set priority. | |
| 434 | - * @param int $log_color Set color. | |
| 435 | - * @param bool $forced forced logging. | |
| 436 | - * @param mixed $website Site object. | |
| 437 | - * | |
| 438 | - * @return bool true|false Default is False. | |
| 439 | - */ | |
| 440 | - private function log( $text, $priority, $log_color = 0, $forced = false, $website = false ) { // phpcs:ignore -- NOSONAR - complex function. | |
| 426 | + return true; | |
| 427 | + } | |
| 428 | + return false; | |
| 429 | + } | |
| 441 | 430 | |
| 442 | - if ( static::DISABLED === $this->logPriority ) { | |
| 443 | - return; | |
| 444 | - } | |
| 431 | + /** | |
| 432 | + * Method log() | |
| 433 | + * | |
| 434 | + * Create Log File. | |
| 435 | + * | |
| 436 | + * @param string $text Log record text. | |
| 437 | + * @param int $priority Set priority. | |
| 438 | + * @param int $log_color Set color. | |
| 439 | + * @param bool $forced forced logging. | |
| 440 | + * | |
| 441 | + * @return bool true|false Default is False. | |
| 442 | + */ | |
| 443 | + private function log( $text, $priority, $log_color = 0, $forced = false ) { // phpcs:ignore -- complex function. | |
| 445 | 444 | |
| 446 | - $log_to_db = apply_filters( 'mainwp_logger_to_db', true, $website ); | |
| 445 | + if ( self::DISABLED == $this->logPriority ) { | |
| 446 | + return; | |
| 447 | + } | |
| 447 | 448 | |
| 448 | - if ( $log_to_db ) { | |
| 449 | - return $this->log_to_db( $text, $priority, $log_color, $forced, $website ); | |
| 450 | - } | |
| 449 | + $log_to_db = apply_filters( 'mainwp_logger_to_db', true ); | |
| 451 | 450 | |
| 452 | - $text = $this->prepare_log_info( $text ); | |
| 451 | + if ( $log_to_db ) { | |
| 452 | + return $this->log_to_db( $text, $priority, $log_color, $forced ); | |
| 453 | + } | |
| 453 | 454 | |
| 454 | - $do_log = false; | |
| 455 | - if ( 1 === $this->logSpecific ) { // 1 - specific log, 0 - not specific log. | |
| 456 | - if ( $this->logPriority === $priority ) { // specific priority number saved setting. | |
| 457 | - $do_log = true; | |
| 458 | - } | |
| 459 | - } elseif ( $this->logPriority >= $priority ) { | |
| 460 | - $do_log = true; | |
| 461 | - } | |
| 455 | + $text = $this->prepare_log_info( $text ); | |
| 462 | 456 | |
| 463 | - if ( $do_log ) { | |
| 464 | - $this->logCurrentFile = $this->get_log_file(); | |
| 465 | - $logCurrentHandle = fopen( $this->logCurrentFile, 'a+' ); | |
| 457 | + $do_log = false; | |
| 458 | + if ( 1 == $this->logSpecific ) { // 1 - specific log, 0 - not specific log. | |
| 459 | + if ( $this->logPriority == $priority ) { // specific priority number saved setting. | |
| 460 | + $do_log = true; | |
| 461 | + } | |
| 462 | + } elseif ( $this->logPriority >= $priority ) { | |
| 463 | + $do_log = true; | |
| 464 | + } | |
| 466 | 465 | |
| 467 | - if ( $logCurrentHandle ) { | |
| 468 | - $time = gmdate( $this->logDateFormat ); | |
| 469 | - $prefix = '[' . $this->get_log_text( $priority ) . ']'; | |
| 466 | + if ( $do_log ) { | |
| 467 | + $this->logCurrentFile = $this->get_log_file(); | |
| 468 | + $logCurrentHandle = fopen( $this->logCurrentFile, 'a+' ); | |
| 470 | 469 | |
| 471 | - /** | |
| 472 | - * Current user global. | |
| 473 | - * | |
| 474 | - * @global string | |
| 475 | - */ | |
| 476 | - global $current_user; | |
| 470 | + if ( $logCurrentHandle ) { | |
| 471 | + $time = gmdate( $this->logDateFormat ); | |
| 472 | + $prefix = '[' . $this->get_log_text( $priority ) . ']'; | |
| 477 | 473 | |
| 478 | - if ( ! empty( $current_user ) && ! empty( $current_user->user_login ) ) { | |
| 479 | - $prefix .= ' [administrator]'; | |
| 480 | - } | |
| 474 | + /** | |
| 475 | + * Current user global. | |
| 476 | + * | |
| 477 | + * @global string | |
| 478 | + */ | |
| 479 | + global $current_user; | |
| 481 | 480 | |
| 482 | - fwrite( $logCurrentHandle, $time . ' ' . $prefix . ' ' . $text . "\n" ); | |
| 483 | - fclose( $logCurrentHandle ); | |
| 484 | - } | |
| 481 | + if ( ! empty( $current_user ) && ! empty( $current_user->user_login ) ) { | |
| 482 | + $prefix .= ' [administrator]'; | |
| 483 | + } | |
| 485 | 484 | |
| 486 | - if ( filesize( $this->logCurrentFile ) > ( $this->logMaxMB * 1048576 ) ) { | |
| 487 | - $logCurrentHandle = fopen( $this->logCurrentFile, 'a+' ); | |
| 488 | - if ( $logCurrentHandle ) { | |
| 489 | - fseek( $logCurrentHandle, 0 ); | |
| 490 | - $newLogFile = $this->logCurrentFile . '.tmp'; | |
| 491 | - $newLogHandle = false; | |
| 492 | - $chunkSize = filesize( $this->logCurrentFile ) - ( $this->logMaxMB * 1048576 ); | |
| 493 | - while ( is_resource( $logCurrentHandle ) && ! feof( $logCurrentHandle ) && ( $chunkSize > 0 ) ) { | |
| 494 | - $content = fread( $logCurrentHandle, $chunkSize ); | |
| 495 | - if ( false === $content ) { | |
| 496 | - break; | |
| 497 | - } | |
| 498 | - $pos = strrpos( $content, "\n" ); | |
| 499 | - if ( $newLogHandle ) { | |
| 500 | - fwrite( $newLogHandle, $content ); | |
| 501 | - } elseif ( $pos ) { | |
| 502 | - if ( ! $newLogHandle ) { | |
| 503 | - $newLogHandle = fopen( $newLogFile, 'w+' ); | |
| 504 | - } | |
| 505 | - fwrite( $newLogHandle, substr( $content, $pos + 1 ) ); | |
| 506 | - } | |
| 507 | - } | |
| 485 | + fwrite( $logCurrentHandle, $time . ' ' . $prefix . ' ' . $text . "\n" ); | |
| 486 | + fclose( $logCurrentHandle ); | |
| 487 | + } | |
| 508 | 488 | |
| 509 | - if ( is_resource( $logCurrentHandle ) ) { | |
| 510 | - fclose( $logCurrentHandle ); | |
| 511 | - } | |
| 489 | + if ( filesize( $this->logCurrentFile ) > ( $this->logMaxMB * 1048576 ) ) { | |
| 490 | + $logCurrentHandle = fopen( $this->logCurrentFile, 'a+' ); | |
| 491 | + if ( $logCurrentHandle ) { | |
| 492 | + fseek( $logCurrentHandle, 0 ); | |
| 493 | + $newLogFile = $this->logCurrentFile . '.tmp'; | |
| 494 | + $newLogHandle = false; | |
| 495 | + $chunkSize = filesize( $this->logCurrentFile ) - ( $this->logMaxMB * 1048576 ); | |
| 496 | + while ( is_resource( $logCurrentHandle ) && ! feof( $logCurrentHandle ) && ( $chunkSize > 0 ) ) { | |
| 497 | + $content = fread( $logCurrentHandle, $chunkSize ); | |
| 498 | + if ( false === $content ) { | |
| 499 | + break; | |
| 500 | + } | |
| 501 | + $pos = strrpos( $content, "\n" ); | |
| 502 | + if ( $newLogHandle ) { | |
| 503 | + fwrite( $newLogHandle, $content ); | |
| 504 | + } elseif ( $pos ) { | |
| 505 | + if ( ! $newLogHandle ) { | |
| 506 | + $newLogHandle = fopen( $newLogFile, 'w+' ); | |
| 507 | + } | |
| 508 | + fwrite( $newLogHandle, substr( $content, $pos + 1 ) ); | |
| 509 | + } | |
| 510 | + } | |
| 512 | 511 | |
| 513 | - if ( $newLogHandle ) { | |
| 514 | - fclose( $newLogHandle ); | |
| 515 | - wp_delete_file( $this->logCurrentFile ); | |
| 516 | - if ( file_exists( $newLogFile ) ) { | |
| 517 | - rename( $newLogFile, $this->logCurrentFile ); | |
| 518 | - } | |
| 519 | - } | |
| 520 | - } | |
| 521 | - } | |
| 512 | + if ( is_resource( $logCurrentHandle ) ) { | |
| 513 | + fclose( $logCurrentHandle ); | |
| 514 | + } | |
| 522 | 515 | |
| 523 | - return true; | |
| 524 | - } | |
| 516 | + if ( $newLogHandle ) { | |
| 517 | + fclose( $newLogHandle ); | |
| 518 | + unlink( $this->logCurrentFile ); | |
| 519 | + if ( file_exists( $newLogFile ) ) { | |
| 520 | + rename( $newLogFile, $this->logCurrentFile ); | |
| 521 | + } | |
| 522 | + } | |
| 523 | + } | |
| 524 | + } | |
| 525 | 525 | |
| 526 | - return false; | |
| 527 | - } | |
| 526 | + return true; | |
| 527 | + } | |
| 528 | 528 | |
| 529 | + return false; | |
| 530 | + } | |
| 529 | 531 | |
| 530 | - /** | |
| 531 | - * Method prepare_log_info() | |
| 532 | - * | |
| 533 | - * Prepare log data. | |
| 534 | - * | |
| 535 | - * @param mixed $data Log data. | |
| 536 | - * | |
| 537 | - * @return mixed $data filtered data. | |
| 538 | - */ | |
| 539 | - public function prepare_log_info( $data ) { | |
| 540 | - $patterns[0] = '/user=([^\&]+)\&/'; | |
| 541 | - $replacement[0] = 'user=xxxxxx&'; | |
| 542 | - $patterns[1] = '/alt_user=([^\&]+)\&/'; | |
| 543 | - $replacement[1] = 'alt_user=xxxxxx&'; | |
| 544 | - $patterns[2] = '/\&server=([^\&]+)\&/'; | |
| 545 | - $replacement[2] = '&server=xxxxxx&'; | |
| 546 | - $data = preg_replace( $patterns, $replacement, $data ); | |
| 547 | - return $data; | |
| 548 | - } | |
| 549 | 532 | |
| 550 | - /** | |
| 551 | - * Method prepend() | |
| 552 | - * | |
| 553 | - * Prepend content to log file. | |
| 554 | - * | |
| 555 | - * @param mixed $str Custom string. | |
| 556 | - * @param mixed $filename Filename. | |
| 557 | - */ | |
| 558 | - public function prepend( $str, $filename ) { | |
| 559 | - $context = stream_context_create(); | |
| 560 | - $fp = fopen( $filename, 'r', 1, $context ); | |
| 561 | - $tmpname = md5( $str ); // NOSONAR - safe for salt file name. | |
| 562 | - file_put_contents( $tmpname, $str ); | |
| 563 | - file_put_contents( $tmpname, $fp, FILE_APPEND ); | |
| 564 | - fclose( $fp ); | |
| 565 | - wp_delete_file( $filename ); | |
| 566 | - rename( $tmpname, $filename ); | |
| 567 | - } | |
| 533 | + /** | |
| 534 | + * Method prepare_log_info() | |
| 535 | + * | |
| 536 | + * Prepare log data. | |
| 537 | + * | |
| 538 | + * @param mixed $data Log data. | |
| 539 | + * | |
| 540 | + * @return mixed $data filtered data. | |
| 541 | + */ | |
| 542 | + public function prepare_log_info( $data ) { | |
| 543 | + $patterns[0] = '/user=([^\&]+)\&/'; | |
| 544 | + $replacement[0] = 'user=xxxxxx&'; | |
| 545 | + $patterns[1] = '/alt_user=([^\&]+)\&/'; | |
| 546 | + $replacement[1] = 'alt_user=xxxxxx&'; | |
| 547 | + $patterns[2] = '/\&server=([^\&]+)\&/'; | |
| 548 | + $replacement[2] = '&server=xxxxxx&'; | |
| 549 | + $data = preg_replace( $patterns, $replacement, $data ); | |
| 550 | + return $data; | |
| 551 | + } | |
| 568 | 552 | |
| 569 | - /** | |
| 570 | - * Method init_execution_time(). | |
| 571 | - * | |
| 572 | - * @param string $time_index index for timer. | |
| 573 | - * | |
| 574 | - * Init execution time start value. | |
| 575 | - */ | |
| 576 | - public function init_execution_time( $time_index = '' ) { | |
| 577 | - if ( null === static::$time_start || ! is_array( static::$time_start ) ) { | |
| 578 | - static::$time_start = array( 'start' => microtime( true ) ); | |
| 579 | - $this->log_action( 'execution time :: init :: [start]', static::EXECUTION_TIME_LOG_PRIORITY ); | |
| 580 | - } | |
| 553 | + /** | |
| 554 | + * Method prepend() | |
| 555 | + * | |
| 556 | + * Prepend content to log file. | |
| 557 | + * | |
| 558 | + * @param mixed $string Custom string. | |
| 559 | + * @param mixed $filename Filename. | |
| 560 | + */ | |
| 561 | + public function prepend( $string, $filename ) { | |
| 562 | + $context = stream_context_create(); | |
| 563 | + $fp = fopen( $filename, 'r', 1, $context ); | |
| 564 | + $tmpname = md5( $string ); | |
| 565 | + file_put_contents( $tmpname, $string ); | |
| 566 | + file_put_contents( $tmpname, $fp, FILE_APPEND ); | |
| 567 | + fclose( $fp ); | |
| 568 | + unlink( $filename ); | |
| 569 | + rename( $tmpname, $filename ); | |
| 570 | + } | |
| 581 | 571 | |
| 582 | - if ( ! empty( $time_index ) && is_string( $time_index ) && 'start' !== $time_index ) { | |
| 583 | - static::$time_start[ $time_index ] = microtime( true ); | |
| 584 | - $this->log_action( 'execution time :: init :: [' . $time_index . ']', static::EXECUTION_TIME_LOG_PRIORITY ); | |
| 585 | - } | |
| 586 | - } | |
| 572 | + /** | |
| 573 | + * Method init_execution_time(). | |
| 574 | + * | |
| 575 | + * @param string $code execution time code. | |
| 576 | + * | |
| 577 | + * Init execution time start value. | |
| 578 | + */ | |
| 579 | + public function init_execution_time( $code = '' ) { | |
| 580 | + if ( null === self::$time_start || ! is_array( self::$time_start ) ) { | |
| 581 | + self::$time_start = array( 'start' => microtime( true ) ); | |
| 582 | + $this->log_action( 'init execution time :: [code=start]', self::EXECUTION_TIME_LOG_PRIORITY ); | |
| 583 | + $code = 'start'; | |
| 584 | + } | |
| 587 | 585 | |
| 588 | - /** | |
| 589 | - * Method log_execution_time(). | |
| 590 | - * | |
| 591 | - * @param string $text Log record text. | |
| 592 | - * | |
| 593 | - * Log the execution time value. | |
| 594 | - */ | |
| 595 | - public function log_execution_time( $text = '' ) { | |
| 596 | - $exec_time = $this->get_execution_time(); | |
| 597 | - $this->log_action( 'execution time :: ' . ( ! empty( $text ) ? (string) $text : '<empty>' ) . ' :: [time=' . round( $exec_time, 4 ) . '](seconds)', static::EXECUTION_TIME_LOG_PRIORITY ); | |
| 598 | - } | |
| 586 | + if ( ! empty( $code ) && is_string( $code ) && 'start' !== $code ) { | |
| 587 | + self::$time_start[ $code ] = microtime( true ); | |
| 588 | + $this->log_action( 'init execution time :: [code=' . $code . ']', self::EXECUTION_TIME_LOG_PRIORITY ); | |
| 589 | + } | |
| 590 | + } | |
| 599 | 591 | |
| 592 | + /** | |
| 593 | + * Method get_execution_time(). | |
| 594 | + * | |
| 595 | + * Get the execution time value. | |
| 596 | + * | |
| 597 | + * @return int execution time. | |
| 598 | + */ | |
| 599 | + private function get_execution_time() { | |
| 600 | + if ( empty( $this->time_start ) ) { | |
| 601 | + return 0; | |
| 602 | + } | |
| 603 | + return round( microtime( true ) - $this->time_start, 6 ); // seconds. | |
| 604 | + } | |
| 600 | 605 | |
| 601 | - /** | |
| 602 | - * Method get_execution_time(). | |
| 603 | - * | |
| 604 | - * Get the execution time value. | |
| 605 | - * | |
| 606 | - * @param string $time_index Index for timer. | |
| 607 | - * | |
| 608 | - * @return int execution time. | |
| 609 | - */ | |
| 610 | - private function get_execution_time( $time_index = '' ) { | |
| 606 | + /** | |
| 607 | + * Method get_log_file() | |
| 608 | + * | |
| 609 | + * Grab Log File. | |
| 610 | + * | |
| 611 | + * @return mixed Log File. | |
| 612 | + */ | |
| 613 | + public function get_log_file() { | |
| 614 | + if ( empty( $this->logDirectory ) ) { | |
| 615 | + $this->logDirectory = MainWP_System_Utility::get_mainwp_dir(); | |
| 616 | + $this->logDirectory = $this->logDirectory[0]; | |
| 617 | + } | |
| 618 | + return $this->logDirectory . $this->logFileNamePrefix . $this->logFileNameSuffix; | |
| 619 | + } | |
| 611 | 620 | |
| 612 | - if ( empty( static::$time_start ) ) { | |
| 613 | - return 0; | |
| 614 | - } | |
| 621 | + /** | |
| 622 | + * Method get_log_text() | |
| 623 | + * | |
| 624 | + * Grab what type of log entry. | |
| 625 | + * | |
| 626 | + * @param mixed $priority Set priority. | |
| 627 | + * | |
| 628 | + * @return string LOG -OR- DISABLED|DEBUG|INFO|WARNING|INFO UPDATE | |
| 629 | + */ | |
| 630 | + public function get_log_text( $priority ) { | |
| 631 | + switch ( $priority ) { | |
| 632 | + case self::DISABLED: | |
| 633 | + return 'DISABLED'; | |
| 634 | + case self::DEBUG: | |
| 635 | + return 'DEBUG'; | |
| 636 | + case self::INFO: | |
| 637 | + return 'INFO'; | |
| 638 | + case self::WARNING: | |
| 639 | + return 'WARNING'; | |
| 640 | + default: | |
| 641 | + return 'SPEC LOG'; | |
| 642 | + } | |
| 643 | + } | |
| 615 | 644 | |
| 616 | - $start = 0; | |
| 617 | - if ( ! empty( $time_index ) ) { | |
| 618 | - $start = is_array( static::$time_start ) && isset( static::$time_start[ $time_index ] ) ? static::$time_start[ $time_index ] : 0; | |
| 619 | - } | |
| 645 | + /** | |
| 646 | + * Method check_log_daily() | |
| 647 | + * | |
| 648 | + * Daily checks to clear the log file. | |
| 649 | + * | |
| 650 | + * @param int $days number of days to keep logs. | |
| 651 | + */ | |
| 652 | + public function check_log_daily( $days = false ) { | |
| 620 | 653 | |
| 621 | - if ( empty( $start ) ) { | |
| 622 | - $start = is_array( static::$time_start ) && isset( static::$time_start['start'] ) ? static::$time_start['start'] : 0; | |
| 623 | - } | |
| 654 | + $enabled = $this->get_log_status(); | |
| 655 | + if ( ! $enabled ) { | |
| 656 | + return; | |
| 657 | + } | |
| 624 | 658 | |
| 625 | - if ( empty( $start ) ) { | |
| 626 | - return 0; | |
| 627 | - } | |
| 628 | - return microtime( true ) - $start; // seconds. | |
| 629 | - } | |
| 659 | + $today_m_y = date_i18n( 'd/m/Y' ); //phpcs:ignore -- local time. | |
| 660 | + // one time per day. | |
| 661 | + if ( get_option( 'mainwp_logger_check_daily' ) != $today_m_y ) { | |
| 662 | + $num_days = apply_filters( 'mainwp_logger_keep_days', 7 ); | |
| 663 | + MainWP_DB_Common::instance()->delete_action_log( $num_days ); | |
| 664 | + MainWP_Utility::update_option( 'mainwp_logger_check_daily', $today_m_y ); | |
| 665 | + } | |
| 666 | + } | |
| 630 | 667 | |
| 631 | - /** | |
| 632 | - * Method get_log_file() | |
| 633 | - * | |
| 634 | - * Grab Log File. | |
| 635 | - * | |
| 636 | - * @return mixed Log File. | |
| 637 | - */ | |
| 638 | - public function get_log_file() { | |
| 639 | - if ( empty( $this->logDirectory ) ) { | |
| 640 | - $this->logDirectory = MainWP_System_Utility::get_mainwp_dir(); | |
| 641 | - $this->logDirectory = $this->logDirectory[0]; | |
| 642 | - } | |
| 643 | - return $this->logDirectory . $this->logFileNamePrefix . $this->logFileNameSuffix; | |
| 644 | - } | |
| 668 | + /** | |
| 669 | + * Method clear_log_db() | |
| 670 | + * | |
| 671 | + * Clear the log file. | |
| 672 | + */ | |
| 673 | + public function clear_log_db() { | |
| 674 | + MainWP_DB_Common::instance()->delete_action_log(); | |
| 675 | + } | |
| 645 | 676 | |
| 646 | - /** | |
| 647 | - * Method get_log_text() | |
| 648 | - * | |
| 649 | - * Grab what type of log entry. | |
| 650 | - * | |
| 651 | - * @param mixed $priority Set priority. | |
| 652 | - * | |
| 653 | - * @return string LOG -OR- DISABLED|DEBUG|INFO|WARNING|INFO UPDATE | |
| 654 | - */ | |
| 655 | - public function get_log_text( $priority ) { | |
| 656 | - switch ( $priority ) { | |
| 657 | - case static::DISABLED: | |
| 658 | - return 'DISABLED'; | |
| 659 | - case static::DEBUG: | |
| 660 | - return 'DEBUG'; | |
| 661 | - case static::INFO: | |
| 662 | - return 'INFO'; | |
| 663 | - case static::WARNING: | |
| 664 | - return 'WARNING'; | |
| 665 | - default: | |
| 666 | - return 'SPEC LOG'; | |
| 667 | - } | |
| 668 | - } | |
| 677 | + /** | |
| 678 | + * Method clear_log() | |
| 679 | + * | |
| 680 | + * Clear the log file. | |
| 681 | + */ | |
| 682 | + public function clear_log() { | |
| 683 | + $logFile = $this->get_log_file(); | |
| 684 | + if ( ! unlink( $logFile ) ) { | |
| 685 | + $fh = fopen( $logFile, 'w' ); | |
| 686 | + if ( false === $fh ) { | |
| 687 | + return; | |
| 688 | + } | |
| 669 | 689 | |
| 670 | - /** | |
| 671 | - * Method check_log_daily() | |
| 672 | - * | |
| 673 | - * Daily checks to clear the log file. | |
| 674 | - */ | |
| 675 | - public function check_log_daily() { | |
| 676 | - $status = (int) $this->get_log_status(); | |
| 677 | - if ( 0 >= $status ) { | |
| 678 | - return; | |
| 679 | - } | |
| 690 | + fclose( $fh ); | |
| 691 | + } | |
| 692 | + } | |
| 680 | 693 | |
| 681 | - $today_m_y = date_i18n( 'd/m/Y' ); //phpcs:ignore -- local time. | |
| 682 | - // one time per day. | |
| 683 | - if ( get_option( 'mainwp_logger_check_daily' ) !== $today_m_y ) { | |
| 684 | - $num_days = apply_filters( 'mainwp_logger_keep_days', 7 ); | |
| 685 | - MainWP_DB_Common::instance()->delete_action_log( $num_days ); | |
| 686 | - MainWP_Utility::update_option( 'mainwp_logger_check_daily', $today_m_y ); | |
| 694 | + /** | |
| 695 | + * Method show_log_db() | |
| 696 | + * | |
| 697 | + * Grab log file and build output to screen. | |
| 698 | + */ | |
| 699 | + public function show_log_db() { | |
| 687 | 700 | |
| 688 | - $enabled_time = get_option( 'mainwp_actionlogs_enabled_timestamp', false ); | |
| 689 | - if ( false === $enabled_time ) { | |
| 690 | - MainWP_Utility::update_option( 'mainwp_actionlogs_enabled_timestamp', time() ); | |
| 691 | - } elseif ( $enabled_time + $num_days * DAY_IN_SECONDS < time() ) { | |
| 692 | - MainWP_Utility::update_option( 'mainwp_actionlogs', static::DISABLED ); | |
| 693 | - } | |
| 694 | - } | |
| 695 | - } | |
| 701 | + echo '<div class="ui hidden divider"></div>'; | |
| 702 | + echo '<div class="ui divided padded relaxed list" local-datetime="' . date( 'Y-m-d H:i:s' ) . '">'; // phpcs:ignore -- local time. | |
| 696 | 703 | |
| 697 | - /** | |
| 698 | - * Method clear_log_db() | |
| 699 | - * | |
| 700 | - * Clear the log file. | |
| 701 | - */ | |
| 702 | - public function clear_log_db() { | |
| 703 | - MainWP_DB_Common::instance()->delete_action_log(); | |
| 704 | - } | |
| 704 | + $rows = MainWP_DB::instance()->query( MainWP_DB_Common::instance()->get_sql_log() ); | |
| 705 | 705 | |
| 706 | - /** | |
| 707 | - * Method clear_log() | |
| 708 | - * | |
| 709 | - * Clear the log file. | |
| 710 | - */ | |
| 711 | - public function clear_log() { | |
| 712 | - $logFile = $this->get_log_file(); | |
| 713 | - wp_delete_file( $logFile ); | |
| 714 | - $fh = fopen( $logFile, 'w' ); | |
| 715 | - if ( false === $fh ) { | |
| 716 | - return; | |
| 717 | - } | |
| 718 | - fclose( $fh ); | |
| 719 | - } | |
| 706 | + $start_wrapper = '<span class="ui mini label mainwp-action-log-show-more">Click to See Response</span><div class="mainwp-action-log-site-response" style="display: none;">'; | |
| 707 | + $end_wrapper = '</div>'; | |
| 720 | 708 | |
| 721 | - /** | |
| 722 | - * Method show_log_db() | |
| 723 | - * | |
| 724 | - * Grab log file and build output to screen. | |
| 725 | - */ | |
| 726 | - public function show_log_db() { | |
| 709 | + while ( $rows && ( $row = MainWP_DB::fetch_object( $rows ) ) ) { | |
| 710 | + $type = $row->log_type; | |
| 711 | + $line = $row->log_content; | |
| 727 | 712 | |
| 728 | - echo '<div class="ui hidden divider"></div>'; | |
| 729 | - echo '<div class="ui divided padded relaxed list" local-datetime="' . date( 'Y-m-d H:i:s' ) . '">'; // phpcs:ignore -- local time. | |
| 713 | + $time = gmdate( $this->logDateFormat, $row->log_timestamp ); | |
| 730 | 714 | |
| 731 | - $rows = MainWP_DB::instance()->query( MainWP_DB_Common::instance()->get_sql_log() ); | |
| 715 | + $showInfo = $this->get_log_type_info( $row->log_type, $row->log_color ); | |
| 716 | + $currentColor = $showInfo['log_color']; | |
| 732 | 717 | |
| 733 | - $start_wrapper = '<span class="ui mini label mainwp-action-log-show-more">Click to See Response</span><div class="mainwp-action-log-site-response" style="display: none;">'; | |
| 734 | - $end_wrapper = '</div>'; | |
| 718 | + $prefix = $time . ' ' . $showInfo['log_prefix']; | |
| 735 | 719 | |
| 736 | - while ( $rows && ( $row = MainWP_DB::fetch_object( $rows ) ) ) { | |
| 737 | - $line = $row->log_content; | |
| 738 | - if ( 120 * 1024 < strlen( $line ) ) { | |
| 739 | - $line = '[Data row too long]'; | |
| 740 | - } | |
| 720 | + $line = htmlentities( $line ); | |
| 741 | 721 | |
| 742 | - $time = gmdate( $this->logDateFormat, $row->log_timestamp ); | |
| 722 | + if ( false !== strpos( $line, '[data-start]' ) ) { | |
| 723 | + $line = str_replace( '[data-start]', $start_wrapper, $line ); | |
| 724 | + $line = str_replace( '[data-end]', $end_wrapper, $line ); | |
| 725 | + } | |
| 743 | 726 | |
| 744 | - $showInfo = $this->get_log_type_info( $row->log_type, $row->log_color ); | |
| 745 | - $currentColor = $showInfo['log_color']; | |
| 727 | + echo '<div class="item" style="color:' . $currentColor . '"><div class="mainwpactionlogsline">'; | |
| 746 | 728 | |
| 747 | - $prefix = $time . ' ' . $showInfo['log_prefix']; | |
| 729 | + echo $prefix . ' ' . $line; | |
| 748 | 730 | |
| 749 | - $line = htmlentities( $line ); | |
| 731 | + echo '</div></div>'; | |
| 732 | + } | |
| 750 | 733 | |
| 751 | - if ( false !== strpos( $line, '[data-start]' ) ) { | |
| 752 | - $line = str_replace( '[data-start]', $start_wrapper, $line ); | |
| 753 | - $line = str_replace( '[data-end]', $end_wrapper, $line ); | |
| 754 | - } | |
| 734 | + echo '</div></div>'; | |
| 755 | 735 | |
| 756 | - echo '<div class="item" style="color:' . esc_html( $currentColor ) . '"><div class="mainwpactionlogsline">'; | |
| 736 | + echo '</div>'; | |
| 757 | 737 | |
| 758 | - echo $prefix . ' ' . $line; // phpcs:ignore WordPress.Security.EscapeOutput | |
| 738 | + ?> | |
| 739 | + <div class="ui large modal" id="mainwp-action-log-response-modal"> | |
| 740 | + <div class="header"><?php esc_html_e( 'Child Site Response', 'mainwp' ); ?></div> | |
| 741 | + <div class="content"> | |
| 742 | + <div class="ui info message"><?php esc_html_e( 'To see the response in a more readable way, you can copy it and paste it into some HTML render tool, such as Codepen.io.', 'mainwp' ); ?> | |
| 743 | + </div> | |
| 744 | + </div> | |
| 745 | + <div class="scrolling content content-response"></div> | |
| 746 | + <div class="actions"> | |
| 747 | + <button class="ui green button mainwp-response-copy-button"><?php esc_html_e( 'Copy Response', 'mainwp' ); ?></button> | |
| 748 | + <div class="ui cancel button mainwp-reload"><?php esc_html_e( 'Close', 'mainwp' ); ?></div> | |
| 749 | + </div> | |
| 750 | + </div> | |
| 751 | + <?php | |
| 752 | + } | |
| 759 | 753 | |
| 760 | - echo '</div></div>'; | |
| 761 | - } | |
| 754 | + /** | |
| 755 | + * Method show_log_file() | |
| 756 | + * | |
| 757 | + * Grab log file and build output to screen. | |
| 758 | + */ | |
| 759 | + public function show_log_file() { | |
| 760 | + $logFile = $this->get_log_file(); | |
| 762 | 761 | |
| 763 | - echo '</div></div>'; | |
| 762 | + if ( ! file_exists( $logFile ) ) { | |
| 763 | + return; | |
| 764 | + } | |
| 764 | 765 | |
| 765 | - echo '</div>'; | |
| 766 | + $fh = fopen( $logFile, 'r' ); | |
| 767 | + if ( false === $fh ) { | |
| 768 | + return; | |
| 769 | + } | |
| 766 | 770 | |
| 767 | - ?> | |
| 768 | - <div class="ui large modal" id="mainwp-action-log-response-modal"> | |
| 769 | - <i class="close icon mainwp-reload"></i> | |
| 770 | - <div class="header"><?php esc_html_e( 'Child Site Response', 'mainwp' ); ?></div> | |
| 771 | - <div class="content"> | |
| 772 | - <div class="ui info message"><?php esc_html_e( 'To see the response in a more readable way, you can copy it and paste it into some HTML render tool, such as Codepen.io.', 'mainwp' ); ?> | |
| 773 | - </div> | |
| 774 | - </div> | |
| 775 | - <div class="scrolling content content-response"></div> | |
| 776 | - <div class="actions"> | |
| 777 | - <button class="ui green button mainwp-response-copy-button"><?php esc_html_e( 'Copy Response', 'mainwp' ); ?></button> | |
| 778 | - </div> | |
| 779 | - </div> | |
| 780 | - <?php | |
| 781 | - } | |
| 771 | + $previousColor = ''; | |
| 772 | + $fontOpen = false; | |
| 773 | + $firstLinePassedProcessed = false; | |
| 774 | + echo '<div class="ui hidden divider"></div>'; | |
| 775 | + echo '<div class="ui divided padded relaxed list">'; | |
| 776 | + while ( false !== ( $line = fgets( $fh ) ) ) { | |
| 777 | + $currentColor = $previousColor; | |
| 778 | + if ( stristr( $line, '[DEBUG]' ) ) { | |
| 779 | + $currentColor = self::DEBUG_COLOR; | |
| 780 | + $firstLinePassed = true; | |
| 781 | + } elseif ( stristr( $line, '[INFO]' ) ) { | |
| 782 | + $currentColor = self::INFO_COLOR; | |
| 783 | + $firstLinePassed = true; | |
| 784 | + } elseif ( stristr( $line, '[WARNING]' ) ) { | |
| 785 | + $currentColor = self::WARNING_COLOR; | |
| 786 | + $firstLinePassed = true; | |
| 787 | + } elseif ( stristr( $line, '[LOG]' ) ) { | |
| 788 | + $currentColor = self::LOG_COLOR; | |
| 789 | + $firstLinePassed = true; | |
| 790 | + } else { | |
| 791 | + $firstLinePassed = false; | |
| 792 | + } | |
| 782 | 793 | |
| 783 | - /** | |
| 784 | - * Method show_log_file() | |
| 785 | - * | |
| 786 | - * Grab log file and build output to screen. | |
| 787 | - */ | |
| 788 | - public function show_log_file() { // phpcs:ignore -- NOSONAR - complex. | |
| 789 | - $logFile = $this->get_log_file(); | |
| 794 | + if ( $firstLinePassedProcessed && ! $firstLinePassed ) { | |
| 795 | + echo ' <span class="ui mini label mainwp-action-log-show-more">Click to See Response</span></div><div class="mainwp-action-log-site-response" style="display: none;">'; | |
| 796 | + } | |
| 790 | 797 | |
| 791 | - if ( ! file_exists( $logFile ) ) { | |
| 792 | - return; | |
| 793 | - } | |
| 798 | + $firstLinePassedProcessed = $firstLinePassed; | |
| 794 | 799 | |
| 795 | - $fh = fopen( $logFile, 'r' ); | |
| 796 | - if ( false === $fh ) { | |
| 797 | - return; | |
| 798 | - } | |
| 800 | + if ( $currentColor != $previousColor ) { | |
| 801 | + if ( $fontOpen ) { | |
| 802 | + echo '</div></div>'; | |
| 803 | + } | |
| 799 | 804 | |
| 800 | - $previousColor = ''; | |
| 801 | - $fontOpen = false; | |
| 802 | - $firstLinePassedProcessed = false; | |
| 803 | - echo '<div class="ui hidden divider"></div>'; | |
| 804 | - echo '<div class="ui divided padded relaxed list">'; | |
| 805 | - while ( false !== ( $line = fgets( $fh ) ) ) { | |
| 806 | - $currentColor = $previousColor; | |
| 807 | - if ( stristr( $line, '[DEBUG]' ) ) { | |
| 808 | - $currentColor = static::DEBUG_COLOR; | |
| 809 | - $firstLinePassed = true; | |
| 810 | - } elseif ( stristr( $line, '[INFO]' ) ) { | |
| 811 | - $currentColor = static::INFO_COLOR; | |
| 812 | - $firstLinePassed = true; | |
| 813 | - } elseif ( stristr( $line, '[WARNING]' ) ) { | |
| 814 | - $currentColor = static::WARNING_COLOR; | |
| 815 | - $firstLinePassed = true; | |
| 816 | - } elseif ( stristr( $line, '[LOG]' ) ) { | |
| 817 | - $currentColor = static::LOG_COLOR; | |
| 818 | - $firstLinePassed = true; | |
| 819 | - } else { | |
| 820 | - $firstLinePassed = false; | |
| 821 | - } | |
| 805 | + echo '<div class="item" style="color:' . $currentColor . '"><div class="mainwpactionlogsline">'; | |
| 806 | + $fontOpen = true; | |
| 807 | + } | |
| 822 | 808 | |
| 823 | - if ( $firstLinePassedProcessed && ! $firstLinePassed ) { | |
| 824 | - echo ' <span class="ui mini label mainwp-action-log-show-more">Click to See Response</span></div><div class="mainwp-action-log-site-response" style="display: none;">'; | |
| 825 | - } | |
| 809 | + echo htmlentities( $line ); | |
| 810 | + } | |
| 826 | 811 | |
| 827 | - $firstLinePassedProcessed = $firstLinePassed; | |
| 812 | + if ( $fontOpen ) { | |
| 813 | + echo '</div></div>'; | |
| 814 | + } | |
| 828 | 815 | |
| 829 | - if ( $currentColor !== $previousColor ) { | |
| 830 | - if ( $fontOpen ) { | |
| 831 | - echo '</div></div>'; | |
| 832 | - } | |
| 816 | + echo '</div>'; | |
| 833 | 817 | |
| 834 | - echo '<div class="item" style="color:' . esc_html( $currentColor ) . '"><div class="mainwpactionlogsline">'; | |
| 835 | - $fontOpen = true; | |
| 836 | - } | |
| 818 | + ?> | |
| 819 | + <div class="ui large modal" id="mainwp-action-log-response-modal"> | |
| 820 | + <div class="header"><?php esc_html_e( 'Child Site Response', 'mainwp' ); ?></div> | |
| 821 | + <div class="content"> | |
| 822 | + <div class="ui info message"><?php esc_html_e( 'To see the response in a more readable way, you can copy it and paste it into some HTML render tool, such as Codepen.io.', 'mainwp' ); ?> | |
| 823 | + </div> | |
| 824 | + </div> | |
| 825 | + <div class="scrolling content content-response"></div> | |
| 826 | + <div class="actions"> | |
| 827 | + <button class="ui green button mainwp-response-copy-button"><?php esc_html_e( 'Copy Response', 'mainwp' ); ?></button> | |
| 828 | + <div class="ui cancel button mainwp-reload"><?php esc_html_e( 'Close', 'mainwp' ); ?></div> | |
| 829 | + </div> | |
| 830 | + </div> | |
| 831 | + <?php | |
| 837 | 832 | |
| 838 | - echo esc_html( htmlentities( $line ) ); | |
| 839 | - } | |
| 833 | + fclose( $fh ); | |
| 834 | + } | |
| 840 | 835 | |
| 841 | - if ( $fontOpen ) { | |
| 842 | - echo '</div></div>'; | |
| 843 | - } | |
| 844 | - | |
| 845 | - echo '</div>'; | |
| 846 | - | |
| 847 | - ?> | |
| 848 | - <div class="ui large modal" id="mainwp-action-log-response-modal"> | |
| 849 | - <i class="close icon mainwp-reload"></i> | |
| 850 | - <div class="header"><?php esc_html_e( 'Child Site Response', 'mainwp' ); ?></div> | |
| 851 | - <div class="content"> | |
| 852 | - <div class="ui info message"><?php esc_html_e( 'To see the response in a more readable way, you can copy it and paste it into some HTML render tool, such as Codepen.io.', 'mainwp' ); ?> | |
| 853 | - </div> | |
| 854 | - </div> | |
| 855 | - <div class="scrolling content content-response"></div> | |
| 856 | - <div class="actions"> | |
| 857 | - <button class="ui green button mainwp-response-copy-button"><?php esc_html_e( 'Copy Response', 'mainwp' ); ?></button> | |
| 858 | - </div> | |
| 859 | - </div> | |
| 860 | - <?php | |
| 861 | - | |
| 862 | - fclose( $fh ); | |
| 863 | - } | |
| 864 | 836 | } |