CustomFonts.php
3 years ago
Export.php
2 months ago
FieldNameObfuscator.php
3 years ago
Styles.php
3 years ago
index.php
3 years ago
CustomFonts.php
130 lines
| 1 | <?php // phpcs:ignore SlevomatCodingStandard.TypeHints.DeclareStrictTypes.DeclareStrictTypesMissing |
| 2 | |
| 3 | namespace MailPoet\Form\Util; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Settings\SettingsController; |
| 9 | use MailPoet\WP\Functions; |
| 10 | |
| 11 | class CustomFonts { |
| 12 | const FONT_CHUNK_SIZE = 25; |
| 13 | const FONTS = [ |
| 14 | 'Abril FatFace', |
| 15 | 'Alegreya', |
| 16 | 'Alegreya Sans', |
| 17 | 'Amatic SC', |
| 18 | 'Anonymous Pro', |
| 19 | 'Architects Daughter', |
| 20 | 'Archivo', |
| 21 | 'Archivo Narrow', |
| 22 | 'Asap', |
| 23 | 'Barlow', |
| 24 | 'BioRhyme', |
| 25 | 'Bonbon', |
| 26 | 'Cabin', |
| 27 | 'Cairo', |
| 28 | 'Cardo', |
| 29 | 'Chivo', |
| 30 | 'Concert One', |
| 31 | 'Cormorant', |
| 32 | 'Crimson Text', |
| 33 | 'Eczar', |
| 34 | 'Exo 2', |
| 35 | 'Fira Sans', |
| 36 | 'Fjalla One', |
| 37 | 'Frank Ruhl Libre', |
| 38 | 'Great Vibes', |
| 39 | 'Heebo', |
| 40 | 'IBM Plex', |
| 41 | 'Inconsolata', |
| 42 | 'Indie Flower', |
| 43 | 'Inknut Antiqua', |
| 44 | 'Inter', |
| 45 | 'Karla', |
| 46 | 'Libre Baskerville', |
| 47 | 'Libre Franklin', |
| 48 | 'Montserrat', |
| 49 | 'Neuton', |
| 50 | 'Notable', |
| 51 | 'Nothing You Could Do', |
| 52 | 'Noto Sans', |
| 53 | 'Nunito', |
| 54 | 'Old Standard TT', |
| 55 | 'Oxygen', |
| 56 | 'Pacifico', |
| 57 | 'Poppins', |
| 58 | 'Proza Libre', |
| 59 | 'PT Sans', |
| 60 | 'PT Serif', |
| 61 | 'Rakkas', |
| 62 | 'Reenie Beanie', |
| 63 | 'Roboto Slab', |
| 64 | 'Ropa Sans', |
| 65 | 'Rubik', |
| 66 | 'Shadows Into Light', |
| 67 | 'Space Mono', |
| 68 | 'Spectral', |
| 69 | 'Sue Ellen Francisco', |
| 70 | 'Titillium Web', |
| 71 | 'Ubuntu', |
| 72 | 'Varela', |
| 73 | 'Vollkorn', |
| 74 | 'Work Sans', |
| 75 | 'Yatra One', |
| 76 | ]; |
| 77 | |
| 78 | /** @var Functions */ |
| 79 | private $wp; |
| 80 | |
| 81 | /** @var SettingsController */ |
| 82 | private $settings; |
| 83 | |
| 84 | public function __construct( |
| 85 | Functions $wp, |
| 86 | SettingsController $settings |
| 87 | ) { |
| 88 | $this->wp = $wp; |
| 89 | $this->settings = $settings; |
| 90 | } |
| 91 | |
| 92 | public function displayCustomFonts(): bool { |
| 93 | $display = $this->wp->applyFilters('mailpoet_display_custom_fonts', $this->settings->get('3rd_party_libs.enabled') === '1'); |
| 94 | return (bool)$display; |
| 95 | } |
| 96 | |
| 97 | public function enqueueStyle() { |
| 98 | if (!$this->displayCustomFonts()) { |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | // Due to a conflict with the WooCommerce Payments plugin, we need to load custom fonts in more requests. |
| 103 | // When we load all custom fonts in one request, a form from WC Payments isn't displayed correctly. |
| 104 | // It looks that the larger file size overloads the Stripe SDK. |
| 105 | foreach (array_chunk(self::FONTS, self::FONT_CHUNK_SIZE) as $key => $fonts) { |
| 106 | $this->wp->wpEnqueueStyle('mailpoet_custom_fonts_' . $key, $this->generateLink($fonts)); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | public function generateHtmlCustomFontLink(): string { |
| 111 | if (!$this->displayCustomFonts()) { |
| 112 | return ''; |
| 113 | } |
| 114 | |
| 115 | $output = ''; |
| 116 | foreach (array_chunk(self::FONTS, self::FONT_CHUNK_SIZE) as $key => $fonts) { |
| 117 | $output .= sprintf('<link href="%s" rel="stylesheet">', $this->generateLink($fonts)); |
| 118 | } |
| 119 | return $output; |
| 120 | } |
| 121 | |
| 122 | private function generateLink(array $fonts): string { |
| 123 | $fonts = array_map(function ($fontName) { |
| 124 | return urlencode($fontName) . ':400,400i,700,700i'; |
| 125 | }, $fonts); |
| 126 | $fonts = implode('|', $fonts); |
| 127 | return 'https://fonts.googleapis.com/css?family=' . $fonts; |
| 128 | } |
| 129 | } |
| 130 |