File: //home/globfdxw/www/wp-content/plugins/wpforms-pdf/src/Templates/Themes.php
<?php
namespace WPFormsPDF\Templates;
use WPForms\Helpers\File;
use WPFormsPDF\Storage;
/**
* PDF templates' themes class.
*
* @since 1.0.0
*/
class Themes {
/**
* Default theme slug.
*
* @since 1.0.0
*
* @var string
*/
public const DEFAULT_THEME = 'creamsicle';
/**
* Custom themes file.
*
* @since 1.0.0
*
* @var string
*/
public const CUSTOM_THEMES_FILE = 'custom-themes.json';
/**
* Default colors.
*
* @since 1.0.0
*
* @var array
*/
public const DEFAULT_COLORS = [
'accent' => '#FA7315',
'complementary' => '#44403C',
'primary' => '#44403C',
'secondary' => '#78716C',
'tertiary' => '#A8A29F',
'border' => '#E7E5E4',
'background_light' => '#F5F5F4',
'background' => '#FFFFFF',
];
/**
* Themes.
*
* @since 1.0.0
*
* @var array
*/
private $themes = [];
/**
* Custom themes.
*
* @since 1.0.0
*
* @var array|mixed
*/
private $custom_themes;
/**
* Class constructor.
*
* @since 1.0.0
*
* @return void
*/
public function __construct() {}
/**
* Get all templates in a single array.
*
* @since 1.0.0
*
* @return array
*/
public function get_all_themes(): array {
return array_merge(
$this->get_custom_themes(),
$this->get_themes()
);
}
/**
* Get single theme data.
*
* @since 1.0.0
*
* @param string $theme_slug Theme slug.
*
* @return array
*/
public function get_theme( string $theme_slug ): array {
$themes = $this->get_all_themes();
$theme = $themes[ $theme_slug ] ?? $themes[ self::DEFAULT_THEME ]; // Fallback to the Creamsicle theme.
if ( empty( $theme ) ) {
// Fallback to the first theme in the array.
$theme = $themes[ key( $themes ) ] ?? [];
}
// Fallback to the default colors.
$theme['colors'] = wp_parse_args( $theme['colors'] ?? [], self::DEFAULT_COLORS );
return $theme;
}
/**
* Get predefined themes data.
*
* @since 1.0.0
*
* @return array
*/
public function get_themes(): array {
if ( ! empty( $this->themes ) ) {
return $this->themes;
}
$themes = [
'creamsicle' => [
'title' => esc_html__( 'Creamsicle', 'wpforms-pdf' ),
'colors' => [
'accent' => '#FA7315',
'complementary' => '#44403C',
'primary' => '#44403C',
'secondary' => '#78716C',
'tertiary' => '#A8A29F',
'border' => '#E7E5E4',
'background_light' => '#F5F5F4',
'background' => '#ffffff',
],
],
'crimson' => [
'title' => esc_html__( 'Crimson', 'wpforms-pdf' ),
'colors' => [
'accent' => '#780000',
'complementary' => '#C1121F',
'primary' => '#003049',
'secondary' => '#669BBC',
'tertiary' => '#B0CBDB',
'border' => '#D6E4EC',
'background_light' => '#f4f7fa',
'background' => '#FFFFFF',
],
],
'ruby' => [
'title' => esc_html__( 'Ruby', 'wpforms-pdf' ),
'colors' => [
'accent' => '#9A1B1B',
'complementary' => '#DC2625',
'primary' => '#44403C',
'secondary' => '#78716C',
'tertiary' => '#A8A29F',
'border' => '#E7E5E4',
'background_light' => '#F5F5F4',
'background' => '#FFFFFF',
],
],
'skyline' => [
'title' => esc_html__( 'Skyline', 'wpforms-pdf' ),
'colors' => [
'accent' => '#AE2012',
'complementary' => '#0A9396',
'primary' => '#001219',
'secondary' => '#005F73',
'tertiary' => '#0A9396',
'border' => '#E9D8A6',
'background_light' => '#f9f5e8',
'background' => '#ffffff',
],
],
'merlot' => [
'title' => esc_html__( 'Merlot', 'wpforms-pdf' ),
'colors' => [
'accent' => '#6F1D1B',
'complementary' => '#BB9457',
'primary' => '#432818',
'secondary' => '#99582A',
'tertiary' => '#BB9457',
'border' => '#FFE6A7',
'background_light' => '#fef8e8',
'background' => '#ffffff',
],
],
'cherry' => [
'title' => esc_html__( 'Cherry', 'wpforms-pdf' ),
'colors' => [
'accent' => '#8C2F39',
'complementary' => '#B23A48',
'primary' => '#461220',
'secondary' => '#8C2F39',
'tertiary' => '#B23A48',
'border' => '#FCB9B2',
'background_light' => '#ffe7dd',
'background' => '#ffffff',
],
],
'rose' => [
'title' => esc_html__( 'Rose', 'wpforms-pdf' ),
'colors' => [
'accent' => '#E11D48',
'complementary' => '#FB7185',
'primary' => '#44403C',
'secondary' => '#78716C',
'tertiary' => '#A8A29F',
'border' => '#E7E5E4',
'background_light' => '#F5F5F4',
'background' => '#ffffff',
],
],
'berry' => [
'title' => esc_html__( 'Berry', 'wpforms-pdf' ),
'colors' => [
'accent' => '#DA4167',
'complementary' => '#3D2645',
'primary' => 'black',
'secondary' => '#3D2645',
'tertiary' => '#832161',
'border' => '#D8D7DF',
'background_light' => '#f7f7f9',
'background' => '#ffffff',
],
],
'orchid' => [
'title' => esc_html__( 'Orchid', 'wpforms-pdf' ),
'colors' => [
'accent' => '#89023E',
'complementary' => '#EA638C',
'primary' => '#1B2021',
'secondary' => '#30343F',
'tertiary' => '#95979E',
'border' => '#FFD9DA',
'background_light' => '#fef5f5',
'background' => '#ffffff',
],
],
'watermelon' => [
'title' => esc_html__( 'Watermelon', 'wpforms-pdf' ),
'colors' => [
'accent' => '#BC4749',
'complementary' => '#A7C957',
'primary' => '#386641',
'secondary' => '#6A994E',
'tertiary' => '#A7C957',
'border' => '#F2E8CF',
'background_light' => '#fbf9f2',
'background' => '#ffffff',
],
],
'coral' => [
'title' => esc_html__( 'Coral', 'wpforms-pdf' ),
'colors' => [
'accent' => '#EE6C4D',
'complementary' => '#98C1D9',
'primary' => '#293241',
'secondary' => '#3D5A80',
'tertiary' => '#98C1D9',
'border' => '#CBDFEB',
'background_light' => '#f1f6f9',
'background' => '#ffffff',
],
],
'rust' => [
'title' => esc_html__( 'Rust', 'wpforms-pdf' ),
'colors' => [
'accent' => '#92400F',
'complementary' => '#D97707',
'primary' => '#44403C',
'secondary' => '#78716C',
'tertiary' => '#A8A29F',
'border' => '#E7E5E4',
'background_light' => '#F5F5F4',
'background' => '#ffffff',
],
],
'amber' => [
'title' => esc_html__( 'Amber', 'wpforms-pdf' ),
'colors' => [
'accent' => '#FF7B00',
'complementary' => '#FFA200',
'primary' => '#202020',
'secondary' => '#333533',
'tertiary' => '#999999',
'border' => '#D6D6D6',
'background_light' => '#fff8f2',
'background' => '#ffffff',
],
],
'citrus' => [
'title' => esc_html__( 'Citrus', 'wpforms-pdf' ),
'colors' => [
'accent' => '#FB8500',
'complementary' => '#FFB705',
'primary' => '#023047',
'secondary' => '#239EBC',
'tertiary' => '#8FCAE6',
'border' => '#E5E5E5',
'background_light' => '#fff9f2',
'background' => '#ffffff',
],
],
'fusion' => [
'title' => esc_html__( 'Fusion', 'wpforms-pdf' ),
'colors' => [
'accent' => '#FF7900',
'complementary' => '#3C096C',
'primary' => '#240046',
'secondary' => '#3C096C',
'tertiary' => '#9D4EDD',
'border' => '#E0AAFF',
'background_light' => '#fdf9ff',
'background' => '#ffffff',
],
],
'vintage' => [
'title' => esc_html__( 'Vintage', 'wpforms-pdf' ),
'colors' => [
'accent' => '#CA8A03',
'complementary' => '#713F11',
'primary' => '#44403C',
'secondary' => '#78716C',
'tertiary' => '#A8A29F',
'border' => '#E7E5E4',
'background_light' => '#F5F5F4',
'background' => '#ffffff',
],
],
'dijon' => [
'title' => esc_html__( 'Dijon', 'wpforms-pdf' ),
'colors' => [
'accent' => '#DE9E36',
'complementary' => '#DEB841',
'primary' => '#37323E',
'secondary' => '#6D6A75',
'tertiary' => '#BFBDC1',
'border' => '#DDDDDF',
'background_light' => '#fdfaf5',
'background' => '#ffffff',
],
],
'spruce' => [
'title' => esc_html__( 'Spruce', 'wpforms-pdf' ),
'colors' => [
'accent' => '#3F4238',
'complementary' => '#A5A58D',
'primary' => '#3F4238',
'secondary' => '#6B705C',
'tertiary' => '#A5A58D',
'border' => '#D9D9D0',
'background_light' => '#f1f1ed',
'background' => '#ffffff',
],
],
'meadow' => [
'title' => esc_html__( 'Meadow', 'wpforms-pdf' ),
'colors' => [
'accent' => '#718355',
'complementary' => '#97A97C',
'primary' => '#718355',
'secondary' => '#87986A',
'tertiary' => '#97A97C',
'border' => '#CFE1B9',
'background_light' => '#f9fdf6',
'background' => '#ffffff',
],
],
'fern' => [
'title' => esc_html__( 'Fern', 'wpforms-pdf' ),
'colors' => [
'accent' => '#606C38',
'complementary' => '#D4A373',
'primary' => '#283618',
'secondary' => '#606C38',
'tertiary' => '#BC6C25',
'border' => '#FAEDCD',
'background_light' => '#f7f8f5',
'background' => '#ffffff',
],
],
'forest' => [
'title' => esc_html__( 'Forest', 'wpforms-pdf' ),
'colors' => [
'accent' => '#3A5A40',
'complementary' => '#588157',
'primary' => '#344E41',
'secondary' => '#3A5A40',
'tertiary' => '#588157',
'border' => '#DAD7CD',
'background_light' => '#f7f9f7',
'background' => '#ffffff',
],
],
'emerald' => [
'title' => esc_html__( 'Emerald', 'wpforms-pdf' ),
'colors' => [
'accent' => '#2D6A4F',
'complementary' => '#40916C',
'primary' => '#1B4332',
'secondary' => '#2D6A4F',
'tertiary' => '#40916C',
'border' => '#74C69D',
'background_light' => '#f5fcf6',
'background' => '#ffffff',
],
],
'ocean' => [
'title' => esc_html__( 'Ocean', 'wpforms-pdf' ),
'colors' => [
'accent' => '#0E9488',
'complementary' => '#0F7490',
'primary' => '#374151',
'secondary' => '#4B5563',
'tertiary' => '#6B7280',
'border' => '#E5E7EB',
'background_light' => '#F3F4F6',
'background' => '#ffffff',
],
],
'seanfoam' => [
'title' => esc_html__( 'Seanfoam', 'wpforms-pdf' ),
'colors' => [
'accent' => '#093E48',
'complementary' => '#5E8C61',
'primary' => '#093E48',
'secondary' => '#054740',
'tertiary' => '#5E8C61',
'border' => '#AEC5B0',
'background_light' => '#fbfff5',
'background' => '#ffffff',
],
],
'lagoon' => [
'title' => esc_html__( 'Lagoon', 'wpforms-pdf' ),
'colors' => [
'accent' => '#2A9D8F',
'complementary' => '#F4A261',
'primary' => '#264653',
'secondary' => '#5B737D',
'tertiary' => '#AAB6BB',
'border' => '#E9C46A',
'background_light' => '#f4faf9',
'background' => '#ffffff',
],
],
'arctic' => [
'title' => esc_html__( 'Arctic', 'wpforms-pdf' ),
'colors' => [
'accent' => '#62B6CB',
'complementary' => '#BEE9E8',
'primary' => '#002855',
'secondary' => '#5FA8D3',
'tertiary' => '#62B6CB',
'border' => '#E3F4FD',
'background_light' => '#f3fbfe',
'background' => '#ffffff',
],
],
'cascade' => [
'title' => esc_html__( 'Cascade', 'wpforms-pdf' ),
'colors' => [
'accent' => '#1985A1',
'complementary' => '#4C5C68',
'primary' => '#46494C',
'secondary' => '#4C5C68',
'tertiary' => '#C5C3C6',
'border' => '#DCDCDD',
'background_light' => '#ECECED',
'background' => '#ffffff',
],
],
'slate' => [
'title' => esc_html__( 'Slate', 'wpforms-pdf' ),
'colors' => [
'accent' => '#124559',
'complementary' => '#598392',
'primary' => '#01161E',
'secondary' => '#124559',
'tertiary' => '#598392',
'border' => '#AEC3B0',
'background_light' => '#f3f6f7',
'background' => '#ffffff',
],
],
'driftwood' => [
'title' => esc_html__( 'Driftwood', 'wpforms-pdf' ),
'colors' => [
'accent' => '#22333B',
'complementary' => '#5E503F',
'primary' => '#0A0908',
'secondary' => '#22333B',
'tertiary' => '#5E503F',
'border' => '#C6AC8F',
'background_light' => '#f5efea',
'background' => '#ffffff',
],
],
'midnight' => [
'title' => esc_html__( 'Midnight', 'wpforms-pdf' ),
'colors' => [
'accent' => '#1B263B',
'complementary' => '#415A77',
'primary' => '#0D1B2A',
'secondary' => '#1B263B',
'tertiary' => '#415A77',
'border' => '#778DA9',
'background_light' => '#eff0ee',
'background' => '#ffffff',
],
],
'cobalt' => [
'title' => esc_html__( 'Cobalt', 'wpforms-pdf' ),
'colors' => [
'accent' => '#013A63',
'complementary' => '#2A6F97',
'primary' => '#012A4A',
'secondary' => '#013A63',
'tertiary' => '#2A6F97',
'border' => '#A9D6E5',
'background_light' => '#e9f4f8',
'background' => '#ffffff',
],
],
'azure' => [
'title' => esc_html__( 'Azure', 'wpforms-pdf' ),
'colors' => [
'accent' => '#0353A4',
'complementary' => '#0466C8',
'primary' => '#002855',
'secondary' => '#023E7D',
'tertiary' => '#5C677D',
'border' => '#979DAC',
'background_light' => '#f2f6fa',
'background' => '#ffffff',
],
],
'sunflower' => [
'title' => esc_html__( 'Sunflower', 'wpforms-pdf' ),
'colors' => [
'accent' => '#00509D',
'complementary' => '#FDC500',
'primary' => '#001D4C',
'secondary' => '#00296B',
'tertiary' => '#00509D',
'border' => '#FDF3BF',
'background_light' => '#fefbee',
'background' => '#ffffff',
],
],
'lavender' => [
'title' => esc_html__( 'Lavender', 'wpforms-pdf' ),
'colors' => [
'accent' => '#613DC1',
'complementary' => '#97DFFC',
'primary' => '#2C0735',
'secondary' => '#571089',
'tertiary' => '#613DC1',
'border' => '#E0AAFF',
'background_light' => '#fbf4ff',
'background' => '#ffffff',
],
],
'amethyst' => [
'title' => esc_html__( 'Amethyst', 'wpforms-pdf' ),
'colors' => [
'accent' => '#D55D92',
'complementary' => '#822FAF',
'primary' => '#47126B',
'secondary' => '#571089',
'tertiary' => '#822FAF',
'border' => '#E0AAFF',
'background_light' => '#fbf4ff',
'background' => '#ffffff',
],
],
'lilac' => [
'title' => esc_html__( 'Lilac', 'wpforms-pdf' ),
'colors' => [
'accent' => '#706677',
'complementary' => '#A6808C',
'primary' => '#565264',
'secondary' => '#706677',
'tertiary' => '#A6808C',
'border' => '#D6CFCB',
'background_light' => '#f1f0f1',
'background' => '#ffffff',
],
],
'espresso' => [
'title' => esc_html__( 'Espresso', 'wpforms-pdf' ),
'colors' => [
'accent' => '#9C6644',
'complementary' => '#B08968',
'primary' => '#7F5539',
'secondary' => '#9C6644',
'tertiary' => '#B08968',
'border' => '#DDB892',
'background_light' => '#fbf7f4',
'background' => '#ffffff',
],
],
'steel' => [
'title' => esc_html__( 'Steel', 'wpforms-pdf' ),
'colors' => [
'accent' => '#343A40',
'complementary' => '#6C757D',
'primary' => '#212529',
'secondary' => '#495057',
'tertiary' => '#6C757D',
'border' => '#CED4DA',
'background_light' => '#f4f5f7',
'background' => '#ffffff',
],
],
'sandstone' => [
'title' => esc_html__( 'Sandstone', 'wpforms-pdf' ),
'colors' => [
'accent' => '#343A40',
'complementary' => '#495057',
'primary' => '#212529',
'secondary' => '#343A40',
'tertiary' => '#495057',
'border' => '#CED4DA',
'background_light' => '#f4f5f7',
'background' => '#ffffff',
],
],
'obsidian' => [
'title' => esc_html__( 'Obsidian', 'wpforms-pdf' ),
'colors' => [
'accent' => '#222222',
'complementary' => '#444444',
'primary' => '#222222',
'secondary' => '#444444',
'tertiary' => '#888888',
'border' => '#DDDDDD',
'background_light' => '#f6f6f6',
'background' => '#ffffff',
],
],
];
$email_defaults = wpforms_pdf()->form_builder->get_defaults()['appearance'];
// Update the default theme with colors from global Email Notification settings.
$themes[ self::DEFAULT_THEME ]['emailAppearance'] = [
'page_background_color' => $email_defaults['page_background_color'],
'container_background_color' => $email_defaults['container_background_color'],
'text_color' => $email_defaults['text_color'],
'link_color' => $email_defaults['link_color'],
];
/**
* Filters PDF templates themes data.
*
* @since 1.0.0
*
* @param array $themes Themes data.
*/
$this->themes = (array) apply_filters( 'wpforms_pdf_templates_themes_get_themes', $themes );
return $this->themes;
}
/**
* Get custom themes file path.
*
* @since 1.0.0
*
* @return string
*/
private function get_custom_themes_file(): string {
return Storage::get_dir() . '/' . self::CUSTOM_THEMES_FILE;
}
/**
* Return custom themes.
*
* @since 1.0.0
*
* @return array
*/
public function get_custom_themes(): array {
if ( $this->custom_themes !== null ) {
return $this->custom_themes;
}
$file_path = $this->get_custom_themes_file();
$themes_json = File::get_contents( $file_path ) ?? '{}';
$themes = json_decode( $themes_json, true );
$this->custom_themes = ! empty( $themes ) ? $themes : [];
return $this->custom_themes;
}
/**
* Update custom theme data.
*
* @since 1.0.0
*
* @param array $theme_data Custom theme data.
*
* @return bool
*/
public function update_custom_theme( array $theme_data ): bool {
$theme_slug = $theme_data['slug'] ?? '';
if ( empty( $theme_slug ) ) {
return false;
}
$custom_themes = $this->get_custom_themes();
// Update custom theme data.
$custom_themes[ $theme_slug ] = $theme_data;
return $this->update_custom_themes( $custom_themes );
}
/**
* Delete custom theme.
*
* @since 1.0.0
*
* @param array $theme_data Custom theme data. Should contain 'slug' key.
*
* @return bool
*/
public function delete_custom_theme( array $theme_data ): bool {
$theme_slug = $theme_data['slug'] ?? '';
if ( empty( $theme_slug ) ) {
return false;
}
$custom_themes = $this->get_custom_themes();
// Update custom theme data.
unset( $custom_themes[ $theme_slug ] );
return $this->update_custom_themes( $custom_themes );
}
/**
* Update custom themes data.
*
* @since 1.8.8
*
* @param array $custom_themes Custom themes data.
*
* @return bool
*/
private function update_custom_themes( array $custom_themes ): bool {
$this->custom_themes = $custom_themes;
// Encode custom themes data to JSON.
$json_data = ! empty( $custom_themes ) ? wp_json_encode( $custom_themes ) : '{}';
$file_path = $this->get_custom_themes_file();
// Save custom themes data and return the result.
return File::put_contents( $file_path, $json_data );
}
}