Completed
Push — master ( 26f6ca...2f9e3c )
by Stephanie
02:54
created
classes/controllers/FrmStylesController.php 1 patch
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 class FrmStylesController {
4
-    public static $post_type = 'frm_styles';
5
-    public static $screen = 'formidable_page_formidable-styles';
4
+	public static $post_type = 'frm_styles';
5
+	public static $screen = 'formidable_page_formidable-styles';
6 6
 
7
-    public static function load_pro_hooks() {
8
-        if ( FrmAppHelper::pro_is_installed() ) {
9
-            FrmProStylesController::load_pro_hooks();
10
-        }
11
-    }
7
+	public static function load_pro_hooks() {
8
+		if ( FrmAppHelper::pro_is_installed() ) {
9
+			FrmProStylesController::load_pro_hooks();
10
+		}
11
+	}
12 12
 
13
-    public static function register_post_types() {
13
+	public static function register_post_types() {
14 14
 		register_post_type(
15 15
 			self::$post_type,
16 16
 			array(
@@ -41,18 +41,18 @@  discard block
 block discarded – undo
41 41
 				),
42 42
 			)
43 43
 		);
44
-    }
44
+	}
45 45
 
46
-    public static function menu() {
46
+	public static function menu() {
47 47
 		add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' );
48
-    }
48
+	}
49 49
 
50 50
 	public static function admin_init() {
51 51
 		if ( ! FrmAppHelper::is_admin_page( 'formidable-styles' ) ) {
52 52
 			return;
53 53
 		}
54 54
 
55
-        self::load_pro_hooks();
55
+		self::load_pro_hooks();
56 56
 
57 57
 		$style_tab = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
58 58
 		if ( $style_tab == 'manage' || $style_tab == 'custom_css' ) {
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 		wp_enqueue_style( 'frm-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_css' ), array(), $version );
67 67
 
68 68
 		$style = apply_filters( 'frm_style_head', false );
69
-        if ( $style ) {
69
+		if ( $style ) {
70 70
 			wp_enqueue_style( 'frm-single-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_load_css&flat=1' ) . '&' . http_build_query( $style->post_content ), array(), $version );
71
-        }
72
-    }
71
+		}
72
+	}
73 73
 
