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,28 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
abstract class TD_NM_Action_Abstract {
/** @var array */
protected $settings;
public function __construct( $settings ) {
$this->settings = $settings;
}
abstract public function execute( $prepare_data );
abstract public function prepare_email_sign_up_data( $sign_up_data );
abstract public function prepare_split_test_ends_data( $split_test_ends_data );
abstract public function prepare_testimonial_submitted_data( $testimonial_data );
}

View File

@@ -0,0 +1,126 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Action_Custom_Script extends TD_NM_Action_Abstract {
public function execute( $prepared_data ) {
$url = $this->settings['url'];
wp_remote_post( $url, array(
'body' => $prepared_data
) );
}
public function prepare_email_sign_up_data( $sign_up_data ) {
$data = array();
$tl_item = $sign_up_data[0];
$tl_form = $sign_up_data[2];
$tl_data = $sign_up_data[4];
$data['thrv_event'] = 'thrv_signup';
$data['source'] = $tl_item->post_type;
$data['source_name'] = $tl_item->post_title;
$data['source_id'] = $tl_item->ID;
$data['source_form_name'] = $tl_form['post_title'];
$data['source_form_id'] = $tl_form['key'];
$data['user_email'] = $tl_data['email'];
$data['user_custom_data'] = $tl_data['custom_fields'];
$labels = array();
if ( ! empty( $tl_data['tve_labels'] ) ) {
$base64_decoded = base64_decode( $tl_data['tve_labels'] );
$labels = thrive_safe_unserialize( $base64_decoded );
}
if ( is_array( $labels ) && ! empty( $labels ) ) {
foreach ( $labels as $input_name => $label ) {
$label = sanitize_text_field( $label );
$data['user_custom_data'][ $label ] = ! empty( $tl_data['custom_fields'][ $input_name ] ) ? $tl_data['custom_fields'][ $input_name ] : null;
}
}
return $data;
}
public function prepare_split_test_ends_data( $split_test_ends_data ) {
$data = array();
$test_item = $split_test_ends_data[0];
$test = $split_test_ends_data[1];
$data['thrv_event'] = 'split_test';
$data['test_id'] = $test->id;
$data['test_url'] = $test->url;
$data['winning_variation_name'] = $test_item->variation['post_title'];
$data['winning_variation_id'] = $test_item->variation['key'];
return $data;
}
public function prepare_testimonial_submitted_data( $testimonial_data ) {
$data = array();
$testimonial = $testimonial_data[0];
$extra_data = $testimonial_data[1];
$data['id'] = $testimonial['id'];
$data['title'] = $testimonial['title'];
$data['date'] = $testimonial['date'];
$data['content'] = $testimonial['summary'];
$data['role'] = $testimonial['role'];
$data['name'] = $testimonial['name'];
$data['email'] = $testimonial['email'];
$data['website_url'] = $testimonial['website_url'];
$data['picture_url'] = $testimonial['picture_url'];
if ( ! empty( $testimonial['tags'] ) && is_array( $testimonial['tags'] ) ) {
$tags_text_arr = array();
foreach ( $testimonial['tags'] as $tag ) {
$tags_text_arr[] = $tag['text'];
}
$data['tags'] = implode( ',', $tags_text_arr );
}
return $data;
}
public function prepare_quiz_completion_data( $data ) {
$quiz = $data[0];
$user = $data[1];
$data = array(
'quiz' => array(
'Name' => $quiz->post_title
),
'quiz_user' => array(
'result' => $user['points'],
'email' => ! empty( $user['email'] ) ? $user['email'] : __( 'unknown', 'thrive-dash' ),
'date_started' => $user['date_started'],
),
'original_data' => $data,
);
$data = apply_filters( 'td_nm_custom_script_quiz_completion', $data );
if ( ! is_array( $data ) ) {
$data = array();
}
$return = array(
'quiz' => ! empty( $data['quiz'] ) ? $data['quiz'] : null,
'user' => ! empty( $data['quiz_user'] ) ? $data['quiz_user'] : null,
);
return $return;
}
}

View File

