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,395 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
#[AllowDynamicProperties]
final class BWFCRM_Core {
/**
* @var BWFCRM_Core
*/
public static $_instance = null;
private static $_registered_entity = array(
'active' => array(),
'inactive' => array(),
);
/**
* @var BWFCRM_Tag
*/
public $tags;
/**
* @var BWFCRM_Lists
*/
public $lists;
/**
* @var BWFCRM_API_Loader
*/
public $api;
/**
* @var BWFCRM_Admin
*/
public $admin;
/**
* @var BWFCRM_Importer
*/
public $importer;
/**
* @var BWFCRM_Public
*/
public $public;
/**
* @var BWFCRM_Campaigns
*/
public $campaigns;
/**
* @var BWFCRM_Merge_Tags
*/
public $merge_tags;
/**
* @var BWFCRM_Conversation
*/
public $conversation;
/**
* @var BWFCRM_SMS
*/
public $sms;
/**
* @var BWFCRM_Form_Controller
*/
public $forms;
/**
* @var BWFCRM_Email_Webhook_Handler
*/
public $email_webhooks;
/**
* @var BWFCRM_Integrations
*/
public $integrations;
/**
* @var BWFCRM_Email_Editor_Controller
*/
public $email_editor;
/**
* @var BWFCRM_Custom_Filters_Controller
*/
public $custom_filters;
/**
* @var BWFCRM_Link_Trigger_Handler
*/
public $link_trigger_handler;
/**
* @var BWFAN\Rest_API\Response_Handler
*/
public $response_handler;
public $ap;
public $exporter;
/**
* @var BWFCRM_Actions_Handler
*/
public $actions;
public $calls;
public $bulk_action;
private function __construct() {
add_action( 'bwfan_loaded', [ $this, 'init_crm' ], 11 );
add_action( 'bwfan_before_automations_loaded', [ $this, 'add_modules' ] );
add_action( 'bwfan_exporters_loaded', [ $this, 'add_exporters' ] );
// adding localized data
add_action( 'bwfan_admin_view_localize_data', array( $this, 'add_admin_view_localize_data' ), 10, 1 );
}
public function init_crm() {
$this->define_plugin_properties();
$this->register_abstract();
$this->core();
$this->load_dependencies_support();
$this->register_classes();
}
/**
* Defining constants
*/
public function define_plugin_properties() {
define( 'BWFCRM_PLUGIN_FILE', __FILE__ );
define( 'BWFCRM_PLUGIN_DIR', __DIR__ );
define( 'BWFCRM_PLUGIN_URL', untrailingslashit( plugin_dir_url( BWFCRM_PLUGIN_FILE ) ) );
define( 'BWFCRM_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
define( 'BWFCRM_ENCODE', sha1( BWFCRM_PLUGIN_BASENAME ) );
define( 'BWFCRM_WEBHOOK_NAMESPACE', 'autonami-webhook' );
define( 'BWFCRM_IMPORT_DIR_BACKUP', WP_CONTENT_DIR . '/uploads/woofunnels/autonami-import' );
define( 'BWFCRM_IMPORT_DIR', wp_upload_dir()['basedir'] . '/funnelkit/fka-import' );
define( 'BWFCRM_EXPORT_DIR_BACKUP', WP_CONTENT_DIR . '/uploads/woofunnels-upload/autonami-export' );
define( 'BWFCRM_EXPORT_DIR', wp_upload_dir()['basedir'] . '/funnelkit/fka-export' );
define( 'BWFCRM_BULK_ACTION_LOG_DIR_BACKUP', WP_CONTENT_DIR . '/uploads/woofunnels-upload/bulk-action-log' );
define( 'BWFCRM_BULK_ACTION_LOG_DIR', wp_upload_dir()['basedir'] . '/funnelkit/fka-bulk-action-log' );
define( 'BWFCRM_EXPORT_URL_BACKUP', site_url( 'wp-content/uploads/woofunnels-upload/autonami-export/' ) );
define( 'BWFCRM_EXPORT_URL', site_url( wp_upload_dir()['baseurl'] . '/funnelkit/fka-export/' ) );
define( 'BWFCRM_PUBLIC_DIR', BWFCRM_PLUGIN_DIR . '/public' );
define( 'BWFCRM_PUBLIC_URL', BWFCRM_PLUGIN_URL . '/public' );
if ( ! defined( 'BWFAN_REST_API_NAMESPACE' ) ) {
define( 'BWFAN_REST_API_NAMESPACE', 'funnelkit-automations' );
}
( ! defined( 'BWFCRM_REACT_ENVIRONMENT' ) ) ? define( 'BWFCRM_REACT_ENVIRONMENT', 1 ) : '';
define( 'BWFCRM_REACT_PROD_URL', BWFCRM_PLUGIN_URL . '/admin/frontend/dist' );
( 1 === BWFCRM_REACT_ENVIRONMENT ) ? define( 'BWFCRM_VERSION_DEV', BWFAN_PRO_VERSION ) : define( 'BWFCRM_VERSION_DEV', time() );
}
/**
* Setting up event Dependency Classes
*/
public function load_dependencies_support() {
require BWFCRM_PLUGIN_DIR . '/includes/bwfcrm-functions.php';
require BWFCRM_PLUGIN_DIR . '/includes/class-bwfcrm-plugin-dependency.php';
}
/**
* register all the files
*/
public function add_modules() {
$integration_dir = BWFAN_PRO_PLUGIN_DIR . '/autonami';
foreach ( glob( $integration_dir . '/class-*.php' ) as $_field_filename ) {
if ( strpos( $_field_filename, 'index.php' ) !== false ) {
continue;
}
require_once( $_field_filename );
}
do_action( 'bwfan_bwfcrm_integrations_loaded', $this );
}
private function core() {
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-filters.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-automations.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-api-loader.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-importer.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-exporter.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-merge-tags.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-sms.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-campaigns.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-dashboards.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-reports.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-form-feed.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-forms.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-email-webhook-handler.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-integrations.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-email-editor.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-common.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-audience.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-actions.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-custom-filters.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-link-trigger-handler.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-calls.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-bulk-action-handler.php';
require BWFAN_PRO_PLUGIN_DIR . '/public/class-bwfcrm-public.php';
if ( ! BWFAN_PRO_Common::is_lite_3_0() ) {
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-contacts.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-lists.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-fields.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-tag.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-funnels.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-group.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-notes.php';
}
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-templates.php';
require BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-conversation.php';
/** Rest APIs classes */
include BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfan-rest-api-loader.php';
include BWFAN_PRO_PLUGIN_DIR . '/crm/includes/controllers/class-bwfan-rest-api-response-handler.php';
include BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfan-rest-api-common.php';
/** Transactional mail loader */
if( bwfan_is_woocommerce_active() ) {
include BWFAN_PRO_PLUGIN_DIR . '/crm/includes/class-bwfcrm-transactional-mail-loader.php';
}
}
public static function get_instance() {
if ( null === self::$_instance ) {
self::$_instance = new self;
}
return self::$_instance;
}
public function register_classes() {
$load_classes = self::get_registered_class();
if ( is_array( $load_classes ) && count( $load_classes ) > 0 ) {
foreach ( $load_classes as $access_key => $class ) {
if ( ! method_exists( $class, 'get_instance' ) ) {
continue;
}
$this->{$access_key} = $class::get_instance();
}
do_action( 'bwfcrm_loaded' );
}
}
public static function get_registered_class() {
return self::$_registered_entity['active'];
}
public static function register( $short_name, $class, $overrides = null ) {
/** Ignore classes that have been marked as inactive */
if ( in_array( $class, self::$_registered_entity['inactive'], true ) ) {
return;
}
/** Mark classes as active. Override existing active classes if they are supposed to be overridden */
$index = array_search( $overrides, self::$_registered_entity['active'], true );
if ( false !== $index ) {
self::$_registered_entity['active'][ $index ] = $class;
} else {
self::$_registered_entity['active'][ $short_name ] = $class;
}
/** Mark overridden classes as inactive. */
if ( ! empty( $overrides ) ) {
self::$_registered_entity['inactive'][] = $overrides;
}
}
/**
*
* function to register all the abstract classes
**/
private function register_abstract() {
$abstract_path = BWFAN_PRO_PLUGIN_DIR . '/crm/includes/abstracts';
foreach ( glob( $abstract_path . '/class-*.php' ) as $_field_filename ) {
$file_data = pathinfo( $_field_filename );
if ( isset( $file_data['basename'] ) && 'index.php' === $file_data['basename'] ) {
continue;
}
require_once( $_field_filename );
}
}
/**
* Load exporters
*
* @return void
*/
public function add_exporters() {
$exporter_dir = BWFAN_PRO_PLUGIN_DIR . '/crm/includes/exporters';
foreach ( glob( $exporter_dir . '/class-*.php' ) as $_field_filename ) {
$file_data = pathinfo( $_field_filename );
if ( isset( $file_data['basename'] ) && 'index.php' === $file_data['basename'] ) {
continue;
}
require_once( $_field_filename );
}
do_action( 'bwfcrm_exporters_loaded' );
}
/**
* adding public api active status
*
* @param BWFCRM_Base_React_Page $bwfcrm_brp_obj
*
* @return void
*/
public function add_admin_view_localize_data( $bwfcrm_brp_obj ) {
$bwfcrm_brp_obj->page_data['localize_texts'] = [
1 => [
'notice' => [
'text' => __('Your FunnelKit Automation Pro license is not activated!', 'wp-marketing-automations-pro'),
'primary_action' => __('Activate License','wp-marketing-automations-pro'),
],
],
2 => [
'notice' => [
'text' => __('<strong>FunnelKit Automation Pro is Not Fully Activated!</strong> Please activate your license to continue using premium features without interruption.', 'wp-marketing-automations-pro'),
'primary_action' => 'Activate License',
],
'modal' => [
'title' => __( 'FunnelKit Automation PRO is not fully Activated', 'wp-marketing-automations-pro' ),
'featureDesc' => __( 'Without an active license your checkout is not affected. However, you are missing on', 'wp-marketing-automations-pro' ),
'benefits' => [
0 => __( 'New revenue boosting features', 'wp-marketing-automations-pro' ),
1 => __( 'Critical security updates', 'wp-marketing-automations-pro' ),
2 => __( 'Access to premium features', 'wp-marketing-automations-pro' ),
3 => __( 'Access to dedicated support', 'wp-marketing-automations-pro' ),
],
'text_before_cta' => __( 'Don\'t miss out on the additional revenue. This problem is easy to fix.', 'wp-marketing-automations-pro' ),
'primary_action' => __( 'Activate License', 'wp-marketing-automations-pro' ),
],
],
3 => [
'notice' => [
'text' => __( '<strong>Your FunnelKit Automation Pro license has expired!</strong> We\'ve extended its features until {{TIME_GRACE_EXPIRED}}, after which they\'ll be limited.', 'wp-marketing-automations-pro' ),
'primary_action' => __( 'Renew Now', 'wp-marketing-automations-pro' ),
'secondary_action' => __( 'I have My License Key', 'wp-marketing-automations-pro' ),
],
],
4 => [
'notice' => [
'text' => __( '<strong>Your FunnelKit Automation Pro license has expired!</strong> Please renew your license to continue using premium features without interruption.', 'wp-marketing-automations-pro' ),
'primary_action' => __( 'Renew Now', 'wp-marketing-automations-pro' ),
'secondary_action' => __( 'I have My License Key', 'wp-marketing-automations-pro' ),
],
'modal' => [
'title' => __( 'Your License has Expired', 'wp-marketing-automations-pro' ),
'featureDesc' => __( 'Without an active license your checkout is not affected. However, you are missing on', 'wp-marketing-automations-pro' ),
'benefits' => [
0 => __( 'New revenue boosting features', 'wp-marketing-automations-pro' ),
1 => __( 'Critical security updates', 'wp-marketing-automations-pro' ),
2 => __( 'Access to premium features', 'wp-marketing-automations-pro' ),
3 => __( 'Access to dedicated support', 'wp-marketing-automations-pro' ),
],
'text_before_cta' => __( 'Don\'t miss out on the additional revenue. This problem is easy to fix.', 'wp-marketing-automations-pro' ),
'primary_action' => __( 'Renew Now', 'wp-marketing-automations-pro' ),
'secondary_action' => __( 'I have My License Key', 'wp-marketing-automations-pro' ),
],
],
];
$bwfcrm_brp_obj->page_data['social_icon_url'] = 'https://d241ue3yrqqwem.cloudfront.net/social-icons/';
if ( version_compare( BWFAN_VERSION, '3.5.4', '<') ) {
$bwfcrm_brp_obj->page_data['bwfan_nonce'] = get_option( 'bwfan_unique_secret', '' );
}
}
}
if ( ! function_exists( 'BWFCRM_Core' ) ) {
/**
* Global Common function to load all the classes
* @return BWFCRM_Core
*/
function BWFCRM_Core() { //@codingStandardsIgnoreLine
return BWFCRM_Core::get_instance();
}
}
BWFCRM_Core();

View File

@@ -0,0 +1,300 @@
<?php
/**
* Class BWFAN_Rest_API_Base
*/
if ( ! class_exists( 'BWFAN_Rest_API_Base' ) ) {
abstract class BWFAN_Rest_API_Base {
public $route = null;
public $method = null;
public $required = [];
public $validate = [];
public $response_code = 200;
/**
* @var stdClass $pagination
*
* It contains two keys: Limit and Offset, for pagination purposes
*/
public $pagination = null;
public $args = array();
public $request_args = array();
public function __construct() {
$this->pagination = new stdClass();
$this->pagination->limit = 0;
$this->pagination->offset = 0;
}
/**
* @param WP_REST_Request $request
* common function for all the apis
* it collects the data and prepare it for processing
*
* @return WP_Error
*/
public function api_call( WP_REST_Request $request ) {
$params = WP_REST_Server::EDITABLE === $this->method ? $request->get_params() : false;
if ( false === $params ) {
$query_params = $request->get_query_params();
$query_params = is_array( $query_params ) ? $query_params : array();
$request_params = $request->get_params();
$request_params = is_array( $request_params ) ? $request_params : array();
$params = array_replace( $query_params, $request_params );
}
$params['limit'] = $params['limit'] ?? 25;
$params['files'] = $request->get_file_params();
$this->pagination->limit = $params['limit'] ?? $this->pagination->limit;
$page = isset( $params['page'] ) && ! empty( $params['page'] ) ? intval( $params['page'] ) : 0;
if ( isset( $params['offset'] ) && ! empty( $params['offset'] ) ) {
$this->pagination->offset = $params['offset'];
} else {
$this->pagination->offset = ( $page > 0 ) ? ( ( $page - 1 ) * $this->pagination->limit ) : 0;
$params['offset'] = $this->pagination->offset;
}
$this->args = wp_parse_args( $params, $this->default_args_values() );
try {
/** Check if required fields missing */
$this->check_required_fields();
$data_obj = $this->validate_data();
return $this->process_api_call( $data_obj );
} catch ( Error $e ) {
$this->error_response( $e->getMessage(), 500 );
}
}
protected function get_current_api_method() {
return $_SERVER['REQUEST_METHOD'];
}
public function check_required_fields() {
if ( empty( $this->required ) || ! is_array( $this->required ) ) {
return;
}
if ( array_intersect( array_keys( $this->args ), $this->required ) ) {
$verified = true;
foreach ( $this->required as $field ) {
/**
* Checking required field is empty
*/
if ( empty( $this->args[ $field ] ) ) {
$verified = false;
break;
}
}
if ( true === $verified ) {
return;
}
}
BWFCRM_Core()->response_handler->error_response( '', 400, null, 'required_fields_missing' );
}
/**
* Validate requested data
* @return void
*/
public function validate_data() {
if ( empty( $this->validate ) || ! is_array( $this->validate ) ) {
return;
}
$validated = true;
$err_code = '';
$data_obj = '';
$data_obj_id = [];
$code = 422;
$id = $this->get_data_id();
foreach ( $this->validate as $data ) {
switch ( true ) {
case 'contact_already_exists' === $data:
if ( ! isset( $data_obj_id['contact'] ) || ! isset( $data_obj_id['contact']['id'] ) ) {
$data_obj_id['contact']['id'] = $id;
$data_obj = BWFAN_Rest_API_Common::is_contact_exists( $id );
}
if ( false !== $data_obj ) {
$validated = false;
$err_code = 'already_exists';
}
break;
case 'contact_not_exists' === $data:
if ( ! isset( $data_obj_id['contact'] ) || ! isset( $data_obj_id['contact']['id'] ) ) {
$data_obj_id['contact']['id'] = $id;
$data_obj = BWFAN_Rest_API_Common::is_contact_exists( $id );
}
if ( false === $data_obj ) {
$validated = false;
$err_code = 'contact_not_exists';
}
break;
case 'field_not_exists' === $data:
if ( ! isset( $data_obj_id['field'] ) || ! isset( $data_obj_id['field']['id'] ) ) {
$data_obj_id['field']['id'] = $id;
$data_obj = BWFCRM_Fields::is_field_exists( $id );
}
if ( false === $data_obj ) {
$validated = false;
$code = 404;
$err_code = 'data_not_found';
}
break;
case 'list_not_exists' === $data:
if ( ! isset( $data_obj_id['list'] ) || ! isset( $data_obj_id['list']['id'] ) ) {
$data_obj_id['list']['id'] = $id;
$data_obj = new BWFCRM_Lists( $id );
}
if ( false === $data_obj->is_exists() ) {
$validated = false;
$code = 404;
$err_code = 'data_not_found';
}
break;
case 'tag_not_exists' === $data:
if ( ! isset( $data_obj_id['tag'] ) || ! isset( $data_obj_id['tag']['id'] ) ) {
$data_obj_id['tag']['id'] = $id;
$data_obj = new BWFCRM_Tag( $id );
}
if ( false === $data_obj->is_exists() ) {
$validated = false;
$code = 404;
$err_code = 'data_not_found';
}
break;
}
if ( false === $validated ) {
break;
}
}
/** Return if data is validated */
if ( true === $validated ) {
return $data_obj;
}
BWFCRM_Core()->response_handler->error_response( '', $code, null, $err_code );
}
/**
* Get requested data id
* @return mixed|string
*/
public function get_data_id() {
$email = isset( $this->args['email'] ) ? $this->args['email'] : '';
return isset( $this->args['id'] ) ? $this->args['id'] : $email;
}
public function error_response( $message = '', $code = 0, $err_code = '', $wp_error = null ) {
BWFCRM_Core()->response_handler->error_response( $message, $code, $wp_error, $err_code );
}
/**
* @param string $key
* @param string $is_a
* @param string $collection
*
* @return bool|array|mixed
*/
public function get_sanitized_arg( $key = '', $is_a = 'key', $collection = '' ) {
$sanitize_method = ( 'bool' === $is_a ? 'rest_sanitize_boolean' : 'sanitize_' . $is_a );
if ( ! is_array( $collection ) ) {
$collection = $this->args;
}
if ( ! empty( $key ) && isset( $collection[ $key ] ) && ! empty( $collection[ $key ] ) ) {
return call_user_func( $sanitize_method, $collection[ $key ] );
}
if ( ! empty( $key ) ) {
return false;
}
return array_map( $sanitize_method, $collection );
}
/** To be implemented in Child Class. Override in Child Class */
public function get_result_total_count() {
return 0;
}
/** To be implemented in Child Class. Override in Child Class */
public function get_result_count_data() {
return 0;
}
/** To be implemented in Child Class. Override in Child Class */
public function get_result_extra_data() {
return [];
}
public function default_args_values() {
return array();
}
/**
* @param $result_array
* @param string $message
* adding extra response data and sending to response handler
*
* @return mixed
*/
public function success_response( $result_array, $message = '' ) {
BWFCRM_Core()->response_handler->response_code = 200;
$extra_data = array();
/** Total Count */
$total_count = $this->get_result_total_count();
if ( ! empty( $total_count ) ) {
$extra_data['total_count'] = $total_count;
}
/** Count Data */
$count_data = $this->get_result_count_data();
if ( ! empty( $count_data ) ) {
$extra_data['count_data'] = $count_data;
}
/** Extra data */
$extra_data = $this->get_result_extra_data();
if ( ! empty( $extra_data ) ) {
$extra_data['extra_data'] = $extra_data;
}
$api_method = ! empty( $this->get_current_api_method() ) ? $this->get_current_api_method() : 'GET';
/** Pagination */
if ( isset( $this->pagination->limit ) && ( 0 === $this->pagination->limit || ! empty( $this->pagination->limit ) ) && 'GET' === $api_method ) {
$extra_data['limit'] = absint( $this->pagination->limit );
}
if ( isset( $this->pagination->offset ) && ( 0 === $this->pagination->offset || ! empty( $this->pagination->offset ) ) && 'GET' === $api_method ) {
$extra_data['offset'] = absint( $this->pagination->offset );
}
return BWFCRM_Core()->response_handler->success_response( $result_array, $message, $extra_data );
}
/**
* This function should be present in all the classes inheriting this class
*
* @param $data_obj
*
* @return mixed
*/
abstract public function process_api_call();
protected function get_contact_statuses() {
return array( "unverified" => 0, "subscribed" => 1, "bounced" => 2, "unsubscribed" => 3 );
}
}
}

View File

@@ -0,0 +1,136 @@
<?php
namespace BWFCRM\Actions;
/**
* Actions base class
*/
#[\AllowDynamicProperties]
abstract class Base {
/** Handle action response type */
public static $RESPONSE_FAILED = 1;
public static $RESPONSE_SUCCESS = 2;
public static $RESPONSE_SKIPPED = 3;
/**
* Action slug
*
* @var string
*/
protected $slug = '';
/**
* Action nice name
*
* @var string
*/
protected $nice_name = '';
/**
* Action group
*
* @var string
*/
protected $group = '';
/**
* Action group nice name
*
* @var string
*/
protected $group_label = '';
/**
* Action priority to show
*
* @var int
*/
protected $priority = 10;
/**
* Actions support 1 - link triggers, 2 - bulk actions
*
* @var array
*/
protected $support = [];
/**
* Autonami Event slug
* @var string
*/
protected $event_slug = '';
/**
* Returns action slug
*
* @return string
*/
public function get_action_slug() {
return $this->slug;
}
/**
* Returns Actions nice name
*
* @return string
*/
public function get_action_nice_name() {
return $this->nice_name;
}
/**
* Return Action Group slug
*
* @return string
*/
public function get_action_group() {
return $this->group;
}
/**
* Return Action Group nicename
*
* @return string
*/
public function get_action_group_nicename() {
return $this->group_label;
}
/**
* Return Action Group priority
*
* @return int
*/
public function get_action_priority() {
return $this->priority;
}
/**
* Return Action Group supported features
*
* @return array
*/
public function get_action_support() {
return $this->support;
}
/**
* Returns action event slug
*
* @return string
*/
public function get_action_event_slug() {
return $this->event_slug;
}
/**
* Abstract function to get schema
*/
abstract public function get_action_schema();
/**
* Abstract function to process action
*/
abstract public function handle_action( $contact, $data );
}

View File

@@ -0,0 +1,244 @@
<?php
#[AllowDynamicProperties]
abstract class BWFCRM_API_Base {
/**
* @var string $route
*/
public $route = null;
/**
* @var string $method
*/
public $method = null;
/**
* @var stdClass $pagination
*
* It contains two keys: Limit and Offset, for pagination purposes
*/
public $pagination = null;
public $response_code = 200;
public $args = array();
public $request_args = array();
public $public_api = false;
public function __construct() {
$this->pagination = new stdClass();
$this->pagination->limit = 0;
$this->pagination->offset = 0;
}
public function api_call( WP_REST_Request $request ) {
BWFAN_PRO_Common::nocache_headers();
$params = WP_REST_Server::EDITABLE === $this->method ? $request->get_params() : false;
if ( false === $params ) {
$query_params = $request->get_query_params();
$query_params = is_array( $query_params ) ? $query_params : array();
$request_params = $request->get_params();
$request_params = is_array( $request_params ) ? $request_params : array();
$params = array_replace( $query_params, $request_params );
}
if( method_exists( 'BWFAN_Common', 'get_mail_replace_string' ) && isset( $params[ 'content' ] ) && ! empty( $params[ 'content' ] ) && is_string( $params[ 'content' ] ) ) {
$replace_array = BWFAN_Common::get_mail_replace_string();
if ( ! empty( $replace_array ) ) {
$params['content'] = str_replace( array_values( $replace_array ), array_keys( $replace_array ), $params['content'] );
}
}
$params['files'] = $request->get_file_params();
$this->pagination->limit = ! empty( $params['limit'] ) ? absint( $params['limit'] ) : $this->pagination->limit;
$this->pagination->limit = apply_filters( 'bwfcrm_api_pagination_limit', $this->pagination->limit );
$this->pagination->offset = ! empty( $params['offset'] ) ? absint( $params['offset'] ) : 0;
$this->args = wp_parse_args( $params, $this->default_args_values() );
try {
/**
* Include necessary classes so that can run admin rest endpoints.
*/
do_action( 'bwfan_rest_call' );
return $this->process_api_call();
} catch ( Exception $e ) {
$this->response_code = 500;
return $this->error_response( $e->getMessage() );
}
}
public function default_args_values() {
return array();
}
/** To be implemented in Child Class. Override in Child Class */
public function get_result_total_count() {
return 0;
}
/** To be implemented in Child Class. Override in Child Class */
public function get_result_count_data() {
return 0;
}
/** To be implemented in Child Class. Override in Child Class */
public function get_result_extra_data() {
return [];
}
public function error_response( $message = '', $wp_error = null, $code = 0 ) {
if ( 0 !== absint( $code ) ) {
$this->response_code = $code;
} else if ( empty( $this->response_code ) ) {
$this->response_code = 500;
}
$data = array();
if ( $wp_error instanceof WP_Error ) {
$message = $wp_error->get_error_message();
$data = $wp_error->get_error_data();
}
return new WP_Error( $this->response_code, $message, array( 'status' => $this->response_code, 'error_data' => $data ) );
}
public function error_response_200( $message = '', $wp_error = null, $code = 0 ) {
if ( 0 !== absint( $code ) ) {
$this->response_code = $code;
} else if ( empty( $this->response_code ) ) {
$this->response_code = 500;
}
$data = array();
if ( $wp_error instanceof WP_Error ) {
$message = $wp_error->get_error_message();
$data = $wp_error->get_error_data();
}
return new WP_Error( $this->response_code, $message, array( 'status' => 200, 'error_data' => $data ) );
}
public function success_response( $result_array, $message = '' ) {
$response = BWFCRM_Common::format_success_response( $result_array, $message, $this->response_code );
/** Total Count */
$total_count = $this->get_result_total_count();
if ( ! empty( $total_count ) ) {
$response['total_count'] = $total_count;
}
/** Count Data */
$count_data = $this->get_result_count_data();
if ( ! empty( $count_data ) ) {
$response['count_data'] = $count_data;
}
/** Extra data */
$extra_data = $this->get_result_extra_data();
if ( ! empty( $extra_data ) ) {
$response['extra_data'] = $extra_data;
}
/** Pagination */
if ( isset( $this->pagination->limit ) && ( 0 === $this->pagination->limit || ! empty( $this->pagination->limit ) ) ) {
$response['limit'] = absint( $this->pagination->limit );
}
if ( isset( $this->pagination->offset ) && ( 0 === $this->pagination->offset || ! empty( $this->pagination->offset ) ) ) {
$response['offset'] = absint( $this->pagination->offset );
}
return rest_ensure_response( $response );
}
/**
* @param string $key
* @param string $is_a
* @param string $collection
*
* @return bool|array|mixed
*/
public function get_sanitized_arg( $key = '', $is_a = 'key', $collection = '' ) {
$sanitize_method = ( 'bool' === $is_a ? 'rest_sanitize_boolean' : 'sanitize_' . $is_a );
if ( ! is_array( $collection ) ) {
$collection = $this->args;
}
if ( ! empty( $key ) && isset( $collection[ $key ] ) && ! empty( $collection[ $key ] ) ) {
return call_user_func( $sanitize_method, $collection[ $key ] );
}
if ( ! empty( $key ) ) {
return false;
}
return array_map( $sanitize_method, $collection );
}
/**
* Rest api permission callback
*
* @return bool
*/
public function rest_permission_callback( WP_REST_Request $request ) {
$default_permissions = array( 'manage_options' );
$permissions = method_exists( 'BWFAN_Common', 'access_capabilities' ) ? BWFAN_Common::access_capabilities() : $default_permissions;
foreach ( $permissions as $permission ) {
if ( current_user_can( $permission ) ) {
return true;
}
}
return false;
}
public function get_sanitized_url( $key = '' ) {
if ( empty( $key ) || ! isset( $this->args[ $key ] ) || empty( $this->args[ $key ] ) ) {
return false;
}
$url = esc_url_raw( $this->args[ $key ] );
if ( false === wp_http_validate_url( $url ) ) {
return false;
}
return $url;
}
abstract public function process_api_call();
/**
* @param $id_key
* @param $email_key
*
* @return BWFCRM_Contact|WP_Error
*/
public function get_contact_by_id_or_email( $id_key, $email_key ) {
$email = $this->get_sanitized_arg( $email_key, 'text_field' );
$id = $this->get_sanitized_arg( $id_key, 'text_field' );
$id_or_email = ( is_numeric( $id ) && absint( $id ) > 0 ? absint( $id ) : ( is_email( $email ) ? $email : '' ) );
$contact = new BWFCRM_Contact( $id_or_email, true );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
if ( is_numeric( $id_or_email ) ) {
$response = __( 'Unable to get contact with contact ID : ' . $id_or_email, 'wp-marketing-automations-pro' );
} else {
$response = __( 'Contact not exists with email:' . $id_or_email, 'wp-marketing-automations-pro' );
}
return $this->error_response( $response );
}
return $contact;
}
}

View File

