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,152 @@
.bwf-c-product-modal-image {
width: 50px;
height: auto;
}
.bwf-c-product-modal-row {
display: flex;
align-items: center;
}
.bwf-c-product-modal-row .bwf-c-product-modal-row-info {
margin-left: 15px;
display: flex;
flex-direction: column;
}
.bwf-c-product-modal-row .bwf-c-product-modal-row-info .bwf-c-product-id {
color: #aaa;
font-size: 12px;
}
table.bwf-c-product-modal-table {
width: 100%;
border-collapse: collapse;
border-spacing: 0 1em;
}
table.bwf-c-product-modal-table .bwf-tag-label {
font-size: 15px;
font-weight: 600;
display: block;
}
table.bwf-c-product-modal-table .bwf-tag-slug {
font-size: 12px;
font-weight: 400;
display: block;
margin-top: 4px;
}
table.bwf-c-product-modal-table .bwf-tag-item-select {
line-height: 45px;
padding: 8px 20px;
background: #007cba;
border-width: 0;
color: #fff;
text-decoration: none;
border-radius: 20px;
cursor: pointer;
}
table.bwf-c-product-modal-table .bwf-button-cell {
text-align: right;
}
table.bwf-c-product-modal-table tr {
border-bottom: 1px solid #eee;
}
table.bwf-c-product-modal-table tr td {
padding: 10px;
}
.bwf-spin-loader {
width: 1.5em;
height: 1.5em;
border: 0.25em solid transparent;
border-radius: 100%;
background-color: transparent !important;
-webkit-animation: bwf-rotate-loading 1.5s linear 0s infinite normal;
animation: bwf-rotate-loading 1.5s linear 0s infinite normal;
border-left-color: #444;
border-right-color: #444;
}
.bwf-spin-loader.bwf-spin-loader-xl {
width: 3em;
height: 3em;
border-width: 0.4em;
}
.bwf-t-center {
text-align: center;
}
.bwf-t-center .bwf-spin-loader {
margin: 0 auto;
}
@-webkit-keyframes bwf-rotate-loading {
0% {
-webkit-transform: rotate(0);
transform: rotate(0);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes bwf-rotate-loading {
0% {
-webkit-transform: rotate(0);
transform: rotate(0);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
.bwf-c-product-modal-pagination .bwf-pagination-page-arrows {
display: flex;
align-items: center;
justify-content: center;
margin-top: 15px;
}
.bwf-c-product-modal-pagination .bwf-pagination-page-arrows-buttons {
margin-left: 10px;
}
.bwf-c-product-modal-pagination .bwf-pagination-link {
width: 32px;
height: 30px;
padding: 0;
cursor: pointer;
}
.bwf-c-product-modal-pagination .bwf-pagination-link:disabled {
cursor: initial;
}
table.bwf-c-product-modal-table .bwf-placeholder-loader {
animation: loading-fade 1.6s ease-in-out infinite;
background-color: #f0f0f0;
color: transparent;
display: inline-block;
height: 16px;
width: 120px;
margin: 0;
}
table.bwf-c-product-modal-table .bwf-placeholder-loader.is-image {
height: 50px;
width: 50px;
}
@keyframes loading-fade {
0% {
opacity: 0.7;
}
50% {
opacity: 1;
}
100% {
opacity: 0.7;
}
}

View File

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

View File

@@ -0,0 +1,486 @@
(function ($) {
class BWFAN_Email_Editor {
formatAmount = null;
productToolEvent = null;
constructor() {
this.registerEvents();
this.initIziModals();
this.token = bwfan_automation_drag_drop.token;
this.initCurrency();
this.initProductToolModal();
}
initCurrency() {
if( typeof wc == 'undefined' || !wc || !wc.currency || !bwfan_automation_drag_drop.currency ) {
return;
}
this.formatAmount = wc.currency.default(bwfan_automation_drag_drop.currency).formatAmount;
}
initIziModals() {
var that = this;
/** iziModal Action For Single Autonami */
if ($('#modal-autonami-product-tool').length > 0) {
$('#modal-autonami-product-tool').iziModal({
width: 786,
radius: 5,
padding: 0,
background: 'rgb(255, 255, 255)',
overlayColor: 'rgba(0, 0, 0, 0.6)',
zindex: 9999999,
transitionIn: 'none',
onOpening: function () {
that.renderProductToolModal();
}
});
}
}
registerEvents() {
const self = this;
this.registerListeners();
const body = $('body');
body.on('click', '#bwf-launch-editor-modal', (e) => {
self.openModal();
e.preventDefault();
});
}
getCurrentDesign() {
const design = $('#bwfan-editor-design').val();
return !!design ? design : '';
}
setDesign(body, json = '') {
!!json && $('#bwfan-editor-design').val(json);
!!body && $('#bwfan-editor-body').val(body);
}
closeModal() {
$('body').removeClass('bwf-c-modal-open');
$('#bwf-modal-editor').removeClass('active');
$('#bwf_email_editor_frame').remove();
}
openModal() {
$('body').addClass('bwf-c-modal-open');
$('#bwf-modal-editor').addClass('active');
const iframeSrc = bwfan_automation_drag_drop.iframe_src.replace(/([^:]\/)\/+/g, "$1");
$('#bwf-modal-editor-inner').append('<iframe style="width:100%;height:100%" src="'+iframeSrc+'" id="bwf_email_editor_frame" ></iframe>');
setTimeout(function () {
$('#bwf-c-editor-modal-close').show();
$('#bwf-c-editor-modal-merge-tags').show();
}, 1000);
}
openMergeTagsModal() {
$('#modal-show-merge-tags').iziModal('open');
}
openLinkTriggerModal() {
$('#modal-autonami-link-trigger-selector').iziModal('open');
}
registerListeners() {
const self = this;
window.addEventListener('message', function (event) {
if (
-1 === event.origin.indexOf('app.getautonami.com') ||
!event.data ||
!event.data.action ||
event.data.token !== self.token
) {
return;
}
switch (event.data.action) {
case 'get_design':
self.getDesignListener(event);
break;
case 'save_design':
self.saveDesignListener(event);
break;
case 'send_test_email':
self.sendTestEmailListener(event);
break;
case 'wp_image_upload':
self.getWPMediaURL(event);
break;
case 'open_merge_tags':
self.openMergeTagsModal();
break;
case 'open_link_trigger':
self.openLinkTriggerModal();
break;
case 'close_editor':
self.closeModal();
break;
case 'select_product_for_tool':
self.productToolEvent = event;
self.selectProduct();
break;
}
});
}
getDesignListener(event) {
const jsonContent = this.getCurrentDesign();
this.sendPostMessage('get_design', {
gotDesign: true,
json: jsonContent,
subject: '',
mergeTags: {},
enableLinkTrigger: true,
}, event.origin);
}
saveDesignListener(event) {
/** Check for required data to send test email */
const {body, design} = event.data.data;
if (!body || !design) {
return;
}
this.setDesign(body, design);
this.saveAutomation();
this.sendPostMessage('save_design', {
isSaved: true,
}, event.origin);
}
saveAutomation() {
$('.wr_tw_save .wr-form-btn').trigger('click');
}
sendPostMessage(action, data, origin) {
const iframe = document.getElementById('bwf_email_editor_frame');
!!iframe && iframe.contentWindow.postMessage(
{
token: this.token,
action,
data,
},
origin
);
}
sendTestEmailListener(event) {
/** Check for required data to send test email */
const {email, body, design} = event.data.data;
if (!email || !body || !design) {
return;
}
this.setDesign(body, design);
this.sendTestEmail(email, event.origin);
}
sendTestEmail(email, origin) {
const self = this;
if ('' === email) {
return;
}
let form_data = $(
'#bwfan-actions-form-container'
).bwfan_serializeAndEncode();
form_data = bwfan_deserialize_obj(form_data);
const group_id = $('.bwfan-selected-action').attr(
'data-group-id'
);
const data_to_send = form_data.bwfan[group_id];
data_to_send.source = BWFAN_Auto.uiDataDetail.trigger.source;
data_to_send.event = BWFAN_Auto.uiDataDetail.trigger.event;
data_to_send._wpnonce = bwfanParams.ajax_nonce;
data_to_send.automation_id =
bwfan_automation_data.automation_id;
data_to_send.email = email;
const ajax = new bwf_ajax();
ajax.ajax('test_email', data_to_send);
ajax.success = (resp) => {
if (resp.status == true) {
self.sendPostMessage('send_test_email', {
isSent: true,
showSnackbar: true
}, origin);
} else {
self.sendPostMessage('send_test_email', {
isSent: false,
showSnackbar: true
}, origin);
}
};
}
getWPMediaURL(event) {
const self = this;
if (!wp || !wp.media) {
return '';
}
if (this.mediaLib) {
this.mediaLib.open();
return;
}
this.mediaLib = wp.media({
title: 'Select or Upload Media',
button: {
text: 'Select Image',
},
multiple: false,
});
this.mediaLib.on('select', function () {
// Get media attachment details from the frame state
const attachment = self.mediaLib
.state()
.get('selection')
.first()
.toJSON();
self.sendPostMessage('wp_image_upload', {
isUploaded: true,
imageURL: attachment.url,
}, event.origin);
});
// Finally, open the modal on click
this.mediaLib.open();
};
//async uploadImageListener(event) {
// const {image} = event.data.data;
// if (!image) {
// return;
// }
//
// const formData = new FormData();
// formData.append('image', image);
//
// const response = await window.fetch('<?php //echo rest_url( '/autonami-admin/upload-image' ) ?>//', {
// headers: {
// 'X-WP-Nonce': wpApiSettings.nonce
// },
// method: 'POST',
// body: formData
// });
//
// const jsonResult = await response.json();
// if (parseInt(jsonResult.code) === 200 && !!jsonResult.result) {
// this.sendPostMessage('upload_media', {
// isUploaded: true,
// imageURL: jsonResult.result,
// }, event.origin);
// }
//
// this.sendPostMessage('upload_media', {
// isUploaded: false,
// imageURL: '',
// }, event.origin);
//}
selectProduct() {
$('#modal-autonami-product-tool').iziModal('open');
}
onProductSelect( product ) {
this.sendPostMessage('select_product_for_tool', {
product: {
...product,
formattedPrice: this.formatAmount( product.price ),
},
}, this.productToolEvent.origin);
$('#modal-autonami-product-tool').iziModal('close');
}
initProductToolModal() {
let search = '';
let limit = 10;
let offset = 0;
const that = this;
/** Pagination Clicks */
$(document).on('click', '#bwf-c-product-modal-prev', function() {
offset = offset - limit;
that.renderProductToolModal( search, limit, offset );
});
$('body').on('click', '#bwf-c-product-modal-next', function() {
offset = offset + limit;
that.renderProductToolModal( search, limit, offset );
});
/** Search event */
const debouncedSearch = _.debounce(function() {
that.renderProductToolModal( search, limit, offset );
}, 700);
$(document).on('input', '#bwf-c-product-tool-search input', function(e) {
search = e.target.value;
debouncedSearch();
});
/** On select */
$(document).on('click', '#bwf-c-product-tool-select', function(e) {
let productData = $(this).data('product');
productData = JSON.parse( decodeURIComponent( productData ) );
that.onProductSelect( productData );
});
}
renderProductsLoading() {
let html = `<table class="bwf-c-product-modal-table"><tbody>`;
Array.from( Array( 10 ).keys() ).map( ( product, index ) => {
html += `<tr>
<td>
<div class="bwf-c-product-modal-row">
<p class="bwf-placeholder-loader is-image"></p>
<div class="bwf-c-product-modal-row-info">
<span class="bwf-tag-label">
<p class="bwf-placeholder-loader" style="width: 70px;"></p>
</span>
<span class="bwf-tag-slug">
<p class="bwf-placeholder-loader" style="height: 10px;"></p>
</span>
</div>
</div>
</td>
<td class="bwf-button-cell">
<p class="bwf-placeholder-loader" style="height: 32px; width: 80px;"></p>
</td>
</tr>`;
} );
html += `</tbody></table>`;
$('#modal-autonami-product-tool-content').html(html);
}
async renderProductToolModal( search = '', limit = 10, offset = 0 ) {
this.renderProductsLoading();
const data = await this.getProducts( search, limit, offset );
if( !! data && !! data.error ) {
return `<div>${ data.error }</div>`;
}
const { products, totalCount } = data;
const html = await this.getProductsHTML( products );
const pagination = this.getProductsPaginationHTML( limit, offset, totalCount );
$('#modal-autonami-product-tool-content').html( html + pagination );
}
getProductsPaginationHTML( limit = 10, offset = 0, total = 0 ) {
const page = ( offset / limit ) + 1;
const totalPages = Math.ceil( total / limit );
const nextPossible = ( totalPages - page ) > 0;
const prevPossible = page > 1;
const html = `<div class="bwf-c-product-modal-pagination">
<div class="bwf-pagination-page-arrows">
<span class="bwf-pagination-page-arrows-label" role="status" aria-live="polite">Page ${ page } of ${ totalPages }</span>
<div class="bwf-pagination-page-arrows-buttons">
<button type="button" ${ ! prevPossible && 'disabled=""' } class="components-button bwf-pagination-link" aria-label="Previous Page" id="bwf-c-product-modal-prev">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" role="img" aria-hidden="true" focusable="false">
<path d="M14.6 7l-1.2-1L8 12l5.4 6 1.2-1-4.6-5z"></path>
</svg>
</button>
<button type="button" ${ ! nextPossible && 'disabled=""' } class="components-button bwf-pagination-link is-active" aria-label="Next Page" id="bwf-c-product-modal-next">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" role="img" aria-hidden="true" focusable="false">
<path d="M10.6 6L9.4 7l4.6 5-4.6 5 1.2 1 5.4-6z"></path>
</svg>
</button>
</div>
</div>
</div>`;
return html;
}
async getProductsHTML( products = [] ) {
let html = `<table class="bwf-c-product-modal-table"><tbody>`;
products.map( ( product, index ) => {
const price = `Price: ${ this.formatAmount( product.price ) }`;
const stockQuantity = !! product.stock_quantity && `Stock: ${ product.stock_quantity }`;
const stockStatus = product.stock_status;
const description = [ price, stockQuantity, stockStatus ]
.filter( Boolean )
.join( ' | ' );
const image = Array.isArray( product.images ) && product.images[ 0 ] ? product.images[ 0 ].src : ''
const imageHTML = !!image ? `<img class="bwf-c-product-modal-image" src='${image}' />` : '';
html += `<tr>
<td>
<div class="bwf-c-product-modal-row">
${imageHTML}
<div class="bwf-c-product-modal-row-info">
<span class="bwf-tag-label">
${ product.name }${ ' ' }
<span class="bwf-c-product-id">
#${ product.id }
</span>
</span>
<span class="bwf-tag-slug">
${ description }
</span>
</div>
</div>
</td>
<td class="bwf-button-cell">
<span id="bwf-c-product-tool-select" data-product="${ encodeURIComponent( JSON.stringify(product) ) }" class="bwf-tag-item-select">Select</span>
</td>
</tr>`;
} );
html += `</tbody></table>`;
return html;
}
async getProducts( search = '', limit = 10, offset = 0 ) {
const query = {
search,
per_page: limit,
page: parseInt( offset / limit ) + 1,
orderby: 'popularity',
};
let response = '';
try {
response = await wp.apiFetch( {
path: wp.url.addQueryArgs( '/wc-analytics/products', query ),
parse: false,
} );
} catch ( error ) {
return { error };
}
return {
products: await response.json(),
totalCount: parseInt( response.headers.get( 'x-wp-total' ), 10 ),
};
}
}
new BWFAN_Email_Editor();
})(jQuery);

View File

@@ -0,0 +1,49 @@
( function ( $ ) {
$( document ).ready( function () {
const adminSearchBar = $( '#bwfan-admin-bar-search' );
adminSearchBar.on( 'keyup', function () {
let value = $( this ).val();
if ( value ) {
fetch(
bwfanProObj.siteUrl+'/wp-json/' + bwfanProObj.apiNamespace + '/contacts?search=' +
value +
'&limit=5&offset=0',
{
credentials: 'include',
headers: {
'content-type': 'application/json',
'X-WP-Nonce': wpApiSettings.nonce,
},
}
)
.then( ( response ) => response.json() )
.then( function ( result ) {
if ( result.code == 200 ) {
let res = result.result;
let template = '';
if ( res.length > 0 ) {
res.map( function ( contact ) {
if (
contact.hasOwnProperty( 'email' ) &&
contact.hasOwnProperty( 'id' )
) {
template +=
'<a class="bwf-contact-suggestion" target="_blank" href="'+bwfanProObj.siteUrl+'/wp-admin/admin.php?page=autonami&path=/contact/' +
contact.id +
'">' +
contact.email +
'</a>';
}
} );
} else {
template = '<span class="label">No contacts found</span>';
}
$( '#bwf-contact-list-suggestion-list' ).html(
template
);
}
} );
}
} );
} );
} )( jQuery );

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@@ -0,0 +1,228 @@
<?php
#[AllowDynamicProperties]
class BWFAN_Pro_Admin {
private static $ins = null;
public $admin_path;
public $admin_url;
private function __construct() {
$this->admin_path = BWFAN_PRO_PLUGIN_DIR . '/admin';
$this->admin_url = BWFAN_PRO_PLUGIN_URL . '/admin';
add_action( 'bwfan_wp_sendemail_setting_html', [ $this, 'utm_fields' ] );
add_filter( 'bwfan_automation_global_js_data', [ $this, 'language_settings' ] );
add_action( 'admin_head', [ $this, 'spinner_gif' ] );
add_action( 'admin_bar_menu', [ $this, 'bwfan_pro_add_menu_in_admin_bar' ], 9999, 1 );
}
public static function get_instance() {
if ( is_null( self::$ins ) ) {
self::$ins = new self();
}
return self::$ins;
}
public function utm_fields( $event ) {
include __DIR__ . '/views/utm_fields.php';
}
/**
* adding language options in case any of the language plugin like wpml, polylang,translatepress activated
*/
public function language_settings( $settings ) {
return BWFAN_PRO_Common::get_language_settings( $settings );
}
public function spinner_gif() {
ob_start();
?>
<style>
.bwfan_btn_spin_blue {
opacity: 1 !important;
position: relative;
color: rgba(0, 163, 161, .05) !important;
pointer-events: none !important;
}
.bwfan_btn_spin_blue::-moz-selection {
color: rgba(0, 163, 161, .05) !important;
}
.bwfan_btn_spin_blue::selection {
color: rgba(0, 163, 161, .05) !important;
}
.bwfan_btn_spin_blue:after {
animation: bwfan_spin .5s infinite linear;
border: 2px solid #0071a1;
border-radius: 50%;
border-right-color: transparent !important;
border-top-color: transparent !important;
content: "";
display: block;
width: 12px;
height: 12px;
top: 50%;
left: 50%;
margin-top: -8px;
margin-left: -8px;
position: absolute;
}
a.bwfan-add-repeater-data i {
font-size: 16px;
width: 16px;
height: 16px;
color: #444;
}
</style>
<?php
echo ob_get_clean(); //phpcs:ignore WordPress.Security.EscapeOutput
}
/**
* Register admin bar autonami links.
*
* @param \WP_Admin_Bar $wp_admin_bar
*/
public function bwfan_pro_add_menu_in_admin_bar( \WP_Admin_Bar $wp_admin_bar ) {
// Always add "search contact" link even at admin pages.
?>
<style type="text/css">
#wp-admin-bar-bwfan_admin_bar_search_contact-default {
width: 400px;
position: relative;
padding: 0 !important;
}
#wp-admin-bar-bwfan_admin_bar_search_contact-default li > .ab-item {
display: none;
}
#wpadminbar .quicklinks .menupop ul li .bwf-search-contacts .ab-item, #wpadminbar .quicklinks .menupop.hover ul li .bwf-search-contacts .ab-item {
height: auto;
}
#wp-admin-bar-bwfan_admin_bar_search_contact-default li .bwf-search-contacts {
background: #fff;
padding: 5px;
}
#wp-admin-bar-bwfan_admin_bar_search_contact-default li .bwf-search-contacts .bwf-search-input input {
width: 100%;
border: 1px solid #8c8f94;
border-radius: 4px;
padding: 0px 10px;
font-size: 15px;
color: #000;
box-sizing: border-box;
}
#wp-admin-bar-bwfan_admin_bar_search_contact-default li .label {
font-size: 14px;
display: block;
color: #000;
font-weight: 500;
cursor: default;
}
#bwf-contact-list-suggestion-list {
padding: 10px;
white-space: normal;
}
#bwf-contact-list-suggestion-list a.bwf-contact-suggestion {
width: fit-content;
border-radius: 18px;
padding: 0px 15px;
background-color: #e5e5e5;
border: 1px solid #9d9898;
color: #000 !important;
display: inline-block;
margin: 0 0 7px 7px;
}
#wp-admin-bar-bwfan_admin_bar_search_contact-default li .bwf-quick-links {
padding: 12px 20px;
background: #f7f5f5;
}
#wp-admin-bar-bwfan_admin_bar_search_contact-default .bwf-quick-links ul li a.ab-item, #wp-admin-bar-bwfan_admin_bar_search_contact-default .bwf-quick-links ul a.ab-item {
display: none;
}
#wp-admin-bar-bwfan_admin_bar_search_contact-default li .bwf-quick-links ul li {
padding: 10px 0;
margin: 0;
display: grid;
grid-template-columns: 50% 50%;
}
#wp-admin-bar-bwfan_admin_bar_search_contact-default li .bwf-quick-links ul li {
list-style: none;
padding: 0;
width: 48%;
display: inline-block;
}
#wpadminbar #wp-admin-bar-bwfan_admin_bar_search_contact-default li .bwf-quick-links ul li a {
text-decoration: none;
color: #1daafc;
}
</style>
<?php
$admin_url = admin_url( 'admin.php?page=autonami' );
$wp_admin_bar->add_node( [
'id' => 'bwfan_admin_bar_search_contact',
'title' => __( 'Search Contact', 'wp-marketing-automations-pro' ),
'parent' => 'top-secondary',
'href' => $admin_url . '&path=/contacts',
'meta' => [
'target' => '_blank',
],
] );
$html = '<div class="bwf-search-contacts">
<div class="bwf-search-input">
<span class="label">Enter name or email to search contact</span>
<input type="text" autocomplete="off" placeholder="Search Contacts" id="bwfan-admin-bar-search"/>
<div id="bwf-contact-list-suggestion-list">
</div>
</div>
<div class="bwf-quick-links">
<p class="label">Quick Links</p>
<ul>
<li><a href="' . esc_url( $admin_url . '&path=/automations' ) . '" target="_blank">Automations</a></li>
<li><a href="' . esc_url( $admin_url . '&path=/contacts' ) . '" target="_blank">Contacts</a></li>
<li><a href="' . esc_url( $admin_url . '&path=/analytics' ) . '" target="_blank">Analytics</a></li>
<li><a href="' . esc_url( $admin_url . '&path=/carts' ) . '" target="_blank">Cart</a></li>
<li><a href="' . esc_url( $admin_url . '&path=/settings' ) . '" target="_blank">Settings</a></li>
</ul>
</div>
</div>';
$wp_admin_bar->add_node( [
'id' => 'bwfan_admin_bar_li1',
'title' => $html,
'parent' => 'bwfan_admin_bar_search_contact',
'href' => "#",
] );
wp_enqueue_script( 'bwfan-admin-bar', $this->admin_url . '/assets/js/bwfan-pro-admin-bar.js', array( 'wp-api' ), BWFAN_VERSION_DEV, true );
wp_localize_script( 'bwfan-admin-bar', 'bwfanProObj', array(
'siteUrl' => site_url(),
'apiNamespace' => BWFAN_API_NAMESPACE,
) );
}
}
BWFAN_Pro_Admin::get_instance();

