| 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 |
/* since the slug below is generated dinamically from other elements we need to determine here if we have a slug or not and not let the wck_generate_slug() function do that */ |
| 9 |
if( !empty( $details['slug'] ) ) |
| 10 |
$slug_from = $details['slug']; |
| 11 |
else |
| 12 |
$slug_from = $details['title']; |
| 13 |
|
| 14 |
/* define id's for input and info div */ |
| 15 |
$upload_input_id = str_replace( '-', '_', Wordpress_Creation_Kit_PB::wck_generate_slug( $meta . $slug_from ) ); |
| 16 |
$upload_info_div_id = str_replace( '-', '_', Wordpress_Creation_Kit_PB::wck_generate_slug( $meta .'_info_container_'. $slug_from ) ); |
| 17 |
|
| 18 |
/* hidden input that will hold the attachment id */ |
| 19 |
$element.= '<input id="'. esc_attr( $upload_input_id ) .'" type="hidden" size="36" name="'. $single_prefix . esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) ) .'" value="'. $value .'" class="mb-text-input mb-field"/>'; |
| 20 |
|
| 21 |
/* container for the image preview (or file ico) and name and file type */ |
| 22 |
if( !empty ( $value ) ){ |
| 23 |
/* it can hold multiple attachments separated by comma */ |
| 24 |
$values = explode( ',', $value ); |
| 25 |
foreach( $values as $value ){ |
| 26 |
$file_src = wp_get_attachment_url($value); |
| 27 |
$thumbnail = wp_get_attachment_image( $value, array( 80, 80 ), true ); |
| 28 |
$file_name = get_the_title( $value ); |
| 29 |
$file_type = get_post_mime_type( $value ); |
| 30 |
$attachment_url = admin_url( "post.php?post={$value}&action=edit" ); |
| 31 |
|
| 32 |
$element.= '<div id="'.esc_attr( $upload_info_div_id ).'_info_container" class="upload-field-details" data-attachment_id="'. $value .'">'; |
| 33 |
$element.= '<div class="file-thumb">'; |
| 34 |
$element.= "<a href='{$attachment_url}' target='_blank' class='wck-attachment-link'>" . $thumbnail . "</a>"; |
| 35 |
$element.= '</div>'; |
| 36 |
|
| 37 |
$element.= '<p><span class="file-name">'; |
| 38 |
$element.= $file_name; |
| 39 |
$element.= '</span><span class="file-type">'; |
| 40 |
$element.= $file_type; |
| 41 |
$element.= '</span>'; |
| 42 |
if( !empty ( $value ) ) |
| 43 |
$element.= '<span class="wck-remove-upload">'.__( 'Remove', 'profile-builder' ).'</span>'; |
| 44 |
$element.= '</p></div>'; |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
$element.= '<a href="#" class="button wck_upload_button" id="upload_'. esc_attr(Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) ) .'_button" data-uploader_title="'. $details['title'] .'" data-uploader_button_text="Select Files" data-upload_input="'.esc_attr( $upload_input_id ).'" '; |
| 49 |
if( is_user_logged_in() ) |
| 50 |
$element.= 'data-uploader_logged_in="true"'; |
| 51 |
|
| 52 |
if( !empty( $post_id ) ) |
| 53 |
$element.= ' data-post_id="'. $post_id .'"'; |
| 54 |
|
| 55 |
if( !empty( $details['multiple_upload'] ) ){ |
| 56 |
if( $details['multiple_upload'] == 'true' ) |
| 57 |
$element.= ' data-multiple_upload="true"'; |
| 58 |
else |
| 59 |
$element.= ' data-multiple_upload="false"'; |
| 60 |
} |
| 61 |
|
| 62 |
if( !empty( $details['attach_to_post'] ) ){ |
| 63 |
if( $details['attach_to_post'] == true ) |
| 64 |
$element.= ' data-attach_to_post="true"'; |
| 65 |
} |
| 66 |
|
| 67 |
if( $context != 'fep' ) |
| 68 |
$element.= ' data-upload_in_backend="true"'; |
| 69 |
else |
| 70 |
$element.= ' data-upload_in_backend="false"'; |
| 71 |
|
| 72 |
if( !empty( $details['allowed_types'] ) ) |
| 73 |
$element.= ' data-allowed_types="'. $details['allowed_types'] .'"'; |
| 74 |
|
| 75 |
$element.= '>'. __( 'Upload ', 'profile-builder' ) . $details['title'] .'</a>'; |
| 76 |
?> |