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,199 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Paid Membership Pro Detection
*/
if ( ! function_exists( 'bwfan_is_paid_membership_pro_active' ) ) {
function bwfan_is_paid_membership_pro_active() {
return BWFAN_PRO_Plugin_Dependency::paid_membership_active_check();
}
}
/**
* Thrive Lead Form Detection
*/
if ( ! function_exists( 'bwfan_is_tve_active' ) ) {
function bwfan_is_tve_active() {
return BWFAN_PRO_Plugin_Dependency::tve_active_check();
}
}
/**
* Thrive Lead architech Detection
*/
if ( ! function_exists( 'bwfan_is_tve_architect_active' ) ) {
function bwfan_is_tve_architect_active() {
return BWFAN_PRO_Plugin_Dependency::tve_architect_active_check();
}
}
/**
* Learndash Detection
*/
if ( ! function_exists( 'bwfan_is_learndash_active' ) ) {
function bwfan_is_learndash_active() {
return BWFAN_PRO_Plugin_Dependency::learndash_active_check();
}
}
/**
* Ninja Forms Detection
*/
if ( ! function_exists( 'bwfan_is_ninja_forms_active' ) ) {
function bwfan_is_ninja_forms_active() {
return BWFAN_PRO_Plugin_Dependency::ninja_forms_active_check();
}
}
/**
* Fluent Forms Detection
*/
if ( ! function_exists( 'bwfan_is_fluent_forms_active' ) ) {
function bwfan_is_fluent_forms_active() {
return BWFAN_PRO_Plugin_Dependency::fluent_forms_active_check();
}
}
/**
* Caldera Forms Detection
*/
if ( ! function_exists( 'bwfan_is_caldera_forms_active' ) ) {
function bwfan_is_caldera_forms_active() {
return BWFAN_PRO_Plugin_Dependency::caldera_forms_active_check();
}
}
/**
* Optin Forms Detection
*/
if ( ! function_exists( 'bwfan_is_optin_forms_active' ) ) {
function bwfan_is_optin_forms_active() {
return BWFAN_PRO_Plugin_Dependency::optin_forms_active_check();
}
}
/**
* Forminator Forms Detection
*/
if ( ! function_exists( 'bwfan_is_forminator_forms_active' ) ) {
function bwfan_is_forminator_forms_active() {
return BWFAN_PRO_Plugin_Dependency::forminator_forms_active_check();
}
}
/**
* Wishlist plugin Detection
*/
if ( ! function_exists( 'bwfan_is_wc_wishlist_active' ) ) {
function bwfan_is_wc_wishlist_active() {
return BWFAN_PRO_Plugin_Dependency::wc_wishlist_active_check();
}
}
/**
*
* Weglot language plugin
*/
if ( ! function_exists( 'bwfan_is_weglot_active' ) ) {
function bwfan_is_weglot_active() {
return BWFAN_PRO_Plugin_Dependency::weglot_active_check();
}
}
/**
* Wishlist Member plugin by Wishlist Products
*/
if ( ! function_exists( 'bwfan_is_wlm_active' ) ) {
function bwfan_is_wlm_active() {
return BWFAN_PRO_Plugin_Dependency::wlm_active_check();
}
}
/**
* Woocommerce Advanced Shipping
*/
if ( ! function_exists( 'bwfan_is_woocommerce_advanced_shipping_pro_active' ) ) {
function bwfan_is_woocommerce_advanced_shipping_pro_active() {
return BWFAN_PRO_Plugin_Dependency::wc_advanced_shipping_active_check();
}
}
/**
* Advanced Coupons for woocommerce free
*/
if ( ! function_exists( 'bwfan_is_advanced_coupon_for_woocommerce_active' ) ) {
function bwfan_is_advanced_coupon_for_woocommerce_active() {
return BWFAN_PRO_Plugin_Dependency::wc_advanced_coupons_active_check();
}
}
if ( ! function_exists( 'bwfan_is_loyalty_program_for_woocommerce_active' ) ) {
function bwfan_is_loyalty_program_for_woocommerce_active() {
return BWFAN_PRO_Plugin_Dependency::wc_loyalty_program_active_check();
}
}
/**
* Funnel Builder Lite
*/
if ( ! function_exists( 'bwfan_is_funnel_active' ) ) {
function bwfan_is_funnel_active() {
return BWFAN_PRO_Plugin_Dependency::bwfan_is_funnel_active_check();
}
}
/**
* Yith Wishlist plugin Detection
*/
if ( ! function_exists( 'bwfan_is_yith_wishlist_active' ) ) {
function bwfan_is_yith_wishlist_active() {
return BWFAN_PRO_Plugin_Dependency::yith_wishlist_active_check();
}
}
/**
* TI WC Wishlist plugin Detection
*/
if ( ! function_exists( 'bwfan_is_ti_wc_wishlist_active' ) ) {
function bwfan_is_ti_wc_wishlist_active() {
return BWFAN_PRO_Plugin_Dependency::ti_wc_wishlist_active_check();
}
}
/**
* XL Next move plugin Detection
*/
if ( ! function_exists( 'bwfan_is_xl_nextmove_thankyou_active' ) ) {
function bwfan_is_xl_nextmove_thankyou_active() {
return BWFAN_PRO_Plugin_Dependency::xl_nextmove_thankyou_active_check();
}
}
/**
* WooCommerce Orders Tracking Premium plugin Detection
*/
if ( ! function_exists( 'bwfan_wc_order_tracking_active' ) ) {
function bwfan_wc_order_tracking_active() {
return BWFAN_PRO_Plugin_Dependency::wc_order_tracking_active_check();
}
}
/**
* FunnelKit stripe payment gateway
*/
if ( ! function_exists( 'bwfan_is_fk_stripe_active' ) ) {
function bwfan_is_fk_stripe_active() {
return BWFAN_PRO_Plugin_Dependency::bwfan_is_fk_stripe_active();
}
}
/**
* FunnelKit stripe payment gateway
*/
if ( ! function_exists( 'bwfan_is_funnel_builder_pro_active' ) ) {
function bwfan_is_funnel_builder_pro_active() {
return BWFAN_PRO_Plugin_Dependency::bwfan_is_funnel_builder_pro_active();
}
}

View File

@@ -0,0 +1,33 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class BWFAN_Contact_Confirmation {
public static function maybe_create_confirmation_page() {
$settings = get_option( 'bwfan_global_settings', array() );
if ( is_array( $settings ) && isset( $setings['bwfan_contact_confirmation_page'] ) ) {
$post = get_post( absint( $settings['bwfan_contact_confirmation_page'] ) );
if ( $post instanceof WP_Post && absint( $post->ID ) > 0 ) {
return;
}
}
$new_page = wp_insert_post( array(
'post_title' => __( "Confirmation", 'wp-marketing-automations-pro' ),
'post_content' => "Thanks for subscribing.",
'post_status' => 'publish',
'post_type' => 'page',
) );
if ( empty( $new_page ) || is_wp_error( $new_page ) ) {
$message = empty( $new_page ) ? 'Unable to create new Confirmation page' : $new_page->get_error_message();
BWFAN_Core()->logger->log( $message, 'contact_confirmation' );
}
$settings = ! is_array( $settings ) ? [] : $settings;
$settings['bwfan_contact_confirmation_page'] = $new_page;
update_option( 'bwfan_global_settings', $settings );
}
}

View File