View File

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

View File

@@ -0,0 +1,35 @@
<?php
?>
<fieldset class="bwfan-tab-content bwfan-activeTab" setting-id="tab-birthday">
<div class="form-group field-input">
<label><?php esc_html_e( 'Show birthday field on checkout', 'wp-marketing-automations-pro' ); ?></label>
<div class="field-wrap">
<div class="wrapper">
<input class="bwfan_enable_birthday_checkout" name="bwfan_enable_birthday_checkout" type="checkbox" value="1" <?php echo empty( $global_settings['bwfan_enable_birthday_checkout'] ) ? '' : 'checked'; ?> />
<span class=""><?php esc_html_e( 'Enable birthday field to be shown on checkout page.', 'wp-marketing-automations-pro' ); ?></span>
</div>
</div>
</div>
<div class="form-group field-input">
<label><?php esc_html_e( 'Field Description', 'wp-marketing-automations-pro' ); ?></label>
<div class="field-wrap">
<div class="wrapper">
<input type="text" name="bwfan_birthday_field_desc" value="<?php echo empty( $global_settings['bwfan_birthday_field_desc'] ) ? '' : $global_settings['bwfan_birthday_field_desc']; //phpcs:ignore WordPress.Security.EscapeOutput ?>"/>
<span class=""><?php esc_html_e( 'This description will be shown with the birthday field.', 'auutonami-automations-pro' ); ?></span>
</div>
</div>
</div>
<div class="form-group field-input">
<label><?php esc_html_e( 'Checkout Field Placement', 'wp-marketing-automations-pro' ); ?></label>
<div class="field-wrap">
<div class="wrapper">
<select name="bwfan_birthday_field_position">
<?php $selected_position = isset( $global_settings['bwfan_birthday_field_position'] ) && ! empty( $global_settings['bwfan_birthday_field_position'] ) ? $global_settings['bwfan_birthday_field_position'] : ''; ?>
<option value="after_order_notes" <?php echo $selected_position === "after_order_notes" ? 'selected' : ''; ?> >After Order Notes</option>
<option value="before_order_notes" <?php echo $selected_position === "before_order_notes" ? 'selected' : ''; ?> >Before Order Notes</option>
<option value="after_billing_details" <?php echo $selected_position === "after_billing_details" ? 'selected' : ''; ?> >After Billing Details</option>
</select>
</div>
</div>
</div>
</fieldset>