@@ -0,0 +1,313 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Action_Send_Email_Notification extends TD_NM_Action_Abstract {
public function execute( $prepared_data ) {
$connection = $this->get_service();
$email_data = array(
'emails' => $this->get_emails(),
'subject' => $this->get_subject( $prepared_data ),
'text_content' => $this->get_text_content( $prepared_data ),
'html_content' => $this->get_html_content( $prepared_data ),
);
if ( ! $connection ) {
return $this->sendMultipleEmails( $email_data );
}
try {
$connection->sendMultipleEmails( $email_data );
} catch ( Exception $e ) {
global $wpdb;
/**
* at this point, we need to log the error in a DB table, so that the user can see all these error later on and (maybe) re-subscribe the user
*/
$log_data = array(
'date' => date( 'Y-m-d H:i:s' ),
'error_message' => sanitize_textarea_field( $e->getMessage() ),
'api_data' => serialize( tve_sanitize_data_recursive( $prepared_data ) ),
'connection' => $connection->get_key(),
'list_id' => 'asset',
);
$wpdb->insert( $wpdb->prefix . 'tcb_api_error_log', $log_data );
}
}
public function prepare_email_sign_up_data( $sign_up_data ) {
$data = array();
$tl_item = $sign_up_data[0];
$tl_form = $sign_up_data[2];
$tl_data = $sign_up_data[4];
$lead_details['source'] = $tl_item->post_type;
$lead_details['source_name'] = $tl_item->post_title;
$lead_details['source_id'] = $tl_item->ID;
$lead_details['source_form_name'] = $tl_form['post_title'];
$lead_details['source_form_id'] = $tl_form['key'];
/*Send also the custom fields to the lead_detail shortcode*/
foreach ( $tl_data['custom_fields'] as $key => $value ) {
$lead_details[ 'custom_' . $key ] = $value;
}
$data['lead_details'] = $lead_details;
$data['lead_email'] = $tl_data['email'];
return $data;
}
public function prepare_split_test_ends_data( $split_test_ends_data ) {
$data = array();
$test_item = $split_test_ends_data[0];
$test = $split_test_ends_data[1];
$test_details['thrv_event'] = 'split_test';
$test_details['test_id'] = $test->id;
$test_details['test_url'] = $test->url;
$test_details['winning_variation_name'] = $test_item->variation['post_title'];
$test_details['winning_variation_id'] = $test_item->variation['key'];
$data['test_details'] = $test_details;
$data['test_link'] = $test->url;
return $data;
}
public function prepare_testimonial_submitted_data( $testimonial_data ) {
$data = array();
$testimonial = $testimonial_data[0];
unset( $testimonial['id'] );
unset( $testimonial['content'] );
unset( $testimonial['status'] );
unset( $testimonial['source'] );
foreach ( $testimonial as $key => $value ) {
if ( ! empty( $value ) ) {
if ( is_string( $value ) ) {
$testimonial_details[ $key ] = $value;
} elseif ( is_array( $value ) ) {
$aux = array();
foreach ( $value as $val ) {
$aux[] = ( ! empty( $val['text'] ) ) ? $val['text'] : '';
}
$testimonial_details[ $key ] = implode( ',', $aux );
}
}
}
$data['lead_details'] = $testimonial_details;
return $data;
}
/**
* @return bool|Thrive_Dash_List_Connection_Abstract
*/
public function get_service() {
$connection = get_option( 'tvd-nm-email-service', false );
if ( ! $connection ) {
return false;
}
return Thrive_Dash_List_Manager::connection_instance( $connection );
}
/**
* returns an array of emails from settings->recipients
*
* @return array
*/
public function get_emails() {
$emails = array();
foreach ( $this->settings['recipients'] as $item ) {
$emails[] = $item['value'];
}
return $emails;
}
public function get_html_content( $prepared_data ) {
$content = $this->settings['message']['content'];
$item_details = '';
if ( isset( $prepared_data['lead_details'] ) ) {
foreach ( $prepared_data['lead_details'] as $key => $value ) {
$item_details .= "<p><strong>{$key}</strong>:\n {$value}</p>";
}
}
if ( isset( $prepared_data['quiz'] ) ) {
foreach ( $prepared_data['quiz'] as $key => $value ) {
$item_details .= "<p><strong>{$key}</strong>:\n <span>{$value}</span></p>";
}
}
if ( isset( $prepared_data['quiz_user'] ) ) {
foreach ( $prepared_data['quiz_user'] as $key => $value ) {
$item_details .= "<p><strong>{$key}</strong>:\n <span>{$value}</span></p>";
}
}
if ( ! empty( $prepared_data['quiz_user_flow'] ) ) {
foreach ( $prepared_data['quiz_user_flow'] as $key => $item ) {
$item_details .= "<p><strong>{$item['question']}</strong>\n<span>{$item['answer']}</span></p>";
}
}
$lead_email = '';
if ( isset( $prepared_data['lead_email'] ) ) {
$lead_email .= "email: " . $prepared_data['lead_email'];
}
if ( stripos( $content, '[lead_email]' ) !== false ) {
$content = str_replace( '[lead_email]', $lead_email, $content );
}
$keywords = array( '[lead_details]', '[testimonial_details]', '[quiz_details]' );
foreach ( $keywords as $keyword ) {
if ( stripos( $content, $keyword ) !== false ) {
$content = str_replace( $keyword, $item_details, $content );
}
}
preg_match( '@\[test_link\](.+)\[/test_link\]@', $content, $matches );
if ( ! empty( $matches ) ) {
$content = str_replace( $matches[0], '<a href="' . $prepared_data["test_link"] . '">' . $matches[1] . '</a>', $content );
}
$content = nl2br( $content );
return $content;
}
public function get_text_content( $prepared_data ) {
$content = $this->settings['message']['content'];
$item_details = "\n";
if ( isset( $prepared_data['lead_details'] ) ) {
foreach ( $prepared_data['lead_details'] as $key => $value ) {
$item_details .= "{$key}: {$value}\n";
}
}
if ( isset( $prepared_data['quiz'] ) ) {
$item_details .= "\nQuiz Details:\n";
foreach ( $prepared_data['quiz'] as $key => $value ) {
$item_details .= "{$key}: {$value}\n";
}
}
if ( isset( $prepared_data['quiz_user'] ) ) {
$item_details .= "\nUser Details:\n";
foreach ( $prepared_data['quiz_user'] as $key => $value ) {
$item_details .= "{$key}: {$value}\n";
}
}
$lead_email = '';
if ( isset( $prepared_data['lead_email'] ) ) {
$lead_email .= "email: " . $prepared_data['lead_email'];
}
if ( stripos( $content, '[lead_details]' ) !== false ) {
$content = str_replace( '[lead_details]', $item_details, $content );
}
if ( stripos( $content, '[lead_email]' ) !== false ) {
$content = str_replace( '[lead_email]', $lead_email, $content );
}
preg_match( '@\[test_link\](.+)\[/test_link\]@', $content, $matches );
if ( ! empty( $matches ) ) {
$content = str_replace( $matches[0], $prepared_data["test_link"], $content );
}
return $content;
}
public function get_subject( $prepared_data ) {
$subject = $this->settings['message']['subject'];
if ( stristr( $subject, '[lead_email]' ) !== false ) {
$subject = str_replace( '[lead_email]', $prepared_data['lead_email'], $subject );
}
return $subject;
}
public function prepare_quiz_completion_data( $data ) {
$quiz = $data[0];
$user = $data[1];
$data = array(
'quiz' => array(
'Quiz Name' => $quiz->post_title,
),
'quiz_user' => array(
'Quiz Result' => $user['points'],
'Email' => ! empty( $user['email'] ) ? $user['email'] : __( 'unknown', 'thrive-dash' ),
'Date started' => $user['date_started'],
),
'original_data' => $data,
);
$filtered = apply_filters( 'td_nm_email_notification_quiz_completion', $data );
if ( ! is_array( $filtered ) ) {
$filtered = array();
}
$return = array(
'quiz' => ! empty( $filtered['quiz'] ) ? $filtered['quiz'] : null,
'quiz_user' => ! empty( $filtered['quiz_user'] ) ? $filtered['quiz_user'] : null,
'quiz_user_flow' => array(),
);
if ( ! empty( $user['flow'] ) ) {
foreach ( $user['flow'] as $question ) {
foreach ( $question['answers'] as $answer ) {
if ( ! empty( $answer['chosen'] ) ) {
$return['quiz_user_flow'][] = array(
'question' => $question['text'],
'answer' => (int) $question['q_type'] === 3 ? $answer['answer_text'] : $answer['text'],
);
}
}
}
}
return $return;
}
protected function sendMultipleEmails( $data ) {
$to = $data['emails'];
$subject = $data['subject'];
$message = $data['html_content'];
$headers = array( 'Content-Type: text/html; charset=UTF-8' );
$sent = wp_mail( $to, $subject, $message, $headers );
return $sent;
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Action_Wordpress_Notification extends TD_NM_Action_Abstract {
public function execute( $prepared_data ) {
preg_match_all( '/\\[link\\].*?\\[\/link\\]/is', $this->settings['message']['content'], $matches );
$message = $this->settings['message']['content'];
$message = sanitize_textarea_field( $message );
if ( ! empty( $matches ) && isset( $matches[0] ) ) {
foreach ( $matches[0] as $expression ) {
preg_match( '#\\[link\\](.+)\\[/link\\]#s', $expression, $expression_match );
$message = str_replace( $expression_match[0], '<a href="javascript:void(0);" onclick="ThriveNMWordpressNotification.functions.trigger_dismiss_notice(' . $this->settings['notification_id'] . ')">' . $expression_match[1] . '</a>', $message );
}
}
$meta_value = array( 'url' => $prepared_data['test_url'], 'message' => $message );
update_post_meta( $this->settings['notification_id'], 'td_nm_wordpress_notification', $meta_value );
}
public function prepare_email_sign_up_data( $sign_up_data ) {
$data = array();
$tl_item = $sign_up_data[0];
$tl_form = $sign_up_data[1];
$data['source'] = $tl_item->post_type;
$data['key'] = $tl_form->ID;
$data['test_url'] = admin_url( 'admin.php?page=thrive_leads_dashboard' ) . '#form-type/' . $tl_form->ID;
$data['trigger_source'] = 'leads';
return $data;
}
public function prepare_split_test_ends_data( $split_test_ends_data ) {
$data = array();
$test_item = $split_test_ends_data[0];
$test = $split_test_ends_data[1];
$data['key'] = $test_item->test_id;
$data['trigger_source'] = $test->trigger_source;
$data['test_url'] = $test->url;
return $data;
}
public function prepare_testimonial_submitted_data( $testimonial_data ) {
$data = array();
$testimonial = $testimonial_data[0];
$extra_data = $testimonial_data[1];
$data['test_url'] = $extra_data['url'];
$data['key'] = $testimonial['id'];
return $data;
}
public function prepare_quiz_completion_data( $data ) {
return array(
'test_url' => admin_url( 'admin.php?page=tqb_admin_dashboard' ) . '#dashboard/quiz/' . $data[0]->ID,
);
}
}

View File

@@ -0,0 +1,256 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Admin_Ajax_Controller {
protected static $_instance;
/**
* TD_NM_Admin_Ajax_Controller constructor.
* Protected constructor because we want to use it as singleton
*/
protected function __construct() {
}
/**
* Gets the SingleTone's instance
*
* @return TD_NM_Admin_Ajax_Controller
*/
public static function instance() {
if ( empty( static::$_instance ) ) {
static::$_instance = new static();
}
return static::$_instance;
}
/**
* Sets the request's header with server protocol and status
* Sets the request's body with specified $message
*
* @param $message
* @param string $status
*/
protected function error( $message, $status = '404 Not Found' ) {
status_header( 400 );
wp_send_json( array(
'error' => $message,
) );
return $message;
}
/**
* Returns the params from $_POST or $_REQUEST
*
* @param $key
* @param null $default
*
* @return mixed|null|$default
*/
protected function param( $key, $default = null ) {
return isset( $_POST[ $key ] ) ? map_deep( $_POST[ $key ], 'sanitize_text_field' ) : ( isset( $_REQUEST[ $key ] ) ? map_deep( $_REQUEST[ $key ], 'sanitize_text_field' ) : $default );
}
public function handle() {
if ( ! check_ajax_referer( 'td_nm_admin_ajax_request', '_nonce', false ) ) {
$this->error( sprintf( __( 'Invalid request', 'thrive-dash' ) ) );
}
$route = $this->param( 'route' );
$route = preg_replace( '#([^a-zA-Z0-9-])#', '', $route );
$method_name = $route . '_action';
if ( ! method_exists( $this, $method_name ) ) {
$this->error( sprintf( __( 'Method %s not implemented', 'thrive-dash' ), $method_name ) );
}
return $this->{$method_name}();
}
public function notification_action() {
$model = json_decode( file_get_contents( 'php://input' ), true );
$method = empty( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ? 'GET' : sanitize_text_field( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
switch ( $method ) {
case 'POST':
case 'PUT':
case 'PATCH':
if ( ! ( $item = td_nm_save_notification( $model ) ) ) {
$this->error( __( 'Notification could not be saved', 'thrive-dash' ) );
}
return $item;
break;
case 'DELETE':
$id = $this->param( 'ID' );
if ( empty( $id ) ) {
$this->error( __( 'Invalid parameters in delete', 'thrive-dash' ) );
}
if ( ( $deleted = td_nm_delete_notification( $id ) ) === false ) {
$this->error( __( 'Notification could not be deleted', 'thrive-dash' ) );
}
return $deleted;
break;
}
}
public function action_action() {
$model = json_decode( file_get_contents( 'php://input' ), true );
$model = tve_sanitize_data_recursive( $model, 'sanitize_textarea_field' );
$method = empty( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ? 'GET' : sanitize_text_field( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
switch ( $method ) {
case 'POST':
case 'PUT':
case 'PATCH':
$old_actions = td_nm_get_actions( $model['notification_id'] );
$update_actions = $old_actions;
$id = null;
if ( is_numeric( $model['ID'] ) ) { //update because we have ID
$update_actions[ $model['ID'] ] = $model;
$id = $model['ID'];
} else { //push new model in array
$update_actions[] = $model;
$id = count( $update_actions ) - 1; // The first action index is 0.
}
if ( $old_actions == $update_actions ) {
return $id;
}
if ( td_nm_save_actions( $update_actions, $model['notification_id'] ) === false ) {
$this->error( __( 'Action could not be saved', 'thrive-dash' ) );
}
return $id;
break;
case 'DELETE':
$saved = false;
if ( ! is_numeric( $this->param( 'ID' ) ) || ! is_numeric( $this->param( 'notification_id' ) ) ) {
$this->error( __( 'Invalid parameters in delete', 'thrive-dash' ) );
}
$actions = td_nm_get_actions( $this->param( 'notification_id' ) );
if ( ! empty( $actions ) ) {
unset( $actions[ $this->param( 'ID' ) ] );
$actions = array_values( $actions );
foreach ( $actions as $key => &$item ) {
$item['ID'] = $key;
}
if ( ( $saved = td_nm_save_actions( $actions, $this->param( 'notification_id' ) ) ) === false ) {
$this->error( __( 'Action could not be deleted', 'thrive-dash' ) );
}
}
return $saved;
break;
}
}
public function trigger_action() {
$model = json_decode( file_get_contents( 'php://input' ), true );
$method = empty( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] ) ? 'GET' : sanitize_text_field( $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] );
switch ( $method ) {
case 'POST':
case 'PUT':
case 'PATCH':
if ( ( $saved = td_nm_save_trigger( $model, $model['ID'] ) ) === false ) {
$this->error( __( 'Trigger could not be saved', 'thrive-dash' ) );
}
return $saved;
break;
}
}
/**
* Set which connection should be used for sending emails
* Updates an WP Option
*
* @return bool
*/
public function toggleservice_action() {
$connection = '';
if ( (int) $this->param( 'active' ) ) {
$connection = $this->param( 'service' );
}
update_option( 'tvd-nm-email-service', $connection );
return true;
}
/**
* Save API Connection by using API List Manager
*
* @return mixed
*/
public function setupconnection_action() {
$connection = Thrive_Dash_List_Manager::connection_instance( $this->param( 'api' ) );
$_POST['api'] = $this->param( 'api' );
$_POST['connection'] = $this->param( 'connection' );
if ( is_string( $saved = $connection->read_credentials() ) ) {
$this->error( $saved );
}
update_option( 'tvd-nm-email-service', $this->param( 'api' ) );
return $saved;
}
/**
* Tests an API Connection
*
* @return string
*/
public function connectiontest_action() {
$connection = Thrive_Dash_List_Manager::connection_instance( $this->param( 'service' ) );
return is_string( $tested = $connection->test_connection() ) ? $this->error( $tested ) : array( 'success' => __( 'Connection OK', 'thrive-dash' ) );
}
/**
* Deletes a wordpress notification from the post meta table
*
* @return bool
*/
public function deletenotification_action() {
$key = $this->param( 'key' );
if ( ! empty( $key ) && is_numeric( $key ) ) {
$return = array();
if ( $this->param( 'redirect' ) == true ) {
$post_meta_value = get_post_meta( $key, 'td_nm_wordpress_notification', true );
$return['redirect_url'] = $post_meta_value['url'];
}
$return['status'] = delete_post_meta( $key, 'td_nm_wordpress_notification' );
wp_send_json( $return );
} else {
$this->error( __( 'Invalid parameter type', 'thrive-dash' ) );
}
return false;
}
}

View File

@@ -0,0 +1,359 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
/**
* Class TD_NM_Admin
*/
class TD_NM_Admin {
private $_dashboard_page = 'tve_dash_notification_manager';
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
add_action( 'init', array( $this, 'includes' ) );
add_action( 'current_screen', array( $this, 'conditional_hooks' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'admin_notices', array( $this, 'td_nm_get_wordpress_notifications' ) );
}
public function init() {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_styles' ) );
}
public function includes() {
}
public function enqueue_styles() {
tve_dash_enqueue_style( 'td-nm-admin', TD_NM()->url( 'assets/css/admin.css' ) );
}
public function enqueue_scripts() {
if ( tve_get_current_screen_key() === 'admin_page_tve_dash_notification_manager' ) {
$current_user = wp_get_current_user();
tve_dash_enqueue();
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'backbone' );
tve_dash_enqueue_script( 'td-nm-admin', TD_NM()->url( 'assets/js/admin/backbone.min.js' ), array(
'tve-dash-main-js',
'jquery',
'backbone',
), false, true );
$params = array(
't' => include TD_NM()->path( 'i18n.php' ),
'dash_url' => admin_url( 'admin.php?page=tve_dash_section' ),
'url' => TD_NM()->url(),
'trigger_types' => TD_NM()->get_trigger_types(),
'action_types' => TD_NM()->get_action_types(),
'tl' => array(
'groups' => $this->get_tl_groups(),
'shortcodes' => $this->get_tl_shortcodes(),
'thrive_boxes' => $this->get_tl_thrive_boxes(),
),
'tqb' => array(
'quizzes' => $this->get_quizzes(),
),
'current_user_email' => $current_user->user_email,
'message_shortcodes' => TD_NM()->get_message_shortcodes(),
'split_tests' => $this->get_split_tests(),
'admin_nonce' => wp_create_nonce( 'td_nm_admin_ajax_request' ),
'notifications' => td_nm_get_notifications(),
'email_services' => $this->get_email_services(),
);
wp_localize_script( 'td-nm-admin', 'TD_NM', $params );
}
}
public function get_quizzes() {
$quizzes = array();
if ( class_exists( 'TQB_Quiz_Manager' ) ) {
$temp_quizzes = TQB_Quiz_Manager::get_quizzes();
foreach ( $temp_quizzes as $quiz ) {
$quizzes[] = array(
'value' => $quiz->ID,
'label' => $quiz->post_title,
);
}
}
return $quizzes;
}
/**
* Hook into based on current screen
*/
public function conditional_hooks() {
$screen = tve_get_current_screen_key();
/**
* Main Dashboard section
*/
if ( $screen === 'toplevel_page_tve_dash_section' ) {
add_filter( 'tve_dash_filter_features', array( $this, 'admin_notification_feature' ) );
}
/**
* NM Dashboard
*/
if ( $screen === 'admin_page_tve_dash_notification_manager' ) {
add_action( 'admin_print_footer_scripts', array( $this, 'admin_backbone_templates' ) );
}
}
/**
* Push in the Notification Manager Feature to be displayed on Dashboard Thrive Features Section
*
* @param $features
*
* @return mixed
*/
public function admin_notification_feature( $features ) {
$features['notification_manager'] = array(
'icon' => 'tvd-icon-notification',
'title' => 'Notification Manager',
'description' => __( 'Receive notifications when certain events occur on your site', 'thrive-dash' ),
'btn_link' => add_query_arg( 'page', $this->_dashboard_page, admin_url( 'admin.php' ) ),
'btn_text' => __( "Manage Notifications", 'thrive-dash' ),
);
return $features;
}
/**
* Add page to admin menu so the page could be accessed
*/
public function admin_menu() {
add_submenu_page( '', __( 'Notification Manager', 'thrive-dash' ), __( 'Notification Manager', 'thrive-dash' ), TVE_DASH_CAPABILITY, $this->_dashboard_page, array(
$this,
'admin_dashboard',
) );
}
/**
* Main TD_NM page content
*/
public function admin_dashboard() {
ob_start(); ?>
<div id="tvd-nm-header"></div>
<div class="tvd-nm-breadcrumbs-wrapper" id="tvd-nm-breadcrumbs-wrapper"></div>
<div id="tvd-nm-wrapper"></div><?php
echo ob_get_clean(); // phpcs:ignore;
}
/**
* Append the backbone templates to source to be later used by Backbone scripts
*/
public function admin_backbone_templates() {
$templates = tve_dash_get_backbone_templates( TD_NM()->path( 'includes/admin/views/backbone' ) );
tve_dash_output_backbone_templates( $templates );
}
/**
* Get TL Groups if the plugin/function is available
*
* @return array
*/
public function get_tl_groups() {
$db = function_exists( 'tve_leads_get_groups' ) ? tve_leads_get_groups() : array();
$items = array();
foreach ( $db as $post ) {
$items[] = array(
'value' => $post->ID,
'label' => $post->post_title,
);
}
return $items;
}
/**
* Get TL Shortcodes if the plugin/function is available
*
* @return array
*/
public function get_tl_shortcodes() {
$db = function_exists( 'tve_leads_get_shortcodes' ) ? tve_leads_get_shortcodes() : array();
$items = array();
foreach ( $db as $post ) {
$items[] = array(
'value' => $post->ID,
'label' => $post->post_title,
);
}
return $items;
}
/**
* Get TL ThriveBoxes if the plugin/function is available
*
* @return array
*/
public function get_tl_thrive_boxes() {
$db = function_exists( 'tve_leads_get_two_step_lightboxes' ) ? tve_leads_get_two_step_lightboxes() : array();
$items = array();
foreach ( $db as $post ) {
$items[] = array(
'value' => $post->ID,
'label' => $post->post_title,
);
}
return $items;
}
public function get_split_tests() {
/** @var $tvedb Thrive_Leads_DB */
global $tvedb;
/** @var $tvedb Tho_Db */
global $thodb;
/** @var TQB_Database */
global $tqbdb;
$tests = array(
'tl' => array(),
'tho' => array(),
'tqb' => array(),
'tab' => array(),
);
if ( $tvedb ) {
$lead_tests = $tvedb->tve_leads_get_tests( array(
'status' => defined( 'TVE_LEADS_STATUS_RUNNING' ) ? TVE_LEADS_STATUS_RUNNING : 'running',
) );
foreach ( $lead_tests as $test ) {
$tests['tl'][] = array(
'value' => $test->id,
'label' => $test->title,
);
}
}
if ( $thodb ) {
$headline_tests = $thodb->get_tests( array( 'status' => THO_TEST_STATUS_ACTIVE ) );
foreach ( $headline_tests as $test ) {
$tests['tho'][] = array(
'value' => $test->id,
'label' => get_the_title( $test->post_id ),
);
}
}
if ( $tqbdb ) {
$tqb_tests = $tqbdb->get_tests( array(
'status' => 1,
) );
foreach ( $tqb_tests as $test ) {
$tests['tqb'][] = array(
'value' => $test['id'],
'label' => $test['title'],
);
}
}
if ( class_exists( 'Thrive_AB_Test_Manager' ) ) {
$tab_test_manager = new Thrive_AB_Test_Manager();
$tab_tests = $tab_test_manager->get_tests( array(
'status' => 'running',
) );
foreach ( $tab_tests as $test ) {
$tests['tab'][] = array(
'value' => $test['id'],
'label' => $test['title'],
);
}
}
return $tests;
}
public function get_email_services() {
$email_services = Thrive_Dash_List_Manager::get_available_apis( false, [ 'include_types' => [ 'email' ] ] );
$connected_services = Thrive_Dash_List_Manager::get_available_apis( true, [ 'include_types' => [ 'email' ] ] );
$connected_keys = array_keys( $connected_services );
$active_connection = get_option( 'tvd-nm-email-service' );
$items = array();
/**
* @var string $key
* @var Thrive_Dash_List_Connection_Abstract $instance
*/
foreach ( $email_services as $key => $instance ) {
$item = array(
'key' => $key,
'title' => $instance->get_title(),
'connected' => in_array( $key, $connected_keys ),
'active' => $key === $active_connection,
'status' => in_array( $key, $connected_keys ) ? __( 'connected', 'thrive-dash' ) : __( 'Unset', 'thrive-dash' ),
);
$items[] = $item;
}
return $items;
}
/**
* Displays WordPress notifications
*/
public function td_nm_get_wordpress_notifications() {
global $wpdb;
$results = $wpdb->get_results( "select post_id from $wpdb->postmeta where meta_key = 'td_nm_wordpress_notification'", ARRAY_A );
if ( ! empty( $results ) ) {
/*Enqueue Script*/
wp_enqueue_script( 'tve-nm-wordpress-notification-js', TD_NM()->url( 'assets/js/admin/wordpress_notification.js' ) );
$thrive_nm_special_routes = array(
'nonce' => wp_create_nonce( 'td_nm_admin_ajax_request' ),
'routes' => array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
),
);
wp_localize_script( 'tve-nm-wordpress-notification-js', 'ThriveNMWordpressNotification', $thrive_nm_special_routes );
foreach ( $results as $post ) {
$post_meta_value = get_post_meta( $post['post_id'], 'td_nm_wordpress_notification', true );
/**
* $post_meta_value['message'] can contain HTML tags
* The string can be of this form:
*
* A new quiz completion was registered. <a href="#">Click here to see the Quiz</a>
*/
printf( '<div data-key="%1$s" class="%2$s"><p>%3$s</p></div>', absint( $post['post_id'] ), 'notice notice-success td_nm_wordpress_notice is-dismissible', strip_tags( $post_meta_value['message'], '<a>' ) );
}
}
}
}
return new TD_NM_Admin();

View File

@@ -0,0 +1,8 @@
<div class="<#= item.get('disable') ? 'tvd-hide' : '' #> tvd-col tvd-s6 tvd-m3 tvd-nm-action-type" data-action-type="<#= item.get('key') #>">
<div class="tvd-center-align tvd-card tvd-white tvd-pointer">
<i class="<#= item.get('icon') #> tvd-nm-large-icon tvd-blue-text"></i>
<p class="tvd-center-align tvd-margin-bottom">
<#= item.get('label') #>
</p>
</div>
</div>

View File

@@ -0,0 +1,6 @@
<h4><?php echo __( 'Custom Script Settings', 'thrive-dash' ) ?></h4>
<p><?php echo sprintf( __( 'When the selected event occurs, Thrive will call the script and pass the event type and any associated data. %s', 'thrive-dash' ), '<a class="tvd-blue-text" target="_blank" href="https://thrivethemes.com/tkb_item/how-to-call-a-custom-script-using-the-notification-manager/">' . __( 'Learn more about how this works and what data is passed', 'thrive-dash' ) . '</a>' ) ?></p>
<div class="tvd-input-field">
<input id="tvd-nm-custom-script-url" type="text" data-bind="url" value="<#= item.get('url') #>">
<label for="tvd-nm-custom-script-url"><?php echo __( 'URL of Custom Script', 'thrive-dash' ) ?></label>
</div>

View File

@@ -0,0 +1,9 @@
<div id="tvd-nm-recipients-wrapper"></div>
<div class="tvd-row">
<div class="tvd-col12">
<a id="tvd-nm-add-recipient" class="tvd-btn-flat tvd-btn-flat-secondary tvd-btn-flat-blue tvd-btn-margin-top tvd-waves-effect tvd-right">
<?php echo __( 'Add recipient', 'thrive-dash' ) ?>
</a>
</div>
</div>
<div id="tvd-nm-message-wrapper"></div>

View File

@@ -0,0 +1,3 @@
<h4><?php echo __( 'WordPress Notification Settings', 'thrive-dash' ) ?></h4>
<p><?php echo __( 'When the selected event occurs, an WordPress notification will be displayed in Admin Dashboard section', 'thrive-dash' ) ?></p>
<div id="tvd-nm-message-wrapper"></div>

View File

@@ -0,0 +1,9 @@
<ul class="tvd-nm-breadcrumbs">
<# links.each( function( item, index ) { item.has_link = index < links.size() - 1 #>
<li class="tvd-breadcrumb <#= ( item.has_link ? '' : ' tvu-no-link' ) #>">
<# if ( item.has_link ) { #><a href="<#= item.get_url() #>"><# } #>
<#= _.escape ( item.get ( 'label' ) ) #>
<# if ( item.has_link ) { #></a><# } #>
</li>
<# } ) #>
</ul>

View File

@@ -0,0 +1,16 @@
<div class="tvd-row">
<div class="tvd-col tvd-s12 tvd-m12 tvd-l12">
<h3 class="tvd-title tvd-left">
<?php echo __( 'Notifications', 'thrive-dash' ) ?>
<a data-source="qCY1Gq9PZv4" class="tvd-open-video">
<span class="tvd-icon-play"></span>
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</h3>
<a href="javascript:void(0)" id="" class="tvd-left tvd-btn tvd-btn-blue tvd-waves-effect tvd-waves-light tvd-nm-create-notification">
<?php echo __( 'Add New', 'thrive-dash' ) ?>
</a>
</div>
</div>
<div id="tvd-nm-notifications-list"></div>

View File

@@ -0,0 +1,26 @@
<nav id="tvd-nav">
<div class="tvd-nav">
<div class="nav-wrapper">
<div class="tve-logo tvd-left">
<a href="<?php echo admin_url( 'admin.php?page=tve_dash_notification_manager' ) ?>"
title="<?php echo __( 'Thrive Notification Manager', 'thrive-dash' ) ?>">
<img alt="<?php echo __( 'Thrive logo', 'thrive-dash' ) ?>" src="<?php echo TVE_DASH_URL; ?>/css/images/thrive-logo.png"/>
</a>
</div>
<ul id="tvd-dash-submenu" class="tvd-right">
<li>
<a id="td-nm-email-services" href="javascript:void(0)">
<i class="tvd-icon-paper-plane"></i>
<?php echo __( 'Email Delivery Setup', 'thrive-dash' ) ?>
</a>
</li>
<li>
<a id="tvd-share-modal" class="tvd-modal-trigger" href="#tvd-modal1" data-overlay_class="tvd-white-bg" data-opacity=".95">
<span class="tvd-icon-heart"></span>
</a>
</li>
</ul>
</div>
</div>
</nav>
<?php include TVE_DASH_PATH . '/templates/share.phtml'; ?>

View File

@@ -0,0 +1,17 @@
<div class="tvd-row">
<div class="tvd-input-field">
<input id="tvd-nm-message-subject" type="text" data-bind="subject" data-field="subject" value="<#- item.get('subject') #>">
<label for="tvd-nm-message-subject"><?php echo __( 'Subject', 'thrive-dash' ) ?></label>
</div>
</div>
<div class="tvd-row">
<div class="tvd-input-field">
<textarea id="tvd-nm-message-content" class="tvd-materialize-textarea" data-bind="content" data-field="content"><#= item.get('content') #></textarea>
<label for="tvd-nm-message-content"><?php echo __( 'Message', 'thrive-dash' ) ?></label>
</div>
</div>
<div id="tvd-nm-message-shortcodes-wrapper">
<h4 class="tvd-nm-inline-display tvd-nm-toggle-display tvd-nm-toggle-display-text"><?php echo __( 'Hide available shortcodes', 'thrive-dash' ) ?></h4>
<span class="tvd-nm-icon-angle-down tvd-nm-inline-display tvd-right tvd-nm-toggle-display tvd-nm-toggle-display-icon"></span>
<div id="tvd-nm-message-shortcodes-container"></div>
</div>

View File

@@ -0,0 +1,17 @@
<div class="tvd-row tvd-copy-row">
<div class="tvd-col tvd-s3">
<div class="tvd-input-field tvd-margin-top-small">
<input readonly="readonly" type="text" value="<#= item.get('shortcode') #>" class="tvd-no-margin tvd-copy">
</div>
</div>
<div class="tvd-col tvd-s2">
<span class="">
<a class="tvd-waves-effect tvd-waves-light tvd-btn tvd-btn-blue tvd-btn-small tvd-margin-top-small tvd-copy-to-clipboard" href="javascript:void(0)">
<span class="tvd-copy-text"><?php echo __( 'Copy', 'thrive-dash' ) ?></span>
</a>
</span>
</div>
<div class="tvd-col tvd-s7 tvd-ver">
<span class="tvd-small-text tvd-nm-shortcode-label"><#= item.get('label') #></span>
</div>
</div>

View File

@@ -0,0 +1,23 @@
<div class="tvd-modal-content">
<h3 class="tvd-modal-title"><?php echo __( 'Add New Action', 'thrive-dash' ) ?></h3>
<div id="tvd-nm-notification-summary"></div>
<p><?php echo __( 'Select what action you want to be performed and fill the required fields. A notification accepts only one action for each type.', 'thrive-dash' ) ?></p>
<div id="tvd-nm-action-types" class="tvd-row tvd-collapse"></div>
<div id="tvd-nm-action-settings"></div>
</div>
<div class="tvd-modal-footer">
<div class="tvd-row">
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)"
class="tvd-btn-flat tvd-btn-flat-secondary tvd-btn-flat-dark tvd-waves-effect tvd-modal-close">
<?php echo __( 'Cancel', 'thrive-dash' ) ?>
</a>
</div>
<div class="tvd-col tvd-s6">
<a href="javascript:void(0)"
class="tvd-waves-effect tvd-waves-light tvd-btn tvd-btn-green tvd-right tvd-modal-submit">
<?php echo __( 'Save Action', 'thrive-dash' ) ?>
</a>
</div>
</div>
</div>

View File

@@ -0,0 +1,49 @@
<div class="tvd-nm-modal-step">
<div class="tvd-modal-content">
<h3 class="tvd-modal-title"><?php echo __( "Create New Notification", 'thrive-dash' ) ?></h3>
<p><?php echo __( 'Step 1: Set your Trigger', 'thrive-dash' ) ?></p>
<div id="tvd-nm-trigger-types" class="tvd-row tvd-collapse"></div>
<div id="tvd-nm-trigger-settings" class="tvd-row tvd-collapse"></div>
</div>
<div class="tvd-modal-footer">
<div class="tvd-row">
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)"
class="tvd-btn-flat tvd-btn-flat-secondary tvd-btn-flat-dark tvd-waves-effect tvd-modal-close">
<?php echo __( 'Cancel', 'thrive-dash' ) ?>
</a>
</div>
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)"
class="tvd-waves-effect tvd-waves-light tvd-btn tvd-btn-green tvd-right tvd-nm-modal-next-step">
<?php echo __( 'Save and continue', 'thrive-dash' ) ?>
</a>
</div>
</div>
</div>
</div>
<div class="tvd-nm-modal-step">
<div class="tvd-modal-content">
<h3 class="tvd-modal-title"><?php echo __( "Create New Notification", 'thrive-dash' ) ?></h3>
<div id="tvd-nm-notification-summary"></div>
<p><?php echo __( 'Step 2: Set the action to be performed', 'thrive-dash' ) ?></p>
<div id="tvd-nm-action-types" class="tvd-row tvd-collapse"></div>
<div id="tvd-nm-action-settings"></div>
</div>
<div class="tvd-modal-footer">
<div class="tvd-row">
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)"
class="tvd-btn-flat tvd-btn-flat-secondary tvd-btn-flat-dark tvd-waves-effect tvd-nm-modal-prev-step">
<?php echo __( 'Back', 'thrive-dash' ) ?>
</a>
</div>
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)"
class="tvd-waves-effect tvd-waves-light tvd-btn tvd-btn-green tvd-right tvd-modal-submit">
<?php echo __( 'Save notification', 'thrive-dash' ) ?>
</a>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,23 @@
<div class="tvd-modal-content tvd-red">
<h3 class="tvd-modal-title tvd-center-align tvd-white-text">
<?php echo __( 'Are you sure you want to remove this?', 'thrive-dash' ); ?>
</h3>
<div class="tvd-v-spacer"></div>
</div>
<div class="tvd-modal-footer tvd-red">
<div class="tvd-row">
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)"
class="tvd-nm-delete-yes tvd-btn-flat tvd-btn-flat-secondary tvd-btn-flat-light tvd-left">
<?php echo __( 'YES, DELETE IT', 'thrive-dash' ); ?>
</a>
</div>
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)"
class="tvd-btn-flat tvd-btn-flat tvd-btn-flat-primary tvd-btn-flat-light tvd-right tvd-modal-close">
<?php echo __( 'NO, KEEP IT', 'thrive-dash' ); ?>
</a>
</div>
</div>
</div>
<a href="javascript:void(0)" class="tvd-modal-action tvd-modal-close tvd-modal-close-x tvd-white-text"><i class="tvd-icon-close2"></i></a>

