Example #1
0
/**
 * Form data for post edit page.
 *
 * @param type $field
 */
function wpcf_fields_skype_meta_box_form($field)
{
    add_thickbox();
    if (isset($field['value'])) {
        $field['value'] = maybe_unserialize($field['value']);
    }
    $form = array();
    add_filter('wpcf_fields_shortcode_slug_' . $field['slug'], 'wpcf_fields_skype_shortcode_filter', 10, 2);
    $rand = wpcf_unique_id(serialize($field));
    $form['skypename'] = array('#type' => 'textfield', '#value' => isset($field['value']['skypename']) ? $field['value']['skypename'] : '', '#name' => 'wpcf[' . $field['slug'] . '][skypename]', '#id' => 'wpcf-fields-skype-' . $field['slug'] . '-' . $rand . '-skypename', '#inline' => true, '#suffix' => '&nbsp;' . __('Skype name', 'wpcf'), '#description' => '', '#prefix' => !empty($field['description']) ? wpcf_translate('field ' . $field['id'] . ' description', $field['description']) . '<br /><br />' : '', '#attributes' => array('style' => 'width:60%;'), '#_validate_this' => true, '#before' => '<div class="wpcf-skype">');
    $form['style'] = array('#type' => 'hidden', '#value' => isset($field['value']['style']) ? $field['value']['style'] : 'btn2', '#name' => 'wpcf[' . $field['slug'] . '][style]', '#id' => 'wpcf-fields-skype-' . $field['slug'] . '-' . $rand . '-style');
    $preview_skypename = !empty($field['value']['skypename']) ? $field['value']['skypename'] : '--not--';
    $preview_style = !empty($field['value']['style']) ? $field['value']['style'] : 'btn2';
    $preview = wpcf_fields_skype_get_button_image($preview_skypename, $preview_style);
    // Set button
    // TODO WPML move
    if (isset($field['disable']) || wpcf_wpml_field_is_copied($field)) {
        $edit_button = '';
    } else {
        $edit_button = '' . '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=insert_skype_button&amp;_wpnonce=' . wp_create_nonce('insert_skype_button') . '&amp;update=wpcf-fields-skype-' . $field['slug'] . '-' . $rand . '&amp;skypename=' . $preview_skypename . '&amp;button_style=' . $preview_style . '&amp;keepThis=true&amp;TB_iframe=true&amp;width=500&amp;height=500') . '"' . ' class="thickbox wpcf-fields-skype button-secondary"' . ' title="' . __('Edit Skype button', 'wpcf') . '"' . '>' . __('Edit Skype button', 'wpcf') . '</a>';
    }
    $form['markup'] = array('#type' => 'markup', '#markup' => '<div class="wpcf-form-item">' . '<div id="wpcf-fields-skype-' . $field['slug'] . '-' . $rand . '-preview">' . $preview . '</div>' . $edit_button . '</div>');
    $form['markup-close'] = array('#type' => 'markup', '#markup' => '</div>');
    return $form;
}
Example #2
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_select_view($params)
{
    $field = wpcf_fields_get_field_by_slug($params['field']['slug']);
    $output = '';
    if (!empty($field['data']['options'])) {
        $field_value = $params['field_value'];
        foreach ($field['data']['options'] as $option_key => $option) {
            if (isset($option['value']) && $option['value'] == $params['field_value']) {
                $field_value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option_key . ' title', $option['title']);
            }
        }
        $output = $field_value;
    }
    return $output;
}
 /** ************************************************************************
  * Recommended. This method is called when the parent class can't find a method
  * specifically build for a given column. Generally, it's recommended to include
  * one method for each column you want to render, keeping your package class
  * neat and organized. For example, if the class needs to process a column
  * named 'title', it would first see if a method named $this->column_title()
  * exists - if it does, that method will be used. If it doesn't, this one will
  * be used. Generally, you should try to use custom column methods as much as
  * possible.
  *
  * Since we have defined a column_title() method later on, this method doesn't
  * need to concern itself with any column with a name of 'title'. Instead, it
  * needs to handle everything else.
  *
  * For more detailed insight into how columns are handled, take a look at
  * WP_List_Table::single_row_columns()
  *
  * @param array $item A singular item (one full row's worth of data)
  * @param array $column_name The name/slug of the column to be processed
  * @return string Text or HTML to be placed inside the column <td>
  **************************************************************************/
 function column_default($item, $column_name)
 {
     switch ($column_name) {
         case 'title':
         case 'description':
             return stripslashes($item[$column_name]);
         case 'supports':
             $rows = array();
             if (!empty($item[$column_name])) {
                 foreach ($item[$column_name] as $temp_post_type => $true) {
                     $rows[] = stripslashes(wpcf_translate($temp_post_type . ' name', $temp_post_type, 'Types-CPT'));
                 }
             }
             return empty($rows) ? __('None', 'wpcf') : implode(', ', $rows);
         case 'status':
             return 'active' == $item[$column_name] ? __('Yes', 'wpcf') : __('No', 'wpcf');
         default:
             return print_r($item, true);
             //Show the whole array for troubleshooting purposes
     }
 }
Example #4
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_select_view($params)
{
    if (isset($params['usermeta']) && !empty($params['usermeta'])) {
        $field = wpcf_fields_get_field_by_slug($params['field']['slug'], 'wpcf-usermeta');
    } else {
        $field = wpcf_fields_get_field_by_slug($params['field']['slug']);
    }
    $output = '';
    if (!empty($field['data']['options'])) {
        $field_value = $params['field_value'];
        foreach ($field['data']['options'] as $option_key => $option) {
            if (isset($option['value']) && $option['value'] == $params['field_value']) {
                // We need to translate here because the stored value is on the original language
                // When updaing the value in the Field group, we might have problems
                $field_value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option_key . ' title', $option['title']);
            }
        }
        $output = $field_value;
    }
    return $output;
}
/**
 * HTML formatted output for 'Delete Field'.
 * 
 * @param type $field
 * @param type $post
 * @return string 
 */
function wpcf_repetitive_delete_umbutton($field, $user_id, $meta_id)
{
    // TODO WPML move Add repetitive control buttons if not copied by WPML
    if (wpcf_wpml_is_translated_profile_page($field)) {
        return '';
    }
    // Let's cache calls
    static $cache = array();
    if (empty($field)) {
        $field = array();
    }
    if (empty($user_id)) {
        $post = array();
    }
    $cache_key = md5(serialize((array) $field) . $meta_id . serialize((array) $user_id));
    // Return cached if there
    if (isset($cache[$cache_key])) {
        return $cache[$cache_key];
    }
    // If post is new show different delete button
    if (empty($user_id)) {
        $cache[$cache_key] = wpcf_repetitive_delete_new_umbutton($field, $user_id);
        return $cache[$cache_key];
    }
    // Regular delete button
    $button = '';
    $title = wpcf_translate("field {$field['id']} name", $field['name']);
    /*
     * No need for old_value anymore.
     * Use meta_id.
     */
    $button .= '&nbsp;<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax' . '&amp;wpcf_action=um_repetitive_delete' . '&amp;_wpnonce=' . wp_create_nonce('um_repetitive_delete') . '&amp;user_id=' . $user_id . '&amp;field_id=' . $field['id'] . '&amp;meta_id=' . $meta_id) . '&amp;wpcf_warning=' . __('Are you sure?', 'wpcf') . '&amp;field_id_md5=' . md5($field['id']) . '" class="wpcf-repetitive-delete button-secondary">' . sprintf(__('Delete %s', 'wpcf'), $title) . '</a>';
    // Cache it
    $cache[$cache_key] = $button;
    return $button;
}
Example #6
0
/**
 * Processes single field.
 * 
 * @staticvar array $repetitive_started
 * @param type $post
 * @param type $field
 * @param type $use_cache
 * @param type $add_to_editor
 * @param type $context
 * @param type $original_cf
 * @param type $invalid_fields
 * @return mixed boolean|array
 */
