PK N\c9D6 manager.phpnu W+A get_log_type_from_php_error( $last_error['type'] ); $last_error['trace'] = true; $item = new PHP( $last_error ); $this->get_logger()->log( $item ); } public function add_system_info_report() { System_Info::add_report( 'log', [ 'file_name' => __DIR__ . '/log-reporter.php', 'class_name' => __NAMESPACE__ . '\Log_Reporter', ] ); } /** * Javascript log. * * Log Elementor errors and save them in the database. * * Fired by `wp_ajax_elementor_js_log` action. * */ public function js_log() { /** @var Module $ajax */ $ajax = Plugin::$instance->common->get_component( 'ajax' ); if ( ! $ajax->verify_request_nonce() || empty( $_POST['data'] ) ) { wp_send_json_error(); } array_walk_recursive( $_POST['data'], function( &$value ) { $value = sanitize_text_field( $value ); } ); foreach ( $_POST['data'] as $error ) { $error['type'] = Logger_Interface::LEVEL_ERROR; if ( ! empty( $error['customFields'] ) ) { $error['meta'] = $error['customFields']; } $item = new JS( $error ); $this->get_logger()->log( $item ); } wp_send_json_success(); } public function register_logger( $name, $class ) { $this->loggers[ $name ] = $class; } public function set_default_logger( $name ) { if ( ! empty( $this->loggers[ $name ] ) ) { $this->default_logger = $name; } } public function register_default_loggers() { $this->register_logger( 'db', 'Elementor\Core\Logger\Loggers\Db' ); $this->set_default_logger( 'db' ); } /** * @param string $name * * @return Logger_Interface */ public function get_logger( $name = '' ) { $this->register_loggers(); if ( empty( $name ) || ! isset( $this->loggers[ $name ] ) ) { $name = $this->default_logger; } if ( ! $this->get_component( $name ) ) { $this->add_component( $name, new $this->loggers[ $name ]() ); } return $this->get_component( $name ); } /** * @param string $message * @param array $args * * @return void */ public function log( $message, $args = [] ) { $this->get_logger()->log( $message, $args ); } /** * @param string $message * @param array $args * * @return void */ public function info( $message, $args = [] ) { $this->get_logger()->info( $message, $args ); } /** * @param string $message * @param array $args * * @return void */ public function notice( $message, $args = [] ) { $this->get_logger()->notice( $message, $args ); } /** * @param string $message * @param array $args * * @return void */ public function warning( $message, $args = [] ) { $this->get_logger()->warning( $message, $args ); } /** * @param string $message * @param array $args * * @return void */ public function error( $message, $args = [] ) { $this->get_logger()->error( $message, $args ); } private function get_log_type_from_php_error( $type ) { $error_map = [ E_CORE_ERROR => Logger_Interface::LEVEL_ERROR, E_ERROR => Logger_Interface::LEVEL_ERROR, E_USER_ERROR => Logger_Interface::LEVEL_ERROR, E_COMPILE_ERROR => Logger_Interface::LEVEL_ERROR, E_RECOVERABLE_ERROR => Logger_Interface::LEVEL_ERROR, E_PARSE => Logger_Interface::LEVEL_ERROR, E_STRICT => Logger_Interface::LEVEL_ERROR, E_WARNING => Logger_Interface::LEVEL_WARNING, E_USER_WARNING => Logger_Interface::LEVEL_WARNING, E_CORE_WARNING => Logger_Interface::LEVEL_WARNING, E_COMPILE_WARNING => Logger_Interface::LEVEL_WARNING, E_NOTICE => Logger_Interface::LEVEL_NOTICE, E_USER_NOTICE => Logger_Interface::LEVEL_NOTICE, E_DEPRECATED => Logger_Interface::LEVEL_NOTICE, E_USER_DEPRECATED => Logger_Interface::LEVEL_NOTICE, ]; return isset( $error_map[ $type ] ) ? $error_map[ $type ] : Logger_Interface::LEVEL_ERROR; } private function register_loggers() { if ( ! did_action( 'elementor/loggers/register' ) ) { do_action( 'elementor/loggers/register', $this ); } } public function __construct() { register_shutdown_function( [ $this, 'shutdown' ] ); add_action( 'admin_init', [ $this, 'add_system_info_report' ], 80 ); add_action( 'wp_ajax_elementor_js_log', [ $this, 'js_log' ] ); add_action( 'elementor/loggers/register', [ $this, 'register_default_loggers' ] ); } } PK N\\6Sa items/base.phpnu W+A date = current_time( 'mysql' ); $this->message = ! empty( $args['message'] ) ? esc_html( $args['message'] ) : ''; $this->type = ! empty( $args['type'] ) ? $args['type'] : 'info'; $this->meta = ! empty( $args['meta'] ) ? $args['meta'] : []; $this->args = $args; $this->set_trace(); } public function __get( $name ) { if ( property_exists( $this, $name ) ) { return $this->{$name}; } return ''; } public function __toString() { $vars = get_object_vars( $this ); return strtr( static::FORMAT, $vars ); } public function jsonSerialize() { return [ 'class' => get_class( $this ), 'item' => [ 'date' => $this->date, 'message' => $this->message, 'type' => $this->type, 'meta' => $this->meta, 'times' => $this->times, 'times_dates' => $this->times_dates, 'args' => $this->args, ], ]; } public function deserialize( $properties ) { $this->date = ! empty( $properties['date'] ) && is_string( $properties['date'] ) ? $properties['date'] : ''; $this->message = ! empty( $properties['message'] ) && is_string( $properties['message'] ) ? $properties['message'] : ''; $this->type = ! empty( $properties['type'] ) && is_string( $properties['type'] ) ? $properties['type'] : ''; $this->meta = ! empty( $properties['meta'] ) && is_array( $properties['meta'] ) ? $properties['meta'] : []; $this->times = ! empty( $properties['times'] ) && is_string( $properties['times'] ) ? $properties['times'] : ''; $this->times_dates = ! empty( $properties['times_dates'] ) && is_array( $properties['times_dates'] ) ? $properties['times_dates'] : []; $this->args = ! empty( $properties['args'] ) && is_array( $properties['args'] ) ? $properties['args'] : []; } /** * @return Log_Item_Interface | null */ public static function from_json( $str ) { $obj = json_decode( $str, true ); if ( ! array_key_exists( 'class', $obj ) ) { return null; } $class = $obj['class']; if ( class_exists( $class ) ) { /** @var Base $item */ $item = new $class( $obj['item']['message'] ); $item->deserialize( $obj['item'] ); return $item; } return null; } public function to_formatted_string( $output_format = 'html' ) { $vars = get_object_vars( $this ); $format = static::FORMAT; if ( 'html' === $output_format ) { $format = str_replace( 'message', 'message', static::FORMAT ); } if ( empty( $vars['meta'] ) ) { $format = str_replace( '[meta]', '', $format ); } else { $vars['meta'] = stripslashes( var_export( $vars['meta'], true ) ); // @codingStandardsIgnoreLine } return strtr( $format, $vars ); } public function get_fingerprint() { $unique_key = $this->type . $this->message . var_export( $this->meta, true ); // @codingStandardsIgnoreLine //info messages are not be aggregated: if ( 'info' === $this->type ) { $unique_key .= $this->date; } return md5( $unique_key ); } public function increase_times( $item, $truncate = true ) { $this->times++; $this->times_dates[] = $item->date; if ( $truncate && ( self::MAX_LOG_ENTRIES < count( $this->times_dates ) ) ) { $this->times_dates = array_slice( $this->times_dates, -self::MAX_LOG_ENTRIES ); } } public function format( $format = 'html' ) { $trace = $this->format_trace(); if ( empty( $trace ) ) { return $this->to_formatted_string( $format ); } $copy = clone $this; $copy->meta['trace'] = $trace; return $copy->to_formatted_string( $format ); } public function get_name() { return 'Log'; } private function format_trace() { $trace = empty( $this->meta['trace'] ) ? '' : $this->meta['trace']; if ( is_string( $trace ) ) { return $trace; } $trace_str = ''; foreach ( $trace as $key => $trace_line ) { $format = static::TRACE_FORMAT; $trace_line['key'] = $key; if ( empty( $trace_line['file'] ) ) { $format = str_replace( 'file(line): ', '', $format ); } $trace_str .= PHP_EOL . strtr( $format, $trace_line ); $trace_str .= empty( $trace_line['args'] ) ? '' : var_export( $trace_line['args'], true ); // @codingStandardsIgnoreLine } return $trace_str . PHP_EOL; } private function set_trace() { if ( ! empty( $this->args['trace'] ) && true === $this->args['trace'] ) { $limit = empty( $this->args['trace_limit'] ) ? static::TRACE_LIMIT : $this->args['trace_limit']; $stack = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); // @codingStandardsIgnoreLine while ( ! empty( $stack ) && ! empty( $stack[0]['file'] ) && ( false !== strpos( $stack[0]['file'], 'core' . DIRECTORY_SEPARATOR . 'logger' ) ) ) { array_shift( $stack ); } $this->meta['trace'] = array_slice( $stack, 0, $limit ); return; } if ( is_array( $this->args ) ) { unset( $this->args['trace'] ); } } } PK N\ items/file.phpnu W+A file = empty( $args['file'] ) ? '' : $args['file']; $this->line = empty( $args['line'] ) ? '' : $args['line']; } public function jsonSerialize() { $json_arr = parent::jsonSerialize(); $json_arr['file'] = $this->file; $json_arr['line'] = $this->line; return $json_arr; } public function deserialize( $properties ) { parent::deserialize( $properties ); $this->file = ! empty( $properties['file'] ) && is_string( $properties['file'] ) ? $properties['file'] : ''; $this->line = ! empty( $properties['line'] ) && is_string( $properties['line'] ) ? $properties['line'] : ''; } public function get_name() { return 'File'; } } PK N\빡 items/php.phpnu W+A column = $args['column']; $this->file = $args['url']; $this->date = gmdate( 'Y-m-d H:i:s', $args['timestamp'] ); } public function jsonSerialize() { $json_arr = parent::jsonSerialize(); $json_arr['column'] = $this->column; return $json_arr; } public function deserialize( $properties ) { parent::deserialize( $properties ); $this->column = ! empty( $properties['column'] ) && is_string( $properties['column'] ) ? $properties['column'] : ''; } public function get_name() { return 'JS'; } } PK N\+ԆS S loggers/base.phpnu W+A create_item( $item, $type, $args ); } $this->save_log( $item ); } public function info( $message, $args = [] ) { $this->log( $message, self::LEVEL_INFO, $args ); } public function notice( $message, $args = [] ) { $this->log( $message, self::LEVEL_NOTICE, $args ); } public function warning( $message, $args = [] ) { $this->log( $message, self::LEVEL_WARNING, $args ); } public function error( $message, $args = [] ) { $this->log( $message, self::LEVEL_ERROR, $args ); } /** * @param string $message * @param string $type * @param array $args * * @return Log_Item_Interface */ private function create_item( $message, $type, $args = [] ) { $args['message'] = $message; $args['type'] = $type; $item = new Log_Item( $args ); return $item; } public function get_formatted_log_entries( $max_entries, $table = true ) { $entries = $this->get_log(); if ( empty( $entries ) ) { return [ 'All' => [ 'total_count' => 0, 'count' => 0, 'entries' => '', ], ]; } $sorted_entries = []; $open_tag = $table ? '