PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 1.6.4
Kubio AI Page Builder v1.6.4
2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / src / Core / License / ActivationForm.php
kubio / lib / src / Core / License Last commit date
ActivationForm.php 4 years ago CheckForm.php 4 years ago Endpoint.php 4 years ago License.php 4 years ago RequestResponse.php 4 years ago Updater.php 4 years ago
ActivationForm.php
177 lines
1 <?php
2 namespace Kubio\Core\License;
3
4 use Kubio\Core\LodashBasic;
5 use Kubio\Core\License\License;
6 use Kubio\Core\License\Updater;
7 use Kubio\Flags;
8 use Plugin_Upgrader;
9
10 class ActivationForm {
11 public function __construct() {
12 add_action( 'wp_ajax_kubiowp-page-builder-activate', array( $this, 'callActivateLicenseEndpoint' ) );
13 add_action( 'wp_ajax_kubiowp-page-builder-maybe-install-pro', array( $this, 'maybeInstallPRO' ) );
14 }
15
16 public function printForm() {
17 add_action( 'admin_notices', array( $this, 'makeActivateNotice' ) );
18 $this->enqueue();
19 }
20
21 public function enqueue() {
22 wp_enqueue_script( 'wp-util' );
23 }
24
25 public function makeUpgradeView( $message = '' ) {
26 ?>
27 <div class="kubio-page-builder-upgade-view kubio-admin-panel">
28 <div class="kubio-page-builder-license-notice kubio-page-builder-activate-license">
29 <h3 class="notice_title"><?php esc_html_e( 'Enter a valid Kubio PRO license key to unlock all the PRO features', 'kubio' ); ?></h3>
30 <?php echo $this->formHtml( $message ); ?>
31 </div>
32 </div>
33 <?php
34 }
35
36 public function makeActivateNotice( $formId = '', $classHhtml = array(), $message = '' ) {
37 if ( ! array( $classHhtml ) ) {
38 $classHhtml = array( $classHhtml );
39 }
40 if ( $formId !== '' ) {
41 $formId = ' id="' . $formId . '"';
42 }
43 $classHhtml = implode( ' ', $classHhtml );
44 ?>
45 <div class="notice notice-error is-dismissible kubio-activation-wrapper <?php echo $classHhtml; ?>"<?php echo $formId; ?>>
46 <div class="notification-logo-wrapper">
47 <div class="notification-logo">
48 <?php echo wp_kses_post( KUBIO_LOGO_SVG ); ?>
49 </div>
50 </div>
51 <div class="kubio-page-builder-license-notice kubio-page-builder-activate-license">
52 <h1 class="notice_title"><?php esc_html_e( 'Activate Kubio PRO License', 'kubio' ); ?></h1>
53 <h3 class="notice_sub_title"><?php esc_html_e( 'If this is a testing site you can ignore this message. If this is your live site then please insert the license key below.', 'kubio' ); ?></h3>
54 <?php echo $this->formHtml( $message ); ?>
55 </div>
56 </div>
57 <?php
58 }
59
60 public function formHtml( $message = '' ) {
61 $html = '<div class="kubio-page-builder-activate-license-form_wrapper">
62 <form id="kubio-page-builder-activate-license-form" class="activate-form">
63 <input placeholder="6F474380-5929B874-D2E0CB90-C7282097" type="text"
64 value="' . esc_attr( get_option( 'kubio_sync_data_source', '' ) ) . '"
65 class="regular-text">
66 <button type="submit" class="button button-primary">' . esc_html__( 'Activate License', 'kubio' ) . '</button>
67 </form>
68 ' . $this->formMessage( $message ) . '
69 </div>';
70
71 return $html;
72 }
73
74 public function formMessage( $message = '' ) {
75 $html = '';
76 if ( '' === $message ) {
77 $html .= '<p id="kubio-page-builder-activate-license-message" class="message" style="display: none;"></p>';
78 } else {
79 $html .= '<p id="kubio-page-builder-activate-license-message" class="message">' . $message . '</p>';
80 }
81
82 $html .= '<p class="description">';
83 $html .= sprintf( __( 'Your key was sent via email when the purchase was completed. Also you can find the key in the %1$s of your %2$s account', 'kubio' ), '<a href="' . esc_attr( License::getInstance()->getDashboardUrl() ) . '/#/my-plans" target="_blank">My plans</a>', '<a href="' . esc_attr( License::getInstance()->getDashboardUrl() ) . '" target="_blank">Kubio</a>' );
84 $html .= '</p>
85 <div class="spinner-holder plugin-installer-spinner" style="display: none;">
86 <span class="icon">
87 <span class="loader">' . kubio_get_iframe_loader(
88 array(
89 'size' => '19px',
90 'color' => '#2271B1',
91 )
92 ) . '</span>
93 <span class="ok"><span class="dashicons dashicons-before dashicons-yes"></span></span>
94 </span>
95 <span class="message"></span>
96 </div>';
97
98 return $html;
99 }
100
101 public function callActivateLicenseEndpoint() {
102 $key = isset( $_REQUEST['key'] ) ? $_REQUEST['key'] : false;
103
104 if ( ! $key ) {
105 wp_send_json_error( esc_html__( 'License key is empty', 'kubio' ), 403 );
106 }
107
108 License::getInstance()->setLicenseKey( $key );
109 $response = Endpoint::activate();
110
111 if ( $response->isError() ) {
112 License::getInstance()->setLicenseKey( null );
113 }
114
115 wp_send_json(
116 array(
117 'data' => $response->getMessage( true ),
118 'success' => $response->isSuccess(),
119 ),
120 $response->getResponseCode()
121 );
122 }
123
124 public function maybeInstallPRO() {
125 add_filter(
126 'kubio/companion/update_remote_data',
127 function ( $data ) {
128 $data['args'] = array(
129 'product' => 'kubio-pro',
130 'key' => License::getInstance()->getLicenseKey(),
131 );
132
133 $data['plugin_path'] = 'kubio-pro/plugin.php';
134
135 return $data;
136 },
137 PHP_INT_MAX
138 );
139
140 $status = (array) Updater::getInstance()->isUpdateAvailable();
141 $url = LodashBasic::array_get_value( $status, 'package_url', false );
142
143 if ( $url ) {
144
145 if ( ! function_exists( 'plugins_api' ) ) {
146 include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
147 }
148
149 if ( ! class_exists( 'Plugin_Upgrader' ) ) {
150 /** Plugin_Upgrader class */
151 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
152 }
153
154 $upgrader = new Plugin_Upgrader( new \Automatic_Upgrader_Skin() );
155 $result = $upgrader->install( $url );
156
157 if ( $result !== true && $result !== null ) {
158 wp_send_json_error();
159 }
160
161 $ac = get_option( 'active_plugins' );
162 $ac = array_diff( $ac, array( 'kubio/plugin.php' ) );
163 $ac[] = 'kubio-pro/plugin.php';
164 update_option( 'active_plugins', $ac );
165
166 // set the kubio pro plugin activation time
167 if ( ! Flags::get( 'kubio_pro_activation_time', false ) ) {
168 Flags::set( 'kubio_pro_activation_time', time() );
169 }
170
171 wp_send_json_success( array( 'message' => esc_html__( 'No error', 'kubio' ) ) );
172 }
173
174 wp_send_json_success( $status );
175 }
176 }
177