Example #1
0
function wpsight_options_sanitize_measurement_units($value)
{
    $recognized = wpsight_measurement_units();
    if (array_key_exists($value, $recognized)) {
        return $value;
    }
    return apply_filters('wpsight_options_default_measurement_units', current($recognized));
}
Example #2
0
 function wpsight_options_listings()
 {
     /** Define data arrays */
     $options_listings = array();
     $options_listings['heading_listings'] = array('name' => __('Listings', 'wpsight'), 'id' => 'heading_listings', 'type' => 'heading');
     // Check of old 'property_id' options was active
     $listing_id_std = wpsight_get_option('property_id') ? wpsight_get_option('property_id') : __('ID-', 'wpsight');
     $options_listings['listing_id'] = array('name' => __('Listing ID Prefix', 'wpsight'), 'id' => 'listing_id', 'desc' => __('The listing ID will be this prefix plus post ID. You can optionally set individual IDs on the listing edit screen.', 'wpsight'), 'std' => $listing_id_std, 'class' => 'mini', 'type' => 'text');
     $options_listings['measurement_unit'] = array('name' => __('Measurement Unit', 'wpsight'), 'desc' => __('Please select the general measurement unit. The unit for the listing standard features can be defined separately below.', 'wpsight'), 'id' => 'measurement_unit', 'std' => 'm2', 'class' => 'mini', 'type' => 'select', 'options' => array_filter(wpsight_measurement_units()));
     $options_listings['currency'] = array('name' => __('Currency', 'wpsight'), 'desc' => __('Please select the currency for the listing prices. If your currency is not listed, please select <code>Other</code>.', 'wpsight'), 'id' => 'currency', 'std' => 'usd', 'class' => 'mini', 'type' => 'select', 'options' => array_merge(array_filter(wpsight_currencies()), array('other' => __('Other', 'wpsight'))));
     $options_listings['currency_other'] = array('name' => __('Other Currency', 'wpsight') . ' (' . __('Abbreviation', 'wpsight') . ')', 'id' => 'currency_other', 'desc' => __('Please insert the abbreviation of your currency (e.g. <code>EUR</code>).', 'wpsight'), 'class' => 'hidden mini', 'type' => 'text');
     $options_listings['currency_other_ent'] = array('name' => __('Other Currency', 'wpsight') . ' (' . __('Symbol', 'wpsight') . ')', 'id' => 'currency_other_ent', 'desc' => __('Please insert the currency symbol or HTML entity (e.g. <code>&amp;euro;</code>).', 'wpsight'), 'class' => 'hidden mini', 'type' => 'text');
     $options_listings['currency_symbol'] = array('name' => __('Currency Symbol', 'wpsight'), 'desc' => __('Please select the position of the currency symbol.', 'wpsight'), 'id' => 'currency_symbol', 'std' => 'before', 'type' => 'radio', 'options' => array('before' => __('Before the value', 'wpsight'), 'after' => __('After the value', 'wpsight')));
     $options_listings['currency_separator'] = array('name' => __('Thousands Separator', 'wpsight'), 'desc' => __('Please select the thousands separator for your listing prices.', 'wpsight'), 'id' => 'currency_separator', 'std' => 'comma', 'type' => 'radio', 'options' => array('comma' => __('Comma (e.g. 1,000,000)', 'wpsight'), 'dot' => __('Period (e.g. 1.000.000)', 'wpsight')));
     /** Toggle standard features */
     $options_listings['listing_features'] = array('name' => __('Listing Features', 'wpsight'), 'desc' => __('Please check the box to edit the listing standard features.', 'wpsight'), 'id' => 'listing_features', 'std' => '0', 'type' => 'checkbox');
     /** Loop through standard features */
     $i = 1;
     foreach (wpsight_standard_details() as $feature_id => $value) {
         $options_listings[$feature_id] = array('name' => __('Standard Feature', 'wpsight') . ' #' . $i, 'id' => $feature_id, 'desc' => $value['description'], 'std' => array('label' => $value['label'], 'unit' => $value['unit']), 'class' => 'hidden', 'type' => 'measurement');
         $i++;
     }
     /** Toggle rental periods */
     $options_listings['rental_periods'] = array('name' => __('Rental Periods', 'wpsight'), 'desc' => __('Please check the box to edit the rental periods.', 'wpsight'), 'id' => 'rental_periods', 'std' => '0', 'type' => 'checkbox');
     /** Loop through rental periods */
     $i = 1;
     foreach (wpsight_rental_periods() as $period_id => $value) {
         $options_listings[$period_id] = array('name' => __('Rental Period', 'wpsight') . ' #' . $i, 'id' => $period_id, 'std' => $value, 'class' => 'hidden', 'type' => 'text');
         $i++;
     }
     return apply_filters('wpsight_options_listings', $options_listings);
 }
