parse_parameters_from_string( trim( $variable_params ) );
if ( is_array( $parameters ) && ! empty( $parameters ) ) {
if ( isset( $parameters['fallback'] ) && ! empty( $parameters['fallback'] ) ) {
$replace_with_fallback = self::un_quote( $parameters['fallback'] );
$is_nested_variable = strpos( $variable_name, '.' ); // Check if variable has dont(.) in its name
if ( $is_nested_variable ) {
$variable_parts = explode( '.', $variable_name );
$variable_type = $variable_parts[0];
$variable_slug = $variable_parts[1];
/**
* For variables like subscribers.name, we need to pass the fallback data as nested array
* $default_keywords['subscribers']['name'] = fallback_value
**/
$default_keywords[ $variable_type ][ $variable_slug ] = $replace_with_fallback;
} else {
$default_keywords[ $variable_name ] = $replace_with_fallback;
}
}
}
}
}
return $default_keywords;
}
/**
* Callback to replace keywords
*
* @param $keyword
* @param $search_and_replace
*
* @return mixed|string
*/
public static function callback_replace_keywords( $keyword, $search_and_replace ) {
if ( strstr( $keyword, '|' ) ) {
list( $variable_name, $variable_params ) = explode( '|', $keyword, 2 );
} else {
$variable_name = $keyword;
$variable_params = '';
}
$variable_name = trim( $variable_name );
//If there is no key found in replaceable array, then return the keyword
if ( ! isset( $search_and_replace[ $variable_name ] ) ) {
return '{{' . $keyword . '}}';
}
$replace_with = $search_and_replace[ $variable_name ];
$replace_with_fallback = '';
//Extract fallback content from the keyword
$variable = new IG_ES_Workflow_Variable_Parser();
$parameters = $variable->parse_parameters_from_string( trim( $variable_params ) );
if ( is_array( $parameters ) && ! empty( $parameters ) ) {
if ( isset( $parameters['fallback'] ) && ! empty( $parameters['fallback'] ) ) {
$replace_with_fallback = self::un_quote($parameters['fallback']);
}
}
//If replaceable value is contain fallback keyword, then return the replaceable value with fallback value
if ( strstr( $replace_with, '%%fallback%%' ) ) {
return str_replace( '%%fallback%%', $replace_with_fallback, $replace_with );
}
//If replaceable value is not empty, then return the replaceable value
if ( ! empty( $replace_with ) ) {
return $replace_with;
}
// return fallback value
return $replace_with_fallback;
}
/**
* Decode the html quotes
*
* @param $string
*
* @return string
*/
public static function decode_html_quotes( $string ) {
$entities_dictionary = [
'' => "'", // Opening single quote
'' => "'", // Closing single quote
'' => '"', // Closing double quote
'' => '"', // Opening double quote
'‘' => "'", // Closing single quote
'’' => "'", // Opening single quote
'‚' => "'", // Single low quote
'“' => '"', // Closing double quote
'”' => '"', // Opening double quote
'„' => '"', // Double low quote
];
// Decode decimal entities
$string = str_replace( array_keys( $entities_dictionary ), array_values( $entities_dictionary ), $string );
return html_entity_decode( $string, ENT_QUOTES | ENT_HTML5, 'UTF-8' );
}
/**
* Remove quotes from string
*
* @param $string
*
* @return string
*/
public static function un_quote( $string ) {
$string = self::decode_html_quotes( $string );
return trim( trim( $string ), "'" );
}
/**
* Parse keywords
*
* @since 5.3.5
* @return false|void
*/
public static function replace_keywords_with_fallback( $content, $search_and_replace ) {
if ( empty( $content ) || empty( $search_and_replace ) ) {
return $content;
}
$replacer = new IG_ES_Replace_Helper( $content, 'ES_Common::callback_replace_keywords', 'variables', $search_and_replace );
$processed_content = $replacer->process();
if ( $processed_content ) {
return $processed_content;
}
return $content;
}
/**
* Process template body
*
* @param $content
* @param int $tmpl_id
* @param int $campaign_id
*
* @return mixed|string
*
* @since 4.0.0
*/
public static function es_process_template_body( $content, $tmpl_id = 0, $campaign_id = 0 ) {
$content = convert_smilies( wptexturize( $content ) );
$content = self::handle_oembed_content( $content );
// Add p tag only if we aren't getting tags inside the content, otherwise html gets marked as invalid.
if ( false === strpos( $content, 'contacts_db->count_active_contacts_by_list_id();
$content = str_replace( '{{TOTAL-CONTACTS}}', $total_contacts, $content );
$content = str_replace( '{{site.total_contacts}}', $total_contacts, $content );
// blog title
$blog_name = get_option( 'blogname' );
$content = str_replace( '{{SITENAME}}', $blog_name, $content );
$content = str_replace( '{{site.name}}', $blog_name, $content );
// site url
$site_url = home_url( '/' );
$content = str_replace( '{{SITEURL}}', $site_url, $content );
$content = str_replace( '{{site.url}}', $site_url, $content );
/*
TODO: Enable it once Pre header issue fix
$meta = ES()->campaigns_db->get_campaign_meta_by_id( $campaign_id );
$meta['pre_header'] = !empty($meta['pre_header']) ? $meta['pre_header'] : '';
if( !empty( $meta['pre_header'] )){
$content = ''.$content;
}
*/
return $content;
}
/**
* Method to handle oembed content
*
* @param string @content Content.
*
* @return string $content
*
* @since 4.4.9
*/
public static function handle_oembed_content( $content = '' ) {
if ( ! empty( $content ) && isset( $GLOBALS['wp_embed'] ) ) {
add_filter( 'embed_oembed_html', array( 'ES_Common', 'handle_link_in_email_content' ), 10, 4 );
add_filter( 'embed_handler_html', array( 'ES_Common', 'handle_link_in_email_content' ), 10, 3 );
$content = $GLOBALS['wp_embed']->autoembed( $content );
remove_filter( 'embed_oembed_html', array( 'ES_Common', 'handle_link_in_email_content' ), 10, 4 );
remove_filter( 'embed_handler_html', array( 'ES_Common', 'handle_link_in_email_content' ), 10, 3 );
}
return $content;
}
/**
* Method to handle link in email content
*
* URL from {{POSTLINK-ONLY}} was being converted to oembed html if it is not wrapped inside tag's href attribute and is on a seperate line in ES template content
* resulting in a link html for {{POSTLINK-ONLY}} instead of plain text link.
*
* Most email clients like GMail, Outlook do not support videos in the email. To handle it, we are replacing the WordPress's oembed generated HTML for video links to their respective thubmnail images which are then linked the original video URL.
*
* @param string $html HTML for current URL.
* @param string $url Current URL.
* @param array $attr Shortcode attribute.
* @param int $post_ID Current post id.
*
* @return string $html HTML for current URL.
*
* @since 4.4.9
*/
public static function handle_link_in_email_content( $html, $url, $attr, $post_ID = 0 ) {
$post_link = '';
if ( ! empty( $post_ID ) ) {
$post_link = get_permalink( $post_ID );
}
// Check if current URL is same as current post's permalink.
if ( ! empty( $post_link ) && $url === $post_link ) {
// Convert URL HTML back to URL itself if it a current post URL.
$html = $url;
} else {
if ( ! class_exists( 'WP_oEmbed' ) ) {
require_once ABSPATH . 'wp-includes/class-wp-oembed.php';
}
$oembed = new WP_oEmbed();
$provider = $oembed->get_provider( $url );
if ( ! empty( $provider ) ) {
$oembed_response = $oembed->fetch( $provider, $url, $attr );
if ( is_object( $oembed_response ) && ! empty( $oembed_response->type ) && 'video' === $oembed_response->type && ! empty( $oembed_response->thumbnail_url ) ) {
$thumbnail_url = $oembed_response->thumbnail_url;
$title = $oembed_response->title;
$provider_name = $oembed_response->provider_name;
$play_icon_url = '';
switch ( $provider_name ) {
case 'YouTube':
$play_icon_url = ES_PLUGIN_URL . 'lite/public/images/youtube-play-button.png';
break;
case 'Vimeo':
$play_icon_url = ES_PLUGIN_URL . 'lite/public/images/vimeo-play-button.png';
break;
default:
$play_icon_url = ES_PLUGIN_URL . 'lite/public/images/default-play-button.png';
break;
}
ob_start();
$thumbnail_width = 'auto';
$thumbnail_height = 'auto';
if ( ! empty( $oembed_response->thumbnail_width ) && ! empty( $oembed_response->thumbnail_height ) ) {
$thumbnail_width = $oembed_response->thumbnail_width . 'px';
$thumbnail_height = $oembed_response->thumbnail_height . 'px';
} elseif ( ! empty( $oembed_response->width ) && ! empty( $oembed_response->height ) ) {
$thumbnail_width = $oembed_response->width . 'px';
$thumbnail_height = $oembed_response->height . 'px';
}
?>
|
__( 'Subscribed', 'email-subscribers' ),
'unconfirmed' => __( 'Unconfirmed', 'email-subscribers' ),
'unsubscribed' => __( 'Unsubscribed', 'email-subscribers' ),
);
$statuses = apply_filters( 'ig_es_get_statuses_key_name_map', $statuses, $page );
if ( $reverse ) {
$statuses = array_flip( $statuses );
}
return $statuses;
}
/**
* Prepare Statuses dropdown
*
* @param string $selected
* @param string $default_label
*
* @return string
*
* @since 4.0.0
*/
public static function prepare_statuses_dropdown_options( $selected = '', $default_label = '', $page = '' ) {
if ( empty( $default_label ) ) {
$default_label = __( 'Select Status', 'email-subscribers' );
}
$default_status[0] = $default_label;
$statuses = self::get_statuses_key_name_map(false, $page);
$statuses = array_merge( $default_status, $statuses );
$dropdown = '';
foreach ( $statuses as $key => $status ) {
$dropdown .= '';
}
return $dropdown;
}
/**
* Prepare status dropdown options
*
* @param $selected
*
* @return string
*
* @since 4.0.0
*/
public static function prepare_status_dropdown_options( $selected ) {
$statuses = array(
'1' => __( 'Active', 'email-subscribers' ),
'0' => __( 'Inactive', 'email-subscribers' ),
);
$dropdown = '';
foreach ( $statuses as $key => $status ) {
$dropdown .= '';
foreach ( $campaign_type as $key => $type ) {
$dropdown .= '';
foreach ( $statuses as $key => $status ) {
$dropdown .= '';
foreach ( $statuses as $key => $status ) {
$dropdown .= '