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,99 @@
<?php // phpcs:ignoreFile
use AdvancedAds\Utilities\WordPress;
/**
* Allow serving ads on external URLs.
*
* Class Advanced_Ads_Pro_Module_Ad_Server_Admin
*/
class Advanced_Ads_Pro_Module_Ad_Server_Admin {
/**
* Advanced_Ads_Pro_Module_Ad_Server_Admin constructor.
*/
public function __construct() {
// Add settings section to allow module enabling.
add_action( 'advanced-ads-settings-init', [ $this, 'settings_init' ] );
// Check if the module was enabled.
$options = Advanced_Ads_Pro::get_instance()->get_options();
if ( empty( $options['ad-server']['enabled'] ) ) {
return;
}
// Show usage information under "show all options".
add_filter( 'advanced-ads-placement-options-after-advanced', [ $this, 'add_placement_setting' ], 10, 2 );
}
/**
* Option to enable the Ad Server module.
*/
public function settings_init() {
// Add new section.
add_settings_field(
'module-ad-server',
__( 'Ad Server', 'advanced-ads-pro' ),
[ $this, 'render_settings' ],
Advanced_Ads_Pro::OPTION_KEY . '-settings',
Advanced_Ads_Pro::OPTION_KEY . '_modules-enable'
);
}
/**
* Render Ad Server module option.
*/
public function render_settings() {
$options = Advanced_Ads_Pro::get_instance()->get_options();
$module_enabled = isset( $options['ad-server']['enabled'] ) && $options['ad-server']['enabled'];
$embedding_url = isset( $options['ad-server']['embedding-url'] ) ? $options['ad-server']['embedding-url'] : '';
$block_no_referrer = ! empty( $options['ad-server']['block-no-referrer'] ); // True if option is set.
include dirname( __FILE__ ) . '/views/module-settings.php';
}
/**
* Show usage information for the ad server
*
* @param string $placement_slug Placement id.
* @param Placement $placement Placement instance.
*/
public function add_placement_setting( $placement_slug, $placement ) {
if ( ! $placement->is_type( 'server' ) ) {
return;
}
// Publically visible name of the placement. Defaults to the placement slug.
$placement_options = $placement->get_data();
$public_slug = ! empty( $placement_options['ad-server-slug'] ) ? sanitize_title( $placement_options['ad-server-slug'] ) : $placement_slug;
ob_start();
include dirname( __FILE__ ) . '/views/placement-settings.php';
$slug_content = ob_get_clean();
WordPress::render_option(
'ad-server-usage',
__( 'Public string', 'advanced-ads-pro' ),
$slug_content
);
$options = Advanced_Ads_Pro::get_instance()->get_options();
// Static URL used for the placement to deliver the content.
$url = admin_url( 'admin-ajax.php' ) . '?action=aa-server-select&p=' . $public_slug;
ob_start();
include dirname( __FILE__ ) . '/views/placement-usage.php';
$usage_content = ob_get_clean();
WordPress::render_option(
'ad-server-usage',
__( 'Usage', 'advanced-ads-pro' ),
$usage_content
);
}
}

View File

