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']; }
function _set_up_field_object($test, &$expected_cats, $key) { // Parent categories $args = array('hide_empty' => false, 'taxonomy' => 'category', 'parent' => 0); $parent_cats = get_categories($args); // Get the correct parent ID(s) for the current test $parent_cat_id = self::_get_parent_cat_id($test, $parent_cats, $expected_cats); $this->assertNotFalse($parent_cat_id, 'Check if there are at least two parent categories with children and two with no children. Needed for the ' . $test . ' test.'); // Child field $field_id = $this->factory->field->get_id_by_key('child-dynamic-taxonomy'); $field = FrmField::getOne($field_id); $field->field_options['hide_opt'][$key] = $parent_cat_id; return $field; }
function test_stats_shortcode() { $forms_to_test = array($this->all_fields_form_key => array('493ito', 'p3eiuk', 'uc580i', '4t3qo4', '54tffk', 'endbcl', 'repeating-text')); foreach ($forms_to_test as $form_key => $fields) { foreach ($fields as $field_key) { $field = FrmField::getOne($field_key); $value = do_shortcode('[frm-stats id=' . $field->id . ' type=count]'); $this->assertNotEmpty($value, 'Field ' . $field_key . ' has no saved values'); if (!empty($field->options)) { $first_option = array_filter($field->options); $first_option = reset($first_option); $filter_by_value = do_shortcode('[frm-stats id=' . $field->id . ' type=count value="' . $first_option . '"]'); $this->assertNotEmpty($filter_by_value, 'Field ' . $field_key . ' has no saved values for "' . $first_option . '"'); } } } }
/** * @covers FrmFieldsController::create */ public function test_create() { wp_set_current_user($this->user_id); $this->assertTrue(is_numeric($this->form_id)); $_POST = array('action' => 'frm_insert_field', 'nonce' => wp_create_nonce('frm_ajax'), 'form_id' => $this->form_id, 'field' => 'text'); try { $this->_handleAjax('frm_insert_field'); } catch (WPAjaxDieContinueException $e) { unset($e); } global $wpdb; $this->field_id = $wpdb->insert_id; $this->assertTrue(is_numeric($this->field_id)); $this->assertNotEmpty($this->field_id); // make sure the field exists $field = FrmField::getOne($this->field_id); $this->assertTrue(is_object($field)); }
public static function update_entry_metas($entry_id, $values) { global $wpdb; $prev_values = FrmDb::get_col($wpdb->prefix . 'frm_item_metas', array('item_id' => $entry_id, 'field_id !' => 0), 'field_id'); foreach ($values as $field_id => $meta_value) { $field = false; if (!empty($field_id)) { $field = FrmField::getOne($field_id); } // set the value for the file upload field and add new tags (in Pro version) $meta_value = apply_filters('frm_prepare_data_before_db', $meta_value, $field_id, $entry_id, compact('field')); if ($prev_values && in_array($field_id, $prev_values)) { if (is_array($meta_value) && empty($meta_value) || !is_array($meta_value) && trim($meta_value) == '') { // remove blank fields unset($values[$field_id]); } else { // if value exists, then update it self::update_entry_meta($entry_id, $field_id, '', $meta_value); } } else { // if value does not exist, then create it self::add_entry_meta($entry_id, $field_id, '', $meta_value); } } if (empty($prev_values)) { return; } $prev_values = array_diff($prev_values, array_keys($values)); if (empty($prev_values)) { return; } // prepare the query $where = array('item_id' => $entry_id, 'field_id' => $prev_values); FrmDb::get_where_clause_and_values($where); // Delete any leftovers $wpdb->query($wpdb->prepare('DELETE FROM ' . $wpdb->prefix . 'frm_item_metas ' . $where['where'], $where['values'])); self::clear_cache(); }
function _get_the_join_field(&$args) { $linked_field = FrmField::getOne($args['field']->field_options['form_select']); $join_fields = FrmField::get_all_types_in_form($linked_field->form_id, 'data'); foreach ($join_fields as $j) { if ($j->field_options['form_select'] == $args['parent_field']->field_options['form_select']) { $args['join_field'] = $j; break; } } }
public static function replace_content_shortcodes($content, $entry, $shortcodes) { $shortcode_values = array('id' => $entry->id, 'key' => $entry->item_key, 'ip' => $entry->ip); foreach ($shortcodes[0] as $short_key => $tag) { $atts = shortcode_parse_atts($shortcodes[3][$short_key]); if (!empty($shortcodes[3][$short_key])) { $tag = str_replace(array('[', ']'), '', $shortcodes[0][$short_key]); $tags = explode(' ', $tag); if (is_array($tags)) { $tag = $tags[0]; } } else { $tag = $shortcodes[2][$short_key]; } switch ($tag) { case 'id': case 'key': case 'ip': $replace_with = $shortcode_values[$tag]; break; case 'user_agent': case 'user-agent': $entry->description = maybe_unserialize($entry->description); $replace_with = FrmEntryFormat::get_browser($entry->description['browser']); break; case 'created_at': case 'created-at': case 'updated_at': case 'updated-at': if (isset($atts['format'])) { $time_format = ' '; } else { $atts['format'] = get_option('date_format'); $time_format = ''; } $this_tag = str_replace('-', '_', $tag); $replace_with = FrmAppHelper::get_formatted_time($entry->{$this_tag}, $atts['format'], $time_format); unset($this_tag); break; case 'created_by': case 'created-by': case 'updated_by': case 'updated-by': $this_tag = str_replace('-', '_', $tag); $replace_with = self::get_display_value($entry->{$this_tag}, (object) array('type' => 'user_id'), $atts); unset($this_tag); break; case 'admin_email': case 'siteurl': case 'frmurl': case 'sitename': case 'get': $replace_with = self::dynamic_default_values($tag, $atts); break; default: $field = FrmField::getOne($tag); if (!$field) { break; } $sep = isset($atts['sep']) ? $atts['sep'] : ', '; $replace_with = FrmEntryMeta::get_meta_value($entry, $field->id); $atts['entry_id'] = $entry->id; $atts['entry_key'] = $entry->item_key; //$replace_with = apply_filters('frmpro_fields_replace_shortcodes', $replace_with, $tag, $atts, $field); if (is_array($replace_with)) { $replace_with = implode($sep, $replace_with); } if (isset($atts['show']) && $atts['show'] == 'field_label') { $replace_with = $field->name; } else { if (isset($atts['show']) && $atts['show'] == 'description') { $replace_with = $field->description; } else { if (empty($replace_with) && $replace_with != '0') { $replace_with = ''; } else { $replace_with = self::get_display_value($replace_with, $field, $atts); } } } unset($field); break; } if (isset($replace_with)) { $content = str_replace($shortcodes[0][$short_key], $replace_with, $content); } unset($atts, $conditional, $replace_with); } return $content; }
public static function import_options() { check_ajax_referer('frm_ajax', 'nonce'); if (!is_admin() || !current_user_can('frm_edit_forms')) { return; } $field_id = absint($_POST['field_id']); $field = FrmField::getOne($field_id); if (!in_array($field->type, array('radio', 'checkbox', 'select'))) { return; } $field = FrmFieldsHelper::setup_edit_vars($field); $opts = stripslashes_deep($_POST['opts']); $opts = explode("\n", rtrim($opts, "\n")); if ($field['separate_value']) { foreach ($opts as $opt_key => $opt) { if (strpos($opt, '|') !== false) { $vals = explode('|', $opt); if ($vals[0] != $vals[1]) { $opts[$opt_key] = array('label' => trim($vals[0]), 'value' => trim($vals[1])); } unset($vals); } unset($opt_key, $opt); } } //Keep other options after bulk update if (isset($field['field_options']['other']) && $field['field_options']['other'] == true) { $other_array = array(); foreach ($field['options'] as $opt_key => $opt) { if ($opt_key && strpos($opt_key, 'other') !== false) { $other_array[$opt_key] = $opt; } unset($opt_key, $opt); } if (!empty($other_array)) { $opts = array_merge($opts, $other_array); } } FrmField::update($field_id, array('options' => maybe_serialize($opts))); $field['options'] = $opts; $field_name = $field['name']; // Get html_id which will be used in single-option.php $html_id = FrmFieldsHelper::get_html_id($field); if ($field['type'] == 'radio' || $field['type'] == 'checkbox') { require FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php'; } else { FrmFieldsHelper::show_single_option($field); } wp_die(); }
<option value="not LIKE" <?php selected($condition['hide_field_cond'], 'not LIKE'); ?> ><?php _e('not like', 'formidable'); ?> </option> </select> <span id="frm_show_selected_values_<?php echo esc_attr($key . '_' . $meta_name); ?> "> <?php if ($condition['hide_field'] && is_numeric($condition['hide_field'])) { $new_field = FrmField::getOne($condition['hide_field']); } $val = isset($condition['hide_opt']) ? $condition['hide_opt'] : ''; if (!isset($field)) { $field = array('hide_opt' => array($meta_name => $val)); } $field_name = $names['hide_opt']; require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/field-values.php'; ?> </span> <a href="javascript:void(0)" class="frm_remove_tag frm_icon_font" data-removeid="<?php echo esc_attr($id); ?> " <?php echo !empty($showlast) ? 'data-showlast="' . esc_attr($showlast) . '"' : ''; ?>
/** * @covers update_for_repeat */ function _check_repeat_options_updated($repeating_section, $expected_repeat, $expected_form_select, $msg) { $new_repeat = FrmField::getOne($repeating_section->id); // Check repeat option $this->assertEquals($expected_repeat, $new_repeat->field_options['repeat'], 'The repeat option is not updated when a divider is switched to ' . $msg); // Check form_select $this->assertEmpty($expected_form_select, $new_repeat->field_options['form_select'], 'Form_select not updated when divider is switched to ' . $msg); }
public static function &filter_email_value($value, $meta, $entry, $atts = array()) { $frm_field = new FrmField(); $field = $frm_field->getOne($meta->field_id); if (!$field) { return $value; } $value = self::filter_display_value($value, $field, $atts); return $value; }
function _get_xml_update_args() { $repeating_section_id = FrmField::get_id_by_key('repeating-section'); $repeating_section_values = self::_get_repeating_section_values($repeating_section_id); $repeating_section = FrmField::getOne($repeating_section_id); $repeating_fields = FrmField::get_all_for_form($repeating_section->field_options['form_select']); $parent_form_id = FrmForm::getIdByKey($this->all_fields_form_key); $parent_entries = FrmEntry::getAll(array('form_id' => $parent_form_id)); $child_entries = FrmEntry::getAll(array('form_id' => $repeating_section->field_options['form_select'])); $embed_form_id = FrmForm::getIdByKey($this->contact_form_key); $embedded_entries = FrmEntry::getAll(array('form_id' => $embed_form_id, 'parent_item_id !' => 0)); $args = array('repeating_section' => $repeating_section, 'repeating_section_values' => $repeating_section_values, 'repeating_fields' => $repeating_fields, 'parent_form_id' => $parent_form_id, 'parent_entries' => $parent_entries, 'child_entries' => $child_entries, 'embedded_entries' => $embedded_entries); return $args; }
/** * Get the value from a specific field and entry * * @since 2.01.02 * @param object $entry * @param int $field_id * @return array|bool|mixed|string */ private static function get_value_from_entry($entry, $field_id) { $observed_value = ''; if (isset($entry->metas[$field_id])) { $observed_value = $entry->metas[$field_id]; } else { if ($entry->post_id && FrmAppHelper::pro_is_installed()) { $field = FrmField::getOne($field_id); $observed_value = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, array('links' => false, 'truncate' => false)); } } return $observed_value; }
public static function field_on_current_page($field) { global $frm_vars; $current = true; $prev = 0; $next = 9999; if (!is_object($field)) { $field = FrmField::getOne($field); } if ($frm_vars['prev_page'] && is_array($frm_vars['prev_page']) && isset($frm_vars['prev_page'][$field->form_id])) { $prev = $frm_vars['prev_page'][$field->form_id]; } if ($frm_vars['next_page'] && is_array($frm_vars['next_page']) && isset($frm_vars['next_page'][$field->form_id])) { $next = $frm_vars['next_page'][$field->form_id]; if (is_object($next)) { $next = $next->field_order; } } if ($field->field_order < $prev || $field->field_order > $next) { $current = false; } $current = apply_filters('frm_show_field_on_page', $current, $field); return $current; }
/** * @return array */ public static function update_fields($id, $values) { if (!isset($values['options']) && !isset($values['item_meta']) && !isset($values['field_options'])) { return $values; } $all_fields = FrmField::get_all_for_form($id); if (empty($all_fields)) { return $values; } if (!isset($values['item_meta'])) { $values['item_meta'] = array(); } $field_array = array(); $existing_keys = array_keys($values['item_meta']); foreach ($all_fields as $fid) { if (!in_array($fid->id, $existing_keys) && (isset($values['frm_fields_submitted']) && in_array($fid->id, $values['frm_fields_submitted'])) || isset($values['options'])) { $values['item_meta'][$fid->id] = ''; } $field_array[$fid->id] = $fid; } unset($all_fields); foreach ($values['item_meta'] as $field_id => $default_value) { if (isset($field_array[$field_id])) { $field = $field_array[$field_id]; } else { $field = FrmField::getOne($field_id); } if (!$field) { continue; } if (isset($values['options']) || isset($values['field_options']['custom_html_' . $field_id])) { //updating the settings page if (isset($values['field_options']['custom_html_' . $field_id])) { $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)); $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); FrmField::update($field_id, array('field_options' => $field->field_options)); } else { if ($field->type == 'hidden' || $field->type == 'user_id') { $prev_opts = $field->field_options; $field->field_options = apply_filters('frm_update_form_field_options', $field->field_options, $field, $values); if ($prev_opts != $field->field_options) { FrmField::update($field_id, array('field_options' => $field->field_options)); } unset($prev_opts); } } } if ((isset($values['options']) || isset($values['field_options']['custom_html_' . $field_id])) && !defined('WP_IMPORTING')) { continue; } //updating the form foreach (array('size', 'max', 'label', 'invalid', 'blank', 'classes', 'captcha_size') as $opt) { $field->field_options[$opt] = isset($values['field_options'][$opt . '_' . $field_id]) ? trim($values['field_options'][$opt . '_' . $field_id]) : ''; } $field->field_options['required_indicator'] = isset($values['field_options']['required_indicator_' . $field_id]) ? trim($values['field_options']['required_indicator_' . $field_id]) : '*'; $field->field_options['separate_value'] = isset($values['field_options']['separate_value_' . $field_id]) ? trim($values['field_options']['separate_value_' . $field_id]) : 0; $field->field_options = apply_filters('frm_update_field_options', $field->field_options, $field, $values); $default_value = maybe_serialize($values['item_meta'][$field_id]); $field_key = isset($values['field_options']['field_key_' . $field_id]) ? $values['field_options']['field_key_' . $field_id] : $field->field_key; $required = isset($values['field_options']['required_' . $field_id]) ? $values['field_options']['required_' . $field_id] : false; $field_type = isset($values['field_options']['type_' . $field_id]) ? $values['field_options']['type_' . $field_id] : $field->type; $field_description = isset($values['field_options']['description_' . $field_id]) ? $values['field_options']['description_' . $field_id] : $field->description; FrmField::update($field_id, array('field_key' => $field_key, 'type' => $field_type, 'default_value' => $default_value, 'field_options' => $field->field_options, 'description' => $field_description, 'required' => $required)); FrmField::delete_form_transient($field->form_id); } return $values; }
public static function get_field_value_shortcode($sc_atts) { $atts = shortcode_atts(array('entry' => false, 'field_id' => false, 'user_id' => false, 'ip' => false, 'show' => '', 'format' => '', 'return_array' => false, 'default' => ''), $sc_atts); // Include all user-defined atts as well $atts = (array) $atts + (array) $sc_atts; // For reverse compatibility if (isset($atts['entry_id']) && !$atts['entry']) { $atts['entry'] = $atts['entry_id']; } if (!$atts['field_id']) { return __('You are missing options in your shortcode. field_id is required.', 'formidable'); } $field = FrmField::getOne($atts['field_id']); if (!$field) { return $atts['default']; } $entry = self::get_frm_field_value_entry($field, $atts); if (!$entry) { return $atts['default']; } $value = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, $atts); $atts['type'] = $field->type; $atts['post_id'] = $entry->post_id; $atts['entry_id'] = $entry->id; if (!isset($atts['show_filename'])) { $atts['show_filename'] = false; } if ($field->type == 'file' && !isset($atts['html'])) { // default to show the image instead of the url $atts['html'] = 1; } if (!empty($atts['format']) || isset($atts['show']) && !empty($atts['show'])) { $value = FrmFieldsHelper::get_display_value($value, $field, $atts); } else { $value = FrmEntriesHelper::display_value($value, $field, $atts); } return $value; }
public static function get_field_matches($args) { extract($args); $f = $orig_f; $where_is = '='; //If using <, >, or != and $f is NOT a field ID if ($f < 20 and !is_numeric($val)) { // >, <, <=, >= TODO: %, !% $orig_val = $val; $lpos = strpos($val, '<'); $gpos = strpos($val, '>'); $not_pos = strpos($val, '!='); if ($not_pos !== false) { //If string contains != $where_is = '!='; $str = explode($where_is, $orig_val); $f = $str[0]; $val = $str[1]; if (empty($entry_ids) && $after_where == 0) { //If entry IDs have not been set by a previous $atts global $wpdb; $query = $wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $field->form_id); //By default, don't get drafts if ($drafts != 'both') { $query .= $wpdb->prepare(" AND is_draft=%d", $drafts); } $entry_ids = $wpdb->get_col($query); unset($query); } $val = FrmAppHelper::replace_quotes($val); $val = trim(trim($val, "'"), '"'); } else { if ($lpos !== false || $gpos !== false) { //If string contains greater than or less than $where_is = ($gpos !== false and $lpos !== false and $lpos > $gpos or $lpos === false) ? '>' : '<'; $str = explode($where_is, $orig_val); if (count($str) == 2) { $f = $str[0]; $val = $str[1]; } else { if (count($str) == 3) { //3 parts assumes a structure like '-1 month'<255<'1 month' $val = str_replace($str[0] . $where_is, '', $orig_val); $entry_ids = self::get_field_matches(compact('entry_ids', 'orig_f', 'val', 'id', 'atts', 'field', 'form_posts', 'after_where', 'drafts')); $after_where = true; $f = $str[1]; $val = $str[0]; $where_is = $where_is == '<' ? '>' : '<'; } } if (strpos($val, '=') === 0) { $where_is .= '='; $val = substr($val, 1); } $val = FrmAppHelper::replace_quotes($val); $val = trim(trim($val, "'"), '"'); } } } if (!is_numeric($f)) { if (in_array($f, array('created_at', 'updated_at'))) { global $wpdb; $query = $wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_items WHERE {$f} {$where_is} %s AND form_id = %d", $val, $field->form_id); if ($after_where) { if (!$entry_ids) { return array(); } $query .= ' AND id in (' . implode(',', $entry_ids) . ')'; } $entry_ids = $wpdb->get_col($query); return $entry_ids; } else { //check for field keys $frm_field = new FrmField(); $this_field = $frm_field->getOne($f); if ($this_field) { $f = $this_field->id; } else { //If no field ID return $entry_ids; } unset($this_field); } } unset($orig_f); $where_atts = apply_filters('frm_stats_where', array('where_is' => $where_is, 'where_val' => $val), array('id' => $id, 'atts' => $atts)); $val = $where_atts['where_val']; $where_is = $where_atts['where_is']; unset($where_atts); $entry_ids = FrmProAppHelper::filter_where($entry_ids, array('where_opt' => $f, 'where_is' => $where_is, 'where_val' => $val, 'form_id' => $field->form_id, 'form_posts' => $form_posts, 'after_where' => $after_where, 'drafts' => $drafts)); unset($f); unset($val); return $entry_ids; }
function import_choices($field_id) { if (!current_user_can('frm_edit_forms')) { return; } global $frm_ajax_url; if (function_exists('register_admin_color_schemes')) { register_admin_color_schemes(); } $hook_suffix = $admin_body_class = ''; if (get_user_setting('mfold') == 'f') { $admin_body_class .= ' folded'; } if (function_exists('is_admin_bar_showing') and is_admin_bar_showing()) { $admin_body_class .= ' admin-bar'; } if (is_rtl()) { $admin_body_class .= ' rtl'; } $admin_body_class .= ' admin-color-' . sanitize_html_class(get_user_option('admin_color'), 'fresh'); $prepop = array(); $prepop[__('Countries', 'formidable')] = FrmAppHelper::get_countries(); $states = FrmAppHelper::get_us_states(); $prepop[__('U.S. States', 'formidable')] = array_values($states); $prepop[__('U.S. State Abbreviations', 'formidable')] = array_keys($states); $prepop[__('Age', 'formidable')] = array(__('Under 18', 'formidable'), __('18-24', 'formidable'), __('25-34', 'formidable'), __('35-44', 'formidable'), __('45-54', 'formidable'), __('55-64', 'formidable'), __('65 or Above', 'formidable'), __('Prefer Not to Answer', 'formidable')); $prepop[__('Satisfaction', 'formidable')] = array(__('Very Satisfied', 'formidable'), __('Satisfied', 'formidable'), __('Neutral', 'formidable'), __('Unsatisfied', 'formidable'), __('Very Unsatisfied', 'formidable'), __('N/A', 'formidable')); $prepop[__('Importance', 'formidable')] = array(__('Very Important', 'formidable'), __('Important', 'formidable'), __('Neutral', 'formidable'), __('Somewhat Important', 'formidable'), __('Not at all Important', 'formidable'), __('N/A', 'formidable')); $prepop[__('Agreement', 'formidable')] = array(__('Strongly Agree', 'formidable'), __('Agree', 'formidable'), __('Neutral', 'formidable'), __('Disagree', 'formidable'), __('Strongly Disagree', 'formidable'), __('N/A', 'formidable')); $field = FrmField::getOne($field_id); $field->options = stripslashes_deep(maybe_unserialize($field->options)); $field->field_options = maybe_unserialize($field->field_options); include FRM_VIEWS_PATH . '/frm-fields/import_choices.php'; die; }
function build_calendar($new_content, $entries, $shortcodes, $display, $show = 'one') { if (!$display or $display->show_count != 'calendar') { return $new_content; } global $frm_entry_meta, $wp_locale; $display_options = maybe_unserialize($display->options); $current_year = date_i18n('Y'); $current_month = date_i18n('n'); $year = FrmAppHelper::get_param('frmcal-year', date('Y')); //4 digit year $month = FrmAppHelper::get_param('frmcal-month', $current_month); //Numeric month without leading zeros $timestamp = mktime(0, 0, 0, $month, 1, $year); $maxday = date('t', $timestamp); //Number of days in the given month $this_month = getdate($timestamp); $startday = $this_month['wday']; if ($current_year == $year and $current_month == $month) { $today = date_i18n('j'); } $cal_end = $maxday + $startday; $t = $cal_end > 35 ? 42 : ($cal_end == 28 ? 28 : 35); $extrarows = $t - $maxday - $startday; $show_entres = false; $daily_entries = array(); if (isset($display_options['date_field_id']) and is_numeric($display_options['date_field_id'])) { $field = FrmField::getOne($display_options['date_field_id']); } if (isset($display_options['edate_field_id']) and is_numeric($display_options['edate_field_id'])) { $efield = FrmField::getOne($display_options['edate_field_id']); } else { $efield = false; } foreach ($entries as $entry) { if (isset($display_options['date_field_id']) and is_numeric($display_options['date_field_id'])) { if (isset($entry->metas)) { $date = isset($entry->metas[$display_options['date_field_id']]) ? $entry->metas[$display_options['date_field_id']] : false; } else { $date = $frm_entry_meta->get_entry_meta_by_field($entry->id, $display_options['date_field_id']); } if ($entry->post_id and !$date) { if ($field) { $field->field_options = maybe_unserialize($field->field_options); if ($field->field_options['post_field']) { $date = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('form_id' => $display->form_id, 'type' => $field->type, 'field' => $field)); } } } } else { if ($display_options['date_field_id'] == 'updated_at') { $date = $entry->updated_at; $i18n = true; } else { $date = $entry->created_at; $i18n = true; } } if (empty($date)) { continue; } if (isset($il8n) and $il8n) { $date = date_i18n('Y-m-d', strtotime($date)); } else { $date = date('Y-m-d', strtotime($date)); } unset($i18n); $dates = array($date); if (isset($display_options['edate_field_id']) and !empty($display_options['edate_field_id'])) { if (is_numeric($display_options['edate_field_id']) and $efield) { $edate = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $efield); if ($efield and $efield->type == 'number' and is_numeric($edate)) { $edate = date('Y-m-d', strtotime('+' . $edate . ' days', strtotime($date))); } } else { if ($display_options['edate_field_id'] == 'updated_at') { $edate = date_i18n('Y-m-d', strtotime($entry->updated_at)); } else { $edate = date_i18n('Y-m-d', strtotime($entry->created_at)); } } if ($edate and !empty($edate)) { $from_date = strtotime($date); $to_date = strtotime($edate); if (!empty($from_date) and $from_date < $to_date) { for ($current_ts = $from_date; $current_ts <= $to_date; $current_ts += 60 * 60 * 24) { $dates[] = date('Y-m-d', $current_ts); } unset($current_ts); } unset($from_date); unset($to_date); } unset($edate); $used_entries = array(); } unset($date); $dates = apply_filters('frm_show_entry_dates', $dates, $entry); for ($i = 0; $i < $maxday + $startday; $i++) { $day = $i - $startday + 1; if (in_array(date('Y-m-d', strtotime("{$year}-{$month}-{$day}")), $dates)) { $show_entres = true; $daily_entres[$i][] = $entry; } unset($day); } unset($dates); } $day_names = $wp_locale->weekday_abbrev; $day_names = FrmProAppHelper::reset_keys($day_names); //switch keys to order ob_start(); include FRMPRO_VIEWS_PATH . '/displays/calendar.php'; $content = ob_get_contents(); ob_end_clean(); return $content; }
function check_data_values($values) { $check = true; if (!empty($values['hide_field']) and (!empty($values['hide_opt']) or !empty($values['form_select']))) { foreach ($values['hide_field'] as $hkey => $f) { if (!$check or !empty($values['hide_opt'][$hkey])) { continue; } $f = FrmField::getOne($f); if ($f and $f->type == 'data') { $check = false; } unset($f); unset($hkey); } } return $check; }
function import_csv($path, $form_id, $field_ids, $entry_key = 0, $start_row = 2, $del = ',') { global $importing_fields, $wpdb; if (!defined('WP_IMPORTING')) { define('WP_IMPORTING', true); } $form_id = (int) $form_id; if (!$form_id) { return $start_row; } if (!$importing_fields) { $importing_fields = array(); } if (!ini_get('safe_mode')) { set_time_limit(0); } //Remove time limit to execute this function if ($f = fopen($path, "r")) { unset($path); global $frm_entry, $frmdb; $row = 0; //setlocale(LC_ALL, 'ja_JP.UTF8'); while (($data = fgetcsv($f, 100000, $del)) !== FALSE) { $row++; if ($start_row > $row) { continue; } $values = array('form_id' => $form_id); $values['item_meta'] = array(); foreach ($field_ids as $key => $field_id) { $data[$key] = isset($data[$key]) ? $data[$key] : ''; //if($data[$key] == ''){ // error_log($row .' key:'. $key .' $data[$key] empty'); // return $row-1; //} if (is_numeric($field_id)) { if (isset($importing_fields[$field_id])) { $field = $importing_fields[$field_id]; } else { $field = FrmField::getOne($field_id); $importing_fields[$field_id] = $field; } $values['item_meta'][$field_id] = $data[$key]; if ($field->type == 'user_id') { if (!is_numeric($values['item_meta'][$field_id])) { if (!isset($user_array)) { $users = $wpdb->get_results("SELECT ID, user_login, display_name FROM {$wpdb->users} ORDER BY display_name ASC"); $user_array = array(); foreach ($users as $user) { $ukey = !empty($user->display_name) ? $user->display_name : $user->user_login; $user_array[$ukey] = $user->ID; unset($ukey); unset($user); } } if (isset($user_array[$values['item_meta'][$field_id]])) { $values['item_meta'][$field_id] = (int) $user_array[$values['item_meta'][$field_id]]; } } $values['user_id'] = $values['item_meta'][$field_id]; } else { if ($field->type == 'checkbox' and !empty($values['item_meta'][$field_id])) { if (!in_array($values['item_meta'][$field_id], (array) $field->options)) { $checked = maybe_unserialize($values['item_meta'][$field_id]); if (!is_array($checked)) { $checked = explode(',', $checked); } if ($checked and count($checked) > 1) { $values['item_meta'][$field_id] = array_map('trim', $checked); } } } } $_POST['item_meta'][$field_id] = $values['item_meta'][$field_id]; FrmProEntryMeta::set_post_fields($field, $values['item_meta'][$field_id]); unset($field); } else { if (is_array($field_id)) { $field_type = isset($field_id['type']) ? $field_id['type'] : false; $linked = isset($field_id['linked']) ? $field_id['linked'] : false; $field_id = $field_id['field_id']; if ($field_type == 'data') { if ($linked) { $entry_id = $frmdb->get_var($frmdb->entry_metas, array('meta_value' => $data[$key], 'field_id' => $linked), 'item_id'); } else { //get entry id of entry with item_key == $data[$key] $entry_id = $frmdb->get_var($frmdb->entries, array('item_key' => $data[$key])); } if ($entry_id) { $values['item_meta'][$field_id] = $entry_id; } } unset($field_type); unset($linked); } else { $values[$field_id] = $data[$key]; } } } if (!isset($values['item_key']) or empty($values['item_key'])) { $values['item_key'] = $data[$entry_key]; } if (isset($values['created_at'])) { $values['created_at'] = date('Y-m-d H:i:s', strtotime($values['created_at'])); } if (isset($values['updated_at'])) { $values['updated_at'] = date('Y-m-d H:i:s', strtotime($values['updated_at'])); } $created = $frm_entry->create($values); unset($_POST); unset($values); unset($created); if ($row - $start_row >= 250) { //change max rows here fclose($f); return $row; } } fclose($f); return $row; } }
function display_value($value, $field, $atts = array()) { global $wpdb; $defaults = array('type' => '', 'show_icon' => true, 'show_filename' => true, 'truncate' => false, 'sep' => ', ', 'post_id' => 0, 'form_id' => $field->form_id, 'field' => $field); $atts = wp_parse_args($atts, $defaults); $field->field_options = maybe_unserialize($field->field_options); if (!isset($field->field_options['post_field'])) { $field->field_options['post_field'] = ''; } if (!isset($field->field_options['custom_field'])) { $field->field_options['custom_field'] = ''; } if ($atts['post_id'] and ($field->field_options['post_field'] or $atts['type'] == 'tag')) { $atts['pre_truncate'] = $atts['truncate']; $atts['truncate'] = true; $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); $atts['truncate'] = $atts['pre_truncate']; } if ($value == '') { return $value; } $value = maybe_unserialize($value); if (is_array($value)) { $value = stripslashes_deep($value); } $value = apply_filters('frm_display_value_custom', $value, $field, $atts); $new_value = ''; if (is_array($value)) { foreach ($value as $val) { if (is_array($val)) { //TODO: add options for display (li or ,) $new_value .= implode($atts['sep'], $val); if ($atts['type'] != 'data') { $new_value .= "<br/>"; } } unset($val); } } if (!empty($new_value)) { $value = $new_value; } else { if (is_array($value)) { $value = implode($atts['sep'], $value); } } if ($atts['truncate'] and $atts['type'] != 'image') { $value = FrmAppHelper::truncate($value, 50); } if ($atts['type'] == 'image') { $value = '<img src="' . $value . '" height="50px" alt="" />'; } else { if ($atts['type'] == 'user_id') { $value = FrmProFieldsHelper::get_display_name($value); } else { if ($atts['type'] == 'file') { $old_value = $value; $value = ''; if ($atts['show_icon']) { $value .= FrmProFieldsHelper::get_file_icon($old_value); } if ($atts['show_icon'] and $atts['show_filename']) { $value .= '<br/>'; } if ($atts['show_filename']) { $value .= FrmProFieldsHelper::get_file_name($old_value); } } else { if ($atts['type'] == 'date') { $value = FrmProFieldsHelper::get_date($value); } else { if ($atts['type'] == 'data') { if (!is_numeric($value)) { $value = explode($atts['sep'], $value); if (is_array($value)) { $new_value = ''; foreach ($value as $entry_id) { if (!empty($new_value)) { $new_value .= $atts['sep']; } if (is_numeric($entry_id)) { $new_value .= FrmProFieldsHelper::get_data_value($entry_id, $field, $atts); } else { $new_value .= $entry_id; } } $value = $new_value; } } else { //replace item id with specified field $value = FrmProFieldsHelper::get_data_value($value, $field, $atts); if ($field->field_options['data_type'] == 'data' or $field->field_options['data_type'] == '') { $linked_field = FrmField::getOne($field->field_options['form_select']); if ($linked_field->type == 'file') { $old_value = $value; $value = '<img src="' . $value . '" height="50px" alt="" />'; if ($atts['show_filename']) { $value .= '<br/>' . $old_value; } } } } } } } } } $value = stripslashes_deep($value); return apply_filters('frm_display_value', $value, $field, $atts); }
/** * Constructor for class * * @since 1.0.0 */ public function __construct() { // add admin page add_action('admin_menu', array($this, 'add_settings_pages'), 25); // save config add_action('wp_ajax_frmwks_save_config', array($this, 'save_config')); // exporter add_action('init', array($this, 'check_exporter')); // get forms list add_filter('formworks_get_forms', array($this, 'get_forms')); add_action('wp_ajax_frmwks_module_data', array($this, 'module_data_loader')); if (current_user_can('manage_options')) { add_action('wp_ajax_frmwks_rebuild_database', array($this, 'rebuild_database')); //add_action( 'wp_ajax_frmwks_reset_form_stats', array( $this, 'reset_form_stats') ); } // create new add_action('wp_ajax_frmwks_create_formworks', array($this, 'create_new_formworks')); // delete add_action('wp_ajax_frmwks_delete_formworks', array($this, 'delete_formworks')); add_filter('formworks_stats_field_name', function ($field, $form_prefix, $form_id) { switch ($form_prefix) { case 'caldera': if (false !== strpos($field, '[')) { $field = strtok($field, '['); } // is CF $form = \Caldera_Forms::get_form($form_id); if (empty($form)) { continue; } if (!empty($form['fields'][$field]['label'])) { $field = $form['fields'][$field]['label']; } break; case 'gform': //get gravity form if (!class_exists('RGFormsModel')) { continue; } $form_info = \RGFormsModel::get_form($form_id); break; case 'ninja': //get ninja form if (!function_exists('Ninja_Forms')) { continue; } $form_name = Ninja_Forms()->form($form_id)->get_setting('form_title'); $form_id = $form_id; break; case 'cf7': //get contact form 7 if (!class_exists('WPCF7_ContactForm')) { continue; } $cf7form = \WPCF7_ContactForm::get_instance($form_id); $form_name = $cf7form->title(); $form_id = $cf7form->id(); break; case 'frmid': if (!class_exists('FrmForm')) { continue; } $field_id = (int) strtok(str_replace('item_meta[', '', $field), ']'); $form_field = \FrmField::getOne($field_id); $field = $form_field->name; if (!empty($form_field->description) && $form_field->description != $form_field->name) { $field .= ':' . $form_field->description; } break; case 'jp': $form_post = get_post($form_id); if (empty($form_post)) { continue; } $field = ucwords(str_replace('g' . $form_id . '-', '', $field)); break; default: //no idea what this is or the form plugin was disabled. break; } return $field; }, 10, 3); }
public static function add_form_row() { //check_ajax_referer( 'frm_ajax', 'nonce' ); $field_id = absint($_POST['field_id']); if (!$field_id) { wp_die(); } $field = FrmField::getOne($field_id); $args = array('i' => absint($_POST['i']), 'parent_field' => absint($field->id), 'form' => isset($field->field_options['form_select']) ? $field->field_options['form_select'] : 0, 'repeat' => 1); $field_name = 'item_meta[' . $args['parent_field'] . ']'; // let's show a textarea since the ajax with multiple rte doesn't work well in WP right now global $frm_vars; $frm_vars['skip_rte'] = true; $response = array(); ob_start(); FrmProFormsHelper::repeat_field_set($field_name, $args); $response['html'] = ob_get_contents(); ob_end_clean(); global $frm_vars; $response['logic'] = FrmProFormsHelper::hide_conditional_fields($frm_vars); echo json_encode($response); wp_die(); }
function get_object_by_id($field_id) { return FrmField::getOne($field_id); }
/** * Replace a text value where_val with the matching entry IDs for Dynamic Field filters * * @param array $args * @param object $where_field */ private static function prepare_dfe_text(&$args, $where_field) { // Only proceed if we have a non-category dynamic field with a string where_val if ($where_field->type != 'data' || !$args['where_val'] || !is_string($args['where_val']) || isset($where_field->field_options['post_field']) && $where_field->field_options['post_field'] == 'post_category') { return; } $linked_id = FrmProField::get_dynamic_field_entry_id($where_field->field_options['form_select'], $args['where_val'], $args['temp_where_is']); // If text doesn't return any entry IDs, get entry IDs from entry key // Note: Keep for reverse compatibility if (!$linked_id) { $linked_field = FrmField::getOne($where_field->field_options['form_select']); if (!$linked_field) { return; } $filter_args = array(); self::add_group_by($filter_args, $args, 'item_key'); $linked_id = FrmDb::get_col('frm_items', array('form_id' => $linked_field->form_id, 'item_key ' . FrmDb::append_where_is($args['temp_where_is']) => $args['where_val'])); } if (!$linked_id) { return; } //Change $args['where_val'] to linked entry IDs $args['where_val'] = (array) $linked_id; // Don't use old where_val_esc value for filtering unset($args['where_val_esc']); $args['where_val'] = apply_filters('frm_filter_dfe_where_val', $args['where_val'], $args); }
private function get_column_value($item, &$val) { $col_name = $this->column_name; if (strpos($col_name, 'frmsep_') === 0) { $sep_val = true; $col_name = str_replace('frmsep_', '', $col_name); } else { $sep_val = false; } if (strpos($col_name, '-_-')) { list($col_name, $embedded_field_id) = explode('-_-', $col_name); } $field = FrmField::getOne($col_name); if (!$field) { return; } $atts = array('type' => $field->type, 'truncate' => true, 'post_id' => $item->post_id, 'entry_id' => $item->id, 'embedded_field_id' => 0); if ($sep_val) { $atts['saved_value'] = true; } if (isset($embedded_field_id)) { $atts['embedded_field_id'] = $embedded_field_id; unset($embedded_field_id); } $val = FrmEntriesHelper::prepare_display_value($item, $field, $atts); }
public static function has_field($type, $form_id, $single = true) { global $wpdb; $frm_field = new FrmField(); if ($single) { $included = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_fields WHERE form_id=%d AND type=%s", $form_id, $type)); if ($included) { $included = $frm_field->getOne($included); } } else { $included = $frm_field->getAll(array('type' => $type, 'fi.form_id' => $form_id)); } return $included; }
/** * Update form_select for all imported repeating sections and embedded forms * * @since 2.0.09 * @param array $repeat_fields - old form ID as keys and section field IDs as items * @param array $imported_forms */ private static function update_repeat_field_options($repeat_fields, $imported_forms) { foreach ($repeat_fields as $old_form_id => $new_repeat_fields) { foreach ($new_repeat_fields as $repeat_field_id) { // Get section/embed form field $repeat_field = FrmField::getOne($repeat_field_id); $field_opts = maybe_unserialize($repeat_field->field_options); if (!isset($imported_forms[$old_form_id])) { return; } $field_opts['form_select'] = $imported_forms[$old_form_id]; // update form_select now FrmField::update($repeat_field_id, array('field_options' => maybe_serialize($field_opts))); } } }
function upgrade() { global $wpdb; $db_version = 14; // this is the version of the database we're moving to $old_db_version = get_option('frmpro_db_version'); if ($db_version != $old_db_version) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $charset_collate = ''; if ($wpdb->has_cap('collation')) { if (!empty($wpdb->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } } /* Create/Upgrade Display Table */ $sql = "CREATE TABLE {$this->displays} (\n id int(11) NOT NULL auto_increment,\n display_key varchar(255) default NULL,\n name varchar(255) default NULL,\n description text default NULL,\n content longtext default NULL,\n dyncontent longtext default NULL,\n insert_loc varchar(255) default NULL,\n param varchar(255) default NULL,\n type varchar(255) default NULL,\n show_count varchar(255) default NULL,\n options longtext default NULL,\n form_id int(11) default NULL,\n entry_id int(11) default NULL,\n post_id int(11) default NULL,\n created_at datetime NOT NULL,\n PRIMARY KEY id (id),\n KEY form_id (form_id),\n KEY entry_id (entry_id),\n KEY post_id (post_id),\n UNIQUE KEY display_key (display_key)\n ) {$charset_collate};"; dbDelta($sql); if ($db_version >= 3 and $old_db_version < 3) { //migrate hidden field data into the parent field $wpdb->update($frmdb->fields, array('type' => 'scale'), array('type' => '10radio')); $fields = FrmField::getAll(); foreach ($fields as $field) { $field->field_options = maybe_unserialize($field->field_options); if (isset($field->field_options['hide_field']) and is_numeric($field->field_options['hide_field']) and (isset($field->field_options['hide_opt']) and !empty($field->field_options['hide_opt']) or isset($field->field_options['form_select']) and !empty($field->field_options['form_select']))) { global $frm_field; //save hidden fields to parent field $parent_field = FrmField::getOne($field->field_options['hide_field']); if ($parent_field) { $parent_options = maybe_unserialize($parent_field->field_options); if (!isset($parent_options['dependent_fields'])) { $parent_options['dependent_fields'] = array(); } else { foreach ($parent_options['dependent_fields'] as $child_id => $child_opt) { if (empty($child_opt) or $child_opt == '') { unset($parent_options['dependent_fields'][$child_id]); } else { if ($child_id != $field->id) { //check to make sure this field is still dependent $check_field = FrmField::getOne($child_id); $check_options = maybe_unserialize($check_field->field_options); if (!is_numeric($check_options['hide_field']) or $check_options['hide_field'] != $parent_field->id or empty($check_options['hide_opt']) and empty($check_options['form_select'])) { unset($parent_options['dependent_fields'][$child_id]); } } } } } $dep_fields = array(); if ($field->type == 'data' and isset($field->field_options['form_select']) and is_numeric($field_options['form_select'])) { $dep_fields[] = $field->field_options['form_select']; $dep_fields[] = $field->field_options['data_type']; } else { if (isset($field->field_options['hide_opt']) and !empty($field->field_options['hide_opt'])) { $dep_fields[] = $field->field_options['hide_opt']; } } if (!empty($dep_fields)) { $parent_options['dependent_fields'][$field->id] = $dep_fields; } $frm_field->update($parent_field->id, array('field_options' => $parent_options)); } } } } /**** ADD DEFAULT TEMPLATES ****/ FrmFormsController::add_default_templates(FRMPRO_TEMPLATES_PATH); update_option('frmpro_db_version', $db_version); global $frmpro_settings; $frmpro_settings->store(); //update the styling settings } }