@@ -0,0 +1,326 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_Conversions' ) ) {
class BWFAN_Conversions {
private static $ins = null;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
add_action( 'woocommerce_order_refunded', array( $this, 'remove_conversion' ) );
add_action( 'woocommerce_order_status_cancelled', array( $this, 'remove_conversion' ) );
add_action( 'before_delete_post', array( $this, 'remove_conversion_on_deletion' ), 10, 2 );
add_filter( 'bwfan_get_global_settings', array( $this, 'modify_conversion_def_value_global' ), 10, 1 );
add_action( 'bwfan_external_event_settings', array( $this, 'bwfan_event_global_tracking_enable' ) );
add_action( 'bwf_normalize_contact_meta_after_save', array( $this, 'process_order_for_conversion' ), 5, 3 );
}
/**
* Helper function
*
* Runs on bwf_normalize_contact_meta_after_save
*
* @param $bwf_contact WooFunnels_Contact
* @param $order_id
* @param $order WC_Order
*/
public function process_order_for_conversion( $bwf_contact, $order_id, $order ) {
/** Don't process orders for conversion during the WC Import (Indexing) */
if ( true === WooFunnels_DB_Updater::$indexing ) {
return;
}
/** If renewal order, don't mark conversion */
if ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order ) ) {
return;
}
/** Check if the Conversion already exists: */
$existing_conversion = BWFAN_Model_Conversions::get_specific_rows( 'wcid', absint( $order_id ) );
if ( ! empty( $existing_conversion ) ) {
return;
}
$order_id = absint( $order_id );
if ( ! $order instanceof WC_Order ) {
$order = wc_get_order( absint( $order_id ) );
}
if ( ! $order instanceof WC_Order || 'shop_order' !== $order->get_type() ) {
return;
}
$contact_id = $bwf_contact->get_id();
if ( empty( $contact_id ) ) {
return;
}
/** checking if there is any used $coupons of autonami generated */
$coupons = $order->get_coupon_codes();
if ( is_array( $coupons ) && count( $coupons ) > 0 ) {
$is_conversion = $this->check_coupon_for_conversion( $contact_id, $order_id, $order, $coupons );
if ( true === $is_conversion ) {
/** Found used coupon created by automation or broadcast */
return;
}
}
global $wpdb;
$global_settings = BWFAN_Common::get_global_settings();
$email_order_conversion_days = $global_settings['bwfan_order_tracking_conversion'];
$email_order_strtotime = $email_order_conversion_days * DAY_IN_SECONDS;
$order_creation_date = $order->get_date_created();
$order_from = ( strtotime( $order_creation_date ) - $email_order_strtotime );
$order_from = date( 'Y-m-d', $order_from );
$order_to = date( 'Y-m-d', strtotime( $order_creation_date ) );
/** Get automation ids in which don't need to mark conversion */
$skip_aids = BWFAN_PRO_Common::get_skip_conversion_automations();
$skip_aids = implode( ', ', $skip_aids );
/** If empty then use single quotes to avoid the sql error */
if ( empty( $skip_aids ) ) {
$skip_aids = "''";
}
$email_open = '(`mode` = 1 && `open` > 0)';
if ( false === apply_filters( 'bwfan_conversion_on_email_open', true ) ) {
$email_open = '(`mode` = 1 && `click` > 0)';
}
/**
* Fetching conversations where email opened or sms clicked of automation or broadcast within given date range
*/
$query = $wpdb->prepare( "SELECT `ID`, `cid`, `oid`, `type` FROM `{$wpdb->prefix}bwfan_engagement_tracking` WHERE DATE(`created_at`) >= %s AND DATE(`created_at`) <= %s AND ($email_open OR ((`mode` = 2 || `mode` = 3) && `click` > 0)) AND `hash_code` != '' AND `cid` = %d AND `oid` > 0 AND `type` IN (1,2) AND ( `oid` NOT IN ($skip_aids) ) ORDER BY `updated_at` DESC LIMIT 0,1", $order_from, $order_to, $contact_id );
$results = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
/** No conversations found */
if ( ! is_array( $results ) || 0 === count( $results ) ) {
return;
}
foreach ( $results as $conversation_data ) {
$this->add_new( $order_id, $conversation_data['ID'], $contact_id, $conversation_data['oid'], $conversation_data['type'] );
}
}
/**
* @param int $order_id
* @param int $conversation_id
* @param int $contact_id
* @param int $source_id
* @param int $source_type
*
* @return false|int
*/
public function add_new( $order_id, $conversation_id, $contact_id, $source_id, $source_type = 1 ) {
if ( ! class_exists( 'WooCommerce' ) ) {
return false;
}
if ( ! absint( $order_id ) > 0 || ! absint( $conversation_id ) > 0 || ! absint( $contact_id ) > 0 || ! absint( $source_id ) > 0 ) {
return false;
}
/** checking if conversion enable for automation event */
if ( 1 === absint( $source_type ) ) {
$is_conversion_enable = self::is_automation_conversion_track( $source_id );
if ( ! $is_conversion_enable ) {
return false;
}
}
$order = wc_get_order( absint( $order_id ) );
if ( ! $order instanceof WC_Order || in_array( $order->get_status(), array( 'failed', 'pending', 'cancelled', 'refunded' ) ) ) {
return false;
}
$order_base_total = $order->get_meta( '_bwfan_order_total_base' );
$order_total = ! empty( $order_base_total ) ? $order_base_total : $order->get_total();
/** @todo order base total needs to calculate and add like we did in abandonment */
$order_date = $order->get_date_paid();
$order_date = ! $order_date instanceof WC_DateTime ? $order->get_date_created() : $order_date;
if ( ! $order_date instanceof WC_DateTime ) {
$order_date = current_time( 'mysql', 1 );
} else {
$order_date->setTimezone( new DateTimeZone( 'UTC' ) );
$order_date = $order_date->format( 'Y-m-d H:i:s' );
}
$data = array(
'wcid' => absint( $order_id ),
'cid' => absint( $contact_id ),
'trackid' => absint( $conversation_id ),
'oid' => absint( $source_id ),
'otype' => absint( $source_type ),
'wctotal' => $order_total,
'date' => $order_date
);
BWFAN_Model_Conversions::insert( $data );
return BWFAN_Model_Conversions::insert_id();
}
/** checking if settings is on in automations
*
* @param $automation_id
*
* @return bool
*/
public static function is_automation_conversion_track( $automation_id ) {
$automation_meta = BWFAN_Core()->automations->get_automation_data_meta( $automation_id );
$automation_event_data = isset( $automation_meta['event_meta'] ) && ! empty( $automation_meta['event_meta'] ) ? $automation_meta['event_meta'] : array();
/** if automation version 2 then create conversion */
if ( isset( $automation_meta['v'] ) && 2 === absint( $automation_meta['v'] ) ) {
return true;
}
/** when email_open_click not set don't create conversations */
if ( ! isset( $automation_event_data['conversion_track'] ) || 1 !== absint( $automation_event_data['conversion_track'] ) ) {
return false;
}
return true;
}
/**
* @param int $order_id
*/
public function remove_conversion( $order_id ) {
if ( empty( $order_id ) ) {
return;
}
$conversions = BWFAN_Model_Conversions::get_specific_rows( 'wcid', $order_id );
if ( empty( $conversions ) ) {
return;
}
foreach ( $conversions as $conversion ) {
BWFAN_Model_Conversions::delete( $conversion['ID'] );
}
}
public function modify_conversion_def_value_global( $settings ) {
if ( ! isset( $settings['bwfan_order_tracking_conversion'] ) || empty( $settings['bwfan_order_tracking_conversion'] ) ) {
$settings['bwfan_order_tracking_conversion'] = 15;
}
return $settings;
}
/**
* check coupon for conversions
*
* @param $contact_id
* @param $order_id
* @param $order
* @param $coupons
*
* @return bool
*/
public function check_coupon_for_conversion( $contact_id, $order_id, $order, $coupons ) {
$order_email = $order->get_billing_email();
$order_phone = $order->get_billing_phone();
if ( ! is_array( $coupons ) || 0 === count( $coupons ) ) {
return false;
}
foreach ( $coupons as $coupon ) {
$coupon_id = wc_get_coupon_id_by_code( $coupon );
$coupon_automation_id = absint( get_post_meta( $coupon_id, '_bwfan_automation_id', true ) );
/** checking if coupon created with automation */
if ( $coupon_automation_id > 0 ) {
/** @todo should check tracking id by automation id, if not then any tracking id */
$track_id = $this->get_tracking_id( $order_email, $order_phone );
$this->add_new( $order_id, $track_id, $contact_id, $coupon_automation_id, 1 );
return true;
}
/** checking if coupon created using broadcast */
$coupon_broadcast_id = absint( get_post_meta( $coupon_id, '_bwfan_broadcast_id', true ) );
if ( $coupon_broadcast_id > 0 ) {
$track_id = $this->get_tracking_id( $order_email, $order_phone );
$this->add_new( $order_id, $track_id, $contact_id, $coupon_broadcast_id, 2 );
return true;
}
}
return false;
}
public function bwfan_event_global_tracking_enable() {
?>
<div class="bwfan-events-email-tracking bwfan-col-sm-12 bwfan-p-0 bwfan-mt-15">
<#
conversion_tracking = '';
if(_.has(bwfan_automation_ui_data_detail.trigger.event_meta, 'conversion_track') ){
conversion_tracking = 'checked' ;
}
#>
<label class="bwfan-label-title">Conversion Tracking</label>
<div class="bwfan_email_tracking bwfan-mb-15">
<label for="bwfan_email_open">
<input type="checkbox" name="event_meta[conversion_track]" id="bwfan_conversion_track" value="1" {{conversion_tracking}}/>
<?php
esc_html_e( 'Track Conversions', 'wp-marketing-automations-pro' );
?>
</label>
</div>
</div>
<?php
}
/**
* Get track id using email, phone and automation id
*
* @param $order_email
* @param $order_phone
*
* @return int|mixed
*/
public static function get_tracking_id( $order_email, $order_phone ) {
global $wpdb;
$track_query = "select ID,oid,type from {$wpdb->prefix}bwfan_engagement_tracking where ((mode=1 && open>0) OR (mode=2 && click>0)) and hash_code !='' and send_to IN ('" . $order_email . "','" . $order_phone . "') order by created_at desc limit 0,1 ";
$track_results = $wpdb->get_results( $track_query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$track_id = ! empty( $track_results[0]['ID'] ) ? $track_results[0]['ID'] : 0;
return $track_id;
}
/**
* Delete conversion on deletion of order
*
* @param $order_id
* @param $post
*/
public function remove_conversion_on_deletion( $order_id, $post ) {
if ( empty( $order_id ) ) {
return;
}
if ( 'shop_order' !== $post->post_type ) {
return;
}
global $wpdb;
$query = $wpdb->prepare( "DELETE FROM {table_name} WHERE `wcid` = %d", $order_id );
BWFAN_Model_Conversions::query( $query );
}
}
BWFAN_Core::register( 'conversions', 'BWFAN_Conversions' );
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* BWFAN_Divi_Forms_Common
*/
class BWFAN_Divi_Forms_Common {
/**
* Extract form info from the Divi shortcode from wp post
*
* @return array
*/
public static function extract_forms_and_fields() {
global $wpdb;
$query = $wpdb->prepare( "SELECT `ID`, `post_content`, `post_title` FROM $wpdb->posts WHERE post_status NOT IN('trash', 'inherit', 'auto-draft') AND post_type IS NOT NULL AND post_type NOT LIKE %s AND post_content LIKE %s", 'revision', '%%et_pb_contact_form%%' );
$form_posts = $wpdb->get_results( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$data = array();
if ( empty( $form_posts ) ) {
return $data;
}
foreach ( $form_posts as $form_post ) {
// Get forms
$pattern_regex = '/\[et_pb_contact_form(.*?)](.+?)\[\/et_pb_contact_form]/';
preg_match_all( $pattern_regex, $form_post->post_content, $forms, PREG_SET_ORDER );
if ( empty( $forms ) ) {
continue;
}
foreach ( $forms as $form_number => $form ) {
$pattern_form = get_shortcode_regex( array( 'et_pb_contact_form' ) );
preg_match_all( "/$pattern_form/", $form[0], $forms_extracted, PREG_SET_ORDER );
if ( empty( $forms_extracted ) ) {
continue;
}
foreach ( $forms_extracted as $form_extracted ) {
$form_attrs = shortcode_parse_atts( $form_extracted[3] );
$form_id = isset( $form_attrs['_unique_id'] ) ? $form_attrs['_unique_id'] : '';
if ( empty( $form_id ) ) {
continue;
}
$form_id = sprintf( '%d-%s', $form_post->ID, $form_id ) . "-$form_number";
$form_title = isset( $form_attrs['title'] ) ? $form_attrs['title'] : __( 'No form title', 'wp-marketing-automations-pro' );
$form_title = sprintf( '%s - %s', $form_post->post_title, $form_title );
// extracting form fields from each form
$fields = self::extract_form_fields( $form[0] );
$data[ $form_id ]['title'] = $form_title;
$data[ $form_id ]['fields'] = $fields;
}
}
}
return $data;
}
/**
* Extracting fields from the form shortcode
*
* @param $content_shortcode
*
* @return array
*/
public static function extract_form_fields( $content_shortcode ) {
$fields = array();
$pattern = get_shortcode_regex( array( 'et_pb_contact_field' ) );
preg_match_all( "/$pattern/", $content_shortcode, $contact_fields, PREG_SET_ORDER );
if ( empty( $contact_fields ) ) {
return $fields;
}
foreach ( $contact_fields as $contact_field ) {
$contact_field_attrs = shortcode_parse_atts( $contact_field[3] );
$field_id = strtolower( self::array_get( $contact_field_attrs, 'field_id' ) );
$fields[] = array(
'field_title' => self::array_get( $contact_field_attrs, 'field_title', __( 'No title', 'wp-marketing-automations-pro' ) ),
'field_id' => $field_id,
'field_type' => self::array_get( $contact_field_attrs, 'field_type', 'text' )
);
}
return $fields;
}
/**
* @param $array
* @param $address
* @param $default
* extract each field from fields array
*
* @return mixed|string
*/
public static function array_get( $array, $address, $default = '' ) {
$keys = is_array( $address ) ? $address : explode( '.', $address );
$value = $array;
foreach ( $keys as $key ) {
if ( ! empty( $key ) && isset( $key[0] ) && '[' === $key[0] ) {
$index = substr( $key, 1, - 1 );
if ( is_numeric( $index ) ) {
$key = (int) $index;
}
}
if ( ! isset( $value[ $key ] ) ) {
return $default;
}
$value = $value[ $key ];
}
return $value;
}
public static function extract_unique_form_id( $form_id ) {
if ( strpos( $form_id, '-' ) === false ) {
return $form_id;
}
$form_unique_id = explode( '-', $form_id );
/** Remove form number */
array_pop( $form_unique_id );
/** Remove post id */
array_shift( $form_unique_id );
return implode( '-', $form_unique_id );
}
}

View File

@@ -0,0 +1,385 @@
<?php
#[AllowDynamicProperties]
class BWFAN_Engagement_Tracking {
private $_db_row = [];
private $_merge_tags = [];
private $_has_changes = false;
/**
* @var BWFCRM_Contact $_contact
*/
private $_contact = null;
public function __construct( $id_or_data = '' ) {
if ( empty( $id_or_data ) ) {
return;
}
if ( is_numeric( $id_or_data ) ) {
$row = BWFAN_Model_Engagement_Tracking::get( absint( $id_or_data ) );
$this->fill_object_from_array( $row );
$this->fill_merge_tags_from_db();
}
if ( is_array( $id_or_data ) ) {
$this->fill_object_from_array( $id_or_data );
}
}
public function fill_merge_tags_from_db() {
if ( ! $this->is_valid() ) {
return false;
}
$tags = BWFAN_Model_Engagement_Trackingmeta::get_merge_tags( $this->get_id() );
if ( empty( $tags ) || ! is_array( $tags ) ) {
return false;
}
$this->_merge_tags = $tags;
return true;
}
public function add_merge_tags_from_string( $string, $merge_tags_data = [] ) {
if ( empty( $string ) ) {
return false;
}
$merge_tags = BWFCRM_Core()->merge_tags->fetch_tags_from_string( $string, $merge_tags_data );
$this->_merge_tags = is_array( $this->_merge_tags ) ? array_replace( $this->_merge_tags, $merge_tags ) : $merge_tags;
$this->_has_changes = true;
return true;
}
public function is_valid() {
return ! empty( $this->get_id() ) && is_numeric( $this->get_id() ) && $this->_contact instanceof BWFCRM_Contact && $this->_contact->is_contact_exists();
}
public function is_contact_valid() {
return $this->_contact instanceof BWFCRM_Contact && $this->_contact->is_contact_exists();
}
public function fill_object_from_array( $data ) {
if ( ! is_array( $data ) || ! isset( $data['ID'] ) || ! isset( $data['oid'] ) ) {
return;
}
$this->_db_row = $data;
if ( ! isset( $this->_db_row['cid'] ) || ! is_numeric( $this->_db_row['cid'] ) ) {
return;
}
$cid = absint( $this->_db_row['cid'] );
$this->_contact = new BWFCRM_Contact( $cid );
}
public function set_contact( $contact ) {
if ( empty( $contact ) ) {
return;
}
$contact = $contact instanceof BWFCRM_Contact ? $contact : new BWFCRM_Contact( $contact );
if ( $this->is_contact_valid() && $this->_contact->get_id() !== $contact->get_id() ) {
$this->_has_changes = true;
}
$this->_contact = $contact;
}
public function set_mode( $mode ) {
if ( empty( $mode ) || ! is_numeric( $mode ) ) {
return;
}
if ( isset( $this->_db_row['mode'] ) && absint( $this->_db_row['mode'] ) !== absint( $mode ) ) {
$this->_has_changes = true;
}
$this->_db_row['mode'] = absint( $mode );
}
public function set_type( $type ) {
if ( empty( $type ) || ! is_numeric( $type ) ) {
return;
}
if ( isset( $this->_db_row['type'] ) && absint( $this->_db_row['type'] ) !== absint( $type ) ) {
$this->_has_changes = true;
}
$this->_db_row['type'] = absint( $type );
}
public function set_send_to( $send_to ) {
if ( empty( $send_to ) ) {
return;
}
if ( isset( $this->_db_row['send_to'] ) && $this->_db_row['send_to'] !== $send_to ) {
$this->_has_changes = true;
}
$this->_db_row['send_to'] = $send_to;
}
public function set_template_id( $tid ) {
if ( empty( $tid ) ) {
return;
}
if ( isset( $this->_db_row['tid'] ) && absint( $this->_db_row['tid'] ) !== absint( $tid ) ) {
$this->_has_changes = true;
}
$this->_db_row['tid'] = absint( $tid );
}
public function set_status( $status ) {
if ( empty( $status ) ) {
return;
}
if ( isset( $this->_db_row['c_status'] ) && absint( $this->_db_row['c_status'] ) !== absint( $status ) ) {
$this->_has_changes = true;
}
$this->_db_row['c_status'] = absint( $status );
}
public function set_oid( $oid ) {
if ( empty( $oid ) ) {
return;
}
if ( isset( $this->_db_row['oid'] ) && absint( $this->_db_row['oid'] ) !== absint( $oid ) ) {
$this->_has_changes = true;
}
$this->_db_row['oid'] = absint( $oid );
}
public function set_merge_tags( $merge_tags ) {
if ( empty( $merge_tags ) || ! is_array( $merge_tags ) ) {
return;
}
$this->_merge_tags = $merge_tags;
$this->_has_changes = true;
}
/**
* Compute Hash Code
*/
public function enable_tracking() {
$send_to = $this->get_send_to();
if ( ! $this->is_contact_valid() || empty( $send_to ) ) {
return false;
}
$hash = md5( time() . $send_to );
$this->_db_row['hash'] = $hash;
$this->_has_changes = true;
return $hash;
}
public function disable_tracking() {
if ( ! empty( $this->_db_row['hash'] ) ) {
$this->_has_changes = true;
}
$this->_db_row['hash'] = '';
}
public function get_mode() {
if ( ! isset( $this->_db_row['mode'] ) || empty( $this->_db_row['mode'] ) ) {
return BWFAN_Email_Conversations::$MODE_EMAIL;
}
return absint( $this->_db_row['mode'] );
}
public function get_send_to() {
if ( ! isset( $this->_db_row['send_to'] ) || empty( $this->_db_row['send_to'] ) ) {
return false;
}
return $this->_db_row['send_to'];
}
public function get_hash() {
if ( ! isset( $this->_db_row['hash'] ) || empty( $this->_db_row['hash'] ) ) {
return '';
}
return $this->_db_row['hash'];
}
public function get_created_at() {
if ( ! isset( $this->_db_row['created_at'] ) || empty( $this->_db_row['created_at'] ) ) {
return '';
}
return $this->_db_row['created_at'];
}
public function get_updated_at() {
if ( ! isset( $this->_db_row['updated_at'] ) || empty( $this->_db_row['updated_at'] ) ) {
return '';
}
return $this->_db_row['updated_at'];
}
public function get_type() {
if ( ! isset( $this->_db_row['type'] ) || empty( $this->_db_row['type'] ) ) {
return 0;
}
return absint( $this->_db_row['type'] );
}
public function get_opens() {
if ( ! isset( $this->_db_row['open'] ) || empty( $this->_db_row['open'] ) ) {
return 0;
}
return absint( $this->_db_row['open'] );
}
public function get_clicks() {
if ( ! isset( $this->_db_row['click'] ) || empty( $this->_db_row['click'] ) ) {
return 0;
}
return absint( $this->_db_row['click'] );
}
public function get_oid() {
if ( ! isset( $this->_db_row['oid'] ) || empty( $this->_db_row['oid'] ) ) {
return 0;
}
return absint( $this->_db_row['oid'] );
}
public function get_author_id() {
if ( ! isset( $this->_db_row['author_id'] ) || empty( $this->_db_row['author_id'] ) ) {
return get_current_user_id();
}
return absint( $this->_db_row['author_id'] );
}
public function get_template_id() {
if ( ! isset( $this->_db_row['tid'] ) || empty( $this->_db_row['tid'] ) ) {
return 0;
}
return absint( $this->_db_row['tid'] );
}
public function get_status() {
if ( ! isset( $this->_db_row['c_status'] ) || empty( $this->_db_row['c_status'] ) ) {
return BWFAN_Email_Conversations::$STATUS_DRAFT;
}
return absint( $this->_db_row['c_status'] );
}
public function get_id() {
return ! empty( $this->_db_row['ID'] ) ? absint( $this->_db_row['ID'] ) : false;
}
public function get_contact() {
return $this->_contact;
}
public function get_merge_tags() {
return $this->_merge_tags;
}
public function save() {
if ( ! $this->is_contact_valid() ) {
return false;
}
$current_time = current_time( 'mysql', 1 );
$conversation = [
'cid' => $this->_contact->get_id(),
'hash_code' => $this->get_hash(),
'created_at' => $this->is_valid() && ! empty( $this->get_created_at() ) ? $this->get_created_at() : $current_time,
'updated_at' => true === $this->_has_changes ? $current_time : $this->get_updated_at(),
'mode' => $this->get_mode(),
'send_to' => $this->get_send_to(),
'type' => $this->get_type(),
'open' => $this->get_opens(),
'click' => $this->get_clicks(),
'oid' => $this->get_oid(),
'author_id' => $this->get_author_id(),
'tid' => $this->get_template_id(),
'c_status' => $this->get_status(),
];
if ( ! $this->is_valid() ) {
BWFCRM_Common::insert_engagement( $conversation, [
'%d', // cid
'%s', // hash_code
'%s', // created_at
'%s', // updated_at
'%d', // mode
'%s', // send_to
'%d', // type
'%d', // open
'%d', // click
'%d', // oid
'%d', // author_id
'%d', // tid
'%d', // c_status
] );
$id = BWFAN_Model_Engagement_Tracking::insert_id();
if ( ! empty( $id ) ) {
$this->_db_row['ID'] = absint( $id );
}
} else {
BWFAN_Model_Engagement_Tracking::update( $conversation, [ 'ID' => $this->get_id() ] );
}
$this->save_merge_tags();
$this->_has_changes = false;
return true;
}
public function save_merge_tags() {
if ( empty( $this->_merge_tags ) || ! is_array( $this->_merge_tags ) ) {
return false;
}
BWFAN_Model_Engagement_Trackingmeta::insert( array(
'eid' => $this->get_id(),
'meta_key' => 'merge_tags',
'meta_value' => wp_json_encode( $this->_merge_tags )
) );
return true;
}
public function fail_the_conversation() {
if ( ! $this->is_valid() ) {
return false;
}
$error = BWFCRM_Common::$captured_email_failed_message;
$error = ! empty( $error ) ? $error : __( 'Email not sent (Error Unknown)', 'wp-marketing-automations-pro' );
return BWFCRM_Core()->conversation->fail_the_conversation( $this->get_id(), $error );
}
}

View File

@@ -0,0 +1,87 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* BWFAN_Fix_Collation class
*/
if ( ! class_exists( 'BWFAN_Fix_Collation' ) ) {
class BWFAN_Fix_Collation {
/**
* Fix table collation
*
* @return bool
*/
public static function maybe_fix_collation_issue() {
global $wpdb;
$table1 = $wpdb->prefix . 'bwfan_message_unsubscribe';
$table2 = $wpdb->prefix . 'bwf_contact';
$table3 = $wpdb->prefix . 'bwf_contact_meta';
$table4 = $wpdb->prefix . 'bwf_wc_customers';
$collation1 = '';
$collation2 = '';
$charset = ( $wpdb->has_cap( 'collation' ) ) ? $wpdb->charset : '';
if ( empty( $charset ) ) {
return false;
}
$table1_columns = $wpdb->get_results( "SHOW FULL COLUMNS FROM {$table1}", ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( is_array( $table1_columns ) && count( $table1_columns ) > 0 ) {
$table1_columns = array_filter( $table1_columns, function ( $i ) {
return ( 'recipient' === $i['Field'] );
} );
}
if ( is_array( $table1_columns ) && count( $table1_columns ) > 0 ) {
$collation1 = array_column( $table1_columns, 'Collation' );
}
$collation1 = is_array( $collation1 ) ? $collation1[0] : '';
BWFAN_Common::log_test_data( "{$table1} table 'recipient' column collation is {$collation1}", 'collation-issue', true );
$table2_columns = $wpdb->get_results( "SHOW FULL COLUMNS FROM {$table2}", ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( is_array( $table2_columns ) && count( $table2_columns ) > 0 ) {
$table2_columns = array_filter( $table2_columns, function ( $i ) {
return ( 'email' === $i['Field'] );
} );
}
if ( is_array( $table2_columns ) && count( $table2_columns ) > 0 ) {
$collation2 = array_column( $table2_columns, 'Collation' );
}
$collation2 = is_array( $collation2 ) ? $collation2[0] : '';
BWFAN_Common::log_test_data( "{$table2} table 'email' column collation is {$collation2}", 'collation-issue', true );
if ( $collation1 === $collation2 ) {
return true;
}
$query = "ALTER TABLE {$table2} CHARACTER SET {$charset} COLLATE {$collation1};";
$res = $wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
BWFAN_Common::log_test_data( "Contact table modify query result: {$res}", 'collation-issue', true );
$query = "ALTER TABLE {$table2} MODIFY email VARCHAR(100) CHARACTER SET {$charset} COLLATE {$collation1};";
$res = $wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
BWFAN_Common::log_test_data( "Email column modify query result: {$res}", 'collation-issue', true );
$query = "ALTER TABLE {$table2} MODIFY contact_no VARCHAR(20) CHARACTER SET {$charset} COLLATE {$collation1};";
$res = $wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
BWFAN_Common::log_test_data( "Phone column modify query result: {$res}", 'collation-issue', true );
$query = "ALTER TABLE {$table3} CHARACTER SET {$charset} COLLATE {$collation1};";
$res = $wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
BWFAN_Common::log_test_data( "Contact Meta table modify query result: {$res}", 'collation-issue', true );
$query = "ALTER TABLE {$table4} CHARACTER SET {$charset} COLLATE {$collation1};";
$res = $wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
BWFAN_Common::log_test_data( "Customer table modify query result: {$res}", 'collation-issue', true );
return true;
}
}
}

View File

@@ -0,0 +1,306 @@
<?php
class BWFAN_Learndash_Common {
public static function init() {
add_filter( 'bwfan_select2_ajax_callable', array( __CLASS__, 'get_callable_object' ), 1, 2 );
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_assets' ), 99 );
add_action( 'wp_ajax_bwfan_get_learndash_quiz', array( __CLASS__, 'bwfan_get_learndash_quiz' ) );
}
public static function admin_enqueue_assets() {
if ( ! isset( $_GET['page'] ) || 'autonami' !== $_GET['page'] ) {
return;
}
/** Prevent LearnDash styles to interfere with Autonami Styles */
wp_dequeue_style( 'learndash-admin-settings-page' );
}
public static function get_callable_object( $is_empty, $data ) {
if ( 'sfwd-courses' === $data['type'] ) {
return [ __CLASS__, 'get_learndash_courses' ];
}
if ( 'sfwd-quizzes' === $data['type'] ) {
return [ __CLASS__, 'get_learndash_quizzes' ];
}
return $is_empty;
}
/**
* Get quizzes by searched term
*
* @param $searched_term
*/
public static function get_learndash_quizzes( $searched_term = '', $limit = 10 ) {
$query_params = array(
'post_type' => learndash_get_post_type_slug( 'quiz' ),
'posts_per_page' => $limit,
'post_status' => 'publish'
);
if ( '' !== $searched_term ) {
$query_params['s'] = $searched_term;
}
$query = new WP_Query( $query_params );
$results = array();
if ( $query->found_posts > 0 ) {
foreach ( $query->posts as $post ) {
$results[] = array(
'id' => $post->ID,
'text' => $post->post_title,
);
}
}
return array( 'results' => $results );
}
/**
* Get WpProQuiz_Model_Quiz models
*
* @return WpProQuiz_Model_Quiz[]
*/
public static function get_learndash_quizzes_models() {
$quiz_mapper = new WpProQuiz_Model_QuizMapper();
/** @var WpProQuiz_Model_Quiz[] $quizzes */
$quizzes = $quiz_mapper->fetchAll();
foreach ( $quizzes as $key => $quiz ) {
if ( empty( $quiz->getPostId() ) ) {
unset( $quizzes[ $key ] );
}
}
return $quizzes;
}
public static function get_learndash_courses( $searched_term = '', $limit = 10 ) {
$courses = array();
$results = array();
$query_params = array(
'post_type' => 'sfwd-courses',
'posts_per_page' => $limit,
'post_status' => 'publish',
);
if ( '' !== $searched_term ) {
$query_params['s'] = $searched_term;
}
$query = new WP_Query( $query_params );
if ( $query->found_posts > 0 ) {
foreach ( $query->posts as $post ) {
$results[] = array(
'id' => $post->ID,
'text' => $post->post_title,
);
}
}
$courses['results'] = $results;
return $courses;
}
/**
* Get LearnDash User's Group's Leaders
*
* @param int $user_id
*
* @return array|null
*/
public static function get_group_leaders_by_user_id( $user_id ) {
global $wpdb;
$query = $wpdb->prepare( "SELECT DISTINCT(user_id) FROM {$wpdb->usermeta} WHERE `meta_key` LIKE '%learndash_group_leaders_%' AND meta_value IN (SELECT meta_value as 'group' FROM {$wpdb->usermeta} WHERE `meta_key` LIKE '%learndash_group_users_%' AND user_id = %d)", $user_id );
return $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Get LearnDash Group's Leaders by Group ID
*
* @param $group_ids
*
* @return array|object|stdClass[]|null
*/
public static function get_group_leaders_by_group_id( $group_ids ) {
global $wpdb;
$meta_value = " AND meta_value = %d";
if ( is_array( $group_ids ) ) {
$string_placeholder = array_fill( 0, count( $group_ids ), '%d' );
$placeholder = implode( ', ', $string_placeholder );
$meta_value = " AND meta_value IN ($placeholder)";
}
$query = "SELECT DISTINCT(user_id) FROM {$wpdb->usermeta} WHERE `meta_key` LIKE '%learndash_group_leaders_%' {$meta_value}";
$query = $wpdb->prepare( $query, $group_ids );
return $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Get LearnDash User's Groups
*
* @param int $user_id
*
* @return array|null
*/
public static function get_groups_by_user_id( $user_id ) {
global $wpdb;
$query = $wpdb->prepare( "SELECT meta_value as 'group' FROM {$wpdb->usermeta} WHERE `meta_key` LIKE '%learndash_group_users_%' AND user_id = %d", $user_id );
return $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function get_user_quiz_attempts( $user_id ) {
return get_user_meta( $user_id, '_sfwd-quizzes', true );
}
/**
* Get LearnDash questions by quiz ID
*
* @param int $quiz_id
*
* @return array
*/
public static function get_learndash_quiz_questions( $quiz_id = 0 ) {
if ( empty( $quiz_id ) ) {
return array();
}
$questions = learndash_get_quiz_questions( absint( $quiz_id ) );
$questions = array_keys( $questions );
$questions_array = array();
foreach ( $questions as $key ) {
$questions_array[ $key ] = get_the_title( $key );
}
return $questions_array;
}
public static function get_learndash_quiz_questions_models( $quiz_id = 0 ) {
if ( empty( $quiz_id ) ) {
return array();
}
$question_mapper = new WpProQuiz_Model_QuestionMapper();
return $question_mapper->fetchAll( $quiz_id );
}
/**
* Get Answers from Quiz Results data (LearnDash)
*
* @param $results
* @param WpProQuiz_Model_Question[] $question_models
*
* @return array
*/
public static function get_learndash_quiz_answers_from_result_data( $results, $question_models ) {
$questions_and_answers = array();
foreach ( $results as $key => $result ) {
$questions_and_answers[ $key ] = $result['e']['r'];
}
// Map the question IDs into post IDs
foreach ( $question_models as $model ) {
foreach ( $questions_and_answers as $key => $result ) {
if ( $key === $model->getId() ) {
// Convert multiple choice from true / false into the selected option
if ( is_array( $result ) ) {
foreach ( $result as $n => $multiple_choice_answer ) {
if ( true === $multiple_choice_answer ) {
$answers = $model->getAnswerData();
foreach ( $answers as $x => $answer ) {
if ( $x === $n ) {
$result = $answer->getAnswer();
break 2;
}
}
}
}
}
$answers[ $model->getId() ] = $result;
}
}
}
return $questions_and_answers;
}
public function bwfan_get_learndash_quiz() {
BWFAN_PRO_Common::nocache_headers();
$finalarr = [];
$query = new WP_Query( array(
'post_type' => learndash_get_post_type_slug( 'quiz' ),
'posts_per_page' => - 1,
'post_status' => 'publish'
) );
if ( $query->found_posts > 0 ) {
foreach ( $query->posts as $post ) {
$finalarr[] = array(
'key' => $post->ID,
'value' => $post->post_title,
);
}
}
wp_send_json( array(
'results' => $finalarr
) );
exit;
}
/**
* fetching last user activity id by activity type
*
* @param $user_id
* @param $activity_type
*
* @return string|null
*/
public static function get_last_user_activity_by_type( $user_id, $activity_type ) {
global $wpdb;
$activity_date_col = 'access' === $activity_type ? 'activity_started' : 'activity_completed';
$sql = "SELECT `post_id`
FROM `{$wpdb->prefix}learndash_user_activity`
WHERE `activity_type`= %s
AND $activity_date_col IS NOT NULL
AND `user_id`=%d
ORDER BY $activity_date_col DESC LIMIT 1";
return $wpdb->get_var( $wpdb->prepare( $sql, $activity_type, $user_id ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* @param $course_id
*
* @return array|int|string|null
*/
public static function get_course_access_lists( $course_id ) {
$course_access_list_setting = learndash_get_setting( $course_id, 'course_access_list' );
$course_access_list_setting = learndash_convert_course_access_list( $course_access_list_setting, true );
$course_access_list_post_meta = get_post_meta( $course_id, 'course_access_list', true );
$course_access_list_post_meta = learndash_convert_course_access_list( $course_access_list_post_meta, true );
$course_access_list_user_meta = learndash_get_course_users_access_from_meta( $course_id );
$course_access_list_user_meta = learndash_convert_course_access_list( $course_access_list_user_meta, true );
$course_access_list = array_merge( $course_access_list_setting, $course_access_list_post_meta, $course_access_list_user_meta );
return array_unique( $course_access_list );
}
}

View File

@@ -0,0 +1,116 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_Message' ) ) {
#[AllowDynamicProperties]
class BWFAN_Message {
private $_id = 0;
private $_track_id = 0;
private $_subject = '';
private $_body = '';
private $_date = '';
public function __construct( $m_id = 0 ) {
if ( empty( absint( $m_id ) ) ) {
return;
}
$message = BWFAN_Model_Message::get( absint( $m_id ) );
if ( ! is_array( $message ) || empty( $message ) ) {
return;
}
$this->set_message( $message['ID'], $message['track_id'], $message['sub'], $message['body'], $message['date'] );
}
public function is_message_exists() {
return $this->get_id() > 0;
}
public function set_message( $id, $track_id, $subject, $body, $date = '' ) {
! empty( absint( $id ) ) && $this->set_id( absint( $id ) );
! empty( absint( $track_id ) ) && $this->set_track_id( absint( $track_id ) );
! empty( $subject ) && $this->set_subject( $subject );
! empty( $body ) && $this->set_body( $body );
! empty( $date ) && $this->set_date( $date );
}
public function get_id() {
return absint( $this->_id );
}
public function get_subject() {
return $this->_subject;
}
public function get_track_id() {
return $this->_track_id;
}
public function get_body() {
return $this->_body;
}
public function get_date() {
return $this->_date;
}
public function set_id( $id ) {
$this->_id = absint( $id );
}
public function set_body( $body ) {
$this->_body = $body;
}
public function set_track_id( $track_id ) {
$this->_track_id = $track_id;
}
public function set_date( $date ) {
$this->_date = $date;
}
public function set_subject( $subject ) {
$this->_subject = $subject;
}
/**
* @return int
*/
public function save() {
if ( empty( $this->get_track_id() ) && empty( $this->get_body() ) ) {
return false;
}
if ( 0 === $this->get_id() ) {
BWFAN_Model_Message::insert( array(
'track_id' => $this->get_track_id(),
'sub' => $this->get_subject(),
'body' => $this->get_body(),
'date' => current_time( 'mysql', 1 )
) );
$this->set_id( BWFAN_Model_Message::insert_id() );
} else {
BWFAN_Model_Message::update( array(
'sub' => $this->get_subject(),
'body' => $this->get_body()
), [ 'ID' => $this->get_id() ] );
}
return $this->get_id();
}
public function get_array() {
$message = array(
'ID' => $this->get_id(),
'track_id' => $this->get_track_id(),
'sub' => $this->get_subject(),
'body' => $this->get_body(),
'date' => $this->get_date()
);
return $message;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,435 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Class BWFAN_Pro_DB_Update
*
* @package Autonami
*
* @since 2.0.5
*/
#[AllowDynamicProperties]
class BWFAN_Pro_DB_Update {
private static $ins = null;
public $db_changes = [];
/**
* 0 - Null | nothing to do
* 1 - DB update can start
* 2 - DB update started
* 3 - DB update complete
*/
/**
* Class constructor
*/
public function __construct() {
add_action( 'admin_init', [ $this, 'db_update' ], 11 );
add_action( 'bwfan_pro_db_update_2_0_4', array( $this, 'db_update_2_0_4_cb' ) );
add_action( 'bwfan_pro_db_update_2_1_0', array( $this, 'db_update_2_1_0_cb' ) );
/**
* Scheduler to update date contact fields
* For 2.1.0
*/
add_action( 'bwfan_update_contact_fields', [ $this, 'bwfan_update_contact_fields' ], 10, 1 );
$this->db_changes = array(
'2.0.4' => '2_0_4',
'2.1.0' => '2_1_0'
);
}
/**
* Return the object of current class
*
* @return null|BWFAN_Pro_DB_Update
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Update pro db function for setting value
*/
public function db_update() {
$db_status = $this->get_saved_data( 'status' );
$db_version = $this->get_saved_data() ?? false;
$db_version = ( false === $db_version ) ? '2.0.3' : $db_version;
/** Status 1 = ready for run, 2 = in progress, 3 = complete */
if ( in_array( $db_status, [ 1, 2, 3 ] ) ) {
return;
}
foreach ( $this->db_changes as $version => $version_value ) {
if ( version_compare( $db_version, $version, '<' ) ) {
$value = [ $version => 1 ];
/** Should run or not */
if ( method_exists( $this, 'should_run_' . $version_value ) && false === call_user_func( [ $this, 'should_run_' . $version_value ] ) ) {
$value = [ $version => 0 ];
}
update_option( 'bwfan_pro_db_update', $value, true );
return;
}
}
}
/**
* Return version or status from the DB saved value
*
* @param string $type
*
* @return false|int|mixed|string|null
*/
public function get_saved_data( $type = 'version' ) {
$data = get_option( 'bwfan_pro_db_update', [] );
if ( ! is_array( $data ) ) {
return ( 'version' === $type ) ? false : 0;
}
/** Return version */
if ( 'version' === $type ) {
return key( $data );
}
$status = (int) current( $data );
/** If status is 2 (in processing) then check if action is scheduled */
if ( 2 === $status ) {
$this->is_action_scheduled( $data );
}
/** Return status */
return $status;
}
/**
* Schedule DB update action
*
* @return bool
*/
public function start_db_update() {
/** Status */
$status = $this->get_saved_data( 'status' );
if ( 0 === $status ) {
return false;
}
/** Check if already scheduled */
if ( in_array( $status, [ 2, 3 ] ) ) {
return true;
}
/** Version */
$version = $this->get_saved_data();
/** Schedule recurring action */
$this->schedule_action( $version );
return true;
}
/**
* Set the DB update current version value to 0
*
* @return bool
*/
public function dismiss_db_update() {
/** Version */
$version = $this->get_saved_data();
if ( false === $version ) {
return false;
}
return update_option( 'bwfan_pro_db_update', [ $version => 0 ], true );
}
/**
* Mark version complete and check for next DB update.
* If available then start it
*
* @param $version_no
*/
protected function mark_complete( $version_no ) {
$version_name = str_replace( ".", "_", $version_no );
BWFAN_Core()->logger->log( 'mark complete: ' . $version_no, 'db_update_' . $version_name );
/** Mark complete */
update_option( 'bwfan_pro_db_update', [ $version_no => 3 ], true );
/** Un-schedule action */
$version_name = str_replace( ".", "_", $version_no );
bwf_unschedule_actions( 'bwfan_pro_db_update_' . $version_name );
/** Maybe schedule next version */
if ( ! is_array( $this->db_changes ) || 0 === count( $this->db_changes ) ) {
return;
}
foreach ( $this->db_changes as $version => $version_value ) {
if ( version_compare( $version_no, $version, '<' ) ) {
/** Schedule recurring action */
$this->schedule_action( $version );
return;
}
}
}
/**
* Schedule recurring action
*
* @param $version
*/
protected function schedule_action( $version ) {
if ( empty( $version ) ) {
return false;
}
/** Mark DB update started */
update_option( 'bwfan_pro_db_update', [ $version => 2 ], true );
$version_name = str_replace( ".", "_", $version );
$action = 'bwfan_pro_db_update_' . $version_name;
$args = array( 'datetime' => current_time( 'mysql', 1 ) );
/** Check if action is already scheduled */
if ( ! bwf_has_action_scheduled( $action, $args, 'bwf_update' ) ) {
bwf_schedule_recurring_action( time(), 60, $action, $args, 'bwf_update' );
BWFAN_Core()->logger->log( 'scheduling action: ' . $version, 'db_update_' . $version_name );
}
return true;
}
/**
* Version 2.0.4 DB update callback
*
* @param $datetime
*/
public function db_update_2_0_4_cb( $datetime ) {
global $wpdb;
$time = time();
$key = 'bwfan_db_update_2_0_4_cb';
$field = BWFAN_Model_Fields::get_field_by_slug( 'last-sent' );
BWFAN_Core()->logger->log( 'call starts for: 2.0.4', 'db_update_2_0_4' );
do {
$db_cid = get_option( $key, 0 );
$query = $wpdb->prepare( "SELECT `cid`, DATE(MAX(`created_at`)) as `created_at` FROM `{$wpdb->prefix}bwfan_engagement_tracking` WHERE `cid` > %d AND `created_at` < %s GROUP BY `cid` ORDER BY `cid` ASC LIMIT 0, 20", $db_cid, $datetime );
$result = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( ! is_array( $result ) || 0 === count( $result ) ) {
delete_option( $key );
$this->mark_complete( '2.0.4' );
return;
}
foreach ( $result as $data ) {
$cid = $data['cid'];
$date = $data['created_at'];
$wpdb->update( $wpdb->prefix . 'bwf_contact_fields', array( 'f' . $field['ID'] => $date ), array( 'cid' => $cid ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
update_option( $key, $cid, true );
}
$ids = empty( $result ) ? [] : array_column( $result, 'cid' );
BWFAN_Core()->logger->log( 'updated: ' . implode( ', ', $ids ), 'db_update_2_0_4' );
} while ( $this->should_run( $time ) ); // keep going until we run out of time, or memory
}
/**
* Check if 2.0.4 version DB update is valid
*
* @return bool
*/
public function should_run_2_0_4() {
if ( empty( BWFAN_Model_Engagement_Tracking::get_first_engagement_id() ) ) {
return false;
}
return true;
}
/**
* Check if time limit or memory passed
*
* @param $time
*
* @return bool
*/
protected function should_run( $time ) {
/** If time exceeds */
if ( ( time() - $time ) > $this->get_threshold_time() ) {
return false;
}
/** If memory exceeds */
$ins = BWF_AS::instance();
return ! $ins->memory_exceeded();
}
/**
* Return call duration time in seconds
*
* @return mixed|void
*/
protected function get_threshold_time() {
return apply_filters( 'bwfan_db_update_call_duration', 20 );
}
public function db_update_2_1_0_cb() {
/** Check if already scheduled */
$date_fields = [];
if ( version_compare( BWFAN_VERSION, '2.5.0', '>=' ) ) {
$date_fields = bwf_options_get( 'contact_date_fields' );
} else {
$date_fields = get_option( 'contact_date_fields', [] );
}
if ( ! empty( $date_fields ) ) {
return;
}
global $wpdb;
$db_columns = $wpdb->get_results( "DESCRIBE {$wpdb->prefix}bwf_contact_fields", ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$date_columns = array_column( array_filter( $db_columns, function ( $col ) {
return $col['Type'] === 'date';
} ), 'Field' );
if ( empty( $date_columns ) ) {
$this->mark_complete( '2.1.0' );
BWFAN_Common::log_test_data( 'No date fields found', 'db_update_2_1_0' );
return;
}
BWFAN_Common::log_test_data( 'Found date fields: ' . implode( ', ', $date_columns ), 'db_update_2_1_0' );
if ( version_compare( BWFAN_VERSION, '2.5.0', '>=' ) ) {
bwf_options_update( 'contact_date_fields', $date_columns );
} else {
update_option( 'contact_date_fields', $date_columns, false );
}
foreach ( $date_columns as $col ) {
if ( ! bwf_has_action_scheduled( 'bwfan_update_contact_fields', [ 'field' => $col ] ) ) {
bwf_schedule_recurring_action( time(), ( 2 * MINUTE_IN_SECONDS ), 'bwfan_update_contact_fields', [ 'field' => $col ] );
}
}
}
public function bwfan_update_contact_fields( $field ) {
BWFAN_Common::log_test_data( 'Callback started for field: ' . $field, 'db_update_2_1_0' );
global $wpdb;
$contact = $wpdb->get_var( "SELECT `ID` FROM {$wpdb->prefix}bwf_contact_fields WHERE CAST(`{$field}` AS CHAR(10)) = '0000-00-00' LIMIT 0, 1" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( empty( $contact ) ) {
$this->check_and_mark_close_2_1_0( $field );
return;
}
$time = time();
try {
do {
$contacts = $wpdb->get_col( "SELECT `ID` FROM `{$wpdb->prefix}bwf_contact_fields` WHERE CAST(`{$field}` AS CHAR(10)) = '0000-00-00' LIMIT 0, 30" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( empty( $contacts ) ) {
$this->check_and_mark_close_2_1_0( $field );
break;
}
$placeholder = array_fill( 0, count( $contacts ), '%d' );
$placeholder = implode( ", ", $placeholder );
$query = $wpdb->prepare( "UPDATE `{$wpdb->prefix}bwf_contact_fields` SET `{$field}` = NULL WHERE `ID` IN ($placeholder);", $contacts );
$wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
} while ( $this->should_run( $time ) ); // keep going until we run out of time, or memory
} catch ( Error $e ) {
BWFAN_Common::log_test_data( 'SQL query update error for field: ' . $field, 'db_update_2_1_0' );
BWFAN_Common::log_test_data( $e->getMessage(), 'db_update_2_1_0' );
}
}
protected function check_and_mark_close_2_1_0( $field ) {
/** Field column updated, no records left */
BWFAN_Common::log_test_data( 'No data left to update for Field: ' . $field, 'db_update_2_1_0' );
if ( version_compare( BWFAN_VERSION, '2.5.0', '>=' ) ) {
$date_fields = bwf_options_get( 'contact_date_fields' );
} else {
$date_fields = get_option( 'contact_date_fields', [] );
}
if ( ( $key = array_search( $field, $date_fields ) ) !== false ) {
unset( $date_fields[ $key ] );
sort( $date_fields );
}
bwf_unschedule_actions( 'bwfan_update_contact_fields', [ 'field' => $field ] );
if ( empty( $date_fields ) ) {
BWFAN_Common::log_test_data( 'No date fields left to update', 'db_update_2_1_0' );
if ( version_compare( BWFAN_VERSION, '2.5.0', '>=' ) ) {
bwf_options_delete( 'contact_date_fields' );
} else {
delete_option( 'contact_date_fields' );
}
$this->mark_complete( '2.1.0' );
return;
}
if ( version_compare( BWFAN_VERSION, '2.5.0', '>=' ) ) {
bwf_options_update( 'contact_date_fields', $date_fields );
return;
}
update_option( 'contact_date_fields', $date_fields, false );
}
/**
* Check DB upgrade action scheduler is scheduled or not
*
* @return void
*/
public function is_action_scheduled( $versions ) {
if ( empty( $versions ) ) {
return;
}
foreach ( $versions as $version => $status ) {
if ( 2 !== intval( $status ) ) {
continue;
}
if ( ! in_array( $version, $this->db_changes, true ) ) {
delete_option( 'bwfan_pro_db_update' );
break;
}
$version_name = str_replace( ".", "_", $version );
$action = 'bwfan_pro_db_update_' . $version_name;
/** Check if action is already scheduled */
if ( ! bwf_has_action_scheduled( $action ) ) {
$args = array( 'datetime' => current_time( 'mysql', 1 ) );
bwf_schedule_recurring_action( time(), 60, $action, $args, 'bwf_update' );
}
}
}
}
BWFAN_Pro_DB_Update::get_instance();

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,347 @@
<?php
/**
* WC Dependency Checker
*/
#[AllowDynamicProperties]
class BWFAN_PRO_Plugin_Dependency {
private static $active_plugins;
/** checking paid membership pro is active
* @return bool
*/
public static function paid_membership_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
return in_array( 'paid-memberships-pro/paid-memberships-pro.php', self::$active_plugins, true ) || array_key_exists( 'paid-memberships-pro/paid-memberships-pro.php', self::$active_plugins );
}
public static function init() {
self::$active_plugins = (array) get_option( 'active_plugins', array() );
if ( is_multisite() ) {
self::$active_plugins = array_merge( self::$active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
}
}
/**
* check if thrive plugin active
* @return bool
*/
public static function tve_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
return in_array( 'thrive-leads/thrive-leads.php', self::$active_plugins, true ) || array_key_exists( 'thrive-leads/thrive-leads.php', self::$active_plugins );
}
/**
* @return bool
*/
public static function tve_architect_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
return in_array( 'thrive-visual-editor/thrive-visual-editor.php', self::$active_plugins, true ) || array_key_exists( 'thrive-visual-editor/thrive-visual-editor.php', self::$active_plugins );
}
/**
* Checking if learndash plugin active
* @return bool
*/
public static function learndash_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( defined( 'LEARNDASH_VERSION' ) ) {
return true;
}
return in_array( 'sfwd-lms/sfwd_lms.php', self::$active_plugins, true ) || array_key_exists( 'sfwd-lms/sfwd_lms.php', self::$active_plugins );
}
/**
* Checking if ninja form plugin active
* @return bool
*/
public static function ninja_forms_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( function_exists( 'Ninja_Forms' ) ) {
return true;
}
return in_array( 'ninja-forms/ninja-forms.php', self::$active_plugins, true ) || array_key_exists( 'ninja-forms/ninja-forms.php', self::$active_plugins );
}
/**
* Checking if fluent form plugin active
* @return bool
*/
public static function fluent_forms_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( defined( 'FLUENTFORM' ) ) {
return true;
}
return in_array( 'fluentform/fluentform.php', self::$active_plugins, true ) || array_key_exists( 'fluentform/fluentform.php', self::$active_plugins );
}
/**
* Checking if caldera form plugin active
* @return bool
*/
public static function caldera_forms_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'Caldera_Forms' ) ) {
return true;
}
return in_array( 'caldera-forms/caldera-core.php', self::$active_plugins, true ) || array_key_exists( 'caldera-forms/caldera-core.php', self::$active_plugins );
}
/**
* Checking if optim form plugin active
* @return bool
*/
public static function optin_forms_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'WFFN_Core' ) ) {
return true;
}
return in_array( 'funnel-builder/funnel-builder.php', self::$active_plugins, true ) || array_key_exists( 'woofunnels-flex-funnels/woofunnels-flex-funnels.php', self::$active_plugins );
}
/**
* Checking if forminator form plugin active
* @return bool
*/
public static function forminator_forms_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'Forminator' ) ) {
return true;
}
return in_array( 'forminator/forminator.php', self::$active_plugins, true ) || array_key_exists( 'forminator/forminator.php', self::$active_plugins );
}
public static function wc_wishlist_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'WC_Wishlists_Plugin' ) ) {
return true;
}
return in_array( 'woocommerce-wishlists/woocommerce-wishlists.php', self::$active_plugins, true ) || array_key_exists( 'woocommerce-wishlists/woocommerce-wishlists.php', self::$active_plugins );
}
/**
* Checking if weglot lanuage plugin active
* @return bool
*/
public static function weglot_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( defined( 'WEGLOT_NAME' ) ) {
return true;
}
return in_array( 'weglot/weglot.php', self::$active_plugins, true ) || array_key_exists( 'weglot/weglot.php', self::$active_plugins );
}
/**
* Checking if wishlist member plugin active
* @return bool
*/
public static function wlm_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'WishListMember' ) ) {
return true;
}
return in_array( 'wishlist-member-x/wpm.php', self::$active_plugins, true ) || array_key_exists( 'wishlist-member-x/wpm.php', self::$active_plugins );
}
/**
* WC Advanced shipping plugin checking
* @return bool
*/
public static function wc_advanced_shipping_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'WooCommerce_Advanced_Shipping' ) ) {
return true;
}
return in_array( 'woocommerce-advanced-shipping/woocommerce-advanced-shipping.php', self::$active_plugins, true ) || array_key_exists( 'woocommerce-advanced-shipping/woocommerce-advanced-shipping.php', self::$active_plugins );
}
/**
* Advanced Coupons for woocommerce free
* @return bool
*/
public static function wc_advanced_coupons_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'ACFWF' ) ) {
return true;
}
return in_array( 'advanced-coupons-for-woocommerce-free/advanced-coupons-for-woocommerce-free.php', self::$active_plugins, true ) || array_key_exists( 'advanced-coupons-for-woocommerce-free/advanced-coupons-for-woocommerce-free.php', self::$active_plugins );
}
public static function wc_loyalty_program_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'LPFW' ) ) {
return true;
}
return in_array( 'loyalty-program-for-woocommerce/loyalty-program-for-woocommerce.php', self::$active_plugins, true ) || array_key_exists( 'loyalty-program-for-woocommerce/loyalty-program-for-woocommerce.php', self::$active_plugins );
}
/**
* WC Advanced shipping plugin checking
* @return bool
*/
public static function bwfan_is_funnel_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'WFFN_Core' ) ) {
return true;
}
return in_array( 'funnel-builder.php', self::$active_plugins, true ) || array_key_exists( 'funnel-builder.php', self::$active_plugins );
}
/**
* Yith Wishlist plugin checking
* @return bool
*/
public static function yith_wishlist_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'YITH_WCWL' ) ) {
return true;
}
/** Checking for lite version */
if ( in_array( 'yith-woocommerce-wishlist/init.php', self::$active_plugins, true ) || array_key_exists( 'yith-woocommerce-wishlist/init.php', self::$active_plugins ) ) {
return true;
}
return in_array( 'yith-woocommerce-wishlist-premium/init.php', self::$active_plugins, true ) || array_key_exists( 'yith-woocommerce-wishlist-premium/init.php', self::$active_plugins );
}
/**
* TI WC Wishlist plugin checking
* @return bool
*/
public static function ti_wc_wishlist_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( in_array( 'ti-woocommerce-wishlist/ti-woocommerce-wishlist.php', self::$active_plugins, true ) || array_key_exists( 'ti-woocommerce-wishlist/ti-woocommerce-wishlist.php', self::$active_plugins ) ) {
return true;
}
return in_array( 'ti-woocommerce-wishlist-premium/ti-woocommerce-wishlist-premium.php', self::$active_plugins, true ) || array_key_exists( 'ti-woocommerce-wishlist-premium/ti-woocommerce-wishlist-premium.php', self::$active_plugins );
}
/**
* Xl next move plugin checking
* @return bool
*/
public static function xl_nextmove_thankyou_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
return in_array( 'thank-you-page-for-woocommerce-nextmove/woocommerce-thankyou-pages.php', self::$active_plugins, true ) || array_key_exists( 'thank-you-page-for-woocommerce-nextmove/woocommerce-thankyou-pages.php', self::$active_plugins );
}
/**
* Checking if WooCommerce Orders Tracking Premium plugin active
* @return bool
*/
public static function wc_order_tracking_active_check() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( in_array( 'woocommerce-orders-tracking/woocommerce-orders-tracking.php', self::$active_plugins, true ) || array_key_exists( 'woocommerce-orders-tracking/woocommerce-orders-tracking.php', self::$active_plugins ) ) {
return true;
}
return in_array( 'woo-orders-tracking/woo-orders-tracking.php', self::$active_plugins, true ) || array_key_exists( 'woo-orders-tracking/woo-orders-tracking.php', self::$active_plugins );
}
public static function bwfan_is_fk_stripe_active() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'FKWCS_Gateway_Stripe' ) ) {
return true;
}
return in_array( 'funnelkit-stripe-woo-payment-gateway/funnelkit-stripe-woo-payment-gateway.php', self::$active_plugins, true ) || array_key_exists( 'funnelkit-stripe-woo-payment-gateway/funnelkit-stripe-woo-payment-gateway.php', self::$active_plugins );
}
/**
* Funnel Builder Pro plugin checking
*
* @return bool
*/
public static function bwfan_is_funnel_builder_pro_active() {
if ( ! self::$active_plugins ) {
self::init();
}
if ( class_exists( 'WFFN_Pro_Core' ) && class_exists( 'WFOCU_Core' ) ) {
return true;
}
return in_array( 'funnel-builder-pro/funnel-builder-pro.php', self::$active_plugins, true ) || array_key_exists( 'funnel-builder-pro/funnel-builder-pro.php', self::$active_plugins );
}
}

