Completed
Push — develop ( dba357...c5be34 )
by Gennady
18:03
created

GravityView_Field_FileUpload::get_files_array()   F

Complexity

Conditions 32
Paths 11544

Size

Total Lines 271

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 81
CRAP Score 46.6932

Importance

Changes 0
Metric Value
cc 32
nc 11544
nop 3
dl 0
loc 271
ccs 81
cts 107
cp 0.757
crap 46.6932
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 8 and the first side effect is on line 353.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @file class-gravityview-field-fileupload.php
4
 * @package GravityView
5
 * @subpackage includes\fields
6
 */
7
8
class GravityView_Field_FileUpload extends GravityView_Field {
9
10
	var $name = 'fileupload';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
11
12
	var $_gf_field_class_name = 'GF_Field_FileUpload';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $_gf_field_class_name.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
13
14
	var $is_searchable = true;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $is_searchable.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
15
16
	var $search_operators = array( 'contains' );
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $search_operators.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
17
18
	var $group = 'advanced';
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $group.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
19
20
	public function __construct() {
21
		$this->label = esc_html__( 'File Upload', 'gravityview' );
22
		parent::__construct();
23
	}
24
25
	function field_options( $field_options, $template_id, $field_id, $context, $input_type ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
26
27
		unset( $field_options['search_filter'] );
28
29
		if( 'edit' === $context ) {
30
			return $field_options;
31
		}
32
33
		$add_options['link_to_file'] = array(
0 ignored issues
show
Coding Style Comprehensibility introduced by
$add_options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $add_options = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
34
			'type' => 'checkbox',
35
			'label' => __( 'Display as a Link:', 'gravityview' ),
36
			'desc' => __('Display the uploaded files as links, rather than embedded content.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
37
			'value' => false,
38
			'merge_tags' => false,
39
		);
40
41
		return $add_options + $field_options;
42
	}
43
44
	/**
45
	 * Trick the GF fileupload field to render with the proper HTML ID to enable the plupload JS to work properly
46
	 *
47
	 * @param array               $form  The Form Object currently being processed.
48
	 * @param string|array        $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission.
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
49
	 * @param null|array          $entry Null or the Entry Object currently being edited.
50
	 * @param GF_Field_FileUpload $field Gravity Forms field
51
	 *
52
	 * @return string
53
	 */
54 2
	function get_field_input( $form, $field_value, $entry, $field ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
55
56 2
		$field->_is_entry_detail = true;
57
58 2
		$return = $field->get_field_input( $form, $field_value, $entry );
59
60 2
		return $return;
61
	}
62
63
	/**
64
	 * Return an array of files prepared for output.
65
	 *
66
	 * Processes files by file type and generates unique output for each. Returns array for each file, with the following keys:
67
	 * - `file_path` => The file path of the file, with a line break
68
	 * - `html` => The file output HTML formatted
69
	 *
70
	 * @since  1.2
71
	 * @todo  Support `playlist` shortcode for playlist of video/audio
72
	 * @param  string $value    Field value passed by Gravity Forms. String of file URL, or serialized string of file URL array
73
	 * @param  string $gv_class Field class to add to the output HTML
74
	 *
75
	 * @since 2.0
76
	 * @param \GV\Template_Context The context.
77
	 *
78
	 * @return array           Array of file output, with `file_path` and `html` keys (see comments above)
79
	 */
80 2
	static function get_files_array( $value, $gv_class, $context = null ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
81
82 2
		if ( $context instanceof \GV\Template_Context ) {
83 2
			$field = $context->field->field;
0 ignored issues
show
Bug introduced by
The property field does not seem to exist in GV\Field.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
84 2
			$field_settings = $context->field->as_configuration();
85 2
			$entry = $context->entry->as_entry();
86 2
			$field_value = $context->value;
87 2
			global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
88 2
			$base_id = $post ? $post->ID : $context->view->ID;
89
90 2
			$is_single = $context->request->is_entry();
91 2
			$lightbox = $context->view->settings->get( 'lightbox', false );
92
93
			/** A compatibility array that's required by some of the deprecated filters. */
94
			$field_compat = array(
95 2
				'form' => $context->source->form,
0 ignored issues
show
Bug introduced by
The property form does not seem to exist in GV\Source.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
96 2
				'field_id' => $context->field->ID,
97 2
				'field' => $field,
98 2
				'field_settings' => $field_settings,
99 2
				'value' => $field_value,
100 2
				'display_value' => $context->display_value,
101 2
				'format' => 'html',
102 2
				'entry' => $entry,
103 2
				'field_type' => $context->field->type,
0 ignored issues
show
Documentation introduced by
The property type does not exist on object<GV\Field>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
104 2
				'field_path' => $context->template->located_template,
105
			);
106
		} else {
107
108
			_doing_it_wrong( __METHOD__, '2.0', 'Please pass a \GV\Template_Context object as the 3rd parameter' );
109
110
			$gravityview_view = GravityView_View::getInstance();
111
			/** @deprecated path */
112
			$gv_field_array = $gravityview_view->getCurrentField();
113
114
			/** @var GF_Field_FileUpload $field */
115
			$field = \GV\Utils::get( $gv_field_array, 'field' );
116
			$field_settings = \GV\Utils::get( $gv_field_array, 'field_settings' );
117
			$entry = \GV\Utils::get( $gv_field_array, 'entry' );
118
			$field_value = \GV\Utils::get( $gv_field_array, 'value' );
119
			$base_id = null;
120
121
			$is_single = gravityview_get_context() === 'single';
0 ignored issues
show
Deprecated Code introduced by
The function gravityview_get_context() has been deprecated with message: since 2.0.6.2 Use `gravityview()->request`

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
122
			$lightbox = ! empty( $gravityview_view->atts['lightbox'] );
0 ignored issues
show
Documentation introduced by
The property $atts is declared protected in GravityView_View. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
123
			$field_compat = $gravityview_view->getCurrentField();
124
		}
125
126 2
		$output_arr = array();
127
128
		// Get an array of file paths for the field.
129 2
		$file_paths = \GV\Utils::get( $field , 'multipleFiles' ) ? json_decode( $value ) : array( $value );
130
131
		// The $value JSON was probably truncated; let's check lead_detail_long.
132 2
		if ( ! is_array( $file_paths ) ) {
133
			$full_value = RGFormsModel::get_lead_field_value( $entry, $field );
134
			$file_paths = json_decode( $full_value );
135
		}
136
137 2
		if ( ! is_array( $file_paths ) ) {
138
			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 ) ) );
139
			return $output_arr;
140
		}
