Completed
Push — master ( 86cb09...971530 )
by Stephanie
03:52
created
classes/controllers/FrmXMLController.php 1 patch
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -2,109 +2,109 @@  discard block
 block discarded – undo
2 2
 
3 3
 class FrmXMLController {
4 4
 
5
-    public static function menu() {
5
+	public static function menu() {
6 6
 		add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' );
7
-    }
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 = '' ) {
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 52
 		$where = array(
53 53
 			'status' => array( null, '', 'published' ),
54 54
 		);
55 55
 		$forms = FrmForm::getAll( $where, 'name' );
56 56
 
57
-        $export_types = apply_filters( 'frm_xml_export_types',
58
-            array( 'forms' => __( 'Forms', 'formidable' ), 'items' => __( 'Entries', 'formidable' ) )
59
-        );
57
+		$export_types = apply_filters( 'frm_xml_export_types',
58
+			array( 'forms' => __( 'Forms', 'formidable' ), 'items' => __( 'Entries', 'formidable' ) )
59
+		);
60 60
 
61
-        $export_format = apply_filters( 'frm_export_formats', array(
62
-            'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ),
61
+		$export_format = apply_filters( 'frm_export_formats', array(
62
+			'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ),
63 63
 			'csv' => array( 'name' => 'CSV', 'support' => 'items', 'count' => 'single' ),
64
-        ) );
64
+		) );
65 65
 
66 66
 		include( FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php' );
67
-    }
67
+	}
68 68
 
69
-    public static function import_xml() {
70
-        $errors = array();
71
-        $message = '';
69
+	public static function import_xml() {
70
+		$errors = array();
71
+		$message = '';
72 72
 
73
-        $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce');
74
-        if ( $permission_error !== false ) {
75
-            $errors[] = $permission_error;
76
-            self::form($errors);
77
-            return;
78
-        }
73
+		$permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce');
74
+		if ( $permission_error !== false ) {
75
+			$errors[] = $permission_error;
76
+			self::form($errors);
77
+			return;
78
+		}
79 79
 
80
-        if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) {
81
-            $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
82
-            self::form($errors);
83
-            return;
84
-        }
80
+		if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) {
81
+			$errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' );
82
+			self::form($errors);
83
+			return;
84
+		}
85 85
 
86
-        $file = $_FILES['frm_import_file']['tmp_name'];
86
+		$file = $_FILES['frm_import_file']['tmp_name'];
87 87
 
88
-        if ( ! is_uploaded_file( $file ) ) {
89
-            unset($file);
90
-            $errors[] = __( 'The file does not exist, please try again.', 'formidable' );
91
-            self::form($errors);
92
-            return;
93
-        }
88
+		if ( ! is_uploaded_file( $file ) ) {
89
+			unset($file);
90
+			$errors[] = __( 'The file does not exist, please try again.', 'formidable' );
91
+			self::form($errors);
92
+			return;
93
+		}
94 94
 
95
-        //add_filter('upload_mimes', 'FrmXMLController::allow_mime');
95
+		//add_filter('upload_mimes', 'FrmXMLController::allow_mime');
96 96
 
97
-        $export_format = apply_filters('frm_export_formats', array(
97
+		$export_format = apply_filters('frm_export_formats', array(
98 98
 			'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ),
99 99
 		) );
100 100
 
101
-        $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION));
102
-        if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) {
103
-            // allow other file types to be imported
101
+		$file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION));
102
+		if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) {
103
+			// allow other file types to be imported
104 104
 			do_action( 'frm_before_import_' . $file_type );
105
-            return;
106
-        }
107
-        unset($file_type);
105
+			return;
106
+		}
107
+		unset($file_type);
108 108
 
109 109
 		if ( ! function_exists( 'libxml_disable_entity_loader' ) ) {
110 110
 			$errors[] = __( 'XML import is not enabled on your server.', 'formidable' );
@@ -123,154 +123,154 @@  discard block
 block discarded – undo
123 123
 		libxml_use_internal_errors( $set_err );
124 124
 		libxml_disable_entity_loader( $loader );
125 125
 
126
-        self::form($errors, $message);
127
-    }
126
+		self::form($errors, $message);
127
+	}
128 128
 
129
-    public static function export_xml() {
130
-        $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' );
131
-        if ( ! empty($error) ) {
132
-            wp_die( $error );
133
-        }
129
+	public static function export_xml() {
130
+		$error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' );
131
+		if ( ! empty($error) ) {
132
+			wp_die( $error );
133
+		}
134 134
 
135 135
 		$ids = FrmAppHelper::get_post_param( 'frm_export_forms', array() );
136 136
 		$type = FrmAppHelper::get_post_param( 'type', array() );
137 137
 		$format = FrmAppHelper::get_post_param( 'format', 'xml', 'sanitize_title' );
138 138
 
139
-        if ( ! headers_sent() && ! $type ) {
140
-            wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) );
141
-            die();
142
-        }
139
+		if ( ! headers_sent() && ! $type ) {
140
+			wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) );
141
+			die();
142
+		}
143 143
 
