GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
class-template.php
Go to the documentation of this file.
1 <?php
2 /**
3  * GravityView templating engine class
4  *
5  * @package GravityView
6  * @license GPL2+
7  * @author GravityView <[email protected]>
8  * @link http://gravityview.co
9  * @copyright Copyright 2014, Katz Web Services, Inc.
10  *
11  * @since 1.0.0
12  */
13 
14 /** If this file is called directly, abort. */
15 if ( ! defined( 'ABSPATH' ) ) {
16  die;
17 }
18 
19 if( ! class_exists( '\GV\Gamajo_Template_Loader' ) ) {
20  require( GRAVITYVIEW_DIR . 'future/lib/class-gamajo-template-loader.php' );
21 }
22 
23 class GravityView_View extends \GV\Gamajo_Template_Loader {
24 
25  /**
26  * Prefix for filter names.
27  *
28  * @var string $filter_prefix
29  */
30  protected $filter_prefix = 'gravityview';
31 
32  /**
33  * Directory name where custom templates for this plugin should be found in the theme.
34  *
35  * @var string $theme_template_directory
36  */
37  protected $theme_template_directory = 'gravityview';
38 
39  /**
40  * Reference to the root directory path of this plugin.
41  *
42  * @var string $plugin_directory
43  */
45 
46  /**
47  * Store templates locations that have already been located
48  *
49  * @var array $located_templates
50  */
51  protected $located_templates = array();
52 
53  /**
54  * The name of the template, like "list", "table", or "datatables"
55  *
56  * @var string $template_part_slug
57  */
58  protected $template_part_slug = '';
59 
60  /**
61  * The name of the file part, like "body" or "single"
62  *
63  * @var string $template_part_name
64  */
65  protected $template_part_name = '';
66 
67  /**
68  * @var int $form_id Gravity Forms form ID
69  */
70  protected $form_id = null;
71 
72  /**
73  * @var int $view_id View ID
74  * @todo: this needs to be public until extensions support 1.7+
75  */
76  public $view_id = null;
77 
78  /**
79  * @var array $fields Fields for the form
80  */
81  protected $fields = array();
82 
83  /**
84  * @var string $context Current screen. Defaults to "directory" or "single"
85  */
86  protected $context = 'directory';
87 
88  /**
89  * @var int|null $post_id If in embedded post or page, the ID of it
90  */
91  protected $post_id = null;
92 
93  /**
94  * @var array $form Gravity Forms form array at ID $form_id
95  */
96  protected $form = null;
97 
98  /**
99  * @var array $atts Configuration for the View
100  */
101  protected $atts = array();
102 
103  /**
104  * @var array $entries Entries for the current result. Single item in array for single entry View
105  */
106  protected $entries = array();
107 
108  /**
109  * @var int $total_entries Total entries count for the current result.
110  */
111  protected $total_entries = 0;
112 
113  /**
114  * @var string $back_link_label The label to display back links
115  */
116  protected $back_link_label = '';
117 
118  /**
119  * @var array $paging Array with `offset` and `page_size` keys
120  */
121  protected $paging = array();
122 
123  /**
124  * @var array $sorting Array with `sort_field` and `sort_direction` keys
125  */
126  protected $sorting = array();
127 
128  /**
129  * @var bool $hide_until_searched Whether to hide the results until a search is performed
130  * @since 1.5.4
131  */
132  protected $hide_until_searched = false;
133 
134  /**
135  * Current entry in the loop
136  *
137  * @var array $_current_entry
138  */
139  protected $_current_entry = array();
140 
141  /**
142  * @var array $_current_field
143  */
144  protected $_current_field = array();
145 
146  /**
147  * @var GravityView_View $instance
148  */
149  static $instance = NULL;
150 
151  /**
152  * Construct the view object
153  * @param array $atts Associative array to set the data of
154  */
155  function __construct( $atts = array() ) {
156 
157  $atts = wp_parse_args( $atts, array(
158  'form_id' => NULL,
159  'view_id' => NULL,
160  'fields' => NULL,
161  'context' => NULL,
162  'post_id' => NULL,
163  'form' => NULL,
164  'atts' => NULL,
165  ) );
166 
167  foreach ($atts as $key => $value) {
168  if( is_null( $value ) ) {
169  continue;
170  }
171  $this->{$key} = $value;
172  }
173 
174  // Add granular overrides
175  add_filter( $this->filter_prefix . '_get_template_part', array( $this, 'add_id_specific_templates' ), 10, 3 );
176 
177  // widget logic
178  add_action( 'gravityview/template/before', array( $this, 'render_widget_hooks' ) );
179  add_action( 'gravityview/template/after', array( $this, 'render_widget_hooks' ) );
180 
181  /**
182  * Clear the current entry after the loop is done
183  * @since 1.7.3
184  */
185  add_action( 'gravityview_footer', array( $this, 'clearCurrentEntry' ), 500 );
186 
187  self::$instance = &$this;
188  }
189 
190  /**
191  * @param null $passed_post
192  *
193  * @return GravityView_View
194  */
195  static function getInstance( $passed_post = NULL ) {
196 
197  if( empty( self::$instance ) ) {
198  self::$instance = new self( $passed_post );
199  }
200 
201  return self::$instance;
202  }
203 
204  /**
205  * @param string|null $key The key to a specific attribute of the current field
206  * @return array|mixed|null If $key is set and attribute exists at $key, return that. If not set, return NULL. Otherwise, return current field array
207  */
208  public function getCurrentField( $key = NULL ) {
209 
210  if( !empty( $key ) ) {
211  if( isset( $this->_current_field[ $key ] ) ) {
212  return $this->_current_field[ $key ];
213  }
214  return NULL;
215  }
216 
217  return $this->_current_field;
218  }
219 
220  public function setCurrentFieldSetting( $key, $value ) {
221 
222  if( !empty( $this->_current_field ) ) {
223  $this->_current_field['field_settings'][ $key ] = $value;
224  }
225 
226  }
227 
228  public function getCurrentFieldSetting( $key ) {
229  $settings = $this->getCurrentField('field_settings');
230 
231  if( $settings && !empty( $settings[ $key ] ) ) {
232  return $settings[ $key ];
233  }
234 
235  return NULL;
236  }
237 
238  /**
239  * @param array $passed_field
240  */
241  public function setCurrentField( $passed_field ) {
242 
243  $existing_field = $this->getCurrentField();
244 
245  $set_field = wp_parse_args( $passed_field, $existing_field );
246 
247  $this->_current_field = $set_field;
248 
249  /**
250  * Backward compatibility
251  * @deprecated 1.6.2
252  */
253  $this->field_data = $set_field;
254  }
255 
256  /**
257  * @param string|null $key The key to a specific field in the fields array
258  * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
259  */
260  public function getAtts( $key = NULL ) {
261 
262  if( !empty( $key ) ) {
263  if( isset( $this->atts[ $key ] ) ) {
264  return $this->atts[ $key ];
265  }
266  return NULL;
267  }
268 
269  return $this->atts;
270  }
271 
272  /**
273  * @param array $atts
274  */
275  public function setAtts( $atts ) {
276  $this->atts = $atts;
277  }
278 
279  /**
280  * @return array
281  */
282  public function getForm() {
283  return $this->form;
284  }
285 
286  /**
287  * @param array $form
288  */
289  public function setForm( $form ) {
290  $this->form = $form;
291  }
292 
293  /**
294  * @return int|null
295  */
296  public function getPostId() {
297  return $this->post_id;
298  }
299 
300  /**
301  * @param int|null $post_id
302  */
303  public function setPostId( $post_id ) {
304  $this->post_id = $post_id;
305  }
306 
307  /**
308  * @return string
309  */
310  public function getContext() {
311  return $this->context;
312  }
313 
314  /**
315  * @param string $context
316  */
317  public function setContext( $context ) {
318  $this->context = $context;
319  }
320 
321  /**
322  * @param string|null $key The key to a specific field in the fields array
323  * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
324  */
325  public function getFields( $key = null ) {
326 
327  $fields = empty( $this->fields ) ? NULL : $this->fields;
328 
329  if( $fields && !empty( $key ) ) {
330  $fields = isset( $fields[ $key ] ) ? $fields[ $key ] : NULL;
331  }
332 
333  return $fields;
334  }
335 
336  /**
337  * Get the fields for a specific context
338  *
339  * @since 1.19.2
340  *
341  * @param string $context [Optional] "directory", "single", or "edit"
342  *
343  * @return array Array of GravityView field layout configurations
344  */
345  public function getContextFields( $context = '' ) {
346 
347  if( '' === $context ) {
348  $context = $this->getContext();
349  }
350 
351  $fields = $this->getFields();
352 
353  foreach ( (array) $fields as $key => $context_fields ) {
354 
355  // Formatted as `{context}_{template id}-{zone name}`, so we want just the $context to match against
356  $matches = explode( '_', $key );
357 
358  if( isset( $matches[0] ) && $matches[0] === $context ) {
359  return $context_fields;
360  }
361  }
362 
363  return array();
364  }
365 
366  /**
367  * @param array $fields
368  */
369  public function setFields( $fields ) {
370  $this->fields = $fields;
371  }
372 
373  /**
374  * @param string $key The key to a specific field in the fields array
375  * @return array|mixed|null If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
376  */
377  public function getField( $key ) {
378 
379  if( !empty( $key ) ) {
380  if( isset( $this->fields[ $key ] ) ) {
381  return $this->fields[ $key ];
382  }
383  }
384 
385  return NULL;
386  }
387 
388  /**
389  * @param string $key The key to a specific field in the fields array
390  * @param mixed $value The value to set for the field
391  */
392  public function setField( $key, $value ) {
393  $this->fields[ $key ] = $value;
394  }
395 
396  /**
397  * @return int
398  */
399  public function getViewId() {
400  return absint( $this->view_id );
401  }
402 
403  /**
404  * @param int $view_id
405  */
406  public function setViewId( $view_id ) {
407  $this->view_id = intval( $view_id );
408  }
409 
410  /**
411  * @return int
412  */
413  public function getFormId() {
414  return $this->form_id;
415  }
416 
417  /**
418  * @param int $form_id
419  */
420  public function setFormId( $form_id ) {
421  $this->form_id = $form_id;
422  }
423 
424  /**
425  * @return array
426  */
427  public function getEntries() {
428  return $this->entries;
429  }
430 
431  /**
432  * @param array $entries
433  */
434  public function setEntries( $entries ) {
435  $this->entries = $entries;
436  }
437 
438  /**
439  * @return int
440  */
441  public function getTotalEntries() {
442  return (int)$this->total_entries;
443  }
444 
445  /**
446  * @param int $total_entries
447  */
448  public function setTotalEntries( $total_entries ) {
449  $this->total_entries = intval( $total_entries );
450  }
451 
452  /**
453  * @return array
454  */
455  public function getPaging() {
456 
457  $default_params = array(
458  'offset' => 0,
459  'page_size' => 20,
460  );
461 
462  return wp_parse_args( $this->paging, $default_params );
463  }
464 
465  /**
466  * @param array $paging
467  */
468  public function setPaging( $paging ) {
469  $this->paging = $paging;
470  }
471 
472  /**
473  * Get an array with pagination information
474  *
475  * @since 1.13
476  *
477  * @return array {
478  * @type int $first The starting entry number (counter, not ID)
479  * @type int $last The last displayed entry number (counter, not ID)
480  * @type int $total The total number of entries
481  * }
482  */
483  public function getPaginationCounts() {
484 
485  $paging = $this->getPaging();
486  $offset = $paging['offset'];
487  $page_size = $paging['page_size'];
488  $total = $this->getTotalEntries();
489 
490  if ( empty( $total ) ) {
491  gravityview()->log->debug( 'No entries. Returning empty array.' );
492 
493  return array();
494  }
495 
496  $first = empty( $offset ) ? 1 : $offset + 1;
497 
498  // If the page size + starting entry is larger than total, the total is the max.
499  $last = ( $offset + $page_size > $total ) ? $total : $offset + $page_size;
500 
501  /**
502  * @filter `gravityview_pagination_counts` Modify the displayed pagination numbers
503  * @since 1.13
504  * @param array $counts Array with $first, $last, $total numbers in that order
505  */
506  list( $first, $last, $total ) = apply_filters( 'gravityview_pagination_counts', array( $first, $last, $total ) );
507 
508  return array( 'first' => (int) $first, 'last' => (int) $last, 'total' => (int) $total );
509  }
510 
511  /**
512  * @return array
513  */
514  public function getSorting() {
515 
516  $defaults_params = array(
517  'sort_field' => 'date_created',
518  'sort_direction' => 'ASC',
519  'is_numeric' => false,
520  );
521 
522  return wp_parse_args( $this->sorting, $defaults_params );
523  }
524 
525  /**
526  * @param array $sorting
527  */
528  public function setSorting( $sorting ) {
529  $this->sorting = $sorting;
530  }
531 
532  /**
533  * @param boolean $do_replace Perform merge tag and shortcode processing on the label. Default: true.
534  * @since 2.0
535  *
536  * @deprecated Use $template->get_back_label();
537  *
538  * @return string
539  */
540  public function getBackLinkLabel( $do_replace = true ) {
541  if ( $do_replace ) {
542  $back_link_label = GravityView_API::replace_variables( $this->back_link_label, $this->getForm(), $this->getCurrentEntry() );
543  return do_shortcode( $back_link_label );
544  }
545 
546  return $this->back_link_label;
547  }
548 
549  /**
550  * @param string $back_link_label
551  */
552  public function setBackLinkLabel( $back_link_label ) {
553  $this->back_link_label = $back_link_label;
554  }
555 
556  /**
557  * @return boolean
558  */
559  public function isHideUntilSearched() {
561  }
562 
563  /**
564  * @param boolean $hide_until_searched
565  */
567  $this->hide_until_searched = $hide_until_searched;
568  }
569 
570  /**
571  * @return string
572  */
573  public function getTemplatePartSlug() {
575  }
576 
577  /**
578  * @param string $template_part_slug
579  */
581  $this->template_part_slug = $template_part_slug;
582  }
583 
584  /**
585  * @return string
586  */
587  public function getTemplatePartName() {
589  }
590 
591  /**
592  * @param string $template_part_name
593  */
595  $this->template_part_name = $template_part_name;
596  }
597 
598  /**
599  * Return the current entry. If in the loop, the current entry. If single entry, the currently viewed entry.
600  * @return array
601  */
602  public function getCurrentEntry() {
603 
604  if( in_array( $this->getContext(), array( 'edit', 'single') ) ) {
605  $entries = $this->getEntries();
606  $entry = $entries[0];
607  } else {
609  }
610 
611  /** @since 1.16 Fixes DataTables empty entry issue */
612  if ( empty( $entry ) && ! empty( $this->_current_field['entry'] ) ) {
613  $entry = $this->_current_field['entry'];
614  }
615 
616  return $entry;
617  }
618 
619  /**
620  * @param array $current_entry
621  * @return void
622  */
623  public function setCurrentEntry( $current_entry ) {
624  $this->_current_entry = $current_entry;
625  }
626 
627  /**
628  * Clear the current entry after all entries in the loop have been displayed.
629  *
630  * @since 1.7.3
631  * @return void
632  */
633  public function clearCurrentEntry() {
634  $this->_current_entry = NULL;
635  }
636 
637  /**
638  * Render an output zone, as configured in the Admin
639  *
640  * @since 1.16.4 Added $echo parameter
641  *
642  * @param string $zone The zone name, like 'footer-left'
643  * @param array $atts
644  * @param bool $echo Whether to print the output
645  *
646  * @deprecated This will never get called in new templates.
647  *
648  * @return string|null
649  */
650  public function renderZone( $zone = '', $atts = array(), $echo = true ) {
651 
652  if ( empty( $zone ) ) {
653  gravityview()->log->error( 'No zone defined.');
654  return NULL;
655  }
656 
657  $defaults = array(
658  'slug' => $this->getTemplatePartSlug(),
659  'context' => $this->getContext(),
660  'entry' => $this->getCurrentEntry(),
661  'form' => $this->getForm(),
662  'hide_empty' => $this->getAtts('hide_empty'),
663  );
664 
665  $final_atts = wp_parse_args( $atts, $defaults );
666 
667  $output = '';
668 
669  $final_atts['zone_id'] = "{$final_atts['context']}_{$final_atts['slug']}-{$zone}";
670 
671  $fields = $this->getField( $final_atts['zone_id'] );
672 
673  // Backward compatibility
674  if ( 'table' === $this->getTemplatePartSlug() ) {
675  /**
676  * @filter `gravityview_table_cells` Modify the fields displayed in a table
677  * @param array $fields
678  * @param \GravityView_View $this
679  * @deprecated Use `gravityview/template/table/fields`
680  */
681  $fields = apply_filters("gravityview_table_cells", $fields, $this );
682  }
683 
684  if ( empty( $fields ) ) {
685 
686  gravityview()->log->warning( 'Empty zone configuration for {zone_id}.', array( 'zone_id' => $final_atts['zone_id'] ) );
687 
688  return NULL;
689  }
690 
691  $field_output = '';
692  foreach ( $fields as $field ) {
693  $final_atts['field'] = $field;
694 
695  $field_output .= gravityview_field_output( $final_atts );
696  }
697 
698  /**
699  * If a zone has no field output, choose whether to show wrapper
700  * False by default to keep backward compatibility
701  * @since 1.7.6
702  * @param boolean $hide_empty_zone Default: false
703  * @since 2.0
704  * @param \GV\Template_Context $context The context. Null here. Since this path is deprecated.
705  */
706  if ( empty( $field_output ) && apply_filters( 'gravityview/render/hide-empty-zone', false, null ) ) {
707  return NULL;
708  }
709 
710  if( !empty( $final_atts['wrapper_class'] ) ) {
711  $output .= '<div class="'.gravityview_sanitize_html_class( $final_atts['wrapper_class'] ).'">';
712  }
713 
714  $output .= $field_output;
715 
716  if( !empty( $final_atts['wrapper_class'] ) ) {
717  $output .= '</div>';
718  }
719 
720  if( $echo ) {
721  echo $output;
722  }
723 
724  return $output;
725  }
726 
727  /**
728  * In order to improve lookup times, we store located templates in a local array.
729  *
730  * This improves performance by up to 1/2 second on a 250 entry View with 7 columns showing
731  *
732  * @inheritdoc
733  * @see Gamajo_Template_Loader::locate_template()
734  * @return null|string NULL: Template not found; String: path to template
735  */
736  function locate_template( $template_names, $load = false, $require_once = true ) {
737 
738  if( is_string( $template_names ) && isset( $this->located_templates[ $template_names ] ) ) {
739 
740  $located = $this->located_templates[ $template_names ];
741 
742  } else {
743 
744  // Set $load to always false so we handle it here.
745  $located = parent::locate_template( $template_names, false, $require_once );
746 
747  if( is_string( $template_names ) ) {
748  $this->located_templates[ $template_names ] = $located;
749  }
750  }
751 
752  if ( $load && $located ) {
753  load_template( $located, $require_once );
754  }
755 
756  return $located;
757  }
758 
759  /**
760  * Magic Method: Instead of throwing an error when a variable isn't set, return null.
761  * @param string $name Key for the data retrieval.
762  * @return mixed|null The stored data.
763  */
764  public function __get( $name ) {
765  if( isset( $this->{$name} ) ) {
766  return $this->{$name};
767  } else {
768  return NULL;
769  }
770  }
771 
772  /**
773  * Enable overrides of GravityView templates on a granular basis
774  *
775  * The loading order is:
776  *
777  * - view-[View ID]-table-footer.php
778  * - form-[Form ID]-table-footer.php
779  * - page-[ID of post or page where view is embedded]-table-footer.php
780  * - table-footer.php
781  *
782  * @see Gamajo_Template_Loader::get_template_file_names() Where the filter is
783  * @param array $templates Existing list of templates.
784  * @param string $slug Name of the template base, example: `table`, `list`, `datatables`, `map`
785  * @param string $name Name of the template part, example: `body`, `footer`, `head`, `single`
786  *
787  * @return array $templates Modified template array, merged with existing $templates values
788  */
790 
791  $additional = array();
792 
793  // form-19-table-body.php
794  $additional[] = sprintf( 'form-%d-%s-%s.php', $this->getFormId(), $slug, $name );
795 
796  if( $view_id = $this->getViewId() ) {
797  // view-3-table-body.php
798  $additional[] = sprintf( 'view-%d-%s-%s.php', $view_id, $slug, $name );
799  }
800 
801  if( $this->getPostId() ) {
802 
803  // page-19-table-body.php
804  $additional[] = sprintf( 'page-%d-%s-%s.php', $this->getPostId(), $slug, $name );
805  }
806 
807  // Combine with existing table-body.php and table.php
808  $templates = array_merge( $additional, $templates );
809 
810  gravityview()->log->debug( 'List of Template Files', array( 'data' => $templates ) );
811 
812  return $templates;
813  }
814 
815  // Load the template
816  public function render( $slug, $name, $require_once = true ) {
817 
818  $this->setTemplatePartSlug( $slug );
819 
820  $this->setTemplatePartName( $name );
821 
822  $template_file = $this->get_template_part( $slug, $name, false );
823 
824  gravityview()->log->debug( 'Rendering Template File: {path}', array( 'path' => $template_file ) );
825 
826  if( !empty( $template_file) ) {
827 
828  if ( $require_once ) {
829  require_once( $template_file );
830  } else {
831  require( $template_file );
832  }
833 
834  }
835  }
836 
837  /**
838  * Output the widgets on before/after hooks.
839  *
840  * @param int|\GV\Template_Context $view_id_or_context The View ID or the context.
841  *
842  * @return void
843  */
844  public function render_widget_hooks( $view_id_or_context ) {
845 
846  /**
847  * @deprecated Numeric argument is deprecated. Pass a \GV\Template_Context instead.
848  */
849  if ( is_numeric( $view_id_or_context ) ) {
850  $view = \GV\View::by_id( $view_id_or_context );
851  $is_single = gravityview_get_context() == 'single';
852  $total_entries = GravityView_View::getInstance()->getTotalEntries();
853 
854  /**
855  * Fake new context for legacy template code.
856  */
857  $view_id_or_context = \GV\Template_Context::from_template( array(
858  'view' => $view,
859  ) );
860 
861  } else if ( $view_id_or_context instanceof \GV\Template_Context ) {
862  $view = $view_id_or_context->view;
863  $is_single = (boolean)$view_id_or_context->request->is_entry();
864  $total_entries = $view_id_or_context->entries ? $view_id_or_context->entries->count() : 0;
865 
866  } else {
867  gravityview()->log->error( 'No View ID or template context provided to render_widget_hooks' );
868  return;
869  }
870 
871  if ( $is_single ) {
872  gravityview()->log->debug( 'Not rendering widgets; single entry' );
873  return;
874  }
875 
876  switch ( current_filter() ) {
877  default:
878  case 'gravityview/template/before':
879  case 'gravityview_before':
880  $zone = 'header';
881  break;
882  case 'gravityview/template/after':
883  case 'gravityview_after':
884  $zone = 'footer';
885  break;
886  }
887 
888  $widgets = $view->widgets->by_position( "$zone*" );
889 
890  /**
891  * Prevent output if no widgets to show.
892  * @since 1.16
893  */
894  if ( ! $widgets->count() ) {
895  gravityview()->log->debug( 'No widgets for View #{view_id} in zone {zone}', array( 'view_id' => $view->ID, 'zone' => $zone ) );
896  return;
897  }
898 
899  // Prevent being called twice
900  if ( did_action( "gravityview/widgets/$zone/{$view->ID}/rendered" ) ) {
901  gravityview()->log->debug( 'Not rendering {zone}; already rendered', array( 'zone' => $zone.'_'.$view->ID.'_widgets' ) );
902  return;
903  }
904 
906 
907  // TODO: Move to sep. method, use an action instead
908  wp_enqueue_style( 'gravityview_default_style' );
909 
910  $default_css_class = 'gv-grid gv-widgets-' . $zone;
911 
912  if ( ! $total_entries ) {
913  $default_css_class .= ' gv-widgets-no-results';
914  }
915 
916  /**
917  * @filter `gravityview/widgets/wrapper_css_class` The CSS class applied to the widget container `<div>`.
918  * @since 1.16.2
919  * @param string $css_class Default: `gv-grid gv-widgets-{zone}` where `{zone}` is replaced by the current `$zone` value. If the View has no results, adds ` gv-widgets-no-results`
920  * @param string $zone Current widget zone, either `header` or `footer`
921  * @param array $widgets Array of widget configurations for the current zone, as set by `gravityview_get_current_view_data()['widgets']`
922  */
923  $css_class = apply_filters('gravityview/widgets/wrapper_css_class', $default_css_class, $zone, $widgets->as_configuration() );
924 
925  $css_class = gravityview_sanitize_html_class( $css_class );
926 
927  // TODO Convert to partials
928  ?>
929  <div class="<?php echo $css_class; ?>">
930  <?php
931  foreach( $rows as $row ) {
932  foreach( $row as $col => $areas ) {
933  $column = ( $col == '2-2' ) ? '1-2 gv-right' : "$col gv-left";
934  ?>
935  <div class="gv-grid-col-<?php echo esc_attr( $column ); ?>">
936  <?php
937  if ( ! empty( $areas ) ) {
938  foreach ( $areas as $area ) {
939  foreach ( $widgets->by_position( $zone . '_' . $area['areaid'] )->all() as $widget ) {
940  do_action( sprintf( 'gravityview/widgets/%s/render', $widget->get_widget_id() ), $widget->configuration->all(), null, $view_id_or_context );
941  }
942  }
943  } ?>
944  </div>
945  <?php } // $row ?>
946  <?php } // $rows ?>
947  </div>
948 
949  <?php
950 
951  /**
952  * Prevent widgets from being called twice.
953  * Checking for loop_start prevents themes and plugins that pre-process shortcodes from triggering the action before displaying. Like, ahem, the Divi theme and WordPress SEO plugin
954  */
955  if ( did_action( 'wp_head' ) ) {
956  do_action( "gravityview/widgets/$zone/{$view->ID}/rendered" );
957  }
958  }
959 
960  /**
961  * Include a file inside this context.
962  *
963  * @param string $path A path to the legacy template to include.
964  *
965  * @return void
966  */
967  public function _include( $path ) {
968  if ( file_exists( $path ) ) {
969  include $path;
970  }
971  }
972 
973 }
974 
const GRAVITYVIEW_DIR
"GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory, with trailing slash ...
Definition: gravityview.php:49
setPostId( $post_id)
getCurrentFieldSetting( $key)
static getInstance( $passed_post=NULL)
setCurrentFieldSetting( $key, $value)
setTemplatePartSlug( $template_part_slug)
$template_part_slug
The name of the template, like "list", "table", or "datatables".
add_id_specific_templates( $templates, $slug, $name)
Enable overrides of GravityView templates on a granular basis.
getAtts( $key=NULL)
$filter_prefix
Prefix for filter names.
locate_template( $template_names, $load=false, $require_once=true)
In order to improve lookup times, we store located templates in a local array.
__get( $name)
Magic Method: Instead of throwing an error when a variable isn&#39;t set, return null.
getCurrentEntry()
Return the current entry.
getContextFields( $context='')
Get the fields for a specific context.
setTemplatePartName( $template_part_name)
setHideUntilSearched( $hide_until_searched)
_include( $path)
Include a file inside this context.
setContext( $context)
static get_default_widget_areas()
Default widget areas.
render( $slug, $name, $require_once=true)
setFormId( $form_id)
$template_part_name
The name of the file part, like "body" or "single".
$templates
getCurrentField( $key=NULL)
$plugin_directory
Reference to the root directory path of this plugin.
setCurrentEntry( $current_entry)
getBackLinkLabel( $do_replace=true)
setTotalEntries( $total_entries)
renderZone( $zone='', $atts=array(), $echo=true)
Render an output zone, as configured in the Admin.
$theme_template_directory
Directory name where custom templates for this plugin should be found in the theme.
setField( $key, $value)
setEntries( $entries)
static from_template( $template, $data=array())
Create a context from a Template.
static by_id( $post_id)
Construct a instance from a post ID.
$located_templates
Store templates locations that have already been located.
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
getFields( $key=null)
If this file is called directly, abort.
__construct( $atts=array())
Construct the view object.
setBackLinkLabel( $back_link_label)
getPaginationCounts()
Get an array with pagination information.
render_widget_hooks( $view_id_or_context)
Output the widgets on before/after hooks.
$_current_entry
Current entry in the loop.
clearCurrentEntry()
Clear the current entry after all entries in the loop have been displayed.
setViewId( $view_id)
gravityview()
The main GravityView wrapper function.
setSorting( $sorting)
gravityview_get_context()
Returns the current GravityView context, or empty string if not GravityView.
Definition: class-api.php:1330
gravityview_field_output( $passed_args, $context=null)
Output field based on a certain html markup.
Definition: class-api.php:1452
$entry
Definition: notes.php:27
setCurrentField( $passed_field)