コード例 #1
1
 function get_id_by_key($entry_key)
 {
     return FrmEntry::get_id_by_key($entry_key);
 }
コード例 #2
0
 function user_can_edit_check($entry, $form)
 {
     global $user_ID;
     if (!$user_ID) {
         return false;
     }
     if (is_numeric($form)) {
         $form = FrmForm::getOne($form);
     }
     $form->options = maybe_unserialize($form->options);
     //if editable and user can edit someone elses entry
     if ($form->editable and isset($form->options['open_editable']) and $form->options['open_editable'] and isset($form->options['open_editable_role']) and FrmAppHelper::user_has_permission($form->options['open_editable_role'])) {
         return true;
     }
     if (is_object($entry)) {
         if ($entry->user_id == $user_ID) {
             return true;
         } else {
             return false;
         }
     }
     $where = "user_id='{$user_ID}' and fr.id='{$form->id}'";
     if ($entry and !empty($entry)) {
         if (is_numeric($entry)) {
             $where .= ' and it.id=' . $entry;
         } else {
             $where .= " and item_key='" . $entry . "'";
         }
     }
     return FrmEntry::getAll($where, '', ' LIMIT 1', true);
 }
コード例 #3
0
 public static function validate($values, $exclude = false)
 {
     global $wpdb;
     FrmEntry::sanitize_entry_post($values);
     $errors = array();
     if (!isset($values['form_id']) || !isset($values['item_meta'])) {
         $errors['form'] = __('There was a problem with your submission. Please try again.', 'formidable');
         return $errors;
     }
     if (FrmAppHelper::is_admin() && is_user_logged_in() && (!isset($values['frm_submit_entry_' . $values['form_id']]) || !wp_verify_nonce($values['frm_submit_entry_' . $values['form_id']], 'frm_submit_entry_nonce'))) {
         $errors['form'] = __('You do not have permission to do that', 'formidable');
     }
     if (!isset($values['item_key']) || $values['item_key'] == '') {
         $_POST['item_key'] = $values['item_key'] = FrmAppHelper::get_unique_key('', $wpdb->prefix . 'frm_items', 'item_key');
     }
     $where = apply_filters('frm_posted_field_ids', array('fi.form_id' => $values['form_id']));
     // Don't get subfields
     $where['fr.parent_form_id'] = array(null, 0);
     // Don't get excluded fields (like file upload fields in the ajax validation)
     if (!empty($exclude)) {
         $where['fi.type not'] = $exclude;
     }
     $posted_fields = FrmField::getAll($where, 'field_order');
     // Pass exclude value to validate_field function so it can be used for repeating sections
     $args = array('exclude' => $exclude);
     foreach ($posted_fields as $posted_field) {
         self::validate_field($posted_field, $errors, $values, $args);
         unset($posted_field);
     }
     // check for spam
     self::spam_check($exclude, $values, $errors);
     $errors = apply_filters('frm_validate_entry', $errors, $values, compact('exclude'));
     return $errors;
 }
コード例 #4
0
 public static function trigger_delete_actions($entry_id, $entry = false)
 {
     if (empty($entry)) {
         $entry = FrmEntry::getOne($entry_id);
     }
     FrmFormActionsController::trigger_actions('delete', $entry->form_id, $entry);
 }