View File

@@ -0,0 +1,266 @@
<?php
#[AllowDynamicProperties]
class BWFAN_Pro_WooFunnels_Support {
public static $_instance = null;
public $full_name = '';
public $is_license_needed = true;
/**
* @var WooFunnels_License_check
*/
public $license_instance;
protected $slug = 'autonami-automations-pro';
protected $encoded_basename = '';
private function __construct() {
$this->full_name = BWFAN_PRO_FULL_NAME;
$this->encoded_basename = sha1( BWFAN_PRO_PLUGIN_BASENAME );
add_filter( 'woofunnels_plugins_license_needed', array( $this, 'add_license_support' ), 10 );
add_action( 'init', array( $this, 'init_licensing' ), 12 );
add_action( 'woofunnels_licenses_submitted', array( $this, 'process_licensing_form' ) );
add_action( 'woofunnels_deactivate_request', array( $this, 'maybe_process_deactivation' ) );
if ( ! wp_next_scheduled( 'woofunnels_bwfan_license_check' ) ) {
wp_schedule_event( time(), 'daily', 'woofunnels_bwfan_license_check' );
}
add_action( 'woofunnels_bwfan_license_check', array( $this, 'license_check' ) );
add_action( 'admin_init', array( $this, 'maybe_handle_license_activation_wizard' ), 1 );
add_filter( 'woofunnels_default_reason_' . BWFAN_PRO_PLUGIN_BASENAME, function () {
return 1;
} );
add_filter( 'woofunnels_default_reason_default', function () {
return 1;
} );
// add_action( 'admin_menu', array( $this, 'add_menus' ), 80.1 );
}
/**
* @return BWFAN_Pro_WooFunnels_Support
*/
public static function get_instance() {
if ( null === self::$_instance ) {
self::$_instance = new self;
}
return self::$_instance;
}
public function woofunnels_page() {
if ( ! isset( $_GET['tab'] ) ) { // WordPress.CSRF.NonceVerification.NoNonceVerification
WooFunnels_dashboard::$selected = 'licenses';
}
WooFunnels_dashboard::load_page();
}
/**
* Adding WooCommerce sub-menu for global options
*/
public function add_menus() {
if ( true === WooFunnels_dashboard::$is_core_menu ) {
return;
}
add_menu_page( __( 'WooFunnels', 'woofunnels' ), __( 'WooFunnels', 'woofunnels' ), 'manage_options', 'woofunnels', array( $this, 'woofunnels_page' ), '', 59 );
add_submenu_page( 'woofunnels', __( 'Licenses', 'woofunnels' ), __( 'License', 'woofunnels' ), 'manage_options', 'woofunnels' );
WooFunnels_dashboard::$is_core_menu = true;
}
/**
* License management helper function to create a slug that is friendly with edd
*
* @param $name
*
* @return String
*/
public function slugify_module_name( $name ) {
return preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $name ) ) );
}
public function add_license_support( $plugins ) {
$status = 'invalid';
$renew = 'Please Activate';
$license = array(
'key' => '',
'email' => '',
'expires' => '',
);
$plugins_in_database = WooFunnels_License_check::get_plugins();
if ( is_array( $plugins_in_database ) && isset( $plugins_in_database[ $this->encoded_basename ] ) && count( $plugins_in_database[ $this->encoded_basename ] ) > 0 ) {
$status = 'active';
$renew = '';
$license = array(
'key' => $plugins_in_database[ $this->encoded_basename ]['data_extra']['api_key'],
'email' => $plugins_in_database[ $this->encoded_basename ]['data_extra']['license_email'],
'expires' => $plugins_in_database[ $this->encoded_basename ]['data_extra']['expires'],
);
}
$plugins[ $this->encoded_basename ] = array(
'plugin' => $this->full_name,
'product_version' => BWFAN_PRO_VERSION,
'product_status' => $status,
'license_expiry' => $renew,
'product_file_path' => $this->encoded_basename,
'existing_key' => $license,
);
return $plugins;
}
public function woofunnels_slugify_module_name( $name ) {
return preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $name ) ) );
}
public function init_licensing() {
if ( class_exists( 'WooFunnels_License_check' ) && $this->is_license_needed ) {
$this->license_instance = new WooFunnels_License_check( $this->encoded_basename );
$plugins = WooFunnels_License_check::get_plugins();
if ( isset( $plugins[ $this->encoded_basename ] ) && count( $plugins[ $this->encoded_basename ] ) > 0 ) {
$data = array(
'plugin_slug' => BWFAN_PRO_PLUGIN_BASENAME,
'plugin_name' => BWFAN_PRO_FULL_NAME,
'license_key' => $plugins[ $this->encoded_basename ]['data_extra']['api_key'],
'product_id' => $this->full_name,
'version' => BWFAN_PRO_VERSION,
);
$this->license_instance->setup_data( $data );
$this->license_instance->start_updater();
}
}
}
public function process_licensing_form( $posted_data ) {
if ( isset( $posted_data['license_keys'][ $this->encoded_basename ] ) ) {
$key = $posted_data['license_keys'][ $this->encoded_basename ]['key'];
$data = array(
'plugin_slug' => BWFAN_PRO_PLUGIN_BASENAME,
'plugin_name' => BWFAN_PRO_FULL_NAME,
'license_key' => $key,
'product_id' => $this->full_name,
'version' => BWFAN_PRO_VERSION,
);
$this->license_instance->setup_data( $data );
$this->license_instance->activate_license();
}
}
/**
* Validate is it is for email product deactivation
*
* @param $posted_data
*/
public function maybe_process_deactivation( $posted_data ) {
if ( isset( $posted_data['filepath'] ) && $posted_data['filepath'] === $this->encoded_basename ) {
$plugins = WooFunnels_License_check::get_plugins();
if ( isset( $plugins[ $this->encoded_basename ] ) && count( $plugins[ $this->encoded_basename ] ) > 0 ) {
$data = array(
'plugin_slug' => BWFAN_PRO_PLUGIN_BASENAME,
'plugin_name' => BWFAN_PRO_FULL_NAME,
'license_key' => $plugins[ $this->encoded_basename ]['data_extra']['api_key'],
'product_id' => $this->full_name,
'version' => BWFAN_PRO_VERSION,
);
$this->license_instance->setup_data( $data );
$this->license_instance->deactivate_license();
wp_safe_redirect( 'admin.php?page=' . $posted_data['page'] . '&tab=' . $posted_data['tab'] );
}
}
}
public function process_activation_api( $key ) {
$data = array(
'plugin_slug' => BWFAN_PRO_PLUGIN_BASENAME,
'plugin_name' => BWFAN_PRO_FULL_NAME,
'license_key' => $key,
'product_id' => $this->full_name,
'version' => BWFAN_PRO_VERSION,
);
BWFAN_Common::log_test_data( $data, 'bwfan-license' );
$this->license_instance->setup_data( $data );
$resp = $this->license_instance->activate_license();
BWFAN_Common::log_test_data( $resp, 'bwfan-license' );
return $resp;
}
public function process_deactivation_api() {
$plugins = WooFunnels_License_check::get_plugins();
$data = array(
'plugin_slug' => BWFAN_PRO_PLUGIN_BASENAME,
'plugin_name' => BWFAN_PRO_FULL_NAME,
'license_key' => $plugins[ $this->encoded_basename ]['data_extra']['api_key'],
'product_id' => $this->full_name,
'version' => BWFAN_PRO_VERSION,
);
BWFAN_Common::log_test_data( $data, 'bwfan-license' );
$this->license_instance->setup_data( $data );
$resp = $this->license_instance->deactivate_license();
BWFAN_Common::log_test_data( $resp, 'bwfan-license' );
return $resp;
}
public function license_check() {
$plugins = WooFunnels_License_check::get_plugins();
if ( isset( $plugins[ $this->encoded_basename ] ) && count( $plugins[ $this->encoded_basename ] ) > 0 ) {
$data = array(
'plugin_slug' => BWFAN_PRO_PLUGIN_BASENAME,
'license_key' => $plugins[ $this->encoded_basename ]['data_extra']['api_key'],
'product_id' => $this->full_name,
'version' => BWFAN_PRO_VERSION,
);
$this->license_instance->setup_data( $data );
$this->license_instance->license_status();
}
}
public function is_license_present() {
$plugins = WooFunnels_License_check::get_plugins();
if ( ! isset( $plugins[ $this->encoded_basename ] ) ) {
return false;
}
return true;
}
public function maybe_handle_license_activation_wizard() {
if ( filter_input( INPUT_POST, 'bwfan_verify_license' ) !== null ) {
$data = array(
'plugin_slug' => BWFAN_PRO_PLUGIN_BASENAME,
'plugin_name' => BWFAN_PRO_FULL_NAME,
'license_key' => filter_input( INPUT_POST, 'license_key' ),
'product_id' => $this->full_name,
'version' => BWFAN_PRO_VERSION,
);
$this->license_instance->setup_data( $data );
$data_response = $this->license_instance->activate_license();
if ( is_array( $data_response ) && true === $data_response['activated'] ) {
BWFAN_Wizard::set_license_state( true );
do_action( 'bwfan_license_activated', 'autonami-automations-pro' );
if ( filter_input( INPUT_POST, '_redirect_link' ) !== null ) {
wp_safe_redirect( filter_input( INPUT_POST, '_redirect_link' ) );
}
} else {
BWFAN_Wizard::set_license_state( false );
BWFAN_Wizard::set_license_key( filter_input( INPUT_POST, 'license_key' ) );
}
}
}
}
BWFAN_Pro_WooFunnels_Support::get_instance();

