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,232 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class TD_REST_Controller
*
* - Base REST controller for TD
*/
class TD_REST_Controller extends WP_REST_Controller {
/**
* The base of this controller's route.
*
* @since 4.7.0
* @var string
*/
protected $rest_base;
protected $namespace = 'td/v1';
protected $webhook_base = '/webhook/trigger';
public function __construct() {
}
public function get_namespace() {
return $this->namespace;
}
public function get_webhook_base() {
return $this->webhook_base;
}
/**
* Registers routes for basic controller
*/
public function register_routes() {
register_rest_route(
$this->namespace,
$this->rest_base . '/authenticate',
array(
'methods' => WP_REST_Server::EDITABLE,
'callback' => array( $this, 'authenticate' ),
'permission_callback' => array( $this, 'permission_callback' ),
'args' => $this->route_args(),
)
);
register_rest_route( $this->namespace, $this->webhook_base . '/(?P<api>\S+)/(?P<id>\d+)/(?P<code>\S+)', array(
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array( $this, 'webhook_trigger' ),
'permission_callback' => '__return_true',
),
) );
register_rest_route( $this->namespace, $this->rest_base . '/license_warning', array(
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array( $this, 'license_warning' ),
'permission_callback' => array( $this, 'permission_callback_license_warning' ),
),
) );
}
/**
* Args required by routes that need permission
* @return array[]
*/
public function route_args() {
return array(
'api_key' => array(
'type' => 'string',
'required' => true,
'validate_callback' => static function ( $param ) {
return ! empty( $param );
},
),
);
}
public static function license_warning( $request ) {
$product = $request->get_param( 'product' );
$transient = 'tve_license_warning_lightbox_' . $product;
set_transient( $transient, true, DAY_IN_SECONDS );
return $product;
}
/**
* callback function
*
* @param WP_REST_Response
*/
public static function webhook_trigger( $request ) {
$id = $request->get_param( 'id' );
$api = $request->get_param( 'api' );
$code = $request->get_param( 'code' );
$data = array();
if ( $api === 'general' ) {
$data = tve_dash_get_general_webhook_data( $request );
} else {
$api_instance = Thrive_Dash_List_Manager::connection_instance( $api );
if ( $api_instance ) {
$data = $api_instance->get_webhook_data( $request );
}
}
if ( empty( $data['email'] ) ) {
global $wpdb;
$log_data = array(
'date' => gmdate( 'Y-m-d H:i:s' ),
'error_message' => 'No email inside webhook payload',
'api_data' => serialize( tve_sanitize_data_recursive( $request ) ),
'connection' => $api,
'list_id' => 'asset',
);
$wpdb->insert( $wpdb->prefix . 'tcb_api_error_log', $log_data );
}
return apply_filters( 'tve_dash_webhook_trigger', $id, $code, $data );
}
/**
* @return mixed|WP_REST_Response
*/
public function authenticate() {
return rest_ensure_response(
array(
'connected' => true,
)
);
}
/**
* Verifies each call to TD REST API
*
* @param $request
*
* @return bool|WP_Error
*/
public function permission_callback( $request ) {
return $this->validate_api_key( $request->get_param( 'api_key' ) );
}
/**
* Verifies each call to TD REST API
*
* @param $request
*
* @return bool|WP_Error
*/
public function permission_callback_license_warning( $request ) {
return $this->validate_license_warning( $request->get_param( 'product' ) );
}
/**
* Checks if the api_key sent as parameter is the same with the one generated in DB
*
* @param $api_key
*
* @return bool|WP_Error
*/
protected function validate_api_key( $api_key = '' ) {
$generated_api_key = get_option( 'td_api_key', null );
/* make sure we don't send an empty api_key */
if ( ! empty( $api_key ) && $generated_api_key === $api_key ) {
$result = true;
} else {
$result = new WP_Error(
'wrong_api_key_provided',
__( 'Provided API Key is wrong', 'thrive-dash' ),
array(
'api_key' => $api_key,
)
);
}
return $result;
}
/**
* Checks if the product is sent as parameter
*
* @param $api_key
*
* @return bool|WP_Error
*/
protected function validate_license_warning( $product = '' ) {
$result = true;
$products = [
'tcb',
'tl',
'tu',
'tvo',
'tqb',
'tcm',
'tva',
'tab',
'ttb'
];
if ( empty( $product ) || ! in_array( $product, $products, true ) ) {
$result = new WP_Error(
'no_product_provided',
__( 'No product identifier provided', 'thrive-dash' ),
array(
'product' => $product,
)
);
}
return $result;
}
}

