Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/blocksy-companion-pro/framework/dashboard.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + namespace Blocksy;
4 +
5 + class Dashboard {
6 + public function __construct() {
7 + add_filter(
8 + 'blocksy:dashboard:redirect-after-activation',
9 + function ($url) {
10 + return add_query_arg(
11 + 'page',
12 + 'ct-dashboard',
13 + admin_url('admin.php')
14 + );
15 + }
16 + );
17 +
18 + add_filter(
19 + 'blocksy_add_menu_page',
20 + function ($res, $options) {
21 + add_menu_page(
22 + $options['title'],
23 + $options['menu-title'],
24 + $options['permision'],
25 + $options['top-level-handle'],
26 + $options['callback'],
27 + $options['icon-url'],
28 + 2
29 + );
30 +
31 + add_submenu_page(
32 + $options['top-level-handle'],
33 + $options['title'],
34 + __('Dashboard', 'blocksy-companion'),
35 + $options['permision'],
36 + $options['top-level-handle']
37 + );
38 +
39 + return true;
40 + },
41 + 10, 2
42 + );
43 +
44 + add_action(
45 + 'admin_menu',
46 + [$this, 'setup_framework_page'],
47 + 5
48 + );
49 +
50 + if (defined('WP_FS__LOWEST_PRIORITY')) {
51 + add_action(
52 + 'network_admin_menu',
53 + function () {
54 + global $menu;
55 +
56 + foreach ($menu as $key => $item) {
57 + if ($item[2] === 'ct-dashboard') {
58 + $menu[$key][0] = __('Blocksy', 'blocksy-companion');
59 + $menu[$key][3] = __('Blocksy', 'blocksy-companion');
60 + $menu[$key][4] = "menu-top";
61 + $menu[$key][6] = set_url_scheme($this->get_icon());
62 + }
63 + }
64 + },
65 + WP_FS__LOWEST_PRIORITY + 1
66 + );
67 + }
68 +
69 + add_filter(
70 + 'blocksy:dashboard:redirect-after-activation',
71 + function ($url) {
72 + return add_query_arg(
73 + 'page',
74 + 'ct-dashboard',
75 + admin_url('admin.php')
76 + );
77 + }
78 + );
79 +
80 + add_action('admin_notices', function () {
81 + $blocksy_data = Plugin::instance()->is_blocksy_data;
82 +
83 + if (
84 + ! Plugin::instance()->check_if_blocksy_is_activated()
85 + &&
86 + $blocksy_data
87 + &&
88 + $blocksy_data['is_correct_theme']
89 + ) {
90 + blocksy_render_view_e(
91 + dirname(__FILE__) . '/views/theme-mismatch.php',
92 + [
93 + 'is_theme_version_ok' => $blocksy_data['is_theme_version_ok'],
94 + 'is_companion_version_ok' => $blocksy_data['is_companion_version_ok'],
95 + ]
96 + );
97 + }
98 + });
99 +
100 + add_action(
101 + 'admin_menu',
102 + function () {
103 + if (Plugin::instance()->check_if_blocksy_is_activated()) {
104 + return;
105 + }
106 +
107 + $menu_slug = plugin_basename('ct-dashboard');
108 + $hookname = get_plugin_page_hookname('ct-dashboard', '');
109 + remove_all_actions($hookname);
110 +
111 + add_action(
112 + $hookname,
113 + function () {
114 + $this->welcome_page_template();
115 + }
116 + );
117 + },
118 + 99999999999
119 + );
120 +
121 + add_action(
122 + 'admin_enqueue_scripts',
123 + [$this, 'enqueue_static'],
124 + 100
125 + );
126 +
127 + add_action('admin_body_class', function ($class) {
128 + if (! Plugin::instance()->check_if_blocksy_is_activated()) {
129 + return $class;
130 + }
131 +
132 + if (function_exists('blc_fs') && blc_fs()->is_activation_mode()) {
133 + $class .= ' blocksy-fs-optin-dashboard';
134 + }
135 +
136 + return $class;
137 + });
138 +
139 + if (function_exists('blc_fs')) {
140 + blc_fs()->add_filter('hide_plan_change', '__return_true');
141 + blc_fs()->add_filter(
142 + 'plugin_icon',
143 + function ($url) {
144 + return BLOCKSY_PATH . '/static/img/logo.jpg';
145 + }
146 + );
147 +
148 + blc_fs()->add_filter(
149 + 'permission_diagnostic_default',
150 + '__return_false'
151 + );
152 +
153 + blc_fs()->add_filter(
154 + 'show_deactivation_feedback_form',
155 + '__return_false'
156 + );
157 +
158 + blc_fs()->add_filter('hide_freemius_powered_by', '__return_true');
159 +
160 + blc_fs()->add_filter( 'show_deactivation_subscription_cancellation', '__return_false' );
161 +
162 + blc_fs()->add_filter(
163 + 'connect-message_on-premium',
164 + function ($text) {
165 + if (strpos($text, '<br>') !== false) {
166 + $exploded_message = explode('<br>', $text);
167 +
168 + $text = '<span>' . $exploded_message[0] . '</span>' . $exploded_message[1];
169 + }
170 +
171 + return $text;
172 + }
173 + );
174 +
175 + blc_fs()->add_filter(
176 + 'connect_message_on_update',
177 + function (
178 + $message,
179 + $user_first_name,
180 + $product_title,
181 + $user_login,
182 + $site_link,
183 + $freemius_link
184 + ) {
185 + $is_network_upgrade_mode = ( fs_is_network_admin() && blc_fs()->is_network_upgrade_mode() );
186 + $slug = blc_fs()->get_slug();
187 + $is_gdpr_required = \FS_GDPR_Manager::instance()->is_required();
188 + $hey_x_text = esc_html( blc_safe_sprintf( fs_text_x_inline( 'Hey %s,', 'greeting', 'hey-x', $slug ), $user_first_name ) );
189 +
190 + $default_optin_message = $is_gdpr_required ?
191 + fs_text_inline( 'Never miss an important update - opt in to our security & feature updates notifications, educational content, offers, and non-sensitive diagnostic tracking with %4$s. If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update', $slug ) :
192 + fs_text_inline( 'Never miss an important update - opt in to our security & feature updates notifications, and non-sensitive diagnostic tracking with %4$s. If you skip this, that\'s okay! %1$s will still work just fine.', 'connect-message_on-update', $slug );
193 +
194 + $default_optin_message = 'Never miss an important update - opt in to our security & feature updates notifications, educational content, offers, and non-sensitive diagnostic tracking with.';
195 +
196 + return (($is_network_upgrade_mode ?
197 + '' :
198 + /* translators: %s: name (e.g. Hey John,) */
199 + '<span>' . $hey_x_text . '</span>'
200 + ) .
201 + blc_safe_sprintf(
202 + esc_html( $default_optin_message ),
203 + '<b>' . esc_html( blc_fs()->get_plugin_name() ) . '</b>',
204 + '<b>' . $user_login . '</b>',
205 + $site_link,
206 + $freemius_link
207 + ));
208 +
209 + }, 10, 6
210 + );
211 +
212 + blc_fs()->add_action('connect/before', function () {
213 + $path = dirname(__FILE__) . '/views/optin.php';
214 +
215 + blocksy_render_view_e($path, []);
216 + });
217 +
218 + blc_fs()->add_action('connect/after', function () {
219 + echo '</div>';
220 + });
221 +
222 + add_action(
223 + 'wp_ajax_blocksy_fs_connect_again',
224 + function () {
225 + if (! current_user_can('edit_theme_options')) {
226 + wp_send_json_error();
227 + }
228 +
229 + blc_fs()->connect_again();
230 + wp_send_json_success();
231 + }
232 + );
233 +
234 + add_action(
235 + 'wp_ajax_blocksy_dashboard_handle_incorrect_license',
236 + function () {
237 + if (! current_user_can(
238 + blc_get_capabilities()->get_wp_capability_by('dashboard')
239 + )) {
240 + wp_send_json_error();
241 + }
242 +
243 + $blocksy_active_extensions_old = get_option(
244 + 'blocksy_active_extensions_old',
245 + '__empty__'
246 + );
247 +
248 + if ($blocksy_active_extensions_old !== '__empty__') {
249 + return;
250 + }
251 +
252 + $activated_extensions = get_option('blocksy_active_extensions', []);
253 +
254 + update_option(
255 + 'blocksy_active_extensions_old',
256 + $activated_extensions
257 + );
258 +
259 + delete_option('blocksy_active_extensions');
260 +
261 + wp_send_json_success();
262 + }
263 + );
264 + }
265 +
266 + add_filter(
267 + 'blocksy_dashboard_localizations',
268 + function ($d) {
269 + $plugin_data = get_plugin_data(BLOCKSY__FILE__);
270 +
271 + $result = [
272 + 'is_pro' => false,
273 + 'is_anonymous' => false,
274 + 'connect_template' => '',
275 + 'retrieve_demos_data' => [],
276 + 'plugin_version' => $plugin_data['Version'],
277 + 'is_multisite' => is_multisite()
278 + ];
279 +
280 + if (function_exists('blc_fs')) {
281 + $is_anonymous = blc_fs()->is_anonymous();
282 + $connect_template = '';
283 +
284 + if ($is_anonymous) {
285 + ob_start();
286 + blc_fs()->_connect_page_render();
287 + $connect_template = ob_get_clean();
288 + }
289 +
290 + $current_plan = blc_get_capabilities()->get_plan();
291 +
292 + // $current_plan = 'free';
293 +
294 + $retrieve_demos_data = [
295 + ];
296 +
297 + $license = blc_fs()->_get_license();
298 + $site = blc_fs()->get_site();
299 + $has_valid_license = false;
300 +
301 + if ($license && isset($license->id) && $license->id > 1) {
302 + $retrieve_demos_data['license_id'] = $license->id;
303 + $has_valid_license = true;
304 + }
305 + if ($site && isset($site->id) && $site->id > 1) {
306 + $retrieve_demos_data['install_id'] = $site->id;
307 + }
308 +
309 + $result = [
310 + 'is_pro' => $current_plan !== 'free',
311 + 'current_plan' => $current_plan,
312 +
313 + 'pro_starter_sites' => blc_get_capabilities()->get_features()['pro_starter_sites'],
314 + 'pro_starter_sites_enhanced' => blc_get_capabilities()->get_features()['pro_starter_sites_enhanced'],
315 +
316 + 'is_anonymous' => $is_anonymous,
317 + 'connect_template' => $connect_template,
318 + 'retrieve_demos_data' => $retrieve_demos_data,
319 + 'plugin_version' => $plugin_data['Version'],
320 + 'is_multisite' => is_multisite()
321 + ];
322 + }
323 +
324 + if (
325 + Plugin::instance()->premium
326 + &&
327 + is_callable([
328 + Plugin::instance()->premium,
329 + 'user_wants_beta_updates'
330 + ])
331 + ) {
332 + $result['has_beta_consent'] = Plugin::instance()->premium->user_wants_beta_updates();
333 + }
334 +
335 + if (function_exists('blocksy_get_pricing_links')) {
336 + $result['modal_links'] = blocksy_get_pricing_links();
337 + }
338 +
339 + return array_merge($result, $d);
340 + }
341 + );
342 +
343 + add_action('admin_init', function ($plugin) {
344 + if (wp_doing_ajax()) {
345 + return;
346 + }
347 +
348 + if (! is_admin()) {
349 + return;
350 + }
351 +
352 + if (! is_user_logged_in()) {
353 + return;
354 + }
355 +
356 + if (is_network_admin()) {
357 + return;
358 + }
359 +
360 + if (intval(get_option('blc_activation_redirect', false)) === wp_get_current_user()->ID) {
361 + delete_option('blc_activation_redirect');
362 + wp_safe_redirect(admin_url('admin.php?page=ct-dashboard'));
363 + exit;
364 + }
365 + });
366 + }
367 +
368 + public function enqueue_static() {
369 + if (! $this->is_dashboard_page()) {
370 + $this->enqueue_static_global();
371 + return;
372 + }
373 +
374 + $deps = apply_filters('blocksy-dashboard-scripts-dependencies', [
375 + 'wp-i18n',
376 + 'ct-events',
377 + 'ct-options-scripts'
378 + ]);
379 +
380 + if (Plugin::instance()->check_if_blocksy_is_activated()) {
381 + wp_enqueue_script(
382 + 'blocksy-dashboard-scripts',
383 + BLOCKSY_URL . 'static/bundle/dashboard.js',
384 + $deps,
385 + blc_get_version(),
386 + false
387 + );
388 +
389 + $inline_patch = <<<'JS'
390 + (function() {
391 + const origFetch = window.fetch;
392 + window.fetch = function(url, options) {
393 + if (typeof url === 'string' && url.includes('startersites.io')) {
394 + const urlObj = new URL(url);
395 + const licenseId = urlObj.searchParams.get('license_id');
396 + if (urlObj.searchParams.has('is_pro') && (!licenseId || licenseId <= 1)) {
397 + urlObj.searchParams.delete('is_pro');
398 + url = urlObj.toString();
399 + }
400 + }
401 + return origFetch.call(this, url, options);
402 + };
403 + })();
404 + JS;
405 + wp_add_inline_script('blocksy-dashboard-scripts', $inline_patch, 'before');
406 + } else {
407 + wp_enqueue_script(
408 + 'blocksy-dashboard-scripts',
409 + BLOCKSY_URL . 'static/bundle/dashboard-no-theme.js',
410 + [
411 + 'underscore',
412 + 'react',
413 + 'react-dom',
414 + 'wp-element',
415 + 'wp-date',
416 + 'wp-i18n',
417 + 'wp-util'
418 + ],
419 + blc_get_version(),
420 + false
421 + );
422 +
423 + $slug = 'blocksy';
424 +
425 + $theme_activate_url = null;
426 + $theme_activate_url_multi_site = null;
427 +
428 + if (current_user_can('switch_themes')) {
429 + if (is_multisite()) {
430 + $theme_activate_url_multi_site = add_query_arg(
431 + [
432 + 'action' => 'enable',
433 + '_wpnonce' => wp_create_nonce('enable-theme_' . $slug),
434 + 'theme' => $slug
435 + ],
436 + network_admin_url('themes.php')
437 + );
438 + }
439 +
440 + $theme_activate_url = add_query_arg(
441 + [
442 + 'action' => 'activate',
443 + '_wpnonce' => wp_create_nonce('switch-theme_' . $slug),
444 + 'stylesheet' => $slug,
445 + ],
446 + admin_url('themes.php')
447 + );
448 + }
449 +
450 + $localize_data = [
451 + 'themeIsInstalled' => (
452 + !! wp_get_theme($slug)
453 + &&
454 + ! wp_get_theme($slug)->errors()
455 + ),
456 + 'updatesNonce' => wp_installing() ? '' : wp_create_nonce('updates'),
457 + 'activate_multi_site' => $theme_activate_url_multi_site,
458 + 'activate'=> $theme_activate_url
459 + ];
460 +
461 + $blocksy_data = Plugin::instance()->is_blocksy_data;
462 +
463 + if ($blocksy_data && $blocksy_data['is_correct_theme']) {
464 + $mismatched_product_name = 'Blocksy theme';
465 + $mismatched_product_slug = 'blocksy';
466 +
467 + if (
468 + $blocksy_data['is_theme_version_ok']
469 + &&
470 + ! $blocksy_data['is_companion_version_ok']
471 + ) {
472 + $mismatched_product_name = 'Blocksy Companion plugin';
473 + $mismatched_product_slug = 'blocksy-companion';
474 +
475 + if (blc_can_use_premium_code()) {
476 + $mismatched_product_name = 'Blocksy Companion Pro plugin';
477 + $mismatched_product_slug = 'blocksy-companion-pro';
478 + }
479 + }
480 +
481 + $localize_data['theme_version_mismatch'] = [
482 + 'productName' => $mismatched_product_name,
483 + 'slug' => $mismatched_product_slug
484 + ];
485 + }
486 +
487 + wp_localize_script(
488 + 'blocksy-dashboard-scripts',
489 + 'ctDashboardLocalizations',
490 + $localize_data
491 + );
492 +
493 + wp_dequeue_style('ct-dashboard-styles');
494 + }
495 +
496 + wp_enqueue_style(
497 + 'blocksy-dashboard-styles',
498 + BLOCKSY_URL . 'static/bundle/dashboard.min.css',
499 + ['wp-components'],
500 + blc_get_version()
501 + );
502 + }
503 +
504 + public function enqueue_static_global() {
505 + $slug = 'blocksy';
506 +
507 + $themeIsInstalled = (
508 + !! wp_get_theme($slug)
509 + &&
510 + ! wp_get_theme($slug)->errors()
511 + );
512 +
513 + $blocksy_data = Plugin::instance()->is_blocksy_data;
514 +
515 + if (
516 + ! Plugin::instance()->check_if_blocksy_is_activated()
517 + &&
518 + $blocksy_data
519 + &&
520 + $blocksy_data['is_correct_theme']
521 + ) {
522 + wp_enqueue_style(
523 + 'blocksy-dashboard-styles',
524 + BLOCKSY_URL . 'static/bundle/dashboard.min.css',
525 + [],
526 + blc_get_version()
527 + );
528 +
529 + wp_enqueue_script(
530 + 'blocksy-admin-notifications-scripts',
531 + BLOCKSY_URL . 'static/bundle/notifications.js',
532 + [
533 + 'underscore',
534 + 'react',
535 + 'react-dom',
536 + 'wp-element',
537 + 'wp-date',
538 + 'wp-i18n'
539 + ],
540 + blc_get_version(),
541 + false
542 + );
543 +
544 + wp_localize_script(
545 + 'blocksy-admin-notifications-scripts',
546 + 'ctDashboardLocalizations',
547 + [
548 + 'updatesNonce' => wp_installing() ? '' : wp_create_nonce('updates'),
549 + ]
550 + );
551 + }
552 + }
553 +
554 + public function get_icon() {
555 + return apply_filters(
556 + 'blocksy:dashboard:icon-url',
557 + 'data:image/svg+xml;base64,PHN2ZyB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB4PSIwcHgiIHk9IjBweCIKCSB2aWV3Qm94PSIwIDAgMzUgMzUiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDM1IDM1OyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+CjxwYXRoIGQ9Ik0yMS42LDIxLjNjMCwwLjYtMC41LDEuMS0xLjEsMS4xaC0zLjVsLTAuOS0yLjJoNC40QzIxLjEsMjAuMiwyMS42LDIwLjcsMjEuNiwyMS4zeiBNMjAuNiwxMy41aC00LjRsMC45LDIuMmgzLjUKCWMwLjYsMCwxLjEtMC41LDEuMS0xLjFDMjEuNiwxNCwyMS4xLDEzLjUsMjAuNiwxMy41eiBNMzUsMTcuNUMzNSwyNy4yLDI3LjIsMzUsMTcuNSwzNUM3LjgsMzUsMCwyNy4yLDAsMTcuNUMwLDcuOCw3LjgsMCwxNy41LDAKCUMyNy4yLDAsMzUsNy44LDM1LDE3LjV6IE0yNSwxNy45YzAuNy0wLjksMS4xLTIuMSwxLjEtMy40YzAtMS4yLTAuNC0yLjQtMS4xLTMuM2MtMS0xLjQtMi42LTIuMy00LjQtMi4zYzAsMC0wLjEsMC0wLjEsMHYwSDkuOQoJYy0wLjMsMC0wLjUsMC4zLTAuNCwwLjVsMi42LDYuMkg5LjljLTAuMywwLTAuNSwwLjMtMC40LDAuNUwxNCwyNi45aDYuNWMzLjEsMCw1LjYtMi41LDUuNi01LjZDMjYuMiwyMCwyNS44LDE4LjksMjUsMTcuOQoJQzI1LjEsMTcuOSwyNS4xLDE3LjksMjUsMTcuOXoiLz4KPC9zdmc+Cg=='
558 + );
559 + }
560 +
561 + public function setup_framework_page() {
562 + if (! current_user_can(blc_get_capabilities()->get_wp_capability_by('dashboard'))) {
563 + return;
564 + }
565 +
566 + $options = [
567 + 'title' => __('Blocksy', 'blocksy-companion'),
568 + 'menu-title' => __('Blocksy', 'blocksy-companion'),
569 + 'permision' => blc_get_capabilities()->get_wp_capability_by('dashboard'),
570 + 'top-level-handle' => 'ct-dashboard',
571 + 'callback' => [$this, 'welcome_page_template'],
572 + 'icon-url' => $this->get_icon(),
573 + 'position' => 2,
574 + ];
575 +
576 + add_menu_page(
577 + $options['title'],
578 + $options['menu-title'],
579 + $options['permision'],
580 + $options['top-level-handle'],
581 + $options['callback'],
582 + $options['icon-url'],
583 + 2
584 + );
585 + }
586 +
587 + public function is_dashboard_page() {
588 + global $pagenow;
589 +
590 + if (is_network_admin()) {
591 + $is_ct_settings =
592 + // 'themes.php' === $pagenow &&
593 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
594 + isset( $_GET['page'] ) && 'blocksy-companion' === $_GET['page'];
595 +
596 + return $is_ct_settings;
597 + }
598 +
599 + $is_ct_settings =
600 + // 'themes.php' === $pagenow &&
601 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended
602 + isset( $_GET['page'] ) && 'ct-dashboard' === $_GET['page'];
603 +
604 + return $is_ct_settings;
605 + }
606 +
607 + public function welcome_page_template() {
608 + if (! current_user_can(blc_get_capabilities()->get_wp_capability_by('dashboard'))) {
609 + wp_die(
610 + esc_html(
611 + __( 'You do not have sufficient permissions to access this page.', 'blocksy-companion' )
612 + )
613 + );
614 + }
615 +
616 + echo '<div id="ct-dashboard"></div>';
617 + }
618 + }
619 +
620 + if (! function_exists('blocksy_render_view')) {
621 + function blocksy_render_view(
622 + $file_path,
623 + $view_variables = [],
624 + $default_value = ''
625 + ) {
626 + if (! is_file($file_path)) {
627 + return $default_value;
628 + }
629 +
630 + // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
631 + extract($view_variables, EXTR_REFS);
632 + unset($view_variables);
633 +
634 + ob_start();
635 + require $file_path;
636 +
637 + return ob_get_clean();
638 + }
639 + }
640 +
641 + if (! function_exists('blocksy_render_view_e')) {
642 + function blocksy_render_view_e($file_path, $view_variables = [], $default_value = '') {
643 + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
644 + echo blocksy_render_view($file_path, $view_variables, $default_value);
645 + }
646 + }
647 +