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,2 @@
<?php
// Silence is golden.

View File

@@ -0,0 +1,291 @@
const bwf_ajax = function (cls, is_form, cb) {
let $ = jQuery;
const self = this;
let element = null;
let handler = {};
let prefix = "bwfan_";
this.action = null;
this.change_prefix = function (new_prefix) {
if (new_prefix !== undefined) {
prefix = new_prefix;
}
};
this.data = function (form_data, formEl = null) {
return form_data;
};
this.before_send = function (formEl) {
};
this.async = function (bool) {
return bool;
};
this.method = function (method) {
return method;
};
this.success = function (rsp, fieldset, loader, jqxhr, status) {
};
this.complete = function (rsp, fieldset, loader, jqxhr, status) {
};
this.error = function (rsp, fieldset, loader, jqxhr, status) {
};
this.action = function (action) {
return action;
};
this.element = function () {
return element;
};
this.validate = function (formEl, action, form_data) {
return true;
};
function reset_form(action, fieldset, loader, rsp, jqxhr, status) {
if (fieldset.length > 0) {
fieldset.prop('disabled', false);
}
loader.remove();
let loader2;
loader2 = $(".bwf_ajax_btn_bottom_container");
loader2.removeClass('ajax_loader_show');
if (self.hasOwnProperty(action) === true && typeof self[action] === 'function') {
self[action](rsp, fieldset, loader, jqxhr, status);
}
}
function form_post(action) {
let formEl = element;
let ajax_loader = null;
let form_data = new FormData(formEl);
form_data.append('action', action);
form_data.append('bwf_nonce', bwf_secure.nonce);
let form_method = $(formEl).attr('method');
if ($(formEl).find("." + action + "_ajax_loader").length === 0) {
$(formEl).find(".bwf_form_submit").prepend("<span class='" + action + "_ajax_loader spinner" + "'></span>");
ajax_loader = $(formEl).find("." + action + "_ajax_loader");
} else {
ajax_loader = $(formEl).find("." + action + "_ajax_loader");
}
let ajax_loader2 = $(".bwf_ajax_btn_bottom_container");
ajax_loader.addClass('ajax_loader_show');
ajax_loader2.addClass('ajax_loader_show');
let fieldset = $(formEl).find("fieldset");
if (fieldset.length > 0) {
fieldset.prop('disabled', true);
}
self.before_send(formEl, action);
let data = self.data(form_data, formEl);
let validated = self.validate(formEl, action, form_data);
if (true !== validated) {
return;
}
let request = {
url: ajaxurl,
async: self.async(true),
method: self.method('POST'),
data: data,
processData: false,
contentType: false,
// contentType: self.content_type(false),
success: function (rsp, jqxhr, status) {
if (typeof rsp === 'object' && rsp.hasOwnProperty('nonce')) {
bwf_secure.nonce = rsp.nonce;
delete rsp.nonce;
}
reset_form(action + "_ajax_success", fieldset, ajax_loader, rsp, jqxhr, status);
self.success(rsp, jqxhr, status, element, ajax_loader, fieldset);
},
complete: function (rsp, jqxhr, status) {
reset_form(action + "_ajax_complete", fieldset, ajax_loader, rsp, jqxhr, status);
self.complete(rsp, jqxhr, status, element, ajax_loader, fieldset);
},
error: function (rsp, jqxhr, status) {
reset_form(action + "_ajax_error", fieldset, ajax_loader, rsp, jqxhr, status);
self.error(rsp, jqxhr, status, element, ajax_loader, fieldset);
}
};
if (handler.hasOwnProperty(action)) {
clearTimeout(handler[action]);
} else {
handler[action] = null;
}
handler[action] = setTimeout(
function (request) {
$.ajax(request);
},
200,
request
);
}
function send_json(action) {
let formEl = element;
let data = self.data({}, formEl);
if (typeof data === 'object') {
data.action = action;
} else {
data = {
'action': action
};
}
self.before_send(formEl, action);
let validated = self.validate(formEl, action);
if (true !== validated) {
return;
}
data.bwf_nonce = bwf_secure.nonce;
let request = {
url: ajaxurl,
async: self.async(true),
method: self.method('POST'),
data: data,
success: function (rsp, jqxhr, status, element) {
if (typeof rsp === 'object' && rsp.hasOwnProperty('nonce')) {
bwf_secure.nonce = rsp.nonce;
delete rsp.nonce;
}
self.success(rsp, jqxhr, status, element);
},
complete: function (rsp, jqxhr, status, element) {
self.complete(rsp, jqxhr, status, element);
},
error: function (rsp, jqxhr, status) {
self.error(rsp, jqxhr, status, element);
}
};
if (handler.hasOwnProperty(action)) {
clearTimeout(handler[action]);
} else {
handler[action] = null;
}
handler[action] = setTimeout(
function (request) {
$.ajax(request);
},
200,
request
);
}
this.ajax = function (action, data) {
if (typeof data === 'object') {
data.action = action;
} else {
data = {
'action': action
};
}
data.action = prefix + action;
self.before_send(document.body, action);
let validated = self.validate(document.body, action, data);
if (true !== validated) {
return;
}
data.bwf_nonce = bwf_secure.nonce;
let request = {
url: ajaxurl,
async: self.async(true),
method: self.method('POST'),
data: data,
success: function (rsp, jqxhr, status) {
if (typeof rsp === 'object' && rsp.hasOwnProperty('nonce')) {
bwf_secure.nonce = rsp.nonce;
delete rsp.nonce;
}
self.success(rsp, jqxhr, status, action);
},
complete: function (rsp, jqxhr, status) {
self.complete(rsp, jqxhr, status, action);
},
error: function (rsp, jqxhr, status) {
self.error(rsp, jqxhr, status, action);
}
};
if (handler.hasOwnProperty(action)) {
clearTimeout(handler[action]);
} else {
handler[action] = null;
}
handler[action] = setTimeout(
function (request) {
$.ajax(request);
},
200,
request
);
};
function form_init(cls) {
if ($(cls).length === 0) {
return;
}
$(cls).on(
"submit",
function (e) {
e.preventDefault();
let action = $(this).data('bwf-action');
if (action !== 'undefined') {
action = prefix + action;
action = action.trim();
element = this;
self.action = action;
form_post(action);
}
}
);
if (typeof cb === 'function') {
cb(self);
}
}
function click_init(cls) {
if ($(cls).length === 0) {
return;
}
$(cls).on(
"click",
function (e) {
e.preventDefault();
let action = $(this).data('bwf-action');
if (action !== 'undefined') {
action = prefix + action;
action = action.trim();
element = this;
self.action = action;
send_json(action);
}
}
);
if (typeof cb === 'function') {
cb(self);
}
}
if (is_form === true) {
form_init(cls, cb);
return this;
}
if (is_form === false) {
click_init(cls, cb);
return this;
}
return this;
};

View File

