function form($form_action, $args = array()) { global $wpdb; extract($args); $post_types = FrmProAppHelper::get_custom_post_types(); if (!$post_types) { return; } $post_type = FrmProFormsHelper::post_type($args['values']['id']); $taxonomies = get_object_taxonomies($post_type); $action_control = $this; $echo = true; $form_id = $form->id; $display = false; $displays = array(); $display_ids = FrmDb::get_col($wpdb->postmeta, array('meta_key' => 'frm_form_id', 'meta_value' => $form_id), 'post_ID'); if ($display_ids) { $query_args = array('pm.meta_key' => 'frm_show_count', 'post_type' => 'frm_display', 'pm.meta_value' => array('dynamic', 'calendar', 'one'), 'p.post_status' => array('publish', 'private'), 'p.ID' => $display_ids); $displays = FrmDb::get_results($wpdb->posts . ' p LEFT JOIN ' . $wpdb->postmeta . ' pm ON (p.ID = pm.post_ID)', $query_args, 'p.ID, p.post_title', array('order_by' => 'p.post_title ASC')); if (isset($form_action->post_content['display_id'])) { // get view from settings if (is_numeric($form_action->post_content['display_id'])) { $display = FrmProDisplay::getOne($form_action->post_content['display_id'], false, true); } } else { if (!is_numeric($form_action->post_content['post_content']) && !empty($display_ids)) { // get auto view $display = FrmProDisplay::get_form_custom_display($form_id); if ($display) { $display = FrmProDisplaysHelper::setup_edit_vars($display, true); } } } } // Get array of all custom fields $custom_fields = array(); if (isset($form_action->post_content['post_custom_fields'])) { foreach ($form_action->post_content['post_custom_fields'] as $custom_field_opts) { if (isset($custom_field_opts['meta_name'])) { $custom_fields[] = $custom_field_opts['meta_name']; } unset($custom_field_opts); } } unset($display_ids); include dirname(__FILE__) . '/post_options.php'; }
function get_content($content) { global $post, $frmpro_display; if (!$post) { return $content; } $display = $entry_id = false; if (is_single() or is_page()) { global $frmdb, $frmprodb; //get entry with post_id $entry = $frmdb->get_one_record($frmdb->entries, array('post_id' => $post->ID), $fields = 'id,item_key,form_id'); if ($entry) { $display = FrmProDisplay::getAll("form_id=" . $entry->form_id . " and show_count in ('single', 'dynamic', 'calendar')", '', ' LIMIT 1'); $entry_id = $entry->id; } } if (!$display) { $display = $frmpro_display->getAll("insert_loc != 'none' and post_id=" . $post->ID, '', ' LIMIT 1'); } if ($display) { global $frm_displayed, $frm_display_position; $display->options = maybe_unserialize($display->options); if (!isset($display->options['insert_pos'])) { $display->options['insert_pos'] = 1; } if (!$frm_displayed) { $frm_displayed = array(); } if (!$frm_display_position) { $frm_display_position = array(); } if (!isset($frm_display_position[$display->id])) { $frm_display_position[$display->id] = 0; } $frm_display_position[$display->id]++; //make sure this isn't loaded multiple times but still works with themes and plugins that call the_content multiple times if (in_the_loop() and !in_array($display->id, (array) $frm_displayed) and $frm_display_position[$display->id] >= (int) $display->options['insert_pos']) { $entry_id = (in_array($display->show_count, array('dynamic', 'calendar')) and $display->type == 'display_key') ? $entry_id ? $entry->item_key : $entry_id : $entry_id; $frm_displayed[] = $display->id; $content = $this->get_display_data($display, $content, $entry_id); } } return $content; }
public static function create_post_entry($id = false, $post_id = false) { if (FrmAppHelper::doing_ajax()) { check_ajax_referer('frm_ajax', 'nonce'); } if (!$id) { $id = (int) $_POST['id']; } if (!$post_id) { $post_id = (int) $_POST['post_id']; } if (!is_numeric($id) || !is_numeric($post_id)) { return; } $post = get_post($post_id); global $wpdb; $values = array('description' => __('Copied from Post', 'formidable'), 'form_id' => $id, 'created_at' => $post->post_date_gmt, 'name' => $post->post_title, 'item_key' => FrmAppHelper::get_unique_key($post->post_name, $wpdb->prefix . 'frm_items', 'item_key'), 'user_id' => $post->post_author, 'post_id' => $post->ID); $results = $wpdb->insert($wpdb->prefix . 'frm_items', $values); unset($values); if (!$results) { wp_die(); } $entry_id = $wpdb->insert_id; $user_id_field = FrmField::get_all_types_in_form($id, 'user_id', 1); if ($user_id_field) { $new_values = array('meta_value' => $post->post_author, 'item_id' => $entry_id, 'field_id' => $user_id_field->id, 'created_at' => current_time('mysql', 1)); $wpdb->insert($wpdb->prefix . 'frm_item_metas', $new_values); } $display = FrmProDisplay::get_auto_custom_display(array('form_id' => $id, 'entry_id' => $entry_id)); if ($display) { update_post_meta($post->ID, 'frm_display_id', $display->ID); } wp_die(); }
private static function popup_opts_display_frm_data(array &$opts, $shortcode) { //'entry_id' => '', 'user_id' => false, 'order' => '', $displays = FrmProDisplay::getAll(array(), 'post_title'); ?> <h4 for="frmsc_<?php echo esc_attr($shortcode); ?> _id" class="frm_left_label"><?php _e('Select a view:', 'formidable'); ?> </h4> <select id="frmsc_<?php echo esc_attr($shortcode); ?> _id"> <option value=""> </option> <?php foreach ($displays as $display) { ?> <option value="<?php echo esc_attr($display->ID); ?> "><?php echo esc_html($display->post_title); ?> </option> <?php } ?> </select> <div class="frm_box_line"></div> <?php $opts = array('filter' => array('val' => 1, 'label' => __('Filter shortcodes within the view content', 'formidable')), 'drafts' => array('val' => 0, 'label' => __('Entry type(s)', 'formidable'), 'type' => 'select', 'opts' => array('0' => __('Published', 'formidable'), '1' => __('Drafts', 'formidable'), 'both' => __('Published and drafts', 'formidable'))), 'limit' => array('val' => '', 'label' => __('Limit', 'formidable'), 'type' => 'text'), 'page_size' => array('val' => '', 'label' => __('Page size', 'formidable'), 'type' => 'text'), 'order' => array('val' => '', 'label' => __('Entry order', 'formidable'), 'type' => 'select', 'opts' => array('' => __('Default', 'formidable'), 'ASC' => __('Ascending', 'formidable'), 'DESC' => __('Descending', 'formidable')))); }
/** * Copy forms that are set to copy from one site to another */ private static function copy_forms($force) { if (!$force) { //don't check on every page load $last_checked = get_option('frmpro_copies_checked'); if (!$last_checked || time() - $last_checked >= 60 * 60) { //check every hour $force = true; } } if (!$force) { return; } global $wpdb, $blog_id; //get all forms to be copied from global table $query = $wpdb->prepare('SELECT c.*, p.post_name FROM ' . self::table_name() . ' c LEFT JOIN ' . $wpdb->prefix . 'frm_forms f ON (c.copy_key = f.form_key) LEFT JOIN ' . $wpdb->posts . ' p ON (c.copy_key = p.post_name) WHERE blog_id != %d AND ((type = %s AND f.form_key is NULL) OR (type = %s AND p.post_name is NULL)) ORDER BY type DESC', $blog_id, 'form', 'display'); $templates = FrmAppHelper::check_cache('all_templates_' . $blog_id, 'frm_copy', $query, 'get_results'); foreach ($templates as $temp) { if ($temp->type == 'form') { FrmForm::duplicate($temp->form_id, false, true, $temp->blog_id); continue; } $values = FrmProDisplay::getOne($temp->form_id, $temp->blog_id, true); if (!$values || 'trash' == $values->post_status) { continue; } // check if post with slug already exists $post_name = wp_unique_post_slug($values->post_name, 0, 'publish', 'frm_display', 0); if ($post_name != $values->post_name) { continue; } if ($values->post_name != $temp->copy_key) { $wpdb->update(self::table_name(), array('copy_key' => $values->post_name), array('id' => $temp->id)); } FrmProDisplay::duplicate($temp->form_id, true, $temp->blog_id); //TODO: replace any ids with field keys in the display before duplicated unset($temp); } update_option('frmpro_copies_checked', time()); }
/** * Migrate displays table into wp_posts */ private static function migrate_to_16() { global $wpdb; $display_posts = array(); if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}frm_display'")) { //only migrate if table exists $dis = FrmDb::get_results('frm_display'); } else { $dis = array(); } foreach ($dis as $d) { $post = array('post_title' => $d->name, 'post_content' => $d->content, 'post_date' => $d->created_at, 'post_excerpt' => $d->description, 'post_name' => $d->display_key, 'post_status' => 'publish', 'post_type' => 'frm_display'); $post_ID = wp_insert_post($post); unset($post); update_post_meta($post_ID, 'frm_old_id', $d->id); if (!isset($d->show_count) || empty($d->show_count)) { $d->show_count = 'none'; } foreach (array('dyncontent', 'param', 'form_id', 'post_id', 'entry_id', 'param', 'type', 'show_count', 'insert_loc') as $f) { update_post_meta($post_ID, 'frm_' . $f, $d->{$f}); unset($f); } $d->options = maybe_unserialize($d->options); update_post_meta($post_ID, 'frm_options', $d->options); if (isset($d->options['insert_loc']) && $d->options['insert_loc'] != 'none' && is_numeric($d->options['post_id']) && !isset($display_posts[$d->options['post_id']])) { $display_posts[$d->options['post_id']] = $post_ID; } unset($d, $post_ID); } unset($dis); //get all post_ids from frm_entries $entry_posts = FrmDb::get_results($wpdb->prefix . 'frm_items', array('post_id >' => 1), 'id, post_id, form_id'); $form_display = array(); foreach ($entry_posts as $ep) { if (isset($form_display[$ep->form_id])) { $display_posts[$ep->post_id] = $form_display[$ep->form_id]; } else { $d = FrmProDisplay::get_auto_custom_display(array('post_id' => $ep->post_id, 'form_id' => $ep->form_id, 'entry_id' => $ep->id)); $display_posts[$ep->post_id] = $form_display[$ep->form_id] = $d ? $d->ID : 0; unset($d); } unset($ep); } unset($form_display); foreach ($display_posts as $post_ID => $d) { if ($d) { update_post_meta($post_ID, 'frm_display_id', $d); } unset($d, $post_ID); } unset($display_posts); }
public static function post_options($values) { $post_types = FrmProAppHelper::get_custom_post_types(); if (!$post_types) { return; } $post_type = FrmProFormsHelper::post_type($values); $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::get_form_custom_display($form_id); if ($display) { $display = FrmProDisplaysHelper::setup_edit_vars($display, true); } require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-forms/post_options.php'; }
/** * Override the post content and date format */ private static function post_value_overrides(&$post, $new_post, $editing, $form, $entry, &$dyn_content) { //if empty post content and auto display, then save compiled post content $display_id = $editing ? get_post_meta($post['ID'], 'frm_display_id', true) : (isset($new_post['post_custom']['frm_display_id']) ? $new_post['post_custom']['frm_display_id'] : 0); if (!isset($post['post_content']) && $display_id) { $display = FrmProDisplay::getOne($display_id, false, true); if ($display) { $dyn_content = 'one' == $display->frm_show_count ? $display->post_content : $display->frm_dyncontent; $post['post_content'] = apply_filters('frm_content', $dyn_content, $form, $entry); } } if (isset($post['post_date']) && !empty($post['post_date']) && (!isset($post['post_date_gmt']) || $post['post_date_gmt'] == '0000-00-00 00:00:00')) { // set post date gmt if post date is set $post['post_date_gmt'] = get_gmt_from_date($post['post_date']); } }
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'; }
function form($instance) { $pages = get_posts(array('post_type' => 'page', 'post_status' => 'publish', 'numberposts' => 999, 'order_by' => 'post_title', 'order' => 'ASC')); $displays = FrmProDisplay::getAll(array('meta_key' => 'frm_show_count', 'meta_value' => 'dynamic')); //Defaults $instance = wp_parse_args((array) $instance, array('title' => false, 'display_id' => false, 'post_id' => false, 'title_id' => false, 'cat_list' => false, 'cat_name' => false, 'cat_count' => false, 'cat_id' => false, 'limit' => false)); if ($instance['display_id']) { $selected_display = FrmProDisplay::getOne($instance['display_id']); if ($selected_display) { $selected_form_id = get_post_meta($selected_display->ID, 'frm_form_id', true); $title_opts = FrmField::getAll(array('fi.form_id' => (int) $selected_form_id, 'type not' => FrmField::no_save_fields()), 'field_order'); $instance['display_id'] = $selected_display->ID; } } ?> <p><label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title', 'formidable'); ?> :</label> <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " value="<?php echo esc_attr(stripslashes($instance['title'])); ?> " /></p> <p><label for="<?php echo $this->get_field_id('display_id'); ?> "><?php _e('Use Settings from View', 'formidable'); ?> :</label> <select name="<?php echo $this->get_field_name('display_id'); ?> " id="<?php echo $this->get_field_id('display_id'); ?> " class="widefat frm_list_items_display_id"> <option value=""> </option> <?php foreach ($displays as $display) { echo '<option value="' . esc_attr($display->ID) . '" ' . selected($instance['display_id'], $display->ID, false) . '>' . FrmAppHelper::kses($display->post_title) . '</option>'; } ?> </select> </p> <p class="description"><?php _e('Views with a "Both (Dynamic)" format will show here.', 'formidable'); ?> </p> <p><label for="<?php echo $this->get_field_id('post_id'); ?> "><?php _e('Page if not specified in View settings', 'formidable'); ?> :</label> <select name="<?php echo $this->get_field_name('post_id'); ?> " id="<?php echo $this->get_field_id('post_id'); ?> " class="widefat"> <option value=""> </option> <?php foreach ($pages as $page) { echo '<option value="' . esc_attr($page->ID) . '" ' . selected($instance['post_id'], $page->ID, false) . '>' . $page->post_title . '</option>'; } ?> </select> </p> <p><label for="<?php echo $this->get_field_id('title_id'); ?> "><?php _e('Title Field', 'formidable'); ?> :</label> <select name="<?php echo $this->get_field_name('title_id'); ?> " id="<?php echo $this->get_field_id('title_id'); ?> " class="widefat frm_list_items_title_id"> <option value=""> </option> <?php if (isset($title_opts) && $title_opts) { foreach ($title_opts as $title_opt) { if ($title_opt->type != 'checkbox') { ?> <option value="<?php echo $title_opt->id; ?> " <?php selected($instance['title_id'], $title_opt->id); ?> ><?php echo $title_opt->name; ?> </option> <?php } } } ?> </select> </p> <p><label for="<?php echo $this->get_field_id('cat_list'); ?> "><input class="checkbox frm_list_items_cat_list" type="checkbox" <?php checked($instance['cat_list'], true); ?> id="<?php echo $this->get_field_id('cat_list'); ?> " name="<?php echo $this->get_field_name('cat_list'); ?> " value="1" /> <?php _e('List Entries by Category', 'formidable'); ?> </label></p> <div id="<?php echo $this->get_field_id('hide_cat_opts'); ?> " class="frm_list_items_hide_cat_opts <?php echo $instance['cat_list'] ? '' : 'frm_hidden'; ?> "> <p><label for="<?php echo $this->get_field_id('cat_id'); ?> "><?php _e('Category Field', 'formidable'); ?> :</label> <select name="<?php echo $this->get_field_name('cat_id'); ?> " id="<?php echo $this->get_field_id('cat_id'); ?> " class="widefat frm_list_items_cat_id"> <option value=""> </option> <?php if (isset($title_opts) && $title_opts) { foreach ($title_opts as $title_opt) { if (in_array($title_opt->type, array('select', 'radio', 'checkbox'))) { echo '<option value="' . esc_attr($title_opt->id) . '"' . selected($instance['cat_id'], $title_opt->id, false) . '>' . FrmAppHelper::kses($title_opt->name) . '</option>'; } } } ?> </select> </p> <p><label for="<?php echo $this->get_field_id('cat_count'); ?> "><input class="checkbox" type="checkbox" <?php checked($instance['cat_count'], true); ?> id="<?php echo $this->get_field_id('cat_count'); ?> " name="<?php echo $this->get_field_name('cat_count'); ?> " value="1" /> <?php _e('Show Entry Counts', 'formidable'); ?> </label></p> <p><input class="checkbox" type="radio" <?php checked($instance['cat_name'], 1); ?> id="<?php echo $this->get_field_id('cat_name'); ?> " name="<?php echo $this->get_field_name('cat_name'); ?> " value="1" /> <label for="<?php echo $this->get_field_id('cat_name'); ?> "><?php _e('Show Only Category Name', 'formidable'); ?> </label><br/> <input class="checkbox" type="radio" <?php checked($instance['cat_name'], 0); ?> id="<?php echo $this->get_field_id('cat_name'); ?> " name="<?php echo $this->get_field_name('cat_name'); ?> " value="0" /> <label for="<?php echo $this->get_field_id('cat_name'); ?> "><?php _e('Show Entries Beneath Categories', 'formidable'); ?> </label></p> </div> <p><label for="<?php echo $this->get_field_id('limit'); ?> "><?php _e('Entry Limit (leave blank to list all)', 'formidable'); ?> :</label> <input type="text" class="widefat" id="<?php echo $this->get_field_id('limit'); ?> " name="<?php echo $this->get_field_name('limit'); ?> " value="<?php echo esc_attr($instance['limit']); ?> " /></p> <?php }
public static function get_post_content() { check_ajax_referer('frm_ajax', 'nonce'); $id = (int) $_POST['id']; $display = FrmProDisplay::getOne($id, false, true); if ('one' == $display->frm_show_count) { echo $display->post_content; } else { echo $display->frm_dyncontent; } wp_die(); }