15 if ( ! defined(
'ABSPATH' ) ) {
19 if( ! class_exists(
'\GV\Gamajo_Template_Loader' ) ) {
20 require(
GRAVITYVIEW_DIR .
'future/lib/class-gamajo-template-loader.php' );
175 add_filter( $this->filter_prefix .
'_get_template_part', array( $this,
'add_id_specific_templates' ), 10, 3 );
178 add_action(
'gravityview/template/before', array( $this,
'render_widget_hooks' ) );
179 add_action(
'gravityview/template/after', array( $this,
'render_widget_hooks' ) );
185 add_action(
'gravityview_footer', array( $this,
'clearCurrentEntry' ), 500 );
187 self::$instance = &$this;
197 if( empty( self::$instance ) ) {
198 self::$instance =
new self( $passed_post );
201 return self::$instance;
210 if( !empty( $key ) ) {
211 if( isset( $this->_current_field[ $key ] ) ) {
212 return $this->_current_field[ $key ];
222 if( !empty( $this->_current_field ) ) {
223 $this->_current_field[
'field_settings'][ $key ] =
$value;
245 $set_field = wp_parse_args( $passed_field, $existing_field );
247 $this->_current_field = $set_field;
253 $this->field_data = $set_field;
262 if( !empty( $key ) ) {
263 if( isset( $this->atts[ $key ] ) ) {
264 return $this->atts[ $key ];
329 if(
$fields && !empty( $key ) ) {
353 foreach ( (array)
$fields as $key => $context_fields ) {
356 $matches = explode(
'_', $key );
358 if( isset( $matches[0] ) && $matches[0] ===
$context ) {
359 return $context_fields;
379 if( !empty( $key ) ) {
380 if( isset( $this->fields[ $key ] ) ) {
381 return $this->fields[ $key ];
393 $this->fields[ $key ] =
$value;
400 return absint( $this->view_id );
407 $this->view_id = intval(
$view_id );
457 $default_params = array(
462 return wp_parse_args( $this->paging, $default_params );
487 $page_size =
$paging[
'page_size'];
490 if ( empty( $total ) ) {
491 gravityview()->log->debug(
'No entries. Returning empty array.' );
496 $first = empty( $offset ) ? 1 : $offset + 1;
499 $last = ( $offset + $page_size > $total ) ? $total : $offset + $page_size;
506 list( $first, $last, $total ) = apply_filters(
'gravityview_pagination_counts', array( $first, $last, $total ) );
508 return array(
'first' => (
int) $first,
'last' => (
int) $last,
'total' => (
int) $total );
516 $defaults_params = array(
517 'sort_field' =>
'date_created',
518 'sort_direction' =>
'ASC',
519 'is_numeric' =>
false,
522 return wp_parse_args( $this->sorting, $defaults_params );
604 if( in_array( $this->
getContext(), array(
'edit',
'single') ) ) {
612 if ( empty(
$entry ) && ! empty( $this->_current_field[
'entry'] ) ) {
613 $entry = $this->_current_field[
'entry'];
624 $this->_current_entry = $current_entry;
634 $this->_current_entry = NULL;
652 if ( empty( $zone ) ) {
662 'hide_empty' => $this->
getAtts(
'hide_empty'),
665 $final_atts = wp_parse_args(
$atts, $defaults );
669 $final_atts[
'zone_id'] =
"{$final_atts['context']}_{$final_atts['slug']}-{$zone}";
681 $fields = apply_filters(
"gravityview_table_cells",
$fields, $this );
686 gravityview()->log->warning(
'Empty zone configuration for {zone_id}.', array(
'zone_id' => $final_atts[
'zone_id'] ) );
693 $final_atts[
'field'] =
$field;
706 if ( empty( $field_output ) && apply_filters(
'gravityview/render/hide-empty-zone',
false, null ) ) {
710 if( !empty( $final_atts[
'wrapper_class'] ) ) {
711 $output .=
'<div class="'.gravityview_sanitize_html_class( $final_atts[
'wrapper_class'] ).
'">';
716 if( !empty( $final_atts[
'wrapper_class'] ) ) {
738 if( is_string( $template_names ) && isset( $this->located_templates[ $template_names ] ) ) {
740 $located = $this->located_templates[ $template_names ];
745 $located = parent::locate_template( $template_names,
false, $require_once );
747 if( is_string( $template_names ) ) {
748 $this->located_templates[ $template_names ] = $located;
752 if ( $load && $located ) {
753 load_template( $located, $require_once );
765 if( isset( $this->{
$name} ) ) {
766 return $this->{
$name};
791 $additional = array();
794 $additional[] = sprintf(
'form-%d-%s-%s.php', $this->
getFormId(), $slug,
$name );
798 $additional[] = sprintf(
'view-%d-%s-%s.php',
$view_id, $slug,
$name );
804 $additional[] = sprintf(
'page-%d-%s-%s.php', $this->
getPostId(), $slug,
$name );
822 $template_file = $this->get_template_part( $slug,
$name,
false );
824 gravityview()->log->debug(
'Rendering Template File: {path}', array(
'path' => $template_file ) );
826 if( !empty( $template_file) ) {
828 if ( $require_once ) {
829 require_once( $template_file );
831 require( $template_file );
849 if ( is_numeric( $view_id_or_context ) ) {
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;
867 gravityview()->log->error(
'No View ID or template context provided to render_widget_hooks' );
872 gravityview()->log->debug(
'Not rendering widgets; single entry' );
876 switch ( current_filter() ) {
878 case 'gravityview/template/before':
879 case 'gravityview_before':
882 case 'gravityview/template/after':
883 case 'gravityview_after':
888 $widgets = $view->widgets->by_position(
"$zone*" );
894 if ( ! $widgets->count() ) {
895 gravityview()->log->debug(
'No widgets for View #{view_id} in zone {zone}', array(
'view_id' => $view->ID,
'zone' => $zone ) );
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' ) );
908 wp_enqueue_style(
'gravityview_default_style' );
910 $default_css_class =
'gv-grid gv-widgets-' . $zone;
913 $default_css_class .=
' gv-widgets-no-results';
923 $css_class = apply_filters(
'gravityview/widgets/wrapper_css_class', $default_css_class, $zone, $widgets->as_configuration() );
925 $css_class = gravityview_sanitize_html_class( $css_class );
929 <div
class=
"<?php echo $css_class; ?>">
931 foreach( $rows as $row ) {
932 foreach( $row as $col => $areas ) {
933 $column = ( $col ==
'2-2' ) ?
'1-2 gv-right' :
"$col gv-left";
935 <div
class=
"gv-grid-col-<?php echo esc_attr( $column ); ?>">
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 );
955 if ( did_action(
'wp_head' ) ) {
956 do_action(
"gravityview/widgets/$zone/{$view->ID}/rendered" );
968 if ( file_exists( $path ) ) {
const GRAVITYVIEW_DIR
"GRAVITYVIEW_DIR" "./" The absolute path to the plugin directory, with trailing slash ...
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.
$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'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.
render( $slug, $name, $require_once=true)
$template_part_name
The name of the file part, like "body" or "single".
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.
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()
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.
gravityview()
The main GravityView wrapper function.
gravityview_get_context()
Returns the current GravityView context, or empty string if not GravityView.
gravityview_field_output( $passed_args, $context=null)
Output field based on a certain html markup.
setCurrentField( $passed_field)