View File

@@ -0,0 +1,60 @@
<?php
class BWFAN_Wlm_Common {
public static function init() {
add_filter( 'bwfan_select2_ajax_callable', array( __CLASS__, 'get_callable_object' ), 1, 2 );
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'admin_enqueue_assets' ), 99 );
}
public static function admin_enqueue_assets() {
//phpcs:disable WordPress.Security.NonceVerification
if ( ! isset( $_GET['page'] ) || 'autonami' !== $_GET['page'] ) {
return;
}
/** Prevent wlm styles to interfere with Autonami Styles */
wp_dequeue_style( 'wlm-admin-settings-page' );
//phpcs:enable WordPress.Security.NonceVerification
}
public static function get_callable_object( $is_empty, $data ) {
if ( 'ppp' === $data['type'] ) {
return [ __CLASS__, 'get_all_pay_per_posts' ];
}
return $is_empty;
}
/**
* Get quizzes by searched term
*
* @param $searched_term
*/
public static function get_all_pay_per_posts( $searched_term = '' ) {
global $WishListMemberInstance;
$searched_term = '%' . $searched_term . '%';
$pay_per_posts = $WishListMemberInstance->get_pay_per_posts( array( 'ID', 'post_title' ), false, $searched_term );
$results = array();
if ( ! empty( $pay_per_posts ) ) {
foreach ( $pay_per_posts as $ppp ) {
$results[] = array(
'id' => $ppp->ID,
'text' => $ppp->post_title,
);
}
}
/*
* data should be return like this using result as the key
* when getting data using search
*/
return array( 'results' => $results );
}
}

View File

@@ -0,0 +1,251 @@
{
"AF": "Afghanistan",
"AX": "\u00c5land Islands",
"AL": "Albania",
"DZ": "Algeria",
"AS": "American Samoa",
"AD": "Andorra",
"AO": "Angola",
"AI": "Anguilla",
"AQ": "Antarctica",
"AG": "Antigua and Barbuda",
"AR": "Argentina",
"AM": "Armenia",
"AW": "Aruba",
"AU": "Australia",
"AT": "Austria",
"AZ": "Azerbaijan",
"BS": "Bahamas",
"BH": "Bahrain",
"BD": "Bangladesh",
"BB": "Barbados",
"BY": "Belarus",
"PW": "Belau",
"BE": "Belgium",
"BZ": "Belize",
"BJ": "Benin",
"BM": "Bermuda",
"BT": "Bhutan",
"BO": "Bolivia",
"BQ": "Bonaire, Saint Eustatius and Saba",
"BA": "Bosnia and Herzegovina",
"BW": "Botswana",
"BV": "Bouvet Island",
"BR": "Brazil",
"IO": "British Indian Ocean Territory",
"BN": "Brunei",
"BG": "Bulgaria",
"BF": "Burkina Faso",
"BI": "Burundi",
"KH": "Cambodia",
"CM": "Cameroon",
"CA": "Canada",
"CV": "Cape Verde",
"KY": "Cayman Islands",
"CF": "Central African Republic",
"TD": "Chad",
"CL": "Chile",
"CN": "China",
"CX": "Christmas Island",
"CC": "Cocos (Keeling) Islands",
"CO": "Colombia",
"KM": "Comoros",
"CG": "Congo (Brazzaville)",
"CD": "Congo (Kinshasa)",
"CK": "Cook Islands",
"CR": "Costa Rica",
"HR": "Croatia",
"CU": "Cuba",
"CW": "Cura\u00e7ao",
"CY": "Cyprus",
"CZ": "Czech Republic",
"DK": "Denmark",
"DJ": "Djibouti",
"DM": "Dominica",
"DO": "Dominican Republic",
"EC": "Ecuador",
"EG": "Egypt",
"SV": "El Salvador",
"GQ": "Equatorial Guinea",
"ER": "Eritrea",
"EE": "Estonia",
"ET": "Ethiopia",
"FK": "Falkland Islands",
"FO": "Faroe Islands",
"FJ": "Fiji",
"FI": "Finland",
"FR": "France",
"GF": "French Guiana",
"PF": "French Polynesia",
"TF": "French Southern Territories",
"GA": "Gabon",
"GM": "Gambia",
"GE": "Georgia",
"DE": "Germany",
"GH": "Ghana",
"GI": "Gibraltar",
"GR": "Greece",
"GL": "Greenland",
"GD": "Grenada",
"GP": "Guadeloupe",
"GU": "Guam",
"GT": "Guatemala",
"GG": "Guernsey",
"GN": "Guinea",
"GW": "Guinea-Bissau",
"GY": "Guyana",
"HT": "Haiti",
"HM": "Heard Island and McDonald Islands",
"HN": "Honduras",
"HK": "Hong Kong",
"HU": "Hungary",
"IS": "Iceland",
"IN": "India",
"ID": "Indonesia",
"IR": "Iran",
"IQ": "Iraq",
"IE": "Ireland",
"IM": "Isle of Man",
"IL": "Israel",
"IT": "Italy",
"CI": "Ivory Coast",
"JM": "Jamaica",
"JP": "Japan",
"JE": "Jersey",
"JO": "Jordan",
"KZ": "Kazakhstan",
"KE": "Kenya",
"KI": "Kiribati",
"KW": "Kuwait",
"KG": "Kyrgyzstan",
"LA": "Laos",
"LV": "Latvia",
"LB": "Lebanon",
"LS": "Lesotho",
"LR": "Liberia",
"LY": "Libya",
"LI": "Liechtenstein",
"LT": "Lithuania",
"LU": "Luxembourg",
"MO": "Macao",
"MG": "Madagascar",
"MW": "Malawi",
"MY": "Malaysia",
"MV": "Maldives",
"ML": "Mali",
"MT": "Malta",
"MH": "Marshall Islands",
"MQ": "Martinique",
"MR": "Mauritania",
"MU": "Mauritius",
"YT": "Mayotte",
"MX": "Mexico",
"FM": "Micronesia",
"MD": "Moldova",
"MC": "Monaco",
"MN": "Mongolia",
"ME": "Montenegro",
"MS": "Montserrat",
"MA": "Morocco",
"MZ": "Mozambique",
"MM": "Myanmar",
"NA": "Namibia",
"NR": "Nauru",
"NP": "Nepal",
"NL": "Netherlands",
"NC": "New Caledonia",
"NZ": "New Zealand",
"NI": "Nicaragua",
"NE": "Niger",
"NG": "Nigeria",
"NU": "Niue",
"NF": "Norfolk Island",
"KP": "North Korea",
"MK": "North Macedonia",
"MP": "Northern Mariana Islands",
"NO": "Norway",
"OM": "Oman",
"PK": "Pakistan",
"PS": "Palestinian Territory",
"PA": "Panama",
"PG": "Papua New Guinea",
"PY": "Paraguay",
"PE": "Peru",
"PH": "Philippines",
"PN": "Pitcairn",
"PL": "Poland",
"PT": "Portugal",
"PR": "Puerto Rico",
"QA": "Qatar",
"RE": "Reunion",
"RO": "Romania",
"RU": "Russia",
"RW": "Rwanda",
"ST": "S\u00e3o Tom\u00e9 and Pr\u00edncipe",
"BL": "Saint Barth\u00e9lemy",
"SH": "Saint Helena",
"KN": "Saint Kitts and Nevis",
"LC": "Saint Lucia",
"SX": "Saint Martin (Dutch part)",
"MF": "Saint Martin (French part)",
"PM": "Saint Pierre and Miquelon",
"VC": "Saint Vincent and the Grenadines",
"WS": "Samoa",
"SM": "San Marino",
"SA": "Saudi Arabia",
"SN": "Senegal",
"RS": "Serbia",
"SC": "Seychelles",
"SL": "Sierra Leone",
"SG": "Singapore",
"SK": "Slovakia",
"SI": "Slovenia",
"SB": "Solomon Islands",
"SO": "Somalia",
"ZA": "South Africa",
"GS": "South Georgia\/Sandwich Islands",
"KR": "South Korea",
"SS": "South Sudan",
"ES": "Spain",
"LK": "Sri Lanka",
"SD": "Sudan",
"SR": "Suriname",
"SJ": "Svalbard and Jan Mayen",
"SZ": "Swaziland",
"SE": "Sweden",
"CH": "Switzerland",
"SY": "Syria",
"TW": "Taiwan",
"TJ": "Tajikistan",
"TZ": "Tanzania",
"TH": "Thailand",
"TL": "Timor-Leste",
"TG": "Togo",
"TK": "Tokelau",
"TO": "Tonga",
"TT": "Trinidad and Tobago",
"TN": "Tunisia",
"TR": "Turkey",
"TM": "Turkmenistan",
"TC": "Turks and Caicos Islands",
"TV": "Tuvalu",
"UG": "Uganda",
"UA": "Ukraine",
"AE": "United Arab Emirates",
"GB": "United Kingdom",
"US": "United States",
"UM": "United States (US) Minor Outlying Islands",
"UY": "Uruguay",
"UZ": "Uzbekistan",
"VU": "Vanuatu",
"VA": "Vatican",
"VE": "Venezuela",
"VN": "Vietnam",
"VG": "Virgin Islands (British)",
"VI": "Virgin Islands (US)",
"WF": "Wallis and Futuna",
"EH": "Western Sahara",
"YE": "Yemen",
"ZM": "Zambia",
"ZW": "Zimbabwe"
}

View File

