';
}
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 = '
';
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;
}
/**
*
* 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 .= '
";
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 .= "
';
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 .= '
';
}
//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 .= '
';
$output .= '
';
$output .= $sub_output;
$output .= '
';
$output .= '
';
$output .= ' ';
//generate the upload link
$output .= '';
//end link
$output .= ' ';
if(!empty($video_button))
{
$output .= ' ';
//generate the upload link
$output .= '';
//end link
$output .= ' ';
}
//delete button
$output .= ' ';
//generate the upload link
$output .= '';
$extraClass = " avia_gallery_image_vid";
}
else if($element['std'] != '')
{
$prevImg = wp_get_attachment_image($element['std'], array(100,100));
$extraClass = " avia_gallery_image_img";
}
$output ="";
$output .='
';
return $output;
}
/**
*
* The text method renders a single input type:text element. If autodetect is set the color picker trys to get the color from an image upload 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 colorpicker( $element )
{
$autodetect = $autodetectClass = "";
if(isset($element['autodetect']) && function_exists('gd_info'))
{
$autodetect = 'Auto detection';
$autodetectClass = ' avia_auto_detector';
}
$output = '';
$output .= '';
$output .= ''.$autodetect.'';
return $output;
}
/**
*
* The file_upload method renders a single zip file upload/insert element: user can select a zip file and a custom function/class will be executed then
* @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 file_upload($element)
{
# deny if user is no super admin
$output = "";
$cap = apply_filters('avf_file_upload_capability', 'update_plugins', $element);
if(!current_user_can($cap))
{
return "
Using this feature is reserved for Super Admins
You unfortunately don't have the necessary permissions.
";
}
#check if its allowed on multisite
if(is_multisite() && strpos(get_site_option('upload_filetypes'), $element['file_extension']) === false)
{
$file = strtoupper($element['file_extension']);
return "
You are currently on a WordPress multisite installation and .{$file} file upload is disabled. Go to your Network settings page and add the '{$file}' file extension to the list of allowed 'Upload file types'
Your Server has disabled the 'allow_url_fopen' setting in your php.ini which might cause problems when uploading and processing files
";
}
# is user is alowed to extract files create the upload/insert button
if(empty($element['data']))
{
$element['data'] = array( 'target' => $element['id'],
'title' => $element['title'],
'type' => $element['file_type'],
'button' => $element['button'],
'trigger' => $element['trigger'],
'class' => 'media-frame '
);
}
$data = "";
foreach($element['data'] as $key=>$value)
{
if(is_array($value)) $value = implode(", ",$value);
$data .= " data-$key='$value' ";
}
$class = 'avia_button avia-media-35 aviabuilder-file-upload avia-builder-file-insert '.$element['class'];
$output .= ''.$element['title'].'';
$output .= '';
//$output .= $this->text($element);
$output .= $this->hidden($element);
$output .= apply_filters('avf_file_upload_extra', '', $element);
return $output;
}
/**
*
* The select method renders a single select element: it either lists custom values, all wordpress pages or all wordpress categories
* @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 select( $element )
{
$base_url = "";
$folder_data = "";
if($element['subtype'] == 'page')
{
$select = 'Select page';
$entries = get_pages('title_li=&orderby=name');
}
else if($element['subtype'] == 'post')
{
$select = 'Select post';
$entries = get_posts('title_li=&orderby=name&numberposts=9999');
}
else if($element['subtype'] == 'cat')
{
$add_taxonomy = "";
if(!empty($element['taxonomy'])) $add_taxonomy = "&taxonomy=".$element['taxonomy'];
$select = 'Select category';
$entries = get_categories('title_li=&orderby=name&hide_empty=0'.$add_taxonomy);
}
else
{
$select = 'Select...';
$entries = $element['subtype'];
$add_entries = array();
if(isset($element['folder']))
{
$add_file_array = avia_backend_load_scripts_by_folder(AVIA_BASE.$element['folder']);
$base_url = AVIA_BASE_URL;
$folder_data = "data-baseurl='{$base_url}'";
if(is_array($add_file_array))
{
foreach($add_file_array as $file)
{
$skip = false;
if(!empty($element['exclude']))
{
foreach($element['exclude'] as $exclude) {
if (stripos($file,$exclude) !== false) $skip = true;
}
}
if(strpos($file, '.') !== 0 && $skip == false)
{
$add_entries[$element['folderlabel'].$file] = "{{AVIA_BASE_URL}}".$element['folder'].$file;
}
}
if(isset($element['group']))
{
$entries[$element['group']] = $add_entries;
}
else
{
$entries = array_merge($entries, $add_entries);
}
}
}
}
//check for onchange function
$onchange = "";
if(isset($element['onchange']))
{
$onchange = " data-avia-onchange='".$element['onchange']."' ";
$element['class'] .= " avia_onchange";
}
$multi = $multi_class = "";
if(isset($element['multiple']))
{
$multi_class = " avia_multiple_select";
$multi = 'multiple="multiple" size="'.$element['multiple'].'"';
if(!empty($element['std']))
{
$element['std'] = explode(',', (string) $element['std']);
}
}
$output = '';
$output .= '';
$output .= ''.$fake_val.'';
$output .= '';
if(isset($element['hook'])) $output.= '';
return $output;
}
function select_sidebar( $element )
{
$save_as = array();
foreach($element['additions'] as $key => $additions)
{
if($additions == "%result%")
{
$save_as = $key;
unset($element['additions'][$key]);
}
}
if(empty($save_as))
{
$element['subtype'] = av_backend_registered_sidebars($element['additions'] , $element['exclude']);
}
else
{
$element['subtype'] = $element['additions'];
$element['subtype'][$save_as] = av_backend_registered_sidebars(array() , $element['exclude']);
}
return $this->select($element);
}
/**
*
* The hidden method renders a div for a visually conected group
* @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 visual_group_start( $element )
{
$required = $extraclass = $data= "";
if(isset($element['required']))
{
$required = '';
$extraclass = ' avia_hidden avia_required_container';
}
$data = "";
if(isset($element['name'])) $data .= " data-group-name='".$element['name']."'";
if(isset($element['global_class'])) $data .= " data-av_set_global_tab_active='".$element['global_class']."'";
if(isset($element['inactive'])) { $data .= " data-group-inactive='".htmlspecialchars($element['inactive'], ENT_QUOTES)."'"; $extraclass .= " inactive_visible";}
$output = '
';
$output .= $required;
return $output;
}
/**
*
* The hidden method ends the div of the visual group
* @return string $output the string returned contains the html code generated within the method
*/
function visual_group_end()
{
$output = '
';
return $output;
}
/**
*
* The hidden method renders a single div element with class hr
* @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 hr( $element )
{
$class = "";
if(isset($element['class'])) $class = $element['class'];
$output = '
';
return $output;
}
/**
*
* The import method adds the option to import dummy content
* @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 import( $element )
{
$data = "";
$extra = "";
$activeClass = "";
$button_class= "";
$click_to_import = __("Click to import",'avia_framework');
if(isset($element['files'])) $data = "data-files='".$element['files']."'";
if(!empty($element['image'])) $extra = "av-import-with-image";
if(isset($element['exists']))
{
$plugin = $element['exists'][0];
if(!class_exists($plugin))
{
$extra .= " av-disable-import";
$click_to_import = $element['exists'][1];
$button_class .= "avia_button_inactive";
}
}
$output = "
Import started. Please dont reload the page. You will be notified as soon as the import has finished! (Usually within a few minutes) :)
';
$output .= '';
$output .= "
";
return $output;
}
/**
*
* The parent_setting_import method adds the option to import settings from your parent theme
* @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 parent_setting_import($element)
{
$output = "";
$nonce = wp_create_nonce ('avia_nonce_import_parent_settings');
$output .= '';
$output .= 'Import Parent Theme Settings';
$output .= '';
$output .= '
Import started. Please wait a few seconds and dont reload the page. You will be notified as soon as the import has finished! :)
';
$output .= '';
return $output;
}
/**
*
* The theme_settings_export method adds the option to export the theme settings
* @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 theme_settings_export($element)
{
$url = admin_url("admin.php?page=avia&avia_export=1&avia_generate_config_file=1");
$output = "";
$output .= ''.__('Export Theme Settings File','avia_framework').'';
return $output;
}
/**
*
* The heading method renders a fullwidth extra description or title
* @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 heading( $element )
{
$extraclass = $required = "";
if(isset($element['required']))
{
$required = '';
$extraclass = ' avia_hidden avia_required_container';
}
if(isset($element['class'])) $extraclass .= ' '.$element['class'];
$output = '
';
return $output;
}
/**
*
* The target method renders a div that is able to hold an image or a background color
* @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 target( $element )
{
$output = $this->section_start( $element );
$output .= '
';
$output .= $element['std'];
$output .= '
';
$output .= $this->section_end( $element );
return $output;
}
/**
*
* The section_start method renders the beginning of an option-section wich basically includes some wrapping divs and the elment name
* @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 section_start( $element )
{
$required = $extraclass = $target = "";
if(isset($element['required']))
{
$required = '';
$extraclass = ' avia_hidden avia_required_container';
}
if(isset($element['target']))
{
if(is_array($element['target']))
{
foreach($element['target'] as $value) { $target .= ''; }
}
else
{
$target = '';
}
}
if(isset($element['class'])) $extraclass .= ' '.$element['class'];
$output = '
';
return $output;
}
/**
*
* The section_end method renders the end of an option-section by closing various divs
* @return string $output the string returned contains the html code generated within the method
*/
function section_end()
{
$output = '
'; //
$output .= '';
$output .= '
'; //
$output .= '
'; //
return $output;
}
/**
*
* The description method renders the description of the current option-section
* @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 description($element)
{
$tags = array('div','div');
if($element['type'] == 'checkbox')
{
$tags = array('label for="'.$element['id'].'"','label');
}
$output = "<{$tags[0]} class='avia_description'>";
$output .= $element['desc'];
$output .= "{$tags[1]}>"; //
$output .= '
';
return $output;
}
/**
*
* The page_header method renders the beginning of the option page, with header area, logo and various other informations
* @return string $output the string returned contains the html code generated within the method
*/
function page_header()
{
$the_title = apply_filters( 'avia_filter_backend_page_title', $this->avia_superobject->base_data['Title'] );
$output = ''; //
$output .= '';
return $output;
}
/**
*
* Creates a button to save the form via ajax
* @return string $output the string returned contains the html code generated within the method
*/
function save_button()
{
$output = 'Save all changes';
return $output;
}
/**
*
* Creates a button to reset the form
* @return string $output the string returned contains the html code generated within the method
*/
function reset_button()
{
if(current_theme_supports('avia_disable_reset_options')) return "";
$output = 'Reset all options';
return $output;
}
/**
*
* A important function that sets various necessary parameters within hidden input elements that the ajax script needs to save the current page
* @return string $output the string returned contains the html code generated within the method
*/
function hidden_data()
{
$options = get_option($this->avia_superobject->option_prefix);
$output = '
';
$nonce_reset = wp_create_nonce ('avia_nonce_reset_backend');
$output .= wp_referer_field( false );
$output .= ' ';
$output .= ' ';
$output .= ' ';
$output .= ' ';
//if we are viewing a page and not a meta box
if($this->context == 'options_page')
{
$nonce = wp_create_nonce ('avia_nonce_save_backend');
$output .= ' ';
$output .= ' ';
$output .= ' ';
if(empty($options)) $output .= ' ';
}
//if the code was rendered for a meta box
if($this->context == 'metabox')
{
$nonce = wp_create_nonce ('avia_nonce_save_metabox');
$output .= ' ';
$output .= ' ';
}
$output .= '
';
return $output;
}
######################################################################
# Dynamic Template Creation:
######################################################################
/**
*
* The create_options_page method renders an input field and button that lets you create options pages dynamically by entering the new of the new option page
* @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 create_options_page($element)
{
$output = "";
$output .= '
';
return $output;
}
/**
*
* The dynamical_add_elements method adds a dropdown list of elements and a submit button that allows you add the selcted element to the dom
* @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 dynamical_add_elements($element)
{
$output = "";
$output .= '