@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | 6 | if (!defined('GRAVITYVIEW_DIR')) { |
7 | - exit(); |
|
7 | + exit(); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * @see https://github.com/GaryJones/Gamajo-Template-Loader |
14 | 14 | */ |
15 | 15 | if (!class_exists('\GV\Gamajo_Template_Loader')) { |
16 | - require gravityview()->plugin->dir('future/lib/class-gamajo-template-loader.php'); |
|
16 | + require gravityview()->plugin->dir('future/lib/class-gamajo-template-loader.php'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -23,222 +23,222 @@ discard block |
||
23 | 23 | */ |
24 | 24 | class Legacy_Override_Template extends \GV\Gamajo_Template_Loader |
25 | 25 | { |
26 | - /** |
|
27 | - * Prefix for filter names. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $filter_prefix = 'gravityview'; |
|
32 | - |
|
33 | - /** |
|
34 | - * Directory name where custom templates for this plugin should be found in the theme. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $theme_template_directory = 'gravityview'; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var \GV\View The view we're working with. |
|
42 | - */ |
|
43 | - private $view; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var \GV\Entry The entry we're working with. |
|
47 | - */ |
|
48 | - private $entry; |
|
49 | - |
|
50 | - /** |
|
51 | - * Catch deprecated template loads. |
|
52 | - * |
|
53 | - * @param \GV\View $view The View. |
|
54 | - * @param \GV\Entry $entry The Entry. |
|
55 | - * @param \GV\Field $field The Field. |
|
56 | - * @param \GV\Request $request The request. |
|
57 | - * |
|
58 | - * @return void |
|
59 | - */ |
|
60 | - public function __construct(\GV\View $view, \GV\Entry $entry = null, \GV\Field $field = null, \GV\Request $request = null) |
|
61 | - { |
|
62 | - add_filter($this->filter_prefix.'_get_template_part', [$this, 'add_id_specific_templates'], 10, 3); |
|
63 | - |
|
64 | - $this->view = $view; |
|
65 | - $this->entry = $entry; |
|
66 | - |
|
67 | - $this->plugin_directory = gravityview()->plugin->dir(); |
|
68 | - $this->plugin_template_directory = 'templates/deprecated/'; |
|
69 | - } |
|
70 | - |
|
71 | - public function __destruct() |
|
72 | - { |
|
73 | - remove_filter($this->filter_prefix.'_get_template_part', [$this, 'add_id_specific_templates']); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @inheritdoc |
|
78 | - * |
|
79 | - * @see Gamajo_Template_Loader::locate_template() |
|
80 | - * |
|
81 | - * @return null|string NULL: Template not found; String: path to template |
|
82 | - */ |
|
83 | - public function locate_template($template_names, $load = false, $require_once = false) |
|
84 | - { |
|
85 | - return parent::locate_template($template_names, false, false); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Enable overrides of GravityView templates on a granular basis. |
|
90 | - * |
|
91 | - * The loading order is: |
|
92 | - * |
|
93 | - * - view-[View ID]-table-footer.php |
|
94 | - * - form-[Form ID]-table-footer.php |
|
95 | - * - page-[ID of post or page where view is embedded]-table-footer.php |
|
96 | - * - table-footer.php |
|
97 | - * |
|
98 | - * @see Gamajo_Template_Loader::get_template_file_names() Where the filter is |
|
99 | - * |
|
100 | - * @param array $templates Existing list of templates. |
|
101 | - * @param string $slug Name of the template base, example: `table`, `list`, `datatables`, `map` |
|
102 | - * @param string $name Name of the template part, example: `body`, `footer`, `head`, `single` |
|
103 | - * |
|
104 | - * @return array $templates Modified template array, merged with existing $templates values |
|
105 | - */ |
|
106 | - public function add_id_specific_templates($templates, $slug, $name) |
|
107 | - { |
|
108 | - $additional = []; |
|
109 | - |
|
110 | - // form-19-table-body.php |
|
111 | - $additional[] = sprintf('form-%d-%s-%s.php', $this->view->form ? $this->view->form->ID : 0, $slug, $name); |
|
112 | - |
|
113 | - // view-3-table-body.php |
|
114 | - $additional[] = sprintf('view-%d-%s-%s.php', $this->view->ID, $slug, $name); |
|
115 | - |
|
116 | - global $post; |
|
117 | - if ($post) { |
|
118 | - // page-19-table-body.php |
|
119 | - $additional[] = sprintf('page-%d-%s-%s.php', $post->ID, $slug, $name); |
|
120 | - } |
|
121 | - |
|
122 | - // Combine with existing table-body.php and table.php |
|
123 | - $templates = array_merge($additional, $templates); |
|
124 | - |
|
125 | - return $templates; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Setup legacy rendering. |
|
130 | - * |
|
131 | - * @param string $slug The slug. |
|
132 | - * |
|
133 | - * @return string The output. |
|
134 | - */ |
|
135 | - public function render($slug) |
|
136 | - { |
|
137 | - add_action('gravityview/template/after', $view_id_output = function ($context) { |
|
138 | - printf('<input type="hidden" class="gravityview-view-id" value="%d">', $context->view->ID); |
|
139 | - }); |
|
140 | - |
|
141 | - ob_start(); |
|
142 | - |
|
143 | - $request = new Mock_Request(); |
|
144 | - $request->returns['is_view'] = $this->view; |
|
145 | - |
|
146 | - /** |
|
147 | - * You got one shot. One opportunity. To render all the widgets you have ever wanted. |
|
148 | - * |
|
149 | - * Since we're overriding the singleton we need to remove the widget actions since they can only |
|
150 | - * be called once in a request (did_action/do_action mutex). |
|
151 | - * |
|
152 | - * Oh, and Mom's spaghetti. |
|
153 | - */ |
|
154 | - global $wp_filter; |
|
155 | - foreach (['gravityview_before', 'gravityview_after'] as $hook) { |
|
156 | - foreach ($wp_filter[$hook]->callbacks[10] as $function_key => $callback) { |
|
157 | - if (strpos($function_key, 'render_widget_hooks')) { |
|
158 | - unset($wp_filter[$hook]->callbacks[10][$function_key]); |
|
159 | - } |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Single entry view. |
|
165 | - */ |
|
166 | - if ($this->entry) { |
|
167 | - $request->returns['is_entry'] = $this->entry; |
|
168 | - |
|
169 | - global $post; |
|
170 | - |
|
171 | - $entries = new Entry_Collection(); |
|
172 | - $entries->add($this->entry); |
|
173 | - |
|
174 | - \GV\Mocks\Legacy_Context::push([ |
|
175 | - 'view' => $this->view, |
|
176 | - 'entry' => $this->entry, |
|
177 | - 'entries' => $entries, |
|
178 | - 'request' => $request, |
|
179 | - 'fields' => $this->view->fields->by_visible($this->view), |
|
180 | - 'in_the_loop' => true, |
|
181 | - ]); |
|
182 | - |
|
183 | - \GravityView_View::getInstance()->setTemplatePartSlug($slug); |
|
184 | - \GravityView_View::getInstance()->setTemplatePartName('single'); |
|
185 | - |
|
186 | - \GravityView_View::getInstance()->_include($this->get_template_part($slug, 'single')); |
|
187 | - |
|
188 | - Mocks\Legacy_Context::pop(); |
|
189 | - |
|
190 | - /** |
|
191 | - * Directory view. |
|
192 | - */ |
|
193 | - } else { |
|
194 | - $entries = $this->view->get_entries($request); |
|
195 | - |
|
196 | - /** |
|
197 | - * Remove multiple sorting before calling legacy filters. |
|
198 | - * This allows us to fake it till we make it. |
|
199 | - */ |
|
200 | - $parameters = $this->view->settings->as_atts(); |
|
201 | - if (!empty($parameters['sort_field']) && is_array($parameters['sort_field'])) { |
|
202 | - $has_multisort = true; |
|
203 | - $parameters['sort_field'] = reset($parameters['sort_field']); |
|
204 | - if (!empty($parameters['sort_direction']) && is_array($parameters['sort_direction'])) { |
|
205 | - $parameters['sort_direction'] = reset($parameters['sort_direction']); |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - $parameters = \GravityView_frontend::get_view_entries_parameters($parameters, $this->view->form->ID); |
|
210 | - |
|
211 | - global $post; |
|
212 | - |
|
213 | - add_action('gravityview_before', [\GravityView_View::getInstance(), 'render_widget_hooks']); |
|
214 | - add_action('gravityview_after', [\GravityView_View::getInstance(), 'render_widget_hooks']); |
|
215 | - |
|
216 | - foreach (['header', 'body', 'footer'] as $part) { |
|
217 | - \GV\Mocks\Legacy_Context::push(array_merge([ |
|
218 | - 'view' => $this->view, |
|
219 | - 'entries' => $entries, |
|
220 | - 'request' => $request, |
|
221 | - 'fields' => $this->view->fields->by_visible($this->view), |
|
222 | - 'in_the_loop' => true, |
|
223 | - ], empty($parameters) ? [] : [ |
|
224 | - 'paging' => $parameters['paging'], |
|
225 | - 'sorting' => $parameters['sorting'], |
|
226 | - ], $post ? [ |
|
227 | - 'post' => $post, |
|
228 | - ] : [])); |
|
229 | - |
|
230 | - \GravityView_View::getInstance()->setTemplatePartSlug($slug); |
|
231 | - |
|
232 | - \GravityView_View::getInstance()->setTemplatePartName($part); |
|
233 | - |
|
234 | - \GravityView_View::getInstance()->_include($this->get_template_part($slug, $part)); |
|
235 | - |
|
236 | - Mocks\Legacy_Context::pop(); |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - remove_action('gravityview/template/after', $view_id_output); |
|
241 | - |
|
242 | - return ob_get_clean(); |
|
243 | - } |
|
26 | + /** |
|
27 | + * Prefix for filter names. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $filter_prefix = 'gravityview'; |
|
32 | + |
|
33 | + /** |
|
34 | + * Directory name where custom templates for this plugin should be found in the theme. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $theme_template_directory = 'gravityview'; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var \GV\View The view we're working with. |
|
42 | + */ |
|
43 | + private $view; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var \GV\Entry The entry we're working with. |
|
47 | + */ |
|
48 | + private $entry; |
|
49 | + |
|
50 | + /** |
|
51 | + * Catch deprecated template loads. |
|
52 | + * |
|
53 | + * @param \GV\View $view The View. |
|
54 | + * @param \GV\Entry $entry The Entry. |
|
55 | + * @param \GV\Field $field The Field. |
|
56 | + * @param \GV\Request $request The request. |
|
57 | + * |
|
58 | + * @return void |
|
59 | + */ |
|
60 | + public function __construct(\GV\View $view, \GV\Entry $entry = null, \GV\Field $field = null, \GV\Request $request = null) |
|
61 | + { |
|
62 | + add_filter($this->filter_prefix.'_get_template_part', [$this, 'add_id_specific_templates'], 10, 3); |
|
63 | + |
|
64 | + $this->view = $view; |
|
65 | + $this->entry = $entry; |
|
66 | + |
|
67 | + $this->plugin_directory = gravityview()->plugin->dir(); |
|
68 | + $this->plugin_template_directory = 'templates/deprecated/'; |
|
69 | + } |
|
70 | + |
|
71 | + public function __destruct() |
|
72 | + { |
|
73 | + remove_filter($this->filter_prefix.'_get_template_part', [$this, 'add_id_specific_templates']); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @inheritdoc |
|
78 | + * |
|
79 | + * @see Gamajo_Template_Loader::locate_template() |
|
80 | + * |
|
81 | + * @return null|string NULL: Template not found; String: path to template |
|
82 | + */ |
|
83 | + public function locate_template($template_names, $load = false, $require_once = false) |
|
84 | + { |
|
85 | + return parent::locate_template($template_names, false, false); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Enable overrides of GravityView templates on a granular basis. |
|
90 | + * |
|
91 | + * The loading order is: |
|
92 | + * |
|
93 | + * - view-[View ID]-table-footer.php |
|
94 | + * - form-[Form ID]-table-footer.php |
|
95 | + * - page-[ID of post or page where view is embedded]-table-footer.php |
|
96 | + * - table-footer.php |
|
97 | + * |
|
98 | + * @see Gamajo_Template_Loader::get_template_file_names() Where the filter is |
|
99 | + * |
|
100 | + * @param array $templates Existing list of templates. |
|
101 | + * @param string $slug Name of the template base, example: `table`, `list`, `datatables`, `map` |
|
102 | + * @param string $name Name of the template part, example: `body`, `footer`, `head`, `single` |
|
103 | + * |
|
104 | + * @return array $templates Modified template array, merged with existing $templates values |
|
105 | + */ |
|
106 | + public function add_id_specific_templates($templates, $slug, $name) |
|
107 | + { |
|
108 | + $additional = []; |
|
109 | + |
|
110 | + // form-19-table-body.php |
|
111 | + $additional[] = sprintf('form-%d-%s-%s.php', $this->view->form ? $this->view->form->ID : 0, $slug, $name); |
|
112 | + |
|
113 | + // view-3-table-body.php |
|
114 | + $additional[] = sprintf('view-%d-%s-%s.php', $this->view->ID, $slug, $name); |
|
115 | + |
|
116 | + global $post; |
|
117 | + if ($post) { |
|
118 | + // page-19-table-body.php |
|
119 | + $additional[] = sprintf('page-%d-%s-%s.php', $post->ID, $slug, $name); |
|
120 | + } |
|
121 | + |
|
122 | + // Combine with existing table-body.php and table.php |
|
123 | + $templates = array_merge($additional, $templates); |
|
124 | + |
|
125 | + return $templates; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Setup legacy rendering. |
|
130 | + * |
|
131 | + * @param string $slug The slug. |
|
132 | + * |
|
133 | + * @return string The output. |
|
134 | + */ |
|
135 | + public function render($slug) |
|
136 | + { |
|
137 | + add_action('gravityview/template/after', $view_id_output = function ($context) { |
|
138 | + printf('<input type="hidden" class="gravityview-view-id" value="%d">', $context->view->ID); |
|
139 | + }); |
|
140 | + |
|
141 | + ob_start(); |
|
142 | + |
|
143 | + $request = new Mock_Request(); |
|
144 | + $request->returns['is_view'] = $this->view; |
|
145 | + |
|
146 | + /** |
|
147 | + * You got one shot. One opportunity. To render all the widgets you have ever wanted. |
|
148 | + * |
|
149 | + * Since we're overriding the singleton we need to remove the widget actions since they can only |
|
150 | + * be called once in a request (did_action/do_action mutex). |
|
151 | + * |
|
152 | + * Oh, and Mom's spaghetti. |
|
153 | + */ |
|
154 | + global $wp_filter; |
|
155 | + foreach (['gravityview_before', 'gravityview_after'] as $hook) { |
|
156 | + foreach ($wp_filter[$hook]->callbacks[10] as $function_key => $callback) { |
|
157 | + if (strpos($function_key, 'render_widget_hooks')) { |
|
158 | + unset($wp_filter[$hook]->callbacks[10][$function_key]); |
|
159 | + } |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Single entry view. |
|
165 | + */ |
|
166 | + if ($this->entry) { |
|
167 | + $request->returns['is_entry'] = $this->entry; |
|
168 | + |
|
169 | + global $post; |
|
170 | + |
|
171 | + $entries = new Entry_Collection(); |
|
172 | + $entries->add($this->entry); |
|
173 | + |
|
174 | + \GV\Mocks\Legacy_Context::push([ |
|
175 | + 'view' => $this->view, |
|
176 | + 'entry' => $this->entry, |
|
177 | + 'entries' => $entries, |
|
178 | + 'request' => $request, |
|
179 | + 'fields' => $this->view->fields->by_visible($this->view), |
|
180 | + 'in_the_loop' => true, |
|
181 | + ]); |
|
182 | + |
|
183 | + \GravityView_View::getInstance()->setTemplatePartSlug($slug); |
|
184 | + \GravityView_View::getInstance()->setTemplatePartName('single'); |
|
185 | + |
|
186 | + \GravityView_View::getInstance()->_include($this->get_template_part($slug, 'single')); |
|
187 | + |
|
188 | + Mocks\Legacy_Context::pop(); |
|
189 | + |
|
190 | + /** |
|
191 | + * Directory view. |
|
192 | + */ |
|
193 | + } else { |
|
194 | + $entries = $this->view->get_entries($request); |
|
195 | + |
|
196 | + /** |
|
197 | + * Remove multiple sorting before calling legacy filters. |
|
198 | + * This allows us to fake it till we make it. |
|
199 | + */ |
|
200 | + $parameters = $this->view->settings->as_atts(); |
|
201 | + if (!empty($parameters['sort_field']) && is_array($parameters['sort_field'])) { |
|
202 | + $has_multisort = true; |
|
203 | + $parameters['sort_field'] = reset($parameters['sort_field']); |
|
204 | + if (!empty($parameters['sort_direction']) && is_array($parameters['sort_direction'])) { |
|
205 | + $parameters['sort_direction'] = reset($parameters['sort_direction']); |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + $parameters = \GravityView_frontend::get_view_entries_parameters($parameters, $this->view->form->ID); |
|
210 | + |
|
211 | + global $post; |
|
212 | + |
|
213 | + add_action('gravityview_before', [\GravityView_View::getInstance(), 'render_widget_hooks']); |
|
214 | + add_action('gravityview_after', [\GravityView_View::getInstance(), 'render_widget_hooks']); |
|
215 | + |
|
216 | + foreach (['header', 'body', 'footer'] as $part) { |
|
217 | + \GV\Mocks\Legacy_Context::push(array_merge([ |
|
218 | + 'view' => $this->view, |
|
219 | + 'entries' => $entries, |
|
220 | + 'request' => $request, |
|
221 | + 'fields' => $this->view->fields->by_visible($this->view), |
|
222 | + 'in_the_loop' => true, |
|
223 | + ], empty($parameters) ? [] : [ |
|
224 | + 'paging' => $parameters['paging'], |
|
225 | + 'sorting' => $parameters['sorting'], |
|
226 | + ], $post ? [ |
|
227 | + 'post' => $post, |
|
228 | + ] : [])); |
|
229 | + |
|
230 | + \GravityView_View::getInstance()->setTemplatePartSlug($slug); |
|
231 | + |
|
232 | + \GravityView_View::getInstance()->setTemplatePartName($part); |
|
233 | + |
|
234 | + \GravityView_View::getInstance()->_include($this->get_template_part($slug, $part)); |
|
235 | + |
|
236 | + Mocks\Legacy_Context::pop(); |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + remove_action('gravityview/template/after', $view_id_output); |
|
241 | + |
|
242 | + return ob_get_clean(); |
|
243 | + } |
|
244 | 244 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace GV; |
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | -if (!defined('GRAVITYVIEW_DIR')) { |
|
6 | +if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
7 | 7 | exit(); |
8 | 8 | } |
9 | 9 | |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | * |
13 | 13 | * @see https://github.com/GaryJones/Gamajo-Template-Loader |
14 | 14 | */ |
15 | -if (!class_exists('\GV\Gamajo_Template_Loader')) { |
|
16 | - require gravityview()->plugin->dir('future/lib/class-gamajo-template-loader.php'); |
|
15 | +if ( ! class_exists( '\GV\Gamajo_Template_Loader' ) ) { |
|
16 | + require gravityview()->plugin->dir( 'future/lib/class-gamajo-template-loader.php' ); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return void |
59 | 59 | */ |
60 | - public function __construct(\GV\View $view, \GV\Entry $entry = null, \GV\Field $field = null, \GV\Request $request = null) |
|
60 | + public function __construct( \GV\View $view, \GV\Entry $entry = null, \GV\Field $field = null, \GV\Request $request = null ) |
|
61 | 61 | { |
62 | - add_filter($this->filter_prefix.'_get_template_part', [$this, 'add_id_specific_templates'], 10, 3); |
|
62 | + add_filter( $this->filter_prefix . '_get_template_part', [ $this, 'add_id_specific_templates' ], 10, 3 ); |
|
63 | 63 | |
64 | 64 | $this->view = $view; |
65 | 65 | $this->entry = $entry; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | |
71 | 71 | public function __destruct() |
72 | 72 | { |
73 | - remove_filter($this->filter_prefix.'_get_template_part', [$this, 'add_id_specific_templates']); |
|
73 | + remove_filter( $this->filter_prefix . '_get_template_part', [ $this, 'add_id_specific_templates' ] ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return null|string NULL: Template not found; String: path to template |
82 | 82 | */ |
83 | - public function locate_template($template_names, $load = false, $require_once = false) |
|
83 | + public function locate_template( $template_names, $load = false, $require_once = false ) |
|
84 | 84 | { |
85 | - return parent::locate_template($template_names, false, false); |
|
85 | + return parent::locate_template( $template_names, false, false ); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -103,24 +103,24 @@ discard block |
||
103 | 103 | * |
104 | 104 | * @return array $templates Modified template array, merged with existing $templates values |
105 | 105 | */ |
106 | - public function add_id_specific_templates($templates, $slug, $name) |
|
106 | + public function add_id_specific_templates( $templates, $slug, $name ) |
|
107 | 107 | { |
108 | - $additional = []; |
|
108 | + $additional = [ ]; |
|
109 | 109 | |
110 | 110 | // form-19-table-body.php |
111 | - $additional[] = sprintf('form-%d-%s-%s.php', $this->view->form ? $this->view->form->ID : 0, $slug, $name); |
|
111 | + $additional[ ] = sprintf( 'form-%d-%s-%s.php', $this->view->form ? $this->view->form->ID : 0, $slug, $name ); |
|
112 | 112 | |
113 | 113 | // view-3-table-body.php |
114 | - $additional[] = sprintf('view-%d-%s-%s.php', $this->view->ID, $slug, $name); |
|
114 | + $additional[ ] = sprintf( 'view-%d-%s-%s.php', $this->view->ID, $slug, $name ); |
|
115 | 115 | |
116 | 116 | global $post; |
117 | - if ($post) { |
|
117 | + if ( $post ) { |
|
118 | 118 | // page-19-table-body.php |
119 | - $additional[] = sprintf('page-%d-%s-%s.php', $post->ID, $slug, $name); |
|
119 | + $additional[ ] = sprintf( 'page-%d-%s-%s.php', $post->ID, $slug, $name ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | // Combine with existing table-body.php and table.php |
123 | - $templates = array_merge($additional, $templates); |
|
123 | + $templates = array_merge( $additional, $templates ); |
|
124 | 124 | |
125 | 125 | return $templates; |
126 | 126 | } |
@@ -132,16 +132,16 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return string The output. |
134 | 134 | */ |
135 | - public function render($slug) |
|
135 | + public function render( $slug ) |
|
136 | 136 | { |
137 | - add_action('gravityview/template/after', $view_id_output = function ($context) { |
|
138 | - printf('<input type="hidden" class="gravityview-view-id" value="%d">', $context->view->ID); |
|
137 | + add_action( 'gravityview/template/after', $view_id_output = function( $context ) { |
|
138 | + printf( '<input type="hidden" class="gravityview-view-id" value="%d">', $context->view->ID ); |
|
139 | 139 | }); |
140 | 140 | |
141 | 141 | ob_start(); |
142 | 142 | |
143 | 143 | $request = new Mock_Request(); |
144 | - $request->returns['is_view'] = $this->view; |
|
144 | + $request->returns[ 'is_view' ] = $this->view; |
|
145 | 145 | |
146 | 146 | /** |
147 | 147 | * You got one shot. One opportunity. To render all the widgets you have ever wanted. |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | * Oh, and Mom's spaghetti. |
153 | 153 | */ |
154 | 154 | global $wp_filter; |
155 | - foreach (['gravityview_before', 'gravityview_after'] as $hook) { |
|
156 | - foreach ($wp_filter[$hook]->callbacks[10] as $function_key => $callback) { |
|
157 | - if (strpos($function_key, 'render_widget_hooks')) { |
|
158 | - unset($wp_filter[$hook]->callbacks[10][$function_key]); |
|
155 | + foreach ( [ 'gravityview_before', 'gravityview_after' ] as $hook ) { |
|
156 | + foreach ( $wp_filter[ $hook ]->callbacks[ 10 ] as $function_key => $callback ) { |
|
157 | + if ( strpos( $function_key, 'render_widget_hooks' ) ) { |
|
158 | + unset( $wp_filter[ $hook ]->callbacks[ 10 ][ $function_key ] ); |
|
159 | 159 | } |
160 | 160 | } |
161 | 161 | } |
@@ -163,27 +163,27 @@ discard block |
||
163 | 163 | /** |
164 | 164 | * Single entry view. |
165 | 165 | */ |
166 | - if ($this->entry) { |
|
167 | - $request->returns['is_entry'] = $this->entry; |
|
166 | + if ( $this->entry ) { |
|
167 | + $request->returns[ 'is_entry' ] = $this->entry; |
|
168 | 168 | |
169 | 169 | global $post; |
170 | 170 | |
171 | 171 | $entries = new Entry_Collection(); |
172 | - $entries->add($this->entry); |
|
172 | + $entries->add( $this->entry ); |
|
173 | 173 | |
174 | - \GV\Mocks\Legacy_Context::push([ |
|
174 | + \GV\Mocks\Legacy_Context::push( [ |
|
175 | 175 | 'view' => $this->view, |
176 | 176 | 'entry' => $this->entry, |
177 | 177 | 'entries' => $entries, |
178 | 178 | 'request' => $request, |
179 | - 'fields' => $this->view->fields->by_visible($this->view), |
|
179 | + 'fields' => $this->view->fields->by_visible( $this->view ), |
|
180 | 180 | 'in_the_loop' => true, |
181 | - ]); |
|
181 | + ] ); |
|
182 | 182 | |
183 | - \GravityView_View::getInstance()->setTemplatePartSlug($slug); |
|
184 | - \GravityView_View::getInstance()->setTemplatePartName('single'); |
|
183 | + \GravityView_View::getInstance()->setTemplatePartSlug( $slug ); |
|
184 | + \GravityView_View::getInstance()->setTemplatePartName( 'single' ); |
|
185 | 185 | |
186 | - \GravityView_View::getInstance()->_include($this->get_template_part($slug, 'single')); |
|
186 | + \GravityView_View::getInstance()->_include( $this->get_template_part( $slug, 'single' ) ); |
|
187 | 187 | |
188 | 188 | Mocks\Legacy_Context::pop(); |
189 | 189 | |
@@ -191,53 +191,53 @@ discard block |
||
191 | 191 | * Directory view. |
192 | 192 | */ |
193 | 193 | } else { |
194 | - $entries = $this->view->get_entries($request); |
|
194 | + $entries = $this->view->get_entries( $request ); |
|
195 | 195 | |
196 | 196 | /** |
197 | 197 | * Remove multiple sorting before calling legacy filters. |
198 | 198 | * This allows us to fake it till we make it. |
199 | 199 | */ |
200 | 200 | $parameters = $this->view->settings->as_atts(); |
201 | - if (!empty($parameters['sort_field']) && is_array($parameters['sort_field'])) { |
|
201 | + if ( ! empty( $parameters[ 'sort_field' ] ) && is_array( $parameters[ 'sort_field' ] ) ) { |
|
202 | 202 | $has_multisort = true; |
203 | - $parameters['sort_field'] = reset($parameters['sort_field']); |
|
204 | - if (!empty($parameters['sort_direction']) && is_array($parameters['sort_direction'])) { |
|
205 | - $parameters['sort_direction'] = reset($parameters['sort_direction']); |
|
203 | + $parameters[ 'sort_field' ] = reset( $parameters[ 'sort_field' ] ); |
|
204 | + if ( ! empty( $parameters[ 'sort_direction' ] ) && is_array( $parameters[ 'sort_direction' ] ) ) { |
|
205 | + $parameters[ 'sort_direction' ] = reset( $parameters[ 'sort_direction' ] ); |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
209 | - $parameters = \GravityView_frontend::get_view_entries_parameters($parameters, $this->view->form->ID); |
|
209 | + $parameters = \GravityView_frontend::get_view_entries_parameters( $parameters, $this->view->form->ID ); |
|
210 | 210 | |
211 | 211 | global $post; |
212 | 212 | |
213 | - add_action('gravityview_before', [\GravityView_View::getInstance(), 'render_widget_hooks']); |
|
214 | - add_action('gravityview_after', [\GravityView_View::getInstance(), 'render_widget_hooks']); |
|
213 | + add_action( 'gravityview_before', [ \GravityView_View::getInstance(), 'render_widget_hooks' ] ); |
|
214 | + add_action( 'gravityview_after', [ \GravityView_View::getInstance(), 'render_widget_hooks' ] ); |
|
215 | 215 | |
216 | - foreach (['header', 'body', 'footer'] as $part) { |
|
217 | - \GV\Mocks\Legacy_Context::push(array_merge([ |
|
216 | + foreach ( [ 'header', 'body', 'footer' ] as $part ) { |
|
217 | + \GV\Mocks\Legacy_Context::push( array_merge( [ |
|
218 | 218 | 'view' => $this->view, |
219 | 219 | 'entries' => $entries, |
220 | 220 | 'request' => $request, |
221 | - 'fields' => $this->view->fields->by_visible($this->view), |
|
221 | + 'fields' => $this->view->fields->by_visible( $this->view ), |
|
222 | 222 | 'in_the_loop' => true, |
223 | - ], empty($parameters) ? [] : [ |
|
224 | - 'paging' => $parameters['paging'], |
|
225 | - 'sorting' => $parameters['sorting'], |
|
223 | + ], empty( $parameters ) ? [ ] : [ |
|
224 | + 'paging' => $parameters[ 'paging' ], |
|
225 | + 'sorting' => $parameters[ 'sorting' ], |
|
226 | 226 | ], $post ? [ |
227 | 227 | 'post' => $post, |
228 | - ] : [])); |
|
228 | + ] : [ ] ) ); |
|
229 | 229 | |
230 | - \GravityView_View::getInstance()->setTemplatePartSlug($slug); |
|
230 | + \GravityView_View::getInstance()->setTemplatePartSlug( $slug ); |
|
231 | 231 | |
232 | - \GravityView_View::getInstance()->setTemplatePartName($part); |
|
232 | + \GravityView_View::getInstance()->setTemplatePartName( $part ); |
|
233 | 233 | |
234 | - \GravityView_View::getInstance()->_include($this->get_template_part($slug, $part)); |
|
234 | + \GravityView_View::getInstance()->_include( $this->get_template_part( $slug, $part ) ); |
|
235 | 235 | |
236 | 236 | Mocks\Legacy_Context::pop(); |
237 | 237 | } |
238 | 238 | } |
239 | 239 | |
240 | - remove_action('gravityview/template/after', $view_id_output); |
|
240 | + remove_action( 'gravityview/template/after', $view_id_output ); |
|
241 | 241 | |
242 | 242 | return ob_get_clean(); |
243 | 243 | } |
@@ -57,8 +57,7 @@ discard block |
||
57 | 57 | * |
58 | 58 | * @return void |
59 | 59 | */ |
60 | - public function __construct(\GV\View $view, \GV\Entry $entry = null, \GV\Field $field = null, \GV\Request $request = null) |
|
61 | - { |
|
60 | + public function __construct(\GV\View $view, \GV\Entry $entry = null, \GV\Field $field = null, \GV\Request $request = null) { |
|
62 | 61 | add_filter($this->filter_prefix.'_get_template_part', [$this, 'add_id_specific_templates'], 10, 3); |
63 | 62 | |
64 | 63 | $this->view = $view; |
@@ -68,8 +67,7 @@ discard block |
||
68 | 67 | $this->plugin_template_directory = 'templates/deprecated/'; |
69 | 68 | } |
70 | 69 | |
71 | - public function __destruct() |
|
72 | - { |
|
70 | + public function __destruct() { |
|
73 | 71 | remove_filter($this->filter_prefix.'_get_template_part', [$this, 'add_id_specific_templates']); |
74 | 72 | } |
75 | 73 | |
@@ -80,8 +78,7 @@ discard block |
||
80 | 78 | * |
81 | 79 | * @return null|string NULL: Template not found; String: path to template |
82 | 80 | */ |
83 | - public function locate_template($template_names, $load = false, $require_once = false) |
|
84 | - { |
|
81 | + public function locate_template($template_names, $load = false, $require_once = false) { |
|
85 | 82 | return parent::locate_template($template_names, false, false); |
86 | 83 | } |
87 | 84 | |
@@ -103,8 +100,7 @@ discard block |
||
103 | 100 | * |
104 | 101 | * @return array $templates Modified template array, merged with existing $templates values |
105 | 102 | */ |
106 | - public function add_id_specific_templates($templates, $slug, $name) |
|
107 | - { |
|
103 | + public function add_id_specific_templates($templates, $slug, $name) { |
|
108 | 104 | $additional = []; |
109 | 105 | |
110 | 106 | // form-19-table-body.php |
@@ -132,8 +128,7 @@ discard block |
||
132 | 128 | * |
133 | 129 | * @return string The output. |
134 | 130 | */ |
135 | - public function render($slug) |
|
136 | - { |
|
131 | + public function render($slug) { |
|
137 | 132 | add_action('gravityview/template/after', $view_id_output = function ($context) { |
138 | 133 | printf('<input type="hidden" class="gravityview-view-id" value="%d">', $context->view->ID); |
139 | 134 | }); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | 6 | if (!defined('GRAVITYVIEW_DIR')) { |
7 | - exit(); |
|
7 | + exit(); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,59 +14,59 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Field_Renderer extends Renderer |
16 | 16 | { |
17 | - /** |
|
18 | - * Renders a \GV\Field instance. |
|
19 | - * |
|
20 | - * @param \GV\Field $request The field. |
|
21 | - * @param \GV\View $view The view for this context if applicable. |
|
22 | - * @param \GV\Source $source The source (form) for this context if applicable. |
|
23 | - * @param \GV\Entry $entry The entry for this context if applicable. |
|
24 | - * @param \GV\Request $request The request for this context if applicable. |
|
25 | - * @param string $class The field template class. Default: \GV\Field_HTML_Template'. |
|
26 | - * |
|
27 | - * @api |
|
28 | - * |
|
29 | - * @since 2.0 |
|
30 | - * @since 2.1 Added Field Template class $class parameter |
|
31 | - * |
|
32 | - * @return string The rendered Field |
|
33 | - */ |
|
34 | - public function render(Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null, $class = '\GV\Field_HTML_Template') |
|
35 | - { |
|
36 | - if (is_null($request)) { |
|
37 | - $request = &gravityview()->request; |
|
38 | - } |
|
17 | + /** |
|
18 | + * Renders a \GV\Field instance. |
|
19 | + * |
|
20 | + * @param \GV\Field $request The field. |
|
21 | + * @param \GV\View $view The view for this context if applicable. |
|
22 | + * @param \GV\Source $source The source (form) for this context if applicable. |
|
23 | + * @param \GV\Entry $entry The entry for this context if applicable. |
|
24 | + * @param \GV\Request $request The request for this context if applicable. |
|
25 | + * @param string $class The field template class. Default: \GV\Field_HTML_Template'. |
|
26 | + * |
|
27 | + * @api |
|
28 | + * |
|
29 | + * @since 2.0 |
|
30 | + * @since 2.1 Added Field Template class $class parameter |
|
31 | + * |
|
32 | + * @return string The rendered Field |
|
33 | + */ |
|
34 | + public function render(Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null, $class = '\GV\Field_HTML_Template') |
|
35 | + { |
|
36 | + if (is_null($request)) { |
|
37 | + $request = &gravityview()->request; |
|
38 | + } |
|
39 | 39 | |
40 | - if (!$request->is_renderable()) { |
|
41 | - gravityview()->log->error('Renderer unable to render View in {request_class} context', ['request_class' => get_class($request)]); |
|
40 | + if (!$request->is_renderable()) { |
|
41 | + gravityview()->log->error('Renderer unable to render View in {request_class} context', ['request_class' => get_class($request)]); |
|
42 | 42 | |
43 | - return null; |
|
44 | - } |
|
43 | + return null; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @filter `gravityview/template/field/class` Filter the template class that is about to be used to render the view. |
|
48 | - * |
|
49 | - * @since 2.0 |
|
50 | - * |
|
51 | - * @param string $class The chosen class - Default: \GV\Field_HTML_Template. |
|
52 | - * @param \GV\Field $field The field about to be rendered. |
|
53 | - * @param \GV\View $view The view in this context, if applicable. |
|
54 | - * @param \GV\Source $source The source (form) in this context, if applicable. |
|
55 | - * @param \GV\Entry $entry The entry in this context, if applicable. |
|
56 | - * @param \GV\Request $request The request in this context, if applicable. |
|
57 | - */ |
|
58 | - $class = apply_filters('gravityview/template/field/class', $class, $field, $view, $source, $entry, $request); |
|
59 | - if (!$class || !class_exists($class)) { |
|
60 | - gravityview()->log->error('{template_class} not found', ['template_class' => $class]); |
|
46 | + /** |
|
47 | + * @filter `gravityview/template/field/class` Filter the template class that is about to be used to render the view. |
|
48 | + * |
|
49 | + * @since 2.0 |
|
50 | + * |
|
51 | + * @param string $class The chosen class - Default: \GV\Field_HTML_Template. |
|
52 | + * @param \GV\Field $field The field about to be rendered. |
|
53 | + * @param \GV\View $view The view in this context, if applicable. |
|
54 | + * @param \GV\Source $source The source (form) in this context, if applicable. |
|
55 | + * @param \GV\Entry $entry The entry in this context, if applicable. |
|
56 | + * @param \GV\Request $request The request in this context, if applicable. |
|
57 | + */ |
|
58 | + $class = apply_filters('gravityview/template/field/class', $class, $field, $view, $source, $entry, $request); |
|
59 | + if (!$class || !class_exists($class)) { |
|
60 | + gravityview()->log->error('{template_class} not found', ['template_class' => $class]); |
|
61 | 61 | |
62 | - return null; |
|
63 | - } |
|
62 | + return null; |
|
63 | + } |
|
64 | 64 | |
65 | - /** @var \GV\Field_Template $class */ |
|
66 | - $renderer = new $class($field, $view, $source, $entry, $request); |
|
67 | - ob_start(); |
|
68 | - $renderer->render(); |
|
65 | + /** @var \GV\Field_Template $class */ |
|
66 | + $renderer = new $class($field, $view, $source, $entry, $request); |
|
67 | + ob_start(); |
|
68 | + $renderer->render(); |
|
69 | 69 | |
70 | - return ob_get_clean(); |
|
71 | - } |
|
70 | + return ob_get_clean(); |
|
71 | + } |
|
72 | 72 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace GV; |
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | -if (!defined('GRAVITYVIEW_DIR')) { |
|
6 | +if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
7 | 7 | exit(); |
8 | 8 | } |
9 | 9 | |
@@ -31,14 +31,14 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @return string The rendered Field |
33 | 33 | */ |
34 | - public function render(Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null, $class = '\GV\Field_HTML_Template') |
|
34 | + public function render( Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null, $class = '\GV\Field_HTML_Template' ) |
|
35 | 35 | { |
36 | - if (is_null($request)) { |
|
36 | + if ( is_null( $request ) ) { |
|
37 | 37 | $request = &gravityview()->request; |
38 | 38 | } |
39 | 39 | |
40 | - if (!$request->is_renderable()) { |
|
41 | - gravityview()->log->error('Renderer unable to render View in {request_class} context', ['request_class' => get_class($request)]); |
|
40 | + if ( ! $request->is_renderable() ) { |
|
41 | + gravityview()->log->error( 'Renderer unable to render View in {request_class} context', [ 'request_class' => get_class( $request ) ] ); |
|
42 | 42 | |
43 | 43 | return null; |
44 | 44 | } |
@@ -55,15 +55,15 @@ discard block |
||
55 | 55 | * @param \GV\Entry $entry The entry in this context, if applicable. |
56 | 56 | * @param \GV\Request $request The request in this context, if applicable. |
57 | 57 | */ |
58 | - $class = apply_filters('gravityview/template/field/class', $class, $field, $view, $source, $entry, $request); |
|
59 | - if (!$class || !class_exists($class)) { |
|
60 | - gravityview()->log->error('{template_class} not found', ['template_class' => $class]); |
|
58 | + $class = apply_filters( 'gravityview/template/field/class', $class, $field, $view, $source, $entry, $request ); |
|
59 | + if ( ! $class || ! class_exists( $class ) ) { |
|
60 | + gravityview()->log->error( '{template_class} not found', [ 'template_class' => $class ] ); |
|
61 | 61 | |
62 | 62 | return null; |
63 | 63 | } |
64 | 64 | |
65 | 65 | /** @var \GV\Field_Template $class */ |
66 | - $renderer = new $class($field, $view, $source, $entry, $request); |
|
66 | + $renderer = new $class( $field, $view, $source, $entry, $request ); |
|
67 | 67 | ob_start(); |
68 | 68 | $renderer->render(); |
69 | 69 |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * Houses some preliminary \GV\Field rendering functionality. |
14 | 14 | */ |
15 | -class Field_Renderer extends Renderer |
|
16 | -{ |
|
15 | +class Field_Renderer extends Renderer { |
|
17 | 16 | /** |
18 | 17 | * Renders a \GV\Field instance. |
19 | 18 | * |
@@ -31,8 +30,7 @@ discard block |
||
31 | 30 | * |
32 | 31 | * @return string The rendered Field |
33 | 32 | */ |
34 | - public function render(Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null, $class = '\GV\Field_HTML_Template') |
|
35 | - { |
|
33 | + public function render(Field $field, View $view = null, Source $source = null, Entry $entry = null, Request $request = null, $class = '\GV\Field_HTML_Template') { |
|
36 | 34 | if (is_null($request)) { |
37 | 35 | $request = &gravityview()->request; |
38 | 36 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | 6 | if (!defined('GRAVITYVIEW_DIR')) { |
7 | - exit(); |
|
7 | + exit(); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,122 +14,122 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Internal_Field extends Field |
16 | 16 | { |
17 | - /** |
|
18 | - * @var \GravityView_Field|false The backing GravityView field (old). False if none exists. |
|
19 | - */ |
|
20 | - public $field; |
|
21 | - |
|
22 | - /** |
|
23 | - * Create self from a configuration array. |
|
24 | - * |
|
25 | - * @param array $configuration The configuration array. |
|
26 | - * |
|
27 | - * @see \GV\Field::as_configuration() |
|
28 | - * |
|
29 | - * @internal |
|
30 | - * |
|
31 | - * @since 2.0 |
|
32 | - * |
|
33 | - * @return \GV\Internal_Field|null The field implementation or null on error. |
|
34 | - */ |
|
35 | - public static function from_configuration($configuration) |
|
36 | - { |
|
37 | - if (empty($configuration['id']) || !is_string($configuration['id'])) { |
|
38 | - gravityview()->log->error('Invalid configuration[id] supplied.'); |
|
39 | - |
|
40 | - return null; |
|
41 | - } |
|
42 | - |
|
43 | - $field = self::by_id($configuration['id']); |
|
44 | - |
|
45 | - $field->update_configuration($configuration); |
|
46 | - |
|
47 | - return $field; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Get a \GV\GF_Field from an internal Gravity Forms field ID. |
|
52 | - * |
|
53 | - * @param int $field_id The internal Gravity Forms field ID. |
|
54 | - * |
|
55 | - * @return \GV\Internal_Field|null The requested field or null if not found. |
|
56 | - */ |
|
57 | - public static function by_id($field_id) |
|
58 | - { |
|
59 | - $field = new self(); |
|
60 | - $field->ID = $field_id; |
|
61 | - $field->type = $field->ID; |
|
62 | - |
|
63 | - /** |
|
64 | - * Retrieve the internal backing field (old for now). |
|
65 | - * |
|
66 | - * @todo switch to future subclasses |
|
67 | - */ |
|
68 | - $field->field = \GravityView_Fields::get_instance($field_id); |
|
69 | - |
|
70 | - return $field; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Retrieve the label for this field. |
|
75 | - * |
|
76 | - * @param \GV\View $view The view for this context if applicable. |
|
77 | - * @param \GV\Source $source The source (form) for this context if applicable. |
|
78 | - * @param \GV\Entry $entry The entry for this context if applicable. |
|
79 | - * @param \GV\Request $request The request for this context if applicable. |
|
80 | - * |
|
81 | - * @return string The label for this field. |
|
82 | - */ |
|
83 | - public function get_label(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
84 | - { |
|
85 | - if (!$this->show_label) { |
|
86 | - return ''; |
|
87 | - } |
|
88 | - |
|
89 | - if ($label = parent::get_label($view, $source, $entry, $request)) { |
|
90 | - return $label; |
|
91 | - } |
|
92 | - |
|
93 | - if ($this->label) { |
|
94 | - return $this->label; |
|
95 | - } |
|
96 | - |
|
97 | - return $this->field ? $this->field->label : ''; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Retrieve the value for this field. |
|
102 | - * |
|
103 | - * Requires the \GV\Entry in this implementation. |
|
104 | - * |
|
105 | - * @param \GV\View $view The view for this context if applicable. |
|
106 | - * @param \GV\Source $source The source (form) for this context if applicable. |
|
107 | - * @param \GV\Entry $entry The entry for this context if applicable. |
|
108 | - * @param \GV\Request $request The request for this context if applicable. |
|
109 | - * |
|
110 | - * @return mixed The value for this field. |
|
111 | - */ |
|
112 | - public function get_value(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
113 | - { |
|
114 | - if (!$entry || !is_a($entry, '\GV\Entry')) { |
|
115 | - gravityview()->log->error('$entry is not a valid \GV\Entry instance'); |
|
116 | - |
|
117 | - return null; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @todo Implement in subclasses, once available. |
|
122 | - * |
|
123 | - * For example the "content" field will be empty here. It's |
|
124 | - * value is actually currently retrieved inside ... |
|
125 | - * |
|
126 | - * *drumroll* |
|
127 | - * |
|
128 | - * A TEMPLATE :) |
|
129 | - */ |
|
130 | - $value = Utils::get($entry->as_entry(), $this->ID); |
|
131 | - |
|
132 | - /** Apply parent filters. */ |
|
133 | - return $this->get_value_filters($value, $view, $source, $entry, $request); |
|
134 | - } |
|
17 | + /** |
|
18 | + * @var \GravityView_Field|false The backing GravityView field (old). False if none exists. |
|
19 | + */ |
|
20 | + public $field; |
|
21 | + |
|
22 | + /** |
|
23 | + * Create self from a configuration array. |
|
24 | + * |
|
25 | + * @param array $configuration The configuration array. |
|
26 | + * |
|
27 | + * @see \GV\Field::as_configuration() |
|
28 | + * |
|
29 | + * @internal |
|
30 | + * |
|
31 | + * @since 2.0 |
|
32 | + * |
|
33 | + * @return \GV\Internal_Field|null The field implementation or null on error. |
|
34 | + */ |
|
35 | + public static function from_configuration($configuration) |
|
36 | + { |
|
37 | + if (empty($configuration['id']) || !is_string($configuration['id'])) { |
|
38 | + gravityview()->log->error('Invalid configuration[id] supplied.'); |
|
39 | + |
|
40 | + return null; |
|
41 | + } |
|
42 | + |
|
43 | + $field = self::by_id($configuration['id']); |
|
44 | + |
|
45 | + $field->update_configuration($configuration); |
|
46 | + |
|
47 | + return $field; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Get a \GV\GF_Field from an internal Gravity Forms field ID. |
|
52 | + * |
|
53 | + * @param int $field_id The internal Gravity Forms field ID. |
|
54 | + * |
|
55 | + * @return \GV\Internal_Field|null The requested field or null if not found. |
|
56 | + */ |
|
57 | + public static function by_id($field_id) |
|
58 | + { |
|
59 | + $field = new self(); |
|
60 | + $field->ID = $field_id; |
|
61 | + $field->type = $field->ID; |
|
62 | + |
|
63 | + /** |
|
64 | + * Retrieve the internal backing field (old for now). |
|
65 | + * |
|
66 | + * @todo switch to future subclasses |
|
67 | + */ |
|
68 | + $field->field = \GravityView_Fields::get_instance($field_id); |
|
69 | + |
|
70 | + return $field; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Retrieve the label for this field. |
|
75 | + * |
|
76 | + * @param \GV\View $view The view for this context if applicable. |
|
77 | + * @param \GV\Source $source The source (form) for this context if applicable. |
|
78 | + * @param \GV\Entry $entry The entry for this context if applicable. |
|
79 | + * @param \GV\Request $request The request for this context if applicable. |
|
80 | + * |
|
81 | + * @return string The label for this field. |
|
82 | + */ |
|
83 | + public function get_label(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
84 | + { |
|
85 | + if (!$this->show_label) { |
|
86 | + return ''; |
|
87 | + } |
|
88 | + |
|
89 | + if ($label = parent::get_label($view, $source, $entry, $request)) { |
|
90 | + return $label; |
|
91 | + } |
|
92 | + |
|
93 | + if ($this->label) { |
|
94 | + return $this->label; |
|
95 | + } |
|
96 | + |
|
97 | + return $this->field ? $this->field->label : ''; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Retrieve the value for this field. |
|
102 | + * |
|
103 | + * Requires the \GV\Entry in this implementation. |
|
104 | + * |
|
105 | + * @param \GV\View $view The view for this context if applicable. |
|
106 | + * @param \GV\Source $source The source (form) for this context if applicable. |
|
107 | + * @param \GV\Entry $entry The entry for this context if applicable. |
|
108 | + * @param \GV\Request $request The request for this context if applicable. |
|
109 | + * |
|
110 | + * @return mixed The value for this field. |
|
111 | + */ |
|
112 | + public function get_value(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
113 | + { |
|
114 | + if (!$entry || !is_a($entry, '\GV\Entry')) { |
|
115 | + gravityview()->log->error('$entry is not a valid \GV\Entry instance'); |
|
116 | + |
|
117 | + return null; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @todo Implement in subclasses, once available. |
|
122 | + * |
|
123 | + * For example the "content" field will be empty here. It's |
|
124 | + * value is actually currently retrieved inside ... |
|
125 | + * |
|
126 | + * *drumroll* |
|
127 | + * |
|
128 | + * A TEMPLATE :) |
|
129 | + */ |
|
130 | + $value = Utils::get($entry->as_entry(), $this->ID); |
|
131 | + |
|
132 | + /** Apply parent filters. */ |
|
133 | + return $this->get_value_filters($value, $view, $source, $entry, $request); |
|
134 | + } |
|
135 | 135 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace GV; |
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | -if (!defined('GRAVITYVIEW_DIR')) { |
|
6 | +if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
7 | 7 | exit(); |
8 | 8 | } |
9 | 9 | |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @return \GV\Internal_Field|null The field implementation or null on error. |
34 | 34 | */ |
35 | - public static function from_configuration($configuration) |
|
35 | + public static function from_configuration( $configuration ) |
|
36 | 36 | { |
37 | - if (empty($configuration['id']) || !is_string($configuration['id'])) { |
|
38 | - gravityview()->log->error('Invalid configuration[id] supplied.'); |
|
37 | + if ( empty( $configuration[ 'id' ] ) || ! is_string( $configuration[ 'id' ] ) ) { |
|
38 | + gravityview()->log->error( 'Invalid configuration[id] supplied.' ); |
|
39 | 39 | |
40 | 40 | return null; |
41 | 41 | } |
42 | 42 | |
43 | - $field = self::by_id($configuration['id']); |
|
43 | + $field = self::by_id( $configuration[ 'id' ] ); |
|
44 | 44 | |
45 | - $field->update_configuration($configuration); |
|
45 | + $field->update_configuration( $configuration ); |
|
46 | 46 | |
47 | 47 | return $field; |
48 | 48 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return \GV\Internal_Field|null The requested field or null if not found. |
56 | 56 | */ |
57 | - public static function by_id($field_id) |
|
57 | + public static function by_id( $field_id ) |
|
58 | 58 | { |
59 | 59 | $field = new self(); |
60 | 60 | $field->ID = $field_id; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * |
66 | 66 | * @todo switch to future subclasses |
67 | 67 | */ |
68 | - $field->field = \GravityView_Fields::get_instance($field_id); |
|
68 | + $field->field = \GravityView_Fields::get_instance( $field_id ); |
|
69 | 69 | |
70 | 70 | return $field; |
71 | 71 | } |
@@ -80,17 +80,17 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return string The label for this field. |
82 | 82 | */ |
83 | - public function get_label(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
83 | + public function get_label( View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) |
|
84 | 84 | { |
85 | - if (!$this->show_label) { |
|
85 | + if ( ! $this->show_label ) { |
|
86 | 86 | return ''; |
87 | 87 | } |
88 | 88 | |
89 | - if ($label = parent::get_label($view, $source, $entry, $request)) { |
|
89 | + if ( $label = parent::get_label( $view, $source, $entry, $request ) ) { |
|
90 | 90 | return $label; |
91 | 91 | } |
92 | 92 | |
93 | - if ($this->label) { |
|
93 | + if ( $this->label ) { |
|
94 | 94 | return $this->label; |
95 | 95 | } |
96 | 96 | |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @return mixed The value for this field. |
111 | 111 | */ |
112 | - public function get_value(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
112 | + public function get_value( View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) |
|
113 | 113 | { |
114 | - if (!$entry || !is_a($entry, '\GV\Entry')) { |
|
115 | - gravityview()->log->error('$entry is not a valid \GV\Entry instance'); |
|
114 | + if ( ! $entry || ! is_a( $entry, '\GV\Entry' ) ) { |
|
115 | + gravityview()->log->error( '$entry is not a valid \GV\Entry instance' ); |
|
116 | 116 | |
117 | 117 | return null; |
118 | 118 | } |
@@ -127,9 +127,9 @@ discard block |
||
127 | 127 | * |
128 | 128 | * A TEMPLATE :) |
129 | 129 | */ |
130 | - $value = Utils::get($entry->as_entry(), $this->ID); |
|
130 | + $value = Utils::get( $entry->as_entry(), $this->ID ); |
|
131 | 131 | |
132 | 132 | /** Apply parent filters. */ |
133 | - return $this->get_value_filters($value, $view, $source, $entry, $request); |
|
133 | + return $this->get_value_filters( $value, $view, $source, $entry, $request ); |
|
134 | 134 | } |
135 | 135 | } |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * Used for custom content fields, etc. |
14 | 14 | */ |
15 | -class Internal_Field extends Field |
|
16 | -{ |
|
15 | +class Internal_Field extends Field { |
|
17 | 16 | /** |
18 | 17 | * @var \GravityView_Field|false The backing GravityView field (old). False if none exists. |
19 | 18 | */ |
@@ -32,8 +31,7 @@ discard block |
||
32 | 31 | * |
33 | 32 | * @return \GV\Internal_Field|null The field implementation or null on error. |
34 | 33 | */ |
35 | - public static function from_configuration($configuration) |
|
36 | - { |
|
34 | + public static function from_configuration($configuration) { |
|
37 | 35 | if (empty($configuration['id']) || !is_string($configuration['id'])) { |
38 | 36 | gravityview()->log->error('Invalid configuration[id] supplied.'); |
39 | 37 | |
@@ -54,8 +52,7 @@ discard block |
||
54 | 52 | * |
55 | 53 | * @return \GV\Internal_Field|null The requested field or null if not found. |
56 | 54 | */ |
57 | - public static function by_id($field_id) |
|
58 | - { |
|
55 | + public static function by_id($field_id) { |
|
59 | 56 | $field = new self(); |
60 | 57 | $field->ID = $field_id; |
61 | 58 | $field->type = $field->ID; |
@@ -80,8 +77,7 @@ discard block |
||
80 | 77 | * |
81 | 78 | * @return string The label for this field. |
82 | 79 | */ |
83 | - public function get_label(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
84 | - { |
|
80 | + public function get_label(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) { |
|
85 | 81 | if (!$this->show_label) { |
86 | 82 | return ''; |
87 | 83 | } |
@@ -109,8 +105,7 @@ discard block |
||
109 | 105 | * |
110 | 106 | * @return mixed The value for this field. |
111 | 107 | */ |
112 | - public function get_value(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
113 | - { |
|
108 | + public function get_value(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) { |
|
114 | 109 | if (!$entry || !is_a($entry, '\GV\Entry')) { |
115 | 110 | gravityview()->log->error('$entry is not a valid \GV\Entry instance'); |
116 | 111 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | 6 | if (!defined('GRAVITYVIEW_DIR')) { |
7 | - exit(); |
|
7 | + exit(); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,413 +14,413 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Field |
16 | 16 | { |
17 | - /** |
|
18 | - * @var array The custom View configuration for this field. |
|
19 | - * |
|
20 | - * Everything else is in the properties. |
|
21 | - */ |
|
22 | - private $configuration = []; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var string The field position in the view. |
|
26 | - * |
|
27 | - * @api |
|
28 | - * |
|
29 | - * @since 2.0 |
|
30 | - */ |
|
31 | - public $position = ''; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var string UID for this field. |
|
35 | - * |
|
36 | - * A unique relation identifier between this field and a view. |
|
37 | - * |
|
38 | - * @api |
|
39 | - * |
|
40 | - * @since 2.0 |
|
41 | - */ |
|
42 | - public $UID = ''; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string The form field ID for this field. |
|
46 | - * |
|
47 | - * @api |
|
48 | - * |
|
49 | - * @since 2.0 |
|
50 | - */ |
|
51 | - public $ID = ''; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var string The form label for this field. |
|
55 | - * |
|
56 | - * @api |
|
57 | - * |
|
58 | - * @since 2.0 |
|
59 | - */ |
|
60 | - public $label = ''; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var string The custom label for this field. |
|
64 | - * |
|
65 | - * @api |
|
66 | - * |
|
67 | - * @since 2.0 |
|
68 | - */ |
|
69 | - public $custom_label = ''; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var bool Whether to show the label or not for this field. |
|
73 | - * |
|
74 | - * @api |
|
75 | - * |
|
76 | - * @since 2.0 |
|
77 | - */ |
|
78 | - public $show_label = true; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var string The custom class for this field. |
|
82 | - * |
|
83 | - * @api |
|
84 | - * |
|
85 | - * @since 2.0 |
|
86 | - */ |
|
87 | - public $custom_class = ''; |
|
88 | - |
|
89 | - /** |
|
90 | - * @var string The capability required to view this field. |
|
91 | - * |
|
92 | - * If empty, anyone can view it, including non-logged in users. |
|
93 | - * |
|
94 | - * @api |
|
95 | - * |
|
96 | - * @since 2.0 |
|
97 | - */ |
|
98 | - public $cap = ''; |
|
99 | - |
|
100 | - /** |
|
101 | - * @var bool Show as a link to entry. |
|
102 | - * |
|
103 | - * @api |
|
104 | - * |
|
105 | - * @since 2.0 |
|
106 | - */ |
|
107 | - public $show_as_link = false; |
|
108 | - |
|
109 | - /** |
|
110 | - * @var bool Filter this field from searching. |
|
111 | - * |
|
112 | - * @api |
|
113 | - * |
|
114 | - * @since 2.0 |
|
115 | - */ |
|
116 | - public $search_filter = false; |
|
117 | - |
|
118 | - /** |
|
119 | - * Return an array of the old format as used by callers of `GVCommon:get_directory_fields()` for example. |
|
120 | - * |
|
121 | - * 'id' => string '9' (length=1) |
|
122 | - * 'label' => string 'Screenshots' (length=11) |
|
123 | - * 'show_label' => string '1' (length=1) |
|
124 | - * 'custom_label' => string '' (length=0) |
|
125 | - * 'custom_class' => string 'gv-gallery' (length=10) |
|
126 | - * 'only_loggedin' => string '0' (length=1) |
|
127 | - * 'only_loggedin_cap' => string 'read' (length=4) |
|
128 | - * 'search_filter' => string '0' |
|
129 | - * 'show_as_link' => string '0' |
|
130 | - * |
|
131 | - * + whatever else specific field types may have |
|
132 | - * |
|
133 | - * @internal |
|
134 | - * |
|
135 | - * @since 2.0 |
|
136 | - * |
|
137 | - * @return array |
|
138 | - */ |
|
139 | - public function as_configuration() |
|
140 | - { |
|
141 | - return array_merge([ |
|
142 | - 'id' => $this->ID, |
|
143 | - 'label' => $this->label, |
|
144 | - 'show_label' => $this->show_label ? '1' : '0', |
|
145 | - 'custom_label' => $this->custom_label, |
|
146 | - 'custom_class' => $this->custom_class, |
|
147 | - 'only_loggedin' => $this->cap ? '1' : '0', |
|
148 | - 'only_loggedin_cap' => $this->cap, |
|
149 | - 'search_filter' => $this->search_filter ? '1' : '0', |
|
150 | - 'show_as_link' => $this->show_as_link ? '1' : '0', |
|
151 | - ], $this->configuration); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * An alias for \GV\Source::get_field(). |
|
156 | - * |
|
157 | - * @see \GV\Source::get_field() |
|
158 | - * |
|
159 | - * @param string $source A \GV\Source class as string this field is tied to. |
|
160 | - * @param array $args The arguments required for the backend to fetch the field (usually just the ID). |
|
161 | - * |
|
162 | - * @return \GV\Field|null A \GV\Field instance or null if not found. |
|
163 | - */ |
|
164 | - final public static function get($source, $args) |
|
165 | - { |
|
166 | - if (!is_string($source) || !class_exists($source)) { |
|
167 | - gravityview()->log->error('{source} class not found', ['source' => $source]); |
|
168 | - |
|
169 | - return null; |
|
170 | - } |
|
171 | - |
|
172 | - if (!method_exists($source, 'get_field')) { |
|
173 | - gravityview()->log->error('{source} does not appear to be a valid \GV\Source subclass (get_field method missing)', ['source' => $source]); |
|
174 | - |
|
175 | - return null; |
|
176 | - } |
|
177 | - |
|
178 | - return call_user_func_array([$source, 'get_field'], is_array($args) ? $args : [$args]); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Create self from a configuration array. |
|
183 | - * |
|
184 | - * @param array $configuration The configuration array. |
|
185 | - * |
|
186 | - * @see \GV\Field::as_configuration() |
|
187 | - * |
|
188 | - * @internal |
|
189 | - * |
|
190 | - * @since 2.0 |
|
191 | - * |
|
192 | - * @return \GV\Field The field implementation from configuration (\GV\GF_Field, \GV\Internal_Field). |
|
193 | - */ |
|
194 | - public static function from_configuration($configuration) |
|
195 | - { |
|
196 | - if (empty($configuration['id'])) { |
|
197 | - $field = new self(); |
|
198 | - gravityview()->log->error('Trying to get field from configuration without a field ID.', ['data' => $configuration]); |
|
199 | - $field->update_configuration($configuration); |
|
200 | - |
|
201 | - return $field; |
|
202 | - } |
|
203 | - |
|
204 | - /** Prevent infinte loops here from unimplemented children. */ |
|
205 | - if (version_compare(phpversion(), '5.4', '>=')) { |
|
206 | - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
|
207 | - } else { |
|
208 | - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
209 | - } |
|
210 | - $trace = $trace[1]; |
|
211 | - if ($trace['function'] == 'from_configuration' && $trace['class'] == __CLASS__) { |
|
212 | - $field = new self(); |
|
213 | - gravityview()->log->error('Infinite loop protection tripped. Returning default class here.'); |
|
214 | - $field->update_configuration($configuration); |
|
215 | - |
|
216 | - return $field; |
|
217 | - } |
|
218 | - |
|
219 | - /** @var \GV\GF_Field|\GV\Internal_Field $field_class Determine the field implementation to use, and try to use. */ |
|
220 | - $field_class = is_numeric($configuration['id']) ? '\GV\GF_Field' : '\GV\Internal_Field'; |
|
221 | - |
|
222 | - /** |
|
223 | - * @filter `gravityview/field/class` Filter the field class about to be created from the configuration. |
|
224 | - * |
|
225 | - * @param string $field_class The field class about to be used. |
|
226 | - * @param array $configuration The configuration as per \GV\Field::as_configuration() |
|
227 | - */ |
|
228 | - $field_class = apply_filters('gravityview/field/class', $field_class, $configuration); |
|
229 | - |
|
230 | - if (!class_exists($field_class) || !method_exists($field_class, 'from_configuration')) { |
|
231 | - $field = new self(); |
|
232 | - gravityview()->log->error('Class {field_class}::from_configuration does not exist.', ['field_class' => $field_class]); |
|
233 | - $field->update_configuration($configuration); |
|
234 | - |
|
235 | - return $field; |
|
236 | - } |
|
237 | - |
|
238 | - $field = $field_class::from_configuration($configuration); |
|
239 | - |
|
240 | - if (!$field) { |
|
241 | - $field = new self(); |
|
242 | - gravityview()->log->error('Could not configure {field_class} with given configuration.', ['field_class' => __CLASS__, 'data' => $configuration]); |
|
243 | - $field->update_configuration($configuration); |
|
244 | - } |
|
245 | - |
|
246 | - return $field; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Update configuration. |
|
251 | - * |
|
252 | - * @param array $configuration The configuration array. |
|
253 | - * |
|
254 | - * @see \GV\Field::as_configuration() |
|
255 | - * @since 2.0 |
|
256 | - * |
|
257 | - * @return void |
|
258 | - */ |
|
259 | - public function update_configuration($configuration) |
|
260 | - { |
|
261 | - $configuration = wp_parse_args($configuration, $this->as_configuration()); |
|
262 | - |
|
263 | - if ($this->ID != $configuration['id']) { |
|
264 | - /** Smelling trouble here... */ |
|
265 | - gravityview()->log->warning('ID is being changed for {field_class} instance, but implementation is not. Use ::from_configuration instead', ['field_class', __CLASS__]); |
|
266 | - } |
|
267 | - |
|
268 | - $this->ID = $configuration['id']; |
|
269 | - $this->label = $configuration['label']; |
|
270 | - $this->show_label = $configuration['show_label'] == '1'; |
|
271 | - $this->custom_label = $configuration['custom_label']; |
|
272 | - $this->custom_class = $configuration['custom_class']; |
|
273 | - $this->cap = $configuration['only_loggedin'] == '1' ? $configuration['only_loggedin_cap'] : ''; |
|
274 | - $this->search_filter = $configuration['search_filter'] == '1'; |
|
275 | - $this->show_as_link = $configuration['show_as_link'] == '1'; |
|
276 | - |
|
277 | - /** Shared among all field types (sort of). */ |
|
278 | - $shared_configuration_keys = [ |
|
279 | - 'id', 'label', 'show_label', 'custom_label', 'custom_class', |
|
280 | - 'only_loggedin', 'only_loggedin_cap', 'search_filter', 'show_as_link', |
|
281 | - ]; |
|
282 | - |
|
283 | - /** Everything else goes into the properties for now. @todo subclasses! */ |
|
284 | - foreach ($configuration as $key => $value) { |
|
285 | - if (!in_array($key, $shared_configuration_keys)) { |
|
286 | - $this->configuration[$key] = $value; |
|
287 | - } |
|
288 | - } |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Retrieve the label for this field. |
|
293 | - * |
|
294 | - * @param \GV\View $view The view for this context if applicable. |
|
295 | - * @param \GV\Source $source The source (form) for this context if applicable. |
|
296 | - * @param \GV\Entry $entry The entry for this context if applicable. |
|
297 | - * @param \GV\Request $request The request for this context if applicable. |
|
298 | - * |
|
299 | - * @return string The label for this field. Nothing here. |
|
300 | - */ |
|
301 | - public function get_label(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
302 | - { |
|
303 | - if (!$this->show_label) { |
|
304 | - return ''; |
|
305 | - } |
|
306 | - |
|
307 | - /** A custom label is available. */ |
|
308 | - if (!empty($this->custom_label)) { |
|
309 | - return \GravityView_API::replace_variables($this->custom_label, $source ? $source->form ?: null : null, $entry ? $entry->as_entry() : null); |
|
310 | - } |
|
311 | - |
|
312 | - return ''; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Retrieve the value for this field. |
|
317 | - * |
|
318 | - * Returns null in this implementation (or, rather, lack thereof). |
|
319 | - * |
|
320 | - * @param \GV\View $view The view for this context if applicable. |
|
321 | - * @param \GV\Source $source The source (form) for this context if applicable. |
|
322 | - * @param \GV\Entry $entry The entry for this context if applicable. |
|
323 | - * @param \GV\Request $request The request for this context if applicable. |
|
324 | - * |
|
325 | - * @return mixed The value for this field. |
|
326 | - */ |
|
327 | - public function get_value(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
328 | - { |
|
329 | - return $this->get_value_filters(null, $view, $source, $entry, $request); |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Apply all the required filters after get_value() was called. |
|
334 | - * |
|
335 | - * @param mixed $value The value that will be filtered. |
|
336 | - * @param \GV\View $view The view for this context if applicable. |
|
337 | - * @param \GV\Source $source The source (form) for this context if applicable. |
|
338 | - * @param \GV\Entry $entry The entry for this context if applicable. |
|
339 | - * @param \GV\Request $request The request for this context if applicable. |
|
340 | - * |
|
341 | - * This is in its own function since \GV\Field subclasses have to call it. |
|
342 | - */ |
|
343 | - protected function get_value_filters($value, View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
344 | - { |
|
345 | - if ($this->type) { |
|
346 | - /** |
|
347 | - * @filter `gravityview/field/$type/value` Override the displayed value here. |
|
348 | - * |
|
349 | - * @param string $value The value. |
|
350 | - * @param \GV\Field The field we're doing this for. |
|
351 | - * @param \GV\View $view The view for this context if applicable. |
|
352 | - * @param \GV\Source $source The source (form) for this context if applicable. |
|
353 | - * @param \GV\Entry $entry The entry for this context if applicable. |
|
354 | - * @param \GV\Request $request The request for this context if applicable. |
|
355 | - */ |
|
356 | - $value = apply_filters("gravityview/field/{$this->type}/value", $value, $this, $view, $source, $entry, $request); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * @filter `gravityview/field/value` Override the displayed value here. |
|
361 | - * |
|
362 | - * @param string $value The value. |
|
363 | - * @param \GV\Field The field we're doing this for. |
|
364 | - * @param \GV\View $view The view for this context if applicable. |
|
365 | - * @param \GV\Source $source The source (form) for this context if applicable. |
|
366 | - * @param \GV\Entry $entry The entry for this context if applicable. |
|
367 | - * @param \GV\Request $request The request for this context if applicable. |
|
368 | - */ |
|
369 | - return apply_filters('gravityview/field/value', $value, $this, $view, $source, $entry, $request); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Whether or not this field is visible. |
|
374 | - * |
|
375 | - * @param \GV\View|null Is visible where exactly? |
|
376 | - * |
|
377 | - * @since develop |
|
378 | - * |
|
379 | - * @return bool |
|
380 | - */ |
|
381 | - public function is_visible($view = null) |
|
382 | - { |
|
383 | - /** |
|
384 | - * @filter `gravityview/field/is_visible` Should this field be visible? |
|
385 | - * |
|
386 | - * @param bool $visible Visible or not, defaults to the set field capability requirement if defined. |
|
387 | - * @param \GV\Field $field The field we're looking at. |
|
388 | - * @param \GV\View|null A context view. Since @develop |
|
389 | - */ |
|
390 | - return apply_filters('gravityview/field/is_visible', (!$this->cap || \GVCommon::has_cap($this->cap)), $this, $view); |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Get one of the extra configuration keys via property accessors. |
|
395 | - * |
|
396 | - * @param string $key The key to get. |
|
397 | - * |
|
398 | - * @return mixed|null The value for the given configuration key, null if doesn't exist. |
|
399 | - */ |
|
400 | - public function __get($key) |
|
401 | - { |
|
402 | - switch ($key) { |
|
403 | - default: |
|
404 | - if (isset($this->configuration[$key])) { |
|
405 | - return $this->configuration[$key]; |
|
406 | - } |
|
407 | - } |
|
408 | - |
|
409 | - return null; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Is this set? |
|
414 | - * |
|
415 | - * @param string $key The key to get. |
|
416 | - * |
|
417 | - * @return bool Whether this $key is set or not. |
|
418 | - */ |
|
419 | - public function __isset($key) |
|
420 | - { |
|
421 | - switch ($key) { |
|
422 | - default: |
|
423 | - return isset($this->configuration[$key]); |
|
424 | - } |
|
425 | - } |
|
17 | + /** |
|
18 | + * @var array The custom View configuration for this field. |
|
19 | + * |
|
20 | + * Everything else is in the properties. |
|
21 | + */ |
|
22 | + private $configuration = []; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var string The field position in the view. |
|
26 | + * |
|
27 | + * @api |
|
28 | + * |
|
29 | + * @since 2.0 |
|
30 | + */ |
|
31 | + public $position = ''; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var string UID for this field. |
|
35 | + * |
|
36 | + * A unique relation identifier between this field and a view. |
|
37 | + * |
|
38 | + * @api |
|
39 | + * |
|
40 | + * @since 2.0 |
|
41 | + */ |
|
42 | + public $UID = ''; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string The form field ID for this field. |
|
46 | + * |
|
47 | + * @api |
|
48 | + * |
|
49 | + * @since 2.0 |
|
50 | + */ |
|
51 | + public $ID = ''; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var string The form label for this field. |
|
55 | + * |
|
56 | + * @api |
|
57 | + * |
|
58 | + * @since 2.0 |
|
59 | + */ |
|
60 | + public $label = ''; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var string The custom label for this field. |
|
64 | + * |
|
65 | + * @api |
|
66 | + * |
|
67 | + * @since 2.0 |
|
68 | + */ |
|
69 | + public $custom_label = ''; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var bool Whether to show the label or not for this field. |
|
73 | + * |
|
74 | + * @api |
|
75 | + * |
|
76 | + * @since 2.0 |
|
77 | + */ |
|
78 | + public $show_label = true; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var string The custom class for this field. |
|
82 | + * |
|
83 | + * @api |
|
84 | + * |
|
85 | + * @since 2.0 |
|
86 | + */ |
|
87 | + public $custom_class = ''; |
|
88 | + |
|
89 | + /** |
|
90 | + * @var string The capability required to view this field. |
|
91 | + * |
|
92 | + * If empty, anyone can view it, including non-logged in users. |
|
93 | + * |
|
94 | + * @api |
|
95 | + * |
|
96 | + * @since 2.0 |
|
97 | + */ |
|
98 | + public $cap = ''; |
|
99 | + |
|
100 | + /** |
|
101 | + * @var bool Show as a link to entry. |
|
102 | + * |
|
103 | + * @api |
|
104 | + * |
|
105 | + * @since 2.0 |
|
106 | + */ |
|
107 | + public $show_as_link = false; |
|
108 | + |
|
109 | + /** |
|
110 | + * @var bool Filter this field from searching. |
|
111 | + * |
|
112 | + * @api |
|
113 | + * |
|
114 | + * @since 2.0 |
|
115 | + */ |
|
116 | + public $search_filter = false; |
|
117 | + |
|
118 | + /** |
|
119 | + * Return an array of the old format as used by callers of `GVCommon:get_directory_fields()` for example. |
|
120 | + * |
|
121 | + * 'id' => string '9' (length=1) |
|
122 | + * 'label' => string 'Screenshots' (length=11) |
|
123 | + * 'show_label' => string '1' (length=1) |
|
124 | + * 'custom_label' => string '' (length=0) |
|
125 | + * 'custom_class' => string 'gv-gallery' (length=10) |
|
126 | + * 'only_loggedin' => string '0' (length=1) |
|
127 | + * 'only_loggedin_cap' => string 'read' (length=4) |
|
128 | + * 'search_filter' => string '0' |
|
129 | + * 'show_as_link' => string '0' |
|
130 | + * |
|
131 | + * + whatever else specific field types may have |
|
132 | + * |
|
133 | + * @internal |
|
134 | + * |
|
135 | + * @since 2.0 |
|
136 | + * |
|
137 | + * @return array |
|
138 | + */ |
|
139 | + public function as_configuration() |
|
140 | + { |
|
141 | + return array_merge([ |
|
142 | + 'id' => $this->ID, |
|
143 | + 'label' => $this->label, |
|
144 | + 'show_label' => $this->show_label ? '1' : '0', |
|
145 | + 'custom_label' => $this->custom_label, |
|
146 | + 'custom_class' => $this->custom_class, |
|
147 | + 'only_loggedin' => $this->cap ? '1' : '0', |
|
148 | + 'only_loggedin_cap' => $this->cap, |
|
149 | + 'search_filter' => $this->search_filter ? '1' : '0', |
|
150 | + 'show_as_link' => $this->show_as_link ? '1' : '0', |
|
151 | + ], $this->configuration); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * An alias for \GV\Source::get_field(). |
|
156 | + * |
|
157 | + * @see \GV\Source::get_field() |
|
158 | + * |
|
159 | + * @param string $source A \GV\Source class as string this field is tied to. |
|
160 | + * @param array $args The arguments required for the backend to fetch the field (usually just the ID). |
|
161 | + * |
|
162 | + * @return \GV\Field|null A \GV\Field instance or null if not found. |
|
163 | + */ |
|
164 | + final public static function get($source, $args) |
|
165 | + { |
|
166 | + if (!is_string($source) || !class_exists($source)) { |
|
167 | + gravityview()->log->error('{source} class not found', ['source' => $source]); |
|
168 | + |
|
169 | + return null; |
|
170 | + } |
|
171 | + |
|
172 | + if (!method_exists($source, 'get_field')) { |
|
173 | + gravityview()->log->error('{source} does not appear to be a valid \GV\Source subclass (get_field method missing)', ['source' => $source]); |
|
174 | + |
|
175 | + return null; |
|
176 | + } |
|
177 | + |
|
178 | + return call_user_func_array([$source, 'get_field'], is_array($args) ? $args : [$args]); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Create self from a configuration array. |
|
183 | + * |
|
184 | + * @param array $configuration The configuration array. |
|
185 | + * |
|
186 | + * @see \GV\Field::as_configuration() |
|
187 | + * |
|
188 | + * @internal |
|
189 | + * |
|
190 | + * @since 2.0 |
|
191 | + * |
|
192 | + * @return \GV\Field The field implementation from configuration (\GV\GF_Field, \GV\Internal_Field). |
|
193 | + */ |
|
194 | + public static function from_configuration($configuration) |
|
195 | + { |
|
196 | + if (empty($configuration['id'])) { |
|
197 | + $field = new self(); |
|
198 | + gravityview()->log->error('Trying to get field from configuration without a field ID.', ['data' => $configuration]); |
|
199 | + $field->update_configuration($configuration); |
|
200 | + |
|
201 | + return $field; |
|
202 | + } |
|
203 | + |
|
204 | + /** Prevent infinte loops here from unimplemented children. */ |
|
205 | + if (version_compare(phpversion(), '5.4', '>=')) { |
|
206 | + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
|
207 | + } else { |
|
208 | + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
209 | + } |
|
210 | + $trace = $trace[1]; |
|
211 | + if ($trace['function'] == 'from_configuration' && $trace['class'] == __CLASS__) { |
|
212 | + $field = new self(); |
|
213 | + gravityview()->log->error('Infinite loop protection tripped. Returning default class here.'); |
|
214 | + $field->update_configuration($configuration); |
|
215 | + |
|
216 | + return $field; |
|
217 | + } |
|
218 | + |
|
219 | + /** @var \GV\GF_Field|\GV\Internal_Field $field_class Determine the field implementation to use, and try to use. */ |
|
220 | + $field_class = is_numeric($configuration['id']) ? '\GV\GF_Field' : '\GV\Internal_Field'; |
|
221 | + |
|
222 | + /** |
|
223 | + * @filter `gravityview/field/class` Filter the field class about to be created from the configuration. |
|
224 | + * |
|
225 | + * @param string $field_class The field class about to be used. |
|
226 | + * @param array $configuration The configuration as per \GV\Field::as_configuration() |
|
227 | + */ |
|
228 | + $field_class = apply_filters('gravityview/field/class', $field_class, $configuration); |
|
229 | + |
|
230 | + if (!class_exists($field_class) || !method_exists($field_class, 'from_configuration')) { |
|
231 | + $field = new self(); |
|
232 | + gravityview()->log->error('Class {field_class}::from_configuration does not exist.', ['field_class' => $field_class]); |
|
233 | + $field->update_configuration($configuration); |
|
234 | + |
|
235 | + return $field; |
|
236 | + } |
|
237 | + |
|
238 | + $field = $field_class::from_configuration($configuration); |
|
239 | + |
|
240 | + if (!$field) { |
|
241 | + $field = new self(); |
|
242 | + gravityview()->log->error('Could not configure {field_class} with given configuration.', ['field_class' => __CLASS__, 'data' => $configuration]); |
|
243 | + $field->update_configuration($configuration); |
|
244 | + } |
|
245 | + |
|
246 | + return $field; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Update configuration. |
|
251 | + * |
|
252 | + * @param array $configuration The configuration array. |
|
253 | + * |
|
254 | + * @see \GV\Field::as_configuration() |
|
255 | + * @since 2.0 |
|
256 | + * |
|
257 | + * @return void |
|
258 | + */ |
|
259 | + public function update_configuration($configuration) |
|
260 | + { |
|
261 | + $configuration = wp_parse_args($configuration, $this->as_configuration()); |
|
262 | + |
|
263 | + if ($this->ID != $configuration['id']) { |
|
264 | + /** Smelling trouble here... */ |
|
265 | + gravityview()->log->warning('ID is being changed for {field_class} instance, but implementation is not. Use ::from_configuration instead', ['field_class', __CLASS__]); |
|
266 | + } |
|
267 | + |
|
268 | + $this->ID = $configuration['id']; |
|
269 | + $this->label = $configuration['label']; |
|
270 | + $this->show_label = $configuration['show_label'] == '1'; |
|
271 | + $this->custom_label = $configuration['custom_label']; |
|
272 | + $this->custom_class = $configuration['custom_class']; |
|
273 | + $this->cap = $configuration['only_loggedin'] == '1' ? $configuration['only_loggedin_cap'] : ''; |
|
274 | + $this->search_filter = $configuration['search_filter'] == '1'; |
|
275 | + $this->show_as_link = $configuration['show_as_link'] == '1'; |
|
276 | + |
|
277 | + /** Shared among all field types (sort of). */ |
|
278 | + $shared_configuration_keys = [ |
|
279 | + 'id', 'label', 'show_label', 'custom_label', 'custom_class', |
|
280 | + 'only_loggedin', 'only_loggedin_cap', 'search_filter', 'show_as_link', |
|
281 | + ]; |
|
282 | + |
|
283 | + /** Everything else goes into the properties for now. @todo subclasses! */ |
|
284 | + foreach ($configuration as $key => $value) { |
|
285 | + if (!in_array($key, $shared_configuration_keys)) { |
|
286 | + $this->configuration[$key] = $value; |
|
287 | + } |
|
288 | + } |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Retrieve the label for this field. |
|
293 | + * |
|
294 | + * @param \GV\View $view The view for this context if applicable. |
|
295 | + * @param \GV\Source $source The source (form) for this context if applicable. |
|
296 | + * @param \GV\Entry $entry The entry for this context if applicable. |
|
297 | + * @param \GV\Request $request The request for this context if applicable. |
|
298 | + * |
|
299 | + * @return string The label for this field. Nothing here. |
|
300 | + */ |
|
301 | + public function get_label(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
302 | + { |
|
303 | + if (!$this->show_label) { |
|
304 | + return ''; |
|
305 | + } |
|
306 | + |
|
307 | + /** A custom label is available. */ |
|
308 | + if (!empty($this->custom_label)) { |
|
309 | + return \GravityView_API::replace_variables($this->custom_label, $source ? $source->form ?: null : null, $entry ? $entry->as_entry() : null); |
|
310 | + } |
|
311 | + |
|
312 | + return ''; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Retrieve the value for this field. |
|
317 | + * |
|
318 | + * Returns null in this implementation (or, rather, lack thereof). |
|
319 | + * |
|
320 | + * @param \GV\View $view The view for this context if applicable. |
|
321 | + * @param \GV\Source $source The source (form) for this context if applicable. |
|
322 | + * @param \GV\Entry $entry The entry for this context if applicable. |
|
323 | + * @param \GV\Request $request The request for this context if applicable. |
|
324 | + * |
|
325 | + * @return mixed The value for this field. |
|
326 | + */ |
|
327 | + public function get_value(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
328 | + { |
|
329 | + return $this->get_value_filters(null, $view, $source, $entry, $request); |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Apply all the required filters after get_value() was called. |
|
334 | + * |
|
335 | + * @param mixed $value The value that will be filtered. |
|
336 | + * @param \GV\View $view The view for this context if applicable. |
|
337 | + * @param \GV\Source $source The source (form) for this context if applicable. |
|
338 | + * @param \GV\Entry $entry The entry for this context if applicable. |
|
339 | + * @param \GV\Request $request The request for this context if applicable. |
|
340 | + * |
|
341 | + * This is in its own function since \GV\Field subclasses have to call it. |
|
342 | + */ |
|
343 | + protected function get_value_filters($value, View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
344 | + { |
|
345 | + if ($this->type) { |
|
346 | + /** |
|
347 | + * @filter `gravityview/field/$type/value` Override the displayed value here. |
|
348 | + * |
|
349 | + * @param string $value The value. |
|
350 | + * @param \GV\Field The field we're doing this for. |
|
351 | + * @param \GV\View $view The view for this context if applicable. |
|
352 | + * @param \GV\Source $source The source (form) for this context if applicable. |
|
353 | + * @param \GV\Entry $entry The entry for this context if applicable. |
|
354 | + * @param \GV\Request $request The request for this context if applicable. |
|
355 | + */ |
|
356 | + $value = apply_filters("gravityview/field/{$this->type}/value", $value, $this, $view, $source, $entry, $request); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * @filter `gravityview/field/value` Override the displayed value here. |
|
361 | + * |
|
362 | + * @param string $value The value. |
|
363 | + * @param \GV\Field The field we're doing this for. |
|
364 | + * @param \GV\View $view The view for this context if applicable. |
|
365 | + * @param \GV\Source $source The source (form) for this context if applicable. |
|
366 | + * @param \GV\Entry $entry The entry for this context if applicable. |
|
367 | + * @param \GV\Request $request The request for this context if applicable. |
|
368 | + */ |
|
369 | + return apply_filters('gravityview/field/value', $value, $this, $view, $source, $entry, $request); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Whether or not this field is visible. |
|
374 | + * |
|
375 | + * @param \GV\View|null Is visible where exactly? |
|
376 | + * |
|
377 | + * @since develop |
|
378 | + * |
|
379 | + * @return bool |
|
380 | + */ |
|
381 | + public function is_visible($view = null) |
|
382 | + { |
|
383 | + /** |
|
384 | + * @filter `gravityview/field/is_visible` Should this field be visible? |
|
385 | + * |
|
386 | + * @param bool $visible Visible or not, defaults to the set field capability requirement if defined. |
|
387 | + * @param \GV\Field $field The field we're looking at. |
|
388 | + * @param \GV\View|null A context view. Since @develop |
|
389 | + */ |
|
390 | + return apply_filters('gravityview/field/is_visible', (!$this->cap || \GVCommon::has_cap($this->cap)), $this, $view); |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Get one of the extra configuration keys via property accessors. |
|
395 | + * |
|
396 | + * @param string $key The key to get. |
|
397 | + * |
|
398 | + * @return mixed|null The value for the given configuration key, null if doesn't exist. |
|
399 | + */ |
|
400 | + public function __get($key) |
|
401 | + { |
|
402 | + switch ($key) { |
|
403 | + default: |
|
404 | + if (isset($this->configuration[$key])) { |
|
405 | + return $this->configuration[$key]; |
|
406 | + } |
|
407 | + } |
|
408 | + |
|
409 | + return null; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Is this set? |
|
414 | + * |
|
415 | + * @param string $key The key to get. |
|
416 | + * |
|
417 | + * @return bool Whether this $key is set or not. |
|
418 | + */ |
|
419 | + public function __isset($key) |
|
420 | + { |
|
421 | + switch ($key) { |
|
422 | + default: |
|
423 | + return isset($this->configuration[$key]); |
|
424 | + } |
|
425 | + } |
|
426 | 426 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace GV; |
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | -if (!defined('GRAVITYVIEW_DIR')) { |
|
6 | +if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
7 | 7 | exit(); |
8 | 8 | } |
9 | 9 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * Everything else is in the properties. |
21 | 21 | */ |
22 | - private $configuration = []; |
|
22 | + private $configuration = [ ]; |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * @var string The field position in the view. |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function as_configuration() |
140 | 140 | { |
141 | - return array_merge([ |
|
141 | + return array_merge( [ |
|
142 | 142 | 'id' => $this->ID, |
143 | 143 | 'label' => $this->label, |
144 | 144 | 'show_label' => $this->show_label ? '1' : '0', |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | 'only_loggedin_cap' => $this->cap, |
149 | 149 | 'search_filter' => $this->search_filter ? '1' : '0', |
150 | 150 | 'show_as_link' => $this->show_as_link ? '1' : '0', |
151 | - ], $this->configuration); |
|
151 | + ], $this->configuration ); |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | /** |
@@ -161,21 +161,21 @@ discard block |
||
161 | 161 | * |
162 | 162 | * @return \GV\Field|null A \GV\Field instance or null if not found. |
163 | 163 | */ |
164 | - final public static function get($source, $args) |
|
164 | + final public static function get( $source, $args ) |
|
165 | 165 | { |
166 | - if (!is_string($source) || !class_exists($source)) { |
|
167 | - gravityview()->log->error('{source} class not found', ['source' => $source]); |
|
166 | + if ( ! is_string( $source ) || ! class_exists( $source ) ) { |
|
167 | + gravityview()->log->error( '{source} class not found', [ 'source' => $source ] ); |
|
168 | 168 | |
169 | 169 | return null; |
170 | 170 | } |
171 | 171 | |
172 | - if (!method_exists($source, 'get_field')) { |
|
173 | - gravityview()->log->error('{source} does not appear to be a valid \GV\Source subclass (get_field method missing)', ['source' => $source]); |
|
172 | + if ( ! method_exists( $source, 'get_field' ) ) { |
|
173 | + gravityview()->log->error( '{source} does not appear to be a valid \GV\Source subclass (get_field method missing)', [ 'source' => $source ] ); |
|
174 | 174 | |
175 | 175 | return null; |
176 | 176 | } |
177 | 177 | |
178 | - return call_user_func_array([$source, 'get_field'], is_array($args) ? $args : [$args]); |
|
178 | + return call_user_func_array( [ $source, 'get_field' ], is_array( $args ) ? $args : [ $args ] ); |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -191,33 +191,33 @@ discard block |
||
191 | 191 | * |
192 | 192 | * @return \GV\Field The field implementation from configuration (\GV\GF_Field, \GV\Internal_Field). |
193 | 193 | */ |
194 | - public static function from_configuration($configuration) |
|
194 | + public static function from_configuration( $configuration ) |
|
195 | 195 | { |
196 | - if (empty($configuration['id'])) { |
|
196 | + if ( empty( $configuration[ 'id' ] ) ) { |
|
197 | 197 | $field = new self(); |
198 | - gravityview()->log->error('Trying to get field from configuration without a field ID.', ['data' => $configuration]); |
|
199 | - $field->update_configuration($configuration); |
|
198 | + gravityview()->log->error( 'Trying to get field from configuration without a field ID.', [ 'data' => $configuration ] ); |
|
199 | + $field->update_configuration( $configuration ); |
|
200 | 200 | |
201 | 201 | return $field; |
202 | 202 | } |
203 | 203 | |
204 | 204 | /** Prevent infinte loops here from unimplemented children. */ |
205 | - if (version_compare(phpversion(), '5.4', '>=')) { |
|
206 | - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
|
205 | + if ( version_compare( phpversion(), '5.4', '>=' ) ) { |
|
206 | + $trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 2 ); |
|
207 | 207 | } else { |
208 | - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
208 | + $trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ); |
|
209 | 209 | } |
210 | - $trace = $trace[1]; |
|
211 | - if ($trace['function'] == 'from_configuration' && $trace['class'] == __CLASS__) { |
|
210 | + $trace = $trace[ 1 ]; |
|
211 | + if ( $trace[ 'function' ] == 'from_configuration' && $trace[ 'class' ] == __CLASS__ ) { |
|
212 | 212 | $field = new self(); |
213 | - gravityview()->log->error('Infinite loop protection tripped. Returning default class here.'); |
|
214 | - $field->update_configuration($configuration); |
|
213 | + gravityview()->log->error( 'Infinite loop protection tripped. Returning default class here.' ); |
|
214 | + $field->update_configuration( $configuration ); |
|
215 | 215 | |
216 | 216 | return $field; |
217 | 217 | } |
218 | 218 | |
219 | 219 | /** @var \GV\GF_Field|\GV\Internal_Field $field_class Determine the field implementation to use, and try to use. */ |
220 | - $field_class = is_numeric($configuration['id']) ? '\GV\GF_Field' : '\GV\Internal_Field'; |
|
220 | + $field_class = is_numeric( $configuration[ 'id' ] ) ? '\GV\GF_Field' : '\GV\Internal_Field'; |
|
221 | 221 | |
222 | 222 | /** |
223 | 223 | * @filter `gravityview/field/class` Filter the field class about to be created from the configuration. |
@@ -225,22 +225,22 @@ discard block |
||
225 | 225 | * @param string $field_class The field class about to be used. |
226 | 226 | * @param array $configuration The configuration as per \GV\Field::as_configuration() |
227 | 227 | */ |
228 | - $field_class = apply_filters('gravityview/field/class', $field_class, $configuration); |
|
228 | + $field_class = apply_filters( 'gravityview/field/class', $field_class, $configuration ); |
|
229 | 229 | |
230 | - if (!class_exists($field_class) || !method_exists($field_class, 'from_configuration')) { |
|
230 | + if ( ! class_exists( $field_class ) || ! method_exists( $field_class, 'from_configuration' ) ) { |
|
231 | 231 | $field = new self(); |
232 | - gravityview()->log->error('Class {field_class}::from_configuration does not exist.', ['field_class' => $field_class]); |
|
233 | - $field->update_configuration($configuration); |
|
232 | + gravityview()->log->error( 'Class {field_class}::from_configuration does not exist.', [ 'field_class' => $field_class ] ); |
|
233 | + $field->update_configuration( $configuration ); |
|
234 | 234 | |
235 | 235 | return $field; |
236 | 236 | } |
237 | 237 | |
238 | - $field = $field_class::from_configuration($configuration); |
|
238 | + $field = $field_class::from_configuration( $configuration ); |
|
239 | 239 | |
240 | - if (!$field) { |
|
240 | + if ( ! $field ) { |
|
241 | 241 | $field = new self(); |
242 | - gravityview()->log->error('Could not configure {field_class} with given configuration.', ['field_class' => __CLASS__, 'data' => $configuration]); |
|
243 | - $field->update_configuration($configuration); |
|
242 | + gravityview()->log->error( 'Could not configure {field_class} with given configuration.', [ 'field_class' => __CLASS__, 'data' => $configuration ] ); |
|
243 | + $field->update_configuration( $configuration ); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return $field; |
@@ -256,23 +256,23 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @return void |
258 | 258 | */ |
259 | - public function update_configuration($configuration) |
|
259 | + public function update_configuration( $configuration ) |
|
260 | 260 | { |
261 | - $configuration = wp_parse_args($configuration, $this->as_configuration()); |
|
261 | + $configuration = wp_parse_args( $configuration, $this->as_configuration() ); |
|
262 | 262 | |
263 | - if ($this->ID != $configuration['id']) { |
|
263 | + if ( $this->ID != $configuration[ 'id' ] ) { |
|
264 | 264 | /** Smelling trouble here... */ |
265 | - gravityview()->log->warning('ID is being changed for {field_class} instance, but implementation is not. Use ::from_configuration instead', ['field_class', __CLASS__]); |
|
265 | + gravityview()->log->warning( 'ID is being changed for {field_class} instance, but implementation is not. Use ::from_configuration instead', [ 'field_class', __CLASS__ ] ); |
|
266 | 266 | } |
267 | 267 | |
268 | - $this->ID = $configuration['id']; |
|
269 | - $this->label = $configuration['label']; |
|
270 | - $this->show_label = $configuration['show_label'] == '1'; |
|
271 | - $this->custom_label = $configuration['custom_label']; |
|
272 | - $this->custom_class = $configuration['custom_class']; |
|
273 | - $this->cap = $configuration['only_loggedin'] == '1' ? $configuration['only_loggedin_cap'] : ''; |
|
274 | - $this->search_filter = $configuration['search_filter'] == '1'; |
|
275 | - $this->show_as_link = $configuration['show_as_link'] == '1'; |
|
268 | + $this->ID = $configuration[ 'id' ]; |
|
269 | + $this->label = $configuration[ 'label' ]; |
|
270 | + $this->show_label = $configuration[ 'show_label' ] == '1'; |
|
271 | + $this->custom_label = $configuration[ 'custom_label' ]; |
|
272 | + $this->custom_class = $configuration[ 'custom_class' ]; |
|
273 | + $this->cap = $configuration[ 'only_loggedin' ] == '1' ? $configuration[ 'only_loggedin_cap' ] : ''; |
|
274 | + $this->search_filter = $configuration[ 'search_filter' ] == '1'; |
|
275 | + $this->show_as_link = $configuration[ 'show_as_link' ] == '1'; |
|
276 | 276 | |
277 | 277 | /** Shared among all field types (sort of). */ |
278 | 278 | $shared_configuration_keys = [ |
@@ -281,9 +281,9 @@ discard block |
||
281 | 281 | ]; |
282 | 282 | |
283 | 283 | /** Everything else goes into the properties for now. @todo subclasses! */ |
284 | - foreach ($configuration as $key => $value) { |
|
285 | - if (!in_array($key, $shared_configuration_keys)) { |
|
286 | - $this->configuration[$key] = $value; |
|
284 | + foreach ( $configuration as $key => $value ) { |
|
285 | + if ( ! in_array( $key, $shared_configuration_keys ) ) { |
|
286 | + $this->configuration[ $key ] = $value; |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | } |
@@ -298,15 +298,15 @@ discard block |
||
298 | 298 | * |
299 | 299 | * @return string The label for this field. Nothing here. |
300 | 300 | */ |
301 | - public function get_label(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
301 | + public function get_label( View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) |
|
302 | 302 | { |
303 | - if (!$this->show_label) { |
|
303 | + if ( ! $this->show_label ) { |
|
304 | 304 | return ''; |
305 | 305 | } |
306 | 306 | |
307 | 307 | /** A custom label is available. */ |
308 | - if (!empty($this->custom_label)) { |
|
309 | - return \GravityView_API::replace_variables($this->custom_label, $source ? $source->form ?: null : null, $entry ? $entry->as_entry() : null); |
|
308 | + if ( ! empty( $this->custom_label ) ) { |
|
309 | + return \GravityView_API::replace_variables( $this->custom_label, $source ? $source->form ?: null : null, $entry ? $entry->as_entry() : null ); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | return ''; |
@@ -324,9 +324,9 @@ discard block |
||
324 | 324 | * |
325 | 325 | * @return mixed The value for this field. |
326 | 326 | */ |
327 | - public function get_value(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
327 | + public function get_value( View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) |
|
328 | 328 | { |
329 | - return $this->get_value_filters(null, $view, $source, $entry, $request); |
|
329 | + return $this->get_value_filters( null, $view, $source, $entry, $request ); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | /** |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | * |
341 | 341 | * This is in its own function since \GV\Field subclasses have to call it. |
342 | 342 | */ |
343 | - protected function get_value_filters($value, View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
343 | + protected function get_value_filters( $value, View $view = null, Source $source = null, Entry $entry = null, Request $request = null ) |
|
344 | 344 | { |
345 | - if ($this->type) { |
|
345 | + if ( $this->type ) { |
|
346 | 346 | /** |
347 | 347 | * @filter `gravityview/field/$type/value` Override the displayed value here. |
348 | 348 | * |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | * @param \GV\Entry $entry The entry for this context if applicable. |
354 | 354 | * @param \GV\Request $request The request for this context if applicable. |
355 | 355 | */ |
356 | - $value = apply_filters("gravityview/field/{$this->type}/value", $value, $this, $view, $source, $entry, $request); |
|
356 | + $value = apply_filters( "gravityview/field/{$this->type}/value", $value, $this, $view, $source, $entry, $request ); |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | /** |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * @param \GV\Entry $entry The entry for this context if applicable. |
367 | 367 | * @param \GV\Request $request The request for this context if applicable. |
368 | 368 | */ |
369 | - return apply_filters('gravityview/field/value', $value, $this, $view, $source, $entry, $request); |
|
369 | + return apply_filters( 'gravityview/field/value', $value, $this, $view, $source, $entry, $request ); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * |
379 | 379 | * @return bool |
380 | 380 | */ |
381 | - public function is_visible($view = null) |
|
381 | + public function is_visible( $view = null ) |
|
382 | 382 | { |
383 | 383 | /** |
384 | 384 | * @filter `gravityview/field/is_visible` Should this field be visible? |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | * @param \GV\Field $field The field we're looking at. |
388 | 388 | * @param \GV\View|null A context view. Since @develop |
389 | 389 | */ |
390 | - return apply_filters('gravityview/field/is_visible', (!$this->cap || \GVCommon::has_cap($this->cap)), $this, $view); |
|
390 | + return apply_filters( 'gravityview/field/is_visible', ( ! $this->cap || \GVCommon::has_cap( $this->cap ) ), $this, $view ); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -397,12 +397,12 @@ discard block |
||
397 | 397 | * |
398 | 398 | * @return mixed|null The value for the given configuration key, null if doesn't exist. |
399 | 399 | */ |
400 | - public function __get($key) |
|
400 | + public function __get( $key ) |
|
401 | 401 | { |
402 | - switch ($key) { |
|
402 | + switch ( $key ) { |
|
403 | 403 | default: |
404 | - if (isset($this->configuration[$key])) { |
|
405 | - return $this->configuration[$key]; |
|
404 | + if ( isset( $this->configuration[ $key ] ) ) { |
|
405 | + return $this->configuration[ $key ]; |
|
406 | 406 | } |
407 | 407 | } |
408 | 408 | |
@@ -416,11 +416,11 @@ discard block |
||
416 | 416 | * |
417 | 417 | * @return bool Whether this $key is set or not. |
418 | 418 | */ |
419 | - public function __isset($key) |
|
419 | + public function __isset( $key ) |
|
420 | 420 | { |
421 | - switch ($key) { |
|
421 | + switch ( $key ) { |
|
422 | 422 | default: |
423 | - return isset($this->configuration[$key]); |
|
423 | + return isset( $this->configuration[ $key ] ); |
|
424 | 424 | } |
425 | 425 | } |
426 | 426 | } |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * Houses all base Field functionality. |
14 | 14 | */ |
15 | -class Field |
|
16 | -{ |
|
15 | +class Field { |
|
17 | 16 | /** |
18 | 17 | * @var array The custom View configuration for this field. |
19 | 18 | * |
@@ -136,8 +135,7 @@ discard block |
||
136 | 135 | * |
137 | 136 | * @return array |
138 | 137 | */ |
139 | - public function as_configuration() |
|
140 | - { |
|
138 | + public function as_configuration() { |
|
141 | 139 | return array_merge([ |
142 | 140 | 'id' => $this->ID, |
143 | 141 | 'label' => $this->label, |
@@ -161,8 +159,7 @@ discard block |
||
161 | 159 | * |
162 | 160 | * @return \GV\Field|null A \GV\Field instance or null if not found. |
163 | 161 | */ |
164 | - final public static function get($source, $args) |
|
165 | - { |
|
162 | + final public static function get($source, $args) { |
|
166 | 163 | if (!is_string($source) || !class_exists($source)) { |
167 | 164 | gravityview()->log->error('{source} class not found', ['source' => $source]); |
168 | 165 | |
@@ -191,8 +188,7 @@ discard block |
||
191 | 188 | * |
192 | 189 | * @return \GV\Field The field implementation from configuration (\GV\GF_Field, \GV\Internal_Field). |
193 | 190 | */ |
194 | - public static function from_configuration($configuration) |
|
195 | - { |
|
191 | + public static function from_configuration($configuration) { |
|
196 | 192 | if (empty($configuration['id'])) { |
197 | 193 | $field = new self(); |
198 | 194 | gravityview()->log->error('Trying to get field from configuration without a field ID.', ['data' => $configuration]); |
@@ -256,8 +252,7 @@ discard block |
||
256 | 252 | * |
257 | 253 | * @return void |
258 | 254 | */ |
259 | - public function update_configuration($configuration) |
|
260 | - { |
|
255 | + public function update_configuration($configuration) { |
|
261 | 256 | $configuration = wp_parse_args($configuration, $this->as_configuration()); |
262 | 257 | |
263 | 258 | if ($this->ID != $configuration['id']) { |
@@ -298,8 +293,7 @@ discard block |
||
298 | 293 | * |
299 | 294 | * @return string The label for this field. Nothing here. |
300 | 295 | */ |
301 | - public function get_label(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
302 | - { |
|
296 | + public function get_label(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) { |
|
303 | 297 | if (!$this->show_label) { |
304 | 298 | return ''; |
305 | 299 | } |
@@ -324,8 +318,7 @@ discard block |
||
324 | 318 | * |
325 | 319 | * @return mixed The value for this field. |
326 | 320 | */ |
327 | - public function get_value(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
328 | - { |
|
321 | + public function get_value(View $view = null, Source $source = null, Entry $entry = null, Request $request = null) { |
|
329 | 322 | return $this->get_value_filters(null, $view, $source, $entry, $request); |
330 | 323 | } |
331 | 324 | |
@@ -340,8 +333,7 @@ discard block |
||
340 | 333 | * |
341 | 334 | * This is in its own function since \GV\Field subclasses have to call it. |
342 | 335 | */ |
343 | - protected function get_value_filters($value, View $view = null, Source $source = null, Entry $entry = null, Request $request = null) |
|
344 | - { |
|
336 | + protected function get_value_filters($value, View $view = null, Source $source = null, Entry $entry = null, Request $request = null) { |
|
345 | 337 | if ($this->type) { |
346 | 338 | /** |
347 | 339 | * @filter `gravityview/field/$type/value` Override the displayed value here. |
@@ -378,8 +370,7 @@ discard block |
||
378 | 370 | * |
379 | 371 | * @return bool |
380 | 372 | */ |
381 | - public function is_visible($view = null) |
|
382 | - { |
|
373 | + public function is_visible($view = null) { |
|
383 | 374 | /** |
384 | 375 | * @filter `gravityview/field/is_visible` Should this field be visible? |
385 | 376 | * |
@@ -397,8 +388,7 @@ discard block |
||
397 | 388 | * |
398 | 389 | * @return mixed|null The value for the given configuration key, null if doesn't exist. |
399 | 390 | */ |
400 | - public function __get($key) |
|
401 | - { |
|
391 | + public function __get($key) { |
|
402 | 392 | switch ($key) { |
403 | 393 | default: |
404 | 394 | if (isset($this->configuration[$key])) { |
@@ -416,8 +406,7 @@ discard block |
||
416 | 406 | * |
417 | 407 | * @return bool Whether this $key is set or not. |
418 | 408 | */ |
419 | - public function __isset($key) |
|
420 | - { |
|
409 | + public function __isset($key) { |
|
421 | 410 | switch ($key) { |
422 | 411 | default: |
423 | 412 | return isset($this->configuration[$key]); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | 6 | if (!defined('GRAVITYVIEW_DIR')) { |
7 | - exit(); |
|
7 | + exit(); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -17,1693 +17,1693 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class View implements \ArrayAccess |
19 | 19 | { |
20 | - /** |
|
21 | - * @var \WP_Post The backing post instance. |
|
22 | - */ |
|
23 | - private $post; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var \GV\View_Settings The settings. |
|
27 | - * |
|
28 | - * @api |
|
29 | - * |
|
30 | - * @since 2.0 |
|
31 | - */ |
|
32 | - public $settings; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var \GV\Widget_Collection The widets attached here. |
|
36 | - * |
|
37 | - * @api |
|
38 | - * |
|
39 | - * @since 2.0 |
|
40 | - */ |
|
41 | - public $widgets; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var \GV\GF_Form|\GV\Form The backing form for this view. |
|
45 | - * |
|
46 | - * Contains the form that is sourced for entries in this view. |
|
47 | - * |
|
48 | - * @api |
|
49 | - * |
|
50 | - * @since 2.0 |
|
51 | - */ |
|
52 | - public $form; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var \GV\Field_Collection The fields for this view. |
|
56 | - * |
|
57 | - * Contains all the fields that are attached to this view. |
|
58 | - * |
|
59 | - * @api |
|
60 | - * |
|
61 | - * @since 2.0 |
|
62 | - */ |
|
63 | - public $fields; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var array |
|
67 | - * |
|
68 | - * Internal static cache for gets, and whatnot. |
|
69 | - * This is not persistent, resets across requests. |
|
70 | - * |
|
71 | - * @internal |
|
72 | - */ |
|
73 | - private static $cache = []; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var \GV\Join[] The joins for all sources in this view. |
|
77 | - * |
|
78 | - * @api |
|
79 | - * |
|
80 | - * @since 2.0.1 |
|
81 | - */ |
|
82 | - public $joins = []; |
|
83 | - |
|
84 | - /** |
|
85 | - * @var \GV\Field[][] The unions for all sources in this view. |
|
86 | - * An array of fields grouped by form_id keyed by |
|
87 | - * main field_id: |
|
88 | - * |
|
89 | - * array( |
|
90 | - * $form_id => array( |
|
91 | - * $field_id => $field, |
|
92 | - * $field_id => $field, |
|
93 | - * ) |
|
94 | - * ) |
|
95 | - * |
|
96 | - * @api |
|
97 | - * |
|
98 | - * @since 2.2.2 |
|
99 | - */ |
|
100 | - public $unions = []; |
|
101 | - |
|
102 | - /** |
|
103 | - * The constructor. |
|
104 | - */ |
|
105 | - public function __construct() |
|
106 | - { |
|
107 | - $this->settings = new View_Settings(); |
|
108 | - $this->fields = new Field_Collection(); |
|
109 | - $this->widgets = new Widget_Collection(); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Register the gravityview WordPress Custom Post Type. |
|
114 | - * |
|
115 | - * @internal |
|
116 | - * |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - public static function register_post_type() |
|
120 | - { |
|
121 | - |
|
122 | - /** Register only once */ |
|
123 | - if (post_type_exists('gravityview')) { |
|
124 | - return; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @filter `gravityview_is_hierarchical` Make GravityView Views hierarchical by returning TRUE |
|
129 | - * This will allow for Views to be nested with Parents and also allows for menu order to be set in the Page Attributes metabox |
|
130 | - * |
|
131 | - * @since 1.13 |
|
132 | - * |
|
133 | - * @param bool $is_hierarchical Default: false |
|
134 | - */ |
|
135 | - $is_hierarchical = (bool) apply_filters('gravityview_is_hierarchical', false); |
|
136 | - |
|
137 | - $supports = ['title', 'revisions']; |
|
138 | - |
|
139 | - if ($is_hierarchical) { |
|
140 | - $supports[] = 'page-attributes'; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @filter `gravityview_post_type_supports` Modify post type support values for `gravityview` post type |
|
145 | - * |
|
146 | - * @see add_post_type_support() |
|
147 | - * @since 1.15.2 |
|
148 | - * |
|
149 | - * @param array $supports Array of features associated with a functional area of the edit screen. Default: 'title', 'revisions'. If $is_hierarchical, also 'page-attributes' |
|
150 | - * @param bool $is_hierarchical Do Views support parent/child relationships? See `gravityview_is_hierarchical` filter. |
|
151 | - */ |
|
152 | - $supports = apply_filters('gravityview_post_type_support', $supports, $is_hierarchical); |
|
153 | - |
|
154 | - /** Register Custom Post Type - gravityview */ |
|
155 | - $labels = [ |
|
156 | - 'name' => _x('Views', 'Post Type General Name', 'gravityview'), |
|
157 | - 'singular_name' => _x('View', 'Post Type Singular Name', 'gravityview'), |
|
158 | - 'menu_name' => _x('Views', 'Menu name', 'gravityview'), |
|
159 | - 'parent_item_colon' => __('Parent View:', 'gravityview'), |
|
160 | - 'all_items' => __('All Views', 'gravityview'), |
|
161 | - 'view_item' => _x('View', 'View Item', 'gravityview'), |
|
162 | - 'add_new_item' => __('Add New View', 'gravityview'), |
|
163 | - 'add_new' => __('New View', 'gravityview'), |
|
164 | - 'edit_item' => __('Edit View', 'gravityview'), |
|
165 | - 'update_item' => __('Update View', 'gravityview'), |
|
166 | - 'search_items' => __('Search Views', 'gravityview'), |
|
167 | - 'not_found' => \GravityView_Admin::no_views_text(), |
|
168 | - 'not_found_in_trash' => __('No Views found in Trash', 'gravityview'), |
|
169 | - 'filter_items_list' => __('Filter Views list', 'gravityview'), |
|
170 | - 'items_list_navigation' => __('Views list navigation', 'gravityview'), |
|
171 | - 'items_list' => __('Views list', 'gravityview'), |
|
172 | - 'view_items' => __('See Views', 'gravityview'), |
|
173 | - 'attributes' => __('View Attributes', 'gravityview'), |
|
174 | - 'item_updated' => __('View updated.', 'gravityview'), |
|
175 | - 'item_published' => __('View published.', 'gravityview'), |
|
176 | - 'item_reverted_to_draft' => __('View reverted to draft.', 'gravityview'), |
|
177 | - 'item_scheduled' => __('View scheduled.', 'gravityview'), |
|
178 | - ]; |
|
179 | - |
|
180 | - $args = [ |
|
181 | - 'label' => __('view', 'gravityview'), |
|
182 | - 'description' => __('Create views based on a Gravity Forms form', 'gravityview'), |
|
183 | - 'labels' => $labels, |
|
184 | - 'supports' => $supports, |
|
185 | - 'hierarchical' => $is_hierarchical, |
|
186 | - /** |
|
187 | - * @filter `gravityview_direct_access` Should Views be directly accessible, or only visible using the shortcode? |
|
188 | - * |
|
189 | - * @see https://codex.wordpress.org/Function_Reference/register_post_type#public |
|
190 | - * @since 1.15.2 |
|
191 | - * |
|
192 | - * @param bool `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded via shortcode. Default: `true` |
|
193 | - * @param int $view_id The ID of the View currently being requested. `0` for general setting |
|
194 | - */ |
|
195 | - 'public' => apply_filters('gravityview_direct_access', gravityview()->plugin->is_compatible(), 0), |
|
196 | - 'show_ui' => gravityview()->plugin->is_compatible(), |
|
197 | - 'show_in_menu' => gravityview()->plugin->is_compatible(), |
|
198 | - 'show_in_nav_menus' => true, |
|
199 | - 'show_in_admin_bar' => true, |
|
200 | - 'menu_position' => 17, |
|
201 | - 'menu_icon' => '', |
|
202 | - 'can_export' => true, |
|
203 | - /** |
|
204 | - * @filter `gravityview_has_archive` Enable Custom Post Type archive? |
|
205 | - * |
|
206 | - * @since 1.7.3 |
|
207 | - * |
|
208 | - * @param bool False: don't have frontend archive; True: yes, have archive. Default: false |
|
209 | - */ |
|
210 | - 'has_archive' => apply_filters('gravityview_has_archive', false), |
|
211 | - 'exclude_from_search' => true, |
|
212 | - 'rewrite' => [ |
|
213 | - /** |
|
214 | - * @filter `gravityview_slug` Modify the url part for a View. |
|
215 | - * |
|
216 | - * @see https://docs.gravityview.co/article/62-changing-the-view-slug |
|
217 | - * |
|
218 | - * @param string $slug The slug shown in the URL |
|
219 | - */ |
|
220 | - 'slug' => apply_filters('gravityview_slug', 'view'), |
|
221 | - |
|
222 | - /** |
|
223 | - * @filter `gravityview/post_type/with_front` Should the permalink structure |
|
224 | - * be prepended with the front base. |
|
225 | - * (example: if your permalink structure is /blog/, then your links will be: false->/view/, true->/blog/view/). |
|
226 | - * Defaults to true. |
|
227 | - * |
|
228 | - * @see https://codex.wordpress.org/Function_Reference/register_post_type |
|
229 | - * @since 2.0 |
|
230 | - * |
|
231 | - * @param bool $with_front |
|
232 | - */ |
|
233 | - 'with_front' => apply_filters('gravityview/post_type/with_front', true), |
|
234 | - ], |
|
235 | - 'capability_type' => 'gravityview', |
|
236 | - 'map_meta_cap' => true, |
|
237 | - ]; |
|
238 | - |
|
239 | - register_post_type('gravityview', $args); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Add extra rewrite endpoints. |
|
244 | - * |
|
245 | - * @return void |
|
246 | - */ |
|
247 | - public static function add_rewrite_endpoint() |
|
248 | - { |
|
249 | - /** |
|
250 | - * CSV. |
|
251 | - */ |
|
252 | - global $wp_rewrite; |
|
253 | - |
|
254 | - $slug = apply_filters('gravityview_slug', 'view'); |
|
255 | - $slug = ('/' !== $wp_rewrite->front) ? sprintf('%s/%s', trim($wp_rewrite->front, '/'), $slug) : $slug; |
|
256 | - $csv_rule = [sprintf('%s/([^/]+)/csv/?', $slug), 'index.php?gravityview=$matches[1]&csv=1', 'top']; |
|
257 | - $tsv_rule = [sprintf('%s/([^/]+)/tsv/?', $slug), 'index.php?gravityview=$matches[1]&tsv=1', 'top']; |
|
258 | - |
|
259 | - add_filter('query_vars', function ($query_vars) { |
|
260 | - $query_vars[] = 'csv'; |
|
261 | - $query_vars[] = 'tsv'; |
|
262 | - |
|
263 | - return $query_vars; |
|
264 | - }); |
|
265 | - |
|
266 | - if (!isset($wp_rewrite->extra_rules_top[$csv_rule[0]])) { |
|
267 | - call_user_func_array('add_rewrite_rule', $csv_rule); |
|
268 | - call_user_func_array('add_rewrite_rule', $tsv_rule); |
|
269 | - } |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * A renderer filter for the View post type content. |
|
274 | - * |
|
275 | - * @param string $content Should be empty, as we don't store anything there. |
|
276 | - * |
|
277 | - * @return string $content The view content as output by the renderers. |
|
278 | - */ |
|
279 | - public static function content($content) |
|
280 | - { |
|
281 | - $request = gravityview()->request; |
|
282 | - |
|
283 | - // Plugins may run through the content in the header. WP SEO does this for its OpenGraph functionality. |
|
284 | - if (!defined('DOING_GRAVITYVIEW_TESTS')) { |
|
285 | - if (!did_action('loop_start')) { |
|
286 | - gravityview()->log->debug('Not processing yet: loop_start hasn\'t run yet. Current action: {action}', ['action' => current_filter()]); |
|
287 | - |
|
288 | - return $content; |
|
289 | - } |
|
290 | - |
|
291 | - // We don't want this filter to run infinite loop on any post content fields |
|
292 | - remove_filter('the_content', [__CLASS__, __METHOD__]); |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * This is not a View. Bail. |
|
297 | - * |
|
298 | - * Shortcodes and oEmbeds and whatnot will be handled |
|
299 | - * elsewhere. |
|
300 | - */ |
|
301 | - if (!$view = $request->is_view()) { |
|
302 | - return $content; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Check permissions. |
|
307 | - */ |
|
308 | - while ($error = $view->can_render(null, $request)) { |
|
309 | - if (!is_wp_error($error)) { |
|
310 | - break; |
|
311 | - } |
|
312 | - |
|
313 | - switch (str_replace('gravityview/', '', $error->get_error_code())) { |
|
314 | - case 'post_password_required': |
|
315 | - return get_the_password_form($view->ID); |
|
316 | - case 'no_form_attached': |
|
317 | - |
|
318 | - gravityview()->log->error('View #{view_id} cannot render: {error_code} {error_message}', ['error_code' => $error->get_error_code(), 'error_message' => $error->get_error_message()]); |
|
319 | - |
|
320 | - /** |
|
321 | - * This View has no data source. There's nothing to show really. |
|
322 | - * ...apart from a nice message if the user can do anything about it. |
|
323 | - */ |
|
324 | - if (\GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview'], $view->ID)) { |
|
325 | - $title = sprintf(__('This View is not configured properly. Start by <a href="%s">selecting a form</a>.', 'gravityview'), esc_url(get_edit_post_link($view->ID, false))); |
|
326 | - |
|
327 | - $message = esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
328 | - |
|
329 | - $image = sprintf('<img alt="%s" src="%s" style="margin-top: 10px;" />', esc_attr__('Data Source', 'gravityview'), esc_url(plugins_url('assets/images/screenshots/data-source.png', GRAVITYVIEW_FILE))); |
|
330 | - |
|
331 | - return \GVCommon::generate_notice('<h3>'.$title.'</h3>'.wpautop($message.$image), 'notice'); |
|
332 | - } |
|
333 | - break; |
|
334 | - case 'in_trash': |
|
335 | - |
|
336 | - if (\GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview'], $view->ID)) { |
|
337 | - $notice = sprintf(__('This View is in the Trash. You can <a href="%s">restore the View here</a>.', 'gravityview'), esc_url(get_edit_post_link($view->ID, false))); |
|
338 | - |
|
339 | - return \GVCommon::generate_notice('<h3>'.$notice.'</h3>', 'notice', ['edit_gravityviews', 'edit_gravityview'], $view->ID); |
|
340 | - } |
|
341 | - |
|
342 | - return ''; // Do not show |
|
343 | - break; |
|
344 | - case 'no_direct_access': |
|
345 | - case 'embed_only': |
|
346 | - case 'not_public': |
|
347 | - default: |
|
348 | - gravityview()->log->notice('View #{view_id} cannot render: {error_code} {error_message}', ['error_code' => $error->get_error_code(), 'error_message' => $error->get_error_message()]); |
|
349 | - |
|
350 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
351 | - } |
|
352 | - |
|
353 | - return $content; |
|
354 | - } |
|
355 | - |
|
356 | - $is_admin_and_can_view = $view->settings->get('admin_show_all_statuses') && \GVCommon::has_cap('gravityview_moderate_entries', $view->ID); |
|
357 | - |
|
358 | - /** |
|
359 | - * Editing a single entry. |
|
360 | - */ |
|
361 | - if ($entry = $request->is_edit_entry($view->form ? $view->form->ID : 0)) { |
|
362 | - if ($entry['status'] != 'active') { |
|
363 | - gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $entry->ID]); |
|
364 | - |
|
365 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
366 | - } |
|
367 | - |
|
368 | - if (apply_filters('gravityview_custom_entry_slug', false) && $entry->slug != get_query_var(\GV\Entry::get_endpoint_name())) { |
|
369 | - gravityview()->log->error('Entry ID #{entry_id} was accessed by a bad slug', ['entry_id' => $entry->ID]); |
|
370 | - |
|
371 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
372 | - } |
|
373 | - |
|
374 | - if ($view->settings->get('show_only_approved') && !$is_admin_and_can_view) { |
|
375 | - if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($entry->ID, \GravityView_Entry_Approval::meta_key))) { |
|
376 | - gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $entry->ID]); |
|
377 | - |
|
378 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
379 | - } |
|
380 | - } |
|
381 | - |
|
382 | - $renderer = new Edit_Entry_Renderer(); |
|
383 | - |
|
384 | - return $renderer->render($entry, $view, $request); |
|
385 | - |
|
386 | - /** |
|
387 | - * Viewing a single entry. |
|
388 | - */ |
|
389 | - } elseif ($entry = $request->is_entry($view->form ? $view->form->ID : 0)) { |
|
390 | - $entryset = $entry->is_multi() ? $entry->entries : [$entry]; |
|
391 | - |
|
392 | - $custom_slug = apply_filters('gravityview_custom_entry_slug', false); |
|
393 | - $ids = explode(',', get_query_var(\GV\Entry::get_endpoint_name())); |
|
394 | - |
|
395 | - $show_only_approved = $view->settings->get('show_only_approved'); |
|
396 | - |
|
397 | - foreach ($entryset as $e) { |
|
398 | - if ('active' !== $e['status']) { |
|
399 | - gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $e->ID]); |
|
400 | - |
|
401 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
402 | - } |
|
403 | - |
|
404 | - if ($custom_slug && !in_array($e->slug, $ids)) { |
|
405 | - gravityview()->log->error('Entry ID #{entry_id} was accessed by a bad slug', ['entry_id' => $e->ID]); |
|
406 | - |
|
407 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
408 | - } |
|
409 | - |
|
410 | - if ($show_only_approved && !$is_admin_and_can_view) { |
|
411 | - if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($e->ID, \GravityView_Entry_Approval::meta_key))) { |
|
412 | - gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $e->ID]); |
|
413 | - |
|
414 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - $error = \GVCommon::check_entry_display($e->as_entry(), $view); |
|
419 | - |
|
420 | - if (is_wp_error($error)) { |
|
421 | - gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing: {message}', ['entry_id' => $e->ID, 'message' => $error->get_error_message()]); |
|
422 | - |
|
423 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
424 | - } |
|
425 | - } |
|
426 | - |
|
427 | - $renderer = new Entry_Renderer(); |
|
428 | - |
|
429 | - return $renderer->render($entry, $view, $request); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Plain old View. |
|
434 | - */ |
|
435 | - $renderer = new View_Renderer(); |
|
436 | - |
|
437 | - return $renderer->render($view, $request); |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * Checks whether this view can be accessed or not. |
|
442 | - * |
|
443 | - * @param string[] $context The context we're asking for access from. |
|
444 | - * Can any and as many of one of: |
|
445 | - * edit An edit context. |
|
446 | - * single A single context. |
|
447 | - * cpt The custom post type single page accessed. |
|
448 | - * shortcode Embedded as a shortcode. |
|
449 | - * oembed Embedded as an oEmbed. |
|
450 | - * rest A REST call. |
|
451 | - * @param \GV\Request $request The request |
|
452 | - * |
|
453 | - * @return bool|\WP_Error An error if this View shouldn't be rendered here. |
|
454 | - */ |
|
455 | - public function can_render($context = null, $request = null) |
|
456 | - { |
|
457 | - if (!$request) { |
|
458 | - $request = gravityview()->request; |
|
459 | - } |
|
460 | - |
|
461 | - if (!is_array($context)) { |
|
462 | - $context = []; |
|
463 | - } |
|
464 | - |
|
465 | - /** |
|
466 | - * @filter `gravityview/view/can_render` Whether the view can be rendered or not. |
|
467 | - * |
|
468 | - * @param bool|\WP_Error $result The result. Default: null. |
|
469 | - * @param \GV\View $view The view. |
|
470 | - * @param string[] $context See \GV\View::can_render |
|
471 | - * @param \GV\Request $request The request. |
|
472 | - */ |
|
473 | - if (!is_null($result = apply_filters('gravityview/view/can_render', null, $this, $context, $request))) { |
|
474 | - return $result; |
|
475 | - } |
|
476 | - |
|
477 | - if (in_array('rest', $context)) { |
|
478 | - // REST |
|
479 | - if (gravityview()->plugin->settings->get('rest_api') === '1' && $this->settings->get('rest_disable') === '1') { |
|
480 | - return new \WP_Error('gravityview/rest_disabled'); |
|
481 | - } elseif (gravityview()->plugin->settings->get('rest_api') !== '1' && $this->settings->get('rest_enable') !== '1') { |
|
482 | - return new \WP_Error('gravityview/rest_disabled'); |
|
483 | - } |
|
484 | - } |
|
485 | - |
|
486 | - if (in_array('csv', $context)) { |
|
487 | - if ($this->settings->get('csv_enable') !== '1') { |
|
488 | - return new \WP_Error('gravityview/csv_disabled', 'The CSV endpoint is not enabled for this View'); |
|
489 | - } |
|
490 | - } |
|
491 | - |
|
492 | - /** |
|
493 | - * This View is password protected. Nothing to do here. |
|
494 | - */ |
|
495 | - if (post_password_required($this->ID)) { |
|
496 | - gravityview()->log->notice('Post password is required for View #{view_id}', ['view_id' => $this->ID]); |
|
497 | - |
|
498 | - return new \WP_Error('gravityview/post_password_required'); |
|
499 | - } |
|
500 | - |
|
501 | - if (!$this->form) { |
|
502 | - gravityview()->log->notice('View #{id} has no form attached to it.', ['id' => $this->ID]); |
|
503 | - |
|
504 | - return new \WP_Error('gravityview/no_form_attached'); |
|
505 | - } |
|
506 | - |
|
507 | - if (!in_array('shortcode', $context)) { |
|
508 | - /** |
|
509 | - * Is this View directly accessible via a post URL? |
|
510 | - * |
|
511 | - * @see https://codex.wordpress.org/Function_Reference/register_post_type#public |
|
512 | - */ |
|
513 | - |
|
514 | - /** |
|
515 | - * @filter `gravityview_direct_access` Should Views be directly accessible, or only visible using the shortcode? |
|
516 | - * |
|
517 | - * @deprecated |
|
518 | - * |
|
519 | - * @param bool `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded. Default: `true` |
|
520 | - * @param int $view_id The ID of the View currently being requested. `0` for general setting |
|
521 | - */ |
|
522 | - $direct_access = apply_filters('gravityview_direct_access', true, $this->ID); |
|
523 | - |
|
524 | - /** |
|
525 | - * @filter `gravityview/request/output/direct` Should this View be directly accessbile? |
|
526 | - * |
|
527 | - * @since 2.0 |
|
528 | - * |
|
529 | - * @param bool Accessible or not. Default: accessbile. |
|
530 | - * @param \GV\View $view The View we're trying to directly render here. |
|
531 | - * @param \GV\Request $request The current request. |
|
532 | - */ |
|
533 | - if (!apply_filters('gravityview/view/output/direct', $direct_access, $this, $request)) { |
|
534 | - return new \WP_Error('gravityview/no_direct_access'); |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Is this View an embed-only View? If so, don't allow rendering here, |
|
539 | - * as this is a direct request. |
|
540 | - */ |
|
541 | - if ($this->settings->get('embed_only') && !\GVCommon::has_cap('read_private_gravityviews')) { |
|
542 | - return new \WP_Error('gravityview/embed_only'); |
|
543 | - } |
|
544 | - } |
|
545 | - |
|
546 | - /** Private, pending, draft, etc. */ |
|
547 | - $public_states = get_post_stati(['public' => true]); |
|
548 | - if (!in_array($this->post_status, $public_states) && !\GVCommon::has_cap('read_gravityview', $this->ID)) { |
|
549 | - gravityview()->log->notice('The current user cannot access this View #{view_id}', ['view_id' => $this->ID]); |
|
550 | - |
|
551 | - return new \WP_Error('gravityview/not_public'); |
|
552 | - } |
|
553 | - |
|
554 | - return true; |
|
555 | - } |
|
556 | - |
|
557 | - /** |
|
558 | - * Get joins associated with a view. |
|
559 | - * |
|
560 | - * @param \WP_Post $post GravityView CPT to get joins for |
|
561 | - * |
|
562 | - * @api |
|
563 | - * |
|
564 | - * @since 2.0.11 |
|
565 | - * |
|
566 | - * @return \GV\Join[] Array of \GV\Join instances |
|
567 | - */ |
|
568 | - public static function get_joins($post) |
|
569 | - { |
|
570 | - $joins = []; |
|
571 | - |
|
572 | - if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
573 | - gravityview()->log->info('Cannot get joined forms; joins feature not supported.'); |
|
574 | - |
|
575 | - return $joins; |
|
576 | - } |
|
577 | - |
|
578 | - if (!$post || 'gravityview' !== get_post_type($post)) { |
|
579 | - gravityview()->log->error('Only "gravityview" post types can be \GV\View instances.'); |
|
580 | - |
|
581 | - return $joins; |
|
582 | - } |
|
583 | - |
|
584 | - $joins_meta = get_post_meta($post->ID, '_gravityview_form_joins', true); |
|
585 | - |
|
586 | - if (empty($joins_meta)) { |
|
587 | - return $joins; |
|
588 | - } |
|
589 | - |
|
590 | - foreach ($joins_meta as $meta) { |
|
591 | - if (!is_array($meta) || count($meta) != 4) { |
|
592 | - continue; |
|
593 | - } |
|
594 | - |
|
595 | - list($join, $join_column, $join_on, $join_on_column) = $meta; |
|
596 | - |
|
597 | - $join = GF_Form::by_id($join); |
|
598 | - $join_on = GF_Form::by_id($join_on); |
|
599 | - |
|
600 | - $join_column = is_numeric($join_column) ? GF_Field::by_id($join, $join_column) : Internal_Field::by_id($join_column); |
|
601 | - $join_on_column = is_numeric($join_on_column) ? GF_Field::by_id($join_on, $join_on_column) : Internal_Field::by_id($join_on_column); |
|
602 | - |
|
603 | - $joins[] = new Join($join, $join_column, $join_on, $join_on_column); |
|
604 | - } |
|
605 | - |
|
606 | - return $joins; |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * Get joined forms associated with a view |
|
611 | - * In no particular order. |
|
612 | - * |
|
613 | - * @since 2.0.11 |
|
614 | - * |
|
615 | - * @api |
|
616 | - * |
|
617 | - * @since 2.0 |
|
618 | - * |
|
619 | - * @param int $post_id ID of the View |
|
620 | - * |
|
621 | - * @return \GV\GF_Form[] Array of \GV\GF_Form instances |
|
622 | - */ |
|
623 | - public static function get_joined_forms($post_id) |
|
624 | - { |
|
625 | - $forms = []; |
|
626 | - |
|
627 | - if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
628 | - gravityview()->log->info('Cannot get joined forms; joins feature not supported.'); |
|
629 | - |
|
630 | - return $forms; |
|
631 | - } |
|
632 | - |
|
633 | - if (!$post_id || !gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
634 | - return $forms; |
|
635 | - } |
|
636 | - |
|
637 | - if (empty($post_id)) { |
|
638 | - gravityview()->log->error('Cannot get joined forms; $post_id was empty'); |
|
639 | - |
|
640 | - return $forms; |
|
641 | - } |
|
642 | - |
|
643 | - $joins_meta = get_post_meta($post_id, '_gravityview_form_joins', true); |
|
644 | - |
|
645 | - if (empty($joins_meta)) { |
|
646 | - return $forms; |
|
647 | - } |
|
648 | - |
|
649 | - foreach ($joins_meta as $meta) { |
|
650 | - if (!is_array($meta) || count($meta) != 4) { |
|
651 | - continue; |
|
652 | - } |
|
653 | - |
|
654 | - list($join, $join_column, $join_on, $join_on_column) = $meta; |
|
655 | - |
|
656 | - if ($form = GF_Form::by_id($join_on)) { |
|
657 | - $forms[$join_on] = $form; |
|
658 | - } |
|
659 | - |
|
660 | - if ($form = GF_Form::by_id($join)) { |
|
661 | - $forms[$join] = $form; |
|
662 | - } |
|
663 | - } |
|
664 | - |
|
665 | - return $forms; |
|
666 | - } |
|
667 | - |
|
668 | - /** |
|
669 | - * Get unions associated with a view. |
|
670 | - * |
|
671 | - * @param \WP_Post $post GravityView CPT to get unions for |
|
672 | - * |
|
673 | - * @api |
|
674 | - * |
|
675 | - * @since 2.2.2 |
|
676 | - * |
|
677 | - * @return \GV\Field[][] Array of unions (see self::$unions) |
|
678 | - */ |
|
679 | - public static function get_unions($post) |
|
680 | - { |
|
681 | - $unions = []; |
|
682 | - |
|
683 | - if (!$post || 'gravityview' !== get_post_type($post)) { |
|
684 | - gravityview()->log->error('Only "gravityview" post types can be \GV\View instances.'); |
|
685 | - |
|
686 | - return $unions; |
|
687 | - } |
|
688 | - |
|
689 | - $fields = get_post_meta($post->ID, '_gravityview_directory_fields', true); |
|
690 | - |
|
691 | - if (empty($fields)) { |
|
692 | - return $unions; |
|
693 | - } |
|
694 | - |
|
695 | - foreach ($fields as $location => $_fields) { |
|
696 | - if (strpos($location, 'directory_') !== 0) { |
|
697 | - continue; |
|
698 | - } |
|
699 | - |
|
700 | - foreach ($_fields as $field) { |
|
701 | - if (!empty($field['unions'])) { |
|
702 | - foreach ($field['unions'] as $form_id => $field_id) { |
|
703 | - if (!isset($unions[$form_id])) { |
|
704 | - $unions[$form_id] = []; |
|
705 | - } |
|
706 | - |
|
707 | - $unions[$form_id][$field['id']] = |
|
708 | - is_numeric($field_id) ? \GV\GF_Field::by_id(\GV\GF_Form::by_id($form_id), $field_id) : \GV\Internal_Field::by_id($field_id); |
|
709 | - } |
|
710 | - } |
|
711 | - } |
|
712 | - |
|
713 | - break; |
|
714 | - } |
|
715 | - |
|
716 | - if ($unions) { |
|
717 | - if (!gravityview()->plugin->supports(Plugin::FEATURE_UNIONS)) { |
|
718 | - gravityview()->log->error('Cannot get unions; unions feature not supported.'); |
|
719 | - } |
|
720 | - } |
|
721 | - |
|
722 | - // @todo We'll probably need to backfill null unions |
|
723 | - |
|
724 | - return $unions; |
|
725 | - } |
|
726 | - |
|
727 | - /** |
|
728 | - * Construct a \GV\View instance from a \WP_Post. |
|
729 | - * |
|
730 | - * @param \WP_Post $post The \WP_Post instance to wrap. |
|
731 | - * |
|
732 | - * @api |
|
733 | - * |
|
734 | - * @since 2.0 |
|
735 | - * |
|
736 | - * @return \GV\View|null An instance around this \WP_Post if valid, null otherwise. |
|
737 | - */ |
|
738 | - public static function from_post($post) |
|
739 | - { |
|
740 | - if (!$post || 'gravityview' !== get_post_type($post)) { |
|
741 | - gravityview()->log->error('Only gravityview post types can be \GV\View instances.'); |
|
742 | - |
|
743 | - return null; |
|
744 | - } |
|
745 | - |
|
746 | - if ($view = Utils::get(self::$cache, "View::from_post:{$post->ID}")) { |
|
747 | - /** |
|
748 | - * @filter `gravityview/view/get` Override View. |
|
749 | - * |
|
750 | - * @param \GV\View $view The View instance pointer. |
|
751 | - * |
|
752 | - * @since 2.1 |
|
753 | - */ |
|
754 | - do_action_ref_array('gravityview/view/get', [&$view]); |
|
755 | - |
|
756 | - return $view; |
|
757 | - } |
|
758 | - |
|
759 | - $view = new self(); |
|
760 | - $view->post = $post; |
|
761 | - |
|
762 | - /** Get connected form. */ |
|
763 | - $view->form = GF_Form::by_id($view->_gravityview_form_id); |
|
764 | - if (!$view->form) { |
|
765 | - gravityview()->log->error('View #{view_id} tried attaching non-existent Form #{form_id} to it.', [ |
|
766 | - 'view_id' => $view->ID, |
|
767 | - 'form_id' => $view->_gravityview_form_id ?: 0, |
|
768 | - ]); |
|
769 | - } |
|
770 | - |
|
771 | - $view->joins = $view::get_joins($post); |
|
772 | - |
|
773 | - $view->unions = $view::get_unions($post); |
|
774 | - |
|
775 | - /** |
|
776 | - * @filter `gravityview/configuration/fields` Filter the View fields' configuration array. |
|
777 | - * |
|
778 | - * @since 1.6.5 |
|
779 | - * @deprecated Use `gravityview/view/configuration/fields` or `gravityview/view/fields` filters. |
|
780 | - * |
|
781 | - * @param $fields array Multi-array of fields with first level being the field zones. |
|
782 | - * @param $view_id int The View the fields are being pulled for. |
|
783 | - */ |
|
784 | - $configuration = apply_filters('gravityview/configuration/fields', (array) $view->_gravityview_directory_fields, $view->ID); |
|
785 | - |
|
786 | - /** |
|
787 | - * @filter `gravityview/view/configuration/fields` Filter the View fields' configuration array. |
|
788 | - * |
|
789 | - * @since 2.0 |
|
790 | - * |
|
791 | - * @param array $fields Multi-array of fields with first level being the field zones. |
|
792 | - * @param \GV\View $view The View the fields are being pulled for. |
|
793 | - */ |
|
794 | - $configuration = apply_filters('gravityview/view/configuration/fields', $configuration, $view); |
|
795 | - |
|
796 | - /** |
|
797 | - * @filter `gravityview/view/fields` Filter the Field Collection for this View. |
|
798 | - * |
|
799 | - * @since 2.0 |
|
800 | - * |
|
801 | - * @param \GV\Field_Collection $fields A collection of fields. |
|
802 | - * @param \GV\View $view The View the fields are being pulled for. |
|
803 | - */ |
|
804 | - $view->fields = apply_filters('gravityview/view/fields', Field_Collection::from_configuration($configuration), $view); |
|
805 | - |
|
806 | - /** |
|
807 | - * @filter `gravityview/view/configuration/widgets` Filter the View widgets' configuration array. |
|
808 | - * |
|
809 | - * @since 2.0 |
|
810 | - * |
|
811 | - * @param array $fields Multi-array of widgets with first level being the field zones. |
|
812 | - * @param \GV\View $view The View the widgets are being pulled for. |
|
813 | - */ |
|
814 | - $configuration = apply_filters('gravityview/view/configuration/widgets', (array) $view->_gravityview_directory_widgets, $view); |
|
815 | - |
|
816 | - /** |
|
817 | - * @filter `gravityview/view/widgets` Filter the Widget Collection for this View. |
|
818 | - * |
|
819 | - * @since 2.0 |
|
820 | - * |
|
821 | - * @param \GV\Widget_Collection $widgets A collection of widgets. |
|
822 | - * @param \GV\View $view The View the widgets are being pulled for. |
|
823 | - */ |
|
824 | - $view->widgets = apply_filters('gravityview/view/widgets', Widget_Collection::from_configuration($configuration), $view); |
|
825 | - |
|
826 | - /** View configuration. */ |
|
827 | - $view->settings->update(gravityview_get_template_settings($view->ID)); |
|
828 | - |
|
829 | - /** Add the template name into the settings. */ |
|
830 | - $view->settings->update(['template' => gravityview_get_template_id($view->ID)]); |
|
831 | - |
|
832 | - /** View basics. */ |
|
833 | - $view->settings->update([ |
|
834 | - 'id' => $view->ID, |
|
835 | - ]); |
|
836 | - |
|
837 | - self::$cache["View::from_post:{$post->ID}"] = &$view; |
|
838 | - |
|
839 | - /** |
|
840 | - * @filter `gravityview/view/get` Override View. |
|
841 | - * |
|
842 | - * @param \GV\View $view The View instance pointer. |
|
843 | - * |
|
844 | - * @since 2.1 |
|
845 | - */ |
|
846 | - do_action_ref_array('gravityview/view/get', [&$view]); |
|
847 | - |
|
848 | - return $view; |
|
849 | - } |
|
850 | - |
|
851 | - /** |
|
852 | - * Flush the view cache. |
|
853 | - * |
|
854 | - * @param int $view_id The View to reset cache for. Optional. Default: resets everything. |
|
855 | - * |
|
856 | - * @internal |
|
857 | - */ |
|
858 | - public static function _flush_cache($view_id = null) |
|
859 | - { |
|
860 | - if ($view_id) { |
|
861 | - unset(self::$cache["View::from_post:$view_id"]); |
|
862 | - |
|
863 | - return; |
|
864 | - } |
|
865 | - self::$cache = []; |
|
866 | - } |
|
867 | - |
|
868 | - /** |
|
869 | - * Construct a \GV\View instance from a post ID. |
|
870 | - * |
|
871 | - * @param int|string $post_id The post ID. |
|
872 | - * |
|
873 | - * @api |
|
874 | - * |
|
875 | - * @since 2.0 |
|
876 | - * |
|
877 | - * @return \GV\View|null An instance around this \WP_Post or null if not found. |
|
878 | - */ |
|
879 | - public static function by_id($post_id) |
|
880 | - { |
|
881 | - if (!$post_id || !$post = get_post($post_id)) { |
|
882 | - return null; |
|
883 | - } |
|
884 | - |
|
885 | - return self::from_post($post); |
|
886 | - } |
|
887 | - |
|
888 | - /** |
|
889 | - * Determines if a view exists to begin with. |
|
890 | - * |
|
891 | - * @param int|\WP_Post|null $view The WordPress post ID, a \WP_Post object or null for global $post; |
|
892 | - * |
|
893 | - * @api |
|
894 | - * |
|
895 | - * @since 2.0 |
|
896 | - * |
|
897 | - * @return bool Whether the post exists or not. |
|
898 | - */ |
|
899 | - public static function exists($view) |
|
900 | - { |
|
901 | - return get_post_type($view) == 'gravityview'; |
|
902 | - } |
|
903 | - |
|
904 | - /** |
|
905 | - * ArrayAccess compatibility layer with GravityView_View_Data::$views. |
|
906 | - * |
|
907 | - * @internal |
|
908 | - * |
|
909 | - * @deprecated |
|
910 | - * @since 2.0 |
|
911 | - * |
|
912 | - * @return bool Whether the offset exists or not, limited to GravityView_View_Data::$views element keys. |
|
913 | - */ |
|
914 | - public function offsetExists($offset) |
|
915 | - { |
|
916 | - $data_keys = ['id', 'view_id', 'form_id', 'template_id', 'atts', 'fields', 'widgets', 'form']; |
|
917 | - |
|
918 | - return in_array($offset, $data_keys); |
|
919 | - } |
|
920 | - |
|
921 | - /** |
|
922 | - * ArrayAccess compatibility layer with GravityView_View_Data::$views. |
|
923 | - * |
|
924 | - * Maps the old keys to the new data; |
|
925 | - * |
|
926 | - * @internal |
|
927 | - * |
|
928 | - * @deprecated |
|
929 | - * @since 2.0 |
|
930 | - * |
|
931 | - * @return mixed The value of the requested view data key limited to GravityView_View_Data::$views element keys. If offset not found, return null. |
|
932 | - */ |
|
933 | - public function offsetGet($offset) |
|
934 | - { |
|
935 | - gravityview()->log->notice('This is a \GV\View object should not be accessed as an array.'); |
|
936 | - |
|
937 | - if (!isset($this[$offset])) { |
|
938 | - return null; |
|
939 | - } |
|
940 | - |
|
941 | - switch ($offset) { |
|
942 | - case 'id': |
|
943 | - case 'view_id': |
|
944 | - return $this->ID; |
|
945 | - case 'form': |
|
946 | - return $this->form; |
|
947 | - case 'form_id': |
|
948 | - return $this->form ? $this->form->ID : null; |
|
949 | - case 'atts': |
|
950 | - return $this->settings->as_atts(); |
|
951 | - case 'template_id': |
|
952 | - return $this->settings->get('template'); |
|
953 | - case 'widgets': |
|
954 | - return $this->widgets->as_configuration(); |
|
955 | - } |
|
956 | - |
|
957 | - return null; |
|
958 | - } |
|
959 | - |
|
960 | - /** |
|
961 | - * ArrayAccess compatibility layer with GravityView_View_Data::$views. |
|
962 | - * |
|
963 | - * @internal |
|
964 | - * |
|
965 | - * @deprecated |
|
966 | - * @since 2.0 |
|
967 | - * |
|
968 | - * @return void |
|
969 | - */ |
|
970 | - public function offsetSet($offset, $value) |
|
971 | - { |
|
972 | - gravityview()->log->error('The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.'); |
|
973 | - } |
|
974 | - |
|
975 | - /** |
|
976 | - * ArrayAccess compatibility layer with GravityView_View_Data::$views. |
|
977 | - * |
|
978 | - * @internal |
|
979 | - * |
|
980 | - * @deprecated |
|
981 | - * @since 2.0 |
|
982 | - * |
|
983 | - * @return void |
|
984 | - */ |
|
985 | - public function offsetUnset($offset) |
|
986 | - { |
|
987 | - gravityview()->log->error('The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.'); |
|
988 | - } |
|
989 | - |
|
990 | - /** |
|
991 | - * Be compatible with the old data object. |
|
992 | - * |
|
993 | - * Some external code expects an array (doing things like foreach on this, or array_keys) |
|
994 | - * so let's return an array in the old format for such cases. Do not use unless using |
|
995 | - * for back-compatibility. |
|
996 | - * |
|
997 | - * @internal |
|
998 | - * |
|
999 | - * @deprecated |
|
1000 | - * @since 2.0 |
|
1001 | - * |
|
1002 | - * @return array |
|
1003 | - */ |
|
1004 | - public function as_data() |
|
1005 | - { |
|
1006 | - return [ |
|
1007 | - 'id' => $this->ID, |
|
1008 | - 'view_id' => $this->ID, |
|
1009 | - 'form_id' => $this->form ? $this->form->ID : null, |
|
1010 | - 'form' => $this->form ? gravityview_get_form($this->form->ID) : null, |
|
1011 | - 'atts' => $this->settings->as_atts(), |
|
1012 | - 'fields' => $this->fields->by_visible($this)->as_configuration(), |
|
1013 | - 'template_id' => $this->settings->get('template'), |
|
1014 | - 'widgets' => $this->widgets->as_configuration(), |
|
1015 | - ]; |
|
1016 | - } |
|
1017 | - |
|
1018 | - /** |
|
1019 | - * Retrieve the entries for the current view and request. |
|
1020 | - * |
|
1021 | - * @param \GV\Request The request. Unused for now. |
|
1022 | - * |
|
1023 | - * @return \GV\Entry_Collection The entries. |
|
1024 | - */ |
|
1025 | - public function get_entries($request = null) |
|
1026 | - { |
|
1027 | - $entries = new \GV\Entry_Collection(); |
|
1028 | - |
|
1029 | - if (!$this->form) { |
|
1030 | - // Documented below. |
|
1031 | - return apply_filters('gravityview/view/entries', $entries, $this, $request); |
|
1032 | - } |
|
1033 | - |
|
1034 | - $parameters = $this->settings->as_atts(); |
|
1035 | - |
|
1036 | - /** |
|
1037 | - * Remove multiple sorting before calling legacy filters. |
|
1038 | - * This allows us to fake it till we make it. |
|
1039 | - */ |
|
1040 | - if (!empty($parameters['sort_field']) && is_array($parameters['sort_field'])) { |
|
1041 | - $has_multisort = true; |
|
1042 | - $parameters['sort_field'] = reset($parameters['sort_field']); |
|
1043 | - if (!empty($parameters['sort_direction']) && is_array($parameters['sort_direction'])) { |
|
1044 | - $parameters['sort_direction'] = reset($parameters['sort_direction']); |
|
1045 | - } |
|
1046 | - } |
|
1047 | - |
|
1048 | - /** |
|
1049 | - * @todo: Stop using _frontend and use something like $request->get_search_criteria() instead |
|
1050 | - */ |
|
1051 | - $parameters = \GravityView_frontend::get_view_entries_parameters($parameters, $this->form->ID); |
|
1052 | - |
|
1053 | - $parameters['context_view_id'] = $this->ID; |
|
1054 | - $parameters = \GVCommon::calculate_get_entries_criteria($parameters, $this->form->ID); |
|
1055 | - |
|
1056 | - if (!is_array($parameters)) { |
|
1057 | - $parameters = []; |
|
1058 | - } |
|
1059 | - |
|
1060 | - if (!is_array($parameters['search_criteria'])) { |
|
1061 | - $parameters['search_criteria'] = []; |
|
1062 | - } |
|
1063 | - |
|
1064 | - if ((!isset($parameters['search_criteria']['field_filters'])) || (!is_array($parameters['search_criteria']['field_filters']))) { |
|
1065 | - $parameters['search_criteria']['field_filters'] = []; |
|
1066 | - } |
|
1067 | - |
|
1068 | - if ($request instanceof REST\Request) { |
|
1069 | - $atts = $this->settings->as_atts(); |
|
1070 | - $paging_parameters = wp_parse_args($request->get_paging(), [ |
|
1071 | - 'paging' => ['page_size' => $atts['page_size']], |
|
1072 | - ]); |
|
1073 | - $parameters['paging'] = $paging_parameters['paging']; |
|
1074 | - } |
|
1075 | - |
|
1076 | - $page = Utils::get($parameters['paging'], 'current_page') ?: ((($parameters['paging']['offset'] - $this->settings->get('offset')) / \GV\Utils::get($parameters, 'paging/page_size', 25)) + 1); |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * Cleanup duplicate field_filter parameters to simplify the query. |
|
1080 | - */ |
|
1081 | - $unique_field_filters = []; |
|
1082 | - foreach (Utils::get($parameters, 'search_criteria/field_filters', []) as $key => $filter) { |
|
1083 | - if ('mode' === $key) { |
|
1084 | - $unique_field_filters['mode'] = $filter; |
|
1085 | - } elseif (!in_array($filter, $unique_field_filters)) { |
|
1086 | - $unique_field_filters[] = $filter; |
|
1087 | - } |
|
1088 | - } |
|
1089 | - $parameters['search_criteria']['field_filters'] = $unique_field_filters; |
|
1090 | - |
|
1091 | - if (!empty($parameters['search_criteria']['field_filters'])) { |
|
1092 | - gravityview()->log->notice('search_criteria/field_filters is not empty, third-party code may be using legacy search_criteria filters.'); |
|
1093 | - } |
|
1094 | - |
|
1095 | - if (gravityview()->plugin->supports(Plugin::FEATURE_GFQUERY)) { |
|
1096 | - $query_class = $this->get_query_class(); |
|
1097 | - |
|
1098 | - /** @var \GF_Query $query */ |
|
1099 | - $query = new $query_class($this->form->ID, $parameters['search_criteria'], Utils::get($parameters, 'sorting')); |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Apply multisort. |
|
1103 | - */ |
|
1104 | - if (!empty($has_multisort)) { |
|
1105 | - $atts = $this->settings->as_atts(); |
|
1106 | - |
|
1107 | - $view_setting_sort_field_ids = \GV\Utils::get($atts, 'sort_field', []); |
|
1108 | - $view_setting_sort_directions = \GV\Utils::get($atts, 'sort_direction', []); |
|
1109 | - |
|
1110 | - $has_sort_query_param = !empty($_GET['sort']) && is_array($_GET['sort']); |
|
1111 | - |
|
1112 | - if ($has_sort_query_param) { |
|
1113 | - $has_sort_query_param = array_filter(array_values($_GET['sort'])); |
|
1114 | - } |
|
1115 | - |
|
1116 | - if ($this->settings->get('sort_columns') && $has_sort_query_param) { |
|
1117 | - $sort_field_ids = array_keys($_GET['sort']); |
|
1118 | - $sort_directions = array_values($_GET['sort']); |
|
1119 | - } else { |
|
1120 | - $sort_field_ids = $view_setting_sort_field_ids; |
|
1121 | - $sort_directions = $view_setting_sort_directions; |
|
1122 | - } |
|
1123 | - |
|
1124 | - $skip_first = false; |
|
1125 | - |
|
1126 | - foreach ((array) $sort_field_ids as $key => $sort_field_id) { |
|
1127 | - if (!$skip_first && !$has_sort_query_param) { |
|
1128 | - $skip_first = true; // Skip the first one, it's already in the query |
|
1129 | - continue; |
|
1130 | - } |
|
1131 | - |
|
1132 | - $sort_field_id = \GravityView_frontend::_override_sorting_id_by_field_type($sort_field_id, $this->form->ID); |
|
1133 | - $sort_direction = strtoupper(\GV\Utils::get($sort_directions, $key, 'ASC')); |
|
1134 | - |
|
1135 | - if (!empty($sort_field_id)) { |
|
1136 | - $order = new \GF_Query_Column($sort_field_id, $this->form->ID); |
|
1137 | - if ('id' !== $sort_field_id && \GVCommon::is_field_numeric($this->form->ID, $sort_field_id)) { |
|
1138 | - $order = \GF_Query_Call::CAST($order, defined('GF_Query::TYPE_DECIMAL') ? \GF_Query::TYPE_DECIMAL : \GF_Query::TYPE_SIGNED); |
|
1139 | - } |
|
1140 | - |
|
1141 | - $query->order($order, $sort_direction); |
|
1142 | - } |
|
1143 | - } |
|
1144 | - } |
|
1145 | - |
|
1146 | - /** |
|
1147 | - * Merge time subfield sorts. |
|
1148 | - */ |
|
1149 | - add_filter('gform_gf_query_sql', $gf_query_timesort_sql_callback = function ($sql) use (&$query) { |
|
1150 | - $q = $query->_introspect(); |
|
1151 | - $orders = []; |
|
1152 | - |
|
1153 | - $merged_time = false; |
|
1154 | - |
|
1155 | - foreach ($q['order'] as $oid => $order) { |
|
1156 | - $column = null; |
|
1157 | - |
|
1158 | - if ($order[0] instanceof \GF_Query_Column) { |
|
1159 | - $column = $order[0]; |
|
1160 | - } elseif ($order[0] instanceof \GF_Query_Call) { |
|
1161 | - if (count($order[0]->columns) != 1 || !$order[0]->columns[0] instanceof \GF_Query_Column) { |
|
1162 | - $orders[$oid] = $order; |
|
1163 | - continue; // Need something that resembles a single sort |
|
1164 | - } |
|
1165 | - $column = $order[0]->columns[0]; |
|
1166 | - } |
|
1167 | - |
|
1168 | - if (!$column || (!$field = \GFAPI::get_field($column->source, $column->field_id)) || $field->type !== 'time') { |
|
1169 | - $orders[$oid] = $order; |
|
1170 | - continue; // Not a time field |
|
1171 | - } |
|
1172 | - |
|
1173 | - if (!class_exists('\GV\Mocks\GF_Query_Call_TIMESORT')) { |
|
1174 | - require_once gravityview()->plugin->dir('future/_mocks.timesort.php'); |
|
1175 | - } |
|
1176 | - |
|
1177 | - $orders[$oid] = [ |
|
1178 | - new \GV\Mocks\GF_Query_Call_TIMESORT('timesort', [$column, $sql]), |
|
1179 | - $order[1], // Mock it! |
|
1180 | - ]; |
|
1181 | - |
|
1182 | - $merged_time = true; |
|
1183 | - } |
|
1184 | - |
|
1185 | - if ($merged_time) { |
|
1186 | - /** |
|
1187 | - * ORDER again. |
|
1188 | - */ |
|
1189 | - if (!empty($orders) && $_orders = $query->_order_generate($orders)) { |
|
1190 | - $sql['order'] = 'ORDER BY '.implode(', ', $_orders); |
|
1191 | - } |
|
1192 | - } |
|
1193 | - |
|
1194 | - return $sql; |
|
1195 | - }); |
|
1196 | - |
|
1197 | - $query->limit($parameters['paging']['page_size']) |
|
1198 | - ->offset((($page - 1) * $parameters['paging']['page_size']) + $this->settings->get('offset')); |
|
1199 | - |
|
1200 | - /** |
|
1201 | - * Any joins? |
|
1202 | - */ |
|
1203 | - if (gravityview()->plugin->supports(Plugin::FEATURE_JOINS) && count($this->joins)) { |
|
1204 | - $is_admin_and_can_view = $this->settings->get('admin_show_all_statuses') && \GVCommon::has_cap('gravityview_moderate_entries', $this->ID); |
|
1205 | - |
|
1206 | - foreach ($this->joins as $join) { |
|
1207 | - $query = $join->as_query_join($query); |
|
1208 | - |
|
1209 | - if ($this->settings->get('multiple_forms_disable_null_joins')) { |
|
1210 | - |
|
1211 | - // Disable NULL outputs |
|
1212 | - $condition = new \GF_Query_Condition( |
|
1213 | - new \GF_Query_Column($join->join_on_column->ID, $join->join_on->ID), |
|
1214 | - \GF_Query_Condition::NEQ, |
|
1215 | - new \GF_Query_Literal('') |
|
1216 | - ); |
|
1217 | - |
|
1218 | - $query_parameters = $query->_introspect(); |
|
1219 | - |
|
1220 | - $query->where(\GF_Query_Condition::_and($query_parameters['where'], $condition)); |
|
1221 | - } |
|
1222 | - |
|
1223 | - /** |
|
1224 | - * This is a temporary stub filter, until GF_Query supports NULL conditions. |
|
1225 | - * Do not use! This filter will be removed. |
|
1226 | - */ |
|
1227 | - if (defined('GF_Query_Condition::NULL')) { |
|
1228 | - $is_null_condition_native = true; |
|
1229 | - } else { |
|
1230 | - $is_null_condition_class = apply_filters('gravityview/query/is_null_condition', null); |
|
1231 | - $is_null_condition_native = false; |
|
1232 | - } |
|
1233 | - |
|
1234 | - // Filter to active entries only |
|
1235 | - $condition = new \GF_Query_Condition( |
|
1236 | - new \GF_Query_Column('status', $join->join_on->ID), |
|
1237 | - \GF_Query_Condition::EQ, |
|
1238 | - new \GF_Query_Literal('active') |
|
1239 | - ); |
|
1240 | - |
|
1241 | - if ($is_null_condition_native) { |
|
1242 | - $condition = \GF_Query_Condition::_or($condition, new \GF_Query_Condition( |
|
1243 | - new \GF_Query_Column('status', $join->join_on->ID), |
|
1244 | - \GF_Query_Condition::IS, |
|
1245 | - \GF_Query_Condition::NULL |
|
1246 | - )); |
|
1247 | - } elseif (!is_null($is_null_condition_class)) { |
|
1248 | - $condition = \GF_Query_Condition::_or($condition, new $is_null_condition_class( |
|
1249 | - new \GF_Query_Column('status', $join->join_on->ID) |
|
1250 | - )); |
|
1251 | - } |
|
1252 | - |
|
1253 | - $q = $query->_introspect(); |
|
1254 | - $query->where(\GF_Query_Condition::_and($q['where'], $condition)); |
|
1255 | - |
|
1256 | - if ($this->settings->get('show_only_approved') && !$is_admin_and_can_view) { |
|
1257 | - |
|
1258 | - // Show only approved joined entries |
|
1259 | - $condition = new \GF_Query_Condition( |
|
1260 | - new \GF_Query_Column(\GravityView_Entry_Approval::meta_key, $join->join_on->ID), |
|
1261 | - \GF_Query_Condition::EQ, |
|
1262 | - new \GF_Query_Literal(\GravityView_Entry_Approval_Status::APPROVED) |
|
1263 | - ); |
|
1264 | - |
|
1265 | - if ($is_null_condition_native) { |
|
1266 | - $condition = \GF_Query_Condition::_or($condition, new \GF_Query_Condition( |
|
1267 | - new \GF_Query_Column(\GravityView_Entry_Approval::meta_key, $join->join_on->ID), |
|
1268 | - \GF_Query_Condition::IS, |
|
1269 | - \GF_Query_Condition::NULL |
|
1270 | - )); |
|
1271 | - } elseif (!is_null($is_null_condition_class)) { |
|
1272 | - $condition = \GF_Query_Condition::_or($condition, new $is_null_condition_class( |
|
1273 | - new \GF_Query_Column(\GravityView_Entry_Approval::meta_key, $join->join_on->ID) |
|
1274 | - )); |
|
1275 | - } |
|
1276 | - |
|
1277 | - $query_parameters = $query->_introspect(); |
|
1278 | - |
|
1279 | - $query->where(\GF_Query_Condition::_and($query_parameters['where'], $condition)); |
|
1280 | - } |
|
1281 | - } |
|
1282 | - |
|
1283 | - /** |
|
1284 | - * Unions? |
|
1285 | - */ |
|
1286 | - } elseif (gravityview()->plugin->supports(Plugin::FEATURE_UNIONS) && count($this->unions)) { |
|
1287 | - $query_parameters = $query->_introspect(); |
|
1288 | - |
|
1289 | - $unions_sql = []; |
|
1290 | - |
|
1291 | - /** |
|
1292 | - * @param \GF_Query_Condition $condition |
|
1293 | - * @param array $fields |
|
1294 | - * @param $recurse |
|
1295 | - * |
|
1296 | - * @return \GF_Query_Condition |
|
1297 | - */ |
|
1298 | - $where_union_substitute = function ($condition, $fields, $recurse) { |
|
1299 | - if ($condition->expressions) { |
|
1300 | - $conditions = []; |
|
1301 | - |
|
1302 | - foreach ($condition->expressions as $_condition) { |
|
1303 | - $conditions[] = $recurse($_condition, $fields, $recurse); |
|
1304 | - } |
|
1305 | - |
|
1306 | - return call_user_func_array( |
|
1307 | - ['\GF_Query_Condition', $condition->operator == 'AND' ? '_and' : '_or'], |
|
1308 | - $conditions |
|
1309 | - ); |
|
1310 | - } |
|
1311 | - |
|
1312 | - if (!($condition->left && $condition->left instanceof \GF_Query_Column) || (!$condition->left->is_entry_column() && !$condition->left->is_meta_column())) { |
|
1313 | - return new \GF_Query_Condition( |
|
1314 | - new \GF_Query_Column($fields[$condition->left->field_id]->ID), |
|
1315 | - $condition->operator, |
|
1316 | - $condition->right |
|
1317 | - ); |
|
1318 | - } |
|
1319 | - |
|
1320 | - return $condition; |
|
1321 | - }; |
|
1322 | - |
|
1323 | - foreach ($this->unions as $form_id => $fields) { |
|
1324 | - |
|
1325 | - // Build a new query for every unioned form |
|
1326 | - $query_class = $this->get_query_class(); |
|
1327 | - |
|
1328 | - /** @var \GF_Query|\GF_Patched_Query $q */ |
|
1329 | - $q = new $query_class($form_id); |
|
1330 | - |
|
1331 | - // Copy the WHERE clauses but substitute the field_ids to the respective ones |
|
1332 | - $q->where($where_union_substitute($query_parameters['where'], $fields, $where_union_substitute)); |
|
1333 | - |
|
1334 | - // Copy the ORDER clause and substitute the field_ids to the respective ones |
|
1335 | - foreach ($query_parameters['order'] as $order) { |
|
1336 | - list($column, $_order) = $order; |
|
1337 | - |
|
1338 | - if ($column && $column instanceof \GF_Query_Column) { |
|
1339 | - if (!$column->is_entry_column() && !$column->is_meta_column()) { |
|
1340 | - $column = new \GF_Query_Column($fields[$column->field_id]->ID); |
|
1341 | - } |
|
1342 | - |
|
1343 | - $q->order($column, $_order); |
|
1344 | - } |
|
1345 | - } |
|
1346 | - |
|
1347 | - add_filter('gform_gf_query_sql', $gf_query_sql_callback = function ($sql) use (&$unions_sql) { |
|
1348 | - // Remove SQL_CALC_FOUND_ROWS as it's not needed in UNION clauses |
|
1349 | - $select = 'UNION ALL '.str_replace('SQL_CALC_FOUND_ROWS ', '', $sql['select']); |
|
1350 | - |
|
1351 | - // Record the SQL |
|
1352 | - $unions_sql[] = [ |
|
1353 | - // Remove columns, we'll rebuild them |
|
1354 | - 'select' => preg_replace('#DISTINCT (.*)#', 'DISTINCT ', $select), |
|
1355 | - 'from' => $sql['from'], |
|
1356 | - 'join' => $sql['join'], |
|
1357 | - 'where' => $sql['where'], |
|
1358 | - // Remove order and limit |
|
1359 | - ]; |
|
1360 | - |
|
1361 | - // Return empty query, no need to call the database |
|
1362 | - return []; |
|
1363 | - }); |
|
1364 | - |
|
1365 | - do_action_ref_array('gravityview/view/query', [&$q, $this, $request]); |
|
1366 | - |
|
1367 | - $q->get(); // Launch |
|
1368 | - |
|
1369 | - remove_filter('gform_gf_query_sql', $gf_query_sql_callback); |
|
1370 | - } |
|
1371 | - |
|
1372 | - add_filter('gform_gf_query_sql', $gf_query_sql_callback = function ($sql) use ($unions_sql) { |
|
1373 | - // Remove SQL_CALC_FOUND_ROWS as it's not needed in UNION clauses |
|
1374 | - $sql['select'] = str_replace('SQL_CALC_FOUND_ROWS ', '', $sql['select']); |
|
1375 | - |
|
1376 | - // Remove columns, we'll rebuild them |
|
1377 | - preg_match('#DISTINCT (`[motc]\d+`.`.*?`)#', $sql['select'], $select_match); |
|
1378 | - $sql['select'] = preg_replace('#DISTINCT (.*)#', 'DISTINCT ', $sql['select']); |
|
1379 | - |
|
1380 | - $unions = []; |
|
1381 | - |
|
1382 | - // Transform selected columns to shared alias names |
|
1383 | - $column_to_alias = function ($column) { |
|
1384 | - $column = str_replace('`', '', $column); |
|
1385 | - |
|
1386 | - return '`'.str_replace('.', '_', $column).'`'; |
|
1387 | - }; |
|
1388 | - |
|
1389 | - // Add all the order columns into the selects, so we can order by the whole union group |
|
1390 | - preg_match_all('#(`[motc]\d+`.`.*?`)#', $sql['order'], $order_matches); |
|
1391 | - |
|
1392 | - $columns = [ |
|
1393 | - sprintf('%s AS %s', $select_match[1], $column_to_alias($select_match[1])), |
|
1394 | - ]; |
|
1395 | - |
|
1396 | - foreach (array_slice($order_matches, 1) as $match) { |
|
1397 | - $columns[] = sprintf('%s AS %s', $match[0], $column_to_alias($match[0])); |
|
1398 | - |
|
1399 | - // Rewrite the order columns to the shared aliases |
|
1400 | - $sql['order'] = str_replace($match[0], $column_to_alias($match[0]), $sql['order']); |
|
1401 | - } |
|
1402 | - |
|
1403 | - $columns = array_unique($columns); |
|
1404 | - |
|
1405 | - // Add the columns to every UNION |
|
1406 | - foreach ($unions_sql as $union_sql) { |
|
1407 | - $union_sql['select'] .= implode(', ', $columns); |
|
1408 | - $unions[] = implode(' ', $union_sql); |
|
1409 | - } |
|
1410 | - |
|
1411 | - // Add the columns to the main SELECT, but only grab the entry id column |
|
1412 | - $sql['select'] = 'SELECT SQL_CALC_FOUND_ROWS t1_id FROM ('.$sql['select'].implode(', ', $columns); |
|
1413 | - $sql['order'] = implode(' ', $unions).') AS u '.$sql['order']; |
|
1414 | - |
|
1415 | - return $sql; |
|
1416 | - }); |
|
1417 | - } |
|
1418 | - |
|
1419 | - /** |
|
1420 | - * @action `gravityview/view/query` Override the \GF_Query before the get() call. |
|
1421 | - * |
|
1422 | - * @param \GF_Query $query The current query object reference |
|
1423 | - * @param \GV\View $this The current view object |
|
1424 | - * @param \GV\Request $request The request object |
|
1425 | - */ |
|
1426 | - do_action_ref_array('gravityview/view/query', [&$query, $this, $request]); |
|
1427 | - |
|
1428 | - gravityview()->log->debug('GF_Query parameters: ', ['data' => Utils::gf_query_debug($query)]); |
|
1429 | - |
|
1430 | - /** |
|
1431 | - * Map from Gravity Forms entries arrays to an Entry_Collection. |
|
1432 | - */ |
|
1433 | - if (count($this->joins)) { |
|
1434 | - foreach ($query->get() as $entry) { |
|
1435 | - $entries->add( |
|
1436 | - Multi_Entry::from_entries(array_map('\GV\GF_Entry::from_entry', $entry)) |
|
1437 | - ); |
|
1438 | - } |
|
1439 | - } else { |
|
1440 | - array_map([$entries, 'add'], array_map('\GV\GF_Entry::from_entry', $query->get())); |
|
1441 | - } |
|
1442 | - |
|
1443 | - if (isset($gf_query_sql_callback)) { |
|
1444 | - remove_action('gform_gf_query_sql', $gf_query_sql_callback); |
|
1445 | - } |
|
1446 | - |
|
1447 | - if (isset($gf_query_timesort_sql_callback)) { |
|
1448 | - remove_action('gform_gf_query_sql', $gf_query_timesort_sql_callback); |
|
1449 | - } |
|
1450 | - |
|
1451 | - /** |
|
1452 | - * Add total count callback. |
|
1453 | - */ |
|
1454 | - $entries->add_count_callback(function () use ($query) { |
|
1455 | - return $query->total_found; |
|
1456 | - }); |
|
1457 | - } else { |
|
1458 | - $entries = $this->form->entries |
|
1459 | - ->filter(\GV\GF_Entry_Filter::from_search_criteria($parameters['search_criteria'])) |
|
1460 | - ->offset($this->settings->get('offset')) |
|
1461 | - ->limit($parameters['paging']['page_size']) |
|
1462 | - ->page($page); |
|
1463 | - |
|
1464 | - if (!empty($parameters['sorting']) && is_array($parameters['sorting'] && !isset($parameters['sorting']['key']))) { |
|
1465 | - // Pluck off multisort arrays |
|
1466 | - $parameters['sorting'] = $parameters['sorting'][0]; |
|
1467 | - } |
|
1468 | - |
|
1469 | - if (!empty($parameters['sorting']) && !empty($parameters['sorting']['key'])) { |
|
1470 | - $field = new \GV\Field(); |
|
1471 | - $field->ID = $parameters['sorting']['key']; |
|
1472 | - $direction = strtolower($parameters['sorting']['direction']) == 'asc' ? \GV\Entry_Sort::ASC : \GV\Entry_Sort::DESC; |
|
1473 | - $entries = $entries->sort(new \GV\Entry_Sort($field, $direction)); |
|
1474 | - } |
|
1475 | - } |
|
1476 | - |
|
1477 | - /** |
|
1478 | - * @filter `gravityview/view/entries` Modify the entry fetching filters, sorts, offsets, limits. |
|
1479 | - * |
|
1480 | - * @param \GV\Entry_Collection $entries The entries for this view. |
|
1481 | - * @param \GV\View $view The view. |
|
1482 | - * @param \GV\Request $request The request. |
|
1483 | - */ |
|
1484 | - return apply_filters('gravityview/view/entries', $entries, $this, $request); |
|
1485 | - } |
|
1486 | - |
|
1487 | - /** |
|
1488 | - * Last chance to configure the output. |
|
1489 | - * |
|
1490 | - * Used for CSV output, for example. |
|
1491 | - * |
|
1492 | - * @return void |
|
1493 | - */ |
|
1494 | - public static function template_redirect() |
|
1495 | - { |
|
1496 | - $is_csv = get_query_var('csv'); |
|
1497 | - $is_tsv = get_query_var('tsv'); |
|
1498 | - |
|
1499 | - /** |
|
1500 | - * CSV output. |
|
1501 | - */ |
|
1502 | - if (!$is_csv && !$is_tsv) { |
|
1503 | - return; |
|
1504 | - } |
|
1505 | - |
|
1506 | - $view = gravityview()->request->is_view(); |
|
1507 | - |
|
1508 | - if (!$view) { |
|
1509 | - return; |
|
1510 | - } |
|
1511 | - |
|
1512 | - $error_csv = $view->can_render(['csv']); |
|
1513 | - |
|
1514 | - if (is_wp_error($error_csv)) { |
|
1515 | - gravityview()->log->error('Not rendering CSV or TSV: '.$error_csv->get_error_message()); |
|
1516 | - |
|
1517 | - return; |
|
1518 | - } |
|
1519 | - |
|
1520 | - $file_type = $is_csv ? 'csv' : 'tsv'; |
|
1521 | - |
|
1522 | - /** |
|
1523 | - * @filter `gravityview/output/{csv|tsv}/filename` Modify the name of the generated CSV or TSV file. Name will be sanitized using sanitize_file_name() before output. |
|
1524 | - * |
|
1525 | - * @see sanitize_file_name() |
|
1526 | - * @since 2.1 |
|
1527 | - * |
|
1528 | - * @param string $filename File name used when downloading a CSV or TSV. Default is "{View title}.csv" or "{View title}.tsv" |
|
1529 | - * @param \GV\View $view Current View being rendered |
|
1530 | - */ |
|
1531 | - $filename = apply_filters('gravityview/output/'.$file_type.'/filename', get_the_title($view->post), $view); |
|
1532 | - |
|
1533 | - if (!defined('DOING_GRAVITYVIEW_TESTS')) { |
|
1534 | - header(sprintf('Content-Disposition: attachment;filename="%s.'.$file_type.'"', sanitize_file_name($filename))); |
|
1535 | - header('Content-Transfer-Encoding: binary'); |
|
1536 | - header('Content-Type: text/'.$file_type); |
|
1537 | - } |
|
1538 | - |
|
1539 | - ob_start(); |
|
1540 | - $csv_or_tsv = fopen('php://output', 'w'); |
|
1541 | - |
|
1542 | - /** |
|
1543 | - * Add da' BOM if GF uses it. |
|
1544 | - * |
|
1545 | - * @see GFExport::start_export() |
|
1546 | - */ |
|
1547 | - if (apply_filters('gform_include_bom_export_entries', true, $view->form ? $view->form->form : null)) { |
|
1548 | - fputs($csv_or_tsv, "\xef\xbb\xbf"); |
|
1549 | - } |
|
1550 | - |
|
1551 | - if ($view->settings->get('csv_nolimit')) { |
|
1552 | - $view->settings->update(['page_size' => -1]); |
|
1553 | - } |
|
1554 | - |
|
1555 | - $entries = $view->get_entries(); |
|
1556 | - |
|
1557 | - $headers_done = false; |
|
1558 | - $allowed = $headers = []; |
|
1559 | - |
|
1560 | - foreach ($view->fields->by_position('directory_*')->by_visible($view)->all() as $id => $field) { |
|
1561 | - $allowed[] = $field; |
|
1562 | - } |
|
1563 | - |
|
1564 | - $renderer = new Field_Renderer(); |
|
1565 | - |
|
1566 | - foreach ($entries->all() as $entry) { |
|
1567 | - $return = []; |
|
1568 | - |
|
1569 | - /** |
|
1570 | - * @filter `gravityview/csv/entry/fields` Allowlist more entry fields by ID that are output in CSV requests. |
|
1571 | - * |
|
1572 | - * @param array $allowed The allowed ones, default by_visible, by_position( "context_*" ), i.e. as set in the View. |
|
1573 | - * @param \GV\View $view The view. |
|
1574 | - * @param \GV\Entry $entry WordPress representation of the item. |
|
1575 | - */ |
|
1576 | - $allowed_field_ids = apply_filters('gravityview/csv/entry/fields', wp_list_pluck($allowed, 'ID'), $view, $entry); |
|
1577 | - |
|
1578 | - $allowed = array_filter($allowed, function ($field) use ($allowed_field_ids) { |
|
1579 | - return in_array($field->ID, $allowed_field_ids, true); |
|
1580 | - }); |
|
1581 | - |
|
1582 | - foreach (array_diff($allowed_field_ids, wp_list_pluck($allowed, 'ID')) as $field_id) { |
|
1583 | - $allowed[] = is_numeric($field_id) ? \GV\GF_Field::by_id($view->form, $field_id) : \GV\Internal_Field::by_id($field_id); |
|
1584 | - } |
|
1585 | - |
|
1586 | - foreach ($allowed as $field) { |
|
1587 | - $source = is_numeric($field->ID) ? $view->form : new \GV\Internal_Source(); |
|
1588 | - |
|
1589 | - $return[] = $renderer->render($field, $view, $source, $entry, gravityview()->request, '\GV\Field_CSV_Template'); |
|
1590 | - |
|
1591 | - if (!$headers_done) { |
|
1592 | - $label = $field->get_label($view, $source, $entry); |
|
1593 | - $headers[] = $label ? $label : $field->ID; |
|
1594 | - } |
|
1595 | - } |
|
1596 | - |
|
1597 | - // If not "tsv" then use comma |
|
1598 | - $delimiter = ('tsv' === $file_type) ? "\t" : ','; |
|
1599 | - |
|
1600 | - if (!$headers_done) { |
|
1601 | - $headers_done = fputcsv($csv_or_tsv, array_map(['\GV\Utils', 'strip_excel_formulas'], array_values($headers)), $delimiter); |
|
1602 | - } |
|
1603 | - |
|
1604 | - fputcsv($csv_or_tsv, array_map(['\GV\Utils', 'strip_excel_formulas'], $return), $delimiter); |
|
1605 | - } |
|
1606 | - |
|
1607 | - fflush($csv_or_tsv); |
|
1608 | - |
|
1609 | - echo rtrim(ob_get_clean()); |
|
1610 | - |
|
1611 | - if (!defined('DOING_GRAVITYVIEW_TESTS')) { |
|
1612 | - exit; |
|
1613 | - } |
|
1614 | - } |
|
1615 | - |
|
1616 | - /** |
|
1617 | - * Return the query class for this View. |
|
1618 | - * |
|
1619 | - * @return string The class name. |
|
1620 | - */ |
|
1621 | - public function get_query_class() |
|
1622 | - { |
|
1623 | - /** |
|
1624 | - * @filter `gravityview/query/class` |
|
1625 | - * |
|
1626 | - * @param string The query class. Default: GF_Query. |
|
1627 | - * @param \GV\View $this The View. |
|
1628 | - */ |
|
1629 | - $query_class = apply_filters('gravityview/query/class', '\GF_Query', $this); |
|
1630 | - |
|
1631 | - return $query_class; |
|
1632 | - } |
|
1633 | - |
|
1634 | - /** |
|
1635 | - * Restrict View access to specific capabilities. |
|
1636 | - * |
|
1637 | - * Hooked into `map_meta_cap` WordPress filter. |
|
1638 | - * |
|
1639 | - * @since develop |
|
1640 | - * |
|
1641 | - * @param $caps array The output capabilities. |
|
1642 | - * @param $cap string The cap that is being checked. |
|
1643 | - * @param $user_id int The User ID. |
|
1644 | - * @param $args array Additional arguments to the capability. |
|
1645 | - * |
|
1646 | - * @return array The resulting capabilities. |
|
1647 | - */ |
|
1648 | - public static function restrict($caps, $cap, $user_id, $args) |
|
1649 | - { |
|
1650 | - /** |
|
1651 | - * @filter `gravityview/security/require_unfiltered_html` Bypass restrictions on Views that require `unfiltered_html`. |
|
1652 | - * |
|
1653 | - * @param bool |
|
1654 | - * |
|
1655 | - * @since develop |
|
1656 | - * |
|
1657 | - * @param string $cap The capability requested. |
|
1658 | - * @param int $user_id The user ID. |
|
1659 | - * @param array $args Any additional args to map_meta_cap |
|
1660 | - */ |
|
1661 | - if (!apply_filters('gravityview/security/require_unfiltered_html', true, $cap, $user_id)) { |
|
1662 | - return $caps; |
|
1663 | - } |
|
1664 | - |
|
1665 | - switch ($cap) { |
|
1666 | - case 'edit_gravityview': |
|
1667 | - case 'edit_gravityviews': |
|
1668 | - case 'edit_others_gravityviews': |
|
1669 | - case 'edit_private_gravityviews': |
|
1670 | - case 'edit_published_gravityviews': |
|
1671 | - if (!user_can($user_id, 'unfiltered_html')) { |
|
1672 | - if (!user_can($user_id, 'gravityview_full_access')) { |
|
1673 | - return ['do_not_allow']; |
|
1674 | - } |
|
1675 | - } |
|
1676 | - |
|
1677 | - return $caps; |
|
1678 | - case 'edit_post': |
|
1679 | - if ('gravityview' === get_post_type(array_pop($args))) { |
|
1680 | - return self::restrict($caps, 'edit_gravityview', $user_id, $args); |
|
1681 | - } |
|
1682 | - } |
|
1683 | - |
|
1684 | - return $caps; |
|
1685 | - } |
|
1686 | - |
|
1687 | - public function __get($key) |
|
1688 | - { |
|
1689 | - if ($this->post) { |
|
1690 | - $raw_post = $this->post->filter('raw'); |
|
1691 | - |
|
1692 | - return $raw_post->{$key}; |
|
1693 | - } |
|
1694 | - |
|
1695 | - return isset($this->{$key}) ? $this->{$key} : null; |
|
1696 | - } |
|
1697 | - |
|
1698 | - /** |
|
1699 | - * Return associated WP post. |
|
1700 | - * |
|
1701 | - * @since 2.13.2 |
|
1702 | - * |
|
1703 | - * @return \WP_Post|null |
|
1704 | - */ |
|
1705 | - public function get_post() |
|
1706 | - { |
|
1707 | - return $this->post ? $this->post : null; |
|
1708 | - } |
|
20 | + /** |
|
21 | + * @var \WP_Post The backing post instance. |
|
22 | + */ |
|
23 | + private $post; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var \GV\View_Settings The settings. |
|
27 | + * |
|
28 | + * @api |
|
29 | + * |
|
30 | + * @since 2.0 |
|
31 | + */ |
|
32 | + public $settings; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var \GV\Widget_Collection The widets attached here. |
|
36 | + * |
|
37 | + * @api |
|
38 | + * |
|
39 | + * @since 2.0 |
|
40 | + */ |
|
41 | + public $widgets; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var \GV\GF_Form|\GV\Form The backing form for this view. |
|
45 | + * |
|
46 | + * Contains the form that is sourced for entries in this view. |
|
47 | + * |
|
48 | + * @api |
|
49 | + * |
|
50 | + * @since 2.0 |
|
51 | + */ |
|
52 | + public $form; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var \GV\Field_Collection The fields for this view. |
|
56 | + * |
|
57 | + * Contains all the fields that are attached to this view. |
|
58 | + * |
|
59 | + * @api |
|
60 | + * |
|
61 | + * @since 2.0 |
|
62 | + */ |
|
63 | + public $fields; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var array |
|
67 | + * |
|
68 | + * Internal static cache for gets, and whatnot. |
|
69 | + * This is not persistent, resets across requests. |
|
70 | + * |
|
71 | + * @internal |
|
72 | + */ |
|
73 | + private static $cache = []; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var \GV\Join[] The joins for all sources in this view. |
|
77 | + * |
|
78 | + * @api |
|
79 | + * |
|
80 | + * @since 2.0.1 |
|
81 | + */ |
|
82 | + public $joins = []; |
|
83 | + |
|
84 | + /** |
|
85 | + * @var \GV\Field[][] The unions for all sources in this view. |
|
86 | + * An array of fields grouped by form_id keyed by |
|
87 | + * main field_id: |
|
88 | + * |
|
89 | + * array( |
|
90 | + * $form_id => array( |
|
91 | + * $field_id => $field, |
|
92 | + * $field_id => $field, |
|
93 | + * ) |
|
94 | + * ) |
|
95 | + * |
|
96 | + * @api |
|
97 | + * |
|
98 | + * @since 2.2.2 |
|
99 | + */ |
|
100 | + public $unions = []; |
|
101 | + |
|
102 | + /** |
|
103 | + * The constructor. |
|
104 | + */ |
|
105 | + public function __construct() |
|
106 | + { |
|
107 | + $this->settings = new View_Settings(); |
|
108 | + $this->fields = new Field_Collection(); |
|
109 | + $this->widgets = new Widget_Collection(); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Register the gravityview WordPress Custom Post Type. |
|
114 | + * |
|
115 | + * @internal |
|
116 | + * |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + public static function register_post_type() |
|
120 | + { |
|
121 | + |
|
122 | + /** Register only once */ |
|
123 | + if (post_type_exists('gravityview')) { |
|
124 | + return; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @filter `gravityview_is_hierarchical` Make GravityView Views hierarchical by returning TRUE |
|
129 | + * This will allow for Views to be nested with Parents and also allows for menu order to be set in the Page Attributes metabox |
|
130 | + * |
|
131 | + * @since 1.13 |
|
132 | + * |
|
133 | + * @param bool $is_hierarchical Default: false |
|
134 | + */ |
|
135 | + $is_hierarchical = (bool) apply_filters('gravityview_is_hierarchical', false); |
|
136 | + |
|
137 | + $supports = ['title', 'revisions']; |
|
138 | + |
|
139 | + if ($is_hierarchical) { |
|
140 | + $supports[] = 'page-attributes'; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @filter `gravityview_post_type_supports` Modify post type support values for `gravityview` post type |
|
145 | + * |
|
146 | + * @see add_post_type_support() |
|
147 | + * @since 1.15.2 |
|
148 | + * |
|
149 | + * @param array $supports Array of features associated with a functional area of the edit screen. Default: 'title', 'revisions'. If $is_hierarchical, also 'page-attributes' |
|
150 | + * @param bool $is_hierarchical Do Views support parent/child relationships? See `gravityview_is_hierarchical` filter. |
|
151 | + */ |
|
152 | + $supports = apply_filters('gravityview_post_type_support', $supports, $is_hierarchical); |
|
153 | + |
|
154 | + /** Register Custom Post Type - gravityview */ |
|
155 | + $labels = [ |
|
156 | + 'name' => _x('Views', 'Post Type General Name', 'gravityview'), |
|
157 | + 'singular_name' => _x('View', 'Post Type Singular Name', 'gravityview'), |
|
158 | + 'menu_name' => _x('Views', 'Menu name', 'gravityview'), |
|
159 | + 'parent_item_colon' => __('Parent View:', 'gravityview'), |
|
160 | + 'all_items' => __('All Views', 'gravityview'), |
|
161 | + 'view_item' => _x('View', 'View Item', 'gravityview'), |
|
162 | + 'add_new_item' => __('Add New View', 'gravityview'), |
|
163 | + 'add_new' => __('New View', 'gravityview'), |
|
164 | + 'edit_item' => __('Edit View', 'gravityview'), |
|
165 | + 'update_item' => __('Update View', 'gravityview'), |
|
166 | + 'search_items' => __('Search Views', 'gravityview'), |
|
167 | + 'not_found' => \GravityView_Admin::no_views_text(), |
|
168 | + 'not_found_in_trash' => __('No Views found in Trash', 'gravityview'), |
|
169 | + 'filter_items_list' => __('Filter Views list', 'gravityview'), |
|
170 | + 'items_list_navigation' => __('Views list navigation', 'gravityview'), |
|
171 | + 'items_list' => __('Views list', 'gravityview'), |
|
172 | + 'view_items' => __('See Views', 'gravityview'), |
|
173 | + 'attributes' => __('View Attributes', 'gravityview'), |
|
174 | + 'item_updated' => __('View updated.', 'gravityview'), |
|
175 | + 'item_published' => __('View published.', 'gravityview'), |
|
176 | + 'item_reverted_to_draft' => __('View reverted to draft.', 'gravityview'), |
|
177 | + 'item_scheduled' => __('View scheduled.', 'gravityview'), |
|
178 | + ]; |
|
179 | + |
|
180 | + $args = [ |
|
181 | + 'label' => __('view', 'gravityview'), |
|
182 | + 'description' => __('Create views based on a Gravity Forms form', 'gravityview'), |
|
183 | + 'labels' => $labels, |
|
184 | + 'supports' => $supports, |
|
185 | + 'hierarchical' => $is_hierarchical, |
|
186 | + /** |
|
187 | + * @filter `gravityview_direct_access` Should Views be directly accessible, or only visible using the shortcode? |
|
188 | + * |
|
189 | + * @see https://codex.wordpress.org/Function_Reference/register_post_type#public |
|
190 | + * @since 1.15.2 |
|
191 | + * |
|
192 | + * @param bool `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded via shortcode. Default: `true` |
|
193 | + * @param int $view_id The ID of the View currently being requested. `0` for general setting |
|
194 | + */ |
|
195 | + 'public' => apply_filters('gravityview_direct_access', gravityview()->plugin->is_compatible(), 0), |
|
196 | + 'show_ui' => gravityview()->plugin->is_compatible(), |
|
197 | + 'show_in_menu' => gravityview()->plugin->is_compatible(), |
|
198 | + 'show_in_nav_menus' => true, |
|
199 | + 'show_in_admin_bar' => true, |
|
200 | + 'menu_position' => 17, |
|
201 | + 'menu_icon' => '', |
|
202 | + 'can_export' => true, |
|
203 | + /** |
|
204 | + * @filter `gravityview_has_archive` Enable Custom Post Type archive? |
|
205 | + * |
|
206 | + * @since 1.7.3 |
|
207 | + * |
|
208 | + * @param bool False: don't have frontend archive; True: yes, have archive. Default: false |
|
209 | + */ |
|
210 | + 'has_archive' => apply_filters('gravityview_has_archive', false), |
|
211 | + 'exclude_from_search' => true, |
|
212 | + 'rewrite' => [ |
|
213 | + /** |
|
214 | + * @filter `gravityview_slug` Modify the url part for a View. |
|
215 | + * |
|
216 | + * @see https://docs.gravityview.co/article/62-changing-the-view-slug |
|
217 | + * |
|
218 | + * @param string $slug The slug shown in the URL |
|
219 | + */ |
|
220 | + 'slug' => apply_filters('gravityview_slug', 'view'), |
|
221 | + |
|
222 | + /** |
|
223 | + * @filter `gravityview/post_type/with_front` Should the permalink structure |
|
224 | + * be prepended with the front base. |
|
225 | + * (example: if your permalink structure is /blog/, then your links will be: false->/view/, true->/blog/view/). |
|
226 | + * Defaults to true. |
|
227 | + * |
|
228 | + * @see https://codex.wordpress.org/Function_Reference/register_post_type |
|
229 | + * @since 2.0 |
|
230 | + * |
|
231 | + * @param bool $with_front |
|
232 | + */ |
|
233 | + 'with_front' => apply_filters('gravityview/post_type/with_front', true), |
|
234 | + ], |
|
235 | + 'capability_type' => 'gravityview', |
|
236 | + 'map_meta_cap' => true, |
|
237 | + ]; |
|
238 | + |
|
239 | + register_post_type('gravityview', $args); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Add extra rewrite endpoints. |
|
244 | + * |
|
245 | + * @return void |
|
246 | + */ |
|
247 | + public static function add_rewrite_endpoint() |
|
248 | + { |
|
249 | + /** |
|
250 | + * CSV. |
|
251 | + */ |
|
252 | + global $wp_rewrite; |
|
253 | + |
|
254 | + $slug = apply_filters('gravityview_slug', 'view'); |
|
255 | + $slug = ('/' !== $wp_rewrite->front) ? sprintf('%s/%s', trim($wp_rewrite->front, '/'), $slug) : $slug; |
|
256 | + $csv_rule = [sprintf('%s/([^/]+)/csv/?', $slug), 'index.php?gravityview=$matches[1]&csv=1', 'top']; |
|
257 | + $tsv_rule = [sprintf('%s/([^/]+)/tsv/?', $slug), 'index.php?gravityview=$matches[1]&tsv=1', 'top']; |
|
258 | + |
|
259 | + add_filter('query_vars', function ($query_vars) { |
|
260 | + $query_vars[] = 'csv'; |
|
261 | + $query_vars[] = 'tsv'; |
|
262 | + |
|
263 | + return $query_vars; |
|
264 | + }); |
|
265 | + |
|
266 | + if (!isset($wp_rewrite->extra_rules_top[$csv_rule[0]])) { |
|
267 | + call_user_func_array('add_rewrite_rule', $csv_rule); |
|
268 | + call_user_func_array('add_rewrite_rule', $tsv_rule); |
|
269 | + } |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * A renderer filter for the View post type content. |
|
274 | + * |
|
275 | + * @param string $content Should be empty, as we don't store anything there. |
|
276 | + * |
|
277 | + * @return string $content The view content as output by the renderers. |
|
278 | + */ |
|
279 | + public static function content($content) |
|
280 | + { |
|
281 | + $request = gravityview()->request; |
|
282 | + |
|
283 | + // Plugins may run through the content in the header. WP SEO does this for its OpenGraph functionality. |
|
284 | + if (!defined('DOING_GRAVITYVIEW_TESTS')) { |
|
285 | + if (!did_action('loop_start')) { |
|
286 | + gravityview()->log->debug('Not processing yet: loop_start hasn\'t run yet. Current action: {action}', ['action' => current_filter()]); |
|
287 | + |
|
288 | + return $content; |
|
289 | + } |
|
290 | + |
|
291 | + // We don't want this filter to run infinite loop on any post content fields |
|
292 | + remove_filter('the_content', [__CLASS__, __METHOD__]); |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * This is not a View. Bail. |
|
297 | + * |
|
298 | + * Shortcodes and oEmbeds and whatnot will be handled |
|
299 | + * elsewhere. |
|
300 | + */ |
|
301 | + if (!$view = $request->is_view()) { |
|
302 | + return $content; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Check permissions. |
|
307 | + */ |
|
308 | + while ($error = $view->can_render(null, $request)) { |
|
309 | + if (!is_wp_error($error)) { |
|
310 | + break; |
|
311 | + } |
|
312 | + |
|
313 | + switch (str_replace('gravityview/', '', $error->get_error_code())) { |
|
314 | + case 'post_password_required': |
|
315 | + return get_the_password_form($view->ID); |
|
316 | + case 'no_form_attached': |
|
317 | + |
|
318 | + gravityview()->log->error('View #{view_id} cannot render: {error_code} {error_message}', ['error_code' => $error->get_error_code(), 'error_message' => $error->get_error_message()]); |
|
319 | + |
|
320 | + /** |
|
321 | + * This View has no data source. There's nothing to show really. |
|
322 | + * ...apart from a nice message if the user can do anything about it. |
|
323 | + */ |
|
324 | + if (\GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview'], $view->ID)) { |
|
325 | + $title = sprintf(__('This View is not configured properly. Start by <a href="%s">selecting a form</a>.', 'gravityview'), esc_url(get_edit_post_link($view->ID, false))); |
|
326 | + |
|
327 | + $message = esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
328 | + |
|
329 | + $image = sprintf('<img alt="%s" src="%s" style="margin-top: 10px;" />', esc_attr__('Data Source', 'gravityview'), esc_url(plugins_url('assets/images/screenshots/data-source.png', GRAVITYVIEW_FILE))); |
|
330 | + |
|
331 | + return \GVCommon::generate_notice('<h3>'.$title.'</h3>'.wpautop($message.$image), 'notice'); |
|
332 | + } |
|
333 | + break; |
|
334 | + case 'in_trash': |
|
335 | + |
|
336 | + if (\GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview'], $view->ID)) { |
|
337 | + $notice = sprintf(__('This View is in the Trash. You can <a href="%s">restore the View here</a>.', 'gravityview'), esc_url(get_edit_post_link($view->ID, false))); |
|
338 | + |
|
339 | + return \GVCommon::generate_notice('<h3>'.$notice.'</h3>', 'notice', ['edit_gravityviews', 'edit_gravityview'], $view->ID); |
|
340 | + } |
|
341 | + |
|
342 | + return ''; // Do not show |
|
343 | + break; |
|
344 | + case 'no_direct_access': |
|
345 | + case 'embed_only': |
|
346 | + case 'not_public': |
|
347 | + default: |
|
348 | + gravityview()->log->notice('View #{view_id} cannot render: {error_code} {error_message}', ['error_code' => $error->get_error_code(), 'error_message' => $error->get_error_message()]); |
|
349 | + |
|
350 | + return __('You are not allowed to view this content.', 'gravityview'); |
|
351 | + } |
|
352 | + |
|
353 | + return $content; |
|
354 | + } |
|
355 | + |
|
356 | + $is_admin_and_can_view = $view->settings->get('admin_show_all_statuses') && \GVCommon::has_cap('gravityview_moderate_entries', $view->ID); |
|
357 | + |
|
358 | + /** |
|
359 | + * Editing a single entry. |
|
360 | + */ |
|
361 | + if ($entry = $request->is_edit_entry($view->form ? $view->form->ID : 0)) { |
|
362 | + if ($entry['status'] != 'active') { |
|
363 | + gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $entry->ID]); |
|
364 | + |
|
365 | + return __('You are not allowed to view this content.', 'gravityview'); |
|
366 | + } |
|
367 | + |
|
368 | + if (apply_filters('gravityview_custom_entry_slug', false) && $entry->slug != get_query_var(\GV\Entry::get_endpoint_name())) { |
|
369 | + gravityview()->log->error('Entry ID #{entry_id} was accessed by a bad slug', ['entry_id' => $entry->ID]); |
|
370 | + |
|
371 | + return __('You are not allowed to view this content.', 'gravityview'); |
|
372 | + } |
|
373 | + |
|
374 | + if ($view->settings->get('show_only_approved') && !$is_admin_and_can_view) { |
|
375 | + if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($entry->ID, \GravityView_Entry_Approval::meta_key))) { |
|
376 | + gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $entry->ID]); |
|
377 | + |
|
378 | + return __('You are not allowed to view this content.', 'gravityview'); |
|
379 | + } |
|
380 | + } |
|
381 | + |
|
382 | + $renderer = new Edit_Entry_Renderer(); |
|
383 | + |
|
384 | + return $renderer->render($entry, $view, $request); |
|
385 | + |
|
386 | + /** |
|
387 | + * Viewing a single entry. |
|
388 | + */ |
|
389 | + } elseif ($entry = $request->is_entry($view->form ? $view->form->ID : 0)) { |
|
390 | + $entryset = $entry->is_multi() ? $entry->entries : [$entry]; |
|
391 | + |
|
392 | + $custom_slug = apply_filters('gravityview_custom_entry_slug', false); |
|
393 | + $ids = explode(',', get_query_var(\GV\Entry::get_endpoint_name())); |
|
394 | + |
|
395 | + $show_only_approved = $view->settings->get('show_only_approved'); |
|
396 | + |
|
397 | + foreach ($entryset as $e) { |
|
398 | + if ('active' !== $e['status']) { |
|
399 | + gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $e->ID]); |
|
400 | + |
|
401 | + return __('You are not allowed to view this content.', 'gravityview'); |
|
402 | + } |
|
403 | + |
|
404 | + if ($custom_slug && !in_array($e->slug, $ids)) { |
|
405 | + gravityview()->log->error('Entry ID #{entry_id} was accessed by a bad slug', ['entry_id' => $e->ID]); |
|
406 | + |
|
407 | + return __('You are not allowed to view this content.', 'gravityview'); |
|
408 | + } |
|
409 | + |
|
410 | + if ($show_only_approved && !$is_admin_and_can_view) { |
|
411 | + if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($e->ID, \GravityView_Entry_Approval::meta_key))) { |
|
412 | + gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $e->ID]); |
|
413 | + |
|
414 | + return __('You are not allowed to view this content.', 'gravityview'); |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + $error = \GVCommon::check_entry_display($e->as_entry(), $view); |
|
419 | + |
|
420 | + if (is_wp_error($error)) { |
|
421 | + gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing: {message}', ['entry_id' => $e->ID, 'message' => $error->get_error_message()]); |
|
422 | + |
|
423 | + return __('You are not allowed to view this content.', 'gravityview'); |
|
424 | + } |
|
425 | + } |
|
426 | + |
|
427 | + $renderer = new Entry_Renderer(); |
|
428 | + |
|
429 | + return $renderer->render($entry, $view, $request); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Plain old View. |
|
434 | + */ |
|
435 | + $renderer = new View_Renderer(); |
|
436 | + |
|
437 | + return $renderer->render($view, $request); |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * Checks whether this view can be accessed or not. |
|
442 | + * |
|
443 | + * @param string[] $context The context we're asking for access from. |
|
444 | + * Can any and as many of one of: |
|
445 | + * edit An edit context. |
|
446 | + * single A single context. |
|
447 | + * cpt The custom post type single page accessed. |
|
448 | + * shortcode Embedded as a shortcode. |
|
449 | + * oembed Embedded as an oEmbed. |
|
450 | + * rest A REST call. |
|
451 | + * @param \GV\Request $request The request |
|
452 | + * |
|
453 | + * @return bool|\WP_Error An error if this View shouldn't be rendered here. |
|
454 | + */ |
|
455 | + public function can_render($context = null, $request = null) |
|
456 | + { |
|
457 | + if (!$request) { |
|
458 | + $request = gravityview()->request; |
|
459 | + } |
|
460 | + |
|
461 | + if (!is_array($context)) { |
|
462 | + $context = []; |
|
463 | + } |
|
464 | + |
|
465 | + /** |
|
466 | + * @filter `gravityview/view/can_render` Whether the view can be rendered or not. |
|
467 | + * |
|
468 | + * @param bool|\WP_Error $result The result. Default: null. |
|
469 | + * @param \GV\View $view The view. |
|
470 | + * @param string[] $context See \GV\View::can_render |
|
471 | + * @param \GV\Request $request The request. |
|
472 | + */ |
|
473 | + if (!is_null($result = apply_filters('gravityview/view/can_render', null, $this, $context, $request))) { |
|
474 | + return $result; |
|
475 | + } |
|
476 | + |
|
477 | + if (in_array('rest', $context)) { |
|
478 | + // REST |
|
479 | + if (gravityview()->plugin->settings->get('rest_api') === '1' && $this->settings->get('rest_disable') === '1') { |
|
480 | + return new \WP_Error('gravityview/rest_disabled'); |
|
481 | + } elseif (gravityview()->plugin->settings->get('rest_api') !== '1' && $this->settings->get('rest_enable') !== '1') { |
|
482 | + return new \WP_Error('gravityview/rest_disabled'); |
|
483 | + } |
|
484 | + } |
|
485 | + |
|
486 | + if (in_array('csv', $context)) { |
|
487 | + if ($this->settings->get('csv_enable') !== '1') { |
|
488 | + return new \WP_Error('gravityview/csv_disabled', 'The CSV endpoint is not enabled for this View'); |
|
489 | + } |
|
490 | + } |
|
491 | + |
|
492 | + /** |
|
493 | + * This View is password protected. Nothing to do here. |
|
494 | + */ |
|
495 | + if (post_password_required($this->ID)) { |
|
496 | + gravityview()->log->notice('Post password is required for View #{view_id}', ['view_id' => $this->ID]); |
|
497 | + |
|
498 | + return new \WP_Error('gravityview/post_password_required'); |
|
499 | + } |
|
500 | + |
|
501 | + if (!$this->form) { |
|
502 | + gravityview()->log->notice('View #{id} has no form attached to it.', ['id' => $this->ID]); |
|
503 | + |
|
504 | + return new \WP_Error('gravityview/no_form_attached'); |
|
505 | + } |
|
506 | + |
|
507 | + if (!in_array('shortcode', $context)) { |
|
508 | + /** |
|
509 | + * Is this View directly accessible via a post URL? |
|
510 | + * |
|
511 | + * @see https://codex.wordpress.org/Function_Reference/register_post_type#public |
|
512 | + */ |
|
513 | + |
|
514 | + /** |
|
515 | + * @filter `gravityview_direct_access` Should Views be directly accessible, or only visible using the shortcode? |
|
516 | + * |
|
517 | + * @deprecated |
|
518 | + * |
|
519 | + * @param bool `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded. Default: `true` |
|
520 | + * @param int $view_id The ID of the View currently being requested. `0` for general setting |
|
521 | + */ |
|
522 | + $direct_access = apply_filters('gravityview_direct_access', true, $this->ID); |
|
523 | + |
|
524 | + /** |
|
525 | + * @filter `gravityview/request/output/direct` Should this View be directly accessbile? |
|
526 | + * |
|
527 | + * @since 2.0 |
|
528 | + * |
|
529 | + * @param bool Accessible or not. Default: accessbile. |
|
530 | + * @param \GV\View $view The View we're trying to directly render here. |
|
531 | + * @param \GV\Request $request The current request. |
|
532 | + */ |
|
533 | + if (!apply_filters('gravityview/view/output/direct', $direct_access, $this, $request)) { |
|
534 | + return new \WP_Error('gravityview/no_direct_access'); |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Is this View an embed-only View? If so, don't allow rendering here, |
|
539 | + * as this is a direct request. |
|
540 | + */ |
|
541 | + if ($this->settings->get('embed_only') && !\GVCommon::has_cap('read_private_gravityviews')) { |
|
542 | + return new \WP_Error('gravityview/embed_only'); |
|
543 | + } |
|
544 | + } |
|
545 | + |
|
546 | + /** Private, pending, draft, etc. */ |
|
547 | + $public_states = get_post_stati(['public' => true]); |
|
548 | + if (!in_array($this->post_status, $public_states) && !\GVCommon::has_cap('read_gravityview', $this->ID)) { |
|
549 | + gravityview()->log->notice('The current user cannot access this View #{view_id}', ['view_id' => $this->ID]); |
|
550 | + |
|
551 | + return new \WP_Error('gravityview/not_public'); |
|
552 | + } |
|
553 | + |
|
554 | + return true; |
|
555 | + } |
|
556 | + |
|
557 | + /** |
|
558 | + * Get joins associated with a view. |
|
559 | + * |
|
560 | + * @param \WP_Post $post GravityView CPT to get joins for |
|
561 | + * |
|
562 | + * @api |
|
563 | + * |
|
564 | + * @since 2.0.11 |
|
565 | + * |
|
566 | + * @return \GV\Join[] Array of \GV\Join instances |
|
567 | + */ |
|
568 | + public static function get_joins($post) |
|
569 | + { |
|
570 | + $joins = []; |
|
571 | + |
|
572 | + if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
573 | + gravityview()->log->info('Cannot get joined forms; joins feature not supported.'); |
|
574 | + |
|
575 | + return $joins; |
|
576 | + } |
|
577 | + |
|
578 | + if (!$post || 'gravityview' !== get_post_type($post)) { |
|
579 | + gravityview()->log->error('Only "gravityview" post types can be \GV\View instances.'); |
|
580 | + |
|
581 | + return $joins; |
|
582 | + } |
|
583 | + |
|
584 | + $joins_meta = get_post_meta($post->ID, '_gravityview_form_joins', true); |
|
585 | + |
|
586 | + if (empty($joins_meta)) { |
|
587 | + return $joins; |
|
588 | + } |
|
589 | + |
|
590 | + foreach ($joins_meta as $meta) { |
|
591 | + if (!is_array($meta) || count($meta) != 4) { |
|
592 | + continue; |
|
593 | + } |
|
594 | + |
|
595 | + list($join, $join_column, $join_on, $join_on_column) = $meta; |
|
596 | + |
|
597 | + $join = GF_Form::by_id($join); |
|
598 | + $join_on = GF_Form::by_id($join_on); |
|
599 | + |
|
600 | + $join_column = is_numeric($join_column) ? GF_Field::by_id($join, $join_column) : Internal_Field::by_id($join_column); |
|
601 | + $join_on_column = is_numeric($join_on_column) ? GF_Field::by_id($join_on, $join_on_column) : Internal_Field::by_id($join_on_column); |
|
602 | + |
|
603 | + $joins[] = new Join($join, $join_column, $join_on, $join_on_column); |
|
604 | + } |
|
605 | + |
|
606 | + return $joins; |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Get joined forms associated with a view |
|
611 | + * In no particular order. |
|
612 | + * |
|
613 | + * @since 2.0.11 |
|
614 | + * |
|
615 | + * @api |
|
616 | + * |
|
617 | + * @since 2.0 |
|
618 | + * |
|
619 | + * @param int $post_id ID of the View |
|
620 | + * |
|
621 | + * @return \GV\GF_Form[] Array of \GV\GF_Form instances |
|
622 | + */ |
|
623 | + public static function get_joined_forms($post_id) |
|
624 | + { |
|
625 | + $forms = []; |
|
626 | + |
|
627 | + if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
628 | + gravityview()->log->info('Cannot get joined forms; joins feature not supported.'); |
|
629 | + |
|
630 | + return $forms; |
|
631 | + } |
|
632 | + |
|
633 | + if (!$post_id || !gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
634 | + return $forms; |
|
635 | + } |
|
636 | + |
|
637 | + if (empty($post_id)) { |
|
638 | + gravityview()->log->error('Cannot get joined forms; $post_id was empty'); |
|
639 | + |
|
640 | + return $forms; |
|
641 | + } |
|
642 | + |
|
643 | + $joins_meta = get_post_meta($post_id, '_gravityview_form_joins', true); |
|
644 | + |
|
645 | + if (empty($joins_meta)) { |
|
646 | + return $forms; |
|
647 | + } |
|
648 | + |
|
649 | + foreach ($joins_meta as $meta) { |
|
650 | + if (!is_array($meta) || count($meta) != 4) { |
|
651 | + continue; |
|
652 | + } |
|
653 | + |
|
654 | + list($join, $join_column, $join_on, $join_on_column) = $meta; |
|
655 | + |
|
656 | + if ($form = GF_Form::by_id($join_on)) { |
|
657 | + $forms[$join_on] = $form; |
|
658 | + } |
|
659 | + |
|
660 | + if ($form = GF_Form::by_id($join)) { |
|
661 | + $forms[$join] = $form; |
|
662 | + } |
|
663 | + } |
|
664 | + |
|
665 | + return $forms; |
|
666 | + } |
|
667 | + |
|
668 | + /** |
|
669 | + * Get unions associated with a view. |
|
670 | + * |
|
671 | + * @param \WP_Post $post GravityView CPT to get unions for |
|
672 | + * |
|
673 | + * @api |
|
674 | + * |
|
675 | + * @since 2.2.2 |
|
676 | + * |
|
677 | + * @return \GV\Field[][] Array of unions (see self::$unions) |
|
678 | + */ |
|
679 | + public static function get_unions($post) |
|
680 | + { |
|
681 | + $unions = []; |
|
682 | + |
|
683 | + if (!$post || 'gravityview' !== get_post_type($post)) { |
|
684 | + gravityview()->log->error('Only "gravityview" post types can be \GV\View instances.'); |
|
685 | + |
|
686 | + return $unions; |
|
687 | + } |
|
688 | + |
|
689 | + $fields = get_post_meta($post->ID, '_gravityview_directory_fields', true); |
|
690 | + |
|
691 | + if (empty($fields)) { |
|
692 | + return $unions; |
|
693 | + } |
|
694 | + |
|
695 | + foreach ($fields as $location => $_fields) { |
|
696 | + if (strpos($location, 'directory_') !== 0) { |
|
697 | + continue; |
|
698 | + } |
|
699 | + |
|
700 | + foreach ($_fields as $field) { |
|
701 | + if (!empty($field['unions'])) { |
|
702 | + foreach ($field['unions'] as $form_id => $field_id) { |
|
703 | + if (!isset($unions[$form_id])) { |
|
704 | + $unions[$form_id] = []; |
|
705 | + } |
|
706 | + |
|
707 | + $unions[$form_id][$field['id']] = |
|
708 | + is_numeric($field_id) ? \GV\GF_Field::by_id(\GV\GF_Form::by_id($form_id), $field_id) : \GV\Internal_Field::by_id($field_id); |
|
709 | + } |
|
710 | + } |
|
711 | + } |
|
712 | + |
|
713 | + break; |
|
714 | + } |
|
715 | + |
|
716 | + if ($unions) { |
|
717 | + if (!gravityview()->plugin->supports(Plugin::FEATURE_UNIONS)) { |
|
718 | + gravityview()->log->error('Cannot get unions; unions feature not supported.'); |
|
719 | + } |
|
720 | + } |
|
721 | + |
|
722 | + // @todo We'll probably need to backfill null unions |
|
723 | + |
|
724 | + return $unions; |
|
725 | + } |
|
726 | + |
|
727 | + /** |
|
728 | + * Construct a \GV\View instance from a \WP_Post. |
|
729 | + * |
|
730 | + * @param \WP_Post $post The \WP_Post instance to wrap. |
|
731 | + * |
|
732 | + * @api |
|
733 | + * |
|
734 | + * @since 2.0 |
|
735 | + * |
|
736 | + * @return \GV\View|null An instance around this \WP_Post if valid, null otherwise. |
|
737 | + */ |
|
738 | + public static function from_post($post) |
|
739 | + { |
|
740 | + if (!$post || 'gravityview' !== get_post_type($post)) { |
|
741 | + gravityview()->log->error('Only gravityview post types can be \GV\View instances.'); |
|
742 | + |
|
743 | + return null; |
|
744 | + } |
|
745 | + |
|
746 | + if ($view = Utils::get(self::$cache, "View::from_post:{$post->ID}")) { |
|
747 | + /** |
|
748 | + * @filter `gravityview/view/get` Override View. |
|
749 | + * |
|
750 | + * @param \GV\View $view The View instance pointer. |
|
751 | + * |
|
752 | + * @since 2.1 |
|
753 | + */ |
|
754 | + do_action_ref_array('gravityview/view/get', [&$view]); |
|
755 | + |
|
756 | + return $view; |
|
757 | + } |
|
758 | + |
|
759 | + $view = new self(); |
|
760 | + $view->post = $post; |
|
761 | + |
|
762 | + /** Get connected form. */ |
|
763 | + $view->form = GF_Form::by_id($view->_gravityview_form_id); |
|
764 | + if (!$view->form) { |
|
765 | + gravityview()->log->error('View #{view_id} tried attaching non-existent Form #{form_id} to it.', [ |
|
766 | + 'view_id' => $view->ID, |
|
767 | + 'form_id' => $view->_gravityview_form_id ?: 0, |
|
768 | + ]); |
|
769 | + } |
|
770 | + |
|
771 | + $view->joins = $view::get_joins($post); |
|
772 | + |
|
773 | + $view->unions = $view::get_unions($post); |
|
774 | + |
|
775 | + /** |
|
776 | + * @filter `gravityview/configuration/fields` Filter the View fields' configuration array. |
|
777 | + * |
|
778 | + * @since 1.6.5 |
|
779 | + * @deprecated Use `gravityview/view/configuration/fields` or `gravityview/view/fields` filters. |
|
780 | + * |
|
781 | + * @param $fields array Multi-array of fields with first level being the field zones. |
|
782 | + * @param $view_id int The View the fields are being pulled for. |
|
783 | + */ |
|
784 | + $configuration = apply_filters('gravityview/configuration/fields', (array) $view->_gravityview_directory_fields, $view->ID); |
|
785 | + |
|
786 | + /** |
|
787 | + * @filter `gravityview/view/configuration/fields` Filter the View fields' configuration array. |
|
788 | + * |
|
789 | + * @since 2.0 |
|
790 | + * |
|
791 | + * @param array $fields Multi-array of fields with first level being the field zones. |
|
792 | + * @param \GV\View $view The View the fields are being pulled for. |
|
793 | + */ |
|
794 | + $configuration = apply_filters('gravityview/view/configuration/fields', $configuration, $view); |
|
795 | + |
|
796 | + /** |
|
797 | + * @filter `gravityview/view/fields` Filter the Field Collection for this View. |
|
798 | + * |
|
799 | + * @since 2.0 |
|
800 | + * |
|
801 | + * @param \GV\Field_Collection $fields A collection of fields. |
|
802 | + * @param \GV\View $view The View the fields are being pulled for. |
|
803 | + */ |
|
804 | + $view->fields = apply_filters('gravityview/view/fields', Field_Collection::from_configuration($configuration), $view); |
|
805 | + |
|
806 | + /** |
|
807 | + * @filter `gravityview/view/configuration/widgets` Filter the View widgets' configuration array. |
|
808 | + * |
|
809 | + * @since 2.0 |
|
810 | + * |
|
811 | + * @param array $fields Multi-array of widgets with first level being the field zones. |
|
812 | + * @param \GV\View $view The View the widgets are being pulled for. |
|
813 | + */ |
|
814 | + $configuration = apply_filters('gravityview/view/configuration/widgets', (array) $view->_gravityview_directory_widgets, $view); |
|
815 | + |
|
816 | + /** |
|
817 | + * @filter `gravityview/view/widgets` Filter the Widget Collection for this View. |
|
818 | + * |
|
819 | + * @since 2.0 |
|
820 | + * |
|
821 | + * @param \GV\Widget_Collection $widgets A collection of widgets. |
|
822 | + * @param \GV\View $view The View the widgets are being pulled for. |
|
823 | + */ |
|
824 | + $view->widgets = apply_filters('gravityview/view/widgets', Widget_Collection::from_configuration($configuration), $view); |
|
825 | + |
|
826 | + /** View configuration. */ |
|
827 | + $view->settings->update(gravityview_get_template_settings($view->ID)); |
|
828 | + |
|
829 | + /** Add the template name into the settings. */ |
|
830 | + $view->settings->update(['template' => gravityview_get_template_id($view->ID)]); |
|
831 | + |
|
832 | + /** View basics. */ |
|
833 | + $view->settings->update([ |
|
834 | + 'id' => $view->ID, |
|
835 | + ]); |
|
836 | + |
|
837 | + self::$cache["View::from_post:{$post->ID}"] = &$view; |
|
838 | + |
|
839 | + /** |
|
840 | + * @filter `gravityview/view/get` Override View. |
|
841 | + * |
|
842 | + * @param \GV\View $view The View instance pointer. |
|
843 | + * |
|
844 | + * @since 2.1 |
|
845 | + */ |
|
846 | + do_action_ref_array('gravityview/view/get', [&$view]); |
|
847 | + |
|
848 | + return $view; |
|
849 | + } |
|
850 | + |
|
851 | + /** |
|
852 | + * Flush the view cache. |
|
853 | + * |
|
854 | + * @param int $view_id The View to reset cache for. Optional. Default: resets everything. |
|
855 | + * |
|
856 | + * @internal |
|
857 | + */ |
|
858 | + public static function _flush_cache($view_id = null) |
|
859 | + { |
|
860 | + if ($view_id) { |
|
861 | + unset(self::$cache["View::from_post:$view_id"]); |
|
862 | + |
|
863 | + return; |
|
864 | + } |
|
865 | + self::$cache = []; |
|
866 | + } |
|
867 | + |
|
868 | + /** |
|
869 | + * Construct a \GV\View instance from a post ID. |
|
870 | + * |
|
871 | + * @param int|string $post_id The post ID. |
|
872 | + * |
|
873 | + * @api |
|
874 | + * |
|
875 | + * @since 2.0 |
|
876 | + * |
|
877 | + * @return \GV\View|null An instance around this \WP_Post or null if not found. |
|
878 | + */ |
|
879 | + public static function by_id($post_id) |
|
880 | + { |
|
881 | + if (!$post_id || !$post = get_post($post_id)) { |
|
882 | + return null; |
|
883 | + } |
|
884 | + |
|
885 | + return self::from_post($post); |
|
886 | + } |
|
887 | + |
|
888 | + /** |
|
889 | + * Determines if a view exists to begin with. |
|
890 | + * |
|
891 | + * @param int|\WP_Post|null $view The WordPress post ID, a \WP_Post object or null for global $post; |
|
892 | + * |
|
893 | + * @api |
|
894 | + * |
|
895 | + * @since 2.0 |
|
896 | + * |
|
897 | + * @return bool Whether the post exists or not. |
|
898 | + */ |
|
899 | + public static function exists($view) |
|
900 | + { |
|
901 | + return get_post_type($view) == 'gravityview'; |
|
902 | + } |
|
903 | + |
|
904 | + /** |
|
905 | + * ArrayAccess compatibility layer with GravityView_View_Data::$views. |
|
906 | + * |
|
907 | + * @internal |
|
908 | + * |
|
909 | + * @deprecated |
|
910 | + * @since 2.0 |
|
911 | + * |
|
912 | + * @return bool Whether the offset exists or not, limited to GravityView_View_Data::$views element keys. |
|
913 | + */ |
|
914 | + public function offsetExists($offset) |
|
915 | + { |
|
916 | + $data_keys = ['id', 'view_id', 'form_id', 'template_id', 'atts', 'fields', 'widgets', 'form']; |
|
917 | + |
|
918 | + return in_array($offset, $data_keys); |
|
919 | + } |
|
920 | + |
|
921 | + /** |
|
922 | + * ArrayAccess compatibility layer with GravityView_View_Data::$views. |
|
923 | + * |
|
924 | + * Maps the old keys to the new data; |
|
925 | + * |
|
926 | + * @internal |
|
927 | + * |
|
928 | + * @deprecated |
|
929 | + * @since 2.0 |
|
930 | + * |
|
931 | + * @return mixed The value of the requested view data key limited to GravityView_View_Data::$views element keys. If offset not found, return null. |
|
932 | + */ |
|
933 | + public function offsetGet($offset) |
|
934 | + { |
|
935 | + gravityview()->log->notice('This is a \GV\View object should not be accessed as an array.'); |
|
936 | + |
|
937 | + if (!isset($this[$offset])) { |
|
938 | + return null; |
|
939 | + } |
|
940 | + |
|
941 | + switch ($offset) { |
|
942 | + case 'id': |
|
943 | + case 'view_id': |
|
944 | + return $this->ID; |
|
945 | + case 'form': |
|
946 | + return $this->form; |
|
947 | + case 'form_id': |
|
948 | + return $this->form ? $this->form->ID : null; |
|
949 | + case 'atts': |
|
950 | + return $this->settings->as_atts(); |
|
951 | + case 'template_id': |
|
952 | + return $this->settings->get('template'); |
|
953 | + case 'widgets': |
|
954 | + return $this->widgets->as_configuration(); |
|
955 | + } |
|
956 | + |
|
957 | + return null; |
|
958 | + } |
|
959 | + |
|
960 | + /** |
|
961 | + * ArrayAccess compatibility layer with GravityView_View_Data::$views. |
|
962 | + * |
|
963 | + * @internal |
|
964 | + * |
|
965 | + * @deprecated |
|
966 | + * @since 2.0 |
|
967 | + * |
|
968 | + * @return void |
|
969 | + */ |
|
970 | + public function offsetSet($offset, $value) |
|
971 | + { |
|
972 | + gravityview()->log->error('The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.'); |
|
973 | + } |
|
974 | + |
|
975 | + /** |
|
976 | + * ArrayAccess compatibility layer with GravityView_View_Data::$views. |
|
977 | + * |
|
978 | + * @internal |
|
979 | + * |
|
980 | + * @deprecated |
|
981 | + * @since 2.0 |
|
982 | + * |
|
983 | + * @return void |
|
984 | + */ |
|
985 | + public function offsetUnset($offset) |
|
986 | + { |
|
987 | + gravityview()->log->error('The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.'); |
|
988 | + } |
|
989 | + |
|
990 | + /** |
|
991 | + * Be compatible with the old data object. |
|
992 | + * |
|
993 | + * Some external code expects an array (doing things like foreach on this, or array_keys) |
|
994 | + * so let's return an array in the old format for such cases. Do not use unless using |
|
995 | + * for back-compatibility. |
|
996 | + * |
|
997 | + * @internal |
|
998 | + * |
|
999 | + * @deprecated |
|
1000 | + * @since 2.0 |
|
1001 | + * |
|
1002 | + * @return array |
|
1003 | + */ |
|
1004 | + public function as_data() |
|
1005 | + { |
|
1006 | + return [ |
|
1007 | + 'id' => $this->ID, |
|
1008 | + 'view_id' => $this->ID, |
|
1009 | + 'form_id' => $this->form ? $this->form->ID : null, |
|
1010 | + 'form' => $this->form ? gravityview_get_form($this->form->ID) : null, |
|
1011 | + 'atts' => $this->settings->as_atts(), |
|
1012 | + 'fields' => $this->fields->by_visible($this)->as_configuration(), |
|
1013 | + 'template_id' => $this->settings->get('template'), |
|
1014 | + 'widgets' => $this->widgets->as_configuration(), |
|
1015 | + ]; |
|
1016 | + } |
|
1017 | + |
|
1018 | + /** |
|
1019 | + * Retrieve the entries for the current view and request. |
|
1020 | + * |
|
1021 | + * @param \GV\Request The request. Unused for now. |
|
1022 | + * |
|
1023 | + * @return \GV\Entry_Collection The entries. |
|
1024 | + */ |
|
1025 | + public function get_entries($request = null) |
|
1026 | + { |
|
1027 | + $entries = new \GV\Entry_Collection(); |
|
1028 | + |
|
1029 | + if (!$this->form) { |
|
1030 | + // Documented below. |
|
1031 | + return apply_filters('gravityview/view/entries', $entries, $this, $request); |
|
1032 | + } |
|
1033 | + |
|
1034 | + $parameters = $this->settings->as_atts(); |
|
1035 | + |
|
1036 | + /** |
|
1037 | + * Remove multiple sorting before calling legacy filters. |
|
1038 | + * This allows us to fake it till we make it. |
|
1039 | + */ |
|
1040 | + if (!empty($parameters['sort_field']) && is_array($parameters['sort_field'])) { |
|
1041 | + $has_multisort = true; |
|
1042 | + $parameters['sort_field'] = reset($parameters['sort_field']); |
|
1043 | + if (!empty($parameters['sort_direction']) && is_array($parameters['sort_direction'])) { |
|
1044 | + $parameters['sort_direction'] = reset($parameters['sort_direction']); |
|
1045 | + } |
|
1046 | + } |
|
1047 | + |
|
1048 | + /** |
|
1049 | + * @todo: Stop using _frontend and use something like $request->get_search_criteria() instead |
|
1050 | + */ |
|
1051 | + $parameters = \GravityView_frontend::get_view_entries_parameters($parameters, $this->form->ID); |
|
1052 | + |
|
1053 | + $parameters['context_view_id'] = $this->ID; |
|
1054 | + $parameters = \GVCommon::calculate_get_entries_criteria($parameters, $this->form->ID); |
|
1055 | + |
|
1056 | + if (!is_array($parameters)) { |
|
1057 | + $parameters = []; |
|
1058 | + } |
|
1059 | + |
|
1060 | + if (!is_array($parameters['search_criteria'])) { |
|
1061 | + $parameters['search_criteria'] = []; |
|
1062 | + } |
|
1063 | + |
|
1064 | + if ((!isset($parameters['search_criteria']['field_filters'])) || (!is_array($parameters['search_criteria']['field_filters']))) { |
|
1065 | + $parameters['search_criteria']['field_filters'] = []; |
|
1066 | + } |
|
1067 | + |
|
1068 | + if ($request instanceof REST\Request) { |
|
1069 | + $atts = $this->settings->as_atts(); |
|
1070 | + $paging_parameters = wp_parse_args($request->get_paging(), [ |
|
1071 | + 'paging' => ['page_size' => $atts['page_size']], |
|
1072 | + ]); |
|
1073 | + $parameters['paging'] = $paging_parameters['paging']; |
|
1074 | + } |
|
1075 | + |
|
1076 | + $page = Utils::get($parameters['paging'], 'current_page') ?: ((($parameters['paging']['offset'] - $this->settings->get('offset')) / \GV\Utils::get($parameters, 'paging/page_size', 25)) + 1); |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * Cleanup duplicate field_filter parameters to simplify the query. |
|
1080 | + */ |
|
1081 | + $unique_field_filters = []; |
|
1082 | + foreach (Utils::get($parameters, 'search_criteria/field_filters', []) as $key => $filter) { |
|
1083 | + if ('mode' === $key) { |
|
1084 | + $unique_field_filters['mode'] = $filter; |
|
1085 | + } elseif (!in_array($filter, $unique_field_filters)) { |
|
1086 | + $unique_field_filters[] = $filter; |
|
1087 | + } |
|
1088 | + } |
|
1089 | + $parameters['search_criteria']['field_filters'] = $unique_field_filters; |
|
1090 | + |
|
1091 | + if (!empty($parameters['search_criteria']['field_filters'])) { |
|
1092 | + gravityview()->log->notice('search_criteria/field_filters is not empty, third-party code may be using legacy search_criteria filters.'); |
|
1093 | + } |
|
1094 | + |
|
1095 | + if (gravityview()->plugin->supports(Plugin::FEATURE_GFQUERY)) { |
|
1096 | + $query_class = $this->get_query_class(); |
|
1097 | + |
|
1098 | + /** @var \GF_Query $query */ |
|
1099 | + $query = new $query_class($this->form->ID, $parameters['search_criteria'], Utils::get($parameters, 'sorting')); |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Apply multisort. |
|
1103 | + */ |
|
1104 | + if (!empty($has_multisort)) { |
|
1105 | + $atts = $this->settings->as_atts(); |
|
1106 | + |
|
1107 | + $view_setting_sort_field_ids = \GV\Utils::get($atts, 'sort_field', []); |
|
1108 | + $view_setting_sort_directions = \GV\Utils::get($atts, 'sort_direction', []); |
|
1109 | + |
|
1110 | + $has_sort_query_param = !empty($_GET['sort']) && is_array($_GET['sort']); |
|
1111 | + |
|
1112 | + if ($has_sort_query_param) { |
|
1113 | + $has_sort_query_param = array_filter(array_values($_GET['sort'])); |
|
1114 | + } |
|
1115 | + |
|
1116 | + if ($this->settings->get('sort_columns') && $has_sort_query_param) { |
|
1117 | + $sort_field_ids = array_keys($_GET['sort']); |
|
1118 | + $sort_directions = array_values($_GET['sort']); |
|
1119 | + } else { |
|
1120 | + $sort_field_ids = $view_setting_sort_field_ids; |
|
1121 | + $sort_directions = $view_setting_sort_directions; |
|
1122 | + } |
|
1123 | + |
|
1124 | + $skip_first = false; |
|
1125 | + |
|
1126 | + foreach ((array) $sort_field_ids as $key => $sort_field_id) { |
|
1127 | + if (!$skip_first && !$has_sort_query_param) { |
|
1128 | + $skip_first = true; // Skip the first one, it's already in the query |
|
1129 | + continue; |
|
1130 | + } |
|
1131 | + |
|
1132 | + $sort_field_id = \GravityView_frontend::_override_sorting_id_by_field_type($sort_field_id, $this->form->ID); |
|
1133 | + $sort_direction = strtoupper(\GV\Utils::get($sort_directions, $key, 'ASC')); |
|
1134 | + |
|
1135 | + if (!empty($sort_field_id)) { |
|
1136 | + $order = new \GF_Query_Column($sort_field_id, $this->form->ID); |
|
1137 | + if ('id' !== $sort_field_id && \GVCommon::is_field_numeric($this->form->ID, $sort_field_id)) { |
|
1138 | + $order = \GF_Query_Call::CAST($order, defined('GF_Query::TYPE_DECIMAL') ? \GF_Query::TYPE_DECIMAL : \GF_Query::TYPE_SIGNED); |
|
1139 | + } |
|
1140 | + |
|
1141 | + $query->order($order, $sort_direction); |
|
1142 | + } |
|
1143 | + } |
|
1144 | + } |
|
1145 | + |
|
1146 | + /** |
|
1147 | + * Merge time subfield sorts. |
|
1148 | + */ |
|
1149 | + add_filter('gform_gf_query_sql', $gf_query_timesort_sql_callback = function ($sql) use (&$query) { |
|
1150 | + $q = $query->_introspect(); |
|
1151 | + $orders = []; |
|
1152 | + |
|
1153 | + $merged_time = false; |
|
1154 | + |
|
1155 | + foreach ($q['order'] as $oid => $order) { |
|
1156 | + $column = null; |
|
1157 | + |
|
1158 | + if ($order[0] instanceof \GF_Query_Column) { |
|
1159 | + $column = $order[0]; |
|
1160 | + } elseif ($order[0] instanceof \GF_Query_Call) { |
|
1161 | + if (count($order[0]->columns) != 1 || !$order[0]->columns[0] instanceof \GF_Query_Column) { |
|
1162 | + $orders[$oid] = $order; |
|
1163 | + continue; // Need something that resembles a single sort |
|
1164 | + } |
|
1165 | + $column = $order[0]->columns[0]; |
|
1166 | + } |
|
1167 | + |
|
1168 | + if (!$column || (!$field = \GFAPI::get_field($column->source, $column->field_id)) || $field->type !== 'time') { |
|
1169 | + $orders[$oid] = $order; |
|
1170 | + continue; // Not a time field |
|
1171 | + } |
|
1172 | + |
|
1173 | + if (!class_exists('\GV\Mocks\GF_Query_Call_TIMESORT')) { |
|
1174 | + require_once gravityview()->plugin->dir('future/_mocks.timesort.php'); |
|
1175 | + } |
|
1176 | + |
|
1177 | + $orders[$oid] = [ |
|
1178 | + new \GV\Mocks\GF_Query_Call_TIMESORT('timesort', [$column, $sql]), |
|
1179 | + $order[1], // Mock it! |
|
1180 | + ]; |
|
1181 | + |
|
1182 | + $merged_time = true; |
|
1183 | + } |
|
1184 | + |
|
1185 | + if ($merged_time) { |
|
1186 | + /** |
|
1187 | + * ORDER again. |
|
1188 | + */ |
|
1189 | + if (!empty($orders) && $_orders = $query->_order_generate($orders)) { |
|
1190 | + $sql['order'] = 'ORDER BY '.implode(', ', $_orders); |
|
1191 | + } |
|
1192 | + } |
|
1193 | + |
|
1194 | + return $sql; |
|
1195 | + }); |
|
1196 | + |
|
1197 | + $query->limit($parameters['paging']['page_size']) |
|
1198 | + ->offset((($page - 1) * $parameters['paging']['page_size']) + $this->settings->get('offset')); |
|
1199 | + |
|
1200 | + /** |
|
1201 | + * Any joins? |
|
1202 | + */ |
|
1203 | + if (gravityview()->plugin->supports(Plugin::FEATURE_JOINS) && count($this->joins)) { |
|
1204 | + $is_admin_and_can_view = $this->settings->get('admin_show_all_statuses') && \GVCommon::has_cap('gravityview_moderate_entries', $this->ID); |
|
1205 | + |
|
1206 | + foreach ($this->joins as $join) { |
|
1207 | + $query = $join->as_query_join($query); |
|
1208 | + |
|
1209 | + if ($this->settings->get('multiple_forms_disable_null_joins')) { |
|
1210 | + |
|
1211 | + // Disable NULL outputs |
|
1212 | + $condition = new \GF_Query_Condition( |
|
1213 | + new \GF_Query_Column($join->join_on_column->ID, $join->join_on->ID), |
|
1214 | + \GF_Query_Condition::NEQ, |
|
1215 | + new \GF_Query_Literal('') |
|
1216 | + ); |
|
1217 | + |
|
1218 | + $query_parameters = $query->_introspect(); |
|
1219 | + |
|
1220 | + $query->where(\GF_Query_Condition::_and($query_parameters['where'], $condition)); |
|
1221 | + } |
|
1222 | + |
|
1223 | + /** |
|
1224 | + * This is a temporary stub filter, until GF_Query supports NULL conditions. |
|
1225 | + * Do not use! This filter will be removed. |
|
1226 | + */ |
|
1227 | + if (defined('GF_Query_Condition::NULL')) { |
|
1228 | + $is_null_condition_native = true; |
|
1229 | + } else { |
|
1230 | + $is_null_condition_class = apply_filters('gravityview/query/is_null_condition', null); |
|
1231 | + $is_null_condition_native = false; |
|
1232 | + } |
|
1233 | + |
|
1234 | + // Filter to active entries only |
|
1235 | + $condition = new \GF_Query_Condition( |
|
1236 | + new \GF_Query_Column('status', $join->join_on->ID), |
|
1237 | + \GF_Query_Condition::EQ, |
|
1238 | + new \GF_Query_Literal('active') |
|
1239 | + ); |
|
1240 | + |
|
1241 | + if ($is_null_condition_native) { |
|
1242 | + $condition = \GF_Query_Condition::_or($condition, new \GF_Query_Condition( |
|
1243 | + new \GF_Query_Column('status', $join->join_on->ID), |
|
1244 | + \GF_Query_Condition::IS, |
|
1245 | + \GF_Query_Condition::NULL |
|
1246 | + )); |
|
1247 | + } elseif (!is_null($is_null_condition_class)) { |
|
1248 | + $condition = \GF_Query_Condition::_or($condition, new $is_null_condition_class( |
|
1249 | + new \GF_Query_Column('status', $join->join_on->ID) |
|
1250 | + )); |
|
1251 | + } |
|
1252 | + |
|
1253 | + $q = $query->_introspect(); |
|
1254 | + $query->where(\GF_Query_Condition::_and($q['where'], $condition)); |
|
1255 | + |
|
1256 | + if ($this->settings->get('show_only_approved') && !$is_admin_and_can_view) { |
|
1257 | + |
|
1258 | + // Show only approved joined entries |
|
1259 | + $condition = new \GF_Query_Condition( |
|
1260 | + new \GF_Query_Column(\GravityView_Entry_Approval::meta_key, $join->join_on->ID), |
|
1261 | + \GF_Query_Condition::EQ, |
|
1262 | + new \GF_Query_Literal(\GravityView_Entry_Approval_Status::APPROVED) |
|
1263 | + ); |
|
1264 | + |
|
1265 | + if ($is_null_condition_native) { |
|
1266 | + $condition = \GF_Query_Condition::_or($condition, new \GF_Query_Condition( |
|
1267 | + new \GF_Query_Column(\GravityView_Entry_Approval::meta_key, $join->join_on->ID), |
|
1268 | + \GF_Query_Condition::IS, |
|
1269 | + \GF_Query_Condition::NULL |
|
1270 | + )); |
|
1271 | + } elseif (!is_null($is_null_condition_class)) { |
|
1272 | + $condition = \GF_Query_Condition::_or($condition, new $is_null_condition_class( |
|
1273 | + new \GF_Query_Column(\GravityView_Entry_Approval::meta_key, $join->join_on->ID) |
|
1274 | + )); |
|
1275 | + } |
|
1276 | + |
|
1277 | + $query_parameters = $query->_introspect(); |
|
1278 | + |
|
1279 | + $query->where(\GF_Query_Condition::_and($query_parameters['where'], $condition)); |
|
1280 | + } |
|
1281 | + } |
|
1282 | + |
|
1283 | + /** |
|
1284 | + * Unions? |
|
1285 | + */ |
|
1286 | + } elseif (gravityview()->plugin->supports(Plugin::FEATURE_UNIONS) && count($this->unions)) { |
|
1287 | + $query_parameters = $query->_introspect(); |
|
1288 | + |
|
1289 | + $unions_sql = []; |
|
1290 | + |
|
1291 | + /** |
|
1292 | + * @param \GF_Query_Condition $condition |
|
1293 | + * @param array $fields |
|
1294 | + * @param $recurse |
|
1295 | + * |
|
1296 | + * @return \GF_Query_Condition |
|
1297 | + */ |
|
1298 | + $where_union_substitute = function ($condition, $fields, $recurse) { |
|
1299 | + if ($condition->expressions) { |
|
1300 | + $conditions = []; |
|
1301 | + |
|
1302 | + foreach ($condition->expressions as $_condition) { |
|
1303 | + $conditions[] = $recurse($_condition, $fields, $recurse); |
|
1304 | + } |
|
1305 | + |
|
1306 | + return call_user_func_array( |
|
1307 | + ['\GF_Query_Condition', $condition->operator == 'AND' ? '_and' : '_or'], |
|
1308 | + $conditions |
|
1309 | + ); |
|
1310 | + } |
|
1311 | + |
|
1312 | + if (!($condition->left && $condition->left instanceof \GF_Query_Column) || (!$condition->left->is_entry_column() && !$condition->left->is_meta_column())) { |
|
1313 | + return new \GF_Query_Condition( |
|
1314 | + new \GF_Query_Column($fields[$condition->left->field_id]->ID), |
|
1315 | + $condition->operator, |
|
1316 | + $condition->right |
|
1317 | + ); |
|
1318 | + } |
|
1319 | + |
|
1320 | + return $condition; |
|
1321 | + }; |
|
1322 | + |
|
1323 | + foreach ($this->unions as $form_id => $fields) { |
|
1324 | + |
|
1325 | + // Build a new query for every unioned form |
|
1326 | + $query_class = $this->get_query_class(); |
|
1327 | + |
|
1328 | + /** @var \GF_Query|\GF_Patched_Query $q */ |
|
1329 | + $q = new $query_class($form_id); |
|
1330 | + |
|
1331 | + // Copy the WHERE clauses but substitute the field_ids to the respective ones |
|
1332 | + $q->where($where_union_substitute($query_parameters['where'], $fields, $where_union_substitute)); |
|
1333 | + |
|
1334 | + // Copy the ORDER clause and substitute the field_ids to the respective ones |
|
1335 | + foreach ($query_parameters['order'] as $order) { |
|
1336 | + list($column, $_order) = $order; |
|
1337 | + |
|
1338 | + if ($column && $column instanceof \GF_Query_Column) { |
|
1339 | + if (!$column->is_entry_column() && !$column->is_meta_column()) { |
|
1340 | + $column = new \GF_Query_Column($fields[$column->field_id]->ID); |
|
1341 | + } |
|
1342 | + |
|
1343 | + $q->order($column, $_order); |
|
1344 | + } |
|
1345 | + } |
|
1346 | + |
|
1347 | + add_filter('gform_gf_query_sql', $gf_query_sql_callback = function ($sql) use (&$unions_sql) { |
|
1348 | + // Remove SQL_CALC_FOUND_ROWS as it's not needed in UNION clauses |
|
1349 | + $select = 'UNION ALL '.str_replace('SQL_CALC_FOUND_ROWS ', '', $sql['select']); |
|
1350 | + |
|
1351 | + // Record the SQL |
|
1352 | + $unions_sql[] = [ |
|
1353 | + // Remove columns, we'll rebuild them |
|
1354 | + 'select' => preg_replace('#DISTINCT (.*)#', 'DISTINCT ', $select), |
|
1355 | + 'from' => $sql['from'], |
|
1356 | + 'join' => $sql['join'], |
|
1357 | + 'where' => $sql['where'], |
|
1358 | + // Remove order and limit |
|
1359 | + ]; |
|
1360 | + |
|
1361 | + // Return empty query, no need to call the database |
|
1362 | + return []; |
|
1363 | + }); |
|
1364 | + |
|
1365 | + do_action_ref_array('gravityview/view/query', [&$q, $this, $request]); |
|
1366 | + |
|
1367 | + $q->get(); // Launch |
|
1368 | + |
|
1369 | + remove_filter('gform_gf_query_sql', $gf_query_sql_callback); |
|
1370 | + } |
|
1371 | + |
|
1372 | + add_filter('gform_gf_query_sql', $gf_query_sql_callback = function ($sql) use ($unions_sql) { |
|
1373 | + // Remove SQL_CALC_FOUND_ROWS as it's not needed in UNION clauses |
|
1374 | + $sql['select'] = str_replace('SQL_CALC_FOUND_ROWS ', '', $sql['select']); |
|
1375 | + |
|
1376 | + // Remove columns, we'll rebuild them |
|
1377 | + preg_match('#DISTINCT (`[motc]\d+`.`.*?`)#', $sql['select'], $select_match); |
|
1378 | + $sql['select'] = preg_replace('#DISTINCT (.*)#', 'DISTINCT ', $sql['select']); |
|
1379 | + |
|
1380 | + $unions = []; |
|
1381 | + |
|
1382 | + // Transform selected columns to shared alias names |
|
1383 | + $column_to_alias = function ($column) { |
|
1384 | + $column = str_replace('`', '', $column); |
|
1385 | + |
|
1386 | + return '`'.str_replace('.', '_', $column).'`'; |
|
1387 | + }; |
|
1388 | + |
|
1389 | + // Add all the order columns into the selects, so we can order by the whole union group |
|
1390 | + preg_match_all('#(`[motc]\d+`.`.*?`)#', $sql['order'], $order_matches); |
|
1391 | + |
|
1392 | + $columns = [ |
|
1393 | + sprintf('%s AS %s', $select_match[1], $column_to_alias($select_match[1])), |
|
1394 | + ]; |
|
1395 | + |
|
1396 | + foreach (array_slice($order_matches, 1) as $match) { |
|
1397 | + $columns[] = sprintf('%s AS %s', $match[0], $column_to_alias($match[0])); |
|
1398 | + |
|
1399 | + // Rewrite the order columns to the shared aliases |
|
1400 | + $sql['order'] = str_replace($match[0], $column_to_alias($match[0]), $sql['order']); |
|
1401 | + } |
|
1402 | + |
|
1403 | + $columns = array_unique($columns); |
|
1404 | + |
|
1405 | + // Add the columns to every UNION |
|
1406 | + foreach ($unions_sql as $union_sql) { |
|
1407 | + $union_sql['select'] .= implode(', ', $columns); |
|
1408 | + $unions[] = implode(' ', $union_sql); |
|
1409 | + } |
|
1410 | + |
|
1411 | + // Add the columns to the main SELECT, but only grab the entry id column |
|
1412 | + $sql['select'] = 'SELECT SQL_CALC_FOUND_ROWS t1_id FROM ('.$sql['select'].implode(', ', $columns); |
|
1413 | + $sql['order'] = implode(' ', $unions).') AS u '.$sql['order']; |
|
1414 | + |
|
1415 | + return $sql; |
|
1416 | + }); |
|
1417 | + } |
|
1418 | + |
|
1419 | + /** |
|
1420 | + * @action `gravityview/view/query` Override the \GF_Query before the get() call. |
|
1421 | + * |
|
1422 | + * @param \GF_Query $query The current query object reference |
|
1423 | + * @param \GV\View $this The current view object |
|
1424 | + * @param \GV\Request $request The request object |
|
1425 | + */ |
|
1426 | + do_action_ref_array('gravityview/view/query', [&$query, $this, $request]); |
|
1427 | + |
|
1428 | + gravityview()->log->debug('GF_Query parameters: ', ['data' => Utils::gf_query_debug($query)]); |
|
1429 | + |
|
1430 | + /** |
|
1431 | + * Map from Gravity Forms entries arrays to an Entry_Collection. |
|
1432 | + */ |
|
1433 | + if (count($this->joins)) { |
|
1434 | + foreach ($query->get() as $entry) { |
|
1435 | + $entries->add( |
|
1436 | + Multi_Entry::from_entries(array_map('\GV\GF_Entry::from_entry', $entry)) |
|
1437 | + ); |
|
1438 | + } |
|
1439 | + } else { |
|
1440 | + array_map([$entries, 'add'], array_map('\GV\GF_Entry::from_entry', $query->get())); |
|
1441 | + } |
|
1442 | + |
|
1443 | + if (isset($gf_query_sql_callback)) { |
|
1444 | + remove_action('gform_gf_query_sql', $gf_query_sql_callback); |
|
1445 | + } |
|
1446 | + |
|
1447 | + if (isset($gf_query_timesort_sql_callback)) { |
|
1448 | + remove_action('gform_gf_query_sql', $gf_query_timesort_sql_callback); |
|
1449 | + } |
|
1450 | + |
|
1451 | + /** |
|
1452 | + * Add total count callback. |
|
1453 | + */ |
|
1454 | + $entries->add_count_callback(function () use ($query) { |
|
1455 | + return $query->total_found; |
|
1456 | + }); |
|
1457 | + } else { |
|
1458 | + $entries = $this->form->entries |
|
1459 | + ->filter(\GV\GF_Entry_Filter::from_search_criteria($parameters['search_criteria'])) |
|
1460 | + ->offset($this->settings->get('offset')) |
|
1461 | + ->limit($parameters['paging']['page_size']) |
|
1462 | + ->page($page); |
|
1463 | + |
|
1464 | + if (!empty($parameters['sorting']) && is_array($parameters['sorting'] && !isset($parameters['sorting']['key']))) { |
|
1465 | + // Pluck off multisort arrays |
|
1466 | + $parameters['sorting'] = $parameters['sorting'][0]; |
|
1467 | + } |
|
1468 | + |
|
1469 | + if (!empty($parameters['sorting']) && !empty($parameters['sorting']['key'])) { |
|
1470 | + $field = new \GV\Field(); |
|
1471 | + $field->ID = $parameters['sorting']['key']; |
|
1472 | + $direction = strtolower($parameters['sorting']['direction']) == 'asc' ? \GV\Entry_Sort::ASC : \GV\Entry_Sort::DESC; |
|
1473 | + $entries = $entries->sort(new \GV\Entry_Sort($field, $direction)); |
|
1474 | + } |
|
1475 | + } |
|
1476 | + |
|
1477 | + /** |
|
1478 | + * @filter `gravityview/view/entries` Modify the entry fetching filters, sorts, offsets, limits. |
|
1479 | + * |
|
1480 | + * @param \GV\Entry_Collection $entries The entries for this view. |
|
1481 | + * @param \GV\View $view The view. |
|
1482 | + * @param \GV\Request $request The request. |
|
1483 | + */ |
|
1484 | + return apply_filters('gravityview/view/entries', $entries, $this, $request); |
|
1485 | + } |
|
1486 | + |
|
1487 | + /** |
|
1488 | + * Last chance to configure the output. |
|
1489 | + * |
|
1490 | + * Used for CSV output, for example. |
|
1491 | + * |
|
1492 | + * @return void |
|
1493 | + */ |
|
1494 | + public static function template_redirect() |
|
1495 | + { |
|
1496 | + $is_csv = get_query_var('csv'); |
|
1497 | + $is_tsv = get_query_var('tsv'); |
|
1498 | + |
|
1499 | + /** |
|
1500 | + * CSV output. |
|
1501 | + */ |
|
1502 | + if (!$is_csv && !$is_tsv) { |
|
1503 | + return; |
|
1504 | + } |
|
1505 | + |
|
1506 | + $view = gravityview()->request->is_view(); |
|
1507 | + |
|
1508 | + if (!$view) { |
|
1509 | + return; |
|
1510 | + } |
|
1511 | + |
|
1512 | + $error_csv = $view->can_render(['csv']); |
|
1513 | + |
|
1514 | + if (is_wp_error($error_csv)) { |
|
1515 | + gravityview()->log->error('Not rendering CSV or TSV: '.$error_csv->get_error_message()); |
|
1516 | + |
|
1517 | + return; |
|
1518 | + } |
|
1519 | + |
|
1520 | + $file_type = $is_csv ? 'csv' : 'tsv'; |
|
1521 | + |
|
1522 | + /** |
|
1523 | + * @filter `gravityview/output/{csv|tsv}/filename` Modify the name of the generated CSV or TSV file. Name will be sanitized using sanitize_file_name() before output. |
|
1524 | + * |
|
1525 | + * @see sanitize_file_name() |
|
1526 | + * @since 2.1 |
|
1527 | + * |
|
1528 | + * @param string $filename File name used when downloading a CSV or TSV. Default is "{View title}.csv" or "{View title}.tsv" |
|
1529 | + * @param \GV\View $view Current View being rendered |
|
1530 | + */ |
|
1531 | + $filename = apply_filters('gravityview/output/'.$file_type.'/filename', get_the_title($view->post), $view); |
|
1532 | + |
|
1533 | + if (!defined('DOING_GRAVITYVIEW_TESTS')) { |
|
1534 | + header(sprintf('Content-Disposition: attachment;filename="%s.'.$file_type.'"', sanitize_file_name($filename))); |
|
1535 | + header('Content-Transfer-Encoding: binary'); |
|
1536 | + header('Content-Type: text/'.$file_type); |
|
1537 | + } |
|
1538 | + |
|
1539 | + ob_start(); |
|
1540 | + $csv_or_tsv = fopen('php://output', 'w'); |
|
1541 | + |
|
1542 | + /** |
|
1543 | + * Add da' BOM if GF uses it. |
|
1544 | + * |
|
1545 | + * @see GFExport::start_export() |
|
1546 | + */ |
|
1547 | + if (apply_filters('gform_include_bom_export_entries', true, $view->form ? $view->form->form : null)) { |
|
1548 | + fputs($csv_or_tsv, "\xef\xbb\xbf"); |
|
1549 | + } |
|
1550 | + |
|
1551 | + if ($view->settings->get('csv_nolimit')) { |
|
1552 | + $view->settings->update(['page_size' => -1]); |
|
1553 | + } |
|
1554 | + |
|
1555 | + $entries = $view->get_entries(); |
|
1556 | + |
|
1557 | + $headers_done = false; |
|
1558 | + $allowed = $headers = []; |
|
1559 | + |
|
1560 | + foreach ($view->fields->by_position('directory_*')->by_visible($view)->all() as $id => $field) { |
|
1561 | + $allowed[] = $field; |
|
1562 | + } |
|
1563 | + |
|
1564 | + $renderer = new Field_Renderer(); |
|
1565 | + |
|
1566 | + foreach ($entries->all() as $entry) { |
|
1567 | + $return = []; |
|
1568 | + |
|
1569 | + /** |
|
1570 | + * @filter `gravityview/csv/entry/fields` Allowlist more entry fields by ID that are output in CSV requests. |
|
1571 | + * |
|
1572 | + * @param array $allowed The allowed ones, default by_visible, by_position( "context_*" ), i.e. as set in the View. |
|
1573 | + * @param \GV\View $view The view. |
|
1574 | + * @param \GV\Entry $entry WordPress representation of the item. |
|
1575 | + */ |
|
1576 | + $allowed_field_ids = apply_filters('gravityview/csv/entry/fields', wp_list_pluck($allowed, 'ID'), $view, $entry); |
|
1577 | + |
|
1578 | + $allowed = array_filter($allowed, function ($field) use ($allowed_field_ids) { |
|
1579 | + return in_array($field->ID, $allowed_field_ids, true); |
|
1580 | + }); |
|
1581 | + |
|
1582 | + foreach (array_diff($allowed_field_ids, wp_list_pluck($allowed, 'ID')) as $field_id) { |
|
1583 | + $allowed[] = is_numeric($field_id) ? \GV\GF_Field::by_id($view->form, $field_id) : \GV\Internal_Field::by_id($field_id); |
|
1584 | + } |
|
1585 | + |
|
1586 | + foreach ($allowed as $field) { |
|
1587 | + $source = is_numeric($field->ID) ? $view->form : new \GV\Internal_Source(); |
|
1588 | + |
|
1589 | + $return[] = $renderer->render($field, $view, $source, $entry, gravityview()->request, '\GV\Field_CSV_Template'); |
|
1590 | + |
|
1591 | + if (!$headers_done) { |
|
1592 | + $label = $field->get_label($view, $source, $entry); |
|
1593 | + $headers[] = $label ? $label : $field->ID; |
|
1594 | + } |
|
1595 | + } |
|
1596 | + |
|
1597 | + // If not "tsv" then use comma |
|
1598 | + $delimiter = ('tsv' === $file_type) ? "\t" : ','; |
|
1599 | + |
|
1600 | + if (!$headers_done) { |
|
1601 | + $headers_done = fputcsv($csv_or_tsv, array_map(['\GV\Utils', 'strip_excel_formulas'], array_values($headers)), $delimiter); |
|
1602 | + } |
|
1603 | + |
|
1604 | + fputcsv($csv_or_tsv, array_map(['\GV\Utils', 'strip_excel_formulas'], $return), $delimiter); |
|
1605 | + } |
|
1606 | + |
|
1607 | + fflush($csv_or_tsv); |
|
1608 | + |
|
1609 | + echo rtrim(ob_get_clean()); |
|
1610 | + |
|
1611 | + if (!defined('DOING_GRAVITYVIEW_TESTS')) { |
|
1612 | + exit; |
|
1613 | + } |
|
1614 | + } |
|
1615 | + |
|
1616 | + /** |
|
1617 | + * Return the query class for this View. |
|
1618 | + * |
|
1619 | + * @return string The class name. |
|
1620 | + */ |
|
1621 | + public function get_query_class() |
|
1622 | + { |
|
1623 | + /** |
|
1624 | + * @filter `gravityview/query/class` |
|
1625 | + * |
|
1626 | + * @param string The query class. Default: GF_Query. |
|
1627 | + * @param \GV\View $this The View. |
|
1628 | + */ |
|
1629 | + $query_class = apply_filters('gravityview/query/class', '\GF_Query', $this); |
|
1630 | + |
|
1631 | + return $query_class; |
|
1632 | + } |
|
1633 | + |
|
1634 | + /** |
|
1635 | + * Restrict View access to specific capabilities. |
|
1636 | + * |
|
1637 | + * Hooked into `map_meta_cap` WordPress filter. |
|
1638 | + * |
|
1639 | + * @since develop |
|
1640 | + * |
|
1641 | + * @param $caps array The output capabilities. |
|
1642 | + * @param $cap string The cap that is being checked. |
|
1643 | + * @param $user_id int The User ID. |
|
1644 | + * @param $args array Additional arguments to the capability. |
|
1645 | + * |
|
1646 | + * @return array The resulting capabilities. |
|
1647 | + */ |
|
1648 | + public static function restrict($caps, $cap, $user_id, $args) |
|
1649 | + { |
|
1650 | + /** |
|
1651 | + * @filter `gravityview/security/require_unfiltered_html` Bypass restrictions on Views that require `unfiltered_html`. |
|
1652 | + * |
|
1653 | + * @param bool |
|
1654 | + * |
|
1655 | + * @since develop |
|
1656 | + * |
|
1657 | + * @param string $cap The capability requested. |
|
1658 | + * @param int $user_id The user ID. |
|
1659 | + * @param array $args Any additional args to map_meta_cap |
|
1660 | + */ |
|
1661 | + if (!apply_filters('gravityview/security/require_unfiltered_html', true, $cap, $user_id)) { |
|
1662 | + return $caps; |
|
1663 | + } |
|
1664 | + |
|
1665 | + switch ($cap) { |
|
1666 | + case 'edit_gravityview': |
|
1667 | + case 'edit_gravityviews': |
|
1668 | + case 'edit_others_gravityviews': |
|
1669 | + case 'edit_private_gravityviews': |
|
1670 | + case 'edit_published_gravityviews': |
|
1671 | + if (!user_can($user_id, 'unfiltered_html')) { |
|
1672 | + if (!user_can($user_id, 'gravityview_full_access')) { |
|
1673 | + return ['do_not_allow']; |
|
1674 | + } |
|
1675 | + } |
|
1676 | + |
|
1677 | + return $caps; |
|
1678 | + case 'edit_post': |
|
1679 | + if ('gravityview' === get_post_type(array_pop($args))) { |
|
1680 | + return self::restrict($caps, 'edit_gravityview', $user_id, $args); |
|
1681 | + } |
|
1682 | + } |
|
1683 | + |
|
1684 | + return $caps; |
|
1685 | + } |
|
1686 | + |
|
1687 | + public function __get($key) |
|
1688 | + { |
|
1689 | + if ($this->post) { |
|
1690 | + $raw_post = $this->post->filter('raw'); |
|
1691 | + |
|
1692 | + return $raw_post->{$key}; |
|
1693 | + } |
|
1694 | + |
|
1695 | + return isset($this->{$key}) ? $this->{$key} : null; |
|
1696 | + } |
|
1697 | + |
|
1698 | + /** |
|
1699 | + * Return associated WP post. |
|
1700 | + * |
|
1701 | + * @since 2.13.2 |
|
1702 | + * |
|
1703 | + * @return \WP_Post|null |
|
1704 | + */ |
|
1705 | + public function get_post() |
|
1706 | + { |
|
1707 | + return $this->post ? $this->post : null; |
|
1708 | + } |
|
1709 | 1709 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace GV; |
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | -if (!defined('GRAVITYVIEW_DIR')) { |
|
6 | +if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
7 | 7 | exit(); |
8 | 8 | } |
9 | 9 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @internal |
72 | 72 | */ |
73 | - private static $cache = []; |
|
73 | + private static $cache = [ ]; |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @var \GV\Join[] The joins for all sources in this view. |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @since 2.0.1 |
81 | 81 | */ |
82 | - public $joins = []; |
|
82 | + public $joins = [ ]; |
|
83 | 83 | |
84 | 84 | /** |
85 | 85 | * @var \GV\Field[][] The unions for all sources in this view. |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @since 2.2.2 |
99 | 99 | */ |
100 | - public $unions = []; |
|
100 | + public $unions = [ ]; |
|
101 | 101 | |
102 | 102 | /** |
103 | 103 | * The constructor. |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | |
122 | 122 | /** Register only once */ |
123 | - if (post_type_exists('gravityview')) { |
|
123 | + if ( post_type_exists( 'gravityview' ) ) { |
|
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @param bool $is_hierarchical Default: false |
134 | 134 | */ |
135 | - $is_hierarchical = (bool) apply_filters('gravityview_is_hierarchical', false); |
|
135 | + $is_hierarchical = (bool)apply_filters( 'gravityview_is_hierarchical', false ); |
|
136 | 136 | |
137 | - $supports = ['title', 'revisions']; |
|
137 | + $supports = [ 'title', 'revisions' ]; |
|
138 | 138 | |
139 | - if ($is_hierarchical) { |
|
140 | - $supports[] = 'page-attributes'; |
|
139 | + if ( $is_hierarchical ) { |
|
140 | + $supports[ ] = 'page-attributes'; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
@@ -149,37 +149,37 @@ discard block |
||
149 | 149 | * @param array $supports Array of features associated with a functional area of the edit screen. Default: 'title', 'revisions'. If $is_hierarchical, also 'page-attributes' |
150 | 150 | * @param bool $is_hierarchical Do Views support parent/child relationships? See `gravityview_is_hierarchical` filter. |
151 | 151 | */ |
152 | - $supports = apply_filters('gravityview_post_type_support', $supports, $is_hierarchical); |
|
152 | + $supports = apply_filters( 'gravityview_post_type_support', $supports, $is_hierarchical ); |
|
153 | 153 | |
154 | 154 | /** Register Custom Post Type - gravityview */ |
155 | 155 | $labels = [ |
156 | - 'name' => _x('Views', 'Post Type General Name', 'gravityview'), |
|
157 | - 'singular_name' => _x('View', 'Post Type Singular Name', 'gravityview'), |
|
158 | - 'menu_name' => _x('Views', 'Menu name', 'gravityview'), |
|
159 | - 'parent_item_colon' => __('Parent View:', 'gravityview'), |
|
160 | - 'all_items' => __('All Views', 'gravityview'), |
|
161 | - 'view_item' => _x('View', 'View Item', 'gravityview'), |
|
162 | - 'add_new_item' => __('Add New View', 'gravityview'), |
|
163 | - 'add_new' => __('New View', 'gravityview'), |
|
164 | - 'edit_item' => __('Edit View', 'gravityview'), |
|
165 | - 'update_item' => __('Update View', 'gravityview'), |
|
166 | - 'search_items' => __('Search Views', 'gravityview'), |
|
156 | + 'name' => _x( 'Views', 'Post Type General Name', 'gravityview' ), |
|
157 | + 'singular_name' => _x( 'View', 'Post Type Singular Name', 'gravityview' ), |
|
158 | + 'menu_name' => _x( 'Views', 'Menu name', 'gravityview' ), |
|
159 | + 'parent_item_colon' => __( 'Parent View:', 'gravityview' ), |
|
160 | + 'all_items' => __( 'All Views', 'gravityview' ), |
|
161 | + 'view_item' => _x( 'View', 'View Item', 'gravityview' ), |
|
162 | + 'add_new_item' => __( 'Add New View', 'gravityview' ), |
|
163 | + 'add_new' => __( 'New View', 'gravityview' ), |
|
164 | + 'edit_item' => __( 'Edit View', 'gravityview' ), |
|
165 | + 'update_item' => __( 'Update View', 'gravityview' ), |
|
166 | + 'search_items' => __( 'Search Views', 'gravityview' ), |
|
167 | 167 | 'not_found' => \GravityView_Admin::no_views_text(), |
168 | - 'not_found_in_trash' => __('No Views found in Trash', 'gravityview'), |
|
169 | - 'filter_items_list' => __('Filter Views list', 'gravityview'), |
|
170 | - 'items_list_navigation' => __('Views list navigation', 'gravityview'), |
|
171 | - 'items_list' => __('Views list', 'gravityview'), |
|
172 | - 'view_items' => __('See Views', 'gravityview'), |
|
173 | - 'attributes' => __('View Attributes', 'gravityview'), |
|
174 | - 'item_updated' => __('View updated.', 'gravityview'), |
|
175 | - 'item_published' => __('View published.', 'gravityview'), |
|
176 | - 'item_reverted_to_draft' => __('View reverted to draft.', 'gravityview'), |
|
177 | - 'item_scheduled' => __('View scheduled.', 'gravityview'), |
|
168 | + 'not_found_in_trash' => __( 'No Views found in Trash', 'gravityview' ), |
|
169 | + 'filter_items_list' => __( 'Filter Views list', 'gravityview' ), |
|
170 | + 'items_list_navigation' => __( 'Views list navigation', 'gravityview' ), |
|
171 | + 'items_list' => __( 'Views list', 'gravityview' ), |
|
172 | + 'view_items' => __( 'See Views', 'gravityview' ), |
|
173 | + 'attributes' => __( 'View Attributes', 'gravityview' ), |
|
174 | + 'item_updated' => __( 'View updated.', 'gravityview' ), |
|
175 | + 'item_published' => __( 'View published.', 'gravityview' ), |
|
176 | + 'item_reverted_to_draft' => __( 'View reverted to draft.', 'gravityview' ), |
|
177 | + 'item_scheduled' => __( 'View scheduled.', 'gravityview' ), |
|
178 | 178 | ]; |
179 | 179 | |
180 | 180 | $args = [ |
181 | - 'label' => __('view', 'gravityview'), |
|
182 | - 'description' => __('Create views based on a Gravity Forms form', 'gravityview'), |
|
181 | + 'label' => __( 'view', 'gravityview' ), |
|
182 | + 'description' => __( 'Create views based on a Gravity Forms form', 'gravityview' ), |
|
183 | 183 | 'labels' => $labels, |
184 | 184 | 'supports' => $supports, |
185 | 185 | 'hierarchical' => $is_hierarchical, |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | * @param bool `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded via shortcode. Default: `true` |
193 | 193 | * @param int $view_id The ID of the View currently being requested. `0` for general setting |
194 | 194 | */ |
195 | - 'public' => apply_filters('gravityview_direct_access', gravityview()->plugin->is_compatible(), 0), |
|
195 | + 'public' => apply_filters( 'gravityview_direct_access', gravityview()->plugin->is_compatible(), 0 ), |
|
196 | 196 | 'show_ui' => gravityview()->plugin->is_compatible(), |
197 | 197 | 'show_in_menu' => gravityview()->plugin->is_compatible(), |
198 | 198 | 'show_in_nav_menus' => true, |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @param bool False: don't have frontend archive; True: yes, have archive. Default: false |
209 | 209 | */ |
210 | - 'has_archive' => apply_filters('gravityview_has_archive', false), |
|
210 | + 'has_archive' => apply_filters( 'gravityview_has_archive', false ), |
|
211 | 211 | 'exclude_from_search' => true, |
212 | 212 | 'rewrite' => [ |
213 | 213 | /** |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @param string $slug The slug shown in the URL |
219 | 219 | */ |
220 | - 'slug' => apply_filters('gravityview_slug', 'view'), |
|
220 | + 'slug' => apply_filters( 'gravityview_slug', 'view' ), |
|
221 | 221 | |
222 | 222 | /** |
223 | 223 | * @filter `gravityview/post_type/with_front` Should the permalink structure |
@@ -230,13 +230,13 @@ discard block |
||
230 | 230 | * |
231 | 231 | * @param bool $with_front |
232 | 232 | */ |
233 | - 'with_front' => apply_filters('gravityview/post_type/with_front', true), |
|
233 | + 'with_front' => apply_filters( 'gravityview/post_type/with_front', true ), |
|
234 | 234 | ], |
235 | 235 | 'capability_type' => 'gravityview', |
236 | 236 | 'map_meta_cap' => true, |
237 | 237 | ]; |
238 | 238 | |
239 | - register_post_type('gravityview', $args); |
|
239 | + register_post_type( 'gravityview', $args ); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -251,21 +251,21 @@ discard block |
||
251 | 251 | */ |
252 | 252 | global $wp_rewrite; |
253 | 253 | |
254 | - $slug = apply_filters('gravityview_slug', 'view'); |
|
255 | - $slug = ('/' !== $wp_rewrite->front) ? sprintf('%s/%s', trim($wp_rewrite->front, '/'), $slug) : $slug; |
|
256 | - $csv_rule = [sprintf('%s/([^/]+)/csv/?', $slug), 'index.php?gravityview=$matches[1]&csv=1', 'top']; |
|
257 | - $tsv_rule = [sprintf('%s/([^/]+)/tsv/?', $slug), 'index.php?gravityview=$matches[1]&tsv=1', 'top']; |
|
254 | + $slug = apply_filters( 'gravityview_slug', 'view' ); |
|
255 | + $slug = ( '/' !== $wp_rewrite->front ) ? sprintf( '%s/%s', trim( $wp_rewrite->front, '/' ), $slug ) : $slug; |
|
256 | + $csv_rule = [ sprintf( '%s/([^/]+)/csv/?', $slug ), 'index.php?gravityview=$matches[1]&csv=1', 'top' ]; |
|
257 | + $tsv_rule = [ sprintf( '%s/([^/]+)/tsv/?', $slug ), 'index.php?gravityview=$matches[1]&tsv=1', 'top' ]; |
|
258 | 258 | |
259 | - add_filter('query_vars', function ($query_vars) { |
|
260 | - $query_vars[] = 'csv'; |
|
261 | - $query_vars[] = 'tsv'; |
|
259 | + add_filter( 'query_vars', function( $query_vars ) { |
|
260 | + $query_vars[ ] = 'csv'; |
|
261 | + $query_vars[ ] = 'tsv'; |
|
262 | 262 | |
263 | 263 | return $query_vars; |
264 | 264 | }); |
265 | 265 | |
266 | - if (!isset($wp_rewrite->extra_rules_top[$csv_rule[0]])) { |
|
267 | - call_user_func_array('add_rewrite_rule', $csv_rule); |
|
268 | - call_user_func_array('add_rewrite_rule', $tsv_rule); |
|
266 | + if ( ! isset( $wp_rewrite->extra_rules_top[ $csv_rule[ 0 ] ] ) ) { |
|
267 | + call_user_func_array( 'add_rewrite_rule', $csv_rule ); |
|
268 | + call_user_func_array( 'add_rewrite_rule', $tsv_rule ); |
|
269 | 269 | } |
270 | 270 | } |
271 | 271 | |
@@ -276,20 +276,20 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return string $content The view content as output by the renderers. |
278 | 278 | */ |
279 | - public static function content($content) |
|
279 | + public static function content( $content ) |
|
280 | 280 | { |
281 | 281 | $request = gravityview()->request; |
282 | 282 | |
283 | 283 | // Plugins may run through the content in the header. WP SEO does this for its OpenGraph functionality. |
284 | - if (!defined('DOING_GRAVITYVIEW_TESTS')) { |
|
285 | - if (!did_action('loop_start')) { |
|
286 | - gravityview()->log->debug('Not processing yet: loop_start hasn\'t run yet. Current action: {action}', ['action' => current_filter()]); |
|
284 | + if ( ! defined( 'DOING_GRAVITYVIEW_TESTS' ) ) { |
|
285 | + if ( ! did_action( 'loop_start' ) ) { |
|
286 | + gravityview()->log->debug( 'Not processing yet: loop_start hasn\'t run yet. Current action: {action}', [ 'action' => current_filter() ] ); |
|
287 | 287 | |
288 | 288 | return $content; |
289 | 289 | } |
290 | 290 | |
291 | 291 | // We don't want this filter to run infinite loop on any post content fields |
292 | - remove_filter('the_content', [__CLASS__, __METHOD__]); |
|
292 | + remove_filter( 'the_content', [ __CLASS__, __METHOD__ ] ); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -298,45 +298,45 @@ discard block |
||
298 | 298 | * Shortcodes and oEmbeds and whatnot will be handled |
299 | 299 | * elsewhere. |
300 | 300 | */ |
301 | - if (!$view = $request->is_view()) { |
|
301 | + if ( ! $view = $request->is_view() ) { |
|
302 | 302 | return $content; |
303 | 303 | } |
304 | 304 | |
305 | 305 | /** |
306 | 306 | * Check permissions. |
307 | 307 | */ |
308 | - while ($error = $view->can_render(null, $request)) { |
|
309 | - if (!is_wp_error($error)) { |
|
308 | + while ( $error = $view->can_render( null, $request ) ) { |
|
309 | + if ( ! is_wp_error( $error ) ) { |
|
310 | 310 | break; |
311 | 311 | } |
312 | 312 | |
313 | - switch (str_replace('gravityview/', '', $error->get_error_code())) { |
|
313 | + switch ( str_replace( 'gravityview/', '', $error->get_error_code() ) ) { |
|
314 | 314 | case 'post_password_required': |
315 | - return get_the_password_form($view->ID); |
|
315 | + return get_the_password_form( $view->ID ); |
|
316 | 316 | case 'no_form_attached': |
317 | 317 | |
318 | - gravityview()->log->error('View #{view_id} cannot render: {error_code} {error_message}', ['error_code' => $error->get_error_code(), 'error_message' => $error->get_error_message()]); |
|
318 | + gravityview()->log->error( 'View #{view_id} cannot render: {error_code} {error_message}', [ 'error_code' => $error->get_error_code(), 'error_message' => $error->get_error_message() ] ); |
|
319 | 319 | |
320 | 320 | /** |
321 | 321 | * This View has no data source. There's nothing to show really. |
322 | 322 | * ...apart from a nice message if the user can do anything about it. |
323 | 323 | */ |
324 | - if (\GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview'], $view->ID)) { |
|
325 | - $title = sprintf(__('This View is not configured properly. Start by <a href="%s">selecting a form</a>.', 'gravityview'), esc_url(get_edit_post_link($view->ID, false))); |
|
324 | + if ( \GVCommon::has_cap( [ 'edit_gravityviews', 'edit_gravityview' ], $view->ID ) ) { |
|
325 | + $title = sprintf( __( 'This View is not configured properly. Start by <a href="%s">selecting a form</a>.', 'gravityview' ), esc_url( get_edit_post_link( $view->ID, false ) ) ); |
|
326 | 326 | |
327 | - $message = esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
327 | + $message = esc_html__( 'You can only see this message because you are able to edit this View.', 'gravityview' ); |
|
328 | 328 | |
329 | - $image = sprintf('<img alt="%s" src="%s" style="margin-top: 10px;" />', esc_attr__('Data Source', 'gravityview'), esc_url(plugins_url('assets/images/screenshots/data-source.png', GRAVITYVIEW_FILE))); |
|
329 | + $image = sprintf( '<img alt="%s" src="%s" style="margin-top: 10px;" />', esc_attr__( 'Data Source', 'gravityview' ), esc_url( plugins_url( 'assets/images/screenshots/data-source.png', GRAVITYVIEW_FILE ) ) ); |
|
330 | 330 | |
331 | - return \GVCommon::generate_notice('<h3>'.$title.'</h3>'.wpautop($message.$image), 'notice'); |
|
331 | + return \GVCommon::generate_notice( '<h3>' . $title . '</h3>' . wpautop( $message . $image ), 'notice' ); |
|
332 | 332 | } |
333 | 333 | break; |
334 | 334 | case 'in_trash': |
335 | 335 | |
336 | - if (\GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview'], $view->ID)) { |
|
337 | - $notice = sprintf(__('This View is in the Trash. You can <a href="%s">restore the View here</a>.', 'gravityview'), esc_url(get_edit_post_link($view->ID, false))); |
|
336 | + if ( \GVCommon::has_cap( [ 'edit_gravityviews', 'edit_gravityview' ], $view->ID ) ) { |
|
337 | + $notice = sprintf( __( 'This View is in the Trash. You can <a href="%s">restore the View here</a>.', 'gravityview' ), esc_url( get_edit_post_link( $view->ID, false ) ) ); |
|
338 | 338 | |
339 | - return \GVCommon::generate_notice('<h3>'.$notice.'</h3>', 'notice', ['edit_gravityviews', 'edit_gravityview'], $view->ID); |
|
339 | + return \GVCommon::generate_notice( '<h3>' . $notice . '</h3>', 'notice', [ 'edit_gravityviews', 'edit_gravityview' ], $view->ID ); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | return ''; // Do not show |
@@ -345,88 +345,88 @@ discard block |
||
345 | 345 | case 'embed_only': |
346 | 346 | case 'not_public': |
347 | 347 | default: |
348 | - gravityview()->log->notice('View #{view_id} cannot render: {error_code} {error_message}', ['error_code' => $error->get_error_code(), 'error_message' => $error->get_error_message()]); |
|
348 | + gravityview()->log->notice( 'View #{view_id} cannot render: {error_code} {error_message}', [ 'error_code' => $error->get_error_code(), 'error_message' => $error->get_error_message() ] ); |
|
349 | 349 | |
350 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
350 | + return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | return $content; |
354 | 354 | } |
355 | 355 | |
356 | - $is_admin_and_can_view = $view->settings->get('admin_show_all_statuses') && \GVCommon::has_cap('gravityview_moderate_entries', $view->ID); |
|
356 | + $is_admin_and_can_view = $view->settings->get( 'admin_show_all_statuses' ) && \GVCommon::has_cap( 'gravityview_moderate_entries', $view->ID ); |
|
357 | 357 | |
358 | 358 | /** |
359 | 359 | * Editing a single entry. |
360 | 360 | */ |
361 | - if ($entry = $request->is_edit_entry($view->form ? $view->form->ID : 0)) { |
|
362 | - if ($entry['status'] != 'active') { |
|
363 | - gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $entry->ID]); |
|
361 | + if ( $entry = $request->is_edit_entry( $view->form ? $view->form->ID : 0 ) ) { |
|
362 | + if ( $entry[ 'status' ] != 'active' ) { |
|
363 | + gravityview()->log->notice( 'Entry ID #{entry_id} is not active', [ 'entry_id' => $entry->ID ] ); |
|
364 | 364 | |
365 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
365 | + return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
366 | 366 | } |
367 | 367 | |
368 | - if (apply_filters('gravityview_custom_entry_slug', false) && $entry->slug != get_query_var(\GV\Entry::get_endpoint_name())) { |
|
369 | - gravityview()->log->error('Entry ID #{entry_id} was accessed by a bad slug', ['entry_id' => $entry->ID]); |
|
368 | + if ( apply_filters( 'gravityview_custom_entry_slug', false ) && $entry->slug != get_query_var( \GV\Entry::get_endpoint_name() ) ) { |
|
369 | + gravityview()->log->error( 'Entry ID #{entry_id} was accessed by a bad slug', [ 'entry_id' => $entry->ID ] ); |
|
370 | 370 | |
371 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
371 | + return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
372 | 372 | } |
373 | 373 | |
374 | - if ($view->settings->get('show_only_approved') && !$is_admin_and_can_view) { |
|
375 | - if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($entry->ID, \GravityView_Entry_Approval::meta_key))) { |
|
376 | - gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $entry->ID]); |
|
374 | + if ( $view->settings->get( 'show_only_approved' ) && ! $is_admin_and_can_view ) { |
|
375 | + if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) ) ) { |
|
376 | + gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', [ 'entry_id' => $entry->ID ] ); |
|
377 | 377 | |
378 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
378 | + return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
379 | 379 | } |
380 | 380 | } |
381 | 381 | |
382 | 382 | $renderer = new Edit_Entry_Renderer(); |
383 | 383 | |
384 | - return $renderer->render($entry, $view, $request); |
|
384 | + return $renderer->render( $entry, $view, $request ); |
|
385 | 385 | |
386 | 386 | /** |
387 | 387 | * Viewing a single entry. |
388 | 388 | */ |
389 | - } elseif ($entry = $request->is_entry($view->form ? $view->form->ID : 0)) { |
|
390 | - $entryset = $entry->is_multi() ? $entry->entries : [$entry]; |
|
389 | + } elseif ( $entry = $request->is_entry( $view->form ? $view->form->ID : 0 ) ) { |
|
390 | + $entryset = $entry->is_multi() ? $entry->entries : [ $entry ]; |
|
391 | 391 | |
392 | - $custom_slug = apply_filters('gravityview_custom_entry_slug', false); |
|
393 | - $ids = explode(',', get_query_var(\GV\Entry::get_endpoint_name())); |
|
392 | + $custom_slug = apply_filters( 'gravityview_custom_entry_slug', false ); |
|
393 | + $ids = explode( ',', get_query_var( \GV\Entry::get_endpoint_name() ) ); |
|
394 | 394 | |
395 | - $show_only_approved = $view->settings->get('show_only_approved'); |
|
395 | + $show_only_approved = $view->settings->get( 'show_only_approved' ); |
|
396 | 396 | |
397 | - foreach ($entryset as $e) { |
|
398 | - if ('active' !== $e['status']) { |
|
399 | - gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $e->ID]); |
|
397 | + foreach ( $entryset as $e ) { |
|
398 | + if ( 'active' !== $e[ 'status' ] ) { |
|
399 | + gravityview()->log->notice( 'Entry ID #{entry_id} is not active', [ 'entry_id' => $e->ID ] ); |
|
400 | 400 | |
401 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
401 | + return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
402 | 402 | } |
403 | 403 | |
404 | - if ($custom_slug && !in_array($e->slug, $ids)) { |
|
405 | - gravityview()->log->error('Entry ID #{entry_id} was accessed by a bad slug', ['entry_id' => $e->ID]); |
|
404 | + if ( $custom_slug && ! in_array( $e->slug, $ids ) ) { |
|
405 | + gravityview()->log->error( 'Entry ID #{entry_id} was accessed by a bad slug', [ 'entry_id' => $e->ID ] ); |
|
406 | 406 | |
407 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
407 | + return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
408 | 408 | } |
409 | 409 | |
410 | - if ($show_only_approved && !$is_admin_and_can_view) { |
|
411 | - if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($e->ID, \GravityView_Entry_Approval::meta_key))) { |
|
412 | - gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $e->ID]); |
|
410 | + if ( $show_only_approved && ! $is_admin_and_can_view ) { |
|
411 | + if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $e->ID, \GravityView_Entry_Approval::meta_key ) ) ) { |
|
412 | + gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', [ 'entry_id' => $e->ID ] ); |
|
413 | 413 | |
414 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
414 | + return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
418 | - $error = \GVCommon::check_entry_display($e->as_entry(), $view); |
|
418 | + $error = \GVCommon::check_entry_display( $e->as_entry(), $view ); |
|
419 | 419 | |
420 | - if (is_wp_error($error)) { |
|
421 | - gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing: {message}', ['entry_id' => $e->ID, 'message' => $error->get_error_message()]); |
|
420 | + if ( is_wp_error( $error ) ) { |
|
421 | + gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing: {message}', [ 'entry_id' => $e->ID, 'message' => $error->get_error_message() ] ); |
|
422 | 422 | |
423 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
423 | + return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | 427 | $renderer = new Entry_Renderer(); |
428 | 428 | |
429 | - return $renderer->render($entry, $view, $request); |
|
429 | + return $renderer->render( $entry, $view, $request ); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | */ |
435 | 435 | $renderer = new View_Renderer(); |
436 | 436 | |
437 | - return $renderer->render($view, $request); |
|
437 | + return $renderer->render( $view, $request ); |
|
438 | 438 | } |
439 | 439 | |
440 | 440 | /** |
@@ -452,14 +452,14 @@ discard block |
||
452 | 452 | * |
453 | 453 | * @return bool|\WP_Error An error if this View shouldn't be rendered here. |
454 | 454 | */ |
455 | - public function can_render($context = null, $request = null) |
|
455 | + public function can_render( $context = null, $request = null ) |
|
456 | 456 | { |
457 | - if (!$request) { |
|
457 | + if ( ! $request ) { |
|
458 | 458 | $request = gravityview()->request; |
459 | 459 | } |
460 | 460 | |
461 | - if (!is_array($context)) { |
|
462 | - $context = []; |
|
461 | + if ( ! is_array( $context ) ) { |
|
462 | + $context = [ ]; |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
@@ -470,41 +470,41 @@ discard block |
||
470 | 470 | * @param string[] $context See \GV\View::can_render |
471 | 471 | * @param \GV\Request $request The request. |
472 | 472 | */ |
473 | - if (!is_null($result = apply_filters('gravityview/view/can_render', null, $this, $context, $request))) { |
|
473 | + if ( ! is_null( $result = apply_filters( 'gravityview/view/can_render', null, $this, $context, $request ) ) ) { |
|
474 | 474 | return $result; |
475 | 475 | } |
476 | 476 | |
477 | - if (in_array('rest', $context)) { |
|
477 | + if ( in_array( 'rest', $context ) ) { |
|
478 | 478 | // REST |
479 | - if (gravityview()->plugin->settings->get('rest_api') === '1' && $this->settings->get('rest_disable') === '1') { |
|
480 | - return new \WP_Error('gravityview/rest_disabled'); |
|
481 | - } elseif (gravityview()->plugin->settings->get('rest_api') !== '1' && $this->settings->get('rest_enable') !== '1') { |
|
482 | - return new \WP_Error('gravityview/rest_disabled'); |
|
479 | + if ( gravityview()->plugin->settings->get( 'rest_api' ) === '1' && $this->settings->get( 'rest_disable' ) === '1' ) { |
|
480 | + return new \WP_Error( 'gravityview/rest_disabled' ); |
|
481 | + } elseif ( gravityview()->plugin->settings->get( 'rest_api' ) !== '1' && $this->settings->get( 'rest_enable' ) !== '1' ) { |
|
482 | + return new \WP_Error( 'gravityview/rest_disabled' ); |
|
483 | 483 | } |
484 | 484 | } |
485 | 485 | |
486 | - if (in_array('csv', $context)) { |
|
487 | - if ($this->settings->get('csv_enable') !== '1') { |
|
488 | - return new \WP_Error('gravityview/csv_disabled', 'The CSV endpoint is not enabled for this View'); |
|
486 | + if ( in_array( 'csv', $context ) ) { |
|
487 | + if ( $this->settings->get( 'csv_enable' ) !== '1' ) { |
|
488 | + return new \WP_Error( 'gravityview/csv_disabled', 'The CSV endpoint is not enabled for this View' ); |
|
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
492 | 492 | /** |
493 | 493 | * This View is password protected. Nothing to do here. |
494 | 494 | */ |
495 | - if (post_password_required($this->ID)) { |
|
496 | - gravityview()->log->notice('Post password is required for View #{view_id}', ['view_id' => $this->ID]); |
|
495 | + if ( post_password_required( $this->ID ) ) { |
|
496 | + gravityview()->log->notice( 'Post password is required for View #{view_id}', [ 'view_id' => $this->ID ] ); |
|
497 | 497 | |
498 | - return new \WP_Error('gravityview/post_password_required'); |
|
498 | + return new \WP_Error( 'gravityview/post_password_required' ); |
|
499 | 499 | } |
500 | 500 | |
501 | - if (!$this->form) { |
|
502 | - gravityview()->log->notice('View #{id} has no form attached to it.', ['id' => $this->ID]); |
|
501 | + if ( ! $this->form ) { |
|
502 | + gravityview()->log->notice( 'View #{id} has no form attached to it.', [ 'id' => $this->ID ] ); |
|
503 | 503 | |
504 | - return new \WP_Error('gravityview/no_form_attached'); |
|
504 | + return new \WP_Error( 'gravityview/no_form_attached' ); |
|
505 | 505 | } |
506 | 506 | |
507 | - if (!in_array('shortcode', $context)) { |
|
507 | + if ( ! in_array( 'shortcode', $context ) ) { |
|
508 | 508 | /** |
509 | 509 | * Is this View directly accessible via a post URL? |
510 | 510 | * |
@@ -519,7 +519,7 @@ discard block |
||
519 | 519 | * @param bool `true`: allow Views to be accessible directly. `false`: Only allow Views to be embedded. Default: `true` |
520 | 520 | * @param int $view_id The ID of the View currently being requested. `0` for general setting |
521 | 521 | */ |
522 | - $direct_access = apply_filters('gravityview_direct_access', true, $this->ID); |
|
522 | + $direct_access = apply_filters( 'gravityview_direct_access', true, $this->ID ); |
|
523 | 523 | |
524 | 524 | /** |
525 | 525 | * @filter `gravityview/request/output/direct` Should this View be directly accessbile? |
@@ -530,25 +530,25 @@ discard block |
||
530 | 530 | * @param \GV\View $view The View we're trying to directly render here. |
531 | 531 | * @param \GV\Request $request The current request. |
532 | 532 | */ |
533 | - if (!apply_filters('gravityview/view/output/direct', $direct_access, $this, $request)) { |
|
534 | - return new \WP_Error('gravityview/no_direct_access'); |
|
533 | + if ( ! apply_filters( 'gravityview/view/output/direct', $direct_access, $this, $request ) ) { |
|
534 | + return new \WP_Error( 'gravityview/no_direct_access' ); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | /** |
538 | 538 | * Is this View an embed-only View? If so, don't allow rendering here, |
539 | 539 | * as this is a direct request. |
540 | 540 | */ |
541 | - if ($this->settings->get('embed_only') && !\GVCommon::has_cap('read_private_gravityviews')) { |
|
542 | - return new \WP_Error('gravityview/embed_only'); |
|
541 | + if ( $this->settings->get( 'embed_only' ) && ! \GVCommon::has_cap( 'read_private_gravityviews' ) ) { |
|
542 | + return new \WP_Error( 'gravityview/embed_only' ); |
|
543 | 543 | } |
544 | 544 | } |
545 | 545 | |
546 | 546 | /** Private, pending, draft, etc. */ |
547 | - $public_states = get_post_stati(['public' => true]); |
|
548 | - if (!in_array($this->post_status, $public_states) && !\GVCommon::has_cap('read_gravityview', $this->ID)) { |
|
549 | - gravityview()->log->notice('The current user cannot access this View #{view_id}', ['view_id' => $this->ID]); |
|
547 | + $public_states = get_post_stati( [ 'public' => true ] ); |
|
548 | + if ( ! in_array( $this->post_status, $public_states ) && ! \GVCommon::has_cap( 'read_gravityview', $this->ID ) ) { |
|
549 | + gravityview()->log->notice( 'The current user cannot access this View #{view_id}', [ 'view_id' => $this->ID ] ); |
|
550 | 550 | |
551 | - return new \WP_Error('gravityview/not_public'); |
|
551 | + return new \WP_Error( 'gravityview/not_public' ); |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | return true; |
@@ -565,42 +565,42 @@ discard block |
||
565 | 565 | * |
566 | 566 | * @return \GV\Join[] Array of \GV\Join instances |
567 | 567 | */ |
568 | - public static function get_joins($post) |
|
568 | + public static function get_joins( $post ) |
|
569 | 569 | { |
570 | - $joins = []; |
|
570 | + $joins = [ ]; |
|
571 | 571 | |
572 | - if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
573 | - gravityview()->log->info('Cannot get joined forms; joins feature not supported.'); |
|
572 | + if ( ! gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) ) { |
|
573 | + gravityview()->log->info( 'Cannot get joined forms; joins feature not supported.' ); |
|
574 | 574 | |
575 | 575 | return $joins; |
576 | 576 | } |
577 | 577 | |
578 | - if (!$post || 'gravityview' !== get_post_type($post)) { |
|
579 | - gravityview()->log->error('Only "gravityview" post types can be \GV\View instances.'); |
|
578 | + if ( ! $post || 'gravityview' !== get_post_type( $post ) ) { |
|
579 | + gravityview()->log->error( 'Only "gravityview" post types can be \GV\View instances.' ); |
|
580 | 580 | |
581 | 581 | return $joins; |
582 | 582 | } |
583 | 583 | |
584 | - $joins_meta = get_post_meta($post->ID, '_gravityview_form_joins', true); |
|
584 | + $joins_meta = get_post_meta( $post->ID, '_gravityview_form_joins', true ); |
|
585 | 585 | |
586 | - if (empty($joins_meta)) { |
|
586 | + if ( empty( $joins_meta ) ) { |
|
587 | 587 | return $joins; |
588 | 588 | } |
589 | 589 | |
590 | - foreach ($joins_meta as $meta) { |
|
591 | - if (!is_array($meta) || count($meta) != 4) { |
|
590 | + foreach ( $joins_meta as $meta ) { |
|
591 | + if ( ! is_array( $meta ) || count( $meta ) != 4 ) { |
|
592 | 592 | continue; |
593 | 593 | } |
594 | 594 | |
595 | - list($join, $join_column, $join_on, $join_on_column) = $meta; |
|
595 | + list( $join, $join_column, $join_on, $join_on_column ) = $meta; |
|
596 | 596 | |
597 | - $join = GF_Form::by_id($join); |
|
598 | - $join_on = GF_Form::by_id($join_on); |
|
597 | + $join = GF_Form::by_id( $join ); |
|
598 | + $join_on = GF_Form::by_id( $join_on ); |
|
599 | 599 | |
600 | - $join_column = is_numeric($join_column) ? GF_Field::by_id($join, $join_column) : Internal_Field::by_id($join_column); |
|
601 | - $join_on_column = is_numeric($join_on_column) ? GF_Field::by_id($join_on, $join_on_column) : Internal_Field::by_id($join_on_column); |
|
600 | + $join_column = is_numeric( $join_column ) ? GF_Field::by_id( $join, $join_column ) : Internal_Field::by_id( $join_column ); |
|
601 | + $join_on_column = is_numeric( $join_on_column ) ? GF_Field::by_id( $join_on, $join_on_column ) : Internal_Field::by_id( $join_on_column ); |
|
602 | 602 | |
603 | - $joins[] = new Join($join, $join_column, $join_on, $join_on_column); |
|
603 | + $joins[ ] = new Join( $join, $join_column, $join_on, $join_on_column ); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | return $joins; |
@@ -620,45 +620,45 @@ discard block |
||
620 | 620 | * |
621 | 621 | * @return \GV\GF_Form[] Array of \GV\GF_Form instances |
622 | 622 | */ |
623 | - public static function get_joined_forms($post_id) |
|
623 | + public static function get_joined_forms( $post_id ) |
|
624 | 624 | { |
625 | - $forms = []; |
|
625 | + $forms = [ ]; |
|
626 | 626 | |
627 | - if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
628 | - gravityview()->log->info('Cannot get joined forms; joins feature not supported.'); |
|
627 | + if ( ! gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) ) { |
|
628 | + gravityview()->log->info( 'Cannot get joined forms; joins feature not supported.' ); |
|
629 | 629 | |
630 | 630 | return $forms; |
631 | 631 | } |
632 | 632 | |
633 | - if (!$post_id || !gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
633 | + if ( ! $post_id || ! gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) ) { |
|
634 | 634 | return $forms; |
635 | 635 | } |
636 | 636 | |
637 | - if (empty($post_id)) { |
|
638 | - gravityview()->log->error('Cannot get joined forms; $post_id was empty'); |
|
637 | + if ( empty( $post_id ) ) { |
|
638 | + gravityview()->log->error( 'Cannot get joined forms; $post_id was empty' ); |
|
639 | 639 | |
640 | 640 | return $forms; |
641 | 641 | } |
642 | 642 | |
643 | - $joins_meta = get_post_meta($post_id, '_gravityview_form_joins', true); |
|
643 | + $joins_meta = get_post_meta( $post_id, '_gravityview_form_joins', true ); |
|
644 | 644 | |
645 | - if (empty($joins_meta)) { |
|
645 | + if ( empty( $joins_meta ) ) { |
|
646 | 646 | return $forms; |
647 | 647 | } |
648 | 648 | |
649 | - foreach ($joins_meta as $meta) { |
|
650 | - if (!is_array($meta) || count($meta) != 4) { |
|
649 | + foreach ( $joins_meta as $meta ) { |
|
650 | + if ( ! is_array( $meta ) || count( $meta ) != 4 ) { |
|
651 | 651 | continue; |
652 | 652 | } |
653 | 653 | |
654 | - list($join, $join_column, $join_on, $join_on_column) = $meta; |
|
654 | + list( $join, $join_column, $join_on, $join_on_column ) = $meta; |
|
655 | 655 | |
656 | - if ($form = GF_Form::by_id($join_on)) { |
|
657 | - $forms[$join_on] = $form; |
|
656 | + if ( $form = GF_Form::by_id( $join_on ) ) { |
|
657 | + $forms[ $join_on ] = $form; |
|
658 | 658 | } |
659 | 659 | |
660 | - if ($form = GF_Form::by_id($join)) { |
|
661 | - $forms[$join] = $form; |
|
660 | + if ( $form = GF_Form::by_id( $join ) ) { |
|
661 | + $forms[ $join ] = $form; |
|
662 | 662 | } |
663 | 663 | } |
664 | 664 | |
@@ -676,36 +676,36 @@ discard block |
||
676 | 676 | * |
677 | 677 | * @return \GV\Field[][] Array of unions (see self::$unions) |
678 | 678 | */ |
679 | - public static function get_unions($post) |
|
679 | + public static function get_unions( $post ) |
|
680 | 680 | { |
681 | - $unions = []; |
|
681 | + $unions = [ ]; |
|
682 | 682 | |
683 | - if (!$post || 'gravityview' !== get_post_type($post)) { |
|
684 | - gravityview()->log->error('Only "gravityview" post types can be \GV\View instances.'); |
|
683 | + if ( ! $post || 'gravityview' !== get_post_type( $post ) ) { |
|
684 | + gravityview()->log->error( 'Only "gravityview" post types can be \GV\View instances.' ); |
|
685 | 685 | |
686 | 686 | return $unions; |
687 | 687 | } |
688 | 688 | |
689 | - $fields = get_post_meta($post->ID, '_gravityview_directory_fields', true); |
|
689 | + $fields = get_post_meta( $post->ID, '_gravityview_directory_fields', true ); |
|
690 | 690 | |
691 | - if (empty($fields)) { |
|
691 | + if ( empty( $fields ) ) { |
|
692 | 692 | return $unions; |
693 | 693 | } |
694 | 694 | |
695 | - foreach ($fields as $location => $_fields) { |
|
696 | - if (strpos($location, 'directory_') !== 0) { |
|
695 | + foreach ( $fields as $location => $_fields ) { |
|
696 | + if ( strpos( $location, 'directory_' ) !== 0 ) { |
|
697 | 697 | continue; |
698 | 698 | } |
699 | 699 | |
700 | - foreach ($_fields as $field) { |
|
701 | - if (!empty($field['unions'])) { |
|
702 | - foreach ($field['unions'] as $form_id => $field_id) { |
|
703 | - if (!isset($unions[$form_id])) { |
|
704 | - $unions[$form_id] = []; |
|
700 | + foreach ( $_fields as $field ) { |
|
701 | + if ( ! empty( $field[ 'unions' ] ) ) { |
|
702 | + foreach ( $field[ 'unions' ] as $form_id => $field_id ) { |
|
703 | + if ( ! isset( $unions[ $form_id ] ) ) { |
|
704 | + $unions[ $form_id ] = [ ]; |
|
705 | 705 | } |
706 | 706 | |
707 | - $unions[$form_id][$field['id']] = |
|
708 | - is_numeric($field_id) ? \GV\GF_Field::by_id(\GV\GF_Form::by_id($form_id), $field_id) : \GV\Internal_Field::by_id($field_id); |
|
707 | + $unions[ $form_id ][ $field[ 'id' ] ] = |
|
708 | + is_numeric( $field_id ) ? \GV\GF_Field::by_id( \GV\GF_Form::by_id( $form_id ), $field_id ) : \GV\Internal_Field::by_id( $field_id ); |
|
709 | 709 | } |
710 | 710 | } |
711 | 711 | } |
@@ -713,9 +713,9 @@ discard block |
||
713 | 713 | break; |
714 | 714 | } |
715 | 715 | |
716 | - if ($unions) { |
|
717 | - if (!gravityview()->plugin->supports(Plugin::FEATURE_UNIONS)) { |
|
718 | - gravityview()->log->error('Cannot get unions; unions feature not supported.'); |
|
716 | + if ( $unions ) { |
|
717 | + if ( ! gravityview()->plugin->supports( Plugin::FEATURE_UNIONS ) ) { |
|
718 | + gravityview()->log->error( 'Cannot get unions; unions feature not supported.' ); |
|
719 | 719 | } |
720 | 720 | } |
721 | 721 | |
@@ -735,15 +735,15 @@ discard block |
||
735 | 735 | * |
736 | 736 | * @return \GV\View|null An instance around this \WP_Post if valid, null otherwise. |
737 | 737 | */ |
738 | - public static function from_post($post) |
|
738 | + public static function from_post( $post ) |
|
739 | 739 | { |
740 | - if (!$post || 'gravityview' !== get_post_type($post)) { |
|
741 | - gravityview()->log->error('Only gravityview post types can be \GV\View instances.'); |
|
740 | + if ( ! $post || 'gravityview' !== get_post_type( $post ) ) { |
|
741 | + gravityview()->log->error( 'Only gravityview post types can be \GV\View instances.' ); |
|
742 | 742 | |
743 | 743 | return null; |
744 | 744 | } |
745 | 745 | |
746 | - if ($view = Utils::get(self::$cache, "View::from_post:{$post->ID}")) { |
|
746 | + if ( $view = Utils::get( self::$cache, "View::from_post:{$post->ID}" ) ) { |
|
747 | 747 | /** |
748 | 748 | * @filter `gravityview/view/get` Override View. |
749 | 749 | * |
@@ -751,7 +751,7 @@ discard block |
||
751 | 751 | * |
752 | 752 | * @since 2.1 |
753 | 753 | */ |
754 | - do_action_ref_array('gravityview/view/get', [&$view]); |
|
754 | + do_action_ref_array( 'gravityview/view/get', [ &$view ] ); |
|
755 | 755 | |
756 | 756 | return $view; |
757 | 757 | } |
@@ -760,17 +760,17 @@ discard block |
||
760 | 760 | $view->post = $post; |
761 | 761 | |
762 | 762 | /** Get connected form. */ |
763 | - $view->form = GF_Form::by_id($view->_gravityview_form_id); |
|
764 | - if (!$view->form) { |
|
765 | - gravityview()->log->error('View #{view_id} tried attaching non-existent Form #{form_id} to it.', [ |
|
763 | + $view->form = GF_Form::by_id( $view->_gravityview_form_id ); |
|
764 | + if ( ! $view->form ) { |
|
765 | + gravityview()->log->error( 'View #{view_id} tried attaching non-existent Form #{form_id} to it.', [ |
|
766 | 766 | 'view_id' => $view->ID, |
767 | 767 | 'form_id' => $view->_gravityview_form_id ?: 0, |
768 | - ]); |
|
768 | + ] ); |
|
769 | 769 | } |
770 | 770 | |
771 | - $view->joins = $view::get_joins($post); |
|
771 | + $view->joins = $view::get_joins( $post ); |
|
772 | 772 | |
773 | - $view->unions = $view::get_unions($post); |
|
773 | + $view->unions = $view::get_unions( $post ); |
|
774 | 774 | |
775 | 775 | /** |
776 | 776 | * @filter `gravityview/configuration/fields` Filter the View fields' configuration array. |
@@ -781,7 +781,7 @@ discard block |
||
781 | 781 | * @param $fields array Multi-array of fields with first level being the field zones. |
782 | 782 | * @param $view_id int The View the fields are being pulled for. |
783 | 783 | */ |
784 | - $configuration = apply_filters('gravityview/configuration/fields', (array) $view->_gravityview_directory_fields, $view->ID); |
|
784 | + $configuration = apply_filters( 'gravityview/configuration/fields', (array)$view->_gravityview_directory_fields, $view->ID ); |
|
785 | 785 | |
786 | 786 | /** |
787 | 787 | * @filter `gravityview/view/configuration/fields` Filter the View fields' configuration array. |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | * @param array $fields Multi-array of fields with first level being the field zones. |
792 | 792 | * @param \GV\View $view The View the fields are being pulled for. |
793 | 793 | */ |
794 | - $configuration = apply_filters('gravityview/view/configuration/fields', $configuration, $view); |
|
794 | + $configuration = apply_filters( 'gravityview/view/configuration/fields', $configuration, $view ); |
|
795 | 795 | |
796 | 796 | /** |
797 | 797 | * @filter `gravityview/view/fields` Filter the Field Collection for this View. |
@@ -801,7 +801,7 @@ discard block |
||
801 | 801 | * @param \GV\Field_Collection $fields A collection of fields. |
802 | 802 | * @param \GV\View $view The View the fields are being pulled for. |
803 | 803 | */ |
804 | - $view->fields = apply_filters('gravityview/view/fields', Field_Collection::from_configuration($configuration), $view); |
|
804 | + $view->fields = apply_filters( 'gravityview/view/fields', Field_Collection::from_configuration( $configuration ), $view ); |
|
805 | 805 | |
806 | 806 | /** |
807 | 807 | * @filter `gravityview/view/configuration/widgets` Filter the View widgets' configuration array. |
@@ -811,7 +811,7 @@ discard block |
||
811 | 811 | * @param array $fields Multi-array of widgets with first level being the field zones. |
812 | 812 | * @param \GV\View $view The View the widgets are being pulled for. |
813 | 813 | */ |
814 | - $configuration = apply_filters('gravityview/view/configuration/widgets', (array) $view->_gravityview_directory_widgets, $view); |
|
814 | + $configuration = apply_filters( 'gravityview/view/configuration/widgets', (array)$view->_gravityview_directory_widgets, $view ); |
|
815 | 815 | |
816 | 816 | /** |
817 | 817 | * @filter `gravityview/view/widgets` Filter the Widget Collection for this View. |
@@ -821,20 +821,20 @@ discard block |
||
821 | 821 | * @param \GV\Widget_Collection $widgets A collection of widgets. |
822 | 822 | * @param \GV\View $view The View the widgets are being pulled for. |
823 | 823 | */ |
824 | - $view->widgets = apply_filters('gravityview/view/widgets', Widget_Collection::from_configuration($configuration), $view); |
|
824 | + $view->widgets = apply_filters( 'gravityview/view/widgets', Widget_Collection::from_configuration( $configuration ), $view ); |
|
825 | 825 | |
826 | 826 | /** View configuration. */ |
827 | - $view->settings->update(gravityview_get_template_settings($view->ID)); |
|
827 | + $view->settings->update( gravityview_get_template_settings( $view->ID ) ); |
|
828 | 828 | |
829 | 829 | /** Add the template name into the settings. */ |
830 | - $view->settings->update(['template' => gravityview_get_template_id($view->ID)]); |
|
830 | + $view->settings->update( [ 'template' => gravityview_get_template_id( $view->ID ) ] ); |
|
831 | 831 | |
832 | 832 | /** View basics. */ |
833 | - $view->settings->update([ |
|
833 | + $view->settings->update( [ |
|
834 | 834 | 'id' => $view->ID, |
835 | - ]); |
|
835 | + ] ); |
|
836 | 836 | |
837 | - self::$cache["View::from_post:{$post->ID}"] = &$view; |
|
837 | + self::$cache[ "View::from_post:{$post->ID}" ] = &$view; |
|
838 | 838 | |
839 | 839 | /** |
840 | 840 | * @filter `gravityview/view/get` Override View. |
@@ -843,7 +843,7 @@ discard block |
||
843 | 843 | * |
844 | 844 | * @since 2.1 |
845 | 845 | */ |
846 | - do_action_ref_array('gravityview/view/get', [&$view]); |
|
846 | + do_action_ref_array( 'gravityview/view/get', [ &$view ] ); |
|
847 | 847 | |
848 | 848 | return $view; |
849 | 849 | } |
@@ -855,14 +855,14 @@ discard block |
||
855 | 855 | * |
856 | 856 | * @internal |
857 | 857 | */ |
858 | - public static function _flush_cache($view_id = null) |
|
858 | + public static function _flush_cache( $view_id = null ) |
|
859 | 859 | { |
860 | - if ($view_id) { |
|
861 | - unset(self::$cache["View::from_post:$view_id"]); |
|
860 | + if ( $view_id ) { |
|
861 | + unset( self::$cache[ "View::from_post:$view_id" ] ); |
|
862 | 862 | |
863 | 863 | return; |
864 | 864 | } |
865 | - self::$cache = []; |
|
865 | + self::$cache = [ ]; |
|
866 | 866 | } |
867 | 867 | |
868 | 868 | /** |
@@ -876,13 +876,13 @@ discard block |
||
876 | 876 | * |
877 | 877 | * @return \GV\View|null An instance around this \WP_Post or null if not found. |
878 | 878 | */ |
879 | - public static function by_id($post_id) |
|
879 | + public static function by_id( $post_id ) |
|
880 | 880 | { |
881 | - if (!$post_id || !$post = get_post($post_id)) { |
|
881 | + if ( ! $post_id || ! $post = get_post( $post_id ) ) { |
|
882 | 882 | return null; |
883 | 883 | } |
884 | 884 | |
885 | - return self::from_post($post); |
|
885 | + return self::from_post( $post ); |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | /** |
@@ -896,9 +896,9 @@ discard block |
||
896 | 896 | * |
897 | 897 | * @return bool Whether the post exists or not. |
898 | 898 | */ |
899 | - public static function exists($view) |
|
899 | + public static function exists( $view ) |
|
900 | 900 | { |
901 | - return get_post_type($view) == 'gravityview'; |
|
901 | + return get_post_type( $view ) == 'gravityview'; |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | /** |
@@ -911,11 +911,11 @@ discard block |
||
911 | 911 | * |
912 | 912 | * @return bool Whether the offset exists or not, limited to GravityView_View_Data::$views element keys. |
913 | 913 | */ |
914 | - public function offsetExists($offset) |
|
914 | + public function offsetExists( $offset ) |
|
915 | 915 | { |
916 | - $data_keys = ['id', 'view_id', 'form_id', 'template_id', 'atts', 'fields', 'widgets', 'form']; |
|
916 | + $data_keys = [ 'id', 'view_id', 'form_id', 'template_id', 'atts', 'fields', 'widgets', 'form' ]; |
|
917 | 917 | |
918 | - return in_array($offset, $data_keys); |
|
918 | + return in_array( $offset, $data_keys ); |
|
919 | 919 | } |
920 | 920 | |
921 | 921 | /** |
@@ -930,15 +930,15 @@ discard block |
||
930 | 930 | * |
931 | 931 | * @return mixed The value of the requested view data key limited to GravityView_View_Data::$views element keys. If offset not found, return null. |
932 | 932 | */ |
933 | - public function offsetGet($offset) |
|
933 | + public function offsetGet( $offset ) |
|
934 | 934 | { |
935 | - gravityview()->log->notice('This is a \GV\View object should not be accessed as an array.'); |
|
935 | + gravityview()->log->notice( 'This is a \GV\View object should not be accessed as an array.' ); |
|
936 | 936 | |
937 | - if (!isset($this[$offset])) { |
|
937 | + if ( ! isset( $this[ $offset ] ) ) { |
|
938 | 938 | return null; |
939 | 939 | } |
940 | 940 | |
941 | - switch ($offset) { |
|
941 | + switch ( $offset ) { |
|
942 | 942 | case 'id': |
943 | 943 | case 'view_id': |
944 | 944 | return $this->ID; |
@@ -949,7 +949,7 @@ discard block |
||
949 | 949 | case 'atts': |
950 | 950 | return $this->settings->as_atts(); |
951 | 951 | case 'template_id': |
952 | - return $this->settings->get('template'); |
|
952 | + return $this->settings->get( 'template' ); |
|
953 | 953 | case 'widgets': |
954 | 954 | return $this->widgets->as_configuration(); |
955 | 955 | } |
@@ -967,9 +967,9 @@ discard block |
||
967 | 967 | * |
968 | 968 | * @return void |
969 | 969 | */ |
970 | - public function offsetSet($offset, $value) |
|
970 | + public function offsetSet( $offset, $value ) |
|
971 | 971 | { |
972 | - gravityview()->log->error('The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.'); |
|
972 | + gravityview()->log->error( 'The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.' ); |
|
973 | 973 | } |
974 | 974 | |
975 | 975 | /** |
@@ -982,9 +982,9 @@ discard block |
||
982 | 982 | * |
983 | 983 | * @return void |
984 | 984 | */ |
985 | - public function offsetUnset($offset) |
|
985 | + public function offsetUnset( $offset ) |
|
986 | 986 | { |
987 | - gravityview()->log->error('The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.'); |
|
987 | + gravityview()->log->error( 'The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.' ); |
|
988 | 988 | } |
989 | 989 | |
990 | 990 | /** |
@@ -1007,10 +1007,10 @@ discard block |
||
1007 | 1007 | 'id' => $this->ID, |
1008 | 1008 | 'view_id' => $this->ID, |
1009 | 1009 | 'form_id' => $this->form ? $this->form->ID : null, |
1010 | - 'form' => $this->form ? gravityview_get_form($this->form->ID) : null, |
|
1010 | + 'form' => $this->form ? gravityview_get_form( $this->form->ID ) : null, |
|
1011 | 1011 | 'atts' => $this->settings->as_atts(), |
1012 | - 'fields' => $this->fields->by_visible($this)->as_configuration(), |
|
1013 | - 'template_id' => $this->settings->get('template'), |
|
1012 | + 'fields' => $this->fields->by_visible( $this )->as_configuration(), |
|
1013 | + 'template_id' => $this->settings->get( 'template' ), |
|
1014 | 1014 | 'widgets' => $this->widgets->as_configuration(), |
1015 | 1015 | ]; |
1016 | 1016 | } |
@@ -1022,13 +1022,13 @@ discard block |
||
1022 | 1022 | * |
1023 | 1023 | * @return \GV\Entry_Collection The entries. |
1024 | 1024 | */ |
1025 | - public function get_entries($request = null) |
|
1025 | + public function get_entries( $request = null ) |
|
1026 | 1026 | { |
1027 | 1027 | $entries = new \GV\Entry_Collection(); |
1028 | 1028 | |
1029 | - if (!$this->form) { |
|
1029 | + if ( ! $this->form ) { |
|
1030 | 1030 | // Documented below. |
1031 | - return apply_filters('gravityview/view/entries', $entries, $this, $request); |
|
1031 | + return apply_filters( 'gravityview/view/entries', $entries, $this, $request ); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | $parameters = $this->settings->as_atts(); |
@@ -1037,85 +1037,85 @@ discard block |
||
1037 | 1037 | * Remove multiple sorting before calling legacy filters. |
1038 | 1038 | * This allows us to fake it till we make it. |
1039 | 1039 | */ |
1040 | - if (!empty($parameters['sort_field']) && is_array($parameters['sort_field'])) { |
|
1040 | + if ( ! empty( $parameters[ 'sort_field' ] ) && is_array( $parameters[ 'sort_field' ] ) ) { |
|
1041 | 1041 | $has_multisort = true; |
1042 | - $parameters['sort_field'] = reset($parameters['sort_field']); |
|
1043 | - if (!empty($parameters['sort_direction']) && is_array($parameters['sort_direction'])) { |
|
1044 | - $parameters['sort_direction'] = reset($parameters['sort_direction']); |
|
1042 | + $parameters[ 'sort_field' ] = reset( $parameters[ 'sort_field' ] ); |
|
1043 | + if ( ! empty( $parameters[ 'sort_direction' ] ) && is_array( $parameters[ 'sort_direction' ] ) ) { |
|
1044 | + $parameters[ 'sort_direction' ] = reset( $parameters[ 'sort_direction' ] ); |
|
1045 | 1045 | } |
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | /** |
1049 | 1049 | * @todo: Stop using _frontend and use something like $request->get_search_criteria() instead |
1050 | 1050 | */ |
1051 | - $parameters = \GravityView_frontend::get_view_entries_parameters($parameters, $this->form->ID); |
|
1051 | + $parameters = \GravityView_frontend::get_view_entries_parameters( $parameters, $this->form->ID ); |
|
1052 | 1052 | |
1053 | - $parameters['context_view_id'] = $this->ID; |
|
1054 | - $parameters = \GVCommon::calculate_get_entries_criteria($parameters, $this->form->ID); |
|
1053 | + $parameters[ 'context_view_id' ] = $this->ID; |
|
1054 | + $parameters = \GVCommon::calculate_get_entries_criteria( $parameters, $this->form->ID ); |
|
1055 | 1055 | |
1056 | - if (!is_array($parameters)) { |
|
1057 | - $parameters = []; |
|
1056 | + if ( ! is_array( $parameters ) ) { |
|
1057 | + $parameters = [ ]; |
|
1058 | 1058 | } |
1059 | 1059 | |
1060 | - if (!is_array($parameters['search_criteria'])) { |
|
1061 | - $parameters['search_criteria'] = []; |
|
1060 | + if ( ! is_array( $parameters[ 'search_criteria' ] ) ) { |
|
1061 | + $parameters[ 'search_criteria' ] = [ ]; |
|
1062 | 1062 | } |
1063 | 1063 | |
1064 | - if ((!isset($parameters['search_criteria']['field_filters'])) || (!is_array($parameters['search_criteria']['field_filters']))) { |
|
1065 | - $parameters['search_criteria']['field_filters'] = []; |
|
1064 | + if ( ( ! isset( $parameters[ 'search_criteria' ][ 'field_filters' ] ) ) || ( ! is_array( $parameters[ 'search_criteria' ][ 'field_filters' ] ) ) ) { |
|
1065 | + $parameters[ 'search_criteria' ][ 'field_filters' ] = [ ]; |
|
1066 | 1066 | } |
1067 | 1067 | |
1068 | - if ($request instanceof REST\Request) { |
|
1068 | + if ( $request instanceof REST\Request ) { |
|
1069 | 1069 | $atts = $this->settings->as_atts(); |
1070 | - $paging_parameters = wp_parse_args($request->get_paging(), [ |
|
1071 | - 'paging' => ['page_size' => $atts['page_size']], |
|
1072 | - ]); |
|
1073 | - $parameters['paging'] = $paging_parameters['paging']; |
|
1070 | + $paging_parameters = wp_parse_args( $request->get_paging(), [ |
|
1071 | + 'paging' => [ 'page_size' => $atts[ 'page_size' ] ], |
|
1072 | + ] ); |
|
1073 | + $parameters[ 'paging' ] = $paging_parameters[ 'paging' ]; |
|
1074 | 1074 | } |
1075 | 1075 | |
1076 | - $page = Utils::get($parameters['paging'], 'current_page') ?: ((($parameters['paging']['offset'] - $this->settings->get('offset')) / \GV\Utils::get($parameters, 'paging/page_size', 25)) + 1); |
|
1076 | + $page = Utils::get( $parameters[ 'paging' ], 'current_page' ) ?: ( ( ( $parameters[ 'paging' ][ 'offset' ] - $this->settings->get( 'offset' ) ) / \GV\Utils::get( $parameters, 'paging/page_size', 25 ) ) + 1 ); |
|
1077 | 1077 | |
1078 | 1078 | /** |
1079 | 1079 | * Cleanup duplicate field_filter parameters to simplify the query. |
1080 | 1080 | */ |
1081 | - $unique_field_filters = []; |
|
1082 | - foreach (Utils::get($parameters, 'search_criteria/field_filters', []) as $key => $filter) { |
|
1083 | - if ('mode' === $key) { |
|
1084 | - $unique_field_filters['mode'] = $filter; |
|
1085 | - } elseif (!in_array($filter, $unique_field_filters)) { |
|
1086 | - $unique_field_filters[] = $filter; |
|
1081 | + $unique_field_filters = [ ]; |
|
1082 | + foreach ( Utils::get( $parameters, 'search_criteria/field_filters', [ ] ) as $key => $filter ) { |
|
1083 | + if ( 'mode' === $key ) { |
|
1084 | + $unique_field_filters[ 'mode' ] = $filter; |
|
1085 | + } elseif ( ! in_array( $filter, $unique_field_filters ) ) { |
|
1086 | + $unique_field_filters[ ] = $filter; |
|
1087 | 1087 | } |
1088 | 1088 | } |
1089 | - $parameters['search_criteria']['field_filters'] = $unique_field_filters; |
|
1089 | + $parameters[ 'search_criteria' ][ 'field_filters' ] = $unique_field_filters; |
|
1090 | 1090 | |
1091 | - if (!empty($parameters['search_criteria']['field_filters'])) { |
|
1092 | - gravityview()->log->notice('search_criteria/field_filters is not empty, third-party code may be using legacy search_criteria filters.'); |
|
1091 | + if ( ! empty( $parameters[ 'search_criteria' ][ 'field_filters' ] ) ) { |
|
1092 | + gravityview()->log->notice( 'search_criteria/field_filters is not empty, third-party code may be using legacy search_criteria filters.' ); |
|
1093 | 1093 | } |
1094 | 1094 | |
1095 | - if (gravityview()->plugin->supports(Plugin::FEATURE_GFQUERY)) { |
|
1095 | + if ( gravityview()->plugin->supports( Plugin::FEATURE_GFQUERY ) ) { |
|
1096 | 1096 | $query_class = $this->get_query_class(); |
1097 | 1097 | |
1098 | 1098 | /** @var \GF_Query $query */ |
1099 | - $query = new $query_class($this->form->ID, $parameters['search_criteria'], Utils::get($parameters, 'sorting')); |
|
1099 | + $query = new $query_class( $this->form->ID, $parameters[ 'search_criteria' ], Utils::get( $parameters, 'sorting' ) ); |
|
1100 | 1100 | |
1101 | 1101 | /** |
1102 | 1102 | * Apply multisort. |
1103 | 1103 | */ |
1104 | - if (!empty($has_multisort)) { |
|
1104 | + if ( ! empty( $has_multisort ) ) { |
|
1105 | 1105 | $atts = $this->settings->as_atts(); |
1106 | 1106 | |
1107 | - $view_setting_sort_field_ids = \GV\Utils::get($atts, 'sort_field', []); |
|
1108 | - $view_setting_sort_directions = \GV\Utils::get($atts, 'sort_direction', []); |
|
1107 | + $view_setting_sort_field_ids = \GV\Utils::get( $atts, 'sort_field', [ ] ); |
|
1108 | + $view_setting_sort_directions = \GV\Utils::get( $atts, 'sort_direction', [ ] ); |
|
1109 | 1109 | |
1110 | - $has_sort_query_param = !empty($_GET['sort']) && is_array($_GET['sort']); |
|
1110 | + $has_sort_query_param = ! empty( $_GET[ 'sort' ] ) && is_array( $_GET[ 'sort' ] ); |
|
1111 | 1111 | |
1112 | - if ($has_sort_query_param) { |
|
1113 | - $has_sort_query_param = array_filter(array_values($_GET['sort'])); |
|
1112 | + if ( $has_sort_query_param ) { |
|
1113 | + $has_sort_query_param = array_filter( array_values( $_GET[ 'sort' ] ) ); |
|
1114 | 1114 | } |
1115 | 1115 | |
1116 | - if ($this->settings->get('sort_columns') && $has_sort_query_param) { |
|
1117 | - $sort_field_ids = array_keys($_GET['sort']); |
|
1118 | - $sort_directions = array_values($_GET['sort']); |
|
1116 | + if ( $this->settings->get( 'sort_columns' ) && $has_sort_query_param ) { |
|
1117 | + $sort_field_ids = array_keys( $_GET[ 'sort' ] ); |
|
1118 | + $sort_directions = array_values( $_GET[ 'sort' ] ); |
|
1119 | 1119 | } else { |
1120 | 1120 | $sort_field_ids = $view_setting_sort_field_ids; |
1121 | 1121 | $sort_directions = $view_setting_sort_directions; |
@@ -1123,22 +1123,22 @@ discard block |
||
1123 | 1123 | |
1124 | 1124 | $skip_first = false; |
1125 | 1125 | |
1126 | - foreach ((array) $sort_field_ids as $key => $sort_field_id) { |
|
1127 | - if (!$skip_first && !$has_sort_query_param) { |
|
1126 | + foreach ( (array)$sort_field_ids as $key => $sort_field_id ) { |
|
1127 | + if ( ! $skip_first && ! $has_sort_query_param ) { |
|
1128 | 1128 | $skip_first = true; // Skip the first one, it's already in the query |
1129 | 1129 | continue; |
1130 | 1130 | } |
1131 | 1131 | |
1132 | - $sort_field_id = \GravityView_frontend::_override_sorting_id_by_field_type($sort_field_id, $this->form->ID); |
|
1133 | - $sort_direction = strtoupper(\GV\Utils::get($sort_directions, $key, 'ASC')); |
|
1132 | + $sort_field_id = \GravityView_frontend::_override_sorting_id_by_field_type( $sort_field_id, $this->form->ID ); |
|
1133 | + $sort_direction = strtoupper( \GV\Utils::get( $sort_directions, $key, 'ASC' ) ); |
|
1134 | 1134 | |
1135 | - if (!empty($sort_field_id)) { |
|
1136 | - $order = new \GF_Query_Column($sort_field_id, $this->form->ID); |
|
1137 | - if ('id' !== $sort_field_id && \GVCommon::is_field_numeric($this->form->ID, $sort_field_id)) { |
|
1138 | - $order = \GF_Query_Call::CAST($order, defined('GF_Query::TYPE_DECIMAL') ? \GF_Query::TYPE_DECIMAL : \GF_Query::TYPE_SIGNED); |
|
1135 | + if ( ! empty( $sort_field_id ) ) { |
|
1136 | + $order = new \GF_Query_Column( $sort_field_id, $this->form->ID ); |
|
1137 | + if ( 'id' !== $sort_field_id && \GVCommon::is_field_numeric( $this->form->ID, $sort_field_id ) ) { |
|
1138 | + $order = \GF_Query_Call::CAST( $order, defined( 'GF_Query::TYPE_DECIMAL' ) ? \GF_Query::TYPE_DECIMAL : \GF_Query::TYPE_SIGNED ); |
|
1139 | 1139 | } |
1140 | 1140 | |
1141 | - $query->order($order, $sort_direction); |
|
1141 | + $query->order( $order, $sort_direction ); |
|
1142 | 1142 | } |
1143 | 1143 | } |
1144 | 1144 | } |
@@ -1146,147 +1146,147 @@ discard block |
||
1146 | 1146 | /** |
1147 | 1147 | * Merge time subfield sorts. |
1148 | 1148 | */ |
1149 | - add_filter('gform_gf_query_sql', $gf_query_timesort_sql_callback = function ($sql) use (&$query) { |
|
1149 | + add_filter( 'gform_gf_query_sql', $gf_query_timesort_sql_callback = function( $sql ) use ( &$query ) { |
|
1150 | 1150 | $q = $query->_introspect(); |
1151 | - $orders = []; |
|
1151 | + $orders = [ ]; |
|
1152 | 1152 | |
1153 | 1153 | $merged_time = false; |
1154 | 1154 | |
1155 | - foreach ($q['order'] as $oid => $order) { |
|
1155 | + foreach ( $q[ 'order' ] as $oid => $order ) { |
|
1156 | 1156 | $column = null; |
1157 | 1157 | |
1158 | - if ($order[0] instanceof \GF_Query_Column) { |
|
1159 | - $column = $order[0]; |
|
1160 | - } elseif ($order[0] instanceof \GF_Query_Call) { |
|
1161 | - if (count($order[0]->columns) != 1 || !$order[0]->columns[0] instanceof \GF_Query_Column) { |
|
1162 | - $orders[$oid] = $order; |
|
1158 | + if ( $order[ 0 ] instanceof \GF_Query_Column ) { |
|
1159 | + $column = $order[ 0 ]; |
|
1160 | + } elseif ( $order[ 0 ] instanceof \GF_Query_Call ) { |
|
1161 | + if ( count( $order[ 0 ]->columns ) != 1 || ! $order[ 0 ]->columns[ 0 ] instanceof \GF_Query_Column ) { |
|
1162 | + $orders[ $oid ] = $order; |
|
1163 | 1163 | continue; // Need something that resembles a single sort |
1164 | 1164 | } |
1165 | - $column = $order[0]->columns[0]; |
|
1165 | + $column = $order[ 0 ]->columns[ 0 ]; |
|
1166 | 1166 | } |
1167 | 1167 | |
1168 | - if (!$column || (!$field = \GFAPI::get_field($column->source, $column->field_id)) || $field->type !== 'time') { |
|
1169 | - $orders[$oid] = $order; |
|
1168 | + if ( ! $column || ( ! $field = \GFAPI::get_field( $column->source, $column->field_id ) ) || $field->type !== 'time' ) { |
|
1169 | + $orders[ $oid ] = $order; |
|
1170 | 1170 | continue; // Not a time field |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - if (!class_exists('\GV\Mocks\GF_Query_Call_TIMESORT')) { |
|
1174 | - require_once gravityview()->plugin->dir('future/_mocks.timesort.php'); |
|
1173 | + if ( ! class_exists( '\GV\Mocks\GF_Query_Call_TIMESORT' ) ) { |
|
1174 | + require_once gravityview()->plugin->dir( 'future/_mocks.timesort.php' ); |
|
1175 | 1175 | } |
1176 | 1176 | |
1177 | - $orders[$oid] = [ |
|
1178 | - new \GV\Mocks\GF_Query_Call_TIMESORT('timesort', [$column, $sql]), |
|
1179 | - $order[1], // Mock it! |
|
1177 | + $orders[ $oid ] = [ |
|
1178 | + new \GV\Mocks\GF_Query_Call_TIMESORT( 'timesort', [ $column, $sql ] ), |
|
1179 | + $order[ 1 ], // Mock it! |
|
1180 | 1180 | ]; |
1181 | 1181 | |
1182 | 1182 | $merged_time = true; |
1183 | 1183 | } |
1184 | 1184 | |
1185 | - if ($merged_time) { |
|
1185 | + if ( $merged_time ) { |
|
1186 | 1186 | /** |
1187 | 1187 | * ORDER again. |
1188 | 1188 | */ |
1189 | - if (!empty($orders) && $_orders = $query->_order_generate($orders)) { |
|
1190 | - $sql['order'] = 'ORDER BY '.implode(', ', $_orders); |
|
1189 | + if ( ! empty( $orders ) && $_orders = $query->_order_generate( $orders ) ) { |
|
1190 | + $sql[ 'order' ] = 'ORDER BY ' . implode( ', ', $_orders ); |
|
1191 | 1191 | } |
1192 | 1192 | } |
1193 | 1193 | |
1194 | 1194 | return $sql; |
1195 | 1195 | }); |
1196 | 1196 | |
1197 | - $query->limit($parameters['paging']['page_size']) |
|
1198 | - ->offset((($page - 1) * $parameters['paging']['page_size']) + $this->settings->get('offset')); |
|
1197 | + $query->limit( $parameters[ 'paging' ][ 'page_size' ] ) |
|
1198 | + ->offset( ( ( $page - 1 ) * $parameters[ 'paging' ][ 'page_size' ] ) + $this->settings->get( 'offset' ) ); |
|
1199 | 1199 | |
1200 | 1200 | /** |
1201 | 1201 | * Any joins? |
1202 | 1202 | */ |
1203 | - if (gravityview()->plugin->supports(Plugin::FEATURE_JOINS) && count($this->joins)) { |
|
1204 | - $is_admin_and_can_view = $this->settings->get('admin_show_all_statuses') && \GVCommon::has_cap('gravityview_moderate_entries', $this->ID); |
|
1203 | + if ( gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) && count( $this->joins ) ) { |
|
1204 | + $is_admin_and_can_view = $this->settings->get( 'admin_show_all_statuses' ) && \GVCommon::has_cap( 'gravityview_moderate_entries', $this->ID ); |
|
1205 | 1205 | |
1206 | - foreach ($this->joins as $join) { |
|
1207 | - $query = $join->as_query_join($query); |
|
1206 | + foreach ( $this->joins as $join ) { |
|
1207 | + $query = $join->as_query_join( $query ); |
|
1208 | 1208 | |
1209 | - if ($this->settings->get('multiple_forms_disable_null_joins')) { |
|
1209 | + if ( $this->settings->get( 'multiple_forms_disable_null_joins' ) ) { |
|
1210 | 1210 | |
1211 | 1211 | // Disable NULL outputs |
1212 | 1212 | $condition = new \GF_Query_Condition( |
1213 | - new \GF_Query_Column($join->join_on_column->ID, $join->join_on->ID), |
|
1213 | + new \GF_Query_Column( $join->join_on_column->ID, $join->join_on->ID ), |
|
1214 | 1214 | \GF_Query_Condition::NEQ, |
1215 | - new \GF_Query_Literal('') |
|
1215 | + new \GF_Query_Literal( '' ) |
|
1216 | 1216 | ); |
1217 | 1217 | |
1218 | 1218 | $query_parameters = $query->_introspect(); |
1219 | 1219 | |
1220 | - $query->where(\GF_Query_Condition::_and($query_parameters['where'], $condition)); |
|
1220 | + $query->where( \GF_Query_Condition::_and( $query_parameters[ 'where' ], $condition ) ); |
|
1221 | 1221 | } |
1222 | 1222 | |
1223 | 1223 | /** |
1224 | 1224 | * This is a temporary stub filter, until GF_Query supports NULL conditions. |
1225 | 1225 | * Do not use! This filter will be removed. |
1226 | 1226 | */ |
1227 | - if (defined('GF_Query_Condition::NULL')) { |
|
1227 | + if ( defined( 'GF_Query_Condition::NULL' ) ) { |
|
1228 | 1228 | $is_null_condition_native = true; |
1229 | 1229 | } else { |
1230 | - $is_null_condition_class = apply_filters('gravityview/query/is_null_condition', null); |
|
1230 | + $is_null_condition_class = apply_filters( 'gravityview/query/is_null_condition', null ); |
|
1231 | 1231 | $is_null_condition_native = false; |
1232 | 1232 | } |
1233 | 1233 | |
1234 | 1234 | // Filter to active entries only |
1235 | 1235 | $condition = new \GF_Query_Condition( |
1236 | - new \GF_Query_Column('status', $join->join_on->ID), |
|
1236 | + new \GF_Query_Column( 'status', $join->join_on->ID ), |
|
1237 | 1237 | \GF_Query_Condition::EQ, |
1238 | - new \GF_Query_Literal('active') |
|
1238 | + new \GF_Query_Literal( 'active' ) |
|
1239 | 1239 | ); |
1240 | 1240 | |
1241 | - if ($is_null_condition_native) { |
|
1242 | - $condition = \GF_Query_Condition::_or($condition, new \GF_Query_Condition( |
|
1243 | - new \GF_Query_Column('status', $join->join_on->ID), |
|
1241 | + if ( $is_null_condition_native ) { |
|
1242 | + $condition = \GF_Query_Condition::_or( $condition, new \GF_Query_Condition( |
|
1243 | + new \GF_Query_Column( 'status', $join->join_on->ID ), |
|
1244 | 1244 | \GF_Query_Condition::IS, |
1245 | 1245 | \GF_Query_Condition::NULL |
1246 | - )); |
|
1247 | - } elseif (!is_null($is_null_condition_class)) { |
|
1248 | - $condition = \GF_Query_Condition::_or($condition, new $is_null_condition_class( |
|
1249 | - new \GF_Query_Column('status', $join->join_on->ID) |
|
1250 | - )); |
|
1246 | + ) ); |
|
1247 | + } elseif ( ! is_null( $is_null_condition_class ) ) { |
|
1248 | + $condition = \GF_Query_Condition::_or( $condition, new $is_null_condition_class( |
|
1249 | + new \GF_Query_Column( 'status', $join->join_on->ID ) |
|
1250 | + ) ); |
|
1251 | 1251 | } |
1252 | 1252 | |
1253 | 1253 | $q = $query->_introspect(); |
1254 | - $query->where(\GF_Query_Condition::_and($q['where'], $condition)); |
|
1254 | + $query->where( \GF_Query_Condition::_and( $q[ 'where' ], $condition ) ); |
|
1255 | 1255 | |
1256 | - if ($this->settings->get('show_only_approved') && !$is_admin_and_can_view) { |
|
1256 | + if ( $this->settings->get( 'show_only_approved' ) && ! $is_admin_and_can_view ) { |
|
1257 | 1257 | |
1258 | 1258 | // Show only approved joined entries |
1259 | 1259 | $condition = new \GF_Query_Condition( |
1260 | - new \GF_Query_Column(\GravityView_Entry_Approval::meta_key, $join->join_on->ID), |
|
1260 | + new \GF_Query_Column( \GravityView_Entry_Approval::meta_key, $join->join_on->ID ), |
|
1261 | 1261 | \GF_Query_Condition::EQ, |
1262 | - new \GF_Query_Literal(\GravityView_Entry_Approval_Status::APPROVED) |
|
1262 | + new \GF_Query_Literal( \GravityView_Entry_Approval_Status::APPROVED ) |
|
1263 | 1263 | ); |
1264 | 1264 | |
1265 | - if ($is_null_condition_native) { |
|
1266 | - $condition = \GF_Query_Condition::_or($condition, new \GF_Query_Condition( |
|
1267 | - new \GF_Query_Column(\GravityView_Entry_Approval::meta_key, $join->join_on->ID), |
|
1265 | + if ( $is_null_condition_native ) { |
|
1266 | + $condition = \GF_Query_Condition::_or( $condition, new \GF_Query_Condition( |
|
1267 | + new \GF_Query_Column( \GravityView_Entry_Approval::meta_key, $join->join_on->ID ), |
|
1268 | 1268 | \GF_Query_Condition::IS, |
1269 | 1269 | \GF_Query_Condition::NULL |
1270 | - )); |
|
1271 | - } elseif (!is_null($is_null_condition_class)) { |
|
1272 | - $condition = \GF_Query_Condition::_or($condition, new $is_null_condition_class( |
|
1273 | - new \GF_Query_Column(\GravityView_Entry_Approval::meta_key, $join->join_on->ID) |
|
1274 | - )); |
|
1270 | + ) ); |
|
1271 | + } elseif ( ! is_null( $is_null_condition_class ) ) { |
|
1272 | + $condition = \GF_Query_Condition::_or( $condition, new $is_null_condition_class( |
|
1273 | + new \GF_Query_Column( \GravityView_Entry_Approval::meta_key, $join->join_on->ID ) |
|
1274 | + ) ); |
|
1275 | 1275 | } |
1276 | 1276 | |
1277 | 1277 | $query_parameters = $query->_introspect(); |
1278 | 1278 | |
1279 | - $query->where(\GF_Query_Condition::_and($query_parameters['where'], $condition)); |
|
1279 | + $query->where( \GF_Query_Condition::_and( $query_parameters[ 'where' ], $condition ) ); |
|
1280 | 1280 | } |
1281 | 1281 | } |
1282 | 1282 | |
1283 | 1283 | /** |
1284 | 1284 | * Unions? |
1285 | 1285 | */ |
1286 | - } elseif (gravityview()->plugin->supports(Plugin::FEATURE_UNIONS) && count($this->unions)) { |
|
1286 | + } elseif ( gravityview()->plugin->supports( Plugin::FEATURE_UNIONS ) && count( $this->unions ) ) { |
|
1287 | 1287 | $query_parameters = $query->_introspect(); |
1288 | 1288 | |
1289 | - $unions_sql = []; |
|
1289 | + $unions_sql = [ ]; |
|
1290 | 1290 | |
1291 | 1291 | /** |
1292 | 1292 | * @param \GF_Query_Condition $condition |
@@ -1295,23 +1295,23 @@ discard block |
||
1295 | 1295 | * |
1296 | 1296 | * @return \GF_Query_Condition |
1297 | 1297 | */ |
1298 | - $where_union_substitute = function ($condition, $fields, $recurse) { |
|
1299 | - if ($condition->expressions) { |
|
1300 | - $conditions = []; |
|
1298 | + $where_union_substitute = function( $condition, $fields, $recurse ) { |
|
1299 | + if ( $condition->expressions ) { |
|
1300 | + $conditions = [ ]; |
|
1301 | 1301 | |
1302 | - foreach ($condition->expressions as $_condition) { |
|
1303 | - $conditions[] = $recurse($_condition, $fields, $recurse); |
|
1302 | + foreach ( $condition->expressions as $_condition ) { |
|
1303 | + $conditions[ ] = $recurse( $_condition, $fields, $recurse ); |
|
1304 | 1304 | } |
1305 | 1305 | |
1306 | 1306 | return call_user_func_array( |
1307 | - ['\GF_Query_Condition', $condition->operator == 'AND' ? '_and' : '_or'], |
|
1307 | + [ '\GF_Query_Condition', $condition->operator == 'AND' ? '_and' : '_or' ], |
|
1308 | 1308 | $conditions |
1309 | 1309 | ); |
1310 | 1310 | } |
1311 | 1311 | |
1312 | - if (!($condition->left && $condition->left instanceof \GF_Query_Column) || (!$condition->left->is_entry_column() && !$condition->left->is_meta_column())) { |
|
1312 | + if ( ! ( $condition->left && $condition->left instanceof \GF_Query_Column ) || ( ! $condition->left->is_entry_column() && ! $condition->left->is_meta_column() ) ) { |
|
1313 | 1313 | return new \GF_Query_Condition( |
1314 | - new \GF_Query_Column($fields[$condition->left->field_id]->ID), |
|
1314 | + new \GF_Query_Column( $fields[ $condition->left->field_id ]->ID ), |
|
1315 | 1315 | $condition->operator, |
1316 | 1316 | $condition->right |
1317 | 1317 | ); |
@@ -1320,97 +1320,97 @@ discard block |
||
1320 | 1320 | return $condition; |
1321 | 1321 | }; |
1322 | 1322 | |
1323 | - foreach ($this->unions as $form_id => $fields) { |
|
1323 | + foreach ( $this->unions as $form_id => $fields ) { |
|
1324 | 1324 | |
1325 | 1325 | // Build a new query for every unioned form |
1326 | 1326 | $query_class = $this->get_query_class(); |
1327 | 1327 | |
1328 | 1328 | /** @var \GF_Query|\GF_Patched_Query $q */ |
1329 | - $q = new $query_class($form_id); |
|
1329 | + $q = new $query_class( $form_id ); |
|
1330 | 1330 | |
1331 | 1331 | // Copy the WHERE clauses but substitute the field_ids to the respective ones |
1332 | - $q->where($where_union_substitute($query_parameters['where'], $fields, $where_union_substitute)); |
|
1332 | + $q->where( $where_union_substitute( $query_parameters[ 'where' ], $fields, $where_union_substitute ) ); |
|
1333 | 1333 | |
1334 | 1334 | // Copy the ORDER clause and substitute the field_ids to the respective ones |
1335 | - foreach ($query_parameters['order'] as $order) { |
|
1336 | - list($column, $_order) = $order; |
|
1335 | + foreach ( $query_parameters[ 'order' ] as $order ) { |
|
1336 | + list( $column, $_order ) = $order; |
|
1337 | 1337 | |
1338 | - if ($column && $column instanceof \GF_Query_Column) { |
|
1339 | - if (!$column->is_entry_column() && !$column->is_meta_column()) { |
|
1340 | - $column = new \GF_Query_Column($fields[$column->field_id]->ID); |
|
1338 | + if ( $column && $column instanceof \GF_Query_Column ) { |
|
1339 | + if ( ! $column->is_entry_column() && ! $column->is_meta_column() ) { |
|
1340 | + $column = new \GF_Query_Column( $fields[ $column->field_id ]->ID ); |
|
1341 | 1341 | } |
1342 | 1342 | |
1343 | - $q->order($column, $_order); |
|
1343 | + $q->order( $column, $_order ); |
|
1344 | 1344 | } |
1345 | 1345 | } |
1346 | 1346 | |
1347 | - add_filter('gform_gf_query_sql', $gf_query_sql_callback = function ($sql) use (&$unions_sql) { |
|
1347 | + add_filter( 'gform_gf_query_sql', $gf_query_sql_callback = function( $sql ) use ( &$unions_sql ) { |
|
1348 | 1348 | // Remove SQL_CALC_FOUND_ROWS as it's not needed in UNION clauses |
1349 | - $select = 'UNION ALL '.str_replace('SQL_CALC_FOUND_ROWS ', '', $sql['select']); |
|
1349 | + $select = 'UNION ALL ' . str_replace( 'SQL_CALC_FOUND_ROWS ', '', $sql[ 'select' ] ); |
|
1350 | 1350 | |
1351 | 1351 | // Record the SQL |
1352 | - $unions_sql[] = [ |
|
1352 | + $unions_sql[ ] = [ |
|
1353 | 1353 | // Remove columns, we'll rebuild them |
1354 | - 'select' => preg_replace('#DISTINCT (.*)#', 'DISTINCT ', $select), |
|
1355 | - 'from' => $sql['from'], |
|
1356 | - 'join' => $sql['join'], |
|
1357 | - 'where' => $sql['where'], |
|
1354 | + 'select' => preg_replace( '#DISTINCT (.*)#', 'DISTINCT ', $select ), |
|
1355 | + 'from' => $sql[ 'from' ], |
|
1356 | + 'join' => $sql[ 'join' ], |
|
1357 | + 'where' => $sql[ 'where' ], |
|
1358 | 1358 | // Remove order and limit |
1359 | 1359 | ]; |
1360 | 1360 | |
1361 | 1361 | // Return empty query, no need to call the database |
1362 | - return []; |
|
1362 | + return [ ]; |
|
1363 | 1363 | }); |
1364 | 1364 | |
1365 | - do_action_ref_array('gravityview/view/query', [&$q, $this, $request]); |
|
1365 | + do_action_ref_array( 'gravityview/view/query', [ &$q, $this, $request ] ); |
|
1366 | 1366 | |
1367 | 1367 | $q->get(); // Launch |
1368 | 1368 | |
1369 | - remove_filter('gform_gf_query_sql', $gf_query_sql_callback); |
|
1369 | + remove_filter( 'gform_gf_query_sql', $gf_query_sql_callback ); |
|
1370 | 1370 | } |
1371 | 1371 | |
1372 | - add_filter('gform_gf_query_sql', $gf_query_sql_callback = function ($sql) use ($unions_sql) { |
|
1372 | + add_filter( 'gform_gf_query_sql', $gf_query_sql_callback = function( $sql ) use ( $unions_sql ) { |
|
1373 | 1373 | // Remove SQL_CALC_FOUND_ROWS as it's not needed in UNION clauses |
1374 | - $sql['select'] = str_replace('SQL_CALC_FOUND_ROWS ', '', $sql['select']); |
|
1374 | + $sql[ 'select' ] = str_replace( 'SQL_CALC_FOUND_ROWS ', '', $sql[ 'select' ] ); |
|
1375 | 1375 | |
1376 | 1376 | // Remove columns, we'll rebuild them |
1377 | - preg_match('#DISTINCT (`[motc]\d+`.`.*?`)#', $sql['select'], $select_match); |
|
1378 | - $sql['select'] = preg_replace('#DISTINCT (.*)#', 'DISTINCT ', $sql['select']); |
|
1377 | + preg_match( '#DISTINCT (`[motc]\d+`.`.*?`)#', $sql[ 'select' ], $select_match ); |
|
1378 | + $sql[ 'select' ] = preg_replace( '#DISTINCT (.*)#', 'DISTINCT ', $sql[ 'select' ] ); |
|
1379 | 1379 | |
1380 | - $unions = []; |
|
1380 | + $unions = [ ]; |
|
1381 | 1381 | |
1382 | 1382 | // Transform selected columns to shared alias names |
1383 | - $column_to_alias = function ($column) { |
|
1384 | - $column = str_replace('`', '', $column); |
|
1383 | + $column_to_alias = function( $column ) { |
|
1384 | + $column = str_replace( '`', '', $column ); |
|
1385 | 1385 | |
1386 | - return '`'.str_replace('.', '_', $column).'`'; |
|
1386 | + return '`' . str_replace( '.', '_', $column ) . '`'; |
|
1387 | 1387 | }; |
1388 | 1388 | |
1389 | 1389 | // Add all the order columns into the selects, so we can order by the whole union group |
1390 | - preg_match_all('#(`[motc]\d+`.`.*?`)#', $sql['order'], $order_matches); |
|
1390 | + preg_match_all( '#(`[motc]\d+`.`.*?`)#', $sql[ 'order' ], $order_matches ); |
|
1391 | 1391 | |
1392 | 1392 | $columns = [ |
1393 | - sprintf('%s AS %s', $select_match[1], $column_to_alias($select_match[1])), |
|
1393 | + sprintf( '%s AS %s', $select_match[ 1 ], $column_to_alias( $select_match[ 1 ] ) ), |
|
1394 | 1394 | ]; |
1395 | 1395 | |
1396 | - foreach (array_slice($order_matches, 1) as $match) { |
|
1397 | - $columns[] = sprintf('%s AS %s', $match[0], $column_to_alias($match[0])); |
|
1396 | + foreach ( array_slice( $order_matches, 1 ) as $match ) { |
|
1397 | + $columns[ ] = sprintf( '%s AS %s', $match[ 0 ], $column_to_alias( $match[ 0 ] ) ); |
|
1398 | 1398 | |
1399 | 1399 | // Rewrite the order columns to the shared aliases |
1400 | - $sql['order'] = str_replace($match[0], $column_to_alias($match[0]), $sql['order']); |
|
1400 | + $sql[ 'order' ] = str_replace( $match[ 0 ], $column_to_alias( $match[ 0 ] ), $sql[ 'order' ] ); |
|
1401 | 1401 | } |
1402 | 1402 | |
1403 | - $columns = array_unique($columns); |
|
1403 | + $columns = array_unique( $columns ); |
|
1404 | 1404 | |
1405 | 1405 | // Add the columns to every UNION |
1406 | - foreach ($unions_sql as $union_sql) { |
|
1407 | - $union_sql['select'] .= implode(', ', $columns); |
|
1408 | - $unions[] = implode(' ', $union_sql); |
|
1406 | + foreach ( $unions_sql as $union_sql ) { |
|
1407 | + $union_sql[ 'select' ] .= implode( ', ', $columns ); |
|
1408 | + $unions[ ] = implode( ' ', $union_sql ); |
|
1409 | 1409 | } |
1410 | 1410 | |
1411 | 1411 | // Add the columns to the main SELECT, but only grab the entry id column |
1412 | - $sql['select'] = 'SELECT SQL_CALC_FOUND_ROWS t1_id FROM ('.$sql['select'].implode(', ', $columns); |
|
1413 | - $sql['order'] = implode(' ', $unions).') AS u '.$sql['order']; |
|
1412 | + $sql[ 'select' ] = 'SELECT SQL_CALC_FOUND_ROWS t1_id FROM (' . $sql[ 'select' ] . implode( ', ', $columns ); |
|
1413 | + $sql[ 'order' ] = implode( ' ', $unions ) . ') AS u ' . $sql[ 'order' ]; |
|
1414 | 1414 | |
1415 | 1415 | return $sql; |
1416 | 1416 | }); |
@@ -1423,54 +1423,54 @@ discard block |
||
1423 | 1423 | * @param \GV\View $this The current view object |
1424 | 1424 | * @param \GV\Request $request The request object |
1425 | 1425 | */ |
1426 | - do_action_ref_array('gravityview/view/query', [&$query, $this, $request]); |
|
1426 | + do_action_ref_array( 'gravityview/view/query', [ &$query, $this, $request ] ); |
|
1427 | 1427 | |
1428 | - gravityview()->log->debug('GF_Query parameters: ', ['data' => Utils::gf_query_debug($query)]); |
|
1428 | + gravityview()->log->debug( 'GF_Query parameters: ', [ 'data' => Utils::gf_query_debug( $query ) ] ); |
|
1429 | 1429 | |
1430 | 1430 | /** |
1431 | 1431 | * Map from Gravity Forms entries arrays to an Entry_Collection. |
1432 | 1432 | */ |
1433 | - if (count($this->joins)) { |
|
1434 | - foreach ($query->get() as $entry) { |
|
1433 | + if ( count( $this->joins ) ) { |
|
1434 | + foreach ( $query->get() as $entry ) { |
|
1435 | 1435 | $entries->add( |
1436 | - Multi_Entry::from_entries(array_map('\GV\GF_Entry::from_entry', $entry)) |
|
1436 | + Multi_Entry::from_entries( array_map( '\GV\GF_Entry::from_entry', $entry ) ) |
|
1437 | 1437 | ); |
1438 | 1438 | } |
1439 | 1439 | } else { |
1440 | - array_map([$entries, 'add'], array_map('\GV\GF_Entry::from_entry', $query->get())); |
|
1440 | + array_map( [ $entries, 'add' ], array_map( '\GV\GF_Entry::from_entry', $query->get() ) ); |
|
1441 | 1441 | } |
1442 | 1442 | |
1443 | - if (isset($gf_query_sql_callback)) { |
|
1444 | - remove_action('gform_gf_query_sql', $gf_query_sql_callback); |
|
1443 | + if ( isset( $gf_query_sql_callback ) ) { |
|
1444 | + remove_action( 'gform_gf_query_sql', $gf_query_sql_callback ); |
|
1445 | 1445 | } |
1446 | 1446 | |
1447 | - if (isset($gf_query_timesort_sql_callback)) { |
|
1448 | - remove_action('gform_gf_query_sql', $gf_query_timesort_sql_callback); |
|
1447 | + if ( isset( $gf_query_timesort_sql_callback ) ) { |
|
1448 | + remove_action( 'gform_gf_query_sql', $gf_query_timesort_sql_callback ); |
|
1449 | 1449 | } |
1450 | 1450 | |
1451 | 1451 | /** |
1452 | 1452 | * Add total count callback. |
1453 | 1453 | */ |
1454 | - $entries->add_count_callback(function () use ($query) { |
|
1454 | + $entries->add_count_callback( function() use ( $query ) { |
|
1455 | 1455 | return $query->total_found; |
1456 | 1456 | }); |
1457 | 1457 | } else { |
1458 | 1458 | $entries = $this->form->entries |
1459 | - ->filter(\GV\GF_Entry_Filter::from_search_criteria($parameters['search_criteria'])) |
|
1460 | - ->offset($this->settings->get('offset')) |
|
1461 | - ->limit($parameters['paging']['page_size']) |
|
1462 | - ->page($page); |
|
1459 | + ->filter( \GV\GF_Entry_Filter::from_search_criteria( $parameters[ 'search_criteria' ] ) ) |
|
1460 | + ->offset( $this->settings->get( 'offset' ) ) |
|
1461 | + ->limit( $parameters[ 'paging' ][ 'page_size' ] ) |
|
1462 | + ->page( $page ); |
|
1463 | 1463 | |
1464 | - if (!empty($parameters['sorting']) && is_array($parameters['sorting'] && !isset($parameters['sorting']['key']))) { |
|
1464 | + if ( ! empty( $parameters[ 'sorting' ] ) && is_array( $parameters[ 'sorting' ] && ! isset( $parameters[ 'sorting' ][ 'key' ] ) ) ) { |
|
1465 | 1465 | // Pluck off multisort arrays |
1466 | - $parameters['sorting'] = $parameters['sorting'][0]; |
|
1466 | + $parameters[ 'sorting' ] = $parameters[ 'sorting' ][ 0 ]; |
|
1467 | 1467 | } |
1468 | 1468 | |
1469 | - if (!empty($parameters['sorting']) && !empty($parameters['sorting']['key'])) { |
|
1469 | + if ( ! empty( $parameters[ 'sorting' ] ) && ! empty( $parameters[ 'sorting' ][ 'key' ] ) ) { |
|
1470 | 1470 | $field = new \GV\Field(); |
1471 | - $field->ID = $parameters['sorting']['key']; |
|
1472 | - $direction = strtolower($parameters['sorting']['direction']) == 'asc' ? \GV\Entry_Sort::ASC : \GV\Entry_Sort::DESC; |
|
1473 | - $entries = $entries->sort(new \GV\Entry_Sort($field, $direction)); |
|
1471 | + $field->ID = $parameters[ 'sorting' ][ 'key' ]; |
|
1472 | + $direction = strtolower( $parameters[ 'sorting' ][ 'direction' ] ) == 'asc' ? \GV\Entry_Sort::ASC : \GV\Entry_Sort::DESC; |
|
1473 | + $entries = $entries->sort( new \GV\Entry_Sort( $field, $direction ) ); |
|
1474 | 1474 | } |
1475 | 1475 | } |
1476 | 1476 | |
@@ -1481,7 +1481,7 @@ discard block |
||
1481 | 1481 | * @param \GV\View $view The view. |
1482 | 1482 | * @param \GV\Request $request The request. |
1483 | 1483 | */ |
1484 | - return apply_filters('gravityview/view/entries', $entries, $this, $request); |
|
1484 | + return apply_filters( 'gravityview/view/entries', $entries, $this, $request ); |
|
1485 | 1485 | } |
1486 | 1486 | |
1487 | 1487 | /** |
@@ -1493,26 +1493,26 @@ discard block |
||
1493 | 1493 | */ |
1494 | 1494 | public static function template_redirect() |
1495 | 1495 | { |
1496 | - $is_csv = get_query_var('csv'); |
|
1497 | - $is_tsv = get_query_var('tsv'); |
|
1496 | + $is_csv = get_query_var( 'csv' ); |
|
1497 | + $is_tsv = get_query_var( 'tsv' ); |
|
1498 | 1498 | |
1499 | 1499 | /** |
1500 | 1500 | * CSV output. |
1501 | 1501 | */ |
1502 | - if (!$is_csv && !$is_tsv) { |
|
1502 | + if ( ! $is_csv && ! $is_tsv ) { |
|
1503 | 1503 | return; |
1504 | 1504 | } |
1505 | 1505 | |
1506 | 1506 | $view = gravityview()->request->is_view(); |
1507 | 1507 | |
1508 | - if (!$view) { |
|
1508 | + if ( ! $view ) { |
|
1509 | 1509 | return; |
1510 | 1510 | } |
1511 | 1511 | |
1512 | - $error_csv = $view->can_render(['csv']); |
|
1512 | + $error_csv = $view->can_render( [ 'csv' ] ); |
|
1513 | 1513 | |
1514 | - if (is_wp_error($error_csv)) { |
|
1515 | - gravityview()->log->error('Not rendering CSV or TSV: '.$error_csv->get_error_message()); |
|
1514 | + if ( is_wp_error( $error_csv ) ) { |
|
1515 | + gravityview()->log->error( 'Not rendering CSV or TSV: ' . $error_csv->get_error_message() ); |
|
1516 | 1516 | |
1517 | 1517 | return; |
1518 | 1518 | } |
@@ -1528,43 +1528,43 @@ discard block |
||
1528 | 1528 | * @param string $filename File name used when downloading a CSV or TSV. Default is "{View title}.csv" or "{View title}.tsv" |
1529 | 1529 | * @param \GV\View $view Current View being rendered |
1530 | 1530 | */ |
1531 | - $filename = apply_filters('gravityview/output/'.$file_type.'/filename', get_the_title($view->post), $view); |
|
1531 | + $filename = apply_filters( 'gravityview/output/' . $file_type . '/filename', get_the_title( $view->post ), $view ); |
|
1532 | 1532 | |
1533 | - if (!defined('DOING_GRAVITYVIEW_TESTS')) { |
|
1534 | - header(sprintf('Content-Disposition: attachment;filename="%s.'.$file_type.'"', sanitize_file_name($filename))); |
|
1535 | - header('Content-Transfer-Encoding: binary'); |
|
1536 | - header('Content-Type: text/'.$file_type); |
|
1533 | + if ( ! defined( 'DOING_GRAVITYVIEW_TESTS' ) ) { |
|
1534 | + header( sprintf( 'Content-Disposition: attachment;filename="%s.' . $file_type . '"', sanitize_file_name( $filename ) ) ); |
|
1535 | + header( 'Content-Transfer-Encoding: binary' ); |
|
1536 | + header( 'Content-Type: text/' . $file_type ); |
|
1537 | 1537 | } |
1538 | 1538 | |
1539 | 1539 | ob_start(); |
1540 | - $csv_or_tsv = fopen('php://output', 'w'); |
|
1540 | + $csv_or_tsv = fopen( 'php://output', 'w' ); |
|
1541 | 1541 | |
1542 | 1542 | /** |
1543 | 1543 | * Add da' BOM if GF uses it. |
1544 | 1544 | * |
1545 | 1545 | * @see GFExport::start_export() |
1546 | 1546 | */ |
1547 | - if (apply_filters('gform_include_bom_export_entries', true, $view->form ? $view->form->form : null)) { |
|
1548 | - fputs($csv_or_tsv, "\xef\xbb\xbf"); |
|
1547 | + if ( apply_filters( 'gform_include_bom_export_entries', true, $view->form ? $view->form->form : null ) ) { |
|
1548 | + fputs( $csv_or_tsv, "\xef\xbb\xbf" ); |
|
1549 | 1549 | } |
1550 | 1550 | |
1551 | - if ($view->settings->get('csv_nolimit')) { |
|
1552 | - $view->settings->update(['page_size' => -1]); |
|
1551 | + if ( $view->settings->get( 'csv_nolimit' ) ) { |
|
1552 | + $view->settings->update( [ 'page_size' => -1 ] ); |
|
1553 | 1553 | } |
1554 | 1554 | |
1555 | 1555 | $entries = $view->get_entries(); |
1556 | 1556 | |
1557 | 1557 | $headers_done = false; |
1558 | - $allowed = $headers = []; |
|
1558 | + $allowed = $headers = [ ]; |
|
1559 | 1559 | |
1560 | - foreach ($view->fields->by_position('directory_*')->by_visible($view)->all() as $id => $field) { |
|
1561 | - $allowed[] = $field; |
|
1560 | + foreach ( $view->fields->by_position( 'directory_*' )->by_visible( $view )->all() as $id => $field ) { |
|
1561 | + $allowed[ ] = $field; |
|
1562 | 1562 | } |
1563 | 1563 | |
1564 | 1564 | $renderer = new Field_Renderer(); |
1565 | 1565 | |
1566 | - foreach ($entries->all() as $entry) { |
|
1567 | - $return = []; |
|
1566 | + foreach ( $entries->all() as $entry ) { |
|
1567 | + $return = [ ]; |
|
1568 | 1568 | |
1569 | 1569 | /** |
1570 | 1570 | * @filter `gravityview/csv/entry/fields` Allowlist more entry fields by ID that are output in CSV requests. |
@@ -1573,42 +1573,42 @@ discard block |
||
1573 | 1573 | * @param \GV\View $view The view. |
1574 | 1574 | * @param \GV\Entry $entry WordPress representation of the item. |
1575 | 1575 | */ |
1576 | - $allowed_field_ids = apply_filters('gravityview/csv/entry/fields', wp_list_pluck($allowed, 'ID'), $view, $entry); |
|
1576 | + $allowed_field_ids = apply_filters( 'gravityview/csv/entry/fields', wp_list_pluck( $allowed, 'ID' ), $view, $entry ); |
|
1577 | 1577 | |
1578 | - $allowed = array_filter($allowed, function ($field) use ($allowed_field_ids) { |
|
1579 | - return in_array($field->ID, $allowed_field_ids, true); |
|
1578 | + $allowed = array_filter( $allowed, function( $field ) use ( $allowed_field_ids ) { |
|
1579 | + return in_array( $field->ID, $allowed_field_ids, true ); |
|
1580 | 1580 | }); |
1581 | 1581 | |
1582 | - foreach (array_diff($allowed_field_ids, wp_list_pluck($allowed, 'ID')) as $field_id) { |
|
1583 | - $allowed[] = is_numeric($field_id) ? \GV\GF_Field::by_id($view->form, $field_id) : \GV\Internal_Field::by_id($field_id); |
|
1582 | + foreach ( array_diff( $allowed_field_ids, wp_list_pluck( $allowed, 'ID' ) ) as $field_id ) { |
|
1583 | + $allowed[ ] = is_numeric( $field_id ) ? \GV\GF_Field::by_id( $view->form, $field_id ) : \GV\Internal_Field::by_id( $field_id ); |
|
1584 | 1584 | } |
1585 | 1585 | |
1586 | - foreach ($allowed as $field) { |
|
1587 | - $source = is_numeric($field->ID) ? $view->form : new \GV\Internal_Source(); |
|
1586 | + foreach ( $allowed as $field ) { |
|
1587 | + $source = is_numeric( $field->ID ) ? $view->form : new \GV\Internal_Source(); |
|
1588 | 1588 | |
1589 | - $return[] = $renderer->render($field, $view, $source, $entry, gravityview()->request, '\GV\Field_CSV_Template'); |
|
1589 | + $return[ ] = $renderer->render( $field, $view, $source, $entry, gravityview()->request, '\GV\Field_CSV_Template' ); |
|
1590 | 1590 | |
1591 | - if (!$headers_done) { |
|
1592 | - $label = $field->get_label($view, $source, $entry); |
|
1593 | - $headers[] = $label ? $label : $field->ID; |
|
1591 | + if ( ! $headers_done ) { |
|
1592 | + $label = $field->get_label( $view, $source, $entry ); |
|
1593 | + $headers[ ] = $label ? $label : $field->ID; |
|
1594 | 1594 | } |
1595 | 1595 | } |
1596 | 1596 | |
1597 | 1597 | // If not "tsv" then use comma |
1598 | - $delimiter = ('tsv' === $file_type) ? "\t" : ','; |
|
1598 | + $delimiter = ( 'tsv' === $file_type ) ? "\t" : ','; |
|
1599 | 1599 | |
1600 | - if (!$headers_done) { |
|
1601 | - $headers_done = fputcsv($csv_or_tsv, array_map(['\GV\Utils', 'strip_excel_formulas'], array_values($headers)), $delimiter); |
|
1600 | + if ( ! $headers_done ) { |
|
1601 | + $headers_done = fputcsv( $csv_or_tsv, array_map( [ '\GV\Utils', 'strip_excel_formulas' ], array_values( $headers ) ), $delimiter ); |
|
1602 | 1602 | } |
1603 | 1603 | |
1604 | - fputcsv($csv_or_tsv, array_map(['\GV\Utils', 'strip_excel_formulas'], $return), $delimiter); |
|
1604 | + fputcsv( $csv_or_tsv, array_map( [ '\GV\Utils', 'strip_excel_formulas' ], $return ), $delimiter ); |
|
1605 | 1605 | } |
1606 | 1606 | |
1607 | - fflush($csv_or_tsv); |
|
1607 | + fflush( $csv_or_tsv ); |
|
1608 | 1608 | |
1609 | - echo rtrim(ob_get_clean()); |
|
1609 | + echo rtrim( ob_get_clean() ); |
|
1610 | 1610 | |
1611 | - if (!defined('DOING_GRAVITYVIEW_TESTS')) { |
|
1611 | + if ( ! defined( 'DOING_GRAVITYVIEW_TESTS' ) ) { |
|
1612 | 1612 | exit; |
1613 | 1613 | } |
1614 | 1614 | } |
@@ -1626,7 +1626,7 @@ discard block |
||
1626 | 1626 | * @param string The query class. Default: GF_Query. |
1627 | 1627 | * @param \GV\View $this The View. |
1628 | 1628 | */ |
1629 | - $query_class = apply_filters('gravityview/query/class', '\GF_Query', $this); |
|
1629 | + $query_class = apply_filters( 'gravityview/query/class', '\GF_Query', $this ); |
|
1630 | 1630 | |
1631 | 1631 | return $query_class; |
1632 | 1632 | } |
@@ -1645,7 +1645,7 @@ discard block |
||
1645 | 1645 | * |
1646 | 1646 | * @return array The resulting capabilities. |
1647 | 1647 | */ |
1648 | - public static function restrict($caps, $cap, $user_id, $args) |
|
1648 | + public static function restrict( $caps, $cap, $user_id, $args ) |
|
1649 | 1649 | { |
1650 | 1650 | /** |
1651 | 1651 | * @filter `gravityview/security/require_unfiltered_html` Bypass restrictions on Views that require `unfiltered_html`. |
@@ -1658,41 +1658,41 @@ discard block |
||
1658 | 1658 | * @param int $user_id The user ID. |
1659 | 1659 | * @param array $args Any additional args to map_meta_cap |
1660 | 1660 | */ |
1661 | - if (!apply_filters('gravityview/security/require_unfiltered_html', true, $cap, $user_id)) { |
|
1661 | + if ( ! apply_filters( 'gravityview/security/require_unfiltered_html', true, $cap, $user_id ) ) { |
|
1662 | 1662 | return $caps; |
1663 | 1663 | } |
1664 | 1664 | |
1665 | - switch ($cap) { |
|
1665 | + switch ( $cap ) { |
|
1666 | 1666 | case 'edit_gravityview': |
1667 | 1667 | case 'edit_gravityviews': |
1668 | 1668 | case 'edit_others_gravityviews': |
1669 | 1669 | case 'edit_private_gravityviews': |
1670 | 1670 | case 'edit_published_gravityviews': |
1671 | - if (!user_can($user_id, 'unfiltered_html')) { |
|
1672 | - if (!user_can($user_id, 'gravityview_full_access')) { |
|
1673 | - return ['do_not_allow']; |
|
1671 | + if ( ! user_can( $user_id, 'unfiltered_html' ) ) { |
|
1672 | + if ( ! user_can( $user_id, 'gravityview_full_access' ) ) { |
|
1673 | + return [ 'do_not_allow' ]; |
|
1674 | 1674 | } |
1675 | 1675 | } |
1676 | 1676 | |
1677 | 1677 | return $caps; |
1678 | 1678 | case 'edit_post': |
1679 | - if ('gravityview' === get_post_type(array_pop($args))) { |
|
1680 | - return self::restrict($caps, 'edit_gravityview', $user_id, $args); |
|
1679 | + if ( 'gravityview' === get_post_type( array_pop( $args ) ) ) { |
|
1680 | + return self::restrict( $caps, 'edit_gravityview', $user_id, $args ); |
|
1681 | 1681 | } |
1682 | 1682 | } |
1683 | 1683 | |
1684 | 1684 | return $caps; |
1685 | 1685 | } |
1686 | 1686 | |
1687 | - public function __get($key) |
|
1687 | + public function __get( $key ) |
|
1688 | 1688 | { |
1689 | - if ($this->post) { |
|
1690 | - $raw_post = $this->post->filter('raw'); |
|
1689 | + if ( $this->post ) { |
|
1690 | + $raw_post = $this->post->filter( 'raw' ); |
|
1691 | 1691 | |
1692 | 1692 | return $raw_post->{$key}; |
1693 | 1693 | } |
1694 | 1694 | |
1695 | - return isset($this->{$key}) ? $this->{$key} : null; |
|
1695 | + return isset( $this->{$key}) ? $this->{$key} : null; |
|
1696 | 1696 | } |
1697 | 1697 | |
1698 | 1698 | /** |
@@ -102,8 +102,7 @@ discard block |
||
102 | 102 | /** |
103 | 103 | * The constructor. |
104 | 104 | */ |
105 | - public function __construct() |
|
106 | - { |
|
105 | + public function __construct() { |
|
107 | 106 | $this->settings = new View_Settings(); |
108 | 107 | $this->fields = new Field_Collection(); |
109 | 108 | $this->widgets = new Widget_Collection(); |
@@ -116,8 +115,7 @@ discard block |
||
116 | 115 | * |
117 | 116 | * @return void |
118 | 117 | */ |
119 | - public static function register_post_type() |
|
120 | - { |
|
118 | + public static function register_post_type() { |
|
121 | 119 | |
122 | 120 | /** Register only once */ |
123 | 121 | if (post_type_exists('gravityview')) { |
@@ -244,8 +242,7 @@ discard block |
||
244 | 242 | * |
245 | 243 | * @return void |
246 | 244 | */ |
247 | - public static function add_rewrite_endpoint() |
|
248 | - { |
|
245 | + public static function add_rewrite_endpoint() { |
|
249 | 246 | /** |
250 | 247 | * CSV. |
251 | 248 | */ |
@@ -276,8 +273,7 @@ discard block |
||
276 | 273 | * |
277 | 274 | * @return string $content The view content as output by the renderers. |
278 | 275 | */ |
279 | - public static function content($content) |
|
280 | - { |
|
276 | + public static function content($content) { |
|
281 | 277 | $request = gravityview()->request; |
282 | 278 | |
283 | 279 | // Plugins may run through the content in the header. WP SEO does this for its OpenGraph functionality. |
@@ -452,8 +448,7 @@ discard block |
||
452 | 448 | * |
453 | 449 | * @return bool|\WP_Error An error if this View shouldn't be rendered here. |
454 | 450 | */ |
455 | - public function can_render($context = null, $request = null) |
|
456 | - { |
|
451 | + public function can_render($context = null, $request = null) { |
|
457 | 452 | if (!$request) { |
458 | 453 | $request = gravityview()->request; |
459 | 454 | } |
@@ -565,8 +560,7 @@ discard block |
||
565 | 560 | * |
566 | 561 | * @return \GV\Join[] Array of \GV\Join instances |
567 | 562 | */ |
568 | - public static function get_joins($post) |
|
569 | - { |
|
563 | + public static function get_joins($post) { |
|
570 | 564 | $joins = []; |
571 | 565 | |
572 | 566 | if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
@@ -620,8 +614,7 @@ discard block |
||
620 | 614 | * |
621 | 615 | * @return \GV\GF_Form[] Array of \GV\GF_Form instances |
622 | 616 | */ |
623 | - public static function get_joined_forms($post_id) |
|
624 | - { |
|
617 | + public static function get_joined_forms($post_id) { |
|
625 | 618 | $forms = []; |
626 | 619 | |
627 | 620 | if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
@@ -676,8 +669,7 @@ discard block |
||
676 | 669 | * |
677 | 670 | * @return \GV\Field[][] Array of unions (see self::$unions) |
678 | 671 | */ |
679 | - public static function get_unions($post) |
|
680 | - { |
|
672 | + public static function get_unions($post) { |
|
681 | 673 | $unions = []; |
682 | 674 | |
683 | 675 | if (!$post || 'gravityview' !== get_post_type($post)) { |
@@ -735,8 +727,7 @@ discard block |
||
735 | 727 | * |
736 | 728 | * @return \GV\View|null An instance around this \WP_Post if valid, null otherwise. |
737 | 729 | */ |
738 | - public static function from_post($post) |
|
739 | - { |
|
730 | + public static function from_post($post) { |
|
740 | 731 | if (!$post || 'gravityview' !== get_post_type($post)) { |
741 | 732 | gravityview()->log->error('Only gravityview post types can be \GV\View instances.'); |
742 | 733 | |
@@ -855,8 +846,7 @@ discard block |
||
855 | 846 | * |
856 | 847 | * @internal |
857 | 848 | */ |
858 | - public static function _flush_cache($view_id = null) |
|
859 | - { |
|
849 | + public static function _flush_cache($view_id = null) { |
|
860 | 850 | if ($view_id) { |
861 | 851 | unset(self::$cache["View::from_post:$view_id"]); |
862 | 852 | |
@@ -876,8 +866,7 @@ discard block |
||
876 | 866 | * |
877 | 867 | * @return \GV\View|null An instance around this \WP_Post or null if not found. |
878 | 868 | */ |
879 | - public static function by_id($post_id) |
|
880 | - { |
|
869 | + public static function by_id($post_id) { |
|
881 | 870 | if (!$post_id || !$post = get_post($post_id)) { |
882 | 871 | return null; |
883 | 872 | } |
@@ -896,8 +885,7 @@ discard block |
||
896 | 885 | * |
897 | 886 | * @return bool Whether the post exists or not. |
898 | 887 | */ |
899 | - public static function exists($view) |
|
900 | - { |
|
888 | + public static function exists($view) { |
|
901 | 889 | return get_post_type($view) == 'gravityview'; |
902 | 890 | } |
903 | 891 | |
@@ -911,8 +899,7 @@ discard block |
||
911 | 899 | * |
912 | 900 | * @return bool Whether the offset exists or not, limited to GravityView_View_Data::$views element keys. |
913 | 901 | */ |
914 | - public function offsetExists($offset) |
|
915 | - { |
|
902 | + public function offsetExists($offset) { |
|
916 | 903 | $data_keys = ['id', 'view_id', 'form_id', 'template_id', 'atts', 'fields', 'widgets', 'form']; |
917 | 904 | |
918 | 905 | return in_array($offset, $data_keys); |
@@ -930,8 +917,7 @@ discard block |
||
930 | 917 | * |
931 | 918 | * @return mixed The value of the requested view data key limited to GravityView_View_Data::$views element keys. If offset not found, return null. |
932 | 919 | */ |
933 | - public function offsetGet($offset) |
|
934 | - { |
|
920 | + public function offsetGet($offset) { |
|
935 | 921 | gravityview()->log->notice('This is a \GV\View object should not be accessed as an array.'); |
936 | 922 | |
937 | 923 | if (!isset($this[$offset])) { |
@@ -967,8 +953,7 @@ discard block |
||
967 | 953 | * |
968 | 954 | * @return void |
969 | 955 | */ |
970 | - public function offsetSet($offset, $value) |
|
971 | - { |
|
956 | + public function offsetSet($offset, $value) { |
|
972 | 957 | gravityview()->log->error('The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.'); |
973 | 958 | } |
974 | 959 | |
@@ -982,8 +967,7 @@ discard block |
||
982 | 967 | * |
983 | 968 | * @return void |
984 | 969 | */ |
985 | - public function offsetUnset($offset) |
|
986 | - { |
|
970 | + public function offsetUnset($offset) { |
|
987 | 971 | gravityview()->log->error('The old view data is no longer mutable. This is a \GV\View object should not be accessed as an array.'); |
988 | 972 | } |
989 | 973 | |
@@ -1001,8 +985,7 @@ discard block |
||
1001 | 985 | * |
1002 | 986 | * @return array |
1003 | 987 | */ |
1004 | - public function as_data() |
|
1005 | - { |
|
988 | + public function as_data() { |
|
1006 | 989 | return [ |
1007 | 990 | 'id' => $this->ID, |
1008 | 991 | 'view_id' => $this->ID, |
@@ -1022,8 +1005,7 @@ discard block |
||
1022 | 1005 | * |
1023 | 1006 | * @return \GV\Entry_Collection The entries. |
1024 | 1007 | */ |
1025 | - public function get_entries($request = null) |
|
1026 | - { |
|
1008 | + public function get_entries($request = null) { |
|
1027 | 1009 | $entries = new \GV\Entry_Collection(); |
1028 | 1010 | |
1029 | 1011 | if (!$this->form) { |
@@ -1491,8 +1473,7 @@ discard block |
||
1491 | 1473 | * |
1492 | 1474 | * @return void |
1493 | 1475 | */ |
1494 | - public static function template_redirect() |
|
1495 | - { |
|
1476 | + public static function template_redirect() { |
|
1496 | 1477 | $is_csv = get_query_var('csv'); |
1497 | 1478 | $is_tsv = get_query_var('tsv'); |
1498 | 1479 | |
@@ -1618,8 +1599,7 @@ discard block |
||
1618 | 1599 | * |
1619 | 1600 | * @return string The class name. |
1620 | 1601 | */ |
1621 | - public function get_query_class() |
|
1622 | - { |
|
1602 | + public function get_query_class() { |
|
1623 | 1603 | /** |
1624 | 1604 | * @filter `gravityview/query/class` |
1625 | 1605 | * |
@@ -1645,8 +1625,7 @@ discard block |
||
1645 | 1625 | * |
1646 | 1626 | * @return array The resulting capabilities. |
1647 | 1627 | */ |
1648 | - public static function restrict($caps, $cap, $user_id, $args) |
|
1649 | - { |
|
1628 | + public static function restrict($caps, $cap, $user_id, $args) { |
|
1650 | 1629 | /** |
1651 | 1630 | * @filter `gravityview/security/require_unfiltered_html` Bypass restrictions on Views that require `unfiltered_html`. |
1652 | 1631 | * |
@@ -1684,8 +1663,7 @@ discard block |
||
1684 | 1663 | return $caps; |
1685 | 1664 | } |
1686 | 1665 | |
1687 | - public function __get($key) |
|
1688 | - { |
|
1666 | + public function __get($key) { |
|
1689 | 1667 | if ($this->post) { |
1690 | 1668 | $raw_post = $this->post->filter('raw'); |
1691 | 1669 | |
@@ -1702,8 +1680,7 @@ discard block |
||
1702 | 1680 | * |
1703 | 1681 | * @return \WP_Post|null |
1704 | 1682 | */ |
1705 | - public function get_post() |
|
1706 | - { |
|
1683 | + public function get_post() { |
|
1707 | 1684 | return $this->post ? $this->post : null; |
1708 | 1685 | } |
1709 | 1686 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | 6 | if (!defined('GRAVITYVIEW_DIR')) { |
7 | - exit(); |
|
7 | + exit(); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -12,237 +12,237 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class gventry extends \GV\Shortcode |
14 | 14 | { |
15 | - /** |
|
16 | - * {@inheritDoc} |
|
17 | - */ |
|
18 | - public $name = 'gventry'; |
|
19 | - |
|
20 | - /** |
|
21 | - * Process and output the [gventry] shortcode. |
|
22 | - * |
|
23 | - * @param array $passed_atts The attributes passed. |
|
24 | - * @param string $content The content inside the shortcode. |
|
25 | - * @param string $tag The shortcode tag. |
|
26 | - * |
|
27 | - * @return string|null The output. |
|
28 | - */ |
|
29 | - public function callback($atts, $content = '', $tag = '') |
|
30 | - { |
|
31 | - $request = gravityview()->request; |
|
32 | - |
|
33 | - if ($request->is_admin()) { |
|
34 | - return apply_filters('gravityview/shortcodes/gventry/output', '', null, null, $atts); |
|
35 | - } |
|
36 | - |
|
37 | - $atts = wp_parse_args($atts, [ |
|
38 | - 'id' => 0, |
|
39 | - 'entry_id' => 0, |
|
40 | - 'view_id' => 0, |
|
41 | - 'edit' => 0, |
|
42 | - ]); |
|
43 | - |
|
44 | - $atts = gv_map_deep($atts, ['GravityView_Merge_Tags', 'replace_get_variables']); |
|
45 | - |
|
46 | - /** |
|
47 | - * @filter `gravityview/shortcodes/gventry/atts` Filter the [gventry] shortcode attributes. |
|
48 | - * |
|
49 | - * @param array $atts The initial attributes. |
|
50 | - * |
|
51 | - * @since 2.0 |
|
52 | - */ |
|
53 | - $atts = apply_filters('gravityview/shortcodes/gventry/atts', $atts); |
|
54 | - |
|
55 | - $view = \GV\View::by_id($atts['view_id']); |
|
56 | - |
|
57 | - if (!$view) { |
|
58 | - gravityview()->log->error('View does not exist #{view_id}', ['view_id' => $atts['view_id']]); |
|
59 | - |
|
60 | - return apply_filters('gravityview/shortcodes/gventry/output', '', null, null, $atts); |
|
61 | - } |
|
62 | - |
|
63 | - $entry_id = !empty($atts['entry_id']) ? $atts['entry_id'] : $atts['id']; |
|
64 | - |
|
65 | - switch ($entry_id) { |
|
66 | - case 'last': |
|
67 | - if (class_exists('\GF_Query')) { |
|
68 | - /** |
|
69 | - * @todo Remove once we refactor the use of get_view_entries_parameters. |
|
70 | - * |
|
71 | - * Since we're using \GF_Query shorthand initialization we have to reverse the order parameters here. |
|
72 | - */ |
|
73 | - add_filter('gravityview_get_entries', $filter = function ($parameters, $args, $form_id) { |
|
74 | - if (!empty($parameters['sorting'])) { |
|
75 | - /** |
|
76 | - * Reverse existing sorts. |
|
77 | - */ |
|
78 | - $sort = &$parameters['sorting']; |
|
79 | - $sort['direction'] = $sort['direction'] == 'RAND' ?: ($sort['direction'] == 'ASC' ? 'DESC' : 'ASC'); |
|
80 | - } else { |
|
81 | - /** |
|
82 | - * Otherwise, sort by date_created. |
|
83 | - */ |
|
84 | - $parameters['sorting'] = [ |
|
85 | - 'key' => 'id', |
|
86 | - 'direction' => 'ASC', |
|
87 | - 'is_numeric' => true, |
|
88 | - ]; |
|
89 | - } |
|
90 | - |
|
91 | - return $parameters; |
|
92 | - }, 10, 3); |
|
93 | - $entries = $view->get_entries(null); |
|
94 | - remove_filter('gravityview_get_entries', $filter); |
|
95 | - } else { |
|
96 | - $entries = $view->get_entries(null); |
|
97 | - |
|
98 | - /** If a sort already exists, reverse it. */ |
|
99 | - if ($sort = end($entries->sorts)) { |
|
100 | - $entries = $entries->sort(new \GV\Entry_Sort($sort->field, $sort->direction == \GV\Entry_Sort::RAND ?: ($sort->direction == \GV\Entry_Sort::ASC ? \GV\Entry_Sort::DESC : \GV\Entry_Sort::ASC)), $sort->mode); |
|
101 | - } else { |
|
102 | - /** Otherwise, sort by date_created */ |
|
103 | - $entries = $entries->sort(new \GV\Entry_Sort(\GV\Internal_Field::by_id('id'), \GV\Entry_Sort::ASC), \GV\Entry_Sort::NUMERIC); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - if (!$entry = $entries->first()) { |
|
108 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, null, $atts); |
|
109 | - } |
|
110 | - break; |
|
111 | - case 'first': |
|
112 | - if (!$entry = $view->get_entries(null)->first()) { |
|
113 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, null, $atts); |
|
114 | - } |
|
115 | - break; |
|
116 | - default: |
|
117 | - if (!$entry = \GV\GF_Entry::by_id($entry_id)) { |
|
118 | - gravityview()->log->error('Entry #{entry_id} not found', ['view_id' => $atts['view_id']]); |
|
119 | - |
|
120 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, null, $atts); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - if ($view->form->ID != $entry['form_id']) { |
|
125 | - gravityview()->log->error('Entry does not belong to view (form mismatch)'); |
|
126 | - |
|
127 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
128 | - } |
|
129 | - |
|
130 | - if (post_password_required($view->ID)) { |
|
131 | - gravityview()->log->notice('Post password is required for View #{view_id}', ['view_id' => $view->ID]); |
|
132 | - |
|
133 | - return apply_filters('gravityview/shortcodes/gventry/output', get_the_password_form($view->ID), $view, $entry, $atts); |
|
134 | - } |
|
135 | - |
|
136 | - if (!$view->form) { |
|
137 | - gravityview()->log->notice('View #{id} has no form attached to it.', ['id' => $view->ID]); |
|
138 | - |
|
139 | - /** |
|
140 | - * This View has no data source. There's nothing to show really. |
|
141 | - * ...apart from a nice message if the user can do anything about it. |
|
142 | - */ |
|
143 | - if (\GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview'], $view->ID)) { |
|
144 | - $return = sprintf(__('This View is not configured properly. Start by <a href="%s">selecting a form</a>.', 'gravityview'), esc_url(get_edit_post_link($view->ID, false))); |
|
145 | - |
|
146 | - return apply_filters('gravityview/shortcodes/gventry/output', $return, $view, $entry, $atts); |
|
147 | - } |
|
148 | - |
|
149 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
150 | - } |
|
151 | - |
|
152 | - /** Private, pending, draft, etc. */ |
|
153 | - $public_states = get_post_stati(['public' => true]); |
|
154 | - if (!in_array($view->post_status, $public_states) && !\GVCommon::has_cap('read_gravityview', $view->ID)) { |
|
155 | - gravityview()->log->notice('The current user cannot access this View #{view_id}', ['view_id' => $view->ID]); |
|
156 | - |
|
157 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
158 | - } |
|
159 | - |
|
160 | - /** Unapproved entries. */ |
|
161 | - if ($entry['status'] != 'active') { |
|
162 | - gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $entry->ID]); |
|
163 | - |
|
164 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
165 | - } |
|
166 | - |
|
167 | - $is_admin_and_can_view = $view->settings->get('admin_show_all_statuses') && \GVCommon::has_cap('gravityview_moderate_entries', $view->ID); |
|
168 | - |
|
169 | - if ($view->settings->get('show_only_approved') && !$is_admin_and_can_view) { |
|
170 | - if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($entry->ID, \GravityView_Entry_Approval::meta_key))) { |
|
171 | - gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $entry->ID]); |
|
172 | - |
|
173 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - if ($atts['edit']) { |
|
178 | - /** |
|
179 | - * Based on code in our unit-tests. |
|
180 | - * Mocks old context, etc. |
|
181 | - */ |
|
182 | - $loader = \GravityView_Edit_Entry::getInstance(); |
|
183 | - $render = $loader->instances['render']; |
|
184 | - |
|
185 | - add_filter('gravityview/is_single_entry', '__return_true'); |
|
186 | - |
|
187 | - $form = \GFAPI::get_form($entry['form_id']); |
|
188 | - |
|
189 | - $data = \GravityView_View_Data::getInstance($view); |
|
190 | - $template = \GravityView_View::getInstance([ |
|
191 | - 'form' => $form, |
|
192 | - 'form_id' => $form['id'], |
|
193 | - 'view_id' => $view->ID, |
|
194 | - 'entries' => [$entry], |
|
195 | - 'atts' => \GVCommon::get_template_settings($view->ID), |
|
196 | - ]); |
|
197 | - |
|
198 | - $_GET['edit'] = wp_create_nonce( |
|
199 | - \GravityView_Edit_Entry::get_nonce_key($view->ID, $form['id'], $entry['id']) |
|
200 | - ); |
|
201 | - |
|
202 | - add_filter('gravityview/edit_entry/success', $callback = function ($message) use ($view, $entry, $atts) { |
|
203 | - $message = __('Entry Updated', 'gravityview'); |
|
204 | - |
|
205 | - /** |
|
206 | - * @filter `gravityview/shortcodes/gventry/edit/success` Modify the edit entry success message in [gventry]. |
|
207 | - * |
|
208 | - * @since develop |
|
209 | - * |
|
210 | - * @param string $message The message. |
|
211 | - * @param \GV\View $view The View. |
|
212 | - * @param \GV\Entry $entry The entry. |
|
213 | - * @param array $atts The attributes. |
|
214 | - */ |
|
215 | - return apply_filters('gravityview/shortcodes/gventry/edit/success', $message, $view, $entry, $atts); |
|
216 | - }); |
|
217 | - |
|
218 | - ob_start() && $render->init($data, \GV\Entry::by_id($entry['id']), $view); |
|
219 | - $output = ob_get_clean(); // Render :) |
|
220 | - |
|
221 | - remove_filter('gravityview/is_single_entry', '__return_true'); |
|
222 | - remove_filter('gravityview/edit_entry/success', $callback); |
|
223 | - } else { |
|
224 | - /** Remove the back link. */ |
|
225 | - add_filter('gravityview/template/links/back/url', '__return_false'); |
|
226 | - |
|
227 | - $renderer = new \GV\Entry_Renderer(); |
|
228 | - |
|
229 | - $request = new \GV\Mock_Request(); |
|
230 | - $request->returns['is_entry'] = $entry; |
|
231 | - |
|
232 | - $output = $renderer->render($entry, $view, $request); |
|
233 | - |
|
234 | - remove_filter('gravityview/template/links/back/url', '__return_false'); |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @filter `gravityview/shortcodes/gventry/output` Filter the [gventry] output. |
|
239 | - * |
|
240 | - * @param string $output The output. |
|
241 | - * @param \GV\View|null $view The View detected or null. |
|
242 | - * @param \GV\Entry|null $entry The Entry or null. |
|
243 | - * |
|
244 | - * @since 2.0 |
|
245 | - */ |
|
246 | - return apply_filters('gravityview/shortcodes/gventry/output', $output, $view, $entry, $atts); |
|
247 | - } |
|
15 | + /** |
|
16 | + * {@inheritDoc} |
|
17 | + */ |
|
18 | + public $name = 'gventry'; |
|
19 | + |
|
20 | + /** |
|
21 | + * Process and output the [gventry] shortcode. |
|
22 | + * |
|
23 | + * @param array $passed_atts The attributes passed. |
|
24 | + * @param string $content The content inside the shortcode. |
|
25 | + * @param string $tag The shortcode tag. |
|
26 | + * |
|
27 | + * @return string|null The output. |
|
28 | + */ |
|
29 | + public function callback($atts, $content = '', $tag = '') |
|
30 | + { |
|
31 | + $request = gravityview()->request; |
|
32 | + |
|
33 | + if ($request->is_admin()) { |
|
34 | + return apply_filters('gravityview/shortcodes/gventry/output', '', null, null, $atts); |
|
35 | + } |
|
36 | + |
|
37 | + $atts = wp_parse_args($atts, [ |
|
38 | + 'id' => 0, |
|
39 | + 'entry_id' => 0, |
|
40 | + 'view_id' => 0, |
|
41 | + 'edit' => 0, |
|
42 | + ]); |
|
43 | + |
|
44 | + $atts = gv_map_deep($atts, ['GravityView_Merge_Tags', 'replace_get_variables']); |
|
45 | + |
|
46 | + /** |
|
47 | + * @filter `gravityview/shortcodes/gventry/atts` Filter the [gventry] shortcode attributes. |
|
48 | + * |
|
49 | + * @param array $atts The initial attributes. |
|
50 | + * |
|
51 | + * @since 2.0 |
|
52 | + */ |
|
53 | + $atts = apply_filters('gravityview/shortcodes/gventry/atts', $atts); |
|
54 | + |
|
55 | + $view = \GV\View::by_id($atts['view_id']); |
|
56 | + |
|
57 | + if (!$view) { |
|
58 | + gravityview()->log->error('View does not exist #{view_id}', ['view_id' => $atts['view_id']]); |
|
59 | + |
|
60 | + return apply_filters('gravityview/shortcodes/gventry/output', '', null, null, $atts); |
|
61 | + } |
|
62 | + |
|
63 | + $entry_id = !empty($atts['entry_id']) ? $atts['entry_id'] : $atts['id']; |
|
64 | + |
|
65 | + switch ($entry_id) { |
|
66 | + case 'last': |
|
67 | + if (class_exists('\GF_Query')) { |
|
68 | + /** |
|
69 | + * @todo Remove once we refactor the use of get_view_entries_parameters. |
|
70 | + * |
|
71 | + * Since we're using \GF_Query shorthand initialization we have to reverse the order parameters here. |
|
72 | + */ |
|
73 | + add_filter('gravityview_get_entries', $filter = function ($parameters, $args, $form_id) { |
|
74 | + if (!empty($parameters['sorting'])) { |
|
75 | + /** |
|
76 | + * Reverse existing sorts. |
|
77 | + */ |
|
78 | + $sort = &$parameters['sorting']; |
|
79 | + $sort['direction'] = $sort['direction'] == 'RAND' ?: ($sort['direction'] == 'ASC' ? 'DESC' : 'ASC'); |
|
80 | + } else { |
|
81 | + /** |
|
82 | + * Otherwise, sort by date_created. |
|
83 | + */ |
|
84 | + $parameters['sorting'] = [ |
|
85 | + 'key' => 'id', |
|
86 | + 'direction' => 'ASC', |
|
87 | + 'is_numeric' => true, |
|
88 | + ]; |
|
89 | + } |
|
90 | + |
|
91 | + return $parameters; |
|
92 | + }, 10, 3); |
|
93 | + $entries = $view->get_entries(null); |
|
94 | + remove_filter('gravityview_get_entries', $filter); |
|
95 | + } else { |
|
96 | + $entries = $view->get_entries(null); |
|
97 | + |
|
98 | + /** If a sort already exists, reverse it. */ |
|
99 | + if ($sort = end($entries->sorts)) { |
|
100 | + $entries = $entries->sort(new \GV\Entry_Sort($sort->field, $sort->direction == \GV\Entry_Sort::RAND ?: ($sort->direction == \GV\Entry_Sort::ASC ? \GV\Entry_Sort::DESC : \GV\Entry_Sort::ASC)), $sort->mode); |
|
101 | + } else { |
|
102 | + /** Otherwise, sort by date_created */ |
|
103 | + $entries = $entries->sort(new \GV\Entry_Sort(\GV\Internal_Field::by_id('id'), \GV\Entry_Sort::ASC), \GV\Entry_Sort::NUMERIC); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + if (!$entry = $entries->first()) { |
|
108 | + return apply_filters('gravityview/shortcodes/gventry/output', '', $view, null, $atts); |
|
109 | + } |
|
110 | + break; |
|
111 | + case 'first': |
|
112 | + if (!$entry = $view->get_entries(null)->first()) { |
|
113 | + return apply_filters('gravityview/shortcodes/gventry/output', '', $view, null, $atts); |
|
114 | + } |
|
115 | + break; |
|
116 | + default: |
|
117 | + if (!$entry = \GV\GF_Entry::by_id($entry_id)) { |
|
118 | + gravityview()->log->error('Entry #{entry_id} not found', ['view_id' => $atts['view_id']]); |
|
119 | + |
|
120 | + return apply_filters('gravityview/shortcodes/gventry/output', '', $view, null, $atts); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + if ($view->form->ID != $entry['form_id']) { |
|
125 | + gravityview()->log->error('Entry does not belong to view (form mismatch)'); |
|
126 | + |
|
127 | + return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
128 | + } |
|
129 | + |
|
130 | + if (post_password_required($view->ID)) { |
|
131 | + gravityview()->log->notice('Post password is required for View #{view_id}', ['view_id' => $view->ID]); |
|
132 | + |
|
133 | + return apply_filters('gravityview/shortcodes/gventry/output', get_the_password_form($view->ID), $view, $entry, $atts); |
|
134 | + } |
|
135 | + |
|
136 | + if (!$view->form) { |
|
137 | + gravityview()->log->notice('View #{id} has no form attached to it.', ['id' => $view->ID]); |
|
138 | + |
|
139 | + /** |
|
140 | + * This View has no data source. There's nothing to show really. |
|
141 | + * ...apart from a nice message if the user can do anything about it. |
|
142 | + */ |
|
143 | + if (\GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview'], $view->ID)) { |
|
144 | + $return = sprintf(__('This View is not configured properly. Start by <a href="%s">selecting a form</a>.', 'gravityview'), esc_url(get_edit_post_link($view->ID, false))); |
|
145 | + |
|
146 | + return apply_filters('gravityview/shortcodes/gventry/output', $return, $view, $entry, $atts); |
|
147 | + } |
|
148 | + |
|
149 | + return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
150 | + } |
|
151 | + |
|
152 | + /** Private, pending, draft, etc. */ |
|
153 | + $public_states = get_post_stati(['public' => true]); |
|
154 | + if (!in_array($view->post_status, $public_states) && !\GVCommon::has_cap('read_gravityview', $view->ID)) { |
|
155 | + gravityview()->log->notice('The current user cannot access this View #{view_id}', ['view_id' => $view->ID]); |
|
156 | + |
|
157 | + return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
158 | + } |
|
159 | + |
|
160 | + /** Unapproved entries. */ |
|
161 | + if ($entry['status'] != 'active') { |
|
162 | + gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $entry->ID]); |
|
163 | + |
|
164 | + return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
165 | + } |
|
166 | + |
|
167 | + $is_admin_and_can_view = $view->settings->get('admin_show_all_statuses') && \GVCommon::has_cap('gravityview_moderate_entries', $view->ID); |
|
168 | + |
|
169 | + if ($view->settings->get('show_only_approved') && !$is_admin_and_can_view) { |
|
170 | + if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($entry->ID, \GravityView_Entry_Approval::meta_key))) { |
|
171 | + gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $entry->ID]); |
|
172 | + |
|
173 | + return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + if ($atts['edit']) { |
|
178 | + /** |
|
179 | + * Based on code in our unit-tests. |
|
180 | + * Mocks old context, etc. |
|
181 | + */ |
|
182 | + $loader = \GravityView_Edit_Entry::getInstance(); |
|
183 | + $render = $loader->instances['render']; |
|
184 | + |
|
185 | + add_filter('gravityview/is_single_entry', '__return_true'); |
|
186 | + |
|
187 | + $form = \GFAPI::get_form($entry['form_id']); |
|
188 | + |
|
189 | + $data = \GravityView_View_Data::getInstance($view); |
|
190 | + $template = \GravityView_View::getInstance([ |
|
191 | + 'form' => $form, |
|
192 | + 'form_id' => $form['id'], |
|
193 | + 'view_id' => $view->ID, |
|
194 | + 'entries' => [$entry], |
|
195 | + 'atts' => \GVCommon::get_template_settings($view->ID), |
|
196 | + ]); |
|
197 | + |
|
198 | + $_GET['edit'] = wp_create_nonce( |
|
199 | + \GravityView_Edit_Entry::get_nonce_key($view->ID, $form['id'], $entry['id']) |
|
200 | + ); |
|
201 | + |
|
202 | + add_filter('gravityview/edit_entry/success', $callback = function ($message) use ($view, $entry, $atts) { |
|
203 | + $message = __('Entry Updated', 'gravityview'); |
|
204 | + |
|
205 | + /** |
|
206 | + * @filter `gravityview/shortcodes/gventry/edit/success` Modify the edit entry success message in [gventry]. |
|
207 | + * |
|
208 | + * @since develop |
|
209 | + * |
|
210 | + * @param string $message The message. |
|
211 | + * @param \GV\View $view The View. |
|
212 | + * @param \GV\Entry $entry The entry. |
|
213 | + * @param array $atts The attributes. |
|
214 | + */ |
|
215 | + return apply_filters('gravityview/shortcodes/gventry/edit/success', $message, $view, $entry, $atts); |
|
216 | + }); |
|
217 | + |
|
218 | + ob_start() && $render->init($data, \GV\Entry::by_id($entry['id']), $view); |
|
219 | + $output = ob_get_clean(); // Render :) |
|
220 | + |
|
221 | + remove_filter('gravityview/is_single_entry', '__return_true'); |
|
222 | + remove_filter('gravityview/edit_entry/success', $callback); |
|
223 | + } else { |
|
224 | + /** Remove the back link. */ |
|
225 | + add_filter('gravityview/template/links/back/url', '__return_false'); |
|
226 | + |
|
227 | + $renderer = new \GV\Entry_Renderer(); |
|
228 | + |
|
229 | + $request = new \GV\Mock_Request(); |
|
230 | + $request->returns['is_entry'] = $entry; |
|
231 | + |
|
232 | + $output = $renderer->render($entry, $view, $request); |
|
233 | + |
|
234 | + remove_filter('gravityview/template/links/back/url', '__return_false'); |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @filter `gravityview/shortcodes/gventry/output` Filter the [gventry] output. |
|
239 | + * |
|
240 | + * @param string $output The output. |
|
241 | + * @param \GV\View|null $view The View detected or null. |
|
242 | + * @param \GV\Entry|null $entry The Entry or null. |
|
243 | + * |
|
244 | + * @since 2.0 |
|
245 | + */ |
|
246 | + return apply_filters('gravityview/shortcodes/gventry/output', $output, $view, $entry, $atts); |
|
247 | + } |
|
248 | 248 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace GV\Shortcodes; |
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | -if (!defined('GRAVITYVIEW_DIR')) { |
|
6 | +if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
7 | 7 | exit(); |
8 | 8 | } |
9 | 9 | |
@@ -26,22 +26,22 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return string|null The output. |
28 | 28 | */ |
29 | - public function callback($atts, $content = '', $tag = '') |
|
29 | + public function callback( $atts, $content = '', $tag = '' ) |
|
30 | 30 | { |
31 | 31 | $request = gravityview()->request; |
32 | 32 | |
33 | - if ($request->is_admin()) { |
|
34 | - return apply_filters('gravityview/shortcodes/gventry/output', '', null, null, $atts); |
|
33 | + if ( $request->is_admin() ) { |
|
34 | + return apply_filters( 'gravityview/shortcodes/gventry/output', '', null, null, $atts ); |
|
35 | 35 | } |
36 | 36 | |
37 | - $atts = wp_parse_args($atts, [ |
|
37 | + $atts = wp_parse_args( $atts, [ |
|
38 | 38 | 'id' => 0, |
39 | 39 | 'entry_id' => 0, |
40 | 40 | 'view_id' => 0, |
41 | 41 | 'edit' => 0, |
42 | - ]); |
|
42 | + ] ); |
|
43 | 43 | |
44 | - $atts = gv_map_deep($atts, ['GravityView_Merge_Tags', 'replace_get_variables']); |
|
44 | + $atts = gv_map_deep( $atts, [ 'GravityView_Merge_Tags', 'replace_get_variables' ] ); |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @filter `gravityview/shortcodes/gventry/atts` Filter the [gventry] shortcode attributes. |
@@ -50,38 +50,38 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @since 2.0 |
52 | 52 | */ |
53 | - $atts = apply_filters('gravityview/shortcodes/gventry/atts', $atts); |
|
53 | + $atts = apply_filters( 'gravityview/shortcodes/gventry/atts', $atts ); |
|
54 | 54 | |
55 | - $view = \GV\View::by_id($atts['view_id']); |
|
55 | + $view = \GV\View::by_id( $atts[ 'view_id' ] ); |
|
56 | 56 | |
57 | - if (!$view) { |
|
58 | - gravityview()->log->error('View does not exist #{view_id}', ['view_id' => $atts['view_id']]); |
|
57 | + if ( ! $view ) { |
|
58 | + gravityview()->log->error( 'View does not exist #{view_id}', [ 'view_id' => $atts[ 'view_id' ] ] ); |
|
59 | 59 | |
60 | - return apply_filters('gravityview/shortcodes/gventry/output', '', null, null, $atts); |
|
60 | + return apply_filters( 'gravityview/shortcodes/gventry/output', '', null, null, $atts ); |
|
61 | 61 | } |
62 | 62 | |
63 | - $entry_id = !empty($atts['entry_id']) ? $atts['entry_id'] : $atts['id']; |
|
63 | + $entry_id = ! empty( $atts[ 'entry_id' ] ) ? $atts[ 'entry_id' ] : $atts[ 'id' ]; |
|
64 | 64 | |
65 | - switch ($entry_id) { |
|
65 | + switch ( $entry_id ) { |
|
66 | 66 | case 'last': |
67 | - if (class_exists('\GF_Query')) { |
|
67 | + if ( class_exists( '\GF_Query' ) ) { |
|
68 | 68 | /** |
69 | 69 | * @todo Remove once we refactor the use of get_view_entries_parameters. |
70 | 70 | * |
71 | 71 | * Since we're using \GF_Query shorthand initialization we have to reverse the order parameters here. |
72 | 72 | */ |
73 | - add_filter('gravityview_get_entries', $filter = function ($parameters, $args, $form_id) { |
|
74 | - if (!empty($parameters['sorting'])) { |
|
73 | + add_filter( 'gravityview_get_entries', $filter = function( $parameters, $args, $form_id ) { |
|
74 | + if ( ! empty( $parameters[ 'sorting' ] ) ) { |
|
75 | 75 | /** |
76 | 76 | * Reverse existing sorts. |
77 | 77 | */ |
78 | - $sort = &$parameters['sorting']; |
|
79 | - $sort['direction'] = $sort['direction'] == 'RAND' ?: ($sort['direction'] == 'ASC' ? 'DESC' : 'ASC'); |
|
78 | + $sort = &$parameters[ 'sorting' ]; |
|
79 | + $sort[ 'direction' ] = $sort[ 'direction' ] == 'RAND' ?: ( $sort[ 'direction' ] == 'ASC' ? 'DESC' : 'ASC' ); |
|
80 | 80 | } else { |
81 | 81 | /** |
82 | 82 | * Otherwise, sort by date_created. |
83 | 83 | */ |
84 | - $parameters['sorting'] = [ |
|
84 | + $parameters[ 'sorting' ] = [ |
|
85 | 85 | 'key' => 'id', |
86 | 86 | 'direction' => 'ASC', |
87 | 87 | 'is_numeric' => true, |
@@ -89,118 +89,118 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | return $parameters; |
92 | - }, 10, 3); |
|
93 | - $entries = $view->get_entries(null); |
|
94 | - remove_filter('gravityview_get_entries', $filter); |
|
92 | + }, 10, 3 ); |
|
93 | + $entries = $view->get_entries( null ); |
|
94 | + remove_filter( 'gravityview_get_entries', $filter ); |
|
95 | 95 | } else { |
96 | - $entries = $view->get_entries(null); |
|
96 | + $entries = $view->get_entries( null ); |
|
97 | 97 | |
98 | 98 | /** If a sort already exists, reverse it. */ |
99 | - if ($sort = end($entries->sorts)) { |
|
100 | - $entries = $entries->sort(new \GV\Entry_Sort($sort->field, $sort->direction == \GV\Entry_Sort::RAND ?: ($sort->direction == \GV\Entry_Sort::ASC ? \GV\Entry_Sort::DESC : \GV\Entry_Sort::ASC)), $sort->mode); |
|
99 | + if ( $sort = end( $entries->sorts ) ) { |
|
100 | + $entries = $entries->sort( new \GV\Entry_Sort( $sort->field, $sort->direction == \GV\Entry_Sort::RAND ?: ( $sort->direction == \GV\Entry_Sort::ASC ? \GV\Entry_Sort::DESC : \GV\Entry_Sort::ASC ) ), $sort->mode ); |
|
101 | 101 | } else { |
102 | 102 | /** Otherwise, sort by date_created */ |
103 | - $entries = $entries->sort(new \GV\Entry_Sort(\GV\Internal_Field::by_id('id'), \GV\Entry_Sort::ASC), \GV\Entry_Sort::NUMERIC); |
|
103 | + $entries = $entries->sort( new \GV\Entry_Sort( \GV\Internal_Field::by_id( 'id' ), \GV\Entry_Sort::ASC ), \GV\Entry_Sort::NUMERIC ); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | - if (!$entry = $entries->first()) { |
|
108 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, null, $atts); |
|
107 | + if ( ! $entry = $entries->first() ) { |
|
108 | + return apply_filters( 'gravityview/shortcodes/gventry/output', '', $view, null, $atts ); |
|
109 | 109 | } |
110 | 110 | break; |
111 | 111 | case 'first': |
112 | - if (!$entry = $view->get_entries(null)->first()) { |
|
113 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, null, $atts); |
|
112 | + if ( ! $entry = $view->get_entries( null )->first() ) { |
|
113 | + return apply_filters( 'gravityview/shortcodes/gventry/output', '', $view, null, $atts ); |
|
114 | 114 | } |
115 | 115 | break; |
116 | 116 | default: |
117 | - if (!$entry = \GV\GF_Entry::by_id($entry_id)) { |
|
118 | - gravityview()->log->error('Entry #{entry_id} not found', ['view_id' => $atts['view_id']]); |
|
117 | + if ( ! $entry = \GV\GF_Entry::by_id( $entry_id ) ) { |
|
118 | + gravityview()->log->error( 'Entry #{entry_id} not found', [ 'view_id' => $atts[ 'view_id' ] ] ); |
|
119 | 119 | |
120 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, null, $atts); |
|
120 | + return apply_filters( 'gravityview/shortcodes/gventry/output', '', $view, null, $atts ); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - if ($view->form->ID != $entry['form_id']) { |
|
125 | - gravityview()->log->error('Entry does not belong to view (form mismatch)'); |
|
124 | + if ( $view->form->ID != $entry[ 'form_id' ] ) { |
|
125 | + gravityview()->log->error( 'Entry does not belong to view (form mismatch)' ); |
|
126 | 126 | |
127 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
127 | + return apply_filters( 'gravityview/shortcodes/gventry/output', '', $view, $entry, $atts ); |
|
128 | 128 | } |
129 | 129 | |
130 | - if (post_password_required($view->ID)) { |
|
131 | - gravityview()->log->notice('Post password is required for View #{view_id}', ['view_id' => $view->ID]); |
|
130 | + if ( post_password_required( $view->ID ) ) { |
|
131 | + gravityview()->log->notice( 'Post password is required for View #{view_id}', [ 'view_id' => $view->ID ] ); |
|
132 | 132 | |
133 | - return apply_filters('gravityview/shortcodes/gventry/output', get_the_password_form($view->ID), $view, $entry, $atts); |
|
133 | + return apply_filters( 'gravityview/shortcodes/gventry/output', get_the_password_form( $view->ID ), $view, $entry, $atts ); |
|
134 | 134 | } |
135 | 135 | |
136 | - if (!$view->form) { |
|
137 | - gravityview()->log->notice('View #{id} has no form attached to it.', ['id' => $view->ID]); |
|
136 | + if ( ! $view->form ) { |
|
137 | + gravityview()->log->notice( 'View #{id} has no form attached to it.', [ 'id' => $view->ID ] ); |
|
138 | 138 | |
139 | 139 | /** |
140 | 140 | * This View has no data source. There's nothing to show really. |
141 | 141 | * ...apart from a nice message if the user can do anything about it. |
142 | 142 | */ |
143 | - if (\GVCommon::has_cap(['edit_gravityviews', 'edit_gravityview'], $view->ID)) { |
|
144 | - $return = sprintf(__('This View is not configured properly. Start by <a href="%s">selecting a form</a>.', 'gravityview'), esc_url(get_edit_post_link($view->ID, false))); |
|
143 | + if ( \GVCommon::has_cap( [ 'edit_gravityviews', 'edit_gravityview' ], $view->ID ) ) { |
|
144 | + $return = sprintf( __( 'This View is not configured properly. Start by <a href="%s">selecting a form</a>.', 'gravityview' ), esc_url( get_edit_post_link( $view->ID, false ) ) ); |
|
145 | 145 | |
146 | - return apply_filters('gravityview/shortcodes/gventry/output', $return, $view, $entry, $atts); |
|
146 | + return apply_filters( 'gravityview/shortcodes/gventry/output', $return, $view, $entry, $atts ); |
|
147 | 147 | } |
148 | 148 | |
149 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
149 | + return apply_filters( 'gravityview/shortcodes/gventry/output', '', $view, $entry, $atts ); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** Private, pending, draft, etc. */ |
153 | - $public_states = get_post_stati(['public' => true]); |
|
154 | - if (!in_array($view->post_status, $public_states) && !\GVCommon::has_cap('read_gravityview', $view->ID)) { |
|
155 | - gravityview()->log->notice('The current user cannot access this View #{view_id}', ['view_id' => $view->ID]); |
|
153 | + $public_states = get_post_stati( [ 'public' => true ] ); |
|
154 | + if ( ! in_array( $view->post_status, $public_states ) && ! \GVCommon::has_cap( 'read_gravityview', $view->ID ) ) { |
|
155 | + gravityview()->log->notice( 'The current user cannot access this View #{view_id}', [ 'view_id' => $view->ID ] ); |
|
156 | 156 | |
157 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
157 | + return apply_filters( 'gravityview/shortcodes/gventry/output', '', $view, $entry, $atts ); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** Unapproved entries. */ |
161 | - if ($entry['status'] != 'active') { |
|
162 | - gravityview()->log->notice('Entry ID #{entry_id} is not active', ['entry_id' => $entry->ID]); |
|
161 | + if ( $entry[ 'status' ] != 'active' ) { |
|
162 | + gravityview()->log->notice( 'Entry ID #{entry_id} is not active', [ 'entry_id' => $entry->ID ] ); |
|
163 | 163 | |
164 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
164 | + return apply_filters( 'gravityview/shortcodes/gventry/output', '', $view, $entry, $atts ); |
|
165 | 165 | } |
166 | 166 | |
167 | - $is_admin_and_can_view = $view->settings->get('admin_show_all_statuses') && \GVCommon::has_cap('gravityview_moderate_entries', $view->ID); |
|
167 | + $is_admin_and_can_view = $view->settings->get( 'admin_show_all_statuses' ) && \GVCommon::has_cap( 'gravityview_moderate_entries', $view->ID ); |
|
168 | 168 | |
169 | - if ($view->settings->get('show_only_approved') && !$is_admin_and_can_view) { |
|
170 | - if (!\GravityView_Entry_Approval_Status::is_approved(gform_get_meta($entry->ID, \GravityView_Entry_Approval::meta_key))) { |
|
171 | - gravityview()->log->error('Entry ID #{entry_id} is not approved for viewing', ['entry_id' => $entry->ID]); |
|
169 | + if ( $view->settings->get( 'show_only_approved' ) && ! $is_admin_and_can_view ) { |
|
170 | + if ( ! \GravityView_Entry_Approval_Status::is_approved( gform_get_meta( $entry->ID, \GravityView_Entry_Approval::meta_key ) ) ) { |
|
171 | + gravityview()->log->error( 'Entry ID #{entry_id} is not approved for viewing', [ 'entry_id' => $entry->ID ] ); |
|
172 | 172 | |
173 | - return apply_filters('gravityview/shortcodes/gventry/output', '', $view, $entry, $atts); |
|
173 | + return apply_filters( 'gravityview/shortcodes/gventry/output', '', $view, $entry, $atts ); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
177 | - if ($atts['edit']) { |
|
177 | + if ( $atts[ 'edit' ] ) { |
|
178 | 178 | /** |
179 | 179 | * Based on code in our unit-tests. |
180 | 180 | * Mocks old context, etc. |
181 | 181 | */ |
182 | 182 | $loader = \GravityView_Edit_Entry::getInstance(); |
183 | - $render = $loader->instances['render']; |
|
183 | + $render = $loader->instances[ 'render' ]; |
|
184 | 184 | |
185 | - add_filter('gravityview/is_single_entry', '__return_true'); |
|
185 | + add_filter( 'gravityview/is_single_entry', '__return_true' ); |
|
186 | 186 | |
187 | - $form = \GFAPI::get_form($entry['form_id']); |
|
187 | + $form = \GFAPI::get_form( $entry[ 'form_id' ] ); |
|
188 | 188 | |
189 | - $data = \GravityView_View_Data::getInstance($view); |
|
190 | - $template = \GravityView_View::getInstance([ |
|
189 | + $data = \GravityView_View_Data::getInstance( $view ); |
|
190 | + $template = \GravityView_View::getInstance( [ |
|
191 | 191 | 'form' => $form, |
192 | - 'form_id' => $form['id'], |
|
192 | + 'form_id' => $form[ 'id' ], |
|
193 | 193 | 'view_id' => $view->ID, |
194 | - 'entries' => [$entry], |
|
195 | - 'atts' => \GVCommon::get_template_settings($view->ID), |
|
196 | - ]); |
|
194 | + 'entries' => [ $entry ], |
|
195 | + 'atts' => \GVCommon::get_template_settings( $view->ID ), |
|
196 | + ] ); |
|
197 | 197 | |
198 | - $_GET['edit'] = wp_create_nonce( |
|
199 | - \GravityView_Edit_Entry::get_nonce_key($view->ID, $form['id'], $entry['id']) |
|
198 | + $_GET[ 'edit' ] = wp_create_nonce( |
|
199 | + \GravityView_Edit_Entry::get_nonce_key( $view->ID, $form[ 'id' ], $entry[ 'id' ] ) |
|
200 | 200 | ); |
201 | 201 | |
202 | - add_filter('gravityview/edit_entry/success', $callback = function ($message) use ($view, $entry, $atts) { |
|
203 | - $message = __('Entry Updated', 'gravityview'); |
|
202 | + add_filter( 'gravityview/edit_entry/success', $callback = function( $message ) use ( $view, $entry, $atts ) { |
|
203 | + $message = __( 'Entry Updated', 'gravityview' ); |
|
204 | 204 | |
205 | 205 | /** |
206 | 206 | * @filter `gravityview/shortcodes/gventry/edit/success` Modify the edit entry success message in [gventry]. |
@@ -212,26 +212,26 @@ discard block |
||
212 | 212 | * @param \GV\Entry $entry The entry. |
213 | 213 | * @param array $atts The attributes. |
214 | 214 | */ |
215 | - return apply_filters('gravityview/shortcodes/gventry/edit/success', $message, $view, $entry, $atts); |
|
215 | + return apply_filters( 'gravityview/shortcodes/gventry/edit/success', $message, $view, $entry, $atts ); |
|
216 | 216 | }); |
217 | 217 | |
218 | - ob_start() && $render->init($data, \GV\Entry::by_id($entry['id']), $view); |
|
218 | + ob_start() && $render->init( $data, \GV\Entry::by_id( $entry[ 'id' ] ), $view ); |
|
219 | 219 | $output = ob_get_clean(); // Render :) |
220 | 220 | |
221 | - remove_filter('gravityview/is_single_entry', '__return_true'); |
|
222 | - remove_filter('gravityview/edit_entry/success', $callback); |
|
221 | + remove_filter( 'gravityview/is_single_entry', '__return_true' ); |
|
222 | + remove_filter( 'gravityview/edit_entry/success', $callback ); |
|
223 | 223 | } else { |
224 | 224 | /** Remove the back link. */ |
225 | - add_filter('gravityview/template/links/back/url', '__return_false'); |
|
225 | + add_filter( 'gravityview/template/links/back/url', '__return_false' ); |
|
226 | 226 | |
227 | 227 | $renderer = new \GV\Entry_Renderer(); |
228 | 228 | |
229 | 229 | $request = new \GV\Mock_Request(); |
230 | - $request->returns['is_entry'] = $entry; |
|
230 | + $request->returns[ 'is_entry' ] = $entry; |
|
231 | 231 | |
232 | - $output = $renderer->render($entry, $view, $request); |
|
232 | + $output = $renderer->render( $entry, $view, $request ); |
|
233 | 233 | |
234 | - remove_filter('gravityview/template/links/back/url', '__return_false'); |
|
234 | + remove_filter( 'gravityview/template/links/back/url', '__return_false' ); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -243,6 +243,6 @@ discard block |
||
243 | 243 | * |
244 | 244 | * @since 2.0 |
245 | 245 | */ |
246 | - return apply_filters('gravityview/shortcodes/gventry/output', $output, $view, $entry, $atts); |
|
246 | + return apply_filters( 'gravityview/shortcodes/gventry/output', $output, $view, $entry, $atts ); |
|
247 | 247 | } |
248 | 248 | } |
@@ -26,8 +26,7 @@ |
||
26 | 26 | * |
27 | 27 | * @return string|null The output. |
28 | 28 | */ |
29 | - public function callback($atts, $content = '', $tag = '') |
|
30 | - { |
|
29 | + public function callback($atts, $content = '', $tag = '') { |
|
31 | 30 | $request = gravityview()->request; |
32 | 31 | |
33 | 32 | if ($request->is_admin()) { |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | 6 | if (!defined('GRAVITYVIEW_DIR')) { |
7 | - exit(); |
|
7 | + exit(); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -12,94 +12,94 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Settings |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array Main storage for key-values in this collection. |
|
17 | - */ |
|
18 | - private $settings = []; |
|
15 | + /** |
|
16 | + * @var array Main storage for key-values in this collection. |
|
17 | + */ |
|
18 | + private $settings = []; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Create with new. |
|
22 | - * |
|
23 | - * @api |
|
24 | - * |
|
25 | - * @since 2.0 |
|
26 | - * |
|
27 | - * @param array $settings Initial settings. Default: none. |
|
28 | - * |
|
29 | - * @return \GV\Settings |
|
30 | - */ |
|
31 | - public function __construct($settings = []) |
|
32 | - { |
|
33 | - if (is_array($settings) && !empty($settings)) { |
|
34 | - $this->update($settings); |
|
35 | - } |
|
36 | - } |
|
20 | + /** |
|
21 | + * Create with new. |
|
22 | + * |
|
23 | + * @api |
|
24 | + * |
|
25 | + * @since 2.0 |
|
26 | + * |
|
27 | + * @param array $settings Initial settings. Default: none. |
|
28 | + * |
|
29 | + * @return \GV\Settings |
|
30 | + */ |
|
31 | + public function __construct($settings = []) |
|
32 | + { |
|
33 | + if (is_array($settings) && !empty($settings)) { |
|
34 | + $this->update($settings); |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Mass update values from the allowed ones. |
|
40 | - * |
|
41 | - * @api |
|
42 | - * |
|
43 | - * @since 2.0 |
|
44 | - * |
|
45 | - * @param array $settings An array of settings to update. |
|
46 | - * |
|
47 | - * @return \GV\Settings self chain. |
|
48 | - */ |
|
49 | - public function update($settings) |
|
50 | - { |
|
51 | - foreach ($settings as $key => $value) { |
|
52 | - $this->set($key, $value); |
|
53 | - } |
|
38 | + /** |
|
39 | + * Mass update values from the allowed ones. |
|
40 | + * |
|
41 | + * @api |
|
42 | + * |
|
43 | + * @since 2.0 |
|
44 | + * |
|
45 | + * @param array $settings An array of settings to update. |
|
46 | + * |
|
47 | + * @return \GV\Settings self chain. |
|
48 | + */ |
|
49 | + public function update($settings) |
|
50 | + { |
|
51 | + foreach ($settings as $key => $value) { |
|
52 | + $this->set($key, $value); |
|
53 | + } |
|
54 | 54 | |
55 | - return $this; |
|
56 | - } |
|
55 | + return $this; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Set a setting. |
|
60 | - * |
|
61 | - * @param mixed $key The key the value should be added under. |
|
62 | - * @param mixed $value The value to be added to the key. |
|
63 | - * |
|
64 | - * @api |
|
65 | - * |
|
66 | - * @since 2.0 |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - public function set($key, $value) |
|
71 | - { |
|
72 | - $this->settings[$key] = $value; |
|
73 | - } |
|
58 | + /** |
|
59 | + * Set a setting. |
|
60 | + * |
|
61 | + * @param mixed $key The key the value should be added under. |
|
62 | + * @param mixed $value The value to be added to the key. |
|
63 | + * |
|
64 | + * @api |
|
65 | + * |
|
66 | + * @since 2.0 |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + public function set($key, $value) |
|
71 | + { |
|
72 | + $this->settings[$key] = $value; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Set an setting. |
|
77 | - * |
|
78 | - * @param mixed $key The key in this setting to retrieve. |
|
79 | - * @param mixed $default A default in case the key is not set. |
|
80 | - * |
|
81 | - * @api |
|
82 | - * |
|
83 | - * @since 2.0 |
|
84 | - * |
|
85 | - * @return mixed|null |
|
86 | - */ |
|
87 | - public function get($key, $default = null) |
|
88 | - { |
|
89 | - return Utils::get($this->settings, $key, $default); |
|
90 | - } |
|
75 | + /** |
|
76 | + * Set an setting. |
|
77 | + * |
|
78 | + * @param mixed $key The key in this setting to retrieve. |
|
79 | + * @param mixed $default A default in case the key is not set. |
|
80 | + * |
|
81 | + * @api |
|
82 | + * |
|
83 | + * @since 2.0 |
|
84 | + * |
|
85 | + * @return mixed|null |
|
86 | + */ |
|
87 | + public function get($key, $default = null) |
|
88 | + { |
|
89 | + return Utils::get($this->settings, $key, $default); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Returns all the objects in this collection as an an array. |
|
94 | - * |
|
95 | - * @api |
|
96 | - * |
|
97 | - * @since 2.0 |
|
98 | - * |
|
99 | - * @return array The objects in this collection. |
|
100 | - */ |
|
101 | - public function all() |
|
102 | - { |
|
103 | - return $this->settings; |
|
104 | - } |
|
92 | + /** |
|
93 | + * Returns all the objects in this collection as an an array. |
|
94 | + * |
|
95 | + * @api |
|
96 | + * |
|
97 | + * @since 2.0 |
|
98 | + * |
|
99 | + * @return array The objects in this collection. |
|
100 | + */ |
|
101 | + public function all() |
|
102 | + { |
|
103 | + return $this->settings; |
|
104 | + } |
|
105 | 105 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace GV; |
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | -if (!defined('GRAVITYVIEW_DIR')) { |
|
6 | +if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
7 | 7 | exit(); |
8 | 8 | } |
9 | 9 | |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | /** |
16 | 16 | * @var array Main storage for key-values in this collection. |
17 | 17 | */ |
18 | - private $settings = []; |
|
18 | + private $settings = [ ]; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Create with new. |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return \GV\Settings |
30 | 30 | */ |
31 | - public function __construct($settings = []) |
|
31 | + public function __construct( $settings = [ ] ) |
|
32 | 32 | { |
33 | - if (is_array($settings) && !empty($settings)) { |
|
34 | - $this->update($settings); |
|
33 | + if ( is_array( $settings ) && ! empty( $settings ) ) { |
|
34 | + $this->update( $settings ); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return \GV\Settings self chain. |
48 | 48 | */ |
49 | - public function update($settings) |
|
49 | + public function update( $settings ) |
|
50 | 50 | { |
51 | - foreach ($settings as $key => $value) { |
|
52 | - $this->set($key, $value); |
|
51 | + foreach ( $settings as $key => $value ) { |
|
52 | + $this->set( $key, $value ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | return $this; |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return void |
69 | 69 | */ |
70 | - public function set($key, $value) |
|
70 | + public function set( $key, $value ) |
|
71 | 71 | { |
72 | - $this->settings[$key] = $value; |
|
72 | + $this->settings[ $key ] = $value; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @return mixed|null |
86 | 86 | */ |
87 | - public function get($key, $default = null) |
|
87 | + public function get( $key, $default = null ) |
|
88 | 88 | { |
89 | - return Utils::get($this->settings, $key, $default); |
|
89 | + return Utils::get( $this->settings, $key, $default ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -10,8 +10,7 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * A generic Settings base class. |
12 | 12 | */ |
13 | -class Settings |
|
14 | -{ |
|
13 | +class Settings { |
|
15 | 14 | /** |
16 | 15 | * @var array Main storage for key-values in this collection. |
17 | 16 | */ |
@@ -28,8 +27,7 @@ discard block |
||
28 | 27 | * |
29 | 28 | * @return \GV\Settings |
30 | 29 | */ |
31 | - public function __construct($settings = []) |
|
32 | - { |
|
30 | + public function __construct($settings = []) { |
|
33 | 31 | if (is_array($settings) && !empty($settings)) { |
34 | 32 | $this->update($settings); |
35 | 33 | } |
@@ -46,8 +44,7 @@ discard block |
||
46 | 44 | * |
47 | 45 | * @return \GV\Settings self chain. |
48 | 46 | */ |
49 | - public function update($settings) |
|
50 | - { |
|
47 | + public function update($settings) { |
|
51 | 48 | foreach ($settings as $key => $value) { |
52 | 49 | $this->set($key, $value); |
53 | 50 | } |
@@ -67,8 +64,7 @@ discard block |
||
67 | 64 | * |
68 | 65 | * @return void |
69 | 66 | */ |
70 | - public function set($key, $value) |
|
71 | - { |
|
67 | + public function set($key, $value) { |
|
72 | 68 | $this->settings[$key] = $value; |
73 | 69 | } |
74 | 70 | |
@@ -84,8 +80,7 @@ discard block |
||
84 | 80 | * |
85 | 81 | * @return mixed|null |
86 | 82 | */ |
87 | - public function get($key, $default = null) |
|
88 | - { |
|
83 | + public function get($key, $default = null) { |
|
89 | 84 | return Utils::get($this->settings, $key, $default); |
90 | 85 | } |
91 | 86 | |
@@ -98,8 +93,7 @@ discard block |
||
98 | 93 | * |
99 | 94 | * @return array The objects in this collection. |
100 | 95 | */ |
101 | - public function all() |
|
102 | - { |
|
96 | + public function all() { |
|
103 | 97 | return $this->settings; |
104 | 98 | } |
105 | 99 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | 6 | if (!defined('GRAVITYVIEW_DIR')) { |
7 | - exit(); |
|
7 | + exit(); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -12,47 +12,47 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Form_Collection extends Collection |
14 | 14 | { |
15 | - /** |
|
16 | - * Add a \GV\Form to this collection. |
|
17 | - * |
|
18 | - * @param \GV\Form $form The form to add to the internal array. |
|
19 | - * |
|
20 | - * @api |
|
21 | - * |
|
22 | - * @since 2.0 |
|
23 | - * |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - public function add($form) |
|
27 | - { |
|
28 | - if (!$form instanceof Form) { |
|
29 | - gravityview()->log->error('Form_Collections can only contain objects of type \GV\Form.'); |
|
15 | + /** |
|
16 | + * Add a \GV\Form to this collection. |
|
17 | + * |
|
18 | + * @param \GV\Form $form The form to add to the internal array. |
|
19 | + * |
|
20 | + * @api |
|
21 | + * |
|
22 | + * @since 2.0 |
|
23 | + * |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + public function add($form) |
|
27 | + { |
|
28 | + if (!$form instanceof Form) { |
|
29 | + gravityview()->log->error('Form_Collections can only contain objects of type \GV\Form.'); |
|
30 | 30 | |
31 | - return; |
|
32 | - } |
|
33 | - parent::add($form); |
|
34 | - } |
|
31 | + return; |
|
32 | + } |
|
33 | + parent::add($form); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get a \GV\Form from this list. |
|
38 | - * |
|
39 | - * @param int $form_id The ID of the form to get. |
|
40 | - * @param string $backend The form backend identifier, allows for multiple form backends in the future. Unused until then. |
|
41 | - * |
|
42 | - * @api |
|
43 | - * |
|
44 | - * @since 2.0 |
|
45 | - * |
|
46 | - * @return \GV\Form|null The \GV\Form with the $form_id as the ID, or null if not found. |
|
47 | - */ |
|
48 | - public function get($form_id, $backend = 'gravityforms') |
|
49 | - { |
|
50 | - foreach ($this->all() as $form) { |
|
51 | - if ($form->ID == $form_id) { |
|
52 | - return $form; |
|
53 | - } |
|
54 | - } |
|
36 | + /** |
|
37 | + * Get a \GV\Form from this list. |
|
38 | + * |
|
39 | + * @param int $form_id The ID of the form to get. |
|
40 | + * @param string $backend The form backend identifier, allows for multiple form backends in the future. Unused until then. |
|
41 | + * |
|
42 | + * @api |
|
43 | + * |
|
44 | + * @since 2.0 |
|
45 | + * |
|
46 | + * @return \GV\Form|null The \GV\Form with the $form_id as the ID, or null if not found. |
|
47 | + */ |
|
48 | + public function get($form_id, $backend = 'gravityforms') |
|
49 | + { |
|
50 | + foreach ($this->all() as $form) { |
|
51 | + if ($form->ID == $form_id) { |
|
52 | + return $form; |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | - return null; |
|
57 | - } |
|
56 | + return null; |
|
57 | + } |
|
58 | 58 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace GV; |
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | -if (!defined('GRAVITYVIEW_DIR')) { |
|
6 | +if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
7 | 7 | exit(); |
8 | 8 | } |
9 | 9 | |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return void |
25 | 25 | */ |
26 | - public function add($form) |
|
26 | + public function add( $form ) |
|
27 | 27 | { |
28 | - if (!$form instanceof Form) { |
|
29 | - gravityview()->log->error('Form_Collections can only contain objects of type \GV\Form.'); |
|
28 | + if ( ! $form instanceof Form ) { |
|
29 | + gravityview()->log->error( 'Form_Collections can only contain objects of type \GV\Form.' ); |
|
30 | 30 | |
31 | 31 | return; |
32 | 32 | } |
33 | - parent::add($form); |
|
33 | + parent::add( $form ); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @return \GV\Form|null The \GV\Form with the $form_id as the ID, or null if not found. |
47 | 47 | */ |
48 | - public function get($form_id, $backend = 'gravityforms') |
|
48 | + public function get( $form_id, $backend = 'gravityforms' ) |
|
49 | 49 | { |
50 | - foreach ($this->all() as $form) { |
|
51 | - if ($form->ID == $form_id) { |
|
50 | + foreach ( $this->all() as $form ) { |
|
51 | + if ( $form->ID == $form_id ) { |
|
52 | 52 | return $form; |
53 | 53 | } |
54 | 54 | } |
@@ -10,8 +10,7 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * A collection of \GV\Form objects. |
12 | 12 | */ |
13 | -class Form_Collection extends Collection |
|
14 | -{ |
|
13 | +class Form_Collection extends Collection { |
|
15 | 14 | /** |
16 | 15 | * Add a \GV\Form to this collection. |
17 | 16 | * |
@@ -23,8 +22,7 @@ discard block |
||
23 | 22 | * |
24 | 23 | * @return void |
25 | 24 | */ |
26 | - public function add($form) |
|
27 | - { |
|
25 | + public function add($form) { |
|
28 | 26 | if (!$form instanceof Form) { |
29 | 27 | gravityview()->log->error('Form_Collections can only contain objects of type \GV\Form.'); |
30 | 28 | |
@@ -45,8 +43,7 @@ discard block |
||
45 | 43 | * |
46 | 44 | * @return \GV\Form|null The \GV\Form with the $form_id as the ID, or null if not found. |
47 | 45 | */ |
48 | - public function get($form_id, $backend = 'gravityforms') |
|
49 | - { |
|
46 | + public function get($form_id, $backend = 'gravityforms') { |
|
50 | 47 | foreach ($this->all() as $form) { |
51 | 48 | if ($form->ID == $form_id) { |
52 | 49 | return $form; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | 6 | if (!defined('GRAVITYVIEW_DIR')) { |
7 | - exit(); |
|
7 | + exit(); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | /** |
@@ -14,291 +14,291 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class View_List_Template extends View_Template |
16 | 16 | { |
17 | - /** |
|
18 | - * @var string The template slug to be loaded (like "table", "list") |
|
19 | - */ |
|
20 | - public static $slug = 'list'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Output the field in the list view. |
|
24 | - * |
|
25 | - * @param \GV\Field $field The field to output. |
|
26 | - * @param \GV\Entry $entry The entry. |
|
27 | - * @param array $extras Extra stuff, like wpautop, etc. |
|
28 | - * |
|
29 | - * @return string |
|
30 | - */ |
|
31 | - public function the_field(\GV\Field $field, \GV\Entry $entry, $extras = null) |
|
32 | - { |
|
33 | - $form = $this->view->form; |
|
34 | - |
|
35 | - if (isset($this->view->unions[$entry['form_id']])) { |
|
36 | - if (isset($this->view->unions[$entry['form_id']][$field->ID])) { |
|
37 | - $field = $this->view->unions[$entry['form_id']][$field->ID]; |
|
38 | - } elseif (!$field instanceof Internal_Field) { |
|
39 | - $field = Internal_Field::from_configuration(['id' => 'custom']); |
|
40 | - } |
|
41 | - } |
|
42 | - |
|
43 | - if ($entry->is_multi()) { |
|
44 | - if (!$single_entry = $entry->from_field($field)) { |
|
45 | - return; |
|
46 | - } |
|
47 | - $form = GF_Form::by_id($field->form_id); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Push legacy entry context. |
|
52 | - */ |
|
53 | - \GV\Mocks\Legacy_Context::load([ |
|
54 | - 'entry' => $entry, |
|
55 | - 'form' => $form, |
|
56 | - ]); |
|
57 | - |
|
58 | - $context = Template_Context::from_template($this, compact('field', 'entry')); |
|
59 | - |
|
60 | - $renderer = new Field_Renderer(); |
|
61 | - $source = is_numeric($field->ID) ? $form : new Internal_Source(); |
|
62 | - |
|
63 | - $value = $renderer->render($field, $this->view, $source, $entry, $this->request); |
|
64 | - |
|
65 | - /** |
|
66 | - * @deprecated Here for back-compatibility. |
|
67 | - */ |
|
68 | - $label = apply_filters('gravityview_render_after_label', $field->get_label($this->view, $form, $entry), $field->as_configuration()); |
|
69 | - $label = apply_filters('gravityview/template/field_label', $label, $field->as_configuration(), $form->form ? $form->form : null, null); |
|
70 | - |
|
71 | - /** |
|
72 | - * @filter `gravityview/template/field/label` Override the field label. |
|
73 | - * |
|
74 | - * @since 2.0 |
|
75 | - * |
|
76 | - * @param string $label The label to override. |
|
77 | - * @param \GV\Template_Context $context The context. |
|
78 | - */ |
|
79 | - $label = apply_filters('gravityview/template/field/label', $label, $context); |
|
80 | - |
|
81 | - /** |
|
82 | - * @filter `gravityview/template/table/entry/hide_empty` |
|
83 | - * |
|
84 | - * @param bool Should the row be hidden if the value is empty? Default: don't hide. |
|
85 | - * @param \GV\Template_Context $context The context ;) Love it, cherish it. And don't you dare modify it! |
|
86 | - */ |
|
87 | - $hide_empty = apply_filters('gravityview/render/hide-empty-zone', Utils::get($extras, 'hide_empty', $this->view->settings->get('hide_empty', false)), $context); |
|
88 | - |
|
89 | - if (is_numeric($field->ID)) { |
|
90 | - $extras['field'] = $field->as_configuration(); |
|
91 | - } |
|
92 | - |
|
93 | - $extras['entry'] = $entry->as_entry(); |
|
94 | - $extras['hide_empty'] = $hide_empty; |
|
95 | - $extras['label'] = $label; |
|
96 | - $extras['value'] = $value; |
|
97 | - |
|
98 | - return \gravityview_field_output($extras, $context); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Return an array of variables ready to be extracted. |
|
103 | - * |
|
104 | - * @param string|array $zones The field zones to grab. |
|
105 | - * |
|
106 | - * @return array An array ready to be extract()ed in the form of |
|
107 | - * $zone => \GV\Field_Collection |
|
108 | - * has_$zone => int |
|
109 | - */ |
|
110 | - public function extract_zone_vars($zones) |
|
111 | - { |
|
112 | - if (!is_array($zones)) { |
|
113 | - $zones = [$zones]; |
|
114 | - } |
|
115 | - |
|
116 | - $vars = []; |
|
117 | - foreach ($zones as $zone) { |
|
118 | - $zone_var = str_replace('-', '_', $zone); |
|
119 | - $vars[$zone_var] = $this->view->fields->by_position('directory_list-'.$zone)->by_visible($this->view); |
|
120 | - $vars["has_$zone_var"] = $vars[$zone_var]->count(); |
|
121 | - } |
|
122 | - |
|
123 | - return $vars; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * `gravityview_entry_class` and `gravityview/template/list/entry/class` filters. |
|
128 | - * |
|
129 | - * Modify of the class of a row. |
|
130 | - * |
|
131 | - * @param string $class The class. |
|
132 | - * @param \GV\Entry $entry The entry. |
|
133 | - * @param \GV\Template_Context The context. |
|
134 | - * |
|
135 | - * @return string The classes. |
|
136 | - */ |
|
137 | - public static function entry_class($class, $entry, $context) |
|
138 | - { |
|
139 | - /** |
|
140 | - * @filter `gravityview_entry_class` Modify the class applied to the entry row. |
|
141 | - * |
|
142 | - * @param string $class Existing class. |
|
143 | - * @param array $entry Current entry being displayed |
|
144 | - * @param \GravityView_View $this Current GravityView_View object |
|
145 | - * |
|
146 | - * @deprecated Use `gravityview/template/list/entry/class` |
|
147 | - * |
|
148 | - * @return string The modified class. |
|
149 | - */ |
|
150 | - $class = apply_filters('gravityview_entry_class', $class, $entry->as_entry(), \GravityView_View::getInstance()); |
|
151 | - |
|
152 | - /** |
|
153 | - * @filter `gravityview/template/list/entry/class` Modify the class aplied to the entry row. |
|
154 | - * |
|
155 | - * @param string $class The existing class. |
|
156 | - * @param \GV\Template_Context The context. |
|
157 | - * |
|
158 | - * @return string The modified class. |
|
159 | - */ |
|
160 | - return apply_filters('gravityview/template/list/entry/class', $class, Template_Context::from_template($context->template, compact('entry'))); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * `gravityview_list_body_before` and `gravityview/template/list/body/before` actions. |
|
165 | - * |
|
166 | - * Output inside the `tbody` of the list. |
|
167 | - * |
|
168 | - * @param $context \GV\Template_Context The 2.0 context. |
|
169 | - * |
|
170 | - * @return void |
|
171 | - */ |
|
172 | - public static function body_before($context) |
|
173 | - { |
|
174 | - /** |
|
175 | - * @action `gravityview/template/list/body/before` Output inside the `tbody` of the list. |
|
176 | - * |
|
177 | - * @since 2.0 |
|
178 | - * |
|
179 | - * @param \GV\Template_Context $context The template context. |
|
180 | - */ |
|
181 | - do_action('gravityview/template/list/body/before', $context); |
|
182 | - |
|
183 | - /** |
|
184 | - * @action `gravityview_list_body_before` Inside the `tbody`, before any rows are rendered. Can be used to insert additional rows. |
|
185 | - * |
|
186 | - * @deprecated Use `gravityview/template/list/body/before` |
|
187 | - * @since 1.0.7 |
|
188 | - * |
|
189 | - * @param \GravityView_View $gravityview_view Current GravityView_View object. |
|
190 | - */ |
|
191 | - do_action('gravityview_list_body_before', \GravityView_View::getInstance() /** ugh! */); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * `gravityview_list_body_after` and `gravityview/template/list/body/after` actions. |
|
196 | - * |
|
197 | - * Output inside the `tbody` of the list. |
|
198 | - * |
|
199 | - * @param $context \GV\Template_Context The 2.0 context. |
|
200 | - * |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - public static function body_after($context) |
|
204 | - { |
|
205 | - /** |
|
206 | - * @action `gravityview/template/list/body/after` Output inside the `tbody` of the list at the end. |
|
207 | - * |
|
208 | - * @since 2.0 |
|
209 | - * |
|
210 | - * @param \GV\Template_Context $context The template context. |
|
211 | - */ |
|
212 | - do_action('gravityview/template/list/body/after', $context); |
|
213 | - |
|
214 | - /** |
|
215 | - * @action `gravityview_list_body_after` Inside the `tbody`, after any rows are rendered. Can be used to insert additional rows. |
|
216 | - * |
|
217 | - * @deprecated Use `gravityview/template/list/body/after` |
|
218 | - * @since 1.0.7 |
|
219 | - * |
|
220 | - * @param \GravityView_View $gravityview_view Current GravityView_View object. |
|
221 | - */ |
|
222 | - do_action('gravityview_list_body_after', \GravityView_View::getInstance() /** ugh! */); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * `gravityview_list_entry_before` and `gravityview/template/list/entry/before` actions. |
|
227 | - * `gravityview_list_entry_title_before` and `gravityview/template/list/entry/title/before` actions. |
|
228 | - * `gravityview_list_entry_content_before` and `gravityview/template/list/entry/content/before` actions. |
|
229 | - * `gravityview_list_entry_footer_before` and `gravityview/template/list/entry/footer/before` actions. |
|
230 | - * |
|
231 | - * Output inside the `entry` of the list. |
|
232 | - * |
|
233 | - * @param \GV\Entry $entry The entry. |
|
234 | - * @param \GV\Template_Context $context The 2.0 context. |
|
235 | - * @param string $zone The list zone (footer, image, title, etc.). |
|
236 | - * |
|
237 | - * @return void |
|
238 | - */ |
|
239 | - public static function entry_before($entry, $context, $zone = '') |
|
240 | - { |
|
241 | - $zone = str_replace('//', '/', "/$zone/"); |
|
242 | - |
|
243 | - /** |
|
244 | - * @action `gravityview/template/list/entry/$zone/before` Output inside the `entry` of the list at the end. |
|
245 | - * |
|
246 | - * @since 2.0 |
|
247 | - * |
|
248 | - * @param \GV\Template_Context $context The template context. |
|
249 | - */ |
|
250 | - do_action(sprintf('gravityview/template/list/entry%sbefore', $zone), Template_Context::from_template($context->template, compact('entry'))); |
|
251 | - |
|
252 | - $zone = str_replace('/', '_', $zone); |
|
253 | - |
|
254 | - /** |
|
255 | - * @action `gravityview_list_entry_$zone_before` Inside the `entry`, before any rows are rendered. Can be used to insert additional rows. |
|
256 | - * |
|
257 | - * @deprecated Use `gravityview/template/list/entry/$zone/before` |
|
258 | - * @since 1.0.7 |
|
259 | - * |
|
260 | - * @param \GravityView_View $gravityview_view Current GravityView_View object. |
|
261 | - */ |
|
262 | - do_action(sprintf('gravityview_list_entry%sbefore', $zone), $entry->as_entry(), \GravityView_View::getInstance() /** ugh! */); |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * `gravityview_list_entry_after` and `gravityview/template/list/entry/after` actions. |
|
267 | - * `gravityview_list_entry_title_after` and `gravityview/template/list/entry/title/after` actions. |
|
268 | - * `gravityview_list_entry_content_after` and `gravityview/template/list/entry/content/after` actions. |
|
269 | - * `gravityview_list_entry_footer_after` and `gravityview/template/list/entry/footer/after` actions. |
|
270 | - * |
|
271 | - * Output inside the `entry` of the list. |
|
272 | - * |
|
273 | - * @param \GV\Entry $entry The entry. |
|
274 | - * @param \GV\Template_Context $context The 2.0 context. |
|
275 | - * @param string $zone The list zone (footer, image, title, etc.). |
|
276 | - * |
|
277 | - * @return void |
|
278 | - */ |
|
279 | - public static function entry_after($entry, $context, $zone = '') |
|
280 | - { |
|
281 | - $zone = str_replace('//', '/', "/$zone/"); |
|
282 | - |
|
283 | - /** |
|
284 | - * @action `gravityview/template/list/entry/$zone/after` Output inside the `entry` of the list at the end. |
|
285 | - * |
|
286 | - * @since 2.0 |
|
287 | - * |
|
288 | - * @param \GV\Template_Context $context The template context. |
|
289 | - */ |
|
290 | - do_action(sprintf('gravityview/template/list/entry%safter', $zone), Template_Context::from_template($context->template, compact('entry'))); |
|
291 | - |
|
292 | - $zone = str_replace('/', '_', $zone); |
|
293 | - |
|
294 | - /** |
|
295 | - * @action `gravityview_list_entry_$zone_after` Inside the `entry`, after any rows are rendered. Can be used to insert additional rows. |
|
296 | - * |
|
297 | - * @deprecated Use `gravityview/template/list/entry/after` |
|
298 | - * @since 1.0.7 |
|
299 | - * |
|
300 | - * @param \GravityView_View $gravityview_view Current GravityView_View object. |
|
301 | - */ |
|
302 | - do_action(sprintf('gravityview_list_entry%safter', $zone), $entry->as_entry(), \GravityView_View::getInstance() /** ugh! */); |
|
303 | - } |
|
17 | + /** |
|
18 | + * @var string The template slug to be loaded (like "table", "list") |
|
19 | + */ |
|
20 | + public static $slug = 'list'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Output the field in the list view. |
|
24 | + * |
|
25 | + * @param \GV\Field $field The field to output. |
|
26 | + * @param \GV\Entry $entry The entry. |
|
27 | + * @param array $extras Extra stuff, like wpautop, etc. |
|
28 | + * |
|
29 | + * @return string |
|
30 | + */ |
|
31 | + public function the_field(\GV\Field $field, \GV\Entry $entry, $extras = null) |
|
32 | + { |
|
33 | + $form = $this->view->form; |
|
34 | + |
|
35 | + if (isset($this->view->unions[$entry['form_id']])) { |
|
36 | + if (isset($this->view->unions[$entry['form_id']][$field->ID])) { |
|
37 | + $field = $this->view->unions[$entry['form_id']][$field->ID]; |
|
38 | + } elseif (!$field instanceof Internal_Field) { |
|
39 | + $field = Internal_Field::from_configuration(['id' => 'custom']); |
|
40 | + } |
|
41 | + } |
|
42 | + |
|
43 | + if ($entry->is_multi()) { |
|
44 | + if (!$single_entry = $entry->from_field($field)) { |
|
45 | + return; |
|
46 | + } |
|
47 | + $form = GF_Form::by_id($field->form_id); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Push legacy entry context. |
|
52 | + */ |
|
53 | + \GV\Mocks\Legacy_Context::load([ |
|
54 | + 'entry' => $entry, |
|
55 | + 'form' => $form, |
|
56 | + ]); |
|
57 | + |
|
58 | + $context = Template_Context::from_template($this, compact('field', 'entry')); |
|
59 | + |
|
60 | + $renderer = new Field_Renderer(); |
|
61 | + $source = is_numeric($field->ID) ? $form : new Internal_Source(); |
|
62 | + |
|
63 | + $value = $renderer->render($field, $this->view, $source, $entry, $this->request); |
|
64 | + |
|
65 | + /** |
|
66 | + * @deprecated Here for back-compatibility. |
|
67 | + */ |
|
68 | + $label = apply_filters('gravityview_render_after_label', $field->get_label($this->view, $form, $entry), $field->as_configuration()); |
|
69 | + $label = apply_filters('gravityview/template/field_label', $label, $field->as_configuration(), $form->form ? $form->form : null, null); |
|
70 | + |
|
71 | + /** |
|
72 | + * @filter `gravityview/template/field/label` Override the field label. |
|
73 | + * |
|
74 | + * @since 2.0 |
|
75 | + * |
|
76 | + * @param string $label The label to override. |
|
77 | + * @param \GV\Template_Context $context The context. |
|
78 | + */ |
|
79 | + $label = apply_filters('gravityview/template/field/label', $label, $context); |
|
80 | + |
|
81 | + /** |
|
82 | + * @filter `gravityview/template/table/entry/hide_empty` |
|
83 | + * |
|
84 | + * @param bool Should the row be hidden if the value is empty? Default: don't hide. |
|
85 | + * @param \GV\Template_Context $context The context ;) Love it, cherish it. And don't you dare modify it! |
|
86 | + */ |
|
87 | + $hide_empty = apply_filters('gravityview/render/hide-empty-zone', Utils::get($extras, 'hide_empty', $this->view->settings->get('hide_empty', false)), $context); |
|
88 | + |
|
89 | + if (is_numeric($field->ID)) { |
|
90 | + $extras['field'] = $field->as_configuration(); |
|
91 | + } |
|
92 | + |
|
93 | + $extras['entry'] = $entry->as_entry(); |
|
94 | + $extras['hide_empty'] = $hide_empty; |
|
95 | + $extras['label'] = $label; |
|
96 | + $extras['value'] = $value; |
|
97 | + |
|
98 | + return \gravityview_field_output($extras, $context); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Return an array of variables ready to be extracted. |
|
103 | + * |
|
104 | + * @param string|array $zones The field zones to grab. |
|
105 | + * |
|
106 | + * @return array An array ready to be extract()ed in the form of |
|
107 | + * $zone => \GV\Field_Collection |
|
108 | + * has_$zone => int |
|
109 | + */ |
|
110 | + public function extract_zone_vars($zones) |
|
111 | + { |
|
112 | + if (!is_array($zones)) { |
|
113 | + $zones = [$zones]; |
|
114 | + } |
|
115 | + |
|
116 | + $vars = []; |
|
117 | + foreach ($zones as $zone) { |
|
118 | + $zone_var = str_replace('-', '_', $zone); |
|
119 | + $vars[$zone_var] = $this->view->fields->by_position('directory_list-'.$zone)->by_visible($this->view); |
|
120 | + $vars["has_$zone_var"] = $vars[$zone_var]->count(); |
|
121 | + } |
|
122 | + |
|
123 | + return $vars; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * `gravityview_entry_class` and `gravityview/template/list/entry/class` filters. |
|
128 | + * |
|
129 | + * Modify of the class of a row. |
|
130 | + * |
|
131 | + * @param string $class The class. |
|
132 | + * @param \GV\Entry $entry The entry. |
|
133 | + * @param \GV\Template_Context The context. |
|
134 | + * |
|
135 | + * @return string The classes. |
|
136 | + */ |
|
137 | + public static function entry_class($class, $entry, $context) |
|
138 | + { |
|
139 | + /** |
|
140 | + * @filter `gravityview_entry_class` Modify the class applied to the entry row. |
|
141 | + * |
|
142 | + * @param string $class Existing class. |
|
143 | + * @param array $entry Current entry being displayed |
|
144 | + * @param \GravityView_View $this Current GravityView_View object |
|
145 | + * |
|
146 | + * @deprecated Use `gravityview/template/list/entry/class` |
|
147 | + * |
|
148 | + * @return string The modified class. |
|
149 | + */ |
|
150 | + $class = apply_filters('gravityview_entry_class', $class, $entry->as_entry(), \GravityView_View::getInstance()); |
|
151 | + |
|
152 | + /** |
|
153 | + * @filter `gravityview/template/list/entry/class` Modify the class aplied to the entry row. |
|
154 | + * |
|
155 | + * @param string $class The existing class. |
|
156 | + * @param \GV\Template_Context The context. |
|
157 | + * |
|
158 | + * @return string The modified class. |
|
159 | + */ |
|
160 | + return apply_filters('gravityview/template/list/entry/class', $class, Template_Context::from_template($context->template, compact('entry'))); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * `gravityview_list_body_before` and `gravityview/template/list/body/before` actions. |
|
165 | + * |
|
166 | + * Output inside the `tbody` of the list. |
|
167 | + * |
|
168 | + * @param $context \GV\Template_Context The 2.0 context. |
|
169 | + * |
|
170 | + * @return void |
|
171 | + */ |
|
172 | + public static function body_before($context) |
|
173 | + { |
|
174 | + /** |
|
175 | + * @action `gravityview/template/list/body/before` Output inside the `tbody` of the list. |
|
176 | + * |
|
177 | + * @since 2.0 |
|
178 | + * |
|
179 | + * @param \GV\Template_Context $context The template context. |
|
180 | + */ |
|
181 | + do_action('gravityview/template/list/body/before', $context); |
|
182 | + |
|
183 | + /** |
|
184 | + * @action `gravityview_list_body_before` Inside the `tbody`, before any rows are rendered. Can be used to insert additional rows. |
|
185 | + * |
|
186 | + * @deprecated Use `gravityview/template/list/body/before` |
|
187 | + * @since 1.0.7 |
|
188 | + * |
|
189 | + * @param \GravityView_View $gravityview_view Current GravityView_View object. |
|
190 | + */ |
|
191 | + do_action('gravityview_list_body_before', \GravityView_View::getInstance() /** ugh! */); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * `gravityview_list_body_after` and `gravityview/template/list/body/after` actions. |
|
196 | + * |
|
197 | + * Output inside the `tbody` of the list. |
|
198 | + * |
|
199 | + * @param $context \GV\Template_Context The 2.0 context. |
|
200 | + * |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + public static function body_after($context) |
|
204 | + { |
|
205 | + /** |
|
206 | + * @action `gravityview/template/list/body/after` Output inside the `tbody` of the list at the end. |
|
207 | + * |
|
208 | + * @since 2.0 |
|
209 | + * |
|
210 | + * @param \GV\Template_Context $context The template context. |
|
211 | + */ |
|
212 | + do_action('gravityview/template/list/body/after', $context); |
|
213 | + |
|
214 | + /** |
|
215 | + * @action `gravityview_list_body_after` Inside the `tbody`, after any rows are rendered. Can be used to insert additional rows. |
|
216 | + * |
|
217 | + * @deprecated Use `gravityview/template/list/body/after` |
|
218 | + * @since 1.0.7 |
|
219 | + * |
|
220 | + * @param \GravityView_View $gravityview_view Current GravityView_View object. |
|
221 | + */ |
|
222 | + do_action('gravityview_list_body_after', \GravityView_View::getInstance() /** ugh! */); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * `gravityview_list_entry_before` and `gravityview/template/list/entry/before` actions. |
|
227 | + * `gravityview_list_entry_title_before` and `gravityview/template/list/entry/title/before` actions. |
|
228 | + * `gravityview_list_entry_content_before` and `gravityview/template/list/entry/content/before` actions. |
|
229 | + * `gravityview_list_entry_footer_before` and `gravityview/template/list/entry/footer/before` actions. |
|
230 | + * |
|
231 | + * Output inside the `entry` of the list. |
|
232 | + * |
|
233 | + * @param \GV\Entry $entry The entry. |
|
234 | + * @param \GV\Template_Context $context The 2.0 context. |
|
235 | + * @param string $zone The list zone (footer, image, title, etc.). |
|
236 | + * |
|
237 | + * @return void |
|
238 | + */ |
|
239 | + public static function entry_before($entry, $context, $zone = '') |
|
240 | + { |
|
241 | + $zone = str_replace('//', '/', "/$zone/"); |
|
242 | + |
|
243 | + /** |
|
244 | + * @action `gravityview/template/list/entry/$zone/before` Output inside the `entry` of the list at the end. |
|
245 | + * |
|
246 | + * @since 2.0 |
|
247 | + * |
|
248 | + * @param \GV\Template_Context $context The template context. |
|
249 | + */ |
|
250 | + do_action(sprintf('gravityview/template/list/entry%sbefore', $zone), Template_Context::from_template($context->template, compact('entry'))); |
|
251 | + |
|
252 | + $zone = str_replace('/', '_', $zone); |
|
253 | + |
|
254 | + /** |
|
255 | + * @action `gravityview_list_entry_$zone_before` Inside the `entry`, before any rows are rendered. Can be used to insert additional rows. |
|
256 | + * |
|
257 | + * @deprecated Use `gravityview/template/list/entry/$zone/before` |
|
258 | + * @since 1.0.7 |
|
259 | + * |
|
260 | + * @param \GravityView_View $gravityview_view Current GravityView_View object. |
|
261 | + */ |
|
262 | + do_action(sprintf('gravityview_list_entry%sbefore', $zone), $entry->as_entry(), \GravityView_View::getInstance() /** ugh! */); |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * `gravityview_list_entry_after` and `gravityview/template/list/entry/after` actions. |
|
267 | + * `gravityview_list_entry_title_after` and `gravityview/template/list/entry/title/after` actions. |
|
268 | + * `gravityview_list_entry_content_after` and `gravityview/template/list/entry/content/after` actions. |
|
269 | + * `gravityview_list_entry_footer_after` and `gravityview/template/list/entry/footer/after` actions. |
|
270 | + * |
|
271 | + * Output inside the `entry` of the list. |
|
272 | + * |
|
273 | + * @param \GV\Entry $entry The entry. |
|
274 | + * @param \GV\Template_Context $context The 2.0 context. |
|
275 | + * @param string $zone The list zone (footer, image, title, etc.). |
|
276 | + * |
|
277 | + * @return void |
|
278 | + */ |
|
279 | + public static function entry_after($entry, $context, $zone = '') |
|
280 | + { |
|
281 | + $zone = str_replace('//', '/', "/$zone/"); |
|
282 | + |
|
283 | + /** |
|
284 | + * @action `gravityview/template/list/entry/$zone/after` Output inside the `entry` of the list at the end. |
|
285 | + * |
|
286 | + * @since 2.0 |
|
287 | + * |
|
288 | + * @param \GV\Template_Context $context The template context. |
|
289 | + */ |
|
290 | + do_action(sprintf('gravityview/template/list/entry%safter', $zone), Template_Context::from_template($context->template, compact('entry'))); |
|
291 | + |
|
292 | + $zone = str_replace('/', '_', $zone); |
|
293 | + |
|
294 | + /** |
|
295 | + * @action `gravityview_list_entry_$zone_after` Inside the `entry`, after any rows are rendered. Can be used to insert additional rows. |
|
296 | + * |
|
297 | + * @deprecated Use `gravityview/template/list/entry/after` |
|
298 | + * @since 1.0.7 |
|
299 | + * |
|
300 | + * @param \GravityView_View $gravityview_view Current GravityView_View object. |
|
301 | + */ |
|
302 | + do_action(sprintf('gravityview_list_entry%safter', $zone), $entry->as_entry(), \GravityView_View::getInstance() /** ugh! */); |
|
303 | + } |
|
304 | 304 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace GV; |
4 | 4 | |
5 | 5 | /** If this file is called directly, abort. */ |
6 | -if (!defined('GRAVITYVIEW_DIR')) { |
|
6 | +if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
7 | 7 | exit(); |
8 | 8 | } |
9 | 9 | |
@@ -28,45 +28,45 @@ discard block |
||
28 | 28 | * |
29 | 29 | * @return string |
30 | 30 | */ |
31 | - public function the_field(\GV\Field $field, \GV\Entry $entry, $extras = null) |
|
31 | + public function the_field( \GV\Field $field, \GV\Entry $entry, $extras = null ) |
|
32 | 32 | { |
33 | 33 | $form = $this->view->form; |
34 | 34 | |
35 | - if (isset($this->view->unions[$entry['form_id']])) { |
|
36 | - if (isset($this->view->unions[$entry['form_id']][$field->ID])) { |
|
37 | - $field = $this->view->unions[$entry['form_id']][$field->ID]; |
|
38 | - } elseif (!$field instanceof Internal_Field) { |
|
39 | - $field = Internal_Field::from_configuration(['id' => 'custom']); |
|
35 | + if ( isset( $this->view->unions[ $entry[ 'form_id' ] ] ) ) { |
|
36 | + if ( isset( $this->view->unions[ $entry[ 'form_id' ] ][ $field->ID ] ) ) { |
|
37 | + $field = $this->view->unions[ $entry[ 'form_id' ] ][ $field->ID ]; |
|
38 | + } elseif ( ! $field instanceof Internal_Field ) { |
|
39 | + $field = Internal_Field::from_configuration( [ 'id' => 'custom' ] ); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
43 | - if ($entry->is_multi()) { |
|
44 | - if (!$single_entry = $entry->from_field($field)) { |
|
43 | + if ( $entry->is_multi() ) { |
|
44 | + if ( ! $single_entry = $entry->from_field( $field ) ) { |
|
45 | 45 | return; |
46 | 46 | } |
47 | - $form = GF_Form::by_id($field->form_id); |
|
47 | + $form = GF_Form::by_id( $field->form_id ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Push legacy entry context. |
52 | 52 | */ |
53 | - \GV\Mocks\Legacy_Context::load([ |
|
53 | + \GV\Mocks\Legacy_Context::load( [ |
|
54 | 54 | 'entry' => $entry, |
55 | 55 | 'form' => $form, |
56 | - ]); |
|
56 | + ] ); |
|
57 | 57 | |
58 | - $context = Template_Context::from_template($this, compact('field', 'entry')); |
|
58 | + $context = Template_Context::from_template( $this, compact( 'field', 'entry' ) ); |
|
59 | 59 | |
60 | 60 | $renderer = new Field_Renderer(); |
61 | - $source = is_numeric($field->ID) ? $form : new Internal_Source(); |
|
61 | + $source = is_numeric( $field->ID ) ? $form : new Internal_Source(); |
|
62 | 62 | |
63 | - $value = $renderer->render($field, $this->view, $source, $entry, $this->request); |
|
63 | + $value = $renderer->render( $field, $this->view, $source, $entry, $this->request ); |
|
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @deprecated Here for back-compatibility. |
67 | 67 | */ |
68 | - $label = apply_filters('gravityview_render_after_label', $field->get_label($this->view, $form, $entry), $field->as_configuration()); |
|
69 | - $label = apply_filters('gravityview/template/field_label', $label, $field->as_configuration(), $form->form ? $form->form : null, null); |
|
68 | + $label = apply_filters( 'gravityview_render_after_label', $field->get_label( $this->view, $form, $entry ), $field->as_configuration() ); |
|
69 | + $label = apply_filters( 'gravityview/template/field_label', $label, $field->as_configuration(), $form->form ? $form->form : null, null ); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * @filter `gravityview/template/field/label` Override the field label. |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param string $label The label to override. |
77 | 77 | * @param \GV\Template_Context $context The context. |
78 | 78 | */ |
79 | - $label = apply_filters('gravityview/template/field/label', $label, $context); |
|
79 | + $label = apply_filters( 'gravityview/template/field/label', $label, $context ); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * @filter `gravityview/template/table/entry/hide_empty` |
@@ -84,18 +84,18 @@ discard block |
||
84 | 84 | * @param bool Should the row be hidden if the value is empty? Default: don't hide. |
85 | 85 | * @param \GV\Template_Context $context The context ;) Love it, cherish it. And don't you dare modify it! |
86 | 86 | */ |
87 | - $hide_empty = apply_filters('gravityview/render/hide-empty-zone', Utils::get($extras, 'hide_empty', $this->view->settings->get('hide_empty', false)), $context); |
|
87 | + $hide_empty = apply_filters( 'gravityview/render/hide-empty-zone', Utils::get( $extras, 'hide_empty', $this->view->settings->get( 'hide_empty', false ) ), $context ); |
|
88 | 88 | |
89 | - if (is_numeric($field->ID)) { |
|
90 | - $extras['field'] = $field->as_configuration(); |
|
89 | + if ( is_numeric( $field->ID ) ) { |
|
90 | + $extras[ 'field' ] = $field->as_configuration(); |
|
91 | 91 | } |
92 | 92 | |
93 | - $extras['entry'] = $entry->as_entry(); |
|
94 | - $extras['hide_empty'] = $hide_empty; |
|
95 | - $extras['label'] = $label; |
|
96 | - $extras['value'] = $value; |
|
93 | + $extras[ 'entry' ] = $entry->as_entry(); |
|
94 | + $extras[ 'hide_empty' ] = $hide_empty; |
|
95 | + $extras[ 'label' ] = $label; |
|
96 | + $extras[ 'value' ] = $value; |
|
97 | 97 | |
98 | - return \gravityview_field_output($extras, $context); |
|
98 | + return \gravityview_field_output( $extras, $context ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -107,17 +107,17 @@ discard block |
||
107 | 107 | * $zone => \GV\Field_Collection |
108 | 108 | * has_$zone => int |
109 | 109 | */ |
110 | - public function extract_zone_vars($zones) |
|
110 | + public function extract_zone_vars( $zones ) |
|
111 | 111 | { |
112 | - if (!is_array($zones)) { |
|
113 | - $zones = [$zones]; |
|
112 | + if ( ! is_array( $zones ) ) { |
|
113 | + $zones = [ $zones ]; |
|
114 | 114 | } |
115 | 115 | |
116 | - $vars = []; |
|
117 | - foreach ($zones as $zone) { |
|
118 | - $zone_var = str_replace('-', '_', $zone); |
|
119 | - $vars[$zone_var] = $this->view->fields->by_position('directory_list-'.$zone)->by_visible($this->view); |
|
120 | - $vars["has_$zone_var"] = $vars[$zone_var]->count(); |
|
116 | + $vars = [ ]; |
|
117 | + foreach ( $zones as $zone ) { |
|
118 | + $zone_var = str_replace( '-', '_', $zone ); |
|
119 | + $vars[ $zone_var ] = $this->view->fields->by_position( 'directory_list-' . $zone )->by_visible( $this->view ); |
|
120 | + $vars[ "has_$zone_var" ] = $vars[ $zone_var ]->count(); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | return $vars; |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @return string The classes. |
136 | 136 | */ |
137 | - public static function entry_class($class, $entry, $context) |
|
137 | + public static function entry_class( $class, $entry, $context ) |
|
138 | 138 | { |
139 | 139 | /** |
140 | 140 | * @filter `gravityview_entry_class` Modify the class applied to the entry row. |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * |
148 | 148 | * @return string The modified class. |
149 | 149 | */ |
150 | - $class = apply_filters('gravityview_entry_class', $class, $entry->as_entry(), \GravityView_View::getInstance()); |
|
150 | + $class = apply_filters( 'gravityview_entry_class', $class, $entry->as_entry(), \GravityView_View::getInstance() ); |
|
151 | 151 | |
152 | 152 | /** |
153 | 153 | * @filter `gravityview/template/list/entry/class` Modify the class aplied to the entry row. |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return string The modified class. |
159 | 159 | */ |
160 | - return apply_filters('gravityview/template/list/entry/class', $class, Template_Context::from_template($context->template, compact('entry'))); |
|
160 | + return apply_filters( 'gravityview/template/list/entry/class', $class, Template_Context::from_template( $context->template, compact( 'entry' ) ) ); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * |
170 | 170 | * @return void |
171 | 171 | */ |
172 | - public static function body_before($context) |
|
172 | + public static function body_before( $context ) |
|
173 | 173 | { |
174 | 174 | /** |
175 | 175 | * @action `gravityview/template/list/body/before` Output inside the `tbody` of the list. |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * |
179 | 179 | * @param \GV\Template_Context $context The template context. |
180 | 180 | */ |
181 | - do_action('gravityview/template/list/body/before', $context); |
|
181 | + do_action( 'gravityview/template/list/body/before', $context ); |
|
182 | 182 | |
183 | 183 | /** |
184 | 184 | * @action `gravityview_list_body_before` Inside the `tbody`, before any rows are rendered. Can be used to insert additional rows. |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @param \GravityView_View $gravityview_view Current GravityView_View object. |
190 | 190 | */ |
191 | - do_action('gravityview_list_body_before', \GravityView_View::getInstance() /** ugh! */); |
|
191 | + do_action( 'gravityview_list_body_before', \GravityView_View::getInstance() /** ugh! */ ); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | /** |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @return void |
202 | 202 | */ |
203 | - public static function body_after($context) |
|
203 | + public static function body_after( $context ) |
|
204 | 204 | { |
205 | 205 | /** |
206 | 206 | * @action `gravityview/template/list/body/after` Output inside the `tbody` of the list at the end. |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * |
210 | 210 | * @param \GV\Template_Context $context The template context. |
211 | 211 | */ |
212 | - do_action('gravityview/template/list/body/after', $context); |
|
212 | + do_action( 'gravityview/template/list/body/after', $context ); |
|
213 | 213 | |
214 | 214 | /** |
215 | 215 | * @action `gravityview_list_body_after` Inside the `tbody`, after any rows are rendered. Can be used to insert additional rows. |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * |
220 | 220 | * @param \GravityView_View $gravityview_view Current GravityView_View object. |
221 | 221 | */ |
222 | - do_action('gravityview_list_body_after', \GravityView_View::getInstance() /** ugh! */); |
|
222 | + do_action( 'gravityview_list_body_after', \GravityView_View::getInstance() /** ugh! */ ); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | /** |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | * |
237 | 237 | * @return void |
238 | 238 | */ |
239 | - public static function entry_before($entry, $context, $zone = '') |
|
239 | + public static function entry_before( $entry, $context, $zone = '' ) |
|
240 | 240 | { |
241 | - $zone = str_replace('//', '/', "/$zone/"); |
|
241 | + $zone = str_replace( '//', '/', "/$zone/" ); |
|
242 | 242 | |
243 | 243 | /** |
244 | 244 | * @action `gravityview/template/list/entry/$zone/before` Output inside the `entry` of the list at the end. |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @param \GV\Template_Context $context The template context. |
249 | 249 | */ |
250 | - do_action(sprintf('gravityview/template/list/entry%sbefore', $zone), Template_Context::from_template($context->template, compact('entry'))); |
|
250 | + do_action( sprintf( 'gravityview/template/list/entry%sbefore', $zone ), Template_Context::from_template( $context->template, compact( 'entry' ) ) ); |
|
251 | 251 | |
252 | - $zone = str_replace('/', '_', $zone); |
|
252 | + $zone = str_replace( '/', '_', $zone ); |
|
253 | 253 | |
254 | 254 | /** |
255 | 255 | * @action `gravityview_list_entry_$zone_before` Inside the `entry`, before any rows are rendered. Can be used to insert additional rows. |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | * |
260 | 260 | * @param \GravityView_View $gravityview_view Current GravityView_View object. |
261 | 261 | */ |
262 | - do_action(sprintf('gravityview_list_entry%sbefore', $zone), $entry->as_entry(), \GravityView_View::getInstance() /** ugh! */); |
|
262 | + do_action( sprintf( 'gravityview_list_entry%sbefore', $zone ), $entry->as_entry(), \GravityView_View::getInstance() /** ugh! */ ); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return void |
278 | 278 | */ |
279 | - public static function entry_after($entry, $context, $zone = '') |
|
279 | + public static function entry_after( $entry, $context, $zone = '' ) |
|
280 | 280 | { |
281 | - $zone = str_replace('//', '/', "/$zone/"); |
|
281 | + $zone = str_replace( '//', '/', "/$zone/" ); |
|
282 | 282 | |
283 | 283 | /** |
284 | 284 | * @action `gravityview/template/list/entry/$zone/after` Output inside the `entry` of the list at the end. |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | * |
288 | 288 | * @param \GV\Template_Context $context The template context. |
289 | 289 | */ |
290 | - do_action(sprintf('gravityview/template/list/entry%safter', $zone), Template_Context::from_template($context->template, compact('entry'))); |
|
290 | + do_action( sprintf( 'gravityview/template/list/entry%safter', $zone ), Template_Context::from_template( $context->template, compact( 'entry' ) ) ); |
|
291 | 291 | |
292 | - $zone = str_replace('/', '_', $zone); |
|
292 | + $zone = str_replace( '/', '_', $zone ); |
|
293 | 293 | |
294 | 294 | /** |
295 | 295 | * @action `gravityview_list_entry_$zone_after` Inside the `entry`, after any rows are rendered. Can be used to insert additional rows. |
@@ -299,6 +299,6 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @param \GravityView_View $gravityview_view Current GravityView_View object. |
301 | 301 | */ |
302 | - do_action(sprintf('gravityview_list_entry%safter', $zone), $entry->as_entry(), \GravityView_View::getInstance() /** ugh! */); |
|
302 | + do_action( sprintf( 'gravityview_list_entry%safter', $zone ), $entry->as_entry(), \GravityView_View::getInstance() /** ugh! */ ); |
|
303 | 303 | } |
304 | 304 | } |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * Renders a \GV\View and a \GV\Entry_Collection via a \GV\View_Renderer. |
14 | 14 | */ |
15 | -class View_List_Template extends View_Template |
|
16 | -{ |
|
15 | +class View_List_Template extends View_Template { |
|
17 | 16 | /** |
18 | 17 | * @var string The template slug to be loaded (like "table", "list") |
19 | 18 | */ |
@@ -28,8 +27,7 @@ discard block |
||
28 | 27 | * |
29 | 28 | * @return string |
30 | 29 | */ |
31 | - public function the_field(\GV\Field $field, \GV\Entry $entry, $extras = null) |
|
32 | - { |
|
30 | + public function the_field(\GV\Field $field, \GV\Entry $entry, $extras = null) { |
|
33 | 31 | $form = $this->view->form; |
34 | 32 | |
35 | 33 | if (isset($this->view->unions[$entry['form_id']])) { |
@@ -107,8 +105,7 @@ discard block |
||
107 | 105 | * $zone => \GV\Field_Collection |
108 | 106 | * has_$zone => int |
109 | 107 | */ |
110 | - public function extract_zone_vars($zones) |
|
111 | - { |
|
108 | + public function extract_zone_vars($zones) { |
|
112 | 109 | if (!is_array($zones)) { |
113 | 110 | $zones = [$zones]; |
114 | 111 | } |
@@ -134,8 +131,7 @@ discard block |
||
134 | 131 | * |
135 | 132 | * @return string The classes. |
136 | 133 | */ |
137 | - public static function entry_class($class, $entry, $context) |
|
138 | - { |
|
134 | + public static function entry_class($class, $entry, $context) { |
|
139 | 135 | /** |
140 | 136 | * @filter `gravityview_entry_class` Modify the class applied to the entry row. |
141 | 137 | * |
@@ -169,8 +165,7 @@ discard block |
||
169 | 165 | * |
170 | 166 | * @return void |
171 | 167 | */ |
172 | - public static function body_before($context) |
|
173 | - { |
|
168 | + public static function body_before($context) { |
|
174 | 169 | /** |
175 | 170 | * @action `gravityview/template/list/body/before` Output inside the `tbody` of the list. |
176 | 171 | * |
@@ -200,8 +195,7 @@ discard block |
||
200 | 195 | * |
201 | 196 | * @return void |
202 | 197 | */ |
203 | - public static function body_after($context) |
|
204 | - { |
|
198 | + public static function body_after($context) { |
|
205 | 199 | /** |
206 | 200 | * @action `gravityview/template/list/body/after` Output inside the `tbody` of the list at the end. |
207 | 201 | * |
@@ -236,8 +230,7 @@ discard block |
||
236 | 230 | * |
237 | 231 | * @return void |
238 | 232 | */ |
239 | - public static function entry_before($entry, $context, $zone = '') |
|
240 | - { |
|
233 | + public static function entry_before($entry, $context, $zone = '') { |
|
241 | 234 | $zone = str_replace('//', '/', "/$zone/"); |
242 | 235 | |
243 | 236 | /** |
@@ -276,8 +269,7 @@ discard block |
||
276 | 269 | * |
277 | 270 | * @return void |
278 | 271 | */ |
279 | - public static function entry_after($entry, $context, $zone = '') |
|
280 | - { |
|
272 | + public static function entry_after($entry, $context, $zone = '') { |
|
281 | 273 | $zone = str_replace('//', '/', "/$zone/"); |
282 | 274 | |
283 | 275 | /** |