PluginProbe
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits / 3.1.9
Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits v3.1.9
3.2.2 3.2.3 3.2.1 3.2.0 3.1.9 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.9 trunk 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.3 1.1.4 1.1.5 All 174 releases
master-addons / inc / modules / dynamic / conditions / content-protection / content-protection.php

content-protection.php in Master Addons for Elementor – Elementor Addons, Widgets, Mega Menu Builder, Popup Builder, Widget Builder & Template Kits 3.1.9, at inc/modules/dynamic/conditions/content-protection/content-protection.php

1,417 lines 39.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace MasterAddons\Inc\Modules\Dynamic\Conditions\ContentProtection;
4
5 if (!defined('ABSPATH')) exit;
6
7 // Elementor classes used in this file are imported below (before the classes).
8 use MasterAddons\Inc\Classes\Helper;
9
10 class JLTMA_Protected_Content
11 {
12
13 protected static $_instance = null;
14
15 public static function instance()
16 {
17 if (is_null(self::$_instance)) {
18 self::$_instance = new self();
19 }
20 return self::$_instance;
21 }
22
23 public function __construct()
24 {
25 $this->init_hooks();
26 }
27
28 public static function init_hooks()
29 {
30 add_action('elementor/element/section/section_advanced/after_section_end', [__CLASS__, 'add_section']);
31 add_action('elementor/element/common/_section_style/after_section_end', [__CLASS__, 'add_section'], 1);
32 add_filter('elementor/frontend/widget/should_render', [__CLASS__, 'add_filter'], 10, 3);
33 add_filter('elementor/frontend/section/should_render', [__CLASS__, 'add_filter'], 10, 3);
34 add_action('elementor/frontend/widget/before_render', [__CLASS__, 'before_render']);
35 add_action('elementor/frontend/section/before_render', [__CLASS__, 'before_render']);
36 }
37
38 public static function add_filter($bool, $element)
39 {
40 $settings = $element->get_settings();
41 if ($settings['jltma_protected_content_enable']) {
42 if (($settings['jltma_protected_content_type'] == 'user_role') && (!empty($settings['jltma_protected_content_roles']))) {
43 if (is_user_logged_in()) {
44 $user = wp_get_current_user();
45 $user_role = (array) $user->roles;
46 if (array_intersect($user_role, $settings['jltma_protected_content_roles'])) {
47 return true;
48 } else {
49 return false;
50 }
51 } else {
52 return false;
53 }
54 } elseif ($settings['jltma_protected_content_type'] == 'capability') {
55 if (is_user_logged_in()) {
56 if (current_user_can($settings['jltma_protected_content_capability'])) {
57 return true;
58 } else {
59 return false;
60 }
61 } else {
62 return false;
63 }
64 } elseif ($settings['jltma_protected_content_type'] == 'login_status') {
65 if ((is_user_logged_in()) && ($settings['jltma_protected_content_login_status'] == 'logged_in')) {
66 return true;
67 } elseif ((!is_user_logged_in()) && ($settings['jltma_protected_content_login_status'] == 'logged_out')) {
68 return true;
69 } else {
70 return false;
71 }
72 } elseif ($settings['jltma_protected_content_type'] == 'password') {
73 // Public front-end content gate: read-only password comparison with no
74 // state change, so a nonce is not applicable (mirrors core post-password).
75 $submitted_password = isset($_GET['password']) ? sanitize_text_field(wp_unslash($_GET['password'])) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
76 if (null === $submitted_password) {
77 return false;
78 } elseif ($submitted_password !== $settings['jltma_protected_content_password']) {
79 return false;
80 } else {
81 return true;
82 }
83 } else {
84 return true;
85 }
86 } else {
87 return true;
88 }
89 }
90
91 public static function before_render(Element_Base $element)
92 {
93 $settings = $element->get_settings();
94 if ($settings['jltma_protected_content_enable']) {
95 // Public front-end content gate: read-only password comparison, no state
96 // change, so a nonce is not applicable (mirrors core post-password).
97 $submitted_password = isset($_GET['password']) ? sanitize_text_field(wp_unslash($_GET['password'])) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
98 if (null === $submitted_password || $submitted_password !== $settings['jltma_protected_content_password']) {
99 if ($settings['jltma_protected_content_type'] == 'password') { ?>
100 <form class="tmea-password-protection" action="<?php the_permalink(); ?>" style="display:flex;flex-direction:column;width:100%;max-width:<?php echo esc_attr($settings['jltma_protected_content_password_width']['size']) . esc_attr($settings['jltma_protected_content_password_width']['unit']); ?>;margin:<?php echo esc_attr($settings['jltma_protected_content_password_spacing']['size']) . esc_attr($settings['jltma_protected_content_password_spacing']['unit']); ?> auto;">
101 <?php
102 if ($settings['jltma_protected_content_password_desc']) {
103 echo '<label class="' . esc_attr($settings['jltma_protected_content_password_label_class']) . '">' . esc_html($settings['jltma_protected_content_password_desc']) . '</label>';
104 } ?>
105 <div class="tmea-password-protection-inner" style="display:flex;align-items:stretch;">
106 <input id="password" name="password" type="text" class="<?php echo esc_attr($settings['jltma_protected_content_password_input_class']); ?>" placeholder="<?php esc_attr_e('Enter Password', 'master-addons'); ?>" maxlength="80" />
107 <button id="submit" type="submit" class="<?php echo esc_attr($settings['jltma_protected_content_password_btn_class']); ?>"><?php esc_html_e('Submit', 'master-addons'); ?></button>
108 </div>
109 </form>
110 <?php }
111 }
112 }
113 }
114
115 public static function add_section(Element_Base $element)
116 {
117
118 $element->start_controls_section(
119 '_section_protected_content',
120 [
121 'label' => esc_html__('TMEA Protected Content', 'master-addons'),
122 'tab' => \Elementor\Controls_Manager::TAB_ADVANCED,
123 ]
124 );
125
126 $element->add_control(
127 'jltma_protected_content_enable',
128 [
129 'label' => esc_html__('Protect Content', 'master-addons'),
130 'type' => \Elementor\Controls_Manager::SWITCHER,
131 'return_value' => 'yes',
132 'frontend_available' => true
133 ]
134 );
135
136 $element->add_control(
137 'jltma_protected_content_type',
138 [
139 'label' => esc_html__('Protection Type', 'master-addons'),
140 'type' => Controls_Manager::SELECT,
141 'options' => [
142 'login_status' => esc_html__('Login Status', 'master-addons'),
143 'user_role' => esc_html__('User Role', 'master-addons'),
144 'capability' => esc_html__('User Capability', 'master-addons'),
145 'password' => esc_html__('Password', 'master-addons')
146 ],
147 'default' => 'login_status',
148 'condition' => [
149 'jltma_protected_content_enable' => 'yes'
150 ]
151 ]
152 );
153
154 $element->add_control(
155 'jltma_protected_content_login_status',
156 [
157 'label' => esc_html__('Login Status', 'master-addons'),
158 'type' => Controls_Manager::SELECT,
159 'options' => [
160 'logged_in' => esc_html__('Logged In', 'master-addons'),
161 'logged_out' => esc_html__('Logged Out', 'master-addons')
162 ],
163 'default' => 'logged_in',
164 'conditions' => [
165 'relation' => 'and',
166 'terms' => [
167 [
168 'name' => 'jltma_protected_content_enable',
169 'value' => 'yes',
170 ],
171 [
172 'name' => 'jltma_protected_content_type',
173 'value' => 'login_status',
174 ]
175 ]
176 ],
177 ]
178 );
179
180 $element->add_control(
181 'jltma_protected_content_roles',
182 [
183 'label' => esc_html__('Roles (Required)', 'master-addons'),
184 'type' => \Elementor\Controls_Manager::SELECT2,
185 'label_block' => 'true',
186 'description' => '<a href="https://wordpress.org/support/article/roles-and-capabilities/" target="_blank">' . esc_html__('Learn more about roles and capabilities', 'master-addons') . '</a>',
187 'multiple' => true,
188 'default' => '',
189 'options' => Helper::jltma_get_user_roles(),
190 'conditions' => [
191 'relation' => 'and',
192 'terms' => [
193 [
194 'name' => 'jltma_protected_content_enable',
195 'value' => 'yes',
196 ],
197 [
198 'name' => 'jltma_protected_content_type',
199 'value' => 'user_role',
200 ]
201 ]
202 ],
203 ]
204 );
205
206 $element->add_control(
207 'jltma_protected_content_capability',
208 [
209 'label' => esc_html__('Capability (Required)', 'master-addons'),
210 'type' => \Elementor\Controls_Manager::TEXT,
211 'default' => 'manage_options',
212 'description' => '<a href="https://wordpress.org/support/article/roles-and-capabilities/" target="_blank">' . esc_html__('Learn more about roles and capabilities', 'master-addons') . '</a>',
213 'conditions' => [
214 'relation' => 'and',
215 'terms' => [
216 [
217 'name' => 'jltma_protected_content_enable',
218 'value' => 'yes',
219 ],
220 [
221 'name' => 'jltma_protected_content_type',
222 'value' => 'capability',
223 ]
224 ]
225 ],
226 ]
227 );
228
229 $element->add_control(
230 'jltma_protected_content_password',
231 [
232 'label' => esc_html__('Password (Required)', 'master-addons'),
233 'type' => \Elementor\Controls_Manager::TEXT,
234 'default' => '123456',
235 'conditions' => [
236 'relation' => 'and',
237 'terms' => [
238 [
239 'name' => 'jltma_protected_content_enable',
240 'value' => 'yes',
241 ],
242 [
243 'name' => 'jltma_protected_content_type',
244 'value' => 'password',
245 ]
246 ]
247 ],
248 ]
249 );
250
251 $element->add_control(
252 'jltma_protected_content_password_desc',
253 [
254 'label' => esc_html__('Description', 'master-addons'),
255 'type' => \Elementor\Controls_Manager::TEXT,
256 'conditions' => [
257 'relation' => 'and',
258 'terms' => [
259 [
260 'name' => 'jltma_protected_content_enable',
261 'value' => 'yes',
262 ],
263 [
264 'name' => 'jltma_protected_content_type',
265 'value' => 'password',
266 ]
267 ]
268 ],
269 ]
270 );
271
272 $element->add_control(
273 'jltma_protected_content_hr_1',
274 [
275 'type' => \Elementor\Controls_Manager::DIVIDER,
276 'conditions' => [
277 'relation' => 'and',
278 'terms' => [
279 [
280 'name' => 'jltma_protected_content_enable',
281 'value' => 'yes',
282 ],
283 [
284 'name' => 'jltma_protected_content_type',
285 'value' => 'password',
286 ]
287 ]
288 ],
289 ]
290 );
291
292 $element->add_responsive_control(
293 'jltma_protected_content_password_width',
294 [
295 'label' => esc_html__('Maximum Form Width', 'master-addons'),
296 'type' => Controls_Manager::SLIDER,
297 'size_units' => ['px', '%', 'rem'],
298 'range' => [
299 '%' => [
300 'min' => 0,
301 'max' => 100,
302 ],
303 'px' => [
304 'min' => 0,
305 'max' => 1000,
306 ],
307 'rem' => [
308 'min' => 0,
309 'max' => 100,
310 ],
311 ],
312 'default' => [
313 'unit' => 'px',
314 'size' => 600,
315 ],
316 'conditions' => [
317 'relation' => 'and',
318 'terms' => [
319 [
320 'name' => 'jltma_protected_content_enable',
321 'value' => 'yes',
322 ],
323 [
324 'name' => 'jltma_protected_content_type',
325 'value' => 'password',
326 ]
327 ]
328 ],
329 ]
330 );
331
332 $element->add_responsive_control(
333 'jltma_protected_content_password_spacing',
334 [
335 'label' => esc_html__('Spacing', 'master-addons'),
336 'type' => Controls_Manager::SLIDER,
337 'size_units' => ['px'],
338 'range' => [
339 'px' => [
340 'min' => 1,
341 'max' => 100,
342 ],
343 ],
344 'default' => [
345 'unit' => 'px',
346 'size' => 80,
347 ],
348 'conditions' => [
349 'relation' => 'and',
350 'terms' => [
351 [
352 'name' => 'jltma_protected_content_enable',
353 'value' => 'yes',
354 ],
355 [
356 'name' => 'jltma_protected_content_type',
357 'value' => 'password',
358 ]
359 ]
360 ],
361 ]
362 );
363
364 $element->add_control(
365 'jltma_protected_content_password_input_class',
366 [
367 'label' => esc_html__('Input Class', 'master-addons'),
368 'type' => \Elementor\Controls_Manager::TEXT,
369 'default' => 'form-control',
370 'conditions' => [
371 'relation' => 'and',
372 'terms' => [
373 [
374 'name' => 'jltma_protected_content_enable',
375 'value' => 'yes',
376 ],
377 [
378 'name' => 'jltma_protected_content_type',
379 'value' => 'password',
380 ]
381 ]
382 ],
383 ]
384 );
385
386 $element->add_control(
387 'jltma_protected_content_password_btn_class',
388 [
389 'label' => esc_html__('Button Class', 'master-addons'),
390 'type' => \Elementor\Controls_Manager::TEXT,
391 'default' => 'btn btn-primary',
392 'conditions' => [
393 'relation' => 'and',
394 'terms' => [
395 [
396 'name' => 'jltma_protected_content_enable',
397 'value' => 'yes',
398 ],
399 [
400 'name' => 'jltma_protected_content_type',
401 'value' => 'password',
402 ]
403 ]
404 ],
405 ]
406 );
407
408 $element->add_control(
409 'jltma_protected_content_password_label_class',
410 [
411 'label' => esc_html__('Label Class', 'master-addons'),
412 'type' => \Elementor\Controls_Manager::TEXT,
413 'conditions' => [
414 'relation' => 'and',
415 'terms' => [
416 [
417 'name' => 'jltma_protected_content_enable',
418 'value' => 'yes',
419 ],
420 [
421 'name' => 'jltma_protected_content_type',
422 'value' => 'password',
423 ]
424 ]
425 ],
426 ]
427 );
428
429 $element->end_controls_section();
430 }
431 }
432
433 JLTMA_Protected_Content::instance();
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454 namespace MasterAddons\Modules;
455
456 /**
457 * Content protection class
458 *
459 * @package MasterAddons\Modules
460 */
461
462
463 use \Elementor\Controls_Manager;
464 use \Elementor\Frontend;
465 use \Elementor\Group_Control_Border;
466 use \Elementor\Group_Control_Box_Shadow;
467 use \Elementor\Group_Control_Typography;
468 use \Elementor\Core\Kits\Documents\Tabs\Global_Typography;
469
470 use MasterAddons\Inc\Classes\Helper;
471 use \MasterAddons\Inc\Classes\Extension_Prototype;
472
473 /**
474 * Class Content_Protection
475 *
476 * @package MasterAddons\Modules
477 */
478 if (!class_exists('MasterAddons\Modules\Extension_Content_Protection')) {
479 class Extension_Content_Protection extends Extension_Prototype
480 {
481
482 private static $instance = null;
483 public $name = 'Content Protection';
484 /**
485 * Content_Protection constructor.
486 */
487 public function __construct()
488 {
489 add_action('elementor/element/common/_section_style/after_section_end', array($this, 'register_controls'), 10);
490 add_action('elementor/widget/render_content', array($this, 'render_content'), 10, 2);
491 }
492
493 /**
494 * Register Content Protection Controls.
495 *
496 * @param Object $element Elementor instance.
497 */
498 public function register_controls($element)
499 {
500 $element->start_controls_section(
501 'jltma_content_protection_section',
502 [
503 'label' => esc_html__('Content Protection', 'master-addons' ),
504 'tab' => Controls_Manager::TAB_ADVANCED,
505 ]
506 );
507
508 $element->add_control(
509 'jltma_content_protection',
510 [
511 'label' => __('Enable Content Protection', 'master-addons' ),
512 'type' => Controls_Manager::SWITCHER,
513 'default' => 'no',
514 'label_on' => __('Yes', 'master-addons' ),
515 'label_off' => __('No', 'master-addons' ),
516 'return_value' => 'yes',
517 ]
518 );
519
520 $element->add_control(
521 'jltma_content_protection_type',
522 [
523 'label' => esc_html__('Protection Type', 'master-addons' ),
524 'label_block' => false,
525 'type' => Controls_Manager::SELECT,
526 'options' => [
527 'role' => esc_html__('User role', 'master-addons' ),
528 'password' => esc_html__('Password protected', 'master-addons' ),
529 'logged-in' => esc_html__('User is logged', 'master-addons' ),
530 'start-end-date' => esc_html__('Start / End date', 'master-addons' ),
531 'days-of-the-week' => esc_html__('Days of the week', 'master-addons' ),
532 ],
533 'default' => 'role',
534 'condition' => [
535 'jltma_content_protection' => 'yes',
536 ],
537 ]
538 );
539
540 $element->add_control(
541 'jltma_content_protection_role',
542 [
543 'label' => __('Select Roles', 'master-addons' ),
544 'type' => Controls_Manager::SELECT2,
545 'label_block' => true,
546 'multiple' => true,
547 'options' => $this->get_user_roles(),
548 'condition' => [
549 'jltma_content_protection' => 'yes',
550 'jltma_content_protection_type' => 'role',
551 ],
552 ]
553 );
554
555 $element->add_control(
556 'jltma_content_protection_password',
557 [
558 'label' => esc_html__('Set Password', 'master-addons' ),
559 'type' => Controls_Manager::TEXT,
560 'input_type' => 'password',
561 'condition' => [
562 'jltma_content_protection' => 'yes',
563 'jltma_content_protection_type' => 'password',
564 ],
565 ]
566 );
567
568 $element->add_control(
569 'jltma_content_protection_password_placeholder',
570 [
571 'label' => esc_html__('Input Placeholder', 'master-addons' ),
572 'type' => Controls_Manager::TEXT,
573 'default' => 'Enter Password',
574 'condition' => [
575 'jltma_content_protection' => 'yes',
576 'jltma_content_protection_type' => 'password',
577 ],
578 ]
579 );
580
581 $element->add_control(
582 'jltma_content_protection_password_submit_btn_txt',
583 [
584 'label' => esc_html__('Submit Button Text', 'master-addons' ),
585 'type' => Controls_Manager::TEXT,
586 'default' => 'Submit',
587 'condition' => [
588 'jltma_content_protection' => 'yes',
589 'jltma_content_protection_type' => 'password',
590 ],
591 ]
592 );
593
594 $date_format = get_option('date_format');
595 $time_format = get_option('time_format');
596 $current_time = gmdate($date_format . ' ' . $time_format);
597 /* translators: %s is the current time */
598 $description = sprintf(__('Current time: %s', 'master-addons' ), $current_time);
599
600 $element->add_control(
601 'server_time_note',
602 [
603 'type' => Controls_Manager::RAW_HTML,
604 'raw' => $description,
605 'conditions' => [
606 'relation' => 'or',
607 'terms' => [
608 [
609 'name' => 'jltma_content_protection_type',
610 'operator' => '===',
611 'value' => 'start-end-date',
612 ],
613 [
614 'name' => 'jltma_content_protection_type',
615 'operator' => '===',
616 'value' => 'days-of-the-week',
617 ],
618 ],
619 ],
620 ]
621 );
622
623 $element->add_control(
624 'jltma_content_protection_period_date',
625 [
626 'label' => __('Period', 'master-addons' ),
627 'type' => Controls_Manager::DATE_TIME,
628 'condition' => [
629 'jltma_content_protection' => 'yes',
630 'jltma_content_protection_type' => 'start-end-date',
631 ],
632 'picker_options' => [
633 'mode' => 'range',
634 ],
635 ]
636 );
637
638 $element->add_control(
639 'jltma_content_protection_days_of_week',
640 [
641 'label' => __('Every', 'master-addons' ),
642 'type' => Controls_Manager::SELECT2,
643 'label_block' => true,
644 'multiple' => true,
645 'options' => $this->get_days_of_week(),
646 'condition' => [
647 'jltma_content_protection' => 'yes',
648 'jltma_content_protection_type' => 'days-of-the-week',
649 ],
650 ]
651 );
652
653 $element->add_control(
654 'jltma_content_protection_days_of_week_time_from',
655 [
656 'label' => __('From', 'master-addons' ),
657 'type' => Controls_Manager::DATE_TIME,
658 'condition' => [
659 'jltma_content_protection' => 'yes',
660 'jltma_content_protection_type' => 'days-of-the-week',
661 'jltma_content_protection_days_of_week!' => '',
662 ],
663 'picker_options' => [
664 'noCalendar' => true,
665 'enableTime' => true,
666 'dateFormat' => 'h:i K',
667 ],
668 ]
669 );
670
671 $element->add_control(
672 'jltma_content_protection_days_of_week_time_to',
673 [
674 'label' => __('To', 'master-addons' ),
675 'type' => Controls_Manager::DATE_TIME,
676 'condition' => [
677 'jltma_content_protection' => 'yes',
678 'jltma_content_protection_type' => 'days-of-the-week',
679 'jltma_content_protection_days_of_week!' => '',
680 'jltma_content_protection_days_of_week_time_from!' => '',
681 ],
682 'picker_options' => [
683 'noCalendar' => true,
684 'enableTime' => true,
685 'dateFormat' => 'h:i K',
686 ],
687 ]
688 );
689
690 $element->start_controls_tabs(
691 'jltma_content_protection_tabs',
692 [
693 'condition' => [
694 'jltma_content_protection' => 'yes',
695 ],
696 ]
697 );
698
699 $element->start_controls_tab(
700 'jltma_content_protection_tab_message',
701 [
702 'label' => __('Message', 'master-addons' ),
703 ]
704 );
705
706 $element->add_control(
707 'jltma_content_protection_message_type',
708 [
709 'label' => esc_html__('Message Type', 'master-addons' ),
710 'label_block' => false,
711 'type' => Controls_Manager::SELECT,
712 'description' => esc_html__('Set a message or a saved template when the content is protected.', 'master-addons' ),
713 'options' => [
714 'none' => esc_html__('None', 'master-addons' ),
715 'text' => esc_html__('Message', 'master-addons' ),
716 'template' => esc_html__('Saved Templates', 'master-addons' ),
717 ],
718 'default' => 'text',
719 ]
720 );
721
722 $element->add_control(
723 'jltma_content_protection_message_text',
724 [
725 'label' => esc_html__('Public Text', 'master-addons' ),
726 'type' => Controls_Manager::WYSIWYG,
727 'default' => esc_html__('You do not have permission to see this content.', 'master-addons' ),
728 'dynamic' => [
729 'active' => true,
730 ],
731 'condition' => [
732 'jltma_content_protection_message_type' => 'text',
733 ],
734 ]
735 );
736
737 $element->add_control(
738 'jltma_content_protection_message_template',
739 [
740 'label' => __('Choose Template', 'master-addons' ),
741 'type' => Controls_Manager::SELECT,
742 'options' => Helper::get_page_template_options(),
743 'condition' => [
744 'jltma_content_protection_message_type' => 'template',
745 ],
746 ]
747 );
748
749 $element->end_controls_tab();
750
751 $element->start_controls_tab(
752 'jltma_content_protection_tab_style',
753 [
754 'label' => __('Style', 'master-addons' ),
755 ]
756 );
757
758 $element->add_control(
759 'jltma_content_protection_message_styles',
760 [
761 'label' => __('Message', 'master-addons' ),
762 'type' => Controls_Manager::HEADING,
763 'separator' => 'after',
764 'condition' => [
765 'jltma_content_protection_message_type' => 'text',
766 ],
767 ]
768 );
769
770 $element->add_control(
771 'jltma_content_protection_message_text_color',
772 [
773 'label' => esc_html__('Text Color', 'master-addons' ),
774 'type' => Controls_Manager::COLOR,
775 'default' => '',
776 'selectors' => [
777 '{{WRAPPER}} .neb-protected-content-message' => 'color: {{VALUE}};',
778 ],
779 'condition' => [
780 'jltma_content_protection_message_type' => 'text',
781 ],
782 ]
783 );
784
785 $element->add_group_control(
786 Group_Control_Typography::get_type(),
787 [
788 'name' => 'jltma_content_protection_message_text_typography',
789 'global' => [
790 'default' => Global_Typography::TYPOGRAPHY_SECONDARY,
791 ],
792 'selector' => '{{WRAPPER}} .neb-protected-content-message, {{WRAPPER}} .protected-content-error-msg',
793 'condition' => [
794 'jltma_content_protection_message_type' => 'text',
795 ],
796 ]
797 );
798
799 $element->add_responsive_control(
800 'jltma_content_protection_message_text_alignment',
801 [
802 'label' => esc_html__('Text Alignment', 'master-addons' ),
803 'type' => Controls_Manager::CHOOSE,
804 'label_block' => true,
805 'options' => Helper::jltma_content_alignment(),
806 'default' => 'left',
807 'selectors' => [
808 '{{WRAPPER}} .neb-protected-content-message, {{WRAPPER}} .protected-content-error-msg' => 'text-align: {{VALUE}};',
809 ],
810 'condition' => [
811 'jltma_content_protection_message_type' => 'text',
812 ],
813 ]
814 );
815
816 $element->add_responsive_control(
817 'jltma_content_protection_message_text_padding',
818 [
819 'label' => esc_html__('Padding', 'master-addons' ),
820 'type' => Controls_Manager::DIMENSIONS,
821 'size_units' => ['px', '%', 'em'],
822 'selectors' => [
823 '{{WRAPPER}} .neb-protected-content-message' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
824 ],
825 'condition' => [
826 'jltma_content_protection_message_type' => 'text',
827 ],
828 ]
829 );
830
831 $element->add_control(
832 'jltma_content_protection_input_styles',
833 [
834 'label' => __('Password Field', 'master-addons' ),
835 'type' => Controls_Manager::HEADING,
836 'separator' => 'after',
837 'condition' => [
838 'jltma_content_protection_type' => 'password',
839 ],
840 ]
841 );
842
843 $element->add_control(
844 'jltma_content_protection_input_width',
845 [
846 'label' => esc_html__('Input Width', 'master-addons' ),
847 'type' => Controls_Manager::SLIDER,
848 'range' => [
849 'px' => [
850 'max' => 1000,
851 ],
852 ],
853 'selectors' => [
854 '{{WRAPPER}} .neb-password-protected-content-fields input.neb-password' => 'width: {{SIZE}}px;',
855 ],
856 'condition' => [
857 'jltma_content_protection_type' => 'password',
858 ],
859 ]
860 );
861
862 $element->add_responsive_control(
863 'jltma_content_protection_input_alignment',
864 [
865 'label' => esc_html__('Input Alignment', 'master-addons' ),
866 'type' => Controls_Manager::CHOOSE,
867 'label_block' => true,
868 'options' => Helper::jltma_content_alignment(),
869 'default' => 'left',
870 'selectors' => [
871 '{{WRAPPER}} .neb-password-protected-content-fields > form' => 'justify-content: {{VALUE}};',
872 ],
873 'condition' => [
874 'jltma_content_protection_type' => 'password',
875 ],
876 ]
877 );
878
879 $element->add_responsive_control(
880 'jltma_content_protection_password_input_padding',
881 [
882 'label' => esc_html__('Padding', 'master-addons' ),
883 'type' => Controls_Manager::DIMENSIONS,
884 'size_units' => ['px', 'em'],
885 'selectors' => [
886 '{{WRAPPER}} .neb-password-protected-content-fields input.neb-password' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
887 ],
888 'condition' => [
889 'jltma_content_protection_type' => 'password',
890 ],
891 ]
892 );
893
894 $element->add_responsive_control(
895 'jltma_content_protection_password_input_margin',
896 [
897 'label' => esc_html__('Margin', 'master-addons' ),
898 'type' => Controls_Manager::DIMENSIONS,
899 'size_units' => ['px', 'em'],
900 'selectors' => [
901 '{{WRAPPER}} .neb-password-protected-content-fields input.neb-password' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
902 ],
903 'condition' => [
904 'jltma_content_protection_type' => 'password',
905 ],
906 ]
907 );
908
909 $element->add_control(
910 'jltma_content_protection_input_border_radius',
911 [
912 'label' => esc_html__('Border Radius', 'master-addons' ),
913 'type' => Controls_Manager::SLIDER,
914 'range' => [
915 'px' => [
916 'max' => 100,
917 ],
918 ],
919 'selectors' => [
920 '{{WRAPPER}} .neb-password-protected-content-fields input.neb-password' => 'border-radius: {{SIZE}}px;',
921 ],
922 'condition' => [
923 'jltma_content_protection_type' => 'password',
924 ],
925 ]
926 );
927
928 $element->add_control(
929 'jltma_content_protection_password_input_color',
930 [
931 'label' => esc_html__('Color', 'master-addons' ),
932 'type' => Controls_Manager::COLOR,
933 'default' => '#333333',
934 'selectors' => [
935 '{{WRAPPER}} .neb-password-protected-content-fields input.neb-password' => 'color: {{VALUE}};',
936 ],
937 'condition' => [
938 'jltma_content_protection_type' => 'password',
939 ],
940 ]
941 );
942
943 $element->add_control(
944 'jltma_content_protection_password_input_bg_color',
945 [
946 'label' => esc_html__('Background Color', 'master-addons' ),
947 'type' => Controls_Manager::COLOR,
948 'default' => '#ffffff',
949 'selectors' => [
950 '{{WRAPPER}} .neb-password-protected-content-fields input.neb-password' => 'background-color: {{VALUE}};',
951 ],
952 'condition' => [
953 'jltma_content_protection_type' => 'password',
954 ],
955 ]
956 );
957
958 $element->add_group_control(
959 Group_Control_Border::get_type(),
960 [
961 'name' => 'jltma_content_protection_password_input_border',
962 'label' => esc_html__('Border', 'master-addons' ),
963 'selector' => '{{WRAPPER}} .neb-password-protected-content-fields .neb-password',
964 'condition' => [
965 'jltma_content_protection_type' => 'password',
966 ],
967 ]
968 );
969
970 $element->add_group_control(
971 Group_Control_Box_Shadow::get_type(),
972 [
973 'name' => 'jltma_content_protection_password_input_shadow',
974 'selector' => '{{WRAPPER}} .neb-password-protected-content-fields .neb-password',
975 'condition' => [
976 'jltma_content_protection_type' => 'password',
977 ],
978 ]
979 );
980
981 $element->add_control(
982 'jltma_content_protection_input_styles_hover',
983 [
984 'label' => __('Password Field Hover', 'master-addons' ),
985 'type' => Controls_Manager::HEADING,
986 'separator' => 'after',
987 'condition' => [
988 'jltma_content_protection_type' => 'password',
989 ],
990 ]
991 );
992
993 $element->add_control(
994 'neb_protected_content_password_input_hover_color',
995 [
996 'label' => esc_html__('Color', 'master-addons' ),
997 'type' => Controls_Manager::COLOR,
998 'default' => '#333333',
999 'selectors' => [
1000 '{{WRAPPER}} .neb-password-protected-content-fields input.neb-password:hover' => 'color: {{VALUE}};',
1001 ],
1002 'condition' => [
1003 'jltma_content_protection_type' => 'password',
1004 ],
1005 ]
1006 );
1007
1008 $element->add_control(
1009 'neb_protected_content_password_input_hover_bg_color',
1010 [
1011 'label' => esc_html__('Background Color', 'master-addons' ),
1012 'type' => Controls_Manager::COLOR,
1013 'default' => '#ffffff',
1014 'selectors' => [
1015 '{{WRAPPER}} .neb-password-protected-content-fields input.neb-password:hover' => 'background-color: {{VALUE}};',
1016 ],
1017 'condition' => [
1018 'jltma_content_protection_type' => 'password',
1019 ],
1020 ]
1021 );
1022
1023 $element->add_group_control(
1024 Group_Control_Border::get_type(),
1025 [
1026 'name' => 'neb_protected_content_password_input_hover_border',
1027 'label' => esc_html__('Border', 'master-addons' ),
1028 'selector' => '{{WRAPPER}} .neb-password-protected-content-fields .neb-password:hover',
1029 'condition' => [
1030 'jltma_content_protection_type' => 'password',
1031 ],
1032 ]
1033 );
1034
1035 $element->add_group_control(
1036 Group_Control_Box_Shadow::get_type(),
1037 [
1038 'name' => 'neb_protected_content_password_input_hover_shadow',
1039 'selector' => '{{WRAPPER}} .neb-password-protected-content-fields .neb-password:hover',
1040 'condition' => [
1041 'jltma_content_protection_type' => 'password',
1042 ],
1043 ]
1044 );
1045
1046 $element->add_control(
1047 'jltma_content_protection_submit_button_styles',
1048 [
1049 'label' => __('Submit Button', 'master-addons' ),
1050 'type' => Controls_Manager::HEADING,
1051 'separator' => 'after',
1052 'condition' => [
1053 'jltma_content_protection_type' => 'password',
1054 ],
1055 ]
1056 );
1057
1058 $element->add_control(
1059 'jltma_content_protection_submit_button_color',
1060 [
1061 'label' => esc_html__('Text Color', 'master-addons' ),
1062 'type' => Controls_Manager::COLOR,
1063 'default' => '#ffffff',
1064 'selectors' => [
1065 '{{WRAPPER}} .neb-password-protected-content-fields .neb-submit' => 'color: {{VALUE}};',
1066 ],
1067 'condition' => [
1068 'jltma_content_protection_type' => 'password',
1069 ],
1070 ]
1071 );
1072
1073 $element->add_control(
1074 'jltma_content_protection_submit_button_bg_color',
1075 [
1076 'label' => esc_html__('Background Color', 'master-addons' ),
1077 'type' => Controls_Manager::COLOR,
1078 'default' => '#333333',
1079 'selectors' => [
1080 '{{WRAPPER}} .neb-password-protected-content-fields .neb-submit' => 'background: {{VALUE}};',
1081 ],
1082 'condition' => [
1083 'jltma_content_protection_type' => 'password',
1084 ],
1085 ]
1086 );
1087
1088 $element->add_group_control(
1089 Group_Control_Border::get_type(),
1090 [
1091 'name' => 'jltma_content_protection_submit_button_border',
1092 'selector' => '{{WRAPPER}} .neb-password-protected-content-fields .neb-submit',
1093 'condition' => [
1094 'jltma_content_protection_type' => 'password',
1095 ],
1096 ]
1097 );
1098
1099 $element->add_group_control(
1100 Group_Control_Box_Shadow::get_type(),
1101 [
1102 'name' => 'jltma_content_protection_submit_button_box_shadow',
1103 'selector' => '{{WRAPPER}} .neb-password-protected-content-fields .neb-submit',
1104 'condition' => [
1105 'jltma_content_protection_type' => 'password',
1106 ],
1107 ]
1108 );
1109
1110 $element->add_control(
1111 'jltma_content_protection_submit_button_styles_hover',
1112 [
1113 'label' => __('Submit Button Hover', 'master-addons' ),
1114 'type' => Controls_Manager::HEADING,
1115 'separator' => 'after',
1116 'condition' => [
1117 'jltma_content_protection_type' => 'password',
1118 ],
1119 ]
1120 );
1121
1122 $element->add_control(
1123 'jltma_content_protection_submit_button_hover_text_color',
1124 [
1125 'label' => esc_html__('Text Color', 'master-addons' ),
1126 'type' => Controls_Manager::COLOR,
1127 'default' => '#ffffff',
1128 'selectors' => [
1129 '{{WRAPPER}} .neb-password-protected-content-fields .neb-submit:hover' => 'color: {{VALUE}};',
1130 ],
1131 'condition' => [
1132 'jltma_content_protection_type' => 'password',
1133 ],
1134 ]
1135 );
1136
1137 $element->add_control(
1138 'jltma_content_protection_submit_button_hover_bg_color',
1139 [
1140 'label' => esc_html__('Background Color', 'master-addons' ),
1141 'type' => Controls_Manager::COLOR,
1142 'default' => '#333333',
1143 'selectors' => [
1144 '{{WRAPPER}} .neb-password-protected-content-fields .neb-submit:hover' => 'background: {{VALUE}};',
1145 ],
1146 'condition' => [
1147 'jltma_content_protection_type' => 'password',
1148 ],
1149 ]
1150 );
1151
1152 $element->add_group_control(
1153 Group_Control_Border::get_type(),
1154 [
1155 'name' => 'jltma_content_protection_submit_button_hover_border',
1156 'selector' => '{{WRAPPER}} .neb-password-protected-content-fields .neb-submit:hover',
1157 'condition' => [
1158 'jltma_content_protection_type' => 'password',
1159 ],
1160 ]
1161 );
1162
1163 $element->add_group_control(
1164 Group_Control_Box_Shadow::get_type(),
1165 [
1166 'name' => 'jltma_content_protection_submit_button_hover_box_shadow',
1167 'selector' => '{{WRAPPER}} .neb-password-protected-content-fields .neb-submit:hover',
1168 'condition' => [
1169 'jltma_content_protection_type' => 'password',
1170 ],
1171 ]
1172 );
1173
1174 $element->end_controls_tab();
1175
1176 $element->end_controls_tabs();
1177
1178 $element->end_controls_section();
1179 }
1180
1181 /**
1182 * Render Content Protection Message.
1183 *
1184 * @param array $settings Widget Settings.
1185 *
1186 * @return string
1187 */
1188 protected function render_message($settings)
1189 {
1190 $html = '<div class="neb-protected-content-message">';
1191
1192 if ($settings['jltma_content_protection_message_type'] === 'text') {
1193 $html .= '<div class="neb-protected-content-message-text">' . esc_attr($settings['jltma_content_protection_message_text']) . '</div>';
1194 } elseif ($settings['jltma_content_protection_message_type'] === 'template') {
1195 if (!empty($settings['jltma_content_protection_message_template'])) {
1196 $template_id = $settings['jltma_content_protection_message_template'];
1197 $frontend = new Frontend();
1198
1199 $html .= $frontend->get_builder_content($template_id, true);
1200 }
1201 }
1202 $html .= '</div>';
1203
1204 return $html;
1205 }
1206
1207 /**
1208 * Render Content Protection form.
1209 *
1210 * @param array $settings Widget settings.
1211 *
1212 * @return string
1213 */
1214 public function password_protected_form($settings)
1215 {
1216 $html = '<div class="neb-password-protected-content-fields">
1217 <form method="post">
1218 <input type="password" name="jltma_content_protection_password" class="neb-password" placeholder="' . esc_attr($settings['jltma_content_protection_password_placeholder']) . '">
1219 <input type="submit" value="' . esc_attr($settings['jltma_content_protection_password_submit_btn_txt']) . '" class="neb-submit">
1220 </form>';
1221
1222 // Public front-end content gate: read-only password comparison, no state
1223 // change, so a nonce is not applicable (mirrors core post-password).
1224 $submitted_password = isset($_POST['jltma_content_protection_password']) ? sanitize_text_field(wp_unslash($_POST['jltma_content_protection_password'])) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
1225 if (null !== $submitted_password) {
1226 if ($settings['jltma_content_protection_password'] !== $submitted_password) {
1227 /* translators: %s is Incorrect password message */
1228 $html .= sprintf(
1229 '<p class="">%s</p>',
1230 __('Password does not match.', 'master-addons' )
1231 );
1232 }
1233 }
1234
1235 $html .= '</div>';
1236
1237 return $html;
1238 }
1239
1240 /**
1241 * Render Content Protection.
1242 *
1243 * @param string $content Content.
1244 * @param Object $widget Widget instance.
1245 *
1246 * @return string
1247 */
1248 public function render_content($content, $widget)
1249 {
1250 $settings = $widget->get_settings_for_display();
1251
1252 if ($settings['jltma_content_protection'] !== 'yes') {
1253 return $content;
1254 }
1255
1256 if ($settings['jltma_content_protection_type'] === 'role') {
1257 if ($this->current_user_privileges($settings) === true) {
1258 return $content;
1259 }
1260 return '<div class="neb-protected-content">' . $this->render_message($settings) . '</div>';
1261 }
1262
1263 if ($settings['jltma_content_protection_type'] === 'password') {
1264 if (empty($settings['jltma_content_protection_password'])) {
1265 return $content;
1266 }
1267
1268 $html = '';
1269 $unlocked = false;
1270
1271 // Public front-end content gate: read-only password comparison, no state
1272 // change, so a nonce is not applicable (mirrors core post-password).
1273 $submitted_password = isset($_POST['jltma_content_protection_password']) ? sanitize_text_field(wp_unslash($_POST['jltma_content_protection_password'])) : null; // phpcs:ignore WordPress.Security.NonceVerification.Missing
1274 if (null !== $submitted_password) {
1275 if ($settings['jltma_content_protection_password'] === $submitted_password) {
1276 $unlocked = true;
1277
1278 $html .= "<script>
1279 var expires = new Date();
1280 expires.setTime( expires.getTime() + ( 60 * 60 * 1000 ) );
1281 document.cookie = 'jltma_content_protection_password=true;expires=' + expires.toUTCString();
1282 </script>";
1283 }
1284 }
1285
1286 if (isset($_COOKIE['jltma_content_protection_password']) || $unlocked) {
1287 $html .= $content;
1288 } else {
1289 $html .= '<div class="neb-protected-content">' . $this->render_message($settings) . $this->password_protected_form($settings) . '</div>';
1290 }
1291 return $html;
1292 }
1293
1294 if ($settings['jltma_content_protection_type'] === 'logged-in') {
1295 if (is_user_logged_in()) {
1296 return $content;
1297 }
1298
1299 return '<div class="neb-protected-content">' . $this->render_message($settings) . '</div>';
1300 }
1301
1302 $current_time = strtotime(gmdate('Y-m-d H:i'));
1303
1304 if ($settings['jltma_content_protection_type'] === 'start-end-date') {
1305 $period = $settings['jltma_content_protection_period_date'];
1306 if (empty($period)) {
1307 return $content;
1308 }
1309
1310 $start_end = explode(' to ', $period);
1311 if (sizeof($start_end) !== 2) {
1312 return $content;
1313 }
1314
1315 $start_date = strtotime($start_end[0]);
1316 $end_date = strtotime($start_end[1]);
1317 if ($start_date <= $current_time && $current_time <= $end_date) {
1318 return '<div class="neb-protected-content">' . $this->render_message($settings) . '</div>';
1319 }
1320
1321 return $content;
1322 }
1323
1324 if ($settings['jltma_content_protection_type'] === 'days-of-the-week') {
1325 $current_day = gmdate('w', $current_time);
1326 $blocked_days = !empty($settings['jltma_content_protection_days_of_week']) ? $settings['jltma_content_protection_days_of_week'] : array();
1327 if (in_array($current_day, $blocked_days, true)) {
1328 if (isset($settings['jltma_content_protection_days_of_week_time_from']) && isset($settings['jltma_content_protection_days_of_week_time_to'])) {
1329 $start = strtotime('today ' . esc_attr($settings['jltma_content_protection_days_of_week_time_from']));
1330 $end = strtotime('today ' . esc_attr($settings['jltma_content_protection_days_of_week_time_to']));
1331 if ($start <= $current_time && $current_time <= $end) {
1332 return '<div class="neb-protected-content">' . $this->render_message($settings) . '</div>';
1333 }
1334
1335 return $content;
1336 }
1337
1338 return '<div class="neb-protected-content">' . $this->render_message($settings) . '</div>';
1339 }
1340
1341 return $content;
1342 }
1343
1344 return $content;
1345 }
1346
1347 /**
1348 * Get user roles.
1349 *
1350 * @return array
1351 */
1352 private function get_user_roles()
1353 {
1354 global $wp_roles;
1355 $roles = $wp_roles->roles;
1356 if (empty($roles)) {
1357 return array();
1358 }
1359
1360 $all_roles = array();
1361 foreach ($roles as $key => $value) {
1362 $all_roles[$key] = $roles[$key]['name'];
1363 }
1364
1365 return $all_roles;
1366 }
1367
1368 /**
1369 * Check current user role exists inside of the roles array.
1370 *
1371 * @param array $settings Current widget settings.
1372 *
1373 * @return bool
1374 */
1375 private function current_user_privileges($settings)
1376 {
1377 if (!is_user_logged_in()) {
1378 return false;
1379 }
1380
1381 $user_role = reset(wp_get_current_user()->roles);
1382
1383 return in_array($user_role, (array) $settings['jltma_content_protection_role'], true);
1384 }
1385
1386 /**
1387 * Return an array with days of the week.
1388 *
1389 * @return array
1390 */
1391 private function get_days_of_week()
1392 {
1393 return array(
1394 6 => __('Saturday', 'master-addons' ),
1395 0 => __('Sunday', 'master-addons' ),
1396 1 => __('Monday', 'master-addons' ),
1397 2 => __('Tuesday', 'master-addons' ),
1398 3 => __('Wednesday', 'master-addons' ),
1399 4 => __('Thursday', 'master-addons' ),
1400 5 => __('Friday', 'master-addons' ),
1401 );
1402 }
1403
1404 public static function get_instance()
1405 {
1406 if (!self::$instance) {
1407 self::$instance = new self;
1408 }
1409 return self::$instance;
1410 }
1411 }
1412 }
1413
1414 if (class_exists('MasterAddons\Modules\Extension_Content_Protection')) {
1415 Extension_Content_Protection::get_instance();
1416 }
1417