View File

@@ -0,0 +1,325 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class TD_REST_Hook_Controller
*
* Used to implement Zapier Integration but it can be extended
* For further REST Hooks
*/
class TD_REST_Hook_Controller extends TD_REST_Controller {
/**
* The base of this controller's route.
*
* @since 4.7.0
* @var string
*/
protected $rest_base;
/**
* REST Hook Name
* - saves the webhook based on this name
*
* @var string
*/
protected $_hook_name;
/**
* Needed to decide webhook's name
*
* @var string
*/
protected $_hook_prefix = 'td_';
/**
* Needed to decide webhook's name
*
* @var string
*/
protected $_hook_suffix = '_webhook';
/**
* TD_REST_Hook_Controller constructor.
*
* @param string $hook_name
*/
public function __construct( $hook_name = '' ) {
parent::__construct();
$this->_hook_name = (string) $hook_name;
$this->rest_base = trailingslashit( $hook_name ) . 'subscription';
}
/**
* Register routes
*/
public function register_routes() {
register_rest_route(
$this->namespace,
$this->rest_base,
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'subscribe' ),
'permission_callback' => array( $this, 'permission_callback' ),
'args' => $this->route_args(),
)
);
register_rest_route(
$this->namespace,
$this->rest_base . '/sample',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'sample' ),
'permission_callback' => array( $this, 'permission_callback' ),
)
);
register_rest_route(
$this->namespace,
$this->rest_base . '/specific_form_data',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'specific_form_data' ),
'permission_callback' => array( $this, 'permission_callback' ),
)
);
register_rest_route(
$this->namespace,
$this->rest_base,
array(
'methods' => WP_REST_Server::DELETABLE,
'callback' => array( $this, 'unsubscribe' ),
'permission_callback' => array( $this, 'permission_callback' ),
'args' => $this->route_args(),
)
);
register_rest_route(
$this->namespace,
$this->rest_base . '/all_lg_forms',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'all_lg_forms' ),
'permission_callback' => array( $this, 'permission_callback' ),
)
);
}
/**
* The endpoint where the Integration subscribes the webhook
*
* @param WP_REST_Request $request
*
* @return array|WP_Error
*/
public function subscribe( $request ) {
// Param from Lead Generation auth
$hook_url = $request->get_param( 'hook_url' );
// Param from Contact Form auth
if ( ! $hook_url ) {
$hook_url = $request->get_param( 'hookUrl' );
}
if ( filter_var( $hook_url, FILTER_VALIDATE_URL ) ) {
update_option( $this->_get_option_name(), $hook_url );
$result = array(
'id' => $this->_get_option_name(),
);
} else {
$result = new WP_Error( 'td_invalid_hook_url', __( 'Invalid Hook URL', 'thrive-dash' ) );
}
return $result;
}
/**
* The endpoint where the Integration unsubscribes the webhook
*
* @return true
*/
public function unsubscribe() {
/**
* Mind that if option does not exist false is return by delete_option()
*/
delete_option( $this->_get_option_name() );
return true;
}
/**
* Required endpoint for creating the trigger in Zapier
* provide a sample of fields and data
*
* @return mixed|WP_REST_Response
*/
public function sample() {
// For LG Subscription
$response_sample = array(
array(
'name' => 'Full name',
'email' => 'name@email.com',
'phone' => '1231231231',
'ip_address' => '192.168.1.1',
'tags' => array(
'tag1',
'tag2',
'tag3',
),
'message' => array(
'message1',
'message2',
'message3',
),
'number' => '123.45',
'date' => '24/09/2024',
'website' => 'https://yourwebsite.com/',
'source_url' => 'https://thrivethemes.com',
'thriveleads_group' => 'Group 1',
'thriveleads_type' => 'Lightbox',
'thriveleads_name' => 'First Lightbox',
),
);
// For CF Subscription [DEPRECATED should be removed when considering that old CF forms are no longer connected on the users side]
if ( 'cf-optin' === $this->_hook_name ) {
$response_sample = array(
array(
'first_name' => 'First name',
'last_name' => 'Last name',
'full_name' => 'Full name',
'email' => 'name@email.com',
'message' => 'Sample message',
'phone' => '1231231231',
'website' => 'https://yourwebsite.com/',
'source_url' => 'https://thrivethemes.com',
'ip_address' => '192.168.1.1',
'tags' => array( 'tag1', 'tag2', 'tag3' ),
),
);
}
return rest_ensure_response( $response_sample );
}
/**
* Required endpoint for creating the trigger in Zapier
* provide fields and data from specific form subscription
*
* @return mixed|WP_REST_Response
*/
public function specific_form_data() {
$response_array = array();
$form_id = ! empty( $_GET['form_id'] ) ? sanitize_text_field( $_GET['form_id'] ) : '';
if ( ! empty( $form_id ) ) {
// get all fields using the form_id from postmeta table.
global $wpdb;
$query = $wpdb->prepare(
"SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '%s'",
'_tve_lead_gen_form_'.$form_id
);
$results = $wpdb->get_results( $query, ARRAY_A );
if ( ! empty( $results ) ) {
foreach ( $results as $row ) {
$meta_value = unserialize( $row['meta_value'] ) ?? [];
$inputs = $meta_value['inputs'] ?? [];
// Format/Rename all the fields.
$messages = array();
$checkbox_count = 1;
$file_url_count = 1;
foreach ( $inputs as $input ) {
if ( strpos( $input['id'], 'mapping_textarea_' ) === 0 ) {
$messages[] = $input['label'];
} elseif ( strpos( $input['id'], 'mapping_checkbox_' ) === 0 ) {
$response_array[ 'checkbox_' . $checkbox_count ] = $input['label'];
$checkbox_count++;
} elseif ( strpos( $input['id'], 'mapping_file_' ) === 0 ) {
$response_array[ 'file_url_' . $file_url_count ] = $input['label'];
$file_url_count++;
} else {
$response_array[ $input['id'] ] = $input['label'];
}
}
if ( ! empty( $messages ) ) {
$response_array['message'] = $messages;
}
}
}
}
// For LG Subscription.
$response_sepcific_form_data = array(
$response_array,
);
return rest_ensure_response( $response_sepcific_form_data );
}
/**
* Uses hook's prefix, name, suffix to establish the option name
* to save the webhook
*
* @return string
*/
protected function _get_option_name() {
return $this->_hook_prefix . $this->_hook_name . $this->_hook_suffix;
}
/**
* Get list of all the LG forms in the site
*
* @return mixed|WP_REST_Response
*/
public function all_lg_forms() {
global $wpdb;
$query = $wpdb->prepare(
"SELECT wpm.meta_key, wpm.meta_value, wp.post_title
FROM $wpdb->postmeta as wpm, $wpdb->posts as wp
WHERE wpm.post_id = wp.ID AND wpm.meta_key LIKE '_tve_lead_gen_form\_%'
ORDER BY wp.post_title"
);
$results = $wpdb->get_results( $query, ARRAY_A );
$response_forms = [];
if ( ! empty( $results ) ) {
foreach ( $results as $row ) {
$meta_value = unserialize( $row['meta_value'] ) ?? [];
$apis = $meta_value['apis'] ?? [];
if( ! empty( $apis ) && in_array( 'zapier', $apis, true ) ) {
$response_forms[] = [
'id' => $row['meta_key'] ? str_replace( '_tve_lead_gen_form_', '', $row['meta_key'] ) : '',
'name' => $row['post_title'] ?? '',
];
}
}
}
return rest_ensure_response( $response_forms );
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Created by PhpStorm.
* User: dan bilauca
* Date: 23-Jul-19
* Time: 01:28 PM
*
* Initializes the REST Controllers under /wp-json/td
* - which are public and used atm by Zapier
*/
require TVE_DASH_PATH . '/rest-api/class-td-rest-controller.php';
require TVE_DASH_PATH . '/rest-api/class-td-rest-hook-controller.php';
add_action( 'rest_api_init', 'tve_dash_init_rest_controllers' );
/**
* Register routes for different built triggers [LG/CF for the moment]
*/
function tve_dash_init_rest_controllers() {
$rest_controller = new TD_REST_Controller();
$rest_controller->register_routes();
// Register LG routes
$zapier_subscribe = new TD_REST_Hook_Controller( 'optin' );
$zapier_subscribe->register_routes();
// Register CF routes
$zapier_subscribe = new TD_REST_Hook_Controller( 'cf-optin' );
$zapier_subscribe->register_routes();
}
function tve_dash_generate_api_key() {
$key = implode( '-', str_split( substr( strtolower( md5( microtime() . rand( 1000, 9999 ) ) ), 0, 30 ), 6 ) );
return $key;
}