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