PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.75
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.75
1.2.76 1.2.75 1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 All 176 releases
userswp / vendor / ayecode / ayecode-connect-helper / ayecode-connect-helper.php

ayecode-connect-helper.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.75, at vendor/ayecode/ayecode-connect-helper/ayecode-connect-helper.php

480 lines 18.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 if ( ! class_exists( "AyeCode_Connect_Helper" ) ) {
7 /**
8 * Allow the quick setup and connection of our AyeCode Connect plugin.
9 *
10 * Class AyeCode_Connect_Helper
11 */
12 class AyeCode_Connect_Helper {
13
14 // Hold the version number
15 var $version = "1.0.5";
16
17 // Hold the default strings.
18 var $strings = array();
19
20 // Hold the default pages.
21 var $pages = array();
22
23 /**
24 * The constructor.
25 *
26 * AyeCode_Connect_Helper constructor.
27 *
28 * @param array $strings
29 * @param array $pages
30 */
31 public function __construct( $strings = array(), $pages = array() ) {
32 // Only fire if not localhost and the current user has the right permissions.
33 if ( ! $this->is_localhost() && current_user_can( 'manage_options' ) ) {
34 // set default strings
35 $default_strings = array(
36 'connect_title' => __( "Thanks for choosing an AyeCode Product!", 'ayecode-connect' ),
37 'connect_external' => __( "Please confirm you wish to connect your site?", 'ayecode-connect' ),
38 'connect' => wp_sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", 'ayecode-connect' ), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>" ),
39 'connect_button' => __( "Connect Site", 'ayecode-connect' ),
40 'connecting_button' => __( "Connecting...", 'ayecode-connect' ),
41 'error_localhost' => __( "This service will only work with a live domain, not a localhost.", 'ayecode-connect' ),
42 'error' => __( "Something went wrong, please refresh and try again.", 'ayecode-connect' ),
43 );
44 $this->strings = array_merge( $default_strings, $strings );
45
46 // set default pages
47 $default_pages = array();
48 $this->pages = array_merge( $default_pages, $pages );
49
50 // maybe show connect site notice
51 add_action( 'admin_notices', array( $this, 'ayecode_connect_install_notice' ) );
52
53 // add ajax action if not already added
54 if ( ! has_action( 'wp_ajax_ayecode_connect_helper' ) ) {
55 add_action( 'wp_ajax_ayecode_connect_helper', array( $this, 'ayecode_connect_install' ) );
56 }
57 }
58
59 // add ajax action if not already added
60 if ( ! has_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed' ) ) {
61 add_action( 'wp_ajax_nopriv_ayecode_connect_helper_installed', array( $this, 'ayecode_connect_helper_installed' ) );
62 }
63 }
64
65 /**
66 * Give a way to check we can connect via a external redirect.
67 */
68 public function ayecode_connect_helper_installed(){
69 $active = array(
70 'gd' => defined('GEODIRECTORY_VERSION') && version_compare(GEODIRECTORY_VERSION,'2.0.0.79','>') ? 1 : 0,
71 'uwp' => defined('USERSWP_VERSION') && version_compare(USERSWP_VERSION,'1.2.1.5','>') ? 1 : 0,
72 'wpi' => defined('WPINV_VERSION') && version_compare(WPINV_VERSION,'1.0.14','>') ? 1 : 0,
73 );
74 wp_send_json_success( $active );
75 wp_die();
76 }
77
78 /**
79 * Get slug from path
80 *
81 * @param string $key
82 *
83 * @return string
84 */
85 private function format_plugin_slug( $key ) {
86 $slug = explode( '/', $key );
87 $slug = explode( '.', end( $slug ) );
88
89 return $slug[0];
90 }
91
92 /**
93 * Install and activate the AyeCode Connect Plugin
94 */
95 public function ayecode_connect_install() {
96 // Security check.
97 check_ajax_referer( 'ayecode-connect-helper', 'security' );
98
99 if ( ! current_user_can( 'manage_options' ) ) {
100 wp_send_json_error( $this->strings['error'] );
101 }
102
103 // bail if localhost
104 if ( $this->is_localhost() ) {
105 wp_send_json_error( $this->strings['error_localhost'] );
106 }
107
108 // Explicitly clear the event.
109 wp_clear_scheduled_hook( 'geodir_plugin_background_installer', func_get_args() );
110
111 $success = true;
112 $plugin_slug = "ayecode-connect";
113 if ( ! empty( $plugin_slug ) ) {
114 require_once( ABSPATH . 'wp-admin/includes/file.php' );
115 require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
116 require_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
117 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
118
119 WP_Filesystem();
120
121 $skin = new Automatic_Upgrader_Skin;
122 $upgrader = new WP_Upgrader( $skin );
123 $installed_plugins = array_map( array( $this, 'format_plugin_slug' ), array_keys( get_plugins() ) );
124 $plugin_slug = $plugin_slug;
125 $plugin = $plugin_slug . '/' . $plugin_slug . '.php';
126 $installed = false;
127 $activate = false;
128
129 // See if the plugin is installed already
130 if ( in_array( $plugin_slug, $installed_plugins ) ) {
131 $installed = true;
132 $activate = ! is_plugin_active( $plugin );
133 }
134
135 // Install this thing!
136 if ( ! $installed ) {
137
138 // Suppress feedback
139 ob_start();
140
141 try {
142 $plugin_information = plugins_api( 'plugin_information', array(
143 'slug' => $plugin_slug,
144 'fields' => array(
145 'short_description' => false,
146 'sections' => false,
147 'requires' => false,
148 'rating' => false,
149 'ratings' => false,
150 'downloaded' => false,
151 'last_updated' => false,
152 'added' => false,
153 'tags' => false,
154 'homepage' => false,
155 'donate_link' => false,
156 'author_profile' => false,
157 'author' => false,
158 ),
159 ) );
160
161 if ( is_wp_error( $plugin_information ) ) {
162 throw new Exception( $plugin_information->get_error_message() );
163 }
164
165 $package = $plugin_information->download_link;
166 $download = $upgrader->download_package( $package );
167
168 if ( is_wp_error( $download ) ) {
169 throw new Exception( $download->get_error_message() );
170 }
171
172 $working_dir = $upgrader->unpack_package( $download, true );
173
174 if ( is_wp_error( $working_dir ) ) {
175 throw new Exception( $working_dir->get_error_message() );
176 }
177
178 $result = $upgrader->install_package( array(
179 'source' => $working_dir,
180 'destination' => WP_PLUGIN_DIR,
181 'clear_destination' => false,
182 'abort_if_destination_exists' => false,
183 'clear_working' => true,
184 'hook_extra' => array(
185 'type' => 'plugin',
186 'action' => 'install',
187 ),
188 ) );
189
190 if ( is_wp_error( $result ) ) {
191 throw new Exception( $result->get_error_message() );
192 }
193
194 $activate = true;
195
196 } catch ( Exception $e ) {
197 $success = false;
198 }
199
200 // Discard feedback
201 ob_end_clean();
202 }
203
204 wp_clean_plugins_cache();
205
206 // Activate this thing
207 if ( $activate ) {
208 try {
209 $result = activate_plugin( $plugin );
210
211 if ( is_wp_error( $result ) ) {
212 $success = false;
213 } else {
214 $success = true;
215 }
216 } catch ( Exception $e ) {
217 $success = false;
218 }
219 }
220 }
221
222 if ( $success && function_exists( 'ayecode_connect_args' ) ) {
223 ayecode_connect();// init
224 $args = ayecode_connect_args();
225 $client = new AyeCode_Connect( $args );
226 $redirect_to = ! empty( $_POST['redirect_to'] ) ? esc_url_raw( $_POST['redirect_to'] ) : '';
227 $redirect = $client->build_connect_url( $redirect_to );
228 wp_send_json_success( array( 'connect_url' => $redirect ) );
229 } else {
230 wp_send_json_error( $this->strings['error_localhost'] );
231 }
232 wp_die();
233 }
234
235 /**
236 * Check if maybe localhost.
237 *
238 * @return bool
239 */
240 public function is_localhost() {
241 $localhost = false;
242
243 $host = isset( $_SERVER['HTTP_HOST'] ) ? $_SERVER['HTTP_HOST'] : '';
244 $localhost_domains = array(
245 'localhost',
246 'localhost.localdomain',
247 '127.0.0.1',
248 '::1'
249 );
250
251 if ( in_array( $host, $localhost_domains ) ) {
252 $localhost = true;
253 }
254
255 return $localhost;
256 }
257
258 /**
259 * Show notice to connect site.
260 */
261 public function ayecode_connect_install_notice() {
262 if ( $this->maybe_show() ) {
263 $connect_title_string = $this->strings['connect_title'];
264 $connect_external_string = $this->strings['connect_external'];
265 $connect_string = $this->strings['connect'];
266 $connect_button_string = $this->strings['connect_button'];
267 $connecting_button_string = $this->strings['connecting_button'];
268 ?>
269 <div class="notice notice-info acch-notice">
270 <span class="acch-float-left">
271 <svg width="61px" height="61px" viewBox="0 0 61 61" version="1.1"
272 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
273 <defs>
274 <polygon id="path-1"
275 points="4.70437018e-05 0.148846272 60.8504481 0.148846272 60.8504481 61 4.70437018e-05 61"></polygon>
276 </defs>
277 <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
278 <g id="Group-6" transform="translate(-8.000000, -4.000000)">
279 <g id="Group-5" transform="translate(8.000000, 4.000000)">
280 <g id="Group-17">
281 <mask id="mask-2" fill="white">
282 <use xlink:href="#path-1"></use>
283 </mask>
284 <g id="Clip-16"></g>
285 <path
286 d="M60.8504481,30.5740468 C60.8504481,47.3793116 47.229101,61.0000314 30.4252476,61.0000314 C13.6215509,61.0000314 4.70437018e-05,47.3793116 4.70437018e-05,30.5740468 C4.70437018e-05,13.7711342 13.6215509,0.148846272 30.4252476,0.148846272 C47.229101,0.148846272 60.8504481,13.7711342 60.8504481,30.5740468"
287 id="Fill-15" fill="#4C96D7" mask="url(#mask-2)"></path>
288 </g>
289 <path
290 d="M7.34736527,20.4434788 C7.34736527,14.815441 10.231253,12 16,12 L16,16.2224505 C13.1153027,16.2224505 11.6736826,17.6294599 11.6736826,20.4434788 L11.6736826,26.7780236 C11.6736826,28.9016534 10.59182,30.310085 8.42858032,30.9988939 C10.5775721,31.7039788 11.6519871,33.1116203 11.6519871,35.2221344 L11.6519871,41.5566793 C11.6519871,44.3705401 13.0927976,45.7777075 15.9783045,45.7777075 L15.9783045,50 C10.2246148,50 7.34736527,47.184717 7.34736527,41.5566793 L7.34736527,35.2221344 C7.34736527,33.815283 5.89748795,33.1116203 3,33.1116203 L3,28.8883797 C5.89748795,28.8883797 7.34736527,28.185033 7.34736527,26.7780236 L7.34736527,20.4434788 Z"
291 id="Fill-18" fill="#FFFFFF"></path>
292 <path
293 d="M53.6524181,41.5551342 C53.6524181,47.1845707 50.7690344,50 45,50 L45,45.7775671 C47.8841934,45.7775671 49.3266948,44.3691413 49.3266948,41.5551342 L49.3266948,35.2221959 C49.3266948,33.0969947 50.4079637,31.689201 52.5719588,30.9989729 C50.4222123,30.2954711 49.3483914,28.8884675 49.3483914,26.77654 L49.3483914,20.4434437 C49.3483914,17.6281723 47.90589,16.2225909 45.021049,16.2225909 L45.021049,12 C50.7758348,12 53.6524181,14.8140072 53.6524181,20.4434437 L53.6524181,26.77654 C53.6524181,28.1835435 55.1023677,28.8884675 58,28.8884675 L58,33.1116905 C55.1023677,33.1116905 53.6524181,33.8151923 53.6524181,35.2221959 L53.6524181,41.5551342 Z"
294 id="Fill-20" fill="#FFFFFF"></path>
295 <path
296 d="M46.0272652,44 C48.1048141,44 48.9396754,43.2042837 48.9795214,41.1979284 L34.4844624,30.499526 L49,19.7867451 C48.9558678,17.7920822 48.1210065,17 46.0479025,17 L45.8064452,17 L30.9992856,27.9275105 L16.1929198,17 L15.9727348,17 C13.8943922,17 13.0596896,17.7958743 13.0206374,19.8023876 L27.5141088,30.499526 L13,41.2126229 C13.0434972,43.2071278 13.8781998,44 15.9513037,44 L16.1929198,44 L30.9992856,33.0718574 L45.8064452,44 L46.0272652,44 Z"
297 id="Fill-22" fill="#FFFFFF"></path>
298 </g>
299 </g>
300 </g>
301 </svg>
302 </span>
303 <span class="acch-float-left acch-text">
304 <h3 class="acch-title"><?php echo esc_attr( $connect_title_string ); ?></h3>
305 <p><?php echo $connect_string; ?>
306 </p>
307 </span>
308
309 <span class="acch-float-left acch-button">
310 <button onclick="ayecode_connect_helper(this);" id="gd-connect-site" class="button button-primary" data-connecting="<?php echo esc_attr( $connecting_button_string ); ?>"><?php echo esc_attr( $connect_button_string ) ?></button>
311 </span>
312 </div>
313
314 <?php
315 // only include the popup HTML if needed.
316 if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
317 ?>
318 <div id="ayecode-connect-helper-external-confirm" style="display:none;">
319 <div class="noticex notice-info acch-notice" style="border: none;">
320 <span class="acch-float-left">
321 <svg width="61px" height="61px" viewBox="0 0 61 61" version="1.1"
322 xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
323 <defs>
324 <polygon id="path-1"
325 points="4.70437018e-05 0.148846272 60.8504481 0.148846272 60.8504481 61 4.70437018e-05 61"></polygon>
326 </defs>
327 <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
328 <g id="Group-6" transform="translate(-8.000000, -4.000000)">
329 <g id="Group-5" transform="translate(8.000000, 4.000000)">
330 <g id="Group-17">
331 <mask id="mask-2" fill="white">
332 <use xlink:href="#path-1"></use>
333 </mask>
334 <g id="Clip-16"></g>
335 <path
336 d="M60.8504481,30.5740468 C60.8504481,47.3793116 47.229101,61.0000314 30.4252476,61.0000314 C13.6215509,61.0000314 4.70437018e-05,47.3793116 4.70437018e-05,30.5740468 C4.70437018e-05,13.7711342 13.6215509,0.148846272 30.4252476,0.148846272 C47.229101,0.148846272 60.8504481,13.7711342 60.8504481,30.5740468"
337 id="Fill-15" fill="#4C96D7" mask="url(#mask-2)"></path>
338 </g>
339 <path
340 d="M7.34736527,20.4434788 C7.34736527,14.815441 10.231253,12 16,12 L16,16.2224505 C13.1153027,16.2224505 11.6736826,17.6294599 11.6736826,20.4434788 L11.6736826,26.7780236 C11.6736826,28.9016534 10.59182,30.310085 8.42858032,30.9988939 C10.5775721,31.7039788 11.6519871,33.1116203 11.6519871,35.2221344 L11.6519871,41.5566793 C11.6519871,44.3705401 13.0927976,45.7777075 15.9783045,45.7777075 L15.9783045,50 C10.2246148,50 7.34736527,47.184717 7.34736527,41.5566793 L7.34736527,35.2221344 C7.34736527,33.815283 5.89748795,33.1116203 3,33.1116203 L3,28.8883797 C5.89748795,28.8883797 7.34736527,28.185033 7.34736527,26.7780236 L7.34736527,20.4434788 Z"
341 id="Fill-18" fill="#FFFFFF"></path>
342 <path
343 d="M53.6524181,41.5551342 C53.6524181,47.1845707 50.7690344,50 45,50 L45,45.7775671 C47.8841934,45.7775671 49.3266948,44.3691413 49.3266948,41.5551342 L49.3266948,35.2221959 C49.3266948,33.0969947 50.4079637,31.689201 52.5719588,30.9989729 C50.4222123,30.2954711 49.3483914,28.8884675 49.3483914,26.77654 L49.3483914,20.4434437 C49.3483914,17.6281723 47.90589,16.2225909 45.021049,16.2225909 L45.021049,12 C50.7758348,12 53.6524181,14.8140072 53.6524181,20.4434437 L53.6524181,26.77654 C53.6524181,28.1835435 55.1023677,28.8884675 58,28.8884675 L58,33.1116905 C55.1023677,33.1116905 53.6524181,33.8151923 53.6524181,35.2221959 L53.6524181,41.5551342 Z"
344 id="Fill-20" fill="#FFFFFF"></path>
345 <path
346 d="M46.0272652,44 C48.1048141,44 48.9396754,43.2042837 48.9795214,41.1979284 L34.4844624,30.499526 L49,19.7867451 C48.9558678,17.7920822 48.1210065,17 46.0479025,17 L45.8064452,17 L30.9992856,27.9275105 L16.1929198,17 L15.9727348,17 C13.8943922,17 13.0596896,17.7958743 13.0206374,19.8023876 L27.5141088,30.499526 L13,41.2126229 C13.0434972,43.2071278 13.8781998,44 15.9513037,44 L16.1929198,44 L30.9992856,33.0718574 L45.8064452,44 L46.0272652,44 Z"
347 id="Fill-22" fill="#FFFFFF"></path>
348 </g>
349 </g>
350 </g>
351 </svg>
352 </span>
353 <span class="acch-float-left acch-text">
354 <h3 class="acch-title"><?php echo esc_attr( $connect_external_string ); ?></h3>
355 </span>
356
357 <span class="acch-float-left acch-button">
358 <button onclick="ayecode_connect_helper(this);" id="gd-connect-site" class="button button-primary" data-connecting="<?php echo esc_attr( $connecting_button_string ); ?>"><?php echo esc_attr( $connect_button_string ) ?></button>
359 </span>
360 </div>
361 </div>
362 <?php
363 }
364
365 // add required scripts
366 $this->script();
367 }
368 }
369
370 /**
371 * Get the JS Script.
372 */
373 public function script() {
374
375 // add thickbox if external request is requested
376 if ( ! empty( $_REQUEST['external-connect-request'] ) ) {
377 add_thickbox();
378 }
379 ?>
380 <style>
381 .acch-title {
382 margin: 0;
383 padding: 0;
384 }
385
386 .acch-notice {
387 display: table;
388 width: 99%;
389 position: relative;
390 margin: 0;
391 padding: 5px;
392 border: 1px solid #ccc;
393 border-radius: 3px;
394 }
395
396 .acch-float-left {
397 display: table-cell;
398 vertical-align: middle;
399 }
400
401 .acch-float-left svg {
402 vertical-align: middle;
403 }
404
405 .acch-button {
406 zoom: 1.3;
407 }
408 </style>
409 <script>
410 /**
411 * Ajax function to install and activate the AyeCode Connect plugin.
412 *
413 * @param $this
414 */
415 function ayecode_connect_helper($this) {
416 $connect_text = jQuery($this).text();
417 $connecting_text = jQuery($this).data('connecting');
418 $current_url = window.location.href + "&ayecode-connected=1";
419 $current_url = $current_url.replace("&external-connect-request=true", ""); // strip external request param
420 $current_url = $current_url.replace("&external-connect-request=1", ""); // strip external request param
421
422 jQuery.ajax({
423 type: "POST",
424 url: ajaxurl,
425 data: {
426 action: 'ayecode_connect_helper',
427 security: '<?php echo wp_create_nonce( 'ayecode-connect-helper' );?>',
428 redirect_to: $current_url
429 },
430 beforeSend: function () {
431 jQuery($this).html('<i class="fas fa-circle-notch fa-spin"></i> ' + $connecting_text).prop('disabled', true);// disable submit
432 },
433 success: function (data) {
434 console.log(data);
435 if (data.success == true && data.data.connect_url) {
436 window.location.href = data.data.connect_url;
437 } else if (data.success === false) {
438 alert(data.data);
439 jQuery($this).html($connect_text).prop('disabled', false);// enable submit
440 }
441 }
442 });
443 }
444 <?php
445 // add thickbox if external request is requested
446 if(! empty( $_REQUEST['external-connect-request'] )) {
447 ?>
448 jQuery(function () {
449 setTimeout(function () {
450 tb_show("AyeCode Connect", "?TB_inline?width=300&height=80&inlineId=ayecode-connect-helper-external-confirm");
451 }, 200);
452 });
453 <?php
454 }
455 ?>
456 </script>
457 <?php
458 }
459
460 /**
461 * Decide what pages to show on.
462 *
463 * @return bool
464 */
465 public function maybe_show() {
466 $show = false;
467
468 // check if on a page set to show
469 if ( isset( $_REQUEST['page'] ) && in_array( $_REQUEST['page'], $this->pages ) ) {
470 // check if not active and connected
471 if ( ! defined( 'AYECODE_CONNECT_VERSION' ) || ! get_option( 'ayecode_connect_blog_token' ) ) {
472 $show = true;
473 }
474 }
475
476 return $show;
477 }
478 }
479 }
480