_comment.php
2 years ago
_db.php
2 years ago
_hidden.php
2 years ago
_label.php
2 years ago
_row.php
2 years ago
attachment.php
2 years ago
checkbox.php
2 years ago
cleditor.php
2 years ago
codemirror.php
2 years ago
color.php
2 years ago
currency.php
2 years ago
date.php
2 years ago
datetime.php
2 years ago
email.php
2 years ago
link.php
2 years ago
number.php
2 years ago
oembed.php
2 years ago
password.php
2 years ago
phone.php
2 years ago
radio.php
2 years ago
select.php
2 years ago
slider.php
2 years ago
slug.php
2 years ago
text.php
2 years ago
textarea.php
2 years ago
time.php
2 years ago
tinymce.php
2 years ago
website.php
2 years ago
attachment.php
187 lines
| 1 | <?php |
| 2 | // Don't load directly. |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | die( '-1' ); |
| 5 | } |
| 6 | |
| 7 | global $post_ID; |
| 8 | |
| 9 | pods_form_enqueue_script( 'pods-handlebars' ); |
| 10 | wp_enqueue_script( 'jquery-ui-core' ); |
| 11 | wp_enqueue_script( 'jquery-ui-sortable' ); |
| 12 | wp_enqueue_script( 'thickbox' ); |
| 13 | |
| 14 | wp_enqueue_style( 'thickbox' ); |
| 15 | |
| 16 | $field_file = PodsForm::field_loader( 'file' ); |
| 17 | |
| 18 | $attributes = array(); |
| 19 | $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options ); |
| 20 | |
| 21 | $css_id = $attributes['id']; |
| 22 | |
| 23 | $uri_hash = wp_create_nonce( 'pods_uri_' . $_SERVER['REQUEST_URI'] ); |
| 24 | |
| 25 | $uid = pods_session_id(); |
| 26 | |
| 27 | if ( is_user_logged_in() ) { |
| 28 | $uid = 'user_' . get_current_user_id(); |
| 29 | } |
| 30 | |
| 31 | $field_nonce = wp_create_nonce( 'pods_upload_' . ( ! is_object( $pod ) ? '0' : $pod->pod_id ) . '_' . $uid . '_' . $uri_hash . '_' . $options['id'] ); |
| 32 | |
| 33 | $limit_file_type = pods_var( $form_field_type . '_type', $options, 'images' ); |
| 34 | |
| 35 | $title_editable = pods_var( $form_field_type . '_edit_title', $options, 0 ); |
| 36 | $linked = pods_var( $form_field_type . '_linked', $options, 0 ); |
| 37 | |
| 38 | if ( 'images' === $limit_file_type ) { |
| 39 | $limit_types = 'jpg,jpeg,png,gif'; |
| 40 | } elseif ( 'video' === $limit_file_type ) { |
| 41 | $limit_types = 'mpg,mov,flv,mp4'; |
| 42 | } elseif ( 'audio' === $limit_file_type ) { |
| 43 | $limit_types = 'mp3,m4a,wav,wma'; |
| 44 | } elseif ( 'text' === $limit_file_type ) { |
| 45 | $limit_types = 'txt,rtx,csv,tsv'; |
| 46 | } elseif ( 'any' === $limit_file_type ) { |
| 47 | $limit_types = ''; |
| 48 | } else { |
| 49 | $limit_types = pods_var( $form_field_type . '_allowed_extensions', $options, '' ); |
| 50 | } |
| 51 | |
| 52 | $limit_types = str_replace( ' ', '', $limit_types ); |
| 53 | |
| 54 | $tab = pods_var( $form_field_type . '_attachment_tab', $options, 'type', null, true ); |
| 55 | |
| 56 | if ( 'upload' === $tab ) { |
| 57 | $tab = 'type'; |
| 58 | } elseif ( 'browse' === $tab ) { |
| 59 | $tab = 'library'; |
| 60 | } |
| 61 | |
| 62 | $file_limit = 1; |
| 63 | |
| 64 | if ( 'multi' == pods_var( $form_field_type . '_format_type', $options, 'single' ) ) { |
| 65 | $file_limit = (int) pods_var( $form_field_type . '_limit', $options, 0 ); |
| 66 | } |
| 67 | |
| 68 | $data = array( |
| 69 | 'limit-types' => $limit_types, |
| 70 | 'limit-files' => $file_limit, |
| 71 | ); |
| 72 | |
| 73 | $the_post_id = ''; |
| 74 | |
| 75 | if ( is_admin() && ! empty( $post_ID ) ) { |
| 76 | $the_post_id = '&post_id=' . (int) $post_ID; |
| 77 | } |
| 78 | |
| 79 | if ( empty( $value ) ) { |
| 80 | $value = array(); |
| 81 | } else { |
| 82 | $value = (array) $value; |
| 83 | } |
| 84 | ?> |
| 85 | <div |
| 86 | <?php |
| 87 | PodsForm::attributes( |
| 88 | array( |
| 89 | 'class' => $attributes['class'], |
| 90 | 'id' => $attributes['id'], |
| 91 | ), $name, $form_field_type, $options |
| 92 | ); |
| 93 | ?> |
| 94 | > |
| 95 | <ul class="pods-files pods-files-list"> |
| 96 | <?php |
| 97 | |
| 98 | // no extra space in ul or CSS:empty won't work |
| 99 | foreach ( $value as $val ) { |
| 100 | $attachment = get_post( $val, ARRAY_A ); |
| 101 | |
| 102 | if ( empty( $attachment ) ) { |
| 103 | continue; |
| 104 | } |
| 105 | |
| 106 | $attachment['filename'] = basename( $attachment['guid'] ); |
| 107 | |
| 108 | $thumb = wp_get_attachment_image_src( $attachment['ID'], 'thumbnail', true ); |
| 109 | $attachment['thumbnail'] = $thumb[0]; |
| 110 | |
| 111 | $attachment['link'] = ''; |
| 112 | |
| 113 | if ( $linked ) { |
| 114 | $attachment['link'] = wp_get_attachment_url( $attachment['ID'] ); |
| 115 | } |
| 116 | |
| 117 | $attachment = apply_filters( 'pods_media_attachment', $attachment ); |
| 118 | |
| 119 | echo $field_file->markup( $attributes, $file_limit, $title_editable, $attachment['ID'], $attachment['thumbnail'], $attachment['post_title'] ); |
| 120 | }//end foreach |
| 121 | ?> |
| 122 | </ul> |
| 123 | |
| 124 | <a class="button pods-file-add pods-media-add" href="<?php echo esc_url( admin_url( 'media-upload.php?inlineId=pods_media_attachment' . $the_post_id . '&tab=' . $tab . '&TB_iframe=1&width=640&height=1500&pods_pod=' . $pod->pod . '&pods_pod_id=' . $pod->pod . '&pods_field=' . $options['name'] . '&pods_field_id=' . $options['id'] . '&pods_uri_hash=' . $uri_hash . '&pods_field_nonce=' . $field_nonce ) ); ?>"><?php echo pods_v( $form_field_type . '_add_button', $options, __( 'Add File', 'pods' ) ); ?></a> |
| 125 | </div> |
| 126 | |
| 127 | <script type="text/x-handlebars" id="<?php echo $css_id; ?>-handlebars"> |
| 128 | <?php echo $field_file->markup( $attributes, $file_limit, $title_editable ); ?> |
| 129 | |
| 130 | </script> |
| 131 | |
| 132 | <script type="text/javascript"> |
| 133 | jQuery( function ( $ ) { |
| 134 | // init sortable |
| 135 | $( '#<?php echo esc_js( $css_id ); ?> ul.pods-files' ) |
| 136 | .sortable( { |
| 137 | containment : 'parent', |
| 138 | axis : 'y', |
| 139 | scrollSensitivity : 40, |
| 140 | tolerance : 'pointer', |
| 141 | opacity : 0.6 |
| 142 | } ); |
| 143 | |
| 144 | // hook delete links |
| 145 | $( '#<?php echo esc_js( $css_id ); ?>' ).on( 'click', 'li.pods-file-delete a', function ( e ) { |
| 146 | e.preventDefault(); |
| 147 | |
| 148 | var podsfile = $( this ).parent().parent().parent(); |
| 149 | podsfile.slideUp( function () { |
| 150 | |
| 151 | // check to see if this was the only entry |
| 152 | if ( podsfile.parent().children().length == 1 ) { // 1 because we haven't removed our target yet |
| 153 | podsfile.parent().hide(); |
| 154 | } |
| 155 | |
| 156 | // remove the entry |
| 157 | $( this ).remove(); |
| 158 | |
| 159 | } ); |
| 160 | } ); |
| 161 | |
| 162 | var maxFiles_<?php echo esc_js( pods_js_name( $attributes['id'] ) ); ?> = <?php echo esc_js( $file_limit ); ?>; |
| 163 | |
| 164 | // hook the add link |
| 165 | $( '#<?php echo esc_js( $css_id ); ?>' ).on( 'click', 'a.pods-file-add', function ( e ) { |
| 166 | e.preventDefault(); |
| 167 | var trigger = $( this ); |
| 168 | var href = trigger.attr( 'href' ), width = $( window ).width(), H = $( window ).height(), |
| 169 | W = ( 720 < width ) ? 720 : width; |
| 170 | if ( !href ) { |
| 171 | return; |
| 172 | } |
| 173 | href = href.replace( /&width=[0-9]+/g, '' ); |
| 174 | href = href.replace( /&height=[0-9]+/g, '' ); |
| 175 | trigger.attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 ) ); |
| 176 | |
| 177 | pods_file_context = trigger.parent().find( 'ul.pods-files' ); |
| 178 | pods_file_thickbox_modder = setInterval( function () { |
| 179 | if ( pods_file_context )pods_attachments( '<?php echo esc_js( $css_id ); ?>', maxFiles_<?php echo esc_js( pods_js_name( $attributes['id'] ) ); ?> ); |
| 180 | }, 500 ); |
| 181 | |
| 182 | tb_show( 'Attach a file', e.target.href, false ); |
| 183 | return false; |
| 184 | } ); |
| 185 | } ); |
| 186 | </script> |
| 187 |