5 if ( ! defined(
'GRAVITYVIEW_DIR' ) ) {
35 if ( $request->is_admin() ) {
39 $atts = wp_parse_args( $passed_atts, array(
47 if ( $atts[
'detail'] && $view = $request->is_view() ) {
55 gravityview()->log->error(
'View does not exist #{view_id}', array(
'view_id' =>
$view_id ) );
59 $post = get_post( $view->ID );
63 if ( ! $gv_view_data->views->contains( $view->ID ) ) {
64 $gv_view_data->views->add( $view );
75 do_action(
'gravityview/shortcode/before-processing', $view,
$post );
83 $is_reembedded =
false;
84 if ( in_array( get_class( $request ), array(
'GV\Frontend_Request',
'GV\Mock_Request' ) ) ) {
86 if ( ( $_view = $request->is_view() ) && $_view->ID !== $view->ID ) {
87 $is_reembedded =
true;
89 } elseif ( $request->is_entry( $view->form ? $view->form->ID : 0 ) && self::$callstack ) {
90 $is_reembedded =
true;
94 array_push( self::$callstack,
true );
99 if ( $is_reembedded ) {
100 $view->widgets = new \GV\Widget_Collection();
105 $view->settings->update( array(
'shortcode_atts' => $atts ) );
106 $view->settings->update( $atts );
111 while ( $error = $view->can_render( array(
'shortcode' ), $request ) ) {
112 if ( ! is_wp_error( $error ) )
115 switch ( str_replace(
'gravityview/',
'', $error->get_error_code() ) ) {
116 case 'post_password_required':
117 return self::_return( get_the_password_form( $view->ID ) );
118 case 'no_form_attached':
123 if ( \
GVCommon::has_cap( array(
'edit_gravityviews',
'edit_gravityview' ), $view->ID ) ) {
124 return self::_return( sprintf( __(
'This View is not configured properly. Start by <a href="%s">selecting a form</a>.',
'gk-gravityview' ), esc_url( get_edit_post_link( $view->ID,
false ) ) ) );
127 case 'no_direct_access':
131 return self::_return( __(
'You are not allowed to view this content.',
'gk-gravityview' ) );
135 $is_admin_and_can_view = $view->settings->get(
'admin_show_all_statuses' ) &&
\GVCommon::has_cap(
'gravityview_moderate_entries', $view->ID );
140 if ( $atts[
'detail'] ) {
141 $entries = $view->get_entries( $request );
147 }
else if ( ! $is_reembedded && (
$entry = $request->is_edit_entry( $view->form ? $view->form->ID : 0 ) ) ) {
152 if ( ( $selected = \
GV\
Utils::_GET(
'gvid' ) ) && $view->ID != $selected ) {
153 gravityview()->log->notice(
'Entry ID #{entry_id} not rendered because another View ID was passed using `?gvid`: #{selected}', array(
'entry_id' =>
$entry->ID,
'selected' => $selected ) );
154 return self::_return(
'' );
157 if (
$entry[
'status'] !=
'active' ) {
158 gravityview()->log->notice(
'Entry ID #{entry_id} is not active', array(
'entry_id' =>
$entry->ID ) );
159 return self::_return( __(
'You are not allowed to view this content.',
'gk-gravityview' ) );
163 gravityview()->log->error(
'Entry ID #{entry_id} was accessed by a bad slug', array(
'entry_id' =>
$entry->ID ) );
164 return self::_return( __(
'You are not allowed to view this content.',
'gk-gravityview' ) );
167 if ( $view->settings->get(
'show_only_approved' ) && ! $is_admin_and_can_view ) {
169 gravityview()->log->error(
'Entry ID #{entry_id} is not approved for viewing', array(
'entry_id' =>
$entry->ID ) );
170 return self::_return( __(
'You are not allowed to view this content.',
'gk-gravityview' ) );
174 $renderer = new \GV\Edit_Entry_Renderer();
175 return self::_return( $renderer->render(
$entry, $view, $request ) );
180 }
else if ( ! $is_reembedded && (
$entry = $request->is_entry( $view->form ? $view->form->ID : 0 ) ) ) {
184 if ( ( $selected = \
GV\
Utils::_GET(
'gvid' ) ) && $view->ID != $selected ) {
185 return self::_return(
'' );
190 foreach ( $entryset as $e ) {
191 if ( $e[
'status'] !=
'active' ) {
192 gravityview()->log->notice(
'Entry ID #{entry_id} is not active', array(
'entry_id' => $e->ID ) );
193 return self::_return( __(
'You are not allowed to view this content.',
'gk-gravityview' ) );
196 if ( apply_filters(
'gravityview_custom_entry_slug',
false ) && $e->slug != get_query_var( \
GV\
Entry::get_endpoint_name() ) ) {
197 gravityview()->log->error(
'Entry ID #{entry_id} was accessed by a bad slug', array(
'entry_id' => $e->ID ) );
198 return self::_return( __(
'You are not allowed to view this content.',
'gk-gravityview' ) );
201 if ( $view->settings->get(
'show_only_approved' ) && ! $is_admin_and_can_view ) {
203 gravityview()->log->error(
'Entry ID #{entry_id} is not approved for viewing', array(
'entry_id' => $e->ID ) );
204 return self::_return( __(
'You are not allowed to view this content.',
'gk-gravityview' ) );
210 if ( is_wp_error( $error ) ) {
211 gravityview()->log->error(
'Entry ID #{entry_id} is not approved for viewing: {message}', array(
'entry_id' => $e->ID,
'message' => $error->get_error_message() ) );
212 return self::_return( __(
'You are not allowed to view this content.',
'gk-gravityview' ) );
216 $renderer = new \GV\Entry_Renderer();
217 return self::_return( $renderer->render(
$entry, $view, $request ) );
223 if ( $is_reembedded ) {
226 $mock_request = new \GV\Mock_Request();
227 $mock_request->returns[
'is_view'] = $view;
228 $mock_request->returns[
'is_entry'] = $request->is_entry( $view->form ? $view->form->ID : 0 );
229 $mock_request->returns[
'is_edit_entry'] = $request->is_edit_entry( $view->form ? $view->form->ID : 0 );
230 $mock_request->returns[
'is_search'] = $request->is_search();
232 $request = $mock_request;
235 $renderer = new \GV\View_Renderer();
236 return self::_return( $renderer->render( $view, $request ) );
260 $supported_atts = array_fill_keys( array_keys( $defaults ),
'' );
263 $filtered_atts = shortcode_atts( $supported_atts, $passed_atts,
'gravityview' );
266 $filtered_atts = array_intersect_key( (array) $passed_atts, $filtered_atts );
270 foreach( $filtered_atts as $key => $passed_value ) {
275 switch( $defaults[ $key ][
'type'] ) {
283 if( is_numeric( $passed_value ) ) {
284 $atts[ $key ] = ( $passed_value + 0 );
290 $atts[ $key ] =
gv_empty( $passed_value,
true,
false ) ? 0 : 1;
298 $options = isset( $defaults[ $key ][
'choices'] ) ? $defaults[ $key ][
'choices'] : $defaults[ $key ][
'options'];
299 if( in_array( $passed_value, array_keys( $options ) ) ) {
300 $atts[ $key ] = $passed_value;
306 $atts[ $key ] = $passed_value;
328 switch ( $key =
$atts[
'detail'] ):
329 case 'total_entries':
333 $output = number_format_i18n( min(
$entries->total(), $view->settings->get(
'offset' ) + 1 ) );
336 $output = number_format_i18n( $view->settings->get(
'page_size' ) + $view->settings->get(
'offset' ) );
339 $output = number_format_i18n( $view->settings->get( $key ) );
353 $output = apply_filters(
"gravityview/shortcode/detail/$key",
$output, $view );
362 array_pop( self::$callstack );
static _GET( $name, $default=null)
Grab a value from the _GET superglobal or default.
If this file is called directly, abort.
callback( $passed_atts, $content='', $tag='')
Process and output the [gravityview] shortcode.
static getInstance( $passed_post=NULL)
static _return( $value)
Pop the callstack and return the value.
If this file is called directly, abort.
static check_entry_display( $entry, $view=null)
Checks if a certain entry is valid according to the View search filters (specially the Adv Filters) ...
static get_endpoint_name()
Return the endpoint name for a single Entry.
parse_and_sanitize_atts( $passed_atts)
Validate attributes passed to the [gravityview] shortcode.
static by_id( $post_id)
Construct a instance from a post ID.
static $callstack
A stack of calls to track nested shortcodes.
static get( $array, $key, $default=null)
Grab a value from an array or an object or default.
gravityview()
The main GravityView wrapper function.
detail( $view, $entries, $atts)
Output view details.
static defaults( $detailed=false, $group=null)
Retrieve the default View settings.
gv_empty( $value, $zero_is_empty=true, $allow_string_booleans=true)
Is the value empty?
static is_approved( $status)
static has_cap( $caps='', $object_id=null, $user_id=null)
Alias of GravityView_Roles_Capabilities::has_cap()