data = $data;
}
public function parse_styles( $data ) {
if ( empty( $data ) || ! is_array( $data ) ) {
return $data;
}
$style = '';
$ignore_arr = [
'border-top-width',
'border-right-width',
'border-bottom-width',
'border-left-width',
'border-style',
'border-color',
'border-top-color',
'border-width',
];
foreach ( $data as $key => $value ) {
$key = preg_replace( '/[^a-z0-9\-]/i', '', (string) $key );
if ( $key === '' || in_array( $key, $ignore_arr, true ) ) {
continue;
}
$value = str_replace( [ "\n", "\r", '"', '{', '}' ], '', (string) $value );
$style .= "{$key}:{$value};";
}
$border_style = $data['border-style'] ?? 'solid';
$border_color = $data['border-color'] ?? ( $data['border-top-color'] ?? 'transparent' );
if ( isset( $data['border-top-width'] ) ) {
foreach ( [ 'top', 'right', 'bottom', 'left' ] as $pos ) {
$style .= ! isset( $data["border-{$pos}-width"] ) || $data["border-{$pos}-width"] === '0px'
? "border-{$pos}:0 hidden;"
: "border-{$pos}:{$data["border-{$pos}-width"]} {$border_style} {$border_color};";
}
} elseif ( isset( $data['border-width'] ) ) {
$border_width = $data['border-width'];
if ( $border_width !== '0px' ) {
$style .= " border-width: {$border_width}; ";
$style .= " border-style: {$border_style}; ";
$style .= " border-color: {$border_color}; ";
} else {
$style .= " border:0 hidden; ";
}
}
return esc_attr( $style );
}
public function render() {
$template_id = $this->data['template_id'] ?? '';
if ( ! $template_id ) {
return;
}
$this->custom_css .= get_post_meta( $template_id, 'emtmpl_custom_css', true );
$data = get_post_meta( $template_id, 'emtmpl_email_structure', true );
$schema = json_decode( html_entity_decode( $data ), true );
$this->direction = get_post_meta( $template_id, 'emtmpl_settings_direction', true );
$this->common_render( $schema );
}
public function preview_render() {
if ( empty( $this->data['schema'] ) ) {
return;
}
$this->direction = isset( $_POST['direction'] ) ? sanitize_text_field( wp_unslash( $_POST['direction'] ) ) : 'ltr';// phpcs:ignore WordPress.Security.NonceVerification.Missing
$schema = $this->data['schema'];
$this->common_render( $schema );
}
public function common_render( $schema ) {
$this->check_rendered = true;
$bg_style = '';
$width = 600;
$responsive = 380;
if ( isset( $schema['style_container'] ) ) {
$width = ! empty( $schema['style_container']['width'] ) ? $schema['style_container']['width'] : $width;
$responsive = ! empty( $schema['style_container']['responsive'] ) ? $schema['style_container']['responsive'] : $responsive;
unset( $schema['style_container']['width'] );
unset( $schema['style_container']['responsive'] );
$bg_style = isset( $schema['style_container'] ) ? $this->parse_styles( $schema['style_container'] ) : '';
}
ob_start();
$this->email_body( $schema );
$email_body = ob_get_clean();
add_filter( 'emtmpl_after_render_style', [ $this, 'custom_css' ] );
$this->email_header( $bg_style, $width, $responsive );
echo $email_body;// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
$this->email_footer();
remove_filter( 'emtmpl_after_render_style', [ $this, 'custom_css' ] );
}
public function email_body( $schema ) {
$left_align = $this->direction == 'rtl' ? 'right' : 'left';
?>
parse_styles( $row['props']['style_outer'] ) : '';
?>
$col ) {
$col_style = ! empty( $col['props']['style'] ) ? $this->parse_styles( $col['props']['style'] ) : '';
if ( $start == $key ) { ?>
parse_styles( str_replace( "'", '', $el['style'] ) ) : '';
$el_style = ! empty( $el['props']['style'] ) ? $this->parse_styles( str_replace( "'", '', $el['props']['style'] ) ) : '';
?>
|
props = $el;
do_action( 'emtmpl_render_content', $type, $el, $this ); ?>
|
|
|
|
|
|
get_template( 'email-header.php', [ 'bg_style' => $bg_style, 'width' => $width, 'responsive' => $responsive, 'direction' => $this->direction ] );
}
public function email_footer() {
$this->get_template( 'email-footer.php' );
}
public function render_content( $type, $props ) {
$func = 'render_' . $type;
if ( method_exists( $this, $func ) ) {
$this->$func( $props );
}
}
public function custom_css($css) {
$css .= $this->custom_style();
return $css;
}
public function custom_style() {
return $this->custom_css ? $this->custom_css : '';
}
public function replace_shortcode( $text ) {
$shortcodes = [
'{admin_email}' => get_bloginfo( 'admin_email' ),
'{home_url}' => home_url(),
'{site_title}' => get_bloginfo( 'name' ),
'{current_year}' => date_i18n( 'Y', current_time( 'U' ) ),
];
return str_replace( array_keys( $shortcodes ), array_values( $shortcodes ), $text );
}
public function render_html_image( $props ) {
$src = isset( $props['attrs']['src'] ) ? $props['attrs']['src'] : '';
$width = isset( $props['childStyle']['img'] ) ? $this->parse_styles( $props['childStyle']['img'] ) : '';
$ol_width = ! empty( $props['childStyle']['img']['width'] ) ? str_replace( 'px', '', $props['childStyle']['img']['width'] ) : '100%';
$href = ! empty( $props['attrs']['data-href'] ) ? $props['attrs']['data-href'] : '#';
$alt = ! empty( $props['attrs']['data-alt'] ) ? $props['attrs']['data-alt'] : '';
?>
replace_shortcode( $content );
echo wp_kses( do_shortcode( $content ), emtmpl_allowed_html() );
}
public function get_p_inherit_style( $props ) {
$inherit_style = ! empty( $props['style'] ) ? $props['style'] : [];
$font_weight = $inherit_style['font-weight'] ?? 'inherit';
$font_size = $inherit_style['font-size'] ?? 'inherit';
$line_height = $inherit_style['line-height'] ?? 'inherit';
$color = $inherit_style['color'] ?? 'inherit';
$p_style = [
"font-weight:{$font_weight}",
"font-size:{$font_size}",
"line-height:{$line_height}",
"color:{$color}",
];
return implode( ';', $p_style );
}
public function render_html_social( $props ) {
$align = $props['style']['text-align'] ?? 'left';
$socials = [ 'facebook', 'twitter', 'instagram', 'youtube', 'linkedin', 'whatsapp' ];
$html = '';
$width = ! empty( $props['attrs']['data-width'] ) ? $props['attrs']['data-width'] : 32;
if ( isset( $props['attrs']['direction'] ) && $props['attrs']['direction'] === 'vertical' ) {
foreach ( $socials as $social ) {
$link = isset( $props['attrs'][ $social . '_url' ] ) ? esc_url( $props['attrs'][ $social . '_url' ] ) : '';
$img = isset( $props['attrs'][ $social ] ) ? esc_url( $props['attrs'][ $social ] ) : '';
if ( ! empty( $img ) && ! empty( $link ) ) {
$html .= " |
";
}
}
} else {
$html = '';
foreach ( $socials as $social ) {
$link = isset( $props['attrs'][ $social . '_url' ] ) ? esc_url( $props['attrs'][ $social . '_url' ] ) : '';
$img = isset( $props['attrs'][ $social ] ) ? esc_url( $props['attrs'][ $social ] ) : '';
if ( ! empty( $img ) && ! empty( $link ) ) {
$html .= " | ";
}
}
$html .= '
';
}
$html = "";
echo wp_kses( $html, emtmpl_allowed_html() );
}
public function render_html_button( $props ) {
$url = isset( $props['attrs']['href'] ) ? $this->replace_shortcode( $props['attrs']['href'] ) : '';
$text = isset( $props['content']['text'] ) ? $this->replace_shortcode( $props['content']['text'] ) : '';
$text = str_replace( [ '', '
' ], [ '', '' ], $text );
$align = $props['style']['text-align'] ?? 'left';
$style = isset( $props['childStyle']['a'] ) ? $props['childStyle']['a'] : [];
$padding = ! empty( $style['padding'] ) ? $style['padding'] : '';
$border_radius = ! empty( $style['border-radius'] ) ? $style['border-radius'] : '';
$bg_color = ! empty( $style['background-color'] ) ? $style['background-color'] : 'inherit';
unset( $style['padding'] );
$style = $this->parse_styles( $style );
$text_color = $props['style']['color'] ?? 'inherit';
$font_weight = $props['style']['font-weight'] ?? 'normal';
$width = $props['childStyle']['a']['width'] ?? '';
$line_height = $props['style']['line-height'] ?? 1;
$height = str_replace( 'px', '', $line_height );
$a_style = [
"color:{$text_color} !important",
"font-weight:{$font_weight}",
"display:block;text-decoration:none;text-transform:none;margin:0;text-align: center;max-width: 100%",
"background-color:{$bg_color}",
"line-height:{$line_height}",
"height:{$line_height}",
];
?>
$value ) {
$link = isset( $props['attrs'][ $key ] ) ? $this->replace_shortcode( $props['attrs'][ $key ] ) : '';
if ( empty( $value ) || ! $link ) {
continue;
} ?>
|
|
$value ) {
$link = isset( $props['attrs'][ $key ] ) ? $this->replace_shortcode( $props['attrs'][ $key ] ) : '';
if ( empty( $value ) || ! $link ) {
continue;
}
?>
|
|
parse_styles( $props['childStyle']['hr'] ) : '';
?>
parse_styles( $props['childStyle']['.emtmpl-spacer'] ) : '';
$mobile_hidden = ! empty( $props['attrs']['mobile-hidden'] ) && $props['attrs']['mobile-hidden'] == 'true' ? 'emtmpl-mobile-hidden' : '';
?>
replace_shortcode( $props['attrs']['home_link'] ) : '';
$text = isset( $props['content']['home_text'] ) ? $this->replace_shortcode( base64_decode( $props['content']['home_text'] ) ) : ''; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
?>
' style='padding-right: 3px;'> |
|
replace_shortcode( $props['attrs']['email_link'] );
?>
' style='padding-right: 3px;'> |
|
' style='padding-right: 3px;'> |
'>
|
parse_styles( $props['childStyle']['p'] ) : '';
$a = ! empty( $props['childStyle']['a'] ) ? $this->parse_styles( $props['childStyle']['a'] ) : '';
// $this->custom_css .= $p ? "#emtmpl-transferred-content p, #emtmpl-transferred-content {{$p}}" : '';
$this->custom_css .= $a ? "#emtmpl-transferred-content a{{$a}}" : '';
$this->custom_css .= "#emtmpl-transferred-content a{color:{$link_color} !important;}";
$content = $this->data['content'] ?? '';
if ( $content ) {
if (apply_filters('emtmpl_render_html_recover_content_auto_break_line', true)) {
// $content = nl2br( $content );
$content = wpautop( $content );
}
printf( '', esc_attr( $p ) );
echo apply_filters('emtmpl_get_html_recover_content',wp_kses( $content, emtmpl_allowed_html() ), $content) . '
';
}
}
public function table( $content, $style = '', $width = '100%', $attr = [] ) {
?>
parse_styles( $data );
}
}