diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index 7b0d03f867..3d65133fdf 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -732,6 +732,8 @@ public static function admin_js() { global $pagenow; if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow === 'edit.php' && $post_type === 'frm_display' ) ) { + self::enqueue_global_settings_scripts( $page ); + wp_enqueue_script( 'admin-widgets' ); wp_enqueue_style( 'widgets' ); self::maybe_deregister_popper2(); @@ -809,6 +811,18 @@ private static function enqueue_builder_assets( $plugin_url, $version ) { wp_enqueue_script( 'formidable-settings-components' ); } + /** + * Enqueues global settings scripts. + * + * @param string $page The `page` param in URL. + */ + private static function enqueue_global_settings_scripts( $page ) { + if ( 'formidable-settings' === $page ) { + wp_enqueue_style( 'wp-color-picker' ); + wp_enqueue_script( 'formidable_settings' ); + } + } + /** * Avoid loading dropzone CSS on the form list page. It isn't required there. * diff --git a/classes/controllers/FrmEmailStylesController.php b/classes/controllers/FrmEmailStylesController.php new file mode 100644 index 0000000000..d63e74e49b --- /dev/null +++ b/classes/controllers/FrmEmailStylesController.php @@ -0,0 +1,476 @@ + array( + 'name' => __( 'Classic', 'formidable' ), + 'selectable' => true, + 'icon_url' => $icon_dir_url . 'classic.svg', + 'is_plain_text' => false, + ), + 'plain' => array( + 'name' => __( 'Plain Text', 'formidable' ), + 'selectable' => true, + 'icon_url' => $icon_dir_url . 'plain.svg', + 'is_plain_text' => true, + ), + 'modern' => array( + 'name' => __( 'Modern', 'formidable' ), + 'selectable' => false, + 'icon_url' => $icon_dir_url . 'modern.svg', + 'is_plain_text' => false, + ), + 'sleek' => array( + 'name' => __( 'Sleek', 'formidable' ), + 'selectable' => false, + 'icon_url' => $icon_dir_url . 'sleek.svg', + 'is_plain_text' => false, + ), + 'compact' => array( + 'name' => __( 'Compact', 'formidable' ), + 'selectable' => false, + 'icon_url' => $icon_dir_url . 'compact.svg', + 'is_plain_text' => false, + ), + ); + + /** + * Filter the email styles. + * + * @since x.x + * + * @param array[] $email_styles The email styles. + * @return array + */ + return apply_filters( 'frm_email_styles', $email_styles ); + } + + /** + * Gets email style preview URL. + * + * @param string $style_key Style key. + * @return string + */ + public static function get_email_style_preview_url( $style_key ) { + return wp_nonce_url( admin_url( 'admin-ajax.php?action=frm_email_style_preview&style_key=' . $style_key ), 'frm_email_style_preview' ); + } + + /** + * Gets the email style set in the Global settings. + * + * @return string + */ + public static function get_default_email_style() { + $frm_settings = FrmAppHelper::get_settings(); + if ( empty( $frm_settings->email_style ) ) { + return 'classic'; + } + + // Check if the selected style is available and selectable. + $styles = self::get_email_styles(); + $style = $frm_settings->email_style; + if ( isset( $styles[ $style ] ) && ! empty( $styles[ $style ]['selectable'] ) ) { + return $style; + } + + return 'classic'; + } + + /** + * Gets the test email content. + * + * @param false|string $style_key Default is `false`, using the one in settings. + * @return string + */ + private static function get_test_email_content( $style_key = false ) { + if ( ! $style_key ) { + $style_key = self::get_default_email_style(); + } + + $table_rows = array( + array( + 'label' => 'Name', + 'value' => 'John Doe', + ), + array( + 'label' => 'Email address', + 'value' => 'john@doe.com', + ), + array( + 'label' => 'Subject', + 'value' => 'Contact subject', + ), + array( + 'label' => 'Message', + 'value' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. + Praesent in risus velit. Donec molestie tincidunt ex sed consequat. Ut ornare fringilla fringilla.', + ), + ); + + if ( 'plain' !== $style_key ) { + $content = self::get_test_rich_text_email_content( $style_key, $table_rows ); + } else { + $content = ''; + foreach ( $table_rows as $row ) { + $content .= $row['label'] . ': ' . $row['value'] . "\r\n"; + } + }//end if + + return $content; + } + + /** + * Gets the test email content. + * + * @param string $style_key Style key. + * @param array $table_rows Table rows. + * @return string + */ + private static function get_test_rich_text_email_content( $style_key, $table_rows ) { + $style_settings = self::get_email_style_settings(); + + // Sleek table style doesn't have any border. + $should_remove_border = 'sleek' === $style_key; + + // Modern and Compact table styles don't have top and bottom border. + $should_remove_top_bottom_border = 'classic' !== $style_key; + + $table_generator = self::get_table_generator( $style_key ); + + $content = $table_generator->generate_table_header(); + + // By default, table has the bottom border and table cells have top border. + if ( $should_remove_top_bottom_border ) { + $content = $table_generator->remove_border( $content, 'bottom' ); + } + + foreach ( $table_rows as $index => $row ) { + if ( 'compact' === $style_key ) { + // Compact table has two columns layout. + $table_row = $table_generator->generate_two_cell_table_row( $row['label'], $row['value'] ); + } else { + // Other table styles have one column layout. + $table_row = $table_generator->generate_single_cell_table_row( self::get_content_for_one_column_cell( $row['label'], $row['value'] ) ); + } + + if ( ! $index && $should_remove_top_bottom_border ) { + $table_row = $table_generator->remove_border( $table_row ); + } + + $content .= $table_row; + } + + $content .= $table_generator->generate_table_footer(); + + if ( $should_remove_border ) { + $content = $table_generator->remove_border( $content, 'top' ); + } + + if ( 'classic' !== $style_key ) { + $content = self::wrap_email_message( $content ); + } + + $wrapped_content = '
'; + if ( 'classic' !== $style_key ) { + // This works in previewing and as a fallback for email content. + $wrapped_content .= ''; + } + $wrapped_content .= '' . $content . '