File: /home/globfdxw/www/wp-content/plugins/wpforms-pdf/src/Builder/Settings/Appearance.php
<?php
namespace WPFormsPDF\Builder\Settings;
use WPFormsPDF\Builder\FormBuilder;
use WPFormsPDF\Templates\Themes;
/**
* Class Appearance handles appearance settings for PDF form builder.
*
* @since 1.0.0
*/
class Appearance {
/**
* PDF ID.
*
* @since 1.0.0
*
* @var int|string
*/
private $pdf_id;
/**
* Settings.
*
* @since 1.0.0
*
* @var object
*/
private $settings;
/**
* Builder.
*
* @since 1.0.0
*
* @var FormBuilder
*/
private $builder;
/**
* Themes.
*
* @since 1.0.0
*
* @var Themes
*/
private $themes;
/**
* Constructor.
*
* @since 1.0.0
*
* @param int|string $pdf_id PDF ID.
* @param object $settings Settings object.
*/
public function __construct( $pdf_id, object $settings ) {
$this->pdf_id = $pdf_id;
$this->settings = $settings;
$this->builder = wpforms_pdf()->form_builder;
$this->themes = wpforms_pdf()->themes;
}
/**
* Get an appearance settings group.
*
* @since 1.0.0
*
* @return string
*/
public function get_settings_group(): string {
$appearance = $this->get_global_settings();
$appearance .= $this->get_notification_settings_group();
$appearance .= $this->get_general_settings_group();
return wpforms_panel_fields_group(
$appearance,
[
'title' => esc_html__( 'Appearance', 'wpforms-pdf' ),
'description' => esc_html__( 'Add a logo and customize the style and orientation of your PDF.', 'wpforms-pdf' ),
'group' => 'settings_pdf_appearance',
'class' => 'wpforms-pdf-appearance-group',
'default' => 'opened',
'borders' => [ 'top' ],
'unfoldable' => true,
],
false
);
}
/**
* Get global settings.
*
* @since 1.0.0
*
* @return string
*/
private function get_global_settings(): string {
$appearance = wpforms_panel_field(
'select',
'pdfs',
'theme',
$this->settings->form_data,
esc_html__( 'Theme', 'wpforms-pdf' ),
[
'options' => $this->get_themes_options(),
'default' => 'creamsicle',
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'wpforms-field-pdf-theme col-two-thirds',
'tooltip' => esc_html__( 'Choose a predefined color theme for your PDF.', 'wpforms-pdf' ),
],
false
);
$appearance .= sprintf(
'<div class="wpforms-panel-field col-third wpforms-field-pdf-theme-edit">
<button type="button" class="wpforms-btn wpforms-btn-sm wpforms-btn-light-grey" aria-label="%2$s" data-pdf-id="%1$s">%2$s</button>
</div>',
$this->pdf_id,
esc_html__( 'Edit Theme Colors', 'wpforms-pdf' )
);
$appearance .= $this->builder->get_custom_entity_settings( $this->pdf_id, 'theme', $this->settings->form_data );
$appearance .= $this->get_theme_editor_settings();
$defaults = $this->builder->get_defaults();
$appearance .= wpforms_panel_field(
'image_upload',
'pdfs',
'logo',
$this->settings->form_data,
esc_html__( 'Logo', 'wpforms-pdf' ),
[
'tooltip' => esc_html__( 'Upload a logo to display at the top of your PDF.', 'wpforms-pdf' ),
'subsection' => $this->pdf_id,
'parent' => 'settings',
'default_size' => $defaults['appearance']['logo_size'],
'default_position' => 'center',
'default_url' => $defaults['appearance']['logo_url'],
],
false
);
return $appearance;
}
/**
* Get theme color editor settings.
*
* @since 1.0.0
*
* @return string
*/
public function get_theme_editor_settings(): string {
$scheme = [
'accent' => esc_html__( 'Accent', 'wpforms-pdf' ),
'complementary' => esc_html__( 'Complementary', 'wpforms-pdf' ),
'primary' => esc_html__( 'Primary', 'wpforms-pdf' ),
'secondary' => esc_html__( 'Secondary', 'wpforms-pdf' ),
'tertiary' => esc_html__( 'Tertiary', 'wpforms-pdf' ),
'border' => esc_html__( 'Border', 'wpforms-pdf' ),
'background_light' => esc_html__( 'Background Tint', 'wpforms-pdf' ),
'background' => esc_html__( 'Background', 'wpforms-pdf' ),
];
$color_settings = '';
foreach ( $scheme as $key => $label ) {
$color_settings .= wpforms_panel_field(
'color',
'pdfs',
'theme_color_' . $key,
$this->settings->form_data,
'',
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'col-half',
'default' => '',
'after' => "<p class='sublabel'>$label</p>",
],
false
);
}
return sprintf(
'<div id="wpforms-panel-field-pdfs-%1$s-theme-editor" class="wpforms-pdf-theme-color-editor wpforms-hidden">%2$s</div>',
$this->pdf_id,
$color_settings
);
}
/**
* Get font settings.
*
* @since 1.2.0
*
* @param string $group The group, 'notification' or 'general'.
*
* @return string
* @noinspection HtmlUnknownAttribute
*/
private function get_font_settings( string $group ): string {
$defaults = $this->builder->get_defaults();
$font_class = $group === 'notification' ? 'col-half' : '';
$font_settings = wpforms_panel_field(
'select',
'pdfs',
$group . '_font',
$this->settings->form_data,
esc_html__( 'Font', 'wpforms-pdf' ),
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => $font_class,
'default' => $defaults['appearance']['font'] ?? 'sans-serif',
'options' => [
'default' => esc_html__( 'Default', 'wpforms-pdf' ),
'sans-serif' => esc_html__( 'Inter', 'wpforms-pdf' ),
'serif' => esc_html__( 'Literata', 'wpforms-pdf' ),
'noto-sans' => esc_html__( 'Noto Sans', 'wpforms-pdf' ),
'noto-sans-arabic' => esc_html__( 'Noto Sans Arabic', 'wpforms-pdf' ),
'noto-sans-sc' => esc_html__( 'Noto Sans Simplified Chinese', 'wpforms-pdf' ),
'noto-sans-tc' => esc_html__( 'Noto Sans Traditional Chinese', 'wpforms-pdf' ),
'noto-sans-devanagari' => esc_html__( 'Noto Sans Devanagari', 'wpforms-pdf' ),
'noto-sans-hebrew' => esc_html__( 'Noto Sans Hebrew', 'wpforms-pdf' ),
'noto-sans-jp' => esc_html__( 'Noto Sans Japanese', 'wpforms-pdf' ),
'noto-sans-kr' => esc_html__( 'Noto Sans Korean', 'wpforms-pdf' ),
],
],
false
);
if ( $group === 'general' ) {
return $font_settings;
}
$font_settings .= wpforms_panel_field(
'select',
'pdfs',
$group . '_font_size',
$this->settings->form_data,
esc_html__( 'Font Size', 'wpforms-pdf' ),
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'col-half',
'default' => '16px',
'options' => [
'8px' => esc_html__( '8px', 'wpforms-pdf' ),
'9px' => esc_html__( '9px', 'wpforms-pdf' ),
'10px' => esc_html__( '10px', 'wpforms-pdf' ),
'11px' => esc_html__( '11px', 'wpforms-pdf' ),
'12px' => esc_html__( '12px', 'wpforms-pdf' ),
'14px' => esc_html__( '14px', 'wpforms-pdf' ),
'16px' => esc_html__( '16px', 'wpforms-pdf' ),
'18px' => esc_html__( '18px', 'wpforms-pdf' ),
'20px' => esc_html__( '20px', 'wpforms-pdf' ),
'22px' => esc_html__( '22px', 'wpforms-pdf' ),
'24px' => esc_html__( '24px', 'wpforms-pdf' ),
],
],
false
);
return $font_settings;
}
/**
* Get notification template appearance settings.
*
* @since 1.0.0
*
* @return string
* @noinspection HtmlUnknownAttribute
*/
private function get_notification_settings_group(): string {
$appearance = sprintf(
'<div class="wpforms-pdf-appearance-settings" data-category="notification" %1$s>',
$this->is_shown( 'notification' ) ? '' : 'style="display:none"'
);
$appearance .= $this->get_font_settings( 'notification' );
$appearance .= wpforms_panel_field(
'color',
'pdfs',
'notification_text_color',
$this->settings->form_data,
esc_html__( 'Text Color', 'wpforms-pdf' ),
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'col-half',
'default' => $this->get_theme_color( 'creamsicle', 'primary' ),
],
false
);
$appearance .= wpforms_panel_field(
'color',
'pdfs',
'notification_link_color',
$this->settings->form_data,
esc_html__( 'Link Color', 'wpforms-pdf' ),
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'col-half',
'default' => $this->get_theme_color( 'creamsicle', 'accent' ),
],
false
);
$appearance .= wpforms_panel_field(
'color',
'pdfs',
'notification_page_background_color',
$this->settings->form_data,
esc_html__( 'Background Color', 'wpforms-pdf' ),
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'col-half',
'default' => $this->get_theme_color( 'creamsicle', 'background' ),
],
false
);
$appearance .= wpforms_panel_field(
'color',
'pdfs',
'notification_container_background_color',
$this->settings->form_data,
esc_html__( 'Body Color', 'wpforms-pdf' ),
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'col-half',
'default' => $this->get_theme_color( 'creamsicle', 'background_light' ),
],
false
);
$appearance .= '</div>';
return $appearance;
}
/**
* Get general template appearance settings based on the screenshot.
*
* @since 1.0.0
*
* @return string
*/
private function get_general_settings_group(): string {
$appearance =
'<div class="wpforms-pdf-appearance-settings" data-category="general" ' .
( $this->is_shown( 'general' ) ? '' : 'style="display:none"' ) . '>';
$appearance .= $this->get_font_settings( 'general' );
$appearance .= wpforms_panel_field(
'color',
'pdfs',
'general_page_background_color',
$this->settings->form_data,
esc_html__( 'Page Background', 'wpforms-pdf' ),
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'col-half',
'default' => $this->get_theme_color( 'creamsicle', 'background' ),
'after' => '<p class="note">' . esc_html__( 'Color', 'wpforms-pdf' ) . '</p>',
],
false
);
$appearance .= wpforms_panel_field(
'select',
'pdfs',
'page_background_image',
$this->settings->form_data,
'',
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'col-half wpforms-pdf-page-background-image',
'default' => 'none',
'options' => $this->get_background_image_options(),
'after' => '<p class="note">' . esc_html__( 'Image', 'wpforms-pdf' ) . '</p>',
],
false
);
$appearance .= wpforms_panel_field(
'color',
'pdfs',
'general_container_background_color',
$this->settings->form_data,
esc_html__( 'Container Background', 'wpforms-pdf' ),
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'col-half',
'default' => $this->get_theme_color( 'creamsicle', 'background_light' ),
'after' => '<p class="note">' . esc_html__( 'Color', 'wpforms-pdf' ) . '</p>',
],
false
);
$appearance .= wpforms_panel_field(
'select',
'pdfs',
'general_container_border_radius',
$this->settings->form_data,
'',
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'col-half',
'default' => '0px',
'options' => [
'0px' => esc_html__( '0px', 'wpforms-pdf' ),
'4px' => esc_html__( '4px', 'wpforms-pdf' ),
'8px' => esc_html__( '8px', 'wpforms-pdf' ),
'12px' => esc_html__( '12px', 'wpforms-pdf' ),
'16px' => esc_html__( '16px', 'wpforms-pdf' ),
],
'after' => '<p class="note">' . esc_html__( 'Rounded Corners', 'wpforms-pdf' ) . '</p>',
],
false
);
$appearance .= wpforms_panel_field(
'select',
'pdfs',
'general_container_border_style',
$this->settings->form_data,
esc_html__( 'Container Border', 'wpforms-pdf' ),
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => 'col-third wpforms-pdf-border-style',
'default' => 'none',
'options' => [
'none' => esc_html__( 'None', 'wpforms-pdf' ),
'solid' => esc_html__( 'Solid', 'wpforms-pdf' ),
'dashed' => esc_html__( 'Dashed', 'wpforms-pdf' ),
'dotted' => esc_html__( 'Dotted', 'wpforms-pdf' ),
],
'after' => '<p class="note">' . esc_html__( 'Style', 'wpforms-pdf' ) . '</p>',
],
false
);
$class =
'col-third wpforms-pdf-border-size' .
( $this->get_settings_value( 'general_container_border_style' ) === 'none' ? ' wpforms-disabled' : '' );
$appearance .= wpforms_panel_field(
'select',
'pdfs',
'general_container_border_size',
$this->settings->form_data,
'',
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => $class,
'default' => '1px',
'options' => [
'1px' => esc_html__( '1px', 'wpforms-pdf' ),
'2px' => esc_html__( '2px', 'wpforms-pdf' ),
'3px' => esc_html__( '3px', 'wpforms-pdf' ),
'4px' => esc_html__( '4px', 'wpforms-pdf' ),
'5px' => esc_html__( '5px', 'wpforms-pdf' ),
],
'after' => '<p class="note">' . esc_html__( 'Size', 'wpforms-pdf' ) . '</p>',
],
false
);
$class =
'col-third wpforms-pdf-border-color' .
( $this->get_settings_value( 'general_container_border_style' ) === 'none' ? ' wpforms-disabled' : '' );
$appearance .= wpforms_panel_field(
'color',
'pdfs',
'general_container_border_color',
$this->settings->form_data,
'',
[
'subsection' => $this->pdf_id,
'parent' => 'settings',
'class' => $class,
'default' => $this->get_theme_color( 'creamsicle', 'border' ),
'after' => '<p class="note">' . esc_html__( 'Color', 'wpforms-pdf' ) . '</p>',
],
false
);
$appearance .= '</div>';
return $appearance;
}
/**
* Get background image options for the PDF settings.
*
* @since 1.0.0
*
* @return array
*/
private function get_background_image_options(): array {
return [
'none' => esc_html__( 'None', 'wpforms-pdf' ),
'ribbons' => esc_html__( 'Ribbons', 'wpforms-pdf' ),
'triangles' => esc_html__( 'Triangles', 'wpforms-pdf' ),
'waves' => esc_html__( 'Waves', 'wpforms-pdf' ),
'wings' => esc_html__( 'Wings', 'wpforms-pdf' ),
'four-corners' => esc_html__( 'Four Corners', 'wpforms-pdf' ),
'two-corners' => esc_html__( 'Two Corners', 'wpforms-pdf' ),
'classic' => esc_html__( 'Classic', 'wpforms-pdf' ),
'vintage' => esc_html__( 'Vintage', 'wpforms-pdf' ),
'halftone' => esc_html__( 'Halftone', 'wpforms-pdf' ),
'layers' => esc_html__( 'Layers', 'wpforms-pdf' ),
'paper' => esc_html__( 'Paper', 'wpforms-pdf' ),
'confetti' => esc_html__( 'Confetti', 'wpforms-pdf' ),
'gradient' => esc_html__( 'Gradient', 'wpforms-pdf' ),
'gradient-reverse' => esc_html__( 'Gradient Reverse', 'wpforms-pdf' ),
'gradient-dark' => esc_html__( 'Gradient Dark', 'wpforms-pdf' ),
'gradient-dark-reverse' => esc_html__( 'Gradient Dark Reverse', 'wpforms-pdf' ),
];
}
/**
* Get themes options.
*
* @since 1.0.0
*
* @return array
*/
private function get_themes_options(): array {
return array_map(
static function ( $theme ) {
return $theme['title'];
},
$this->get_themes()
);
}
/**
* Get available themes.
*
* @since 1.0.0
*
* @return array Themes data.
*/
private function get_themes(): array {
return $this->themes->get_all_themes();
}
/**
* Get theme color.
*
* @since 1.0.0
*
* @param string $theme_id Theme ID.
* @param string $color Color slug.
*
* @return string Color value.
* @noinspection PhpSameParameterValueInspection
*/
private function get_theme_color( string $theme_id, string $color ): string {
$theme = $this->themes->get_theme( $theme_id );
return $theme['colors'][ $color ] ?? '';
}
/**
* Get settings value.
*
* @since 1.0.0
*
* @param string $key Settings key.
* @param string $default_value Default value.
*
* @return string Setting value.
*/
private function get_settings_value( string $key, string $default_value = '' ): string {
$settings = $this->settings->form_data['settings']['pdfs'] ?? [];
return $settings[ $this->pdf_id ][ $key ] ?? $default_value;
}
/**
* Check if the category is shown based on the selected category.
*
* @since 1.0.0
*
* @param string $category Category slug.
*
* @return bool
*/
private function is_shown( string $category ): bool {
$selected_category = $this->get_settings_value( 'template_category', 'notification' );
if ( $category === 'notification' && $selected_category === 'notification' ) {
return true;
}
if ( $category === 'general' && $selected_category !== 'notification' ) {
return true;
}
return false;
}
}