コード例 #5
0
 public function prepare_items()
 {
     global $wpdb, $per_page;
     $per_page = $this->get_items_per_page('formidable_page_formidable_entries_per_page');
     $form_id = $this->params['form'];
     if (!$form_id) {
         $this->items = array();
         $this->set_pagination_args(array('total_items' => 0, 'per_page' => $per_page));
         return;
     }
     $default_orderby = 'id';
     $default_order = 'DESC';
     $s_query = array('it.form_id' => $form_id);
     $s = isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : '';
     if ($s != '' && FrmAppHelper::pro_is_installed()) {
         $fid = isset($_REQUEST['fid']) ? sanitize_title($_REQUEST['fid']) : '';
         $s_query = FrmProEntriesHelper::get_search_str($s_query, $s, $form_id, $fid);
     }
     $orderby = isset($_REQUEST['orderby']) ? sanitize_title($_REQUEST['orderby']) : $default_orderby;
     if (strpos($orderby, 'meta') !== false) {
         $order_field_type = FrmField::get_type(str_replace('meta_', '', $orderby));
         $orderby .= in_array($order_field_type, array('number', 'scale')) ? ' +0 ' : '';
     }
     $order = isset($_REQUEST['order']) ? sanitize_title($_REQUEST['order']) : $default_order;
     $order = ' ORDER BY ' . $orderby . ' ' . $order;
     $page = $this->get_pagenum();
     $start = (int) isset($_REQUEST['start']) ? absint($_REQUEST['start']) : ($page - 1) * $per_page;
     $this->items = FrmEntry::getAll($s_query, $order, ' LIMIT ' . $start . ',' . $per_page, true, false);
     $total_items = FrmEntry::getRecordCount($s_query);
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page));
 }
コード例 #6
0
 /**
  * @covers FrmEntry::getAll
  */
 function test_getAll()
 {
     $form = $this->factory->form->get_object_by_id($this->contact_form_key);
     $entry_data = $this->factory->field->generate_entry_array($form);
     $entry_id = $this->factory->entry->create_many(10, $entry_data);
     $items = FrmEntry::getAll(array('it.form_id' => $form->id));
     $this->assertTrue(count($items) >= 10, 'There are no entries in form ' . $form->id);
 }
コード例 #7
0
 /**
  * Constructs and initializes an Formidable Forms payment data object.
  *
  * @param string $entry_id
  * @param string $form_id
  * @param WP_Post $action
  */
 public function __construct($entry_id, $form_id, $action)
 {
     parent::__construct();
     $this->entry_id = $entry_id;
     $this->form_id = $form_id;
     $this->action = $action;
     // @see https://github.com/wp-premium/formidable-paypal/blob/3.02/controllers/FrmPaymentsController.php#L285
     $this->entry = FrmEntry::getOne($this->entry_id, true);
 }
コード例 #8
0
 /**
  * Make sure all entries are still retrieved with All Entries View even if entry parameter is in the URL
  */
 function _test_all_entries_view_with_entry_param($detail_type)
 {
     // Get all the entries in the form
     $where['form_key'] = 'all_field_types';
     $total_entries = count(FrmEntry::getAll($where));
     // Get the All Entries View Content
     $all_entries_view = do_shortcode('[display-frm-data id="all-entries"]');
     $entry_num = substr_count($all_entries_view, 'All Entries');
     $this->assertTrue($total_entries == $entry_num, 'All Entries View is affected by entry ' . $detail_type . ' parameter');
 }
コード例 #9
0
ファイル: Analytics.php プロジェクト: nextbuzz/buzz-seo
 /**
  * Formidable after submission
  * @param int $entryId
  * @param int $formId
  */
 public function formidableSubmission($entryId, $formId)
 {
     // Since a lot of form types do not reload the page, we handle the form event server side.
     $tracker = $this->getGATracker();
     if ($tracker) {
         $entry = \FrmEntry::getOne($entryId);
         $description = unserialize($entry->description);
         $referrer = $description['referrer'];
         $tracker->event("Formidable", "Submit Form ID " . $formId, $referrer);
     }
 }
コード例 #10
0
 function import_xml()
 {
     // install test data in older format
     add_filter('frm_default_templates_files', 'FrmUnitTest::install_data');
     FrmXMLController::add_default_templates();
     $form = FrmForm::getOne('contact-db12');
     $this->assertEquals($form->form_key, 'contact-db12');
     $entry = FrmEntry::getOne('utah');
     $this->assertNotEmpty($entry);
     $this->assertEquals($entry->item_key, 'utah');
 }
