PluginProbe ʕ •ᴥ•ʔ
WPML Multilingual & Multicurrency for WooCommerce / 5.5.7
WPML Multilingual & Multicurrency for WooCommerce v5.5.7
5.5.7 5.3.8 5.3.9 5.4.3 5.4.4 5.4.5 5.5.1 5.5.1.1 5.5.2.2 5.5.2.3 5.5.3 5.5.3.1 5.5.4 5.5.5 5.5.6 trunk 0.9 1.0 1.1 1.2 1.3 1.4 1.5 2.0 2.2 2.3 2.3.1 2.3.2 3.0 3.0.1 3.1 3.2 3.2.1 3.2.2 3.3 3.3.1 3.3.2 3.3.3 3.3.4 3.4 3.4.1 3.4.2 3.4.3 3.5 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.6 3.6.1 3.6.10 3.6.11 3.6.2 3.6.3 3.6.4 3.6.5 3.6.5.1 3.6.6 3.6.7 3.6.8 3.6.9 3.7 3.7.1 3.7.10 3.7.11 3.7.12 3.7.13 3.7.14 3.7.15 3.7.16 3.7.2 3.7.3 3.7.4 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.9.0 3.9.1 3.9.1.1 3.9.2 3.9.3 3.9.4 3.9.5 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.10.4 4.11.2 4.11.3.2 4.11.5 4.11.6 4.12.1 4.12.4 4.12.5 4.12.6 4.2.0 4.2.0.1 4.2.1 4.2.1.1 4.2.10 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.7.1 4.2.8 4.2.8.1 4.2.9 4.3.0 4.3.1 4.3.2 4.3.2.1 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.4.0 4.4.1 4.4.2 4.4.2.1 4.5.0 4.6.0 4.6.1 4.6.2 4.6.2.1 4.6.3 4.6.5 4.6.6 4.6.7 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / vendor / otgs / installer / includes / class-installer-theme.php
woocommerce-multilingual / vendor / otgs / installer / includes Last commit date
CDTClient 1 month ago admin-notices 1 month ago buy-url 1 month ago debug 1 month ago exceptions 5 years ago instances 1 month ago loader 5 years ago products 1 month ago repository 1 month ago rest 1 month ago site-key 1 month ago support 1 month ago template-service 1 month ago upgrade 1 month ago utilities 1 month ago wpml-content-stats 1 month ago class-installer-dependencies.php 1 month ago class-installer-theme.php 1 month ago class-installer-upgrader-skins.php 1 month ago class-otgs-installer-autoloader.php 5 years ago class-otgs-installer-cloned-sites-handler.php 1 month ago class-otgs-installer-debug-info.php 1 month ago class-otgs-installer-factory.php 1 month ago class-otgs-installer-filename-hooks.php 1 month ago class-otgs-installer-icons.php 1 month ago class-otgs-installer-loader.php 10 months ago class-otgs-installer-package-product-finder.php 1 month ago class-otgs-installer-package-product.php 1 month ago class-otgs-installer-package.php 5 years ago class-otgs-installer-php-functions.php 1 month ago class-otgs-installer-plugin-factory.php 1 month ago class-otgs-installer-plugin-finder.php 1 month ago class-otgs-installer-plugin.php 1 month ago class-otgs-installer-plugins-page-notice.php 1 month ago class-otgs-installer-plugins-update-cache-cleaner.php 5 years ago class-otgs-installer-settings.php 1 month ago class-otgs-installer-source-factory.php 5 years ago class-otgs-installer-source.php 1 month ago class-otgs-installer-subscription-factory.php 5 years ago class-otgs-installer-subscription-warning-message.php 1 month ago class-otgs-installer-subscription.php 1 month ago class-otgs-installer-wp-components-hooks.php 1 month ago class-otgs-installer-wp-components-sender.php 1 month ago class-otgs-installer-wp-components-setting-ajax.php 1 month ago class-otgs-installer-wp-components-setting-resources.php 1 month ago class-otgs-installer-wp-components-storage.php 1 month ago class-otgs-installer-wp-share-local-components-setting-hooks.php 1 month ago class-otgs-installer-wp-share-local-components-setting.php 1 month ago class-translation-service-info.php 1 month ago class-wp-installer-api.php 1 month ago class-wp-installer-channels.php 1 month ago class-wp-installer.php 1 month ago functions-core.php 1 month ago functions-templates.php 1 month ago otgs-installer-autoload-classmap.php 10 months ago
class-installer-theme.php
810 lines
1 <?php
2
3 if ( !defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class Installer_Theme_Class {
8
9 private $theme_repo;
10
11 private $repository_api;
12
13 private $repository_theme_products;
14
15 private $installer_site_url;
16
17 private $installer_site_key;
18
19 protected $installer_themes_option;
20
21 protected $installer_themes_available_updates;
22
23 protected $installer_themes = array();
24
25 protected $installer_repo_with_themes;
26
27 protected $installer_theme_active_tab;
28
29 protected $theme_user_registration;
30
31 protected $installer_theme_subscription_type;
32
33 public function __construct() {
34
35
36 $installer_repositories = WP_Installer()->get_repositories();
37
38 $repos_with_themes = $this->installer_theme_reposities_that_has_themes( $installer_repositories );
39
40 if ( is_array( $repos_with_themes ) ) {
41 $this->installer_repo_with_themes = $repos_with_themes;
42
43 foreach ( $repos_with_themes as $k => $repo ) {
44
45 $this->theme_repo[] = $repo;
46
47 if ( isset( $installer_repositories[ $repo ]['api-url'] ) ) {
48 $products_manager = WP_Installer()->get_products_manager();
49 $this->repository_api[$repo] = $installer_repositories[$repo]['api-url'];
50 $this->installer_site_url[$repo] = WP_Installer()->get_installer_site_url( $repo );
51 $this->installer_site_key[$repo] = WP_Installer()->get_site_key( $repo );
52 $this->repository_theme_products[ $repo ] = $products_manager->get_products_url(
53 $repo,
54 $this->installer_site_key[ $repo ],
55 $this->installer_site_url[ $repo ],
56 false
57 );
58
59
60 $this->theme_user_registration[$repo] = false;
61
62 if ( WP_Installer()->repository_has_valid_subscription( $repo ) ) {
63
64 $this->installer_theme_subscription_type = WP_Installer()->get_subscription_type_for_repository( $repo );
65 $this->installer_themes_option[$repo] = 'wp_installer_' . $repo . '_themes';
66 $this->installer_themes_available_updates[$repo] = 'wp_installer_' . $repo . '_updated_themes';
67 $this->installer_theme_active_tab = '';
68
69 $this->installer_theme_available( $repo, $this->installer_theme_subscription_type );
70
71 add_action( 'installer_themes_support_set_up', array($this, 'installer_theme_sets_active_tab_on_init'), 10 );
72 $this->theme_user_registration[$repo] = true;
73 }
74
75 $this->init();
76 }
77 }
78 add_action( 'installer_themes_support_set_up', array($this, 'installer_theme_loaded_hooks') );
79 }
80 }
81
82 public function init() {
83 add_action( 'admin_enqueue_scripts', array($this, 'installer_theme_enqueue_scripts') );
84 add_filter( 'themes_api', array($this, 'installer_theme_api_override'), 10, 3 );
85 add_filter( 'themes_api_result', array($this, 'installer_theme_api_override_response'), 10, 3 );
86 add_filter( 'site_transient_update_themes', array($this, 'installer_theme_upgrade_check'), 10, 1 );
87 add_action( 'http_api_debug', array($this, 'installer_theme_sync_native_wp_api'), 10, 5 );
88 add_filter( 'installer_theme_hook_response_theme', array($this, 'installer_theme_add_num_ratings'), 10, 1 );
89 add_filter( 'themes_update_check_locales', array($this, 'installer_theme_sync_call_wp_theme_api'), 10, 1 );
90 add_filter( 'admin_url', array($this, 'installer_theme_add_query_arg_tab'), 10, 3 );
91 add_filter( 'network_admin_url', array($this, 'installer_theme_add_query_arg_tab'), 10, 2 );
92 add_action( 'wp_ajax_installer_theme_frontend_selected_tab', array($this, 'installer_theme_frontend_selected_tab'), 0 );
93 add_action( 'wp_loaded', array($this, 'installer_themes_support_set_up_func') );
94 }
95
96 public function installer_theme_enqueue_scripts() {
97 $current_screen = $this->installer_theme_current_screen();
98 $commercial_plugin_screen = $this->installer_theme_is_commercial_plugin_screen( $current_screen );
99 if ( ('theme-install' == $current_screen) || ($commercial_plugin_screen) || ('theme-install-network' == $current_screen) ) {
100 $repo_with_themes = $this->installer_repo_with_themes;
101 $js_array = array();
102 if ( is_array( $repo_with_themes ) ) {
103 foreach ( $repo_with_themes as $k => $v ) {
104
105 $theme_repo_name = $this->installer_theme_get_repo_product_name( $v );
106 $the_hyperlink_text = esc_js( $theme_repo_name );
107
108 if ( is_multisite() ) {
109 $admin_url_passed = network_admin_url();
110 } else {
111 $admin_url_passed = admin_url();
112 }
113
114 $js_array[$v] = array(
115 'the_hyperlink_text' => $the_hyperlink_text,
116 'registration_status' => $this->theme_user_registration[$v],
117 'is_commercial_plugin_tab' => $commercial_plugin_screen,
118 'registration_url' => $admin_url_passed . 'plugin-install.php?tab=commercial#installer_repo_' . $v
119 );
120
121 }
122 }
123
124 if ( !(empty($js_array)) ) {
125 wp_register_script( 'otgs-purify', WP_Installer()->res_url() . '/dist/js/domPurify/app.js', [], WP_Installer()->version() );
126 wp_enqueue_script( 'installer-theme-install', WP_Installer()->res_url() . '/res/js/installer_theme_install.js', [
127 'jquery',
128 'otgs-purify'
129 ], WP_Installer()->version() );
130 $installer_ajax_url = admin_url( 'admin-ajax.php' );
131
132 if ( is_ssl() ) {
133 $installer_ajax_url = str_replace( 'http://', 'https://', $installer_ajax_url );
134 } else {
135 $installer_ajax_url = str_replace( 'https://', 'http://', $installer_ajax_url );
136 }
137
138 $subscription_js_check = $this->installer_theme_subscription_does_not_have_theme( $js_array );
139
140 wp_localize_script( 'installer-theme-install', 'installer_theme_install_localize',
141 array(
142 'js_array_installer' => $js_array,
143 'ajaxurl' => $installer_ajax_url,
144 'no_associated_themes' => $subscription_js_check,
145 'installer_theme_frontend_selected_tab_nonce' => wp_create_nonce( 'installer_theme_frontend_selected_tab' )
146 )
147 );
148 }
149 }
150 }
151
152 protected function installer_theme_subscription_does_not_have_theme( $js_array ) {
153
154 $any_subscription_has_theme = array();
155 $number_of_registrations = array();
156
157 foreach ( $js_array as $repo_slug => $js_details ) {
158
159 if ( isset($this->theme_user_registration[$repo_slug]) ) {
160 $registration_status = $this->theme_user_registration[$repo_slug];
161 if ( $registration_status ) {
162
163 $number_of_registrations[] = $repo_slug;
164
165 $themes_available = false;
166 if ( isset($this->installer_themes[$repo_slug]) ) {
167 $themes_available = $this->installer_themes[$repo_slug];
168 if ( !(empty($themes_available)) ) {
169 $themes_available = true;
170 }
171 }
172
173 if ( $themes_available ) {
174 $any_subscription_has_theme[] = $repo_slug;
175 }
176 }
177 }
178
179 }
180
181 if ( empty( $registration_status ) ) {
182 return false;
183 }
184
185 if ( empty($any_subscription_has_theme) ) {
186 return true;
187 }
188
189 return false;
190 }
191
192 private function installer_theme_is_commercial_plugin_screen( $current_screen ) {
193 $commercial = false;
194 if ( ('plugin-install' == $current_screen) || ('plugin-install-network' == $current_screen) ) {
195 if ( isset($_GET['tab']) ) {
196 $tab = sanitize_text_field( $_GET['tab'] );
197 if ( 'commercial' == $tab ) {
198 $commercial = true;
199 }
200 }
201 }
202 return $commercial;
203 }
204
205 private function installer_theme_current_screen() {
206
207 $current_screen_loaded = false;
208
209 if ( function_exists( 'get_current_screen' ) ) {
210
211 $screen_output = get_current_screen();
212 $current_screen_loaded = $screen_output->id;
213
214 }
215
216 return $current_screen_loaded;
217
218 }
219
220 public function installer_theme_api_override( $api_boolean, $action, $args ) {
221
222 if ( isset($args->browse) ) {
223 $browse = $args->browse;
224 if ( in_array( $browse, $this->theme_repo ) ) {
225 if ( 'query_themes' == $action ) {
226 $api_boolean = true;
227 }
228 }
229 } elseif ( isset($args->slug) ) {
230 $theme_to_install = $args->slug;
231
232 $validate_check = $this->installer_themes_belong_to_us( $theme_to_install );
233 if ( $validate_check ) {
234 if ( !(empty($theme_to_install)) ) {
235 $api_boolean = true;
236 }
237 }
238 }
239
240 return $api_boolean;
241 }
242
243 public function installer_theme_api_override_response( $res, $action, $args ) {
244 if ( true === $res ) {
245 if ( isset($args->browse) ) {
246 $browse = $args->browse;
247 if ( in_array( $browse, $this->theme_repo ) ) {
248 if ( 'query_themes' == $action ) {
249 if ( isset($this->theme_user_registration[$browse]) ) {
250 if ( !($this->theme_user_registration[$browse]) ) {
251 $res = new stdClass();
252 $res->info = array();
253 $res->themes = array();
254 return $res;
255 } else {
256 $themes = $this->installer_theme_get_themes( '', $browse );
257 $res = $this->installer_theme_format_response( $themes, $action );
258 }
259 }
260 }
261 }
262 } elseif ( isset($args->slug) ) {
263 $theme_to_install = $args->slug;
264
265 $validate_check = $this->installer_themes_belong_to_us( $theme_to_install );
266 if ( $validate_check ) {
267 if ( ($res) && ('theme_information' == $action) ) {
268 $themes = $this->installer_theme_get_themes( '', $this->installer_theme_active_tab );
269 $res = $this->installer_theme_format_response( $themes, $action, $args->slug );
270 }
271 }
272 }
273 }
274
275 return $res;
276 }
277
278 private function installer_theme_get_themes( $product_url = '', $repository_id = '' ) {
279
280 if ( empty($product_url) ) {
281 if ( isset($this->repository_theme_products[$this->installer_theme_active_tab]) ) {
282 $query_remote_url = $this->repository_theme_products[$this->installer_theme_active_tab];
283 }
284
285 } else {
286 $query_remote_url = $product_url;
287 }
288
289 $current_installer_settings = WP_Installer()->get_settings();
290
291 $themes = false;
292
293 if ( (is_array( $current_installer_settings )) && (!(empty($current_installer_settings))) ) {
294
295 if ( isset($current_installer_settings['repositories'][$repository_id]['data']) ) {
296 $products = $current_installer_settings['repositories'][$repository_id]['data'];
297 if ( isset($products['downloads']['themes']) ) {
298 $themes = $products['downloads']['themes'];
299 }
300 }
301
302 } else {
303
304 $response = wp_remote_get( $query_remote_url );
305
306 if ( is_wp_error( $response ) ) {
307 $query_remote_url = preg_replace( "@^https://@", 'http://', $query_remote_url );
308 $response = wp_remote_get( $query_remote_url );
309 }
310
311 if ( !(is_wp_error( $response )) ) {
312 if ( $response && isset($response['response']['code']) && $response['response']['code'] == 200 ) {
313 $body = wp_remote_retrieve_body( $response );
314 if ( $body ) {
315 $products = json_decode( $body, true );
316 if ( isset($products['downloads']['themes']) ) {
317 $themes = $products['downloads']['themes'];
318 }
319 }
320
321 }
322 }
323 }
324
325 return apply_filters( 'installer_theme_get_themes', $themes, $this->installer_theme_active_tab );
326 }
327
328 private function installer_theme_format_response( $themes, $action, $slug = '' ) {
329
330 if ( ('theme_information' == $action) && (!(empty($slug))) ) {
331
332 foreach ( $themes as $k => $theme ) {
333 if ( $slug == $theme['basename'] ) {
334 $theme['download_link'] = WP_Installer()->append_site_key_to_download_url( $theme['url'], $this->installer_site_key[$this->installer_theme_active_tab], $this->installer_theme_active_tab );
335 $theme = json_decode( (string) json_encode( $theme ), false );
336 return $theme;
337 }
338 }
339
340 } else {
341
342 $res = new stdClass();
343 $res->info = array();
344 $res->themes = array();
345
346 $res->info['page'] = 1;
347 $res->info['pages'] = 10;
348
349 $res->info['results'] = count( $themes );
350
351 $this->installer_theme_savethemes_by_slug( $themes );
352
353 if ( isset($this->installer_theme_subscription_type) ) {
354 $this->installer_theme_available( $this->installer_theme_active_tab, $this->installer_theme_subscription_type );
355 } else {
356 $this->installer_theme_available( $this->installer_theme_active_tab );
357 }
358
359 $theme_compatible_array=array();
360 if ((is_array($themes))) {
361 foreach ($themes as $k=>$v) {
362 $theme_compatible_array[]=(object)($v);
363 }
364 }
365 $res->themes = $theme_compatible_array;
366 $res->themes = apply_filters( 'installer_theme_hook_response_theme', $res->themes );
367 return $res;
368 }
369 }
370
371 private function installer_theme_savethemes_by_slug( $themes, $doing_query = false ) {
372
373 if ( !($doing_query) ) {
374 $this->installer_themes[$this->installer_theme_active_tab] = array();
375 }
376
377 if ( !(empty($themes)) ) {
378 $themes_for_saving = array();
379 foreach ( $themes as $k => $theme ) {
380 if ( !($doing_query) ) {
381 if ( isset($theme['slug']) ) {
382 $theme_slug = $theme['slug'];
383 if ( !(empty($theme_slug)) ) {
384 $themes_for_saving[] = $theme_slug;
385 }
386 }
387 } else {
388
389 if ( ((isset($theme['slug'])) && (isset($theme['version'])) &&
390 (isset($theme['theme_page_url']))) && (isset($theme['url']))
391 ) {
392 $theme_slug = $theme['slug'];
393 $theme_version = $theme['version'];
394 $theme_page_url = $theme['theme_page_url'];
395 $theme_url = $theme['url'];
396 if ( (!(empty($theme_slug))) && (!(empty($theme_version))) &&
397 (!(empty($theme_page_url))) && (!(empty($theme_url)))
398 ) {
399 $themes_for_saving[$theme_slug] = array(
400 'version' => $theme_version,
401 'theme_page_url' => $theme_page_url,
402 'url' => $theme_url
403 );
404
405 }
406 }
407 }
408
409 }
410
411 if ( !(empty($themes_for_saving)) ) {
412 if ( !($doing_query) ) {
413 $existing_themes = get_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
414 if ( !($existing_themes) ) {
415 delete_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
416 update_option( $this->installer_themes_option[$this->installer_theme_active_tab], $themes_for_saving );
417 } else {
418 if ( $existing_themes == $themes_for_saving ) {
419 } else {
420 delete_option( $this->installer_themes_option[$this->installer_theme_active_tab] );
421 update_option( $this->installer_themes_option[$this->installer_theme_active_tab], $themes_for_saving );
422 }
423 }
424 } else {
425 return $themes_for_saving;
426 }
427 }
428 }
429 }
430
431 private function installer_theme_available( $repo, $subscription_type = '' ) {
432
433 $subscription_type = intval( $subscription_type );
434 if ( $subscription_type > 0 ) {
435
436 $themes_associated_with_subscription = $this->installer_themes[$repo] = $this->installer_theme_get_themes_by_subscription( $subscription_type, $repo );
437 if ( !(empty($themes_associated_with_subscription)) ) {
438 $this->installer_themes[$repo] = $themes_associated_with_subscription;
439 }
440 } else {
441
442 $this->installer_themes[$repo] = get_option( $this->installer_themes_option[$repo] );
443 }
444 }
445
446 public function installer_theme_upgrade_check( $the_value ) {
447
448 if ( (is_array( $this->installer_repo_with_themes )) && (!(empty($this->installer_repo_with_themes))) ) {
449 foreach ( $this->installer_repo_with_themes as $k => $repo_slug ) {
450 if ( is_array( $this->installer_themes_available_updates ) && isset( $this->installer_themes_available_updates[ $repo_slug ] ) ) {
451 $update_available = get_option( $this->installer_themes_available_updates[ $repo_slug ] );
452 } else {
453 $update_available = false;
454 }
455
456 if ( $update_available ) {
457 if ( is_array( $update_available ) ) {
458 foreach ( $update_available as $theme_slug => $v ) {
459 $the_value->response [$theme_slug] = array(
460 'theme' => $theme_slug,
461 'new_version' => $v['new_version'],
462 'url' => $v['url'],
463 'package' => $v['package']
464 );
465 }
466 }
467 }
468 }
469 }
470 return $the_value;
471 }
472
473 private function installer_theme_reposities_that_has_themes( $repositories, $ret_value = true, $doing_api_query = false ) {
474
475 $repositories_with_themes = array();
476
477 if ( (is_array( $repositories )) && (!(empty($repositories))) ) {
478
479 $themes = get_option( 'installer_repositories_with_theme' );
480
481 if ( (!($themes)) || ($doing_api_query) ) {
482 foreach ( $repositories as $repository_id => $repository_data ) {
483 $products_manager = WP_Installer()->get_products_manager();
484 $product_url = $products_manager->get_products_url(
485 $repository_id,
486 WP_Installer()->get_site_key( $repository_id ),
487 WP_Installer()->get_installer_site_url( $repository_id ),
488 false
489 );
490 if ( $product_url ) {
491 $themes = $this->installer_theme_get_themes( $product_url, $repository_id );
492 if ( ( is_array( $themes ) ) && ( ! ( empty( $themes ) ) ) ) {
493 $repositories_with_themes[] = $repository_id;
494 }
495 }
496 }
497 } else {
498 $repositories_with_themes = $themes;
499 }
500
501 if ( (((is_array( $repositories_with_themes )) && (!(empty($repositories_with_themes)))) && (!($themes))) || ($doing_api_query) ) {
502 update_option( 'installer_repositories_with_theme', $repositories_with_themes );
503 }
504 }
505
506 if ( $ret_value ) {
507 return $repositories_with_themes;
508 }
509
510 }
511
512 public function installer_theme_sync_native_wp_api( $response, $responsetext, $class, $args, $url ) {
513
514 $api_native_string = 'api.wordpress.org/themes/';
515 if ( (strpos( $url, $api_native_string ) !== false) ) {
516 $installer_repositories = WP_Installer()->get_repositories();
517
518 $this->installer_theme_reposities_that_has_themes( $installer_repositories, false, true );
519 }
520 }
521
522 private function installer_theme_get_repo_product_name( $theme_repo ) {
523
524 $theme_repo_name = false;
525
526 if ( isset(WP_Installer()->settings['repositories'][$theme_repo]['data']['product-name']) ) {
527 $prod_name = WP_Installer()->settings['repositories'][$theme_repo]['data']['product-name'];
528 if ( !(empty($prod_name)) ) {
529 $theme_repo_name = $prod_name;
530 }
531 } else {
532 if ( $theme_repo == $this->theme_repo ) {
533 $result = $this->installer_theme_general_api_query();
534 if ( isset($result['product-name']) ) {
535 $product_name = $result['product-name'];
536 if ( !(empty($product_name)) ) {
537 $theme_repo_name = $product_name;
538 }
539 }
540 }
541 }
542
543 return $theme_repo_name;
544 }
545
546 private function installer_theme_general_api_query() {
547 $products = false;
548 $response = wp_remote_get( $this->repository_theme_products );
549 if ( !(is_wp_error( $response )) ) {
550 if ( $response && isset($response['response']['code']) && $response['response']['code'] == 200 ) {
551 $body = wp_remote_retrieve_body( $response );
552 if ( $body ) {
553 $result = json_decode( $body, true );
554 if ( (is_array( $result )) && (!(empty($result))) ) {
555 $products = $result;
556 }
557 }
558
559 }
560 }
561
562 return $products;
563 }
564
565 private function installer_themes_belong_to_us( $theme_slug ) {
566
567 $found = false;
568 $theme_slug = trim( $theme_slug );
569
570 foreach ( $this->installer_themes as $repo_with_theme => $themes ) {
571 foreach ( $themes as $k => $otgs_theme_slug ) {
572 if ( $theme_slug == $otgs_theme_slug ) {
573 return true;
574 }
575 }
576 }
577 return $found;
578
579 }
580
581 public function installer_theme_sets_active_tab_on_init() {
582
583 if ( isset ($_SERVER ['REQUEST_URI']) ) {
584 $request_uri = $_SERVER ['REQUEST_URI'];
585 if ( isset ($_GET ['browse']) ) {
586 $active_tab = sanitize_text_field( $_GET['browse'] );
587 $this->installer_theme_active_tab = $active_tab;
588 } elseif ( isset ($_POST ['request'] ['browse']) ) {
589 $active_tab = sanitize_text_field ( $_POST['request']['browse'] );
590 $this->installer_theme_active_tab = $active_tab;
591 } elseif ( (isset ($_GET ['theme_repo'])) && (isset ($_GET ['action'])) ) {
592 $theme_repo = sanitize_text_field( $_GET['theme_repo'] );
593 $the_action = sanitize_text_field( $_GET['action'] );
594 if ( ('install-theme' == $the_action) && (!(empty($theme_repo))) ) {
595 $this->installer_theme_active_tab = $theme_repo;
596 }
597 } elseif ( wp_get_referer() ) {
598 $referer = wp_get_referer();
599 $parts = parse_url( $referer );
600 if ( isset($parts['query']) ) {
601 parse_str( $parts['query'], $query );
602 if ( isset($query['browse']) ) {
603 $this->installer_theme_active_tab = $query['browse'];
604 }
605 }
606 }
607 }
608 }
609
610 public function installer_theme_add_num_ratings( $themes ) {
611
612 if ( (is_array( $themes )) && (!(empty($themes))) ) {
613 foreach ( $themes as $k => $v ) {
614 if ( !(isset($v->num_ratings)) ) {
615 $themes[$k]->num_ratings = 100;
616 }
617 if ( !(isset($v->rating)) ) {
618 $themes[$k]->rating = 100;
619 }
620 }
621 }
622
623 return $themes;
624 }
625
626 public function installer_theme_sync_call_wp_theme_api( $locales ) {
627
628 $this->installer_theme_upgrade_theme_check();
629
630 return $locales;
631 }
632
633 private function installer_theme_upgrade_theme_check() {
634
635 $installed_themes = wp_get_themes();
636
637 foreach ( $this->installer_repo_with_themes as $k => $repo_slug ) {
638
639 $products_url = $this->repository_theme_products [$repo_slug];
640
641 $available_themes = $this->installer_theme_get_themes( $products_url, $repo_slug );
642
643 if ( !($available_themes) ) {
644
645 return;
646 } else {
647
648 $simplified_available_themes = $this->installer_theme_savethemes_by_slug( $available_themes, true );
649
650 if ( (is_array( $installed_themes )) && (!(empty ($installed_themes))) ) {
651 $otgs_theme_updates_available = array();
652 foreach ( $installed_themes as $theme_slug => $theme_object ) {
653 if ( array_key_exists( $theme_slug, $simplified_available_themes ) ) {
654
655 $local_version = $theme_object->get( 'Version' );
656
657 $repository_version = $simplified_available_themes [$theme_slug] ['version'];
658 $theme_page_url = $simplified_available_themes [$theme_slug] ['theme_page_url'];
659 $theme_download_url = $simplified_available_themes [$theme_slug] ['url'];
660
661 if ( version_compare( $repository_version, $local_version, '>' ) ) {
662
663 $package_url = WP_Installer()->append_site_key_to_download_url( $theme_download_url, $this->installer_site_key [$repo_slug], $repo_slug );
664
665 $otgs_theme_updates_available[$theme_slug] = array(
666 'theme' => $theme_slug,
667 'new_version' => $repository_version,
668 'url' => $theme_page_url,
669 'package' => $package_url
670 );
671 }
672 }
673 }
674 if ( !empty($otgs_theme_updates_available) ) {
675 if ( is_array( $this->installer_themes_available_updates ) && isset( $this->installer_themes_available_updates[ $repo_slug ] ) ) {
676 update_option( $this->installer_themes_available_updates[ $repo_slug ], $otgs_theme_updates_available );
677 }
678 } else {
679 if ( is_array( $this->installer_themes_available_updates ) && isset( $this->installer_themes_available_updates[ $repo_slug ] ) ) {
680 delete_option( $this->installer_themes_available_updates[ $repo_slug ] );
681 }
682 }
683 }
684 }
685 }
686 }
687
688 public function installer_theme_add_query_arg_tab( $url, $path, $blog_id = null ) {
689
690 $wp_install_string = 'update.php?action=install-theme';
691 if ( $path == $wp_install_string ) {
692 if ( isset($this->installer_theme_active_tab) ) {
693 if ( !(empty($this->installer_theme_active_tab)) ) {
694 $url = add_query_arg( array(
695 'theme_repo' => $this->installer_theme_active_tab
696 ), $url );
697 }
698 }
699 }
700 return $url;
701 }
702
703 public function installer_theme_frontend_selected_tab() {
704 if ( isset($_POST["frontend_tab_selected"]) ) {
705 check_ajax_referer( 'installer_theme_frontend_selected_tab', 'installer_theme_frontend_selected_tab_nonce' );
706
707 $frontend_tab_selected = sanitize_text_field( $_POST['frontend_tab_selected'] );
708 if ( !(empty($frontend_tab_selected)) ) {
709 update_option( 'wp_installer_clientside_active_tab', $frontend_tab_selected, false );
710
711 if ( isset($this->theme_user_registration[$frontend_tab_selected]) ) {
712 if ( !($this->theme_user_registration[$frontend_tab_selected]) ) {
713
714 if ( is_multisite() ) {
715 $admin_url_passed = network_admin_url();
716 } else {
717 $admin_url_passed = admin_url();
718 }
719
720 $registration_url = $admin_url_passed . 'plugin-install.php?tab=commercial#installer_repo_' . $frontend_tab_selected;
721
722 $theme_repo_name = $this->installer_theme_get_repo_product_name( $frontend_tab_selected );;
723 $response['unregistered_messages'] = sprintf( __( 'To install and update %s, please %sregister%s %s for this site.', 'installer' ),
724 $theme_repo_name, '<a href="' . $registration_url . '">', '</a>', $theme_repo_name );
725
726 }
727 }
728
729 $response['output'] = $frontend_tab_selected;
730 echo json_encode( $response );
731 }
732 die();
733 }
734 die();
735 }
736
737 public function installer_theme_loaded_hooks() {
738
739 if ( isset($this->installer_theme_subscription_type) ) {
740 $subscription_type = intval( $this->installer_theme_subscription_type );
741 if ( $subscription_type > 0 ) {
742 add_filter( 'installer_theme_get_themes', array($this, 'installer_theme_filter_themes_by_subscription'), 10, 2 );
743 }
744 }
745
746 }
747
748 protected function installer_theme_get_themes_by_subscription( $subscription_type, $repo ) {
749
750 $themes_associated_with_subscription = array();
751 if ( isset(WP_Installer()->settings['repositories'][$repo]['data']['packages']) ) {
752 $packages = WP_Installer()->settings['repositories'][$repo]['data']['packages'];
753 $available_themes_subscription = array();
754 foreach ( $packages as $package_id => $package_details ) {
755 if ( isset($package_details['products']) ) {
756 $the_products = $package_details['products'];
757 foreach ( $the_products as $product_slug => $product_details ) {
758 if ( isset($product_details['subscription_type']) ) {
759 $subscription_type_from_settings = intval( $product_details['subscription_type'] );
760 if ( $subscription_type_from_settings == $subscription_type ) {
761 if ( isset($product_details['themes']) ) {
762 $themes_associated_with_subscription = $product_details['themes'];
763 return $themes_associated_with_subscription;
764 }
765 }
766 }
767
768 }
769 }
770 }
771 }
772 return $themes_associated_with_subscription;
773 }
774
775 public function installer_theme_filter_themes_by_subscription( $themes, $active_tab ) {
776
777 $orig = is_array( $themes ) ? count( $themes ) : 0;
778 if ( in_array( $active_tab, $this->theme_repo ) ) {
779 if ( isset($this->installer_themes[$active_tab]) ) {
780 $available_themes = $this->installer_themes[$active_tab];
781 if ( (is_array( $themes )) && (!(empty($themes))) ) {
782 foreach ( $themes as $k => $theme ) {
783 if ( isset($theme['slug']) ) {
784 $theme_slug = $theme['slug'];
785 if ( !(empty($theme_slug)) ) {
786 if ( !(in_array( $theme_slug, $available_themes )) ) {
787 unset($themes[$k]);
788 }
789 }
790 }
791 }
792 }
793 }
794 }
795 $new = is_array( $themes ) ? count( $themes ) : 0;
796 if ( $orig != $new ) {
797 $themes = array_values( $themes );
798 }
799
800 return $themes;
801 }
802
803 public function installer_themes_support_set_up_func() {
804 do_action( 'installer_themes_support_set_up' );
805 }
806
807 }
808
809 new Installer_Theme_Class;
810