@@ -0,0 +1,4 @@
<?php
new Advanced_Ads_Pro_Module_Ad_Server_Admin();

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@@ -0,0 +1,195 @@
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use AdvancedAds\Abstracts\Ad;
use AdvancedAds\Framework\Utilities\Params;
/**
* Allow serving ads on external URLs.
*/
class Advanced_Ads_Pro_Module_Ad_Server {
/**
* Advanced_Ads_Pro_Module_Ad_Server constructor.
*/
public function __construct() {
// Register frontend AJAX calls.
add_action( 'wp_ajax_aa-server-select', [ $this, 'get_placement' ] );
add_action( 'wp_ajax_nopriv_aa-server-select', [ $this, 'get_placement' ] );
add_filter( 'advanced-ads-set-wrapper', [ $this, 'ad_wrapper' ], 10, 2 );
// Add allowed HTTP origins.
if ( wp_doing_ajax() ) {
add_filter( 'allowed_http_origins', [ $this, 'add_allowed_origins' ] );
}
}
/**
* Add a wrapper to served top level ads
*
* @param array $wrapper existing wrapper data.
* @param Ad $ad the ad.
*
* @return array
*/
public function ad_wrapper( $wrapper, $ad ) {
$placement = $ad->get_root_placement();
if ( ! $placement || ! $placement->is_type( 'server' ) ) {
return $wrapper;
}
if ( ! $ad->is_top_level() ) {
return $wrapper;
}
if ( ! is_array( $wrapper ) || ! isset( $wrapper['id'] ) ) {
$wrapper['id'] = $ad->create_wrapper_id();
}
return $wrapper;
}
/**
* Load placement content
*
* Based on Advanced_Ads_Ajax::advads_ajax_ad_select()
*/
public function get_placement() {
$options = Advanced_Ads_Pro::get_instance()->get_options();
$block_no_referrer = ! empty( $options['ad-server']['block-no-referrer'] ); // True if option is set.
// Prevent direct access through the URL.
if ( $block_no_referrer && ! Params::server( 'HTTP_REFERER' ) ) {
die( 'direct access forbidden' );
}
// Set correct frontend headers.
header( 'X-Robots-Tag: noindex,nofollow' );
header( 'Content-Type: text/html; charset=UTF-8' );
$embedding_urls = $this->get_embedding_urls();
// Cross Origin Resource Sharing.
if ( ! empty( $embedding_urls ) ) {
$embedding_urls_string = implode( ' ', $embedding_urls );
header( 'Content-Security-Policy: frame-ancestors ' . $embedding_urls_string );
foreach ( $embedding_urls as $url ) {
$parsed_url = wp_parse_url( $url );
$scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : 'https://';
header( 'Access-Control-Allow-Origin: ' . $scheme . $parsed_url['host'] );
}
}
$public_slug = Params::request( 'p', null );
if ( empty( $public_slug || ! is_string( $public_slug ) ) ) {
die( 'missing p parameter' );
}
// Get placement output by public slug.
$placement_content = $this->get_placement_output_by_public_slug( $public_slug );
include __DIR__ . '/views/frontend-template.php';
die();
}
/**
* Modify the ad object before serving
*
* @param false|string $override overridden ad output.
* @param Ad $ad the ad.
*
* @return false
*/
public function override_ad_object( $override, $ad ) {
/**
* We need to force the ad to open in a new window when the link is created through Advanced Ads. Otherwise,
* clicking the ad in an iframe would load the target page in the iframe, too.
*
* 1. The Tracking add-on has a dedicated option on the ad edit page for this.
* We are setting it to open in a new window here and ignore the options the user might have set.
*/
$ad->set_prop_temp( 'tracking.target', 'new' );
// Ignore consent settings for ad-server ads.
$ad->set_prop_temp( 'privacy.ignore-consent', 'on' );
/**
* 2. The Advanced Ads plugin adds target="_blank" based on a global option
* We change force that option to open ads in a new window by hooking into the advanced-ads-options filter below.
*/
add_filter(
'advanced-ads-options',
function ( $options ) {
$options['target-blank'] = 1;
return $options;
}
);
return false;
}
/**
* Get the content of a placement based on the public slug.
*
* @param string $public_slug placement ID or public slug.
*/
private function get_placement_output_by_public_slug( $public_slug = '' ) {
if ( '' === $public_slug ) {
return '';
}
$placement = wp_advads_get_placement( $public_slug );
// Return placement if there is one with public_slug being the placement ID.
if ( $placement ) {
add_filter( 'advanced-ads-ad-select-override-by-ad', [ $this, 'override_ad_object' ], 10, 2 );
return $placement->output();
}
// Load all placements.
$placements = wp_advads_get_placements();
// Iterate through "ad-server" placements and look for the one with the public slug.
foreach ( $placements as $placement ) {
if ( $placement->is_type( 'server' ) && $public_slug === $placement->get_prop( 'ad-server-slug' ) ) {
add_filter( 'advanced-ads-ad-select-override-by-ad', [ $this, 'override_ad_object' ], 10, 3 );
return $placement->output();
}
}
}
/**
* Add allowed HTTP origins.
* Needed for the JavaScript-based implementation of the placement.
*
* @param array $origins Allowed HTTP origins.
* @return array $origins Allowed HTTP origins.
*/
public function add_allowed_origins( $origins ) {
$embedding_urls = $this->get_embedding_urls();
if ( is_array( $embedding_urls ) && count( $embedding_urls ) ) {
$origins = array_merge( $origins, $embedding_urls );
}
return $origins;
}
/**
* Get the embedding URL array
*
* @return array $embedding_urls.
*/
public function get_embedding_urls() {
$options = Advanced_Ads_Pro::get_instance()->get_options();
$embedding_url_option = isset( $options['ad-server']['embedding-url'] ) ? $options['ad-server']['embedding-url'] : false;
$embedding_urls_raw = explode( ',', $embedding_url_option );
$embedding_urls = [];
foreach ( $embedding_urls_raw as $_url ) {
$embedding_urls[] = esc_url_raw( $_url );
}
return $embedding_urls;
}
}