function wpcf_admin_post_process_field($post = false, $field_unedited = array(), $use_cache = true, $add_to_editor = true, $context = 'group', $original_cf = array(), $invalid_fields = array())
{
    $field = wpcf_admin_fields_get_field($field_unedited['id']);
    if (!empty($field)) {
        // Set values
        $field['value'] = isset($field_unedited['value']) ? $field_unedited['value'] : '';
        $field['wpml_action'] = isset($field_unedited['wpml_action']) ? $field_unedited['wpml_action'] : '';
        if (isset($count[$field['type'] . '-' . $field['slug']])) {
            $field_id = 'wpcf-' . $field['type'] . '-' . $field['slug'] . '-' . $count[$field['type'] . '-' . $field['slug']] . '-' . mt_rand();
            $count[$field['type'] . '-' . $field['slug']] += 1;
        } else {
            $field_id = 'wpcf-' . $field['type'] . '-' . $field['slug'] . '-' . mt_rand();
            $count[$field['type'] . '-' . $field['slug']] = 1;
        }
        $field_init_data = wpcf_fields_type_action($field['type']);
        // Get inherited field
        $inherited_field_data = false;
        if (isset($field_init_data['inherited_field_type'])) {
            $inherited_field_data = wpcf_fields_type_action($field_init_data['inherited_field_type']);
        }
        // Mark any field that is going to be copied.
        if (!empty($original_cf['fields'])) {
            foreach ($original_cf['fields'] as $cf_id) {
                if (wpcf_types_get_meta_prefix($field) . $field['slug'] == $cf_id) {
                    $field['readonly'] = true;
                    $field['wpml_action'] = 'copy';
                    break;
                }
            }
        }
        // Apply filters
        $field['value'] = apply_filters('wpcf_fields_value_get', $field['value'], $field, $field_init_data);
        $field['value'] = apply_filters('wpcf_fields_slug_' . $field['slug'] . '_value_get', $field['value'], $field, $field_init_data);
        $field['value'] = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_get', $field['value'], $field, $field_init_data);
        wpcf_admin_post_field_load_js_css($field_init_data);
        $element = array();
        // Set generic values
        $element = array('#type' => isset($field_init_data['inherited_field_type']) ? $field_init_data['inherited_field_type'] : $field['type'], '#id' => $field_id, '#title' => wpcf_translate('field ' . $field['id'] . ' name', $field['name']), '#description' => wpautop(wpcf_translate('field ' . $field['id'] . ' description', $field['description'])), '#name' => 'wpcf[' . $field['slug'] . ']', '#value' => isset($field['value']) ? $field['value'] : '', 'wpcf-id' => $field['id'], 'wpcf-slug' => $field['slug'], 'wpcf-type' => $field['type']);
        // Set inherited values
        $element_inherited = array();
        if ($inherited_field_data) {
            if (function_exists('wpcf_fields_' . $field_init_data['inherited_field_type'] . '_meta_box_form')) {
                $element_inherited = call_user_func_array('wpcf_fields_' . $field_init_data['inherited_field_type'] . '_meta_box_form', array($field, $element));
            }
        }
        $element = array_merge($element, $element_inherited);
        if (isset($field['description_extra'])) {
            $element['#description'] .= wpautop($field['description_extra']);
        }
        // Set atributes #1
        if (isset($field['disable'])) {
            $field['#disable'] = $field['disable'];
        }
        if (!empty($field['disable'])) {
            $field['#attributes']['disabled'] = 'disabled';
        }
        if (!empty($field['readonly'])) {
            $field['#attributes']['readonly'] = 'readonly';
        }
        // Set specific values
        if (defined('WPCF_INC_ABSPATH') && file_exists(WPCF_INC_ABSPATH . '/fields/' . $field['type'] . '.php')) {
            require_once WPCF_INC_ABSPATH . '/fields/' . $field['type'] . '.php';
        }
        // Load field
        if (function_exists('wpcf_fields_' . $field['type'] . '_meta_box_form')) {
            $element_specific = call_user_func_array('wpcf_fields_' . $field['type'] . '_meta_box_form', array($field, $element));
            // Check if it's single
            if (isset($element_specific['#type'])) {
                // Format description
                if (!empty($element_specific['#description'])) {
                    $element_specific['#description'] = wpautop($element_specific['#description']);
                }
                $element = array_merge($element, $element_specific);
                // Set validation element
                if (isset($field['data']['validate'])) {
                    $element['#validate'] = $field['data']['validate'];
                }
                // Repetitive fields
                if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship' && (!isset($field['wpml_action']) || $field['wpml_action'] != 'copy')) {
                    $element = wpcf_admin_post_process_repetitive_field($post, $field, $element);
                }
            } else {
                // More fields, loop all
                // Only Skype for now have multiple fields, so process only that
                if ($field['type'] == 'skype') {
                    $skype_element = array();
                    foreach ($element_specific as $element_specific_fields_key => $element_specific_fields_value) {
                        $element_specific_fields_value['__element_key'] = $element_specific_fields_key;
                        // Format description
                        if (!empty($element_specific_fields_value['#description'])) {
                            $element_specific_fields_value['#description'] = wpautop($element_specific_fields_value['#description']);
                        }
                        // If no ID
                        if (!isset($element_specific_fields_value['#id'])) {
                            $element_specific_fields_value['#id'] = 'wpcf-' . $field['slug'] . '-' . mt_rand();
                        }
                        // Set validation element
                        if (!empty($element_specific_fields_value['#_validate_this']) && isset($field['data']['validate'])) {
                            $element_specific_fields_value['#validate'] = $field['data']['validate'];
                        }
                        if ($element_specific_fields_key != 'skypename') {
                            if (!isset($element_specific_fields_value['#name'])) {
                                $element_specific_fields_value['#name'] = 'wpcf[ignore][' . mt_rand() . ']';
                            }
                            $skype_element[$element_specific_fields_value['#id']] = $element_specific_fields_value;
                            continue;
                        }
                        // This one is actually value and keep it (#name is required)
                        $element = array_merge($element, $element_specific_fields_value);
                        // Add it here to keep order
                        $skype_element[$element['#id']] = $element;
                    }
                    // Repetitive fields
                    if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship' && (!isset($field['wpml_action']) || $field['wpml_action'] != 'copy')) {
                        list($element, $skype_element) = wpcf_admin_post_process_repetitive_field_skype($post, $field, $skype_element);
                    }
                }
            }
        } else {
            // Repetitive fields
            if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship' && (!isset($field['wpml_action']) || $field['wpml_action'] != 'copy')) {
                $element = wpcf_admin_post_process_repetitive_field($post, $field, $element);
            }
        }
        // Set atributes #2 (override)
        if (isset($field['disable'])) {
            $element['#disable'] = $field['disable'];
        }
        if (!empty($field['disable'])) {
            $element['#attributes']['disabled'] = 'disabled';
        }
        if (!empty($field['readonly'])) {
            $element['#attributes']['readonly'] = 'readonly';
            if (!empty($element['#options'])) {
                foreach ($element['#options'] as $key => $option) {
                    if (!is_array($option)) {
                        $element['#options'][$key] = array('#title' => $key, '#value' => $option);
                    }
                    $element['#options'][$key]['#attributes']['readonly'] = 'readonly';
                    if ($element['#type'] == 'select') {
                        $element['#options'][$key]['#attributes']['disabled'] = 'disabled';
                    }
                }
            }
            if ($element['#type'] == 'select') {
                $element['#attributes']['disabled'] = 'disabled';
            }
        }
        // Set validation element
        if ($field['type'] != 'skype' && empty($element['#validate']) && isset($field['data']['validate'])) {
            $element['#validate'] = $field['data']['validate'];
        }
        // Check if it was invalid no submit and add error message
        if ($post && !empty($invalid_fields)) {
            if (isset($invalid_fields[$element['#id']]['#error'])) {
                $element['#error'] = $invalid_fields[$element['#id']]['#error'];
            }
        }
        // Set WPML locked icon
        if (isset($field['wpml_action']) && $field['wpml_action'] == 'copy') {
            $element['#title'] .= '<img src="' . WPCF_EMBEDDED_RES_RELPATH . '/images/locked.png" alt="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" title="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" style="position:relative;left:2px;top:2px;" />';
        }
        // Add to editor
        if ($add_to_editor) {
            wpcf_admin_post_add_to_editor($field);
        }
        // Add repetitive class
        if (wpcf_admin_is_repetitive($field) && $context != 'post_relationship' && (!isset($field['wpml_action']) || $field['wpml_action'] != 'copy')) {
            if (!empty($element['#options']) && $element['#type'] != 'select') {
                foreach ($element['#options'] as $temp_key => $temp_value) {
                    $element['#options'][$temp_key]['#attributes']['class'] = isset($element['#attributes']['class']) ? $element['#attributes']['class'] . ' wpcf-repetitive' : 'wpcf-repetitive';
                }
            } else {
                $element['#attributes']['class'] = isset($element['#attributes']['class']) ? $element['#attributes']['class'] . ' wpcf-repetitive' : 'wpcf-repetitive';
            }
            wpcf_admin_add_js_settings('wpcfFormRepetitiveUniqueValuesCheckText', '\'' . __('Warning: same values set', 'wpcf') . '\'');
        }
        // Set read-only
        if (isset($field['wpml_action']) && $field['wpml_action'] == 'copy') {
            if (isset($element['#options'])) {
                foreach ($element['#options'] as $temp_key => $temp_value) {
                    if (isset($temp_value['#attributes'])) {
                        $element['#options'][$temp_key]['#attributes']['readonly'] = 'readonly';
                    } else {
                        $element['#options'][$temp_key]['#attributes'] = array('readonly' => 'readonly');
                    }
                }
            }
            if ($field['type'] == 'select') {
                if (isset($element['#attributes'])) {
                    $element['#attributes']['disabled'] = 'disabled';
                } else {
                    $element['#attributes'] = array('disabled' => 'disabled');
                }
            } else {
                if (isset($element['#attributes'])) {
                    $element['#attributes']['readonly'] = 'readonly';
                } else {
                    $element['#attributes'] = array('readonly' => 'readonly');
                }
            }
        }
        // Specific for Skype
        if ($field['type'] == 'skype') {
            $skype_element[$element['#id']] = $element;
            $element = $skype_element;
        }
        return array('field' => $field, 'element' => $element);
    }
    return false;
}
Example #7
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_checkboxes_view($params)
{
    $option = array();
    // Basic checks
    if (empty($params['field']['data']['options']) || !is_array($params['field_value'])) {
        return '__wpcf_skip_empty';
    }
    /*
     * 
     * NO OPTION specified
     * loop over all options and display all of them
     */
    if (!isset($params['option'])) {
        $separator = isset($params['separator']) ? html_entity_decode($params['separator']) : ', ';
        foreach ($params['field_value'] as $name => &$value) {
            /*
             * 
             * Set option
             */
            if (isset($params['field']['data']['options'][$name])) {
                $option = $params['field']['data']['options'][$name];
            } else {
                // Unset if not valid
                unset($params['field_value'][$name]);
                continue;
            }
            /*
             * 
             * Set output according to settings.
             * 'db' or 'value'
             */
            if ($option['display'] == 'db' && !empty($option['set_value']) && !empty($value)) {
                $value = $option['set_value'];
                $value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $name . ' value', $value);
            } else {
                if ($option['display'] == 'value') {
                    if (isset($option['display_value_selected']) && !empty($value)) {
                        $value = $option['display_value_selected'];
                        $value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $name . ' display value selected', $value);
                    } else {
                        $value = $option['display_value_not_selected'];
                        $value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $name . ' display value not selected', $value);
                    }
                } else {
                    unset($params['field_value'][$name]);
                }
            }
        }
        $output = implode(array_values($params['field_value']), $separator);
        return empty($output) ? '__wpcf_skip_empty' : stripslashes($output);
    }
    /*
     * 
     * 
     * OPTION specified - set required option.
     */
    $i = 0;
    foreach ($params['field']['data']['options'] as $option_key => $option_value) {
        if (intval($params['option']) == $i) {
            $option['key'] = $option_key;
            $option['data'] = $option_value;
            $option['value'] = !empty($params['field_value'][$option_key]) ? $params['field_value'][$option_key] : '__wpcf_unchecked';
            break;
        }
        $i++;
    }
    $output = '';
    /*
     * STATE set - use #content is as render value.
     * If setings are faulty - return '__wpcf_skip_empty'.
     */
    if (isset($params['state'])) {
        $content = !empty($params['#content']) ? htmlspecialchars_decode($params['#content']) : '__wpcf_skip_empty';
        if ($params['state'] == 'checked' && $option['value'] != '__wpcf_unchecked') {
            return $content;
        } else {
            if ($params['state'] == 'unchecked' && $option['value'] == '__wpcf_unchecked') {
                return $content;
            } else {
                if (isset($params['state'])) {
                    return '__wpcf_skip_empty';
                }
            }
        }
    }
    /*
     * 
     * MAIN settings
     * 'db'      - Use 'set_value' as render value
     * 'value'   - Use values set in Group form data 'display_value_selected'
     *                  or 'display_value_not_selected'
     * 
     * Only set if it matches settings.
     * Otherwise leave empty and '__wpcf_skip_empty' will be returned.
     *
     */
    if (isset($option['data']) && $option['data']['display'] == 'db') {
        /*
         * 
         * Only if NOT unchecked!
         */
        if (!empty($option['data']['set_value']) && $option['value'] != '__wpcf_unchecked') {
            $output = $option['data']['set_value'];
            $output = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option['key'] . ' value', $output);
        }
    } else {
        if (isset($option['data']) && $option['data']['display'] == 'value') {
            /*
             * 
             * Checked
             */
            if ($option['value'] != '__wpcf_unchecked') {
                if (isset($option['data']['display_value_selected'])) {
                    $output = $option['data']['display_value_selected'];
                    $output = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option['key'] . ' display value selected', $output);
                }
                /*
                 * 
                 * 
                 * Un-checked
                 */
            } else {
                if (isset($option['data']['display_value_not_selected'])) {
                    $output = $option['data']['display_value_not_selected'];
                    $output = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option['key'] . ' display value not selected', $output);
                }
            }
        }
    }
    if (empty($output)) {
        return '__wpcf_skip_empty';
    }
    return $output;
}
/**
 * Renders 'widefat' table.
 */
function wpcf_admin_ctt_list()
{
    $custom_types = get_option('wpcf-custom-types', array());
    $custom_taxonomies = get_option('wpcf-custom-taxonomies', array());
    if (empty($custom_types) && empty($custom_taxonomies)) {
        echo '<p>' . __('Custom Post Types are user-defined content types. Custom Taxonomies are used to categorize your content.', 'wpcf') . ' ' . __('You can read more about Custom Post Types and Taxonomies in this tutorial. <a href="http://wp-types.com/learn/custom-post-types/" target="_blank">http://wp-types.com/learn/custom-post-types/</a>', 'wpcf') . '</p>';
    }
    echo '<br /><a class="button-secondary" href="' . admin_url('admin.php?page=wpcf-edit-type') . '">' . __('Add Custom Post Type', 'wpcf') . '</a>' . '&nbsp;&nbsp;<a class="button-secondary" href="' . admin_url('admin.php?page=wpcf-edit-tax') . '">' . __('Add Custom Taxonomy', 'wpcf') . '</a><br /><br />';
    if (!empty($custom_types)) {
        $rows = array();
        $header = array('name' => __('Post Type Name', 'wpcf'), 'description' => __('Description', 'wpcf'), 'active' => __('Active', 'wpcf'), 'tax' => __('Taxonomies', 'wpcf'));
        foreach ($custom_types as $post_type => $type) {
            $name = '';
            $name .= '<a href="' . admin_url('admin.php?page=wpcf-edit-type&amp;wpcf-post-type=' . $post_type) . '">' . wpcf_translate($post_type . ' name', $type['labels']['name'], 'Types-CPT') . '</a>';
            $name .= '<br />';
            $name .= '<a href="' . admin_url('admin.php?page=wpcf-edit-type&amp;wpcf-post-type=' . $post_type) . '">' . __('Edit', 'wpcf') . '</a> | ';
            $name .= empty($type['disabled']) ? wpcf_admin_custom_types_get_ajax_deactivation_link($post_type) . ' | ' : wpcf_admin_custom_types_get_ajax_activation_link($post_type) . ' | ';
            $name .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=delete_post_type&amp;wpcf-post-type=' . $post_type . '&amp;wpcf_ajax_update=wpcf_list_ajax_response_' . $post_type) . '&amp;wpcf_ajax_callback=wpcfRefresh&amp;_wpnonce=' . wp_create_nonce('delete_post_type') . '&amp;wpcf_warning=' . __('Are you sure?', 'wpcf') . '" class="wpcf-ajax-link" id="wpcf-list-delete-' . $post_type . '">' . __('Delete Permanently', 'wpcf') . '</a>';
            $name .= '<div id="wpcf_list_ajax_response_' . $post_type . '"></div>';
            $rows[$post_type]['name'] = $name;
            $rows[$post_type]['description'] = isset($type['description']) ? htmlspecialchars(stripslashes(wpcf_translate($post_type . ' description', $type['description'], 'Types-CPT')), ENT_QUOTES) : '';
            $rows[$post_type]['active-' . $post_type] = !empty($type['disabled']) ? __('No', 'wpcf') : __('Yes', 'wpcf');
            $rows[$post_type]['tax'] = array();
            if (!empty($type['taxonomies'])) {
                foreach ($type['taxonomies'] as $temp_tax => $true) {
                    $rows[$post_type]['tax'][] = wpcf_translate($temp_tax . ' name', $temp_tax, 'Types-TAX');
                }
            }
            $rows[$post_type]['tax'] = !empty($rows[$post_type]['tax']) ? implode(', ', $rows[$post_type]['tax']) : __('None', 'wpcf');
        }
        // Render table
        wpcf_admin_widefat_table('wpcf_types_list', $header, $rows);
    }
    if (!empty($custom_taxonomies)) {
        $rows = array();
        $header = array('name' => __('Taxonomy Name', 'wpcf'), 'description' => __('Description', 'wpcf'), 'active' => __('Active', 'wpcf'), 'post_types' => __('Post Types', 'wpcf'));
        foreach ($custom_taxonomies as $taxonomy => $data) {
            $name = '';
            $name .= '<a href="' . admin_url('admin.php?page=wpcf-edit-tax&amp;wpcf-tax=' . $taxonomy) . '">' . wpcf_translate($taxonomy . ' name', $data['labels']['name'], 'Types-TAX') . '</a>';
            $name .= '<br />';
            $name .= '<a href="' . admin_url('admin.php?page=wpcf-edit-tax&amp;wpcf-tax=' . $taxonomy) . '">' . __('Edit', 'wpcf') . '</a> | ';
            $name .= empty($data['disabled']) ? wpcf_admin_custom_taxonomies_get_ajax_deactivation_link($taxonomy) . ' | ' : wpcf_admin_custom_taxonomies_get_ajax_activation_link($taxonomy) . ' | ';
            $name .= '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=delete_taxonomy&amp;wpcf-tax=' . $taxonomy . '&amp;wpcf_ajax_callback=wpcfRefresh&amp;wpcf_ajax_update=wpcf_list_ajax_response_' . $taxonomy) . '&amp;_wpnonce=' . wp_create_nonce('delete_taxonomy') . '&amp;wpcf_warning=' . __('Are you sure?', 'wpcf') . '" class="wpcf-ajax-link" id="wpcf-list-delete-' . $taxonomy . '">' . __('Delete Permanently', 'wpcf') . '</a>';
            $name .= '<div id="wpcf_list_ajax_response_' . $taxonomy . '"></div>';
            $rows[$taxonomy]['name'] = $name;
            $rows[$taxonomy]['description'] = isset($data['description']) ? htmlspecialchars(stripslashes(wpcf_translate($taxonomy . ' description', $type['description'], 'Types-TAX')), ENT_QUOTES) : '';
            $rows[$taxonomy]['active-' . $taxonomy] = !empty($data['disabled']) ? __('No', 'wpcf') : __('Yes', 'wpcf');
            $rows[$taxonomy]['post_types'] = array();
            if (!empty($data['supports'])) {
                foreach ($data['supports'] as $temp_post_type => $true) {
                    $rows[$taxonomy]['post_types'][] = wpcf_translate($temp_post_type . ' name', $temp_post_type, 'Types-CPT');
                }
            }
            $rows[$taxonomy]['post_types'] = !empty($rows[$taxonomy]['post_types']) ? implode(', ', $rows[$taxonomy]['post_types']) : __('None', 'wpcf');
        }
        // Render table
        echo '<br />';
        wpcf_admin_widefat_table('wpcf_tax_list', $header, $rows);
    }
    do_action('wpcf_types_tax_list_table_after');
}
Example #9
0
/**
 * Renders meta box content.
 *
 * Core function. Works and stable.
 * If required, add hooks only.
 *
 * @todo Revise this 1.1.5
 *
 * @param type $post
 * @param type $group
 * @param type $echo
 * @param type boolean $open_style_editor if true use code for open style editor when edit group
 */
