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,154 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NI_Ajax_Controller {
/**
* @var TD_NI_Ajax_Controller
*/
protected static $_instance;
/**
* @var int
*/
public $version = 1;
/**
* @var string
*/
public $namespace = 'notification-inbox/v';
/**
* TD_NI_Ajax_Controller constructor.
*/
private function __construct() {
}
/**
* @return TD_NI_Ajax_Controller
*/
public static function instance() {
if ( empty( static::$_instance ) ) {
static::$_instance = new static();
}
return static::$_instance;
}
/**
* @return mixed
*/
public function handle() {
if ( ! check_ajax_referer( 'td_ni_admin_ajax_request', '_nonce', false ) ) {
$this->error( sprintf( __( 'Invalid request', 'thrive-dash' ) ) );
}
$route = $this->param( 'action' );
$route = preg_replace( '#([^a-zA-Z0-9-])#', '', $route );
$method_name = $route . '_action';
if ( ! method_exists( $this, $method_name ) ) {
$this->error( sprintf( __( 'Method %s not implemented', 'thrive-dash' ), $method_name ) );
}
$model = json_decode( file_get_contents( 'php://input' ), true );
wp_send_json( $this->{$method_name}( $model ) );
}
/**
* Handle ajax route for read inbox message read
*
* @return false|mixed|string|void
*/
public function thrvnotifications_action() {
$this->_verify_nonce();
if ( empty( $_REQUEST['notification_id'] ) ) {
$this->error( __( 'Missing parameter [notification_id] in ajax request', 'thrive-dash' ) );
}
try {
TVE_Dash_InboxManager::instance()->set_read( $this->param( 'notification_id' ) );
$return = array( 'total_unread' => TVE_Dash_InboxManager::instance()->count_unread() );
return json_encode( $return );
} catch ( Exception $e ) {
$this->error( $e->getMessage() );
}
return $this->error( __( 'An error ocurred on updating notification', 'thrive-dash' ) );
}
/**
* Buld read action
*
* @return bool
*/
public function thrvbulkread_action() {
$this->_verify_nonce();
TVE_Dash_InboxManager::instance()->bulk_read();
$response = array( 'total_unread' => TVE_Dash_InboxManager::instance()->count_unread() );
return json_encode( $response );
}
/**
* @return bool
*/
public function thrvloadmore_action() {
$this->_verify_nonce();
$offset = $this->param( 'offset' );
$limit = $this->param( 'limit' );
return array_values( TVE_Dash_InboxManager::instance()->load_more( $offset, $limit ) );
}
/**
* @param $key
* @param null $default
*
* @return null
*/
protected function param( $key, $default = null ) {
return isset( $_POST[ $key ] ) ? map_deep( $_POST[ $key ], 'sanitize_text_field' ) : ( isset( $_REQUEST[ $key ] ) ? map_deep( $_REQUEST[ $key ], 'sanitize_text_field' ) : $default );
}
/**
* @param $message
* @param string $status
*/
protected function error( $message, $status = '404 Not Found' ) {
status_header( 400 );
wp_send_json( array(
'error' => $message,
) );
return $message;
}
/**
* Verify nonce
*/
private function _verify_nonce() {
if ( ! check_ajax_referer( 'td_ni_admin_ajax_request', '_nonce', false ) ) {
$this->error( sprintf( __( 'Invalid request', 'thrive-dash' ) ) );
}
}
}

View File