View File

@@ -0,0 +1,4 @@
<?php
new Advanced_Ads_Pro_Module_Ad_Server;

View File

@@ -0,0 +1,26 @@
<?php
/**
* Template to show the ad.
*
* @package Advanced_Ads_Pro
*
* @var string $placement_content content of the placement.
* @var string $public_slug public slug or placement ID send as $_GET['p'] to allow placement-specific usage of the hooks.
*/
?>
<!DOCTYPE html>
<html>
<head>
<meta name="robots" content="noindex,nofollow">
<?php do_action( 'advanced-ads-pro-ad-server-template-head', $public_slug ); ?>
</head>
<body style="margin: 0;" >
<?php do_action( 'advanced-ads-pro-ad-server-template-after-opening-body', $public_slug ); ?>
<?php
// phpcs:ignore
echo $placement_content;
?>
<?php do_action( 'advanced-ads-pro-ad-server-template-before-closing-body', $public_slug ); ?>
</body>
</html>

View File

@@ -0,0 +1,57 @@
<?php
/**
* Render options for the Ad Server module
*
* @var string $embedding_url URL where the ad should be loaded.
* @var boolean $block_no_referrer Value of the block-no-referrer option.
*/
?>
<input name="<?php echo esc_attr( Advanced_Ads_Pro::OPTION_KEY ); ?>[ad-server][enabled]"
class="advads-has-sub-settings"
id="advanced-ads-pro-ad-server-enabled" type="checkbox" value="1" <?php checked( $module_enabled ); ?> />
<label for="advanced-ads-pro-ad-server-enabled" class="description">
<?php esc_html_e( 'Activate module.', 'advanced-ads-pro' ); ?>
</label>
<a href="https://wpadvancedads.com/ad-server-wordpress/?utm_source=advanced-ads&utm_medium=link&utm_campaign=pro-ad-server-manual'; ?>" target="_blank" class="advads-manual-link"><?php esc_html_e( 'Manual', 'advanced-ads-pro' ); ?></a>
<div class="advads-sub-settings">
<p class="description"><?php esc_html_e( 'Top level domains on which the ads will be loaded.', 'advanced-ads-pro' ); ?> <?php esc_html_e( 'Separate multiple values with a comma.', 'advanced-ads-pro' ); ?></p>
<label>
<input style="width: 90%" id="advanced-ads-pro-server-domains"
name="<?php echo esc_attr( Advanced_Ads_Pro::OPTION_KEY ); ?>[ad-server][embedding-url]" type="text"
value="<?php echo esc_html( $embedding_url ); ?>"/>
<p id="advanced-ads-pro-server-domains-error"
class="advads-notice-inline advads-error hidden"><?php esc_html_e( 'Please dont enter subdirectories.', 'advanced-ads-pro' ); ?></p>
</label>
<br/><br/>
<label>
<input name="<?php echo esc_attr( Advanced_Ads_Pro::OPTION_KEY ); ?>[ad-server][block-no-referrer]"
type="checkbox" value="1" <?php checked( $block_no_referrer ); ?> />
<?php esc_html_e( 'Prevent direct access to the placement URL.', 'advanced-ads-pro' ); ?>
</label>
</div>
<script>
// check if input is valid URLs without subdirectories
jQuery(document).ready(function () {
jQuery( '#advanced-ads-pro-server-domains' ).on( 'change', function () {
// Sudirectories are not allowed so lets just check for the / character
advanced_ads_pro_server_check_target_urls( jQuery(this).val() );
});
});
// run the check once on load.
advanced_ads_pro_server_check_target_urls( jQuery( '#advanced-ads-pro-server-domains' ).val() );
/**
* check if the URLs of the target sites are valid
* if not, show a warning
*
* @param string value of the target URL.
*/
function advanced_ads_pro_server_check_target_urls( value ) {
// is there a "/" with a preceding and following alphanumeric value then this might be a subdirectory
if ( /[a-z0-9]\/[a-z0-9]/.test( value ) ) {
jQuery('#advanced-ads-pro-server-domains-error').show();
} else {
jQuery('#advanced-ads-pro-server-domains-error').hide();
}
}
</script>

