function get_related_entries($entry_id) { $term_ids = FrmProEntry::get_entry_tags($entry_id, array('fields' => 'ids')); $entry_ids = FrmProEntry::get_tagged_entries($term_ids); foreach ($entry_ids as $key => $id) { if ($id == $entry_id) { unset($entry_ids[$key]); } } return $entry_ids; }
function update_field_ajax($entry_id, $field_id, $value) { global $frmdb, $wpdb, $frm_field; $entry_id = (int) $entry_id; if (!$entry_id) { return false; } $where = ''; if (is_numeric($field_id)) { $where .= "fi.id={$field_id}"; } else { $where .= "field_key='{$field_id}'"; } $field = $frm_field->getAll($where, '', ' LIMIT 1'); if (!$field or !FrmProEntry::user_can_edit($entry_id, $field->form_id)) { return false; } $post_id = false; $field->field_options = maybe_unserialize($field->field_options); if (isset($field->field_options['post_field']) and !empty($field->field_options['post_field'])) { $post_id = $frmdb->get_var($frmdb->entries, array('id' => $entry_id), 'post_id'); } if (!$post_id) { $updated = $wpdb->update($frmdb->entry_metas, array('meta_value' => $value), array('item_id' => $entry_id, 'field_id' => $field_id)); if (!$updated) { $wpdb->query($wpdb->prepare("DELETE FROM {$frmdb->entry_metas} WHERE item_id = %d and field_id = %d", $entry_id, $field_id)); $updated = FrmEntryMeta::add_entry_meta($entry_id, $field_id, '', $value); } wp_cache_delete($entry_id, 'frm_entry'); } else { switch ($field->field_options['post_field']) { case 'post_custom': $updated = update_post_meta($post_id, $field->field_options['post_custom'], maybe_serialize($value)); break; case 'post_category': $taxonomy = (isset($field->field_options['taxonomy']) and !empty($field->field_options['taxonomy'])) ? $field->field_options['taxonomy'] : 'category'; $updated = wp_set_post_terms($post_id, $value, $taxonomy); break; default: $post = get_post($post_id, ARRAY_A); $post[$field->field_options['post_field']] = maybe_serialize($value); $updated = wp_insert_post($post); } } do_action('frm_after_update_field', compact('entry_id', 'field_id', 'value')); return $updated; }
public static function replace_single_shortcode($shortcodes, $short_key, $tag, $entry, $display, $args, &$content) { global $post; $conditional = preg_match('/^\\[if/s', $shortcodes[0][$short_key]) ? true : false; $foreach = preg_match('/^\\[foreach/s', $shortcodes[0][$short_key]) ? true : false; $atts = shortcode_parse_atts($shortcodes[3][$short_key]); $tag = FrmFieldsHelper::get_shortcode_tag($shortcodes, $short_key, compact('conditional', 'foreach')); if (strpos($tag, '-')) { $switch_tags = array('post-id', 'created-at', 'updated-at', 'created-by', 'updated-by', 'parent-id'); if (in_array($tag, $switch_tags)) { $tag = str_replace('-', '_', $tag); } unset($switch_tags); } $tags = array('event_date', 'entry_count', 'detaillink', 'editlink', 'deletelink', 'created_at', 'updated_at', 'created_by', 'updated_by', 'evenodd', 'post_id', 'parent_id', 'id'); if (in_array($tag, $tags)) { $args['entry'] = $entry; $args['tag'] = $tag; $args['conditional'] = $conditional; $function = 'do_shortcode_' . $tag; self::$function($content, $atts, $shortcodes, $short_key, $args, $display); return; } $field = FrmField::getOne($tag); if (!$field) { return; } if (!$foreach && !$conditional && isset($atts['show']) && ($atts['show'] == 'field_label' || $atts['show'] == 'description')) { // get the field label or description and return before any other checking $replace_with = $atts['show'] == 'field_label' ? $field->name : $field->description; $content = str_replace($shortcodes[0][$short_key], $replace_with, $content); return; } $sep = isset($atts['sep']) ? $atts['sep'] : ', '; if ($field->form_id == $entry->form_id) { $replace_with = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $field, $atts); } else { // get entry ids linked through repeat field or embeded form $child_entries = FrmProEntry::get_sub_entries($entry->id, true); $replace_with = FrmProEntryMetaHelper::get_sub_meta_values($child_entries, $field, $atts); $replace_with = FrmAppHelper::array_flatten($replace_with); } $atts['entry_id'] = $entry->id; $atts['entry_key'] = $entry->item_key; $atts['post_id'] = $entry->post_id; $replace_with = apply_filters('frmpro_fields_replace_shortcodes', $replace_with, $tag, $atts, $field); self::get_file_from_atts($atts, $field, $replace_with); if (isset($atts['show']) && $atts['show'] == 'count') { $replace_with = is_array($replace_with) ? count($replace_with) : !empty($replace_with); } else { if (is_array($replace_with) && !$foreach) { $replace_with = FrmAppHelper::array_flatten($replace_with); $replace_with = implode($sep, $replace_with); } } if ($foreach) { $atts['short_key'] = $shortcodes[0][$short_key]; $args['display'] = $display; self::check_conditional_shortcode($content, $replace_with, $atts, $tag, 'foreach', $args); } else { if ($conditional) { $atts['short_key'] = $shortcodes[0][$short_key]; self::check_conditional_shortcode($content, $replace_with, $atts, $tag, 'if', array('field' => $field)); } else { if (empty($replace_with) && $replace_with != '0') { $replace_with = ''; if ($field->type == 'number') { $replace_with = '0'; } } else { $replace_with = FrmFieldsHelper::get_display_value($replace_with, $field, $atts); } self::trigger_shortcode_atts($atts, $display, $args, $replace_with); $content = str_replace($shortcodes[0][$short_key], $replace_with, $content); } } }
public static function update($values = array()) { if (empty($values)) { $values = $_POST; } //Set radio button and checkbox meta equal to "other" value if (FrmAppHelper::pro_is_installed()) { $values = FrmProEntry::mod_other_vals($values, 'back'); } $errors = FrmForm::validate($values); $permission_error = FrmAppHelper::permission_nonce_error('frm_edit_forms', 'frm_save_form', 'frm_save_form_nonce'); if ($permission_error !== false) { $errors['form'] = $permission_error; } $id = isset($values['id']) ? absint($values['id']) : FrmAppHelper::get_param('id', '', 'get', 'absint'); if (count($errors) > 0) { return self::get_edit_vars($id, $errors); } else { FrmForm::update($id, $values); $message = __('Form was Successfully Updated', 'formidable'); if (defined('DOING_AJAX')) { wp_die($message); } return self::get_edit_vars($id, array(), $message); } }
public static function update_post($entry_id, $form_id) { _deprecated_function(__FUNCTION__, '2.0', 'FrmProEntriesController::trigger_post'); FrmProEntry::create_post($entry_id, $form_id, 'update'); }
,<?php echo $c; ?> ,"<?php echo str_replace(array("\r\n", "\n"), '\\r', str_replace(''', "'", esc_attr($val))); ?> "); <?php } } $c++; unset($val); unset($col); unset($type); } if ($edit_link and FrmProEntry::user_can_edit($entry, $form)) { ?> data.setCell(<?php echo $i; ?> ,<?php echo $c; ?> ,'<a href="<?php echo esc_url(add_query_arg(array('frm_action' => 'edit', 'entry' => $entry->id), $permalink) . $anchor); ?> "><?php echo addslashes($edit_link); ?> </a>'); <?php
public static function add_repeating_value_to_entry($field, &$entry) { // If field is in a repeating section if ($entry->form_id != $field->form_id) { // get entry ids linked through repeat field or embeded form $child_entries = FrmProEntry::get_sub_entries($entry->id, true); $val = FrmProEntryMetaHelper::get_sub_meta_values($child_entries, $field); if (!empty($val)) { //Flatten multi-dimensional arrays if (is_array($val)) { $val = FrmAppHelper::array_flatten($val); } $entry->metas[$field->id] = $val; } } else { $val = ''; FrmProEntriesHelper::get_dynamic_list_values($field, $entry, $val); $entry->metas[$field->id] = $val; } }
</dh> <?php } foreach ($form_cols as $col) { ?> <td valign="top"> <?php echo FrmProEntryMetaHelper::display_value(isset($entry->metas[$col->id]) ? $entry->metas[$col->id] : false, $col, array('type' => $col->type, 'post_id' => $entry->post_id, 'entry_id' => $entry->id)); ?> </td> <?php } if ($edit_link) { ?> <td><?php if (FrmProEntry::user_can_edit($entry, $form)) { ?> <a href="<?php echo esc_url(add_query_arg(array('frm_action' => 'edit', 'entry' => $entry->id), $permalink) . $anchor); ?> "><?php echo $edit_link; ?> </a><?php } ?> </td> <?php } ?> </tr>
public static function get_display_data($display, $content = '', $entry_id = false, $extra_atts = array()) { if (post_password_required($display)) { return get_the_password_form($display); } add_action('frm_load_view_hooks', 'FrmProDisplaysController::trigger_load_view_hooks'); FrmAppHelper::trigger_hook_load('view', $display); global $frm_vars, $post; $frm_vars['forms_loaded'][] = true; if (!isset($display->frm_empty_msg)) { $display = FrmProDisplaysHelper::setup_edit_vars($display, false); } if (!isset($display->frm_form_id) || empty($display->frm_form_id)) { return $content; } //for backwards compatability $display->id = $display->frm_old_id; $display->display_key = $display->post_name; $defaults = array('filter' => false, 'user_id' => '', 'limit' => '', 'page_size' => '', 'order_by' => '', 'order' => '', 'drafts' => false, 'auto_id' => ''); $extra_atts = wp_parse_args($extra_atts, $defaults); extract($extra_atts); //if (FrmProAppHelper::rewriting_on() && $frmpro_settings->permalinks ) // self::parse_pretty_entry_url(); if ($display->frm_show_count == 'one' && is_numeric($display->frm_entry_id) && $display->frm_entry_id > 0 && !$entry_id) { $entry_id = $display->frm_entry_id; } $entry = false; $show = 'all'; // Don't filter with $entry_ids by default because the query gets too long. // Only filter with $entry_ids when showing one entry $use_ids = false; global $wpdb; $where = array('it.form_id' => $display->frm_form_id); if (in_array($display->frm_show_count, array('dynamic', 'calendar', 'one'))) { $one_param = FrmAppHelper::simple_get('entry', 'sanitize_title', $extra_atts['auto_id']); $get_param = FrmAppHelper::simple_get($display->frm_param, 'sanitize_title', $display->frm_show_count == 'one' ? $one_param : $extra_atts['auto_id']); unset($one_param); if ($get_param) { if (($display->frm_type == 'id' || $display->frm_show_count == 'one') && is_numeric($get_param)) { $where['it.id'] = $get_param; } else { $where['it.item_key'] = $get_param; } $entry = FrmEntry::getAll($where, '', 1, 0); if ($entry) { $entry = reset($entry); } if ($entry && $entry->post_id) { //redirect to single post page if this entry is a post if (in_the_loop() && $display->frm_show_count != 'one' && !is_single($entry->post_id) && $post->ID != $entry->post_id) { $this_post = get_post($entry->post_id); if (in_array($this_post->post_status, array('publish', 'private'))) { die(FrmAppHelper::js_redirect(get_permalink($entry->post_id))); } } } } unset($get_param); } if ($entry && in_array($display->frm_show_count, array('dynamic', 'calendar'))) { $new_content = $display->frm_dyncontent; $show = 'one'; } else { $new_content = $display->post_content; } $show = $display->frm_show_count == 'one' ? 'one' : $show; $shortcodes = FrmProDisplaysHelper::get_shortcodes($new_content, $display->frm_form_id); //don't let page size and limit override single entry displays if ($display->frm_show_count == 'one') { $display->frm_page_size = $display->frm_limit = ''; } //don't keep current content if post type is frm_display if ($post && $post->post_type == self::$post_type) { $display->frm_insert_loc = ''; } $pagination = ''; $form_query = array('form_id' => $display->frm_form_id, 'post_id >' => 1); if ($extra_atts['drafts'] != 'both') { $is_draft = empty($extra_atts['drafts']) ? 0 : 1; $form_query['is_draft'] = $is_draft; } else { $is_draft = 'both'; } if ($entry && $entry->form_id == $display->frm_form_id) { $form_query['id'] = $entry->id; } $form_posts = FrmDb::get_results('frm_items', $form_query, 'id, post_id'); unset($form_query); $getting_entries = !$entry || !$post || empty($extra_atts['auto_id']); $check_filter_opts = !empty($display->frm_where) && $getting_entries; if ($entry && $entry->form_id == $display->frm_form_id) { $entry_ids = array($entry->id); // Filter by this entry ID to make query faster $use_ids = true; } else { if ($check_filter_opts || isset($_GET['frm_search'])) { //Only get $entry_ids if filters are set or if frm_search parameter is set $entry_query = array('form_id' => $display->frm_form_id); if ($extra_atts['drafts'] != 'both') { $entry_query['is_draft'] = $is_draft; } $entry_ids = FrmDb::get_col('frm_items', $entry_query); unset($entry_query); } } $empty_msg = isset($display->frm_empty_msg) && !empty($display->frm_empty_msg) ? '<div class="frm_no_entries">' . FrmProFieldsHelper::get_default_value($display->frm_empty_msg, false) . '</div>' : ''; if (isset($message)) { // if an entry was deleted above, show a message $empty_msg = $message . $empty_msg; } $after_where = false; $user_id = $extra_atts['user_id']; if (!empty($user_id)) { $user_id = FrmAppHelper::get_user_id_param($user_id); $uid_used = false; } self::add_group_by_filter($display, $getting_entries); unset($getting_entries); if ($check_filter_opts) { $display->frm_where = apply_filters('frm_custom_where_opt', $display->frm_where, array('display' => $display, 'entry' => $entry)); $continue = false; foreach ($display->frm_where as $where_key => $where_opt) { $where_val = isset($display->frm_where_val[$where_key]) ? $display->frm_where_val[$where_key] : ''; if (preg_match("/\\[(get|get-(.?))\\b(.*?)(?:(\\/))?\\]/s", $where_val)) { $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true); //if this param doesn't exist, then don't include it if ($where_val == '') { if (!$after_where) { $continue = true; } continue; } } else { $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true); } $continue = false; if ($where_val == 'current_user') { if ($user_id && is_numeric($user_id)) { $where_val = $user_id; $uid_used = true; } else { $where_val = get_current_user_id(); } } else { if (!is_array($where_val)) { $where_val = do_shortcode($where_val); } } if (in_array($where_opt, array('id', 'item_key', 'post_id')) && !is_array($where_val) && strpos($where_val, ',')) { $where_val = explode(',', $where_val); $where_val = array_filter($where_val); } if (is_array($where_val) && !empty($where_val)) { if (strpos($display->frm_where_is[$where_key], '!') === false && strpos($display->frm_where_is[$where_key], 'not') === false) { $display->frm_where_is[$where_key] = ' in '; } else { $display->frm_where_is[$where_key] = 'not in'; } } if (is_numeric($where_opt)) { $filter_opts = apply_filters('frm_display_filter_opt', array('where_opt' => $where_opt, 'where_is' => $display->frm_where_is[$where_key], 'where_val' => $where_val, 'form_id' => $display->frm_form_id, 'form_posts' => $form_posts, 'after_where' => $after_where, 'display' => $display, 'drafts' => $is_draft, 'use_ids' => $use_ids)); $entry_ids = FrmProAppHelper::filter_where($entry_ids, $filter_opts); unset($filter_opts); $after_where = true; $continue = false; if (empty($entry_ids)) { break; } } else { if (in_array($where_opt, array('created_at', 'updated_at'))) { if ($where_val == 'NOW') { $where_val = current_time('mysql', 1); } if (strpos($display->frm_where_is[$where_key], 'LIKE') === false) { $where_val = date('Y-m-d H:i:s', strtotime($where_val)); // If using less than or equal to, set the time to the end of the day if ($display->frm_where_is[$where_key] == '<=') { $where_val = str_replace('00:00:00', '23:59:59', $where_val); } // Convert date to GMT since that is the format in the DB $where_val = get_gmt_from_date($where_val); } $where['it.' . sanitize_title($where_opt) . FrmDb::append_where_is($display->frm_where_is[$where_key])] = $where_val; $continue = true; } else { if (in_array($where_opt, array('id', 'item_key', 'post_id', 'ip'))) { $where['it.' . sanitize_title($where_opt) . FrmDb::append_where_is($display->frm_where_is[$where_key])] = $where_val; // Update entry IDs if the entry ID filter is set to "equal to" if ($where_opt == 'id' && in_array($display->frm_where_is[$where_key], array('=', ' in '))) { $entry_ids = $where_val; } $continue = true; } } } } if (!$continue && empty($entry_ids)) { if ($display->frm_insert_loc == 'after') { $content .= $empty_msg; } else { if ($display->frm_insert_loc == 'before') { $content = $empty_msg . $content; } else { if ($filter) { $empty_msg = apply_filters('the_content', $empty_msg); } if ($post && $post->post_type == self::$post_type && in_the_loop()) { $content = ''; } $content .= $empty_msg; } } return $content; } } if ($user_id && is_numeric($user_id) && !$uid_used) { $where['it.user_id'] = $user_id; } $s = FrmAppHelper::get_param('frm_search', false, 'get', 'sanitize_text_field'); if ($s) { $new_ids = FrmProEntriesHelper::get_search_ids($s, $display->frm_form_id, array('is_draft' => $extra_atts['drafts'])); if ($after_where && isset($entry_ids) && !empty($entry_ids)) { $entry_ids = array_intersect($new_ids, $entry_ids); } else { $entry_ids = $new_ids; } if (empty($entry_ids)) { if ($post->post_type == self::$post_type && in_the_loop()) { $content = ''; } return $content . ' ' . $empty_msg; } } if (isset($entry_ids) && !empty($entry_ids)) { $where['it.id'] = $entry_ids; } self::maybe_add_entry_query($entry_id, $where); if ($extra_atts['drafts'] != 'both') { $where['is_draft'] = $is_draft; } unset($is_draft); if ($show == 'one') { $limit = ' LIMIT 1'; } else { self::maybe_add_cat_query($where); } if (!empty($limit) && is_numeric($limit)) { $display->frm_limit = (int) $limit; } if (is_numeric($display->frm_limit)) { $num_limit = (int) $display->frm_limit; $limit = ' LIMIT ' . $display->frm_limit; } if (!empty($order_by)) { $display->frm_order_by = explode(',', $order_by); } if (!empty($order)) { $display->frm_order = explode(',', $order); if (!isset($display->frm_order_by[0])) { $display->frm_order_by = FrmProAppHelper::reset_keys($display->frm_order_by); } } unset($order); if (!empty($page_size) && is_numeric($page_size)) { $display->frm_page_size = (int) $page_size; } // if limit is lower than page size, ignore the page size if (isset($num_limit) && $display->frm_page_size > $num_limit) { $display->frm_page_size = ''; } $display_page_query = array('order_by_array' => $display->frm_order_by, 'order_array' => $display->frm_order, 'posts' => $form_posts, 'display' => $display); if (isset($display->frm_page_size) && is_numeric($display->frm_page_size)) { $page_param = $_GET && isset($_GET['frm-page-' . $display->ID]) ? 'frm-page-' . $display->ID : 'frm-page'; $current_page = FrmAppHelper::simple_get($page_param, 'absint', 1); $record_count = FrmEntry::getRecordCount($where); if (isset($num_limit) && $record_count > (int) $num_limit) { $record_count = (int) $num_limit; } $page_count = FrmEntry::getPageCount($display->frm_page_size, $record_count); $entry_ids = FrmProEntry::get_view_page($current_page, $display->frm_page_size, $where, $display_page_query); $page_last_record = FrmAppHelper::get_last_record_num($record_count, $current_page, $display->frm_page_size); $page_first_record = FrmAppHelper::get_first_record_num($record_count, $current_page, $display->frm_page_size); if ($page_count > 1) { $page_param = 'frm-page-' . $display->ID; $pagination = FrmAppHelper::get_file_contents(FrmAppHelper::plugin_path() . '/pro/classes/views/displays/pagination.php', compact('current_page', 'record_count', 'page_count', 'page_last_record', 'page_first_record', 'page_param')); } } else { $display_page_query['limit'] = $limit; //Get all entries $entry_ids = FrmProEntry::get_view_results($where, $display_page_query); } $total_count = count($entry_ids); $sc_atts = array(); if (isset($record_count)) { $sc_atts['record_count'] = $record_count; } else { $sc_atts['record_count'] = $total_count; } $display_content = ''; if (isset($message)) { // if an entry was deleted above, show a message $display_content .= $message; } if ($show == 'all') { $display_content .= isset($display->frm_before_content) ? $display->frm_before_content : ''; } add_filter('frm_before_display_content', 'FrmProDisplaysController::calendar_header', 10, 3); add_filter('frm_before_display_content', 'FrmProDisplaysController::filter_after_content', 10, 4); $display_content = apply_filters('frm_before_display_content', $display_content, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids)); add_filter('frm_display_entries_content', 'FrmProDisplaysController::build_calendar', 10, 5); $filtered_content = apply_filters('frm_display_entries_content', $new_content, $entry_ids, $shortcodes, $display, $show, $sc_atts); if ($filtered_content != $new_content) { $display_content .= $filtered_content; } else { $odd = 'odd'; $count = 0; if (!empty($entry_ids)) { $loop_entry_ids = $entry_ids; while ($next_set = array_splice($loop_entry_ids, 0, 30)) { $entries = FrmEntry::getAll(array('id' => $next_set), ' ORDER BY FIELD(it.id,' . implode(',', $next_set) . ')', '', true, false); foreach ($entries as $entry) { $count++; //TODO: use the count with conditionals $display_content .= apply_filters('frm_display_entry_content', $new_content, $entry, $shortcodes, $display, $show, $odd, array('count' => $count, 'total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'pagination' => $pagination, 'entry_ids' => $entry_ids)); $odd = $odd == 'odd' ? 'even' : 'odd'; unset($entry); } unset($entries); } unset($loop_entry_ids, $count); } else { if ($post && $post->post_type == self::$post_type && in_the_loop()) { $display_content = ''; } if (!isset($message) || FrmAppHelper::get_param('frm_action', '', 'get', 'sanitize_title') != 'destroy') { $display_content .= $empty_msg; } } } if (isset($message)) { unset($message); } if ($show == 'all' && isset($display->frm_after_content)) { add_filter('frm_after_content', 'FrmProDisplaysController::filter_after_content', 10, 4); $display_content .= apply_filters('frm_after_content', $display->frm_after_content, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids)); } if (!isset($sc_atts)) { $sc_atts = array('record_count' => 0); } if (!isset($total_count)) { $total_count = 0; } $pagination = self::calendar_footer($pagination, $display, $show); $display_content .= apply_filters('frm_after_display_content', $pagination, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids)); unset($sc_atts); $display_content = FrmProFieldsHelper::get_default_value($display_content, false, true, false); if ($display->frm_insert_loc == 'after') { $content .= $display_content; } else { if ($display->frm_insert_loc == 'before') { $content = $display_content . $content; } else { if ($filter) { $display_content = apply_filters('the_content', $display_content); } $content = $display_content; } } // load the styling for css classes and pagination FrmStylesController::enqueue_style(); return $content; }