PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.26.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.26.1
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / helpers / FrmApiHelper.php

FrmApiHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.26.1, at classes/helpers/FrmApiHelper.php

194 lines 3.7 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 die( 'You are not allowed to call this page directly.' );
4 }
5
6 /**
7 * @since 6.17
8 */
9 class FrmApiHelper {
10
11 /**
12 * Check if an API item matches the current site license target.
13 *
14 * @since 6.17
15 *
16 * @param array $item Inbox or Sale item.
17 *
18 * @return bool
19 */
20 public static function is_for_user( $item ) {
21 if ( ! isset( $item['who'] ) || $item['who'] === 'all' ) {
22 return true;
23 }
24
25 $who = (array) $item['who'];
26
27 if ( self::is_for_everyone( $who ) ) {
28 return true;
29 }
30
31 if ( self::is_user_type( $who ) ) {
32 return true;
33 }
34
35 if ( in_array( 'free_first_30', $who, true ) && self::is_free_first_30() ) {
36 return true;
37 }
38
39 if ( in_array( 'free_not_first_30', $who, true ) && self::is_free_not_first_30() ) {
40 return true;
41 }
42
43 if ( self::check_free_segments( $who ) ) {
44 return true;
45 }
46 return false;
47 }
48
49 /**
50 * @since 6.17
51 *
52 * @param array $who
53 *
54 * @return bool
55 */
56 private static function is_for_everyone( $who ) {
57 return in_array( 'all', $who, true );
58 }
59
60 /**
61 * @since 6.17
62 *
63 * @param array $who
64 *
65 * @return bool
66 */
67 private static function is_user_type( $who ) {
68 return in_array( self::get_user_type(), $who, true );
69 }
70
71 /**
72 * @since 6.17
73 *
74 * @return string
75 */
76 private static function get_user_type() {
77 if ( ! FrmAppHelper::pro_is_installed() ) {
78 return 'free';
79 }
80
81 return FrmAddonsController::license_type();
82 }
83
84 /**
85 * Check if user is still using the Lite version only, and within
86 * the first 30 days of activation.
87 *
88 * @since 6.17
89 *
90 * @return bool
91 */
92 private static function is_free_first_30() {
93 return self::is_free() && self::is_first_30();
94 }
95
96 /**
97 * @since 6.17
98 *
99 * @return bool
100 */
101 private static function is_first_30() {
102 $activation_timestamp = get_option( 'frm_first_activation' );
103
104 if ( false === $activation_timestamp ) {
105 // If the option does not exist, assume that it is
106 // because the user was active before this option was introduced.
107 return false;
108 }
109
110 $cutoff = strtotime( '-30 days' );
111 return $activation_timestamp > $cutoff;
112 }
113
114 /**
115 * @since 6.17
116 *
117 * @return bool
118 */
119 private static function is_free_not_first_30() {
120 return self::is_free() && ! self::is_first_30();
121 }
122
123 /**
124 * Check if the Pro plugin is active. If not, consider the user to be on the free version.
125 *
126 * @since 6.17
127 *
128 * @return bool
129 */
130 private static function is_free() {
131 return ! FrmAppHelper::pro_is_included();
132 }
133
134 /**
135 * @since 6.18
136 *
137 * @param array $who
138 *
139 * @return bool
140 */
141 private static function check_free_segments( $who ) {
142 $segments = array(
143 'free_first_1',
144 'free_first_2_3',
145 'free_first_4_7',
146 'free_first_8_11',
147 'free_first_12_19',
148 'free_first_20_30',
149 );
150 $intersecting_keys = array_intersect( $segments, $who );
151
152 if ( ! $intersecting_keys ) {
153 return false;
154 }
155
156 if ( ! self::is_free() || ! self::is_first_30() ) {
157 return false;
158 }
159
160 $activation_timestamp = get_option( 'frm_first_activation' );
161
162 foreach ( $intersecting_keys as $key ) {
163 if ( self::matches_segment( $key, $activation_timestamp ) ) {
164 return true;
165 }
166 }
167
168 return false;
169 }
170
171 /**
172 * @since 6.18
173 *
174 * @param string $key
175 * @param int $activation_timestamp
176 *
177 * @return bool
178 */
179 private static function matches_segment( $key, $activation_timestamp ) {
180 $range_part = str_replace( 'free_first_', '', $key );
181 $range_parts = explode( '_', $range_part );
182
183 if ( ! $range_parts ) {
184 return false;
185 }
186
187 $current_day = (int) floor( ( time() - $activation_timestamp ) / DAY_IN_SECONDS ) + 1;
188 $start = (int) $range_parts[0];
189 $end = 1 === count( $range_parts ) ? $start : (int) $range_parts[1];
190
191 return $current_day >= $start && $current_day <= $end;
192 }
193 }
194