IntegrationCatalog.php
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Models; |
| 4 | |
| 5 | /** |
| 6 | * The integration listing model. |
| 7 | */ |
| 8 | class IntegrationCatalog extends ExternalApiModel { |
| 9 | /** |
| 10 | * Rest API endpoint |
| 11 | * |
| 12 | * @var string |
| 13 | */ |
| 14 | protected $endpoint = 'v1'; |
| 15 | |
| 16 | /** |
| 17 | * Default query parameters |
| 18 | * |
| 19 | * @var array |
| 20 | */ |
| 21 | protected $default_query = [ |
| 22 | '_embed' => true, |
| 23 | '_fields' => 'id,slug,title,content,_links.wp:featuredmedia,_embedded.wp:featuredmedia,_links.wp:term,_embedded.wp:term,acf', |
| 24 | 'acf_format' => 'standard', |
| 25 | 'per_page' => 100, |
| 26 | ]; |
| 27 | |
| 28 | /** |
| 29 | * Base URL |
| 30 | * |
| 31 | * @var string |
| 32 | */ |
| 33 | protected $base_url = 'https://integrations-catalog.surecart.com/'; |
| 34 | |
| 35 | /** |
| 36 | * Get the is plugin active attribute. |
| 37 | * |
| 38 | * @return bool |
| 39 | */ |
| 40 | public function getIsPluginActiveAttribute() { |
| 41 | if ( 'pie-calendar' === $this->slug ) { // Since Pie Calendar Free & Pro plugin had same plugin file name we need to check if the pro plugin is active explicitly. |
| 42 | return $this->isPieCalendarProPluginActive(); |
| 43 | } |
| 44 | |
| 45 | if ( empty( $this->acf['plugin_file'] ) ) { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | return is_plugin_active( $this->acf['plugin_file'] ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Get the is plugin active attribute. |
| 54 | * |
| 55 | * @return bool |
| 56 | */ |
| 57 | public function getIsThemeActiveAttribute() { |
| 58 | if ( empty( $this->acf['theme_slug'] ) ) { |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | return wp_get_theme()->get_template() === $this->acf['theme_slug']; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Get the is enabled attribute. |
| 67 | * |
| 68 | * @return bool |
| 69 | */ |
| 70 | public function getIsEnabledAttribute() { |
| 71 | if ( $this->getIsThemeActiveAttribute() ) { |
| 72 | return true; |
| 73 | } |
| 74 | if ( $this->getIsPluginActiveAttribute() ) { |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Get the logo URL. |
| 83 | * |
| 84 | * @return string |
| 85 | */ |
| 86 | public function getLogoUrlAttribute() { |
| 87 | // svg first. |
| 88 | if ( file_exists( SURECART_PLUGIN_DIR . '/images/integrations/' . $this->slug . '.svg' ) ) { |
| 89 | return untrailingslashit( \SureCart::core()->assets()->getUrl() ) . '/images/integrations/' . $this->slug . '.svg'; |
| 90 | } |
| 91 | |
| 92 | // then png. |
| 93 | if ( file_exists( SURECART_PLUGIN_DIR . '/images/integrations/' . $this->slug . '.png' ) ) { |
| 94 | return untrailingslashit( \SureCart::core()->assets()->getUrl() ) . '/images/integrations/' . $this->slug . '.png'; |
| 95 | } |
| 96 | |
| 97 | // then fallback to the featured media. |
| 98 | return $this->_embedded['wp:featuredmedia'][0]['media_details']['sizes']['medium']['source_url'] ?? $this->_embedded['wp:featuredmedia'][0]['source_url'] ?? ''; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Is Pie Calendar Pro plugin active. |
| 103 | * |
| 104 | * @return bool |
| 105 | */ |
| 106 | public function isPieCalendarProPluginActive() { |
| 107 | if ( ! function_exists( 'piecal_pro_classic_metabox' ) ) { |
| 108 | return false; |
| 109 | } |
| 110 | |
| 111 | return true; |
| 112 | } |
| 113 | } |
| 114 |