public static function after_duplicate($form_id, $values) { $new_opts = $values['options'] = maybe_unserialize($values['options']); if (isset($new_opts['success_msg'])) { $new_opts['success_msg'] = FrmFieldsHelper::switch_field_ids($new_opts['success_msg']); } $new_opts = apply_filters('frm_after_duplicate_form_values', $new_opts, $form_id); if ($new_opts != $values['options']) { global $wpdb; $wpdb->update($wpdb->prefix . 'frm_forms', array('options' => maybe_serialize($new_opts)), array('id' => $form_id)); } }
private static function migrate_email_settings_to_action($form_options, $form_id, $post_type, &$imported, $switch) { // No old notifications or autoresponders to carry over if (!isset($form_options['auto_responder']) && !isset($form_options['notification']) && !isset($form_options['email_to'])) { return; } // Initialize notifications array $notifications = array(); // Migrate regular notifications self::migrate_notifications_to_action($form_options, $form_id, $notifications); // Migrate autoresponders self::migrate_autoresponder_to_action($form_options, $form_id, $notifications); if (empty($notifications)) { return; } foreach ($notifications as $new_notification) { $new_notification['post_type'] = $post_type; $new_notification['post_excerpt'] = 'email'; $new_notification['post_title'] = __('Email Notification', 'formidable'); $new_notification['menu_order'] = $form_id; $new_notification['post_status'] = 'publish'; // Switch field IDs and keys, if needed if ($switch) { // Switch field IDs in email conditional logic self::switch_email_contition_field_ids($new_notification['post_content']); // Switch all other field IDs in email $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids($new_notification['post_content']); } $new_notification['post_content'] = FrmAppHelper::prepare_and_encode($new_notification['post_content']); $exists = get_posts(array('name' => $new_notification['post_name'], 'post_type' => $new_notification['post_type'], 'post_status' => $new_notification['post_status'], 'numberposts' => 1)); if (empty($exists)) { FrmAppHelper::save_json_post($new_notification); $imported['imported']['actions']++; } unset($new_notification); } }
public function duplicate_one($action, $form_id) { global $frm_duplicate_ids; $action->menu_order = $form_id; $switch = $this->get_global_switch_fields(); foreach ((array) $action->post_content as $key => $val) { if (is_numeric($val) && isset($frm_duplicate_ids[$val])) { $action->post_content[$key] = $frm_duplicate_ids[$val]; } else { if (!is_array($val)) { $action->post_content[$key] = FrmFieldsHelper::switch_field_ids($val); } else { if (isset($switch[$key]) && is_array($switch[$key])) { // loop through each value if empty if (empty($switch[$key])) { $switch[$key] = array_keys($val); } foreach ($switch[$key] as $subkey) { $action->post_content[$key] = $this->duplicate_array_walk($action->post_content[$key], $subkey, $val); } } } } unset($key, $val); } unset($action->ID); return $this->save_settings($action); }
public static function switch_field_ids($val) { // for reverse compatability return FrmFieldsHelper::switch_field_ids($val); }
function after_duplicate($new_opts, $id) { if (isset($new_opts['success_url'])) { $new_opts['success_url'] = FrmFieldsHelper::switch_field_ids($new_opts['success_url']); } if (!isset($new_opts['notification'])) { return $new_opts; } global $frm_duplicate_ids; foreach ((array) $new_opts['notification'] as $n => $v) { foreach ($v as $o => $opt) { if (in_array($o, array('reply_to_name', 'reply_to')) && is_numeric($opt) && isset($frm_duplicate_ids[$opt])) { $new_opts['notification'][$n][$o] = $frm_duplicate_ids[$opt]; } else { if (in_array($o, array('email_subject', 'email_to', 'email_message'))) { $new_opts['notification'][$n][$o] = FrmFieldsHelper::switch_field_ids($new_opts['notification'][$n][$o]); } else { if ('conditions' == $o) { foreach ((array) $opt as $ck => $cv) { if (isset($cv['hide_field']) && is_numeric($cv['hide_field']) && isset($frm_duplicate_ids[$cv['hide_field']])) { $new_opts['notification'][$n]['conditions'][$ck]['hide_field'] = $frm_duplicate_ids[$cv['hide_field']]; } unset($ck); unset($cv); } } } } unset($o); unset($opt); } unset($n); unset($opt); } return $new_opts; }
public static function import_xml_views($views, $imported) { global $frm_duplicate_ids; $imported['posts'] = array(); foreach ($views as $item) { $post = array('post_title' => (string) $item->title, 'post_name' => (string) $item->post_name, 'post_type' => (string) $item->post_type, 'post_password' => (string) $item->post_password, 'guid' => (string) $item->guid, 'post_status' => (string) $item->status, 'post_author' => FrmProAppHelper::get_user_id_param((string) $item->post_author), 'post_id' => (int) $item->post_id, 'post_parent' => (int) $item->post_parent, 'menu_order' => (int) $item->menu_order, 'post_content' => FrmFieldsHelper::switch_field_ids((string) $item->content), 'post_excerpt' => FrmFieldsHelper::switch_field_ids((string) $item->excerpt), 'is_sticky' => (string) $item->is_sticky, 'comment_status' => (string) $item->comment_status, 'post_date' => (string) $item->post_date, 'post_date_gmt' => (string) $item->post_date_gmt, 'ping_status' => (string) $item->ping_status); if (isset($item->attachment_url)) { $post['attachment_url'] = (string) $item->attachment_url; } $post['postmeta'] = array(); foreach ($item->postmeta as $meta) { $m = array('key' => (string) $meta->meta_key, 'value' => (string) $meta->meta_value); //switch old form and field ids to new ones if ($m['key'] == 'frm_form_id' && isset($imported['forms'][(int) $meta->meta_value])) { $m['value'] = $imported['forms'][(int) $meta->meta_value]; } else { $m['value'] = FrmAppHelper::maybe_json_decode($m['value'], true); if (!empty($frm_duplicate_ids)) { if ($m['key'] == 'frm_dyncontent') { $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); } else { if ($m['key'] == 'frm_options') { if (isset($m['value']['date_field_id']) && is_numeric($m['value']['date_field_id']) && isset($frm_duplicate_ids[$m['value']['date_field_id']])) { $m['value']['date_field_id'] = $frm_duplicate_ids[$m['value']['date_field_id']]; } if (isset($m['value']['edate_field_id']) && is_numeric($m['value']['edate_field_id']) && isset($frm_duplicate_ids[$m['value']['edate_field_id']])) { $m['value']['edate_field_id'] = $frm_duplicate_ids[$m['value']['edate_field_id']]; } if (isset($m['value']['order_by']) && !empty($m['value']['order_by'])) { if (is_numeric($m['value']['order_by']) && isset($frm_duplicate_ids[$m['value']['order_by']])) { $m['value']['order_by'] = $frm_duplicate_ids[$m['value']['order_by']]; } else { if (is_array($m['value']['order_by'])) { foreach ($m['value']['order_by'] as $mk => $mv) { if (isset($frm_duplicate_ids[$mv])) { $m['value']['order_by'][$mk] = $frm_duplicate_ids[$mv]; } unset($mk); unset($mv); } } } } if (isset($m['value']['where']) && !empty($m['value']['where'])) { foreach ((array) $m['value']['where'] as $mk => $mv) { if (isset($frm_duplicate_ids[$mv])) { $m['value']['where'][$mk] = $frm_duplicate_ids[$mv]; } unset($mk); unset($mv); } } } } } } if (!is_array($m['value'])) { $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); } $post['postmeta'][(string) $meta->meta_key] = $m['value']; unset($m); unset($meta); } //Add terms $post['tax_input'] = array(); foreach ($item->category as $c) { $att = $c->attributes(); if (isset($att['nicename'])) { $taxonomy = (string) $att['domain']; if (is_taxonomy_hierarchical($taxonomy)) { $name = (string) $att['nicename']; $h_term = get_term_by('slug', $name, $taxonomy); if ($h_term) { $name = $h_term->term_id; } unset($h_term); } else { $name = (string) $c; } if (!isset($post['tax_input'][$taxonomy])) { $post['tax_input'][$taxonomy] = array(); } $post['tax_input'][$taxonomy][] = $name; unset($name); } } unset($item); // edit view if the key and created time match $old_id = $post['post_id']; $match_by = array('post_type' => $post['post_type'], 'name' => $post['post_name'], 'post_status' => $post['post_status'], 'posts_per_page' => 1); if (in_array($post['post_status'], array('trash', 'draft'))) { $match_by['include'] = $post['post_id']; unset($match_by['name']); } $editing = get_posts($match_by); if (!empty($editing) && current($editing)->post_date == $post['post_date']) { $post['ID'] = current($editing)->ID; } unset($editing); //create post $post_id = wp_insert_post($post); if (!is_numeric($post_id)) { continue; } foreach ($post['postmeta'] as $k => $v) { if ('_edit_last' == $k) { $v = FrmProAppHelper::get_user_id_param($v); } else { if ('_thumbnail_id' == $k) { //change the attachment ID $v = self::get_file_id($v); } } $u = update_post_meta($post_id, $k, $v); unset($k); unset($v); } if (isset($post['ID'])) { $imported['updated'][$post['post_type'] == 'frm_display' ? 'views' : 'posts']++; } else { $imported['imported'][$post['post_type'] == 'frm_display' ? 'views' : 'posts']++; } unset($post); $imported['posts'][(int) $old_id] = $post_id; } return $imported; }
public static function after_duplicate($new_opts) { if (isset($new_opts['success_url'])) { $new_opts['success_url'] = FrmFieldsHelper::switch_field_ids($new_opts['success_url']); } return $new_opts; }