PluginProbe
Disable Comments & Delete All Comments / trunk
Disable Comments & Delete All Comments vtrunk
1.3.3 1.3.2 trunk 1.0.0 1.0.4 1.0.5 1.0.8 1.0.9 1.1.1 1.1.3 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.3.0 1.3.1
comments-plus / libs / factory / templates / pages / class-page-license.php

class-page-license.php in Disable Comments & Delete All Comments trunk, at libs/factory/templates/pages/class-page-license.php

423 lines 13.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WBCR\Factory_Templates_134\Pages;
4
5 // Exit if accessed directly
6 if( !defined('ABSPATH') ) {
7 exit;
8 }
9
10 /**
11 * Class Wbcr_FactoryLicense000_LicensePage is used as template to display form to active premium functionality.
12 *
13 * @author Alex Kovalev <alex.kovalevv@gmail.com>, Github: https://github.com/alexkovalevv
14 * @since 2.0.7
15 */
16 class License extends PageBase {
17
18 /**
19 * {@inheritdoc}
20 *
21 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
22 * @since 2.1.2
23 * @var string
24 */
25 public $type = "page";
26
27 /**
28 * {@inheritdoc}
29 *
30 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
31 * @since 2.1.2
32 * @var string
33 */
34 public $page_menu_dashicon = 'dashicons-admin-network';
35
36 /**
37 * {@inheritdoc}
38 *
39 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
40 * @since 2.1.2
41 * @var bool
42 */
43 public $show_right_sidebar_in_options = false;
44
45 /**
46 * {@inheritdoc}
47 *
48 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
49 * @since 2.1.2
50 * @var int
51 */
52 public $page_menu_position = 0;
53
54 /**
55 * {@inheritdoc}
56 *
57 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
58 * @since 2.1.2
59 * @var bool
60 */
61 public $available_for_multisite = true;
62
63 /**
64 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
65 * @since 2.1.2
66 * @var string
67 */
68 public $plugin_name;
69
70 /**
71 * @var string Name of the paid plan.
72 */
73 public $plan_name;
74
75 // PREMIUM SECTION
76 // ------------------------------------------------------------------
77 /**
78 * @since 2.0.7
79 * @var bool
80 */
81 protected $is_premium;
82
83 /**
84 * @since 2.0.7
85 * @var \WBCR\Factory_480\Premium\Provider
86 */
87 protected $premium;
88
89 /**
90 * @since 2.0.7
91 * @var bool
92 */
93 protected $is_premium_active;
94
95 /**
96 * @since 2.0.7
97 * @var bool
98 */
99 protected $premium_has_subscription;
100
101 /**
102 * @since 2.0.7
103 * @var \WBCR\Factory_480\Premium\Interfaces\License
104 */
105 protected $premium_license;
106
107 // END PREMIUM SECTION
108 // ------------------------------------------------------------------
109
110 /**
111 * {@inheritdoc}
112 * @param \Wbcr_Factory480_Plugin $plugin
113 */
114 public function __construct(\Wbcr_Factory480_Plugin $plugin)
115 {
116 $this->plugin = $plugin;
117
118 parent::__construct($plugin);
119
120 if( !$this->id ) {
121 $this->id = $this->plugin->getPrefix() . 'license';
122 }
123
124 $this->plugin_name = $this->plugin->getPluginName();
125 $this->premium = $plugin->premium;
126 $this->is_premium = $this->premium->is_activate();
127 $this->is_premium_active = $this->premium->is_active();
128 $this->premium_has_subscription = $this->premium->has_paid_subscription();
129 $this->premium_license = $this->premium->get_license();
130
131 add_action("wp_ajax_wbcr-clearfy-activate-license-for-{$this->plugin_name}", [$this, 'ajax_handler']);
132 }
133
134 /**
135 * [MAGIC] Magic method that configures assets for a page.
136 */
137 public function assets($scripts, $styles)
138 {
139 parent::assets($scripts, $styles);
140
141 $this->styles->add(FACTORY_TEMPLATES_134_URL . '/assets/css/license-manager.css');
142 $this->scripts->add(FACTORY_TEMPLATES_134_URL . '/assets/js/clearfy-license-manager.js');
143 }
144
145 /**
146 * Регистрируем ajax обработчик для текущей страницы
147 *
148 * @since 2.0.7
149 */
150 public function ajax_handler()
151 {
152 wbcr_factory_templates_134_check_license($this->plugin);
153 }
154
155 /**
156 * {@inheritdoc}
157 */
158 public function showPageContent()
159 {
160 ?>
161 <div id="wcl-license-wrapper"
162 data-loader="<?php echo FACTORY_TEMPLATES_134_URL . '/assets/img/loader.gif'; ?>"
163 data-plugin-name="<?php echo esc_attr($this->plugin_name); ?>"
164 data-nonce="<?php echo wp_create_nonce("clearfy_activate_license_for_{$this->plugin_name}") ?>">
165 <?php $this->show_license_form(); ?>
166 </div>
167 <?php
168 }
169
170 /**
171 * Get before content.
172 *
173 * @return string Before content.
174 */
175 protected function get_plan_description()
176 {
177 return '';
178 }
179
180 /**
181 * @return string
182 */
183 protected function get_hidden_license_key()
184 {
185 if( !$this->is_premium ) {
186 return '';
187 }
188
189 return $this->premium_license->get_hidden_key();
190 }
191
192 /**
193 * @return string
194 */
195 protected function get_plan()
196 {
197 if( !$this->is_premium ) {
198 return 'free';
199 }
200
201 return $this->premium->get_plan();
202 }
203
204 /**
205 * @return mixed
206 */
207 protected function get_expiration_days()
208 {
209 if( !$this->is_premium ) {
210 return '';
211 }
212
213 return $this->premium_license->get_expiration_time('days');
214 }
215
216 /**
217 * @return string
218 */
219 protected function get_billing_cycle_readable()
220 {
221 if( !$this->is_premium ) {
222 return '';
223 }
224
225 $billing_cycle = $this->premium->get_billing_cycle();
226 $billing = 'lifetime';
227
228 if( 1 == $billing_cycle ) {
229 $billing = 'month';
230 } else if( 12 == $billing_cycle ) {
231 $billing = 'year';
232 }
233
234 return $billing;
235 }
236
237 /**
238 * Тип лицензии, цветовое оформление для формы лицензирования
239 * free - бесплатная
240 * gift - пожизненная лицензия, лицензия на особы�
241 условия�
242
243 * trial - красный цвет, применяется для триалов, если лиценизия истекла или заблокирована
244 * paid - обычная оплаченная лицензия, в данный момент активна.
245 *
246 * @return string
247 */
248 protected function get_license_type()
249 {
250 if( !$this->is_premium ) {
251 return 'free';
252 }
253
254 $license = $this->premium_license;
255
256 if( $license->is_lifetime() ) {
257 return 'gift';
258 } else if( $license->get_expiration_time('days') < 1 ) {
259 return 'trial';
260 }
261
262 return 'paid';
263 }
264
265 protected function render_learnmore_section()
266 {
267 if( $this->is_premium ):
268 ?>
269 <p style="margin-top: 10px;">
270 <?php printf(__('<a href="%s" target="_blank" rel="noopener">Lean more</a> about the premium version and get the license key to activate it now!', 'wbcr_factory_templates_134'), $this->plugin->get_support()->get_pricing_url(true, 'license_page')); ?>
271 </p>
272 <?php else: ?>
273 <p style="margin-top: 10px;">
274 <?php printf(__('Can’t find your key? Go to <a href="%s" target="_blank" rel="noopener">this page</a> and login using the e-mail address associated with your purchase.', 'wbcr_factory_templates_134'), $this->plugin->get_support()->get_contacts_url(true, 'license_page')) ?>
275 </p>
276 <?php endif;
277 }
278
279 /**
280 * @param bool|WP_Error $notice
281 */
282 public function show_license_form($notice = false)
283 {
284 ?>
285 <div id="license-manager"
286 class="factory-bootstrap-482 onp-page-wrap <?php echo $this->get_license_type() ?>-license-manager-content">
287 <div>
288 <h3><?php printf(__('Activate %s', 'wbcr_factory_templates_134'), $this->plan_name) ?></h3>
289 <?php echo $this->get_plan_description() ?>
290 </div>
291 <br>
292 <?php if( is_wp_error($notice) ) : ?>
293 <div class="license-message <?php echo $this->get_license_type() ?>-license-message">
294 <div class="alert <?php echo esc_attr($notice->get_error_code()); ?>">
295 <h4 class="alert-heading"><?php _e($notice->get_error_message(), 'wbcr_factory_templates_134') ?></h4>
296 </div>
297 </div>
298 <?php endif; ?>
299 <div class="onp-container">
300 <div class="license-details">
301 <?php if( $this->get_license_type() == 'free' ): ?>
302 <a href="<?php echo $this->plugin->get_support()->get_pricing_url(true, 'license_page'); ?>"
303 class="purchase-premium" target="_blank" rel="noopener">
304 <span class="btn btn-gold btn-inner-wrap">
305 <?php _e('Upgrade to Premium', 'wbcr_factory_templates_134') ?>
306 </span>
307 </a>
308 <p><?php printf(__('Your current license for %1$s:', 'wbcr_factory_templates_134'), $this->plugin->getPluginTitle()) ?></p>
309 <?php endif; ?>
310 <div class="license-details-block <?php echo $this->get_license_type() ?>-details-block">
311 <?php if( $this->is_premium ): ?>
312 <a data-action="deactivate" href="#"
313 class="btn btn-default btn-small license-delete-button wcl-control-btn">
314 <?php _e('Delete Key', 'wbcr_factory_templates_134') ?>
315 </a>
316 <a data-action="sync" href="#"
317 class="btn btn-default btn-small license-synchronization-button wcl-control-btn">
318 <?php _e('Synchronization', 'wbcr_factory_templates_134') ?>
319 </a>
320 <?php endif; ?>
321 <h3>
322 <?php echo ucfirst($this->get_plan()); ?>
323
324 <?php if( $this->is_premium && $this->premium_has_subscription ): ?>
325 <span style="font-size: 15px;">
326 (<?php printf(__('Automatic renewal, every %s', ''), esc_attr($this->get_billing_cycle_readable())); ?>)
327 </span>
328 <?php endif; ?>
329 </h3>
330 <?php if( $this->is_premium ): ?>
331 <div class="license-key-identity">
332 <code><?php echo esc_attr($this->get_hidden_license_key()) ?></code>
333 </div>
334 <?php endif; ?>
335 <div class="license-key-description">
336 <?php if( !$this->is_premium ): ?>
337 <p><?php _e('Public License is a GPLv3 compatible license allowing you to change and use this version of the plugin for free. Please keep in mind this license covers only free edition of the plugin. Premium versions are distributed with other type of a license.', 'wbcr_factory_templates_134') ?></p>
338 <?php else: ?>
339 <p><?php _e('Сommercial license, only to the premium add-on to this free plugin. You cannot distribute or modify the premium add-on. But free plugin is a GPLv3 compatible license allowing you to change and use this version of the plugin for free.', 'wbcr_factory_templates_134') ?></p>
340 <?php endif; ?>
341 <?php if( $this->is_premium && $this->premium_has_subscription ): ?>
342 <p class="activate-trial-hint">
343 <?php _e('You use a paid subscription for the plugin updates. In case you don’t want to receive paid updates, please, click <a data-action="unsubscribe" class="wcl-control-btn" href="#">cancel subscription</a>', 'wbcr_factory_templates_134') ?>
344 </p>
345 <?php endif; ?>
346
347 <?php if( $this->get_license_type() == 'trial' ): ?>
348 <p class="activate-error-hint">
349 <?php printf(__('Your license has expired, please extend the license to get updates and support.', 'wbcr_factory_templates_134'), '') ?>
350 </p>
351 <?php endif; ?>
352 </div>
353 <table class="license-params" colspacing="0" colpadding="0">
354 <tr>
355 <!--<td class="license-param license-param-domain">
356 <span class="license-value"><?php echo esc_attr($_SERVER['SERVER_NAME']); ?></span>
357 <span class="license-value-name"><?php _e('domain', 'wbcr_factory_templates_134') ?></span>
358 </td>-->
359 <td class="license-param license-param-days">
360 <span class="license-value"><?php echo $this->get_plan() ?></span>
361 <span class="license-value-name"><?php _e('plan', 'wbcr_factory_templates_134') ?></span>
362 </td>
363 <?php if( $this->is_premium ) : ?>
364 <td class="license-param license-param-sites">
365 <span class="license-value">
366 <?php echo esc_attr($this->premium_license->get_count_active_sites()); ?>
367 <?php _e('of', 'wbcr_factory_templates_134') ?>
368 <?php echo esc_attr($this->premium_license->get_sites_quota()); ?></span>
369 <span class="license-value-name"><?php _e('active sites', 'wbcr_factory_templates_134') ?></span>
370 </td>
371 <?php endif; ?>
372 <td class="license-param license-param-version">
373 <span class="license-value"><?php echo $this->plugin->getPluginVersion() ?></span>
374 <span class="license-value-name"><span>version</span></span>
375 </td>
376 <?php if( $this->is_premium ): ?>
377 <td class="license-param license-param-days">
378 <?php if( $this->get_license_type() == 'trial' ): ?>
379 <span class="license-value"><?php _e('EXPIRED!', 'wbcr_factory_templates_134') ?></span>
380 <span class="license-value-name"><?php _e('please update the key', 'wbcr_factory_templates_134') ?></span>
381 <?php else: ?>
382 <span class="license-value">
383 <?php
384 if( $this->premium_license->is_lifetime() ) {
385 echo 'infiniate';
386 } else {
387 echo $this->get_expiration_days();
388 }
389 ?>
390 <small> <?php _e('day(s)', 'wbcr_factory_templates_134') ?></small>
391 </span>
392 <span class="license-value-name"><?php _e('remained', 'wbcr_factory_templates_134') ?></span>
393 <?php endif; ?>
394 </td>
395 <?php endif; ?>
396 </tr>
397 </table>
398 </div>
399 </div>
400 <div class="license-input">
401 <form action="" method="post">
402 <?php if($this->is_premium): ?>
403 <p><?php _e('Have a key to activate the premium version? Paste it here:', 'wbcr_factory_templates_134') ?><p>
404 <?php else: ?>
405 <p><?php _e('Have a key to activate the plugin? Paste it here:', 'wbcr_factory_templates_134') ?>
406 <p>
407 <?php endif; ?>
408 <button data-action="activate" class="btn btn-default wcl-control-btn" type="button"
409 id="license-submit">
410 <?php _e('Submit Key', 'wbcr_factory_templates_134') ?>
411 </button>
412 <div class="license-key-wrap">
413 <input type="text" id="license-key" name="licensekey" value="" class="form-control"/>
414 </div>
415 <?php $this->render_learnmore_section(); ?>
416 </form>
417 </div>
418 </div>
419 </div>
420 <?php
421 }
422 }
423