| @@ -4,21 +4,15 @@ | ||
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmXMLController { |
| 7 | 7 | |
| 8 | - /** | |
| 9 | - * @return void | |
| 10 | - */ | |
| 11 | 8 | public static function menu() { |
| 12 | 9 | add_submenu_page( 'formidable', 'Formidable | ' . __( 'Import/Export', 'formidable' ), __( 'Import/Export', 'formidable' ), 'frm_edit_forms', 'formidable-import', 'FrmXMLController::route' ); |
| 13 | 10 | } |
| 14 | 11 | |
| 15 | - /** | |
| 16 | - * @return void | |
| 17 | - */ | |
| 18 | 12 | public static function add_default_templates() { |
| 19 | 13 | if ( FrmXMLHelper::check_if_libxml_disable_entity_loader_exists() ) { |
| 20 | - // XML import is not enabled on your server. | |
| 14 | + // XML import is not enabled on your server | |
| 21 | 15 | return; |
| 22 | 16 | } |
| 23 | 17 | |
| 24 | 18 | $set_err = libxml_use_internal_errors( true ); |
| @@ -40,35 +34,18 @@ | ||
| 40 | 34 | /** |
| 41 | 35 | * Use the template link to install the XML template |
| 42 | 36 | * |
| 43 | 37 | * @since 3.06 |
| 44 | - * | |
| 45 | - * @return void | |
| 46 | 38 | */ |
| 47 | 39 | public static function install_template() { |
| 48 | 40 | FrmAppHelper::permission_check( 'frm_edit_forms' ); |
| 49 | 41 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 50 | 42 | |
| 51 | - if ( ! function_exists( 'simplexml_load_string' ) ) { | |
| 52 | - $response = array( | |
| 53 | - 'message' => __( 'Your server is missing the Simple XML extension. This is required to install a template.', 'formidable' ), | |
| 54 | - ); | |
| 55 | - echo wp_json_encode( $response ); | |
| 56 | - wp_die(); | |
| 57 | - } | |
| 43 | + $url = FrmAppHelper::get_param( 'xml', '', 'post', 'esc_url_raw' ); | |
| 58 | 44 | |
| 59 | 45 | $form = self::get_posted_form(); |
| 60 | - $url = FrmAppHelper::get_param( 'xml', '', 'post', 'esc_url_raw' ); | |
| 61 | 46 | self::override_url( $form, $url ); |
| 62 | 47 | |
| 63 | - if ( ! self::validate_xml_url( $url ) ) { | |
| 64 | - $response = array( | |
| 65 | - 'message' => __( 'The template you are trying to install could not be validated.', 'formidable' ), | |
| 66 | - ); | |
| 67 | - echo wp_json_encode( $response ); | |
| 68 | - wp_die(); | |
| 69 | - } | |
| 70 | - | |
| 71 | 48 | $response = wp_remote_get( $url ); |
| 72 | 49 | $body = wp_remote_retrieve_body( $response ); |
| 73 | 50 | $xml = simplexml_load_string( $body ); |
| 74 | 51 | |
| @@ -73,9 +50,9 @@ | ||
| 73 | 50 | $xml = simplexml_load_string( $body ); |
| 74 | 51 | |
| 75 | 52 | if ( ! $xml ) { |
| 76 | 53 | $response = array( |
| 77 | - 'message' => __( 'There was an error reading the form template.', 'formidable' ), | |
| 54 | + 'message' => __( 'There was an error reading the form template', 'formidable' ), | |
| 78 | 55 | ); |
| 79 | 56 | echo wp_json_encode( $response ); |
| 80 | 57 | wp_die(); |
| 81 | 58 | } |
| @@ -81,20 +58,18 @@ | ||
| 81 | 58 | } |
| 82 | 59 | |
| 83 | 60 | self::set_new_form_name( $xml ); |
| 84 | 61 | |
| 85 | - $imported = FrmXMLHelper::import_xml_now( $xml, true ); | |
| 86 | - | |
| 87 | - if ( ! empty( $imported['form_status'] ) ) { | |
| 62 | + $imported = FrmXMLHelper::import_xml_now( $xml ); | |
| 63 | + if ( isset( $imported['form_status'] ) && ! empty( $imported['form_status'] ) ) { | |
| 88 | 64 | // Get the last form id in case there are child forms. |
| 89 | 65 | end( $imported['form_status'] ); |
| 90 | 66 | $form_id = key( $imported['form_status'] ); |
| 91 | 67 | $response = array( |
| 92 | 68 | 'id' => $form_id, |
| 93 | - 'redirect' => FrmForm::get_edit_link( $form_id ) . '&new_template=true', | |
| 69 | + 'redirect' => FrmForm::get_edit_link( $form_id ), | |
| 94 | 70 | 'success' => 1, |
| 95 | 71 | ); |
| 96 | - | |
| 97 | 72 | if ( ! empty( $imported['imported']['posts'] ) ) { |
| 98 | 73 | // Return the link to the last page created. |
| 99 | 74 | $pages = $imported['posts']; |
| 100 | 75 | } |
| @@ -103,10 +78,10 @@ | ||
| 103 | 78 | // Create selected pages with the correct shortcodes. |
| 104 | 79 | $pages = self::create_pages_for_import( $form ); |
| 105 | 80 | } |
| 106 | 81 | |
| 107 | - if ( ! empty( $pages ) ) { | |
| 108 | - $post_id = end( $pages ); | |
| 82 | + if ( isset( $pages ) && ! empty( $pages ) ) { | |
| 83 | + $post_id = end( $pages ); | |
| 109 | 84 | $response['redirect'] = get_permalink( $post_id ); |
| 110 | 85 | } |
| 111 | 86 | } else { |
| 112 | 87 | if ( isset( $imported['error'] ) ) { |
| @@ -113,19 +88,15 @@ | ||
| 113 | 88 | $message = $imported['error']; |
| 114 | 89 | } else { |
| 115 | 90 | $message = __( 'There was an error importing form', 'formidable' ); |
| 116 | 91 | } |
| 117 | - | |
| 118 | 92 | $response = array( |
| 119 | 93 | 'message' => $message, |
| 120 | 94 | ); |
| 121 | 95 | |
| 122 | - }//end if | |
| 96 | + } | |
| 123 | 97 | |
| 124 | - /** | |
| 125 | - * @since 6.18 Added `url` to the $args. | |
| 126 | - */ | |
| 127 | - $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported', 'url' ) ); | |
| 98 | + $response = apply_filters( 'frm_xml_response', $response, compact( 'form', 'imported' ) ); | |
| 128 | 99 | |
| 129 | 100 | echo wp_json_encode( $response ); |
| 130 | 101 | wp_die(); |
| 131 | 102 | } |
| @@ -130,33 +101,15 @@ | ||
| 130 | 101 | wp_die(); |
| 131 | 102 | } |
| 132 | 103 | |
| 133 | 104 | /** |
| 134 | - * Make sure that the XML file we're trying to load is in fact an XML file, and that it's coming from our S3 bucket. | |
| 135 | - * This is to make sure that the URL can't be exploited for a SSRF attack. | |
| 136 | - * | |
| 137 | - * @since 5.5.5 | |
| 138 | - * | |
| 139 | - * @param string $url | |
| 140 | - * | |
| 141 | - * @return bool True on success, False on error. | |
| 142 | - */ | |
| 143 | - private static function validate_xml_url( $url ) { | |
| 144 | - return FrmAppHelper::validate_url_is_in_s3_bucket( $url, 'xml' ); | |
| 145 | - } | |
| 146 | - | |
| 147 | - /** | |
| 148 | 105 | * @since 4.06.02 |
| 149 | - * | |
| 150 | - * @return mixed | |
| 151 | 106 | */ |
| 152 | 107 | private static function get_posted_form() { |
| 153 | 108 | $form = FrmAppHelper::get_param( 'form', '', 'post', 'wp_unslash' ); |
| 154 | - | |
| 155 | 109 | if ( empty( $form ) ) { |
| 156 | 110 | return $form; |
| 157 | 111 | } |
| 158 | - | |
| 159 | 112 | $form = json_decode( $form, true ); |
| 160 | 113 | return $form; |
| 161 | 114 | } |
| 162 | 115 | |
| @@ -163,23 +116,16 @@ | ||
| 163 | 116 | /** |
| 164 | 117 | * Get a different URL depending on the selection in the form. |
| 165 | 118 | * |
| 166 | 119 | * @since 4.06.02 |
| 167 | - * | |
| 168 | - * @param array $form The posted form values. | |
| 169 | - * @param string $url The URL to override. | |
| 170 | - * | |
| 171 | - * @return void | |
| 172 | 120 | */ |
| 173 | 121 | private static function override_url( $form, &$url ) { |
| 174 | 122 | $selected_form = self::get_selected_in_form( $form, 'form' ); |
| 175 | - | |
| 176 | 123 | if ( empty( $selected_form ) ) { |
| 177 | 124 | return; |
| 178 | 125 | } |
| 179 | 126 | |
| 180 | - $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; | |
| 181 | - | |
| 127 | + $selected_xml = isset( $form['xml'] ) && isset( $form['xml'][ $selected_form ] ) ? $form['xml'][ $selected_form ] : ''; | |
| 182 | 128 | if ( empty( $selected_xml ) || strpos( $selected_xml, 'http' ) !== 0 ) { |
| 183 | 129 | return; |
| 184 | 130 | } |
| 185 | 131 | |
| @@ -187,16 +133,11 @@ | ||
| 187 | 133 | } |
| 188 | 134 | |
| 189 | 135 | /** |
| 190 | 136 | * @since 4.06.02 |
| 191 | - * | |
| 192 | - * @param array $form | |
| 193 | - * @param string $value | |
| 194 | - * | |
| 195 | - * @return string | |
| 196 | 137 | */ |
| 197 | 138 | private static function get_selected_in_form( $form, $value = 'form' ) { |
| 198 | - if ( ! empty( $form ) && ! empty( $form[ $value ] ) ) { | |
| 139 | + if ( ! empty( $form ) && isset( $form[ $value ] ) && ! empty( $form[ $value ] ) ) { | |
| 199 | 140 | return $form[ $value ]; |
| 200 | 141 | } |
| 201 | 142 | |
| 202 | 143 | return ''; |
| @@ -206,20 +147,19 @@ | ||
| 206 | 147 | * @since 4.06.02 |
| 207 | 148 | * |
| 208 | 149 | * @param array $form The posted form values. |
| 209 | 150 | * |
| 210 | - * @return array|null The array of created pages. | |
| 151 | + * @return array The array of created pages. | |
| 211 | 152 | */ |
| 212 | 153 | private static function create_pages_for_import( $form ) { |
| 213 | - if ( empty( $form['pages'] ) ) { | |
| 214 | - return null; | |
| 154 | + if ( ! isset( $form['pages'] ) || empty( $form['pages'] ) ) { | |
| 155 | + return; | |
| 215 | 156 | } |
| 216 | 157 | |
| 217 | - $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 158 | + $form_key = self::get_selected_in_form( $form, 'form' ); | |
| 218 | 159 | $view_keys = self::get_selected_in_form( $form, 'view' ); |
| 219 | 160 | |
| 220 | 161 | $page_ids = array(); |
| 221 | - | |
| 222 | 162 | foreach ( (array) $form['pages'] as $for => $name ) { |
| 223 | 163 | if ( empty( $name ) ) { |
| 224 | 164 | // Don't create a page if no title is given. |
| 225 | 165 | continue; |
| @@ -228,9 +168,9 @@ | ||
| 228 | 168 | if ( $for === 'view' ) { |
| 229 | 169 | $item_key = is_array( $view_keys ) ? $view_keys[ $form_key ] : $view_keys; |
| 230 | 170 | $shortcode = '[display-frm-data id=%1$s filter=limited]'; |
| 231 | 171 | } elseif ( $for === 'form' ) { |
| 232 | - $item_key = $form_key; | |
| 172 | + $item_key = $form_key; | |
| 233 | 173 | $shortcode = '[formidable id=%1$s]'; |
| 234 | 174 | } else { |
| 235 | 175 | $item_key = self::get_selected_in_form( $form, 'form' ); |
| 236 | 176 | $shortcode = '[' . esc_html( $for ) . ' id=%1$s]'; |
| @@ -247,9 +187,9 @@ | ||
| 247 | 187 | 'post_type' => 'page', |
| 248 | 188 | 'post_content' => sprintf( $shortcode, $item_key ), |
| 249 | 189 | ) |
| 250 | 190 | ); |
| 251 | - }//end foreach | |
| 191 | + } | |
| 252 | 192 | |
| 253 | 193 | return $page_ids; |
| 254 | 194 | } |
| 255 | 195 | |
| @@ -260,10 +200,8 @@ | ||
| 260 | 200 | * |
| 261 | 201 | * @since 3.06 |
| 262 | 202 | * |
| 263 | 203 | * @param object $xml The values included in the XML. |
| 264 | - * | |
| 265 | - * @return void | |
| 266 | 204 | */ |
| 267 | 205 | private static function set_new_form_name( &$xml ) { |
| 268 | 206 | if ( ! isset( $xml->form ) ) { |
| 269 | 207 | return; |
| @@ -270,38 +208,33 @@ | ||
| 270 | 208 | } |
| 271 | 209 | |
| 272 | 210 | $name = FrmAppHelper::get_param( 'name', '', 'post', 'sanitize_text_field' ); |
| 273 | 211 | $description = FrmAppHelper::get_param( 'desc', '', 'post', 'sanitize_textarea_field' ); |
| 274 | - | |
| 275 | - if ( ! $name && ! $description ) { | |
| 212 | + if ( empty( $name ) && empty( $description ) ) { | |
| 276 | 213 | return; |
| 277 | 214 | } |
| 278 | 215 | |
| 279 | 216 | // Get the main form ID. |
| 280 | 217 | $set_name = 0; |
| 281 | - | |
| 282 | 218 | foreach ( $xml->form as $form ) { |
| 283 | - if ( empty( $form->parent_form_id ) ) { | |
| 284 | - $set_name = (int) $form->id; | |
| 219 | + if ( ! isset( $form->parent_form_id ) || empty( $form->parent_form_id ) ) { | |
| 220 | + $set_name = $form->id; | |
| 285 | 221 | } |
| 286 | 222 | } |
| 287 | 223 | |
| 288 | 224 | foreach ( $xml->form as $form ) { |
| 289 | 225 | // Maybe set the form name if this isn't a child form. |
| 290 | - if ( $set_name === (int) $form->id ) { | |
| 226 | + if ( $set_name == $form->id ) { | |
| 291 | 227 | $form->name = $name; |
| 292 | 228 | $form->description = $description; |
| 293 | 229 | } |
| 294 | 230 | |
| 295 | 231 | // Use a unique key to prevent editing existing form. |
| 296 | - $sanitized_form_name = sanitize_title( $form->name ); | |
| 297 | - $form->form_key = FrmAppHelper::get_unique_key( $sanitized_form_name, 'frm_forms', 'form_key' ); | |
| 232 | + $name = sanitize_title( $form->name ); | |
| 233 | + $form->form_key = FrmAppHelper::get_unique_key( $name, 'frm_forms', 'form_key' ); | |
| 298 | 234 | } |
| 299 | 235 | } |
| 300 | 236 | |
| 301 | - /** | |
| 302 | - * @return void | |
| 303 | - */ | |
| 304 | 237 | public static function route() { |
| 305 | 238 | $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
| 306 | 239 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 307 | 240 | FrmAppHelper::include_svg(); |
| @@ -306,22 +239,16 @@ | ||
| 306 | 239 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 307 | 240 | FrmAppHelper::include_svg(); |
| 308 | 241 | |
| 309 | 242 | if ( 'import_xml' === $action ) { |
| 310 | - self::import_xml(); | |
| 243 | + return self::import_xml(); | |
| 311 | 244 | } elseif ( 'export_xml' === $action ) { |
| 312 | - self::export_xml(); | |
| 245 | + return self::export_xml(); | |
| 313 | 246 | } elseif ( apply_filters( 'frm_xml_route', true, $action ) ) { |
| 314 | - self::form(); | |
| 247 | + return self::form(); | |
| 315 | 248 | } |
| 316 | 249 | } |
| 317 | 250 | |
| 318 | - /** | |
| 319 | - * @param string[] $errors | |
| 320 | - * @param string $message | |
| 321 | - * | |
| 322 | - * @return void | |
| 323 | - */ | |
| 324 | 251 | public static function form( $errors = array(), $message = '' ) { |
| 325 | 252 | $where = array( |
| 326 | 253 | 'status' => array( null, '', 'published' ), |
| 327 | 254 | ); |
| @@ -346,20 +273,16 @@ | ||
| 346 | 273 | ), |
| 347 | 274 | ); |
| 348 | 275 | $export_format = apply_filters( 'frm_export_formats', $export_format ); |
| 349 | 276 | |
| 350 | - include FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php'; | |
| 277 | + include( FrmAppHelper::plugin_path() . '/classes/views/xml/import_form.php' ); | |
| 351 | 278 | } |
| 352 | 279 | |
| 353 | - /** | |
| 354 | - * @return void | |
| 355 | - */ | |
| 356 | 280 | public static function import_xml() { |
| 357 | 281 | $errors = array(); |
| 358 | 282 | $message = ''; |
| 359 | 283 | |
| 360 | 284 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'import-xml', 'import-xml-nonce' ); |
| 361 | - | |
| 362 | 285 | if ( false !== $permission_error ) { |
| 363 | 286 | $errors[] = $permission_error; |
| 364 | 287 | self::form( $errors ); |
| 365 | 288 | |
| @@ -365,11 +288,9 @@ | ||
| 365 | 288 | |
| 366 | 289 | return; |
| 367 | 290 | } |
| 368 | 291 | |
| 369 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 370 | - $has_file = ! empty( $_FILES['frm_import_file'] ) && ! empty( $_FILES['frm_import_file']['name'] ) && ! empty( $_FILES['frm_import_file']['size'] ) && (int) $_FILES['frm_import_file']['size'] > 0; | |
| 371 | - | |
| 292 | + $has_file = isset( $_FILES ) && isset( $_FILES['frm_import_file'] ) && ! empty( $_FILES['frm_import_file']['name'] ) && ! empty( $_FILES['frm_import_file']['size'] ) && (int) $_FILES['frm_import_file']['size'] > 0; | |
| 372 | 293 | if ( ! $has_file ) { |
| 373 | 294 | $errors[] = __( 'Oops, you didn\'t select a file.', 'formidable' ); |
| 374 | 295 | self::form( $errors ); |
| 375 | 296 | |
| @@ -375,9 +296,9 @@ | ||
| 375 | 296 | |
| 376 | 297 | return; |
| 377 | 298 | } |
| 378 | 299 | |
| 379 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 300 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 380 | 301 | $file = isset( $_FILES['frm_import_file']['tmp_name'] ) ? sanitize_option( 'upload_path', $_FILES['frm_import_file']['tmp_name'] ) : ''; |
| 381 | 302 | |
| 382 | 303 | if ( ! is_uploaded_file( $file ) ) { |
| 383 | 304 | unset( $file ); |
| @@ -386,8 +307,10 @@ | ||
| 386 | 307 | |
| 387 | 308 | return; |
| 388 | 309 | } |
| 389 | 310 | |
| 311 | + //add_filter('upload_mimes', 'FrmXMLController::allow_mime'); | |
| 312 | + | |
| 390 | 313 | $export_format = array( |
| 391 | 314 | 'xml' => array( |
| 392 | 315 | 'name' => 'XML', |
| 393 | 316 | 'support' => 'forms', |
| @@ -395,12 +318,11 @@ | ||
| 395 | 318 | ), |
| 396 | 319 | ); |
| 397 | 320 | $export_format = apply_filters( 'frm_export_formats', $export_format ); |
| 398 | 321 | |
| 399 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.NonceVerification.Missing | |
| 322 | + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 400 | 323 | $file_type = sanitize_option( 'upload_path', $_FILES['frm_import_file']['name'] ); |
| 401 | 324 | $file_type = strtolower( pathinfo( $file_type, PATHINFO_EXTENSION ) ); |
| 402 | - | |
| 403 | 325 | if ( 'xml' !== $file_type && isset( $export_format[ $file_type ] ) ) { |
| 404 | 326 | // allow other file types to be imported |
| 405 | 327 | do_action( 'frm_before_import_' . $file_type ); |
| 406 | 328 | |
| @@ -428,14 +350,10 @@ | ||
| 428 | 350 | |
| 429 | 351 | self::form( $errors, $message ); |
| 430 | 352 | } |
| 431 | 353 | |
| 432 | - /** | |
| 433 | - * @return void | |
| 434 | - */ | |
| 435 | 354 | public static function export_xml() { |
| 436 | 355 | $error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'export-xml', 'export-xml-nonce' ); |
| 437 | - | |
| 438 | 356 | if ( ! empty( $error ) ) { |
| 439 | 357 | wp_die( esc_html( $error ) ); |
| 440 | 358 | } |
| 441 | 359 | |
| @@ -458,28 +376,13 @@ | ||
| 458 | 376 | |
| 459 | 377 | wp_die(); |
| 460 | 378 | } |
| 461 | 379 | |
| 462 | - /** | |
| 463 | - * @param array<string>|string $type | |
| 464 | - * @param array $args | |
| 465 | - * | |
| 466 | - * @psalm-param array{ids?: mixed} $args | |
| 467 | - * | |
| 468 | - * @return void | |
| 469 | - */ | |
| 470 | 380 | public static function generate_xml( $type, $args = array() ) { |
| 471 | 381 | global $wpdb; |
| 472 | 382 | |
| 473 | 383 | self::prepare_types_array( $type ); |
| 474 | 384 | |
| 475 | - if ( ! is_array( $type ) ) { | |
| 476 | - // This shouldn't be possible. | |
| 477 | - // It is cast to array in prepare_types_array. | |
| 478 | - // This is just for static analysis. | |
| 479 | - return; | |
| 480 | - } | |
| 481 | - | |
| 482 | 385 | $tables = array( |
| 483 | 386 | 'items' => $wpdb->prefix . 'frm_items', |
| 484 | 387 | 'forms' => $wpdb->prefix . 'frm_forms', |
| 485 | 388 | 'posts' => $wpdb->posts, |
| @@ -508,9 +411,9 @@ | ||
| 508 | 411 | $query_vars = array(); |
| 509 | 412 | |
| 510 | 413 | switch ( $tb_type ) { |
| 511 | 414 | case 'forms': |
| 512 | - // Add forms. | |
| 415 | + //add forms | |
| 513 | 416 | if ( $args['ids'] ) { |
| 514 | 417 | $where[] = array( |
| 515 | 418 | 'or' => 1, |
| 516 | 419 | $table . '.id' => $args['ids'], |
| @@ -522,9 +425,8 @@ | ||
| 522 | 425 | break; |
| 523 | 426 | case 'actions': |
| 524 | 427 | $select = $table . '.ID'; |
| 525 | 428 | $where['post_type'] = FrmFormActionsController::$action_post_type; |
| 526 | - | |
| 527 | 429 | if ( ! empty( $args['ids'] ) ) { |
| 528 | 430 | $where['menu_order'] = $args['ids']; |
| 529 | 431 | } |
| 530 | 432 | break; |
| @@ -539,12 +441,10 @@ | ||
| 539 | 441 | $frm_style = new FrmStyle(); |
| 540 | 442 | $default_style = $frm_style->get_default_style(); |
| 541 | 443 | $form_ids = $args['ids']; |
| 542 | 444 | $style_ids = array(); |
| 543 | - | |
| 544 | 445 | foreach ( $form_ids as $form_id ) { |
| 545 | 446 | $form_data = FrmForm::getOne( $form_id ); |
| 546 | - | |
| 547 | 447 | // For forms that have not been updated while running 2.0, check if custom_style is set. |
| 548 | 448 | if ( isset( $form_data->options['custom_style'] ) ) { |
| 549 | 449 | if ( 1 === absint( $form_data->options['custom_style'] ) ) { |
| 550 | 450 | $style_ids[] = $default_style->ID; |
| @@ -553,9 +453,8 @@ | ||
| 553 | 453 | } |
| 554 | 454 | } |
| 555 | 455 | unset( $form_id, $form_data ); |
| 556 | 456 | } |
| 557 | - | |
| 558 | 457 | $select = $table . '.ID'; |
| 559 | 458 | $where['post_type'] = 'frm_styles'; |
| 560 | 459 | |
| 561 | 460 | // Only export selected styles. |
| @@ -572,15 +471,15 @@ | ||
| 572 | 471 | $where['pm.meta_value >'] = 1; |
| 573 | 472 | } else { |
| 574 | 473 | $where['pm.meta_value'] = $args['ids']; |
| 575 | 474 | } |
| 576 | - }//end switch | |
| 475 | + } | |
| 577 | 476 | |
| 578 | 477 | $records[ $tb_type ] = FrmDb::get_col( $table . $join, $where, $select ); |
| 579 | 478 | unset( $tb_type ); |
| 580 | - }//end foreach | |
| 479 | + } | |
| 581 | 480 | |
| 582 | - $filename = self::get_file_name( $args, $records ); | |
| 481 | + $filename = self::get_file_name( $args, $type, $records ); | |
| 583 | 482 | |
| 584 | 483 | header( 'Content-Description: File Transfer' ); |
| 585 | 484 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
| 586 | 485 | header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
| @@ -585,50 +484,19 @@ | ||
| 585 | 484 | header( 'Content-Disposition: attachment; filename=' . $filename ); |
| 586 | 485 | header( 'Content-Type: text/xml; charset=' . get_option( 'blog_charset' ), true ); |
| 587 | 486 | |
| 588 | 487 | echo '<?xml version="1.0" encoding="' . esc_attr( get_bloginfo( 'charset' ) ) . "\" ?>\n"; |
| 589 | - include FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php'; | |
| 488 | + include( FrmAppHelper::plugin_path() . '/classes/views/xml/xml.php' ); | |
| 590 | 489 | } |
| 591 | 490 | |
| 592 | - /** | |
| 593 | - * Returns an array that has parent term slugs for the terms provided. | |
| 594 | - * | |
| 595 | - * @since 6.8.3 | |
| 596 | - * | |
| 597 | - * @param array $terms | |
| 598 | - * | |
| 599 | - * @return array | |
| 600 | - */ | |
| 601 | - public static function get_parent_terms_slugs( $terms ) { | |
| 602 | - $parent_term_ids = array_filter( array_unique( wp_list_pluck( $terms, 'parent' ) ) ); | |
| 603 | - $parent_slugs = array(); | |
| 604 | - | |
| 605 | - if ( ! $parent_term_ids ) { | |
| 606 | - return $parent_slugs; | |
| 607 | - } | |
| 608 | - | |
| 609 | - $results = FrmDb::get_results( 'terms', array( 'term_id' => $parent_term_ids ), 'term_id, slug' ); | |
| 610 | - $parent_slugs = wp_list_pluck( $results, 'slug', 'term_id' ); | |
| 611 | - | |
| 612 | - return $parent_slugs; | |
| 613 | - } | |
| 614 | - | |
| 615 | - /** | |
| 616 | - * Prepare the types array. | |
| 617 | - * | |
| 618 | - * @param array<string>|string $type | |
| 619 | - * | |
| 620 | - * @return void | |
| 621 | - */ | |
| 622 | 491 | private static function prepare_types_array( &$type ) { |
| 623 | 492 | $type = (array) $type; |
| 624 | - | |
| 625 | - if ( ! in_array( 'forms', $type, true ) && ( in_array( 'items', $type, true ) || in_array( 'posts', $type, true ) ) ) { | |
| 493 | + if ( ! in_array( 'forms', $type ) && ( in_array( 'items', $type ) || in_array( 'posts', $type ) ) ) { | |
| 626 | 494 | // make sure the form is included if there are entries |
| 627 | 495 | $type[] = 'forms'; |
| 628 | 496 | } |
| 629 | 497 | |
| 630 | - if ( in_array( 'forms', $type, true ) ) { | |
| 498 | + if ( in_array( 'forms', $type ) ) { | |
| 631 | 499 | // include actions with forms |
| 632 | 500 | $type[] = 'actions'; |
| 633 | 501 | } |
| 634 | 502 | } |
| @@ -638,16 +506,12 @@ | ||
| 638 | 506 | * Use the nme of the form if only one form is exported. |
| 639 | 507 | * |
| 640 | 508 | * @since 3.06 |
| 641 | 509 | * |
| 642 | - * @param array $args | |
| 643 | - * @param array $records | |
| 644 | - * | |
| 645 | 510 | * @return string |
| 646 | 511 | */ |
| 647 | - private static function get_file_name( $args, $records ) { | |
| 648 | - $has_one_form = ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 649 | - | |
| 512 | + private static function get_file_name( $args, $type, $records ) { | |
| 513 | + $has_one_form = isset( $records['forms'] ) && ! empty( $records['forms'] ) && count( $args['ids'] ) === 1; | |
| 650 | 514 | if ( $has_one_form ) { |
| 651 | 515 | // one form is being exported |
| 652 | 516 | $selected_form_id = reset( $args['ids'] ); |
| 653 | 517 | $filename = 'form-' . $selected_form_id . '.xml'; |
| @@ -653,13 +517,11 @@ | ||
| 653 | 517 | $filename = 'form-' . $selected_form_id . '.xml'; |
| 654 | 518 | |
| 655 | 519 | foreach ( $records['forms'] as $form_id ) { |
| 656 | 520 | $filename = 'form-' . $form_id . '.xml'; |
| 657 | - | |
| 658 | 521 | if ( $selected_form_id === $form_id ) { |
| 659 | 522 | $form = FrmForm::getOne( $form_id ); |
| 660 | - $filename = $form->name !== '' ? $form->name : $form->form_key; | |
| 661 | - $filename = sanitize_title( $filename ) . '-form.xml'; | |
| 523 | + $filename = sanitize_title( $form->name ) . '-form.xml'; | |
| 662 | 524 | break; |
| 663 | 525 | } |
| 664 | 526 | } |
| 665 | 527 | } else { |
| @@ -667,28 +529,16 @@ | ||
| 667 | 529 | |
| 668 | 530 | if ( ! empty( $sitename ) ) { |
| 669 | 531 | $sitename .= '.'; |
| 670 | 532 | } |
| 671 | - | |
| 672 | 533 | $filename = $sitename . 'formidable.' . gmdate( 'Y-m-d' ) . '.xml'; |
| 673 | - }//end if | |
| 534 | + } | |
| 674 | 535 | |
| 675 | - /** | |
| 676 | - * @since 5.3 | |
| 677 | - * | |
| 678 | - * @param string $filename | |
| 679 | - */ | |
| 680 | - return apply_filters( 'frm_xml_filename', $filename ); | |
| 536 | + return $filename; | |
| 681 | 537 | } |
| 682 | 538 | |
| 683 | - /** | |
| 684 | - * @param array $atts | |
| 685 | - * | |
| 686 | - * @return void | |
| 687 | - */ | |
| 688 | 539 | public static function generate_csv( $atts ) { |
| 689 | 540 | $form_ids = $atts['ids']; |
| 690 | - | |
| 691 | 541 | if ( empty( $form_ids ) ) { |
| 692 | 542 | wp_die( esc_html__( 'Please select a form', 'formidable' ) ); |
| 693 | 543 | } |
| 694 | 544 | self::csv( reset( $form_ids ) ); |
| @@ -697,14 +547,8 @@ | ||
| 697 | 547 | /** |
| 698 | 548 | * Export to CSV |
| 699 | 549 | * |
| 700 | 550 | * @since 2.0.19 |
| 701 | - * | |
| 702 | - * @param false|int|string $form_id | |
| 703 | - * @param string $search | |
| 704 | - * @param string $fid | |
| 705 | - * | |
| 706 | - * @return void | |
| 707 | 551 | */ |
| 708 | 552 | public static function csv( $form_id = false, $search = '', $fid = '' ) { |
| 709 | 553 | FrmAppHelper::permission_check( 'frm_view_entries' ); |
| 710 | 554 | |
| @@ -713,15 +557,10 @@ | ||
| 713 | 557 | $search = FrmAppHelper::get_param( ( isset( $_REQUEST['s'] ) ? 's' : 'search' ), '', 'get', 'sanitize_text_field' ); |
| 714 | 558 | $fid = FrmAppHelper::get_param( 'fid', '', 'get', 'sanitize_text_field' ); |
| 715 | 559 | } |
| 716 | 560 | |
| 717 | - // Remove time limit to execute this function. | |
| 718 | - if ( function_exists( 'set_time_limit' ) ) { | |
| 719 | - set_time_limit( 0 ); | |
| 720 | - } | |
| 721 | - | |
| 561 | + set_time_limit( 0 ); //Remove time limit to execute this function | |
| 722 | 562 | $mem_limit = str_replace( 'M', '', ini_get( 'memory_limit' ) ); |
| 723 | - | |
| 724 | 563 | if ( (int) $mem_limit < 256 ) { |
| 725 | 564 | wp_raise_memory_limit(); |
| 726 | 565 | } |
| 727 | 566 | |
| @@ -726,20 +565,14 @@ | ||
| 726 | 565 | } |
| 727 | 566 | |
| 728 | 567 | global $wpdb; |
| 729 | 568 | |
| 730 | - $form = FrmForm::getOne( $form_id ); | |
| 569 | + $form = FrmForm::getOne( $form_id ); | |
| 570 | + $form_id = $form->id; | |
| 731 | 571 | |
| 732 | - if ( ! $form ) { | |
| 733 | - esc_html_e( 'Form not found.', 'formidable' ); | |
| 734 | - wp_die(); | |
| 735 | - } | |
| 736 | - | |
| 737 | - $form_id = $form->id; | |
| 738 | 572 | $form_cols = self::get_fields_for_csv_export( $form_id, $form ); |
| 739 | 573 | |
| 740 | 574 | $item_id = FrmAppHelper::get_param( 'item_id', 0, 'get', 'sanitize_text_field' ); |
| 741 | - | |
| 742 | 575 | if ( ! empty( $item_id ) ) { |
| 743 | 576 | $item_id = explode( ',', $item_id ); |
| 744 | 577 | } |
| 745 | 578 | |
| @@ -774,19 +607,17 @@ | ||
| 774 | 607 | /** |
| 775 | 608 | * Get the fields that should be included in the CSV export |
| 776 | 609 | * |
| 777 | 610 | * @since 2.0.19 |
| 778 | - * @since 5.0.16 function went from private to public. | |
| 779 | 611 | * |
| 780 | - * @param int $form_id | |
| 612 | + * @param int $form_id | |
| 781 | 613 | * @param object $form |
| 782 | 614 | * |
| 783 | 615 | * @return array $csv_fields |
| 784 | 616 | */ |
| 785 | - public static function get_fields_for_csv_export( $form_id, $form ) { | |
| 617 | + private static function get_fields_for_csv_export( $form_id, $form ) { | |
| 786 | 618 | $csv_fields = FrmField::get_all_for_form( $form_id, '', 'include', 'include' ); |
| 787 | 619 | $no_export_fields = FrmField::no_save_fields(); |
| 788 | - | |
| 789 | 620 | foreach ( $csv_fields as $k => $f ) { |
| 790 | 621 | if ( in_array( $f->type, $no_export_fields, true ) ) { |
| 791 | 622 | unset( $csv_fields[ $k ] ); |
| 792 | 623 | } |
| @@ -791,16 +622,11 @@ | ||
| 791 | 622 | unset( $csv_fields[ $k ] ); |
| 792 | 623 | } |
| 793 | 624 | } |
| 794 | 625 | |
| 795 | - return apply_filters( 'frm_fields_for_csv_export', $csv_fields, compact( 'form' ) ); | |
| 626 | + return $csv_fields; | |
| 796 | 627 | } |
| 797 | 628 | |
| 798 | - /** | |
| 799 | - * @param array $mimes | |
| 800 | - * | |
| 801 | - * @return array | |
| 802 | - */ | |
| 803 | 629 | public static function allow_mime( $mimes ) { |
| 804 | 630 | if ( ! isset( $mimes['csv'] ) ) { |
| 805 | 631 | // allow csv files |
| 806 | 632 | $mimes['csv'] = 'text/csv'; |