View File

@@ -0,0 +1,22 @@
<div class="tvd-modal-content">
<h3 class="tvd-modal-title"></h3>
<div class="tvd-v-spacer"></div>
<div id="tvd-nm-action-types" class="tvd-row tvd-collapse"></div>
<div id="tvd-nm-action-settings"></div>
</div>
<div class="tvd-modal-footer">
<div class="tvd-row">
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)"
class="tvd-btn-flat tvd-btn-flat-secondary tvd-btn-flat-dark tvd-waves-effect tvd-modal-close">
<?php echo __( 'Cancel', 'thrive-dash' ) ?>
</a>
</div>
<div class="tvd-col tvd-s6">
<a href="javascript:void(0)"
class="tvd-waves-effect tvd-waves-light tvd-btn tvd-btn-green tvd-right tvd-modal-submit">
<?php echo __( 'Save Action', 'thrive-dash' ) ?>
</a>
</div>
</div>
</div>

View File

@@ -0,0 +1,21 @@
<div class="tvd-modal-content">
<h3 class="tvd-modal-title"><?php echo __( "Edit trigger", 'thrive-dash' ) ?></h3>
<div id="tvd-nm-trigger-types" class="tvd-row tvd-collapse"></div>
<div id="tvd-nm-trigger-settings" class="tvd-row tvd-collapse"></div>
</div>
<div class="tvd-modal-footer">
<div class="tvd-row">
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)"
class="tvd-btn-flat tvd-btn-flat-secondary tvd-btn-flat-dark tvd-waves-effect tvd-modal-close">
<?php echo __( 'Cancel', 'thrive-dash' ) ?>
</a>
</div>
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)"
class="tvd-waves-effect tvd-waves-light tvd-btn tvd-btn-green tvd-right tvd-modal-submit">
<?php echo __( 'Save Trigger', 'thrive-dash' ) ?>
</a>
</div>
</div>
</div>