function wpcf_admin_post_meta_box($post, $group, $echo = '', $open_style_editor = false)
{
    if (false === $open_style_editor && defined('WPTOOLSET_FORMS_VERSION')) {
        if (isset($group['args']['html'])) {
            /**
             * show group description
             */
            if (array_key_exists('description', $group['args']) && !empty($group['args']['description'])) {
                echo '<div class="wpcf-meta-box-description">';
                echo wpautop(wpcf_translate('group ' . $group['args']['id'] . ' description', $group['args']['description']));
                echo '</div>';
            }
            foreach ($group['args']['html'] as $field) {
                echo is_array($field) ? wptoolset_form_field('post', $field['config'], $field['meta']) : $field;
            }
        }
        return;
    }
    global $wpcf;
    /**
     * fake post object if need
     */
    $post = wpcf_admin_create_fake_post_if_need($post);
    static $nonce_added = false;
    $group_output = '';
    if (!isset($group['title'])) {
        $temp = $group;
        $group = '';
        $group['args'] = $temp;
        $group['id'] = $temp['slug'];
        $group['title'] = $temp['name'];
        $name = $temp['name'];
    }
    if (!empty($echo)) {
        $group_output = '<h3>This Preview generated for latest post "' . $post->post_title . '"</h3>' . "\n" . '<!-- Previous lines visible only in Admin Style Editor.-->' . "\n\n";
        $group_output .= '<div id="wpcf-group-' . $group['id'] . '" class="postbox " >
            <h3 class=\'hndle\'><span>' . $name . '</span></h3>
            <div class="inside">' . "\n";
    }
    /*
     * TODO Document where this is used
     */
    if (!$nonce_added && empty($echo)) {
        $nonce_action = 'update-' . $post->post_type . '_' . $post->ID;
        wp_nonce_field($nonce_action, '_wpcf_post_wpnonce');
        $nonce_added = true;
    }
    $group_output .= "\n\n" . '<div id="wpcf-group-metabox-id-' . $group['args']['slug'] . '">' . "\n";
    /*
     * TODO Move to Conditional code
     *
     * This is already checked. Use hook to add wrapper DIVS and apply CSS.
     */
    if (!empty($group['args']['_conditional_display'])) {
        if ($group['args']['_conditional_display'] == 'failed') {
            $group_output .= '<div class="wpcf-cd-group wpcf-cd-group-failed" style="display:none;">';
        } else {
            $group_output .= '<div class="wpcf-cd-group wpcf-cd-group-passed">';
        }
    }
    /*
     * TODO Move this into Field code
     * Process fields
     */
    if (!empty($group['args']['fields'])) {
        // Display description
        if (!empty($group['args']['description'])) {
            $group_output .= '<div class="wpcf-meta-box-description">' . wpautop(wpcf_translate('group ' . $group['args']['id'] . ' description', $group['args']['description'])) . '</div>';
        }
        foreach ($group['args']['fields'] as $field_slug => $field) {
            if (empty($field) || !is_array($field)) {
                continue;
            }
            $field = $wpcf->field->_parse_cf_form_element($field);
            if (isset($field['wpcf-type'])) {
                // May be ignored
                $field = apply_filters('wpcf_fields_' . $field['wpcf-type'] . '_meta_box_form_value_display', $field);
            }
            if (!isset($field['#id'])) {
                $field['#id'] = wpcf_unique_id(serialize($field));
            }
            // Render form elements
            if (wpcf_compare_wp_version() && array_key_exists('#type', $field) && 'wysiwyg' == $field['#type'] && !isset($field['#attributes']['disabled'])) {
                //                if ( isset( $field['#attributes']['disabled'] ) ) {
                //                    $field['#editor_settings']['tinymce'] = false;
                //                    $field['#editor_settings']['teeny'] = false;
                //                    $field['#editor_settings']['media_buttons'] = false;
                //                    $field['#editor_settings']['quicktags'] = false;
                //                    $field['#editor_settings']['dfw'] = false;
                //                }
                // Especially for WYSIWYG
                $group_output .= '<div class="wpcf-wysiwyg">';
                $group_output .= '<div id="wpcf-textarea-textarea-wrapper" class="form-item form-item-textarea wpcf-form-item wpcf-form-item-textarea">';
                $group_output .= isset($field['#before']) ? $field['#before'] : '';
                $group_output .= '<label class="wpcf-form-label wpcf-form-textarea-label">' . stripslashes($field['#title']) . '</label>';
                $group_output .= '<div class="description wpcf-form-description wpcf-form-description-textarea description-textarea">
                    ' . wpautop($field['#description']) . '</div>';
                ob_start();
                wp_editor($field['#value'], $field['#id'], $field['#editor_settings']);
                $group_output .= ob_get_clean() . "\n\n";
                $field['slug'] = str_replace(WPCF_META_PREFIX . 'wysiwyg-', '', $field_slug);
                $field['type'] = 'wysiwyg';
                $group_output .= '</div>';
                $group_output .= isset($field['#after']) ? $field['#after'] : '';
                $group_output .= '</div>';
            } else {
                if (array_key_exists('#type', $field) && 'wysiwyg' == $field['#type']) {
                    $field['#type'] = 'textarea';
                }
                if (!empty($echo)) {
                    $field['#validate'] = '';
                }
                $group_output .= wpcf_form_simple(array($field['#id'] => $field));
            }
            do_action('wpcf_fields_' . $field_slug . '_meta_box_form', $field);
            if (isset($field['wpcf-type'])) {
                // May be ignored
                do_action('wpcf_fields_' . $field['wpcf-type'] . '_meta_box_form', $field);
            }
        }
    }
    /*
     * TODO Move to Conditional code
     *
     * This is already checked. Use hook to add wrapper DIVS and apply CSS.
     */
    if (!empty($group['args']['_conditional_display'])) {
        $group_output .= '</div>';
    }
    $group_output .= '</div>';
    if (!empty($echo)) {
        $group_output .= "\n\n</div></div>";
        return $group_output;
    } else {
        echo $group_output;
    }
}
Example #10
0
 /**
  * Get group name as it should be displayed to the user.
  *
  * Handles string translation if applicable.
  */
 public function get_display_name()
 {
     return wpcf_translate(sprintf('group %d name', $this->get_id()), $this->get_name());
 }
Example #11
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_radio_view($params)
{
    if (isset($params['style']) && $params['style'] == 'raw') {
        return '';
    }
    if (isset($params['termmeta']) && !empty($params['termmeta'])) {
        $field = wpcf_fields_get_field_by_slug($params['field']['slug'], 'wpcf-termmeta');
    } else {
        if (isset($params['usermeta']) && !empty($params['usermeta'])) {
            $field = wpcf_fields_get_field_by_slug($params['field']['slug'], 'wpcf-usermeta');
        } else {
            $field = wpcf_fields_get_field_by_slug($params['field']['slug']);
        }
    }
    $output = '';
    // See if user specified output for each field
    if (isset($params['option'])) {
        foreach ($field['data']['options'] as $option_key => $option) {
            if (isset($option['value'])) {
                $test_val = stripslashes(strval($option['value']));
                if ($test_val == $params['field_value'] && $option_key == $params['option']) {
                    return htmlspecialchars_decode($params['#content']);
                }
            }
        }
        //        return ' ';
        return '__wpcf_skip_empty';
    }
    if (!empty($field['data']['options'])) {
        $field_value = $params['field_value'];
        foreach ($field['data']['options'] as $option_key => $option) {
            if (isset($option['value']) && stripslashes($option['value']) == stripslashes($params['field_value'])) {
                // We need to translate here because the stored value is on the original language
                // When updaing the value in the Field group, we might have problems
                $field_value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option_key . ' title', $option['title']);
                if (isset($params['field']['data']['display']) && $params['field']['data']['display'] != 'db' && !empty($option['display_value'])) {
                    // We need to translate here because the stored value is on the original language
                    // When updaing the value in the Field group, we might have problems
                    $field_value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option_key . ' display value', $option['display_value']);
                }
            }
        }
        $output = $field_value;
    }
    return $output;
}
Example #12
0
/**
 * WPML editor filter
 * 
 * @param type $cf_name
 * @param type $description
 * @return type 
 */
function wpcf_icl_editor_cf_description_filter($description, $cf_name)
{
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
    $fields = wpcf_admin_fields_get_fields();
    if (empty($fields)) {
        return $description;
    }
    $cf_name = substr($cf_name, 6);
    if (strpos($cf_name, WPCF_META_PREFIX) == 0) {
        $cf_name = str_replace(WPCF_META_PREFIX, '', $cf_name);
    }
    if (isset($fields[$cf_name]['description'])) {
        $description = wpcf_translate('field ' . $fields[$cf_name]['id'] . ' description', $fields[$cf_name]['description']);
    }
    return $description;
}
Example #13
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_radio_view($params)
{
    if ($params['style'] == 'raw') {
        return '';
    }
    $field = wpcf_fields_get_field_by_slug($params['field']['slug']);
    $output = '';
    // See if user specified output for each field
    if (isset($params['option'])) {
        foreach ($field['data']['options'] as $option_key => $option) {
            if (isset($option['value']) && $option['value'] == $params['field_value'] && $option_key == $params['option']) {
                return htmlspecialchars_decode($params['#content']);
            }
        }
        return ' ';
    }
    if (!empty($field['data']['options'])) {
        $field_value = $params['field_value'];
        foreach ($field['data']['options'] as $option_key => $option) {
            if (isset($option['value']) && $option['value'] == $params['field_value']) {
                $field_value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option_key . ' title', $option['title']);
                if (isset($params['field']['data']['display']) && $params['field']['data']['display'] != 'db' && !empty($option['display_value'])) {
                    $field_value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option_key . ' display value', $option['display_value']);
                }
            }
        }
        $field_value = wpcf_frontend_wrap_field_value($params['field'], $field_value, $params);
        $output = wpcf_frontend_wrap_field($params['field'], $field_value);
    }
    return $output;
}
Example #14
0
/**
 * Renders meta box content.
 * 
 * Core function. Works and stable.
 * If required, add hooks only.
 * 
 * @todo Revise this 1.1.5
 * 
 * @param type $post
 * @param type $group 
 */
