Completed
Push — develop ( 08585c...0ba009 )
by Gennady
17:09
created

class-api.php ➔ gravityview_get_current_views()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.1406

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 0
dl 0
loc 22
ccs 6
cts 8
cp 0.75
crap 3.1406
rs 9.568
c 0
b 0
f 0
1
<?php
2
/**
3
 * GravityView template tags API
4
 *
5
 * @package   GravityView
6
 * @license   GPL2+
7
 * @author    Katz Web Services, Inc.
8
 * @link      http://gravityview.co
9
 * @copyright Copyright 2014, Katz Web Services, Inc.
10
 *
11
 * @since 1.0.0
12
 */
13
14
class GravityView_API {
15
16
	/**
17
	 * Fetch Field Label
18
	 *
19
	 * @deprecated Use \GV\Field::get_label()
20
	 *
21
	 * @access public
22
	 * @static
23
	 * @param array $field GravityView field array
24
	 * @param array $entry Gravity Forms entry array
25
	 * @param boolean $force_show_label Whether to always show the label, regardless of field settings
26
	 * @return string
27
	 */
28 3
	public static function field_label( $field, $entry = array(), $force_show_label = false ) {
29
30 3
		$gravityview_view = GravityView_View::getInstance();
31
32 3
		$form = $gravityview_view->getForm();
33
34 3
		if ( defined( 'DOING_GRAVITYVIEW_TESTS' ) && ! empty( $GLOBALS['GravityView_API_field_label_override'] ) ) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
35
			/** Allow to fall through for back compatibility testing purposes. */
36
		} else {
37 3
			return \GV\Mocks\GravityView_API_field_label( $form, $field, $entry, $force_show_label );
38
		}
39 1
	}
40
41
	/**
42
	 * Alias for GravityView_Merge_Tags::replace_variables()
43
	 *
44
	 * @see GravityView_Merge_Tags::replace_variables() Moved in 1.8.4
45
	 * @since 1.22.4 - Added $nl2br, $format, $aux_data args
46
	 *
47
	 * @param  string     $text         Text to replace variables in
48
	 * @param  array      $form         GF Form array
49
	 * @param  array      $entry        GF Entry array
50
	 * @param  bool       $url_encode   Pass return value through `url_encode()`
51
	 * @param  bool       $esc_html     Pass return value through `esc_html()`
52
	 * @param  bool       $nl2br        Convert newlines to <br> HTML tags
53
	 * @param  string     $format       The format requested for the location the merge is being used. Possible values: html, text or url.
54
	 * @param  array      $aux_data     Additional data to be used to replace merge tags {@see https://www.gravityhelp.com/documentation/article/gform_merge_tag_data/}
55
	 * @return string                   Text with variables maybe replaced
56
	 */
57 26
	public static function replace_variables( $text, $form = array(), $entry = array(), $url_encode = false, $esc_html = true, $nl2br = true, $format = 'html', $aux_data = array() ) {
58 26
		return GravityView_Merge_Tags::replace_variables( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format, $aux_data );
59
	}
60
61
	/**
62
	 * Get column width from the field setting
63
	 *
64
	 * @since 1.9
65
	 *
66
	 * @param array $field Array of settings for the field
67
	 * @param string $format Format for width. "%" (default) will return
68
	 *
69
	 * @return string|null If not empty, string in $format format. Otherwise, null.
70
	 */
