/** * @covers FrmForm::duplicate */ function test_duplicate() { $form = $this->factory->form->get_object_by_id('contact'); $id = FrmForm::duplicate($form->id); $this->assertTrue(is_numeric($id)); $this->assertNotEmpty($id); // check the number of form actions $original_actions = FrmFormAction::get_action_for_form($form->id); $new_actions = FrmFormAction::get_action_for_form($id); $this->assertEquals(count($original_actions), count($new_actions)); }
/** * @covers FrmForm::duplicate */ function test_duplicate() { $form = $this->factory->form->get_object_by_id($this->all_fields_form_key); $id = FrmForm::duplicate($form->id); $this->assertTrue(is_numeric($id)); $this->assertNotEmpty($id); // check the number of form actions $original_actions = FrmFormAction::get_action_for_form($form->id); $new_actions = FrmFormAction::get_action_for_form($id); $this->assertEquals(count($original_actions), count($new_actions)); // For repeating sections self::_check_if_child_forms_duplicate($form->id, $id); self::_check_if_form_select_updates($form->id, $id); }
/** * @covers FrmNotification::trigger_email */ public function test_trigger_email() { // get the imported form with the email action $form = $this->factory->form->get_object_by_id($this->contact_form_key); // get the email settings $actions = FrmFormAction::get_action_for_form($form->id, 'email'); $this->assertNotEmpty($actions); $entry_data = $this->factory->field->generate_entry_array($form); $entry_id = $this->factory->entry->create($entry_data); $entry = FrmEntry::getOne($entry_id, true); $this->assertNotEmpty($entry); foreach ($actions as $action) { $expected_to = $action->post_content['email_to']; FrmNotification::trigger_email($action, $entry, $form); $this->assertEquals($expected_to, $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0]); //$this->assertNotEmpty( strpos( $GLOBALS['phpmailer']->mock_sent[0]['header'], 'Reply-To: admin@example.org' ) ); // TODO: check email body, reply to, cc, bcc, from } }
public static function insert_post($entry, $new_post, $post, $form = false, $action = false) { if (!$action) { $action = FrmFormAction::get_action_for_form($form->id, 'wppost', 1); if (!$action) { return; } } $post_fields = self::get_post_fields($new_post, 'insert_post'); $editing = true; if (empty($post)) { $editing = false; $post = array(); } foreach ($post_fields as $post_field) { if (isset($new_post[$post_field])) { $post[$post_field] = $new_post[$post_field]; } unset($post_field); } unset($post_fields); $dyn_content = ''; self::post_value_overrides($post, $new_post, $editing, $form, $entry, $dyn_content); $post_ID = wp_insert_post($post); if (is_wp_error($post_ID) || empty($post_ID)) { return; } self::save_taxonomies($new_post, $post_ID); self::link_post_attachments($post_ID, $editing); self::save_post_meta($new_post, $post_ID); self::save_post_id_to_entry($post_ID, $entry, $editing); // Make sure save_post_id_to_entry stays above save_dynamic_content because // save_dynamic_content needs updated entry object from save_post_id_to_entry self::save_dynamic_content($post, $post_ID, $dyn_content, $form, $entry); self::delete_duplicated_meta($action, $entry); return $post_ID; }
/** * @covers FrmDb::migrate_to_17 */ function test_migrate_from_12_to_17() { $this->frm_install(); update_option('frm_db_version', 12); $form = FrmForm::getOne('contact-db12'); $this->assertNotEmpty($form); $this->assertTrue(is_numeric($form->id)); $notification = array(0 => array('email_to' => '*****@*****.**', 'also_email_to' => array(1, 2), 'reply_to' => '*****@*****.**', 'reply_to_name' => 'Reply to me', 'cust_reply_to' => '', 'cust_reply_to_name' => '', 'plain_text' => 1, 'email_message' => 'This is my email message. [default-message]', 'email_subject' => 'The subject', 'update_email' => 2, 'inc_user_info' => 1)); $form->options['notification'] = $notification; global $wpdb; $updated = $wpdb->update($wpdb->prefix . 'frm_forms', array('options' => maybe_serialize($form->options)), array('id' => $form->id)); FrmForm::clear_form_cache(); $this->assertEquals($updated, 1); $form = FrmForm::getOne('contact-db12'); $this->assertNotEmpty($form->options, 'The form settings are empty'); $this->assertTrue(isset($form->options['notification']), 'The old notification settings are missing'); $this->assertEquals($form->options['notification'][0]['email_to'], '*****@*****.**'); // migrate data FrmAppController::install(); $form_actions = FrmFormAction::get_action_for_form($form->id, 'email'); foreach ($form_actions as $action) { $this->assertTrue(strpos($action->post_content['email_to'], '*****@*****.**') !== false); } }
public static function destroy_all() { if (!current_user_can('frm_delete_entries')) { $frm_settings = FrmAppHelper::get_settings(); wp_die($frm_settings->admin_permission); } global $wpdb; $params = FrmForm::get_admin_params(); $message = ''; $errors = array(); $form_id = (int) $params['form']; if ($form_id) { $entry_ids = FrmDb::get_col('frm_items', array('form_id' => $form_id)); $action = FrmFormAction::get_action_for_form($form_id, 'wppost', 1); if ($action) { // this action takes a while, so only trigger it if there are posts to delete foreach ($entry_ids as $entry_id) { do_action('frm_before_destroy_entry', $entry_id); unset($entry_id); } } $wpdb->query($wpdb->prepare("DELETE em.* FROM {$wpdb->prefix}frm_item_metas as em INNER JOIN {$wpdb->prefix}frm_items as e on (em.item_id=e.id) and form_id=%d", $form_id)); $results = $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $form_id)); if ($results) { $message = __('Entries were Successfully Destroyed', 'formidable'); } } else { $errors = __('No entries were specified', 'formidable'); } self::display_list($message, $errors); }
/** * @param string $id_base */ public function FrmFormAction($id_base, $name, $action_options = array(), $control_options = array()) { FrmFormAction::__construct($id_base, $name, $action_options, $control_options); }
public function __construct() { $action_ops = FrmFormAction::default_action_opts('frm_highrise_icon'); $this->FrmFormAction('highrise', __('Highrise', 'formidable'), $action_ops); }
public static function set_post_fields($field, $value, $errors) { // save file ids for later use if ('file' == $field->type) { global $frm_vars; if (!isset($frm_vars['media_id'])) { $frm_vars['media_id'] = array(); } $frm_vars['media_id'][$field->id] = $value; } if (empty($value) || !FrmField::is_option_true($field, 'unique')) { return $errors; } $post_form_action = FrmFormAction::get_action_for_form($field->form_id, 'wppost', 1); if (!$post_form_action) { return $errors; } // check if this is a regular post field $post_field = array_search($field->id, $post_form_action->post_content); $custom_field = ''; if (!$post_field) { // check if this is a custom field foreach ($post_form_action->post_content['post_custom_fields'] as $custom_field) { if (isset($custom_field['field_id']) && !empty($custom_field['field_id']) && isset($custom_field['meta_name']) && !empty($custom_field['meta_name']) && $field->id == $custom_field['field_id']) { $post_field = 'post_custom'; $custom_field = $custom_field['meta_name']; } } if (!$post_field) { return $errors; } } // check for unique values in post fields $entry_id = $_POST && isset($_POST['id']) ? $_POST['id'] : false; $post_id = false; if ($entry_id) { global $wpdb; $post_id = FrmDb::get_var($wpdb->prefix . 'frm_items', array('id' => $entry_id), 'post_id'); } if (self::post_value_exists($post_field, $value, $post_id, $custom_field)) { $errors['field' . $field->id] = FrmFieldsHelper::get_error_msg($field, 'unique_msg'); } return $errors; }
/** * @param string $event */ public static function trigger_actions($event, $form, $entry, $type = 'all', $args = array()) { $form_actions = FrmFormAction::get_action_for_form(is_object($form) ? $form->id : $form, $type); if (empty($form_actions)) { return; } FrmForm::maybe_get_form($form); $link_settings = self::get_form_actions($type); if ('all' != $type) { $link_settings = array($type => $link_settings); } $stored_actions = $action_priority = array(); foreach ($form_actions as $action) { if (!in_array($event, $action->post_content['event'])) { continue; } if (!is_object($entry)) { $entry = FrmEntry::getOne($entry, true); } if (empty($entry) || $entry->is_draft) { continue; } $child_entry = $form && is_numeric($form->parent_form_id) && $form->parent_form_id || $entry && ($entry->form_id != $form->id || $entry->parent_item_id) || isset($args['is_child']) && $args['is_child']; if ($child_entry) { //don't trigger actions for sub forms continue; } // check conditional logic $stop = FrmFormAction::action_conditions_met($action, $entry); if ($stop) { continue; } // store actions so they can be triggered with the correct priority $stored_actions[$action->ID] = $action; $action_priority[$action->ID] = $link_settings[$action->post_excerpt]->action_options['priority']; unset($action); } if (!empty($stored_actions)) { asort($action_priority); // make sure hooks are loaded new FrmNotification(); foreach ($action_priority as $action_id => $priority) { $action = $stored_actions[$action_id]; do_action('frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event); do_action('frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form); // If post is created, get updated $entry object if ($action->post_excerpt == 'wppost' && $event == 'create') { $entry = FrmEntry::getOne($entry->id, true); } } } }
} } else { ?> <p><label class="frm_left_label"><?php _e('Trigger this action after', 'formidable'); ?> </label> <select name="<?php echo esc_attr($action_control->get_field_name('event')); ?> []" multiple="multiple" class="frm_multiselect" id="<?php echo esc_attr($action_control->get_field_id('event')); ?> "> <?php $event_labels = FrmFormAction::trigger_labels(); foreach ($action_control->action_options['event'] as $event) { ?> <option value="<?php echo esc_attr($event); ?> " <?php echo in_array($event, (array) $form_action->post_content['event']) ? ' selected="selected"' : ''; ?> ><?php echo isset($event_labels[$event]) ? $event_labels[$event] : $event; ?> </option> <?php } ?>
public static function &post_type($form) { if (is_numeric($form)) { $form_id = $form; } else { $form_id = (array) $form['id']; } $action = FrmFormAction::get_action_for_form($form_id, 'wppost'); $action = reset($action); if (!$action || !isset($action->post_content['post_type'])) { $type = 'post'; } else { $type = $action->post_content['post_type']; } return $type; }
/** * Constructs and initializes an Formidable payment action. * * @see https://github.com/wp-premium/formidable/blob/2.0.21/classes/models/FrmFormAction.php#L58-L94 * @see https://github.com/wp-premium/formidable-paypal/blob/3.02/models/FrmPaymentAction.php */ public function __construct() { parent::__construct('pronamic_pay', __('Pronamic Pay', 'pronamic_ideal'), array('classes' => 'pronamic-pay-formidable-icon', 'active' => true, 'event' => array('create'), 'priority' => 9, 'limit' => 99)); }
public static function default_action_opts($class = '') { //_deprecated_function( __FUNCTION__, '2.0.9', 'FrmFormAction::default_action_opts' ); return FrmFormAction::default_action_opts($class); }
public static function create_entry_from_post_box($post_type, $post = false) { if (!$post || !isset($post->ID) || $post_type == 'attachment' || $post_type == 'link') { return; } global $wpdb, $frm_vars; //don't show the meta box if there is already an entry for this post $post_entry = FrmDb::get_var($wpdb->prefix . 'frm_items', array('post_id' => $post->ID)); if ($post_entry) { return; } //don't show meta box if no forms are set up to create this post type $actions = FrmFormAction::get_action_for_form(0, 'wppost'); if (!$actions) { return; } $form_ids = array(); foreach ($actions as $action) { if ($action->post_content['post_type'] == $post_type && $action->menu_order) { $form_ids[] = $action->menu_order; } } if (empty($form_ids)) { return; } $forms = FrmDb::get_results('frm_forms', array('id' => $form_ids), 'id, name'); $frm_vars['post_forms'] = $forms; if (current_user_can('frm_create_entries')) { add_meta_box('frm_create_entry', __('Create Entry in Form', 'formidable'), 'FrmProEntriesController::render_meta_box_content', null, 'side'); } }
function __construct() { $action_ops = array('classes' => 'ab-icon frm_dashicon_font dashicons-before', 'limit' => 1, 'priority' => 40, 'event' => array('create', 'update', 'import'), 'force_event' => true); parent::__construct('wppost', __('Create Post', 'formidable'), $action_ops); }
/** * @param string $event */ public static function trigger_actions($event, $form, $entry, $type = 'all', $args = array()) { $form_actions = FrmFormAction::get_action_for_form(is_object($form) ? $form->id : $form, $type); if (empty($form_actions)) { return; } FrmForm::maybe_get_form($form); $link_settings = self::get_form_actions($type); if ('all' != $type) { $link_settings = array($type => $link_settings); } $stored_actions = $action_priority = array(); $importing = in_array($event, array('create', 'update')) && defined('WP_IMPORTING') && WP_IMPORTING; foreach ($form_actions as $action) { $trigger_on_import = $importing && in_array('import', $action->post_content['event']); $skip_this_action = !in_array($event, $action->post_content['event']) && !$trigger_on_import; $skip_this_action = apply_filters('frm_skip_form_action', $skip_this_action, compact('action', 'entry', 'form', 'event')); if ($skip_this_action) { continue; } if (!is_object($entry)) { $entry = FrmEntry::getOne($entry, true); } if (empty($entry) || $entry->is_draft && $event != 'draft') { continue; } $child_entry = $form && is_numeric($form->parent_form_id) && $form->parent_form_id || $entry && ($entry->form_id != $form->id || $entry->parent_item_id) || isset($args['is_child']) && $args['is_child']; if ($child_entry) { // maybe trigger actions for sub forms $trigger_children = apply_filters('frm_use_embedded_form_actions', false, compact('form', 'entry')); if (!$trigger_children) { continue; } } // check conditional logic $stop = FrmFormAction::action_conditions_met($action, $entry); if ($stop) { continue; } // store actions so they can be triggered with the correct priority $stored_actions[$action->ID] = $action; $action_priority[$action->ID] = $link_settings[$action->post_excerpt]->action_options['priority']; unset($action); } if (!empty($stored_actions)) { asort($action_priority); // make sure hooks are loaded new FrmNotification(); foreach ($action_priority as $action_id => $priority) { $action = $stored_actions[$action_id]; do_action('frm_trigger_' . $action->post_excerpt . '_action', $action, $entry, $form, $event); do_action('frm_trigger_' . $action->post_excerpt . '_' . $event . '_action', $action, $entry, $form); // If post is created, get updated $entry object if ($action->post_excerpt == 'wppost' && $event == 'create') { $entry = FrmEntry::getOne($entry->id, true); } } } }
public function __construct() { $action_ops = array('classes' => 'frm_email_icon frm_icon_font', 'active' => true, 'event' => array('create'), 'limit' => 99, 'priority' => 10, 'ajax_load' => false); $action_ops = apply_filters('frm_email_control_settings', $action_ops); parent::__construct('email', __('Email Notification', 'formidable'), $action_ops); }
public static function update_form_field_options($field_options, $field) { $field_options['post_field'] = $field_options['custom_field'] = ''; $field_options['taxonomy'] = 'category'; $field_options['exclude_cat'] = 0; $action_name = apply_filters('frm_save_post_name', 'wppost', $field); $post_action = FrmFormAction::get_action_for_form($field->form_id, $action_name, 1); if (!$post_action) { return $field_options; } $post_fields = array('post_content', 'post_excerpt', 'post_title', 'post_name', 'post_date', 'post_status', 'post_password'); $this_post_field = array_search($field->id, $post_action->post_content); if (in_array($this_post_field, $post_fields)) { $field_options['post_field'] = $this_post_field; } if ($this_post_field == 'post_status') { $field_options['separate_value'] = 1; } unset($this_post_field); //Set post categories foreach ((array) $post_action->post_content['post_category'] as $field_name) { if (!isset($field_name['field_id']) || $field_name['field_id'] != $field->id) { continue; } $field_options['post_field'] = 'post_category'; $field_options['taxonomy'] = isset($field_name['meta_name']) ? $field_name['meta_name'] : 'category'; $field_options['exclude_cat'] = isset($field_name['exclude_cat']) ? $field_name['exclude_cat'] : 0; } //Set post custom fields foreach ((array) $post_action->post_content['post_custom_fields'] as $field_name) { if (!isset($field_name['field_id']) || $field_name['field_id'] != $field->id) { continue; } $field_options['post_field'] = 'post_custom'; $field_options['custom_field'] = $field_name['meta_name'] == '' && isset($field_name['custom_meta_name']) && $field_name['custom_meta_name'] != '' ? $field_name['custom_meta_name'] : $field_name['meta_name']; } return $field_options; }