PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22
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.22, at classes/helpers/FrmApiHelper.php

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