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,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.