71 29
	public static function field_width( $field, $format = '%d%%' ) {
72
73 29
		$width = NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
74
75 29
		if( !empty( $field['width'] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
76 1
			$width = absint( $field['width'] );
77
78
			// If using percentages, limit to 100%
79 1
			if( '%d%%' === $format && $width > 100 ) {
80 1
				$width = 100;
81
			}
82
83 1
			$width = sprintf( $format, $width );
84
		}
85
86 29
		return $width;
87
	}
88
89
	/**
90
	 * Fetch Field class
91
	 *
92
	 * @access public
93
	 * @static
94
	 * @param mixed $field
95
	 * @return string
96
	 */
97 32
	public static function field_class( $field, $form = NULL, $entry = NULL ) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
98 32
		$classes = array();
99
100 32
		if( !empty( $field['custom_class'] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
101
102 2
            $custom_class = $field['custom_class'];
103
104 2
            if( !empty( $entry ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
105
106
                // We want the merge tag to be formatted as a class. The merge tag may be
107
                // replaced by a multiple-word value that should be output as a single class.
108
                // "Office Manager" will be formatted as `.OfficeManager`, not `.Office` and `.Manager`
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
109 2
                add_filter('gform_merge_tag_filter', 'sanitize_html_class');
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...
110
111 2
                $custom_class = self::replace_variables( $custom_class, $form, $entry);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
112
113
                // And then we want life to return to normal
114 2
                remove_filter('gform_merge_tag_filter', 'sanitize_html_class');
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...
115
            }
116
117
			// And now we want the spaces to be handled nicely.
118 2
			$classes[] = gravityview_sanitize_html_class( $custom_class );
119
120
		}
121
122 32
		if(!empty($field['id'])) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
introduced by
Expected 1 space before "!"; 0 found
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
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...
introduced by
No space before closing parenthesis is prohibited
Loading history...
123 32
			if( !empty( $form ) && !empty( $form['id'] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
124 32
				$form_id = '-'.$form['id'];
125
			} else {
126
				// @deprecated path. Form should always be given.
127
				gravityview()->log->warning( 'GravityView_View::getInstance() legacy API called' );
128
				$gravityview_view = GravityView_View::getInstance();
129
				$form_id = $gravityview_view->getFormId() ? '-'. $gravityview_view->getFormId() : '';
130
			}
131
132 32
			$classes[] = 'gv-field'.$form_id.'-'.$field['id'];
133
		}
134
135 32
		return esc_attr(implode(' ', $classes));
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...
136
	}
137
138
	/**
139
	 * Fetch Field HTML ID
140
	 *
141
	 * @since 1.11
142
	 *
143
	 * @access public
144
	 * @static
145
	 * @param array $field GravityView field array passed to gravityview_field_output()
146
	 * @param array $form Gravity Forms form array, if set.
147
	 * @param array $entry Gravity Forms entry array
148
	 * @return string Sanitized unique HTML `id` attribute for the field
149
	 */
150 28
	public static function field_html_attr_id( $field, $form = array(), $entry = array() ) {
0 ignored issues
show
Unused Code introduced by
The parameter $entry is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
151 28
		$id = $field['id'];
152
153 28
		if ( ! empty( $id ) ) {
154 28
			if ( ! empty( $form ) && ! empty( $form['id'] ) ) {
155 28
				$form_id = '-' . $form['id'];
156
			} else {
157
				// @deprecated path. Form should always be given.
158
				gravityview()->log->warning( 'GravityView_View::getInstance() legacy API called' );
159
				$gravityview_view = GravityView_View::getInstance();
160
				$form_id = $gravityview_view->getFormId() ? '-' . $gravityview_view->getFormId() : '';
161
			}
162
163 28
			$id = 'gv-field' . $form_id . '-' . $field['id'];
164
		}
165
166 28
		return esc_attr( $id );
167
	}
168
169
170
	/**
171
	 * Given an entry and a form field id, calculate the entry value for that field.
172
	 *
173
	 * @deprecated Use \GV\Field_Template::render() or the more low-level \GV\Field::get_value()
174
	 *
175
	 * @access public
176
	 * @param array $entry
177
	 * @param array $field
0 ignored issues
show
Bug introduced by
There is no parameter named $field. 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...
178
	 * @return null|string
179
	 */
180 3
	public static function field_value( $entry, $field_settings, $format = 'html' ) {
181 3
		gravityview()->log->notice( '\GravityView_API::field_value is deprecated. Use \GV\Field_Template::render() or \GV\Field::get_value()' );
182 3
		return \GV\Mocks\GravityView_API_field_value( $entry, $field_settings, $format );
0 ignored issues
show
Deprecated Code introduced by
The function GV\Mocks\GravityView_API_field_value() has been deprecated with message: Use \GV\Field_Template::render()

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...
183
	}
184
185
	/**
186
	 * Generate an anchor tag that links to an entry.
187
	 *
188
	 * @since 1.6
189
	 * @see GVCommon::get_link_html()
190
	 *
191
	 * @param string $anchor_text The text or HTML inside the link
192
	 * @param array $entry Gravity Forms entry array
193
	 * @param array|string $passed_tag_atts Attributes to be added to the anchor tag, such as `title` or `rel`.
194
	 * @param array $field_settings Array of field settings. Optional, but passed to the `gravityview_field_entry_link` filter
195
	 *
196
	 * @since 2.0
197
	 * @param int $base_id The post or the view that this entry is linked from.
198
	 *
199
	 * @return string|null Returns HTML for an anchor link. Null if $entry isn't defined or is missing an ID.
200
	 */
201 2
	public static function entry_link_html( $entry = array(), $anchor_text = '', $passed_tag_atts = array(), $field_settings = array(), $base_id = null ) {
202
203 2
		if ( empty( $entry ) || ! is_array( $entry ) || ! isset( $entry['id'] ) ) {
204 1
			gravityview()->log->debug( 'Entry not defined; returning null', array( 'data' => $entry ) );
205 1
			return NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
206
		}
207
208 2
		$href = self::entry_link( $entry, $base_id );
209
210 2
		if( '' === $href ) {
211
			return NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
212
		}
213
214 2
		$link = gravityview_get_link( $href, $anchor_text, $passed_tag_atts );
215
216
		/**
217
		 * @filter `gravityview_field_entry_link` Modify the link HTML
218
		 * @param string $link HTML output of the link
219
		 * @param string $href URL of the link
220
		 * @param array  $entry The GF entry array
221
		 * @param  array $field_settings Settings for the particular GV field
222
		 */
223 2
		$output = apply_filters( 'gravityview_field_entry_link', $link, $href, $entry, $field_settings );
224
225 2
		return $output;
226
	}
227
228
	/**
229
	 * Get the "No Results" text depending on whether there were results.
230
	 * @param  boolean     $wpautop Apply wpautop() to the output?
231
	 *
232
	 * @since 2.0
233
	 * @param \GV\Template_Context $context The context
234
	 *
235
	 * @return string               HTML of "no results" text
236
	 */
237 9
	public static function no_results( $wpautop = true, $context = null ) {
238 9
		$is_search = false;
239
240 9
		if ( $context instanceof \GV\Template_Context ) {
241 7
			if ( $context->request->is_search() ) {
242 7
				$is_search = true;
243
			}
244
		} else {
245 2
			$gravityview_view = GravityView_View::getInstance();
246
247 2
			if( $gravityview_view && ( $gravityview_view->curr_start || $gravityview_view->curr_end || $gravityview_view->curr_search ) ) {
0 ignored issues
show
Documentation introduced by
The property curr_start does not exist on object<GravityView_View>. 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...
Documentation introduced by
The property curr_end does not exist on object<GravityView_View>. 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...
Documentation introduced by
The property curr_search does not exist on object<GravityView_View>. 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...
248 1
				$is_search = true;
249
			}
250
		}
251
252 9
		if ( $is_search ) {
253 1
			$output = __( 'This search returned no results.', 'gravityview' );
254
		} else {
255 9
			$output = __( 'No entries match your request.', 'gravityview' );
256
		}
257
258
		/**
259
		 * @filter `gravitview_no_entries_text` Modify the text displayed when there are no entries.
260
		 * Note: this filter is, and always has been, misspelled. This will not be fixed, since the filter is deprecated.
261
		 * @param string $output The existing "No Entries" text
262
		 * @param boolean $is_search Is the current page a search result, or just a multiple entries screen?
263
		 * @return string The modified text.
264
		 * @deprecated Use `gravityview/template/text/no_entries`
265
		 */
266 9
		$output = apply_filters( 'gravitview_no_entries_text', $output, $is_search );
267
268
		/**
269
		 * @filter `gravityview/template/text/no_entries` Modify the text displayed when there are no entries.
270
		 * @since 2.0
271
		 * @param string $output The existing "No Entries" text
272
		 * @param boolean $is_search Is the current page a search result, or just a multiple entries screen?
273
		 * @param \GV\Template_Context $context The context.
274
		 * @return string The modified text.
275
		 */
276 9
		$output = apply_filters( 'gravityview/template/text/no_entries', $output, $is_search, $context );
277
278 9
		return $wpautop ? wpautop( $output ) : $output;
279
	}
280
281
	/**
282
	 * Generate a URL to the Directory context
283
	 *
284
	 * Uses `wp_cache_get` and `wp_cache_get` (since 1.3) to speed up repeated requests to get permalink, which improves load time. Since we may be doing this hundreds of times per request, it adds up!
285
	 *
286
	 * @param int $post_id Post ID
287
	 * @param boolean $add_query_args Add pagination and sorting arguments
288
	 *
289
	 * @since 2.0
290
	 * @param \GV\Template_Context $context The context this is being used in.
291
	 *
292
	 * @return string      Permalink to multiple entries view
293
	 */
294 29
	public static function directory_link( $post_id = NULL, $add_query_args = true, $context = null ) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
295 29
		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...
296
297 29
		if ( empty( $post_id ) ) {
298
			// DataTables passes the Post ID
299 17
			if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
300
				$post_id = \GV\Utils::_POST( 'post_id', false );
301
			} else {
302 17
				if ( $context instanceof \GV\Template_Context ) {
303
					// Shortcodes, embeds
304 14
					if ( is_a( $post, 'WP_Post' ) ) {
305 3
						$post_id = $post->ID;
306
307
					// Actual views
308
					} else {
309 14
						$post_id = $context->view ? $context->view->ID : false;
310
					}
311
				} else {
312
					/** @deprecated path of execution */
313 3
					$gravityview_view = GravityView_View::getInstance();
314
315
					// The Post ID has been passed via the shortcode
316 3
					if ( ! empty( $gravityview_view ) && $gravityview_view->getPostId() ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $gravityview_view->getPostId() of type integer|null is loosely compared to true; this is ambiguous if the integer can be zero. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
317 2
						$post_id = $gravityview_view->getPostId();
318
					} else {
319
						// This is a GravityView post type
320 1
						if ( GravityView_frontend::getInstance()->isGravityviewPostType() ) {
321
							$post_id = isset( $gravityview_view ) ? $gravityview_view->getViewId() : $post->ID;
322
						} else {
323
							// This is an embedded GravityView; use the embedded post's ID as the base.
324 1
							if ( GravityView_frontend::getInstance()->isPostHasShortcode() && is_a( $post, 'WP_Post' ) ) {
325
								$post_id = $post->ID;
326 1
							} elseif ( $gravityview_view->getViewId() ) {
327
								// The GravityView has been embedded in a widget or in a template, and
328
								// is not in the current content. Thus, we defer to the View's own ID.
329
								$post_id = $gravityview_view->getViewId();
330
							}
331
						}
332
					}
333
				}
334
			}
335
		}
336
337
		// No post ID, get outta here.
338 29
		if ( empty( $post_id ) ) {
339 1
			return null;
340
		}
341
342
		// If we've saved the permalink in memory, use it
343
		// @since 1.3
344 28
		$link = wp_cache_get( 'gv_directory_link_'.$post_id );
345
346 28
		if ( (int) $post_id === (int) get_option( 'page_on_front' ) ) {
347
			$link = home_url();
348
		}
349
350 28
		if ( empty( $link ) ) {
351 28
			$link = get_permalink( $post_id );
352
353
			// If not yet saved, cache the permalink.
354
			// @since 1.3
355 28
			wp_cache_set( 'gv_directory_link_'.$post_id, $link );
356
		}
357
358
		// Deal with returning to proper pagination for embedded views
359 28
		if ( $link && $add_query_args ) {
360
361 24
			$args = array();
362
363 24
			if( $pagenum = \GV\Utils::_GET( 'pagenum' ) ) {
364 1
				$args['pagenum'] = intval( $pagenum );
365
			}
366
367 24
			if( $sort = \GV\Utils::_GET( 'sort' ) ) {
368
				$args['sort'] = $sort;
369
				$args['dir'] = \GV\Utils::_GET( 'dir' );
370
			}
371
372 24
			$link = add_query_arg( $args, $link );
373
		}
374
375
		/**
376
		 * @filter `gravityview_directory_link` Modify the URL to the View "directory" context
377
		 * @since 1.19.4
378
		 * @param string $link URL to the View's "directory" context (Multiple Entries screen)
379
		 * @param int $post_id ID of the post to link to. If the View is embedded, it is the post or page ID
380
		 */
381 28
		$link = apply_filters( 'gravityview_directory_link', $link, $post_id );
382
383
		/**
384
		 * @filter `gravityview/view/links/directory` Modify the URL to the View "directory" context
385
		 * @since 2.0
386
		 * @param string $link URL to the View's "directory" context (Multiple Entries screen)
387
		 * @param \GV\Template_Context $context 
388
		 */
389 28
		return apply_filters( 'gravityview/view/links/directory', $link, $context );
390
	}
