tenweb-speed-optimizer
Last commit date
assets
11 months ago
config
2 years ago
exported
4 years ago
includes
2 months ago
test
4 years ago
vendor
1 month ago
views
11 months ago
.editorconfig
3 years ago
OptimizerAdmin.php
1 year ago
OptimizerAdminBar.php
2 years ago
OptimizerApi.php
1 month ago
OptimizerCli.php
1 year ago
OptimizerDataRepository.php
1 year ago
changelog.txt
3 years ago
config.php
1 month ago
env.php
1 month ago
phpcs.xml
3 years ago
readme.txt
1 month ago
tenweb_speed_optimizer.php
1 month ago
webpack.config.js
3 years ago
OptimizerAdminBar.php
992 lines
| 1 | <?php |
| 2 | |
| 3 | namespace TenWebOptimizer; |
| 4 | |
| 5 | /** |
| 6 | * Class OptimizerAdminBar |
| 7 | */ |
| 8 | class OptimizerAdminBar |
| 9 | { |
| 10 | /* 1 - active and connected, 2 - test mode, 3 - disconnected, 4 - pro case, 5 - abandoned, 6 - connection issues */ |
| 11 | public $two_booster_status = 1; |
| 12 | |
| 13 | /* Total pages count */ |
| 14 | public $total_pages_count; |
| 15 | |
| 16 | /* Not optimized pages count */ |
| 17 | public $notoptimized_pages_count; |
| 18 | |
| 19 | /* Optimized pages count */ |
| 20 | public $optimized_pages_count; |
| 21 | |
| 22 | /* Total count of optimized images */ |
| 23 | public $optimized_images_count; |
| 24 | |
| 25 | /* Total count of images */ |
| 26 | public $total_images_count; |
| 27 | |
| 28 | /* Domain Id */ |
| 29 | private $domain_id; |
| 30 | |
| 31 | /* Workspace Id */ |
| 32 | private $workspace_id; |
| 33 | |
| 34 | /* Booster active and connected */ |
| 35 | public const TWO_CONNECTED = 1; |
| 36 | |
| 37 | /* Booster active and in test mode */ |
| 38 | public const TWO_TEST_MODE = 2; |
| 39 | |
| 40 | /* Booster disconnected */ |
| 41 | public const TWO_DISCONNECTED = 3; |
| 42 | |
| 43 | /* Booster connection issues */ |
| 44 | public const TWO_CONNECTIONISSUES = 6; |
| 45 | |
| 46 | /* Booster is PRO */ |
| 47 | public const TWO_PRO_CONNECTED = 4; |
| 48 | |
| 49 | /* Booster is ABANDONED */ |
| 50 | public const TWO_ABANDONED = 5; |
| 51 | |
| 52 | private $current_plan; |
| 53 | |
| 54 | private $empty_images_count_transient; |
| 55 | |
| 56 | private $referral_hash; |
| 57 | |
| 58 | public $two_frontend; |
| 59 | |
| 60 | public function __construct($wp_admin_bar) |
| 61 | { |
| 62 | $this->referral_hash = get_site_option(TENWEB_PREFIX . '_client_referral_hash'); |
| 63 | global $tenweb_plan_title; |
| 64 | $this->current_plan = !empty($tenweb_plan_title) ? $tenweb_plan_title : 'Free'; //this check is just to be sure that plan_title is set |
| 65 | $this->current_plan = strtolower($this->current_plan) == 'speed' ? 'Free' : $this->current_plan; // just a dirty fix |
| 66 | |
| 67 | if (!is_admin() && !OptimizerUrl::urlIsOptimizable(null, true)) { |
| 68 | return; |
| 69 | } |
| 70 | $this->two_set_data(); |
| 71 | |
| 72 | /* Case when page is frontend and user is Pro*/ |
| 73 | if (!is_admin() && $this->two_booster_status == 4) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | wp_enqueue_style('two_speed_css', TENWEB_SO_URL . '/assets/css/speed.css', ['two-open-sans'], TENWEB_SO_VERSION); |
| 78 | |
| 79 | //add some inline style to have free user's admin bar visible for small screens too |
| 80 | if ($this->two_booster_status == 1) { |
| 81 | $style_for_free_admin_bar = '@media screen and (max-width:1279px) { |
| 82 | #wpadminbar div.two_admin_bar_menu_main { |
| 83 | left: -322px; |
| 84 | } |
| 85 | }'; |
| 86 | wp_add_inline_style('two_speed_css', $style_for_free_admin_bar); |
| 87 | } |
| 88 | wp_enqueue_script('two_circle_js', TENWEB_SO_URL . '/assets/js/circle-progress.js', ['jquery'], TENWEB_SO_VERSION); |
| 89 | wp_enqueue_script('two_speed_js', TENWEB_SO_URL . '/assets/js/speed.js', ['jquery', 'two_circle_js'], TENWEB_SO_VERSION); |
| 90 | wp_localize_script('two_speed_js', 'two_speed', [ |
| 91 | 'nonce' => wp_create_nonce('two_ajax_nonce'), |
| 92 | 'ajax_url' => admin_url('admin-ajax.php'), |
| 93 | 'clearing' => __('Clearing...', 'tenweb-speed-optimizer'), |
| 94 | 'cleared' => __('Cleared cache', 'tenweb-speed-optimizer'), |
| 95 | 'clear' => __('Clear cache', 'tenweb-speed-optimizer'), |
| 96 | ]); |
| 97 | wp_enqueue_script( |
| 98 | 'two_referral_program_js', |
| 99 | TENWEB_SO_URL . '/assets/js/referral_program.js', |
| 100 | ['jquery'], |
| 101 | TENWEB_SO_VERSION |
| 102 | ); |
| 103 | |
| 104 | $wp_admin_bar->add_menu([ |
| 105 | 'id' => 'two_adminbar_info', |
| 106 | 'title' => $this->two_admin_menu(), |
| 107 | 'meta' => [ |
| 108 | 'html' => $this->two_admin_bar_menu_content(), |
| 109 | ], |
| 110 | ]); |
| 111 | |
| 112 | if (is_admin()) { |
| 113 | $wp_admin_bar->add_menu([ |
| 114 | 'id' => 'two_adminbar_progress_info', |
| 115 | 'title' => $this->two_admin_notif_menu(), |
| 116 | 'meta' => [ |
| 117 | 'html' => $this->two_optimize_notification(), |
| 118 | ], |
| 119 | ]); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | /** |
| 124 | * Set values to class variables. |
| 125 | */ |
| 126 | public function two_set_data() |
| 127 | { |
| 128 | if (is_admin()) { |
| 129 | $this->two_frontend = 0; |
| 130 | } |
| 131 | $this->optimized_pages_count = count(\TenWebOptimizer\OptimizerUtils::getCriticalPages()); |
| 132 | $count_pages = wp_count_posts('page'); |
| 133 | $count_posts = wp_count_posts('post'); |
| 134 | $terms_count = (int) get_terms(['fields' => 'count', 'hide_empty' => false]); |
| 135 | $this->total_pages_count = $count_pages->publish + $count_posts->publish + $terms_count; |
| 136 | |
| 137 | if ($this->optimized_pages_count > $this->total_pages_count) { |
| 138 | $this->optimized_pages_count = $this->total_pages_count; |
| 139 | } |
| 140 | $this->notoptimized_pages_count = $this->total_pages_count - $this->optimized_pages_count; |
| 141 | $this->workspace_id = (int) get_site_option(TENWEBIO_MANAGER_PREFIX . '_workspace_id', 0); |
| 142 | $this->domain_id = (int) get_option(TENWEBIO_MANAGER_PREFIX . '_domain_id', 0); |
| 143 | |
| 144 | $two_settings = get_option('two_settings'); |
| 145 | $two_settings = json_decode($two_settings, 1); |
| 146 | $this->two_booster_status = self::TWO_DISCONNECTED; |
| 147 | |
| 148 | if ((\Tenweb_Authorization\Login::get_instance()->check_logged_in() && $this->domain_id == 0) |
| 149 | || (!\Tenweb_Authorization\Login::get_instance()->check_logged_in() && !empty(get_option('two_first_connect')) && $this->domain_id != 0)) { |
| 150 | $this->two_booster_status = self::TWO_CONNECTIONISSUES; |
| 151 | } elseif ((defined('TWO_INCOMPATIBLE_ERROR') && TWO_INCOMPATIBLE_ERROR) || !OptimizerUtils::is_tenweb_booster_connected()) { |
| 152 | $this->two_booster_status = self::TWO_DISCONNECTED; |
| 153 | } elseif (\TenWebOptimizer\OptimizerUtils::is_paid_user()) { |
| 154 | $this->two_booster_status = self::TWO_PRO_CONNECTED; |
| 155 | } elseif (!empty($two_settings)) { |
| 156 | if (isset($two_settings['two_test_mode']) && $two_settings['two_test_mode'] == 'on') { |
| 157 | $this->two_booster_status = self::TWO_TEST_MODE; |
| 158 | } elseif (isset($two_settings['two_connected']) && $two_settings['two_connected'] == 1) { |
| 159 | $two_flow_finished = get_option('two_flow_status') != 1 ? true : false; |
| 160 | |
| 161 | if (!$two_flow_finished) { |
| 162 | $this->two_booster_status = self::TWO_ABANDONED; |
| 163 | } else { |
| 164 | $this->two_booster_status = self::TWO_CONNECTED; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | if ($this->two_booster_status != 3 && $this->two_booster_status != 2) { |
| 170 | $this->get_images_data_api(); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Admin bar menu. |
| 176 | * |
| 177 | * @return string |
| 178 | */ |
| 179 | public function two_admin_menu() |
| 180 | { |
| 181 | if (!is_admin() && $this->two_booster_status != 3 && $this->two_booster_status != 2) { |
| 182 | $img = '<img src="' . TENWEB_SO_URL . '/assets/images/logo_green.svg" />'; |
| 183 | $img_display_none = '<img src="' . TENWEB_SO_URL . '/assets/images/logo_green.svg" / style="display:none">'; |
| 184 | $className = ' two_frontpage_not_optimized'; |
| 185 | |
| 186 | if ($this->two_is_page_optimized()) { |
| 187 | $className = ' two_frontpage_optimized'; |
| 188 | } |
| 189 | $two_admin_bar_menu = '<div class="two_admin_bar_menu two_frontend"><div class="two_admin_bar_menu_header' . $className . '"><span class="two_hidden"></span>' . $img . TWO_SO_ORGANIZATION_NAME . ' Booster' . '</div></div>'; |
| 190 | |
| 191 | if ($this->two_is_optimize_inprogress()) { |
| 192 | $className = ' two_frontpage_optimizing'; |
| 193 | $two_admin_bar_menu = '<div class="two_admin_bar_menu two_frontend"><div class="two_admin_bar_menu_header' . $className . '"><span></span>' . $img_display_none . TWO_SO_ORGANIZATION_NAME . ' Booster' . '</div></div>'; |
| 194 | } |
| 195 | } else { |
| 196 | if ($this->two_booster_status == 1) { |
| 197 | $img = '<img src="' . TENWEB_SO_URL . '/assets/images/logo_green.svg" />' . TWO_SO_ORGANIZATION_NAME . ' Booster' . '<p class="two_page_count">' . $this->notoptimized_pages_count . '</p>'; |
| 198 | } elseif ($this->two_booster_status == 4) { |
| 199 | $img = '<img src="' . TENWEB_SO_URL . '/assets/images/logo_green.svg" />' . TWO_SO_ORGANIZATION_NAME . ' Booster'; |
| 200 | } else { |
| 201 | $img = '<img src="' . TENWEB_SO_URL . '/assets/images/logo_disconnect.svg" />' . TWO_SO_ORGANIZATION_NAME . ' Booster'; |
| 202 | } |
| 203 | $two_admin_bar_menu = '<div class="two_admin_bar_menu two_backend"><div class="two_admin_bar_menu_header">' . $img . '</div></div>'; |
| 204 | } |
| 205 | |
| 206 | return $two_admin_bar_menu; |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * Admin bar notif menu. |
| 211 | * |
| 212 | * @return string |
| 213 | */ |
| 214 | public function two_admin_notif_menu() |
| 215 | { |
| 216 | if ($this->two_booster_status == 1) { |
| 217 | $two_admin_bar_menu = '<div class="two_admin_bar_notif_menu two_backend"><div class="two_admin_bar_menu_header"><span></span></div></div>'; |
| 218 | |
| 219 | return $two_admin_bar_menu; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Adminbar menu content. |
| 225 | * |
| 226 | * @return string |
| 227 | */ |
| 228 | public function two_admin_bar_menu_content() |
| 229 | { |
| 230 | $front_score_data = get_option('two-front-page-speed'); |
| 231 | |
| 232 | $optimized_images_count = $this->optimized_images_count; |
| 233 | $total_images_count = $this->total_images_count; |
| 234 | $rest_page_count = (int) (6 - $this->optimized_pages_count); |
| 235 | |
| 236 | $free_reached = 1; |
| 237 | |
| 238 | if ($this->optimized_pages_count < 6) { |
| 239 | $free_reached = 0; |
| 240 | } |
| 241 | $post_id = get_option('page_on_front'); |
| 242 | ob_start(); |
| 243 | $reanalyze_button_status_current = false; |
| 244 | |
| 245 | if (!empty($front_score_data)) { |
| 246 | if (isset($front_score_data['current_score']) && isset($front_score_data['current_score']['status']) |
| 247 | && $front_score_data['current_score']['status'] == 'inprogress') { |
| 248 | $reanalyze_button_status_current = true; |
| 249 | } |
| 250 | } |
| 251 | $hidden_class = TW_OPTIMIZE_PREFIX . '_hidden'; |
| 252 | |
| 253 | if ($this->two_booster_status == 6 && !get_option(TW_OPTIMIZE_PREFIX . '_reconnection_bar_was_shown')) { |
| 254 | $hidden_class = ''; |
| 255 | } ?> |
| 256 | <div class="two_admin_bar_menu_main <?php echo esc_attr($hidden_class); ?>" dir="ltr"> |
| 257 | <?php |
| 258 | /* Frontend and booster is not disconnected or in test mode or has some connection issues */ |
| 259 | if (!is_admin() && $this->two_booster_status != 3 && $this->two_booster_status != 6 && $this->two_booster_status != 2) { |
| 260 | if (!$this->two_is_page_optimized()) { |
| 261 | $this->two_front_not_optimized_content(); |
| 262 | } else { |
| 263 | $this->two_front_optimized_content(); |
| 264 | } |
| 265 | } else { |
| 266 | if ($this->two_booster_status == 1) { |
| 267 | ?> |
| 268 | <div class="two_admin_bar_menu_content two_booster_on_free two-any-reanalyzing-score-section" data-id="front_page"> |
| 269 | <p class="two_info_row"><?php echo esc_html(sprintf(__('Not optimized pages: %s', 'tenweb-speed-optimizer'), (int) $this->notoptimized_pages_count)); ?></p> |
| 270 | <p class="two_status_title"><?php echo esc_html(sprintf(__('%s is ON', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME . ' Booster')); ?></p> |
| 271 | <div class="two_plan_container"> |
| 272 | <p><?php echo sprintf(__('Current Plan: %s', 'tenweb-speed-optimizer'), esc_html($this->current_plan)); ?></p> |
| 273 | <a href="#" class="two_clear_cache"><?php _e('Clear cache', 'tenweb-speed-optimizer'); ?></a> |
| 274 | </div> |
| 275 | <hr> |
| 276 | |
| 277 | <div class="two_score_success_container"> |
| 278 | <div class="two_score_title_container"> |
| 279 | <p class="two_score_title"><?php _e('Your optimized homepage score:', 'tenweb-speed-optimizer'); ?></p> |
| 280 | <div class="two_reanalyze_container"> |
| 281 | <span class="two-page-speed two-optimizing <?php echo $reanalyze_button_status_current ? '' : 'two-hidden'; ?>"></span> |
| 282 | <a onclick="two_reanalyze_score(this)" data-from-wp-admin="1" data-post_id="front_page" |
| 283 | data-initiator="admin-bar" class="two_reanalyze_button"> |
| 284 | <?php $reanalyze_button_status_current ? _e('Reanalyzing...', 'tenweb-speed-optimizer') : _e('Reanalyze', 'tenweb-speed-optimizer'); ?> |
| 285 | </a> |
| 286 | </div> |
| 287 | </div> |
| 288 | <?php $this->two_score_circles($front_score_data, 'front_page'); ?> |
| 289 | |
| 290 | <div class="two_pages_count_info <?php echo esc_attr($free_reached) ? 'two_free_reached' : ''; ?>"> |
| 291 | <p> |
| 292 | <?php |
| 293 | if (!$free_reached) { |
| 294 | echo sprintf(__('Optimize %s more pages within the Free Plan limit.', 'tenweb-speed-optimizer'), (int) $rest_page_count); |
| 295 | } else { |
| 296 | _e('You have reached the Free plan limit.', 'tenweb-speed-optimizer'); ?> |
| 297 | </p> |
| 298 | <p><?php _e('6 of 6', 'tenweb-speed-optimizer'); ?></p> |
| 299 | <div class="two_red_counter_line"></div> |
| 300 | <?php |
| 301 | } ?> |
| 302 | </div> |
| 303 | </div> |
| 304 | <div class="two_optimized_pages_info"> |
| 305 | <p><?php _e('Optimized pages', 'tenweb-speed-optimizer'); ?></p> |
| 306 | <p><?php echo sprintf(__('%s of %s', 'tenweb-speed-optimizer'), (int) $this->optimized_pages_count, (int) $this->total_pages_count); ?></p> |
| 307 | </div> |
| 308 | <div class="two_optimized_images_info"> |
| 309 | <p><?php _e('Optimized images', 'tenweb-speed-optimizer'); ?></p> |
| 310 | <?php if (empty($optimized_images_count) && empty($total_images_count)) { ?> |
| 311 | <p class="<?php echo esc_attr($this->empty_images_count_transient); ?>"><?php _e('0', 'tenweb-speed-optimizer'); ?></p> |
| 312 | <?php } else { ?> |
| 313 | <p><?php echo sprintf(__('%s of %s', 'tenweb-speed-optimizer'), (int) $optimized_images_count, (int) $total_images_count); ?></p> |
| 314 | <?php } ?> |
| 315 | </div> |
| 316 | <?php if (!$free_reached) { |
| 317 | $url = admin_url('edit.php?post_type=page'); ?> |
| 318 | <a href="<?php echo esc_url($url); ?>" class="two_add_page_button"><?php _e('Optimize more pages', 'tenweb-speed-optimizer'); ?></a> |
| 319 | <?php |
| 320 | } ?> |
| 321 | </div> |
| 322 | <?php |
| 323 | $checkout_url = TENWEB_DASHBOARD . '/websites/' . $this->domain_id . '/booster/pro'; |
| 324 | $current_ts = time(); |
| 325 | $deadline_ts = mktime(0, 0, 0, 11, 29, 2022); |
| 326 | $black_friday_on = true; |
| 327 | |
| 328 | if ($current_ts > $deadline_ts) { |
| 329 | $black_friday_on = false; |
| 330 | } |
| 331 | |
| 332 | if ($black_friday_on) { |
| 333 | $black_friday_upgrade_button = trim(TENWEB_DASHBOARD, '/') . '/upgrade-plan' |
| 334 | . '?from_plugin=' . \TenWebOptimizer\OptimizerUtils::FROM_PLUGIN . '?two_comes_from=adminBarAfterLimit'; |
| 335 | $black_friday_total_pages = (int) $this->total_pages_count; |
| 336 | $black_friday_total_images = (int) $total_images_count; ?> |
| 337 | <div class="two_pro_container two_black_friday_offer"> |
| 338 | <?php require __DIR__ . '/views/two_black_friday.php'; ?> |
| 339 | </div> |
| 340 | <?php |
| 341 | } else { |
| 342 | ?> |
| 343 | <div> |
| 344 | <div class="two_pro_container"> |
| 345 | <p class="two_pro_container_title"><?php _e('Achieve more with Booster Pro', 'tenweb-speed-optimizer'); ?></p> |
| 346 | <p class="two_pro_option two_pro_option_diamond"><?php echo sprintf(__('Auto-optimize all %s pages and %s images', 'tenweb-speed-optimizer'), (int) $this->total_pages_count, (int) $total_images_count); ?></p> |
| 347 | <p class="two_pro_option two_pro_option_diamond"><?php _e('Pro optimization with Cloudflare CDN', 'tenweb-speed-optimizer'); ?></p> |
| 348 | <p class="two_pro_option"><?php _e('50% faster load times', 'tenweb-speed-optimizer'); ?></p> |
| 349 | <p class="two_pro_option"><?php _e('30% higher PageSpeed score', 'tenweb-speed-optimizer'); ?></p> |
| 350 | <p class="two_pro_option"><?php _e('275 caching locations worldwide', 'tenweb-speed-optimizer'); ?></p> |
| 351 | <div class="two_pages_count_info two_agency_plan_intro"> |
| 352 | <p><?php _e('Introducing our new Agency plan:', 'tenweb-speed-optimizer'); ?></p> |
| 353 | <p><?php _e('Optimize unlimited number of websites.', 'tenweb-speed-optimizer'); ?></p> |
| 354 | </div> |
| 355 | <a href="<?php echo esc_url($checkout_url . '?two_comes_from=adminBarAfterLimit'); ?>" target="_blank" class="two_add_page_button"><?php _e('Upgrade', 'tenweb-speed-optimizer'); ?></a> |
| 356 | </div> |
| 357 | </div> |
| 358 | <?php |
| 359 | } |
| 360 | } elseif ($this->two_booster_status == 2) { |
| 361 | $this->two_booster_testmode_content(); |
| 362 | } elseif ($this->two_booster_status == 3) { |
| 363 | $this->two_booster_disconnect_content(); |
| 364 | } elseif ($this->two_booster_status == 6) { |
| 365 | $this->two_booster_reonnect_content(); |
| 366 | } elseif ($this->two_booster_status == 4) { |
| 367 | $this->two_booster_pro_content(); |
| 368 | } elseif ($this->two_booster_status == 5) { |
| 369 | $this->two_booster_abandoned_content(); |
| 370 | } |
| 371 | } ?> |
| 372 | </div> |
| 373 | <?php |
| 374 | return ob_get_clean(); |
| 375 | } |
| 376 | |
| 377 | /* Adminbar menu content in case of booster disconnected */ |
| 378 | public function two_booster_disconnect_content() |
| 379 | { |
| 380 | $care_url = TENWEB_DASHBOARD . '/websites/?open=livechat'; |
| 381 | |
| 382 | if (!\TenWebOptimizer\OptimizerUtils::is_paid_user()) { |
| 383 | $care_url = '#'; |
| 384 | add_action('admin_footer', function () { |
| 385 | $this->two_contact_care_popup(); |
| 386 | }); |
| 387 | add_action('wp_footer', function () { |
| 388 | $this->two_contact_care_popup(); |
| 389 | }); |
| 390 | } ?> |
| 391 | <div class="two_admin_bar_menu_content two_booster_disconnect"> |
| 392 | <p class="two_status_title"><?php echo esc_html(sprintf(__('%s is disconnected', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME . ' Booster')); ?></p> |
| 393 | <p><?php echo esc_html(sprintf(__('Your website is disconnected from %s service.', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME . ' Booster')); ?></p> |
| 394 | <p><?php |
| 395 | esc_html_e('Please reconnect your website or ', 'tenweb-speed-optimizer'); ?> |
| 396 | <a href="<?php echo esc_url($care_url); ?>" class="two-open-contact-care-team" target="_blank"> |
| 397 | <?php esc_html_e('contact our Customer Care Team', 'tenweb-speed-optimizer'); ?></a> |
| 398 | <?php esc_html_e(' for further assistance.', 'tenweb-speed-optimizer'); ?></p> |
| 399 | </div> |
| 400 | <?php |
| 401 | } |
| 402 | |
| 403 | /* Adminbar menu content in case of booster needs reconnect */ |
| 404 | public function two_booster_reonnect_content() |
| 405 | { |
| 406 | $two_disconnect_nonce = wp_create_nonce('two_disconnect_nonce'); |
| 407 | $two_reconnect_nonce = wp_create_nonce('two_reconnect_nonce'); |
| 408 | $query_args['two_disconnect'] = 1; |
| 409 | $query_args['two_reconnect'] = 1; |
| 410 | $query_args['two_reconnect_nonce'] = $two_reconnect_nonce; |
| 411 | $query_args['nonce'] = $two_disconnect_nonce; |
| 412 | $reconnect_link = add_query_arg( |
| 413 | $query_args, |
| 414 | get_admin_url() . 'admin.php?page=two_settings_page' |
| 415 | ); |
| 416 | update_option(TW_OPTIMIZE_PREFIX . '_reconnection_bar_was_shown', 1, false); ?> |
| 417 | <div class="two_admin_bar_menu_content two_booster_disconnect"> |
| 418 | <p class="two_status_title"><?php echo esc_html(sprintf(__('%s is disconnected', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME . ' Booster')); ?></p> |
| 419 | <p><?php echo wp_kses_post(sprintf(__('Looks like there might be some problems with<br> the %s connection.', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME . ' Booster')); ?></p> |
| 420 | <p><?php |
| 421 | echo esc_html(sprintf(__('Reconnect to %s to take full advantage of its features.', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME)); ?> |
| 422 | </p> |
| 423 | <a href="<?php echo esc_url($reconnect_link); ?>" class="two_add_page_button two_button_small"><?php _e('Reconnect', 'tenweb-speed-optimizer'); ?></a> |
| 424 | </div> |
| 425 | <?php |
| 426 | } |
| 427 | |
| 428 | private function two_contact_care_popup() |
| 429 | { |
| 430 | $main_class = 'two-contact-care-popup-main two-hidden'; |
| 431 | $close_icon = true; |
| 432 | require_once __DIR__ . '/views/customer_support.php'; |
| 433 | customer_care_html($main_class, $close_icon); |
| 434 | } |
| 435 | |
| 436 | /* Adminbar menu content in case of booster active in test mode */ |
| 437 | public function two_booster_testmode_content() |
| 438 | { |
| 439 | $settings_url = TENWEB_DASHBOARD . '/websites/' . $this->domain_id . '/booster/frontend?tab=settings'; ?> |
| 440 | <div class="two_admin_bar_menu_content two_booster_test"> |
| 441 | <p class="two_status_title"><?php echo esc_html(sprintf(__('%s is in Test mode', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME . ' Booster')); ?></p> |
| 442 | <p><?php echo wp_kses_post(sprintf(__('Test mode temporarily disables %s <br>for website visitors.', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME . ' Booster')); ?></p> |
| 443 | <p><?php _e('Go to 10Web dashboard to manage Test mode settings and preview optimization levels.', 'tenweb-speed-optimizer'); ?></p> |
| 444 | <a href="<?php echo esc_url($settings_url); ?>" target="_blank" class="two_add_page_button"><?php _e('Manage settings', 'tenweb-speed-optimizer'); ?></a> |
| 445 | </div> |
| 446 | <?php |
| 447 | } |
| 448 | |
| 449 | /* Adminbar if booster plugin is PRO content */ |
| 450 | public function two_booster_pro_content() |
| 451 | { |
| 452 | $front_score_data = get_option('two-front-page-speed'); |
| 453 | $db_cloudflare_page = TENWEB_DASHBOARD . '/websites/' . $this->domain_id . '/booster/cloudflare'; |
| 454 | $is_homepage_score = false; |
| 455 | |
| 456 | if (!empty($front_score_data) && isset($front_score_data['current_score']) && isset($front_score_data['current_score']['desktop_score'])) { |
| 457 | $is_homepage_score = true; |
| 458 | } |
| 459 | $reanalyze_button_status_current = false; |
| 460 | |
| 461 | if (!empty($front_score_data)) { |
| 462 | if (isset($front_score_data['current_score']) && isset($front_score_data['current_score']['status']) |
| 463 | && $front_score_data['current_score']['status'] == 'inprogress') { |
| 464 | $reanalyze_button_status_current = true; |
| 465 | } |
| 466 | } ?> |
| 467 | <div class="two_admin_bar_menu_content two_booster_on_free two-any-reanalyzing-score-section" data-id="front_page"> |
| 468 | <?php if (!$is_homepage_score) { ?> |
| 469 | <p class="two_info_row two_success"><?php _e('All pages are optimized', 'tenweb-speed-optimizer'); ?></p> |
| 470 | <?php } ?> |
| 471 | <p class="two_status_title"><?php echo esc_html(sprintf(__('%s is ON', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME . ' Booster')); ?></p> |
| 472 | <div class="two_plan_container"> |
| 473 | <p><?php echo esc_html(__('Current Plan: ' . $this->current_plan, 'tenweb-speed-optimizer')); ?></p> |
| 474 | <a href="#" class="two_clear_cache"><?php _e('Clear cache', 'tenweb-speed-optimizer'); ?></a> |
| 475 | </div> |
| 476 | <hr> |
| 477 | <div class="two_score_title_container"> |
| 478 | <p class="two_score_title"><?php _e('Your optimized homepage score:', 'tenweb-speed-optimizer'); ?></p> |
| 479 | <div class="two_reanalyze_container"> |
| 480 | <span class="two-page-speed two-optimizing <?php echo $reanalyze_button_status_current ? '' : 'two-hidden'; ?>"></span> |
| 481 | <a onclick="two_reanalyze_score(this)" data-from-wp-admin="1" data-post_id="front_page" |
| 482 | data-initiator="admin-bar" class="two_reanalyze_button"> |
| 483 | <?php $reanalyze_button_status_current ? _e('Reanalyzing...', 'tenweb-speed-optimizer') : _e('Reanalyze', 'tenweb-speed-optimizer'); ?> |
| 484 | </a> |
| 485 | </div> |
| 486 | </div> |
| 487 | <?php $this->two_score_circles($front_score_data, 'front_page'); ?> |
| 488 | <div class="two_pages_count_info two_pages_count_all"> |
| 489 | <?php |
| 490 | _e('All pages are optimized', 'tenweb-speed-optimizer'); ?> |
| 491 | </div> |
| 492 | <div class="two_optimized_pages_info"> |
| 493 | <p><?php _e('Optimized pages', 'tenweb-speed-optimizer'); ?></p> |
| 494 | <p><?php echo (int) $this->total_pages_count; ?></p> |
| 495 | </div> |
| 496 | </div> |
| 497 | <?php |
| 498 | global $TwoSettings; |
| 499 | |
| 500 | if (!TENWEB_SO_HOSTED_ON_10WEB && $TwoSettings->get_settings('cloudflare_cache_status') != 'on' |
| 501 | && strtolower(TWO_SO_ORGANIZATION_NAME) === '10web') {?> |
| 502 | <div class="two_pro_container" style="background-image: none;"> |
| 503 | <div class="two-cdn-not-applied"> |
| 504 | <p class="two_pro_container_title"><?php esc_html_e('Pro optimization hasn’t been applied yet', 'tenweb-speed-optimizer'); ?></p> |
| 505 | <p class="two_pro_container_desc"><?php echo wp_kses('You have upgraded to 10Web Booster Pro but<br> haven’t enabled the Pro optimization on your<br> website.', ['br' => []]); ?></p> |
| 506 | </div> |
| 507 | <p class="two_pro_container_title"><?php esc_html_e('Enable CDN to enjoy the benefits:', 'tenweb-speed-optimizer'); ?></p> |
| 508 | <p class="two_pro_option"><?php esc_html_e('30% higher PageSpeed score', 'tenweb-speed-optimizer'); ?></p> |
| 509 | <p class="two_pro_option"><?php esc_html_e('50% faster load times', 'tenweb-speed-optimizer'); ?></p> |
| 510 | <p class="two_pro_option"><?php esc_html_e('275 caching locations worldwide', 'tenweb-speed-optimizer'); ?></p> |
| 511 | <a href="<?php echo esc_url($db_cloudflare_page); ?>" target="_blank" class="two_add_page_button"><?php esc_html_e('Enable', 'tenweb-speed-optimizer'); ?></a> |
| 512 | </div> |
| 513 | <?php |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | /* Frontend Adminbar menu content in case of page not optimized */ |
| 518 | public function two_front_not_optimized_content() |
| 519 | { |
| 520 | global $post; |
| 521 | |
| 522 | if (empty($post)) { |
| 523 | return false; |
| 524 | } |
| 525 | |
| 526 | $post_id = $post->ID; |
| 527 | |
| 528 | $posts_in_progress = $this->two_is_optimize_inprogress(); |
| 529 | |
| 530 | if ($posts_in_progress) { |
| 531 | $this->two_front_optimize_in_progress_content($post_id, true); |
| 532 | } else { |
| 533 | $checkout_url = TENWEB_DASHBOARD . '/websites/' . $this->domain_id . '/booster/pro'; ?> |
| 534 | <div class="two_admin_bar_menu_content two_not_optimized_content"> |
| 535 | <p class="two_status_title"><?php echo esc_html(sprintf(__('Optimize this page with %s', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME . ' Booster')); ?></p> |
| 536 | <p><?php echo esc_html(sprintf(__('We found that this page isn’t optimized with %s.', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME . ' Booster')); ?></p> |
| 537 | <p><?php _e('Get a 90+ PageSpeed score, faster load times and smoother user experience by optimizing this page.', 'tenweb-speed-optimizer'); ?></p> |
| 538 | <a <?php echo ($this->optimized_pages_count >= 6) ? 'href="' . esc_url($checkout_url) . '"' : 'id="two_optimize_now_button"'; ?> data-post-id="<?php echo esc_attr($post_id); ?>" data-initiator="admin-bar" target="_blank" |
| 539 | class="two_add_page_button"><?php _e('Optimize', 'tenweb-speed-optimizer'); ?></a> |
| 540 | </div> |
| 541 | <?php |
| 542 | $this->two_front_optimize_in_progress_content($post_id); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /* Frontend Adminbar menu content in case of page is optimizing */ |
| 547 | public function two_front_optimize_in_progress_content($post_id, $optimize_inprogress = false) |
| 548 | { |
| 549 | ?> |
| 550 | <div class="two_in_progress_cont <?php echo !$optimize_inprogress ? 'two_hidden' : ''; ?>"> |
| 551 | <p class="two_status_title"><?php _e('Optimization in progress…', 'tenweb-speed-optimizer'); ?></p> |
| 552 | <?php |
| 553 | if ($post_id == 'front_page') { |
| 554 | $page_title = 'Homepage'; ?> |
| 555 | <p><?php echo sprintf(__('Your %s is currently being optimized.', 'tenweb-speed-optimizer'), '<span>' . esc_html($page_title) . '</span>'); ?></p> |
| 556 | <?php |
| 557 | } else { |
| 558 | $page_title = get_the_title($post_id); ?> |
| 559 | <p><?php echo sprintf(__('Your %s page is currently being optimized.', 'tenweb-speed-optimizer'), '<span>' . esc_html($page_title) . '</span>'); ?></p> |
| 560 | <?php |
| 561 | } ?> |
| 562 | <p><?php _e('You will receive a notification once optimization is completed.', 'tenweb-speed-optimizer'); ?></p> |
| 563 | </div> |
| 564 | <?php |
| 565 | $this->two_empty_front_optimized_content_template($post_id); |
| 566 | } |
| 567 | |
| 568 | /* Adminbar menu content in case of abandoned optimization */ |
| 569 | public function two_booster_abandoned_content() |
| 570 | { |
| 571 | $abandon_url = home_url() . '?two_setup=1'; ?> |
| 572 | <div class="two_admin_bar_menu_content two_not_optimized_content"> |
| 573 | <p class="two_status_title"><?php _e('Optimization not finished', 'tenweb-speed-optimizer'); ?></p> |
| 574 | <p><?php _e('You haven’t finished optimizing your website,<br> which means no changes were applied to your live site.', 'tenweb-speed-optimizer'); ?></p> |
| 575 | <p><?php _e('Return to the flow to finish the optimization.', 'tenweb-speed-optimizer'); ?></p> |
| 576 | <a href="<?php echo esc_url($abandon_url); ?>" target="_blank" class="two_add_page_button"><?php _e('Finish optimization', 'tenweb-speed-optimizer'); ?></a> |
| 577 | </div> |
| 578 | <?php |
| 579 | } |
| 580 | |
| 581 | /* Frontend Adminbar menu content in case of page is already optimized */ |
| 582 | public function two_front_optimized_content() |
| 583 | { |
| 584 | global $post; |
| 585 | |
| 586 | if (empty($post)) { |
| 587 | return false; |
| 588 | } |
| 589 | |
| 590 | $post_id = $post->ID; |
| 591 | |
| 592 | if (is_front_page()) { |
| 593 | $page_title = __('Homepage', 'tenweb-speed-optimizer'); |
| 594 | } else { |
| 595 | $page_title = get_the_title($post_id); |
| 596 | } |
| 597 | |
| 598 | /* Check home page */ |
| 599 | if (is_front_page()) { |
| 600 | $score_data = get_option('two-front-page-speed'); |
| 601 | $post_id = 'front_page'; |
| 602 | } else { |
| 603 | $score_data = get_post_meta($post_id, 'two_page_speed'); |
| 604 | $score_data = end($score_data); |
| 605 | } |
| 606 | $date = 0; |
| 607 | |
| 608 | if (!empty($score_data) && !isset($score_data['previous_score'])) { |
| 609 | return false; |
| 610 | } elseif (!empty($score_data) && isset($score_data['current_score']) && isset($score_data['current_score']['desktop_score'])) { |
| 611 | $optimized_pages = \TenWebOptimizer\OptimizerUtils::getCriticalPages(); |
| 612 | |
| 613 | if (isset($optimized_pages[$post_id]) && isset($optimized_pages[$post_id]['critical_date'])) { |
| 614 | $date = $optimized_pages[$post_id]['critical_date']; |
| 615 | } elseif (isset($score_data['current_score']['date'])) { |
| 616 | $date = strtotime($score_data['current_score']['date']); |
| 617 | } |
| 618 | } |
| 619 | $modified_date = get_the_modified_date('d.m.Y h:i:s a', $post_id); |
| 620 | $modified_date = strtotime($modified_date); |
| 621 | $posts_in_progress = $this->two_is_optimize_inprogress(); |
| 622 | |
| 623 | if ($posts_in_progress) { |
| 624 | $this->two_front_optimize_in_progress_content($post_id, true); |
| 625 | } else { ?> |
| 626 | <div class="two_admin_bar_menu_content two_optimized two-any-reanalyzing-score-section" data-id="<?php echo esc_attr($post_id); ?>"> |
| 627 | <p class="two_status_title"><?php _e('Congrats!', 'tenweb-speed-optimizer'); ?></p> |
| 628 | <div class="two_optimized_congrats_container"> |
| 629 | <p class="two_optimized_congrats_subtitle"> |
| 630 | <span class="two_optimized_congrats_title"><?php echo esc_html($page_title) . ' '; ?></span> |
| 631 | <?php echo esc_html(sprintf( |
| 632 | __(' %s is successfully optimized.', 'tenweb-speed-optimizer'), |
| 633 | (!is_front_page() ? 'page' : '') |
| 634 | )); ?> |
| 635 | </p> |
| 636 | <?php echo wp_kses_post($this->two_check_score_improvement($score_data)); ?> |
| 637 | </div> |
| 638 | <div class="two_score_success_container"> |
| 639 | <?php $this->two_score_circles($score_data, $post_id); ?> |
| 640 | </div> |
| 641 | |
| 642 | <?php if ($modified_date > $date && $date != 0) { ?> |
| 643 | <a id="two_optimize_now_button" data-post-id="<?php echo esc_attr($post_id); ?>" data-initiator="admin-bar" target="_blank" |
| 644 | class="two_add_page_button"><?php _e('Re-optimize', 'tenweb-speed-optimizer'); ?></a> |
| 645 | <?php } ?> |
| 646 | </div> |
| 647 | <?php |
| 648 | $this->two_front_optimize_in_progress_content($post_id); |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | public function two_empty_front_optimized_content_template($post_id) |
| 653 | { |
| 654 | if ($post_id == 'front_page') { |
| 655 | $page_title = 'Homepage'; |
| 656 | } else { |
| 657 | $page_title = get_the_title($post_id); |
| 658 | } ?> |
| 659 | <div class="two_admin_bar_menu_content two_empty_front_optimized_content two_hidden two-any-reanalyzing-score-section" data-id="<?php echo esc_attr($post_id); ?>"> |
| 660 | <p class="two_status_title"><?php _e('Congrats!', 'tenweb-speed-optimizer'); ?></p> |
| 661 | <div class="two_optimized_congrats_container two-any-reanalyzing-score-section" data-id="<?php echo esc_attr($post_id); ?>"> |
| 662 | <p class="two_optimized_congrats_subtitle"> |
| 663 | <span class="two_optimized_congrats_title"><?php echo esc_html($page_title) . ' '; ?></span> |
| 664 | <?php echo esc_html(sprintf( |
| 665 | __(' %s is successfully optimized.', 'tenweb-speed-optimizer'), |
| 666 | (!is_front_page() ? 'page' : '') |
| 667 | )); ?> |
| 668 | </p> |
| 669 | <?php $this->two_check_score_improvement(''); ?> |
| 670 | </div> |
| 671 | <?php $this->two_score_circles([], ''); ?> |
| 672 | </div> |
| 673 | <?php |
| 674 | } |
| 675 | |
| 676 | /* Show notification during the page load if there is optimizing page in progress */ |
| 677 | public function two_optimize_notification() |
| 678 | { |
| 679 | if (is_admin() && $this->two_booster_status == 1) { |
| 680 | if ($this->two_booster_status == 3 || $this->two_booster_status == 2 || $this->two_booster_status == 5) { |
| 681 | return; |
| 682 | } |
| 683 | $data = ['optimized' => [], 'optimizing' => []]; |
| 684 | $post_ids = new \WP_Query([ |
| 685 | 'post_type' => ['page', 'post'], |
| 686 | 'fields' => 'ids', |
| 687 | // phpcs:ignore Squiz.PHP.CommentedOutCode.Found |
| 688 | // 'meta_query' => array( |
| 689 | // array( |
| 690 | // 'key' => 'two_page_speed', |
| 691 | // ), |
| 692 | // ) |
| 693 | ]); |
| 694 | $post_ids = isset($post_ids->posts) ? $post_ids->posts : []; |
| 695 | |
| 696 | $two_optimization_notif_status = get_option('two_optimization_notif_status'); |
| 697 | |
| 698 | foreach ($post_ids as $post_id) { |
| 699 | $page_score = get_post_meta($post_id, 'two_page_speed', true); |
| 700 | $page_title = get_the_title($post_id); |
| 701 | $status = 'optimized'; |
| 702 | $critical_pages = \TenWebOptimizer\OptimizerUtils::getCriticalPages(); |
| 703 | |
| 704 | if (\TenWebWpTransients\OptimizerTransients::get('two_optimize_inprogress_' . $post_id)) { |
| 705 | $status = 'optimizing'; |
| 706 | } elseif (!array_key_exists($post_id, $critical_pages)) { |
| 707 | $status = 'notOptimized'; |
| 708 | } |
| 709 | |
| 710 | if (\TenWebWpTransients\OptimizerTransients::get('two_optimize_inprogress_' . $post_id) |
| 711 | || (isset($two_optimization_notif_status[$post_id]) && $two_optimization_notif_status[$post_id] == 'optimizing')) { |
| 712 | $data['optimizing'][] = [ |
| 713 | 'status' => $status, |
| 714 | 'post_id' => $post_id, |
| 715 | 'post_title' => $page_title, |
| 716 | ]; |
| 717 | } elseif (!empty($page_score) && isset($page_score['current_score']) && isset($page_score['previous_score']) |
| 718 | && isset($two_optimization_notif_status[$post_id]) && $two_optimization_notif_status[$post_id] == 'optimized_not_closed') { |
| 719 | $data['optimized'][] = [ |
| 720 | 'status' => $status, |
| 721 | 'post_id' => $post_id, |
| 722 | 'post_title' => $page_title, |
| 723 | 'mobile_new' => $page_score['current_score']['mobile_score'] ?? '', |
| 724 | 'mobile_loading_time_new' => $page_score['current_score']['mobile_tti'] ?? '', |
| 725 | 'desktop_new' => $page_score['current_score']['desktop_score'] ?? '', |
| 726 | 'desktop_loading_time_new' => $page_score['current_score']['desktop_tti'] ?? '', |
| 727 | 'mobile_old' => $page_score['previous_score']['mobile_score'] ?? '', |
| 728 | 'mobile_loading_time_old' => $page_score['previous_score']['mobile_tti'] ?? '', |
| 729 | 'desktop_old' => $page_score['previous_score']['desktop_score'] ?? '', |
| 730 | 'desktop_loading_time_old' => $page_score['previous_score']['desktop_tti'] ?? '', |
| 731 | ]; |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | if (empty($data['optimized']) && empty($data['optimizing'])) { |
| 736 | return; |
| 737 | } |
| 738 | ob_start(); ?> |
| 739 | <div class="two_admin_bar_menu_main_notif <?php echo empty($data['optimized']) ? 'two_hidden' : ''; ?>"> |
| 740 | <?php |
| 741 | $i = 1; |
| 742 | |
| 743 | foreach ($data['optimized'] as $optimized) { |
| 744 | $score_data = [ |
| 745 | 'previous_score' => [ |
| 746 | 'mobile_score' => $optimized['mobile_old'], |
| 747 | 'mobile_tti' => $optimized['mobile_loading_time_old'], |
| 748 | 'desktop_score' => $optimized['desktop_old'], |
| 749 | 'desktop_tti' => $optimized['desktop_loading_time_old'], |
| 750 | ], |
| 751 | 'current_score' => [ |
| 752 | 'mobile_score' => $optimized['mobile_new'], |
| 753 | 'mobile_tti' => $optimized['mobile_loading_time_new'], |
| 754 | 'desktop_score' => $optimized['desktop_new'], |
| 755 | 'desktop_tti' => $optimized['desktop_loading_time_new'] |
| 756 | ], |
| 757 | ]; ?> |
| 758 | <div class="two_admin_bar_menu_content two_optimized"> |
| 759 | <span class="two_admin_bar_menu_main_notif_optimized_close" data-post_id="<?php echo esc_attr($optimized['post_id']); ?>"></span> |
| 760 | <div class="two_optimized_cont two-any-reanalyzing-score-section" data-id="<?php echo esc_attr($optimized['post_id']); ?>"> |
| 761 | <div class="two_optimized_congrats_row"> |
| 762 | <p class="two_status_title"><?php _e('Congrats!', 'tenweb-speed-optimizer'); ?></p> |
| 763 | <?php if (count($data['optimized']) > 1) { ?> |
| 764 | <span class="two_arrow <?php echo ($i == 1) ? 'two_up_arrow' : 'two_down_arrow'; ?>"></span> |
| 765 | <?php } ?> |
| 766 | </div> |
| 767 | <div class="two_optimized_congrats_container"> |
| 768 | <p class="two_optimized_congrats_subtitle"> |
| 769 | <span class="two_optimized_congrats_title"><?php echo esc_html($optimized['post_title'] . ' '); ?></span> |
| 770 | <?php echo esc_html(sprintf( |
| 771 | __(' %s is successfully optimized.', 'tenweb-speed-optimizer'), |
| 772 | (!is_front_page() ? 'page' : '') |
| 773 | )); ?> |
| 774 | </p> |
| 775 | <?php echo wp_kses_post($this->two_check_score_improvement($score_data)); ?> |
| 776 | </div> |
| 777 | <div class="two_score_block_container <?php echo ($i == 1) ? '' : 'two_hidden'; ?>"> |
| 778 | <?php |
| 779 | $this->two_score_circles($score_data, $optimized['post_id']); ?> |
| 780 | </div> |
| 781 | </div> |
| 782 | <?php if ($this->referral_hash) { ?> |
| 783 | <div class="two_get_referral_link_admin_bar"> |
| 784 | <p class="two_get_referral_title"> |
| 785 | <img src="<?php echo esc_url(TENWEB_SO_URL . '/assets/images/shape.png'); ?>"> |
| 786 | <?php _e('Refer a friend and receive a $20 credit for the first referral and $10 credit for each additional one.', 'tenweb-speed-optimizer'); ?> |
| 787 | </p> |
| 788 | <a class="two-link-to-wp-referral" href="<?php echo esc_url(admin_url('admin.php?page=two_referral_program')); ?>"> |
| 789 | <?php esc_html_e('Get Referral link', 'tenweb-speed-optimizer'); ?> |
| 790 | </a> |
| 791 | </div> |
| 792 | <?php } ?> |
| 793 | </div> |
| 794 | <?php |
| 795 | $i++; |
| 796 | } ?> |
| 797 | <?php foreach ($data['optimizing'] as $optimizing) { ?> |
| 798 | <div class="two_admin_bar_menu_content two_optimizing_container" data-post_id="<?php echo esc_attr($optimizing['post_id']); ?>"> |
| 799 | <p class="two_optimizing_title"><span></span><?php _e('Optimization in progress…', 'tenweb-speed-optimizer'); ?></p> |
| 800 | <p><?php echo sprintf(__('Your %s page is currently being optimized.', 'tenweb-speed-optimizer'), '<span>' . esc_html($optimizing['post_title']) . '</span>'); ?></p> |
| 801 | </div> |
| 802 | <?php } ?> |
| 803 | </div> |
| 804 | <?php |
| 805 | return ob_get_clean(); |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | /* Get website images total count and optimized images count from endpoint */ |
| 810 | public function get_images_data_api() |
| 811 | { |
| 812 | $two_images_count = \TenWebWpTransients\OptimizerTransients::get('two_images_count'); |
| 813 | |
| 814 | if (!empty($two_images_count)) { |
| 815 | $this->optimized_images_count = $two_images_count['optimized_images_count']; |
| 816 | $this->total_images_count = $two_images_count['total_images_count']; |
| 817 | $this->empty_images_count_transient = ''; |
| 818 | } else { |
| 819 | $this->empty_images_count_transient = 'two-adminBar two_empty_images_count'; |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | /* Check if current frontend page is optimized */ |
| 824 | public function two_is_page_optimized() |
| 825 | { |
| 826 | global $post; |
| 827 | |
| 828 | if (empty($post)) { |
| 829 | return false; |
| 830 | } |
| 831 | $post_id = $post->ID; |
| 832 | |
| 833 | if (is_front_page()) { |
| 834 | $post_id = 'front_page'; |
| 835 | } |
| 836 | $optimized_pages = \TenWebOptimizer\OptimizerUtils::getCriticalPages(); |
| 837 | |
| 838 | if (isset($optimized_pages[$post_id])) { |
| 839 | return true; |
| 840 | } |
| 841 | |
| 842 | return false; |
| 843 | } |
| 844 | |
| 845 | /* Check current page optimization in progress */ |
| 846 | public function two_is_optimize_inprogress() |
| 847 | { |
| 848 | global $post; |
| 849 | |
| 850 | if (empty($post)) { |
| 851 | return false; |
| 852 | } |
| 853 | $post_id = $post->ID; |
| 854 | |
| 855 | if (is_front_page()) { |
| 856 | $post_id = 'front_page'; |
| 857 | } |
| 858 | |
| 859 | if (\TenWebWpTransients\OptimizerTransients::get('two_optimize_inprogress_' . $post_id)) { |
| 860 | return true; |
| 861 | } |
| 862 | |
| 863 | return false; |
| 864 | } |
| 865 | |
| 866 | /* Before and After score template */ |
| 867 | public function two_score_circles($score_data, $post_id) |
| 868 | { |
| 869 | $reanalyze_button_status_previous = false; |
| 870 | $reanalyze_button_status_current = false; |
| 871 | |
| 872 | if (!empty($score_data)) { |
| 873 | if (isset($score_data['current_score']) && isset($score_data['current_score']['status']) |
| 874 | && $score_data['current_score']['status'] == 'inprogress') { |
| 875 | $reanalyze_button_status_current = true; |
| 876 | } |
| 877 | |
| 878 | if (isset($score_data['previous_score']) && isset($score_data['previous_score']['status']) |
| 879 | && $score_data['previous_score']['status'] == 'inprogress') { |
| 880 | $reanalyze_button_status_previous = true; |
| 881 | } |
| 882 | } ?> |
| 883 | <div class="two_score_block"> |
| 884 | <div class="two_score_block_left"> |
| 885 | <p class="two_score_block_title two_score_title_adminbar"><?php _e('Before optimization', 'tenweb-speed-optimizer'); ?></p> |
| 886 | <?php if (empty($score_data) || !isset($score_data['previous_score']) |
| 887 | || !isset($score_data['previous_score']['desktop_score']) || $reanalyze_button_status_previous) { |
| 888 | $no_old_scores = 'two-no-scores'; |
| 889 | } ?> |
| 890 | <div class="two_score_container_both two-old-scores <?php echo isset($no_old_scores) ? esc_html($no_old_scores) : ''; ?>" |
| 891 | data-no-score-for="<?php echo $reanalyze_button_status_previous ? esc_attr($post_id) : ''; ?>"> |
| 892 | <div class="two_score_container two_score_container_mobile_old"> |
| 893 | <div class="two-score-circle" data-score="<?php echo isset($no_old_scores) ? '' : (int) $score_data['previous_score']['mobile_score']; ?>" data-size="30" |
| 894 | data-thickness="2" data-id="mobile"> |
| 895 | <span class="two-score-circle-animated"></span> |
| 896 | </div> |
| 897 | <div class="two_score_info"> |
| 898 | <p><?php _e('Mobile score', 'tenweb-speed-optimizer'); ?></p> |
| 899 | <p><?php _e('Load time: ', 'tenweb-speed-optimizer'); ?> |
| 900 | <span class="two_load_time"><?php echo isset($no_old_scores) ? '' : esc_html($score_data['previous_score']['mobile_tti'] . __('s', 'tenweb-speed-optimizer')); ?></span></p> |
| 901 | </div> |
| 902 | </div> |
| 903 | <div class="two_score_container two_score_container_desktop_old"> |
| 904 | <div class="two-score-circle" data-score="<?php echo isset($no_old_scores) ? '' : (int) $score_data['previous_score']['desktop_score']; ?>" data-size="30" |
| 905 | data-thickness="2" data-id="desktop"> |
| 906 | <span class="two-score-circle-animated"></span> |
| 907 | </div> |
| 908 | <div class="two_score_info"> |
| 909 | <p><?php _e('Desktop score', 'tenweb-speed-optimizer'); ?></p> |
| 910 | <p><?php _e('Load time: ', 'tenweb-speed-optimizer'); ?> |
| 911 | <span class="two_load_time"><?php echo isset($no_old_scores) ? '' : esc_html($score_data['previous_score']['desktop_tti'] . __('s', 'tenweb-speed-optimizer')); ?></span></p> |
| 912 | </div> |
| 913 | </div> |
| 914 | <?php if ($post_id != '') { ?> |
| 915 | <a onclick="<?php echo 'two_reanalyze_score(this)'; ?>" data-from-wp-admin="1" data-post_id="<?php echo esc_attr($post_id); ?>" target="_blank" |
| 916 | data-initiator="admin-bar" class="two_reanalyze_link <?php echo $reanalyze_button_status_previous ? 'two-hidden' : ''; ?>"> |
| 917 | </a> |
| 918 | <span class="two-page-speed two-optimizing <?php echo $reanalyze_button_status_previous ? '' : 'two-hidden'; ?>"></span> |
| 919 | <?php } ?> |
| 920 | </div> |
| 921 | </div> |
| 922 | <div class="two_score_block_right"> |
| 923 | <p class="two_score_block_title two_score_title_adminbar"><?php echo esc_html(sprintf(__('After %s optimization', 'tenweb-speed-optimizer'), TWO_SO_ORGANIZATION_NAME . ' Booster')); ?></p> |
| 924 | <?php if (empty($score_data) || !isset($score_data['current_score']) |
| 925 | || !isset($score_data['current_score']['desktop_score']) || $reanalyze_button_status_current) { |
| 926 | $no_new_scores = 'two-no-scores'; |
| 927 | } ?> |
| 928 | <div class="two_score_container_both two-new-scores <?php echo isset($no_new_scores) ? esc_html($no_new_scores) : ''; ?>" |
| 929 | data-no-score-for="<?php echo $reanalyze_button_status_current ? esc_attr($post_id) : ''; ?>"> |
| 930 | <div class="two_score_container two_score_container_mobile"> |
| 931 | <div class="two-score-circle" data-score="<?php echo isset($no_new_scores) ? '' : (int) $score_data['current_score']['mobile_score']; ?>" data-size="30" |
| 932 | data-thickness="2" data-id="mobile"> |
| 933 | <span class="two-score-circle-animated"></span> |
| 934 | </div> |
| 935 | <div class="two_score_info"> |
| 936 | <p><?php _e('Mobile score', 'tenweb-speed-optimizer'); ?></p> |
| 937 | <p><?php _e('Load time: ', 'tenweb-speed-optimizer'); ?> |
| 938 | <span class="two_load_time"><?php echo isset($no_new_scores) ? '' : esc_html($score_data['current_score']['mobile_tti'] . __('s', 'tenweb-speed-optimizer')); ?></span></p> |
| 939 | </div> |
| 940 | </div> |
| 941 | <div class="two_score_container two_score_container_desktop"> |
| 942 | <div class="two-score-circle" data-score="<?php echo isset($no_new_scores) ? '' : (int) $score_data['current_score']['desktop_score']; ?>" data-size="30" |
| 943 | data-thickness="2" data-id="desktop"> |
| 944 | <span class="two-score-circle-animated"></span> |
| 945 | </div> |
| 946 | <div class="two_score_info"> |
| 947 | <p><?php _e('Desktop score', 'tenweb-speed-optimizer'); ?></p> |
| 948 | <p><?php _e('Load time: ', 'tenweb-speed-optimizer'); ?> |
| 949 | <span class="two_load_time"><?php echo isset($no_new_scores) ? '' : esc_html($score_data['current_score']['desktop_tti'] . __('s', 'tenweb-speed-optimizer')); ?></span></p> |
| 950 | </div> |
| 951 | </div> |
| 952 | <?php if ($post_id != '') { ?> |
| 953 | <a onclick="<?php echo 'two_reanalyze_score(this)'; ?>" data-from-wp-admin="1" data-post_id="<?php echo esc_attr($post_id); ?>" target="_blank" |
| 954 | data-initiator="admin-bar" class="two_reanalyze_link <?php echo $reanalyze_button_status_current ? 'two-hidden' : ''; ?>"> |
| 955 | </a> |
| 956 | <span class="two-page-speed two-optimizing <?php echo $reanalyze_button_status_current ? '' : 'two-hidden'; ?>"></span> |
| 957 | <?php } ?> |
| 958 | </div> |
| 959 | </div> |
| 960 | </div> |
| 961 | <?php |
| 962 | } |
| 963 | |
| 964 | public function two_check_score_improvement($score_data) |
| 965 | { |
| 966 | $improvement_sec = ''; |
| 967 | |
| 968 | if ($score_data == '') { |
| 969 | $improvement_sec = ''; |
| 970 | } else { |
| 971 | if (!empty($score_data) && isset($score_data['current_score']) && isset($score_data['previous_score']) |
| 972 | && isset($score_data['current_score']['desktop_score']) && isset($score_data['previous_score']['desktop_score']) |
| 973 | && (float) $score_data['previous_score']['desktop_score'] != 0 && (float) $score_data['previous_score']['mobile_score'] != 0) { |
| 974 | /* score improvement calculation */ |
| 975 | $desktopScoreImprove = (((float) $score_data['current_score']['desktop_score'] |
| 976 | - (float) $score_data['previous_score']['desktop_score']) / (float) $score_data['previous_score']['desktop_score']) * 100; |
| 977 | $mobileScoreImprove = (((float) $score_data['current_score']['mobile_score'] |
| 978 | - (float) $score_data['previous_score']['mobile_score']) / (float) $score_data['previous_score']['mobile_score']) * 100; |
| 979 | $maxScore = max($desktopScoreImprove, $mobileScoreImprove); |
| 980 | $showImproveBadge = round($maxScore) > 20; |
| 981 | $improvedPercent = round($maxScore) > 20 ? round($maxScore) : 0; |
| 982 | |
| 983 | if ($showImproveBadge) { |
| 984 | $improvement_sec = '<p class="two_optimized_improvement">Improved<span>' . esc_html($improvedPercent) . '%' . '</span></p>'; |
| 985 | } |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | return $improvement_sec; |
| 990 | } |
| 991 | } |
| 992 |