@@ -746,6 +746,9 @@ discard block |
||
746 | 746 | return FrmFieldsHelper::prepare_other_input( $args, $other_opt, $checked ); |
747 | 747 | } |
748 | 748 | |
749 | + /** |
|
750 | + * @param string $function |
|
751 | + */ |
|
749 | 752 | public static function recursive_function_map( $value, $function ) { |
750 | 753 | if ( is_array( $value ) ) { |
751 | 754 | $original_function = $function; |
@@ -1173,6 +1176,9 @@ discard block |
||
1173 | 1176 | return $sub . (($len < $original_len) ? $continue : ''); |
1174 | 1177 | } |
1175 | 1178 | |
1179 | + /** |
|
1180 | + * @param string[] $function_names |
|
1181 | + */ |
|
1176 | 1182 | public static function mb_function( $function_names, $args ) { |
1177 | 1183 | $mb_function_name = $function_names[0]; |
1178 | 1184 | $function_name = $function_names[1]; |
@@ -1206,6 +1212,9 @@ discard block |
||
1206 | 1212 | return $formatted; |
1207 | 1213 | } |
1208 | 1214 | |
1215 | + /** |
|
1216 | + * @param string $time_format |
|
1217 | + */ |
|
1209 | 1218 | private static function add_time_to_date( $time_format, $date ) { |
1210 | 1219 | if ( empty( $time_format ) ) { |
1211 | 1220 | $time_format = get_option('time_format'); |
@@ -12,126 +12,126 @@ discard block |
||
12 | 12 | */ |
13 | 13 | public static $plug_version = '2.0.17'; |
14 | 14 | |
15 | - /** |
|
16 | - * @since 1.07.02 |
|
17 | - * |
|
18 | - * @param none |
|
19 | - * @return string The version of this plugin |
|
20 | - */ |
|
21 | - public static function plugin_version() { |
|
22 | - return self::$plug_version; |
|
23 | - } |
|
24 | - |
|
25 | - public static function plugin_folder() { |
|
26 | - return basename(self::plugin_path()); |
|
27 | - } |
|
28 | - |
|
29 | - public static function plugin_path() { |
|
30 | - return dirname(dirname(dirname(__FILE__))); |
|
31 | - } |
|
32 | - |
|
33 | - public static function plugin_url() { |
|
34 | - //prevously FRM_URL constant |
|
35 | - return plugins_url( '', self::plugin_path() .'/formidable.php' ); |
|
36 | - } |
|
15 | + /** |
|
16 | + * @since 1.07.02 |
|
17 | + * |
|
18 | + * @param none |
|
19 | + * @return string The version of this plugin |
|
20 | + */ |
|
21 | + public static function plugin_version() { |
|
22 | + return self::$plug_version; |
|
23 | + } |
|
24 | + |
|
25 | + public static function plugin_folder() { |
|
26 | + return basename(self::plugin_path()); |
|
27 | + } |
|
28 | + |
|
29 | + public static function plugin_path() { |
|
30 | + return dirname(dirname(dirname(__FILE__))); |
|
31 | + } |
|
32 | + |
|
33 | + public static function plugin_url() { |
|
34 | + //prevously FRM_URL constant |
|
35 | + return plugins_url( '', self::plugin_path() .'/formidable.php' ); |
|
36 | + } |
|
37 | 37 | |
38 | 38 | public static function relative_plugin_url() { |
39 | 39 | return str_replace( array( 'https:', 'http:' ), '', self::plugin_url() ); |
40 | 40 | } |
41 | 41 | |
42 | - /** |
|
43 | - * @return string Site URL |
|
44 | - */ |
|
45 | - public static function site_url() { |
|
46 | - return site_url(); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Get the name of this site |
|
51 | - * Used for [sitename] shortcode |
|
52 | - * |
|
53 | - * @since 2.0 |
|
54 | - * @return string |
|
55 | - */ |
|
56 | - public static function site_name() { |
|
57 | - return get_option('blogname'); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Get the Formidable settings |
|
62 | - * |
|
63 | - * @since 2.0 |
|
64 | - * |
|
65 | - * @param None |
|
66 | - * @return FrmSettings $frm_setings |
|
67 | - */ |
|
68 | - public static function get_settings() { |
|
69 | - global $frm_settings; |
|
70 | - if ( empty($frm_settings) ) { |
|
71 | - $frm_settings = new FrmSettings(); |
|
72 | - } |
|
73 | - return $frm_settings; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Show a message in place of pro features |
|
78 | - * |
|
79 | - * @since 2.0 |
|
80 | - */ |
|
42 | + /** |
|
43 | + * @return string Site URL |
|
44 | + */ |
|
45 | + public static function site_url() { |
|
46 | + return site_url(); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Get the name of this site |
|
51 | + * Used for [sitename] shortcode |
|
52 | + * |
|
53 | + * @since 2.0 |
|
54 | + * @return string |
|
55 | + */ |
|
56 | + public static function site_name() { |
|
57 | + return get_option('blogname'); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Get the Formidable settings |
|
62 | + * |
|
63 | + * @since 2.0 |
|
64 | + * |
|
65 | + * @param None |
|
66 | + * @return FrmSettings $frm_setings |
|
67 | + */ |
|
68 | + public static function get_settings() { |
|
69 | + global $frm_settings; |
|
70 | + if ( empty($frm_settings) ) { |
|
71 | + $frm_settings = new FrmSettings(); |
|
72 | + } |
|
73 | + return $frm_settings; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Show a message in place of pro features |
|
78 | + * |
|
79 | + * @since 2.0 |
|
80 | + */ |
|
81 | 81 | public static function update_message( $features, $class = '' ) { |
82 | 82 | return; // hide the upgrade messages for now |
83 | - if ( ! self::pro_is_installed() ) { |
|
84 | - include(self::plugin_path() .'/classes/views/shared/update_message.php'); |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - public static function pro_is_installed() { |
|
89 | - return apply_filters('frm_pro_installed', false); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Check for certain page in Formidable settings |
|
94 | - * |
|
95 | - * @since 2.0 |
|
96 | - * |
|
97 | - * @param string $page The name of the page to check |
|
98 | - * @return boolean |
|
99 | - */ |
|
83 | + if ( ! self::pro_is_installed() ) { |
|
84 | + include(self::plugin_path() .'/classes/views/shared/update_message.php'); |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + public static function pro_is_installed() { |
|
89 | + return apply_filters('frm_pro_installed', false); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Check for certain page in Formidable settings |
|
94 | + * |
|
95 | + * @since 2.0 |
|
96 | + * |
|
97 | + * @param string $page The name of the page to check |
|
98 | + * @return boolean |
|
99 | + */ |
|
100 | 100 | public static function is_admin_page( $page = 'formidable' ) { |
101 | - global $pagenow; |
|
101 | + global $pagenow; |
|
102 | 102 | $get_page = self::simple_get( 'page', 'sanitize_title' ); |
103 | - if ( $pagenow ) { |
|
103 | + if ( $pagenow ) { |
|
104 | 104 | return $pagenow == 'admin.php' && $get_page == $page; |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | return is_admin() && $get_page == $page; |
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Check for the form preview page |
|
112 | - * |
|
113 | - * @since 2.0 |
|
114 | - * |
|
115 | - * @param None |
|
116 | - * @return boolean |
|
117 | - */ |
|
118 | - public static function is_preview_page() { |
|
119 | - global $pagenow; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Check for the form preview page |
|
112 | + * |
|
113 | + * @since 2.0 |
|
114 | + * |
|
115 | + * @param None |
|
116 | + * @return boolean |
|
117 | + */ |
|
118 | + public static function is_preview_page() { |
|
119 | + global $pagenow; |
|
120 | 120 | $action = FrmAppHelper::simple_get( 'action', 'sanitize_title' ); |
121 | 121 | return $pagenow && $pagenow == 'admin-ajax.php' && $action == 'frm_forms_preview'; |
122 | - } |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Check for ajax except the form preview page |
|
126 | - * |
|
127 | - * @since 2.0 |
|
128 | - * |
|
129 | - * @param None |
|
130 | - * @return boolean |
|
131 | - */ |
|
132 | - public static function doing_ajax() { |
|
133 | - return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page(); |
|
134 | - } |
|
124 | + /** |
|
125 | + * Check for ajax except the form preview page |
|
126 | + * |
|
127 | + * @since 2.0 |
|
128 | + * |
|
129 | + * @param None |
|
130 | + * @return boolean |
|
131 | + */ |
|
132 | + public static function doing_ajax() { |
|
133 | + return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page(); |
|
134 | + } |
|
135 | 135 | |
136 | 136 | /** |
137 | 137 | * @since 2.0.8 |
@@ -141,101 +141,101 @@ discard block |
||
141 | 141 | return isset( $frm_vars['prevent_caching'] ) && $frm_vars['prevent_caching']; |
142 | 142 | } |
143 | 143 | |
144 | - /** |
|
145 | - * Check if on an admin page |
|
146 | - * |
|
147 | - * @since 2.0 |
|
148 | - * |
|
149 | - * @param None |
|
150 | - * @return boolean |
|
151 | - */ |
|
152 | - public static function is_admin() { |
|
153 | - return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX ); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Check if value contains blank value or empty array |
|
158 | - * |
|
159 | - * @since 2.0 |
|
160 | - * @param $value - value to check |
|
161 | - * @return boolean |
|
162 | - */ |
|
163 | - public static function is_empty_value( $value, $empty = '' ) { |
|
164 | - return ( is_array( $value ) && empty( $value ) ) || $value == $empty; |
|
165 | - } |
|
166 | - |
|
167 | - public static function is_not_empty_value( $value, $empty = '' ) { |
|
168 | - return ! self::is_empty_value( $value, $empty ); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Get any value from the $_SERVER |
|
173 | - * |
|
174 | - * @since 2.0 |
|
175 | - * @param string $value |
|
176 | - * @return string |
|
177 | - */ |
|
144 | + /** |
|
145 | + * Check if on an admin page |
|
146 | + * |
|
147 | + * @since 2.0 |
|
148 | + * |
|
149 | + * @param None |
|
150 | + * @return boolean |
|
151 | + */ |
|
152 | + public static function is_admin() { |
|
153 | + return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX ); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Check if value contains blank value or empty array |
|
158 | + * |
|
159 | + * @since 2.0 |
|
160 | + * @param $value - value to check |
|
161 | + * @return boolean |
|
162 | + */ |
|
163 | + public static function is_empty_value( $value, $empty = '' ) { |
|
164 | + return ( is_array( $value ) && empty( $value ) ) || $value == $empty; |
|
165 | + } |
|
166 | + |
|
167 | + public static function is_not_empty_value( $value, $empty = '' ) { |
|
168 | + return ! self::is_empty_value( $value, $empty ); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Get any value from the $_SERVER |
|
173 | + * |
|
174 | + * @since 2.0 |
|
175 | + * @param string $value |
|
176 | + * @return string |
|
177 | + */ |
|
178 | 178 | public static function get_server_value( $value ) { |
179 | - return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : ''; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Check for the IP address in several places |
|
184 | - * Used by [ip] shortcode |
|
185 | - * |
|
186 | - * @return string The IP address of the current user |
|
187 | - */ |
|
188 | - public static function get_ip_address() { |
|
179 | + return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : ''; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Check for the IP address in several places |
|
184 | + * Used by [ip] shortcode |
|
185 | + * |
|
186 | + * @return string The IP address of the current user |
|
187 | + */ |
|
188 | + public static function get_ip_address() { |
|
189 | 189 | $ip = ''; |
190 | - foreach ( array( |
|
191 | - 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', |
|
192 | - 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR', |
|
193 | - ) as $key ) { |
|
194 | - if ( ! isset( $_SERVER[ $key ] ) ) { |
|
195 | - continue; |
|
196 | - } |
|
197 | - |
|
198 | - foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) { |
|
199 | - $ip = trim($ip); // just to be safe |
|
200 | - |
|
201 | - if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) { |
|
202 | - return $ip; |
|
203 | - } |
|
204 | - } |
|
205 | - } |
|
190 | + foreach ( array( |
|
191 | + 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', |
|
192 | + 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR', |
|
193 | + ) as $key ) { |
|
194 | + if ( ! isset( $_SERVER[ $key ] ) ) { |
|
195 | + continue; |
|
196 | + } |
|
197 | + |
|
198 | + foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) { |
|
199 | + $ip = trim($ip); // just to be safe |
|
200 | + |
|
201 | + if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) { |
|
202 | + return $ip; |
|
203 | + } |
|
204 | + } |
|
205 | + } |
|
206 | 206 | |
207 | 207 | return sanitize_text_field( $ip ); |
208 | - } |
|
208 | + } |
|
209 | 209 | |
210 | - public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) { |
|
211 | - if ( strpos($param, '[') ) { |
|
212 | - $params = explode('[', $param); |
|
213 | - $param = $params[0]; |
|
214 | - } |
|
210 | + public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) { |
|
211 | + if ( strpos($param, '[') ) { |
|
212 | + $params = explode('[', $param); |
|
213 | + $param = $params[0]; |
|
214 | + } |
|
215 | 215 | |
216 | 216 | if ( $src == 'get' ) { |
217 | - $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default ); |
|
218 | - if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) { |
|
219 | - $value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[ $param ] ) ) ); |
|
220 | - } |
|
217 | + $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default ); |
|
218 | + if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) { |
|
219 | + $value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[ $param ] ) ) ); |
|
220 | + } |
|
221 | 221 | self::sanitize_value( $sanitize, $value ); |
222 | 222 | } else { |
223 | - $value = self::get_simple_request( array( 'type' => $src, 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) ); |
|
224 | - } |
|
223 | + $value = self::get_simple_request( array( 'type' => $src, 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) ); |
|
224 | + } |
|
225 | 225 | |
226 | 226 | if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) { |
227 | - foreach ( $params as $k => $p ) { |
|
228 | - if ( ! $k || ! is_array($value) ) { |
|
229 | - continue; |
|
230 | - } |
|
227 | + foreach ( $params as $k => $p ) { |
|
228 | + if ( ! $k || ! is_array($value) ) { |
|
229 | + continue; |
|
230 | + } |
|
231 | 231 | |
232 | - $p = trim($p, ']'); |
|
233 | - $value = isset( $value[ $p ] ) ? $value[ $p ] : $default; |
|
234 | - } |
|
235 | - } |
|
232 | + $p = trim($p, ']'); |
|
233 | + $value = isset( $value[ $p ] ) ? $value[ $p ] : $default; |
|
234 | + } |
|
235 | + } |
|
236 | 236 | |
237 | - return $value; |
|
238 | - } |
|
237 | + return $value; |
|
238 | + } |
|
239 | 239 | |
240 | 240 | /** |
241 | 241 | * |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public static function simple_get( $param, $sanitize = 'sanitize_text_field', $default = '' ) { |
258 | 258 | return self::get_simple_request( array( 'type' => 'get', 'param' => $param, 'default' => $default, 'sanitize' => $sanitize ) ); |
259 | - } |
|
259 | + } |
|
260 | 260 | |
261 | 261 | /** |
262 | 262 | * Get a GET/POST/REQUEST value and sanitize it |
@@ -290,12 +290,12 @@ discard block |
||
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
293 | - * Preserve backslashes in a value, but make sure value doesn't get compounding slashes |
|
294 | - * |
|
295 | - * @since 2.0.8 |
|
296 | - * @param string $value |
|
297 | - * @return string $value |
|
298 | - */ |
|
293 | + * Preserve backslashes in a value, but make sure value doesn't get compounding slashes |
|
294 | + * |
|
295 | + * @since 2.0.8 |
|
296 | + * @param string $value |
|
297 | + * @return string $value |
|
298 | + */ |
|
299 | 299 | public static function preserve_backslashes( $value ) { |
300 | 300 | // If backslashes have already been added, don't add them again |
301 | 301 | if ( strpos( $value, '\\\\' ) === false ) { |
@@ -314,14 +314,14 @@ discard block |
||
314 | 314 | } |
315 | 315 | } |
316 | 316 | |
317 | - public static function sanitize_request( $sanitize_method, &$values ) { |
|
318 | - $temp_values = $values; |
|
319 | - foreach ( $temp_values as $k => $val ) { |
|
320 | - if ( isset( $sanitize_method[ $k ] ) ) { |
|
317 | + public static function sanitize_request( $sanitize_method, &$values ) { |
|
318 | + $temp_values = $values; |
|
319 | + foreach ( $temp_values as $k => $val ) { |
|
320 | + if ( isset( $sanitize_method[ $k ] ) ) { |
|
321 | 321 | $values[ $k ] = call_user_func( $sanitize_method[ $k ], $val ); |
322 | - } |
|
323 | - } |
|
324 | - } |
|
322 | + } |
|
323 | + } |
|
324 | + } |
|
325 | 325 | |
326 | 326 | public static function sanitize_array( &$values ) { |
327 | 327 | $temp_values = $values; |
@@ -336,12 +336,12 @@ discard block |
||
336 | 336 | */ |
337 | 337 | public static function kses( $value, $allowed = array() ) { |
338 | 338 | $html = array( |
339 | - 'a' => array( |
|
339 | + 'a' => array( |
|
340 | 340 | 'href' => array(), |
341 | 341 | 'title' => array(), |
342 | 342 | 'id' => array(), |
343 | 343 | 'class' => array(), |
344 | - ), |
|
344 | + ), |
|
345 | 345 | ); |
346 | 346 | |
347 | 347 | $allowed_html = array(); |
@@ -352,176 +352,176 @@ discard block |
||
352 | 352 | return wp_kses( $value, $allowed_html ); |
353 | 353 | } |
354 | 354 | |
355 | - /** |
|
356 | - * Used when switching the action for a bulk action |
|
357 | - * @since 2.0 |
|
358 | - */ |
|
359 | - public static function remove_get_action() { |
|
360 | - if ( ! isset($_GET) ) { |
|
361 | - return; |
|
362 | - } |
|
355 | + /** |
|
356 | + * Used when switching the action for a bulk action |
|
357 | + * @since 2.0 |
|
358 | + */ |
|
359 | + public static function remove_get_action() { |
|
360 | + if ( ! isset($_GET) ) { |
|
361 | + return; |
|
362 | + } |
|
363 | 363 | |
364 | - $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' ); |
|
365 | - if ( ! empty( $new_action ) ) { |
|
364 | + $new_action = isset( $_GET['action'] ) ? sanitize_text_field( $_GET['action'] ) : ( isset( $_GET['action2'] ) ? sanitize_text_field( $_GET['action2'] ) : '' ); |
|
365 | + if ( ! empty( $new_action ) ) { |
|
366 | 366 | $_SERVER['REQUEST_URI'] = str_replace( '&action=' . $new_action, '', FrmAppHelper::get_server_value( 'REQUEST_URI' ) ); |
367 | - } |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Check the WP query for a parameter |
|
372 | - * |
|
373 | - * @since 2.0 |
|
374 | - * @return string|array |
|
375 | - */ |
|
376 | - public static function get_query_var( $value, $param ) { |
|
377 | - if ( $value != '' ) { |
|
378 | - return $value; |
|
379 | - } |
|
380 | - |
|
381 | - global $wp_query; |
|
382 | - if ( isset( $wp_query->query_vars[ $param ] ) ) { |
|
383 | - $value = $wp_query->query_vars[ $param ]; |
|
384 | - } |
|
385 | - |
|
386 | - return $value; |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * @param string $type |
|
391 | - */ |
|
392 | - public static function trigger_hook_load( $type, $object = null ) { |
|
393 | - // only load the form hooks once |
|
394 | - $hooks_loaded = apply_filters('frm_'. $type .'_hooks_loaded', false, $object); |
|
395 | - if ( ! $hooks_loaded ) { |
|
396 | - do_action('frm_load_'. $type .'_hooks'); |
|
397 | - } |
|
398 | - } |
|
399 | - |
|
400 | - /** |
|
401 | - * Check cache before fetching values and saving to cache |
|
402 | - * |
|
403 | - * @since 2.0 |
|
404 | - * |
|
405 | - * @param string $cache_key The unique name for this cache |
|
406 | - * @param string $group The name of the cache group |
|
407 | - * @param string $query If blank, don't run a db call |
|
408 | - * @param string $type The wpdb function to use with this query |
|
409 | - * @return mixed $results The cache or query results |
|
410 | - */ |
|
411 | - public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) { |
|
412 | - $results = wp_cache_get($cache_key, $group); |
|
413 | - if ( ! self::is_empty_value( $results, false ) || empty($query) ) { |
|
414 | - return $results; |
|
415 | - } |
|
416 | - |
|
417 | - if ( 'get_posts' == $type ) { |
|
418 | - $results = get_posts($query); |
|
419 | - } else { |
|
420 | - global $wpdb; |
|
421 | - $results = $wpdb->{$type}($query); |
|
422 | - } |
|
367 | + } |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Check the WP query for a parameter |
|
372 | + * |
|
373 | + * @since 2.0 |
|
374 | + * @return string|array |
|
375 | + */ |
|
376 | + public static function get_query_var( $value, $param ) { |
|
377 | + if ( $value != '' ) { |
|
378 | + return $value; |
|
379 | + } |
|
380 | + |
|
381 | + global $wp_query; |
|
382 | + if ( isset( $wp_query->query_vars[ $param ] ) ) { |
|
383 | + $value = $wp_query->query_vars[ $param ]; |
|
384 | + } |
|
385 | + |
|
386 | + return $value; |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * @param string $type |
|
391 | + */ |
|
392 | + public static function trigger_hook_load( $type, $object = null ) { |
|
393 | + // only load the form hooks once |
|
394 | + $hooks_loaded = apply_filters('frm_'. $type .'_hooks_loaded', false, $object); |
|
395 | + if ( ! $hooks_loaded ) { |
|
396 | + do_action('frm_load_'. $type .'_hooks'); |
|
397 | + } |
|
398 | + } |
|
399 | + |
|
400 | + /** |
|
401 | + * Check cache before fetching values and saving to cache |
|
402 | + * |
|
403 | + * @since 2.0 |
|
404 | + * |
|
405 | + * @param string $cache_key The unique name for this cache |
|
406 | + * @param string $group The name of the cache group |
|
407 | + * @param string $query If blank, don't run a db call |
|
408 | + * @param string $type The wpdb function to use with this query |
|
409 | + * @return mixed $results The cache or query results |
|
410 | + */ |
|
411 | + public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) { |
|
412 | + $results = wp_cache_get($cache_key, $group); |
|
413 | + if ( ! self::is_empty_value( $results, false ) || empty($query) ) { |
|
414 | + return $results; |
|
415 | + } |
|
416 | + |
|
417 | + if ( 'get_posts' == $type ) { |
|
418 | + $results = get_posts($query); |
|
419 | + } else { |
|
420 | + global $wpdb; |
|
421 | + $results = $wpdb->{$type}($query); |
|
422 | + } |
|
423 | 423 | |
424 | 424 | if ( ! self::prevent_caching() ) { |
425 | 425 | wp_cache_set( $cache_key, $results, $group, $time ); |
426 | 426 | } |
427 | 427 | |
428 | - return $results; |
|
429 | - } |
|
428 | + return $results; |
|
429 | + } |
|
430 | 430 | |
431 | - /** |
|
432 | - * Data that should be stored for a long time can be stored in a transient. |
|
433 | - * First check the cache, then check the transient |
|
434 | - * @since 2.0 |
|
435 | - * @return mixed The cached value or false |
|
436 | - */ |
|
431 | + /** |
|
432 | + * Data that should be stored for a long time can be stored in a transient. |
|
433 | + * First check the cache, then check the transient |
|
434 | + * @since 2.0 |
|
435 | + * @return mixed The cached value or false |
|
436 | + */ |
|
437 | 437 | public static function check_cache_and_transient( $cache_key ) { |
438 | - // check caching layer first |
|
439 | - $results = self::check_cache( $cache_key ); |
|
440 | - if ( $results ) { |
|
441 | - return $results; |
|
442 | - } |
|
443 | - |
|
444 | - // then check the transient |
|
445 | - $results = get_transient($cache_key); |
|
446 | - if ( $results ) { |
|
447 | - wp_cache_set($cache_key, $results); |
|
448 | - } |
|
449 | - |
|
450 | - return $results; |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * @since 2.0 |
|
455 | - * @param string $cache_key |
|
456 | - */ |
|
438 | + // check caching layer first |
|
439 | + $results = self::check_cache( $cache_key ); |
|
440 | + if ( $results ) { |
|
441 | + return $results; |
|
442 | + } |
|
443 | + |
|
444 | + // then check the transient |
|
445 | + $results = get_transient($cache_key); |
|
446 | + if ( $results ) { |
|
447 | + wp_cache_set($cache_key, $results); |
|
448 | + } |
|
449 | + |
|
450 | + return $results; |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * @since 2.0 |
|
455 | + * @param string $cache_key |
|
456 | + */ |
|
457 | 457 | public static function delete_cache_and_transient( $cache_key ) { |
458 | - delete_transient($cache_key); |
|
459 | - wp_cache_delete($cache_key); |
|
460 | - } |
|
461 | - |
|
462 | - /** |
|
463 | - * Delete all caching in a single group |
|
464 | - * |
|
465 | - * @since 2.0 |
|
466 | - * |
|
467 | - * @param string $group The name of the cache group |
|
468 | - * @return boolean True or False |
|
469 | - */ |
|
458 | + delete_transient($cache_key); |
|
459 | + wp_cache_delete($cache_key); |
|
460 | + } |
|
461 | + |
|
462 | + /** |
|
463 | + * Delete all caching in a single group |
|
464 | + * |
|
465 | + * @since 2.0 |
|
466 | + * |
|
467 | + * @param string $group The name of the cache group |
|
468 | + * @return boolean True or False |
|
469 | + */ |
|
470 | 470 | public static function cache_delete_group( $group ) { |
471 | - global $wp_object_cache; |
|
472 | - |
|
473 | - if ( isset( $wp_object_cache->cache[ $group ] ) ) { |
|
474 | - foreach ( $wp_object_cache->cache[ $group ] as $k => $v ) { |
|
475 | - wp_cache_delete($k, $group); |
|
476 | - } |
|
477 | - return true; |
|
478 | - } |
|
479 | - |
|
480 | - return false; |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Check a value from a shortcode to see if true or false. |
|
485 | - * True when value is 1, true, 'true', 'yes' |
|
486 | - * |
|
487 | - * @since 1.07.10 |
|
488 | - * |
|
489 | - * @param string $value The value to compare |
|
490 | - * @return boolean True or False |
|
491 | - */ |
|
471 | + global $wp_object_cache; |
|
472 | + |
|
473 | + if ( isset( $wp_object_cache->cache[ $group ] ) ) { |
|
474 | + foreach ( $wp_object_cache->cache[ $group ] as $k => $v ) { |
|
475 | + wp_cache_delete($k, $group); |
|
476 | + } |
|
477 | + return true; |
|
478 | + } |
|
479 | + |
|
480 | + return false; |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Check a value from a shortcode to see if true or false. |
|
485 | + * True when value is 1, true, 'true', 'yes' |
|
486 | + * |
|
487 | + * @since 1.07.10 |
|
488 | + * |
|
489 | + * @param string $value The value to compare |
|
490 | + * @return boolean True or False |
|
491 | + */ |
|
492 | 492 | public static function is_true( $value ) { |
493 | - return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value ); |
|
494 | - } |
|
493 | + return ( true === $value || 1 == $value || 'true' == $value || 'yes' == $value ); |
|
494 | + } |
|
495 | 495 | |
496 | - /** |
|
497 | - * Used to filter shortcode in text widgets |
|
498 | - */ |
|
499 | - public static function widget_text_filter_callback( $matches ) { |
|
500 | - return do_shortcode( $matches[0] ); |
|
501 | - } |
|
496 | + /** |
|
497 | + * Used to filter shortcode in text widgets |
|
498 | + */ |
|
499 | + public static function widget_text_filter_callback( $matches ) { |
|
500 | + return do_shortcode( $matches[0] ); |
|
501 | + } |
|
502 | 502 | |
503 | 503 | public static function load_scripts( $scripts ) { |
504 | - _deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_script' ); |
|
505 | - foreach ( (array) $scripts as $s ) { |
|
506 | - wp_enqueue_script($s); |
|
507 | - } |
|
508 | - } |
|
504 | + _deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_script' ); |
|
505 | + foreach ( (array) $scripts as $s ) { |
|
506 | + wp_enqueue_script($s); |
|
507 | + } |
|
508 | + } |
|
509 | 509 | |
510 | 510 | public static function load_styles( $styles ) { |
511 | - _deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_style' ); |
|
512 | - foreach ( (array) $styles as $s ) { |
|
513 | - wp_enqueue_style($s); |
|
514 | - } |
|
515 | - } |
|
511 | + _deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_style' ); |
|
512 | + foreach ( (array) $styles as $s ) { |
|
513 | + wp_enqueue_style($s); |
|
514 | + } |
|
515 | + } |
|
516 | 516 | |
517 | - public static function get_pages() { |
|
517 | + public static function get_pages() { |
|
518 | 518 | return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ) ); |
519 | - } |
|
519 | + } |
|
520 | 520 | |
521 | - public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) { |
|
522 | - $pages = self::get_pages(); |
|
521 | + public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) { |
|
522 | + $pages = self::get_pages(); |
|
523 | 523 | $selected = self::get_post_param( $field_name, $page_id, 'absint' ); |
524 | - ?> |
|
524 | + ?> |
|
525 | 525 | <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" class="frm-pages-dropdown"> |
526 | 526 | <option value=""> </option> |
527 | 527 | <?php foreach ( $pages as $page ) { ?> |
@@ -531,107 +531,107 @@ discard block |
||
531 | 531 | <?php } ?> |
532 | 532 | </select> |
533 | 533 | <?php |
534 | - } |
|
534 | + } |
|
535 | 535 | |
536 | 536 | public static function post_edit_link( $post_id ) { |
537 | - $post = get_post($post_id); |
|
538 | - if ( $post ) { |
|
539 | - return '<a href="'. esc_url(admin_url('post.php') .'?post='. $post_id .'&action=edit') .'">'. self::truncate($post->post_title, 50) .'</a>'; |
|
540 | - } |
|
541 | - return ''; |
|
542 | - } |
|
537 | + $post = get_post($post_id); |
|
538 | + if ( $post ) { |
|
539 | + return '<a href="'. esc_url(admin_url('post.php') .'?post='. $post_id .'&action=edit') .'">'. self::truncate($post->post_title, 50) .'</a>'; |
|
540 | + } |
|
541 | + return ''; |
|
542 | + } |
|
543 | 543 | |
544 | 544 | public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) { |
545 | - ?> |
|
545 | + ?> |
|
546 | 546 | <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" <?php |
547 | - echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : ''; |
|
548 | - ?> class="frm_multiselect"> |
|
547 | + echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : ''; |
|
548 | + ?> class="frm_multiselect"> |
|
549 | 549 | <?php self::roles_options($capability); ?> |
550 | 550 | </select> |
551 | 551 | <?php |
552 | - } |
|
552 | + } |
|
553 | 553 | |
554 | 554 | public static function roles_options( $capability ) { |
555 | - global $frm_vars; |
|
556 | - if ( isset($frm_vars['editable_roles']) ) { |
|
557 | - $editable_roles = $frm_vars['editable_roles']; |
|
558 | - } else { |
|
559 | - $editable_roles = get_editable_roles(); |
|
560 | - $frm_vars['editable_roles'] = $editable_roles; |
|
561 | - } |
|
562 | - |
|
563 | - foreach ( $editable_roles as $role => $details ) { |
|
564 | - $name = translate_user_role($details['name'] ); ?> |
|
555 | + global $frm_vars; |
|
556 | + if ( isset($frm_vars['editable_roles']) ) { |
|
557 | + $editable_roles = $frm_vars['editable_roles']; |
|
558 | + } else { |
|
559 | + $editable_roles = get_editable_roles(); |
|
560 | + $frm_vars['editable_roles'] = $editable_roles; |
|
561 | + } |
|
562 | + |
|
563 | + foreach ( $editable_roles as $role => $details ) { |
|
564 | + $name = translate_user_role($details['name'] ); ?> |
|
565 | 565 | <option value="<?php echo esc_attr($role) ?>" <?php echo in_array($role, (array) $capability) ? ' selected="selected"' : ''; ?>><?php echo esc_attr($name) ?> </option> |
566 | 566 | <?php |
567 | - unset($role, $details); |
|
568 | - } |
|
569 | - } |
|
567 | + unset($role, $details); |
|
568 | + } |
|
569 | + } |
|
570 | 570 | |
571 | 571 | public static function frm_capabilities( $type = 'auto' ) { |
572 | - $cap = array( |
|
573 | - 'frm_view_forms' => __( 'View Forms and Templates', 'formidable' ), |
|
574 | - 'frm_edit_forms' => __( 'Add/Edit Forms and Templates', 'formidable' ), |
|
575 | - 'frm_delete_forms' => __( 'Delete Forms and Templates', 'formidable' ), |
|
576 | - 'frm_change_settings' => __( 'Access this Settings Page', 'formidable' ), |
|
577 | - 'frm_view_entries' => __( 'View Entries from Admin Area', 'formidable' ), |
|
578 | - 'frm_delete_entries' => __( 'Delete Entries from Admin Area', 'formidable' ), |
|
579 | - ); |
|
572 | + $cap = array( |
|
573 | + 'frm_view_forms' => __( 'View Forms and Templates', 'formidable' ), |
|
574 | + 'frm_edit_forms' => __( 'Add/Edit Forms and Templates', 'formidable' ), |
|
575 | + 'frm_delete_forms' => __( 'Delete Forms and Templates', 'formidable' ), |
|
576 | + 'frm_change_settings' => __( 'Access this Settings Page', 'formidable' ), |
|
577 | + 'frm_view_entries' => __( 'View Entries from Admin Area', 'formidable' ), |
|
578 | + 'frm_delete_entries' => __( 'Delete Entries from Admin Area', 'formidable' ), |
|
579 | + ); |
|
580 | 580 | |
581 | 581 | if ( ! self::pro_is_installed() && 'pro' != $type ) { |
582 | - return $cap; |
|
583 | - } |
|
582 | + return $cap; |
|
583 | + } |
|
584 | 584 | |
585 | - $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' ); |
|
586 | - $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' ); |
|
587 | - $cap['frm_view_reports'] = __( 'View Reports', 'formidable' ); |
|
588 | - $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' ); |
|
585 | + $cap['frm_create_entries'] = __( 'Add Entries from Admin Area', 'formidable' ); |
|
586 | + $cap['frm_edit_entries'] = __( 'Edit Entries from Admin Area', 'formidable' ); |
|
587 | + $cap['frm_view_reports'] = __( 'View Reports', 'formidable' ); |
|
588 | + $cap['frm_edit_displays'] = __( 'Add/Edit Views', 'formidable' ); |
|
589 | 589 | |
590 | - return $cap; |
|
591 | - } |
|
590 | + return $cap; |
|
591 | + } |
|
592 | 592 | |
593 | 593 | public static function user_has_permission( $needed_role ) { |
594 | - if ( $needed_role == '-1' ) { |
|
595 | - return false; |
|
594 | + if ( $needed_role == '-1' ) { |
|
595 | + return false; |
|
596 | 596 | } |
597 | 597 | |
598 | - // $needed_role will be equal to blank if "Logged-in users" is selected |
|
599 | - if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) { |
|
600 | - return true; |
|
601 | - } |
|
598 | + // $needed_role will be equal to blank if "Logged-in users" is selected |
|
599 | + if ( ( $needed_role == '' && is_user_logged_in() ) || current_user_can( $needed_role ) ) { |
|
600 | + return true; |
|
601 | + } |
|
602 | 602 | |
603 | - $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' ); |
|
604 | - foreach ( $roles as $role ) { |
|
603 | + $roles = array( 'administrator', 'editor', 'author', 'contributor', 'subscriber' ); |
|
604 | + foreach ( $roles as $role ) { |
|
605 | 605 | if ( current_user_can( $role ) ) { |
606 | - return true; |
|
606 | + return true; |
|
607 | 607 | } |
608 | - if ( $role == $needed_role ) { |
|
609 | - break; |
|
608 | + if ( $role == $needed_role ) { |
|
609 | + break; |
|
610 | 610 | } |
611 | - } |
|
612 | - return false; |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Make sure administrators can see Formidable menu |
|
617 | - * |
|
618 | - * @since 2.0 |
|
619 | - */ |
|
620 | - public static function maybe_add_permissions() { |
|
611 | + } |
|
612 | + return false; |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Make sure administrators can see Formidable menu |
|
617 | + * |
|
618 | + * @since 2.0 |
|
619 | + */ |
|
620 | + public static function maybe_add_permissions() { |
|
621 | 621 | self::force_capability( 'frm_view_entries' ); |
622 | 622 | |
623 | - if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) { |
|
624 | - return; |
|
625 | - } |
|
623 | + if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) { |
|
624 | + return; |
|
625 | + } |
|
626 | 626 | |
627 | 627 | $user_id = get_current_user_id(); |
628 | 628 | $user = new WP_User( $user_id ); |
629 | - $frm_roles = self::frm_capabilities(); |
|
630 | - foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
629 | + $frm_roles = self::frm_capabilities(); |
|
630 | + foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
|
631 | 631 | $user->add_cap( $frm_role ); |
632 | - unset($frm_role, $frm_role_description); |
|
633 | - } |
|
634 | - } |
|
632 | + unset($frm_role, $frm_role_description); |
|
633 | + } |
|
634 | + } |
|
635 | 635 | |
636 | 636 | /** |
637 | 637 | * Make sure admins have permission to see the menu items |
@@ -647,28 +647,28 @@ discard block |
||
647 | 647 | } |
648 | 648 | } |
649 | 649 | |
650 | - /** |
|
651 | - * Check if the user has permision for action. |
|
652 | - * Return permission message and stop the action if no permission |
|
653 | - * @since 2.0 |
|
654 | - * @param string $permission |
|
655 | - */ |
|
650 | + /** |
|
651 | + * Check if the user has permision for action. |
|
652 | + * Return permission message and stop the action if no permission |
|
653 | + * @since 2.0 |
|
654 | + * @param string $permission |
|
655 | + */ |
|
656 | 656 | public static function permission_check( $permission, $show_message = 'show' ) { |
657 | - $permission_error = self::permission_nonce_error($permission); |
|
658 | - if ( $permission_error !== false ) { |
|
659 | - if ( 'hide' == $show_message ) { |
|
660 | - $permission_error = ''; |
|
661 | - } |
|
662 | - wp_die($permission_error); |
|
663 | - } |
|
664 | - } |
|
665 | - |
|
666 | - /** |
|
667 | - * Check user permission and nonce |
|
668 | - * @since 2.0 |
|
669 | - * @param string $permission |
|
670 | - * @return false|string The permission message or false if allowed |
|
671 | - */ |
|
657 | + $permission_error = self::permission_nonce_error($permission); |
|
658 | + if ( $permission_error !== false ) { |
|
659 | + if ( 'hide' == $show_message ) { |
|
660 | + $permission_error = ''; |
|
661 | + } |
|
662 | + wp_die($permission_error); |
|
663 | + } |
|
664 | + } |
|
665 | + |
|
666 | + /** |
|
667 | + * Check user permission and nonce |
|
668 | + * @since 2.0 |
|
669 | + * @param string $permission |
|
670 | + * @return false|string The permission message or false if allowed |
|
671 | + */ |
|
672 | 672 | public static function permission_nonce_error( $permission, $nonce_name = '', $nonce = '' ) { |
673 | 673 | if ( ! empty( $permission ) && ! current_user_can( $permission ) && ! current_user_can( 'administrator' ) ) { |
674 | 674 | $frm_settings = self::get_settings(); |
@@ -676,75 +676,75 @@ discard block |
||
676 | 676 | } |
677 | 677 | |
678 | 678 | $error = false; |
679 | - if ( empty($nonce_name) ) { |
|
680 | - return $error; |
|
681 | - } |
|
679 | + if ( empty($nonce_name) ) { |
|
680 | + return $error; |
|
681 | + } |
|
682 | 682 | |
683 | - if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) { |
|
684 | - $frm_settings = self::get_settings(); |
|
685 | - $error = $frm_settings->admin_permission; |
|
686 | - } |
|
683 | + if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) { |
|
684 | + $frm_settings = self::get_settings(); |
|
685 | + $error = $frm_settings->admin_permission; |
|
686 | + } |
|
687 | 687 | |
688 | - return $error; |
|
689 | - } |
|
688 | + return $error; |
|
689 | + } |
|
690 | 690 | |
691 | - public static function checked( $values, $current ) { |
|
691 | + public static function checked( $values, $current ) { |
|
692 | 692 | if ( self::check_selected( $values, $current ) ) { |
693 | - echo ' checked="checked"'; |
|
693 | + echo ' checked="checked"'; |
|
694 | 694 | } |
695 | - } |
|
695 | + } |
|
696 | 696 | |
697 | 697 | public static function check_selected( $values, $current ) { |
698 | - $values = self::recursive_function_map( $values, 'trim' ); |
|
699 | - $current = trim($current); |
|
700 | - |
|
701 | - return ( is_array($values) && in_array($current, $values) ) || ( ! is_array($values) && $values == $current ); |
|
702 | - } |
|
703 | - |
|
704 | - /** |
|
705 | - * Check if current field option is an "other" option |
|
706 | - * |
|
707 | - * @since 2.0 |
|
708 | - * |
|
709 | - * @param string $opt_key |
|
710 | - * @return boolean Returns true if current field option is an "Other" option |
|
711 | - */ |
|
712 | - public static function is_other_opt( $opt_key ) { |
|
713 | - _deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::is_other_opt' ); |
|
714 | - return FrmFieldsHelper::is_other_opt( $opt_key ); |
|
715 | - } |
|
716 | - |
|
717 | - /** |
|
718 | - * Get value that belongs in "Other" text box |
|
719 | - * |
|
720 | - * @since 2.0 |
|
721 | - * |
|
722 | - * @param string $opt_key |
|
723 | - * @param array $field |
|
724 | - * @return string $other_val |
|
725 | - */ |
|
726 | - public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) { |
|
698 | + $values = self::recursive_function_map( $values, 'trim' ); |
|
699 | + $current = trim($current); |
|
700 | + |
|
701 | + return ( is_array($values) && in_array($current, $values) ) || ( ! is_array($values) && $values == $current ); |
|
702 | + } |
|
703 | + |
|
704 | + /** |
|
705 | + * Check if current field option is an "other" option |
|
706 | + * |
|
707 | + * @since 2.0 |
|
708 | + * |
|
709 | + * @param string $opt_key |
|
710 | + * @return boolean Returns true if current field option is an "Other" option |
|
711 | + */ |
|
712 | + public static function is_other_opt( $opt_key ) { |
|
713 | + _deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::is_other_opt' ); |
|
714 | + return FrmFieldsHelper::is_other_opt( $opt_key ); |
|
715 | + } |
|
716 | + |
|
717 | + /** |
|
718 | + * Get value that belongs in "Other" text box |
|
719 | + * |
|
720 | + * @since 2.0 |
|
721 | + * |
|
722 | + * @param string $opt_key |
|
723 | + * @param array $field |
|
724 | + * @return string $other_val |
|
725 | + */ |
|
726 | + public static function get_other_val( $opt_key, $field, $parent = false, $pointer = false ) { |
|
727 | 727 | _deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::get_other_val' ); |
728 | 728 | return FrmFieldsHelper::get_other_val( compact( 'opt_key', 'field', 'parent', 'pointer' ) ); |
729 | - } |
|
730 | - |
|
731 | - /** |
|
732 | - * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val. |
|
733 | - * Intended for front-end use |
|
734 | - * |
|
735 | - * @since 2.0 |
|
736 | - * |
|
737 | - * @param array $field |
|
738 | - * @param boolean $other_opt |
|
739 | - * @param string $checked |
|
740 | - * @param array $args should include opt_key and field name |
|
741 | - * @return string $other_val |
|
742 | - */ |
|
743 | - public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ) { |
|
729 | + } |
|
730 | + |
|
731 | + /** |
|
732 | + * Check if there is a saved value for the "Other" text field. If so, set it as the $other_val. |
|
733 | + * Intended for front-end use |
|
734 | + * |
|
735 | + * @since 2.0 |
|
736 | + * |
|
737 | + * @param array $field |
|
738 | + * @param boolean $other_opt |
|
739 | + * @param string $checked |
|
740 | + * @param array $args should include opt_key and field name |
|
741 | + * @return string $other_val |
|
742 | + */ |
|
743 | + public static function prepare_other_input( $field, &$other_opt, &$checked, $args = array() ) { |
|
744 | 744 | _deprecated_function( __FUNCTION__, '2.0.6', 'FrmFieldsHelper::prepare_other_input' ); |
745 | 745 | $args['field'] = $field; |
746 | 746 | return FrmFieldsHelper::prepare_other_input( $args, $other_opt, $checked ); |
747 | - } |
|
747 | + } |
|
748 | 748 | |
749 | 749 | public static function recursive_function_map( $value, $function ) { |
750 | 750 | if ( is_array( $value ) ) { |
@@ -774,334 +774,334 @@ discard block |
||
774 | 774 | return (bool) count( array_filter( array_keys( $array ), 'is_string' ) ); |
775 | 775 | } |
776 | 776 | |
777 | - /** |
|
778 | - * Flatten a multi-dimensional array |
|
779 | - */ |
|
777 | + /** |
|
778 | + * Flatten a multi-dimensional array |
|
779 | + */ |
|
780 | 780 | public static function array_flatten( $array, $keys = 'keep' ) { |
781 | - $return = array(); |
|
782 | - foreach ( $array as $key => $value ) { |
|
783 | - if ( is_array($value) ) { |
|
781 | + $return = array(); |
|
782 | + foreach ( $array as $key => $value ) { |
|
783 | + if ( is_array($value) ) { |
|
784 | 784 | $return = array_merge( $return, self::array_flatten( $value, $keys ) ); |
785 | - } else { |
|
785 | + } else { |
|
786 | 786 | if ( $keys == 'keep' ) { |
787 | 787 | $return[ $key ] = $value; |
788 | 788 | } else { |
789 | 789 | $return[] = $value; |
790 | 790 | } |
791 | - } |
|
792 | - } |
|
793 | - return $return; |
|
794 | - } |
|
795 | - |
|
796 | - public static function esc_textarea( $text ) { |
|
797 | - $safe_text = str_replace('"', '"', $text); |
|
798 | - $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES ); |
|
799 | - return apply_filters( 'esc_textarea', $safe_text, $text ); |
|
800 | - } |
|
801 | - |
|
802 | - /** |
|
803 | - * Add auto paragraphs to text areas |
|
804 | - * @since 2.0 |
|
805 | - */ |
|
791 | + } |
|
792 | + } |
|
793 | + return $return; |
|
794 | + } |
|
795 | + |
|
796 | + public static function esc_textarea( $text ) { |
|
797 | + $safe_text = str_replace('"', '"', $text); |
|
798 | + $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES ); |
|
799 | + return apply_filters( 'esc_textarea', $safe_text, $text ); |
|
800 | + } |
|
801 | + |
|
802 | + /** |
|
803 | + * Add auto paragraphs to text areas |
|
804 | + * @since 2.0 |
|
805 | + */ |
|
806 | 806 | public static function use_wpautop( $content ) { |
807 | - if ( apply_filters('frm_use_wpautop', true) ) { |
|
808 | - $content = wpautop(str_replace( '<br>', '<br />', $content)); |
|
809 | - } |
|
810 | - return $content; |
|
811 | - } |
|
807 | + if ( apply_filters('frm_use_wpautop', true) ) { |
|
808 | + $content = wpautop(str_replace( '<br>', '<br />', $content)); |
|
809 | + } |
|
810 | + return $content; |
|
811 | + } |
|
812 | 812 | |
813 | 813 | public static function replace_quotes( $val ) { |
814 | - //Replace double quotes |
|
814 | + //Replace double quotes |
|
815 | 815 | $val = str_replace( array( '“', '”', '″' ), '"', $val ); |
816 | - //Replace single quotes |
|
817 | - $val = str_replace( array( '‘', '’', '′', '′', '’', '‘' ), "'", $val ); |
|
818 | - return $val; |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * @since 2.0 |
|
823 | - * @return string The base Google APIS url for the current version of jQuery UI |
|
824 | - */ |
|
825 | - public static function jquery_ui_base_url() { |
|
826 | - $url = 'http'. ( is_ssl() ? 's' : '' ) .'://ajax.googleapis.com/ajax/libs/jqueryui/'. self::script_version('jquery-ui-core'); |
|
827 | - $url = apply_filters('frm_jquery_ui_base_url', $url); |
|
828 | - return $url; |
|
829 | - } |
|
830 | - |
|
831 | - /** |
|
832 | - * @param string $handle |
|
833 | - */ |
|
816 | + //Replace single quotes |
|
817 | + $val = str_replace( array( '‘', '’', '′', '′', '’', '‘' ), "'", $val ); |
|
818 | + return $val; |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * @since 2.0 |
|
823 | + * @return string The base Google APIS url for the current version of jQuery UI |
|
824 | + */ |
|
825 | + public static function jquery_ui_base_url() { |
|
826 | + $url = 'http'. ( is_ssl() ? 's' : '' ) .'://ajax.googleapis.com/ajax/libs/jqueryui/'. self::script_version('jquery-ui-core'); |
|
827 | + $url = apply_filters('frm_jquery_ui_base_url', $url); |
|
828 | + return $url; |
|
829 | + } |
|
830 | + |
|
831 | + /** |
|
832 | + * @param string $handle |
|
833 | + */ |
|
834 | 834 | public static function script_version( $handle ) { |
835 | - global $wp_scripts; |
|
836 | - if ( ! $wp_scripts ) { |
|
837 | - return false; |
|
838 | - } |
|
835 | + global $wp_scripts; |
|
836 | + if ( ! $wp_scripts ) { |
|
837 | + return false; |
|
838 | + } |
|
839 | 839 | |
840 | - $ver = 0; |
|
840 | + $ver = 0; |
|
841 | 841 | |
842 | - if ( ! isset( $wp_scripts->registered[ $handle ] ) ) { |
|
843 | - return $ver; |
|
844 | - } |
|
842 | + if ( ! isset( $wp_scripts->registered[ $handle ] ) ) { |
|
843 | + return $ver; |
|
844 | + } |
|
845 | 845 | |
846 | - $query = $wp_scripts->registered[ $handle ]; |
|
847 | - if ( is_object( $query ) ) { |
|
848 | - $ver = $query->ver; |
|
849 | - } |
|
846 | + $query = $wp_scripts->registered[ $handle ]; |
|
847 | + if ( is_object( $query ) ) { |
|
848 | + $ver = $query->ver; |
|
849 | + } |
|
850 | 850 | |
851 | - return $ver; |
|
852 | - } |
|
851 | + return $ver; |
|
852 | + } |
|
853 | 853 | |
854 | 854 | public static function js_redirect( $url ) { |
855 | 855 | return '<script type="text/javascript">window.location="' . esc_url_raw( $url ) . '"</script>'; |
856 | - } |
|
856 | + } |
|
857 | 857 | |
858 | 858 | public static function get_user_id_param( $user_id ) { |
859 | - if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) { |
|
860 | - return $user_id; |
|
861 | - } |
|
859 | + if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) { |
|
860 | + return $user_id; |
|
861 | + } |
|
862 | 862 | |
863 | 863 | if ( $user_id == 'current' ) { |
864 | - $user_ID = get_current_user_id(); |
|
865 | - $user_id = $user_ID; |
|
864 | + $user_ID = get_current_user_id(); |
|
865 | + $user_id = $user_ID; |
|
866 | 866 | } else { |
867 | - if ( is_email($user_id) ) { |
|
868 | - $user = get_user_by('email', $user_id); |
|
869 | - } else { |
|
870 | - $user = get_user_by('login', $user_id); |
|
871 | - } |
|
867 | + if ( is_email($user_id) ) { |
|
868 | + $user = get_user_by('email', $user_id); |
|
869 | + } else { |
|
870 | + $user = get_user_by('login', $user_id); |
|
871 | + } |
|
872 | 872 | |
873 | - if ( $user ) { |
|
874 | - $user_id = $user->ID; |
|
875 | - } |
|
876 | - unset($user); |
|
877 | - } |
|
873 | + if ( $user ) { |
|
874 | + $user_id = $user->ID; |
|
875 | + } |
|
876 | + unset($user); |
|
877 | + } |
|
878 | 878 | |
879 | - return $user_id; |
|
880 | - } |
|
879 | + return $user_id; |
|
880 | + } |
|
881 | 881 | |
882 | 882 | public static function get_file_contents( $filename, $atts = array() ) { |
883 | - if ( ! is_file($filename) ) { |
|
884 | - return false; |
|
885 | - } |
|
886 | - |
|
887 | - extract($atts); |
|
888 | - ob_start(); |
|
889 | - include($filename); |
|
890 | - $contents = ob_get_contents(); |
|
891 | - ob_end_clean(); |
|
892 | - return $contents; |
|
893 | - } |
|
894 | - |
|
895 | - /** |
|
896 | - * @param string $table_name |
|
897 | - * @param string $column |
|
898 | - */ |
|
899 | - public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 6 ) { |
|
900 | - global $wpdb; |
|
901 | - |
|
902 | - $key = ''; |
|
903 | - |
|
904 | - if ( ! empty( $name ) ) { |
|
905 | - $key = sanitize_key($name); |
|
906 | - } |
|
883 | + if ( ! is_file($filename) ) { |
|
884 | + return false; |
|
885 | + } |
|
886 | + |
|
887 | + extract($atts); |
|
888 | + ob_start(); |
|
889 | + include($filename); |
|
890 | + $contents = ob_get_contents(); |
|
891 | + ob_end_clean(); |
|
892 | + return $contents; |
|
893 | + } |
|
894 | + |
|
895 | + /** |
|
896 | + * @param string $table_name |
|
897 | + * @param string $column |
|
898 | + */ |
|
899 | + public static function get_unique_key( $name = '', $table_name, $column, $id = 0, $num_chars = 6 ) { |
|
900 | + global $wpdb; |
|
901 | + |
|
902 | + $key = ''; |
|
903 | + |
|
904 | + if ( ! empty( $name ) ) { |
|
905 | + $key = sanitize_key($name); |
|
906 | + } |
|
907 | 907 | |
908 | 908 | if ( empty( $key ) ) { |
909 | - $max_slug_value = pow(36, $num_chars); |
|
910 | - $min_slug_value = 37; // we want to have at least 2 characters in the slug |
|
911 | - $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
912 | - } |
|
909 | + $max_slug_value = pow(36, $num_chars); |
|
910 | + $min_slug_value = 37; // we want to have at least 2 characters in the slug |
|
911 | + $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
912 | + } |
|
913 | 913 | |
914 | 914 | if ( is_numeric($key) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) { |
915 | - $key = $key .'a'; |
|
916 | - } |
|
915 | + $key = $key .'a'; |
|
916 | + } |
|
917 | 917 | |
918 | 918 | $key_check = FrmDb::get_var( $table_name, array( $column => $key, 'ID !' => $id ), $column ); |
919 | 919 | |
920 | - if ( $key_check || is_numeric($key_check) ) { |
|
921 | - $suffix = 2; |
|
920 | + if ( $key_check || is_numeric($key_check) ) { |
|
921 | + $suffix = 2; |
|
922 | 922 | do { |
923 | 923 | $alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix; |
924 | 924 | $key_check = FrmDb::get_var( $table_name, array( $column => $alt_post_name, 'ID !' => $id ), $column ); |
925 | 925 | $suffix++; |
926 | 926 | } while ($key_check || is_numeric($key_check)); |
927 | 927 | $key = $alt_post_name; |
928 | - } |
|
929 | - return $key; |
|
930 | - } |
|
931 | - |
|
932 | - /** |
|
933 | - * Editing a Form or Entry |
|
934 | - * @param string $table |
|
935 | - * @return bool|array |
|
936 | - */ |
|
937 | - public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) { |
|
938 | - if ( ! $record ) { |
|
939 | - return false; |
|
940 | - } |
|
941 | - |
|
942 | - global $frm_vars; |
|
943 | - |
|
944 | - if ( empty($post_values) ) { |
|
945 | - $post_values = stripslashes_deep($_POST); |
|
946 | - } |
|
928 | + } |
|
929 | + return $key; |
|
930 | + } |
|
931 | + |
|
932 | + /** |
|
933 | + * Editing a Form or Entry |
|
934 | + * @param string $table |
|
935 | + * @return bool|array |
|
936 | + */ |
|
937 | + public static function setup_edit_vars( $record, $table, $fields = '', $default = false, $post_values = array(), $args = array() ) { |
|
938 | + if ( ! $record ) { |
|
939 | + return false; |
|
940 | + } |
|
941 | + |
|
942 | + global $frm_vars; |
|
943 | + |
|
944 | + if ( empty($post_values) ) { |
|
945 | + $post_values = stripslashes_deep($_POST); |
|
946 | + } |
|
947 | 947 | |
948 | 948 | $values = array( 'id' => $record->id, 'fields' => array() ); |
949 | 949 | |
950 | 950 | foreach ( array( 'name', 'description' ) as $var ) { |
951 | - $default_val = isset($record->{$var}) ? $record->{$var} : ''; |
|
952 | - $values[ $var ] = self::get_param( $var, $default_val ); |
|
953 | - unset($var, $default_val); |
|
954 | - } |
|
955 | - |
|
956 | - $values['description'] = self::use_wpautop($values['description']); |
|
957 | - $frm_settings = self::get_settings(); |
|
958 | - $is_form_builder = self::is_admin_page('formidable' ); |
|
959 | - |
|
960 | - foreach ( (array) $fields as $field ) { |
|
961 | - // Make sure to filter default values (for placeholder text), but not on the form builder page |
|
962 | - if ( ! $is_form_builder ) { |
|
963 | - $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true ); |
|
964 | - } |
|
951 | + $default_val = isset($record->{$var}) ? $record->{$var} : ''; |
|
952 | + $values[ $var ] = self::get_param( $var, $default_val ); |
|
953 | + unset($var, $default_val); |
|
954 | + } |
|
955 | + |
|
956 | + $values['description'] = self::use_wpautop($values['description']); |
|
957 | + $frm_settings = self::get_settings(); |
|
958 | + $is_form_builder = self::is_admin_page('formidable' ); |
|
959 | + |
|
960 | + foreach ( (array) $fields as $field ) { |
|
961 | + // Make sure to filter default values (for placeholder text), but not on the form builder page |
|
962 | + if ( ! $is_form_builder ) { |
|
963 | + $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true ); |
|
964 | + } |
|
965 | 965 | $parent_form_id = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id; |
966 | 966 | self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings', 'parent_form_id' ) ); |
967 | - } |
|
967 | + } |
|
968 | 968 | |
969 | - self::fill_form_opts($record, $table, $post_values, $values); |
|
969 | + self::fill_form_opts($record, $table, $post_values, $values); |
|
970 | 970 | |
971 | - if ( $table == 'entries' ) { |
|
972 | - $values = FrmEntriesHelper::setup_edit_vars( $values, $record ); |
|
973 | - } else if ( $table == 'forms' ) { |
|
974 | - $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values ); |
|
975 | - } |
|
971 | + if ( $table == 'entries' ) { |
|
972 | + $values = FrmEntriesHelper::setup_edit_vars( $values, $record ); |
|
973 | + } else if ( $table == 'forms' ) { |
|
974 | + $values = FrmFormsHelper::setup_edit_vars( $values, $record, $post_values ); |
|
975 | + } |
|
976 | 976 | |
977 | - return $values; |
|
978 | - } |
|
977 | + return $values; |
|
978 | + } |
|
979 | 979 | |
980 | 980 | private static function fill_field_defaults( $field, $record, array &$values, $args ) { |
981 | - $post_values = $args['post_values']; |
|
982 | - |
|
983 | - if ( $args['default'] ) { |
|
984 | - $meta_value = $field->default_value; |
|
985 | - } else { |
|
986 | - if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) { |
|
987 | - if ( ! isset($field->field_options['custom_field']) ) { |
|
988 | - $field->field_options['custom_field'] = ''; |
|
989 | - } |
|
981 | + $post_values = $args['post_values']; |
|
982 | + |
|
983 | + if ( $args['default'] ) { |
|
984 | + $meta_value = $field->default_value; |
|
985 | + } else { |
|
986 | + if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) { |
|
987 | + if ( ! isset($field->field_options['custom_field']) ) { |
|
988 | + $field->field_options['custom_field'] = ''; |
|
989 | + } |
|
990 | 990 | $meta_value = FrmProEntryMetaHelper::get_post_value( $record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array( 'truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field ) ); |
991 | - } else { |
|
991 | + } else { |
|
992 | 992 | $meta_value = FrmEntryMeta::get_meta_value( $record, $field->id ); |
993 | - } |
|
994 | - } |
|
995 | - |
|
996 | - $field_type = isset( $post_values['field_options'][ 'type_'. $field->id ] ) ? $post_values['field_options'][ 'type_'. $field->id ] : $field->type; |
|
997 | - $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value; |
|
998 | - |
|
999 | - $field_array = array( |
|
1000 | - 'id' => $field->id, |
|
1001 | - 'value' => $new_value, |
|
1002 | - 'default_value' => $field->default_value, |
|
1003 | - 'name' => $field->name, |
|
1004 | - 'description' => $field->description, |
|
1005 | - 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value), |
|
1006 | - 'options' => $field->options, |
|
1007 | - 'required' => $field->required, |
|
1008 | - 'field_key' => $field->field_key, |
|
1009 | - 'field_order' => $field->field_order, |
|
1010 | - 'form_id' => $field->form_id, |
|
993 | + } |
|
994 | + } |
|
995 | + |
|
996 | + $field_type = isset( $post_values['field_options'][ 'type_'. $field->id ] ) ? $post_values['field_options'][ 'type_'. $field->id ] : $field->type; |
|
997 | + $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value; |
|
998 | + |
|
999 | + $field_array = array( |
|
1000 | + 'id' => $field->id, |
|
1001 | + 'value' => $new_value, |
|
1002 | + 'default_value' => $field->default_value, |
|
1003 | + 'name' => $field->name, |
|
1004 | + 'description' => $field->description, |
|
1005 | + 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value), |
|
1006 | + 'options' => $field->options, |
|
1007 | + 'required' => $field->required, |
|
1008 | + 'field_key' => $field->field_key, |
|
1009 | + 'field_order' => $field->field_order, |
|
1010 | + 'form_id' => $field->form_id, |
|
1011 | 1011 | 'parent_form_id' => $args['parent_form_id'], |
1012 | - ); |
|
1012 | + ); |
|
1013 | 1013 | |
1014 | - $args['field_type'] = $field_type; |
|
1015 | - self::fill_field_opts($field, $field_array, $args); |
|
1014 | + $args['field_type'] = $field_type; |
|
1015 | + self::fill_field_opts($field, $field_array, $args); |
|
1016 | 1016 | |
1017 | - $field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']); |
|
1017 | + $field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']); |
|
1018 | 1018 | |
1019 | - if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) { |
|
1020 | - $field_array['unique_msg'] = ''; |
|
1021 | - } |
|
1019 | + if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) { |
|
1020 | + $field_array['unique_msg'] = ''; |
|
1021 | + } |
|
1022 | 1022 | |
1023 | - $field_array = array_merge( $field->field_options, $field_array ); |
|
1023 | + $field_array = array_merge( $field->field_options, $field_array ); |
|
1024 | 1024 | |
1025 | - $values['fields'][ $field->id ] = $field_array; |
|
1026 | - } |
|
1025 | + $values['fields'][ $field->id ] = $field_array; |
|
1026 | + } |
|
1027 | 1027 | |
1028 | 1028 | private static function fill_field_opts( $field, array &$field_array, $args ) { |
1029 | - $post_values = $args['post_values']; |
|
1030 | - $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
1031 | - |
|
1032 | - foreach ( $opt_defaults as $opt => $default_opt ) { |
|
1033 | - $field_array[ $opt ] = ( $post_values && isset( $post_values['field_options'][ $opt .'_'. $field->id ] ) ) ? maybe_unserialize( $post_values['field_options'][ $opt .'_'. $field->id ] ) : ( isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default_opt ); |
|
1034 | - if ( $opt == 'blank' && $field_array[ $opt ] == '' ) { |
|
1035 | - $field_array[ $opt ] = $args['frm_settings']->blank_msg; |
|
1036 | - } else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) { |
|
1037 | - if ( $args['field_type'] == 'captcha' ) { |
|
1038 | - $field_array[ $opt ] = $args['frm_settings']->re_msg; |
|
1039 | - } else { |
|
1040 | - $field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] ); |
|
1041 | - } |
|
1042 | - } |
|
1043 | - } |
|
1044 | - |
|
1045 | - if ( $field_array['custom_html'] == '' ) { |
|
1046 | - $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']); |
|
1047 | - } |
|
1048 | - } |
|
1049 | - |
|
1050 | - /** |
|
1051 | - * @param string $table |
|
1052 | - */ |
|
1029 | + $post_values = $args['post_values']; |
|
1030 | + $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
1031 | + |
|
1032 | + foreach ( $opt_defaults as $opt => $default_opt ) { |
|
1033 | + $field_array[ $opt ] = ( $post_values && isset( $post_values['field_options'][ $opt .'_'. $field->id ] ) ) ? maybe_unserialize( $post_values['field_options'][ $opt .'_'. $field->id ] ) : ( isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default_opt ); |
|
1034 | + if ( $opt == 'blank' && $field_array[ $opt ] == '' ) { |
|
1035 | + $field_array[ $opt ] = $args['frm_settings']->blank_msg; |
|
1036 | + } else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) { |
|
1037 | + if ( $args['field_type'] == 'captcha' ) { |
|
1038 | + $field_array[ $opt ] = $args['frm_settings']->re_msg; |
|
1039 | + } else { |
|
1040 | + $field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] ); |
|
1041 | + } |
|
1042 | + } |
|
1043 | + } |
|
1044 | + |
|
1045 | + if ( $field_array['custom_html'] == '' ) { |
|
1046 | + $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']); |
|
1047 | + } |
|
1048 | + } |
|
1049 | + |
|
1050 | + /** |
|
1051 | + * @param string $table |
|
1052 | + */ |
|
1053 | 1053 | private static function fill_form_opts( $record, $table, $post_values, array &$values ) { |
1054 | - if ( $table == 'entries' ) { |
|
1055 | - $form = $record->form_id; |
|
1054 | + if ( $table == 'entries' ) { |
|
1055 | + $form = $record->form_id; |
|
1056 | 1056 | FrmForm::maybe_get_form( $form ); |
1057 | - } else { |
|
1058 | - $form = $record; |
|
1059 | - } |
|
1057 | + } else { |
|
1058 | + $form = $record; |
|
1059 | + } |
|
1060 | 1060 | |
1061 | - if ( ! $form ) { |
|
1062 | - return; |
|
1063 | - } |
|
1061 | + if ( ! $form ) { |
|
1062 | + return; |
|
1063 | + } |
|
1064 | 1064 | |
1065 | - $values['form_name'] = isset($record->form_id) ? $form->name : ''; |
|
1065 | + $values['form_name'] = isset($record->form_id) ? $form->name : ''; |
|
1066 | 1066 | $values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0; |
1067 | 1067 | |
1068 | - if ( ! is_array($form->options) ) { |
|
1069 | - return; |
|
1070 | - } |
|
1068 | + if ( ! is_array($form->options) ) { |
|
1069 | + return; |
|
1070 | + } |
|
1071 | 1071 | |
1072 | - foreach ( $form->options as $opt => $value ) { |
|
1073 | - $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value; |
|
1074 | - } |
|
1072 | + foreach ( $form->options as $opt => $value ) { |
|
1073 | + $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value; |
|
1074 | + } |
|
1075 | 1075 | |
1076 | - self::fill_form_defaults($post_values, $values); |
|
1077 | - } |
|
1076 | + self::fill_form_defaults($post_values, $values); |
|
1077 | + } |
|
1078 | 1078 | |
1079 | - /** |
|
1080 | - * Set to POST value or default |
|
1081 | - */ |
|
1079 | + /** |
|
1080 | + * Set to POST value or default |
|
1081 | + */ |
|
1082 | 1082 | private static function fill_form_defaults( $post_values, array &$values ) { |
1083 | - $form_defaults = FrmFormsHelper::get_default_opts(); |
|
1083 | + $form_defaults = FrmFormsHelper::get_default_opts(); |
|
1084 | 1084 | |
1085 | - foreach ( $form_defaults as $opt => $default ) { |
|
1086 | - if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) { |
|
1085 | + foreach ( $form_defaults as $opt => $default ) { |
|
1086 | + if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) { |
|
1087 | 1087 | $values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default; |
1088 | - } |
|
1088 | + } |
|
1089 | 1089 | |
1090 | - unset($opt, $defaut); |
|
1091 | - } |
|
1090 | + unset($opt, $defaut); |
|
1091 | + } |
|
1092 | 1092 | |
1093 | - if ( ! isset($values['custom_style']) ) { |
|
1094 | - $frm_settings = self::get_settings(); |
|
1093 | + if ( ! isset($values['custom_style']) ) { |
|
1094 | + $frm_settings = self::get_settings(); |
|
1095 | 1095 | $values['custom_style'] = ( $post_values && isset( $post_values['options']['custom_style'] ) ) ? absint( $_POST['options']['custom_style'] ) : ( $frm_settings->load_style != 'none' ); |
1096 | - } |
|
1096 | + } |
|
1097 | 1097 | |
1098 | 1098 | foreach ( array( 'before', 'after', 'submit' ) as $h ) { |
1099 | - if ( ! isset( $values[ $h .'_html' ] ) ) { |
|
1100 | - $values[ $h .'_html' ] = ( isset( $post_values['options'][ $h .'_html' ] ) ? $post_values['options'][ $h .'_html' ] : FrmFormsHelper::get_default_html( $h ) ); |
|
1101 | - } |
|
1102 | - unset($h); |
|
1103 | - } |
|
1104 | - } |
|
1099 | + if ( ! isset( $values[ $h .'_html' ] ) ) { |
|
1100 | + $values[ $h .'_html' ] = ( isset( $post_values['options'][ $h .'_html' ] ) ? $post_values['options'][ $h .'_html' ] : FrmFormsHelper::get_default_html( $h ) ); |
|
1101 | + } |
|
1102 | + unset($h); |
|
1103 | + } |
|
1104 | + } |
|
1105 | 1105 | |
1106 | 1106 | public static function get_meta_value( $field_id, $entry ) { |
1107 | 1107 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryMeta::get_meta_value' ); |
@@ -1109,69 +1109,69 @@ discard block |
||
1109 | 1109 | } |
1110 | 1110 | |
1111 | 1111 | public static function insert_opt_html( $args ) { |
1112 | - $class = ''; |
|
1113 | - if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) { |
|
1114 | - $class .= 'show_frm_not_email_to'; |
|
1115 | - } |
|
1116 | - ?> |
|
1112 | + $class = ''; |
|
1113 | + if ( in_array( $args['type'], array( 'email', 'user_id', 'hidden', 'select', 'radio', 'checkbox', 'phone', 'text' ) ) ) { |
|
1114 | + $class .= 'show_frm_not_email_to'; |
|
1115 | + } |
|
1116 | + ?> |
|
1117 | 1117 | <li> |
1118 | 1118 | <a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['id']) ?>" >[<?php echo esc_attr( $args['id'] ) ?>]</a> |
1119 | 1119 | <a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['key']) ?>" >[<?php echo esc_attr( self::truncate($args['key'], 10) ) ?>]</a> |
1120 | 1120 | <a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr($args['id']) ?>" ><?php echo esc_attr( self::truncate($args['name'], 60) ) ?></a> |
1121 | 1121 | </li> |
1122 | 1122 | <?php |
1123 | - } |
|
1123 | + } |
|
1124 | 1124 | |
1125 | - public static function get_us_states() { |
|
1126 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmFieldsHelper::get_us_states' ); |
|
1127 | - return FrmFieldsHelper::get_us_states(); |
|
1128 | - } |
|
1125 | + public static function get_us_states() { |
|
1126 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmFieldsHelper::get_us_states' ); |
|
1127 | + return FrmFieldsHelper::get_us_states(); |
|
1128 | + } |
|
1129 | 1129 | |
1130 | - public static function get_countries() { |
|
1131 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmFieldsHelper::get_countries' ); |
|
1132 | - return FrmFieldsHelper::get_countries(); |
|
1133 | - } |
|
1130 | + public static function get_countries() { |
|
1131 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmFieldsHelper::get_countries' ); |
|
1132 | + return FrmFieldsHelper::get_countries(); |
|
1133 | + } |
|
1134 | 1134 | |
1135 | 1135 | public static function truncate( $str, $length, $minword = 3, $continue = '...' ) { |
1136 | - if ( is_array( $str ) ) { |
|
1137 | - return; |
|
1136 | + if ( is_array( $str ) ) { |
|
1137 | + return; |
|
1138 | 1138 | } |
1139 | 1139 | |
1140 | - $length = (int) $length; |
|
1140 | + $length = (int) $length; |
|
1141 | 1141 | $str = wp_strip_all_tags( $str ); |
1142 | 1142 | $original_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $str ) ); |
1143 | 1143 | |
1144 | 1144 | if ( $length == 0 ) { |
1145 | - return ''; |
|
1146 | - } else if ( $length <= 10 ) { |
|
1145 | + return ''; |
|
1146 | + } else if ( $length <= 10 ) { |
|
1147 | 1147 | $sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) ); |
1148 | - return $sub . (($length < $original_len) ? $continue : ''); |
|
1149 | - } |
|
1148 | + return $sub . (($length < $original_len) ? $continue : ''); |
|
1149 | + } |
|
1150 | 1150 | |
1151 | - $sub = ''; |
|
1152 | - $len = 0; |
|
1151 | + $sub = ''; |
|
1152 | + $len = 0; |
|
1153 | 1153 | |
1154 | 1154 | $words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) ); |
1155 | 1155 | |
1156 | 1156 | foreach ( $words as $word ) { |
1157 | - $part = (($sub != '') ? ' ' : '') . $word; |
|
1157 | + $part = (($sub != '') ? ' ' : '') . $word; |
|
1158 | 1158 | $total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) ); |
1159 | - if ( $total_len > $length && str_word_count($sub) ) { |
|
1160 | - break; |
|
1161 | - } |
|
1159 | + if ( $total_len > $length && str_word_count($sub) ) { |
|
1160 | + break; |
|
1161 | + } |
|
1162 | 1162 | |
1163 | - $sub .= $part; |
|
1163 | + $sub .= $part; |
|
1164 | 1164 | $len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) ); |
1165 | 1165 | |
1166 | - if ( str_word_count($sub) > $minword && $total_len >= $length ) { |
|
1167 | - break; |
|
1168 | - } |
|
1166 | + if ( str_word_count($sub) > $minword && $total_len >= $length ) { |
|
1167 | + break; |
|
1168 | + } |
|
1169 | 1169 | |
1170 | - unset($total_len, $word); |
|
1171 | - } |
|
1170 | + unset($total_len, $word); |
|
1171 | + } |
|
1172 | 1172 | |
1173 | - return $sub . (($len < $original_len) ? $continue : ''); |
|
1174 | - } |
|
1173 | + return $sub . (($len < $original_len) ? $continue : ''); |
|
1174 | + } |
|
1175 | 1175 | |
1176 | 1176 | public static function mb_function( $function_names, $args ) { |
1177 | 1177 | $mb_function_name = $function_names[0]; |
@@ -1183,18 +1183,18 @@ discard block |
||
1183 | 1183 | } |
1184 | 1184 | |
1185 | 1185 | public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) { |
1186 | - if ( empty($date) ) { |
|
1187 | - return $date; |
|
1188 | - } |
|
1186 | + if ( empty($date) ) { |
|
1187 | + return $date; |
|
1188 | + } |
|
1189 | 1189 | |
1190 | - if ( empty($date_format) ) { |
|
1191 | - $date_format = get_option('date_format'); |
|
1192 | - } |
|
1190 | + if ( empty($date_format) ) { |
|
1191 | + $date_format = get_option('date_format'); |
|
1192 | + } |
|
1193 | 1193 | |
1194 | - if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) { |
|
1195 | - $frmpro_settings = new FrmProSettings(); |
|
1196 | - $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d'); |
|
1197 | - } |
|
1194 | + if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) { |
|
1195 | + $frmpro_settings = new FrmProSettings(); |
|
1196 | + $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d'); |
|
1197 | + } |
|
1198 | 1198 | |
1199 | 1199 | $formatted = self::get_localized_date( $date_format, $date ); |
1200 | 1200 | |
@@ -1203,8 +1203,8 @@ discard block |
||
1203 | 1203 | $formatted .= self::add_time_to_date( $time_format, $date ); |
1204 | 1204 | } |
1205 | 1205 | |
1206 | - return $formatted; |
|
1207 | - } |
|
1206 | + return $formatted; |
|
1207 | + } |
|
1208 | 1208 | |
1209 | 1209 | private static function add_time_to_date( $time_format, $date ) { |
1210 | 1210 | if ( empty( $time_format ) ) { |
@@ -1228,117 +1228,117 @@ discard block |
||
1228 | 1228 | return date_i18n( $date_format, strtotime( $date ) ); |
1229 | 1229 | } |
1230 | 1230 | |
1231 | - /** |
|
1232 | - * @return string The time ago in words |
|
1233 | - */ |
|
1234 | - public static function human_time_diff( $from, $to = '' ) { |
|
1235 | - if ( empty($to) ) { |
|
1236 | - $to = time(); |
|
1237 | - } |
|
1238 | - |
|
1239 | - // Array of time period chunks |
|
1240 | - $chunks = array( |
|
1241 | - array( 60 * 60 * 24 * 365, __( 'year', 'formidable' ), __( 'years', 'formidable' ) ), |
|
1242 | - array( 60 * 60 * 24 * 30, __( 'month', 'formidable' ), __( 'months', 'formidable' ) ), |
|
1243 | - array( 60 * 60 * 24 * 7, __( 'week', 'formidable' ), __( 'weeks', 'formidable' ) ), |
|
1244 | - array( 60 * 60 * 24, __( 'day', 'formidable' ), __( 'days', 'formidable' ) ), |
|
1245 | - array( 60 * 60, __( 'hour', 'formidable' ), __( 'hours', 'formidable' ) ), |
|
1246 | - array( 60, __( 'minute', 'formidable' ), __( 'minutes', 'formidable' ) ), |
|
1247 | - array( 1, __( 'second', 'formidable' ), __( 'seconds', 'formidable' ) ), |
|
1248 | - ); |
|
1249 | - |
|
1250 | - // Difference in seconds |
|
1251 | - $diff = (int) ($to - $from); |
|
1252 | - |
|
1253 | - // Something went wrong with date calculation and we ended up with a negative date. |
|
1231 | + /** |
|
1232 | + * @return string The time ago in words |
|
1233 | + */ |
|
1234 | + public static function human_time_diff( $from, $to = '' ) { |
|
1235 | + if ( empty($to) ) { |
|
1236 | + $to = time(); |
|
1237 | + } |
|
1238 | + |
|
1239 | + // Array of time period chunks |
|
1240 | + $chunks = array( |
|
1241 | + array( 60 * 60 * 24 * 365, __( 'year', 'formidable' ), __( 'years', 'formidable' ) ), |
|
1242 | + array( 60 * 60 * 24 * 30, __( 'month', 'formidable' ), __( 'months', 'formidable' ) ), |
|
1243 | + array( 60 * 60 * 24 * 7, __( 'week', 'formidable' ), __( 'weeks', 'formidable' ) ), |
|
1244 | + array( 60 * 60 * 24, __( 'day', 'formidable' ), __( 'days', 'formidable' ) ), |
|
1245 | + array( 60 * 60, __( 'hour', 'formidable' ), __( 'hours', 'formidable' ) ), |
|
1246 | + array( 60, __( 'minute', 'formidable' ), __( 'minutes', 'formidable' ) ), |
|
1247 | + array( 1, __( 'second', 'formidable' ), __( 'seconds', 'formidable' ) ), |
|
1248 | + ); |
|
1249 | + |
|
1250 | + // Difference in seconds |
|
1251 | + $diff = (int) ($to - $from); |
|
1252 | + |
|
1253 | + // Something went wrong with date calculation and we ended up with a negative date. |
|
1254 | 1254 | if ( $diff < 1 ) { |
1255 | 1255 | return '0 ' . __( 'seconds', 'formidable' ); |
1256 | - } |
|
1256 | + } |
|
1257 | 1257 | |
1258 | - /** |
|
1259 | - * We only want to output one chunks of time here, eg: |
|
1260 | - * x years |
|
1261 | - * xx months |
|
1262 | - * so there's only one bit of calculation below: |
|
1263 | - */ |
|
1258 | + /** |
|
1259 | + * We only want to output one chunks of time here, eg: |
|
1260 | + * x years |
|
1261 | + * xx months |
|
1262 | + * so there's only one bit of calculation below: |
|
1263 | + */ |
|
1264 | 1264 | |
1265 | - $count = 0; |
|
1265 | + $count = 0; |
|
1266 | 1266 | |
1267 | - //Step one: the first chunk |
|
1267 | + //Step one: the first chunk |
|
1268 | 1268 | for ( $i = 0, $j = count( $chunks ); $i < $j; $i++ ) { |
1269 | - $seconds = $chunks[ $i ][0]; |
|
1270 | - |
|
1271 | - // Finding the biggest chunk (if the chunk fits, break) |
|
1272 | - if ( ( $count = floor($diff / $seconds) ) != 0 ) { |
|
1273 | - break; |
|
1274 | - } |
|
1275 | - } |
|
1276 | - |
|
1277 | - // Set output var |
|
1278 | - $output = ( 1 == $count ) ? '1 '. $chunks[ $i ][1] : $count . ' ' . $chunks[ $i ][2]; |
|
1279 | - |
|
1280 | - if ( ! (int) trim( $output ) ) { |
|
1281 | - $output = '0 ' . __( 'seconds', 'formidable' ); |
|
1282 | - } |
|
1283 | - |
|
1284 | - return $output; |
|
1285 | - } |
|
1286 | - |
|
1287 | - /** |
|
1288 | - * Added for < WP 4.0 compatability |
|
1289 | - * |
|
1290 | - * @since 1.07.10 |
|
1291 | - * |
|
1292 | - * @param string $term The value to escape |
|
1293 | - * @return string The escaped value |
|
1294 | - */ |
|
1269 | + $seconds = $chunks[ $i ][0]; |
|
1270 | + |
|
1271 | + // Finding the biggest chunk (if the chunk fits, break) |
|
1272 | + if ( ( $count = floor($diff / $seconds) ) != 0 ) { |
|
1273 | + break; |
|
1274 | + } |
|
1275 | + } |
|
1276 | + |
|
1277 | + // Set output var |
|
1278 | + $output = ( 1 == $count ) ? '1 '. $chunks[ $i ][1] : $count . ' ' . $chunks[ $i ][2]; |
|
1279 | + |
|
1280 | + if ( ! (int) trim( $output ) ) { |
|
1281 | + $output = '0 ' . __( 'seconds', 'formidable' ); |
|
1282 | + } |
|
1283 | + |
|
1284 | + return $output; |
|
1285 | + } |
|
1286 | + |
|
1287 | + /** |
|
1288 | + * Added for < WP 4.0 compatability |
|
1289 | + * |
|
1290 | + * @since 1.07.10 |
|
1291 | + * |
|
1292 | + * @param string $term The value to escape |
|
1293 | + * @return string The escaped value |
|
1294 | + */ |
|
1295 | 1295 | public static function esc_like( $term ) { |
1296 | - global $wpdb; |
|
1297 | - if ( method_exists($wpdb, 'esc_like') ) { |
|
1296 | + global $wpdb; |
|
1297 | + if ( method_exists($wpdb, 'esc_like') ) { |
|
1298 | 1298 | // WP 4.0 |
1299 | - $term = $wpdb->esc_like( $term ); |
|
1300 | - } else { |
|
1301 | - $term = like_escape( $term ); |
|
1302 | - } |
|
1299 | + $term = $wpdb->esc_like( $term ); |
|
1300 | + } else { |
|
1301 | + $term = like_escape( $term ); |
|
1302 | + } |
|
1303 | 1303 | |
1304 | - return $term; |
|
1305 | - } |
|
1304 | + return $term; |
|
1305 | + } |
|
1306 | 1306 | |
1307 | - /** |
|
1308 | - * @param string $order_query |
|
1309 | - */ |
|
1307 | + /** |
|
1308 | + * @param string $order_query |
|
1309 | + */ |
|
1310 | 1310 | public static function esc_order( $order_query ) { |
1311 | - if ( empty($order_query) ) { |
|
1312 | - return ''; |
|
1313 | - } |
|
1314 | - |
|
1315 | - // remove ORDER BY before santizing |
|
1316 | - $order_query = strtolower($order_query); |
|
1317 | - if ( strpos($order_query, 'order by') !== false ) { |
|
1318 | - $order_query = str_replace('order by', '', $order_query); |
|
1319 | - } |
|
1320 | - |
|
1321 | - $order_query = explode(' ', trim($order_query)); |
|
1322 | - |
|
1323 | - $order_fields = array( |
|
1324 | - 'id', 'form_key', 'name', 'description', |
|
1325 | - 'parent_form_id', 'logged_in', 'is_template', |
|
1326 | - 'default_template', 'status', 'created_at', |
|
1327 | - ); |
|
1328 | - |
|
1329 | - $order = trim(trim(reset($order_query), ',')); |
|
1330 | - if ( ! in_array($order, $order_fields) ) { |
|
1331 | - return ''; |
|
1332 | - } |
|
1333 | - |
|
1334 | - $order_by = ''; |
|
1335 | - if ( count($order_query) > 1 ) { |
|
1311 | + if ( empty($order_query) ) { |
|
1312 | + return ''; |
|
1313 | + } |
|
1314 | + |
|
1315 | + // remove ORDER BY before santizing |
|
1316 | + $order_query = strtolower($order_query); |
|
1317 | + if ( strpos($order_query, 'order by') !== false ) { |
|
1318 | + $order_query = str_replace('order by', '', $order_query); |
|
1319 | + } |
|
1320 | + |
|
1321 | + $order_query = explode(' ', trim($order_query)); |
|
1322 | + |
|
1323 | + $order_fields = array( |
|
1324 | + 'id', 'form_key', 'name', 'description', |
|
1325 | + 'parent_form_id', 'logged_in', 'is_template', |
|
1326 | + 'default_template', 'status', 'created_at', |
|
1327 | + ); |
|
1328 | + |
|
1329 | + $order = trim(trim(reset($order_query), ',')); |
|
1330 | + if ( ! in_array($order, $order_fields) ) { |
|
1331 | + return ''; |
|
1332 | + } |
|
1333 | + |
|
1334 | + $order_by = ''; |
|
1335 | + if ( count($order_query) > 1 ) { |
|
1336 | 1336 | $order_by = end( $order_query ); |
1337 | 1337 | self::esc_order_by( $order_by ); |
1338 | - } |
|
1338 | + } |
|
1339 | 1339 | |
1340 | - return ' ORDER BY '. $order . ' '. $order_by; |
|
1341 | - } |
|
1340 | + return ' ORDER BY '. $order . ' '. $order_by; |
|
1341 | + } |
|
1342 | 1342 | |
1343 | 1343 | /** |
1344 | 1344 | * Make sure this is ordering by either ASC or DESC |
@@ -1350,183 +1350,183 @@ discard block |
||
1350 | 1350 | } |
1351 | 1351 | } |
1352 | 1352 | |
1353 | - /** |
|
1354 | - * @param string $limit |
|
1355 | - */ |
|
1353 | + /** |
|
1354 | + * @param string $limit |
|
1355 | + */ |
|
1356 | 1356 | public static function esc_limit( $limit ) { |
1357 | - if ( empty($limit) ) { |
|
1358 | - return ''; |
|
1359 | - } |
|
1360 | - |
|
1361 | - $limit = trim(str_replace(' limit', '', strtolower($limit))); |
|
1362 | - if ( is_numeric($limit) ) { |
|
1363 | - return ' LIMIT '. $limit; |
|
1364 | - } |
|
1365 | - |
|
1366 | - $limit = explode(',', trim($limit)); |
|
1367 | - foreach ( $limit as $k => $l ) { |
|
1368 | - if ( is_numeric( $l ) ) { |
|
1369 | - $limit[ $k ] = $l; |
|
1370 | - } |
|
1371 | - } |
|
1372 | - |
|
1373 | - $limit = implode(',', $limit); |
|
1374 | - return ' LIMIT '. $limit; |
|
1375 | - } |
|
1376 | - |
|
1377 | - /** |
|
1378 | - * Get an array of values ready to go through $wpdb->prepare |
|
1379 | - * @since 2.0 |
|
1380 | - */ |
|
1381 | - public static function prepare_array_values( $array, $type = '%s' ) { |
|
1382 | - $placeholders = array_fill(0, count($array), $type); |
|
1383 | - return implode(', ', $placeholders); |
|
1384 | - } |
|
1385 | - |
|
1386 | - public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) { |
|
1387 | - if ( empty($where) ) { |
|
1388 | - return ''; |
|
1389 | - } |
|
1357 | + if ( empty($limit) ) { |
|
1358 | + return ''; |
|
1359 | + } |
|
1360 | + |
|
1361 | + $limit = trim(str_replace(' limit', '', strtolower($limit))); |
|
1362 | + if ( is_numeric($limit) ) { |
|
1363 | + return ' LIMIT '. $limit; |
|
1364 | + } |
|
1365 | + |
|
1366 | + $limit = explode(',', trim($limit)); |
|
1367 | + foreach ( $limit as $k => $l ) { |
|
1368 | + if ( is_numeric( $l ) ) { |
|
1369 | + $limit[ $k ] = $l; |
|
1370 | + } |
|
1371 | + } |
|
1372 | + |
|
1373 | + $limit = implode(',', $limit); |
|
1374 | + return ' LIMIT '. $limit; |
|
1375 | + } |
|
1376 | + |
|
1377 | + /** |
|
1378 | + * Get an array of values ready to go through $wpdb->prepare |
|
1379 | + * @since 2.0 |
|
1380 | + */ |
|
1381 | + public static function prepare_array_values( $array, $type = '%s' ) { |
|
1382 | + $placeholders = array_fill(0, count($array), $type); |
|
1383 | + return implode(', ', $placeholders); |
|
1384 | + } |
|
1385 | + |
|
1386 | + public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) { |
|
1387 | + if ( empty($where) ) { |
|
1388 | + return ''; |
|
1389 | + } |
|
1390 | 1390 | |
1391 | 1391 | if ( is_array( $where ) ) { |
1392 | - global $wpdb; |
|
1393 | - FrmDb::get_where_clause_and_values( $where, $starts_with ); |
|
1392 | + global $wpdb; |
|
1393 | + FrmDb::get_where_clause_and_values( $where, $starts_with ); |
|
1394 | 1394 | $where = $wpdb->prepare( $where['where'], $where['values'] ); |
1395 | 1395 | } else { |
1396 | - $where = $starts_with . $where; |
|
1397 | - } |
|
1396 | + $where = $starts_with . $where; |
|
1397 | + } |
|
1398 | 1398 | |
1399 | - return $where; |
|
1400 | - } |
|
1399 | + return $where; |
|
1400 | + } |
|
1401 | 1401 | |
1402 | - // Pagination Methods |
|
1402 | + // Pagination Methods |
|
1403 | 1403 | |
1404 | - /** |
|
1405 | - * @param integer $current_p |
|
1406 | - */ |
|
1404 | + /** |
|
1405 | + * @param integer $current_p |
|
1406 | + */ |
|
1407 | 1407 | public static function get_last_record_num( $r_count, $current_p, $p_size ) { |
1408 | 1408 | return ( ( $r_count < ( $current_p * $p_size ) ) ? $r_count : ( $current_p * $p_size ) ); |
1409 | 1409 | } |
1410 | 1410 | |
1411 | - /** |
|
1412 | - * @param integer $current_p |
|
1413 | - */ |
|
1414 | - public static function get_first_record_num( $r_count, $current_p, $p_size ) { |
|
1415 | - if ( $current_p == 1 ) { |
|
1416 | - return 1; |
|
1417 | - } else { |
|
1418 | - return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 ); |
|
1419 | - } |
|
1420 | - } |
|
1421 | - |
|
1422 | - /** |
|
1423 | - * @param string $table_name |
|
1424 | - */ |
|
1425 | - public static function &getRecordCount( $where = '', $table_name ) { |
|
1426 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_count' ); |
|
1427 | - $count = FrmDb::get_count( $table_name, $where ); |
|
1428 | - return $count; |
|
1429 | - } |
|
1430 | - |
|
1431 | - public static function get_referer_info() { |
|
1432 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::get_server_value' ); |
|
1433 | - return self::get_server_value('HTTP_REFERER'); |
|
1434 | - } |
|
1411 | + /** |
|
1412 | + * @param integer $current_p |
|
1413 | + */ |
|
1414 | + public static function get_first_record_num( $r_count, $current_p, $p_size ) { |
|
1415 | + if ( $current_p == 1 ) { |
|
1416 | + return 1; |
|
1417 | + } else { |
|
1418 | + return ( self::get_last_record_num( $r_count, ( $current_p - 1 ), $p_size ) + 1 ); |
|
1419 | + } |
|
1420 | + } |
|
1421 | + |
|
1422 | + /** |
|
1423 | + * @param string $table_name |
|
1424 | + */ |
|
1425 | + public static function &getRecordCount( $where = '', $table_name ) { |
|
1426 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmDb::get_count' ); |
|
1427 | + $count = FrmDb::get_count( $table_name, $where ); |
|
1428 | + return $count; |
|
1429 | + } |
|
1430 | + |
|
1431 | + public static function get_referer_info() { |
|
1432 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::get_server_value' ); |
|
1433 | + return self::get_server_value('HTTP_REFERER'); |
|
1434 | + } |
|
1435 | 1435 | |
1436 | 1436 | /** |
1437 | 1437 | * @return array |
1438 | 1438 | */ |
1439 | 1439 | public static function json_to_array( $json_vars ) { |
1440 | - $vars = array(); |
|
1441 | - foreach ( $json_vars as $jv ) { |
|
1442 | - $jv_name = explode('[', $jv['name']); |
|
1443 | - $last = count($jv_name) - 1; |
|
1444 | - foreach ( $jv_name as $p => $n ) { |
|
1445 | - $name = trim($n, ']'); |
|
1446 | - if ( ! isset($l1) ) { |
|
1447 | - $l1 = $name; |
|
1448 | - } |
|
1449 | - |
|
1450 | - if ( ! isset($l2) ) { |
|
1451 | - $l2 = $name; |
|
1452 | - } |
|
1453 | - |
|
1454 | - if ( ! isset($l3) ) { |
|
1455 | - $l3 = $name; |
|
1456 | - } |
|
1457 | - |
|
1458 | - $this_val = ( $p == $last ) ? $jv['value'] : array(); |
|
1459 | - |
|
1460 | - switch ( $p ) { |
|
1461 | - case 0: |
|
1462 | - $l1 = $name; |
|
1463 | - self::add_value_to_array( $name, $l1, $this_val, $vars ); |
|
1464 | - break; |
|
1465 | - |
|
1466 | - case 1: |
|
1467 | - $l2 = $name; |
|
1468 | - self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] ); |
|
1469 | - break; |
|
1470 | - |
|
1471 | - case 2: |
|
1472 | - $l3 = $name; |
|
1473 | - self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] ); |
|
1474 | - break; |
|
1475 | - |
|
1476 | - case 3: |
|
1477 | - $l4 = $name; |
|
1478 | - self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] ); |
|
1479 | - break; |
|
1480 | - } |
|
1481 | - |
|
1482 | - unset($this_val, $n); |
|
1483 | - } |
|
1484 | - |
|
1485 | - unset($last, $jv); |
|
1486 | - } |
|
1487 | - |
|
1488 | - return $vars; |
|
1489 | - } |
|
1490 | - |
|
1491 | - /** |
|
1492 | - * @param string $name |
|
1493 | - * @param string $l1 |
|
1494 | - */ |
|
1495 | - public static function add_value_to_array( $name, $l1, $val, &$vars ) { |
|
1496 | - if ( $name == '' ) { |
|
1497 | - $vars[] = $val; |
|
1498 | - } else if ( ! isset( $vars[ $l1 ] ) ) { |
|
1499 | - $vars[ $l1 ] = $val; |
|
1500 | - } |
|
1501 | - } |
|
1440 | + $vars = array(); |
|
1441 | + foreach ( $json_vars as $jv ) { |
|
1442 | + $jv_name = explode('[', $jv['name']); |
|
1443 | + $last = count($jv_name) - 1; |
|
1444 | + foreach ( $jv_name as $p => $n ) { |
|
1445 | + $name = trim($n, ']'); |
|
1446 | + if ( ! isset($l1) ) { |
|
1447 | + $l1 = $name; |
|
1448 | + } |
|
1449 | + |
|
1450 | + if ( ! isset($l2) ) { |
|
1451 | + $l2 = $name; |
|
1452 | + } |
|
1453 | + |
|
1454 | + if ( ! isset($l3) ) { |
|
1455 | + $l3 = $name; |
|
1456 | + } |
|
1457 | + |
|
1458 | + $this_val = ( $p == $last ) ? $jv['value'] : array(); |
|
1459 | + |
|
1460 | + switch ( $p ) { |
|
1461 | + case 0: |
|
1462 | + $l1 = $name; |
|
1463 | + self::add_value_to_array( $name, $l1, $this_val, $vars ); |
|
1464 | + break; |
|
1465 | + |
|
1466 | + case 1: |
|
1467 | + $l2 = $name; |
|
1468 | + self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] ); |
|
1469 | + break; |
|
1470 | + |
|
1471 | + case 2: |
|
1472 | + $l3 = $name; |
|
1473 | + self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] ); |
|
1474 | + break; |
|
1475 | + |
|
1476 | + case 3: |
|
1477 | + $l4 = $name; |
|
1478 | + self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] ); |
|
1479 | + break; |
|
1480 | + } |
|
1481 | + |
|
1482 | + unset($this_val, $n); |
|
1483 | + } |
|
1484 | + |
|
1485 | + unset($last, $jv); |
|
1486 | + } |
|
1487 | + |
|
1488 | + return $vars; |
|
1489 | + } |
|
1490 | + |
|
1491 | + /** |
|
1492 | + * @param string $name |
|
1493 | + * @param string $l1 |
|
1494 | + */ |
|
1495 | + public static function add_value_to_array( $name, $l1, $val, &$vars ) { |
|
1496 | + if ( $name == '' ) { |
|
1497 | + $vars[] = $val; |
|
1498 | + } else if ( ! isset( $vars[ $l1 ] ) ) { |
|
1499 | + $vars[ $l1 ] = $val; |
|
1500 | + } |
|
1501 | + } |
|
1502 | 1502 | |
1503 | 1503 | public static function maybe_add_tooltip( $name, $class = 'closed', $form_name = '' ) { |
1504 | - $tooltips = array( |
|
1505 | - 'action_title' => __( 'Give this action a label for easy reference.', 'formidable' ), |
|
1506 | - 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected]. [admin_email] is the address set in WP General Settings.', 'formidable' ), |
|
1507 | - 'cc' => __( 'Add CC addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
1508 | - 'bcc' => __( 'Add BCC addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
1509 | - 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
1510 | - 'from' => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ), |
|
1511 | - 'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ), |
|
1512 | - ); |
|
1513 | - |
|
1514 | - if ( ! isset( $tooltips[ $name ] ) ) { |
|
1515 | - return; |
|
1516 | - } |
|
1517 | - |
|
1518 | - if ( 'open' == $class ) { |
|
1519 | - echo ' frm_help"'; |
|
1520 | - } else { |
|
1521 | - echo ' class="frm_help"'; |
|
1522 | - } |
|
1523 | - |
|
1524 | - echo ' title="'. esc_attr( $tooltips[ $name ] ); |
|
1525 | - |
|
1526 | - if ( 'open' != $class ) { |
|
1527 | - echo '"'; |
|
1528 | - } |
|
1529 | - } |
|
1504 | + $tooltips = array( |
|
1505 | + 'action_title' => __( 'Give this action a label for easy reference.', 'formidable' ), |
|
1506 | + 'email_to' => __( 'Add one or more recipient addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected]. [admin_email] is the address set in WP General Settings.', 'formidable' ), |
|
1507 | + 'cc' => __( 'Add CC addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
1508 | + 'bcc' => __( 'Add BCC addresses separated by a ",". FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
1509 | + 'reply_to' => __( 'If you would like a different reply to address than the "from" address, add a single address here. FORMAT: Name <[email protected]> or [email protected].', 'formidable' ), |
|
1510 | + 'from' => __( 'Enter the name and/or email address of the sender. FORMAT: John Bates <[email protected]> or [email protected].', 'formidable' ), |
|
1511 | + 'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ), |
|
1512 | + ); |
|
1513 | + |
|
1514 | + if ( ! isset( $tooltips[ $name ] ) ) { |
|
1515 | + return; |
|
1516 | + } |
|
1517 | + |
|
1518 | + if ( 'open' == $class ) { |
|
1519 | + echo ' frm_help"'; |
|
1520 | + } else { |
|
1521 | + echo ' class="frm_help"'; |
|
1522 | + } |
|
1523 | + |
|
1524 | + echo ' title="'. esc_attr( $tooltips[ $name ] ); |
|
1525 | + |
|
1526 | + if ( 'open' != $class ) { |
|
1527 | + echo '"'; |
|
1528 | + } |
|
1529 | + } |
|
1530 | 1530 | |
1531 | 1531 | /** |
1532 | 1532 | * Add the current_page class to that page in the form nav |
@@ -1542,32 +1542,32 @@ discard block |
||
1542 | 1542 | } |
1543 | 1543 | } |
1544 | 1544 | |
1545 | - /** |
|
1546 | - * Prepare and json_encode post content |
|
1547 | - * |
|
1548 | - * @since 2.0 |
|
1549 | - * |
|
1550 | - * @param array $post_content |
|
1551 | - * @return string $post_content ( json encoded array ) |
|
1552 | - */ |
|
1553 | - public static function prepare_and_encode( $post_content ) { |
|
1554 | - //Loop through array to strip slashes and add only the needed ones |
|
1545 | + /** |
|
1546 | + * Prepare and json_encode post content |
|
1547 | + * |
|
1548 | + * @since 2.0 |
|
1549 | + * |
|
1550 | + * @param array $post_content |
|
1551 | + * @return string $post_content ( json encoded array ) |
|
1552 | + */ |
|
1553 | + public static function prepare_and_encode( $post_content ) { |
|
1554 | + //Loop through array to strip slashes and add only the needed ones |
|
1555 | 1555 | foreach ( $post_content as $key => $val ) { |
1556 | 1556 | self::prepare_action_slashes( $val, $key, $post_content ); |
1557 | - unset( $key, $val ); |
|
1558 | - } |
|
1557 | + unset( $key, $val ); |
|
1558 | + } |
|
1559 | 1559 | |
1560 | - // json_encode the array |
|
1561 | - $post_content = json_encode( $post_content ); |
|
1560 | + // json_encode the array |
|
1561 | + $post_content = json_encode( $post_content ); |
|
1562 | 1562 | |
1563 | - // add extra slashes for \r\n since WP strips them |
|
1563 | + // add extra slashes for \r\n since WP strips them |
|
1564 | 1564 | $post_content = str_replace( array( '\\r', '\\n', '\\u', '\\t' ), array( '\\\\r', '\\\\n', '\\\\u', '\\\\t' ), $post_content ); |
1565 | 1565 | |
1566 | - // allow for " |
|
1567 | - $post_content = str_replace( '"', '\\"', $post_content ); |
|
1566 | + // allow for " |
|
1567 | + $post_content = str_replace( '"', '\\"', $post_content ); |
|
1568 | 1568 | |
1569 | - return $post_content; |
|
1570 | - } |
|
1569 | + return $post_content; |
|
1570 | + } |
|
1571 | 1571 | |
1572 | 1572 | private static function prepare_action_slashes( $val, $key, &$post_content ) { |
1573 | 1573 | if ( ! isset( $post_content[ $key ] ) ) { |
@@ -1635,64 +1635,64 @@ discard block |
||
1635 | 1635 | } |
1636 | 1636 | |
1637 | 1637 | public static function maybe_json_decode( $string ) { |
1638 | - if ( is_array($string) ) { |
|
1639 | - return $string; |
|
1640 | - } |
|
1638 | + if ( is_array($string) ) { |
|
1639 | + return $string; |
|
1640 | + } |
|
1641 | 1641 | |
1642 | - $new_string = json_decode($string, true); |
|
1643 | - if ( function_exists('json_last_error') ) { |
|
1642 | + $new_string = json_decode($string, true); |
|
1643 | + if ( function_exists('json_last_error') ) { |
|
1644 | 1644 | // php 5.3+ |
1645 | - if ( json_last_error() == JSON_ERROR_NONE ) { |
|
1646 | - $string = $new_string; |
|
1647 | - } |
|
1648 | - } else if ( isset($new_string) ) { |
|
1645 | + if ( json_last_error() == JSON_ERROR_NONE ) { |
|
1646 | + $string = $new_string; |
|
1647 | + } |
|
1648 | + } else if ( isset($new_string) ) { |
|
1649 | 1649 | // php < 5.3 fallback |
1650 | - $string = $new_string; |
|
1651 | - } |
|
1652 | - return $string; |
|
1653 | - } |
|
1654 | - |
|
1655 | - /** |
|
1656 | - * @since 1.07.10 |
|
1657 | - * |
|
1658 | - * @param string $post_type The name of the post type that may need to be highlighted |
|
1659 | - * @return echo The javascript to open and highlight the Formidable menu |
|
1660 | - */ |
|
1650 | + $string = $new_string; |
|
1651 | + } |
|
1652 | + return $string; |
|
1653 | + } |
|
1654 | + |
|
1655 | + /** |
|
1656 | + * @since 1.07.10 |
|
1657 | + * |
|
1658 | + * @param string $post_type The name of the post type that may need to be highlighted |
|
1659 | + * @return echo The javascript to open and highlight the Formidable menu |
|
1660 | + */ |
|
1661 | 1661 | public static function maybe_highlight_menu( $post_type ) { |
1662 | - global $post, $pagenow; |
|
1662 | + global $post, $pagenow; |
|
1663 | 1663 | |
1664 | - if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) { |
|
1665 | - return; |
|
1666 | - } |
|
1664 | + if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) { |
|
1665 | + return; |
|
1666 | + } |
|
1667 | 1667 | |
1668 | - if ( is_object($post) && $post->post_type != $post_type ) { |
|
1669 | - return; |
|
1670 | - } |
|
1668 | + if ( is_object($post) && $post->post_type != $post_type ) { |
|
1669 | + return; |
|
1670 | + } |
|
1671 | 1671 | |
1672 | - self::load_admin_wide_js(); |
|
1673 | - echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>'; |
|
1674 | - } |
|
1672 | + self::load_admin_wide_js(); |
|
1673 | + echo '<script type="text/javascript">jQuery(document).ready(function(){frmSelectSubnav();});</script>'; |
|
1674 | + } |
|
1675 | 1675 | |
1676 | - /** |
|
1677 | - * Load the JS file on non-Formidable pages in the admin area |
|
1678 | - * @since 2.0 |
|
1679 | - */ |
|
1676 | + /** |
|
1677 | + * Load the JS file on non-Formidable pages in the admin area |
|
1678 | + * @since 2.0 |
|
1679 | + */ |
|
1680 | 1680 | public static function load_admin_wide_js( $load = true ) { |
1681 | - $version = FrmAppHelper::plugin_version(); |
|
1681 | + $version = FrmAppHelper::plugin_version(); |
|
1682 | 1682 | wp_register_script( 'formidable_admin_global', FrmAppHelper::plugin_url() . '/js/formidable_admin_global.js', array( 'jquery' ), $version ); |
1683 | 1683 | |
1684 | - wp_localize_script( 'formidable_admin_global', 'frmGlobal', array( |
|
1684 | + wp_localize_script( 'formidable_admin_global', 'frmGlobal', array( |
|
1685 | 1685 | 'updating_msg' => __( 'Please wait while your site updates.', 'formidable' ), |
1686 | - 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ), |
|
1686 | + 'deauthorize' => __( 'Are you sure you want to deauthorize Formidable Forms on this site?', 'formidable' ), |
|
1687 | 1687 | 'url' => FrmAppHelper::plugin_url(), |
1688 | 1688 | 'loading' => __( 'Loading…' ), |
1689 | 1689 | 'nonce' => wp_create_nonce( 'frm_ajax' ), |
1690 | - ) ); |
|
1690 | + ) ); |
|
1691 | 1691 | |
1692 | 1692 | if ( $load ) { |
1693 | 1693 | wp_enqueue_script( 'formidable_admin_global' ); |
1694 | 1694 | } |
1695 | - } |
|
1695 | + } |
|
1696 | 1696 | |
1697 | 1697 | /** |
1698 | 1698 | * @since 2.0.9 |
@@ -1701,9 +1701,9 @@ discard block |
||
1701 | 1701 | wp_enqueue_style( 'frm_fonts', self::plugin_url() . '/css/frm_fonts.css', array(), self::plugin_version() ); |
1702 | 1702 | } |
1703 | 1703 | |
1704 | - /** |
|
1705 | - * @param string $location |
|
1706 | - */ |
|
1704 | + /** |
|
1705 | + * @param string $location |
|
1706 | + */ |
|
1707 | 1707 | public static function localize_script( $location ) { |
1708 | 1708 | $ajax_url = admin_url( 'admin-ajax.php', is_ssl() ? 'admin' : 'http' ); |
1709 | 1709 | $ajax_url = apply_filters( 'frm_ajax_url', $ajax_url ); |
@@ -1753,81 +1753,81 @@ discard block |
||
1753 | 1753 | } |
1754 | 1754 | } |
1755 | 1755 | |
1756 | - /** |
|
1757 | - * @since 1.07.10 |
|
1758 | - * |
|
1759 | - * @param float $min_version The version the add-on requires |
|
1760 | - * @return echo The message on the plugins listing page |
|
1761 | - */ |
|
1756 | + /** |
|
1757 | + * @since 1.07.10 |
|
1758 | + * |
|
1759 | + * @param float $min_version The version the add-on requires |
|
1760 | + * @return echo The message on the plugins listing page |
|
1761 | + */ |
|
1762 | 1762 | public static function min_version_notice( $min_version ) { |
1763 | - $frm_version = self::plugin_version(); |
|
1763 | + $frm_version = self::plugin_version(); |
|
1764 | 1764 | |
1765 | - // check if Formidable meets minimum requirements |
|
1766 | - if ( version_compare($frm_version, $min_version, '>=') ) { |
|
1767 | - return; |
|
1768 | - } |
|
1765 | + // check if Formidable meets minimum requirements |
|
1766 | + if ( version_compare($frm_version, $min_version, '>=') ) { |
|
1767 | + return; |
|
1768 | + } |
|
1769 | 1769 | |
1770 | - $wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
|
1770 | + $wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
|
1771 | 1771 | echo '<tr class="plugin-update-tr active"><th colspan="' . absint( $wp_list_table->get_column_count() ) . '" class="check-column plugin-update colspanchange"><div class="update-message">' . |
1772 | - __( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) . |
|
1773 | - '</div></td></tr>'; |
|
1774 | - } |
|
1775 | - |
|
1776 | - public static function locales( $type = 'date' ) { |
|
1777 | - $locales = array( |
|
1778 | - 'en' => __( 'English', 'formidable' ), '' => __( 'English/Western', 'formidable' ), |
|
1779 | - 'af' => __( 'Afrikaans', 'formidable' ), 'sq' => __( 'Albanian', 'formidable' ), |
|
1780 | - 'ar' => __( 'Arabic', 'formidable' ), 'hy' => __( 'Armenian', 'formidable' ), |
|
1781 | - 'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ), |
|
1782 | - 'bs' => __( 'Bosnian', 'formidable' ), 'bg' => __( 'Bulgarian', 'formidable' ), |
|
1783 | - 'ca' => __( 'Catalan', 'formidable' ), 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ), |
|
1784 | - 'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ), |
|
1785 | - 'hr' => __( 'Croatian', 'formidable' ), 'cs' => __( 'Czech', 'formidable' ), |
|
1786 | - 'da' => __( 'Danish', 'formidable' ), 'nl' => __( 'Dutch', 'formidable' ), |
|
1787 | - 'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ), |
|
1788 | - 'et' => __( 'Estonian', 'formidable' ), 'fo' => __( 'Faroese', 'formidable' ), |
|
1789 | - 'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ), |
|
1790 | - 'fi' => __( 'Finnish', 'formidable' ), 'fr' => __( 'French', 'formidable' ), |
|
1791 | - 'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ), |
|
1792 | - 'de' => __( 'German', 'formidable' ), 'de-AT' => __( 'German/Austria', 'formidable' ), |
|
1793 | - 'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ), |
|
1794 | - 'he' => __( 'Hebrew', 'formidable' ), 'iw' => __( 'Hebrew', 'formidable' ), |
|
1795 | - 'hi' => __( 'Hindi', 'formidable' ), 'hu' => __( 'Hungarian', 'formidable' ), |
|
1796 | - 'is' => __( 'Icelandic', 'formidable' ), 'id' => __( 'Indonesian', 'formidable' ), |
|
1797 | - 'it' => __( 'Italian', 'formidable' ), 'ja' => __( 'Japanese', 'formidable' ), |
|
1798 | - 'ko' => __( 'Korean', 'formidable' ), 'lv' => __( 'Latvian', 'formidable' ), |
|
1799 | - 'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ), |
|
1800 | - 'no' => __( 'Norwegian', 'formidable' ), 'pl' => __( 'Polish', 'formidable' ), |
|
1801 | - 'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ), |
|
1802 | - 'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ), |
|
1803 | - 'ru' => __( 'Russian', 'formidable' ), 'sr' => __( 'Serbian', 'formidable' ), |
|
1804 | - 'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ), |
|
1805 | - 'sl' => __( 'Slovenian', 'formidable' ), 'es' => __( 'Spanish', 'formidable' ), |
|
1806 | - 'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ), |
|
1807 | - 'ta' => __( 'Tamil', 'formidable' ), 'th' => __( 'Thai', 'formidable' ), |
|
1808 | - 'tu' => __( 'Turkish', 'formidable' ), 'tr' => __( 'Turkish', 'formidable' ), |
|
1809 | - 'uk' => __( 'Ukranian', 'formidable' ), 'vi' => __( 'Vietnamese', 'formidable' ), |
|
1810 | - ); |
|
1811 | - |
|
1812 | - if ( $type == 'captcha' ) { |
|
1813 | - // remove the languages unavailable for the captcha |
|
1814 | - $unset = array( |
|
1815 | - '', 'af', 'sq', 'hy', 'az', 'eu', 'bs', |
|
1816 | - 'zh-HK', 'eo', 'et', 'fo', 'fr-CH', |
|
1817 | - 'he', 'is', 'ms', 'sr-SR', 'ta', 'tu', |
|
1818 | - ); |
|
1819 | - } else { |
|
1820 | - // remove the languages unavailable for the datepicker |
|
1821 | - $unset = array( |
|
1822 | - 'en', 'fil', 'fr-CA', 'de-AT', 'de-AT', |
|
1823 | - 'de-CH', 'iw', 'hi', 'pt', 'pt-PT', |
|
1824 | - 'es-419', 'tr', |
|
1825 | - ); |
|
1826 | - } |
|
1827 | - |
|
1828 | - $locales = array_diff_key($locales, array_flip($unset)); |
|
1829 | - $locales = apply_filters('frm_locales', $locales); |
|
1830 | - |
|
1831 | - return $locales; |
|
1832 | - } |
|
1772 | + __( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) . |
|
1773 | + '</div></td></tr>'; |
|
1774 | + } |
|
1775 | + |
|
1776 | + public static function locales( $type = 'date' ) { |
|
1777 | + $locales = array( |
|
1778 | + 'en' => __( 'English', 'formidable' ), '' => __( 'English/Western', 'formidable' ), |
|
1779 | + 'af' => __( 'Afrikaans', 'formidable' ), 'sq' => __( 'Albanian', 'formidable' ), |
|
1780 | + 'ar' => __( 'Arabic', 'formidable' ), 'hy' => __( 'Armenian', 'formidable' ), |
|
1781 | + 'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ), |
|
1782 | + 'bs' => __( 'Bosnian', 'formidable' ), 'bg' => __( 'Bulgarian', 'formidable' ), |
|
1783 | + 'ca' => __( 'Catalan', 'formidable' ), 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ), |
|
1784 | + 'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ), |
|
1785 | + 'hr' => __( 'Croatian', 'formidable' ), 'cs' => __( 'Czech', 'formidable' ), |
|
1786 | + 'da' => __( 'Danish', 'formidable' ), 'nl' => __( 'Dutch', 'formidable' ), |
|
1787 | + 'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ), |
|
1788 | + 'et' => __( 'Estonian', 'formidable' ), 'fo' => __( 'Faroese', 'formidable' ), |
|
1789 | + 'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ), |
|
1790 | + 'fi' => __( 'Finnish', 'formidable' ), 'fr' => __( 'French', 'formidable' ), |
|
1791 | + 'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ), |
|
1792 | + 'de' => __( 'German', 'formidable' ), 'de-AT' => __( 'German/Austria', 'formidable' ), |
|
1793 | + 'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ), |
|
1794 | + 'he' => __( 'Hebrew', 'formidable' ), 'iw' => __( 'Hebrew', 'formidable' ), |
|
1795 | + 'hi' => __( 'Hindi', 'formidable' ), 'hu' => __( 'Hungarian', 'formidable' ), |
|
1796 | + 'is' => __( 'Icelandic', 'formidable' ), 'id' => __( 'Indonesian', 'formidable' ), |
|
1797 | + 'it' => __( 'Italian', 'formidable' ), 'ja' => __( 'Japanese', 'formidable' ), |
|
1798 | + 'ko' => __( 'Korean', 'formidable' ), 'lv' => __( 'Latvian', 'formidable' ), |
|
1799 | + 'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ), |
|
1800 | + 'no' => __( 'Norwegian', 'formidable' ), 'pl' => __( 'Polish', 'formidable' ), |
|
1801 | + 'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ), |
|
1802 | + 'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ), |
|
1803 | + 'ru' => __( 'Russian', 'formidable' ), 'sr' => __( 'Serbian', 'formidable' ), |
|
1804 | + 'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ), |
|
1805 | + 'sl' => __( 'Slovenian', 'formidable' ), 'es' => __( 'Spanish', 'formidable' ), |
|
1806 | + 'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ), |
|
1807 | + 'ta' => __( 'Tamil', 'formidable' ), 'th' => __( 'Thai', 'formidable' ), |
|
1808 | + 'tu' => __( 'Turkish', 'formidable' ), 'tr' => __( 'Turkish', 'formidable' ), |
|
1809 | + 'uk' => __( 'Ukranian', 'formidable' ), 'vi' => __( 'Vietnamese', 'formidable' ), |
|
1810 | + ); |
|
1811 | + |
|
1812 | + if ( $type == 'captcha' ) { |
|
1813 | + // remove the languages unavailable for the captcha |
|
1814 | + $unset = array( |
|
1815 | + '', 'af', 'sq', 'hy', 'az', 'eu', 'bs', |
|
1816 | + 'zh-HK', 'eo', 'et', 'fo', 'fr-CH', |
|
1817 | + 'he', 'is', 'ms', 'sr-SR', 'ta', 'tu', |
|
1818 | + ); |
|
1819 | + } else { |
|
1820 | + // remove the languages unavailable for the datepicker |
|
1821 | + $unset = array( |
|
1822 | + 'en', 'fil', 'fr-CA', 'de-AT', 'de-AT', |
|
1823 | + 'de-CH', 'iw', 'hi', 'pt', 'pt-PT', |
|
1824 | + 'es-419', 'tr', |
|
1825 | + ); |
|
1826 | + } |
|
1827 | + |
|
1828 | + $locales = array_diff_key($locales, array_flip($unset)); |
|
1829 | + $locales = apply_filters('frm_locales', $locales); |
|
1830 | + |
|
1831 | + return $locales; |
|
1832 | + } |
|
1833 | 1833 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | 3 | die( 'You are not allowed to call this page directly.' ); |
4 | 4 | } |
5 | 5 | |
@@ -23,16 +23,16 @@ discard block |
||
23 | 23 | } |
24 | 24 | |
25 | 25 | public static function plugin_folder() { |
26 | - return basename(self::plugin_path()); |
|
26 | + return basename( self::plugin_path() ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | public static function plugin_path() { |
30 | - return dirname(dirname(dirname(__FILE__))); |
|
30 | + return dirname( dirname( dirname( __FILE__ ) ) ); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | public static function plugin_url() { |
34 | 34 | //prevously FRM_URL constant |
35 | - return plugins_url( '', self::plugin_path() .'/formidable.php' ); |
|
35 | + return plugins_url( '', self::plugin_path() . '/formidable.php' ); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | public static function relative_plugin_url() { |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @return string |
55 | 55 | */ |
56 | 56 | public static function site_name() { |
57 | - return get_option('blogname'); |
|
57 | + return get_option( 'blogname' ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public static function get_settings() { |
69 | 69 | global $frm_settings; |
70 | - if ( empty($frm_settings) ) { |
|
70 | + if ( empty( $frm_settings ) ) { |
|
71 | 71 | $frm_settings = new FrmSettings(); |
72 | 72 | } |
73 | 73 | return $frm_settings; |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | public static function update_message( $features, $class = '' ) { |
82 | 82 | return; // hide the upgrade messages for now |
83 | 83 | if ( ! self::pro_is_installed() ) { |
84 | - include(self::plugin_path() .'/classes/views/shared/update_message.php'); |
|
84 | + include( self::plugin_path() . '/classes/views/shared/update_message.php' ); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | 88 | public static function pro_is_installed() { |
89 | - return apply_filters('frm_pro_installed', false); |
|
89 | + return apply_filters( 'frm_pro_installed', false ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | * @return boolean |
131 | 131 | */ |
132 | 132 | public static function doing_ajax() { |
133 | - return defined('DOING_AJAX') && DOING_AJAX && ! self::is_preview_page(); |
|
133 | + return defined( 'DOING_AJAX' ) && DOING_AJAX && ! self::is_preview_page(); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @return boolean |
151 | 151 | */ |
152 | 152 | public static function is_admin() { |
153 | - return is_admin() && ( ! defined('DOING_AJAX') || ! DOING_AJAX ); |
|
153 | + return is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @return string |
177 | 177 | */ |
178 | 178 | public static function get_server_value( $value ) { |
179 | - return isset( $_SERVER[ $value ] ) ? wp_strip_all_tags( $_SERVER[ $value ] ) : ''; |
|
179 | + return isset( $_SERVER[$value] ) ? wp_strip_all_tags( $_SERVER[$value] ) : ''; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -191,14 +191,14 @@ discard block |
||
191 | 191 | 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', |
192 | 192 | 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR', |
193 | 193 | ) as $key ) { |
194 | - if ( ! isset( $_SERVER[ $key ] ) ) { |
|
194 | + if ( ! isset( $_SERVER[$key] ) ) { |
|
195 | 195 | continue; |
196 | 196 | } |
197 | 197 | |
198 | - foreach ( explode( ',', $_SERVER[ $key ] ) as $ip ) { |
|
199 | - $ip = trim($ip); // just to be safe |
|
198 | + foreach ( explode( ',', $_SERVER[$key] ) as $ip ) { |
|
199 | + $ip = trim( $ip ); // just to be safe |
|
200 | 200 | |
201 | - if ( filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false ) { |
|
201 | + if ( filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) !== false ) { |
|
202 | 202 | return $ip; |
203 | 203 | } |
204 | 204 | } |
@@ -208,15 +208,15 @@ discard block |
||
208 | 208 | } |
209 | 209 | |
210 | 210 | public static function get_param( $param, $default = '', $src = 'get', $sanitize = '' ) { |
211 | - if ( strpos($param, '[') ) { |
|
212 | - $params = explode('[', $param); |
|
211 | + if ( strpos( $param, '[' ) ) { |
|
212 | + $params = explode( '[', $param ); |
|
213 | 213 | $param = $params[0]; |
214 | 214 | } |
215 | 215 | |
216 | 216 | if ( $src == 'get' ) { |
217 | - $value = isset( $_POST[ $param ] ) ? stripslashes_deep( $_POST[ $param ] ) : ( isset( $_GET[ $param ] ) ? stripslashes_deep( $_GET[ $param ] ) : $default ); |
|
218 | - if ( ! isset( $_POST[ $param ] ) && isset( $_GET[ $param ] ) && ! is_array( $value ) ) { |
|
219 | - $value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[ $param ] ) ) ); |
|
217 | + $value = isset( $_POST[$param] ) ? stripslashes_deep( $_POST[$param] ) : ( isset( $_GET[$param] ) ? stripslashes_deep( $_GET[$param] ) : $default ); |
|
218 | + if ( ! isset( $_POST[$param] ) && isset( $_GET[$param] ) && ! is_array( $value ) ) { |
|
219 | + $value = stripslashes_deep( htmlspecialchars_decode( urldecode( $_GET[$param] ) ) ); |
|
220 | 220 | } |
221 | 221 | self::sanitize_value( $sanitize, $value ); |
222 | 222 | } else { |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | |
226 | 226 | if ( isset( $params ) && is_array( $value ) && ! empty( $value ) ) { |
227 | 227 | foreach ( $params as $k => $p ) { |
228 | - if ( ! $k || ! is_array($value) ) { |
|
228 | + if ( ! $k || ! is_array( $value ) ) { |
|
229 | 229 | continue; |
230 | 230 | } |
231 | 231 | |
232 | - $p = trim($p, ']'); |
|
233 | - $value = isset( $value[ $p ] ) ? $value[ $p ] : $default; |
|
232 | + $p = trim( $p, ']' ); |
|
233 | + $value = isset( $value[$p] ) ? $value[$p] : $default; |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
@@ -272,16 +272,16 @@ discard block |
||
272 | 272 | |
273 | 273 | $value = $args['default']; |
274 | 274 | if ( $args['type'] == 'get' ) { |
275 | - if ( $_GET && isset( $_GET[ $args['param'] ] ) ) { |
|
276 | - $value = $_GET[ $args['param'] ]; |
|
275 | + if ( $_GET && isset( $_GET[$args['param']] ) ) { |
|
276 | + $value = $_GET[$args['param']]; |
|
277 | 277 | } |
278 | 278 | } else if ( $args['type'] == 'post' ) { |
279 | - if ( isset( $_POST[ $args['param'] ] ) ) { |
|
280 | - $value = stripslashes_deep( maybe_unserialize( $_POST[ $args['param'] ] ) ); |
|
279 | + if ( isset( $_POST[$args['param']] ) ) { |
|
280 | + $value = stripslashes_deep( maybe_unserialize( $_POST[$args['param']] ) ); |
|
281 | 281 | } |
282 | 282 | } else { |
283 | - if ( isset( $_REQUEST[ $args['param'] ] ) ) { |
|
284 | - $value = $_REQUEST[ $args['param'] ]; |
|
283 | + if ( isset( $_REQUEST[$args['param']] ) ) { |
|
284 | + $value = $_REQUEST[$args['param']]; |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | |
@@ -317,8 +317,8 @@ discard block |
||
317 | 317 | public static function sanitize_request( $sanitize_method, &$values ) { |
318 | 318 | $temp_values = $values; |
319 | 319 | foreach ( $temp_values as $k => $val ) { |
320 | - if ( isset( $sanitize_method[ $k ] ) ) { |
|
321 | - $values[ $k ] = call_user_func( $sanitize_method[ $k ], $val ); |
|
320 | + if ( isset( $sanitize_method[$k] ) ) { |
|
321 | + $values[$k] = call_user_func( $sanitize_method[$k], $val ); |
|
322 | 322 | } |
323 | 323 | } |
324 | 324 | } |
@@ -326,7 +326,7 @@ discard block |
||
326 | 326 | public static function sanitize_array( &$values ) { |
327 | 327 | $temp_values = $values; |
328 | 328 | foreach ( $temp_values as $k => $val ) { |
329 | - $values[ $k ] = wp_kses_post( $val ); |
|
329 | + $values[$k] = wp_kses_post( $val ); |
|
330 | 330 | } |
331 | 331 | } |
332 | 332 | |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | |
347 | 347 | $allowed_html = array(); |
348 | 348 | foreach ( $allowed as $a ) { |
349 | - $allowed_html[ $a ] = isset( $html[ $a ] ) ? $html[ $a ] : array(); |
|
349 | + $allowed_html[$a] = isset( $html[$a] ) ? $html[$a] : array(); |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | return wp_kses( $value, $allowed_html ); |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | * @since 2.0 |
358 | 358 | */ |
359 | 359 | public static function remove_get_action() { |
360 | - if ( ! isset($_GET) ) { |
|
360 | + if ( ! isset( $_GET ) ) { |
|
361 | 361 | return; |
362 | 362 | } |
363 | 363 | |
@@ -379,8 +379,8 @@ discard block |
||
379 | 379 | } |
380 | 380 | |
381 | 381 | global $wp_query; |
382 | - if ( isset( $wp_query->query_vars[ $param ] ) ) { |
|
383 | - $value = $wp_query->query_vars[ $param ]; |
|
382 | + if ( isset( $wp_query->query_vars[$param] ) ) { |
|
383 | + $value = $wp_query->query_vars[$param]; |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | return $value; |
@@ -391,9 +391,9 @@ discard block |
||
391 | 391 | */ |
392 | 392 | public static function trigger_hook_load( $type, $object = null ) { |
393 | 393 | // only load the form hooks once |
394 | - $hooks_loaded = apply_filters('frm_'. $type .'_hooks_loaded', false, $object); |
|
394 | + $hooks_loaded = apply_filters( 'frm_' . $type . '_hooks_loaded', false, $object ); |
|
395 | 395 | if ( ! $hooks_loaded ) { |
396 | - do_action('frm_load_'. $type .'_hooks'); |
|
396 | + do_action( 'frm_load_' . $type . '_hooks' ); |
|
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
@@ -409,16 +409,16 @@ discard block |
||
409 | 409 | * @return mixed $results The cache or query results |
410 | 410 | */ |
411 | 411 | public static function check_cache( $cache_key, $group = '', $query = '', $type = 'get_var', $time = 300 ) { |
412 | - $results = wp_cache_get($cache_key, $group); |
|
413 | - if ( ! self::is_empty_value( $results, false ) || empty($query) ) { |
|
412 | + $results = wp_cache_get( $cache_key, $group ); |
|
413 | + if ( ! self::is_empty_value( $results, false ) || empty( $query ) ) { |
|
414 | 414 | return $results; |
415 | 415 | } |
416 | 416 | |
417 | 417 | if ( 'get_posts' == $type ) { |
418 | - $results = get_posts($query); |
|
418 | + $results = get_posts( $query ); |
|
419 | 419 | } else { |
420 | 420 | global $wpdb; |
421 | - $results = $wpdb->{$type}($query); |
|
421 | + $results = $wpdb->{$type}( $query ); |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | if ( ! self::prevent_caching() ) { |
@@ -442,9 +442,9 @@ discard block |
||
442 | 442 | } |
443 | 443 | |
444 | 444 | // then check the transient |
445 | - $results = get_transient($cache_key); |
|
445 | + $results = get_transient( $cache_key ); |
|
446 | 446 | if ( $results ) { |
447 | - wp_cache_set($cache_key, $results); |
|
447 | + wp_cache_set( $cache_key, $results ); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | return $results; |
@@ -455,8 +455,8 @@ discard block |
||
455 | 455 | * @param string $cache_key |
456 | 456 | */ |
457 | 457 | public static function delete_cache_and_transient( $cache_key ) { |
458 | - delete_transient($cache_key); |
|
459 | - wp_cache_delete($cache_key); |
|
458 | + delete_transient( $cache_key ); |
|
459 | + wp_cache_delete( $cache_key ); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | /** |
@@ -470,9 +470,9 @@ discard block |
||
470 | 470 | public static function cache_delete_group( $group ) { |
471 | 471 | global $wp_object_cache; |
472 | 472 | |
473 | - if ( isset( $wp_object_cache->cache[ $group ] ) ) { |
|
474 | - foreach ( $wp_object_cache->cache[ $group ] as $k => $v ) { |
|
475 | - wp_cache_delete($k, $group); |
|
473 | + if ( isset( $wp_object_cache->cache[$group] ) ) { |
|
474 | + foreach ( $wp_object_cache->cache[$group] as $k => $v ) { |
|
475 | + wp_cache_delete( $k, $group ); |
|
476 | 476 | } |
477 | 477 | return true; |
478 | 478 | } |
@@ -503,29 +503,29 @@ discard block |
||
503 | 503 | public static function load_scripts( $scripts ) { |
504 | 504 | _deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_script' ); |
505 | 505 | foreach ( (array) $scripts as $s ) { |
506 | - wp_enqueue_script($s); |
|
506 | + wp_enqueue_script( $s ); |
|
507 | 507 | } |
508 | 508 | } |
509 | 509 | |
510 | 510 | public static function load_styles( $styles ) { |
511 | 511 | _deprecated_function( __FUNCTION__, '2.0', 'wp_enqueue_style' ); |
512 | 512 | foreach ( (array) $styles as $s ) { |
513 | - wp_enqueue_style($s); |
|
513 | + wp_enqueue_style( $s ); |
|
514 | 514 | } |
515 | 515 | } |
516 | 516 | |
517 | 517 | public static function get_pages() { |
518 | - return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC' ) ); |
|
518 | + return get_posts( array( 'post_type' => 'page', 'post_status' => array( 'publish', 'private' ), 'numberposts' => - 1, 'orderby' => 'title', 'order' => 'ASC' ) ); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | public static function wp_pages_dropdown( $field_name, $page_id, $truncate = false ) { |
522 | 522 | $pages = self::get_pages(); |
523 | 523 | $selected = self::get_post_param( $field_name, $page_id, 'absint' ); |
524 | 524 | ?> |
525 | - <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" class="frm-pages-dropdown"> |
|
525 | + <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" class="frm-pages-dropdown"> |
|
526 | 526 | <option value=""> </option> |
527 | 527 | <?php foreach ( $pages as $page ) { ?> |
528 | - <option value="<?php echo esc_attr($page->ID); ?>" <?php selected( $selected, $page->ID ) ?>> |
|
528 | + <option value="<?php echo esc_attr( $page->ID ); ?>" <?php selected( $selected, $page->ID ) ?>> |
|
529 | 529 | <?php echo esc_html( $truncate ? self::truncate( $page->post_title, $truncate ) : $page->post_title ); ?> |
530 | 530 | </option> |
531 | 531 | <?php } ?> |
@@ -534,26 +534,26 @@ discard block |
||
534 | 534 | } |
535 | 535 | |
536 | 536 | public static function post_edit_link( $post_id ) { |
537 | - $post = get_post($post_id); |
|
537 | + $post = get_post( $post_id ); |
|
538 | 538 | if ( $post ) { |
539 | - return '<a href="'. esc_url(admin_url('post.php') .'?post='. $post_id .'&action=edit') .'">'. self::truncate($post->post_title, 50) .'</a>'; |
|
539 | + return '<a href="' . esc_url( admin_url( 'post.php' ) . '?post=' . $post_id . '&action=edit' ) . '">' . self::truncate( $post->post_title, 50 ) . '</a>'; |
|
540 | 540 | } |
541 | 541 | return ''; |
542 | 542 | } |
543 | 543 | |
544 | 544 | public static function wp_roles_dropdown( $field_name, $capability, $multiple = 'single' ) { |
545 | 545 | ?> |
546 | - <select name="<?php echo esc_attr($field_name); ?>" id="<?php echo esc_attr($field_name); ?>" <?php |
|
546 | + <select name="<?php echo esc_attr( $field_name ); ?>" id="<?php echo esc_attr( $field_name ); ?>" <?php |
|
547 | 547 | echo ( 'multiple' == $multiple ) ? 'multiple="multiple"' : ''; |
548 | 548 | ?> class="frm_multiselect"> |
549 | - <?php self::roles_options($capability); ?> |
|
549 | + <?php self::roles_options( $capability ); ?> |
|
550 | 550 | </select> |
551 | 551 | <?php |
552 | 552 | } |
553 | 553 | |
554 | 554 | public static function roles_options( $capability ) { |
555 | 555 | global $frm_vars; |
556 | - if ( isset($frm_vars['editable_roles']) ) { |
|
556 | + if ( isset( $frm_vars['editable_roles'] ) ) { |
|
557 | 557 | $editable_roles = $frm_vars['editable_roles']; |
558 | 558 | } else { |
559 | 559 | $editable_roles = get_editable_roles(); |
@@ -561,10 +561,10 @@ discard block |
||
561 | 561 | } |
562 | 562 | |
563 | 563 | foreach ( $editable_roles as $role => $details ) { |
564 | - $name = translate_user_role($details['name'] ); ?> |
|
565 | - <option value="<?php echo esc_attr($role) ?>" <?php echo in_array($role, (array) $capability) ? ' selected="selected"' : ''; ?>><?php echo esc_attr($name) ?> </option> |
|
564 | + $name = translate_user_role( $details['name'] ); ?> |
|
565 | + <option value="<?php echo esc_attr( $role ) ?>" <?php echo in_array( $role, (array) $capability ) ? ' selected="selected"' : ''; ?>><?php echo esc_attr( $name ) ?> </option> |
|
566 | 566 | <?php |
567 | - unset($role, $details); |
|
567 | + unset( $role, $details ); |
|
568 | 568 | } |
569 | 569 | } |
570 | 570 | |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | public static function maybe_add_permissions() { |
621 | 621 | self::force_capability( 'frm_view_entries' ); |
622 | 622 | |
623 | - if ( ! current_user_can('administrator') || current_user_can('frm_view_forms') ) { |
|
623 | + if ( ! current_user_can( 'administrator' ) || current_user_can( 'frm_view_forms' ) ) { |
|
624 | 624 | return; |
625 | 625 | } |
626 | 626 | |
@@ -629,7 +629,7 @@ discard block |
||
629 | 629 | $frm_roles = self::frm_capabilities(); |
630 | 630 | foreach ( $frm_roles as $frm_role => $frm_role_description ) { |
631 | 631 | $user->add_cap( $frm_role ); |
632 | - unset($frm_role, $frm_role_description); |
|
632 | + unset( $frm_role, $frm_role_description ); |
|
633 | 633 | } |
634 | 634 | } |
635 | 635 | |
@@ -654,12 +654,12 @@ discard block |
||
654 | 654 | * @param string $permission |
655 | 655 | */ |
656 | 656 | public static function permission_check( $permission, $show_message = 'show' ) { |
657 | - $permission_error = self::permission_nonce_error($permission); |
|
657 | + $permission_error = self::permission_nonce_error( $permission ); |
|
658 | 658 | if ( $permission_error !== false ) { |
659 | 659 | if ( 'hide' == $show_message ) { |
660 | 660 | $permission_error = ''; |
661 | 661 | } |
662 | - wp_die($permission_error); |
|
662 | + wp_die( $permission_error ); |
|
663 | 663 | } |
664 | 664 | } |
665 | 665 | |
@@ -676,11 +676,11 @@ discard block |
||
676 | 676 | } |
677 | 677 | |
678 | 678 | $error = false; |
679 | - if ( empty($nonce_name) ) { |
|
679 | + if ( empty( $nonce_name ) ) { |
|
680 | 680 | return $error; |
681 | 681 | } |
682 | 682 | |
683 | - if ( $_REQUEST && ( ! isset( $_REQUEST[ $nonce_name ] ) || ! wp_verify_nonce( $_REQUEST[ $nonce_name ], $nonce ) ) ) { |
|
683 | + if ( $_REQUEST && ( ! isset( $_REQUEST[$nonce_name] ) || ! wp_verify_nonce( $_REQUEST[$nonce_name], $nonce ) ) ) { |
|
684 | 684 | $frm_settings = self::get_settings(); |
685 | 685 | $error = $frm_settings->admin_permission; |
686 | 686 | } |
@@ -696,9 +696,9 @@ discard block |
||
696 | 696 | |
697 | 697 | public static function check_selected( $values, $current ) { |
698 | 698 | $values = self::recursive_function_map( $values, 'trim' ); |
699 | - $current = trim($current); |
|
699 | + $current = trim( $current ); |
|
700 | 700 | |
701 | - return ( is_array($values) && in_array($current, $values) ) || ( ! is_array($values) && $values == $current ); |
|
701 | + return ( is_array( $values ) && in_array( $current, $values ) ) || ( ! is_array( $values ) && $values == $current ); |
|
702 | 702 | } |
703 | 703 | |
704 | 704 | /** |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | } else { |
760 | 760 | foreach ( $value as $k => $v ) { |
761 | 761 | if ( ! is_array( $v ) ) { |
762 | - $value[ $k ] = call_user_func( $original_function, $v ); |
|
762 | + $value[$k] = call_user_func( $original_function, $v ); |
|
763 | 763 | } |
764 | 764 | } |
765 | 765 | } |
@@ -780,11 +780,11 @@ discard block |
||
780 | 780 | public static function array_flatten( $array, $keys = 'keep' ) { |
781 | 781 | $return = array(); |
782 | 782 | foreach ( $array as $key => $value ) { |
783 | - if ( is_array($value) ) { |
|
783 | + if ( is_array( $value ) ) { |
|
784 | 784 | $return = array_merge( $return, self::array_flatten( $value, $keys ) ); |
785 | 785 | } else { |
786 | 786 | if ( $keys == 'keep' ) { |
787 | - $return[ $key ] = $value; |
|
787 | + $return[$key] = $value; |
|
788 | 788 | } else { |
789 | 789 | $return[] = $value; |
790 | 790 | } |
@@ -794,7 +794,7 @@ discard block |
||
794 | 794 | } |
795 | 795 | |
796 | 796 | public static function esc_textarea( $text ) { |
797 | - $safe_text = str_replace('"', '"', $text); |
|
797 | + $safe_text = str_replace( '"', '"', $text ); |
|
798 | 798 | $safe_text = htmlspecialchars( $safe_text, ENT_NOQUOTES ); |
799 | 799 | return apply_filters( 'esc_textarea', $safe_text, $text ); |
800 | 800 | } |
@@ -804,8 +804,8 @@ discard block |
||
804 | 804 | * @since 2.0 |
805 | 805 | */ |
806 | 806 | public static function use_wpautop( $content ) { |
807 | - if ( apply_filters('frm_use_wpautop', true) ) { |
|
808 | - $content = wpautop(str_replace( '<br>', '<br />', $content)); |
|
807 | + if ( apply_filters( 'frm_use_wpautop', true ) ) { |
|
808 | + $content = wpautop( str_replace( '<br>', '<br />', $content ) ); |
|
809 | 809 | } |
810 | 810 | return $content; |
811 | 811 | } |
@@ -823,8 +823,8 @@ discard block |
||
823 | 823 | * @return string The base Google APIS url for the current version of jQuery UI |
824 | 824 | */ |
825 | 825 | public static function jquery_ui_base_url() { |
826 | - $url = 'http'. ( is_ssl() ? 's' : '' ) .'://ajax.googleapis.com/ajax/libs/jqueryui/'. self::script_version('jquery-ui-core'); |
|
827 | - $url = apply_filters('frm_jquery_ui_base_url', $url); |
|
826 | + $url = 'http' . ( is_ssl() ? 's' : '' ) . '://ajax.googleapis.com/ajax/libs/jqueryui/' . self::script_version( 'jquery-ui-core' ); |
|
827 | + $url = apply_filters( 'frm_jquery_ui_base_url', $url ); |
|
828 | 828 | return $url; |
829 | 829 | } |
830 | 830 | |
@@ -839,11 +839,11 @@ discard block |
||
839 | 839 | |
840 | 840 | $ver = 0; |
841 | 841 | |
842 | - if ( ! isset( $wp_scripts->registered[ $handle ] ) ) { |
|
842 | + if ( ! isset( $wp_scripts->registered[$handle] ) ) { |
|
843 | 843 | return $ver; |
844 | 844 | } |
845 | 845 | |
846 | - $query = $wp_scripts->registered[ $handle ]; |
|
846 | + $query = $wp_scripts->registered[$handle]; |
|
847 | 847 | if ( is_object( $query ) ) { |
848 | 848 | $ver = $query->ver; |
849 | 849 | } |
@@ -856,7 +856,7 @@ discard block |
||
856 | 856 | } |
857 | 857 | |
858 | 858 | public static function get_user_id_param( $user_id ) { |
859 | - if ( ! $user_id || empty($user_id) || is_numeric($user_id) ) { |
|
859 | + if ( ! $user_id || empty( $user_id ) || is_numeric( $user_id ) ) { |
|
860 | 860 | return $user_id; |
861 | 861 | } |
862 | 862 | |
@@ -864,29 +864,29 @@ discard block |
||
864 | 864 | $user_ID = get_current_user_id(); |
865 | 865 | $user_id = $user_ID; |
866 | 866 | } else { |
867 | - if ( is_email($user_id) ) { |
|
868 | - $user = get_user_by('email', $user_id); |
|
867 | + if ( is_email( $user_id ) ) { |
|
868 | + $user = get_user_by( 'email', $user_id ); |
|
869 | 869 | } else { |
870 | - $user = get_user_by('login', $user_id); |
|
870 | + $user = get_user_by( 'login', $user_id ); |
|
871 | 871 | } |
872 | 872 | |
873 | 873 | if ( $user ) { |
874 | 874 | $user_id = $user->ID; |
875 | 875 | } |
876 | - unset($user); |
|
876 | + unset( $user ); |
|
877 | 877 | } |
878 | 878 | |
879 | 879 | return $user_id; |
880 | 880 | } |
881 | 881 | |
882 | 882 | public static function get_file_contents( $filename, $atts = array() ) { |
883 | - if ( ! is_file($filename) ) { |
|
883 | + if ( ! is_file( $filename ) ) { |
|
884 | 884 | return false; |
885 | 885 | } |
886 | 886 | |
887 | - extract($atts); |
|
887 | + extract( $atts ); |
|
888 | 888 | ob_start(); |
889 | - include($filename); |
|
889 | + include( $filename ); |
|
890 | 890 | $contents = ob_get_contents(); |
891 | 891 | ob_end_clean(); |
892 | 892 | return $contents; |
@@ -902,28 +902,28 @@ discard block |
||
902 | 902 | $key = ''; |
903 | 903 | |
904 | 904 | if ( ! empty( $name ) ) { |
905 | - $key = sanitize_key($name); |
|
905 | + $key = sanitize_key( $name ); |
|
906 | 906 | } |
907 | 907 | |
908 | 908 | if ( empty( $key ) ) { |
909 | - $max_slug_value = pow(36, $num_chars); |
|
909 | + $max_slug_value = pow( 36, $num_chars ); |
|
910 | 910 | $min_slug_value = 37; // we want to have at least 2 characters in the slug |
911 | - $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
911 | + $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 ); |
|
912 | 912 | } |
913 | 913 | |
914 | - if ( is_numeric($key) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) { |
|
915 | - $key = $key .'a'; |
|
914 | + if ( is_numeric( $key ) || in_array( $key, array( 'id', 'key', 'created-at', 'detaillink', 'editlink', 'siteurl', 'evenodd' ) ) ) { |
|
915 | + $key = $key . 'a'; |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | $key_check = FrmDb::get_var( $table_name, array( $column => $key, 'ID !' => $id ), $column ); |
919 | 919 | |
920 | - if ( $key_check || is_numeric($key_check) ) { |
|
920 | + if ( $key_check || is_numeric( $key_check ) ) { |
|
921 | 921 | $suffix = 2; |
922 | 922 | do { |
923 | 923 | $alt_post_name = substr( $key, 0, 200 - ( strlen( $suffix ) + 1 ) ) . $suffix; |
924 | 924 | $key_check = FrmDb::get_var( $table_name, array( $column => $alt_post_name, 'ID !' => $id ), $column ); |
925 | - $suffix++; |
|
926 | - } while ($key_check || is_numeric($key_check)); |
|
925 | + $suffix ++; |
|
926 | + } while ( $key_check || is_numeric( $key_check ) ); |
|
927 | 927 | $key = $alt_post_name; |
928 | 928 | } |
929 | 929 | return $key; |
@@ -941,32 +941,32 @@ discard block |
||
941 | 941 | |
942 | 942 | global $frm_vars; |
943 | 943 | |
944 | - if ( empty($post_values) ) { |
|
945 | - $post_values = stripslashes_deep($_POST); |
|
944 | + if ( empty( $post_values ) ) { |
|
945 | + $post_values = stripslashes_deep( $_POST ); |
|
946 | 946 | } |
947 | 947 | |
948 | 948 | $values = array( 'id' => $record->id, 'fields' => array() ); |
949 | 949 | |
950 | 950 | foreach ( array( 'name', 'description' ) as $var ) { |
951 | - $default_val = isset($record->{$var}) ? $record->{$var} : ''; |
|
952 | - $values[ $var ] = self::get_param( $var, $default_val ); |
|
953 | - unset($var, $default_val); |
|
951 | + $default_val = isset( $record->{$var}) ? $record->{$var} : ''; |
|
952 | + $values[$var] = self::get_param( $var, $default_val ); |
|
953 | + unset( $var, $default_val ); |
|
954 | 954 | } |
955 | 955 | |
956 | - $values['description'] = self::use_wpautop($values['description']); |
|
956 | + $values['description'] = self::use_wpautop( $values['description'] ); |
|
957 | 957 | $frm_settings = self::get_settings(); |
958 | - $is_form_builder = self::is_admin_page('formidable' ); |
|
958 | + $is_form_builder = self::is_admin_page( 'formidable' ); |
|
959 | 959 | |
960 | 960 | foreach ( (array) $fields as $field ) { |
961 | 961 | // Make sure to filter default values (for placeholder text), but not on the form builder page |
962 | 962 | if ( ! $is_form_builder ) { |
963 | - $field->default_value = apply_filters('frm_get_default_value', $field->default_value, $field, true ); |
|
963 | + $field->default_value = apply_filters( 'frm_get_default_value', $field->default_value, $field, true ); |
|
964 | 964 | } |
965 | 965 | $parent_form_id = isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id; |
966 | - self::fill_field_defaults($field, $record, $values, compact('default', 'post_values', 'frm_settings', 'parent_form_id' ) ); |
|
966 | + self::fill_field_defaults( $field, $record, $values, compact( 'default', 'post_values', 'frm_settings', 'parent_form_id' ) ); |
|
967 | 967 | } |
968 | 968 | |
969 | - self::fill_form_opts($record, $table, $post_values, $values); |
|
969 | + self::fill_form_opts( $record, $table, $post_values, $values ); |
|
970 | 970 | |
971 | 971 | if ( $table == 'entries' ) { |
972 | 972 | $values = FrmEntriesHelper::setup_edit_vars( $values, $record ); |
@@ -983,8 +983,8 @@ discard block |
||
983 | 983 | if ( $args['default'] ) { |
984 | 984 | $meta_value = $field->default_value; |
985 | 985 | } else { |
986 | - if ( $record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field'] ) { |
|
987 | - if ( ! isset($field->field_options['custom_field']) ) { |
|
986 | + if ( $record->post_id && self::pro_is_installed() && isset( $field->field_options['post_field'] ) && $field->field_options['post_field'] ) { |
|
987 | + if ( ! isset( $field->field_options['custom_field'] ) ) { |
|
988 | 988 | $field->field_options['custom_field'] = ''; |
989 | 989 | } |
990 | 990 | $meta_value = FrmProEntryMetaHelper::get_post_value( $record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array( 'truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field ) ); |
@@ -993,8 +993,8 @@ discard block |
||
993 | 993 | } |
994 | 994 | } |
995 | 995 | |
996 | - $field_type = isset( $post_values['field_options'][ 'type_'. $field->id ] ) ? $post_values['field_options'][ 'type_'. $field->id ] : $field->type; |
|
997 | - $new_value = isset( $post_values['item_meta'][ $field->id ] ) ? maybe_unserialize( $post_values['item_meta'][ $field->id ] ) : $meta_value; |
|
996 | + $field_type = isset( $post_values['field_options']['type_' . $field->id] ) ? $post_values['field_options']['type_' . $field->id] : $field->type; |
|
997 | + $new_value = isset( $post_values['item_meta'][$field->id] ) ? maybe_unserialize( $post_values['item_meta'][$field->id] ) : $meta_value; |
|
998 | 998 | |
999 | 999 | $field_array = array( |
1000 | 1000 | 'id' => $field->id, |
@@ -1002,7 +1002,7 @@ discard block |
||
1002 | 1002 | 'default_value' => $field->default_value, |
1003 | 1003 | 'name' => $field->name, |
1004 | 1004 | 'description' => $field->description, |
1005 | - 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value), |
|
1005 | + 'type' => apply_filters( 'frm_field_type', $field_type, $field, $new_value ), |
|
1006 | 1006 | 'options' => $field->options, |
1007 | 1007 | 'required' => $field->required, |
1008 | 1008 | 'field_key' => $field->field_key, |
@@ -1012,38 +1012,38 @@ discard block |
||
1012 | 1012 | ); |
1013 | 1013 | |
1014 | 1014 | $args['field_type'] = $field_type; |
1015 | - self::fill_field_opts($field, $field_array, $args); |
|
1015 | + self::fill_field_opts( $field, $field_array, $args ); |
|
1016 | 1016 | |
1017 | - $field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']); |
|
1017 | + $field_array = apply_filters( 'frm_setup_edit_fields_vars', $field_array, $field, $values['id'] ); |
|
1018 | 1018 | |
1019 | - if ( ! isset($field_array['unique']) || ! $field_array['unique'] ) { |
|
1019 | + if ( ! isset( $field_array['unique'] ) || ! $field_array['unique'] ) { |
|
1020 | 1020 | $field_array['unique_msg'] = ''; |
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | $field_array = array_merge( $field->field_options, $field_array ); |
1024 | 1024 | |
1025 | - $values['fields'][ $field->id ] = $field_array; |
|
1025 | + $values['fields'][$field->id] = $field_array; |
|
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | private static function fill_field_opts( $field, array &$field_array, $args ) { |
1029 | 1029 | $post_values = $args['post_values']; |
1030 | - $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
1030 | + $opt_defaults = FrmFieldsHelper::get_default_field_opts( $field_array['type'], $field, true ); |
|
1031 | 1031 | |
1032 | 1032 | foreach ( $opt_defaults as $opt => $default_opt ) { |
1033 | - $field_array[ $opt ] = ( $post_values && isset( $post_values['field_options'][ $opt .'_'. $field->id ] ) ) ? maybe_unserialize( $post_values['field_options'][ $opt .'_'. $field->id ] ) : ( isset( $field->field_options[ $opt ] ) ? $field->field_options[ $opt ] : $default_opt ); |
|
1034 | - if ( $opt == 'blank' && $field_array[ $opt ] == '' ) { |
|
1035 | - $field_array[ $opt ] = $args['frm_settings']->blank_msg; |
|
1036 | - } else if ( $opt == 'invalid' && $field_array[ $opt ] == '' ) { |
|
1033 | + $field_array[$opt] = ( $post_values && isset( $post_values['field_options'][$opt . '_' . $field->id] ) ) ? maybe_unserialize( $post_values['field_options'][$opt . '_' . $field->id] ) : ( isset( $field->field_options[$opt] ) ? $field->field_options[$opt] : $default_opt ); |
|
1034 | + if ( $opt == 'blank' && $field_array[$opt] == '' ) { |
|
1035 | + $field_array[$opt] = $args['frm_settings']->blank_msg; |
|
1036 | + } else if ( $opt == 'invalid' && $field_array[$opt] == '' ) { |
|
1037 | 1037 | if ( $args['field_type'] == 'captcha' ) { |
1038 | - $field_array[ $opt ] = $args['frm_settings']->re_msg; |
|
1038 | + $field_array[$opt] = $args['frm_settings']->re_msg; |
|
1039 | 1039 | } else { |
1040 | - $field_array[ $opt ] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] ); |
|
1040 | + $field_array[$opt] = sprintf( __( '%s is invalid', 'formidable' ), $field_array['name'] ); |
|
1041 | 1041 | } |
1042 | 1042 | } |
1043 | 1043 | } |
1044 | 1044 | |
1045 | 1045 | if ( $field_array['custom_html'] == '' ) { |
1046 | - $field_array['custom_html'] = FrmFieldsHelper::get_default_html($args['field_type']); |
|
1046 | + $field_array['custom_html'] = FrmFieldsHelper::get_default_html( $args['field_type'] ); |
|
1047 | 1047 | } |
1048 | 1048 | } |
1049 | 1049 | |
@@ -1062,18 +1062,18 @@ discard block |
||
1062 | 1062 | return; |
1063 | 1063 | } |
1064 | 1064 | |
1065 | - $values['form_name'] = isset($record->form_id) ? $form->name : ''; |
|
1065 | + $values['form_name'] = isset( $record->form_id ) ? $form->name : ''; |
|
1066 | 1066 | $values['parent_form_id'] = isset( $record->form_id ) ? $form->parent_form_id : 0; |
1067 | 1067 | |
1068 | - if ( ! is_array($form->options) ) { |
|
1068 | + if ( ! is_array( $form->options ) ) { |
|
1069 | 1069 | return; |
1070 | 1070 | } |
1071 | 1071 | |
1072 | 1072 | foreach ( $form->options as $opt => $value ) { |
1073 | - $values[ $opt ] = isset( $post_values[ $opt ] ) ? maybe_unserialize( $post_values[ $opt ] ) : $value; |
|
1073 | + $values[$opt] = isset( $post_values[$opt] ) ? maybe_unserialize( $post_values[$opt] ) : $value; |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | - self::fill_form_defaults($post_values, $values); |
|
1076 | + self::fill_form_defaults( $post_values, $values ); |
|
1077 | 1077 | } |
1078 | 1078 | |
1079 | 1079 | /** |
@@ -1083,23 +1083,23 @@ discard block |
||
1083 | 1083 | $form_defaults = FrmFormsHelper::get_default_opts(); |
1084 | 1084 | |
1085 | 1085 | foreach ( $form_defaults as $opt => $default ) { |
1086 | - if ( ! isset( $values[ $opt ] ) || $values[ $opt ] == '' ) { |
|
1087 | - $values[ $opt ] = ( $post_values && isset( $post_values['options'][ $opt ] ) ) ? $post_values['options'][ $opt ] : $default; |
|
1086 | + if ( ! isset( $values[$opt] ) || $values[$opt] == '' ) { |
|
1087 | + $values[$opt] = ( $post_values && isset( $post_values['options'][$opt] ) ) ? $post_values['options'][$opt] : $default; |
|
1088 | 1088 | } |
1089 | 1089 | |
1090 | - unset($opt, $defaut); |
|
1090 | + unset( $opt, $defaut ); |
|
1091 | 1091 | } |
1092 | 1092 | |
1093 | - if ( ! isset($values['custom_style']) ) { |
|
1093 | + if ( ! isset( $values['custom_style'] ) ) { |
|
1094 | 1094 | $frm_settings = self::get_settings(); |
1095 | 1095 | $values['custom_style'] = ( $post_values && isset( $post_values['options']['custom_style'] ) ) ? absint( $_POST['options']['custom_style'] ) : ( $frm_settings->load_style != 'none' ); |
1096 | 1096 | } |
1097 | 1097 | |
1098 | 1098 | foreach ( array( 'before', 'after', 'submit' ) as $h ) { |
1099 | - if ( ! isset( $values[ $h .'_html' ] ) ) { |
|
1100 | - $values[ $h .'_html' ] = ( isset( $post_values['options'][ $h .'_html' ] ) ? $post_values['options'][ $h .'_html' ] : FrmFormsHelper::get_default_html( $h ) ); |
|
1099 | + if ( ! isset( $values[$h . '_html'] ) ) { |
|
1100 | + $values[$h . '_html'] = ( isset( $post_values['options'][$h . '_html'] ) ? $post_values['options'][$h . '_html'] : FrmFormsHelper::get_default_html( $h ) ); |
|
1101 | 1101 | } |
1102 | - unset($h); |
|
1102 | + unset( $h ); |
|
1103 | 1103 | } |
1104 | 1104 | } |
1105 | 1105 | |
@@ -1115,9 +1115,9 @@ discard block |
||
1115 | 1115 | } |
1116 | 1116 | ?> |
1117 | 1117 | <li> |
1118 | - <a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['id']) ?>" >[<?php echo esc_attr( $args['id'] ) ?>]</a> |
|
1119 | - <a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr($class) ?>" data-code="<?php echo esc_attr($args['key']) ?>" >[<?php echo esc_attr( self::truncate($args['key'], 10) ) ?>]</a> |
|
1120 | - <a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr($args['id']) ?>" ><?php echo esc_attr( self::truncate($args['name'], 60) ) ?></a> |
|
1118 | + <a href="javascript:void(0)" class="frmids frm_insert_code alignright <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr( $args['id'] ) ?>" >[<?php echo esc_attr( $args['id'] ) ?>]</a> |
|
1119 | + <a href="javascript:void(0)" class="frmkeys frm_insert_code alignright <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr( $args['key'] ) ?>" >[<?php echo esc_attr( self::truncate( $args['key'], 10 ) ) ?>]</a> |
|
1120 | + <a href="javascript:void(0)" class="frm_insert_code <?php echo esc_attr( $class ) ?>" data-code="<?php echo esc_attr( $args['id'] ) ?>" ><?php echo esc_attr( self::truncate( $args['name'], 60 ) ) ?></a> |
|
1121 | 1121 | </li> |
1122 | 1122 | <?php |
1123 | 1123 | } |
@@ -1145,7 +1145,7 @@ discard block |
||
1145 | 1145 | return ''; |
1146 | 1146 | } else if ( $length <= 10 ) { |
1147 | 1147 | $sub = self::mb_function( array( 'mb_substr', 'substr' ), array( $str, 0, $length ) ); |
1148 | - return $sub . (($length < $original_len) ? $continue : ''); |
|
1148 | + return $sub . ( ( $length < $original_len ) ? $continue : '' ); |
|
1149 | 1149 | } |
1150 | 1150 | |
1151 | 1151 | $sub = ''; |
@@ -1154,23 +1154,23 @@ discard block |
||
1154 | 1154 | $words = self::mb_function( array( 'mb_split', 'explode' ), array( ' ', $str ) ); |
1155 | 1155 | |
1156 | 1156 | foreach ( $words as $word ) { |
1157 | - $part = (($sub != '') ? ' ' : '') . $word; |
|
1157 | + $part = ( ( $sub != '' ) ? ' ' : '' ) . $word; |
|
1158 | 1158 | $total_len = self::mb_function( array( 'mb_strlen', 'strlen' ), array( $sub . $part ) ); |
1159 | - if ( $total_len > $length && str_word_count($sub) ) { |
|
1159 | + if ( $total_len > $length && str_word_count( $sub ) ) { |
|
1160 | 1160 | break; |
1161 | 1161 | } |
1162 | 1162 | |
1163 | 1163 | $sub .= $part; |
1164 | 1164 | $len += self::mb_function( array( 'mb_strlen', 'strlen' ), array( $part ) ); |
1165 | 1165 | |
1166 | - if ( str_word_count($sub) > $minword && $total_len >= $length ) { |
|
1166 | + if ( str_word_count( $sub ) > $minword && $total_len >= $length ) { |
|
1167 | 1167 | break; |
1168 | 1168 | } |
1169 | 1169 | |
1170 | - unset($total_len, $word); |
|
1170 | + unset( $total_len, $word ); |
|
1171 | 1171 | } |
1172 | 1172 | |
1173 | - return $sub . (($len < $original_len) ? $continue : ''); |
|
1173 | + return $sub . ( ( $len < $original_len ) ? $continue : '' ); |
|
1174 | 1174 | } |
1175 | 1175 | |
1176 | 1176 | public static function mb_function( $function_names, $args ) { |
@@ -1183,17 +1183,17 @@ discard block |
||
1183 | 1183 | } |
1184 | 1184 | |
1185 | 1185 | public static function get_formatted_time( $date, $date_format = '', $time_format = '' ) { |
1186 | - if ( empty($date) ) { |
|
1186 | + if ( empty( $date ) ) { |
|
1187 | 1187 | return $date; |
1188 | 1188 | } |
1189 | 1189 | |
1190 | - if ( empty($date_format) ) { |
|
1191 | - $date_format = get_option('date_format'); |
|
1190 | + if ( empty( $date_format ) ) { |
|
1191 | + $date_format = get_option( 'date_format' ); |
|
1192 | 1192 | } |
1193 | 1193 | |
1194 | - if ( preg_match('/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date) && self::pro_is_installed() ) { |
|
1194 | + if ( preg_match( '/^\d{1-2}\/\d{1-2}\/\d{4}$/', $date ) && self::pro_is_installed() ) { |
|
1195 | 1195 | $frmpro_settings = new FrmProSettings(); |
1196 | - $date = FrmProAppHelper::convert_date($date, $frmpro_settings->date_format, 'Y-m-d'); |
|
1196 | + $date = FrmProAppHelper::convert_date( $date, $frmpro_settings->date_format, 'Y-m-d' ); |
|
1197 | 1197 | } |
1198 | 1198 | |
1199 | 1199 | $formatted = self::get_localized_date( $date_format, $date ); |
@@ -1208,7 +1208,7 @@ discard block |
||
1208 | 1208 | |
1209 | 1209 | private static function add_time_to_date( $time_format, $date ) { |
1210 | 1210 | if ( empty( $time_format ) ) { |
1211 | - $time_format = get_option('time_format'); |
|
1211 | + $time_format = get_option( 'time_format' ); |
|
1212 | 1212 | } |
1213 | 1213 | |
1214 | 1214 | $trimmed_format = trim( $time_format ); |
@@ -1232,7 +1232,7 @@ discard block |
||
1232 | 1232 | * @return string The time ago in words |
1233 | 1233 | */ |
1234 | 1234 | public static function human_time_diff( $from, $to = '' ) { |
1235 | - if ( empty($to) ) { |
|
1235 | + if ( empty( $to ) ) { |
|
1236 | 1236 | $to = time(); |
1237 | 1237 | } |
1238 | 1238 | |
@@ -1248,7 +1248,7 @@ discard block |
||
1248 | 1248 | ); |
1249 | 1249 | |
1250 | 1250 | // Difference in seconds |
1251 | - $diff = (int) ($to - $from); |
|
1251 | + $diff = (int) ( $to - $from ); |
|
1252 | 1252 | |
1253 | 1253 | // Something went wrong with date calculation and we ended up with a negative date. |
1254 | 1254 | if ( $diff < 1 ) { |
@@ -1265,17 +1265,17 @@ discard block |
||
1265 | 1265 | $count = 0; |
1266 | 1266 | |
1267 | 1267 | //Step one: the first chunk |
1268 | - for ( $i = 0, $j = count( $chunks ); $i < $j; $i++ ) { |
|
1269 | - $seconds = $chunks[ $i ][0]; |
|
1268 | + for ( $i = 0, $j = count( $chunks ); $i < $j; $i ++ ) { |
|
1269 | + $seconds = $chunks[$i][0]; |
|
1270 | 1270 | |
1271 | 1271 | // Finding the biggest chunk (if the chunk fits, break) |
1272 | - if ( ( $count = floor($diff / $seconds) ) != 0 ) { |
|
1272 | + if ( ( $count = floor( $diff / $seconds ) ) != 0 ) { |
|
1273 | 1273 | break; |
1274 | 1274 | } |
1275 | 1275 | } |
1276 | 1276 | |
1277 | 1277 | // Set output var |
1278 | - $output = ( 1 == $count ) ? '1 '. $chunks[ $i ][1] : $count . ' ' . $chunks[ $i ][2]; |
|
1278 | + $output = ( 1 == $count ) ? '1 ' . $chunks[$i][1] : $count . ' ' . $chunks[$i][2]; |
|
1279 | 1279 | |
1280 | 1280 | if ( ! (int) trim( $output ) ) { |
1281 | 1281 | $output = '0 ' . __( 'seconds', 'formidable' ); |
@@ -1294,7 +1294,7 @@ discard block |
||
1294 | 1294 | */ |
1295 | 1295 | public static function esc_like( $term ) { |
1296 | 1296 | global $wpdb; |
1297 | - if ( method_exists($wpdb, 'esc_like') ) { |
|
1297 | + if ( method_exists( $wpdb, 'esc_like' ) ) { |
|
1298 | 1298 | // WP 4.0 |
1299 | 1299 | $term = $wpdb->esc_like( $term ); |
1300 | 1300 | } else { |
@@ -1308,17 +1308,17 @@ discard block |
||
1308 | 1308 | * @param string $order_query |
1309 | 1309 | */ |
1310 | 1310 | public static function esc_order( $order_query ) { |
1311 | - if ( empty($order_query) ) { |
|
1311 | + if ( empty( $order_query ) ) { |
|
1312 | 1312 | return ''; |
1313 | 1313 | } |
1314 | 1314 | |
1315 | 1315 | // remove ORDER BY before santizing |
1316 | - $order_query = strtolower($order_query); |
|
1317 | - if ( strpos($order_query, 'order by') !== false ) { |
|
1318 | - $order_query = str_replace('order by', '', $order_query); |
|
1316 | + $order_query = strtolower( $order_query ); |
|
1317 | + if ( strpos( $order_query, 'order by' ) !== false ) { |
|
1318 | + $order_query = str_replace( 'order by', '', $order_query ); |
|
1319 | 1319 | } |
1320 | 1320 | |
1321 | - $order_query = explode(' ', trim($order_query)); |
|
1321 | + $order_query = explode( ' ', trim( $order_query ) ); |
|
1322 | 1322 | |
1323 | 1323 | $order_fields = array( |
1324 | 1324 | 'id', 'form_key', 'name', 'description', |
@@ -1326,18 +1326,18 @@ discard block |
||
1326 | 1326 | 'default_template', 'status', 'created_at', |
1327 | 1327 | ); |
1328 | 1328 | |
1329 | - $order = trim(trim(reset($order_query), ',')); |
|
1330 | - if ( ! in_array($order, $order_fields) ) { |
|
1329 | + $order = trim( trim( reset( $order_query ), ',' ) ); |
|
1330 | + if ( ! in_array( $order, $order_fields ) ) { |
|
1331 | 1331 | return ''; |
1332 | 1332 | } |
1333 | 1333 | |
1334 | 1334 | $order_by = ''; |
1335 | - if ( count($order_query) > 1 ) { |
|
1335 | + if ( count( $order_query ) > 1 ) { |
|
1336 | 1336 | $order_by = end( $order_query ); |
1337 | 1337 | self::esc_order_by( $order_by ); |
1338 | 1338 | } |
1339 | 1339 | |
1340 | - return ' ORDER BY '. $order . ' '. $order_by; |
|
1340 | + return ' ORDER BY ' . $order . ' ' . $order_by; |
|
1341 | 1341 | } |
1342 | 1342 | |
1343 | 1343 | /** |
@@ -1354,24 +1354,24 @@ discard block |
||
1354 | 1354 | * @param string $limit |
1355 | 1355 | */ |
1356 | 1356 | public static function esc_limit( $limit ) { |
1357 | - if ( empty($limit) ) { |
|
1357 | + if ( empty( $limit ) ) { |
|
1358 | 1358 | return ''; |
1359 | 1359 | } |
1360 | 1360 | |
1361 | - $limit = trim(str_replace(' limit', '', strtolower($limit))); |
|
1362 | - if ( is_numeric($limit) ) { |
|
1363 | - return ' LIMIT '. $limit; |
|
1361 | + $limit = trim( str_replace( ' limit', '', strtolower( $limit ) ) ); |
|
1362 | + if ( is_numeric( $limit ) ) { |
|
1363 | + return ' LIMIT ' . $limit; |
|
1364 | 1364 | } |
1365 | 1365 | |
1366 | - $limit = explode(',', trim($limit)); |
|
1366 | + $limit = explode( ',', trim( $limit ) ); |
|
1367 | 1367 | foreach ( $limit as $k => $l ) { |
1368 | 1368 | if ( is_numeric( $l ) ) { |
1369 | - $limit[ $k ] = $l; |
|
1369 | + $limit[$k] = $l; |
|
1370 | 1370 | } |
1371 | 1371 | } |
1372 | 1372 | |
1373 | - $limit = implode(',', $limit); |
|
1374 | - return ' LIMIT '. $limit; |
|
1373 | + $limit = implode( ',', $limit ); |
|
1374 | + return ' LIMIT ' . $limit; |
|
1375 | 1375 | } |
1376 | 1376 | |
1377 | 1377 | /** |
@@ -1379,12 +1379,12 @@ discard block |
||
1379 | 1379 | * @since 2.0 |
1380 | 1380 | */ |
1381 | 1381 | public static function prepare_array_values( $array, $type = '%s' ) { |
1382 | - $placeholders = array_fill(0, count($array), $type); |
|
1383 | - return implode(', ', $placeholders); |
|
1382 | + $placeholders = array_fill( 0, count( $array ), $type ); |
|
1383 | + return implode( ', ', $placeholders ); |
|
1384 | 1384 | } |
1385 | 1385 | |
1386 | 1386 | public static function prepend_and_or_where( $starts_with = ' WHERE ', $where = '' ) { |
1387 | - if ( empty($where) ) { |
|
1387 | + if ( empty( $where ) ) { |
|
1388 | 1388 | return ''; |
1389 | 1389 | } |
1390 | 1390 | |
@@ -1430,7 +1430,7 @@ discard block |
||
1430 | 1430 | |
1431 | 1431 | public static function get_referer_info() { |
1432 | 1432 | _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::get_server_value' ); |
1433 | - return self::get_server_value('HTTP_REFERER'); |
|
1433 | + return self::get_server_value( 'HTTP_REFERER' ); |
|
1434 | 1434 | } |
1435 | 1435 | |
1436 | 1436 | /** |
@@ -1439,19 +1439,19 @@ discard block |
||
1439 | 1439 | public static function json_to_array( $json_vars ) { |
1440 | 1440 | $vars = array(); |
1441 | 1441 | foreach ( $json_vars as $jv ) { |
1442 | - $jv_name = explode('[', $jv['name']); |
|
1443 | - $last = count($jv_name) - 1; |
|
1442 | + $jv_name = explode( '[', $jv['name'] ); |
|
1443 | + $last = count( $jv_name ) - 1; |
|
1444 | 1444 | foreach ( $jv_name as $p => $n ) { |
1445 | - $name = trim($n, ']'); |
|
1446 | - if ( ! isset($l1) ) { |
|
1445 | + $name = trim( $n, ']' ); |
|
1446 | + if ( ! isset( $l1 ) ) { |
|
1447 | 1447 | $l1 = $name; |
1448 | 1448 | } |
1449 | 1449 | |
1450 | - if ( ! isset($l2) ) { |
|
1450 | + if ( ! isset( $l2 ) ) { |
|
1451 | 1451 | $l2 = $name; |
1452 | 1452 | } |
1453 | 1453 | |
1454 | - if ( ! isset($l3) ) { |
|
1454 | + if ( ! isset( $l3 ) ) { |
|
1455 | 1455 | $l3 = $name; |
1456 | 1456 | } |
1457 | 1457 | |
@@ -1465,24 +1465,24 @@ discard block |
||
1465 | 1465 | |
1466 | 1466 | case 1: |
1467 | 1467 | $l2 = $name; |
1468 | - self::add_value_to_array( $name, $l2, $this_val, $vars[ $l1 ] ); |
|
1468 | + self::add_value_to_array( $name, $l2, $this_val, $vars[$l1] ); |
|
1469 | 1469 | break; |
1470 | 1470 | |
1471 | 1471 | case 2: |
1472 | 1472 | $l3 = $name; |
1473 | - self::add_value_to_array( $name, $l3, $this_val, $vars[ $l1 ][ $l2 ] ); |
|
1473 | + self::add_value_to_array( $name, $l3, $this_val, $vars[$l1][$l2] ); |
|
1474 | 1474 | break; |
1475 | 1475 | |
1476 | 1476 | case 3: |
1477 | 1477 | $l4 = $name; |
1478 | - self::add_value_to_array( $name, $l4, $this_val, $vars[ $l1 ][ $l2 ][ $l3 ] ); |
|
1478 | + self::add_value_to_array( $name, $l4, $this_val, $vars[$l1][$l2][$l3] ); |
|
1479 | 1479 | break; |
1480 | 1480 | } |
1481 | 1481 | |
1482 | - unset($this_val, $n); |
|
1482 | + unset( $this_val, $n ); |
|
1483 | 1483 | } |
1484 | 1484 | |
1485 | - unset($last, $jv); |
|
1485 | + unset( $last, $jv ); |
|
1486 | 1486 | } |
1487 | 1487 | |
1488 | 1488 | return $vars; |
@@ -1495,8 +1495,8 @@ discard block |
||
1495 | 1495 | public static function add_value_to_array( $name, $l1, $val, &$vars ) { |
1496 | 1496 | if ( $name == '' ) { |
1497 | 1497 | $vars[] = $val; |
1498 | - } else if ( ! isset( $vars[ $l1 ] ) ) { |
|
1499 | - $vars[ $l1 ] = $val; |
|
1498 | + } else if ( ! isset( $vars[$l1] ) ) { |
|
1499 | + $vars[$l1] = $val; |
|
1500 | 1500 | } |
1501 | 1501 | } |
1502 | 1502 | |
@@ -1511,7 +1511,7 @@ discard block |
||
1511 | 1511 | 'email_subject' => esc_attr( sprintf( __( 'If you leave the subject blank, the default will be used: %1$s Form submitted on %2$s', 'formidable' ), $form_name, self::site_name() ) ), |
1512 | 1512 | ); |
1513 | 1513 | |
1514 | - if ( ! isset( $tooltips[ $name ] ) ) { |
|
1514 | + if ( ! isset( $tooltips[$name] ) ) { |
|
1515 | 1515 | return; |
1516 | 1516 | } |
1517 | 1517 | |
@@ -1521,7 +1521,7 @@ discard block |
||
1521 | 1521 | echo ' class="frm_help"'; |
1522 | 1522 | } |
1523 | 1523 | |
1524 | - echo ' title="'. esc_attr( $tooltips[ $name ] ); |
|
1524 | + echo ' title="' . esc_attr( $tooltips[$name] ); |
|
1525 | 1525 | |
1526 | 1526 | if ( 'open' != $class ) { |
1527 | 1527 | echo '"'; |
@@ -1570,13 +1570,13 @@ discard block |
||
1570 | 1570 | } |
1571 | 1571 | |
1572 | 1572 | private static function prepare_action_slashes( $val, $key, &$post_content ) { |
1573 | - if ( ! isset( $post_content[ $key ] ) ) { |
|
1573 | + if ( ! isset( $post_content[$key] ) ) { |
|
1574 | 1574 | return; |
1575 | 1575 | } |
1576 | 1576 | |
1577 | 1577 | if ( is_array( $val ) ) { |
1578 | 1578 | foreach ( $val as $k1 => $v1 ) { |
1579 | - self::prepare_action_slashes( $v1, $k1, $post_content[ $key ] ); |
|
1579 | + self::prepare_action_slashes( $v1, $k1, $post_content[$key] ); |
|
1580 | 1580 | unset( $k1, $v1 ); |
1581 | 1581 | } |
1582 | 1582 | } else { |
@@ -1584,7 +1584,7 @@ discard block |
||
1584 | 1584 | $val = stripslashes( $val ); |
1585 | 1585 | |
1586 | 1586 | // Add backslashes before double quotes and forward slashes only |
1587 | - $post_content[ $key ] = addcslashes( $val, '"\\/' ); |
|
1587 | + $post_content[$key] = addcslashes( $val, '"\\/' ); |
|
1588 | 1588 | } |
1589 | 1589 | } |
1590 | 1590 | |
@@ -1601,7 +1601,7 @@ discard block |
||
1601 | 1601 | $settings['post_content'] = FrmAppHelper::prepare_and_encode( $settings['post_content'] ); |
1602 | 1602 | |
1603 | 1603 | if ( empty( $settings['ID'] ) ) { |
1604 | - unset( $settings['ID']); |
|
1604 | + unset( $settings['ID'] ); |
|
1605 | 1605 | } |
1606 | 1606 | |
1607 | 1607 | // delete all caches for this group |
@@ -1635,17 +1635,17 @@ discard block |
||
1635 | 1635 | } |
1636 | 1636 | |
1637 | 1637 | public static function maybe_json_decode( $string ) { |
1638 | - if ( is_array($string) ) { |
|
1638 | + if ( is_array( $string ) ) { |
|
1639 | 1639 | return $string; |
1640 | 1640 | } |
1641 | 1641 | |
1642 | - $new_string = json_decode($string, true); |
|
1643 | - if ( function_exists('json_last_error') ) { |
|
1642 | + $new_string = json_decode( $string, true ); |
|
1643 | + if ( function_exists( 'json_last_error' ) ) { |
|
1644 | 1644 | // php 5.3+ |
1645 | 1645 | if ( json_last_error() == JSON_ERROR_NONE ) { |
1646 | 1646 | $string = $new_string; |
1647 | 1647 | } |
1648 | - } else if ( isset($new_string) ) { |
|
1648 | + } else if ( isset( $new_string ) ) { |
|
1649 | 1649 | // php < 5.3 fallback |
1650 | 1650 | $string = $new_string; |
1651 | 1651 | } |
@@ -1661,11 +1661,11 @@ discard block |
||
1661 | 1661 | public static function maybe_highlight_menu( $post_type ) { |
1662 | 1662 | global $post, $pagenow; |
1663 | 1663 | |
1664 | - if ( isset($_REQUEST['post_type']) && $_REQUEST['post_type'] != $post_type ) { |
|
1664 | + if ( isset( $_REQUEST['post_type'] ) && $_REQUEST['post_type'] != $post_type ) { |
|
1665 | 1665 | return; |
1666 | 1666 | } |
1667 | 1667 | |
1668 | - if ( is_object($post) && $post->post_type != $post_type ) { |
|
1668 | + if ( is_object( $post ) && $post->post_type != $post_type ) { |
|
1669 | 1669 | return; |
1670 | 1670 | } |
1671 | 1671 | |
@@ -1763,11 +1763,11 @@ discard block |
||
1763 | 1763 | $frm_version = self::plugin_version(); |
1764 | 1764 | |
1765 | 1765 | // check if Formidable meets minimum requirements |
1766 | - if ( version_compare($frm_version, $min_version, '>=') ) { |
|
1766 | + if ( version_compare( $frm_version, $min_version, '>=' ) ) { |
|
1767 | 1767 | return; |
1768 | 1768 | } |
1769 | 1769 | |
1770 | - $wp_list_table = _get_list_table('WP_Plugins_List_Table'); |
|
1770 | + $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
1771 | 1771 | echo '<tr class="plugin-update-tr active"><th colspan="' . absint( $wp_list_table->get_column_count() ) . '" class="check-column plugin-update colspanchange"><div class="update-message">' . |
1772 | 1772 | __( 'You are running an outdated version of Formidable. This plugin may not work correctly if you do not update Formidable.', 'formidable' ) . |
1773 | 1773 | '</div></td></tr>'; |
@@ -1775,38 +1775,38 @@ discard block |
||
1775 | 1775 | |
1776 | 1776 | public static function locales( $type = 'date' ) { |
1777 | 1777 | $locales = array( |
1778 | - 'en' => __( 'English', 'formidable' ), '' => __( 'English/Western', 'formidable' ), |
|
1779 | - 'af' => __( 'Afrikaans', 'formidable' ), 'sq' => __( 'Albanian', 'formidable' ), |
|
1780 | - 'ar' => __( 'Arabic', 'formidable' ), 'hy' => __( 'Armenian', 'formidable' ), |
|
1778 | + 'en' => __( 'English', 'formidable' ), '' => __( 'English/Western', 'formidable' ), |
|
1779 | + 'af' => __( 'Afrikaans', 'formidable' ), 'sq' => __( 'Albanian', 'formidable' ), |
|
1780 | + 'ar' => __( 'Arabic', 'formidable' ), 'hy' => __( 'Armenian', 'formidable' ), |
|
1781 | 1781 | 'az' => __( 'Azerbaijani', 'formidable' ), 'eu' => __( 'Basque', 'formidable' ), |
1782 | - 'bs' => __( 'Bosnian', 'formidable' ), 'bg' => __( 'Bulgarian', 'formidable' ), |
|
1783 | - 'ca' => __( 'Catalan', 'formidable' ), 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ), |
|
1782 | + 'bs' => __( 'Bosnian', 'formidable' ), 'bg' => __( 'Bulgarian', 'formidable' ), |
|
1783 | + 'ca' => __( 'Catalan', 'formidable' ), 'zh-HK' => __( 'Chinese Hong Kong', 'formidable' ), |
|
1784 | 1784 | 'zh-CN' => __( 'Chinese Simplified', 'formidable' ), 'zh-TW' => __( 'Chinese Traditional', 'formidable' ), |
1785 | - 'hr' => __( 'Croatian', 'formidable' ), 'cs' => __( 'Czech', 'formidable' ), |
|
1786 | - 'da' => __( 'Danish', 'formidable' ), 'nl' => __( 'Dutch', 'formidable' ), |
|
1785 | + 'hr' => __( 'Croatian', 'formidable' ), 'cs' => __( 'Czech', 'formidable' ), |
|
1786 | + 'da' => __( 'Danish', 'formidable' ), 'nl' => __( 'Dutch', 'formidable' ), |
|
1787 | 1787 | 'en-GB' => __( 'English/UK', 'formidable' ), 'eo' => __( 'Esperanto', 'formidable' ), |
1788 | - 'et' => __( 'Estonian', 'formidable' ), 'fo' => __( 'Faroese', 'formidable' ), |
|
1788 | + 'et' => __( 'Estonian', 'formidable' ), 'fo' => __( 'Faroese', 'formidable' ), |
|
1789 | 1789 | 'fa' => __( 'Farsi/Persian', 'formidable' ), 'fil' => __( 'Filipino', 'formidable' ), |
1790 | - 'fi' => __( 'Finnish', 'formidable' ), 'fr' => __( 'French', 'formidable' ), |
|
1790 | + 'fi' => __( 'Finnish', 'formidable' ), 'fr' => __( 'French', 'formidable' ), |
|
1791 | 1791 | 'fr-CA' => __( 'French/Canadian', 'formidable' ), 'fr-CH' => __( 'French/Swiss', 'formidable' ), |
1792 | - 'de' => __( 'German', 'formidable' ), 'de-AT' => __( 'German/Austria', 'formidable' ), |
|
1792 | + 'de' => __( 'German', 'formidable' ), 'de-AT' => __( 'German/Austria', 'formidable' ), |
|
1793 | 1793 | 'de-CH' => __( 'German/Switzerland', 'formidable' ), 'el' => __( 'Greek', 'formidable' ), |
1794 | - 'he' => __( 'Hebrew', 'formidable' ), 'iw' => __( 'Hebrew', 'formidable' ), |
|
1795 | - 'hi' => __( 'Hindi', 'formidable' ), 'hu' => __( 'Hungarian', 'formidable' ), |
|
1796 | - 'is' => __( 'Icelandic', 'formidable' ), 'id' => __( 'Indonesian', 'formidable' ), |
|
1797 | - 'it' => __( 'Italian', 'formidable' ), 'ja' => __( 'Japanese', 'formidable' ), |
|
1798 | - 'ko' => __( 'Korean', 'formidable' ), 'lv' => __( 'Latvian', 'formidable' ), |
|
1794 | + 'he' => __( 'Hebrew', 'formidable' ), 'iw' => __( 'Hebrew', 'formidable' ), |
|
1795 | + 'hi' => __( 'Hindi', 'formidable' ), 'hu' => __( 'Hungarian', 'formidable' ), |
|
1796 | + 'is' => __( 'Icelandic', 'formidable' ), 'id' => __( 'Indonesian', 'formidable' ), |
|
1797 | + 'it' => __( 'Italian', 'formidable' ), 'ja' => __( 'Japanese', 'formidable' ), |
|
1798 | + 'ko' => __( 'Korean', 'formidable' ), 'lv' => __( 'Latvian', 'formidable' ), |
|
1799 | 1799 | 'lt' => __( 'Lithuanian', 'formidable' ), 'ms' => __( 'Malaysian', 'formidable' ), |
1800 | - 'no' => __( 'Norwegian', 'formidable' ), 'pl' => __( 'Polish', 'formidable' ), |
|
1800 | + 'no' => __( 'Norwegian', 'formidable' ), 'pl' => __( 'Polish', 'formidable' ), |
|
1801 | 1801 | 'pt' => __( 'Portuguese', 'formidable' ), 'pt-BR' => __( 'Portuguese/Brazilian', 'formidable' ), |
1802 | 1802 | 'pt-PT' => __( 'Portuguese/Portugal', 'formidable' ), 'ro' => __( 'Romanian', 'formidable' ), |
1803 | - 'ru' => __( 'Russian', 'formidable' ), 'sr' => __( 'Serbian', 'formidable' ), |
|
1803 | + 'ru' => __( 'Russian', 'formidable' ), 'sr' => __( 'Serbian', 'formidable' ), |
|
1804 | 1804 | 'sr-SR' => __( 'Serbian', 'formidable' ), 'sk' => __( 'Slovak', 'formidable' ), |
1805 | - 'sl' => __( 'Slovenian', 'formidable' ), 'es' => __( 'Spanish', 'formidable' ), |
|
1805 | + 'sl' => __( 'Slovenian', 'formidable' ), 'es' => __( 'Spanish', 'formidable' ), |
|
1806 | 1806 | 'es-419' => __( 'Spanish/Latin America', 'formidable' ), 'sv' => __( 'Swedish', 'formidable' ), |
1807 | - 'ta' => __( 'Tamil', 'formidable' ), 'th' => __( 'Thai', 'formidable' ), |
|
1808 | - 'tu' => __( 'Turkish', 'formidable' ), 'tr' => __( 'Turkish', 'formidable' ), |
|
1809 | - 'uk' => __( 'Ukranian', 'formidable' ), 'vi' => __( 'Vietnamese', 'formidable' ), |
|
1807 | + 'ta' => __( 'Tamil', 'formidable' ), 'th' => __( 'Thai', 'formidable' ), |
|
1808 | + 'tu' => __( 'Turkish', 'formidable' ), 'tr' => __( 'Turkish', 'formidable' ), |
|
1809 | + 'uk' => __( 'Ukranian', 'formidable' ), 'vi' => __( 'Vietnamese', 'formidable' ), |
|
1810 | 1810 | ); |
1811 | 1811 | |
1812 | 1812 | if ( $type == 'captcha' ) { |
@@ -1825,8 +1825,8 @@ discard block |
||
1825 | 1825 | ); |
1826 | 1826 | } |
1827 | 1827 | |
1828 | - $locales = array_diff_key($locales, array_flip($unset)); |
|
1829 | - $locales = apply_filters('frm_locales', $locales); |
|
1828 | + $locales = array_diff_key( $locales, array_flip( $unset ) ); |
|
1829 | + $locales = apply_filters( 'frm_locales', $locales ); |
|
1830 | 1830 | |
1831 | 1831 | return $locales; |
1832 | 1832 | } |
@@ -69,7 +69,7 @@ |
||
69 | 69 | * @uses api_request() |
70 | 70 | * |
71 | 71 | * @param array $_transient_data Update array build by WordPress. |
72 | - * @return array Modified update array with custom plugin data. |
|
72 | + * @return stdClass Modified update array with custom plugin data. |
|
73 | 73 | */ |
74 | 74 | public function check_update( $_transient_data ) { |
75 | 75 |
@@ -15,184 +15,184 @@ discard block |
||
15 | 15 | * @version 1.6 |
16 | 16 | */ |
17 | 17 | class EDD_SL_Plugin_Updater { |
18 | - private $api_url = ''; |
|
19 | - private $api_data = array(); |
|
20 | - private $name = ''; |
|
21 | - private $slug = ''; |
|
22 | - private $version = ''; |
|
23 | - |
|
24 | - /** |
|
25 | - * Class constructor. |
|
26 | - * |
|
27 | - * @uses plugin_basename() |
|
28 | - * @uses hook() |
|
29 | - * |
|
30 | - * @param string $_api_url The URL pointing to the custom API endpoint. |
|
31 | - * @param string $_plugin_file Path to the plugin file. |
|
32 | - * @param array $_api_data Optional data to send with API calls. |
|
33 | - */ |
|
34 | - public function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
35 | - $this->api_url = trailingslashit( $_api_url ); |
|
36 | - $this->api_data = $_api_data; |
|
37 | - $this->name = plugin_basename( $_plugin_file ); |
|
38 | - $this->slug = basename( $_plugin_file, '.php' ); |
|
39 | - $this->version = $_api_data['version']; |
|
40 | - |
|
41 | - // Set up hooks. |
|
42 | - $this->init(); |
|
43 | - add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Set up WordPress filters to hook into WP's update process. |
|
48 | - * |
|
49 | - * @uses add_filter() |
|
50 | - * |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function init() { |
|
54 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
55 | - add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Check for Updates at the defined API endpoint and modify the update array. |
|
60 | - * |
|
61 | - * This function dives into the update API just when WordPress creates its update array, |
|
62 | - * then adds a custom API call and injects the custom plugin data retrieved from the API. |
|
63 | - * It is reassembled from parts of the native WordPress plugin update code. |
|
64 | - * See wp-includes/update.php line 121 for the original wp_update_plugins() function. |
|
65 | - * |
|
66 | - * @uses api_request() |
|
67 | - * |
|
68 | - * @param array $_transient_data Update array build by WordPress. |
|
69 | - * @return array Modified update array with custom plugin data. |
|
70 | - */ |
|
71 | - public function check_update( $_transient_data ) { |
|
72 | - |
|
73 | - global $pagenow; |
|
74 | - |
|
75 | - if ( ! is_object( $_transient_data ) ) { |
|
76 | - $_transient_data = new stdClass; |
|
77 | - } |
|
78 | - |
|
79 | - if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
80 | - |
|
81 | - $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
82 | - |
|
83 | - if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
84 | - |
|
85 | - if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
86 | - |
|
87 | - if ( empty( $version_info->plugin ) ) { |
|
88 | - $version_info->plugin = $this->name; |
|
89 | - } |
|
18 | + private $api_url = ''; |
|
19 | + private $api_data = array(); |
|
20 | + private $name = ''; |
|
21 | + private $slug = ''; |
|
22 | + private $version = ''; |
|
23 | + |
|
24 | + /** |
|
25 | + * Class constructor. |
|
26 | + * |
|
27 | + * @uses plugin_basename() |
|
28 | + * @uses hook() |
|
29 | + * |
|
30 | + * @param string $_api_url The URL pointing to the custom API endpoint. |
|
31 | + * @param string $_plugin_file Path to the plugin file. |
|
32 | + * @param array $_api_data Optional data to send with API calls. |
|
33 | + */ |
|
34 | + public function __construct( $_api_url, $_plugin_file, $_api_data = null ) { |
|
35 | + $this->api_url = trailingslashit( $_api_url ); |
|
36 | + $this->api_data = $_api_data; |
|
37 | + $this->name = plugin_basename( $_plugin_file ); |
|
38 | + $this->slug = basename( $_plugin_file, '.php' ); |
|
39 | + $this->version = $_api_data['version']; |
|
40 | + |
|
41 | + // Set up hooks. |
|
42 | + $this->init(); |
|
43 | + add_action( 'admin_init', array( $this, 'show_changelog' ) ); |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Set up WordPress filters to hook into WP's update process. |
|
48 | + * |
|
49 | + * @uses add_filter() |
|
50 | + * |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function init() { |
|
54 | + add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); |
|
55 | + add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 ); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Check for Updates at the defined API endpoint and modify the update array. |
|
60 | + * |
|
61 | + * This function dives into the update API just when WordPress creates its update array, |
|
62 | + * then adds a custom API call and injects the custom plugin data retrieved from the API. |
|
63 | + * It is reassembled from parts of the native WordPress plugin update code. |
|
64 | + * See wp-includes/update.php line 121 for the original wp_update_plugins() function. |
|
65 | + * |
|
66 | + * @uses api_request() |
|
67 | + * |
|
68 | + * @param array $_transient_data Update array build by WordPress. |
|
69 | + * @return array Modified update array with custom plugin data. |
|
70 | + */ |
|
71 | + public function check_update( $_transient_data ) { |
|
72 | + |
|
73 | + global $pagenow; |
|
74 | + |
|
75 | + if ( ! is_object( $_transient_data ) ) { |
|
76 | + $_transient_data = new stdClass; |
|
77 | + } |
|
90 | 78 | |
91 | - $_transient_data->response[ $this->name ] = $version_info; |
|
79 | + if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
92 | 80 | |
93 | - } |
|
94 | - |
|
95 | - $_transient_data->last_checked = time(); |
|
96 | - $_transient_data->checked[ $this->name ] = $this->version; |
|
81 | + $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
|
97 | 82 | |
98 | - } |
|
99 | - } |
|
83 | + if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
|
100 | 84 | |
101 | - return $_transient_data; |
|
102 | - } |
|
85 | + if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
|
103 | 86 | |
104 | - /** |
|
105 | - * Updates information on the "View version x.x details" page with custom data. |
|
106 | - * |
|
107 | - * @uses api_request() |
|
108 | - * |
|
109 | - * @param mixed $_data |
|
110 | - * @param string $_action |
|
111 | - * @param object $_args |
|
112 | - * @return object $_data |
|
113 | - */ |
|
114 | - public function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
87 | + if ( empty( $version_info->plugin ) ) { |
|
88 | + $version_info->plugin = $this->name; |
|
89 | + } |
|
115 | 90 | |
116 | - if ( $_action != 'plugin_information' ) { |
|
91 | + $_transient_data->response[ $this->name ] = $version_info; |
|
117 | 92 | |
118 | - return $_data; |
|
93 | + } |
|
119 | 94 | |
120 | - } |
|
95 | + $_transient_data->last_checked = time(); |
|
96 | + $_transient_data->checked[ $this->name ] = $this->version; |
|
121 | 97 | |
122 | - if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
98 | + } |
|
99 | + } |
|
123 | 100 | |
124 | - return $_data; |
|
101 | + return $_transient_data; |
|
102 | + } |
|
125 | 103 | |
126 | - } |
|
104 | + /** |
|
105 | + * Updates information on the "View version x.x details" page with custom data. |
|
106 | + * |
|
107 | + * @uses api_request() |
|
108 | + * |
|
109 | + * @param mixed $_data |
|
110 | + * @param string $_action |
|
111 | + * @param object $_args |
|
112 | + * @return object $_data |
|
113 | + */ |
|
114 | + public function plugins_api_filter( $_data, $_action = '', $_args = null ) { |
|
127 | 115 | |
128 | - $to_send = array( |
|
129 | - 'slug' => $this->slug, |
|
130 | - 'is_ssl' => is_ssl(), |
|
131 | - 'fields' => array( |
|
132 | - 'banners' => false, // These will be supported soon hopefully |
|
133 | - 'reviews' => false, |
|
134 | - ), |
|
135 | - ); |
|
116 | + if ( $_action != 'plugin_information' ) { |
|
136 | 117 | |
137 | - $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
118 | + return $_data; |
|
138 | 119 | |
139 | - if ( false !== $api_response ) { |
|
140 | - $_data = $api_response; |
|
141 | - } |
|
120 | + } |
|
142 | 121 | |
143 | - return $_data; |
|
144 | - } |
|
122 | + if ( ! isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) { |
|
145 | 123 | |
124 | + return $_data; |
|
146 | 125 | |
147 | - /** |
|
148 | - * Disable SSL verification in order to prevent download update failures |
|
149 | - * |
|
150 | - * @param array $args |
|
151 | - * @param string $url |
|
152 | - * @return object $array |
|
153 | - */ |
|
154 | - public function http_request_args( $args, $url ) { |
|
155 | - // If it is an https request and we are performing a package download, disable ssl verification |
|
156 | - if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
157 | - $args['sslverify'] = false; |
|
158 | - } |
|
159 | - return $args; |
|
160 | - } |
|
126 | + } |
|
161 | 127 | |
162 | - /** |
|
163 | - * Calls the API and, if successfull, returns the object delivered by the API. |
|
164 | - * |
|
165 | - * @uses get_bloginfo() |
|
166 | - * @uses wp_remote_post() |
|
167 | - * @uses is_wp_error() |
|
168 | - * |
|
169 | - * @param string $_action The requested action. |
|
170 | - * @param array $_data Parameters for the API action. |
|
171 | - * @return false|object |
|
172 | - */ |
|
173 | - private function api_request( $_action, $_data ) { |
|
128 | + $to_send = array( |
|
129 | + 'slug' => $this->slug, |
|
130 | + 'is_ssl' => is_ssl(), |
|
131 | + 'fields' => array( |
|
132 | + 'banners' => false, // These will be supported soon hopefully |
|
133 | + 'reviews' => false, |
|
134 | + ), |
|
135 | + ); |
|
174 | 136 | |
175 | - global $wp_version; |
|
137 | + $api_response = $this->api_request( 'plugin_information', $to_send ); |
|
176 | 138 | |
177 | - $data = array_merge( $this->api_data, $_data ); |
|
139 | + if ( false !== $api_response ) { |
|
140 | + $_data = $api_response; |
|
141 | + } |
|
178 | 142 | |
179 | - if ( $data['slug'] != $this->slug ) { |
|
180 | - return; |
|
143 | + return $_data; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * Disable SSL verification in order to prevent download update failures |
|
149 | + * |
|
150 | + * @param array $args |
|
151 | + * @param string $url |
|
152 | + * @return object $array |
|
153 | + */ |
|
154 | + public function http_request_args( $args, $url ) { |
|
155 | + // If it is an https request and we are performing a package download, disable ssl verification |
|
156 | + if ( strpos( $url, 'https://' ) !== false && strpos( $url, 'edd_action=package_download' ) ) { |
|
157 | + $args['sslverify'] = false; |
|
158 | + } |
|
159 | + return $args; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Calls the API and, if successfull, returns the object delivered by the API. |
|
164 | + * |
|
165 | + * @uses get_bloginfo() |
|
166 | + * @uses wp_remote_post() |
|
167 | + * @uses is_wp_error() |
|
168 | + * |
|
169 | + * @param string $_action The requested action. |
|
170 | + * @param array $_data Parameters for the API action. |
|
171 | + * @return false|object |
|
172 | + */ |
|
173 | + private function api_request( $_action, $_data ) { |
|
174 | + |
|
175 | + global $wp_version; |
|
176 | + |
|
177 | + $data = array_merge( $this->api_data, $_data ); |
|
178 | + |
|
179 | + if ( $data['slug'] != $this->slug ) { |
|
180 | + return; |
|
181 | 181 | } |
182 | 182 | |
183 | - if ( $this->api_url == home_url() ) { |
|
184 | - return false; // Don't allow a plugin to ping itself |
|
185 | - } |
|
183 | + if ( $this->api_url == home_url() ) { |
|
184 | + return false; // Don't allow a plugin to ping itself |
|
185 | + } |
|
186 | 186 | |
187 | - $api_params = array( |
|
188 | - 'edd_action' => 'get_version', |
|
189 | - 'license' => ! empty( $data['license'] ) ? $data['license'] : '', |
|
190 | - 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
191 | - 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
192 | - 'slug' => $data['slug'], |
|
193 | - 'author' => $data['author'], |
|
194 | - 'url' => home_url(), |
|
195 | - ); |
|
187 | + $api_params = array( |
|
188 | + 'edd_action' => 'get_version', |
|
189 | + 'license' => ! empty( $data['license'] ) ? $data['license'] : '', |
|
190 | + 'item_name' => isset( $data['item_name'] ) ? $data['item_name'] : false, |
|
191 | + 'item_id' => isset( $data['item_id'] ) ? $data['item_id'] : false, |
|
192 | + 'slug' => $data['slug'], |
|
193 | + 'author' => $data['author'], |
|
194 | + 'url' => home_url(), |
|
195 | + ); |
|
196 | 196 | |
197 | 197 | $cache_key = 'edd_plugin_' . md5( sanitize_key( $api_params['license'] . $this->version ) . '_' . $api_params['edd_action'] ); |
198 | 198 | $cached_response = get_transient( $cache_key ); |
@@ -201,47 +201,47 @@ discard block |
||
201 | 201 | return $cached_response; |
202 | 202 | } |
203 | 203 | |
204 | - $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
204 | + $request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) ); |
|
205 | 205 | |
206 | - if ( ! is_wp_error( $request ) ) { |
|
207 | - $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
208 | - } |
|
206 | + if ( ! is_wp_error( $request ) ) { |
|
207 | + $request = json_decode( wp_remote_retrieve_body( $request ) ); |
|
208 | + } |
|
209 | 209 | |
210 | - if ( $request && isset( $request->sections ) ) { |
|
211 | - $request->sections = maybe_unserialize( $request->sections ); |
|
210 | + if ( $request && isset( $request->sections ) ) { |
|
211 | + $request->sections = maybe_unserialize( $request->sections ); |
|
212 | 212 | set_transient( $cache_key, $request, DAY_IN_SECONDS ); |
213 | - } else { |
|
214 | - $request = false; |
|
213 | + } else { |
|
214 | + $request = false; |
|
215 | 215 | set_transient( $cache_key, 0, DAY_IN_SECONDS ); |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - return $request; |
|
219 | - } |
|
218 | + return $request; |
|
219 | + } |
|
220 | 220 | |
221 | - public function show_changelog() { |
|
221 | + public function show_changelog() { |
|
222 | 222 | |
223 | - if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
224 | - return; |
|
225 | - } |
|
223 | + if ( empty( $_REQUEST['edd_sl_action'] ) || 'view_plugin_changelog' != $_REQUEST['edd_sl_action'] ) { |
|
224 | + return; |
|
225 | + } |
|
226 | 226 | |
227 | - if ( empty( $_REQUEST['plugin'] ) ) { |
|
228 | - return; |
|
229 | - } |
|
227 | + if ( empty( $_REQUEST['plugin'] ) ) { |
|
228 | + return; |
|
229 | + } |
|
230 | 230 | |
231 | - if ( empty( $_REQUEST['slug'] ) ) { |
|
232 | - return; |
|
233 | - } |
|
231 | + if ( empty( $_REQUEST['slug'] ) ) { |
|
232 | + return; |
|
233 | + } |
|
234 | 234 | |
235 | - if ( ! current_user_can( 'update_plugins' ) ) { |
|
236 | - wp_die( __( 'You do not have permission to install plugin updates', 'edd' ), __( 'Error', 'edd' ), array( 'response' => 403 ) ); |
|
237 | - } |
|
235 | + if ( ! current_user_can( 'update_plugins' ) ) { |
|
236 | + wp_die( __( 'You do not have permission to install plugin updates', 'edd' ), __( 'Error', 'edd' ), array( 'response' => 403 ) ); |
|
237 | + } |
|
238 | 238 | |
239 | - $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
239 | + $response = $this->api_request( 'plugin_latest_version', array( 'slug' => $_REQUEST['slug'] ) ); |
|
240 | 240 | |
241 | - if ( $response && isset( $response->sections['changelog'] ) ) { |
|
242 | - echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
243 | - } |
|
241 | + if ( $response && isset( $response->sections['changelog'] ) ) { |
|
242 | + echo '<div style="background:#fff;padding:10px;">' . $response->sections['changelog'] . '</div>'; |
|
243 | + } |
|
244 | 244 | |
245 | - exit; |
|
246 | - } |
|
245 | + exit; |
|
246 | + } |
|
247 | 247 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | $_transient_data = new stdClass; |
77 | 77 | } |
78 | 78 | |
79 | - if ( empty( $_transient_data->response ) || empty( $_transient_data->response[ $this->name ] ) ) { |
|
79 | + if ( empty( $_transient_data->response ) || empty( $_transient_data->response[$this->name] ) ) { |
|
80 | 80 | |
81 | 81 | $version_info = $this->api_request( 'plugin_latest_version', array( 'slug' => $this->slug ) ); |
82 | 82 | |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | $version_info->plugin = $this->name; |
89 | 89 | } |
90 | 90 | |
91 | - $_transient_data->response[ $this->name ] = $version_info; |
|
91 | + $_transient_data->response[$this->name] = $version_info; |
|
92 | 92 | |
93 | 93 | } |
94 | 94 | |
95 | 95 | $_transient_data->last_checked = time(); |
96 | - $_transient_data->checked[ $this->name ] = $this->version; |
|
96 | + $_transient_data->checked[$this->name] = $this->version; |
|
97 | 97 | |
98 | 98 | } |
99 | 99 | } |
@@ -61,6 +61,9 @@ discard block |
||
61 | 61 | return $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values ); |
62 | 62 | } |
63 | 63 | |
64 | + /** |
|
65 | + * @param integer $entry_id |
|
66 | + */ |
|
64 | 67 | public static function update_entry_metas( $entry_id, $values ) { |
65 | 68 | global $wpdb; |
66 | 69 | |
@@ -286,6 +289,7 @@ discard block |
||
286 | 289 | * @param string|array $where |
287 | 290 | * @param string $order_by |
288 | 291 | * @param string $limit |
292 | + * @param boolean $unique |
|
289 | 293 | */ |
290 | 294 | private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) { |
291 | 295 | global $wpdb; |
@@ -5,27 +5,27 @@ discard block |
||
5 | 5 | |
6 | 6 | class FrmEntryMeta { |
7 | 7 | |
8 | - /** |
|
9 | - * @param string $meta_key |
|
10 | - */ |
|
8 | + /** |
|
9 | + * @param string $meta_key |
|
10 | + */ |
|
11 | 11 | public static function add_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) { |
12 | - global $wpdb; |
|
12 | + global $wpdb; |
|
13 | 13 | |
14 | - if ( FrmAppHelper::is_empty_value( $meta_value ) ) { |
|
15 | - // don't save blank fields |
|
16 | - return; |
|
17 | - } |
|
14 | + if ( FrmAppHelper::is_empty_value( $meta_value ) ) { |
|
15 | + // don't save blank fields |
|
16 | + return; |
|
17 | + } |
|
18 | 18 | |
19 | - $new_values = array( |
|
19 | + $new_values = array( |
|
20 | 20 | 'meta_value' => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ), |
21 | - 'item_id' => $entry_id, |
|
22 | - 'field_id' => $field_id, |
|
23 | - 'created_at' => current_time('mysql', 1), |
|
24 | - ); |
|
21 | + 'item_id' => $entry_id, |
|
22 | + 'field_id' => $field_id, |
|
23 | + 'created_at' => current_time('mysql', 1), |
|
24 | + ); |
|
25 | 25 | |
26 | - $new_values = apply_filters('frm_add_entry_meta', $new_values); |
|
26 | + $new_values = apply_filters('frm_add_entry_meta', $new_values); |
|
27 | 27 | |
28 | - $query_results = $wpdb->insert( $wpdb->prefix .'frm_item_metas', $new_values ); |
|
28 | + $query_results = $wpdb->insert( $wpdb->prefix .'frm_item_metas', $new_values ); |
|
29 | 29 | |
30 | 30 | if ( $query_results ) { |
31 | 31 | self::clear_cache(); |
@@ -34,89 +34,89 @@ discard block |
||
34 | 34 | $id = 0; |
35 | 35 | } |
36 | 36 | |
37 | - return $id; |
|
38 | - } |
|
37 | + return $id; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param string $meta_key |
|
42 | - */ |
|
40 | + /** |
|
41 | + * @param string $meta_key |
|
42 | + */ |
|
43 | 43 | public static function update_entry_meta( $entry_id, $field_id, $meta_key = null, $meta_value ) { |
44 | - if ( ! $field_id ) { |
|
45 | - return false; |
|
46 | - } |
|
44 | + if ( ! $field_id ) { |
|
45 | + return false; |
|
46 | + } |
|
47 | 47 | |
48 | - global $wpdb; |
|
48 | + global $wpdb; |
|
49 | 49 | |
50 | - $values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id ); |
|
51 | - $values['meta_value'] = $meta_value; |
|
52 | - $values = apply_filters('frm_update_entry_meta', $values); |
|
50 | + $values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id ); |
|
51 | + $values['meta_value'] = $meta_value; |
|
52 | + $values = apply_filters('frm_update_entry_meta', $values); |
|
53 | 53 | if ( is_array($values['meta_value']) ) { |
54 | 54 | $values['meta_value'] = array_filter( $values['meta_value'], 'FrmAppHelper::is_not_empty_value' ); |
55 | 55 | } |
56 | - $meta_value = maybe_serialize($values['meta_value']); |
|
56 | + $meta_value = maybe_serialize($values['meta_value']); |
|
57 | 57 | |
58 | - wp_cache_delete( $entry_id, 'frm_entry'); |
|
58 | + wp_cache_delete( $entry_id, 'frm_entry'); |
|
59 | 59 | self::clear_cache(); |
60 | 60 | |
61 | - return $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values ); |
|
62 | - } |
|
61 | + return $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values ); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | public static function update_entry_metas( $entry_id, $values ) { |
65 | - global $wpdb; |
|
65 | + global $wpdb; |
|
66 | 66 | |
67 | 67 | $prev_values = FrmDb::get_col( $wpdb->prefix .'frm_item_metas', array( 'item_id' => $entry_id, 'field_id !' => 0 ), 'field_id' ); |
68 | 68 | |
69 | - foreach ( $values as $field_id => $meta_value ) { |
|
70 | - // set the value for the file upload field and add new tags (in Pro version) |
|
71 | - $values = apply_filters( 'frm_prepare_data_before_db', $values, $field_id, $entry_id ); |
|
69 | + foreach ( $values as $field_id => $meta_value ) { |
|
70 | + // set the value for the file upload field and add new tags (in Pro version) |
|
71 | + $values = apply_filters( 'frm_prepare_data_before_db', $values, $field_id, $entry_id ); |
|
72 | 72 | |
73 | - if ( $prev_values && in_array($field_id, $prev_values) ) { |
|
74 | - if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) { |
|
75 | - // remove blank fields |
|
73 | + if ( $prev_values && in_array($field_id, $prev_values) ) { |
|
74 | + if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) { |
|
75 | + // remove blank fields |
|
76 | 76 | unset( $values[ $field_id ] ); |
77 | - } else { |
|
78 | - // if value exists, then update it |
|
77 | + } else { |
|
78 | + // if value exists, then update it |
|
79 | 79 | self::update_entry_meta( $entry_id, $field_id, '', $values[ $field_id ] ); |
80 | - } |
|
81 | - } else { |
|
82 | - // if value does not exist, then create it |
|
80 | + } |
|
81 | + } else { |
|
82 | + // if value does not exist, then create it |
|
83 | 83 | self::add_entry_meta( $entry_id, $field_id, '', $values[ $field_id ] ); |
84 | - } |
|
85 | - } |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - if ( empty($prev_values) ) { |
|
88 | - return; |
|
89 | - } |
|
87 | + if ( empty($prev_values) ) { |
|
88 | + return; |
|
89 | + } |
|
90 | 90 | |
91 | - $prev_values = array_diff($prev_values, array_keys($values)); |
|
91 | + $prev_values = array_diff($prev_values, array_keys($values)); |
|
92 | 92 | |
93 | - if ( empty($prev_values) ) { |
|
94 | - return; |
|
95 | - } |
|
93 | + if ( empty($prev_values) ) { |
|
94 | + return; |
|
95 | + } |
|
96 | 96 | |
97 | 97 | // prepare the query |
98 | 98 | $where = array( 'item_id' => $entry_id, 'field_id' => $prev_values ); |
99 | 99 | FrmDb::get_where_clause_and_values( $where ); |
100 | 100 | |
101 | - // Delete any leftovers |
|
102 | - $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) ); |
|
101 | + // Delete any leftovers |
|
102 | + $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'] ) ); |
|
103 | 103 | self::clear_cache(); |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | 106 | public static function duplicate_entry_metas( $old_id, $new_id ) { |
107 | - $metas = self::get_entry_meta_info($old_id); |
|
108 | - foreach ( $metas as $meta ) { |
|
109 | - self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value); |
|
110 | - unset($meta); |
|
111 | - } |
|
107 | + $metas = self::get_entry_meta_info($old_id); |
|
108 | + foreach ( $metas as $meta ) { |
|
109 | + self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value); |
|
110 | + unset($meta); |
|
111 | + } |
|
112 | 112 | self::clear_cache(); |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | 115 | public static function delete_entry_meta( $entry_id, $field_id ) { |
116 | - global $wpdb; |
|
116 | + global $wpdb; |
|
117 | 117 | self::clear_cache(); |
118 | - return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id)); |
|
119 | - } |
|
118 | + return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id)); |
|
119 | + } |
|
120 | 120 | |
121 | 121 | /** |
122 | 122 | * Clear entry meta caching |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | } |
142 | 142 | |
143 | 143 | public static function get_entry_meta_by_field( $entry_id, $field_id ) { |
144 | - global $wpdb; |
|
144 | + global $wpdb; |
|
145 | 145 | |
146 | 146 | if ( is_object( $entry_id ) ) { |
147 | 147 | $entry = $entry_id; |
@@ -154,24 +154,24 @@ discard block |
||
154 | 154 | |
155 | 155 | if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) { |
156 | 156 | $result = $cached->metas[ $field_id ]; |
157 | - return stripslashes_deep($result); |
|
158 | - } |
|
157 | + return stripslashes_deep($result); |
|
158 | + } |
|
159 | 159 | |
160 | 160 | $get_table = $wpdb->prefix .'frm_item_metas'; |
161 | 161 | $query = array( 'item_id' => $entry_id ); |
162 | - if ( is_numeric($field_id) ) { |
|
162 | + if ( is_numeric($field_id) ) { |
|
163 | 163 | $query['field_id'] = $field_id; |
164 | - } else { |
|
164 | + } else { |
|
165 | 165 | $get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id'; |
166 | 166 | $query['fi.field_key'] = $field_id; |
167 | - } |
|
167 | + } |
|
168 | 168 | |
169 | 169 | $result = FrmDb::get_var( $get_table, $query, 'meta_value' ); |
170 | - $result = maybe_unserialize($result); |
|
171 | - $result = stripslashes_deep($result); |
|
170 | + $result = maybe_unserialize($result); |
|
171 | + $result = stripslashes_deep($result); |
|
172 | 172 | |
173 | - return $result; |
|
174 | - } |
|
173 | + return $result; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | public static function get_entry_meta( $entry_id, $field_id ) { |
177 | 177 | _deprecated_function( __FUNCTION__, '2.0', 'FrmEntryMeta::get_entry_meta_by_field' ); |
@@ -179,117 +179,117 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | public static function get_entry_metas( $entry_id ) { |
182 | - _deprecated_function( __FUNCTION__, '1.07.10'); |
|
182 | + _deprecated_function( __FUNCTION__, '1.07.10'); |
|
183 | 183 | |
184 | - global $wpdb; |
|
184 | + global $wpdb; |
|
185 | 185 | return FrmDb::get_col( $wpdb->prefix . 'frm_item_metas', array( 'item_id' => $entry_id ), 'meta_value' ); |
186 | - } |
|
186 | + } |
|
187 | 187 | |
188 | - public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) { |
|
188 | + public static function get_entry_metas_for_field( $field_id, $order = '', $limit = '', $args = array() ) { |
|
189 | 189 | $defaults = array( 'value' => false, 'unique' => false, 'stripslashes' => true, 'is_draft' => false ); |
190 | - $args = wp_parse_args( $args, $defaults ); |
|
190 | + $args = wp_parse_args( $args, $defaults ); |
|
191 | 191 | |
192 | - $query = array(); |
|
193 | - self::meta_field_query($field_id, $order, $limit, $args, $query); |
|
194 | - $query = implode(' ', $query); |
|
192 | + $query = array(); |
|
193 | + self::meta_field_query($field_id, $order, $limit, $args, $query); |
|
194 | + $query = implode(' ', $query); |
|
195 | 195 | |
196 | - $cache_key = 'entry_metas_for_field_'. $field_id . $order . $limit . maybe_serialize($args); |
|
197 | - $values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col'); |
|
196 | + $cache_key = 'entry_metas_for_field_'. $field_id . $order . $limit . maybe_serialize($args); |
|
197 | + $values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col'); |
|
198 | 198 | |
199 | - if ( ! $args['stripslashes'] ) { |
|
200 | - return $values; |
|
201 | - } |
|
199 | + if ( ! $args['stripslashes'] ) { |
|
200 | + return $values; |
|
201 | + } |
|
202 | 202 | |
203 | 203 | foreach ( $values as $k => $v ) { |
204 | 204 | $values[ $k ] = maybe_unserialize( $v ); |
205 | - unset($k, $v); |
|
206 | - } |
|
205 | + unset($k, $v); |
|
206 | + } |
|
207 | 207 | |
208 | - return stripslashes_deep($values); |
|
209 | - } |
|
208 | + return stripslashes_deep($values); |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * @param string $order |
|
213 | - * @param string $limit |
|
214 | - */ |
|
211 | + /** |
|
212 | + * @param string $order |
|
213 | + * @param string $limit |
|
214 | + */ |
|
215 | 215 | private static function meta_field_query( $field_id, $order, $limit, $args, array &$query ) { |
216 | - global $wpdb; |
|
217 | - $query[] = 'SELECT'; |
|
218 | - $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value'; |
|
219 | - $query[] = 'FROM '. $wpdb->prefix .'frm_item_metas em '; |
|
220 | - |
|
221 | - if ( ! $args['is_draft'] ) { |
|
222 | - $query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=em.item_id)'; |
|
223 | - } |
|
224 | - |
|
225 | - if ( is_numeric($field_id) ) { |
|
226 | - $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id); |
|
227 | - } else { |
|
228 | - $query[] = $wpdb->prepare('LEFT JOIN '. $wpdb->prefix .'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id); |
|
229 | - } |
|
230 | - |
|
231 | - if ( ! $args['is_draft'] ) { |
|
232 | - $query[] = 'AND e.is_draft=0'; |
|
233 | - } |
|
234 | - |
|
235 | - if ( $args['value'] ) { |
|
236 | - $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']); |
|
237 | - } |
|
238 | - $query[] = $order . $limit; |
|
239 | - } |
|
216 | + global $wpdb; |
|
217 | + $query[] = 'SELECT'; |
|
218 | + $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value'; |
|
219 | + $query[] = 'FROM '. $wpdb->prefix .'frm_item_metas em '; |
|
220 | + |
|
221 | + if ( ! $args['is_draft'] ) { |
|
222 | + $query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=em.item_id)'; |
|
223 | + } |
|
224 | + |
|
225 | + if ( is_numeric($field_id) ) { |
|
226 | + $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id); |
|
227 | + } else { |
|
228 | + $query[] = $wpdb->prepare('LEFT JOIN '. $wpdb->prefix .'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id); |
|
229 | + } |
|
230 | + |
|
231 | + if ( ! $args['is_draft'] ) { |
|
232 | + $query[] = 'AND e.is_draft=0'; |
|
233 | + } |
|
234 | + |
|
235 | + if ( $args['value'] ) { |
|
236 | + $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']); |
|
237 | + } |
|
238 | + $query[] = $order . $limit; |
|
239 | + } |
|
240 | 240 | |
241 | 241 | public static function get_entry_meta_info( $entry_id ) { |
242 | 242 | return FrmDb::get_results( 'frm_item_metas', array( 'item_id' => $entry_id ) ); |
243 | - } |
|
243 | + } |
|
244 | 244 | |
245 | 245 | public static function getAll( $where = array(), $order_by = '', $limit = '', $stripslashes = false ) { |
246 | - global $wpdb; |
|
247 | - $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key, |
|
246 | + global $wpdb; |
|
247 | + $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key, |
|
248 | 248 | fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options |
249 | 249 | FROM '. $wpdb->prefix .'frm_item_metas it LEFT OUTER JOIN '. $wpdb->prefix .'frm_fields fi ON it.field_id=fi.id' . |
250 | - FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
250 | + FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
251 | 251 | |
252 | - $cache_key = 'all_'. maybe_serialize($where) . $order_by . $limit; |
|
253 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results')); |
|
252 | + $cache_key = 'all_'. maybe_serialize($where) . $order_by . $limit; |
|
253 | + $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results')); |
|
254 | 254 | |
255 | - if ( ! $results || ! $stripslashes ) { |
|
256 | - return $results; |
|
257 | - } |
|
255 | + if ( ! $results || ! $stripslashes ) { |
|
256 | + return $results; |
|
257 | + } |
|
258 | 258 | |
259 | - foreach ( $results as $k => $result ) { |
|
259 | + foreach ( $results as $k => $result ) { |
|
260 | 260 | $results[ $k ]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) ); |
261 | - unset($k, $result); |
|
262 | - } |
|
261 | + unset($k, $result); |
|
262 | + } |
|
263 | 263 | |
264 | - return $results; |
|
265 | - } |
|
264 | + return $results; |
|
265 | + } |
|
266 | 266 | |
267 | - public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) { |
|
267 | + public static function getEntryIds( $where = array(), $order_by = '', $limit = '', $unique = true, $args = array() ) { |
|
268 | 268 | $defaults = array( |
269 | 269 | 'is_draft' => false, |
270 | 270 | 'user_id' => '', |
271 | 271 | 'group_by' => '', |
272 | 272 | ); |
273 | - $args = wp_parse_args($args, $defaults); |
|
273 | + $args = wp_parse_args($args, $defaults); |
|
274 | 274 | |
275 | - $query = array(); |
|
276 | - self::get_ids_query($where, $order_by, $limit, $unique, $args, $query ); |
|
277 | - $query = implode(' ', $query); |
|
275 | + $query = array(); |
|
276 | + self::get_ids_query($where, $order_by, $limit, $unique, $args, $query ); |
|
277 | + $query = implode(' ', $query); |
|
278 | 278 | |
279 | - $cache_key = 'ids_'. maybe_serialize($where) . $order_by . 'l'. $limit . 'u'. $unique . maybe_serialize($args); |
|
280 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col')); |
|
279 | + $cache_key = 'ids_'. maybe_serialize($where) . $order_by . 'l'. $limit . 'u'. $unique . maybe_serialize($args); |
|
280 | + $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col')); |
|
281 | 281 | |
282 | - return $results; |
|
283 | - } |
|
282 | + return $results; |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * @param string|array $where |
|
287 | - * @param string $order_by |
|
288 | - * @param string $limit |
|
289 | - */ |
|
285 | + /** |
|
286 | + * @param string|array $where |
|
287 | + * @param string $order_by |
|
288 | + * @param string $limit |
|
289 | + */ |
|
290 | 290 | private static function get_ids_query( $where, $order_by, $limit, $unique, $args, array &$query ) { |
291 | - global $wpdb; |
|
292 | - $query[] = 'SELECT'; |
|
291 | + global $wpdb; |
|
292 | + $query[] = 'SELECT'; |
|
293 | 293 | |
294 | 294 | $defaults = array( 'return_parent_id' => false ); |
295 | 295 | $args = array_merge( $defaults, $args ); |
@@ -300,91 +300,91 @@ discard block |
||
300 | 300 | $query[] = $unique ? 'DISTINCT(it.item_id)' : 'it.item_id'; |
301 | 301 | } |
302 | 302 | |
303 | - $query[] = 'FROM '. $wpdb->prefix .'frm_item_metas it LEFT OUTER JOIN '. $wpdb->prefix .'frm_fields fi ON it.field_id=fi.id'; |
|
303 | + $query[] = 'FROM '. $wpdb->prefix .'frm_item_metas it LEFT OUTER JOIN '. $wpdb->prefix .'frm_fields fi ON it.field_id=fi.id'; |
|
304 | 304 | |
305 | - $query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=it.item_id)'; |
|
306 | - if ( is_array($where) ) { |
|
307 | - if ( ! $args['is_draft'] ) { |
|
308 | - $where['e.is_draft'] = 0; |
|
309 | - } else if ( $args['is_draft'] == 1 ) { |
|
310 | - $where['e.is_draft'] = 1; |
|
311 | - } |
|
305 | + $query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=it.item_id)'; |
|
306 | + if ( is_array($where) ) { |
|
307 | + if ( ! $args['is_draft'] ) { |
|
308 | + $where['e.is_draft'] = 0; |
|
309 | + } else if ( $args['is_draft'] == 1 ) { |
|
310 | + $where['e.is_draft'] = 1; |
|
311 | + } |
|
312 | 312 | |
313 | - if ( ! empty($args['user_id']) ) { |
|
314 | - $where['e.user_id'] = $args['user_id']; |
|
315 | - } |
|
316 | - $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
313 | + if ( ! empty($args['user_id']) ) { |
|
314 | + $where['e.user_id'] = $args['user_id']; |
|
315 | + } |
|
316 | + $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
317 | 317 | |
318 | 318 | if ( $args['group_by'] ) { |
319 | 319 | $query[] = ' GROUP BY '. sanitize_text_field( $args['group_by'] ); |
320 | 320 | } |
321 | - return; |
|
322 | - } |
|
321 | + return; |
|
322 | + } |
|
323 | 323 | |
324 | 324 | $draft_where = $user_where = ''; |
325 | - if ( ! $args['is_draft'] ) { |
|
325 | + if ( ! $args['is_draft'] ) { |
|
326 | 326 | $draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 0 ); |
327 | - } else if ( $args['is_draft'] == 1 ) { |
|
327 | + } else if ( $args['is_draft'] == 1 ) { |
|
328 | 328 | $draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 ); |
329 | - } |
|
330 | - |
|
331 | - if ( ! empty($args['user_id']) ) { |
|
332 | - $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']); |
|
333 | - } |
|
334 | - |
|
335 | - if ( strpos($where, ' GROUP BY ') ) { |
|
336 | - // don't inject WHERE filtering after GROUP BY |
|
337 | - $parts = explode(' GROUP BY ', $where); |
|
338 | - $where = $parts[0]; |
|
339 | - $where .= $draft_where . $user_where; |
|
340 | - $where .= ' GROUP BY '. $parts[1]; |
|
341 | - } else { |
|
342 | - $where .= $draft_where . $user_where; |
|
343 | - } |
|
329 | + } |
|
330 | + |
|
331 | + if ( ! empty($args['user_id']) ) { |
|
332 | + $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']); |
|
333 | + } |
|
334 | + |
|
335 | + if ( strpos($where, ' GROUP BY ') ) { |
|
336 | + // don't inject WHERE filtering after GROUP BY |
|
337 | + $parts = explode(' GROUP BY ', $where); |
|
338 | + $where = $parts[0]; |
|
339 | + $where .= $draft_where . $user_where; |
|
340 | + $where .= ' GROUP BY '. $parts[1]; |
|
341 | + } else { |
|
342 | + $where .= $draft_where . $user_where; |
|
343 | + } |
|
344 | 344 | |
345 | 345 | // The query has already been prepared |
346 | 346 | $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
347 | - } |
|
347 | + } |
|
348 | 348 | |
349 | - public static function search_entry_metas( $search, $field_id = '', $operator ) { |
|
350 | - $cache_key = 'search_'. maybe_serialize($search) . $field_id . $operator; |
|
351 | - $results = wp_cache_get($cache_key, 'frm_entry'); |
|
352 | - if ( false !== $results ) { |
|
353 | - return $results; |
|
354 | - } |
|
349 | + public static function search_entry_metas( $search, $field_id = '', $operator ) { |
|
350 | + $cache_key = 'search_'. maybe_serialize($search) . $field_id . $operator; |
|
351 | + $results = wp_cache_get($cache_key, 'frm_entry'); |
|
352 | + if ( false !== $results ) { |
|
353 | + return $results; |
|
354 | + } |
|
355 | 355 | |
356 | - global $wpdb; |
|
356 | + global $wpdb; |
|
357 | 357 | if ( is_array( $search ) ) { |
358 | - $where = ''; |
|
358 | + $where = ''; |
|
359 | 359 | foreach ( $search as $field => $value ) { |
360 | 360 | if ( $value <= 0 || ! in_array( $field, array( 'year', 'month', 'day' ) ) ) { |
361 | - continue; |
|
362 | - } |
|
363 | - |
|
364 | - switch ( $field ) { |
|
365 | - case 'year': |
|
366 | - $value = '%'. $value; |
|
367 | - break; |
|
368 | - case 'month': |
|
369 | - $value .= '%'; |
|
370 | - break; |
|
371 | - case 'day': |
|
372 | - $value = '%'. $value .'%'; |
|
373 | - } |
|
374 | - $where .= $wpdb->prepare(' meta_value '. $operator .' %s and', $value); |
|
375 | - } |
|
376 | - $where .= $wpdb->prepare(' field_id=%d', $field_id); |
|
377 | - $query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas". FrmAppHelper::prepend_and_or_where(' WHERE ', $where); |
|
378 | - } else { |
|
361 | + continue; |
|
362 | + } |
|
363 | + |
|
364 | + switch ( $field ) { |
|
365 | + case 'year': |
|
366 | + $value = '%'. $value; |
|
367 | + break; |
|
368 | + case 'month': |
|
369 | + $value .= '%'; |
|
370 | + break; |
|
371 | + case 'day': |
|
372 | + $value = '%'. $value .'%'; |
|
373 | + } |
|
374 | + $where .= $wpdb->prepare(' meta_value '. $operator .' %s and', $value); |
|
375 | + } |
|
376 | + $where .= $wpdb->prepare(' field_id=%d', $field_id); |
|
377 | + $query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas". FrmAppHelper::prepend_and_or_where(' WHERE ', $where); |
|
378 | + } else { |
|
379 | 379 | if ( $operator == 'LIKE' ) { |
380 | - $search = '%' . $search . '%'; |
|
380 | + $search = '%' . $search . '%'; |
|
381 | 381 | } |
382 | - $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id); |
|
383 | - } |
|
382 | + $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id); |
|
383 | + } |
|
384 | 384 | |
385 | - $results = $wpdb->get_col($query, 0); |
|
386 | - wp_cache_set($cache_key, $results, 'frm_entry', 300); |
|
385 | + $results = $wpdb->get_col($query, 0); |
|
386 | + wp_cache_set($cache_key, $results, 'frm_entry', 300); |
|
387 | 387 | |
388 | - return $results; |
|
389 | - } |
|
388 | + return $results; |
|
389 | + } |
|
390 | 390 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined('ABSPATH') ) { |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | 3 | die( 'You are not allowed to call this page directly.' ); |
4 | 4 | } |
5 | 5 | |
@@ -20,12 +20,12 @@ discard block |
||
20 | 20 | 'meta_value' => is_array( $meta_value ) ? serialize( array_filter( $meta_value, 'FrmAppHelper::is_not_empty_value' ) ) : trim( $meta_value ), |
21 | 21 | 'item_id' => $entry_id, |
22 | 22 | 'field_id' => $field_id, |
23 | - 'created_at' => current_time('mysql', 1), |
|
23 | + 'created_at' => current_time( 'mysql', 1 ), |
|
24 | 24 | ); |
25 | 25 | |
26 | - $new_values = apply_filters('frm_add_entry_meta', $new_values); |
|
26 | + $new_values = apply_filters( 'frm_add_entry_meta', $new_values ); |
|
27 | 27 | |
28 | - $query_results = $wpdb->insert( $wpdb->prefix .'frm_item_metas', $new_values ); |
|
28 | + $query_results = $wpdb->insert( $wpdb->prefix . 'frm_item_metas', $new_values ); |
|
29 | 29 | |
30 | 30 | if ( $query_results ) { |
31 | 31 | self::clear_cache(); |
@@ -49,48 +49,48 @@ discard block |
||
49 | 49 | |
50 | 50 | $values = $where_values = array( 'item_id' => $entry_id, 'field_id' => $field_id ); |
51 | 51 | $values['meta_value'] = $meta_value; |
52 | - $values = apply_filters('frm_update_entry_meta', $values); |
|
53 | - if ( is_array($values['meta_value']) ) { |
|
52 | + $values = apply_filters( 'frm_update_entry_meta', $values ); |
|
53 | + if ( is_array( $values['meta_value'] ) ) { |
|
54 | 54 | $values['meta_value'] = array_filter( $values['meta_value'], 'FrmAppHelper::is_not_empty_value' ); |
55 | 55 | } |
56 | - $meta_value = maybe_serialize($values['meta_value']); |
|
56 | + $meta_value = maybe_serialize( $values['meta_value'] ); |
|
57 | 57 | |
58 | - wp_cache_delete( $entry_id, 'frm_entry'); |
|
58 | + wp_cache_delete( $entry_id, 'frm_entry' ); |
|
59 | 59 | self::clear_cache(); |
60 | 60 | |
61 | - return $wpdb->update( $wpdb->prefix .'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values ); |
|
61 | + return $wpdb->update( $wpdb->prefix . 'frm_item_metas', array( 'meta_value' => $meta_value ), $where_values ); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | public static function update_entry_metas( $entry_id, $values ) { |
65 | 65 | global $wpdb; |
66 | 66 | |
67 | - $prev_values = FrmDb::get_col( $wpdb->prefix .'frm_item_metas', array( 'item_id' => $entry_id, 'field_id !' => 0 ), 'field_id' ); |
|
67 | + $prev_values = FrmDb::get_col( $wpdb->prefix . 'frm_item_metas', array( 'item_id' => $entry_id, 'field_id !' => 0 ), 'field_id' ); |
|
68 | 68 | |
69 | 69 | foreach ( $values as $field_id => $meta_value ) { |
70 | 70 | // set the value for the file upload field and add new tags (in Pro version) |
71 | 71 | $values = apply_filters( 'frm_prepare_data_before_db', $values, $field_id, $entry_id ); |
72 | 72 | |
73 | - if ( $prev_values && in_array($field_id, $prev_values) ) { |
|
73 | + if ( $prev_values && in_array( $field_id, $prev_values ) ) { |
|
74 | 74 | if ( ( is_array( $meta_value ) && empty( $meta_value ) ) || ( ! is_array( $meta_value ) && trim( $meta_value ) == '' ) ) { |
75 | 75 | // remove blank fields |
76 | - unset( $values[ $field_id ] ); |
|
76 | + unset( $values[$field_id] ); |
|
77 | 77 | } else { |
78 | 78 | // if value exists, then update it |
79 | - self::update_entry_meta( $entry_id, $field_id, '', $values[ $field_id ] ); |
|
79 | + self::update_entry_meta( $entry_id, $field_id, '', $values[$field_id] ); |
|
80 | 80 | } |
81 | 81 | } else { |
82 | 82 | // if value does not exist, then create it |
83 | - self::add_entry_meta( $entry_id, $field_id, '', $values[ $field_id ] ); |
|
83 | + self::add_entry_meta( $entry_id, $field_id, '', $values[$field_id] ); |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | |
87 | - if ( empty($prev_values) ) { |
|
87 | + if ( empty( $prev_values ) ) { |
|
88 | 88 | return; |
89 | 89 | } |
90 | 90 | |
91 | - $prev_values = array_diff($prev_values, array_keys($values)); |
|
91 | + $prev_values = array_diff( $prev_values, array_keys( $values ) ); |
|
92 | 92 | |
93 | - if ( empty($prev_values) ) { |
|
93 | + if ( empty( $prev_values ) ) { |
|
94 | 94 | return; |
95 | 95 | } |
96 | 96 | |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | } |
105 | 105 | |
106 | 106 | public static function duplicate_entry_metas( $old_id, $new_id ) { |
107 | - $metas = self::get_entry_meta_info($old_id); |
|
107 | + $metas = self::get_entry_meta_info( $old_id ); |
|
108 | 108 | foreach ( $metas as $meta ) { |
109 | - self::add_entry_meta($new_id, $meta->field_id, null, $meta->meta_value); |
|
110 | - unset($meta); |
|
109 | + self::add_entry_meta( $new_id, $meta->field_id, null, $meta->meta_value ); |
|
110 | + unset( $meta ); |
|
111 | 111 | } |
112 | 112 | self::clear_cache(); |
113 | 113 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | public static function delete_entry_meta( $entry_id, $field_id ) { |
116 | 116 | global $wpdb; |
117 | 117 | self::clear_cache(); |
118 | - return $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id)); |
|
118 | + return $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_item_metas WHERE field_id=%d AND item_id=%d", $field_id, $entry_id ) ); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | public static function get_meta_value( $entry, $field_id ) { |
136 | 136 | if ( isset( $entry->metas ) ) { |
137 | - return isset( $entry->metas[ $field_id ] ) ? $entry->metas[ $field_id ] : false; |
|
137 | + return isset( $entry->metas[$field_id] ) ? $entry->metas[$field_id] : false; |
|
138 | 138 | } else { |
139 | 139 | return self::get_entry_meta_by_field( $entry->id, $field_id ); |
140 | 140 | } |
@@ -152,14 +152,14 @@ discard block |
||
152 | 152 | $cached = FrmAppHelper::check_cache( $entry_id, 'frm_entry' ); |
153 | 153 | } |
154 | 154 | |
155 | - if ( $cached && isset( $cached->metas ) && isset( $cached->metas[ $field_id ] ) ) { |
|
156 | - $result = $cached->metas[ $field_id ]; |
|
157 | - return stripslashes_deep($result); |
|
155 | + if ( $cached && isset( $cached->metas ) && isset( $cached->metas[$field_id] ) ) { |
|
156 | + $result = $cached->metas[$field_id]; |
|
157 | + return stripslashes_deep( $result ); |
|
158 | 158 | } |
159 | 159 | |
160 | - $get_table = $wpdb->prefix .'frm_item_metas'; |
|
160 | + $get_table = $wpdb->prefix . 'frm_item_metas'; |
|
161 | 161 | $query = array( 'item_id' => $entry_id ); |
162 | - if ( is_numeric($field_id) ) { |
|
162 | + if ( is_numeric( $field_id ) ) { |
|
163 | 163 | $query['field_id'] = $field_id; |
164 | 164 | } else { |
165 | 165 | $get_table .= ' it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id'; |
@@ -167,8 +167,8 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | $result = FrmDb::get_var( $get_table, $query, 'meta_value' ); |
170 | - $result = maybe_unserialize($result); |
|
171 | - $result = stripslashes_deep($result); |
|
170 | + $result = maybe_unserialize( $result ); |
|
171 | + $result = stripslashes_deep( $result ); |
|
172 | 172 | |
173 | 173 | return $result; |
174 | 174 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | } |
180 | 180 | |
181 | 181 | public static function get_entry_metas( $entry_id ) { |
182 | - _deprecated_function( __FUNCTION__, '1.07.10'); |
|
182 | + _deprecated_function( __FUNCTION__, '1.07.10' ); |
|
183 | 183 | |
184 | 184 | global $wpdb; |
185 | 185 | return FrmDb::get_col( $wpdb->prefix . 'frm_item_metas', array( 'item_id' => $entry_id ), 'meta_value' ); |
@@ -190,22 +190,22 @@ discard block |
||
190 | 190 | $args = wp_parse_args( $args, $defaults ); |
191 | 191 | |
192 | 192 | $query = array(); |
193 | - self::meta_field_query($field_id, $order, $limit, $args, $query); |
|
194 | - $query = implode(' ', $query); |
|
193 | + self::meta_field_query( $field_id, $order, $limit, $args, $query ); |
|
194 | + $query = implode( ' ', $query ); |
|
195 | 195 | |
196 | - $cache_key = 'entry_metas_for_field_'. $field_id . $order . $limit . maybe_serialize($args); |
|
197 | - $values = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, 'get_col'); |
|
196 | + $cache_key = 'entry_metas_for_field_' . $field_id . $order . $limit . maybe_serialize( $args ); |
|
197 | + $values = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, 'get_col' ); |
|
198 | 198 | |
199 | 199 | if ( ! $args['stripslashes'] ) { |
200 | 200 | return $values; |
201 | 201 | } |
202 | 202 | |
203 | 203 | foreach ( $values as $k => $v ) { |
204 | - $values[ $k ] = maybe_unserialize( $v ); |
|
205 | - unset($k, $v); |
|
204 | + $values[$k] = maybe_unserialize( $v ); |
|
205 | + unset( $k, $v ); |
|
206 | 206 | } |
207 | 207 | |
208 | - return stripslashes_deep($values); |
|
208 | + return stripslashes_deep( $values ); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -216,16 +216,16 @@ discard block |
||
216 | 216 | global $wpdb; |
217 | 217 | $query[] = 'SELECT'; |
218 | 218 | $query[] = $args['unique'] ? 'DISTINCT(em.meta_value)' : 'em.meta_value'; |
219 | - $query[] = 'FROM '. $wpdb->prefix .'frm_item_metas em '; |
|
219 | + $query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas em '; |
|
220 | 220 | |
221 | 221 | if ( ! $args['is_draft'] ) { |
222 | - $query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=em.item_id)'; |
|
222 | + $query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=em.item_id)'; |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( is_numeric($field_id) ) { |
|
226 | - $query[] = $wpdb->prepare('WHERE em.field_id=%d', $field_id); |
|
225 | + if ( is_numeric( $field_id ) ) { |
|
226 | + $query[] = $wpdb->prepare( 'WHERE em.field_id=%d', $field_id ); |
|
227 | 227 | } else { |
228 | - $query[] = $wpdb->prepare('LEFT JOIN '. $wpdb->prefix .'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id); |
|
228 | + $query[] = $wpdb->prepare( 'LEFT JOIN ' . $wpdb->prefix . 'frm_fields fi ON (em.field_id = fi.id) WHERE fi.field_key=%s', $field_id ); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | if ( ! $args['is_draft'] ) { |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | } |
234 | 234 | |
235 | 235 | if ( $args['value'] ) { |
236 | - $query[] = $wpdb->prepare(' AND meta_value=%s', $args['value']); |
|
236 | + $query[] = $wpdb->prepare( ' AND meta_value=%s', $args['value'] ); |
|
237 | 237 | } |
238 | 238 | $query[] = $order . $limit; |
239 | 239 | } |
@@ -246,19 +246,19 @@ discard block |
||
246 | 246 | global $wpdb; |
247 | 247 | $query = 'SELECT it.*, fi.type as field_type, fi.field_key as field_key, |
248 | 248 | fi.required as required, fi.form_id as field_form_id, fi.name as field_name, fi.options as fi_options |
249 | - FROM '. $wpdb->prefix .'frm_item_metas it LEFT OUTER JOIN '. $wpdb->prefix .'frm_fields fi ON it.field_id=fi.id' . |
|
250 | - FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
249 | + FROM '. $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id' . |
|
250 | + FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
251 | 251 | |
252 | - $cache_key = 'all_'. maybe_serialize($where) . $order_by . $limit; |
|
253 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_row' : 'get_results')); |
|
252 | + $cache_key = 'all_' . maybe_serialize( $where ) . $order_by . $limit; |
|
253 | + $results = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_row' : 'get_results' ) ); |
|
254 | 254 | |
255 | 255 | if ( ! $results || ! $stripslashes ) { |
256 | 256 | return $results; |
257 | 257 | } |
258 | 258 | |
259 | 259 | foreach ( $results as $k => $result ) { |
260 | - $results[ $k ]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) ); |
|
261 | - unset($k, $result); |
|
260 | + $results[$k]->meta_value = stripslashes_deep( maybe_unserialize( $result->meta_value ) ); |
|
261 | + unset( $k, $result ); |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | return $results; |
@@ -270,14 +270,14 @@ discard block |
||
270 | 270 | 'user_id' => '', |
271 | 271 | 'group_by' => '', |
272 | 272 | ); |
273 | - $args = wp_parse_args($args, $defaults); |
|
273 | + $args = wp_parse_args( $args, $defaults ); |
|
274 | 274 | |
275 | 275 | $query = array(); |
276 | - self::get_ids_query($where, $order_by, $limit, $unique, $args, $query ); |
|
277 | - $query = implode(' ', $query); |
|
276 | + self::get_ids_query( $where, $order_by, $limit, $unique, $args, $query ); |
|
277 | + $query = implode( ' ', $query ); |
|
278 | 278 | |
279 | - $cache_key = 'ids_'. maybe_serialize($where) . $order_by . 'l'. $limit . 'u'. $unique . maybe_serialize($args); |
|
280 | - $results = FrmAppHelper::check_cache($cache_key, 'frm_entry', $query, ($limit == ' LIMIT 1' ? 'get_var' : 'get_col')); |
|
279 | + $cache_key = 'ids_' . maybe_serialize( $where ) . $order_by . 'l' . $limit . 'u' . $unique . maybe_serialize( $args ); |
|
280 | + $results = FrmAppHelper::check_cache( $cache_key, 'frm_entry', $query, ( $limit == ' LIMIT 1' ? 'get_var' : 'get_col' ) ); |
|
281 | 281 | |
282 | 282 | return $results; |
283 | 283 | } |
@@ -300,23 +300,23 @@ discard block |
||
300 | 300 | $query[] = $unique ? 'DISTINCT(it.item_id)' : 'it.item_id'; |
301 | 301 | } |
302 | 302 | |
303 | - $query[] = 'FROM '. $wpdb->prefix .'frm_item_metas it LEFT OUTER JOIN '. $wpdb->prefix .'frm_fields fi ON it.field_id=fi.id'; |
|
303 | + $query[] = 'FROM ' . $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id=fi.id'; |
|
304 | 304 | |
305 | - $query[] = 'INNER JOIN '. $wpdb->prefix .'frm_items e ON (e.id=it.item_id)'; |
|
306 | - if ( is_array($where) ) { |
|
305 | + $query[] = 'INNER JOIN ' . $wpdb->prefix . 'frm_items e ON (e.id=it.item_id)'; |
|
306 | + if ( is_array( $where ) ) { |
|
307 | 307 | if ( ! $args['is_draft'] ) { |
308 | 308 | $where['e.is_draft'] = 0; |
309 | 309 | } else if ( $args['is_draft'] == 1 ) { |
310 | 310 | $where['e.is_draft'] = 1; |
311 | 311 | } |
312 | 312 | |
313 | - if ( ! empty($args['user_id']) ) { |
|
313 | + if ( ! empty( $args['user_id'] ) ) { |
|
314 | 314 | $where['e.user_id'] = $args['user_id']; |
315 | 315 | } |
316 | - $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
316 | + $query[] = FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
317 | 317 | |
318 | 318 | if ( $args['group_by'] ) { |
319 | - $query[] = ' GROUP BY '. sanitize_text_field( $args['group_by'] ); |
|
319 | + $query[] = ' GROUP BY ' . sanitize_text_field( $args['group_by'] ); |
|
320 | 320 | } |
321 | 321 | return; |
322 | 322 | } |
@@ -328,27 +328,27 @@ discard block |
||
328 | 328 | $draft_where = $wpdb->prepare( ' AND e.is_draft=%d', 1 ); |
329 | 329 | } |
330 | 330 | |
331 | - if ( ! empty($args['user_id']) ) { |
|
332 | - $user_where = $wpdb->prepare(' AND e.user_id=%d', $args['user_id']); |
|
331 | + if ( ! empty( $args['user_id'] ) ) { |
|
332 | + $user_where = $wpdb->prepare( ' AND e.user_id=%d', $args['user_id'] ); |
|
333 | 333 | } |
334 | 334 | |
335 | - if ( strpos($where, ' GROUP BY ') ) { |
|
335 | + if ( strpos( $where, ' GROUP BY ' ) ) { |
|
336 | 336 | // don't inject WHERE filtering after GROUP BY |
337 | - $parts = explode(' GROUP BY ', $where); |
|
337 | + $parts = explode( ' GROUP BY ', $where ); |
|
338 | 338 | $where = $parts[0]; |
339 | 339 | $where .= $draft_where . $user_where; |
340 | - $where .= ' GROUP BY '. $parts[1]; |
|
340 | + $where .= ' GROUP BY ' . $parts[1]; |
|
341 | 341 | } else { |
342 | 342 | $where .= $draft_where . $user_where; |
343 | 343 | } |
344 | 344 | |
345 | 345 | // The query has already been prepared |
346 | - $query[] = FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit; |
|
346 | + $query[] = FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit; |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | public static function search_entry_metas( $search, $field_id = '', $operator ) { |
350 | - $cache_key = 'search_'. maybe_serialize($search) . $field_id . $operator; |
|
351 | - $results = wp_cache_get($cache_key, 'frm_entry'); |
|
350 | + $cache_key = 'search_' . maybe_serialize( $search ) . $field_id . $operator; |
|
351 | + $results = wp_cache_get( $cache_key, 'frm_entry' ); |
|
352 | 352 | if ( false !== $results ) { |
353 | 353 | return $results; |
354 | 354 | } |
@@ -363,27 +363,27 @@ discard block |
||
363 | 363 | |
364 | 364 | switch ( $field ) { |
365 | 365 | case 'year': |
366 | - $value = '%'. $value; |
|
366 | + $value = '%' . $value; |
|
367 | 367 | break; |
368 | 368 | case 'month': |
369 | 369 | $value .= '%'; |
370 | 370 | break; |
371 | 371 | case 'day': |
372 | - $value = '%'. $value .'%'; |
|
372 | + $value = '%' . $value . '%'; |
|
373 | 373 | } |
374 | - $where .= $wpdb->prepare(' meta_value '. $operator .' %s and', $value); |
|
374 | + $where .= $wpdb->prepare( ' meta_value ' . $operator . ' %s and', $value ); |
|
375 | 375 | } |
376 | - $where .= $wpdb->prepare(' field_id=%d', $field_id); |
|
377 | - $query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas". FrmAppHelper::prepend_and_or_where(' WHERE ', $where); |
|
376 | + $where .= $wpdb->prepare( ' field_id=%d', $field_id ); |
|
377 | + $query = "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas" . FrmAppHelper::prepend_and_or_where( ' WHERE ', $where ); |
|
378 | 378 | } else { |
379 | 379 | if ( $operator == 'LIKE' ) { |
380 | 380 | $search = '%' . $search . '%'; |
381 | 381 | } |
382 | - $query = $wpdb->prepare("SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id); |
|
382 | + $query = $wpdb->prepare( "SELECT DISTINCT item_id FROM {$wpdb->prefix}frm_item_metas WHERE meta_value {$operator} %s and field_id = %d", $search, $field_id ); |
|
383 | 383 | } |
384 | 384 | |
385 | - $results = $wpdb->get_col($query, 0); |
|
386 | - wp_cache_set($cache_key, $results, 'frm_entry', 300); |
|
385 | + $results = $wpdb->get_col( $query, 0 ); |
|
386 | + wp_cache_set( $cache_key, $results, 'frm_entry', 300 ); |
|
387 | 387 | |
388 | 388 | return $results; |
389 | 389 | } |
@@ -4,7 +4,7 @@ |
||
4 | 4 | public $id = 0; // the id of the post |
5 | 5 | |
6 | 6 | /** |
7 | - * @param int|string $id The id of the stylsheet or 'default' |
|
7 | + * @param integer $id The id of the stylsheet or 'default' |
|
8 | 8 | */ |
9 | 9 | public function __construct( $id = 0 ) { |
10 | 10 | $this->id = $id; |
@@ -1,52 +1,52 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class FrmStyle { |
3 | - public $number = false; // Unique ID number of the current instance. |
|
3 | + public $number = false; // Unique ID number of the current instance. |
|
4 | 4 | public $id = 0; // the id of the post |
5 | 5 | |
6 | 6 | /** |
7 | 7 | * @param int|string $id The id of the stylsheet or 'default' |
8 | 8 | */ |
9 | 9 | public function __construct( $id = 0 ) { |
10 | - $this->id = $id; |
|
11 | - } |
|
10 | + $this->id = $id; |
|
11 | + } |
|
12 | 12 | |
13 | - public function get_new() { |
|
13 | + public function get_new() { |
|
14 | 14 | $this->id = 0; |
15 | 15 | |
16 | - $max_slug_value = pow(36, 6); |
|
17 | - $min_slug_value = 37; // we want to have at least 2 characters in the slug |
|
18 | - $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
19 | - |
|
20 | - $style = array( |
|
21 | - 'post_type' => FrmStylesController::$post_type, |
|
22 | - 'ID' => '', |
|
23 | - 'post_title' => __( 'New Style', 'formidable' ), |
|
24 | - 'post_name' => $key, |
|
25 | - 'post_content' => $this->get_defaults(), |
|
26 | - 'menu_order' => '', |
|
27 | - 'post_status' => 'publish', |
|
28 | - ); |
|
16 | + $max_slug_value = pow(36, 6); |
|
17 | + $min_slug_value = 37; // we want to have at least 2 characters in the slug |
|
18 | + $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
19 | + |
|
20 | + $style = array( |
|
21 | + 'post_type' => FrmStylesController::$post_type, |
|
22 | + 'ID' => '', |
|
23 | + 'post_title' => __( 'New Style', 'formidable' ), |
|
24 | + 'post_name' => $key, |
|
25 | + 'post_content' => $this->get_defaults(), |
|
26 | + 'menu_order' => '', |
|
27 | + 'post_status' => 'publish', |
|
28 | + ); |
|
29 | 29 | |
30 | - return (object) $style; |
|
31 | - } |
|
30 | + return (object) $style; |
|
31 | + } |
|
32 | 32 | |
33 | 33 | public function save( $settings ) { |
34 | 34 | return FrmAppHelper::save_settings( $settings, 'frm_styles' ); |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | 37 | public function duplicate( $id ) { |
38 | - // duplicating is a pro feature |
|
39 | - } |
|
38 | + // duplicating is a pro feature |
|
39 | + } |
|
40 | 40 | |
41 | - public function update( $id = 'default' ) { |
|
41 | + public function update( $id = 'default' ) { |
|
42 | 42 | $all_instances = $this->get_all(); |
43 | 43 | |
44 | 44 | if ( empty($id) ) { |
45 | - $new_style = (array) $this->get_new(); |
|
46 | - $all_instances[] = $new_style; |
|
45 | + $new_style = (array) $this->get_new(); |
|
46 | + $all_instances[] = $new_style; |
|
47 | 47 | } |
48 | 48 | |
49 | - $action_ids = array(); |
|
49 | + $action_ids = array(); |
|
50 | 50 | |
51 | 51 | foreach ( $all_instances as $number => $new_instance ) { |
52 | 52 | $new_instance = stripslashes_deep( (array) $new_instance); |
@@ -54,40 +54,40 @@ discard block |
||
54 | 54 | if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) { |
55 | 55 | $all_instances[ $number ] = $new_instance; |
56 | 56 | |
57 | - if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) { |
|
58 | - // this style was set to default, so remove default setting on previous default style |
|
59 | - $new_instance['menu_order'] = 0; |
|
60 | - $action_ids[] = $this->save($new_instance); |
|
61 | - } |
|
57 | + if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) { |
|
58 | + // this style was set to default, so remove default setting on previous default style |
|
59 | + $new_instance['menu_order'] = 0; |
|
60 | + $action_ids[] = $this->save($new_instance); |
|
61 | + } |
|
62 | 62 | |
63 | - // don't continue if not saving this style |
|
64 | - continue; |
|
63 | + // don't continue if not saving this style |
|
64 | + continue; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | $new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] ); |
68 | 68 | $new_instance['post_content'] = $_POST['frm_style_setting']['post_content']; |
69 | 69 | $new_instance['post_type'] = FrmStylesController::$post_type; |
70 | - $new_instance['post_status'] = 'publish'; |
|
70 | + $new_instance['post_status'] = 'publish'; |
|
71 | 71 | $new_instance['menu_order'] = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0; |
72 | 72 | |
73 | - if ( empty($id) ) { |
|
74 | - $new_instance['post_name'] = $new_instance['post_title']; |
|
75 | - } |
|
73 | + if ( empty($id) ) { |
|
74 | + $new_instance['post_name'] = $new_instance['post_title']; |
|
75 | + } |
|
76 | 76 | |
77 | - $default_settings = $this->get_defaults(); |
|
77 | + $default_settings = $this->get_defaults(); |
|
78 | 78 | |
79 | - foreach ( $default_settings as $setting => $default ) { |
|
79 | + foreach ( $default_settings as $setting => $default ) { |
|
80 | 80 | if ( strpos( $setting, 'color' ) !== false || in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ) ) ) { |
81 | - //if is a color |
|
81 | + //if is a color |
|
82 | 82 | $new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] ); |
83 | 83 | } else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) { |
84 | 84 | $new_instance['post_content'][ $setting ] = 0; |
85 | - } |
|
86 | - } |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | 88 | $all_instances[ $number ] = $new_instance; |
89 | 89 | |
90 | - $action_ids[] = $this->save($new_instance); |
|
90 | + $action_ids[] = $this->save($new_instance); |
|
91 | 91 | |
92 | 92 | } |
93 | 93 | |
@@ -96,74 +96,74 @@ discard block |
||
96 | 96 | return $action_ids; |
97 | 97 | } |
98 | 98 | |
99 | - /** |
|
100 | - * Create static css file |
|
101 | - */ |
|
99 | + /** |
|
100 | + * Create static css file |
|
101 | + */ |
|
102 | 102 | public function save_settings( $styles ) { |
103 | - $filename = FrmAppHelper::plugin_path() .'/css/custom_theme.css.php'; |
|
103 | + $filename = FrmAppHelper::plugin_path() .'/css/custom_theme.css.php'; |
|
104 | 104 | |
105 | - if ( ! is_file($filename) ) { |
|
106 | - return; |
|
107 | - } |
|
105 | + if ( ! is_file($filename) ) { |
|
106 | + return; |
|
107 | + } |
|
108 | 108 | |
109 | - $defaults = $this->get_defaults(); |
|
110 | - $uploads = wp_upload_dir(); |
|
111 | - $target_path = $uploads['basedir'] .'/formidable'; |
|
112 | - $needed_dirs = array( $target_path, $target_path .'/css' ); |
|
113 | - $dirs_exist = true; |
|
109 | + $defaults = $this->get_defaults(); |
|
110 | + $uploads = wp_upload_dir(); |
|
111 | + $target_path = $uploads['basedir'] .'/formidable'; |
|
112 | + $needed_dirs = array( $target_path, $target_path .'/css' ); |
|
113 | + $dirs_exist = true; |
|
114 | 114 | |
115 | - $saving = true; |
|
116 | - $css = '/* '. __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) .' */'. "\n"; |
|
115 | + $saving = true; |
|
116 | + $css = '/* '. __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) .' */'. "\n"; |
|
117 | 117 | |
118 | - ob_start(); |
|
119 | - $frm_style = $this; |
|
120 | - include($filename); |
|
118 | + ob_start(); |
|
119 | + $frm_style = $this; |
|
120 | + include($filename); |
|
121 | 121 | $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) ); |
122 | - ob_end_clean(); |
|
122 | + ob_end_clean(); |
|
123 | 123 | |
124 | - $access_type = get_filesystem_method(); |
|
125 | - if ( $access_type === 'direct' ) { |
|
126 | - $creds = request_filesystem_credentials( site_url() .'/wp-admin/', '', false, false, array() ); |
|
124 | + $access_type = get_filesystem_method(); |
|
125 | + if ( $access_type === 'direct' ) { |
|
126 | + $creds = request_filesystem_credentials( site_url() .'/wp-admin/', '', false, false, array() ); |
|
127 | 127 | } else { |
128 | 128 | $creds = $this->get_ftp_creds( $access_type ); |
129 | 129 | } |
130 | 130 | |
131 | 131 | if ( ! empty( $creds ) ) { |
132 | - // initialize the API |
|
133 | - if ( ! WP_Filesystem( $creds ) ) { |
|
134 | - // any problems and we exit |
|
135 | - $dirs_exist = false; |
|
132 | + // initialize the API |
|
133 | + if ( ! WP_Filesystem( $creds ) ) { |
|
134 | + // any problems and we exit |
|
135 | + $dirs_exist = false; |
|
136 | 136 | } |
137 | 137 | |
138 | - if ( $dirs_exist ) { |
|
139 | - global $wp_filesystem; |
|
138 | + if ( $dirs_exist ) { |
|
139 | + global $wp_filesystem; |
|
140 | 140 | |
141 | - $chmod_dir = defined('FS_CHMOD_DIR') ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 ); |
|
142 | - $chmod_file = defined('FS_CHMOD_FILE') ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
|
141 | + $chmod_dir = defined('FS_CHMOD_DIR') ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 ); |
|
142 | + $chmod_file = defined('FS_CHMOD_FILE') ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
|
143 | 143 | |
144 | - // Create the directories if need be: |
|
145 | - foreach ( $needed_dirs as $_dir ) { |
|
146 | - // Only check to see if the Dir exists upon creation failure. Less I/O this way. |
|
147 | - if ( ! $wp_filesystem->mkdir( $_dir, $chmod_dir ) && ! $wp_filesystem->is_dir( $_dir ) ) { |
|
148 | - $dirs_exist = false; |
|
149 | - } |
|
150 | - } |
|
144 | + // Create the directories if need be: |
|
145 | + foreach ( $needed_dirs as $_dir ) { |
|
146 | + // Only check to see if the Dir exists upon creation failure. Less I/O this way. |
|
147 | + if ( ! $wp_filesystem->mkdir( $_dir, $chmod_dir ) && ! $wp_filesystem->is_dir( $_dir ) ) { |
|
148 | + $dirs_exist = false; |
|
149 | + } |
|
150 | + } |
|
151 | 151 | |
152 | - $index_path = $target_path .'/index.php'; |
|
153 | - $wp_filesystem->put_contents( $index_path, "<?php\n// Silence is golden.\n?>", $chmod_file ); |
|
152 | + $index_path = $target_path .'/index.php'; |
|
153 | + $wp_filesystem->put_contents( $index_path, "<?php\n// Silence is golden.\n?>", $chmod_file ); |
|
154 | 154 | |
155 | - // only write the file if the folders exist |
|
156 | - if ( $dirs_exist ) { |
|
157 | - $css_file = $target_path .'/css/formidablepro.css'; |
|
158 | - $wp_filesystem->put_contents( $css_file, $css, $chmod_file ); |
|
159 | - } |
|
160 | - } |
|
161 | - } |
|
155 | + // only write the file if the folders exist |
|
156 | + if ( $dirs_exist ) { |
|
157 | + $css_file = $target_path .'/css/formidablepro.css'; |
|
158 | + $wp_filesystem->put_contents( $css_file, $css, $chmod_file ); |
|
159 | + } |
|
160 | + } |
|
161 | + } |
|
162 | 162 | |
163 | - update_option('frmpro_css', $css); |
|
163 | + update_option('frmpro_css', $css); |
|
164 | 164 | |
165 | - delete_transient('frmpro_css'); |
|
166 | - set_transient('frmpro_css', $css); |
|
165 | + delete_transient('frmpro_css'); |
|
166 | + set_transient('frmpro_css', $css); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | private function get_ftp_creds( $type ) { |
@@ -217,264 +217,264 @@ discard block |
||
217 | 217 | } |
218 | 218 | |
219 | 219 | public function destroy( $id ) { |
220 | - return wp_delete_post($id); |
|
221 | - } |
|
220 | + return wp_delete_post($id); |
|
221 | + } |
|
222 | 222 | |
223 | - public function get_one() { |
|
224 | - if ( 'default' == $this->id ) { |
|
225 | - $style = $this->get_default_style(); |
|
226 | - if ( $style ) { |
|
227 | - $this->id = $style->ID; |
|
228 | - } else { |
|
229 | - $this->id = 0; |
|
230 | - } |
|
231 | - return $style; |
|
232 | - } |
|
223 | + public function get_one() { |
|
224 | + if ( 'default' == $this->id ) { |
|
225 | + $style = $this->get_default_style(); |
|
226 | + if ( $style ) { |
|
227 | + $this->id = $style->ID; |
|
228 | + } else { |
|
229 | + $this->id = 0; |
|
230 | + } |
|
231 | + return $style; |
|
232 | + } |
|
233 | 233 | |
234 | - $style = get_post($this->id); |
|
234 | + $style = get_post($this->id); |
|
235 | 235 | |
236 | - if ( ! $style ) { |
|
237 | - return $style; |
|
238 | - } |
|
236 | + if ( ! $style ) { |
|
237 | + return $style; |
|
238 | + } |
|
239 | 239 | |
240 | - $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
240 | + $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
241 | 241 | |
242 | - $default_values = $this->get_defaults(); |
|
242 | + $default_values = $this->get_defaults(); |
|
243 | 243 | |
244 | - // fill default values |
|
245 | - $style->post_content = $this->override_defaults($style->post_content); |
|
246 | - $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
244 | + // fill default values |
|
245 | + $style->post_content = $this->override_defaults($style->post_content); |
|
246 | + $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
247 | 247 | |
248 | - return $style; |
|
249 | - } |
|
248 | + return $style; |
|
249 | + } |
|
250 | 250 | |
251 | - public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) { |
|
252 | - $post_atts = array( |
|
251 | + public function get_all( $orderby = 'title', $order = 'ASC', $limit = 99 ) { |
|
252 | + $post_atts = array( |
|
253 | 253 | 'post_type' => FrmStylesController::$post_type, |
254 | 254 | 'post_status' => 'publish', |
255 | 255 | 'numberposts' => $limit, |
256 | 256 | 'orderby' => $orderby, |
257 | 257 | 'order' => $order, |
258 | - ); |
|
259 | - |
|
260 | - $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts'); |
|
261 | - |
|
262 | - if ( empty($temp_styles) ) { |
|
263 | - global $wpdb; |
|
264 | - // make sure there wasn't a conflict with the query |
|
265 | - $query = $wpdb->prepare('SELECT * FROM '. $wpdb->posts .' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish'); |
|
266 | - $temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results'); |
|
267 | - |
|
268 | - if ( empty($temp_styles) ) { |
|
269 | - // create a new style if there are none |
|
270 | - $new = $this->get_new(); |
|
271 | - $new->post_title = $new->post_name = __( 'Formidable Style', 'formidable' ); |
|
272 | - $new->menu_order = 1; |
|
273 | - $new = $this->save( (array) $new); |
|
274 | - $this->update('default'); |
|
275 | - |
|
276 | - $post_atts['include'] = $new; |
|
277 | - |
|
278 | - $temp_styles = get_posts( $post_atts ); |
|
279 | - } |
|
280 | - } |
|
281 | - |
|
282 | - $default_values = $this->get_defaults(); |
|
283 | - $default_style = false; |
|
284 | - |
|
285 | - $styles = array(); |
|
286 | - foreach ( $temp_styles as $style ) { |
|
287 | - $this->id = $style->ID; |
|
288 | - if ( $style->menu_order ) { |
|
289 | - if ( $default_style ) { |
|
290 | - // only return one default |
|
291 | - $style->menu_order = 0; |
|
292 | - } else { |
|
293 | - // check for a default style |
|
294 | - $default_style = $style->ID; |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
299 | - |
|
300 | - // fill default values |
|
301 | - $style->post_content = $this->override_defaults($style->post_content); |
|
302 | - $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
258 | + ); |
|
259 | + |
|
260 | + $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts'); |
|
261 | + |
|
262 | + if ( empty($temp_styles) ) { |
|
263 | + global $wpdb; |
|
264 | + // make sure there wasn't a conflict with the query |
|
265 | + $query = $wpdb->prepare('SELECT * FROM '. $wpdb->posts .' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish'); |
|
266 | + $temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results'); |
|
267 | + |
|
268 | + if ( empty($temp_styles) ) { |
|
269 | + // create a new style if there are none |
|
270 | + $new = $this->get_new(); |
|
271 | + $new->post_title = $new->post_name = __( 'Formidable Style', 'formidable' ); |
|
272 | + $new->menu_order = 1; |
|
273 | + $new = $this->save( (array) $new); |
|
274 | + $this->update('default'); |
|
275 | + |
|
276 | + $post_atts['include'] = $new; |
|
277 | + |
|
278 | + $temp_styles = get_posts( $post_atts ); |
|
279 | + } |
|
280 | + } |
|
281 | + |
|
282 | + $default_values = $this->get_defaults(); |
|
283 | + $default_style = false; |
|
284 | + |
|
285 | + $styles = array(); |
|
286 | + foreach ( $temp_styles as $style ) { |
|
287 | + $this->id = $style->ID; |
|
288 | + if ( $style->menu_order ) { |
|
289 | + if ( $default_style ) { |
|
290 | + // only return one default |
|
291 | + $style->menu_order = 0; |
|
292 | + } else { |
|
293 | + // check for a default style |
|
294 | + $default_style = $style->ID; |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
299 | + |
|
300 | + // fill default values |
|
301 | + $style->post_content = $this->override_defaults($style->post_content); |
|
302 | + $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
303 | 303 | |
304 | 304 | $styles[ $style->ID ] = $style; |
305 | - } |
|
305 | + } |
|
306 | 306 | |
307 | - if ( ! $default_style ) { |
|
308 | - $default_style = reset($styles); |
|
307 | + if ( ! $default_style ) { |
|
308 | + $default_style = reset($styles); |
|
309 | 309 | $styles[ $default_style->ID ]->menu_order = 1; |
310 | - } |
|
310 | + } |
|
311 | 311 | |
312 | - return $styles; |
|
313 | - } |
|
312 | + return $styles; |
|
313 | + } |
|
314 | 314 | |
315 | 315 | public function get_default_style( $styles = null ) { |
316 | - if ( ! isset($styles) ) { |
|
316 | + if ( ! isset($styles) ) { |
|
317 | 317 | $styles = $this->get_all( 'menu_order', 'DESC', 1 ); |
318 | - } |
|
318 | + } |
|
319 | 319 | |
320 | - foreach ( $styles as $style ) { |
|
321 | - if ( $style->menu_order ) { |
|
322 | - return $style; |
|
323 | - } |
|
324 | - } |
|
325 | - } |
|
320 | + foreach ( $styles as $style ) { |
|
321 | + if ( $style->menu_order ) { |
|
322 | + return $style; |
|
323 | + } |
|
324 | + } |
|
325 | + } |
|
326 | 326 | |
327 | 327 | public function override_defaults( $settings ) { |
328 | - if ( ! is_array($settings) ) { |
|
329 | - return $settings; |
|
330 | - } |
|
331 | - |
|
332 | - $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height']; |
|
333 | - |
|
334 | - if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) { |
|
335 | - $settings['form_desc_size'] = $settings['description_font_size']; |
|
336 | - $settings['form_desc_color'] = $settings['description_color']; |
|
337 | - $settings['title_color'] = $settings['label_color']; |
|
338 | - } |
|
339 | - |
|
340 | - if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) { |
|
341 | - $settings['section_color'] = $settings['label_color']; |
|
342 | - $settings['section_border_color'] = $settings['border_color']; |
|
343 | - } |
|
344 | - |
|
345 | - if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) { |
|
346 | - $settings['submit_hover_bg_color'] = $settings['submit_bg_color']; |
|
347 | - $settings['submit_hover_color'] = $settings['submit_text_color']; |
|
348 | - $settings['submit_hover_border_color'] = $settings['submit_border_color']; |
|
349 | - |
|
350 | - $settings['submit_active_bg_color'] = $settings['submit_bg_color']; |
|
351 | - $settings['submit_active_color'] = $settings['submit_text_color']; |
|
352 | - $settings['submit_active_border_color'] = $settings['submit_border_color']; |
|
353 | - } |
|
354 | - |
|
355 | - return $settings; |
|
328 | + if ( ! is_array($settings) ) { |
|
329 | + return $settings; |
|
330 | + } |
|
331 | + |
|
332 | + $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height']; |
|
333 | + |
|
334 | + if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) { |
|
335 | + $settings['form_desc_size'] = $settings['description_font_size']; |
|
336 | + $settings['form_desc_color'] = $settings['description_color']; |
|
337 | + $settings['title_color'] = $settings['label_color']; |
|
338 | + } |
|
339 | + |
|
340 | + if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) { |
|
341 | + $settings['section_color'] = $settings['label_color']; |
|
342 | + $settings['section_border_color'] = $settings['border_color']; |
|
343 | + } |
|
344 | + |
|
345 | + if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) { |
|
346 | + $settings['submit_hover_bg_color'] = $settings['submit_bg_color']; |
|
347 | + $settings['submit_hover_color'] = $settings['submit_text_color']; |
|
348 | + $settings['submit_hover_border_color'] = $settings['submit_border_color']; |
|
349 | + |
|
350 | + $settings['submit_active_bg_color'] = $settings['submit_bg_color']; |
|
351 | + $settings['submit_active_color'] = $settings['submit_text_color']; |
|
352 | + $settings['submit_active_border_color'] = $settings['submit_border_color']; |
|
353 | + } |
|
354 | + |
|
355 | + return $settings; |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | public function get_defaults() { |
359 | - return array( |
|
360 | - 'theme_css' => 'ui-lightness', |
|
361 | - 'theme_name' => 'UI Lightness', |
|
359 | + return array( |
|
360 | + 'theme_css' => 'ui-lightness', |
|
361 | + 'theme_name' => 'UI Lightness', |
|
362 | 362 | |
363 | 363 | 'center_form' => '', |
364 | - 'form_width' => '100%', |
|
365 | - 'form_align' => 'left', |
|
366 | - 'direction' => is_rtl() ? 'rtl' : 'ltr', |
|
367 | - 'fieldset' => '0px', |
|
368 | - 'fieldset_color' => '000000', |
|
369 | - 'fieldset_padding' => '0 0 15px 0', |
|
370 | - 'fieldset_bg_color' => '', |
|
371 | - |
|
372 | - 'title_size' => '20px', |
|
373 | - 'title_color' => '444444', |
|
374 | - 'form_desc_size' => '14px', |
|
375 | - 'form_desc_color' => '666666', |
|
376 | - |
|
377 | - 'font' => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif', |
|
378 | - 'font_size' => '14px', |
|
379 | - 'label_color' => '444444', |
|
380 | - 'weight' => 'bold', |
|
381 | - 'position' => 'none', |
|
382 | - 'align' => 'left', |
|
383 | - 'width' => '150px', |
|
384 | - 'required_color' => 'B94A48', |
|
385 | - 'required_weight' => 'bold', |
|
386 | - 'label_padding' => '0 0 3px 0', |
|
387 | - |
|
388 | - 'description_font_size' => '12px', |
|
389 | - 'description_color' => '666666', |
|
390 | - 'description_weight' => 'normal', |
|
391 | - 'description_style' => 'normal', |
|
392 | - 'description_align' => 'left', |
|
393 | - |
|
394 | - 'field_font_size' => '14px', |
|
395 | - 'field_height' => '32px', |
|
396 | - 'line_height' => 'normal', |
|
397 | - 'field_width' => '100%', |
|
398 | - 'auto_width' => false, |
|
399 | - 'field_pad' => '6px 10px', |
|
400 | - 'field_margin' => '20px', |
|
401 | - 'text_color' => '555555', |
|
402 | - //'border_color_hv' => 'cccccc', |
|
403 | - 'border_color' => 'cccccc', |
|
404 | - 'field_border_width' => '1px', |
|
405 | - 'field_border_style' => 'solid', |
|
406 | - |
|
407 | - 'bg_color' => 'ffffff', |
|
408 | - //'bg_color_hv' => 'ffffff', |
|
409 | - 'bg_color_active' => 'ffffff', |
|
364 | + 'form_width' => '100%', |
|
365 | + 'form_align' => 'left', |
|
366 | + 'direction' => is_rtl() ? 'rtl' : 'ltr', |
|
367 | + 'fieldset' => '0px', |
|
368 | + 'fieldset_color' => '000000', |
|
369 | + 'fieldset_padding' => '0 0 15px 0', |
|
370 | + 'fieldset_bg_color' => '', |
|
371 | + |
|
372 | + 'title_size' => '20px', |
|
373 | + 'title_color' => '444444', |
|
374 | + 'form_desc_size' => '14px', |
|
375 | + 'form_desc_color' => '666666', |
|
376 | + |
|
377 | + 'font' => '"Lucida Grande","Lucida Sans Unicode",Tahoma,sans-serif', |
|
378 | + 'font_size' => '14px', |
|
379 | + 'label_color' => '444444', |
|
380 | + 'weight' => 'bold', |
|
381 | + 'position' => 'none', |
|
382 | + 'align' => 'left', |
|
383 | + 'width' => '150px', |
|
384 | + 'required_color' => 'B94A48', |
|
385 | + 'required_weight' => 'bold', |
|
386 | + 'label_padding' => '0 0 3px 0', |
|
387 | + |
|
388 | + 'description_font_size' => '12px', |
|
389 | + 'description_color' => '666666', |
|
390 | + 'description_weight' => 'normal', |
|
391 | + 'description_style' => 'normal', |
|
392 | + 'description_align' => 'left', |
|
393 | + |
|
394 | + 'field_font_size' => '14px', |
|
395 | + 'field_height' => '32px', |
|
396 | + 'line_height' => 'normal', |
|
397 | + 'field_width' => '100%', |
|
398 | + 'auto_width' => false, |
|
399 | + 'field_pad' => '6px 10px', |
|
400 | + 'field_margin' => '20px', |
|
401 | + 'text_color' => '555555', |
|
402 | + //'border_color_hv' => 'cccccc', |
|
403 | + 'border_color' => 'cccccc', |
|
404 | + 'field_border_width' => '1px', |
|
405 | + 'field_border_style' => 'solid', |
|
406 | + |
|
407 | + 'bg_color' => 'ffffff', |
|
408 | + //'bg_color_hv' => 'ffffff', |
|
409 | + 'bg_color_active' => 'ffffff', |
|
410 | 410 | 'border_color_active' => '66afe9', |
411 | - 'text_color_error' => '444444', |
|
412 | - 'bg_color_error' => 'ffffff', |
|
411 | + 'text_color_error' => '444444', |
|
412 | + 'bg_color_error' => 'ffffff', |
|
413 | 413 | 'border_color_error' => 'B94A48', |
414 | 414 | 'border_width_error' => '1px', |
415 | 415 | 'border_style_error' => 'solid', |
416 | - 'bg_color_disabled' => 'ffffff', |
|
417 | - 'border_color_disabled' => 'E5E5E5', |
|
418 | - 'text_color_disabled' => 'A1A1A1', |
|
419 | - |
|
420 | - 'radio_align' => 'block', |
|
421 | - 'check_align' => 'block', |
|
422 | - 'check_font_size' => '13px', |
|
423 | - 'check_label_color' => '444444', |
|
424 | - 'check_weight' => 'normal', |
|
425 | - |
|
426 | - 'section_font_size' => '18px', |
|
427 | - 'section_color' => '444444', |
|
428 | - 'section_weight' => 'bold', |
|
429 | - 'section_pad' => '15px 0 3px 0', |
|
430 | - 'section_mar_top' => '15px', |
|
416 | + 'bg_color_disabled' => 'ffffff', |
|
417 | + 'border_color_disabled' => 'E5E5E5', |
|
418 | + 'text_color_disabled' => 'A1A1A1', |
|
419 | + |
|
420 | + 'radio_align' => 'block', |
|
421 | + 'check_align' => 'block', |
|
422 | + 'check_font_size' => '13px', |
|
423 | + 'check_label_color' => '444444', |
|
424 | + 'check_weight' => 'normal', |
|
425 | + |
|
426 | + 'section_font_size' => '18px', |
|
427 | + 'section_color' => '444444', |
|
428 | + 'section_weight' => 'bold', |
|
429 | + 'section_pad' => '15px 0 3px 0', |
|
430 | + 'section_mar_top' => '15px', |
|
431 | 431 | 'section_mar_bottom' => '12px', |
432 | - 'section_bg_color' => '', |
|
433 | - 'section_border_color' => 'e8e8e8', |
|
434 | - 'section_border_width' => '2px', |
|
435 | - 'section_border_style' => 'solid', |
|
436 | - 'section_border_loc' => '-top', |
|
437 | - 'collapse_icon' => '6', |
|
438 | - 'collapse_pos' => 'after', |
|
439 | - 'repeat_icon' => '1', |
|
440 | - |
|
441 | - 'submit_style' => false, |
|
442 | - 'submit_font_size' => '14px', |
|
443 | - 'submit_width' => 'auto', |
|
444 | - 'submit_height' => 'auto', |
|
445 | - 'submit_bg_color' => 'ffffff', |
|
446 | - 'submit_border_color' => 'cccccc', |
|
447 | - 'submit_border_width' => '1px', |
|
448 | - 'submit_text_color' => '444444', |
|
449 | - 'submit_weight' => 'normal', |
|
450 | - 'submit_border_radius' => '4px', |
|
451 | - 'submit_bg_img' => '', |
|
452 | - 'submit_margin' => '10px', |
|
453 | - 'submit_padding' => '6px 11px', |
|
454 | - 'submit_shadow_color' => 'eeeeee', |
|
455 | - 'submit_hover_bg_color' => 'efefef', |
|
456 | - 'submit_hover_color' => '444444', |
|
457 | - 'submit_hover_border_color' => 'cccccc', |
|
458 | - 'submit_active_bg_color' => 'efefef', |
|
459 | - 'submit_active_color' => '444444', |
|
460 | - 'submit_active_border_color' => 'cccccc', |
|
461 | - |
|
462 | - 'border_radius' => '4px', |
|
463 | - 'error_bg' => 'F2DEDE', |
|
464 | - 'error_border' => 'EBCCD1', |
|
465 | - 'error_text' => 'B94A48', |
|
466 | - 'error_font_size' => '14px', |
|
467 | - |
|
468 | - 'success_bg_color' => 'DFF0D8', |
|
469 | - 'success_border_color' => 'D6E9C6', |
|
470 | - 'success_text_color' => '468847', |
|
471 | - 'success_font_size' => '14px', |
|
472 | - |
|
473 | - 'important_style' => false, |
|
474 | - |
|
475 | - 'custom_css' => '', |
|
476 | - ); |
|
477 | - } |
|
432 | + 'section_bg_color' => '', |
|
433 | + 'section_border_color' => 'e8e8e8', |
|
434 | + 'section_border_width' => '2px', |
|
435 | + 'section_border_style' => 'solid', |
|
436 | + 'section_border_loc' => '-top', |
|
437 | + 'collapse_icon' => '6', |
|
438 | + 'collapse_pos' => 'after', |
|
439 | + 'repeat_icon' => '1', |
|
440 | + |
|
441 | + 'submit_style' => false, |
|
442 | + 'submit_font_size' => '14px', |
|
443 | + 'submit_width' => 'auto', |
|
444 | + 'submit_height' => 'auto', |
|
445 | + 'submit_bg_color' => 'ffffff', |
|
446 | + 'submit_border_color' => 'cccccc', |
|
447 | + 'submit_border_width' => '1px', |
|
448 | + 'submit_text_color' => '444444', |
|
449 | + 'submit_weight' => 'normal', |
|
450 | + 'submit_border_radius' => '4px', |
|
451 | + 'submit_bg_img' => '', |
|
452 | + 'submit_margin' => '10px', |
|
453 | + 'submit_padding' => '6px 11px', |
|
454 | + 'submit_shadow_color' => 'eeeeee', |
|
455 | + 'submit_hover_bg_color' => 'efefef', |
|
456 | + 'submit_hover_color' => '444444', |
|
457 | + 'submit_hover_border_color' => 'cccccc', |
|
458 | + 'submit_active_bg_color' => 'efefef', |
|
459 | + 'submit_active_color' => '444444', |
|
460 | + 'submit_active_border_color' => 'cccccc', |
|
461 | + |
|
462 | + 'border_radius' => '4px', |
|
463 | + 'error_bg' => 'F2DEDE', |
|
464 | + 'error_border' => 'EBCCD1', |
|
465 | + 'error_text' => 'B94A48', |
|
466 | + 'error_font_size' => '14px', |
|
467 | + |
|
468 | + 'success_bg_color' => 'DFF0D8', |
|
469 | + 'success_border_color' => 'D6E9C6', |
|
470 | + 'success_text_color' => '468847', |
|
471 | + 'success_font_size' => '14px', |
|
472 | + |
|
473 | + 'important_style' => false, |
|
474 | + |
|
475 | + 'custom_css' => '', |
|
476 | + ); |
|
477 | + } |
|
478 | 478 | |
479 | 479 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
480 | 480 | return 'frm_style_setting'. ( empty($post_field) ? '' : '['. $post_field .']' ) .'[' . $field_name . ']'; |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class FrmStyle { |
3 | - public $number = false; // Unique ID number of the current instance. |
|
3 | + public $number = false; // Unique ID number of the current instance. |
|
4 | 4 | public $id = 0; // the id of the post |
5 | 5 | |
6 | 6 | /** |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | public function get_new() { |
14 | 14 | $this->id = 0; |
15 | 15 | |
16 | - $max_slug_value = pow(36, 6); |
|
16 | + $max_slug_value = pow( 36, 6 ); |
|
17 | 17 | $min_slug_value = 37; // we want to have at least 2 characters in the slug |
18 | - $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 ); |
|
18 | + $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 ); |
|
19 | 19 | |
20 | 20 | $style = array( |
21 | 21 | 'post_type' => FrmStylesController::$post_type, |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public function update( $id = 'default' ) { |
42 | 42 | $all_instances = $this->get_all(); |
43 | 43 | |
44 | - if ( empty($id) ) { |
|
44 | + if ( empty( $id ) ) { |
|
45 | 45 | $new_style = (array) $this->get_new(); |
46 | 46 | $all_instances[] = $new_style; |
47 | 47 | } |
@@ -49,15 +49,15 @@ discard block |
||
49 | 49 | $action_ids = array(); |
50 | 50 | |
51 | 51 | foreach ( $all_instances as $number => $new_instance ) { |
52 | - $new_instance = stripslashes_deep( (array) $new_instance); |
|
52 | + $new_instance = stripslashes_deep( (array) $new_instance ); |
|
53 | 53 | $this->id = $new_instance['ID']; |
54 | - if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) { |
|
55 | - $all_instances[ $number ] = $new_instance; |
|
54 | + if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) { |
|
55 | + $all_instances[$number] = $new_instance; |
|
56 | 56 | |
57 | - if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) { |
|
57 | + if ( $new_instance['menu_order'] && $_POST && empty( $_POST['prev_menu_order'] ) && isset( $_POST['frm_style_setting']['menu_order'] ) ) { |
|
58 | 58 | // this style was set to default, so remove default setting on previous default style |
59 | 59 | $new_instance['menu_order'] = 0; |
60 | - $action_ids[] = $this->save($new_instance); |
|
60 | + $action_ids[] = $this->save( $new_instance ); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | // don't continue if not saving this style |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | $new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] ); |
68 | 68 | $new_instance['post_content'] = $_POST['frm_style_setting']['post_content']; |
69 | 69 | $new_instance['post_type'] = FrmStylesController::$post_type; |
70 | - $new_instance['post_status'] = 'publish'; |
|
70 | + $new_instance['post_status'] = 'publish'; |
|
71 | 71 | $new_instance['menu_order'] = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0; |
72 | 72 | |
73 | - if ( empty($id) ) { |
|
73 | + if ( empty( $id ) ) { |
|
74 | 74 | $new_instance['post_name'] = $new_instance['post_title']; |
75 | 75 | } |
76 | 76 | |
@@ -79,19 +79,19 @@ discard block |
||
79 | 79 | foreach ( $default_settings as $setting => $default ) { |
80 | 80 | if ( strpos( $setting, 'color' ) !== false || in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ) ) ) { |
81 | 81 | //if is a color |
82 | - $new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] ); |
|
83 | - } else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) { |
|
84 | - $new_instance['post_content'][ $setting ] = 0; |
|
82 | + $new_instance['post_content'][$setting] = str_replace( '#', '', $new_instance['post_content'][$setting] ); |
|
83 | + } else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][$setting] ) ) { |
|
84 | + $new_instance['post_content'][$setting] = 0; |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | |
88 | - $all_instances[ $number ] = $new_instance; |
|
88 | + $all_instances[$number] = $new_instance; |
|
89 | 89 | |
90 | - $action_ids[] = $this->save($new_instance); |
|
90 | + $action_ids[] = $this->save( $new_instance ); |
|
91 | 91 | |
92 | 92 | } |
93 | 93 | |
94 | - $this->save_settings($all_instances); |
|
94 | + $this->save_settings( $all_instances ); |
|
95 | 95 | |
96 | 96 | return $action_ids; |
97 | 97 | } |
@@ -100,30 +100,30 @@ discard block |
||
100 | 100 | * Create static css file |
101 | 101 | */ |
102 | 102 | public function save_settings( $styles ) { |
103 | - $filename = FrmAppHelper::plugin_path() .'/css/custom_theme.css.php'; |
|
103 | + $filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php'; |
|
104 | 104 | |
105 | - if ( ! is_file($filename) ) { |
|
105 | + if ( ! is_file( $filename ) ) { |
|
106 | 106 | return; |
107 | 107 | } |
108 | 108 | |
109 | 109 | $defaults = $this->get_defaults(); |
110 | 110 | $uploads = wp_upload_dir(); |
111 | - $target_path = $uploads['basedir'] .'/formidable'; |
|
112 | - $needed_dirs = array( $target_path, $target_path .'/css' ); |
|
111 | + $target_path = $uploads['basedir'] . '/formidable'; |
|
112 | + $needed_dirs = array( $target_path, $target_path . '/css' ); |
|
113 | 113 | $dirs_exist = true; |
114 | 114 | |
115 | 115 | $saving = true; |
116 | - $css = '/* '. __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) .' */'. "\n"; |
|
116 | + $css = '/* ' . __( 'WARNING: Any changes made to this file will be lost when your Formidable settings are updated', 'formidable' ) . ' */' . "\n"; |
|
117 | 117 | |
118 | 118 | ob_start(); |
119 | 119 | $frm_style = $this; |
120 | - include($filename); |
|
120 | + include( $filename ); |
|
121 | 121 | $css .= preg_replace( '/\/\*(.|\s)*?\*\//', '', str_replace( array( "\r\n", "\r", "\n", "\t", ' ' ), '', ob_get_contents() ) ); |
122 | 122 | ob_end_clean(); |
123 | 123 | |
124 | 124 | $access_type = get_filesystem_method(); |
125 | 125 | if ( $access_type === 'direct' ) { |
126 | - $creds = request_filesystem_credentials( site_url() .'/wp-admin/', '', false, false, array() ); |
|
126 | + $creds = request_filesystem_credentials( site_url() . '/wp-admin/', '', false, false, array() ); |
|
127 | 127 | } else { |
128 | 128 | $creds = $this->get_ftp_creds( $access_type ); |
129 | 129 | } |
@@ -138,8 +138,8 @@ discard block |
||
138 | 138 | if ( $dirs_exist ) { |
139 | 139 | global $wp_filesystem; |
140 | 140 | |
141 | - $chmod_dir = defined('FS_CHMOD_DIR') ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 ); |
|
142 | - $chmod_file = defined('FS_CHMOD_FILE') ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
|
141 | + $chmod_dir = defined( 'FS_CHMOD_DIR' ) ? FS_CHMOD_DIR : ( fileperms( ABSPATH ) & 0777 | 0755 ); |
|
142 | + $chmod_file = defined( 'FS_CHMOD_FILE' ) ? FS_CHMOD_FILE : ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
|
143 | 143 | |
144 | 144 | // Create the directories if need be: |
145 | 145 | foreach ( $needed_dirs as $_dir ) { |
@@ -149,33 +149,33 @@ discard block |
||
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | - $index_path = $target_path .'/index.php'; |
|
152 | + $index_path = $target_path . '/index.php'; |
|
153 | 153 | $wp_filesystem->put_contents( $index_path, "<?php\n// Silence is golden.\n?>", $chmod_file ); |
154 | 154 | |
155 | 155 | // only write the file if the folders exist |
156 | 156 | if ( $dirs_exist ) { |
157 | - $css_file = $target_path .'/css/formidablepro.css'; |
|
157 | + $css_file = $target_path . '/css/formidablepro.css'; |
|
158 | 158 | $wp_filesystem->put_contents( $css_file, $css, $chmod_file ); |
159 | 159 | } |
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | - update_option('frmpro_css', $css); |
|
163 | + update_option( 'frmpro_css', $css ); |
|
164 | 164 | |
165 | - delete_transient('frmpro_css'); |
|
166 | - set_transient('frmpro_css', $css); |
|
165 | + delete_transient( 'frmpro_css' ); |
|
166 | + set_transient( 'frmpro_css', $css ); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | private function get_ftp_creds( $type ) { |
170 | 170 | $credentials = get_option( 'ftp_credentials', array( 'hostname' => '', 'username' => '' ) ); |
171 | 171 | |
172 | - $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : $credentials['hostname']; |
|
173 | - $credentials['username'] = defined('FTP_USER') ? FTP_USER : $credentials['username']; |
|
174 | - $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : ''; |
|
172 | + $credentials['hostname'] = defined( 'FTP_HOST' ) ? FTP_HOST : $credentials['hostname']; |
|
173 | + $credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : $credentials['username']; |
|
174 | + $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : ''; |
|
175 | 175 | |
176 | 176 | // Check to see if we are setting the public/private keys for ssh |
177 | - $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : ''; |
|
178 | - $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : ''; |
|
177 | + $credentials['public_key'] = defined( 'FTP_PUBKEY' ) ? FTP_PUBKEY : ''; |
|
178 | + $credentials['private_key'] = defined( 'FTP_PRIKEY' ) ? FTP_PRIKEY : ''; |
|
179 | 179 | |
180 | 180 | // Sanitize the hostname, Some people might pass in odd-data: |
181 | 181 | $credentials['hostname'] = preg_replace( '|\w+://|', '', $credentials['hostname'] ); //Strip any schemes off |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | } |
218 | 218 | |
219 | 219 | public function destroy( $id ) { |
220 | - return wp_delete_post($id); |
|
220 | + return wp_delete_post( $id ); |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | public function get_one() { |
@@ -231,19 +231,19 @@ discard block |
||
231 | 231 | return $style; |
232 | 232 | } |
233 | 233 | |
234 | - $style = get_post($this->id); |
|
234 | + $style = get_post( $this->id ); |
|
235 | 235 | |
236 | 236 | if ( ! $style ) { |
237 | 237 | return $style; |
238 | 238 | } |
239 | 239 | |
240 | - $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
240 | + $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content ); |
|
241 | 241 | |
242 | 242 | $default_values = $this->get_defaults(); |
243 | 243 | |
244 | 244 | // fill default values |
245 | - $style->post_content = $this->override_defaults($style->post_content); |
|
246 | - $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
245 | + $style->post_content = $this->override_defaults( $style->post_content ); |
|
246 | + $style->post_content = wp_parse_args( $style->post_content, $default_values ); |
|
247 | 247 | |
248 | 248 | return $style; |
249 | 249 | } |
@@ -257,21 +257,21 @@ discard block |
||
257 | 257 | 'order' => $order, |
258 | 258 | ); |
259 | 259 | |
260 | - $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts'); |
|
260 | + $temp_styles = FrmAppHelper::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' ); |
|
261 | 261 | |
262 | - if ( empty($temp_styles) ) { |
|
262 | + if ( empty( $temp_styles ) ) { |
|
263 | 263 | global $wpdb; |
264 | 264 | // make sure there wasn't a conflict with the query |
265 | - $query = $wpdb->prepare('SELECT * FROM '. $wpdb->posts .' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish'); |
|
266 | - $temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results'); |
|
265 | + $query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' ); |
|
266 | + $temp_styles = FrmAppHelper::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' ); |
|
267 | 267 | |
268 | - if ( empty($temp_styles) ) { |
|
268 | + if ( empty( $temp_styles ) ) { |
|
269 | 269 | // create a new style if there are none |
270 | 270 | $new = $this->get_new(); |
271 | 271 | $new->post_title = $new->post_name = __( 'Formidable Style', 'formidable' ); |
272 | 272 | $new->menu_order = 1; |
273 | - $new = $this->save( (array) $new); |
|
274 | - $this->update('default'); |
|
273 | + $new = $this->save( (array) $new ); |
|
274 | + $this->update( 'default' ); |
|
275 | 275 | |
276 | 276 | $post_atts['include'] = $new; |
277 | 277 | |
@@ -295,25 +295,25 @@ discard block |
||
295 | 295 | } |
296 | 296 | } |
297 | 297 | |
298 | - $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content); |
|
298 | + $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content ); |
|
299 | 299 | |
300 | 300 | // fill default values |
301 | - $style->post_content = $this->override_defaults($style->post_content); |
|
302 | - $style->post_content = wp_parse_args( $style->post_content, $default_values); |
|
301 | + $style->post_content = $this->override_defaults( $style->post_content ); |
|
302 | + $style->post_content = wp_parse_args( $style->post_content, $default_values ); |
|
303 | 303 | |
304 | - $styles[ $style->ID ] = $style; |
|
304 | + $styles[$style->ID] = $style; |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | if ( ! $default_style ) { |
308 | - $default_style = reset($styles); |
|
309 | - $styles[ $default_style->ID ]->menu_order = 1; |
|
308 | + $default_style = reset( $styles ); |
|
309 | + $styles[$default_style->ID]->menu_order = 1; |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | return $styles; |
313 | 313 | } |
314 | 314 | |
315 | 315 | public function get_default_style( $styles = null ) { |
316 | - if ( ! isset($styles) ) { |
|
316 | + if ( ! isset( $styles ) ) { |
|
317 | 317 | $styles = $this->get_all( 'menu_order', 'DESC', 1 ); |
318 | 318 | } |
319 | 319 | |
@@ -325,24 +325,24 @@ discard block |
||
325 | 325 | } |
326 | 326 | |
327 | 327 | public function override_defaults( $settings ) { |
328 | - if ( ! is_array($settings) ) { |
|
328 | + if ( ! is_array( $settings ) ) { |
|
329 | 329 | return $settings; |
330 | 330 | } |
331 | 331 | |
332 | - $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height']; |
|
332 | + $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height']; |
|
333 | 333 | |
334 | - if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) { |
|
334 | + if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) { |
|
335 | 335 | $settings['form_desc_size'] = $settings['description_font_size']; |
336 | 336 | $settings['form_desc_color'] = $settings['description_color']; |
337 | 337 | $settings['title_color'] = $settings['label_color']; |
338 | 338 | } |
339 | 339 | |
340 | - if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) { |
|
340 | + if ( ! isset( $settings['section_color'] ) && isset( $settings['label_color'] ) ) { |
|
341 | 341 | $settings['section_color'] = $settings['label_color']; |
342 | 342 | $settings['section_border_color'] = $settings['border_color']; |
343 | 343 | } |
344 | 344 | |
345 | - if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) { |
|
345 | + if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) { |
|
346 | 346 | $settings['submit_hover_bg_color'] = $settings['submit_bg_color']; |
347 | 347 | $settings['submit_hover_color'] = $settings['submit_text_color']; |
348 | 348 | $settings['submit_hover_border_color'] = $settings['submit_border_color']; |
@@ -477,7 +477,7 @@ discard block |
||
477 | 477 | } |
478 | 478 | |
479 | 479 | public function get_field_name( $field_name, $post_field = 'post_content' ) { |
480 | - return 'frm_style_setting'. ( empty($post_field) ? '' : '['. $post_field .']' ) .'[' . $field_name . ']'; |
|
480 | + return 'frm_style_setting' . ( empty( $post_field ) ? '' : '[' . $post_field . ']' ) . '[' . $field_name . ']'; |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | public static function get_bold_options() { |
@@ -3,14 +3,14 @@ discard block |
||
3 | 3 | class FrmAppController { |
4 | 4 | |
5 | 5 | public static function menu() { |
6 | - FrmAppHelper::maybe_add_permissions(); |
|
7 | - if ( ! current_user_can( 'frm_view_forms' ) ) { |
|
8 | - return; |
|
9 | - } |
|
6 | + FrmAppHelper::maybe_add_permissions(); |
|
7 | + if ( ! current_user_can( 'frm_view_forms' ) ) { |
|
8 | + return; |
|
9 | + } |
|
10 | 10 | |
11 | - $frm_settings = FrmAppHelper::get_settings(); |
|
12 | - add_menu_page( 'Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', 'FrmFormsController::route', FrmAppHelper::plugin_url() . '/images/form_16.png', self::get_menu_position() ); |
|
13 | - } |
|
11 | + $frm_settings = FrmAppHelper::get_settings(); |
|
12 | + add_menu_page( 'Formidable', $frm_settings->menu, 'frm_view_forms', 'formidable', 'FrmFormsController::route', FrmAppHelper::plugin_url() . '/images/form_16.png', self::get_menu_position() ); |
|
13 | + } |
|
14 | 14 | |
15 | 15 | private static function get_menu_position() { |
16 | 16 | $count = count( get_post_types( array( 'show_ui' => true, '_builtin' => false, 'show_in_menu' => true ) ) ); |
@@ -19,55 +19,55 @@ discard block |
||
19 | 19 | return $pos; |
20 | 20 | } |
21 | 21 | |
22 | - public static function load_wp_admin_style() { |
|
23 | - FrmAppHelper::load_font_style(); |
|
24 | - } |
|
22 | + public static function load_wp_admin_style() { |
|
23 | + FrmAppHelper::load_font_style(); |
|
24 | + } |
|
25 | 25 | |
26 | 26 | public static function get_form_nav( $form, $show_nav = false, $title = 'show' ) { |
27 | - global $pagenow, $frm_vars; |
|
27 | + global $pagenow, $frm_vars; |
|
28 | 28 | |
29 | 29 | $show_nav = FrmAppHelper::get_param( 'show_nav', $show_nav, 'get', 'absint' ); |
30 | - if ( empty( $show_nav ) ) { |
|
31 | - return; |
|
32 | - } |
|
30 | + if ( empty( $show_nav ) ) { |
|
31 | + return; |
|
32 | + } |
|
33 | 33 | |
34 | 34 | $current_page = isset( $_GET['page'] ) ? FrmAppHelper::simple_get( 'page', 'sanitize_title' ) : FrmAppHelper::simple_get( 'post_type', 'sanitize_title', 'None' ); |
35 | 35 | |
36 | - if ( $form ) { |
|
36 | + if ( $form ) { |
|
37 | 37 | FrmForm::maybe_get_form( $form ); |
38 | 38 | |
39 | - if ( is_object( $form ) ) { |
|
40 | - $id = $form->id; |
|
41 | - } |
|
42 | - } |
|
39 | + if ( is_object( $form ) ) { |
|
40 | + $id = $form->id; |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | - if ( ! isset( $id ) ) { |
|
45 | - $form = $id = false; |
|
46 | - } |
|
44 | + if ( ! isset( $id ) ) { |
|
45 | + $form = $id = false; |
|
46 | + } |
|
47 | 47 | |
48 | - include( FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php' ); |
|
49 | - } |
|
48 | + include( FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php' ); |
|
49 | + } |
|
50 | 50 | |
51 | - // Adds a settings link to the plugins page |
|
52 | - public static function settings_link( $links ) { |
|
51 | + // Adds a settings link to the plugins page |
|
52 | + public static function settings_link( $links ) { |
|
53 | 53 | $settings = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings' ) ) . '">' . __( 'Settings', 'formidable' ) . '</a>'; |
54 | - array_unshift( $links, $settings ); |
|
54 | + array_unshift( $links, $settings ); |
|
55 | 55 | |
56 | - return $links; |
|
57 | - } |
|
56 | + return $links; |
|
57 | + } |
|
58 | 58 | |
59 | - public static function pro_get_started_headline() { |
|
60 | - // Don't display this error as we're upgrading the thing, or if the user shouldn't see the message |
|
61 | - if ( 'upgrade-plugin' == FrmAppHelper::simple_get( 'action', 'sanitize_title' ) || ! current_user_can( 'update_plugins' ) ) { |
|
62 | - return; |
|
63 | - } |
|
59 | + public static function pro_get_started_headline() { |
|
60 | + // Don't display this error as we're upgrading the thing, or if the user shouldn't see the message |
|
61 | + if ( 'upgrade-plugin' == FrmAppHelper::simple_get( 'action', 'sanitize_title' ) || ! current_user_can( 'update_plugins' ) ) { |
|
62 | + return; |
|
63 | + } |
|
64 | 64 | |
65 | 65 | if ( get_site_option( 'frmpro-authorized' ) && ! file_exists( FrmAppHelper::plugin_path() . '/pro/formidable-pro.php' ) ) { |
66 | - FrmAppHelper::load_admin_wide_js(); |
|
66 | + FrmAppHelper::load_admin_wide_js(); |
|
67 | 67 | |
68 | - // user is authorized, but running free version |
|
69 | - $inst_install_url = 'https://formidablepro.com/knowledgebase/install-formidable-forms/'; |
|
70 | - ?> |
|
68 | + // user is authorized, but running free version |
|
69 | + $inst_install_url = 'https://formidablepro.com/knowledgebase/install-formidable-forms/'; |
|
70 | + ?> |
|
71 | 71 | <div class="error" class="frm_previous_install"> |
72 | 72 | <?php |
73 | 73 | echo wp_kses_post( apply_filters( 'frm_pro_update_msg', |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | ) ); ?> |
80 | 80 | </div> |
81 | 81 | <?php |
82 | - } |
|
83 | - } |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | /** |
86 | 86 | * If there are CURL problems on this server, wp_remote_post won't work for installing |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
125 | - public static function admin_js() { |
|
125 | + public static function admin_js() { |
|
126 | 126 | $version = FrmAppHelper::plugin_version(); |
127 | 127 | FrmAppHelper::load_admin_wide_js( false ); |
128 | 128 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | 'bootstrap_tooltip', 'bootstrap-multiselect', |
134 | 134 | ), $version, true ); |
135 | 135 | wp_register_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css', array(), $version ); |
136 | - wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() . '/js/bootstrap.min.js', array( 'jquery' ), '3.3.4' ); |
|
136 | + wp_register_script( 'bootstrap_tooltip', FrmAppHelper::plugin_url() . '/js/bootstrap.min.js', array( 'jquery' ), '3.3.4' ); |
|
137 | 137 | |
138 | 138 | // load multselect js |
139 | 139 | wp_register_script( 'bootstrap-multiselect', FrmAppHelper::plugin_url() . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip' ), '0.9.8', true ); |
@@ -144,78 +144,78 @@ discard block |
||
144 | 144 | global $pagenow; |
145 | 145 | if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow == 'edit.php' && $post_type == 'frm_display' ) ) { |
146 | 146 | |
147 | - wp_enqueue_script( 'admin-widgets' ); |
|
148 | - wp_enqueue_style( 'widgets' ); |
|
149 | - wp_enqueue_script( 'formidable' ); |
|
150 | - wp_enqueue_script( 'formidable_admin' ); |
|
147 | + wp_enqueue_script( 'admin-widgets' ); |
|
148 | + wp_enqueue_style( 'widgets' ); |
|
149 | + wp_enqueue_script( 'formidable' ); |
|
150 | + wp_enqueue_script( 'formidable_admin' ); |
|
151 | 151 | FrmAppHelper::localize_script( 'admin' ); |
152 | 152 | |
153 | - wp_enqueue_style( 'formidable-admin' ); |
|
154 | - add_thickbox(); |
|
153 | + wp_enqueue_style( 'formidable-admin' ); |
|
154 | + add_thickbox(); |
|
155 | 155 | |
156 | - wp_register_script( 'formidable-editinplace', FrmAppHelper::plugin_url() . '/js/jquery/jquery.editinplace.packed.js', array( 'jquery' ), '2.3.0' ); |
|
156 | + wp_register_script( 'formidable-editinplace', FrmAppHelper::plugin_url() . '/js/jquery/jquery.editinplace.packed.js', array( 'jquery' ), '2.3.0' ); |
|
157 | 157 | |
158 | - } else if ( $pagenow == 'post.php' || ( $pagenow == 'post-new.php' && $post_type == 'frm_display' ) ) { |
|
159 | - if ( isset( $_REQUEST['post_type'] ) ) { |
|
160 | - $post_type = sanitize_title( $_REQUEST['post_type'] ); |
|
158 | + } else if ( $pagenow == 'post.php' || ( $pagenow == 'post-new.php' && $post_type == 'frm_display' ) ) { |
|
159 | + if ( isset( $_REQUEST['post_type'] ) ) { |
|
160 | + $post_type = sanitize_title( $_REQUEST['post_type'] ); |
|
161 | 161 | } else if ( isset( $_REQUEST['post'] ) && absint( $_REQUEST['post'] ) ) { |
162 | 162 | $post = get_post( absint( $_REQUEST['post'] ) ); |
163 | - if ( ! $post ) { |
|
164 | - return; |
|
165 | - } |
|
166 | - $post_type = $post->post_type; |
|
167 | - } else { |
|
168 | - return; |
|
169 | - } |
|
170 | - |
|
171 | - if ( $post_type == 'frm_display' ) { |
|
172 | - wp_enqueue_script( 'jquery-ui-draggable' ); |
|
173 | - wp_enqueue_script( 'formidable_admin' ); |
|
174 | - wp_enqueue_style( 'formidable-admin' ); |
|
163 | + if ( ! $post ) { |
|
164 | + return; |
|
165 | + } |
|
166 | + $post_type = $post->post_type; |
|
167 | + } else { |
|
168 | + return; |
|
169 | + } |
|
170 | + |
|
171 | + if ( $post_type == 'frm_display' ) { |
|
172 | + wp_enqueue_script( 'jquery-ui-draggable' ); |
|
173 | + wp_enqueue_script( 'formidable_admin' ); |
|
174 | + wp_enqueue_style( 'formidable-admin' ); |
|
175 | 175 | FrmAppHelper::localize_script( 'admin' ); |
176 | - } |
|
177 | - } else if ( $pagenow == 'widgets.php' ) { |
|
178 | - FrmAppHelper::load_admin_wide_js(); |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - public static function wp_admin_body_class( $classes ) { |
|
183 | - global $wp_version; |
|
184 | - //we need this class everywhere in the admin for the menu |
|
185 | - if ( version_compare( $wp_version, '3.7.2', '>' ) ) { |
|
186 | - $classes .= ' frm_38_trigger'; |
|
187 | - } |
|
188 | - |
|
189 | - return $classes; |
|
190 | - } |
|
191 | - |
|
192 | - public static function load_lang() { |
|
193 | - load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() . '/languages/' ); |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Filter shortcodes in text widgets |
|
198 | - */ |
|
199 | - public static function widget_text_filter( $content ) { |
|
200 | - $regex = '/\[\s*(formidable|display-frm-data|frm-stats|frm-graph|frm-entry-links|formresults|frm-search)\s+.*\]/'; |
|
201 | - return preg_replace_callback( $regex, 'FrmAppHelper::widget_text_filter_callback', $content ); |
|
202 | - } |
|
203 | - |
|
204 | - public static function widget_text_filter_callback( $matches ) { |
|
205 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::widget_text_filter_callback' ); |
|
206 | - return FrmAppHelper::widget_text_filter_callback( $matches ); |
|
207 | - } |
|
208 | - |
|
209 | - public static function front_head() { |
|
210 | - if ( is_multisite() ) { |
|
211 | - $old_db_version = get_option( 'frm_db_version' ); |
|
212 | - $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false; |
|
213 | - if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) || |
|
214 | - ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) { |
|
215 | - self::install( $old_db_version ); |
|
216 | - } |
|
217 | - } |
|
218 | - } |
|
176 | + } |
|
177 | + } else if ( $pagenow == 'widgets.php' ) { |
|
178 | + FrmAppHelper::load_admin_wide_js(); |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + public static function wp_admin_body_class( $classes ) { |
|
183 | + global $wp_version; |
|
184 | + //we need this class everywhere in the admin for the menu |
|
185 | + if ( version_compare( $wp_version, '3.7.2', '>' ) ) { |
|
186 | + $classes .= ' frm_38_trigger'; |
|
187 | + } |
|
188 | + |
|
189 | + return $classes; |
|
190 | + } |
|
191 | + |
|
192 | + public static function load_lang() { |
|
193 | + load_plugin_textdomain( 'formidable', false, FrmAppHelper::plugin_folder() . '/languages/' ); |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Filter shortcodes in text widgets |
|
198 | + */ |
|
199 | + public static function widget_text_filter( $content ) { |
|
200 | + $regex = '/\[\s*(formidable|display-frm-data|frm-stats|frm-graph|frm-entry-links|formresults|frm-search)\s+.*\]/'; |
|
201 | + return preg_replace_callback( $regex, 'FrmAppHelper::widget_text_filter_callback', $content ); |
|
202 | + } |
|
203 | + |
|
204 | + public static function widget_text_filter_callback( $matches ) { |
|
205 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::widget_text_filter_callback' ); |
|
206 | + return FrmAppHelper::widget_text_filter_callback( $matches ); |
|
207 | + } |
|
208 | + |
|
209 | + public static function front_head() { |
|
210 | + if ( is_multisite() ) { |
|
211 | + $old_db_version = get_option( 'frm_db_version' ); |
|
212 | + $pro_db_version = FrmAppHelper::pro_is_installed() ? get_option( 'frmpro_db_version' ) : false; |
|
213 | + if ( ( (int) $old_db_version < (int) FrmAppHelper::$db_version ) || |
|
214 | + ( FrmAppHelper::pro_is_installed() && (int) $pro_db_version < (int) FrmAppHelper::$pro_db_version ) ) { |
|
215 | + self::install( $old_db_version ); |
|
216 | + } |
|
217 | + } |
|
218 | + } |
|
219 | 219 | |
220 | 220 | public static function localize_script( $location ) { |
221 | 221 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmAppHelper::localize_script' ); |
@@ -275,77 +275,77 @@ discard block |
||
275 | 275 | wp_die(); |
276 | 276 | } |
277 | 277 | |
278 | - public static function activation_install() { |
|
279 | - FrmAppHelper::delete_cache_and_transient( 'frm_plugin_version' ); |
|
280 | - FrmFormActionsController::actions_init(); |
|
281 | - self::install(); |
|
282 | - } |
|
278 | + public static function activation_install() { |
|
279 | + FrmAppHelper::delete_cache_and_transient( 'frm_plugin_version' ); |
|
280 | + FrmFormActionsController::actions_init(); |
|
281 | + self::install(); |
|
282 | + } |
|
283 | 283 | |
284 | - public static function install( $old_db_version = false ) { |
|
285 | - $frmdb = new FrmDb(); |
|
286 | - $frmdb->upgrade( $old_db_version ); |
|
287 | - } |
|
284 | + public static function install( $old_db_version = false ) { |
|
285 | + $frmdb = new FrmDb(); |
|
286 | + $frmdb->upgrade( $old_db_version ); |
|
287 | + } |
|
288 | 288 | |
289 | - public static function uninstall() { |
|
290 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
289 | + public static function uninstall() { |
|
290 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
291 | 291 | |
292 | - if ( current_user_can( 'administrator' ) ) { |
|
293 | - $frmdb = new FrmDb(); |
|
294 | - $frmdb->uninstall(); |
|
292 | + if ( current_user_can( 'administrator' ) ) { |
|
293 | + $frmdb = new FrmDb(); |
|
294 | + $frmdb->uninstall(); |
|
295 | 295 | |
296 | 296 | //disable the plugin and redirect after uninstall so the tables don't get added right back |
297 | 297 | deactivate_plugins( FrmAppHelper::plugin_folder() . '/formidable.php', false, false ); |
298 | 298 | echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) ); |
299 | - } else { |
|
300 | - $frm_settings = FrmAppHelper::get_settings(); |
|
301 | - wp_die( $frm_settings->admin_permission ); |
|
302 | - } |
|
303 | - wp_die(); |
|
304 | - } |
|
305 | - |
|
306 | - public static function drop_tables( $tables ) { |
|
307 | - global $wpdb; |
|
308 | - $tables[] = $wpdb->prefix . 'frm_fields'; |
|
309 | - $tables[] = $wpdb->prefix . 'frm_forms'; |
|
310 | - $tables[] = $wpdb->prefix . 'frm_items'; |
|
311 | - $tables[] = $wpdb->prefix . 'frm_item_metas'; |
|
312 | - return $tables; |
|
313 | - } |
|
314 | - |
|
315 | - // Routes for wordpress pages -- we're just replacing content here folks. |
|
316 | - public static function page_route( $content ) { |
|
317 | - global $post; |
|
318 | - |
|
319 | - $frm_settings = FrmAppHelper::get_settings(); |
|
320 | - if ( $post && $post->ID == $frm_settings->preview_page_id && isset( $_GET['form'] ) ) { |
|
321 | - $content = FrmFormsController::page_preview(); |
|
322 | - } |
|
323 | - |
|
324 | - return $content; |
|
325 | - } |
|
326 | - |
|
327 | - public static function update_message( $features ) { |
|
328 | - _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::update_message' ); |
|
329 | - return FrmAppHelper::update_message( $features ); |
|
330 | - } |
|
331 | - |
|
332 | - public static function deauthorize() { |
|
333 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
334 | - |
|
335 | - delete_option( 'frmpro-credentials' ); |
|
336 | - delete_option( 'frmpro-authorized' ); |
|
337 | - delete_site_option( 'frmpro-credentials' ); |
|
338 | - delete_site_option( 'frmpro-authorized' ); |
|
339 | - wp_die(); |
|
340 | - } |
|
341 | - |
|
342 | - public static function get_form_shortcode( $atts ) { |
|
343 | - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' ); |
|
344 | - return FrmFormsController::get_form_shortcode( $atts ); |
|
345 | - } |
|
346 | - |
|
347 | - public static function get_postbox_class() { |
|
348 | - _deprecated_function( __FUNCTION__, '2.0' ); |
|
349 | - return 'postbox-container'; |
|
350 | - } |
|
299 | + } else { |
|
300 | + $frm_settings = FrmAppHelper::get_settings(); |
|
301 | + wp_die( $frm_settings->admin_permission ); |
|
302 | + } |
|
303 | + wp_die(); |
|
304 | + } |
|
305 | + |
|
306 | + public static function drop_tables( $tables ) { |
|
307 | + global $wpdb; |
|
308 | + $tables[] = $wpdb->prefix . 'frm_fields'; |
|
309 | + $tables[] = $wpdb->prefix . 'frm_forms'; |
|
310 | + $tables[] = $wpdb->prefix . 'frm_items'; |
|
311 | + $tables[] = $wpdb->prefix . 'frm_item_metas'; |
|
312 | + return $tables; |
|
313 | + } |
|
314 | + |
|
315 | + // Routes for wordpress pages -- we're just replacing content here folks. |
|
316 | + public static function page_route( $content ) { |
|
317 | + global $post; |
|
318 | + |
|
319 | + $frm_settings = FrmAppHelper::get_settings(); |
|
320 | + if ( $post && $post->ID == $frm_settings->preview_page_id && isset( $_GET['form'] ) ) { |
|
321 | + $content = FrmFormsController::page_preview(); |
|
322 | + } |
|
323 | + |
|
324 | + return $content; |
|
325 | + } |
|
326 | + |
|
327 | + public static function update_message( $features ) { |
|
328 | + _deprecated_function( __FUNCTION__, '2.0', 'FrmAppHelper::update_message' ); |
|
329 | + return FrmAppHelper::update_message( $features ); |
|
330 | + } |
|
331 | + |
|
332 | + public static function deauthorize() { |
|
333 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
334 | + |
|
335 | + delete_option( 'frmpro-credentials' ); |
|
336 | + delete_option( 'frmpro-authorized' ); |
|
337 | + delete_site_option( 'frmpro-credentials' ); |
|
338 | + delete_site_option( 'frmpro-authorized' ); |
|
339 | + wp_die(); |
|
340 | + } |
|
341 | + |
|
342 | + public static function get_form_shortcode( $atts ) { |
|
343 | + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode()' ); |
|
344 | + return FrmFormsController::get_form_shortcode( $atts ); |
|
345 | + } |
|
346 | + |
|
347 | + public static function get_postbox_class() { |
|
348 | + _deprecated_function( __FUNCTION__, '2.0' ); |
|
349 | + return 'postbox-container'; |
|
350 | + } |
|
351 | 351 | } |
@@ -2,199 +2,199 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmEntriesController { |
4 | 4 | |
5 | - public static function menu() { |
|
5 | + public static function menu() { |
|
6 | 6 | FrmAppHelper::force_capability( 'frm_view_entries' ); |
7 | 7 | |
8 | - add_submenu_page('formidable', 'Formidable | '. __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); |
|
8 | + add_submenu_page('formidable', 'Formidable | '. __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); |
|
9 | 9 | |
10 | 10 | if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show' ) ) ) { |
11 | - $frm_settings = FrmAppHelper::get_settings(); |
|
11 | + $frm_settings = FrmAppHelper::get_settings(); |
|
12 | 12 | add_filter( 'manage_' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entries_columns', 'FrmEntriesController::manage_columns' ); |
13 | 13 | add_filter( 'get_user_option_manage' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entriescolumnshidden', 'FrmEntriesController::hidden_columns' ); |
14 | 14 | add_filter( 'manage_' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entries_sortable_columns', 'FrmEntriesController::sortable_columns' ); |
15 | - } |
|
16 | - } |
|
15 | + } |
|
16 | + } |
|
17 | 17 | |
18 | - /* Display in Back End */ |
|
19 | - public static function route() { |
|
18 | + /* Display in Back End */ |
|
19 | + public static function route() { |
|
20 | 20 | $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' ); |
21 | 21 | |
22 | - switch ( $action ) { |
|
23 | - case 'show': |
|
24 | - case 'destroy': |
|
25 | - case 'destroy_all': |
|
26 | - return self::$action(); |
|
22 | + switch ( $action ) { |
|
23 | + case 'show': |
|
24 | + case 'destroy': |
|
25 | + case 'destroy_all': |
|
26 | + return self::$action(); |
|
27 | 27 | |
28 | - default: |
|
29 | - do_action( 'frm_entry_action_route', $action ); |
|
30 | - if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) { |
|
31 | - return; |
|
32 | - } |
|
28 | + default: |
|
29 | + do_action( 'frm_entry_action_route', $action ); |
|
30 | + if ( apply_filters( 'frm_entry_stop_action_route', false, $action ) ) { |
|
31 | + return; |
|
32 | + } |
|
33 | 33 | |
34 | - return self::display_list(); |
|
35 | - } |
|
36 | - } |
|
34 | + return self::display_list(); |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | 38 | public static function contextual_help( $help, $screen_id, $screen ) { |
39 | - // Only add to certain screens. add_help_tab was introduced in WordPress 3.3 |
|
40 | - if ( $screen_id != 'formidable_page_formidable-entries' || ! method_exists( $screen, 'add_help_tab' ) ) { |
|
41 | - return $help; |
|
42 | - } |
|
39 | + // Only add to certain screens. add_help_tab was introduced in WordPress 3.3 |
|
40 | + if ( $screen_id != 'formidable_page_formidable-entries' || ! method_exists( $screen, 'add_help_tab' ) ) { |
|
41 | + return $help; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
45 | 45 | $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
46 | 46 | if ( $page != 'formidable-entries' || ( ! empty( $action ) && $action != 'list' ) ) { |
47 | - return $help; |
|
48 | - } |
|
47 | + return $help; |
|
48 | + } |
|
49 | 49 | unset( $action, $page ); |
50 | 50 | |
51 | - $screen->add_help_tab( array( |
|
52 | - 'id' => 'formidable-entries-tab', |
|
53 | - 'title' => __( 'Overview', 'formidable' ), |
|
51 | + $screen->add_help_tab( array( |
|
52 | + 'id' => 'formidable-entries-tab', |
|
53 | + 'title' => __( 'Overview', 'formidable' ), |
|
54 | 54 | 'content' => '<p>' . esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) .'</p> <p>'. esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) . '</p>', |
55 | - )); |
|
55 | + )); |
|
56 | 56 | |
57 | - $screen->set_help_sidebar( |
|
57 | + $screen->set_help_sidebar( |
|
58 | 58 | '<p><strong>' . esc_html__( 'For more information:', 'formidable' ) . '</strong></p>' . |
59 | 59 | '<p><a href="http://formidablepro.com/knowledgebase/manage-entries-from-the-back-end/" target="_blank">' . esc_html__( 'Documentation on Entries', 'formidable' ) . '</a></p>' . |
60 | 60 | '<p><a href="http://formidablepro.com/help-topics/" target="_blank">' . esc_html__( 'Support', 'formidable' ) . '</a></p>' |
61 | - ); |
|
61 | + ); |
|
62 | 62 | |
63 | - return $help; |
|
64 | - } |
|
63 | + return $help; |
|
64 | + } |
|
65 | 65 | |
66 | 66 | public static function manage_columns( $columns ) { |
67 | - global $frm_vars, $wpdb; |
|
67 | + global $frm_vars, $wpdb; |
|
68 | 68 | $form_id = FrmForm::get_current_form_id(); |
69 | 69 | |
70 | - $columns[ $form_id .'_id' ] = 'ID'; |
|
70 | + $columns[ $form_id .'_id' ] = 'ID'; |
|
71 | 71 | $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' ); |
72 | 72 | |
73 | - if ( ! $form_id ) { |
|
74 | - return $columns; |
|
75 | - } |
|
73 | + if ( ! $form_id ) { |
|
74 | + return $columns; |
|
75 | + } |
|
76 | 76 | |
77 | - $form_cols = FrmField::get_all_for_form($form_id, '', 'include'); |
|
77 | + $form_cols = FrmField::get_all_for_form($form_id, '', 'include'); |
|
78 | 78 | |
79 | - foreach ( $form_cols as $form_col ) { |
|
79 | + foreach ( $form_cols as $form_col ) { |
|
80 | 80 | if ( FrmField::is_no_save_field( $form_col->type ) ) { |
81 | - continue; |
|
82 | - } |
|
81 | + continue; |
|
82 | + } |
|
83 | 83 | |
84 | - if ( $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ) ) { |
|
84 | + if ( $form_col->type == 'form' && isset( $form_col->field_options['form_select'] ) && ! empty( $form_col->field_options['form_select'] ) ) { |
|
85 | 85 | $sub_form_cols = FrmField::get_all_for_form( $form_col->field_options['form_select'] ); |
86 | 86 | |
87 | - if ( $sub_form_cols ) { |
|
88 | - foreach ( $sub_form_cols as $k => $sub_form_col ) { |
|
87 | + if ( $sub_form_cols ) { |
|
88 | + foreach ( $sub_form_cols as $k => $sub_form_col ) { |
|
89 | 89 | if ( FrmField::is_no_save_field( $sub_form_col->type ) ) { |
90 | - unset( $sub_form_cols[ $k ] ); |
|
91 | - continue; |
|
92 | - } |
|
90 | + unset( $sub_form_cols[ $k ] ); |
|
91 | + continue; |
|
92 | + } |
|
93 | 93 | $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 ); |
94 | - unset($sub_form_col); |
|
95 | - } |
|
96 | - } |
|
97 | - unset($sub_form_cols); |
|
98 | - } else { |
|
99 | - $col_id = $form_col->field_key; |
|
100 | - if ( $form_col->form_id != $form_id ) { |
|
101 | - $col_id .= '-_-form'. $form_col->form_id; |
|
102 | - } |
|
103 | - |
|
104 | - if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) { |
|
105 | - $columns[ $form_id .'_frmsep_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
106 | - } |
|
107 | - $columns[ $form_id .'_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - $columns[ $form_id .'_created_at' ] = __( 'Entry creation date', 'formidable' ); |
|
112 | - $columns[ $form_id .'_updated_at' ] = __( 'Entry update date', 'formidable' ); |
|
113 | - $columns[ $form_id .'_ip' ] = 'IP'; |
|
114 | - |
|
115 | - $frm_vars['cols'] = $columns; |
|
94 | + unset($sub_form_col); |
|
95 | + } |
|
96 | + } |
|
97 | + unset($sub_form_cols); |
|
98 | + } else { |
|
99 | + $col_id = $form_col->field_key; |
|
100 | + if ( $form_col->form_id != $form_id ) { |
|
101 | + $col_id .= '-_-form'. $form_col->form_id; |
|
102 | + } |
|
103 | + |
|
104 | + if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) { |
|
105 | + $columns[ $form_id .'_frmsep_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
106 | + } |
|
107 | + $columns[ $form_id .'_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + $columns[ $form_id .'_created_at' ] = __( 'Entry creation date', 'formidable' ); |
|
112 | + $columns[ $form_id .'_updated_at' ] = __( 'Entry update date', 'formidable' ); |
|
113 | + $columns[ $form_id .'_ip' ] = 'IP'; |
|
114 | + |
|
115 | + $frm_vars['cols'] = $columns; |
|
116 | 116 | |
117 | 117 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
118 | 118 | if ( FrmAppHelper::is_admin_page( 'formidable-entries' ) && in_array( $action, array( '', 'list', 'destroy' ) ) ) { |
119 | 119 | add_screen_option( 'per_page', array( 'label' => __( 'Entries', 'formidable' ), 'default' => 20, 'option' => 'formidable_page_formidable_entries_per_page' ) ); |
120 | - } |
|
120 | + } |
|
121 | 121 | |
122 | - return $columns; |
|
123 | - } |
|
122 | + return $columns; |
|
123 | + } |
|
124 | 124 | |
125 | 125 | public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) { |
126 | - $frm_settings = FrmAppHelper::get_settings(); |
|
127 | - if ( $meta_key != 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden' || $meta_value == $prev_value ) { |
|
128 | - return $check; |
|
129 | - } |
|
126 | + $frm_settings = FrmAppHelper::get_settings(); |
|
127 | + if ( $meta_key != 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden' || $meta_value == $prev_value ) { |
|
128 | + return $check; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | if ( empty( $prev_value ) ) { |
132 | - $prev_value = get_metadata('user', $object_id, $meta_key, true); |
|
133 | - } |
|
132 | + $prev_value = get_metadata('user', $object_id, $meta_key, true); |
|
133 | + } |
|
134 | 134 | |
135 | - global $frm_vars; |
|
136 | - //add a check so we don't create a loop |
|
137 | - $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
135 | + global $frm_vars; |
|
136 | + //add a check so we don't create a loop |
|
137 | + $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
138 | 138 | |
139 | - return $check; |
|
140 | - } |
|
139 | + return $check; |
|
140 | + } |
|
141 | 141 | |
142 | - //add hidden columns back from other forms |
|
142 | + //add hidden columns back from other forms |
|
143 | 143 | public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) { |
144 | - $frm_settings = FrmAppHelper::get_settings(); |
|
145 | - |
|
146 | - $sanitized = sanitize_title($frm_settings->menu); |
|
147 | - if ( $meta_key != 'manage'. $sanitized .'_page_formidable-entriescolumnshidden' ) { |
|
148 | - return; |
|
149 | - } |
|
150 | - |
|
151 | - global $frm_vars; |
|
152 | - if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) { |
|
153 | - return; //don't continue if there's no previous value |
|
154 | - } |
|
155 | - |
|
156 | - foreach ( $meta_value as $mk => $mv ) { |
|
157 | - //remove blank values |
|
158 | - if ( empty( $mv ) ) { |
|
159 | - unset( $meta_value[ $mk ] ); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - $cur_form_prefix = reset($meta_value); |
|
164 | - $cur_form_prefix = explode('_', $cur_form_prefix); |
|
165 | - $cur_form_prefix = $cur_form_prefix[0]; |
|
166 | - $save = false; |
|
167 | - |
|
168 | - foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) { |
|
144 | + $frm_settings = FrmAppHelper::get_settings(); |
|
145 | + |
|
146 | + $sanitized = sanitize_title($frm_settings->menu); |
|
147 | + if ( $meta_key != 'manage'. $sanitized .'_page_formidable-entriescolumnshidden' ) { |
|
148 | + return; |
|
149 | + } |
|
150 | + |
|
151 | + global $frm_vars; |
|
152 | + if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) { |
|
153 | + return; //don't continue if there's no previous value |
|
154 | + } |
|
155 | + |
|
156 | + foreach ( $meta_value as $mk => $mv ) { |
|
157 | + //remove blank values |
|
158 | + if ( empty( $mv ) ) { |
|
159 | + unset( $meta_value[ $mk ] ); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + $cur_form_prefix = reset($meta_value); |
|
164 | + $cur_form_prefix = explode('_', $cur_form_prefix); |
|
165 | + $cur_form_prefix = $cur_form_prefix[0]; |
|
166 | + $save = false; |
|
167 | + |
|
168 | + foreach ( (array) $frm_vars['prev_hidden_cols'] as $prev_hidden ) { |
|
169 | 169 | if ( empty( $prev_hidden ) || in_array( $prev_hidden, $meta_value ) ) { |
170 | - //don't add blank cols or process included cols |
|
171 | - continue; |
|
172 | - } |
|
170 | + //don't add blank cols or process included cols |
|
171 | + continue; |
|
172 | + } |
|
173 | 173 | |
174 | 174 | $form_prefix = explode( '_', $prev_hidden ); |
175 | - $form_prefix = $form_prefix[0]; |
|
176 | - if ( $form_prefix == $cur_form_prefix ) { |
|
177 | - //don't add back columns that are meant to be hidden |
|
178 | - continue; |
|
179 | - } |
|
175 | + $form_prefix = $form_prefix[0]; |
|
176 | + if ( $form_prefix == $cur_form_prefix ) { |
|
177 | + //don't add back columns that are meant to be hidden |
|
178 | + continue; |
|
179 | + } |
|
180 | 180 | |
181 | - $meta_value[] = $prev_hidden; |
|
182 | - $save = true; |
|
183 | - unset($form_prefix); |
|
184 | - } |
|
181 | + $meta_value[] = $prev_hidden; |
|
182 | + $save = true; |
|
183 | + unset($form_prefix); |
|
184 | + } |
|
185 | 185 | |
186 | 186 | if ( $save ) { |
187 | - $user = wp_get_current_user(); |
|
188 | - update_user_option( $user->ID, 'manage'. $sanitized .'_page_formidable-entriescolumnshidden', $meta_value, true ); |
|
189 | - } |
|
190 | - } |
|
187 | + $user = wp_get_current_user(); |
|
188 | + update_user_option( $user->ID, 'manage'. $sanitized .'_page_formidable-entriescolumnshidden', $meta_value, true ); |
|
189 | + } |
|
190 | + } |
|
191 | 191 | |
192 | 192 | public static function save_per_page( $save, $option, $value ) { |
193 | - if ( $option == 'formidable_page_formidable_entries_per_page' ) { |
|
194 | - $save = (int) $value; |
|
195 | - } |
|
196 | - return $save; |
|
197 | - } |
|
193 | + if ( $option == 'formidable_page_formidable_entries_per_page' ) { |
|
194 | + $save = (int) $value; |
|
195 | + } |
|
196 | + return $save; |
|
197 | + } |
|
198 | 198 | |
199 | 199 | public static function sortable_columns() { |
200 | 200 | $form_id = FrmForm::get_current_form_id(); |
@@ -220,226 +220,226 @@ discard block |
||
220 | 220 | } |
221 | 221 | |
222 | 222 | public static function hidden_columns( $result ) { |
223 | - global $frm_vars; |
|
223 | + global $frm_vars; |
|
224 | 224 | |
225 | 225 | $form_id = FrmForm::get_current_form_id(); |
226 | 226 | |
227 | - $return = false; |
|
228 | - foreach ( (array) $result as $r ) { |
|
229 | - if ( ! empty( $r ) ) { |
|
230 | - $form_prefix = explode( '_', $r ); |
|
231 | - $form_prefix = $form_prefix[0]; |
|
227 | + $return = false; |
|
228 | + foreach ( (array) $result as $r ) { |
|
229 | + if ( ! empty( $r ) ) { |
|
230 | + $form_prefix = explode( '_', $r ); |
|
231 | + $form_prefix = $form_prefix[0]; |
|
232 | 232 | |
233 | - if ( (int) $form_prefix == (int) $form_id ) { |
|
234 | - $return = true; |
|
235 | - break; |
|
236 | - } |
|
233 | + if ( (int) $form_prefix == (int) $form_id ) { |
|
234 | + $return = true; |
|
235 | + break; |
|
236 | + } |
|
237 | 237 | |
238 | - unset($form_prefix); |
|
239 | - } |
|
240 | - } |
|
238 | + unset($form_prefix); |
|
239 | + } |
|
240 | + } |
|
241 | 241 | |
242 | - if ( $return ) { |
|
242 | + if ( $return ) { |
|
243 | 243 | return $result; |
244 | 244 | } |
245 | 245 | |
246 | - $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0; |
|
247 | - $max_columns = 8; |
|
248 | - if ( $i <= $max_columns ) { |
|
246 | + $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0; |
|
247 | + $max_columns = 8; |
|
248 | + if ( $i <= $max_columns ) { |
|
249 | 249 | return $result; |
250 | 250 | } |
251 | 251 | |
252 | - global $frm_vars; |
|
253 | - if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) { |
|
254 | - $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options); |
|
255 | - } |
|
252 | + global $frm_vars; |
|
253 | + if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) { |
|
254 | + $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options); |
|
255 | + } |
|
256 | 256 | |
257 | - if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] && isset($frm_vars['current_form']->options['hidden_cols']) && ! empty($frm_vars['current_form']->options['hidden_cols']) ) { |
|
258 | - $result = $frm_vars['current_form']->options['hidden_cols']; |
|
259 | - } else { |
|
260 | - $cols = $frm_vars['cols']; |
|
261 | - $cols = array_reverse($cols, true); |
|
257 | + if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] && isset($frm_vars['current_form']->options['hidden_cols']) && ! empty($frm_vars['current_form']->options['hidden_cols']) ) { |
|
258 | + $result = $frm_vars['current_form']->options['hidden_cols']; |
|
259 | + } else { |
|
260 | + $cols = $frm_vars['cols']; |
|
261 | + $cols = array_reverse($cols, true); |
|
262 | 262 | |
263 | - $result[] = $form_id .'_id'; |
|
264 | - $i--; |
|
263 | + $result[] = $form_id .'_id'; |
|
264 | + $i--; |
|
265 | 265 | |
266 | - $result[] = $form_id .'_item_key'; |
|
267 | - $i--; |
|
266 | + $result[] = $form_id .'_item_key'; |
|
267 | + $i--; |
|
268 | 268 | |
269 | 269 | foreach ( $cols as $col_key => $col ) { |
270 | - if ( $i > $max_columns ) { |
|
270 | + if ( $i > $max_columns ) { |
|
271 | 271 | $result[] = $col_key; |
272 | 272 | } |
273 | - //remove some columns by default |
|
274 | - $i--; |
|
275 | - unset($col_key, $col); |
|
276 | - } |
|
277 | - } |
|
273 | + //remove some columns by default |
|
274 | + $i--; |
|
275 | + unset($col_key, $col); |
|
276 | + } |
|
277 | + } |
|
278 | 278 | |
279 | - return $result; |
|
280 | - } |
|
279 | + return $result; |
|
280 | + } |
|
281 | 281 | |
282 | 282 | public static function display_list( $message = '', $errors = array() ) { |
283 | - global $wpdb, $frm_vars; |
|
283 | + global $wpdb, $frm_vars; |
|
284 | 284 | |
285 | 285 | $form = FrmForm::get_current_form(); |
286 | 286 | $params = FrmForm::get_admin_params( $form ); |
287 | 287 | |
288 | - if ( $form ) { |
|
289 | - $params['form'] = $form->id; |
|
290 | - $frm_vars['current_form'] = $form; |
|
288 | + if ( $form ) { |
|
289 | + $params['form'] = $form->id; |
|
290 | + $frm_vars['current_form'] = $form; |
|
291 | 291 | |
292 | - if ( 'trash' == $form->status ) { |
|
293 | - $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
|
294 | - $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) ); |
|
295 | - $errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete ); |
|
296 | - unset( $time_to_delete, $delete_timestamp ); |
|
297 | - } |
|
292 | + if ( 'trash' == $form->status ) { |
|
293 | + $delete_timestamp = time() - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS ); |
|
294 | + $time_to_delete = FrmAppHelper::human_time_diff( $delete_timestamp, ( isset( $form->options['trash_time'] ) ? ( $form->options['trash_time'] ) : time() ) ); |
|
295 | + $errors['trash'] = sprintf( __( 'This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable' ), $time_to_delete ); |
|
296 | + unset( $time_to_delete, $delete_timestamp ); |
|
297 | + } |
|
298 | 298 | } |
299 | 299 | |
300 | - $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' ); |
|
300 | + $table_class = apply_filters( 'frm_entries_list_class', 'FrmEntriesListHelper' ); |
|
301 | 301 | |
302 | - $wp_list_table = new $table_class( array( 'params' => $params ) ); |
|
302 | + $wp_list_table = new $table_class( array( 'params' => $params ) ); |
|
303 | 303 | |
304 | - $pagenum = $wp_list_table->get_pagenum(); |
|
304 | + $pagenum = $wp_list_table->get_pagenum(); |
|
305 | 305 | |
306 | - $wp_list_table->prepare_items(); |
|
306 | + $wp_list_table->prepare_items(); |
|
307 | 307 | |
308 | - $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
309 | - if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
308 | + $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
309 | + if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
310 | 310 | $url = add_query_arg( 'paged', $total_pages ); |
311 | - if ( headers_sent() ) { |
|
312 | - echo FrmAppHelper::js_redirect($url); |
|
313 | - } else { |
|
314 | - wp_redirect( esc_url_raw( $url ) ); |
|
315 | - } |
|
316 | - die(); |
|
317 | - } |
|
318 | - |
|
319 | - if ( empty($message) && isset($_GET['import-message']) ) { |
|
320 | - $message = __( 'Your import is complete', 'formidable' ); |
|
321 | - } |
|
322 | - |
|
323 | - require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php'); |
|
324 | - } |
|
325 | - |
|
326 | - /* Back End CRUD */ |
|
311 | + if ( headers_sent() ) { |
|
312 | + echo FrmAppHelper::js_redirect($url); |
|
313 | + } else { |
|
314 | + wp_redirect( esc_url_raw( $url ) ); |
|
315 | + } |
|
316 | + die(); |
|
317 | + } |
|
318 | + |
|
319 | + if ( empty($message) && isset($_GET['import-message']) ) { |
|
320 | + $message = __( 'Your import is complete', 'formidable' ); |
|
321 | + } |
|
322 | + |
|
323 | + require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php'); |
|
324 | + } |
|
325 | + |
|
326 | + /* Back End CRUD */ |
|
327 | 327 | public static function show( $id = 0 ) { |
328 | - FrmAppHelper::permission_check('frm_view_entries'); |
|
328 | + FrmAppHelper::permission_check('frm_view_entries'); |
|
329 | 329 | |
330 | - if ( ! $id ) { |
|
330 | + if ( ! $id ) { |
|
331 | 331 | $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); |
332 | 332 | |
333 | - if ( ! $id ) { |
|
333 | + if ( ! $id ) { |
|
334 | 334 | $id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'absint' ); |
335 | - } |
|
336 | - } |
|
335 | + } |
|
336 | + } |
|
337 | 337 | |
338 | - $entry = FrmEntry::getOne($id, true); |
|
338 | + $entry = FrmEntry::getOne($id, true); |
|
339 | 339 | |
340 | - $data = maybe_unserialize($entry->description); |
|
340 | + $data = maybe_unserialize($entry->description); |
|
341 | 341 | if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) { |
342 | 342 | $data = array( 'referrer' => $data ); |
343 | 343 | } |
344 | 344 | |
345 | 345 | $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' ); |
346 | - $to_emails = array(); |
|
346 | + $to_emails = array(); |
|
347 | 347 | |
348 | - include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/show.php'); |
|
349 | - } |
|
348 | + include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/show.php'); |
|
349 | + } |
|
350 | 350 | |
351 | - public static function destroy() { |
|
352 | - FrmAppHelper::permission_check('frm_delete_entries'); |
|
351 | + public static function destroy() { |
|
352 | + FrmAppHelper::permission_check('frm_delete_entries'); |
|
353 | 353 | |
354 | 354 | $params = FrmForm::get_admin_params(); |
355 | 355 | |
356 | - if ( isset($params['keep_post']) && $params['keep_post'] ) { |
|
357 | - //unlink entry from post |
|
358 | - global $wpdb; |
|
356 | + if ( isset($params['keep_post']) && $params['keep_post'] ) { |
|
357 | + //unlink entry from post |
|
358 | + global $wpdb; |
|
359 | 359 | $wpdb->update( $wpdb->prefix .'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) ); |
360 | - } |
|
360 | + } |
|
361 | 361 | |
362 | - $message = ''; |
|
363 | - if ( FrmEntry::destroy( $params['id'] ) ) { |
|
364 | - $message = __( 'Entry was Successfully Destroyed', 'formidable' ); |
|
365 | - } |
|
362 | + $message = ''; |
|
363 | + if ( FrmEntry::destroy( $params['id'] ) ) { |
|
364 | + $message = __( 'Entry was Successfully Destroyed', 'formidable' ); |
|
365 | + } |
|
366 | 366 | |
367 | - self::display_list( $message ); |
|
368 | - } |
|
367 | + self::display_list( $message ); |
|
368 | + } |
|
369 | 369 | |
370 | - public static function destroy_all() { |
|
371 | - if ( ! current_user_can( 'frm_delete_entries' ) ) { |
|
372 | - $frm_settings = FrmAppHelper::get_settings(); |
|
373 | - wp_die( $frm_settings->admin_permission ); |
|
374 | - } |
|
370 | + public static function destroy_all() { |
|
371 | + if ( ! current_user_can( 'frm_delete_entries' ) ) { |
|
372 | + $frm_settings = FrmAppHelper::get_settings(); |
|
373 | + wp_die( $frm_settings->admin_permission ); |
|
374 | + } |
|
375 | 375 | |
376 | - global $wpdb; |
|
376 | + global $wpdb; |
|
377 | 377 | $params = FrmForm::get_admin_params(); |
378 | - $message = ''; |
|
379 | - $errors = array(); |
|
380 | - $form_id = (int) $params['form']; |
|
378 | + $message = ''; |
|
379 | + $errors = array(); |
|
380 | + $form_id = (int) $params['form']; |
|
381 | 381 | |
382 | - if ( $form_id ) { |
|
383 | - $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) ); |
|
382 | + if ( $form_id ) { |
|
383 | + $entry_ids = FrmDb::get_col( 'frm_items', array( 'form_id' => $form_id ) ); |
|
384 | 384 | $action = FrmFormAction::get_action_for_form( $form_id, 'wppost', 1 ); |
385 | 385 | |
386 | - if ( $action ) { |
|
387 | - // this action takes a while, so only trigger it if there are posts to delete |
|
388 | - foreach ( $entry_ids as $entry_id ) { |
|
389 | - do_action( 'frm_before_destroy_entry', $entry_id ); |
|
390 | - unset( $entry_id ); |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - $wpdb->query( $wpdb->prepare( "DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id ) ); |
|
395 | - $results = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id ) ); |
|
396 | - if ( $results ) { |
|
397 | - $message = __( 'Entries were Successfully Destroyed', 'formidable' ); |
|
398 | - } |
|
399 | - } else { |
|
400 | - $errors = __( 'No entries were specified', 'formidable' ); |
|
401 | - } |
|
402 | - |
|
403 | - self::display_list( $message, $errors ); |
|
404 | - } |
|
405 | - |
|
406 | - public static function show_form( $id = '', $key = '', $title = false, $description = false ) { |
|
407 | - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' ); |
|
408 | - return FrmFormsController::show_form( $id, $key, $title, $description ); |
|
409 | - } |
|
410 | - |
|
411 | - public static function get_form( $filename, $form, $title, $description ) { |
|
412 | - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' ); |
|
413 | - return FrmFormsController::get_form( $form, $title, $description ); |
|
414 | - } |
|
415 | - |
|
416 | - public static function process_entry( $errors = '', $ajax = false ) { |
|
386 | + if ( $action ) { |
|
387 | + // this action takes a while, so only trigger it if there are posts to delete |
|
388 | + foreach ( $entry_ids as $entry_id ) { |
|
389 | + do_action( 'frm_before_destroy_entry', $entry_id ); |
|
390 | + unset( $entry_id ); |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + $wpdb->query( $wpdb->prepare( "DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id ) ); |
|
395 | + $results = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id ) ); |
|
396 | + if ( $results ) { |
|
397 | + $message = __( 'Entries were Successfully Destroyed', 'formidable' ); |
|
398 | + } |
|
399 | + } else { |
|
400 | + $errors = __( 'No entries were specified', 'formidable' ); |
|
401 | + } |
|
402 | + |
|
403 | + self::display_list( $message, $errors ); |
|
404 | + } |
|
405 | + |
|
406 | + public static function show_form( $id = '', $key = '', $title = false, $description = false ) { |
|
407 | + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::show_form()' ); |
|
408 | + return FrmFormsController::show_form( $id, $key, $title, $description ); |
|
409 | + } |
|
410 | + |
|
411 | + public static function get_form( $filename, $form, $title, $description ) { |
|
412 | + _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form()' ); |
|
413 | + return FrmFormsController::get_form( $form, $title, $description ); |
|
414 | + } |
|
415 | + |
|
416 | + public static function process_entry( $errors = '', $ajax = false ) { |
|
417 | 417 | $form_id = FrmAppHelper::get_post_param( 'form_id', '', 'absint' ); |
418 | 418 | if ( FrmAppHelper::is_admin() || empty( $_POST ) || empty( $form_id ) || ! isset( $_POST['item_key'] ) ) { |
419 | - return; |
|
420 | - } |
|
419 | + return; |
|
420 | + } |
|
421 | 421 | |
422 | - global $frm_vars; |
|
422 | + global $frm_vars; |
|
423 | 423 | |
424 | 424 | $form = FrmForm::getOne( $form_id ); |
425 | - if ( ! $form ) { |
|
426 | - return; |
|
427 | - } |
|
425 | + if ( ! $form ) { |
|
426 | + return; |
|
427 | + } |
|
428 | 428 | |
429 | 429 | $params = FrmForm::get_params( $form ); |
430 | 430 | |
431 | - if ( ! isset( $frm_vars['form_params'] ) ) { |
|
432 | - $frm_vars['form_params'] = array(); |
|
433 | - } |
|
431 | + if ( ! isset( $frm_vars['form_params'] ) ) { |
|
432 | + $frm_vars['form_params'] = array(); |
|
433 | + } |
|
434 | 434 | $frm_vars['form_params'][ $form->id ] = $params; |
435 | 435 | |
436 | 436 | if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) { |
437 | - return; |
|
438 | - } |
|
437 | + return; |
|
438 | + } |
|
439 | 439 | |
440 | - if ( $errors == '' ) { |
|
440 | + if ( $errors == '' ) { |
|
441 | 441 | $errors = FrmEntryValidate::validate( $_POST ); |
442 | - } |
|
442 | + } |
|
443 | 443 | |
444 | 444 | /** |
445 | 445 | * Use this filter to add trigger actions and add errors after |
@@ -450,102 +450,102 @@ discard block |
||
450 | 450 | |
451 | 451 | $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors ); |
452 | 452 | |
453 | - if ( empty( $errors ) ) { |
|
453 | + if ( empty( $errors ) ) { |
|
454 | 454 | $_POST['frm_skip_cookie'] = 1; |
455 | - if ( $params['action'] == 'create' ) { |
|
455 | + if ( $params['action'] == 'create' ) { |
|
456 | 456 | if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { |
457 | 457 | $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); |
458 | - } |
|
459 | - } |
|
458 | + } |
|
459 | + } |
|
460 | 460 | |
461 | - do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); |
|
461 | + do_action( 'frm_process_entry', $params, $errors, $form, array( 'ajax' => $ajax ) ); |
|
462 | 462 | unset( $_POST['frm_skip_cookie'] ); |
463 | - } |
|
464 | - } |
|
465 | - |
|
466 | - public static function delete_entry_before_redirect( $url, $form, $atts ) { |
|
467 | - self::_delete_entry( $atts['id'], $form ); |
|
468 | - return $url; |
|
469 | - } |
|
470 | - |
|
471 | - //Delete entry if not redirected |
|
472 | - public static function delete_entry_after_save( $atts ) { |
|
473 | - self::_delete_entry( $atts['entry_id'], $atts['form'] ); |
|
474 | - } |
|
475 | - |
|
476 | - private static function _delete_entry( $entry_id, $form ) { |
|
477 | - if ( ! $form ) { |
|
478 | - return; |
|
479 | - } |
|
480 | - |
|
481 | - $form->options = maybe_unserialize( $form->options ); |
|
482 | - if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) { |
|
483 | - FrmEntry::destroy( $entry_id ); |
|
484 | - } |
|
485 | - } |
|
463 | + } |
|
464 | + } |
|
465 | + |
|
466 | + public static function delete_entry_before_redirect( $url, $form, $atts ) { |
|
467 | + self::_delete_entry( $atts['id'], $form ); |
|
468 | + return $url; |
|
469 | + } |
|
470 | + |
|
471 | + //Delete entry if not redirected |
|
472 | + public static function delete_entry_after_save( $atts ) { |
|
473 | + self::_delete_entry( $atts['entry_id'], $atts['form'] ); |
|
474 | + } |
|
475 | + |
|
476 | + private static function _delete_entry( $entry_id, $form ) { |
|
477 | + if ( ! $form ) { |
|
478 | + return; |
|
479 | + } |
|
480 | + |
|
481 | + $form->options = maybe_unserialize( $form->options ); |
|
482 | + if ( isset( $form->options['no_save'] ) && $form->options['no_save'] ) { |
|
483 | + FrmEntry::destroy( $entry_id ); |
|
484 | + } |
|
485 | + } |
|
486 | 486 | |
487 | 487 | public static function show_entry_shortcode( $atts ) { |
488 | 488 | return FrmEntryFormat::show_entry( $atts ); |
489 | 489 | } |
490 | 490 | |
491 | - public static function &filter_email_value( $value, $meta, $entry, $atts = array() ) { |
|
492 | - $field = FrmField::getOne($meta->field_id); |
|
493 | - if ( ! $field ) { |
|
494 | - return $value; |
|
495 | - } |
|
491 | + public static function &filter_email_value( $value, $meta, $entry, $atts = array() ) { |
|
492 | + $field = FrmField::getOne($meta->field_id); |
|
493 | + if ( ! $field ) { |
|
494 | + return $value; |
|
495 | + } |
|
496 | 496 | |
497 | - $value = self::filter_display_value($value, $field, $atts); |
|
498 | - return $value; |
|
499 | - } |
|
497 | + $value = self::filter_display_value($value, $field, $atts); |
|
498 | + return $value; |
|
499 | + } |
|
500 | 500 | |
501 | 501 | public static function &filter_shortcode_value( $value, $tag, $atts, $field ) { |
502 | - $plain_text = add_filter('frm_plain_text_email', true); |
|
502 | + $plain_text = add_filter('frm_plain_text_email', true); |
|
503 | 503 | FrmEntryFormat::textarea_display_value( $field->type, $plain_text, $value ); |
504 | 504 | |
505 | - if ( isset($atts['show']) && $atts['show'] == 'value' ) { |
|
506 | - return $value; |
|
507 | - } |
|
505 | + if ( isset($atts['show']) && $atts['show'] == 'value' ) { |
|
506 | + return $value; |
|
507 | + } |
|
508 | 508 | |
509 | - return self::filter_display_value($value, $field, $atts); |
|
510 | - } |
|
509 | + return self::filter_display_value($value, $field, $atts); |
|
510 | + } |
|
511 | 511 | |
512 | - public static function &filter_display_value( $value, $field, $atts = array() ) { |
|
513 | - $saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false; |
|
512 | + public static function &filter_display_value( $value, $field, $atts = array() ) { |
|
513 | + $saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false; |
|
514 | 514 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'radio', 'select' ) ) || ! FrmField::is_option_true( $field, 'separate_value' ) || $saved_value ) { |
515 | - return $value; |
|
516 | - } |
|
517 | - |
|
518 | - $f_values = $f_labels = array(); |
|
519 | - |
|
520 | - foreach ( $field->options as $opt_key => $opt ) { |
|
521 | - if ( ! is_array($opt) ) { |
|
522 | - continue; |
|
523 | - } |
|
524 | - |
|
525 | - $f_labels[ $opt_key ] = isset( $opt['label'] ) ? $opt['label'] : reset($opt); |
|
526 | - $f_values[ $opt_key ] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[ $opt_key ]; |
|
527 | - if ( $f_labels[ $opt_key ] == $f_values[ $opt_key ] ) { |
|
528 | - unset( $f_values[ $opt_key ], $f_labels[ $opt_key ] ); |
|
529 | - } |
|
530 | - unset($opt_key, $opt); |
|
531 | - } |
|
532 | - |
|
533 | - if ( ! empty($f_values) ) { |
|
534 | - foreach ( (array) $value as $v_key => $val ) { |
|
535 | - if ( in_array($val, $f_values) ) { |
|
536 | - $opt = array_search($val, $f_values); |
|
537 | - if ( is_array($value) ) { |
|
538 | - $value[ $v_key ] = $f_labels[ $opt ]; |
|
539 | - } else { |
|
540 | - $value = $f_labels[ $opt ]; |
|
541 | - } |
|
542 | - } |
|
543 | - unset($v_key, $val); |
|
544 | - } |
|
545 | - } |
|
546 | - |
|
547 | - return $value; |
|
548 | - } |
|
515 | + return $value; |
|
516 | + } |
|
517 | + |
|
518 | + $f_values = $f_labels = array(); |
|
519 | + |
|
520 | + foreach ( $field->options as $opt_key => $opt ) { |
|
521 | + if ( ! is_array($opt) ) { |
|
522 | + continue; |
|
523 | + } |
|
524 | + |
|
525 | + $f_labels[ $opt_key ] = isset( $opt['label'] ) ? $opt['label'] : reset($opt); |
|
526 | + $f_values[ $opt_key ] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[ $opt_key ]; |
|
527 | + if ( $f_labels[ $opt_key ] == $f_values[ $opt_key ] ) { |
|
528 | + unset( $f_values[ $opt_key ], $f_labels[ $opt_key ] ); |
|
529 | + } |
|
530 | + unset($opt_key, $opt); |
|
531 | + } |
|
532 | + |
|
533 | + if ( ! empty($f_values) ) { |
|
534 | + foreach ( (array) $value as $v_key => $val ) { |
|
535 | + if ( in_array($val, $f_values) ) { |
|
536 | + $opt = array_search($val, $f_values); |
|
537 | + if ( is_array($value) ) { |
|
538 | + $value[ $v_key ] = $f_labels[ $opt ]; |
|
539 | + } else { |
|
540 | + $value = $f_labels[ $opt ]; |
|
541 | + } |
|
542 | + } |
|
543 | + unset($v_key, $val); |
|
544 | + } |
|
545 | + } |
|
546 | + |
|
547 | + return $value; |
|
548 | + } |
|
549 | 549 | |
550 | 550 | public static function get_params( $form = null ) { |
551 | 551 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_params' ); |
@@ -553,13 +553,13 @@ discard block |
||
553 | 553 | } |
554 | 554 | |
555 | 555 | public static function entry_sidebar( $entry ) { |
556 | - $data = maybe_unserialize($entry->description); |
|
557 | - $date_format = get_option('date_format'); |
|
558 | - $time_format = get_option('time_format'); |
|
556 | + $data = maybe_unserialize($entry->description); |
|
557 | + $date_format = get_option('date_format'); |
|
558 | + $time_format = get_option('time_format'); |
|
559 | 559 | if ( isset( $data['browser'] ) ) { |
560 | 560 | $browser = FrmEntryFormat::get_browser( $data['browser'] ); |
561 | 561 | } |
562 | 562 | |
563 | - include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/sidebar-shared.php'); |
|
564 | - } |
|
563 | + include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/sidebar-shared.php'); |
|
564 | + } |
|
565 | 565 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | public static function menu() { |
6 | 6 | FrmAppHelper::force_capability( 'frm_view_entries' ); |
7 | 7 | |
8 | - add_submenu_page('formidable', 'Formidable | '. __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); |
|
8 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Entries', 'formidable' ), __( 'Entries', 'formidable' ), 'frm_view_entries', 'formidable-entries', 'FrmEntriesController::route' ); |
|
9 | 9 | |
10 | 10 | if ( ! in_array( FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ), array( 'edit', 'show' ) ) ) { |
11 | 11 | $frm_settings = FrmAppHelper::get_settings(); |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | $screen->add_help_tab( array( |
52 | 52 | 'id' => 'formidable-entries-tab', |
53 | 53 | 'title' => __( 'Overview', 'formidable' ), |
54 | - 'content' => '<p>' . esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) .'</p> <p>'. esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) . '</p>', |
|
55 | - )); |
|
54 | + 'content' => '<p>' . esc_html__( 'This screen provides access to all of your entries. You can customize the display of this screen to suit your workflow.', 'formidable' ) . '</p> <p>' . esc_html__( 'Hovering over a row in the entries list will display action links that allow you to manage your entry.', 'formidable' ) . '</p>', |
|
55 | + ) ); |
|
56 | 56 | |
57 | 57 | $screen->set_help_sidebar( |
58 | 58 | '<p><strong>' . esc_html__( 'For more information:', 'formidable' ) . '</strong></p>' . |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | global $frm_vars, $wpdb; |
68 | 68 | $form_id = FrmForm::get_current_form_id(); |
69 | 69 | |
70 | - $columns[ $form_id .'_id' ] = 'ID'; |
|
71 | - $columns[ $form_id . '_item_key' ] = esc_html__( 'Entry Key', 'formidable' ); |
|
70 | + $columns[$form_id . '_id'] = 'ID'; |
|
71 | + $columns[$form_id . '_item_key'] = esc_html__( 'Entry Key', 'formidable' ); |
|
72 | 72 | |
73 | 73 | if ( ! $form_id ) { |
74 | 74 | return $columns; |
75 | 75 | } |
76 | 76 | |
77 | - $form_cols = FrmField::get_all_for_form($form_id, '', 'include'); |
|
77 | + $form_cols = FrmField::get_all_for_form( $form_id, '', 'include' ); |
|
78 | 78 | |
79 | 79 | foreach ( $form_cols as $form_col ) { |
80 | 80 | if ( FrmField::is_no_save_field( $form_col->type ) ) { |
@@ -87,30 +87,30 @@ discard block |
||
87 | 87 | if ( $sub_form_cols ) { |
88 | 88 | foreach ( $sub_form_cols as $k => $sub_form_col ) { |
89 | 89 | if ( FrmField::is_no_save_field( $sub_form_col->type ) ) { |
90 | - unset( $sub_form_cols[ $k ] ); |
|
90 | + unset( $sub_form_cols[$k] ); |
|
91 | 91 | continue; |
92 | 92 | } |
93 | - $columns[ $form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id ] = FrmAppHelper::truncate( $sub_form_col->name, 35 ); |
|
94 | - unset($sub_form_col); |
|
93 | + $columns[$form_id . '_' . $sub_form_col->field_key . '-_-' . $form_col->id] = FrmAppHelper::truncate( $sub_form_col->name, 35 ); |
|
94 | + unset( $sub_form_col ); |
|
95 | 95 | } |
96 | 96 | } |
97 | - unset($sub_form_cols); |
|
97 | + unset( $sub_form_cols ); |
|
98 | 98 | } else { |
99 | 99 | $col_id = $form_col->field_key; |
100 | 100 | if ( $form_col->form_id != $form_id ) { |
101 | - $col_id .= '-_-form'. $form_col->form_id; |
|
101 | + $col_id .= '-_-form' . $form_col->form_id; |
|
102 | 102 | } |
103 | 103 | |
104 | - if ( isset($form_col->field_options['separate_value']) && $form_col->field_options['separate_value'] ) { |
|
105 | - $columns[ $form_id .'_frmsep_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
104 | + if ( isset( $form_col->field_options['separate_value'] ) && $form_col->field_options['separate_value'] ) { |
|
105 | + $columns[$form_id . '_frmsep_' . $col_id] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
106 | 106 | } |
107 | - $columns[ $form_id .'_'. $col_id ] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
107 | + $columns[$form_id . '_' . $col_id] = FrmAppHelper::truncate( $form_col->name, 35 ); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | - $columns[ $form_id .'_created_at' ] = __( 'Entry creation date', 'formidable' ); |
|
112 | - $columns[ $form_id .'_updated_at' ] = __( 'Entry update date', 'formidable' ); |
|
113 | - $columns[ $form_id .'_ip' ] = 'IP'; |
|
111 | + $columns[$form_id . '_created_at'] = __( 'Entry creation date', 'formidable' ); |
|
112 | + $columns[$form_id . '_updated_at'] = __( 'Entry update date', 'formidable' ); |
|
113 | + $columns[$form_id . '_ip'] = 'IP'; |
|
114 | 114 | |
115 | 115 | $frm_vars['cols'] = $columns; |
116 | 116 | |
@@ -124,17 +124,17 @@ discard block |
||
124 | 124 | |
125 | 125 | public static function check_hidden_cols( $check, $object_id, $meta_key, $meta_value, $prev_value ) { |
126 | 126 | $frm_settings = FrmAppHelper::get_settings(); |
127 | - if ( $meta_key != 'manage'. sanitize_title($frm_settings->menu) .'_page_formidable-entriescolumnshidden' || $meta_value == $prev_value ) { |
|
127 | + if ( $meta_key != 'manage' . sanitize_title( $frm_settings->menu ) . '_page_formidable-entriescolumnshidden' || $meta_value == $prev_value ) { |
|
128 | 128 | return $check; |
129 | 129 | } |
130 | 130 | |
131 | 131 | if ( empty( $prev_value ) ) { |
132 | - $prev_value = get_metadata('user', $object_id, $meta_key, true); |
|
132 | + $prev_value = get_metadata( 'user', $object_id, $meta_key, true ); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | global $frm_vars; |
136 | 136 | //add a check so we don't create a loop |
137 | - $frm_vars['prev_hidden_cols'] = ( isset($frm_vars['prev_hidden_cols']) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
137 | + $frm_vars['prev_hidden_cols'] = ( isset( $frm_vars['prev_hidden_cols'] ) && $frm_vars['prev_hidden_cols'] ) ? false : $prev_value; |
|
138 | 138 | |
139 | 139 | return $check; |
140 | 140 | } |
@@ -143,25 +143,25 @@ discard block |
||
143 | 143 | public static function update_hidden_cols( $meta_id, $object_id, $meta_key, $meta_value ) { |
144 | 144 | $frm_settings = FrmAppHelper::get_settings(); |
145 | 145 | |
146 | - $sanitized = sanitize_title($frm_settings->menu); |
|
147 | - if ( $meta_key != 'manage'. $sanitized .'_page_formidable-entriescolumnshidden' ) { |
|
146 | + $sanitized = sanitize_title( $frm_settings->menu ); |
|
147 | + if ( $meta_key != 'manage' . $sanitized . '_page_formidable-entriescolumnshidden' ) { |
|
148 | 148 | return; |
149 | 149 | } |
150 | 150 | |
151 | 151 | global $frm_vars; |
152 | - if ( ! isset($frm_vars['prev_hidden_cols']) || ! $frm_vars['prev_hidden_cols'] ) { |
|
152 | + if ( ! isset( $frm_vars['prev_hidden_cols'] ) || ! $frm_vars['prev_hidden_cols'] ) { |
|
153 | 153 | return; //don't continue if there's no previous value |
154 | 154 | } |
155 | 155 | |
156 | 156 | foreach ( $meta_value as $mk => $mv ) { |
157 | 157 | //remove blank values |
158 | - if ( empty( $mv ) ) { |
|
159 | - unset( $meta_value[ $mk ] ); |
|
158 | + if ( empty( $mv ) ) { |
|
159 | + unset( $meta_value[$mk] ); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | - $cur_form_prefix = reset($meta_value); |
|
164 | - $cur_form_prefix = explode('_', $cur_form_prefix); |
|
163 | + $cur_form_prefix = reset( $meta_value ); |
|
164 | + $cur_form_prefix = explode( '_', $cur_form_prefix ); |
|
165 | 165 | $cur_form_prefix = $cur_form_prefix[0]; |
166 | 166 | $save = false; |
167 | 167 | |
@@ -180,12 +180,12 @@ discard block |
||
180 | 180 | |
181 | 181 | $meta_value[] = $prev_hidden; |
182 | 182 | $save = true; |
183 | - unset($form_prefix); |
|
183 | + unset( $form_prefix ); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | if ( $save ) { |
187 | 187 | $user = wp_get_current_user(); |
188 | - update_user_option( $user->ID, 'manage'. $sanitized .'_page_formidable-entriescolumnshidden', $meta_value, true ); |
|
188 | + update_user_option( $user->ID, 'manage' . $sanitized . '_page_formidable-entriescolumnshidden', $meta_value, true ); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | foreach ( $fields as $field ) { |
213 | 213 | if ( $field->type != 'checkbox' && ( ! isset( $field->field_options['post_field'] ) || $field->field_options['post_field'] == '' ) ) { |
214 | 214 | // Can't sort on checkboxes because they are stored serialized, or post fields |
215 | - $columns[ $form_id . '_' . $field->field_key ] = 'meta_' . $field->id; |
|
215 | + $columns[$form_id . '_' . $field->field_key] = 'meta_' . $field->id; |
|
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | break; |
236 | 236 | } |
237 | 237 | |
238 | - unset($form_prefix); |
|
238 | + unset( $form_prefix ); |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
@@ -243,36 +243,36 @@ discard block |
||
243 | 243 | return $result; |
244 | 244 | } |
245 | 245 | |
246 | - $i = isset($frm_vars['cols']) ? count($frm_vars['cols']) : 0; |
|
246 | + $i = isset( $frm_vars['cols'] ) ? count( $frm_vars['cols'] ) : 0; |
|
247 | 247 | $max_columns = 8; |
248 | 248 | if ( $i <= $max_columns ) { |
249 | 249 | return $result; |
250 | 250 | } |
251 | 251 | |
252 | 252 | global $frm_vars; |
253 | - if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] ) { |
|
254 | - $frm_vars['current_form']->options = maybe_unserialize($frm_vars['current_form']->options); |
|
253 | + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] ) { |
|
254 | + $frm_vars['current_form']->options = maybe_unserialize( $frm_vars['current_form']->options ); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( isset($frm_vars['current_form']) && $frm_vars['current_form'] && isset($frm_vars['current_form']->options['hidden_cols']) && ! empty($frm_vars['current_form']->options['hidden_cols']) ) { |
|
257 | + if ( isset( $frm_vars['current_form'] ) && $frm_vars['current_form'] && isset( $frm_vars['current_form']->options['hidden_cols'] ) && ! empty( $frm_vars['current_form']->options['hidden_cols'] ) ) { |
|
258 | 258 | $result = $frm_vars['current_form']->options['hidden_cols']; |
259 | 259 | } else { |
260 | 260 | $cols = $frm_vars['cols']; |
261 | - $cols = array_reverse($cols, true); |
|
261 | + $cols = array_reverse( $cols, true ); |
|
262 | 262 | |
263 | - $result[] = $form_id .'_id'; |
|
264 | - $i--; |
|
263 | + $result[] = $form_id . '_id'; |
|
264 | + $i --; |
|
265 | 265 | |
266 | - $result[] = $form_id .'_item_key'; |
|
267 | - $i--; |
|
266 | + $result[] = $form_id . '_item_key'; |
|
267 | + $i --; |
|
268 | 268 | |
269 | 269 | foreach ( $cols as $col_key => $col ) { |
270 | 270 | if ( $i > $max_columns ) { |
271 | 271 | $result[] = $col_key; |
272 | 272 | } |
273 | 273 | //remove some columns by default |
274 | - $i--; |
|
275 | - unset($col_key, $col); |
|
274 | + $i --; |
|
275 | + unset( $col_key, $col ); |
|
276 | 276 | } |
277 | 277 | } |
278 | 278 | |
@@ -309,23 +309,23 @@ discard block |
||
309 | 309 | if ( $pagenum > $total_pages && $total_pages > 0 ) { |
310 | 310 | $url = add_query_arg( 'paged', $total_pages ); |
311 | 311 | if ( headers_sent() ) { |
312 | - echo FrmAppHelper::js_redirect($url); |
|
312 | + echo FrmAppHelper::js_redirect( $url ); |
|
313 | 313 | } else { |
314 | 314 | wp_redirect( esc_url_raw( $url ) ); |
315 | 315 | } |
316 | 316 | die(); |
317 | 317 | } |
318 | 318 | |
319 | - if ( empty($message) && isset($_GET['import-message']) ) { |
|
319 | + if ( empty( $message ) && isset( $_GET['import-message'] ) ) { |
|
320 | 320 | $message = __( 'Your import is complete', 'formidable' ); |
321 | 321 | } |
322 | 322 | |
323 | - require(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/list.php'); |
|
323 | + require( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php' ); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /* Back End CRUD */ |
327 | 327 | public static function show( $id = 0 ) { |
328 | - FrmAppHelper::permission_check('frm_view_entries'); |
|
328 | + FrmAppHelper::permission_check( 'frm_view_entries' ); |
|
329 | 329 | |
330 | 330 | if ( ! $id ) { |
331 | 331 | $id = FrmAppHelper::get_param( 'id', 0, 'get', 'absint' ); |
@@ -335,9 +335,9 @@ discard block |
||
335 | 335 | } |
336 | 336 | } |
337 | 337 | |
338 | - $entry = FrmEntry::getOne($id, true); |
|
338 | + $entry = FrmEntry::getOne( $id, true ); |
|
339 | 339 | |
340 | - $data = maybe_unserialize($entry->description); |
|
340 | + $data = maybe_unserialize( $entry->description ); |
|
341 | 341 | if ( ! is_array( $data ) || ! isset( $data['referrer'] ) ) { |
342 | 342 | $data = array( 'referrer' => $data ); |
343 | 343 | } |
@@ -345,18 +345,18 @@ discard block |
||
345 | 345 | $fields = FrmField::get_all_for_form( $entry->form_id, '', 'include' ); |
346 | 346 | $to_emails = array(); |
347 | 347 | |
348 | - include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/show.php'); |
|
348 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/show.php' ); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | public static function destroy() { |
352 | - FrmAppHelper::permission_check('frm_delete_entries'); |
|
352 | + FrmAppHelper::permission_check( 'frm_delete_entries' ); |
|
353 | 353 | |
354 | 354 | $params = FrmForm::get_admin_params(); |
355 | 355 | |
356 | - if ( isset($params['keep_post']) && $params['keep_post'] ) { |
|
356 | + if ( isset( $params['keep_post'] ) && $params['keep_post'] ) { |
|
357 | 357 | //unlink entry from post |
358 | 358 | global $wpdb; |
359 | - $wpdb->update( $wpdb->prefix .'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) ); |
|
359 | + $wpdb->update( $wpdb->prefix . 'frm_items', array( 'post_id' => '' ), array( 'id' => $params['id'] ) ); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | $message = ''; |
@@ -431,9 +431,9 @@ discard block |
||
431 | 431 | if ( ! isset( $frm_vars['form_params'] ) ) { |
432 | 432 | $frm_vars['form_params'] = array(); |
433 | 433 | } |
434 | - $frm_vars['form_params'][ $form->id ] = $params; |
|
434 | + $frm_vars['form_params'][$form->id] = $params; |
|
435 | 435 | |
436 | - if ( isset( $frm_vars['created_entries'][ $form_id ] ) ) { |
|
436 | + if ( isset( $frm_vars['created_entries'][$form_id] ) ) { |
|
437 | 437 | return; |
438 | 438 | } |
439 | 439 | |
@@ -448,13 +448,13 @@ discard block |
||
448 | 448 | */ |
449 | 449 | $errors = apply_filters( 'frm_entries_before_create', $errors, $form ); |
450 | 450 | |
451 | - $frm_vars['created_entries'][ $form_id ] = array( 'errors' => $errors ); |
|
451 | + $frm_vars['created_entries'][$form_id] = array( 'errors' => $errors ); |
|
452 | 452 | |
453 | 453 | if ( empty( $errors ) ) { |
454 | 454 | $_POST['frm_skip_cookie'] = 1; |
455 | 455 | if ( $params['action'] == 'create' ) { |
456 | - if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][ $form_id ]['entry_id'] ) ) { |
|
457 | - $frm_vars['created_entries'][ $form_id ]['entry_id'] = FrmEntry::create( $_POST ); |
|
456 | + if ( apply_filters( 'frm_continue_to_create', true, $form_id ) && ! isset( $frm_vars['created_entries'][$form_id]['entry_id'] ) ) { |
|
457 | + $frm_vars['created_entries'][$form_id]['entry_id'] = FrmEntry::create( $_POST ); |
|
458 | 458 | } |
459 | 459 | } |
460 | 460 | |
@@ -489,28 +489,28 @@ discard block |
||
489 | 489 | } |
490 | 490 | |
491 | 491 | public static function &filter_email_value( $value, $meta, $entry, $atts = array() ) { |
492 | - $field = FrmField::getOne($meta->field_id); |
|
492 | + $field = FrmField::getOne( $meta->field_id ); |
|
493 | 493 | if ( ! $field ) { |
494 | 494 | return $value; |
495 | 495 | } |
496 | 496 | |
497 | - $value = self::filter_display_value($value, $field, $atts); |
|
497 | + $value = self::filter_display_value( $value, $field, $atts ); |
|
498 | 498 | return $value; |
499 | 499 | } |
500 | 500 | |
501 | 501 | public static function &filter_shortcode_value( $value, $tag, $atts, $field ) { |
502 | - $plain_text = add_filter('frm_plain_text_email', true); |
|
502 | + $plain_text = add_filter( 'frm_plain_text_email', true ); |
|
503 | 503 | FrmEntryFormat::textarea_display_value( $field->type, $plain_text, $value ); |
504 | 504 | |
505 | - if ( isset($atts['show']) && $atts['show'] == 'value' ) { |
|
505 | + if ( isset( $atts['show'] ) && $atts['show'] == 'value' ) { |
|
506 | 506 | return $value; |
507 | 507 | } |
508 | 508 | |
509 | - return self::filter_display_value($value, $field, $atts); |
|
509 | + return self::filter_display_value( $value, $field, $atts ); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | public static function &filter_display_value( $value, $field, $atts = array() ) { |
513 | - $saved_value = ( isset($atts['saved_value']) && $atts['saved_value'] ) ? true : false; |
|
513 | + $saved_value = ( isset( $atts['saved_value'] ) && $atts['saved_value'] ) ? true : false; |
|
514 | 514 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'radio', 'select' ) ) || ! FrmField::is_option_true( $field, 'separate_value' ) || $saved_value ) { |
515 | 515 | return $value; |
516 | 516 | } |
@@ -518,29 +518,29 @@ discard block |
||
518 | 518 | $f_values = $f_labels = array(); |
519 | 519 | |
520 | 520 | foreach ( $field->options as $opt_key => $opt ) { |
521 | - if ( ! is_array($opt) ) { |
|
521 | + if ( ! is_array( $opt ) ) { |
|
522 | 522 | continue; |
523 | 523 | } |
524 | 524 | |
525 | - $f_labels[ $opt_key ] = isset( $opt['label'] ) ? $opt['label'] : reset($opt); |
|
526 | - $f_values[ $opt_key ] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[ $opt_key ]; |
|
527 | - if ( $f_labels[ $opt_key ] == $f_values[ $opt_key ] ) { |
|
528 | - unset( $f_values[ $opt_key ], $f_labels[ $opt_key ] ); |
|
525 | + $f_labels[$opt_key] = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
526 | + $f_values[$opt_key] = isset( $opt['value'] ) ? $opt['value'] : $f_labels[$opt_key]; |
|
527 | + if ( $f_labels[$opt_key] == $f_values[$opt_key] ) { |
|
528 | + unset( $f_values[$opt_key], $f_labels[$opt_key] ); |
|
529 | 529 | } |
530 | - unset($opt_key, $opt); |
|
530 | + unset( $opt_key, $opt ); |
|
531 | 531 | } |
532 | 532 | |
533 | - if ( ! empty($f_values) ) { |
|
533 | + if ( ! empty( $f_values ) ) { |
|
534 | 534 | foreach ( (array) $value as $v_key => $val ) { |
535 | - if ( in_array($val, $f_values) ) { |
|
536 | - $opt = array_search($val, $f_values); |
|
537 | - if ( is_array($value) ) { |
|
538 | - $value[ $v_key ] = $f_labels[ $opt ]; |
|
535 | + if ( in_array( $val, $f_values ) ) { |
|
536 | + $opt = array_search( $val, $f_values ); |
|
537 | + if ( is_array( $value ) ) { |
|
538 | + $value[$v_key] = $f_labels[$opt]; |
|
539 | 539 | } else { |
540 | - $value = $f_labels[ $opt ]; |
|
540 | + $value = $f_labels[$opt]; |
|
541 | 541 | } |
542 | 542 | } |
543 | - unset($v_key, $val); |
|
543 | + unset( $v_key, $val ); |
|
544 | 544 | } |
545 | 545 | } |
546 | 546 | |
@@ -553,13 +553,13 @@ discard block |
||
553 | 553 | } |
554 | 554 | |
555 | 555 | public static function entry_sidebar( $entry ) { |
556 | - $data = maybe_unserialize($entry->description); |
|
557 | - $date_format = get_option('date_format'); |
|
558 | - $time_format = get_option('time_format'); |
|
556 | + $data = maybe_unserialize( $entry->description ); |
|
557 | + $date_format = get_option( 'date_format' ); |
|
558 | + $time_format = get_option( 'time_format' ); |
|
559 | 559 | if ( isset( $data['browser'] ) ) { |
560 | 560 | $browser = FrmEntryFormat::get_browser( $data['browser'] ); |
561 | 561 | } |
562 | 562 | |
563 | - include(FrmAppHelper::plugin_path() .'/classes/views/frm-entries/sidebar-shared.php'); |
|
563 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-entries/sidebar-shared.php' ); |
|
564 | 564 | } |
565 | 565 | } |
@@ -1,109 +1,109 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class FrmFormActionsController { |
4 | - public static $action_post_type = 'frm_form_actions'; |
|
5 | - public static $registered_actions; |
|
6 | - |
|
7 | - public static function register_post_types() { |
|
8 | - register_post_type( self::$action_post_type, array( |
|
9 | - 'label' => __( 'Form Actions', 'formidable' ), |
|
10 | - 'description' => '', |
|
11 | - 'public' => false, |
|
12 | - 'show_ui' => false, |
|
13 | - 'exclude_from_search' => true, |
|
14 | - 'show_in_nav_menus' => false, |
|
15 | - 'show_in_menu' => true, |
|
16 | - 'capability_type' => 'page', |
|
17 | - 'supports' => array( |
|
4 | + public static $action_post_type = 'frm_form_actions'; |
|
5 | + public static $registered_actions; |
|
6 | + |
|
7 | + public static function register_post_types() { |
|
8 | + register_post_type( self::$action_post_type, array( |
|
9 | + 'label' => __( 'Form Actions', 'formidable' ), |
|
10 | + 'description' => '', |
|
11 | + 'public' => false, |
|
12 | + 'show_ui' => false, |
|
13 | + 'exclude_from_search' => true, |
|
14 | + 'show_in_nav_menus' => false, |
|
15 | + 'show_in_menu' => true, |
|
16 | + 'capability_type' => 'page', |
|
17 | + 'supports' => array( |
|
18 | 18 | 'title', 'editor', 'excerpt', 'custom-fields', |
19 | 19 | 'page-attributes', |
20 | - ), |
|
21 | - 'has_archive' => false, |
|
22 | - ) ); |
|
23 | - |
|
24 | - /** |
|
25 | - * post_content: json settings |
|
26 | - * menu_order: form id |
|
27 | - * post_excerpt: action type |
|
28 | - */ |
|
29 | - |
|
30 | - self::actions_init(); |
|
31 | - } |
|
32 | - |
|
33 | - public static function actions_init() { |
|
34 | - self::$registered_actions = new Frm_Form_Action_Factory(); |
|
35 | - self::register_actions(); |
|
36 | - do_action( 'frm_form_actions_init' ); |
|
37 | - } |
|
38 | - |
|
39 | - public static function register_actions() { |
|
40 | - $action_classes = apply_filters( 'frm_registered_form_actions', array( |
|
41 | - 'email' => 'FrmEmailAction', |
|
42 | - 'wppost' => 'FrmDefPostAction', |
|
43 | - 'register' => 'FrmDefRegAction', |
|
44 | - 'paypal' => 'FrmDefPayPalAction', |
|
45 | - //'aweber' => 'FrmDefAweberAction', |
|
46 | - 'mailchimp' => 'FrmDefMlcmpAction', |
|
47 | - 'twilio' => 'FrmDefTwilioAction', |
|
48 | - 'highrise' => 'FrmDefHrsAction', |
|
49 | - ) ); |
|
50 | - |
|
51 | - include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php'); |
|
52 | - include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php'); |
|
53 | - |
|
54 | - foreach ( $action_classes as $action_class ) { |
|
55 | - self::$registered_actions->register($action_class); |
|
56 | - } |
|
57 | - } |
|
20 | + ), |
|
21 | + 'has_archive' => false, |
|
22 | + ) ); |
|
23 | + |
|
24 | + /** |
|
25 | + * post_content: json settings |
|
26 | + * menu_order: form id |
|
27 | + * post_excerpt: action type |
|
28 | + */ |
|
29 | + |
|
30 | + self::actions_init(); |
|
31 | + } |
|
32 | + |
|
33 | + public static function actions_init() { |
|
34 | + self::$registered_actions = new Frm_Form_Action_Factory(); |
|
35 | + self::register_actions(); |
|
36 | + do_action( 'frm_form_actions_init' ); |
|
37 | + } |
|
38 | + |
|
39 | + public static function register_actions() { |
|
40 | + $action_classes = apply_filters( 'frm_registered_form_actions', array( |
|
41 | + 'email' => 'FrmEmailAction', |
|
42 | + 'wppost' => 'FrmDefPostAction', |
|
43 | + 'register' => 'FrmDefRegAction', |
|
44 | + 'paypal' => 'FrmDefPayPalAction', |
|
45 | + //'aweber' => 'FrmDefAweberAction', |
|
46 | + 'mailchimp' => 'FrmDefMlcmpAction', |
|
47 | + 'twilio' => 'FrmDefTwilioAction', |
|
48 | + 'highrise' => 'FrmDefHrsAction', |
|
49 | + ) ); |
|
50 | + |
|
51 | + include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php'); |
|
52 | + include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php'); |
|
53 | + |
|
54 | + foreach ( $action_classes as $action_class ) { |
|
55 | + self::$registered_actions->register($action_class); |
|
56 | + } |
|
57 | + } |
|
58 | 58 | |
59 | 59 | public static function get_form_actions( $action = 'all' ) { |
60 | - $temp_actions = self::$registered_actions; |
|
61 | - if ( empty($temp_actions) ) { |
|
62 | - self::actions_init(); |
|
63 | - $temp_actions = self::$registered_actions->actions; |
|
64 | - } else { |
|
65 | - $temp_actions = $temp_actions->actions; |
|
66 | - } |
|
60 | + $temp_actions = self::$registered_actions; |
|
61 | + if ( empty($temp_actions) ) { |
|
62 | + self::actions_init(); |
|
63 | + $temp_actions = self::$registered_actions->actions; |
|
64 | + } else { |
|
65 | + $temp_actions = $temp_actions->actions; |
|
66 | + } |
|
67 | 67 | |
68 | - $actions = array(); |
|
68 | + $actions = array(); |
|
69 | 69 | |
70 | - foreach ( $temp_actions as $a ) { |
|
71 | - if ( 'all' != $action && $a->id_base == $action ) { |
|
72 | - return $a; |
|
73 | - } |
|
70 | + foreach ( $temp_actions as $a ) { |
|
71 | + if ( 'all' != $action && $a->id_base == $action ) { |
|
72 | + return $a; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | $actions[ $a->id_base ] = $a; |
76 | - } |
|
77 | - unset( $temp_actions, $a ); |
|
78 | - |
|
79 | - $action_limit = 10; |
|
80 | - if ( count( $actions ) <= $action_limit ) { |
|
81 | - return $actions; |
|
82 | - } |
|
83 | - |
|
84 | - // remove the last few inactive icons if there are too many |
|
85 | - $temp_actions = $actions; |
|
86 | - arsort( $temp_actions ); |
|
87 | - foreach ( $temp_actions as $type => $a ) { |
|
88 | - if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) { |
|
76 | + } |
|
77 | + unset( $temp_actions, $a ); |
|
78 | + |
|
79 | + $action_limit = 10; |
|
80 | + if ( count( $actions ) <= $action_limit ) { |
|
81 | + return $actions; |
|
82 | + } |
|
83 | + |
|
84 | + // remove the last few inactive icons if there are too many |
|
85 | + $temp_actions = $actions; |
|
86 | + arsort( $temp_actions ); |
|
87 | + foreach ( $temp_actions as $type => $a ) { |
|
88 | + if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) { |
|
89 | 89 | unset( $actions[ $type ] ); |
90 | - if ( count( $actions ) <= $action_limit ) { |
|
91 | - break; |
|
92 | - } |
|
93 | - } |
|
94 | - unset( $type, $a ); |
|
95 | - } |
|
90 | + if ( count( $actions ) <= $action_limit ) { |
|
91 | + break; |
|
92 | + } |
|
93 | + } |
|
94 | + unset( $type, $a ); |
|
95 | + } |
|
96 | 96 | |
97 | - return $actions; |
|
98 | - } |
|
97 | + return $actions; |
|
98 | + } |
|
99 | 99 | |
100 | 100 | /** |
101 | 101 | * @since 2.0 |
102 | 102 | */ |
103 | - public static function list_actions( $form, $values ) { |
|
104 | - if ( empty( $form ) ) { |
|
105 | - return; |
|
106 | - } |
|
103 | + public static function list_actions( $form, $values ) { |
|
104 | + if ( empty( $form ) ) { |
|
105 | + return; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | /** |
109 | 109 | * use this hook to migrate old settings into a new action |
@@ -113,114 +113,114 @@ discard block |
||
113 | 113 | |
114 | 114 | $form_actions = FrmFormAction::get_action_for_form( $form->id ); |
115 | 115 | |
116 | - $action_controls = self::get_form_actions(); |
|
116 | + $action_controls = self::get_form_actions(); |
|
117 | 117 | |
118 | - $action_map = array(); |
|
118 | + $action_map = array(); |
|
119 | 119 | |
120 | 120 | foreach ( $action_controls as $key => $control ) { |
121 | - $action_map[ $control->id_base ] = $key; |
|
122 | - } |
|
121 | + $action_map[ $control->id_base ] = $key; |
|
122 | + } |
|
123 | 123 | |
124 | - foreach ( $form_actions as $action ) { |
|
125 | - if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
|
126 | - // don't try and show settings if action no longer exists |
|
127 | - continue; |
|
128 | - } |
|
124 | + foreach ( $form_actions as $action ) { |
|
125 | + if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
|
126 | + // don't try and show settings if action no longer exists |
|
127 | + continue; |
|
128 | + } |
|
129 | 129 | |
130 | - self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
|
131 | - } |
|
132 | - } |
|
130 | + self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
|
131 | + } |
|
132 | + } |
|
133 | 133 | |
134 | 134 | public static function action_control( $form_action, $form, $action_key, $action_control, $values ) { |
135 | - $action_control->_set($action_key); |
|
136 | - include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php'); |
|
137 | - } |
|
135 | + $action_control->_set($action_key); |
|
136 | + include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php'); |
|
137 | + } |
|
138 | 138 | |
139 | - public static function add_form_action() { |
|
140 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
139 | + public static function add_form_action() { |
|
140 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
141 | 141 | |
142 | - global $frm_vars; |
|
142 | + global $frm_vars; |
|
143 | 143 | |
144 | 144 | $action_key = absint( $_POST['list_id'] ); |
145 | - $action_type = sanitize_text_field( $_POST['type'] ); |
|
145 | + $action_type = sanitize_text_field( $_POST['type'] ); |
|
146 | 146 | |
147 | - $action_control = self::get_form_actions( $action_type ); |
|
148 | - $action_control->_set($action_key); |
|
147 | + $action_control = self::get_form_actions( $action_type ); |
|
148 | + $action_control->_set($action_key); |
|
149 | 149 | |
150 | - $form_id = absint( $_POST['form_id'] ); |
|
150 | + $form_id = absint( $_POST['form_id'] ); |
|
151 | 151 | |
152 | - $form_action = $action_control->prepare_new($form_id); |
|
152 | + $form_action = $action_control->prepare_new($form_id); |
|
153 | 153 | |
154 | - $values = array(); |
|
155 | - $form = self::fields_to_values($form_id, $values); |
|
154 | + $values = array(); |
|
155 | + $form = self::fields_to_values($form_id, $values); |
|
156 | 156 | |
157 | - include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php'); |
|
158 | - wp_die(); |
|
159 | - } |
|
157 | + include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php'); |
|
158 | + wp_die(); |
|
159 | + } |
|
160 | 160 | |
161 | - public static function fill_action() { |
|
162 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
161 | + public static function fill_action() { |
|
162 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
163 | 163 | |
164 | - $action_key = absint( $_POST['action_id'] ); |
|
165 | - $action_type = sanitize_text_field( $_POST['action_type'] ); |
|
164 | + $action_key = absint( $_POST['action_id'] ); |
|
165 | + $action_type = sanitize_text_field( $_POST['action_type'] ); |
|
166 | 166 | |
167 | - $action_control = self::get_form_actions( $action_type ); |
|
168 | - if ( empty($action_control) ) { |
|
169 | - wp_die(); |
|
170 | - } |
|
167 | + $action_control = self::get_form_actions( $action_type ); |
|
168 | + if ( empty($action_control) ) { |
|
169 | + wp_die(); |
|
170 | + } |
|
171 | 171 | |
172 | - $form_action = $action_control->get_single_action( $action_key ); |
|
172 | + $form_action = $action_control->get_single_action( $action_key ); |
|
173 | 173 | |
174 | - $values = array(); |
|
175 | - $form = self::fields_to_values($form_action->menu_order, $values); |
|
174 | + $values = array(); |
|
175 | + $form = self::fields_to_values($form_action->menu_order, $values); |
|
176 | 176 | |
177 | - include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/_action_inside.php'); |
|
178 | - wp_die(); |
|
179 | - } |
|
177 | + include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/_action_inside.php'); |
|
178 | + wp_die(); |
|
179 | + } |
|
180 | 180 | |
181 | 181 | private static function fields_to_values( $form_id, array &$values ) { |
182 | - $form = FrmForm::getOne($form_id); |
|
182 | + $form = FrmForm::getOne($form_id); |
|
183 | 183 | |
184 | 184 | $values = array( 'fields' => array(), 'id' => $form->id ); |
185 | 185 | |
186 | - $fields = FrmField::get_all_for_form($form->id); |
|
187 | - foreach ( $fields as $k => $f ) { |
|
188 | - $f = (array) $f; |
|
189 | - $opts = (array) $f['field_options']; |
|
190 | - $f = array_merge($opts, $f); |
|
191 | - if ( ! isset( $f['post_field'] ) ) { |
|
192 | - $f['post_field'] = ''; |
|
193 | - } |
|
194 | - $values['fields'][] = $f; |
|
195 | - unset($k, $f); |
|
196 | - } |
|
197 | - |
|
198 | - return $form; |
|
199 | - } |
|
186 | + $fields = FrmField::get_all_for_form($form->id); |
|
187 | + foreach ( $fields as $k => $f ) { |
|
188 | + $f = (array) $f; |
|
189 | + $opts = (array) $f['field_options']; |
|
190 | + $f = array_merge($opts, $f); |
|
191 | + if ( ! isset( $f['post_field'] ) ) { |
|
192 | + $f['post_field'] = ''; |
|
193 | + } |
|
194 | + $values['fields'][] = $f; |
|
195 | + unset($k, $f); |
|
196 | + } |
|
197 | + |
|
198 | + return $form; |
|
199 | + } |
|
200 | 200 | |
201 | 201 | public static function update_settings( $form_id ) { |
202 | - global $wpdb; |
|
202 | + global $wpdb; |
|
203 | 203 | |
204 | - $registered_actions = self::$registered_actions->actions; |
|
204 | + $registered_actions = self::$registered_actions->actions; |
|
205 | 205 | |
206 | 206 | $old_actions = FrmDb::get_col( $wpdb->posts, array( 'post_type' => self::$action_post_type, 'menu_order' => $form_id ), 'ID' ); |
207 | - $new_actions = array(); |
|
207 | + $new_actions = array(); |
|
208 | 208 | |
209 | - foreach ( $registered_actions as $registered_action ) { |
|
210 | - $action_ids = $registered_action->update_callback($form_id); |
|
211 | - if ( ! empty( $action_ids ) ) { |
|
212 | - $new_actions[] = $action_ids; |
|
213 | - } |
|
214 | - } |
|
209 | + foreach ( $registered_actions as $registered_action ) { |
|
210 | + $action_ids = $registered_action->update_callback($form_id); |
|
211 | + if ( ! empty( $action_ids ) ) { |
|
212 | + $new_actions[] = $action_ids; |
|
213 | + } |
|
214 | + } |
|
215 | 215 | |
216 | - //Only use array_merge if there are new actions |
|
217 | - if ( ! empty( $new_actions ) ) { |
|
218 | - $new_actions = call_user_func_array( 'array_merge', $new_actions ); |
|
219 | - } |
|
220 | - $old_actions = array_diff( $old_actions, $new_actions ); |
|
216 | + //Only use array_merge if there are new actions |
|
217 | + if ( ! empty( $new_actions ) ) { |
|
218 | + $new_actions = call_user_func_array( 'array_merge', $new_actions ); |
|
219 | + } |
|
220 | + $old_actions = array_diff( $old_actions, $new_actions ); |
|
221 | 221 | |
222 | 222 | self::delete_missing_actions( $old_actions ); |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | 225 | public static function delete_missing_actions( $old_actions ) { |
226 | 226 | if ( ! empty( $old_actions ) ) { |
@@ -235,36 +235,36 @@ discard block |
||
235 | 235 | self::trigger_actions( 'create', $form_id, $entry_id, 'all', $args ); |
236 | 236 | } |
237 | 237 | |
238 | - /** |
|
239 | - * @param string $event |
|
240 | - */ |
|
238 | + /** |
|
239 | + * @param string $event |
|
240 | + */ |
|
241 | 241 | public static function trigger_actions( $event, $form, $entry, $type = 'all', $args = array() ) { |
242 | 242 | $form_actions = FrmFormAction::get_action_for_form( ( is_object( $form ) ? $form->id : $form ), $type ); |
243 | 243 | |
244 | 244 | if ( empty( $form_actions ) ) { |
245 | - return; |
|
246 | - } |
|
245 | + return; |
|
246 | + } |
|
247 | 247 | |
248 | 248 | FrmForm::maybe_get_form( $form ); |
249 | 249 | |
250 | - $link_settings = self::get_form_actions( $type ); |
|
251 | - if ( 'all' != $type ) { |
|
252 | - $link_settings = array( $type => $link_settings ); |
|
253 | - } |
|
250 | + $link_settings = self::get_form_actions( $type ); |
|
251 | + if ( 'all' != $type ) { |
|
252 | + $link_settings = array( $type => $link_settings ); |
|
253 | + } |
|
254 | 254 | |
255 | - $stored_actions = $action_priority = array(); |
|
255 | + $stored_actions = $action_priority = array(); |
|
256 | 256 | |
257 | 257 | $importing = in_array( $event, array( 'create', 'update' ) ) && defined( 'WP_IMPORTING' ) && WP_IMPORTING; |
258 | 258 | |
259 | - foreach ( $form_actions as $action ) { |
|
259 | + foreach ( $form_actions as $action ) { |
|
260 | 260 | $trigger_on_import = $importing && in_array( 'import', $action->post_content['event'] ); |
261 | 261 | if ( ! in_array( $event, $action->post_content['event'] ) && ! $trigger_on_import ) { |
262 | - continue; |
|
263 | - } |
|
262 | + continue; |
|
263 | + } |
|
264 | 264 | |
265 | - if ( ! is_object( $entry ) ) { |
|
266 | - $entry = FrmEntry::getOne( $entry, true ); |
|
267 | - } |
|
265 | + if ( ! is_object( $entry ) ) { |
|
266 | + $entry = FrmEntry::getOne( $entry, true ); |
|
267 | + } |
|
268 | 268 | |
269 | 269 | if ( empty( $entry ) || $entry->is_draft ) { |
270 | 270 | continue; |
@@ -273,66 +273,66 @@ discard block |
||
273 | 273 | $child_entry = ( ( $form && is_numeric( $form->parent_form_id ) && $form->parent_form_id ) || ( $entry && ( $entry->form_id != $form->id || $entry->parent_item_id ) ) || ( isset( $args['is_child'] ) && $args['is_child'] ) ); |
274 | 274 | |
275 | 275 | if ( $child_entry ) { |
276 | - //don't trigger actions for sub forms |
|
277 | - continue; |
|
278 | - } |
|
276 | + //don't trigger actions for sub forms |
|
277 | + continue; |
|
278 | + } |
|
279 | 279 | |
280 | - // check conditional logic |
|
280 | + // check conditional logic |
|
281 | 281 | $stop = FrmFormAction::action_conditions_met( $action, $entry ); |
282 | - if ( $stop ) { |
|
283 | - continue; |
|
284 | - } |
|
282 | + if ( $stop ) { |
|
283 | + continue; |
|
284 | + } |
|
285 | 285 | |
286 | - // store actions so they can be triggered with the correct priority |
|
287 | - $stored_actions[ $action->ID ] = $action; |
|
288 | - $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
|
286 | + // store actions so they can be triggered with the correct priority |
|
287 | + $stored_actions[ $action->ID ] = $action; |
|
288 | + $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
|
289 | 289 | |
290 | - unset($action); |
|
291 | - } |
|
290 | + unset($action); |
|
291 | + } |
|
292 | 292 | |
293 | - if ( ! empty( $stored_actions ) ) { |
|
294 | - asort($action_priority); |
|
293 | + if ( ! empty( $stored_actions ) ) { |
|
294 | + asort($action_priority); |
|
295 | 295 | |
296 | - // make sure hooks are loaded |
|
297 | - new FrmNotification(); |
|
296 | + // make sure hooks are loaded |
|
297 | + new FrmNotification(); |
|
298 | 298 | |
299 | - foreach ( $action_priority as $action_id => $priority ) { |
|
300 | - $action = $stored_actions[ $action_id ]; |
|
301 | - do_action('frm_trigger_'. $action->post_excerpt .'_action', $action, $entry, $form, $event); |
|
302 | - do_action('frm_trigger_'. $action->post_excerpt .'_'. $event .'_action', $action, $entry, $form); |
|
299 | + foreach ( $action_priority as $action_id => $priority ) { |
|
300 | + $action = $stored_actions[ $action_id ]; |
|
301 | + do_action('frm_trigger_'. $action->post_excerpt .'_action', $action, $entry, $form, $event); |
|
302 | + do_action('frm_trigger_'. $action->post_excerpt .'_'. $event .'_action', $action, $entry, $form); |
|
303 | 303 | |
304 | - // If post is created, get updated $entry object |
|
305 | - if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { |
|
306 | - $entry = FrmEntry::getOne($entry->id, true); |
|
307 | - } |
|
308 | - } |
|
309 | - } |
|
310 | - } |
|
304 | + // If post is created, get updated $entry object |
|
305 | + if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { |
|
306 | + $entry = FrmEntry::getOne($entry->id, true); |
|
307 | + } |
|
308 | + } |
|
309 | + } |
|
310 | + } |
|
311 | 311 | |
312 | 312 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
313 | - if ( ! isset($args['old_id']) || empty($args['old_id']) ) { |
|
314 | - // continue if we know which actions to copy |
|
315 | - return; |
|
316 | - } |
|
313 | + if ( ! isset($args['old_id']) || empty($args['old_id']) ) { |
|
314 | + // continue if we know which actions to copy |
|
315 | + return; |
|
316 | + } |
|
317 | 317 | |
318 | - $action_controls = self::get_form_actions( ); |
|
318 | + $action_controls = self::get_form_actions( ); |
|
319 | 319 | |
320 | - foreach ( $action_controls as $action_control ) { |
|
321 | - $action_control->duplicate_form_actions( $form_id, $args['old_id'] ); |
|
322 | - unset( $action_control ); |
|
323 | - } |
|
324 | - } |
|
320 | + foreach ( $action_controls as $action_control ) { |
|
321 | + $action_control->duplicate_form_actions( $form_id, $args['old_id'] ); |
|
322 | + unset( $action_control ); |
|
323 | + } |
|
324 | + } |
|
325 | 325 | |
326 | - public static function limit_by_type( $where ) { |
|
327 | - global $frm_vars, $wpdb; |
|
326 | + public static function limit_by_type( $where ) { |
|
327 | + global $frm_vars, $wpdb; |
|
328 | 328 | |
329 | - if ( ! isset( $frm_vars['action_type'] ) ) { |
|
330 | - return $where; |
|
331 | - } |
|
329 | + if ( ! isset( $frm_vars['action_type'] ) ) { |
|
330 | + return $where; |
|
331 | + } |
|
332 | 332 | |
333 | - $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); |
|
334 | - return $where; |
|
335 | - } |
|
333 | + $where .= $wpdb->prepare( ' AND post_excerpt = %s ', $frm_vars['action_type'] ); |
|
334 | + return $where; |
|
335 | + } |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | foreach ( $keys as $key ) { |
360 | 360 | // don't register new action if old action with the same id is already registered |
361 | 361 | if ( ! isset( $this->actions[ $key ] ) ) { |
362 | - $this->actions[ $key ]->_register(); |
|
362 | + $this->actions[ $key ]->_register(); |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 | } |
@@ -48,17 +48,17 @@ discard block |
||
48 | 48 | 'highrise' => 'FrmDefHrsAction', |
49 | 49 | ) ); |
50 | 50 | |
51 | - include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php'); |
|
52 | - include_once(FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php'); |
|
51 | + include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/email_action.php' ); |
|
52 | + include_once( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/default_actions.php' ); |
|
53 | 53 | |
54 | 54 | foreach ( $action_classes as $action_class ) { |
55 | - self::$registered_actions->register($action_class); |
|
55 | + self::$registered_actions->register( $action_class ); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | |
59 | 59 | public static function get_form_actions( $action = 'all' ) { |
60 | 60 | $temp_actions = self::$registered_actions; |
61 | - if ( empty($temp_actions) ) { |
|
61 | + if ( empty( $temp_actions ) ) { |
|
62 | 62 | self::actions_init(); |
63 | 63 | $temp_actions = self::$registered_actions->actions; |
64 | 64 | } else { |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | return $a; |
73 | 73 | } |
74 | 74 | |
75 | - $actions[ $a->id_base ] = $a; |
|
75 | + $actions[$a->id_base] = $a; |
|
76 | 76 | } |
77 | 77 | unset( $temp_actions, $a ); |
78 | 78 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | arsort( $temp_actions ); |
87 | 87 | foreach ( $temp_actions as $type => $a ) { |
88 | 88 | if ( ! isset( $a->action_options['active'] ) || empty( $a->action_options['active'] ) ) { |
89 | - unset( $actions[ $type ] ); |
|
89 | + unset( $actions[$type] ); |
|
90 | 90 | if ( count( $actions ) <= $action_limit ) { |
91 | 91 | break; |
92 | 92 | } |
@@ -118,22 +118,22 @@ discard block |
||
118 | 118 | $action_map = array(); |
119 | 119 | |
120 | 120 | foreach ( $action_controls as $key => $control ) { |
121 | - $action_map[ $control->id_base ] = $key; |
|
121 | + $action_map[$control->id_base] = $key; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | foreach ( $form_actions as $action ) { |
125 | - if ( ! isset( $action_map[ $action->post_excerpt ] ) ) { |
|
125 | + if ( ! isset( $action_map[$action->post_excerpt] ) ) { |
|
126 | 126 | // don't try and show settings if action no longer exists |
127 | 127 | continue; |
128 | 128 | } |
129 | 129 | |
130 | - self::action_control( $action, $form, $action->ID, $action_controls[ $action_map[ $action->post_excerpt ] ], $values ); |
|
130 | + self::action_control( $action, $form, $action->ID, $action_controls[$action_map[$action->post_excerpt]], $values ); |
|
131 | 131 | } |
132 | 132 | } |
133 | 133 | |
134 | 134 | public static function action_control( $form_action, $form, $action_key, $action_control, $values ) { |
135 | - $action_control->_set($action_key); |
|
136 | - include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php'); |
|
135 | + $action_control->_set( $action_key ); |
|
136 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' ); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | public static function add_form_action() { |
@@ -145,16 +145,16 @@ discard block |
||
145 | 145 | $action_type = sanitize_text_field( $_POST['type'] ); |
146 | 146 | |
147 | 147 | $action_control = self::get_form_actions( $action_type ); |
148 | - $action_control->_set($action_key); |
|
148 | + $action_control->_set( $action_key ); |
|
149 | 149 | |
150 | 150 | $form_id = absint( $_POST['form_id'] ); |
151 | 151 | |
152 | - $form_action = $action_control->prepare_new($form_id); |
|
152 | + $form_action = $action_control->prepare_new( $form_id ); |
|
153 | 153 | |
154 | 154 | $values = array(); |
155 | - $form = self::fields_to_values($form_id, $values); |
|
155 | + $form = self::fields_to_values( $form_id, $values ); |
|
156 | 156 | |
157 | - include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/form_action.php'); |
|
157 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/form_action.php' ); |
|
158 | 158 | wp_die(); |
159 | 159 | } |
160 | 160 | |
@@ -165,34 +165,34 @@ discard block |
||
165 | 165 | $action_type = sanitize_text_field( $_POST['action_type'] ); |
166 | 166 | |
167 | 167 | $action_control = self::get_form_actions( $action_type ); |
168 | - if ( empty($action_control) ) { |
|
168 | + if ( empty( $action_control ) ) { |
|
169 | 169 | wp_die(); |
170 | 170 | } |
171 | 171 | |
172 | 172 | $form_action = $action_control->get_single_action( $action_key ); |
173 | 173 | |
174 | 174 | $values = array(); |
175 | - $form = self::fields_to_values($form_action->menu_order, $values); |
|
175 | + $form = self::fields_to_values( $form_action->menu_order, $values ); |
|
176 | 176 | |
177 | - include(FrmAppHelper::plugin_path() .'/classes/views/frm-form-actions/_action_inside.php'); |
|
177 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_inside.php' ); |
|
178 | 178 | wp_die(); |
179 | 179 | } |
180 | 180 | |
181 | 181 | private static function fields_to_values( $form_id, array &$values ) { |
182 | - $form = FrmForm::getOne($form_id); |
|
182 | + $form = FrmForm::getOne( $form_id ); |
|
183 | 183 | |
184 | 184 | $values = array( 'fields' => array(), 'id' => $form->id ); |
185 | 185 | |
186 | - $fields = FrmField::get_all_for_form($form->id); |
|
186 | + $fields = FrmField::get_all_for_form( $form->id ); |
|
187 | 187 | foreach ( $fields as $k => $f ) { |
188 | 188 | $f = (array) $f; |
189 | 189 | $opts = (array) $f['field_options']; |
190 | - $f = array_merge($opts, $f); |
|
190 | + $f = array_merge( $opts, $f ); |
|
191 | 191 | if ( ! isset( $f['post_field'] ) ) { |
192 | 192 | $f['post_field'] = ''; |
193 | 193 | } |
194 | 194 | $values['fields'][] = $f; |
195 | - unset($k, $f); |
|
195 | + unset( $k, $f ); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | return $form; |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | $new_actions = array(); |
208 | 208 | |
209 | 209 | foreach ( $registered_actions as $registered_action ) { |
210 | - $action_ids = $registered_action->update_callback($form_id); |
|
210 | + $action_ids = $registered_action->update_callback( $form_id ); |
|
211 | 211 | if ( ! empty( $action_ids ) ) { |
212 | 212 | $new_actions[] = $action_ids; |
213 | 213 | } |
@@ -284,33 +284,33 @@ discard block |
||
284 | 284 | } |
285 | 285 | |
286 | 286 | // store actions so they can be triggered with the correct priority |
287 | - $stored_actions[ $action->ID ] = $action; |
|
288 | - $action_priority[ $action->ID ] = $link_settings[ $action->post_excerpt ]->action_options['priority']; |
|
287 | + $stored_actions[$action->ID] = $action; |
|
288 | + $action_priority[$action->ID] = $link_settings[$action->post_excerpt]->action_options['priority']; |
|
289 | 289 | |
290 | - unset($action); |
|
290 | + unset( $action ); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | if ( ! empty( $stored_actions ) ) { |
294 | - asort($action_priority); |
|
294 | + asort( $action_priority ); |
|
295 | 295 | |
296 | 296 | // make sure hooks are loaded |
297 | 297 | new FrmNotification(); |
298 | 298 | |
299 | 299 | foreach ( $action_priority as $action_id => $priority ) { |
300 | - $action = $stored_actions[ $action_id ]; |
|
301 | - do_action('frm_trigger_'. $action->post_excerpt .'_action', $action, $entry, $form, $event); |
|
302 | - do_action('frm_trigger_'. $action->post_excerpt .'_'. $event .'_action', $action, $entry, $form); |
|
300 | + $action = $stored_actions[$action_id]; |
|
301 | + do_action( 'frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event ); |
|
302 | + do_action( 'frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form ); |
|
303 | 303 | |
304 | 304 | // If post is created, get updated $entry object |
305 | 305 | if ( $action->post_excerpt == 'wppost' && $event == 'create' ) { |
306 | - $entry = FrmEntry::getOne($entry->id, true); |
|
306 | + $entry = FrmEntry::getOne( $entry->id, true ); |
|
307 | 307 | } |
308 | 308 | } |
309 | 309 | } |
310 | 310 | } |
311 | 311 | |
312 | 312 | public static function duplicate_form_actions( $form_id, $values, $args = array() ) { |
313 | - if ( ! isset($args['old_id']) || empty($args['old_id']) ) { |
|
313 | + if ( ! isset( $args['old_id'] ) || empty( $args['old_id'] ) ) { |
|
314 | 314 | // continue if we know which actions to copy |
315 | 315 | return; |
316 | 316 | } |
@@ -344,22 +344,22 @@ discard block |
||
344 | 344 | } |
345 | 345 | |
346 | 346 | public function register( $action_class ) { |
347 | - $this->actions[ $action_class ] = new $action_class(); |
|
347 | + $this->actions[$action_class] = new $action_class(); |
|
348 | 348 | } |
349 | 349 | |
350 | 350 | public function unregister( $action_class ) { |
351 | - if ( isset( $this->actions[ $action_class ] ) ) { |
|
352 | - unset($this->actions[ $action_class ]); |
|
351 | + if ( isset( $this->actions[$action_class] ) ) { |
|
352 | + unset( $this->actions[$action_class] ); |
|
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
356 | 356 | public function _register_actions() { |
357 | - $keys = array_keys($this->actions); |
|
357 | + $keys = array_keys( $this->actions ); |
|
358 | 358 | |
359 | 359 | foreach ( $keys as $key ) { |
360 | 360 | // don't register new action if old action with the same id is already registered |
361 | - if ( ! isset( $this->actions[ $key ] ) ) { |
|
362 | - $this->actions[ $key ]->_register(); |
|
361 | + if ( ! isset( $this->actions[$key] ) ) { |
|
362 | + $this->actions[$key]->_register(); |
|
363 | 363 | } |
364 | 364 | } |
365 | 365 | } |
@@ -1,215 +1,215 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class FrmHooksController { |
4 | - /** |
|
5 | - * Trigger plugin-wide hook loading |
|
6 | - */ |
|
7 | - public static function trigger_load_hook( $hooks = 'load_hooks' ) { |
|
8 | - $controllers = apply_filters( 'frm_load_controllers', array( 'FrmHooksController' ) ); |
|
9 | - |
|
10 | - $trigger_hooks = $hooks; |
|
11 | - $hooks = (array) $hooks; |
|
12 | - |
|
13 | - if ( 'load_hooks' == $trigger_hooks ) { |
|
14 | - if ( is_admin() ) { |
|
15 | - $hooks[] = 'load_admin_hooks'; |
|
16 | - if ( defined( 'DOING_AJAX' ) ) { |
|
17 | - $hooks[] = 'load_ajax_hooks'; |
|
18 | - $hooks[] = 'load_form_hooks'; |
|
19 | - } |
|
20 | - } |
|
21 | - |
|
22 | - if ( is_multisite() ) { |
|
23 | - $hooks[] = 'load_multisite_hooks'; |
|
24 | - } |
|
25 | - } else { |
|
26 | - // Make sure the hooks are only triggered once |
|
27 | - add_filter( 'frm' . str_replace( 'load', '', $trigger_hooks ) . '_loaded', '__return_true' ); |
|
28 | - } |
|
29 | - unset( $trigger_hooks ); |
|
30 | - |
|
31 | - // Instansiate Controllers |
|
32 | - foreach ( $controllers as $c ) { |
|
33 | - foreach ( $hooks as $hook ) { |
|
4 | + /** |
|
5 | + * Trigger plugin-wide hook loading |
|
6 | + */ |
|
7 | + public static function trigger_load_hook( $hooks = 'load_hooks' ) { |
|
8 | + $controllers = apply_filters( 'frm_load_controllers', array( 'FrmHooksController' ) ); |
|
9 | + |
|
10 | + $trigger_hooks = $hooks; |
|
11 | + $hooks = (array) $hooks; |
|
12 | + |
|
13 | + if ( 'load_hooks' == $trigger_hooks ) { |
|
14 | + if ( is_admin() ) { |
|
15 | + $hooks[] = 'load_admin_hooks'; |
|
16 | + if ( defined( 'DOING_AJAX' ) ) { |
|
17 | + $hooks[] = 'load_ajax_hooks'; |
|
18 | + $hooks[] = 'load_form_hooks'; |
|
19 | + } |
|
20 | + } |
|
21 | + |
|
22 | + if ( is_multisite() ) { |
|
23 | + $hooks[] = 'load_multisite_hooks'; |
|
24 | + } |
|
25 | + } else { |
|
26 | + // Make sure the hooks are only triggered once |
|
27 | + add_filter( 'frm' . str_replace( 'load', '', $trigger_hooks ) . '_loaded', '__return_true' ); |
|
28 | + } |
|
29 | + unset( $trigger_hooks ); |
|
30 | + |
|
31 | + // Instansiate Controllers |
|
32 | + foreach ( $controllers as $c ) { |
|
33 | + foreach ( $hooks as $hook ) { |
|
34 | 34 | call_user_func( array( $c, $hook ) ); |
35 | 35 | unset( $hook ); |
36 | - } |
|
36 | + } |
|
37 | 37 | unset( $c ); |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - public static function trigger_load_form_hooks() { |
|
43 | - self::trigger_load_hook( 'load_form_hooks' ); |
|
44 | - } |
|
42 | + public static function trigger_load_form_hooks() { |
|
43 | + self::trigger_load_hook( 'load_form_hooks' ); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | public static function load_hooks() { |
47 | - if ( ! is_admin() ) { |
|
48 | - add_filter( 'the_content', 'FrmAppController::page_route', 10 ); |
|
49 | - } |
|
50 | - |
|
51 | - add_action( 'plugins_loaded', 'FrmAppController::load_lang' ); |
|
52 | - add_filter( 'widget_text', 'FrmAppController::widget_text_filter', 8 ); |
|
53 | - |
|
54 | - // Entries controller |
|
55 | - add_action( 'wp_loaded', 'FrmEntriesController::process_entry', 10, 0 ); |
|
56 | - add_filter( 'frm_redirect_url', 'FrmEntriesController::delete_entry_before_redirect', 50, 3 ); |
|
57 | - add_action( 'frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100 ); |
|
58 | - add_filter( 'frm_email_value', 'FrmEntriesController::filter_email_value', 10, 3 ); |
|
59 | - add_filter( 'frmpro_fields_replace_shortcodes', 'FrmEntriesController::filter_shortcode_value', 10, 4 ); |
|
60 | - |
|
61 | - // Form Actions Controller |
|
62 | - add_action( 'init', 'FrmFormActionsController::register_post_types', 1 ); |
|
47 | + if ( ! is_admin() ) { |
|
48 | + add_filter( 'the_content', 'FrmAppController::page_route', 10 ); |
|
49 | + } |
|
50 | + |
|
51 | + add_action( 'plugins_loaded', 'FrmAppController::load_lang' ); |
|
52 | + add_filter( 'widget_text', 'FrmAppController::widget_text_filter', 8 ); |
|
53 | + |
|
54 | + // Entries controller |
|
55 | + add_action( 'wp_loaded', 'FrmEntriesController::process_entry', 10, 0 ); |
|
56 | + add_filter( 'frm_redirect_url', 'FrmEntriesController::delete_entry_before_redirect', 50, 3 ); |
|
57 | + add_action( 'frm_after_entry_processed', 'FrmEntriesController::delete_entry_after_save', 100 ); |
|
58 | + add_filter( 'frm_email_value', 'FrmEntriesController::filter_email_value', 10, 3 ); |
|
59 | + add_filter( 'frmpro_fields_replace_shortcodes', 'FrmEntriesController::filter_shortcode_value', 10, 4 ); |
|
60 | + |
|
61 | + // Form Actions Controller |
|
62 | + add_action( 'init', 'FrmFormActionsController::register_post_types', 1 ); |
|
63 | 63 | add_action( 'frm_after_create_entry', 'FrmFormActionsController::trigger_create_actions', 20, 3 ); |
64 | 64 | |
65 | - // Forms Controller |
|
66 | - add_action( 'widgets_init', 'FrmFormsController::register_widgets' ); |
|
65 | + // Forms Controller |
|
66 | + add_action( 'widgets_init', 'FrmFormsController::register_widgets' ); |
|
67 | 67 | add_action( 'init', 'FrmFormsController::front_head' ); |
68 | - add_filter( 'frm_content', 'FrmFormsController::filter_content', 10, 3 ); |
|
69 | - add_filter( 'frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20, 3 ); |
|
70 | - add_action( 'admin_bar_init', 'FrmFormsController::admin_bar_css' ); |
|
68 | + add_filter( 'frm_content', 'FrmFormsController::filter_content', 10, 3 ); |
|
69 | + add_filter( 'frm_replace_content_shortcodes', 'FrmFormsController::replace_content_shortcodes', 20, 3 ); |
|
70 | + add_action( 'admin_bar_init', 'FrmFormsController::admin_bar_css' ); |
|
71 | 71 | add_action( 'wp_footer', 'FrmFormsController::footer_js', 1, 0 ); |
72 | 72 | |
73 | 73 | add_action( 'wp_scheduled_delete', 'FrmForm::scheduled_delete' ); |
74 | 74 | |
75 | - // Form Shortcodes |
|
76 | - add_shortcode( 'formidable', 'FrmFormsController::get_form_shortcode' ); |
|
75 | + // Form Shortcodes |
|
76 | + add_shortcode( 'formidable', 'FrmFormsController::get_form_shortcode' ); |
|
77 | 77 | |
78 | - // Styles Controller |
|
79 | - add_action( 'init', 'FrmStylesController::register_post_types', 0 ); |
|
80 | - add_filter( 'frm_get_style_opts', 'FrmStylesController::get_style_opts' ); |
|
81 | - add_filter( 'frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2 ); |
|
82 | - add_filter( 'frm_show_entry_styles', 'FrmStylesController::show_entry_styles' ); |
|
83 | - } |
|
78 | + // Styles Controller |
|
79 | + add_action( 'init', 'FrmStylesController::register_post_types', 0 ); |
|
80 | + add_filter( 'frm_get_style_opts', 'FrmStylesController::get_style_opts' ); |
|
81 | + add_filter( 'frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2 ); |
|
82 | + add_filter( 'frm_show_entry_styles', 'FrmStylesController::show_entry_styles' ); |
|
83 | + } |
|
84 | 84 | |
85 | 85 | public static function load_admin_hooks() { |
86 | - add_action( 'admin_menu', 'FrmAppController::menu', 1 ); |
|
87 | - add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' ); |
|
88 | - add_action( 'admin_notices', 'FrmAppController::pro_get_started_headline' ); |
|
86 | + add_action( 'admin_menu', 'FrmAppController::menu', 1 ); |
|
87 | + add_action( 'admin_enqueue_scripts', 'FrmAppController::load_wp_admin_style' ); |
|
88 | + add_action( 'admin_notices', 'FrmAppController::pro_get_started_headline' ); |
|
89 | 89 | add_action( 'admin_init', 'FrmAppController::admin_init', 11 ); |
90 | 90 | add_filter( 'admin_body_class', 'FrmAppController::wp_admin_body_class' ); |
91 | 91 | add_filter( 'plugin_action_links_' . FrmAppHelper::plugin_folder() . '/formidable.php', 'FrmAppController::settings_link' ); |
92 | 92 | register_activation_hook( FrmAppHelper::plugin_folder() . '/formidable.php', 'FrmAppController::activation_install' ); |
93 | 93 | |
94 | - // Entries Controller |
|
95 | - add_action( 'admin_menu', 'FrmEntriesController::menu', 12 ); |
|
96 | - add_filter( 'contextual_help', 'FrmEntriesController::contextual_help', 10, 3 ); |
|
97 | - add_filter( 'set-screen-option', 'FrmEntriesController::save_per_page', 10, 3 ); |
|
98 | - add_filter( 'update_user_metadata', 'FrmEntriesController::check_hidden_cols', 10, 5 ); |
|
99 | - add_action( 'updated_user_meta', 'FrmEntriesController::update_hidden_cols', 10, 4 ); |
|
100 | - |
|
101 | - // Fields Controller |
|
102 | - add_filter( 'frm_display_field_options', 'FrmFieldsController::display_field_options' ); |
|
103 | - add_action( 'frm_field_options_form', 'FrmFieldsController::add_conditional_update_msg', 50 ); |
|
104 | - |
|
105 | - // Form Actions Controller |
|
106 | - if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
107 | - add_action( 'frm_before_update_form_settings', 'FrmFormActionsController::update_settings' ); |
|
108 | - } |
|
109 | - add_action( 'frm_after_duplicate_form', 'FrmFormActionsController::duplicate_form_actions', 20, 3 ); |
|
110 | - |
|
111 | - // Forms Controller |
|
112 | - add_action( 'admin_menu', 'FrmFormsController::menu', 10 ); |
|
113 | - add_action( 'admin_head-toplevel_page_formidable', 'FrmFormsController::head' ); |
|
114 | - |
|
115 | - add_filter( 'set-screen-option', 'FrmFormsController::save_per_page', 10, 3 ); |
|
116 | - add_action( 'admin_footer', 'FrmFormsController::insert_form_popup' ); |
|
94 | + // Entries Controller |
|
95 | + add_action( 'admin_menu', 'FrmEntriesController::menu', 12 ); |
|
96 | + add_filter( 'contextual_help', 'FrmEntriesController::contextual_help', 10, 3 ); |
|
97 | + add_filter( 'set-screen-option', 'FrmEntriesController::save_per_page', 10, 3 ); |
|
98 | + add_filter( 'update_user_metadata', 'FrmEntriesController::check_hidden_cols', 10, 5 ); |
|
99 | + add_action( 'updated_user_meta', 'FrmEntriesController::update_hidden_cols', 10, 4 ); |
|
100 | + |
|
101 | + // Fields Controller |
|
102 | + add_filter( 'frm_display_field_options', 'FrmFieldsController::display_field_options' ); |
|
103 | + add_action( 'frm_field_options_form', 'FrmFieldsController::add_conditional_update_msg', 50 ); |
|
104 | + |
|
105 | + // Form Actions Controller |
|
106 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
107 | + add_action( 'frm_before_update_form_settings', 'FrmFormActionsController::update_settings' ); |
|
108 | + } |
|
109 | + add_action( 'frm_after_duplicate_form', 'FrmFormActionsController::duplicate_form_actions', 20, 3 ); |
|
110 | + |
|
111 | + // Forms Controller |
|
112 | + add_action( 'admin_menu', 'FrmFormsController::menu', 10 ); |
|
113 | + add_action( 'admin_head-toplevel_page_formidable', 'FrmFormsController::head' ); |
|
114 | + |
|
115 | + add_filter( 'set-screen-option', 'FrmFormsController::save_per_page', 10, 3 ); |
|
116 | + add_action( 'admin_footer', 'FrmFormsController::insert_form_popup' ); |
|
117 | 117 | add_action( 'media_buttons', 'FrmFormsController::insert_form_button' ); |
118 | 118 | |
119 | - // Forms Model |
|
120 | - add_action( 'frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2 ); |
|
119 | + // Forms Model |
|
120 | + add_action( 'frm_after_duplicate_form', 'FrmForm::after_duplicate', 10, 2 ); |
|
121 | 121 | |
122 | - // Settings Controller |
|
123 | - add_action( 'admin_menu', 'FrmSettingsController::menu', 45 ); |
|
124 | - add_action( 'frm_before_settings', 'FrmSettingsController::license_box' ); |
|
122 | + // Settings Controller |
|
123 | + add_action( 'admin_menu', 'FrmSettingsController::menu', 45 ); |
|
124 | + add_action( 'frm_before_settings', 'FrmSettingsController::license_box' ); |
|
125 | 125 | |
126 | - // Stats Controller |
|
127 | - add_action( 'admin_menu', 'FrmStatisticsController::menu', 24 ); |
|
128 | - add_action( 'frm_form_action_reports', 'FrmStatisticsController::list_reports' ); |
|
126 | + // Stats Controller |
|
127 | + add_action( 'admin_menu', 'FrmStatisticsController::menu', 24 ); |
|
128 | + add_action( 'frm_form_action_reports', 'FrmStatisticsController::list_reports' ); |
|
129 | 129 | |
130 | - // Styles Controller |
|
131 | - add_action( 'admin_menu', 'FrmStylesController::menu', 14 ); |
|
132 | - add_action( 'admin_init', 'FrmStylesController::admin_init' ); |
|
130 | + // Styles Controller |
|
131 | + add_action( 'admin_menu', 'FrmStylesController::menu', 14 ); |
|
132 | + add_action( 'admin_init', 'FrmStylesController::admin_init' ); |
|
133 | 133 | |
134 | - // XML Controller |
|
135 | - add_action( 'admin_menu', 'FrmXMLController::menu', 41 ); |
|
136 | - } |
|
134 | + // XML Controller |
|
135 | + add_action( 'admin_menu', 'FrmXMLController::menu', 41 ); |
|
136 | + } |
|
137 | 137 | |
138 | 138 | public static function load_ajax_hooks() { |
139 | 139 | add_action( 'wp_ajax_frm_silent_upgrade', 'FrmAppController::ajax_install' ); |
140 | 140 | add_action( 'wp_ajax_nopriv_frm_silent_upgrade', 'FrmAppController::ajax_install' ); |
141 | 141 | add_action( 'wp_ajax_frm_install', 'FrmAppController::ajax_install' ); |
142 | - add_action( 'wp_ajax_frm_uninstall', 'FrmAppController::uninstall' ); |
|
143 | - add_action( 'wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' ); |
|
142 | + add_action( 'wp_ajax_frm_uninstall', 'FrmAppController::uninstall' ); |
|
143 | + add_action( 'wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' ); |
|
144 | 144 | |
145 | 145 | // Addons Controller |
146 | 146 | add_action('wp_ajax_frm_addon_activate', 'FrmAddon::activate' ); |
147 | 147 | add_action('wp_ajax_frm_addon_deactivate', 'FrmAddon::deactivate' ); |
148 | 148 | |
149 | - // Fields Controller |
|
150 | - add_action( 'wp_ajax_frm_load_field', 'FrmFieldsController::load_field' ); |
|
151 | - add_action( 'wp_ajax_frm_insert_field', 'FrmFieldsController::create' ); |
|
152 | - add_action( 'wp_ajax_frm_update_field_form_id', 'FrmFieldsController::update_form_id' ); |
|
153 | - add_action( 'wp_ajax_frm_field_name_in_place_edit', 'FrmFieldsController::edit_name' ); |
|
154 | - add_action( 'wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option' ); |
|
155 | - add_action( 'wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate' ); |
|
156 | - add_action( 'wp_ajax_frm_delete_field', 'FrmFieldsController::destroy' ); |
|
157 | - add_action( 'wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option' ); |
|
158 | - add_action( 'wp_ajax_frm_field_option_ipe', 'FrmFieldsController::edit_option' ); |
|
159 | - add_action( 'wp_ajax_frm_delete_field_option', 'FrmFieldsController::delete_option' ); |
|
160 | - add_action( 'wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices' ); |
|
161 | - add_action( 'wp_ajax_frm_import_options', 'FrmFieldsController::import_options' ); |
|
162 | - add_action( 'wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order' ); |
|
163 | - |
|
164 | - // Form Actions Controller |
|
165 | - add_action( 'wp_ajax_frm_add_form_action', 'FrmFormActionsController::add_form_action' ); |
|
166 | - add_action( 'wp_ajax_frm_form_action_fill', 'FrmFormActionsController::fill_action' ); |
|
167 | - |
|
168 | - // Forms Controller |
|
149 | + // Fields Controller |
|
150 | + add_action( 'wp_ajax_frm_load_field', 'FrmFieldsController::load_field' ); |
|
151 | + add_action( 'wp_ajax_frm_insert_field', 'FrmFieldsController::create' ); |
|
152 | + add_action( 'wp_ajax_frm_update_field_form_id', 'FrmFieldsController::update_form_id' ); |
|
153 | + add_action( 'wp_ajax_frm_field_name_in_place_edit', 'FrmFieldsController::edit_name' ); |
|
154 | + add_action( 'wp_ajax_frm_update_ajax_option', 'FrmFieldsController::update_ajax_option' ); |
|
155 | + add_action( 'wp_ajax_frm_duplicate_field', 'FrmFieldsController::duplicate' ); |
|
156 | + add_action( 'wp_ajax_frm_delete_field', 'FrmFieldsController::destroy' ); |
|
157 | + add_action( 'wp_ajax_frm_add_field_option', 'FrmFieldsController::add_option' ); |
|
158 | + add_action( 'wp_ajax_frm_field_option_ipe', 'FrmFieldsController::edit_option' ); |
|
159 | + add_action( 'wp_ajax_frm_delete_field_option', 'FrmFieldsController::delete_option' ); |
|
160 | + add_action( 'wp_ajax_frm_import_choices', 'FrmFieldsController::import_choices' ); |
|
161 | + add_action( 'wp_ajax_frm_import_options', 'FrmFieldsController::import_options' ); |
|
162 | + add_action( 'wp_ajax_frm_update_field_order', 'FrmFieldsController::update_order' ); |
|
163 | + |
|
164 | + // Form Actions Controller |
|
165 | + add_action( 'wp_ajax_frm_add_form_action', 'FrmFormActionsController::add_form_action' ); |
|
166 | + add_action( 'wp_ajax_frm_form_action_fill', 'FrmFormActionsController::fill_action' ); |
|
167 | + |
|
168 | + // Forms Controller |
|
169 | 169 | add_action( 'wp_ajax_frm_create_from_template', 'FrmFormsController::_create_from_template' ); |
170 | 170 | add_action( 'wp_ajax_frm_save_form', 'FrmFormsController::route' ); |
171 | 171 | add_action( 'wp_ajax_frm_form_key_in_place_edit', 'FrmFormsController::edit_key' ); |
172 | 172 | add_action( 'wp_ajax_frm_form_desc_in_place_edit', 'FrmFormsController::edit_description' ); |
173 | - add_action( 'wp_ajax_frm_get_default_html', 'FrmFormsController::get_email_html' ); |
|
174 | - add_action( 'wp_ajax_frm_get_shortcode_opts', 'FrmFormsController::get_shortcode_opts' ); |
|
175 | - add_action( 'wp_ajax_frm_forms_preview', 'FrmFormsController::preview' ); |
|
176 | - add_action( 'wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview' ); |
|
177 | - |
|
178 | - // Styles Controller |
|
179 | - add_action( 'wp_ajax_frm_settings_reset', 'FrmStylesController::reset_styling' ); |
|
180 | - add_action( 'wp_ajax_frm_change_styling', 'FrmStylesController::change_styling' ); |
|
181 | - add_action( 'wp_ajax_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
182 | - add_action( 'wp_ajax_nopriv_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
173 | + add_action( 'wp_ajax_frm_get_default_html', 'FrmFormsController::get_email_html' ); |
|
174 | + add_action( 'wp_ajax_frm_get_shortcode_opts', 'FrmFormsController::get_shortcode_opts' ); |
|
175 | + add_action( 'wp_ajax_frm_forms_preview', 'FrmFormsController::preview' ); |
|
176 | + add_action( 'wp_ajax_nopriv_frm_forms_preview', 'FrmFormsController::preview' ); |
|
177 | + |
|
178 | + // Styles Controller |
|
179 | + add_action( 'wp_ajax_frm_settings_reset', 'FrmStylesController::reset_styling' ); |
|
180 | + add_action( 'wp_ajax_frm_change_styling', 'FrmStylesController::change_styling' ); |
|
181 | + add_action( 'wp_ajax_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
182 | + add_action( 'wp_ajax_nopriv_frmpro_load_css', 'FrmStylesController::load_css' ); |
|
183 | 183 | add_action( 'wp_ajax_frmpro_css', 'FrmStylesController::load_saved_css' ); |
184 | 184 | add_action( 'wp_ajax_nopriv_frmpro_css', 'FrmStylesController::load_saved_css' ); |
185 | 185 | |
186 | - // XML Controller |
|
187 | - add_action( 'wp_ajax_frm_export_xml', 'FrmXMLController::export_xml' ); |
|
188 | - } |
|
186 | + // XML Controller |
|
187 | + add_action( 'wp_ajax_frm_export_xml', 'FrmXMLController::export_xml' ); |
|
188 | + } |
|
189 | 189 | |
190 | 190 | public static function load_form_hooks() { |
191 | - // Fields Controller |
|
192 | - add_filter( 'frm_field_type', 'FrmFieldsController::change_type' ); |
|
193 | - add_action( 'frm_field_input_html', 'FrmFieldsController::input_html' ); |
|
194 | - add_filter( 'frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3 ); |
|
195 | - add_filter( 'frm_field_label_seen', 'FrmFieldsController::check_label' ); |
|
191 | + // Fields Controller |
|
192 | + add_filter( 'frm_field_type', 'FrmFieldsController::change_type' ); |
|
193 | + add_action( 'frm_field_input_html', 'FrmFieldsController::input_html' ); |
|
194 | + add_filter( 'frm_field_value_saved', 'FrmFieldsController::check_value', 50, 3 ); |
|
195 | + add_filter( 'frm_field_label_seen', 'FrmFieldsController::check_label' ); |
|
196 | 196 | |
197 | 197 | // Forms Controller |
198 | 198 | add_filter( 'frm_form_classes', 'FrmFormsController::form_classes' ); |
199 | 199 | |
200 | - // Styles Controller |
|
201 | - add_filter( 'frm_use_important_width', 'FrmStylesController::important_style', 10, 2 ); |
|
202 | - } |
|
200 | + // Styles Controller |
|
201 | + add_filter( 'frm_use_important_width', 'FrmStylesController::important_style', 10, 2 ); |
|
202 | + } |
|
203 | 203 | |
204 | 204 | public static function load_view_hooks() { |
205 | - // Hooks go here when a view is loaded |
|
206 | - } |
|
205 | + // Hooks go here when a view is loaded |
|
206 | + } |
|
207 | 207 | |
208 | 208 | public static function load_multisite_hooks() { |
209 | 209 | add_action( 'init', 'FrmAppController::front_head' ); |
210 | 210 | add_action( 'wpmu_upgrade_site', 'FrmAppController::network_upgrade_site' ); |
211 | 211 | |
212 | - // drop tables when mu site is deleted |
|
213 | - add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' ); |
|
214 | - } |
|
212 | + // drop tables when mu site is deleted |
|
213 | + add_filter( 'wpmu_drop_tables', 'FrmAppController::drop_tables' ); |
|
214 | + } |
|
215 | 215 | } |
@@ -143,8 +143,8 @@ |
||
143 | 143 | add_action( 'wp_ajax_frm_deauthorize', 'FrmAppController::deauthorize' ); |
144 | 144 | |
145 | 145 | // Addons Controller |
146 | - add_action('wp_ajax_frm_addon_activate', 'FrmAddon::activate' ); |
|
147 | - add_action('wp_ajax_frm_addon_deactivate', 'FrmAddon::deactivate' ); |
|
146 | + add_action( 'wp_ajax_frm_addon_activate', 'FrmAddon::activate' ); |
|
147 | + add_action( 'wp_ajax_frm_addon_deactivate', 'FrmAddon::deactivate' ); |
|
148 | 148 | |
149 | 149 | // Fields Controller |
150 | 150 | add_action( 'wp_ajax_frm_load_field', 'FrmFieldsController::load_field' ); |
@@ -2,78 +2,78 @@ |
||
2 | 2 | |
3 | 3 | class FrmSettingsController { |
4 | 4 | |
5 | - public static function menu() { |
|
5 | + public static function menu() { |
|
6 | 6 | // Make sure admins can see the menu items |
7 | 7 | FrmAppHelper::force_capability( 'frm_change_settings' ); |
8 | 8 | |
9 | - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' ); |
|
10 | - } |
|
9 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' ); |
|
10 | + } |
|
11 | 11 | |
12 | - public static function license_box() { |
|
12 | + public static function license_box() { |
|
13 | 13 | $a = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' ); |
14 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/license_box.php' ); |
|
15 | - } |
|
14 | + include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/license_box.php' ); |
|
15 | + } |
|
16 | 16 | |
17 | - public static function display_form( $errors = array(), $message = '' ) { |
|
18 | - global $frm_vars; |
|
17 | + public static function display_form( $errors = array(), $message = '' ) { |
|
18 | + global $frm_vars; |
|
19 | 19 | |
20 | - $frm_settings = FrmAppHelper::get_settings(); |
|
21 | - $frm_roles = FrmAppHelper::frm_capabilities(); |
|
20 | + $frm_settings = FrmAppHelper::get_settings(); |
|
21 | + $frm_roles = FrmAppHelper::frm_capabilities(); |
|
22 | 22 | |
23 | - $uploads = wp_upload_dir(); |
|
24 | - $target_path = $uploads['basedir'] . '/formidable/css'; |
|
23 | + $uploads = wp_upload_dir(); |
|
24 | + $target_path = $uploads['basedir'] . '/formidable/css'; |
|
25 | 25 | |
26 | 26 | $sections = array(); |
27 | 27 | if ( apply_filters( 'frm_include_addon_page', false ) ) { |
28 | 28 | $sections['licenses'] = array( 'class' => 'FrmAddonsController', 'function' => 'show_addons' ); |
29 | 29 | } |
30 | - $sections = apply_filters( 'frm_add_settings_section', $sections ); |
|
30 | + $sections = apply_filters( 'frm_add_settings_section', $sections ); |
|
31 | 31 | |
32 | - $captcha_lang = FrmAppHelper::locales( 'captcha' ); |
|
32 | + $captcha_lang = FrmAppHelper::locales( 'captcha' ); |
|
33 | 33 | |
34 | - require( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/form.php' ); |
|
35 | - } |
|
34 | + require( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/form.php' ); |
|
35 | + } |
|
36 | 36 | |
37 | - public static function process_form( $stop_load = false ) { |
|
38 | - global $frm_vars; |
|
37 | + public static function process_form( $stop_load = false ) { |
|
38 | + global $frm_vars; |
|
39 | 39 | |
40 | - $frm_settings = FrmAppHelper::get_settings(); |
|
40 | + $frm_settings = FrmAppHelper::get_settings(); |
|
41 | 41 | |
42 | 42 | $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); |
43 | 43 | if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { |
44 | - wp_die( $frm_settings->admin_permission ); |
|
45 | - } |
|
44 | + wp_die( $frm_settings->admin_permission ); |
|
45 | + } |
|
46 | 46 | |
47 | - $errors = array(); |
|
48 | - $message = ''; |
|
47 | + $errors = array(); |
|
48 | + $message = ''; |
|
49 | 49 | |
50 | - if ( ! isset( $frm_vars['settings_routed'] ) || ! $frm_vars['settings_routed'] ) { |
|
51 | - //$errors = $frm_settings->validate($_POST,array()); |
|
52 | - $frm_settings->update( stripslashes_deep( $_POST ) ); |
|
50 | + if ( ! isset( $frm_vars['settings_routed'] ) || ! $frm_vars['settings_routed'] ) { |
|
51 | + //$errors = $frm_settings->validate($_POST,array()); |
|
52 | + $frm_settings->update( stripslashes_deep( $_POST ) ); |
|
53 | 53 | |
54 | - if ( empty( $errors ) ) { |
|
55 | - $frm_settings->store(); |
|
56 | - $message = __( 'Settings Saved', 'formidable' ); |
|
57 | - } |
|
58 | - } else { |
|
59 | - $message = __( 'Settings Saved', 'formidable' ); |
|
60 | - } |
|
54 | + if ( empty( $errors ) ) { |
|
55 | + $frm_settings->store(); |
|
56 | + $message = __( 'Settings Saved', 'formidable' ); |
|
57 | + } |
|
58 | + } else { |
|
59 | + $message = __( 'Settings Saved', 'formidable' ); |
|
60 | + } |
|
61 | 61 | |
62 | 62 | if ( $stop_load == 'stop_load' ) { |
63 | - $frm_vars['settings_routed'] = true; |
|
64 | - return; |
|
65 | - } |
|
63 | + $frm_vars['settings_routed'] = true; |
|
64 | + return; |
|
65 | + } |
|
66 | 66 | |
67 | - self::display_form( $errors, $message ); |
|
68 | - } |
|
67 | + self::display_form( $errors, $message ); |
|
68 | + } |
|
69 | 69 | |
70 | - public static function route( $stop_load = false ) { |
|
71 | - $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
70 | + public static function route( $stop_load = false ) { |
|
71 | + $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
72 | 72 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
73 | - if ( $action == 'process-form' ) { |
|
74 | - return self::process_form( $stop_load ); |
|
75 | - } else if ( $stop_load != 'stop_load' ) { |
|
76 | - return self::display_form(); |
|
77 | - } |
|
78 | - } |
|
73 | + if ( $action == 'process-form' ) { |
|
74 | + return self::process_form( $stop_load ); |
|
75 | + } else if ( $stop_load != 'stop_load' ) { |
|
76 | + return self::display_form(); |
|
77 | + } |
|
78 | + } |
|
79 | 79 | } |