@@ -1,380 +1,380 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | if ( ! defined('ABSPATH') ) { |
| 3 | - die('You are not allowed to call this page directly.'); |
|
| 3 | + die('You are not allowed to call this page directly.'); |
|
| 4 | 4 | } |
| 5 | 5 | |
| 6 | 6 | class FrmForm { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @return int|boolean id on success or false on failure |
|
| 10 | - */ |
|
| 11 | - public static function create( $values ) { |
|
| 12 | - global $wpdb; |
|
| 8 | + /** |
|
| 9 | + * @return int|boolean id on success or false on failure |
|
| 10 | + */ |
|
| 11 | + public static function create( $values ) { |
|
| 12 | + global $wpdb; |
|
| 13 | 13 | |
| 14 | - $new_values = array( |
|
| 14 | + $new_values = array( |
|
| 15 | 15 | 'form_key' => FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key' ), |
| 16 | - 'name' => $values['name'], |
|
| 17 | - 'description' => $values['description'], |
|
| 18 | - 'status' => isset($values['status']) ? $values['status'] : 'draft', |
|
| 19 | - 'logged_in' => isset($values['logged_in']) ? $values['logged_in'] : 0, |
|
| 20 | - 'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0, |
|
| 16 | + 'name' => $values['name'], |
|
| 17 | + 'description' => $values['description'], |
|
| 18 | + 'status' => isset($values['status']) ? $values['status'] : 'draft', |
|
| 19 | + 'logged_in' => isset($values['logged_in']) ? $values['logged_in'] : 0, |
|
| 20 | + 'is_template' => isset($values['is_template']) ? (int) $values['is_template'] : 0, |
|
| 21 | 21 | 'parent_form_id' => isset( $values['parent_form_id'] ) ? absint( $values['parent_form_id'] ) : 0, |
| 22 | - 'editable' => isset($values['editable']) ? (int) $values['editable'] : 0, |
|
| 23 | - 'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0, |
|
| 24 | - 'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1), |
|
| 25 | - ); |
|
| 22 | + 'editable' => isset($values['editable']) ? (int) $values['editable'] : 0, |
|
| 23 | + 'default_template' => isset($values['default_template']) ? (int) $values['default_template'] : 0, |
|
| 24 | + 'created_at' => isset($values['created_at']) ? $values['created_at'] : current_time('mysql', 1), |
|
| 25 | + ); |
|
| 26 | 26 | |
| 27 | 27 | $options = isset( $values['options'] ) ? (array) $values['options'] : array(); |
| 28 | 28 | FrmFormsHelper::fill_form_options( $options, $values ); |
| 29 | 29 | |
| 30 | - $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
| 31 | - $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
| 32 | - $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
| 30 | + $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
| 31 | + $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
| 32 | + $options['submit_html'] = isset($values['options']['submit_html']) ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
| 33 | 33 | |
| 34 | - $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
| 35 | - $new_values['options'] = serialize($options); |
|
| 34 | + $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
| 35 | + $new_values['options'] = serialize($options); |
|
| 36 | 36 | |
| 37 | - //if(isset($values['id']) && is_numeric($values['id'])) |
|
| 38 | - // $new_values['id'] = $values['id']; |
|
| 37 | + //if(isset($values['id']) && is_numeric($values['id'])) |
|
| 38 | + // $new_values['id'] = $values['id']; |
|
| 39 | 39 | |
| 40 | 40 | $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
| 41 | 41 | |
| 42 | - $id = $wpdb->insert_id; |
|
| 42 | + $id = $wpdb->insert_id; |
|
| 43 | 43 | |
| 44 | 44 | // Clear form caching |
| 45 | 45 | self::clear_form_cache(); |
| 46 | 46 | |
| 47 | - return $id; |
|
| 48 | - } |
|
| 47 | + return $id; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @return int|boolean ID on success or false on failure |
|
| 52 | - */ |
|
| 53 | - public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
|
| 54 | - global $wpdb; |
|
| 50 | + /** |
|
| 51 | + * @return int|boolean ID on success or false on failure |
|
| 52 | + */ |
|
| 53 | + public static function duplicate( $id, $template = false, $copy_keys = false, $blog_id = false ) { |
|
| 54 | + global $wpdb; |
|
| 55 | 55 | |
| 56 | - $values = self::getOne( $id, $blog_id ); |
|
| 57 | - if ( ! $values ) { |
|
| 58 | - return false; |
|
| 59 | - } |
|
| 56 | + $values = self::getOne( $id, $blog_id ); |
|
| 57 | + if ( ! $values ) { |
|
| 58 | + return false; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $new_key = $copy_keys ? $values->form_key : ''; |
|
| 61 | + $new_key = $copy_keys ? $values->form_key : ''; |
|
| 62 | 62 | |
| 63 | - $new_values = array( |
|
| 63 | + $new_values = array( |
|
| 64 | 64 | 'form_key' => FrmAppHelper::get_unique_key( $new_key, $wpdb->prefix . 'frm_forms', 'form_key' ), |
| 65 | - 'name' => $values->name, |
|
| 66 | - 'description' => $values->description, |
|
| 67 | - 'status' => $template ? 'published' : 'draft', |
|
| 68 | - 'logged_in' => $values->logged_in ? $values->logged_in : 0, |
|
| 69 | - 'editable' => $values->editable ? $values->editable : 0, |
|
| 70 | - 'created_at' => current_time('mysql', 1), |
|
| 71 | - 'is_template' => $template ? 1 : 0, |
|
| 72 | - ); |
|
| 73 | - |
|
| 74 | - if ( $blog_id ) { |
|
| 75 | - $new_values['status'] = 'published'; |
|
| 76 | - $new_options = maybe_unserialize($values->options); |
|
| 77 | - $new_options['email_to'] = get_option('admin_email'); |
|
| 78 | - $new_options['copy'] = false; |
|
| 79 | - $new_values['options'] = $new_options; |
|
| 80 | - } else { |
|
| 81 | - $new_values['options'] = $values->options; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - if ( is_array($new_values['options']) ) { |
|
| 85 | - $new_values['options'] = serialize($new_values['options']); |
|
| 86 | - } |
|
| 65 | + 'name' => $values->name, |
|
| 66 | + 'description' => $values->description, |
|
| 67 | + 'status' => $template ? 'published' : 'draft', |
|
| 68 | + 'logged_in' => $values->logged_in ? $values->logged_in : 0, |
|
| 69 | + 'editable' => $values->editable ? $values->editable : 0, |
|
| 70 | + 'created_at' => current_time('mysql', 1), |
|
| 71 | + 'is_template' => $template ? 1 : 0, |
|
| 72 | + ); |
|
| 73 | + |
|
| 74 | + if ( $blog_id ) { |
|
| 75 | + $new_values['status'] = 'published'; |
|
| 76 | + $new_options = maybe_unserialize($values->options); |
|
| 77 | + $new_options['email_to'] = get_option('admin_email'); |
|
| 78 | + $new_options['copy'] = false; |
|
| 79 | + $new_values['options'] = $new_options; |
|
| 80 | + } else { |
|
| 81 | + $new_values['options'] = $values->options; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + if ( is_array($new_values['options']) ) { |
|
| 85 | + $new_values['options'] = serialize($new_values['options']); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_forms', $new_values ); |
| 89 | 89 | |
| 90 | - if ( $query_results ) { |
|
| 90 | + if ( $query_results ) { |
|
| 91 | 91 | // Clear form caching |
| 92 | 92 | self::clear_form_cache(); |
| 93 | 93 | |
| 94 | - $form_id = $wpdb->insert_id; |
|
| 95 | - FrmField::duplicate($id, $form_id, $copy_keys, $blog_id); |
|
| 94 | + $form_id = $wpdb->insert_id; |
|
| 95 | + FrmField::duplicate($id, $form_id, $copy_keys, $blog_id); |
|
| 96 | 96 | |
| 97 | - // update form settings after fields are created |
|
| 97 | + // update form settings after fields are created |
|
| 98 | 98 | do_action( 'frm_after_duplicate_form', $form_id, $new_values, array( 'old_id' => $id ) ); |
| 99 | - return $form_id; |
|
| 100 | - } |
|
| 99 | + return $form_id; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - return false; |
|
| 103 | - } |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | 105 | public static function after_duplicate( $form_id, $values ) { |
| 106 | - $new_opts = $values['options'] = maybe_unserialize($values['options']); |
|
| 106 | + $new_opts = $values['options'] = maybe_unserialize($values['options']); |
|
| 107 | 107 | |
| 108 | - if ( isset($new_opts['success_msg']) ) { |
|
| 109 | - $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']); |
|
| 110 | - } |
|
| 108 | + if ( isset($new_opts['success_msg']) ) { |
|
| 109 | + $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id); |
|
| 112 | + $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id); |
|
| 113 | 113 | |
| 114 | - if ( $new_opts != $values['options'] ) { |
|
| 115 | - global $wpdb; |
|
| 114 | + if ( $new_opts != $values['options'] ) { |
|
| 115 | + global $wpdb; |
|
| 116 | 116 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $new_opts ) ), array( 'id' => $form_id ) ); |
| 117 | - } |
|
| 118 | - } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * @return int|boolean |
|
| 122 | - */ |
|
| 123 | - public static function update( $id, $values, $create_link = false ) { |
|
| 124 | - global $wpdb; |
|
| 120 | + /** |
|
| 121 | + * @return int|boolean |
|
| 122 | + */ |
|
| 123 | + public static function update( $id, $values, $create_link = false ) { |
|
| 124 | + global $wpdb; |
|
| 125 | 125 | |
| 126 | - if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) { |
|
| 127 | - $values['status'] = 'published'; |
|
| 128 | - } |
|
| 126 | + if ( ! isset( $values['status'] ) && ( $create_link || isset( $values['options'] ) || isset( $values['item_meta'] ) || isset( $values['field_options'] ) ) ) { |
|
| 127 | + $values['status'] = 'published'; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - if ( isset($values['form_key']) ) { |
|
| 130 | + if ( isset($values['form_key']) ) { |
|
| 131 | 131 | $values['form_key'] = FrmAppHelper::get_unique_key( $values['form_key'], $wpdb->prefix . 'frm_forms', 'form_key', $id ); |
| 132 | - } |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' ); |
|
| 134 | + $form_fields = array( 'form_key', 'name', 'description', 'status', 'parent_form_id' ); |
|
| 135 | 135 | |
| 136 | - $new_values = self::set_update_options( array(), $values); |
|
| 136 | + $new_values = self::set_update_options( array(), $values); |
|
| 137 | 137 | |
| 138 | - foreach ( $values as $value_key => $value ) { |
|
| 139 | - if ( in_array($value_key, $form_fields) ) { |
|
| 138 | + foreach ( $values as $value_key => $value ) { |
|
| 139 | + if ( in_array($value_key, $form_fields) ) { |
|
| 140 | 140 | $new_values[ $value_key ] = $value; |
| 141 | - } |
|
| 142 | - } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { |
|
| 145 | - $new_values['status'] = $values['new_status']; |
|
| 146 | - } |
|
| 144 | + if ( isset( $values['new_status'] ) && ! empty( $values['new_status'] ) ) { |
|
| 145 | + $new_values['status'] = $values['new_status']; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - if ( ! empty( $new_values ) ) { |
|
| 148 | + if ( ! empty( $new_values ) ) { |
|
| 149 | 149 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', $new_values, array( 'id' => $id ) ); |
| 150 | - if ( $query_results ) { |
|
| 150 | + if ( $query_results ) { |
|
| 151 | 151 | self::clear_form_cache(); |
| 152 | - } |
|
| 153 | - } else { |
|
| 154 | - $query_results = true; |
|
| 155 | - } |
|
| 156 | - unset($new_values); |
|
| 152 | + } |
|
| 153 | + } else { |
|
| 154 | + $query_results = true; |
|
| 155 | + } |
|
| 156 | + unset($new_values); |
|
| 157 | 157 | |
| 158 | - $values = self::update_fields($id, $values); |
|
| 158 | + $values = self::update_fields($id, $values); |
|
| 159 | 159 | |
| 160 | 160 | do_action( 'frm_update_form', $id, $values ); |
| 161 | 161 | do_action( 'frm_update_form_' . $id, $values ); |
| 162 | 162 | |
| 163 | - return $query_results; |
|
| 164 | - } |
|
| 163 | + return $query_results; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * @return array |
|
| 168 | - */ |
|
| 166 | + /** |
|
| 167 | + * @return array |
|
| 168 | + */ |
|
| 169 | 169 | public static function set_update_options( $new_values, $values ) { |
| 170 | - if ( ! isset($values['options']) ) { |
|
| 171 | - return $new_values; |
|
| 172 | - } |
|
| 170 | + if ( ! isset($values['options']) ) { |
|
| 171 | + return $new_values; |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | 174 | $options = isset( $values['options'] ) ? (array) $values['options'] : array(); |
| 175 | 175 | FrmFormsHelper::fill_form_options( $options, $values ); |
| 176 | 176 | |
| 177 | - $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0; |
|
| 178 | - $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
| 179 | - $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
| 180 | - $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
| 177 | + $options['custom_style'] = isset($values['options']['custom_style']) ? $values['options']['custom_style'] : 0; |
|
| 178 | + $options['before_html'] = isset($values['options']['before_html']) ? $values['options']['before_html'] : FrmFormsHelper::get_default_html('before'); |
|
| 179 | + $options['after_html'] = isset($values['options']['after_html']) ? $values['options']['after_html'] : FrmFormsHelper::get_default_html('after'); |
|
| 180 | + $options['submit_html'] = (isset($values['options']['submit_html']) && $values['options']['submit_html'] != '') ? $values['options']['submit_html'] : FrmFormsHelper::get_default_html('submit'); |
|
| 181 | 181 | |
| 182 | - $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
| 183 | - $new_values['options'] = serialize($options); |
|
| 182 | + $options = apply_filters('frm_form_options_before_update', $options, $values); |
|
| 183 | + $new_values['options'] = serialize($options); |
|
| 184 | 184 | |
| 185 | - return $new_values; |
|
| 186 | - } |
|
| 185 | + return $new_values; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | |
| 189 | - /** |
|
| 190 | - * @return array |
|
| 191 | - */ |
|
| 189 | + /** |
|
| 190 | + * @return array |
|
| 191 | + */ |
|
| 192 | 192 | public static function update_fields( $id, $values ) { |
| 193 | 193 | |
| 194 | - if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) { |
|
| 195 | - return $values; |
|
| 196 | - } |
|
| 194 | + if ( ! isset($values['options']) && ! isset($values['item_meta']) && ! isset($values['field_options']) ) { |
|
| 195 | + return $values; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - $all_fields = FrmField::get_all_for_form($id); |
|
| 199 | - if ( empty($all_fields) ) { |
|
| 200 | - return $values; |
|
| 201 | - } |
|
| 198 | + $all_fields = FrmField::get_all_for_form($id); |
|
| 199 | + if ( empty($all_fields) ) { |
|
| 200 | + return $values; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - if ( ! isset($values['item_meta']) ) { |
|
| 204 | - $values['item_meta'] = array(); |
|
| 205 | - } |
|
| 203 | + if ( ! isset($values['item_meta']) ) { |
|
| 204 | + $values['item_meta'] = array(); |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - $field_array = array(); |
|
| 208 | - $existing_keys = array_keys($values['item_meta']); |
|
| 209 | - foreach ( $all_fields as $fid ) { |
|
| 210 | - if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) { |
|
| 207 | + $field_array = array(); |
|
| 208 | + $existing_keys = array_keys($values['item_meta']); |
|
| 209 | + foreach ( $all_fields as $fid ) { |
|
| 210 | + if ( ! in_array($fid->id, $existing_keys) && ( isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted']) ) || isset($values['options']) ) { |
|
| 211 | 211 | $values['item_meta'][ $fid->id ] = ''; |
| 212 | - } |
|
| 212 | + } |
|
| 213 | 213 | $field_array[ $fid->id ] = $fid; |
| 214 | - } |
|
| 215 | - unset($all_fields); |
|
| 214 | + } |
|
| 215 | + unset($all_fields); |
|
| 216 | 216 | |
| 217 | - foreach ( $values['item_meta'] as $field_id => $default_value ) { |
|
| 217 | + foreach ( $values['item_meta'] as $field_id => $default_value ) { |
|
| 218 | 218 | if ( isset( $field_array[ $field_id ] ) ) { |
| 219 | 219 | $field = $field_array[ $field_id ]; |
| 220 | - } else { |
|
| 221 | - $field = FrmField::getOne($field_id); |
|
| 222 | - } |
|
| 220 | + } else { |
|
| 221 | + $field = FrmField::getOne($field_id); |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - if ( ! $field ) { |
|
| 225 | - continue; |
|
| 226 | - } |
|
| 224 | + if ( ! $field ) { |
|
| 225 | + continue; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | 228 | $is_settings_page = ( isset( $values['options'] ) || isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ); |
| 229 | 229 | if ( $is_settings_page ) { |
| 230 | - //updating the settings page |
|
| 230 | + //updating the settings page |
|
| 231 | 231 | if ( isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ) { |
| 232 | 232 | $field->field_options['custom_html'] = isset( $values['field_options'][ 'custom_html_' . $field_id ] ) ? $values['field_options'][ 'custom_html_' . $field_id ] : ( isset( $field->field_options['custom_html'] ) ? $field->field_options['custom_html'] : FrmFieldsHelper::get_default_html( $field->type ) ); |
| 233 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
| 233 | + $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
| 234 | 234 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
| 235 | - } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
|
| 236 | - $prev_opts = $field->field_options; |
|
| 237 | - $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
| 238 | - if ( $prev_opts != $field->field_options ) { |
|
| 235 | + } else if ( $field->type == 'hidden' || $field->type == 'user_id' ) { |
|
| 236 | + $prev_opts = $field->field_options; |
|
| 237 | + $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); |
|
| 238 | + if ( $prev_opts != $field->field_options ) { |
|
| 239 | 239 | FrmField::update( $field_id, array( 'field_options' => $field->field_options ) ); |
| 240 | - } |
|
| 241 | - unset($prev_opts); |
|
| 242 | - } |
|
| 243 | - } |
|
| 240 | + } |
|
| 241 | + unset($prev_opts); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | 245 | if ( $is_settings_page && ! defined( 'WP_IMPORTING' ) ) { |
| 246 | - continue; |
|
| 247 | - } |
|
| 246 | + continue; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - //updating the form |
|
| 249 | + //updating the form |
|
| 250 | 250 | $update_options = FrmFieldsHelper::get_default_field_opts( $field->type, $field, true ); |
| 251 | 251 | unset( $update_options['custom_html'] ); // don't check for POST html |
| 252 | 252 | $update_options = apply_filters( 'frm_field_options_to_update', $update_options ); |
| 253 | 253 | |
| 254 | 254 | foreach ( $update_options as $opt => $default ) { |
| 255 | 255 | $field->field_options[ $opt ] = isset( $values['field_options'][ $opt . '_' . $field_id ] ) ? trim( sanitize_text_field( $values['field_options'][ $opt . '_' . $field_id ] ) ) : $default; |
| 256 | - } |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
| 258 | + $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); |
|
| 259 | 259 | $default_value = maybe_serialize( $values['item_meta'][ $field_id ] ); |
| 260 | 260 | $field_key = isset( $values['field_options'][ 'field_key_' . $field_id ] ) ? $values['field_options'][ 'field_key_' . $field_id ] : $field->field_key; |
| 261 | 261 | $required = isset( $values['field_options'][ 'required_' . $field_id ] ) ? $values['field_options'][ 'required_' . $field_id ] : false; |
| 262 | 262 | $field_type = isset( $values['field_options'][ 'type_' . $field_id ] ) ? $values['field_options'][ 'type_' . $field_id ] : $field->type; |
| 263 | 263 | $field_description = isset( $values['field_options'][ 'description_' . $field_id ] ) ? $values['field_options'][ 'description_' . $field_id ] : $field->description; |
| 264 | 264 | |
| 265 | - FrmField::update($field_id, array( |
|
| 266 | - 'field_key' => $field_key, 'type' => $field_type, |
|
| 267 | - 'default_value' => $default_value, 'field_options' => $field->field_options, |
|
| 268 | - 'description' => $field_description, 'required' => $required, |
|
| 269 | - ) ); |
|
| 265 | + FrmField::update($field_id, array( |
|
| 266 | + 'field_key' => $field_key, 'type' => $field_type, |
|
| 267 | + 'default_value' => $default_value, 'field_options' => $field->field_options, |
|
| 268 | + 'description' => $field_description, 'required' => $required, |
|
| 269 | + ) ); |
|
| 270 | 270 | |
| 271 | - FrmField::delete_form_transient($field->form_id); |
|
| 272 | - } |
|
| 271 | + FrmField::delete_form_transient($field->form_id); |
|
| 272 | + } |
|
| 273 | 273 | self::clear_form_cache(); |
| 274 | 274 | |
| 275 | - return $values; |
|
| 276 | - } |
|
| 275 | + return $values; |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - /** |
|
| 279 | - * @param string $status |
|
| 280 | - * @return int|boolean |
|
| 281 | - */ |
|
| 278 | + /** |
|
| 279 | + * @param string $status |
|
| 280 | + * @return int|boolean |
|
| 281 | + */ |
|
| 282 | 282 | public static function set_status( $id, $status ) { |
| 283 | - if ( 'trash' == $status ) { |
|
| 284 | - return self::trash($id); |
|
| 285 | - } |
|
| 283 | + if ( 'trash' == $status ) { |
|
| 284 | + return self::trash($id); |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | 287 | $statuses = array( 'published', 'draft', 'trash' ); |
| 288 | - if ( ! in_array( $status, $statuses ) ) { |
|
| 289 | - return false; |
|
| 290 | - } |
|
| 288 | + if ( ! in_array( $status, $statuses ) ) { |
|
| 289 | + return false; |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - global $wpdb; |
|
| 292 | + global $wpdb; |
|
| 293 | 293 | |
| 294 | - if ( is_array($id) ) { |
|
| 294 | + if ( is_array($id) ) { |
|
| 295 | 295 | $where = array( 'id' => $id ); |
| 296 | 296 | FrmDb::get_where_clause_and_values( $where ); |
| 297 | 297 | array_unshift( $where['values'], $status ); |
| 298 | 298 | |
| 299 | 299 | $query_results = $wpdb->query( $wpdb->prepare( 'UPDATE ' . $wpdb->prefix . 'frm_forms SET status = %s ' . $where['where'], $where['values'] ) ); |
| 300 | - } else { |
|
| 300 | + } else { |
|
| 301 | 301 | $query_results = $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'status' => $status ), array( 'id' => $id ) ); |
| 302 | - } |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - if ( $query_results ) { |
|
| 304 | + if ( $query_results ) { |
|
| 305 | 305 | self::clear_form_cache(); |
| 306 | - } |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - return $query_results; |
|
| 309 | - } |
|
| 308 | + return $query_results; |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - /** |
|
| 312 | - * @return int|boolean |
|
| 313 | - */ |
|
| 311 | + /** |
|
| 312 | + * @return int|boolean |
|
| 313 | + */ |
|
| 314 | 314 | public static function trash( $id ) { |
| 315 | - if ( ! EMPTY_TRASH_DAYS ) { |
|
| 316 | - return self::destroy( $id ); |
|
| 317 | - } |
|
| 315 | + if ( ! EMPTY_TRASH_DAYS ) { |
|
| 316 | + return self::destroy( $id ); |
|
| 317 | + } |
|
| 318 | 318 | |
| 319 | - $form = self::getOne($id); |
|
| 320 | - if ( ! $form ) { |
|
| 321 | - return false; |
|
| 322 | - } |
|
| 319 | + $form = self::getOne($id); |
|
| 320 | + if ( ! $form ) { |
|
| 321 | + return false; |
|
| 322 | + } |
|
| 323 | 323 | |
| 324 | - $options = $form->options; |
|
| 325 | - $options['trash_time'] = time(); |
|
| 324 | + $options = $form->options; |
|
| 325 | + $options['trash_time'] = time(); |
|
| 326 | 326 | |
| 327 | - global $wpdb; |
|
| 328 | - $query_results = $wpdb->update( |
|
| 327 | + global $wpdb; |
|
| 328 | + $query_results = $wpdb->update( |
|
| 329 | 329 | $wpdb->prefix . 'frm_forms', |
| 330 | 330 | array( 'status' => 'trash', 'options' => serialize( $options ) ), |
| 331 | 331 | array( 'id' => $id ) |
| 332 | - ); |
|
| 332 | + ); |
|
| 333 | 333 | |
| 334 | - if ( $query_results ) { |
|
| 334 | + if ( $query_results ) { |
|
| 335 | 335 | self::clear_form_cache(); |
| 336 | - } |
|
| 336 | + } |
|
| 337 | 337 | |
| 338 | - return $query_results; |
|
| 339 | - } |
|
| 338 | + return $query_results; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - /** |
|
| 342 | - * @return int|boolean |
|
| 343 | - */ |
|
| 341 | + /** |
|
| 342 | + * @return int|boolean |
|
| 343 | + */ |
|
| 344 | 344 | public static function destroy( $id ) { |
| 345 | - global $wpdb; |
|
| 345 | + global $wpdb; |
|
| 346 | 346 | |
| 347 | - $form = self::getOne($id); |
|
| 348 | - if ( ! $form ) { |
|
| 349 | - return false; |
|
| 350 | - } |
|
| 347 | + $form = self::getOne($id); |
|
| 348 | + if ( ! $form ) { |
|
| 349 | + return false; |
|
| 350 | + } |
|
| 351 | 351 | $id = $form->id; |
| 352 | 352 | |
| 353 | - // Disconnect the entries from this form |
|
| 353 | + // Disconnect the entries from this form |
|
| 354 | 354 | $entries = FrmDb::get_col( $wpdb->prefix . 'frm_items', array( 'form_id' => $id ) ); |
| 355 | - foreach ( $entries as $entry_id ) { |
|
| 356 | - FrmEntry::destroy($entry_id); |
|
| 357 | - unset($entry_id); |
|
| 358 | - } |
|
| 355 | + foreach ( $entries as $entry_id ) { |
|
| 356 | + FrmEntry::destroy($entry_id); |
|
| 357 | + unset($entry_id); |
|
| 358 | + } |
|
| 359 | 359 | |
| 360 | - // Disconnect the fields from this form |
|
| 360 | + // Disconnect the fields from this form |
|
| 361 | 361 | $wpdb->query( $wpdb->prepare( 'DELETE fi FROM ' . $wpdb->prefix . 'frm_fields AS fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id) WHERE fi.form_id=%d OR parent_form_id=%d', $id, $id ) ); |
| 362 | 362 | |
| 363 | 363 | $query_results = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id ) ); |
| 364 | - if ( $query_results ) { |
|
| 365 | - // Delete all form actions linked to this form |
|
| 366 | - $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
| 367 | - $action_control->destroy($id, 'all'); |
|
| 364 | + if ( $query_results ) { |
|
| 365 | + // Delete all form actions linked to this form |
|
| 366 | + $action_control = FrmFormActionsController::get_form_actions( 'email' ); |
|
| 367 | + $action_control->destroy($id, 'all'); |
|
| 368 | 368 | |
| 369 | 369 | // Clear form caching |
| 370 | 370 | self::clear_form_cache(); |
| 371 | 371 | |
| 372 | 372 | do_action( 'frm_destroy_form', $id ); |
| 373 | 373 | do_action( 'frm_destroy_form_' . $id ); |
| 374 | - } |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - return $query_results; |
|
| 377 | - } |
|
| 376 | + return $query_results; |
|
| 377 | + } |
|
| 378 | 378 | |
| 379 | 379 | /** |
| 380 | 380 | * Delete trashed forms based on how long they have been trashed |
@@ -406,49 +406,49 @@ discard block |
||
| 406 | 406 | return $count; |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - /** |
|
| 410 | - * @return string form name |
|
| 411 | - */ |
|
| 412 | - public static function &getName( $id ) { |
|
| 413 | - global $wpdb; |
|
| 414 | - |
|
| 415 | - $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
| 416 | - if ( $form ) { |
|
| 417 | - $r = stripslashes($form->name); |
|
| 418 | - return $r; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
| 422 | - $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
| 423 | - $r = stripslashes($r); |
|
| 424 | - |
|
| 425 | - return $r; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * @param string $key |
|
| 430 | - * @return int form id |
|
| 431 | - */ |
|
| 409 | + /** |
|
| 410 | + * @return string form name |
|
| 411 | + */ |
|
| 412 | + public static function &getName( $id ) { |
|
| 413 | + global $wpdb; |
|
| 414 | + |
|
| 415 | + $form = FrmAppHelper::check_cache($id, 'frm_form'); |
|
| 416 | + if ( $form ) { |
|
| 417 | + $r = stripslashes($form->name); |
|
| 418 | + return $r; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + $query_key = is_numeric( $id ) ? 'id' : 'form_key'; |
|
| 422 | + $r = FrmDb::get_var( 'frm_forms', array( $query_key => $id ), 'name' ); |
|
| 423 | + $r = stripslashes($r); |
|
| 424 | + |
|
| 425 | + return $r; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * @param string $key |
|
| 430 | + * @return int form id |
|
| 431 | + */ |
|
| 432 | 432 | public static function &getIdByKey( $key ) { |
| 433 | - $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
|
| 434 | - return $id; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * @param int $id |
|
| 439 | - * @return string form key |
|
| 440 | - */ |
|
| 433 | + $id = FrmDb::get_var( 'frm_forms', array( 'form_key' => sanitize_title( $key ) ) ); |
|
| 434 | + return $id; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * @param int $id |
|
| 439 | + * @return string form key |
|
| 440 | + */ |
|
| 441 | 441 | public static function &getKeyById( $id ) { |
| 442 | - $id = (int) $id; |
|
| 443 | - $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
| 444 | - if ( $cache ) { |
|
| 445 | - return $cache->form_key; |
|
| 446 | - } |
|
| 442 | + $id = (int) $id; |
|
| 443 | + $cache = FrmAppHelper::check_cache($id, 'frm_form'); |
|
| 444 | + if ( $cache ) { |
|
| 445 | + return $cache->form_key; |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | - $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
| 448 | + $key = FrmDb::get_var( 'frm_forms', array( 'id' => $id ), 'form_key' ); |
|
| 449 | 449 | |
| 450 | - return $key; |
|
| 451 | - } |
|
| 450 | + return $key; |
|
| 451 | + } |
|
| 452 | 452 | |
| 453 | 453 | /** |
| 454 | 454 | * If $form is numeric, get the form object |
@@ -461,47 +461,47 @@ discard block |
||
| 461 | 461 | } |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - /** |
|
| 465 | - * @return object form |
|
| 466 | - */ |
|
| 467 | - public static function getOne( $id, $blog_id = false ) { |
|
| 468 | - global $wpdb; |
|
| 464 | + /** |
|
| 465 | + * @return object form |
|
| 466 | + */ |
|
| 467 | + public static function getOne( $id, $blog_id = false ) { |
|
| 468 | + global $wpdb; |
|
| 469 | 469 | |
| 470 | - if ( $blog_id && is_multisite() ) { |
|
| 471 | - global $wpmuBaseTablePrefix; |
|
| 470 | + if ( $blog_id && is_multisite() ) { |
|
| 471 | + global $wpmuBaseTablePrefix; |
|
| 472 | 472 | $prefix = $wpmuBaseTablePrefix ? $wpmuBaseTablePrefix . $blog_id . '_' : $wpdb->get_blog_prefix( $blog_id ); |
| 473 | 473 | |
| 474 | 474 | $table_name = $prefix . 'frm_forms'; |
| 475 | - } else { |
|
| 475 | + } else { |
|
| 476 | 476 | $table_name = $wpdb->prefix . 'frm_forms'; |
| 477 | - $cache = wp_cache_get($id, 'frm_form'); |
|
| 478 | - if ( $cache ) { |
|
| 479 | - if ( isset($cache->options) ) { |
|
| 480 | - $cache->options = maybe_unserialize($cache->options); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - return stripslashes_deep($cache); |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - if ( is_numeric($id) ) { |
|
| 488 | - $where = array( 'id' => $id ); |
|
| 489 | - } else { |
|
| 490 | - $where = array( 'form_key' => $id ); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - $results = FrmDb::get_row( $table_name, $where ); |
|
| 494 | - |
|
| 495 | - if ( isset($results->options) ) { |
|
| 496 | - wp_cache_set($results->id, $results, 'frm_form'); |
|
| 497 | - $results->options = maybe_unserialize($results->options); |
|
| 498 | - } |
|
| 499 | - return stripslashes_deep($results); |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * @return object|array of objects |
|
| 504 | - */ |
|
| 477 | + $cache = wp_cache_get($id, 'frm_form'); |
|
| 478 | + if ( $cache ) { |
|
| 479 | + if ( isset($cache->options) ) { |
|
| 480 | + $cache->options = maybe_unserialize($cache->options); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + return stripslashes_deep($cache); |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + if ( is_numeric($id) ) { |
|
| 488 | + $where = array( 'id' => $id ); |
|
| 489 | + } else { |
|
| 490 | + $where = array( 'form_key' => $id ); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + $results = FrmDb::get_row( $table_name, $where ); |
|
| 494 | + |
|
| 495 | + if ( isset($results->options) ) { |
|
| 496 | + wp_cache_set($results->id, $results, 'frm_form'); |
|
| 497 | + $results->options = maybe_unserialize($results->options); |
|
| 498 | + } |
|
| 499 | + return stripslashes_deep($results); |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * @return object|array of objects |
|
| 504 | + */ |
|
| 505 | 505 | public static function getAll( $where = array(), $order_by = '', $limit = '' ) { |
| 506 | 506 | if ( is_array( $where ) && ! empty( $where ) ) { |
| 507 | 507 | $results = FrmDb::get_results( 'frm_forms', $where, '*', array( 'order_by' => $order_by, 'limit' => $limit ) ); |
@@ -525,8 +525,8 @@ discard block |
||
| 525 | 525 | $results = reset( $results ); |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - return stripslashes_deep($results); |
|
| 529 | - } |
|
| 528 | + return stripslashes_deep($results); |
|
| 529 | + } |
|
| 530 | 530 | |
| 531 | 531 | /** |
| 532 | 532 | * Get all published forms |
@@ -544,47 +544,47 @@ discard block |
||
| 544 | 544 | return $forms; |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | - /** |
|
| 548 | - * @return int count of forms |
|
| 549 | - */ |
|
| 550 | - public static function &get_count() { |
|
| 551 | - global $wpdb; |
|
| 547 | + /** |
|
| 548 | + * @return int count of forms |
|
| 549 | + */ |
|
| 550 | + public static function &get_count() { |
|
| 551 | + global $wpdb; |
|
| 552 | 552 | |
| 553 | - $cache_key = 'frm_form_counts'; |
|
| 553 | + $cache_key = 'frm_form_counts'; |
|
| 554 | 554 | |
| 555 | - $counts = wp_cache_get( $cache_key, 'counts' ); |
|
| 556 | - if ( false !== $counts ) { |
|
| 557 | - return $counts; |
|
| 558 | - } |
|
| 555 | + $counts = wp_cache_get( $cache_key, 'counts' ); |
|
| 556 | + if ( false !== $counts ) { |
|
| 557 | + return $counts; |
|
| 558 | + } |
|
| 559 | 559 | |
| 560 | - $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' ); |
|
| 560 | + $results = (array) FrmDb::get_results( 'frm_forms', array( 'or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0 ), 'status, is_template' ); |
|
| 561 | 561 | |
| 562 | 562 | $statuses = array( 'published', 'draft', 'template', 'trash' ); |
| 563 | - $counts = array_fill_keys( $statuses, 0 ); |
|
| 563 | + $counts = array_fill_keys( $statuses, 0 ); |
|
| 564 | 564 | |
| 565 | - foreach ( $results as $row ) { |
|
| 566 | - if ( 'trash' != $row->status ) { |
|
| 567 | - if ( $row->is_template ) { |
|
| 565 | + foreach ( $results as $row ) { |
|
| 566 | + if ( 'trash' != $row->status ) { |
|
| 567 | + if ( $row->is_template ) { |
|
| 568 | 568 | $counts['template']++; |
| 569 | - } else { |
|
| 569 | + } else { |
|
| 570 | 570 | $counts['published']++; |
| 571 | - } |
|
| 572 | - } else { |
|
| 571 | + } |
|
| 572 | + } else { |
|
| 573 | 573 | $counts['trash']++; |
| 574 | - } |
|
| 574 | + } |
|
| 575 | 575 | |
| 576 | - if ( 'draft' == $row->status ) { |
|
| 576 | + if ( 'draft' == $row->status ) { |
|
| 577 | 577 | $counts['draft']++; |
| 578 | - } |
|
| 578 | + } |
|
| 579 | 579 | |
| 580 | - unset($row); |
|
| 581 | - } |
|
| 580 | + unset($row); |
|
| 581 | + } |
|
| 582 | 582 | |
| 583 | - $counts = (object) $counts; |
|
| 584 | - wp_cache_set( $cache_key, $counts, 'counts' ); |
|
| 583 | + $counts = (object) $counts; |
|
| 584 | + wp_cache_set( $cache_key, $counts, 'counts' ); |
|
| 585 | 585 | |
| 586 | - return $counts; |
|
| 587 | - } |
|
| 586 | + return $counts; |
|
| 587 | + } |
|
| 588 | 588 | |
| 589 | 589 | /** |
| 590 | 590 | * Clear form caching |
@@ -597,14 +597,14 @@ discard block |
||
| 597 | 597 | FrmAppHelper::cache_delete_group( 'frm_form' ); |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | - /** |
|
| 601 | - * @return array of errors |
|
| 602 | - */ |
|
| 600 | + /** |
|
| 601 | + * @return array of errors |
|
| 602 | + */ |
|
| 603 | 603 | public static function validate( $values ) { |
| 604 | - $errors = array(); |
|
| 604 | + $errors = array(); |
|
| 605 | 605 | |
| 606 | - return apply_filters('frm_validate_form', $errors, $values); |
|
| 607 | - } |
|
| 606 | + return apply_filters('frm_validate_form', $errors, $values); |
|
| 607 | + } |
|
| 608 | 608 | |
| 609 | 609 | public static function get_params( $form = null ) { |
| 610 | 610 | global $frm_vars; |
@@ -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 | |