View File

@@ -0,0 +1,64 @@
<div class="tvd-nm-modal-step">
<div class="tvd-modal-content">
<h3 class="tvd-modal-title"><?php echo __( "Email Delivery Setup", 'thrive-dash' ) ?></h3>
<p id="tvd-nm-connections-text"><?php echo __( 'Your existing connections', 'thrive-dash' ) ?></p>
<ul id="tvd-nm-connected-list"></ul>
<button class="tvd-btn-flat-blue tvd-btn-flat tvd-waves-effect tvd-nm-modal-next-step">
<span class="tvd-icon-plus tvd-icon-small"></span><?php echo __( 'Add New', 'thrive-dash' ) ?>
</button>
</div>
<div class="tvd-modal-footer">
<div class="tvd-row">
<div class="tvd-col tvd-s12">
<a href="javascript:void(0)"
class="tvd-waves-effect tvd-waves-light tvd-btn tvd-btn-green tvd-right tvd-modal-close">
<?php echo __( 'OK', 'thrive-dash' ) ?>
</a>
</div>
</div>
</div>
</div>
<div class="tvd-nm-modal-step">
<div class="tvd-modal-content">
<h3 class="tvd-modal-title"><?php echo __( "Email Delivery Setup", 'thrive-dash' ) ?></h3>
<p><?php echo __( 'Select the email delivery service you want to use for Send Email Notification Actions. Integrating one of these services ensures your emails get delivered without you needing to deal with email server setups and spam protection', 'thrive-dash' ) ?></p>
<div id="tvd-nm-connections-list" class="tvd-row"></div>
</div>
<div class="tvd-modal-footer">
<div class="tvd-row">
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)" class="tvd-btn-flat-blue tvd-btn-flat tvd-waves-effect tvd-nm-modal-prev-step">
<?php echo __( 'Back', 'thrive-dash' ) ?>
</a>
</div>
</div>
</div>
</div>
<div class="tvd-nm-modal-step">
<div class="tvd-modal-content">
<h3 class="tvd-modal-title"><?php echo __( "Email Delivery Setup", 'thrive-dash' ) ?></h3>
<p><?php echo __( "Fill the form's fields with your credentials and click the Connect button to establish the connection.", 'thrive-dash' ) ?></p>
<div id="tvd-nm-connection-form" class="tvd-row tvd-collapse"></div>
</div>
<div class="tvd-modal-footer">
<div class="tvd-row">
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)" class="tvd-btn-flat tvd-btn-flat-secondary tvd-btn-flat-dark tvd-waves-effect tvd-nm-modal-prev-step">
<?php echo __( 'Cancel', 'thrive-dash' ) ?>
</a>
</div>
<div class="tvd-col tvd-s12 tvd-m6">
<a href="javascript:void(0)"
class="tvd-waves-effect tvd-waves-light tvd-btn tvd-btn-green tvd-right tvd-nm-save-connection">
<?php echo __( 'Connect', 'thrive-dash' ) ?>
</a>
</div>
</div>
</div>
</div>
<?php foreach ( Thrive_Dash_List_Manager::get_available_apis( false, [ 'include_types' => [ 'email' ] ] ) as $key => $api ) : ?>
<?php /** @var $api Thrive_Dash_List_Connection_Abstract */ ?>
<div class="tvd-nm-connection-form" data-key="<?php echo $key ?>" style="display: none">
<?php echo $api->output_setup_form() ?>
</div>
<?php endforeach; ?>

