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,92 @@
<?php
namespace WPDRMS\ASP\Api\Rest0;
use WP_Error, WP_REST_Request, WPDRMS\ASP\Patterns\SingletonTrait;
class Rest {
use SingletonTrait;
/**
* The Rest Namespace with version code
*
* @var string
*/
private $namespace = 'ajax-search-pro/v0';
/**
* Route information
*
* @var string[][]
*/
private $routes = array(
'/woo_search' => array(
'methods' => 'GET',
'handler' => 'RouteWooSearch'
),
'/search' => array(
'methods' => 'GET',
'handler' => 'RouteSearch'
)
);
/**
* Init process
*
* @return bool
*/
function init(): bool {
if ( defined('ASP_DISABLE_REST') && ASP_DISABLE_REST ) {
return false;
} else {
add_action('rest_api_init', array($this, 'registerRoutes'));
}
return true;
}
/**
* Registering the routes
*/
function registerRoutes() {
foreach ( $this->routes as $route => $data ) {
register_rest_route($this->namespace, $route, array(
'methods' => $data['methods'],
'callback' => array( $this, 'route'),
'permission_callback' => '__return_true'
));
}
}
/**
* Handles the request route
*
* @param WP_REST_Request $request
* @return array|WP_Error
*/
function route( WP_REST_Request $request ) {
$route = str_replace($this->namespace . '/', '', $request->get_route());
if ( isset($this->routes[$route]) ) {
if ( !$this->securityCheck( $request ) ) {
return new WP_Error(
'401',
esc_html__( 'Not Authorized', 'ajax-search-pro' ),
array( 'status' => 401 )
);
} else {
// PHP 7.4 support, the $class name has to be put into a variable first
$class = __NAMESPACE__ . '\\' . $this->routes[$route]['handler'];
return (new $class)->handle($request);
}
} else {
return new WP_Error(
'400',
esc_html__( 'Route error', 'ajax-search-pro' ),
array( 'status' => 400 )
);
}
}
/** @noinspection PhpUnusedParameterInspection */
private function securityCheck($request ): bool {
return true;
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace WPDRMS\ASP\API\REST0;
use WP_REST_Request;
interface RouteInterface {
public function handle( WP_REST_Request $request );
}

View File

@@ -0,0 +1,75 @@
<?php
namespace WPDRMS\ASP\Api\Rest0;
use ASP_Post;
use WP_Post;
use WP_REST_Request;
use WPDRMS\ASP\Query\SearchQuery;
class RouteSearch implements RouteInterface {
private $args, $params;
/**
* Handles the Search Route
*
* @param WP_REST_Request $request
* @return WP_Post[]|ASP_Post[]
*/
function handle( WP_REST_Request $request ): array {
$defaults = $this->args = array(
's' => '',
'id' => -1,
'is_wp_json' => true,
'posts_per_page' => 9999,
);
$this->params = $request->get_params();
foreach ( $defaults as $k => $v ) {
if ( isset($this->params[ $k ]) && $this->params[ $k ] !== null ) {
$this->args[ $k ] = $this->params[ $k ];
}
}
$search_id = $this->args['id'];
// id does not exist in SearchQueryArgs constructor
unset($this->args['id']);
$this->getPostTypeArgs();
$this->getTaxonomyArgs();
$this->getPostMetaArgs();
$this->getExclusionArgs();
$this->getInclusionArgs();
$this->args = apply_filters('asp_rest_search_query_args', $this->args, $search_id, $request);
$asp_query = new SearchQuery($this->args, $search_id);
return $asp_query->posts;
}
private function getTaxonomyArgs(): void {
// Post taxonomy filter
if ( isset($this->params['post_tax_filter']) ) {
$this->args['post_tax_filter'] = array();
foreach ( $this->params['post_tax_filter'] as $taxonomy => $terms ) {
if ( taxonomy_exists($taxonomy) && is_array($terms) && count($terms) ) {
$this->args['post_tax_filter'][] = array(
'taxonomy' => $taxonomy,
'include' => array_map('intval', $terms),
'allow_empty' => false,
);
}
}
}
}
private function getPostTypeArgs(): void {
}
private function getPostMetaArgs(): void {
}
private function getExclusionArgs(): void {
}
private function getInclusionArgs(): void {
}
}

View File

@@ -0,0 +1,48 @@
<?php
namespace WPDRMS\ASP\Api\Rest0;
use WP_REST_Request;
use WPDRMS\ASP\Query\SearchQuery;
class RouteWooSearch implements RouteInterface {
function handle( WP_REST_Request $request): array {
$defaults = $args = array(
's' => '',
'id' => -1,
'is_wp_json' => true,
'posts_per_page' => 9999
);
foreach ($defaults as $k => $v) {
$param = $request->get_param($k);
if ( $param !== null ) {
$args[$k] = $param;
}
}
if ( $args['id'] == -1 ) {
// Fetch the search ID, which is probably the WooCommerce search
foreach (wd_asp()->instances->get() as $instance) {
if ( in_array('product', $instance['data']['customtypes']) ) {
$args['id'] = $instance['id'];
break;
}
}
}
// No search was found with products enabled, set it explicitly
if ( $args['id'] == -1 ) {
$args['post_type'] = array('product');
}
$search_id = $args['id'];
// id does not exist in SearchQueryArgs constructor
unset( $args['id']);
$args = apply_filters('asp_rest_woo_search_query_args', $args, $search_id, $request);
$asp_query = new SearchQuery($args, $search_id);
return $asp_query->posts;
}
}

View File

@@ -0,0 +1,84 @@
<?php /** @noinspection PhpLanguageLevelInspection */
namespace WPDRMS\ASP\Api\Swagger;
use OpenApi\Attributes as OA;
#[OA\Schema]
class ASP_Data {
#[OA\Property]
/**
* Title including advanced title field data
*/
public string $title;
#[OA\Property]
/**
* Result ID
*/
public int $id;
#[OA\Property]
/**
* Result blog ID
*/
public ?int $blogid;
#[OA\Property]
/**
* Result blog ID
*/
public string $date;
#[OA\Property]
/**
* Content including advanced title field data
*/
public string $content;
#[OA\Property]
/**
* Excerpt data
*/
public ?string $excerpt;
#[OA\Property]
/**
* Post type
*/
public ?string $post_type;
#[OA\Property]
/**
* Content type
*
* @var "pagepost"|"user"|"term"|"blog"|"bp_group"|"bp_activity"|"comment"
*/
public string $content_type;
#[OA\Property]
/**
* Author
*/
public ?string $author;
#[OA\Property]
/**
* URL of the search result when search ID is not set
*/
public ?string $asp_guid;
#[OA\Property]
/**
* URL of the search result when search ID is set
*/
public ?string $url;
#[OA\Property]
/**
* Image URL when search ID is set
*
* @var string
*/
public ?string $image;
}

View File

@@ -0,0 +1,54 @@
<?php /** @noinspection PhpLanguageLevelInspection */
/**
* Swagger related stuff, to make it easy all is in this directory.
* This code is not used anywhere, it's only for swagger generator.
*/
namespace WPDRMS\ASP\Api\Swagger;
use OpenApi\Attributes as OA;
#[OA\Info(
version: "1.0",
title: "Ajax Search Pro for WordPress"
)]
final class Routes {
#[OA\Get(
path: '/wp-json/ajax-search-pro/v0/search',
description: 'Generic search',
tags: ['search'],
parameters: [
new OA\Parameter(name: 's', in: 'query', required: true, schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'id', in: 'query', required: false, schema: new OA\Schema(type: 'integer')),
],
responses: [
new OA\Response(
response: 200,
description: 'Results array.',
content: new OA\JsonContent(type: 'array', items: new OA\Items(type: 'object', ref: WP_Post_ASP::class))
),
]
)]
public function searchRoute() {}
#[OA\Get(
path: '/wp-json/ajax-search-pro/v0/woo_search',
description: 'WooCommerce Specific Search',
tags: ['woocommerce'],
parameters: [
new OA\Parameter(name: 's', in: 'query', required: true, schema: new OA\Schema(type: 'string')),
new OA\Parameter(name: 'id', in: 'query', required: false, schema: new OA\Schema(type: 'integer')),
],
responses: [
new OA\Response(
response: 200,
description: 'Product results array.',
content: new OA\JsonContent(type: 'array', items: new OA\Items(type: 'object', ref: WP_Post_ASP::class))
),
]
)]
public function wooSearchRoute() {}
}