function wpcf_admin_post_meta_box($post, $group)
{
    global $wpcf;
    static $nonce_added = false;
    /*
     * TODO Document where this is used
     */
    if (!$nonce_added) {
        $nonce_action = 'update-' . $post->post_type . '_' . $post->ID;
        wp_nonce_field($nonce_action, '_wpcf_post_wpnonce');
        $nonce_added = true;
    }
    /*
     * TODO Move to Conditional code
     * 
     * This is already checked. Use hook to add wrapper DIVS and apply CSS.
     */
    if (!empty($group['args']['_conditional_display'])) {
        if ($group['args']['_conditional_display'] == 'failed') {
            echo '<div class="wpcf-cd-group wpcf-cd-group-failed" style="display:none;">';
        } else {
            echo '<div class="wpcf-cd-group wpcf-cd-group-passed">';
        }
    }
    /*
     * TODO Move this into Field code
     * Process fields
     */
    if (!empty($group['args']['fields'])) {
        // Display description
        if (!empty($group['args']['description'])) {
            echo '<div class="wpcf-meta-box-description">' . wpautop(wpcf_translate('group ' . $group['args']['id'] . ' description', $group['args']['description'])) . '</div>';
        }
        foreach ($group['args']['fields'] as $field_slug => $field) {
            if (empty($field) || !is_array($field)) {
                continue;
            }
            $field = $wpcf->field->_parse_cf_form_element($field);
            if (!isset($field['#id'])) {
                $field['#id'] = wpcf_unique_id(serialize($field));
            }
            // Render form elements
            if (wpcf_compare_wp_version() && $field['#type'] == 'wysiwyg') {
                // Especially for WYSIWYG
                echo '<div class="wpcf-wysiwyg">';
                echo '<div id="wpcf-textarea-textarea-wrapper" class="form-item form-item-textarea wpcf-form-item wpcf-form-item-textarea">';
                echo isset($field['#before']) ? $field['#before'] : '';
                echo '
<label class="wpcf-form-label wpcf-form-textarea-label">' . $field['#title'] . '</label>';
                echo '<div class="description wpcf-form-description wpcf-form-description-textarea description-textarea">
' . wpautop($field['#description']) . '</div>';
                wp_editor($field['#value'], $field['#id'], $field['#editor_settings']);
                $field['slug'] = str_replace(WPCF_META_PREFIX . 'wysiwyg-', '', $field_slug);
                $field['type'] = 'wysiwyg';
                echo '</div>';
                echo isset($field['#after']) ? $field['#after'] : '';
                echo '</div><br /><br />';
            } else {
                if ($field['#type'] == 'wysiwyg') {
                    $field['#type'] = 'textarea';
                }
                echo wpcf_form_simple(array($field['#id'] => $field));
            }
            do_action('wpcf_fields_' . $field_slug . '_meta_box_form', $field);
            if (isset($field['wpcf-type'])) {
                // May be ignored
                do_action('wpcf_fields_' . $field['wpcf-type'] . '_meta_box_form', $field);
            }
        }
    }
    /*
     * TODO Move to Conditional code
     * 
     * This is already checked. Use hook to add wrapper DIVS and apply CSS.
     */
    if (!empty($group['args']['_conditional_display'])) {
        echo '</div>';
    }
}
Example #15
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_checkbox_view($params)
{
    $output = '';
    if (isset($params['state']) && $params['state'] == 'unchecked' && empty($params['field_value'])) {
        return htmlspecialchars_decode($params['#content']);
    } else {
        if (isset($params['state']) && $params['state'] == 'unchecked') {
            return '__wpcf_skip_empty';
        }
    }
    if (isset($params['state']) && $params['state'] == 'checked' && !empty($params['field_value'])) {
        return htmlspecialchars_decode($params['#content']);
    } else {
        if (isset($params['state']) && $params['state'] == 'checked') {
            return '__wpcf_skip_empty';
        }
    }
    if (!empty($params['#content'])) {
        return htmlspecialchars_decode($params['#content']);
    }
    if ($params['field']['data']['display'] == 'db' && $params['field_value'] != '') {
        $field = wpcf_fields_get_field_by_slug($params['field']['slug']);
        $output = $field['data']['set_value'];
        // Show the translated value if we have one.
        $output = wpcf_translate('field ' . $field['id'] . ' checkbox value', $output);
    } else {
        if ($params['field']['data']['display'] == 'value' && $params['field_value'] != '') {
            if (!empty($params['field']['data']['display_value_selected'])) {
                $output = $params['field']['data']['display_value_selected'];
                $output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value selected', $output);
            }
        } else {
            if ($params['field']['data']['display'] == 'value') {
                if (!empty($params['field']['data']['display_value_not_selected'])) {
                    $output = $params['field']['data']['display_value_not_selected'];
                    $output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value not selected', $output);
                }
            }
        }
    }
    return $output;
}
Example #16
0
/**
 * Calls view function for specific field type.
 * 
 * @param type $field
 * @param type $atts
 * @return type 
 */