Example #3
0
 function wpsight_meta_box_listing_details()
 {
     $details_labels = array('title' => __('Listing Details', 'wpsight'), 'id' => __('ID', 'wpsight'));
     // Get standard features and merge with title
     $standardDetails = wpsight_standard_details();
     if (!is_array($standardDetails)) {
         $standardDetails = array();
     }
     $details_labels = array_merge($details_labels, $standardDetails);
     $details_labels = apply_filters('wpsight_listing_details_labels', $details_labels);
     /**
      * Add backward compatibility
      * for old wpCasa _property_id
      * custom field value
      */
     $listing_id = false;
     if (wpsight_get_listing_edit_id()) {
         // Get old wpCasa _property_id
         $property_id_meta = get_post_meta(wpsight_get_listing_edit_id(), '_property_id', true);
         // Get new wpSight _listing_id
         $listing_id_meta = get_post_meta(wpsight_get_listing_edit_id(), '_listing_id', true);
         if (!empty($property_id_meta) && empty($listing_id_meta)) {
             update_post_meta(wpsight_get_listing_edit_id(), '_listing_id', $property_id_meta, '');
         }
         if (empty($property_id_meta) && empty($listing_id_meta)) {
             $listing_id = wpsight_get_listing_id(wpsight_get_listing_edit_id());
         }
     }
     // Set meta box
     $meta_box = array('id' => 'listing_details', 'title' => $details_labels['title'], 'pages' => array(wpsight_listing_post_type()), 'context' => 'normal', 'priority' => 'high', 'fields' => array('id' => array('name' => $details_labels['id'], 'id' => '_listing_id', 'type' => 'text', 'std' => $listing_id)));
     /**
      * Add standard details
      */
     $units = wpsight_measurement_units();
     foreach ($standardDetails as $detail => $value) {
         $standard_details_option = wpsight_get_option($detail);
         // If details hasn't been set before, display default
         if (!isset($standard_details_option['label'])) {
             $standard_details_option = wpsight_get_option($detail, true);
         }
         // Don't show detail if label is emtpy in options
         if (empty($standard_details_option['label'])) {
             continue;
         }
         if (!empty($details_labels[$detail])) {
             // Optionally add measurement label to title
             $unit = '';
             if (!empty($details_labels[$detail]['unit'])) {
                 $unit = $details_labels[$detail]['unit'];
                 $unit = $units[$unit];
                 $unit = ' (' . $unit . ')';
             }
             // If there is select data, create select fields else text
             if (!empty($details_labels[$detail]['data'])) {
                 $meta_box['fields'][$detail] = array('name' => $details_labels[$detail]['label'] . $unit, 'id' => '_' . $detail, 'type' => 'select', 'options' => $details_labels[$detail]['data'], 'desc' => $details_labels[$detail]['description']);
             } else {
                 $meta_box['fields'][$detail] = array('name' => $details_labels[$detail]['label'] . $unit, 'id' => '_' . $detail, 'type' => 'text', 'desc' => $details_labels[$detail]['description']);
             }
             // end if
         }
         // end if
     }
     // end foreach
     // Apply filter to array
     $meta_box = apply_filters('wpsight_meta_box_listing_details', $meta_box);
     return $meta_box;
 }
Example #4
0
/**
 * Get measurement value from unit key
 *
 * @since 1.0
 */