74 74
 	/**
75 75
 	 * @param string $register Either 'enqueue' or 'register'.
@@ -225,10 +225,10 @@  discard block
 block discarded – undo
225 225
 	}
226 226
 
227 227
 	public static function load_styler( $style, $message = '' ) {
228
-        global $frm_settings;
228
+		global $frm_settings;
229 229
 
230
-        $frm_style = new FrmStyle();
231
-        $styles = $frm_style->get_all();
230
+		$frm_style = new FrmStyle();
231
+		$styles = $frm_style->get_all();
232 232
 
233 233
 		if ( is_numeric( $style ) ) {
234 234
 			$style = $styles[ $style ];
@@ -236,10 +236,10 @@  discard block
 block discarded – undo
236 236
 			$style = $frm_style->get_default_style( $styles );
237 237
 		}
238 238
 
239
-        self::add_meta_boxes();
239
+		self::add_meta_boxes();
240 240
 
241 241
 		include( FrmAppHelper::plugin_path() . '/classes/views/styles/show.php' );
242
-    }
242
+	}
243 243
 
244 244
 	/**
245 245
 	 * @param string $message
@@ -257,31 +257,31 @@  discard block
 block discarded – undo
257 257
 		include( FrmAppHelper::plugin_path() . '/classes/views/styles/manage.php' );
258 258
 	}
259 259
 
260
-    private static function manage_styles() {
260
+	private static function manage_styles() {
261 261
 		$style_nonce = FrmAppHelper::get_post_param( 'frm_manage_style', '', 'sanitize_text_field' );
262 262
 		if ( ! $_POST || ! isset( $_POST['style'] ) || ! wp_verify_nonce( $style_nonce, 'frm_manage_style_nonce' ) ) {
263
-            return self::manage();
264
-        }
263
+			return self::manage();
264
+		}
265 265
 
266
-        global $wpdb;
266
+		global $wpdb;
267 267
 
268 268
 		$forms = FrmForm::get_published_forms();
269
-        foreach ( $forms as $form ) {
270
-            if ( $_POST['style'][ $form->id ] == $_POST['prev_style'][ $form->id ] ) {
271
-                continue;
272
-            }
269
+		foreach ( $forms as $form ) {
270
+			if ( $_POST['style'][ $form->id ] == $_POST['prev_style'][ $form->id ] ) {
271
+				continue;
272
+			}
273 273
 
274
-            $form->options['custom_style'] = $_POST['style'][ $form->id ];
274
+			$form->options['custom_style'] = $_POST['style'][ $form->id ];
275 275
 
276 276
 			$wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
277 277
 			unset( $form );
278
-        }
278
+		}
279 279
 
280
-        $message = __( 'Your form styles have been saved.', 'formidable' );
280
+		$message = __( 'Your form styles have been saved.', 'formidable' );
281 281
 		return self::manage( $message, $forms );
282
-    }
282
+	}
283 283
 
284
-    public static function custom_css( $message = '', $style = null ) {
284
+	public static function custom_css( $message = '', $style = null ) {
285 285
 		if ( function_exists( 'wp_enqueue_code_editor' ) ) {
286 286
 			$id = 'frm_codemirror_box';
287 287
 			$settings = wp_enqueue_code_editor(
@@ -324,41 +324,41 @@  discard block
 block discarded – undo
324 324
 		return self::custom_css( $message );
325 325
 	}
326 326
 
327
-    public static function route() {
327
+	public static function route() {
328 328
 		$action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
329 329
 
330
-        switch ( $action ) {
331
-            case 'edit':
332
-            case 'save':
333
-            case 'manage':
334
-            case 'manage_styles':
335
-            case 'custom_css':
336
-            case 'save_css':
330
+		switch ( $action ) {
331
+			case 'edit':
332
+			case 'save':
333
+			case 'manage':
334
+			case 'manage_styles':
335
+			case 'custom_css':
336
+			case 'save_css':
337 337
 				return self::$action();
338
-            default:
339
-            	do_action( 'frm_style_action_route', $action );
340
-            	if ( apply_filters( 'frm_style_stop_action_route', false, $action ) ) {
341
-                	return;
342
-            	}
338
+			default:
339
+				do_action( 'frm_style_action_route', $action );
340
+				if ( apply_filters( 'frm_style_stop_action_route', false, $action ) ) {
341
+					return;
342
+				}
343 343
 
344
-                if ( 'new_style' == $action || 'duplicate' == $action ) {
345
-                    return self::$action();
346
-                }
344
+				if ( 'new_style' == $action || 'duplicate' == $action ) {
345
+					return self::$action();
346
+				}
347 347
 
348
-                return self::edit();
349
-        }
350
-    }
348
+				return self::edit();
349
+		}
350
+	}
351 351
 
352
-    public static function reset_styling() {
352
+	public static function reset_styling() {
353 353
 		FrmAppHelper::permission_check( 'frm_change_settings' );
354
-        check_ajax_referer( 'frm_ajax', 'nonce' );
354
+		check_ajax_referer( 'frm_ajax', 'nonce' );
355 355
 
356
-        $frm_style = new FrmStyle();
357
-        $defaults = $frm_style->get_defaults();
356
+		$frm_style = new FrmStyle();
357
+		$defaults = $frm_style->get_defaults();
358 358
 
359
-        echo json_encode( $defaults );
360
-        wp_die();
361
-    }
359
+		echo json_encode( $defaults );
360
+		wp_die();
361
+	}
362 362
 
363 363
 	public static function change_styling() {
364 364
 		check_ajax_referer( 'frm_ajax', 'nonce' );
@@ -373,21 +373,21 @@  discard block
 block discarded – undo
373 373
 		wp_die();
374 374
 	}
375 375
 
376
-    private static function add_meta_boxes() {
377
-
378
-        // setup meta boxes
379
-        $meta_boxes = array(
380
-            'general'           => __( 'General', 'formidable' ),
381
-            'form-title'        => __( 'Form Title', 'formidable' ),
382
-            'form-description'  => __( 'Form Description', 'formidable' ),
383
-            'field-labels'      => __( 'Field Labels', 'formidable' ),
384
-            'field-description' => __( 'Field Description', 'formidable' ),
385
-            'field-colors'      => __( 'Field Colors', 'formidable' ),
386
-            'field-sizes'       => __( 'Field Settings', 'formidable' ),
387
-            'check-box-radio-fields' => __( 'Check Box & Radio Fields', 'formidable' ),
388
-            'buttons'           => __( 'Buttons', 'formidable' ),
389
-            'form-messages'     => __( 'Form Messages', 'formidable' ),
390
-        );
376
+	private static function add_meta_boxes() {
377
+
378
+		// setup meta boxes
379
+		$meta_boxes = array(
380
+			'general'           => __( 'General', 'formidable' ),
381
+			'form-title'        => __( 'Form Title', 'formidable' ),
382
+			'form-description'  => __( 'Form Description', 'formidable' ),
383
+			'field-labels'      => __( 'Field Labels', 'formidable' ),
384
+			'field-description' => __( 'Field Description', 'formidable' ),
385
+			'field-colors'      => __( 'Field Colors', 'formidable' ),
386
+			'field-sizes'       => __( 'Field Settings', 'formidable' ),
387
+			'check-box-radio-fields' => __( 'Check Box & Radio Fields', 'formidable' ),
388
+			'buttons'           => __( 'Buttons', 'formidable' ),
389
+			'form-messages'     => __( 'Form Messages', 'formidable' ),
390
+		);
391 391
 
392 392
 		/**
393 393
 		 * Add custom boxes to the styling settings
@@ -420,18 +420,18 @@  discard block
 block discarded – undo
420 420
 		$file_name = apply_filters( 'frm_style_settings_' . $sec['args'], $file_name );
421 421
 
422 422
 		include( $file_name );
423
-    }
423
+	}
424 424
 
425
-    public static function load_css() {
425
+	public static function load_css() {
426 426
 		header( 'Content-type: text/css' );
427 427
 
428
-        $frm_style = new FrmStyle();
429
-        $defaults = $frm_style->get_defaults();
428
+		$frm_style = new FrmStyle();
429
+		$defaults = $frm_style->get_defaults();
430 430
 		$style = '';
431 431
 
432 432
 		include( FrmAppHelper::plugin_path() . '/css/_single_theme.css.php' );
433
-        wp_die();
434
-    }
433
+		wp_die();
434
+	}
435 435
 
436 436
 	public static function load_saved_css() {
437 437
 		$css = get_transient( 'frmpro_css' );
@@ -440,50 +440,50 @@  discard block
 block discarded – undo
440 440
 		wp_die();
441 441
 	}
442 442
 
443
-    /**
444
-     * Check if the Formidable styling should be loaded,
445
-     * then enqueue it for the footer
443
+	/**
444
+	 * Check if the Formidable styling should be loaded,
445
+	 * then enqueue it for the footer
446 446
 	 *
447
-     * @since 2.0
448
-     */
449
-    public static function enqueue_style() {
450
-        global $frm_vars;
451
-
452
-        if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
453
-            // the CSS has already been loaded
454
-            return;
455
-        }
456
-
457
-        $frm_settings = FrmAppHelper::get_settings();
458
-        if ( $frm_settings->load_style != 'none' ) {
459
-            wp_enqueue_style( 'formidable' );
460
-            $frm_vars['css_loaded'] = true;
461
-        }
462
-    }
463
-
464
-    // Get the stylesheets for the form settings page
465
-    public static function get_style_opts() {
466
-        $frm_style = new FrmStyle();
467
-        $styles = $frm_style->get_all();
468
-
469
-        return $styles;
470
-    }
471
-
472
-    public static function get_form_style( $form = 'default' ) {
473
-        $style = FrmFormsHelper::get_form_style( $form );
474
-
475
-        if ( empty( $style ) || 1 == $style ) {
476
-            $style = 'default';
477
-        }
478
-
479
-        $frm_style = new FrmStyle( $style );
480
-        return $frm_style->get_one();
481
-    }
482
-
483
-    /**
484
-     * @param string $class
485
-     * @param string $style
486
-     */
447
+	 * @since 2.0
448
+	 */
449
+	public static function enqueue_style() {
450
+		global $frm_vars;
451
+
452
+		if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
453
+			// the CSS has already been loaded
454
+			return;
455
+		}
456
+
457
+		$frm_settings = FrmAppHelper::get_settings();
458
+		if ( $frm_settings->load_style != 'none' ) {
459
+			wp_enqueue_style( 'formidable' );
460
+			$frm_vars['css_loaded'] = true;
461
+		}
462
+	}
463
+
464
+	// Get the stylesheets for the form settings page
465
+	public static function get_style_opts() {
466
+		$frm_style = new FrmStyle();
467
+		$styles = $frm_style->get_all();
468
+
469
+		return $styles;
470
+	}
471
+
472
+	public static function get_form_style( $form = 'default' ) {
473
+		$style = FrmFormsHelper::get_form_style( $form );
474
+
475
+		if ( empty( $style ) || 1 == $style ) {
476
+			$style = 'default';
477
+		}
478
+
479
+		$frm_style = new FrmStyle( $style );
480
+		return $frm_style->get_one();
481
+	}
482
+
483
+	/**
484
+	 * @param string $class
485
+	 * @param string $style
486
+	 */
487 487
 	public static function get_form_style_class( $class, $style ) {
488 488
 		if ( 1 == $style ) {
489 489
 			$style = 'default';
@@ -513,9 +513,9 @@  discard block
 block discarded – undo
513 513
 		}
514 514
 	}
