Files
roi-theme/wp-content/plugins/wp-database-tools/includes/data/class-wp-database-tools-database-data-option.php
root a22573bf0b Commit inicial - WordPress Análisis de Precios Unitarios
- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 21:04:30 -06:00

211 lines
4.6 KiB
PHP
Executable File

<?php
/**
* Option class file
*
* @link https://raiolanetworks.es
* @since 1.0.0
*
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes/data
*/
/**
* Option.
*
* This class defines all code necessary to manage the Option.
*
* @since 1.0.0
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes/data
* @author Raiola Networks <info@raiolanetworks.es>
*/
class Wp_Database_Tools_Database_Data_Option 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 $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 Option.
*
* @access public
* @since 1.0.0
*
* @param Obj $option Option row data.
* @param Array $feedback Feedback array content by user meta.
*/
public function __construct( $option, $feedback ) {
parent::__construct();
// Option data.
$this->autoload = $option->autoload;
$this->extract = $this->set_extract( $option->option_value );
$this->value = htmlentities( $option->option_value );
// Common data.
$this->id = $option->option_id;
$this->name = $option->option_name;
$this->section = 'options';
$this->size = $option->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 option 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 option.
*/
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 $option Option row data.
*/
public function sum_size( $option ) {
if ( isset( $option->Data_length ) && isset( $option->Index_length ) ) {
$sum = $option->Data_length + $option->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 option 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 );
}
}