PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.17.21
Shortcodes and extra features for Phlox theme v2.17.21
2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / admin / includes / classes / class-auxin-license-activation.php
auxin-elements / admin / includes / classes Last commit date
class-auxels-system-check.php 6 months ago class-auxin-cli-commands.php 5 months ago class-auxin-license-activation.php 6 months ago class-auxin-notices.php 3 years ago class-auxin-upgrader-ajax-handlers.php 1 year ago class-auxin-upgrader-plugin.php 2 years ago class-auxin-upgrader-prepare.php 3 years ago class-auxin-upgrader-theme.php 4 years ago
class-auxin-license-activation.php
243 lines
1 <?php
2
3 // no direct access allowed
4 if ( ! defined('ABSPATH') ) {
5 die();
6 }
7
8 class Auxin_License_Activation {
9
10 /**
11 * Instance of this class.
12 *
13 * @since 1.0.0
14 *
15 * @var object
16 */
17 protected static $instance = null;
18
19 protected $api = 'https://env.averta.net/en/api/?branch=envato&group=items&cat=verify-purchase';
20 protected $usermail = '';
21 protected $purchase_code = '';
22 protected $option_prefix = '';
23 protected $action = 'activate';
24
25
26 public function __construct(){
27 $this->option_prefix = AUXELS_PURCHASE_KEY;
28 }
29
30 /**
31 * Return an instance of this class.
32 *
33 * @since 1.0.0
34 *
35 * @return object A single instance of this class.
36 */
37 public static function get_instance() {
38
39 // If the single instance hasn't been set, set it now.
40 if ( null == self::$instance ) {
41 self::$instance = new self;
42 }
43
44 return self::$instance;
45 }
46
47 /**
48 * The result of license validation request
49 *
50 * @return string|array the server response
51 */
52 private function get_license_result() {
53
54 if( empty( $this->usermail ) || empty( $this->purchase_code ) ) {
55 return false;
56 }
57
58 global $wp_version;
59
60 $action = ( 'activate' === $this->action ) ? 'activate' : 'deactivate';
61 $token = $this->get_license_info( 'token' );
62
63 $args = array(
64 'user-agent' => 'WordPress/'.$wp_version.'; ' . get_site_url(),
65 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
66 'body' => array(
67 'action' => $action,
68 'key' => $this->purchase_code,
69 'email' => $this->usermail,
70 'token' => $token,
71 'url' => get_site_url(),
72 'item_id' => '3909293',
73 'ip' => isset( $_SERVER['SERVER_ADDR'] ) ? $_SERVER['SERVER_ADDR'] : ''
74 )
75 );
76
77 $args = apply_filters( 'auxels_get_license_result_args', $args );
78
79 $request = wp_remote_post( $this->api, $args );
80
81 if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) {
82 return false;
83 }
84
85 return json_decode( $request['body'], true );
86 }
87
88
89 /**
90 * Activate or deactivate license if license info is correct
91 *
92 * @param string $usermail envato usermail
93 * @param string $purchase_code item purchase code
94 * @param string $action activate or deactivate license
95 *
96 * @return array An array containing result of activation or deactivation
97 */
98 public function license_action( $usermail, $purchase_code, $action = 'activate' ){
99
100 $output = array(
101 'success' => 0,
102 'status' => '',
103 'message' => '',
104 'error' => ''
105 );
106
107 if( empty( $usermail ) ){
108 $output['message'] = __( 'Email address is required.', 'auxin-elements' );
109 return $output;
110 } elseif( empty( $purchase_code ) ){
111 $output['message'] = __( 'Purchase key is required.', 'auxin-elements' );
112 return $output;
113 }
114
115 // Check email validation
116 if( ! is_email( $usermail ) ){
117 $output['message'] = __( 'Please enter a valid email address.', 'auxin-elements' );
118 return $output;
119 }
120
121 // get previous license info
122 $license_info = $this->get_license_info();
123
124 $this->usermail = $usermail;
125 $this->purchase_code = $purchase_code;
126 $this->action = $action;
127 // fetch license info
128 $response = $this->get_license_result();
129
130 if( false !== $response ){
131
132 if( empty( $response['result'] ) ){
133 $output['message'] = __( 'Bad request with wrong header ..', 'auxin-elements' );
134 return $output;
135 }
136
137
138 if( 'success' == $response['result'] ){
139 // Remove token transient
140 auxin_delete_transient( 'auxin_check_token_validation_status' );
141
142 if( 'active' == $response['status'] ){
143
144 $token = isset( $response['token'] ) ? $response['token'] : '';
145 $license_info['usermail'] = $usermail;
146 $license_info['purchase_code'] = $purchase_code;
147 $license_info['token'] = $token;
148 update_site_option( $this->option_prefix, $license_info );
149
150 } elseif( 'deactive' == $response['status'] ){
151
152 $license_info['token'] = '';
153 update_site_option( $this->option_prefix, $license_info );
154
155 }
156
157 $output['success'] = 1;
158 $output['status' ] = $response['status'];
159
160 // if an error occurred
161 } else {
162 $output['success'] = 0;
163 $output['status' ] = $response['status'];
164 }
165
166 $output['message'] = $response['msg'] . sprintf( ' <sub>[%s]</sub>', $response['code'] );
167
168 } else {
169 $output['message'] = sprintf( "%s <a href='http://avt.li/phmli'>%s</a>", __( 'Connection error...', 'auxin-elements' ), __( 'Learn more', 'auxin-elements' ) );
170 $output['success'] = 0;
171 }
172
173 do_action( 'auxin_on_license_action', $action, $output );
174
175 return $output;
176 }
177
178
179 private function get_token_validation_status() {
180
181 global $wp_version;
182
183 $token = $this->get_license_info( 'token' );
184
185 $args = array(
186 'user-agent' => 'WordPress/'.$wp_version.'; ' . get_site_url(),
187 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
188 'body' => array(
189 'action' => 'token',
190 'token' => $token,
191 'url' => get_site_url()
192 )
193 );
194
195 $request = wp_remote_post( $this->api, $args );
196
197
198 if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) {
199 return false;
200 }
201
202 $response = json_decode( $request['body'], true );
203 $response['token'] = $token;
204
205 return $response;
206 }
207
208
209 public function maybe_invalid_token(){
210
211 $status = $this->get_token_validation_status();
212
213 if( false !== $status && isset( $status['allowed'] ) ){
214 // if token is no longer valid to be used on this domain
215 if ( ! $status['allowed'] ){
216 $license_info = get_site_option( $this->option_prefix, array() );
217 $license_info['token'] = '';
218 update_site_option( $this->option_prefix, $license_info );
219 }
220 }
221
222 return $status;
223 }
224
225
226
227 /**
228 * Retrieves license info or a specific license field
229 *
230 * @param string $field Specific license field or empty string
231 * @return array|string Returns all license info in array or a string containing license field value
232 */
233 private function get_license_info( $field = '', $default = '' ){
234 $license_info = get_site_option( $this->option_prefix, array() );
235
236 if( empty( $field ) )
237 return $license_info;
238
239 return isset( $license_info[ $field ] ) ? $license_info[ $field ] : $default;
240 }
241
242 }
243