515 515
 
516
-    /**
517
-     * @param string $val
518
-     */
516
+	/**
517
+	 * @param string $val
518
+	 */
519 519
 	public static function get_style_val( $val, $form = 'default' ) {
520 520
 		$style = self::get_form_style( $form );
521 521
 		if ( $style && isset( $style->post_content[ $val ] ) ) {
@@ -525,72 +525,72 @@  discard block
 block discarded – undo
525 525
 
526 526
 	public static function show_entry_styles( $default_styles ) {
527 527
 		$frm_style = new FrmStyle( 'default' );
528
-        $style = $frm_style->get_one();
529
-
530
-        if ( ! $style ) {
531
-            return $default_styles;
532
-        }
533
-
534
-        foreach ( $default_styles as $name => $val ) {
535
-            $setting = $name;
536
-            if ( 'border_width' == $name ) {
537
-                $setting = 'field_border_width';
538
-            } else if ( 'alt_bg_color' == $name ) {
539
-                $setting = 'bg_color_active';
540
-            }
541
-            $default_styles[ $name ] = $style->post_content[ $setting ];
528
+		$style = $frm_style->get_one();
529
+
530
+		if ( ! $style ) {
531
+			return $default_styles;
532
+		}
533
+
534
+		foreach ( $default_styles as $name => $val ) {
535
+			$setting = $name;
536
+			if ( 'border_width' == $name ) {
537
+				$setting = 'field_border_width';
538
+			} else if ( 'alt_bg_color' == $name ) {
539
+				$setting = 'bg_color_active';
540
+			}
541
+			$default_styles[ $name ] = $style->post_content[ $setting ];
542 542
 			unset( $name, $val );
543
-        }
543
+		}
544 544
 
545
-        return $default_styles;
546
-    }
545
+		return $default_styles;
546
+	}
547 547
 
548 548
 	public static function &important_style( $important, $field ) {
549 549
 		$important = self::get_style_val( 'important_style', $field['form_id'] );
550
-        return $important;
551
-    }
550
+		return $important;
551
+	}
552 552
 
