Esempio n. 1
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_numeric_view($params)
{
    $output = '';
    if (!empty($params['format'])) {
        $patterns = array('/FIELD_NAME/', '/FIELD_VALUE/');
        $replacements = array($params['field']['name'], $params['field_value']);
        $output = preg_replace($patterns, $replacements, $params['format']);
        $output = sprintf($output, $params['field_value']);
    }
    $output = wpcf_frontend_wrap_field_value($params['field'], $output, $params);
    $output = wpcf_frontend_wrap_field($params['field'], $output, $params);
    return $output;
}
Esempio n. 2
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_email_view($params)
{
    if ($params['style'] == 'raw') {
        return '';
    }
    $title = '';
    $add = '';
    if (!empty($params['title'])) {
        $add .= ' title="' . $params['title'] . '"';
        $title .= $params['title'];
    } else {
        $add .= ' title="' . $params['field_value'] . '"';
        $title .= $params['field_value'];
    }
    $output = '<a href="mailto:' . $params['field_value'] . '"' . $add . '>' . $title . '</a>';
    $output = wpcf_frontend_wrap_field_value($params['field'], $output, $params);
    return wpcf_frontend_wrap_field($params['field'], $output, $params);
}
Esempio n. 3
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_select_view($params)
{
    if ($params['style'] == 'raw') {
        return '';
    }
    $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']);
            }
        }
        $field_value = wpcf_frontend_wrap_field_value($params['field'], $field_value, $params);
        $output = wpcf_frontend_wrap_field($params['field'], $field_value, $params);
    }
    return $output;
}
Esempio n. 4
0
function wpcf_frontend_compat_html_output($output, $field, $content, $params)
{
    // 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;
    }
    // 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);
    }
    return $output;
}
Esempio n. 5
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;
}
Esempio n. 6
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_skype_view($params)
{
    if (!isset($params['field_value']['skypename'])) {
        return '--';
    }
    // Style can be overrided by params (shortcode)
    if (!isset($params['field_value']['style'])) {
        $params['field_value']['style'] = '';
    }
    $style = !empty($params['style']) && $params['style'] != 'default' ? $params['style'] : $params['field_value']['style'];
    $content = wpcf_fields_skype_get_button($params['field_value']['skypename'], $style);
    return wpcf_frontend_wrap_field($params['field'], $content);
}
Esempio n. 7
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_date_view($params)
{
    global $wp_locale;
    $defaults = array('format' => get_option('date_format'));
    $params = wp_parse_args($params, $defaults);
    $output = '';
    switch ($params['style']) {
        case 'calendar':
            $output .= wpcf_fields_date_get_calendar($params, true, false);
            break;
        default:
            $field_name = '';
            // Extract the Full month and Short month from the format.
            // We'll replace with the translated months if possible.
            $format = $params['format'];
            $format = str_replace('F', '#111111#', $format);
            $format = str_replace('M', '#222222#', $format);
            // Same for the Days
            $format = str_replace('D', '#333333#', $format);
            $format = str_replace('l', '#444444#', $format);
            $date_out = date($format, intval($params['field_value']));
            $month = date('m', intval($params['field_value']));
            $month_full = $wp_locale->get_month($month);
            $date_out = str_replace('#111111#', $month_full, $date_out);
            $month_short = $wp_locale->get_month_abbrev($month_full);
            $date_out = str_replace('#222222#', $month_short, $date_out);
            $day = date('w', intval($params['field_value']));
            $day_full = $wp_locale->get_weekday($day);
            $date_out = str_replace('#333333#', $day_full, $date_out);
            $day_short = $wp_locale->get_weekday_abbrev($day_full);
            $date_out = str_replace('#444444#', $day_short, $date_out);
            $field_value = wpcf_frontend_wrap_field_value($params['field'], $date_out, $params);
            $output = wpcf_frontend_wrap_field($params['field'], $field_value, $params);
            break;
    }
    return $output;
}
Esempio n. 8
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_file_view($params)
{
    $output = '';
    if (isset($params['link']) && $params['link'] == 'true') {
        $title = '';
        $add = '';
        if (!empty($params['title'])) {
            $add .= ' title="' . $params['title'] . '"';
            $title .= $params['title'];
        } else {
            $add .= ' title="' . $params['field_value'] . '"';
            $title .= $params['field_value'];
        }
        if (!empty($params['class'])) {
            $add .= ' class="' . $params['class'] . '"';
        }
        $output = '<a href="' . $params['field_value'] . '"' . $add . '>' . $title . '</a>';
    } else {
        $output = $params['field_value'];
    }
    $output = wpcf_frontend_wrap_field_value($params['field'], $output, $params);
    $output = wpcf_frontend_wrap_field($params['field'], $output, $params);
    return $output;
}
Esempio n. 9
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));
}
Esempio n. 10
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));
}
Esempio n. 11
0
/**
 * View function.
 * 
 * @param type $params 
 */
