Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/fluentformpro/src/classes/ConditionalContent.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + namespace FluentFormPro\classes;
4 +
5 + if (!defined('ABSPATH')) {
6 + exit; // Exit if accessed directly.
7 + }
8 +
9 + class ConditionalContent
10 + {
11 + private static $entryId;
12 + private static $formData;
13 + private static $form;
14 +
15 + public static function handle($atts, $content)
16 + {
17 + $atts['to'] = html_entity_decode($atts['to']);
18 + $default = [
19 + 'field' => '',
20 + 'is' => '',
21 + 'to' => ''
22 + ];
23 + $default = apply_filters_deprecated(
24 + 'fluentform_conditional_shortcode_defaults',
25 + [
26 + $default,
27 + $atts
28 + ],
29 + FLUENTFORM_FRAMEWORK_UPGRADE,
30 + 'fluentform/conditional_shortcode_defaults',
31 + 'Use fluentform/conditional_shortcode_defaults instead of fluentform_conditional_shortcode_defaults.'
32 + );
33 + $shortcodeDefaults = apply_filters('fluentform/conditional_shortcode_defaults', $default, $atts);
34 +
35 + extract(shortcode_atts($shortcodeDefaults, $atts));
36 +
37 + if(!$field || !$is || !isset($to)) {
38 + return '';
39 + }
40 +
41 + $operatorMaps = [
42 + 'equal' => '=',
43 + 'not_equal' => '!=',
44 + 'greater_than' => '>',
45 + 'less_than' => '<',
46 + 'greater_or_equal' => '>=',
47 + 'less_or_equal' => '<=',
48 + 'starts_with' => 'startsWith',
49 + 'ends_with' => 'endsWith',
50 + 'contains' => 'contains',
51 + 'not_contains' => 'doNotContains'
52 + ];
53 +
54 + if(!isset($operatorMaps[$is])) {
55 + return '';
56 + }
57 +
58 + $is = $operatorMaps[$is];
59 +
60 + $condition = [
61 + 'conditionals' => [
62 + 'status' => true,
63 + 'type' => 'any',
64 + 'conditions' => [
65 + [
66 + "field" => $field,
67 + "operator" => $is,
68 + "value" => $to
69 + ]
70 + ]
71 + ]
72 + ];
73 +
74 + if (\FluentForm\App\Services\ConditionAssesor::evaluate($condition, static::$formData)) {
75 + return do_shortcode($content);
76 + }
77 +
78 + return '';
79 + }
80 +
81 +
82 + public static function initiate($content, $entryId, $formData, $form)
83 + {
84 + if(!has_shortcode($content, 'ff_if') || !$content) {
85 + return $content;
86 + }
87 +
88 + static::$entryId = $entryId;
89 + static::$formData = $formData;
90 +
91 + static::$form = $form;
92 + return do_shortcode($content);
93 + }
94 + }
95 +