|
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
|
|
|
* Load up the Gamajo Template Loader. |
|
11
|
|
|
* |
|
12
|
|
|
* @see https://github.com/GaryJones/Gamajo-Template-Loader |
|
13
|
|
|
*/ |
|
14
|
|
|
if ( ! class_exists( '\GV\Gamajo_Template_Loader' ) ) { |
|
15
|
|
|
require gravityview()->plugin->dir( 'future/lib/class-gamajo-template-loader.php' ); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The View Template class . |
|
20
|
|
|
* |
|
21
|
|
|
* Renders a \GV\View and a \GV\Entry_Collection via a \GV\View_Renderer. |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class View_Template extends Template { |
|
24
|
|
|
/** |
|
25
|
|
|
* Prefix for filter names. |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $filter_prefix = 'gravityview/template/views'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Directory name where custom templates for this plugin should be found in the theme. |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $theme_template_directory = 'gravityview/views/'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Directory name where the default templates for this plugin are found. |
|
38
|
|
|
* @var string |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $plugin_template_directory = 'templates/views/'; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @var \GV\View The view connected to this template. |
|
44
|
|
|
*/ |
|
45
|
|
|
public $view; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var \GV\Entry_Collection The entries that need to be rendered. |
|
49
|
|
|
*/ |
|
50
|
|
|
public $entries; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @var \GV\Request The request context. |
|
54
|
|
|
*/ |
|
55
|
|
|
public $request; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var string The template slug to be loaded (like "table", "list") |
|
59
|
|
|
*/ |
|
60
|
|
|
public static $slug; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Initializer. |
|
64
|
|
|
* |
|
65
|
|
|
* @param \GV\View $view The View connected to this template. |
|
66
|
|
|
* @param \GV\Entry_Collection $entries A collection of entries for this view. |
|
67
|
|
|
* @param \GV\Request $request The request context. |
|
68
|
|
|
*/ |
|
69
|
2 |
|
public function __construct( View $view, Entry_Collection $entries, Request $request ) { |
|
70
|
2 |
|
$this->view = $view; |
|
71
|
2 |
|
$this->entries = $entries; |
|
72
|
2 |
|
$this->request = $request; |
|
73
|
|
|
|
|
74
|
|
|
/** Add granular overrides. */ |
|
75
|
2 |
|
add_filter( $this->filter_prefix . '_get_template_part', array( $this, 'add_id_specific_templates' ), 10, 3 ); |
|
76
|
|
|
|
|
77
|
2 |
|
parent::__construct(); |
|
78
|
2 |
|
} |
|
79
|
|
|
|
|
80
|
2 |
|
public function __destruct() { |
|
81
|
2 |
|
remove_filter( $this->filter_prefix . '_get_template_part', array( $this, 'add_id_specific_templates' ) ); |
|
82
|
2 |
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Enable granular template overrides based on current post, view, form, etc. |
|
86
|
|
|
* |
|
87
|
|
|
* The loading order is: |
|
88
|
|
|
* |
|
89
|
|
|
* - post-[ID of post or page where view is embedded]-view-[View ID]-table-footer.php |
|
90
|
|
|
* - post-[ID of post or page where view is embedded]-table-footer.php |
|
91
|
|
|
* - view-[View ID]-table-footer.php |
|
92
|
|
|
* - form-[Form ID]-table-footer.php |
|
93
|
|
|
* - table-footer.php |
|
94
|
|
|
* |
|
95
|
|
|
* @see Gamajo_Template_Loader::get_template_file_names() Where the filter is |
|
96
|
|
|
* @param array $templates Existing list of templates. |
|
97
|
|
|
* @param string $slug Name of the template base, example: `table`, `list`, `datatables`, `map` |
|
98
|
|
|
* @param string $name Name of the template part, example: `body`, `footer`, `head`, `single` |
|
99
|
|
|
* |
|
100
|
|
|
* @return array $templates Modified template array, merged with existing $templates values |
|
101
|
|
|
*/ |
|
102
|
2 |
|
public function add_id_specific_templates( $templates, $slug, $name ) { |
|
103
|
|
|
|
|
104
|
2 |
|
$specifics = array(); |
|
105
|
|
|
|
|
106
|
2 |
|
list( $slug_dir, $slug_name ) = self::split_slug( $slug, $name ); |
|
107
|
|
|
|
|
108
|
2 |
|
global $post; |
|
109
|
|
|
|
|
110
|
2 |
|
if ( ! $this->request->is_view() && $post ) { |
|
111
|
|
|
$specifics []= sprintf( '%spost-%d-view-%d-%s.php', $slug_dir, $post->ID, $this->view->ID, $slug_name ); |
|
|
|
|
|
|
112
|
|
|
$specifics []= sprintf( '%spost-%d-%s.php', $slug_dir, $post->ID, $slug_name ); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
|
|
116
|
2 |
|
$specifics []= sprintf( '%sview-%d-%s.php', $slug_dir, $this->view->ID, $slug_name ); |
|
|
|
|
|
|
117
|
2 |
|
$specifics []= sprintf( '%sform-%d-%s.php', $slug_dir, $this->view->form->ID, $slug_name ); |
|
118
|
|
|
|
|
119
|
2 |
|
return array_merge( $specifics, $templates ); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Output some HTML. |
|
124
|
|
|
* |
|
125
|
|
|
* @return void |
|
126
|
|
|
*/ |
|
127
|
2 |
|
public function render() { |
|
128
|
2 |
|
$context = Template_Context::from_template( $this ); |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Make various pieces of data available to the template |
|
132
|
|
|
* under the $gravityview scoped variable. |
|
133
|
|
|
* |
|
134
|
|
|
* @filter `gravityview/template/view/context` |
|
135
|
|
|
* @param \GV\Template_Context $context The context for this template. |
|
136
|
|
|
* @param \GV\View_Template $template The current template. |
|
137
|
|
|
* @since 2.0 |
|
138
|
|
|
*/ |
|
139
|
2 |
|
$this->push_template_data( $context = apply_filters( 'gravityview/template/view/context', $context, $this ), 'gravityview' ); |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @filter `gravityview/template/view/render` Before rendering. |
|
143
|
|
|
* @param \GV\View_Template $template The current template. |
|
144
|
|
|
* @since 2.0 |
|
145
|
|
|
*/ |
|
146
|
2 |
|
do_action( 'gravityview/template/view/render', $context ); |
|
147
|
|
|
|
|
148
|
|
|
/** Load the template. */ |
|
149
|
2 |
|
$this->get_template_part( static::$slug ); |
|
150
|
2 |
|
$this->pop_template_data( 'gravityview' ); |
|
151
|
2 |
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** Load implementations. */ |
|
155
|
|
|
require gravityview()->plugin->dir( 'future/includes/class-gv-template-view-table.php' ); |
|
156
|
|
|
require gravityview()->plugin->dir( 'future/includes/class-gv-template-view-list.php' ); |
|
157
|
|
|
require gravityview()->plugin->dir( 'future/includes/class-gv-template-view-legacy.php' ); |
|
158
|
|
|
|
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.