141
142
		// Process each file path
143 2
		foreach ( $file_paths as $file_path ) {
144
145 2
			$text = $rendered = null;
146
147
			// If the site is HTTPS, use HTTPS
148 2
			if ( function_exists('set_url_scheme') ) {
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
149 2
				$file_path = set_url_scheme( $file_path );
150
			}
151
152
			// This is from Gravity Forms's code
153 2
			$file_path = esc_attr( str_replace( " ", "%20", $file_path ) );
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal %20 does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
154
155
			// Get file path information
156 2
			$file_path_info = pathinfo( $file_path );
157
158
			// If pathinfo() gave us the extension of the file, run the switch statement using that.
159 2
			$extension = empty( $file_path_info['extension'] ) ? NULL : strtolower( $file_path_info['extension'] );
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
160 2
			$basename = $file_path_info['basename'];
161
162
			// Get the secure download URL
163 2
			$is_secure = false;
164 2
			$secure_file_path = $field->get_download_url( $file_path );
165
166 2
			if ( $secure_file_path != $file_path ) {
167 1
				$basename = basename( $secure_file_path );
168 1
				$insecure_file_path = $file_path;
169 1
				$file_path = $secure_file_path;
170 1
				$is_secure = true;
171
			}
172
173
			/**
174
			 * @filter `gravityview/fields/fileupload/file_path` Modify the file path before generating a link to it
175
			 * @since 1.22.3
176
			 * @since 2.0 Added $context parameter
177
			 * @param string $file_path Path to the file uploaded by Gravity Forms
178
			 * @param array  $field_settings Array of GravityView field settings
179
			 * @param \GV\Template_Context $context The context.
180
			 */
181 2
			$file_path = apply_filters( 'gravityview/fields/fileupload/file_path', $file_path, $field_settings, $context );
182
183
			// Audio
184 2
			if ( in_array( $extension, wp_get_audio_extensions() ) ) {
185 2
				if ( shortcode_exists( 'audio' ) ) {
186 2
					$src = $is_secure ? $insecure_file_path : $file_path;
0 ignored issues
show
Bug introduced by
The variable $insecure_file_path does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
187
188
					/**
189
					 * @filter `gravityview_audio_settings` Modify the settings passed to the `wp_video_shortcode()` function
190
					 * @since  1.2
191
					 * @param array $audio_settings Array with `src` and `class` keys
192
					 * @since 2.0
193
					 * @param \GV\Template_Context $context The context.
194
					 */
195 2
					$audio_settings = apply_filters( 'gravityview_audio_settings', array(
196 2
						'src' => $src,
197 2
						'class' => 'wp-audio-shortcode gv-audio gv-field-id-'.$field_settings['id']
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
198 2
					), $context );
199
200
					/**
201
					 * Generate the audio shortcode
202
					 * @see http://codex.wordpress.org/Audio_Shortcode
203
					 * @see https://developer.wordpress.org/reference/functions/wp_audio_shortcode/
204
					 */
205 2
					$rendered = wp_audio_shortcode( $audio_settings );
206
207 2
					if ( $is_secure ) {
208 1
						foreach ( array( 'esc_attr', 'esc_html', 'esc_url', 'trim' /** noop */ ) as $f ) {
209 2
							$rendered = str_replace( $f( $insecure_file_path ), $f( $secure_file_path ), $rendered );
210
						}
211
					}
212
				}
213
214
			// Video
215 2
			} else if ( in_array( $extension, wp_get_video_extensions() ) ) {
216
				if ( shortcode_exists( 'video' ) ) {
217
					$src = $is_secure ? $insecure_file_path : $file_path;
218
219
					/**
220
					 * @filter `gravityview_video_settings` Modify the settings passed to the `wp_video_shortcode()` function
221
					 * @since  1.2
222
					 * @param array $video_settings Array with `src` and `class` keys
223
					 * @since 2.0
224
					 * @param \GV\Template_Context $context The context.
225
					 */
226
					$video_settings = apply_filters( 'gravityview_video_settings', array(
227
						'src' => $src,
228
						'class' => 'wp-video-shortcode gv-video gv-field-id-'.$field_settings['id']
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
229
					), $context );
230
231
					/**
232
					 * Generate the video shortcode
233
					 * @see http://codex.wordpress.org/Video_Shortcode
234
					 * @see https://developer.wordpress.org/reference/functions/wp_video_shortcode/
235
					 */
236
					$rendered = wp_video_shortcode( $video_settings );
237
238
					if ( $is_secure ) {
239
						foreach ( array( 'esc_attr', 'esc_html', 'esc_url', 'trim' /** noop */ ) as $f ) {
240
							$rendered = str_replace( $f( $insecure_file_path ), $f( $secure_file_path ), $rendered );
241
						}
242
					}
243
				}
244
245
			// PDF
246 2
			} else if ( $extension === 'pdf' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
247
				// PDF needs to be displayed in an IFRAME
248
				$file_path = add_query_arg( array( 'TB_iframe' => 'true' ), $file_path );
249
250
			// Images
251 2
			} else if ( in_array( $extension, array( 'jpg', 'jpeg', 'jpe', 'gif', 'png' ) ) ) {
252
				$image_atts = array(
253 2
					'src' => $file_path,
254 2
					'class' => 'gv-image gv-field-id-'.$field_settings['id'],
255 2
					'alt' => $field_settings['label'],
256 2
					'width' => ( $is_single ? NULL : 250 )
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
257
				);
258
259 2
				if ( $is_secure ) {
260 1
					$image_atts['validate_src'] = false;
261
				}
262
263
				/**
264
				 * Modify the default image attributes for uploaded images
265
				 * @since 2.0
266
				 * @see GravityView_Image For the available attributes
267
				 * @param array $image_atts
268
				 */
269 2
				$image_atts = apply_filters( 'gravityview/fields/fileupload/image_atts', $image_atts );
270
271 2
				$image = new GravityView_Image( $image_atts );
272
273 2
				$entry_slug = GravityView_API::get_entry_slug( $entry['id'], $entry );
274
275 2
				$text = $image->html();
276
277 2
				if ( $lightbox && empty( $field_settings['show_as_link'] ) ) {
278
					$lightbox_link_atts = array(
279 1
						'rel' => sprintf( "%s-%s", $gv_class, $entry_slug ),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal %s-%s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
280 1
						'class' => 'thickbox',
281
					);
282
283 1
					$rendered = gravityview_get_link( $file_path, $image->html(), $lightbox_link_atts );
284
				} else {
285 2
					$rendered = $image->html();
286
				}
287
			}
288
289
			/**
290
			 * @filter `gravityview/fields/fileupload/disable_link` Filter to alter the default behaviour of wrapping images (or image names) with a link to the content object
291
			 * @since 1.5.1
292
			 * @param bool $disable_wrapped_link whether to wrap the content with a link to the content object.
293
			 * @param array $field_compat Current GravityView field array
294
			 * @see GravityView_API:field_value() for info about $gravityview_view->field_data
295
			 * @since 2.0
296
			 * @param \GV\Template_Context $context The context.
297
			 */
298 2
			$disable_wrapped_link = apply_filters( 'gravityview/fields/fileupload/disable_link', false, $field_compat, $context );
299
300
			// Output textualized content where 
301 2
			if ( ! $disable_wrapped_link && ( ! empty( $field_settings['link_to_file'] ) && empty( $field_settings['show_as_link'] ) ) ) {
302 1
				$content = empty( $text ) ? $basename : $text;
303
304
				/**
305
				 * Modify the link text (defaults to the file name)
306
				 *
307
				 * @since 1.7
308
				 *
309
				 * @param string $content The existing anchor content. Could be `<img>` tag, audio/video embed or the file name
310
				 * @param array $field_compat Current GravityView field array
311
				 * @since 2.0
312
				 * @param \GV\Template_Context $context The context.
313
				 */
314 1
				$content = apply_filters( 'gravityview/fields/fileupload/link_content', $content, $field_compat, $context );
315
316
				/**
317
				 * @filter `gravityview/fields/fileupload/link_atts` Modify the link attributes for a file upload field
318
				 * @param array|string $link_atts Array or attributes string
319
				 * @param array $field_compat Current GravityView field array
320
				 * @since 2.0
321
				 * @param \GV\Template_Context $context The context.
322
				 */
323 1
				$link_atts = apply_filters( 'gravityview/fields/fileupload/link_atts', array( 'target' => '_blank' ), $field_compat, $context );
324
325 1
				$content = gravityview_get_link( $file_path, $content, $link_atts );
326
			} else {
327 2
				$content = empty( $rendered ) ? ( empty( $text ) ? $basename : $text ) : $rendered;
328
			}
329
330 2
			$output_arr[] = array(
331 2
				'file_path' => $file_path,
332 2
				'content' => $content
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
333
			);
334
335
		} // End foreach loop
336
337
		/**
338
		 * @filter `gravityview/fields/fileupload/files_array` Modify the files array
339
		 * @since 1.7
340
		 * @param array $output_arr Associative array of files \n
341
		 *  @type string $file_path The path to the file as stored in Gravity Forms \n
342
		 *  @type string $content The generated output for the file \n
343
		 * @param array $field_compat Current GravityView field array
344
		 * @since 2.0
345
		 * @param \GV\Template_Context $context The context.
346
		 */
347 2
		$output_arr = apply_filters( 'gravityview/fields/fileupload/files_array', $output_arr, $field_compat, $context );
348
349 2
		return $output_arr;
350
	}
351
}
352
353
new GravityView_Field_FileUpload;
354