@@ -107,14 +107,14 @@ |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | switch($input_type) { |
| 110 | - case 'fileupload': |
|
| 111 | - $value = self::preview_image_value("input_{$field['id']}", $field, $form, $lead); |
|
| 112 | - $value = self::preview_image_display($field, $form, $value); |
|
| 113 | - break; |
|
| 114 | - default: |
|
| 115 | - $value = self::preview_image_value("input_{$field['id']}", $field, $form, $lead); |
|
| 116 | - $value = GFCommon::get_lead_field_display($field, $value, $currency); |
|
| 117 | - break; |
|
| 110 | + case 'fileupload': |
|
| 111 | + $value = self::preview_image_value("input_{$field['id']}", $field, $form, $lead); |
|
| 112 | + $value = self::preview_image_display($field, $form, $value); |
|
| 113 | + break; |
|
| 114 | + default: |
|
| 115 | + $value = self::preview_image_value("input_{$field['id']}", $field, $form, $lead); |
|
| 116 | + $value = GFCommon::get_lead_field_display($field, $value, $currency); |
|
| 117 | + break; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | return $value; |
@@ -34,26 +34,26 @@ discard block |
||
| 34 | 34 | private static $lead; |
| 35 | 35 | |
| 36 | 36 | public static function init() { |
| 37 | - add_filter( 'gform_pre_render', array( __class__, 'replace_merge_tags' ) ); |
|
| 37 | + add_filter('gform_pre_render', array(__class__, 'replace_merge_tags')); |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public static function replace_merge_tags( $form ) { |
|
| 40 | + public static function replace_merge_tags($form) { |
|
| 41 | 41 | |
| 42 | 42 | $current_page = isset(GFFormDisplay::$submission[$form['id']]) ? GFFormDisplay::$submission[$form['id']]['page_number'] : 1; |
| 43 | 43 | $fields = array(); |
| 44 | 44 | |
| 45 | 45 | // get all HTML fields on the current page |
| 46 | - foreach($form['fields'] as &$field) { |
|
| 46 | + foreach ($form['fields'] as &$field) { |
|
| 47 | 47 | |
| 48 | 48 | // skip all fields on the first page |
| 49 | - if(rgar($field, 'pageNumber') <= 1) |
|
| 49 | + if (rgar($field, 'pageNumber') <= 1) |
|
| 50 | 50 | continue; |
| 51 | 51 | |
| 52 | 52 | $default_value = rgar($field, 'defaultValue'); |
| 53 | 53 | preg_match_all('/{.+}/', $default_value, $matches, PREG_SET_ORDER); |
| 54 | - if(!empty($matches)) { |
|
| 54 | + if (!empty($matches)) { |
|
| 55 | 55 | // if default value needs to be replaced but is not on current page, wait until on the current page to replace it |
| 56 | - if(rgar($field, 'pageNumber') != $current_page) { |
|
| 56 | + if (rgar($field, 'pageNumber') != $current_page) { |
|
| 57 | 57 | $field['defaultValue'] = ''; |
| 58 | 58 | } else { |
| 59 | 59 | $field['defaultValue'] = self::preview_replace_variables($default_value, $form); |
@@ -61,12 +61,12 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | // only run 'content' filter for fields on the current page |
| 64 | - if(rgar($field, 'pageNumber') != $current_page) |
|
| 64 | + if (rgar($field, 'pageNumber') != $current_page) |
|
| 65 | 65 | continue; |
| 66 | 66 | |
| 67 | 67 | $html_content = rgar($field, 'content'); |
| 68 | 68 | preg_match_all('/{.+}/', $html_content, $matches, PREG_SET_ORDER); |
| 69 | - if(!empty($matches)) { |
|
| 69 | + if (!empty($matches)) { |
|
| 70 | 70 | $field['content'] = self::preview_replace_variables($html_content, $form); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -81,32 +81,32 @@ discard block |
||
| 81 | 81 | public static function preview_special_merge_tags($value, $input_id, $merge_tag, $field) { |
| 82 | 82 | |
| 83 | 83 | // added to prevent overriding :noadmin filter (and other filters that remove fields) |
| 84 | - if( ! $value ) |
|
| 84 | + if (!$value) |
|
| 85 | 85 | return $value; |
| 86 | 86 | |
| 87 | 87 | $input_type = RGFormsModel::get_input_type($field); |
| 88 | 88 | |
| 89 | - $is_upload_field = in_array( $input_type, array('post_image', 'fileupload') ); |
|
| 90 | - $is_multi_input = is_array( rgar($field, 'inputs') ); |
|
| 91 | - $is_input = intval( $input_id ) != $input_id; |
|
| 89 | + $is_upload_field = in_array($input_type, array('post_image', 'fileupload')); |
|
| 90 | + $is_multi_input = is_array(rgar($field, 'inputs')); |
|
| 91 | + $is_input = intval($input_id) != $input_id; |
|
| 92 | 92 | |
| 93 | - if( !$is_upload_field && !$is_multi_input ) |
|
| 93 | + if (!$is_upload_field && !$is_multi_input) |
|
| 94 | 94 | return $value; |
| 95 | 95 | |
| 96 | 96 | // if is individual input of multi-input field, return just that input value |
| 97 | - if(!$is_input ) |
|
| 97 | + if (!$is_input) |
|
| 98 | 98 | return $value; |
| 99 | 99 | |
| 100 | 100 | $form = RGFormsModel::get_form_meta($field['formId']); |
| 101 | 101 | $lead = self::create_lead($form); |
| 102 | 102 | $currency = GFCommon::get_currency(); |
| 103 | 103 | |
| 104 | - if(is_array(rgar($field, 'inputs'))) { |
|
| 104 | + if (is_array(rgar($field, 'inputs'))) { |
|
| 105 | 105 | $value = RGFormsModel::get_lead_field_value($lead, $field); |
| 106 | 106 | return GFCommon::get_lead_field_display($field, $value, $currency); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - switch($input_type) { |
|
| 109 | + switch ($input_type) { |
|
| 110 | 110 | case 'fileupload': |
| 111 | 111 | $value = self::preview_image_value("input_{$field['id']}", $field, $form, $lead); |
| 112 | 112 | $value = self::preview_image_display($field, $form, $value); |
@@ -126,10 +126,10 @@ discard block |
||
| 126 | 126 | $file_info = RGFormsModel::get_temp_filename($form['id'], $input_name); |
| 127 | 127 | $source = RGFormsModel::get_upload_url($form['id']) . "/tmp/" . $file_info["temp_filename"]; |
| 128 | 128 | |
| 129 | - if(!$file_info) |
|
| 129 | + if (!$file_info) |
|
| 130 | 130 | return ''; |
| 131 | 131 | |
| 132 | - switch(RGFormsModel::get_input_type($field)){ |
|
| 132 | + switch (RGFormsModel::get_input_type($field)) { |
|
| 133 | 133 | |
| 134 | 134 | case "post_image": |
| 135 | 135 | list(,$image_title, $image_caption, $image_description) = explode("|:|", $lead[$field['id']]); |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | $file_info = RGFormsModel::get_temp_filename($form['id'], $input_name); |
| 153 | 153 | |
| 154 | 154 | $file_path = $value; |
| 155 | - if(!empty($file_path)){ |
|
| 155 | + if (!empty($file_path)) { |
|
| 156 | 156 | $file_path = esc_attr(str_replace(" ", "%20", $file_path)); |
| 157 | 157 | $value = "<a href='$file_path' target='_blank' title='" . __("Click to view", "gravityforms") . "'>" . $file_info['uploaded_filename'] . "</a>"; |
| 158 | 158 | } |
@@ -163,17 +163,17 @@ discard block |
||
| 163 | 163 | /** |
| 164 | 164 | * Retrieves $lead object from class if it has already been created; otherwise creates a new $lead object. |
| 165 | 165 | */ |
| 166 | - public static function create_lead( $form ) { |
|
| 166 | + public static function create_lead($form) { |
|
| 167 | 167 | |
| 168 | - if( empty( self::$lead ) ) { |
|
| 169 | - self::$lead = GFFormsModel::create_lead( $form ); |
|
| 170 | - self::clear_field_value_cache( $form ); |
|
| 168 | + if (empty(self::$lead)) { |
|
| 169 | + self::$lead = GFFormsModel::create_lead($form); |
|
| 170 | + self::clear_field_value_cache($form); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | return self::$lead; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - public static function preview_replace_variables( $content, $form ) { |
|
| 176 | + public static function preview_replace_variables($content, $form) { |
|
| 177 | 177 | |
| 178 | 178 | $lead = self::create_lead($form); |
| 179 | 179 | |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | return $content; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - public static function clear_field_value_cache( $form ) { |
|
| 193 | + public static function clear_field_value_cache($form) { |
|
| 194 | 194 | |
| 195 | - if( ! class_exists( 'GFCache' ) ) |
|
| 195 | + if (!class_exists('GFCache')) |
|
| 196 | 196 | return; |
| 197 | 197 | |
| 198 | - foreach( $form['fields'] as &$field ) { |
|
| 199 | - if( GFFormsModel::get_input_type( $field ) == 'total' ) |
|
| 200 | - GFCache::delete( 'GFFormsModel::get_lead_field_value__' . $field['id'] ); |
|
| 198 | + foreach ($form['fields'] as &$field) { |
|
| 199 | + if (GFFormsModel::get_input_type($field) == 'total') |
|
| 200 | + GFCache::delete('GFFormsModel::get_lead_field_value__' . $field['id']); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | } |