';
}
if ( ! empty( $s['admin_notify'] ) ) {
$to = $s['admin_to'] ? $s['admin_to'] : fillnova_get_setting( 'admin_email', get_option( 'admin_email' ) );
$h = $headers;
if ( ! empty( $s['reply_to_field'] ) && ! empty( $values[ $s['reply_to_field'] ] ) && is_email( $values[ $s['reply_to_field'] ] ) ) {
$h[] = 'Reply-To: ' . $values[ $s['reply_to_field'] ];
}
$subject = self::merge_tags( $s['admin_subject'], $form, $values, $entry_id, true );
$body = self::wrap( self::merge_tags( $s['admin_message'], $form, $values, $entry_id ), $form, $entry_id, true );
wp_mail( $to, wp_strip_all_tags( $subject ), $body, apply_filters( 'fillnova_admin_email_headers', $h, $form, $values ) );
}
if ( ! empty( $s['user_notify'] ) && ! empty( $s['user_email_field'] ) && ! empty( $values[ $s['user_email_field'] ] ) && is_email( $values[ $s['user_email_field'] ] ) ) {
$subject = self::merge_tags( $s['user_subject'], $form, $values, $entry_id, true );
$body = self::wrap( self::merge_tags( $s['user_message'], $form, $values, $entry_id ), $form, $entry_id, false );
wp_mail( $values[ $s['user_email_field'] ], wp_strip_all_tags( $subject ), $body, $headers );
}
}
/**
* Wrap message in a clean HTML email template.
*
* @param string $content Content (may contain HTML).
* @param array $form Form.
* @param int $entry_id Entry ID.
* @param bool $admin Admin email.
* @return string
*/
protected static function wrap( $content, $form, $entry_id, $admin ) {
$color = esc_attr( $form['settings']['primary_color'] );
$link = '';
if ( $admin && $entry_id ) {
$url = admin_url( 'admin.php?page=fillnova-entries&entry=' . $entry_id );
$link = '
' . esc_html__( 'View entry', 'fillnova' ) . '
';
}
$html = ''
. '
'
. '
'
. '
'
. '
' . esc_html( $form['title'] ) . '
'
. ( false !== strpos( $content, '
'
. '' . esc_html( get_bloginfo( 'name' ) ) . '
'
. '';
return apply_filters( 'fillnova_email_html', $html, $content, $form, $entry_id );
}
/**
* Apply wpautop to text but leave tables untouched.
*
* @param string $content Content.
* @return string
*/
public static function autop_outside_tables( $content ) {
$parts = preg_split( '/()/s', $content, -1, PREG_SPLIT_DELIM_CAPTURE );
$out = '';
foreach ( $parts as $p ) {
$out .= 0 === strpos( $p, ' $form['title'],
'{form_id}' => (string) $form['id'],
'{entry_id}' => (string) $entry_id,
'{site_name}' => get_bloginfo( 'name' ),
'{site_url}' => home_url(),
'{date}' => wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ),
'{ip}' => fillnova_client_ip(),
);
if ( false !== strpos( $text, '{all_fields}' ) ) {
$map['{all_fields}'] = $plain ? self::all_fields_plain( $form, $values ) : self::all_fields_html( $form, $values );
}
$text = strtr( (string) $text, $map );
$text = preg_replace_callback(
'/\{field:([a-z0-9_]+)\}/',
function ( $m ) use ( $fields, $values, $plain ) {
if ( ! isset( $values[ $m[1] ] ) ) {
return '';
}
$f = isset( $fields[ $m[1] ] ) ? $fields[ $m[1] ] : array( 'type' => 'text' );
$v = self::format_value( $f, $values[ $m[1] ] );
return $plain ? $v : esc_html( $v );
},
$text
);
return (string) apply_filters( 'fillnova_merge_tags', $text, $form, $values, $entry_id, $plain );
}
/**
* Human readable value.
*
* @param array $field Field.
* @param mixed $value Value.
* @return string
*/
public static function format_value( $field, $value ) {
$custom = apply_filters( 'fillnova_format_value', null, $field, $value );
if ( null !== $custom ) {
return (string) $custom;
}
if ( in_array( $field['type'], array( 'name', 'address' ), true ) && is_array( $value ) ) {
$sep = 'name' === $field['type'] ? ' ' : ', ';
return implode( $sep, array_filter( array_map( 'strval', $value ) ) );
}
if ( 'rating' === $field['type'] && '' !== (string) $value ) {
$stars = ! empty( $field['stars'] ) ? (int) $field['stars'] : 5;
return $value . ' / ' . $stars;
}
return fillnova_value_to_string( $value );
}
/**
* Fields list as HTML table.
*
* @param array $form Form.
* @param array $values Values.
* @return string
*/
public static function all_fields_html( $form, $values ) {
$rows = '';
foreach ( $form['fields'] as $f ) {
if ( ! array_key_exists( $f['id'], $values ) || 'hidden' === $f['type'] && '' === (string) $values[ $f['id'] ] ) {
continue;
}
$v = self::format_value( $f, $values[ $f['id'] ] );
if ( 'file' === $f['type'] && is_array( $values[ $f['id'] ] ) ) {
$links = array();
foreach ( $values[ $f['id'] ] as $url ) {
$links[] = '' . esc_html( basename( $url ) ) . '';
}
$v_html = implode( '
', $links );
} else {
$v_html = nl2br( esc_html( '' !== $v ? $v : '—' ) );
}
$rows .= '| ' . esc_html( isset( $f['label'] ) ? $f['label'] : $f['id'] ) . '' . $v_html . ' |
';
}
return '';
}
/**
* Fields list as plain text.
*
* @param array $form Form.
* @param array $values Values.
* @return string
*/
public static function all_fields_plain( $form, $values ) {
$lines = array();
foreach ( $form['fields'] as $f ) {
if ( array_key_exists( $f['id'], $values ) ) {
$lines[] = ( isset( $f['label'] ) ? $f['label'] : $f['id'] ) . ': ' . self::format_value( $f, $values[ $f['id'] ] );
}
}
return implode( "\n", $lines );
}
}