| @@ -8,31 +8,28 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | class FrmApplicationTemplate { |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * @var array<string>|null $keys | |
| 12 | + * @var array<string>|null | |
| 13 | 13 | */ |
| 14 | 14 | private static $keys; |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | - * @var array<string>|null $keys_with_images | |
| 17 | + * @var array<string>|null | |
| 18 | 18 | */ |
| 19 | 19 | private static $keys_with_images; |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | - * @var array<string>|null $categories | |
| 22 | + * @var array<string>|null | |
| 23 | 23 | */ |
| 24 | 24 | private static $categories; |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * @var array $api_data | |
| 27 | + * @var array | |
| 28 | 28 | */ |
| 29 | 29 | private $api_data; |
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | - * @param array<string> $keys | |
| 33 | - * @param array<string> $keys_with_images | |
| 34 | - * | |
| 35 | 32 | * @return void |
| 36 | 33 | */ |
| 37 | 34 | public static function init() { |
| 38 | 35 | /** |
| @@ -43,18 +40,42 @@ | ||
| 43 | 40 | self::$keys = apply_filters( |
| 44 | 41 | 'frm_application_data_keys', |
| 45 | 42 | array( 'key', 'name', 'description', 'link', 'categories', 'views', 'forms' ) |
| 46 | 43 | ); |
| 47 | - self::$keys_with_images = self::get_template_keys_with_local_images(); | |
| 44 | + self::$keys_with_images = array_merge( | |
| 45 | + self::get_template_keys_with_local_png_images(), | |
| 46 | + self::get_template_keys_with_local_webp_images() | |
| 47 | + ); | |
| 48 | 48 | self::$categories = array(); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | + * Newer templates now use .webp files instead of .png. | |
| 53 | + * | |
| 54 | + * @since 6.16 | |
| 55 | + * | |
| 56 | + * @return array<string> | |
| 57 | + */ | |
| 58 | + private static function get_template_keys_with_local_webp_images() { | |
| 59 | + return array( | |
| 60 | + 'member-directory', | |
| 61 | + 'link-in-bio-instagram', | |
| 62 | + 'letter-of-recommendation', | |
| 63 | + 'invoice-pdf', | |
| 64 | + 'freelance-invoice-generator', | |
| 65 | + 'contract-agreement', | |
| 66 | + 'charity-tracker', | |
| 67 | + 'certificate', | |
| 68 | + 'testimonials', | |
| 69 | + ); | |
| 70 | + } | |
| 71 | + | |
| 72 | + /** | |
| 52 | 73 | * Return the template keys that have embedded images. Otherwise, we want to avoid trying to load the URL and use the placeholder instead. |
| 53 | 74 | * |
| 54 | 75 | * @return array<string> |
| 55 | 76 | */ |
| 56 | - private static function get_template_keys_with_local_images() { | |
| 77 | + private static function get_template_keys_with_local_png_images() { | |
| 57 | 78 | return array( |
| 58 | 79 | 'business-hours', |
| 59 | 80 | 'faq-template-wordpress', |
| 60 | 81 | 'restaurant-menu', |
| @@ -60,8 +81,9 @@ | ||
| 60 | 81 | 'restaurant-menu', |
| 61 | 82 | 'team-directory', |
| 62 | 83 | 'product-review', |
| 63 | 84 | 'real-estate-listings', |
| 85 | + 'business-directory', | |
| 64 | 86 | ); |
| 65 | 87 | } |
| 66 | 88 | |
| 67 | 89 | /** |
| @@ -101,9 +123,9 @@ | ||
| 101 | 123 | private static function category_matches_a_license_type( $category ) { |
| 102 | 124 | if ( false !== strpos( $category, '+Views' ) ) { |
| 103 | 125 | return true; |
| 104 | 126 | } |
| 105 | - return in_array( $category, FrmFormsHelper::ignore_template_categories(), true ); | |
| 127 | + return in_array( $category, FrmFormsHelper::get_license_types(), true ); | |
| 106 | 128 | } |
| 107 | 129 | |
| 108 | 130 | /** |
| 109 | 131 | * @return array<string> |
| @@ -115,8 +137,12 @@ | ||
| 115 | 137 | /** |
| 116 | 138 | * @return array |
| 117 | 139 | */ |
| 118 | 140 | public function as_js_object() { |
| 141 | + if ( ! is_array( self::$keys ) ) { | |
| 142 | + return array(); | |
| 143 | + } | |
| 144 | + | |
| 119 | 145 | $application = array(); |
| 120 | 146 | foreach ( self::$keys as $key ) { |
| 121 | 147 | if ( ! isset( $this->api_data[ $key ] ) ) { |
| 122 | 148 | continue; |
| @@ -130,9 +156,9 @@ | ||
| 130 | 156 | } elseif ( 'categories' === $key ) { |
| 131 | 157 | $application[ $key ] = array_values( |
| 132 | 158 | array_filter( |
| 133 | 159 | $value, |
| 134 | - function( $category ) { | |
| 160 | + function ( $category ) { | |
| 135 | 161 | return false === strpos( $category, '+Views' ); |
| 136 | 162 | } |
| 137 | 163 | ) |
| 138 | 164 | ); |
| @@ -147,12 +173,13 @@ | ||
| 147 | 173 | // Strip off the " Template" text at the end of the name as it takes up space. |
| 148 | 174 | $value = substr( $value, 0, -9 ); |
| 149 | 175 | } |
| 150 | 176 | $application[ $key ] = $value; |
| 151 | - } | |
| 152 | - } | |
| 177 | + }//end if | |
| 178 | + }//end foreach | |
| 153 | 179 | |
| 154 | 180 | $application['hasLiteThumbnail'] = in_array( $application['key'], self::$keys_with_images, true ); |
| 181 | + $application['isWebp'] = in_array( $application['key'], self::get_template_keys_with_local_webp_images(), true ); | |
| 155 | 182 | |
| 156 | 183 | if ( ! array_key_exists( 'url', $application ) ) { |
| 157 | 184 | $purchase_url = $this->is_available_for_purchase(); |
| 158 | 185 | if ( false !== $purchase_url ) { |
| @@ -231,8 +258,8 @@ | ||
| 231 | 258 | array( |
| 232 | 259 | 'content' => 'upgrade', |
| 233 | 260 | 'medium' => 'applications', |
| 234 | 261 | ), |
| 235 | - '/view-templates/' . $this->api_data['slug'] | |
| 262 | + 'view-templates/' . $this->api_data['slug'] | |
| 236 | 263 | ); |
| 237 | 264 | } |
| 238 | 265 | } |