is_entry_detail();
$is_form_editor = $this->is_form_editor();
$is_admin = $is_entry_detail || $is_form_editor;
$id = (int) $this->id;
$field_id = $is_entry_detail || $is_form_editor || $form_id == 0 ? "input_$id" : 'input_' . $form_id . "_$id";
$size = $this->size;
$class_suffix = $is_entry_detail ? '_admin' : '';
$class = $size . $class_suffix;
$class = esc_attr( $class );
$disabled_text = $is_form_editor ? 'disabled="disabled"' : '';
$alt = esc_attr( rgget( $this->id . '.2', $value ) );
$title = esc_attr( rgget( $this->id . '.1', $value ) );
$caption = esc_attr( rgget( $this->id . '.4', $value ) );
$description = esc_attr( rgget( $this->id . '.7', $value ) );
//hiding meta fields for admin
$hidden_style = "style='display:none;'";
$alt_style = ! $this->displayAlt && $is_admin ? $hidden_style : '';
$title_style = ! $this->displayTitle && $is_admin ? $hidden_style : '';
$caption_style = ! $this->displayCaption && $is_admin ? $hidden_style : '';
$description_style = ! $this->displayDescription && $is_admin ? $hidden_style : '';
$file_label_style = $is_admin && ! ( $this->displayAlt || $this->displayTitle || $this->displayCaption || $this->displayDescription ) ? $hidden_style : '';
$form_sub_label_placement = rgar( $form, 'subLabelPlacement' );
$field_sub_label_placement = $this->subLabelPlacement;
$is_sub_label_above = $field_sub_label_placement == 'above' || ( empty( $field_sub_label_placement ) && $form_sub_label_placement == 'above' );
// Prepare accepted extensions message.
$allowed_extensions = join( ',', GFCommon::clean_extensions( explode( ',', strtolower( $this->allowedExtensions ) ) ) );
$extensions_message_id = 'extensions_message_' . $form_id . '_' . $id;
$extensions_message = sprintf(
"%s",
$extensions_message_id,
esc_attr( sprintf( __( 'Accepted file types: %s.', 'gravityforms' ), str_replace( ',', ', ', $allowed_extensions ) ) )
);
// Aria attributes.
$required_attribute = $this->isRequired ? 'aria-required="true"' : '';
$invalid_attribute = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"';
$aria_describedby = $this->get_aria_describedby( array( $extensions_message_id ) );
$hidden_class = $preview = '';
$file_info = RGFormsModel::get_temp_filename( $form_id, "input_{$id}" );
if ( $file_info ) {
$hidden_class = ' gform_hidden';
$file_label_style = $hidden_style;
$preview = "" . esc_html( $file_info['uploaded_filename'] ) . " | " . __( 'delete', 'gravityforms' ) . '';
}
//in admin, render all meta fields to allow for immediate feedback, but hide the ones not selected
$file_label = ( $is_admin || $this->displayAlt || $this->displayTitle || $this->displayCaption || $this->displayDescription ) ? "' : '';
$tabindex = $this->get_tabindex();
if( $is_sub_label_above ){
$upload = sprintf( "$file_label{$preview}{$extensions_message}", $id, $field_id, esc_attr( $class . $hidden_class ), $disabled_text );
} else {
$upload = sprintf( "{$preview}{$extensions_message}$file_label", $id, $field_id, esc_attr( $class . $hidden_class ), $disabled_text );
}
$tabindex = $this->get_tabindex();
if( $is_sub_label_above ){
$alt_field = $this->displayAlt || $is_admin ? sprintf( "", $field_id, $id, $field_id, $alt, $disabled_text ) : '';
} else {
$alt_field = $this->displayAlt || $is_admin ? sprintf( "', $id, $field_id, $alt, $disabled_text, $field_id ) : '';
}
$tabindex = $this->get_tabindex();
if( $is_sub_label_above ){
$title_field = $this->displayTitle || $is_admin ? sprintf( "", $field_id, $id, $field_id, $title, $disabled_text ) : '';
} else {
$title_field = $this->displayTitle || $is_admin ? sprintf( "', $id, $field_id, $title, $disabled_text, $field_id ) : '';
}
$tabindex = $this->get_tabindex();
if( $is_sub_label_above ){
$caption_field = $this->displayCaption || $is_admin ? sprintf( "", $field_id, $id, $field_id, $caption, $disabled_text ) : '';
} else {
$caption_field = $this->displayCaption || $is_admin ? sprintf( "', $id, $field_id, $caption, $disabled_text, $field_id ) : '';
}
$tabindex = $this->get_tabindex();
if( $is_sub_label_above ){
$description_field = $this->displayDescription || $is_admin ? sprintf( "", $field_id, $id, $field_id, $description, $disabled_text ) : '';
} else {
$description_field = $this->displayDescription || $is_admin ? sprintf( "', $id, $field_id, $description, $disabled_text, $field_id ) : '';
}
return "
" . $upload . $alt_field . $title_field . $caption_field . $description_field . '
';
}
public function get_value_save_entry( $value, $form, $input_name, $lead_id, $lead ) {
$form_id = $form['id'];
$url = $this->get_single_file_value( $form_id, $input_name );
if ( empty( $url ) ) {
return '';
}
if ( ! GFCommon::is_valid_url( $url ) ) {
GFCommon::log_debug( __METHOD__ . '(): aborting; File URL invalid.' );
return '';
}
$image_alt = isset( $_POST["{$input_name}_2"] ) ? wp_strip_all_tags( $_POST["{$input_name}_2"] ) : '';
$image_title = isset( $_POST["{$input_name}_1"] ) ? wp_strip_all_tags( $_POST["{$input_name}_1"] ) : '';
$image_caption = isset( $_POST["{$input_name}_4"] ) ? wp_strip_all_tags( $_POST["{$input_name}_4"] ) : '';
$image_description = isset( $_POST["{$input_name}_7"] ) ? wp_strip_all_tags( $_POST["{$input_name}_7"] ) : '';
return $url . '|:|' . $image_title . '|:|' . $image_caption . '|:|' . $image_description . '|:|' . $image_alt;
}
public function get_value_entry_list( $value, $entry, $field_id, $columns, $form ) {
list( $url, $title, $caption, $description, $alt ) = rgexplode( '|:|', $value, 5 );
if ( ! empty( $url ) ) {
// displaying thumbnail (if file is an image) or an icon based on the extension.
$thumb = GFEntryList::get_icon_url( $url );
$value = "
";
}
return $value;
}
public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
$ary = explode( '|:|', $value );
$url = count( $ary ) > 0 ? $ary[0] : '';
$title = count( $ary ) > 1 ? $ary[1] : '';
$caption = count( $ary ) > 2 ? $ary[2] : '';
$description = count( $ary ) > 3 ? $ary[3] : '';
$alt = count( $ary ) > 4 ? $ary[4] : '';
if ( ! empty( $url ) ) {
$url = str_replace( ' ', '%20', $url );
switch ( $format ) {
case 'text' :
$value = $url;
$value .= ! empty( $alt ) ? "\n\n" . $this->label . ' (' . __( 'Alternative Text', 'gravityforms' ) . '): ' . $description : '';
$value .= ! empty( $title ) ? "\n\n" . $this->label . ' (' . __( 'Title', 'gravityforms' ) . '): ' . $title : '';
$value .= ! empty( $caption ) ? "\n\n" . $this->label . ' (' . __( 'Caption', 'gravityforms' ) . '): ' . $caption : '';
$value .= ! empty( $description ) ? "\n\n" . $this->label . ' (' . __( 'Description', 'gravityforms' ) . '): ' . $description : '';
break;
default :
$value = "
";
$value .= ! empty( $alt ) ? '' . esc_html__( 'Alternative Text', 'gravityforms' ) . ": $alt
" : '';
$value .= ! empty( $title ) ? '' . esc_html__( 'Title', 'gravityforms' ) . ": $title
" : '';
$value .= ! empty( $caption ) ? '' . esc_html__( 'Caption', 'gravityforms' ) . ": $caption
" : '';
$value .= ! empty( $description ) ? '' . esc_html__( 'Description', 'gravityforms' ) . ": $description
" : '';
break;
}
}
return $value;
}
public function get_value_submission( $field_values, $get_from_post_global_var = true ) {
$value[ $this->id . '.2' ] = $this->get_input_value_submission( 'input_' . $this->id . '_2', $get_from_post_global_var );
$value[ $this->id . '.1' ] = $this->get_input_value_submission( 'input_' . $this->id . '_1', $get_from_post_global_var );
$value[ $this->id . '.4' ] = $this->get_input_value_submission( 'input_' . $this->id . '_4', $get_from_post_global_var );
$value[ $this->id . '.7' ] = $this->get_input_value_submission( 'input_' . $this->id . '_7', $get_from_post_global_var );
return $value;
}
/**
* Gets merge tag values.
*
* @since Unknown
* @since 2.5 Add alt text.
* @access public
*
* @param array|string $value The value of the input.
* @param string $input_id The input ID to use.
* @param array $entry The Entry Object.
* @param array $form The Form Object
* @param string $modifier The modifier passed.
* @param array|string $raw_value The raw value of the input.
* @param bool $url_encode If the result should be URL encoded.
* @param bool $esc_html If the HTML should be escaped.
* @param string $format The format that the value should be.
* @param bool $nl2br If the nl2br function should be used.
*
* @return string The processed merge tag.
*/
public function get_value_merge_tag( $value, $input_id, $entry, $form, $modifier, $raw_value, $url_encode, $esc_html, $format, $nl2br ) {
list( $url, $title, $caption, $description, $alt ) = array_pad( explode( '|:|', $value ), 5, false );
switch ( $modifier ) {
case 'alt' :
return $alt;
case 'title' :
return $title;
case 'caption' :
return $caption;
case 'description' :
return $description;
default :
return str_replace( ' ', '%20', $url );
}
}
}
GF_Fields::register( new GF_Field_Post_Image() );