@@ -0,0 +1,158 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWF_Model_Contact_Fields' ) ) {
class BWF_Model_Contact_Fields {
static $primary_key = 'ID';
public static $db_field_types = [
'1' => [
'name' => 'Text Input',
'type' => 'VARCHAR',
'length' => 99
],
'2' => [
'name' => 'Text Number',
'type' => 'BIGINT',
'length' => 10,
'unsigned' => true
],
'3' => [
'name' => 'Text Area',
'type' => 'LONGTEXT'
],
'4' => [
'name' => 'Drop Down',
'type' => 'VARCHAR',
'length' => 99
],
'5' => [
'name' => 'Radio Button',
'type' => 'VARCHAR',
'length' => 99
],
'6' => [
'name' => 'Checkboxes',
'type' => 'LONGTEXT'
],
'7' => [
'name' => 'Date',
'type' => 'DATE'
],
'8' => [
'name' => 'Datetime',
'type' => 'DATETIME'
]
];
static function _table() {
global $wpdb;
return "{$wpdb->prefix}bwf_contact_fields";
}
static function insert( $data ) {
global $wpdb;
$wpdb->insert( self::_table(), $data ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
}
static function update( $data, $where ) {
global $wpdb;
return $wpdb->update( self::_table(), $data, $where ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function get_contact_field_by_id( $contact_id ) {
global $wpdb;
$table = self::_table();
$query = "SELECT * from $table where cid = $contact_id LIMIT 0, 1";
$field = $wpdb->get_row( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return ! empty( $field ) ? $field : '';
}
public static function column_already_exists( $field_id ) {
global $wpdb;
$table = self::_table();
$column = "f{$field_id}";
$query = "SHOW COLUMNS FROM {$table} LIKE '" . esc_sql( $column ) . "'";
return $wpdb->get_row( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function add_column_field( $field_id, $searchable = 2 ) {
global $wpdb;
$table = self::_table();
$field_type = BWFAN_Model_Fields::get_field_type( $field_id );
$db_details = self::$db_field_types[ $field_type ];
$data_type = $db_details['type'];
$length = '';
$unsigned = '';
$indexing = '';
$column = "f{$field_id}";
if ( isset( $db_details['length'] ) ) {
$length = "(" . $db_details['length'] . ")";
}
if ( isset( $db_details['unsigned'] ) ) {
$unsigned = " unsigned ";
}
if ( 1 === absint( $searchable ) && 'LONGTEXT' !== $db_details['type'] ) {
$indexing = ", ADD KEY ($column)";
}
$query = "ALTER TABLE $table ADD $column $data_type{$length} $unsigned DEFAULT NULL $indexing";
$wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return empty( $wpdb->last_error ) ? true : $wpdb->last_error;
}
public static function drop_contact_field_column( $field_id ) {
global $wpdb;
$table = self::_table();
$column = "f{$field_id}";
if ( ! empty( self::column_already_exists( $field_id ) ) ) {
$query = "ALTER TABLE $table DROP COLUMN $column";
$wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
}
public static function get_contact_fields( $contact_id ) {
global $wpdb;
$table = self::_table();
$query = "SELECT * FROM $table WHERE cid = $contact_id LIMIT 0, 1";
return $wpdb->get_row( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function update_contact_field_column_indexing( $field_id, $searchable = 1 ) {
global $wpdb;
$table = self::_table();
$already_exist = self::column_already_exists( $field_id );
if ( empty( $already_exist ) || ( ! empty( $already_exist['Type'] ) && 'longtext' === $already_exist['Type'] ) ) {
return false;
}
/** Checking indexing already set or not **/
if ( ( 1 === absint( $searchable ) && ! empty( $already_exist['Key'] ) ) || ( 2 === absint( $searchable ) && empty( $already_exist['Key'] ) ) ) {
return false;
}
$column = "f{$field_id}";
$indexing = " ADD KEY ($column)";
if ( 2 === absint( $searchable ) ) {
$indexing = " DROP KEY `$column` ";
}
$query = "ALTER TABLE $table $indexing";
$wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return empty( $wpdb->last_error ) ? true : false;
}
}
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* BWF_Model_Contact_WLM_Fields Class
*/
class BWF_Model_Contact_WLM_Fields {
private static function _table() {
/** @var wpdb $wpdb */
global $wpdb;
return $wpdb->prefix . 'bwf_contact_wlm_fields';
}
public static function insert( $contact_id, $status = array(), $reg = array(), $exp = array() ) {
/** @var wpdb $wpdb */
global $wpdb;
$table = self::_table();
$data = array(
'status' => wp_json_encode( $status ),
'cid' => absint( $contact_id ),
);
/** Registered Dates */
if ( ! empty( $reg ) && is_array( $reg ) ) {
foreach ( $reg as $id => $date ) {
$data[ "reg_$id" ] = $date;
}
}
/** Expiry Dates */
if ( ! empty( $exp ) && is_array( $exp ) ) {
foreach ( $exp as $id => $date ) {
$data[ "exp_$id" ] = $date;
}
}
$wpdb->insert( $table, $data ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return ! empty( $wpdb->insert_id ) ? absint( $wpdb->insert_id ) : new WP_Error( 500, $wpdb->last_error );
}
public static function update( $contact_id, $status = array(), $reg = array(), $exp = array() ) {
/** @var wpdb $wpdb */
global $wpdb;
$data = array(
'status' => wp_json_encode( $status ),
);
/** Registered Dates */
if ( ! empty( $reg ) && is_array( $reg ) ) {
foreach ( $reg as $id => $date ) {
$data[ "reg_$id" ] = $date;
}
}
/** Expiry Dates */
if ( ! empty( $exp ) && is_array( $exp ) ) {
foreach ( $exp as $id => $date ) {
$data[ "exp_$id" ] = $date;
}
}
if ( false === $wpdb->update( self::_table(), $data, array( 'cid' => $contact_id ) ) ) { //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return new WP_Error( 500, $wpdb->last_error );
}
return true;
}
public static function delete( $contact_id ) {
/** @var wpdb $wpdb */
global $wpdb;
if ( false === $wpdb->delete( $wpdb->prefix . 'bwf_contact_wlm_fields', array( 'cid' => $contact_id ) ) ) { //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return new WP_Error( 500, $wpdb->last_error );
}
return true;
}
public static function truncate() {
/** @var wpdb $wpdb */
global $wpdb;
$table = self::_table();
$wpdb->query( "TRUNCATE TABLE $table" );
}
public static function get_member( $contact_id, $lookup = false ) {
/** @var wpdb $wpdb */
global $wpdb;
$columns = true === $lookup ? 'id' : '*';
$table = self::_table();
$sql = "SELECT $columns FROM $table WHERE cid = {$contact_id}";
if ( ! $lookup ) {
return $wpdb->get_row( $sql, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
return absint( $wpdb->get_col( $sql ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function check_if_level_exists( $level_id ) {
if ( empty( $level_id ) ) {
return false;
}
/** @var wpdb $wpdb */
global $wpdb;
$table = self::_table();
$result = $wpdb->get_col( "SHOW COLUMNS FROM `{$table}` LIKE `reg_{$level_id}`" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return ! empty( $result );
}
public static function add_level_db_columns( $level_id ) {
if ( empty( $level_id ) ) {
return false;
}
/** @var wpdb $wpdb */
global $wpdb;
$table = self::_table();
$wpdb->query( "ALTER TABLE {$table} ADD COLUMN reg_{$level_id} datetime default NULL, ADD COLUMN exp_{$level_id} datetime default NULL" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange
}
}

View File

@@ -0,0 +1,303 @@
<?php
/**
* Bulk action modal class
*/
class BWFAN_Model_Bulk_Action extends BWFAN_Model {
static $primary_key = 'ID';
protected static function _table() {
global $wpdb;
return $wpdb->prefix . 'bwfan_bulk_action';
}
/**
* Insert new bulk action to db
*
* @param $data
*/
public static function bwfan_create_new_bulk_action( $data ) {
if ( empty( $data ) ) {
return;
}
self::insert( $data );
$insert_id = absint( self::insert_id() );
return $insert_id;
}
/**
* Update bulk action data by id
*
* @param $id
* @param $data
*/
public static function update_bulk_action_data( $id, $data ) {
if ( ! is_array( $data ) ) {
return false;
}
return ! ! self::update( $data, array(
'id' => absint( $id ),
) );
}
/**
* Check if action exists with field and value
*
* @param $field
* @param $value
*
* @return bool
*/
public static function check_bulk_action_exists_with( $field, $value ) {
global $wpdb;
$exists = false;
if ( empty( $field ) || empty( $value ) ) {
return false;
}
$query = 'SELECT ID FROM ' . self::_table();
$query .= $wpdb->prepare( " WHERE {$field} = %s ", $value, 1 );
$result = $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( ! empty( $result ) ) {
$exists = true;
}
return $exists;
}
/**
* Returns bulk action list
*
* @param string $search
* @param string $status
* @param int $limit
* @param int $offset
* @param false $get_total
* @param array $ids
*
* @return array
*/
public static function get_bulk_actions( $search = '', $status = '', $limit = 0, $offset = 0, $get_total = false, $ids = [] ) {
global $wpdb;
/**
* Default response
*/
$response = [
'list' => [],
'total' => 0
];
$table = self::_table();
$sql = "SELECT * FROM {$table} ";
$where_sql = ' WHERE 1=1';
/**
* If search needed
*/
if ( ! empty( $search ) ) {
$where_sql .= " AND title LIKE '%$search%'";
}
/** Get by Status */
if ( ! empty( $status ) ) {
$where_sql .= " AND `status` = {$status}";
}
if ( ! empty( $ids ) ) {
$where_sql .= " AND ID IN(" . implode( ',', $ids ) . ")";
}
/** Set Pagination */
$pagination_sql = '';
$limit = ! empty( $limit ) ? absint( $limit ) : 0;
$offset = ! empty( $offset ) ? absint( $offset ) : 0;
if ( ! empty( $limit ) || ! empty( $offset ) ) {
$pagination_sql = " LIMIT $offset, $limit";
}
/** Order By */
$order = ' ORDER BY `ID` DESC';
$sql = $sql . $where_sql . $order . $pagination_sql;
$response['list'] = $wpdb->get_results( $sql, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( ! empty( $response['list'] ) ) {
$response['list'] = self::format_action_data( $response['list'] );
}
/**
* Get total
*/
if ( $get_total ) {
$total_sql = "SELECT count(*) FROM {$table} " . $where_sql;
$response['total'] = absint( $wpdb->get_var( $total_sql ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
return $response;
}
/**
* Format bulk action data
*
* @param array $bulk_action
* @param bool $format
*
* @return array
*/
public static function format_action_data( $bulk_actions, $format = true ) {
if ( ! $format ) {
return $bulk_actions;
}
return array_map( function ( $bulk_action ) {
$meta = [];
if ( ! empty( $bulk_action['meta'] ) ) {
$meta = json_decode( $bulk_action['meta'], true );
unset( $bulk_action['meta'] );
}
if ( ! empty( $bulk_action['actions'] ) ) {
$bulk_action['actions'] = json_decode( $bulk_action['actions'], true );
}
return array_merge( $bulk_action, $meta );
}, $bulk_actions );
}
/**
* Clone bulk action
*
* @param $id
*
* @return array
*/
public static function clone_bulk_action( $id ) {
$status = 404;
$message = __( 'Unable to find bulk action with the given id.', 'wp-marketing-automations-pro' );
$bulk_action_data = self::get_specific_rows( 'ID', $id );
if ( ! empty( $bulk_action_data ) ) {
$create_time = current_time( 'mysql', 1 );
$bulk_action_data = $bulk_action_data[0];
unset( $bulk_action_data['ID'] );
unset( $bulk_action_data['ID'] );
$bulk_action_data['status'] = 0;
$bulk_action_data['meta'] = json_decode( $bulk_action_data['meta'], true );
if ( isset( $bulk_action_data['meta'] ) && ! empty( $bulk_action_data['meta'] ) && isset( $bulk_action_data['meta']['log_file'] ) ) {
unset( $bulk_action_data['meta']['log_file'] );
}
$bulk_action_data['meta'] = json_encode( $bulk_action_data['meta'] );
$bulk_action_data['title'] = $bulk_action_data['title'] . ' ( ' . __( 'Copy', 'wp-marketing-automations-pro' ) . ' )';
$bulk_action_data['created_at'] = $create_time;
$bulk_action_data['updated_at'] = $create_time;
$bulk_action_data['offset'] = 0;
$bulk_action_data['processed'] = 0;
self::insert( $bulk_action_data );
$new_bulk_action_id = self::insert_id();
if ( $new_bulk_action_id ) {
$status = 200;
$message = __( 'Bulk Action cloned.', 'wp-marketing-automations-pro' );
}
}
return array(
'status' => $status,
'message' => $message,
);
}
/**
* Delete multiple bulk actions
*
* @param $ids
*
* @return bool
*/
public static function delete_multiple_bulk_actions( $ids ) {
global $wpdb;
$bulk_action_table = self::_table();
$ids = implode( ',', array_map( 'absint', $ids ) );
return $wpdb->query( "DELETE FROM $bulk_action_table WHERE id IN( $ids )" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Return bulk action id
*/
public static function get_first_bulk_action_id() {
global $wpdb;
$query = 'SELECT MIN(ID) from ' . self::_table();
return $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Get single bulk action data
*
* @param int $id
* @param bool $format
*
* @return array|mixed
*/
public static function bwfan_get_bulk_action( $id, $format = true ) {
$bulk_action_table = self::_table();
$query = "SELECT * FROM $bulk_action_table WHERE 1=1 ";
if ( absint( $id ) > 0 ) {
$query .= " AND ID=$id ";
}
$result = self::get_results( $query );
return is_array( $result ) && ! empty( $result ) ? self::format_action_data( $result, $format )[0] : array();
}
/**
* Returns link trigegrs count by status
*
* @param $only_total get only total
*
* @return string|null
*/
public static function get_bulk_actions_total_count( $only_total = false ) {
global $wpdb;
$response = [
'all' => 0,
'0' => 0,
'1' => 0,
'2' => 0,
'3' => 0,
];
$all = 0;
$bulk_action_table = self::_table();
$query = "SELECT status, COUNT(*) as count FROM {$bulk_action_table} GROUP BY status ";
$result = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( empty( $result ) ) {
return $response;
}
foreach ( $result as $row ) {
$response[ $row['status'] ] = intval( $row['count'] );
$all += intval( $row['count'] );
}
if ( $only_total ) {
return $all;
}
$response['all'] = $all;
return $response;
}
}

View File

@@ -0,0 +1,307 @@
<?php
/**
* Link Triggers modal class
*/
class BWFAN_Model_Link_Triggers extends BWFAN_Model {
public static $primary_key = 'ID';
public static $cached_query = [];
protected static function _table() {
global $wpdb;
return $wpdb->prefix . 'bwfan_link_triggers';
}
/**
* Insert new link trigger to db
*
* @param $data
*/
public static function bwfan_create_new_link_trigger( $data ) {
if ( empty( $data ) ) {
return;
}
self::insert( $data );
$link_id = absint( self::insert_id() );
$hash = md5( $link_id . time() );
self::update_link_trigger_data( $link_id, [
'hash' => $hash
] );
return $link_id;
}
/**
* Update link trigger data by id
*
* @param $id
* @param $data
*/
public static function update_link_trigger_data( $id, $data ) {
if ( ! is_array( $data ) ) {
return false;
}
return ! ! self::update( $data, array(
'id' => absint( $id ),
) );
}
/**
* Check if link already exists with field and value
*
* @param $field
* @param $value
*
* @return bool
*/
public static function check_link_exists_with( $field, $value ) {
global $wpdb;
$exists = false;
if ( empty( $field ) || empty( $value ) ) {
return false;
}
$query = 'SELECT `ID` FROM ' . self::_table();
$query .= $wpdb->prepare( " WHERE {$field} = %s LIMIT 0,1", $value, 1 );
$result = $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( ! empty( $result ) ) {
$exists = true;
}
return $exists;
}
/**
* Returns link triggers data
*
* @param string $search
* @param int $limit
* @param int $offset
* @param string $status
* @param false $get_total
*
* @return array
*/
public static function get_link_triggers( $search = '', $status = '', $limit = 0, $offset = 0, $get_total = false, $ids = [] ) {
global $wpdb;
/**
* Default response
*/
$response = [
'links' => [],
'total' => 0
];
$table = self::_table();
$sql = "SELECT * FROM {$table} ";
$where_sql = ' WHERE 1=1';
/**
* If search needed
*/
if ( ! empty( $search ) ) {
$where_sql .= " AND `title` LIKE '%" . esc_sql( $search ) . "%'";
}
/** Get by Status */
if ( ! empty( $status ) ) {
$where_sql .= " AND `status` = {$status}";
}
if ( ! empty( $ids ) ) {
$where_sql .= " AND `ID` IN(" . implode( ',', $ids ) . ")";
}
/** Set Pagination */
$pagination_sql = '';
$limit = ! empty( $limit ) ? absint( $limit ) : 0;
$offset = ! empty( $offset ) ? absint( $offset ) : 0;
if ( ! empty( $limit ) || ! empty( $offset ) ) {
$pagination_sql = " LIMIT $offset, $limit";
}
/** Order By */
$order = ' ORDER BY `ID` DESC';
$sql = $sql . $where_sql . $order . $pagination_sql;
$response['links'] = $wpdb->get_results( $sql, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( ! empty( $response['links'] ) ) {
$response['links'] = self::format_link_data( $response['links'] );
}
/**
* Get total
*/
if ( $get_total ) {
$total_sql = "SELECT count(*) FROM {$table} " . $where_sql;
$response['total'] = absint( $wpdb->get_var( $total_sql ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
return $response;
}
/**
* Format link data
*
* @param $links
*
* @return array
*/
public static function format_link_data( $links ) {
return array_map( function ( $link ) {
if ( ! empty( $link['data'] ) ) {
$link['data'] = json_decode( $link['data'], true );
}
return $link;
}, $links );
}
/**
* Clone link trigger
*
* @param $id
*
* @return array
*/
public static function clone_link_trigger( $id ) {
$status = 404;
$message = __( 'Unable to find link with the given id.', 'wp-marketing-automations-pro' );
$link_data = self::get_specific_rows( 'id', $id );
if ( ! empty( $link_data ) ) {
$create_time = current_time( 'mysql', 1 );
$link_data = $link_data[0];
unset( $link_data['ID'] );
unset( $link_data['hash'] );
$link_data['title'] = $link_data['title'] . ' ( Copy )';
$link_data['created_at'] = $create_time;
$link_data['updated_at'] = $create_time;
self::insert( $link_data );
$new_link_id = self::insert_id();
if ( $new_link_id ) {
/** Add hash */
$hash = md5( $new_link_id . time() );
self::update_link_trigger_data( $new_link_id, [
'hash' => $hash
] );
$status = 200;
$message = __( 'Link Trigger cloned successfully.', 'wp-marketing-automations-pro' );
}
}
return array(
'status' => $status,
'message' => $message,
);
}
/**
* Delete multiple links
*
* @param $link_ids
*
* @return bool
*/
public static function delete_multiple_links( $link_ids ) {
global $wpdb;
$link_table = self::_table();
$ids = implode( ',', array_map( 'absint', $link_ids ) );
return $wpdb->query( "DELETE FROM $link_table WHERE `ID` IN( $ids )" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Return link id
*/
public static function get_first_link_id() {
global $wpdb;
$query = 'SELECT MIN(`ID`) FROM ' . self::_table();
return $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Get single Link data
*
* @param $link_id
*
* @return array|mixed
*/
public static function bwfan_get_link_trigger( $link_id, $hash = '' ) {
$link_table = self::_table();
$query = "SELECT * FROM $link_table WHERE 1=1 ";
$args = [];
if ( intval( $link_id ) > 0 ) {
$query .= " AND `ID` = %d";
$args[] = $link_id;
}
if ( ! empty( $hash ) ) {
$query .= " AND `hash` = %s";
$args[] = $hash;
}
global $wpdb;
$query = $wpdb->prepare( $query, $args );
$key = md5( $query );
if ( isset( self::$cached_query[ $key ] ) ) {
$result = self::$cached_query[ $key ];
} else {
$result = self::get_results( $query );
self::$cached_query[ $key ] = $result;
}
return is_array( $result ) && ! empty( $result ) ? self::format_link_data( $result )[0] : array();
}
/**
* Returns link triggers count by status
*
* @param int $status
*
* @return string|null
*/
public static function get_link_triggers_total_count() {
global $wpdb;
$response = [
'all' => 0,
'0' => 0,
'1' => 0,
'2' => 0,
];
$all = 0;
$link_table = self::_table();
$query = "SELECT status, COUNT(*) as count FROM {$link_table} GROUP BY status ";
$result = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( empty( $result ) ) {
return $response;
}
foreach ( $result as $row ) {
$response[ $row['status'] ] = intval( $row['count'] );
$all += intval( $row['count'] );
}
$response['all'] = $all;
return $response;
}
}

View File

@@ -0,0 +1,44 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_Model_Contact_Note' ) ) {
class BWFAN_Model_Contact_Note extends BWFAN_Model {
/**
* @param $contact_id
* @param int $offset
* @param int $limit
*
* @return array
*/
public static function get_contact_notes( $contact_id, $offset = 0, $limit = 0 ) {
if ( empty( $offset ) && empty( $limit ) ) {
$query = "SELECT * FROM {table_name} WHERE `cid`='" . $contact_id . "' ORDER BY `created_date` DESC";
} else {
$query = "SELECT * FROM {table_name} WHERE `cid`='" . $contact_id . "' ORDER BY `created_date` DESC LIMIT $offset,$limit";
}
return self::get_results( $query );
}
/**
* Update contact note
*
* @param $contact_id
* @param $notes
* @param $note_id
*
* @return bool|int|mysqli_result|resource|null
*/
public static function update_contact_note( $contact_id, $notes, $note_id ) {
$data = $notes;
$where = array(
'id' => $note_id,
'cid' => $contact_id,
);
return self::update( $data, $where );
}
}
}

View File

@@ -0,0 +1,130 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_Model_Conversions' ) ) {
class BWFAN_Model_Conversions extends BWFAN_Model {
static $primary_key = 'ID';
public static function get_conversions_by_source_type( $source_id, $source_type = 1, $limit = 0, $offset = 25 ) {
global $wpdb;
$table = self::_table();
$query = "SELECT bwc.* FROM $table as bwc JOIN {$wpdb->prefix}posts as p ON bwc.wcid=p.ID WHERE bwc.oid = $source_id AND bwc.otype=$source_type ORDER BY bwc.wcid DESC LIMIT $limit OFFSET $offset";
$conversions = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( empty( $conversions ) ) {
return [ 'conversions' => array(), 'total' => 0 ];
}
$total_query = "SELECT COUNT(*) FROM $table as bwc JOIN {$wpdb->prefix}posts as p ON bwc.wcid=p.ID WHERE bwc.oid = $source_id AND bwc.otype=$source_type";
$total = absint( $wpdb->get_var( $total_query ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
foreach ( $conversions as $key => $conv ) {
$order = wc_get_order( absint( $conv['wcid'] ) );
/** unset the conversion if order deleted or not exists */
if ( ! $order instanceof WC_Order ) {
unset( $conversions[ $key ] );
continue;
}
$order_details = [];
$order_details['f_name'] = $order->get_billing_first_name();
$order_details['l_name'] = $order->get_billing_last_name();
$order_details['email'] = $order->get_billing_email();
$order_details['status'] = $order->get_status();
$order_items = $order->get_items();
$order_details['items'] = [];
$order_details['currency'] = BWFAN_Automations::get_currency( $order->get_currency() );
foreach ( $order_items as $item_key => $item ) {
$product_id = $item->get_product_id(); // the Product id
$variation_id = $item->get_variation_id();
if ( ! empty( $variation_id ) ) {
$order_details['items'][ $variation_id ] = $item->get_name();
} else {
$order_details['items'][ $product_id ] = $item->get_name();
}
}
$conversions[ $key ] = array_replace( $conv, $order_details );
$conversions[ $key ]['wctotal'] = $order->get_total();
}
return [
'conversions' => $conversions,
'total' => $total
];
}
public static function get_conversions_by_oid( $oid, $contact_id, $engagements_ids = [], $type = 1 ) {
global $wpdb;
$table = self::_table();
$query = "SELECT wcid,date,wctotal FROM $table WHERE otype=$type AND oid=$oid AND cid=$contact_id";
if ( ! empty( $engagements_ids ) ) {
$engagements_ids = implode( ', ', $engagements_ids );
$query .= " AND trackid IN($engagements_ids)";
}
return $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function get_conversions_for_check_validity( $saved_last_conversion_id ) {
if ( empty( absint( $saved_last_conversion_id ) ) ) {
return [];
}
global $wpdb;
$table = self::_table();
$and = '';
if ( ! empty( $saved_last_conversion_id ) ) {
$and .= " AND ID <= $saved_last_conversion_id";
}
$query = "SELECt ID,wcid FROM $table WHERE 1=1 $and ORDER BY ID DESC";
return $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function get_last_conversion_id() {
global $wpdb;
$table = self::_table();
$query = "SELECT MAX(`ID`) FROM $table";
return $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function delete_conversions_by_track_id( $ids ) {
if ( empty( $ids ) ) {
return;
}
global $wpdb;
$table = self::_table();
$placeholders = array_fill( 0, count( $ids ), '%d' );
$placeholders = implode( ', ', $placeholders );
$query = $wpdb->prepare( "DELETE FROM {$table} WHERE trackid IN ($placeholders)", $ids );
return $wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function get_automation_revenue( $aid, $start_date, $end_date, $is_interval, $interval ) {
global $wpdb;
$table = self::_table();
$date_col = "date";
$interval_query = '';
$group_by = '';
$order_by = ' ID ';
if ( 'interval' === $is_interval ) {
$get_interval = BWFCRM_Dashboards::get_interval_format_query( $interval, $date_col );
$interval_query = $get_interval['interval_query'];
$interval_group = $get_interval['interval_group'];
$group_by = "GROUP BY " . $interval_group;
$order_by = ' time_interval ';
}
$base_query = "SELECT count(ID) as conversions, SUM(wctotal) as revenue $interval_query FROM `" . $table . "` WHERE 1=1 AND oid = $aid AND otype = 1 AND `" . $date_col . "` >= '" . $start_date . "' AND `" . $date_col . "` <= '" . $end_date . "'" . $group_by . " ORDER BY " . $order_by . " ASC";
return $wpdb->get_results( $base_query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
}
}

View File

@@ -0,0 +1,510 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_Model_Engagement_Tracking' ) ) {
class BWFAN_Model_Engagement_Tracking extends BWFAN_Model {
static $primary_key = 'ID';
static function get_conversations_by_cid( $cid, $mode, $offset = 0, $limit = 25 ) {
global $wpdb;
$table = self::_table();
$and = '';
if ( ! empty( $mode ) ) {
$and = " AND con.mode = $mode";
}
$query = "SELECT con.*, ct.subject, ct.template as message FROM $table AS con LEFT JOIN {$wpdb->prefix}bwfan_templates AS ct ON con.tid=ct.ID WHERE cid = '$cid' $and ORDER BY created_at DESC LIMIT $limit OFFSET $offset";
return self::get_results( $query );
}
public static function get_total_engagements( $cid, $mode ) {
global $wpdb;
$table = self::_table();
$query = [];
$query[] = "SELECT COUNT(ID) FROM {$table} WHERE 1=1";
$query[] = $wpdb->prepare( "AND cid = %d", $cid );
$query[] = $wpdb->prepare( "AND mode = %d", $mode );
return $wpdb->get_var( implode( ' ', $query ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function get_recipents_by_type( $oid, $type, $offset = 0, $limit = 25 ) {
global $wpdb;
/** Fetching all Engagements for broadcast **/
$table = self::_table();
$query = "SELECT conv.ID AS conversation_id,c.f_name,c.l_name,c.wpid,conv.send_to,conv.cid,conv.mode,conv.type,conv.open,conv.click,conv.oid,if(conv.c_status=2,1,0) as sent,conv.created_at as sent_time FROM {table_name} AS conv LEFT JOIN {$wpdb->prefix}bwf_contact AS c ON c.ID = conv.cid WHERE conv.type = $type AND conv.oid = $oid AND (c_status = 2 OR c_status = 3) ORDER BY conv.updated_at DESC LIMIT $limit OFFSET $offset";
$results = self::get_results( $query );
/** Fetch Engagements total count **/
$query = "SELECT COUNT(conv.ID) FROM $table AS conv WHERE conv.type = $type AND conv.oid = $oid";
$total = absint( $wpdb->get_var( $query ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$conversations_ids = empty( $results ) ? [] : array_column( $results, 'conversation_id' );
$conversions = [];
/** Fetch Engagement's conversions **/
if ( ! empty( $conversations_ids ) ) {
$conv_ids = implode( ', ', $conversations_ids );
$conversion_query = "SELECT wcid,cid,trackid,wctotal FROM {$wpdb->prefix}bwfan_conversions WHERE trackid IN( $conv_ids ) AND otype = $type";
$conversions_result = self::get_results( $conversion_query );
foreach ( $conversions_result as $conversion ) {
if ( ! isset( $conversions[ absint( $conversion['cid'] ) ] ) ) {
$conversions[ absint( $conversion['cid'] ) ] = [];
}
if ( ! isset( $conversions[ absint( $conversion['cid'] ) ][ absint( $conversion['trackid'] ) ] ) ) {
$conversions[ absint( $conversion['cid'] ) ][ absint( $conversion['trackid'] ) ] = 0;
}
$conversions[ absint( $conversion['cid'] ) ][ absint( $conversion['trackid'] ) ] += floatval( $conversion['wctotal'] );
}
}
$send_to = empty( $results ) ? [] : array_column( $results, 'send_to' );
$recipients = implode( "', '", $send_to );
$unsubscribers = [];
/** Fetch Unsubsribers of broadcast **/
if ( ! empty( $recipients ) ) {
$unsubscribe_query = "SELECT ID,recipient FROM {$wpdb->prefix}bwfan_message_unsubscribe WHERE recipient IN ('$recipients') AND automation_id=$oid AND c_type = 2";
$unsubscribers_result = self::get_results( $unsubscribe_query );
foreach ( $unsubscribers_result as $unsubscriber ) {
$unsubscribers[ $unsubscriber['recipient'] ] = $unsubscriber;
}
}
$conversations = array_map( function ( $engagement ) use ( $conversions, $unsubscribers ) {
$conv_id = absint( $engagement['conversation_id'] );
$contact_id = absint( $engagement['cid'] );
$contact = new BWFCRM_Contact( $contact_id );
$deleted = ! $contact->is_contact_exists();
$revenue = ( isset( $conversions[ $contact_id ][ $conv_id ] ) ) ? $conversions[ $contact_id ][ $conv_id ] : 0;
$conversions_count = ( isset( $conversions[ $contact_id ][ $conv_id ] ) ) ? 1 : 0;
$unsubscribed = ( isset( $unsubscribers[ $engagement['send_to'] ] ) ) ? 1 : 0;
$engagement['revenue'] = $revenue;
$engagement['conversions'] = $conversions_count;
$engagement['unsubscribed'] = $unsubscribed;
$engagement['contact_deleted'] = $deleted;
return $engagement;
}, $results );
return array( 'conversations' => $conversations, 'total' => $total );
}
public static function get_automation_recipents( $oid, $offset = 0, $limit = 25 ) {
global $wpdb;
$table = self::_table();
$type = BWFAN_Email_Conversations::$TYPE_AUTOMATION;
/** Fetching all Engagements for automation **/
$query = "SELECT GROUP_CONCAT(DISTINCT ID) as track_ids,cid, send_to, SUM(open) as open,mode, SUM(click) as click, COUNT(*) as total, SUM(IF(c_status=2,1,0)) as sent,MAX(created_at) as sent_time FROM $table WHERE oid = $oid AND type = $type AND cid>0 AND (c_status = 2 OR c_status = 3) GROUP BY send_to,cid,mode ORDER BY sent_time DESC LIMIT $limit OFFSET $offset";
$engagements = self::get_results( $query );
if ( empty( $engagements ) ) {
array( 'conversations' => [], 'total' => 0 );
}
/** Get Engagements total count **/
$count_query = "SELECT count(send_to) FROM $table WHERE oid = $oid AND type = $type AND cid>0 AND (c_status = 2 OR c_status = 3) GROUP BY send_to,cid,mode";
$total = self::get_results( $count_query );
$c_ids = empty( $engagements ) ? [] : array_column( $engagements, 'cid' );
$conversions = [];
$contacts = [];
if ( ! empty( $c_ids ) ) {
/** Get contacts f_name, l_name **/
$cids = implode( ',', $c_ids );
$contact_query = "SELECT id,f_name,l_name,email,contact_no FROM {$wpdb->prefix}bwf_contact WHERE id IN($cids)";
$contact_data = self::get_results( $contact_query );
foreach ( $contact_data as $contact ) {
$contacts[ $contact['id'] ] = $contact;
}
/** Get contacts conversion **/
$conversion_query = "SELECT c.wcid,c.cid,c.trackid,c.wctotal FROM {$wpdb->prefix}bwfan_conversions as c JOIN {$wpdb->prefix}posts as p on c.wcid=p.ID WHERE 1=1 AND c.oid = $oid AND c.otype = $type AND c.cid IN( $cids )";
$conversion_result = self::get_results( $conversion_query );
foreach ( $conversion_result as $conversion ) {
if ( ! isset( $conversions[ absint( $conversion['cid'] ) ] ) ) {
$conversions[ absint( $conversion['cid'] ) ] = [];
}
if ( ! isset( $conversions[ absint( $conversion['cid'] ) ][ absint( $conversion['trackid'] ) ] ) ) {
$conversions[ absint( $conversion['cid'] ) ][ absint( $conversion['trackid'] ) ] = 0;
}
$conversions[ absint( $conversion['cid'] ) ][ absint( $conversion['trackid'] ) ] += floatval( $conversion['wctotal'] );
}
}
$send_to = empty( $engagements ) ? [] : array_column( $engagements, 'send_to' );
$recipients = implode( "', '", $send_to );
$unsubscribers = [];
if ( ! empty( $recipients ) ) {
/** Get unsubscribers data **/
$unsubscribe_query = "SELECT ID,recipient FROM {$wpdb->prefix}bwfan_message_unsubscribe WHERE recipient IN ('$recipients') AND automation_id=$oid AND c_type = $type";
$unsubscribers_result = self::get_results( $unsubscribe_query );
foreach ( $unsubscribers_result as $unsubscriber ) {
$unsubscribers[ $unsubscriber['recipient'] ] = $unsubscriber;
}
}
$conversations = array_map( function ( $engagement ) use ( $contacts, $conversions, $unsubscribers ) {
$contact_id = absint( $engagement['cid'] );
$deleted = true;
if ( isset( $contacts[ $contact_id ] ) ) {
$engagement['f_name'] = $contacts[ $contact_id ]['f_name'];
$engagement['l_name'] = $contacts[ $contact_id ]['l_name'];
$deleted = false;
}
$revenue = 0;
$conversions_count = 0;
$track_ids = $engagement['track_ids'];
$track_ids = explode( ',', $track_ids );
$track_ids = array_map( 'absint', $track_ids );
if ( isset( $conversions[ $contact_id ] ) ) {
$conversion_trackids = array_keys( $conversions[ $contact_id ] );
if ( array_intersect( $track_ids, $conversion_trackids ) ) {
$revenue = array_sum( $conversions[ $contact_id ] );
}
$conversions_count = count( $conversion_trackids );
}
$engagement['revenue'] = $revenue;
$engagement['conversions'] = $conversions_count;
$engagement['unsubscribed'] = isset( $unsubscribers[ $engagement['send_to'] ] ) ? 1 : 0;
$engagement['contact_deleted'] = $deleted;
return $engagement;
}, $engagements );
return array( 'conversations' => $conversations, 'total' => count( $total ) );
}
public static function get_engagement_recipient_timeline( $convid ) {
$conv = self::get( absint( $convid ) );
if ( empty( $conv ) || ! isset( $conv['o_interaction'] ) ) {
return array();
}
$conversions = BWFAN_Model_Conversions::get_specific_rows( 'trackid', absint( $convid ) );
$final_data = self::prepare_timeline_data( $conv, $conversions );
return $final_data;
}
public static function prepare_timeline_data( $conv, $conversions = [] ) {
$opens = ! empty( $conv['o_interaction'] ) ? json_decode( $conv['o_interaction'], true ) : array();
$clicks = ! empty( $conv['c_interaction'] ) ? json_decode( $conv['c_interaction'], true ) : array();
$mode = $conv['mode'];
$final_data = [
[
'type' => 2 === absint( $conv['c_status'] ) ? 'sent' : 'failed',
'mode' => $mode,
'date' => ! empty( $conv['created_at'] ) ? get_date_from_gmt( $conv['created_at'] ) : ''
]
];
if ( 3 === absint( $conv['c_status'] ) ) {
$msg = BWFAN_Model_Engagement_Trackingmeta::get_meta( $conv['ID'], 'error_msg' );
$final_data[0]['err_message'] = empty( $msg[0]['meta_value'] ) ? 'Email not sent' : $msg[0]['meta_value'];
}
/** Opens */
$final_data = array_merge( $final_data, array_map( function ( $open ) {
return array( 'type' => 'open', 'date' => $open );
}, $opens ) );
/** Clicks */
$final_data = array_merge( $final_data, array_map( function ( $click ) use ( $mode ) {
return array( 'type' => 'click', 'mode' => $mode, 'date' => $click );
}, $clicks ) );
if ( ! empty( $conversions ) ) {
/** Conversions */
$final_data = array_merge( $final_data, array_map( function ( $conversion ) {
return array(
'type' => 'conversion',
'date' => ! empty( $conversion['date'] ) ? get_date_from_gmt( $conversion['date'] ) : '',
'revenue' => $conversion['wctotal'],
'order_id' => $conversion['wcid']
);
}, $conversions ) );
}
usort( $final_data, function ( $datum1, $datum2 ) {
return strtotime( $datum1['date'] ) > strtotime( $datum2['date'] ) ? - 1 : 1;
} );
return $final_data;
}
/**
* @param $automation_id
* @param int $contat_id
*
* @return array
*/
public static function get_automation_recipient_timeline( $automation_id, $contact_id, $mode ) {
$table = self::_table();
$query = " SELECT ID,mode,c_status,c_interaction,o_interaction,created_at FROM $table WHERE type = 1 AND oid = $automation_id AND cid = $contact_id AND (c_status = 2 OR c_status = 3) AND mode=$mode";
$engagements = self::get_results( $query );
$engage_ids = array_map( function ( $engagement ) {
return $engagement['ID'];
}, $engagements );
$conversions = BWFAN_Model_Conversions::get_conversions_by_oid( $automation_id, $contact_id, $engage_ids );
$final_data = [];
foreach ( $engagements as $engagement ) {
$final_data = array_merge( $final_data, self::prepare_timeline_data( $engagement ) );
}
/** Conversions */
$final_data = array_merge( $final_data, array_map( function ( $conversion ) {
return array(
'type' => 'conversion',
'date' => ! empty( $conversion['date'] ) ? get_date_from_gmt( $conversion['date'] ) : '',
'revenue' => $conversion['wctotal'],
'order_id' => $conversion['wcid']
);
}, $conversions ) );
usort( $final_data, function ( $data1, $data2 ) {
return strtotime( $data1['date'] ) > strtotime( $data2['date'] ) ? - 1 : 1;
} );
return $final_data;
}
/**
* @param $oid (Conversation's Source ID)
* @param int $o_type (Conversation's Source Type)
*
* @return false|string|null
*/
public static function get_first_conversation_date( $oid, $o_type = 1 ) {
if ( empty( $oid ) ) {
return false;
}
global $wpdb;
$query = "SELECT MIN(created_at) FROM `{$wpdb->prefix}bwfan_engagement_tracking` where oid = $oid and type = $o_type";
return $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* @param $after
* @param $before
*
* @return array|object|null
*/
public static function get_stats( $after, $before ) {
global $wpdb;
$query = "select count( ID ) as sent_total, sum( open ) as total_open, sum( click ) as total_click from {$wpdb->prefix}bwfan_engagement_tracking where c_status = 2 group by c_status";
return $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* @return array|object|null
*/
public static function get_popular_emails() {
global $wpdb;
$template_table = $wpdb->prefix . 'bwfan_templates';
$engagement_table = $wpdb->prefix . 'bwfan_engagement_tracking';
$query = "SELECT `tid`, SUM(`open`) as `opens`, SUM(`click`) as `clicks` FROM $engagement_table WHERE tid IS NOT NULL AND open > 0 GROUP BY tid ORDER BY `opens` DESC LIMIT 0,5";
$results = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( empty( $results ) ) {
return [];
}
$tids = array_column( $results, 'tid' );
$placeholders = array_fill( 0, count( $tids ), '%d' );
$placeholders = implode( ', ', $placeholders );
$query = $wpdb->prepare( "SELECT `ID`, `subject` FROM $template_table WHERE `ID` IN ($placeholders)", $tids );
$result2 = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$subjects = [];
foreach ( $result2 as $val ) {
$subjects[ $val['ID'] ] = $val['subject'];
}
foreach ( $results as $key => $val ) {
if ( isset( $subjects[ $val['tid'] ] ) ) {
$results[ $key ]['subject'] = $subjects[ $val['tid'] ];
}
}
return $results;
}
public static function get_last_engagement_sent_time( $contact_id, $mode = 1 ) {
$query = "SELECT max(created_at) as last_sent FROM {table_name} WHERE cid = $contact_id AND mode = $mode AND c_status = 2";
$results = self::get_results( $query );
$res = '';
if ( ! empty( $results[0]['last_sent'] ) ) {
$res = $results[0]['last_sent'];
}
return $res;
}
public static function get_last_email_open_time( $contact_id ) {
$query = "SELECT o_interaction,c_interaction FROM {table_name} WHERE cid = $contact_id AND c_status = 2";
$results = self::get_results( $query );
$last_open_time = 0;
$last_click_time = 0;
foreach ( $results as $data ) {
$o_interactions = ! empty( $data['o_interaction'] ) ? json_decode( $data['o_interaction'], true ) : '';
$c_interaction = ! empty( $data['c_interaction'] ) ? json_decode( $data['c_interaction'], true ) : '';
// Get last open time
if ( is_array( $o_interactions ) ) {
$max_o_interaction = max( $o_interactions );
if ( $max_o_interaction > $last_open_time ) {
$last_open_time = $max_o_interaction;
}
}
// Get last click time
if ( is_array( $c_interaction ) ) {
$max_c_interaction = max( $c_interaction );
if ( $max_c_interaction > $last_click_time ) {
$last_click_time = $max_c_interaction;
}
}
}
return [ 'last_open_time' => $last_open_time, 'last_click_time' => $last_click_time ];
}
public static function get_last_24_hours_conversations_count( $mode = 1 ) {
global $wpdb;
$start_time = date( 'Y-m-d H:i:s', strtotime( '-24 hours' ) );
$and_mode = ! empty( absint( $mode ) ) ? " AND mode = $mode " : "";
$query = "SELECT COUNT(ID) FROM {$wpdb->prefix}bwfan_engagement_tracking WHERE c_status = 2 AND created_at > '$start_time' $and_mode";
return $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function get_most_interacted_template( $oid, $otype, $mode ) {
global $wpdb;
$interaction = BWFAN_Email_Conversations::$MODE_SMS === absint( $mode ) ? 'click' : 'open';
$sql = "SELECT tid, SUM($interaction) as $interaction FROM `{$wpdb->prefix}bwfan_engagement_tracking` WHERE oid=$oid AND type=$otype AND c_status=2 GROUP BY tid ORDER BY $interaction DESC LIMIT 0, 1";
return $wpdb->get_row( $sql, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Return first engagement id
*/
public static function get_first_engagement_id() {
global $wpdb;
$query = 'SELECT MIN(`ID`) FROM ' . self::_table();
return $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Get automation step analytics
*
* @param $oid
* @param $step_ids
* @param $after_date
*
* @return array|object|stdClass
*/
public static function get_automation_step_analytics( $oid, $step_ids, $after_date = '', $end_date = '' ) {
global $wpdb;
if ( empty( $step_ids ) ) {
return [];
}
$table = "{$wpdb->prefix}bwfan_engagement_tracking";
$step_ids = ! is_array( $step_ids ) ? [ $step_ids ] : $step_ids;
$ids = implode( "','", $step_ids );
$conversions_query = "SELECT trackid, count(ID) as conversions, SUM(wctotal) as revenue, cid FROM {$wpdb->prefix}bwfan_conversions GROUP BY trackid,cid";
$query = "SELECT SUM(if(con.open>0,1,0)) AS open_count,(SUM(IF(con.open>0, 1, 0))/COUNT(con.ID)) * 100 as open_rate ,SUM(IF(con.c_status=2, 1, 0)) as sent,SUM(if(con.click>0,1,0)) AS click_count,(SUM(IF(con.click>0, 1, 0))/COUNT(con.ID)) * 100 as click_rate, SUM(conv.conversions) as conversions, SUM(conv.revenue) as revenue, COUNT(DISTINCT con.cid) as contacts_count FROM {$table} AS con LEFT JOIN ({$conversions_query}) as conv ON con.ID = conv.trackid WHERE 1=1 AND con.type = " . BWFAN_Email_Conversations::$TYPE_AUTOMATION . " AND con.sid IN('$ids') AND con.c_status = 2 ";
if ( ! empty( $oid ) ) {
$query .= " AND con.oid IN ($oid) ";
}
/** Add query for get data after date */
if ( ! empty( $after_date ) && empty( $end_date ) ) {
$query .= " AND con.created_at > '$after_date'";
}
if ( ! empty( $after_date ) && ! empty( $end_date ) ) {
$query .= " AND ( con.created_at > '$after_date' AND con.created_at < '$end_date' ) ";
}
$results = $wpdb->get_row( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$results['unsubscribers'] = self::get_automation_unsubscribers( $oid, $step_ids );
return $results;
}
public static function get_automation_unsubscribers( $aid, $step_ids = [] ) {
global $wpdb;
$query = "SELECT COUNT(*) FROM {$wpdb->prefix}bwfan_message_unsubscribe WHERE `automation_id`=%d AND `c_type`=1";
$args = [ $aid ];
if ( count( $step_ids ) > 0 ) {
$placeholders = array_fill( 0, count( $step_ids ), '%d' );
$placeholders = implode( ', ', $placeholders );
$query .= " AND `sid` IN($placeholders) ";
$args = array_merge( $args, $step_ids );
}
$query = $wpdb->prepare( $query, $args );
return absint( $wpdb->get_var( $query ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function get_contact_engagements( $aid, $cid, $start_date, $last_date ) {
global $wpdb;
$table = self::_table();
$query = $wpdb->prepare( "SELECT ID FROM {$table} WHERE cid = %d AND oid = %d AND type = 1 AND `created_at` BETWEEN %s AND %s", $cid, $aid, $start_date, $last_date );
return $wpdb->get_col( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function delete_contact_engagements( $ids ) {
if ( empty( $ids ) ) {
return;
}
global $wpdb;
$table = self::_table();
$placeholders = array_fill( 0, count( $ids ), '%d' );
$placeholders = implode( ', ', $placeholders );
$query = $wpdb->prepare( "DELETE FROM {$table} WHERE ID IN ($placeholders)", $ids );
return $wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function get_engagements_tid( $aid, $sids ) {
global $wpdb;
if ( ! is_array( $sids ) || empty( $sids ) ) {
return [];
}
$placeholders = array_fill( 0, count( $sids ), '%d' );
$placeholders = implode( ', ', $placeholders );
$args = [ $aid, 1 ];
$args = array_merge( $args, $sids );
$query = "SELECT `sid`, `tid` FROM {$wpdb->prefix}bwfan_engagement_tracking WHERE `oid` = %d AND `type` = %d AND `sid` IN ($placeholders)";
return $wpdb->get_results( $wpdb->prepare( $query, $args ), ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_Model_Engagement_Trackingmeta' ) ) {
class BWFAN_Model_Engagement_Trackingmeta extends BWFAN_Model {
static $primary_key = 'ID';
static function get_meta( $con_id, $key = '' ) {
global $wpdb;
$table = self::_table();
$meta_key_query = '';
if ( ! empty( $key ) ) {
$meta_key_query = "meta_key = '$key'";
}
return $wpdb->get_results( "SELECT meta_key, meta_value from $table WHERE $meta_key_query AND eid=$con_id", ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
static function get_merge_tags( $con_id ) {
$result = self::get_meta( $con_id, 'merge_tags' );
if ( empty( $result ) ) {
return array();
}
try {
$merge_tags = json_decode( $result[0]['meta_value'], true );
} catch ( Exception $e ) {
return array();
}
return $merge_tags;
}
public static function delete_engagements_meta( $ids ) {
if ( empty( $ids ) ) {
return;
}
global $wpdb;
$table = self::_table();
$placeholders = array_fill( 0, count( $ids ), '%d' );
$placeholders = implode( ', ', $placeholders );
$query = $wpdb->prepare( "DELETE FROM {$table} WHERE eid IN ($placeholders)", $ids );
return $wpdb->query( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
}
}

View File

@@ -0,0 +1,19 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_Model_Field_Groups' ) ) {
class BWFAN_Model_Field_Groups extends BWFAN_Model {
static $primary_key = 'ID';
/**
* function to return group using term slug
**/
static function get_group_by_slug( $slug ) {
global $wpdb;
$query = "SELECT * from {table_name} where slug='" . $slug . "'";
$groupdata = self::get_results( $query );
$groupdata = is_array( $groupdata ) && ! empty( $groupdata ) ? $groupdata[0] : array();
return $groupdata;
}
}
}

View File

@@ -0,0 +1,190 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_Model_Fields' ) ) {
class BWFAN_Model_Fields extends BWFAN_Model {
private static $fields_cache_by_slug = [];
static $primary_key = 'ID';
static $cache_query = [];
/**
* function to return field data using term slug
*
* @param $id
*
* @return array|mixed
*/
static function get_field_by_id( $id ) {
global $wpdb;
$query = "SELECT * from {table_name} where ID = $id ";
$fielddata = self::get_results( $query );
$fielddata = is_array( $fielddata ) && ! empty( $fielddata ) ? $fielddata[0] : array();
if ( isset( $fielddata['meta'] ) ) {
$fielddata['meta'] = json_decode( $fielddata['meta'] );
}
return $fielddata;
}
public static function get_group_fields( $group_id = 0, $mode = null, $vmode = null, $searchable = null ) {
global $wpdb;
$query = "SELECT fg.name AS group_name, cf.ID AS field_id, cf.name, cf.slug, cf.type, cf.gid, cf.meta, cf.search, cf.mode, cf.vmode, cf.created_at FROM {table_name} AS cf LEFT JOIN {$wpdb->prefix}bwfan_field_groups AS fg ON cf.gid = fg.ID ";
$query .= " WHERE 1=1";
! empty( $mode ) && $query .= " AND mode = $mode";
! empty( $vmode ) && $query .= " AND vmode = $vmode";
! empty( $searchable ) && $query .= " AND search = $searchable";
$group_id > 0 ? $query .= " AND fg.ID = $group_id" : $query .= " AND (EXISTS (SELECT 1 FROM {$wpdb->prefix}bwfan_field_groups WHERE cf.gid=ID) OR cf.gid=0 )";
$fields = self::get_results( $query );
return $fields;
}
public static function get_custom_fields( $mode = null, $vmode = null, $searchable = null, $viewable = null, $type = null, $limit = 0, $offset = 0 ) {
global $wpdb;
$query = "SELECT * FROM {table_name} WHERE 1=1";
! empty( $mode ) && $query .= " AND mode = $mode";
! empty( $vmode ) && $query .= " AND vmode = $vmode";
! empty( $searchable ) && $query .= " AND search = $searchable";
! empty( $viewable ) && $query .= " AND view = $viewable";
! empty( $type ) && $query .= " AND type = $type";
if ( $limit > 0 ) {
$query .= $wpdb->prepare( " LIMIT %d, %d", $offset, $limit );
}
$fields = self::get_results( $query );
return $fields;
}
public static function get_field_by_slug( $slug ) {
$field = self::get_fields_by_slugs_cache( [ $slug ] );
return $field;
}
public static function get_fields_by_multiple_slugs( $slugs = [] ) {
$fields = self::get_fields_by_slugs_cache( $slugs );
return $fields;
}
public static function get_fields_by_slugs_cache( $slugs, $return_by = 'slug' ) {
if ( empty( $slugs ) ) {
return [];
}
$fields = self::$fields_cache_by_slug;
if ( 0 === count( $fields ) ) {
global $wpdb;
$table = self::_table();
$query = "SELECT * from $table";
$rest_fields = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$fields = [];
foreach ( $rest_fields as $field ) {
if ( ! is_array( $field ) ) {
continue;
}
$fields[ $field['slug'] ] = $field;
}
self::$fields_cache_by_slug = $fields;
}
$return = [];
foreach ( $slugs as $slug ) {
if ( ! isset( $fields[ $slug ] ) || ! is_array( $fields[ $slug ] ) ) {
continue;
}
$field = $fields[ $slug ];
$key = 'slug' === $return_by ? $slug : $field['id'];
if ( 1 === count( $slugs ) ) {
return $field;
}
$return[ $key ] = $field;
}
return $return;
}
public static function get_field_type( $id ) {
global $wpdb;
$table = self::_table();
$query = "SELECT `type` FROM $table WHERE `ID` = $id LIMIT 0,1";
if ( isset( self::$cache_query[ md5( $query ) ] ) ) {
return self::$cache_query[ md5( $query ) ];
}
self::$cache_query[ md5( $query ) ] = $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return self::$cache_query[ md5( $query ) ];
}
/**
* Get all fields and their slug, name, type details
*
* @return array|object|stdClass[]|null
*/
public static function get_field_types() {
global $wpdb;
$table = self::_table();
$query = "SELECT `ID`, `slug`, `type`, `name` FROM $table LIMIT 0,500";
if ( isset( self::$cache_query[ md5( $query ) ] ) ) {
return self::$cache_query[ md5( $query ) ];
}
self::$cache_query[ md5( $query ) ] = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return self::$cache_query[ md5( $query ) ];
}
/**Get total Count of fields for showing in frontend*/
public static function get_fields_count() {
global $wpdb;
$table = self::_table();
$addressfield = implode( "', '", array_keys( BWFCRM_Fields::$contact_address_fields ) );
$query = "SELECT COUNT(ID) FROM {$table} WHERE 1=1 AND vmode=1 AND slug NOT IN('$addressfield')";
$custom_fields = $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$column_field = BWFCRM_Fields::$contact_columns;
if ( isset( $column_field['creation_date'] ) ) {
unset( $column_field['creation_date'] );
}
$fields_count = $custom_fields + count( $column_field ) + count( BWFCRM_Fields::$extra_columns );
return $fields_count;
}
/**
* Get multiple fields
*
* @param $ids
*
* @return array|object|stdClass[]|null
*/
public static function get_multiple_fields( $ids ) {
if ( empty( $ids ) ) {
return [];
}
global $wpdb;
$table = self::_table();
$ids = implode( ',', $ids );
$query = "SELECT * From $table WHERE ID IN ($ids)";
return $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
}
}

View File

@@ -0,0 +1,102 @@
<?php
class BWFAN_Model_Form_Feeds extends BWFAN_Model {
static $primary_key = 'ID';
public static function get_feeds( $args = array() ) {
global $wpdb;
$table = self::_table();
$sql = "SELECT * FROM {$table}";
if ( ! is_array( $args ) || empty( $args ) ) {
return array(
'feeds' => $wpdb->get_results( $sql, ARRAY_A ), //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
'total' => 0
);
}
$where_sql = ' WHERE 1=1';
if ( isset( $args['search'] ) && ! empty( $args['search'] ) ) {
$where_sql .= $wpdb->prepare( " AND `title` LIKE %s", "%{$args['search']}%" );
}
/** Get by Source */
if ( isset( $args['source'] ) && ! empty( $args['source'] ) ) {
$where_sql .= $wpdb->prepare( " AND `source` = %s", $args['source'] );
}
/** Get by title Search */
if ( isset( $args['search'] ) && ! empty( $args['search'] ) ) {
$where_sql .= " AND `title` LIKE '%" . esc_sql( $args['search'] ) . "%'";
}
/** Get by Status */
if ( isset( $args['status'] ) && ! empty( $args['status'] ) ) {
$where_sql .= $wpdb->prepare( " AND `status` = %d", $args['status'] );
}
/** Set Pagination */
$pagination_sql = '';
$limit = isset( $args['limit'] ) ? absint( $args['limit'] ) : 0;
$offset = isset( $args['offset'] ) ? absint( $args['offset'] ) : 0;
if ( ! empty( $limit ) || ! empty( $offset ) ) {
$pagination_sql = " LIMIT $offset, $limit";
}
/** Order By */
$order = ' ORDER BY `ID` DESC';
$sql = $sql . $where_sql . $order . $pagination_sql;
$total_sql = "SELECT count(*) FROM {$table}" . $where_sql;
$grab_totals = isset( $args['grab_totals'] ) && ! empty( absint( $args['grab_totals'] ) );
return array(
'feeds' => $wpdb->get_results( $sql, ARRAY_A ), //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
'total' => $grab_totals ? absint( $wpdb->get_var( $total_sql ) ) : 0 //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
);
}
/**
* Get first form id
*
*/
public static function get_first_form_id() {
global $wpdb;
$query = "SELECT MIN(`ID`) FROM " . self::_table();
return $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Return form count data by status
*
* @return string|null
*/
public static function get_forms_total_count() {
global $wpdb;
$response = [
'all' => 0,
'1' => 0,
'2' => 0,
'3' => 0,
];
$all = 0;
$table = self::_table();
$query = "SELECT status, COUNT(*) as count FROM {$table} GROUP BY status ";
$result = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( empty( $result ) ) {
return $response;
}
foreach ( $result as $row ) {
$response[ $row['status'] ] = intval( $row['count'] );
$all += intval( $row['count'] );
}
$response['all'] = $all;
return $response;
}
}

View File

@@ -0,0 +1,30 @@
<?php
class BWFAN_Model_Import_Export extends BWFAN_Model {
/** Status 1: In-Progress, 2: Failed, 3: Success */
public static function get_export_import( $type, $limit, $offset ) {
global $wpdb;
$table = "{$wpdb->prefix}bwfan_import_export";
$query = " SELECT * FROM $table WHERE type = $type ORDER BY ID DESC LIMIT $offset,$limit";
$count_query = " SELECT COUNT(id) FROM $table WHERE type = $type ";
$result = [
'exports' => self::get_results( $query ),
'total_count' => $wpdb->get_var( $count_query ) //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
];
return $result;
}
/**
* Get first export id
*/
public static function get_first_export_id() {
global $wpdb;
$table = "{$wpdb->prefix}bwfan_import_export";
$query = " SELECT MIN(`id`) FROM $table WHERE type = 2 ";
return $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
}

View File

@@ -0,0 +1,57 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_Model_Message' ) ) {
class BWFAN_Model_Message extends BWFAN_Model {
static $primary_key = 'ID';
public static function get_messages( $args = array() ) {
global $wpdb;
$table = self::_table();
$sql = "SELECT * FROM {$table}";
if ( ! is_array( $args ) || empty( $args ) ) {
return $wpdb->get_results( $sql, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
$where_sql = ' WHERE 1=1';
/** Get by Track id */
if ( isset( $args['track_id'] ) && ! empty( $args['track_id'] ) ) {
$where_sql .= " AND track_id = '{$args['track_id']}'";
}
/** Get by Subject */
if ( isset( $args['sub'] ) && ! empty( $args['sub'] ) ) {
$where_sql .= " AND sub = {$args['sub']}";
}
/** Get by Body */
if ( isset( $args['body'] ) && ! empty( $args['body'] ) ) {
$where_sql .= " AND body = {$args['body']}";
}
/** Set Pagination */
$pagination_sql = '';
$limit = isset( $args['limit'] ) ? absint( $args['limit'] ) : 0;
$offset = isset( $args['offset'] ) ? absint( $args['offset'] ) : 0;
if ( ! empty( $limit ) || ! empty( $offset ) ) {
$pagination_sql = " limit $offset, $limit";
}
$sql = $sql . $where_sql . $pagination_sql;
// $total_sql = "SELECT count(*) FROM {$table}" . $where_sql;
// $grab_totals = isset( $args['grab_totals'] ) && ! empty( absint( $args['grab_totals'] ) );
return $wpdb->get_results( $sql, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
public static function get_message_by_track_id( $track_id ) {
global $wpdb;
$table = self::_table();
$sql = "SELECT ID,sub as subject, body as template FROM {$table} WHERE track_id = $track_id LIMIT 0, 1";
return $wpdb->get_row( $sql, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
}
}

View File

@@ -0,0 +1,37 @@
<?php
if ( ! class_exists( 'BWFAN_Model_Stripe_Offer' ) ) {
class BWFAN_Model_Stripe_Offer extends BWFAN_Model {
public static $primary_key = 'ID';
/**
* Get stripe offer by cid and funnel id
*
* @param $cid
* @param $fid
*
* @return string|null
*/
public static function get_stripe_offer_id( $cid, $fid ) {
global $wpdb;
$table = self::_table();
$query = "SELECT ID FROM {$table} WHERE `clicked`= %d AND `cid`=%d AND `fid`=%d ORDER BY `ID` DESC LIMIT 1";
return $wpdb->get_var( $wpdb->prepare( $query, 1, $cid, $fid ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
protected static function _table() {
global $wpdb;
return $wpdb->prefix . 'bwfan_stripe_offer';
}
public static function get_analytics( $step_id ) {
global $wpdb;
$table = self::_table();
$query = "SELECT count(`ID`) AS `sent`, SUM(`clicked`) AS `click_count`, (SUM(`clicked`)/COUNT(`ID`)) * 100 as `click_rate`, COUNT(distinct NULLIF(`order_id`, '')) AS `conversions`, SUM(`order_total`) AS `revenue`, COUNT(DISTINCT `cid`) as `contacts_count` FROM {$table} WHERE `sid`=%d";
return $wpdb->get_row( $wpdb->prepare( $query, $step_id ), ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
}
}

View File

@@ -0,0 +1,347 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_Model_Templates' ) ) {
class BWFAN_Model_Templates extends BWFAN_Model {
static $primary_key = 'ID';
/**
* Get templates from db
*
* @param $offset
* @param $limit
* @param $search
* @param $id
* @param bool $get_template
*
* @return array|object
*/
public static function bwfan_get_templates( $offset, $limit, $search, $id, $get_template = true, $mode = '' ) {
global $wpdb;
$column = '*';
if ( ! $get_template ) {
$column = 'ID, title, mode, created_at, updated_at';
}
$query = "SELECT $column FROM {table_name} WHERE 1=1 AND type = 1 AND canned = 1";
if ( ! empty( $id ) ) {
$query .= $wpdb->prepare( " AND ID in ( " . implode( ',', $id ) . " )" );
}
if ( ! empty( $mode ) ) {
$query .= $wpdb->prepare( " AND mode = %d", $mode );
}
if ( ! empty( $search ) ) {
$query .= $wpdb->prepare( " AND title LIKE %s", "%" . esc_sql( $search ) . "%" );
}
$query .= ' ORDER BY updated_at DESC';
if ( intval( $limit ) > 0 ) {
$offset = ! empty( $offset ) ? intval( $offset ) : 0;
$query .= $wpdb->prepare( " LIMIT %d, %d", $offset, $limit );
}
$result = self::get_results( $query );
$result = is_array( $result ) && ! empty( $result ) ? $result : array();
return $result;
}
/**
* Get layouts from db
*
* @param $offset
* @param $limit
* @param $search
* @param $id
* @param bool $get_template
*
* @return array|object
*/
public static function bwfan_get_layouts( $offset, $limit, $search, $id ) {
global $wpdb;
$query = "SELECT * FROM {table_name} WHERE 1=1 AND type = 1 AND canned = 0 AND mode = 6";
if ( ! empty( $id ) ) {
$query .= $wpdb->prepare( " AND ID in ( " . implode( ',', $id ) . " )" );
}
if ( ! empty( $search ) ) {
$query .= $wpdb->prepare( " AND title LIKE %s", "%" . esc_sql( $search ) . "%" );
}
$query .= ' ORDER BY updated_at DESC';
if ( intval( $limit ) > 0 ) {
$offset = ! empty( $offset ) ? intval( $offset ) : 0;
$query .= $wpdb->prepare( " LIMIT %d, %d", $offset, $limit );
}
$result = self::get_results( $query );
$result = is_array( $result ) && ! empty( $result ) ? $result : array();
return $result;
}
/**
* Get templates count from db
*
* @param $search
* @param $id
*
* @return int
*/
public static function bwfan_get_templates_count( $search, $id, $mode ) {
global $wpdb;
$table = $wpdb->prefix . 'bwfan_templates';
$query = 'SELECT count(ID) FROM ' . $table . ' WHERE 1=1 AND type = 1 AND canned = 1';
if ( ! empty( $id ) ) {
$query .= $wpdb->prepare( " AND ID in ( " . implode( ',', $id ) . " )" );
}
if ( ! empty( $mode ) ) {
$query .= $wpdb->prepare( " AND mode = %d", $mode );
}
if ( ! empty( $search ) ) {
$query .= $wpdb->prepare( " AND title LIKE %s", "%" . esc_sql( $search ) . "%" );
}
$result = $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return $result ? intval( $result ) : 0;
}
/**
* Get layout count from db
*
* @param $search
* @param $id
*
* @return int
*/
public static function bwfan_get_layouts_count( $search, $id ) {
global $wpdb;
$table = $wpdb->prefix . 'bwfan_templates';
$query = 'SELECT count(ID) FROM ' . $table . ' WHERE 1=1 AND type = 1 AND canned = 0 AND mode=6';
if ( ! empty( $id ) ) {
$query .= $wpdb->prepare( " AND ID in ( " . implode( ',', $id ) . " )" );
}
if ( ! empty( $search ) ) {
$query .= $wpdb->prepare( " AND title LIKE %s", "%" . esc_sql( $search ) . "%" );
}
$result = $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return $result ? intval( $result ) : 0;
}
/**
* Check if template already exists
*
* @param $field
* @param $data
*
* @return int
*/
public static function bwfan_check_template_exists( $field, $data ) {
global $wpdb;
$query = 'SELECT COUNT(ID) FROM ' . self::_table();
$string_with_dash = "$data - %";
$query .= $wpdb->prepare( " WHERE ( {$field} = %s OR {$field} LIKE %s ) AND canned = %d LIMIT 0,1", $data, esc_sql( $string_with_dash ), 1 );
$result = $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return $result;
}
/**
* Check if layout already exists
*
* @param $field
* @param $data
*
* @return int
*/
public static function bwfan_check_layout_exists( $field, $data ) {
global $wpdb;
$query = 'SELECT COUNT(ID) FROM ' . self::_table();
$string_with_dash = "$data - %";
$query .= $wpdb->prepare( " WHERE ( {$field} = %s OR {$field} LIKE %s ) AND canned = %d LIMIT 0,1", $data, esc_sql( $string_with_dash ), 0 );
$result = $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return $result;
}
/**
* Insert new template to db
*
* @param $data
*/
public static function bwfan_create_new_template( $data ) {
if ( empty( $data ) ) {
return;
}
self::insert( $data );
$id = absint( self::insert_id() );
return $id;
}
/**
* Delete template
*
* @param $id
*
* @return bool
*/
public static function bwf_delete_template( $id ) {
$template_data = [
'canned' => 0,
];
$table_name = self::_table();
if ( is_array( $id ) ) {
/**Update multiple rows */
$query = "UPDATE $table_name SET `canned` = 0 WHERE `ID` IN ('" . implode( "','", array_map( 'esc_sql', $id ) ) . "')";
self::update_multiple( $query );
} else {
$delete_template = self::update( $template_data, array(
'id' => absint( $id ),
) );
if ( false === $delete_template ) {
return false;
}
}
return true;
}
/**
* Delete layout
*
* @param $id
*
* @return bool
*/
public static function bwf_delete_layout( $id ) {
global $wpdb;
$table_name = self::_table();
$delete_layout = $wpdb->delete( $table_name, array( 'ID' => $id ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( false === $delete_layout ) {
return false;
}
return true;
}
/**
* Fetch template by id
*
* @param $id
*
* @return array|mixed
*/
public static function bwfan_get_template( $id ) {
$query = 'SELECT * FROM {table_name} WHERE type = 1 AND canned = 1 AND ID=' . $id;
$result = self::get_results( $query );
$result = is_array( $result ) && ! empty( $result ) ? $result[0] : array();
return $result;
}
/**
* Update Template data by id
*
* @param $id
* @param $data
*/
public static function bwfan_update_template( $id, $data ) {
if ( ! is_array( $data ) ) {
return false;
}
return ! ! self::update( $data, array(
'id' => absint( $id ),
) );
}
/**
* Return template id
*/
public static function get_first_template_id() {
global $wpdb;
$table = "{$wpdb->prefix}bwfan_templates";
$query = " SELECT MIN(`id`) FROM $table WHERE `type` = 1 AND `canned` = 1 ";
return $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Clone given template ID
*
* @param $template_id
*
* @return array
*/
public static function clone_template( $template_id ) {
$status = 404;
$message = __( 'Unable to find template with the given id.', 'wp-marketing-automations-pro' );
$template = self::get_specific_rows( 'id', $template_id );
if ( ! empty( $template ) ) {
$create_time = current_time( 'mysql', 1 );
$template = $template[0];
unset( $template['ID'] );
$template['title'] = $template['title'] . ' ( Copy )';
$template['created_at'] = $create_time;
$template['updated_at'] = $create_time;
self::insert( $template );
$new_template_id = self::insert_id();
if ( $new_template_id ) {
$status = 200;
$message = __( 'Template cloned', 'wp-marketing-automations-pro' );
}
}
return array(
'status' => $status,
'message' => $message,
);
}
/**
* Get templates by ids
*
* @param $tids
*
* @return array
*/
public static function get_templates_by_ids( $tids ) {
global $wpdb;
if ( empty( $tids ) ) {
return [];
}
$placeholders = array_fill( 0, count( $tids ), '%d' );
$placeholders = implode( ', ', $placeholders );
$query = "SELECT `ID`,`subject`, `template`, `type` FROM {$wpdb->prefix}bwfan_templates WHERE `ID` IN( $placeholders )";
$result = $wpdb->get_results( $wpdb->prepare( $query, $tids ), ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$data = [];
foreach ( $result as $template ) {
$data[ $template['ID'] ] = $template;
}
return $data;
}
}
}

View File

@@ -0,0 +1,398 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_Model_Terms' ) ) {
class BWFAN_Model_Terms extends BWFAN_Model {
static $primary_key = 'ID';
/** @var array $terms_cache */
private static $terms_cache = [];
private static $query_cache = [];
/**
* function to return term_data using term slug
**/
static function get_term_by_name( $term_slug, $type = 1 ) {
$query = "SELECT * FROM `{table_name}` WHERE `name` LIKE '" . esc_sql( $term_slug ) . "' AND `type` = '" . $type . "'";
$query_md5 = md5( $query );
if ( isset( self::$query_cache[ $query_md5 ] ) && ! empty( self::$query_cache[ $query_md5 ] ) ) {
$term_data = self::$query_cache[ $query_md5 ];
} else {
$term_data = self::get_results( $query );
self::$query_cache[ $query_md5 ] = $term_data;
}
return is_array( $term_data ) && ! empty( $term_data ) ? $term_data[0] : array();
}
/**
* function to return term_data using term slug
**/
static function search_term( $term_slug, $type = 1 ) {
$query = "SELECT * FROM `{table_name}` WHERE `name` LIKE '%" . esc_sql( $term_slug ) . "%' AND `type` = '" . $type . "'";
$term_data = self::get_results( $query );
return is_array( $term_data ) && ! empty( $term_data ) ? $term_data : array();
}
/**
* @param int $type
* @param int $offset
* @param int $limit
* @param string $search
* @param array $ids
* @param string $search_nature
* @param bool $use_cache
*
* @return array|object
*/
static function get_terms( $type = 1, $offset = 0, $limit = 10, $search = '', $ids = array(), $search_nature = '', $use_cache = false ) {
$found_terms = [];
/** Cache Implementation: BEGIN */
/**
* Retrieving terms from cache is only possible when there is Exact names of terms to be searched.
* OR, we have IDs to retrieve
* Means either Term Name or ID is needed to retrieve from cache.
*
* Also don't use cache in case we have pagination parameters,
* which makes it difficult to populate terms from both cache & DB for a particular page
*/
$eligible_for_cache = ( 'exact' === $search_nature && ! empty( $search ) ) || ( ! empty( $ids ) && is_array( $ids ) );
if ( $use_cache && $eligible_for_cache ) {
$offset = 0;
$limit = 1000;
$result = self::_get_terms_from_cache( $search, $search_nature, $ids, $type );
if ( empty( $result['ids_not_found'] ) && empty( $result['search_not_found'] ) ) {
return $result['found_terms'];
}
$search = $result['search_not_found'];
$ids = $result['ids_not_found'];
$found_terms = $result['found_terms'];
}
/** Cache Implementation: END */
global $wpdb;
$search_terms = '';
$limit_query = '';
$order = ' ORDER BY `ID` DESC';
if ( ! empty( $search ) ) {
if ( ! is_array( $search ) ) {
$search = BWFAN_PRO_Common::get_formatted_value_for_dbquery( $search );
$search_terms = ( 'exact' === $search_nature ? " AND name = '$search'" : "AND name LIKE '%" . esc_sql( $search ) . "%'" );
} else if ( 'exact' === $search_nature ) {
$search = array_map( function ( $value ) {
return BWFAN_PRO_Common::get_formatted_value_for_dbquery( $value );
}, $search );
$search = implode( "','", $search );
$search_terms = " AND name IN ('$search')";
} else {
$search_terms = array_map( function ( $s_term ) {
$s_term = BWFAN_PRO_Common::get_formatted_value_for_dbquery( $s_term );
return "name LIKE '%" . esc_sql( $s_term ) . "%'";
}, $search );
$search_terms = implode( ' OR ', $search_terms );
$search_terms = " AND ($search_terms)";
}
$order = ' ORDER BY `name` ASC';
}
if ( ! empty( $ids ) ) {
$search_terms .= " AND ID IN(" . implode( ',', $ids ) . ")";
}
if ( ! empty( $limit ) ) {
$offset = ! empty( $offset ) ? $offset : 0;
$limit_query = " LIMIT $offset,$limit";
}
$type_query = empty( $type ) ? '' : " AND type='$type'";
$query = "SELECT * FROM `{$wpdb->prefix}bwfan_terms` WHERE 1=1 $type_query $search_terms $order $limit_query";
$term_data = self::get_results( $query );
$term_data = is_array( $term_data ) && ! empty( $term_data ) ? $term_data : array();
/** Store the retrieved terms into the cache */
if ( $use_cache && $eligible_for_cache ) {
self::$terms_cache = array_merge( self::$terms_cache, $term_data );
return array_merge( $found_terms, $term_data );
}
return $term_data;
}
private static function _get_terms_from_cache( $search, $search_nature, $ids, $type ) {
$found_terms = [];
$search_not_found = [];
$ids_not_found = [];
if ( empty( $ids ) && ( 'exact' !== $search_nature || empty( $search ) ) ) {
return [
'found_terms' => $found_terms,
'search_not_found' => $search_not_found,
'ids_not_found' => $ids_not_found
];
}
/**
* In search with exact words (not wildcard words eg %s%), we can get terms by term name.
*/
if ( 'exact' === $search_nature && ! empty( $search ) ) {
if ( ! is_array( $search ) ) {
$search = [ $search ];
}
foreach ( $search as $index => $s_term ) {
$found_term = false;
foreach ( self::$terms_cache as $c_term ) {
if ( ! is_array( $c_term ) || ! isset( $c_term['name'] ) || $s_term !== $c_term['name'] || $c_term['type'] !== $type ) {
continue;
}
$found_term = $c_term;
break;
}
if ( false === $found_term || ! is_array( $found_term ) ) {
$search_not_found[] = $s_term;
} else {
$found_terms[] = $found_term;
}
}
}
/**
* In case we have ids for terms to retrieve, we can get terms by term IDs from cache array.
*/
if ( ! empty( $ids ) && is_array( $ids ) ) {
foreach ( $ids as $term_id ) {
$found_term = false;
foreach ( self::$terms_cache as $c_term ) {
if ( ! is_array( $c_term ) || ! isset( $c_term['name'] ) || absint( $term_id ) !== absint( $c_term['ID'] ) ) {
continue;
}
$found_term = $c_term;
break;
}
if ( false === $found_term || ! is_array( $found_term ) ) {
$ids_not_found[] = absint( $term_id );
} else {
$found_terms[] = $found_term;
}
}
}
return [
'found_terms' => $found_terms,
'search_not_found' => $search_not_found,
'ids_not_found' => $ids_not_found
];
}
public static function checking_term( $term_id, $type = 1 ) {
$query = "SELECT ID from {table_name} where ID='" . $term_id . "' and type='" . $type . "'";
$term_result = self::get_results( $query );
return $term_result;
}
public static function get_all( $type = 1 ) {
$query = "select ID, name from {table_name} where type='" . $type . "'";
$term_results = self::get_results( $query );
return $term_results;
}
/**
* @param $id
*
* @return bool
*/
public static function delete_term( $id ) {
global $wpdb;
$term_table = $wpdb->prefix . 'bwfan_terms';
$delete_term = $wpdb->delete( $term_table, array( 'ID' => $id ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( false === $delete_term ) {
return false;
}
return true;
}
static function insert_multiple( $values, $keys, $format = [] ) {
if ( ( ! is_array( $keys ) || empty( $keys ) ) || ( ! is_array( $values ) || empty( $values ) ) ) {
return false;
}
global $wpdb;
$values = array_map( function ( $value ) use ( $keys ) {
$return = array();
foreach ( $keys as $key ) {
if ( is_numeric( $value[ $key ] ) && 'name' !== $key ) {
$return[] = absint( $value[ $key ] );
}
if ( is_string( $value[ $key ] ) ) {
$formatted_value = BWFAN_PRO_Common::get_formatted_value_for_dbquery( $value[ $key ] );
$return[] = "'" . $formatted_value . "'";
}
}
return '(' . implode( ',', $return ) . ')';
}, $values );
$values = implode( ', ', $values );
$keys = '(' . implode( ', ', $keys ) . ')';
$query = 'INSERT INTO ' . self::_table() . ' ' . $keys . ' VALUES ' . $values;
return $wpdb->query( $wpdb->prepare( "$query ", $values ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* @param int $type
* @param string $search
* @param array $ids
* @param string $search_nature
*
* @return int
*/
static function get_terms_count( $type = 1, $search = '', $ids = array(), $search_nature = '' ) {
global $wpdb;
$search_terms = '';
if ( ! empty( $search ) ) {
if ( ! is_array( $search ) ) {
$search_terms = ( 'exact' === $search_nature ? " AND name = '$search'" : "AND name LIKE '%" . esc_sql( $search ) . "%'" );
$search_terms = 'name_with_dash' === $search_nature ? " AND ( name = '$search' OR name LIKE '" . esc_sql( $search ) . " - %' ) " : $search_terms;
} else if ( 'exact' === $search_nature ) {
$search = implode( "','", $search );
$search_terms = " AND name IN ('$search')";
} else {
$search_terms = array_map( function ( $s_term ) {
return "name LIKE '%" . esc_sql( $s_term ) . "%'";
}, $search );
$search_terms = implode( ' OR ', $search_terms );
$search_terms = " AND ($search_terms)";
}
}
if ( ! empty( $ids ) ) {
$search_terms .= " AND ID IN(" . implode( ',', $ids ) . ")";
}
$query = "SELECT COUNT(ID) from {$wpdb->prefix}bwfan_terms where type='$type' $search_terms ";
return $wpdb->get_var( $query ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* Get term ids
* Create terms if 0 id passed
*
* @param $terms
* @param $type
*
* @return array
*/
public static function get_crm_term_ids( $terms = [], $type = 1 ) {
if ( empty( $terms ) || ! in_array( $type, [ BWFCRM_Term_Type::$TAG, BWFCRM_Term_Type::$LIST ], true ) ) {
return [];
}
foreach ( $terms as $k => $term ) {
if ( ! is_array( $term ) || 0 < intval( $term['id'] ) ) {
continue;
}
$name = ( isset( $term['name'] ) && ! empty( $term['name'] ) ) ? $term['name'] : '';
$name = ( empty( $name ) && isset( $term['value'] ) && ! empty( $term['value'] ) ) ? $term['value'] : $name;
if ( empty( $name ) ) {
continue;
}
/** check if term exists */
$term_row = self::get_term_by_name( $name, $type );
if ( ! empty( $term_row ) ) {
/** term found */
$terms[ $k ]['id'] = $term_row['ID'];
continue;
}
/** create term */
$id = self::create_single_term( $name, $type );
if ( ! empty( $id ) ) {
$terms[ $k ]['id'] = $id;
}
}
$ids = array_column( $terms, 'id' );
$ids = array_unique( $ids );
sort( $ids );
return $ids;
}
/**
* Get term objects
*
* @param $terms
*
* @return array
*/
public static function get_term_objects( $terms = [] ) {
if ( empty( $terms ) ) {
return [];
}
$term_obj = array_map( function ( $term_id ) {
$db_row = BWFAN_Model_Terms::get( $term_id );
if ( ! is_array( $db_row ) ) {
return false;
}
return ( BWFCRM_Term_Type::$TAG === absint( $db_row['type'] ) ? ( new BWFCRM_Tag( $db_row ) ) : ( new BWFCRM_Lists( $db_row ) ) );
}, $terms );
return array_filter( $term_obj );
}
/**
* Create a term
*
* @param $term_name
* @param $type
*
* @return false|int term id
*/
public static function create_single_term( $term_name, $type ) {
global $wpdb;
$data = array(
'name' => $term_name,
'type' => $type,
'created_at' => current_time( 'mysql', 1 ),
);
self::insert( $data );
if ( empty( $wpdb->last_error ) ) {
return $wpdb->insert_id;
}
return false;
}
}
}

View File

@@ -0,0 +1,158 @@
<?php
/**
* Class BWFAN_Rest_API_DB_Model
*/
class BWFAN_Rest_API_DB_Model {
private static function _table() {
/** @var wpdb $wpdb */ global $wpdb;
return $wpdb->prefix . 'bwfan_api_keys';
}
/**
* @param $data
*
* @return int|WP_Error
*/
public static function insert( $data ) {
global $wpdb;
if ( empty( $data ) ) {
new WP_Error( 500, __( 'Data to insert is not provided', 'wp-marketing-automations-pro' ) );
}
$wpdb->insert( self::_table(), $data ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
return ! empty( $wpdb->insert_id ) ? absint( $wpdb->insert_id ) : new WP_Error( 500, $wpdb->last_error );
}
/**
* @param array $columns
* @param array $where
* @param int $limit
* @param int $offset
*
* @return array|object|stdClass[]|null
*/
public static function fetch( $columns = array(), $where = array(), $limit = 0, $offset = 0, $search = '', $grab_count = false ) {
global $wpdb;
$table = self::_table();
if ( ! empty( $columns ) ) {
$column = implode( ',', array_map( function ( $col ) {
return 'p.' . $col;
}, $columns ) );
} else {
$column = 'p.*, u.display_name as user_login,u.user_email';
}
$sql = "Select $column FROM $table as p JOIN {$wpdb->users} as u ON p.uid = u.ID";
$total_sql = "Select count(p.id) FROM $table as p JOIN {$wpdb->users} as u ON p.uid = u.ID";
$where_sql = " WHERE 1=1";
// mapping field and value present in $where and imploding it with &
if ( ! empty( $where ) ) {
$data = array_map( function ( $k, $v ) {
return 'p.' . $k . '=' . $v;
}, array_keys( $where ), array_values( $where ) );
$where_sql .= " AND " . implode( ' AND ', $data );
}
if ( ! empty( $search ) ) {
$where_sql .= " AND (u.user_login LIKE '%$search%' || u.user_email LIKE '%$search%')";
}
if ( ! empty( $where_sql ) ) {
$sql .= $where_sql . ' ORDER BY `id` DESC';
$total_sql .= $where_sql;
}
//adding limit and offset if limit provided
if ( ! empty( $limit ) ) {
$sql .= " LIMIT $offset,$limit";
}
if ( $grab_count ) {
return [
'total' => $wpdb->get_var( $wpdb->prepare( $total_sql ) ), //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
'data' => $wpdb->get_results( $wpdb->prepare( $sql ), ARRAY_A ) //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
];
}
return $wpdb->get_results( $wpdb->prepare( $sql ), ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* @param $data
*
* @return bool|WP_Error
*/
public static function delete( $data ) {
/** @var wpdb $wpdb */ global $wpdb;
if ( empty( $data ) ) {
new WP_Error( 500, __( 'Data to be deleted not provided', 'wp-marketing-automations-pro' ) );
}
if ( false === $wpdb->delete( self::_table(), $data ) ) { //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return new WP_Error( 500, $wpdb->last_error );
}
return true;
}
/**
* @param $data
* @param $where
*
* @return bool|WP_Error
*/
public static function update( $data, $where ) {
global $wpdb;
if ( empty( $data ) || empty( $where ) ) {
new WP_Error( 500, __( 'Data to be updated not provided', 'wp-marketing-automations-pro' ) );
}
if ( false === $wpdb->update( self::_table(), $data, $where ) ) { //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return new WP_Error( 500, $wpdb->last_error );
}
return true;
}
/**
* @param $api_key
*
* @return array|object|stdClass[]|null
*/
public static function get_user_details_by_api( $api_key ) {
global $wpdb;
if ( empty( $api_key ) ) {
new WP_Error( 500, __( 'API key not provided', 'wp-marketing-automations-pro' ) );
}
$table = self::_table();
$sql = "SELECT * FROM $table WHERE api_key = %s";
return $wpdb->get_row( $wpdb->prepare( $sql, $api_key ), ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/**
* @param $api_key_id
* update last access time of the api key
*
* @return bool
*/
public static function update_api_key_last_access( $api_key_id ) {
global $wpdb;
if ( empty( $api_key_id ) ) {
new WP_Error( 500, __( 'API key ID not provided', 'wp-marketing-automations-pro' ) );
}
$wpdb->update( self::_table(), array( 'last_access' => current_time( 'mysql' ) ), array( 'id' => $api_key_id ) ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return true;
}
}

View File

@@ -0,0 +1,103 @@
<?php
class BWFCRM_Model_Automations extends BWFAN_Model {
static $primary_key = 'ID';
protected static function _table() {
global $wpdb;
return $wpdb->prefix . 'bwfan_contact_automations';
}
public static function get_tasks_for_contact( $contact_id ) {
global $wpdb;
$scheduled_tasks = array();
$get_contact_automation_id = $wpdb->get_col( "SELECT DISTINCT automation_id from {$wpdb->prefix}bwfan_contact_automations where contact_id='" . $contact_id . "'" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( empty( $get_contact_automation_id ) ) {
return $scheduled_tasks;
}
$stringPlaceholders = array_fill( 0, count( $get_contact_automation_id ), '%s' );
$placeholdersautomation = implode( ', ', $stringPlaceholders );
$scheduled_tasks_query = $wpdb->prepare( "
SELECT t.ID as id, t.integration_slug as slug, t.integration_action as action, t.automation_id as a_id, t.status as status, t.e_date as date
FROM {$wpdb->prefix}bwfan_tasks as t
LEFT JOIN {$wpdb->prefix}bwfan_taskmeta as m
ON t.ID = m.bwfan_task_id
WHERE t.automation_id IN ($placeholdersautomation)
ORDER BY t.e_date DESC
", $get_contact_automation_id );
$scheduled_tasks = $wpdb->get_results( $scheduled_tasks_query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return $scheduled_tasks;
}
public static function get_logs_for_contact( $contact_id ) {
$contact_logs = array();
global $wpdb;
$get_contact_automation_id = $wpdb->get_col( "SELECT DISTINCT automation_id from {$wpdb->prefix}bwfan_contact_automations where contact_id='" . $contact_id . "'" ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
if ( empty( $get_contact_automation_id ) ) {
return $contact_logs;
}
$stringPlaceholders = array_fill( 0, count( $get_contact_automation_id ), '%s' );
$placeholdersautomation = implode( ', ', $stringPlaceholders );
$contact_logs_query = $wpdb->prepare( "
SELECT l.ID as id, l.integration_slug as slug, l.integration_action as action, l.automation_id as a_id, l.status as status, l.e_date as date
FROM {$wpdb->prefix}bwfan_logs as l
LEFT JOIN {$wpdb->prefix}bwfan_logmeta as m
ON l.ID = m.bwfan_log_id
WHERE l.automation_id IN ($placeholdersautomation)
ORDER BY l.e_date DESC
", $get_contact_automation_id );
$contact_logs = $wpdb->get_results( $contact_logs_query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return $contact_logs;
}
/**
* Get last abandoned cart
*
* @param $contact_email
*
* @return array|object|stdClass[]|null
*/
public static function get_last_abandoned_cart( $contact_email = '' ) {
global $wpdb;
$query = "SELECT `last_modified`, `items`, `total` FROM {$wpdb->prefix}bwfan_abandonedcarts WHERE `status` IN (1,3,4) and `email` = %s ORDER BY `last_modified` DESC LIMIT 0,1";
return $wpdb->get_results( $wpdb->prepare( $query, $contact_email ), ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
}
/** get top automation data
* @return array|object|null
*/
public static function get_top_automations() {
global $wpdb;
$automation_table = $wpdb->prefix . 'bwfan_automations';
$query = "SELECT a.`ID` AS aid, a.`event`, `title` AS name, a.`v`, COUNT(ac.`cid`) AS `contact` FROM {$automation_table} AS a LEFT JOIN {$wpdb->prefix}bwfan_automation_complete_contact AS ac ON ac.aid = a.ID WHERE `status` = 1 GROUP BY ac.`aid` ORDER BY `contact` DESC LIMIT 0,5";
if ( bwfan_is_woocommerce_active() ) {
$conversion_table = $wpdb->prefix . 'bwfan_conversions';
$post_table = $wpdb->prefix . 'posts';
$query = "SELECT c.`oid` AS `aid`,a.`event`, SUM(c.`wctotal`) AS `total_revenue`, a.`v`, a.`title` AS `name` FROM $automation_table AS a LEFT JOIN $conversion_table AS c ON a.ID = c.oid JOIN $post_table AS p ON c.`wcid` = p.`ID` WHERE c.`otype` = 1 GROUP BY c.`oid` ORDER BY `total_revenue` DESC LIMIT 0,5";
}
$automations = $wpdb->get_results( $query, ARRAY_A ); //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
return ! empty( $automations ) ? array_map( function ( $automation ) {
if ( isset( $automation['event'] ) ) {
$event_obj = BWFAN_Core()->sources->get_event( $automation['event'] );
$automation['event'] = ! empty( $event_obj ) ? $event_obj->get_name() : '';
}
return $automation;
}, $automations ) : [];
}
}

View File

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

View File

@@ -0,0 +1,53 @@
<?php
/**
* bwfan_terms table class
*
*/
class BWFAN_DB_Table_API_Keys extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_api_keys';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"id",
"uid",
"permission",
"api_key",
"description",
"status",
"created_by",
"created_at",
"last_access",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`id` bigint(20) unsigned NOT NULL auto_increment,
`uid` bigint(20) unsigned NOT NULL COMMENT 'wp user_id',
`permission` tinyint (1) unsigned COMMENT '1 read | 2 write | 3 read/write',
`api_key` varchar(60) NOT NULL,
`description` varchar(200),
`status` tinyint (1) unsigned default 1 COMMENT '1 active | 2 revoked',
`created_by` bigint(20) unsigned,
`created_at` datetime NOT NULL default '0000-00-00 00:00:00',
`last_access` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
KEY cid (`uid`),
KEY `api_key` (`api_key`)
) $collate;";
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* bwfan_broadcast table class
*
*/
class BWFAN_DB_Table_Broadcast extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_broadcast';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"id",
"title",
"description",
"type",
"status",
"count",
"processed",
"created_by",
"offset",
"modified_by",
"execution_time",
"created_at",
"last_modified",
"data",
"parent",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`id` bigint(20) UNSIGNED NOT NULL auto_increment,
`title` varchar(255) NOT NULL,
`description` longtext,
`type` tinyint(1) unsigned NOT NULL DEFAULT 1,
`status` tinyint(1) unsigned NOT NULL DEFAULT 1,
`count` bigint(10) unsigned NOT NULL,
`processed` bigint(10) unsigned NOT NULL,
`created_by` bigint(20) unsigned NOT NULL,
`offset` bigint(10) unsigned NOT NULL,
`modified_by` bigint(20) NOT NULL,
`execution_time` datetime DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`last_modified` datetime DEFAULT NULL,
`data` longtext,
`parent` bigint(20) unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (`id`),
KEY `type` (`type`),
KEY `status` (`status`)
) $collate;";
}
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* bwfan_bulk_action table class
*
*/
class BWFAN_DB_Table_Bulk_Action extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_bulk_action';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"offset",
"processed",
"count",
"title",
"status",
"actions",
"meta",
"created_by",
"created_at",
"updated_at",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`offset` bigint(20) unsigned NOT NULL,
`processed` bigint(20) unsigned NOT NULL,
`count` bigint(20) unsigned NOT NULL,
`title` varchar(255) default NULL,
`status` tinyint(1) unsigned not null default 0 COMMENT '0 - Draft 1 - Ongoing 2 - Completed 3 - Paused',
`actions` longtext NOT NULL,
`meta` longtext NOT NULL,
`created_by` bigint(10) unsigned default 0,
`created_at` datetime NOT NULL default '0000-00-00 00:00:00',
`updated_at` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`ID`),
KEY `title` (`title`),
KEY `status` (`status`)
) $collate;";
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* bwf_contact_fields table class
*
*/
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_DB_Table_Contact_Fields' ) ) {
class BWFAN_DB_Table_Contact_Fields extends BWFAN_DB_Tables_Base {
public $table_name = 'bwf_contact_fields';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"cid",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`cid` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`ID`),
KEY `cid` (`cid`)
) $collate;";
}
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* bwfan_contact_note table class
*
*/
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_DB_Table_Contact_Note' ) ) {
class BWFAN_DB_Table_Contact_Note extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_contact_note';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"id",
"cid",
"type",
"created_by",
"created_date",
"private",
"title",
"body",
"modified_by",
"modified_date",
"date_time",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`id` bigint(20) unsigned NOT NULL auto_increment,
`cid` bigint(20) unsigned NOT NULL,
`type` varchar(255) NOT NULL,
`created_by` bigint(20),
`created_date` datetime,
`private` tinyint(1) unsigned not null default 0,
`title` varchar(255),
`body` longtext,
`modified_by` bigint(20) default null,
`modified_date` datetime default null,
`date_time` datetime default null,
PRIMARY KEY (`id`),
KEY `cid` (`cid`)
) $collate;";
}
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* bwfan_conversions table class
*
*/
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_DB_Table_Conversions' ) ) {
class BWFAN_DB_Table_Conversions extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_conversions';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"wcid",
"cid",
"trackid",
"oid",
"otype",
"wctotal",
"date",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`wcid` bigint(20) unsigned NOT NULL,
`cid` bigint(20) unsigned NOT NULL,
`trackid` bigint(20) unsigned NOT NULL,
`oid` bigint(20) unsigned NOT NULL,
`otype` tinyint(2) unsigned not null COMMENT '1 - Automation 2 - Campaign 3 - Note 4 - Email 5 - SMS',
`wctotal` varchar(32),
`date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`ID`),
KEY `cid` (`cid`),
KEY `oid` (`oid`),
KEY `otype` (`otype`),
KEY `date` (`date`)
) $collate;";
}
}
}

View File

@@ -0,0 +1,85 @@
<?php
/**
* bwfan_engagement_tracking table class
*
*/
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_DB_Table_Engagement_Tracking' ) ) {
class BWFAN_DB_Table_Engagement_Tracking extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_engagement_tracking';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"cid",
"hash_code",
"created_at",
"updated_at",
"mode",
"send_to",
"type",
"open",
"click",
"oid",
"sid",
"author_id",
"tid",
"o_interaction",
"f_open",
"c_interaction",
"f_click",
"c_status",
"day",
"hour",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`cid` bigint(20) unsigned NOT NULL default 0,
`hash_code` varchar(60) NOT NULL,
`created_at` datetime NOT NULL default '0000-00-00 00:00:00',
`updated_at` datetime default NULL,
`mode` tinyint(1) unsigned not null default 1 COMMENT '1 - Email 2 - SMS',
`send_to` varchar(255) NOT NULL,
`type` tinyint(2) unsigned not null default 1 COMMENT '1 - Automation 2 - Broadcast 3 - Note 4 - Email 5 - SMS',
`open` smallint(3) unsigned NOT NULL default 0,
`click` smallint(3) unsigned NOT NULL default 0,
`oid` bigint(20) unsigned NOT NULL,
`sid` bigint(20) unsigned NOT NULL default 0 COMMENT 'Step ID',
`author_id` bigint(10) unsigned NOT NULL default 1,
`tid` int(20) unsigned NOT NULL default 0 COMMENT 'Template ID',
`o_interaction` varchar(255),
`f_open` datetime default NULL,
`c_interaction` varchar(255),
`f_click` datetime default NULL,
`c_status` tinyint(2) unsigned default 1 COMMENT '1 - Draft 2 - Send 3 - Error 4 - Bounced',
`day` tinyint(1) unsigned default NUll,
`hour` tinyint(2) unsigned default NUll,
PRIMARY KEY (`ID`),
KEY `cid` (`cid`),
KEY `hash_code` (`hash_code`),
KEY `created_at` (`created_at`),
KEY `mode` (`mode`),
KEY `type` (`type`),
KEY `oid` (`oid`),
KEY `sid` (`sid`),
KEY `c_status` (`c_status`)
) $collate;";
}
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* bwfan_engagement_trackingmeta table class
*
*/
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_DB_Table_Engagement_Trackingmeta' ) ) {
class BWFAN_DB_Table_Engagement_Trackingmeta extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_engagement_trackingmeta';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"eid",
"meta_key",
"meta_value",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`eid` bigint(20) unsigned NOT NULL,
`meta_key` varchar(255) default NULL,
`meta_value` longtext,
PRIMARY KEY (`ID`),
KEY `eid` (`eid`)
) $collate;";
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* bwfan_field_groups table class
*
*/
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_DB_Table_Field_Groups' ) ) {
class BWFAN_DB_Table_Field_Groups extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_field_groups';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"name",
"created_at",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`created_at` datetime,
PRIMARY KEY (`ID`)
) $collate;";
}
}
}

View File

@@ -0,0 +1,63 @@
<?php
/**
* bwfan_fields table class
*
*/
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_DB_Table_Fields' ) ) {
class BWFAN_DB_Table_Fields extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_fields';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"name",
"slug",
"type",
"gid",
"meta",
"mode",
"vmode",
"search",
"view",
"created_at",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`slug` varchar(255) NOT NULL,
`type` tinyint(2) unsigned NOT NULL,
`gid` bigint(20) unsigned NOT NULL,
`meta` text NOT NULL,
`mode` tinyint(2) unsigned NOT NULL default 1 COMMENT '1 - Editable 2 - Non-editable',
`vmode` tinyint(2) unsigned NOT NULL default 1 COMMENT '1 - Editable 2 - Non-editable',
`search` tinyint(1) unsigned NOT NULL default 2 COMMENT '1 - Searchable 2 - Non-searchable',
`view` tinyint(1) unsigned NOT NULL default 1 COMMENT '1 - Viwable 2 - Non-Viwable',
`created_at` datetime,
PRIMARY KEY (`ID`),
KEY `slug` (`slug`($this->max_index_length)),
KEY `gid` (`gid`),
KEY `mode` (`mode`),
KEY `vmode` (`vmode`),
KEY `search` (`search`),
KEY `view` (`view`)
) $collate;";
}
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* bwfan_form_feeds table class
*
*/
class BWFAN_DB_Table_Form_Feeds extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_form_feeds';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"title",
"status",
"source",
"contacts",
"created_at",
"updated_at",
"data",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL,
`status` tinyint(1) unsigned NOT NULL DEFAULT 1 COMMENT '1 - Draft 2 - Active 3 - InActive',
`source` varchar(255) NOT NULL,
`contacts` bigint(20) NOT NULL DEFAULT 0,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`data` longtext,
PRIMARY KEY (`ID`),
KEY `source` (`source`(191)),
KEY `status` (`status`)
) $collate;";
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* bwfan_import_export table class
*
*/
if ( ! class_exists( 'BWFAN_DB_Table_Lite_Import_Export' ) ) { // This class exists in FKA Lite, so we check if it exists to avoid conflicts.
class BWFAN_DB_Table_Import_Export extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_import_export';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"id",
"offset",
"processed",
"count",
"type",
"status",
"meta",
"last_modified",
"created_date",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`id` bigint(20) unsigned NOT NULL auto_increment,
`offset` bigint(20) unsigned NOT NULL,
`processed` bigint(20) unsigned NOT NULL,
`count` bigint(20) unsigned NOT NULL,
`type` tinyint(1) unsigned not null default 1,
`status` tinyint(1) unsigned not null default 1,
`meta` text NOT NULL,
`last_modified` datetime default null,
`created_date` datetime,
PRIMARY KEY (`id`),
KEY `type` (`type`),
KEY `status` (`status`)
) $collate;";
}
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* bwfan_link_triggers table class
*
*/
class BWFAN_DB_Table_Link_Triggers extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_link_triggers';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"hash",
"title",
"status",
"total_clicked",
"data",
"created_by",
"created_at",
"updated_at",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`hash` varchar(40) NOT NULL,
`title` varchar(255) default NULL,
`status` tinyint(1) unsigned not null default 1 COMMENT '0 - Draft 1 - Inactive 2 - Active',
`total_clicked` bigint(10) unsigned default 0,
`data` longtext,
`created_by` bigint(10) unsigned default 0,
`created_at` datetime NOT NULL default '0000-00-00 00:00:00',
`updated_at` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`ID`),
KEY `hash` (`hash`),
KEY `title` (`title`),
KEY `status` (`status`)
) $collate;";
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* bwfan_message table class
*
*/
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_DB_Table_Message' ) ) {
class BWFAN_DB_Table_Message extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_message';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"track_id",
"sub",
"body",
"date",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`track_id` bigint(20) unsigned NOT NULL,
`sub` varchar(255) NOT NULL,
`body` longtext,
`date` datetime DEFAULT NULL,
PRIMARY KEY (`ID`),
KEY `track_id` (`track_id`)
) $collate;";
}
}
}

View File

@@ -0,0 +1,61 @@
<?php
class BWFAN_DB_Table_Stripe_Offer extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_stripe_offer';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"cid",
"hash_code",
"oid",
"fid",
"created_at",
"expiry_days",
"updated_at",
"sid",
"clicked",
"order_id",
"order_total",
"order_date",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` INT(10) UNSIGNED NOT NULL auto_increment,
`cid` bigint(10) unsigned NOT NULL,
`hash_code` varchar(60) NOT NULL,
`oid` bigint(10) unsigned NOT NULL COMMENT 'Offer id',
`fid` bigint(10) unsigned NOT NULL COMMENT 'Funnel id',
`created_at` datetime NOT NULL default '0000-00-00 00:00:00',
`expiry_days` smallint(4) unsigned NOT NULL,
`updated_at` datetime NOT NULL default '0000-00-00 00:00:00',
`sid` bigint(10) unsigned NOT NULL COMMENT 'Step id',
`clicked` tinyint(1) unsigned not null default 0,
`order_id` bigint(10) unsigned default NULL,
`order_total` DECIMAL(10,2) default NULL,
`order_date` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`ID`),
KEY `hash_code` (`hash_code`),
KEY `sid` (`sid`),
KEY `order_id` (`order_id`),
KEY `oid` (`oid`),
KEY `fid` (`fid`),
KEY `created_at` (`created_at`)
) $collate;";
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* bwfan_templates table class
*
*/
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_DB_Table_Templates' ) ) {
class BWFAN_DB_Table_Templates extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_templates';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"subject",
"template",
"type",
"title",
"mode",
"data",
"canned",
"created_at",
"updated_at",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`subject` varchar(255) default NULL,
`template` longtext,
`type` tinyint(1) unsigned not null default 1 COMMENT '1 - Email 2 - SMS',
`title` varchar(255) default NULL,
`mode` tinyint(1) NOT NULL default 1 COMMENT '1 - text only 2 - wc 3 - raw html 4 - drag and drop',
`data` longtext,
`canned` tinyint(1) default 0,
`created_at` datetime NOT NULL default '0000-00-00 00:00:00',
`updated_at` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`ID`),
KEY `type` (`type`),
KEY `mode` (`mode`),
KEY `canned` (`canned`)
) $collate;";
}
}
}

View File

@@ -0,0 +1,48 @@
<?php
/**
* bwfan_terms table class
*
*/
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFAN_DB_Table_Terms' ) ) {
class BWFAN_DB_Table_Terms extends BWFAN_DB_Tables_Base {
public $table_name = 'bwfan_terms';
/**
* Get table's columns
*
* @return string[]
*/
public function get_columns() {
return [
"ID",
"name",
"type",
"data",
"created_at",
"updated_at",
];
}
/**
* Get query for create table
*
* @return string
*/
public function get_create_table_query() {
global $wpdb;
$collate = $this->get_collation();
return "CREATE TABLE {$wpdb->prefix}$this->table_name (
`ID` bigint(20) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`type` tinyint(2) unsigned NOT NULL,
`data` longtext,
`created_at` datetime,
`updated_at` datetime,
PRIMARY KEY (`ID`),
KEY `type` (`type`)
) $collate;";
}
}
}

View File

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

View File

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