Exemplo n.º 1
0
	public static function undsgn_machine($options) {

		$data = get_option(OPTIONS);

		$defaults = array();
		$counter = 0;
		$menu = '';
		$output = '';
		foreach ($options as $value) {

			$counter++;
			$val = '';

			//create array of defaults
			if ($value['type'] == 'multicheck'){
				if (is_array($value['std'])){
					foreach($value['std'] as $i=>$key){
						$defaults[$value['id']][$key] = true;
					}
				} else {
					$defaults[$value['id']][$value['std']] = true;
				}
			} else {
				if (isset($value['id'])) {
					if (isset($value['std'])) $defaults[$value['id']] = $value['std'];
				}
			}


			//Start Heading
			if ( $value['type'] != "heading" )
			{
				$class = ''; if(isset( $value['class'] )) { $class = $value['class']; }

				$fold='';
				$unfold='';
				//hide items in checkbox-group
				if (array_key_exists("fold",$value)) {
					if ($data[$value['fold']]) {
						$fold="f_".$value['fold']." ";
					} else {
						$fold="f_".$value['fold']." temphide ";
					}
				}

				if (array_key_exists("unfold",$value)) {
					if ($data[$value['unfold']]) {
						$unfold="u_".$value['unfold']." temphide ";
					} else {

						$unfold="u_".$value['unfold']." ";
					}
				}

				$output .= '<div id="section-'.$value['id'].'" class="'.$fold.$unfold.'section section-'.$value['type'].' '. $class .'">'."\n";
				if ($value['name']) $output .= '<h3 class="heading">'. $value['name'] .'</h3>'."\n";
				$output .= '<div class="option">'."\n" . '<div class="controls">'."\n";

			}
			//End Heading

			switch ( $value['type'] ) {

			case 'text':
				$t_value = '';

				if (isset($data[$value['id']]) && $data[$value['id']]) $t_value = stripslashes($data[$value['id']]);

				$mini ='';
				if(!isset($value['mod'])) $value['mod'] = '';
				if($value['mod'] == 'mini') { $mini = 'mini';}

				$output .= '<input class="undsgn-input '.$mini.'" name="'.$value['id'].'" id="'. $value['id'] .'" type="'. $value['type'] .'" value="'. $t_value .'" />';
				break;
			case 'select':
				$mini ='';
				if(!isset($value['mod'])) $value['mod'] = '';
				if($value['mod'] == 'mini') { $mini = 'mini';}
				$output .= '<div class="select_wrapper ' . $mini . '">';
				$output .= '<select class="select undsgn-input" name="'.$value['id'].'" id="'. $value['id'] .'">';
				foreach ($value['options'] as $select_ID => $option) {
					$output .= '<option id="' . $select_ID . '" value="'.$option.'" ' . selected($data[$value['id']], $option, false) . ' />'.$option.'</option>';
				}
				$output .= '</select></div>';
				break;
			case 'select2':
				$mini ='';
				if(!isset($value['mod'])) $value['mod'] = '';
				if($value['mod'] == 'mini') { $mini = 'mini';}
				$output .= '<div class="select_wrapper ' . $mini . '">';
				$output .= '<select class="select undsgn-input" name="'.$value['id'].'" id="'. $value['id'] .'">';
				foreach ($value['options'] as $select_ID => $option) {
					$std = (isset($data[$value['id']])) ? $data[$value['id']] : $value['std'];
					$output .= '<option id="' . $select_ID . '" value="'.$select_ID.'" ' . selected($std, $select_ID, false) . ' />'.$option.'</option>';
				}
				$output .= '</select></div>';
				break;
			case 'textarea':
				$cols = '8';
				$ta_value = '';

				if(isset($value['options'])){
					$ta_options = $value['options'];
					if(isset($ta_options['cols'])){
						$cols = $ta_options['cols'];
					}
				}

				if (isset($data[$value['id']]) && $data[$value['id']]) $ta_value = stripslashes($data[$value['id']]);
				$output .= '<textarea class="undsgn-input" name="'.$value['id'].'" id="'. $value['id'] .'" cols="'. $cols .'" rows="8">'.$ta_value.'</textarea>';
				break;
			case "radio":
				foreach($value['options'] as $option=>$name) {
					$std = (isset($data[$value['id']])) ? $data[$value['id']] : $value['std'];
					$output .= '<input class="undsgn-input undsgn-radio" name="'.$value['id'].'" type="radio" value="'.$option.'" ' . checked($std, $option, false) . ' /><label class="radio">'.$name.'</label><br/>';
				}
				break;
			case 'checkbox':
				if (!isset($data[$value['id']])) {
					$data[$value['id']] = 0;
				}

				if (array_key_exists("folds",$value)) {
					$fold="fld ";
				}

				$output .= '<input type="hidden" class="'.$fold.'checkbox aq-input" name="'.$value['id'].'" id="'. $value['id'] .'" value="0"/>';
				$output .= '<input type="checkbox" class="'.$fold.'checkbox undsgn-input" name="'.$value['id'].'" id="'. $value['id'] .'" value="1" '. checked($data[$value['id']], 1, false) .' />';
				break;
			case 'multicheck':
				$multi_stored = $data[$value['id']];

				foreach ($value['options'] as $key => $option) {
					if (!isset($multi_stored[$key])) {$multi_stored[$key] = '';}
					$undsgn_key_string = $value['id'] . '_' . $key;
					$output .= '<input type="checkbox" class="checkbox undsgn-input" name="'.$value['id'].'['.$key.']'.'" id="'. $undsgn_key_string .'" value="1" '. checked($multi_stored[$key], 1, false) .' /><label class="multicheck" for="'. $undsgn_key_string .'">'. $option .'</label><br />';
				}
				break;
			case 'upload':
				if(!isset($value['mod'])) $value['mod'] = '';
				$output .= Options_Machine::undsgn_uploader_function($value['id'],$value['std'],$value['mod']);
				break;
			case 'media':
				$_id = strip_tags( strtolower($value['id']) );
				$int = '';
				$int = undsgn_mlu_get_silentpost( $_id );
				if(!isset($value['mod'])) $value['mod'] = '';
				$output .= Options_Machine::undsgn_media_uploader_function( $value['id'], $value['std'], $int, $value['mod'] ); // New AJAX Uploader using Media Library
				break;
			case 'color':
				$output .= '<div id="' . $value['id'] . '_picker" class="colorSelector"><div style="background-color: '.$data[$value['id']].'"></div></div>';
				$output .= '<input class="undsgn-color" name="'.$value['id'].'" id="'. $value['id'] .'" type="text" value="'. $data[$value['id']] .'" />';
				break;
			case 'typography':

				$typography_stored = isset($data[$value['id']]) ? $data[$value['id']] : $value['std'];

				/* Font Size */

				if(isset($typography_stored['size'])) {
					$output .= '<div class="select_wrapper typography-size" original-title="Font size">';
					$output .= '<select class="undsgn-typography undsgn-typography-size select" name="'.$value['id'].'[size]" id="'. $value['id'].'_size">';
					for ($i = 9; $i < 20; $i++){
						$test = $i.'px';
						$output .= '<option value="'. $i .'px" ' . selected($typography_stored['size'], $test, false) . '>'. $i .'px</option>';
					}

					$output .= '</select></div>';

				}

				/* Line Height */

				if(isset($typography_stored['height'])) {

					$output .= '<div class="select_wrapper typography-height" original-title="Line height">';
					$output .= '<select class="undsgn-typography undsgn-typography-height select" name="'.$value['id'].'[height]" id="'. $value['id'].'_height">';
					for ($i = 20; $i < 38; $i++){
						$test = $i.'px';
						$output .= '<option value="'. $i .'px" ' . selected($typography_stored['height'], $test, false) . '>'. $i .'px</option>';
					}

					$output .= '</select></div>';

				}

				/* Font Face */

				if(isset($typography_stored['face'])) {

					$output .= '<div class="select_wrapper typography-face" original-title="Font family">';
					$output .= '<select class="undsgn-typography undsgn-typography-face select" name="'.$value['id'].'[face]" id="'. $value['id'].'_face">';

					$faces = array('arial'=>'Arial',
						'verdana'=>'Verdana, Geneva',
						'trebuchet'=>'Trebuchet',
						'georgia' =>'Georgia',
						'times'=>'Times New Roman',
						'tahoma'=>'Tahoma, Geneva',
						'palatino'=>'Palatino',
						'helvetica'=>'Helvetica' );
					foreach ($faces as $i=>$face) {
						$output .= '<option value="'. $i .'" ' . selected($typography_stored['face'], $i, false) . '>'. $face .'</option>';
					}

					$output .= '</select></div>';

				}

				/* Font Weight */

				if(isset($typography_stored['style'])) {

					$output .= '<div class="select_wrapper typography-style" original-title="Font style">';
					$output .= '<select class="undsgn-typography undsgn-typography-style select" name="'.$value['id'].'[style]" id="'. $value['id'].'_style">';
					$styles = array('normal'=>'Normal',
						'italic'=>'Italic',
						'bold'=>'Bold',
						'bold italic'=>'Bold Italic');

					foreach ($styles as $i=>$style){

						$output .= '<option value="'. $i .'" ' . selected($typography_stored['style'], $i, false) . '>'. $style .'</option>';
					}
					$output .= '</select></div>';

				}

				/* Font Color */

				if(isset($typography_stored['color'])) {

					$output .= '<div id="' . $value['id'] . '_color_picker" class="colorSelector typography-color"><div style="background-color: '.$typography_stored['color'].'"></div></div>';
					$output .= '<input class="undsgn-color undsgn-typography undsgn-typography-color" original-title="Font color" name="'.$value['id'].'[color]" id="'. $value['id'] .'_color" type="text" value="'. $typography_stored['color'] .'" />';

				}

				break;
			case 'border':

				/* Border Width */
				$border_stored = $data[$value['id']];

				$output .= '<div class="select_wrapper border-width">';
				$output .= '<select class="undsgn-border undsgn-border-width select" name="'.$value['id'].'[width]" id="'. $value['id'].'_width">';
				for ($i = 0; $i < 21; $i++){
					$output .= '<option value="'. $i .'" ' . selected($border_stored['width'], $i, false) . '>'. $i .'</option>';     }
				$output .= '</select></div>';

				/* Border Style */
				$output .= '<div class="select_wrapper border-style">';
				$output .= '<select class="undsgn-border undsgn-border-style select" name="'.$value['id'].'[style]" id="'. $value['id'].'_style">';

				$styles = array('none'=>'None',
					'solid'=>'Solid',
					'dashed'=>'Dashed',
					'dotted'=>'Dotted');

				foreach ($styles as $i=>$style){
					$output .= '<option value="'. $i .'" ' . selected($border_stored['style'], $i, false) . '>'. $style .'</option>';
				}

				$output .= '</select></div>';

				/* Border Color */
				$output .= '<div id="' . $value['id'] . '_color_picker" class="colorSelector"><div style="background-color: '.$border_stored['color'].'"></div></div>';
				$output .= '<input class="undsgn-color undsgn-border undsgn-border-color" name="'.$value['id'].'[color]" id="'. $value['id'] .'_color" type="text" value="'. $border_stored['color'] .'" />';

				break;
			case 'images':

				$i = 0;

				$select_value = $data[$value['id']];

				foreach ($value['options'] as $key => $option)
				{
					$i++;

					$checked = '';
					$selected = '';
					if(NULL!=checked($select_value, $key, false)) {
						$checked = checked($select_value, $key, false);
						$selected = 'undsgn-radio-img-selected';
					}
					$output .= '<span>';
					$output .= '<input type="radio" id="undsgn-radio-img-' . $value['id'] . $i . '" class="checkbox undsgn-radio-img-radio" value="'.$key.'" name="'.$value['id'].'" '.$checked.' />';
					$output .= '<div class="undsgn-radio-img-label">'. $key .'</div>';
					$output .= '<img src="'.$option.'" alt="" class="undsgn-radio-img-img '. $selected .'" onClick="document.getElementById(\'undsgn-radio-img-'. $value['id'] . $i.'\').checked = true;" />';
					$output .= '</span>';
				}

				break;
			case "info":
				$info_text = $value['std'];
				$output .= '<div class="undsgn-info">'.$info_text.'</div>';
				break;
			case "image":
				$src = $value['std'];
				$output .= '<img src="'.$src.'">';
				break;
			case 'heading':
				if($counter >= 2){
					$output .= '</div>'."\n";
				}
				$header_class = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']) );
				$jquery_click_hook = ereg_replace("[^A-Za-z0-9]", "", strtolower($value['name']) );
				$jquery_click_hook = "undsgn-option-" . $jquery_click_hook;
				$menu .= '<li class="'. $header_class .'"><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 'slider':
				$_id = strip_tags( strtolower($value['id']) );
				$int = '';
				$int = undsgn_mlu_get_silentpost( $_id );
				$output .= '<div class="slider"><ul id="'.$value['id'].'" rel="'.$int.'">';
				if (isset($data[$value['id']]) && $data[$value['id']]) {
					$slides = $data[$value['id']];
					$count = count($slides);
					if ($count < 2) {
						$oldorder = 1;
						$order = 1;
						$output .= Options_Machine::undsgn_slider_function($value['id'],$value['std'],$oldorder,$order,$int);
					} else {
						$i = 0;
						foreach ($slides as $slide) {
							$oldorder = $slide['order'];
							$i++;
							$order = $i;
							$output .= Options_Machine::undsgn_slider_function($value['id'],$value['std'],$oldorder,$order,$int);
						}
					}
				}
				$output .= '</ul>';
				$output .= '<a href="#" class="button slide_add_button">Add New Slide</a></div>';

				break;
			case 'frontpage':
				$_id = strip_tags( strtolower($value['id']) );
				$int = '';
				$int = undsgn_mlu_get_silentpost( $_id );
				$output .= '<div class="slider"><input type="checkbox" class="toggleIncluded" /><ul id="'.$value['id'].'" class="frontpagelist" rel="'.$int.'">';
				if (isset($data[$value['id']]) && $data[$value['id']]) {
					$slides = $data[$value['id']];
					$count = count($slides);
					if ($count < 2) {
						$oldorder = 1;
						$order = 1;
						$output .= Options_Machine::undsgn_frontpage_function($value['id'],$value['std'],$oldorder,$order,$int);
					} else {
						$i = 0;
						foreach ($slides as $slide) {
							$oldorder = $slide['order'];
							$i++;
							$order = $i;
							$output .= Options_Machine::undsgn_frontpage_function($value['id'],$value['std'],$oldorder,$order,$int);
						}
					}
				}
				$output .= '</ul>';
				$output .= '<a href="#" class="button front_add_content">Load content</a></div>';

				break;
			case 'dynalist':
				$_id = strip_tags( strtolower($value['id']) );
				$int = '';
				$int = undsgn_mlu_get_silentpost( $_id );
				$output .= '<div class="slider"><ul id="'.$value['id'].'" rel="'.$int.'">';
				if (isset($data[$value['id']]) && $data[$value['id']]) {
					$slides = $data[$value['id']];
					$count = count($slides);
					if ($count < 2) {
						$oldorder = 1;
						$order = 1;
						$output .= Options_Machine::undsgn_dynalist_function($value['id'],$value['std'],$oldorder,$order,$int);
					} else {
						$i = 0;
						foreach ($slides as $slide) {
							$oldorder = $slide['order'];
							$i++;
							$order = $i;
							$output .= Options_Machine::undsgn_dynalist_function($value['id'],$value['std'],$oldorder,$order,$int);
						}
					}
				}
				$output .= '</ul>';
				$output .= '<a href="#" class="button list_add_button">Add New Detail</a></div>';

				break;
			case 'sorter':

				$sortlists = isset($data[$value['id']]) && !empty($data[$value['id']]) ? $data[$value['id']] : $value['std'];

				$output .= '<div id="'.$value['id'].'" class="sorter">';


				if ($sortlists) {

					foreach ($sortlists as $group=>$sortlist) {

						$output .= '<ul id="'.$value['id'].'_'.$group.'" class="sortlist_'.$value['id'].'">';
						$output .= '<h3>'.$group.'</h3>';

						foreach ($sortlist as $key => $list) {

							$output .= '<input class="sorter-placebo" type="hidden" name="'.$value['id'].'['.$group.'][placebo]" value="placebo">';

							if ($key != "placebo") {

								$output .= '<li id="'.$key.'" class="sortee">';
								$output .= '<input class="position" type="hidden" name="'.$value['id'].'['.$group.']['.$key.']" value="'.$list.'">';
								$output .= $list;
								$output .= '</li>';

							}

						}

						$output .= '</ul>';
					}
				}

				$output .= '</div>';
				break;
			case 'tiles':

				$i = 0;
				$select_value = '';
				$select_value = $data[$value['id']];

				foreach ($value['options'] as $key => $option)
				{
					$i++;

					$checked = '';
					$selected = '';
					if(NULL!=checked($select_value, $option, false)) {
						$checked = checked($select_value, $option, false);
						$selected = 'undsgn-radio-tile-selected';
					}
					$output .= '<span>';
					$output .= '<input type="radio" id="undsgn-radio-tile-' . $value['id'] . $i . '" class="checkbox undsgn-radio-tile-radio" value="'.$option.'" name="'.$value['id'].'" '.$checked.' />';
					$output .= '<div class="undsgn-radio-tile-img '. $selected .'" style="background: url('.$option.')" onClick="document.getElementById(\'undsgn-radio-tile-'. $value['id'] . $i.'\').checked = true;"></div>';
					$output .= '</span>';
				}

				break;
				// Background
			case 'background':

				$background = $data[$value['id']];

				// Background Color
				$output .= '<div id="' . esc_attr( $value['id'] ) . '_color_picker" class="colorSelector"><div style="' . esc_attr( 'background-color:' . $background['color'] ) . '"></div></div>';
				$output .= '<input class="undsgn-color undsgn-background undsgn-background-color" name="' . esc_attr( $option_name . '[' . $value['id'] . '][color]' ) . '" id="' . esc_attr( $value['id'] . '_color' ) . '" type="text" value="' . esc_attr( $background['color'] ) . '" />';

				// Background Image - New AJAX Uploader using Media Library
				if (!isset($background['image'])) {
					$background['image'] = '';
				}

				$output .= undsgn_medialibrary_uploader( $value['id'], $background['image'], null, '',0,'image');
				$class = 'undsgn-background-properties';
				if ( '' == $background['image'] ) {
					$class .= ' hide';
				}
				$output .= '<div class="' . esc_attr( $class ) . '">';

				// Background Repeat
				$output .= '<select class="undsgn-background undsgn-background-repeat" name="' . esc_attr( $option_name . '[' . $value['id'] . '][repeat]'  ) . '" id="' . esc_attr( $value['id'] . '_repeat' ) . '">';
				$repeats = undsgn_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="undsgn-background undsgn-background-position" name="' . esc_attr( $option_name . '[' . $value['id'] . '][position]' ) . '" id="' . esc_attr( $value['id'] . '_position' ) . '">';
				$positions = undsgn_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="undsgn-background undsgn-background-attachment" name="' . esc_attr( $option_name . '[' . $value['id'] . '][attachment]' ) . '" id="' . esc_attr( $value['id'] . '_attachment' ) . '">';
				$attachments = undsgn_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;
			case 'iconic':
				$output .= '<div class="upload_button_div">';
				$output .= '<a href="#" id="undsgn_entypo_button" class="button" title="Install Entypo">Download and Install Entypo Iconic Font</a>';
				$output .= '</div>';
				break;
			case 'backup':

				/* $instructions = $value['options']; */
				$backup = get_option(BACKUPS);

				if(!isset($backup['backup_log'])) {
					$log = 'No backups yet';
				} else {
					$log = $backup['backup_log'];
				}

				$output .= '<div class="backup-box upload_button_div"><div>';
				/* $output .= '<div class="instructions">'.$instructions."\n"; */
				$output .= '<p><strong>'. __('Last Backup : ', 'undsgnoptions' ).'<span class="backup-log">'.$log.'</span></strong></p></div>'."\n";
				$output .= '<a href="#" id="undsgn_backup_button" class="button" title="Backup Options">Backup Options</a>';
				$output .= '<a href="#" id="undsgn_restore_button" class="button" title="Restore Options">Restore Options</a>';
				$output .= '</div>';

				break;

			//export or import data between different installs
				case 'transfer':

					$instructions = $value['desc'];
					$output .= '<textarea id="export_data" rows="8">'.base64_encode(serialize($data)) /* 100% safe - ignore theme check nag */ .'</textarea>'."\n";
					$output .= '<div class="upload_button_div"><a href="#" id="undsgn_import_button" class="button" title="Restore Options">Import Options</a></div>';

				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 undsgn-input" name="'. $id .'" id="'. $id .'" type="text" value="'. $std .'" />';
						$output .= '<span class="meta-two">'.$meta.'</span>';
					}
				}
			}
			if ( $value['type'] != 'heading' ) {
				if(!isset($value['desc'])){ $explain_value = ''; } else{
					$explain_value = '<div class="explain">'. $value['desc'] .'</div>'."\n";
				}
				$output .= '</div>'.$explain_value."\n";
				$output .= '<div class="clear"> </div></div></div>'."\n";
			}

		}
		$output .= '</div>';
		return array($output,$menu,$defaults);
	}