function wpcf_fields_image_view($params)
{
    $output = '';
    $alt = false;
    $title = false;
    $class = array();
    // Get image data
    $image_data = wpcf_fields_image_get_data($params['field_value']);
    // Display error to admin only
    if (!empty($image_data['error'])) {
        if (current_user_can('administrator')) {
            return '<div style="padding:10px;background-color:Red;color:#FFFFFF;">' . 'Types: ' . $image_data['error'] . '</div>';
        }
        return $params['field_value'];
    }
    if (!$image_data['is_outsider'] && !$image_data['is_dir_writable']) {
        if (current_user_can('administrator')) {
            return '<div style="padding:10px;background-color:Red;color:#FFFFFF;">' . 'Types: ' . sprintf(__('Directory %s not writable', 'wpcf'), $image_data['abspath']) . '</div>';
        }
        return $params['field_value'];
    }
    // Set alt
    if (isset($params['alt'])) {
        $alt = $params['alt'];
    }
    // Set title
    if (isset($params['title'])) {
        $title = $params['title'];
    }
    // Set attachment class
    if (!empty($params['size'])) {
        $class[] = 'attachment-' . $params['size'];
    }
    // Set align class
    if (!empty($params['align']) && $params['align'] != 'none') {
        $class[] = 'align' . $params['align'];
    }
    // Pre-configured size (use WP function)
    if ($image_data['is_attachment'] && !empty($params['size'])) {
        $output = wp_get_attachment_image($image_data['is_attachment'], $params['size'], false, array('class' => implode(' ', $class), 'alt' => $alt, 'title' => $title));
        $output = wpcf_frontend_wrap_field_value($params['field'], $output, $params);
        $output = wpcf_frontend_wrap_field($params['field'], $output, $params);
    } else {
        // Custom size
        $width = !empty($params['width']) ? intval($params['width']) : null;
        $height = !empty($params['height']) ? intval($params['height']) : null;
        $crop = !empty($params['proportional']) && $params['proportional'] == 'true' ? false : true;
        // Check if image is outsider
        if (!$image_data['is_outsider']) {
            $resized_image = wpcf_fields_image_resize_image($params['field_value'], $width, $height, 'relpath', false, $crop);
            if (!$resized_image) {
                $resized_image = $params['field_value'];
            }
        } else {
            $resized_image = $params['field_value'];
        }
        $output = '<img alt="';
        $output .= $alt !== false ? $alt : $resized_image;
        $output .= '" title="';
        $output .= $title !== false ? $title : $resized_image;
        $output .= '"';
        $output .= !empty($params['onload']) ? ' onload="' . $params['onload'] . '"' : '';
        $output .= !empty($class) ? ' class="' . implode(' ', $class) . '"' : '';
        $output .= ' src="' . $resized_image . '" />';
        $output = wpcf_frontend_wrap_field_value($params['field'], $output, $params);
        $output = wpcf_frontend_wrap_field($params['field'], $output, $params);
    }
    return $output;
}