View File

@@ -0,0 +1,23 @@
<div class="tvd-col tvd-s4">
<div class="tvd-card tvd-white tvd-small tvd-valign-wrapper">
<div class="tvd-card-content tvd-center-align tvd-valign">
<span class="tvd-nm-large-icon tvd-green-text <#= trigger.get('icon') #>"></span>
<p>
<#= trigger.get('label') #>
</p>
</div>
</div>
</div>
<# if(action !== null){ #>
<div class="tvd-col tvd-s4">
<div class="tvd-card tvd-white tvd-small tvd-valign-wrapper">
<div class="tvd-card-content tvd-center-align tvd-valign">
<span class="tvd-nm-large-icon tvd-green-text <#= action.get('icon') #>"></span>
<p>
<#= action.get('label') #>
</p>
</div>
</div>
</div>
<# } #>

View File

@@ -0,0 +1,6 @@
<div class="tvd-card tvd-card-new tvd-valign-wrapper">
<div class="tvd-card-content tvd-valign tvd-center-align">
<i class="tvd-icon-plus tvd-icon-rounded tvd-icon-medium"></i>
<h4 class="tvd-nm-new-button-header-text"><?php echo __( 'Add New Notification', 'thrive-dash' ) ?></h4>
</div>
</div>

View File

@@ -0,0 +1,4 @@
<div class="tvd-col tvd-s3 tvd-m3" id="tvd-nm-trigger-wrapper"></div>
<div class="tvd-col tvd-s9 tvd-m9">
<div class="tvd-row" id="tvd-nm-actions-wrapper"></div>
</div>

View File

@@ -0,0 +1,3 @@
<a class="tvd-btn-icon-only tvd-btn-icon-only-red tvd-right tvd-nm-delete-notification tvd-tooltipped" data-position="top" data-tooltip="<?php echo __( 'Delete notification', 'thrive-dash' ); ?>" href="javascript:void(0)">
<i class="tvd-icon-trash-o"></i>
</a>

View File

@@ -0,0 +1,4 @@
<input type="checkbox" id="tvd-nm-checkbox-<#= item.get('value') #>-<#= item.cid #>" data-id="<#= item.get('value') #>">
<label for="tvd-nm-checkbox-<#= item.get('value') #>-<#= item.cid #>" title="<#= item.get('label') #>" class="tvd-nm-checkbox-label">
<#= item.get('label') #>
</label>

View File

@@ -0,0 +1,13 @@
<div class="tvd-col tvd-s9">
<div class="tvd-input-field">
<input id="tvd-nm-option-input-<#= item.cid #>" type="email" value="<#= item.get('value') #>" data-bind="value">
<label for="tvd-nm-option-input-<#= item.cid #>" class="tvd-active">
<#= item.get('label') #>
</label>
</div>
</div>
<div class="tvd-col tvd-s3">
<a href="javascript:void(0)" class="tvd-nm-remove-recipient tvd-btn-flat tvd-btn-flat-secondary tvd-btn-flat-gray tvd-btn-margin-top tvd-waves-effect tvd-full-btn">
<?php echo __( 'Remove', 'thrive-dash' ) ?>
</a>
</div>

