@@ -23,30 +23,30 @@ discard block |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | public static function import_xml( $file ) { |
| 26 | - $defaults = array( |
|
| 27 | - 'forms' => 0, 'fields' => 0, 'terms' => 0, |
|
| 28 | - 'posts' => 0, 'views' => 0, 'actions' => 0, |
|
| 29 | - 'styles' => 0, |
|
| 30 | - ); |
|
| 31 | - |
|
| 32 | - $imported = array( |
|
| 33 | - 'imported' => $defaults, |
|
| 26 | + $defaults = array( |
|
| 27 | + 'forms' => 0, 'fields' => 0, 'terms' => 0, |
|
| 28 | + 'posts' => 0, 'views' => 0, 'actions' => 0, |
|
| 29 | + 'styles' => 0, |
|
| 30 | + ); |
|
| 31 | + |
|
| 32 | + $imported = array( |
|
| 33 | + 'imported' => $defaults, |
|
| 34 | 34 | 'updated' => $defaults, |
| 35 | 35 | 'forms' => array(), |
| 36 | 36 | 'terms' => array(), |
| 37 | - ); |
|
| 37 | + ); |
|
| 38 | 38 | |
| 39 | - unset($defaults); |
|
| 39 | + unset($defaults); |
|
| 40 | 40 | |
| 41 | 41 | if ( ! defined( 'WP_IMPORTING' ) ) { |
| 42 | - define('WP_IMPORTING', true); |
|
| 43 | - } |
|
| 42 | + define('WP_IMPORTING', true); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | if ( ! class_exists( 'DOMDocument' ) ) { |
| 46 | - return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() ); |
|
| 47 | - } |
|
| 46 | + return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() ); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - $dom = new DOMDocument; |
|
| 49 | + $dom = new DOMDocument; |
|
| 50 | 50 | $success = $dom->loadXML( file_get_contents( $file ) ); |
| 51 | 51 | if ( ! $success ) { |
| 52 | 52 | return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() ); |
@@ -64,45 +64,45 @@ discard block |
||
| 64 | 64 | return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() ); |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order |
|
| 67 | + // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order |
|
| 68 | 68 | foreach ( array( 'term', 'form', 'view' ) as $item_type ) { |
| 69 | - // grab cats, tags, and terms, or forms or posts |
|
| 70 | - if ( isset($xml->{$item_type} ) ) { |
|
| 69 | + // grab cats, tags, and terms, or forms or posts |
|
| 70 | + if ( isset($xml->{$item_type} ) ) { |
|
| 71 | 71 | $function_name = 'import_xml_' . $item_type . 's'; |
| 72 | 72 | $imported = self::$function_name( $xml->{$item_type}, $imported ); |
| 73 | 73 | unset( $function_name, $xml->{$item_type} ); |
| 74 | - } |
|
| 75 | - } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - $return = apply_filters('frm_importing_xml', $imported, $xml ); |
|
| 77 | + $return = apply_filters('frm_importing_xml', $imported, $xml ); |
|
| 78 | 78 | |
| 79 | - return $return; |
|
| 80 | - } |
|
| 79 | + return $return; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | public static function import_xml_terms( $terms, $imported ) { |
| 83 | - foreach ( $terms as $t ) { |
|
| 83 | + foreach ( $terms as $t ) { |
|
| 84 | 84 | if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) { |
| 85 | - continue; |
|
| 85 | + continue; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $parent = self::get_term_parent_id( $t ); |
| 89 | 89 | |
| 90 | 90 | $term = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array( |
| 91 | - 'slug' => (string) $t->term_slug, |
|
| 92 | - 'description' => (string) $t->term_description, |
|
| 91 | + 'slug' => (string) $t->term_slug, |
|
| 92 | + 'description' => (string) $t->term_description, |
|
| 93 | 93 | 'parent' => empty( $parent ) ? 0 : $parent, |
| 94 | - )); |
|
| 94 | + )); |
|
| 95 | 95 | |
| 96 | 96 | if ( $term && is_array( $term ) ) { |
| 97 | - $imported['imported']['terms']++; |
|
| 97 | + $imported['imported']['terms']++; |
|
| 98 | 98 | $imported['terms'][ (int) $t->term_id ] = $term['term_id']; |
| 99 | - } |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | unset( $term, $t ); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | return $imported; |
| 105 | - } |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | 108 | * @since 2.0.8 |
@@ -127,99 +127,99 @@ discard block |
||
| 127 | 127 | self::put_child_forms_first( $forms ); |
| 128 | 128 | |
| 129 | 129 | foreach ( $forms as $item ) { |
| 130 | - $form = array( |
|
| 131 | - 'id' => (int) $item->id, |
|
| 132 | - 'form_key' => (string) $item->form_key, |
|
| 133 | - 'name' => (string) $item->name, |
|
| 134 | - 'description' => (string) $item->description, |
|
| 135 | - 'options' => (string) $item->options, |
|
| 136 | - 'logged_in' => (int) $item->logged_in, |
|
| 137 | - 'is_template' => (int) $item->is_template, |
|
| 138 | - 'default_template' => (int) $item->default_template, |
|
| 139 | - 'editable' => (int) $item->editable, |
|
| 140 | - 'status' => (string) $item->status, |
|
| 141 | - 'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0, |
|
| 142 | - 'created_at' => date( 'Y-m-d H:i:s', strtotime( (string) $item->created_at ) ), |
|
| 143 | - ); |
|
| 144 | - |
|
| 145 | - $form['options'] = FrmAppHelper::maybe_json_decode($form['options']); |
|
| 130 | + $form = array( |
|
| 131 | + 'id' => (int) $item->id, |
|
| 132 | + 'form_key' => (string) $item->form_key, |
|
| 133 | + 'name' => (string) $item->name, |
|
| 134 | + 'description' => (string) $item->description, |
|
| 135 | + 'options' => (string) $item->options, |
|
| 136 | + 'logged_in' => (int) $item->logged_in, |
|
| 137 | + 'is_template' => (int) $item->is_template, |
|
| 138 | + 'default_template' => (int) $item->default_template, |
|
| 139 | + 'editable' => (int) $item->editable, |
|
| 140 | + 'status' => (string) $item->status, |
|
| 141 | + 'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0, |
|
| 142 | + 'created_at' => date( 'Y-m-d H:i:s', strtotime( (string) $item->created_at ) ), |
|
| 143 | + ); |
|
| 144 | + |
|
| 145 | + $form['options'] = FrmAppHelper::maybe_json_decode($form['options']); |
|
| 146 | 146 | |
| 147 | 147 | self::update_custom_style_setting_on_import( $form ); |
| 148 | 148 | |
| 149 | - // if template, allow to edit if form keys match, otherwise, creation date must also match |
|
| 149 | + // if template, allow to edit if form keys match, otherwise, creation date must also match |
|
| 150 | 150 | $edit_query = array( 'form_key' => $form['form_key'], 'is_template' => $form['is_template'] ); |
| 151 | - if ( ! $form['is_template'] ) { |
|
| 152 | - $edit_query['created_at'] = $form['created_at']; |
|
| 153 | - } |
|
| 151 | + if ( ! $form['is_template'] ) { |
|
| 152 | + $edit_query['created_at'] = $form['created_at']; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form); |
|
| 155 | + $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form); |
|
| 156 | 156 | |
| 157 | - $this_form = FrmForm::getAll($edit_query, '', 1); |
|
| 158 | - unset($edit_query); |
|
| 157 | + $this_form = FrmForm::getAll($edit_query, '', 1); |
|
| 158 | + unset($edit_query); |
|
| 159 | 159 | |
| 160 | - if ( ! empty( $this_form ) ) { |
|
| 161 | - $old_id = $form_id = $this_form->id; |
|
| 162 | - FrmForm::update($form_id, $form ); |
|
| 163 | - $imported['updated']['forms']++; |
|
| 164 | - // Keep track of whether this specific form was updated or not |
|
| 160 | + if ( ! empty( $this_form ) ) { |
|
| 161 | + $old_id = $form_id = $this_form->id; |
|
| 162 | + FrmForm::update($form_id, $form ); |
|
| 163 | + $imported['updated']['forms']++; |
|
| 164 | + // Keep track of whether this specific form was updated or not |
|
| 165 | 165 | $imported['form_status'][ $form_id ] = 'updated'; |
| 166 | 166 | |
| 167 | 167 | $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' ); |
| 168 | - $old_fields = array(); |
|
| 169 | - foreach ( $form_fields as $f ) { |
|
| 168 | + $old_fields = array(); |
|
| 169 | + foreach ( $form_fields as $f ) { |
|
| 170 | 170 | $old_fields[ $f->id ] = $f; |
| 171 | 171 | $old_fields[ $f->field_key ] = $f->id; |
| 172 | - unset($f); |
|
| 173 | - } |
|
| 174 | - $form_fields = $old_fields; |
|
| 175 | - unset($old_fields); |
|
| 176 | - } else { |
|
| 177 | - $old_id = false; |
|
| 178 | - //form does not exist, so create it |
|
| 172 | + unset($f); |
|
| 173 | + } |
|
| 174 | + $form_fields = $old_fields; |
|
| 175 | + unset($old_fields); |
|
| 176 | + } else { |
|
| 177 | + $old_id = false; |
|
| 178 | + //form does not exist, so create it |
|
| 179 | 179 | $form_id = FrmForm::create( $form ); |
| 180 | - if ( $form_id ) { |
|
| 181 | - $imported['imported']['forms']++; |
|
| 182 | - // Keep track of whether this specific form was updated or not |
|
| 180 | + if ( $form_id ) { |
|
| 181 | + $imported['imported']['forms']++; |
|
| 182 | + // Keep track of whether this specific form was updated or not |
|
| 183 | 183 | $imported['form_status'][ $form_id ] = 'imported'; |
| 184 | 184 | self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms ); |
| 185 | - } |
|
| 186 | - } |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - self::import_xml_fields( $item->field, $form_id, $this_form, $form_fields, $imported ); |
|
| 188 | + self::import_xml_fields( $item->field, $form_id, $this_form, $form_fields, $imported ); |
|
| 189 | 189 | |
| 190 | - // Delete any fields attached to this form that were not included in the template |
|
| 191 | - if ( isset( $form_fields ) && ! empty( $form_fields ) ) { |
|
| 190 | + // Delete any fields attached to this form that were not included in the template |
|
| 191 | + if ( isset( $form_fields ) && ! empty( $form_fields ) ) { |
|
| 192 | 192 | foreach ( $form_fields as $field ) { |
| 193 | - if ( is_object($field) ) { |
|
| 194 | - FrmField::destroy($field->id); |
|
| 195 | - } |
|
| 196 | - unset($field); |
|
| 197 | - } |
|
| 198 | - unset($form_fields); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // Update field ids/keys to new ones |
|
| 193 | + if ( is_object($field) ) { |
|
| 194 | + FrmField::destroy($field->id); |
|
| 195 | + } |
|
| 196 | + unset($field); |
|
| 197 | + } |
|
| 198 | + unset($form_fields); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // Update field ids/keys to new ones |
|
| 202 | 202 | do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) ); |
| 203 | 203 | |
| 204 | 204 | $imported['forms'][ (int) $item->id ] = $form_id; |
| 205 | 205 | |
| 206 | - // Send pre 2.0 form options through function that creates actions |
|
| 207 | - self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true ); |
|
| 206 | + // Send pre 2.0 form options through function that creates actions |
|
| 207 | + self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true ); |
|
| 208 | 208 | |
| 209 | - unset($form, $item); |
|
| 209 | + unset($form, $item); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms ); |
| 213 | 213 | |
| 214 | 214 | return $imported; |
| 215 | - } |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | 217 | /** |
| 218 | - * Put child forms first so they will be imported before parents |
|
| 219 | - * |
|
| 220 | - * @since 2.0.16 |
|
| 221 | - * @param array $forms |
|
| 222 | - */ |
|
| 218 | + * Put child forms first so they will be imported before parents |
|
| 219 | + * |
|
| 220 | + * @since 2.0.16 |
|
| 221 | + * @param array $forms |
|
| 222 | + */ |
|
| 223 | 223 | private static function put_child_forms_first( &$forms ) { |
| 224 | 224 | $child_forms = array(); |
| 225 | 225 | $regular_forms = array(); |
@@ -238,13 +238,13 @@ discard block |
||
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
| 241 | - * Keep track of all imported child forms |
|
| 242 | - * |
|
| 243 | - * @since 2.0.16 |
|
| 244 | - * @param int $form_id |
|
| 245 | - * @param int $parent_form_id |
|
| 246 | - * @param array $child_forms |
|
| 247 | - */ |
|
| 241 | + * Keep track of all imported child forms |
|
| 242 | + * |
|
| 243 | + * @since 2.0.16 |
|
| 244 | + * @param int $form_id |
|
| 245 | + * @param int $parent_form_id |
|
| 246 | + * @param array $child_forms |
|
| 247 | + */ |
|
| 248 | 248 | private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) { |
| 249 | 249 | if ( $parent_form_id ) { |
| 250 | 250 | $child_forms[ $form_id ] = $parent_form_id; |
@@ -252,13 +252,13 @@ discard block |
||
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
| 255 | - * Update the parent_form_id on imported child forms |
|
| 256 | - * Child forms are imported first so their parent_form_id will need to be updated after the parent is imported |
|
| 257 | - * |
|
| 258 | - * @since 2.0.6 |
|
| 259 | - * @param array $imported_forms |
|
| 260 | - * @param array $child_forms |
|
| 261 | - */ |
|
| 255 | + * Update the parent_form_id on imported child forms |
|
| 256 | + * Child forms are imported first so their parent_form_id will need to be updated after the parent is imported |
|
| 257 | + * |
|
| 258 | + * @since 2.0.6 |
|
| 259 | + * @param array $imported_forms |
|
| 260 | + * @param array $child_forms |
|
| 261 | + */ |
|
| 262 | 262 | private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) { |
| 263 | 263 | foreach ( $child_forms as $child_form_id => $old_parent_form_id ) { |
| 264 | 264 | |
@@ -272,40 +272,40 @@ discard block |
||
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
| 275 | - * Import all fields for a form |
|
| 276 | - * @since 2.0.13 |
|
| 277 | - * |
|
| 278 | - * TODO: Cut down on params |
|
| 279 | - */ |
|
| 275 | + * Import all fields for a form |
|
| 276 | + * @since 2.0.13 |
|
| 277 | + * |
|
| 278 | + * TODO: Cut down on params |
|
| 279 | + */ |
|
| 280 | 280 | private static function import_xml_fields( $xml_fields, $form_id, $this_form, &$form_fields, &$imported ) { |
| 281 | 281 | $in_section = 0; |
| 282 | 282 | |
| 283 | 283 | foreach ( $xml_fields as $field ) { |
| 284 | - $f = array( |
|
| 285 | - 'id' => (int) $field->id, |
|
| 286 | - 'field_key' => (string) $field->field_key, |
|
| 287 | - 'name' => (string) $field->name, |
|
| 288 | - 'description' => (string) $field->description, |
|
| 289 | - 'type' => (string) $field->type, |
|
| 290 | - 'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value), |
|
| 291 | - 'field_order' => (int) $field->field_order, |
|
| 292 | - 'form_id' => (int) $form_id, |
|
| 293 | - 'required' => (int) $field->required, |
|
| 294 | - 'options' => FrmAppHelper::maybe_json_decode( (string) $field->options), |
|
| 284 | + $f = array( |
|
| 285 | + 'id' => (int) $field->id, |
|
| 286 | + 'field_key' => (string) $field->field_key, |
|
| 287 | + 'name' => (string) $field->name, |
|
| 288 | + 'description' => (string) $field->description, |
|
| 289 | + 'type' => (string) $field->type, |
|
| 290 | + 'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value), |
|
| 291 | + 'field_order' => (int) $field->field_order, |
|
| 292 | + 'form_id' => (int) $form_id, |
|
| 293 | + 'required' => (int) $field->required, |
|
| 294 | + 'options' => FrmAppHelper::maybe_json_decode( (string) $field->options), |
|
| 295 | 295 | 'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ), |
| 296 | - ); |
|
| 297 | - |
|
| 298 | - if ( is_array($f['default_value']) && in_array($f['type'], array( |
|
| 299 | - 'text', 'email', 'url', 'textarea', |
|
| 300 | - 'number','phone', 'date', 'time', |
|
| 301 | - 'hidden', 'password', 'tag', 'image', |
|
| 302 | - )) ) { |
|
| 303 | - if ( count($f['default_value']) === 1 ) { |
|
| 296 | + ); |
|
| 297 | + |
|
| 298 | + if ( is_array($f['default_value']) && in_array($f['type'], array( |
|
| 299 | + 'text', 'email', 'url', 'textarea', |
|
| 300 | + 'number','phone', 'date', 'time', |
|
| 301 | + 'hidden', 'password', 'tag', 'image', |
|
| 302 | + )) ) { |
|
| 303 | + if ( count($f['default_value']) === 1 ) { |
|
| 304 | 304 | $f['default_value'] = '[' . reset( $f['default_value'] ) . ']'; |
| 305 | - } else { |
|
| 306 | - $f['default_value'] = reset($f['default_value']); |
|
| 307 | - } |
|
| 308 | - } |
|
| 305 | + } else { |
|
| 306 | + $f['default_value'] = reset($f['default_value']); |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | 310 | self::maybe_update_in_section_variable( $in_section, $f ); |
| 311 | 311 | self::maybe_update_form_select( $f, $imported ); |
@@ -368,12 +368,12 @@ discard block |
||
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
| 371 | - * Switch the form_select on a repeating field or embedded form if it needs to be switched |
|
| 372 | - * |
|
| 373 | - * @since 2.0.16 |
|
| 374 | - * @param array $f |
|
| 375 | - * @param array $imported |
|
| 376 | - */ |
|
| 371 | + * Switch the form_select on a repeating field or embedded form if it needs to be switched |
|
| 372 | + * |
|
| 373 | + * @since 2.0.16 |
|
| 374 | + * @param array $f |
|
| 375 | + * @param array $imported |
|
| 376 | + */ |
|
| 377 | 377 | private static function maybe_update_form_select( &$f, $imported ) { |
| 378 | 378 | if ( ! isset( $imported['forms'] ) ) { |
| 379 | 379 | return; |
@@ -425,13 +425,13 @@ discard block |
||
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | /** |
| 428 | - * Updates the custom style setting on import |
|
| 429 | - * Convert the post slug to an ID |
|
| 430 | - * |
|
| 431 | - * @since 2.0.19 |
|
| 432 | - * @param array $form |
|
| 433 | - * |
|
| 434 | - */ |
|
| 428 | + * Updates the custom style setting on import |
|
| 429 | + * Convert the post slug to an ID |
|
| 430 | + * |
|
| 431 | + * @since 2.0.19 |
|
| 432 | + * @param array $form |
|
| 433 | + * |
|
| 434 | + */ |
|
| 435 | 435 | private static function update_custom_style_setting_on_import( &$form ) { |
| 436 | 436 | if ( ! isset( $form['options']['custom_style'] ) ) { |
| 437 | 437 | return; |
@@ -485,16 +485,16 @@ discard block |
||
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | public static function import_xml_views( $views, $imported ) { |
| 488 | - $imported['posts'] = array(); |
|
| 489 | - $form_action_type = FrmFormActionsController::$action_post_type; |
|
| 488 | + $imported['posts'] = array(); |
|
| 489 | + $form_action_type = FrmFormActionsController::$action_post_type; |
|
| 490 | 490 | |
| 491 | - $post_types = array( |
|
| 492 | - 'frm_display' => 'views', |
|
| 493 | - $form_action_type => 'actions', |
|
| 494 | - 'frm_styles' => 'styles', |
|
| 495 | - ); |
|
| 491 | + $post_types = array( |
|
| 492 | + 'frm_display' => 'views', |
|
| 493 | + $form_action_type => 'actions', |
|
| 494 | + 'frm_styles' => 'styles', |
|
| 495 | + ); |
|
| 496 | 496 | |
| 497 | - foreach ( $views as $item ) { |
|
| 497 | + foreach ( $views as $item ) { |
|
| 498 | 498 | $post = array( |
| 499 | 499 | 'post_title' => (string) $item->title, |
| 500 | 500 | 'post_name' => (string) $item->post_name, |
@@ -513,52 +513,52 @@ discard block |
||
| 513 | 513 | 'post_date' => (string) $item->post_date, |
| 514 | 514 | 'post_date_gmt' => (string) $item->post_date_gmt, |
| 515 | 515 | 'ping_status' => (string) $item->ping_status, |
| 516 | - 'postmeta' => array(), |
|
| 517 | - 'tax_input' => array(), |
|
| 516 | + 'postmeta' => array(), |
|
| 517 | + 'tax_input' => array(), |
|
| 518 | 518 | ); |
| 519 | 519 | |
| 520 | - $old_id = $post['post_id']; |
|
| 521 | - self::populate_post($post, $item, $imported); |
|
| 520 | + $old_id = $post['post_id']; |
|
| 521 | + self::populate_post($post, $item, $imported); |
|
| 522 | 522 | |
| 523 | 523 | unset($item); |
| 524 | 524 | |
| 525 | 525 | $post_id = false; |
| 526 | - if ( $post['post_type'] == $form_action_type ) { |
|
| 527 | - $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] ); |
|
| 526 | + if ( $post['post_type'] == $form_action_type ) { |
|
| 527 | + $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] ); |
|
| 528 | 528 | if ( $action_control && is_object( $action_control ) ) { |
| 529 | 529 | $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] ); |
| 530 | 530 | } |
| 531 | - unset($action_control); |
|
| 532 | - } else if ( $post['post_type'] == 'frm_styles' ) { |
|
| 533 | - // Properly encode post content before inserting the post |
|
| 534 | - $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
|
| 535 | - $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] ); |
|
| 536 | - |
|
| 537 | - // Create/update post now |
|
| 538 | - $post_id = wp_insert_post( $post ); |
|
| 539 | - } else { |
|
| 540 | - // Create/update post now |
|
| 541 | - $post_id = wp_insert_post( $post ); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - if ( ! is_numeric($post_id) ) { |
|
| 545 | - continue; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - self::update_postmeta($post, $post_id); |
|
| 549 | - |
|
| 550 | - $this_type = 'posts'; |
|
| 531 | + unset($action_control); |
|
| 532 | + } else if ( $post['post_type'] == 'frm_styles' ) { |
|
| 533 | + // Properly encode post content before inserting the post |
|
| 534 | + $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
|
| 535 | + $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] ); |
|
| 536 | + |
|
| 537 | + // Create/update post now |
|
| 538 | + $post_id = wp_insert_post( $post ); |
|
| 539 | + } else { |
|
| 540 | + // Create/update post now |
|
| 541 | + $post_id = wp_insert_post( $post ); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + if ( ! is_numeric($post_id) ) { |
|
| 545 | + continue; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + self::update_postmeta($post, $post_id); |
|
| 549 | + |
|
| 550 | + $this_type = 'posts'; |
|
| 551 | 551 | if ( isset( $post_types[ $post['post_type'] ] ) ) { |
| 552 | 552 | $this_type = $post_types[ $post['post_type'] ]; |
| 553 | - } |
|
| 553 | + } |
|
| 554 | 554 | |
| 555 | - if ( isset($post['ID']) && $post_id == $post['ID'] ) { |
|
| 556 | - $imported['updated'][ $this_type ]++; |
|
| 557 | - } else { |
|
| 558 | - $imported['imported'][ $this_type ]++; |
|
| 559 | - } |
|
| 555 | + if ( isset($post['ID']) && $post_id == $post['ID'] ) { |
|
| 556 | + $imported['updated'][ $this_type ]++; |
|
| 557 | + } else { |
|
| 558 | + $imported['imported'][ $this_type ]++; |
|
| 559 | + } |
|
| 560 | 560 | |
| 561 | - unset($post); |
|
| 561 | + unset($post); |
|
| 562 | 562 | |
| 563 | 563 | $imported['posts'][ (int) $old_id ] = $post_id; |
| 564 | 564 | } |
@@ -566,16 +566,16 @@ discard block |
||
| 566 | 566 | self::maybe_update_stylesheet( $imported ); |
| 567 | 567 | |
| 568 | 568 | return $imported; |
| 569 | - } |
|
| 569 | + } |
|
| 570 | 570 | |
| 571 | - private static function populate_post( &$post, $item, $imported ) { |
|
| 571 | + private static function populate_post( &$post, $item, $imported ) { |
|
| 572 | 572 | if ( isset($item->attachment_url) ) { |
| 573 | 573 | $post['attachment_url'] = (string) $item->attachment_url; |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) { |
| 577 | - // update to new form id |
|
| 578 | - $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ]; |
|
| 577 | + // update to new form id |
|
| 578 | + $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ]; |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | // Don't allow default styles to take over a site's default style |
@@ -584,144 +584,144 @@ discard block |
||
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | foreach ( $item->postmeta as $meta ) { |
| 587 | - self::populate_postmeta($post, $meta, $imported); |
|
| 587 | + self::populate_postmeta($post, $meta, $imported); |
|
| 588 | 588 | unset($meta); |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - self::populate_taxonomies($post, $item); |
|
| 591 | + self::populate_taxonomies($post, $item); |
|
| 592 | 592 | |
| 593 | - self::maybe_editing_post($post); |
|
| 594 | - } |
|
| 593 | + self::maybe_editing_post($post); |
|
| 594 | + } |
|
| 595 | 595 | |
| 596 | - private static function populate_postmeta( &$post, $meta, $imported ) { |
|
| 597 | - global $frm_duplicate_ids; |
|
| 596 | + private static function populate_postmeta( &$post, $meta, $imported ) { |
|
| 597 | + global $frm_duplicate_ids; |
|
| 598 | 598 | |
| 599 | - $m = array( |
|
| 599 | + $m = array( |
|
| 600 | 600 | 'key' => (string) $meta->meta_key, |
| 601 | 601 | 'value' => (string) $meta->meta_value, |
| 602 | 602 | ); |
| 603 | 603 | |
| 604 | 604 | //switch old form and field ids to new ones |
| 605 | 605 | if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) { |
| 606 | - $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
|
| 606 | + $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
|
| 607 | 607 | } else { |
| 608 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
| 608 | + $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
| 609 | 609 | |
| 610 | - if ( ! empty($frm_duplicate_ids) ) { |
|
| 610 | + if ( ! empty($frm_duplicate_ids) ) { |
|
| 611 | 611 | |
| 612 | - if ( $m['key'] == 'frm_dyncontent' ) { |
|
| 613 | - $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); |
|
| 614 | - } else if ( $m['key'] == 'frm_options' ) { |
|
| 612 | + if ( $m['key'] == 'frm_dyncontent' ) { |
|
| 613 | + $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); |
|
| 614 | + } else if ( $m['key'] == 'frm_options' ) { |
|
| 615 | 615 | |
| 616 | 616 | foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) { |
| 617 | 617 | if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) { |
| 618 | 618 | $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ]; |
| 619 | - } |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - $check_dup_array = array(); |
|
| 623 | - if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { |
|
| 624 | - if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
|
| 625 | - $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
|
| 626 | - } else if ( is_array( $m['value']['order_by'] ) ) { |
|
| 627 | - $check_dup_array[] = 'order_by'; |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) { |
|
| 632 | - $check_dup_array[] = 'where'; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - foreach ( $check_dup_array as $check_k ) { |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + $check_dup_array = array(); |
|
| 623 | + if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { |
|
| 624 | + if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
|
| 625 | + $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
|
| 626 | + } else if ( is_array( $m['value']['order_by'] ) ) { |
|
| 627 | + $check_dup_array[] = 'order_by'; |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) { |
|
| 632 | + $check_dup_array[] = 'where'; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + foreach ( $check_dup_array as $check_k ) { |
|
| 636 | 636 | foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) { |
| 637 | 637 | if ( isset( $frm_duplicate_ids[ $mv ] ) ) { |
| 638 | 638 | $m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ]; |
| 639 | - } |
|
| 640 | - unset($mk, $mv); |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - } |
|
| 644 | - } |
|
| 639 | + } |
|
| 640 | + unset($mk, $mv); |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | if ( ! is_array($m['value']) ) { |
| 648 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
| 648 | + $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | $post['postmeta'][ (string) $meta->meta_key ] = $m['value']; |
| 652 | - } |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Add terms to post |
|
| 656 | - * @param array $post by reference |
|
| 657 | - * @param object $item The XML object data |
|
| 658 | - */ |
|
| 659 | - private static function populate_taxonomies( &$post, $item ) { |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Add terms to post |
|
| 656 | + * @param array $post by reference |
|
| 657 | + * @param object $item The XML object data |
|
| 658 | + */ |
|
| 659 | + private static function populate_taxonomies( &$post, $item ) { |
|
| 660 | 660 | foreach ( $item->category as $c ) { |
| 661 | 661 | $att = $c->attributes(); |
| 662 | 662 | if ( ! isset( $att['nicename'] ) ) { |
| 663 | - continue; |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - $taxonomy = (string) $att['domain']; |
|
| 667 | - if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
| 668 | - $name = (string) $att['nicename']; |
|
| 669 | - $h_term = get_term_by('slug', $name, $taxonomy); |
|
| 670 | - if ( $h_term ) { |
|
| 671 | - $name = $h_term->term_id; |
|
| 672 | - } |
|
| 673 | - unset($h_term); |
|
| 674 | - } else { |
|
| 675 | - $name = (string) $c; |
|
| 676 | - } |
|
| 663 | + continue; |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + $taxonomy = (string) $att['domain']; |
|
| 667 | + if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
| 668 | + $name = (string) $att['nicename']; |
|
| 669 | + $h_term = get_term_by('slug', $name, $taxonomy); |
|
| 670 | + if ( $h_term ) { |
|
| 671 | + $name = $h_term->term_id; |
|
| 672 | + } |
|
| 673 | + unset($h_term); |
|
| 674 | + } else { |
|
| 675 | + $name = (string) $c; |
|
| 676 | + } |
|
| 677 | 677 | |
| 678 | 678 | if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) { |
| 679 | 679 | $post['tax_input'][ $taxonomy ] = array(); |
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | $post['tax_input'][ $taxonomy ][] = $name; |
| 683 | - unset($name); |
|
| 683 | + unset($name); |
|
| 684 | 684 | } |
| 685 | - } |
|
| 685 | + } |
|
| 686 | 686 | |
| 687 | - /** |
|
| 688 | - * Edit post if the key and created time match |
|
| 689 | - */ |
|
| 690 | - private static function maybe_editing_post( &$post ) { |
|
| 687 | + /** |
|
| 688 | + * Edit post if the key and created time match |
|
| 689 | + */ |
|
| 690 | + private static function maybe_editing_post( &$post ) { |
|
| 691 | 691 | $match_by = array( |
| 692 | - 'post_type' => $post['post_type'], |
|
| 693 | - 'name' => $post['post_name'], |
|
| 694 | - 'post_status' => $post['post_status'], |
|
| 695 | - 'posts_per_page' => 1, |
|
| 692 | + 'post_type' => $post['post_type'], |
|
| 693 | + 'name' => $post['post_name'], |
|
| 694 | + 'post_status' => $post['post_status'], |
|
| 695 | + 'posts_per_page' => 1, |
|
| 696 | 696 | ); |
| 697 | 697 | |
| 698 | 698 | if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) { |
| 699 | - $match_by['include'] = $post['post_id']; |
|
| 700 | - unset($match_by['name']); |
|
| 699 | + $match_by['include'] = $post['post_id']; |
|
| 700 | + unset($match_by['name']); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | $editing = get_posts($match_by); |
| 704 | 704 | |
| 705 | - if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) { |
|
| 706 | - // set the id of the post to edit |
|
| 707 | - $post['ID'] = current($editing)->ID; |
|
| 708 | - } |
|
| 709 | - } |
|
| 705 | + if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) { |
|
| 706 | + // set the id of the post to edit |
|
| 707 | + $post['ID'] = current($editing)->ID; |
|
| 708 | + } |
|
| 709 | + } |
|
| 710 | 710 | |
| 711 | - private static function update_postmeta( &$post, $post_id ) { |
|
| 712 | - foreach ( $post['postmeta'] as $k => $v ) { |
|
| 713 | - if ( '_edit_last' == $k ) { |
|
| 714 | - $v = FrmAppHelper::get_user_id_param($v); |
|
| 715 | - } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) { |
|
| 716 | - //change the attachment ID |
|
| 717 | - $v = FrmProXMLHelper::get_file_id($v); |
|
| 718 | - } |
|
| 711 | + private static function update_postmeta( &$post, $post_id ) { |
|
| 712 | + foreach ( $post['postmeta'] as $k => $v ) { |
|
| 713 | + if ( '_edit_last' == $k ) { |
|
| 714 | + $v = FrmAppHelper::get_user_id_param($v); |
|
| 715 | + } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) { |
|
| 716 | + //change the attachment ID |
|
| 717 | + $v = FrmProXMLHelper::get_file_id($v); |
|
| 718 | + } |
|
| 719 | 719 | |
| 720 | - update_post_meta($post_id, $k, $v); |
|
| 720 | + update_post_meta($post_id, $k, $v); |
|
| 721 | 721 | |
| 722 | - unset($k, $v); |
|
| 723 | - } |
|
| 724 | - } |
|
| 722 | + unset($k, $v); |
|
| 723 | + } |
|
| 724 | + } |
|
| 725 | 725 | |
| 726 | 726 | private static function maybe_update_stylesheet( $imported ) { |
| 727 | 727 | $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] ); |
@@ -737,72 +737,72 @@ discard block |
||
| 737 | 737 | } |
| 738 | 738 | } |
| 739 | 739 | |
| 740 | - /** |
|
| 741 | - * @param string $message |
|
| 742 | - */ |
|
| 740 | + /** |
|
| 741 | + * @param string $message |
|
| 742 | + */ |
|
| 743 | 743 | public static function parse_message( $result, &$message, &$errors ) { |
| 744 | - if ( is_wp_error($result) ) { |
|
| 745 | - $errors[] = $result->get_error_message(); |
|
| 746 | - } else if ( ! $result ) { |
|
| 747 | - return; |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - if ( ! is_array($result) ) { |
|
| 751 | - $message = is_string( $result ) ? $result : print_r( $result, 1 ); |
|
| 752 | - return; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - $t_strings = array( |
|
| 756 | - 'imported' => __( 'Imported', 'formidable' ), |
|
| 757 | - 'updated' => __( 'Updated', 'formidable' ), |
|
| 758 | - ); |
|
| 759 | - |
|
| 760 | - $message = '<ul>'; |
|
| 761 | - foreach ( $result as $type => $results ) { |
|
| 744 | + if ( is_wp_error($result) ) { |
|
| 745 | + $errors[] = $result->get_error_message(); |
|
| 746 | + } else if ( ! $result ) { |
|
| 747 | + return; |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + if ( ! is_array($result) ) { |
|
| 751 | + $message = is_string( $result ) ? $result : print_r( $result, 1 ); |
|
| 752 | + return; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + $t_strings = array( |
|
| 756 | + 'imported' => __( 'Imported', 'formidable' ), |
|
| 757 | + 'updated' => __( 'Updated', 'formidable' ), |
|
| 758 | + ); |
|
| 759 | + |
|
| 760 | + $message = '<ul>'; |
|
| 761 | + foreach ( $result as $type => $results ) { |
|
| 762 | 762 | if ( ! isset( $t_strings[ $type ] ) ) { |
| 763 | - // only print imported and updated |
|
| 764 | - continue; |
|
| 765 | - } |
|
| 763 | + // only print imported and updated |
|
| 764 | + continue; |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | - $s_message = array(); |
|
| 768 | - foreach ( $results as $k => $m ) { |
|
| 769 | - self::item_count_message($m, $k, $s_message); |
|
| 770 | - unset($k, $m); |
|
| 771 | - } |
|
| 767 | + $s_message = array(); |
|
| 768 | + foreach ( $results as $k => $m ) { |
|
| 769 | + self::item_count_message($m, $k, $s_message); |
|
| 770 | + unset($k, $m); |
|
| 771 | + } |
|
| 772 | 772 | |
| 773 | - if ( ! empty($s_message) ) { |
|
| 773 | + if ( ! empty($s_message) ) { |
|
| 774 | 774 | $message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> '; |
| 775 | - $message .= implode(', ', $s_message); |
|
| 776 | - $message .= '</li>'; |
|
| 777 | - } |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - if ( $message == '<ul>' ) { |
|
| 781 | - $message = ''; |
|
| 782 | - $errors[] = __( 'Nothing was imported or updated', 'formidable' ); |
|
| 783 | - } else { |
|
| 784 | - $message .= '</ul>'; |
|
| 785 | - } |
|
| 786 | - } |
|
| 775 | + $message .= implode(', ', $s_message); |
|
| 776 | + $message .= '</li>'; |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + if ( $message == '<ul>' ) { |
|
| 781 | + $message = ''; |
|
| 782 | + $errors[] = __( 'Nothing was imported or updated', 'formidable' ); |
|
| 783 | + } else { |
|
| 784 | + $message .= '</ul>'; |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | 787 | |
| 788 | 788 | public static function item_count_message( $m, $type, &$s_message ) { |
| 789 | - if ( ! $m ) { |
|
| 790 | - return; |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - $strings = array( |
|
| 794 | - 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ), |
|
| 795 | - 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ), |
|
| 796 | - 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ), |
|
| 797 | - 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ), |
|
| 798 | - 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ), |
|
| 799 | - 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ), |
|
| 800 | - 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ), |
|
| 801 | - 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ), |
|
| 802 | - ); |
|
| 789 | + if ( ! $m ) { |
|
| 790 | + return; |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + $strings = array( |
|
| 794 | + 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ), |
|
| 795 | + 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ), |
|
| 796 | + 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ), |
|
| 797 | + 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ), |
|
| 798 | + 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ), |
|
| 799 | + 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ), |
|
| 800 | + 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ), |
|
| 801 | + 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ), |
|
| 802 | + ); |
|
| 803 | 803 | |
| 804 | 804 | $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type ); |
| 805 | - } |
|
| 805 | + } |
|
| 806 | 806 | |
| 807 | 807 | /** |
| 808 | 808 | * Prepare the form options for export |
@@ -833,16 +833,16 @@ discard block |
||
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | public static function cdata( $str ) { |
| 836 | - $str = maybe_unserialize($str); |
|
| 837 | - if ( is_array($str) ) { |
|
| 838 | - $str = json_encode($str); |
|
| 836 | + $str = maybe_unserialize($str); |
|
| 837 | + if ( is_array($str) ) { |
|
| 838 | + $str = json_encode($str); |
|
| 839 | 839 | } else if ( seems_utf8( $str ) == false ) { |
| 840 | 840 | $str = utf8_encode( $str ); |
| 841 | 841 | } |
| 842 | 842 | |
| 843 | - if ( is_numeric($str) ) { |
|
| 844 | - return $str; |
|
| 845 | - } |
|
| 843 | + if ( is_numeric($str) ) { |
|
| 844 | + return $str; |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | 847 | self::remove_invalid_characters_from_xml( $str ); |
| 848 | 848 | |
@@ -863,58 +863,58 @@ discard block |
||
| 863 | 863 | $str = str_replace( '\x1F', '', $str ); |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | - public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) { |
|
| 867 | - // Get post type |
|
| 868 | - $post_type = FrmFormActionsController::$action_post_type; |
|
| 869 | - |
|
| 870 | - // Set up imported index, if not set up yet |
|
| 871 | - if ( ! isset( $imported['imported']['actions'] ) ) { |
|
| 872 | - $imported['imported']['actions'] = 0; |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - // Migrate post settings to action |
|
| 876 | - self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
| 877 | - |
|
| 878 | - // Migrate email settings to action |
|
| 879 | - self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - /** |
|
| 883 | - * Migrate post settings to form action |
|
| 884 | - * |
|
| 885 | - * @param string $post_type |
|
| 886 | - */ |
|
| 887 | - private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
| 888 | - if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) { |
|
| 889 | - return; |
|
| 890 | - } |
|
| 891 | - |
|
| 892 | - $new_action = array( |
|
| 893 | - 'post_type' => $post_type, |
|
| 894 | - 'post_excerpt' => 'wppost', |
|
| 866 | + public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) { |
|
| 867 | + // Get post type |
|
| 868 | + $post_type = FrmFormActionsController::$action_post_type; |
|
| 869 | + |
|
| 870 | + // Set up imported index, if not set up yet |
|
| 871 | + if ( ! isset( $imported['imported']['actions'] ) ) { |
|
| 872 | + $imported['imported']['actions'] = 0; |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + // Migrate post settings to action |
|
| 876 | + self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
| 877 | + |
|
| 878 | + // Migrate email settings to action |
|
| 879 | + self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + /** |
|
| 883 | + * Migrate post settings to form action |
|
| 884 | + * |
|
| 885 | + * @param string $post_type |
|
| 886 | + */ |
|
| 887 | + private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
| 888 | + if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) { |
|
| 889 | + return; |
|
| 890 | + } |
|
| 891 | + |
|
| 892 | + $new_action = array( |
|
| 893 | + 'post_type' => $post_type, |
|
| 894 | + 'post_excerpt' => 'wppost', |
|
| 895 | 895 | 'post_title' => __( 'Create Posts', 'formidable' ), |
| 896 | - 'menu_order' => $form_id, |
|
| 897 | - 'post_status' => 'publish', |
|
| 898 | - 'post_content' => array(), |
|
| 896 | + 'menu_order' => $form_id, |
|
| 897 | + 'post_status' => 'publish', |
|
| 898 | + 'post_content' => array(), |
|
| 899 | 899 | 'post_name' => $form_id . '_wppost_1', |
| 900 | - ); |
|
| 900 | + ); |
|
| 901 | 901 | |
| 902 | - $post_settings = array( |
|
| 903 | - 'post_type', 'post_category', 'post_content', |
|
| 904 | - 'post_excerpt', 'post_title', 'post_name', 'post_date', |
|
| 902 | + $post_settings = array( |
|
| 903 | + 'post_type', 'post_category', 'post_content', |
|
| 904 | + 'post_excerpt', 'post_title', 'post_name', 'post_date', |
|
| 905 | 905 | 'post_status', 'post_custom_fields', 'post_password', |
| 906 | - ); |
|
| 906 | + ); |
|
| 907 | 907 | |
| 908 | - foreach ( $post_settings as $post_setting ) { |
|
| 908 | + foreach ( $post_settings as $post_setting ) { |
|
| 909 | 909 | if ( isset( $form_options[ $post_setting ] ) ) { |
| 910 | 910 | $new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ]; |
| 911 | - } |
|
| 912 | - unset($post_setting); |
|
| 913 | - } |
|
| 911 | + } |
|
| 912 | + unset($post_setting); |
|
| 913 | + } |
|
| 914 | 914 | |
| 915 | 915 | $new_action['event'] = array( 'create', 'update' ); |
| 916 | 916 | |
| 917 | - if ( $switch ) { |
|
| 917 | + if ( $switch ) { |
|
| 918 | 918 | // Fields with string or int saved |
| 919 | 919 | $basic_fields = array( 'post_title', 'post_content', 'post_excerpt', 'post_password', 'post_date', 'post_status' ); |
| 920 | 920 | |
@@ -922,22 +922,22 @@ discard block |
||
| 922 | 922 | $array_fields = array( 'post_category', 'post_custom_fields' ); |
| 923 | 923 | |
| 924 | 924 | $new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields ); |
| 925 | - } |
|
| 926 | - $new_action['post_content'] = json_encode($new_action['post_content']); |
|
| 925 | + } |
|
| 926 | + $new_action['post_content'] = json_encode($new_action['post_content']); |
|
| 927 | 927 | |
| 928 | - $exists = get_posts( array( |
|
| 929 | - 'name' => $new_action['post_name'], |
|
| 930 | - 'post_type' => $new_action['post_type'], |
|
| 931 | - 'post_status' => $new_action['post_status'], |
|
| 932 | - 'numberposts' => 1, |
|
| 933 | - ) ); |
|
| 928 | + $exists = get_posts( array( |
|
| 929 | + 'name' => $new_action['post_name'], |
|
| 930 | + 'post_type' => $new_action['post_type'], |
|
| 931 | + 'post_status' => $new_action['post_status'], |
|
| 932 | + 'numberposts' => 1, |
|
| 933 | + ) ); |
|
| 934 | 934 | |
| 935 | - if ( ! $exists ) { |
|
| 935 | + if ( ! $exists ) { |
|
| 936 | 936 | // this isn't an email, but we need to use a class that will always be included |
| 937 | 937 | FrmAppHelper::save_json_post( $new_action ); |
| 938 | - $imported['imported']['actions']++; |
|
| 939 | - } |
|
| 940 | - } |
|
| 938 | + $imported['imported']['actions']++; |
|
| 939 | + } |
|
| 940 | + } |
|
| 941 | 941 | |
| 942 | 942 | /** |
| 943 | 943 | * Switch old field IDs for new field IDs in emails and post |
@@ -950,211 +950,211 @@ discard block |
||
| 950 | 950 | * @return string $post_content - new field IDs |
| 951 | 951 | */ |
| 952 | 952 | private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) { |
| 953 | - global $frm_duplicate_ids; |
|
| 953 | + global $frm_duplicate_ids; |
|
| 954 | 954 | |
| 955 | - // If there aren't IDs that were switched, end now |
|
| 956 | - if ( ! $frm_duplicate_ids ) { |
|
| 957 | - return; |
|
| 958 | - } |
|
| 955 | + // If there aren't IDs that were switched, end now |
|
| 956 | + if ( ! $frm_duplicate_ids ) { |
|
| 957 | + return; |
|
| 958 | + } |
|
| 959 | 959 | |
| 960 | - // Get old IDs |
|
| 961 | - $old = array_keys( $frm_duplicate_ids ); |
|
| 960 | + // Get old IDs |
|
| 961 | + $old = array_keys( $frm_duplicate_ids ); |
|
| 962 | 962 | |
| 963 | - // Get new IDs |
|
| 964 | - $new = array_values( $frm_duplicate_ids ); |
|
| 963 | + // Get new IDs |
|
| 964 | + $new = array_values( $frm_duplicate_ids ); |
|
| 965 | 965 | |
| 966 | - // Do a str_replace with each item to set the new IDs |
|
| 967 | - foreach ( $post_content as $key => $setting ) { |
|
| 968 | - if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) { |
|
| 969 | - // Replace old IDs with new IDs |
|
| 966 | + // Do a str_replace with each item to set the new IDs |
|
| 967 | + foreach ( $post_content as $key => $setting ) { |
|
| 968 | + if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) { |
|
| 969 | + // Replace old IDs with new IDs |
|
| 970 | 970 | $post_content[ $key ] = str_replace( $old, $new, $setting ); |
| 971 | - } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) { |
|
| 972 | - foreach ( $setting as $k => $val ) { |
|
| 973 | - // Replace old IDs with new IDs |
|
| 971 | + } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) { |
|
| 972 | + foreach ( $setting as $k => $val ) { |
|
| 973 | + // Replace old IDs with new IDs |
|
| 974 | 974 | $post_content[ $key ][ $k ] = str_replace( $old, $new, $val ); |
| 975 | - } |
|
| 976 | - } |
|
| 977 | - unset( $key, $setting ); |
|
| 978 | - } |
|
| 979 | - return $post_content; |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
| 983 | - // No old notifications or autoresponders to carry over |
|
| 975 | + } |
|
| 976 | + } |
|
| 977 | + unset( $key, $setting ); |
|
| 978 | + } |
|
| 979 | + return $post_content; |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
| 983 | + // No old notifications or autoresponders to carry over |
|
| 984 | 984 | if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) { |
| 985 | - return; |
|
| 986 | - } |
|
| 985 | + return; |
|
| 986 | + } |
|
| 987 | 987 | |
| 988 | - // Initialize notifications array |
|
| 989 | - $notifications = array(); |
|
| 988 | + // Initialize notifications array |
|
| 989 | + $notifications = array(); |
|
| 990 | 990 | |
| 991 | - // Migrate regular notifications |
|
| 992 | - self::migrate_notifications_to_action( $form_options, $form_id, $notifications ); |
|
| 991 | + // Migrate regular notifications |
|
| 992 | + self::migrate_notifications_to_action( $form_options, $form_id, $notifications ); |
|
| 993 | 993 | |
| 994 | - // Migrate autoresponders |
|
| 995 | - self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications ); |
|
| 994 | + // Migrate autoresponders |
|
| 995 | + self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications ); |
|
| 996 | 996 | |
| 997 | - if ( empty( $notifications ) ) { |
|
| 998 | - return; |
|
| 999 | - } |
|
| 997 | + if ( empty( $notifications ) ) { |
|
| 998 | + return; |
|
| 999 | + } |
|
| 1000 | 1000 | |
| 1001 | - foreach ( $notifications as $new_notification ) { |
|
| 1002 | - $new_notification['post_type'] = $post_type; |
|
| 1003 | - $new_notification['post_excerpt'] = 'email'; |
|
| 1001 | + foreach ( $notifications as $new_notification ) { |
|
| 1002 | + $new_notification['post_type'] = $post_type; |
|
| 1003 | + $new_notification['post_excerpt'] = 'email'; |
|
| 1004 | 1004 | $new_notification['post_title'] = __( 'Email Notification', 'formidable' ); |
| 1005 | - $new_notification['menu_order'] = $form_id; |
|
| 1006 | - $new_notification['post_status'] = 'publish'; |
|
| 1005 | + $new_notification['menu_order'] = $form_id; |
|
| 1006 | + $new_notification['post_status'] = 'publish'; |
|
| 1007 | 1007 | |
| 1008 | - // Switch field IDs and keys, if needed |
|
| 1009 | - if ( $switch ) { |
|
| 1008 | + // Switch field IDs and keys, if needed |
|
| 1009 | + if ( $switch ) { |
|
| 1010 | 1010 | |
| 1011 | 1011 | // Switch field IDs in email conditional logic |
| 1012 | 1012 | self::switch_email_contition_field_ids( $new_notification['post_content'] ); |
| 1013 | 1013 | |
| 1014 | 1014 | // Switch all other field IDs in email |
| 1015 | - $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] ); |
|
| 1016 | - } |
|
| 1017 | - $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
| 1018 | - |
|
| 1019 | - $exists = get_posts( array( |
|
| 1020 | - 'name' => $new_notification['post_name'], |
|
| 1021 | - 'post_type' => $new_notification['post_type'], |
|
| 1022 | - 'post_status' => $new_notification['post_status'], |
|
| 1023 | - 'numberposts' => 1, |
|
| 1024 | - ) ); |
|
| 1025 | - |
|
| 1026 | - if ( empty($exists) ) { |
|
| 1015 | + $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] ); |
|
| 1016 | + } |
|
| 1017 | + $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
| 1018 | + |
|
| 1019 | + $exists = get_posts( array( |
|
| 1020 | + 'name' => $new_notification['post_name'], |
|
| 1021 | + 'post_type' => $new_notification['post_type'], |
|
| 1022 | + 'post_status' => $new_notification['post_status'], |
|
| 1023 | + 'numberposts' => 1, |
|
| 1024 | + ) ); |
|
| 1025 | + |
|
| 1026 | + if ( empty($exists) ) { |
|
| 1027 | 1027 | FrmAppHelper::save_json_post( $new_notification ); |
| 1028 | - $imported['imported']['actions']++; |
|
| 1029 | - } |
|
| 1030 | - unset($new_notification); |
|
| 1031 | - } |
|
| 1032 | - } |
|
| 1033 | - |
|
| 1034 | - private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) { |
|
| 1035 | - if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) { |
|
| 1036 | - // add old settings into notification array |
|
| 1028 | + $imported['imported']['actions']++; |
|
| 1029 | + } |
|
| 1030 | + unset($new_notification); |
|
| 1031 | + } |
|
| 1032 | + } |
|
| 1033 | + |
|
| 1034 | + private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) { |
|
| 1035 | + if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) { |
|
| 1036 | + // add old settings into notification array |
|
| 1037 | 1037 | $form_options['notification'] = array( 0 => $form_options ); |
| 1038 | - } else if ( isset( $form_options['notification']['email_to'] ) ) { |
|
| 1039 | - // make sure it's in the correct format |
|
| 1038 | + } else if ( isset( $form_options['notification']['email_to'] ) ) { |
|
| 1039 | + // make sure it's in the correct format |
|
| 1040 | 1040 | $form_options['notification'] = array( 0 => $form_options['notification'] ); |
| 1041 | - } |
|
| 1041 | + } |
|
| 1042 | 1042 | |
| 1043 | - if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) { |
|
| 1044 | - foreach ( $form_options['notification'] as $email_key => $notification ) { |
|
| 1043 | + if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) { |
|
| 1044 | + foreach ( $form_options['notification'] as $email_key => $notification ) { |
|
| 1045 | 1045 | |
| 1046 | - $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key ); |
|
| 1046 | + $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key ); |
|
| 1047 | 1047 | |
| 1048 | - // Format the email data |
|
| 1049 | - self::format_email_data( $atts, $notification ); |
|
| 1048 | + // Format the email data |
|
| 1049 | + self::format_email_data( $atts, $notification ); |
|
| 1050 | 1050 | |
| 1051 | 1051 | if ( isset( $notification['twilio'] ) && $notification['twilio'] ) { |
| 1052 | 1052 | do_action( 'frm_create_twilio_action', $atts, $notification ); |
| 1053 | 1053 | } |
| 1054 | 1054 | |
| 1055 | - // Setup the new notification |
|
| 1056 | - $new_notification = array(); |
|
| 1057 | - self::setup_new_notification( $new_notification, $notification, $atts ); |
|
| 1055 | + // Setup the new notification |
|
| 1056 | + $new_notification = array(); |
|
| 1057 | + self::setup_new_notification( $new_notification, $notification, $atts ); |
|
| 1058 | 1058 | |
| 1059 | - $notifications[] = $new_notification; |
|
| 1060 | - } |
|
| 1061 | - } |
|
| 1062 | - } |
|
| 1059 | + $notifications[] = $new_notification; |
|
| 1060 | + } |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | 1063 | |
| 1064 | - private static function format_email_data( &$atts, $notification ) { |
|
| 1065 | - // Format email_to |
|
| 1066 | - self::format_email_to_data( $atts, $notification ); |
|
| 1064 | + private static function format_email_data( &$atts, $notification ) { |
|
| 1065 | + // Format email_to |
|
| 1066 | + self::format_email_to_data( $atts, $notification ); |
|
| 1067 | 1067 | |
| 1068 | - // Format the reply to email and name |
|
| 1069 | - $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' ); |
|
| 1070 | - foreach ( $reply_fields as $f => $val ) { |
|
| 1068 | + // Format the reply to email and name |
|
| 1069 | + $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' ); |
|
| 1070 | + foreach ( $reply_fields as $f => $val ) { |
|
| 1071 | 1071 | if ( isset( $notification[ $f ] ) ) { |
| 1072 | 1072 | $atts[ $f ] = $notification[ $f ]; |
| 1073 | 1073 | if ( 'custom' == $notification[ $f ] ) { |
| 1074 | 1074 | $atts[ $f ] = $notification[ 'cust_' . $f ]; |
| 1075 | 1075 | } else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) { |
| 1076 | 1076 | $atts[ $f ] = '[' . $atts[ $f ] . ']'; |
| 1077 | - } |
|
| 1078 | - } |
|
| 1079 | - unset( $f, $val ); |
|
| 1080 | - } |
|
| 1077 | + } |
|
| 1078 | + } |
|
| 1079 | + unset( $f, $val ); |
|
| 1080 | + } |
|
| 1081 | 1081 | |
| 1082 | - // Format event |
|
| 1082 | + // Format event |
|
| 1083 | 1083 | $atts['event'] = array( 'create' ); |
| 1084 | - if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) { |
|
| 1085 | - $atts['event'][] = 'update'; |
|
| 1086 | - } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) { |
|
| 1084 | + if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) { |
|
| 1085 | + $atts['event'][] = 'update'; |
|
| 1086 | + } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) { |
|
| 1087 | 1087 | $atts['event'] = array( 'update' ); |
| 1088 | - } |
|
| 1089 | - } |
|
| 1088 | + } |
|
| 1089 | + } |
|
| 1090 | 1090 | |
| 1091 | - private static function format_email_to_data( &$atts, $notification ) { |
|
| 1092 | - if ( isset( $notification['email_to'] ) ) { |
|
| 1091 | + private static function format_email_to_data( &$atts, $notification ) { |
|
| 1092 | + if ( isset( $notification['email_to'] ) ) { |
|
| 1093 | 1093 | $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] ); |
| 1094 | - } else { |
|
| 1095 | - $atts['email_to'] = array(); |
|
| 1096 | - } |
|
| 1094 | + } else { |
|
| 1095 | + $atts['email_to'] = array(); |
|
| 1096 | + } |
|
| 1097 | 1097 | |
| 1098 | - if ( isset( $notification['also_email_to'] ) ) { |
|
| 1099 | - $email_fields = (array) $notification['also_email_to']; |
|
| 1100 | - $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] ); |
|
| 1101 | - unset( $email_fields ); |
|
| 1102 | - } |
|
| 1098 | + if ( isset( $notification['also_email_to'] ) ) { |
|
| 1099 | + $email_fields = (array) $notification['also_email_to']; |
|
| 1100 | + $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] ); |
|
| 1101 | + unset( $email_fields ); |
|
| 1102 | + } |
|
| 1103 | 1103 | |
| 1104 | - foreach ( $atts['email_to'] as $key => $email_field ) { |
|
| 1104 | + foreach ( $atts['email_to'] as $key => $email_field ) { |
|
| 1105 | 1105 | |
| 1106 | - if ( is_numeric( $email_field ) ) { |
|
| 1106 | + if ( is_numeric( $email_field ) ) { |
|
| 1107 | 1107 | $atts['email_to'][ $key ] = '[' . $email_field . ']'; |
| 1108 | - } |
|
| 1108 | + } |
|
| 1109 | 1109 | |
| 1110 | - if ( strpos( $email_field, '|') ) { |
|
| 1111 | - $email_opt = explode( '|', $email_field ); |
|
| 1112 | - if ( isset( $email_opt[0] ) ) { |
|
| 1110 | + if ( strpos( $email_field, '|') ) { |
|
| 1111 | + $email_opt = explode( '|', $email_field ); |
|
| 1112 | + if ( isset( $email_opt[0] ) ) { |
|
| 1113 | 1113 | $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']'; |
| 1114 | - } |
|
| 1115 | - unset( $email_opt ); |
|
| 1116 | - } |
|
| 1117 | - } |
|
| 1118 | - $atts['email_to'] = implode(', ', $atts['email_to']); |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - private static function setup_new_notification( &$new_notification, $notification, $atts ) { |
|
| 1122 | - // Set up new notification |
|
| 1123 | - $new_notification = array( |
|
| 1124 | - 'post_content' => array( |
|
| 1125 | - 'email_to' => $atts['email_to'], |
|
| 1126 | - 'event' => $atts['event'], |
|
| 1127 | - ), |
|
| 1114 | + } |
|
| 1115 | + unset( $email_opt ); |
|
| 1116 | + } |
|
| 1117 | + } |
|
| 1118 | + $atts['email_to'] = implode(', ', $atts['email_to']); |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + private static function setup_new_notification( &$new_notification, $notification, $atts ) { |
|
| 1122 | + // Set up new notification |
|
| 1123 | + $new_notification = array( |
|
| 1124 | + 'post_content' => array( |
|
| 1125 | + 'email_to' => $atts['email_to'], |
|
| 1126 | + 'event' => $atts['event'], |
|
| 1127 | + ), |
|
| 1128 | 1128 | 'post_name' => $atts['form_id'] . '_email_' . $atts['email_key'], |
| 1129 | - ); |
|
| 1129 | + ); |
|
| 1130 | 1130 | |
| 1131 | - // Add more fields to the new notification |
|
| 1132 | - $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' ); |
|
| 1133 | - foreach ( $add_fields as $add_field ) { |
|
| 1131 | + // Add more fields to the new notification |
|
| 1132 | + $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' ); |
|
| 1133 | + foreach ( $add_fields as $add_field ) { |
|
| 1134 | 1134 | if ( isset( $notification[ $add_field ] ) ) { |
| 1135 | 1135 | $new_notification['post_content'][ $add_field ] = $notification[ $add_field ]; |
| 1136 | - } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) { |
|
| 1136 | + } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) { |
|
| 1137 | 1137 | $new_notification['post_content'][ $add_field ] = 0; |
| 1138 | - } else { |
|
| 1138 | + } else { |
|
| 1139 | 1139 | $new_notification['post_content'][ $add_field ] = ''; |
| 1140 | - } |
|
| 1141 | - unset( $add_field ); |
|
| 1142 | - } |
|
| 1140 | + } |
|
| 1141 | + unset( $add_field ); |
|
| 1142 | + } |
|
| 1143 | 1143 | |
| 1144 | 1144 | // Set reply to |
| 1145 | 1145 | $new_notification['post_content']['reply_to'] = $atts['reply_to']; |
| 1146 | 1146 | |
| 1147 | - // Set from |
|
| 1147 | + // Set from |
|
| 1148 | 1148 | if ( ! empty( $atts['reply_to'] ) || ! empty( $atts['reply_to_name'] ) ) { |
| 1149 | 1149 | $new_notification['post_content']['from'] = ( empty( $atts['reply_to_name'] ) ? '[sitename]' : $atts['reply_to_name'] ) . ' <' . ( empty( $atts['reply_to'] ) ? '[admin_email]' : $atts['reply_to'] ) . '>'; |
| 1150 | - } |
|
| 1151 | - } |
|
| 1150 | + } |
|
| 1151 | + } |
|
| 1152 | 1152 | |
| 1153 | 1153 | /** |
| 1154 | - * Switch field IDs in pre-2.0 email conditional logic |
|
| 1155 | - * |
|
| 1156 | - * @param $post_content array, pass by reference |
|
| 1157 | - */ |
|
| 1154 | + * Switch field IDs in pre-2.0 email conditional logic |
|
| 1155 | + * |
|
| 1156 | + * @param $post_content array, pass by reference |
|
| 1157 | + */ |
|
| 1158 | 1158 | private static function switch_email_contition_field_ids( &$post_content ) { |
| 1159 | 1159 | // Switch field IDs in conditional logic |
| 1160 | 1160 | if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) { |
@@ -1167,36 +1167,36 @@ discard block |
||
| 1167 | 1167 | } |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | - private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) { |
|
| 1171 | - if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) { |
|
| 1172 | - // migrate autoresponder |
|
| 1173 | - |
|
| 1174 | - $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0; |
|
| 1175 | - if ( strpos($email_field, '|') ) { |
|
| 1176 | - // data from entries field |
|
| 1177 | - $email_field = explode('|', $email_field); |
|
| 1178 | - if ( isset($email_field[1]) ) { |
|
| 1179 | - $email_field = $email_field[1]; |
|
| 1180 | - } |
|
| 1181 | - } |
|
| 1182 | - if ( is_numeric($email_field) && ! empty($email_field) ) { |
|
| 1170 | + private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) { |
|
| 1171 | + if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) { |
|
| 1172 | + // migrate autoresponder |
|
| 1173 | + |
|
| 1174 | + $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0; |
|
| 1175 | + if ( strpos($email_field, '|') ) { |
|
| 1176 | + // data from entries field |
|
| 1177 | + $email_field = explode('|', $email_field); |
|
| 1178 | + if ( isset($email_field[1]) ) { |
|
| 1179 | + $email_field = $email_field[1]; |
|
| 1180 | + } |
|
| 1181 | + } |
|
| 1182 | + if ( is_numeric($email_field) && ! empty($email_field) ) { |
|
| 1183 | 1183 | $email_field = '[' . $email_field . ']'; |
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - $notification = $form_options; |
|
| 1187 | - $new_notification2 = array( |
|
| 1188 | - 'post_content' => array( |
|
| 1189 | - 'email_message' => $notification['ar_email_message'], |
|
| 1190 | - 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '', |
|
| 1191 | - 'email_to' => $email_field, |
|
| 1192 | - 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0, |
|
| 1193 | - 'inc_user_info' => 0, |
|
| 1194 | - ), |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + $notification = $form_options; |
|
| 1187 | + $new_notification2 = array( |
|
| 1188 | + 'post_content' => array( |
|
| 1189 | + 'email_message' => $notification['ar_email_message'], |
|
| 1190 | + 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '', |
|
| 1191 | + 'email_to' => $email_field, |
|
| 1192 | + 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0, |
|
| 1193 | + 'inc_user_info' => 0, |
|
| 1194 | + ), |
|
| 1195 | 1195 | 'post_name' => $form_id . '_email_' . count( $notifications ), |
| 1196 | - ); |
|
| 1196 | + ); |
|
| 1197 | 1197 | |
| 1198 | - $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : ''; |
|
| 1199 | - $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : ''; |
|
| 1198 | + $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : ''; |
|
| 1199 | + $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : ''; |
|
| 1200 | 1200 | |
| 1201 | 1201 | if ( ! empty( $reply_to ) ) { |
| 1202 | 1202 | $new_notification2['post_content']['reply_to'] = $reply_to; |
@@ -1206,9 +1206,9 @@ discard block |
||
| 1206 | 1206 | $new_notification2['post_content']['from'] = ( empty( $reply_to_name ) ? '[sitename]' : $reply_to_name ) . ' <' . ( empty( $reply_to ) ? '[admin_email]' : $reply_to ) . '>'; |
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | - $notifications[] = $new_notification2; |
|
| 1210 | - unset( $new_notification2 ); |
|
| 1211 | - } |
|
| 1212 | - } |
|
| 1209 | + $notifications[] = $new_notification2; |
|
| 1210 | + unset( $new_notification2 ); |
|
| 1211 | + } |
|
| 1212 | + } |
|
| 1213 | 1213 | } |
| 1214 | 1214 | |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -if ( ! defined('ABSPATH') ) { |
|
| 2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
| 3 | 3 | die( 'You are not allowed to call this page directly.' ); |
| 4 | 4 | } |
| 5 | 5 | |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | 'terms' => array(), |
| 37 | 37 | ); |
| 38 | 38 | |
| 39 | - unset($defaults); |
|
| 39 | + unset( $defaults ); |
|
| 40 | 40 | |
| 41 | 41 | if ( ! defined( 'WP_IMPORTING' ) ) { |
| 42 | - define('WP_IMPORTING', true); |
|
| 42 | + define( 'WP_IMPORTING', true ); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | if ( ! class_exists( 'DOMDocument' ) ) { |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() ); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - if ( ! function_exists('simplexml_import_dom') ) { |
|
| 55 | + if ( ! function_exists( 'simplexml_import_dom' ) ) { |
|
| 56 | 56 | return new WP_Error( 'SimpleXML_parse_error', __( 'Your server is missing the simplexml_import_dom function', 'formidable' ), libxml_get_errors() ); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -67,14 +67,14 @@ discard block |
||
| 67 | 67 | // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order |
| 68 | 68 | foreach ( array( 'term', 'form', 'view' ) as $item_type ) { |
| 69 | 69 | // grab cats, tags, and terms, or forms or posts |
| 70 | - if ( isset($xml->{$item_type} ) ) { |
|
| 70 | + if ( isset( $xml->{$item_type} ) ) { |
|
| 71 | 71 | $function_name = 'import_xml_' . $item_type . 's'; |
| 72 | 72 | $imported = self::$function_name( $xml->{$item_type}, $imported ); |
| 73 | 73 | unset( $function_name, $xml->{$item_type} ); |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $return = apply_filters('frm_importing_xml', $imported, $xml ); |
|
| 77 | + $return = apply_filters( 'frm_importing_xml', $imported, $xml ); |
|
| 78 | 78 | |
| 79 | 79 | return $return; |
| 80 | 80 | } |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | 'slug' => (string) $t->term_slug, |
| 92 | 92 | 'description' => (string) $t->term_description, |
| 93 | 93 | 'parent' => empty( $parent ) ? 0 : $parent, |
| 94 | - )); |
|
| 94 | + ) ); |
|
| 95 | 95 | |
| 96 | 96 | if ( $term && is_array( $term ) ) { |
| 97 | - $imported['imported']['terms']++; |
|
| 98 | - $imported['terms'][ (int) $t->term_id ] = $term['term_id']; |
|
| 97 | + $imported['imported']['terms'] ++; |
|
| 98 | + $imported['terms'][(int) $t->term_id] = $term['term_id']; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | unset( $term, $t ); |
@@ -138,11 +138,11 @@ discard block |
||
| 138 | 138 | 'default_template' => (int) $item->default_template, |
| 139 | 139 | 'editable' => (int) $item->editable, |
| 140 | 140 | 'status' => (string) $item->status, |
| 141 | - 'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0, |
|
| 141 | + 'parent_form_id' => isset( $item->parent_form_id ) ? (int) $item->parent_form_id : 0, |
|
| 142 | 142 | 'created_at' => date( 'Y-m-d H:i:s', strtotime( (string) $item->created_at ) ), |
| 143 | 143 | ); |
| 144 | 144 | |
| 145 | - $form['options'] = FrmAppHelper::maybe_json_decode($form['options']); |
|
| 145 | + $form['options'] = FrmAppHelper::maybe_json_decode( $form['options'] ); |
|
| 146 | 146 | |
| 147 | 147 | self::update_custom_style_setting_on_import( $form ); |
| 148 | 148 | |
@@ -152,35 +152,35 @@ discard block |
||
| 152 | 152 | $edit_query['created_at'] = $form['created_at']; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form); |
|
| 155 | + $edit_query = apply_filters( 'frm_match_xml_form', $edit_query, $form ); |
|
| 156 | 156 | |
| 157 | - $this_form = FrmForm::getAll($edit_query, '', 1); |
|
| 158 | - unset($edit_query); |
|
| 157 | + $this_form = FrmForm::getAll( $edit_query, '', 1 ); |
|
| 158 | + unset( $edit_query ); |
|
| 159 | 159 | |
| 160 | 160 | if ( ! empty( $this_form ) ) { |
| 161 | 161 | $old_id = $form_id = $this_form->id; |
| 162 | - FrmForm::update($form_id, $form ); |
|
| 163 | - $imported['updated']['forms']++; |
|
| 162 | + FrmForm::update( $form_id, $form ); |
|
| 163 | + $imported['updated']['forms'] ++; |
|
| 164 | 164 | // Keep track of whether this specific form was updated or not |
| 165 | - $imported['form_status'][ $form_id ] = 'updated'; |
|
| 165 | + $imported['form_status'][$form_id] = 'updated'; |
|
| 166 | 166 | |
| 167 | 167 | $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' ); |
| 168 | 168 | $old_fields = array(); |
| 169 | 169 | foreach ( $form_fields as $f ) { |
| 170 | - $old_fields[ $f->id ] = $f; |
|
| 171 | - $old_fields[ $f->field_key ] = $f->id; |
|
| 172 | - unset($f); |
|
| 170 | + $old_fields[$f->id] = $f; |
|
| 171 | + $old_fields[$f->field_key] = $f->id; |
|
| 172 | + unset( $f ); |
|
| 173 | 173 | } |
| 174 | 174 | $form_fields = $old_fields; |
| 175 | - unset($old_fields); |
|
| 175 | + unset( $old_fields ); |
|
| 176 | 176 | } else { |
| 177 | 177 | $old_id = false; |
| 178 | 178 | //form does not exist, so create it |
| 179 | 179 | $form_id = FrmForm::create( $form ); |
| 180 | 180 | if ( $form_id ) { |
| 181 | - $imported['imported']['forms']++; |
|
| 181 | + $imported['imported']['forms'] ++; |
|
| 182 | 182 | // Keep track of whether this specific form was updated or not |
| 183 | - $imported['form_status'][ $form_id ] = 'imported'; |
|
| 183 | + $imported['form_status'][$form_id] = 'imported'; |
|
| 184 | 184 | self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms ); |
| 185 | 185 | } |
| 186 | 186 | } |
@@ -190,23 +190,23 @@ discard block |
||
| 190 | 190 | // Delete any fields attached to this form that were not included in the template |
| 191 | 191 | if ( isset( $form_fields ) && ! empty( $form_fields ) ) { |
| 192 | 192 | foreach ( $form_fields as $field ) { |
| 193 | - if ( is_object($field) ) { |
|
| 194 | - FrmField::destroy($field->id); |
|
| 193 | + if ( is_object( $field ) ) { |
|
| 194 | + FrmField::destroy( $field->id ); |
|
| 195 | 195 | } |
| 196 | - unset($field); |
|
| 196 | + unset( $field ); |
|
| 197 | 197 | } |
| 198 | - unset($form_fields); |
|
| 198 | + unset( $form_fields ); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // Update field ids/keys to new ones |
| 202 | 202 | do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) ); |
| 203 | 203 | |
| 204 | - $imported['forms'][ (int) $item->id ] = $form_id; |
|
| 204 | + $imported['forms'][(int) $item->id] = $form_id; |
|
| 205 | 205 | |
| 206 | 206 | // Send pre 2.0 form options through function that creates actions |
| 207 | 207 | self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true ); |
| 208 | 208 | |
| 209 | - unset($form, $item); |
|
| 209 | + unset( $form, $item ); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms ); |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | $regular_forms = array(); |
| 226 | 226 | |
| 227 | 227 | foreach ( $forms as $form ) { |
| 228 | - $parent_form_id = isset( $form->parent_form_id) ? (int) $form->parent_form_id : 0; |
|
| 228 | + $parent_form_id = isset( $form->parent_form_id ) ? (int) $form->parent_form_id : 0; |
|
| 229 | 229 | |
| 230 | 230 | if ( $parent_form_id ) { |
| 231 | 231 | $child_forms[] = $form; |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | */ |
| 248 | 248 | private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) { |
| 249 | 249 | if ( $parent_form_id ) { |
| 250 | - $child_forms[ $form_id ] = $parent_form_id; |
|
| 250 | + $child_forms[$form_id] = $parent_form_id; |
|
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | 253 | |
@@ -262,9 +262,9 @@ discard block |
||
| 262 | 262 | private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) { |
| 263 | 263 | foreach ( $child_forms as $child_form_id => $old_parent_form_id ) { |
| 264 | 264 | |
| 265 | - if ( isset( $imported_forms[ $old_parent_form_id ] ) && $imported_forms[ $old_parent_form_id ] != $old_parent_form_id ) { |
|
| 265 | + if ( isset( $imported_forms[$old_parent_form_id] ) && $imported_forms[$old_parent_form_id] != $old_parent_form_id ) { |
|
| 266 | 266 | // Update all children with this old parent_form_id |
| 267 | - $new_parent_form_id = (int) $imported_forms[ $old_parent_form_id ]; |
|
| 267 | + $new_parent_form_id = (int) $imported_forms[$old_parent_form_id]; |
|
| 268 | 268 | |
| 269 | 269 | FrmForm::update( $child_form_id, array( 'parent_form_id' => $new_parent_form_id ) ); |
| 270 | 270 | } |
@@ -287,23 +287,23 @@ discard block |
||
| 287 | 287 | 'name' => (string) $field->name, |
| 288 | 288 | 'description' => (string) $field->description, |
| 289 | 289 | 'type' => (string) $field->type, |
| 290 | - 'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value), |
|
| 290 | + 'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value ), |
|
| 291 | 291 | 'field_order' => (int) $field->field_order, |
| 292 | 292 | 'form_id' => (int) $form_id, |
| 293 | 293 | 'required' => (int) $field->required, |
| 294 | - 'options' => FrmAppHelper::maybe_json_decode( (string) $field->options), |
|
| 294 | + 'options' => FrmAppHelper::maybe_json_decode( (string) $field->options ), |
|
| 295 | 295 | 'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ), |
| 296 | 296 | ); |
| 297 | 297 | |
| 298 | - if ( is_array($f['default_value']) && in_array($f['type'], array( |
|
| 298 | + if ( is_array( $f['default_value'] ) && in_array( $f['type'], array( |
|
| 299 | 299 | 'text', 'email', 'url', 'textarea', |
| 300 | - 'number','phone', 'date', 'time', |
|
| 300 | + 'number', 'phone', 'date', 'time', |
|
| 301 | 301 | 'hidden', 'password', 'tag', 'image', |
| 302 | - )) ) { |
|
| 303 | - if ( count($f['default_value']) === 1 ) { |
|
| 302 | + ) ) ) { |
|
| 303 | + if ( count( $f['default_value'] ) === 1 ) { |
|
| 304 | 304 | $f['default_value'] = '[' . reset( $f['default_value'] ) . ']'; |
| 305 | 305 | } else { |
| 306 | - $f['default_value'] = reset($f['default_value']); |
|
| 306 | + $f['default_value'] = reset( $f['default_value'] ); |
|
| 307 | 307 | } |
| 308 | 308 | } |
| 309 | 309 | |
@@ -311,27 +311,27 @@ discard block |
||
| 311 | 311 | self::maybe_update_form_select( $f, $imported ); |
| 312 | 312 | self::maybe_update_get_values_form_setting( $imported, $f ); |
| 313 | 313 | |
| 314 | - if ( ! empty($this_form) ) { |
|
| 314 | + if ( ! empty( $this_form ) ) { |
|
| 315 | 315 | // check for field to edit by field id |
| 316 | - if ( isset( $form_fields[ $f['id'] ] ) ) { |
|
| 316 | + if ( isset( $form_fields[$f['id']] ) ) { |
|
| 317 | 317 | FrmField::update( $f['id'], $f ); |
| 318 | - $imported['updated']['fields']++; |
|
| 318 | + $imported['updated']['fields'] ++; |
|
| 319 | 319 | |
| 320 | - unset( $form_fields[ $f['id'] ] ); |
|
| 320 | + unset( $form_fields[$f['id']] ); |
|
| 321 | 321 | |
| 322 | 322 | //unset old field key |
| 323 | - if ( isset( $form_fields[ $f['field_key'] ] ) ) { |
|
| 324 | - unset( $form_fields[ $f['field_key'] ] ); |
|
| 323 | + if ( isset( $form_fields[$f['field_key']] ) ) { |
|
| 324 | + unset( $form_fields[$f['field_key']] ); |
|
| 325 | 325 | } |
| 326 | - } else if ( isset( $form_fields[ $f['field_key'] ] ) ) { |
|
| 326 | + } else if ( isset( $form_fields[$f['field_key']] ) ) { |
|
| 327 | 327 | // check for field to edit by field key |
| 328 | - unset($f['id']); |
|
| 328 | + unset( $f['id'] ); |
|
| 329 | 329 | |
| 330 | - FrmField::update( $form_fields[ $f['field_key'] ], $f ); |
|
| 331 | - $imported['updated']['fields']++; |
|
| 330 | + FrmField::update( $form_fields[$f['field_key']], $f ); |
|
| 331 | + $imported['updated']['fields'] ++; |
|
| 332 | 332 | |
| 333 | - unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id |
|
| 334 | - unset( $form_fields[ $f['field_key'] ] ); //unset old field key |
|
| 333 | + unset( $form_fields[$form_fields[$f['field_key']]] ); //unset old field id |
|
| 334 | + unset( $form_fields[$f['field_key']] ); //unset old field key |
|
| 335 | 335 | } else { |
| 336 | 336 | // if no matching field id or key in this form, create the field |
| 337 | 337 | self::create_imported_field( $f, $imported ); |
@@ -382,8 +382,8 @@ discard block |
||
| 382 | 382 | if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) { |
| 383 | 383 | if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) { |
| 384 | 384 | $form_select = $f['field_options']['form_select']; |
| 385 | - if ( isset( $imported['forms'][ $form_select ] ) ) { |
|
| 386 | - $f['field_options']['form_select'] = $imported['forms'][ $form_select ]; |
|
| 385 | + if ( isset( $imported['forms'][$form_select] ) ) { |
|
| 386 | + $f['field_options']['form_select'] = $imported['forms'][$form_select]; |
|
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | 389 | } |
@@ -403,8 +403,8 @@ discard block |
||
| 403 | 403 | |
| 404 | 404 | if ( FrmField::is_option_true_in_array( $f['field_options'], 'get_values_form' ) ) { |
| 405 | 405 | $old_form = $f['field_options']['get_values_form']; |
| 406 | - if ( isset( $imported['forms'][ $old_form ] ) ) { |
|
| 407 | - $f['field_options']['get_values_form'] = $imported['forms'][ $old_form ]; |
|
| 406 | + if ( isset( $imported['forms'][$old_form] ) ) { |
|
| 407 | + $f['field_options']['get_values_form'] = $imported['forms'][$old_form]; |
|
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | } |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | private static function create_imported_field( $f, &$imported ) { |
| 420 | 420 | $new_id = FrmField::create( $f ); |
| 421 | 421 | if ( $new_id != false ) { |
| 422 | - $imported['imported']['fields']++; |
|
| 422 | + $imported['imported']['fields'] ++; |
|
| 423 | 423 | do_action( 'frm_after_field_is_imported', $f, $new_id ); |
| 424 | 424 | } |
| 425 | 425 | } |
@@ -518,9 +518,9 @@ discard block |
||
| 518 | 518 | ); |
| 519 | 519 | |
| 520 | 520 | $old_id = $post['post_id']; |
| 521 | - self::populate_post($post, $item, $imported); |
|
| 521 | + self::populate_post( $post, $item, $imported ); |
|
| 522 | 522 | |
| 523 | - unset($item); |
|
| 523 | + unset( $item ); |
|
| 524 | 524 | |
| 525 | 525 | $post_id = false; |
| 526 | 526 | if ( $post['post_type'] == $form_action_type ) { |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | if ( $action_control && is_object( $action_control ) ) { |
| 529 | 529 | $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] ); |
| 530 | 530 | } |
| 531 | - unset($action_control); |
|
| 531 | + unset( $action_control ); |
|
| 532 | 532 | } else if ( $post['post_type'] == 'frm_styles' ) { |
| 533 | 533 | // Properly encode post content before inserting the post |
| 534 | 534 | $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
@@ -541,26 +541,26 @@ discard block |
||
| 541 | 541 | $post_id = wp_insert_post( $post ); |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | - if ( ! is_numeric($post_id) ) { |
|
| 544 | + if ( ! is_numeric( $post_id ) ) { |
|
| 545 | 545 | continue; |
| 546 | 546 | } |
| 547 | 547 | |
| 548 | - self::update_postmeta($post, $post_id); |
|
| 548 | + self::update_postmeta( $post, $post_id ); |
|
| 549 | 549 | |
| 550 | 550 | $this_type = 'posts'; |
| 551 | - if ( isset( $post_types[ $post['post_type'] ] ) ) { |
|
| 552 | - $this_type = $post_types[ $post['post_type'] ]; |
|
| 551 | + if ( isset( $post_types[$post['post_type']] ) ) { |
|
| 552 | + $this_type = $post_types[$post['post_type']]; |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | - if ( isset($post['ID']) && $post_id == $post['ID'] ) { |
|
| 556 | - $imported['updated'][ $this_type ]++; |
|
| 555 | + if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) { |
|
| 556 | + $imported['updated'][$this_type] ++; |
|
| 557 | 557 | } else { |
| 558 | - $imported['imported'][ $this_type ]++; |
|
| 558 | + $imported['imported'][$this_type] ++; |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - unset($post); |
|
| 561 | + unset( $post ); |
|
| 562 | 562 | |
| 563 | - $imported['posts'][ (int) $old_id ] = $post_id; |
|
| 563 | + $imported['posts'][(int) $old_id] = $post_id; |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | self::maybe_update_stylesheet( $imported ); |
@@ -569,13 +569,13 @@ discard block |
||
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | private static function populate_post( &$post, $item, $imported ) { |
| 572 | - if ( isset($item->attachment_url) ) { |
|
| 572 | + if ( isset( $item->attachment_url ) ) { |
|
| 573 | 573 | $post['attachment_url'] = (string) $item->attachment_url; |
| 574 | 574 | } |
| 575 | 575 | |
| 576 | - if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) { |
|
| 576 | + if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][(int) $post['menu_order']] ) ) { |
|
| 577 | 577 | // update to new form id |
| 578 | - $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ]; |
|
| 578 | + $post['menu_order'] = $imported['forms'][(int) $post['menu_order']]; |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | // Don't allow default styles to take over a site's default style |
@@ -584,13 +584,13 @@ discard block |
||
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | foreach ( $item->postmeta as $meta ) { |
| 587 | - self::populate_postmeta($post, $meta, $imported); |
|
| 588 | - unset($meta); |
|
| 587 | + self::populate_postmeta( $post, $meta, $imported ); |
|
| 588 | + unset( $meta ); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - self::populate_taxonomies($post, $item); |
|
| 591 | + self::populate_taxonomies( $post, $item ); |
|
| 592 | 592 | |
| 593 | - self::maybe_editing_post($post); |
|
| 593 | + self::maybe_editing_post( $post ); |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | private static function populate_postmeta( &$post, $meta, $imported ) { |
@@ -602,27 +602,27 @@ discard block |
||
| 602 | 602 | ); |
| 603 | 603 | |
| 604 | 604 | //switch old form and field ids to new ones |
| 605 | - if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) { |
|
| 606 | - $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
|
| 605 | + if ( $m['key'] == 'frm_form_id' && isset( $imported['forms'][(int) $m['value']] ) ) { |
|
| 606 | + $m['value'] = $imported['forms'][(int) $m['value']]; |
|
| 607 | 607 | } else { |
| 608 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
| 608 | + $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] ); |
|
| 609 | 609 | |
| 610 | - if ( ! empty($frm_duplicate_ids) ) { |
|
| 610 | + if ( ! empty( $frm_duplicate_ids ) ) { |
|
| 611 | 611 | |
| 612 | 612 | if ( $m['key'] == 'frm_dyncontent' ) { |
| 613 | - $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); |
|
| 613 | + $m['value'] = FrmFieldsHelper::switch_field_ids( $m['value'] ); |
|
| 614 | 614 | } else if ( $m['key'] == 'frm_options' ) { |
| 615 | 615 | |
| 616 | 616 | foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) { |
| 617 | - if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) { |
|
| 618 | - $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ]; |
|
| 617 | + if ( isset( $m['value'][$setting_name] ) && is_numeric( $m['value'][$setting_name] ) && isset( $frm_duplicate_ids[$m['value'][$setting_name]] ) ) { |
|
| 618 | + $m['value'][$setting_name] = $frm_duplicate_ids[$m['value'][$setting_name]]; |
|
| 619 | 619 | } |
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | $check_dup_array = array(); |
| 623 | 623 | if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { |
| 624 | - if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
|
| 625 | - $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
|
| 624 | + if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[$m['value']['order_by']] ) ) { |
|
| 625 | + $m['value']['order_by'] = $frm_duplicate_ids[$m['value']['order_by']]; |
|
| 626 | 626 | } else if ( is_array( $m['value']['order_by'] ) ) { |
| 627 | 627 | $check_dup_array[] = 'order_by'; |
| 628 | 628 | } |
@@ -633,22 +633,22 @@ discard block |
||
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | foreach ( $check_dup_array as $check_k ) { |
| 636 | - foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) { |
|
| 637 | - if ( isset( $frm_duplicate_ids[ $mv ] ) ) { |
|
| 638 | - $m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ]; |
|
| 636 | + foreach ( (array) $m['value'][$check_k] as $mk => $mv ) { |
|
| 637 | + if ( isset( $frm_duplicate_ids[$mv] ) ) { |
|
| 638 | + $m['value'][$check_k][$mk] = $frm_duplicate_ids[$mv]; |
|
| 639 | 639 | } |
| 640 | - unset($mk, $mv); |
|
| 640 | + unset( $mk, $mv ); |
|
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | 643 | } |
| 644 | 644 | } |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - if ( ! is_array($m['value']) ) { |
|
| 648 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
| 647 | + if ( ! is_array( $m['value'] ) ) { |
|
| 648 | + $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] ); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | - $post['postmeta'][ (string) $meta->meta_key ] = $m['value']; |
|
| 651 | + $post['postmeta'][(string) $meta->meta_key] = $m['value']; |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | /** |
@@ -664,23 +664,23 @@ discard block |
||
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | $taxonomy = (string) $att['domain']; |
| 667 | - if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
| 667 | + if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
|
| 668 | 668 | $name = (string) $att['nicename']; |
| 669 | - $h_term = get_term_by('slug', $name, $taxonomy); |
|
| 669 | + $h_term = get_term_by( 'slug', $name, $taxonomy ); |
|
| 670 | 670 | if ( $h_term ) { |
| 671 | 671 | $name = $h_term->term_id; |
| 672 | 672 | } |
| 673 | - unset($h_term); |
|
| 673 | + unset( $h_term ); |
|
| 674 | 674 | } else { |
| 675 | 675 | $name = (string) $c; |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | - if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) { |
|
| 679 | - $post['tax_input'][ $taxonomy ] = array(); |
|
| 678 | + if ( ! isset( $post['tax_input'][$taxonomy] ) ) { |
|
| 679 | + $post['tax_input'][$taxonomy] = array(); |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | - $post['tax_input'][ $taxonomy ][] = $name; |
|
| 683 | - unset($name); |
|
| 682 | + $post['tax_input'][$taxonomy][] = $name; |
|
| 683 | + unset( $name ); |
|
| 684 | 684 | } |
| 685 | 685 | } |
| 686 | 686 | |
@@ -697,29 +697,29 @@ discard block |
||
| 697 | 697 | |
| 698 | 698 | if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) { |
| 699 | 699 | $match_by['include'] = $post['post_id']; |
| 700 | - unset($match_by['name']); |
|
| 700 | + unset( $match_by['name'] ); |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | - $editing = get_posts($match_by); |
|
| 703 | + $editing = get_posts( $match_by ); |
|
| 704 | 704 | |
| 705 | - if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) { |
|
| 705 | + if ( ! empty( $editing ) && current( $editing )->post_date == $post['post_date'] ) { |
|
| 706 | 706 | // set the id of the post to edit |
| 707 | - $post['ID'] = current($editing)->ID; |
|
| 707 | + $post['ID'] = current( $editing )->ID; |
|
| 708 | 708 | } |
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | private static function update_postmeta( &$post, $post_id ) { |
| 712 | 712 | foreach ( $post['postmeta'] as $k => $v ) { |
| 713 | 713 | if ( '_edit_last' == $k ) { |
| 714 | - $v = FrmAppHelper::get_user_id_param($v); |
|
| 714 | + $v = FrmAppHelper::get_user_id_param( $v ); |
|
| 715 | 715 | } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) { |
| 716 | 716 | //change the attachment ID |
| 717 | - $v = FrmProXMLHelper::get_file_id($v); |
|
| 717 | + $v = FrmProXMLHelper::get_file_id( $v ); |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | - update_post_meta($post_id, $k, $v); |
|
| 720 | + update_post_meta( $post_id, $k, $v ); |
|
| 721 | 721 | |
| 722 | - unset($k, $v); |
|
| 722 | + unset( $k, $v ); |
|
| 723 | 723 | } |
| 724 | 724 | } |
| 725 | 725 | |
@@ -741,13 +741,13 @@ discard block |
||
| 741 | 741 | * @param string $message |
| 742 | 742 | */ |
| 743 | 743 | public static function parse_message( $result, &$message, &$errors ) { |
| 744 | - if ( is_wp_error($result) ) { |
|
| 744 | + if ( is_wp_error( $result ) ) { |
|
| 745 | 745 | $errors[] = $result->get_error_message(); |
| 746 | 746 | } else if ( ! $result ) { |
| 747 | 747 | return; |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - if ( ! is_array($result) ) { |
|
| 750 | + if ( ! is_array( $result ) ) { |
|
| 751 | 751 | $message = is_string( $result ) ? $result : print_r( $result, 1 ); |
| 752 | 752 | return; |
| 753 | 753 | } |
@@ -759,20 +759,20 @@ discard block |
||
| 759 | 759 | |
| 760 | 760 | $message = '<ul>'; |
| 761 | 761 | foreach ( $result as $type => $results ) { |
| 762 | - if ( ! isset( $t_strings[ $type ] ) ) { |
|
| 762 | + if ( ! isset( $t_strings[$type] ) ) { |
|
| 763 | 763 | // only print imported and updated |
| 764 | 764 | continue; |
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | $s_message = array(); |
| 768 | 768 | foreach ( $results as $k => $m ) { |
| 769 | - self::item_count_message($m, $k, $s_message); |
|
| 770 | - unset($k, $m); |
|
| 769 | + self::item_count_message( $m, $k, $s_message ); |
|
| 770 | + unset( $k, $m ); |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | - if ( ! empty($s_message) ) { |
|
| 774 | - $message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> '; |
|
| 775 | - $message .= implode(', ', $s_message); |
|
| 773 | + if ( ! empty( $s_message ) ) { |
|
| 774 | + $message .= '<li><strong>' . $t_strings[$type] . ':</strong> '; |
|
| 775 | + $message .= implode( ', ', $s_message ); |
|
| 776 | 776 | $message .= '</li>'; |
| 777 | 777 | } |
| 778 | 778 | } |
@@ -801,7 +801,7 @@ discard block |
||
| 801 | 801 | 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ), |
| 802 | 802 | ); |
| 803 | 803 | |
| 804 | - $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type ); |
|
| 804 | + $s_message[] = isset( $strings[$type] ) ? $strings[$type] : ' ' . $m . ' ' . ucfirst( $type ); |
|
| 805 | 805 | } |
| 806 | 806 | |
| 807 | 807 | /** |
@@ -833,14 +833,14 @@ discard block |
||
| 833 | 833 | } |
| 834 | 834 | |
| 835 | 835 | public static function cdata( $str ) { |
| 836 | - $str = maybe_unserialize($str); |
|
| 837 | - if ( is_array($str) ) { |
|
| 838 | - $str = json_encode($str); |
|
| 836 | + $str = maybe_unserialize( $str ); |
|
| 837 | + if ( is_array( $str ) ) { |
|
| 838 | + $str = json_encode( $str ); |
|
| 839 | 839 | } else if ( seems_utf8( $str ) == false ) { |
| 840 | 840 | $str = utf8_encode( $str ); |
| 841 | 841 | } |
| 842 | 842 | |
| 843 | - if ( is_numeric($str) ) { |
|
| 843 | + if ( is_numeric( $str ) ) { |
|
| 844 | 844 | return $str; |
| 845 | 845 | } |
| 846 | 846 | |
@@ -885,7 +885,7 @@ discard block |
||
| 885 | 885 | * @param string $post_type |
| 886 | 886 | */ |
| 887 | 887 | private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
| 888 | - if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) { |
|
| 888 | + if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) { |
|
| 889 | 889 | return; |
| 890 | 890 | } |
| 891 | 891 | |
@@ -906,10 +906,10 @@ discard block |
||
| 906 | 906 | ); |
| 907 | 907 | |
| 908 | 908 | foreach ( $post_settings as $post_setting ) { |
| 909 | - if ( isset( $form_options[ $post_setting ] ) ) { |
|
| 910 | - $new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ]; |
|
| 909 | + if ( isset( $form_options[$post_setting] ) ) { |
|
| 910 | + $new_action['post_content'][$post_setting] = $form_options[$post_setting]; |
|
| 911 | 911 | } |
| 912 | - unset($post_setting); |
|
| 912 | + unset( $post_setting ); |
|
| 913 | 913 | } |
| 914 | 914 | |
| 915 | 915 | $new_action['event'] = array( 'create', 'update' ); |
@@ -923,7 +923,7 @@ discard block |
||
| 923 | 923 | |
| 924 | 924 | $new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields ); |
| 925 | 925 | } |
| 926 | - $new_action['post_content'] = json_encode($new_action['post_content']); |
|
| 926 | + $new_action['post_content'] = json_encode( $new_action['post_content'] ); |
|
| 927 | 927 | |
| 928 | 928 | $exists = get_posts( array( |
| 929 | 929 | 'name' => $new_action['post_name'], |
@@ -935,7 +935,7 @@ discard block |
||
| 935 | 935 | if ( ! $exists ) { |
| 936 | 936 | // this isn't an email, but we need to use a class that will always be included |
| 937 | 937 | FrmAppHelper::save_json_post( $new_action ); |
| 938 | - $imported['imported']['actions']++; |
|
| 938 | + $imported['imported']['actions'] ++; |
|
| 939 | 939 | } |
| 940 | 940 | } |
| 941 | 941 | |
@@ -967,11 +967,11 @@ discard block |
||
| 967 | 967 | foreach ( $post_content as $key => $setting ) { |
| 968 | 968 | if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) { |
| 969 | 969 | // Replace old IDs with new IDs |
| 970 | - $post_content[ $key ] = str_replace( $old, $new, $setting ); |
|
| 970 | + $post_content[$key] = str_replace( $old, $new, $setting ); |
|
| 971 | 971 | } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) { |
| 972 | 972 | foreach ( $setting as $k => $val ) { |
| 973 | 973 | // Replace old IDs with new IDs |
| 974 | - $post_content[ $key ][ $k ] = str_replace( $old, $new, $val ); |
|
| 974 | + $post_content[$key][$k] = str_replace( $old, $new, $val ); |
|
| 975 | 975 | } |
| 976 | 976 | } |
| 977 | 977 | unset( $key, $setting ); |
@@ -994,14 +994,14 @@ discard block |
||
| 994 | 994 | // Migrate autoresponders |
| 995 | 995 | self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications ); |
| 996 | 996 | |
| 997 | - if ( empty( $notifications ) ) { |
|
| 997 | + if ( empty( $notifications ) ) { |
|
| 998 | 998 | return; |
| 999 | 999 | } |
| 1000 | 1000 | |
| 1001 | 1001 | foreach ( $notifications as $new_notification ) { |
| 1002 | 1002 | $new_notification['post_type'] = $post_type; |
| 1003 | 1003 | $new_notification['post_excerpt'] = 'email'; |
| 1004 | - $new_notification['post_title'] = __( 'Email Notification', 'formidable' ); |
|
| 1004 | + $new_notification['post_title'] = __( 'Email Notification', 'formidable' ); |
|
| 1005 | 1005 | $new_notification['menu_order'] = $form_id; |
| 1006 | 1006 | $new_notification['post_status'] = 'publish'; |
| 1007 | 1007 | |
@@ -1014,7 +1014,7 @@ discard block |
||
| 1014 | 1014 | // Switch all other field IDs in email |
| 1015 | 1015 | $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] ); |
| 1016 | 1016 | } |
| 1017 | - $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
| 1017 | + $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
| 1018 | 1018 | |
| 1019 | 1019 | $exists = get_posts( array( |
| 1020 | 1020 | 'name' => $new_notification['post_name'], |
@@ -1023,11 +1023,11 @@ discard block |
||
| 1023 | 1023 | 'numberposts' => 1, |
| 1024 | 1024 | ) ); |
| 1025 | 1025 | |
| 1026 | - if ( empty($exists) ) { |
|
| 1026 | + if ( empty( $exists ) ) { |
|
| 1027 | 1027 | FrmAppHelper::save_json_post( $new_notification ); |
| 1028 | - $imported['imported']['actions']++; |
|
| 1028 | + $imported['imported']['actions'] ++; |
|
| 1029 | 1029 | } |
| 1030 | - unset($new_notification); |
|
| 1030 | + unset( $new_notification ); |
|
| 1031 | 1031 | } |
| 1032 | 1032 | } |
| 1033 | 1033 | |
@@ -1040,7 +1040,7 @@ discard block |
||
| 1040 | 1040 | $form_options['notification'] = array( 0 => $form_options['notification'] ); |
| 1041 | 1041 | } |
| 1042 | 1042 | |
| 1043 | - if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) { |
|
| 1043 | + if ( isset( $form_options['notification'] ) && is_array( $form_options['notification'] ) ) { |
|
| 1044 | 1044 | foreach ( $form_options['notification'] as $email_key => $notification ) { |
| 1045 | 1045 | |
| 1046 | 1046 | $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key ); |
@@ -1068,12 +1068,12 @@ discard block |
||
| 1068 | 1068 | // Format the reply to email and name |
| 1069 | 1069 | $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' ); |
| 1070 | 1070 | foreach ( $reply_fields as $f => $val ) { |
| 1071 | - if ( isset( $notification[ $f ] ) ) { |
|
| 1072 | - $atts[ $f ] = $notification[ $f ]; |
|
| 1073 | - if ( 'custom' == $notification[ $f ] ) { |
|
| 1074 | - $atts[ $f ] = $notification[ 'cust_' . $f ]; |
|
| 1075 | - } else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) { |
|
| 1076 | - $atts[ $f ] = '[' . $atts[ $f ] . ']'; |
|
| 1071 | + if ( isset( $notification[$f] ) ) { |
|
| 1072 | + $atts[$f] = $notification[$f]; |
|
| 1073 | + if ( 'custom' == $notification[$f] ) { |
|
| 1074 | + $atts[$f] = $notification['cust_' . $f]; |
|
| 1075 | + } else if ( is_numeric( $atts[$f] ) && ! empty( $atts[$f] ) ) { |
|
| 1076 | + $atts[$f] = '[' . $atts[$f] . ']'; |
|
| 1077 | 1077 | } |
| 1078 | 1078 | } |
| 1079 | 1079 | unset( $f, $val ); |
@@ -1083,7 +1083,7 @@ discard block |
||
| 1083 | 1083 | $atts['event'] = array( 'create' ); |
| 1084 | 1084 | if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) { |
| 1085 | 1085 | $atts['event'][] = 'update'; |
| 1086 | - } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) { |
|
| 1086 | + } else if ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) { |
|
| 1087 | 1087 | $atts['event'] = array( 'update' ); |
| 1088 | 1088 | } |
| 1089 | 1089 | } |
@@ -1104,18 +1104,18 @@ discard block |
||
| 1104 | 1104 | foreach ( $atts['email_to'] as $key => $email_field ) { |
| 1105 | 1105 | |
| 1106 | 1106 | if ( is_numeric( $email_field ) ) { |
| 1107 | - $atts['email_to'][ $key ] = '[' . $email_field . ']'; |
|
| 1107 | + $atts['email_to'][$key] = '[' . $email_field . ']'; |
|
| 1108 | 1108 | } |
| 1109 | 1109 | |
| 1110 | - if ( strpos( $email_field, '|') ) { |
|
| 1110 | + if ( strpos( $email_field, '|' ) ) { |
|
| 1111 | 1111 | $email_opt = explode( '|', $email_field ); |
| 1112 | 1112 | if ( isset( $email_opt[0] ) ) { |
| 1113 | - $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']'; |
|
| 1113 | + $atts['email_to'][$key] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']'; |
|
| 1114 | 1114 | } |
| 1115 | 1115 | unset( $email_opt ); |
| 1116 | 1116 | } |
| 1117 | 1117 | } |
| 1118 | - $atts['email_to'] = implode(', ', $atts['email_to']); |
|
| 1118 | + $atts['email_to'] = implode( ', ', $atts['email_to'] ); |
|
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | 1121 | private static function setup_new_notification( &$new_notification, $notification, $atts ) { |
@@ -1131,12 +1131,12 @@ discard block |
||
| 1131 | 1131 | // Add more fields to the new notification |
| 1132 | 1132 | $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' ); |
| 1133 | 1133 | foreach ( $add_fields as $add_field ) { |
| 1134 | - if ( isset( $notification[ $add_field ] ) ) { |
|
| 1135 | - $new_notification['post_content'][ $add_field ] = $notification[ $add_field ]; |
|
| 1134 | + if ( isset( $notification[$add_field] ) ) { |
|
| 1135 | + $new_notification['post_content'][$add_field] = $notification[$add_field]; |
|
| 1136 | 1136 | } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) { |
| 1137 | - $new_notification['post_content'][ $add_field ] = 0; |
|
| 1137 | + $new_notification['post_content'][$add_field] = 0; |
|
| 1138 | 1138 | } else { |
| 1139 | - $new_notification['post_content'][ $add_field ] = ''; |
|
| 1139 | + $new_notification['post_content'][$add_field] = ''; |
|
| 1140 | 1140 | } |
| 1141 | 1141 | unset( $add_field ); |
| 1142 | 1142 | } |
@@ -1160,26 +1160,26 @@ discard block |
||
| 1160 | 1160 | if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) { |
| 1161 | 1161 | foreach ( $post_content['conditions'] as $email_key => $val ) { |
| 1162 | 1162 | if ( is_numeric( $email_key ) ) { |
| 1163 | - $post_content['conditions'][ $email_key ] = self::switch_action_field_ids( $val, array( 'hide_field' ) ); |
|
| 1163 | + $post_content['conditions'][$email_key] = self::switch_action_field_ids( $val, array( 'hide_field' ) ); |
|
| 1164 | 1164 | } |
| 1165 | - unset( $email_key, $val); |
|
| 1165 | + unset( $email_key, $val ); |
|
| 1166 | 1166 | } |
| 1167 | 1167 | } |
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | 1170 | private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) { |
| 1171 | - if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) { |
|
| 1171 | + if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) { |
|
| 1172 | 1172 | // migrate autoresponder |
| 1173 | 1173 | |
| 1174 | - $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0; |
|
| 1175 | - if ( strpos($email_field, '|') ) { |
|
| 1174 | + $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0; |
|
| 1175 | + if ( strpos( $email_field, '|' ) ) { |
|
| 1176 | 1176 | // data from entries field |
| 1177 | - $email_field = explode('|', $email_field); |
|
| 1178 | - if ( isset($email_field[1]) ) { |
|
| 1177 | + $email_field = explode( '|', $email_field ); |
|
| 1178 | + if ( isset( $email_field[1] ) ) { |
|
| 1179 | 1179 | $email_field = $email_field[1]; |
| 1180 | 1180 | } |
| 1181 | 1181 | } |
| 1182 | - if ( is_numeric($email_field) && ! empty($email_field) ) { |
|
| 1182 | + if ( is_numeric( $email_field ) && ! empty( $email_field ) ) { |
|
| 1183 | 1183 | $email_field = '[' . $email_field . ']'; |
| 1184 | 1184 | } |
| 1185 | 1185 | |
@@ -1187,16 +1187,16 @@ discard block |
||
| 1187 | 1187 | $new_notification2 = array( |
| 1188 | 1188 | 'post_content' => array( |
| 1189 | 1189 | 'email_message' => $notification['ar_email_message'], |
| 1190 | - 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '', |
|
| 1190 | + 'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '', |
|
| 1191 | 1191 | 'email_to' => $email_field, |
| 1192 | - 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0, |
|
| 1192 | + 'plain_text' => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0, |
|
| 1193 | 1193 | 'inc_user_info' => 0, |
| 1194 | 1194 | ), |
| 1195 | 1195 | 'post_name' => $form_id . '_email_' . count( $notifications ), |
| 1196 | 1196 | ); |
| 1197 | 1197 | |
| 1198 | - $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : ''; |
|
| 1199 | - $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : ''; |
|
| 1198 | + $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : ''; |
|
| 1199 | + $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : ''; |
|
| 1200 | 1200 | |
| 1201 | 1201 | if ( ! empty( $reply_to ) ) { |
| 1202 | 1202 | $new_notification2['post_content']['reply_to'] = $reply_to; |