コード例 #11
0
 function _get_dynamic_entry_ids($form_key, $where_field_key, $args)
 {
     // Get where_field
     $where_field = FrmField::getOne($where_field_key);
     // Get all entry IDs for form
     $form_id = $this->factory->form->get_id_by_key($form_key);
     $entry_ids = FrmEntry::getAll(array('it.form_id' => $form_id), '', '', false, false);
     // Prepare the args
     self::_do_prepare_where_args($args, $where_field, $entry_ids);
     // Set new where_val
     self::_do_prepare_dfe_text($args, $where_field);
     return $args['where_val'];
 }
コード例 #12
0
 public static function show_entry($atts)
 {
     $atts = shortcode_atts(array('id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false, 'user_info' => false, 'include_blank' => false, 'default_email' => false, 'form_id' => false, 'format' => 'text', 'direction' => 'ltr', 'font_size' => '', 'text_color' => '', 'border_width' => '', 'border_color' => '', 'bg_color' => '', 'alt_bg_color' => '', 'clickable' => false), $atts);
     if ($atts['format'] != 'text') {
         //format options are text, array, or json
         $atts['plain_text'] = true;
     }
     if (is_object($atts['entry']) && !isset($atts['entry']->metas)) {
         // if the entry does not include metas, force it again
         $atts['entry'] = false;
     }
     if (!$atts['entry'] || !is_object($atts['entry'])) {
         if (!$atts['id'] && !$atts['default_email']) {
             return '';
         }
         if ($atts['id']) {
             $atts['entry'] = FrmEntry::getOne($atts['id'], true);
         }
     }
     if ($atts['entry']) {
         $atts['form_id'] = $atts['entry']->form_id;
         $atts['id'] = $atts['entry']->id;
     }
     if (!$atts['fields'] || !is_array($atts['fields'])) {
         $atts['fields'] = FrmField::get_all_for_form($atts['form_id'], '', 'include');
     }
     $values = array();
     foreach ($atts['fields'] as $f) {
         if ($f->type != 'password' && $f->type != 'credit_card') {
             self::fill_entry_values($atts, $f, $values);
         }
         unset($f);
     }
     self::fill_entry_user_info($atts, $values);
     if ($atts['format'] == 'json') {
         return json_encode($values);
     } else {
         if ($atts['format'] == 'array') {
             return $values;
         }
     }
     $content = array();
     self::convert_entry_to_content($values, $atts, $content);
     if ('text' == $atts['format']) {
         $content = implode('', $content);
     }
     if ($atts['clickable']) {
         $content = make_clickable($content);
     }
     return $content;
 }
コード例 #13
0
 /**
  * @covers FrmEntry::package_entry_to_update
  */
 function test_package_entry_to_update()
 {
     $entry = FrmEntry::getOne('post-entry-1', true);
     $values = self::_setup_test_update_values($entry);
     $new_values = self::_do_private_package_entry_to_update_function($entry->id, $values);
     self::_check_packaged_entry_name($values, $new_values);
     self::_check_packaged_form_id($values, $new_values);
     self::_check_packaged_is_draft($values, $new_values);
     self::_check_packaged_updated_at($values, $new_values);
     self::_check_packaged_updated_by($values, $new_values);
     self::_check_packaged_post_id($values, $new_values);
     self::_check_packaged_item_key($values, $new_values);
     self::_check_packaged_parent_item_id($values, $new_values);
     self::_check_packaged_frm_user_id($values, $new_values);
 }
コード例 #14
0
 /**
  * Search for a value in an entry
  */
 function test_search_by_field()
 {
     $form = $this->factory->form->create_and_get();
     $this->assertNotEmpty($form);
     $field_id = $this->factory->field->create(array('type' => 'email', 'form_id' => $form->id));
     $this->assertNotEmpty($field_id);
     $this->assertTrue(is_numeric($field_id));
     $entry_data = $this->factory->field->generate_entry_array($form);
     $this->factory->entry->create_many(10, $entry_data);
     $s_query = array('it.form_id' => $form->id);
     if (is_callable('FrmProEntriesHelper::get_search_str')) {
         $s = '*****@*****.**';
         //$s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form->id, $field_id );
     }
     $items = FrmEntry::getAll($s_query, '', '', true, false);
     $this->assertNotEmpty($items);
 }
コード例 #15
0
 public static function get_post_or_meta_value($entry, $field, $atts = array())
 {
     $defaults = array('links' => true, 'show' => '', 'truncate' => true, 'sep' => ', ');
     $atts = wp_parse_args((array) $atts, $defaults);
     FrmEntry::maybe_get_entry($entry);
     if (empty($entry) || empty($field)) {
         return '';
     }
     if ($entry->post_id) {
         if (!isset($field->field_options['custom_field'])) {
             $field->field_options['custom_field'] = '';
         }
         if (!isset($field->field_options['post_field'])) {
             $field->field_options['post_field'] = '';
         }
         $links = $atts['links'];
         if ($field->type == 'tag' || $field->field_options['post_field']) {
             $post_args = array('type' => $field->type, 'form_id' => $field->form_id, 'field' => $field, 'links' => $links, 'exclude_cat' => $field->field_options['exclude_cat']);
             foreach (array('show', 'truncate', 'sep') as $p) {
                 $post_args[$p] = $atts[$p];
                 unset($p);
             }
             $value = self::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], $post_args);
             unset($post_args);
         } else {
             $value = FrmEntryMeta::get_meta_value($entry, $field->id);
         }
     } else {
         $value = FrmEntryMeta::get_meta_value($entry, $field->id);
         if (('tag' == $field->type || isset($field->field_options['post_field']) && $field->field_options['post_field'] == 'post_category') && !empty($value)) {
             $value = maybe_unserialize($value);
             $new_value = array();
             foreach ((array) $value as $tax_id) {
                 if (is_numeric($tax_id)) {
                     $cat = get_term($tax_id, $field->field_options['taxonomy']);
                     $new_value[] = $cat ? $cat->name : $tax_id;
                     unset($cat);
                 } else {
                     $new_value[] = $tax_id;
                 }
             }
             $value = $new_value;
         }
     }
     return $value;
 }