391
392
	/**
393
	 * Calculate an *unique* hash for an entry based on the entry ID
394
	 *
395
	 * This allows you to be more discrete as to the number of the entry - if you don't want users to know that you have made a certain number of sales, for example, or that their entry in the giveaway is entry #3.
396
	 *
397
	 * The hashed value MUST be unique, otherwise multiple entries will share the same URL, which leads to obvious problems.
398
	 *
399
	 * @param  int|string $id Entry ID to generate the hash for.
400
	 * @param  array  $entry        Entry data passed to provide additional information when generating the hash. Optional - don't rely on it being available.
401
	 * @return string               Hashed unique value for entry
402
	 */
403 3
	private static function get_custom_entry_slug( $id, $entry = array() ) {
404
405
		// Generate an unique hash to use as the default value
406 3
		$slug = substr( wp_hash( $id, 'gravityview'.$id ), 0, 8 );
407
408
		/**
409
		 * @filter `gravityview_entry_slug` Modify the unique hash ID generated, if you want to improve usability or change the format. This will allow for custom URLs, such as `{entryid}-{first-name}` or even, if unique, `{first-name}-{last-name}`
410
		 * @param string $hash Existing hash generated by GravityView
411
		 * @param  string $id The entry ID
412
		 * @param  array $entry Entry data array. May be empty.
413
		 */
414 3
		$slug = apply_filters( 'gravityview_entry_slug', $slug, $id, $entry );
415
416
		// Make sure we have something - use the original ID as backup.
417 3
		if( empty( $slug ) ) {
418
			$slug = $id;
419
		}
420
421 3
		return sanitize_title( $slug );
422
	}
423
424
	/**
425
	 * Get the entry slug for the entry. By default, it is the entry ID.
426
	 *
427
	 *
428
	 * @see gravityview_get_entry()
429
	 * @uses GravityView_API::get_custom_entry_slug() If using custom slug, gets the custom slug value
430
	 * @since 1.4
431
	 * @param  int|string $id_or_string ID of the entry, or custom slug string
432
	 * @param  array  $entry        Gravity Forms Entry array, optional. Used only to provide data to customize the `gravityview_entry_slug` filter
433
	 * @return string               Unique slug ID, passed through `sanitize_title()`
434
	 */
435 87
	public static function get_entry_slug( $id_or_string, $entry = array() ) {
436
437
		/**
438
		 * Default: use the entry ID as the unique identifier
439
		 */
440 87
		$slug = $id_or_string;
441
442
		/**
443
		 * @filter `gravityview_custom_entry_slug` Whether to enable and use custom entry slugs.
444
		 * @param boolean True: Allow for slugs based on entry values. False: always use entry IDs (default)
445
		 */
446 87
		$custom = apply_filters( 'gravityview_custom_entry_slug', false );
447
448
		// If we're using custom slug...
449 87
		if ( $custom ) {
450
451
			// Get the entry hash
452 3
			$hash = self::get_custom_entry_slug( $id_or_string, $entry );
453
454
			// Cache the slugs
455 3
			static $cache = array();
456
457 3
			if ( ! isset( $cache[ $id_or_string ] ) ) {
458 3
				global $wpdb;
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...
459
460 3
				if ( version_compare( GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) ) {
461 3
					$table = GFFormsModel::get_entry_meta_table_name();
462 3
					$column = 'entry_id';
463
				} else {
464
					$table = RGFormsModel::get_lead_meta_table_name();
465
					$column = 'lead_id';
466
				}
467
468 3
				$results = $wpdb->get_results( $wpdb->prepare( "SELECT $column, meta_value FROM $table WHERE form_id = (SELECT form_id FROM $table WHERE $column = %d LIMIT 1) AND meta_key = 'gravityview_unique_id'", $id_or_string ) );
0 ignored issues
show
introduced by
Usage of a direct database call is discouraged.
Loading history...
introduced by
Usage of a direct database call without caching is prohibited. Use wp_cache_get / wp_cache_set.
Loading history...
469
470 3
				if ( $results ) {
471
					$cache = array_replace( $cache, array_combine( wp_list_pluck( $results, $column ), wp_list_pluck( $results, 'meta_value' ) ) );
472
				}
473
474 3
				if ( ! isset( $cache[ $id_or_string ] ) ) {
475 3
					$cache[ $id_or_string ] = false;
476
				}
477
			}
478
479 3
			$value = $cache[ $id_or_string ];
480
481
			// If it does have a hash set, and the hash is expected, use it.
482
			// This check allows users to change the hash structure using the
483
			// gravityview_entry_hash filter and have the old hashes expire.
484 3
			if ( empty( $value ) || $value !== $hash ) {
485 3
				gravityview()->log->debug( 'Setting hash for entry {entry}: {hash}', array( 'entry' => $id_or_string, 'hash' => $hash ) );
486 3
				gform_update_meta( $id_or_string, 'gravityview_unique_id', $hash, \GV\Utils::get( $entry, 'form_id' ) );
487
			}
488
489 3
			$slug = $hash;
490
491 3
			unset( $value, $hash );
492
		}
493
494 87
		return sanitize_title( $slug );
495
	}
496
497
    /**
498
     * If using the entry custom slug feature, make sure the new entries have the custom slug created and saved as meta
499
     *
500
     * Triggered by add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
501
     *
502
     * @param $entry array Gravity Forms entry object
503
     * @param $form array Gravity Forms form object
504
     */
