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