function siteoptions_machine($options)
{
    $counter = 0;
    $menu = '';
    $output = '';
    if (!empty($options) && is_array($options)) {
        foreach ($options as $value) {
            $counter++;
            $val = '';
            //Start Heading
            if ($value['type'] != "heading") {
                $class = '';
                if (isset($value['class'])) {
                    $class = $value['class'];
                }
                //$output .= '<div class="section section-'. $value['type'] .'">'."\n".'<div class="option-inner">'."\n";
                $output .= '<div class="section section-' . $value['type'] . ' ' . $class . '">' . "\n";
                $output .= '<h3 class="heading">' . $value['name'] . '</h3>' . "\n";
                $output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
            }
            //End Heading
            $select_value = '';
            switch ($value['type']) {
                case 'text':
                    $val = $value['std'];
                    $std = stripslashes(get_option($value['id']));
                    if ($std != "") {
                        $val = $std;
                    }
                    $output .= '<input class="of-input" name="' . $value['id'] . '" id="' . $value['id'] . '" type="' . $value['type'] . '" value="' . $val . '" />';
                    break;
                case 'select':
                    $output .= '<select class="of-input" name="' . $value['id'] . '" id="' . $value['id'] . '">';
                    $select_value = get_option($value['id']);
                    foreach ($value['options'] as $option) {
                        $selected = '';
                        if ($select_value != '') {
                            if ($select_value == $option) {
                                $selected = ' selected="selected"';
                            }
                        } else {
                            if (isset($value['std'])) {
                                if ($value['std'] == $option) {
                                    $selected = ' selected="selected"';
                                }
                            }
                        }
                        $output .= '<option' . $selected . '>';
                        $output .= $option;
                        $output .= '</option>';
                    }
                    $output .= '</select>';
                    break;
                case 'fontsize':
                    /* Font Size */
                    $val = $default['size'];
                    if ($typography_stored['size'] != "") {
                        $val = $typography_stored['size'];
                    }
                    $output .= '<select class="of-typography of-typography-size" name="' . $value['id'] . '_size" id="' . $value['id'] . '_size">';
                    for ($i = 9; $i < 71; $i++) {
                        if ($val == $i) {
                            $active = 'selected="selected"';
                        } else {
                            $active = '';
                        }
                        $output .= '<option value="' . $i . '" ' . $active . '>' . $i . 'px</option>';
                    }
                    $output .= '</select>';
                    break;
                case "multicheck":
                    $existing_values = get_option($value['id']);
                    foreach ($value['options'] as $key => $option) {
                        $tt_key = $value['id'] . '_' . $key;
                        if (isset($existing_values) && is_array($existing_values)) {
                            if (in_array($key, $existing_values)) {
                                $checked = 'checked="checked"';
                            } else {
                                $checked = '';
                            }
                        } else {
                            if (isset($value['std']) && is_array($value['std']) && in_array($key, $value['std'])) {
                                $checked = 'checked="checked"';
                            } else {
                                $checked = '';
                            }
                        }
                        $output .= '<input type="checkbox" class="checkbox of-input" name="' . $value['id'] . '[]" id="' . $tt_key . '" value="' . $key . '" ' . $checked . ' /><label for="' . $tt_key . '">' . $option . '</label><br />';
                    }
                    break;
                case 'textarea':
                    $cols = '8';
                    $ta_value = '';
                    if (isset($value['std'])) {
                        $ta_value = $value['std'];
                        if (isset($value['options'])) {
                            $ta_options = $value['options'];
                            if (isset($ta_options['cols'])) {
                                $cols = $ta_options['cols'];
                            } else {
                                $cols = '8';
                            }
                        }
                    }
                    $std = get_option($value['id']);
                    if ($std != "") {
                        $ta_value = stripslashes($std);
                    }
                    $output .= '<textarea class="of-input" name="' . $value['id'] . '" id="' . $value['id'] . '" cols="' . $cols . '" rows="8">' . $ta_value . '</textarea>';
                    break;
                case "radio":
                    $select_value = get_option($value['id']);
                    foreach ($value['options'] as $key => $option) {
                        $checked = '';
                        if ($select_value != '') {
                            if ($select_value == $key) {
                                $checked = ' checked';
                            }
                        } else {
                            if ($value['std'] == $key) {
                                $checked = ' checked';
                            }
                        }
                        $output .= '<input class="of-input of-radio" type="radio" name="' . $value['id'] . '" value="' . $key . '" ' . $checked . ' />' . $option . '<br />';
                    }
                    break;
                case "checkbox":
                    if (isset($value['std'])) {
                        $std = $value['std'];
                    }
                    $saved_std = get_option($value['id']);
                    $checked = '';
                    if (!empty($saved_std)) {
                        if ($saved_std == 'true') {
                            $checked = 'checked="checked"';
                        } else {
                            $checked = '';
                        }
                    } elseif ($std == 'true') {
                        $checked = 'checked="checked"';
                    } else {
                        $checked = '';
                    }
                    $output .= '<input type="checkbox" class="checkbox of-input" name="' . $value['id'] . '" id="' . $value['id'] . '" value="true" ' . $checked . ' />';
                    break;
                case "upload":
                    $output .= siteoptions_uploader_function($value['id'], $value['std'], null);
                    break;
                case "upload_min":
                    $output .= siteoptions_uploader_function($value['id'], $value['std'], 'min');
                    break;
                case "color":
                    $val = $value['std'];
                    $stored = get_option($value['id']);
                    if ($stored != "") {
                        $val = $stored;
                    }
                    $output .= '<div id="' . $value['id'] . '_picker" class="colorSelector"><div></div></div>';
                    $output .= '<input class="of-color" name="' . $value['id'] . '" id="' . $value['id'] . '" type="text" value="' . $val . '" />';
                    break;
                case "images":
                    $i = 0;
                    $select_value = get_option($value['id']);
                    foreach ($value['options'] as $key => $option) {
                        $i++;
                        $checked = '';
                        $selected = '';
                        if ($select_value != '') {
                            if ($select_value == $key) {
                                $checked = ' checked';
                                $selected = 'of-radio-img-selected';
                            }
                        } else {
                            if ($value['std'] == $key) {
                                $checked = ' checked';
                                $selected = 'of-radio-img-selected';
                            } elseif ($i == 1 && !isset($select_value)) {
                                $checked = ' checked';
                                $selected = 'of-radio-img-selected';
                            } elseif ($i == 1 && $value['std'] == '') {
                                $checked = ' checked';
                                $selected = 'of-radio-img-selected';
                            } else {
                                $checked = '';
                            }
                        }
                        $output .= '<span>';
                        $output .= '<input type="radio" id="of-radio-img-' . $value['id'] . $i . '" class="checkbox of-radio-img-radio" value="' . $key . '" name="' . $value['id'] . '" ' . $checked . ' />';
                        $output .= '<div class="of-radio-img-label">' . $key . '</div>';
                        $output .= '<img src="' . $option . '" alt="" class="of-radio-img-img ' . $selected . '" onClick="document.getElementById(\'of-radio-img-' . $value['id'] . $i . '\').checked = true;" />';
                        $output .= '</span>';
                    }
                    break;
                case "info":
                    $default = $value['std'];
                    $output .= $default;
                    break;
                case "heading":
                    if ($counter >= 2) {
                        $output .= '</div>' . "\n";
                    }
                    $jquery_click_hook = preg_replace(array("[^A-Za-z0-9]", "[\\s+]"), array("", "-"), strtolower($value['name']));
                    $jquery_click_hook = "of-option-" . $jquery_click_hook;
                    $menu .= '<li><a title="' . $value['name'] . '" href="#' . $jquery_click_hook . '">' . $value['name'] . '</a></li>';
                    $output .= '<div class="group" id="' . $jquery_click_hook . '"><h2>' . $value['name'] . '</h2>' . "\n";
                    break;
            }
            // if TYPE is an array, formatted into smaller inputs... ie smaller values
            if (is_array($value['type'])) {
                foreach ($value['type'] as $array) {
                    $id = $array['id'];
                    $std = $array['std'];
                    $saved_std = get_option($id);
                    if ($saved_std != $std) {
                        $std = $saved_std;
                    }
                    $meta = $array['meta'];
                    if ($array['type'] == 'text') {
                        // Only text at this point
                        $output .= '<input class="input-text-small of-input" name="' . $id . '" id="' . $id . '" type="text" value="' . $std . '" />';
                        $output .= '<span class="meta-two">' . $meta . '</span>';
                    }
                }
            }
            if ($value['type'] != "heading") {
                if ($value['type'] != "checkbox") {
                    $output .= '<br/>';
                }
                if (!isset($value['desc'])) {
                    $explain_value = '';
                } else {
                    $explain_value = $value['desc'];
                }
                $output .= '</div><div class="explain">' . $explain_value . '</div>' . "\n";
                $output .= '<div class="clear"> </div></div></div>' . "\n";
            }
        }
    }
    $output .= '</div>';
    return array($output, $menu);
}
Beispiel #2
0
function siteoptions_machine($options)
{
    $counter = 0;
    $menu = '';
    $output = '';
    foreach ($options as $value) {
        $counter++;
        $val = '';
        //Start Heading
        if ($value['type'] != "heading") {
            $class = '';
            if (isset($value['class'])) {
                $class = $value['class'];
            }
            //$output .= '<div class="section section-'. $value['type'] .'">'."\n".'<div class="option-inner">'."\n";
            if (isset($value['type'])) {
                $output .= '<div class="section section-' . $value['type'] . ' ' . $class . '">' . "\n";
            }
            if (isset($value['name'])) {
                $output .= '<h3 class="heading">' . $value['name'] . '</h3>' . "\n";
            }
            $output .= '<div class="option">' . "\n" . '<div class="controls">' . "\n";
        }
        //End Heading
        $select_value = '';
        switch ($value['type']) {
            case 'text':
                $val = $value['std'];
                $std = get_option($value['id']);
                if ($std != "") {
                    $val = $std;
                }
                $output .= '<input class="m413-input" name="' . $value['id'] . '" id="' . $value['id'] . '" type="' . $value['type'] . '" value="' . $val . '" />';
                break;
            case 'select':
                $output .= '<select class="m413-input" name="' . $value['id'] . '" id="' . $value['id'] . '">';
                $select_value = get_option($value['id']);
                foreach ($value['options'] as $option) {
                    $selected = '';
                    if ($select_value != '') {
                        if ($select_value == $option) {
                            $selected = ' selected="selected"';
                        }
                    } else {
                        if (isset($value['std'])) {
                            if ($value['std'] == $option) {
                                $selected = ' selected="selected"';
                            }
                        }
                    }
                    $output .= '<option' . $selected . '>';
                    $output .= $option;
                    $output .= '</option>';
                }
                $output .= '</select>';
                break;
            case 'fontsize':
                /* Font Size */
                $val = $default['size'];
                if ($typography_stored['size'] != "") {
                    $val = $typography_stored['size'];
                }
                $output .= '<select class="m413-typography m413-typography-size" name="' . $value['id'] . '_size" id="' . $value['id'] . '_size">';
                for ($i = 9; $i < 71; $i++) {
                    if ($val == $i) {
                        $active = 'selected="selected"';
                    } else {
                        $active = '';
                    }
                    $output .= '<option value="' . $i . '" ' . $active . '>' . $i . 'px</option>';
                }
                $output .= '</select>';
                break;
            case "multicheck":
                $std = $value['std'];
                foreach ($value['options'] as $key => $option) {
                    $tt_key = $value['id'] . '_' . $key;
                    $saved_std = get_option($tt_key);
                    if (!empty($saved_std)) {
                        if ($saved_std == 'true') {
                            $checked = 'checked="checked"';
                        } else {
                            $checked = '';
                        }
                    } elseif ($std == $key) {
                        $checked = 'checked="checked"';
                    } else {
                        $checked = '';
                    }
                    $output .= '<input type="checkbox" class="checkbox m413-input" name="' . $tt_key . '" id="' . $tt_key . '" value="true" ' . $checked . ' /><label for="' . $tt_key . '">' . $option . '</label><br />';
                }
                break;
            case 'textarea':
                $cols = '8';
                $ta_value = '';
                if (isset($value['std'])) {
                    $ta_value = $value['std'];
                    if (isset($value['options'])) {
                        $ta_options = $value['options'];
                        if (isset($ta_options['cols'])) {
                            $cols = $ta_options['cols'];
                        } else {
                            $cols = '8';
                        }
                    }
                }
                $std = get_option($value['id']);
                if ($std != "") {
                    $ta_value = stripslashes($std);
                }
                $output .= '<textarea class="m413-input" name="' . $value['id'] . '" id="' . $value['id'] . '" cols="' . $cols . '" rows="8">' . $ta_value . '</textarea>';
                break;
            case "radio":
                $select_value = get_option($value['id']);
                foreach ($value['options'] as $key => $option) {
                    $checked = '';
                    if ($select_value != '') {
                        if ($select_value == $key) {
                            $checked = ' checked';
                        }
                    } else {
                        if ($value['std'] == $key) {
                            $checked = ' checked';
                        }
                    }
                    $output .= '<input class="m413-input m413-radio" type="radio" name="' . $value['id'] . '" value="' . $key . '" ' . $checked . ' />' . $option . '<br />';
                }
                break;
            case "checkbox":
                $std = $value['std'];
                $saved_std = get_option($value['id']);
                $checked = '';
                if (!empty($saved_std)) {
                    if ($saved_std == 'true') {
                        $checked = 'checked="checked"';
                    } else {
                        $checked = '';
                    }
                } elseif ($std == 'true') {
                    $checked = 'checked="checked"';
                } else {
                    $checked = '';
                }
                $output .= '<input type="checkbox" class="checkbox m413-input" name="' . $value['id'] . '" id="' . $value['id'] . '" value="true" ' . $checked . ' />';
                break;
            case "upload":
                $output .= siteoptions_uploader_function($value['id'], $value['std'], null);
                break;
            case "upload_min":
                $output .= siteoptions_uploader_function($value['id'], $value['std'], 'min');
                break;
            case "color":
                $val = $value['std'];
                $stored = get_option($value['id']);
                if ($stored != "") {
                    $val = $stored;
                }
                $output .= '<div id="' . $value['id'] . '_picker" class="colorSelector"><div></div></div>';
                $output .= '<input class="m413-color" name="' . $value['id'] . '" id="' . $value['id'] . '" type="text" value="' . $val . '" />';
                break;
            case "images":
                $i = 0;
                $select_value = get_option($value['id']);
                foreach ($value['options'] as $key => $option) {
                    $i++;
                    $checked = '';
                    $selected = '';
                    if ($select_value != '') {
                        if ($select_value == $key) {
                            $checked = ' checked';
                            $selected = 'm413-radio-img-selected';
                        }
                    } else {
                        if ($value['std'] == $key) {
                            $checked = ' checked';
                            $selected = 'm413-radio-img-selected';
                        } elseif ($i == 1 && !isset($select_value)) {
                            $checked = ' checked';
                            $selected = 'm413-radio-img-selected';
                        } elseif ($i == 1 && $value['std'] == '') {
                            $checked = ' checked';
                            $selected = 'm413-radio-img-selected';
                        } else {
                            $checked = '';
                        }
                    }
                    $output .= '<span>';
                    $output .= '<input type="radio" id="m413-radio-img-' . $value['id'] . $i . '" class="checkbox m413-radio-img-radio" value="' . $key . '" name="' . $value['id'] . '" ' . $checked . ' />';
                    $output .= '<div class="m413-radio-img-label">' . $key . '</div>';
                    $output .= '<img src="' . $option . '" alt="" class="m413-radio-img-img ' . $selected . '" onClick="document.getElementById(\'m413-radio-img-' . $value['id'] . $i . '\').checked = true;" />';
                    $output .= '</span>';
                }
                break;
            case "info":
                $default = $value['std'];
                $output .= $default;
                break;
                /*
                		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' => m413_recognized_font_sizes(),
                				'faces' => m413_recognized_font_faces(),
                				'styles' => m413_recognized_font_styles(),
                				'color' => true
                				);
                
                			if ( isset( $value['options'])){
                				$typography_options = wp_parse_args( $value['options'], $typography_options);
                			}
                
                			//font sizes
                			if ( $typography_options['sizes']){
                				$font_size = '<select class="m413-typography m413-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). '>'. exc_html($size). '</option>';
                				}
                				$font_size .= '</select>';
                			}
                
                			//font face
                			if ( $typography_options['faces'] ) {
                				$font_face = '<select class="m413-typography m413-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 style
                			if ( $typography_options['styles'] ) {
                				$font_style = '<select class="m413-typography m413-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'] ) {
                				$font_color = '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $typography_stored['color'] ) . '"></div></div>';
                				$font_color .= '<input class="m413-color m413-typography m413-typography-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $typography_stored['color'] ) . '" />';
                			}
                
                			// Allow modification/injection of typography fields
                			$typography_fields = compact( 'font_size', 'font_face', 'font_style', 'font_color' );
                			$typography_fields = apply_filters( 'm413_typography_fields', $typography_fields, $typography_stored, $option_name, $value );
                			$output .= implode( '', $typography_fields );
                
                			break;
                */
            /*
            		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' => m413_recognized_font_sizes(),
            				'faces' => m413_recognized_font_faces(),
            				'styles' => m413_recognized_font_styles(),
            				'color' => true
            				);
            
            			if ( isset( $value['options'])){
            				$typography_options = wp_parse_args( $value['options'], $typography_options);
            			}
            
            			//font sizes
            			if ( $typography_options['sizes']){
            				$font_size = '<select class="m413-typography m413-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). '>'. exc_html($size). '</option>';
            				}
            				$font_size .= '</select>';
            			}
            
            			//font face
            			if ( $typography_options['faces'] ) {
            				$font_face = '<select class="m413-typography m413-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 style
            			if ( $typography_options['styles'] ) {
            				$font_style = '<select class="m413-typography m413-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'] ) {
            				$font_color = '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $typography_stored['color'] ) . '"></div></div>';
            				$font_color .= '<input class="m413-color m413-typography m413-typography-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $typography_stored['color'] ) . '" />';
            			}
            
            			// Allow modification/injection of typography fields
            			$typography_fields = compact( 'font_size', 'font_face', 'font_style', 'font_color' );
            			$typography_fields = apply_filters( 'm413_typography_fields', $typography_fields, $typography_stored, $option_name, $value );
            			$output .= implode( '', $typography_fields );
            
            			break;
            */
            case "heading":
                if ($counter >= 2) {
                    $output .= '</div>' . "\n";
                }
                $jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']));
                $jquery_click_hook = "m413-option-" . $jquery_click_hook;
                $menu .= '<li><a title="' . $value['name'] . '" href="#' . $jquery_click_hook . '">' . $value['name'] . '</a></li>';
                $output .= '<div class="group" id="' . $jquery_click_hook . '"><h2>' . $value['name'] . '</h2>' . "\n";
                break;
            case "divider":
                $output .= '';
                break;
        }
        // if TYPE is an array, formatted into smaller inputs... ie smaller values
        if (is_array($value['type'])) {
            foreach ($value['type'] as $array) {
                $id = $array['id'];
                $std = $array['std'];
                $saved_std = get_option($id);
                if ($saved_std != $std) {
                    $std = $saved_std;
                }
                $meta = $array['meta'];
                if ($array['type'] == 'text') {
                    // Only text at this point
                    $output .= '<input class="input-text-small m413-input" name="' . $id . '" id="' . $id . '" type="text" value="' . $std . '" />';
                    $output .= '<span class="meta-two">' . $meta . '</span>';
                }
            }
        }
        if ($value['type'] != "heading") {
            if ($value['type'] != "checkbox") {
                $output .= '<br/>';
            }
            if (!isset($value['desc'])) {
                $explain_value = '';
            } else {
                $explain_value = $value['desc'];
            }
            $output .= '</div><div class="explain">' . $explain_value . '</div>' . "\n";
            $output .= '<div class="clear"> </div></div></div>' . "\n";
        }
    }
    $output .= '</div>';
    return array($output, $menu);
}