function wpsight_get_measurement_units($unit)
{
    $measurements = wpsight_measurement_units();
    return $measurements[$unit];
}
Example #5
0
/**
 * Generates the options fields that are used in the form.
 */
function wpsight_options_fields()
{
    global $allowedtags;
    $wpsight_options_settings = get_option(WPSIGHT_DOMAIN);
    // Gets the unique option id
    if (isset($wpsight_options_settings['id'])) {
        $option_name = $wpsight_options_settings['id'];
    } else {
        $option_name = WPSIGHT_DOMAIN;
    }
    $settings = get_option($option_name);
    $options = wpsight_options();
    $counter = 0;
    $menu = '';
    foreach ($options as $value) {
        $val = '';
        $select_value = '';
        $checked = '';
        $output = '';
        // Wrap all options
        if ($value['type'] != "heading" && $value['type'] != "info") {
            // Keep all ids lowercase with no spaces
            $value['id'] = preg_replace('/[^a-zA-Z0-9._\\-]/', '', strtolower($value['id']));
            $id = 'section-' . $value['id'];
            $class = 'section';
            if (isset($value['type'])) {
                $class .= ' section-' . $value['type'];
            }
            if (isset($value['class'])) {
                $class .= ' ' . $value['class'];
            }
            $output .= '<div id="' . esc_attr($id) . '" class="' . esc_attr($class) . '">' . "\n";
            if (isset($value['name'])) {
                $output .= '<h4 class="heading">' . esc_html($value['name']) . '</h4>' . "\n";
            }
            if ($value['type'] != 'editor') {
                $output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
            } else {
                $output .= '<div class="option">' . "\n" . '<div>' . "\n";
            }
        }
        // Set default value to $val
        if (isset($value['std'])) {
            $val = $value['std'];
        }
        // If the option is already saved, ovveride $val
        if ($value['type'] != 'heading' && $value['type'] != 'info') {
            if (isset($settings[$value['id']])) {
                $val = $settings[$value['id']];
                // Striping slashes of non-array options
                if (!is_array($val)) {
                    $val = stripslashes($val);
                }
            }
        }
        // If there is a description save it for labels
        $explain_value = '';
        if (isset($value['desc'])) {
            $explain_value = $value['desc'];
        }
        switch ($value['type']) {
            // Basic text input
            case 'text':
                $output .= '<input id="' . esc_attr($value['id']) . '" class="wpsight-options-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" type="text" value="' . esc_attr($val) . '" />';
                break;
                // Password input
            // Password input
            case 'password':
                $output .= '<input id="' . esc_attr($value['id']) . '" class="wpsight-options-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" type="password" value="' . esc_attr($val) . '" />';
                break;
                // Textarea
            // Textarea
            case 'textarea':
                $rows = '8';
                if (isset($value['settings']['rows'])) {
                    $custom_rows = $value['settings']['rows'];
                    if (is_numeric($custom_rows)) {
                        $rows = $custom_rows;
                    }
                }
                $val = stripslashes($val);
                $output .= '<textarea id="' . esc_attr($value['id']) . '" class="wpsight-options-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" rows="' . $rows . '">' . esc_textarea($val) . '</textarea>';
                break;
                // Select Box
            // Select Box
            case 'select':
                $output .= '<select class="wpsight-options-input" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" id="' . esc_attr($value['id']) . '">';
                foreach ($value['options'] as $key => $option) {
                    $selected = '';
                    if ($val != '') {
                        if ($val == $key) {
                            $selected = ' selected="selected"';
                        }
                    }
                    $value = strpos(esc_attr($key), '_disabled') !== false ? 'disabled' : 'value="' . esc_attr($key) . '"';
                    $output .= '<option' . $selected . ' ' . $value . '>' . $option . '</option>';
                }
                $output .= '</select>';
                break;
                // Radio Box
            // Radio Box
            case "radio":
                $name = $option_name . '[' . $value['id'] . ']';
                foreach ($value['options'] as $key => $option) {
                    $id = $option_name . '-' . $value['id'] . '-' . $key;
                    $output .= '<input class="wpsight-options-input wpsight-options-radio" type="radio" name="' . esc_attr($name) . '" id="' . esc_attr($id) . '" value="' . esc_attr($key) . '" ' . checked($val, $key, false) . ' /><label for="' . esc_attr($id) . '">' . $option . '</label>';
                }
                break;
                // Image Selectors
            // Image Selectors
            case "images":
                $name = $option_name . '[' . $value['id'] . ']';
                foreach ($value['options'] as $key => $option) {
                    $selected = '';
                    $checked = '';
                    if ($val != '') {
                        if ($val == $key) {
                            $selected = ' wpsight-options-radio-img-selected';
                            $checked = ' checked="checked"';
                        }
                    }
                    $output .= '<input type="radio" id="' . esc_attr($value['id'] . '_' . $key) . '" class="wpsight-options-radio-img-radio" value="' . esc_attr($key) . '" name="' . esc_attr($name) . '" ' . $checked . ' />';
                    $output .= '<div class="wpsight-options-radio-img-label">' . esc_html($key) . '</div>';
                    $output .= '<img src="' . esc_url($option) . '" alt="' . $option . '" class="wpsight-options-radio-img-img' . $selected . '" onclick="document.getElementById(\'' . esc_attr($value['id'] . '_' . $key) . '\').checked=true;" />';
                }
                break;
                // Checkbox
            // Checkbox
            case "checkbox":
                $output .= '<input id="' . esc_attr($value['id']) . '" class="checkbox wpsight-options-input" type="checkbox" name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" ' . checked($val, 1, false) . ' />';
                $output .= '<label class="explain" for="' . esc_attr($value['id']) . '">' . wp_kses($explain_value, $allowedtags) . '</label>';
                break;
                // Multicheck
            // Multicheck
            case "multicheck":
                foreach ($value['options'] as $key => $option) {
                    $checked = '';
                    $label = $option;
                    $option = preg_replace('/[^a-zA-Z0-9._\\-]/', '', strtolower($key));
                    $id = $option_name . '-' . $value['id'] . '-' . $option;
                    $name = $option_name . '[' . $value['id'] . '][' . $option . ']';
                    if (isset($val[$option])) {
                        $checked = checked($val[$option], 1, false);
                    }
                    $output .= '<input id="' . esc_attr($id) . '" class="checkbox wpsight-options-input" type="checkbox" name="' . esc_attr($name) . '" ' . $checked . ' /><label for="' . esc_attr($id) . '">' . esc_html($label) . '</label>';
                }
                break;
                // Color picker
            // Color picker
            case "color":
                $default_color = '';
                if (isset($value['std'])) {
                    if ($val != $value['std']) {
                        $default_color = ' data-default-color="' . $value['std'] . '" ';
                    }
                }
                $output .= '<input name="' . esc_attr($option_name . '[' . $value['id'] . ']') . '" id="' . esc_attr($value['id']) . '" class="wpsight-options-color"  type="text" value="' . esc_attr($val) . '"' . $default_color . ' />';
                break;
                // Uploader
            // Uploader
            case "upload":
                $output .= wpsight_options_uploader($value['id'], $val, null);
                break;
                // Typography
            // Typography
            case 'typography':
                unset($font_size, $font_style, $font_face, $font_color);
                $typography_defaults = array('size' => '', 'face' => '', 'style' => '', 'color' => '');
                $typography_stored = wp_parse_args($val, $typography_defaults);
                $typography_options = array('sizes' => of_recognized_font_sizes(), 'faces' => of_recognized_font_faces(), 'styles' => of_recognized_font_styles(), 'color' => true);
                if (isset($value['options'])) {
                    $typography_options = wp_parse_args($value['options'], $typography_options);
                }
                // Font Size
                if ($typography_options['sizes']) {
                    $font_size = '<select class="wpsight-options-typography wpsight-options-typography-size" name="' . esc_attr($option_name . '[' . $value['id'] . '][size]') . '" id="' . esc_attr($value['id'] . '_size') . '">';
                    $sizes = $typography_options['sizes'];
                    foreach ($sizes as $i) {
                        $size = $i . 'px';
                        $font_size .= '<option value="' . esc_attr($size) . '" ' . selected($typography_stored['size'], $size, false) . '>' . esc_html($size) . '</option>';
                    }
                    $font_size .= '</select>';
                }
                // Font Face
                if ($typography_options['faces']) {
                    $font_face = '<select class="wpsight-options-typography wpsight-options-typography-face" name="' . esc_attr($option_name . '[' . $value['id'] . '][face]') . '" id="' . esc_attr($value['id'] . '_face') . '">';
                    $faces = $typography_options['faces'];
                    foreach ($faces as $key => $face) {
                        $font_face .= '<option value="' . esc_attr($key) . '" ' . selected($typography_stored['face'], $key, false) . '>' . esc_html($face) . '</option>';
                    }
                    $font_face .= '</select>';
                }
                // Font Styles
                if ($typography_options['styles']) {
                    $font_style = '<select class="wpsight-options-typography wpsight-options-typography-style" name="' . $option_name . '[' . $value['id'] . '][style]" id="' . $value['id'] . '_style">';
                    $styles = $typography_options['styles'];
                    foreach ($styles as $key => $style) {
                        $font_style .= '<option value="' . esc_attr($key) . '" ' . selected($typography_stored['style'], $key, false) . '>' . $style . '</option>';
                    }
                    $font_style .= '</select>';
                }
                // Font Color
                if ($typography_options['color']) {
                    $default_color = '';
                    if (isset($value['std']['color'])) {
                        if ($val != $value['std']['color']) {
                            $default_color = ' data-default-color="' . $value['std']['color'] . '" ';
                        }
                    }
                    $font_color = '<input name="' . esc_attr($option_name . '[' . $value['id'] . '][color]') . '" id="' . esc_attr($value['id'] . '_color') . '" class="wpsight-options-color wpsight-options-typography-color  type="text" value="' . esc_attr($typography_stored['color']) . '"' . $default_color . ' />';
                }
                // Allow modification/injection of typography fields
                $typography_fields = compact('font_size', 'font_face', 'font_style', 'font_color');
                $typography_fields = apply_filters('of_typography_fields', $typography_fields, $typography_stored, $option_name, $value);
                $output .= implode('', $typography_fields);
                break;
                // Background
            // Background
            case 'background':
                $background = $val;
                // Background Color
                $default_color = '';
                if (isset($value['std']['color'])) {
                    if ($val != $value['std']['color']) {
                        $default_color = ' data-default-color="' . $value['std']['color'] . '" ';
                    }
                }
                $output .= '<input name="' . esc_attr($option_name . '[' . $value['id'] . '][color]') . '" id="' . esc_attr($value['id'] . '_color') . '" class="wpsight-options-color wpsight-options-background-color"  type="text" value="' . esc_attr($background['color']) . '"' . $default_color . ' />';
                // Background Image
                if (!isset($background['image'])) {
                    $background['image'] = '';
                }
                $output .= wpsight_options_uploader($value['id'], $background['image'], null, esc_attr($option_name . '[' . $value['id'] . '][image]'));
                $class = 'wpsight-options-background-properties';
                if ('' == $background['image']) {
                    $class .= ' hide';
                }
                $output .= '<div class="' . esc_attr($class) . '">';
                // Background Repeat
                $output .= '<select class="wpsight-options-background wpsight-options-background-repeat" name="' . esc_attr($option_name . '[' . $value['id'] . '][repeat]') . '" id="' . esc_attr($value['id'] . '_repeat') . '">';
                $repeats = of_recognized_background_repeat();
                foreach ($repeats as $key => $repeat) {
                    $output .= '<option value="' . esc_attr($key) . '" ' . selected($background['repeat'], $key, false) . '>' . esc_html($repeat) . '</option>';
                }
                $output .= '</select>';
                // Background Position
                $output .= '<select class="wpsight-options-background wpsight-options-background-position" name="' . esc_attr($option_name . '[' . $value['id'] . '][position]') . '" id="' . esc_attr($value['id'] . '_position') . '">';
                $positions = of_recognized_background_position();
                foreach ($positions as $key => $position) {
                    $output .= '<option value="' . esc_attr($key) . '" ' . selected($background['position'], $key, false) . '>' . esc_html($position) . '</option>';
                }
                $output .= '</select>';
                // Background Attachment
                $output .= '<select class="wpsight-options-background wpsight-options-background-attachment" name="' . esc_attr($option_name . '[' . $value['id'] . '][attachment]') . '" id="' . esc_attr($value['id'] . '_attachment') . '">';
                $attachments = of_recognized_background_attachment();
                foreach ($attachments as $key => $attachment) {
                    $output .= '<option value="' . esc_attr($key) . '" ' . selected($background['attachment'], $key, false) . '>' . esc_html($attachment) . '</option>';
                }
                $output .= '</select>';
                $output .= '</div>';
                break;
                // Editor
            // Editor
            case 'editor':
                $output .= '<div class="explain">' . wp_kses($explain_value, $allowedtags) . '</div>' . "\n";
                echo $output;
                $textarea_name = esc_attr($option_name . '[' . $value['id'] . ']');
                $default_editor_settings = array('textarea_name' => $textarea_name, 'media_buttons' => false, 'tinymce' => array('plugins' => 'wordpress'));
                $editor_settings = array();
                if (isset($value['settings'])) {
                    $editor_settings = $value['settings'];
                }
                $editor_settings = array_merge($editor_settings, $default_editor_settings);
                wp_editor($val, $value['id'], $editor_settings);
                $output = '';
                break;
                // Measurement
            // Measurement
            case 'measurement':
                $measurement = $val;
                $output .= '<div class="wpsight-options-measurement-wrap">';
                // Feature
                $output .= '<input class="wpsight-options-measurement wpsight-options-measurement-feature" name="' . esc_attr($option_name . '[' . $value['id'] . '][label]') . '" id="' . esc_attr($value['id'] . '_label') . '" type="text" value="' . esc_attr($measurement['label']) . '" />';
                // Unit
                $output .= '<select class="wpsight-options-measurement wpsight-options-measurement-unit" name="' . esc_attr($option_name . '[' . $value['id'] . '][unit]') . '" id="' . esc_attr($value['id'] . '_unit') . '">';
                $units = wpsight_measurement_units();
                foreach ($units as $key => $unit) {
                    $output .= '<option value="' . esc_attr($key) . '" ' . selected($measurement['unit'], $key, false) . '>' . $unit . '</option>';
                }
                $output .= '</select>';
                $output .= '</div>';
                break;
                // Info
            // Info
            case "info":
                $id = '';
                $class = 'section';
                if (isset($value['id'])) {
                    $id = 'id="' . esc_attr($value['id']) . '" ';
                }
                if (isset($value['type'])) {
                    $class .= ' section-' . $value['type'];
                }
                if (isset($value['class'])) {
                    $class .= ' ' . $value['class'];
                }
                $output .= '<div ' . $id . 'class="' . esc_attr($class) . '">' . "\n";
                if (isset($value['name'])) {
                    $output .= '<h4 class="heading">' . esc_html($value['name']) . '</h4>' . "\n";
                }
                if ($value['desc']) {
                    $output .= apply_filters('of_sanitize_info', $value['desc']) . "\n";
                }
                $output .= '</div>' . "\n";
                break;
                // Heading for Navigation
            // Heading for Navigation
            case "heading":
                $counter++;
                if ($counter >= 2) {
                    $output .= '</div>' . "\n";
                }
                $class = '';
                $class = !empty($value['id']) ? $value['id'] : $value['name'];
                $class = preg_replace('/[^a-zA-Z0-9._\\-]/', '', strtolower($class));
                $output .= '<div id="options-group-' . $counter . '" class="group ' . $class . '">';
                $output .= '<h3>' . esc_html($value['name']) . '</h3>' . "\n";
                break;
        }
        $type = isset($value['type']) ? $value['type'] : false;
        if ($type != "heading" && $type != "info") {
            $output .= '</div>';
            if ($type != "checkbox" && $type != "editor") {
                $output .= '<div class="explain">' . wp_kses($explain_value, $allowedtags) . '</div>' . "\n";
            }
            $output .= '</div></div>' . "\n";
        }
        echo $output;
    }
    echo '</div>';
}