144
-        if ( $format == 'xml' ) {
145
-            self::generate_xml($type, compact('ids'));
144
+		if ( $format == 'xml' ) {
145
+			self::generate_xml($type, compact('ids'));
146 146
 		} if ( $format == 'csv' ) {
147 147
 			self::generate_csv( compact('ids') );
148
-        } else {
148
+		} else {
149 149
 			do_action( 'frm_export_format_' . $format, compact('ids') );
150
-        }
150
+		}
151 151
 
152
-        wp_die();
153
-    }
152
+		wp_die();
153
+	}
154 154
 
155 155
 	public static function generate_xml( $type, $args = array() ) {
156
-    	global $wpdb;
156
+		global $wpdb;
157 157
 
158
-	    $type = (array) $type;
159
-        if ( in_array( 'items', $type) && ! in_array( 'forms', $type) ) {
160
-            // make sure the form is included if there are entries
161
-            $type[] = 'forms';
162
-        }
158
+		$type = (array) $type;
159
+		if ( in_array( 'items', $type) && ! in_array( 'forms', $type) ) {
160
+			// make sure the form is included if there are entries
161
+			$type[] = 'forms';
162
+		}
163 163
 
164
-	    if ( in_array( 'forms', $type) ) {
165
-            // include actions with forms
166
-	        $type[] = 'actions';
167
-	    }
164
+		if ( in_array( 'forms', $type) ) {
165
+			// include actions with forms
166
+			$type[] = 'actions';
167
+		}
168 168
 
169
-	    $tables = array(
169
+		$tables = array(
170 170
 			'items'     => $wpdb->prefix . 'frm_items',
171 171
 			'forms'     => $wpdb->prefix . 'frm_forms',
172
-	        'posts'     => $wpdb->posts,
173
-	        'styles'    => $wpdb->posts,
174
-	        'actions'   => $wpdb->posts,
175
-	    );
172
+			'posts'     => $wpdb->posts,
173
+			'styles'    => $wpdb->posts,
174
+			'actions'   => $wpdb->posts,
175
+		);
176 176
 
177 177
 		$defaults = array( 'ids' => false );
178
-	    $args = wp_parse_args( $args, $defaults );
178
+		$args = wp_parse_args( $args, $defaults );
179 179
 
180
-        $sitename = sanitize_key( get_bloginfo( 'name' ) );
180
+		$sitename = sanitize_key( get_bloginfo( 'name' ) );
181 181
 
182
-    	if ( ! empty( $sitename ) ) {
182
+		if ( ! empty( $sitename ) ) {
183 183
 			$sitename .= '.';
184 184
 		}
185
-    	$filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
185
+		$filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml';
186 186
 
187
-    	header( 'Content-Description: File Transfer' );
188
-    	header( 'Content-Disposition: attachment; filename=' . $filename );
189
-    	header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
187
+		header( 'Content-Description: File Transfer' );
188
+		header( 'Content-Disposition: attachment; filename=' . $filename );
189
+		header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true );
190 190
 
191
-        //make sure ids are numeric
192
-    	if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) {
193
-	        $args['ids'] = array_filter( $args['ids'], 'is_numeric' );
194
-	    }
191
+		//make sure ids are numeric
192
+		if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) {
193
+			$args['ids'] = array_filter( $args['ids'], 'is_numeric' );
194
+		}
195 195
 
196
-	    $records = array();
196
+		$records = array();
197 197
 