View File

@@ -0,0 +1,18 @@
<?php //phpcs:ignoreFile
/**
* Show placement related options
*
* @var string $public_slug URL where the ad placement can be accessed directly.
*/
?>
<input type="text" id="advanced-ads-pro-placement-server-slug" name="advads[placements][options][ad-server-slug]" value="<?php echo esc_attr( $public_slug ); ?>" />
<p id="advanced-ads-pro-placement-server-slug-update-message" class="advads-notice-inline advads-error hidden"><?php esc_html_e( 'Save the page to update the usage code below.', 'advanced-ads-pro' ); ?></p>
<p class="description"><?php esc_html_e( 'The name of the placement that appears in the URL and injection code.', 'advanced-ads-pro' ); ?></p>
<script>
jQuery( document ).ready( function() {
jQuery( '#advanced-ads-pro-placement-server-slug' ).on( 'change', function(){
jQuery( '#advanced-ads-pro-placement-server-slug-update-message' ).show();
});
});
</script>

View File

@@ -0,0 +1,32 @@
<?php
/**
* Show examples on how to use the ad server placement.
*
* @package AdvancedAds\Pro
*
* @var string $url URL where the ad placement can be accessed directly.
* @var string $placement_slug placement ID.
* @var string $public_slug public name of the placement.
*/
?>
<label>
<p><?php esc_html_e( 'Direct URL', 'advanced-ads-pro' ); ?></p>
<input type="text" onclick="this.select();" readonly="readonly" value="<?php echo esc_url( $url ); ?>" style="width:600px;max-width:90%;"/>
</label>
<br/><br/>
<label>
<p>iframe</p>
<input type="text" onclick="this.select();" readonly="readonly" value="<?php echo esc_html( '<iframe src="' . $url . '" scrolling="no" width="300" height="250" style="overflow: hidden;border:none;"></iframe>' ); ?>" style="width:600px;max-width:90%;"/>
</label>
<br/><br/>
<label>
<p>JavaScript</p>
<?php //phpcs:disable ?>
<textarea onclick="this.select();" readonly="readonly" style="width:600px;max-width:90%;" rows="5">
<div id="<?php echo $public_slug; ?>-box"></div>
<script>
fetch('<?php echo esc_url( $url ); ?>').then(function(e) { return e.text();}).then(function(body) { var server_parser = new DOMParser(); var doc = server_parser.parseFromString(body, "text/html"); var ad_container = doc.querySelector('div'); document.querySelector('#<?php echo $public_slug; ?>-box').innerHTML = ad_container.innerHTML; });
</script></textarea>
<?php //phpcs:enable ?>
</label>