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;
 }
 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;
 }
    public static function get_child_checkboxes($args)
    {
        $defaults = array('field' => 0, 'field_name' => false, 'opt_key' => 0, 'opt' => '', 'type' => 'checkbox', 'value' => false, 'exclude' => 0, 'hide_id' => false, 'tax_num' => 0);
        $args = wp_parse_args($args, $defaults);
        if (!$args['field'] || !isset($args['field']['post_field']) || $args['field']['post_field'] != 'post_category') {
            return;
        }
        if (!$args['value']) {
            $args['value'] = isset($args['field']['value']) ? $args['field']['value'] : '';
        }
        if (!$args['exclude']) {
            $args['exclude'] = is_array($args['field']['exclude_cat']) ? implode(',', $args['field']['exclude_cat']) : $args['field']['exclude_cat'];
            $args['exclude'] = apply_filters('frm_exclude_cats', $args['exclude'], $args['field']);
        }
        if (!$args['field_name']) {
            $args['field_name'] = 'item_meta[' . $args['field']['id'] . ']';
        }
        if ($args['type'] == 'checkbox') {
            $args['field_name'] .= '[]';
        }
        $post_type = FrmProFormsHelper::post_type($args['field']['form_id']);
        $taxonomy = 'category';
        $cat_atts = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false, 'parent' => $args['opt_key'], 'exclude' => $args['exclude'], 'type' => $post_type);
        if (!$args['opt_key']) {
            $cat_atts['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $args['field']);
            if (!$cat_atts['taxonomy']) {
                echo '<p>' . __('No Categories', 'formidable') . '</p>';
                return;
            }
            $taxonomy = $cat_atts['taxonomy'];
        }
        $children = get_categories($cat_atts);
        unset($cat_atts);
        $level = $args['opt_key'] ? 2 : 1;
        foreach ($children as $key => $cat) {
            ?>
    	<div class="frm_catlevel_<?php 
            echo (int) $level;
            ?>
"><?php 
            self::_show_category(array('cat' => $cat, 'field' => $args['field'], 'field_name' => $args['field_name'], 'exclude' => $args['exclude'], 'type' => $args['type'], 'value' => $args['value'], 'level' => $level, 'onchange' => '', 'post_type' => $post_type, 'taxonomy' => $taxonomy, 'hide_id' => $args['hide_id'], 'tax_num' => $args['tax_num']));
            ?>
</div>
<?php 
        }
    }
Example #4
0
    function get_child_checkboxes($args)
    {
        $defaults = array('field' => 0, 'field_name' => false, 'opt_key' => 0, 'opt' => '', 'type' => 'checkbox', 'value' => false, 'exclude' => 0, 'hide_id' => false);
        extract(wp_parse_args($args, $defaults));
        if (!$field or !isset($field['post_field']) or $field['post_field'] != 'post_category') {
            return;
        }
        if (!$value) {
            $value = isset($field['value']) ? $field['value'] : '';
        }
        if (!$exclude) {
            $exclude = is_array($field['exclude_cat']) ? implode(',', $field['exclude_cat']) : $field['exclude_cat'];
        }
        if (!$field_name) {
            $field_name = "item_meta[{$field['id']}]";
        }
        if ($type == 'checkbox') {
            $field_name .= '[]';
            $onchange = ' onchange="frmCheckParents(this.id)"';
        } else {
            $onchange = '';
        }
        $post_type = FrmProForm::post_type($field['form_id']);
        $taxonomy = 'category';
        $args = array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false, 'parent' => $opt_key, 'exclude' => $exclude, 'type' => $post_type);
        if (!$opt_key and function_exists('get_object_taxonomies')) {
            $args['taxonomy'] = FrmProAppHelper::get_custom_taxonomy($post_type, $field);
            if (!$args['taxonomy']) {
                echo '<p>' . __('No Categories', 'formidable') . '</p>';
                return;
            }
            $taxonomy = $args['taxonomy'];
        }
        $children = get_categories($args);
        $level = $opt_key ? 2 : 1;
        foreach ($children as $key => $cat) {
            ?>
 	    
    	<div class="frm_catlevel_<?php 
            echo $level;
            ?>
"><?php 
            FrmProFieldsHelper::_show_category(compact('cat', 'field', 'field_name', 'exclude', 'type', 'value', 'exclude', 'level', 'onchange', 'post_type', 'taxonomy', 'hide_id'));
            ?>
</div>
<?php 
        }
    }
 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;
 }
 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);
 }
 /**
  * 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();
     }
 }
Example #8
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;
 }
Example #9
0
 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;
 }
 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;
 }