View File

@@ -0,0 +1,4 @@
<input id="tvd-nm-option-input-<#= item.get('cId') #>" type="text" value="<#= item.get('value') #>" data-bind="value">
<label label="tvd-nm-option-input-<#= item.get('cId') #>">
<#= item.get('label') #>
</label>

View File

@@ -0,0 +1,8 @@
<div>
Value:
<#= item.get('value') #>
</div>
<div>
Label:
<#= item.get('label') #>
</div>

View File

@@ -0,0 +1,3 @@
<span class="tvd-chip">
<#= item.get('value') #>
</span>

View File

@@ -0,0 +1,48 @@
<ul class="tvd-collection <#= item.get('active') ? 'tvd-nm-selected-service' : '' #>">
<li class="tvd-collection-item">
<div class="tvd-row tvd-collapse">
<div class="tvd-col tvd-s3">
<div class="tvd-vertical-align">
<img alt="<?php echo __( 'Autoresponder logo', 'thrive-dash' ) ?>" src="<?php echo TVE_DASH_URL . '/inc/auto-responder/views/images/' ?><#= item.get('key') #>_small.jpg">
<strong class="tvd-capitalize">
<#= item.get('title') #>
</strong>
</div>
</div>
<div class="tvd-col tvd-s4">
<div class="tvd-row">
<div class="tvd-col tvd-l4">
<div class="tvd-switch tvd-vertical-align">
<label>
<input data-key="<#= item.get('key') #>"
<#= item.get('active') ? 'checked' : '' #> class="tvd-nm-toggle-service" type="checkbox" autocomplete="off">
<span class="tvd-lever"></span>
</label>
</div>
</div>
<div class="tvd-col tvd-l8">
<strong class="tvd-vertical-align tvd-capitalize">
<#= item.get('status') #>,
<#= item.get('active') ? TD_NM.t.active : TD_NM.t.inactive #>
</strong>
</div>
</div>
</div>
<div class="tvd-col tvd-s4">
<span class="tvd-vertical-align">
<span class="tvd-icon-exchange tvd-text-gray"></span>
<a class="tvd-underline tvd-nm-connection-test" data-key="<#= item.get('key') #>" title="<?php echo __( 'Test connection', 'thrive-dash' ) ?>" href="javascript:void(0)">
<?php echo __( 'Test connection', 'thrive-dash' ) ?>
</a>
</span>
</div>
<div class="tvd-col tvd-s1">
<div class="tvd-vertical-align">
<a href="javascript:void(0)" class="tvd-right tvd-nm-connection" data-key="<#= item.get('key') #>">
<span class="tvd-icon-pencil"></span>
</a>
</div>
</div>
</div>
</li>
</ul>

View File

@@ -0,0 +1,7 @@
<div class="tvd-col tvd-s3 tvd-center-align">
<a href="javascript:void(0)" data-key="<#= item.get('key') #>" class="tvd-nm-connection tvd-nm-connection-<#= item.get('key') #> <#= item.get('connected') ? 'tvd-nm-connected' : '' #>"></a>
<span class="tvd-nm-connection-name">
<#= item.get('title') #><br>
<span class=""><#= item.get('connected') ? '(connected)' : '&nbsp;' #></span>
</span>
</div>

View File

@@ -0,0 +1,3 @@
<div class="tvd-card tvd-white tvd-small tvd-valign-wrapper">
summary item
</div>

View File

@@ -0,0 +1,15 @@
<div class="tvd-card-content tvd-center-align tvd-valign">
<div class="tvd-nm-action-buttons">
<a class="tvd-nm-blue-gray-text" href="javascript:void(0)">
<i class="tvd-icon-pencil tvd-left"></i>
</a>
<a class="tvd-nm-blue-gray-text" href="javascript:void(0)">
<i class="tvd-icon-trash-o"></i>
</a>
</div>
<i class="<#= item.get('icon') #> tvd-nm-large-icon tvd-blue-text"></i>
<p>
<#- item.get('label') #>
</p>
</div>

View File

@@ -0,0 +1,26 @@
<div class="tvd-card-content tvd-valign">
<div class="tvd-nm-action-buttons">
<a class="tvd-btn-icon-only tvd-btn-icon-only-blue tvd-nm-action-edit" href="javascript:void(0)">
<i class="tvd-icon-pencil tvd-left"></i>
</a>
<a class="tvd-btn-icon-only tvd-btn-icon-only-red tvd-nm-action-delete" href="javascript:void(0)">
<i class="tvd-icon-trash-o"></i>
</a>
</div>
<h4><?php echo __( 'Call custom script', 'thrive-dash' ) ?></h4>
<div class="tvd-row tvd-copy-row">
<div class="tvd-col tvd-s8">
<div class="tvd-input-field tvd-margin-top-small">
<input readonly="readonly" type="text" value="<#= item.get('url') #>" class="tvd-no-margin tvd-copy">
</div>
</div>
<div class="tvd-col tvd-s4">
<span class="">
<a class="tvd-waves-effect tvd-waves-light tvd-btn tvd-btn-blue tvd-btn-small tvd-margin-top-small tvd-copy-to-clipboard" href="javascript:void(0)">
<span class="tvd-copy-text"><?php echo __( 'Copy', 'thrive-dash' ) ?></span>
</a>
</span>
</div>
</div>
</div>

View File

@@ -0,0 +1,26 @@
<div class="tvd-card-content tvd-valign">
<div class="tvd-nm-action-buttons">
<a class="tvd-btn-icon-only tvd-btn-icon-only-blue tvd-nm-action-edit" href="javascript:void(0)">
<i class="tvd-icon-pencil tvd-left"></i>
</a>
<a class="tvd-btn-icon-only tvd-btn-icon-only-red tvd-nm-action-delete" href="javascript:void(0)">
<i class="tvd-icon-trash-o"></i>
</a>
</div>
<div>
<span><?php echo __( 'Email subject line:', 'thrive-dash' ) ?></span>
<span>
<strong>
<# if(item.get('message').get('subject').length >= 20){ #>
<#- item.get('message').get('subject').substring(0, 17) #>...
<# }else{ #>
<#- item.get('message').get('subject') #>
<# } #>
</strong>
</span>
</div>
<div class="tvd-nm-emails-list">
<span><?php echo __( 'To:', 'thrive-dash' ) ?></span>
</div>
</div>

View File

@@ -0,0 +1,26 @@
<div class="tvd-card-content tvd-valign">
<div class="tvd-nm-action-buttons">
<a class="tvd-btn-icon-only tvd-btn-icon-only-blue tvd-nm-action-edit" href="javascript:void(0)">
<i class="tvd-icon-pencil tvd-left"></i>
</a>
<a class="tvd-btn-icon-only tvd-btn-icon-only-red tvd-nm-action-delete" href="javascript:void(0)">
<i class="tvd-icon-trash-o"></i>
</a>
</div>
<h4><?php echo __( 'WordPress Notification', 'thrive-dash' ) ?></h4>
<div class="tvd-row tvd-copy-row">
<div class="tvd-col tvd-s8">
<div class="tvd-input-field tvd-margin-top-small">
<input readonly="readonly" type="text" value="<#= item.get('message').get('content') #>" class="tvd-no-margin tvd-copy">
</div>
</div>
<div class="tvd-col tvd-s4">
<span class="">
<a class="tvd-waves-effect tvd-waves-light tvd-btn tvd-btn-blue tvd-btn-small tvd-margin-top-small tvd-copy-to-clipboard" href="javascript:void(0)">
<span class="tvd-copy-text"><?php echo __( 'Copy', 'thrive-dash' ) ?></span>
</a>
</span>
</div>
</div>
</div>

View File

@@ -0,0 +1,8 @@
<div class="tvd-card tvd-white tvd-small tvd-valign-wrapper <#= item.get('class') #>">
<div class="tvd-card-content tvd-center-align tvd-valign">
<i class="<#= item.get('icon') #> tvd-nm-large-icon <#= item.get('color') #>"></i>
<p>
<#= item.get('label') #>
</p>
</div>
</div>

View File

@@ -0,0 +1,12 @@
<div class="tvd-card-content tvd-center-align tvd-valign">
<div class="tvd-nm-action-buttons">
<a class="tvd-btn-icon-only tvd-btn-icon-only-blue tvd-nm-edit-trigger" href="javascript:void(0)">
<i class="tvd-icon-pencil"></i>
</a>
</div>
<i class="<#= item.get('icon') #> tvd-nm-large-icon tvd-green-text"></i>
<p>
<#= item.get('label') #>
</p>
</div>

View File

@@ -0,0 +1,8 @@
<div class="tvd-col tvd-s6 tvd-m3 tvd-nm-trigger-type" data-trigger-type="<#= item.get('key') #>">
<div class="tvd-center-align tvd-card tvd-white tvd-pointer">
<i class="<#= item.get('icon') #> tvd-nm-large-icon tvd-green-text"></i>
<p class="tvd-center-align tvd-margin-bottom">
<#= item.get('label') #>
</p>
</div>
</div>

View File

@@ -0,0 +1,5 @@
<h4><?php echo __( 'Email Sign Up Settings', 'thrive-dash' ) ?></h4>
<p><?php echo __( 'Which source of email sign up should trigger the notification?', 'thrive-dash' ) ?></p>
<div id="tvd-nm-lead-groups-wrapper" class="tvd-row"></div>
<div id="tvd-nm-lead-shortcodes-wrapper" class="tvd-row"></div>
<div id="tvd-nm-lead-thrive-boxes-wrapper" class="tvd-row"></div>

View File

@@ -0,0 +1,3 @@
<h4><?php echo __( 'New Quiz Completion', 'thrive-dash' ) ?></h4>
<p><?php echo __( 'Receive a notification when someone completes a quiz on your website', 'thrive-dash' ) ?></p>
<div id="tvd-nm-quizzes-wrapper" class="tvd-row"></div>

View File

@@ -0,0 +1,6 @@
<h4><?php echo __( 'A/B Test Ends Settings', 'thrive-dash' ) ?></h4>
<p><?php echo __( 'Which sort of A/B test should trigger the notification?', 'thrive-dash' ) ?></p>
<div id="tvd-nm-tl-tests-wrapper" class="tvd-row"></div>
<div id="tvd-nm-tho-tests-wrapper" class="tvd-row"></div>
<div id="tvd-nm-tqb-tests-wrapper" class="tvd-row"></div>
<div id="tvd-nm-tab-tests-wrapper" class="tvd-row"></div>

