Ejemplo n.º 1
0
 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';
 }
Ejemplo n.º 2
0
 /**
  * @param integer $form_id
  */
 public static function include_new_field($field_type, $form_id)
 {
     $values = array();
     if (FrmAppHelper::pro_is_installed()) {
         $values['post_type'] = FrmProFormsHelper::post_type($form_id);
     }
     $field_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars($field_type, $form_id));
     $field_id = FrmField::create($field_values);
     if (!$field_id) {
         return false;
     }
     $field = self::include_single_field($field_id, $values, $form_id);
     return $field;
 }
Ejemplo n.º 3
0
 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';
 }
Ejemplo n.º 4
0
 public static function create()
 {
     $field_data = $_POST['field'];
     $form_id = $_POST['form_id'];
     $values = array();
     if (class_exists('FrmProForm')) {
         $values['post_type'] = FrmProFormsHelper::post_type($form_id);
     }
     $field_values = apply_filters('frm_before_field_created', FrmFieldsHelper::setup_new_vars($field_data, $form_id));
     $frm_field = new FrmField();
     $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 FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php';
     }
     die;
 }
Ejemplo n.º 5
0
 function create_post($entry_id, $form_id)
 {
     if (!isset($_POST['frm_wp_post'])) {
         return;
     }
     global $wpdb, $frmdb, $frmpro_display;
     $post_id = NULL;
     $post = array('post_type' => FrmProFormsHelper::post_type($form_id));
     if (isset($_POST['frm_user_id']) && 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($wpdb->prefix . 'frm_forms', array('id' => $form_id), 'options');
         $form_options = maybe_unserialize($form_options);
         if (isset($form_options['post_status']) && $form_options['post_status'] == 'publish') {
             $post['post_status'] = 'publish';
         }
     }
     //check for auto view and set frm_display_id
     $display = $frmpro_display->get_auto_custom_display(compact('form_id', 'entry_id'));
     if ($display) {
         $_POST['frm_wp_post_custom']['=frm_display_id'] = $display->ID;
     }
     $post_id = $this->insert_post($entry_id, $post, false, $form_id);
 }
Ejemplo n.º 6
0
 public static 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 = isset($field_options['taxonomy']) ? $field_options['taxonomy'] : 'frm_tag';
             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, $tax)) . '" 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 = FrmProFormsHelper::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, $taxonomy)) . '" 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;
 }