505
    public static function entry_create_custom_slug( $entry, $form ) {
0 ignored issues
show
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
506
        /**
507
         * @filter `gravityview_custom_entry_slug` On entry creation, check if we are using the custom entry slug feature and update the meta
508
         * @param boolean $custom Should we process the custom entry slug?
509
         */
510
        $custom = apply_filters( 'gravityview_custom_entry_slug', false );
511
        if( $custom ) {
512
            // create the gravityview_unique_id and save it
513
514
            // Get the entry hash
515
            $hash = self::get_custom_entry_slug( $entry['id'], $entry );
516
517
	        gravityview()->log->debug( 'Setting hash for entry {entry_id}: {hash}', array( 'entry_id' => $entry['id'], 'hash' => $hash ) );
518
519
            gform_update_meta( $entry['id'], 'gravityview_unique_id', $hash, \GV\Utils::get( $entry, 'form_id' ) );
520
521
        }
522
    }
523
524
525
526
527
	/**
528
	 * return href for single entry
529
	 * @param  array|int $entry   Entry array or entry ID
530
	 * @param  int|null $post_id If wanting to define the parent post, pass a post ID
531
	 * @param boolean $add_directory_args True: Add args to help return to directory; False: only include args required to get to entry {@since 1.7.3}
532
	 * @return string          Link to the entry with the directory parent slug, or empty string if embedded post or View doesn't exist
533
	 */
534 6
	public static function entry_link( $entry, $post_id = NULL, $add_directory_args = true ) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
535
536 6
		if ( ! empty( $entry ) && ! is_array( $entry ) ) {
537
			$entry = GVCommon::get_entry( $entry );
538 6
		} else if( empty( $entry ) ) {
539
			// @deprecated path
540
			$entry = GravityView_frontend::getInstance()->getEntry();
541
		}
542
543
		// Second parameter used to be passed as $field; this makes sure it's not an array
544 6
		if ( ! is_numeric( $post_id ) ) {
545 1
			$post_id = NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
546
		}
547
548
		// Get the permalink to the View
549 6
		$directory_link = self::directory_link( $post_id, false );
550
551
		// No post ID? Get outta here.
552 6
		if ( empty( $directory_link ) ) {
553 1
			return '';
554
		}
555
556 5
		$query_arg_name = \GV\Entry::get_endpoint_name();
557
558 5
		$entry_slug = self::get_entry_slug( $entry['id'], $entry );
559
560 5
		if ( get_option('permalink_structure') && !is_preview() ) {
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...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
561
562
			$args = array();
563
564
			/**
565
			 * Make sure the $directory_link doesn't contain any query otherwise it will break when adding the entry slug.
566
			 * @since 1.16.5
567
			 */
568
			$link_parts = explode( '?', $directory_link );
569
570
			$query = !empty( $link_parts[1] ) ? '?'.$link_parts[1] : '';
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
571
572
			$directory_link = trailingslashit( $link_parts[0] ) . $query_arg_name . '/'. $entry_slug .'/' . $query;
573
574
		} else {
575
576 5
			$args = array( $query_arg_name => $entry_slug );
577
		}
578
579
		/**
580
		 * @since 1.7.3
581
		 */
582 5
		if ( $add_directory_args ) {
583
584 5
			if ( ! empty( $_GET['pagenum'] ) ) {
585
				$args['pagenum'] = intval( $_GET['pagenum'] );
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
586
			}
587
588
			/**
589
			 * @since 1.7
590
			 */
591 5
			if ( $sort = \GV\Utils::_GET( 'sort' ) ) {
592
				$args['sort'] = $sort;
593
				$args['dir'] = \GV\Utils::_GET( 'dir' );
594
			}
595
596
		}
597
598 5
		if( $post_id ) {
599 5
			$passed_post = get_post( $post_id );
600 5
			$views       = \GV\View_Collection::from_post( $passed_post );
601 5
			$has_multiple_views = $views->count() > 1;
602
		} else {
603
			$has_multiple_views = class_exists( 'GravityView_View_Data' ) && GravityView_View_Data::getInstance()->has_multiple_views();
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_View_Data::has_multiple_views() has been deprecated.

This method has been deprecated.

Loading history...
604
		}
605
606 5
		if ( $has_multiple_views ) {
607 1
			$args['gvid'] = gravityview_get_view_id();
608
		}
609
610 5
		return add_query_arg( $args, $directory_link );
611
612
	}
613
614
615
}
616
617
618
// inside loop functions
619
620
/**
621
 * @deprecated Use \GV\Field::get_label()
622
 */
623
function gv_label( $field, $entry = NULL ) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
624 2
	return GravityView_API::field_label( $field, $entry );
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_API::field_label() has been deprecated with message: Use \GV\Field::get_label()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
625
}
626
627
function gv_class( $field, $form = NULL, $entry = array() ) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
628 31
	return GravityView_API::field_class( $field, $form, $entry  );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 2 found
Loading history...
629
}
630
631
/**
632
 * Generate a CSS class to be added to the wrapper <div> of a View
633
 *
634
 * @since 1.5.4
635
 * @since 1.16 Added $echo parameter.
636
 * @since 2.0 Added $context parameter.
637
 *
638
 * @param string $passed_css_class Default: `gv-container gv-container-{view id}`. If View is hidden until search, adds ` hidden`
639
 * @param boolean $echo Whether to echo the output. Default: true
640
 * @param \GV\Template_Context $context The template context.
641
 *
642
 * @return string CSS class, sanitized by gravityview_sanitize_html_class()
643
 */
644
function gv_container_class( $passed_css_class = '', $echo = true, $context = null ) {
645 32
	if ( $context instanceof \GV\Template_Context ) {
646 30
		$hide_until_searched = false;
647 30
		$total_entries = 0;
648 30
		$view_id = 0;
649 30
		if ( $context->view ) {
650 30
			$view_id = $context->view->ID;
651 30
			if( $context->view->settings->get( 'hide_until_searched' ) ) {
652 4
				$hide_until_searched = ( empty( $context->entry ) && ! $context->request->is_search() );
653
			}
654
		}
655 30
		if ( $context->entries ) {
656 18
			$total_entries = $context->entries->total();
657 14
		} else if ( $context->entry ) {
658 30
			$total_entries = 1;
659
		}
660
	} else {
661
		/** @deprecated legacy execution path */
662 3
		$view_id = GravityView_View::getInstance()->getViewId();
663 3
		$hide_until_searched = GravityView_View::getInstance()->isHideUntilSearched();
664 3
		$total_entries = GravityView_View::getInstance()->getTotalEntries();
665
	}
666
667 32
	$passed_css_class = trim( $passed_css_class );
668
669 32
	$default_css_class = ! empty( $view_id ) ? sprintf( 'gv-container gv-container-%d', $view_id ) : 'gv-container';
670
671 32
	if ( $hide_until_searched ) {
672 4
		$default_css_class .= ' hidden';
673
	}
674
675 32
	if ( 0 === $total_entries ) {
676 7
		$default_css_class .= ' gv-container-no-results';
677
	}
678
679 32
	$css_class = trim( $passed_css_class . ' '. $default_css_class );
680
681
	/**
682
	 * @filter `gravityview/render/container/class` Modify the CSS class to be added to the wrapper <div> of a View
683
	 * @since 1.5.4
684
	 * @param[in,out] string $css_class Default: `gv-container gv-container-{view id}`. If View is hidden until search, adds ` hidden`. If the View has no results, adds `gv-container-no-results`
685
	 * @since 2.0
686
	 * @param \GV\Template_Context $context The context.
687
	 */
688 32
	$css_class = apply_filters( 'gravityview/render/container/class', $css_class, $context );
689
690 32
	$css_class = gravityview_sanitize_html_class( $css_class );
691
692 32
	if ( $echo ) {
693 32
		echo $css_class;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$css_class'
Loading history...
694
	}
695
696 32
	return $css_class;
697
}
698
699
/**
700
 * @deprecated Use \GV\Field_Template::render()
701
 */