View File

@@ -0,0 +1,2 @@
<h4><?php echo __( 'New Testimonial Submission', 'thrive-dash' ) ?></h4>
<p><?php echo __( 'Receive a notification when someone submits a testimonial via one of the testimonial capture forms on your website.', 'thrive-dash' ) ?></p>

View File

@@ -0,0 +1,22 @@
<?php
$unavailable_tooltip_text = __( 'This feature is only available for Thrive Leads, Thrive Ovation, Thrive Headline Optimizer, Thrive Quiz Builder', 'thrive-dash' );
?>
<div class="tvd-row">
<div class="tvd-col tvd-s12 tvd-m12 tvd-l12">
<h3 class="tvd-title tvd-left">
<?php echo __( 'Notifications', 'thrive-dash' ) ?>
<a class="tvd-open-video" data-source="qCY1Gq9PZv4">
<span class="tvd-icon-play"></span>
</a>
</h3>
<a style="margin-left: 30px;" href="javascript:void(0)" data-position="top" data-tooltip="<?php echo $unavailable_tooltip_text; ?>" class="tvd-disabled tvd-left tvd-btn tvd-btn-blue tvd-waves-effect tvd-waves-light tvd-tooltipped">
<?php echo __( 'Add New', 'thrive-dash' ) ?>
</a>
</div>
</div>
<div class="tvd-card tvd-card-new tvd-valign-wrapper tvd-tooltipped" data-position="top" data-tooltip="<?php echo $unavailable_tooltip_text; ?>">
<div class="tvd-card-content tvd-valign tvd-center-align">
<i class="tvd-icon-plus tvd-icon-rounded tvd-icon-medium"></i>
<h4><?php echo __( 'Add New Notification', 'thrive-dash' ) ?></h4>
</div>
</div>

View File

@@ -0,0 +1,46 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Ajax {
public static function init() {
static::add_ajax_events();
}
public static function add_ajax_events() {
$ajax_events = array(
'admin_controller' => false,
);
foreach ( $ajax_events as $ajax_event => $nopriv ) {
add_action( 'wp_ajax_td_nm_' . $ajax_event, array( __CLASS__, $ajax_event ) );
if ( $nopriv ) {
add_action( 'wp_ajax_nopriv_td_nm_' . $ajax_event, array( __CLASS__, $ajax_event ) );
}
}
}
/**
* All ajax requests for admin will be managed by admin ajax controller
* Dies with json response
*/
public static function admin_controller() {
if ( ! current_user_can( TVE_DASH_CAPABILITY ) ) {
wp_die( '' );
}
include_once TD_NM()->path( 'includes/admin/class-td-nm-admin-ajax-controller.php' );
$response = TD_NM_Admin_Ajax_Controller::instance()->handle();
wp_send_json( $response );
}
}
TD_NM_Ajax::init();

View File

@@ -0,0 +1,235 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Checker {
protected static $instance;
protected function __construct() {
$this->init_hooks();
}
public function init_hooks() {
add_action( 'tve_leads_form_conversion', array( __CLASS__, 'on_email_sign_up' ), 10, 5 );
add_action( 'tve_leads_action_set_test_item_winner', array( $this, 'on_split_test_ends' ), 10, 2 );
add_action( 'tho_action_set_test_item_winner', array( $this, 'on_split_test_ends' ), 10, 2 );
add_action( 'tab_action_set_test_item_winner', array( $this, 'on_split_test_ends' ), 10, 2 );
add_action( 'tqb_split_test_ends', array( $this, 'on_split_test_ends' ), 10, 2 );
add_action( 'tvo_testimonial_added_through_capture_form', array( $this, 'on_testimonial_added' ), 10, 2 );
add_action( 'tqb_quiz_completed', array( $this, 'on_quiz_completion' ), 10, 2 );
}
public static function instance() {
if ( ! static::$instance ) {
static::$instance = new self();
}
return static::$instance;
}
public function on_quiz_completion( $quiz, $user ) {
$notifications = td_nm_get_notifications( array(
'meta_key' => 'td_nm_trigger_type',
'meta_value' => 'quiz_completion',
) );
$data = func_get_args();
foreach ( $notifications as $notification ) {
$trigger = new TD_NM_Trigger_Quiz_Completion( $notification->trigger['settings'] );
if ( $trigger->applicable_on_data( $quiz ) ) {
static::instance()->execute_quiz_completion_actions( $notification->actions, $data );
}
}
}
public static function on_email_sign_up( $tl_item, $tl_form_type, $tl_variation, $tl_test, $optin_data ) {
$notifications = td_nm_get_notifications( array(
'meta_key' => 'td_nm_trigger_type',
'meta_value' => 'email_sign_up',
) );
$sign_up_data = func_get_args();
foreach ( $notifications as $notification ) {
$trigger = new TD_NM_Trigger_Email_Sign_Up( $notification->trigger['settings'] );
if ( $trigger->applicable_on_data( $tl_item ) ) {
static::instance()->execute_sign_up_actions( $notification->actions, $sign_up_data );
}
}
}
public function on_split_test_ends( $test_item, $test ) {
$notifications = td_nm_get_notifications( array(
'meta_key' => 'td_nm_trigger_type',
'meta_value' => 'split_test_ends',
) );
$test_data = func_get_args();
foreach ( $notifications as $notification ) {
$trigger = new TD_NM_Trigger_Split_Test_Ends( $notification->trigger['settings'] );
if ( $trigger->applicable_on_data( $test ) ) {
$this->execute_split_test_ends_actions( $notification->actions, $test_data );
}
}
}
public function on_testimonial_added( $testimonial, $extra_data ) {
$notifications = td_nm_get_notifications( array(
'meta_key' => 'td_nm_trigger_type',
'meta_value' => 'testimonial_submitted',
) );
$testimonial_data = func_get_args();
foreach ( $notifications as $notification ) {
$trigger = new TD_NM_Trigger_Testimonial_Submitted( $notification->trigger['settings'] );
if ( $trigger->applicable_on_data( $extra_data ) ) {
$this->execute_testimonial_submitted_actions( $notification->actions, $testimonial_data );
}
}
}
public function execute_sign_up_actions( $actions, $sign_up_data ) {
foreach ( $actions as $item ) {
/** @var TD_NM_Action_Abstract $action */
$action = null;
$prepared_data = array();
/**
* ugly way to instantiate the action but we have to make sure it works in PHP 5.2
*/
switch ( $item['type'] ) {
case 'custom_script':
/** @var TD_NM_Action_Custom_Script $action */
$action = new TD_NM_Action_Custom_Script( $item );
$prepared_data = $action->prepare_email_sign_up_data( $sign_up_data );
break;
case 'send_email_notification':
/** @var TD_NM_Action_Send_Email_Notification $action */
$action = new TD_NM_Action_Send_Email_Notification( $item );
$prepared_data = $action->prepare_email_sign_up_data( $sign_up_data );
break;
case 'wordpress_notification':
/** @var TD_NM_Action_Wordpress_Notification $action */
$action = new TD_NM_Action_Wordpress_Notification( $item );
$prepared_data = $action->prepare_email_sign_up_data( $sign_up_data );
break;
}
if ( $action ) {
$action->execute( $prepared_data );
}
}
}
public function execute_quiz_completion_actions( $actions, $data ) {
foreach ( $actions as $item ) {
/** @var TD_NM_Action_Abstract $action */
$action = null;
$prepared_data = array();
/**
* ugly way to instantiate the action but we have to make sure it works in PHP 5.2
*/
switch ( $item['type'] ) {
case 'custom_script':
/** @var TD_NM_Action_Custom_Script $action */
$action = new TD_NM_Action_Custom_Script( $item );
$prepared_data = $action->prepare_quiz_completion_data( $data );
break;
case 'send_email_notification':
/** @var TD_NM_Action_Send_Email_Notification $action */
$action = new TD_NM_Action_Send_Email_Notification( $item );
$prepared_data = $action->prepare_quiz_completion_data( $data );
break;
case 'wordpress_notification':
/** @var TD_NM_Action_Wordpress_Notification $action */
$action = new TD_NM_Action_Wordpress_Notification( $item );
$prepared_data = $action->prepare_quiz_completion_data( $data );
break;
}
if ( $action ) {
$action->execute( $prepared_data );
}
}
}
public function execute_split_test_ends_actions( $actions, $test_data ) {
foreach ( $actions as $item ) {
/** @var TD_NM_Action_Abstract $action */
$action = null;
$prepared_data = array();
/**
* ugly way to instantiate the action but we have to make sure it works in PHP 5.2
*/
switch ( $item['type'] ) {
case 'custom_script':
/** @var TD_NM_Action_Custom_Script $action */
$action = new TD_NM_Action_Custom_Script( $item );
$prepared_data = $action->prepare_split_test_ends_data( $test_data );
break;
case 'send_email_notification':
/** @var TD_NM_Action_Send_Email_Notification $action */
$action = new TD_NM_Action_Send_Email_Notification( $item );
$prepared_data = $action->prepare_split_test_ends_data( $test_data );
break;
case 'wordpress_notification':
/** @var TD_NM_Action_Wordpress_Notification $action */
$action = new TD_NM_Action_Wordpress_Notification( $item );
$prepared_data = $action->prepare_split_test_ends_data( $test_data );
break;
}
if ( $action ) {
$action->execute( $prepared_data );
}
}
}
public function execute_testimonial_submitted_actions( $actions, $testimonial_data ) {
foreach ( $actions as $item ) {
/** @var TD_NM_Action_Abstract $action */
$action = null;
$prepared_data = array();
/**
* ugly way to instantiate the action but we have to make sure it works in PHP 5.2
*/
switch ( $item['type'] ) {
case 'custom_script':
/** @var TD_NM_Action_Custom_Script $action */
$action = new TD_NM_Action_Custom_Script( $item );
$prepared_data = $action->prepare_testimonial_submitted_data( $testimonial_data );
break;
case 'send_email_notification':
/** @var TD_NM_Action_Send_Email_Notification $action */
$action = new TD_NM_Action_Send_Email_Notification( $item );
$prepared_data = $action->prepare_testimonial_submitted_data( $testimonial_data );
break;
case 'wordpress_notification':
/** @var TD_NM_Action_Wordpress_Notification $action */
$action = new TD_NM_Action_Wordpress_Notification( $item );
$prepared_data = $action->prepare_testimonial_submitted_data( $testimonial_data );
break;
}
if ( $action ) {
$action->execute( $prepared_data );
}
}
}
}