Ejemplo n.º 7
0
 public static function dropdown_categories($args)
 {
     $defaults = array('field' => false, 'name' => false, 'show_option_all' => ' ');
     $args = wp_parse_args($args, $defaults);
     if (!$args['field']) {
         return;
     }
     if (!$args['name']) {
         $args['name'] = 'item_meta[' . $args['field']['id'] . ']';
     }
     $id = self::get_html_id($args['field']);
     $class = $args['field']['type'];
     $exclude = is_array($args['field']['exclude_cat']) ? implode(',', $args['field']['exclude_cat']) : $args['field']['exclude_cat'];
     $exclude = apply_filters('frm_exclude_cats', $exclude, $args['field']);
     if (is_array($args['field']['value'])) {
         if (!empty($exclude)) {
             $args['field']['value'] = array_diff($args['field']['value'], explode(',', $exclude));
         }
         $selected = reset($args['field']['value']);
     } else {
         $selected = $args['field']['value'];
     }
     $tax_atts = array('show_option_all' => $args['show_option_all'], 'hierarchical' => 1, 'name' => $args['name'], 'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected, 'hide_empty' => false, 'echo' => 0, 'orderby' => 'name');
     $tax_atts = apply_filters('frm_dropdown_cat', $tax_atts, $args['field']);
     if (FrmAppHelper::pro_is_installed()) {
         $post_type = FrmProFormsHelper::post_type($args['field']['form_id']);
         $tax_atts['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $args['field']);
         if (!$tax_atts['taxonomy']) {
             return;
         }
         // If field type is dropdown (not Dynamic), exclude children when parent is excluded
         if ($args['field']['type'] != 'data' && is_taxonomy_hierarchical($tax_atts['taxonomy'])) {
             $tax_atts['exclude_tree'] = $exclude;
         }
     }
     $dropdown = wp_dropdown_categories($tax_atts);
     $add_html = FrmFieldsController::input_html($args['field'], false);
     if (FrmAppHelper::pro_is_installed()) {
         $add_html .= FrmProFieldsController::input_html($args['field'], false);
     }
     $dropdown = str_replace("<select name='" . esc_attr($args['name']) . "' id='" . esc_attr($id) . "' class='" . esc_attr($class) . "'", "<select name='" . esc_attr($args['name']) . "' id='" . esc_attr($id) . "' " . $add_html, $dropdown);
     if (is_array($args['field']['value'])) {
         $skip = true;
         foreach ($args['field']['value'] as $v) {
             if ($skip) {
                 $skip = false;
                 continue;
             }
             $dropdown = str_replace(' value="' . esc_attr($v) . '"', ' value="' . esc_attr($v) . '" selected="selected"', $dropdown);
             unset($v);
         }
     }
     return $dropdown;
 }
Ejemplo n.º 8
0
 public static function get_status_options($field, $options = array())
 {
     $post_type = FrmProFormsHelper::post_type($field->form_id);
     $post_type_object = get_post_type_object($post_type);
     if (!$post_type_object) {
         return $options;
     }
     $new_options = array();
     foreach ($options as $opt_key => $opt) {
         if (is_array($opt)) {
             $opt_key = isset($opt['value']) ? $opt['value'] : (isset($opt['label']) ? $opt['label'] : reset($opt));
         } else {
             $opt_key = $opt;
         }
         if (in_array($opt_key, array('publish', 'private'))) {
             $new_options[$opt_key] = $opt;
         }
     }
     if (!empty($new_options)) {
         return $new_options;
     }
     $can_publish = current_user_can($post_type_object->cap->publish_posts);
     $options = get_post_statuses();
     //'draft', pending, publish, private
     // Contributors only get "Unpublished" and "Pending Review"
     if (!$can_publish) {
         unset($options['publish']);
         if (isset($options['future'])) {
             unset($options['future']);
         }
     }
     return $options;
 }
Ejemplo n.º 9
0
 public static function get_status_options($field)
 {
     $post_type = FrmProFormsHelper::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;
 }
Ejemplo n.º 10
0
 public static function post_type($form_id)
 {
     _deprecated_function(__FUNCTION__, '1.07.05', 'FrmProFormsHelper::post_type');
     return FrmProFormsHelper::post_type($form_id);
 }
Ejemplo n.º 11
0
 public static function ajax_data_options()
 {
     $hide_field = FrmAppHelper::get_param('hide_field');
     $entry_id = FrmAppHelper::get_param('entry_id');
     $selected_field_id = FrmAppHelper::get_param('selected_field_id');
     $field_id = FrmAppHelper::get_param('field_id');
     global $frm_field;
     $data_field = $frm_field->getOne($selected_field_id);
     if ($entry_id == '') {
         die;
     }
     $entry_id = explode(',', $entry_id);
     $field_data = $frm_field->getOne($field_id);
     $field_name = "item_meta[{$field_id}]";
     if (isset($field_data->field_options['multiple']) and $field_data->field_options['multiple'] and ($field_data->type == 'select' or $field_data->type == 'data' and isset($field_data->field_options['data_type']) and $field_data->field_options['data_type'] == 'select')) {
         $field_name .= '[]';
     }
     $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' => $field_data->options, 'size' => isset($field_data->field_options['size']) && $field_data->field_options['size'] != '' ? $field_data->field_options['size'] : '', 'field_key' => $field_data->field_key);
     if ($field['size'] == '') {
         global $frm_vars;
         $field['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : '';
     }
     if (is_numeric($selected_field_id)) {
         $field['options'] = array();
         $metas = FrmProEntryMetaHelper::meta_through_join($hide_field, $data_field, $entry_id);
         $metas = stripslashes_deep($metas);
         if ($metas and (!isset($field_data->field_options['data_type']) or !in_array($field_data->field_options['data_type'], array('radio', 'checkbox'))) and (!isset($field_data->field_options['multiple']) or !$field_data->field_options['multiple'] or isset($field_data->field_options['autocom']) and $field_data->field_options['autocom'])) {
             $field['options'][''] = '';
         }
         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));
             unset($meta);
         }
         $field = apply_filters('frm_setup_new_fields_vars', $field, $field_data);
     } else {
         if ($selected_field_id == 'taxonomy') {
             if ($entry_id == 0) {
                 die;
             }
             if (is_array($entry_id)) {
                 $zero = array_search(0, $entry_id);
                 if ($zero !== false) {
                     unset($entry_id[$zero]);
                 }
                 if (empty($entry_id)) {
                     die;
                 }
             }
             $field = apply_filters('frm_setup_new_fields_vars', $field, $field_data);
             $cat_ids = array_keys($field['options']);
             $args = array('include' => implode(',', $cat_ids), 'hide_empty' => false);
             $post_type = FrmProFormsHelper::post_type($field_data->form_id);
             $args['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $field_data);
             if (!$args['taxonomy']) {
                 die;
             }
             $cats = get_categories($args);
             foreach ($cats as $cat) {
                 if (!in_array($cat->parent, (array) $entry_id)) {
                     unset($field['options'][$cat->term_id]);
                 }
             }
             if (count($field['options']) == 1 and reset($field['options']) == '') {
                 die;
             }
         } else {
             $field = apply_filters('frm_setup_new_fields_vars', $field, $field_data);
         }
     }
     $auto_width = isset($field['size']) && $field['size'] > 0 ? 'class="auto_width"' : '';
     require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/data-options.php';
     die;
 }
Ejemplo n.º 12
0
 /**
  * Get the options for a dependent Dynamic category field
  *
  * @since 2.0.16
  * @param array $args
  * @param array $field
  */
 private static function get_dependent_category_field_options($args, &$field)
 {
     if ($args['entry_id'] == 0) {
         wp_die();
     }
     if (is_array($args['entry_id'])) {
         $zero = array_search(0, $args['entry_id']);
         if ($zero !== false) {
             unset($args['entry_id'][$zero]);
         }
         if (empty($args['entry_id'])) {
             wp_die();
         }
     }
     $field = apply_filters('frm_setup_new_fields_vars', $field, $args['field_data']);
     $cat_ids = array_keys($field['options']);
     $cat_args = array('include' => implode(',', $cat_ids), 'hide_empty' => false);
     $post_type = FrmProFormsHelper::post_type($args['field_data']->form_id);
     $cat_args['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $args['field_data']);
     if (!$cat_args['taxonomy']) {
         wp_die();
     }
     $cats = get_categories($cat_args);
     foreach ($cats as $cat) {
         if (!in_array($cat->parent, (array) $args['entry_id'])) {
             unset($field['options'][$cat->term_id]);
         }
     }
     if (count($field['options']) == 1 && reset($field['options']) == '') {
         wp_die();
     }
 }
Ejemplo n.º 13
0
 public static function dropdown_categories($args)
 {
     global $frm_vars;
     $defaults = array('field' => false, 'name' => false, 'show_option_all' => ' ');
     extract(wp_parse_args($args, $defaults));
     if (!$field) {
         return;
     }
     if (!$name) {
         $name = "item_meta[{$field['id']}]";
     }
     $id = 'field_' . $field['field_key'];
     $class = $field['type'];
     $exclude = is_array($field['exclude_cat']) ? implode(',', $field['exclude_cat']) : $field['exclude_cat'];
     $exclude = apply_filters('frm_exclude_cats', $exclude, $field);
     if (is_array($field['value'])) {
         if (!empty($exclude)) {
             $field['value'] = array_diff($field['value'], explode(',', $exclude));
         }
         $selected = reset($field['value']);
     } else {
         $selected = $field['value'];
     }
     $args = array('show_option_all' => $show_option_all, 'hierarchical' => 1, 'name' => $name, 'id' => $id, 'exclude' => $exclude, 'class' => $class, 'selected' => $selected, 'hide_empty' => false, 'echo' => 0, 'orderby' => 'name');
     $args = apply_filters('frm_dropdown_cat', $args, $field);
     if (class_exists('FrmProFormsHelper')) {
         $post_type = FrmProFormsHelper::post_type($field['form_id']);
         $args['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $field);
         if (!$args['taxonomy']) {
             return;
         }
         if (is_taxonomy_hierarchical($args['taxonomy'])) {
             $args['exclude_tree'] = $exclude;
         }
     }
     $dropdown = wp_dropdown_categories($args);
     $add_html = FrmFieldsController::input_html($field, false);
     if ($frm_vars['pro_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);
     if (is_array($field['value'])) {
         $skip = true;
         foreach ($field['value'] as $v) {
             if ($skip) {
                 $skip = false;
                 continue;
             }
             $dropdown = str_replace(' value="' . $v . '"', ' value="' . $v . '" selected="selected"', $dropdown);
             unset($v);
         }
     }
     return $dropdown;
 }
Ejemplo n.º 14
0
 public static 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 = isset($field_options['taxonomy']) ? $field_options['taxonomy'] : 'frm_tag';
             if ($tags = get_the_terms($post_id, $tax)) {
                 $names = array();
                 foreach ($tags as $tag) {
                     self::get_term_with_link($tag, $tax, $names, $atts);
                 }
                 $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 = FrmProFormsHelper::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']) && in_array($cat->term_id, (array) $atts['exclude_cat'])) {
                             continue;
                         }
                         self::get_term_with_link($cat, $taxonomy, $names, $atts);
                         $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;
 }