@@ -2,110 +2,110 @@ 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 = '' ) { |
|
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 | 'parent_form_id' => array( null, 0 ), |
54 | 54 | 'status' => array( null, '', 'published' ) |
55 | 55 | ); |
56 | 56 | $forms = FrmForm::getAll( $where, 'name' ); |
57 | 57 | |
58 | - $export_types = apply_filters( 'frm_xml_export_types', |
|
59 | - array( 'forms' => __( 'Forms', 'formidable' ), 'items' => __( 'Entries', 'formidable' ) ) |
|
60 | - ); |
|
58 | + $export_types = apply_filters( 'frm_xml_export_types', |
|
59 | + array( 'forms' => __( 'Forms', 'formidable' ), 'items' => __( 'Entries', 'formidable' ) ) |
|
60 | + ); |
|
61 | 61 | |
62 | - $export_format = apply_filters( 'frm_export_formats', array( |
|
63 | - 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ), |
|
62 | + $export_format = apply_filters( 'frm_export_formats', array( |
|
63 | + 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ), |
|
64 | 64 | 'csv' => array( 'name' => 'CSV', 'support' => 'items', 'count' => 'single' ), |
65 | - ) ); |
|
65 | + ) ); |
|
66 | 66 | |
67 | - include(FrmAppHelper::plugin_path() .'/classes/views/xml/import_form.php'); |
|
68 | - } |
|
67 | + include(FrmAppHelper::plugin_path() .'/classes/views/xml/import_form.php'); |
|
68 | + } |
|
69 | 69 | |
70 | - public static function import_xml() { |
|
71 | - $errors = array(); |
|
72 | - $message = ''; |
|
70 | + public static function import_xml() { |
|
71 | + $errors = array(); |
|
72 | + $message = ''; |
|
73 | 73 | |
74 | - $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce'); |
|
75 | - if ( $permission_error !== false ) { |
|
76 | - $errors[] = $permission_error; |
|
77 | - self::form($errors); |
|
78 | - return; |
|
79 | - } |
|
74 | + $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce'); |
|
75 | + if ( $permission_error !== false ) { |
|
76 | + $errors[] = $permission_error; |
|
77 | + self::form($errors); |
|
78 | + return; |
|
79 | + } |
|
80 | 80 | |
81 | - if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) { |
|
82 | - $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
|
83 | - self::form($errors); |
|
84 | - return; |
|
85 | - } |
|
81 | + if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) { |
|
82 | + $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
|
83 | + self::form($errors); |
|
84 | + return; |
|
85 | + } |
|
86 | 86 | |
87 | - $file = $_FILES['frm_import_file']['tmp_name']; |
|
87 | + $file = $_FILES['frm_import_file']['tmp_name']; |
|
88 | 88 | |
89 | - if ( ! is_uploaded_file( $file ) ) { |
|
90 | - unset($file); |
|
91 | - $errors[] = __( 'The file does not exist, please try again.', 'formidable' ); |
|
92 | - self::form($errors); |
|
93 | - return; |
|
94 | - } |
|
89 | + if ( ! is_uploaded_file( $file ) ) { |
|
90 | + unset($file); |
|
91 | + $errors[] = __( 'The file does not exist, please try again.', 'formidable' ); |
|
92 | + self::form($errors); |
|
93 | + return; |
|
94 | + } |
|
95 | 95 | |
96 | - //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); |
|
96 | + //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); |
|
97 | 97 | |
98 | - $export_format = apply_filters('frm_export_formats', array( |
|
98 | + $export_format = apply_filters('frm_export_formats', array( |
|
99 | 99 | 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ), |
100 | 100 | ) ); |
101 | 101 | |
102 | - $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION)); |
|
103 | - if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) { |
|
104 | - // allow other file types to be imported |
|
105 | - do_action('frm_before_import_'. $file_type ); |
|
106 | - return; |
|
107 | - } |
|
108 | - unset($file_type); |
|
102 | + $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION)); |
|
103 | + if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) { |
|
104 | + // allow other file types to be imported |
|
105 | + do_action('frm_before_import_'. $file_type ); |
|
106 | + return; |
|
107 | + } |
|
108 | + unset($file_type); |
|
109 | 109 | |
110 | 110 | if ( ! function_exists( 'libxml_disable_entity_loader' ) ) { |
111 | 111 | $errors[] = __( 'XML import is not enabled on your server.', 'formidable' ); |
@@ -124,148 +124,148 @@ discard block |
||
124 | 124 | libxml_use_internal_errors( $set_err ); |
125 | 125 | libxml_disable_entity_loader( $loader ); |
126 | 126 | |
127 | - self::form($errors, $message); |
|
128 | - } |
|
127 | + self::form($errors, $message); |
|
128 | + } |
|
129 | 129 | |
130 | - public static function export_xml() { |
|
131 | - $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
|
132 | - if ( ! empty($error) ) { |
|
133 | - wp_die( $error ); |
|
134 | - } |
|
130 | + public static function export_xml() { |
|
131 | + $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
|
132 | + if ( ! empty($error) ) { |
|
133 | + wp_die( $error ); |
|
134 | + } |
|
135 | 135 | |
136 | 136 | $ids = FrmAppHelper::get_post_param( 'frm_export_forms', array() ); |
137 | 137 | $type = FrmAppHelper::get_post_param( 'type', array() ); |
138 | 138 | $format = FrmAppHelper::get_post_param( 'format', 'xml', 'sanitize_title' ); |
139 | 139 | |
140 | - if ( ! headers_sent() && ! $type ) { |
|
141 | - wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) ); |
|
142 | - die(); |
|
143 | - } |
|
140 | + if ( ! headers_sent() && ! $type ) { |
|
141 | + wp_redirect( esc_url_raw( admin_url( 'admin.php?page=formidable-import' ) ) ); |
|
142 | + die(); |
|
143 | + } |
|
144 | 144 | |
145 | - if ( $format == 'xml' ) { |
|
146 | - self::generate_xml($type, compact('ids')); |
|
145 | + if ( $format == 'xml' ) { |
|
146 | + self::generate_xml($type, compact('ids')); |
|
147 | 147 | } if ( $format == 'csv' ) { |
148 | 148 | self::generate_csv( compact('ids') ); |
149 | - } else { |
|
150 | - do_action('frm_export_format_'. $format, compact('ids')); |
|
151 | - } |
|
149 | + } else { |
|
150 | + do_action('frm_export_format_'. $format, compact('ids')); |
|
151 | + } |
|
152 | 152 | |
153 | - wp_die(); |
|
154 | - } |
|
153 | + wp_die(); |
|
154 | + } |
|
155 | 155 | |
156 | 156 | public static function generate_xml( $type, $args = array() ) { |
157 | - global $wpdb; |
|
158 | - |
|
159 | - $type = (array) $type; |
|
160 | - if ( in_array( 'items', $type) && ! in_array( 'forms', $type) ) { |
|
161 | - // make sure the form is included if there are entries |
|
162 | - $type[] = 'forms'; |
|
163 | - } |
|
164 | - |
|
165 | - if ( in_array( 'forms', $type) ) { |
|
166 | - // include actions with forms |
|
167 | - $type[] = 'actions'; |
|
168 | - } |
|
169 | - |
|
170 | - $tables = array( |
|
171 | - 'items' => $wpdb->prefix .'frm_items', |
|
172 | - 'forms' => $wpdb->prefix .'frm_forms', |
|
173 | - 'posts' => $wpdb->posts, |
|
174 | - 'styles' => $wpdb->posts, |
|
175 | - 'actions' => $wpdb->posts, |
|
176 | - ); |
|
157 | + global $wpdb; |
|
158 | + |
|
159 | + $type = (array) $type; |
|
160 | + if ( in_array( 'items', $type) && ! in_array( 'forms', $type) ) { |
|
161 | + // make sure the form is included if there are entries |
|
162 | + $type[] = 'forms'; |
|
163 | + } |
|
164 | + |
|
165 | + if ( in_array( 'forms', $type) ) { |
|
166 | + // include actions with forms |
|
167 | + $type[] = 'actions'; |
|
168 | + } |
|
169 | + |
|
170 | + $tables = array( |
|
171 | + 'items' => $wpdb->prefix .'frm_items', |
|
172 | + 'forms' => $wpdb->prefix .'frm_forms', |
|
173 | + 'posts' => $wpdb->posts, |
|
174 | + 'styles' => $wpdb->posts, |
|
175 | + 'actions' => $wpdb->posts, |
|
176 | + ); |
|
177 | 177 | |
178 | 178 | $defaults = array( 'ids' => false ); |
179 | - $args = wp_parse_args( $args, $defaults ); |
|
179 | + $args = wp_parse_args( $args, $defaults ); |
|
180 | 180 | |
181 | - $sitename = sanitize_key( get_bloginfo( 'name' ) ); |
|
181 | + $sitename = sanitize_key( get_bloginfo( 'name' ) ); |
|
182 | 182 | |
183 | - if ( ! empty( $sitename ) ) { |
|
183 | + if ( ! empty( $sitename ) ) { |
|
184 | 184 | $sitename .= '.'; |
185 | 185 | } |
186 | - $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml'; |
|
186 | + $filename = $sitename . 'formidable.' . date( 'Y-m-d' ) . '.xml'; |
|
187 | 187 | |
188 | - header( 'Content-Description: File Transfer' ); |
|
189 | - header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
190 | - header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
|
188 | + header( 'Content-Description: File Transfer' ); |
|
189 | + header( 'Content-Disposition: attachment; filename=' . $filename ); |
|
190 | + header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
|
191 | 191 | |
192 | - //make sure ids are numeric |
|
193 | - if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) { |
|
194 | - $args['ids'] = array_filter( $args['ids'], 'is_numeric' ); |
|
195 | - } |
|
192 | + //make sure ids are numeric |
|
193 | + if ( is_array( $args['ids'] ) && ! empty( $args['ids'] ) ) { |
|
194 | + $args['ids'] = array_filter( $args['ids'], 'is_numeric' ); |
|
195 | + } |
|
196 | 196 | |
197 | - $records = array(); |
|
197 | + $records = array(); |
|
198 | 198 | |
199 | 199 | foreach ( $type as $tb_type ) { |
200 | - $where = array(); |
|
200 | + $where = array(); |
|
201 | 201 | $join = ''; |
202 | - $table = $tables[ $tb_type ]; |
|
202 | + $table = $tables[ $tb_type ]; |
|
203 | 203 | |
204 | - $select = $table .'.id'; |
|
205 | - $query_vars = array(); |
|
204 | + $select = $table .'.id'; |
|
205 | + $query_vars = array(); |
|
206 | 206 | |
207 | - switch ( $tb_type ) { |
|
208 | - case 'forms': |
|
209 | - //add forms |
|
210 | - if ( $args['ids'] ) { |
|
207 | + switch ( $tb_type ) { |
|
208 | + case 'forms': |
|
209 | + //add forms |
|
210 | + if ( $args['ids'] ) { |
|
211 | 211 | $where[] = array( 'or' => 1, $table . '.id' => $args['ids'], $table .'.parent_form_id' => $args['ids'] ); |
212 | - } else { |
|
212 | + } else { |
|
213 | 213 | $where[ $table . '.status !' ] = 'draft'; |
214 | - } |
|
215 | - break; |
|
216 | - case 'actions': |
|
217 | - $select = $table .'.ID'; |
|
214 | + } |
|
215 | + break; |
|
216 | + case 'actions': |
|
217 | + $select = $table .'.ID'; |
|
218 | 218 | $where['post_type'] = FrmFormActionsController::$action_post_type; |
219 | - if ( ! empty($args['ids']) ) { |
|
219 | + if ( ! empty($args['ids']) ) { |
|
220 | 220 | $where['menu_order'] = $args['ids']; |
221 | - } |
|
222 | - break; |
|
223 | - case 'items': |
|
224 | - //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)"; |
|
225 | - if ( $args['ids'] ) { |
|
221 | + } |
|
222 | + break; |
|
223 | + case 'items': |
|
224 | + //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)"; |
|
225 | + if ( $args['ids'] ) { |
|
226 | 226 | $where[ $table . '.form_id' ] = $args['ids']; |
227 | - } |
|
228 | - break; |
|
229 | - case 'styles': |
|
230 | - // Loop through all exported forms and get their selected style IDs |
|
231 | - $form_ids = $args['ids']; |
|
232 | - $style_ids = array(); |
|
233 | - foreach ( $form_ids as $form_id ) { |
|
234 | - $form_data = FrmForm::getOne( $form_id ); |
|
235 | - // For forms that have not been updated while running 2.0, check if custom_style is set |
|
236 | - if ( isset( $form_data->options['custom_style'] ) ) { |
|
237 | - $style_ids[] = $form_data->options['custom_style']; |
|
238 | - } |
|
239 | - unset( $form_id, $form_data ); |
|
240 | - } |
|
241 | - $select = $table .'.ID'; |
|
242 | - $where['post_type'] = 'frm_styles'; |
|
243 | - |
|
244 | - // Only export selected styles |
|
245 | - if ( ! empty( $style_ids ) ) { |
|
246 | - $where['ID'] = $style_ids; |
|
247 | - } |
|
248 | - break; |
|
249 | - default: |
|
250 | - $select = $table .'.ID'; |
|
251 | - $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)'; |
|
252 | - $where['pm.meta_key'] = 'frm_form_id'; |
|
253 | - |
|
254 | - if ( empty($args['ids']) ) { |
|
255 | - $where['pm.meta_value >'] = 1; |
|
256 | - } else { |
|
257 | - $where['pm.meta_value'] = $args['ids']; |
|
258 | - } |
|
259 | - break; |
|
260 | - } |
|
227 | + } |
|
228 | + break; |
|
229 | + case 'styles': |
|
230 | + // Loop through all exported forms and get their selected style IDs |
|
231 | + $form_ids = $args['ids']; |
|
232 | + $style_ids = array(); |
|
233 | + foreach ( $form_ids as $form_id ) { |
|
234 | + $form_data = FrmForm::getOne( $form_id ); |
|
235 | + // For forms that have not been updated while running 2.0, check if custom_style is set |
|
236 | + if ( isset( $form_data->options['custom_style'] ) ) { |
|
237 | + $style_ids[] = $form_data->options['custom_style']; |
|
238 | + } |
|
239 | + unset( $form_id, $form_data ); |
|
240 | + } |
|
241 | + $select = $table .'.ID'; |
|
242 | + $where['post_type'] = 'frm_styles'; |
|
243 | + |
|
244 | + // Only export selected styles |
|
245 | + if ( ! empty( $style_ids ) ) { |
|
246 | + $where['ID'] = $style_ids; |
|
247 | + } |
|
248 | + break; |
|
249 | + default: |
|
250 | + $select = $table .'.ID'; |
|
251 | + $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)'; |
|
252 | + $where['pm.meta_key'] = 'frm_form_id'; |
|
253 | + |
|
254 | + if ( empty($args['ids']) ) { |
|
255 | + $where['pm.meta_value >'] = 1; |
|
256 | + } else { |
|
257 | + $where['pm.meta_value'] = $args['ids']; |
|
258 | + } |
|
259 | + break; |
|
260 | + } |
|
261 | 261 | |
262 | 262 | $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select ); |
263 | - unset($tb_type); |
|
264 | - } |
|
263 | + unset($tb_type); |
|
264 | + } |
|
265 | 265 | |
266 | 266 | echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo('charset') ) . "\" ?>\n"; |
267 | - include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php'); |
|
268 | - } |
|
267 | + include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php'); |
|
268 | + } |
|
269 | 269 | |
270 | 270 | |
271 | 271 | public static function generate_csv( $atts ) { |
@@ -336,14 +336,14 @@ discard block |
||
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
339 | - * Get the fields that should be included in the CSV export |
|
340 | - * |
|
341 | - * @since 2.0.19 |
|
342 | - * |
|
343 | - * @param int $form_id |
|
344 | - * @param object $form |
|
345 | - * @return array $csv_fields |
|
346 | - */ |
|
339 | + * Get the fields that should be included in the CSV export |
|
340 | + * |
|
341 | + * @since 2.0.19 |
|
342 | + * |
|
343 | + * @param int $form_id |
|
344 | + * @param object $form |
|
345 | + * @return array $csv_fields |
|
346 | + */ |
|
347 | 347 | private static function get_fields_for_csv_export( $form_id, $form ) { |
348 | 348 | $csv_field_ids = apply_filters( 'frm_csv_field_ids', '', $form_id, array( 'form' => $form ) ); |
349 | 349 | |
@@ -371,16 +371,16 @@ discard block |
||
371 | 371 | } |
372 | 372 | |
373 | 373 | public static function allow_mime( $mimes ) { |
374 | - if ( ! isset( $mimes['csv'] ) ) { |
|
375 | - // allow csv files |
|
376 | - $mimes['csv'] = 'text/csv'; |
|
377 | - } |
|
378 | - |
|
379 | - if ( ! isset( $mimes['xml'] ) ) { |
|
380 | - // allow xml |
|
381 | - $mimes['xml'] = 'text/xml'; |
|
382 | - } |
|
383 | - |
|
384 | - return $mimes; |
|
385 | - } |
|
374 | + if ( ! isset( $mimes['csv'] ) ) { |
|
375 | + // allow csv files |
|
376 | + $mimes['csv'] = 'text/csv'; |
|
377 | + } |
|
378 | + |
|
379 | + if ( ! isset( $mimes['xml'] ) ) { |
|
380 | + // allow xml |
|
381 | + $mimes['xml'] = 'text/xml'; |
|
382 | + } |
|
383 | + |
|
384 | + return $mimes; |
|
385 | + } |
|
386 | 386 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | class FrmXMLController { |
4 | 4 | |
5 | 5 | public static function menu() { |
6 | - add_submenu_page('formidable', 'Formidable | '. __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route'); |
|
6 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' ); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | public static function add_default_templates() { |
@@ -12,14 +12,14 @@ discard block |
||
12 | 12 | return; |
13 | 13 | } |
14 | 14 | |
15 | - $set_err = libxml_use_internal_errors(true); |
|
15 | + $set_err = libxml_use_internal_errors( true ); |
|
16 | 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 | 20 | foreach ( (array) $files as $file ) { |
21 | - FrmXMLHelper::import_xml($file); |
|
22 | - unset($file); |
|
21 | + FrmXMLHelper::import_xml( $file ); |
|
22 | + unset( $file ); |
|
23 | 23 | } |
24 | 24 | /* |
25 | 25 | if(is_wp_error($result)) |
@@ -64,48 +64,48 @@ discard block |
||
64 | 64 | 'csv' => array( 'name' => 'CSV', 'support' => 'items', 'count' => 'single' ), |
65 | 65 | ) ); |
66 | 66 | |
67 | - include(FrmAppHelper::plugin_path() .'/classes/views/xml/import_form.php'); |
|
67 | + include( FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php' ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | public static function import_xml() { |
71 | 71 | $errors = array(); |
72 | 72 | $message = ''; |
73 | 73 | |
74 | - $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'import-xml', 'import-xml-nonce'); |
|
74 | + $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' ); |
|
75 | 75 | if ( $permission_error !== false ) { |
76 | 76 | $errors[] = $permission_error; |
77 | - self::form($errors); |
|
77 | + self::form( $errors ); |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | - if ( ! isset($_FILES) || ! isset($_FILES['frm_import_file']) || empty($_FILES['frm_import_file']['name']) || (int) $_FILES['frm_import_file']['size'] < 1 ) { |
|
81 | + if ( ! isset( $_FILES ) || ! isset( $_FILES['frm_import_file'] ) || empty( $_FILES['frm_import_file']['name'] ) || (int) $_FILES['frm_import_file']['size'] < 1 ) { |
|
82 | 82 | $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
83 | - self::form($errors); |
|
83 | + self::form( $errors ); |
|
84 | 84 | return; |
85 | 85 | } |
86 | 86 | |
87 | 87 | $file = $_FILES['frm_import_file']['tmp_name']; |
88 | 88 | |
89 | 89 | if ( ! is_uploaded_file( $file ) ) { |
90 | - unset($file); |
|
90 | + unset( $file ); |
|
91 | 91 | $errors[] = __( 'The file does not exist, please try again.', 'formidable' ); |
92 | - self::form($errors); |
|
92 | + self::form( $errors ); |
|
93 | 93 | return; |
94 | 94 | } |
95 | 95 | |
96 | 96 | //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); |
97 | 97 | |
98 | - $export_format = apply_filters('frm_export_formats', array( |
|
98 | + $export_format = apply_filters( 'frm_export_formats', array( |
|
99 | 99 | 'xml' => array( 'name' => 'XML', 'support' => 'forms', 'count' => 'multiple' ), |
100 | 100 | ) ); |
101 | 101 | |
102 | - $file_type = strtolower(pathinfo($_FILES['frm_import_file']['name'], PATHINFO_EXTENSION)); |
|
103 | - if ( $file_type != 'xml' && isset( $export_format[ $file_type ] ) ) { |
|
102 | + $file_type = strtolower( pathinfo( $_FILES['frm_import_file']['name'], PATHINFO_EXTENSION ) ); |
|
103 | + if ( $file_type != 'xml' && isset( $export_format[$file_type] ) ) { |
|
104 | 104 | // allow other file types to be imported |
105 | - do_action('frm_before_import_'. $file_type ); |
|
105 | + do_action( 'frm_before_import_' . $file_type ); |
|
106 | 106 | return; |
107 | 107 | } |
108 | - unset($file_type); |
|
108 | + unset( $file_type ); |
|
109 | 109 | |
110 | 110 | if ( ! function_exists( 'libxml_disable_entity_loader' ) ) { |
111 | 111 | $errors[] = __( 'XML import is not enabled on your server.', 'formidable' ); |
@@ -124,12 +124,12 @@ discard block |
||
124 | 124 | libxml_use_internal_errors( $set_err ); |
125 | 125 | libxml_disable_entity_loader( $loader ); |
126 | 126 | |
127 | - self::form($errors, $message); |
|
127 | + self::form( $errors, $message ); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | public static function export_xml() { |
131 | 131 | $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
132 | - if ( ! empty($error) ) { |
|
132 | + if ( ! empty( $error ) ) { |
|
133 | 133 | wp_die( $error ); |
134 | 134 | } |
135 | 135 | |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | if ( $format == 'xml' ) { |
146 | - self::generate_xml($type, compact('ids')); |
|
146 | + self::generate_xml( $type, compact( 'ids' ) ); |
|
147 | 147 | } if ( $format == 'csv' ) { |
148 | - self::generate_csv( compact('ids') ); |
|
148 | + self::generate_csv( compact( 'ids' ) ); |
|
149 | 149 | } else { |
150 | - do_action('frm_export_format_'. $format, compact('ids')); |
|
150 | + do_action( 'frm_export_format_' . $format, compact( 'ids' ) ); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | wp_die(); |
@@ -157,19 +157,19 @@ discard block |
||
157 | 157 | global $wpdb; |
158 | 158 | |
159 | 159 | $type = (array) $type; |
160 | - if ( in_array( 'items', $type) && ! in_array( 'forms', $type) ) { |
|
160 | + if ( in_array( 'items', $type ) && ! in_array( 'forms', $type ) ) { |
|
161 | 161 | // make sure the form is included if there are entries |
162 | 162 | $type[] = 'forms'; |
163 | 163 | } |
164 | 164 | |
165 | - if ( in_array( 'forms', $type) ) { |
|
165 | + if ( in_array( 'forms', $type ) ) { |
|
166 | 166 | // include actions with forms |
167 | 167 | $type[] = 'actions'; |
168 | 168 | } |
169 | 169 | |
170 | 170 | $tables = array( |
171 | - 'items' => $wpdb->prefix .'frm_items', |
|
172 | - 'forms' => $wpdb->prefix .'frm_forms', |
|
171 | + 'items' => $wpdb->prefix . 'frm_items', |
|
172 | + 'forms' => $wpdb->prefix . 'frm_forms', |
|
173 | 173 | 'posts' => $wpdb->posts, |
174 | 174 | 'styles' => $wpdb->posts, |
175 | 175 | 'actions' => $wpdb->posts, |
@@ -199,31 +199,31 @@ discard block |
||
199 | 199 | foreach ( $type as $tb_type ) { |
200 | 200 | $where = array(); |
201 | 201 | $join = ''; |
202 | - $table = $tables[ $tb_type ]; |
|
202 | + $table = $tables[$tb_type]; |
|
203 | 203 | |
204 | - $select = $table .'.id'; |
|
204 | + $select = $table . '.id'; |
|
205 | 205 | $query_vars = array(); |
206 | 206 | |
207 | 207 | switch ( $tb_type ) { |
208 | 208 | case 'forms': |
209 | 209 | //add forms |
210 | 210 | if ( $args['ids'] ) { |
211 | - $where[] = array( 'or' => 1, $table . '.id' => $args['ids'], $table .'.parent_form_id' => $args['ids'] ); |
|
211 | + $where[] = array( 'or' => 1, $table . '.id' => $args['ids'], $table . '.parent_form_id' => $args['ids'] ); |
|
212 | 212 | } else { |
213 | - $where[ $table . '.status !' ] = 'draft'; |
|
213 | + $where[$table . '.status !'] = 'draft'; |
|
214 | 214 | } |
215 | 215 | break; |
216 | 216 | case 'actions': |
217 | - $select = $table .'.ID'; |
|
217 | + $select = $table . '.ID'; |
|
218 | 218 | $where['post_type'] = FrmFormActionsController::$action_post_type; |
219 | - if ( ! empty($args['ids']) ) { |
|
219 | + if ( ! empty( $args['ids'] ) ) { |
|
220 | 220 | $where['menu_order'] = $args['ids']; |
221 | 221 | } |
222 | 222 | break; |
223 | 223 | case 'items': |
224 | 224 | //$join = "INNER JOIN {$wpdb->prefix}frm_item_metas im ON ($table.id = im.item_id)"; |
225 | 225 | if ( $args['ids'] ) { |
226 | - $where[ $table . '.form_id' ] = $args['ids']; |
|
226 | + $where[$table . '.form_id'] = $args['ids']; |
|
227 | 227 | } |
228 | 228 | break; |
229 | 229 | case 'styles': |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | } |
239 | 239 | unset( $form_id, $form_data ); |
240 | 240 | } |
241 | - $select = $table .'.ID'; |
|
241 | + $select = $table . '.ID'; |
|
242 | 242 | $where['post_type'] = 'frm_styles'; |
243 | 243 | |
244 | 244 | // Only export selected styles |
@@ -247,11 +247,11 @@ discard block |
||
247 | 247 | } |
248 | 248 | break; |
249 | 249 | default: |
250 | - $select = $table .'.ID'; |
|
250 | + $select = $table . '.ID'; |
|
251 | 251 | $join = ' INNER JOIN ' . $wpdb->postmeta . ' pm ON (pm.post_id=' . $table . '.ID)'; |
252 | 252 | $where['pm.meta_key'] = 'frm_form_id'; |
253 | 253 | |
254 | - if ( empty($args['ids']) ) { |
|
254 | + if ( empty( $args['ids'] ) ) { |
|
255 | 255 | $where['pm.meta_value >'] = 1; |
256 | 256 | } else { |
257 | 257 | $where['pm.meta_value'] = $args['ids']; |
@@ -259,12 +259,12 @@ discard block |
||
259 | 259 | break; |
260 | 260 | } |
261 | 261 | |
262 | - $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select ); |
|
263 | - unset($tb_type); |
|
262 | + $records[$tb_type] = FrmDb::get_col( $table . $join, $where, $select ); |
|
263 | + unset( $tb_type ); |
|
264 | 264 | } |
265 | 265 | |
266 | - echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo('charset') ) . "\" ?>\n"; |
|
267 | - include(FrmAppHelper::plugin_path() .'/classes/views/xml/xml.php'); |
|
266 | + echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo( 'charset' ) ) . "\" ?>\n"; |
|
267 | + include( FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php' ); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | |
@@ -289,11 +289,11 @@ discard block |
||
289 | 289 | $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' ); |
290 | 290 | } |
291 | 291 | |
292 | - if ( ! ini_get('safe_mode') ) { |
|
293 | - set_time_limit(0); //Remove time limit to execute this function |
|
294 | - $mem_limit = str_replace('M', '', ini_get('memory_limit')); |
|
292 | + if ( ! ini_get( 'safe_mode' ) ) { |
|
293 | + set_time_limit( 0 ); //Remove time limit to execute this function |
|
294 | + $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) ); |
|
295 | 295 | if ( (int) $mem_limit < 256 ) { |
296 | - ini_set('memory_limit', '256M'); |
|
296 | + ini_set( 'memory_limit', '256M' ); |
|
297 | 297 | } |
298 | 298 | } |
299 | 299 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | */ |
324 | 324 | $query = apply_filters( 'frm_csv_where', $query, compact( 'form_id', 'search', 'fid', 'item_id' ) ); |
325 | 325 | |
326 | - $entry_ids = FrmDb::get_col( $wpdb->prefix .'frm_items it', $query ); |
|
326 | + $entry_ids = FrmDb::get_col( $wpdb->prefix . 'frm_items it', $query ); |
|
327 | 327 | unset( $query ); |
328 | 328 | |
329 | 329 | if ( empty( $entry_ids ) ) { |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | if ( ! is_array( $csv_field_ids ) ) { |
354 | 354 | $csv_field_ids = explode( ',', $csv_field_ids ); |
355 | 355 | } |
356 | - if ( ! empty( $csv_field_ids ) ) { |
|
356 | + if ( ! empty( $csv_field_ids ) ) { |
|
357 | 357 | $where['fi.id'] = $csv_field_ids; |
358 | 358 | } |
359 | 359 | $csv_fields = FrmField::getAll( $where, 'field_order' ); |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | $no_export_fields = FrmField::no_save_fields(); |
363 | 363 | foreach ( $csv_fields as $k => $f ) { |
364 | 364 | if ( in_array( $f->type, $no_export_fields ) ) { |
365 | - unset( $csv_fields[ $k ] ); |
|
365 | + unset( $csv_fields[$k] ); |
|
366 | 366 | } |
367 | 367 | } |
368 | 368 | } |
@@ -353,7 +353,7 @@ |
||
353 | 353 | if ( ! is_array( $csv_field_ids ) ) { |
354 | 354 | $csv_field_ids = explode( ',', $csv_field_ids ); |
355 | 355 | } |
356 | - if ( ! empty( $csv_field_ids ) ) { |
|
356 | + if ( ! empty( $csv_field_ids ) ) { |
|
357 | 357 | $where['fi.id'] = $csv_field_ids; |
358 | 358 | } |
359 | 359 | $csv_fields = FrmField::getAll( $where, 'field_order' ); |