View File

@@ -0,0 +1,239 @@
<?php
namespace WPDRMS\ASP\Api\Swagger;
use OpenApi\Attributes as OA;
#[OA\Schema]
final class WP_Post_ASP {
#[OA\Property]
/**
* Post ID.
*
* @since 3.5.0
* @var int
*/
public $ID;
#[OA\Property]
/**
* ID of post author.
*
* A numeric string, for compatibility reasons.
*
* @since 3.5.0
* @var string
*/
public $post_author = 0;
#[OA\Property]
/**
* The post's local publication time.
*
* @since 3.5.0
* @var string
*/
public $post_date = '0000-00-00 00:00:00';
#[OA\Property]
/**
* The post's GMT publication time.
*
* @since 3.5.0
* @var string
*/
public $post_date_gmt = '0000-00-00 00:00:00';
#[OA\Property]
/**
* The post's content.
*
* @since 3.5.0
* @var string
*/
public $post_content = '';
#[OA\Property]
/**
* The post's title.
*
* @since 3.5.0
* @var string
*/
public $post_title = '';
#[OA\Property]
/**
* The post's excerpt.
*
* @since 3.5.0
* @var string
*/
public $post_excerpt = '';
#[OA\Property]
/**
* The post's status.
*
* @since 3.5.0
* @var string
*/
public $post_status = 'publish';
#[OA\Property]
/**
* Whether comments are allowed.
*
* @since 3.5.0
* @var string
*/
public $comment_status = 'open';
#[OA\Property]
/**
* Whether pings are allowed.
*
* @since 3.5.0
* @var string
*/
public $ping_status = 'open';
#[OA\Property]
/**
* The post's password in plain text.
*
* @since 3.5.0
* @var string
*/
public $post_password = '';
#[OA\Property]
/**
* The post's slug.
*
* @since 3.5.0
* @var string
*/
public $post_name = '';
#[OA\Property]
/**
* URLs queued to be pinged.
*
* @since 3.5.0
* @var string
*/
public $to_ping = '';
#[OA\Property]
/**
* URLs that have been pinged.
*
* @since 3.5.0
* @var string
*/
public $pinged = '';
#[OA\Property]
/**
* The post's local modified time.
*
* @since 3.5.0
* @var string
*/
public $post_modified = '0000-00-00 00:00:00';
#[OA\Property]
/**
* The post's GMT modified time.
*
* @since 3.5.0
* @var string
*/
public $post_modified_gmt = '0000-00-00 00:00:00';
#[OA\Property]
/**
* A utility DB field for post content.
*
* @since 3.5.0
* @var string
*/
public $post_content_filtered = '';
#[OA\Property]
/**
* ID of a post's parent post.
*
* @since 3.5.0
* @var int
*/
public $post_parent = 0;
#[OA\Property]
/**
* The unique identifier for a post, not necessarily a URL, used as the feed GUID.
*
* @since 3.5.0
* @var string
*/
public $guid = '';
#[OA\Property]
/**
* A field used for ordering posts.
*
* @since 3.5.0
* @var int
*/
public $menu_order = 0;
#[OA\Property]
/**
* The post's type, like post or page.
*
* @since 3.5.0
* @var string
*/
public $post_type = 'post';
#[OA\Property]
/**
* An attachment's mime type.
*
* @since 3.5.0
* @var string
*/
public $post_mime_type = '';
#[OA\Property]
/**
* Cached comment count.
*
* A numeric string, for compatibility reasons.
*
* @since 3.5.0
* @var string
*/
public $comment_count = 0;
#[OA\Property]
/**
* Stores the post object's sanitization level.
*
* Does not correspond to a DB field.
*
* @since 3.5.0
* @var string
*/
public $filter;
#[OA\Property]
/**
* Additional Search Data added by Ajax Search Pro
*
* @var ASP_Data
*/
public ASP_Data $asp_data;
}