View File

@@ -0,0 +1,32 @@
<?php
$license = BWFAN_Common::get_pro_license();
$token = get_option( 'bwfan_u_key', 0 );
$site_url = urlencode( home_url() );
$automation_id = sanitize_key( $_GET['edit'] );
$iframe_src = "//app.getautonami.com/get/$license/$token/$site_url/crm.automation.$automation_id";
/** Remove extra slashes */
$iframe_src = preg_replace('/([^:])(\/{2,})/', '$1/', $iframe_src);
?>
<div class="bwf-c-editor-modal-wrapper" id="bwf-modal-editor">
<div class="bwf-c-editor-modal bwf-c-editor-modal-full-width" id="bwf-modal-editor-inner">
</div>
</div>
<div class="bwfan_izimodal_default" style="display: none" id="modal-autonami-product-tool">
<div class="bwfan-search-filter-modal-wrap">
<div class="bwfan-modal-header bwfan_p15">
<div class="modal-header-title bwfan_heading_l bwfan_head_mr"><?php esc_html_e( 'Select a Product', 'wp-marketing-automations-pro' ) ?></div>
<div class="modal-header-search" id="bwf-c-product-tool-search">
<span class="dashicons dashicons-search modal-search-icon"></span>
<input type="search" id="modal-search-action-field" placeholder="<?php esc_html_e( 'Search Product', 'wp-marketing-automations-pro' ) ?>">
</div>
<span class="dashicons dashicons-no-alt bwfan_btn_close bwfan_modal_close" data-izimodal-close></span>
</div>
<div class="bwfan-modal-content">
<div class="bwfan-modal-content-content bwfan_p15" id="modal-autonami-product-tool-content">
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,11 @@
<#
is_enable_dragdrop = ('editor' === selected_template) ? '' : 'bwfan-display-none';
editor = !!data.actionSavedData && !!data.actionSavedData.data && !!data.actionSavedData.data.editor ? data.actionSavedData.data.editor : {};
body = !!editor.body ? editor.body : '';
design = !!editor.design ? editor.design : '';
#>
<div class="bwfan-email-editor bwfan-col-sm-12 bwfan-pl-0 bwfan-pr-0 bwfan-mb-15 {{is_enable_dragdrop}}">
<button class="button bwfan-button primary" id="bwf-launch-editor-modal"><?php esc_html_e( 'Launch Editor', 'wp-marketing-automations-pro' ) ?></button>
<input name="bwfan[{{data.action_id}}][data][editor][body]" type="hidden" value="{{body}}" id="bwfan-editor-body"/>
<input name="bwfan[{{data.action_id}}][data][editor][design]" type="hidden" value="{{design}}" id="bwfan-editor-design"/>
</div>

