avia_superobject = $avia_superobject; $options = get_option($this->avia_superobject->option_prefix); //check which option pages were already saved yet and need replacement of the default values foreach($avia_superobject->option_pages as $page) { if(isset($options[$page['parent']]) && $options[$page['parent']] != "") { $this->replace_default[$page['slug']] = true; } } } function get_page_elements($slug) { $page_elements = array(); if(isset($this->avia_superobject->option_page_data)) { foreach($this->avia_superobject->option_page_data as $key => $value) { if($value['slug'] == $slug) { $page_elements[$key] = $value; } } } return $page_elements; } ###################################################################### # Rendering Functions ###################################################################### function create_container_based_on_slug($option_page, $firstClass = '') { $output = ""; //get all elements of the current page and save them to the page elements array $page_elements = $this->get_page_elements($option_page['slug']); //subpage heading $output .= $this->render_page_container($option_page, $firstClass); //remove button if available: if(isset($option_page['removable'])) { $output .= "".$option_page['removable'].""; } //page elements foreach($page_elements as $key=>$element) { $output .= $this->render_single_element($element); } $output .= $this->render_page_container_end(); return $output; } /** * render_single_element * * The function renders a single option-section which means it creates the divs arround the form element, as well as descripio, adds values and sets ids * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section * @return string $output the string returned contains the html code generated within the method */ function render_single_element( $element ) { if( method_exists( $this, $element['type'] ) || (isset($element['use_function']) && function_exists($element['type']))) { //init indices that are not set yet to prevent php notice if( !isset( $element['id'] ) ) { $element['id'] = ""; } if( !isset( $element['desc'] ) ) { $element['desc'] = ""; } if( !isset( $element['name'] ) ) { $element['name'] = ""; } if( !isset( $element['label'] ) ) { $element['label'] = ""; } if( !isset( $element['std'] ) ) { $element['std'] = ""; } if( !isset( $element['class'] ) ) { $element['class'] = ""; } if( !isset( $element['dynamic'] ) ) { $element['dynamic'] = false; } if($this->context != 'metabox') { if(isset($this->avia_superobject->page_slug) && isset($this->replace_default[$element['slug']]) && isset($this->avia_superobject->options[$this->avia_superobject->page_slug][$element['id']])) { $element['std'] = $this->avia_superobject->options[$this->avia_superobject->page_slug][$element['id']]; } } //start rendering $output = ""; //check if its a dynamic (sortable) element $dynamic_end = ""; if($element['dynamic']) { $output .= '
'; $output .= '
'; $output .= '
'.$element['name'].'+
'; $output .= '
'; $output .= ' Loading'; $output .= " ".$element['removable'].""; $dynamic_end = '
'; } //check if we should only render the element itself or description as well if($element['type'] == 'group' || (isset($element['nodescription']) && $element['nodescription'] != "")) { if(isset($element['use_function'])) { $output .= $element['type']( $element ); } else { $output .= $this->{$element['type']}( $element ); } } else { $output .= $this->section_start( $element ); if(isset($element['removable']) && !isset($element['dynamic'])) { $output .= ' Loading'; $output .= " ".$element['removable'].""; } $output .= $this->description( $element ); if(isset($element['use_function'])) { $output .= $element['type']( $element ); } else { $output .= $this->{$element['type']}( $element ); } $output .= $this->section_end( $element ); } $output .= $dynamic_end; return $output; } } /** * Creates a wrapper around a set of elements. This set can be cloned with javascript * @param array $element the array holds data like id, class and some js settings * @return string $output the string returned contains the html code generated within the method */ function group( $element ) { $iterations = 1; $output = ""; $real_id = $element['id']; if((isset($element['std']) && is_array($element['std'])) && !isset($element['ajax_request'])) { $iterations = count($element['std']); } if(isset($element['ajax_request'])) $iterations = $element['ajax_request']; // ajax requests usually need only one element per default for ($i = 0; $i < $iterations; $i++) { if(!isset($element['linktext'])) $element['linktext'] = "add"; if(!isset($element['deletetext'])) $element['deletetext'] = "remove"; //start generating html output $element['id'] = $real_id.'-__-'.$i; $output .= '
'; $output .= '
'; $output .= $this->get_subelements($element, $i); $output .= ' Loading'; $output .= ' '.$element['linktext'].''; $output .= ' '.$element['deletetext'].''; $output .= '
'; $output .= '
'; } return $output; } /** * Creates the subelements for groups and specail objects like gallery upload * @param array $element the array holds data like id, class and some js settings * @return string $output the string returned contains the html code generated within the method */ function get_subelements($element, $i = 1) { $output = ""; foreach($element['subelements'] as $key => $subelement) { if(isset($element['std']) && is_array($element['std']) && isset($element['std'][$i][$subelement['id']])) { $subelement['std'] = $element['std'][$i][$subelement['id']]; } if(isset($element['ajax_request'])) { $subelement['ajax_request'] = $element['ajax_request']; } $subelement['subgroup_item'] = true; $subelement['id'] = $element['id']."-__-".$subelement['id']; if(isset($element['apply_all'])) $subelement['apply_all'] = $element['apply_all']; $output .= $this->render_single_element($subelement); } return $output; } /** * * The text method renders the title and the page containing wrapper necessary for javascript sidebar tabs * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section * @return string $output the string returned contains the html code generated within the method */ function render_page_container( $pageinfo , $firstClass ) { if(!isset($pageinfo['sortable'])) $pageinfo['sortable'] = ""; $output = '
'; $output .= '
'; $output .= ' '; $output .= $pageinfo['title']; $output .= ' '; $output .= '
'; return $output; } /** * Closes the page container * @return string $output the string returned contains the html code generated within the method */ function render_page_container_end() { $output = '
'; return $output; } function verification_field( $element ) { $callback = $element['ajax']; $js_callback = isset($element['js_callback']) ? $element['js_callback'] : ""; $element['simple'] = true; $output = ""; $ajax = false; if(isset($element['button-relabel']) && !empty($element['std'])) { $element['button-label'] = $element['button-relabel']; } $output .= ''; $output .= $this->text($element); $output .= ''.$element['button-label'].''; $output .= ''; $output .= isset($element['help']) ? "".$element['help']."" : ""; $output .= "
"; if($element['std'] != "") { $output .= str_replace('avia_trigger_save' ,"",$callback( $element['std'] , $ajax)); } $output .= "
"; return $output; } /** * * The text method renders a single input type:text element * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section * @return string $output the string returned contains the html code generated within the method */ function text( $element ) { $extraClass = ""; if(isset($element['class_on_value']) && !empty($element['std'])) $extraClass = " ".$element['class_on_value']; $text = ''; if(isset($element['simple'])) return $text; return ''.$text.''; } /** * * The hidden method renders a single input type:hidden element * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section * @return string $output the string returned contains the html code generated within the method */ function hidden( $element ) { $output = '
'; return $output; } /** * * The checkbox method renders a single input type:checkbox element * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section * @return string $output the string returned contains the html code generated within the method * @todo: fix: checkboxes at metaboxes currently dont work */ function checkbox( $element ) { $checked = ""; if( $element['std'] != "" && $element['std'] != "disabled" ) { $checked = 'checked = "checked"'; } $output = ''; return $output; } /** * * The radio method renders one or more input type:radio elements, based on the definition of the $elements array * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section * @return string $output the string returned contains the html code generated within the method */ function radio( $element ) { $output = ""; $counter = 1; foreach($element['buttons'] as $radiobutton) { $checked = ""; if( $element['std'] == $counter ) { $checked = 'checked = "checked"'; } $output .= ''; $output .= ''; $output .= ''; $output .= ''; $counter++; } return $output; } /** * * The textarea method renders a single textarea element * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section * @return string $output the string returned contains the html code generated within the method */ function textarea( $element ) { $output = ''; return $output; } /** * * The link_controller method renders a bunch of links that are able to set values for other page elements * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section * @return string $output the string returned contains the html code generated within the method */ function link_controller( $element ) { $output = ""; $output .= '
'; if(!empty($element['subtype'])) { $counter = 0; foreach($element['subtype'] as $key=>$array) { $counter ++; $active = $style = $class = $data = ""; if(isset($array[$element['id']]) && $array[$element['id']] == $element['std'] ) $active = " avia_link_controller_active"; if(isset($array['style'])) { $style = " style='".$array['style']."' "; unset($array['style']); } if(isset($array['class'])) { $class = " ".$array['class']; unset($array['class']); } foreach($array as $datakey=> $datavalue) { $data .= "data-".$datakey."='".$datavalue."' "; } $output .= "".$key.""; } } $output .= ''; $output .= "
"; return $output; } /** * * The upload method renders a single upload element so users can add their own pictures * the script first gets the id of a hidden post that should store the image. if no post is set it will create one * then we check if a basic url based upload should be used or a more sophisticated id based for slideshows and feauted images, which need * the images resized automatically * * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section * @return string $output the string returned contains the html code generated within the method */ function upload( $element ) { global $post_ID; $output = ""; $gallery_mode = false; $id_generated = false; $image_url = $element['std']; if(empty($element['button-label'])) $element['button-label'] = "Upload"; //get post id of the hidden post that stores the image if(!empty($element['attachment-prefix'])) { if(empty($element['std']) && empty($element['no-attachment-id'])) { $element['std'] = uniqid(); $id_generated = true; } $gallery_mode = true; $postId = avia_media::get_custom_post($element['attachment-prefix'].$element['std']); } else { $postId = avia_media::get_custom_post($element['name']); if(is_numeric($element['std'])) { $image_url = wp_get_attachment_image_src($element['std'], 'full'); $image_url = $image_url[0]; } } //switch between normal url upload and advanced image id upload $mode = $prevImg = ""; //video or image, advanced or default upload? if(isset($element['subtype'])) { $mode = ' avia_advanced_upload'; if(!is_numeric($element['std']) && $element['std'] != '') { $prevImg = '×'; } else if($element['std'] != '') { $prevImg = '×'.wp_get_attachment_image($element['std'], array(100,100)); } } else { if(!preg_match('!\.jpg$|\.jpeg$|\.ico$|\.png$|\.gif$!', $image_url) && $image_url != "" ) { $prevImg = '×'; } else if($image_url != '') { $prevImg = '×'; } } if($gallery_mode) { $image_url_array = array(); $attachments = get_children(array('post_parent' => $postId, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')); foreach($attachments as $key => $attachment) { $image_url_array[] = avia_image_by_id($attachment->ID, array('width'=>80,'height'=>80)); } $output .= "
"; if(isset($image_url_array[0])) { foreach($image_url_array as $key => $img) { $output .= ""; } $output .= "
"; } $output .= "
"; } $data = ""; $upload_class = "avia_uploader"; global $wp_version; if(version_compare($wp_version, '3.5', '>=' ) && empty($element['force_old_media']) && empty($element['subtype']) ) //check if new media upload is enabled { $upload_class = "avia_uploader_35"; if(empty($element['data'])) { $element['data'] = array( 'target' => $element['id'], 'title' => $element['name'], 'type' => 'image', 'button' => $element['label'], 'class' => 'media-frame av-media-frame-image-only' , 'frame' => 'select', 'state' => 'av_select_single_image', 'fetch' => 'url', ); } foreach($element['data'] as $key=>$value) { if(is_array($value)) $value = implode(", ",$value); $data .= " data-$key='$value' "; } } $output .= '
'; $output .= ' '; $output .= ' '; $output .= ' '.$element['button-label'].''; $output .= ' '; $output .= '
'.$prevImg.'
'; $output .= ' '; if($gallery_mode) $output .= ' '; $output .= '
'; return $output; } /** * * The upload gallery method renders a single upload element so users can add their own pictures and/or videos * * @param array $element the array holds data like type, value, id, class, description which are necessary to render the whole option-section * @return string $output the string returned contains the html code generated within the method */ function upload_gallery( $element ) { //first gernerate the sub_item_output $sub_output = ""; $iterations = 0; $real_id = $element['id']; if((isset($element['std']) && is_array($element['std'])) && !isset($element['ajax_request'])) { if(!empty($element['std'][0]['slideshow_image']) || !empty($element['std'][0]['slideshow_video'])) { $iterations = count($element['std']); } } $video_button = "Add external video by URL"; if(isset($element['button_video'])) $video_button = $element['button_video']; // ajax requests usually need only one element per default if(isset($element['ajax_request'])) $iterations = $element['ajax_request']; // ajax requests usually need only one element per default for ($i = 0; $i < $iterations; $i++) { //start generating html output $element['id'] = $real_id.'-__-'.$i; $sub_output .= '
'; $sub_output .= '
'; $sub_output .= $this->get_subelements($element, $i); $sub_output .= ' '.__('(remove)').''; $sub_output .= ' '.__('Show').''; $sub_output .= '
'; $sub_output .= '
'; } //if this is an ajax request stop here if(isset($element['ajax_request'])) return $sub_output; global $post_ID; //if we want to retrieve the whole element and this is not an ajax call do the following as well: if(empty($element['button-label'])) $element['button-label'] = "Add Image to slideshow"; $postId = $post_ID; //avia_media::get_custom_post($element['name']); $output = ""; $output .= '