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,21 @@
<?php
require_once dirname( __FILE__ ) . '/http-header.php';
/**
* Check that a cookie value exists
*/
class Cookie_Match extends Header_Match {
public function name() {
return __( 'URL and cookie', 'redirection' );
}
public function is_match( $url ) {
if ( $this->regex ) {
$regex = new Red_Regex( $this->value, true );
return $regex->is_match( Redirection_Request::get_cookie( $this->name ) );
}
return Redirection_Request::get_cookie( $this->name ) === $this->value;
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* Perform a check against the results of a custom filter
*/
class Custom_Match extends Red_Match {
use FromNotFrom_Match;
/**
* Filter name
*
* @var string
*/
public $filter = '';
public function name() {
return __( 'URL and custom filter', 'redirection' );
}
public function save( array $details, $no_target_url = false ) {
$data = [
'filter' => isset( $details['filter'] ) ? $this->sanitize_filter( $details['filter'] ) : '',
];
return $this->save_data( $details, $no_target_url, $data );
}
public function sanitize_filter( $name ) {
$name = preg_replace( '/[^A-Za-z0-9\-_]/', '', sanitize_text_field( $name ) );
return trim( $name );
}
public function is_match( $url ) {
return apply_filters( $this->filter, false, $url );
}
public function get_data() {
return array_merge( [
'filter' => $this->filter,
], $this->get_from_data() );
}
public function load( $values ) {
$values = $this->load_data( $values );
$this->filter = isset( $values['filter'] ) ? $values['filter'] : '';
}
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* Trait to add redirect matching that adds a matched target
*/
trait FromNotFrom_Match {
/**
* Target URL if matched
*
* @var string
*/
public $url_from = '';
/**
* Target URL if not matched
*
* @var string
*/
public $url_notfrom = '';
/**
* Save data to an array, ready for serializing.
*
* @param array $details New match data.
* @param boolean $no_target_url Does the action have a target URL.
* @param array $data Existing match data.
* @return array
*/
private function save_data( array $details, $no_target_url, array $data ) {
if ( $no_target_url === false ) {
return array_merge( array(
'url_from' => isset( $details['url_from'] ) ? $this->sanitize_url( $details['url_from'] ) : '',
'url_notfrom' => isset( $details['url_notfrom'] ) ? $this->sanitize_url( $details['url_notfrom'] ) : '',
), $data );
}
return $data;
}
/**
* Get target URL for this match, depending on whether we match or not
*
* @param string $requested_url Request URL.
* @param string $source_url Redirect source URL.
* @param Red_Source_Flags $flags Redirect flags.
* @param boolean $matched Has the source been matched.
* @return string|false
*/
public function get_target_url( $requested_url, $source_url, Red_Source_Flags $flags, $matched ) {
// Action needs a target URL based on whether we matched or not
$target = $this->get_matched_target( $matched );
if ( $flags->is_regex() && $target ) {
return $this->get_target_regex_url( $source_url, $target, $requested_url, $flags );
}
return $target;
}
/**
* Return the matched target if we have matched and one exists, or return the unmatched target if not matched.
*
* @param boolean $matched Is it matched.
* @return false|string
*/
private function get_matched_target( $matched ) {
if ( $this->url_from !== '' && $matched ) {
return $this->url_from;
}
if ( $this->url_notfrom !== '' && ! $matched ) {
return $this->url_notfrom;
}
return false;
}
/**
* Load the data into the instance.
*
* @param string $values Serialized PHP data.
* @return array
*/
private function load_data( $values ) {
$values = @unserialize( $values );
if ( isset( $values['url_from'] ) ) {
$this->url_from = $values['url_from'];
}
if ( isset( $values['url_notfrom'] ) ) {
$this->url_notfrom = $values['url_notfrom'];
}
return $values;
}
/**
* Get the match data
*
* @return array<url_from: string, url_notfrom: string>
*/
private function get_from_data() {
return [
'url_from' => $this->url_from,
'url_notfrom' => $this->url_notfrom,
];
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* Trait to add redirect matching that adds a matched target
*/
trait FromUrl_Match {
/**
* URL to match against
*
* @var string
*/
public $url = '';
/**
* Save data to an array, ready for serializing.
*
* @param array $details New match data.
* @param boolean $no_target_url Does the action have a target URL.
* @param array $data Existing match data.
* @return array
*/
private function save_data( array $details, $no_target_url, array $data ) {
if ( $no_target_url === false ) {
return array_merge( [
'url' => isset( $details['url'] ) ? $this->sanitize_url( $details['url'] ) : '',
], $data );
}
return $data;
}
/**
* Get target URL for this match, depending on whether we match or not
*
* @param string $requested_url Request URL.
* @param string $source_url Redirect source URL.
* @param Red_Source_Flags $flags Redirect flags.
* @param boolean $matched Is the URL matched.
* @return string|false
*/
public function get_target_url( $requested_url, $source_url, Red_Source_Flags $flags, $matched ) {
$target = $this->get_matched_target( $matched );
if ( $flags->is_regex() && $target ) {
return $this->get_target_regex_url( $source_url, $target, $requested_url, $flags );
}
return $target;
}
/**
* Return the matched target, if one exists.
*
* @param boolean $matched Is it matched.
* @return false|string
*/
private function get_matched_target( $matched ) {
if ( $matched ) {
return $this->url;
}
return false;
}
/**
* Load the data into the instance.
*
* @param string $values Serialized PHP data.
* @return array
*/
private function load_data( $values ) {
$values = unserialize( $values );
if ( isset( $values['url'] ) ) {
$this->url = $values['url'];
}
return $values;
}
/**
* Get the loaded data as an array.
*
* @return array<url: string>
*/
private function get_from_data() {
return [
'url' => $this->url,
];
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* Check a HTTP request header
*/
class Header_Match extends Red_Match {
use FromNotFrom_Match;
/**
* HTTP header name
*
* @var String
*/
public $name = '';
/**
* HTTP header value
*
* @var String
*/
public $value = '';
/**
* Is this a regex?
*
* @var boolean
*/
public $regex = false;
public function name() {
return __( 'URL and HTTP header', 'redirection' );
}
public function save( array $details, $no_target_url = false ) {
$data = array(
'regex' => isset( $details['regex'] ) && $details['regex'] ? true : false,
'name' => isset( $details['name'] ) ? $this->sanitize_name( $details['name'] ) : '',
'value' => isset( $details['value'] ) ? $this->sanitize_value( $details['value'] ) : '',
);
return $this->save_data( $details, $no_target_url, $data );
}
public function sanitize_name( $name ) {
$name = $this->sanitize_url( sanitize_text_field( $name ) );
$name = str_replace( ' ', '', $name );
$name = preg_replace( '/[^A-Za-z0-9\-_]/', '', $name );
return trim( trim( $name, ':' ) );
}
public function sanitize_value( $value ) {
return $this->sanitize_url( sanitize_text_field( $value ) );
}
public function is_match( $url ) {
if ( $this->regex ) {
$regex = new Red_Regex( $this->value, true );
return $regex->is_match( Redirection_Request::get_header( $this->name ) );
}
return Redirection_Request::get_header( $this->name ) === $this->value;
}
public function get_data() {
return array_merge( array(
'regex' => $this->regex,
'name' => $this->name,
'value' => $this->value,
), $this->get_from_data() );
}
/**
* Load the match data into this instance.
*
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
$values = $this->load_data( $values );
$this->regex = isset( $values['regex'] ) ? $values['regex'] : false;
$this->name = isset( $values['name'] ) ? $values['name'] : '';
$this->value = isset( $values['value'] ) ? $values['value'] : '';
}
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* Check the request IP
*/
class IP_Match extends Red_Match {
use FromNotFrom_Match;
/**
* Array of IP addresses
*
* @var string[]
*/
public $ip = [];
public function name() {
return __( 'URL and IP', 'redirection' );
}
public function save( array $details, $no_target_url = false ) {
$data = array( 'ip' => isset( $details['ip'] ) && is_array( $details['ip'] ) ? $this->sanitize_ips( $details['ip'] ) : [] );
return $this->save_data( $details, $no_target_url, $data );
}
/**
* Sanitize a single IP
*
* @param string $ip IP.
* @return string|false
*/
private function sanitize_single_ip( $ip ) {
$ip = @inet_pton( trim( sanitize_text_field( $ip ) ) );
if ( $ip !== false ) {
return @inet_ntop( $ip ); // Convert back to string
}
return false;
}
/**
* Sanitize a list of IPs
*
* @param string[] $ips List of IPs.
* @return string[]
*/
private function sanitize_ips( array $ips ) {
$ips = array_map( array( $this, 'sanitize_single_ip' ), $ips );
return array_values( array_filter( array_unique( $ips ) ) );
}
/**
* Get a list of IPs that match.
*
* @param string $match_ip IP to match.
* @return string[]
*/
private function get_matching_ips( $match_ip ) {
$current_ip = @inet_pton( $match_ip );
return array_filter( $this->ip, function( $ip ) use ( $current_ip ) {
return @inet_pton( $ip ) === $current_ip;
} );
}
public function is_match( $url ) {
$matched = $this->get_matching_ips( Redirection_Request::get_ip() );
return count( $matched ) > 0;
}
public function get_data() {
return array_merge( array(
'ip' => $this->ip,
), $this->get_from_data() );
}
public function load( $values ) {
$values = $this->load_data( $values );
$this->ip = isset( $values['ip'] ) ? $values['ip'] : [];
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* Check the client language
*/
class Language_Match extends Red_Match {
use FromNotFrom_Match;
/**
* Language to check.
*
* @var String
*/
public $language = '';
public function name() {
return __( 'URL and language', 'redirection' );
}
public function save( array $details, $no_target_url = false ) {
$data = array( 'language' => isset( $details['language'] ) ? $this->sanitize_language( $details['language'] ) : '' );
return $this->save_data( $details, $no_target_url, $data );
}
/**
* Sanitize the language value to a CSV string
*
* @param string $language User supplied language strings.
* @return string
*/
private function sanitize_language( $language ) {
$parts = explode( ',', str_replace( ' ', '', sanitize_text_field( $language ) ) );
return implode( ',', $parts );
}
public function is_match( $url ) {
$matches = explode( ',', $this->language );
$requested = Redirection_Request::get_accept_language();
foreach ( $matches as $match ) {
if ( in_array( $match, $requested, true ) ) {
return true;
}
}
return false;
}
public function get_data() {
return array_merge( array(
'language' => $this->language,
), $this->get_from_data() );
}
/**
* Load the match data into this instance.
*
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
$values = $this->load_data( $values );
$this->language = isset( $values['language'] ) ? $values['language'] : '';
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* Check whether the user is logged in or out
*/
class Login_Match extends Red_Match {
/**
* Target URL when logged in.
*
* @var String
*/
public $logged_in = '';
/**
* Target URL when logged out.
*
* @var String
*/
public $logged_out = '';
public function name() {
return __( 'URL and login status', 'redirection' );
}
public function save( array $details, $no_target_url = false ) {
if ( $no_target_url ) {
return null;
}
return [
'logged_in' => isset( $details['logged_in'] ) ? $this->sanitize_url( $details['logged_in'] ) : '',
'logged_out' => isset( $details['logged_out'] ) ? $this->sanitize_url( $details['logged_out'] ) : '',
];
}
public function is_match( $url ) {
return is_user_logged_in();
}
public function get_target_url( $requested_url, $source_url, Red_Source_Flags $flags, $match ) {
$target = false;
if ( $match && $this->logged_in !== '' ) {
$target = $this->logged_in;
} elseif ( ! $match && $this->logged_out !== '' ) {
$target = $this->logged_out;
}
if ( $flags->is_regex() && $target ) {
$target = $this->get_target_regex_url( $source_url, $target, $requested_url, $flags );
}
return $target;
}
public function get_data() {
return [
'logged_in' => $this->logged_in,
'logged_out' => $this->logged_out,
];
}
/**
* Load the match data into this instance.
*
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
$values = unserialize( $values );
$this->logged_in = isset( $values['logged_in'] ) ? $values['logged_in'] : '';
$this->logged_out = isset( $values['logged_out'] ) ? $values['logged_out'] : '';
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Match the WordPress page type
*/
class Page_Match extends Red_Match {
use FromUrl_Match;
/**
* Page type
*
* @var String
*/
public $page = '404';
public function name() {
return __( 'URL and WordPress page type', 'redirection' );
}
public function save( array $details, $no_target_url = false ) {
$data = array( 'page' => isset( $details['page'] ) ? $this->sanitize_page( $details['page'] ) : '404' );
return $this->save_data( $details, $no_target_url, $data );
}
private function sanitize_page( $page ) {
return '404';
}
public function is_match( $url ) {
return is_404();
}
public function get_data() {
return array_merge( array(
'page' => $this->page,
), $this->get_from_data() );
}
/**
* Load the match data into this instance.
*
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
$values = $this->load_data( $values );
$this->page = isset( $values['page'] ) ? $values['page'] : '404';
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* Match the referrer
*/
class Referrer_Match extends Red_Match {
use FromNotFrom_Match;
/**
* Referrer
*
* @var String
*/
public $referrer = '';
/**
* Regex match?
*
* @var boolean
*/
public $regex = false;
public function name() {
return __( 'URL and referrer', 'redirection' );
}
public function save( array $details, $no_target_url = false ) {
$data = array(
'regex' => isset( $details['regex'] ) && $details['regex'] ? true : false,
'referrer' => isset( $details['referrer'] ) ? $this->sanitize_referrer( $details['referrer'] ) : '',
);
return $this->save_data( $details, $no_target_url, $data );
}
public function sanitize_referrer( $agent ) {
return $this->sanitize_url( $agent );
}
public function is_match( $url ) {
if ( $this->regex ) {
$regex = new Red_Regex( $this->referrer, true );
return $regex->is_match( Redirection_Request::get_referrer() );
}
return Redirection_Request::get_referrer() === $this->referrer;
}
public function get_data() {
return array_merge( array(
'regex' => $this->regex,
'referrer' => $this->referrer,
), $this->get_from_data() );
}
/**
* Load the match data into this instance.
*
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
$values = $this->load_data( $values );
$this->regex = isset( $values['regex'] ) ? $values['regex'] : false;
$this->referrer = isset( $values['referrer'] ) ? $values['referrer'] : '';
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* Match the server URL. Used to match requests for another domain.
*/
class Server_Match extends Red_Match {
use FromNotFrom_Match;
/**
* Server URL.
*
* @var String
*/
public $server = '';
public function name() {
return __( 'URL and server', 'redirection' );
}
public function save( array $details, $no_target_url = false ) {
$data = array( 'server' => isset( $details['server'] ) ? $this->sanitize_server( $details['server'] ) : '' );
return $this->save_data( $details, $no_target_url, $data );
}
private function sanitize_server( $server ) {
if ( strpos( $server, 'http' ) === false ) {
$server = ( is_ssl() ? 'https://' : 'http://' ) . $server;
}
$parts = wp_parse_url( $server );
if ( isset( $parts['host'] ) ) {
return $parts['scheme'] . '://' . $parts['host'];
}
return '';
}
public function is_match( $url ) {
$server = wp_parse_url( $this->server, PHP_URL_HOST );
return $server === Redirection_Request::get_server_name();
}
public function get_data() {
return array_merge( array(
'server' => $this->server,
), $this->get_from_data() );
}
/**
* Load the match data into this instance.
*
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
$values = $this->load_data( $values );
$this->server = isset( $values['server'] ) ? $values['server'] : '';
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Match the URL only.
*/
class URL_Match extends Red_Match {
/**
* URL
*
* @var String
*/
public $url = '';
public function name() {
return __( 'URL only', 'redirection' );
}
public function save( array $details, $no_target_url = false ) {
$data = isset( $details['url'] ) ? $details['url'] : '';
if ( strlen( $data ) === 0 ) {
$data = '/';
}
if ( $no_target_url ) {
return null;
}
return $this->sanitize_url( $data );
}
public function is_match( $url ) {
return true;
}
public function get_target_url( $original_url, $matched_url, Red_Source_Flags $flag, $is_matched ) {
$target = $this->url;
if ( $flag->is_regex() ) {
$target = $this->get_target_regex_url( $matched_url, $target, $original_url, $flag );
}
return $target;
}
public function get_data() {
if ( $this->url ) {
return [
'url' => $this->url,
];
}
return null;
}
public function load( $values ) {
$this->url = $values;
}
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* Match the user agent
*/
class Agent_Match extends Red_Match {
use FromNotFrom_Match;
/**
* User agent.
*
* @var String
*/
public $agent = '';
/**
* Is this a regex match?
*
* @var boolean
*/
public $regex = false;
public function name() {
return __( 'URL and user agent', 'redirection' );
}
public function save( array $details, $no_target_url = false ) {
$data = array(
'regex' => isset( $details['regex'] ) && $details['regex'] ? true : false,
'agent' => isset( $details['agent'] ) ? $this->sanitize_agent( $details['agent'] ) : '',
);
return $this->save_data( $details, $no_target_url, $data );
}
private function sanitize_agent( $agent ) {
return $this->sanitize_url( $agent );
}
public function is_match( $url ) {
if ( $this->regex ) {
$regex = new Red_Regex( $this->agent, true );
return $regex->is_match( Redirection_Request::get_user_agent() );
}
return $this->agent === Redirection_Request::get_user_agent();
}
public function get_data() {
return array_merge( array(
'regex' => $this->regex,
'agent' => $this->agent,
), $this->get_from_data() );
}
/**
* Load the match data into this instance.
*
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
$values = $this->load_data( $values );
$this->regex = isset( $values['regex'] ) ? $values['regex'] : false;
$this->agent = isset( $values['agent'] ) ? $values['agent'] : '';
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* Match a particular role or capability
*/
class Role_Match extends Red_Match {
use FromNotFrom_Match;
/**
* WordPress role or capability
*
* @var String
*/
public $role = '';
public function name() {
return __( 'URL and role/capability', 'redirection' );
}
public function save( array $details, $no_target_url = false ) {
$data = array( 'role' => isset( $details['role'] ) ? $details['role'] : '' );
return $this->save_data( $details, $no_target_url, $data );
}
public function is_match( $url ) {
return current_user_can( $this->role );
}
public function get_data() {
return array_merge( array(
'role' => $this->role,
), $this->get_from_data() );
}
/**
* Load the match data into this instance.
*
* @param string $values Match values, as read from the database (plain text or serialized PHP).
* @return void
*/
public function load( $values ) {
$values = $this->load_data( $values );
$this->role = isset( $values['role'] ) ? $values['role'] : '';
}
}