GravityView  2.5
The best, easiest way to display Gravity Forms entries on your website.
class-api.php
Go to the documentation of this file.
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 
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  public static function field_label( $field, $entry = array(), $force_show_label = false ) {
29 
31 
32  $form = $gravityview_view->getForm();
33 
34  if ( defined( 'DOING_GRAVITYVIEW_TESTS' ) && ! empty( $GLOBALS['GravityView_API_field_label_override'] ) ) {
35  /** Allow to fall through for back compatibility testing purposes. */
36  } else {
38  }
39 
40  $label = '';
41 
42  if( !empty( $field['show_label'] ) || $force_show_label ) {
43 
44  $label = $field['label'];
45 
46  // Support Gravity Forms 1.9+
47  if( class_exists( 'GF_Field' ) ) {
48 
49  $field_object = RGFormsModel::get_field( $form, $field['id'] );
50 
51  if( $field_object ) {
52 
53  $input = GFFormsModel::get_input( $field_object, $field['id'] );
54 
55  // This is a complex field, with labels on a per-input basis
56  if( $input ) {
57 
58  // Does the input have a custom label on a per-input basis? Otherwise, default label.
59  $label = ! empty( $input['customLabel'] ) ? $input['customLabel'] : $input['label'];
60 
61  } else {
62 
63  // This is a field with one label
64  $label = $field_object->get_field_label( true, $field['label'] );
65 
66  }
67 
68  }
69 
70  }
71 
72  // Use Gravity Forms label by default, but if a custom label is defined in GV, use it.
73  if ( !empty( $field['custom_label'] ) ) {
74 
75  $label = self::replace_variables( $field['custom_label'], $form, $entry );
76 
77  }
78 
79  /**
80  * @filter `gravityview_render_after_label` Append content to a field label
81  * @param[in,out] string $appended_content Content you can add after a label. Empty by default.
82  * @param[in] array $field GravityView field array
83  */
84  $label .= apply_filters( 'gravityview_render_after_label', '', $field );
85 
86  } // End $field['show_label']
87 
88  /**
89  * @filter `gravityview/template/field_label` Modify field label output
90  * @since 1.7
91  * @param[in,out] string $label Field label HTML
92  * @param[in] array $field GravityView field array
93  * @param[in] array $form Gravity Forms form array
94  * @param[in] array $entry Gravity Forms entry array
95  *
96  * @deprecated Use the context-aware version `gravityview/template/field/label`
97  */
98  $label = apply_filters( 'gravityview/template/field_label', $label, $field, $form, $entry );
99 
100  return $label;
101  }
102 
103  /**
104  * Alias for GravityView_Merge_Tags::replace_variables()
105  *
106  * @see GravityView_Merge_Tags::replace_variables() Moved in 1.8.4
107  * @since 1.22.4 - Added $nl2br, $format, $aux_data args
108  *
109  * @param string $text Text to replace variables in
110  * @param array $form GF Form array
111  * @param array $entry GF Entry array
112  * @param bool $url_encode Pass return value through `url_encode()`
113  * @param bool $esc_html Pass return value through `esc_html()`
114  * @param bool $nl2br Convert newlines to <br> HTML tags
115  * @param string $format The format requested for the location the merge is being used. Possible values: html, text or url.
116  * @param array $aux_data Additional data to be used to replace merge tags {@see https://www.gravityhelp.com/documentation/article/gform_merge_tag_data/}
117  * @return string Text with variables maybe replaced
118  */
119  public static function replace_variables( $text, $form = array(), $entry = array(), $url_encode = false, $esc_html = true, $nl2br = true, $format = 'html', $aux_data = array() ) {
120  return GravityView_Merge_Tags::replace_variables( $text, $form, $entry, $url_encode, $esc_html, $nl2br, $format, $aux_data );
121  }
122 
123  /**
124  * Get column width from the field setting
125  *
126  * @since 1.9
127  *
128  * @param array $field Array of settings for the field
129  * @param string $format Format for width. "%" (default) will return
130  *
131  * @return string|null If not empty, string in $format format. Otherwise, null.
132  */
133  public static function field_width( $field, $format = '%d%%' ) {
134 
135  $width = NULL;
136 
137  if( !empty( $field['width'] ) ) {
138  $width = absint( $field['width'] );
139 
140  // If using percentages, limit to 100%
141  if( '%d%%' === $format && $width > 100 ) {
142  $width = 100;
143  }
144 
145  $width = sprintf( $format, $width );
146  }
147 
148  return $width;
149  }
150 
151  /**
152  * Fetch Field class
153  *
154  * @access public
155  * @static
156  * @param mixed $field
157  * @return string
158  */
159  public static function field_class( $field, $form = NULL, $entry = NULL ) {
160  $classes = array();
161 
162  if( !empty( $field['custom_class'] ) ) {
163 
164  $custom_class = $field['custom_class'];
165 
166  if( !empty( $entry ) ) {
167 
168  // We want the merge tag to be formatted as a class. The merge tag may be
169  // replaced by a multiple-word value that should be output as a single class.
170  // "Office Manager" will be formatted as `.OfficeManager`, not `.Office` and `.Manager`
171  add_filter('gform_merge_tag_filter', 'sanitize_html_class');
172 
173  $custom_class = self::replace_variables( $custom_class, $form, $entry);
174 
175  // And then we want life to return to normal
176  remove_filter('gform_merge_tag_filter', 'sanitize_html_class');
177  }
178 
179  // And now we want the spaces to be handled nicely.
180  $classes[] = gravityview_sanitize_html_class( $custom_class );
181 
182  }
183 
184  if(!empty($field['id'])) {
185  if( !empty( $form ) && !empty( $form['id'] ) ) {
186  $form_id = '-'.$form['id'];
187  } else {
188  // @deprecated path. Form should always be given.
189  gravityview()->log->warning( 'GravityView_View::getInstance() legacy API called' );
191  $form_id = $gravityview_view->getFormId() ? '-'. $gravityview_view->getFormId() : '';
192  }
193 
194  $classes[] = 'gv-field'.$form_id.'-'.$field['id'];
195  }
196 
197  return esc_attr(implode(' ', $classes));
198  }
199 
200  /**
201  * Fetch Field HTML ID
202  *
203  * @since 1.11
204  *
205  * @access public
206  * @static
207  * @param array $field GravityView field array passed to gravityview_field_output()
208  * @param array $form Gravity Forms form array, if set.
209  * @param array $entry Gravity Forms entry array
210  * @return string Sanitized unique HTML `id` attribute for the field
211  */
212  public static function field_html_attr_id( $field, $form = array(), $entry = array() ) {
213  $id = $field['id'];
214 
215  if ( ! empty( $id ) ) {
216  if ( ! empty( $form ) && ! empty( $form['id'] ) ) {
217  $form_id = '-' . $form['id'];
218  } else {
219  // @deprecated path. Form should always be given.
220  gravityview()->log->warning( 'GravityView_View::getInstance() legacy API called' );
222  $form_id = $gravityview_view->getFormId() ? '-' . $gravityview_view->getFormId() : '';
223  }
224 
225  $id = 'gv-field' . $form_id . '-' . $field['id'];
226  }
227 
228  return esc_attr( $id );
229  }
230 
231 
232  /**
233  * Given an entry and a form field id, calculate the entry value for that field.
234  *
235  * @deprecated Use \GV\Field_Template::render() or the more low-level \GV\Field::get_value()
236  *
237  * @access public
238  * @param array $entry
239  * @param array $field
240  * @return null|string
241  */
242  public static function field_value( $entry, $field_settings, $format = 'html' ) {
243  gravityview()->log->notice( '\GravityView_API::field_value is deprecated. Use \GV\Field_Template::render() or \GV\Field::get_value()' );
245  }
246 
247  /**
248  * Generate an anchor tag that links to an entry.
249  *
250  * @since 1.6
251  * @see GVCommon::get_link_html()
252  *
253  * @param string $anchor_text The text or HTML inside the link
254  * @param array $entry Gravity Forms entry array
255  * @param array|string $passed_tag_atts Attributes to be added to the anchor tag, such as `title` or `rel`.
256  * @param array $field_settings Array of field settings. Optional, but passed to the `gravityview_field_entry_link` filter
257  *
258  * @since 2.0
259  * @param int $base_id The post or the view that this entry is linked from.
260  *
261  * @return string|null Returns HTML for an anchor link. Null if $entry isn't defined or is missing an ID.
262  */
263  public static function entry_link_html( $entry = array(), $anchor_text = '', $passed_tag_atts = array(), $field_settings = array(), $base_id = null ) {
264 
265  if ( empty( $entry ) || ! is_array( $entry ) || ! isset( $entry['id'] ) ) {
266  gravityview()->log->debug( 'Entry not defined; returning null', array( 'data' => $entry ) );
267  return NULL;
268  }
269 
270  $href = self::entry_link( $entry, $base_id );
271 
272  if( '' === $href ) {
273  return NULL;
274  }
275 
276  $link = gravityview_get_link( $href, $anchor_text, $passed_tag_atts );
277 
278  /**
279  * @filter `gravityview_field_entry_link` Modify the link HTML
280  * @param string $link HTML output of the link
281  * @param string $href URL of the link
282  * @param array $entry The GF entry array
283  * @param array $field_settings Settings for the particular GV field
284  */
285  $output = apply_filters( 'gravityview_field_entry_link', $link, $href, $entry, $field_settings );
286 
287  return $output;
288  }
289 
290  /**
291  * Get the "No Results" text depending on whether there were results.
292  * @param boolean $wpautop Apply wpautop() to the output?
293  *
294  * @since 2.0
295  * @param \GV\Template_Context $context The context
296  *
297  * @return string HTML of "no results" text
298  */
299  public static function no_results( $wpautop = true, $context = null ) {
300  $is_search = false;
301 
302  if ( $context instanceof \GV\Template_Context ) {
303  if ( $context->request->is_search() ) {
304  $is_search = true;
305  }
306  } else {
308 
309  if( $gravityview_view && ( $gravityview_view->curr_start || $gravityview_view->curr_end || $gravityview_view->curr_search ) ) {
310  $is_search = true;
311  }
312  }
313 
314  if ( $is_search ) {
315  $output = __( 'This search returned no results.', 'gravityview' );
316  } else {
317  $output = __( 'No entries match your request.', 'gravityview' );
318  }
319 
320  /**
321  * @filter `gravitview_no_entries_text` Modify the text displayed when there are no entries.
322  * Note: this filter is, and always has been, misspelled. This will not be fixed, since the filter is deprecated.
323  * @param string $output The existing "No Entries" text
324  * @param boolean $is_search Is the current page a search result, or just a multiple entries screen?
325  * @return string The modified text.
326  * @deprecated Use `gravityview/template/text/no_entries`
327  */
328  $output = apply_filters( 'gravitview_no_entries_text', $output, $is_search );
329 
330  /**
331  * @filter `gravityview/template/text/no_entries` Modify the text displayed when there are no entries.
332  * @since 2.0
333  * @param string $output The existing "No Entries" text
334  * @param boolean $is_search Is the current page a search result, or just a multiple entries screen?
335  * @param \GV\Template_Context $context The context.
336  * @return string The modified text.
337  */
338  $output = apply_filters( 'gravityview/template/text/no_entries', $output, $is_search, $context );
339 
340  return $wpautop ? wpautop( $output ) : $output;
341  }
342 
343  /**
344  * Generate a URL to the Directory context
345  *
346  * 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!
347  *
348  * @param int $post_id Post ID
349  * @param boolean $add_query_args Add pagination and sorting arguments
350  *
351  * @since 2.0
352  * @param \GV\Template_Context $context The context this is being used in.
353  *
354  * @return string Permalink to multiple entries view
355  */
356  public static function directory_link( $post_id = NULL, $add_query_args = true, $context = null ) {
357  global $post;
358 
359  if ( empty( $post_id ) ) {
360  // DataTables passes the Post ID
361  if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
362  $post_id = \GV\Utils::_POST( 'post_id', false );
363  } else {
364  if ( $context instanceof \GV\Template_Context ) {
365  // Shortcodes, embeds
366  if ( is_a( $post, 'WP_Post' ) ) {
367  $post_id = $post->ID;
368 
369  // Actual views
370  } else {
371  $post_id = $context->view ? $context->view->ID : false;
372  }
373  } else {
374  /** @deprecated path of execution */
376 
377  // The Post ID has been passed via the shortcode
378  if ( ! empty( $gravityview_view ) && $gravityview_view->getPostId() ) {
379  $post_id = $gravityview_view->getPostId();
380  } else {
381  // This is a GravityView post type
382  if ( GravityView_frontend::getInstance()->isGravityviewPostType() ) {
383  $post_id = isset( $gravityview_view ) ? $gravityview_view->getViewId() : $post->ID;
384  } else {
385  // This is an embedded GravityView; use the embedded post's ID as the base.
386  if ( GravityView_frontend::getInstance()->isPostHasShortcode() && is_a( $post, 'WP_Post' ) ) {
387  $post_id = $post->ID;
388  } elseif ( $gravityview_view->getViewId() ) {
389  // The GravityView has been embedded in a widget or in a template, and
390  // is not in the current content. Thus, we defer to the View's own ID.
391  $post_id = $gravityview_view->getViewId();
392  }
393  }
394  }
395  }
396  }
397  }
398 
399  // No post ID, get outta here.
400  if ( empty( $post_id ) ) {
401  return null;
402  }
403 
404  // If we've saved the permalink in memory, use it
405  // @since 1.3
406  $link = wp_cache_get( 'gv_directory_link_'.$post_id );
407 
408  if ( (int) $post_id === (int) get_option( 'page_on_front' ) ) {
409  $link = home_url();
410  }
411 
412  if ( empty( $link ) ) {
413  $link = get_permalink( $post_id );
414 
415  // If not yet saved, cache the permalink.
416  // @since 1.3
417  wp_cache_set( 'gv_directory_link_'.$post_id, $link );
418  }
419 
420  // Deal with returning to proper pagination for embedded views
421  if ( $link && $add_query_args ) {
422 
423  $args = array();
424 
425  if( $pagenum = \GV\Utils::_GET( 'pagenum' ) ) {
426  $args['pagenum'] = intval( $pagenum );
427  }
428 
429  if( $sort = \GV\Utils::_GET( 'sort' ) ) {
430  $args['sort'] = $sort;
431  $args['dir'] = \GV\Utils::_GET( 'dir' );
432  }
433 
434  $link = add_query_arg( $args, $link );
435  }
436 
437  /**
438  * @filter `gravityview_directory_link` Modify the URL to the View "directory" context
439  * @since 1.19.4
440  * @param string $link URL to the View's "directory" context (Multiple Entries screen)
441  * @param int $post_id ID of the post to link to. If the View is embedded, it is the post or page ID
442  */
443  $link = apply_filters( 'gravityview_directory_link', $link, $post_id );
444 
445  /**
446  * @filter `gravityview/view/links/directory` Modify the URL to the View "directory" context
447  * @since 2.0
448  * @param string $link URL to the View's "directory" context (Multiple Entries screen)
449  * @param \GV\Template_Context $context
450  */
451  return apply_filters( 'gravityview/view/links/directory', $link, $context );
452  }
453 
454  /**
455  * Calculate an *unique* hash for an entry based on the entry ID
456  *
457  * 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.
458  *
459  * The hashed value MUST be unique, otherwise multiple entries will share the same URL, which leads to obvious problems.
460  *
461  * @param int|string $id Entry ID to generate the hash for.
462  * @param array $entry Entry data passed to provide additional information when generating the hash. Optional - don't rely on it being available.
463  * @return string Hashed unique value for entry
464  */
465  private static function get_custom_entry_slug( $id, $entry = array() ) {
466 
467  // Generate an unique hash to use as the default value
468  $slug = substr( wp_hash( $id, 'gravityview'.$id ), 0, 8 );
469 
470  /**
471  * @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}`
472  * @param string $hash Existing hash generated by GravityView
473  * @param string $id The entry ID
474  * @param array $entry Entry data array. May be empty.
475  */
476  $slug = apply_filters( 'gravityview_entry_slug', $slug, $id, $entry );
477 
478  // Make sure we have something - use the original ID as backup.
479  if( empty( $slug ) ) {
480  $slug = $id;
481  }
482 
483  return sanitize_title( $slug );
484  }
485 
486  /**
487  * Get the entry slug for the entry. By default, it is the entry ID.
488  *
489  *
490  * @see gravityview_get_entry()
491  * @uses GravityView_API::get_custom_entry_slug() If using custom slug, gets the custom slug value
492  * @since 1.4
493  * @param int|string $id_or_string ID of the entry, or custom slug string
494  * @param array $entry Gravity Forms Entry array, optional. Used only to provide data to customize the `gravityview_entry_slug` filter
495  * @return string Unique slug ID, passed through `sanitize_title()`
496  */
497  public static function get_entry_slug( $id_or_string, $entry = array() ) {
498 
499  /**
500  * Default: use the entry ID as the unique identifier
501  */
502  $slug = $id_or_string;
503 
504  /**
505  * @filter `gravityview_custom_entry_slug` Whether to enable and use custom entry slugs.
506  * @param boolean True: Allow for slugs based on entry values. False: always use entry IDs (default)
507  */
508  $custom = apply_filters( 'gravityview_custom_entry_slug', false );
509 
510  // If we're using custom slug...
511  if ( $custom ) {
512 
513  // Get the entry hash
514  $hash = self::get_custom_entry_slug( $id_or_string, $entry );
515 
516  // Cache the slugs
517  static $cache = array();
518 
519  if ( ! isset( $cache[ $id_or_string ] ) ) {
520  global $wpdb;
521 
522  if ( version_compare( GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) ) {
523  $table = GFFormsModel::get_entry_meta_table_name();
524  $column = 'entry_id';
525  } else {
526  $table = RGFormsModel::get_lead_meta_table_name();
527  $column = 'lead_id';
528  }
529 
530  $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 ) );
531 
532  if ( $results ) {
533  $cache = array_replace( $cache, array_combine( wp_list_pluck( $results, $column ), wp_list_pluck( $results, 'meta_value' ) ) );
534  }
535 
536  if ( ! isset( $cache[ $id_or_string ] ) ) {
537  $cache[ $id_or_string ] = false;
538  }
539  }
540 
541  $value = $cache[ $id_or_string ];
542 
543  // If it does have a hash set, and the hash is expected, use it.
544  // This check allows users to change the hash structure using the
545  // gravityview_entry_hash filter and have the old hashes expire.
546  if ( empty( $value ) || $value !== $hash ) {
547  gravityview()->log->debug( 'Setting hash for entry {entry}: {hash}', array( 'entry' => $id_or_string, 'hash' => $hash ) );
548  gform_update_meta( $id_or_string, 'gravityview_unique_id', $hash, \GV\Utils::get( $entry, 'form_id' ) );
549  }
550 
551  $slug = $hash;
552 
553  unset( $value, $hash );
554  }
555 
556  return sanitize_title( $slug );
557  }
558 
559  /**
560  * If using the entry custom slug feature, make sure the new entries have the custom slug created and saved as meta
561  *
562  * Triggered by add_action( 'gform_entry_created', array( 'GravityView_API', 'entry_create_custom_slug' ), 10, 2 );
563  *
564  * @param $entry array Gravity Forms entry object
565  * @param $form array Gravity Forms form object
566  */
567  public static function entry_create_custom_slug( $entry, $form ) {
568  /**
569  * @filter `gravityview_custom_entry_slug` On entry creation, check if we are using the custom entry slug feature and update the meta
570  * @param boolean $custom Should we process the custom entry slug?
571  */
572  $custom = apply_filters( 'gravityview_custom_entry_slug', false );
573  if( $custom ) {
574  // create the gravityview_unique_id and save it
575 
576  // Get the entry hash
577  $hash = self::get_custom_entry_slug( $entry['id'], $entry );
578 
579  gravityview()->log->debug( 'Setting hash for entry {entry_id}: {hash}', array( 'entry_id' => $entry['id'], 'hash' => $hash ) );
580 
581  gform_update_meta( $entry['id'], 'gravityview_unique_id', $hash, \GV\Utils::get( $entry, 'form_id' ) );
582 
583  }
584  }
585 
586 
587 
588 
589  /**
590  * return href for single entry
591  * @param array|int $entry Entry array or entry ID
592  * @param int|null $post_id If wanting to define the parent post, pass a post ID
593  * @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}
594  * @return string Link to the entry with the directory parent slug, or empty string if embedded post or View doesn't exist
595  */
596  public static function entry_link( $entry, $post_id = NULL, $add_directory_args = true ) {
597 
598  if ( ! empty( $entry ) && ! is_array( $entry ) ) {
600  } else if( empty( $entry ) ) {
601  // @deprecated path
603  }
604 
605  // Second parameter used to be passed as $field; this makes sure it's not an array
606  if ( ! is_numeric( $post_id ) ) {
607  $post_id = NULL;
608  }
609 
610  // Get the permalink to the View
611  $directory_link = self::directory_link( $post_id, false );
612 
613  // No post ID? Get outta here.
614  if ( empty( $directory_link ) ) {
615  return '';
616  }
617 
618  $query_arg_name = \GV\Entry::get_endpoint_name();
619 
620  if ( ! empty( $entry['_multi'] ) ) {
621  $entry_slugs = array();
622  foreach ( $entry['_multi'] as $_multi ) {
623  $entry_slugs[] = self::get_entry_slug( $_multi['id'], $_multi );
624  $forms[] = $_multi['form_id'];
625  }
626  $entry_slug = implode( ',', $entry_slugs );
627  } else {
628  $entry_slug = self::get_entry_slug( $entry['id'], $entry );
629  }
630 
631  if ( get_option('permalink_structure') && !is_preview() ) {
632 
633  $args = array();
634 
635  /**
636  * Make sure the $directory_link doesn't contain any query otherwise it will break when adding the entry slug.
637  * @since 1.16.5
638  */
639  $link_parts = explode( '?', $directory_link );
640 
641  $query = !empty( $link_parts[1] ) ? '?'.$link_parts[1] : '';
642 
643  $directory_link = trailingslashit( $link_parts[0] ) . $query_arg_name . '/'. $entry_slug .'/' . $query;
644 
645  } else {
646 
647  $args = array( $query_arg_name => $entry_slug );
648  }
649 
650  /**
651  * @since 1.7.3
652  */
653  if ( $add_directory_args ) {
654 
655  if ( ! empty( $_GET['pagenum'] ) ) {
656  $args['pagenum'] = intval( $_GET['pagenum'] );
657  }
658 
659  /**
660  * @since 1.7
661  */
662  if ( $sort = \GV\Utils::_GET( 'sort' ) ) {
663  $args['sort'] = $sort;
664  $args['dir'] = \GV\Utils::_GET( 'dir' );
665  }
666 
667  }
668 
669  if( $post_id ) {
670  $passed_post = get_post( $post_id );
671  $views = \GV\View_Collection::from_post( $passed_post );
672  $has_multiple_views = $views->count() > 1;
673  } else {
674  $has_multiple_views = class_exists( 'GravityView_View_Data' ) && GravityView_View_Data::getInstance()->has_multiple_views();
675  }
676 
677  if ( $has_multiple_views ) {
678  $args['gvid'] = gravityview_get_view_id();
679  }
680 
681  return add_query_arg( $args, $directory_link );
682 
683  }
684 
685 
686 }
687 
688 
689 // inside loop functions
690 
691 /**
692  * @deprecated Use \GV\Field::get_label()
693  */
694 function gv_label( $field, $entry = NULL ) {
696 }
697 
698 function gv_class( $field, $form = NULL, $entry = array() ) {
700 }
701 
702 /**
703  * Generate a CSS class to be added to the wrapper <div> of a View
704  *
705  * @since 1.5.4
706  * @since 1.16 Added $echo parameter.
707  * @since 2.0 Added $context parameter.
708  *
709  * @param string $passed_css_class Default: `gv-container gv-container-{view id}`. If View is hidden until search, adds ` hidden`
710  * @param boolean $echo Whether to echo the output. Default: true
711  * @param \GV\Template_Context $context The template context.
712  *
713  * @return string CSS class, sanitized by gravityview_sanitize_html_class()
714  */
715 function gv_container_class( $passed_css_class = '', $echo = true, $context = null ) {
716  if ( $context instanceof \GV\Template_Context ) {
717  $hide_until_searched = false;
718  $total_entries = 0;
719  $view_id = 0;
720  if ( $context->view ) {
721  $view_id = $context->view->ID;
722  if( $context->view->settings->get( 'hide_until_searched' ) ) {
723  $hide_until_searched = ( empty( $context->entry ) && ! $context->request->is_search() );
724  }
725  }
726  if ( $context->entries ) {
727  $total_entries = $context->entries->total();
728  } else if ( $context->entry ) {
729  $total_entries = 1;
730  }
731  } else {
732  /** @deprecated legacy execution path */
733  $view_id = GravityView_View::getInstance()->getViewId();
734  $hide_until_searched = GravityView_View::getInstance()->isHideUntilSearched();
735  $total_entries = GravityView_View::getInstance()->getTotalEntries();
736  }
737 
738  $passed_css_class = trim( $passed_css_class );
739 
740  $default_css_class = ! empty( $view_id ) ? sprintf( 'gv-container gv-container-%d', $view_id ) : 'gv-container';
741 
742  if ( $hide_until_searched ) {
743  $default_css_class .= ' hidden';
744  }
745 
746  if ( 0 === $total_entries ) {
747  $default_css_class .= ' gv-container-no-results';
748  }
749 
750  $css_class = trim( $passed_css_class . ' '. $default_css_class );
751 
752  /**
753  * @filter `gravityview/render/container/class` Modify the CSS class to be added to the wrapper <div> of a View
754  * @since 1.5.4
755  * @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`
756  * @since 2.0
757  * @param \GV\Template_Context $context The context.
758  */
759  $css_class = apply_filters( 'gravityview/render/container/class', $css_class, $context );
760 
761  $css_class = gravityview_sanitize_html_class( $css_class );
762 
763  if ( $echo ) {
764  echo $css_class;
765  }
766 
767  return $css_class;
768 }
769 
770 /**
771  * @deprecated Use \GV\Field_Template::render()
772  */
773 function gv_value( $entry, $field ) {
774 
776 
777  if( $value === '' ) {
778  /**
779  * @filter `gravityview_empty_value` What to display when a field is empty
780  * @param string $value (empty string)
781  */
782  $value = apply_filters( 'gravityview_empty_value', '' );
783  }
784 
785  return $value;
786 }
787 
788 function gv_directory_link( $post = NULL, $add_pagination = true, $context = null ) {
789  return GravityView_API::directory_link( $post, $add_pagination, $context );
790 }
791 
792 function gv_entry_link( $entry, $post_id = NULL ) {
793  return GravityView_API::entry_link( $entry, $post_id );
794 }
795 
796 function gv_no_results( $wpautop = true, $context = null ) {
797  return GravityView_API::no_results( $wpautop, $context );
798 }
799 
800 /**
801  * Generate HTML for the back link from single entry view
802  * @since 1.0.1
803  * @since 2.0
804  * @param \GV\Template_Context $context The context this link is being displayed from.
805  * @return string|null If no GV post exists, null. Otherwise, HTML string of back link.
806  */
807 function gravityview_back_link( $context = null ) {
808 
809  $href = gv_directory_link( null, true, $context );
810 
811  /**
812  * @filter `gravityview_go_back_url` Modify the back link URL
813  * @since 1.17.5
814  * @see gv_directory_link() Generated the original back link
815  * @param string $href Existing label URL
816  * @deprecated Use `gravityview/template/links/back/url`
817  */
818  $href = apply_filters( 'gravityview_go_back_url', $href );
819 
820  /**
821  * @filter `gravityview/template/links/back/url` Modify the back link URL
822  * @since 2.0
823  * @see gv_directory_link() Generated the original back link
824  * @param string $href Existing label URL
825  * @param \GV\Template_Context The context.
826  */
827  $href = apply_filters( 'gravityview/template/links/back/url', $href, $context );
828 
829  if ( empty( $href ) ) {
830  return NULL;
831  }
832 
833  if ( $context instanceof \GV\Template_Context ) {
834  $view_id = $context->view->ID;
835  $view_label = $context->template->get_back_label();
836  } else {
837  /** @deprecated legacy path */
839  $view_id = $gravityview_view->getViewId();
840  $view_label = $gravityview_view->getBackLinkLabel() ? $gravityview_view->getBackLinkLabel() : false;
841  }
842 
843  /** Default */
844  $label = $view_label ? $view_label : __( '&larr; Go back', 'gravityview' );
845 
846  /**
847  * @filter `gravityview_go_back_label` Modify the back link text
848  * @since 1.0.9
849  * @param string $label Existing label text
850  * @deprecated Use `gravityview/template/links/back/label`
851  */
852  $label = apply_filters( 'gravityview_go_back_label', $label );
853 
854  /**
855  * @filter `gravityview/template/links/back/label` Modify the back link text
856  * @since 2.0
857  * @see gv_directory_link() Generated the original back link
858  * @param string $label Existing label text
859  * @param \GV\Template_Context The context.
860  */
861  $label = apply_filters( 'gravityview/template/links/back/label', $label, $context );
862 
863  /**
864  * @filter `gravityview/template/links/back/atts` Modify the attributes used on the back link anchor tag
865  * @since 2.1
866  * @param array $atts Original attributes, default: [ data-viewid => $view_id ]
867  * @param \GV\Template_Context The context.
868  */
869  $atts = apply_filters( 'gravityview/template/links/back/atts', array( 'data-viewid' => $view_id ), $context );
870 
871  $link = gravityview_get_link( $href, esc_html( $label ), $atts );
872 
873  return $link;
874 }
875 
876 /**
877  * Handle getting values for complex Gravity Forms fields
878  *
879  * If the field is complex, like a product, the field ID, for example, 11, won't exist. Instead,
880  * it will be 11.1, 11.2, and 11.3. This handles being passed 11 and 11.2 with the same function.
881  *
882  * @since 1.0.4
883  * @param array $entry GF entry array
884  * @param string $field_id [description]
885  * @param string $display_value The value generated by Gravity Forms
886  * @return string Value
887  */
889 
890  if( floatval( $field_id ) === floor( floatval( $field_id ) ) ) {
891 
892  // For the complete field value as generated by Gravity Forms
893  return $display_value;
894 
895  } else {
896 
897  // For one part of the address (City, ZIP, etc.)
898  return isset( $entry[ $field_id ] ) ? $entry[ $field_id ] : '';
899 
900  }
901 
902 }
903 
904 /**
905  * Take a passed CSV of terms and generate a linked list of terms
906  *
907  * Gravity Forms passes categories as "Name:ID" so we handle that using the ID, which
908  * is more accurate than checking the name, which is more likely to change.
909  *
910  * @param string $value Existing value
911  * @param string $taxonomy Type of term (`post_tag` or `category`)
912  * @return string CSV of linked terms
913  */
914 function gravityview_convert_value_to_term_list( $value, $taxonomy = 'post_tag' ) {
915 
916  $output = array();
917 
918  if ( is_array( $value ) ) {
919  $terms = array_filter( array_values( $value ), 'strlen' );
920  } else {
921  $terms = explode( ', ', $value );
922  }
923 
924  foreach ($terms as $term_name ) {
925 
926  // If we're processing a category,
927  if( $taxonomy === 'category' ) {
928 
929  // Use rgexplode to prevent errors if : doesn't exist
930  list( $term_name, $term_id ) = rgexplode( ':', $term_name, 2 );
931 
932  // The explode was succesful; we have the category ID
933  if( !empty( $term_id )) {
934  $term = get_term_by( 'id', $term_id, $taxonomy );
935  } else {
936  // We have to fall back to the name
937  $term = get_term_by( 'name', $term_name, $taxonomy );
938  }
939 
940  } else {
941  // Use the name of the tag to get the full term information
942  $term = get_term_by( 'name', $term_name, $taxonomy );
943  }
944 
945  // There's still a tag/category here.
946  if( $term ) {
947 
948  $term_link = get_term_link( $term, $taxonomy );
949 
950  // If there was an error, continue to the next term.
951  if ( is_wp_error( $term_link ) ) {
952  continue;
953  }
954 
955  $output[] = gravityview_get_link( $term_link, esc_html( $term->name ) );
956  }
957  }
958 
959  return implode(', ', $output );
960 }
961 
962 /**
963  * Get the links for post_tags and post_category output based on post ID
964  * @param int $post_id The ID of the post
965  * @param boolean $link Add links or no?
966  * @param string $taxonomy Taxonomy of term to fetch.
967  * @return string String with terms
968  */
969 function gravityview_get_the_term_list( $post_id, $link = true, $taxonomy = 'post_tag' ) {
970 
971  $output = get_the_term_list( $post_id, $taxonomy, NULL, ', ' );
972 
973  if( empty( $link ) ) {
974  return strip_tags( $output);
975  }
976 
977  return $output;
978 
979 }
980 
981 
982 /**
983  * Get all views processed so far for the current page load
984  *
985  * @see GravityView_View_Data::add_view()
986  * @return array Array of View data, each View data with `id`, `view_id`, `form_id`, `template_id`, `atts`, `fields`, `widgets`, `form` keys.
987  */
989 
991 
992  // Solve problem when loading content via admin-ajax.php
993  if( ! $fe->getGvOutputData() ) {
994 
995  gravityview()->log->debug( 'gv_output_data not defined; parsing content.' );
996 
997  $fe->parse_content();
998  }
999 
1000  // Make 100% sure that we're dealing with a properly called situation
1001  if( !is_a( $fe->getGvOutputData(), 'GravityView_View_Data' ) ) {
1002 
1003  gravityview()->log->debug( 'gv_output_data not an object or get_view not callable.', array( 'data' => $fe->getGvOutputData() ) );
1004 
1005  return array();
1006  }
1007 
1008  return $fe->getGvOutputData()->get_views();
1009 }
1010 
1011 /**
1012  * Get data for a specific view
1013  *
1014  * @deprecated use \GV\View API instead
1015  * @since 2.5
1016  *
1017  * @see GravityView_View_Data::get_view()
1018  * @return array View data with `id`, `view_id`, `form_id`, `template_id`, `atts`, `fields`, `widgets`, `form` keys.
1019  */
1021  if ( $view_id ) {
1022  if ( $view = \GV\View::by_id( $view_id ) ) {
1023  return $view; // implements ArrayAccess
1024  }
1025  return array();
1026  }
1027 
1029 
1030  // If not set, grab the current view ID
1031  if ( empty( $view_id ) ) {
1032  $view_id = $fe->get_context_view_id();
1033  }
1034 
1035  if ( ! $fe->getGvOutputData() ) { return array(); }
1036 
1037  return $fe->getGvOutputData()->get_view( $view_id );
1038 }
1039 
1040 // Templates' hooks
1042  /**
1043  * @action `gravityview/template/before` Append content to the view.
1044  * @param object $gravityview The $gravityview object available in templates.
1045  */
1046  if ( count( $args = func_get_args() ) ) {
1047  $gravityview = reset( $args );
1048  if ( $gravityview instanceof \GV\Template_Context ) {
1049  /**
1050  * @action `gravityview/template/before` Prepend content to the view.
1051  * @param \GV\Template_Context $gravityview The $gravityview object available in templates.
1052  */
1053  do_action( 'gravityview/template/before', $gravityview );
1054 
1055  /**
1056  * @deprecated Use `gravityview/template/before`
1057  */
1058  return do_action( 'gravityview_before', $gravityview->view->ID );
1059  }
1060  }
1061 
1062  /**
1063  * @action `gravityview_before` Prepend content to the View container `<div>`
1064  * @deprecated Use `gravityview/template/before`.
1065  * @param int $view_id The ID of the View being displayed
1066  */
1067  do_action( 'gravityview_before', gravityview_get_view_id() );
1068 }
1069 
1071  /**
1072  * @action `gravityview/template/header` Append content to the view.
1073  * @param object $gravityview The $gravityview object available in templates.
1074  */
1075  if ( count( $args = func_get_args() ) ) {
1076  $gravityview = reset( $args );
1077  if ( $gravityview instanceof \GV\Template_Context ) {
1078  /**
1079  * @action `gravityview/template/header` Prepend content to the view container <div>.
1080  * @param \GV\Template_Context $gravityview The $gravityview object available in templates.
1081  */
1082  do_action( 'gravityview/template/header', $gravityview );
1083 
1084  /**
1085  * @deprecated Use `gravityview/template/header`
1086  */
1087  return do_action( 'gravityview_header', $gravityview->view->ID );
1088  }
1089  }
1090 
1091  /**
1092  * @action `gravityview_header` Prepend content to the View container `<div>`
1093  * @deprecated Use `gravityview/template/header`.
1094  * @param int $view_id The ID of the View being displayed
1095  */
1096  do_action( 'gravityview_header', gravityview_get_view_id() );
1097 }
1098 
1100  /**
1101  * @action `gravityview/template/footer` Append content to the view.
1102  * @param object $gravityview The $gravityview object available in templates.
1103  */
1104  if ( count( $args = func_get_args() ) ) {
1105  $gravityview = reset( $args );
1106  if ( $gravityview instanceof \GV\Template_Context ) {
1107  /**
1108  * @action `gravityview/template/footer` Prepend outside of the view container <div>.
1109  * @param \GV\Template_Context $gravityview The $gravityview object available in templates.
1110  */
1111  do_action( 'gravityview/template/footer', $gravityview );
1112 
1113  /**
1114  * @deprecated Use `gravityview/template/footer`
1115  */
1116  return do_action( 'gravityview_footer', $gravityview->view->ID );
1117  }
1118  }
1119 
1120  /**
1121  * @action `gravityview_after` Display content after a View. Used to render footer widget areas. Rendered outside the View container `<div>`
1122  * @deprecated Use `gravityview/template/footer`.
1123  * @param int $view_id The ID of the View being displayed
1124  */
1125  do_action( 'gravityview_footer', gravityview_get_view_id() );
1126 }
1127 
1128 function gravityview_after() {
1129  if ( count( $args = func_get_args() ) ) {
1130  $gravityview = reset( $args );
1131  if ( $gravityview instanceof \GV\Template_Context ) {
1132  /**
1133  * @action `gravityview/template/after` Append content to the view.
1134  * @param \GV\Template_Context $gravityview The $gravityview object available in templates.
1135  */
1136  do_action( 'gravityview/template/after', $gravityview );
1137 
1138  /**
1139  * @deprecated Use `gravityview/template/after`
1140  */
1141  do_action( 'gravityview_after', $gravityview->view->ID );
1142 
1143  return;
1144  }
1145  }
1146 
1147  /**
1148  * @action `gravityview_after` Append content to the View container `<div>`
1149  * @deprecated Use `gravityview/template/after`
1150  * @param int $view_id The ID of the View being displayed
1151  */
1152  do_action( 'gravityview_after', gravityview_get_view_id() );
1153 }
1154 
1155 /**
1156  * Get the current View ID being rendered
1157  *
1158  * @global GravityView_View $gravityview_view
1159  *
1160  * @return int View ID, if exists. `0` if `GravityView_View` doesn't exist, like in the admin, or no View is set.
1161  */
1163 
1164  if ( ! class_exists( 'GravityView_View' ) ) {
1165  return 0;
1166  }
1167 
1168  return GravityView_View::getInstance()->getViewId();
1169 }
1170 
1171 /**
1172  * Returns the current GravityView context, or empty string if not GravityView
1173  *
1174  * - Returns empty string on GravityView archive pages
1175  * - Returns empty string on archive pages containing embedded Views
1176  * - Returns empty string for embedded Views, not 'directory'
1177  * - Returns empty string for embedded entries (oEmbed or [gventry]), not 'single'
1178  * - Returns 'single' when viewing a [gravityview] shortcode-embedded single entry
1179  *
1180  * @global GravityView_View $gravityview_view
1181  * @deprecated since 2.0.6.2 Use `gravityview()->request`
1182  * @return string View context "directory", "single", "edit", or empty string if not GravityView
1183  */
1185  global $wp_query;
1186 
1187  if ( isset( $wp_query ) && $wp_query->post_count > 1 ) {
1188  return '';
1189  }
1190 
1191  /**
1192  * @filter `gravityview_is_edit_entry` Whether we're currently on the Edit Entry screen \n
1193  * The Edit Entry functionality overrides this value.
1194  * @param boolean $is_edit_entry
1195  */
1196  $is_edit_entry = apply_filters( 'gravityview_is_edit_entry', false );
1197 
1198  if ( $is_edit_entry ) {
1199  return 'edit';
1200  } else if ( gravityview()->request->is_entry() ) {
1201  return 'single';
1202  } else if ( gravityview()->request->is_view() ) {
1203  return 'directory';
1204  }
1205 
1206  return '';
1207 }
1208 
1209 
1210 /**
1211  * Return an array of files prepared for output. Wrapper for GravityView_Field_FileUpload::get_files_array()
1212  *
1213  * Processes files by file type and generates unique output for each.
1214  *
1215  * Returns array for each file, with the following keys:
1216  *
1217  * `file_path` => The file path of the file, with a line break
1218  * `html` => The file output HTML formatted
1219  *
1220  * @see GravityView_Field_FileUpload::get_files_array()
1221  *
1222  * @since 1.2
1223  * @param string $value Field value passed by Gravity Forms. String of file URL, or serialized string of file URL array
1224  * @param string $gv_class Field class to add to the output HTML
1225  * @since 2.0
1226  * @param \GV\Template_Context $context The context
1227  * @return array Array of file output, with `file_path` and `html` keys (see comments above)
1228  */
1229 function gravityview_get_files_array( $value, $gv_class = '', $context = null ) {
1230  /** @define "GRAVITYVIEW_DIR" "../" */
1231 
1232  if( !class_exists( 'GravityView_Field' ) ) {
1233  include_once( GRAVITYVIEW_DIR .'includes/fields/class-gravityview-field.php' );
1234  }
1235 
1236  if( !class_exists( 'GravityView_Field_FileUpload' ) ) {
1237  include_once( GRAVITYVIEW_DIR .'includes/fields/class-gravityview-field-fileupload.php' );
1238  }
1239 
1240  if ( is_null( $context ) ) {
1241  _doing_it_wrong( __FUNCTION__, '2.0', 'Please pass an \GV\Template_Context object as the 3rd parameter' );
1242  }
1243 
1244  return GravityView_Field_FileUpload::get_files_array( $value, $gv_class, $context );
1245 }
1246 
1247 /**
1248  * Generate a mapping link from an address
1249  *
1250  * The address should be plain text with new line (`\n`) or `<br />` line breaks separating sections
1251  *
1252  * @todo use GF's field get_export_value() instead
1253  *
1254  * @see https://gravityview.co/support/documentation/201608159 Read how to modify the link
1255  * @param string $address Address
1256  * @return string URL of link to map of address
1257  */
1258 function gravityview_get_map_link( $address ) {
1259 
1260  $address_qs = str_replace( array( '<br />', "\n" ), ' ', $address ); // Replace \n with spaces
1261  $address_qs = urlencode( $address_qs );
1262 
1263  $url = "https://maps.google.com/maps?q={$address_qs}";
1264 
1265  $link_text = esc_html__( 'Map It', 'gravityview' );
1266 
1267  $link = gravityview_get_link( $url, $link_text, 'class=map-it-link' );
1268 
1269  /**
1270  * @filter `gravityview_map_link` Modify the map link generated. You can use a different mapping service, for example.
1271  * @param[in,out] string $link Map link
1272  * @param[in] string $address Address to generate link for
1273  * @param[in] string $url URL generated by the function
1274  */
1275  $link = apply_filters( 'gravityview_map_link', $link, $address, $url );
1276 
1277  return $link;
1278 }
1279 
1280 
1281 /**
1282  * Output field based on a certain html markup
1283  *
1284  * markup - string to be used on a sprintf statement.
1285  * Use:
1286  * {{label}} - field label
1287  * {{value}} - entry field value
1288  * {{class}} - field class
1289  *
1290  * wpautop - true will filter the value using wpautop function
1291  *
1292  * @since 1.1.5
1293  * @param array $passed_args Associative array with field data. `field` and `form` are required.
1294  * @since 2.0
1295  * @param \GV\Template_Context The template context.
1296  * @return string Field output. If empty value and hide empty is true, return empty.
1297  */
1298 function gravityview_field_output( $passed_args, $context = null ) {
1299  $defaults = array(
1300  'entry' => null,
1301  'field' => null,
1302  'form' => null,
1303  'hide_empty' => true,
1304  'markup' => '<div id="{{ field_id }}" class="{{ class }}">{{ label }}{{ value }}</div>',
1305  'label_markup' => '',
1306  'wpautop' => false,
1307  'zone_id' => null,
1308  );
1309 
1310  $args = wp_parse_args( $passed_args, $defaults );
1311 
1312  /**
1313  * @filter `gravityview/field_output/args` Modify the args before generation begins
1314  * @since 1.7
1315  * @param array $args Associative array; `field` and `form` is required.
1316  * @param array $passed_args Original associative array with field data. `field` and `form` are required.
1317  * @since 2.0
1318  * @param \GV\Template_Context $context The context.
1319  * @deprecated
1320  */
1321  $args = apply_filters( 'gravityview/field_output/args', $args, $passed_args, $context );
1322 
1323  /**
1324  * @filter `gravityview/template/field_output/context` Modify the context before generation begins.
1325  * @since 2.0
1326  * @param[in,out] \GV\Template_Context $context The context.
1327  * @param array $args The sanitized arguments, these should not be trusted any longer.
1328  * @param array $passed_args The passed arguments, these should not be trusted any longer.
1329  */
1330  $context = apply_filters( 'gravityview/template/field_output/context', $context, $args, $passed_args );
1331 
1332  if ( $context instanceof \GV\Template_Context ) {
1333  if ( ! $context->field || ! $context->view || ! $context->view->form ) {
1334  gravityview()->log->error( 'Field or form are empty.', array( 'data' => array( $context->field, $context->view->form ) ) );
1335  return '';
1336  }
1337  } else {
1338  // @deprecated path
1339  // Required fields.
1340  if ( empty( $args['field'] ) || empty( $args['form'] ) ) {
1341  gravityview()->log->error( 'Field or form are empty.', array( 'data' => $args ) );
1342  return '';
1343  }
1344  }
1345 
1346  if ( $context instanceof \GV\Template_Context ) {
1347  $entry = $args['entry'] ? : ( $context->entry ? $context->entry->as_entry() : array() );
1348  $field = $args['field'] ? : ( $context->field ? $context->field->as_configuration() : array() );
1349  $form = $args['form'] ? : ( $context->view->form ? $context->view->form->form : array() );
1350  } else {
1351  // @deprecated path
1352  $entry = empty( $args['entry'] ) ? array() : $args['entry'];
1353  $field = $args['field'];
1354  $form = $args['form'];
1355  }
1356 
1357  /**
1358  * Create the content variables for replacing.
1359  * @since 1.11
1360  */
1361  $placeholders = array(
1362  'value' => '',
1363  'width' => '',
1364  'width:style' => '',
1365  'label' => '',
1366  'label_value' => '',
1367  'label_value:esc_attr' => '',
1368  'label_value:data-label' => '',
1369  'class' => '',
1370  'field_id' => '',
1371  );
1372 
1373  if ( $context instanceof \GV\Template_Context ) {
1374  $placeholders['value'] = \GV\Utils::get( $args, 'value', '' );
1375  } else {
1376  // @deprecated path
1377  $placeholders['value'] = gv_value( $entry, $field );
1378  }
1379 
1380  // If the value is empty and we're hiding empty, return empty.
1381  if ( $placeholders['value'] === '' && ! empty( $args['hide_empty'] ) ) {
1382  return '';
1383  }
1384 
1385  if ( $placeholders['value'] !== '' && ! empty( $args['wpautop'] ) ) {
1386  $placeholders['value'] = wpautop( $placeholders['value'] );
1387  }
1388 
1389  // Get width setting, if exists
1390  $placeholders['width'] = GravityView_API::field_width( $field );
1391 
1392  // If replacing with CSS inline formatting, let's do it.
1393  $placeholders['width:style'] = GravityView_API::field_width( $field, 'width:' . $placeholders['width'] . '%;' );
1394 
1395  // Grab the Class using `gv_class`
1396  $placeholders['class'] = gv_class( $field, $form, $entry );
1397  $placeholders['field_id'] = GravityView_API::field_html_attr_id( $field, $form, $entry );
1398 
1399  if ( $context instanceof \GV\Template_Context ) {
1400  $placeholders['label_value'] = \GV\Utils::get( $args, 'label' );
1401  } else {
1402  // Default Label value
1403  $placeholders['label_value'] = gv_label( $field, $entry );
1404  }
1405 
1406  $placeholders['label_value:data-label'] = trim( esc_attr( strip_tags( str_replace( '>&nbsp;', '>', $placeholders['label_value'] ) ) ) );
1407  $placeholders['label_value:esc_attr'] = esc_attr( $placeholders['label_value'] );
1408 
1409  if ( empty( $placeholders['label'] ) && ! empty( $placeholders['label_value'] ) ){
1410  $placeholders['label'] = '<span class="gv-field-label">{{ label_value }}</span>';
1411  }
1412 
1413  /**
1414  * @filter `gravityview/field_output/pre_html` Allow Pre filtering of the HTML
1415  * @since 1.11
1416  * @param string $markup The HTML for the markup
1417  * @param array $args All args for the field output
1418  * @since 2.0
1419  * @param \GV\Template_Context $context The context.
1420  */
1421  $html = apply_filters( 'gravityview/field_output/pre_html', $args['markup'], $args, $context );
1422 
1423  /**
1424  * @filter `gravityview/field_output/open_tag` Modify the opening tags for the template content placeholders
1425  * @since 1.11
1426  * @param string $open_tag Open tag for template content placeholders. Default: `{{`
1427  * @since 2.0
1428  * @param \GV\Template_Context $context The context.
1429  */
1430  $open_tag = apply_filters( 'gravityview/field_output/open_tag', '{{', $args, $context );
1431 
1432  /**
1433  * @filter `gravityview/field_output/close_tag` Modify the closing tags for the template content placeholders
1434  * @since 1.11
1435  * @param string $close_tag Close tag for template content placeholders. Default: `}}`
1436  * @since 2.0
1437  * @param \GV\Template_Context $context The context.
1438  */
1439  $close_tag = apply_filters( 'gravityview/field_output/close_tag', '}}', $args, $context );
1440 
1441  /**
1442  * Loop through each of the tags to replace and replace both `{{tag}}` and `{{ tag }}` with the values
1443  * @since 1.11
1444  */
1445  foreach ( $placeholders as $tag => $value ) {
1446 
1447  // If the tag doesn't exist just skip it
1448  if ( false === strpos( $html, $open_tag . $tag . $close_tag ) && false === strpos( $html, $open_tag . ' ' . $tag . ' ' . $close_tag ) ){
1449  continue;
1450  }
1451 
1452  // Array to search
1453  $search = array(
1454  $open_tag . $tag . $close_tag,
1455  $open_tag . ' ' . $tag . ' ' . $close_tag,
1456  );
1457 
1458  /**
1459  * `gravityview/field_output/context/{$tag}` Allow users to filter content on context
1460  * @since 1.11
1461  * @param string $value The content to be shown instead of the {{tag}} placeholder
1462  * @param array $args Arguments passed to the function
1463  * @since 2.0
1464  * @param \GV\Template_Context $context The context.
1465  */
1466  $value = apply_filters( 'gravityview/field_output/context/' . $tag, $value, $args, $context );
1467 
1468  // Finally do the replace
1469  $html = str_replace( $search, $value, $html );
1470  }
1471 
1472  /**
1473  * @filter `gravityview_field_output` Modify field HTML output
1474  * @param string $html Existing HTML output
1475  * @param array $args Arguments passed to the function
1476  * @since 2.0
1477  * @param \GV\Template_Context $context The context.
1478  */
1479  $html = apply_filters( 'gravityview_field_output', $html, $args, $context );
1480 
1481  /**
1482  * @filter `gravityview/field_output/html` Modify field HTML output
1483  * @param string $html Existing HTML output
1484  * @param array $args Arguments passed to the function
1485  * @since 2.0
1486  * @param \GV\Template_Context $context The context.
1487  */
1488  $html = apply_filters( 'gravityview/field_output/html', $html, $args, $context );
1489 
1490  /** @since 2.0.8 Remove unused atts */
1491  $html = str_replace( array( ' style=""', ' class=""', ' id=""' ), '', $html );
1492 
1493  return $html;
1494 }
gravityview_get_view_id()
Get the current View ID being rendered.
Definition: class-api.php:1162
const GRAVITYVIEW_DIR
"GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory, with trailing slash ...
Definition: gravityview.php:40
$url
Definition: post_image.php:25
gv_value( $entry, $field)
Definition: class-api.php:773
gv_no_results( $wpautop=true, $context=null)
Definition: class-api.php:796
static no_results( $wpautop=true, $context=null)
Get the "No Results" text depending on whether there were results.
Definition: class-api.php:299
static _GET( $name, $default=null)
Grab a value from the _GET superglobal or default.
$forms
Definition: data-source.php:19
gravityview_get_field_value( $entry, $field_id, $display_value)
Handle getting values for complex Gravity Forms fields.
Definition: class-api.php:888
static getInstance( $passed_post=NULL)
gravityview_get_files_array( $value, $gv_class='', $context=null)
Return an array of files prepared for output.
Definition: class-api.php:1229
gv_directory_link( $post=NULL, $add_pagination=true, $context=null)
Definition: class-api.php:788
gravityview_get_the_term_list( $post_id, $link=true, $taxonomy='post_tag')
Get the links for post_tags and post_category output based on post ID.
Definition: class-api.php:969
gravityview_after()
Definition: class-api.php:1128
static getInstance( $passed_post=NULL)
Definition: class-data.php:120
gravityview_get_map_link( $address)
Generate a mapping link from an address.
Definition: class-api.php:1258
if(gv_empty( $field['value'], false, false)) $format
$display_value
gravityview_footer()
Definition: class-api.php:1099
static get_entry( $entry_slug, $force_allow_ids=false, $check_entry_display=true)
Return a single entry object.
gravityview_get_current_view_data( $view_id=0)
Get data for a specific view.
Definition: class-api.php:1020
$field_settings['content']
Definition: custom.php:27
static replace_variables( $text, $form=array(), $entry=array(), $url_encode=false, $esc_html=true, $nl2br=true, $format='html', $aux_data=array())
Alias for GFCommon::replace_variables()
gravityview_get_link( $href='', $anchor_text='', $atts=array())
Generate an HTML anchor tag with a list of supported attributes.
static from_post(\WP_Post $post)
Get a list of objects inside the supplied .
gravityview()
Definition: _stubs.php:26
GravityView_API_field_value( $entry, $field_settings, $format)
The old function does a bit too much, not only does it retrieve the value for a field, but it also renders some output.
Definition: _mocks.php:144
get( $key, $default=null)
Retrieve a setting.
static get_custom_entry_slug( $id, $entry=array())
Calculate an unique hash for an entry based on the entry ID.
Definition: class-api.php:465
static entry_create_custom_slug( $entry, $form)
If using the entry custom slug feature, make sure the new entries have the custom slug created and sa...
Definition: class-api.php:567
gravityview_back_link( $context=null)
Generate HTML for the back link from single entry view.
Definition: class-api.php:807
static directory_link( $post_id=NULL, $add_query_args=true, $context=null)
Generate a URL to the Directory context.
Definition: class-api.php:356
gv_container_class( $passed_css_class='', $echo=true, $context=null)
Generate a CSS class to be added to the wrapper of a View.
Definition: class-api.php:715
$link
static get_endpoint_name()
Return the endpoint name for a single Entry.
static field_html_attr_id( $field, $form=array(), $entry=array())
Fetch Field HTML ID.
Definition: class-api.php:212
static entry_link_html( $entry=array(), $anchor_text='', $passed_tag_atts=array(), $field_settings=array(), $base_id=null)
Generate an anchor tag that links to an entry.
Definition: class-api.php:263
static field_value( $entry, $field_settings, $format='html')
Given an entry and a form field id, calculate the entry value for that field.
Definition: class-api.php:242
gravityview_header()
Definition: class-api.php:1070
static entry_link( $entry, $post_id=NULL, $add_directory_args=true)
return href for single entry
Definition: class-api.php:596
$field_id
Definition: time.php:17
gravityview_convert_value_to_term_list( $value, $taxonomy='post_tag')
Take a passed CSV of terms and generate a linked list of terms.
Definition: class-api.php:914
static field_width( $field, $format='%d%%')
Get column width from the field setting.
Definition: class-api.php:133
gv_label( $field, $entry=NULL)
Definition: class-api.php:694
static replace_variables( $text, $form=array(), $entry=array(), $url_encode=false, $esc_html=true, $nl2br=true, $format='html', $aux_data=array())
Alias for GravityView_Merge_Tags::replace_variables()
Definition: class-api.php:119
gv_class( $field, $form=NULL, $entry=array())
Definition: class-api.php:698
if(empty( $created_by)) $form_id
GravityView_API_field_label( $form, $field_settings, $entry, $force_show_label=false)
Mock out the ::field_label method.
Definition: _mocks.php:214
static get_entry_slug( $id_or_string, $entry=array())
Get the entry slug for the entry.
Definition: class-api.php:497
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
global $post
gv_entry_link( $entry, $post_id=NULL)
Definition: class-api.php:792
gravityview_get_context()
Returns the current GravityView context, or empty string if not GravityView.
Definition: class-api.php:1184
static field_class( $field, $form=NULL, $entry=NULL)
Fetch Field class.
Definition: class-api.php:159
$entry_slug
Definition: notes.php:30
gravityview_field_output( $passed_args, $context=null)
Output field based on a certain html markup.
Definition: class-api.php:1298
$entry
Definition: notes.php:27
gravityview_before()
Definition: class-api.php:1041
$field
Definition: gquiz_grade.php:11
static _POST( $name, $default=null)
Grab a value from the _POST superglobal or default.
static field_label( $field, $entry=array(), $force_show_label=false)
Fetch Field Label.
Definition: class-api.php:28
static getInstance()
Get the one true instantiated self.
gravityview_get_current_views()
Get all views processed so far for the current page load.
Definition: class-api.php:988