View File

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

View File

@@ -0,0 +1,45 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* @var $event BWFAN_Wp_Sendemail
*/
?>
<div class="bwfan_email_tracking bwfan-mb-15">
<label for="bwfan_append_utm">
<input type="checkbox" name="bwfan[{{data.action_id}}][data][append_utm]" id="bwfan_append_utm" value="1" {{is_append_utm}}/>
<?php
echo esc_html__( 'Add UTM parameters to the links', 'wp-marketing-automations-pro' );
$message = __( 'Add UTM parameters in all the links present in the email.', 'wp-marketing-automations-pro' );
echo $event->add_description( $message, 'xl' ); //phpcs:ignore WordPress.Security.EscapeOutput
?>
</label>
<div class="bwfan_utm_sources {{show_utm_parameters}}">
<div class="bwfan-input-form clearfix">
<div class="bwfan-col-sm-4 bwfan-pl-0"><span class="bwfan_label_input"><?php echo esc_html__( 'UTM Source', 'wp-marketing-automations-pro' ); ?></span></div>
<div class="bwfan-col-sm-8 bwfan-pr-0">
<input type="text" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][utm_source]" value="{{entered_utm_source}}" id="bwfan_utm_source"/>
</div>
</div>
<div class="bwfan-input-form clearfix">
<div class="bwfan-col-sm-4 bwfan-pl-0"><span class="bwfan_label_input"><?php echo esc_html__( 'UTM Medium', 'wp-marketing-automations-pro' ); ?></span></div>
<div class="bwfan-col-sm-8 bwfan-pr-0">
<input type="text" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][utm_medium]" value="{{entered_utm_medium}}" id="bwfan_utm_medium"/>
</div>
</div>
<div class="bwfan-input-form clearfix">
<div class="bwfan-col-sm-4 bwfan-pl-0"><span class="bwfan_label_input"><?php echo esc_html__( 'UTM Campaign', 'wp-marketing-automations-pro' ); ?></span></div>
<div class="bwfan-col-sm-8 bwfan-pr-0">
<input type="text" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][utm_campaign]" value="{{entered_utm_campaign}}" id="bwfan_utm_campaign"/>
</div>
</div>
<div class="bwfan-input-form clearfix">
<div class="bwfan-col-sm-4 bwfan-pl-0"><span class="bwfan_label_input"><?php echo esc_html__( 'UTM Term', 'wp-marketing-automations-pro' ); ?></span></div>
<div class="bwfan-col-sm-8 bwfan-pr-0">
<input type="text" class="bwfan-input-wrapper" name="bwfan[{{data.action_id}}][data][utm_term]" value="{{entered_utm_term}}" id="bwfan_utm_term"/>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,47 @@
<?php
/**
* Class BWFAN_Pro_Compatibilities
* Loads all the compatibilities files we have in Autonami against plugins
*/
class BWFAN_Pro_Compatibilities {
public static function load_merge_tags_compatibilities() {
$compatibilities = [
'merge_tags/class-bwfan-pro-compatibility-handl-utm-grabber-data.php' => function_exists( 'bwfan_is_utm_grabber_active' ) && bwfan_is_utm_grabber_active(),
'merge_tags/class-bwfan-pro-compatibility-wc-advanced-shipment-tracking.php' => function_exists( 'wc_advanced_shipment_tracking' ) || class_exists( 'Ast_Pro' ),
'merge_tags/class-bwfan-pro-compatibility-wc-order-tracking.php' => bwfan_is_woocommerce_active() && function_exists( 'bwfan_wc_order_tracking_active' ) && bwfan_wc_order_tracking_active(),
'merge_tags/class-bwfan-pro-compatibility-wc-sequential-order-number.php' => class_exists( 'WC_Sequential_Order_Numbers_Pro_Loader' ) || class_exists( 'WC_Seq_Order_Number' ),
'merge_tags/class-bwfan-pro-compatibility-wc-services.php' => defined( 'WOOCOMMERCE_CONNECT_MINIMUM_WOOCOMMERCE_VERSION' ),
'merge_tags/class-bwfan-pro-compatibility-wc-shipment-tracking.php' => function_exists( 'wc_shipment_tracking' ),
'plugins/class-bwfan-pro-compatibility-translatepress.php' => class_exists( 'TRP_Translate_Press' ),
];
self::add_files( array_filter( $compatibilities ) );
}
/**
* Include valid compatibility files
*
* @param $paths
*
* @return void
*/
public static function add_files( $paths ) {
/** Compatibilities folder */
$dir = BWFAN_PRO_PLUGIN_DIR . '/compatibilities';
try {
foreach ( $paths as $file => $condition ) {
if ( ! file_exists( $dir . '/' . $file ) ) {
continue;
}
include_once $dir . '/' . $file;
}
} catch ( Exception|Error $e ) {
BWF_Logger::get_instance()->log( 'Error while loading compatibility files: ' . $e->getMessage(), 'compatibilities-load-error', 'fka-files-load-error' );
}
}
}
add_action( 'bwfan_merge_tags_loaded', array( 'BWFAN_Pro_Compatibilities', 'load_merge_tags_compatibilities' ), 999 );