コード例 #16
0
 /**
  * @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
     }
 }
コード例 #17
0
 function get_object_by_id($entry_id)
 {
     return FrmEntry::getOne($entry_id);
 }
コード例 #18
0
 public static function is_new_entry($entry)
 {
     FrmEntry::maybe_get_entry($entry);
     // this function will only be correct if the entry has already gone through FrmProEntriesController::check_draft_status
     return $entry->created_at == $entry->updated_at;
 }
コード例 #19
0
 /**
  * @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);
             }
         }
     }
 }
コード例 #20
0
 function _check_xml_updated_number_of_entries($args)
 {
     $parent_entries = FrmEntry::getAll(array('form_id' => $args['parent_form_id']));
     $this->assertEquals(count($args['parent_entries']), count($parent_entries), 'The number of entries in form ' . $args['parent_form_id'] . ' should be the same after an XML update.');
     $rep_sec_form_id = FrmForm::getIdByKey($this->repeat_sec_form_key);
     $child_entries = FrmEntry::getAll(array('form_id' => $rep_sec_form_id));
     $this->assertEquals(count($args['child_entries']), count($child_entries), 'The number of entries in form ' . $rep_sec_form_id . ' should be the same after an XML update.');
     $embed_form_id = FrmForm::getIdByKey($this->contact_form_key);
     $embedded_entries = FrmEntry::getAll(array('form_id' => $embed_form_id, 'parent_item_id !' => 0));
     $this->assertEquals(count($args['embedded_entries']), count($embedded_entries), 'The number of entries in the embedded form should be the same after an XML update.');
 }
コード例 #21
0
 /**
  * @covers FrmProFieldsHelper::move_entries_to_child_form
  */
 function _check_if_child_entries_created($args, $child_form_id)
 {
     global $wpdb;
     // Check for value in repeating section
     $rep_meta_values = $wpdb->get_col("SELECT meta_value FROM " . $wpdb->prefix . "frm_item_metas WHERE field_id=" . $args['field_id']);
     $this->assertNotEmpty($rep_meta_values, 'When switching from non-repeating to repeating, the repeating section frm_item_metas is not saving the IDs of the child entries.');
     // Check if entries were created in child form
     $child_items = FrmEntry::getAll(array('it.form_id' => $child_form_id));
     $parent_items = FrmEntry::getAll(array('it.form_id' => $args['parent_form_id']));
     $this->assertEquals(count($parent_items), count($child_items), 'When switching from non-repeating to repeating section, child entries are not created. ');
     // Check if entries in child form match IDs saved in repeating section frm_item_metas
     $child_ids = array_keys($child_items);
     $this->assertEquals($child_ids, $rep_meta_values, 'When switching from non-repeating to repeating, created entry IDs do not match IDs saved in repeating section field frm_item_metas.');
     // Check if the item_id for child field frm_item_metas was updated to match new child entry IDs
     $new_child_metas = FrmDb::get_col($wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_items it ON it.id=m.item_id', array('field_id' => $args['children']), 'm.item_id', array('order_by' => 'it.created_at ASC'));
     $new_child_metas = array_unique($new_child_metas);
     $this->assertEquals($child_ids, $new_child_metas, 'When switching from non-repeating to repeating, the item_id is not updated on frm_item_metas for child fields');
 }
コード例 #22
0
 public static function get_data_display_value($replace_with, $atts, $field)
 {
     //if ( is_numeric($replace_with) || is_array($replace_with) )
     if (!isset($field->field_options['form_select']) || $field->field_options['form_select'] == 'taxonomy') {
         return $replace_with;
     }
     $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
     $atts['show'] = isset($atts['show']) ? $atts['show'] : false;
     if (!empty($replace_with) && !is_array($replace_with)) {
         $replace_with = explode($sep, $replace_with);
     }
     $linked_ids = (array) $replace_with;
     $replace_with = array();
     if ($atts['show'] == 'id') {
         // keep the values the same since we already have the ids
         $replace_with = $linked_ids;
     } else {
         if (in_array($atts['show'], array('key', 'created-at', 'created_at', 'updated-at', 'updated_at, updated-by, updated_by', 'post_id'))) {
             $nice_show = str_replace('-', '_', $atts['show']);
             foreach ($linked_ids as $linked_id) {
                 $linked_entry = FrmEntry::getOne($linked_id);
                 if (isset($linked_entry->{$atts['show']})) {
                     $replace_with[] = $linked_entry->{$atts['show']};
                 } else {
                     if (isset($linked_entry->{$nice_show})) {
                         $replace_with[] = $linked_entry->{$nice_show};
                     } else {
                         $replace_with[] = $linked_entry->item_key;
                     }
                 }
             }
         } else {
             foreach ($linked_ids as $linked_id) {
                 $new_val = self::get_data_value($linked_id, $field, $atts);
                 if ($linked_id == $new_val) {
                     continue;
                 }
                 if (is_array($new_val)) {
                     $new_val = implode($sep, $new_val);
                 }
                 $replace_with[] = $new_val;
                 unset($new_val);
             }
         }
     }
     return implode($sep, $replace_with);
 }
コード例 #23
0
 private static function _delete_entry($entry_id, $form)
 {
     if (!$form) {
         return;
     }
     $form->options = maybe_unserialize($form->options);
     if (isset($form->options['no_save']) && $form->options['no_save']) {
         FrmEntry::destroy($entry_id);
     }
 }
コード例 #24
0
ファイル: FrmForm.php プロジェクト: mazykin46/portfolio
 /**
  * @return int|boolean
  */
 public static function destroy($id)
 {
     global $wpdb;
     $form = self::getOne($id);
     if (!$form) {
         return false;
     }
     // Disconnect the entries from this form
     $entries = FrmDb::get_col($wpdb->prefix . 'frm_items', array('form_id' => $id));
     foreach ($entries as $entry_id) {
         FrmEntry::destroy($entry_id);
         unset($entry_id);
     }
     // Disconnect the fields from this form
     $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));
     $query_results = $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'frm_forms WHERE id=%d OR parent_form_id=%d', $id, $id));
     if ($query_results) {
         // Delete all form actions linked to this form
         $action_control = FrmFormActionsController::get_form_actions('email');
         $action_control->destroy($id, 'all');
         // Clear form caching
         self::clear_form_cache();
         do_action('frm_destroy_form', $id);
         do_action('frm_destroy_form_' . $id);
     }
     return $query_results;
 }
