PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.5.8
Shortcodes and extra features for Phlox theme v2.5.8
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 6 years ago class-auxin-dashboard-notice.php 7 years ago class-auxin-license-activation.php 7 years ago class-auxin-notices.php 6 years ago class-auxin-upgrader-ajax-handlers.php 7 years ago class-auxin-upgrader-http-api.php 6 years ago class-auxin-upgrader-plugin.php 7 years ago class-auxin-upgrader-prepare.php 6 years ago class-auxin-upgrader-theme.php 7 years ago
class-auxin-license-activation.php
240 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 $request = wp_remote_post( $this->api, $args );
77
78 if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) {
79 return false;
80 }
81
82 return json_decode( $request['body'], true );
83 }
84
85
86 /**
87 * Activate or deactivate license if license info is correct
88 *
89 * @param string $usermail envato usermail
90 * @param string $purchase_code item purchase code
91 * @param string $action activate or deactivate license
92 *
93 * @return array An array containing result of activation or deactivation
94 */
95 public function license_action( $usermail, $purchase_code, $action = 'activate' ){
96
97 $output = array(
98 'success' => 0,
99 'status' => '',
100 'message' => '',
101 'error' => ''
102 );
103
104 if( empty( $usermail ) ){
105 $output['message'] = __( 'Email address is required.', 'auxin-elements' );
106 return $output;
107 } elseif( empty( $purchase_code ) ){
108 $output['message'] = __( 'Purchase key is required.', 'auxin-elements' );
109 return $output;
110 }
111
112 // Check email validation
113 if( ! is_email( $usermail ) ){
114 $output['message'] = __( 'Please enter a valid email address.', 'auxin-elements' );
115 return $output;
116 }
117
118 // get previous license info
119 $license_info = $this->get_license_info();
120
121 $this->usermail = $usermail;
122 $this->purchase_code = $purchase_code;
123 $this->action = $action;
124 // fetch license info
125 $response = $this->get_license_result();
126
127 if( false !== $response ){
128
129 if( empty( $response['result'] ) ){
130 $output['message'] = __( 'Bad request with wrong header ..', 'auxin-elements' );
131 return $output;
132 }
133
134
135 if( 'success' == $response['result'] ){
136 // Remove token transient
137 auxin_delete_transient( 'auxin_check_token_validation_status' );
138
139 if( 'active' == $response['status'] ){
140
141 $token = isset( $response['token'] ) ? $response['token'] : '';
142 $license_info['usermail'] = $usermail;
143 $license_info['purchase_code'] = $purchase_code;
144 $license_info['token'] = $token;
145 update_site_option( $this->option_prefix, $license_info );
146
147 } elseif( 'deactive' == $response['status'] ){
148
149 $license_info['token'] = '';
150 update_site_option( $this->option_prefix, $license_info );
151
152 }
153
154 $output['success'] = 1;
155 $output['status' ] = $response['status'];
156
157 // if an error occurred
158 } else {
159 $output['success'] = 0;
160 $output['status' ] = $response['status'];
161 }
162
163 $output['message'] = $response['msg'] . sprintf( ' <sub>[%s]</sub>', $response['code'] );
164
165 } else {
166 $output['message'] = __( 'Connection error...', 'auxin-elements' );
167 $output['success'] = 0;
168 }
169
170 do_action( 'auxin_on_license_action', $action, $output );
171
172 return $output;
173 }
174
175
176 private function get_token_validation_status() {
177
178 global $wp_version;
179
180 $token = $this->get_license_info( 'token' );
181
182 $args = array(
183 'user-agent' => 'WordPress/'.$wp_version.'; ' . get_site_url(),
184 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
185 'body' => array(
186 'action' => 'token',
187 'token' => $token,
188 'url' => get_site_url()
189 )
190 );
191
192 $request = wp_remote_post( $this->api, $args );
193
194
195 if ( is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) !== 200 ) {
196 return false;
197 }
198
199 $response = json_decode( $request['body'], true );
200 $response['token'] = $token;
201
202 return $response;
203 }
204
205
206 public function maybe_invalid_token(){
207
208 $status = $this->get_token_validation_status();
209
210 if( false !== $status && isset( $status['allowed'] ) ){
211 // if token is no longer valid to be used on this domain
212 if ( ! $status['allowed'] ){
213 $license_info = get_site_option( $this->option_prefix, array() );
214 $license_info['token'] = '';
215 update_site_option( $this->option_prefix, $license_info );
216 }
217 }
218
219 return $status;
220 }
221
222
223
224 /**
225 * Retrieves license info or a specific license field
226 *
227 * @param string $field Specific license field or empty string
228 * @return array|string Returns all license info in array or a string containing license field value
229 */
230 private function get_license_info( $field = '', $default = '' ){
231 $license_info = get_site_option( $this->option_prefix, array() );
232
233 if( empty( $field ) )
234 return $license_info;
235
236 return isset( $license_info[ $field ] ) ? $license_info[ $field ] : $default;
237 }
238
239 }
240