View File

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

View File

@@ -0,0 +1,172 @@
<?php
/**
* Plugin: https://wordpress.org/plugins/woo-advanced-shipment-tracking
* Class BWFAN_Handl_Utm_Grabber_Data
*/
class BWFAN_Handl_Utm_Grabber_Data extends Cart_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'handl_utm_grabber_data';
$this->tag_description = __( 'HandL UTM Grabber Data', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_handl_utm_grabber_data', array( $this, 'parse_shortcode' ) );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Show the html in popup for the merge tag.
*/
public function get_view() {
$handle_utm_fields = $this->get_view_data();
$this->get_back_button();
?>
<div class="bwfan_mtag_wrap">
<div class="bwfan_label">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'Select Handl UTM Grabber', 'wp-marketing-automations-pro' ); ?></label>
</div>
<div class="bwfan_label_val">
<select id="" class="bwfan-input-wrapper bwfan_tag_select" name="data">
<?php
foreach ( $handle_utm_fields as $slug => $name ) {
echo '<option value="' . esc_attr__( $slug ) . '">' . esc_attr__( $name ) . '</option>';
}
?>
</select>
</div>
</div>
<?php
if ( $this->support_fallback ) {
$this->get_fallback();
}
$this->get_preview();
$this->get_copy_button();
}
public function get_view_data() {
$handler_merge_key = array(
'utm_campaign' => __( 'UTM Campaign', 'wp-marketing-automations-pro' ),
'utm_source' => __( 'UTM Source', 'wp-marketing-automations-pro' ),
'utm_term' => __( 'UTM Term', 'wp-marketing-automations-pro' ),
'utm_medium' => __( 'UTM Medium', 'wp-marketing-automations-pro' ),
'utm_content' => __( 'UTM Content', 'wp-marketing-automations-pro' ),
'gclid' => __( 'Gclid', 'wp-marketing-automations-pro' ),
'handl_original_ref' => __( 'Handl Original Reference', 'wp-marketing-automations-pro' ),
'handl_landing_page' => __( 'Handl Landing Page', 'wp-marketing-automations-pro' ),
'handl_ip' => __( 'Handl IP', 'wp-marketing-automations-pro' ),
'handl_ref' => __( 'Handl Reference', 'wp-marketing-automations-pro' ),
'handl_url' => __( 'Handl URL', 'wp-marketing-automations-pro' ),
);
return apply_filters( 'bwfan_external_handl_utm_grabber_key', $handler_merge_key );
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|string|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview();
}
$cart_details = BWFAN_Merge_Tag_Loader::get_data( 'cart_details' );
$checkout_data = isset( $cart_details['checkout_data'] ) ? $cart_details['checkout_data'] : '';
$key = ! isset( $attr['data'] ) ? 'utm_campaign' : $attr['data'];
/** getting the grabber data from checkout */
if ( ! empty( $checkout_data ) ) {
$field_value = '';
$checkout_data = json_decode( $checkout_data, true );
$field_value = '';
if ( isset( $checkout_data['handle_utm_grabber'][ $key ] ) ) {
$field_value = $checkout_data['handle_utm_grabber'][ $key ];
}
return $this->parse_shortcode_output( $field_value, $attr );
}
/** if order id available then get the details */
$order_id = $this->get_order_id();
if ( ! empty( $order_id ) ) {
$order = wc_get_order( $order_id );
if ( ! $order instanceof WC_Order ) {
return $this->parse_shortcode_output( '', $attr );
}
$field_value = $order->get_meta( $key );
return $this->parse_shortcode_output( $field_value, $attr );
}
return $this->parse_shortcode_output( '', $attr );
}
public function get_order_id() {
$order_id = absint( BWFAN_Merge_Tag_Loader::get_data( 'wc_order_id' ) );
$order_id = ( 0 === $order_id ) ? absint( BWFAN_Merge_Tag_Loader::get_data( 'order_id' ) ) : $order_id;
if ( 0 === $order_id ) {
$order = BWFAN_Merge_Tag_Loader::get_data( 'wc_order' );
$order_id = $order instanceof WC_Order ? absint( BWFAN_Woocommerce_Compatibility::get_order_id( $order ) ) : $order_id;
}
return $order_id;
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*/
public function get_dummy_preview() {
return '';
}
/**
* Returns merge tag schema
*
* @return array[]
*/
public function get_setting_schema() {
$utm_data = $this->get_view_data();
$options = [];
foreach ( $utm_data as $utm_key => $data ) {
$options[] = [
'value' => $utm_key,
'label' => $data,
];
}
return [
[
'id' => 'data',
'type' => 'select',
'options' => $options,
'label' => __( 'Select UTM', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper',
"required" => true,
'placeholder' => __( 'Select', 'wp-marketing-automations-pro' ),
"description" => ""
]
];
}
}
BWFAN_Merge_Tag_Loader::register( 'wc_ab_cart', 'BWFAN_Handl_Utm_Grabber_Data' );
BWFAN_Merge_Tag_Loader::register( 'wc_order', 'BWFAN_Handl_Utm_Grabber_Data' );

View File

@@ -0,0 +1,142 @@
<?php
/**
* Plugin: https://wordpress.org/plugins/woo-advanced-shipment-tracking
* Class BWFAN_WC_Advanced_Shipment_Tracking
*/
class BWFAN_WC_Advanced_Shipment_Tracking extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'wc_adv_shipment';
$this->tag_description = __( 'WooCommerce Advanced Shipment Tracking details', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_wc_advanced_shipment_tracking', array( $this, 'parse_shortcode' ) );
add_shortcode( 'bwfan_wc_adv_shipment', array( $this, 'parse_shortcode' ) );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Show the html in popup for the merge tag.
*/
public function get_view() {
$tracking_fields = $this->get_view_data();
$this->get_back_button();
?>
<div class="bwfan_mtag_wrap">
<div class="bwfan_label">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'Select Shipment Tracking Field', 'wp-marketing-automations-pro' ); ?></label>
</div>
<div class="bwfan_label_val">
<select id="" class="bwfan-input-wrapper bwfan_tag_select" name="data">
<?php
foreach ( $tracking_fields as $slug => $name ) {
echo '<option value="' . esc_attr__( $slug ) . '">' . esc_attr__( $name ) . '</option>';
}
?>
</select>
</div>
</div>
<?php
if ( $this->support_fallback ) {
$this->get_fallback();
}
$this->get_preview();
$this->get_copy_button();
}
public function get_view_data() {
return array(
'tracking_number' => __( 'Tracking Number', 'wp-marketing-automations-pro' ),
'formatted_tracking_provider' => __( 'Tracking Provider', 'wp-marketing-automations-pro' ),
'formatted_tracking_link' => __( 'Tracking Link', 'wp-marketing-automations-pro' ),
'date_shipped' => __( 'Date Shipped', 'wp-marketing-automations-pro' ),
);
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|string|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview();
}
$order_id = absint( BWFAN_Merge_Tag_Loader::get_data( 'wc_order_id' ) );
$order_id = empty( $order_id ) && ! empty( BWFAN_Merge_Tag_Loader::get_data( 'order_id' ) ) ? BWFAN_Merge_Tag_Loader::get_data( 'order_id' ) : $order_id;
if ( empty( $order_id ) ) {
return '';
}
$tracking_items = ast_get_tracking_items( $order_id );
if ( ! is_array( $tracking_items ) || 1 > count( $tracking_items ) ) {
return '';
}
/** If more than one shipments, then sort by date_shipped */
if ( count( $tracking_items ) > 1 ) {
usort( $tracking_items, function ( $item1, $item2 ) {
return absint( $item1['date_shipped'] ) <= absint( $item2['date_shipped'] );
} );
}
$item_key = ( isset( $attr['data'] ) && ! empty( $attr['data'] ) ) ? $attr['data'] : 'tracking_number';
$return_value = 'date_shipped' === $item_key ? date( 'm-d-Y', $tracking_items[0]['date_shipped'] ) : $tracking_items[0][ $item_key ];
return $this->parse_shortcode_output( $return_value, $attr );
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*/
public function get_dummy_preview() {
return '123456789';
}
/**
* Return merge tag schema
*
* @return array[]
*/
public function get_setting_schema() {
$tracking_data = $this->get_view_data();
$options = [];
foreach ( $tracking_data as $track_key => $data ) {
$options[] = [
'value' => $track_key,
'label' => $data,
];
}
return [
[
'id' => 'data',
'type' => 'select',
'options' => $options,
'label' => __( 'Select Shipment Tracking Field', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper',
"placeholder" => __( 'Select', 'wp-marketing-automations-pro' ),
"required" => false,
"description" => ""
],
];
}
}
/** checking for both WC Advanced Shipment Tracking Lite and Pro plugin */
BWFAN_Merge_Tag_Loader::register( 'wc_order', 'BWFAN_WC_Advanced_Shipment_Tracking' );

View File

@@ -0,0 +1,147 @@
<?php
class BWFAN_WC_Order_Tracking extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'wc_order_tracking';
$this->tag_description = __( 'WooCommerce order Tracking details', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_wc_order_tracking', array( $this, 'parse_shortcode' ) );
$this->support_v1 = false;
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function get_view_data() {
return array(
'Items_name' => __( 'Tracking Item Name', 'wp-marketing-automations-pro' ),
'carrier_name' => __( 'Carrier Name', 'wp-marketing-automations-pro' ),
'tracking_number' => __( 'Tracking Number', 'wp-marketing-automations-pro' ),
'tracking_url_show' => __( 'Tracking Link', 'wp-marketing-automations-pro' ),
'order_tracking_formatted' => __( 'Formatted', 'wp-marketing-automations-pro' ),
);
}
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview( $attr );
}
$order_id = absint( BWFAN_Merge_Tag_Loader::get_data( 'wc_order_id' ) );
$order_id = empty( $order_id ) && ! empty( BWFAN_Merge_Tag_Loader::get_data( 'order_id' ) ) ? BWFAN_Merge_Tag_Loader::get_data( 'order_id' ) : $order_id;
if ( empty( $order_id ) ) {
return '';
}
$tracking_data = self::get_tracking_data( $order_id );
if ( empty( $tracking_data ) ) {
return '';
}
$item_key = ( isset( $attr['data'] ) && ! empty( $attr['data'] ) ) ? $attr['data'] : 'tracking_number';
if ( 'order_tracking_formatted' === $item_key ) {
$return_value = $this->get_formatted_order_tracking( $tracking_data );
return $this->parse_shortcode_output( $return_value, $attr );
}
$return_value = 'Items_name' === $item_key ? implode( ', ', array_map( function ( $item ) {
return $item['item_name'];
}, $tracking_data ) ) : implode( ', ', array_column( $tracking_data, $item_key ) );
return $this->parse_shortcode_output( $return_value, $attr );
}
public function get_formatted_order_tracking( $tracking_items ) {
$formatted_order_tracking = array_map( function ( $item ) {
return "{$item['item_name']}\n{$item['carrier_name']} ({$item['tracking_number']})\n{$item['tracking_url_show']}";
}, $tracking_items );
return implode( ", \n", $formatted_order_tracking );
}
public function get_dummy_preview( $attr ) {
switch ( $attr['data'] ) {
case 'Items_name':
return 'Album, Belt';
case 'carrier_name':
return 'Carrier Name, Carrier Name 2';
case 'tracking_url_show':
return 'https://example.com, https://example2.com';
case 'order_tracking_formatted':
return "Item Name,\nCarrier Name (Tracking Code)\nhttps://example.com";
default:
return 'ABCD123, ABCDE1234';
}
}
public function get_setting_schema() {
$tracking_data = $this->get_view_data();
$options = [];
foreach ( $tracking_data as $track_key => $data ) {
$options[] = [
'value' => $track_key,
'label' => $data,
];
}
return [
[
'id' => 'data',
'type' => 'select',
'options' => $options,
'label' => __( 'Select order Tracking Field', 'wp-marketing-automations-pro' ),
'class' => 'bwfan-input-wrapper',
'placeholder' => __( 'Select', 'wp-marketing-automations-pro' ),
'required' => false,
'description' => ''
],
];
}
public static function get_tracking_data( $order_id ) {
$order = wc_get_order( $order_id );
if ( ! $order instanceof WC_Order || empty( $order->get_items() ) ) {
return [];
}
if ( class_exists( 'VI_WOOCOMMERCE_ORDERS_TRACKING_DATA' ) ) {
return VI_WOOCOMMERCE_ORDERS_TRACKING_DATA::get_tracking_numbers( $order_id );
}
$tracking_data = [];
foreach ( $order->get_items() as $item_id => $item ) {
$item_tracking_data = wc_get_order_item_meta( $item_id, '_vi_wot_order_item_tracking_data', true );
if ( empty( $item_tracking_data ) ) {
continue;
}
$item_tracking_data = json_decode( $item_tracking_data, true );
if ( empty( $item_tracking_data ) || ! is_array( $item_tracking_data ) ) {
continue;
}
foreach ( $item_tracking_data as $tracking ) {
// Check if tracking number already exists to prevent duplicates
if ( ! in_array( $tracking['tracking_number'], array_column( $tracking_data, 'tracking_number' ) ) ) {
$tracking_data[] = [
'tracking_number' => $tracking['tracking_number'] ?? '',
'carrier_name' => $tracking['carrier_name'] ?? '',
'item_name' => $item->get_name(),
'tracking_url_show' => str_replace( '{tracking_number}', $tracking['tracking_number'] ?? '', $tracking['carrier_url'] ?? '' ),
];
}
}
}
return $tracking_data;
}
}
BWFAN_Merge_Tag_Loader::register( 'wc_order', 'BWFAN_WC_Order_Tracking' );