@@ -0,0 +1,59 @@
<?php
#[AllowDynamicProperties]
abstract class BWFCRM_API_Start_Import_Base extends BWFCRM_API_Base {
public $importer_slug = '';
public $importer_name = '';
protected function before_create_import( $importer ) {
return;
}
public function process_api_call() {
if ( empty( $this->importer_slug ) || empty( $this->importer_name ) ) {
return $this->error_response( __( 'Invalid Importer name or slug', 'wp-marketing-automations-pro' ), null, 500 );
}
/** @var BWFCRM_Importer_Base $importer */
$importer = BWFCRM_Core()->importer->get_importer( $this->importer_slug );
if ( ! $importer instanceof BWFCRM_Importer_Base ) {
$this->error_response( $this->importer_name . __( 'Importer not found', 'wp-marketing-automations-pro' ), null, 500 );
}
$start_import = $this->get_sanitized_arg( 'start_import', 'bool' );
$import_id = $this->get_sanitized_arg( 'import_id', 'text_field' );
$import_id = empty( $import_id ) ? 0 : absint( $import_id );
/** Get Status if not start import */
if ( ! $start_import ) {
if ( empty( $import_id ) ) {
return $this->error_response( __( 'Invalid Import ID provided.', 'wp-marketing-automations-pro' ), null, 500 );
}
$stats = $importer->get_import_status( $import_id );
return is_string( $stats ) ? $this->error_response( $stats, null, 500 ) : $this->success_response( $stats, '' );
}
/** Inputs */
$tags = isset( $this->args['tags'] ) && is_array( $this->args['tags'] ) ? $this->args['tags'] : array();
$lists = isset( $this->args['lists'] ) && is_array( $this->args['lists'] ) ? $this->args['lists'] : array();
$update_existing = $this->get_sanitized_arg( 'update_existing', 'bool' );
$marketing_status = $this->get_sanitized_arg( 'marketing_status', 'bool' );
$disable_events = $this->get_sanitized_arg( 'disable_events', 'bool' );
$imported_contact_status = $this->get_sanitized_arg( 'imported_contact_status', 'text_field' );
/** Before Creating Import */
$this->before_create_import( $importer );
/** Create Import & Start Importing */
$import_id = $importer->create_import( $tags, $lists, $update_existing, $marketing_status, ! $disable_events, $imported_contact_status );
if ( empty( $import_id ) ) {
return $this->error_response( __( 'Unable to create Import for: ', 'wp-marketing-automations-pro' ) . $this->importer_name, null, 500 );
}
/** Get and Send status */
$stats = $importer->get_import_status( $import_id );
return is_string( $stats ) ? $this->error_response( $stats, null, 500 ) : $this->success_response( $stats, '' );
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace BWFCRM\Calls;
/**
* Calls base class
*/
#[\AllowDynamicProperties]
abstract class Base {
/** Handle action response type */
public static $RESPONSE_FAILED = 1;
public static $RESPONSE_SUCCESS = 2;
public static $RESPONSE_SKIPPED = 3;
/**
* Abstract function to process call
*
* @param $contact
* @param $data
*/
abstract public function process_call( $contact, $data );
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* BWFCRM_Custom_Filter_Base Abstract Class
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class BWFCRM_Custom_Filter_Base
*/
#[AllowDynamicProperties]
abstract class BWFCRM_Custom_Filter_Base {
public $name = '';
/** Helper Functions */
public function maybe_get_current_filter( $custom_filters ) {
if ( ! is_array( $custom_filters ) ) {
return false;
}
foreach ( $custom_filters as $filter ) {
if ( ! is_array( $filter ) || ! isset( $filter['key'] ) || $this->name !== $filter['key'] ) {
continue;
}
return $filter;
}
return false;
}
/** Check if current filter exists in an array of filters */
public function is_current_filter_exists( $custom_filters ) {
$filter = $this->maybe_get_current_filter( $custom_filters );
return false !== $filter;
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* BWFCRM_Email_Webhook_Base Abstract Class
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class BWFCRM_Email_Webhook_Base
*
*/
#[\AllowDynamicProperties]
abstract class BWFCRM_Email_Webhook_Base {
protected $_data = [];
protected $_name = "";
public function set_data( $data = [] ) {
$this->_data = $data;
}
public function get_name() {
return $this->_name;
}
abstract public function handle_webhook();
protected function mark_contact_bounce( $contact_email ) {
$contact = new BWFCRM_Contact( $contact_email );
if ( ! $contact->mark_as_bounced() ) {
BWFAN_Core()->logger->log( "Unable to change contact status to bounce. Contact not found of email: $contact_email", 'crm_email_webhooks' );
}
}
protected function mark_contact_soft_bounce( $contact_email ) {
$contact = new BWFCRM_Contact( $contact_email );
if ( method_exists( $contact, 'mark_as_soft_bounced' ) && ! $contact->mark_as_soft_bounced() ) {
BWFAN_Core()->logger->log( "Unable to change contact status to soft bounce. Contact not found of email: $contact_email", 'crm_email_webhooks' );
}
/** Older FKA lite version do nothing */
}
protected function mark_contact_complaint( $contact_email ) {
$contact = new BWFCRM_Contact( $contact_email );
if ( method_exists( $contact, 'mark_as_complaint' ) ) {
if ( ! $contact->mark_as_complaint() ) {
BWFAN_Core()->logger->log( "Unable to change contact status to complaint. Contact not found of email: $contact_email", 'crm_email_webhooks' );
}
return;
}
/** Older FKA lite version */
if ( ! $contact->mark_as_bounced() ) {
BWFAN_Core()->logger->log( "Unable to change contact status to complaint first then bounce. Contact not found of email: $contact_email", 'crm_email_webhooks' );
}
}
}

View File

@@ -0,0 +1,279 @@
<?php
#[AllowDynamicProperties]
abstract class BWFCRM_Form_Base {
/** Active Feeds based on form, for Create/Update contact */
/** @var BWFCRM_Form_Feed[] $feeds */
protected $feeds = array();
protected $cid = 0;
abstract public function capture_async_submission();
public function find_feeds_and_create_contacts() {
/** Form Source */
$source = $this->get_source();
/** Find Active Feeds */
/** @var BWFCRM_Form_Feed[] $feeds */
$this->feeds = BWFCRM_Core()->forms->get_active_feeds_by_form( $source );
if ( ! is_array( $this->feeds ) || empty( $this->feeds ) ) {
return;
}
/** Filter for feeds related to current submitted form entry */
$this->feeds = $this->filter_feeds_for_current_entry();
if ( ! is_array( $this->feeds ) || empty( $this->feeds ) ) {
return;
}
/** Create Contacts based on those filtered & active feeds */
$this->create_contacts_from_feeds();
}
abstract public function filter_feeds_for_current_entry();
public function create_contacts_from_feeds() {
foreach ( $this->feeds as $feed ) {
$mapped_fields = $feed->get_data( 'mapped_fields' );
$update_existing = $feed->get_data( 'update_existing' );
// Parameter usage is different as per name ( if enabled restrict blank data from update )
$dont_update_blank = $feed->get_data( 'update_blank' );
$contact_data = $this->prepare_contact_data_from_feed_entry( $mapped_fields );
/** Filter blank value from data */
if ( $dont_update_blank ) {
$contact_data = array_filter( $contact_data, function ( $data ) {
return '' !== $data;
} );
}
if ( ! is_array( $contact_data ) || empty( $contact_data ) || ! isset( $contact_data['email'] ) ) {
continue;
}
$contact_data['email'] = trim( $contact_data['email'] );
$cid = isset( $this->cid ) && ! empty( $this->cid ) ? absint( $this->cid ) : 0;
/** Try to Get that Contact */
$contact = new BWFCRM_Contact( ! empty( $cid ) ? $cid : $contact_data['email'] );
/** Increment the Submissions */
$feed->increment_contacts();
$feed->save();
/** Conditions to check if contact is freshly created or not */
$contact_created_at = $contact->is_contact_exists() && ! empty( $contact->contact->get_creation_date() ) ? strtotime( $contact->contact->get_creation_date() ) : false;
$contact_recently_added = ! empty( $contact_created_at ) && ( strtotime( current_time( 'mysql' ) ) - $contact_created_at <= 120 );
/**
* If Contact not exists, or Recently Added, or on FLAG:update existing contact = true.
* Then save the contact, and it's fields
*/
if ( ! $contact->is_contact_exists() || $contact_recently_added || 1 === absint( $update_existing ) ) {
$newly_created = ( ! $contact->is_contact_exists() || $contact_recently_added );
$contact = $this->set_contact_data( $contact, $feed, $contact_data, $newly_created );
$trigger_events = $feed->get_data( 'trigger_events' );
if ( ! $trigger_events && isset( $contact->contact->is_subscribed ) ) {
$contact->contact->is_subscribed = false;
}
$contact->save();
$contact->save_fields();
}
if ( $feed->get_data( 'not_send_to_subscribed' ) && $contact->contact->get_status() == 1 && empty( $contact->check_contact_unsubscribed() ) ) { //also check for not unsubscribe
continue;
}
BWFCRM_Core()->forms->send_incentive_email( $contact, $feed );
}
}
/**
* @param BWFCRM_Contact $contact
* @param BWFCRM_Form_Feed $feed
* @param $contact_data
* @param $new Bool
*
* @return BWFCRM_Contact $contact
*/
public function set_contact_data( $contact, $feed, $contact_data, $new ) {
$cid = isset( $this->cid ) && ! empty( $this->cid ) ? absint( $this->cid ) : 0;
$contact->set_data( $contact_data, $cid );
if ( ! $contact->contact instanceof WooFunnels_Contact ) {
return $contact;
}
/** Set Source to current Form, if source is empty */
if ( empty( $contact->contact->get_source() ) ) {
$contact->contact->set_source( $this->get_source() );
}
/** Set Form Feed ID field, if empty */
if ( empty( $contact->get_field_by_slug( 'form-feed-id' ) ) ) {
$contact->set_field_by_slug( 'form-feed-id', $feed->get_id() );
}
$marketing_status = $feed->get_data( 'marketing_status' );
/** If no status available to set */
if ( 0 === intval( $marketing_status ) ) {
return $this->apply_terms_to_contact_from_feed( $contact, $feed );
}
/** Auto-confirm contacts is enable */
/** If contact unsubscribed then resubscribe */
if ( 1 === intval( $contact->contact->get_status() ) && $contact->check_contact_unsubscribed() ) {
$contact->resubscribe();
/** Set Tags and Lists */
return $this->apply_terms_to_contact_from_feed( $contact, $feed );
}
/** Set status */
$contact->contact->set_status( intval( $marketing_status ) );
/** Set Tags and Lists */
return $this->apply_terms_to_contact_from_feed( $contact, $feed );
}
/**
* @param BWFCRM_Contact $contact
* @param BWFCRM_Form_Feed $feed
*/
public function apply_terms_to_contact_from_feed( $contact, $feed ) {
$tags = $feed->get_data( 'tags' );
$lists = $feed->get_data( 'lists' );
$trigger_events = $feed->get_data( 'trigger_events' );
$tags = is_array( $tags ) ? array_filter( array_values( $tags ) ) : array();
$lists = is_array( $lists ) ? array_filter( array_values( $lists ) ) : array();
! empty( $tags ) && $contact->set_tags( $tags, false, ! $trigger_events );
! empty( $lists ) && $contact->set_lists( $lists, false, ! $trigger_events );
return $contact;
}
/**
* @param BWFCRM_Form_Feed $feed
*
* @return bool
*/
public function is_selected_form_valid( $feed ) {
if ( ! $feed instanceof BWFCRM_Form_Feed ) {
return false;
}
$data = $feed->get_data();
if ( ! is_array( $data ) || empty( $data ) ) {
return false;
}
$steps = $this->get_form_selection( $data, true );
return $this->verify_selected_data( $steps, $data );
}
/**
* Verify if the selected data is valid
*
* @param array $steps
* @param array $data
*
* @return bool
*/
public function verify_selected_data( $steps, $data ) {
if ( ! is_array( $steps ) || empty( $steps ) ) {
return false;
}
$form_meta = $this->get_meta();
$form_meta = array_keys( $form_meta['form_selection_fields'] );
foreach ( $form_meta as $index => $selection ) {
if ( ! isset( $data[ $selection ] ) || empty( $data[ $selection ] ) ) {
return false;
}
$step_no = absint( $index ) + 1;
if ( ! isset( $steps[ $step_no ] ) || ! is_array( $steps[ $step_no ] ) ) {
return false;
}
$step = $steps[ $step_no ]['options'];
$step_value = $data[ $selection ];
$value_found = false;
foreach ( $step as $group ) {
if ( is_array( $group ) && isset( $group[ $step_value ] ) ) {
$value_found = true;
break;
}
}
if ( false === $value_found ) {
return false;
}
}
return true;
}
/**
* @param array $mapped_fields
*
* @return mixed
*/
abstract public function prepare_contact_data_from_feed_entry( $mapped_fields );
abstract public function get_form_selection( $args, $return_all_available );
abstract public function update_form_selection( $args, $feed_id );
abstract public function get_total_selection_steps();
/**
* Returned Form Fields must be in this format ['field_slug'=>'field_name']
*
* @param $feed
*
* @return mixed
*/
abstract public function get_form_fields( $feed );
public function format_form_fields_for_mapping( $fields ) {
if ( ! is_array( $fields ) || empty( $fields ) ) {
return array();
}
$map_fields = array();
foreach ( $fields as $slug => $field ) {
$map_fields[] = array(
'index' => $slug,
'header' => $field,
);
}
return $map_fields;
}
/**
* @return array
*/
abstract public function get_meta();
/** Get Form Source Slug */
abstract public function get_source();
/** Provide link for the id */
abstract public function get_form_link( $feed );
public function get_step_selection_array( $step_name, $step_slug, $step_no, $step_options = array() ) {
return array(
$step_no => array(
'name' => $step_name,
'slug' => $step_slug,
'options' => $step_options,
),
);
}
}

View File

@@ -0,0 +1,6 @@
<?php
abstract class BWFCRM_Import_Export_Type {
public static $IMPORT = 1;
public static $EXPORT = 2;
}

View File

@@ -0,0 +1,23 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Class BWFCRM_Importer
*
* @package Autonami CRM
*/
abstract class BWFCRM_Importer_Base {
protected $log_file = null;
public function get_import_status( $import_id ) {
return array();
}
public function create_import( $tags = array(), $lists = array(), $update_existing = false, $marketing_status = false, $disable_events = true, $imported_contact_status = 1 ) {
return 0;
}
}

View File

@@ -0,0 +1,99 @@
<?php
#[AllowDynamicProperties]
abstract class BWFCRM_Merge_Tag_Base {
protected $_tag_name = '';
protected $_tag_description = '';
public function shortcode_callback( $atts = array() ) {
$tag_data = BWFCRM_Core()->merge_tags->get_data();
$atts = is_array( $atts ) ? array_replace( $atts, $tag_data ) : $tag_data;
/** assign current user id */
if ( isset( $atts['is_preview'] ) && true === $atts['is_preview'] && empty( $atts['contact_id'] ) ) {
$contact = BWFCRM_Common::get_current_user_crm_object();
if ( ! empty( $contact ) ) {
$atts['contact_id'] = $contact->get_id();
}
}
$final_val = isset( $atts['is_preview'] ) && true === $atts['is_preview'] ? $this->get_dummy_value( $atts ) : $this->get_value( $atts );
if ( $final_val instanceof WP_Error ) {
BWFAN_Core()->logger->log( $final_val->get_error_message() . ': ' . get_class( $this ), 'crm_errors' );
return '';
}
return $final_val;
}
public function get_value( $data = array() ) {
return '';
}
public function get_dummy_value( $atts ) {
return '';
}
public function get_name() {
return $this->_tag_name;
}
public function get_description() {
return $this->_tag_description;
}
public function get_array() {
return [
'name' => $this->get_name(),
'description' => $this->get_description()
];
}
/**
* Get date value in WordPress set date format
*
* @param $date_value
*
* @return string
*/
public function get_formatted_date_value( $date_value ) {
if ( empty( $date_value ) ) {
return '';
}
if ( false === $this->validate_date( $date_value ) ) {
return $date_value;
}
$date_format = get_option( 'date_format' ); // e.g. "F j, Y"
$date_value = date( $date_format, strtotime( $date_value ) );
return $date_value;
}
/**
* Validate date
*
* @param $date
* @param string $format
*
* @return bool
*/
public function validate_date( $date, $format = 'Y-m-d' ) {
$d = $date !== null ? DateTime::createFromFormat( $format, $date ) : '';
return $d && $d->format( $format ) === $date;
}
public function maybe_get_contact( $data = array() ) {
if ( ! isset( $data['contact_id'] ) || empty( $data['contact_id'] ) ) {
return BWFCRM_Common::crm_error( __( 'No Contact ID passed in merge tag', 'wp-marketing-automations-pro' ) );
}
$contact_id = absint( $data['contact_id'] );
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
return BWFCRM_Common::crm_error( __( "No contact found with ID: $contact_id", 'wp-marketing-automations-pro' ) );
}
return $contact;
}
}

View File

@@ -0,0 +1,22 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFCRM_Term_Type' ) ) {
#[\AllowDynamicProperties]
abstract class BWFCRM_Term_Type {
public static $TAG = 1;
public static $LIST = 2;
}
if ( ! function_exists( 'bwfcrm_get_term_type_text' ) ) {
function bwfcrm_get_term_type_text( $type = 1 ) {
switch ( $type ) {
case BWFCRM_Term_Type::$TAG:
return 'Tag';
case BWFCRM_Term_Type::$LIST:
return 'List';
}
return 'Tag';
}
}
}

View File

@@ -0,0 +1,419 @@
<?php
if ( ! BWFAN_PRO_Common::is_lite_3_0() && ! class_exists( 'BWFCRM_Term' ) ) {
#[AllowDynamicProperties]
class BWFCRM_Term {
protected $_id = null;
protected $_name = null;
protected $_type = null;
protected $_created_at = null;
protected $_updated_at = null;
protected $_newly_created = false;
protected $_data = '';
public static $tags_by_id = array();
public function __construct( $data = false, $type = 1, $force_create = false ) {
if ( empty( $data ) ) {
$this->_type = $type;
return;
}
/** If data is BWFCRM_Term */
if ( $data instanceof BWFCRM_Term ) {
$this->init_term( $data );
}
/** Check if the term is already stored in cache */
$term = self::maybe_get_term( $data );
if ( false !== $term && $term instanceof BWFCRM_Term ) {
$this->init_term( $term );
}
/** If data is an array */
if ( is_array( $data ) ) {
$this->init_term( $data );
}
/** If data is an integer */
if ( is_numeric( $data ) && 0 < absint( $data ) ) {
$this->init_term( BWFAN_Model_Terms::get( absint( $data ) ) );
}
/** If data is a string */
if ( ! empty( $data ) && is_string( $data ) ) {
$term_row = BWFAN_Model_Terms::get_term_by_name( $data, $type );
/** in case of not found then insert */
if ( empty( $term_row ) && $force_create ) {
$term_row = self::add_term_to_db( $data, $type );
}
if ( ! empty( $term_row ) ) {
$this->init_term( $term_row );
$this->_newly_created = true;
}
}
/** Store terms for further use, within current HTTP Request */
if ( ! empty( $this->get_id() ) ) {
self::$tags_by_id[ $this->get_id() ] = $this;
}
}
public static function maybe_get_term( $data = false ) {
if ( is_array( $data ) && isset( $data['ID'] ) && isset( self::$tags_by_id[ absint( $data['ID'] ) ] ) ) {
return self::$tags_by_id[ absint( $data['ID'] ) ];
}
if ( is_numeric( $data ) && absint( $data ) > 0 ) {
if ( isset( self::$tags_by_id[ absint( $data ) ] ) ) {
return self::$tags_by_id[ absint( $data ) ];
}
}
return false;
}
public function is_exists() {
return is_numeric( $this->get_id() ) && ! empty( $this->get_id() );
}
public function is_newly_created() {
return $this->_newly_created;
}
public static function add_term_to_db( $term_name, $type = 0 ) {
BWFAN_Model_Terms::insert( array(
'name' => $term_name,
'type' => $type,
'created_at' => current_time( 'mysql', 1 ),
) );
return BWFAN_Model_Terms::get( BWFAN_Model_Terms::insert_id() );
}
private function init_term( $db_term ) {
if ( $db_term instanceof BWFCRM_Term ) {
$db_term = array(
'ID' => $db_term->get_id(),
'name' => $db_term->get_name(),
'type' => $db_term->get_type(),
'created_at' => $db_term->get_created_at(),
);
}
$this->_id = isset( $db_term['ID'] ) ? absint( $db_term['ID'] ) : 0;
if ( empty( $this->_id ) && isset( $db_term['_id'] ) ) {
$this->_id = $db_term['_id'];
}
$this->_type = isset( $db_term['type'] ) ? $db_term['type'] : - 1;
if ( empty( $this->_type ) && isset( $db_term['_type'] ) ) {
$this->_type = $db_term['_type'];
}
$this->_name = isset( $db_term['name'] ) ? $db_term['name'] : '';
if ( empty( $this->_name ) && isset( $db_term['_name'] ) ) {
$this->_name = $db_term['_name'];
}
$this->_created_at = isset( $db_term['created_at'] ) ? $db_term['created_at'] : null;
if ( empty( $this->_created_at ) && isset( $db_term['_created_at'] ) ) {
$this->_created_at = $db_term['_created_at'];
}
$this->_updated_at = isset( $db_term['updated_at'] ) ? $db_term['updated_at'] : null;
if ( empty( $this->_updated_at ) && isset( $db_term['_updated_at'] ) ) {
$this->_updated_at = $db_term['_updated_at'];
}
$this->_data = isset( $db_term['data'] ) && ! empty( $db_term['data'] ) ? json_decode( $db_term['data'], true ) : null;
if ( empty( $this->_data ) && isset( $db_term['_data'] ) && ! empty( $db_term['_data'] ) ) {
$this->_data = json_decode( $db_term['_data'], true );
}
}
public function save() {
if ( empty( $this->_name ) || empty( $this->_type ) ) {
return BWFCRM_Common::crm_error( __( 'Required term data is missing.', 'wp-marketing-automations-pro' ) );
}
$term = array(
'name' => $this->_name,
'type' => $this->_type,
'data' => empty( $this->_data ) ? '' : wp_json_encode( $this->_data ),
'updated_at' => current_time( 'mysql', 1 ),
);
if ( ! empty( $this->_id ) ) {
return BWFAN_Model_Terms::update( $term, array( 'ID' => absint( $this->_id ) ) );
} else {
$term['created_at'] = $term['updated_at'];
BWFAN_Model_Terms::insert( $term );
return BWFAN_Model_Terms::insert_id();
}
}
public function get_data() {
return $this->_data;
}
public function get_id() {
return absint( $this->_id );
}
public function get_name() {
return $this->_name;
}
public function set_name( $name ) {
$this->_name = $name;
}
public function get_type() {
return $this->_type;
}
public function get_created_at() {
return $this->_created_at;
}
public function get_updated_at() {
return $this->_updated_at;
}
public function get_array() {
return array(
'ID' => $this->get_id(),
'name' => $this->get_name(),
'type' => $this->get_type(),
'created_at' => $this->get_created_at(),
'updated_at' => $this->get_updated_at(),
'data' => $this->get_data(),
);
}
/**
* @param BWFCRM_Term[] $objects
* @param string $key
*
* @return array[]
*/
public static function get_collection_array( $objects, $key = '' ) {
if ( ! is_array( $objects ) || empty( $objects ) ) {
return array();
}
$array = array_map( function ( $object ) use ( $key ) {
if ( ! $object instanceof BWFCRM_Term ) {
return false;
}
if ( ! empty( $key ) ) {
$value = call_user_func( array( $object, 'get_' . $key ) );
return $value;
}
return $object->get_array();
}, $objects );
return array_filter( $array );
}
public static function get_objects_from_db_rows( $data = array() ) {
if ( ! is_array( $data ) || empty( $data ) ) {
return array();
}
return array_map( function ( $single_data ) {
if ( $single_data instanceof BWFCRM_Term ) {
return $single_data;
}
return ( BWFCRM_Term_Type::$TAG === absint( $single_data['type'] ) ? ( new BWFCRM_Tag( $single_data ) ) : ( new BWFCRM_Lists( $single_data ) ) );
}, $data );
}
public static function get_array_from_db_rows( $data = array() ) {
if ( ! is_array( $data ) || empty( $data ) ) {
return array();
}
return array_map( function ( $single_data ) {
/** To store the db_row in cache i.e.: BWFCRM_Term::$tags_by_id & BWFCRM_Term::$tags_by_slug */
$term = BWFCRM_Term_Type::$TAG === absint( $single_data['type'] ) ? ( new BWFCRM_Tag( $single_data ) ) : ( new BWFCRM_Lists( $single_data ) );
return $term->get_array();
}, $data );
}
public static function get_terms( $type = 1, $ids = array(), $search = '', $offset = 0, $limit = 0, $return = ARRAY_A, $search_nature = '', $use_cache = false ) {
$db_terms = BWFAN_Model_Terms::get_terms( $type, $offset, $limit, $search, $ids, $search_nature, $use_cache );
return ( ARRAY_A === $return ? self::get_array_from_db_rows( $db_terms ) : self::get_objects_from_db_rows( $db_terms ) );
}
public static function get_terms_by_type( $type = 1, $return = ARRAY_A ) {
$db_terms = BWFAN_Model_Terms::get_specific_rows( 'type', $type );
return ARRAY_A === $return ? self::get_array_from_db_rows( $db_terms ) : self::get_objects_from_db_rows( $db_terms );
}
/**
* @param $terms
* @param $type
*
* @return bool
*/
public static function add_terms_to_db( $terms, $type ) {
$terms = array_map( function ( $term ) use ( $type ) {
return array(
'name' => $term,
'type' => $type,
'created_at' => current_time( 'mysql', 1 ),
);
}, $terms );
$result = BWFAN_Model_Terms::insert_multiple( $terms, array( 'name', 'type', 'created_at' ) );
if ( false === $result ) {
return $result;
}
return true;
}
/**
* Terms in Apply Contact Tag will be in this format:
* [
* [ 'id'=> 3, 'name'=>'Product' ],
* [ 'id'=> 1, 'name'=>'Hello' ],
* [ 'id'=> 0, 'name'=>'Hi' ],
* [ 'id'=> 0, 'name'=>'Done' ],
* ]
*
* So we need to differentiate which terms are new and which are already available in DB.
* This method differentiate that
*
* @param $terms
* @param int $type
* @param bool $use_cache
*
* @return array
*/
public static function parse_terms_request( $terms, $type = 1, $use_cache = false ) {
/** Separate new terms from existing terms */
$existing_terms = array();
$new_terms_to_add = array_map( function ( $term ) use ( &$existing_terms ) {
if ( 0 !== absint( $term['id'] ) ) {
$existing_terms[] = $term;
return false;
}
return $term['value'];
}, $terms );
$new_terms_to_add = array_filter( $new_terms_to_add );
/** Get terms by IDs */
$existing_term_ids = array_map( 'absint', array_filter( array_column( $existing_terms, 'id' ) ) );
$db_existing_terms = array();
if ( ! empty( $existing_term_ids ) ) {
$db_existing_terms = BWFAN_Model_Terms::get_terms( $type, 0, count( $existing_term_ids ), '', $existing_term_ids, '', $use_cache );
}
/** Check if any term by IDs missing from DB, then add that term name to "need to be created terms" */
$db_term_ids = array_map( 'absint', array_column( $db_existing_terms, 'ID' ) );
if ( count( $db_existing_terms ) !== count( $existing_terms ) ) {
foreach ( $existing_terms as $e_term ) {
if ( false === array_search( absint( $e_term['id'] ), $db_term_ids ) ) {
$new_terms_to_add[] = $e_term['value'];
}
}
}
/** Array Unique => the (To be Created) term names, and run SQL to check if any term exists by their name */
$new_terms_to_add = array_unique( $new_terms_to_add );
$db_new_terms_to_add = array();
if ( ! empty( $new_terms_to_add ) ) {
$db_new_terms_to_add = BWFAN_Model_Terms::get_terms( $type, 0, 0, $new_terms_to_add, array(), 'exact', $use_cache );
}
/** If any exists, add the term ID to "Need to assigned terms" and remove from "to be created" terms names */
if ( ! empty( $db_new_terms_to_add ) ) {
foreach ( $db_new_terms_to_add as $e_term ) {
if ( false === array_search( $e_term['name'], $new_terms_to_add ) ) {
continue;
}
$new_terms_to_add = array_diff( $new_terms_to_add, array( $e_term['name'] ) );
if ( false === array_search( $e_term['ID'], $db_term_ids ) ) {
$db_term_ids[] = $e_term['ID'];
}
}
}
/** Array Unique => the (To be Assigned) term IDs. (In any case if duplication exists) */
$db_term_ids = array_unique( $db_term_ids );
return array(
'ids' => $db_term_ids,
'names' => $new_terms_to_add,
);
}
/**
* @param array $terms
* @param int $type
* @param bool $create_if_not_exists
* @param bool $separate_created_terms
* @param bool $use_cache
*
* @return array|array[]|BWFCRM_Lists[]|BWFCRM_Tag[]|BWFCRM_Term[]
*/
public static function get_or_create_terms( $terms = array(), $type = 1, $create_if_not_exists = false, $separate_created_terms = false, $use_cache = false ) {
$terms = self::parse_terms_request( $terms, $type, $use_cache );
if ( ! isset( $terms['ids'] ) || ! isset( $terms['names'] ) ) {
return true === $separate_created_terms ? array(
'created' => array(),
'existing' => array(),
) : array();
}
$existing_terms = array();
if ( ! empty( $terms['ids'] ) ) {
$existing_terms = self::get_terms( $type, $terms['ids'], '', 0, 0, OBJECT, '', $use_cache );
}
if ( false === $create_if_not_exists || empty( $terms['names'] ) ) {
return true === $separate_created_terms ? array(
'created' => array(),
'existing' => $existing_terms,
) : $existing_terms;
}
/** Create rest of the terms */
$terms_created = self::add_terms_to_db( $terms['names'], $type );
$new_terms = array();
if ( $terms_created ) {
$new_terms = self::get_terms( $type, array(), $terms['names'], 0, 0, OBJECT, 'exact', $use_cache );
}
/** Get added terms */
if ( false === $separate_created_terms ) {
return array_merge( $existing_terms, $new_terms );
}
return array(
'created' => $new_terms,
'existing' => $existing_terms,
);
}
}
}

View File

@@ -0,0 +1,353 @@
<?php
#[AllowDynamicProperties]
abstract class BWFCRM_Transactional_Mail_Base {
/**
* Slug of mail should be same as class name BWFCRM_Transactional_Mail_Base{ slug }
*
* @var string
*/
protected $slug = '';
/**
* Name of mail
*
* @var string
*/
protected $name = '';
/**
* Description of mail
*
* @var string
*/
protected $description = '';
/**
* Is enabled by user
*
* @var bool
*/
protected $enabled = false;
/**
* Supported block
*
* @var array
*/
protected $supported_block = [];
/**
* Priority of mail to change position of mail in mail list
*
* @var int
*/
protected $priority = 10;
/**
* Supported merge tag groups
*
* @var array
*/
protected $merge_tag_group = [];
/**
* Recipient of mail Admin | Customer
*
* @var string
*/
protected $recipient = '';
/**
* Data for template data to make mail
*
* @var array
*/
protected $template_data = [];
/**
* Subject of mail
*
* @var string
*/
protected $subject = '';
/**
* WC mail id
*
* @var string
*/
protected $wc_mail_id = '';
/**
* Template url
*
* @var string
*/
protected $template_url = 'https://app.getautonami.com/transactional-mail/';
/**
* @function get_data
*/
public function get_data( $key ) {
if ( property_exists( $this, $key ) ) {
return $this->{$key};
}
return null;
}
/**
* Check if mail is valid with dependency
*
* @return bool
*/
public function is_valid() {
return true;
}
/**
* Set status based on template data
*
* @return void
*/
public function set_data_by_template_data() {
if ( empty( $this->template_data ) ) {
return;
}
if ( isset( $this->template_data['status'] ) && $this->template_data['status'] === 'enabled' ) {
$this->enabled = true;
}
}
/**
* Returns API data
*
* @return array
*/
public function get_api_data() {
return [
'slug' => $this->slug,
'name' => $this->name,
'description' => $this->description,
'enabled' => $this->enabled,
'priority' => $this->priority,
'recipient' => $this->recipient,
'template_data' => $this->template_data,
'merge_tag_group' => $this->merge_tag_group,
'supported_block' => $this->supported_block,
];
}
/**
* Create engagement tracking based on passed template id and merge tags data
*
* @param $template_id
* @param $transactional_data
* @param $merge_tags_data
*
* @return bool|mixed
*/
public function create_engagement_tracking( $template_id, $transactional_data, $merge_tags_data = [] ) {
$template_data = BWFCRM_Templates::get_transactional_mail_by_template_id( $template_id );
if ( empty( $template_data ) ) {
return false;
}
// Set flag for transactional mail
$merge_tags_data['bwfan_transactional_mail'] = true;
$email_content = isset( $template_data['data'] ) && BWFAN_Common::is_json( $template_data['data'] ) ? json_decode( $template_data['data'], true ) : [];
$template_email_body = ! empty( $template_data['template'] ) ? $template_data['template'] : '';
$email_subject = ! empty( $template_data['subject'] ) ? $template_data['subject'] : '';
$other_recipient = ! empty( $email_content['other_recipients'] ) ? $email_content['other_recipients'] : '';
if ( empty( $template_email_body ) || empty( $email_subject ) ) {
return false;
}
$recipients = [];
if ( ! empty( $other_recipient ) ) {
$data = explode( ',', $other_recipient );
if ( ! empty( $data ) ) {
foreach ( $data as $recipient ) {
$recipient = BWFAN_Common::decode_merge_tags( trim( $recipient ) );
if ( is_email( $recipient ) ) {
$recipients[] = $recipient;
}
}
}
}
// Set wc trancasactional recipient data
$merge_tags_data['bwfan_wc_transactional_recipient'] = $transactional_data['recipient'];
if ( $transactional_data['recipient'] === 'admin' && empty( $recipients ) ) {
$recipients[] = BWFAN_Common::$admin_email;
}
if ( empty( $recipients ) || $transactional_data['recipient'] === 'customer' ) {
// if customer is recipient then first priority is mail not contact id
$data = ! empty( $merge_tags_data['email'] ) ? $merge_tags_data['email'] : ( ! empty( $merge_tags_data['contact_id'] ) ? $merge_tags_data['contact_id'] : '' );
if ( ! empty( $data ) ) {
$recipients[] = $data;
}
}
/** @var $global_email_settings BWFAN_Common settings */
$global_email_settings = BWFAN_Common::get_global_settings();
/** Apply Click tracking and UTM Params */
$utm_enabled = isset( $email_content['utmEnabled'] ) && 1 === absint( $email_content['utmEnabled'] );
$utm_data = $utm_enabled && isset( $email_content['utm'] ) && is_array( $email_content['utm'] ) ? $email_content['utm'] : array();
/** load block files */
BWFAN_Common::bwfan_before_send_mail( 'block' );
$email_status = false;
foreach ( $recipients as $recipient ) {
$contact = new BWFCRM_Contact( $recipient, true );
if ( ! $contact instanceof BWFCRM_Contact || false === $contact->is_contact_exists() ) {
continue;
}
/** Set email to contact */
$merge_tags_data['email'] = $contact->contact->get_email();
$conversation = new BWFAN_Engagement_Tracking();
$conversation->set_template_id( $template_id );
$conversation->set_oid( isset( $merge_tags_data['oid'] ) ? $merge_tags_data['oid'] : '' );
$conversation->set_mode( BWFAN_Email_Conversations::$MODE_EMAIL );
$conversation->set_contact( $contact );
$conversation->set_send_to( $contact->contact->get_email() );
$conversation->enable_tracking();
$conversation->set_type( BWFAN_Email_Conversations::$TYPE_TRANSACTIONAL );
$conversation->set_template_id( $template_id );
$conversation->set_status( BWFAN_Email_Conversations::$STATUS_DRAFT );
$conversation->add_merge_tags_from_string( $template_email_body, $merge_tags_data );
$conversation->add_merge_tags_from_string( $email_subject, $merge_tags_data );
/** Email Subject */
$email_body = method_exists( 'BWFAN_Common', 'correct_shortcode_string' ) ? BWFAN_Common::correct_shortcode_string( $template_email_body, 5 ) : $template_email_body;
$subject = BWFAN_Common::decode_merge_tags( $email_subject );
$merge_tags = $conversation->get_merge_tags();
$email_body = BWFAN_Common::replace_merge_tags( $email_body, $merge_tags, $contact->get_id() );
$email_body = BWFAN_Common::decode_merge_tags( $email_body );
/** Email Body */
$body = BWFAN_Common::bwfan_correct_protocol_url( $email_body );
$body = BWFCRM_Core()->conversation->apply_template_by_type( $body, 'block', $subject );
$uid = $contact->contact->get_uid();
/** Set contact object */
BWFCRM_Core()->conversation->contact = $contact;
BWFCRM_Core()->conversation->engagement_type = BWFAN_Email_Conversations::$TYPE_TRANSACTIONAL;
if ( property_exists( BWFAN_Core()->conversation, 'template_id' ) ) {
BWFAN_Core()->conversation->template_id = $template_id;
}
$body = BWFCRM_Core()->conversation->append_to_email_body_links( $body, $utm_data, $conversation->get_hash(), $uid );
/** Apply Pre-Header and Hash ID (open pixel id) */
$pre_header = isset( $email_content['preheader'] ) && ! empty( $email_content['preheader'] ) ? $email_content['preheader'] : '';
$pre_header = BWFAN_Common::decode_merge_tags( $pre_header );
$body = BWFCRM_Core()->conversation->append_to_email_body( $body, $pre_header, $conversation->get_hash() );
/** Removed wp mail filters */
BWFCRM_Common::bwf_remove_filter_before_wp_mail();
/** Email Headers */
$reply_to_email = isset( $email_content['reply_to_email'] ) ? BWFAN_Common::decode_merge_tags( $email_content['reply_to_email'] ) : $global_email_settings['bwfan_email_reply_to'];
$from_email = isset( $email_content['from_email'] ) ? BWFAN_Common::decode_merge_tags( $email_content['from_email'] ) : $global_email_settings['bwfan_email_from'];
$from_name = isset( $email_content['from_name'] ) ? BWFAN_Common::decode_merge_tags( $email_content['from_name'] ) : $global_email_settings['bwfan_email_from_name'];
/** Setup Headers */
$header = [ 'MIME-Version: 1.0' ];
if ( ! empty( $from_email ) && ! empty( $from_name ) ) {
$header[] = 'From: ' . $from_name . ' <' . $from_email . '>';
}
if ( ! empty( $reply_to_email ) ) {
$header[] = 'Reply-To: ' . $reply_to_email;
}
$header[] = 'Content-type:text/html;charset=UTF-8';
$header = apply_filters( 'bwfan_email_headers', $header );
BWFCRM_Common::$captured_email_failed_message = null;
/** Send the Email */
$email_status = wp_mail( $conversation->get_send_to(), $subject, $body, $header, $this->get_attachments() );
/** Set the status of Email */
if ( true === $email_status ) {
$conversation->set_status( BWFAN_Email_Conversations::$STATUS_SEND );
} else {
$conversation->set_status( BWFAN_Email_Conversations::$STATUS_ERROR );
}
$conversation->save();
}
return $email_status;
}
/**
* Get email attachments.
*
* @return array
*/
public function get_attachments() {
$merge_tags_data = BWFAN_Merge_Tag_Loader::get_data();
return apply_filters( 'woocommerce_email_attachments', [], $this->wc_mail_id, ! empty( $merge_tags_data['order_id'] ) ? wc_get_order( $merge_tags_data['order_id'] ) : '', null );
}
/**
* Get default template data from api
*
* @param string $lang
*
* @return array
*/
public function get_default_template_data( $lang = '' ) {
$template_data = [
'title' => $this->slug,
'subject' => $this->subject,
'type' => 1,
'mode' => 7,
'canned' => 0,
];
$api_url = $this->template_url . $this->slug . ( ! empty( $lang ) ? '?lang=' . $lang : '' );
// Fetch data from api
$response = wp_remote_get( $api_url );
if ( is_wp_error( $response ) ) {
$fetched_data = [];
} else {
$body = wp_remote_retrieve_body( $response );
$fetched_data = json_decode( $body, true );
if ( json_last_error() !== JSON_ERROR_NONE ) {
$fetched_data = [];
}
}
// Set template data
$template_data['template'] = isset( $fetched_data['html'] ) ? $fetched_data['html'] : '';
$from_name = get_option( 'woocommerce_email_from_name' );
$from_mail = get_option( 'woocommerce_email_from_address' );
// Set mail data
$template_data['data'] = [
'block' => isset( $fetched_data['block'] ) ? $fetched_data['block'] : '',
'preheader' => '',
'utmEnabled' => false,
'utm' => [],
"from_name" => ! empty( $from_name ) ? $from_name : '',
"from_email" => ! empty( $from_mail ) ? $from_mail : '',
"reply_to_email" => ! empty( $from_mail ) ? $from_mail : '',
];
$template_data['data'] = wp_json_encode( $template_data['data'] );
return $template_data;
}
}

View File

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

View File

@@ -0,0 +1,30 @@
<?php
class BWFCRM_API_AFFWP_Start_Import extends BWFCRM_API_Start_Import_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/import/affwp/status';
$this->request_args = array(
'import_id' => array(
'description' => __( 'Get the import status, and Maybe Process this Import ID', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
$this->importer_slug = 'affwp';
$this->importer_name = 'AffiliateWP';
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_AFFWP_Start_Import' );

View File

@@ -0,0 +1,43 @@
<?php
class BWFCRM_API_AFFWP_Import_Affiliates_Count extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/import/affwp/get-affiliate-count';
}
public function process_api_call() {
/** Process */
/** @var BWFCRM_AFFWP_Importer $importer */
$importer = BWFCRM_Core()->importer->get_importer( 'affwp' );
if ( ! $importer instanceof BWFCRM_AFFWP_Importer ) {
return $this->error_response( __( 'affwp Importer not found', 'wp-marketing-automations-pro' ), null, 500 );
}
/** Outputs */
$affiliates_count = $importer->get_affiliates_count();
/** Mark import done, if count is 0 */
if ( 0 === absint( $affiliates_count ) ) {
$key = 'bwfan_import_done';
$imported = get_option( $key, array() );
$imported['affwp'] = 1;
update_option( $key, $imported );
}
return $this->success_response( $affiliates_count, __( 'Affiliates fetched', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_AFFWP_Import_Affiliates_Count' );

View File

@@ -0,0 +1,34 @@
<?php
class BWFCRM_API_AFFWP_Get_Affiliates extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/affwp/contact/(?P<contact_id>[\\d]+)';
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
if ( empty( $contact_id ) ) {
return $this->error_response_200( __( 'No Contact ID provided', 'wp-marketing-automations-pro' ), null, 400 );
}
/** @var BWFCRM_Integration_Affiliate $ins */
$ins = BWFCRM_Core()->integrations->get_integration( 'affwp' );
$details = $ins->get_contact_affiliate_details( absint( $contact_id ) );
return $this->success_response( $details );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_WLM_Get_Contact_Member' );

View File

@@ -0,0 +1,37 @@
<?php
class BWFCRM_API_AFFWP_Get_Referrals extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/affwp/contact/(?P<contact_id>[\\d]+)';
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
if ( empty( $contact_id ) ) {
return $this->error_response_200( __( 'No Contact ID provided', 'wp-marketing-automations-pro' ), null, 400 );
}
$offset = $this->pagination->offset;
$limit = $this->pagination->limit;
/** @var BWFCRM_Integration_Affiliate $ins */
$ins = BWFCRM_Core()->integrations->get_integration( 'affwp' );
$details = $ins->get_contact_referrals( absint( $contact_id ), $offset, $limit );
return $this->success_response( $details );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_AFFWP_Get_Referrals' );

View File

@@ -0,0 +1,70 @@
<?php
class BWFCRM_Api_Create_Audience extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/audience';
$this->response_code = 200;
}
public function default_args_values() {
$args = array(
'name' => '',
'data' => [],
);
return $args;
}
public function process_api_call() {
$name = $this->get_sanitized_arg( 'name', 'text_field', $this->args['name'] );
if ( empty( $name ) ) {
$this->response_code = 400;
$response = __( 'Name is mandatory', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
if ( empty( $this->args['data'] ) || ( is_array( $this->args['data'] ) && empty( $this->args['data']['filters'] ) ) ) {
$this->response_code = 400;
$response = __( 'Filters are mandatory.', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$audience = new BWFCRM_Audience();
$already_exists = $audience->check_audience_is_exists( $name );
if ( absint( $already_exists ) > 0 ) {
$name = "$name - $already_exists";
}
$create_time = current_time( 'mysql', 1 );
$audience->set_audience( 0, $name, $this->args['data'], $create_time, $create_time );
$audience->save();
if ( empty( $audience->get_id() ) ) {
$this->response_code = 500;
return $this->error_response( '', $audience );
}
$audience_data = $audience->get_array();
return $this->success_response( $audience_data, __( 'Audience created', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Create_Audience' );

View File

@@ -0,0 +1,65 @@
<?php
class BWFCRM_Api_Delete_Audience extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/audience/(?P<audience_id>[\\d]+)';
}
public function default_args_values() {
return array( 'audience_id' => '' );
}
public function process_api_call() {
$audience_id = $this->get_sanitized_arg( 'audience_id', 'key' );
if ( empty( $audience_id ) ) {
$this->response_code = 404;
$response = __( 'Audience ID is mandatory', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
/** if the provided id is tag id or not $data */
$audience = new BWFCRM_Audience( $audience_id );
$audience->is_audience_exists();
if ( ! $audience->is_audience_exists() ) {
$this->response_code = 404;
$response = __( "Audience not exist with given ID #" . $audience_id, 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$delete_audince = BWFAN_Model_Terms::delete_term( $audience_id );
if ( false === $delete_audince ) {
$this->response_code = 404;
$response = __( 'Unable to delete the Audience', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$this->response_code = 200;
$success_message = __( 'Audience deleted', 'wp-marketing-automations-pro' );
return $this->success_response( [], $success_message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Delete_Audience' );

View File

@@ -0,0 +1,62 @@
<?php
class BWFCRM_Api_Get_Audience_By_ID extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/audience/(?P<audience_id>[\\d]+)';
}
public function default_args_values() {
return array( 'audience_id' => '' );
}
public function process_api_call() {
$audience_id = $this->get_sanitized_arg( 'audience_id', 'key' );
if ( empty( $audience_id ) ) {
$this->response_code = 404;
$response = __( 'Audience ID is mandatory ', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$audience = new BWFCRM_Audience( absint( $audience_id ) );
if ( ! $audience->is_audience_exists() ) {
$this->response_code = 404;
$response = __( "Audience not exist with given ID #" . $audience_id, 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$audience_data = $audience->get_array();
if ( empty( $audience_data ) ) {
$this->response_code = 404;
$response = __( 'No audience data found related with audience id:' . $audience_id, 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$audience_data['data'] = json_decode( $audience_data['data'] );
$this->response_code = 200;
$success_message = __( 'Audience data found with audience id:' . $audience_id, 'wp-marketing-automations-pro' );
return $this->success_response( $audience_data, $success_message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Get_Audience_By_ID' );

View File

@@ -0,0 +1,85 @@
<?php
class BWFCRM_Api_Get_Audience_Contacts_Count extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/audiences/contacts';
}
public function default_args_values() {
$args = [
'audience_ids' => []
];
return $args;
}
public function process_api_call() {
$audience_ids = $this->get_sanitized_arg( '', 'text_field', $this->args['audience_ids'] );
$data = [];
if ( $audience_ids ) {
foreach ( $audience_ids as $audience_id ) {
$audience = new BWFCRM_Audience( $audience_id );
if ( empty( $audience ) ) {
continue;
}
$audience_data = $audience->get_data();
$audience_data = json_decode( $audience_data, true );
$filters = $audience_data['filters'];
$contacts_count = $this->get_contacts_count( $filters );
$subscribers_count = $this->get_contacts_count( $filters, true );
if ( ! isset( $data[ $audience_id ] ) ) {
$data[ $audience_id ] = [];
}
$data[ $audience_id ]['contact_count'] = is_array( $contacts_count ) && isset( $contacts_count['total_count'] ) ? absint( $contacts_count['total_count'] ) : 0;
$data[ $audience_id ]['subscribers_count'] = is_array( $subscribers_count ) && isset( $subscribers_count['total_count'] ) ? absint( $subscribers_count['total_count'] ) : 0;
}
}
$this->response_code = 200;
return $this->success_response( $data );
}
public function get_contacts_count( $filters, $exclude_unsubscribers = false ) {
$unsubscribed_status = [ 0, 2, 3, 4, 5 ];
/**
* if unverified(0), bounced(2), unsubscribed(3), soft bounced(4) and complaint(5) status available in filter then
* no need to get subscribers count
*/
if ( $exclude_unsubscribers && isset( $filters['status_is'] ) && in_array( absint( $filters['status_is'] ), $unsubscribed_status, true ) ) {
return false;
}
$additional_info = [
'grab_totals' => true,
'only_count' => true,
'customer_data' => false,
];
if ( $exclude_unsubscribers ) {
$filters['status_is'] = 1;
}
return BWFCRM_Contact::get_contacts( '', 0, 5, $filters, $additional_info );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Get_Audience_Contacts_Count' );

View File

@@ -0,0 +1,73 @@
<?php
class BWFCRM_Api_Get_Audiences extends BWFCRM_API_Base {
public static $ins;
public $audiences = array();
public $total_count = 0;
public $count_data = [];
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/audiences';
$this->request_args = array(
'search' => array(
'description' => __( 'Search from name', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'ids' => array(
'description' => __( 'Search from audience ids', 'wp-marketing-automations-pro' ),
'type' => 'string'
),
);
}
public function default_args_values() {
return array( 'ids' => '', 'search' => '' );
}
public function process_api_call() {
/** if isset search param then get the tag by name **/
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$audience_ids = empty( $this->args['ids'] ) ? array() : explode( ',', $this->args['ids'] );
$limit = $this->get_sanitized_arg( 'limit', 'text_field' );
$offset = $this->get_sanitized_arg( 'offset', 'text_field' );
$audiences = BWFAN_Model_Terms::get_terms( 3, $offset, $limit, $search, $audience_ids );
if ( ! is_array( $audiences ) ) {
$audiences = array();
}
$audiences = array_map( function ( $audience ) {
$audience['data'] = json_decode( $audience['data'] );
return $audience;
}, $audiences );
$count = BWFAN_Model_Terms::get_terms_count( 3, $search, $audience_ids );
$this->total_count = $count;
$this->count_data = BWFAN_PRO_Common::get_contact_data_counts();
$this->response_code = 200;
return $this->success_response( $audiences );
}
public function get_result_total_count() {
return $this->total_count;
}
public function get_result_count_data() {
return $this->count_data;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Get_Audiences' );

View File

@@ -0,0 +1,78 @@
<?php
class BWFCRM_Api_Update_Audience extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/audience/(?P<audience_id>[\\d]+)';
}
public function default_args_values() {
$args = array(
'audience_id' => '',
'name' => '',
'data' => ''
);
return $args;
}
public function process_api_call() {
$audience_id = $this->get_sanitized_arg( 'audience_id', 'text_field' );
if ( empty( $audience_id ) ) {
$this->response_code = 404;
$response = __( "Audience Id is mandatory", 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$name = $this->get_sanitized_arg( 'name', 'text_field' );
if ( empty( $name ) ) {
$this->response_code = 404;
$response = __( "Audience name is Mandatory", 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
/** if the provided id is audience id or not $data */
$audience = new BWFCRM_Audience( absint( $audience_id ) );
if ( ! $audience->is_audience_exists() ) {
$this->response_code = 404;
$response = __( "Audience not exist with given ID #" . $audience_id, 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$updated_time = current_time( 'mysql', 1 );
$audience->set_audience( $audience_id, $name, $this->args['data'], '', $updated_time );
$saved = $audience->save();
if ( 0 === $saved ) {
$response = __( 'Unable to update audience with id ' . $audience_id, 'wp-marketing-automations-pro' );
$this->response_code = 400;
return $this->error_response( $response );
}
$response = __( 'Audience updated', 'wp-marketing-automations-pro' );
return $this->success_response( [], $response );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Update_Audience' );

View File

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

View File

@@ -0,0 +1,274 @@
<?php
class BWFCRM_API_Declare_Path_Winner extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public $automation_id = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = 'automation/(?P<automation_id>[\\d]+)/step/(?P<step_id>[\\d]+)/declare-winner';
$this->request_args = array(
'automation_id' => array(
'description' => __( 'Automation id to get split step', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'step_id' => array(
'description' => __( 'Step Id of split test', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'node_id' => array(
'description' => __( 'Step node to get all steps of split step', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'path_num' => array(
'description' => __( 'Path number to declare winner', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function process_api_call() {
$this->automation_id = $this->get_sanitized_arg( 'automation_id' );
$node_id = $this->get_sanitized_arg( 'node_id' );
$path_num = $this->get_sanitized_arg( 'path_num' );
$step_id = $this->get_sanitized_arg( 'step_id' );
if ( empty( $this->automation_id ) || empty( $node_id ) || empty( $path_num ) ) {
return $this->error_response( __( 'Invalid / Empty automation ID provided', 'wp-marketing-automations-pro' ), null, 400 );
}
$current_path = 'p-' . $path_num;
/** Initiate automation object */
$automation_obj = BWFAN_Automation_V2::get_instance( $this->automation_id );
/** Check for automation exists */
if ( ! empty( $automation_obj->error ) ) {
return $this->error_response( [], $automation_obj->error );
}
/** Get all nodes of split step */
$split_steps = BWFAN_Model_Automationmeta::get_meta( $this->automation_id, 'split_steps' );
if ( isset( $split_steps[ $step_id ] ) ) {
$all_steps = $split_steps[ $step_id ];
}
/** Get steps to mark archive */
$steps_for_archive = [];
foreach ( $all_steps as $path => $nodes ) {
if ( $current_path === $path ) {
continue;
}
$steps_for_archive = array_merge( $steps_for_archive, $nodes );
}
$steps_for_archive = array_filter( $steps_for_archive );
/** Mark steps to split archive */
BWFAN_Model_Automation_Step::update_steps_status( $steps_for_archive );
$data = $this->set_winner_path( $step_id, $path_num );
/** Save completed split steps */
$this->save_completed_split( $step_id, $all_steps, $automation_obj );
$this->response_code = 200;
return $this->success_response( $data, __( 'Winner path set', 'wp-marketing-automations-pro' ) );
}
/**
* @param $step_data
*
* @return array|array[]
*/
public function get_path_stats( $step_data ) {
$create_time = $step_data['created_at'];
$data = isset( $step_data['data'] ) ? $step_data['data'] : [];
/** Email and SMS steps in all paths */
$mail_steps = isset( $data['sidebarData']['mail_steps'] ) ? $data['sidebarData']['mail_steps'] : [];
if ( empty( $mail_steps ) ) {
return [];
}
$paths_stats = [];
$step_stats = [];
foreach ( $mail_steps as $path => $steps ) {
$sent = 0;
$open_count = 0;
$click_count = 0;
$revenue = 0;
$unsubscribes = 0;
$conversions = 0;
$contacts_count = 0;
/** Get analytics of each single step */
foreach ( $steps as $step ) {
$stats = BWFCRM_Automations::get_path_stats( $this->automation_id, [ $step ], $create_time, false );
$path_num = str_replace( 'p-', '', $path );
$contact_count = BWFAN_Model_Automation_Contact_Trail::get_path_contact_count( $step_data['ID'], $path_num );
$stats['tiles'][0] = [
'l' => 'Contacts',
'v' => ! empty( $contact_count ) ? intval( $contact_count ) : '-',
];
$sent += intval( $stats['stats']['sent'] );
$open_count += intval( $stats['stats']['open_count'] );
$click_count += intval( $stats['stats']['click_count'] );
$contacts_count += intval( $stats['stats']['contacts_count'] );
$revenue += floatval( $stats['stats']['revenue'] );
$unsubscribes += intval( $stats['stats']['unsubscribes'] );
$conversions += intval( $stats['stats']['conversions'] );
$step_stats[ $step ]['tiles'] = $stats['tiles'];
}
$open_rate = $open_count > 0 ? number_format( ( $open_count / $sent ) * 100, 1 ) : 0;
$click_rate = $click_count > 0 ? number_format( ( $click_count / $sent ) * 100, 1 ) : 0;
$rev_per_person = empty( $contacts_count ) || empty( $revenue ) ? 0 : number_format( $revenue / $contacts_count, 1 );
$unsubscribe_rate = empty( $contacts_count ) || empty( $unsubscribes ) ? 0 : ( $unsubscribes / $contacts_count ) * 100;
/** Get click rate from total opens */
$click_to_open_rate = ( empty( $click_count ) || empty( $open_count ) ) ? 0 : number_format( ( $click_count / $open_count ) * 100, 1 );
$paths_stats[ $path ] = [
[
'l' => __( 'Contact', 'wp-marketing-automations-pro' ),
'v' => empty( $contacts_count ) ? '-' : $contacts_count,
],
[
'l' => __( 'Sent', 'wp-marketing-automations-pro' ),
'v' => empty( $sent ) ? '-' : $sent,
],
[
'l' => __( 'Opened', 'wp-marketing-automations-pro' ),
'v' => empty( $open_count ) ? '-' : $open_count . ' (' . $open_rate . '%)',
],
[
'l' => __( 'Clicked', 'wp-marketing-automations-pro' ),
'v' => empty( $click_count ) ? '-' : $click_count . ' (' . $click_rate . '%)',
],
[
'l' => __( 'Click to Open.', 'wp-marketing-automations-pro' ),
'v' => empty( $click_to_open_rate ) ? '-' : $click_to_open_rate . '%',
],
];
if ( bwfan_is_woocommerce_active() ) {
$currency_symbol = get_woocommerce_currency_symbol();
$revenue = empty( $revenue ) ? '' : html_entity_decode( $currency_symbol . $revenue );
$rev_per_person = empty( $rev_per_person ) ? '-' : html_entity_decode( $currency_symbol . $rev_per_person );
$revenue_tiles = [
[
'l' => __( 'Rev.', 'wp-marketing-automations-pro' ),
'v' => empty( $revenue ) ? '-' : $revenue . ' (' . $conversions . ')',
],
[
'l' => __( 'Rev Per Contact', 'wp-marketing-automations-pro' ),
'v' => empty( $rev_per_person ) ? '-' : $rev_per_person,
]
];
$paths_stats[ $path ] = array_merge( $paths_stats[ $path ], $revenue_tiles );
}
$paths_stats[ $path ][] = [
'l' => __( 'Unsubscribed', 'wp-marketing-automations-pro' ),
'v' => empty( $unsubscribes ) ? '-' : $unsubscribes . ' (' . number_format( $unsubscribe_rate, 1 ) . '%)',
];
}
return [
'paths_stats' => $paths_stats,
'step_steps' => $step_stats
];
}
/**
* Set winner path in split step data
*
* @param $step_id
* @param $winner_path
*
* @return array[]|void
*/
public function set_winner_path( $step_id, $winner_path ) {
/** Step data */
$data = BWFAN_Model_Automation_Step::get_step_data( $step_id );
$sidebarData = isset( $data['data']['sidebarData'] ) ? $data['data']['sidebarData'] : [];
$sidebarData['winner'] = $winner_path;
$sidebarData['complete_time'] = current_time( 'mysql', 1 );
/** Set split stats */
$sidebarData['split_stats'] = $this->get_path_stats( $data );
/** Set split preview data */
$sidebarData['preview_data'] = BWFCRM_Automations::get_split_preview_data( $this->automation_id, $step_id );
$this->save_step_data( $step_id, $sidebarData );
$updated_data = [
'sidebarData' => $sidebarData
];
return $updated_data;
}
/**
* @param $step_id
* @param $sidebarData
*
* @return void
*/
public function save_step_data( $step_id, $sidebarData ) {
$updated_data = [
'sidebarData' => $sidebarData
];
BWFAN_Model_Automation_Step::update( array(
'data' => wp_json_encode( $updated_data ),
'status' => 4,
), array(
'ID' => $step_id,
) );
}
/**
* @param $step_id
* @param $all_steps
* @param $automation_obj
*
* @return bool|void
*/
public function save_completed_split( $step_id, $all_steps, $automation_obj ) {
$meta_data = $automation_obj->get_automation_meta_data();
if ( ! isset( $meta_data['completed_split_steps'] ) ) {
$split_steps = [
$step_id => $all_steps
];
$data = [
'completed_split_steps' => maybe_serialize( $split_steps )
];
return BWFAN_Model_Automationmeta::insert_automation_meta_data( $automation_obj->automation_id, $data );;
}
$split_steps = $meta_data['completed_split_steps'];
$split_steps[ $step_id ] = $all_steps;
$meta_data_arr = [
'completed_split_steps' => maybe_serialize( $split_steps )
];
return BWFAN_Model_Automationmeta::update_automation_meta_values( $automation_obj->automation_id, $meta_data_arr );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Declare_Path_Winner' );

View File

@@ -0,0 +1,82 @@
<?php
class BWFCRM_API_Get_Automation_Conversions extends BWFCRM_API_Base {
public static $ins;
private $aid = 0;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/automation/(?P<automation_id>[\\d]+)/conversions/';
$this->pagination->offset = 0;
$this->pagination->limit = 10;
$this->request_args = array(
'automation_id' => array(
'description' => __( 'Automation ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'offset' => array(
'description' => __( 'Contacts list Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function process_api_call() {
$automation_id = $this->get_sanitized_arg( 'automation_id', 'text_field' );
$automation_obj = BWFAN_Automation_V2::get_instance( $automation_id );
/** Check for automation exists */
if ( ! empty( $automation_obj->error ) ) {
return $this->error_response( [], $automation_obj->error );
}
$this->aid = $automation_id;
$conversions = BWFCRM_Automations::get_conversions( $automation_id, $this->pagination->offset, $this->pagination->limit );
$conversions['automation_data'] = $automation_obj->automation_data;
if ( isset( $conversions['automation_data']['v'] ) && 1 === absint( $conversions['automation_data']['v'] ) ) {
$meta = BWFAN_Model_Automationmeta::get_automation_meta( $automation_id );
$conversions['automation_data']['title'] = isset( $meta['title'] ) ? $meta['title'] : '';
}
if ( empty( $conversions['total'] ) ) {
$this->response_code = 404;
$response = __( "No orders found", "autonami-automations-pro" );
return $this->success_response( $conversions, $response );
}
$this->total_count = $conversions['total'];
return $this->success_response( $conversions, __( 'Got All Orders', 'wp-marketing-automations-pro' ) );
}
public function get_result_total_count() {
return $this->total_count;
}
/**
* @return array
*/
public function get_result_count_data() {
return [
'failed' => BWFAN_Model_Automation_Contact::get_active_count( $this->aid, 2 )
];
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Automation_Conversions' );

View File

@@ -0,0 +1,190 @@
<?php
class BWFCRM_API_Get_Split_Path_Stats_By_Step extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = 'automation/(?P<automation_id>[\\d]+)/step/(?P<step_id>[\\d]+)/path/(?P<path_id>[\\d]+)';
$this->request_args = array(
'automation_id' => array(
'description' => __( 'Automation id to get path stats', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'step_id' => array(
'description' => __( 'Step id to get path stats', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'path_id' => array(
'description' => __( 'Path id to get stats', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function process_api_call() {
$automation_id = $this->get_sanitized_arg( 'automation_id' );
$step_id = $this->get_sanitized_arg( 'step_id' );
$path_id = $this->get_sanitized_arg( 'path_id' );
if ( empty( $automation_id ) || empty( $step_id ) ) {
return $this->error_response( __( 'Invalid / Empty automation ID provided', 'wp-marketing-automations-pro' ), null, 400 );
}
$path_name = 'p-' . $path_id;
/** Initiate automation object */
$automation_obj = BWFAN_Automation_V2::get_instance( $automation_id );
/** Check for automation exists */
if ( ! empty( $automation_obj->error ) ) {
return $this->error_response( [], $automation_obj->error );
}
$step_data = BWFAN_Model_Automation_Step::get_step_data_by_id( $step_id );
$data = isset( $step_data['data'] ) ? json_decode( $step_data['data'], true ) : [];
if ( empty( $data ) || ! is_array( $data ) || ! isset( $data['sidebarData'] ) ) {
return $this->success_response( [], __( 'Path stats not found', 'wp-marketing-automations-pro' ) );
}
/** Email and SMS steps in all paths */
$mail_steps = isset( $data['sidebarData']['mail_steps'] ) ? $data['sidebarData']['mail_steps'] : [];
$split_stats = isset( $data['sidebarData']['split_stats'] ) ? $data['sidebarData']['split_stats'] : [];
$step_stats = isset( $split_stats['step_stats'] ) ? $split_stats['step_stats'] : [];
if ( ! isset( $mail_steps[ $path_name ] ) ) {
return $this->success_response( [], __( 'Path stats not found', 'wp-marketing-automations-pro' ) );
}
$path_steps = $mail_steps[ $path_name ];
$final_data = [];
foreach ( $path_steps as $step_id ) {
if ( ! isset( $step_stats[ $step_id ] ) ) {
$tid_data = BWFAN_Model_Engagement_Tracking::get_engagements_tid( $automation_id, [ $step_id ] );
$tids = array_column( $tid_data, 'tid' );
$templates = BWFAN_Model_Templates::get_templates_by_ids( $tids );
$subject = $type = '';
foreach ( $tid_data as $data ) {
$template = $templates[ $data['tid'] ];
$subject = isset( $template['subject'] ) ? $template['subject'] : '';
$subject = 1 === intval( $template['type'] ) ? $subject : $template['template'];
$type = $template['type'];
}
$tiles = $this->get_path_stats( $automation_id, [ $step_id ], $step_data['created_at'] );
$final_data[] = [
'step' => $step_id,
'title' => $subject,
'type' => $type,
'tile' => $tiles,
];
continue;
}
$final_data[] = [
'step' => $step_id,
'title' => isset( $step_stats[ $step_id ]['subject'] ) ? $step_stats[ $step_id ]['subject'] : '',
'type' => isset( $step_stats[ $step_id ]['type'] ) ? $step_stats[ $step_id ]['type'] : '',
'tile' => $step_stats[ $step_id ]['tiles'],
];
}
$this->response_code = 200;
return $this->success_response( $final_data, __( 'paths stats found', 'wp-marketing-automations-pro' ) );
}
/**
* Get path's stats
*
* @param $automation_id
* @param $step_ids
*
* @return array|WP_Error
*/
public function get_path_stats( $automation_id, $step_ids, $after_date ) {
if ( empty( $step_ids ) ) {
return [];
}
$data = BWFAN_Model_Engagement_Tracking::get_automation_step_analytics( $automation_id, $step_ids, $after_date );
if ( empty( $data ) || ! is_array( $data ) ) {
return [];
}
$open_rate = isset( $data['open_rate'] ) ? number_format( $data['open_rate'], 2 ) : 0;
$click_rate = isset( $data['click_rate'] ) ? number_format( $data['click_rate'], 2 ) : 0;
$revenue = isset( $data['revenue'] ) ? floatval( $data['revenue'] ) : 0;
$unsubscribes = isset( $data['unsbuscribers'] ) ? absint( $data['unsbuscribers'] ) : 0;
$conversions = isset( $data['conversions'] ) ? absint( $data['conversions'] ) : 0;
$sent = isset( $data['sent'] ) ? absint( $data['sent'] ) : 0;
$open_count = isset( $data['open_count'] ) ? absint( $data['open_count'] ) : 0;
$click_count = isset( $data['click_count'] ) ? absint( $data['click_count'] ) : 0;
$contacts_count = isset( $data['contacts_count'] ) ? absint( $data['contacts_count'] ) : 1;
$rev_per_person = empty( $contacts_count ) || empty( $revenue ) ? 0 : number_format( $revenue / $contacts_count, 2 );
$unsubscribe_rate = empty( $contacts_count ) || empty( $unsubscribes ) ? 0 : ( $unsubscribes / $contacts_count ) * 100;
/** Get click rate from total opens */
$click_to_open_rate = ( empty( $click_count ) || empty( $open_count ) ) ? 0 : number_format( ( $click_count / $open_count ) * 100, 2 );
$tiles = [
// [
// 'l' => 'Contacts',
// 'v' => $contacts_count
// ],
[
'l' => __( 'Sent', 'wp-marketing-automations-pro' ),
'v' => $sent,
],
[
'l' => __( 'Opened', 'wp-marketing-automations-pro' ),
'v' => empty( $open_count ) ? '-' : $open_count . '( ' . $open_rate . '% )',
],
[
'l' => __( 'Clicked', 'wp-marketing-automations-pro' ),
'v' => empty( $click_count ) ? '-' : $click_count . ' ( ' . $click_rate . '% )',
],
[
'l' => __( 'Click to Open.', 'wp-marketing-automations-pro' ),
'v' => $click_to_open_rate . '%',
]
];
if ( bwfan_is_woocommerce_active() ) {
$currency_symbol = get_woocommerce_currency_symbol();
$revenue = html_entity_decode( $currency_symbol . $revenue );
$rev_per_person = html_entity_decode( $currency_symbol . $rev_per_person );
$revenue_tiles = [
[
'l' => __( 'Rev.', 'wp-marketing-automations-pro' ),
'v' => empty( $revenue ) ? '-' : $revenue . ' ( ' . $conversions . ' )',
],
[
'l' => __( 'Rev Per Contact', 'wp-marketing-automations-pro' ),
'v' => $rev_per_person,
]
];
$tiles = array_merge( $tiles, $revenue_tiles );
}
$tiles[] = [
'l' => __( 'Unsubscribed', 'wp-marketing-automations-pro' ),
'v' => empty( $unsubscribes ) ? '-' : $unsubscribes . '( ' . number_format( $unsubscribe_rate, 2 ) . '% )',
];
return $tiles;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Split_Path_Stats_By_Step' );

View File

@@ -0,0 +1,115 @@
<?php
class BWFCRM_API_Get_Automation_Path_Stats extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = 'automation/(?P<automation_id>[\\d]+)/step/(?P<step_id>[\\d]+)/path-stats/';
$this->request_args = array(
'automation_id' => array(
'description' => __( 'Automation id to get path stats', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'step_id' => array(
'description' => __( 'Step id to get path stats', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function process_api_call() {
$automation_id = $this->get_sanitized_arg( 'automation_id' );
$step_id = $this->get_sanitized_arg( 'step_id' );
if ( empty( $automation_id ) || empty( $step_id ) ) {
return $this->error_response( __( 'Invalid / Empty automation ID provided', 'wp-marketing-automations-pro' ), null, 400 );
}
/** Initiate automation object */
$automation_obj = BWFAN_Automation_V2::get_instance( $automation_id );
/** Check for automation exists */
if ( ! empty( $automation_obj->error ) ) {
return $this->error_response( [], $automation_obj->error );
}
$step_data = BWFAN_Model_Automation_Step::get_step_data_by_id( $step_id );
$data = isset( $step_data['data'] ) ? json_decode( $step_data['data'], true ) : [];
if ( empty( $data ) || ! is_array( $data ) || ! isset( $data['sidebarData'] ) ) {
return $this->error_response( [], $automation_obj->error );
}
$default_stat = [
[
'l' => 'Sent',
'v' => '-',
],
[
'l' => 'Open Rate',
'v' => '-',
],
[
'l' => 'Click Rate',
'v' => '-',
],
[
'l' => 'Click to Open Rate',
'v' => '-',
],
[
'l' => 'Revenue',
'v' => '-',
],
[
'l' => 'Revenue/Contact',
'v' => '-',
],
[
'l' => 'Unsubscribe Rate',
'v' => '-',
]
];
/** Email and SMS steps in all paths */
$mail_steps = isset( $data['sidebarData']['mail_steps'] ) ? $data['sidebarData']['mail_steps'] : [];
if ( empty( $mail_steps ) ) {
$split_path_count = isset( $data['sidebarData']['split_path'] ) ? intval( $data['sidebarData']['split_path'] ) : 3;
$stats = [];
for ( $i = 1; $i <= $split_path_count; $i ++ ) {
$stats[] = [
'path' => $i,
'tile' => $default_stat,
];
}
return $this->success_response( $stats, __( 'No data found', 'wp-marketing-automations-pro' ) );
}
foreach ( $mail_steps as $path => $step_ids ) {
$path = str_replace( 'p-', '', $path );
$tiles = BWFCRM_Automations::get_path_stats( $automation_id, $step_ids, $step_data['created_at'] );
$stats[] = [
'path' => $path,
'tile' => empty( $tiles ) ? $default_stat : $tiles,
];
}
$this->response_code = 200;
return $this->success_response( $stats, __( 'paths stats found', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Automation_Path_Stats' );

View File

@@ -0,0 +1,53 @@
<?php
class BWFCRM_API_Get_Automation_Recipient_Timeline extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $recipients_timeline = [];
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/automation/(?P<automation_id>[\\d]+)/recipients/(?P<contact_id>[\\d]+)/timeline';
$this->pagination->offset = 0;
$this->pagination->limit = 10;
$this->request_args = array(
'automation_id' => array(
'description' => __( 'Automation ID to retrieve engagements', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'contact_id' => array(
'description' => __( 'Contact ID to retrieve recipient timeline', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function process_api_call() {
$automation_id = $this->get_sanitized_arg( 'automation_id', 'text_field' );
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$mode = ! empty( absint( $this->get_sanitized_arg( 'mode', 'text_field' ) ) ) ? $this->get_sanitized_arg( 'mode', 'text_field' ) : 1;
$recipients_timeline = BWFAN_Model_Engagement_Tracking::get_automation_recipient_timeline( $automation_id, $contact_id, $mode );
if ( empty( $recipients_timeline ) ) {
return $this->success_response( [], __( 'No engagement found', 'wp-marketing-automations-pro' ) );
}
$this->recipients_timeline = $recipients_timeline;
return $this->success_response( $recipients_timeline, __( 'Got All timeline', 'wp-marketing-automations-pro' ) );
}
public function get_result_total_count() {
return count( $this->recipients_timeline );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Automation_Recipient_Timeline' );

View File

@@ -0,0 +1,85 @@
<?php
class BWFCRM_API_Get_Automation_Recipients extends BWFCRM_API_Base {
public static $ins;
private $aid = 0;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/automation/(?P<automation_id>[\\d]+)/recipients/';
$this->pagination->offset = 0;
$this->pagination->limit = 10;
$this->request_args = array(
'automation_id' => array(
'description' => __( 'Automation ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'offset' => array(
'description' => __( 'Contacts list Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function process_api_call() {
$automation_id = $this->get_sanitized_arg( 'automation_id', 'text_field' );
$automation_obj = BWFAN_Automation_V2::get_instance( $automation_id );
/** Check for automation exists */
if ( ! empty( $automation_obj->error ) ) {
return $this->error_response( [], $automation_obj->error );
}
$this->aid = $automation_id;
$recipients = BWFAN_Model_Engagement_Tracking::get_automation_recipents( $automation_id, $this->pagination->offset, $this->pagination->limit );
$recipients['recipients'] = $recipients['conversations'];
unset( $recipients['conversations'] );
$recipients['automation_data'] = $automation_obj->automation_data;
if ( isset( $recipients['automation_data']['v'] ) && 1 === absint( $recipients['automation_data']['v'] ) ) {
$meta = BWFAN_Model_Automationmeta::get_automation_meta( $automation_id );
$recipients['automation_data']['title'] = isset( $meta['title'] ) ? $meta['title'] : '';
}
if ( empty( $recipients['total'] ) ) {
$this->response_code = 404;
$response = __( "No recipients found", "autonami-automations-pro" );
return $this->success_response( $recipients, $response );
}
$this->total_count = $recipients['total'];
return $this->success_response( $recipients, __( 'Got All Recipients', 'wp-marketing-automations-pro' ) );
}
public function get_result_total_count() {
return $this->total_count;
}
/**
* @return array
*/
public function get_result_count_data() {
return [
'failed' => BWFAN_Model_Automation_Contact::get_active_count( $this->aid, 2 )
];
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Automation_Recipients' );

View File

@@ -0,0 +1,64 @@
<?php
class BWFCRM_API_Get_Automation_split_Preview extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = 'automation/(?P<automation_id>[\\d]+)/split/(?P<split_id>[\\d]+)/preview';
$this->request_args = array(
'automation_id' => array(
'description' => __( 'Automation id to get path stats', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'split_id' => array(
'description' => __( 'split id to get preview', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function process_api_call() {
$automation_id = $this->get_sanitized_arg( 'automation_id' );
$split_id = $this->get_sanitized_arg( 'split_id' );
if ( empty( $automation_id ) ) {
return $this->error_response( __( 'Invalid / Empty automation ID provided', 'wp-marketing-automations-pro' ), null, 400 );
}
/** Initiate automation object */
$automation_obj = BWFAN_Automation_V2::get_instance( $automation_id );
/** Check for automation exists */
if ( ! empty( $automation_obj->error ) ) {
return $this->error_response( [], $automation_obj->error );
}
$split_data = BWFAN_Model_Automation_Step::get_step_data( $split_id );
$split_status = isset( $split_data['status'] ) ? intval( $split_data['status'] ) : '';
$this->response_code = 200;
/** Split step is archive */
if ( 4 === $split_status ) {
$data = isset( $split_data['data']['sidebarData']['preview_data'] ) ? $split_data['data']['sidebarData']['preview_data'] : [];
return $this->success_response( $data, __( 'Split step preview', 'wp-marketing-automations-pro' ) );
}
$data = BWFCRM_Automations::get_split_preview_data( $automation_id, $split_id, $automation_obj );
return $this->success_response( $data, __( 'Split step preview', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Automation_split_Preview' );

View File

@@ -0,0 +1,172 @@
<?php
class BWFCRM_API_Get_Automation_split_Stats extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = 'automation/(?P<automation_id>[\\d]+)/split-stats/';
$this->request_args = array(
'automation_id' => array(
'description' => __( 'Automation id to get path stats', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function process_api_call() {
$automation_id = $this->get_sanitized_arg( 'automation_id' );
if ( empty( $automation_id ) ) {
return $this->error_response( __( 'Invalid / Empty automation ID provided', 'wp-marketing-automations-pro' ), null, 400 );
}
/** Initiate automation object */
$automation_obj = BWFAN_Automation_V2::get_instance( $automation_id );
/** Check for automation exists */
if ( ! empty( $automation_obj->error ) ) {
return $this->error_response( [], $automation_obj->error );
}
$meta_data = $automation_obj->get_automation_meta_data();
$split_steps = isset( $meta_data['split_steps'] ) ? $meta_data['split_steps'] : [];
$completed_split_steps = isset( $meta_data['completed_split_steps'] ) ? $meta_data['completed_split_steps'] : [];
$split_steps = array_replace( $split_steps, $completed_split_steps );
$prepared_data = [];
$empty_tiles = [
[
'l' => __( 'Contacts', 'wp-marketing-automations-pro' ),
'v' => '-',
],
[
'l' => __( 'Sent', 'wp-marketing-automations-pro' ),
'v' => '-',
],
[
'l' => __( 'Opened', 'wp-marketing-automations-pro' ),
'v' => '-',
],
[
'l' => __( 'Clicked', 'wp-marketing-automations-pro' ),
'v' => '-',
],
[
'l' => __( 'Click to Open', 'wp-marketing-automations-pro' ),
'v' => '-',
],
[
'l' => __( 'Rev.', 'wp-marketing-automations-pro' ),
'v' => '-',
],
[
'l' => __( 'Rev. Per Contact', 'wp-marketing-automations-pro' ),
'v' => '-',
],
[
'l' => __( 'Unsubscribed', 'wp-marketing-automations-pro' ),
'v' => '-',
]
];
foreach ( $split_steps as $step_id => $step ) {
$data = BWFAN_Model_Automation_Step::get_step_data( $step_id );
$sidebarData = isset( $data['data']['sidebarData'] ) ? $data['data']['sidebarData'] : [];
$paths = isset( $sidebarData['mail_steps'] ) ? $sidebarData['mail_steps'] : [];
$split_stats = isset( $sidebarData['split_stats'] ) ? $sidebarData['split_stats'] : [];
$paths_stats = isset( $split_stats['paths_stats'] ) ? $split_stats['paths_stats'] : [];
$title = isset( $sidebarData['title'] ) ? $sidebarData['title'] : '';
$completed = isset( $sidebarData['complete_time'] ) ? $sidebarData['complete_time'] : '';
$winner = isset( $sidebarData['winner'] ) ? $sidebarData['winner'] : '';
$desc = isset( $sidebarData['desc'] ) ? $sidebarData['desc'] : '';
$prep_data = [
'title' => $title,
'status' => isset( $data['status'] ) && intval( $data['status'] ) !== 4 ? 'ongoing' : 'completed',
'started' => isset( $data['created_at'] ) ? $data['created_at'] : '',
'completed' => $completed,
'desc' => $desc,
'step_id' => $step_id,
];
/** If no steps found in paths */
if ( empty( $paths ) ) {
$split_path_count = isset( $sidebarData['split_path'] ) ? intval( $sidebarData['split_path'] ) : 3;
for ( $i = 1; $i <= $split_path_count; $i ++ ) {
$prep_data['path'][] = [
'path' => $i,
'tile' => $empty_tiles
];
}
}
/** For ongoing split step */
if ( empty( $split_stats ) ) {
foreach ( $paths as $path_name => $mail_steps ) {
$path = str_replace( 'p-', '', $path_name );
if ( empty( $mail_steps ) ) {
$prep_data['path'][] = [
'path' => $path,
'tile' => $empty_tiles
];
continue;
}
$tiles = BWFCRM_Automations::get_path_stats( $automation_id, $mail_steps, $data['created_at'] );
$contact_count = BWFAN_Model_Automation_Contact_Trail::get_path_contact_count( $step_id, $path );
$tiles[0] = [
'l' => __( 'Contacts', 'wp-marketing-automations-pro' ),
'v' => ! empty( $contact_count ) ? intval( $contact_count ) : '-',
];
$prep_data['path'][] = [
'path' => $path,
'tile' => $tiles,
'winner' => false,
];
}
$prepared_data[] = $prep_data;
continue;
}
/** For completed split step */
foreach ( $paths as $path_name => $mail_steps ) {
$path_stats = isset( $paths_stats[ $path_name ] ) ? $paths_stats[ $path_name ] : [];
$p_name = str_replace( 'p-', '', $path_name );
if ( empty( $path_stats ) ) {
$prep_data['path'][] = [
'path' => $p_name,
'tile' => $empty_tiles
];
continue;
}
$prep_data['path'][] = [
'path' => $p_name,
'tile' => $path_stats,
'winner' => ( intval( $winner ) === intval( $p_name ) ),
];
}
$prepared_data[] = $prep_data;
}
$key_values = array_column( $prepared_data, 'started' );
array_multisort( $key_values, SORT_DESC, $prepared_data );
$this->response_code = 200;
return $this->success_response( [
'automation_data' => $automation_obj->get_automation_data(),
'data' => $prepared_data,
], __( 'paths stats found', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Automation_split_Stats' );

View File

@@ -0,0 +1,3 @@
<?php
//silence is golden5

View File

@@ -0,0 +1,38 @@
<?php
class BWFCRM_Api_Get_Generic_rules extends BWFCRM_API_Base {
public static $ins;
public $total_count = 0;
public $count_data = [];
protected $stock_status = '';
protected array $categories = [];
protected $serach_title = '';
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/generic-rules';
}
public function process_api_call() {
$rules = BWFAN_PRO_Common::get_generic_rules();
return $this->success_response( $rules );
}
public function get_result_count_data() {
return $this->count_data;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Get_Generic_rules' );

View File

@@ -0,0 +1,76 @@
<?php
/**
* Bulk Action Clone API file
*
* @package BWFCRM_API_Base
*/
/**
* Bulk Action Clone API class
*/
class BWFCRM_API_Clone_Bulk_Action extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/bulk-action/(?P<id>[\\d]+)/clone';
$this->request_args = array(
'id' => array(
'description' => __( 'Bulk action ID whose data to be cloned.', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'id' => 0,
);
}
/**
* API callback
*/
public function process_api_call() {
$id = $this->get_sanitized_arg( 'id', 'key' );
if ( intval( $id ) > 0 ) {
$data = BWFAN_Model_Bulk_Action::clone_bulk_action( $id );
$this->response_code = $data['status'];
if ( $data['status'] === 200 ) {
return $this->success_response( [], $data['message'] );
}
return $this->error_response( $data['message'] );
}
$this->response_code = 404;
return $this->error_response( __( 'Please provide a valid bulk action id.', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Clone_Bulk_Action' );

View File

@@ -0,0 +1,144 @@
<?php
/**
* Create bulk action API
*/
class BWFCRM_Api_Create_Bulk_Action extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/bulk-action';
$this->response_code = 200;
}
public function default_args_values() {
return array(
'title' => '',
);
}
public function process_api_call() {
$title = $this->get_sanitized_arg( 'title', 'text_field', $this->args['title'] );
$only_action = isset( $this->args['only_action'] ) && boolval( $this->args['only_action'] );
$include_ids = isset( $this->args['include_ids'] ) && ! empty( $this->args['include_ids'] ) ? $this->args['include_ids'] : [];
$actions = isset( $this->args['actions'] ) && ! empty( $this->args['actions'] ) ? $this->args['actions'] : [];
if ( empty( $title ) && ! $only_action ) {
$this->response_code = 400;
$response = __( 'Oops Title not entered, enter title to create bulk action', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$already_exists = ! $only_action ? BWFAN_Model_Bulk_Action::check_bulk_action_exists_with( 'title', $title ) : false;
if ( $already_exists ) {
$this->response_code = 400;
$response = __( 'Bulk Action already exists with title : ', 'wp-marketing-automations-pro' ) . $title;
return $this->error_response( $response );
}
$utc_time = current_time( 'mysql', 1 );
$store_time = current_time( 'mysql' );
$data = [
'title' => $only_action ? __( 'Contacts Bulk Action ', 'wp-marketing-automation-pro' ) . '(' . $store_time . ')' : $title,
'status' => 0,
'created_by' => get_current_user_id(),
'created_at' => $utc_time,
'updated_at' => $utc_time,
];
if ( $only_action ) {
if ( empty( $actions ) ) {
$this->response_code = 400;
$response = __( 'Oops Actions not entered, enter actions to create bulk action', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
/** Check for directory exists */
if ( ! file_exists( BWFCRM_BULK_ACTION_LOG_DIR . '/' ) ) {
wp_mkdir_p( BWFCRM_BULK_ACTION_LOG_DIR );
}
/** Create log file */
$file_name = 'FKA-Bulk-Action-' . time() . '-' . wp_generate_password( 5, false ) . '-log.csv';
/** Open log file */
$file = fopen( BWFCRM_BULK_ACTION_LOG_DIR . '/' . $file_name, "wb" );
if ( ! empty( $file ) ) {
/** Updating headers in log file */
fputcsv( $file, array_merge( [ 'Contact ID' ], array_keys( $actions ) ) );
/** Close log file */
fclose( $file );
}
$enable_automation = isset( $this->args['enable_automation'] ) && boolval( $this->args['enable_automation'] );
$data['actions'] = json_encode( $this->add_new_list_and_tags( $actions ) );
$data['status'] = 1;
$data['count'] = count( $include_ids );
// Set meta data
$data['meta']['include_ids'] = $include_ids;
$data['meta']['log_file'] = $file_name;
$data['meta']['enable_automation_run'] = $enable_automation;
$data['meta'] = json_encode( $data['meta'] );
}
$result = BWFAN_Model_Bulk_Action::bwfan_create_new_bulk_action( $data );
if ( empty( $result ) ) {
$this->response_code = 500;
return $this->error_response( __( 'Unable to create bulk action', 'wp-marketing-automations-pro' ) );
}
if ( $only_action ) {
BWFCRM_Core()->bulk_action->schedule_bulk_action( $result );
}
return $this->success_response( [ 'id' => $result ], __( 'Bulk action created', 'wp-marketing-automations-pro' ) );
}
/**
* Create tags and list
*
* @param $actions
*
* @return array
*/
public function add_new_list_and_tags( $actions ) {
foreach ( $actions as $action_key => $action_val ) {
$terms = [];
$term_type = 0;
if ( $action_key === 'add_tags' ) {
$term_type = BWFCRM_Term_Type::$TAG;
$terms = $action_val;
} else if ( $action_key === 'add_to_lists' ) {
$term_type = BWFCRM_Term_Type::$LIST;
$terms = $action_val;
}
if ( is_array( $terms ) && ! empty( $terms ) && method_exists( 'BWFAN_PRO_Common', 'get_or_create_terms' ) ) {
$terms = BWFAN_PRO_Common::get_or_create_terms( $terms, $term_type );
$actions[ $action_key ] = $terms;
}
}
return $actions;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Create_Bulk_Action' );

View File

@@ -0,0 +1,52 @@
<?php
class BWFCRM_Api_Delete_Bulk_Action extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/bulk-actions/delete';
}
public function default_args_values() {
return array(
'ids' => [],
);
}
public function process_api_call() {
$ids = $this->args['ids'];
if ( empty( $ids ) || ! is_array( $ids ) ) {
return $this->error_response( __( 'Bulk actions ids are missing.', 'wp-marketing-automations-pro' ), null, 500 );
}
/** delete actions */
$deleted = BWFAN_Model_Bulk_Action::delete_multiple_bulk_actions( $ids );
if ( false === $deleted ) {
$this->response_code = 404;
$response = __( 'Unable to delete the bulk actions', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$this->response_code = 200;
$success_message = __( 'Bulk action deleted', 'wp-marketing-automations-pro' );
return $this->success_response( [], $success_message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Delete_Bulk_Action' );

View File

@@ -0,0 +1,76 @@
<?php
class BWFCRM_API_Download_Log_File extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = 'bulk-action/download/(?P<bulk_action_id>[\\d]+)';
}
public function process_api_call() {
$bulk_action_id = absint( $this->get_sanitized_arg( 'bulk_action_id' ) );
if ( empty( $bulk_action_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Invalid Bulk Action ID', 'wp-marketing-automations-pro' ) );
}
$action_data = BWFAN_Model_Bulk_Action::bwfan_get_bulk_action( $bulk_action_id );
if ( ! isset( $action_data['log_file'] ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Log file url is missing', 'wp-marketing-automations-pro' ) );
}
$filename = BWFCRM_BULK_ACTION_LOG_DIR . '/' . $action_data['log_file'];
if ( ! file_exists( $filename ) ) {
$filename = BWFCRM_BULK_ACTION_LOG_DIR_BACKUP . '/' . $action_data['log_file'];
}
if ( ! file_exists( $filename ) ) {
wp_die();
}
// Define header information
header( 'Content-Description: File Transfer' );
header( 'Content-Type: application/octet-stream' );
header( 'Cache-Control: no-cache, must-revalidate' );
header( 'Expires: 0' );
header( 'Content-Disposition: attachment; filename="' . basename( $filename ) . '"' );
header( 'Content-Length: ' . filesize( $filename ) );
header( 'Pragma: public' );
// Clear system output buffer
flush();
// Read the size of the file
readfile( $filename );
exit;
}
/**
* Rest api permission callback
*
* @return bool
*/
public function rest_permission_callback( WP_REST_Request $request ) {
$query_params = $request->get_query_params();
if ( isset( $query_params['bwf-nonce'] ) && $query_params['bwf-nonce'] === get_option( 'bwfan_unique_secret', '' ) ) {
return true;
}
return false;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Download_Log_File' );

View File

@@ -0,0 +1,61 @@
<?php
/**
* Get Bulk Action Status API
*/
class BWFCRM_Api_Get_Bulk_Action_Status extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/bulk-action/status/(?P<bulk_action_id>[\\d]+)';
$this->request_args = array(
'bulk_action_id' => array(
'description' => __( 'Bulk Action ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
/**
* Process API Call
*
* @return WP_Error|WP_HTTP_Response|WP_REST_Response
*/
public function process_api_call() {
$id = $this->get_sanitized_arg( 'bulk_action_id' );
if ( empty( $id ) ) {
return $this->error_response( __( 'Invalid / Empty bulk action ID provided', 'wp-marketing-automations-pro' ), null, 400 );
}
/** Check for bulk action entry */
$data = BWFAN_Model_Bulk_Action::bwfan_get_bulk_action( $id );
if ( empty( $data ) ) {
return $this->error_response( __( 'Bulk Action not found with provided ID', 'wp-marketing-automations-pro' ), null, 400 );
}
/** Get bulk action status */
$action_status = BWFCRM_Core()->bulk_action->get_bulk_action_status( $id );
if ( empty( $action_status ) ) {
return $this->error_response( __( 'Bulk Action data to found with provided ID.', 'wp-marketing-automations-pro' ), null, 400 );
}
$this->response_code = 200;
return $this->success_response( $action_status );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Get_Bulk_Action_Status' );

View File

@@ -0,0 +1,87 @@
<?php
/**
* Get Bulk Action API
*/
class BWFCRM_Api_Get_Bulk_Action extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/bulk-action/(?P<bulk_action_id>[\\d]+)';
$this->request_args = array(
'bulk_action_id' => array(
'description' => __( 'Bulk Action ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function process_api_call() {
$bulk_action_id = $this->get_sanitized_arg( 'bulk_action_id' );
if ( empty( $bulk_action_id ) ) {
return $this->error_response( __( 'Invalid / Empty bulk action ID provided', 'wp-marketing-automations-pro' ), null, 400 );
}
$data = BWFAN_Model_Bulk_Action::bwfan_get_bulk_action( $bulk_action_id );
if ( empty( $data ) ) {
return $this->error_response( __( 'Bulk Action not found with provided ID', 'wp-marketing-automations-pro' ), null, 400 );
}
/** Fetch updated list */
if ( isset( $data['actions']['add_to_lists'] ) ) {
$data['actions']['add_to_lists'] = BWFAN_Common::get_updated_tags_and_list( $data['actions']['add_to_lists'] );
}
/** Fetch updated Tags */
if ( isset( $data['actions']['add_tags'] ) ) {
$data['actions']['add_tags'] = BWFAN_Common::get_updated_tags_and_list( $data['actions']['add_tags'] );
}
$response = [
'data' => $data,
'actions' => $this->format_action_array( BWFCRM_Core()->actions->get_all_action_list( 2 ) ),
'action_schema' => BWFCRM_Core()->actions->get_all_actions_schema_data(),
'group_data' => BWFCRM_Core()->actions->get_group_list(),
];
$this->response_code = 200;
return $this->success_response( $response );
}
/**
* Format the action data
*
* @param $actions
*
* @return array|array[]
*/
public function format_action_array( $actions ) {
if ( empty( $actions ) ) {
return [];
}
return array_map( function ( $slug, $nice_name ) {
return [
'value' => $slug,
'label' => $nice_name,
];
}, array_keys( $actions ), $actions );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Get_Bulk_Action' );

View File

@@ -0,0 +1,90 @@
<?php
/**
* Get bulk action API
*/
class BWFCRM_Api_Get_Bulk_Actions extends BWFCRM_API_Base {
public static $ins;
public $total_count = 0;
public $count_data = [];
public $extra_data = [];
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/bulk-actions';
}
/**
* Set default Values
*
* @return string[]
*/
public function default_args_values() {
return array( 's' => '' );
}
/**
* API call handler
*
* @return WP_Error|WP_HTTP_Response|WP_REST_Response
*/
public function process_api_call() {
$search = ! empty( $this->get_sanitized_arg( 'search', 'key' ) ) ? $this->get_sanitized_arg( 'search', 'text_field' ) : '';
$offset = ! empty( $this->get_sanitized_arg( 'offset', 'key' ) ) ? $this->get_sanitized_arg( 'offset', 'text_field' ) : 0;
$limit = ! empty( $this->get_sanitized_arg( 'limit', 'key' ) ) ? $this->get_sanitized_arg( 'limit', 'text_field' ) : 0;
$status = ! empty( $this->get_sanitized_arg( 'status', 'key' ) ) ? $this->get_sanitized_arg( 'status', 'text_field' ) : '';
$ids = empty( $this->args['ids'] ) ? array() : explode( ',', $this->args['ids'] );
/**
* Get bulk action data
*/
$bulk_action_data = BWFAN_Model_Bulk_Action::get_bulk_actions( $search, $status, $limit, $offset, true, $ids );
$bulk_actions = isset( $bulk_action_data['list'] ) ? $bulk_action_data['list'] : [];
$this->total_count = isset( $bulk_action_data['total'] ) ? intval( $bulk_action_data['total'] ) : 0;
$this->extra_data['total'] = BWFAN_PRO_Common::get_bulk_actions_data_count();
$this->extra_data['actions'] = ( array ) BWFCRM_Core()->actions->get_all_action_list( 2 );
$this->count_data = BWFAN_PRO_Common::get_contact_data_counts();
$this->response_code = 200;
return $this->success_response( $bulk_actions );
}
/**
* Returns total count
*
* @return int
*/
public function get_result_total_count() {
return $this->total_count;
}
/**
* Returns extra data
*
* @return array|int
*/
public function get_result_extra_data() {
return $this->extra_data;
}
/**
* Returns bulk action count based on status
*
* @return array|int
*/
public function get_result_count_data() {
return $this->count_data;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Get_Bulk_Actions' );

View File

@@ -0,0 +1,72 @@
<?php
/**
* Update bulk action status API
*/
class BWFCRM_Api_Update_Bulk_Action_Status extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/bulk-action/(?P<bulk_action_id>[\\d]+)/update-status';
$this->request_args = array(
'bulk_action_id' => array(
'description' => __( 'Bulk Action ID to update', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
$this->response_code = 200;
}
public function process_api_call() {
$bulk_action_id = $this->get_sanitized_arg( 'bulk_action_id' );
$status = $this->get_sanitized_arg( 'status', 'text_field', $this->args['status'] );
if ( empty( $bulk_action_id ) ) {
return $this->error_response( __( 'Invalid / Empty bulk action ID provided', 'wp-marketing-automations-pro' ), null, 400 );
}
$data = BWFAN_Model_Bulk_Action::bwfan_get_bulk_action( $bulk_action_id, false );
if ( empty( $data ) ) {
return $this->error_response( __( 'Bulk Action not found with provided ID', 'wp-marketing-automations-pro' ), null, 400 );
}
$data['updated_at'] = current_time( 'mysql', 1 );
if ( isset( $data['status'] ) ) {
$data['status'] = intval( $status );
}
$result = BWFAN_Model_Bulk_Action::update_bulk_action_data( $bulk_action_id, $data );
if ( intval( $status ) === 3 && ! empty( $result ) ) {
if ( bwf_has_action_scheduled( 'bwfcrm_bulk_action_process', array( 'bulk_action_id' => absint( $bulk_action_id ) ), 'bwfcrm' ) ) {
bwf_unschedule_actions( 'bwfcrm_bulk_action_process', array( 'bulk_action_id' => absint( $bulk_action_id ) ), 'bwfcrm' );
}
}
if ( intval( $status ) === 1 && ! empty( $result ) ) {
BWFCRM_Core()->bulk_action->schedule_bulk_action( $bulk_action_id );
}
if ( empty( $result ) ) {
$this->response_code = 500;
return $this->error_response( __( 'Unable to update bulk action status', 'wp-marketing-automations-pro' ) );
}
return $this->success_response( [ 'id' => $result ], __( 'Successfully updated bulk action status', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Update_Bulk_Action_Status' );

View File

@@ -0,0 +1,179 @@
<?php
/**
* Update bulk action API
*/
class BWFCRM_Api_Update_Bulk_Action extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/bulk-action/(?P<bulk_action_id>[\\d]+)';
$this->response_code = 200;
}
public function default_args_values() {
return array(
'bulk_action_id' => '',
'count' => 0,
);
}
public function process_api_call() {
$bulk_action_id = $this->get_sanitized_arg( 'bulk_action_id', 'key' );
$title = $this->get_sanitized_arg( 'title', 'text_field', $this->args['title'] );
$created_at = isset( $this->args['created_at'] ) ? $this->args['created_at'] : '';
if ( empty( $created_at ) ) {
/** Title update call */
BWFAN_Model_Bulk_Action::update_bulk_action_data( $bulk_action_id, [ 'title' => $title ] );
$data = BWFAN_Model_Bulk_Action::bwfan_get_bulk_action( $bulk_action_id );
return $this->success_response( $data, __( 'Bulk action updated', 'wp-marketing-automations-pro' ) );
}
$count = $this->get_sanitized_arg( 'count', 'text_field', $this->args['count'] );
$actions = isset( $this->args['actions'] ) && ! empty( $this->args['actions'] ) ? $this->args['actions'] : [];
$contact_filters = isset( $this->args['contactFilters'] ) && ! empty( $this->args['contactFilters'] ) ? $this->args['contactFilters'] : [];
$exclude_ids = isset( $this->args['exclude_ids'] ) && ! empty( $this->args['exclude_ids'] ) ? $this->args['exclude_ids'] : [];
$include_ids = isset( $this->args['include_ids'] ) && ! empty( $this->args['include_ids'] ) ? $this->args['include_ids'] : [];
$start_bulk_action = isset( $this->args['start_bulk_action'] ) && boolval( $this->args['start_bulk_action'] );
$stop_bulk_action = isset( $this->args['stop_bulk_action'] ) && boolval( $this->args['stop_bulk_action'] );
$file_name = isset( $this->args['log_file'] ) && boolval( $this->args['log_file'] );
$enable_automation_run = isset( $this->args['enable_automation_run'] ) && boolval( $this->args['enable_automation_run'] );
$meta = [];
if ( empty( $title ) ) {
$this->response_code = 400;
$response = __( 'Oops Title not entered, enter title to save bulk action', 'wp-marketing-automations-pro' );
return $this->error_response( $response );
}
$already_exists = BWFAN_Model_Bulk_Action::check_bulk_action_exists_with( 'ID', $bulk_action_id );
if ( ! $already_exists ) {
$this->response_code = 400;
$response = __( "Bulk Action doesn't exists with id : ", 'wp-marketing-automations-pro' ) . $bulk_action_id;
return $this->error_response( $response );
}
$update_time = current_time( 'mysql', 1 );
$meta['contactFilters'] = $contact_filters;
$meta['exclude_ids'] = $exclude_ids;
$meta['include_ids'] = $include_ids;
$meta['enable_automation_run'] = $enable_automation_run;
$actions = $this->add_new_list_and_tags( $actions );
$link_data = [
'title' => $title,
'count' => intval( $count ) > 0 ? $count : 0,
'actions' => json_encode( $actions ),
'updated_at' => $update_time,
];
if ( $start_bulk_action ) {
$link_data['status'] = 1;
/** Check if file already exists */
if ( empty( $file_name ) ) {
/** Check for directory exists */
if ( ! file_exists( BWFCRM_BULK_ACTION_LOG_DIR . '/' ) ) {
wp_mkdir_p( BWFCRM_BULK_ACTION_LOG_DIR );
}
/** Create log file */
$file_name = 'FKA-Bulk-Action-' . time() . '-' . wp_generate_password( 5, false ) . '-log.csv';
/** Open log file */
$file = fopen( BWFCRM_BULK_ACTION_LOG_DIR . '/' . $file_name, "wb" );
if ( ! empty( $file ) ) {
/** Updating headers in log file */
fputcsv( $file, array_merge( [ 'Contact ID' ], array_keys( $actions ) ) );
/** Close log file */
fclose( $file );
}
}
$meta['log_file'] = $file_name;
}
if ( $stop_bulk_action ) {
$link_data['status'] = 3;
if ( bwf_has_action_scheduled( 'bwfcrm_bulk_action_process', array( 'bulk_action_id' => absint( $bulk_action_id ) ), 'bwfcrm' ) ) {
bwf_unschedule_actions( 'bwfcrm_bulk_action_process', array( 'bulk_action_id' => absint( $bulk_action_id ) ), 'bwfcrm' );
}
}
$link_data['meta'] = json_encode( $meta );
/** Updating db entry for bulk action */
$result = BWFAN_Model_Bulk_Action::update_bulk_action_data( $bulk_action_id, $link_data );
/** Error handle */
if ( empty( $result ) ) {
$this->response_code = 500;
return $this->error_response( __( 'Unable to update bulk action', 'wp-marketing-automations-pro' ) );
}
/** Schedule action */
if ( $start_bulk_action ) {
BWFCRM_Core()->bulk_action->schedule_bulk_action( $bulk_action_id );
}
/** Get bulk action data to return */
$data = BWFAN_Model_Bulk_Action::bwfan_get_bulk_action( $bulk_action_id );
if ( empty( $data ) ) {
return $this->error_response( __( 'Bulk Action not found with provided ID', 'wp-marketing-automations-pro' ), null, 400 );
}
/** Set success response */
return $this->success_response( $data, __( 'Bulk action updated', 'wp-marketing-automations-pro' ) );
}
/**
* Create tags and list
*
* @param $actions
*
* @return array
*/
public function add_new_list_and_tags( $actions ) {
foreach ( $actions as $action_key => $action_val ) {
$terms = [];
$term_type = 0;
if ( $action_key === 'add_tags' ) {
$term_type = BWFCRM_Term_Type::$TAG;
$terms = $action_val;
} else if ( $action_key === 'add_to_lists' ) {
$term_type = BWFCRM_Term_Type::$LIST;
$terms = $action_val;
}
if ( is_array( $terms ) && ! empty( $terms ) && method_exists( 'BWFAN_PRO_Common', 'get_or_create_terms' ) ) {
$terms = BWFAN_PRO_Common::get_or_create_terms( $terms, $term_type );
$actions[ $action_key ] = $terms;
}
}
return $actions;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Update_Bulk_Action' );

View File

@@ -0,0 +1,107 @@
<?php
/**
* Broadcast Lookup API file
*
* @package BWFCRM_API_Base
*/
/**
* Broadcast Lookup API class
*/
class BWFCRM_API_Broadcast_Lookup extends BWFCRM_API_Base {
/**
* BWFCRM_API_Broadcast_Lookup obj
*
* @var BWFCRM_API_Broadcast_Lookup
*/
public static $ins;
/***
* Total count
*
* @var int
*/
public $total_count = 0;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/broadcasts-lookup';
$this->pagination->offset = 0;
$this->pagination->limit = 25;
$this->request_args = array(
'search' => array(
'description' => __( 'Search from Broadcast name', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'offset' => array(
'description' => __( 'Broadcast Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'ids' => array(
'description' => __( 'Broadcast IDs', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'type' => array(
'description' => __( 'Broadcast type filter', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
);
}
/**
* API callback
*/
public function process_api_call() {
$search = ! empty( $this->get_sanitized_arg( 'search', 'key' ) ) ? $this->get_sanitized_arg( 'search', 'text_field' ) : '';
$offset = ! empty( $this->get_sanitized_arg( 'offset', 'key' ) ) ? $this->get_sanitized_arg( 'offset', 'text_field' ) : $this->pagination->offset;
$limit = ! empty( $this->get_sanitized_arg( 'limit', 'key' ) ) ? $this->get_sanitized_arg( 'limit', 'text_field' ) : $this->pagination->limit;
$ids = ! empty( $this->get_sanitized_arg( 'ids', 'text_field' ) ) ? $this->get_sanitized_arg( 'ids', 'text_field' ) : '';
$type = ! empty( $this->get_sanitized_arg( 'type', 'key' ) ) ? $this->get_sanitized_arg( 'type', 'text_field' ) : '';
$ids = ! empty( $ids ) ? explode( ',', $ids ) : array();
$broadcasts = BWFCRM_Core()->campaigns->get_broadcast_lookup(
array(
'search' => $search,
'offset' => $offset,
'limit' => $limit,
'ids' => $ids,
'type' => $type,
)
);
$this->total_count = count( $broadcasts );
return $this->success_response( $broadcasts );
}
/**
* Get total count
*/
public function get_result_total_count() {
return $this->total_count;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Broadcast_Lookup' );

View File

@@ -0,0 +1,70 @@
<?php
/**
* Campaign Email Preview API class
*/
class BWFCRM_API_Campaign_Email_Preview extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/broadcast/email-preview';
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'content' => 0
);
}
/**
* API callback
*/
public function process_api_call() {
$content = '';
$type = ! empty( $this->args['type'] ) ? $this->args['type'] : 'rich';
if ( ! empty( $this->args['content'] ) ) {
$content = $this->args['content'];
}
if ( method_exists( 'BWFAN_Common', 'bwfan_before_send_mail' ) ) {
BWFAN_Common::bwfan_before_send_mail( $type );
}
/** Email Subject */
BWFAN_Merge_Tag_Loader::set_data( [ 'is_preview' => true ] );
$body = method_exists( 'BWFAN_Common', 'correct_shortcode_string' ) ? BWFAN_Common::correct_shortcode_string( $content, $type ) : $content;
$body = BWFAN_Common::decode_merge_tags( $body );
$body = BWFAN_Common::bwfan_correct_protocol_url( $body );
$body = BWFCRM_Core()->conversation->apply_template_by_type( $body, $type, '' );
$this->response_code = 200;
return $this->success_response( [ 'body' => $body ] );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Campaign_Email_Preview' );

View File

@@ -0,0 +1,95 @@
<?php
/**
* Campaign Clone API file
*
* @package BWFCRM_API_Base
*/
/**
* Campaign Clone API class
*/
class BWFCRM_API_Clone_Campaign extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/broadcast/(?P<campaign_id>[\\d]+)/clone';
$this->request_args = array(
'campaign_id' => array(
'description' => __( 'Broadcast ID whose data to be cloned.', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'created_by' => array(
'description' => __( 'User ID who is cloning contact.', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'campaign_id' => 0,
'created_by' => '',
);
}
/**
* API callback
*/
public function process_api_call() {
$campaign_id = $this->get_sanitized_arg( 'campaign_id', 'key' );
$send_to_unopen = $this->get_sanitized_arg( 'send_to_unopen', 'bool' );
$created_by = $this->get_sanitized_arg( 'created_by', 'key' );
$created_by = ! empty( $created_by ) ? $created_by : '';
$user_exists = (bool) get_users(
array(
'include' => $created_by,
'fields' => 'ID',
)
);
if ( ! $user_exists ) {
$this->response_code = 404;
return $this->error_response( __( 'User does not exists with provided ID', 'wp-marketing-automations-pro' ) );
}
if ( intval( $campaign_id ) > 0 ) {
$campaign_data = BWFAN_Model_Broadcast::clone_campaign( $campaign_id, $created_by, $send_to_unopen );
$this->response_code = $campaign_data['status'];
if ( $campaign_data['status'] === 200 ) {
return $this->success_response( $campaign_data['data'], $campaign_data['message'] );
} else {
return $this->error_response( $campaign_data['message'] );
}
} else {
$this->response_code = 404;
return $this->error_response( __( 'Please provide a valid broadcast id.', 'wp-marketing-automations-pro' ) );
}
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Clone_Campaign' );

View File

@@ -0,0 +1,100 @@
<?php
/**
* Camapign Create API file
*
* @package BWFCRM_API_Base
*/
/**
* Campaign Create API class
*/
class BWFCRM_API_Create_Campaign extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/broadcast';
}
/**
* Default campaign args.
*/
public function default_args_values() {
return array(
'title' => '',
'description' => '',
'type' => '',
'created_by' => '',
);
}
/**
* API callback
*/
public function process_api_call() {
$title = ! empty( $this->get_sanitized_arg( 'title', 'text_field' ) ) ? $this->get_sanitized_arg( 'title', 'text_field' ) : '';
$type = ! empty( $this->get_sanitized_arg( 'type', 'key' ) ) ? $this->get_sanitized_arg( 'type', 'key' ) : 0;
// $created_by = ! empty( $this->get_sanitized_arg( 'created_by', 'key' ) ) ? $this->get_sanitized_arg( 'created_by', 'key' ) : '';
/** Create send to unopen broadcast */
$createUnopen = $this->get_sanitized_arg( 'createUnopen', 'key' );
if ( 1 !== absint( $type ) ) {
$createUnopen = false;
}
if ( empty( $title ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Title is a mandatory field', 'wp-marketing-automations-pro' ) );
}
if ( intval( $type ) <= 0 || ! in_array( intval( $type ), array( 1, 2, 3 ), true ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Please select a type', 'wp-marketing-automations-pro' ) );
}
$created_by = get_current_user_id();
if ( 0 === $created_by ) {
$this->response_code = 404;
return $this->error_response( __( 'User is not logged in.', 'wp-marketing-automations-pro' ) );
}
$description = ! empty( $this->get_sanitized_arg( 'description', 'text_field' ) ) ? $this->get_sanitized_arg( 'description', 'text_field' ) : '';
$campaign_data = BWFAN_Model_Broadcast::create_campaign( $title, $description, $type, $created_by, $createUnopen );
$this->response_code = $campaign_data['status'];
if ( $campaign_data['status'] === 200 ) {
return $this->success_response( $campaign_data['data'], __( 'Broadcast created', 'wp-marketing-automations-pro' ) );
} else {
return $this->error_response( __( 'Error occurred in creating a broadcast', 'wp-marketing-automations-pro' ), null, 500 );
}
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Create_Campaign' );

View File

@@ -0,0 +1,77 @@
<?php
/**
* Campaign Delete API file
*
* @package BWFCRM_API_Base
*/
/**
* Campaign Delete API class
*/
class BWFCRM_API_Delete_Campaign extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/broadcast/(?P<campaign_id>[\\d]+)';
$this->request_args = array(
'campaign_id' => array(
'description' => __( 'Broadcast ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'campaign_id' => 0,
);
}
/**
* API callback
*/
public function process_api_call() {
$campaign_id = $this->get_sanitized_arg( 'campaign_id', 'key' );
if ( intval( $campaign_id ) > 0 ) {
$campaign_data = BWFAN_Model_Broadcast::delete_campaign( $campaign_id );
$this->response_code = $campaign_data['status'];
if ( $campaign_data['status'] === 200 ) {
return $this->success_response( $campaign_data['data'], $campaign_data['message'] );
} else {
return $this->error_response( $campaign_data['message'] );
}
} else {
$this->response_code = 404;
return $this->error_response( __( 'Unable to delete a broadcast, invalid ID', 'wp-marketing-automations-pro' ) );
}
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Delete_Campaign' );

View File

@@ -0,0 +1,76 @@
<?php
/**
* Campaign Get API file
*
* @package BWFCRM_API_Base
*/
/**
* Campaign Get API class
*/
class BWFCRM_API_Get_Broadcast_Overview_Stats extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/broadcast/(?P<broadcast_id>[\\d]+)/overview-stats';
$this->request_args = array(
'broadcast_id' => array(
'description' => __( 'Broadcast ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'broadcast_id' => 0,
);
}
/**
* API callback
*/
public function process_api_call() {
$broadcast_id = $this->get_sanitized_arg( 'broadcast_id', 'key' );
if ( empty( $broadcast_id ) ) {
return $this->error_response( __( 'Broadcast not found', 'wp-marketing-automations-pro' ), null, 404 );
}
$broadcast = BWFAN_Model_Broadcast::get_broadcast_basic_stats( $broadcast_id );
// $last_modified = isset( $broadcast['last_modified'] ) && ! empty( $broadcast['last_modified'] ) ? strtotime( $broadcast['last_modified'] ) : false;
/** Ping worker if last modified is greater than 5 seconds */
// if ( ! empty( $last_modified ) && ( time() - $last_modified ) > 5 ) {
// BWFCRM_Common::reschedule_broadcast_action();
// }
return $this->success_response( $broadcast );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Broadcast_Overview_Stats' );

View File

@@ -0,0 +1,139 @@
<?php
/**
* Campaign Get API file
*
* @package BWFCRM_API_Base
*/
/**
* Campaign Get API class
*/
class BWFCRM_API_Get_Broadcasts_Stats extends BWFCRM_API_Base {
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/broadcasts-stats';
}
/**
* API callback
*/
public function process_api_call() {
$broadcasts_ids = isset( $this->args['broadcast_ids'] ) ? $this->args['broadcast_ids'] : [];
$child_broadcast_ids = BWFAN_Model_Broadcast::get_broadcast_child( $broadcasts_ids, true );
/** Fetch second level child */
$child2_broadcast_ids = ! empty( $child_broadcast_ids ) ? BWFAN_Model_Broadcast::get_broadcast_child( $child_broadcast_ids, true ) : [];
$broadcasts_ids = array_merge( $broadcasts_ids, $child_broadcast_ids, $child2_broadcast_ids );
$final_data = [];
$cached_key = 'bwfan_broadcast_stats';
$force = filter_input( INPUT_GET, 'force' );
$exp = BWFAN_Common::get_admin_analytics_cache_lifespan();
try {
if ( 'false' === $force ) {
$stats = get_transient( $cached_key );
if ( ! empty( $stats ) ) {
$broadcasts_ids = array_filter( $broadcasts_ids, function ( $id ) use ( $stats ) {
return ! array_key_exists( $id, $stats );
} );
if ( count( $broadcasts_ids ) > 0 ) {
sort( $broadcasts_ids );
}
$final_data = $stats;
}
}
if ( is_array( $broadcasts_ids ) && count( $broadcasts_ids ) > 0 ) {
$ids = $broadcasts_ids;
$batch_size = 10;
$data = [];
$conversions = [];
while ( count( $ids ) > 0 ) {
/** Get ids in batches */
$selected_ids = ( count( $ids ) > $batch_size ) ? array_slice( $ids, 0, $batch_size ) : $ids;
/** update broadcast ids for next run */
$ids = array_diff( $ids, $selected_ids );
sort( $ids );
$batch_data = BWFAN_Model_Broadcast::include_open_click_rate( $selected_ids, [], true );
$data = array_merge( $data, $batch_data );
/** Get formatted ids for conversions */
$formatted_ids = [];
foreach ( $selected_ids as $id ) {
$formatted_ids[] = [ 'id' => $id ];
}
/** Get conversions */
$batch_conversions = BWFAN_Model_Broadcast::include_conversion_into_campaigns( $formatted_ids, true );
$conversions = array_merge( $conversions, $batch_conversions );
}
$broadcast_ids = empty( $data ) ? [] : array_column( $data, 'oid' );
$conversion_ids = empty( $conversions ) ? [] : array_column( $conversions, 'oid' );
foreach ( $broadcasts_ids as $id ) {
$index = array_search( $id, $broadcast_ids );
$open_rate = 0;
$sent = 0;
$click_rate = 0;
if ( false !== $index ) {
$open_rate = isset( $data[ $index ]['open_rate'] ) ? $data[ $index ]['open_rate'] : 0;
$sent = isset( $data[ $index ]['sent'] ) ? $data[ $index ]['sent'] : 0;
$click_rate = isset( $data[ $index ]['click_rate'] ) ? $data[ $index ]['click_rate'] : 0;
}
$index = array_search( $id, $conversion_ids );
$conversion_count = 0;
$revenue = 0;
if ( false !== $index ) {
$conversion_count = isset( $conversions[ $index ]['conversions'] ) ? $conversions[ $index ]['conversions'] : 0;
$revenue = isset( $conversions[ $index ]['revenue'] ) ? $conversions[ $index ]['revenue'] : 0;
}
$final_data[ $id ] = [
'open_rate' => $open_rate,
'sent' => $sent,
'click_rate' => $click_rate,
'conversions' => $conversion_count,
'revenue' => $revenue,
];
}
set_transient( $cached_key, $final_data, $exp );
BWFAN_Common::validate_scheduled_recurring_actions();
}
$this->response_code = 200;
return $this->success_response( $final_data, '' );
} catch ( Error $e ) {
$this->response_code = 404;
return $this->error_response( $e['message'] );
}
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Broadcasts_Stats' );

View File

@@ -0,0 +1,57 @@
<?php
class BWFCRM_API_Get_Campaign_Recipients extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/broadcasts/(?P<campaign_id>[\\d]+)/conversions/';
$this->pagination->offset = 0;
$this->pagination->limit = 10;
$this->request_args = array(
'campaign_id' => array(
'description' => __( 'Broadcast ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'offset' => array(
'description' => __( 'Contacts list Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function process_api_call() {
$campaign_id = $this->get_sanitized_arg( 'campaign_id', 'text_field' );
$recipients = BWFCRM_Core()->campaigns->get_conversions( $campaign_id, $this->pagination->offset, $this->pagination->limit );
if ( empty( $recipients['conversions'] ) ) {
$this->response_code = 404;
$response = __( "No orders found", "autonami-automations-pro" );
return $this->success_response([], $response );
}
$this->total_count = $recipients['total'];
return $this->success_response( $recipients['conversions'], __( 'Got All Orders', 'wp-marketing-automations-pro' ) );
}
public function get_result_total_count() {
return $this->total_count;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Campaign_Recipients' );

View File

@@ -0,0 +1,71 @@
<?php
/**
* Campaign Get API file
*
* @package BWFCRM_API_Base
*/
/**
* Campaign Stats Get API class
*/
class BWFCRM_API_Get_Campaign_Stats extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/broadcast/(?P<campaign_id>[\\d]+)/stats';
$this->request_args = array(
'campaign_id' => array(
'description' => __( 'Broadcast ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'campaign_id' => 0,
);
}
/**
* API callback
*/
public function process_api_call() {
$campaign_id = $this->get_sanitized_arg( 'campaign_id', 'key' );
if ( absint( $campaign_id ) > 0 ) {
$campaign_data = BWFCRM_Core()->campaigns->get_campaign_open_click_analytics($campaign_id);
return $this->success_response( $campaign_data );
} else {
return $this->error_response( __( 'Invalid broadcast ID given', 'wp-marketing-automations-pro' ), null, 400 );
}
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Campaign_Stats' );

View File

@@ -0,0 +1,92 @@
<?php
/**
* Campaign Get API file
*
* @package BWFCRM_API_Base
*/
/**
* Campaign Get API class
*/
class BWFCRM_API_Get_Campaign extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/broadcast/(?P<campaign_id>[\\d]+)';
$this->request_args = array(
'campaign_id' => array(
'description' => __( 'Broadcast ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'campaign_id' => 0,
);
}
/**
* API callback
*/
public function process_api_call() {
$campaign_id = $this->get_sanitized_arg( 'campaign_id', 'key' );
$ab_mode = $this->get_sanitized_arg( 'ab_mode', 'bool' );
$ping_worker = $this->get_sanitized_arg( 'ping_worker', 'bool' );
if ( true === $ping_worker ) {
BWFCRM_Common::ping_woofunnels_worker();
}
if ( 0 === intval( $campaign_id ) ) {
$this->response_code = 404;
$this->error_response( __( 'Invalid broadcast ID given', 'wp-marketing-automations-pro' ) );
}
$campaign_data = BWFAN_Model_Broadcast::get_campaign( $campaign_id, ! $ab_mode, $ab_mode );
/** Check for template stats */
if ( ! empty( $campaign_data['data']['data']['smart_send_stat'] ) ) {
$campaign_data['data']['data']['smart_send_stat'] = BWFAN_Model_Broadcast::get_formatted_smart_stat( $campaign_data['data']['data']['smart_send_stat'], true );
}
$this->response_code = $campaign_data['status'];
if ( ! $ab_mode ) {
$campaign_data['data']['count'] = BWFCRM_Campaigns::get_broadcast_updated_contact_count( $campaign_data['data'] );
}
if ( 200 === intval( $campaign_data['status'] ) ) {
return $this->success_response( $campaign_data['data'], $campaign_data['message'] );
}
return $this->error_response( $campaign_data['message'] );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Campaign' );

View File

@@ -0,0 +1,142 @@
<?php
/**
* Campaign Get API file
*
* @package BWFCRM_API_Base
*/
/**
* Campaign Get API class
*/
class BWFCRM_API_Get_Campaigns extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/***
* Total count
*
* @var int
*/
public $total_count = 0;
/***
* Count Data
*
* @var array
*/
public $count_data = [];
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/broadcasts';
$this->pagination->offset = 0;
$this->pagination->limit = 25;
$this->request_args = array(
'search' => array(
'description' => __( 'Search from campaign name', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'offset' => array(
'description' => __( 'Broadcast list Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'order' => array(
'description' => __( 'Order of the campaign list', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'order_by' => array(
'description' => __( 'Order campaign list according to fields', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'fields' => array(
'description' => __( 'Comma separated fields to get', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'type' => array(
'description' => __( 'Broadcast type filter', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'status' => array(
'description' => __( 'Broadcast status filter', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
);
}
/**
* API callback
*/
public function process_api_call() {
$search = ! empty( $this->get_sanitized_arg( 'search', 'key' ) ) ? $this->get_sanitized_arg( 'search', 'text_field' ) : '';
$offset = ! empty( $this->get_sanitized_arg( 'offset', 'key' ) ) ? $this->get_sanitized_arg( 'offset', 'text_field' ) : $this->pagination->offset;
$limit = ! empty( $this->get_sanitized_arg( 'limit', 'key' ) ) ? $this->get_sanitized_arg( 'limit', 'text_field' ) : $this->pagination->limit;
$order = ! empty( $this->get_sanitized_arg( 'order', 'key' ) ) ? $this->get_sanitized_arg( 'order', 'text_field' ) : 'DESC';
$type = ! empty( $this->get_sanitized_arg( 'type', 'key' ) ) ? $this->get_sanitized_arg( 'type', 'text_field' ) : '';
$status = ! empty( $this->get_sanitized_arg( 'status', 'key' ) ) ? $this->get_sanitized_arg( 'status', 'text_field' ) : '';
try {
$campaign_data = BWFAN_Model_Broadcast::get_campaigns( $search, $limit, $offset, $order, $type, $status );
$this->count_data = BWFAN_PRO_Common::get_broadcast_data_count( $type );
$this->response_code = 200;
$this->total_count = intval( $campaign_data['total'] );
/** Check if worker call is late */
$last_run = bwf_options_get( 'fk_core_worker_let' );
$threshold_time = method_exists( 'BWFAN_Common', 'get_worker_delay_timestamp' ) ? BWFAN_Common::get_worker_delay_timestamp() : 300;
if ( '' !== $last_run && ( ( time() - $last_run ) > $threshold_time ) ) {
/** Worker is running late */
$campaign_data['data']['worker_delayed'] = time() - $last_run;
}
/** Check basic worker last run time and status code check */
$resp = method_exists( 'BWFAN_Common', 'validate_core_worker' ) ? BWFAN_Common::validate_core_worker() : [];
if ( isset( $resp['response_code'] ) ) {
$campaign_data['data']['response_code'] = $resp['response_code'];
}
return $this->success_response( $campaign_data['data'], $campaign_data['message'] );
} catch ( Error $e ) {
$this->response_code = 404;
return $this->error_response( $e['message'] );
}
}
/**
* Get total count
*/
public function get_result_total_count() {
return $this->total_count;
}
public function get_result_count_data() {
return $this->count_data;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Campaigns' );

View File

@@ -0,0 +1,78 @@
<?php
/**
* Broadcast Editor Content API file
*
* @package BWFCRM_API_Base
*/
/**
* Get Broadcast Editor Content API class
*/
class BWFCRM_API_Get_Editor_Content extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/broadcast/(?P<broadcast_id>[\\d]+)/content/(?P<content_id>[\\d]+)';
$this->request_args = array(
'broadcast_id' => array(
'description' => __( 'Broadcast ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'content_id' => array(
'description' => __( 'A/B Content index\'s data to retreive', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'broadcast_id' => 0,
);
}
/**
* API callback
*/
public function process_api_call() {
$broadcast_id = $this->get_sanitized_arg( 'broadcast_id', 'key' );
$content_id = $this->get_sanitized_arg( 'content_id', 'key' );
if ( empty( $broadcast_id ) || ( empty( $content_id ) && 0 !== absint( $content_id ) ) ) {
return $this->error_response( __( 'Invalid Broadcast ID / Content Index given', 'wp-marketing-automations-pro' ) );
}
$content = BWFCRM_Core()->campaigns->get_editor_content( $broadcast_id, $content_id );
if ( ! is_array( $content ) || empty( $content ) ) {
$content = [];
}
return $this->success_response( $content );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Editor_Content' );

View File

@@ -0,0 +1,152 @@
<?php
class BWFCRM_Api_Get_Merge_Tags extends BWFCRM_API_Base {
public static $ins;
private $_form_merge_tags = [ 'bwfan_contact_confirmation_link' ];
public $merge_tags = [];
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = 'broadcast/merge-tags';
$this->response_code = 200;
$this->merge_tags = array();
}
public function process_api_call() {
$context = $this->get_sanitized_arg( 'context', 'text_field' );
$fetch_for_forms = 'forms' === $context;
$custom_context = [];
if ( 'forms' !== $context ) {
$custom_context = explode( ',', $context );
}
$custom_context[] = 'bwfan_default';
try {
if ( BWFAN_PRO_Common::is_lite_3_0() ) {
$merge_tags = BWFAN_Core()->merge_tags->get_localize_tags_with_group( $fetch_for_forms, $custom_context );
$merge_tags = $this->get_all_data_for_merge_tags( $merge_tags, $fetch_for_forms );
} else {
$merge_tags = BWFCRM_Core()->merge_tags->get_registered_grouped_tags( true, $fetch_for_forms );
}
} catch ( Error $e ) {
$this->response_code = 404;
$response = $e->getMessage();
return $this->error_response( $response );
}
if ( empty( $merge_tags ) ) {
$this->response_code = 404;
$response = __( "No merge tags found", "wp-marketing-automations-pro" );
return $this->error_response( $response );
}
$this->merge_tags = $merge_tags;
return $this->success_response( $merge_tags, __( 'Got All Merge Tags', 'wp-marketing-automations-pro' ) );
}
public function get_all_data_for_merge_tags( $merge_tags, $fetch_for_forms ) {
$merge_tags_data = [];
$broadcast_merge_tag_groups = array_keys( $merge_tags );
$form_merge_tags = $this->_form_merge_tags;
$custom_tag_data = [];
foreach ( $broadcast_merge_tag_groups as $merge_tag_group ) {
if ( ! isset( $merge_tags[ $merge_tag_group ] ) ) {
continue;
}
/** creating custom contact field merge tag if present */
if ( isset( $merge_tags[ $merge_tag_group ]['bwfan_contact_field'] ) ) {
$field_merge_tags = $merge_tags[ $merge_tag_group ]['bwfan_contact_field'];
$custom_tag_data = $this->get_contact_fields_tags( $field_merge_tags->get_priority() );
unset( $merge_tags[ $merge_tag_group ]['bwfan_contact_field'] ); // unsetting so that it will not loop over again
}
$tag_data = array_map( function ( $tags ) use ( $fetch_for_forms, $form_merge_tags ) {
if ( false === $fetch_for_forms && in_array( $tags->get_name(), $form_merge_tags ) ) {
return false;
}
$data = [
'tag_name' => $tags->get_name(),
'tag_description' => $tags->get_description(),
'priority' => $tags->get_priority(),
];
if ( method_exists( $tags, 'get_setting_schema' ) ) {
$data['schema'] = $tags->get_setting_schema();
}
if ( method_exists( $tags, 'get_default_values' ) ) {
$data['default_val'] = $tags->get_default_values();
}
return $data;
}, $merge_tags[ $merge_tag_group ] );
if ( ! empty( $custom_tag_data ) ) {
$tag_data = array_merge( $tag_data, $custom_tag_data );
}
$tag_data = array_filter( $tag_data );
uasort( $tag_data, function ( $a, $b ) {
return $a['priority'] <= $b['priority'] ? - 1 : 1;
} );
if ( ! empty( $merge_tags[ $merge_tag_group ] ) ) {
$merge_tags_data[ $merge_tag_group ] = array_merge( $merge_tags[ $merge_tag_group ], $tag_data );
} else {
$merge_tags_data[ $merge_tag_group ] = $tag_data;
}
}
foreach ( $merge_tags_data as $group => $merge_tag_det ) {
foreach ( $merge_tag_det as $key => $v ) {
if ( false === $fetch_for_forms && in_array( $key, $this->_form_merge_tags ) ) {
unset( $merge_tags_data[ $group ][ $key ] );
}
}
}
return $merge_tags_data;
}
/**
* Fetching all the contact custom fields for creating merge tag
*
* @param $priority
*
* @return array
*/
public function get_contact_fields_tags( $priority ) {
$fields = BWFCRM_Fields::get_custom_fields( 1, 1, null );
$return = [];
foreach ( $fields as $field ) {
if ( ! is_array( $field ) || ! isset( $field['slug'] ) ) {
continue;
}
$field_group = 'contact_field key="' . $field['slug'] . '"';
$return[ $field_group ]['tag_name'] = $field_group;
$return[ $field_group ]['tag_description'] = $field['name'];
$return[ $field_group ]['priority'] = $priority;
}
return $return;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_Api_Get_Merge_Tags' );

View File

@@ -0,0 +1,52 @@
<?php
class BWFCRM_API_Get_Recipient_Timeline extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $recipients_timeline = [];
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/broadcasts/(?P<campaign_id>[\\d]+)/recipients/(?P<conversation_id>[\\d]+)/timeline';
$this->pagination->offset = 0;
$this->pagination->limit = 10;
$this->request_args = array(
'campaign_id' => array(
'description' => __( 'Broadcast ID to retrieve campaign', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'conversation_id' => array(
'description' => __( 'Conversation ID to retrieve recipient timeline', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function process_api_call() {
$campaign_id = $this->get_sanitized_arg( 'campaign_id', 'text_field' );
$conversation_id = $this->get_sanitized_arg( 'conversation_id', 'text_field' );
$recipients_timeline = BWFAN_Model_Engagement_Tracking::get_engagement_recipient_timeline( $conversation_id );
if ( empty( $recipients_timeline ) ) {
return $this->success_response( [], __( 'No engagement found', 'wp-marketing-automations-pro' ) );
}
$this->recipients_timeline = $recipients_timeline;
return $this->success_response( $recipients_timeline, __( 'Got All timeline', 'wp-marketing-automations-pro' ) );
}
public function get_result_total_count() {
return count( $this->recipients_timeline );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Recipient_Timeline' );

View File

@@ -0,0 +1,57 @@
<?php
class BWFCRM_API_Get_Recipients extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/broadcasts/(?P<campaign_id>[\\d]+)/recipients/';
$this->pagination->offset = 0;
$this->pagination->limit = 10;
$this->request_args = array(
'campaign_id' => array(
'description' => __( 'Campaign ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'offset' => array(
'description' => __( 'Contacts list Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function process_api_call() {
$campaign_id = $this->get_sanitized_arg( 'campaign_id', 'text_field' );
$recipients = BWFAN_Model_Engagement_Tracking::get_recipents_by_type( $campaign_id, BWFAN_Email_Conversations::$TYPE_CAMPAIGN, $this->pagination->offset, $this->pagination->limit );
if ( empty( $recipients['conversations'] ) ) {
$this->response_code = 404;
$response = __( "No recipients found", "autonami-automations-pro" );
return $this->success_response( [], $response );
}
$this->total_count = $recipients['total'];
return $this->success_response( $recipients['conversations'], __( 'Got All Recipients', 'wp-marketing-automations-pro' ) );
}
public function get_result_total_count() {
return $this->total_count;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Recipients' );

View File

@@ -0,0 +1,93 @@
<?php
/**
* Campaign Test Mail API file
*
* @package BWFCRM_API_Base
*/
/**
* Campaign Test Mail API class
*/
class BWFCRM_API_Pause_Unpause_Broadcast extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/broadcast/(?P<campaign_id>[\\d]+)/pause-unpause';
$this->request_args = array(
'campaign_id' => array(
'description' => __( 'Broadcast ID whose state has to be changes.', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'campaign_id' => 0,
'status' => ''
);
}
/**
* API callback
*/
public function process_api_call() {
$campaign_id = $this->get_sanitized_arg( 'campaign_id', 'key' );
$status = 0;
$campaign_data = false;
if ( ! empty( $this->args['status'] ) ) {
$status = intval( $this->args['status'] );
}
$this->response_code = 404;
if ( intval( $campaign_id ) > 0 ) {
if ( 3 === $status ) {
$campaign_data = BWFAN_Model_Broadcast::update_status_to_ongoing( $campaign_id );
} elseif ( 6 === $status ) {
$campaign_data = BWFAN_Model_Broadcast::update_status_to_pause( $campaign_id );
BWFCRM_Broadcast_Processing::action_schedule_save_last_sent( $campaign_id, false );
} elseif ( 1 === $status ) {
$campaign_data = BWFAN_Model_Broadcast::update_status_to_draft( $campaign_id );
} elseif ( 7 === $status ) {
$campaign_data = BWFAN_Model_Broadcast::update_status_to_cancel( $campaign_id );
}
if ( $campaign_data ) {
$this->response_code = 200;
return $this->success_response( '', __( 'Successfully updated broadcast status', 'wp-marketing-automations-pro' ) );
}
return $this->error_response( __( 'Unable to set broadcast status.', 'wp-marketing-automations-pro' ) );
}
return $this->error_response( __( 'Invalid broadcast ID provided', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Pause_Unpause_Broadcast' );

View File

@@ -0,0 +1,75 @@
<?php
/**
* Campaign Save Content API file
*
* @package BWFCRM_API_Base
*/
/**
* Campaign Save Content API class
*/
class BWFCRM_API_Save_Content extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/***
* Total count
*
* @return BWFCRM_API_Save_Content
* @var int
*
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/broadcast/(?P<broadcast_id>[\\d]+)/save-content';
}
/**
* Default args
*/
public function default_args_values() {
return array(
'broadcast_id' => 0,
'content' => array()
);
}
/**
* API callback
*/
public function process_api_call() {
$broadcast_id = $this->get_sanitized_arg( 'broadcast_id', 'key' );
if ( empty( $broadcast_id ) ) {
return $this->error_response( __( 'Unable to save broadcast, Broadcast ID missing', 'wp-marketing-automations-pro' ), null, 400 );
}
/** Filter data */
$data = isset( $this->args['content'] ) ? $this->args['content'] : [];
$data = BWFAN_Common::is_json( $data ) ? json_decode( $data, true ) : $data;
$result = BWFCRM_Core()->campaigns->save_broadcast_content( $broadcast_id, $data );
if ( is_wp_error( $result ) ) {
return $this->error_response( '', $result, $result->get_error_code() );
}
return $this->success_response( [], 'Broadcast Content Saved!' );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Save_Content' );

View File

@@ -0,0 +1,105 @@
<?php
/**
* Campaign Update API file
*
* @package BWFCRM_API_Base
*/
/**
* Campaign Update API class
*/
class BWFCRM_API_Update_Campaign extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/***
* Total count
*
* @return BWFCRM_API_Update_Campaign
* @var int
*
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/broadcast/(?P<campaign_id>[\\d]+)';
}
/**
* Default args
*/
public function default_args_values() {
return array(
'campaign_id' => 0,
'step' => 0,
'content' => array()
);
}
/**
* API callback
*/
public function process_api_call() {
$campaign_id = $this->get_sanitized_arg( 'campaign_id', 'key' );
$step = $this->get_sanitized_arg( 'step', 'key' );
/** Check fo data */
$data = isset( $this->args['content'] ) ? $this->args['content'] : [];
$data = BWFAN_Common::is_json( $data ) ? json_decode( $data, true ) : $data;
/** For old version */
if ( empty( $data ) && isset( $this->args['data'] ) && ! empty( $this->args['data'] ) ) {
$data = BWFAN_Common::is_json( $this->args['data'] ) ? json_decode( $this->args['data'], true ) : $this->args['data'];
}
if ( empty( $campaign_id ) || ! $step || intval( $step ) < 1 ) {
$this->response_code = 404;
return $this->error_response( __( 'Unable to save broadcast, ID is missing', 'wp-marketing-automations-pro' ) );
}
if ( empty( $data ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Unable to save broadcast, data is missing', 'wp-marketing-automations-pro' ) );
}
$campaign = BWFAN_Model_Broadcast::update_campaign( $campaign_id, $step, $data );
/** validating the content */
if ( isset( $data['content'] ) && is_array( $data['content'] ) ) {
foreach ( $data['content'] as $key => $content ) {
try {
BWFCRM_Core()->conversation->emogrify_email( $content['body'] );
$campaign['data'][ 'validated_email_body_' . $key ] = true;
} catch ( Error $e ) {
$campaign['data'][ 'validated_email_body_' . $key ] = false;
}
}
}
$this->response_code = $campaign['status'];
if ( 200 === $campaign['status'] ) {
return $this->success_response( $campaign['data'], $campaign['message'] );
}
return $this->error_response( $campaign['message'] );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Update_Campaign' );

View File

@@ -0,0 +1,114 @@
<?php
class BWFCRM_API_Apply_Field extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/fields';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'email' => '',
'fields' => '',
);
}
public function process_api_call() {
$contact = $this->get_contact_by_id_or_email( 'contact_id', 'email' );
$email = $this->get_sanitized_arg( 'email', 'text_field' );
if ( is_wp_error( $contact ) ) {
return $contact;
}
if ( empty( $email ) || ! is_email( $email ) ) {
$email = $contact->contact->get_email();
}
$sanitize_cb = 'text_field';
if ( is_array( $this->args['fields'] ) ) {
$ids = array_keys( $this->args['fields'] );
$ids = array_filter( $ids, [ $this, 'check_field_type_textarea' ] );
if ( count( $ids ) > 0 ) {
$sanitize_cb = 'textarea_field';
}
}
$fields = $this->get_sanitized_arg( '', $sanitize_cb, $this->args['fields'] );
if ( empty( $fields ) ) {
$response = __( 'Required Fields missing', 'wp-marketing-automations-pro' );
$this->response_code = 400;
return $this->error_response( $response );
}
$field_email = $this->get_sanitized_arg( 'email', 'text_field', $this->args['fields'] );
if ( ! empty( $field_email ) && $email !== $field_email ) {
if ( ! is_email( $field_email ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Email is not valid.', 'wp-marketing-automations-pro' ) );
}
$check_contact = new BWFCRM_Contact( $field_email );
/** If email is already exists with other contacts*/
if ( $check_contact->is_contact_exists() ) {
/** If Only email field to be updated then return error response */
if ( 1 === count( $this->args['fields'] ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Email is already associated with other contact.', 'wp-marketing-automations-pro' ) );
}
/**If other fields also available for update then unset the email */
unset( $fields['email'] );
}
}
$response = $contact->update_custom_fields( $fields );
if ( ! ( $response ) || empty( $response ) ) {
$this->response_code = 200;
return $this->success_response( '', __( 'Unable to Update fields', 'wp-marketing-automations-pro' ) );
}
/** If email changed and email is set for change then hook added */
if ( ! empty( $field_email ) && $email !== $field_email ) {
do_action( 'bwfan_contact_email_changed', $field_email, $email, $contact );
}
return $this->success_response( $contact->get_array( false, true, true, true ), 'Contact updated' );
}
public function check_field_type_textarea( $id ) {
$fields = BWFCRM_Fields::get_custom_fields( null, null, null );
$fields = array_filter( $fields, function ( $val ) {
if ( isset( $val['type'] ) && 3 == $val['type'] ) {
/** 3 is textarea */
return true;
}
return false;
} );
if ( is_array( $fields ) && array_key_exists( $id, $fields ) ) {
return true;
}
return false;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Apply_Field' );

View File

@@ -0,0 +1,89 @@
<?php
class BWFCRM_API_Apply_Lists extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/lists';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'lists' => array(),
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$lists = $this->args['lists'];
$lists = array_filter( array_values( $lists ) );
if ( empty( $lists ) ) {
$response = __( 'Required Lists missing', 'wp-marketing-automations-pro' );
$this->response_code = 404;
return $this->error_response( $response );
}
$added_lists = $contact->add_lists( $lists );
if ( is_wp_error( $added_lists ) ) {
$this->response_code = 500;
return $this->error_response( '', $added_lists );
}
if ( empty( $added_lists ) ) {
$this->response_code = 200;
return $this->success_response( '', __( 'Provided lists are applied already.', 'wp-marketing-automations-pro' ) );
}
$result = [];
$lists_added = array_map( function ( $list ) {
return $list->get_array();
}, $added_lists );
$message = __( 'List(s) assigned', 'wp-marketing-automations-pro' );
if ( count( $lists ) !== count( $added_lists ) ) {
$added_lists_names = array_map( function ( $list ) {
return $list->get_name();
}, $added_lists );
$added_lists_names = implode( ', ', $added_lists_names );
$this->response_code = 200;
$message = __( 'Some Lists are applied already. Applied Lists are: ' . $added_lists_names, 'wp-marketing-automations-pro' );
}
$result['list_added'] = is_array( $lists_added ) ? array_values( $lists_added ) : $lists_added;
$result['last_modified'] = $contact->contact->get_last_modified();
return $this->success_response( $result, $message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Apply_Lists' );

View File

@@ -0,0 +1,85 @@
<?php
class BWFCRM_API_Apply_Tags extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/tags';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'tags' => array(),
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$tags = $this->args['tags'];
$tags = array_filter( array_values( $tags ) );
if ( empty( $tags ) ) {
$response = __( 'No Tags provided', 'wp-marketing-automations-pro' );
$this->response_code = 400;
return $this->error_response( $response );
}
$added_tags = $contact->add_tags( $tags );
if ( is_wp_error( $added_tags ) ) {
$this->response_code = 500;
return $this->error_response( '', $added_tags );
}
if ( empty( $added_tags ) ) {
$this->response_code = 200;
return $this->success_response( '', __( 'Provided tags are applied already.', 'wp-marketing-automations-pro' ) );
}
$tags_added = array_map( function ( $tag ) {
return $tag->get_array();
}, $added_tags );
$result = [];
$message = __( 'Tag(s) added', 'wp-marketing-automations-pro' );
if ( count( $tags ) !== count( $added_tags ) ) {
$applied_tags_names = array_map( function ( $tag ) {
return $tag->get_name();
}, $added_tags );
$applied_tags_names = implode( ', ', $applied_tags_names );
$this->response_code = 200;
$message = __( 'Some Tags are applied already. Applied Tags are: ' . $applied_tags_names, 'wp-marketing-automations-pro' );
}
$result['tags_added'] = is_array( $tags_added ) ? array_values( $tags_added ) : $tags_added;
$result['last_modified'] = $contact->contact->get_last_modified();
return $this->success_response( $result, $message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Apply_Tags' );

View File

@@ -0,0 +1,82 @@
<?php
class BWFCRM_API_Contact_Listing extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public $count_data = [];
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/listing';
$this->pagination->offset = 0;
$this->pagination->limit = 10;
}
public function process_api_call() {
/** checking if search present in params */
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$filters_collection = empty( $this->args['filters'] ) ? array() : $this->args['filters'];
$get_wc_data = $this->get_sanitized_arg( 'get_wc', 'bool' );
$grab_totals = $this->get_sanitized_arg( 'grab_totals', 'bool' );
$only_count = $this->get_sanitized_arg( 'only_count', 'bool' );
$contact_mode = $this->get_sanitized_arg( 'fetch_base', 'text_field' );
$exclude_unsubs = $this->get_sanitized_arg( 'exclude_unsubs', 'bool' );
$exclude_unsubs_lists = $this->get_sanitized_arg( 'exclude_unsubs_lists', 'bool' );
$grab_custom_fields = $this->get_sanitized_arg( 'grab_custom_fields', 'bool' );
$order = $this->get_sanitized_arg( 'order', 'text_field' );
$order_by = $this->get_sanitized_arg( 'order_by', 'text_field' );
$additional_info = array(
'grab_totals' => $grab_totals,
'only_count' => $only_count,
'fetch_base' => $contact_mode,
'exclude_unsubs' => $exclude_unsubs,
'exclude_unsubs_lists' => $exclude_unsubs_lists,
'grab_custom_fields' => $grab_custom_fields,
);
if ( ! empty( $order ) && ! empty( $order_by ) ) {
$additional_info['order'] = $order;
$additional_info['order_by'] = $order_by;
}
if ( class_exists( 'WooCommerce' ) ) {
$additional_info['customer_data'] = $get_wc_data;
}
$filter_match = isset( $filters_collection['match'] ) && ! empty( $filters_collection['match'] ) ? $filters_collection['match'] : 'all';
$filter_match = ( 'any' === $filter_match ? ' OR ' : ' AND ' );
$normalized_filters = BWFCRM_Filters::_normalize_input_filters( $filters_collection );
// $contacts = BWFCRM_Contact::get_contacts( $search, $this->pagination->offset, $this->pagination->limit, $filters_collection, $additional_info );
$contacts = BWFCRM_Model_Contact::get_contact_listing( $search, $this->pagination->limit, $this->pagination->offset, $normalized_filters, $additional_info, $filter_match );
$this->count_data = BWFAN_PRO_Common::get_contact_data_counts();
$this->total_count = $contacts['total'];
$this->response_code = 200;
return $this->success_response( $contacts['contacts'] );
}
public function get_result_total_count() {
return $this->total_count;
}
public function get_result_count_data() {
return $this->count_data;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Contact_Listing' );

View File

@@ -0,0 +1,61 @@
<?php
class BWFCRM_API_Contact_Resubscribe extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/resubscribe';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID to resubscribe contact', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function default_args_values() {
return array(
'contact_id' => ''
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$contact = new BWFCRM_Contact( absint( $contact_id ) );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact doesn\'t exist', 'wp-marketing-automations-pro' ) );
}
$unsubscribe_data = $contact->check_contact_unsubscribed( false );
if ( empty( $unsubscribe_data ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact already subscribed', 'wp-marketing-automations-pro' ) );
}
foreach ( $unsubscribe_data as $data ) {
BWFAN_Model_Message_Unsubscribe::delete( $data['ID'] );
}
$contact->save_last_modified();
$this->response_code = 200;
return $this->success_response( [ 'contact_id' => $contact_id ], __( 'Contact subscribed', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Contact_Resubscribe' );

View File

@@ -0,0 +1,101 @@
<?php
class BWFCRM_API_Contact_Status_Change extends BWFCRM_API_Base {
public static $ins;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/execute_status_action/(?P<status>[a-zA-Z0-9-]+)';
}
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$status = $this->get_sanitized_arg( 'status', 'text_field' );
$contact = new BWFCRM_Contact( absint( $contact_id ) );
if ( ! $contact->is_contact_exists() ) {
return $this->error_response( __( 'Contact does not exists', 'wp-marketing-automations-pro' ) );
}
$result = false;
$message = __( 'Unable to perform requested action', 'wp-marketing-automations-pro' );
switch ( $status ) {
case 'resubscribe':
$result = $contact->resubscribe();
if ( true === $result ) {
$message = __( 'Contact resubscribed', 'wp-marketing-automations-pro' );
}
break;
case 'unsubscribe':
$result = $contact->unsubscribe();
if ( true === $result ) {
$message = __( 'Contact unsubscribed', 'wp-marketing-automations-pro' );
}
break;
case 'verify':
$result = $contact->verify();
if ( true === $result ) {
$message = __( 'Contact subscribed', 'wp-marketing-automations-pro' );
}
break;
case 'unverify':
$result = $contact->unverify();
if ( true === $result ) {
$message = __( 'Contact unverfied', 'wp-marketing-automations-pro' );
}
break;
case 'bounced':
$result = $contact->mark_as_bounced();
if ( true === $result ) {
$message = __( 'Contact bounced', 'wp-marketing-automations-pro' );
}
break;
case 'softbounced':
if ( method_exists( $contact, 'mark_as_soft_bounced' ) ) {
$result = $contact->mark_as_soft_bounced();
if ( true === $result ) {
$message = __( 'Contact soft bounced', 'wp-marketing-automations-pro' );
}
} else {
$result = $contact->mark_as_bounced();
if ( true === $result ) {
$message = __( 'Contact bounced', 'wp-marketing-automations-pro' );
}
}
break;
case 'complaint':
if ( method_exists( $contact, 'mark_as_complaint' ) ) {
$result = $contact->mark_as_complaint();
if ( true === $result ) {
$message = __( 'Contact complaint', 'wp-marketing-automations-pro' );
}
} else {
$result = $contact->mark_as_bounced();
if ( true === $result ) {
$message = __( 'Contact bounced', 'wp-marketing-automations-pro' );
}
}
break;
}
if ( ! $result ) {
return $this->error_response( $message, null, 500 );
}
return $this->success_response( [
'status' => $contact->get_display_status(),
'data' => $contact->get_array( false, true, true, true, true ),
], $message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Contact_Status_Change' );

View File

@@ -0,0 +1,81 @@
<?php
class BWFCRM_API_Contact_Unsubscribe extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/unsubscribe';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID to unsubscribe contact', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function default_args_values() {
return array(
'contact_id' => '',
'mode' => '',
'automation_id' => '',
'c_type' => ''
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$automation_id = $this->get_sanitized_arg( 'automation_id', 'text_field' );
$c_type = $this->get_sanitized_arg( 'c_type', 'text_field' );
$contact = new BWFCRM_Contact( absint( $contact_id ) );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact doesn\'t exist', 'wp-marketing-automations-pro' ) );
}
$unsubscribed = $contact->check_contact_unsubscribed();
if ( ! empty( $unsubscribed['ID'] ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact already unsubscribed', 'wp-marketing-automations-pro' ) );
}
$recipients = [];
$email = $contact->contact->get_email();
$phone = $contact->contact->get_contact_no();
$recipients[] = $email;
if ( ! empty( $phone ) ) {
$recipients[] = $phone;
}
foreach ( $recipients as $recipient ) {
$insert_data = array(
'recipient' => $recipient,
'mode' => is_email( $recipient ) ? 1 : 2,
'c_date' => current_time( 'mysql', 1 ),
'automation_id' => ! empty( $automation_id ) ? absint( $automation_id ) : get_current_user_id(),
'c_type' => ! empty( $c_type ) ? absint( $c_type ) : 3
);
BWFAN_Model_Message_Unsubscribe::insert( $insert_data );
/** hook when any contact unsubscribed */
do_action( 'bwfcrm_after_contact_unsubscribed', $insert_data );
}
$contact->save_last_modified();
return $this->success_response( [ 'contact_id' => $contact_id ], __( 'Contact unsubscribed', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Contact_Unsubscribe' );

View File

@@ -0,0 +1,62 @@
<?php
class BWFCRM_API_Create_Contact_Note extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/notes';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'notes' => array(),
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$notes = $this->args['notes'];
if ( empty( $notes ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Note is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$note_added = $contact->add_note_to_contact( $notes );
if ( false === $note_added || is_wp_error( $note_added ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Unable to add note to contact', 'wp-marketing-automations-pro' ) );
}
$this->response_code = 200;
return $this->success_response( [], __( 'Contact note added', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Create_Contact_Note' );

View File

@@ -0,0 +1,75 @@
<?php
class BWFCRM_API_Create_Contact extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/contacts';
}
public function process_api_call() {
$email = $this->get_sanitized_arg( 'email', 'email' );
if ( false === $email || ! is_email( $email ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Email is not valid', 'wp-marketing-automations-pro' ) );
}
$params = array(
'f_name' => isset( $this->args['f_name'] ) ? $this->get_sanitized_arg( 'f_name', 'text_field', $this->args['f_name'] ) : '',
'l_name' => isset( $this->args['l_name'] ) ? $this->get_sanitized_arg( 'l_name', 'text_field', $this->args['l_name'] ) : '',
'create_wp_user' => isset( $this->args['create_wp_user'] ) ? rest_sanitize_boolean( $this->args['create_wp_user'] ) : '',
'wp_password' => isset( $this->args['wp_password'] ) ? $this->args['wp_password'] : '',
'contact_no' => isset( $this->args['contact_no'] ) ? $this->get_sanitized_arg( 'contact_no', 'text_field', $this->args['contact_no'] ) : '',
'source' => isset( $this->args['source'] ) ? $this->get_sanitized_arg( 'source', 'text_field', $this->args['source'] ) : '',
'status' => isset( $this->args['status'] ) ? $this->get_sanitized_arg( 'status', 'text_field', $this->args['status'] ) : '',
);
foreach ( $this->args as $key => $value ) {
if ( ! is_numeric( $key ) ) {
continue;
}
$params[ $key ] = $value;
}
$contact = new BWFCRM_Contact( $email, true, $params );
if ( isset( $this->args['tags'] ) ) {
$contact->set_tags( $this->args['tags'], true, false );
}
if ( isset( $this->args['lists'] ) ) {
$contact->set_lists( $this->args['lists'], true, false );
}
$contact->save();
if ( $contact->already_exists ) {
$this->response_code = 422;
return $this->error_response( __( 'Contact already exists', 'wp-marketing-automations-pro' ) );
}
if ( $contact->is_contact_exists() ) {
$this->response_code = 200;
return $this->success_response( $contact->get_array( false, class_exists( 'WooCommerce' ) ), __( 'Contact created', 'wp-marketing-automations-pro' ) );
}
$this->response_code = 500;
return $this->error_response( __( 'Unable to create contact', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Create_Contact' );

View File

@@ -0,0 +1,59 @@
<?php
class BWFCRM_API_DELETE_Contact_Note extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/notes/(?P<note_id>[\\d]+)';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'note_id' => 0,
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact id is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact instanceof BWFCRM_Contact || 0 === $contact->get_id() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$note_id = $this->get_sanitized_arg( 'note_id', 'key' );
$delete_contact_note_result = $contact->delete_notes( $note_id );
if ( ! $delete_contact_note_result ) {
$this->response_code = 404;
return $this->error_response( __( 'Unable to delete the note for contact #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$this->response_code = 200;
$success_message = __( 'Contact notes deleted', 'wp-marketing-automations-pro' );
return $this->success_response( array( 'contact_id' => $contact_id ), $success_message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_DELETE_Contact_Note' );

View File

@@ -0,0 +1,58 @@
<?php
class BWFCRM_API_DELETE_Contact extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)';
}
public function default_args_values() {
return array(
'contact_id' => '',
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact id is missing.', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact instanceof BWFCRM_Contact || 0 === $contact->get_id() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given contact id: ' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$delete_contact_result = BWFCRM_Model_Contact::delete_contact( $contact_id );
if ( ! $delete_contact_result ) {
$this->response_code = 404;
return $this->error_response( __( 'Some error occurred during deletion of contact and its data.', 'wp-marketing-automations-pro' ) );
}
$this->response_code = 200;
$success_message = __( 'Contact deleted', 'wp-marketing-automations-pro' );
return $this->success_response( array( 'contact_id' => $contact_id ), $success_message );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_DELETE_Contact' );

View File

@@ -0,0 +1,36 @@
<?php
class BWFCRM_API_Delete_Contacts extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts';
}
public function process_api_call() {
$contact_ids = $this->args['contacts'];
if ( empty( $contact_ids ) || ! is_array( $contact_ids ) ) {
return $this->error_response( __( 'Contact ids are missing.', 'wp-marketing-automations-pro' ), null, 500 );
}
BWFCRM_Model_Contact::delete_multiple_contacts( $contact_ids );
$this->response_code = 200;
return $this->success_response( array( 'contacts' => $contact_ids ), __( 'Contacts deleted!', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Delete_Contacts' );

View File

@@ -0,0 +1,91 @@
<?php
class BWFCRM_API_Get_Contact_Automations extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/automations';
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
$offset = ! empty( $this->get_sanitized_arg( 'offset', 'text_field' ) ) ? absint( $this->get_sanitized_arg( 'offset', 'text_field' ) ) : 0;
$limit = ! empty( $this->get_sanitized_arg( 'limit', 'text_field' ) ) ? $this->get_sanitized_arg( 'limit', 'text_field' ) : 25;
/** contact id missing than return */
if ( empty( $contact_id ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Contact id is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contact_automations = [];
if ( class_exists('BWFAN_Common') ) {
$contact_automations = BWFAN_Common::get_automations_for_contact( $contact_id, $limit, $offset );
}
if ( empty( $contact_automations ) ) {
$this->response_code = 200;
return $this->error_response( __( 'No contact automation found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contact_automations['contacts'] = array_map( function( $contact ) {
/** Get event name */
$event_slug = BWFAN_Model_Automations::get_event_name($contact['aid']);
$event_obj = BWFAN_Core()->sources->get_event( $event_slug );
$event_name = ! empty( $event_obj ) ? $event_obj->get_name(): '';
$automation_meta = BWFAN_Core()->automations->get_automation_data_meta( $contact['aid'] );
$contact['event'] = $event_name;
$contact['automation_title'] = $automation_meta['title'];
return $contact;
}, $contact_automations['contacts'] );
$this->total_count = isset( $contact_automations[ 'total' ] ) ? $contact_automations[ 'total' ] : 0;
$this->response_code = 200;
$success_message = __( 'Got all contact automations', 'wp-marketing-automations-pro' );
return $this->success_response( $contact_automations, $success_message );
}
public function get_result_total_count() {
return $this->total_count;
}
}
if ( function_exists( 'BWFAN_Core' ) ) {
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Automations' );
}

View File

@@ -0,0 +1,91 @@
<?php
class BWFCRM_API_Get_Contact_Funnels extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/funnels';
}
public function default_args_values() {
return array(
'contact_id' => '',
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
$offset = $this->get_sanitized_arg( 'offset', 'key' );
$limit = $this->get_sanitized_arg( 'limit', 'key' );
$offset = empty( $offset ) ? $this->pagination->offset : $offset;
$limit = empty( $offset ) ? $this->pagination->limit : $limit;
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contacts_funnel = array();
$contacts_funnel['funnel'] = $contact->get_contact_funnels_array();
if ( function_exists( 'WFACP_Core' ) ) {
$contacts_funnel['funnel']['checkout'] = [];
}
if ( function_exists( 'WFOB_Core' ) ) {
$contacts_funnel['funnel']['order_bump'] = [];
}
if ( function_exists( 'WFOPP_Core' ) ) {
$optin_etries = $contact->get_contact_optin_array();
if ( is_array( $optin_etries ) && ! empty( $optin_etries ) ) {
/** Add email in optin entry */
$optin_etries = array_map( function ( $optin ) {
$entry = json_decode( $optin['entry'], true );
if ( ! empty( $optin['email'] ) && ! empty( $entry ) ) {
$entry['optin_email'] = $optin['email'];
}
$optin['entry'] = wp_json_encode( $entry );
return $optin;
}, $optin_etries );
}
$contacts_funnel['funnel']['optin'] = $optin_etries;
}
if ( function_exists( 'WFOCU_Core' ) ) {
$contacts_funnel['funnel']['upsells'] = [];
}
$this->response_code = 200;
$success_message = __( 'Contacts funnels', 'wp-marketing-automations-pro' );
return $this->success_response( $contacts_funnel, $success_message );
}
}
if ( class_exists( 'WFFN_Core' ) ) {
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Funnels' );
}

View File

@@ -0,0 +1,89 @@
<?php
class BWFCRM_API_Get_Contact_Lists extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/lists';
$this->pagination->offset = 0;
$this->pagination->limit = 30;
$this->request_args = array(
'search' => array(
'description' => __( 'Search from list name', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'offset' => array(
'description' => __( 'list Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function default_args_values() {
return array(
'contact_id' => '',
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$offset = $this->get_sanitized_arg( 'offset', 'text_field' );
$limit = $this->get_sanitized_arg( 'limit', 'text_field' );
$offset = empty( $offset ) ? $this->pagination->offset : $offset;
$limit = empty( $offset ) ? $this->pagination->limit : $limit;
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact id is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
// $contact_terms_count = BWFCRM_Model_Contact_Terms::get_contact_terms_count( $contact->get_id(), $search, 1 );
// $contact_terms = BWFCRM_Model_Contact_Terms::get_contact_terms( $contact->get_id(), $offset, $limit, $search, 1 );
$contact_terms = $contact->get_all_lists();
if ( empty( $contact_terms ) ) {
$this->response_code = 404;
$error_message = ! empty( $search ) ? __( 'No Searched lists found for contact with name \'' . $search . '\'', 'wp-marketing-automations-pro' ) : __( 'No contacts lists found', 'wp-marketing-automations-pro' );
return $this->error_response( $error_message );
}
$this->total_count = count( $contact_terms );
$this->response_code = 200;
$success_message = ! empty( $search ) ? __( 'Searched lists for contact \'' . $search . '\'', 'wp-marketing-automations-pro' ) : __( 'Got all contacts lists', 'wp-marketing-automations-pro' );
return $this->success_response( $contact_terms, $success_message );
}
public function get_result_total_count() {
return $this->total_count;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Lists' );

View File

@@ -0,0 +1,67 @@
<?php
class BWFCRM_API_Get_Contact_Note extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/notes';
$this->pagination->limit = 25;
$this->pagination->offset = 0;
}
public function default_args_values() {
return array(
'contact_id' => '',
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$offset = ! empty( $this->get_sanitized_arg( 'offset', 'key' ) ) ? $this->get_sanitized_arg( 'offset', 'text_field' ) : $this->pagination->offset;
$limit = ! empty( $this->get_sanitized_arg( 'limit', 'key' ) ) ? $this->get_sanitized_arg( 'limit', 'text_field' ) : $this->pagination->limit;
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contact_notes = $contact->get_contact_notes_array( $offset, $limit );
if ( empty( $contact_notes ) ) {
$this->response_code = 200;
return $this->success_response( [], __( 'No contact notes found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$all_contact_notes = $contact->get_contact_notes_array( 0, 0 );
$this->total_count = count( $all_contact_notes );
$this->response_code = 200;
$success_message = __( 'Contact notes reated to contact id :' . $contact_id, 'wp-marketing-automations-pro' );
return $this->success_response( $contact_notes, $success_message );
}
public function get_result_total_count() {
return $this->total_count;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Note' );

View File

@@ -0,0 +1,282 @@
<?php
class BWFCRM_API_Get_Contact_Orders extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/orders';
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
/** contact id missing than return */
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact id is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$limit = $this->get_sanitized_arg( 'limit', 'text_field' );
$offset = $this->get_sanitized_arg( 'offset', 'text_field' );
$limit = ! empty( $limit ) ? $limit : 10;
$offset = ! empty( $offset ) ? $offset : 0;
$order_ids = $contact->get_orders( $offset, $limit );
$orders = $this->get_contact_activity_records( $contact_id, $order_ids );
if ( empty( $orders ) ) {
$response = [
'orders' => [],
];
$this->response_code = 200;
return $this->success_response( $response, __( 'No contact order found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$response = [
'orders' => $orders,
];
$this->total_count = $contact->get_orders_count();
$this->response_code = 200;
$success_message = __( 'Got all contact orders', 'wp-marketing-automations-pro' );
return $this->success_response( $response, $success_message );
}
public function get_contact_activity_records( $cid, $order_ids, $funnel_id = '' ) {
if ( ! is_array( $order_ids ) || count( $order_ids ) === 0 ) {
return [];
}
$all_orders = [];
$sales_data = [];
$order_statuses = wc_get_order_statuses();
foreach ( $order_ids as $order_id ) {
$conv_order = $tags = $categories = [];
$product_data = $this->get_single_order_info( $order_id, $cid );
$conv_data = apply_filters( 'wffn_conversion_tracking_data_activity', [], $cid, $order_id );
$conv_order = array_merge( $conv_order, $conv_data );
$conv_order['products'] = $product_data['products'];
/** Get Products Categories name */
if ( empty( $product_data['cat_ids'] ) ) {
$categories = array_map( function ( $term_id ) {
$cat = get_term( absint( $term_id ) );
return $cat instanceof WP_Term ? $cat->name : false;
}, array_unique( $product_data['cat_ids'] ) );
$categories = array_values( array_filter( $categories ) );
}
/** Get Products Tags name */
if ( ! empty( $product_data['tag_ids'] ) ) {
$tags = array_map( function ( $term_id ) {
$tag = get_term( absint( $term_id ) );
return $tag instanceof WP_Term ? $tag->name : false;
}, array_unique( $product_data['tag_ids'] ) );
$tags = array_values( array_filter( $tags ) );
}
$conv_order['tags'] = $tags;
$conv_order['categories'] = $categories;
$sales_data = array_merge( $sales_data, $product_data['timeline_data'] );
$funnel_ids = array_unique( array_column( $conv_order['products'], 'fid' ) );
$conv_order['order_id'] = $order_id;
if ( isset( $conv_order['overview'] ) ) {
unset( $conv_order['overview'] );
}
if ( isset( $conv_order['conversion'] ) ) {
$conv_order['conversion']['funnel_link'] = '';
$conv_order['conversion']['funnel_title'] = '';
$s_funnel_id = ! empty( $funnel_id ) ? $funnel_id : ( ( is_array( $funnel_ids ) && count( $funnel_ids ) > 0 ) ? $funnel_ids[0] : 0 );
$conv_order['conversion']['funnel_id'] = $s_funnel_id;
$get_funnel = new WFFN_Funnel( $s_funnel_id );
if ( $get_funnel instanceof WFFN_Funnel && 0 !== $get_funnel->get_id() ) {
$funnel_link = ( $get_funnel->get_id() === WFFN_Common::get_store_checkout_id() ) ? admin_url( "admin.php?page=bwf&path=/store-checkout" ) : admin_url( "admin.php?page=bwf&path=/funnels/$s_funnel_id" );
$conv_order['conversion']['funnel_link'] = $funnel_link;
$conv_order['conversion']['funnel_title'] = $get_funnel->get_title();
}
}
$conv_order['customer_info'] = array(
'email' => '',
'phone' => '',
'billing_address' => '',
'shipping_address' => '',
);
$conv_order['coupons'] = [];
if ( ! empty( $order_id ) && absint( $order_id ) > 0 && function_exists( 'wc_get_order' ) ) {
$order_data = wc_get_order( $order_id );
if ( $order_data instanceof WC_Order ) {
$conv_order['coupons'] = $order_data->get_coupon_codes();
$conv_order['customer_info'] = [
'email' => $order_data->get_billing_email(),
'phone' => $order_data->get_billing_phone(),
'billing_address' => wp_kses_post( $order_data->get_formatted_billing_address() ),
'shipping_address' => wp_kses_post( $order_data->get_formatted_shipping_address() ),
'purchased_on' => ! empty( $order_data->get_date_created() ) ? $order_data->get_date_created()->date( 'Y-m-d H:i:s' ) : $product_data['date_added'],
'payment_method' => $order_data->get_payment_method_title(),
];
$conv_order['status'] = [
'label' => isset( $order_statuses[ 'wc-' . $order_data->get_status() ] ) ? $order_statuses[ 'wc-' . $order_data->get_status() ] : $order_data->get_status(),
'value' => 'wc-' . $order_data->get_status()
];
}
}
$all_orders[] = $conv_order;
}
return $all_orders;
}
public function get_single_order_info( $order_id, $cid = '' ) {
$timeline_data = [];
$products = [];
$data = [
'products' => $products,
'date_added' => '',
'timeline_data' => $timeline_data,
'tag_ids' => [],
'cat_ids' => [],
];
$order = wc_get_order( $order_id );
if ( ! $order instanceof \WC_Order ) {
return $data;
}
$items = $order->get_items();
$subtotal = 0;
$i = 0;
foreach ( $items as $item ) {
$product = new stdClass();
$key = 'checkout';
$product->date = '';
/**
* create data for show timeline data
*/
if ( class_exists( 'WFACP_Contacts_Analytics' ) && ! empty( $cid ) && 0 === $i ) {
/*
* show checkout in timeline only one time per order
*/
$aero_obj = WFACP_Contacts_Analytics::get_instance();
$checkout_records = $aero_obj->get_contacts_revenue_records( $cid, $order_id );
if ( is_array( $checkout_records ) && ! isset( $checkout_records['db_error'] ) && isset( $checkout_records[0] ) ) {
$data['date_added'] = $checkout_records[0]->date;
$data['timeline_data'][] = $checkout_records[0];
}
}
if ( 'yes' === $item->get_meta( '_upstroke_purchase' ) ) {
$key = 'upsell';
if ( class_exists( 'WFOCU_Contacts_Analytics' ) ) {
$upsell_obj = WFOCU_Contacts_Analytics::get_instance();
$upsell_records = $upsell_obj->get_contacts_revenue_records( $cid, $order_id );
if ( is_array( $upsell_records ) && ! isset( $upsell_records['db_error'] ) && isset( $upsell_records[0] ) ) {
$data['date_added'] = empty( $data['date_added'] ) ? $upsell_records[0]->date : $data['date_added'];
$data['timeline_data'][] = $upsell_records[0];
}
}
}
if ( 'yes' === $item->get_meta( '_bump_purchase' ) ) {
$key = 'bump';
if ( class_exists( 'WFOB_Contacts_Analytics' ) ) {
$bump_obj = WFOB_Contacts_Analytics::get_instance();
$bump_records = $bump_obj->get_contacts_revenue_records( $cid, $order_id );
if ( is_array( $bump_records ) && ! isset( $bump_records['db_error'] ) && isset( $bump_records[0] ) ) {
$data['date_added'] = empty( $data['date_added'] ) ? $bump_records[0]->date : $data['date_added'];
$data['timeline_data'][] = $bump_records[0];
}
}
}
$sub_total = $item->get_subtotal();
$product->name = $item->get_name();
$product->revenue = $sub_total;
$product->type = $key;
$data['products'][] = $product;
$subtotal += $sub_total;
$i ++;
/** Fetch tags and categories */
$item_data = $item->get_data();
$wc_product = intval( $item_data['product_id'] ) ? wc_get_product( $item_data['product_id'] ) : '';
$tag_ids = $wc_product instanceof WC_Product ? $wc_product->get_tag_ids() : [];
$cat_ids = $wc_product instanceof WC_Product ? $wc_product->get_category_ids() : [];
$data['tag_ids'] = array_merge( $data['tag_ids'], $tag_ids );
$data['cat_ids'] = array_merge( $data['cat_ids'], $cat_ids );
}
$order_total = $order->get_total();
$total_discount = $order->get_total_discount();
$remaining_amount = $order_total - ( $subtotal - $total_discount );
if ( $remaining_amount > 0 ) {
$shipping_tax = new stdClass();
$shipping_tax->name = __( 'Including shipping and taxes ,other costs', 'funnel-builder' );
$shipping_tax->revenue = $remaining_amount;
$shipping_tax->type = 'shipping';
$data['products'][] = $shipping_tax;
}
if ( $order->get_total_discount() > 0 ) {
$discount = new stdClass();
$discount->name = __( 'Discount', 'funnel-builder' );
$discount->revenue = $order->get_total_discount();
$discount->type = 'discount';
$data['products'][] = $discount;
}
return $data;
}
public function get_result_total_count() {
return $this->total_count;
}
}
if ( class_exists( 'woocommerce' ) ) {
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Orders' );
}

View File

@@ -0,0 +1,79 @@
<?php
class BWFCRM_API_Get_Contact_Subscriptions extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/subscriptions';
$this->pagination->limit = 10;
$this->pagination->offset = 0;
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
/** contact id missing than return */
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact id is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$limit = $this->get_sanitized_arg( 'limit', 'text_field' );
$limit = ! empty( $limit ) ? $limit : $this->pagination->limit;
$offset = $this->get_sanitized_arg( 'offset', 'text_field' );
$offset = ! empty( $offset ) ? $offset : 0;
$contact_orders = $contact->get_subscriptions_array( $offset, $limit );
if ( empty( $contact_orders['subscriptions'] ) ) {
$this->response_code = 200;
return $this->success_response( [], __( 'No contact subscriptions found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$total_contact_subscriptions = $contact->get_total_subscriptions();
$this->total_count = empty( $total_contact_subscriptions ) ? 0 : $total_contact_subscriptions;
$this->response_code = 200;
$success_message = __( 'Got all contact subscriptions', 'wp-marketing-automations-pro' );
return $this->success_response( $contact_orders, $success_message );
}
public function get_result_total_count() {
return $this->total_count;
}
}
if ( class_exists( 'WC_Subscriptions' ) ) {
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Subscriptions' );
}

View File

@@ -0,0 +1,77 @@
<?php
class BWFCRM_API_Get_Contact_Tags extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/tags';
$this->pagination->offset = 0;
$this->pagination->limit = 30;
$this->request_args = array(
'search' => array(
'description' => __( 'Search from tag name', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'offset' => array(
'description' => __( 'Tags list Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function default_args_values() {
return array(
'contact_id' => '',
);
}
public function process_api_call() {
/** checking if search present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$offset = $this->get_sanitized_arg( 'offset', 'text_field' );
$limit = $this->get_sanitized_arg( 'limit', 'text_field' );
$offset = empty( $offset ) ? $this->pagination->offset : $offset;
$limit = empty( $limit ) ? $this->pagination->limit : $limit;
if ( empty( $contact_id ) ) {
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
// $contact_terms = BWFCRM_Model_Contact_Terms::get_contact_terms( $contact->get_id(), $offset, $limit, $search, 0 );
$contact_terms = $contact->get_all_tags();
$this->response_code = 200;
return $this->success_response( $contact_terms );
}
public function get_result_total_count() {
return $this->total_count;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Tags' );

View File

@@ -0,0 +1,62 @@
<?php
class BWFCRM_API_Get_Contact_Tasks extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/tasks';
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
/** contact id missing than return */
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contact_tasks = $contact->get_tasks_array();
if ( empty( $contact_tasks ) ) {
$this->response_code = 404;
return $this->error_response( __( 'No tasks available for the contact', 'wp-marketing-automations-pro' ) );
}
$this->response_code = 200;
$success_message = __( 'Got all contact tasks', 'wp-marketing-automations-pro' );
return $this->success_response( $contact_tasks, $success_message );
}
}
if ( function_exists( 'BWFAN_Core' ) ) {
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Tasks' );
}

View File

@@ -0,0 +1,49 @@
<?php
class BWFCRM_API_Get_Contact extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$id = $this->get_sanitized_arg( 'contact_id', 'key' );
$contact = new BWFCRM_Contact( $id );
if ( $contact->is_contact_exists() ) {
return $this->success_response( $contact->get_array( false, true, true, true, true ) );
} else {
$this->response_code = 404;
return $this->error_response( __( "No contact found with given id #", 'wp-marketing-automations-pro' ) . $id );
}
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact' );

View File

@@ -0,0 +1,151 @@
<?php
class BWFCRM_API_Get_Contacts extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $total_count = 0;
public $count_data = [];
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts';
$this->pagination->offset = 0;
$this->pagination->limit = 10;
$this->request_args = array(
'search' => array(
'description' => __( 'Search from email, first_name or last_name', 'wp-marketing-automations-pro' ),
'type' => 'string',
),
'offset' => array(
'description' => __( 'Contacts list Offset', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'limit' => array(
'description' => __( 'Per page limit', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'get_wc' => array(
'description' => __( 'Get WC Data as well', 'wp-marketing-automations-pro' ),
'type' => 'boolean',
),
'grab_totals' => array(
'description' => __( 'Grab total contact count as well', 'wp-marketing-automations-pro' ),
'type' => 'boolean',
),
'start_indexing' => array(
'description' => __( 'Start Indexing of Contacts in case indexing is pending', 'wp-marketing-automations-pro' ),
'type' => 'boolean',
),
);
}
public function default_args_values() {
return array(
'search' => '',
'filters' => array(),
);
}
public function process_api_call() {
$additional_info = array(
'grab_totals' => $this->get_sanitized_arg( 'grab_totals', 'bool' ),
'only_count' => $this->get_sanitized_arg( 'only_count', 'bool' ),
'fetch_base' => $this->get_sanitized_arg( 'fetch_base', 'text_field' ),
'exclude_unsubs' => $this->get_sanitized_arg( 'exclude_unsubs', 'bool' ),
'exclude_unsubs_lists' => $this->get_sanitized_arg( 'exclude_unsubs_lists', 'bool' ),
'grab_custom_fields' => $this->get_sanitized_arg( 'grab_custom_fields', 'bool' ),
'include_soft_bounce' => $this->get_sanitized_arg( 'includeSoftBounce', 'bool' ), // specific for broadcast
'include_unverified' => $this->get_sanitized_arg( 'includeUnverified', 'bool' ),
'include_unsubscribe' => $this->get_sanitized_arg( 'include_unsubs', 'bool' ),
'include_ids' => isset( $this->args[ 'include_ids' ] ) ? $this->args[ 'include_ids' ] : [],
);
/** Un-Open contacts case */
$un_open_broadcast = $this->get_sanitized_arg( 'unopen_broadcast', 'key' );
if ( ! empty( $un_open_broadcast ) ) {
return $this->get_unopened_broadcast_contacts( $un_open_broadcast, $additional_info );
}
$order = $this->get_sanitized_arg( 'order', 'text_field' );
$order_by = $this->get_sanitized_arg( 'order_by', 'text_field' );
if ( ! empty( $order ) && ! empty( $order_by ) ) {
$additional_info['order'] = $order;
$additional_info['order_by'] = $order_by;
}
if ( class_exists( 'WooCommerce' ) ) {
$additional_info['customer_data'] = $this->get_sanitized_arg( 'get_wc', 'bool' );
}
/** checking if search present in params */
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$filters_collection = empty( $this->args['filters'] ) ? array() : $this->args['filters'];
if ( false === $additional_info['exclude_unsubs'] ) {
$additional_info['exclude_unsubs'] = apply_filters( 'bwfan_force_exclude_unsubscribe_contact', false );
}
$contacts = BWFCRM_Contact::get_contacts( $search, $this->pagination->offset, $this->pagination->limit, $filters_collection, $additional_info );
if ( ! is_array( $contacts ) ) {
$this->response_code = 500;
return $this->error_response( is_string( $contacts ) ? $contacts : __( 'Unknown error occurred', 'wp-marketing-automations-pro' ) );
}
if ( isset( $contacts['total_count'] ) ) {
$this->total_count = absint( $contacts['total_count'] );
}
if ( ! isset( $contacts['contacts'] ) || empty( $contacts['contacts'] ) ) {
return $this->success_response( array() );
}
$this->response_code = 200;
return $this->success_response( $contacts['contacts'] );
}
public function get_result_total_count() {
return $this->total_count;
}
public function get_result_count_data() {
return $this->count_data;
}
public function get_unopened_broadcast_contacts( $broadcast_id, $additional_info ) {
$additional_info['offset'] = $this->pagination->offset;
$additional_info['limit'] = $this->pagination->limit;
$contacts = BWFCRM_Core()->campaigns->get_unopen_broadcast_contacts( absint( $broadcast_id ), $additional_info, );
if ( ! is_array( $contacts ) ) {
$this->response_code = 500;
return $this->error_response( is_string( $contacts ) ? $contacts : __( 'Unknown error occurred', 'wp-marketing-automations-pro' ) );
}
if ( isset( $contacts['total_count'] ) ) {
$this->total_count = absint( $contacts['total_count'] );
}
if ( ! isset( $contacts['contacts'] ) || empty( $contacts['contacts'] ) ) {
return $this->success_response( array() );
}
$this->response_code = 200;
return $this->success_response( $contacts['contacts'] );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contacts' );

View File

@@ -0,0 +1,75 @@
<?php
class BWFCRM_API_Get_Indexing_Status extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/indexing';
}
public function default_args_values() {
return array(
'search' => '',
'filters' => array(),
);
}
public function process_api_call() {
/** Indexing status */
$status = BWFCRM_WC_Importer::get_indexing_status();
if ( ! empty( $status ) || BWFCRM_WC_Importer::$INDEXING_COMPLETE === $status ) {
return $this->success_response( array(
'indexing_required' => true,
'indexing_status' => $status
) );
}
/** checking if search present in params **/
$search = $this->get_sanitized_arg( 'search', 'text_field' );
$filters_collection = empty( $this->args['filters'] ) ? array() : $this->args['filters'];
$get_wc_data = $this->get_sanitized_arg( 'get_wc', 'bool' );
$grab_totals = $this->get_sanitized_arg( 'grab_totals', 'bool' );
$additional_info = class_exists( 'WooCommerce' ) ? [
'customer_data' => $get_wc_data,
'grab_totals' => $grab_totals
] : [];
$filters = $this->get_sanitized_arg( '', 'text_field', $filters_collection );
$contacts = BWFCRM_Contact::get_contacts( $search, $this->pagination->offset, $this->pagination->limit, $filters, $additional_info );
if ( ! is_array( $contacts ) ) {
$this->response_code = 500;
return $this->error_response( is_string( $contacts ) ? $contacts : __( 'Unknown Error', 'wp-marketing-automations-pro' ) );
}
if ( ! isset( $contacts['contacts'] ) || empty( $contacts['contacts'] ) ) {
return $this->success_response( [] );
}
if ( isset( $contacts['total_count'] ) ) {
$this->total_count = absint( $contacts['total_count'] );
}
$this->response_code = 200;
return $this->success_response( $contacts['contacts'] );
}
public function get_result_total_count() {
return $this->total_count;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Indexing_Status' );

View File

@@ -0,0 +1,77 @@
<?php
class BWFCRM_API_Remove_Lists extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/lists';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'lists' => '',
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
$lists = $this->get_sanitized_arg( '', 'key', $this->args['lists'] );
/** No Lists Provided */
if ( empty( $lists ) ) {
$response = __( 'No Lists provided', 'wp-marketing-automations-pro' );
$this->response_code = 404;
return $this->error_response( $response );
}
/** No Contact found */
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given id #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
/** Check if provided lists ids are valid numbers */
$lists = array_map( 'absint', $lists );
$lists = array_filter( $lists );
if ( empty( absint( $lists ) ) ) {
$this->response_code = 400;
return $this->error_response( __( 'No list found', 'wp-marketing-automations-pro' ) );
}
$removed_lists = $contact->remove_lists( $lists );
$contact->save();
$lists_not_removed = array_diff( $lists, $removed_lists );
if ( count( $lists_not_removed ) === count( $lists ) ) {
$response = __( 'Unable to remove the list', 'wp-marketing-automations-pro' );
$this->response_code = 500;
return $this->error_response( $response );
}
$result = [];
$response = __( 'Lists Unassigned', 'wp-marketing-automations-pro' );
if ( ! empty( $lists_not_removed ) ) {
$removed_lists_text = implode( ', ', $removed_lists );
$response = __( 'Some lists removed: ' . $removed_lists_text, 'wp-marketing-automations-pro' );
}
$result['last_modified'] = $contact->contact->get_last_modified();
return $this->success_response( $result, $response );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Remove_Lists' );

View File

@@ -0,0 +1,96 @@
<?php
class BWFCRM_API_Remove_Tags extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::DELETABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/tags';
$this->request_args = array(
'tags' => array(
'description' => __( 'Tags to remove', 'wp-marketing-automations-pro' ),
'type' => 'array',
),
);
}
public function default_args_values() {
return array(
'contact_id' => 0,
'tags' => '',
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
$tags = $this->get_sanitized_arg( '', 'key', $this->args['tags'] );
/** No Tags Provided */
if ( empty( $tags ) ) {
$response = __( 'No Tags provided', 'wp-marketing-automations-pro' );
$this->response_code = 404;
return $this->error_response( $response );
}
/** No Contact found */
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found with given ID #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
/** If provided tags not array */
if ( ! is_array( $tags ) ) {
if ( is_string( $tags ) && false !== strpos( $tags, ',' ) ) {
$tags = explode( ',', $tags );
} else if ( empty( absint( $tags ) ) ) {
$this->response_code = 400;
return $this->error_response( __( 'No tag found', 'wp-marketing-automations-pro' ) );
} else {
$tags = array( absint( $tags ) );
}
}
/** Check if provided tag ids are valid numbers */
$tags = array_map( 'absint', $tags );
$tags = array_filter( $tags );
if ( empty( absint( $tags ) ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Invalid Tags Provided', 'wp-marketing-automations-pro' ) );
}
$removed_tags = $contact->remove_tags( $tags );
$contact->save();
$tags_not_removed = array_diff( $tags, $removed_tags );
if ( count( $tags_not_removed ) === count( $tags ) ) {
$response = __( 'Unable to remove any tag', 'wp-marketing-automations-pro' );
$this->response_code = 500;
return $this->error_response( $response );
}
$result = [];
$response = __( 'Tag removed', 'wp-marketing-automations-pro' );
if ( ! empty( $tags_not_removed ) ) {
$removed_tags_text = implode( ', ', $removed_tags );
$response = __( 'Some tags removed: ' . $removed_tags_text, 'wp-marketing-automations-pro' );
}
$result['last_modified'] = $contact->contact->get_last_modified();
return $this->success_response( $result, $response );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Remove_Tags' );

View File

@@ -0,0 +1,279 @@
<?php
class BWFCRM_API_SendMessage extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/sendmessage';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID to send message', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function default_args_values() {
return array(
'contact_id' => '',
'title' => '',
'message' => '',
'type' => 'email'
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'text_field' );
$title = $this->get_sanitized_arg( 'title', 'text_field' );
$message = $this->args['message'];
$type = $this->get_sanitized_arg( 'type', 'text_field' );
$contact = new BWFCRM_Contact( absint( $contact_id ) );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 400;
return $this->error_response( __( 'No contact found with given ID #' . $contact_id, 'wp-marketing-automations-pro' ) );
}
/** Check if contacts status is bounced */
if ( 4 === $contact->get_display_status() ) {
$this->response_code = 400;
return $this->error_response( __( 'Contact status is bounced', 'wp-marketing-automations-pro' ) );
}
if ( 'email' === $type && empty( $title ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Title is mandatory', 'wp-marketing-automations-pro' ) );
}
if ( empty( $message ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Message is mandatory', 'wp-marketing-automations-pro' ) );
}
$author_id = get_current_user_id();
$mode = BWFAN_Email_Conversations::$MODE_EMAIL;
switch ( $type ) {
case 'sms':
$mode = BWFAN_Email_Conversations::$MODE_SMS;
break;
case 'whatsapp':
$mode = BWFAN_Email_Conversations::$MODE_WHATSAPP;
break;
}
BWFAN_Merge_Tag_Loader::set_data( array(
'contact_id' => $contact->get_id(),
'contact_mode' => $mode
) );
$message = BWFAN_Common::decode_merge_tags( ( 1 === $mode ? wpautop( $message ) : $message ) );
$template = [
'subject' => ( empty( $title ) ? '' : $title ),
'template' => ( empty( $message ) ? '' : $message )
];
$conversation = BWFCRM_Core()->conversation->create_campaign_conversation( $contact, 0, 0, $author_id, $mode, true, $template );
if ( empty( $conversation['conversation_id'] ) ) {
return $this->error_response( $conversation );
}
if ( class_exists( 'BWFAN_Message' ) ) {
$message_obj = new BWFAN_Message();
$message_obj->set_message( 0, $conversation['conversation_id'], $title, $message );
$message_obj->save();
}
$conversation['template'] = $message;
$conversation['subject'] = $title;
if ( 'sms' === $type ) {
$sent = $this->send_single_sms( $conversation, $contact );
} else if ( 'whatsapp' === $type ) {
$sent = $this->send_single_whatsapp_message( $conversation, $contact );
} else {
$sent = $this->send_single_email( $title, $conversation, $contact );
}
if ( true === $sent ) {
return $this->success_response( [], __( 'Message sent', 'wp-marketing-automations-pro' ) );
}
return $this->error_response( $sent, null, 500 );
}
/**
* @param $title
* @param $conversation
* @param $contact BWFCRM_Contact
*
* @return string|true|null
*/
public function send_single_email( $title, $conversation, $contact ) {
$conversation_id = $conversation['conversation_id'];
$contact_id = $contact->contact->get_id();
$email_subject = BWFCRM_Core()->conversation->prepare_email_subject( $title, $contact_id );
try {
$email_body = BWFCRM_Core()->conversation->prepare_email_body( $conversation['conversation_id'], $contact_id, $conversation['hash_code'], 'rich', $conversation['template'] );
} catch ( Error $e ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $e->getMessage() );
return $e->getMessage();
}
if ( is_wp_error( $email_body ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $email_body->get_error_message() );
return $email_body->get_error_message();
}
$to = $contact->contact->get_email();
if ( ! is_email( $to ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, __( 'No email found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' ) );
return __( 'No email found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' );
}
$global_email_settings = BWFAN_Common::get_global_settings();
$headers = array(
'MIME-Version: 1.0',
'Content-type: text/html;charset=UTF-8'
);
$from = '';
if ( isset( $global_email_settings['bwfan_email_from_name'] ) && ! empty( $global_email_settings['bwfan_email_from_name'] ) ) {
$from = 'From: ' . $global_email_settings['bwfan_email_from_name'];
}
if ( isset( $global_email_settings['bwfan_email_from'] ) && ! empty( $global_email_settings['bwfan_email_from'] ) ) {
$headers[] = $from . ' <' . $global_email_settings['bwfan_email_from'] . '>';
}
if ( isset( $global_email_settings['bwfan_email_reply_to'] ) && ! empty( $global_email_settings['bwfan_email_reply_to'] ) ) {
$headers[] = 'Reply-To: ' . $global_email_settings['bwfan_email_reply_to'];
}
/** Set unsubscribe link in header */
$unsubscribe_link = BWFAN_PRO_Common::get_unsubscribe_link( [ 'uid' => $contact->contact->get_uid() ] );
if ( ! empty( $unsubscribe_link ) ) {
$headers[] = "List-Unsubscribe: <$unsubscribe_link>";
$headers[] = "List-Unsubscribe-Post: List-Unsubscribe=One-Click";
}
BWFCRM_Common::bwf_remove_filter_before_wp_mail();
$headers = apply_filters( 'bwfan_email_headers', $headers );
BWFCRM_Common::$captured_email_failed_message = null;
$result = wp_mail( $to, $email_subject, $email_body, $headers );
if ( true === $result ) {
/** Save the time of last sent engagement **/
$data = array( 'cid' => $contact_id );
BWFCRM_Conversation::save_last_sent_engagement( $data );
BWFCRM_Core()->conversation->update_conversation_status( $conversation_id, BWFAN_Email_Conversations::$STATUS_SEND );
} else {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, __( 'Email not sent', 'wp-marketing-automations-pro' ) );
return __( 'Email not sent', 'wp-marketing-automations-pro' );
}
return $result;
}
public function send_single_sms( $conversation, $contact ) {
$conversation_id = $conversation['conversation_id'];
$contact_id = $contact->contact->get_id();
$sms_body = BWFCRM_Core()->conversation->prepare_sms_body( $conversation['conversation_id'], $contact_id, $conversation['hash_code'], $conversation['template'] );
if ( is_wp_error( $sms_body ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $sms_body->get_error_message() );
return $sms_body->get_error_message();
}
$to = BWFAN_PRO_Common::get_contact_full_number( $contact->contact );
if ( empty( $to ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, __( 'No phone number found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' ) );
return __( 'No phone number found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' );
}
$send_sms_result = BWFCRM_Common::send_sms( array(
'to' => $to,
'body' => $sms_body,
) );
if ( $send_sms_result instanceof WP_Error ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $send_sms_result->get_error_message() );
return $send_sms_result->get_error_message();
}
/** Save the date of last sent engagement **/
$data = array( 'cid' => $contact_id );
BWFCRM_Conversation::save_last_sent_engagement( $data );
BWFCRM_Core()->conversation->update_conversation_status( $conversation_id, BWFAN_Email_Conversations::$STATUS_SEND );
return true;
}
public function send_single_whatsapp_message( $conversation, $contact ) {
$conversation_id = $conversation['conversation_id'];
$contact_id = $contact->contact->get_id();
$message_body = BWFCRM_Core()->conversation->prepare_sms_body( $conversation['conversation_id'], $contact_id, $conversation['hash_code'], $conversation['template'] );
if ( is_wp_error( $message_body ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $message_body->get_error_message() );
return $message_body->get_error_message();
}
$to = BWFAN_PRO_Common::get_contact_full_number( $contact->contact );
if ( empty( $to ) ) {
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, __( 'No phone number found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' ) );
return __( 'No phone number found for this contact: ' . $contact_id, 'wp-marketing-automations-pro' );
}
$response = BWFCRM_Core()->conversation->send_whatsapp_message( $to, array(
array(
'type' => 'text',
'data' => $message_body,
)
) );
if ( $response['status'] == true ) {
/** Save the time of last sent engagement **/
$data = array( 'cid' => $contact_id );
BWFCRM_Conversation::save_last_sent_engagement( $data );
BWFCRM_Core()->conversation->update_conversation_status( $conversation_id, BWFAN_Email_Conversations::$STATUS_SEND );
return true;
}
$error_message = isset( $response['msg'] ) && ! empty( $response['msg'] ) ? $response['msg'] : 'Unable to send message';
BWFCRM_Core()->conversation->fail_the_conversation( $conversation_id, $error_message );
return $error_message;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_SendMessage' );

View File

@@ -0,0 +1,71 @@
<?php
class BWFCRM_API_Update_Contact_Note extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/notes/(?P<note_id>[\\d]+)';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'note_id' => 0,
'notes' => array(),
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$note_id = $this->get_sanitized_arg( 'note_id', 'key' );
if ( empty( $note_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Note ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$notes = $this->args['notes'];
if ( empty( $notes ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Notes are mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$note_updated = $contact->update_contact_note( $notes, $note_id );
if ( false === $note_updated || is_wp_error( $note_updated ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Unable to update note of contact', 'wp-marketing-automations-pro' ) );
}
$this->response_code = 200;
return $this->success_response( [], __( 'Contact note updated', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Update_Contact_Note' );

View File

@@ -0,0 +1,124 @@
<?php
class BWFCRM_API_Update_Contact extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::EDITABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)';
}
public function default_args_values() {
return array(
'contact_id' => 0,
'first_name' => '',
'last_name' => '',
'meta' => [],
'lists' => [],
'tags' => [],
);
}
public function process_api_call() {
$contact_id = $this->get_sanitized_arg( 'contact_id', 'key' );
if ( empty( $contact_id ) ) {
$this->response_code = 404;
return $this->error_response( __( 'Contact ID is mandatory', 'wp-marketing-automations-pro' ) );
}
$contact = new BWFCRM_Contact( $contact_id );
if ( ! $contact->is_contact_exists() ) {
$this->response_code = 404;
return $this->error_response( __( 'No contact found related with contact id :' . $contact_id, 'wp-marketing-automations-pro' ) );
}
$contact_basic_info = array();
$contact_first_name = $this->get_sanitized_arg( 'first_name', 'text_field' );
$contact_last_name = $this->get_sanitized_arg( 'last_name', 'text_field' );
$contact_email = $this->get_sanitized_arg( 'email', 'text_field' );
if ( ! empty( $contact_first_name ) ) {
$contact_basic_info['first_name'] = $contact_first_name;
}
if ( ! empty( $contact_last_name ) ) {
$contact_basic_info['last_name'] = $contact_last_name;
}
if ( ! empty( $contact_email ) ) {
$contact_basic_info['email'] = $contact_email;
}
if ( ! empty( $this->args['meta'] ) && is_array( $this->args['meta'] ) ) {
$contact_basic_info['meta'] = $this->args['meta'];
}
if ( empty( $contact_basic_info ) && empty( $this->args['lists'] ) && empty( $this->args['tags'] ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Unable to update contact as update data missing', 'wp-marketing-automations-pro' ) );
}
if ( ! empty( $contact_basic_info ) ) {
$contact_basic_info['id'] = $contact_id;
/** @var $update_contact_details */
$contact_field_updated = $contact->update( $contact_basic_info );
}
if ( ! empty( $this->args['lists'] ) && is_array( $this->args['lists'] ) ) {
$lists = $this->args['lists'];
$added_lists = $contact->set_lists( $lists );
$lists_added = array_map( function ( $list ) {
return $list->get_array();
}, $added_lists );
}
if ( ! empty( $this->args['tags'] ) && is_array( $this->args['tags'] ) ) {
$tags = $this->args['tags'];
$added_tags = $contact->set_tags( $tags );
$tags_added = array_map( function ( $tags ) {
return $tags->get_array();
}, $added_tags );
}
$contact->save();
if ( false === $contact_field_updated && empty( $added_lists ) && empty( $added_tags ) ) {
$this->response_code = 200;
return $this->error_response( __( 'Unable to update contact fields', 'wp-marketing-automations-pro' ) );
}
$result = [];
if ( ! empty( $contact_field_updated ) ) {
$result['contact'] = $contact_field_updated;
}
if ( ! empty( $lists_added ) ) {
$result['lists'] = $lists_added;
}
if ( ! empty( $tags_added ) ) {
$result['tags'] = $tags_added;
}
return $this->success_response( $result, __( 'Contact updated', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Update_Contact' );

View File

@@ -0,0 +1,60 @@
<?php
class BWFCRM_API_Get_Contact_Conversation extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/engagement/(?P<engagement_id>[\\d]+)';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
'engagement_id' => array(
'description' => __( 'Engagement ID', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function default_args_values() {
return array(
'contact_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params */
$id = $this->get_sanitized_arg( 'contact_id', 'key' );
$engagement_id = $this->get_sanitized_arg( 'engagement_id', 'key' );
if ( ! class_exists( 'BWFAN_Email_Conversations' ) || ! isset( BWFAN_Core()->conversations ) || ! BWFAN_Core()->conversations instanceof BWFAN_Email_Conversations ) {
return $this->error_response( __( 'Unable to find Funnelkit Automations message tracking module', 'wp-marketing-automations-pro' ), null, 500 );
}
$this->contact = new BWFCRM_Contact( absint( $id ) );
if ( ! $this->contact instanceof BWFCRM_Contact || ! $this->contact->is_contact_exists() ) {
return $this->error_response( __( 'No contact found with given ID #' . $id, 'wp-marketing-automations-pro' ), null, 500 );
}
$conversation = $this->contact->get_conversation_email( $engagement_id );
if ( $conversation instanceof WP_Error || ( is_array( $conversation ) && isset( $conversation['error'] ) ) ) {
return $this->error_response( ! is_array( $conversation ) ? __( 'Unknown error occurred', 'wp-marketing-automations-pro' ) : $conversation['error'], $conversation instanceof WP_Error ? $conversation : null, 500 );
}
return $this->success_response( $conversation );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Conversation' );

View File

@@ -0,0 +1,65 @@
<?php
class BWFCRM_API_Get_Contact_Conversations extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $contact;
public $mode = null;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/contacts/(?P<contact_id>[\\d]+)/engagements';
$this->request_args = array(
'contact_id' => array(
'description' => __( 'Contact ID for which engagements to retrieve', 'wp-marketing-automations-pro' ),
'type' => 'integer',
),
);
}
public function default_args_values() {
return array(
'contact_id' => 0,
'mode' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$id = $this->get_sanitized_arg( 'contact_id', 'key' );
$this->mode = $this->get_sanitized_arg( 'mode', 'key' );
$limit = ! empty( $this->get_sanitized_arg( 'limit', 'text_field' ) ) ? $this->get_sanitized_arg( 'limit', 'text_field' ) : 25;
$offset = ! empty( $this->get_sanitized_arg( 'offset', 'text_field' ) ) ? $this->get_sanitized_arg( 'offset', 'text_field' ) : 0;
if ( ! class_exists( 'BWFAN_Email_Conversations' ) || ! isset( BWFAN_Core()->conversations ) || ! BWFAN_Core()->conversations instanceof BWFAN_Email_Conversations ) {
return $this->error_response( __( 'Unable to find conversations module', 'wp-marketing-automations-pro' ), null, 500 );
}
$this->contact = new BWFCRM_Contact( absint( $id ) );
if ( ! $this->contact instanceof BWFCRM_Contact || ! $this->contact->is_contact_exists() ) {
return $this->error_response( __( 'Contact doesn\'t exists', 'wp-marketing-automations-pro' ), null, 500 );
}
$conversation = $this->contact->get_conversations( $this->mode, $offset, $limit );
if ( $conversation instanceof WP_Error ) {
return $this->error_response( '', $conversation, 500 );
}
return $this->success_response( $conversation );
}
public function get_result_total_count() {
return $this->contact instanceof BWFCRM_Contact && $this->contact->is_contact_exists() ? $this->contact->get_conversations_total( $this->mode ) : 0;
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Contact_Conversations' );

View File

@@ -0,0 +1,29 @@
<?php
class BWFCRM_API_Get_Message_Daily_Limit extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/messages/daily-limit';
}
public function process_api_call() {
$daily_limit = BWFCRM_Core()->campaigns->get_daily_limit_status_array();
return $this->success_response( $daily_limit );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Message_Daily_Limit' );

View File

@@ -0,0 +1,50 @@
<?php
class BWFCRM_API_Get_Conversation_Template extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public $contact;
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::READABLE;
$this->route = '/templates/(?P<template_id>[\\d]+)';
$this->request_args = array(
'template_id' => array(
'description' => __( 'Template ID', 'wp-marketing-automations-pro' ),
'type' => 'integer',
)
);
}
public function default_args_values() {
return array(
'template_id' => 0,
);
}
public function process_api_call() {
/** checking if id or email present in params **/
$template_id = $this->get_sanitized_arg( 'template_id', 'key' );
if ( empty( $template_id ) ) {
return $this->error_response( __( 'Invalid template ID provided', 'wp-marketing-automations-pro' ), null, 400 );
}
$template = BWFCRM_Core()->conversation->get_conversation_template_array( $template_id );
if ( ! is_array( $template ) || empty( $template ) ) {
return $this->error_response( __( 'Template doesn\'t exists', 'wp-marketing-automations-pro' ), null, 500 );
}
return $this->success_response( $template );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Get_Conversation_Template' );

View File

@@ -0,0 +1,76 @@
<?php
/**
* Test Mail API file
*
* @package BWFCRM_API_Base
*/
/**
* Test Mail API class
*/
class BWFCRM_API_Send_Test_Mail extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/send-test-email';
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'email' => '',
'content' => 0
);
}
/**
* API callback
*/
public function process_api_call() {
$content = isset( $this->args['content'] ) ? $this->args['content'] : [];
$content = BWFAN_Common::is_json( $content ) ? json_decode( $content, true ) : $content;
if ( empty( $content ) ) {
return $this->error_response( __( 'No content data found', 'wp-marketing-automations-pro' ) );
}
if ( isset( $content['mail_data'] ) && is_array( $content['mail_data'] ) ) {
$mail_data = $content['mail_data'];
unset( $content['mail_data'] );
$content = array_replace( $content, $mail_data );
}
$content['email'] = $this->get_sanitized_arg( 'email', 'text_field' );
if ( BWFAN_Common::send_test_email( $content ) ) {
return $this->success_response( '', 'Test Email Sent' );
}
return $this->error_response( 'Unable to send test email', null, 500 );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Send_Test_Mail' );

View File

@@ -0,0 +1,89 @@
<?php
/**
* Test SMS API file
*
* @package BWFCRM_API_Base
*/
/**
* Test Mail API class
*/
class BWFCRM_API_Send_Test_SMS extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/send-test-sms';
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'phone' => '',
'sms_body' => '',
);
}
/**
* API callback
*/
public function process_api_call() {
if ( ! isset( $this->args ) || empty( $this->args ) || ! is_array( $this->args ) ) {
return $this->error_response( __( 'No data found', 'wp-marketing-automations-pro' ) );
}
$phone = $this->args['phone'];
if ( empty( $phone ) ) {
return $this->error_response( __( 'Phone no is required.', 'wp-marketing-automations-pro' ), null, 400 );
}
$sms_body = $this->args['sms_body'];
if ( empty( $sms_body ) ) {
return $this->error_response( __( 'SMS body is required.', 'wp-marketing-automations-pro' ), null, 400 );
}
BWFAN_Merge_Tag_Loader::set_data( array(
'is_preview' => true,
) );
$sms_body = BWFAN_Common::decode_merge_tags( $sms_body );
/** Append UTM parameters */
$sms_body = BWFAN_PRO_Common::add_test_broadcast_utm_params( $sms_body, $this->args['sms_data'], 'sms' );
$send_sms_result = BWFCRM_Common::send_sms( array(
'to' => $phone,
'body' => $sms_body,
'is_test' => true
) );
if ( $send_sms_result instanceof WP_Error ) {
return $this->error_response( 'Unable to send test sms. Error: ' . $send_sms_result->get_error_message(), null, 500 );
}
return $this->success_response( '', 'Test SMS Sent' );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Send_Test_SMS' );

View File

@@ -0,0 +1,115 @@
<?php
/**
* Test WhatsApp Message API file
*
* @package BWFCRM_API_Base
*/
/**
* Test WhatsApp API class
*/
class BWFCRM_API_Send_Test_WhatsApp_Message extends BWFCRM_API_Base {
/**
* BWFCRM_Core obj
*
* @var BWFCRM_Core
*/
public static $ins;
/**
* Return class instance
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
/**
* Class constructor
*/
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/send-test-whatsapp-message';
}
/**
* Default arg.
*/
public function default_args_values() {
return array(
'phone' => '',
'sms_body' => ''
);
}
/**
* API callback
*/
public function process_api_call() {
if ( ! isset( $this->args ) || empty( $this->args ) || ! is_array( $this->args ) ) {
return $this->error_response( __( 'No data found', 'wp-marketing-automations-pro' ) );
}
$phone = $this->args['phone'];
if ( empty( $phone ) ) {
return $this->error_response( __( 'Phone no is required.', 'wp-marketing-automations-pro' ), null, 400 );
}
$sms_body = $this->args['sms_body'];
if ( empty( $sms_body ) ) {
return $this->error_response( __( 'SMS body is required.', 'wp-marketing-automations-pro' ), null, 400 );
}
$data = [];
$imagedata = [];
$first = false;
if ( ! empty( $sms_body ) ) {
if ( isset( $sms_body['body'] ) && ! empty( $sms_body ) ) {
/** Decode Merge Tags for Preview */
BWFAN_Merge_Tag_Loader::set_data( array(
'is_preview' => true,
) );
$sms_body['body'] = BWFAN_Common::decode_merge_tags( $sms_body['body'] );
$data = array(
'type' => 'text',
'data' => $sms_body['body'],
);
}
if ( isset( $sms_body['whatsAppImage'] ) && $sms_body['whatsAppImage'] && isset( $sms_body['whatsAppImageSetting'] ) && isset( $sms_body['whatsAppImageSetting']['imageURL'] ) && ! empty( $sms_body['whatsAppImageSetting']['imageURL'] ) ) {
$imagedata = array(
'type' => 'image',
'data' => $sms_body['whatsAppImageSetting']['imageURL'],
);
if ( isset( $sms_body['whatsAppImageSetting']['position'] ) && ! empty( $sms_body['whatsAppImageSetting']['position'] ) && $sms_body['whatsAppImageSetting']['position'] != 'after' ) {
$first = true;
}
}
}
$finalData = [];
if ( ! empty( $imagedata ) ) {
if ( $first ) {
$finalData = [ $imagedata, $data ];
} else {
$finalData = [ $data, $imagedata ];
}
} else {
$finalData[] = $data;
}
$response = BWFCRM_Core()->conversation->send_whatsapp_message( $phone, $finalData );
if ( $response['status'] == true ) {
return $this->success_response( '', 'Test Message Sent' );
}
return $this->error_response( isset( $response['msg'] ) && ! empty( $response['msg'] ) ? $response['msg'] : 'Unable to send test message', null, 500 );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Send_Test_WhatsApp_Message' );

View File

@@ -0,0 +1,37 @@
<?php
class BWFCRM_API_Upload_Image extends BWFCRM_API_Base {
public static $ins;
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function __construct() {
parent::__construct();
$this->method = WP_REST_Server::CREATABLE;
$this->route = '/upload-image';
}
public function process_api_call() {
$files = $this->args['files'];
if ( empty( $files ) || ! is_array( $files['image'] ) || ! is_uploaded_file( $files['image']['tmp_name'] ) ) {
$this->response_code = 400;
return $this->error_response( __( 'Not any image file found for import', 'wp-marketing-automations-pro' ), null, 400 );
}
$url = BWFCRM_Core()->email_editor->upload_media( $files['image'] );
if ( empty( $url ) || is_wp_error( $url ) ) {
return $this->error_response( __( 'Unable to upload image file', 'wp-marketing-automations-pro' ), null, 500 );
}
return $this->success_response( $url, __( 'Headers Data', 'wp-marketing-automations-pro' ) );
}
}
BWFCRM_API_Loader::register( 'BWFCRM_API_Upload_Image' );

Some files were not shown because too many files have changed in this diff Show More