View File

@@ -0,0 +1,14 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Data {
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Post_Types {
public static function init() {
add_action( 'init', array( __CLASS__, 'register_post_types' ), 5 );
}
public static function register_post_types() {
if ( post_type_exists( 'td_nm_notification' ) ) {
return;
}
register_post_type( 'td_nm_notification', array(
'publicly_queryable' => true,
'query_var' => false,
'description' => 'Thrive Notification',
'rewrite' => false,
'labels' => array(
'name' => 'Thrive Notification',
),
) );
}
}
TD_NM_Post_Types::init();

View File

@@ -0,0 +1,12 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
include( 'td-nm-data-functions.php' ); //data functions

View File

@@ -0,0 +1,180 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
/**
* Save the Notification Post
*
* @param $model
*
* @return int|false
*/
function td_nm_save_notification( $model ) {
$defaults = array(
'post_type' => 'td_nm_notification',
'post_status' => 'publish',
);
if ( empty( $model['ID'] ) ) {
$id = wp_insert_post( array_merge( $defaults, $model ) );
} else {
$id = wp_update_post( $model );
}
if ( empty( $id ) || is_wp_error( $id ) ) {
return false;
}
//save trigger or delete the notification
$trigger_saved = td_nm_save_trigger( $model['trigger'], $id );
if ( empty( $trigger_saved ) ) {
td_nm_delete_notification( $id );
return false;
}
//save the actions or delete the notification
$actions_saved = td_nm_save_actions( $model['actions'], $id );
if ( empty( $actions_saved ) ) {
td_nm_delete_notification( $id );
return false;
}
return $id;
}
/**
* Assign some post_meta for the a notification|post
*
* @param array $trigger
* @param int $notification_id
*
* @return int|false
*/
function td_nm_save_trigger( $trigger, $notification_id ) {
if ( empty( $trigger['type'] ) || empty( $trigger['settings'] ) || get_post_status( $notification_id ) === false ) {
return false;
}
$old_type = get_post_meta( $notification_id, 'td_nm_trigger_type', true );
$old_settings = get_post_meta( $notification_id, 'td_nm_trigger_settings', true );
if ( $trigger['type'] === $old_type && $old_settings === $trigger['settings'] ) {
return $notification_id;
}
update_post_meta( $notification_id, 'td_nm_trigger_type', $trigger['type'] );
update_post_meta( $notification_id, 'td_nm_trigger_settings', $trigger['settings'] );
return $notification_id;
}
/**
* Read Notifications from DB based on filters
*
* @param array $filters
*
* @return array
*/
function td_nm_get_notifications( $filters = array() ) {
$defaults = array(
'posts_per_page' => - 1,
'post_type' => 'td_nm_notification',
'orderby' => 'date',
'order' => 'ASC',
);
if ( ! function_exists( 'is_plugin_active' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$filters = array_merge( $defaults, $filters );
$posts = get_posts( $filters );
$notifications = array();
foreach ( $posts as $post ) {
$trigger = td_nm_get_trigger( $post->ID );
$trigger_instance = TD_NM_Trigger_Factory::get_instance( $trigger );
if ( $applicable = $trigger_instance->is_notification_applicable() ) {
$post->trigger = $trigger;
$post->actions = td_nm_get_actions( $post->ID );
$notifications[] = $post;
}
}
return $notifications;
}
/**
* Get trigger for a notification|post
*
* @param int $notification_id
*
* @return array
*/
function td_nm_get_trigger( $notification_id ) {
$item = array(
'type' => null,
'settings' => array(),
);
$item['type'] = get_post_meta( $notification_id, 'td_nm_trigger_type', true );
$item['settings'] = get_post_meta( $notification_id, 'td_nm_trigger_settings', true );
$item['ID'] = $notification_id;
return $item;
}
/**
* Get actions for a notification|post
*
* @param int $notification_id
*
* @return array
*/
function td_nm_get_actions( $notification_id ) {
$items = get_post_meta( $notification_id, 'td_nm_actions', true );
foreach ( $items as $key => &$item ) {
$item['ID'] = $key;
}
return $items;
}
/**
* @param $actions
* @param $notification_id
*
* @return bool|int
*/
function td_nm_save_actions( $actions, $notification_id ) {
foreach ( $actions as &$action ) {
$action['notification_id'] = $notification_id;
}
return update_post_meta( $notification_id, 'td_nm_actions', $actions );
}
/**
* Delete notification|post with all its data|meta
*
* @param $notification_id
*
* @return bool
*/
function td_nm_delete_notification( $notification_id ) {
$post_deleted = wp_delete_post( $notification_id, true );
return empty( $post_deleted ) || is_wp_error( $post_deleted ) ? false : true;
}

View File

@@ -0,0 +1,82 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
abstract class TD_NM_Trigger_Abstract {
protected $settings;
protected $_types;
public function __construct( $settings ) {
$this->settings = $settings;
}
/**
* Check if item exists in list
*
* @param $list
* @param $id
*
* @return bool
*/
protected function in_list( $list, $id ) {
foreach ( $list as $key => $item ) {
if ( $item['value'] == $id ) {
return true;
}
}
return false;
}
public function get_types() {
if ( ! $this->_types ) {
$types = TD_NM()->get_trigger_types();
foreach ( $types as $type ) {
$this->_types[] = $type['key'];
}
}
return $this->_types;
}
/**
* Check if this trigger is applicable based on its type
* and if the corresponding plugin is loaded
* and if corresponding data is set
*
* @see td_nm_get_notifications()
*
* @return bool
*/
public function is_notification_applicable() {
$types = $this->get_types();
$applicable = false;
if ( is_array( $types ) && in_array( $this->settings['type'], $types ) ) {
$applicable = true;
}
return $applicable;
}
/**
* Check if settings are applicable for that item
*
* @param mixed $item
*
* @return mixed
*/
abstract public function applicable_on_data( $item );
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Trigger_Email_Sign_Up extends TD_NM_Trigger_Abstract {
public function applicable_on_data( $tl_item ) {
if ( $this->in_list( $this->settings['groups'], $tl_item->ID ) ) {
return true;
}
if ( $this->in_list( $this->settings['shortcodes'], $tl_item->ID ) ) {
return true;
}
if ( $this->in_list( $this->settings['thrive_boxes'], $tl_item->ID ) ) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Trigger_Factory {
/**
* @param array $trigger
*
* @return TD_NM_Trigger_Abstract
*/
public static function get_instance( $trigger ) {
if ( is_array( $trigger ) && ! empty( $trigger['type'] ) ) {
$class_name = 'TD_NM_Trigger_' . self::prepare_class_name( $trigger['type'] );
}
return isset( $class_name ) && class_exists( $class_name, false ) ? new $class_name( $trigger ) : null;
}
/**
* @param string $type
*
* @return string
*/
private static function prepare_class_name( $type ) {
$chunks = explode( '_', $type );
$chunks = array_map( 'ucfirst', $chunks );
return implode( '_', $chunks );
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Trigger_Quiz_Completion extends TD_NM_Trigger_Abstract {
public function applicable_on_data( $quiz ) {
return $this->in_list( $this->settings, $quiz->ID );
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Trigger_Split_Test_Ends extends TD_NM_Trigger_Abstract {
public function applicable_on_data( $test_item ) {
$applicable = false;
if ( ! empty( $this->settings['tho'] ) && $this->in_list( $this->settings['tho'], $test_item->id ) ) {
$applicable = true;
} else if ( ! empty( $this->settings['tqb'] ) && $this->in_list( $this->settings['tqb'], $test_item->id ) ) {
$applicable = true;
} else if ( ! empty( $this->settings['tl'] ) && $this->in_list( $this->settings['tl'], $test_item->id ) ) {
$applicable = true;
} else if ( ! empty( $this->settings['tab'] ) && $this->in_list( $this->settings['tab'], $test_item->id ) ) {
$applicable = true;
}
return $applicable;
}
/**
* split_test_ends trigger can be initiated by more plugins (TL, TQB, THO)
* and we need to check if the trigger is applicable for any of the plugin
*
* @return bool
*/
public function is_notification_applicable() {
$applicable = parent::is_notification_applicable();
return $applicable && ( $this->_is_tl_applicable() || $this->_is_tho_applicable() || $this->_is_tqb_applicable() || $this->_is_tab_applicable() );
}
protected function _is_tl_applicable() {
$plugin_active = tve_dash_is_plugin_active( 'thrive-leads' );
return $plugin_active && ! empty( $this->settings['settings']['tl'] );
}
protected function _is_tho_applicable() {
$plugin_active = tve_dash_is_plugin_active( 'thrive-headline-optimizer' );
return $plugin_active && ! empty( $this->settings['settings']['tho'] );
}
protected function _is_tqb_applicable() {
$plugin_active = tve_dash_is_plugin_active( 'thrive-quiz-builder' );
return $plugin_active && ! empty( $this->settings['settings']['tqb'] );
}
protected function _is_tab_applicable() {
$plugin_active = tve_dash_is_plugin_active( 'thrive-ab-page-testing' );
return $plugin_active && ! empty( $this->settings['settings']['tab'] );
}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* Thrive Themes - https://thrivethemes.com
*
* @package thrive-dashboard
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Silence is golden
}
class TD_NM_Trigger_Testimonial_Submitted extends TD_NM_Trigger_Abstract {
public function applicable_on_data( $testimonial ) {
if ( defined( 'TVO_SOURCE_DIRECT_CAPTURE' ) && ! empty( $testimonial['source'] ) && TVO_SOURCE_DIRECT_CAPTURE == $testimonial['source'] ) {
return true;
}
return false;
}
}