Completed
Push — master ( 5d7055...b13940 )
by Stephanie
04:18
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
 	/**
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
     public function get_new() {
14 14
 		$this->id = 0;
15 15
 
16
-        $max_slug_value = pow(36, 6);
16
+        $max_slug_value = pow( 36, 6 );
17 17
         $min_slug_value = 37; // we want to have at least 2 characters in the slug
18
-        $key = base_convert( rand($min_slug_value, $max_slug_value), 10, 36 );
18
+        $key = base_convert( rand( $min_slug_value, $max_slug_value ), 10, 36 );
19 19
 
20 20
         $style = array(
21 21
             'post_type'     => FrmStylesController::$post_type,
@@ -41,7 +41,7 @@  discard block
 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,10 +67,10 @@  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
 
@@ -79,17 +79,17 @@  discard block
 block discarded – undo
79 79
             foreach ( $default_settings as $setting => $default ) {
80 80
 				if ( strpos( $setting, 'color' ) !== false || in_array( $setting, array( 'error_bg', 'error_border', 'error_text' ) ) ) {
81 81
                     //if is a color
82
-					$new_instance['post_content'][ $setting ] = str_replace( '#', '', $new_instance['post_content'][ $setting ] );
83
-				} else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][ $setting ] ) ) {
84
-					$new_instance['post_content'][ $setting ] = 0;
82
+					$new_instance['post_content'][$setting] = str_replace( '#', '', $new_instance['post_content'][$setting] );
83
+				} else if ( in_array( $setting, array( 'submit_style', 'important_style', 'auto_width' ) ) && ! isset( $new_instance['post_content'][$setting] ) ) {
84
+					$new_instance['post_content'][$setting] = 0;
85 85
                 } else if ( $setting == 'font' ) {
86
-                	$new_instance['post_content'][ $setting ] = $this->force_balanced_quotation( $new_instance['post_content'][ $setting ] );
86
+                	$new_instance['post_content'][$setting] = $this->force_balanced_quotation( $new_instance['post_content'][$setting] );
87 87
                 }
88 88
             }
89 89
 
90
-			$all_instances[ $number ] = $new_instance;
90
+			$all_instances[$number] = $new_instance;
91 91
 
92
-            $action_ids[] = $this->save($new_instance);
92
+            $action_ids[] = $this->save( $new_instance );
93 93
 
94 94
  		}
95 95
 
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
      */
104 104
 	public function save_settings() {
105 105
 		$filename = FrmAppHelper::plugin_path() . '/css/custom_theme.css.php';
106
-		update_option( 'frm_last_style_update', date('njGi') );
106
+		update_option( 'frm_last_style_update', date( 'njGi' ) );
107 107
 
108
-        if ( ! is_file($filename) ) {
108
+        if ( ! is_file( $filename ) ) {
109 109
             return;
110 110
         }
111 111
 
@@ -114,10 +114,10 @@  discard block
 block discarded – undo
114 114
 		$create_file = new FrmCreateFile( array( 'folder_name' => 'formidable/css', 'file_name' => 'formidablepro.css' ) );
115 115
 		$create_file->create_file( $css );
116 116
 
117
-        update_option('frmpro_css', $css);
117
+        update_option( 'frmpro_css', $css );
118 118
 
119
-        delete_transient('frmpro_css');
120
-        set_transient('frmpro_css', $css);
119
+        delete_transient( 'frmpro_css' );
120
+        set_transient( 'frmpro_css', $css );
121 121
 	}
122 122
 
123 123
 	private function get_css_content( $filename ) {
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 	}
136 136
 
137 137
 	public function destroy( $id ) {
138
-        return wp_delete_post($id);
138
+        return wp_delete_post( $id );
139 139
     }
140 140
 
141 141
     public function get_one() {
@@ -149,19 +149,19 @@  discard block
 block discarded – undo
149 149
             return $style;
150 150
         }
151 151
 
152
-        $style = get_post($this->id);
152
+        $style = get_post( $this->id );
153 153
 
154 154
         if ( ! $style ) {
155 155
             return $style;
156 156
         }
157 157
 
158
-        $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
158
+        $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
159 159
 
160 160
         $default_values = $this->get_defaults();
161 161
 
162 162
         // fill default values
163
-        $style->post_content = $this->override_defaults($style->post_content);
164
-        $style->post_content = wp_parse_args( $style->post_content, $default_values);
163
+        $style->post_content = $this->override_defaults( $style->post_content );
164
+        $style->post_content = wp_parse_args( $style->post_content, $default_values );
165 165
 
166 166
         return $style;
167 167
     }
@@ -175,21 +175,21 @@  discard block
 block discarded – undo
175 175
 			'order'       => $order,
176 176
         );
177 177
 
