Completed
Push — master ( 6ad657...b09366 )
by Jamie
03:00
created
classes/models/FrmStyle.php 1 patch
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 class FrmStyle {
3
-    public $number = false;	// Unique ID number of the current instance.
3
+    public $number = false; // Unique ID number of the current instance.
4 4
 	public $id = 0; // the id of the post
5 5
 
6 6
 	/**
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 
16 16
         $max_slug_value = 2147483647;
17 17
         $min_slug_value = 37; // we want to have at least 2 characters in the slug
18
-        $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
18
+        $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
19 19
 
20 20
         $style = array(
21 21
             'post_type'     => FrmStylesController::$post_type,
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
     public function update( $id = 'default' ) {
42 42
  		$all_instances = $this->get_all();
43 43
 
44
- 		if ( empty($id) ) {
44
+ 		if ( empty( $id ) ) {
45 45
  		     $new_style = (array) $this->get_new();
46 46
  		     $all_instances[] = $new_style;
47 47
  		}
@@ -49,15 +49,15 @@  discard block
 block discarded – undo
49 49
         $action_ids = array();
50 50
 
51 51
  		foreach ( $all_instances as $number => $new_instance ) {
52
- 			$new_instance = stripslashes_deep( (array) $new_instance);
52
+ 			$new_instance = stripslashes_deep( (array) $new_instance );
53 53
  			$this->id = $new_instance['ID'];
54
- 			if ( $id != $this->id || ! $_POST || ! isset($_POST['frm_style_setting']) ) {
55
-				$all_instances[ $number ] = $new_instance;
54
+ 			if ( $id != $this->id || ! $_POST || ! isset( $_POST['frm_style_setting'] ) ) {
55
+				$all_instances[$number] = $new_instance;
56 56
 
57
- 			    if ( $new_instance['menu_order'] && $_POST && empty($_POST['prev_menu_order']) && isset($_POST['frm_style_setting']['menu_order']) ) {
57
+ 			    if ( $new_instance['menu_order'] && $_POST && empty( $_POST['prev_menu_order'] ) && isset( $_POST['frm_style_setting']['menu_order'] ) ) {
58 58
  			        // this style was set to default, so remove default setting on previous default style
59 59
  			        $new_instance['menu_order'] = 0;
60
- 			        $action_ids[] = $this->save($new_instance);
60
+ 			        $action_ids[] = $this->save( $new_instance );
61 61
  			    }
62 62
 
63 63
  			    // don't continue if not saving this style
@@ -67,33 +67,33 @@  discard block
 block discarded – undo
67 67
  			$new_instance['post_title'] = sanitize_text_field( $_POST['frm_style_setting']['post_title'] );
68 68
  			$new_instance['post_content'] = $_POST['frm_style_setting']['post_content'];
69 69
  			$new_instance['post_type']  = FrmStylesController::$post_type;
70
-            $new_instance['post_status']  = 'publish';
70
+            $new_instance['post_status'] = 'publish';
71 71
 			$new_instance['menu_order']  = isset( $_POST['frm_style_setting']['menu_order'] ) ? absint( $_POST['frm_style_setting']['menu_order'] ) : 0;
72 72
 
73
-            if ( empty($id) ) {
73
+            if ( empty( $id ) ) {
74 74
                 $new_instance['post_name'] = $new_instance['post_title'];
75 75
             }
76 76
 
77 77
             $default_settings = $this->get_defaults();
78 78
 
79 79
             foreach ( $default_settings as $setting => $default ) {
80
-				if ( ! isset( $new_instance['post_content'][ $setting ] ) ) {
81
-					$new_instance['post_content'][ $setting ] = $default;
80
+				if ( ! isset( $new_instance['post_content'][$setting] ) ) {
81
+					$new_instance['post_content'][$setting] = $default;
82 82
 				}
83 83
 
84 84
 				if ( strpos( $setting, 'color' ) !== false || in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ) ) ) {
85 85
                     //if is a color
86
-					$new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] );
87
-				} else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) {
88
-					$new_instance['post_content'][ $setting ] = 0;
86
+					$new_instance['post_content'][$setting] = str_replace( '#', '', $new_instance['post_content'][$setting] );
87
+				} else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][$setting] ) ) {
88
+					$new_instance['post_content'][$setting] = 0;
89 89
                 } else if ( $setting == 'font' ) {
90
-                	$new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
90
+                	$new_instance['post_content'][$setting] = $this->force_balanced_quotation( $new_instance['post_content'][$setting] );
91 91
                 }
92 92
             }
93 93
 
94
-			$all_instances[ $number ] = $new_instance;
94
+			$all_instances[$number] = $new_instance;
95 95
 
96
-            $action_ids[] = $this->save($new_instance);
96
+            $action_ids[] = $this->save( $new_instance );
97 97
 
98 98
  		}
99 99
 
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
      */
108 108
 	public function save_settings() {
109 109
 		$filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php';
110
-		update_option( 'frm_last_style_update', date('njGi') );
110
+		update_option( 'frm_last_style_update', date( 'njGi' ) );
111 111
 
112
-        if ( ! is_file($filename) ) {
112
+        if ( ! is_file( $filename ) ) {
113 113
             return;
114 114
         }
115 115
 
@@ -120,9 +120,9 @@  discard block
 block discarded – undo
120 120
 		$create_file = new FrmCreateFile( array( 'folder_name' => 'formidable/css', 'file_name' => 'formidablepro.css' ) );
121 121
 		$create_file->create_file( $css );
122 122
 
123
-        update_option('frmpro_css', $css);
123
+        update_option( 'frmpro_css', $css );
124 124
 
125
-        set_transient('frmpro_css', $css);
125
+        set_transient( 'frmpro_css', $css );
126 126
 	}
127 127
 
128 128
 	private function get_css_content( $filename ) {
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	}
155 155
 
156 156
 	public function destroy( $id ) {
157
-        return wp_delete_post($id);
157
+        return wp_delete_post( $id );
158 158
     }
159 159
 
160 160
     public function get_one() {
@@ -168,19 +168,19 @@  discard block
 block discarded – undo
168 168
             return $style;
169 169
         }
170 170
 
171
-        $style = get_post($this->id);
171
+        $style = get_post( $this->id );
172 172
 
173 173
         if ( ! $style ) {
174 174
             return $style;
175 175
         }
176 176
 
177
-        $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
177
+        $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
178 178
 
179 179
         $default_values = $this->get_defaults();
180 180
 
181 181
         // fill default values
182
-        $style->post_content = $this->override_defaults($style->post_content);
183
-        $style->post_content = wp_parse_args( $style->post_content, $default_values);
182
+        $style->post_content = $this->override_defaults( $style->post_content );
183
+        $style->post_content = wp_parse_args( $style->post_content, $default_values );
184 184
 
185 185
         return $style;
186 186
     }
@@ -194,22 +194,22 @@  discard block
 block discarded – undo
194 194
 			'order'       => $order,
195 195
         );
