@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -1,21 +1,21 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | class FrmStylesController { |
4 | - public static $post_type = 'frm_styles'; |
|
5 | - public static $screen = 'formidable_page_formidable-styles'; |
|
6 | - |
|
7 | - public static function load_pro_hooks() { |
|
8 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
9 | - FrmProStylesController::load_pro_hooks(); |
|
10 | - } |
|
11 | - } |
|
12 | - |
|
13 | - public static function register_post_types() { |
|
14 | - register_post_type( self::$post_type, array( |
|
15 | - 'label' => __( 'Styles', 'formidable' ), |
|
16 | - 'public' => false, |
|
17 | - 'show_ui' => false, |
|
18 | - 'capability_type' => 'page', |
|
4 | + public static $post_type = 'frm_styles'; |
|
5 | + public static $screen = 'formidable_page_formidable-styles'; |
|
6 | + |
|
7 | + public static function load_pro_hooks() { |
|
8 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
9 | + FrmProStylesController::load_pro_hooks(); |
|
10 | + } |
|
11 | + } |
|
12 | + |
|
13 | + public static function register_post_types() { |
|
14 | + register_post_type( self::$post_type, array( |
|
15 | + 'label' => __( 'Styles', 'formidable' ), |
|
16 | + 'public' => false, |
|
17 | + 'show_ui' => false, |
|
18 | + 'capability_type' => 'page', |
|
19 | 19 | 'capabilities' => array( |
20 | 20 | 'edit_post' => 'frm_change_settings', |
21 | 21 | 'edit_posts' => 'frm_change_settings', |
@@ -25,11 +25,11 @@ discard block |
||
25 | 25 | 'delete_posts' => 'frm_change_settings', |
26 | 26 | 'read_private_posts' => 'read_private_posts', |
27 | 27 | ), |
28 | - 'supports' => array( |
|
28 | + 'supports' => array( |
|
29 | 29 | 'title', |
30 | - ), |
|
31 | - 'has_archive' => false, |
|
32 | - 'labels' => array( |
|
30 | + ), |
|
31 | + 'has_archive' => false, |
|
32 | + 'labels' => array( |
|
33 | 33 | 'name' => __( 'Styles', 'formidable' ), |
34 | 34 | 'singular_name' => __( 'Style', 'formidable' ), |
35 | 35 | 'menu_name' => __( 'Style', 'formidable' ), |
@@ -37,31 +37,31 @@ discard block |
||
37 | 37 | 'add_new_item' => __( 'Create a New Style', 'formidable' ), |
38 | 38 | 'edit_item' => __( 'Edit Style', 'formidable' ), |
39 | 39 | ), |
40 | - ) ); |
|
41 | - } |
|
40 | + ) ); |
|
41 | + } |
|
42 | 42 | |
43 | - public static function menu() { |
|
44 | - add_submenu_page('formidable', 'Formidable | '. __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route'); |
|
45 | - } |
|
43 | + public static function menu() { |
|
44 | + add_submenu_page('formidable', 'Formidable | '. __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route'); |
|
45 | + } |
|
46 | 46 | |
47 | - public static function admin_init() { |
|
48 | - if ( ! FrmAppHelper::is_admin_page('formidable-styles') ) { |
|
49 | - return; |
|
50 | - } |
|
47 | + public static function admin_init() { |
|
48 | + if ( ! FrmAppHelper::is_admin_page('formidable-styles') ) { |
|
49 | + return; |
|
50 | + } |
|
51 | 51 | |
52 | - self::load_pro_hooks(); |
|
53 | - wp_enqueue_script('jquery-ui-datepicker'); |
|
52 | + self::load_pro_hooks(); |
|
53 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
54 | 54 | |
55 | - $version = FrmAppHelper::plugin_version(); |
|
55 | + $version = FrmAppHelper::plugin_version(); |
|
56 | 56 | wp_enqueue_script( 'jquery-frm-themepicker', FrmAppHelper::plugin_url() . '/js/jquery/jquery-ui-themepicker.js', array( 'jquery' ), $version ); |
57 | 57 | |
58 | - wp_enqueue_style('frm-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_css'); |
|
58 | + wp_enqueue_style('frm-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_css'); |
|
59 | 59 | |
60 | - $style = apply_filters('frm_style_head', false); |
|
61 | - if ( $style ) { |
|
62 | - wp_enqueue_style('frm-single-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_load_css&flat=1&'. http_build_query($style->post_content)); |
|
63 | - } |
|
64 | - } |
|
60 | + $style = apply_filters('frm_style_head', false); |
|
61 | + if ( $style ) { |
|
62 | + wp_enqueue_style('frm-single-custom-theme', admin_url('admin-ajax.php') .'?action=frmpro_load_css&flat=1&'. http_build_query($style->post_content)); |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | 66 | public static function enqueue_css( $register = 'enqueue' ) { |
67 | 67 | global $frm_vars; |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | } |
129 | 129 | |
130 | 130 | public static function new_style( $return = '' ) { |
131 | - FrmAppHelper::update_message( __( 'create multiple styling templates', 'formidable' ), 'wrap' ); |
|
132 | - self::load_styler('default'); |
|
133 | - } |
|
131 | + FrmAppHelper::update_message( __( 'create multiple styling templates', 'formidable' ), 'wrap' ); |
|
132 | + self::load_styler('default'); |
|
133 | + } |
|
134 | 134 | |
135 | 135 | public static function duplicate() { |
136 | 136 | FrmAppHelper::update_message( __( 'duplicate styling templates', 'formidable' ), 'wrap' ); |
@@ -138,219 +138,219 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | public static function edit( $style_id = false, $message = '' ) { |
141 | - if ( ! $style_id ) { |
|
141 | + if ( ! $style_id ) { |
|
142 | 142 | $style_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' ); |
143 | - if ( empty($style_id) ) { |
|
144 | - $style_id = 'default'; |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - if ( 'default' == $style_id ) { |
|
149 | - $style = 'default'; |
|
150 | - } else { |
|
151 | - $frm_style = new FrmStyle($style_id); |
|
152 | - $style = $frm_style->get_one(); |
|
153 | - $style = $style->ID; |
|
154 | - } |
|
155 | - |
|
156 | - self::load_styler($style, $message); |
|
157 | - } |
|
158 | - |
|
159 | - public static function save() { |
|
160 | - $frm_style = new FrmStyle(); |
|
161 | - $message = ''; |
|
143 | + if ( empty($style_id) ) { |
|
144 | + $style_id = 'default'; |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + if ( 'default' == $style_id ) { |
|
149 | + $style = 'default'; |
|
150 | + } else { |
|
151 | + $frm_style = new FrmStyle($style_id); |
|
152 | + $style = $frm_style->get_one(); |
|
153 | + $style = $style->ID; |
|
154 | + } |
|
155 | + |
|
156 | + self::load_styler($style, $message); |
|
157 | + } |
|
158 | + |
|
159 | + public static function save() { |
|
160 | + $frm_style = new FrmStyle(); |
|
161 | + $message = ''; |
|
162 | 162 | $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' ); |
163 | 163 | $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' ); |
164 | 164 | |
165 | 165 | if ( $post_id !== false && wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) { |
166 | - $id = $frm_style->update($post_id); |
|
167 | - if ( empty($post_id) && ! empty($id) ) { |
|
168 | - // set the post id to the new style so it will be loaded for editing |
|
169 | - $post_id = reset($id); |
|
170 | - } |
|
171 | - // include the CSS that includes this style |
|
166 | + $id = $frm_style->update($post_id); |
|
167 | + if ( empty($post_id) && ! empty($id) ) { |
|
168 | + // set the post id to the new style so it will be loaded for editing |
|
169 | + $post_id = reset($id); |
|
170 | + } |
|
171 | + // include the CSS that includes this style |
|
172 | 172 | echo '<link href="' . esc_url( admin_url( 'admin-ajax.php' ) . '?action=frmpro_css' ) . '" type="text/css" rel="Stylesheet" class="frm-custom-theme" />'; |
173 | - $message = __( 'Your styling settings have been saved.', 'formidable' ); |
|
174 | - } |
|
173 | + $message = __( 'Your styling settings have been saved.', 'formidable' ); |
|
174 | + } |
|
175 | 175 | |
176 | - return self::edit($post_id, $message); |
|
177 | - } |
|
176 | + return self::edit($post_id, $message); |
|
177 | + } |
|
178 | 178 | |
179 | 179 | public static function load_styler( $style, $message = '' ) { |
180 | - global $frm_settings; |
|
180 | + global $frm_settings; |
|
181 | 181 | |
182 | - $frm_style = new FrmStyle(); |
|
183 | - $styles = $frm_style->get_all(); |
|
182 | + $frm_style = new FrmStyle(); |
|
183 | + $styles = $frm_style->get_all(); |
|
184 | 184 | |
185 | - if ( is_numeric($style) ) { |
|
186 | - $style = $styles[ $style ]; |
|
187 | - } else if ( 'default' == $style ) { |
|
188 | - $style = $frm_style->get_default_style($styles); |
|
189 | - } |
|
185 | + if ( is_numeric($style) ) { |
|
186 | + $style = $styles[ $style ]; |
|
187 | + } else if ( 'default' == $style ) { |
|
188 | + $style = $frm_style->get_default_style($styles); |
|
189 | + } |
|
190 | 190 | |
191 | - self::add_meta_boxes(); |
|
191 | + self::add_meta_boxes(); |
|
192 | 192 | |
193 | - include(FrmAppHelper::plugin_path() .'/classes/views/styles/show.php'); |
|
194 | - } |
|
193 | + include(FrmAppHelper::plugin_path() .'/classes/views/styles/show.php'); |
|
194 | + } |
|
195 | 195 | |
196 | 196 | /** |
197 | 197 | * @param string $message |
198 | 198 | * @param array $forms |
199 | 199 | */ |
200 | 200 | private static function manage( $message = '', $forms = array() ) { |
201 | - $frm_style = new FrmStyle(); |
|
202 | - $styles = $frm_style->get_all(); |
|
203 | - $default_style = $frm_style->get_default_style($styles); |
|
201 | + $frm_style = new FrmStyle(); |
|
202 | + $styles = $frm_style->get_all(); |
|
203 | + $default_style = $frm_style->get_default_style($styles); |
|
204 | 204 | |
205 | - if ( empty($forms) ) { |
|
206 | - $forms = FrmForm::get_published_forms(); |
|
207 | - } |
|
205 | + if ( empty($forms) ) { |
|
206 | + $forms = FrmForm::get_published_forms(); |
|
207 | + } |
|
208 | 208 | |
209 | - include(FrmAppHelper::plugin_path() .'/classes/views/styles/manage.php'); |
|
210 | - } |
|
209 | + include(FrmAppHelper::plugin_path() .'/classes/views/styles/manage.php'); |
|
210 | + } |
|
211 | 211 | |
212 | - private static function manage_styles() { |
|
212 | + private static function manage_styles() { |
|
213 | 213 | $style_nonce = FrmAppHelper::get_post_param( 'frm_manage_style', '', 'sanitize_text_field' ); |
214 | 214 | if ( ! $_POST || ! isset( $_POST['style'] ) || ! wp_verify_nonce( $style_nonce, 'frm_manage_style_nonce' ) ) { |
215 | - return self::manage(); |
|
216 | - } |
|
215 | + return self::manage(); |
|
216 | + } |
|
217 | 217 | |
218 | - global $wpdb; |
|
218 | + global $wpdb; |
|
219 | 219 | |
220 | 220 | $forms = FrmForm::get_published_forms(); |
221 | - foreach ( $forms as $form ) { |
|
222 | - if ( $_POST['style'][ $form->id ] == $_POST['prev_style'][ $form->id ] ) { |
|
223 | - continue; |
|
224 | - } |
|
221 | + foreach ( $forms as $form ) { |
|
222 | + if ( $_POST['style'][ $form->id ] == $_POST['prev_style'][ $form->id ] ) { |
|
223 | + continue; |
|
224 | + } |
|
225 | 225 | |
226 | - $form->options['custom_style'] = $_POST['style'][ $form->id ]; |
|
226 | + $form->options['custom_style'] = $_POST['style'][ $form->id ]; |
|
227 | 227 | |
228 | 228 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) ); |
229 | - unset($form); |
|
230 | - } |
|
229 | + unset($form); |
|
230 | + } |
|
231 | 231 | |
232 | - $message = __( 'Your form styles have been saved.', 'formidable' ); |
|
233 | - return self::manage($message, $forms); |
|
234 | - } |
|
232 | + $message = __( 'Your form styles have been saved.', 'formidable' ); |
|
233 | + return self::manage($message, $forms); |
|
234 | + } |
|
235 | 235 | |
236 | - public static function custom_css( $message = '', $style = null ) { |
|
237 | - wp_enqueue_style('codemirror', FrmAppHelper::plugin_url() . '/css/codemirror.css'); |
|
238 | - wp_enqueue_script('codemirror', FrmAppHelper::plugin_url() . '/js/codemirror/codemirror.js', array(), '4.7'); |
|
239 | - wp_enqueue_script( 'codemirror-css', FrmAppHelper::plugin_url() . '/js/codemirror/css.js', array( 'codemirror' ), '4.7' ); |
|
236 | + public static function custom_css( $message = '', $style = null ) { |
|
237 | + wp_enqueue_style('codemirror', FrmAppHelper::plugin_url() . '/css/codemirror.css'); |
|
238 | + wp_enqueue_script('codemirror', FrmAppHelper::plugin_url() . '/js/codemirror/codemirror.js', array(), '4.7'); |
|
239 | + wp_enqueue_script( 'codemirror-css', FrmAppHelper::plugin_url() . '/js/codemirror/css.js', array( 'codemirror' ), '4.7' ); |
|
240 | 240 | |
241 | - if ( ! isset($style) ) { |
|
242 | - $frm_style = new FrmStyle(); |
|
243 | - $style = $frm_style->get_default_style(); |
|
244 | - } |
|
241 | + if ( ! isset($style) ) { |
|
242 | + $frm_style = new FrmStyle(); |
|
243 | + $style = $frm_style->get_default_style(); |
|
244 | + } |
|
245 | 245 | |
246 | - include(FrmAppHelper::plugin_path() .'/classes/views/styles/custom_css.php'); |
|
247 | - } |
|
246 | + include(FrmAppHelper::plugin_path() .'/classes/views/styles/custom_css.php'); |
|
247 | + } |
|
248 | 248 | |
249 | - public static function save_css() { |
|
250 | - $frm_style = new FrmStyle(); |
|
249 | + public static function save_css() { |
|
250 | + $frm_style = new FrmStyle(); |
|
251 | 251 | |
252 | - $message = ''; |
|
252 | + $message = ''; |
|
253 | 253 | $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_text_field' ); |
254 | 254 | $nonce = FrmAppHelper::get_post_param( 'frm_custom_css', '', 'sanitize_text_field' ); |
255 | 255 | if ( wp_verify_nonce( $nonce, 'frm_custom_css_nonce' ) ) { |
256 | - $frm_style->update($post_id); |
|
257 | - $message = __( 'Your styling settings have been saved.', 'formidable' ); |
|
258 | - } |
|
256 | + $frm_style->update($post_id); |
|
257 | + $message = __( 'Your styling settings have been saved.', 'formidable' ); |
|
258 | + } |
|
259 | 259 | |
260 | - return self::custom_css($message); |
|
261 | - } |
|
260 | + return self::custom_css($message); |
|
261 | + } |
|
262 | 262 | |
263 | - public static function route() { |
|
263 | + public static function route() { |
|
264 | 264 | $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' ); |
265 | 265 | |
266 | - switch ( $action ) { |
|
267 | - case 'edit': |
|
268 | - case 'save': |
|
269 | - case 'manage': |
|
270 | - case 'manage_styles': |
|
271 | - case 'custom_css': |
|
272 | - case 'save_css': |
|
266 | + switch ( $action ) { |
|
267 | + case 'edit': |
|
268 | + case 'save': |
|
269 | + case 'manage': |
|
270 | + case 'manage_styles': |
|
271 | + case 'custom_css': |
|
272 | + case 'save_css': |
|
273 | 273 | return self::$action(); |
274 | - default: |
|
275 | - do_action( 'frm_style_action_route', $action ); |
|
276 | - if ( apply_filters( 'frm_style_stop_action_route', false, $action ) ) { |
|
277 | - return; |
|
278 | - } |
|
279 | - |
|
280 | - if ( 'new_style' == $action || 'duplicate' == $action ) { |
|
281 | - return self::$action(); |
|
282 | - } |
|
283 | - |
|
284 | - return self::edit(); |
|
285 | - } |
|
286 | - } |
|
287 | - |
|
288 | - public static function reset_styling() { |
|
289 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
290 | - |
|
291 | - $frm_style = new FrmStyle(); |
|
292 | - $defaults = $frm_style->get_defaults(); |
|
293 | - |
|
294 | - echo json_encode( $defaults ); |
|
295 | - wp_die(); |
|
296 | - } |
|
297 | - |
|
298 | - public static function change_styling() { |
|
299 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
300 | - |
|
301 | - $frm_style = new FrmStyle(); |
|
302 | - $defaults = $frm_style->get_defaults(); |
|
303 | - |
|
304 | - // remove the # from the colors |
|
305 | - foreach ( $_GET['frm_style_setting']['post_content'] as $k => $v ) { |
|
306 | - if ( ! is_array($v) && strpos($v, '#') === 0 ) { |
|
307 | - $_GET['frm_style_setting']['post_content'][ $k ] = str_replace( '#', '', $v ); |
|
308 | - } |
|
309 | - } |
|
310 | - |
|
311 | - echo '<style type="text/css">'; |
|
312 | - include(FrmAppHelper::plugin_path() .'/css/_single_theme.css.php'); |
|
313 | - echo '</style>'; |
|
314 | - wp_die(); |
|
315 | - } |
|
316 | - |
|
317 | - private static function add_meta_boxes() { |
|
318 | - |
|
319 | - // setup meta boxes |
|
320 | - $meta_boxes = array( |
|
321 | - 'general' => __( 'General', 'formidable' ), |
|
322 | - 'field-labels' => __( 'Field Labels', 'formidable' ), |
|
323 | - 'field-description' => __( 'Field Description', 'formidable' ), |
|
324 | - 'field-colors' => __( 'Field Colors', 'formidable' ), |
|
325 | - 'field-sizes' => __( 'Field Settings', 'formidable' ), |
|
326 | - 'check-box-radio-fields' => __( 'Check Box & Radio Fields', 'formidable' ), |
|
327 | - 'section-fields' => __( 'Section Fields', 'formidable' ), |
|
328 | - 'date-fields' => __( 'Date Fields', 'formidable' ), |
|
329 | - 'buttons' => __( 'Buttons', 'formidable' ), |
|
330 | - 'form-messages' => __( 'Form Messages', 'formidable' ), |
|
331 | - ); |
|
332 | - |
|
333 | - foreach ( $meta_boxes as $nicename => $name ) { |
|
334 | - add_meta_box( $nicename .'-style', $name, 'FrmStylesController::include_style_section', self::$screen, 'side', 'default', $nicename ); |
|
335 | - unset($nicename, $name); |
|
336 | - } |
|
337 | - } |
|
274 | + default: |
|
275 | + do_action( 'frm_style_action_route', $action ); |
|
276 | + if ( apply_filters( 'frm_style_stop_action_route', false, $action ) ) { |
|
277 | + return; |
|
278 | + } |
|
279 | + |
|
280 | + if ( 'new_style' == $action || 'duplicate' == $action ) { |
|
281 | + return self::$action(); |
|
282 | + } |
|
283 | + |
|
284 | + return self::edit(); |
|
285 | + } |
|
286 | + } |
|
287 | + |
|
288 | + public static function reset_styling() { |
|
289 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
290 | + |
|
291 | + $frm_style = new FrmStyle(); |
|
292 | + $defaults = $frm_style->get_defaults(); |
|
293 | + |
|
294 | + echo json_encode( $defaults ); |
|
295 | + wp_die(); |
|
296 | + } |
|
297 | + |
|
298 | + public static function change_styling() { |
|
299 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
300 | + |
|
301 | + $frm_style = new FrmStyle(); |
|
302 | + $defaults = $frm_style->get_defaults(); |
|
303 | + |
|
304 | + // remove the # from the colors |
|
305 | + foreach ( $_GET['frm_style_setting']['post_content'] as $k => $v ) { |
|
306 | + if ( ! is_array($v) && strpos($v, '#') === 0 ) { |
|
307 | + $_GET['frm_style_setting']['post_content'][ $k ] = str_replace( '#', '', $v ); |
|
308 | + } |
|
309 | + } |
|
310 | + |
|
311 | + echo '<style type="text/css">'; |
|
312 | + include(FrmAppHelper::plugin_path() .'/css/_single_theme.css.php'); |
|
313 | + echo '</style>'; |
|
314 | + wp_die(); |
|
315 | + } |
|
316 | + |
|
317 | + private static function add_meta_boxes() { |
|
318 | + |
|
319 | + // setup meta boxes |
|
320 | + $meta_boxes = array( |
|
321 | + 'general' => __( 'General', 'formidable' ), |
|
322 | + 'field-labels' => __( 'Field Labels', 'formidable' ), |
|
323 | + 'field-description' => __( 'Field Description', 'formidable' ), |
|
324 | + 'field-colors' => __( 'Field Colors', 'formidable' ), |
|
325 | + 'field-sizes' => __( 'Field Settings', 'formidable' ), |
|
326 | + 'check-box-radio-fields' => __( 'Check Box & Radio Fields', 'formidable' ), |
|
327 | + 'section-fields' => __( 'Section Fields', 'formidable' ), |
|
328 | + 'date-fields' => __( 'Date Fields', 'formidable' ), |
|
329 | + 'buttons' => __( 'Buttons', 'formidable' ), |
|
330 | + 'form-messages' => __( 'Form Messages', 'formidable' ), |
|
331 | + ); |
|
332 | + |
|
333 | + foreach ( $meta_boxes as $nicename => $name ) { |
|
334 | + add_meta_box( $nicename .'-style', $name, 'FrmStylesController::include_style_section', self::$screen, 'side', 'default', $nicename ); |
|
335 | + unset($nicename, $name); |
|
336 | + } |
|
337 | + } |
|
338 | 338 | |
339 | 339 | public static function include_style_section( $atts, $sec ) { |
340 | - extract($atts); |
|
340 | + extract($atts); |
|
341 | 341 | $current_tab = FrmAppHelper::simple_get( 'page-tab', 'sanitize_title', 'default' ); |
342 | - include(FrmAppHelper::plugin_path() .'/classes/views/styles/_'. $sec['args'] .'.php'); |
|
343 | - } |
|
342 | + include(FrmAppHelper::plugin_path() .'/classes/views/styles/_'. $sec['args'] .'.php'); |
|
343 | + } |
|
344 | 344 | |
345 | - public static function load_css() { |
|
346 | - header('Content-type: text/css'); |
|
345 | + public static function load_css() { |
|
346 | + header('Content-type: text/css'); |
|
347 | 347 | |
348 | - $frm_style = new FrmStyle(); |
|
349 | - $defaults = $frm_style->get_defaults(); |
|
348 | + $frm_style = new FrmStyle(); |
|
349 | + $defaults = $frm_style->get_defaults(); |
|
350 | 350 | |
351 | - include(FrmAppHelper::plugin_path() .'/css/_single_theme.css.php'); |
|
352 | - wp_die(); |
|
353 | - } |
|
351 | + include(FrmAppHelper::plugin_path() .'/css/_single_theme.css.php'); |
|
352 | + wp_die(); |
|
353 | + } |
|
354 | 354 | |
355 | 355 | public static function load_saved_css() { |
356 | 356 | $css = get_transient( 'frmpro_css' ); |
@@ -359,142 +359,142 @@ discard block |
||
359 | 359 | wp_die(); |
360 | 360 | } |
361 | 361 | |
362 | - /** |
|
363 | - * Check if the Formidable styling should be loaded, |
|
364 | - * then enqueue it for the footer |
|
365 | - * @since 2.0 |
|
366 | - */ |
|
367 | - public static function enqueue_style() { |
|
368 | - global $frm_vars; |
|
369 | - |
|
370 | - if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) { |
|
371 | - // the CSS has already been loaded |
|
372 | - return; |
|
373 | - } |
|
374 | - |
|
375 | - $frm_settings = FrmAppHelper::get_settings(); |
|
376 | - if ( $frm_settings->load_style != 'none' ) { |
|
377 | - wp_enqueue_style( 'formidable' ); |
|
378 | - $frm_vars['css_loaded'] = true; |
|
379 | - } |
|
380 | - } |
|
381 | - |
|
382 | - // Get the stylesheets for the form settings page |
|
383 | - public static function get_style_opts() { |
|
384 | - $frm_style = new FrmStyle(); |
|
385 | - $styles = $frm_style->get_all(); |
|
386 | - |
|
387 | - return $styles; |
|
388 | - } |
|
389 | - |
|
390 | - public static function get_form_style( $form = 'default' ) { |
|
391 | - $style = FrmFormsHelper::get_form_style( $form ); |
|
392 | - |
|
393 | - if ( empty( $style ) || 1 == $style ) { |
|
394 | - $style = 'default'; |
|
395 | - } |
|
396 | - |
|
397 | - $frm_style = new FrmStyle( $style ); |
|
398 | - return $frm_style->get_one(); |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * @param string $class |
|
403 | - * @param string $style |
|
404 | - */ |
|
362 | + /** |
|
363 | + * Check if the Formidable styling should be loaded, |
|
364 | + * then enqueue it for the footer |
|
365 | + * @since 2.0 |
|
366 | + */ |
|
367 | + public static function enqueue_style() { |
|
368 | + global $frm_vars; |
|
369 | + |
|
370 | + if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) { |
|
371 | + // the CSS has already been loaded |
|
372 | + return; |
|
373 | + } |
|
374 | + |
|
375 | + $frm_settings = FrmAppHelper::get_settings(); |
|
376 | + if ( $frm_settings->load_style != 'none' ) { |
|
377 | + wp_enqueue_style( 'formidable' ); |
|
378 | + $frm_vars['css_loaded'] = true; |
|
379 | + } |
|
380 | + } |
|
381 | + |
|
382 | + // Get the stylesheets for the form settings page |
|
383 | + public static function get_style_opts() { |
|
384 | + $frm_style = new FrmStyle(); |
|
385 | + $styles = $frm_style->get_all(); |
|
386 | + |
|
387 | + return $styles; |
|
388 | + } |
|
389 | + |
|
390 | + public static function get_form_style( $form = 'default' ) { |
|
391 | + $style = FrmFormsHelper::get_form_style( $form ); |
|
392 | + |
|
393 | + if ( empty( $style ) || 1 == $style ) { |
|
394 | + $style = 'default'; |
|
395 | + } |
|
396 | + |
|
397 | + $frm_style = new FrmStyle( $style ); |
|
398 | + return $frm_style->get_one(); |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * @param string $class |
|
403 | + * @param string $style |
|
404 | + */ |
|
405 | 405 | public static function get_form_style_class( $class, $style ) { |
406 | - if ( 1 == $style ) { |
|
407 | - $style = 'default'; |
|
408 | - } |
|
406 | + if ( 1 == $style ) { |
|
407 | + $style = 'default'; |
|
408 | + } |
|
409 | 409 | |
410 | - $frm_style = new FrmStyle($style); |
|
411 | - $style = $frm_style->get_one(); |
|
410 | + $frm_style = new FrmStyle($style); |
|
411 | + $style = $frm_style->get_one(); |
|
412 | 412 | |
413 | - if ( $style ) { |
|
414 | - $class .= ' frm_style_'. $style->post_name; |
|
415 | - } |
|
413 | + if ( $style ) { |
|
414 | + $class .= ' frm_style_'. $style->post_name; |
|
415 | + } |
|
416 | 416 | |
417 | - return $class; |
|
418 | - } |
|
417 | + return $class; |
|
418 | + } |
|
419 | 419 | |
420 | - /** |
|
421 | - * @param string $val |
|
422 | - */ |
|
420 | + /** |
|
421 | + * @param string $val |
|
422 | + */ |
|
423 | 423 | public static function get_style_val( $val, $form = 'default' ) { |
424 | - $style = self::get_form_style($form); |
|
425 | - if ( $style && isset( $style->post_content[ $val ] ) ) { |
|
426 | - return $style->post_content[ $val ]; |
|
427 | - } |
|
428 | - } |
|
424 | + $style = self::get_form_style($form); |
|
425 | + if ( $style && isset( $style->post_content[ $val ] ) ) { |
|
426 | + return $style->post_content[ $val ]; |
|
427 | + } |
|
428 | + } |
|
429 | 429 | |
430 | 430 | public static function show_entry_styles( $default_styles ) { |
431 | - $frm_style = new FrmStyle('default'); |
|
432 | - $style = $frm_style->get_one(); |
|
433 | - |
|
434 | - if ( ! $style ) { |
|
435 | - return $default_styles; |
|
436 | - } |
|
437 | - |
|
438 | - foreach ( $default_styles as $name => $val ) { |
|
439 | - $setting = $name; |
|
440 | - if ( 'border_width' == $name ) { |
|
441 | - $setting = 'field_border_width'; |
|
442 | - } else if ( 'alt_bg_color' == $name ) { |
|
443 | - $setting = 'bg_color_active'; |
|
444 | - } |
|
445 | - $default_styles[ $name ] = $style->post_content[ $setting ]; |
|
446 | - unset($name, $val); |
|
447 | - } |
|
448 | - |
|
449 | - return $default_styles; |
|
450 | - } |
|
431 | + $frm_style = new FrmStyle('default'); |
|
432 | + $style = $frm_style->get_one(); |
|
433 | + |
|
434 | + if ( ! $style ) { |
|
435 | + return $default_styles; |
|
436 | + } |
|
437 | + |
|
438 | + foreach ( $default_styles as $name => $val ) { |
|
439 | + $setting = $name; |
|
440 | + if ( 'border_width' == $name ) { |
|
441 | + $setting = 'field_border_width'; |
|
442 | + } else if ( 'alt_bg_color' == $name ) { |
|
443 | + $setting = 'bg_color_active'; |
|
444 | + } |
|
445 | + $default_styles[ $name ] = $style->post_content[ $setting ]; |
|
446 | + unset($name, $val); |
|
447 | + } |
|
448 | + |
|
449 | + return $default_styles; |
|
450 | + } |
|
451 | 451 | |
452 | 452 | public static function &important_style( $important, $field ) { |
453 | - $important = self::get_style_val('important_style', $field['form_id']); |
|
454 | - return $important; |
|
455 | - } |
|
453 | + $important = self::get_style_val('important_style', $field['form_id']); |
|
454 | + return $important; |
|
455 | + } |
|
456 | 456 | |
457 | - /** |
|
458 | - * Fallback for WP < 3.6 |
|
459 | - */ |
|
460 | - public static function do_accordion_sections( $screen, $context, $object ) { |
|
461 | - if ( function_exists( 'do_accordion_sections' ) ) { |
|
462 | - return do_accordion_sections( $screen, $context, $object ); |
|
463 | - } |
|
457 | + /** |
|
458 | + * Fallback for WP < 3.6 |
|
459 | + */ |
|
460 | + public static function do_accordion_sections( $screen, $context, $object ) { |
|
461 | + if ( function_exists( 'do_accordion_sections' ) ) { |
|
462 | + return do_accordion_sections( $screen, $context, $object ); |
|
463 | + } |
|
464 | 464 | |
465 | - global $wp_meta_boxes; |
|
465 | + global $wp_meta_boxes; |
|
466 | 466 | |
467 | - $screen = 'formidable_page_formidable-styles'; |
|
468 | - $screen = convert_to_screen( $screen ); |
|
467 | + $screen = 'formidable_page_formidable-styles'; |
|
468 | + $screen = convert_to_screen( $screen ); |
|
469 | 469 | |
470 | - $page = $screen->id; |
|
470 | + $page = $screen->id; |
|
471 | 471 | |
472 | - $hidden = get_hidden_meta_boxes( $screen ); |
|
473 | - ?> |
|
472 | + $hidden = get_hidden_meta_boxes( $screen ); |
|
473 | + ?> |
|
474 | 474 | <div id="side-sortables" class="accordion-container"> |
475 | 475 | <?php |
476 | - $i = 0; |
|
477 | - $first_open = false; |
|
478 | - do { |
|
476 | + $i = 0; |
|
477 | + $first_open = false; |
|
478 | + do { |
|
479 | 479 | if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[ $page ] ) || ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) { |
480 | 480 | break; |
481 | 481 | } |
482 | 482 | |
483 | - foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { |
|
484 | - if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { |
|
485 | - foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { |
|
486 | - if ( false == $box || ! $box['title'] ) { |
|
487 | - continue; |
|
483 | + foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { |
|
484 | + if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { |
|
485 | + foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { |
|
486 | + if ( false == $box || ! $box['title'] ) { |
|
487 | + continue; |
|
488 | 488 | } |
489 | 489 | |
490 | - $i++; |
|
491 | - $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : ''; |
|
490 | + $i++; |
|
491 | + $hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : ''; |
|
492 | 492 | |
493 | - if ( ! $first_open && empty( $hidden_class ) ) { |
|
494 | - $first_open = true; |
|
495 | - } |
|
493 | + if ( ! $first_open && empty( $hidden_class ) ) { |
|
494 | + $first_open = true; |
|
495 | + } |
|
496 | 496 | |
497 | - ?> |
|
497 | + ?> |
|
498 | 498 | <div class="postbox <?php echo esc_attr( $box['id'] ); ?>"> |
499 | 499 | <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'formidable' ) ?>"><br/></div> |
500 | 500 | <h3 class='hndle'><span><?php echo esc_html( $box['title'] ); ?></span></h3> |
@@ -505,13 +505,13 @@ discard block |
||
505 | 505 | </div><!-- .accordion-section-content --> |
506 | 506 | </div><!-- .postbox --> |
507 | 507 | <?php |
508 | - } |
|
509 | - } |
|
510 | - } |
|
511 | - } while ( 0 ); |
|
512 | - ?> |
|
508 | + } |
|
509 | + } |
|
510 | + } |
|
511 | + } while ( 0 ); |
|
512 | + ?> |
|
513 | 513 | </div><!-- .accordion-container --> |
514 | 514 | <?php |
515 | - return $i; |
|
516 | - } |
|
515 | + return $i; |
|
516 | + } |
|
517 | 517 | } |
@@ -2,114 +2,114 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmXMLController { |
4 | 4 | |
5 | - public static function menu() { |
|
6 | - add_submenu_page('formidable', 'Formidable | '. __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route'); |
|
7 | - } |
|
5 | + public static function menu() { |
|
6 | + add_submenu_page('formidable', 'Formidable | '. __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route'); |
|
7 | + } |
|
8 | 8 | |
9 | - public static function add_default_templates() { |
|
9 | + public static function add_default_templates() { |
|
10 | 10 | if ( ! function_exists( 'libxml_disable_entity_loader' ) ) { |
11 | - // XML import is not enabled on your server |
|
12 | - return; |
|
13 | - } |
|
11 | + // XML import is not enabled on your server |
|
12 | + return; |
|
13 | + } |
|
14 | 14 | |
15 | - $set_err = libxml_use_internal_errors(true); |
|
16 | - $loader = libxml_disable_entity_loader( true ); |
|
15 | + $set_err = libxml_use_internal_errors(true); |
|
16 | + $loader = libxml_disable_entity_loader( true ); |
|
17 | 17 | |
18 | 18 | $files = apply_filters( 'frm_default_templates_files', array( FrmAppHelper::plugin_path() . '/classes/views/xml/default-templates.xml' ) ); |
19 | 19 | |
20 | - foreach ( (array) $files as $file ) { |
|
21 | - FrmXMLHelper::import_xml($file); |
|
22 | - unset($file); |
|
23 | - } |
|
24 | - /* |
|
20 | + foreach ( (array) $files as $file ) { |
|
21 | + FrmXMLHelper::import_xml($file); |
|
22 | + unset($file); |
|
23 | + } |
|
24 | + /* |
|
25 | 25 | if(is_wp_error($result)) |
26 | 26 | $errors[] = $result->get_error_message(); |
27 | 27 | else if($result) |
28 | 28 | $message = $result; |
29 | 29 | */ |
30 | 30 | |
31 | - unset( $files ); |
|
31 | + unset( $files ); |
|
32 | 32 | |
33 | - libxml_use_internal_errors( $set_err ); |
|
34 | - libxml_disable_entity_loader( $loader ); |
|
35 | - } |
|
33 | + libxml_use_internal_errors( $set_err ); |
|
34 | + libxml_disable_entity_loader( $loader ); |
|
35 | + } |
|
36 | 36 | |
37 | - public static function route() { |
|
38 | - $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
37 | + public static function route() { |
|
38 | + $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
39 | 39 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
40 | 40 | if ( $action == 'import_xml' ) { |
41 | - return self::import_xml(); |
|
41 | + return self::import_xml(); |
|
42 | 42 | } else if ( $action == 'export_xml' ) { |
43 | - return self::export_xml(); |
|
44 | - } else { |
|
45 | - if ( apply_filters( 'frm_xml_route', true, $action ) ) { |
|
46 | - return self::form(); |
|
47 | - } |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - public static function form( $errors = array(), $message = '' ) { |
|
52 | - $forms = FrmForm::getAll( array( 'status' => array( null, '', 'published' ) ), 'name' ); |
|
53 | - |
|
54 | - $export_types = apply_filters( 'frm_xml_export_types', |
|
55 | - array( 'forms' => __( 'Forms', 'formidable' ) ) |
|
56 | - ); |
|
57 | - |
|
58 | - $export_format = apply_filters( 'frm_export_formats', array( |
|
59 | - 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ), |
|
60 | - ) ); |
|
61 | - |
|
62 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
63 | - $frmpro_settings = new FrmProSettings(); |
|
64 | - $csv_format = $frmpro_settings->csv_format; |
|
65 | - } else { |
|
66 | - $csv_format = 'UTF-8'; |
|
67 | - } |
|
68 | - |
|
69 | - include(FrmAppHelper::plugin_path() .'/classes/views/xml/import_form.php'); |
|
70 | - } |
|
71 | - |
|
72 | - public static function import_xml() { |
|
73 | - $errors = array(); |
|
74 | - $message = ''; |
|
75 | - |
|
76 | - $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce'); |
|
77 | - if ( $permission_error !== false ) { |
|
78 | - $errors[] = $permission_error; |
|
79 | - self::form($errors); |
|
80 | - return; |
|
81 | - } |
|
82 | - |
|
83 | - if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) { |
|
84 | - $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
|
85 | - self::form($errors); |
|
86 | - return; |
|
87 | - } |
|
88 | - |
|
89 | - $file = $_FILES['frm_import_file']['tmp_name']; |
|
90 | - |
|
91 | - if ( ! is_uploaded_file( $file ) ) { |
|
92 | - unset($file); |
|
93 | - $errors[] = __( 'The file does not exist, please try again.', 'formidable' ); |
|
94 | - self::form($errors); |
|
95 | - return; |
|
96 | - } |
|
97 | - |
|
98 | - //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); |
|
99 | - |
|
100 | - $export_format = apply_filters('frm_export_formats', array( |
|
43 | + return self::export_xml(); |
|
44 | + } else { |
|
45 | + if ( apply_filters( 'frm_xml_route', true, $action ) ) { |
|
46 | + return self::form(); |
|
47 | + } |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + public static function form( $errors = array(), $message = '' ) { |
|
52 | + $forms = FrmForm::getAll( array( 'status' => array( null, '', 'published' ) ), 'name' ); |
|
53 | + |
|
54 | + $export_types = apply_filters( 'frm_xml_export_types', |
|
55 | + array( 'forms' => __( 'Forms', 'formidable' ) ) |
|
56 | + ); |
|
57 | + |
|
58 | + $export_format = apply_filters( 'frm_export_formats', array( |
|
59 | + 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ), |
|
60 | + ) ); |
|
61 | + |
|
62 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
63 | + $frmpro_settings = new FrmProSettings(); |
|
64 | + $csv_format = $frmpro_settings->csv_format; |
|
65 | + } else { |
|
66 | + $csv_format = 'UTF-8'; |
|
67 | + } |
|
68 | + |
|
69 | + include(FrmAppHelper::plugin_path() .'/classes/views/xml/import_form.php'); |
|
70 | + } |
|
71 | + |
|
72 | + public static function import_xml() { |
|
73 | + $errors = array(); |
|
74 | + $message = ''; |
|
75 | + |
|
76 | + $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce'); |
|
77 | + if ( $permission_error !== false ) { |
|
78 | + $errors[] = $permission_error; |
|
79 | + self::form($errors); |
|
80 | + return; |
|
81 | + } |
|
82 | + |
|
83 | + if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) { |
|
84 | + $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
|
85 | + self::form($errors); |
|
86 | + return; |
|
87 | + } |
|
88 | + |
|
89 | + $file = $_FILES['frm_import_file']['tmp_name']; |
|
90 | + |
|
91 | + if ( ! is_uploaded_file( $file ) ) { |
|
92 | + unset($file); |
|
93 | + $errors[] = __( 'The file does not exist, please try again.', 'formidable' ); |
|
94 | + self::form($errors); |
|
95 | + return; |
|
96 | + } |
|
97 | + |
|
98 | + //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); |
|
99 | + |
|
100 | + $export_format = apply_filters('frm_export_formats', array( |
|
101 | 101 | 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ), |
102 | 102 | ) ); |
103 | 103 | |
104 | - $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION)); |
|
105 | - if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) { |
|
106 | - // allow other file types to be imported |
|
107 | - do_action('frm_before_import_'. $file_type ); |
|
108 | - return; |
|
109 | - } |
|
110 | - unset($file_type); |
|
104 | + $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION)); |
|
105 | + if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) { |
|
106 | + // allow other file types to be imported |
|
107 | + do_action('frm_before_import_'. $file_type ); |
|
108 | + return; |
|
109 | + } |
|
110 | + unset($file_type); |
|
111 | 111 | |
112 | - //$media_id = FrmProAppHelper::upload_file('frm_import_file'); |
|
112 | + //$media_id = FrmProAppHelper::upload_file('frm_import_file'); |
|
113 | 113 | |
114 | 114 | if ( ! function_exists( 'libxml_disable_entity_loader' ) ) { |
115 | 115 | $errors[] = __( 'XML import is not enabled on your server.', 'formidable' ); |
@@ -128,158 +128,158 @@ discard block |
||
128 | 128 | libxml_use_internal_errors( $set_err ); |
129 | 129 | libxml_disable_entity_loader( $loader ); |
130 | 130 | |
131 | - self::form($errors, $message); |
|
132 | - } |
|
131 | + self::form($errors, $message); |
|
132 | + } |
|
133 | 133 | |
134 | - public static function export_xml() { |
|
135 | - $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
|
136 | - if ( ! empty($error) ) { |
|
137 | - wp_die( $error ); |
|
138 | - } |
|
134 | + public static function export_xml() { |
|
135 | + $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
|
136 | + if ( ! empty($error) ) { |
|
137 | + wp_die( $error ); |
|
138 | + } |
|
139 | 139 | |
140 | 140 | $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array() ); |
141 | 141 | $type = FrmAppHelper::get_post_param( 'type', array() ); |
142 | 142 | $format = FrmAppHelper::get_post_param( 'format', 'xml', 'sanitize_title' ); |
143 | 143 | |
144 | - if ( ! headers_sent() && ! $type ) { |
|
145 | - wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) ); |
|
146 | - die(); |
|
147 | - } |
|
144 | + if ( ! headers_sent() && ! $type ) { |
|
145 | + wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) ); |
|
146 | + die(); |
|
147 | + } |
|
148 | 148 | |
149 | - if ( $format == 'xml' ) { |
|
150 | - self::generate_xml($type, compact('ids')); |
|
151 | - } else { |
|
152 | - do_action('frm_export_format_'. $format, compact('ids')); |
|
153 | - } |
|
149 | + if ( $format == 'xml' ) { |
|
150 | + self::generate_xml($type, compact('ids')); |
|
151 | + } else { |
|
152 | + do_action('frm_export_format_'. $format, compact('ids')); |
|
153 | + } |
|
154 | 154 | |
155 | - wp_die(); |
|
156 | - } |
|
155 | + wp_die(); |
|
156 | + } |
|
157 | 157 | |
158 | 158 | public static function generate_xml( $type, $args = array() ) { |
159 | - global $wpdb; |
|
160 | - |
|
161 | - $type = (array) $type; |
|
162 | - if ( in_array( 'items', $type) && ! in_array( 'forms', $type) ) { |
|
163 | - // make sure the form is included if there are entries |
|
164 | - $type[] = 'forms'; |
|
165 | - } |
|
166 | - |
|
167 | - if ( in_array( 'forms', $type) ) { |
|
168 | - // include actions with forms |
|
169 | - $type[] = 'actions'; |
|
170 | - } |
|
171 | - |
|
172 | - $tables = array( |
|
173 | - 'items' => $wpdb->prefix .'frm_items', |
|
174 | - 'forms' => $wpdb->prefix .'frm_forms', |
|
175 | - 'posts' => $wpdb->posts, |
|
176 | - 'styles' => $wpdb->posts, |
|
177 | - 'actions' => $wpdb->posts, |
|
178 | - ); |
|
159 | + global $wpdb; |
|
160 | + |
|
161 | + $type = (array) $type; |
|
162 | + if ( in_array( 'items', $type) && ! in_array( 'forms', $type) ) { |
|
163 | + // make sure the form is included if there are entries |
|
164 | + $type[] = 'forms'; |
|
165 | + } |
|
166 | + |
|
167 | + if ( in_array( 'forms', $type) ) { |
|
168 | + // include actions with forms |
|
169 | + $type[] = 'actions'; |
|
170 | + } |
|
171 | + |
|
172 | + $tables = array( |
|
173 | + 'items' => $wpdb->prefix .'frm_items', |
|
174 | + 'forms' => $wpdb->prefix .'frm_forms', |
|
175 | + 'posts' => $wpdb->posts, |
|
176 | + 'styles' => $wpdb->posts, |
|
177 | + 'actions' => $wpdb->posts, |
|
178 | + ); |
|
179 | 179 | |
180 | 180 | $defaults = array( 'ids' => false ); |
181 | - $args = wp_parse_args( $args, $defaults ); |
|
181 | + $args = wp_parse_args( $args, $defaults ); |
|
182 | 182 | |
183 | - $sitename = sanitize_key( get_bloginfo( 'name' ) ); |
|
183 | + $sitename = sanitize_key( get_bloginfo( 'name' ) ); |
|
184 | 184 | |
185 | - if ( ! empty( $sitename ) ) { |
|
185 | + if ( ! empty( $sitename ) ) { |
|
186 | 186 | $sitename .= '.'; |
187 | 187 | } |
188 | - $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml'; |
|
188 | + $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml'; |
|
189 | 189 | |
190 | - header( 'Content-Description: File Transfer' ); |
|
191 | - header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
192 | - header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
|
190 | + header( 'Content-Description: File Transfer' ); |
|
191 | + header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
192 | + header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
|
193 | 193 | |
194 | - //make sure ids are numeric |
|
195 | - if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) { |
|
196 | - $args['ids'] = array_filter( $args['ids'], 'is_numeric' ); |
|
197 | - } |
|
194 | + //make sure ids are numeric |
|
195 | + if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) { |
|
196 | + $args['ids'] = array_filter( $args['ids'], 'is_numeric' ); |
|
197 | + } |
|
198 | 198 | |
199 | - $records = array(); |
|
199 | + $records = array(); |
|
200 | 200 | |
201 | 201 | foreach ( $type as $tb_type ) { |
202 | - $where = array(); |
|
202 | + $where = array(); |
|
203 | 203 | $join = ''; |
204 | - $table = $tables[ $tb_type ]; |
|
204 | + $table = $tables[ $tb_type ]; |
|
205 | 205 | |
206 | - $select = $table .'.id'; |
|
207 | - $query_vars = array(); |
|
206 | + $select = $table .'.id'; |
|
207 | + $query_vars = array(); |
|
208 | 208 | |
209 | - switch ( $tb_type ) { |
|
210 | - case 'forms': |
|
211 | - //add forms |
|
212 | - if ( $args['ids'] ) { |
|
209 | + switch ( $tb_type ) { |
|
210 | + case 'forms': |
|
211 | + //add forms |
|
212 | + if ( $args['ids'] ) { |
|
213 | 213 | $where[] = array( 'or' => 1, $table . '.id' => $args['ids'], $table .'.parent_form_id' => $args['ids'] ); |
214 | - } else { |
|
214 | + } else { |
|
215 | 215 | $where[ $table . '.status !' ] = 'draft'; |
216 | - } |
|
217 | - break; |
|
218 | - case 'actions': |
|
219 | - $select = $table .'.ID'; |
|
216 | + } |
|
217 | + break; |
|
218 | + case 'actions': |
|
219 | + $select = $table .'.ID'; |
|
220 | 220 | $where['post_type'] = FrmFormActionsController::$action_post_type; |
221 | - if ( ! empty($args['ids']) ) { |
|
221 | + if ( ! empty($args['ids']) ) { |
|
222 | 222 | $where['menu_order'] = $args['ids']; |
223 | - } |
|
224 | - break; |
|
225 | - case 'items': |
|
226 | - //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)"; |
|
227 | - if ( $args['ids'] ) { |
|
223 | + } |
|
224 | + break; |
|
225 | + case 'items': |
|
226 | + //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)"; |
|
227 | + if ( $args['ids'] ) { |
|
228 | 228 | $where[ $table . '.form_id' ] = $args['ids']; |
229 | - } |
|
230 | - break; |
|
231 | - case 'styles': |
|
232 | - // Loop through all exported forms and get their selected style IDs |
|
233 | - $form_ids = $args['ids']; |
|
234 | - $style_ids = array(); |
|
235 | - foreach ( $form_ids as $form_id ) { |
|
236 | - $form_data = FrmForm::getOne( $form_id ); |
|
237 | - // For forms that have not been updated while running 2.0, check if custom_style is set |
|
238 | - if ( isset( $form_data->options['custom_style'] ) ) { |
|
239 | - $style_ids[] = $form_data->options['custom_style']; |
|
240 | - } |
|
241 | - unset( $form_id, $form_data ); |
|
242 | - } |
|
243 | - $select = $table .'.ID'; |
|
244 | - $where['post_type'] = 'frm_styles'; |
|
245 | - |
|
246 | - // Only export selected styles |
|
247 | - if ( ! empty( $style_ids ) ) { |
|
248 | - $where['ID'] = $style_ids; |
|
249 | - } |
|
250 | - break; |
|
251 | - default: |
|
252 | - $select = $table .'.ID'; |
|
253 | - $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)'; |
|
254 | - $where['pm.meta_key'] = 'frm_form_id'; |
|
255 | - |
|
256 | - if ( empty($args['ids']) ) { |
|
257 | - $where['pm.meta_value >'] = 1; |
|
258 | - } else { |
|
259 | - $where['pm.meta_value'] = $args['ids']; |
|
260 | - } |
|
261 | - break; |
|
262 | - } |
|
229 | + } |
|
230 | + break; |
|
231 | + case 'styles': |
|
232 | + // Loop through all exported forms and get their selected style IDs |
|
233 | + $form_ids = $args['ids']; |
|
234 | + $style_ids = array(); |
|
235 | + foreach ( $form_ids as $form_id ) { |
|
236 | + $form_data = FrmForm::getOne( $form_id ); |
|
237 | + // For forms that have not been updated while running 2.0, check if custom_style is set |
|
238 | + if ( isset( $form_data->options['custom_style'] ) ) { |
|
239 | + $style_ids[] = $form_data->options['custom_style']; |
|
240 | + } |
|
241 | + unset( $form_id, $form_data ); |
|
242 | + } |
|
243 | + $select = $table .'.ID'; |
|
244 | + $where['post_type'] = 'frm_styles'; |
|
245 | + |
|
246 | + // Only export selected styles |
|
247 | + if ( ! empty( $style_ids ) ) { |
|
248 | + $where['ID'] = $style_ids; |
|
249 | + } |
|
250 | + break; |
|
251 | + default: |
|
252 | + $select = $table .'.ID'; |
|
253 | + $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)'; |
|
254 | + $where['pm.meta_key'] = 'frm_form_id'; |
|
255 | + |
|
256 | + if ( empty($args['ids']) ) { |
|
257 | + $where['pm.meta_value >'] = 1; |
|
258 | + } else { |
|
259 | + $where['pm.meta_value'] = $args['ids']; |
|
260 | + } |
|
261 | + break; |
|
262 | + } |
|
263 | 263 | |
264 | 264 | $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select ); |
265 | - unset($tb_type); |
|
266 | - } |
|
265 | + unset($tb_type); |
|
266 | + } |
|
267 | 267 | |
268 | 268 | echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo('charset') ) . "\" ?>\n"; |
269 | - include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php'); |
|
270 | - } |
|
269 | + include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php'); |
|
270 | + } |
|
271 | 271 | |
272 | 272 | public static function allow_mime( $mimes ) { |
273 | - if ( ! isset( $mimes['csv'] ) ) { |
|
274 | - // allow csv files |
|
275 | - $mimes['csv'] = 'text/csv'; |
|
276 | - } |
|
277 | - |
|
278 | - if ( ! isset( $mimes['xml'] ) ) { |
|
279 | - // allow xml |
|
280 | - $mimes['xml'] = 'text/xml'; |
|
281 | - } |
|
282 | - |
|
283 | - return $mimes; |
|
284 | - } |
|
273 | + if ( ! isset( $mimes['csv'] ) ) { |
|
274 | + // allow csv files |
|
275 | + $mimes['csv'] = 'text/csv'; |
|
276 | + } |
|
277 | + |
|
278 | + if ( ! isset( $mimes['xml'] ) ) { |
|
279 | + // allow xml |
|
280 | + $mimes['xml'] = 'text/xml'; |
|
281 | + } |
|
282 | + |
|
283 | + return $mimes; |
|
284 | + } |
|
285 | 285 | } |
@@ -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 | } |
@@ -5,68 +5,68 @@ discard block |
||
5 | 5 | |
6 | 6 | class FrmEntriesHelper { |
7 | 7 | |
8 | - public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
|
9 | - global $frm_vars; |
|
10 | - $values = array(); |
|
8 | + public static function setup_new_vars( $fields, $form = '', $reset = false, $args = array() ) { |
|
9 | + global $frm_vars; |
|
10 | + $values = array(); |
|
11 | 11 | foreach ( array( 'name' => '', 'description' => '', 'item_key' => '' ) as $var => $default ) { |
12 | - $values[ $var ] = FrmAppHelper::get_post_param( $var, $default ); |
|
13 | - } |
|
14 | - |
|
15 | - $values['fields'] = array(); |
|
16 | - if ( empty($fields) ) { |
|
17 | - return apply_filters('frm_setup_new_entry', $values); |
|
18 | - } |
|
19 | - |
|
20 | - foreach ( (array) $fields as $field ) { |
|
21 | - $new_value = self::get_field_value_for_new_entry( $field, $reset ); |
|
22 | - |
|
23 | - $field_array = array( |
|
24 | - 'id' => $field->id, |
|
25 | - 'value' => $new_value, |
|
26 | - 'default_value' => $field->default_value, |
|
27 | - 'name' => $field->name, |
|
28 | - 'description' => $field->description, |
|
29 | - 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
30 | - 'options' => $field->options, |
|
31 | - 'required' => $field->required, |
|
32 | - 'field_key' => $field->field_key, |
|
33 | - 'field_order' => $field->field_order, |
|
34 | - 'form_id' => $field->form_id, |
|
12 | + $values[ $var ] = FrmAppHelper::get_post_param( $var, $default ); |
|
13 | + } |
|
14 | + |
|
15 | + $values['fields'] = array(); |
|
16 | + if ( empty($fields) ) { |
|
17 | + return apply_filters('frm_setup_new_entry', $values); |
|
18 | + } |
|
19 | + |
|
20 | + foreach ( (array) $fields as $field ) { |
|
21 | + $new_value = self::get_field_value_for_new_entry( $field, $reset ); |
|
22 | + |
|
23 | + $field_array = array( |
|
24 | + 'id' => $field->id, |
|
25 | + 'value' => $new_value, |
|
26 | + 'default_value' => $field->default_value, |
|
27 | + 'name' => $field->name, |
|
28 | + 'description' => $field->description, |
|
29 | + 'type' => apply_filters('frm_field_type', $field->type, $field, $new_value), |
|
30 | + 'options' => $field->options, |
|
31 | + 'required' => $field->required, |
|
32 | + 'field_key' => $field->field_key, |
|
33 | + 'field_order' => $field->field_order, |
|
34 | + 'form_id' => $field->form_id, |
|
35 | 35 | 'parent_form_id' => isset( $args['parent_form_id'] ) ? $args['parent_form_id'] : $field->form_id, |
36 | - ); |
|
36 | + ); |
|
37 | 37 | |
38 | - $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
39 | - $opt_defaults['required_indicator'] = ''; |
|
38 | + $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); |
|
39 | + $opt_defaults['required_indicator'] = ''; |
|
40 | 40 | $opt_defaults['original_type'] = $field->type; |
41 | 41 | |
42 | 42 | foreach ( $opt_defaults as $opt => $default_opt ) { |
43 | - $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
44 | - unset($opt, $default_opt); |
|
45 | - } |
|
43 | + $field_array[ $opt ] = ( isset( $field->field_options[ $opt ] ) && $field->field_options[ $opt ] != '' ) ? $field->field_options[ $opt ] : $default_opt; |
|
44 | + unset($opt, $default_opt); |
|
45 | + } |
|
46 | 46 | |
47 | - unset($opt_defaults); |
|
47 | + unset($opt_defaults); |
|
48 | 48 | |
49 | - if ( $field_array['custom_html'] == '' ) { |
|
50 | - $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
51 | - } |
|
49 | + if ( $field_array['custom_html'] == '' ) { |
|
50 | + $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field->type); |
|
51 | + } |
|
52 | 52 | |
53 | - $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field); |
|
54 | - $field_array = array_merge( $field->field_options, $field_array ); |
|
53 | + $field_array = apply_filters('frm_setup_new_fields_vars', $field_array, $field); |
|
54 | + $field_array = array_merge( $field->field_options, $field_array ); |
|
55 | 55 | |
56 | - $values['fields'][] = $field_array; |
|
56 | + $values['fields'][] = $field_array; |
|
57 | 57 | |
58 | - if ( ! $form || ! isset($form->id) ) { |
|
59 | - $form = FrmForm::getOne($field->form_id); |
|
60 | - } |
|
61 | - } |
|
58 | + if ( ! $form || ! isset($form->id) ) { |
|
59 | + $form = FrmForm::getOne($field->form_id); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | |
63 | - $form->options = maybe_unserialize($form->options); |
|
64 | - if ( is_array($form->options) ) { |
|
65 | - foreach ( $form->options as $opt => $value ) { |
|
66 | - $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
67 | - unset($opt, $value); |
|
68 | - } |
|
69 | - } |
|
63 | + $form->options = maybe_unserialize($form->options); |
|
64 | + if ( is_array($form->options) ) { |
|
65 | + foreach ( $form->options as $opt => $value ) { |
|
66 | + $values[ $opt ] = FrmAppHelper::get_post_param( $opt, $value ); |
|
67 | + unset($opt, $value); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | |
71 | 71 | $form_defaults = FrmFormsHelper::get_default_opts(); |
72 | 72 | |
@@ -76,18 +76,18 @@ discard block |
||
76 | 76 | $values = array_merge( $form_defaults, $values ); |
77 | 77 | |
78 | 78 | return apply_filters( 'frm_setup_new_entry', $values ); |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | 81 | /** |
82 | - * Set the value for each field |
|
83 | - * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
84 | - * |
|
85 | - * @since 2.0.13 |
|
86 | - * |
|
87 | - * @param object $field - this is passed by reference since it is an object |
|
88 | - * @param boolean $reset |
|
89 | - * @return string|array $new_value |
|
90 | - */ |
|
82 | + * Set the value for each field |
|
83 | + * This function is used when the form is first loaded and on all page turns *for a new entry* |
|
84 | + * |
|
85 | + * @since 2.0.13 |
|
86 | + * |
|
87 | + * @param object $field - this is passed by reference since it is an object |
|
88 | + * @param boolean $reset |
|
89 | + * @return string|array $new_value |
|
90 | + */ |
|
91 | 91 | private static function get_field_value_for_new_entry( $field, $reset ) { |
92 | 92 | //If checkbox, multi-select dropdown, or checkbox data from entries field, the value should be an array |
93 | 93 | $return_array = FrmField::is_field_with_multiple_values( $field ); |
@@ -118,15 +118,15 @@ discard block |
||
118 | 118 | |
119 | 119 | public static function setup_edit_vars( $values, $record ) { |
120 | 120 | $values['item_key'] = FrmAppHelper::get_post_param( 'item_key', $record->item_key, 'sanitize_title' ); |
121 | - $values['form_id'] = $record->form_id; |
|
122 | - $values['is_draft'] = $record->is_draft; |
|
123 | - return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
124 | - } |
|
121 | + $values['form_id'] = $record->form_id; |
|
122 | + $values['is_draft'] = $record->is_draft; |
|
123 | + return apply_filters('frm_setup_edit_entry_vars', $values, $record); |
|
124 | + } |
|
125 | 125 | |
126 | - public static function get_admin_params( $form = null ) { |
|
126 | + public static function get_admin_params( $form = null ) { |
|
127 | 127 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_admin_params' ); |
128 | 128 | return FrmForm::set_current_form( $form ); |
129 | - } |
|
129 | + } |
|
130 | 130 | |
131 | 131 | public static function set_current_form( $form_id ) { |
132 | 132 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::set_current_form' ); |
@@ -138,280 +138,280 @@ discard block |
||
138 | 138 | return FrmForm::get_current_form( $form_id ); |
139 | 139 | } |
140 | 140 | |
141 | - public static function get_current_form_id() { |
|
141 | + public static function get_current_form_id() { |
|
142 | 142 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmForm::get_current_form_id' ); |
143 | 143 | return FrmForm::get_current_form_id(); |
144 | - } |
|
144 | + } |
|
145 | 145 | |
146 | - public static function maybe_get_entry( &$entry ) { |
|
146 | + public static function maybe_get_entry( &$entry ) { |
|
147 | 147 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntry::maybe_get_entry' ); |
148 | 148 | FrmEntry::maybe_get_entry( $entry ); |
149 | - } |
|
149 | + } |
|
150 | 150 | |
151 | 151 | public static function replace_default_message( $message, $atts ) { |
152 | - if ( strpos($message, '[default-message') === false && |
|
153 | - strpos($message, '[default_message') === false && |
|
154 | - ! empty( $message ) ) { |
|
155 | - return $message; |
|
156 | - } |
|
157 | - |
|
158 | - if ( empty($message) ) { |
|
159 | - $message = '[default-message]'; |
|
160 | - } |
|
161 | - |
|
162 | - preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
163 | - |
|
164 | - foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
165 | - $add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
166 | - if ( $add_atts ) { |
|
167 | - $this_atts = array_merge($atts, $add_atts); |
|
168 | - } else { |
|
169 | - $this_atts = $atts; |
|
170 | - } |
|
152 | + if ( strpos($message, '[default-message') === false && |
|
153 | + strpos($message, '[default_message') === false && |
|
154 | + ! empty( $message ) ) { |
|
155 | + return $message; |
|
156 | + } |
|
157 | + |
|
158 | + if ( empty($message) ) { |
|
159 | + $message = '[default-message]'; |
|
160 | + } |
|
161 | + |
|
162 | + preg_match_all("/\[(default-message|default_message)\b(.*?)(?:(\/))?\]/s", $message, $shortcodes, PREG_PATTERN_ORDER); |
|
163 | + |
|
164 | + foreach ( $shortcodes[0] as $short_key => $tag ) { |
|
165 | + $add_atts = shortcode_parse_atts( $shortcodes[2][ $short_key ] ); |
|
166 | + if ( $add_atts ) { |
|
167 | + $this_atts = array_merge($atts, $add_atts); |
|
168 | + } else { |
|
169 | + $this_atts = $atts; |
|
170 | + } |
|
171 | 171 | |
172 | 172 | $default = FrmEntryFormat::show_entry( $this_atts ); |
173 | 173 | |
174 | - // Add the default message |
|
175 | - $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
176 | - } |
|
174 | + // Add the default message |
|
175 | + $message = str_replace( $shortcodes[0][ $short_key ], $default, $message ); |
|
176 | + } |
|
177 | 177 | |
178 | - return $message; |
|
179 | - } |
|
178 | + return $message; |
|
179 | + } |
|
180 | 180 | |
181 | 181 | public static function prepare_display_value( $entry, $field, $atts ) { |
182 | 182 | $field_value = isset( $entry->metas[ $field->id ] ) ? $entry->metas[ $field->id ] : false; |
183 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
183 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
184 | 184 | FrmProEntriesHelper::get_dynamic_list_values( $field, $entry, $field_value ); |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | - if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
188 | - return self::display_value($field_value, $field, $atts); |
|
189 | - } |
|
187 | + if ( $field->form_id == $entry->form_id || empty($atts['embedded_field_id']) ) { |
|
188 | + return self::display_value($field_value, $field, $atts); |
|
189 | + } |
|
190 | 190 | |
191 | - // this is an embeded form |
|
192 | - $val = ''; |
|
191 | + // this is an embeded form |
|
192 | + $val = ''; |
|
193 | 193 | |
194 | - if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
195 | - //this is a repeating section |
|
194 | + if ( strpos($atts['embedded_field_id'], 'form') === 0 ) { |
|
195 | + //this is a repeating section |
|
196 | 196 | $child_entries = FrmEntry::getAll( array( 'it.parent_item_id' => $entry->id ) ); |
197 | - } else { |
|
198 | - // get all values for this field |
|
199 | - $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
197 | + } else { |
|
198 | + // get all values for this field |
|
199 | + $child_values = isset( $entry->metas[ $atts['embedded_field_id'] ] ) ? $entry->metas[ $atts['embedded_field_id'] ] : false; |
|
200 | 200 | |
201 | - if ( $child_values ) { |
|
202 | - $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
203 | - } |
|
204 | - } |
|
201 | + if ( $child_values ) { |
|
202 | + $child_entries = FrmEntry::getAll( array( 'it.id' => (array) $child_values ) ); |
|
203 | + } |
|
204 | + } |
|
205 | 205 | |
206 | - $field_value = array(); |
|
206 | + $field_value = array(); |
|
207 | 207 | |
208 | - if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
209 | - return $val; |
|
210 | - } |
|
208 | + if ( ! isset($child_entries) || ! $child_entries || ! FrmAppHelper::pro_is_installed() ) { |
|
209 | + return $val; |
|
210 | + } |
|
211 | 211 | |
212 | - foreach ( $child_entries as $child_entry ) { |
|
213 | - $atts['item_id'] = $child_entry->id; |
|
214 | - $atts['post_id'] = $child_entry->post_id; |
|
212 | + foreach ( $child_entries as $child_entry ) { |
|
213 | + $atts['item_id'] = $child_entry->id; |
|
214 | + $atts['post_id'] = $child_entry->post_id; |
|
215 | 215 | |
216 | - // get the value for this field -- check for post values as well |
|
217 | - $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
216 | + // get the value for this field -- check for post values as well |
|
217 | + $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field); |
|
218 | 218 | |
219 | - if ( $entry_val ) { |
|
220 | - // foreach entry get display_value |
|
221 | - $field_value[] = self::display_value($entry_val, $field, $atts); |
|
222 | - } |
|
219 | + if ( $entry_val ) { |
|
220 | + // foreach entry get display_value |
|
221 | + $field_value[] = self::display_value($entry_val, $field, $atts); |
|
222 | + } |
|
223 | 223 | |
224 | - unset($child_entry); |
|
225 | - } |
|
224 | + unset($child_entry); |
|
225 | + } |
|
226 | 226 | |
227 | - $val = implode(', ', (array) $field_value ); |
|
227 | + $val = implode(', ', (array) $field_value ); |
|
228 | 228 | $val = wp_kses_post( $val ); |
229 | 229 | |
230 | - return $val; |
|
231 | - } |
|
230 | + return $val; |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * Prepare the saved value for display |
|
235 | - * @return string |
|
236 | - */ |
|
233 | + /** |
|
234 | + * Prepare the saved value for display |
|
235 | + * @return string |
|
236 | + */ |
|
237 | 237 | public static function display_value( $value, $field, $atts = array() ) { |
238 | 238 | |
239 | - $defaults = array( |
|
240 | - 'type' => '', 'html' => false, 'show_filename' => true, |
|
241 | - 'truncate' => false, 'sep' => ', ', 'post_id' => 0, |
|
242 | - 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0, |
|
239 | + $defaults = array( |
|
240 | + 'type' => '', 'html' => false, 'show_filename' => true, |
|
241 | + 'truncate' => false, 'sep' => ', ', 'post_id' => 0, |
|
242 | + 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0, |
|
243 | 243 | 'return_array' => false, |
244 | - ); |
|
244 | + ); |
|
245 | 245 | |
246 | - $atts = wp_parse_args( $atts, $defaults ); |
|
247 | - $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
246 | + $atts = wp_parse_args( $atts, $defaults ); |
|
247 | + $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); |
|
248 | 248 | |
249 | - if ( ! isset($field->field_options['post_field']) ) { |
|
250 | - $field->field_options['post_field'] = ''; |
|
251 | - } |
|
249 | + if ( ! isset($field->field_options['post_field']) ) { |
|
250 | + $field->field_options['post_field'] = ''; |
|
251 | + } |
|
252 | 252 | |
253 | - if ( ! isset($field->field_options['custom_field']) ) { |
|
254 | - $field->field_options['custom_field'] = ''; |
|
255 | - } |
|
253 | + if ( ! isset($field->field_options['custom_field']) ) { |
|
254 | + $field->field_options['custom_field'] = ''; |
|
255 | + } |
|
256 | 256 | |
257 | - if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
|
258 | - $atts['pre_truncate'] = $atts['truncate']; |
|
259 | - $atts['truncate'] = true; |
|
260 | - $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
257 | + if ( FrmAppHelper::pro_is_installed() && $atts['post_id'] && ( $field->field_options['post_field'] || $atts['type'] == 'tag' ) ) { |
|
258 | + $atts['pre_truncate'] = $atts['truncate']; |
|
259 | + $atts['truncate'] = true; |
|
260 | + $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; |
|
261 | 261 | |
262 | - $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
263 | - $atts['truncate'] = $atts['pre_truncate']; |
|
264 | - } |
|
262 | + $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); |
|
263 | + $atts['truncate'] = $atts['pre_truncate']; |
|
264 | + } |
|
265 | 265 | |
266 | - if ( $value == '' ) { |
|
267 | - return $value; |
|
268 | - } |
|
266 | + if ( $value == '' ) { |
|
267 | + return $value; |
|
268 | + } |
|
269 | 269 | |
270 | - $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts); |
|
270 | + $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts); |
|
271 | 271 | |
272 | - $new_value = ''; |
|
272 | + $new_value = ''; |
|
273 | 273 | |
274 | - if ( is_array($value) && $atts['type'] != 'file' ) { |
|
275 | - foreach ( $value as $val ) { |
|
276 | - if ( is_array($val) ) { |
|
274 | + if ( is_array($value) && $atts['type'] != 'file' ) { |
|
275 | + foreach ( $value as $val ) { |
|
276 | + if ( is_array($val) ) { |
|
277 | 277 | //TODO: add options for display (li or ,) |
278 | - $new_value .= implode($atts['sep'], $val); |
|
279 | - if ( $atts['type'] != 'data' ) { |
|
280 | - $new_value .= '<br/>'; |
|
281 | - } |
|
282 | - } |
|
283 | - unset($val); |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - if ( ! empty($new_value) ) { |
|
288 | - $value = $new_value; |
|
289 | - } else if ( is_array($value) && $atts['type'] != 'file' && ! $atts['return_array'] ) { |
|
290 | - $value = implode($atts['sep'], $value); |
|
291 | - } |
|
292 | - |
|
293 | - if ( $atts['truncate'] && $atts['type'] != 'image' ) { |
|
294 | - $value = FrmAppHelper::truncate($value, 50); |
|
295 | - } |
|
278 | + $new_value .= implode($atts['sep'], $val); |
|
279 | + if ( $atts['type'] != 'data' ) { |
|
280 | + $new_value .= '<br/>'; |
|
281 | + } |
|
282 | + } |
|
283 | + unset($val); |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + if ( ! empty($new_value) ) { |
|
288 | + $value = $new_value; |
|
289 | + } else if ( is_array($value) && $atts['type'] != 'file' && ! $atts['return_array'] ) { |
|
290 | + $value = implode($atts['sep'], $value); |
|
291 | + } |
|
292 | + |
|
293 | + if ( $atts['truncate'] && $atts['type'] != 'image' ) { |
|
294 | + $value = FrmAppHelper::truncate($value, 50); |
|
295 | + } |
|
296 | 296 | |
297 | 297 | if ( ! $atts['keepjs'] && ! is_array( $value ) ) { |
298 | 298 | $value = wp_kses_post( $value ); |
299 | 299 | } |
300 | 300 | |
301 | - return apply_filters('frm_display_value', $value, $field, $atts); |
|
302 | - } |
|
301 | + return apply_filters('frm_display_value', $value, $field, $atts); |
|
302 | + } |
|
303 | 303 | |
304 | 304 | public static function set_posted_value( $field, $value, $args ) { |
305 | - // If validating a field with "other" opt, set back to prev value now |
|
306 | - if ( isset( $args['other'] ) && $args['other'] ) { |
|
307 | - $value = $args['temp_value']; |
|
308 | - } |
|
309 | - if ( empty($args['parent_field_id']) ) { |
|
310 | - $_POST['item_meta'][ $field->id ] = $value; |
|
311 | - } else { |
|
312 | - $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
313 | - } |
|
314 | - } |
|
305 | + // If validating a field with "other" opt, set back to prev value now |
|
306 | + if ( isset( $args['other'] ) && $args['other'] ) { |
|
307 | + $value = $args['temp_value']; |
|
308 | + } |
|
309 | + if ( empty($args['parent_field_id']) ) { |
|
310 | + $_POST['item_meta'][ $field->id ] = $value; |
|
311 | + } else { |
|
312 | + $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field->id ] = $value; |
|
313 | + } |
|
314 | + } |
|
315 | 315 | |
316 | 316 | public static function get_posted_value( $field, &$value, $args ) { |
317 | 317 | $field_id = is_object( $field ) ? $field->id : $field; |
318 | 318 | |
319 | - if ( empty($args['parent_field_id']) ) { |
|
320 | - $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
321 | - } else { |
|
322 | - $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : ''; |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Check if field has an "Other" option and if any other values are posted |
|
328 | - * |
|
329 | - * @since 2.0 |
|
330 | - * |
|
331 | - * @param object $field |
|
332 | - * @param string|array $value |
|
333 | - * @param array $args |
|
334 | - */ |
|
335 | - public static function maybe_set_other_validation( $field, &$value, &$args ) { |
|
336 | - $args['other'] = false; |
|
337 | - if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) { |
|
338 | - return; |
|
339 | - } |
|
340 | - |
|
341 | - // Get other value for fields in repeating section |
|
342 | - self::set_other_repeating_vals( $field, $value, $args ); |
|
343 | - |
|
344 | - // Check if there are any posted "Other" values |
|
319 | + if ( empty($args['parent_field_id']) ) { |
|
320 | + $value = isset( $_POST['item_meta'][ $field_id ] ) ? $_POST['item_meta'][ $field_id ] : ''; |
|
321 | + } else { |
|
322 | + $value = isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] ) ? $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ][ $field_id ] : ''; |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Check if field has an "Other" option and if any other values are posted |
|
328 | + * |
|
329 | + * @since 2.0 |
|
330 | + * |
|
331 | + * @param object $field |
|
332 | + * @param string|array $value |
|
333 | + * @param array $args |
|
334 | + */ |
|
335 | + public static function maybe_set_other_validation( $field, &$value, &$args ) { |
|
336 | + $args['other'] = false; |
|
337 | + if ( ! $value || empty( $value ) || ! FrmAppHelper::pro_is_installed() ) { |
|
338 | + return; |
|
339 | + } |
|
340 | + |
|
341 | + // Get other value for fields in repeating section |
|
342 | + self::set_other_repeating_vals( $field, $value, $args ); |
|
343 | + |
|
344 | + // Check if there are any posted "Other" values |
|
345 | 345 | if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta']['other'][ $field->id ] ) ) { |
346 | 346 | |
347 | - // Save original value |
|
348 | - $args['temp_value'] = $value; |
|
349 | - $args['other'] = true; |
|
350 | - $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
351 | - |
|
352 | - // Set the validation value now |
|
353 | - self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
354 | - } |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
|
359 | - * |
|
360 | - * @since 2.0 |
|
361 | - * |
|
362 | - * @param object $field |
|
363 | - * @param string|array $value |
|
364 | - * @param array $args |
|
365 | - */ |
|
366 | - public static function set_other_repeating_vals( $field, &$value, &$args ) { |
|
367 | - if ( ! $args['parent_field_id'] ) { |
|
368 | - return; |
|
369 | - } |
|
370 | - |
|
371 | - // Check if there are any other posted "other" values for this field |
|
347 | + // Save original value |
|
348 | + $args['temp_value'] = $value; |
|
349 | + $args['other'] = true; |
|
350 | + $other_vals = stripslashes_deep( $_POST['item_meta']['other'][ $field->id ] ); |
|
351 | + |
|
352 | + // Set the validation value now |
|
353 | + self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
354 | + } |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Sets radio or checkbox value equal to "other" value if it is set - FOR REPEATING SECTIONS |
|
359 | + * |
|
360 | + * @since 2.0 |
|
361 | + * |
|
362 | + * @param object $field |
|
363 | + * @param string|array $value |
|
364 | + * @param array $args |
|
365 | + */ |
|
366 | + public static function set_other_repeating_vals( $field, &$value, &$args ) { |
|
367 | + if ( ! $args['parent_field_id'] ) { |
|
368 | + return; |
|
369 | + } |
|
370 | + |
|
371 | + // Check if there are any other posted "other" values for this field |
|
372 | 372 | if ( FrmField::is_option_true( $field, 'other' ) && isset( $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ] ) ) { |
373 | - // Save original value |
|
374 | - $args['temp_value'] = $value; |
|
375 | - $args['other'] = true; |
|
376 | - |
|
377 | - $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
378 | - |
|
379 | - // Set the validation value now |
|
380 | - self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
381 | - } |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Modify value used for validation |
|
386 | - * This function essentially removes the "Other" radio or checkbox value from the $value being validated. |
|
387 | - * It also adds any text from the free text fields to the value |
|
388 | - * |
|
389 | - * Needs to accommodate for times when other opt is selected, but no other free text is entered |
|
390 | - * |
|
391 | - * @since 2.0 |
|
392 | - * |
|
393 | - * @param string|array $value |
|
394 | - * @param string|array $other_vals (usually of posted values) |
|
395 | - * @param object $field |
|
396 | - * @param array $args |
|
397 | - */ |
|
398 | - public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
|
399 | - // Checkboxes and multi-select dropdowns |
|
400 | - if ( is_array( $value ) && $field->type == 'checkbox' ) { |
|
401 | - // Combine "Other" values with checked values. "Other" values will override checked box values. |
|
402 | - $value = array_merge( $value, $other_vals ); |
|
403 | - $value = array_filter( $value ); |
|
404 | - if ( count( $value ) == 0 ) { |
|
405 | - $value = ''; |
|
406 | - } |
|
407 | - } else { |
|
373 | + // Save original value |
|
374 | + $args['temp_value'] = $value; |
|
375 | + $args['other'] = true; |
|
376 | + |
|
377 | + $other_vals = $_POST['item_meta'][ $args['parent_field_id'] ][ $args['key_pointer'] ]['other'][ $field->id ]; |
|
378 | + |
|
379 | + // Set the validation value now |
|
380 | + self::set_other_validation_val( $value, $other_vals, $field, $args ); |
|
381 | + } |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Modify value used for validation |
|
386 | + * This function essentially removes the "Other" radio or checkbox value from the $value being validated. |
|
387 | + * It also adds any text from the free text fields to the value |
|
388 | + * |
|
389 | + * Needs to accommodate for times when other opt is selected, but no other free text is entered |
|
390 | + * |
|
391 | + * @since 2.0 |
|
392 | + * |
|
393 | + * @param string|array $value |
|
394 | + * @param string|array $other_vals (usually of posted values) |
|
395 | + * @param object $field |
|
396 | + * @param array $args |
|
397 | + */ |
|
398 | + public static function set_other_validation_val( &$value, $other_vals, $field, &$args ) { |
|
399 | + // Checkboxes and multi-select dropdowns |
|
400 | + if ( is_array( $value ) && $field->type == 'checkbox' ) { |
|
401 | + // Combine "Other" values with checked values. "Other" values will override checked box values. |
|
402 | + $value = array_merge( $value, $other_vals ); |
|
403 | + $value = array_filter( $value ); |
|
404 | + if ( count( $value ) == 0 ) { |
|
405 | + $value = ''; |
|
406 | + } |
|
407 | + } else { |
|
408 | 408 | // Radio and dropdowns |
409 | - $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
410 | - $other_key = reset( $other_key ); |
|
409 | + $other_key = array_filter( array_keys($field->options), 'is_string'); |
|
410 | + $other_key = reset( $other_key ); |
|
411 | 411 | |
412 | - // Multi-select dropdown |
|
413 | - if ( is_array( $value ) ) { |
|
414 | - $o_key = array_search( $field->options[ $other_key ], $value ); |
|
412 | + // Multi-select dropdown |
|
413 | + if ( is_array( $value ) ) { |
|
414 | + $o_key = array_search( $field->options[ $other_key ], $value ); |
|
415 | 415 | |
416 | 416 | if ( $o_key !== false ) { |
417 | 417 | // Modify the original value so other key will be preserved |
@@ -426,20 +426,20 @@ discard block |
||
426 | 426 | $args['temp_value'] = $value; |
427 | 427 | $value[ $other_key ] = reset( $other_vals ); |
428 | 428 | } |
429 | - } else if ( $field->options[ $other_key ] == $value ) { |
|
430 | - $value = $other_vals; |
|
431 | - } |
|
432 | - } |
|
433 | - } |
|
429 | + } else if ( $field->options[ $other_key ] == $value ) { |
|
430 | + $value = $other_vals; |
|
431 | + } |
|
432 | + } |
|
433 | + } |
|
434 | 434 | |
435 | 435 | public static function enqueue_scripts( $params ) { |
436 | 436 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmFormsController::enqueue_scripts' ); |
437 | 437 | return FrmFormsController::enqueue_scripts( $params ); |
438 | 438 | } |
439 | 439 | |
440 | - // Add submitted values to a string for spam checking |
|
440 | + // Add submitted values to a string for spam checking |
|
441 | 441 | public static function entry_array_to_string( $values ) { |
442 | - $content = ''; |
|
442 | + $content = ''; |
|
443 | 443 | foreach ( $values['item_meta'] as $val ) { |
444 | 444 | if ( $content != '' ) { |
445 | 445 | $content .= "\n\n"; |
@@ -447,14 +447,14 @@ discard block |
||
447 | 447 | |
448 | 448 | if ( is_array($val) ) { |
449 | 449 | $val = FrmAppHelper::array_flatten( $val ); |
450 | - $val = implode(',', $val); |
|
450 | + $val = implode(',', $val); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | $content .= $val; |
454 | 454 | } |
455 | 455 | |
456 | 456 | return $content; |
457 | - } |
|
457 | + } |
|
458 | 458 | |
459 | 459 | public static function fill_entry_values( $atts, $f, array &$values ) { |
460 | 460 | _deprecated_function( __FUNCTION__, '2.0.9', 'FrmEntryFormat::fill_entry_values' ); |