178
-        $temp_styles = FrmAppHelper::check_cache(serialize($post_atts), 'frm_styles', $post_atts, 'get_posts');
178
+        $temp_styles = FrmAppHelper::check_cache( serialize( $post_atts ), 'frm_styles', $post_atts, 'get_posts' );
179 179
 
180
-        if ( empty($temp_styles) ) {
180
+        if ( empty( $temp_styles ) ) {
181 181
             global $wpdb;
182 182
             // make sure there wasn't a conflict with the query
183 183
 			$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' );
184
-            $temp_styles = FrmAppHelper::check_cache('frm_backup_style_check', 'frm_styles', $query, 'get_results');
184
+            $temp_styles = FrmAppHelper::check_cache( 'frm_backup_style_check', 'frm_styles', $query, 'get_results' );
185 185
 
186
-            if ( empty($temp_styles) ) {
186
+            if ( empty( $temp_styles ) ) {
187 187
                 // create a new style if there are none
188 188
          		$new = $this->get_new();
189 189
          		$new->post_title = $new->post_name = __( 'Formidable Style', 'formidable' );
190 190
          		$new->menu_order = 1;
191
-         		$new = $this->save( (array) $new);
192
-         		$this->update('default');
191
+         		$new = $this->save( (array) $new );
192
+         		$this->update( 'default' );
193 193
 
194 194
                 $post_atts['include'] = $new;
195 195
 
@@ -213,25 +213,25 @@  discard block
 block discarded – undo
213 213
                 }
214 214
             }
215 215
 
216
-            $style->post_content = FrmAppHelper::maybe_json_decode($style->post_content);
216
+            $style->post_content = FrmAppHelper::maybe_json_decode( $style->post_content );
217 217
 
218 218
             // fill default values
219
-            $style->post_content = $this->override_defaults($style->post_content);
220
-            $style->post_content = wp_parse_args( $style->post_content, $default_values);
219
+            $style->post_content = $this->override_defaults( $style->post_content );
220
+            $style->post_content = wp_parse_args( $style->post_content, $default_values );
221 221
 
222
-			$styles[ $style->ID ] = $style;
222
+			$styles[$style->ID] = $style;
223 223
         }
224 224
 
225 225
         if ( ! $default_style ) {
226
-            $default_style = reset($styles);
227
-			$styles[ $default_style->ID ]->menu_order = 1;
226
+            $default_style = reset( $styles );
227
+			$styles[$default_style->ID]->menu_order = 1;
228 228
         }
229 229
 
230 230
         return $styles;
231 231
     }
232 232
 
233 233
 	public function get_default_style( $styles = null ) {
234
-        if ( ! isset($styles) ) {
234
+        if ( ! isset( $styles ) ) {
235 235
 			$styles = $this->get_all( 'menu_order', 'DESC', 1 );
236 236
         }
237 237
 
@@ -243,24 +243,24 @@  discard block
 block discarded – undo
243 243
     }
244 244
 
245 245
 	public function override_defaults( $settings ) {
246
-	    if ( ! is_array($settings) ) {
246
+	    if ( ! is_array( $settings ) ) {
247 247
 	        return $settings;
248 248
 	    }
249 249
 
250
-	    $settings['line_height'] = ( ! isset($settings['field_height']) || $settings['field_height'] == '' || $settings['field_height'] == 'auto') ? 'normal' : $settings['field_height'];
250
+	    $settings['line_height'] = ( ! isset( $settings['field_height'] ) || $settings['field_height'] == '' || $settings['field_height'] == 'auto' ) ? 'normal' : $settings['field_height'];
251 251
 
252
-	    if ( ! isset($settings['form_desc_size']) && isset($settings['description_font_size']) ) {
252
+	    if ( ! isset( $settings['form_desc_size'] ) && isset( $settings['description_font_size'] ) ) {
253 253
 	        $settings['form_desc_size'] = $settings['description_font_size'];
254 254
 	        $settings['form_desc_color'] = $settings['description_color'];
255 255
 	        $settings['title_color'] = $settings['label_color'];
256 256
 	    }
257 257
 
258
-	    if ( ! isset($settings['section_color']) && isset($settings['label_color']) ) {
258
+	    if ( ! isset( $settings['section_color'] ) && isset( $settings['label_color'] ) ) {
259 259
 	        $settings['section_color'] = $settings['label_color'];
260 260
 	        $settings['section_border_color'] = $settings['border_color'];
261 261
 	    }
262 262
 
263
-	    if ( ! isset($settings['submit_hover_bg_color']) && isset($settings['submit_bg_color']) ) {
263
+	    if ( ! isset( $settings['submit_hover_bg_color'] ) && isset( $settings['submit_bg_color'] ) ) {
264 264
 	        $settings['submit_hover_bg_color'] = $settings['submit_bg_color'];
265 265
 	        $settings['submit_hover_color'] = $settings['submit_text_color'];
266 266
 	        $settings['submit_hover_border_color'] = $settings['submit_border_color'];
Please login to merge, or discard this patch.