| @@ -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 | /** |
| @@ -41,20 +38,44 @@ | ||
| 41 | 38 | * @param array $keys |
| 42 | 39 | */ |
| 43 | 40 | self::$keys = apply_filters( |
| 44 | 41 | 'frm_application_data_keys', |
| 45 | - array( 'key', 'name', 'description', 'link', 'categories', 'views', 'forms' ) | |
| 42 | + array( 'key', 'name', 'description', 'link', 'categories', 'views', 'forms', 'used_addons' ) | |
| 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,13 +81,36 @@ | ||
| 60 | 81 | 'restaurant-menu', |
| 61 | 82 | 'team-directory', |
| 62 | 83 | 'product-review', |
| 63 | 84 | 'real-estate-listings', |
| 85 | + 'business-directory', | |
| 86 | + 'artist-gallery', | |
| 87 | + 'classifieds', | |
| 88 | + 'community-event-calendar', | |
| 89 | + 'company-timeline', | |
| 90 | + 'crowdfunding', | |
| 91 | + 'job-board', | |
| 92 | + 'logo-cloud', | |
| 93 | + 'multi-property-booking-system', | |
| 94 | + 'wedding-venue-booking', | |
| 95 | + 'permission-slip', | |
| 96 | + 'property-directory', | |
| 97 | + 'radio-station', | |
| 98 | + 'recipe', | |
| 99 | + 'rsvp-invite', | |
| 100 | + 'searchable-directory', | |
| 101 | + 'shopping-cart', | |
| 102 | + 'sports-league-calendar', | |
| 103 | + 'staff-directory', | |
| 104 | + 'tiered-pricing', | |
| 105 | + 'trip-itinerary', | |
| 106 | + 'twitterx', | |
| 64 | 107 | ); |
| 65 | 108 | } |
| 66 | 109 | |
| 67 | 110 | /** |
| 68 | 111 | * @param array $api_data |
| 112 | + * | |
| 69 | 113 | * @return void |
| 70 | 114 | */ |
| 71 | 115 | public function __construct( $api_data ) { |
| 72 | 116 | $this->api_data = $api_data; |
| @@ -77,8 +121,9 @@ | ||
| 77 | 121 | } |
| 78 | 122 | |
| 79 | 123 | /** |
| 80 | 124 | * @param array<string> $categories |
| 125 | + * | |
| 81 | 126 | * @return void |
| 82 | 127 | */ |
| 83 | 128 | private static function populate_category_information( $categories ) { |
| 84 | 129 | foreach ( $categories as $category ) { |
| @@ -84,8 +129,9 @@ | ||
| 84 | 129 | foreach ( $categories as $category ) { |
| 85 | 130 | if ( self::category_matches_a_license_type( $category ) ) { |
| 86 | 131 | continue; |
| 87 | 132 | } |
| 133 | + | |
| 88 | 134 | if ( in_array( $category, self::$categories, true ) ) { |
| 89 | 135 | continue; |
| 90 | 136 | } |
| 91 | 137 | self::$categories[] = $category; |
| @@ -95,15 +141,16 @@ | ||
| 95 | 141 | /** |
| 96 | 142 | * @since 5.5.2 |
| 97 | 143 | * |
| 98 | 144 | * @param string $category |
| 145 | + * | |
| 99 | 146 | * @return bool |
| 100 | 147 | */ |
| 101 | 148 | private static function category_matches_a_license_type( $category ) { |
| 102 | - if ( false !== strpos( $category, '+Views' ) ) { | |
| 149 | + if ( str_contains( $category, '+Views' ) ) { | |
| 103 | 150 | return true; |
| 104 | 151 | } |
| 105 | - return in_array( $category, FrmFormsHelper::ignore_template_categories(), true ); | |
| 152 | + return in_array( $category, FrmFormsHelper::get_license_types(), true ); | |
| 106 | 153 | } |
| 107 | 154 | |
| 108 | 155 | /** |
| 109 | 156 | * @return array<string> |
| @@ -108,9 +155,9 @@ | ||
| 108 | 155 | /** |
| 109 | 156 | * @return array<string> |
| 110 | 157 | */ |
| 111 | 158 | public static function get_categories() { |
| 112 | - return isset( self::$categories ) ? self::$categories : array(); | |
| 159 | + return self::$categories ?? array(); | |
| 113 | 160 | } |
| 114 | 161 | |
| 115 | 162 | /** |
| 116 | 163 | * @return array |
| @@ -115,9 +162,14 @@ | ||
| 115 | 162 | /** |
| 116 | 163 | * @return array |
| 117 | 164 | */ |
| 118 | 165 | public function as_js_object() { |
| 166 | + if ( ! is_array( self::$keys ) ) { | |
| 167 | + return array(); | |
| 168 | + } | |
| 169 | + | |
| 119 | 170 | $application = array(); |
| 171 | + | |
| 120 | 172 | foreach ( self::$keys as $key ) { |
| 121 | 173 | if ( ! isset( $this->api_data[ $key ] ) ) { |
| 122 | 174 | continue; |
| 123 | 175 | } |
| @@ -130,10 +182,10 @@ | ||
| 130 | 182 | } elseif ( 'categories' === $key ) { |
| 131 | 183 | $application[ $key ] = array_values( |
| 132 | 184 | array_filter( |
| 133 | 185 | $value, |
| 134 | - function( $category ) { | |
| 135 | - return false === strpos( $category, '+Views' ); | |
| 186 | + function ( $category ) { | |
| 187 | + return ! str_contains( $category, '+Views' ); | |
| 136 | 188 | } |
| 137 | 189 | ) |
| 138 | 190 | ); |
| 139 | 191 | } else { |
| @@ -142,30 +194,48 @@ | ||
| 142 | 194 | } elseif ( 'forms' === $key ) { |
| 143 | 195 | $key = 'formCount'; |
| 144 | 196 | } |
| 145 | 197 | |
| 146 | - if ( 'name' === $key && ' Template' === substr( $value, -9 ) ) { | |
| 198 | + if ( 'name' === $key && str_ends_with( $value, ' Template' ) ) { | |
| 147 | 199 | // Strip off the " Template" text at the end of the name as it takes up space. |
| 148 | 200 | $value = substr( $value, 0, -9 ); |
| 149 | 201 | } |
| 202 | + | |
| 150 | 203 | $application[ $key ] = $value; |
| 151 | - } | |
| 152 | - } | |
| 204 | + }//end if | |
| 205 | + }//end foreach | |
| 153 | 206 | |
| 154 | 207 | $application['hasLiteThumbnail'] = in_array( $application['key'], self::$keys_with_images, true ); |
| 208 | + $application['isWebp'] = in_array( $application['key'], self::get_template_keys_with_local_webp_images(), true ); | |
| 155 | 209 | |
| 156 | 210 | if ( ! array_key_exists( 'url', $application ) ) { |
| 211 | + $application['requires'] = FrmFormsHelper::get_plan_required( $application ); | |
| 212 | + | |
| 213 | + if ( false === $application['requires'] ) { | |
| 214 | + // Application is invalid if the URL is unavailable and there is no plan required. | |
| 215 | + return array(); | |
| 216 | + } | |
| 217 | + | |
| 157 | 218 | $purchase_url = $this->is_available_for_purchase(); |
| 219 | + | |
| 158 | 220 | if ( false !== $purchase_url ) { |
| 159 | 221 | $application['forPurchase'] = true; |
| 160 | 222 | } |
| 223 | + | |
| 161 | 224 | $application['upgradeUrl'] = $this->get_admin_upgrade_link(); |
| 162 | - $application['requires'] = FrmFormsHelper::get_plan_required( $application ); | |
| 163 | 225 | $application['link'] = $application['upgradeUrl']; |
| 164 | 226 | } |
| 165 | 227 | |
| 166 | 228 | $application['isNew'] = $this->is_new(); |
| 167 | 229 | |
| 230 | + $application['usedAddons'] = array(); | |
| 231 | + | |
| 232 | + if ( isset( $application['used_addons'] ) ) { | |
| 233 | + // Change key to camel case. | |
| 234 | + $application['usedAddons'] = $application['used_addons']; | |
| 235 | + unset( $application['used_addons'] ); | |
| 236 | + } | |
| 237 | + | |
| 168 | 238 | return $application; |
| 169 | 239 | } |
| 170 | 240 | |
| 171 | 241 | /** |
| @@ -184,8 +254,9 @@ | ||
| 184 | 254 | return false; |
| 185 | 255 | } |
| 186 | 256 | |
| 187 | 257 | $pro = $addons[93790]; |
| 258 | + | |
| 188 | 259 | if ( ! array_key_exists( 'type', $pro ) ) { |
| 189 | 260 | return false; |
| 190 | 261 | } |
| 191 | 262 | |
| @@ -193,13 +264,9 @@ | ||
| 193 | 264 | $args = array( |
| 194 | 265 | 'license_type' => $license_type, |
| 195 | 266 | 'plan_required' => $this->get_required_license(), |
| 196 | 267 | ); |
| 197 | - if ( ! FrmFormsHelper::plan_is_allowed( $args ) ) { | |
| 198 | - return false; | |
| 199 | - } | |
| 200 | - | |
| 201 | - return true; | |
| 268 | + return FrmFormsHelper::plan_is_allowed( $args ); | |
| 202 | 269 | } |
| 203 | 270 | |
| 204 | 271 | /** |
| 205 | 272 | * Check if an application template is new. If it is, we include a "NEW" pill beside the title. |
| @@ -216,12 +283,9 @@ | ||
| 216 | 283 | * @return string |
| 217 | 284 | */ |
| 218 | 285 | private function get_required_license() { |
| 219 | 286 | $required_license = strtolower( $this->api_data['min_plan'] ); |
| 220 | - if ( 'plus' === $required_license ) { | |
| 221 | - $required_license = 'personal'; | |
| 222 | - } | |
| 223 | - return $required_license; | |
| 287 | + return 'plus' === $required_license ? 'personal' : $required_license; | |
| 224 | 288 | } |
| 225 | 289 | |
| 226 | 290 | /** |
| 227 | 291 | * @return string |
| @@ -231,8 +295,8 @@ | ||
| 231 | 295 | array( |
| 232 | 296 | 'content' => 'upgrade', |
| 233 | 297 | 'medium' => 'applications', |
| 234 | 298 | ), |
| 235 | - '/view-templates/' . $this->api_data['slug'] | |
| 299 | + 'view-templates/' . $this->api_data['slug'] | |
| 236 | 300 | ); |
| 237 | 301 | } |
| 238 | 302 | } |