View File

@@ -0,0 +1,64 @@
<?php
class BWFAN_WC_Sequential_Order_Number extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'wc_seq_order_number';
$this->tag_description = __( 'WooCommerce Sequential Order Number', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_wc_sequential_order_number', array( $this, 'parse_shortcode' ) );
add_shortcode( 'bwfan_wc_seq_order_number', array( $this, 'parse_shortcode' ) );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|string|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview();
}
$order = null;
$order_id = absint( BWFAN_Merge_Tag_Loader::get_data( 'wc_order_id' ) );
$order_id = 0 === $order_id ? absint( BWFAN_Merge_Tag_Loader::get_data( 'order_id' ) ) : $order_id;
if ( 0 === $order_id ) {
$order = BWFAN_Merge_Tag_Loader::get_data( 'wc_order' );
} else {
$order = wc_get_order( $order_id );
}
if ( ! $order instanceof WC_Order ) {
return '';
}
$order_number = $order->get_meta( '_order_number_formatted' );
$order_number = empty( $order_number ) ? $order->get_meta( '_order_number' ) : $order_number;
return $this->parse_shortcode_output( $order_number, $attr );
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*/
public function get_dummy_preview() {
return 'WC-1234-2020';
}
}
BWFAN_Merge_Tag_Loader::register( 'wc_order', 'BWFAN_WC_Sequential_Order_Number' );

View File