198 198
 		foreach ( $type as $tb_type ) {
199
-            $where = array();
199
+			$where = array();
200 200
 			$join = '';
201
-            $table = $tables[ $tb_type ];
201
+			$table = $tables[ $tb_type ];
202 202
 
203 203
 			$select = $table . '.id';
204
-            $query_vars = array();
204
+			$query_vars = array();
205 205
 
206
-            switch ( $tb_type ) {
207
-                case 'forms':
208
-                    //add forms
209
-                    if ( $args['ids'] ) {
206
+			switch ( $tb_type ) {
207
+				case 'forms':
208
+					//add forms
209
+					if ( $args['ids'] ) {
210 210
 						$where[] = array( 'or' => 1, $table . '.id' => $args['ids'], $table . '.parent_form_id' => $args['ids'] );
211
-                	} else {
211
+					} else {
212 212
 						$where[ $table . '.status !' ] = 'draft';
213
-                	}
214
-                break;
215
-                case 'actions':
213
+					}
214
+				break;
215
+				case 'actions':
216 216
 					$select = $table . '.ID';
217 217
 					$where['post_type'] = FrmFormActionsController::$action_post_type;
218
-                    if ( ! empty($args['ids']) ) {
218
+					if ( ! empty($args['ids']) ) {
219 219
 						$where['menu_order'] = $args['ids'];
220
-                    }
221
-                break;
222
-                case 'items':
223
-                    //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
224
-                    if ( $args['ids'] ) {
220
+					}
221
+				break;
222
+				case 'items':
223
+					//$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)";
224
+					if ( $args['ids'] ) {
225 225
 						$where[ $table . '.form_id' ] = $args['ids'];
226
-                    }
227
-                break;
228
-                case 'styles':
229
-                    // Loop through all exported forms and get their selected style IDs
226
+					}
227
+				break;
228
+				case 'styles':
229
+					// Loop through all exported forms and get their selected style IDs
230 230
 					$frm_style = new FrmStyle();
231 231
 					$default_style = $frm_style->get_default_style();
232
-                    $form_ids = $args['ids'];
233
-                    $style_ids = array();
234
-                    foreach ( $form_ids as $form_id ) {
235
-                        $form_data = FrmForm::getOne( $form_id );
236
-                        // For forms that have not been updated while running 2.0, check if custom_style is set
237
-                        if ( isset( $form_data->options['custom_style'] ) ) {
232
+					$form_ids = $args['ids'];
233
+					$style_ids = array();
234
+					foreach ( $form_ids as $form_id ) {
235
+						$form_data = FrmForm::getOne( $form_id );
236
+						// For forms that have not been updated while running 2.0, check if custom_style is set
237
+						if ( isset( $form_data->options['custom_style'] ) ) {
238 238
 							if ( $form_data->options['custom_style'] == 1 ) {
239 239
 								$style_ids[] = $default_style->ID;
240 240
 							} else {
241 241
 								$style_ids[] = $form_data->options['custom_style'];
242 242
 							}
243
-                        }
244
-                        unset( $form_id, $form_data );
245
-                    }
243
+						}
244
+						unset( $form_id, $form_data );
245
+					}
246 246
 					$select = $table . '.ID';
247
-                    $where['post_type'] = 'frm_styles';
248
-
249
-                    // Only export selected styles
250
-                    if ( ! empty( $style_ids ) ) {
251
-                        $where['ID'] = $style_ids;
252
-                    }
253
-                break;
254
-                default:
247
+					$where['post_type'] = 'frm_styles';
248
+
249
+					// Only export selected styles
250
+					if ( ! empty( $style_ids ) ) {
251
+						$where['ID'] = $style_ids;
252
+					}
253
+				break;
254
+				default:
255 255
 					$select = $table . '.ID';
256
-                    $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
257
-                    $where['pm.meta_key'] = 'frm_form_id';
258
-
259
-                    if ( empty($args['ids']) ) {
260
-                        $where['pm.meta_value >'] = 1;
261
-                    } else {
262
-                        $where['pm.meta_value'] = $args['ids'];
263
-                    }
264
-                break;
265
-            }
256
+					$join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)';
257
+					$where['pm.meta_key'] = 'frm_form_id';
258
+
259
+					if ( empty($args['ids']) ) {
260
+						$where['pm.meta_value >'] = 1;
261
+					} else {
262
+						$where['pm.meta_value'] = $args['ids'];
263
+					}
264
+				break;
265
+			}
266 266
 
267 267
 			$records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select );
268
-            unset($tb_type);
269
-        }
268
+			unset($tb_type);
269
+		}
270 270
 
271 271
 		echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo('charset') ) . "\" ?>\n";
272 272
 		include( FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php' );
273
-    }
273
+	}
274 274
 
275 275
 
276 276
 	public static function generate_csv( $atts ) {
@@ -339,14 +339,14 @@  discard block
 block discarded – undo
339 339
 	}
340 340
 
341 341
 	/**
342
-	* Get the fields that should be included in the CSV export
343
-	*
344
-	* @since 2.0.19
345
-	*
346
-	* @param int $form_id
347
-	* @param object $form
348
-	* @return array $csv_fields
349
-	*/
342
+	 * Get the fields that should be included in the CSV export
343
+	 *
344
+	 * @since 2.0.19
345
+	 *
346
+	 * @param int $form_id
347
+	 * @param object $form
348
+	 * @return array $csv_fields
349
+	 */
350 350
 	private static function get_fields_for_csv_export( $form_id, $form ) {
351 351
 		// Phase frm_csv_field_ids out by 2.01.05
352 352
 		$csv_field_ids = apply_filters( 'frm_csv_field_ids', '', $form_id, array( 'form' => $form ) );
@@ -376,16 +376,16 @@  discard block
 block discarded – undo
376 376
 	}
377 377
 
378 378
 	public static function allow_mime( $mimes ) {
379
-        if ( ! isset( $mimes['csv'] ) ) {
380
-            // allow csv files
381
-            $mimes['csv'] = 'text/csv';
382
-        }
383
-
384
-        if ( ! isset( $mimes['xml'] ) ) {
385
-            // allow xml
386
-            $mimes['xml'] = 'text/xml';
387
-        }
388
-
389
-        return $mimes;
390
-    }
379
+		if ( ! isset( $mimes['csv'] ) ) {
380
+			// allow csv files
381
+			$mimes['csv'] = 'text/csv';
382
+		}
383
+
384
+		if ( ! isset( $mimes['xml'] ) ) {
385
+			// allow xml
386
+			$mimes['xml'] = 'text/xml';
387
+		}
388
+
389
+		return $mimes;
390
+	}
391 391
 }
Please login to merge, or discard this patch.