*/ class Wp_Database_Tools_Database_Data_Transient extends Wp_Database_Tools_Database_Data { /** * The general data of database. * * @since 1.0.0 * @access protected * @var array $autoload The general data of database. */ protected $expired; /** * The general data of database. * * @since 1.0.0 * @access protected * @var array $autoload The general data of database. */ protected $autoload; /** * The general data of database. * * @since 1.0.0 * @access protected * @var array $extract The general data of database. */ protected $extract; /** * Constructor * * Create the instance of a transient. * * @access public * @since 1.0.0 * * @param Obj $transient Transient row data. * @param Array $feedback Feedback array content by user meta. */ public function __construct( $transient, $feedback ) { parent::__construct(); // transient data. $this->autoload = $transient->autoload; $this->extract = $this->set_extract( $transient->transient_value ); $this->value = htmlentities( $transient->transient_value ); // Common data. $this->id = $transient->transient_id; $this->name = $transient->transient_name; $this->section = 'transients'; $this->size = $transient->size; $this->format_size = $this->get_file_size_info( $this->size ); $this->format_size = $this->format_size['size'] . '' . $this->format_size['type']; $this->set_feedback( $feedback ); $this->check_regex(); } /** * Determine whether to display the integer value or an extract in * case the length is greater than a certain number * * @access public * @since 1.0.0 * * @param String $value The transient value. */ public function set_extract( $value ) { return ( strlen( $value ) > 16 ) ? substr( esc_attr( wp_strip_all_tags( $value ) ), 0, 16 ) . '...' : ''; } /** * Converts bit size to a readable format * * @access public * @since 1.0.0 * * @param int $file_size The size transient. */ public function get_file_size_info( $file_size ) { $bytes = array( 'B', 'KB', 'MB', 'GB', 'TB' ); if ( $file_size < 1024 ) { $file_size = 1; } for ( $i = 0; $file_size > 1024; $i++ ) { $file_size /= 1024; } $db_size_info['size'] = round( $file_size, 2 ); $db_size_info['type'] = $bytes[ $i ]; return $db_size_info; } /** * Adds the size of a record * * @access public * @since 1.0.0 * * @param Obj $transient transient row data. */ public function sum_size( $transient ) { if ( isset( $transient->Data_length ) && isset( $transient->Index_length ) ) { $sum = $transient->Data_length + $transient->Index_length; } else { $sum = 0; } return $sum; } /** * Set true the multiple attribute * * @access public * @since 1.0.0 */ public function set_multiple() { $this->multiple = true; } /** * We found that the transient does not conform to certain patterns. * If it does meet a pattern we set the regex property. * This is done so that no such records are stored in the database, * but the regex is simply stored as a string. * * @access public * @since 1.0.0 */ public function check_regex() { $this->set_regex( false ); // Regex wpseo. if ( str_starts_with( $this->name, 'wpseo_sitemap_' ) ) { $pattern = '/wpseo_sitemap_([0-9]+)_cache_validator/i'; if ( preg_match( $pattern, $this->name ) ) { $this->set_regex( 'wpseo_sitemap_{regex}_cache_validator' ); } } // Regex updraft_lock_. if ( str_starts_with( $this->name, 'updraft_lock_' ) ) { $pattern = '/updraft_lock_([a-z0-9]{12})/i'; if ( preg_match( $pattern, $this->name ) ) { $this->set_regex( 'updraft_lock_{regex}' ); } } // Regex jetpack_nonce_. if ( str_starts_with( $this->name, 'jetpack_nonce_' ) ) { $pattern = '/jetpack_nonce_([0-9]{10})_([a-z0-9]{10})/i'; if ( preg_match( $pattern, $this->name ) ) { $this->set_regex( 'jetpack_nonce_{regex}_{regex}' ); } } } /** * Return the autoload attribute. * * @access public * @since 1.0.0 * * @return string this->autoload The autoload attribute. */ public function get_autoload() { return $this->autoload; } /** * Return attributes as an array * * @access public * @since 1.0.0 * * @return Array Array attributes. */ public function return_object_vars() { return get_object_vars( $this ); } }