Importers
2 months ago
Admin.php
1 week ago
Editor.php
1 year ago
Elementor.php
1 year ago
License.php
1 year ago
Logger.php
2 years ago
Main.php
1 week ago
Rest_Server.php
2 weeks ago
Sites_Listing.php
2 weeks ago
Starter_Ranking.php
1 week ago
TI_Beaver.php
1 year ago
WP_Cli.php
3 months ago
White_Label_Config.php
3 years ago
Sites_Listing.php
237 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Theme Onboarding Sites_Listing |
| 4 | * |
| 5 | * @package templates-patterns-collection |
| 6 | */ |
| 7 | |
| 8 | namespace TIOB; |
| 9 | |
| 10 | /** |
| 11 | * Class Sites_Listing |
| 12 | */ |
| 13 | class Sites_Listing { |
| 14 | |
| 15 | /** |
| 16 | * Sites Listing API URL |
| 17 | */ |
| 18 | const API = 'https://api.themeisle.com/sites/wp-json/demosites-api/sites'; |
| 19 | |
| 20 | /** |
| 21 | * Key of transient where we save the sites list. |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | private $transient_key = 'tiob_sites'; |
| 26 | |
| 27 | /** |
| 28 | * The onboarding config. |
| 29 | * |
| 30 | * @var array |
| 31 | */ |
| 32 | private $onboarding_config = array(); |
| 33 | |
| 34 | /** |
| 35 | * Initialize the Class. |
| 36 | */ |
| 37 | public function init() { |
| 38 | // Personalization is applied on the client via /starter_order. |
| 39 | $this->onboarding_config = array( |
| 40 | 'remote' => $this->get_sites(), |
| 41 | 'upsell' => array(), |
| 42 | 'can_migrate' => array( |
| 43 | 'zerif-pro' => array( |
| 44 | 'theme_name' => 'Zelle Pro', |
| 45 | 'theme_mod_check' => 'zelle_frontpage_was_imported', |
| 46 | 'template' => 'zelle', |
| 47 | 'heading' => __( 'Want to keep using Zelle\'s homepage?', 'templates-patterns-collection' ), |
| 48 | 'description' => __( 'Hi! We\'ve noticed you were using Zelle before. To make your transition easier, we can help you keep the same beautiful homepage you had before, by converting it into an Elementor template. This option will also import your homepage content.', 'templates-patterns-collection' ), |
| 49 | 'mandatory_plugins' => array( |
| 50 | 'elementor' => 'Elementor Page Builder', |
| 51 | ), |
| 52 | ), |
| 53 | 'zerif-lite' => array( |
| 54 | 'theme_name' => 'Zelle Lite', |
| 55 | 'theme_mod_check' => 'zelle_frontpage_was_imported', |
| 56 | 'template' => 'zelle', |
| 57 | 'heading' => __( 'Want to keep using Zelle\'s homepage?', 'templates-patterns-collection' ), |
| 58 | 'description' => __( 'Hi! We\'ve noticed you were using Zelle before. To make your transition easier, we can help you keep the same beautiful homepage you had before, by converting it into an Elementor template. This option will also import your homepage content.', 'templates-patterns-collection' ), |
| 59 | 'mandatory_plugins' => array( |
| 60 | 'elementor' => 'Elementor Page Builder', |
| 61 | ), |
| 62 | ), |
| 63 | ), |
| 64 | 'pro_link' => tsdk_translate_link( tsdk_utmify( 'https://themeisle.com/themes/neve/upgrade/', 'onboarding' ), 'query' ), |
| 65 | ); |
| 66 | $this->add_sites_library_support(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Return the API path |
| 71 | * |
| 72 | * @return string |
| 73 | */ |
| 74 | final public static function get_api_path() { |
| 75 | if ( defined( 'TPC_USE_STAGING' ) && TPC_USE_STAGING === true ) { |
| 76 | return ( ( defined( 'TPC_API_STAGING' ) && ! empty( TPC_API_STAGING ) ) ? TPC_API_STAGING : self::API ) . self::add_query_args(); |
| 77 | } |
| 78 | return self::API . self::add_query_args(); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * Allows adding $_GET arguments to API path. |
| 83 | * |
| 84 | * @return string |
| 85 | */ |
| 86 | private static function add_query_args() { |
| 87 | $query_args = array(); |
| 88 | $allowed_keys = array( |
| 89 | 'show-legacy-sites', |
| 90 | ); |
| 91 | // filter all keys that are not in $allowed_keys since the filter can provide third parties access to the URL. |
| 92 | $query_args = array_intersect_key( apply_filters( 'tpc_starter_api_query_filter', $query_args ), array_flip( $allowed_keys ) ); |
| 93 | $query_string = http_build_query( $query_args ); |
| 94 | |
| 95 | return ( ! empty( $query_string ) ) ? '?' . $query_string : ''; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Add theme support |
| 100 | */ |
| 101 | public function add_sites_library_support() { |
| 102 | add_theme_support( 'themeisle-demo-import', $this->get_ti_demo_content_support_data() ); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Get the sites |
| 107 | * |
| 108 | * @return array |
| 109 | */ |
| 110 | private function get_sites() { |
| 111 | $cache = get_transient( $this->transient_key ); |
| 112 | |
| 113 | if ( $cache !== false ) { |
| 114 | $response = $cache; |
| 115 | } else { |
| 116 | $response = wp_remote_get( esc_url( self::get_api_path() ) ); |
| 117 | |
| 118 | if ( is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) !== 200 ) { |
| 119 | return array(); |
| 120 | } |
| 121 | |
| 122 | $response = wp_remote_retrieve_body( $response ); |
| 123 | |
| 124 | $response = json_decode( $response, true ); |
| 125 | |
| 126 | if ( ! is_array( $response ) || empty( $response ) ) { |
| 127 | return array(); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 132 | $upsell_status = $this->get_upsell_status(); |
| 133 | |
| 134 | $divi = array( |
| 135 | array( |
| 136 | 'name' => 'Divi Builder', |
| 137 | 'active' => is_plugin_active( 'divi-builder/divi-builder.php' ), |
| 138 | 'author_url' => esc_url( 'https://www.elegantthemes.com/gallery/divi/' ), |
| 139 | ), |
| 140 | ); |
| 141 | $thive = array( |
| 142 | array( |
| 143 | 'name' => 'Thrive Architect', |
| 144 | 'active' => is_plugin_active( 'thrive-visual-editor/thrive-visual-editor.php' ), |
| 145 | 'author_url' => esc_url( 'https://thrivethemes.com/architect/' ), |
| 146 | ), |
| 147 | ); |
| 148 | |
| 149 | foreach ( $response as $editor => $sites ) { |
| 150 | foreach ( $sites as $slug => $site_data ) { |
| 151 | if ( $editor === 'divi builder' ) { |
| 152 | $response[ $editor ][ $slug ]['external_plugins'] = $divi; |
| 153 | } |
| 154 | if ( $editor === 'thrive architect' ) { |
| 155 | $response[ $editor ][ $slug ]['external_plugins'] = $thive; |
| 156 | } |
| 157 | if ( isset( $site_data['upsell'] ) ) { |
| 158 | $response[ $editor ][ $slug ]['upsell'] = $upsell_status; |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | set_transient( $this->transient_key, $response, 12 * HOUR_IN_SECONDS ); |
| 164 | |
| 165 | return $response; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Get the themeisle demo content support data. |
| 170 | * |
| 171 | * @return array |
| 172 | */ |
| 173 | private function get_ti_demo_content_support_data() { |
| 174 | $this->reorder_starter_sites(); |
| 175 | return apply_filters( 'neve_filter_onboarding_sites', $this->onboarding_config ); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Reorder starter sites based on previous theme |
| 180 | * |
| 181 | * @return bool |
| 182 | */ |
| 183 | private function reorder_starter_sites() { |
| 184 | $previous_theme = get_theme_mod( 'ti_prev_theme' ); |
| 185 | if ( empty( $previous_theme ) ) { |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | $slug_association = array( |
| 190 | 'zerif-pro' => 'neve-zelle', |
| 191 | 'zerif-lite' => 'neve-zelle', |
| 192 | 'themotion' => 'neve-themotion', |
| 193 | 'themotion-lite' => 'neve-themotion', |
| 194 | 'amadeus' => 'neve-amadeus', |
| 195 | 'rokophoto-lite' => 'neve-rokophoto', |
| 196 | 'rokophoto' => 'neve-rokophoto', |
| 197 | 'oblique' => 'neve-oblique', |
| 198 | 'shop-isle' => 'neve-shop', |
| 199 | 'shop-isle-pro' => 'neve-shop', |
| 200 | 'lawyeria-lite' => 'neve-lawyer', |
| 201 | 'lawyeria' => 'neve-lawyer', |
| 202 | ); |
| 203 | if ( ! array_key_exists( $previous_theme, $slug_association ) ) { |
| 204 | return false; |
| 205 | } |
| 206 | if ( ! isset( $this->onboarding_config['local']['elementor'][ $slug_association[ $previous_theme ] ] ) ) { |
| 207 | return false; |
| 208 | } |
| 209 | $starter_site = $this->onboarding_config['local']['elementor'][ $slug_association[ $previous_theme ] ]; |
| 210 | unset( $this->onboarding_config['local']['elementor'][ $slug_association[ $previous_theme ] ] ); |
| 211 | $this->onboarding_config['local']['elementor'] = array( $slug_association[ $previous_theme ] => $starter_site ) + $this->onboarding_config['local']['elementor']; |
| 212 | |
| 213 | return true; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Get upsell status. |
| 218 | * |
| 219 | * @return bool |
| 220 | */ |
| 221 | private function get_upsell_status() { |
| 222 | $category = apply_filters( 'product_neve_license_plan', -1 ); |
| 223 | $category_mapping = array( |
| 224 | 1 => 1, |
| 225 | 2 => 1, |
| 226 | 3 => 2, |
| 227 | 4 => 2, |
| 228 | 5 => 3, |
| 229 | 6 => 3, |
| 230 | 7 => 1, |
| 231 | 8 => 2, |
| 232 | 9 => 3, |
| 233 | ); |
| 234 | return apply_filters( 'product_neve_license_status', false ) !== 'valid' || ! isset( $category_mapping[ $category ] ) || $category_mapping[ $category ] < 2; |
| 235 | } |
| 236 | } |
| 237 |