Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/Engine/Plugin/RenewalNotice.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + declare(strict_types=1);
3 +
4 + namespace WP_Rocket\Engine\Plugin;
5 +
6 + use WP_Rocket\Abstract_Render;
7 + use WP_Rocket\Engine\License\API\User;
8 +
9 + class RenewalNotice extends Abstract_Render {
10 + /**
11 + * User instance
12 + *
13 + * @var User
14 + */
15 + private $user;
16 +
17 + /**
18 + * Constructor
19 + *
20 + * @param User $user User instance.
21 + * @param string $template_path Template path.
22 + */
23 + public function __construct( User $user, string $template_path ) {
24 + parent::__construct( $template_path );
25 +
26 + $this->user = $user;
27 + }
28 +
29 + /**
30 + * Display the renewal notice on plugins page
31 + *
32 + * @param string $version Latest version number.
33 + *
34 + * @return void
35 + */
36 + public function renewal_notice( $version ) {
37 + if ( ! $this->user->is_license_expired() ) {
38 + return;
39 + }
40 +
41 + if ( ! $this->is_major_version_available( $version ) ) {
42 + return;
43 + }
44 +
45 + $major = $this->extract_major( $version );
46 +
47 + $data = [
48 + 'version' => $major,
49 + 'release_url' => 'https://wp-rocket.me/blog/wp-rocket-' . str_replace( '.', '-', $major ) . '/',
50 + 'renew_url' => $this->user->get_renewal_url(),
51 + ];
52 +
53 + echo $this->generate( 'update-renewal-expired-notice', $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
54 + }
55 +
56 + /**
57 + * Adds styles for expired banner
58 + *
59 + * @param string $version Latest version number.
60 + *
61 + * @return void
62 + */
63 + public function add_expired_styles( $version ) {
64 + if ( ! $this->user->is_license_expired() ) {
65 + return;
66 + }
67 +
68 + if ( ! $this->is_major_version_available( $version ) ) {
69 + return;
70 + }
71 +
72 + echo '<style>.plugins tr[data-slug=wp-rocket] th, .plugins tr[data-slug=wp-rocket] td {box-shadow: none !important;}.notice.wp-rocket-update{border-color:#d63638;background-color:#fbf9e8;}.plugin-update .notice.wp-rocket-update a{color:#2782ad;}.wp-rocket-update p::before{display: inline-block;font: normal 20px/1 dashicons;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;vertical-align: top;color: #d63638;content: "\f534";}@media screen and (max-width: 782px){.plugins tr[data-slug=wp-rocket].active + .plugin-update-tr::before {background-color: #f0f6fc;border-left: 4px solid #72aee6;}}</style>';
73 + }
74 +
75 + /**
76 + * Checks if a new major version is available
77 + *
78 + * @param string $version Version available from the API.
79 + *
80 + * @return bool
81 + */
82 + private function is_major_version_available( $version ): bool {
83 + $current_version = rocket_get_constant( 'WP_ROCKET_VERSION', '' );
84 +
85 + $current_major = $this->extract_major( $current_version );
86 + $version_major = $this->extract_major( $version );
87 +
88 + return version_compare( $current_major, $version_major, '<' );
89 + }
90 +
91 + /**
92 + * Extracts the major version number from the provided version
93 + *
94 + * @param string $version Version number.
95 + *
96 + * @return string
97 + */
98 + private function extract_major( $version ): string {
99 + $parts = explode( '.', $version );
100 +
101 + return $parts[0] . '.' . $parts[1];
102 + }
103 + }
104 +