@@ -0,0 +1,173 @@
<?php
class BWFAN_WC_Jetpack_Shipment extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'wc_jetpack_shipment';
$this->tag_description = __( 'WooCommerce Services - Jetpack', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_wc_jetpack_shipment', array( $this, 'parse_shortcode' ) );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Show the html in popup for the merge tag.
*/
public function get_view() {
$tracking_fields = $this->get_view_data();
$this->get_back_button();
?>
<div class="bwfan_mtag_wrap">
<div class="bwfan_label">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'Select Tracking Field', 'wp-marketing-automations-pro' ); ?></label>
</div>
<div class="bwfan_label_val">
<select id="" class="bwfan-input-wrapper bwfan_tag_select" name="data">
<?php
foreach ( $tracking_fields as $slug => $name ) {
echo '<option value="' . esc_attr__( $slug ) . '">' . esc_attr__( $name ) . '</option>';
}
?>
</select>
</div>
</div>
<?php
if ( $this->support_fallback ) {
$this->get_fallback();
}
$this->get_preview();
$this->get_copy_button();
}
public function get_view_data() {
return array(
'carrier_name_short' => __( 'Carrier Name - Short', 'wp-marketing-automations-pro' ),
'carrier_name_full' => __( 'Carrier Name - Full', 'wp-marketing-automations-pro' ),
'package_name' => __( 'Package Name', 'wp-marketing-automations-pro' ),
'tracking_number' => __( 'Tracking Number', 'wp-marketing-automations-pro' ),
'tracking_link' => __( 'Tracking Link', 'wp-marketing-automations-pro' ),
);
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|string|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview();
}
$order_id = absint( BWFAN_Merge_Tag_Loader::get_data( 'wc_order_id' ) );
$order_id = empty( $order_id ) && ! empty( BWFAN_Merge_Tag_Loader::get_data( 'order_id' ) ) ? BWFAN_Merge_Tag_Loader::get_data( 'order_id' ) : $order_id;
if ( empty( $order_id ) ) {
return '';
}
$order = wc_get_order( $order_id );
if ( ! $order instanceof WC_Order ) {
return '';
}
$tracking_items = $order->get_meta( 'wc_connect_labels' );
if ( ! is_array( $tracking_items ) || empty( $tracking_items ) ) {
$tracking_items = $order->get_meta( '_wc_shipment_tracking_items' );
}
if ( ! is_array( $tracking_items ) || empty( $tracking_items ) ) {
return '';
}
$item = $tracking_items[0];
$return_value = '';
$item_key = isset( $attr['data'] ) && ! empty( $attr['data'] ) ? $attr['data'] : 'tracking_number';
switch ( $item_key ) {
case 'carrier_name_short':
$return_value = isset( $item['tracking_provider'] ) ? strtoupper( $item['tracking_provider'] ) : ( isset( $item['custom_tracking_provider'] ) ? strtoupper( $item['custom_tracking_provider'] ) : '' );
break;
case 'carrier_name_full':
$return_value = isset( $item['custom_tracking_provider'] ) ? $item['custom_tracking_provider'] : '';
break;
case 'package_name':
$return_value = isset( $item['package_name'] ) ? $item['package_name'] : '';
break;
case 'tracking_number':
$return_value = isset( $item['tracking_number'] ) ? $item['tracking_number'] : '';
break;
case 'tracking_link':
$return_value = isset( $item['custom_tracking_link'] ) ? $item['custom_tracking_link'] : '';
break;
}
return $this->parse_shortcode_output( $return_value, $attr );
}
public function get_tracking_url( $carrier, $tracking_number ) {
$tracking_url = '';
switch ( $carrier ) {
case 'fedex':
$tracking_url = 'https://www.fedex.com/apps/fedextrack/?action=track&tracknumbers=' . $tracking_number;
break;
case 'usps':
$tracking_url = 'https://tools.usps.com/go/TrackConfirmAction.action?tLabels=' . $tracking_number;
break;
}
return $tracking_url;
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*/
public function get_dummy_preview() {
return '123456789';
}
/**
* Return merge tag schema
*
* @return array[]
*/
public function get_setting_schema() {
$tracking_data = $this->get_view_data();
$options = [];
foreach ( $tracking_data as $track_key => $data ) {
$options[] = [
'value' => $track_key,
'label' => $data,
];
}
return [
[
'id' => 'data',
'type' => 'select',
'options' => $options,
'label' => __( 'Select Shipment Tracking Field', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper',
"placeholder" => __( 'Select', 'wp-marketing-automations-pro' ),
"required" => false,
"description" => ""
],
];
}
}
BWFAN_Merge_Tag_Loader::register( 'wc_order', 'BWFAN_WC_Jetpack_Shipment' );

View File

@@ -0,0 +1,158 @@
<?php
class BWFAN_WC_Shipment_Tracking extends BWFAN_Merge_Tag {
private static $instance = null;
public function __construct() {
$this->tag_name = 'wc_shipment_tracking';
$this->tag_description = __( 'WooCommerce Shipment Tracking details', 'wp-marketing-automations-pro' );
add_shortcode( 'bwfan_wc_shipment_tracking', array( $this, 'parse_shortcode' ) );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Show the html in popup for the merge tag.
*/
public function get_view() {
$tracking_fields = $this->get_view_data();
$this->get_back_button();
?>
<div class="bwfan_mtag_wrap">
<div class="bwfan_label">
<label for="" class="bwfan-label-title"><?php esc_html_e( 'Select Shipment Tracking Field', 'wp-marketing-automations-pro' ); ?></label>
</div>
<div class="bwfan_label_val">
<select id="" class="bwfan-input-wrapper bwfan_tag_select" name="data">
<?php
foreach ( $tracking_fields as $slug => $name ) {
echo '<option value="' . esc_attr__( $slug ) . '">' . esc_attr__( $name ) . '</option>';
}
?>
</select>
</div>
</div>
<?php
if ( $this->support_fallback ) {
$this->get_fallback();
}
$this->get_preview();
$this->get_copy_button();
}
public function get_view_data() {
return array(
'tracking_number' => __( 'Tracking Number', 'wp-marketing-automations-pro' ),
'formatted_tracking_provider' => __( 'Tracking Provider', 'wp-marketing-automations-pro' ),
'formatted_tracking_link' => __( 'Tracking Link', 'wp-marketing-automations-pro' ),
'date_shipped' => __( 'Date Shipped', 'wp-marketing-automations-pro' ),
'shipping_formatted' => __( 'Formatted', 'wp-marketing-automations-pro' ),
);
}
/**
* Parse the merge tag and return its value.
*
* @param $attr
*
* @return mixed|string|void
*/
public function parse_shortcode( $attr ) {
if ( true === BWFAN_Merge_Tag_Loader::get_data( 'is_preview' ) ) {
return $this->get_dummy_preview();
}
$order_id = absint( BWFAN_Merge_Tag_Loader::get_data( 'wc_order_id' ) );
$order_id = empty( $order_id ) && ! empty( BWFAN_Merge_Tag_Loader::get_data( 'order_id' ) ) ? BWFAN_Merge_Tag_Loader::get_data( 'order_id' ) : $order_id;
if ( empty( $order_id ) ) {
return '';
}
$tracking_items = wc_shipment_tracking()->actions->get_tracking_items( $order_id, true );
if ( count( $tracking_items ) < 1 ) {
return '';
}
$date_format = get_option( 'date_format', 'Y-m-d' );
$item_key = ( isset( $attr['data'] ) && ! empty( $attr['data'] ) ) ? $attr['data'] : 'tracking_number';
if ( 'shipping_formatted' === $item_key ) {
$return_value = $this->get_formatted_shipping( $tracking_items, $date_format );
return $this->parse_shortcode_output( $return_value, $attr );
}
$return_value = 'date_shipped' === $item_key ? implode( ', ', array_map( function ( $item ) use ( $date_format ) {
return date( $date_format, $item['date_shipped'] );
}, $tracking_items ) ) : implode( ', ', array_column( $tracking_items, $item_key ) );
return $this->parse_shortcode_output( $return_value, $attr );
}
/**
* Format shipping information.
*
* @param array $tracking_items Tracking items array.
*
* @return string Formatted shipping information.
*/
public function get_formatted_shipping( $tracking_items, $date_format ) {
$formatted_shipping = array_map( function ( $item ) use ( $date_format ) {
$output = "{$item['formatted_tracking_provider']} ({$item['tracking_number']})";
$output .= "\n{$item['formatted_tracking_link']}";
$output .= "\n" . date( $date_format, $item['date_shipped'] );
return $output;
}, $tracking_items );
return implode( "\n\n", $formatted_shipping );
}
/**
* Show dummy value of the current merge tag.
*
* @return string
*/
public function get_dummy_preview() {
return '123456789';
}
/**
* Return merge tag schema
*
* @return array[]
*/
public function get_setting_schema() {
$tracking_data = $this->get_view_data();
$options = [];
foreach ( $tracking_data as $track_key => $data ) {
$options[] = [
'value' => $track_key,
'label' => $data,
];
}
return [
[
'id' => 'data',
'type' => 'select',
'options' => $options,
'label' => __( 'Select Shipment Tracking Field', 'wp-marketing-automations-pro' ),
"class" => 'bwfan-input-wrapper',
"placeholder" => __( 'Select', 'wp-marketing-automations-pro' ),
"required" => false,
"description" => ""
],
];
}
}
BWFAN_Merge_Tag_Loader::register( 'wc_order', 'BWFAN_WC_Shipment_Tracking' );

View File

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

View File

@@ -0,0 +1,28 @@
<?php
/**
* Plugin: https://wordpress.org/plugins/translatepress-multilingual/
* Class BWFAN_Pro_Compatibility_TranslatePress
*/
class BWFAN_Pro_Compatibility_TranslatePress {
private static $instance = null;
public function __construct() {
add_action( 'bwfan_before_executing_broadcast', [ $this, 'unhook_wp_mail_filter' ] );
}
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
public function unhook_wp_mail_filter() {
BWFAN_PRO_Common::remove_actions( 'wp_mail', 'TRP_Translation_Render', 'wp_mail_filter' );
}
}
BWFAN_Pro_Compatibility_TranslatePress::get_instance();

View File

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

View File

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

View File

@@ -0,0 +1,244 @@
<?php
if ( ! class_exists( 'BWFCO_Stripe' ) ) {
#[AllowDynamicProperties]
class BWFCO_Stripe extends BWF_CO {
private static $ins = null;
public static $headers = null;
public $is_setting = true;
public $v2 = true;
public $is_pro = false;
public $direct_connect = true;
public $is_new = 1;
public static $plugin_zip_url = 'https://downloads.wordpress.org/plugin/funnelkit-stripe-woo-payment-gateway.zip';
public static $plugin = 'funnelkit-stripe-woo-payment-gateway/funnelkit-stripe-woo-payment-gateway.php';
public function __construct() {
$this->is_setting = true;
$this->dir = __DIR__;
$this->connector_url = BWFAN_PRO_PLUGIN_URL;
$this->autonami_int_slug = 'BWFAN_Upsell_Stripe_Integration';
$this->priority = 5;
add_filter( 'wfco_connectors_loaded', array( $this, 'add_card' ) );
add_action( 'fkwcs_after_connect_with_stripe', array( $this, 'connect_disconnect_on_strip_config' ) );
}
/**
* @return BWFCO_Stripe|null
*/
public static function get_instance() {
if ( null === self::$ins ) {
self::$ins = new self();
}
return self::$ins;
}
public function add_card( $available_connectors ) {
$available_connectors['autonami']['connectors']['bwfco_stripe'] = array(
'name' => 'Stripe',
'desc' => __( 'Now recover more orders when users rejects upsell offers or bumps and follow up with special one click link when they pay via Stripe.', 'wp-marketing-automations-pro' ),
'connector_class' => 'bwfco_stripe',
'image' => BWFAN_PLUGIN_URL . '/includes/connectors-logo/stripe.png',
'source' => '',
'file' => '',
);
return $available_connectors;
}
public function connect_disconnect_on_strip_config( $status ) {
if ( $status === 'success' ) {
WFCO_Common::save_connector_data( [], $this->get_slug(), 1 );
return;
}
$stripe_connect = WFCO_Load_Connectors::get_connector( $this->get_slug() );
if ( method_exists( $stripe_connect, 'disconnect' ) ) {
$stripe_connect->disconnect();
}
}
/**
* Handles the settings form submission
*
* @param $data
* @param $type
*
* @return array|string[]
*/
public function handle_settings_form( $data, $type = 'save' ) {
/** Stripe upsell offer table obj */
BWFAN_DB::load_table_classes();
require_once BWFAN_PRO_PLUGIN_DIR . '/includes/db/tables/class-bwfan-db-table-stripe-offer.php';
$table_obj = new BWFAN_DB_Table_Stripe_Offer();
if ( ! $table_obj->is_exists() ) {
$table_obj->create_table();
}
$resp = $this->bwf_install_activate_fkstripe();
$resp = array_merge( array(
'status' => 'success',
'message' => '',
), $resp );
if ( $resp['status'] === 'success' && ! isset( $resp['redirect'] ) ) {
$resp['id'] = WFCO_Common::save_connector_data( [], $this->get_slug(), 1 );
}
return $resp;
}
public function get_fields_schema() {
$is_connected = isset( WFCO_Common::$connectors_saved_data[ $this->get_slug() ] ) && true === $this->has_settings();
return array(
array(
'id' => 'bwfan_upsell_strip_info',
'type' => 'para',
'class' => 'bwfan_upsell_strip_info',
'required' => false,
'children' => ! $is_connected ? __( 'To connect with upsell stripe click on connect', 'wp-marketing-automations-pro' ) : __( 'Already Connected. To reconnect, press the disconnect button and connect again.', 'wp-marketing-automations-pro' ),
),
);
}
public function get_settings_fields_values() {
return [];
}
public function bwf_install_activate_fkstripe() {
$all_plugins = get_plugins();
$resp = [];
if ( ! array_key_exists( self::$plugin, $all_plugins ) ) {
$resp = $this->bwfan_install_stripe();
}
if ( isset( $resp['status'] ) && ( ! $resp['status'] || $resp['status'] === 'rerun_api' ) ) {
return $resp;
}
$resp = true;
if ( ! is_plugin_active( self::$plugin ) ) {
$resp = $this->maybe_activate_stripe( self::$plugin );
if ( $resp ) {
return [
'status' => 'rerun_api'
];
}
}
if ( is_array( $resp ) && isset( $resp['status'] ) && $resp['status'] === 'rerun_api' ) {
return $resp;
}
if ( $resp && \FKWCS\Gateway\Stripe\Admin::get_instance()->is_stripe_connected() ) {
return [
'status' => 'success',
];
}
return [
'status' => 'not_connected',
'redirect' => \FKWCS\Gateway\Stripe\Admin::get_instance()->get_connect_url()
];
}
public function bwfan_install_stripe() {
$resp = array();
$installed = $this->maybe_install_stripe( self::$plugin, self::$plugin_zip_url );
$resp['status'] = true;
$resp['message'] = __( 'Funnelkit stripe gateway plugin installed successfully', 'wp-marketing-automations-pro' );
if ( ! $installed ) {
return [
'status' => false,
'message' => __( "Funnelkit stripe gateway plugin could not be installed", 'wp-marketing-automations-pro' )
];
}
// update option after installing stripe plugin
update_option( 'fkwcs_wp_stripe', 'c7ffb6c58db95d6f19059ae19a0a85bf', false );
$resp = $this->maybe_activate_stripe( self::$plugin );
if ( $resp ) {
return [
'status' => 'rerun_api'
];
}
return $resp;
}
public function maybe_install_stripe( $plugin, $plugin_url ) {
if ( empty( $plugin_url ) ) {
return false;
}
$all_plugins = get_plugins();
if ( array_key_exists( $plugin, $all_plugins ) ) {
return true;
}
require_once BWFAN_PLUGIN_DIR . '/includes/plugin_helpers/class-bwfan-plugin-install-skin.php';
require_once BWFAN_PLUGIN_DIR . '/includes/plugin_helpers/class-bwfan-plugin-silent-upgrader.php';
// Do not allow WordPress to search/download translations, as this will break JS output.
remove_action( 'upgrader_process_complete', [ 'Language_Pack_Upgrader', 'async_upgrade' ], 20 );
// Create the plugin upgrader with our custom skin.
$installer = new BWFAN_Plugin_Silent_Upgrader( new BWFAN_Plugin_Install_Skin() );
if ( ! method_exists( $installer, 'install' ) ) {
return false;
}
if ( ! $installer->install( $plugin_url ) ) {
return false;
}
/**
* Fire after plugin installing via the BWFAN installer.
*/
return true;
}
public function maybe_activate_stripe( $plugin ) {
if ( empty( $plugin ) ) {
return false;
}
if ( ! current_user_can( 'activate_plugins' ) ) {
return false;
}
// Activate the plugin silently.
$activated = activate_plugin( $plugin );
if ( is_wp_error( $activated ) ) {
return false;
}
return true;
}
public function get_required_plugins() {
return [
[
"slug" => "stripe",
"name" => "Stripe"
],
[
"slug" => "fb",
"name" => "Funnel Builder"
]
];
}
}
if ( bwfan_is_woocommerce_active() && bwfan_is_funnel_builder_pro_active() ) {
WFCO_Load_Connectors::register( 'BWFCO_Stripe' );
}
}

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' );

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