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>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
<?php
/**
* Author class file
*
* @link https://raiolanetworks.es
* @since 1.0.0
*
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes/data
*/
/**
* Author.
*
* This class defines all code necessary to manage the Author.
*
* @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_Author {
/**
* The id of the Author.
*
* @since 1.0.0
* @access protected
* @var string $id The id of the Author.
*/
protected $id;
/**
* The name of the Author.
*
* @since 1.0.0
* @access protected
* @var string $name The name of the Author.
*/
protected $name;
/**
* The url of the Author.
*
* @since 1.0.0
* @access protected
* @var string $url The name of the Author.
*/
protected $url;
/**
* Constructor
*
* Create the instance of a Author.
*
* @access public
* @since 1.0.0
*/
public function __construct() {
$this->id = str_shuffle( 'abcdefABCDEF' ) . '-' . rand( 1000, 2000 );
$this->name = 'Unknown';
$this->url = null;
}
/**
* Set object attributes via API information
*
* @access public
* @since 1.0.0
*
* @param Object $api_data Object obtained from API information.
*/
public function set_author_by_api( $api_data ) {
$this->id = $api_data->id;
$this->name = $api_data->author ?? $api_data->user_nicname ?? null;
$this->url = $api_data->profile ?? $api_data->author_url ?? null;
}
/**
* Set object attributes via algorithm
*
* @access public
* @since 1.0.0
*
* @param Array $algorithm_data Array returning the identification algorithm.
*/
public function set_author_by_algorithm( $algorithm_data ) {
$this->name = $data_algorithm['author'] ?? $data_algorithm['author_name'] ?? null;
$this->url = $data_algorithm['author_url'] ?? null;
}
/**
* 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 );
}
}

View File

@@ -0,0 +1,153 @@
<?php
/**
* Database functions
*
* @link https://raiolanetworks.es
* @since 1.0.0
*
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes
*/
/**
* Contains the functionalities related to database management.
*
* This class defines all code necessary to manage the database functionalities.
*
* @since 1.0.0
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes
* @author Raiola Networks <info@raiolanetworks.es>
*/
class Wp_Database_Tools_Database_Data_Cronjob extends Wp_Database_Tools_Database_Data {
/**
* The schedule of cronjob.
*
* @since 1.0.0
* @access protected
* @var array $schedule The schedule of cronjob.
*/
protected $schedule;
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var array $display The general data of database.
*/
protected $display;
/**
* The args of cronjob.
*
* @since 1.0.0
* @access protected
* @var array $args The args of cronjob.
*/
protected $args;
/**
* The interval of cronjob.
*
* @since 1.0.0
* @access protected
* @var array $interval The interval of cronjob.
*/
protected $interval;
/**
* Next run of cronjob.
*
* @since 1.0.0
* @access protected
* @var array $next_run Next run of cronjob.
*/
protected $next_run;
/**
* The timestamp of cronjob.
*
* @since 1.0.0
* @access protected
* @var array $timestamp The timestamp of cronjob.
*/
protected $timestamp;
/**
* Constructor
*
* Create the instance of a Marketplace.
*
* @access public
* @since 1.0.0
*
* @param Array $schedules Schedules.
* @param int $timestamp Timestamp.
* @param string $event_hook Event_hook name.
* @param Array $events Events.
* @param Object $event Event.
* @param Array $feedback Feedback info.
*/
public function __construct( $schedules, $timestamp, $event_hook, $events, $event, $feedback ) {
parent::__construct();
$args_value = '';
foreach ( $event['args'] as $key => $arg ) {
$args_value .= $arg . ' ';
}
// Cronjob data.
$this->schedule = empty( $event['schedule'] ) ? '-' : $event['schedule'];
$this->display = $schedules[ $event['schedule'] ]['display'] ?? '';
$this->args_array = ( ! empty( $args_value ) ) ? $event['args'] : '';
$this->args = $args_value;
$this->interval = isset( $event['interval'] ) ? $event['interval'] : 0;
$this->next_run = ( $timestamp ) ? date( 'Y-m-d H:i:s', $timestamp ) : '-';
$this->timestamp = ( $timestamp ) ? $timestamp : 0;
$this->section = 'cronjobs';
// Common data.
$this->id = trim( $event_hook . '↔' . htmlspecialchars( json_encode( $event['args'] ) ) . '↔' . $timestamp );
$this->name = $event_hook;
$this->set_feedback( $feedback );
$this->check_regex();
}
/**
* Set true the regex attribute
*
* @access public
* @since 1.0.0
*/
public function check_regex() {
// Parent method.
$this->set_regex( false );
}
/**
* Set true the multiple attribute
*
* @access public
* @since 1.0.0
*/
public function set_multiple() {
$this->multiple = true;
}
/**
* 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 );
}
}

View File

@@ -0,0 +1,126 @@
<?php
/**
* Marketplace class file
*
* @link https://raiolanetworks.es
* @since 1.0.0
*
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes/data
*/
/**
* Marketplace.
*
* This class defines all code necessary to manage the Marketplace.
*
* @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_Marketplace {
/**
* The id of the marketplace.
*
* @since 1.0.0
* @access protected
* @var string $id Id of the marketplace.
*/
protected $id;
/**
* The name of the marketplace.
*
* @since 1.0.0
* @access protected
* @var string $name The name of the marketplace.
*/
protected $name;
/**
* The slug of the marketplace.
*
* @since 1.0.0
* @access protected
* @var string $slug The slug of the marketplace.
*/
protected $slug;
/**
* The url of marketplace.
*
* @since 1.0.0
* @access protected
* @var string $homepage The url of marketplace.
*/
protected $homepage;
/**
* The image of marketplace.
*
* @since 1.0.0
* @access protected
* @var string $image The image of marketplace.
*/
protected $image;
/**
* Constructor
*
* Create the instance of a Marketplace.
*
* @access public
* @since 1.0.0
*/
public function __construct() {
$this->id = str_shuffle( 'abcdefABCDEF' ) . '-' . rand( 1000, 2000 );
$this->name = 'Unknown';
$this->slug = 'unknown-marketplace';
$this->homepage = null;
$this->image = null;
}
/**
* Set object attributes via API information
*
* @access public
* @since 1.0.0
*
* @param Object $api_data Object obtained from API information.
*/
public function set_marketplace_by_api( $api_data ) {
$this->id = $api_data->id ?? $this->id;
$this->name = $api_data->name ?? $this->name;
$this->slug = $api_data->slug;
$this->homepage = $api_data->homepage;
$this->image = $api_data->image;
}
/**
* Set object attributes via algorithm
*
* @access public
* @since 1.0.0
*
* @param Array $algorithm_data Array returning the identification algorithm.
*/
public function set_marketplace_by_algorithm( $algorithm_data ) {
$this->name = $data_algorithm['marketplace'] ?? 'Unknown';
$this->url = sanitize_title( $algorithm_data['marketplace'] ) ?? 'unknown-marketplace';
}
/**
* 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 );
}
}

View File

@@ -0,0 +1,210 @@
<?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 );
}
}

View File

@@ -0,0 +1,511 @@
<?php
/**
* Option class file
*
* @link https://raiolanetworks.es
* @since 1.0.0
*
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes/data
*/
/**
* Origin.
*
* This class defines all code necessary to manage the Origin.
*
* @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_Origin {
/**
* The id of Origin.
*
* @since 1.0.0
* @access protected
* @var string $id The id of Origin.
*/
protected $id;
/**
* The name of Origin.
*
* @since 1.0.0
* @access protected
* @var string $name The name of Origin.
*/
protected $name;
/**
* The type of Origin.
*
* @since 1.0.0
* @access protected
* @var string $type uncategorized|plugin|theme.
*/
protected $type;
/**
* The search term of Origin.
*
* @since 1.0.0
* @access protected
* @var string $search The search term of Origin.
*/
protected $search;
/**
* The slug term of Origin.
*
* @since 1.0.0
* @access protected
* @var string $slug The slug term of Origin.
*/
protected $slug;
/**
* The warning of Origin.
*
* When an origin is detected by the algorithm the warning attribute is set to yes.
*
* @since 1.0.0
* @access protected
* @var string $warning yes|no.
*/
protected $warning;
/**
* The homepage of Origin.
*
* @since 1.0.0
* @access protected
* @var string $homepage The website of the Origin.
*/
protected $homepage;
/**
* The download url of Origin.
*
* @since 1.0.0
* @access protected
* @var string $download_link The download url of Origin.
*/
protected $download_link;
/**
* The rating of Origin.
*
* @since 1.0.0
* @access protected
* @var string $rating The rating of Origin.
*/
protected $rating;
/**
* The status of Origin.
*
* @since 1.0.0
* @access protected
* @var string $status active|inactive|uninstall|unknown.
*/
protected $status;
/**
* The current version of Origin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of Origin.
*/
protected $version;
/**
* The reliability of Origin.
*
* @since 1.0.0
* @access protected
* @var int $reliability The reliability of Origin.
*/
protected $reliability;
/**
* The reliability level of Origin.
*
* @since 1.0.0
* @access protected
* @var int $reliability_level low|medium|hight.
*/
protected $reliability_level;
/**
* The question feedback origin.
*
* @since 1.0.0
* @access protected
* @var array $question The question feedback origin.
*/
protected $question;
/**
* The total likes.
*
* @since 1.0.0
* @access protected
* @var int $likes The total likes.
*/
protected $likes;
/**
* The total dislikes.
*
* @since 1.0.0
* @access protected
* @var int $dislikes The total dislikes.
*/
protected $dislikes;
/**
* The author of Origin.
*
* @since 1.0.0
* @access protected
* @var Wp_Database_Tools_Database_Data_Author $author The author of Origin.
*/
protected $author;
/**
* The Marketplace of Origin.
*
* @since 1.0.0
* @access protected
* @var Wp_Database_Tools_Database_Data_Marketplace $marketplace The Marketplace of Origin.
*/
protected $marketplace;
/**
* Constructor
*
* Create the instance of a Origin.
*
* @access public
* @since 1.0.0
*/
public function __construct() {
$this->id = 'uncategorized';
$this->search = 'Uncategorized';
$this->name = 'Uncategorized';
$this->type = 'uncategorized';
$this->status = 'unknown';
$this->slug = '-';
$this->rating = '-';
$this->download_link = '';
$this->homepage = '';
$this->dislikes = 0;
$this->likes = 0;
$this->author = new Wp_Database_Tools_Database_Data_Author();
$this->marketplace = new Wp_Database_Tools_Database_Data_Marketplace();
}
/**
* Set object attributes via API information
*
* @access public
* @since 1.0.0
*
* @param Object $api_data Object obtained from API information.
* @param string $section The section of data.
*/
public function set_origin_by_api( $api_data, $section ) {
// Dynamic access property.
if ( 'tables' === $section ) {
$morph = 'tableable';
}
if ( 'options' === $section ) {
$morph = 'optionable';
}
if ( 'transients' === $section ) {
$morph = 'transientable';
}
if ( 'cronjobs' === $section ) {
$morph = 'cronable';
}
$source = $api_data['source'];
$origin = $api_data['origin'];
// Set the origin fields.
$this->type = $source->{$morph . '_type'} ?? $this->type;
if ( 'uncategorized' !== $this->type ) {
$this->type = strtolower( str_replace( 'App\Models\\', '', $this->type ) );
}
$this->id = ( 'core' === $this->type ) ? 'wordpress-core' : $origin->slug ?? $this->id;
$this->name = ( 'core' === $this->type ) ? __( 'WordPress Core', 'wp-database-tools' ) : $origin->custom_name ?? $origin->name ?? $this->slug;
$this->search = ( 'core' === $this->type ) ? 'WordPress Core' : $origin->slug ?? $this->slug;
$this->homepage = ( 'core' === $this->type ) ? 'https://es.wordpress.org/' : $origin->homepage ?? $this->homepage;
$this->download_link = ( 'core' === $this->type ) ? 'https://wordpress.org/latest.zip' : $origin->download_link ?? $this->download_link;
$this->slug = ( 'core' === $this->type ) ? '-' : $origin->slug ?? $this->slug;
$this->warning = 'no';
$this->rating = $origin->rating ?? $this->rating;
$this->reliability = $source->reliability ?? $this->reliability;
$this->reliability_level = $this->calculate_reliability_level( $this->reliability );
$this->dislikes = $source->dislikes;
$this->likes = $source->likes;
$this->author->set_author_by_api( $api_data['author'] );
$this->marketplace->set_marketplace_by_api( $api_data['marketplace'] );
}
/**
* Set object attributes via algorithm
*
* @access public
* @since 1.0.0
*
* @param Array $data_algorithm Array returning the identification algorithm.
*/
public function set_origin_by_algorithm( $data_algorithm ) {
// Set origin fields.
$this->id = $data_algorithm['origin']['slug'] ?? $data_algorithm['origin']['name'];
$this->version = $data_algorithm['origin']['version'];
$this->name = $data_algorithm['origin']['name'];
$this->search = $data_algorithm['origin']['slug'];
$this->slug = $data_algorithm['origin']['slug'];
$this->type = $data_algorithm['type'];
$this->warning = 'yes';
$this->reliability = $this->calculate_match_porcent( $data_algorithm['length'], $data_algorithm['match'] );
$this->reliability_level = $this->calculate_reliability_level( $this->reliability );
$this->author->set_author_by_algorithm( $data_algorithm['origin'] );
$this->marketplace->set_marketplace_by_algorithm( $data_algorithm['origin'] );
}
/**
* Set the selection of origins in the frontend (choices) by passing
* the data through admin ajax.
*
* @access public
* @since 1.0.0
*
* @param Array $choices Array returning choices.
*/
public function check_choices( $choices ) {
if ( 'uncategorized' !== $this->type && 'core' !== $this->type ) {
$index = ( 'plugin' === $this->type ) ? 1 : 2;
$value = $this->name . '$' . $this->type . '$' . $this->warning;
$label = ( 'no' === $this->warning )
? $this->name
: '<div class="d-flex-start"><img class="mr-5" width="15px" src="' . WPDBT_ADMIN_URL . 'img/warning.svg">' . $this->name . '</div>';
$key = array_search( $value, array_column( $choices[ $index ]['choices'], 'value' ) );
if ( false === $key ) {
$data = array(
'value' => $value,
'label' => $label,
'selected' => false,
);
array_push( $choices[ $index ]['choices'], $data );
}
}
return $choices;
}
/**
* Set the selection of origins in the frontend (choices) by passing
* the data through admin ajax.
*
* @access public
* @since 1.0.0
*
* @param Array $plugins Array with all plugins.
* @param Array $themes Array with all themes.
*/
public function set_status( $plugins, $themes ) {
if ( 'plugin' === $this->type ) {
$key = array_search(
$this->slug,
array_filter(
array_combine(
array_keys( $plugins ),
array_column(
$plugins,
'slug'
)
)
)
);
if ( false === $key ) {
$this->status = 'uninstalled';
return;
}
$this->status = $plugins[ $key ]['status'];
return;
}
if ( 'theme' === $this->type ) {
if ( isset( $themes[ $this->slug ] ) ) {
$this->status = $themes[ $this->slug ]['status'];
return;
}
$this->status = 'uninstalled';
return;
}
if ( 'core' === $this->type ) {
$this->status = 'active';
return;
}
$this->status = 'unknown';
}
/**
* Calculate the match porcent.
*
* @access public
* @since 1.0.0
*
* @param string $length length.
* @param string $match match.
*/
protected function calculate_match_porcent( $length, $match ) {
if ( $match > $length ) {
return 90;
}
return ( $match * 100 ) / 25;
}
/**
* Return the level string.
*
* @access public
* @since 1.0.0
*
* @param int $level the puntuation of reliability.
*
* @return string The string indicates by level.
*/
protected function calculate_reliability_level( $level ) {
if ( $level < 50 ) {
return 'low';
}
if ( $level >= 50 && $level <= 70 ) {
return 'medium';
}
if ( $level > 70 ) {
return 'hight';
}
}
/**
* Return the author of Origin.
*
* @access public
* @since 1.0.0
*
* @return Wp_Database_Tools_Database_Data_Author $author The author of Origin.
*/
public function get_author() {
return $this->author;
}
/**
* Return the marketplace of Origin.
*
* @access public
* @since 1.0.0
*
* @return Wp_Database_Tools_Database_Data_Marketplace $marketplace The marketplace of Origin.
*/
public function get_marketplace() {
return $this->marketplace;
}
/**
* Return the type of Origin.
*
* @access public
* @since 1.0.0
*
* @return string $type The type of Origin.
*/
public function get_type() {
return $this->type;
}
/**
* Set the question attribute
*
* @access public
* @since 1.0.0
*
* @param string $name the name of source.
*/
public function set_question( $name ) {
$quote = str_contains( strtolower( WPDBT_CURRENT_LANG ), 'es' ) ? '¿' : '';
$this->question = $quote . '<strong>' . $name . '</strong> ' . __( 'belongs to this', 'wp-database-tools' ) . ' ' . $this->get_type() . '?';
}
/**
* Set the question attribute
*
* @access public
* @since 1.0.0
*
* @param Wp_Database_Tools_Database_Data_Author $value The author.
*/
public function set_author( $value ) {
$this->author = $value;
}
/**
* Set the question attribute
*
* @access public
* @since 1.0.0
*
* @param Wp_Database_Tools_Database_Data_Marketplace $value The marketplace.
*/
public function set_marketplace( $value ) {
$this->marketplace = $value;
}
/**
* 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 );
}
}

View File

@@ -0,0 +1,113 @@
<?php
/**
* Database functions
*
* @link https://raiolanetworks.es
* @since 1.0.0
*
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes
*/
/**
* Contains the functionalities related to database management.
*
* This class defines all code necessary to manage the database functionalities.
*
* @since 1.0.0
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes
* @author Raiola Networks <info@raiolanetworks.es>
*/
class Wp_Database_Tools_Database_Data_Table extends Wp_Database_Tools_Database_Data
{
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var int $data The general data of database.
*/
protected $row;
/**
* Indicates if the table is prefixed or not
*
* @since 1.0.0
* @access protected
* @var boolean $prefix Table has prefix.
*/
protected $prefix;
/**
* Table name without prefix
*
* @since 1.0.0
* @access protected
* @var string $name_without_prefix Table name without prefix.
*/
protected $name_without_prefix;
public function __construct($table, $feedback)
{
parent::__construct();
global $wpdb;
// table data
$this->row = $table->Rows;
// Common data
$this->name = $table->Name;
$this->id = $this->name;
$this->section = 'tables';
$this->size = $this->sum_size($table);
$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();
$this->set_prefix($table->Name, $wpdb->prefix);
}
public function check_regex(){
$this->set_regex(false);
}
public function set_multiple($value){
$this->multiple = true;
}
public function return_object_vars(){
return get_object_vars($this);
}
public function set_prefix($name, $prefix){
if (str_starts_with($name, $prefix)) {
$this->name_without_prefix = substr($name, strlen($prefix));
}else{
$this->name_without_prefix = $name;
}
$this->prefix = ($prefix . $this->name_without_prefix == $name);
}
public function get_name()
{
return ($this->prefix) ? $this->name_without_prefix : $this->name;
}
public function get_name_without_prefix()
{
return $this->name_without_prefix;
}
}

View File

@@ -0,0 +1,219 @@
<?php
/**
* transient class file
*
* @link https://raiolanetworks.es
* @since 1.0.0
*
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes/data
*/
/**
* transient.
*
* This class defines all code necessary to manage the transient.
*
* @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_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 );
}
}

View File

@@ -0,0 +1,260 @@
<?php
/**
* Database functions
*
* @link https://raiolanetworks.es
* @since 1.0.0
*
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes
*/
/**
* Contains the functionalities related to database management.
*
* This class defines all code necessary to manage the database functionalities.
*
* @since 1.0.0
* @package Wp_Database_Tools
* @subpackage Wp_Database_Tools/includes
* @author Raiola Networks <info@raiolanetworks.es>
*/
class Wp_Database_Tools_Database_Data {
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var int $likes The general data of database.
*/
protected $id;
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var int $likes The general data of database.
*/
protected $name;
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var int $dislikes The general data of database.
*/
protected $feedback;
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var array $data The general data of database.
*/
protected $multiple;
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var Wp_Database_Tools_Database_Data_Origin $origin The general data of database.
*/
public $origin;
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var array $data The general data of database.
*/
protected $check;
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var array $data The general data of database.
*/
protected $size;
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var array $data The general data of database.
*/
protected $format_size;
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var array $data The general data of database.
*/
protected $section;
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var array $data The general data of database.
*/
protected $regex;
/**
* The general data of database.
*
* @since 1.0.0
* @access protected
* @var array $data The general data of database.
*/
protected $value;
public function __construct() {
$admin_url = plugin_dir_url( __DIR__ ) . 'admin/';
$this->origin = new Wp_Database_Tools_Database_Data_Origin();
$this->multiple = false;
$this->reliability = '-';
$this->check = false;
}
public function get_matching_data( $matching, $plugins, $themes, $name ) {
$data_value = null;
if ( $this->section == 'options' ) {
$data_value = ( $this->value == '' ) ? null : $this->value;
}
$slug_concidence_plugins = $matching->find_match( 'plugin', $name, $data_value );
$slug_concidence_themes = $matching->find_match( 'theme', $name, $data_value );
$concidence = false;
if ( ! empty( $slug_concidence_plugins ) && ! empty( $slug_concidence_themes ) ) {
// Set the better coincidence
$type = ( $slug_concidence_plugins['match'] >= $slug_concidence_themes['match'] ) ? 'plugin' : 'theme';
$coincidence_data = ( $type == 'plugin' ) ? $slug_concidence_plugins : $slug_concidence_themes;
$concidence = true;
} elseif ( ! empty( $slug_concidence_plugins ) ) {
$type = 'plugin';
$coincidence_data = $slug_concidence_plugins;
$concidence = true;
} elseif ( ! empty( $slug_concidence_themes ) ) {
$type = 'theme';
$coincidence_data = $slug_concidence_themes;
$concidence = true;
}
if ( $concidence == true ) {
if ( $type == 'plugin' ) {
$key = array_search( $coincidence_data['slug'], array_column( $plugins, 'slug' ) );
$data['origin'] = $plugins[ array_keys( $plugins )[ $key ] ];
}
if ( $type == 'theme' ) {
$key = array_search( $coincidence_data['slug'], array_column( $themes, 'slug' ) );
$data['origin'] = $themes[ array_keys( $themes )[ $key ] ];
}
if ( is_null( $data['origin'] ) ) {
return null;
}
$data['type'] = $type;
$data['length'] = strlen( $coincidence_data['slug'] );
$data['match'] = $coincidence_data['match'];
return $data;
} else {
return null;
}
}
public function set_feedback( $feedback ) {
if ( isset( $feedback ) ) {
$feedback = (array) $feedback;
$this->feedback = isset( $feedback[ $this->name ] );
} else {
$this->feedback = false;
}
}
public function set_data_by_algorithm( $data_algorithm ) {
$this->origin->set_origin_by_algorithm( $data_algorithm );
}
public function sum_size( $row ) {
if ( isset( $row->Data_length ) && isset( $row->Index_length ) ) {
$sum = $row->Data_length + $row->Index_length;
} else {
$sum = 0;
}
return $sum;
}
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;
}
public function get_name() {
return $this->name;
}
public function get_size() {
return $this->size;
}
public function get_origin() {
return $this->origin;
}
public function get_regex() {
return $this->regex;
}
public function set_origin( $value ) {
$this->origin = $value;
}
public function set_regex( $value ) {
$this->regex = $value;
}
}