';
}
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'];
$attr = ! empty( $element['readonly'] ) ? 'readonly="readonly"' : '';
$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 imgselect method renders one or more input type:radio elements, based on the definition of the $elements array with images
* @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 imgselect( $element )
{
$output = "";
$counter = 1;
foreach($element['buttons'] as $key => $radiobutton)
{
$checked = "";
$image = "";
$extra_class = "";
if( $element['std'] == $key ) {
$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'