23 $this->label = esc_html__(
'File Upload',
'gk-gravityview' );
24 parent::__construct();
29 unset( $field_options[
'search_filter'] );
31 if(
'edit' === $context ) {
32 return $field_options;
35 $add_options[
'link_to_file'] = array(
37 'label' => __(
'Display as a Link:',
'gk-gravityview' ),
38 'desc' => __(
'Display the uploaded files as links, rather than embedded content.',
'gk-gravityview'),
40 'merge_tags' =>
false,
43 $add_options[
'image_width'] = array(
45 'label' => __(
'Custom Width:',
'gk-gravityview' ),
46 'desc' => __(
'Override the default image width (250).',
'gk-gravityview' ),
48 'merge_tags' =>
false,
54 if( empty(
$field->field->multipleFiles ) ) {
56 $add_options[
'alt_text'] = array(
58 'label' => __(
'Alternative text',
'gk-gravityview' ),
59 'desc' => __(
'Define an alternative text description of a file. For supported file types only. By default, the field label is used.',
'gk-gravityview' ),
61 'merge_tags' =>
'force',
62 'group' =>
'advanced',
67 return $add_options + $field_options;
82 $field->_is_entry_detail =
true;
108 $rendered = str_replace(
'?_=',
'&_=', $rendered );
110 $rendered = str_replace( esc_attr( $insecure_file_path ), esc_attr( $secure_file_path ), $rendered );
111 $rendered = str_replace( esc_html( $insecure_file_path ), esc_html( $secure_file_path ), $rendered );
112 $rendered = str_replace( esc_url( $insecure_file_path ), esc_url( $secure_file_path ), $rendered );
113 $rendered = str_replace( trim( $insecure_file_path ), trim( $secure_file_path ), $rendered );
137 if ( $context instanceof \
GV\Template_Context ) {
138 $field = $context->field->field;
140 $entry = $context->entry->as_entry();
143 $base_id = $post ? $post->ID : $context->view->ID;
145 $is_single = $context->request->is_entry();
146 $lightbox = $context->view->settings->get(
'lightbox',
false );
149 $field_compat = array(
150 'form' => (isset($context->source->form) ? $context->source->form :
''),
151 'field_id' => $context->field->ID,
155 'display_value' => $context->display_value,
158 'field_type' => $context->field->type,
159 'field_path' => (isset($context->template->located_template) ? $context->template->located_template :
''),
163 _doing_it_wrong( __METHOD__,
'2.0',
'Please pass a \GV\Template_Context object as the 3rd parameter' );
181 $output_arr = array();
187 if ( ! is_array( $file_paths ) ) {
188 $full_value = RGFormsModel::get_lead_field_value(
$entry,
$field );
189 $file_paths = json_decode( $full_value );
192 if ( ! is_array( $file_paths ) ) {
193 gravityview()->log->error(
'Field does not have a valid image array. JSON decode may have failed.', array(
'data' => array(
'$value' =>
$value,
'$field_value' =>
$field_value ) ) );
199 foreach ( $file_paths as $index => $file_path ) {
205 $file_path = $file_info[
'file_path'];
206 $basename = $file_info[
'basename'];
207 $extension = $file_info[
'extension'];
208 $insecure_file_path = $file_info[
'insecure_file_path'];
209 $secure_file_path = $file_info[
'secure_file_path'];
210 $is_secure = $file_info[
'is_secure'];
212 $disable_lightbox =
false;
220 if ( in_array( $extension, wp_get_audio_extensions() ) ) {
221 if ( shortcode_exists(
'audio' ) ) {
230 $audio_settings = apply_filters(
'gravityview_audio_settings', array(
231 'src' => $insecure_file_path,
232 'class' =>
'wp-audio-shortcode gv-audio gv-field-id-'.
$field_settings[
'id']
240 $rendered = wp_audio_shortcode( $audio_settings );
243 $rendered = self::replace_insecure_wp_shortcode_output( $rendered, $insecure_file_path, $secure_file_path );
248 }
else if ( in_array( $extension, wp_get_video_extensions() ) ) {
250 if ( shortcode_exists(
'video' ) ) {
259 $video_settings = apply_filters(
'gravityview_video_settings', array(
260 'src' => $insecure_file_path,
261 'class' =>
'wp-video-shortcode gv-video gv-field-id-'.
$field_settings[
'id']
269 $rendered = wp_video_shortcode( $video_settings );
272 $rendered = self::replace_insecure_wp_shortcode_output( $rendered, $insecure_file_path, $secure_file_path );
277 }
else if ( in_array( $extension, array(
'pdf',
'txt' ),
true ) ) {
280 if ( $context instanceof \
GV\Template_Context && ! ( $context->template instanceof \
GV\Field_CSV_Template ) ) {
282 $file_path = add_query_arg( array(
'gv-iframe' =>
'true' ), $file_path );
295 'width' => ( $is_single ? null : ( $width ? $width: 250 ) )
322 $lightbox_link_atts = array(
323 'rel' => sprintf(
"%s-%s", $gv_class,
$entry_slug ),
327 $lightbox_link_atts = apply_filters(
'gravityview/fields/fileupload/link_atts', $lightbox_link_atts, $field_compat, $context );
331 $rendered =
$image->html();
342 $disable_lightbox =
true;
354 $disable_wrapped_link = apply_filters(
'gravityview/fields/fileupload/disable_link',
false, $field_compat, $context );
368 $content = apply_filters(
'gravityview/fields/fileupload/link_content', $text, $field_compat, $context );
383 $link_atts = apply_filters(
'gravityview/fields/fileupload/link_atts', array(
'target' =>
'_blank' ), $field_compat, $context, compact(
'file_path',
'insecure_file_path',
'disable_lightbox' ) );
388 $content = empty( $rendered ) ? $text : $rendered;
391 $output_arr[] = array(
392 'file_path' => $file_path,
410 $output_arr = apply_filters(
'gravityview/fields/fileupload/files_array', $output_arr, $field_compat, $context );
431 if ( function_exists(
'set_url_scheme' ) ) {
432 $file_path = set_url_scheme( $file_path );
436 $file_path = esc_attr( str_replace(
' ',
'%20', $file_path ) );
439 $file_path_info = pathinfo( $file_path );
442 $extension = empty( $file_path_info[
'extension'] ) ? null : strtolower( $file_path_info[
'extension'] );
451 $extension = apply_filters(
'gravityview/fields/fileupload/extension', $extension, $file_path );
453 $basename = $file_path_info[
'basename'];
457 $insecure_file_path = $file_path;
458 $secure_file_path =
$field->get_download_url( $file_path );
460 if ( $secure_file_path !== $file_path ) {
461 $file_path = $secure_file_path;
476 $file_path = apply_filters(
'gravityview/fields/fileupload/file_path', $file_path,
$field_settings, $context, $index );
479 'file_path' => $file_path,
480 'insecure_file_path' => $insecure_file_path,
481 'secure_file_path' => $secure_file_path,
482 'basename' => $basename,
483 'extension' => $extension,
484 'is_secure' => $is_secure,
Modify field settings by extending this class.
Generic class for generating image tag.
static getInstance( $passed_post=NULL)
$gravityview_view
array $entry array $form array $field_settings
get_field_input( $form, $field_value, $entry, $field)
Trick the GF fileupload field to render with the proper HTML ID to enable the plupload JS to work pro...
$field_settings['content']
gravityview_get_link( $href='', $anchor_text='', $atts=array())
Generate an HTML anchor tag with a list of supported attributes.
static from_entry( $entry)
Construct a instance from a Gravity Forms entry array.
static get_file_info( $file_path, $field, $field_settings, $context, $index)
Prepares information about the file.
if(gravityview() ->plugin->is_GF_25()) $form
static by_id( $form, $field_id)
Get a by and Field ID.
if(empty( $field_settings['content'])) $content
static get_files_array( $value, $gv_class, $context=null)
Return an array of files prepared for output.
static replace_insecure_wp_shortcode_output( $rendered='', $insecure_file_path='', $secure_file_path='')
Replaces insecure file paths with secure file paths for WordPress media shortcode output...
new GravityView_Field_FileUpload
field_options( $field_options, $template_id, $field_id, $context, $input_type, $form_id)
if(empty( $created_by)) $form_id
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
gravityview()
The main GravityView wrapper function.
gravityview_get_context()
Returns the current GravityView context, or empty string if not GravityView.
if(false !==strpos( $value, '00:00')) $field_id
string $field_id ID of the field being displayed
static get_image_extensions()
Returns an array of file extensions recognized by GravityView as images.