コード例 #25
0
 /**
  * @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);
             }
         }
     }
 }
コード例 #26
0
 private static function get_entry_by_param(&$entry)
 {
     if (!$entry || !is_object($entry)) {
         if (!$entry || !is_numeric($entry)) {
             $entry = FrmAppHelper::get_post_param('id', false, 'sanitize_title');
         }
         FrmEntry::maybe_get_entry($entry);
     }
 }
コード例 #27
0
 function email_value($value, $meta, $entry)
 {
     global $frm_field;
     if ($entry->id != $meta->item_id) {
         $entry = FrmEntry::getOne($meta->item_id);
     }
     $field = $frm_field->getOne($meta->field_id);
     if (!$field) {
         return $value;
     }
     $field->field_options = maybe_unserialize($field->field_options);
     if (isset($field->field_options['post_field']) and $field->field_options['post_field']) {
         if ($entry->post_id) {
             $value = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('truncate' => false, 'form_id' => $entry->form_id, 'field' => $field, 'type' => $field->type, 'truncate' => true));
         } else {
             if ($meta->field_type == 'tag' or $field->field_options['post_field'] == 'post_category' and !empty($value)) {
                 $value = (array) $value;
                 $new_value = array();
                 foreach ($value as $tax_id) {
                     if (is_numeric($tax_id)) {
                         $cat = $term = get_term($tax_id, $field->field_options['taxonomy']);
                         $new_value[] = $cat ? $cat->name : $tax_id;
                         unset($cat);
                     } else {
                         $new_value[] = $tax_id;
                     }
                 }
                 $value = $new_value;
             }
         }
     }
     switch ($field->type) {
         case 'user_id':
             $value = FrmProFieldsHelper::get_display_name($value);
             break;
         case 'data':
             if (is_array($value)) {
                 $new_value = array();
                 foreach ($value as $val) {
                     $new_value[] = FrmProFieldsHelper::get_data_value($val, $field);
                 }
                 $value = $new_value;
             } else {
                 $value = FrmProFieldsHelper::get_data_value($value, $field);
             }
             break;
         case 'file':
             $value = FrmProFieldsHelper::get_file_name($value);
             break;
         case 'date':
             $value = FrmProFieldsHelper::get_date($value);
     }
     if (is_array($value)) {
         $new_value = '';
         foreach ($value as $val) {
             if (is_array($val)) {
                 $new_value .= implode(', ', $val) . "\n";
             }
         }
         if ($new_value != '') {
             $value = $new_value;
         }
     }
     return $value;
 }
コード例 #28
0
 function get_display_value($replace_with, $field, $atts = array())
 {
     $sep = isset($atts['sep']) ? $atts['sep'] : ', ';
     if ($field->type == 'user_id') {
         $user_info = isset($atts['show']) ? $atts['show'] : 'display_name';
         $replace_with = FrmProFieldsHelper::get_display_name($replace_with, $user_info, $atts);
         if (is_array($replace_with)) {
             $new_val = '';
             foreach ($replace_with as $key => $val) {
                 if (!empty($new_val)) {
                     $new_val .= ', ';
                 }
                 $new_val .= $key . '. ' . $val;
             }
             $replace_with = $new_val;
         }
     } else {
         if ($field->type == 'date') {
             if (isset($atts['time_ago'])) {
                 $atts['format'] = 'Y-m-d H:i:s';
             }
             if (!isset($atts['format'])) {
                 $atts['format'] = false;
             }
             $replace_with = FrmProFieldsHelper::get_date($replace_with, $atts['format']);
             if (isset($atts['time_ago'])) {
                 $replace_with = FrmProAppHelper::human_time_diff(strtotime($replace_with), strtotime(date_i18n('Y-m-d')));
             }
         } else {
             if (is_numeric($replace_with) and $field->type == 'file') {
                 //size options are thumbnail, medium, large, or full
                 $size = isset($atts['size']) ? $atts['size'] : 'thumbnail';
                 if ($size != 'id') {
                     $replace_with = FrmProFieldsHelper::get_media_from_id($replace_with, $size);
                 }
             } else {
                 if ($field->type == 'data') {
                     //and (is_numeric($replace_with) or is_array($replace_with))
                     $field->field_options = maybe_unserialize($field->field_options);
                     if (isset($field->field_options['form_select']) and $field->field_options['form_select'] == 'taxonomy') {
                         return $replace_with;
                     }
                     $replace_with = explode($sep, $replace_with);
                     if (isset($atts['show'])) {
                         if (in_array($atts['show'], array('key', 'created-at', 'created_at', 'updated-at', 'updated_at', 'post_id'))) {
                             global $frm_entry;
                             if (is_array($replace_with)) {
                                 $linked_ids = $replace_with;
                                 $replace_with = '';
                                 foreach ($linked_ids as $linked_id) {
                                     $linked_entry = FrmEntry::getOne($linked_id);
                                     if (!empty($replace_with)) {
                                         $replace_with .= $sep;
                                     }
                                     if ($atts['show'] == 'created-at') {
                                         $replace_with .= $linked_entry->created_at;
                                     } else {
                                         if ($atts['show'] == 'updated-at') {
                                             $replace_with .= $linked_entry->updated_at;
                                         } else {
                                             if ($atts['show'] == 'key') {
                                                 $replace_with .= $linked_entry->item_key;
                                             } else {
                                                 $replace_with .= isset($linked_entry->{$atts['show']}) ? $linked_entry->{$atts['show']} : $linked_entry->item_key;
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 $linked_entry = FrmEntry::getOne($replace_with);
                                 if ($atts['show'] == 'created-at') {
                                     $replace_with = $linked_entry->created_at;
                                 } else {
                                     if ($atts['show'] == 'updated-at') {
                                         $replace_with = $linked_entry->updated_at;
                                     } else {
                                         if ($atts['show'] == 'key') {
                                             $replace_with = $linked_entry->item_key;
                                         } else {
                                             $replace_with = isset($linked_entry->{$atts['show']}) ? $linked_entry->{$atts['show']} : $linked_entry->item_key;
                                         }
                                     }
                                 }
                             }
                         } else {
                             if ($atts['show'] == 'id') {
                                 if (is_array($replace_with)) {
                                     $replace_with = implode($sep, $replace_with);
                                 }
                                 //just keep the value since it's already the id
                             } else {
                                 if (is_array($replace_with)) {
                                     $linked_ids = $replace_with;
                                     $replace_with = array();
                                     foreach ($linked_ids as $linked_id) {
                                         $new_val = FrmProFieldsHelper::get_data_value($linked_id, $field, $atts);
                                         if ($linked_id != $new_val) {
                                             $replace_with[] = $new_val;
                                         }
                                         unset($new_val);
                                     }
                                     $replace_with = implode($sep, $replace_with);
                                 } else {
                                     $replace_with = FrmProFieldsHelper::get_data_value($replace_with, $field, $atts);
                                 }
                             }
                         }
                     } else {
                         if (is_array($replace_with)) {
                             $linked_ids = $replace_with;
                             $replace_with = array();
                             foreach ($linked_ids as $linked_id) {
                                 $new_val = FrmProFieldsHelper::get_data_value($linked_id, $field, $atts);
                                 if ($linked_id != $new_val) {
                                     $replace_with[] = $new_val;
                                 }
                                 unset($new_val);
                             }
                             $replace_with = implode($sep, $replace_with);
                         } else {
                             $replace_with = FrmProFieldsHelper::get_data_value($replace_with, $field, $atts);
                         }
                     }
                 } else {
                     if ($field->type == 'textarea') {
                         $autop = isset($atts['wpautop']) ? $atts['wpautop'] : true;
                         if (apply_filters('frm_use_wpautop', $autop)) {
                             $replace_with = wpautop($replace_with);
                         }
                         unset($autop);
                     } else {
                         if ($field->type == 'number') {
                             if (!isset($atts['decimal'])) {
                                 $num = explode('.', $replace_with);
                                 $atts['decimal'] = isset($num[1]) ? strlen($num[1]) : 0;
                             }
                             if (!isset($atts['dec_point'])) {
                                 $atts['dec_point'] = '.';
                             }
                             if (!isset($atts['thousands_sep'])) {
                                 $atts['thousands_sep'] = '';
                             }
                             $replace_with = number_format($replace_with, $atts['decimal'], $atts['dec_point'], $atts['thousands_sep']);
                         }
                     }
                 }
             }
         }
     }
     $replace_with = stripslashes_deep($replace_with);
     return $replace_with;
 }
コード例 #29
0
 public static function prepare_display_value($entry, $field, $atts)
 {
     $field_value = isset($entry->metas[$field->id]) ? $entry->metas[$field->id] : false;
     if (FrmAppHelper::pro_is_installed()) {
         FrmProEntriesHelper::get_dynamic_list_values($field, $entry, $field_value);
     }
     if ($field->form_id == $entry->form_id || empty($atts['embedded_field_id'])) {
         return self::display_value($field_value, $field, $atts);
     }
     // this is an embeded form
     $val = '';
     if (strpos($atts['embedded_field_id'], 'form') === 0) {
         //this is a repeating section
         $child_entries = FrmEntry::getAll(array('it.parent_item_id' => $entry->id));
     } else {
         // get all values for this field
         $child_values = isset($entry->metas[$atts['embedded_field_id']]) ? $entry->metas[$atts['embedded_field_id']] : false;
         if ($child_values) {
             $child_entries = FrmEntry::getAll(array('it.id' => (array) $child_values));
         }
     }
     $field_value = array();
     if (!isset($child_entries) || !$child_entries || !FrmAppHelper::pro_is_installed()) {
         return $val;
     }
     foreach ($child_entries as $child_entry) {
         $atts['item_id'] = $child_entry->id;
         $atts['post_id'] = $child_entry->post_id;
         // get the value for this field -- check for post values as well
         $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field);
         if ($entry_val) {
             // foreach entry get display_value
             $field_value[] = self::display_value($entry_val, $field, $atts);
         }
         unset($child_entry);
     }
     $val = implode(', ', (array) $field_value);
     $val = wp_kses_post($val);
     return $val;
 }
コード例 #30
0
 public static function maybe_delete_entry($entry)
 {
     FrmEntry::maybe_get_entry($entry);
     if (!$entry || !FrmProEntriesHelper::user_can_delete($entry)) {
         $message = __('There was an error deleting that entry', 'formidable');
         return $message;
     }
     $result = FrmEntry::destroy($entry->id);
     return $result;
 }