| 1 |
<?php |
| 2 |
/* @param string $meta Meta name. |
| 3 |
* @param array $details Contains the details for the field. |
| 4 |
* @param string $value Contains input value; |
| 5 |
* @param string $context Context where the function is used. Depending on it some actions are preformed.; |
| 6 |
* @return string $element input element html string. */ |
| 7 |
|
| 8 |
/* define id's for input and info div */ |
| 9 |
$upload_input_id = str_replace( '-', '_', Wordpress_Creation_Kit_PB::wck_generate_slug( $meta . $details['title'] ) ); |
| 10 |
$upload_info_div_id = str_replace( '-', '_', Wordpress_Creation_Kit_PB::wck_generate_slug( $meta .'_info_container_'. $details['title'] ) ); |
| 11 |
|
| 12 |
/* hidden input that will hold the attachment id */ |
| 13 |
$element .= '<input id="'. esc_attr( $upload_input_id ) .'" type="hidden" size="36" name="'. esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) ) .'" value="'. $value .'" class="mb-text-input mb-field"/>'; |
| 14 |
|
| 15 |
$thumbnail = ''; |
| 16 |
$file_name = ''; |
| 17 |
$file_type = ''; |
| 18 |
/* container for the image preview (or file ico) and name and file type */ |
| 19 |
if( !empty ( $value ) ){ |
| 20 |
$file_src = wp_get_attachment_url($value); |
| 21 |
$thumbnail = wp_get_attachment_image( $value, array( 80, 60 ), true ); |
| 22 |
$file_name = get_the_title( $value ); |
| 23 |
|
| 24 |
if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $value ), $matches ) ) |
| 25 |
$file_type = esc_html( strtoupper( $matches[1] ) ); |
| 26 |
else |
| 27 |
$file_type = strtoupper( str_replace( 'image/', '', get_post_mime_type( $value ) ) ); |
| 28 |
} |
| 29 |
$element .= '<div id="'. esc_attr( $upload_info_div_id ) .'" class="upload-field-details">'. $thumbnail .'<p><span class="file-name">'. $file_name .'</span><span class="file-type">'. $file_type . '</span>'; |
| 30 |
if( !empty ( $value ) ) |
| 31 |
$element .= '<span class="wck-remove-upload">'.__( 'Remove', 'wck' ).'</span>'; |
| 32 |
$element .= '</p></div>'; |
| 33 |
/* the upload link. we send through get the hidden input id, details div id and meta name */ |
| 34 |
if( !empty( $details['attach_to_post'] ) ){ |
| 35 |
$attach_to_post = 'post_id='. $post_id .'&'; |
| 36 |
}else { |
| 37 |
$attach_to_post = ''; |
| 38 |
} |
| 39 |
if( empty( $var_prefix ) ) |
| 40 |
$var_prefix = ''; |
| 41 |
if( empty( $edit_class ) ) |
| 42 |
$edit_class = ''; |
| 43 |
|
| 44 |
$media_upload_url = 'media-upload.php?'.$attach_to_post.'type=file&mb_type='. $var_prefix . esc_js(strtolower( $upload_input_id ) ).'&mb_info_div='.$var_prefix . esc_js(strtolower( $upload_info_div_id ) ).'&meta_name='.$meta.'&TB_iframe=1'; |
| 45 |
|
| 46 |
$media_upload_url = admin_url( $media_upload_url ); |
| 47 |
|
| 48 |
$element .= '<a id="upload_'. esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'] ) ) .'_button" class="button" onclick="tb_show(\'\', \''.$media_upload_url.'\');">'. __( 'Upload ', 'wck' ) . $details['title'] .' </a>'; |
| 49 |
|
| 50 |
/* add js global var for the hidden input, and info container div */ |
| 51 |
$element .= '<script type="text/javascript">'; |
| 52 |
$element .= 'window.'. $var_prefix . strtolower( $upload_input_id ) .' = jQuery(\''.$edit_class.'#'. $upload_input_id.'\');'; |
| 53 |
$element .= 'window.'. $var_prefix . strtolower( $upload_info_div_id ) .' = jQuery(\''.$edit_class.'#'. $upload_info_div_id.'\');'; |
| 54 |
$element .= '</script>'; |
| 55 |
?> |