PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
← All changes | templates/form-fields/picture.php +113 -62 1.7.0 → 1.8.13 View file →
@@ -1,5 +1,11 @@
1 1 <?php
2 +
3 +// Exit if accessed directly.
4 +if ( ! defined( 'ABSPATH' ) ) {
5 + exit;
6 +}
7 +
2 8 /**
3 9 * The template used to display file form fields.
4 10 *
5 11 * @author WP Charitable LLC
@@ -5,8 +11,10 @@
5 11 * @author WP Charitable LLC
6 12 * @package Charitable/Templates/Form Fields
7 13 * @since 1.0.0
8 14 * @version 1.6.13
15 + * @version 1.8.8.6
16 + * @version 1.8.12.4
9 17 */
10 18
11 19 if ( ! isset( $view_args['form'] ) || ! isset( $view_args['field'] ) ) {
12 20 return;
@@ -15,39 +23,51 @@
15 23 if ( array_key_exists( 'uploader', $view_args['field'] ) && ! $view_args['field']['uploader'] ) {
16 24 return charitable_template( 'form-fields/file.php', $view_args );
17 25 }
18 26
19 -$form = $view_args['form'];
20 -$field = $view_args['field'];
21 -$classes = $view_args['classes'];
22 -$is_required = isset( $field['required'] ) ? $field['required'] : false;
23 -$placeholder = isset( $field['placeholder'] ) ? esc_attr( $field['placeholder'] ) : '';
24 -$size = isset( $field['size'] ) ? $field['size'] : 'thumbnail';
25 -$max_uploads = isset( $field['max_uploads'] ) ? $field['max_uploads'] : 1;
26 -$max_file_size = isset( $field['max_file_size'] ) ? $field['max_file_size'] : wp_max_upload_size();
27 -$pictures = isset( $field['value'] ) ? $field['value'] : array();
27 +$charitable_form = $view_args['form'];
28 +$charitable_field = $view_args['field'];
29 +$charitable_classes = $view_args['classes'];
30 +$charitable_is_required = isset( $charitable_field['required'] ) ? $charitable_field['required'] : false;
31 +$charitable_placeholder = isset( $charitable_field['placeholder'] ) ? esc_attr( $charitable_field['placeholder'] ) : '';
32 +$charitable_size = isset( $charitable_field['size'] ) ? $charitable_field['size'] : 'thumbnail';
33 +$charitable_max_uploads = isset( $charitable_field['max_uploads'] ) ? $charitable_field['max_uploads'] : 1;
34 +$charitable_max_file_size = isset( $charitable_field['max_file_size'] ) ? $charitable_field['max_file_size'] : wp_max_upload_size();
35 +$charitable_pictures = isset( $charitable_field['value'] ) ? $charitable_field['value'] : array();
28 36
29 37 if ( wp_is_mobile() ) {
30 - $classes .= ' mobile';
38 + $charitable_classes .= ' mobile';
31 39 }
32 40
33 -if ( ! is_array( $pictures ) ) {
34 - $pictures = array( $pictures );
41 +if ( ! is_array( $charitable_pictures ) ) {
42 + $charitable_pictures = array( $charitable_pictures );
35 43 }
36 44
37 -foreach ( $pictures as $i => $picture ) {
38 - if ( false === strpos( $picture, 'img' ) && ! wp_attachment_is_image( $picture ) ) {
39 - unset( $pictures[ $i ] );
45 +foreach ( $charitable_pictures as $charitable_i => $charitable_picture ) {
46 + if ( false === strpos( $charitable_picture, 'img' ) && ! wp_attachment_is_image( $charitable_picture ) ) {
47 + unset( $charitable_pictures[ $charitable_i ] );
40 48 }
41 49 }
42 50
43 -$has_max_uploads = count( $pictures ) >= $max_uploads;
44 -$params = array(
51 +/*
52 + * Ask the same question the AJAX endpoint asks. Without this the field draws a fully
53 + * working drag-and-drop zone for a logged-out visitor whose uploads charitable_plupload_
54 + * image_upload() will always refuse - the visitor picks a file and gets an error with no
55 + * way to succeed. Say so up front instead. Mirrors the disabled state Ambassadors renders
56 + * for its own gallery field.
57 + */
58 +$charitable_uploads_enabled = charitable_picture_uploads_enabled(
59 + $charitable_field['key'],
60 + isset( $charitable_field['parent_id'] ) ? absint( $charitable_field['parent_id'] ) : 0
61 +);
62 +
63 +$charitable_has_max_uploads = count( $charitable_pictures ) >= $charitable_max_uploads;
64 +$charitable_params = array(
45 65 'runtimes' => 'html5,silverlight,flash,html4',
46 66 'file_data_name' => 'async-upload',
47 - 'container' => $field['key'] . '-dragdrop',
48 - 'browse_button' => $field['key'] . '-browse-button',
49 - 'drop_element' => $field['key'] . '-dragdrop-dropzone',
67 + 'container' => $charitable_field['key'] . '-dragdrop',
68 + 'browse_button' => $charitable_field['key'] . '-browse-button',
69 + 'drop_element' => $charitable_field['key'] . '-dragdrop-dropzone',
50 70 'multiple_queues' => true,
51 71 'url' => admin_url( 'admin-ajax.php' ),
52 72 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
53 73 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
@@ -55,64 +75,95 @@
55 75 'urlstream_upload' => true,
56 76 'filters' => array(
57 77 array(
58 78 'title' => _x( 'Allowed Image Files', 'image upload', 'charitable' ),
59 - 'extensions' => 'jpg,jpeg,gif,png',
79 + 'extensions' => 'jpg,jpeg,gif,png,webp',
60 80 ),
61 81 ),
62 82 'multipart_params' => array(
63 - 'field_id' => $field['key'],
83 + 'field_id' => $charitable_field['key'],
64 84 'action' => 'charitable_plupload_image_upload',
65 - '_ajax_nonce' => wp_create_nonce( "charitable-upload-images-{$field[ 'key' ]}" ),
66 - 'post_id' => isset( $field['parent_id'] ) && strlen( $field['parent_id'] ) ? $field['parent_id'] : '0',
67 - 'size' => $size,
68 - 'max_uploads' => $max_uploads,
85 + '_ajax_nonce' => wp_create_nonce( "charitable-upload-images-{$charitable_field[ 'key' ]}" ),
86 + 'post_id' => isset( $charitable_field['parent_id'] ) && strlen( $charitable_field['parent_id'] ) ? $charitable_field['parent_id'] : '0',
87 + 'size' => $charitable_size,
88 + 'max_uploads' => $charitable_max_uploads,
69 89 ),
70 90 );
71 91
72 -wp_enqueue_script( 'charitable-plup-fields' );
92 +if ( $charitable_uploads_enabled ) {
93 + wp_enqueue_script( 'charitable-plup-fields' );
94 +}
95 +
73 96 wp_enqueue_style( 'charitable-plup-styles' );
74 97
75 98 ?>
76 -<div id="charitable_field_<?php echo $field['key']; ?>" class="<?php echo $classes; ?>">
77 - <?php if ( isset( $field['label'] ) ) : ?>
99 +<div id="charitable_field_<?php echo esc_attr( $charitable_field['key'] ); ?>" class="<?php echo esc_attr( $charitable_classes ); ?>">
100 + <?php if ( isset( $charitable_field['label'] ) ) : ?>
78 101 <label>
79 - <?php echo $field['label']; ?>
80 - <?php if ( $is_required ) : ?>
81 - <abbr class="required" title="required">*</abbr>
102 + <?php echo wp_kses_post( $charitable_field['label'] ); ?>
103 + <?php if ( $charitable_is_required ) : ?>
104 + <abbr class="required" title="<?php esc_html_e( 'Required', 'charitable' ); ?>">*</abbr>
82 105 <?php endif ?>
83 106 </label>
84 107 <?php endif ?>
85 - <?php if ( isset( $field['help'] ) ) : ?>
86 - <p class="charitable-field-help"><?php echo $field['help']; ?></p>
108 + <?php if ( isset( $charitable_field['help'] ) ) : ?>
109 + <p class="charitable-field-help"><?php echo $charitable_field['help']; // phpcs:ignore ?></p>
87 110 <?php endif ?>
88 - <div id="<?php echo $field['key']; ?>-dragdrop"
89 - class="charitable-drag-drop"
90 - data-max-size="<?php echo $max_file_size; ?>"
91 - data-images="<?php echo $field['key']; ?>-dragdrop-images"
92 - data-params="<?php echo esc_attr( wp_json_encode( $params ) ); ?>">
93 - <div id="<?php echo $field['key']; ?>-dragdrop-dropzone" class="charitable-drag-drop-dropzone" <?php echo $has_max_uploads ? 'style="display:none;"' : ''; ?>>
94 - <p class="charitable-drag-drop-info"><?php echo 1 == $max_uploads ? _x( 'Drop image here', 'image upload', 'charitable' ) : _x( 'Drop images here', 'image upload plural', 'charitable' ); ?></p>
95 - <p><?php _ex( 'or', 'image upload', 'charitable' ); ?></p>
96 - <p class="charitable-drag-drop-buttons">
97 - <button id="<?php echo $field['key']; ?>-browse-button" class="button" type="button"><?php _ex( 'Select Files', 'image upload', 'charitable' ); ?></button>
98 - </p>
111 + <?php if ( ! $charitable_uploads_enabled ) : ?>
112 + <?php
113 + /*
114 + * No .charitable-drag-drop class here on purpose: that class is what
115 + * charitable-plupload-fields.js constructs an Uploader from. Not printing the params
116 + * also keeps the user-0 nonce off public pages, so there is no token to scrape.
117 + */
118 + ?>
119 + <div class="charitable-drag-drop-disabled">
120 + <p class="charitable-drag-drop-info"><?php esc_html_e( 'Image uploads are available to logged-in users. Please log in or create an account to add an image.', 'charitable' ); ?></p>
121 + <?php if ( ! empty( $charitable_pictures ) ) : ?>
122 + <ul class="charitable-drag-drop-images charitable-drag-drop-images-<?php echo esc_attr( $charitable_max_uploads ); ?>">
123 + <?php
124 + foreach ( $charitable_pictures as $charitable_image ) :
125 + charitable_template(
126 + 'form-fields/picture-preview.php',
127 + array(
128 + 'image' => $charitable_image,
129 + 'field' => $charitable_field,
130 + )
131 + );
132 + endforeach;
133 + ?>
134 + </ul>
135 + <?php endif ?>
99 136 </div>
100 - <div class="charitable-drag-drop-image-loader" style="display: none;">
101 - <p class="loader-title"><?php _e( 'Uploading...', 'charitable' ); ?></p>
102 - <ul class="images"></ul>
137 + <?php else : ?>
138 + <div id="<?php echo esc_attr( $charitable_field['key'] ); ?>-dragdrop"
139 + class="charitable-drag-drop"
140 + data-max-size="<?php echo esc_attr( $charitable_max_file_size ); ?>"
141 + data-images="<?php echo esc_attr( $charitable_field['key'] ); ?>-dragdrop-images"
142 + data-params="<?php echo esc_attr( wp_json_encode( $charitable_params ) ); ?>">
143 + <div id="<?php echo esc_attr( $charitable_field['key'] ); ?>-dragdrop-dropzone" class="charitable-drag-drop-dropzone" <?php echo $charitable_has_max_uploads ? 'style="display:none;"' : ''; ?>>
144 + <p class="charitable-drag-drop-info"><?php echo esc_html( 1 === $charitable_max_uploads ? _x( 'Drop image here', 'image upload', 'charitable' ) : _x( 'Drop images here', 'image upload plural', 'charitable' ) ); ?></p>
145 + <p><?php echo esc_html_x( 'or', 'image upload', 'charitable' ); ?></p>
146 + <p class="charitable-drag-drop-buttons">
147 + <button id="<?php echo esc_attr( $charitable_field['key'] ); ?>-browse-button" class="button" type="button"><?php echo esc_html_x( 'Select Files', 'image upload', 'charitable' ); ?></button>
148 + </p>
149 + </div>
150 + <div class="charitable-drag-drop-image-loader" style="display: none;">
151 + <p class="loader-title"><?php esc_html_e( 'Uploading...', 'charitable' ); ?></p>
152 + <ul class="images"></ul>
153 + </div>
154 + <ul id="<?php echo esc_attr( $charitable_field['key'] ); ?>-dragdrop-images" class="charitable-drag-drop-images charitable-drag-drop-images-<?php echo esc_attr( $charitable_max_uploads ); ?>">
155 + <?php
156 + foreach ( $charitable_pictures as $charitable_image ) :
157 + charitable_template(
158 + 'form-fields/picture-preview.php',
159 + array(
160 + 'image' => $charitable_image,
161 + 'field' => $charitable_field,
162 + )
163 + );
164 + endforeach;
165 + ?>
166 + </ul>
103 167 </div>
104 - <ul id="<?php echo $field['key']; ?>-dragdrop-images" class="charitable-drag-drop-images charitable-drag-drop-images-<?php echo $max_uploads; ?>">
105 - <?php
106 - foreach ( $pictures as $image ) :
107 - charitable_template(
108 - 'form-fields/picture-preview.php',
109 - array(
110 - 'image' => $image,
111 - 'field' => $field,
112 - )
113 - );
114 - endforeach;
115 - ?>
116 - </ul>
117 - </div>
168 + <?php endif ?>
118 169 </div>