702
function gv_value( $entry, $field ) {
703
704 2
	$value = GravityView_API::field_value( $entry, $field );
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_API::field_value() has been deprecated with message: Use \GV\Field_Template::render() or the more low-level \GV\Field::get_value()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
705
706 2
	if( $value === '' ) {
707
		/**
708
		 * @filter `gravityview_empty_value` What to display when a field is empty
709
		 * @param string $value (empty string)
710
		 */
711 1
		$value = apply_filters( 'gravityview_empty_value', '' );
712
	}
713
714 2
	return $value;
715
}
716
717
function gv_directory_link( $post = NULL, $add_pagination = true, $context = null ) {
0 ignored issues
show
introduced by
Overridding WordPress globals is prohibited
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
718 15
	return GravityView_API::directory_link( $post, $add_pagination, $context );
719
}
720
721
function gv_entry_link( $entry, $post_id = NULL ) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
722 2
	return GravityView_API::entry_link( $entry, $post_id );
723
}
724
725
function gv_no_results( $wpautop = true, $context = null ) {
726 8
	return GravityView_API::no_results( $wpautop, $context );
727
}
728
729
/**
730
 * Generate HTML for the back link from single entry view
731
 * @since 1.0.1
732
 * @since 2.0
733
 * @param \GV\Template_Context $context The context this link is being displayed from.
734
 * @return string|null      If no GV post exists, null. Otherwise, HTML string of back link.
735
 */
736
function gravityview_back_link( $context = null ) {
737
738 14
	$href = gv_directory_link( null, true, $context );
739
740
	/**
741
	 * @filter `gravityview_go_back_url` Modify the back link URL
742
	 * @since 1.17.5
743
	 * @see gv_directory_link() Generated the original back link
744
	 * @param string $href Existing label URL
745
	 * @deprecated Use `gravityview/template/links/back/url`
746
	 */
747 14
	$href = apply_filters( 'gravityview_go_back_url', $href );
748
749
	/**
750
	 * @filter `gravityview/template/links/back/url` Modify the back link URL
751
	 * @since 2.0
752
	 * @see gv_directory_link() Generated the original back link
753
	 * @param string $href Existing label URL
754
	 * @param \GV\Template_Context The context.
755
	 */
756 14
	$href = apply_filters( 'gravityview/template/links/back/url', $href, $context );
757
758 14
	if ( empty( $href ) ) {
759 3
		return NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
760
	}
761
762 12
	if ( $context instanceof \GV\Template_Context ) {
763 12
		$view_id = $context->view->ID;
764 12
		$view_label = $context->template->get_back_label();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class GV\Template as the method get_back_label() does only exist in the following sub-classes of GV\Template: GV\Entry_Legacy_Template, GV\Entry_List_Template, GV\Entry_Table_Template, GV\Entry_Template. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
765
	} else {
766
		/** @deprecated legacy path */
767
		$gravityview_view = GravityView_View::getInstance();
768
		$view_id = $gravityview_view->getViewId();
769
		$view_label = $gravityview_view->getBackLinkLabel() ? $gravityview_view->getBackLinkLabel() : false;
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_View::getBackLinkLabel() has been deprecated with message: Use $template->get_back_label();

This method has been deprecated. The supplier of the class has supplied an explanatory message.

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

Loading history...
770
	}
771
772
	/** Default */
773 12
	$label = $view_label ? $view_label : __( '&larr; Go back', 'gravityview' );
774
775
	/**
776
	 * @filter `gravityview_go_back_label` Modify the back link text
777
	 * @since 1.0.9
778
	 * @param string $label Existing label text
779
	 * @deprecated Use `gravityview/template/links/back/label`
780
	 */
781 12
	$label = apply_filters( 'gravityview_go_back_label', $label );
782
783
	/**
784
	 * @filter `gravityview/template/links/back/label` Modify the back link text
785
	 * @since 2.0
786
	 * @see gv_directory_link() Generated the original back link
787
	 * @param string $label Existing label text
788
	 * @param \GV\Template_Context The context.
789
	 */
790 12
	$label = apply_filters( 'gravityview/template/links/back/label', $label, $context );
791
792
	/**
793
	 * @filter `gravityview/template/links/back/atts` Modify the attributes used on the back link anchor tag
794
	 * @since 2.1
795
	 * @param array $atts Original attributes, default: [ data-viewid => $view_id ]
796
	 * @param \GV\Template_Context The context.
797
	 */
798 12
	$atts = apply_filters( 'gravityview/template/links/back/atts', array( 'data-viewid' => $view_id ), $context );
799
800 12
	$link = gravityview_get_link( $href, esc_html( $label ), $atts );
801
802 12
	return $link;
803
}
804
805
/**
806
 * Handle getting values for complex Gravity Forms fields
807
 *
808
 * If the field is complex, like a product, the field ID, for example, 11, won't exist. Instead,
809
 * it will be 11.1, 11.2, and 11.3. This handles being passed 11 and 11.2 with the same function.
810
 *
811
 * @since 1.0.4
812
 * @param  array      $entry    GF entry array
813
 * @param  string      $field_id [description]
814
 * @param  string 	$display_value The value generated by Gravity Forms
815
 * @return string                Value
816
 */
817
function gravityview_get_field_value( $entry, $field_id, $display_value ) {
818
819 9
	if( floatval( $field_id ) === floor( floatval( $field_id ) ) ) {
820
821
		// For the complete field value as generated by Gravity Forms
822 6
		return $display_value;
823
824
	} else {
825
826
		// For one part of the address (City, ZIP, etc.)
827 7
		return isset( $entry[ $field_id ] ) ? $entry[ $field_id ] : '';
828
829
	}
830
831
}
832
833
/**
834
 * Take a passed CSV of terms and generate a linked list of terms
835
 *
836
 * Gravity Forms passes categories as "Name:ID" so we handle that using the ID, which
837
 * is more accurate than checking the name, which is more likely to change.
838
 *
839
 * @param  string      $value    Existing value
840
 * @param  string      $taxonomy Type of term (`post_tag` or `category`)
841
 * @return string                CSV of linked terms
842
 */
843
function gravityview_convert_value_to_term_list( $value, $taxonomy = 'post_tag' ) {
844
845 1
	$output = array();
846
847 1
	if ( is_array( $value ) ) {
848 1
		$terms = array_filter( array_values( $value ), 'strlen' );
849
	} else {
850 1
		$terms = explode( ', ', $value );
851
	}
852
853 1
	foreach ($terms as $term_name ) {
0 ignored issues
show
introduced by
No space after opening parenthesis is prohibited
Loading history...
854
855
		// If we're processing a category,
856 1
		if( $taxonomy === 'category' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
857
858
			// Use rgexplode to prevent errors if : doesn't exist
859 1
			list( $term_name, $term_id ) = rgexplode( ':', $term_name, 2 );
860
861
			// The explode was succesful; we have the category ID
862 1
			if( !empty( $term_id )) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
863 1
				$term = get_term_by( 'id', $term_id, $taxonomy );
864
			} else {
865
			// We have to fall back to the name
866 1
				$term = get_term_by( 'name', $term_name, $taxonomy );
867
			}
868
869
		} else {
870
			// Use the name of the tag to get the full term information
871 1
			$term = get_term_by( 'name', $term_name, $taxonomy );
872
		}
873
874
		// There's still a tag/category here.
875 1
		if( $term ) {
876
877 1
			$term_link = get_term_link( $term, $taxonomy );
878
879
			// If there was an error, continue to the next term.
880 1
			if ( is_wp_error( $term_link ) ) {
881
			    continue;
882
			}
883
884 1
			$output[] = gravityview_get_link( $term_link, esc_html( $term->name ) );
885
		}
886
	}