@@ -0,0 +1,217 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WFCO_Admin' ) ) {
#[AllowDynamicProperties]
class WFCO_Admin {
private static $ins = null;
public $admin_path;
public $admin_url;
public $section_page = '';
public $should_show_shortcodes = null;
public function __construct() {
define( 'WFCO_PLUGIN_FILE', __FILE__ );
define( 'WFCO_PLUGIN_DIR', __DIR__ );
define( 'WFCO_PLUGIN_URL', untrailingslashit( plugin_dir_url( WFCO_PLUGIN_FILE ) ) );
$this->admin_path = WFCO_PLUGIN_DIR;
$this->admin_url = WFCO_PLUGIN_URL;
add_action( 'admin_enqueue_scripts', array( $this, 'include_global_assets' ), 98 );
$should_include = apply_filters( 'wfco_include_connector', false );
if ( false === $should_include ) {
return;
}
$this->initialize_connector();
}
private function initialize_connector() {
include_once( $this->admin_path . '/class-wfco-connector.php' ); //phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
include_once( $this->admin_path . '/class-wfco-call.php' ); //phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
include_once( $this->admin_path . '/class-wfco-load-connectors.php' ); //phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
include_once( $this->admin_path . '/class-wfco-common.php' ); //phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
include_once( $this->admin_path . '/class-wfco-db.php' ); //phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
include_once( $this->admin_path . '/class-wfco-connector-api.php' ); //phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable
WFCO_Common::init();
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self;
}
return self::$ins;
}
public static function get_plugins() {
return apply_filters( 'all_plugins', get_plugins() );
}
public static function get_oauth_connector() {
$oauth_connectors = [];
$all_connector = WFCO_Admin::get_available_connectors();
if ( empty( $all_connector ) ) {
return $oauth_connectors;
}
foreach ( $all_connector as $addons ) {
if ( empty( $addons ) ) {
continue;
}
foreach ( $addons as $addons_slug => $addon ) {
if ( $addon->is_activated() ) {
$instance = $addons_slug::get_instance();
if ( $instance->is_oauth() ) {
$oauth_connectors[] = $addons_slug;
}
}
}
}
return $oauth_connectors;
}
public static function get_available_connectors( $type = '' ) {
$woofunnels_cache_object = WooFunnels_Cache::get_instance();
$woofunnels_transient_obj = WooFunnels_Transient::get_instance();
$data = $woofunnels_cache_object->get_cache( 'get_available_connectors' );
if ( empty( $data ) ) {
$data = $woofunnels_transient_obj->get_transient( 'get_available_connectors' );
}
if ( ! empty( $data ) && is_array( $data ) ) {
$data = apply_filters( 'wfco_connectors_loaded', $data );
return self::load_connector_screens( $data, $type );
}
$connector_api = new WFCO_Connector_api();
$response_data = $connector_api->set_action( 'get_available_connectors' )->get()->get_package();
if ( is_array( $response_data ) ) {
$woofunnels_transient_obj->set_transient( 'get_available_connectors', $response_data, 3 * HOUR_IN_SECONDS );
}
$response_data = apply_filters( 'wfco_connectors_loaded', $response_data );
if ( '' !== $type ) {
return isset( $response_data[ $type ] ) ? $response_data[ $type ] : [];
}
return self::load_connector_screens( $response_data, $type );
}
private static function load_connector_screens( $response_data, $type = '' ) {
foreach ( $response_data as $slug => $data ) {
$connectors = $data['connectors'];
foreach ( $connectors as $c_slug => $connector ) {
$connector['type'] = $slug;
if ( isset( $data['source'] ) && ! empty( $data['source'] ) ) {
$connector['source'] = $data['source'];
}
if ( isset( $data['file'] ) && ! empty( $data['file'] ) ) {
$connector['file'] = $data['file'];
}
if ( isset( $data['support'] ) && ! empty( $data['support'] ) ) {
$connector['support'] = $data['support'];
}
if ( isset( $data['connector_class'] ) && ! empty( $data['connector_class'] ) ) {
$connector['connector_class'] = $data['connector_class'];
}
WFCO_Connector_Screen_Factory::create( $c_slug, $connector );
}
}
return WFCO_Connector_Screen_Factory::getAll( $type );
}
public static function get_error_message() {
$errors = [];
$errors[100] = __( 'Connector not found', 'woofunnels' ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
$errors[101] = __( 'FunnelKit Automations license is required in order to install a connector', 'woofunnels' ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
$errors[102] = __( 'FunnelKit Automations license is invalid, kindly contact woofunnels team.', 'woofunnels' ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
$errors[103] = __( 'FunnelKit Automations license is expired, kindly renew and activate it first.', 'woofunnels' ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
return $errors;
}
public static function js_text() {
$data = array(
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'text_copied' => __( 'Text Copied', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'sync_title' => __( 'Sync Connector', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'sync_text' => __( 'All the data of this Connector will be Synced.', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'sync_wait' => __( 'Please Wait...', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'sync_progress' => __( 'Sync in progress...', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'sync_success_title' => __( 'Connector Synced', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'sync_success_text' => __( 'We have detected change in the connector during syncing. Please re-save the Automations.', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'oops_title' => __( 'Oops', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'oops_text' => __( 'There was some error. Please try again later.', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'delete_int_title' => __( 'There was some error. Please try again later.', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'delete_int_text' => __( 'There was some error. Please try again later.', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'update_int_prompt_title' => __( 'Connector Updated', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'update_int_prompt_text' => __( 'We have detected change in the connector during updating. Please re-save the Automations.', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'delete_int_prompt_title' => __( 'Disconnecting Connector?', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'delete_int_prompt_text' => __( 'All the action, tasks, logs of this connector will be deleted.', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'delete_int_wait_title' => __( 'Please Wait...', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'delete_int_wait_text' => __( 'Disconnecting the connector ...', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'delete_int_success' => __( 'Connector Disconnected', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'update_btn' => __( 'Update', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'save_progress' => __( 'Saving in progress...', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'update_btn_process' => __( 'Updating...', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'connect_btn_process' => __( 'Connecting...', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'install_success_title' => __( 'Connector Installed Successfully', 'woofunnels' ),
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'connect_success_title' => __( 'Connected Successfully', 'woofunnels' ),
);
return $data;
}
public function get_admin_url() {
return plugin_dir_url( WFCO_PLUGIN_FILE ) . 'admin';
}
public function include_global_assets() {
wp_enqueue_script( 'wfco-admin-ajax', $this->admin_url . '/assets/js/wfco-admin-ajax.js', array(), WooFunnel_Loader::$version );
wp_localize_script( 'wfco-admin-ajax', 'bwf_secure', [
'nonce' => wp_create_nonce( 'bwf_secure_key' ),
] );
}
public function tooltip( $text ) {
?>
<span class="wfco-help"><i class="icon"></i><div class="helpText"><?php echo $text; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div></span>
<?php
}
}
}

View File

@@ -0,0 +1,175 @@
<?php
if ( ! class_exists( 'WFCO_Call' ) ) {
#[AllowDynamicProperties]
abstract class WFCO_Call {
protected $data = array();
protected $allowed_responses = array( 200, 201, 202 );
protected $connector_slug = null;
protected $required_fields = array();
protected $missing_field = false;
public function get_slug() {
return sanitize_title( get_class( $this ) );
}
public function get_connector_slug() {
return $this->connector_slug;
}
public function set_connector_slug( $slug ) {
$this->connector_slug = $slug;
}
public function get_random_api_error() {
return __( 'Api Error: No response from API', 'woofunnels' ); // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
}
public function process() {
return [];
}
/**
* Checks the required fields for every action
*
* @param $data
* @param $required_fields
*
* @return bool
*/
public function check_fields( $data, $required_fields ) {
$failed = false;
foreach ( $required_fields as $single_field ) {
$failed = ! isset( $data[ $single_field ] );
/** Existence Checking */
$failed = $failed || ( is_array( $data[ $single_field ] ) && empty( $data[ $single_field ] ) );
/** Array Checking */
$failed = $failed || ( is_null( $data[ $single_field ] ) || '' === $data[ $single_field ] );
/** Null or Empty String Checking */
if ( true === $failed ) {
$this->missing_field = $single_field;
break;
}
}
return ! $failed;
}
/**
* Return the error
*
* @return array
*/
public function show_fields_error() {
return array(
'response' => 502,
'body' => array( 'Required Field Missing' . ( false !== $this->missing_field ? ' : ' . $this->missing_field : '' ) ),
);
}
/**
* Set the data for every action
*
* @param $data
*/
public function set_data( $data ) {
$data = apply_filters( 'modify_set_data', $data );
$this->data = $data;
}
/**
* Sends a wp remote call to Third party softwares.
*
* @param $url
* @param array $params
* @param int $req_method
*
* @return array|mixed|object|string
*/
public function make_wp_requests( $url, $params = array(), $headers = array(), $req_method = 1 ) {
$body = array(
'response' => 500,
'body' => array( __( 'CURL Error', 'woofunnels' ) ), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
);
// $req_method
// 1 stands for get
// 2 stands for post
// 3 stands for delete
$args = array(
'timeout' => 45,
'httpversion' => '1.0',
'blocking' => true,
'body' => $params,
);
if ( is_array( $headers ) && count( $headers ) > 0 ) {
$args['headers'] = $headers;
}
switch ( $req_method ) {
case 2:
$args['method'] = 'POST';
break;
case 3:
$args['method'] = 'DELETE';
break;
case 4:
$args['method'] = 'PUT';
break;
case 5:
$args['method'] = 'PATCH';
break;
default:
$args['method'] = 'GET';
break;
}
$response = wp_remote_request( $url, $args );
if ( ! is_wp_error( $response ) ) {
$body = wp_remote_retrieve_body( $response );
$headers = wp_remote_retrieve_headers( $response );
if ( $this->is_json( $body ) ) {
$body = json_decode( $body, true );
}
$body = maybe_unserialize( $body );
if ( in_array( $response['response']['code'], $this->allowed_responses, true ) ) {
$response_code = 200;
} else {
$response_code = $response['response']['code'];
}
$body = array(
'response' => intval( $response_code ),
'body' => $body,
'headers' => $headers,
);
return $body;
}
$body['body'] = [ $response->get_error_message() ];
return $body;
}
/**
* check if a string is json or not
*
* @param $string
*
* @return bool
*/
public function is_json( $string ) {
json_decode( $string );
return ( json_last_error() === JSON_ERROR_NONE );
}
}
}

View File

@@ -0,0 +1,640 @@
<?php
if ( ! class_exists( 'WFCO_Common' ) ) {
#[AllowDynamicProperties]
class WFCO_Common {
public static $ins = null;
public static $http;
public static $connectors_saved_data = array();
public static $saved_data = false;
public static function init() {
add_filter( 'bwf_add_db_table_schema', [ __CLASS__, 'create_db_tables' ], 10, 2 );
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self;
}
return self::$ins;
}
/**
* Create required tables
*/
public static function create_db_tables( $args, $tables ) {
$max_index_length = 191;
if ( $tables['version'] !== BWF_DB_VERSION || ! in_array( 'wfco_connectors', $tables['tables'], true ) ) {
$args[] = [
'name' => 'wfco_connectors',
'schema' => "CREATE TABLE `{table_prefix}wfco_connectors` (
ID bigint(20) unsigned NOT NULL auto_increment,
last_sync datetime NOT NULL default '0000-00-00 00:00:00',
slug varchar(255) default NULL,
status tinyint(1) not null default 0 COMMENT '1 - Active 2 - Inactive',
PRIMARY KEY (ID),
KEY slug (slug($max_index_length)),
KEY status (status)
) {table_collate};",
];
}
if ( $tables['version'] !== BWF_DB_VERSION || ! in_array( 'wfco_connectormeta', $tables['tables'], true ) ) {
$args[] = [
'name' => 'wfco_connectormeta',
'schema' => "CREATE TABLE `{table_prefix}wfco_connectormeta` (
ID bigint(20) unsigned NOT NULL auto_increment,
connector_id bigint(20) unsigned NOT NULL default '0',
meta_key varchar(255) default NULL,
meta_value longtext,
PRIMARY KEY (ID),
KEY connector_id (connector_id),
KEY meta_key (meta_key($max_index_length))
) {table_collate};",
];
}
return $args;
}
/**
* Send remote call
*
* @param $api_url
* @param $data
* @param string $method_type
*
* @return array|mixed|null|object|string
*/
public static function send_remote_call( $api_url, $data, $method_type = 'post' ) {
if ( 'get' === $method_type ) {
$httpPostRequest = self::http()->get( $api_url, array(
'body' => $data,
'sslverify' => false,
'timeout' => 30,
) );
} else {
$httpPostRequest = self::http()->post( $api_url, array(
'body' => $data,
'sslverify' => false,
'timeout' => 30,
) );
}
if ( isset( $httpPostRequest->errors ) ) {
$response = null;
} elseif ( isset( $httpPostRequest['body'] ) && '' !== $httpPostRequest['body'] ) {
$body = $httpPostRequest['body'];
$response = json_decode( $body, true );
} else {
$response = 'No result';
}
return $response;
}
public static function http() {
if ( self::$http === null ) {
self::$http = new WP_Http();
}
return self::$http;
}
/**
* Save connector data
*
* @param $data
* @param $slug
* @param $status
*
* @return int
*/
public static function save_connector_data( $data, $slug, $status ) {
$settings = array();
$settings['last_sync'] = current_time( 'mysql', 1 );
$settings['slug'] = $slug;
$settings['status'] = $status;
WFCO_Model_Connectors::insert( $settings );
$connector_id = WFCO_Model_Connectors::insert_id();
foreach ( $data as $key => $val ) {
$meta_data = array();
$meta_data['connector_id'] = $connector_id;
$meta_data['meta_key'] = $key;
$meta_data['meta_value'] = maybe_serialize( $val );
WFCO_Model_ConnectorMeta::insert( $meta_data );
}
return $connector_id;
}
/**
* get all connectors saved data for global access
*/
public static function get_connectors_data() {
$temp = array();
$temp_arr = array();
if ( false === self::$saved_data ) {
$response = WFCO_Model_Connectors::get_results( 'SELECT * FROM {table_name}' );
if ( is_array( $response ) && count( $response ) > 0 ) {
$connector_ids = array_column( $response, 'ID' );
$meta = WFCO_Model_ConnectorMeta::get_connectors_meta( $connector_ids );
foreach ( $response as $connector ) {
$temp[ $connector['slug'] ]['id'] = $connector['ID'];
$temp[ $connector['slug'] ]['last_sync'] = $connector['last_sync'];
$temp[ $connector['slug'] ]['status'] = $connector['status'];
$settings_meta = isset( $meta[ $connector['ID'] ] ) ? $meta[ $connector['ID'] ] : [];
$temp_arr[ $connector['slug'] ] = array_merge( $temp[ $connector['slug'] ], $settings_meta );
}
}
self::$saved_data = $temp_arr;
} else {
$temp_arr = self::$saved_data;
}
self::$connectors_saved_data = $temp_arr;
}
public static function get_metakey_value( $all_meta, $meta_key, $primary_id = null, $primary_key_name = null ) {
$value = null;
foreach ( $all_meta as $value1 ) {
if ( ! is_null( $primary_id ) ) {
if ( $value1[ $primary_key_name ] == $primary_id ) {
if ( $meta_key === $value1['meta_key'] ) {
$value = maybe_unserialize( $value1[ $meta_key ] );
break;
}
}
}
if ( $meta_key === $value1['meta_key'] ) {
$value = maybe_unserialize( $value1['meta_value'] );
break;
}
}
return $value;
}
/**
* update connector data
*
* @param array $new_data
*/
public static function update_connector_data( $new_data = array(), $connector_id = 0 ) {
global $wpdb;
$data = array();
$data['last_sync'] = current_time( 'mysql', 1 );
$where['ID'] = $connector_id;
WFCO_Model_Connectors::update( $data, $where );
$sql_query = 'DELETE from {table_name} where connector_id = %d';
$sql_query = $wpdb->prepare( $sql_query, $connector_id ); //phpcs:ignore WordPress.DB.PreparedSQL
WFCO_Model_ConnectorMeta::delete_multiple( $sql_query );
foreach ( $new_data as $key => $val ) {
$meta_data = array();
$meta_data['connector_id'] = $connector_id;
$meta_data['meta_key'] = $key;
$meta_data['meta_value'] = maybe_serialize( $val );
WFCO_Model_ConnectorMeta::insert( $meta_data );
}
}
public static function is_load_admin_assets( $screen_type = 'all' ) {
$screen = get_current_screen();
if ( 'all' === $screen_type ) {
if ( filter_input( INPUT_GET, 'page' ) === 'autonami' ) {
return true;
}
} elseif ( 'all' === $screen_type || 'settings' === $screen_type ) {
if ( filter_input( INPUT_GET, 'page' ) === 'autonami' && filter_input( INPUT_GET, 'tab' ) === 'settings' ) {
return true;
}
}
return apply_filters( 'wfco_enqueue_scripts', false, $screen_type, $screen );
}
public static function array_flatten( $array ) {
if ( ! is_array( $array ) ) {
return false;
}
$result = iterator_to_array( new RecursiveIteratorIterator( new RecursiveArrayIterator( $array ) ), false );
return $result;
}
public static function pr( $arr ) {
echo '<pre>';
print_r( $arr );
echo '</pre>';
}
public static function slugify_classname( $class_name ) {
$new_class_name = self::custom_sanitize_title( $class_name );
$new_class_name = str_replace( '_', '-', $new_class_name );
return $new_class_name;
}
/**
* Custom sanitize title method to avoid conflicts with WordPress hooks on sanitize_title
*
* @param string $title The title to sanitize
* @return string The sanitized title
*/
private static function custom_sanitize_title( $title ) {
$title = remove_accents( $title );
$title = sanitize_title_with_dashes( $title );
return $title;
}
/**
* Recursive Un-serialization based on WP's is_serialized();
*
* @param $val
*
* @return mixed|string
* @see is_serialized()
*/
public static function unserialize_recursive( $val ) {
/**$pattern = "/.*\{(.*)\}/";*/
if ( is_serialized( $val ) ) {
$val = trim( $val );
$ret = maybe_unserialize( $val );
if ( is_array( $ret ) ) {
foreach ( $ret as &$r ) {
$r = self::unserialize_recursive( $r );
}
}
return $ret;
} elseif ( is_array( $val ) ) {
foreach ( $val as &$r ) {
$r = self::unserialize_recursive( $r );
}
return $val;
} else {
return $val;
}
}
public static function get_option() {
return;
}
public static function active_class( $trigger_slug ) {
if ( self::get_current_trigger() === $trigger_slug ) {
return 'current';
}
return '';
}
public static function get_current_trigger() {
if ( 'autonami' === filter_input( INPUT_GET, 'page', FILTER_UNSAFE_RAW ) && filter_input( INPUT_GET, 'status', FILTER_UNSAFE_RAW ) ) {
return filter_input( INPUT_GET, 'status', FILTER_UNSAFE_RAW );
}
return 'all';
}
public static function string2hex( $string ) {
$hex = '';
for ( $i = 0; $i < strlen( $string ); $i ++ ) {
$hex .= dechex( ord( $string[ $i ] ) );
}
return $hex;
}
public static function maybe_filter_boolean_strings( $options ) {
$cloned_option = $options;
foreach ( $options as $key => $value ) {
if ( is_object( $options ) ) {
if ( $value === 'true' || $value === true ) {
$cloned_option->$key = true;
}
if ( $value === 'false' || $value === false ) {
$cloned_option->$key = false;
}
} elseif ( is_array( $options ) ) {
if ( $value === 'true' || $value === true ) {
$cloned_option[ $key ] = true;
}
if ( $value === 'false' || $value === false ) {
$cloned_option[ $key ] = false;
}
}
}
return $cloned_option;
}
public static function is_add_on_exist( $add_on = 'MultiProduct' ) {
$status = false;
if ( class_exists( 'WFCO_' . $add_on ) ) {
$status = true;
}
return $status;
}
public static function get_date_format() {
return get_option( 'date_format', '' ) . ' ' . get_option( 'time_format', '' );
}
public static function between( $needle, $that, $inthat ) {
return self::before( $that, self::after( $needle, $inthat ) );
}
public static function before( $needle, $inthat ) {
return substr( $inthat, 0, strpos( $inthat, $needle ) );
}
public static function after( $needle, $inthat ) {
if ( ! is_bool( strpos( $inthat, $needle ) ) ) {
return substr( $inthat, strpos( $inthat, $needle ) + strlen( $needle ) );
}
}
public static function clean_ascii_characters( $content ) {
if ( '' === $content ) {
return $content;
}
$content = str_replace( '%', '_', $content );
$content = str_replace( '!', '_', $content );
$content = str_replace( '\"', '_', $content );
$content = str_replace( '#', '_', $content );
$content = str_replace( '$', '_', $content );
$content = str_replace( '&', '_', $content );
$content = str_replace( '(', '_', $content );
$content = str_replace( ')', '_', $content );
$content = str_replace( '(', '_', $content );
$content = str_replace( '*', '_', $content );
$content = str_replace( ',', '_', $content );
$content = str_replace( '', '_', $content );
$content = str_replace( '.', '_', $content );
$content = str_replace( '/', '_', $content );
return $content;
}
/**
* Function to get timezone string by checking WordPress timezone settings
* @return mixed|string|void
*/
public static function wc_timezone_string() {
// if site timezone string exists, return it
if ( $timezone = get_option( 'timezone_string' ) ) {
return $timezone;
}
// get UTC offset, if it isn't set then return UTC
if ( 0 === ( $utc_offset = get_option( 'gmt_offset', 0 ) ) ) {
return 'UTC';
}
// get timezone using offset manual
return self::get_timezone_by_offset( $utc_offset );
}
/**
* Function to get timezone string based on specified offset
*
* @param $offset
*
* @return string
*/
public static function get_timezone_by_offset( $offset ) {
switch ( $offset ) {
case '-12':
return 'GMT-12';
break;
case '-11.5':
return 'Pacific/Niue'; // 30 mins wrong
break;
case '-11':
return 'Pacific/Niue';
break;
case '-10.5':
return 'Pacific/Honolulu'; // 30 mins wrong
break;
case '-10':
return 'Pacific/Tahiti';
break;
case '-9.5':
return 'Pacific/Marquesas';
break;
case '-9':
return 'Pacific/Gambier';
break;
case '-8.5':
return 'Pacific/Pitcairn'; // 30 mins wrong
break;
case '-8':
return 'Pacific/Pitcairn';
break;
case '-7.5':
return 'America/Hermosillo'; // 30 mins wrong
break;
case '-7':
return 'America/Hermosillo';
break;
case '-6.5':
case '-6':
return 'America/Belize';
break;
case '-5.5':
return 'America/Belize'; // 30 mins wrong
break;
case '-5':
return 'America/Panama';
break;
case '-4.5':
return 'America/Lower_Princes'; // 30 mins wrong
break;
case '-4':
return 'America/Curacao';
break;
case '-3.5':
return 'America/Paramaribo'; // 30 mins wrong
break;
case '-3':
return 'America/Recife';
break;
case '-2.5':
return 'America/St_Johns';
break;
case '-2':
return 'America/Noronha';
break;
case '-1.5':
return 'Atlantic/Cape_Verde'; // 30 mins wrong
break;
case '-1':
return 'Atlantic/Cape_Verde';
break;
case '+1':
return 'Africa/Luanda';
break;
case '+1.5':
return 'Africa/Mbabane'; // 30 mins wrong
break;
case '+2':
return 'Africa/Harare';
break;
case '+2.5':
return 'Indian/Comoro'; // 30 mins wrong
break;
case '+3':
return 'Asia/Baghdad';
break;
case '+3.5':
return 'Indian/Mauritius'; // 30 mins wrong
break;
case '+4':
return 'Indian/Mauritius';
break;
case '+4.5':
return 'Asia/Kabul';
break;
case '+5':
return 'Indian/Maldives';
break;
case '+5.5':
return 'Asia/Kolkata';
break;
case '+5.75':
return 'Asia/Kathmandu';
break;
case '+6':
return 'Asia/Urumqi';
break;
case '+6.5':
return 'Asia/Yangon';
break;
case '+7':
return 'Antarctica/Davis';
break;
case '+7.5':
return 'Asia/Jakarta'; // 30 mins wrong
break;
case '+8':
return 'Asia/Manila';
break;
case '+8.5':
return 'Asia/Pyongyang';
break;
case '+8.75':
return 'Australia/Eucla';
break;
case '+9':
return 'Asia/Tokyo';
break;
case '+9.5':
return 'Australia/Darwin';
break;
case '+10':
return 'Australia/Brisbane';
break;
case '+10.5':
return 'Australia/Lord_Howe';
break;
case '+11':
return 'Antarctica/Casey';
break;
case '+11.5':
return 'Pacific/Auckland'; // 30 mins wrong
break;
case '+12':
return 'Pacific/Wallis';
break;
case '+12.75':
return 'Pacific/Chatham';
break;
case '+13':
return 'Pacific/Fakaofo';
break;
case '+13.75':
return 'Pacific/Chatham'; // 1 hr wrong
break;
case '+14':
return 'Pacific/Kiritimati';
break;
default:
return 'UTC';
break;
}
}
/**
* Generate random string
*
* @param int $length
*
* @return string
*/
public static function generateRandomString( $length = 5 ) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen( $characters );
$randomString = '';
for ( $i = 0; $i < $length; $i ++ ) {
$randomString .= $characters[ rand( 0, $charactersLength - 1 ) ];
}
return $randomString;
}
/**
* Get all merge tags from string
*
* @param $text
*
* @return array|null
*/
public static function get_merge_tags_from_text( $text ) {
$merge_tags = null;
preg_match_all( '/\{{(.*?)\}}/', $text, $more_merge_tags );
if ( is_array( $more_merge_tags[1] ) && count( $more_merge_tags[1] ) > 0 ) {
$merge_tags = $more_merge_tags[1];
}
return $merge_tags;
}
public static function get_single_connector_data( $connector_slug, $meta_key = null ) {
$data_to_return = [];
if ( is_null( $meta_key ) ) {
if ( isset( WFCO_Common::$connectors_saved_data[ $connector_slug ] ) ) {
$data_to_return = WFCO_Common::$connectors_saved_data[ $connector_slug ];
return $data_to_return;
}
}
if ( isset( WFCO_Common::$connectors_saved_data[ $connector_slug ][ $meta_key ] ) ) {
$data_to_return = WFCO_Common::$connectors_saved_data[ $connector_slug ][ $meta_key ];
}
return $data_to_return;
}
public static function get_call_object( $connector_slug, $call_slug ) {
$all_connectors = WFCO_Load_Connectors::get_all_connectors();
return $all_connectors[ $connector_slug ][ $call_slug ];
}
}
}

View File

@@ -0,0 +1,113 @@
<?php
if ( ! class_exists( 'WFCO_Connector_api' ) ) {
#[AllowDynamicProperties]
class WFCO_Connector_api {
private $license = '';
private $connector = '';
private $action = 'find_connector';
private $package = [];
private $api_params = [];
private $api_url = 'https://myaccount.funnelkit.com/';
private $response_data = [];
public function __construct( $license = '', $connector = '', $action = 'find_connector' ) {
if ( '' !== $license ) {
$this->license = trim( $license );
}
if ( '' !== $connector ) {
$this->connector = trim( $connector );
}
if ( '' !== $action ) {
$this->action = trim( $action );
}
$this->api_url = add_query_arg( array(
'wc-api' => 'am-connector',
), $this->api_url );
$this->api_params = [
'connector_api' => 'yes',
'action' => $this->action,
'data' => [],
];
}
public function set_action( $action ) {
$this->action = trim( $action );
return $this;
}
/**
* @param array $data Associative array
* @param bool $reset
*/
public function set_data( $data = [], $reset = false ) {
if ( is_array( $data ) && count( $data ) > 0 ) {
foreach ( $data as $key => $d ) {
$this->api_params['data'][ $key ] = $d;
}
}
return $this;
}
public function get_license() {
return $this->license;
}
public function get_connector() {
return $this->connector;
}
public function get_package() {
return $this->package;
}
public function create_license() {
$this->find_connector();
}
public function find_connector() {
$this->api_params['data']['connector'] = $this->connector;
$this->api_params['data']['license'] = $this->license;
$this->fetch_data();
return $this;
}
private function fetch_data() {
$this->api_params['action'] = $this->action;
$this->api_params['data']['platform'] = home_url();
$request = wp_remote_post( $this->api_url, [
'timeout' => 15,
'sslverify' => false,
'body' => $this->api_params,
] );
if ( ! is_wp_error( $request ) ) {
$this->response_data = json_decode( wp_remote_retrieve_body( $request ), true );
}
if ( ! empty( $this->response_data ) ) {
$this->package = $this->response_data;
}
}
public function get() {
$this->fetch_data();
return $this;
}
}
}

View File

@@ -0,0 +1,27 @@
<?php
if ( ! class_exists( 'WFCO_Connector_Screen_Factory' ) ) {
#[AllowDynamicProperties]
abstract class WFCO_Connector_Screen_Factory {
private static $screens = [];
public static function create( $slug, $data ) {
$type = $data['type'];
self::$screens[ $type ][ $slug ] = new WFCO_Connector_Screen( $slug, $data );
}
public static function get( $screen ) {
return self::$screens[ $screen ];
}
public static function getAll( $type = '' ) {
if ( empty( $type ) ) {
return self::$screens;
}
return isset( self::$screens[ $type ] ) ? self::$screens[ $type ] : [];
}
}
}

View File

@@ -0,0 +1,106 @@
<?php
if ( ! class_exists( 'WFCO_Connector_Screen' ) ) {
#[AllowDynamicProperties]
class WFCO_Connector_Screen {
private $slug = '';
private $image = '';
private $name = '';
private $desc = '';
private $is_active = false;
private $activation_url = '';
private $file = '';
private $connector_class = '';
private $source = '';
private $support = [];
private $type = 'FunnelKit Automations';
private $show_setting_btn = true;
public function __construct( $slug, $data ) {
$this->slug = $slug;
if ( is_array( $data ) && count( $data ) > 0 ) {
foreach ( $data as $property => $val ) {
if ( is_array( $val ) ) {
$this->{$property} = $val;
continue;
}
if ( is_bool( $val ) || in_array( $val, [ 'true', 'false' ], true ) ) {
$this->{$property} = (bool) $val;
continue;
}
$this->{$property} = trim( $val );
}
}
}
public function get_logo() {
return $this->image;
}
public function is_active() {
return $this->is_active;
}
public function is_installed() {
}
public function activation_url() {
return $this->activation_url;
}
public function get_path() {
return $this->file;
}
public function get_class() {
return $this->connector_class;
}
public function get_source() {
return $this->source;
}
public function get_support() {
return $this->support;
}
public function get_slug() {
return $this->slug;
}
public function get_type() {
return $this->type;
}
public function get_name() {
return $this->name;
}
public function get_desc() {
return $this->desc;
}
public function is_activated() {
if ( class_exists( $this->connector_class ) ) {
return true;
}
return false;
}
public function show_setting_btn() {
return $this->show_setting_btn;
}
public function is_present() {
$plugins = get_plugins();
$file = trim( $this->file );
if ( '' !== $this->file && isset( $plugins[ $file ] ) ) {
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,265 @@
<?php
if ( ! class_exists( 'BWF_CO' ) ) {
#[AllowDynamicProperties]
abstract class BWF_CO {
public static $GET = 1;
public static $POST = 2;
public static $DELETE = 3;
public static $PUT = 4;
public static $PATCH = 5;
/** @var string Connector folder directory */
public $dir = __DIR__;
/** @var string Autonami integration class name */
public $autonami_int_slug = '';
/** @var null Nice name */
public $nice_name = null;
/** @var bool Connector has settings */
public $is_setting = true;
/** @var string Public directory URL */
protected $connector_url = '';
/** @var array Connector keys which are tracked during syncing and update */
protected $keys_to_track = [];
protected $form_req_keys = [];
protected $sync = false;
protected $is_oauth = false;
/** @var bool Connector is available for pro: default true */
public $is_pro = true;
/** @var bool If connector is configured through a direct url */
public $direct_connect = false;
public $is_new = 0;
protected $priority = 10;
/**
* Loads all calls of current connector
*/
public function load_calls() {
$resource_dir = $this->dir . '/calls';
if ( @file_exists( $resource_dir ) ) {
foreach ( glob( $resource_dir . '/class-*.php' ) as $filename ) {
$call_class = require_once( $filename );
if ( ( is_object( $call_class ) || is_string( $call_class ) ) && method_exists( $call_class, 'get_instance' ) ) {
$call_obj = $call_class::get_instance();
$call_obj->set_connector_slug( $this->get_slug() );
WFCO_Load_Connectors::register_calls( $call_obj );
}
}
}
do_action( 'bwfan_' . $this->get_slug() . '_actions_loaded' );
}
public function get_slug() {
return sanitize_title( get_class( $this ) );
}
/**
* Handles the settings form submission
*
* @param $data
* @param string $type
*
* @return $array
*/
public function handle_settings_form( $data, $type = 'save' ) {
$old_data = [];
$new_data = [];
$status = 'failed';
$resp = array(
'status' => $status,
'id' => 0,
'message' => '',
);
/** Validating form settings */
if ( 'sync' !== $type ) {
$is_valid = $this->validate_settings_fields( $data, $type );
if ( false === $is_valid ) {
$resp['message'] = $this->get_connector_messages( 'connector_settings_missing' );
return $resp;
}
}
switch ( $type ) {
case 'save':
$new_data = $this->get_api_data( $data );
if ( is_array( $new_data['api_data'] ) && count( $new_data['api_data'] ) > 0 && isset( $new_data['status'] ) && 'failed' !== $new_data['status'] ) {
$id = WFCO_Common::save_connector_data( $new_data['api_data'], $this->get_slug(), 1 );
$resp['id'] = $id;
$resp['message'] = $this->get_connector_messages( 'connector_saved' );
}
break;
case 'update':
$saved_data = WFCO_Common::$connectors_saved_data;
$old_data = $saved_data[ $this->get_slug() ];
$new_data = $this->get_api_data( $data );
if ( isset( $new_data['status'] ) && 'success' === $new_data['status'] ) {
$resp['message'] = $this->get_connector_messages( 'connector_updated' );
}
break;
case 'sync':
$saved_data = WFCO_Common::$connectors_saved_data;
$old_data = $saved_data[ $this->get_slug() ];
$new_data = $this->get_api_data( $old_data );
if ( isset( $new_data['status'] ) && 'success' === $new_data['status'] ) {
$resp['message'] = $this->get_connector_messages( 'connector_synced' );
}
break;
}
$resp['status'] = $this->get_response_status( $new_data, 'status' );
if ( '' === $resp['message'] && isset( $new_data['message'] ) && '' !== $new_data['message'] ) {
$resp['message'] = $new_data['message'];
}
$resp['data_changed'] = 0;
/** Return for save type case */
if ( 'save' === $type ) {
return $resp;
}
/** Assigning ID */
$resp['id'] = $data['id'];
/** Saving new data */
WFCO_Common::update_connector_data( $new_data['api_data'], $resp['id'] );
/** Tracking if data changed */
$is_data_changed = $this->track_sync_changes( $new_data['api_data'], $old_data );
if ( true === $is_data_changed ) {
do_action( 'change_in_connector_data', $this->get_slug() );
$resp['data_changed'] = 1;
}
return $resp;
}
/**
* Validating connector form settings fields, all required fields should be present with values
*
* @param $data
* @param string $type
*
* @return boolean
*
* @todo empty values need to check
*/
protected function validate_settings_fields( $data, $type = 'save' ) {
$available_keys = array_keys( $data );
if ( 'save' !== $type ) {
$available_keys[] = 'id';
}
$diff = array_diff( $this->form_req_keys, $available_keys );
if ( count( $diff ) > 0 ) {
return false;
}
return true;
}
public function get_connector_messages( $key = 'connector_saved' ) {
$messages = array(
'connector_saved' => __( 'Connector saved successfully', 'woofunnels' ), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'connector_synced' => __( 'Connector synced successfully', 'woofunnels' ), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'connector_updated' => __( 'Connector updated successfully', 'woofunnels' ), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
'connector_settings_missing' => __( 'Connector settings missing', 'woofunnels' ), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
);
return ( isset( $messages[ $key ] ) ) ? $messages[ $key ] : '';
}
/**
* Get data from the API call, must required function otherwise call
*
* @param $data
*
* @return array
*/
protected function get_api_data( $data ) {
return array(
'status' => 'failed',
'message' => __( 'Connector forgot to override the method - get_api_data.', 'woofunnels' ), // phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
);
}
public function get_response_status( $data, $key = 'status' ) {
$value = ( isset( $data[ $key ] ) ) ? $data[ $key ] : '';
$value = ( 'status' === $key && empty( $value ) ) ? 'failed' : $value;
return $value;
}
/**
* Track connector old and new data and return if any data change detected.
*
* @param $new_data
* @param $old_data
*
* @return bool
*/
protected function track_sync_changes( $new_data, $old_data ) {
$has_changes = false;
if ( empty( $this->keys_to_track ) || empty( $new_data ) || empty( $old_data ) ) {
return $has_changes;
}
foreach ( $this->keys_to_track as $key ) {
$str1 = isset( $new_data[ $key ] ) ? $new_data[ $key ] : '';
$str2 = isset( $old_data[ $key ] ) ? $old_data[ $key ] : '';
$str1 = is_array( $str1 ) ? wp_json_encode( $str1 ) : $str1;
$str2 = is_array( $str2 ) ? wp_json_encode( $str2 ) : $str2;
$diff = strcmp( $str1, $str2 );
if ( 0 === $diff ) {
continue;
}
$has_changes = true;
break;
}
return $has_changes;
}
public function get_image() {
return $this->connector_url . '/views/logo.png';
}
public function has_settings() {
return $this->is_setting;
}
public function is_syncable() {
return $this->sync;
}
public function is_oauth() {
return $this->is_oauth;
}
/**
* Get the connector loading priority
*
* @return int|mixed
*/
public function get_priority() {
return $this->priority;
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! class_exists( 'WFCO_Db' ) ) {
/**
* Class WFCO_Db
* @package Autonami
* @author XlPlugins
*/
#[AllowDynamicProperties]
class WFCO_Db {
private static $ins = null;
/**
* WFCO_Db constructor.
*/
public function __construct() {
add_action( 'plugins_loaded', [ $this, 'load_db_classes' ], 8 );
}
/**
* Return the object of current class
*
* @return null|WFCO_Db
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Include all the DB Table files
*/
public static function load_db_classes() {
$connector_dir = __DIR__ . '/db';
foreach ( glob( $connector_dir . '/class-*.php' ) as $_field_filename ) {
$file_data = pathinfo( $_field_filename );
if ( isset( $file_data['basename'] ) && 'index.php' === $file_data['basename'] ) {
continue;
}
require_once( $_field_filename );
}
}
}
if ( class_exists( 'WFCO_Db' ) ) {
WFCO_Db::get_instance();
}
}

View File

@@ -0,0 +1,206 @@
<?php
if ( ! class_exists( 'WFCO_Load_Connectors' ) ) {
#[AllowDynamicProperties]
class WFCO_Load_Connectors {
/** @var class instance */
private static $ins = null;
/** @var array All connectors with object */
private static $connectors = array();
/** @var array All calls with object */
private static $registered_calls = array();
/** @var array All calls objects group by connectors */
private static $registered_connectors_calls = array();
public function __construct() {
add_action( 'rest_api_init', [ $this, 'load_connectors_rest_call' ], 8 );
add_action( 'current_screen', [ $this, 'load_connectors_admin' ], 8 );
add_action( 'admin_init', [ $this, 'load_connectors_admin_ajax' ], 8 );
}
/**
* Return class instance
*
* @return class|WFCO_Load_Connectors
*/
public static function get_instance() {
if ( null == self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Include all connectors files directly
*
* @return void
*/
public static function load_connectors_direct() {
do_action( 'wfco_load_connectors' );
}
/**
* Include all connectors files on rest endpoints
*
* @return void
*/
public static function load_connectors_rest_call() {
$rest_route = isset( $_GET['rest_route'] ) ? $_GET['rest_route'] : '';
if ( empty( $rest_route ) ) {
$rest_route = $_SERVER['REQUEST_URI'];
}
if ( empty( $rest_route ) ) {
return;
}
if ( strpos( $rest_route, 'autonami/' ) === false && strpos( $rest_route, 'woofunnel_customer/' ) === false && strpos( $rest_route, 'funnelkit-app' ) === false && strpos( $rest_route, 'autonami-app' ) === false && strpos( $rest_route, 'funnelkit-automations' ) === false && strpos( $rest_route, 'autonami-webhook' ) === false && strpos( $rest_route, 'woofunnels/' ) === false && strpos( $rest_route, '/omapp/' ) === false ) {
return;
}
do_action( 'wfco_load_connectors' );
}
/**
* Include all connectors files on admin screen
*
* @return void
*/
public static function load_connectors_admin() {
$screen = get_current_screen();
if ( ! is_object( $screen ) ) {
return;
}
if ( empty( $screen->id ) || ( 'toplevel_page_autonami' !== $screen->id && 'funnelkit-automations_page_autonami-automations' !== $screen->id ) ) {
return;
}
do_action( 'wfco_load_connectors' );
}
/**
* Include all connectors files on admin ajax call
*
* @return void
*/
public static function load_connectors_admin_ajax() {
if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) {
return;
}
$ajax_action = $_POST['action'] ?? '';
if ( empty( $ajax_action ) ) {
return;
}
$array = [ 'wfco', 'bwfan', 'bwf_' ];
foreach ( $array as $value ) {
if ( strpos( $ajax_action, $value ) !== false ) {
do_action( 'wfco_load_connectors' );
break;
}
}
}
/**
* Register a connector with their object
* Assign to static property $connectors
* Load connector respective calls
*
* @param $class
*/
public static function register( $class ) {
if ( ! class_exists( $class ) && ! method_exists( $class, 'get_instance' ) ) {
return;
}
$temp_ins = $class::get_instance();
if ( ! $temp_ins instanceof BWF_CO ) {
return;
}
$slug = $temp_ins->get_slug();
self::$connectors[ $slug ] = $temp_ins;
$temp_ins->load_calls();
}
/**
* Register a call with their object
* Assign to static property $registered_calls
* Assign to static property $registered_connectors_calls
*
* @param WFCO_Call $call_obj
*/
public static function register_calls( WFCO_Call $call_obj ) {
if ( method_exists( $call_obj, 'get_instance' ) ) {
$slug = $call_obj->get_slug();
$connector_slug = $call_obj->get_connector_slug();
self::$registered_connectors_calls[ $connector_slug ][ $slug ] = self::$registered_calls[ $slug ] = $call_obj;
}
}
/**
* Return all the connectors with their calls objects
*
* @return array
*/
public static function get_all_connectors() {
return self::$registered_connectors_calls;
}
/**
* Returns Instance of single connector
*
* @param $connector
*
* @return BWF_CO
*/
public static function get_connector( $connector ) {
return isset( self::$connectors[ $connector ] ) ? self::$connectors[ $connector ] : null;
}
/**
* Returns all the active connectors i.e. plugin active
*
* @return array
*/
public static function get_active_connectors() {
return self::$connectors;
}
/**
* Return a call object if call slug is passed.
* Return all calls object if no single call slug passed.
*
* @param string $slug
*
* @return array|mixed
*/
public function get_calls( $slug = '' ) {
if ( empty( $slug ) ) {
return self::$registered_calls;
}
if ( isset( self::$registered_calls[ $slug ] ) ) {
return self::$registered_calls[ $slug ];
}
}
/**
* Return a call object based on the given slug.
*
* @param string $slug call slug
*
* @return WFCO_Call | null
*/
public function get_call( $slug ) {
return ( ! empty( $slug ) && isset( self::$registered_calls[ $slug ] ) ) ? self::$registered_calls[ $slug ] : null;
}
}
/**
* Initiate the class as soon as it is included
*/
WFCO_Load_Connectors::get_instance();
}

View File

@@ -0,0 +1,76 @@
<?php
if ( ! class_exists( 'WFCO_Model_ConnectorMeta' ) ) {
class WFCO_Model_ConnectorMeta extends WFCO_Model {
static $primary_key = 'ID';
public static function get_meta( $id, $key ) {
$rows = self::get_connector_meta( $id );
$value = '';
if ( count( $rows ) > 0 && isset( $rows[ $key ] ) ) {
$value = $rows[ $key ];
}
return $value;
}
public static function get_connector_meta( $id ) {
if ( 0 === $id ) {
return [];
}
global $wpdb;
$table = self::_table();
$sql_query = "SELECT * FROM $table WHERE connector_id =%d";
$sql_query = $wpdb->prepare( $sql_query, $id ); //phpcs:ignore WordPress.DB.PreparedSQL
$result = $wpdb->get_results( $sql_query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL
$meta = [];
if ( is_array( $result ) && count( $result ) > 0 ) {
foreach ( $result as $meta_values ) {
$key = $meta_values['meta_key'];
$meta[ $key ] = maybe_unserialize( $meta_values['meta_value'] );
}
}
return $meta;
}
private static function _table() {
global $wpdb;
$table_name = strtolower( get_called_class() );
$table_name = str_replace( 'wfco_model_', 'wfco_', $table_name );
return $wpdb->prefix . $table_name;
}
public static function get_connectors_meta( $ids = [] ) {
$meta = [];
if ( empty( $ids ) || ! is_array( $ids ) ) {
return $meta;
}
global $wpdb;
$table = self::_table();
$count = count( $ids );
$placeholders = array_fill( 0, $count, '%d' );
$placeholders = implode( ', ', $placeholders );
/** Fetching connectors meta - single query */
$query = "Select * FROM $table WHERE connector_id IN ($placeholders)";
$query = $wpdb->prepare( $query, $ids ); // WPCS: unprepared SQL OK
$result = self::get_results( $query );
if ( is_array( $result ) && count( $result ) > 0 ) {
foreach ( $result as $meta_values ) {
$meta[ $meta_values['connector_id'] ][ $meta_values['meta_key'] ] = maybe_unserialize( $meta_values['meta_value'] );
}
}
return $meta;
}
}
}

View File

@@ -0,0 +1,28 @@
<?php
if ( ! class_exists( 'WFCO_Model_Connectors' ) ) {
class WFCO_Model_Connectors extends WFCO_Model {
static $primary_key = 'ID';
public static function count_rows( $dependency = null ) {
global $wpdb;
$table_name = self::_table();
$sql = 'SELECT COUNT(*) FROM ' . $table_name;
if ( 'all' !== filter_input( INPUT_GET, 'status', FILTER_UNSAFE_RAW ) ) {
$status = filter_input( INPUT_GET, 'status', FILTER_UNSAFE_RAW );
$status = ( 'active' === $status ) ? 1 : 2;
$sql = $wpdb->prepare( "SELECT COUNT(*) FROM $table_name WHERE status = %d", $status ); //phpcs:ignore WordPress.DB.PreparedSQL
}
return $wpdb->get_var( $sql ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL
}
private static function _table() {
global $wpdb;
$table_name = strtolower( get_called_class() );
$table_name = str_replace( 'wfco_model_', 'wfco_', $table_name );
return $wpdb->prefix . $table_name;
}
}
}

View File

@@ -0,0 +1,2 @@
<?php
# Silence is golden.

View File

@@ -0,0 +1,2 @@
<?php
// Silence is golden.