196 196
 
197
-        $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts');
197
+        $temp_styles = FrmAppHelper::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
198 198
 
199
-        if ( empty($temp_styles) ) {
199
+        if ( empty( $temp_styles ) ) {
200 200
             global $wpdb;
201 201
             // make sure there wasn't a conflict with the query
202 202
 			$query = $wpdb->prepare( 'SELECT * FROM ' . $wpdb->posts . ' WHERE post_type=%s AND post_status=%s ORDER BY post_title ASC LIMIT 99', FrmStylesController::$post_type, 'publish' );
203
-            $temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results');
203
+            $temp_styles = FrmAppHelper::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
204 204
 
205
-            if ( empty($temp_styles) ) {
205
+            if ( empty( $temp_styles ) ) {
206 206
                 // create a new style if there are none
207 207
          		$new = $this->get_new();
208 208
 				$new->post_title = __( 'Formidable Style', 'formidable' );
209 209
 				$new->post_name = $new->post_title;
210 210
          		$new->menu_order = 1;
211
-         		$new = $this->save( (array) $new);
212
-         		$this->update('default');
211
+         		$new = $this->save( (array) $new );
212
+         		$this->update( 'default' );
213 213
 
214 214
                 $post_atts['include'] = $new;
215 215
 
@@ -233,25 +233,25 @@  discard block
 block discarded – undo
233 233
                 }
234 234
             }
235 235
 
236
-            $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
236
+            $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
237 237
 
238 238
             // fill default values
239
-            $style->post_content = $this->override_defaults($style->post_content);
240
-            $style->post_content = wp_parse_args( $style->post_content, $default_values);
239
+            $style->post_content = $this->override_defaults( $style->post_content );
240
+            $style->post_content = wp_parse_args( $style->post_content, $default_values );
241 241
 
242
-			$styles[ $style->ID ] = $style;
242
+			$styles[$style->ID] = $style;
243 243
         }
244 244
 
245 245
         if ( ! $default_style ) {
246
-            $default_style = reset($styles);
247
-			$styles[ $default_style->ID ]->menu_order = 1;
246
+            $default_style = reset( $styles );
247
+			$styles[$default_style->ID]->menu_order = 1;
248 248
         }
249 249
 
250 250
         return $styles;
251 251
     }
252 252
 
253 253
 	public function get_default_style( $styles = null ) {
254
-        if ( ! isset($styles) ) {
254
+        if ( ! isset( $styles ) ) {
255 255
 			$styles = $this->get_all( 'menu_order', 'DESC', 1 );
256 256
         }
257 257
 
@@ -263,24 +263,24 @@  discard block
 block discarded – undo
263 263
     }
264 264
 
265 265
 	public function override_defaults( $settings ) {
266
-	    if ( ! is_array($settings) ) {
266
+	    if ( ! is_array( $settings ) ) {
267 267
 	        return $settings;
268 268
 	    }
269 269
 
270
-	    $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height'];
270
+	    $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height'];
271 271
 
272
-	    if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) {
272
+	    if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
273 273
 	        $settings['form_desc_size'] = $settings['description_font_size'];
274 274
 	        $settings['form_desc_color'] = $settings['description_color'];
275 275
 	        $settings['title_color'] = $settings['label_color'];
276 276
 	    }
277 277
 
278
-	    if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) {
278
+	    if ( ! isset( $settings['section_color'] ) && isset( $settings['label_color'] ) ) {
279 279
 	        $settings['section_color'] = $settings['label_color'];
280 280
 	        $settings['section_border_color'] = $settings['border_color'];
281 281
 	    }
282 282
 
283
-	    if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) {
283
+	    if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) {
284 284
 	        $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
285 285
 	        $settings['submit_hover_color'] = $settings['submit_text_color'];
286 286
 	        $settings['submit_hover_border_color'] = $settings['submit_border_color'];
Please login to merge, or discard this patch.