887
888 1
	return implode(', ', $output );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
889
}
890
891
/**
892
 * Get the links for post_tags and post_category output based on post ID
893
 * @param  int      $post_id  The ID of the post
894
 * @param  boolean     $link     Add links or no?
895
 * @param  string      $taxonomy Taxonomy of term to fetch.
896
 * @return string                String with terms
897
 */
898
function gravityview_get_the_term_list( $post_id, $link = true, $taxonomy = 'post_tag' ) {
899
900 1
	$output = get_the_term_list( $post_id, $taxonomy, NULL, ', ' );
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
901
902 1
	if( empty( $link ) ) {
903 1
		return strip_tags( $output);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
904
	}
905
906 1
	return $output;
907
908
}
909
910
911
/**
912
 * Get all views processed so far for the current page load
913
 *
914
 * @see  GravityView_View_Data::add_view()
915
 * @return array Array of View data, each View data with `id`, `view_id`, `form_id`, `template_id`, `atts`, `fields`, `widgets`, `form` keys.
916
 */
917
function gravityview_get_current_views() {
918
919 1
	$fe = GravityView_frontend::getInstance();
920
921
	// Solve problem when loading content via admin-ajax.php
922 1
	if( ! $fe->getGvOutputData() ) {
923
924 1
		gravityview()->log->debug( 'gv_output_data not defined; parsing content.' );
925
926 1
		$fe->parse_content();
927
	}
928
929
	// Make 100% sure that we're dealing with a properly called situation
930 1
	if( !is_a( $fe->getGvOutputData(), 'GravityView_View_Data' ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
931
932
		gravityview()->log->debug( 'gv_output_data not an object or get_view not callable.', array( 'data' => $fe->getGvOutputData() ) );
933
934
		return array();
935
	}
936
937 1
	return $fe->getGvOutputData()->get_views();
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_View_Data::get_views() has been deprecated.

This method has been deprecated.

Loading history...
938
}
939
940
/**
941
 * Get data for a specific view
942
 *
943
 * @see  GravityView_View_Data::get_view()
944
 * @return array View data with `id`, `view_id`, `form_id`, `template_id`, `atts`, `fields`, `widgets`, `form` keys.
945
 */
946
function gravityview_get_current_view_data( $view_id = 0 ) {
947
948
	$fe = GravityView_frontend::getInstance();
949
950
	// If not set, grab the current view ID
951
	if ( empty( $view_id ) ) {
952
		$view_id = $fe->get_context_view_id();
953
	}
954
955
	if ( ! $fe->getGvOutputData() ) { return array(); }
956
957
	return $fe->getGvOutputData()->get_view( $view_id );
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_View_Data::get_view() has been deprecated.

This method has been deprecated.

Loading history...
958
}
959
960
// Templates' hooks
961
function gravityview_before() {
962
	/**
963
	 * @action `gravityview/template/before` Append content to the view.
964
	 * @param object $gravityview The $gravityview object available in templates.
965
	 */
966 31
	if ( count( $args = func_get_args() ) ) {
967 29
		$gravityview = reset( $args );
968 29
		if ( $gravityview instanceof \GV\Template_Context ) {
969
			/**
970
			 * @action `gravityview/template/before` Prepend content to the view.
971
			 * @param \GV\Template_Context $gravityview The $gravityview object available in templates.
972
			 */
973 29
			do_action( 'gravityview/template/before', $gravityview );
974
975
			/**
976
			 * @deprecated Use `gravityview/template/before`
977
			 */
978 29
			return do_action( 'gravityview_before', $gravityview->view->ID );
979
		}
980
	}
981
982
	/**
983
	 * @action `gravityview_before` Prepend content to the View container `<div>`
984
	 * @deprecated Use `gravityview/template/before`.
985
	 * @param int $view_id The ID of the View being displayed
986
	 */
987 2
	do_action( 'gravityview_before', gravityview_get_view_id() );
988 2
}
989
990
function gravityview_header() {
991
	/**
992
	 * @action `gravityview/template/header` Append content to the view.
993
	 * @param object $gravityview The $gravityview object available in templates.
994
	 */
995 27
	if ( count( $args = func_get_args() ) ) {
996 25
		$gravityview = reset( $args );
997 25
		if ( $gravityview instanceof \GV\Template_Context ) {
998
			/**
999
			 * @action `gravityview/template/header` Prepend content to the view container <div>.
1000
			 * @param \GV\Template_Context $gravityview The $gravityview object available in templates.
1001
			 */
1002 25
			do_action( 'gravityview/template/header', $gravityview );
1003
1004
			/**
1005
			 * @deprecated Use `gravityview/template/header`
1006
			 */
1007 25
			return do_action( 'gravityview_header', $gravityview->view->ID );
1008
		}
1009
	}
1010
1011
	/**
1012
	 * @action `gravityview_header` Prepend content to the View container `<div>`
1013
	 * @deprecated Use `gravityview/template/header`.
1014
	 * @param int $view_id The ID of the View being displayed
1015
	 */
1016 2
	do_action( 'gravityview_header', gravityview_get_view_id() );
1017 2
}
1018
1019
function gravityview_footer() {
1020
	/**
1021
	 * @action `gravityview/template/footer` Append content to the view.
1022
	 * @param object $gravityview The $gravityview object available in templates.
1023
	 */
1024 27
	if ( count( $args = func_get_args() ) ) {
1025 25
		$gravityview = reset( $args );
1026 25
		if ( $gravityview instanceof \GV\Template_Context ) {
1027
			/**
1028
			 * @action `gravityview/template/footer` Prepend outside of the view container <div>.
1029
			 * @param \GV\Template_Context $gravityview The $gravityview object available in templates.
1030
			 */
1031 25
			do_action( 'gravityview/template/footer', $gravityview );
1032
1033
			/**
1034
			 * @deprecated Use `gravityview/template/footer`
1035
			 */
1036 25
			return do_action( 'gravityview_footer', $gravityview->view->ID );
1037
		}
1038
	}
1039
1040
	/**
1041
	 * @action `gravityview_after` Display content after a View. Used to render footer widget areas. Rendered outside the View container `<div>`
1042
	 * @deprecated Use `gravityview/template/footer`.
1043
	 * @param int $view_id The ID of the View being displayed
1044
	 */
1045 2
	do_action( 'gravityview_footer', gravityview_get_view_id() );
1046 2
}
1047
1048
function gravityview_after() {
1049 31
	if ( count( $args = func_get_args() ) ) {
1050 29
		$gravityview = reset( $args );
1051 29
		if ( $gravityview instanceof \GV\Template_Context ) {
1052
			/**
1053
			 * @action `gravityview/template/after` Append content to the view.
1054
			 * @param \GV\Template_Context $gravityview The $gravityview object available in templates.
1055
			 */
1056 29
			do_action( 'gravityview/template/after', $gravityview );
1057
1058
			/**
1059
			 * @deprecated Use `gravityview/template/after`
1060
			 */
1061 29
			do_action( 'gravityview_after', $gravityview->view->ID );
1062
1063 29
			return;
1064
		}
1065
	}
1066
1067
	/**
1068
	 * @action `gravityview_after` Append content to the View container `<div>`
1069
	 * @deprecated Use `gravityview/template/after`
1070
	 * @param int $view_id The ID of the View being displayed
1071
	 */
1072 2
	do_action( 'gravityview_after', gravityview_get_view_id() );
1073 2
}
1074
1075
/**
1076
 * Get the current View ID being rendered
1077
 *
1078
 * @global GravityView_View $gravityview_view
1079
 *
1080
 * @return int View ID, if exists. `0` if `GravityView_View` doesn't exist, like in the admin, or no View is set.
1081
 */
1082
function gravityview_get_view_id() {
1083
1084 2
	if ( ! class_exists( 'GravityView_View' ) ) {
1085
		return 0;
1086
	}
1087
1088 2
	return GravityView_View::getInstance()->getViewId();
1089
}
1090
1091
/**
1092
 * Returns the current GravityView context, or empty string if not GravityView
1093
 *
1094
 * - Returns empty string on GravityView archive pages
1095
 * - Returns empty string on archive pages containing embedded Views
1096
 * - Returns empty string for embedded Views, not 'directory'
1097
 * - Returns empty string for embedded entries (oEmbed or [gventry]), not 'single'
1098
 * - Returns 'single' when viewing a [gravityview] shortcode-embedded single entry
1099
 *
1100
 * @global GravityView_View $gravityview_view
1101
 * @deprecated since 2.0.6.2 Use `gravityview()->request`
1102
 * @return string View context "directory", "single", "edit", or empty string if not GravityView
1103
 */
1104
function gravityview_get_context() {
1105 4
	global $wp_query;
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...
1106
1107 4
	if ( isset( $wp_query ) && $wp_query->post_count > 1 ) {
1108
		return '';
1109
	}
1110
1111
	/**
1112
	 * @filter `gravityview_is_edit_entry` Whether we're currently on the Edit Entry screen \n
1113
	 * The Edit Entry functionality overrides this value.
1114
	 * @param boolean $is_edit_entry
1115
	 */
1116 4
	$is_edit_entry = apply_filters( 'gravityview_is_edit_entry', false );
1117
1118 4
	if ( $is_edit_entry ) {
1119
		return 'edit';
1120 4
	} else if ( gravityview()->request->is_entry() ) {
1121 1
		return 'single';
1122 3
	} else if ( gravityview()->request->is_view() ) {
1123 2
		return 'directory';
1124
	}
1125
1126 1
	return '';
1127
}
1128
1129
1130
/**
1131
 * Return an array of files prepared for output. Wrapper for GravityView_Field_FileUpload::get_files_array()
1132
 *
1133
 * Processes files by file type and generates unique output for each.
1134
 *
1135
 * Returns array for each file, with the following keys:
1136
 *
1137
 * `file_path` => The file path of the file, with a line break
1138
 * `html` => The file output HTML formatted
1139
 *
1140
 * @see GravityView_Field_FileUpload::get_files_array()
1141
 *
1142
 * @since  1.2
1143
 * @param  string $value    Field value passed by Gravity Forms. String of file URL, or serialized string of file URL array
1144
 * @param  string $gv_class Field class to add to the output HTML
1145
 * @since  2.0
1146
 * @param  \GV\Template_Context $context The context
1147
 * @return array           Array of file output, with `file_path` and `html` keys (see comments above)
1148
 */
1149
function gravityview_get_files_array( $value, $gv_class = '', $context = null ) {
1150
	/** @define "GRAVITYVIEW_DIR" "../" */
1151
1152 3
	if( !class_exists( 'GravityView_Field' ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
1153
		include_once( GRAVITYVIEW_DIR .'includes/fields/class-gravityview-field.php' );
1154
	}
1155
1156 3
	if( !class_exists( 'GravityView_Field_FileUpload' ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
1157
		include_once( GRAVITYVIEW_DIR .'includes/fields/class-gravityview-field-fileupload.php' );
1158
	}
1159
1160 3
	if ( is_null( $context ) ) {
1161
		_doing_it_wrong( __FUNCTION__, '2.0', 'Please pass an \GV\Template_Context object as the 3rd parameter' );
1162
	}
1163
1164 3
	return GravityView_Field_FileUpload::get_files_array( $value, $gv_class, $context );
1165
}
1166
1167
/**
1168
 * Generate a mapping link from an address
1169
 *
1170
 * The address should be plain text with new line (`\n`) or `<br />` line breaks separating sections
1171
 *
1172
 * @todo use GF's field get_export_value() instead
1173
 *
1174
 * @see https://gravityview.co/support/documentation/201608159 Read how to modify the link
1175
 * @param  string $address Address
1176
 * @return string          URL of link to map of address
1177
 */
1178
function gravityview_get_map_link( $address ) {
1179
1180
	$address_qs = str_replace( array( '<br />', "\n" ), ' ', $address ); // Replace \n with spaces
1181
	$address_qs = urlencode( $address_qs );
1182
1183
	$url = "https://maps.google.com/maps?q={$address_qs}";
1184
1185
	$link_text = esc_html__( 'Map It', 'gravityview' );
1186
1187
	$link = gravityview_get_link( $url, $link_text, 'class=map-it-link' );
1188
1189
	/**
1190
	 * @filter `gravityview_map_link` Modify the map link generated. You can use a different mapping service, for example.
1191
	 * @param[in,out]  string $link Map link
1192
	 * @param[in] string $address Address to generate link for
1193
	 * @param[in] string $url URL generated by the function
1194
	 */
1195
	$link = apply_filters( 'gravityview_map_link', $link, $address, $url );
1196
1197
	return $link;
1198
}
1199
1200
1201
/**
1202
 * Output field based on a certain html markup
1203
 *
1204
 *   markup - string to be used on a sprintf statement.
1205
 *      Use:
1206
 *         {{label}} - field label
1207
 *         {{value}} - entry field value
1208
 *         {{class}} - field class
1209
 *
1210
 *   wpautop - true will filter the value using wpautop function
1211
 *
1212
 * @since  1.1.5
1213
 * @param  array $passed_args Associative array with field data. `field` and `form` are required.
1214
 * @since  2.0
1215
 * @param  \GV\Template_Context The template context.
1216
 * @return string Field output. If empty value and hide empty is true, return empty.
1217
 */
1218
function gravityview_field_output( $passed_args, $context = null ) {
1219
	$defaults = array(
1220 28
		'entry' => null,
1221
		'field' => null,
1222
		'form' => null,
1223
		'hide_empty' => true,
1224
		'markup' => '<div id="{{ field_id }}" class="{{ class }}">{{ label }}{{ value }}</div>',
1225
		'label_markup' => '',
1226
		'wpautop' => false,
1227
		'zone_id' => null,
1228
	);
1229
1230 28
	$args = wp_parse_args( $passed_args, $defaults );
1231
1232
	/**
1233
	 * @filter `gravityview/field_output/args` Modify the args before generation begins
1234
	 * @since 1.7
1235
	 * @param array $args Associative array; `field` and `form` is required.
1236
	 * @param array $passed_args Original associative array with field data. `field` and `form` are required.
1237
	 * @since 2.0
1238
	 * @param \GV\Template_Context $context The context.
1239
	 * @deprecated
1240
	 */
1241 28
	$args = apply_filters( 'gravityview/field_output/args', $args, $passed_args, $context );
1242
1243
	/**
1244
	 * @filter `gravityview/template/field_output/context` Modify the context before generation begins.
1245
	 * @since 2.0
1246
	 * @param[in,out] \GV\Template_Context $context The context.
1247
	 * @param array $args The sanitized arguments, these should not be trusted any longer.
1248
	 * @param array $passed_args The passed arguments, these should not be trusted any longer.
1249
	 */
1250 28
	$context = apply_filters( 'gravityview/template/field_output/context', $context, $args, $passed_args );
1251
1252 28
	if ( $context instanceof \GV\Template_Context ) {
1253 26
		if ( ! $context->field || ! $context->view || ! $context->view->form ) {
1254
			gravityview()->log->error( 'Field or form are empty.', array( 'data' => array( $context->field, $context->view->form ) ) );
1255 26
			return '';
1256
		}
1257
	} else {
1258
		// @deprecated path
1259
		// Required fields.
1260 2
		if ( empty( $args['field'] ) || empty( $args['form'] ) ) {
1261
			gravityview()->log->error( 'Field or form are empty.', array( 'data' => $args ) );
1262
			return '';
1263
		}
1264
	}
1265
1266 28
	if ( $context instanceof \GV\Template_Context ) {
1267 26
		$entry = $args['entry'] ? : ( $context->entry ? $context->entry->as_entry() : array() );
1268 26
		$field = $args['field'] ? : ( $context->field ? $context->field->as_configuration() : array() );
1269 26
		$form = $args['form'] ? : ( $context->view->form ? $context->view->form->form : array() );
0 ignored issues
show
Documentation introduced by
The property $form is declared private in GV\Form. 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...
1270
	} else {
1271
		// @deprecated path
1272 2
		$entry = empty( $args['entry'] ) ? array() : $args['entry'];
1273 2
		$field = $args['field'];
1274 2
		$form = $args['form'];
1275
	}
1276
1277
	/**
1278
	 * Create the content variables for replacing.
1279
	 * @since 1.11
1280
	 */
1281
	$placeholders = array(
1282 28
		'value' => '',
1283
		'width' => '',
1284
		'width:style' => '',
1285
		'label' => '',
1286
		'label_value' => '',
1287
		'label_value:esc_attr' => '',
1288
		'label_value:data-label' => '',
1289
		'class' => '',
1290
		'field_id' => '',
1291
	);
1292
1293 28
	if ( $context instanceof \GV\Template_Context ) {
1294 26
		$placeholders['value'] = \GV\Utils::get( $args, 'value', '' );
1295
	} else {
1296
		// @deprecated path
1297 2
		$placeholders['value'] = gv_value( $entry, $field );
0 ignored issues
show
Deprecated Code introduced by
The function gv_value() has been deprecated with message: Use \GV\Field_Template::render()

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...
1298
	}
1299
1300
	// If the value is empty and we're hiding empty, return empty.
1301 28
	if ( $placeholders['value'] === '' && ! empty( $args['hide_empty'] ) ) {
1302 5
		return '';
1303
	}
1304
1305 28
	if ( $placeholders['value'] !== '' && ! empty( $args['wpautop'] ) ) {
1306 5
		$placeholders['value'] = wpautop( $placeholders['value'] );
1307
	}
1308
1309
	// Get width setting, if exists
1310 28
	$placeholders['width'] = GravityView_API::field_width( $field );
1311
1312
	// If replacing with CSS inline formatting, let's do it.
1313 28
	$placeholders['width:style'] = GravityView_API::field_width( $field, 'width:' . $placeholders['width'] . '%;' );
1314
1315
	// Grab the Class using `gv_class`
1316 28
	$placeholders['class'] = gv_class( $field, $form, $entry );
1317 28
	$placeholders['field_id'] = GravityView_API::field_html_attr_id( $field, $form, $entry );
1318
1319 28
	if ( $context instanceof \GV\Template_Context ) {
1320 26
		$placeholders['label_value'] = \GV\Utils::get( $args, 'label' );
1321
	} else {
1322
		// Default Label value
1323 2
		$placeholders['label_value'] = gv_label( $field, $entry );
0 ignored issues
show
Deprecated Code introduced by
The function gv_label() has been deprecated with message: Use \GV\Field::get_label()

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...
1324
	}
1325
1326 28
	$placeholders['label_value:data-label'] = trim( esc_attr( strip_tags( str_replace( '>&nbsp;', '>', $placeholders['label_value'] ) ) ) );
1327 28
	$placeholders['label_value:esc_attr'] = esc_attr( $placeholders['label_value'] );
1328
1329 28
	if ( empty( $placeholders['label'] ) && ! empty( $placeholders['label_value'] ) ){
1330 28
		$placeholders['label'] = '<span class="gv-field-label">{{ label_value }}</span>';
1331
	}
1332
1333
	/**
1334
	 * @filter `gravityview/field_output/pre_html` Allow Pre filtering of the HTML
1335
	 * @since 1.11
1336
	 * @param string $markup The HTML for the markup
1337
	 * @param array $args All args for the field output
1338
	 * @since 2.0
1339
	 * @param \GV\Template_Context $context The context.
1340
	 */
1341 28
	$html = apply_filters( 'gravityview/field_output/pre_html', $args['markup'], $args, $context );
1342
1343
	/**
1344
	 * @filter `gravityview/field_output/open_tag` Modify the opening tags for the template content placeholders
1345
	 * @since 1.11
1346
	 * @param string $open_tag Open tag for template content placeholders. Default: `{{`
1347
	 * @since 2.0
1348
	 * @param \GV\Template_Context $context The context.
1349
	 */
1350 28
	$open_tag = apply_filters( 'gravityview/field_output/open_tag', '{{', $args, $context );
1351
1352
	/**
1353
	 * @filter `gravityview/field_output/close_tag` Modify the closing tags for the template content placeholders
1354
	 * @since 1.11
1355
	 * @param string $close_tag Close tag for template content placeholders. Default: `}}`
1356
	 * @since 2.0
1357
	 * @param \GV\Template_Context $context The context.
1358
	 */
1359 28
	$close_tag = apply_filters( 'gravityview/field_output/close_tag', '}}', $args, $context );
1360
1361
	/**
1362
	 * Loop through each of the tags to replace and replace both `{{tag}}` and `{{ tag }}` with the values
1363
	 * @since 1.11
1364
	 */
1365 28
	foreach ( $placeholders as $tag => $value ) {
1366
1367
		// If the tag doesn't exist just skip it
1368 28
		if ( false === strpos( $html, $open_tag . $tag . $close_tag ) && false === strpos( $html, $open_tag . ' ' . $tag . ' ' . $close_tag ) ){
1369 28
			continue;
1370
		}
1371
1372
		// Array to search
1373
		$search = array(
1374 28
			$open_tag . $tag . $close_tag,
1375 28
			$open_tag . ' ' . $tag . ' ' . $close_tag,
1376
		);
1377
1378
		/**
1379
		 * `gravityview/field_output/context/{$tag}` Allow users to filter content on context
1380
		 * @since 1.11
1381
		 * @param string $value The content to be shown instead of the {{tag}} placeholder
1382
		 * @param array $args Arguments passed to the function
1383
		 * @since 2.0
1384
		 * @param \GV\Template_Context $context The context.
1385
		 */
1386 28
		$value = apply_filters( 'gravityview/field_output/context/' . $tag, $value, $args, $context );
1387
1388
		// Finally do the replace
1389 28
		$html = str_replace( $search, $value, $html );
1390
	}
1391
1392
	/**
1393
	 * @filter `gravityview_field_output` Modify field HTML output
1394
	 * @param string $html Existing HTML output
1395
	 * @param array $args Arguments passed to the function
1396
	 * @since 2.0
1397
	 * @param \GV\Template_Context $context The context.
1398
	 */
1399 28
	$html = apply_filters( 'gravityview_field_output', $html, $args, $context );
1400
1401
	/**
1402
	 * @filter `gravityview/field_output/html` Modify field HTML output
1403
	 * @param string $html Existing HTML output
1404
	 * @param array $args Arguments passed to the function
1405
	 * @since 2.0
1406
	 * @param \GV\Template_Context $context The context.
1407
	 */
1408 28
	$html = apply_filters( 'gravityview/field_output/html', $html, $args, $context );
1409
1410
	/** @since 2.0.8 Remove unused atts */
1411 28
	$html = str_replace( array( ' style=""', ' class=""', ' id=""' ), '', $html );
1412
1413 28
	return $html;
1414
}
1415