553
-    /**
554
-     * Fallback for WP < 3.6
555
-     */
556
-    public static function do_accordion_sections( $screen, $context, $object ) {
557
-        if ( function_exists( 'do_accordion_sections' ) ) {
558
-            return do_accordion_sections( $screen, $context, $object );
559
-        }
553
+	/**
554
+	 * Fallback for WP < 3.6
555
+	 */
556
+	public static function do_accordion_sections( $screen, $context, $object ) {
557
+		if ( function_exists( 'do_accordion_sections' ) ) {
558
+			return do_accordion_sections( $screen, $context, $object );
559
+		}
560 560
 
561
-    	global $wp_meta_boxes;
561
+		global $wp_meta_boxes;
562 562
 
563
-        $screen = 'formidable_page_formidable-styles';
564
-        $screen = convert_to_screen( $screen );
563
+		$screen = 'formidable_page_formidable-styles';
564
+		$screen = convert_to_screen( $screen );
565 565
 
566
-    	$page = $screen->id;
566
+		$page = $screen->id;
567 567
 
568
-    	$hidden = get_hidden_meta_boxes( $screen );
569
-    	?>
568
+		$hidden = get_hidden_meta_boxes( $screen );
569
+		?>
570 570
     	<div id="side-sortables" class="accordion-container">
571 571
     	<?php
572
-    	$i = 0;
573
-    	$first_open = false;
574
-    	do {
572
+		$i = 0;
573
+		$first_open = false;
574
+		do {
575 575
 			if ( ! isset( $wp_meta_boxes ) || ! isset( $wp_meta_boxes[ $page ] ) || ! isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
576 576
 				break;
577 577
 			}
578 578
 
579
-    		foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
580
-    			if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
581
-    				foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
582
-    					if ( false == $box || ! $box['title'] ) {
583
-    						continue;
579
+			foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
580
+				if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
581
+					foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
582
+						if ( false == $box || ! $box['title'] ) {
583
+							continue;
584 584
 						}
585 585
 
586
-    					$i++;
587
-    					$hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
586
+						$i++;
587
+						$hidden_class = in_array( $box['id'], $hidden ) ? 'hide-if-js' : '';
588 588
 
589
-    					if ( ! $first_open && empty( $hidden_class ) ) {
590
-    						$first_open = true;
591
-    					}
589
+						if ( ! $first_open && empty( $hidden_class ) ) {
590
+							$first_open = true;
591
+						}
592 592
 
593
-    					?>
593
+						?>
594 594
 						<div class="postbox <?php echo esc_attr( $box['id'] ); ?>">
595 595
 						<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'formidable' ); ?>"><br/></div>
596 596
                         <h3 class='hndle'><span><?php echo esc_html( $box['title'] ); ?></span></h3>
@@ -601,13 +601,13 @@  discard block
 block discarded – undo
601 601
     						</div><!-- .accordion-section-content -->
602 602
     					</div><!-- .postbox -->
603 603
     					<?php
604
-    				}
605
-    			}
606
-    		}
607
-    	} while ( 0 );
608
-    	?>
604
+					}
605
+				}
606
+			}
607
+		} while ( 0 );
608
+		?>
609 609
     	</div><!-- .accordion-container -->
610 610
     	<?php
611
-    	return $i;
612
-    }
611
+		return $i;
612
+	}
613 613
 }
Please login to merge, or discard this patch.