function types_render_field($field, $params, $content = null, $code = '')
{
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
    // Count fields (if there are duplicates)
    static $count = array();
    // Get field
    $field = wpcf_fields_get_field_by_slug($field);
    if (empty($field)) {
        return '';
    }
    // Count it
    if (!isset($count[$field['slug']])) {
        $count[$field['slug']] = 1;
    } else {
        $count[$field['slug']] += 1;
    }
    // Get post field value
    global $post;
    $value = get_post_meta($post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
    if ($value == '' && $field['type'] != 'checkbox') {
        return '';
    }
    // Load type
    $type = wpcf_fields_type_action($field['type']);
    // Apply filters to field value
    $value = apply_filters('wpcf_fields_value_display', $value);
    $value = apply_filters('wpcf_fields_slug_' . $field['slug'] . '_value_display', $value);
    $value = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_display', $value);
    // To make sure
    if (is_string($value)) {
        $value = addslashes(stripslashes($value));
    }
    // Set values
    $field['name'] = wpcf_translate('field ' . $field['id'] . ' name', $field['name']);
    $params['field'] = $field;
    $params['post'] = $post;
    $params['field_value'] = $value;
    // Get output
    $params['#content'] = htmlspecialchars($content);
    $params['#code'] = $code;
    $output = wpcf_fields_type_action($field['type'], 'view', $params);
    // Convert to string
    if (!empty($output)) {
        $output = strval($output);
    }
    // @todo Reconsider if ever changing this (works fine now)
    // If no output or 'raw' return default
    if (($params['raw'] == 'true' || empty($output)) && !empty($value)) {
        $field_name = '';
        if ($params['show_name'] == 'true') {
            $field_name = wpcf_frontend_wrap_field_name($field, $field['name'], $params);
        }
        $field_value = wpcf_frontend_wrap_field_value($field, $value, $params);
        $output = wpcf_frontend_wrap_field($field, $field_name . $field_value);
    }
    // Apply filters
    $output = strval(apply_filters('types_view', $output, $value, $field['type'], $field['slug'], $field['name'], $params));
    // Add count
    if (isset($count[$field['slug']]) && intval($count[$field['slug']]) > 1) {
        $add = '-' . intval($count[$field['slug']]);
        $output = str_replace('id="wpcf-field-' . $field['slug'] . '"', 'id="wpcf-field-' . $field['slug'] . $add . '"', $output);
    }
    return htmlspecialchars_decode(stripslashes($output));
}
/**
 * View function.
 *
 * @param type $params
 */
function wpcf_fields_checkbox_view($params)
{
    $output = '';
    $option_name = 'wpcf-fields';
    if (isset($params['usermeta']) && !empty($params['usermeta'])) {
        $option_name = 'wpcf-usermeta';
    } else {
        if (isset($params['termmeta']) && !empty($params['termmeta'])) {
            $option_name = 'wpcf-termmeta';
        }
    }
    if (isset($params['option_name'])) {
        $option_name = $params['option_name'];
    }
    if (isset($params['state']) && $params['state'] == 'unchecked' && empty($params['field_value'])) {
        if (empty($params['#content'])) {
            return '__wpcf_skip_empty';
        }
        return htmlspecialchars_decode($params['#content']);
    } elseif (isset($params['state']) && $params['state'] == 'unchecked') {
        return '__wpcf_skip_empty';
    }
    if (isset($params['state']) && $params['state'] == 'checked' && !empty($params['field_value'])) {
        if (empty($params['#content'])) {
            return '__wpcf_skip_empty';
        }
        return htmlspecialchars_decode($params['#content']);
    } elseif (isset($params['state']) && $params['state'] == 'checked') {
        return '__wpcf_skip_empty';
    }
    if (!empty($params['#content']) && !empty($params['field_value'])) {
        return htmlspecialchars_decode($params['#content']);
    }
    // Check if 'save_empty' is yes and if value is 0 - set value to empty string
    if (isset($params['field']['data']['save_empty']) && $params['field']['data']['save_empty'] == 'yes' && $params['field_value'] == '0' && 'db' != $params['field']['data']['display']) {
        $params['field_value'] = '';
    }
    if ('db' == $params['field']['data']['display'] && $params['field_value'] != '') {
        // We need to translate here because the stored value is on the original language
        // When updaing the value in the Field group, we might have problems
        $output = $params['field_value'];
        // Show the translated value if we have one.
        $field = wpcf_fields_get_field_by_slug($params['field']['slug'], $option_name);
        if (is_array($field) && isset($field['id'])) {
            $output = wpcf_translate('field ' . $field['id'] . ' checkbox value', $output);
        }
    } elseif ($params['field']['data']['display'] == 'value' && $params['field_value'] != '') {
        if (!empty($params['field']['data']['display_value_selected'])) {
            // We need to translate here because the stored value is on the original language
            // When updaing the value in the Field group, we might have problems
            $output = $params['field']['data']['display_value_selected'];
            $output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value selected', $output);
        }
    } elseif ($params['field']['data']['display'] == 'value' && !empty($params['field']['data']['display_value_not_selected'])) {
        // We need to translate here because the stored value is on the original language
        // When updaing the value in the Field group, we might have problems
        $output = $params['field']['data']['display_value_not_selected'];
        $output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value not selected', $output);
    } else {
        return '__wpcf_skip_empty';
    }
    return $output;
}
/**
 * View function.
 *
 * @param type $params
 */
function wpcf_fields_checkbox_view($params)
{
    $output = '';
    $option_name = 'wpcf-fields';
    if (isset($params['usermeta']) && !empty($params['usermeta'])) {
        $option_name = 'wpcf-usermeta';
    }
    if (isset($params['option_name'])) {
        $option_name = $params['option_name'];
    }
    if (isset($params['state']) && $params['state'] == 'unchecked' && empty($params['field_value'])) {
        if (empty($params['#content'])) {
            return '__wpcf_skip_empty';
        }
        return htmlspecialchars_decode($params['#content']);
    } elseif (isset($params['state']) && $params['state'] == 'unchecked') {
        return '__wpcf_skip_empty';
    }
    if (isset($params['state']) && $params['state'] == 'checked' && !empty($params['field_value'])) {
        if (empty($params['#content'])) {
            return '__wpcf_skip_empty';
        }
        return htmlspecialchars_decode($params['#content']);
    } elseif (isset($params['state']) && $params['state'] == 'checked') {
        return '__wpcf_skip_empty';
    }
    if (!empty($params['#content']) && !empty($params['field_value'])) {
        return htmlspecialchars_decode($params['#content']);
    }
    // Check if 'save_empty' is yes and if value is 0 - set value to empty string
    if (isset($params['field']['data']['save_empty']) && $params['field']['data']['save_empty'] == 'yes' && $params['field_value'] == '0' && 'db' != $params['field']['data']['display']) {
        $params['field_value'] = '';
    }
    if ('db' == $params['field']['data']['display'] && $params['field_value'] != '') {
        $output = $params['field_value'];
        // Show the translated value if we have one.
        $field = wpcf_fields_get_field_by_slug($params['field']['slug'], $option_name);
        $output = wpcf_translate('field ' . $field['id'] . ' checkbox value', $output);
    } elseif ($params['field']['data']['display'] == 'value' && $params['field_value'] != '') {
        if (!empty($params['field']['data']['display_value_selected'])) {
            $output = $params['field']['data']['display_value_selected'];
            $output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value selected', $output);
        }
    } elseif ($params['field']['data']['display'] == 'value' && !empty($params['field']['data']['display_value_not_selected'])) {
        $output = $params['field']['data']['display_value_not_selected'];
        $output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value not selected', $output);
    } else {
        return '__wpcf_skip_empty';
    }
    return $output;
}
Example #19
0
/**
 * Creates form elements.
 * 
 * @param type $post
 * @param type $fields
 * @return type 
 */
function wpcf_admin_post_process_fields($post = false, $fields = array(), $use_cache = true, $add_to_editor = true, $context = 'group')
{
    global $pagenow;
    static $count = array();
    //Need this to count if there are more than one same field on page
    // Get cached
    static $cache = array();
    $cache_key = $post ? $post->ID : false;
    if ($use_cache && $cache_key && isset($cache[$cache_key])) {
        return $cache[$cache_key];
    }
    $fields_processed = array();
    // Get invalid fields (if submitted)
    if ($post) {
        $invalid_fields = get_post_meta($post->ID, 'wpcf-invalid-fields', true);
        delete_post_meta($post->ID, 'wpcf-invalid-fields');
    }
    $original_cf = array();
    if (function_exists('wpml_get_copied_fields_for_post_edit')) {
        $original_cf = wpml_get_copied_fields_for_post_edit();
    }
    foreach ($fields as $field) {
        $field = wpcf_admin_fields_get_field($field['id']);
        if (!empty($field)) {
            // TODO Monitor added rand suffix
            if (isset($count[$field['type'] . '-' . $field['slug']])) {
                $field_id = 'wpcf-' . $field['type'] . '-' . $field['slug'] . '-' . $count[$field['type'] . '-' . $field['slug']] . '-' . mt_rand();
                $count[$field['type'] . '-' . $field['slug']] += 1;
            } else {
                $field_id = 'wpcf-' . $field['type'] . '-' . $field['slug'] . '-' . mt_rand();
                $count[$field['type'] . '-' . $field['slug']] = 1;
            }
            $field_init_data = wpcf_fields_type_action($field['type']);
            // Get inherited field
            $inherited_field_data = false;
            if (isset($field_init_data['inherited_field_type'])) {
                $inherited_field_data = wpcf_fields_type_action($field_init_data['inherited_field_type']);
            }
            // Set value
            $field['value'] = '';
            if ($post) {
                $field['value'] = get_post_meta($post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
            } else {
                // see if it's in the original custom fields to copy.
                if (!empty($original_cf['fields'])) {
                    foreach ($original_cf['fields'] as $cf_id) {
                        if (wpcf_types_get_meta_prefix($field) . $field['slug'] == $cf_id) {
                            $field['wpml_action'] = 'copy';
                            $field['value'] = get_post_meta($original_cf['original_post_id'], wpcf_types_get_meta_prefix($field) . $field['slug'], true);
                            break;
                        }
                    }
                }
            }
            // Mark any field that is going to be copied.
            if (!empty($original_cf['fields'])) {
                foreach ($original_cf['fields'] as $cf_id) {
                    if (wpcf_types_get_meta_prefix($field) . $field['slug'] == $cf_id) {
                        //                        $field['description_extra'] = $original_cf['copy_message'];
                        $field['readonly'] = true;
                        $field['wpml_action'] = 'copy';
                        break;
                    }
                }
            }
            // Apply filters
            $field['value'] = apply_filters('wpcf_fields_value_get', $field['value'], $field, $field_init_data);
            $field['value'] = apply_filters('wpcf_fields_slug_' . $field['slug'] . '_value_get', $field['value'], $field, $field_init_data);
            $field['value'] = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_get', $field['value'], $field, $field_init_data);
            wpcf_admin_post_field_load_js_css($field_init_data);
            $element = array();
            // Set generic values
            $element = array('#type' => isset($field_init_data['inherited_field_type']) ? $field_init_data['inherited_field_type'] : $field['type'], '#id' => $field_id, '#title' => wpcf_translate('field ' . $field['id'] . ' name', $field['name']), '#description' => wpautop(wpcf_translate('field ' . $field['id'] . ' description', $field['description'])), '#name' => 'wpcf[' . $field['slug'] . ']', '#value' => isset($field['value']) ? $field['value'] : '', 'wpcf-id' => $field['id'], 'wpcf-slug' => $field['slug'], 'wpcf-type' => $field['type']);
            // Set inherited values
            $element_inherited = array();
            if ($inherited_field_data) {
                if (function_exists('wpcf_fields_' . $field_init_data['inherited_field_type'] . '_meta_box_form')) {
                    $element_inherited = call_user_func_array('wpcf_fields_' . $field_init_data['inherited_field_type'] . '_meta_box_form', array($field, $element));
                }
            }
            $element = array_merge($element, $element_inherited);
            if (isset($field['description_extra'])) {
                $element['#description'] .= wpautop($field['description_extra']);
            }
            // Set atributes #1
            if (isset($field['disable'])) {
                $field['#disable'] = $field['disable'];
            }
            if (!empty($field['disable'])) {
                $field['#attributes']['disabled'] = 'disabled';
            }
            if (!empty($field['readonly'])) {
                $field['#attributes']['readonly'] = 'readonly';
            }
            // Set specific values
            if (defined('WPCF_INC_ABSPATH') && file_exists(WPCF_INC_ABSPATH . '/fields/' . $field['type'] . '.php')) {
                require_once WPCF_INC_ABSPATH . '/fields/' . $field['type'] . '.php';
            }
            // Load field
            // TODO remove
            //            wpcf_fields_type_action($field['type']);
            //            require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/' . $field['type']
            //                    . '.php';
            if (function_exists('wpcf_fields_' . $field['type'] . '_meta_box_form')) {
                $element_specific = call_user_func_array('wpcf_fields_' . $field['type'] . '_meta_box_form', array($field, $element));
                // Check if it's single
                if (isset($element_specific['#type'])) {
                    // Format description
                    if (!empty($element_specific['#description'])) {
                        $element_specific['#description'] = wpautop($element_specific['#description']);
                    }
                    $element = array_merge($element, $element_specific);
                    // Set validation element
                    if (isset($field['data']['validate'])) {
                        $element['#validate'] = $field['data']['validate'];
                    }
                } else {
                    // More fields, loop all
                    foreach ($element_specific as $element_specific_fields_key => $element_specific_fields_value) {
                        // Format description
                        if (!empty($element_specific_fields_value['#description'])) {
                            $element_specific_fields_value['#description'] = wpautop($element_specific_fields_value['#description']);
                        }
                        // If no ID
                        if (!isset($element_specific_fields_value['#id'])) {
                            $element_specific_fields_value['#id'] = 'wpcf-' . $field['slug'] . '-' . mt_rand();
                        }
                        // Set validation element
                        if (!empty($element_specific_fields_value['#_validate_this']) && isset($field['data']['validate'])) {
                            $element_specific_fields_value['#validate'] = $field['data']['validate'];
                        }
                        // If no name, name = #ignore or id = #ignore - IGNORE
                        if (!isset($element_specific_fields_value['#name']) || $element_specific_fields_value['#name'] == '#ignore' || $element_specific_fields_value['#id'] == '#ignore') {
                            $element_specific_fields_value['#id'] = 'wpcf-' . $field['slug'] . '-' . mt_rand();
                            $element_specific_fields_value['#name'] = 'wpcf[ignore][' . mt_rand() . ']';
                            $fields_processed[$element_specific_fields_value['#id']] = $element_specific_fields_value;
                            continue;
                        }
                        //                        if ($field['type'] == 'skype' && strpos($element_specific_fields_value['#name'], '[skypename]') === false) {
                        //                            continue;
                        //                        }
                        // This one is actually value and keep it (#name is required)
                        $element = array_merge($element, $element_specific_fields_value);
                        // Add it here to keep order
                        $fields_processed[$element['#id']] = $element;
                    }
                }
            }
            // Set atributes #2 (override)
            if (isset($field['disable'])) {
                $element['#disable'] = $field['disable'];
            }
            if (!empty($field['disable'])) {
                $element['#attributes']['disabled'] = 'disabled';
            }
            if (!empty($field['readonly'])) {
                $element['#attributes']['readonly'] = 'readonly';
                if (!empty($element['#options'])) {
                    foreach ($element['#options'] as $key => $option) {
                        if (!is_array($option)) {
                            $element['#options'][$key] = array('#title' => $key, '#value' => $option);
                        }
                        $element['#options'][$key]['#attributes']['readonly'] = 'readonly';
                        if ($element['#type'] == 'select') {
                            $element['#options'][$key]['#attributes']['disabled'] = 'disabled';
                        }
                    }
                }
                if ($element['#type'] == 'select') {
                    $element['#attributes']['disabled'] = 'disabled';
                }
            }
            // Set validation element
            if ($field['type'] != 'skype' && empty($element['#validate']) && isset($field['data']['validate'])) {
                $element['#validate'] = $field['data']['validate'];
            }
            // Check if it was invalid no submit and add error message
            if ($post && !empty($invalid_fields)) {
                if (isset($invalid_fields[$element['#id']]['#error'])) {
                    $element['#error'] = $invalid_fields[$element['#id']]['#error'];
                }
            }
            // Set WPML locked icon
            if (isset($field['wpml_action']) && $field['wpml_action'] == 'copy') {
                $element['#title'] .= '<img src="' . WPCF_EMBEDDED_RES_RELPATH . '/images/locked.png" alt="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" title="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" style="position:relative;left:2px;top:2px;" />';
            }
            // Add to editor
            if ($add_to_editor) {
                wpcf_admin_post_add_to_editor($field);
            }
            $fields_processed[$element['#id']] = apply_filters('wpcf_post_edit_field', $element, $field, $post, $context);
        }
    }
    if ($cache_key && isset($cache[$cache_key])) {
        $cache[$cache_key] = $fields_processed;
    }
    return $fields_processed;
}
/**
 * 
 * Views-Shortcode: wpv-control
 *
 * Description: Add filters for View
 *
 * Parameters:
 * type: type of retrieved field layout (radio, checkbox, select, textfield, checkboxes, datepicker)
 * url_param: the URL parameter passed as an argument
 * values: Optional. a list of supplied values
 * display_values: Optional. A list of values to display for the corresponding values
 * auto_fill: Optional. When set to a "field-slug" the control will be populated with custom field values from the database.
 * auto_fill_default: Optional. Used to set the default, unselected, value of the control. eg Ignore or Don't care
 * auto_fill_sort: Optional. 'asc', 'desc', 'ascnum', 'descnum', 'none'. Defaults to ascending.
 * field: Optional. a Types field to retrieve values from
 * title: Optional. Use for the checkbox title
 * taxonomy: Optional. Use when a taxonomy control should be displayed.
 * default_label: Optional. Use when a taxonomy control should be displayed using select input type.
 * date_format: Optional. Used for a datepicker control
 *
 * Example usage:
 *
 * Link:
 * More details about this shortcode here: <a href="http://wp-types.com/documentation/wpv-control-fields-in-front-end-filters/" title="wpv-control – Displaying fields in front-end filters">http://wp-types.com/documentation/wpv-control-fields-in-front-end-filters/</a>
 *
 * Note:
 *
 */
function wpv_shortcode_wpv_control($atts)
{
    if (!isset($atts['url_param'])) {
        return __('The url_param is missing from the wpv-control shortcode argument.', 'wpv-views');
    }
    if ((!isset($atts['type']) || $atts == '') && !isset($atts['field'])) {
        return __('The "type" or "field" needs to be set in the wpv-control shortcode argument.', 'wpv-views');
    }
    extract(shortcode_atts(array('type' => '', 'values' => array(), 'display_values' => array(), 'field' => '', 'url_param' => '', 'title' => '', 'taxonomy' => '', 'default_label' => '', 'auto_fill' => '', 'auto_fill_default' => '', 'auto_fill_sort' => '', 'date_format' => ''), $atts));
    if ($taxonomy != '') {
        // pass the new shortcode attribute $default_label
        return _wpv_render_taxonomy_control($taxonomy, $type, $url_param, $default_label);
    }
    if ($auto_fill != '') {
        // See if we should handle types checkboxes
        $types_checkboxes_field = false;
        if (_wpv_is_field_of_type($auto_fill, 'checkboxes')) {
            if (!function_exists('wpcf_admin_fields_get_fields')) {
                if (defined('WPCF_EMBEDDED_ABSPATH')) {
                    include WPCF_EMBEDDED_ABSPATH . '/includes/fields.php';
                }
            }
            if (function_exists('wpcf_admin_fields_get_fields')) {
                $fields = wpcf_admin_fields_get_fields();
                $field_name = substr($auto_fill, 5);
                if (isset($fields[$field_name])) {
                    $types_checkboxes_field = true;
                    $db_values = array();
                    $options = $fields[$field_name]['data']['options'];
                    foreach ($options as $option) {
                        $db_values[] = $option['title'];
                    }
                    switch (strtolower($auto_fill_sort)) {
                        case 'desc':
                            sort($db_values);
                            $db_values = array_reverse($db_values);
                            break;
                        case 'descnum':
                            sort($db_values, SORT_NUMERIC);
                            $db_values = array_reverse($db_values);
                            break;
                        case 'none':
                            break;
                        case 'ascnum':
                            sort($db_values, SORT_NUMERIC);
                            break;
                        default:
                            sort($db_values);
                            break;
                    }
                }
            }
        }
        if (!$types_checkboxes_field) {
            if (!function_exists('wpcf_admin_fields_get_fields')) {
                if (defined('WPCF_EMBEDDED_ABSPATH')) {
                    include WPCF_EMBEDDED_ABSPATH . '/includes/fields.php';
                }
            }
            if (function_exists('wpcf_admin_fields_get_fields')) {
                $fields = wpcf_admin_fields_get_fields();
            }
            $field_name = substr($auto_fill, 5);
            if (isset($fields) && isset($fields[$field_name]) && isset($fields[$field_name]['data']['options'])) {
                $display_text = array();
                $options = $fields[$field_name]['data']['options'];
                if (isset($options['default'])) {
                    unset($options['default']);
                }
                // remove the default option from the array
                if (isset($fields[$field_name]['data']['display'])) {
                    $display_option = $fields[$field_name]['data']['display'];
                }
                foreach ($options as $option) {
                    if (isset($option['value'])) {
                        $db_values[] = $option['value'];
                    }
                    if (isset($display_option) && 'value' == $display_option && isset($option['display_value'])) {
                        $display_text[$option['value']] = $option['display_value'];
                        // fill an array with the actual display values
                    } else {
                        $display_text[$option['value']] = $option['title'];
                    }
                }
            } else {
                global $wpdb;
                switch (strtolower($auto_fill_sort)) {
                    case 'desc':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value DESC");
                        break;
                    case 'descnum':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value + 0 DESC");
                        break;
                    case 'none':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}'");
                        break;
                    case 'ascnum':
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value + 0 ASC");
                        break;
                    default:
                        $db_values = $wpdb->get_col("SELECT DISTINCT meta_value FROM {$wpdb->postmeta} WHERE meta_key = '{$auto_fill}' ORDER BY meta_value ASC");
                        break;
                }
            }
        }
        if ($auto_fill_default != '') {
            $values = '';
            $display_values = $auto_fill_default;
            $first = false;
        } else {
            $values = '';
            $display_values = '';
            $first = true;
        }
        foreach ($db_values as $value) {
            if ($value) {
                if (!$first) {
                    $values .= ',';
                    $display_values .= ',';
                }
                $values .= $value;
                if (isset($display_text[$value])) {
                    $display_values .= $display_text[$value];
                } else {
                    $display_values .= $value;
                }
                $first = false;
            }
        }
    }
    $out = '';
    // Use when values attributes are defined (predefined values to list)
    if (!empty($values)) {
        $values_arr = explode(',', $values);
        if (!empty($display_values)) {
            $display_values = explode(',', $display_values);
        }
        $options = array();
        if (!in_array($type, array('radio', 'radios', 'select', 'checkboxes'))) {
            $type = 'select';
        }
        if ($type == 'radio') {
            $type = 'radios';
        }
        switch ($type) {
            case 'checkboxes':
                $defaults = array();
                $original_get = null;
                if (isset($auto_fill_default)) {
                    // check if the defaul value already exists and set the appropriate arrays and values
                    $num_auto_fill_default_display = array_count_values($display_values);
                    if (isset($num_auto_fill_default_display[$auto_fill_default]) && $num_auto_fill_default_display[$auto_fill_default] > 1 || in_array($auto_fill_default, $values_arr)) {
                        // if the default value is an existing display value or stored value
                        $values_arr_def = array_shift($values_arr);
                        $display_values_def = array_shift($display_values);
                    }
                    $defaults = explode(',', $auto_fill_default);
                    $defaults = array_map('trim', $defaults);
                }
                if (isset($_GET[$url_param])) {
                    $original_get = $_GET[$url_param];
                    $defaults = $_GET[$url_param];
                    if (is_string($defaults)) {
                        $defaults = explode(',', $defaults);
                    }
                    unset($_GET[$url_param]);
                }
                for ($i = 0; $i < count($values_arr); $i++) {
                    $value = $values_arr[$i];
                    $value = trim($value);
                    // Check for a display value.
                    if (isset($display_values[$i])) {
                        $display_value = $display_values[$i];
                    } else {
                        $display_value = $value;
                    }
                    $options[$value]['#name'] = $url_param . '[]';
                    $options[$value]['#title'] = $display_value;
                    $options[$value]['#value'] = $value;
                    $options[$value]['#default_value'] = in_array($value, $defaults) || in_array($options[$value]['#title'], $defaults);
                    // set default using option titles too
                    //                    $options[$value]['#inline'] = true;
                    //                    $options[$value]['#after'] = '&nbsp;&nbsp;';
                }
                $element = wpv_form_control(array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param . '[]', '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options)));
                if ($original_get) {
                    $_GET[$url_param] = $original_get;
                }
                break;
            default:
                for ($i = 0; $i < count($values_arr); $i++) {
                    $value = $values_arr[$i];
                    $value = trim($value);
                    // Check for a display value.
                    if (isset($display_values[$i])) {
                        $display_value = $display_values[$i];
                    } else {
                        $display_value = $value;
                    }
                    $options[$display_value] = $value;
                }
                if (count($values_arr) != count($options)) {
                    // if the $values_arr has one more item than $options, there is a repeating value reset on creation: the existing default
                    $default_value = reset($options);
                } else {
                    // so the default value in this case is the first element in $values_arr
                    $default_value = $values_arr[0];
                }
                if (isset($_GET[$url_param]) && in_array($_GET[$url_param], $options)) {
                    $default_value = $_GET[$url_param];
                }
                $element = wpv_form_control(array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => $default_value)));
                break;
        }
        return $element;
    } else {
        if (!empty($field)) {
            // check if Types is active
            if (!function_exists('wpcf_admin_fields_get_field')) {
                if (defined('WPCF_EMBEDDED_ABSPATH')) {
                    include WPCF_EMBEDDED_ABSPATH . '/includes/fields.php';
                } else {
                    return __('Types plugin is required.', 'wpv-views');
                }
            }
            if (!function_exists('wpv_form_control')) {
                include '../common/functions.php';
            }
            // get field options
            $field_options = wpcf_admin_fields_get_field($field);
            if (empty($field_options)) {
                return __('Empty field values or incorrect field defined. ', 'wpv-views');
            }
            $field_options['name'] = wpcf_translate('field ' . $field_options['id'] . ' name', $field_options['name']);
            // get the type of custom field (radio, checkbox, other)
            $field_type = $field_options['type'];
            // override with type
            if (!empty($type)) {
                $field_type = $type;
            }
            if (!in_array($field_type, array('radio', 'checkbox', 'checkboxes', 'select', 'textfield', 'date', 'datepicker'))) {
                $field_type = 'textfield';
            }
            // Radio field
            if ($field_type == 'radio') {
                $field_radio_options = $field_options['data']['options'];
                $options = array();
                foreach ($field_radio_options as $key => $opts) {
                    if (is_array($opts)) {
                        if (isset($field_options['data']['display']) && 'value' == $field_options['data']['display'] && isset($opts['display_value'])) {
                            $options[$opts['display_value']] = $opts['value'];
                            // if we have an actual display value and is set to be used, use it
                        } else {
                            $options[$opts['title']] = $opts['value'];
                            // else, use the field value title
                        }
                    }
                }
                // get the form content
                $element = wpv_form_control(array('field' => array('#type' => 'radios', '#id' => 'wpv_control_radio_' . $field, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => isset($_GET[$url_param]) ? $_GET[$url_param] : null)));
                return $element;
            } else {
                if ($field_type == 'checkbox') {
                    if (isset($atts['title'])) {
                        $checkbox_name = $title;
                    } else {
                        $checkbox_name = $field_options['name'];
                    }
                    $element = wpv_form_control(array('field' => array('#type' => 'checkbox', '#id' => 'wpv_control_checkbox_' . $field, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#title' => $checkbox_name, '#value' => $field_options['data']['set_value'], '#default_value' => 0)));
                    return $element;
                } else {
                    if ($field_type == 'checkboxes') {
                        $defaults = array();
                        $original_get = null;
                        if (isset($_GET[$url_param])) {
                            $original_get = $_GET[$url_param];
                            $defaults = $_GET[$url_param];
                            if (is_string($defaults)) {
                                $defaults = explode(',', $defaults);
                            }
                            unset($_GET[$url_param]);
                        }
                        foreach ($field_options['data']['options'] as $value) {
                            $value = trim($value['title']);
                            $display_value = $value;
                            $options[$value]['#name'] = $url_param . '[]';
                            $options[$value]['#title'] = $display_value;
                            $options[$value]['#value'] = $value;
                            $options[$value]['#default_value'] = in_array($value, $defaults);
                            //                $options[$value]['#inline'] = true;
                            //                $options[$value]['#after'] = '&nbsp;&nbsp;';
                        }
                        $element = wpv_form_control(array('field' => array('#type' => 'checkboxes', '#id' => 'wpv_control_checkbox_' . $field, '#name' => $url_param . '[]', '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options)));
                        if ($original_get) {
                            $_GET[$url_param] = $original_get;
                        }
                        return $element;
                    } else {
                        if ($field_type == 'select') {
                            $field_select_options = $field_options['data']['options'];
                            $options = array();
                            foreach ($field_select_options as $key => $opts) {
                                if (is_array($opts)) {
                                    $options[$opts['title']] = $opts['value'];
                                }
                            }
                            $default_value = false;
                            if (isset($_GET[$url_param]) && in_array($_GET[$url_param], $options)) {
                                $default_value = $_GET[$url_param];
                            }
                            $element = wpv_form_control(array('field' => array('#type' => 'select', '#id' => 'wpv_control_select_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#options' => $options, '#default_value' => $default_value)));
                            return $element;
                        } else {
                            if ($field_type == 'textfield') {
                                $default_value = '';
                                if (isset($_GET[$url_param])) {
                                    $default_value = esc_attr($_GET[$url_param]);
                                }
                                $element = wpv_form_control(array('field' => array('#type' => 'textfield', '#id' => 'wpv_control_textfield_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value)));
                                return $element;
                            } else {
                                if ($field_type == 'date' || $field_type == 'datepicker') {
                                    $out = wpv_render_datepicker($url_param, $date_format);
                                    return $out;
                                }
                            }
                        }
                    }
                }
            }
            return '';
        } else {
            // type parameter without values
            $default_value = '';
            if (isset($_GET[$url_param])) {
                $default_value = $_GET[$url_param];
            }
            switch ($type) {
                case 'checkbox':
                    $element = array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value));
                    $element['field']['#title'] = $title;
                    $element = wpv_form_control($element);
                    break;
                case 'datepicker':
                    $element = wpv_render_datepicker($url_param, $date_format);
                    break;
                default:
                    $element = array('field' => array('#type' => $type, '#id' => 'wpv_control_' . $type . '_' . $url_param, '#name' => $url_param, '#attributes' => array('style' => ''), '#inline' => true, '#value' => $default_value));
                    $element = wpv_form_control($element);
                    break;
            }
            return $element;
        }
    }
}
Example #21
0
/**
 * Calls view function for specific field type by single field.
 * 
 * @param type $field
 * @param type $atts
 * @return type 
 */
function types_render_field_single($field, $params, $content = null, $code = '')
{
    global $post;
    // Count fields (if there are duplicates)
    static $count = array();
    // Count it
    if (!isset($count[$field['slug']])) {
        $count[$field['slug']] = 1;
    } else {
        $count[$field['slug']] += 1;
    }
    // Load type
    $type = wpcf_fields_type_action($field['type']);
    // If 'class' or 'style' parameters are set - force HTML output
    if ((!empty($params['class']) || !empty($params['style'])) && $field['type'] != 'date') {
        $params['output'] = 'html';
    }
    // Apply filters to field value
    $params['field_value'] = apply_filters('wpcf_fields_value_display', $params['field_value'], $params);
    $params['field_value'] = apply_filters('wpcf_fields_slug_' . $field['slug'] . '_value_display', $params['field_value'], $params);
    $params['field_value'] = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_display', $params['field_value'], $params);
    // To make sure
    if (is_string($params['field_value'])) {
        $params['field_value'] = addslashes(stripslashes($params['field_value']));
    }
    // Set values
    $field['name'] = wpcf_translate('field ' . $field['id'] . ' name', $field['name']);
    $params['field'] = $field;
    $params['#content'] = htmlspecialchars($content);
    $params['#code'] = $code;
    $output = '';
    if (isset($params['raw']) && $params['raw'] == 'true') {
        // Skype is array
        if ($field['type'] == 'skype' && isset($params['field_value']['skypename'])) {
            $output = $params['field_value']['skypename'];
        } else {
            $output = $params['field_value'];
        }
    } else {
        $output = wpcf_fields_type_action($field['type'], 'view', $params);
        // Convert to string
        if (!empty($output)) {
            $output = strval($output);
        }
        // If no output
        if (empty($output) && !empty($params['field_value'])) {
            $output = wpcf_frontend_wrap_field_value($field, $params['field_value'], $params);
            $output = wpcf_frontend_wrap_field($field, $output, $params);
        } else {
            if ($output != '__wpcf_skip_empty') {
                $output = wpcf_frontend_wrap_field_value($field, $output, $params);
                $output = wpcf_frontend_wrap_field($field, $output, $params);
            } else {
                $output = '';
            }
        }
        // Add count
        if (isset($count[$field['slug']]) && intval($count[$field['slug']]) > 1) {
            $add = '-' . intval($count[$field['slug']]);
            $output = str_replace('id="wpcf-field-' . $field['slug'] . '"', 'id="wpcf-field-' . $field['slug'] . $add . '"', $output);
        }
    }
    // Apply filters
    $output = strval(apply_filters('types_view', $output, $params['field_value'], $field['type'], $field['slug'], $field['name'], $params));
    return htmlspecialchars_decode(stripslashes($output));
}
Example #22
0
function wpcf_admin_render_fields($group, $user_id, $echo = '')
{
    global $wpcf;
    $output = '<div class="wpcf-group-area wpcf-group-area_' . $group['slug'] . '">' . "\n\n";
    $output .= '<h3>' . wpcf_translate('group ' . $group['id'] . ' name', $group['name']) . '</h3>' . "\n\n";
    if (!empty($group['fields'])) {
        // Display description
        if (!empty($group['description'])) {
            $output .= '<span>' . wpautop(wpcf_translate('group ' . $group['id'] . ' description', $group['description'])) . '</span>' . "\n\n";
        }
        $output .= '<div class="wpcf-profile-field-line">' . "\n\n";
        foreach ($group['fields'] as $field_slug => $field) {
            if (empty($field) || !is_array($field)) {
                continue;
            }
            $field = $wpcf->usermeta_field->_parse_cf_form_element($field);
            if (!isset($field['#id'])) {
                $field['#id'] = wpcf_unique_id(serialize($field));
            }
            if (isset($field['wpcf-type'])) {
                // May be ignored
                $field = apply_filters('wpcf_fields_' . $field['wpcf-type'] . '_meta_box_form_value_display', $field);
            }
            // Render form elements
            if (wpcf_compare_wp_version() && $field['#type'] == 'wysiwyg') {
                $field['#editor_settings']['media_buttons'] = '';
                if (!empty($echo)) {
                    $field['#editor_settings']['wpautop'] = true;
                }
                // Especially for WYSIWYG
                $output .= "\n" . '<div class="wpcf-profile-field-line">' . "\n\n";
                $output .= '<div class="wpcf-wysiwyg">' . "\n\n";
                $output .= '<div id="wpcf-textarea-textarea-wrapper" class="form-item form-item-textarea wpcf-form-item wpcf-form-item-textarea">' . "\n\n";
                $output .= isset($field['#before']) ? $field['#before'] : '';
                $output .= '<label class="wpcf-form-label wpcf-form-textarea-label">' . $field['#title'] . '</label>' . "\n\n";
                $output .= '<div class="description wpcf-form-description wpcf-form-description-textarea description-textarea">' . "\n\n" . wpautop($field['#description']) . '</div>' . "\n\n";
                ob_start();
                wp_editor($field['#value'], $field['#id'], $field['#editor_settings']);
                $output .= ob_get_clean() . "\n\n";
                $field['slug'] = str_replace(WPCF_META_PREFIX . 'wysiwyg-', '', $field_slug);
                $field['type'] = 'wysiwyg';
                $output .= '</div>' . "\n\n";
                $output .= isset($field['#after']) ? $field['#after'] : '';
                $output .= '</div>' . "\n\n";
                $output .= '</div>' . "\n\n";
            } else {
                if ($field['#type'] == 'wysiwyg') {
                    $field['#type'] = 'textarea';
                }
                $field['#pattern'] = "\n" . '<div class="wpcf-profile-field-line">
	<div class="wpcf-profile-line-left">
		<LABEL><DESCRIPTION>
	</div>
	<div class="wpcf-profile-line-right"><BEFORE><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER></div>
</div>' . "\n\n";
                if (isset($field['#name']) && (strpos($field['#name'], '[hour]') !== false || strpos($field['#name'], '[minute]') !== false)) {
                    if (isset($field['#attributes']) && $field['#attributes']['class'] == 'wpcf-repetitive') {
                        $field['#pattern'] = strpos($field['#name'], '[hour]') !== false ? __('Hour', 'wpcf') : __('Minute', 'wpcf');
                        $field['#pattern'] .= '<LABEL><DESCRIPTION><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER>' . "\n\n";
                    } else {
                        if (strpos($field['#name'], '[hour]') !== false) {
                            $field['#pattern'] = "\n" . '<div class="wpcf-profile-field-line">
	<div class="wpcf-profile-line-left">&nbsp;&nbsp;&nbsp;&nbsp;' . __('Time', 'wpcf') . '</div>
	<div class="wpcf-profile-line-right">
	<LABEL><DESCRIPTION><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER>' . "\n";
                        } else {
                            $field['#pattern'] = "\n" . '
	<LABEL><DESCRIPTION><ERROR><PREFIX><ELEMENT><SUFFIX><AFTER></div>
</div>' . "\n\n";
                        }
                    }
                }
                if (!empty($echo)) {
                    $field['#validate'] = '';
                }
                $output .= wpcf_form_simple(array($field['#id'] => $field));
            }
        }
        $output .= '</div>';
    }
    /*
     * TODO Move to Conditional code
     *
     * This is already checked. Use hook to add wrapper DIVS and apply CSS.
     */
    if (!empty($group['_conditional_display'])) {
        $output .= '</div>';
    }
    $output .= "\n\n" . '</div>';
    if (!empty($echo)) {
        return $output;
    } else {
        echo $output;
    }
}
Example #23
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_checkboxes_view($params)
{
    $option = array();
    if (!isset($params['option']) || empty($params['field']['data']['options'])) {
        return '__wpcf_skip_empty';
    }
    $i = 0;
    foreach ($params['field']['data']['options'] as $option_key => $option_value) {
        if (intval($params['option']) == $i) {
            $option['key'] = $option_key;
            $option['data'] = $option_value;
            $option['value'] = isset($params['field_value'][$option_key]) ? $params['field_value'][$option_key] : '__wpcf_unchecked';
            break;
        }
        $i++;
    }
    $output = '';
    if (isset($params['state']) && $params['state'] == 'unchecked' && $option['value'] == '__wpcf_unchecked') {
        return htmlspecialchars_decode($params['#content']);
    } else {
        if (isset($params['state']) && $params['state'] == 'unchecked') {
            return '__wpcf_skip_empty';
        }
    }
    if (isset($params['state']) && $params['state'] == 'checked' && $option['value'] != '__wpcf_unchecked') {
        return htmlspecialchars_decode($params['#content']);
    } else {
        if (isset($params['state']) && $params['state'] == 'checked') {
            return '__wpcf_skip_empty';
        }
    }
    //    if (!empty($params['#content'])) {
    //        return htmlspecialchars_decode($params['#content']);
    //    }
    if ($option['data']['display'] == 'db' && !empty($option['data']['set_value']) && $option['value'] != '__wpcf_unchecked') {
        $output = $option['data']['set_value'];
        $output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value', $output);
    } else {
        if ($option['data']['display'] == 'value' && $option['value'] != '__wpcf_unchecked') {
            if (isset($option['data']['display_value_selected'])) {
                $output = $option['data']['display_value_selected'];
                $output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value selected', $output);
            }
        } else {
            if ($option['data']['display'] == 'value') {
                if (isset($option['data']['display_value_not_selected'])) {
                    $output = $option['data']['display_value_not_selected'];
                    $output = wpcf_translate('field ' . $params['field']['id'] . ' checkbox value not selected', $output);
                }
            }
        }
    }
    if (empty($output)) {
        return '__wpcf_skip_empty';
    }
    return $output;
}
Example #24
0
/**
 * Calls view function for specific field type by single field.
 *
 * @param type $field
 * @param type $atts
 * @return type
 */
function types_render_field_single($field, $params, $content = null, $code = '', $meta_id = null)
{
    global $post;
    if (empty($post)) {
        $post = (object) array('ID' => '');
    }
    // Apply filters to field value
    if (is_string($params['field_value'])) {
        $params['field_value'] = trim($params['field_value']);
    }
    $params = apply_filters('types_field_shortcode_parameters', $params, $field, $post, $meta_id);
    $params['field_value'] = apply_filters('wpcf_fields_value_display', $params['field_value'], $params, $post->ID, $field['id'], $meta_id);
    $params['field_value'] = apply_filters('wpcf_fields_slug_' . $field['slug'] . '_value_display', $params['field_value'], $params, $post->ID, $field['id'], $meta_id);
    $params['field_value'] = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_display', $params['field_value'], $params, $post->ID, $field['id'], $meta_id);
    // To make sure
    if (is_string($params['field_value'])) {
        $params['field_value'] = addslashes(stripslashes(strval($params['field_value'])));
    }
    // Note that $params['field_value'] does NOT need translating
    // When a variable string or label output needs translating we do it on 'wpcf_fields_type_' . $field['type'] . '_value_display' on a field type basis
    $field['name'] = wpcf_translate('field ' . $field['id'] . ' name', $field['name']);
    $params['field'] = $field;
    $params['#content'] = htmlspecialchars($content);
    $params['#code'] = $code;
    // Set additional data
    $params['__meta_id'] = $meta_id;
    $params['field']['__meta_id'] = $meta_id;
    if (isset($params['raw']) && $params['raw'] == 'true' || isset($params['output']) && $params['output'] == 'raw') {
        // Skype is array
        if ($field['type'] == 'skype' && isset($params['field_value']['skypename'])) {
            $output = $params['field_value']['skypename'];
        } else {
            if ($field['type'] == 'checkboxes' && is_array($params['field_value'])) {
                $output = '';
                foreach ($params['field_value'] as $value) {
                    if ($output != '') {
                        $output .= ', ';
                    }
                    $output .= $value[0];
                }
            } else {
                $output = $params['field_value'];
            }
        }
    } else {
        /*
         * This is place where view function is called.
         * Returned data should be string.
         */
        $output = '';
        $_view_func = 'wpcf_fields_' . strtolower($field['type']) . '_view';
        if (is_callable($_view_func)) {
            $output = strval(call_user_func($_view_func, $params));
        }
        // If no output
        if (empty($output) && isset($params['field_value']) && $params['field_value'] !== "") {
            $output = $params['field_value'];
        } else {
            if ($output == '__wpcf_skip_empty') {
                $output = '';
            }
        }
        if (isset($params['output']) && $params['output'] == 'html') {
            $output = wpcf_frontend_compat_html_output($output, $field, $content, $params);
        } else {
            // Prepend name if needed
            if (!empty($output) && isset($params['show_name']) && $params['show_name'] == 'true') {
                $output = $params['field']['name'] . ': ' . $output;
            }
        }
    }
    // Apply filters
    $output = strval(apply_filters('types_view', $output, $params['field_value'], $field['type'], $field['slug'], $field['name'], $params));
    return stripslashes(strval($output));
}
/**
 * Creates form elements.
 * 
 * @param type $post
 * @param type $fields
 * @return type 
 */
function wpcf_admin_post_process_fields($post = false, $fields = array())
{
    global $pagenow;
    // Get cached
    static $cache = array();
    $cache_key = $post ? $post->ID : false;
    if ($cache_key && isset($cache[$cache_key])) {
        return $cache[$cache_key];
    }
    $fields_processed = array();
    // Get invalid fields (if submitted)
    if ($post) {
        $invalid_fields = get_post_meta($post->ID, 'wpcf-invalid-fields', true);
        delete_post_meta($post->ID, 'wpcf-invalid-fields');
    }
    $original_cf = array();
    if (function_exists('wpml_get_copied_fields_for_post_edit')) {
        $original_cf = wpml_get_copied_fields_for_post_edit();
    }
    foreach ($fields as $field) {
        $field = wpcf_admin_fields_get_field($field['id']);
        if (!empty($field)) {
            $field_id = 'wpcf-' . $field['type'] . '-' . $field['slug'];
            $field_init_data = wpcf_fields_type_action($field['type']);
            // Get inherited field
            $inherited_field_data = false;
            if (isset($field_init_data['inherited_field_type'])) {
                $inherited_field_data = wpcf_fields_type_action($field_init_data['inherited_field_type']);
            }
            // Set value
            $field['value'] = '';
            if ($post) {
                $field['value'] = get_post_meta($post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
            } else {
                // see if it's in the original custom fields to copy.
                if (!empty($original_cf['fields'])) {
                    foreach ($original_cf['fields'] as $cf_id) {
                        if (wpcf_types_get_meta_prefix($field) . $field['slug'] == $cf_id) {
                            $field['wpml_action'] = 'copy';
                            $field['value'] = get_post_meta($original_cf['original_post_id'], wpcf_types_get_meta_prefix($field) . $field['slug'], true);
                            break;
                        }
                    }
                }
            }
            // Mark any field that is going to be copied.
            if (!empty($original_cf['fields'])) {
                foreach ($original_cf['fields'] as $cf_id) {
                    if (wpcf_types_get_meta_prefix($field) . $field['slug'] == $cf_id) {
                        //                        $field['description_extra'] = $original_cf['copy_message'];
                        $field['readonly'] = true;
                        $field['wpml_action'] = 'copy';
                        break;
                    }
                }
            }
            // Apply filters
            $field['value'] = apply_filters('wpcf_fields_value_get', $field['value'], $field, $field_init_data);
            $field['value'] = apply_filters('wpcf_fields_slug_' . $field['slug'] . '_value_get', $field['value'], $field, $field_init_data);
            $field['value'] = apply_filters('wpcf_fields_type_' . $field['type'] . '_value_get', $field['value'], $field, $field_init_data);
            // Process JS
            if (!empty($field_init_data['meta_box_js'])) {
                foreach ($field_init_data['meta_box_js'] as $handle => $data) {
                    if (isset($data['inline'])) {
                        add_action('admin_footer', $data['inline']);
                        continue;
                    }
                    $deps = !empty($data['deps']) ? $data['deps'] : array();
                    $in_footer = !empty($data['in_footer']) ? $data['in_footer'] : false;
                    wp_register_script($handle, $data['src'], $deps, WPCF_VERSION, $in_footer);
                    wp_enqueue_script($handle);
                }
            }
            // Process CSS
            if (!empty($field_init_data['meta_box_css'])) {
                foreach ($field_init_data['meta_box_css'] as $handle => $data) {
                    if (isset($data['src'])) {
                        $deps = !empty($data['deps']) ? $data['deps'] : array();
                        wp_enqueue_style($handle, $data['src'], $deps, WPCF_VERSION);
                    } else {
                        if (isset($data['inline'])) {
                            add_action('admin_head', $data['inline']);
                        }
                    }
                }
            }
            $element = array();
            // Set inherited values
            if ($inherited_field_data) {
                if (function_exists('wpcf_fields_' . $field_init_data['inherited_field_type'] . '_meta_box_form')) {
                    $element = call_user_func('wpcf_fields_' . $field_init_data['inherited_field_type'] . '_meta_box_form', $field);
                }
            }
            // Set generic values
            $element = array_merge(array('#type' => isset($field_init_data['inherited_field_type']) ? $field_init_data['inherited_field_type'] : $field['type'], '#id' => $field_id, '#title' => wpcf_translate('field ' . $field['id'] . ' name', $field['name']), '#description' => wpautop(wpcf_translate('field ' . $field['id'] . ' description', $field['description'])), '#name' => 'wpcf[' . $field['slug'] . ']', '#value' => isset($field['value']) ? $field['value'] : '', 'wpcf-id' => $field['id'], 'wpcf-slug' => $field['slug'], 'wpcf-type' => $field['type']), $element);
            if (isset($field['description_extra'])) {
                $element['#description'] .= wpautop($field['description_extra']);
            }
            // Set atributes #1
            if (isset($field['disable'])) {
                $field['#disable'] = $field['disable'];
            }
            if (!empty($field['disable'])) {
                $field['#attributes']['disabled'] = 'disabled';
            }
            if (!empty($field['readonly'])) {
                $field['#attributes']['readonly'] = 'readonly';
            }
            // Set specific values
            if (defined('WPCF_INC_ABSPATH') && file_exists(WPCF_INC_ABSPATH . '/fields/' . $field['type'] . '.php')) {
                require_once WPCF_INC_ABSPATH . '/fields/' . $field['type'] . '.php';
            }
            // Load field
            // TODO remove
            //            wpcf_fields_type_action($field['type']);
            //            require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields/' . $field['type']
            //                    . '.php';
            if (function_exists('wpcf_fields_' . $field['type'] . '_meta_box_form')) {
                $element_specific = call_user_func('wpcf_fields_' . $field['type'] . '_meta_box_form', $field);
                // Check if it's single
                if (isset($element_specific['#type'])) {
                    // Format description
                    if (!empty($element_specific['#description'])) {
                        $element_specific['#description'] = wpautop($element_specific['#description']);
                    }
                    $element = array_merge($element, $element_specific);
                } else {
                    // More fields, loop all
                    foreach ($element_specific as $element_specific_fields_key => $element_specific_fields_value) {
                        // Format description
                        if (!empty($element_specific_fields_value['#description'])) {
                            $element_specific_fields_value['#description'] = wpautop($element_specific_fields_value['#description']);
                        }
                        // If no ID
                        if (!isset($element_specific_fields_value['#id'])) {
                            $element_specific_fields_value['#id'] = 'wpcf-' . $field['slug'] . '-' . mt_rand();
                        }
                        // If no name, name = #ignore or id = #ignore - IGNORE
                        if (!isset($element_specific_fields_value['#name']) || $element_specific_fields_value['#name'] == '#ignore' || $element_specific_fields_value['#id'] == '#ignore') {
                            $element_specific_fields_value['#id'] = 'wpcf-' . $field['slug'] . '-' . mt_rand();
                            $element_specific_fields_value['#name'] = 'wpcf[ignore][' . mt_rand() . ']';
                            $fields_processed[$element_specific_fields_value['#id']] = $element_specific_fields_value;
                            continue;
                        }
                        // This one is actually value and keep it (#name is required)
                        $element = array_merge($element, $element_specific_fields_value);
                        // Add it here to keep order
                        $fields_processed[$element['#id']] = $element;
                    }
                }
            }
            // Set atributes #2 (override)
            if (isset($field['disable'])) {
                $element['#disable'] = $field['disable'];
            }
            if (!empty($field['disable'])) {
                $element['#attributes']['disabled'] = 'disabled';
            }
            if (!empty($field['readonly'])) {
                $element['#attributes']['readonly'] = 'readonly';
                if (!empty($element['#options'])) {
                    foreach ($element['#options'] as $key => $option) {
                        if (!is_array($option)) {
                            $element['#options'][$key] = array('#title' => $key, '#value' => $option);
                        }
                        $element['#options'][$key]['#attributes']['readonly'] = 'readonly';
                        if ($element['#type'] == 'select') {
                            $element['#options'][$key]['#attributes']['disabled'] = 'disabled';
                        }
                    }
                }
                if ($element['#type'] == 'select') {
                    $element['#attributes']['disabled'] = 'disabled';
                }
            }
            // Set validation element
            if (isset($field['data']['validate'])) {
                $element['#validate'] = $field['data']['validate'];
            }
            // Check if it was invalid no submit and add error message
            if ($post && !empty($invalid_fields)) {
                if (isset($invalid_fields[$element['#id']]['#error'])) {
                    $element['#error'] = $invalid_fields[$element['#id']]['#error'];
                }
            }
            // Set WPML locked icon
            if (isset($field['wpml_action']) && $field['wpml_action'] == 'copy') {
                $element['#title'] .= '<img src="' . WPCF_EMBEDDED_RES_RELPATH . '/images/locked.png" alt="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" title="' . __('This field is locked for editing because WPML will copy its value from the original language.', 'wpcf') . '" style="position:relative;left:2px;top:2px;" />';
            }
            // Add to editor
            wpcf_admin_post_add_to_editor($field);
            // Add shortcode info
            //            $shortcode = '<div class="wpcf-shortcode">'
            //                    . __('Shortcode:', 'wpcf') . ' '
            //                    . '<span class="code">' . wpcf_fields_get_shortcode($field)
            //                    . '</span></div>';
            //            if (isset($element['#after']) && strpos($element['#after'],
            //                            'class="wpcf-shortcode"') === FALSE) {
            //                $element['#after'] .= $shortcode;
            //            } else {
            //                $element['#after'] = $shortcode;
            //            }
            $fields_processed[$element['#id']] = $element;
        }
    }
    if ($cache_key && isset($cache[$cache_key])) {
        $cache[$cache_key] = $fields_processed;
    }
    return $fields_processed;
}
Example #26
0
 /**
  * Sets field meta box form.
  *
  * @return type
  */
 function _get_meta_form($meta_value = null, $meta_id = null, $wrap = true)
 {
     /*
      * Note that field may be registered outside of Types.
      * In that case, it's on developer to make sure it's loaded.
      */
     $this->_include_file_by_field_type($this->cf['type']);
     /*
      * Set value
      *
      * IMPORTANT
      * Here we set values for form elements
      */
     $this->cf['value'] = is_null($meta_value) ? $this->meta : $meta_value;
     $form = array();
     $form_meta_box = array();
     $inherited = array();
     $this->__multiple = false;
     // Open main wrapper
     if ($wrap) {
         $form['__meta_form_OPEN'] = array('#type' => 'markup', '#markup' => '' . '<div id="wpcf_wrapper_' . $this->unique_id . '" class="wpcf-wrap wpcf-meta-form">');
     }
     /*
      *
      *
      *
      *
      * Since Types 1.2
      * Avoid using parent (inherited) type
      * $this->config->inherited_field_type
      */
     // See if inherited data and merge
     if (isset($this->config->inherited_field_type)) {
         if (!array_key_exists($this->cf['type'], $this->_deprecated_inherited_allowed())) {
             //                _deprecated_argument( 'inherited_field_type', '1.2',
             //                        'Since Types 1.2 we encourage developers to completely define fields' );
         }
         $file = $this->_include_file_by_field_type($this->config->inherited_field_type);
         if (file_exists($file)) {
             if (function_exists('wpcf_fields_' . $this->config->inherited_field_type . '_meta_box_form')) {
                 $inherited = call_user_func_array('wpcf_fields_' . $this->config->inherited_field_type . '_meta_box_form', array($this->cf, $this));
                 // If single form - convert to array of elements
                 if (isset($inherited['#type'])) {
                     $inherited = array('wpcf_field_' . $this->unique_id => $inherited);
                 }
                 // One value?
                 if (count($inherited) > 1) {
                     $this->__multiple = true;
                 }
                 $form = $form + $inherited;
             }
         }
     }
     $func = 'wpcf_fields_' . $this->cf['type'] . '_meta_box_form';
     if (is_callable($func)) {
         /*
          *
          * From Types 1.2 use complete form setup
          */
         $form_meta_box = call_user_func_array('wpcf_fields_' . $this->cf['type'] . '_meta_box_form', array($this->cf, $this));
         // If single form - convert to array of elements
         if (isset($form_meta_box['#type'])) {
             $form_meta_box = array('wpcf_field_' . $this->unique_id => $form_meta_box);
         }
         // One value?
         if (count($form_meta_box) > 1) {
             $this->__multiple = true;
         }
         // Merge
         $form = array_merge($form, $form_meta_box);
     }
     if (!empty($form)) {
         // Process each field
         foreach ($form as $element_key => $element) {
             /*
              *
              * Start using __ in keys to skip element
              */
             // Skip protected
             if (strpos($element_key, '__') === 0) {
                 $form[$element_key] = $element;
                 continue;
             }
             // Add title and description
             // TODO WPML
             if (empty($started)) {
                 $_title = isset($element['#title']) ? $element['#title'] : $this->cf['name'];
                 $element['#title'] = wpcf_translate('field ' . $this->cf['id'] . ' name', $_title);
                 // Add asterisk for required fields
                 if (isset($this->cf['data']['validate']['required'])) {
                     $element['#title'] .= '&#42;';
                 }
                 $_description = isset($element['#description']) ? $element['#description'] : $this->cf['description'];
                 $element['#description'] = wpautop(wpcf_translate('field ' . $this->cf['id'] . ' description', $_description));
                 $started = true;
             }
             // Set current element
             $this->__current_form_element = $element;
             // Process field
             $temp_processed = wpcf_admin_post_process_field($this);
             if (!empty($temp_processed['element'])) {
                 $element = $temp_processed['element'];
             }
             // Set form element
             $form[$element_key] = apply_filters('wpcf_post_edit_field', $element, $this->cf, $this->post, $this->context);
         }
         // Add to editor
         if ($this->add_to_editor) {
             wpcf_admin_post_add_to_editor($this->cf);
         }
         $this->enqueue_script();
         $this->enqueue_style();
     }
     // Close main wrapper
     if ($wrap) {
         $form['meta_form_CLOSE'] = array('#type' => 'markup', '#markup' => '' . '</div>');
     }
     // Add unique IDs
     foreach ($form as $k => $v) {
         $_form[$k . '_' . $this->unique_id] = $v;
     }
     return apply_filters('wpcf_meta_form', $_form);
 }
Example #27
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_checkboxes_view($params)
{
    $option = array();
    if (empty($params['field']['data']['options'])) {
        return '__wpcf_skip_empty';
    }
    // If no option specified, display all of them
    if (!isset($params['option'])) {
        $separator = isset($params['separator']) ? $params['separator'] : ', ';
        foreach ($params['field_value'] as $name => &$value) {
            if (isset($params['field']['data']['options'][$name])) {
                $option = $params['field']['data']['options'][$name];
            } else {
                unset($params['field_value'][$name]);
                continue;
            }
            if ($option['display'] == 'db' && !empty($option['set_value']) && !empty($value)) {
                $value = $option['set_value'];
                $value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $name . ' value', $value);
            } else {
                if ($option['display'] == 'value') {
                    if (isset($option['display_value_selected']) && !empty($value)) {
                        $value = $option['display_value_selected'];
                        $value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $name . ' display value selected', $value);
                    } else {
                        $value = $option['display_value_not_selected'];
                        $value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $name . ' display value not selected', $value);
                    }
                } else {
                    unset($params['field_value'][$name]);
                }
            }
        }
        $output = implode(array_values($params['field_value']), $separator);
        return $output;
    }
    $i = 0;
    foreach ($params['field']['data']['options'] as $option_key => $option_value) {
        if (intval($params['option']) == $i) {
            $option['key'] = $option_key;
            $option['data'] = $option_value;
            $option['value'] = !empty($params['field_value'][$option_key]) ? $params['field_value'][$option_key] : '__wpcf_unchecked';
            break;
        }
        $i++;
    }
    $output = '';
    if (isset($params['state']) && $params['state'] == 'unchecked' && $option['value'] == '__wpcf_unchecked') {
        return htmlspecialchars_decode($params['#content']);
    } else {
        if (isset($params['state']) && $params['state'] == 'unchecked') {
            return '__wpcf_skip_empty';
        }
    }
    if (isset($params['state']) && $params['state'] == 'checked' && $option['value'] != '__wpcf_unchecked') {
        return htmlspecialchars_decode($params['#content']);
    } else {
        if (isset($params['state']) && $params['state'] == 'checked') {
            return '__wpcf_skip_empty';
        }
    }
    if ($option['data']['display'] == 'db' && !empty($option['data']['set_value']) && $option['value'] != '__wpcf_unchecked') {
        $output = $option['data']['set_value'];
        $output = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option['key'] . ' value', $output);
    } else {
        if ($option['data']['display'] == 'value' && $option['value'] != '__wpcf_unchecked') {
            if (isset($option['data']['display_value_selected'])) {
                $output = $option['data']['display_value_selected'];
                $output = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option['key'] . ' display value selected', $output);
            }
        } else {
            if ($option['data']['display'] == 'value') {
                if (isset($option['data']['display_value_not_selected'])) {
                    $output = $option['data']['display_value_not_selected'];
                    $output = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option['key'] . ' display value not selected', $output);
                }
            }
        }
    }
    if (empty($output)) {
        return '__wpcf_skip_empty';
    }
    return $output;
}
Example #28
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_radio_view($params)
{
    if (isset($params['style']) && $params['style'] == 'raw') {
        return '';
    }
    if (isset($params['usermeta']) && !empty($params['usermeta'])) {
        $field = wpcf_fields_get_field_by_slug($params['field']['slug'], 'wpcf-usermeta');
    } else {
        $field = wpcf_fields_get_field_by_slug($params['field']['slug']);
    }
    $output = '';
    // See if user specified output for each field
    if (isset($params['option'])) {
        foreach ($field['data']['options'] as $option_key => $option) {
            if (isset($option['value'])) {
                $test_val = stripslashes(strval($option['value']));
                if ($test_val == $params['field_value'] && $option_key == $params['option']) {
                    return htmlspecialchars_decode($params['#content']);
                }
            }
        }
        //        return ' ';
        return '__wpcf_skip_empty';
    }
    if (!empty($field['data']['options'])) {
        $field_value = $params['field_value'];
        foreach ($field['data']['options'] as $option_key => $option) {
            if (isset($option['value']) && stripslashes($option['value']) == stripslashes($params['field_value'])) {
                $field_value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option_key . ' title', $option['title']);
                if (isset($params['field']['data']['display']) && $params['field']['data']['display'] != 'db' && !empty($option['display_value'])) {
                    $field_value = wpcf_translate('field ' . $params['field']['id'] . ' option ' . $option_key . ' display value', $option['display_value']);
                }
            }
        }
        $output = $field_value;
    }
    return $output;
}
Example #29
0
/**
 * Translates data.
 *
 * @param type $taxonomy
 * @param type $data
 */
function wpcf_wpml_taxonomy_translate($data, $taxonomy)
{
    if (!function_exists('icl_t')) {
        return $data;
    }
    $default = wpcf_custom_taxonomies_default();
    if (!empty($data['description'])) {
        $data['description'] = wpcf_translate($taxonomy . ' description', $data['description'], 'Types-TAX');
    }
    foreach ($data['labels'] as $label => $string) {
        if ($label == 'name' || $label == 'singular_name') {
            $data['labels'][$label] = wpcf_translate($taxonomy . ' ' . $label, $string, 'Types-TAX');
            continue;
        }
        if (!isset($default['labels'][$label]) || $string !== $default['labels'][$label]) {
            $data['labels'][$label] = wpcf_translate($taxonomy . ' ' . $label, $string, 'Types-TAX');
        } else {
            $data['labels'][$label] = wpcf_translate($label, $string, 'Types-TAX');
        }
    }
    return $data;
}