| @@ -69,9 +69,111 @@ | ||
| 69 | 69 | * @param array $item licence id, name and key |
| 70 | 70 | * @return string |
| 71 | 71 | */ |
| 72 | 72 | protected function get_row( $item ) { |
| 73 | - return $item->get_form_field(); | |
| 73 | + if ( ! empty( $item->license_data ) ) { | |
| 74 | + $license = $item->license_data; | |
| 75 | + } | |
| 76 | + | |
| 77 | + $class = 'license-null'; | |
| 78 | + | |
| 79 | + $out = sprintf( | |
| 80 | + '<td><label for="pll-licenses[%1$s]">%2$s</label></td>' . | |
| 81 | + '<td><input name="licenses[%1$s]" id="pll-licenses[%1$s]" type="text" value="%3$s" class="regular-text code" />', | |
| 82 | + esc_attr( $item->id ), | |
| 83 | + esc_attr( $item->name ), | |
| 84 | + esc_html( $item->license_key ) | |
| 85 | + ); | |
| 86 | + | |
| 87 | + if ( ! empty( $license ) && is_object( $license ) ) { | |
| 88 | + $now = current_time( 'timestamp' ); | |
| 89 | + $expiration = strtotime( $license->expires, $now ); | |
| 90 | + | |
| 91 | + // Special case: the license expired after the last check | |
| 92 | + if ( $license->success && $expiration < $now ) { | |
| 93 | + $license->success = false; | |
| 94 | + $license->error = 'expired'; | |
| 95 | + } | |
| 96 | + | |
| 97 | + if ( false === $license->success ) { | |
| 98 | + $class = 'notice-error notice-alt'; | |
| 99 | + | |
| 100 | + switch ( $license->error ) { | |
| 101 | + case 'expired': | |
| 102 | + $message = sprintf( | |
| 103 | + /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */ | |
| 104 | + __( 'Your license key expired on %1$s. Please %2$srenew your license key%3$s.', 'polylang' ), | |
| 105 | + date_i18n( get_option( 'date_format' ), strtotime( $license->expires, current_time( 'timestamp' ) ) ), | |
| 106 | + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/checkout/?edd_license_key=' . $item->license_key ), | |
| 107 | + '</a>' | |
| 108 | + ); | |
| 109 | + break; | |
| 110 | + | |
| 111 | + case 'missing': | |
| 112 | + $message = sprintf( | |
| 113 | + /* translators: %1$s is link start tag, %2$s is link end tag. */ | |
| 114 | + __( 'Invalid license. Please %1$svisit your account page%2$s and verify it.', 'polylang' ), | |
| 115 | + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ), | |
| 116 | + '</a>' | |
| 117 | + ); | |
| 118 | + break; | |
| 119 | + | |
| 120 | + case 'invalid': | |
| 121 | + case 'site_inactive': | |
| 122 | + $message = sprintf( | |
| 123 | + /* translators: %1$s is a product name, %2$s is link start tag, %3$s is link end tag. */ | |
| 124 | + __( 'Your %1$s license key is not active for this URL. Please %2$svisit your account page%3$s to manage your license key URLs.', 'polylang' ), | |
| 125 | + $item->name, | |
| 126 | + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ), | |
| 127 | + '</a>' | |
| 128 | + ); | |
| 129 | + break; | |
| 130 | + | |
| 131 | + case 'item_name_mismatch': | |
| 132 | + /* translators: %s is a product name */ | |
| 133 | + $message = sprintf( __( 'This is not a %s license key.', 'polylang' ), $item->name ); | |
| 134 | + break; | |
| 135 | + | |
| 136 | + case 'no_activations_left': | |
| 137 | + $message = sprintf( | |
| 138 | + /* translators: %1$s is link start tag, %2$s is link end tag */ | |
| 139 | + __( 'Your license key has reached its activation limit. %1$sView possible upgrades%2$s now.', 'polylang' ), | |
| 140 | + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/account' ), | |
| 141 | + '</a>' | |
| 142 | + ); | |
| 143 | + break; | |
| 144 | + } | |
| 145 | + } else { | |
| 146 | + $class = 'license-valid'; | |
| 147 | + | |
| 148 | + $out .= sprintf( '<button id="deactivate_%s" type="button" class="button button-secondary pll-deactivate-license">%s</button>', $item->id, __( 'Deactivate', 'polylang' ) ); | |
| 149 | + | |
| 150 | + if ( 'lifetime' === $license->expires ) { | |
| 151 | + $message = __( 'The license key never expires.', 'polylang' ); | |
| 152 | + } elseif ( $expiration > $now && $expiration - $now < ( DAY_IN_SECONDS * 30 ) ) { | |
| 153 | + $class = 'notice-warning notice-alt'; | |
| 154 | + $message = sprintf( | |
| 155 | + /* translators: %1$s is a date, %2$s is link start tag, %3$s is link end tag. */ | |
| 156 | + __( 'Your license key will expire soon! Precisely, it will expire on %1$s. %2$sRenew your license key today!%3$s.', 'polylang' ), | |
| 157 | + date_i18n( get_option( 'date_format' ), strtotime( $license->expires, $now ) ), | |
| 158 | + sprintf( '<a href="%s" target="_blank">', 'https://polylang.pro/checkout/?edd_license_key=' . $item->license_key ), | |
| 159 | + '</a>' | |
| 160 | + ); | |
| 161 | + } else { | |
| 162 | + $message = sprintf( | |
| 163 | + /* translators: %s is a date */ | |
| 164 | + __( 'Your license key expires on %s.', 'polylang' ), | |
| 165 | + date_i18n( get_option( 'date_format' ), strtotime( $license->expires, $now ) ) | |
| 166 | + ); | |
| 167 | + } | |
| 168 | + } | |
| 169 | + } | |
| 170 | + | |
| 171 | + if ( ! empty( $message ) ) { | |
| 172 | + $out .= '<p>' . $message . '</p>'; | |
| 173 | + } | |
| 174 | + | |
| 175 | + return sprintf( '<tr id="pll-license-%s" class="%s">%s</tr>', $item->id, $class, $out ); | |
| 74 | 176 | } |
| 75 | 177 | |
| 76 | 178 | /** |
| 77 | 179 | * Ajax method to save the license keys and activate the licenses at the same time |