@@ -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,61 +272,61 @@ 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 | foreach ( $xml_fields as $field ) { |
| 282 | - $f = array( |
|
| 283 | - 'id' => (int) $field->id, |
|
| 284 | - 'field_key' => (string) $field->field_key, |
|
| 285 | - 'name' => (string) $field->name, |
|
| 286 | - 'description' => (string) $field->description, |
|
| 287 | - 'type' => (string) $field->type, |
|
| 288 | - 'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value), |
|
| 289 | - 'field_order' => (int) $field->field_order, |
|
| 290 | - 'form_id' => (int) $form_id, |
|
| 291 | - 'required' => (int) $field->required, |
|
| 292 | - 'options' => FrmAppHelper::maybe_json_decode( (string) $field->options), |
|
| 282 | + $f = array( |
|
| 283 | + 'id' => (int) $field->id, |
|
| 284 | + 'field_key' => (string) $field->field_key, |
|
| 285 | + 'name' => (string) $field->name, |
|
| 286 | + 'description' => (string) $field->description, |
|
| 287 | + 'type' => (string) $field->type, |
|
| 288 | + 'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value), |
|
| 289 | + 'field_order' => (int) $field->field_order, |
|
| 290 | + 'form_id' => (int) $form_id, |
|
| 291 | + 'required' => (int) $field->required, |
|
| 292 | + 'options' => FrmAppHelper::maybe_json_decode( (string) $field->options), |
|
| 293 | 293 | 'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ), |
| 294 | - ); |
|
| 295 | - |
|
| 296 | - if ( is_array($f['default_value']) && in_array($f['type'], array( |
|
| 297 | - 'text', 'email', 'url', 'textarea', |
|
| 298 | - 'number','phone', 'date', 'time', |
|
| 299 | - 'hidden', 'password', 'tag', 'image', |
|
| 300 | - )) ) { |
|
| 301 | - if ( count($f['default_value']) === 1 ) { |
|
| 302 | - $f['default_value'] = '['. reset($f['default_value']) .']'; |
|
| 303 | - } else { |
|
| 304 | - $f['default_value'] = reset($f['default_value']); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - $f = apply_filters('frm_duplicated_field', $f); |
|
| 294 | + ); |
|
| 295 | + |
|
| 296 | + if ( is_array($f['default_value']) && in_array($f['type'], array( |
|
| 297 | + 'text', 'email', 'url', 'textarea', |
|
| 298 | + 'number','phone', 'date', 'time', |
|
| 299 | + 'hidden', 'password', 'tag', 'image', |
|
| 300 | + )) ) { |
|
| 301 | + if ( count($f['default_value']) === 1 ) { |
|
| 302 | + $f['default_value'] = '['. reset($f['default_value']) .']'; |
|
| 303 | + } else { |
|
| 304 | + $f['default_value'] = reset($f['default_value']); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + $f = apply_filters('frm_duplicated_field', $f); |
|
| 309 | 309 | |
| 310 | 310 | self::maybe_update_form_select( $f, $imported ); |
| 311 | 311 | |
| 312 | - if ( ! empty($this_form) ) { |
|
| 313 | - // check for field to edit by field id |
|
| 312 | + if ( ! empty($this_form) ) { |
|
| 313 | + // check for field to edit by field id |
|
| 314 | 314 | if ( isset( $form_fields[ $f['id'] ] ) ) { |
| 315 | - FrmField::update( $f['id'], $f ); |
|
| 316 | - $imported['updated']['fields']++; |
|
| 315 | + FrmField::update( $f['id'], $f ); |
|
| 316 | + $imported['updated']['fields']++; |
|
| 317 | 317 | |
| 318 | 318 | unset( $form_fields[ $f['id'] ] ); |
| 319 | 319 | |
| 320 | - //unset old field key |
|
| 320 | + //unset old field key |
|
| 321 | 321 | if ( isset( $form_fields[ $f['field_key'] ] ) ) { |
| 322 | 322 | unset( $form_fields[ $f['field_key'] ] ); |
| 323 | 323 | } |
| 324 | 324 | } else if ( isset( $form_fields[ $f['field_key'] ] ) ) { |
| 325 | - // check for field to edit by field key |
|
| 326 | - unset($f['id']); |
|
| 325 | + // check for field to edit by field key |
|
| 326 | + unset($f['id']); |
|
| 327 | 327 | |
| 328 | 328 | FrmField::update( $form_fields[ $f['field_key'] ], $f ); |
| 329 | - $imported['updated']['fields']++; |
|
| 329 | + $imported['updated']['fields']++; |
|
| 330 | 330 | |
| 331 | 331 | unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id |
| 332 | 332 | unset( $form_fields[ $f['field_key'] ] ); //unset old field key |
@@ -336,29 +336,29 @@ discard block |
||
| 336 | 336 | continue; |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - // if no matching field id or key in this form, create the field |
|
| 340 | - $imported['imported']['fields']++; |
|
| 341 | - } |
|
| 339 | + // if no matching field id or key in this form, create the field |
|
| 340 | + $imported['imported']['fields']++; |
|
| 341 | + } |
|
| 342 | 342 | } else { |
| 343 | 343 | $new_id = FrmField::create( $f ); |
| 344 | 344 | if ( $new_id == false ) { |
| 345 | 345 | continue; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - $imported['imported']['fields']++; |
|
| 349 | - } |
|
| 348 | + $imported['imported']['fields']++; |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | 351 | unset($field, $new_id); |
| 352 | 352 | } |
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
| 356 | - * Switch the form_select on a repeating field or embedded form if it needs to be switched |
|
| 357 | - * |
|
| 358 | - * @since 2.0.16 |
|
| 359 | - * @param array $f |
|
| 360 | - * @param array $imported |
|
| 361 | - */ |
|
| 356 | + * Switch the form_select on a repeating field or embedded form if it needs to be switched |
|
| 357 | + * |
|
| 358 | + * @since 2.0.16 |
|
| 359 | + * @param array $f |
|
| 360 | + * @param array $imported |
|
| 361 | + */ |
|
| 362 | 362 | private static function maybe_update_form_select( &$f, $imported ) { |
| 363 | 363 | if ( ! isset( $imported['forms'] ) ) { |
| 364 | 364 | return; |
@@ -375,12 +375,12 @@ discard block |
||
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | /** |
| 378 | - * Updates the custom style setting on import |
|
| 379 | - * |
|
| 380 | - * @since 2.0.19 |
|
| 381 | - * @param array $form |
|
| 382 | - * |
|
| 383 | - */ |
|
| 378 | + * Updates the custom style setting on import |
|
| 379 | + * |
|
| 380 | + * @since 2.0.19 |
|
| 381 | + * @param array $form |
|
| 382 | + * |
|
| 383 | + */ |
|
| 384 | 384 | private static function update_custom_style_setting_on_import( &$form ) { |
| 385 | 385 | if ( is_numeric( $form['options']['custom_style'] ) ) { |
| 386 | 386 | // Set to default |
@@ -407,16 +407,16 @@ discard block |
||
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | public static function import_xml_views( $views, $imported ) { |
| 410 | - $imported['posts'] = array(); |
|
| 411 | - $form_action_type = FrmFormActionsController::$action_post_type; |
|
| 410 | + $imported['posts'] = array(); |
|
| 411 | + $form_action_type = FrmFormActionsController::$action_post_type; |
|
| 412 | 412 | |
| 413 | - $post_types = array( |
|
| 414 | - 'frm_display' => 'views', |
|
| 415 | - $form_action_type => 'actions', |
|
| 416 | - 'frm_styles' => 'styles', |
|
| 417 | - ); |
|
| 413 | + $post_types = array( |
|
| 414 | + 'frm_display' => 'views', |
|
| 415 | + $form_action_type => 'actions', |
|
| 416 | + 'frm_styles' => 'styles', |
|
| 417 | + ); |
|
| 418 | 418 | |
| 419 | - foreach ( $views as $item ) { |
|
| 419 | + foreach ( $views as $item ) { |
|
| 420 | 420 | $post = array( |
| 421 | 421 | 'post_title' => (string) $item->title, |
| 422 | 422 | 'post_name' => (string) $item->post_name, |
@@ -435,52 +435,52 @@ discard block |
||
| 435 | 435 | 'post_date' => (string) $item->post_date, |
| 436 | 436 | 'post_date_gmt' => (string) $item->post_date_gmt, |
| 437 | 437 | 'ping_status' => (string) $item->ping_status, |
| 438 | - 'postmeta' => array(), |
|
| 439 | - 'tax_input' => array(), |
|
| 438 | + 'postmeta' => array(), |
|
| 439 | + 'tax_input' => array(), |
|
| 440 | 440 | ); |
| 441 | 441 | |
| 442 | - $old_id = $post['post_id']; |
|
| 443 | - self::populate_post($post, $item, $imported); |
|
| 442 | + $old_id = $post['post_id']; |
|
| 443 | + self::populate_post($post, $item, $imported); |
|
| 444 | 444 | |
| 445 | 445 | unset($item); |
| 446 | 446 | |
| 447 | 447 | $post_id = false; |
| 448 | - if ( $post['post_type'] == $form_action_type ) { |
|
| 449 | - $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] ); |
|
| 448 | + if ( $post['post_type'] == $form_action_type ) { |
|
| 449 | + $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] ); |
|
| 450 | 450 | if ( $action_control ) { |
| 451 | 451 | $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] ); |
| 452 | 452 | } |
| 453 | - unset($action_control); |
|
| 454 | - } else if ( $post['post_type'] == 'frm_styles' ) { |
|
| 455 | - // Properly encode post content before inserting the post |
|
| 456 | - $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
|
| 457 | - $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] ); |
|
| 458 | - |
|
| 459 | - // Create/update post now |
|
| 460 | - $post_id = wp_insert_post( $post ); |
|
| 461 | - } else { |
|
| 462 | - // Create/update post now |
|
| 463 | - $post_id = wp_insert_post( $post ); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - if ( ! is_numeric($post_id) ) { |
|
| 467 | - continue; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - self::update_postmeta($post, $post_id); |
|
| 471 | - |
|
| 472 | - $this_type = 'posts'; |
|
| 453 | + unset($action_control); |
|
| 454 | + } else if ( $post['post_type'] == 'frm_styles' ) { |
|
| 455 | + // Properly encode post content before inserting the post |
|
| 456 | + $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
|
| 457 | + $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] ); |
|
| 458 | + |
|
| 459 | + // Create/update post now |
|
| 460 | + $post_id = wp_insert_post( $post ); |
|
| 461 | + } else { |
|
| 462 | + // Create/update post now |
|
| 463 | + $post_id = wp_insert_post( $post ); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + if ( ! is_numeric($post_id) ) { |
|
| 467 | + continue; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + self::update_postmeta($post, $post_id); |
|
| 471 | + |
|
| 472 | + $this_type = 'posts'; |
|
| 473 | 473 | if ( isset( $post_types[ $post['post_type'] ] ) ) { |
| 474 | 474 | $this_type = $post_types[ $post['post_type'] ]; |
| 475 | - } |
|
| 475 | + } |
|
| 476 | 476 | |
| 477 | - if ( isset($post['ID']) && $post_id == $post['ID'] ) { |
|
| 478 | - $imported['updated'][ $this_type ]++; |
|
| 479 | - } else { |
|
| 480 | - $imported['imported'][ $this_type ]++; |
|
| 481 | - } |
|
| 477 | + if ( isset($post['ID']) && $post_id == $post['ID'] ) { |
|
| 478 | + $imported['updated'][ $this_type ]++; |
|
| 479 | + } else { |
|
| 480 | + $imported['imported'][ $this_type ]++; |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | - unset($post); |
|
| 483 | + unset($post); |
|
| 484 | 484 | |
| 485 | 485 | $imported['posts'][ (int) $old_id ] = $post_id; |
| 486 | 486 | } |
@@ -488,157 +488,157 @@ discard block |
||
| 488 | 488 | self::maybe_update_stylesheet( $imported ); |
| 489 | 489 | |
| 490 | 490 | return $imported; |
| 491 | - } |
|
| 491 | + } |
|
| 492 | 492 | |
| 493 | - private static function populate_post( &$post, $item, $imported ) { |
|
| 493 | + private static function populate_post( &$post, $item, $imported ) { |
|
| 494 | 494 | if ( isset($item->attachment_url) ) { |
| 495 | 495 | $post['attachment_url'] = (string) $item->attachment_url; |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) { |
| 499 | - // update to new form id |
|
| 500 | - $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ]; |
|
| 499 | + // update to new form id |
|
| 500 | + $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ]; |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | foreach ( $item->postmeta as $meta ) { |
| 504 | - self::populate_postmeta($post, $meta, $imported); |
|
| 504 | + self::populate_postmeta($post, $meta, $imported); |
|
| 505 | 505 | unset($meta); |
| 506 | 506 | } |
| 507 | 507 | |
| 508 | - self::populate_taxonomies($post, $item); |
|
| 508 | + self::populate_taxonomies($post, $item); |
|
| 509 | 509 | |
| 510 | - self::maybe_editing_post($post); |
|
| 511 | - } |
|
| 510 | + self::maybe_editing_post($post); |
|
| 511 | + } |
|
| 512 | 512 | |
| 513 | - private static function populate_postmeta( &$post, $meta, $imported ) { |
|
| 514 | - global $frm_duplicate_ids; |
|
| 513 | + private static function populate_postmeta( &$post, $meta, $imported ) { |
|
| 514 | + global $frm_duplicate_ids; |
|
| 515 | 515 | |
| 516 | - $m = array( |
|
| 516 | + $m = array( |
|
| 517 | 517 | 'key' => (string) $meta->meta_key, |
| 518 | 518 | 'value' => (string) $meta->meta_value, |
| 519 | 519 | ); |
| 520 | 520 | |
| 521 | 521 | //switch old form and field ids to new ones |
| 522 | 522 | if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) { |
| 523 | - $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
|
| 523 | + $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
|
| 524 | 524 | } else { |
| 525 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
| 525 | + $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
| 526 | 526 | |
| 527 | - if ( ! empty($frm_duplicate_ids) ) { |
|
| 527 | + if ( ! empty($frm_duplicate_ids) ) { |
|
| 528 | 528 | |
| 529 | - if ( $m['key'] == 'frm_dyncontent' ) { |
|
| 530 | - $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); |
|
| 531 | - } else if ( $m['key'] == 'frm_options' ) { |
|
| 529 | + if ( $m['key'] == 'frm_dyncontent' ) { |
|
| 530 | + $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); |
|
| 531 | + } else if ( $m['key'] == 'frm_options' ) { |
|
| 532 | 532 | |
| 533 | 533 | foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) { |
| 534 | 534 | if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) { |
| 535 | 535 | $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ]; |
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - $check_dup_array = array(); |
|
| 540 | - if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { |
|
| 541 | - if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
|
| 542 | - $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
|
| 543 | - } else if ( is_array( $m['value']['order_by'] ) ) { |
|
| 544 | - $check_dup_array[] = 'order_by'; |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) { |
|
| 549 | - $check_dup_array[] = 'where'; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - foreach ( $check_dup_array as $check_k ) { |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + $check_dup_array = array(); |
|
| 540 | + if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { |
|
| 541 | + if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
|
| 542 | + $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
|
| 543 | + } else if ( is_array( $m['value']['order_by'] ) ) { |
|
| 544 | + $check_dup_array[] = 'order_by'; |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) { |
|
| 549 | + $check_dup_array[] = 'where'; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + foreach ( $check_dup_array as $check_k ) { |
|
| 553 | 553 | foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) { |
| 554 | 554 | if ( isset( $frm_duplicate_ids[ $mv ] ) ) { |
| 555 | 555 | $m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ]; |
| 556 | - } |
|
| 557 | - unset($mk, $mv); |
|
| 558 | - } |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - } |
|
| 556 | + } |
|
| 557 | + unset($mk, $mv); |
|
| 558 | + } |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | if ( ! is_array($m['value']) ) { |
| 565 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
| 565 | + $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | $post['postmeta'][ (string) $meta->meta_key ] = $m['value']; |
| 569 | - } |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * Add terms to post |
|
| 573 | - * @param array $post by reference |
|
| 574 | - * @param object $item The XML object data |
|
| 575 | - */ |
|
| 576 | - private static function populate_taxonomies( &$post, $item ) { |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * Add terms to post |
|
| 573 | + * @param array $post by reference |
|
| 574 | + * @param object $item The XML object data |
|
| 575 | + */ |
|
| 576 | + private static function populate_taxonomies( &$post, $item ) { |
|
| 577 | 577 | foreach ( $item->category as $c ) { |
| 578 | 578 | $att = $c->attributes(); |
| 579 | 579 | if ( ! isset( $att['nicename'] ) ) { |
| 580 | - continue; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - $taxonomy = (string) $att['domain']; |
|
| 584 | - if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
| 585 | - $name = (string) $att['nicename']; |
|
| 586 | - $h_term = get_term_by('slug', $name, $taxonomy); |
|
| 587 | - if ( $h_term ) { |
|
| 588 | - $name = $h_term->term_id; |
|
| 589 | - } |
|
| 590 | - unset($h_term); |
|
| 591 | - } else { |
|
| 592 | - $name = (string) $c; |
|
| 593 | - } |
|
| 580 | + continue; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + $taxonomy = (string) $att['domain']; |
|
| 584 | + if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
| 585 | + $name = (string) $att['nicename']; |
|
| 586 | + $h_term = get_term_by('slug', $name, $taxonomy); |
|
| 587 | + if ( $h_term ) { |
|
| 588 | + $name = $h_term->term_id; |
|
| 589 | + } |
|
| 590 | + unset($h_term); |
|
| 591 | + } else { |
|
| 592 | + $name = (string) $c; |
|
| 593 | + } |
|
| 594 | 594 | |
| 595 | 595 | if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) { |
| 596 | 596 | $post['tax_input'][ $taxonomy ] = array(); |
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | $post['tax_input'][ $taxonomy ][] = $name; |
| 600 | - unset($name); |
|
| 600 | + unset($name); |
|
| 601 | 601 | } |
| 602 | - } |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | - /** |
|
| 605 | - * Edit post if the key and created time match |
|
| 606 | - */ |
|
| 607 | - private static function maybe_editing_post( &$post ) { |
|
| 604 | + /** |
|
| 605 | + * Edit post if the key and created time match |
|
| 606 | + */ |
|
| 607 | + private static function maybe_editing_post( &$post ) { |
|
| 608 | 608 | $match_by = array( |
| 609 | - 'post_type' => $post['post_type'], |
|
| 610 | - 'name' => $post['post_name'], |
|
| 611 | - 'post_status' => $post['post_status'], |
|
| 612 | - 'posts_per_page' => 1, |
|
| 609 | + 'post_type' => $post['post_type'], |
|
| 610 | + 'name' => $post['post_name'], |
|
| 611 | + 'post_status' => $post['post_status'], |
|
| 612 | + 'posts_per_page' => 1, |
|
| 613 | 613 | ); |
| 614 | 614 | |
| 615 | 615 | if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) { |
| 616 | - $match_by['include'] = $post['post_id']; |
|
| 617 | - unset($match_by['name']); |
|
| 616 | + $match_by['include'] = $post['post_id']; |
|
| 617 | + unset($match_by['name']); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | $editing = get_posts($match_by); |
| 621 | 621 | |
| 622 | - if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) { |
|
| 623 | - // set the id of the post to edit |
|
| 624 | - $post['ID'] = current($editing)->ID; |
|
| 625 | - } |
|
| 626 | - } |
|
| 622 | + if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) { |
|
| 623 | + // set the id of the post to edit |
|
| 624 | + $post['ID'] = current($editing)->ID; |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | 627 | |
| 628 | - private static function update_postmeta( &$post, $post_id ) { |
|
| 629 | - foreach ( $post['postmeta'] as $k => $v ) { |
|
| 630 | - if ( '_edit_last' == $k ) { |
|
| 631 | - $v = FrmAppHelper::get_user_id_param($v); |
|
| 632 | - } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) { |
|
| 633 | - //change the attachment ID |
|
| 634 | - $v = FrmProXMLHelper::get_file_id($v); |
|
| 635 | - } |
|
| 628 | + private static function update_postmeta( &$post, $post_id ) { |
|
| 629 | + foreach ( $post['postmeta'] as $k => $v ) { |
|
| 630 | + if ( '_edit_last' == $k ) { |
|
| 631 | + $v = FrmAppHelper::get_user_id_param($v); |
|
| 632 | + } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) { |
|
| 633 | + //change the attachment ID |
|
| 634 | + $v = FrmProXMLHelper::get_file_id($v); |
|
| 635 | + } |
|
| 636 | 636 | |
| 637 | - update_post_meta($post_id, $k, $v); |
|
| 637 | + update_post_meta($post_id, $k, $v); |
|
| 638 | 638 | |
| 639 | - unset($k, $v); |
|
| 640 | - } |
|
| 641 | - } |
|
| 639 | + unset($k, $v); |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | 642 | |
| 643 | 643 | private static function maybe_update_stylesheet( $imported ) { |
| 644 | 644 | if ( ( isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] ) ) || ( isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] ) ) ) { |
@@ -649,72 +649,72 @@ discard block |
||
| 649 | 649 | } |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | - /** |
|
| 653 | - * @param string $message |
|
| 654 | - */ |
|
| 652 | + /** |
|
| 653 | + * @param string $message |
|
| 654 | + */ |
|
| 655 | 655 | public static function parse_message( $result, &$message, &$errors ) { |
| 656 | - if ( is_wp_error($result) ) { |
|
| 657 | - $errors[] = $result->get_error_message(); |
|
| 658 | - } else if ( ! $result ) { |
|
| 659 | - return; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - if ( ! is_array($result) ) { |
|
| 663 | - $message = is_string( $result ) ? $result : print_r( $result, 1 ); |
|
| 664 | - return; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - $t_strings = array( |
|
| 668 | - 'imported' => __( 'Imported', 'formidable' ), |
|
| 669 | - 'updated' => __( 'Updated', 'formidable' ), |
|
| 670 | - ); |
|
| 671 | - |
|
| 672 | - $message = '<ul>'; |
|
| 673 | - foreach ( $result as $type => $results ) { |
|
| 656 | + if ( is_wp_error($result) ) { |
|
| 657 | + $errors[] = $result->get_error_message(); |
|
| 658 | + } else if ( ! $result ) { |
|
| 659 | + return; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + if ( ! is_array($result) ) { |
|
| 663 | + $message = is_string( $result ) ? $result : print_r( $result, 1 ); |
|
| 664 | + return; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + $t_strings = array( |
|
| 668 | + 'imported' => __( 'Imported', 'formidable' ), |
|
| 669 | + 'updated' => __( 'Updated', 'formidable' ), |
|
| 670 | + ); |
|
| 671 | + |
|
| 672 | + $message = '<ul>'; |
|
| 673 | + foreach ( $result as $type => $results ) { |
|
| 674 | 674 | if ( ! isset( $t_strings[ $type ] ) ) { |
| 675 | - // only print imported and updated |
|
| 676 | - continue; |
|
| 677 | - } |
|
| 675 | + // only print imported and updated |
|
| 676 | + continue; |
|
| 677 | + } |
|
| 678 | 678 | |
| 679 | - $s_message = array(); |
|
| 680 | - foreach ( $results as $k => $m ) { |
|
| 681 | - self::item_count_message($m, $k, $s_message); |
|
| 682 | - unset($k, $m); |
|
| 683 | - } |
|
| 679 | + $s_message = array(); |
|
| 680 | + foreach ( $results as $k => $m ) { |
|
| 681 | + self::item_count_message($m, $k, $s_message); |
|
| 682 | + unset($k, $m); |
|
| 683 | + } |
|
| 684 | 684 | |
| 685 | - if ( ! empty($s_message) ) { |
|
| 685 | + if ( ! empty($s_message) ) { |
|
| 686 | 686 | $message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> '; |
| 687 | - $message .= implode(', ', $s_message); |
|
| 688 | - $message .= '</li>'; |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - if ( $message == '<ul>' ) { |
|
| 693 | - $message = ''; |
|
| 694 | - $errors[] = __( 'Nothing was imported or updated', 'formidable' ); |
|
| 695 | - } else { |
|
| 696 | - $message .= '</ul>'; |
|
| 697 | - } |
|
| 698 | - } |
|
| 687 | + $message .= implode(', ', $s_message); |
|
| 688 | + $message .= '</li>'; |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + if ( $message == '<ul>' ) { |
|
| 693 | + $message = ''; |
|
| 694 | + $errors[] = __( 'Nothing was imported or updated', 'formidable' ); |
|
| 695 | + } else { |
|
| 696 | + $message .= '</ul>'; |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | 699 | |
| 700 | 700 | public static function item_count_message( $m, $type, &$s_message ) { |
| 701 | - if ( ! $m ) { |
|
| 702 | - return; |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - $strings = array( |
|
| 706 | - 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ), |
|
| 707 | - 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ), |
|
| 708 | - 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ), |
|
| 709 | - 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ), |
|
| 710 | - 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ), |
|
| 711 | - 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ), |
|
| 712 | - 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ), |
|
| 713 | - 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ), |
|
| 714 | - ); |
|
| 701 | + if ( ! $m ) { |
|
| 702 | + return; |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + $strings = array( |
|
| 706 | + 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ), |
|
| 707 | + 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ), |
|
| 708 | + 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ), |
|
| 709 | + 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ), |
|
| 710 | + 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ), |
|
| 711 | + 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ), |
|
| 712 | + 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ), |
|
| 713 | + 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ), |
|
| 714 | + ); |
|
| 715 | 715 | |
| 716 | 716 | $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type ); |
| 717 | - } |
|
| 717 | + } |
|
| 718 | 718 | |
| 719 | 719 | /** |
| 720 | 720 | * Prepare the form options for export |
@@ -745,16 +745,16 @@ discard block |
||
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | public static function cdata( $str ) { |
| 748 | - $str = maybe_unserialize($str); |
|
| 749 | - if ( is_array($str) ) { |
|
| 750 | - $str = json_encode($str); |
|
| 748 | + $str = maybe_unserialize($str); |
|
| 749 | + if ( is_array($str) ) { |
|
| 750 | + $str = json_encode($str); |
|
| 751 | 751 | } else if ( seems_utf8( $str ) == false ) { |
| 752 | 752 | $str = utf8_encode( $str ); |
| 753 | 753 | } |
| 754 | 754 | |
| 755 | - if ( is_numeric($str) ) { |
|
| 756 | - return $str; |
|
| 757 | - } |
|
| 755 | + if ( is_numeric($str) ) { |
|
| 756 | + return $str; |
|
| 757 | + } |
|
| 758 | 758 | |
| 759 | 759 | // $str = ent2ncr(esc_html($str)); |
| 760 | 760 | $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>'; |
@@ -762,58 +762,58 @@ discard block |
||
| 762 | 762 | return $str; |
| 763 | 763 | } |
| 764 | 764 | |
| 765 | - public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) { |
|
| 766 | - // Get post type |
|
| 767 | - $post_type = FrmFormActionsController::$action_post_type; |
|
| 768 | - |
|
| 769 | - // Set up imported index, if not set up yet |
|
| 770 | - if ( ! isset( $imported['imported']['actions'] ) ) { |
|
| 771 | - $imported['imported']['actions'] = 0; |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - // Migrate post settings to action |
|
| 775 | - self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
| 776 | - |
|
| 777 | - // Migrate email settings to action |
|
| 778 | - self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - /** |
|
| 782 | - * Migrate post settings to form action |
|
| 783 | - * |
|
| 784 | - * @param string $post_type |
|
| 785 | - */ |
|
| 786 | - private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
| 787 | - if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) { |
|
| 788 | - return; |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - $new_action = array( |
|
| 792 | - 'post_type' => $post_type, |
|
| 793 | - 'post_excerpt' => 'wppost', |
|
| 765 | + public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) { |
|
| 766 | + // Get post type |
|
| 767 | + $post_type = FrmFormActionsController::$action_post_type; |
|
| 768 | + |
|
| 769 | + // Set up imported index, if not set up yet |
|
| 770 | + if ( ! isset( $imported['imported']['actions'] ) ) { |
|
| 771 | + $imported['imported']['actions'] = 0; |
|
| 772 | + } |
|
| 773 | + |
|
| 774 | + // Migrate post settings to action |
|
| 775 | + self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
| 776 | + |
|
| 777 | + // Migrate email settings to action |
|
| 778 | + self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + /** |
|
| 782 | + * Migrate post settings to form action |
|
| 783 | + * |
|
| 784 | + * @param string $post_type |
|
| 785 | + */ |
|
| 786 | + private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
| 787 | + if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) { |
|
| 788 | + return; |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + $new_action = array( |
|
| 792 | + 'post_type' => $post_type, |
|
| 793 | + 'post_excerpt' => 'wppost', |
|
| 794 | 794 | 'post_title' => __( 'Create Posts', 'formidable' ), |
| 795 | - 'menu_order' => $form_id, |
|
| 796 | - 'post_status' => 'publish', |
|
| 797 | - 'post_content' => array(), |
|
| 798 | - 'post_name' => $form_id .'_wppost_1', |
|
| 799 | - ); |
|
| 800 | - |
|
| 801 | - $post_settings = array( |
|
| 802 | - 'post_type', 'post_category', 'post_content', |
|
| 803 | - 'post_excerpt', 'post_title', 'post_name', 'post_date', |
|
| 795 | + 'menu_order' => $form_id, |
|
| 796 | + 'post_status' => 'publish', |
|
| 797 | + 'post_content' => array(), |
|
| 798 | + 'post_name' => $form_id .'_wppost_1', |
|
| 799 | + ); |
|
| 800 | + |
|
| 801 | + $post_settings = array( |
|
| 802 | + 'post_type', 'post_category', 'post_content', |
|
| 803 | + 'post_excerpt', 'post_title', 'post_name', 'post_date', |
|
| 804 | 804 | 'post_status', 'post_custom_fields', 'post_password', |
| 805 | - ); |
|
| 805 | + ); |
|
| 806 | 806 | |
| 807 | - foreach ( $post_settings as $post_setting ) { |
|
| 807 | + foreach ( $post_settings as $post_setting ) { |
|
| 808 | 808 | if ( isset( $form_options[ $post_setting ] ) ) { |
| 809 | 809 | $new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ]; |
| 810 | - } |
|
| 811 | - unset($post_setting); |
|
| 812 | - } |
|
| 810 | + } |
|
| 811 | + unset($post_setting); |
|
| 812 | + } |
|
| 813 | 813 | |
| 814 | 814 | $new_action['event'] = array( 'create', 'update' ); |
| 815 | 815 | |
| 816 | - if ( $switch ) { |
|
| 816 | + if ( $switch ) { |
|
| 817 | 817 | // Fields with string or int saved |
| 818 | 818 | $basic_fields = array( 'post_title', 'post_content', 'post_excerpt', 'post_password', 'post_date', 'post_status' ); |
| 819 | 819 | |
@@ -821,22 +821,22 @@ discard block |
||
| 821 | 821 | $array_fields = array( 'post_category', 'post_custom_fields' ); |
| 822 | 822 | |
| 823 | 823 | $new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields ); |
| 824 | - } |
|
| 825 | - $new_action['post_content'] = json_encode($new_action['post_content']); |
|
| 824 | + } |
|
| 825 | + $new_action['post_content'] = json_encode($new_action['post_content']); |
|
| 826 | 826 | |
| 827 | - $exists = get_posts( array( |
|
| 828 | - 'name' => $new_action['post_name'], |
|
| 829 | - 'post_type' => $new_action['post_type'], |
|
| 830 | - 'post_status' => $new_action['post_status'], |
|
| 831 | - 'numberposts' => 1, |
|
| 832 | - ) ); |
|
| 827 | + $exists = get_posts( array( |
|
| 828 | + 'name' => $new_action['post_name'], |
|
| 829 | + 'post_type' => $new_action['post_type'], |
|
| 830 | + 'post_status' => $new_action['post_status'], |
|
| 831 | + 'numberposts' => 1, |
|
| 832 | + ) ); |
|
| 833 | 833 | |
| 834 | - if ( ! $exists ) { |
|
| 834 | + if ( ! $exists ) { |
|
| 835 | 835 | // this isn't an email, but we need to use a class that will always be included |
| 836 | 836 | FrmAppHelper::save_json_post( $new_action ); |
| 837 | - $imported['imported']['actions']++; |
|
| 838 | - } |
|
| 839 | - } |
|
| 837 | + $imported['imported']['actions']++; |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | 840 | |
| 841 | 841 | /** |
| 842 | 842 | * Switch old field IDs for new field IDs in emails and post |
@@ -849,211 +849,211 @@ discard block |
||
| 849 | 849 | * @return string $post_content - new field IDs |
| 850 | 850 | */ |
| 851 | 851 | private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) { |
| 852 | - global $frm_duplicate_ids; |
|
| 852 | + global $frm_duplicate_ids; |
|
| 853 | 853 | |
| 854 | - // If there aren't IDs that were switched, end now |
|
| 855 | - if ( ! $frm_duplicate_ids ) { |
|
| 856 | - return; |
|
| 857 | - } |
|
| 854 | + // If there aren't IDs that were switched, end now |
|
| 855 | + if ( ! $frm_duplicate_ids ) { |
|
| 856 | + return; |
|
| 857 | + } |
|
| 858 | 858 | |
| 859 | - // Get old IDs |
|
| 860 | - $old = array_keys( $frm_duplicate_ids ); |
|
| 859 | + // Get old IDs |
|
| 860 | + $old = array_keys( $frm_duplicate_ids ); |
|
| 861 | 861 | |
| 862 | - // Get new IDs |
|
| 863 | - $new = array_values( $frm_duplicate_ids ); |
|
| 862 | + // Get new IDs |
|
| 863 | + $new = array_values( $frm_duplicate_ids ); |
|
| 864 | 864 | |
| 865 | - // Do a str_replace with each item to set the new IDs |
|
| 866 | - foreach ( $post_content as $key => $setting ) { |
|
| 867 | - if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) { |
|
| 868 | - // Replace old IDs with new IDs |
|
| 865 | + // Do a str_replace with each item to set the new IDs |
|
| 866 | + foreach ( $post_content as $key => $setting ) { |
|
| 867 | + if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) { |
|
| 868 | + // Replace old IDs with new IDs |
|
| 869 | 869 | $post_content[ $key ] = str_replace( $old, $new, $setting ); |
| 870 | - } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) { |
|
| 871 | - foreach ( $setting as $k => $val ) { |
|
| 872 | - // Replace old IDs with new IDs |
|
| 870 | + } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) { |
|
| 871 | + foreach ( $setting as $k => $val ) { |
|
| 872 | + // Replace old IDs with new IDs |
|
| 873 | 873 | $post_content[ $key ][ $k ] = str_replace( $old, $new, $val ); |
| 874 | - } |
|
| 875 | - } |
|
| 876 | - unset( $key, $setting ); |
|
| 877 | - } |
|
| 878 | - return $post_content; |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
| 882 | - // No old notifications or autoresponders to carry over |
|
| 874 | + } |
|
| 875 | + } |
|
| 876 | + unset( $key, $setting ); |
|
| 877 | + } |
|
| 878 | + return $post_content; |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
| 882 | + // No old notifications or autoresponders to carry over |
|
| 883 | 883 | if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) { |
| 884 | - return; |
|
| 885 | - } |
|
| 884 | + return; |
|
| 885 | + } |
|
| 886 | 886 | |
| 887 | - // Initialize notifications array |
|
| 888 | - $notifications = array(); |
|
| 887 | + // Initialize notifications array |
|
| 888 | + $notifications = array(); |
|
| 889 | 889 | |
| 890 | - // Migrate regular notifications |
|
| 891 | - self::migrate_notifications_to_action( $form_options, $form_id, $notifications ); |
|
| 890 | + // Migrate regular notifications |
|
| 891 | + self::migrate_notifications_to_action( $form_options, $form_id, $notifications ); |
|
| 892 | 892 | |
| 893 | - // Migrate autoresponders |
|
| 894 | - self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications ); |
|
| 893 | + // Migrate autoresponders |
|
| 894 | + self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications ); |
|
| 895 | 895 | |
| 896 | - if ( empty( $notifications ) ) { |
|
| 897 | - return; |
|
| 898 | - } |
|
| 896 | + if ( empty( $notifications ) ) { |
|
| 897 | + return; |
|
| 898 | + } |
|
| 899 | 899 | |
| 900 | - foreach ( $notifications as $new_notification ) { |
|
| 901 | - $new_notification['post_type'] = $post_type; |
|
| 902 | - $new_notification['post_excerpt'] = 'email'; |
|
| 900 | + foreach ( $notifications as $new_notification ) { |
|
| 901 | + $new_notification['post_type'] = $post_type; |
|
| 902 | + $new_notification['post_excerpt'] = 'email'; |
|
| 903 | 903 | $new_notification['post_title'] = __( 'Email Notification', 'formidable' ); |
| 904 | - $new_notification['menu_order'] = $form_id; |
|
| 905 | - $new_notification['post_status'] = 'publish'; |
|
| 904 | + $new_notification['menu_order'] = $form_id; |
|
| 905 | + $new_notification['post_status'] = 'publish'; |
|
| 906 | 906 | |
| 907 | - // Switch field IDs and keys, if needed |
|
| 908 | - if ( $switch ) { |
|
| 907 | + // Switch field IDs and keys, if needed |
|
| 908 | + if ( $switch ) { |
|
| 909 | 909 | |
| 910 | 910 | // Switch field IDs in email conditional logic |
| 911 | 911 | self::switch_email_contition_field_ids( $new_notification['post_content'] ); |
| 912 | 912 | |
| 913 | 913 | // Switch all other field IDs in email |
| 914 | - $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] ); |
|
| 915 | - } |
|
| 916 | - $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
| 917 | - |
|
| 918 | - $exists = get_posts( array( |
|
| 919 | - 'name' => $new_notification['post_name'], |
|
| 920 | - 'post_type' => $new_notification['post_type'], |
|
| 921 | - 'post_status' => $new_notification['post_status'], |
|
| 922 | - 'numberposts' => 1, |
|
| 923 | - ) ); |
|
| 924 | - |
|
| 925 | - if ( empty($exists) ) { |
|
| 914 | + $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] ); |
|
| 915 | + } |
|
| 916 | + $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
| 917 | + |
|
| 918 | + $exists = get_posts( array( |
|
| 919 | + 'name' => $new_notification['post_name'], |
|
| 920 | + 'post_type' => $new_notification['post_type'], |
|
| 921 | + 'post_status' => $new_notification['post_status'], |
|
| 922 | + 'numberposts' => 1, |
|
| 923 | + ) ); |
|
| 924 | + |
|
| 925 | + if ( empty($exists) ) { |
|
| 926 | 926 | FrmAppHelper::save_json_post( $new_notification ); |
| 927 | - $imported['imported']['actions']++; |
|
| 928 | - } |
|
| 929 | - unset($new_notification); |
|
| 930 | - } |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) { |
|
| 934 | - if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) { |
|
| 935 | - // add old settings into notification array |
|
| 927 | + $imported['imported']['actions']++; |
|
| 928 | + } |
|
| 929 | + unset($new_notification); |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) { |
|
| 934 | + if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) { |
|
| 935 | + // add old settings into notification array |
|
| 936 | 936 | $form_options['notification'] = array( 0 => $form_options ); |
| 937 | - } else if ( isset( $form_options['notification']['email_to'] ) ) { |
|
| 938 | - // make sure it's in the correct format |
|
| 937 | + } else if ( isset( $form_options['notification']['email_to'] ) ) { |
|
| 938 | + // make sure it's in the correct format |
|
| 939 | 939 | $form_options['notification'] = array( 0 => $form_options['notification'] ); |
| 940 | - } |
|
| 940 | + } |
|
| 941 | 941 | |
| 942 | - if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) { |
|
| 943 | - foreach ( $form_options['notification'] as $email_key => $notification ) { |
|
| 942 | + if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) { |
|
| 943 | + foreach ( $form_options['notification'] as $email_key => $notification ) { |
|
| 944 | 944 | |
| 945 | - $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key ); |
|
| 945 | + $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key ); |
|
| 946 | 946 | |
| 947 | - // Format the email data |
|
| 948 | - self::format_email_data( $atts, $notification ); |
|
| 947 | + // Format the email data |
|
| 948 | + self::format_email_data( $atts, $notification ); |
|
| 949 | 949 | |
| 950 | 950 | if ( isset( $notification['twilio'] ) && $notification['twilio'] ) { |
| 951 | 951 | do_action( 'frm_create_twilio_action', $atts, $notification ); |
| 952 | 952 | } |
| 953 | 953 | |
| 954 | - // Setup the new notification |
|
| 955 | - $new_notification = array(); |
|
| 956 | - self::setup_new_notification( $new_notification, $notification, $atts ); |
|
| 954 | + // Setup the new notification |
|
| 955 | + $new_notification = array(); |
|
| 956 | + self::setup_new_notification( $new_notification, $notification, $atts ); |
|
| 957 | 957 | |
| 958 | - $notifications[] = $new_notification; |
|
| 959 | - } |
|
| 960 | - } |
|
| 961 | - } |
|
| 958 | + $notifications[] = $new_notification; |
|
| 959 | + } |
|
| 960 | + } |
|
| 961 | + } |
|
| 962 | 962 | |
| 963 | - private static function format_email_data( &$atts, $notification ) { |
|
| 964 | - // Format email_to |
|
| 965 | - self::format_email_to_data( $atts, $notification ); |
|
| 963 | + private static function format_email_data( &$atts, $notification ) { |
|
| 964 | + // Format email_to |
|
| 965 | + self::format_email_to_data( $atts, $notification ); |
|
| 966 | 966 | |
| 967 | - // Format the reply to email and name |
|
| 968 | - $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' ); |
|
| 969 | - foreach ( $reply_fields as $f => $val ) { |
|
| 967 | + // Format the reply to email and name |
|
| 968 | + $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' ); |
|
| 969 | + foreach ( $reply_fields as $f => $val ) { |
|
| 970 | 970 | if ( isset( $notification[ $f ] ) ) { |
| 971 | 971 | $atts[ $f ] = $notification[ $f ]; |
| 972 | 972 | if ( 'custom' == $notification[ $f ] ) { |
| 973 | 973 | $atts[ $f ] = $notification[ 'cust_' . $f ]; |
| 974 | 974 | } else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) { |
| 975 | 975 | $atts[ $f ] = '[' . $atts[ $f ] . ']'; |
| 976 | - } |
|
| 977 | - } |
|
| 978 | - unset( $f, $val ); |
|
| 979 | - } |
|
| 976 | + } |
|
| 977 | + } |
|
| 978 | + unset( $f, $val ); |
|
| 979 | + } |
|
| 980 | 980 | |
| 981 | - // Format event |
|
| 981 | + // Format event |
|
| 982 | 982 | $atts['event'] = array( 'create' ); |
| 983 | - if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) { |
|
| 984 | - $atts['event'][] = 'update'; |
|
| 985 | - } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) { |
|
| 983 | + if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) { |
|
| 984 | + $atts['event'][] = 'update'; |
|
| 985 | + } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) { |
|
| 986 | 986 | $atts['event'] = array( 'update' ); |
| 987 | - } |
|
| 988 | - } |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | 989 | |
| 990 | - private static function format_email_to_data( &$atts, $notification ) { |
|
| 991 | - if ( isset( $notification['email_to'] ) ) { |
|
| 990 | + private static function format_email_to_data( &$atts, $notification ) { |
|
| 991 | + if ( isset( $notification['email_to'] ) ) { |
|
| 992 | 992 | $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] ); |
| 993 | - } else { |
|
| 994 | - $atts['email_to'] = array(); |
|
| 995 | - } |
|
| 993 | + } else { |
|
| 994 | + $atts['email_to'] = array(); |
|
| 995 | + } |
|
| 996 | 996 | |
| 997 | - if ( isset( $notification['also_email_to'] ) ) { |
|
| 998 | - $email_fields = (array) $notification['also_email_to']; |
|
| 999 | - $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] ); |
|
| 1000 | - unset( $email_fields ); |
|
| 1001 | - } |
|
| 997 | + if ( isset( $notification['also_email_to'] ) ) { |
|
| 998 | + $email_fields = (array) $notification['also_email_to']; |
|
| 999 | + $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] ); |
|
| 1000 | + unset( $email_fields ); |
|
| 1001 | + } |
|
| 1002 | 1002 | |
| 1003 | - foreach ( $atts['email_to'] as $key => $email_field ) { |
|
| 1003 | + foreach ( $atts['email_to'] as $key => $email_field ) { |
|
| 1004 | 1004 | |
| 1005 | - if ( is_numeric( $email_field ) ) { |
|
| 1005 | + if ( is_numeric( $email_field ) ) { |
|
| 1006 | 1006 | $atts['email_to'][ $key ] = '[' . $email_field . ']'; |
| 1007 | - } |
|
| 1007 | + } |
|
| 1008 | 1008 | |
| 1009 | - if ( strpos( $email_field, '|') ) { |
|
| 1010 | - $email_opt = explode( '|', $email_field ); |
|
| 1011 | - if ( isset( $email_opt[0] ) ) { |
|
| 1009 | + if ( strpos( $email_field, '|') ) { |
|
| 1010 | + $email_opt = explode( '|', $email_field ); |
|
| 1011 | + if ( isset( $email_opt[0] ) ) { |
|
| 1012 | 1012 | $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']'; |
| 1013 | - } |
|
| 1014 | - unset( $email_opt ); |
|
| 1015 | - } |
|
| 1016 | - } |
|
| 1017 | - $atts['email_to'] = implode(', ', $atts['email_to']); |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - private static function setup_new_notification( &$new_notification, $notification, $atts ) { |
|
| 1021 | - // Set up new notification |
|
| 1022 | - $new_notification = array( |
|
| 1023 | - 'post_content' => array( |
|
| 1024 | - 'email_to' => $atts['email_to'], |
|
| 1025 | - 'event' => $atts['event'], |
|
| 1026 | - ), |
|
| 1027 | - 'post_name' => $atts['form_id'] .'_email_'. $atts['email_key'], |
|
| 1028 | - ); |
|
| 1029 | - |
|
| 1030 | - // Add more fields to the new notification |
|
| 1031 | - $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' ); |
|
| 1032 | - foreach ( $add_fields as $add_field ) { |
|
| 1013 | + } |
|
| 1014 | + unset( $email_opt ); |
|
| 1015 | + } |
|
| 1016 | + } |
|
| 1017 | + $atts['email_to'] = implode(', ', $atts['email_to']); |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + private static function setup_new_notification( &$new_notification, $notification, $atts ) { |
|
| 1021 | + // Set up new notification |
|
| 1022 | + $new_notification = array( |
|
| 1023 | + 'post_content' => array( |
|
| 1024 | + 'email_to' => $atts['email_to'], |
|
| 1025 | + 'event' => $atts['event'], |
|
| 1026 | + ), |
|
| 1027 | + 'post_name' => $atts['form_id'] .'_email_'. $atts['email_key'], |
|
| 1028 | + ); |
|
| 1029 | + |
|
| 1030 | + // Add more fields to the new notification |
|
| 1031 | + $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' ); |
|
| 1032 | + foreach ( $add_fields as $add_field ) { |
|
| 1033 | 1033 | if ( isset( $notification[ $add_field ] ) ) { |
| 1034 | 1034 | $new_notification['post_content'][ $add_field ] = $notification[ $add_field ]; |
| 1035 | - } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) { |
|
| 1035 | + } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) { |
|
| 1036 | 1036 | $new_notification['post_content'][ $add_field ] = 0; |
| 1037 | - } else { |
|
| 1037 | + } else { |
|
| 1038 | 1038 | $new_notification['post_content'][ $add_field ] = ''; |
| 1039 | - } |
|
| 1040 | - unset( $add_field ); |
|
| 1041 | - } |
|
| 1039 | + } |
|
| 1040 | + unset( $add_field ); |
|
| 1041 | + } |
|
| 1042 | 1042 | |
| 1043 | 1043 | // Set reply to |
| 1044 | 1044 | $new_notification['post_content']['reply_to'] = $atts['reply_to']; |
| 1045 | 1045 | |
| 1046 | - // Set from |
|
| 1046 | + // Set from |
|
| 1047 | 1047 | if ( ! empty( $atts['reply_to'] ) || ! empty( $atts['reply_to_name'] ) ) { |
| 1048 | - $new_notification['post_content']['from'] = ( empty($atts['reply_to_name']) ? '[sitename]' : $atts['reply_to_name'] ) .' <'. ( empty($atts['reply_to']) ? '[admin_email]' : $atts['reply_to'] ) .'>'; |
|
| 1049 | - } |
|
| 1050 | - } |
|
| 1048 | + $new_notification['post_content']['from'] = ( empty($atts['reply_to_name']) ? '[sitename]' : $atts['reply_to_name'] ) .' <'. ( empty($atts['reply_to']) ? '[admin_email]' : $atts['reply_to'] ) .'>'; |
|
| 1049 | + } |
|
| 1050 | + } |
|
| 1051 | 1051 | |
| 1052 | 1052 | /** |
| 1053 | - * Switch field IDs in pre-2.0 email conditional logic |
|
| 1054 | - * |
|
| 1055 | - * @param $post_content array, pass by reference |
|
| 1056 | - */ |
|
| 1053 | + * Switch field IDs in pre-2.0 email conditional logic |
|
| 1054 | + * |
|
| 1055 | + * @param $post_content array, pass by reference |
|
| 1056 | + */ |
|
| 1057 | 1057 | private static function switch_email_contition_field_ids( &$post_content ) { |
| 1058 | 1058 | // Switch field IDs in conditional logic |
| 1059 | 1059 | if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) { |
@@ -1066,48 +1066,48 @@ discard block |
||
| 1066 | 1066 | } |
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | - private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) { |
|
| 1070 | - if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) { |
|
| 1071 | - // migrate autoresponder |
|
| 1072 | - |
|
| 1073 | - $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0; |
|
| 1074 | - if ( strpos($email_field, '|') ) { |
|
| 1075 | - // data from entries field |
|
| 1076 | - $email_field = explode('|', $email_field); |
|
| 1077 | - if ( isset($email_field[1]) ) { |
|
| 1078 | - $email_field = $email_field[1]; |
|
| 1079 | - } |
|
| 1080 | - } |
|
| 1081 | - if ( is_numeric($email_field) && ! empty($email_field) ) { |
|
| 1082 | - $email_field = '['. $email_field .']'; |
|
| 1083 | - } |
|
| 1084 | - |
|
| 1085 | - $notification = $form_options; |
|
| 1086 | - $new_notification2 = array( |
|
| 1087 | - 'post_content' => array( |
|
| 1088 | - 'email_message' => $notification['ar_email_message'], |
|
| 1089 | - 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '', |
|
| 1090 | - 'email_to' => $email_field, |
|
| 1091 | - 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0, |
|
| 1092 | - 'inc_user_info' => 0, |
|
| 1093 | - ), |
|
| 1094 | - 'post_name' => $form_id .'_email_'. count( $notifications ), |
|
| 1095 | - ); |
|
| 1096 | - |
|
| 1097 | - $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : ''; |
|
| 1098 | - $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : ''; |
|
| 1069 | + private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) { |
|
| 1070 | + if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) { |
|
| 1071 | + // migrate autoresponder |
|
| 1072 | + |
|
| 1073 | + $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0; |
|
| 1074 | + if ( strpos($email_field, '|') ) { |
|
| 1075 | + // data from entries field |
|
| 1076 | + $email_field = explode('|', $email_field); |
|
| 1077 | + if ( isset($email_field[1]) ) { |
|
| 1078 | + $email_field = $email_field[1]; |
|
| 1079 | + } |
|
| 1080 | + } |
|
| 1081 | + if ( is_numeric($email_field) && ! empty($email_field) ) { |
|
| 1082 | + $email_field = '['. $email_field .']'; |
|
| 1083 | + } |
|
| 1084 | + |
|
| 1085 | + $notification = $form_options; |
|
| 1086 | + $new_notification2 = array( |
|
| 1087 | + 'post_content' => array( |
|
| 1088 | + 'email_message' => $notification['ar_email_message'], |
|
| 1089 | + 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '', |
|
| 1090 | + 'email_to' => $email_field, |
|
| 1091 | + 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0, |
|
| 1092 | + 'inc_user_info' => 0, |
|
| 1093 | + ), |
|
| 1094 | + 'post_name' => $form_id .'_email_'. count( $notifications ), |
|
| 1095 | + ); |
|
| 1096 | + |
|
| 1097 | + $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : ''; |
|
| 1098 | + $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : ''; |
|
| 1099 | 1099 | |
| 1100 | 1100 | if ( ! empty( $reply_to ) ) { |
| 1101 | 1101 | $new_notification2['post_content']['reply_to'] = $reply_to; |
| 1102 | 1102 | } |
| 1103 | 1103 | |
| 1104 | 1104 | if ( ! empty( $reply_to ) || ! empty( $reply_to_name ) ) { |
| 1105 | - $new_notification2['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>'; |
|
| 1105 | + $new_notification2['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>'; |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | - $notifications[] = $new_notification2; |
|
| 1109 | - unset( $new_notification2 ); |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1108 | + $notifications[] = $new_notification2; |
|
| 1109 | + unset( $new_notification2 ); |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | 1112 | } |
| 1113 | 1113 | |