function create() { global $frm_field, $frm_ajax_url; $field_data = $_POST['field']; $form_id = $_POST['form_id']; $values = array(); if (class_exists('FrmProForm')) { $values['post_type'] = FrmProForm::post_type($form_id); } $field_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars($field_data, $form_id)); $field_id = $frm_field->create($field_values); if ($field_id) { $field = FrmFieldsHelper::setup_edit_vars($frm_field->getOne($field_id)); $field_name = "item_meta[{$field_id}]"; $id = $form_id; require FRM_VIEWS_PATH . '/frm-forms/add_field.php'; require FRM_VIEWS_PATH . '/frm-forms/new-field-js.php'; } die; }
function get_search_str($where_clause = '', $search_str, $form_id = false, $fid = false) { global $frm_entry_meta; $where_item = ''; $join = ' ('; if (!is_array($search_str)) { $search_str = explode(" ", $search_str); } foreach ($search_str as $search_param) { $search_param = esc_sql(like_escape($search_param)); if (!is_numeric($fid)) { $where_item .= empty($where_item) ? ' (' : ' OR'; if (in_array($fid, array('created_at', 'user_id', 'updated_at'))) { if ($fid == 'user_id' and !is_numeric($search_param)) { $search_param = FrmProAppHelper::get_user_id_param($search_param); } $where_item .= " it.{$fid} like '%{$search_param}%'"; } else { $where_item .= " it.name like '%{$search_param}%' OR it.item_key like '%{$search_param}%' OR it.description like '%{$search_param}%' OR it.created_at like '%{$search_param}%'"; } } if (empty($fid) or is_numeric($fid)) { $where_entries = "(meta_value LIKE '%{$search_param}%'"; if ($data_fields = FrmProForm::has_field('data', $form_id, false)) { $df_form_ids = array(); //search the joined entry too foreach ((array) $data_fields as $df) { $df->field_options = maybe_unserialize($df->field_options); if (is_numeric($df->field_options['form_select'])) { $df_form_ids[] = $df->field_options['form_select']; } unset($df); } unset($data_fields); global $wpdb, $frmdb; $data_form_ids = $wpdb->get_col("SELECT form_id FROM {$frmdb->fields} WHERE id in (" . implode(',', $df_form_ids) . ")"); unset($df_form_ids); if ($data_form_ids) { $data_entry_ids = $frm_entry_meta->getEntryIds("fi.form_id in (" . implode(',', $data_form_ids) . ") and meta_value LIKE '%" . $search_param . "%'"); if (!empty($data_entry_ids)) { $where_entries .= " OR meta_value in (" . implode(',', $data_entry_ids) . ")"; } } unset($data_form_ids); } $where_entries .= ")"; if (is_numeric($fid)) { $where_entries .= " AND fi.id={$fid}"; } $meta_ids = $frm_entry_meta->getEntryIds($where_entries); if (!empty($meta_ids)) { if (!empty($where_clause)) { $where_clause .= " AND" . $join; if (!empty($join)) { $join = ''; } } $where_clause .= " it.id in (" . implode(',', $meta_ids) . ")"; } else { if (!empty($where_clause)) { $where_clause .= " AND" . $join; if (!empty($join)) { $join = ''; } } $where_clause .= " it.id=0"; } } } if (!empty($where_item)) { $where_item .= ')'; if (!empty($where_clause)) { $where_clause .= empty($fid) ? ' OR' : ' AND'; } $where_clause .= $where_item; if (empty($join)) { $where_clause .= ')'; } } else { if (empty($join)) { $where_clause .= ')'; } } return $where_clause; }
function get_search_ids($s, $form_id) { global $wpdb, $frmdb, $frm_entry_meta; if (empty($s)) { return false; } $s = stripslashes($s); preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches); $search_terms = array_map('_search_terms_tidy', $matches[0]); $n = '%'; //!empty($q['exact']) ? '' : '%'; $p_search = $search = ''; $search_or = ''; $data_field = FrmProForm::has_field('data', $form_id, false); foreach ((array) $search_terms as $term) { $term = esc_sql(like_escape($term)); $p_search .= " AND (({$wpdb->posts}.post_title LIKE '{$n}{$term}{$n}') OR ({$wpdb->posts}.post_content LIKE '{$n}{$term}{$n}'))"; $search .= "{$search_or}meta_value LIKE '{$n}{$term}{$n}'"; $search_or = ' OR '; if ($data_field) { $df_form_ids = array(); //search the joined entry too foreach ((array) $data_field as $df) { $df->field_options = maybe_unserialize($df->field_options); if (is_numeric($df->field_options['form_select'])) { $df_form_ids[] = $df->field_options['form_select']; } unset($df); } global $wpdb, $frmdb; $data_form_ids = $wpdb->get_col("SELECT form_id FROM {$frmdb->fields} WHERE id in (" . implode(',', $df_form_ids) . ")"); unset($df_form_ids); if ($data_form_ids) { $data_entry_ids = $frm_entry_meta->getEntryIds("fi.form_id in (" . implode(',', $data_form_ids) . ") and meta_value LIKE '%" . $term . "%'"); if ($data_entry_ids) { $search .= "{$search_or}meta_value in (" . implode(',', $data_entry_ids) . ")"; } } unset($data_form_ids); } } $p_ids = ''; $matching_posts = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE 1=1 {$p_search}"); if ($matching_posts) { $p_ids = $wpdb->get_col("SELECT id from {$frmdb->entries} WHERE post_id in (" . implode(',', $matching_posts) . ") AND form_id='{$form_id}'"); $p_ids = $p_ids ? " OR item_id in (" . implode(',', $p_ids) . ")" : ''; } return $frm_entry_meta->getEntryIds("(({$search}){$p_ids}) and fi.form_id='{$form_id}'"); }
public static function validate($errors, $values) { return FrmProForm::validate($errors, $values); }
function get_post_value($post_id, $post_field, $custom_field, $atts) { if (!$post_id) { return ''; } $post = get_post($post_id); if (!$post) { return ''; } $defaults = array('sep' => ', ', 'truncate' => true, 'form_id' => false, 'field' => array(), 'links' => false, 'show' => ''); $atts = wp_parse_args($atts, $defaults); $value = ''; if ($atts['type'] == 'tag') { if (isset($atts['field']->field_options)) { $field_options = maybe_unserialize($atts['field']->field_options); $tax = $field_options['taxonomy']; if ($tags = get_the_terms($post_id, $tax)) { $names = array(); foreach ($tags as $tag) { $tag_name = $tag->name; if ($atts['links']) { $tag_name = '<a href="' . esc_attr(get_term_link($tag)) . '" title="' . esc_attr(sprintf(__('View all posts filed under %s', 'formidable'), $tag_name)) . '">' . $tag_name . '</a>'; } $names[] = $tag_name; } $value = implode($atts['sep'], $names); } } } else { if ($post_field == 'post_custom') { //get custom post field value $value = get_post_meta($post_id, $custom_field, true); } else { if ($post_field == 'post_category') { if ($atts['form_id']) { $post_type = FrmProForm::post_type($atts['form_id']); $taxonomy = FrmProAppHelper::get_custom_taxonomy($post_type, $atts['field']); } else { $taxonomy = 'category'; } $categories = get_the_terms($post_id, $taxonomy); $names = array(); $cat_ids = array(); if ($categories) { foreach ($categories as $cat) { if (isset($atts['exclude_cat']) and in_array($cat->term_id, (array) $atts['exclude_cat'])) { continue; } $cat_name = $cat->name; if ($atts['links']) { $cat_name = '<a href="' . esc_attr(get_term_link($cat)) . '" title="' . esc_attr(sprintf(__('View all posts filed under %s', 'formidable'), $cat_name)) . '">' . $cat_name . '</a>'; } $names[] = $cat_name; $cat_ids[] = $cat->term_id; } } if ($atts['show'] == 'id') { $value = implode($atts['sep'], $cat_ids); } else { if ($atts['truncate']) { $value = implode($atts['sep'], $names); } else { $value = $cat_ids; } } } else { $post = (array) $post; $value = $post[$post_field]; } } } return $value; }
function get_status_options($field) { $post_type = FrmProForm::post_type($field->form_id); $post_type_object = get_post_type_object($post_type); $options = array(); if (!$post_type_object) { return $options; } $can_publish = current_user_can($post_type_object->cap->publish_posts); $options = get_post_statuses(); //'draft', pending, publish, private if (!$can_publish) { // Contributors only get "Unpublished" and "Pending Review" unset($options['publish']); if (isset($options['future'])) { unset($options['future']); } } return $options; }
public static function ajax_create() { if (!FrmAppHelper::doing_ajax() || !isset($_POST['form_id'])) { // normally, this function would be triggered with the wp_ajax hook, but we need it fired sooner return; } $allowed_actions = array('frm_entries_create', 'frm_entries_update'); if (!in_array(FrmAppHelper::get_post_param('action', '', 'sanitize_title'), $allowed_actions)) { // allow ajax creating and updating return; } $form = FrmForm::getOne((int) $_POST['form_id']); if (!$form) { echo false; wp_die(); } $no_ajax_fields = array('file'); $errors = FrmEntryValidate::validate($_POST, $no_ajax_fields); if (empty($errors)) { if (FrmProForm::is_ajax_on($form)) { global $frm_vars; $frm_vars['ajax'] = true; $frm_vars['css_loaded'] = true; // don't load scripts if we are going backwards in the form $going_backwards = FrmProFormsHelper::going_to_prev($form->id); // save the entry if there is not another page or when saving a draft if (!isset($_POST['frm_page_order_' . $form->id]) && !$going_backwards || FrmProFormsHelper::saving_draft()) { $processed = true; FrmEntriesController::process_entry($errors, true); } echo FrmFormsController::show_form($form->id); // trigger the footer scripts if there is a form to show if ($errors || !isset($processed) || !empty($frm_vars['forms_loaded'])) { self::print_ajax_scripts($going_backwards ? 'none' : ''); } } else { echo false; } } else { $obj = array(); foreach ($errors as $field => $error) { $field_id = str_replace('field', '', $field); $obj[$field_id] = $error; } echo json_encode($obj); } wp_die(); }
function dropdown_categories($args) { $defaults = array('field' => false, 'name' => false); extract(wp_parse_args($args, $defaults)); if (!$field) { return; } if (!$name) { $name = "item_meta[{$field['id']}]"; } $selected = is_array($field['value']) ? reset($field['value']) : $field['value']; $exclude = is_array($field['exclude_cat']) ? implode(',', $field['exclude_cat']) : $field['exclude_cat']; $exclude = apply_filters('frm_exclude_cats', $exclude, $field); $args = array('show_option_all' => ' ', 'hierarchical' => 1, 'name' => $name, 'id' => 'field_' . $field['field_key'], 'exclude' => $exclude, 'class' => $field['type'], 'selected' => $selected, 'hide_empty' => false, 'echo' => 0, 'orderby' => 'name'); if (class_exists('FrmProForm')) { $post_type = FrmProForm::post_type($field['form_id']); if (function_exists('get_object_taxonomies')) { $args['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $field); if (!$args['taxonomy']) { return; } } } return wp_dropdown_categories($args); }
function create_post($entry_id, $form_id) { global $wpdb, $frmdb; $post_id = NULL; if (isset($_POST['frm_wp_post'])) { $post = array(); $post['post_type'] = FrmProForm::post_type($form_id); if (isset($_POST['frm_user_id']) and is_numeric($_POST['frm_user_id'])) { $post['post_author'] = $_POST['frm_user_id']; } $status = false; foreach ($_POST['frm_wp_post'] as $post_data => $value) { if ($status) { continue; } $post_data = explode('=', $post_data); if ($post_data[1] == 'post_status') { $status = true; } } if (!$status) { $form_options = $frmdb->get_var($frmdb->forms, array('id' => $form_id), 'options'); $form_options = maybe_unserialize($form_options); if (isset($form_options['post_status']) and $form_options['post_status'] == 'publish') { $post['post_status'] = 'publish'; } } $post_id = $this->insert_post($entry_id, $post); } //save post_id with the entry $updated = $wpdb->update($frmdb->entries, array('post_id' => $post_id), array('id' => $entry_id)); if ($updated) { wp_cache_delete($entry_id, 'frm_entry'); } }
public static function validate($errors, $values) { $frmpro_form = new FrmProForm(); return $frmpro_form->validate($errors, $values); }
function post_options($values) { global $frm_ajax_url; $post_types = FrmProAppHelper::get_custom_post_types(); if (!$post_types) { return; } $post_type = FrmProForm::post_type($values); if (function_exists('get_object_taxonomies')) { $taxonomies = get_object_taxonomies($post_type); } $echo = true; $show_post_type = false; if (isset($values['fields']) and $values['fields']) { foreach ($values['fields'] as $field) { if (!$show_post_type and $field['post_field'] != '') { $show_post_type = true; } } } if ($show_post_type) { $values['create_post'] = true; } require FRMPRO_VIEWS_PATH . '/frmpro-forms/post_options.php'; }
function dropdown_categories($args) { global $frmpro_is_installed; $defaults = array('field' => false, 'name' => false); extract(wp_parse_args($args, $defaults)); if (!$field) { return; } if (!$name) { $name = "item_meta[{$field['id']}]"; } $id = 'field_' . $field['field_key']; $class = $field['type']; $selected = is_array($field['value']) ? reset($field['value']) : $field['value']; $exclude = is_array($field['exclude_cat']) ? implode(',', $field['exclude_cat']) : $field['exclude_cat']; $exclude = apply_filters('frm_exclude_cats', $exclude, $field); $args = array('show_option_all' => ' ', 'hierarchical' => 1, 'name' => $name, 'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected, 'hide_empty' => false, 'echo' => 0, 'orderby' => 'name'); if (class_exists('FrmProForm')) { $post_type = FrmProForm::post_type($field['form_id']); if (function_exists('get_object_taxonomies')) { $args['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $field); if (!$args['taxonomy']) { return; } } } $dropdown = wp_dropdown_categories($args); $add_html = FrmFieldsController::input_html($field, false); if ($frmpro_is_installed) { $add_html .= FrmProFieldsController::input_html($field, false); } $dropdown = str_replace("<select name='{$name}' id='{$id}' class='{$class}'", "<select name='{$name}' id='{$id}' " . $add_html, $dropdown); return $dropdown; }
function ajax_data_options($hide_field, $entry_id, $selected_field_id, $field_id) { global $frmpro_entry_meta, $frm_field; $data_field = $frm_field->getOne($selected_field_id); $entry_id = explode(',', $entry_id); $field_name = "item_meta[{$field_id}]"; $field_data = $frm_field->getOne($field_id); $field_data->field_options = maybe_unserialize($field_data->field_options); $field = array('id' => $field_id, 'value' => '', 'default_value' => '', 'form_id' => $field_data->form_id, 'type' => apply_filters('frm_field_type', $field_data->type, $field_data, ''), 'options' => stripslashes_deep(maybe_unserialize($field_data->options)), 'size' => isset($field_data->field_options['size']) && $field_data->field_options['size'] != '' ? $field_data->field_options['size'] : ''); if ($field['size'] == '') { global $frm_sidebar_width; $field['size'] = $frm_sidebar_width; } $field = apply_filters('frm_setup_new_fields_vars', stripslashes_deep($field), $field_data); if (is_numeric($selected_field_id)) { $field['options'] = array(); $metas = $frmpro_entry_meta->meta_through_join($hide_field, $data_field, $entry_id); foreach ($metas as $meta) { $field['options'][$meta->item_id] = FrmProEntryMetaHelper::display_value($meta->meta_value, $data_field, array('type' => $data_field->type, 'show_icon' => true, 'show_filename' => false)); } } else { if ($selected_field_id == 'taxonomy') { $cat_ids = array_keys($field['options']); $args = array('include' => implode(',', $cat_ids), 'hide_empty' => false); if (function_exists('get_object_taxonomies')) { $post_type = FrmProForm::post_type($field_data->form_id); $args['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $field_data); if (!$args['taxonomy']) { return; } } $cats = get_categories($args); foreach ($cats as $cat) { if (!in_array($cat->parent, (array) $entry_id)) { unset($field['options'][$cat->term_id]); } } } } $auto_width = isset($field['size']) && $field['size'] > 0 ? 'class="auto_width"' : ''; require FRMPRO_VIEWS_PATH . '/frmpro-fields/data-options.php'; die; }
function post_options($values) { global $frm_ajax_url; $post_types = FrmProAppHelper::get_custom_post_types(); if (!$post_types) { return; } $post_type = FrmProForm::post_type($values); if (function_exists('get_object_taxonomies')) { $taxonomies = get_object_taxonomies($post_type); } $echo = true; $show_post_type = false; if (isset($values['fields']) and $values['fields']) { foreach ($values['fields'] as $field) { if (!$show_post_type and $field['post_field'] != '') { $show_post_type = true; } } } if ($show_post_type) { $values['create_post'] = true; } $form_id = (int) $_GET['id']; $display = FrmProDisplay::getAll("form_id={$form_id} and show_count in ('single', 'dynamic', 'calendar')", '', ' LIMIT 1'); require FRMPRO_VIEWS_PATH . '/frmpro-forms/post_options.php'; }