@@ -0,0 +1,355 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class TVE_Dash_InboxManager
*/
class TVE_Dash_InboxManager {
/**
* Option name, for storing NI messages
*/
const INBOX_OPTION_NAME = 'tvd_dash_inbox';
/**
* For saving inbox errors into this option
*/
const INBOX_OPTION_ERRORS = 'tvd_dash_inbox_err';
/**
* @var null
*/
protected static $_instance = null;
/**
* @var array
*/
public $list = array();
/**
* Retrieved data from DB
*
* @var array
*/
private $_existing_list = array();
/**
* TVE_Dash_InboxManager constructor.
*/
private function __construct() {
}
/**
* @return TVE_Dash_InboxManager|null
*/
public static function instance() {
if ( empty( static::$_instance ) ) {
static::$_instance = new self();
}
return static::$_instance;
}
/**
* @param $msg_id
*
* @throws Exception
*/
public function set_read( $msg_id ) {
if ( empty( $msg_id ) ) {
throw new Exception( __( __METHOD__ . ' required message_id on updating notification status. ', 'thrive-dash' ) );
}
$this->_refresh_messages();
if ( isset( $this->_existing_list[ $msg_id ] ) ) {
$this->_existing_list[ $msg_id ]['read'] = 1;
}
$this->_update();
}
/**
* Remove message from API connection lsit
*
* @param $slug
*
* @return bool
*/
public function remove_api_connection( $slug ) {
if ( empty( $slug ) ) {
return false;
}
$this->_refresh_messages();
$found = 0;
foreach ( $this->_existing_list as $msg_id => $message ) {
if ( ! empty( $message['slug'] ) && ! empty( $message['type'] ) && $slug === $message['slug'] && TD_Inbox_Message::TYPE_API === $message['type'] ) {
$found = 1;
unset( $this->_existing_list[ $msg_id ] );
}
}
if ( $found ) {
return $this->_update();
}
return false;
}
/**
* Bulk update notifications read
*/
public function bulk_read() {
$this->_refresh_messages();
foreach ( $this->_existing_list as $id => $notification ) {
if ( isset( $notification['read'] ) ) {
$this->_existing_list[ $id ]['read'] = 1;
}
}
return $this->_update();
}
/**
* Add to the beginning of the list
*
* @param $message
*
* @throws Exception
*/
public function prepend( $message ) {
if ( ! $message instanceof TD_Inbox_Message ) {
throw new Exception( __( __METHOD__ . ' must be instanceof TD_Inbox_Message. ', 'thrive-dash' ) );
}
$message_id = $message->get_property( 'id' );
try {
if ( $this->_message_exists( $message_id ) ) {
throw new Exception( __METHOD__ . __( " Could not save, [{$message_id}] already exists.", 'thrive-dash' ) );
}
} catch ( Exception $e ) {
throw new Exception( ( $e->getMessage() ) );
}
$this->list = array( $message_id => $message->to_array() ) + $this->list;
}
/**
* Add to the end of the list
*
* @param $message
*
* @throws Exception
*/
public function append( $message ) {
if ( ! $message instanceof TD_Inbox_Message ) {
throw new Exception( __METHOD__ . __( ' message must be instanceof TD_Inbox_Message. ', 'thrive-dash' ) );
}
$message_id = $message->get_property( 'id' );
try {
if ( $this->_message_exists( $message_id ) ) {
throw new Exception( __METHOD__ . __( " Could not save, [{$message_id}] already exists.", 'thrive-dash' ) );
}
} catch ( Exception $e ) {
throw new Exception( ( $e->getMessage() ) );
}
$this->list[ $message_id ] = $message->to_array();
}
/**
* Get all or inbox type option inbox data
*
* @return array
*/
public function get_data( $type = '' ) {
$data = (array) get_option( self::INBOX_OPTION_NAME, array() );
if ( ! empty( $type ) && TD_Inbox_Message::TYPE_INBOX === $type ) {
foreach ( $data as $msg_id => $message ) {
if ( isset( $message['type'] ) && TD_Inbox_Message::TYPE_API === $message['type'] ) {
unset( $data[ $msg_id ] );
}
}
}
return $data;
}
/**
* @param $offset
* @param int $length
*
* @return array
*/
public function load_more( $offset, $length = 10 ) {
$this->_refresh_messages();
return array_slice( $this->_existing_list, $offset, $length );
}
/**
* Count the sent list or regenerate and count
*
* @param array $data
*
* @return int
*/
public function count_unread( $data = array(), $type = TD_Inbox_Message::TYPE_INBOX ) {
$cnt = 0;
if ( empty( $data ) ) {
$this->_refresh_messages();
$data = $this->_existing_list;
}
foreach ( $data as $notification ) {
if ( ! empty( $notification['type'] ) && $type === $notification['type'] && 0 === $notification['read'] ) {
$cnt ++;
}
}
return $cnt;
}
/**
* @return mixed|void
*/
public function added_messages() {
return $this->list;
}
/**
* @return bool
* @throws Exception
*/
public function push_notifications() {
if ( empty( $this->list ) ) {
throw new Exception( __( 'Could not push_notification with empty arguments', 'thrive-dash' ) );
}
return $this->_save();
}
/**
* Save errors into DB
*
* @param $message
*
* @return bool
*/
public function error( $message ) {
if ( empty( $message ) ) {
return false;
}
$messages = (array) get_option( self::INBOX_OPTION_ERRORS, array() );
$messages[ date( 'Y-m-d H:i:s' ) ] = $message;
update_option( self::INBOX_OPTION_ERRORS, $messages );
}
/**
* @param $slug
*
* @return array|mixed
*/
public function get_by_slug( $slug ) {
if ( empty( $slug ) || ! is_string( $slug ) ) {
return array();
}
$this->_refresh_messages();
foreach ( $this->_existing_list as $id => $notification ) {
if ( ! empty( $notification['slug'] ) && $notification['slug'] === $slug ) {
return $notification;
}
}
return array();
}
/**
* Verify if the message is already saved into the DB
* based on the message id { md5( $message['title') ] }
*
* @param $msg_id
*
* @return bool
* @throws Exception
*/
private function _message_exists( $msg_id ) {
if ( ! $msg_id ) {
throw new Exception( __METHOD__ . __( ' $msg_id can\'t be empty.', 'thrive-dash' ) );
}
// Set / refresh existing DB data to $_existing_list array
$this->_refresh_messages();
if ( isset( $this->_existing_list[ $msg_id ] ) ) {
return true;
}
return false;
}
/**
* Grab the latest messages from DB
*/
private function _refresh_messages() {
$this->_existing_list = $this->get_data();
}
/**
* @return bool
*/
private function _save() {
if ( empty( $this->list ) ) {
return false;
}
$this->_refresh_messages();
$all_data = $this->list + $this->_existing_list;
return ! empty( $all_data ) ? update_option( self::INBOX_OPTION_NAME, $all_data ) : false;
}
/**
* @return bool
*/
private function _update() {
return ! empty( $this->_existing_list ) ? update_option( self::INBOX_OPTION_NAME, $this->_existing_list ) : false;
}
}

