diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-10-27 14:18:03 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-10-27 14:18:03 +0100 |
commit | 670b97c434d6bd5d3eab57d3497e45ead7746942 (patch) | |
tree | faeb0a6ebd4d3179069d869b38dbabe28b361b90 /daggerhart-openid-connect-generic/includes/openid-connect-generic-option-logger.php | |
parent | 0bfc2f4ef0216b92493e8485044686ea26142bf1 (diff) | |
download | woocommerce-taler-670b97c434d6bd5d3eab57d3497e45ead7746942.tar.gz woocommerce-taler-670b97c434d6bd5d3eab57d3497e45ead7746942.tar.bz2 woocommerce-taler-670b97c434d6bd5d3eab57d3497e45ead7746942.zip |
update plugin version
Diffstat (limited to 'daggerhart-openid-connect-generic/includes/openid-connect-generic-option-logger.php')
-rw-r--r--[-rwxr-xr-x] | daggerhart-openid-connect-generic/includes/openid-connect-generic-option-logger.php | 178 |
1 files changed, 112 insertions, 66 deletions
diff --git a/daggerhart-openid-connect-generic/includes/openid-connect-generic-option-logger.php b/daggerhart-openid-connect-generic/includes/openid-connect-generic-option-logger.php index 3ea7b1d..d61e539 100755..100644 --- a/daggerhart-openid-connect-generic/includes/openid-connect-generic-option-logger.php +++ b/daggerhart-openid-connect-generic/includes/openid-connect-generic-option-logger.php @@ -1,90 +1,132 @@ <?php /** - * Simple class for logging messages to the options table + * Plugin logging class. + * + * @package OpenID_Connect_Generic + * @category Logging + * @author Jonathan Daggerhart <jonathan@daggerhart.com> + * @copyright 2015-2020 daggerhart + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL-2.0+ + */ + +/** + * OpenID_Connect_Generic_Option_Logger class. + * + * Simple class for logging messages to the options table. + * + * @package OpenID_Connect_Generic + * @category Logging */ class OpenID_Connect_Generic_Option_Logger { - // wp option name/key + /** + * Thw WordPress option name/key. + * + * @var string + */ private $option_name; - // default message type + /** + * The default message type. + * + * @var string + */ private $default_message_type; - // the number of items to keep in the log + /** + * The number of items to keep in the log. + * + * @var int + */ private $log_limit; - // whether or not the + /** + * Whether or not logging is enabled. + * + * @var bool + */ private $logging_enabled; - // internal cache of logs + /** + * Internal cache of logs. + * + * @var array + */ private $logs; /** - * Setup the logger according to the needs of the instance + * Setup the logger according to the needs of the instance. * - * @param string $option_name - * @param string $default_message_type - * @param bool|TRUE $logging_enabled - * @param int $log_limit + * @param string $option_name The plugin log WordPress option name. + * @param string $default_message_type The log message type. + * @param bool|TRUE $logging_enabled Whether logging is enabled. + * @param int $log_limit The log entry limit. */ - function __construct( $option_name, $default_message_type = 'none', $logging_enabled = true, $log_limit = 1000 ){ + function __construct( $option_name, $default_message_type = 'none', $logging_enabled = true, $log_limit = 1000 ) { $this->option_name = $option_name; $this->default_message_type = $default_message_type; - $this->logging_enabled = (bool) $logging_enabled; - $this->log_limit = (int) $log_limit; + $this->logging_enabled = boolval( $logging_enabled ); + $this->log_limit = intval( $log_limit ); } /** - * Subscribe logger to a set of filters + * Subscribe logger to a set of filters. * - * @param $filter_names - * @param int $priority + * @param array|string $filter_names The array, or string, of the name(s) of an filter(s) to hook the logger into. + * @param int $priority The WordPress filter priority level. + * + * @return void */ - function log_filters( $filter_names, $priority = 10 ){ + function log_filters( $filter_names, $priority = 10 ) { if ( ! is_array( $filter_names ) ) { $filter_names = array( $filter_names ); } - foreach ( $filter_names as $filter ){ + foreach ( $filter_names as $filter ) { add_filter( $filter, array( $this, 'log_hook' ), $priority ); } } /** - * Subscribe logger to a set of actions + * Subscribe logger to a set of actions. + * + * @param array|string $action_names The array, or string, of the name(s) of an action(s) to hook the logger into. + * @param int $priority The WordPress action priority level. * - * @param $action_names - * @param $priority + * @return void */ - function log_actions( $action_names, $priority ){ + function log_actions( $action_names, $priority ) { if ( ! is_array( $action_names ) ) { $action_names = array( $action_names ); } - foreach ( $action_names as $action ){ + foreach ( $action_names as $action ) { add_filter( $action, array( $this, 'log_hook' ), $priority ); } } /** - * Log the data + * Log the data. + * + * @param mixed $arg1 The hook argument. * - * @param null $arg1 - * @return null + * @return mixed */ - function log_hook( $arg1 = null ){ + function log_hook( $arg1 = null ) { $this->log( func_get_args(), current_filter() ); return $arg1; } /** - * Save an array of data to the logs + * Save an array of data to the logs. + * + * @param mixed $data The data to be logged. + * @param mixed $type The type of log message. * - * @param $data mixed * @return bool */ public function log( $data, $type = null ) { - if ( (bool) $this->logging_enabled ) { + if ( boolval( $this->logging_enabled ) ) { $logs = $this->get_logs(); $logs[] = $this->make_message( $data, $type ); $logs = $this->upkeep_logs( $logs ); @@ -95,12 +137,12 @@ class OpenID_Connect_Generic_Option_Logger { } /** - * Retrieve all log messages + * Retrieve all log messages. * * @return array */ public function get_logs() { - if ( is_null( $this->logs ) ) { + if ( empty( $this->logs ) ) { $this->logs = get_option( $this->option_name, array() ); } @@ -108,41 +150,40 @@ class OpenID_Connect_Generic_Option_Logger { } /** - * Get the name of the option where this log is stored + * Get the name of the option where this log is stored. * * @return string */ - public function get_option_name(){ + public function get_option_name() { return $this->option_name; } /** - * Create a message array containing the data and other information + * Create a message array containing the data and other information. * - * @param $data mixed - * @param $type + * @param mixed $data The log message data. + * @param mixed $type The log message type. * * @return array */ - private function make_message( $data, $type ){ - // determine the type of message + private function make_message( $data, $type ) { + // Determine the type of message. if ( empty( $type ) ) { - $this->default_message_type; + $type = $this->default_message_type; - if ( is_array( $data ) && isset( $data['type'] ) ){ + if ( is_array( $data ) && isset( $data['type'] ) ) { $type = $data['type']; - } - else if ( is_wp_error( $data ) ){ + } else if ( is_wp_error( $data ) ) { $type = $data->get_error_code(); } } - // construct our message + // Construct the message. $message = array( 'type' => $type, 'time' => time(), 'user_ID' => get_current_user_id(), - 'uri' => preg_replace('/code=([^&]+)/i', 'code=', $_SERVER['REQUEST_URI']), + 'uri' => preg_replace( '/code=([^&]+)/i', 'code=', $_SERVER['REQUEST_URI'] ), 'data' => $data, ); @@ -150,54 +191,59 @@ class OpenID_Connect_Generic_Option_Logger { } /** - * Keep our log count under the limit + * Keep the log count under the limit. + * + * @param array $logs The plugin logs. * - * @param $message array - extra data about the message * @return array */ private function upkeep_logs( $logs ) { $items_to_remove = count( $logs ) - $this->log_limit; - if ( $items_to_remove > 0 ){ - // keep only the last $log_limit messages from the end - $logs = array_slice( $logs, ( $items_to_remove * -1) ); + if ( $items_to_remove > 0 ) { + // Only keep the last $log_limit messages from the end. + $logs = array_slice( $logs, ( $items_to_remove * -1 ) ); } return $logs; } /** - * Save the log messages + * Save the log messages. + * + * @param array $logs The array of log messages. * - * @param $logs * @return bool */ - private function save_logs( $logs ){ - // save our logs + private function save_logs( $logs ) { + // Save the logs. $this->logs = $logs; return update_option( $this->option_name, $logs, false ); } /** - * Clear all log messages + * Clear all log messages. + * + * @return void */ - public function clear_logs(){ + public function clear_logs() { $this->save_logs( array() ); } /** - * Get a simple html table of all the logs + * Get a simple html table of all the logs. + * + * @param array $logs The array of log messages. * - * @param array $logs * @return string */ - public function get_logs_table( $logs = array() ){ + public function get_logs_table( $logs = array() ) { if ( empty( $logs ) ) { $logs = $this->get_logs(); } $logs = array_reverse( $logs ); - ini_set( 'xdebug.var_display_max_depth', -1 ); + ini_set( 'xdebug.var_display_max_depth', '-1' ); ob_start(); ?> @@ -216,19 +262,19 @@ class OpenID_Connect_Generic_Option_Logger { <tr> <td class="col-details"> <div> - <label><?php _e( 'Type' ); ?>: </label> + <label><?php _e( 'Type', 'daggerhart-openid-connect-generic' ); ?>: </label> <?php print $log['type']; ?> </div> <div> - <label><?php _e( 'Date' ); ?>: </label> - <?php print date( 'Y-m-d H:i:s', $log['time'] ); ?> + <label><?php _e( 'Date', 'daggerhart-openid-connect-generic' ); ?>: </label> + <?php print gmdate( 'Y-m-d H:i:s', $log['time'] ); ?> </div> <div> - <label><?php _e( 'User' ); ?>: </label> + <label><?php _e( 'User', 'daggerhart-openid-connect-generic' ); ?>: </label> <?php print ( get_userdata( $log['user_ID'] ) ) ? get_userdata( $log['user_ID'] )->user_login : '0'; ?> </div> <div> - <label><?php _e( 'URI ' ); ?>: </label> + <label><?php _e( 'URI ', 'daggerhart-openid-connect-generic' ); ?>: </label> <?php print $log['uri']; ?> </div> </td> |