|
1
|
|
|
<?php |
|
2
|
|
|
namespace GV; |
|
3
|
|
|
|
|
4
|
|
|
/** If this file is called directly, abort. */ |
|
5
|
|
|
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
6
|
|
|
die(); |
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* The \GV\Entry_Renderer class. |
|
11
|
|
|
* |
|
12
|
|
|
* Houses some preliminary \GV\Entry rendering functionality. |
|
13
|
|
|
*/ |
|
14
|
|
|
class Entry_Renderer extends Renderer { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Renders a single \GV\Entry instance. |
|
18
|
|
|
* |
|
19
|
|
|
* @param \GV\Entry $entry The Entry instance to render. |
|
20
|
|
|
* @param \GV\View $view The View connected to the entry. |
|
21
|
|
|
* @param \GV\Request $request The request context we're currently in. Default: `gravityview()->request` |
|
22
|
|
|
* |
|
23
|
|
|
* @api |
|
24
|
|
|
* @since 2.0 |
|
25
|
|
|
* |
|
26
|
|
|
* @return string The rendered Entry. |
|
27
|
|
|
*/ |
|
28
|
19 |
|
public function render( Entry $entry, View $view, Request $request = null ) { |
|
29
|
19 |
|
if ( is_null( $request ) ) { |
|
30
|
10 |
|
$request = &gravityview()->request; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
19 |
|
if ( ! $request->is_renderable() ) { |
|
34
|
|
|
gravityview()->log->error( 'Renderer unable to render Entry in {request_class} context', array( 'request_class' => get_class( $request ) ) ); |
|
35
|
|
|
return null; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* This View is password protected. Output the form. |
|
40
|
|
|
*/ |
|
41
|
19 |
|
if ( post_password_required( $view->ID ) ) { |
|
|
|
|
|
|
42
|
1 |
|
return get_the_password_form( $view->ID ); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @action `gravityview_render_entry_{View ID}` Before rendering a single entry for a specific View ID |
|
48
|
|
|
* @since 1.17 |
|
49
|
|
|
* |
|
50
|
|
|
* @since 2.0 |
|
51
|
|
|
* @param \GV\Entry $entry The entry about to be rendered |
|
52
|
|
|
* @param \GV\View $view The connected view |
|
53
|
|
|
* @param \GV\Request $request The associated request |
|
54
|
|
|
*/ |
|
55
|
19 |
|
do_action( 'gravityview_render_entry_' . $view->ID, $entry, $view, $request ); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** Entry does not belong to this view. */ |
|
58
|
19 |
|
if ( $view->joins ) { |
|
|
|
|
|
|
59
|
1 |
|
$form_ids = array(); |
|
60
|
1 |
|
foreach ( $view->joins as $join ) { |
|
61
|
1 |
|
$form_ids[] = $join->join->ID; |
|
|
|
|
|
|
62
|
1 |
|
$form_ids[] = $join->join_on->ID; |
|
63
|
|
|
} |
|
64
|
1 |
|
foreach ( $entry->entries as $e ) { |
|
|
|
|
|
|
65
|
1 |
|
if ( ! in_array( $e['form_id'], $form_ids ) ) { |
|
66
|
|
|
gravityview()->log->error( 'The requested entry does not belong to this View. Entry #{entry_id}, #View {view_id}', array( 'entry_id' => $e->ID, 'view_id' => $view->ID ) ); |
|
|
|
|
|
|
67
|
|
|
return null; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
18 |
|
} else if ( $view->form && $view->form->ID != $entry['form_id'] ) { |
|
71
|
|
|
gravityview()->log->error( 'The requested entry does not belong to this View. Entry #{entry_id}, #View {view_id}', array( 'entry_id' => $entry->ID, 'view_id' => $view->ID ) ); |
|
|
|
|
|
|
72
|
|
|
return null; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @filter `gravityview_template_slug_{$template_id}` Modify the template slug about to be loaded in directory views. |
|
77
|
|
|
* @since 1.6 |
|
78
|
|
|
* @param deprecated |
|
79
|
|
|
* @see The `gravityview_get_template_id` filter |
|
80
|
|
|
* @param string $slug Default: 'table' |
|
81
|
|
|
* @param string $view The current view context: single |
|
82
|
|
|
*/ |
|
83
|
19 |
|
$template_slug = apply_filters( 'gravityview_template_slug_' . $view->settings->get( 'template' ), 'table', 'single' ); |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Load a legacy override template if exists. |
|
87
|
|
|
*/ |
|
88
|
19 |
|
$override = new \GV\Legacy_Override_Template( $view, $entry, null, $request ); |
|
89
|
19 |
|
foreach ( array( 'single' ) as $part ) { |
|
90
|
19 |
|
if ( ( $path = $override->get_template_part( $template_slug, $part ) ) && strpos( $path, '/deprecated' ) === false ) { |
|
91
|
|
|
/** |
|
92
|
|
|
* We have to bail and call the legacy renderer. Crap! |
|
93
|
|
|
*/ |
|
94
|
|
|
gravityview()->log->notice( 'Legacy templates detected in theme {path}', array( 'path' => $path ) ); |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Show a warning at the top, if View is editable by the user. |
|
98
|
|
|
*/ |
|
99
|
|
|
add_action( 'gravityview_before', $this->legacy_template_warning( $view, $path ) ); |
|
100
|
|
|
|
|
101
|
|
|
return $override->render( $template_slug ); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @filter `gravityview/template/entry/class` Filter the template class that is about to be used to render the entry. |
|
107
|
|
|
* @since 2.0 |
|
108
|
|
|
* @param string $class The chosen class - Default: \GV\Entry_Table_Template. |
|
109
|
|
|
* @param \GV\Entry $entry The entry about to be rendered. |
|
110
|
|
|
* @param \GV\View $view The view connected to it. |
|
111
|
|
|
* @param \GV\Request $request The associated request. |
|
112
|
|
|
*/ |
|
113
|
19 |
|
$class = apply_filters( 'gravityview/template/entry/class', sprintf( '\GV\Entry_%s_Template', ucfirst( $template_slug ) ), $entry, $view, $request ); |
|
114
|
19 |
|
if ( ! $class || ! class_exists( $class ) ) { |
|
115
|
|
|
gravityview()->log->notice( '{template_class} not found, falling back to legacy', array( 'template_class' => $class ) ); |
|
116
|
|
|
$class = '\GV\Entry_Legacy_Template'; |
|
117
|
|
|
} |
|
118
|
19 |
|
$template = new $class( $entry, $view, $request ); |
|
119
|
|
|
|
|
120
|
|
|
add_action( 'gravityview/template/after', $view_id_output = function( $context ) { |
|
121
|
19 |
|
printf( '<input type="hidden" class="gravityview-view-id" value="%d">', $context->view->ID ); |
|
122
|
19 |
|
} ); |
|
123
|
|
|
|
|
124
|
|
|
/** Mock the legacy state for the widgets and whatnot */ |
|
125
|
19 |
|
$entries = new Entry_Collection(); |
|
126
|
19 |
|
$entries->add( $entry ); |
|
127
|
19 |
|
\GV\Mocks\Legacy_Context::push( array( |
|
128
|
19 |
|
'view' => $view, |
|
129
|
19 |
|
'entries' => $entries, |
|
130
|
19 |
|
'entry' => $entry, |
|
131
|
19 |
|
'request' => $request, |
|
132
|
|
|
) ); |
|
133
|
|
|
|
|
134
|
19 |
|
ob_start(); |
|
135
|
19 |
|
$template->render(); |
|
136
|
|
|
|
|
137
|
19 |
|
remove_action( 'gravityview/template/after', $view_id_output ); |
|
138
|
|
|
|
|
139
|
19 |
|
return ob_get_clean(); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.