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.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 1.7.0.9 All 211 releases
charitable / templates / form-fields / picture.php

picture.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.13, at templates/form-fields/picture.php

170 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly.
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * The template used to display file form fields.
10 *
11 * @author WP Charitable LLC
12 * @package Charitable/Templates/Form Fields
13 * @since 1.0.0
14 * @version 1.6.13
15 * @version 1.8.8.6
16 * @version 1.8.12.4
17 */
18
19 if ( ! isset( $view_args['form'] ) || ! isset( $view_args['field'] ) ) {
20 return;
21 }
22
23 if ( array_key_exists( 'uploader', $view_args['field'] ) && ! $view_args['field']['uploader'] ) {
24 return charitable_template( 'form-fields/file.php', $view_args );
25 }
26
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();
36
37 if ( wp_is_mobile() ) {
38 $charitable_classes .= ' mobile';
39 }
40
41 if ( ! is_array( $charitable_pictures ) ) {
42 $charitable_pictures = array( $charitable_pictures );
43 }
44
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 ] );
48 }
49 }
50
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(
65 'runtimes' => 'html5,silverlight,flash,html4',
66 'file_data_name' => 'async-upload',
67 'container' => $charitable_field['key'] . '-dragdrop',
68 'browse_button' => $charitable_field['key'] . '-browse-button',
69 'drop_element' => $charitable_field['key'] . '-dragdrop-dropzone',
70 'multiple_queues' => true,
71 'url' => admin_url( 'admin-ajax.php' ),
72 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
73 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
74 'multipart' => true,
75 'urlstream_upload' => true,
76 'filters' => array(
77 array(
78 'title' => _x( 'Allowed Image Files', 'image upload', 'charitable' ),
79 'extensions' => 'jpg,jpeg,gif,png,webp',
80 ),
81 ),
82 'multipart_params' => array(
83 'field_id' => $charitable_field['key'],
84 'action' => 'charitable_plupload_image_upload',
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,
89 ),
90 );
91
92 if ( $charitable_uploads_enabled ) {
93 wp_enqueue_script( 'charitable-plup-fields' );
94 }
95
96 wp_enqueue_style( 'charitable-plup-styles' );
97
98 ?>
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'] ) ) : ?>
101 <label>
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>
105 <?php endif ?>
106 </label>
107 <?php endif ?>
108 <?php if ( isset( $charitable_field['help'] ) ) : ?>
109 <p class="charitable-field-help"><?php echo $charitable_field['help']; // phpcs:ignore ?></p>
110 <?php endif ?>
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 ?>
136 </div>
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>
167 </div>
168 <?php endif ?>
169 </div>
170