PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.7.9
Shortcodes and extra features for Phlox theme v2.7.9
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-plugin-check-update.php 5 years ago class-auxels-system-check.php 5 years ago class-auxin-cli-commands.php 5 years ago class-auxin-license-activation.php 6 years ago class-auxin-notices.php 6 years ago class-auxin-upgrader-ajax-handlers.php 7 years ago class-auxin-upgrader-http-api.php 5 years ago class-auxin-upgrader-plugin.php 5 years ago class-auxin-upgrader-prepare.php 6 years ago class-auxin-upgrader-theme.php 7 years ago
class-auxin-license-activation.php
242 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 = 'http://support.averta.net/en/api/?branch=envato&group=items&cat=verify-purchase';
20 protected $usermail = '';
21 protected $purchase_code = '';
22 protected $action = 'activate';
23
24
25 function __construct(){
26 $this->option_prefix = AUXELS_PURCHASE_KEY;
27 }
28
29 /**
30 * Return an instance of this class.
31 *
32 * @since 1.0.0
33 *
34 * @return object A single instance of this class.
35 */
36 public static function get_instance() {
37
38 // If the single instance hasn't been set, set it now.
39 if ( null == self::$instance ) {
40 self::$instance = new self;
41 }
42
43 return self::$instance;
44 }
45
46 /**
47 * The result of license validation request
48 *
49 * @return string|array the server response
50 */
51 private function get_license_result() {
52
53 if( empty( $this->usermail ) || empty( $this->purchase_code ) ) {
54 return false;
55 }
56
57 global $wp_version;
58
59 $action = ( 'activate' === $this->action ) ? 'activate': 'deactivate';
60 $token = $this->get_license_info( 'token' );
61
62 $args = array(
63 'user-agent' => 'WordPress/'.$wp_version.'; ' . get_site_url(),
64 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
65 'body' => array(
66 'action' => $action,
67 'key' => $this->purchase_code,
68 'email' => $this->usermail,
69 'token' => $token,
70 'url' => get_site_url(),
71 'item_id' => '3909293',
72 'ip' => isset( $_SERVER['SERVER_ADDR'] ) ? $_SERVER['SERVER_ADDR'] : ''
73 )
74 );
75
76 $args = apply_filters( 'auxels_get_license_result_args', $args );
77
78 $request = wp_remote_post( $this->api, $args );
79
80 if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) {
81 return false;
82 }
83
84 return json_decode( $request['body'], true );
85 }
86
87
88 /**
89 * Activate or deactivate license if license info is correct
90 *
91 * @param string $usermail envato usermail
92 * @param string $purchase_code item purchase code
93 * @param string $action activate or deactivate license
94 *
95 * @return array An array containing result of activation or deactivation
96 */
97 public function license_action( $usermail, $purchase_code, $action = 'activate' ){
98
99 $output = array(
100 'success' => 0,
101 'status' => '',
102 'message' => '',
103 'error' => ''
104 );
105
106 if( empty( $usermail ) ){
107 $output['message'] = __( 'Email address is required.', 'auxin-elements' );
108 return $output;
109 } elseif( empty( $purchase_code ) ){
110 $output['message'] = __( 'Purchase key is required.', 'auxin-elements' );
111 return $output;
112 }
113
114 // Check email validation
115 if( ! is_email( $usermail ) ){
116 $output['message'] = __( 'Please enter a valid email address.', 'auxin-elements' );
117 return $output;
118 }
119
120 // get previous license info
121 $license_info = $this->get_license_info();
122
123 $this->usermail = $usermail;
124 $this->purchase_code = $purchase_code;
125 $this->action = $action;
126 // fetch license info
127 $response = $this->get_license_result();
128
129 if( false !== $response ){
130
131 if( empty( $response['result'] ) ){
132 $output['message'] = __( 'Bad request with wrong header ..', 'auxin-elements' );
133 return $output;
134 }
135
136
137 if( 'success' == $response['result'] ){
138 // Remove token transient
139 auxin_delete_transient( 'auxin_check_token_validation_status' );
140
141 if( 'active' == $response['status'] ){
142
143 $token = isset( $response['token'] ) ? $response['token'] : '';
144 $license_info['usermail'] = $usermail;
145 $license_info['purchase_code'] = $purchase_code;
146 $license_info['token'] = $token;
147 update_site_option( $this->option_prefix, $license_info );
148
149 } elseif( 'deactive' == $response['status'] ){
150
151 $license_info['token'] = '';
152 update_site_option( $this->option_prefix, $license_info );
153
154 }
155
156 $output['success'] = 1;
157 $output['status' ] = $response['status'];
158
159 // if an error occurred
160 } else {
161 $output['success'] = 0;
162 $output['status' ] = $response['status'];
163 }
164
165 $output['message'] = $response['msg'] . sprintf( ' <sub>[%s]</sub>', $response['code'] );
166
167 } else {
168 $output['message'] = __( 'Connection error...', 'auxin-elements' );
169 $output['success'] = 0;
170 }
171
172 do_action( 'auxin_on_license_action', $action, $output );
173
174 return $output;
175 }
176
177
178 private function get_token_validation_status() {
179
180 global $wp_version;
181
182 $token = $this->get_license_info( 'token' );
183
184 $args = array(
185 'user-agent' => 'WordPress/'.$wp_version.'; ' . get_site_url(),
186 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
187 'body' => array(
188 'action' => 'token',
189 'token' => $token,
190 'url' => get_site_url()
191 )
192 );
193
194 $request = wp_remote_post( $this->api, $args );
195
196
197 if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) {
198 return false;
199 }
200
201 $response = json_decode( $request['body'], true );
202 $response['token'] = $token;
203
204 return $response;
205 }
206
207
208 public function maybe_invalid_token(){
209
210 $status = $this->get_token_validation_status();
211
212 if( false !== $status && isset( $status['allowed'] ) ){
213 // if token is no longer valid to be used on this domain
214 if ( ! $status['allowed'] ){
215 $license_info = get_site_option( $this->option_prefix, array() );
216 $license_info['token'] = '';
217 update_site_option( $this->option_prefix, $license_info );
218 }
219 }
220
221 return $status;
222 }
223
224
225
226 /**
227 * Retrieves license info or a specific license field
228 *
229 * @param string $field Specific license field or empty string
230 * @return array|string Returns all license info in array or a string containing license field value
231 */
232 private function get_license_info( $field = '', $default = '' ){
233 $license_info = get_site_option( $this->option_prefix, array() );
234
235 if( empty( $field ) )
236 return $license_info;
237
238 return isset( $license_info[ $field ] ) ? $license_info[ $field ] : $default;
239 }
240
241 }
242