GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
_mocks.php
Go to the documentation of this file.
1 <?php
2 namespace GV\Mocks;
3 
4 /**
5  * This file contains mock code for deprecated functions.
6  */
7 
8 /**
9  * @see \GravityView_View_Data::add_view
10  * @internal
11  * @since 2.0
12  *
13  * @return array|false The old array data, or false on error.
14  */
15 function GravityView_View_Data_add_view( $view_id, $atts, $_this ) {
16  /** Handle array of IDs. */
17  if ( is_array( $view_id ) ) {
18  foreach ( $view_id as $id ) {
19  call_user_func( __FUNCTION__, $id, $atts, $_this );
20  }
21 
22  if ( ! $_this->views->count() ) {
23  return array();
24  }
25 
26  return array_combine(
27  array_map( function( $view ) { return $view->ID; }, $_this->views->all() ),
28  array_map( function( $view ) { return $view->as_data(); }, $_this->views->all() )
29  );
30  }
31 
32  /** View has been set already. */
33  if ( $view = $_this->views->get( $view_id ) ) {
34  do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; View #%s already exists.', $view_id ) );
35  return $view->as_data();
36  }
37 
38  $view = \GV\View::by_id( $view_id );
39  if ( ! $view ) {
40  do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; View #%s does not exist.', $view_id ) );
41  return false;
42  }
43 
44  /** Doesn't have a connected form. */
45  if ( ! $view->form ) {
46  do_action( 'gravityview_log_debug', sprintf( 'GravityView_View_Data[add_view] Returning; Post ID #%s does not have a connected form.', $view_id ) );
47  return false;
48  }
49 
50  /** Update the settings */
51  if ( is_array( $atts ) ) {
52  $view->settings->update( $atts );
53  }
54 
55  $_this->views->add( $view );
56 
57  return $view->as_data();
58 }
59 
60 /**
61  * @see \GravityView_frontend::get_view_entries
62  * @internal
63  * @since 2.0
64  *
65  * @return array The old associative array data as returned by
66  * \GravityView_frontend::get_view_entries(), the paging parameters
67  * and a total count of all entries.
68  */
69 function GravityView_frontend_get_view_entries( $args, $form_id, $parameters, $count ) {
71 
72  /**
73  * Kick off all advanced filters.
74  *
75  * Parameters and criteria are pretty much the same thing here, just
76  * different naming, where `$parameters` are the initial parameters
77  * calculated for hte view, and `$criteria` are the filtered ones
78  * retrieved via \GVCommon::calculate_get_entries_criteria()
79  */
81 
82  do_action( 'gravityview_log_debug', '[gravityview_get_entries] Final Parameters', $criteria );
83 
84  /** ...and all the (now deprecated) filters that usually follow `gravityview_get_entries` */
85 
86  /**
87  * @deprecated
88  * Do not use this filter anymore.
89  */
90  $entries = apply_filters_ref_array( 'gravityview_before_get_entries', array( null, $criteria, $parameters, &$count ) );
91 
92  if ( ! is_null( $entries ) ) {
93  /**
94  * We've been given an entries result that we can return,
95  * just set the paging and we're good to go.
96  */
97  $paging = \GV\Utils::get( $parameters, 'paging' );
98  } else {
99  $entries = new \GV\Entry_Collection();
100  if ( $view = \GV\View::by_id( \GV\Utils::get( $args, 'id' ) ) ) {
101  $view->settings->update( $args );
102  $entries = $view->get_entries( gravityview()->request );
103  }
104 
105  $page = \GV\Utils::get( $parameters['paging'], 'current_page' ) ?
106  : ( ( ( $parameters['paging']['offset'] - $view->settings->get( 'offset' ) ) / $parameters['paging']['page_size'] ) + 1 );
107 
108  /** Set paging, count and unwrap the entries. */
109  $paging = array(
110  'offset' => ( $page - 1 ) * $view->settings->get( 'page_size' ),
111  'page_size' => $view->settings->get( 'page_size' ),
112  );
113  /**
114  * GF_Query does not subtract the offset, we have to subtract it ourselves.
115  */
116  $count = $entries->total() - ( gravityview()->plugin->supports( \GV\Plugin::FEATURE_GFQUERY ) ? $view->settings->get( 'offset' ) : 0 );
117  $entries = array_map( function( $e ) { return $e->as_entry(); }, $entries->all() );
118  }
119 
120  /** Just one more filter, for compatibility's sake! */
121 
122  /**
123  * @deprecated
124  * Do not use this filter anymore.
125  */
126  $entries = apply_filters_ref_array( 'gravityview_entries', array( $entries, $criteria, $parameters, &$count ) );
127 
128  return array( $entries, $paging, $count );
129 }
130 
131 /**
132  * The old function does a bit too much, not only does it retrieve
133  * the value for a field, but it also renders some output. We are
134  * stubbing the plain value part of it, the rendering will follow once
135  * our field renderers are ready.
136  *
137  * @see \GravityView_API::field_value
138  * @deprecated Use \GV\Field_Template::render()
139  * @internal
140  * @since 2.0
141  *
142  * @return null|string The value of a field in an entry.
143  */
145  if ( empty( $entry['form_id'] ) || empty( $field_settings['id'] ) ) {
146  gravityview()->log->error( 'No entry or field_settings[id] supplied', array( 'data' => array( func_get_args() ) ) );
147  return null;
148  }
149 
150  if ( ! empty( $entry['_multi'] ) && ! empty( $field_settings['form_id'] ) && ! empty( $entry['_multi'][ $field_settings['form_id'] ] ) ) {
151  $multientry = \GV\Multi_Entry::from_entries( array_map( '\GV\GF_Entry::from_entry', $entry['_multi'] ) );
152  $entry = $entry['_multi'][ $field_settings['form_id'] ];
153  }
154 
155  if ( empty( $entry['id'] ) || ! $entry = \GV\GF_Entry::by_id( $entry['id'] ) ) {
156  gravityview()->log->error( 'Invalid \GV\GF_Entry supplied', array( 'data' => $entry ) );
157  return null;
158  }
159 
160  /**
161  * Determine the source backend.
162  *
163  * Fields with a numeric ID are Gravity Forms ones.
164  */
165  $source = is_numeric( $field_settings['id'] ) ? \GV\Source::BACKEND_GRAVITYFORMS : \GV\Source::BACKEND_INTERNAL;;
166 
167  /** Initialize the future field. */
168  switch ( $source ):
169  /** The Gravity Forms backend. */
170  case \GV\Source::BACKEND_GRAVITYFORMS:
171  if ( ! $form = \GV\GF_Form::by_id( $entry['form_id'] ) ) {
172  gravityview()->log->error( 'No form Gravity Form found for entry', array( 'data' => $entry ) );
173  return null;
174  }
175 
176  if ( ! $field = $form::get_field( $form, $field_settings['id'] ) ) {
177  return null;
178  }
179 
180  break;
181 
182  /** Our internal backend. */
183  case \GV\Source::BACKEND_INTERNAL:
184  if ( ! $field = \GV\Internal_Source::get_field( $field_settings['id'] ) ) {
185  return null;
186  }
187 
188  break;
189 
190  /** An unidentified backend. */
191  default:
192  gravityview()->log->error( 'Could not determine source for entry', array( 'data' => array( func_get_args() ) ) );
193  return null;
194  endswitch;
195 
196  /** Add the field settings. */
197  $field->update_configuration( $field_settings );
198 
199  $renderer = new \GV\Field_Renderer();
200  return $renderer->render( $field, gravityview()->views->get(), $source == \GV\Source::BACKEND_GRAVITYFORMS ? $form : null, isset( $multientry ) ? $multientry : $entry, gravityview()->request );
201 }
202 
203 /**
204  * Mock out the \GravityView_API::field_label method
205  *
206  * Uses the new \GV\Field::get_label methods
207  *
208  * @see \GravityView_API::field_label
209  * @internal
210  * @since 2.0
211  *
212  * @return string The label of a field in an entry.
213  */
214 function GravityView_API_field_label( $form, $field_settings, $entry, $force_show_label = false ) {
215 
216  /** A bail condition. */
217  $bail = function( $label, $field_settings, $entry, $force_show_label, $form ) {
218  if ( ! empty( $field_settings['show_label'] ) || $force_show_label ) {
219 
220  $label = isset( $field_settings['label'] ) ? $field_settings['label'] : '';
221 
222  // Use Gravity Forms label by default, but if a custom label is defined in GV, use it.
223  if ( ! empty( $field_settings['custom_label'] ) ) {
224  $label = \GravityView_API::replace_variables( $field_settings['custom_label'], $form, $entry );
225  }
226 
227  /**
228  * @filter `gravityview_render_after_label` Append content to a field label
229  * @param string $appended_content Content you can add after a label. Empty by default.
230  * @param array $field GravityView field array
231  */
232  $label .= apply_filters( 'gravityview_render_after_label', '', $field_settings );
233  }
234 
235  /**
236  * @filter `gravityview/template/field_label` Modify field label output
237  * @since 1.7
238  * @param string $label Field label HTML
239  * @param array $field GravityView field array
240  * @param array $form Gravity Forms form array
241  * @param array $entry Gravity Forms entry array
242  */
243  $label = apply_filters( 'gravityview/template/field_label', $label, $field_settings, $form, $entry );
244 
245  return $label;
246  };
247 
248  $label = '';
249 
250  if ( ! empty( $entry['_multi'] ) && ! empty( $field_settings['form_id'] ) && ! empty( $entry['_multi'][ $field_settings['form_id'] ] ) ) {
251  $entry = $entry['_multi'][ $field_settings['form_id'] ];
252  if ( $_form = \GV\GF_Form::by_id( $field_settings['form_id'] ) ) {
253  $form = $_form->form;
254  }
255  }
256 
257  if ( empty( $entry['form_id'] ) || empty( $field_settings['id'] ) ) {
258  gravityview()->log->error( 'No entry or field_settings[id] supplied', array( 'data' => array( func_get_args() ) ) );
259  return $bail( $label, $field_settings, $entry, $force_show_label, $form );
260  }
261 
262  if ( empty( $entry['id'] ) || ! $gv_entry = \GV\GF_Entry::by_id( $entry['id'] ) ) {
263  gravityview()->log->error( 'Invalid \GV\GF_Entry supplied', array( 'data' => $entry ) );
264  return $bail( $label, $field_settings, $entry, $force_show_label, $form );
265  }
266 
267  $entry = $gv_entry;
268 
269  /**
270  * Determine the source backend.
271  *
272  * Fields with a numeric ID are Gravity Forms ones.
273  */
274  $source = is_numeric( $field_settings['id'] ) ? \GV\Source::BACKEND_GRAVITYFORMS : \GV\Source::BACKEND_INTERNAL;
275 
276  /** Initialize the future field. */
277  switch ( $source ):
278  /** The Gravity Forms backend. */
279  case \GV\Source::BACKEND_GRAVITYFORMS:
280  if ( ! $gf_form = \GV\GF_Form::by_id( $entry['form_id'] ) ) {
281  gravityview()->log->error( 'No form Gravity Form found for entry', array( 'data' => $entry ) );
282  return $bail( $label, $field_settings, $entry->as_entry(), $force_show_label, $form );
283  }
284 
285  if ( ! $field = $gf_form::get_field( $gf_form, $field_settings['id'] ) ) {
286  gravityview()->log->error( 'No field found for specified form and field ID #{field_id}', array( 'field_id' => $field_settings['id'], 'data' => $form ) );
287  return $bail( $label, $field_settings, $entry->as_entry(), $force_show_label, $gf_form->form );
288  }
289  if ( empty( $field_settings['show_label'] ) ) {
290  /** The label never wins... */
291  $field_settings['label'] = '';
292  }
293 
294  break;
295 
296  /** Our internal backend. */
297  case \GV\Source::BACKEND_INTERNAL:
298  if ( ! $field = \GV\Internal_Source::get_field( $field_settings['id'] ) ) {
299  return $bail( $label, $field_settings, $entry->as_entry(), $force_show_label, $form );
300  }
301  break;
302 
303  /** An unidentified backend. */
304  default:
305  gravityview()->log->error( 'Could not determine source for entry. Using empty field.', array( 'data' => array( func_get_args() ) ) );
306  $field = new \GV\Field();
307  break;
308  endswitch;
309 
310  if( $force_show_label ) {
311  $field_settings['show_label'] = '1';
312  }
313 
314  /** Add the field settings. */
315  $field->update_configuration( $field_settings );
316 
317  if ( ! empty( $field->show_label ) ) {
318 
319  $label = $field->get_label( null, isset( $gf_form ) ? $gf_form : null, $entry );
320 
321  /**
322  * @filter `gravityview_render_after_label` Append content to a field label
323  * @param string $appended_content Content you can add after a label. Empty by default.
324  * @param array $field GravityView field array
325  */
326  $label .= apply_filters( 'gravityview_render_after_label', '', $field->as_configuration() );
327 
328  }
329 
330  /**
331  * @filter `gravityview/template/field_label` Modify field label output
332  * @since 1.7
333  * @param string $label Field label HTML
334  * @param array $field GravityView field array
335  * @param array $form Gravity Forms form array
336  * @param array $entry Gravity Forms entry array
337  */
338  return apply_filters( 'gravityview/template/field_label', $label, $field->as_configuration(), isset( $gf_form ) ? $gf_form->form : $form, $entry->as_entry() );
339 }
340 
341 
342 /**
343  * A manager of legacy global states and contexts.
344  *
345  * Handles mocking of:
346  * - \GravityView_View_Data
347  * - \GravityView_View
348  * - \GravityView_frontend
349  *
350  * Allows us to set a specific state globally using the old
351  * containers, then reset it. Useful for legacy code that keeps
352  * on depending on these variables.
353  *
354  * Some examples right now include template files, utility functions,
355  * some actions and filters that expect the old contexts to be set.
356  */
357 final class Legacy_Context {
358  private static $stack = array();
359 
360  /**
361  * Set the state depending on the provided configuration.
362  *
363  * Saves current global state and context.
364  *
365  * Configuration keys:
366  *
367  * - \GV\View view: sets \GravityView_View::atts, \GravityView_View::view_id,
368  * \GravityView_View::back_link_label
369  * \GravityView_frontend::context_view_id,
370  * \GravityView_View::form, \GravityView_View::form_id
371  * - \GV\Field field: sets \GravityView_View::_current_field, \GravityView_View::field_data,
372  * - \GV\Entry entry: sets \GravityView_View::_current_entry, \GravityView_frontend::single_entry,
373  * \GravityView_frontend::entry
374  * - \WP_Post post: sets \GravityView_View::post_id, \GravityView_frontend::post_id,
375  * \GravityView_frontend::is_gravityview_post_type,
376  * \GravityView_frontend::post_has_shortcode
377  * - array paging: sets \GravityView_View::paging
378  * - array sorting: sets \GravityView_View::sorting
379  * - array template: sets \GravityView_View::template_part_slug, \GravityView_View::template_part_name
380  *
381  * - boolean in_the_loop sets $wp_actions['loop_start'] and $wp_query::in_the_loop
382  *
383  * also:
384  *
385  * - \GV\Request request: sets \GravityView_frontend::is_search, \GravityView_frontend::single_entry,
386  * \GravityView_View::context, \GravityView_frontend::entry
387  *
388  * - \GV\View_Collection views: sets \GravityView_View_Data::views
389  * - \GV\Field_Collection fields: sets \GravityView_View::fields
390  * - \GV\Entry_Collection entries: sets \GravityView_View::entries, \GravityView_View::total_entries
391  *
392  * and automagically:
393  *
394  * - \GravityView_View data: sets \GravityView_frontend::gv_output_data
395  *
396  * @param array $configuration The configuration.
397  *
398  * @return void
399  */
400  public static function push( $configuration ) {
401  array_push( self::$stack, self::freeze() );
402  self::load( $configuration );
403  }
404 
405  /**
406  * Restores last saved state and context.
407  *
408  * @return void
409  */
410  public static function pop() {
411  self::thaw( array_pop( self::$stack ) );
412  }
413 
414  /**
415  * Serializes the current configuration as needed.
416  *
417  * @return array The configuration.
418  */
419  public static function freeze() {
420  global $wp_actions, $wp_query;
421 
422  return array(
423  '\GravityView_View::atts' => \GravityView_View::getInstance()->getAtts(),
424  '\GravityView_View::view_id' => \GravityView_View::getInstance()->getViewId(),
425  '\GravityView_View::back_link_label' => \GravityView_View::getInstance()->getBackLinkLabel( false ),
426  '\GravityView_View_Data::views' => \GravityView_View_Data::getInstance()->views,
427  '\GravityView_View::entries' => \GravityView_View::getInstance()->getEntries(),
428  '\GravityView_View::form' => \GravityView_View::getInstance()->getForm(),
429  '\GravityView_View::form_id' => \GravityView_View::getInstance()->getFormId(),
430  '\GravityView_View::context' => \GravityView_View::getInstance()->getContext(),
431  '\GravityView_View::total_entries' => \GravityView_View::getInstance()->getTotalEntries(),
432  '\GravityView_View::post_id' => \GravityView_View::getInstance()->getPostId(),
433  '\GravityView_View::hide_until_searched' => \GravityView_View::getInstance()->isHideUntilSearched(),
434  '\GravityView_frontend::post_id' => \GravityView_frontend::getInstance()->getPostId(),
435  '\GravityView_frontend::context_view_id' => \GravityView_frontend::getInstance()->get_context_view_id(),
436  '\GravityView_frontend::is_gravityview_post_type' => \GravityView_frontend::getInstance()->isGravityviewPostType(),
437  '\GravityView_frontend::post_has_shortcode' => \GravityView_frontend::getInstance()->isPostHasShortcode(),
438  '\GravityView_frontend::gv_output_data' => \GravityView_frontend::getInstance()->getGvOutputData(),
439  '\GravityView_View::paging' => \GravityView_View::getInstance()->getPaging(),
440  '\GravityView_View::sorting' => \GravityView_View::getInstance()->getSorting(),
441  '\GravityView_frontend::is_search' => \GravityView_frontend::getInstance()->isSearch(),
442  '\GravityView_frontend::single_entry' => \GravityView_frontend::getInstance()->getSingleEntry(),
443  '\GravityView_frontend::entry' => \GravityView_frontend::getInstance()->getEntry(),
444  '\GravityView_View::_current_entry' => \GravityView_View::getInstance()->getCurrentEntry(),
445  '\GravityView_View::fields' => \GravityView_View::getInstance()->getFields(),
446  '\GravityView_View::_current_field' => \GravityView_View::getInstance()->getCurrentField(),
447  'wp_actions[loop_start]' => empty( $wp_actions['loop_start'] ) ? 0 : $wp_actions['loop_start'],
448  'wp_query::in_the_loop' => $wp_query->in_the_loop,
449  );
450  }
451 
452  /**
453  * Deserializes a saved configuration. Modifies the global state.
454  *
455  * @param array $data Saved configuration from self::freeze()
456  */
457  public static function thaw( $data ) {
458  foreach ( (array)$data as $key => $value ) {
459  switch ( $key ):
460  case '\GravityView_View::atts':
462  break;
463  case '\GravityView_View::view_id':
464  \GravityView_View::getInstance()->setViewId( $value );
465  break;
466  case '\GravityView_View::back_link_label':
467  \GravityView_View::getInstance()->setBackLinkLabel( $value );
468  break;
469  case '\GravityView_View_Data::views':
471  break;
472  case '\GravityView_View::entries':
473  \GravityView_View::getInstance()->setEntries( $value );
474  break;
475  case '\GravityView_View::form':
477  break;
478  case '\GravityView_View::form_id':
479  \GravityView_View::getInstance()->setFormId( $value );
480  break;
481  case '\GravityView_View::context':
482  \GravityView_View::getInstance()->setContext( $value );
483  break;
484  case '\GravityView_View::total_entries':
485  \GravityView_View::getInstance()->setTotalEntries( $value );
486  break;
487  case '\GravityView_View::post_id':
488  \GravityView_View::getInstance()->setPostId( $value );
489  break;
490  case '\GravityView_View::is_hide_until_searched':
491  \GravityView_View::getInstance()->setHideUntilSearched( $value );
492  break;
493  case '\GravityView_frontend::post_id':
495  break;
496  case '\GravityView_frontend::context_view_id':
498  $frontend->context_view_id = $value;
499  break;
500  case '\GravityView_frontend::is_gravityview_post_type':
501  \GravityView_frontend::getInstance()->setIsGravityviewPostType( $value );
502  break;
503  case '\GravityView_frontend::post_has_shortcode':
504  \GravityView_frontend::getInstance()->setPostHasShortcode( $value );
505  break;
506  case '\GravityView_frontend::gv_output_data':
507  \GravityView_frontend::getInstance()->setGvOutputData( $value );
508  break;
509  case '\GravityView_View::paging':
510  \GravityView_View::getInstance()->setPaging( $value );
511  break;
512  case '\GravityView_View::sorting':
513  \GravityView_View::getInstance()->setSorting( $value );
514  break;
515  case '\GravityView_frontend::is_search':
516  \GravityView_frontend::getInstance()->setIsSearch( $value );
517  break;
518  case '\GravityView_frontend::single_entry':
519  \GravityView_frontend::getInstance()->setSingleEntry( $value );
520  break;
521  case '\GravityView_frontend::entry':
523  break;
524  case '\GravityView_View::_current_entry':
525  \GravityView_View::getInstance()->setCurrentEntry( $value );
526  break;
527  case '\GravityView_View::fields':
528  \GravityView_View::getInstance()->setFields( $value );
529  break;
530  case '\GravityView_View::_current_field':
531  \GravityView_View::getInstance()->setCurrentField( $value );
532  break;
533  case 'wp_actions[loop_start]':
534  global $wp_actions;
535  $wp_actions['loop_start'] = $value;
536  break;
537  case 'wp_query::in_the_loop':
538  global $wp_query;
539  $wp_query->in_the_loop = $value;
540  break;
541  endswitch;
542  }
543  }
544 
545  /**
546  * Hydrates the legacy context globals as needed.
547  *
548  * @see Legacy_Context::push() for format.
549  *
550  * @return void
551  */
552  public static function load( $configuration ) {
553  foreach ( (array)$configuration as $key => $value ) {
554  switch ( $key ):
555  case 'view':
556  $views = new \GV\View_Collection();
557  $views->add( $value );
558 
559  self::thaw( array(
560  '\GravityView_View::atts' => $value->settings->as_atts(),
561  '\GravityView_View::view_id' => $value->ID,
562  '\GravityView_View::back_link_label' => $value->settings->get( 'back_link_label', null ),
563  '\GravityView_View::form' => $value->form ? $value->form->form : null,
564  '\GravityView_View::form_id' => $value->form ? $value->form->ID : null,
565  '\GravityView_View::is_hide_until_searched' => $value->settings->get( 'hide_until_searched', null ) && ! gravityview()->request->is_search(),
566 
567  '\GravityView_View_Data::views' => $views,
568  '\GravityView_frontend::gv_output_data' => \GravityView_View_Data::getInstance(),
569  '\GravityView_frontend::context_view_id' => $value->ID,
570  ) );
571  break;
572  case 'post':
573  $has_shortcode = false;
574  foreach ( \GV\Shortcode::parse( $value->post_content ) as $shortcode ) {
575  if ( $shortcode->name == 'gravityview' ) {
576  $has_shortcode = true;
577  break;
578  }
579  }
580  self::thaw( array(
581  '\GravityView_View::post_id' => $value->ID,
582  '\GravityView_frontend::post_id' => $value->ID,
583  '\GravityView_frontend::is_gravityview_post_type' => $value->post_type == 'gravityview',
584  '\GravityView_frontend::post_has_shortcode' => $has_shortcode,
585  ) );
586  break;
587  case 'views':
588  self::thaw( array(
589  '\GravityView_View_Data::views' => $value,
590  '\GravityView_frontend::gv_output_data' => \GravityView_View_Data::getInstance(),
591  ) );
592  break;
593  case 'entries':
594  self::thaw( array(
595  '\GravityView_View::entries' => array_map( function( $e ) { return $e->as_entry(); }, $value->all() ),
596  '\GravityView_View::total_entries' => $value->total(),
597  ) );
598  break;
599  case 'entry':
600  self::thaw( array(
601  '\GravityView_frontend::single_entry' => $value->ID,
602  '\GravityView_frontend::entry' => $value->as_entry(),
603  '\GravityView_View::_current_entry' => $value->as_entry(),
604  ) );
605  break;
606  case 'fields':
607  self::thaw( array(
608  '\GravityView_View::fields' => $value->as_configuration(),
609  ) );
610  break;
611  case 'field':
612  self::thaw( array(
613  '\GravityView_View::_current_field' => array(
614  'field_id' => $value->ID,
615  'field' => $value->field,
616  'field_settings' => $value->as_configuration(),
617  'form' => \GravityView_View::getInstance()->getForm(),
618  'field_type' => $value->type, /** {@since 1.6} */
619  'entry' => \GravityView_View::getInstance()->getCurrentEntry(),
620  'UID' => $value->UID,
621 
622  // 'field_path' => $field_path, /** {@since 1.16} */
623  // 'value' => $value,
624  // 'display_value' => $display_value,
625  // 'format' => $format,
626  ),
627  ) );
628  break;
629  case 'request':
630  self::thaw( array(
631  '\GravityView_View::context' => (
632  $value->is_entry() ? 'single' :
633  ( $value->is_edit_entry() ? 'edit' :
634  ( $value->is_view( false ) ? 'directory': null )
635  )
636  ),
637  '\GravityView_frontend::is_search' => $value->is_search(),
638  ) );
639 
640  if ( ! $value->is_entry() ) {
641  self::thaw( array(
642  '\GravityView_frontend::single_entry' => 0,
643  '\GravityView_frontend::entry' => 0
644  ) );
645  }
646  break;
647  case 'paging':
648  self::thaw( array(
649  '\GravityView_View::paging' => $value,
650  ) );
651  break;
652  case 'sorting':
653  self::thaw( array(
654  '\GravityView_View::sorting' => $value,
655  ) );
656  break;
657  case 'in_the_loop':
658  self::thaw( array(
659  'wp_query::in_the_loop' => $value,
660  'wp_actions[loop_start]' => $value ? 1 : 0,
661  ) );
662  break;
663  endswitch;
664  }
665 
666  global $gravityview_view;
667  $gravityview_view = \GravityView_View::getInstance();
668  }
669 
670  /**
671  * Resets the global state completely.
672  *
673  * Use with utmost care, as filter and action callbacks
674  * may be added again.
675  *
676  * Does not touch the context stack.
677  *
678  * @return void
679  */
680  public static function reset() {
684 
685  global $wp_query, $wp_actions;
686 
687  $wp_query->in_the_loop = false;
688  $wp_actions['loop_start'] = 0;
689  }
690 }
691 
692 
693 /** Add some global fix for field capability discrepancies. */
694 add_filter( 'gravityview/configuration/fields', function( $fields ) {
695  if ( empty( $fields ) ) {
696  return $fields;
697  }
698 
699  /**
700  * Each view field is saved in a weird capability state by default.
701  *
702  * With loggedin set to false, but a capability of 'read' it introduces
703  * some logical issues and is not robust. Fix this behavior throughout
704  * core by making sure capability is '' if log in is not required.
705  *
706  * Perhaps in the UI a fix would be to unite the two fields (as our new
707  * \GV\Field class already does) into one dropdown:
708  *
709  * Anyone, Logged In Only, ... etc. etc.
710  *
711  * The two "settings" should be as tightly coupled as possible to avoid
712  * split logic scenarios. Uniting them into one field is the way to go.
713  */
714 
715  foreach ( $fields as $position => &$_fields ) {
716 
717  if ( empty( $_fields ) || ! is_array( $_fields ) ) {
718  continue;
719  }
720 
721  foreach ( $_fields as $uid => &$_field ) {
722  if ( ! isset( $_field['only_loggedin'] ) ) {
723  continue;
724  }
725  /** If we do not require login, we don't require a cap. */
726  $_field['only_loggedin'] != '1' && ( $_field['only_loggedin_cap'] = '' );
727  }
728  }
729  return $fields;
730 } );
731 
732 
733 /** Add a future fix to make sure field configurations include the form ID. */
734 add_filter( 'gravityview/view/configuration/fields', function( $fields, $view ) {
735  if ( ! $view || empty( $fields ) ) {
736  return $fields;
737  }
738 
739  if ( ! $view->form || ! $view->form->ID ) {
740  return $fields;
741  }
742 
743  /**
744  * In order to instantiate the correct \GV\Field implementation
745  * we need to provide a form_id inside the configuration.
746  *
747  * @todo Make sure this actually happens in the admin side
748  * when saving the views.
749  */
750  foreach ( $fields as $position => &$_fields ) {
751 
752  if ( empty( $_fields ) || ! is_array( $_fields ) ) {
753  continue;
754  }
755 
756  foreach ( $_fields as $uid => &$_field ) {
757  if ( ! empty( $_field['id'] ) && is_numeric( $_field['id'] ) && empty( $_field['form_id'] ) ) {
758  $_field['form_id'] = $view->form->ID;
759  }
760  }
761  }
762 
763  return $fields;
764 }, 10, 2 );
765 
766 
767 /** Make sure the non-configured notice is not output twice. */
768 add_action( 'gravityview/template/after', function( $gravityview = null ) {
769  if ( class_exists( '\GravityView_frontend' ) ) {
770  global $wp_filter;
771 
772  if ( empty( $wp_filter['gravityview_after'] ) ) {
773  return;
774  }
775 
776  foreach ( $wp_filter['gravityview_after']->callbacks[10] as $function_key => $callback ) {
777  if ( strpos( $function_key, 'context_not_configured_warning' ) ) {
778  unset( $wp_filter['gravityview_after']->callbacks[10][ $function_key ] );
779  }
780  }
781  }
782 } );
783 
784 add_filter( 'gravityview/query/is_null_condition', function() {
785  if ( ! class_exists( $class = '\GV\Mocks\GF_Query_Condition_IS_NULL' ) ) {
786  require_once gravityview()->plugin->dir( 'future/_mocks.isnull.php' );
787  }
788 
789  return $class;
790 } );
static getInstance( $passed_post=NULL)
GravityView_View_Data_add_view( $view_id, $atts, $_this)
This file contains mock code for deprecated functions.
Definition: _mocks.php:15
static calculate_get_entries_criteria( $passed_criteria=array(), $form_ids=array())
Calculates the Search Criteria used on the self::get_entries / self::get_entry methods.
static getInstance( $passed_post=NULL)
Definition: class-data.php:122
if(gv_empty( $field['value'], false, false)) $format
A manager of legacy global states and contexts.
Definition: _mocks.php:357
static reset()
Resets the global state completely.
Definition: _mocks.php:680
$class
$field_settings['content']
Definition: custom.php:27
$entries
const BACKEND_INTERNAL
static freeze()
Serializes the current configuration as needed.
Definition: _mocks.php:419
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
if(gravityview() ->plugin->is_GF_25()) $form
static load( $configuration)
Hydrates the legacy context globals as needed.
Definition: _mocks.php:552
GravityView_frontend_get_view_entries( $args, $form_id, $parameters, $count)
Definition: _mocks.php:69
$criteria['paging']
Modify the search parameters before the entries are fetched.
static get_field()
Get a by Field ID for this data source.
$gf_form
static pop()
Restores last saved state and context.
Definition: _mocks.php:410
static push( $configuration)
Set the state depending on the provided configuration.
Definition: _mocks.php:400
static by_id( $post_id)
Construct a instance from a post ID.
static from_entries( $entries)
Construct a multientry from an array of entries.
static by_id( $form_id)
Construct a instance by ID.
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:118
const BACKEND_GRAVITYFORMS
static thaw( $data)
Deserializes a saved configuration.
Definition: _mocks.php:457
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
foreach(GravityKitFoundation::helpers() ->core->get_plugins() as $path=> $plugin)
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
gravityview()
The main GravityView wrapper function.
const FEATURE_GFQUERY
static parse( $content)
Parse a string of content and figure out which ones there are.
static by_id( $entry_id, $form_id=0)
Construct a instance by ID.
$entry
Definition: notes.php:27
static getInstance()
Get the one true instantiated self.