View File

@@ -0,0 +1,147 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden!
}
/**
* Class TD_Inbox_Message
*
* Build the Message object, required for push_notification
*/
class TD_Inbox_Message {
/**
* Type of the message [used on displaying in API Connections]
*/
const TYPE_API = 'api_connections';
/**
* Message inbox type [used on displaying in Dash Inbox]
*/
const TYPE_INBOX = 'inbox';
/**
* @var string
*/
private $id;
/**
* @var string
*/
private $title;
/**
* @var string
*/
private $info;
/**
* @var int
*/
private $read = 0;
/**
* @var string
*/
private $date;
/**
* @var null
*/
private $slug = null;
/**
* @var null
*/
private $type = null;
/**
* TD_Inbox_Message constructor.
*
* @param $data
*
* @throws Exception
*/
public function __construct( $data ) {
if ( ! is_array( $data ) ) {
throw new Exception( __METHOD__ . __( ' message must be array ', 'thrive-dash' ) );
}
if ( empty( $data['title'] ) ) {
throw new Exception( __METHOD__ . __( ' title can not be empty.. ', 'thrive-dash' ) );
}
$this->_set( $data );
}
/**
* Returns objects properties as array
*
* @return array
*/
public function to_array() {
return (array) $this->_get_data();
}
/**
* Returns objects properties as json
*
* @return false|mixed|string|void
*/
public function to_json() {
return json_encode( $this->_get_data() );
}
/**
* @param $property
*
* @return bool
*/
public function get_property( $property ) {
if ( ! isset( $this->{$property} ) ) {
return false;
}
return $this->{$property};
}
/**
* Returns all object accessible non-static properties in this scope
*
* @return array
*/
private function _get_data() {
return get_object_vars( $this );
}
/**
* @param $data
*/
private function _set( $data ) {
foreach ( $data as $key => $value ) {
if ( property_exists( $this, $key ) ) {
$this->{$key} = $value;
}
}
if ( $this->title ) {
$this->id = md5( $this->title );
}
$this->date = date( 'jS F Y' );
$this->read = 0;
}
}