@@ -15,85 +15,85 @@ |
||
15 | 15 | */ |
16 | 16 | class views |
17 | 17 | { |
18 | - /** |
|
19 | - * @var \GV\View An internal View keeper. |
|
20 | - */ |
|
21 | - private $view = null; |
|
18 | + /** |
|
19 | + * @var \GV\View An internal View keeper. |
|
20 | + */ |
|
21 | + private $view = null; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Gets a View. |
|
25 | - * |
|
26 | - * Doesn't care what you provide it. Will try to find |
|
27 | - * out what you need from the current context, from the supplied |
|
28 | - * args, etc. |
|
29 | - * |
|
30 | - * @param string|int|array|\GV\View|\WP_Post|null Anything goes. |
|
31 | - * |
|
32 | - * @return \GV\View|null The detected View. |
|
33 | - */ |
|
34 | - public function get($view = null) |
|
35 | - { |
|
23 | + /** |
|
24 | + * Gets a View. |
|
25 | + * |
|
26 | + * Doesn't care what you provide it. Will try to find |
|
27 | + * out what you need from the current context, from the supplied |
|
28 | + * args, etc. |
|
29 | + * |
|
30 | + * @param string|int|array|\GV\View|\WP_Post|null Anything goes. |
|
31 | + * |
|
32 | + * @return \GV\View|null The detected View. |
|
33 | + */ |
|
34 | + public function get($view = null) |
|
35 | + { |
|
36 | 36 | |
37 | - /** |
|
38 | - * By View. |
|
39 | - */ |
|
40 | - if ($view instanceof \GV\View && $view->ID) { |
|
41 | - return $this->get($view->ID); |
|
42 | - } |
|
37 | + /** |
|
38 | + * By View. |
|
39 | + */ |
|
40 | + if ($view instanceof \GV\View && $view->ID) { |
|
41 | + return $this->get($view->ID); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * By View ID. |
|
46 | - */ |
|
47 | - if (is_numeric($view)) { |
|
48 | - return \GV\View::by_id($view); |
|
49 | - } |
|
44 | + /** |
|
45 | + * By View ID. |
|
46 | + */ |
|
47 | + if (is_numeric($view)) { |
|
48 | + return \GV\View::by_id($view); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * By post object. |
|
53 | - */ |
|
54 | - if ($view instanceof \WP_Post) { |
|
55 | - return \GV\View::from_post($view); |
|
56 | - } |
|
51 | + /** |
|
52 | + * By post object. |
|
53 | + */ |
|
54 | + if ($view instanceof \WP_Post) { |
|
55 | + return \GV\View::from_post($view); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * By array. |
|
60 | - */ |
|
61 | - if (is_array($view) && !empty($view['id'])) { |
|
62 | - return $this->get($view['id']); |
|
63 | - } |
|
58 | + /** |
|
59 | + * By array. |
|
60 | + */ |
|
61 | + if (is_array($view) && !empty($view['id'])) { |
|
62 | + return $this->get($view['id']); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * From various contexts. |
|
67 | - */ |
|
68 | - if (is_null($view)) { |
|
69 | - if (gravityview()->request->is_renderable() && $view = gravityview()->request->is_view()) { |
|
70 | - return $view; |
|
71 | - } |
|
65 | + /** |
|
66 | + * From various contexts. |
|
67 | + */ |
|
68 | + if (is_null($view)) { |
|
69 | + if (gravityview()->request->is_renderable() && $view = gravityview()->request->is_view()) { |
|
70 | + return $view; |
|
71 | + } |
|
72 | 72 | |
73 | - global $post; |
|
73 | + global $post; |
|
74 | 74 | |
75 | - if ($post instanceof \WP_Post && $post->post_type == 'gravityview') { |
|
76 | - return $this->get($post); |
|
77 | - } |
|
75 | + if ($post instanceof \WP_Post && $post->post_type == 'gravityview') { |
|
76 | + return $this->get($post); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Final fallback. |
|
81 | - */ |
|
82 | - return $this->view; |
|
83 | - } |
|
79 | + /** |
|
80 | + * Final fallback. |
|
81 | + */ |
|
82 | + return $this->view; |
|
83 | + } |
|
84 | 84 | |
85 | - return null; |
|
86 | - } |
|
85 | + return null; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Mock the internal pointer. |
|
90 | - * |
|
91 | - * @param \GV\View $view The View to supply on fallback in ::get() |
|
92 | - * |
|
93 | - * @return void |
|
94 | - */ |
|
95 | - public function set($view) |
|
96 | - { |
|
97 | - $this->view = $view; |
|
98 | - } |
|
88 | + /** |
|
89 | + * Mock the internal pointer. |
|
90 | + * |
|
91 | + * @param \GV\View $view The View to supply on fallback in ::get() |
|
92 | + * |
|
93 | + * @return void |
|
94 | + */ |
|
95 | + public function set($view) |
|
96 | + { |
|
97 | + $this->view = $view; |
|
98 | + } |
|
99 | 99 | } |
@@ -31,49 +31,49 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @return \GV\View|null The detected View. |
33 | 33 | */ |
34 | - public function get($view = null) |
|
34 | + public function get( $view = null ) |
|
35 | 35 | { |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * By View. |
39 | 39 | */ |
40 | - if ($view instanceof \GV\View && $view->ID) { |
|
41 | - return $this->get($view->ID); |
|
40 | + if ( $view instanceof \GV\View && $view->ID ) { |
|
41 | + return $this->get( $view->ID ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * By View ID. |
46 | 46 | */ |
47 | - if (is_numeric($view)) { |
|
48 | - return \GV\View::by_id($view); |
|
47 | + if ( is_numeric( $view ) ) { |
|
48 | + return \GV\View::by_id( $view ); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | 52 | * By post object. |
53 | 53 | */ |
54 | - if ($view instanceof \WP_Post) { |
|
55 | - return \GV\View::from_post($view); |
|
54 | + if ( $view instanceof \WP_Post ) { |
|
55 | + return \GV\View::from_post( $view ); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | 59 | * By array. |
60 | 60 | */ |
61 | - if (is_array($view) && !empty($view['id'])) { |
|
62 | - return $this->get($view['id']); |
|
61 | + if ( is_array( $view ) && ! empty( $view[ 'id' ] ) ) { |
|
62 | + return $this->get( $view[ 'id' ] ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | 66 | * From various contexts. |
67 | 67 | */ |
68 | - if (is_null($view)) { |
|
69 | - if (gravityview()->request->is_renderable() && $view = gravityview()->request->is_view()) { |
|
68 | + if ( is_null( $view ) ) { |
|
69 | + if ( gravityview()->request->is_renderable() && $view = gravityview()->request->is_view() ) { |
|
70 | 70 | return $view; |
71 | 71 | } |
72 | 72 | |
73 | 73 | global $post; |
74 | 74 | |
75 | - if ($post instanceof \WP_Post && $post->post_type == 'gravityview') { |
|
76 | - return $this->get($post); |
|
75 | + if ( $post instanceof \WP_Post && $post->post_type == 'gravityview' ) { |
|
76 | + return $this->get( $post ); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return void |
94 | 94 | */ |
95 | - public function set($view) |
|
95 | + public function set( $view ) |
|
96 | 96 | { |
97 | 97 | $this->view = $view; |
98 | 98 | } |
@@ -13,8 +13,7 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * The views magic wrapper. |
15 | 15 | */ |
16 | -class views |
|
17 | -{ |
|
16 | +class views { |
|
18 | 17 | /** |
19 | 18 | * @var \GV\View An internal View keeper. |
20 | 19 | */ |
@@ -31,8 +30,7 @@ discard block |
||
31 | 30 | * |
32 | 31 | * @return \GV\View|null The detected View. |
33 | 32 | */ |
34 | - public function get($view = null) |
|
35 | - { |
|
33 | + public function get($view = null) { |
|
36 | 34 | |
37 | 35 | /** |
38 | 36 | * By View. |
@@ -92,8 +90,7 @@ discard block |
||
92 | 90 | * |
93 | 91 | * @return void |
94 | 92 | */ |
95 | - public function set($view) |
|
96 | - { |
|
93 | + public function set($view) { |
|
97 | 94 | $this->view = $view; |
98 | 95 | } |
99 | 96 | } |
@@ -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,255 +14,255 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Renderer |
16 | 16 | { |
17 | - /** |
|
18 | - * Initialization. |
|
19 | - */ |
|
20 | - public function __construct() |
|
21 | - { |
|
22 | - if (!has_action('gravityview/template/before', [__CLASS__, 'maybe_print_notices'])) { |
|
23 | - add_action('gravityview/template/before', [__CLASS__, 'maybe_print_notices']); |
|
24 | - } |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Print unconfigured notices to admins. |
|
29 | - * Print reserved slug warnings. |
|
30 | - * Print entry approval notice. |
|
31 | - * |
|
32 | - * @param \GV\Template_Context $gravityview The $gravityview template object. |
|
33 | - * |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public static function maybe_print_notices($gravityview = null) |
|
37 | - { |
|
38 | - if (!$gravityview instanceof \GV\Template_Context) { |
|
39 | - /** Call the legacy code. */ |
|
40 | - \GravityView_frontend::getInstance()->context_not_configured_warning(gravityview_get_view_id()); |
|
41 | - |
|
42 | - return; |
|
43 | - } |
|
44 | - |
|
45 | - self::maybe_print_reserved_slugs_notice($gravityview); |
|
46 | - |
|
47 | - self::maybe_print_configuration_notice($gravityview); |
|
48 | - |
|
49 | - self::maybe_print_entry_approval_notice($gravityview); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Print notice warning admins that "Show only approved" is enabled. |
|
54 | - * |
|
55 | - * @since 2.9.5 |
|
56 | - * |
|
57 | - * @param \GV\Template_Context $gravityview The $gravityview template object. |
|
58 | - * |
|
59 | - * @return void |
|
60 | - */ |
|
61 | - private static function maybe_print_entry_approval_notice($gravityview) |
|
62 | - { |
|
63 | - if ($gravityview->entries && $gravityview->entries->count()) { |
|
64 | - return; |
|
65 | - } |
|
66 | - |
|
67 | - if ($gravityview->request->is_search()) { |
|
68 | - return; |
|
69 | - } |
|
70 | - |
|
71 | - // "Show Only Approved" is not enabled. |
|
72 | - if (!$gravityview->view->settings->get('show_only_approved', 0)) { |
|
73 | - return; |
|
74 | - } |
|
75 | - |
|
76 | - // If "Show all entries to administrators" is enabled, approval status isn't the issue. |
|
77 | - if ($gravityview->view->settings->get('admin_show_all_statuses', 0)) { |
|
78 | - return; |
|
79 | - } |
|
80 | - |
|
81 | - // Don't show when no entries are being displayed due to "Hide View data until search is performed". |
|
82 | - if ($gravityview->view->settings->get('hide_until_searched', 0)) { |
|
83 | - return; |
|
84 | - } |
|
85 | - |
|
86 | - $current_user = wp_get_current_user(); |
|
87 | - $user_meta_key = '_gv_dismissed_entry_approval_notice'.$gravityview->view->ID; |
|
88 | - |
|
89 | - if (isset($_GET['gv-dismiss']) && wp_verify_nonce($_GET['gv-dismiss'], 'dismiss')) { |
|
90 | - add_user_meta($current_user->ID, $user_meta_key, 1); // Prevent user from seeing this again for this View |
|
91 | - |
|
92 | - return; |
|
93 | - } |
|
94 | - |
|
95 | - // The user has already dismissed the notice |
|
96 | - if (get_user_meta($current_user->ID, $user_meta_key, true)) { |
|
97 | - return; |
|
98 | - } |
|
99 | - |
|
100 | - $form = $gravityview->view->form; |
|
101 | - |
|
102 | - if (!$form) { |
|
103 | - return; |
|
104 | - } |
|
105 | - |
|
106 | - $count = \GFAPI::count_entries($gravityview->view->form->ID, [ |
|
107 | - 'status' => 'active', |
|
108 | - 'field_filters' => [ |
|
109 | - [ |
|
110 | - 'key' => 'is_approved', |
|
111 | - 'operator' => 'isnot', |
|
112 | - 'value' => \GravityView_Entry_Approval_Status::APPROVED, |
|
113 | - ], |
|
114 | - ], |
|
115 | - ]); |
|
116 | - |
|
117 | - // There aren't any entries to show! |
|
118 | - if (empty($count)) { |
|
119 | - return; |
|
120 | - } |
|
121 | - |
|
122 | - $notice_title = _n( |
|
123 | - esc_html__('There is an unapproved entry that is not being shown.', 'gravityview'), |
|
124 | - esc_html__('There are %s unapproved entries that are not being shown.', 'gravityview'), |
|
125 | - $count |
|
126 | - ); |
|
127 | - |
|
128 | - $float_dir = is_rtl() ? 'left' : 'right'; |
|
129 | - $hide_link = sprintf('<a href="%s" style="float: '.$float_dir.'; font-size: 1rem" role="button">%s</a>', esc_url(wp_nonce_url(add_query_arg(['notice' => 'no_entries_'.$gravityview->view->ID]), 'dismiss', 'gv-dismiss')), esc_html__('Hide this notice', 'gravityview')); |
|
130 | - |
|
131 | - $message_strings = [ |
|
132 | - '<h3>'.sprintf($notice_title, number_format_i18n($count)).$hide_link.'</h3>', |
|
133 | - esc_html__('The "Show only approved entries" setting is enabled, so only entries that have been approved are displayed.', 'gravityview'), |
|
134 | - sprintf('<a href="%s">%s</a>', 'https://docs.gravityview.co/article/490-entry-approval-gravity-forms', esc_html__('Learn about entry approval.', 'gravityview')), |
|
135 | - "\n\n", |
|
136 | - sprintf(esc_html_x('%sEdit the View settings%s or %sApprove entries%s', 'Replacements are HTML links', 'gravityview'), '<a href="'.esc_url(get_edit_post_link($gravityview->view->ID, false)).'" style="font-weight: bold;">', '</a>', '<a href="'.esc_url(admin_url('admin.php?page=gf_entries&id='.$gravityview->view->form->ID)).'" style="font-weight: bold;">', '</a>'), |
|
137 | - "\n\n", |
|
138 | - sprintf('<img alt="%s" src="%s" style="padding: 10px 0; max-width: 550px;" />', esc_html__('Show only approved entries', 'gravityview'), esc_url(plugins_url('assets/images/screenshots/entry-approval.png', GRAVITYVIEW_FILE))), |
|
139 | - "\n\n", |
|
140 | - esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'), |
|
141 | - ]; |
|
142 | - |
|
143 | - $notice = wpautop(implode(' ', $message_strings)); |
|
144 | - |
|
145 | - echo \GVCommon::generate_notice($notice, 'warning', 'edit_gravityview', $gravityview->view->ID); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Check empty configuration. |
|
150 | - * |
|
151 | - * @since 2.10 |
|
152 | - * |
|
153 | - * @param \GV\Template_Context $gravityview The $gravityview template object. |
|
154 | - * |
|
155 | - * @return void |
|
156 | - */ |
|
157 | - private static function maybe_print_configuration_notice($gravityview) |
|
158 | - { |
|
159 | - switch (true) { |
|
160 | - case $gravityview->request->is_edit_entry() : |
|
161 | - $tab = __('Edit Entry', 'gravityview'); |
|
162 | - $context = 'edit'; |
|
163 | - break; |
|
164 | - case $gravityview->request->is_entry($gravityview->view->form ? $gravityview->view->form->ID : 0) : |
|
165 | - $tab = __('Single Entry', 'gravityview'); |
|
166 | - $context = 'single'; |
|
167 | - break; |
|
168 | - default: |
|
169 | - $tab = __('Multiple Entries', 'gravityview'); |
|
170 | - $context = 'directory'; |
|
171 | - break; |
|
172 | - } |
|
173 | - |
|
174 | - $cls = $gravityview->template; |
|
175 | - $slug = property_exists($cls, '_configuration_slug') ? $cls::$_configuration_slug : $cls::$slug; |
|
176 | - |
|
177 | - // If the zone has been configured, don't display notice. |
|
178 | - if ($gravityview->fields->by_position(sprintf('%s_%s-*', $context, $slug))->by_visible($gravityview->view)->count()) { |
|
179 | - return; |
|
180 | - } |
|
181 | - |
|
182 | - $title = sprintf(esc_html_x('The %s layout has not been configured.', 'Displayed when a View is not configured. %s is replaced by the tab label', 'gravityview'), $tab); |
|
183 | - $edit_link = admin_url(sprintf('post.php?post=%d&action=edit#%s-view', $gravityview->view->ID, $context)); |
|
184 | - $action_text = sprintf(esc_html__('Add fields to %s', 'gravityview'), $tab); |
|
185 | - $message = esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
186 | - |
|
187 | - $image = sprintf('<img alt="%s" src="%s" style="margin-top: 10px;" />', $tab, esc_url(plugins_url(sprintf('assets/images/tab-%s.png', $context), GRAVITYVIEW_FILE))); |
|
188 | - $output = sprintf('<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>', $title, esc_url($edit_link), $action_text, $message); |
|
189 | - |
|
190 | - echo \GVCommon::generate_notice($output.$image, 'gv-warning warning', 'edit_gravityview', $gravityview->view->ID); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Print reserved slug warnings, if they exist. |
|
195 | - * |
|
196 | - * @since 2.9.5 |
|
197 | - * |
|
198 | - * @param Template_Context $gravityview The $gravityview template object. |
|
199 | - * |
|
200 | - * @return void |
|
201 | - */ |
|
202 | - private static function maybe_print_reserved_slugs_notice($gravityview) |
|
203 | - { |
|
204 | - global $wp; |
|
205 | - global $wp_rewrite; |
|
206 | - |
|
207 | - $reserved_slugs = [ |
|
208 | - $wp_rewrite->search_base, |
|
209 | - apply_filters('gravityview_directory_endpoint', 'entry'), |
|
210 | - ]; |
|
211 | - |
|
212 | - $post_types = get_post_types(); |
|
213 | - |
|
214 | - foreach ($post_types as $post_type) { |
|
215 | - $post_type_rewrite = get_post_type_object($post_type)->rewrite; |
|
216 | - |
|
217 | - if ($slug = \GV\Utils::get($post_type_rewrite, 'slug')) { |
|
218 | - $reserved_slugs[] = $slug; |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - unset($post_types, $post_type_rewrite); |
|
223 | - |
|
224 | - /** |
|
225 | - * @filter `gravityview/rewrite/reserved_slugs` Modify the reserved embed slugs that trigger a warning. |
|
226 | - * |
|
227 | - * @since 2.5 |
|
228 | - * |
|
229 | - * @param array $reserved_slugs An array of strings, reserved slugs. |
|
230 | - * @param \GV\Template_Context $gravityview The context. |
|
231 | - */ |
|
232 | - $reserved_slugs = apply_filters('gravityview/rewrite/reserved_slugs', $reserved_slugs, $gravityview); |
|
233 | - |
|
234 | - $reserved_slugs = array_map('strtolower', $reserved_slugs); |
|
235 | - |
|
236 | - if (!in_array(strtolower($wp->request), $reserved_slugs, true)) { |
|
237 | - return; |
|
238 | - } |
|
239 | - |
|
240 | - gravityview()->log->error('{slug} page URL is reserved.', ['slug' => $wp->request]); |
|
241 | - |
|
242 | - $title = esc_html__('GravityView will not work correctly on this page because of the URL Slug.', 'gravityview'); |
|
243 | - $message = __('Please <a href="%s">read this article</a> for more information.', 'gravityview'); |
|
244 | - $message .= ' '.esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
245 | - |
|
246 | - $output = sprintf('<h3>%s</h3><p>%s</p>', $title, sprintf($message, 'https://docs.gravityview.co/article/659-reserved-urls')); |
|
247 | - |
|
248 | - echo \GVCommon::generate_notice($output, 'gv-error error', 'edit_gravityview', $gravityview->view->ID); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Warn about legacy template being used. |
|
253 | - * |
|
254 | - * Generate a callback that shows which legacy template was at fault. |
|
255 | - * Used in gravityview_before. |
|
256 | - * |
|
257 | - * @param \GV\View $view The view we're looking at. |
|
258 | - * @param string $path The path of the offending template. |
|
259 | - * |
|
260 | - * @return \callable A closure used in the filter. |
|
261 | - */ |
|
262 | - public function legacy_template_warning($view, $path) |
|
263 | - { |
|
264 | - return function () { |
|
265 | - // Do not panic for now... |
|
266 | - }; |
|
267 | - } |
|
17 | + /** |
|
18 | + * Initialization. |
|
19 | + */ |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + if (!has_action('gravityview/template/before', [__CLASS__, 'maybe_print_notices'])) { |
|
23 | + add_action('gravityview/template/before', [__CLASS__, 'maybe_print_notices']); |
|
24 | + } |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Print unconfigured notices to admins. |
|
29 | + * Print reserved slug warnings. |
|
30 | + * Print entry approval notice. |
|
31 | + * |
|
32 | + * @param \GV\Template_Context $gravityview The $gravityview template object. |
|
33 | + * |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public static function maybe_print_notices($gravityview = null) |
|
37 | + { |
|
38 | + if (!$gravityview instanceof \GV\Template_Context) { |
|
39 | + /** Call the legacy code. */ |
|
40 | + \GravityView_frontend::getInstance()->context_not_configured_warning(gravityview_get_view_id()); |
|
41 | + |
|
42 | + return; |
|
43 | + } |
|
44 | + |
|
45 | + self::maybe_print_reserved_slugs_notice($gravityview); |
|
46 | + |
|
47 | + self::maybe_print_configuration_notice($gravityview); |
|
48 | + |
|
49 | + self::maybe_print_entry_approval_notice($gravityview); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Print notice warning admins that "Show only approved" is enabled. |
|
54 | + * |
|
55 | + * @since 2.9.5 |
|
56 | + * |
|
57 | + * @param \GV\Template_Context $gravityview The $gravityview template object. |
|
58 | + * |
|
59 | + * @return void |
|
60 | + */ |
|
61 | + private static function maybe_print_entry_approval_notice($gravityview) |
|
62 | + { |
|
63 | + if ($gravityview->entries && $gravityview->entries->count()) { |
|
64 | + return; |
|
65 | + } |
|
66 | + |
|
67 | + if ($gravityview->request->is_search()) { |
|
68 | + return; |
|
69 | + } |
|
70 | + |
|
71 | + // "Show Only Approved" is not enabled. |
|
72 | + if (!$gravityview->view->settings->get('show_only_approved', 0)) { |
|
73 | + return; |
|
74 | + } |
|
75 | + |
|
76 | + // If "Show all entries to administrators" is enabled, approval status isn't the issue. |
|
77 | + if ($gravityview->view->settings->get('admin_show_all_statuses', 0)) { |
|
78 | + return; |
|
79 | + } |
|
80 | + |
|
81 | + // Don't show when no entries are being displayed due to "Hide View data until search is performed". |
|
82 | + if ($gravityview->view->settings->get('hide_until_searched', 0)) { |
|
83 | + return; |
|
84 | + } |
|
85 | + |
|
86 | + $current_user = wp_get_current_user(); |
|
87 | + $user_meta_key = '_gv_dismissed_entry_approval_notice'.$gravityview->view->ID; |
|
88 | + |
|
89 | + if (isset($_GET['gv-dismiss']) && wp_verify_nonce($_GET['gv-dismiss'], 'dismiss')) { |
|
90 | + add_user_meta($current_user->ID, $user_meta_key, 1); // Prevent user from seeing this again for this View |
|
91 | + |
|
92 | + return; |
|
93 | + } |
|
94 | + |
|
95 | + // The user has already dismissed the notice |
|
96 | + if (get_user_meta($current_user->ID, $user_meta_key, true)) { |
|
97 | + return; |
|
98 | + } |
|
99 | + |
|
100 | + $form = $gravityview->view->form; |
|
101 | + |
|
102 | + if (!$form) { |
|
103 | + return; |
|
104 | + } |
|
105 | + |
|
106 | + $count = \GFAPI::count_entries($gravityview->view->form->ID, [ |
|
107 | + 'status' => 'active', |
|
108 | + 'field_filters' => [ |
|
109 | + [ |
|
110 | + 'key' => 'is_approved', |
|
111 | + 'operator' => 'isnot', |
|
112 | + 'value' => \GravityView_Entry_Approval_Status::APPROVED, |
|
113 | + ], |
|
114 | + ], |
|
115 | + ]); |
|
116 | + |
|
117 | + // There aren't any entries to show! |
|
118 | + if (empty($count)) { |
|
119 | + return; |
|
120 | + } |
|
121 | + |
|
122 | + $notice_title = _n( |
|
123 | + esc_html__('There is an unapproved entry that is not being shown.', 'gravityview'), |
|
124 | + esc_html__('There are %s unapproved entries that are not being shown.', 'gravityview'), |
|
125 | + $count |
|
126 | + ); |
|
127 | + |
|
128 | + $float_dir = is_rtl() ? 'left' : 'right'; |
|
129 | + $hide_link = sprintf('<a href="%s" style="float: '.$float_dir.'; font-size: 1rem" role="button">%s</a>', esc_url(wp_nonce_url(add_query_arg(['notice' => 'no_entries_'.$gravityview->view->ID]), 'dismiss', 'gv-dismiss')), esc_html__('Hide this notice', 'gravityview')); |
|
130 | + |
|
131 | + $message_strings = [ |
|
132 | + '<h3>'.sprintf($notice_title, number_format_i18n($count)).$hide_link.'</h3>', |
|
133 | + esc_html__('The "Show only approved entries" setting is enabled, so only entries that have been approved are displayed.', 'gravityview'), |
|
134 | + sprintf('<a href="%s">%s</a>', 'https://docs.gravityview.co/article/490-entry-approval-gravity-forms', esc_html__('Learn about entry approval.', 'gravityview')), |
|
135 | + "\n\n", |
|
136 | + sprintf(esc_html_x('%sEdit the View settings%s or %sApprove entries%s', 'Replacements are HTML links', 'gravityview'), '<a href="'.esc_url(get_edit_post_link($gravityview->view->ID, false)).'" style="font-weight: bold;">', '</a>', '<a href="'.esc_url(admin_url('admin.php?page=gf_entries&id='.$gravityview->view->form->ID)).'" style="font-weight: bold;">', '</a>'), |
|
137 | + "\n\n", |
|
138 | + sprintf('<img alt="%s" src="%s" style="padding: 10px 0; max-width: 550px;" />', esc_html__('Show only approved entries', 'gravityview'), esc_url(plugins_url('assets/images/screenshots/entry-approval.png', GRAVITYVIEW_FILE))), |
|
139 | + "\n\n", |
|
140 | + esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'), |
|
141 | + ]; |
|
142 | + |
|
143 | + $notice = wpautop(implode(' ', $message_strings)); |
|
144 | + |
|
145 | + echo \GVCommon::generate_notice($notice, 'warning', 'edit_gravityview', $gravityview->view->ID); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Check empty configuration. |
|
150 | + * |
|
151 | + * @since 2.10 |
|
152 | + * |
|
153 | + * @param \GV\Template_Context $gravityview The $gravityview template object. |
|
154 | + * |
|
155 | + * @return void |
|
156 | + */ |
|
157 | + private static function maybe_print_configuration_notice($gravityview) |
|
158 | + { |
|
159 | + switch (true) { |
|
160 | + case $gravityview->request->is_edit_entry() : |
|
161 | + $tab = __('Edit Entry', 'gravityview'); |
|
162 | + $context = 'edit'; |
|
163 | + break; |
|
164 | + case $gravityview->request->is_entry($gravityview->view->form ? $gravityview->view->form->ID : 0) : |
|
165 | + $tab = __('Single Entry', 'gravityview'); |
|
166 | + $context = 'single'; |
|
167 | + break; |
|
168 | + default: |
|
169 | + $tab = __('Multiple Entries', 'gravityview'); |
|
170 | + $context = 'directory'; |
|
171 | + break; |
|
172 | + } |
|
173 | + |
|
174 | + $cls = $gravityview->template; |
|
175 | + $slug = property_exists($cls, '_configuration_slug') ? $cls::$_configuration_slug : $cls::$slug; |
|
176 | + |
|
177 | + // If the zone has been configured, don't display notice. |
|
178 | + if ($gravityview->fields->by_position(sprintf('%s_%s-*', $context, $slug))->by_visible($gravityview->view)->count()) { |
|
179 | + return; |
|
180 | + } |
|
181 | + |
|
182 | + $title = sprintf(esc_html_x('The %s layout has not been configured.', 'Displayed when a View is not configured. %s is replaced by the tab label', 'gravityview'), $tab); |
|
183 | + $edit_link = admin_url(sprintf('post.php?post=%d&action=edit#%s-view', $gravityview->view->ID, $context)); |
|
184 | + $action_text = sprintf(esc_html__('Add fields to %s', 'gravityview'), $tab); |
|
185 | + $message = esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
186 | + |
|
187 | + $image = sprintf('<img alt="%s" src="%s" style="margin-top: 10px;" />', $tab, esc_url(plugins_url(sprintf('assets/images/tab-%s.png', $context), GRAVITYVIEW_FILE))); |
|
188 | + $output = sprintf('<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>', $title, esc_url($edit_link), $action_text, $message); |
|
189 | + |
|
190 | + echo \GVCommon::generate_notice($output.$image, 'gv-warning warning', 'edit_gravityview', $gravityview->view->ID); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Print reserved slug warnings, if they exist. |
|
195 | + * |
|
196 | + * @since 2.9.5 |
|
197 | + * |
|
198 | + * @param Template_Context $gravityview The $gravityview template object. |
|
199 | + * |
|
200 | + * @return void |
|
201 | + */ |
|
202 | + private static function maybe_print_reserved_slugs_notice($gravityview) |
|
203 | + { |
|
204 | + global $wp; |
|
205 | + global $wp_rewrite; |
|
206 | + |
|
207 | + $reserved_slugs = [ |
|
208 | + $wp_rewrite->search_base, |
|
209 | + apply_filters('gravityview_directory_endpoint', 'entry'), |
|
210 | + ]; |
|
211 | + |
|
212 | + $post_types = get_post_types(); |
|
213 | + |
|
214 | + foreach ($post_types as $post_type) { |
|
215 | + $post_type_rewrite = get_post_type_object($post_type)->rewrite; |
|
216 | + |
|
217 | + if ($slug = \GV\Utils::get($post_type_rewrite, 'slug')) { |
|
218 | + $reserved_slugs[] = $slug; |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + unset($post_types, $post_type_rewrite); |
|
223 | + |
|
224 | + /** |
|
225 | + * @filter `gravityview/rewrite/reserved_slugs` Modify the reserved embed slugs that trigger a warning. |
|
226 | + * |
|
227 | + * @since 2.5 |
|
228 | + * |
|
229 | + * @param array $reserved_slugs An array of strings, reserved slugs. |
|
230 | + * @param \GV\Template_Context $gravityview The context. |
|
231 | + */ |
|
232 | + $reserved_slugs = apply_filters('gravityview/rewrite/reserved_slugs', $reserved_slugs, $gravityview); |
|
233 | + |
|
234 | + $reserved_slugs = array_map('strtolower', $reserved_slugs); |
|
235 | + |
|
236 | + if (!in_array(strtolower($wp->request), $reserved_slugs, true)) { |
|
237 | + return; |
|
238 | + } |
|
239 | + |
|
240 | + gravityview()->log->error('{slug} page URL is reserved.', ['slug' => $wp->request]); |
|
241 | + |
|
242 | + $title = esc_html__('GravityView will not work correctly on this page because of the URL Slug.', 'gravityview'); |
|
243 | + $message = __('Please <a href="%s">read this article</a> for more information.', 'gravityview'); |
|
244 | + $message .= ' '.esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
245 | + |
|
246 | + $output = sprintf('<h3>%s</h3><p>%s</p>', $title, sprintf($message, 'https://docs.gravityview.co/article/659-reserved-urls')); |
|
247 | + |
|
248 | + echo \GVCommon::generate_notice($output, 'gv-error error', 'edit_gravityview', $gravityview->view->ID); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Warn about legacy template being used. |
|
253 | + * |
|
254 | + * Generate a callback that shows which legacy template was at fault. |
|
255 | + * Used in gravityview_before. |
|
256 | + * |
|
257 | + * @param \GV\View $view The view we're looking at. |
|
258 | + * @param string $path The path of the offending template. |
|
259 | + * |
|
260 | + * @return \callable A closure used in the filter. |
|
261 | + */ |
|
262 | + public function legacy_template_warning($view, $path) |
|
263 | + { |
|
264 | + return function () { |
|
265 | + // Do not panic for now... |
|
266 | + }; |
|
267 | + } |
|
268 | 268 | } |
@@ -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,8 +19,8 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function __construct() |
21 | 21 | { |
22 | - if (!has_action('gravityview/template/before', [__CLASS__, 'maybe_print_notices'])) { |
|
23 | - add_action('gravityview/template/before', [__CLASS__, 'maybe_print_notices']); |
|
22 | + if ( ! has_action( 'gravityview/template/before', [ __CLASS__, 'maybe_print_notices' ] ) ) { |
|
23 | + add_action( 'gravityview/template/before', [ __CLASS__, 'maybe_print_notices' ] ); |
|
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
@@ -33,20 +33,20 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return void |
35 | 35 | */ |
36 | - public static function maybe_print_notices($gravityview = null) |
|
36 | + public static function maybe_print_notices( $gravityview = null ) |
|
37 | 37 | { |
38 | - if (!$gravityview instanceof \GV\Template_Context) { |
|
38 | + if ( ! $gravityview instanceof \GV\Template_Context ) { |
|
39 | 39 | /** Call the legacy code. */ |
40 | - \GravityView_frontend::getInstance()->context_not_configured_warning(gravityview_get_view_id()); |
|
40 | + \GravityView_frontend::getInstance()->context_not_configured_warning( gravityview_get_view_id() ); |
|
41 | 41 | |
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | - self::maybe_print_reserved_slugs_notice($gravityview); |
|
45 | + self::maybe_print_reserved_slugs_notice( $gravityview ); |
|
46 | 46 | |
47 | - self::maybe_print_configuration_notice($gravityview); |
|
47 | + self::maybe_print_configuration_notice( $gravityview ); |
|
48 | 48 | |
49 | - self::maybe_print_entry_approval_notice($gravityview); |
|
49 | + self::maybe_print_entry_approval_notice( $gravityview ); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -58,52 +58,52 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return void |
60 | 60 | */ |
61 | - private static function maybe_print_entry_approval_notice($gravityview) |
|
61 | + private static function maybe_print_entry_approval_notice( $gravityview ) |
|
62 | 62 | { |
63 | - if ($gravityview->entries && $gravityview->entries->count()) { |
|
63 | + if ( $gravityview->entries && $gravityview->entries->count() ) { |
|
64 | 64 | return; |
65 | 65 | } |
66 | 66 | |
67 | - if ($gravityview->request->is_search()) { |
|
67 | + if ( $gravityview->request->is_search() ) { |
|
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | 71 | // "Show Only Approved" is not enabled. |
72 | - if (!$gravityview->view->settings->get('show_only_approved', 0)) { |
|
72 | + if ( ! $gravityview->view->settings->get( 'show_only_approved', 0 ) ) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | 76 | // If "Show all entries to administrators" is enabled, approval status isn't the issue. |
77 | - if ($gravityview->view->settings->get('admin_show_all_statuses', 0)) { |
|
77 | + if ( $gravityview->view->settings->get( 'admin_show_all_statuses', 0 ) ) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Don't show when no entries are being displayed due to "Hide View data until search is performed". |
82 | - if ($gravityview->view->settings->get('hide_until_searched', 0)) { |
|
82 | + if ( $gravityview->view->settings->get( 'hide_until_searched', 0 ) ) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
86 | 86 | $current_user = wp_get_current_user(); |
87 | - $user_meta_key = '_gv_dismissed_entry_approval_notice'.$gravityview->view->ID; |
|
87 | + $user_meta_key = '_gv_dismissed_entry_approval_notice' . $gravityview->view->ID; |
|
88 | 88 | |
89 | - if (isset($_GET['gv-dismiss']) && wp_verify_nonce($_GET['gv-dismiss'], 'dismiss')) { |
|
90 | - add_user_meta($current_user->ID, $user_meta_key, 1); // Prevent user from seeing this again for this View |
|
89 | + if ( isset( $_GET[ 'gv-dismiss' ] ) && wp_verify_nonce( $_GET[ 'gv-dismiss' ], 'dismiss' ) ) { |
|
90 | + add_user_meta( $current_user->ID, $user_meta_key, 1 ); // Prevent user from seeing this again for this View |
|
91 | 91 | |
92 | 92 | return; |
93 | 93 | } |
94 | 94 | |
95 | 95 | // The user has already dismissed the notice |
96 | - if (get_user_meta($current_user->ID, $user_meta_key, true)) { |
|
96 | + if ( get_user_meta( $current_user->ID, $user_meta_key, true ) ) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
100 | 100 | $form = $gravityview->view->form; |
101 | 101 | |
102 | - if (!$form) { |
|
102 | + if ( ! $form ) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | - $count = \GFAPI::count_entries($gravityview->view->form->ID, [ |
|
106 | + $count = \GFAPI::count_entries( $gravityview->view->form->ID, [ |
|
107 | 107 | 'status' => 'active', |
108 | 108 | 'field_filters' => [ |
109 | 109 | [ |
@@ -112,37 +112,37 @@ discard block |
||
112 | 112 | 'value' => \GravityView_Entry_Approval_Status::APPROVED, |
113 | 113 | ], |
114 | 114 | ], |
115 | - ]); |
|
115 | + ] ); |
|
116 | 116 | |
117 | 117 | // There aren't any entries to show! |
118 | - if (empty($count)) { |
|
118 | + if ( empty( $count ) ) { |
|
119 | 119 | return; |
120 | 120 | } |
121 | 121 | |
122 | 122 | $notice_title = _n( |
123 | - esc_html__('There is an unapproved entry that is not being shown.', 'gravityview'), |
|
124 | - esc_html__('There are %s unapproved entries that are not being shown.', 'gravityview'), |
|
123 | + esc_html__( 'There is an unapproved entry that is not being shown.', 'gravityview' ), |
|
124 | + esc_html__( 'There are %s unapproved entries that are not being shown.', 'gravityview' ), |
|
125 | 125 | $count |
126 | 126 | ); |
127 | 127 | |
128 | 128 | $float_dir = is_rtl() ? 'left' : 'right'; |
129 | - $hide_link = sprintf('<a href="%s" style="float: '.$float_dir.'; font-size: 1rem" role="button">%s</a>', esc_url(wp_nonce_url(add_query_arg(['notice' => 'no_entries_'.$gravityview->view->ID]), 'dismiss', 'gv-dismiss')), esc_html__('Hide this notice', 'gravityview')); |
|
129 | + $hide_link = sprintf( '<a href="%s" style="float: ' . $float_dir . '; font-size: 1rem" role="button">%s</a>', esc_url( wp_nonce_url( add_query_arg( [ 'notice' => 'no_entries_' . $gravityview->view->ID ] ), 'dismiss', 'gv-dismiss' ) ), esc_html__( 'Hide this notice', 'gravityview' ) ); |
|
130 | 130 | |
131 | 131 | $message_strings = [ |
132 | - '<h3>'.sprintf($notice_title, number_format_i18n($count)).$hide_link.'</h3>', |
|
133 | - esc_html__('The "Show only approved entries" setting is enabled, so only entries that have been approved are displayed.', 'gravityview'), |
|
134 | - sprintf('<a href="%s">%s</a>', 'https://docs.gravityview.co/article/490-entry-approval-gravity-forms', esc_html__('Learn about entry approval.', 'gravityview')), |
|
132 | + '<h3>' . sprintf( $notice_title, number_format_i18n( $count ) ) . $hide_link . '</h3>', |
|
133 | + esc_html__( 'The "Show only approved entries" setting is enabled, so only entries that have been approved are displayed.', 'gravityview' ), |
|
134 | + sprintf( '<a href="%s">%s</a>', 'https://docs.gravityview.co/article/490-entry-approval-gravity-forms', esc_html__( 'Learn about entry approval.', 'gravityview' ) ), |
|
135 | 135 | "\n\n", |
136 | - sprintf(esc_html_x('%sEdit the View settings%s or %sApprove entries%s', 'Replacements are HTML links', 'gravityview'), '<a href="'.esc_url(get_edit_post_link($gravityview->view->ID, false)).'" style="font-weight: bold;">', '</a>', '<a href="'.esc_url(admin_url('admin.php?page=gf_entries&id='.$gravityview->view->form->ID)).'" style="font-weight: bold;">', '</a>'), |
|
136 | + sprintf( esc_html_x( '%sEdit the View settings%s or %sApprove entries%s', 'Replacements are HTML links', 'gravityview' ), '<a href="' . esc_url( get_edit_post_link( $gravityview->view->ID, false ) ) . '" style="font-weight: bold;">', '</a>', '<a href="' . esc_url( admin_url( 'admin.php?page=gf_entries&id=' . $gravityview->view->form->ID ) ) . '" style="font-weight: bold;">', '</a>' ), |
|
137 | 137 | "\n\n", |
138 | - sprintf('<img alt="%s" src="%s" style="padding: 10px 0; max-width: 550px;" />', esc_html__('Show only approved entries', 'gravityview'), esc_url(plugins_url('assets/images/screenshots/entry-approval.png', GRAVITYVIEW_FILE))), |
|
138 | + sprintf( '<img alt="%s" src="%s" style="padding: 10px 0; max-width: 550px;" />', esc_html__( 'Show only approved entries', 'gravityview' ), esc_url( plugins_url( 'assets/images/screenshots/entry-approval.png', GRAVITYVIEW_FILE ) ) ), |
|
139 | 139 | "\n\n", |
140 | - esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'), |
|
140 | + esc_html__( 'You can only see this message because you are able to edit this View.', 'gravityview' ), |
|
141 | 141 | ]; |
142 | 142 | |
143 | - $notice = wpautop(implode(' ', $message_strings)); |
|
143 | + $notice = wpautop( implode( ' ', $message_strings ) ); |
|
144 | 144 | |
145 | - echo \GVCommon::generate_notice($notice, 'warning', 'edit_gravityview', $gravityview->view->ID); |
|
145 | + echo \GVCommon::generate_notice( $notice, 'warning', 'edit_gravityview', $gravityview->view->ID ); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -154,40 +154,39 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @return void |
156 | 156 | */ |
157 | - private static function maybe_print_configuration_notice($gravityview) |
|
157 | + private static function maybe_print_configuration_notice( $gravityview ) |
|
158 | 158 | { |
159 | - switch (true) { |
|
159 | + switch ( true ) { |
|
160 | 160 | case $gravityview->request->is_edit_entry() : |
161 | - $tab = __('Edit Entry', 'gravityview'); |
|
161 | + $tab = __( 'Edit Entry', 'gravityview' ); |
|
162 | 162 | $context = 'edit'; |
163 | 163 | break; |
164 | - case $gravityview->request->is_entry($gravityview->view->form ? $gravityview->view->form->ID : 0) : |
|
165 | - $tab = __('Single Entry', 'gravityview'); |
|
164 | + case $gravityview->request->is_entry( $gravityview->view->form ? $gravityview->view->form->ID : 0 ) : $tab = __( 'Single Entry', 'gravityview' ); |
|
166 | 165 | $context = 'single'; |
167 | 166 | break; |
168 | 167 | default: |
169 | - $tab = __('Multiple Entries', 'gravityview'); |
|
168 | + $tab = __( 'Multiple Entries', 'gravityview' ); |
|
170 | 169 | $context = 'directory'; |
171 | 170 | break; |
172 | 171 | } |
173 | 172 | |
174 | 173 | $cls = $gravityview->template; |
175 | - $slug = property_exists($cls, '_configuration_slug') ? $cls::$_configuration_slug : $cls::$slug; |
|
174 | + $slug = property_exists( $cls, '_configuration_slug' ) ? $cls::$_configuration_slug : $cls::$slug; |
|
176 | 175 | |
177 | 176 | // If the zone has been configured, don't display notice. |
178 | - if ($gravityview->fields->by_position(sprintf('%s_%s-*', $context, $slug))->by_visible($gravityview->view)->count()) { |
|
177 | + if ( $gravityview->fields->by_position( sprintf( '%s_%s-*', $context, $slug ) )->by_visible( $gravityview->view )->count() ) { |
|
179 | 178 | return; |
180 | 179 | } |
181 | 180 | |
182 | - $title = sprintf(esc_html_x('The %s layout has not been configured.', 'Displayed when a View is not configured. %s is replaced by the tab label', 'gravityview'), $tab); |
|
183 | - $edit_link = admin_url(sprintf('post.php?post=%d&action=edit#%s-view', $gravityview->view->ID, $context)); |
|
184 | - $action_text = sprintf(esc_html__('Add fields to %s', 'gravityview'), $tab); |
|
185 | - $message = esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
181 | + $title = sprintf( esc_html_x( 'The %s layout has not been configured.', 'Displayed when a View is not configured. %s is replaced by the tab label', 'gravityview' ), $tab ); |
|
182 | + $edit_link = admin_url( sprintf( 'post.php?post=%d&action=edit#%s-view', $gravityview->view->ID, $context ) ); |
|
183 | + $action_text = sprintf( esc_html__( 'Add fields to %s', 'gravityview' ), $tab ); |
|
184 | + $message = esc_html__( 'You can only see this message because you are able to edit this View.', 'gravityview' ); |
|
186 | 185 | |
187 | - $image = sprintf('<img alt="%s" src="%s" style="margin-top: 10px;" />', $tab, esc_url(plugins_url(sprintf('assets/images/tab-%s.png', $context), GRAVITYVIEW_FILE))); |
|
188 | - $output = sprintf('<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>', $title, esc_url($edit_link), $action_text, $message); |
|
186 | + $image = sprintf( '<img alt="%s" src="%s" style="margin-top: 10px;" />', $tab, esc_url( plugins_url( sprintf( 'assets/images/tab-%s.png', $context ), GRAVITYVIEW_FILE ) ) ); |
|
187 | + $output = sprintf( '<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>', $title, esc_url( $edit_link ), $action_text, $message ); |
|
189 | 188 | |
190 | - echo \GVCommon::generate_notice($output.$image, 'gv-warning warning', 'edit_gravityview', $gravityview->view->ID); |
|
189 | + echo \GVCommon::generate_notice( $output . $image, 'gv-warning warning', 'edit_gravityview', $gravityview->view->ID ); |
|
191 | 190 | } |
192 | 191 | |
193 | 192 | /** |
@@ -199,27 +198,27 @@ discard block |
||
199 | 198 | * |
200 | 199 | * @return void |
201 | 200 | */ |
202 | - private static function maybe_print_reserved_slugs_notice($gravityview) |
|
201 | + private static function maybe_print_reserved_slugs_notice( $gravityview ) |
|
203 | 202 | { |
204 | 203 | global $wp; |
205 | 204 | global $wp_rewrite; |
206 | 205 | |
207 | 206 | $reserved_slugs = [ |
208 | 207 | $wp_rewrite->search_base, |
209 | - apply_filters('gravityview_directory_endpoint', 'entry'), |
|
208 | + apply_filters( 'gravityview_directory_endpoint', 'entry' ), |
|
210 | 209 | ]; |
211 | 210 | |
212 | 211 | $post_types = get_post_types(); |
213 | 212 | |
214 | - foreach ($post_types as $post_type) { |
|
215 | - $post_type_rewrite = get_post_type_object($post_type)->rewrite; |
|
213 | + foreach ( $post_types as $post_type ) { |
|
214 | + $post_type_rewrite = get_post_type_object( $post_type )->rewrite; |
|
216 | 215 | |
217 | - if ($slug = \GV\Utils::get($post_type_rewrite, 'slug')) { |
|
218 | - $reserved_slugs[] = $slug; |
|
216 | + if ( $slug = \GV\Utils::get( $post_type_rewrite, 'slug' ) ) { |
|
217 | + $reserved_slugs[ ] = $slug; |
|
219 | 218 | } |
220 | 219 | } |
221 | 220 | |
222 | - unset($post_types, $post_type_rewrite); |
|
221 | + unset( $post_types, $post_type_rewrite ); |
|
223 | 222 | |
224 | 223 | /** |
225 | 224 | * @filter `gravityview/rewrite/reserved_slugs` Modify the reserved embed slugs that trigger a warning. |
@@ -229,23 +228,23 @@ discard block |
||
229 | 228 | * @param array $reserved_slugs An array of strings, reserved slugs. |
230 | 229 | * @param \GV\Template_Context $gravityview The context. |
231 | 230 | */ |
232 | - $reserved_slugs = apply_filters('gravityview/rewrite/reserved_slugs', $reserved_slugs, $gravityview); |
|
231 | + $reserved_slugs = apply_filters( 'gravityview/rewrite/reserved_slugs', $reserved_slugs, $gravityview ); |
|
233 | 232 | |
234 | - $reserved_slugs = array_map('strtolower', $reserved_slugs); |
|
233 | + $reserved_slugs = array_map( 'strtolower', $reserved_slugs ); |
|
235 | 234 | |
236 | - if (!in_array(strtolower($wp->request), $reserved_slugs, true)) { |
|
235 | + if ( ! in_array( strtolower( $wp->request ), $reserved_slugs, true ) ) { |
|
237 | 236 | return; |
238 | 237 | } |
239 | 238 | |
240 | - gravityview()->log->error('{slug} page URL is reserved.', ['slug' => $wp->request]); |
|
239 | + gravityview()->log->error( '{slug} page URL is reserved.', [ 'slug' => $wp->request ] ); |
|
241 | 240 | |
242 | - $title = esc_html__('GravityView will not work correctly on this page because of the URL Slug.', 'gravityview'); |
|
243 | - $message = __('Please <a href="%s">read this article</a> for more information.', 'gravityview'); |
|
244 | - $message .= ' '.esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
241 | + $title = esc_html__( 'GravityView will not work correctly on this page because of the URL Slug.', 'gravityview' ); |
|
242 | + $message = __( 'Please <a href="%s">read this article</a> for more information.', 'gravityview' ); |
|
243 | + $message .= ' ' . esc_html__( 'You can only see this message because you are able to edit this View.', 'gravityview' ); |
|
245 | 244 | |
246 | - $output = sprintf('<h3>%s</h3><p>%s</p>', $title, sprintf($message, 'https://docs.gravityview.co/article/659-reserved-urls')); |
|
245 | + $output = sprintf( '<h3>%s</h3><p>%s</p>', $title, sprintf( $message, 'https://docs.gravityview.co/article/659-reserved-urls' ) ); |
|
247 | 246 | |
248 | - echo \GVCommon::generate_notice($output, 'gv-error error', 'edit_gravityview', $gravityview->view->ID); |
|
247 | + echo \GVCommon::generate_notice( $output, 'gv-error error', 'edit_gravityview', $gravityview->view->ID ); |
|
249 | 248 | } |
250 | 249 | |
251 | 250 | /** |
@@ -259,9 +258,9 @@ discard block |
||
259 | 258 | * |
260 | 259 | * @return \callable A closure used in the filter. |
261 | 260 | */ |
262 | - public function legacy_template_warning($view, $path) |
|
261 | + public function legacy_template_warning( $view, $path ) |
|
263 | 262 | { |
264 | - return function () { |
|
263 | + return function() { |
|
265 | 264 | // Do not panic for now... |
266 | 265 | }; |
267 | 266 | } |
@@ -12,13 +12,11 @@ discard block |
||
12 | 12 | * |
13 | 13 | * The base for all renderers. |
14 | 14 | */ |
15 | -class Renderer |
|
16 | -{ |
|
15 | +class Renderer { |
|
17 | 16 | /** |
18 | 17 | * Initialization. |
19 | 18 | */ |
20 | - public function __construct() |
|
21 | - { |
|
19 | + public function __construct() { |
|
22 | 20 | if (!has_action('gravityview/template/before', [__CLASS__, 'maybe_print_notices'])) { |
23 | 21 | add_action('gravityview/template/before', [__CLASS__, 'maybe_print_notices']); |
24 | 22 | } |
@@ -33,8 +31,7 @@ discard block |
||
33 | 31 | * |
34 | 32 | * @return void |
35 | 33 | */ |
36 | - public static function maybe_print_notices($gravityview = null) |
|
37 | - { |
|
34 | + public static function maybe_print_notices($gravityview = null) { |
|
38 | 35 | if (!$gravityview instanceof \GV\Template_Context) { |
39 | 36 | /** Call the legacy code. */ |
40 | 37 | \GravityView_frontend::getInstance()->context_not_configured_warning(gravityview_get_view_id()); |
@@ -58,8 +55,7 @@ discard block |
||
58 | 55 | * |
59 | 56 | * @return void |
60 | 57 | */ |
61 | - private static function maybe_print_entry_approval_notice($gravityview) |
|
62 | - { |
|
58 | + private static function maybe_print_entry_approval_notice($gravityview) { |
|
63 | 59 | if ($gravityview->entries && $gravityview->entries->count()) { |
64 | 60 | return; |
65 | 61 | } |
@@ -154,8 +150,7 @@ discard block |
||
154 | 150 | * |
155 | 151 | * @return void |
156 | 152 | */ |
157 | - private static function maybe_print_configuration_notice($gravityview) |
|
158 | - { |
|
153 | + private static function maybe_print_configuration_notice($gravityview) { |
|
159 | 154 | switch (true) { |
160 | 155 | case $gravityview->request->is_edit_entry() : |
161 | 156 | $tab = __('Edit Entry', 'gravityview'); |
@@ -199,8 +194,7 @@ discard block |
||
199 | 194 | * |
200 | 195 | * @return void |
201 | 196 | */ |
202 | - private static function maybe_print_reserved_slugs_notice($gravityview) |
|
203 | - { |
|
197 | + private static function maybe_print_reserved_slugs_notice($gravityview) { |
|
204 | 198 | global $wp; |
205 | 199 | global $wp_rewrite; |
206 | 200 | |
@@ -259,8 +253,7 @@ discard block |
||
259 | 253 | * |
260 | 254 | * @return \callable A closure used in the filter. |
261 | 255 | */ |
262 | - public function legacy_template_warning($view, $path) |
|
263 | - { |
|
256 | + public function legacy_template_warning($view, $path) { |
|
264 | 257 | return function () { |
265 | 258 | // Do not panic for now... |
266 | 259 | }; |
@@ -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,270 +14,270 @@ discard block |
||
14 | 14 | */ |
15 | 15 | abstract class Entry |
16 | 16 | { |
17 | - /** |
|
18 | - * @var string The identifier of the backend used for this entry. |
|
19 | - * |
|
20 | - * @api |
|
21 | - * |
|
22 | - * @since 2.0 |
|
23 | - */ |
|
24 | - public static $backend = null; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var int The ID for this entry. |
|
28 | - * |
|
29 | - * @api |
|
30 | - * |
|
31 | - * @since 2.0 |
|
32 | - */ |
|
33 | - public $ID = null; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var mixed The backing entry. |
|
37 | - */ |
|
38 | - protected $entry; |
|
39 | - |
|
40 | - /** |
|
41 | - * Adds the necessary rewrites for single Entries. |
|
42 | - * |
|
43 | - * @internal |
|
44 | - * |
|
45 | - * @return void |
|
46 | - */ |
|
47 | - public static function add_rewrite_endpoint() |
|
48 | - { |
|
49 | - global $wp_rewrite; |
|
50 | - |
|
51 | - $endpoint = self::get_endpoint_name(); |
|
52 | - |
|
53 | - /** Let's make sure the endpoint array is not polluted. */ |
|
54 | - if (in_array([EP_PERMALINK | EP_PERMALINK | EP_ROOT, $endpoint, $endpoint], $wp_rewrite->endpoints)) { |
|
55 | - return; |
|
56 | - } |
|
57 | - |
|
58 | - add_rewrite_endpoint($endpoint, EP_PAGES | EP_PERMALINK | EP_ROOT); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Return the endpoint name for a single Entry. |
|
63 | - * |
|
64 | - * Also used as the query_var for the time being. |
|
65 | - * |
|
66 | - * @internal |
|
67 | - * |
|
68 | - * @return string The name. Default: "entry" |
|
69 | - */ |
|
70 | - public static function get_endpoint_name() |
|
71 | - { |
|
72 | - /** |
|
73 | - * @filter `gravityview_directory_endpoint` Change the slug used for single entries |
|
74 | - * |
|
75 | - * @param string $endpoint Slug to use when accessing single entry. Default: `entry` |
|
76 | - */ |
|
77 | - $endpoint = apply_filters('gravityview_directory_endpoint', 'entry'); |
|
78 | - |
|
79 | - return sanitize_title($endpoint); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Construct a \GV\Entry instance by ID. |
|
84 | - * |
|
85 | - * @param int|string $entry_id The internal entry ID. |
|
86 | - * |
|
87 | - * @api |
|
88 | - * |
|
89 | - * @since 2.0 |
|
90 | - * |
|
91 | - * @return \GV\Entry|null An instance of this entry or null if not found. |
|
92 | - */ |
|
93 | - public static function by_id($entry_id) |
|
94 | - { |
|
95 | - return null; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Return the backing entry object. |
|
100 | - * |
|
101 | - * @return array The backing entry object. |
|
102 | - */ |
|
103 | - public function as_entry() |
|
104 | - { |
|
105 | - return $this->entry; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Return the link to this entry in the supplied context. |
|
110 | - * |
|
111 | - * @api |
|
112 | - * |
|
113 | - * @since 2.0 |
|
114 | - * |
|
115 | - * @param \GV\View|null $view The View context. |
|
116 | - * @param \GV\Request $request The Request (current if null). |
|
117 | - * @param bool $track_directory Keep the housing directory arguments intact (used for breadcrumbs, for example). Default: true. |
|
118 | - * |
|
119 | - * @return string The permalink to this entry. |
|
120 | - */ |
|
121 | - public function get_permalink(\GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
122 | - { |
|
123 | - if (is_null($request)) { |
|
124 | - $request = &gravityview()->request; |
|
125 | - } |
|
126 | - |
|
127 | - global $post; |
|
128 | - |
|
129 | - $args = []; |
|
130 | - |
|
131 | - $view_id = is_null($view) ? null : $view->ID; |
|
132 | - |
|
133 | - $permalink = null; |
|
134 | - |
|
135 | - /** This is not a regular view. */ |
|
136 | - if (!$request->is_view()) { |
|
137 | - |
|
138 | - /** Must be an embed of some sort. */ |
|
139 | - if (is_object($post) && is_numeric($post->ID)) { |
|
140 | - $permalink = get_permalink($post->ID); |
|
141 | - |
|
142 | - $view_collection = View_Collection::from_post($post); |
|
143 | - |
|
144 | - if (1 < $view_collection->count()) { |
|
145 | - $args['gvid'] = $view_id; |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - /** Fallback to regular view base. */ |
|
151 | - if (is_null($permalink)) { |
|
152 | - $permalink = get_permalink($view_id); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @filter `gravityview_directory_link` Modify the URL to the View "directory" context |
|
157 | - * |
|
158 | - * @since 1.19.4 |
|
159 | - * |
|
160 | - * @param string $link URL to the View's "directory" context (Multiple Entries screen) |
|
161 | - * @param int $post_id ID of the post to link to. If the View is embedded, it is the post or page ID |
|
162 | - */ |
|
163 | - $permalink = apply_filters('gravityview_directory_link', $permalink, $request->is_view() ? $view_id : ($post ? $post->ID : null)); |
|
164 | - |
|
165 | - $entry_endpoint_name = \GV\Entry::get_endpoint_name(); |
|
166 | - |
|
167 | - $entry_slug = $this->get_slug(true, $view, $request, $track_directory); |
|
168 | - |
|
169 | - /** Assemble the permalink. */ |
|
170 | - if (get_option('permalink_structure') && !is_preview()) { |
|
171 | - /** |
|
172 | - * Make sure the $directory_link doesn't contain any query otherwise it will break when adding the entry slug. |
|
173 | - * |
|
174 | - * @since 1.16.5 |
|
175 | - */ |
|
176 | - $link_parts = explode('?', $permalink); |
|
177 | - |
|
178 | - $query = !empty($link_parts[1]) ? '?'.$link_parts[1] : ''; |
|
179 | - |
|
180 | - $permalink = trailingslashit($link_parts[0]).$entry_endpoint_name.'/'.$entry_slug.'/'.$query; |
|
181 | - } else { |
|
182 | - $args[$entry_endpoint_name] = $entry_slug; |
|
183 | - } |
|
184 | - |
|
185 | - if ($track_directory) { |
|
186 | - if (!empty($_GET['pagenum'])) { |
|
187 | - $args['pagenum'] = intval($_GET['pagenum']); |
|
188 | - } |
|
189 | - |
|
190 | - if ($sort = Utils::_GET('sort')) { |
|
191 | - $args['sort'] = $sort; |
|
192 | - $args['dir'] = Utils::_GET('dir'); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - $permalink = add_query_arg($args, $permalink); |
|
197 | - |
|
198 | - /** |
|
199 | - * @filter `gravityview/entry/permalink` The permalink of this entry. |
|
200 | - * |
|
201 | - * @since 2.0 |
|
202 | - * |
|
203 | - * @param string $permalink The permalink. |
|
204 | - * @param \GV\Entry $entry The entry we're retrieving it for. |
|
205 | - * @param \GV\View|null $view The view context. |
|
206 | - * @param \GV\Request $request The request context. |
|
207 | - */ |
|
208 | - return apply_filters('gravityview/entry/permalink', $permalink, $this, $view, $request); |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Get the entry slug. |
|
213 | - * |
|
214 | - * @internal (for now!) |
|
215 | - * |
|
216 | - * @todo Should $apply_filter be default true or false? Unit tests pass either way... |
|
217 | - * |
|
218 | - * @since 2.7 |
|
219 | - * |
|
220 | - * @uses \GravityView_API::get_entry_slug |
|
221 | - * |
|
222 | - * @param bool $apply_filter Whether to apply the `gravityview/entry/slug` filter. Default: false. |
|
223 | - * @param \GV\View|null $view The View context. |
|
224 | - * @param \GV\Request $request The Request (current if null). |
|
225 | - * @param bool $track_directory Keep the housing directory arguments intact (used for breadcrumbs, for example). Default: true. |
|
226 | - * |
|
227 | - * @return string Unique slug ID, passed through `sanitize_title()`, with `gravityview/entry/slug` filter applied |
|
228 | - */ |
|
229 | - public function get_slug($apply_filter = false, \GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
230 | - { |
|
231 | - $entry_slug = \GravityView_API::get_entry_slug($this->ID, $this->as_entry()); |
|
232 | - |
|
233 | - if (!$apply_filter) { |
|
234 | - return $entry_slug; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @filter `gravityview/entry/slug` Modify the entry URL slug as needed. |
|
239 | - * |
|
240 | - * @since 2.2.1 |
|
241 | - * |
|
242 | - * @param string $entry_slug The slug, sanitized with sanitize_title() |
|
243 | - * @param null|\GV\Entry $this The entry object. |
|
244 | - * @param null|\GV\View $view The view object. |
|
245 | - * @param null|\GV\Request $request The request. |
|
246 | - * @param bool $track_directory Whether the directory is tracked. |
|
247 | - */ |
|
248 | - $entry_slug = apply_filters('gravityview/entry/slug', $entry_slug, $this, $view, $request, $track_directory); |
|
249 | - |
|
250 | - return $entry_slug; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Is this a multi-entry (joined entry). |
|
255 | - * |
|
256 | - * @since 2.2 |
|
257 | - * |
|
258 | - * @return bool |
|
259 | - */ |
|
260 | - public function is_multi() |
|
261 | - { |
|
262 | - return $this instanceof Multi_Entry; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * If this is a Multi_Entry filter it by Field. |
|
267 | - * |
|
268 | - * @since 2.2 |
|
269 | - * |
|
270 | - * @param \GV\Field $field The field to filter by. |
|
271 | - * @param int $fallback A fallback form_id if the field supplied is invalid. |
|
272 | - * |
|
273 | - * @return \GV\Entry|null A \GV\Entry or null if not found. |
|
274 | - */ |
|
275 | - public function from_field($field, $fallback = null) |
|
276 | - { |
|
277 | - if (!$this->is_multi()) { |
|
278 | - return $this; |
|
279 | - } |
|
280 | - |
|
281 | - return Utils::get($this, $field->form_id, $fallback); |
|
282 | - } |
|
17 | + /** |
|
18 | + * @var string The identifier of the backend used for this entry. |
|
19 | + * |
|
20 | + * @api |
|
21 | + * |
|
22 | + * @since 2.0 |
|
23 | + */ |
|
24 | + public static $backend = null; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var int The ID for this entry. |
|
28 | + * |
|
29 | + * @api |
|
30 | + * |
|
31 | + * @since 2.0 |
|
32 | + */ |
|
33 | + public $ID = null; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var mixed The backing entry. |
|
37 | + */ |
|
38 | + protected $entry; |
|
39 | + |
|
40 | + /** |
|
41 | + * Adds the necessary rewrites for single Entries. |
|
42 | + * |
|
43 | + * @internal |
|
44 | + * |
|
45 | + * @return void |
|
46 | + */ |
|
47 | + public static function add_rewrite_endpoint() |
|
48 | + { |
|
49 | + global $wp_rewrite; |
|
50 | + |
|
51 | + $endpoint = self::get_endpoint_name(); |
|
52 | + |
|
53 | + /** Let's make sure the endpoint array is not polluted. */ |
|
54 | + if (in_array([EP_PERMALINK | EP_PERMALINK | EP_ROOT, $endpoint, $endpoint], $wp_rewrite->endpoints)) { |
|
55 | + return; |
|
56 | + } |
|
57 | + |
|
58 | + add_rewrite_endpoint($endpoint, EP_PAGES | EP_PERMALINK | EP_ROOT); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Return the endpoint name for a single Entry. |
|
63 | + * |
|
64 | + * Also used as the query_var for the time being. |
|
65 | + * |
|
66 | + * @internal |
|
67 | + * |
|
68 | + * @return string The name. Default: "entry" |
|
69 | + */ |
|
70 | + public static function get_endpoint_name() |
|
71 | + { |
|
72 | + /** |
|
73 | + * @filter `gravityview_directory_endpoint` Change the slug used for single entries |
|
74 | + * |
|
75 | + * @param string $endpoint Slug to use when accessing single entry. Default: `entry` |
|
76 | + */ |
|
77 | + $endpoint = apply_filters('gravityview_directory_endpoint', 'entry'); |
|
78 | + |
|
79 | + return sanitize_title($endpoint); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Construct a \GV\Entry instance by ID. |
|
84 | + * |
|
85 | + * @param int|string $entry_id The internal entry ID. |
|
86 | + * |
|
87 | + * @api |
|
88 | + * |
|
89 | + * @since 2.0 |
|
90 | + * |
|
91 | + * @return \GV\Entry|null An instance of this entry or null if not found. |
|
92 | + */ |
|
93 | + public static function by_id($entry_id) |
|
94 | + { |
|
95 | + return null; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Return the backing entry object. |
|
100 | + * |
|
101 | + * @return array The backing entry object. |
|
102 | + */ |
|
103 | + public function as_entry() |
|
104 | + { |
|
105 | + return $this->entry; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Return the link to this entry in the supplied context. |
|
110 | + * |
|
111 | + * @api |
|
112 | + * |
|
113 | + * @since 2.0 |
|
114 | + * |
|
115 | + * @param \GV\View|null $view The View context. |
|
116 | + * @param \GV\Request $request The Request (current if null). |
|
117 | + * @param bool $track_directory Keep the housing directory arguments intact (used for breadcrumbs, for example). Default: true. |
|
118 | + * |
|
119 | + * @return string The permalink to this entry. |
|
120 | + */ |
|
121 | + public function get_permalink(\GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
122 | + { |
|
123 | + if (is_null($request)) { |
|
124 | + $request = &gravityview()->request; |
|
125 | + } |
|
126 | + |
|
127 | + global $post; |
|
128 | + |
|
129 | + $args = []; |
|
130 | + |
|
131 | + $view_id = is_null($view) ? null : $view->ID; |
|
132 | + |
|
133 | + $permalink = null; |
|
134 | + |
|
135 | + /** This is not a regular view. */ |
|
136 | + if (!$request->is_view()) { |
|
137 | + |
|
138 | + /** Must be an embed of some sort. */ |
|
139 | + if (is_object($post) && is_numeric($post->ID)) { |
|
140 | + $permalink = get_permalink($post->ID); |
|
141 | + |
|
142 | + $view_collection = View_Collection::from_post($post); |
|
143 | + |
|
144 | + if (1 < $view_collection->count()) { |
|
145 | + $args['gvid'] = $view_id; |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + /** Fallback to regular view base. */ |
|
151 | + if (is_null($permalink)) { |
|
152 | + $permalink = get_permalink($view_id); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @filter `gravityview_directory_link` Modify the URL to the View "directory" context |
|
157 | + * |
|
158 | + * @since 1.19.4 |
|
159 | + * |
|
160 | + * @param string $link URL to the View's "directory" context (Multiple Entries screen) |
|
161 | + * @param int $post_id ID of the post to link to. If the View is embedded, it is the post or page ID |
|
162 | + */ |
|
163 | + $permalink = apply_filters('gravityview_directory_link', $permalink, $request->is_view() ? $view_id : ($post ? $post->ID : null)); |
|
164 | + |
|
165 | + $entry_endpoint_name = \GV\Entry::get_endpoint_name(); |
|
166 | + |
|
167 | + $entry_slug = $this->get_slug(true, $view, $request, $track_directory); |
|
168 | + |
|
169 | + /** Assemble the permalink. */ |
|
170 | + if (get_option('permalink_structure') && !is_preview()) { |
|
171 | + /** |
|
172 | + * Make sure the $directory_link doesn't contain any query otherwise it will break when adding the entry slug. |
|
173 | + * |
|
174 | + * @since 1.16.5 |
|
175 | + */ |
|
176 | + $link_parts = explode('?', $permalink); |
|
177 | + |
|
178 | + $query = !empty($link_parts[1]) ? '?'.$link_parts[1] : ''; |
|
179 | + |
|
180 | + $permalink = trailingslashit($link_parts[0]).$entry_endpoint_name.'/'.$entry_slug.'/'.$query; |
|
181 | + } else { |
|
182 | + $args[$entry_endpoint_name] = $entry_slug; |
|
183 | + } |
|
184 | + |
|
185 | + if ($track_directory) { |
|
186 | + if (!empty($_GET['pagenum'])) { |
|
187 | + $args['pagenum'] = intval($_GET['pagenum']); |
|
188 | + } |
|
189 | + |
|
190 | + if ($sort = Utils::_GET('sort')) { |
|
191 | + $args['sort'] = $sort; |
|
192 | + $args['dir'] = Utils::_GET('dir'); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + $permalink = add_query_arg($args, $permalink); |
|
197 | + |
|
198 | + /** |
|
199 | + * @filter `gravityview/entry/permalink` The permalink of this entry. |
|
200 | + * |
|
201 | + * @since 2.0 |
|
202 | + * |
|
203 | + * @param string $permalink The permalink. |
|
204 | + * @param \GV\Entry $entry The entry we're retrieving it for. |
|
205 | + * @param \GV\View|null $view The view context. |
|
206 | + * @param \GV\Request $request The request context. |
|
207 | + */ |
|
208 | + return apply_filters('gravityview/entry/permalink', $permalink, $this, $view, $request); |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Get the entry slug. |
|
213 | + * |
|
214 | + * @internal (for now!) |
|
215 | + * |
|
216 | + * @todo Should $apply_filter be default true or false? Unit tests pass either way... |
|
217 | + * |
|
218 | + * @since 2.7 |
|
219 | + * |
|
220 | + * @uses \GravityView_API::get_entry_slug |
|
221 | + * |
|
222 | + * @param bool $apply_filter Whether to apply the `gravityview/entry/slug` filter. Default: false. |
|
223 | + * @param \GV\View|null $view The View context. |
|
224 | + * @param \GV\Request $request The Request (current if null). |
|
225 | + * @param bool $track_directory Keep the housing directory arguments intact (used for breadcrumbs, for example). Default: true. |
|
226 | + * |
|
227 | + * @return string Unique slug ID, passed through `sanitize_title()`, with `gravityview/entry/slug` filter applied |
|
228 | + */ |
|
229 | + public function get_slug($apply_filter = false, \GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
230 | + { |
|
231 | + $entry_slug = \GravityView_API::get_entry_slug($this->ID, $this->as_entry()); |
|
232 | + |
|
233 | + if (!$apply_filter) { |
|
234 | + return $entry_slug; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @filter `gravityview/entry/slug` Modify the entry URL slug as needed. |
|
239 | + * |
|
240 | + * @since 2.2.1 |
|
241 | + * |
|
242 | + * @param string $entry_slug The slug, sanitized with sanitize_title() |
|
243 | + * @param null|\GV\Entry $this The entry object. |
|
244 | + * @param null|\GV\View $view The view object. |
|
245 | + * @param null|\GV\Request $request The request. |
|
246 | + * @param bool $track_directory Whether the directory is tracked. |
|
247 | + */ |
|
248 | + $entry_slug = apply_filters('gravityview/entry/slug', $entry_slug, $this, $view, $request, $track_directory); |
|
249 | + |
|
250 | + return $entry_slug; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Is this a multi-entry (joined entry). |
|
255 | + * |
|
256 | + * @since 2.2 |
|
257 | + * |
|
258 | + * @return bool |
|
259 | + */ |
|
260 | + public function is_multi() |
|
261 | + { |
|
262 | + return $this instanceof Multi_Entry; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * If this is a Multi_Entry filter it by Field. |
|
267 | + * |
|
268 | + * @since 2.2 |
|
269 | + * |
|
270 | + * @param \GV\Field $field The field to filter by. |
|
271 | + * @param int $fallback A fallback form_id if the field supplied is invalid. |
|
272 | + * |
|
273 | + * @return \GV\Entry|null A \GV\Entry or null if not found. |
|
274 | + */ |
|
275 | + public function from_field($field, $fallback = null) |
|
276 | + { |
|
277 | + if (!$this->is_multi()) { |
|
278 | + return $this; |
|
279 | + } |
|
280 | + |
|
281 | + return Utils::get($this, $field->form_id, $fallback); |
|
282 | + } |
|
283 | 283 | } |
@@ -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 | |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | $endpoint = self::get_endpoint_name(); |
52 | 52 | |
53 | 53 | /** Let's make sure the endpoint array is not polluted. */ |
54 | - if (in_array([EP_PERMALINK | EP_PERMALINK | EP_ROOT, $endpoint, $endpoint], $wp_rewrite->endpoints)) { |
|
54 | + if ( in_array( [ EP_PERMALINK | EP_PERMALINK | EP_ROOT, $endpoint, $endpoint ], $wp_rewrite->endpoints ) ) { |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | - add_rewrite_endpoint($endpoint, EP_PAGES | EP_PERMALINK | EP_ROOT); |
|
58 | + add_rewrite_endpoint( $endpoint, EP_PAGES | EP_PERMALINK | EP_ROOT ); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -74,9 +74,9 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @param string $endpoint Slug to use when accessing single entry. Default: `entry` |
76 | 76 | */ |
77 | - $endpoint = apply_filters('gravityview_directory_endpoint', 'entry'); |
|
77 | + $endpoint = apply_filters( 'gravityview_directory_endpoint', 'entry' ); |
|
78 | 78 | |
79 | - return sanitize_title($endpoint); |
|
79 | + return sanitize_title( $endpoint ); |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @return \GV\Entry|null An instance of this entry or null if not found. |
92 | 92 | */ |
93 | - public static function by_id($entry_id) |
|
93 | + public static function by_id( $entry_id ) |
|
94 | 94 | { |
95 | 95 | return null; |
96 | 96 | } |
@@ -118,38 +118,38 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @return string The permalink to this entry. |
120 | 120 | */ |
121 | - public function get_permalink(\GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
121 | + public function get_permalink( \GV\View $view = null, \GV\Request $request = null, $track_directory = true ) |
|
122 | 122 | { |
123 | - if (is_null($request)) { |
|
123 | + if ( is_null( $request ) ) { |
|
124 | 124 | $request = &gravityview()->request; |
125 | 125 | } |
126 | 126 | |
127 | 127 | global $post; |
128 | 128 | |
129 | - $args = []; |
|
129 | + $args = [ ]; |
|
130 | 130 | |
131 | - $view_id = is_null($view) ? null : $view->ID; |
|
131 | + $view_id = is_null( $view ) ? null : $view->ID; |
|
132 | 132 | |
133 | 133 | $permalink = null; |
134 | 134 | |
135 | 135 | /** This is not a regular view. */ |
136 | - if (!$request->is_view()) { |
|
136 | + if ( ! $request->is_view() ) { |
|
137 | 137 | |
138 | 138 | /** Must be an embed of some sort. */ |
139 | - if (is_object($post) && is_numeric($post->ID)) { |
|
140 | - $permalink = get_permalink($post->ID); |
|
139 | + if ( is_object( $post ) && is_numeric( $post->ID ) ) { |
|
140 | + $permalink = get_permalink( $post->ID ); |
|
141 | 141 | |
142 | - $view_collection = View_Collection::from_post($post); |
|
142 | + $view_collection = View_Collection::from_post( $post ); |
|
143 | 143 | |
144 | - if (1 < $view_collection->count()) { |
|
145 | - $args['gvid'] = $view_id; |
|
144 | + if ( 1 < $view_collection->count() ) { |
|
145 | + $args[ 'gvid' ] = $view_id; |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | 150 | /** Fallback to regular view base. */ |
151 | - if (is_null($permalink)) { |
|
152 | - $permalink = get_permalink($view_id); |
|
151 | + if ( is_null( $permalink ) ) { |
|
152 | + $permalink = get_permalink( $view_id ); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -160,40 +160,40 @@ discard block |
||
160 | 160 | * @param string $link URL to the View's "directory" context (Multiple Entries screen) |
161 | 161 | * @param int $post_id ID of the post to link to. If the View is embedded, it is the post or page ID |
162 | 162 | */ |
163 | - $permalink = apply_filters('gravityview_directory_link', $permalink, $request->is_view() ? $view_id : ($post ? $post->ID : null)); |
|
163 | + $permalink = apply_filters( 'gravityview_directory_link', $permalink, $request->is_view() ? $view_id : ( $post ? $post->ID : null ) ); |
|
164 | 164 | |
165 | 165 | $entry_endpoint_name = \GV\Entry::get_endpoint_name(); |
166 | 166 | |
167 | - $entry_slug = $this->get_slug(true, $view, $request, $track_directory); |
|
167 | + $entry_slug = $this->get_slug( true, $view, $request, $track_directory ); |
|
168 | 168 | |
169 | 169 | /** Assemble the permalink. */ |
170 | - if (get_option('permalink_structure') && !is_preview()) { |
|
170 | + if ( get_option( 'permalink_structure' ) && ! is_preview() ) { |
|
171 | 171 | /** |
172 | 172 | * Make sure the $directory_link doesn't contain any query otherwise it will break when adding the entry slug. |
173 | 173 | * |
174 | 174 | * @since 1.16.5 |
175 | 175 | */ |
176 | - $link_parts = explode('?', $permalink); |
|
176 | + $link_parts = explode( '?', $permalink ); |
|
177 | 177 | |
178 | - $query = !empty($link_parts[1]) ? '?'.$link_parts[1] : ''; |
|
178 | + $query = ! empty( $link_parts[ 1 ] ) ? '?' . $link_parts[ 1 ] : ''; |
|
179 | 179 | |
180 | - $permalink = trailingslashit($link_parts[0]).$entry_endpoint_name.'/'.$entry_slug.'/'.$query; |
|
180 | + $permalink = trailingslashit( $link_parts[ 0 ] ) . $entry_endpoint_name . '/' . $entry_slug . '/' . $query; |
|
181 | 181 | } else { |
182 | - $args[$entry_endpoint_name] = $entry_slug; |
|
182 | + $args[ $entry_endpoint_name ] = $entry_slug; |
|
183 | 183 | } |
184 | 184 | |
185 | - if ($track_directory) { |
|
186 | - if (!empty($_GET['pagenum'])) { |
|
187 | - $args['pagenum'] = intval($_GET['pagenum']); |
|
185 | + if ( $track_directory ) { |
|
186 | + if ( ! empty( $_GET[ 'pagenum' ] ) ) { |
|
187 | + $args[ 'pagenum' ] = intval( $_GET[ 'pagenum' ] ); |
|
188 | 188 | } |
189 | 189 | |
190 | - if ($sort = Utils::_GET('sort')) { |
|
191 | - $args['sort'] = $sort; |
|
192 | - $args['dir'] = Utils::_GET('dir'); |
|
190 | + if ( $sort = Utils::_GET( 'sort' ) ) { |
|
191 | + $args[ 'sort' ] = $sort; |
|
192 | + $args[ 'dir' ] = Utils::_GET( 'dir' ); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | |
196 | - $permalink = add_query_arg($args, $permalink); |
|
196 | + $permalink = add_query_arg( $args, $permalink ); |
|
197 | 197 | |
198 | 198 | /** |
199 | 199 | * @filter `gravityview/entry/permalink` The permalink of this entry. |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @param \GV\View|null $view The view context. |
206 | 206 | * @param \GV\Request $request The request context. |
207 | 207 | */ |
208 | - return apply_filters('gravityview/entry/permalink', $permalink, $this, $view, $request); |
|
208 | + return apply_filters( 'gravityview/entry/permalink', $permalink, $this, $view, $request ); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -226,11 +226,11 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @return string Unique slug ID, passed through `sanitize_title()`, with `gravityview/entry/slug` filter applied |
228 | 228 | */ |
229 | - public function get_slug($apply_filter = false, \GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
229 | + public function get_slug( $apply_filter = false, \GV\View $view = null, \GV\Request $request = null, $track_directory = true ) |
|
230 | 230 | { |
231 | - $entry_slug = \GravityView_API::get_entry_slug($this->ID, $this->as_entry()); |
|
231 | + $entry_slug = \GravityView_API::get_entry_slug( $this->ID, $this->as_entry() ); |
|
232 | 232 | |
233 | - if (!$apply_filter) { |
|
233 | + if ( ! $apply_filter ) { |
|
234 | 234 | return $entry_slug; |
235 | 235 | } |
236 | 236 | |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | * @param null|\GV\Request $request The request. |
246 | 246 | * @param bool $track_directory Whether the directory is tracked. |
247 | 247 | */ |
248 | - $entry_slug = apply_filters('gravityview/entry/slug', $entry_slug, $this, $view, $request, $track_directory); |
|
248 | + $entry_slug = apply_filters( 'gravityview/entry/slug', $entry_slug, $this, $view, $request, $track_directory ); |
|
249 | 249 | |
250 | 250 | return $entry_slug; |
251 | 251 | } |
@@ -272,12 +272,12 @@ discard block |
||
272 | 272 | * |
273 | 273 | * @return \GV\Entry|null A \GV\Entry or null if not found. |
274 | 274 | */ |
275 | - public function from_field($field, $fallback = null) |
|
275 | + public function from_field( $field, $fallback = null ) |
|
276 | 276 | { |
277 | - if (!$this->is_multi()) { |
|
277 | + if ( ! $this->is_multi() ) { |
|
278 | 278 | return $this; |
279 | 279 | } |
280 | 280 | |
281 | - return Utils::get($this, $field->form_id, $fallback); |
|
281 | + return Utils::get( $this, $field->form_id, $fallback ); |
|
282 | 282 | } |
283 | 283 | } |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * Contains all entry data and some processing and logic rules. |
14 | 14 | */ |
15 | -abstract class Entry |
|
16 | -{ |
|
15 | +abstract class Entry { |
|
17 | 16 | /** |
18 | 17 | * @var string The identifier of the backend used for this entry. |
19 | 18 | * |
@@ -44,8 +43,7 @@ discard block |
||
44 | 43 | * |
45 | 44 | * @return void |
46 | 45 | */ |
47 | - public static function add_rewrite_endpoint() |
|
48 | - { |
|
46 | + public static function add_rewrite_endpoint() { |
|
49 | 47 | global $wp_rewrite; |
50 | 48 | |
51 | 49 | $endpoint = self::get_endpoint_name(); |
@@ -67,8 +65,7 @@ discard block |
||
67 | 65 | * |
68 | 66 | * @return string The name. Default: "entry" |
69 | 67 | */ |
70 | - public static function get_endpoint_name() |
|
71 | - { |
|
68 | + public static function get_endpoint_name() { |
|
72 | 69 | /** |
73 | 70 | * @filter `gravityview_directory_endpoint` Change the slug used for single entries |
74 | 71 | * |
@@ -90,8 +87,7 @@ discard block |
||
90 | 87 | * |
91 | 88 | * @return \GV\Entry|null An instance of this entry or null if not found. |
92 | 89 | */ |
93 | - public static function by_id($entry_id) |
|
94 | - { |
|
90 | + public static function by_id($entry_id) { |
|
95 | 91 | return null; |
96 | 92 | } |
97 | 93 | |
@@ -100,8 +96,7 @@ discard block |
||
100 | 96 | * |
101 | 97 | * @return array The backing entry object. |
102 | 98 | */ |
103 | - public function as_entry() |
|
104 | - { |
|
99 | + public function as_entry() { |
|
105 | 100 | return $this->entry; |
106 | 101 | } |
107 | 102 | |
@@ -118,8 +113,7 @@ discard block |
||
118 | 113 | * |
119 | 114 | * @return string The permalink to this entry. |
120 | 115 | */ |
121 | - public function get_permalink(\GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
122 | - { |
|
116 | + public function get_permalink(\GV\View $view = null, \GV\Request $request = null, $track_directory = true) { |
|
123 | 117 | if (is_null($request)) { |
124 | 118 | $request = &gravityview()->request; |
125 | 119 | } |
@@ -226,8 +220,7 @@ discard block |
||
226 | 220 | * |
227 | 221 | * @return string Unique slug ID, passed through `sanitize_title()`, with `gravityview/entry/slug` filter applied |
228 | 222 | */ |
229 | - public function get_slug($apply_filter = false, \GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
230 | - { |
|
223 | + public function get_slug($apply_filter = false, \GV\View $view = null, \GV\Request $request = null, $track_directory = true) { |
|
231 | 224 | $entry_slug = \GravityView_API::get_entry_slug($this->ID, $this->as_entry()); |
232 | 225 | |
233 | 226 | if (!$apply_filter) { |
@@ -257,8 +250,7 @@ discard block |
||
257 | 250 | * |
258 | 251 | * @return bool |
259 | 252 | */ |
260 | - public function is_multi() |
|
261 | - { |
|
253 | + public function is_multi() { |
|
262 | 254 | return $this instanceof Multi_Entry; |
263 | 255 | } |
264 | 256 | |
@@ -272,8 +264,7 @@ discard block |
||
272 | 264 | * |
273 | 265 | * @return \GV\Entry|null A \GV\Entry or null if not found. |
274 | 266 | */ |
275 | - public function from_field($field, $fallback = null) |
|
276 | - { |
|
267 | + public function from_field($field, $fallback = null) { |
|
277 | 268 | if (!$this->is_multi()) { |
278 | 269 | return $this; |
279 | 270 | } |
@@ -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,179 +12,179 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Field_Collection extends Collection |
14 | 14 | { |
15 | - /** |
|
16 | - * Returns all the objects in this collection as an an array. Here for docBlock purposes only. |
|
17 | - * |
|
18 | - * @since 2.0.13.1 |
|
19 | - * |
|
20 | - * @return \GV\Field[] |
|
21 | - */ |
|
22 | - public function all() |
|
23 | - { |
|
24 | - return parent::all(); |
|
25 | - } |
|
26 | - |
|
27 | - /** |
|
28 | - * Add a \GV\Field to this collection. |
|
29 | - * |
|
30 | - * @param \GV\Field $field The field to add to the internal array. |
|
31 | - * |
|
32 | - * @api |
|
33 | - * |
|
34 | - * @since 2.0 |
|
35 | - * |
|
36 | - * @return void |
|
37 | - */ |
|
38 | - public function add($field) |
|
39 | - { |
|
40 | - if (!$field instanceof Field) { |
|
41 | - gravityview()->log->error('Field_Collections can only contain objects of type \GV\Field.'); |
|
42 | - |
|
43 | - return; |
|
44 | - } |
|
45 | - parent::add($field); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Get a \GV\Field from this list by UID. |
|
50 | - * |
|
51 | - * @param int $field_uid The UID of the field in the field to get. |
|
52 | - * |
|
53 | - * @api |
|
54 | - * |
|
55 | - * @since 2.0 |
|
56 | - * |
|
57 | - * @return \GV\Field|null The \GV\Field with the $field_uid as the UID, or null if not found. |
|
58 | - */ |
|
59 | - public function get($field_uid) |
|
60 | - { |
|
61 | - foreach ($this->all() as $field) { |
|
62 | - if ($field->UID == $field_uid) { |
|
63 | - return $field; |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - return null; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Get a copy of this \GV\Field_Collection filtered by position. |
|
72 | - * |
|
73 | - * @param string $position The position to get the fields for. |
|
74 | - * Can be a wildcard * |
|
75 | - * |
|
76 | - * @api |
|
77 | - * |
|
78 | - * @since |
|
79 | - * |
|
80 | - * @return \GV\Field_Collection A filtered collection of \GV\Fields, filtered by position. |
|
81 | - */ |
|
82 | - public function by_position($position) |
|
83 | - { |
|
84 | - $fields = new self(); |
|
85 | - |
|
86 | - $search = implode('.*', array_map('preg_quote', explode('*', $position))); |
|
87 | - |
|
88 | - foreach ($this->all() as $field) { |
|
89 | - if (preg_match("#^{$search}$#", $field->position)) { |
|
90 | - $fields->add($field); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - return $fields; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Get a copy of this \GV\Field_Collection filtered by visibility to current user context. |
|
99 | - * |
|
100 | - * @api |
|
101 | - * |
|
102 | - * @since |
|
103 | - * |
|
104 | - * @param $view \GV\View The view! |
|
105 | - * |
|
106 | - * @return \GV\Field_Collection A filtered collection of \GV\Fields, filtered by visibility. |
|
107 | - */ |
|
108 | - public function by_visible($view = null) |
|
109 | - { |
|
110 | - $fields = new self(); |
|
111 | - |
|
112 | - /** @var \GV\Field $field */ |
|
113 | - foreach ($this->all() as $field) { |
|
114 | - if ($field->is_visible($view)) { |
|
115 | - $fields->add($field); |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - return $fields; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Parse a configuration array into a Field_Collection. |
|
124 | - * |
|
125 | - * @param array $configuration The configuration, structured like so: |
|
126 | - * |
|
127 | - * array( |
|
128 | - * |
|
129 | - * [other zones] |
|
130 | - * |
|
131 | - * 'directory_list-title' => array( |
|
132 | - * |
|
133 | - * [other fields] |
|
134 | - * |
|
135 | - * '5372653f25d44' => array( |
|
136 | - * |
|
137 | - * @see \GV\Field::as_configuration() for structure |
|
138 | - * ) |
|
139 | - * |
|
140 | - * [other fields] |
|
141 | - * ) |
|
142 | - * |
|
143 | - * [other zones] |
|
144 | - * ) |
|
145 | - * |
|
146 | - * @return \GV\Field_Collection A collection of fields. |
|
147 | - */ |
|
148 | - public static function from_configuration($configuration) |
|
149 | - { |
|
150 | - $fields = new self(); |
|
151 | - foreach ($configuration as $position => $_fields) { |
|
152 | - if (empty($_fields) || !is_array($_fields)) { |
|
153 | - continue; |
|
154 | - } |
|
155 | - |
|
156 | - foreach ($_fields as $uid => $_configuration) { |
|
157 | - $field = Field::from_configuration($_configuration); |
|
158 | - $field->UID = $uid; |
|
159 | - $field->position = $position; |
|
160 | - |
|
161 | - $fields->add($field); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - return $fields; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Return a configuration array for this field collection. |
|
170 | - * |
|
171 | - * @return array See \GV\Field_Collection::from_configuration() for structure. |
|
172 | - */ |
|
173 | - public function as_configuration() |
|
174 | - { |
|
175 | - $configuration = []; |
|
176 | - |
|
177 | - /** |
|
178 | - * @var \GV\Field $field |
|
179 | - */ |
|
180 | - foreach ($this->all() as $field) { |
|
181 | - if (empty($configuration[$field->position])) { |
|
182 | - $configuration[$field->position] = []; |
|
183 | - } |
|
184 | - |
|
185 | - $configuration[$field->position][$field->UID] = $field->as_configuration(); |
|
186 | - } |
|
187 | - |
|
188 | - return $configuration; |
|
189 | - } |
|
15 | + /** |
|
16 | + * Returns all the objects in this collection as an an array. Here for docBlock purposes only. |
|
17 | + * |
|
18 | + * @since 2.0.13.1 |
|
19 | + * |
|
20 | + * @return \GV\Field[] |
|
21 | + */ |
|
22 | + public function all() |
|
23 | + { |
|
24 | + return parent::all(); |
|
25 | + } |
|
26 | + |
|
27 | + /** |
|
28 | + * Add a \GV\Field to this collection. |
|
29 | + * |
|
30 | + * @param \GV\Field $field The field to add to the internal array. |
|
31 | + * |
|
32 | + * @api |
|
33 | + * |
|
34 | + * @since 2.0 |
|
35 | + * |
|
36 | + * @return void |
|
37 | + */ |
|
38 | + public function add($field) |
|
39 | + { |
|
40 | + if (!$field instanceof Field) { |
|
41 | + gravityview()->log->error('Field_Collections can only contain objects of type \GV\Field.'); |
|
42 | + |
|
43 | + return; |
|
44 | + } |
|
45 | + parent::add($field); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Get a \GV\Field from this list by UID. |
|
50 | + * |
|
51 | + * @param int $field_uid The UID of the field in the field to get. |
|
52 | + * |
|
53 | + * @api |
|
54 | + * |
|
55 | + * @since 2.0 |
|
56 | + * |
|
57 | + * @return \GV\Field|null The \GV\Field with the $field_uid as the UID, or null if not found. |
|
58 | + */ |
|
59 | + public function get($field_uid) |
|
60 | + { |
|
61 | + foreach ($this->all() as $field) { |
|
62 | + if ($field->UID == $field_uid) { |
|
63 | + return $field; |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + return null; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Get a copy of this \GV\Field_Collection filtered by position. |
|
72 | + * |
|
73 | + * @param string $position The position to get the fields for. |
|
74 | + * Can be a wildcard * |
|
75 | + * |
|
76 | + * @api |
|
77 | + * |
|
78 | + * @since |
|
79 | + * |
|
80 | + * @return \GV\Field_Collection A filtered collection of \GV\Fields, filtered by position. |
|
81 | + */ |
|
82 | + public function by_position($position) |
|
83 | + { |
|
84 | + $fields = new self(); |
|
85 | + |
|
86 | + $search = implode('.*', array_map('preg_quote', explode('*', $position))); |
|
87 | + |
|
88 | + foreach ($this->all() as $field) { |
|
89 | + if (preg_match("#^{$search}$#", $field->position)) { |
|
90 | + $fields->add($field); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + return $fields; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Get a copy of this \GV\Field_Collection filtered by visibility to current user context. |
|
99 | + * |
|
100 | + * @api |
|
101 | + * |
|
102 | + * @since |
|
103 | + * |
|
104 | + * @param $view \GV\View The view! |
|
105 | + * |
|
106 | + * @return \GV\Field_Collection A filtered collection of \GV\Fields, filtered by visibility. |
|
107 | + */ |
|
108 | + public function by_visible($view = null) |
|
109 | + { |
|
110 | + $fields = new self(); |
|
111 | + |
|
112 | + /** @var \GV\Field $field */ |
|
113 | + foreach ($this->all() as $field) { |
|
114 | + if ($field->is_visible($view)) { |
|
115 | + $fields->add($field); |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + return $fields; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Parse a configuration array into a Field_Collection. |
|
124 | + * |
|
125 | + * @param array $configuration The configuration, structured like so: |
|
126 | + * |
|
127 | + * array( |
|
128 | + * |
|
129 | + * [other zones] |
|
130 | + * |
|
131 | + * 'directory_list-title' => array( |
|
132 | + * |
|
133 | + * [other fields] |
|
134 | + * |
|
135 | + * '5372653f25d44' => array( |
|
136 | + * |
|
137 | + * @see \GV\Field::as_configuration() for structure |
|
138 | + * ) |
|
139 | + * |
|
140 | + * [other fields] |
|
141 | + * ) |
|
142 | + * |
|
143 | + * [other zones] |
|
144 | + * ) |
|
145 | + * |
|
146 | + * @return \GV\Field_Collection A collection of fields. |
|
147 | + */ |
|
148 | + public static function from_configuration($configuration) |
|
149 | + { |
|
150 | + $fields = new self(); |
|
151 | + foreach ($configuration as $position => $_fields) { |
|
152 | + if (empty($_fields) || !is_array($_fields)) { |
|
153 | + continue; |
|
154 | + } |
|
155 | + |
|
156 | + foreach ($_fields as $uid => $_configuration) { |
|
157 | + $field = Field::from_configuration($_configuration); |
|
158 | + $field->UID = $uid; |
|
159 | + $field->position = $position; |
|
160 | + |
|
161 | + $fields->add($field); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + return $fields; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Return a configuration array for this field collection. |
|
170 | + * |
|
171 | + * @return array See \GV\Field_Collection::from_configuration() for structure. |
|
172 | + */ |
|
173 | + public function as_configuration() |
|
174 | + { |
|
175 | + $configuration = []; |
|
176 | + |
|
177 | + /** |
|
178 | + * @var \GV\Field $field |
|
179 | + */ |
|
180 | + foreach ($this->all() as $field) { |
|
181 | + if (empty($configuration[$field->position])) { |
|
182 | + $configuration[$field->position] = []; |
|
183 | + } |
|
184 | + |
|
185 | + $configuration[$field->position][$field->UID] = $field->as_configuration(); |
|
186 | + } |
|
187 | + |
|
188 | + return $configuration; |
|
189 | + } |
|
190 | 190 | } |
@@ -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 | |
@@ -35,14 +35,14 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @return void |
37 | 37 | */ |
38 | - public function add($field) |
|
38 | + public function add( $field ) |
|
39 | 39 | { |
40 | - if (!$field instanceof Field) { |
|
41 | - gravityview()->log->error('Field_Collections can only contain objects of type \GV\Field.'); |
|
40 | + if ( ! $field instanceof Field ) { |
|
41 | + gravityview()->log->error( 'Field_Collections can only contain objects of type \GV\Field.' ); |
|
42 | 42 | |
43 | 43 | return; |
44 | 44 | } |
45 | - parent::add($field); |
|
45 | + parent::add( $field ); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @return \GV\Field|null The \GV\Field with the $field_uid as the UID, or null if not found. |
58 | 58 | */ |
59 | - public function get($field_uid) |
|
59 | + public function get( $field_uid ) |
|
60 | 60 | { |
61 | - foreach ($this->all() as $field) { |
|
62 | - if ($field->UID == $field_uid) { |
|
61 | + foreach ( $this->all() as $field ) { |
|
62 | + if ( $field->UID == $field_uid ) { |
|
63 | 63 | return $field; |
64 | 64 | } |
65 | 65 | } |
@@ -79,15 +79,15 @@ discard block |
||
79 | 79 | * |
80 | 80 | * @return \GV\Field_Collection A filtered collection of \GV\Fields, filtered by position. |
81 | 81 | */ |
82 | - public function by_position($position) |
|
82 | + public function by_position( $position ) |
|
83 | 83 | { |
84 | 84 | $fields = new self(); |
85 | 85 | |
86 | - $search = implode('.*', array_map('preg_quote', explode('*', $position))); |
|
86 | + $search = implode( '.*', array_map( 'preg_quote', explode( '*', $position ) ) ); |
|
87 | 87 | |
88 | - foreach ($this->all() as $field) { |
|
89 | - if (preg_match("#^{$search}$#", $field->position)) { |
|
90 | - $fields->add($field); |
|
88 | + foreach ( $this->all() as $field ) { |
|
89 | + if ( preg_match( "#^{$search}$#", $field->position ) ) { |
|
90 | + $fields->add( $field ); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | * |
106 | 106 | * @return \GV\Field_Collection A filtered collection of \GV\Fields, filtered by visibility. |
107 | 107 | */ |
108 | - public function by_visible($view = null) |
|
108 | + public function by_visible( $view = null ) |
|
109 | 109 | { |
110 | 110 | $fields = new self(); |
111 | 111 | |
112 | 112 | /** @var \GV\Field $field */ |
113 | - foreach ($this->all() as $field) { |
|
114 | - if ($field->is_visible($view)) { |
|
115 | - $fields->add($field); |
|
113 | + foreach ( $this->all() as $field ) { |
|
114 | + if ( $field->is_visible( $view ) ) { |
|
115 | + $fields->add( $field ); |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | |
@@ -145,20 +145,20 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return \GV\Field_Collection A collection of fields. |
147 | 147 | */ |
148 | - public static function from_configuration($configuration) |
|
148 | + public static function from_configuration( $configuration ) |
|
149 | 149 | { |
150 | 150 | $fields = new self(); |
151 | - foreach ($configuration as $position => $_fields) { |
|
152 | - if (empty($_fields) || !is_array($_fields)) { |
|
151 | + foreach ( $configuration as $position => $_fields ) { |
|
152 | + if ( empty( $_fields ) || ! is_array( $_fields ) ) { |
|
153 | 153 | continue; |
154 | 154 | } |
155 | 155 | |
156 | - foreach ($_fields as $uid => $_configuration) { |
|
157 | - $field = Field::from_configuration($_configuration); |
|
156 | + foreach ( $_fields as $uid => $_configuration ) { |
|
157 | + $field = Field::from_configuration( $_configuration ); |
|
158 | 158 | $field->UID = $uid; |
159 | 159 | $field->position = $position; |
160 | 160 | |
161 | - $fields->add($field); |
|
161 | + $fields->add( $field ); |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
@@ -172,17 +172,17 @@ discard block |
||
172 | 172 | */ |
173 | 173 | public function as_configuration() |
174 | 174 | { |
175 | - $configuration = []; |
|
175 | + $configuration = [ ]; |
|
176 | 176 | |
177 | 177 | /** |
178 | 178 | * @var \GV\Field $field |
179 | 179 | */ |
180 | - foreach ($this->all() as $field) { |
|
181 | - if (empty($configuration[$field->position])) { |
|
182 | - $configuration[$field->position] = []; |
|
180 | + foreach ( $this->all() as $field ) { |
|
181 | + if ( empty( $configuration[ $field->position ] ) ) { |
|
182 | + $configuration[ $field->position ] = [ ]; |
|
183 | 183 | } |
184 | 184 | |
185 | - $configuration[$field->position][$field->UID] = $field->as_configuration(); |
|
185 | + $configuration[ $field->position ][ $field->UID ] = $field->as_configuration(); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | return $configuration; |
@@ -10,8 +10,7 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * A collection of \GV\Field objects. |
12 | 12 | */ |
13 | -class Field_Collection extends Collection |
|
14 | -{ |
|
13 | +class Field_Collection extends Collection { |
|
15 | 14 | /** |
16 | 15 | * Returns all the objects in this collection as an an array. Here for docBlock purposes only. |
17 | 16 | * |
@@ -19,8 +18,7 @@ discard block |
||
19 | 18 | * |
20 | 19 | * @return \GV\Field[] |
21 | 20 | */ |
22 | - public function all() |
|
23 | - { |
|
21 | + public function all() { |
|
24 | 22 | return parent::all(); |
25 | 23 | } |
26 | 24 | |
@@ -35,8 +33,7 @@ discard block |
||
35 | 33 | * |
36 | 34 | * @return void |
37 | 35 | */ |
38 | - public function add($field) |
|
39 | - { |
|
36 | + public function add($field) { |
|
40 | 37 | if (!$field instanceof Field) { |
41 | 38 | gravityview()->log->error('Field_Collections can only contain objects of type \GV\Field.'); |
42 | 39 | |
@@ -56,8 +53,7 @@ discard block |
||
56 | 53 | * |
57 | 54 | * @return \GV\Field|null The \GV\Field with the $field_uid as the UID, or null if not found. |
58 | 55 | */ |
59 | - public function get($field_uid) |
|
60 | - { |
|
56 | + public function get($field_uid) { |
|
61 | 57 | foreach ($this->all() as $field) { |
62 | 58 | if ($field->UID == $field_uid) { |
63 | 59 | return $field; |
@@ -79,8 +75,7 @@ discard block |
||
79 | 75 | * |
80 | 76 | * @return \GV\Field_Collection A filtered collection of \GV\Fields, filtered by position. |
81 | 77 | */ |
82 | - public function by_position($position) |
|
83 | - { |
|
78 | + public function by_position($position) { |
|
84 | 79 | $fields = new self(); |
85 | 80 | |
86 | 81 | $search = implode('.*', array_map('preg_quote', explode('*', $position))); |
@@ -105,8 +100,7 @@ discard block |
||
105 | 100 | * |
106 | 101 | * @return \GV\Field_Collection A filtered collection of \GV\Fields, filtered by visibility. |
107 | 102 | */ |
108 | - public function by_visible($view = null) |
|
109 | - { |
|
103 | + public function by_visible($view = null) { |
|
110 | 104 | $fields = new self(); |
111 | 105 | |
112 | 106 | /** @var \GV\Field $field */ |
@@ -145,8 +139,7 @@ discard block |
||
145 | 139 | * |
146 | 140 | * @return \GV\Field_Collection A collection of fields. |
147 | 141 | */ |
148 | - public static function from_configuration($configuration) |
|
149 | - { |
|
142 | + public static function from_configuration($configuration) { |
|
150 | 143 | $fields = new self(); |
151 | 144 | foreach ($configuration as $position => $_fields) { |
152 | 145 | if (empty($_fields) || !is_array($_fields)) { |
@@ -170,8 +163,7 @@ discard block |
||
170 | 163 | * |
171 | 164 | * @return array See \GV\Field_Collection::from_configuration() for structure. |
172 | 165 | */ |
173 | - public function as_configuration() |
|
174 | - { |
|
166 | + public function as_configuration() { |
|
175 | 167 | $configuration = []; |
176 | 168 | |
177 | 169 | /** |
@@ -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 | /** |
@@ -15,165 +15,165 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class Multi_Entry extends Entry implements \ArrayAccess |
17 | 17 | { |
18 | - /** |
|
19 | - * The entries in this form. |
|
20 | - */ |
|
21 | - public $entries = []; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var string The identifier of the backend used for this entry. |
|
25 | - * |
|
26 | - * @api |
|
27 | - * |
|
28 | - * @since 2.0 |
|
29 | - */ |
|
30 | - public static $backend = 'multi'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Initialization. |
|
34 | - */ |
|
35 | - private function __construct() |
|
36 | - { |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Construct a multientry from an array of entries. |
|
41 | - * |
|
42 | - * @param \GV\Entry[] $entries The entries. |
|
43 | - * |
|
44 | - * @return \GV\Multi_Entry A multientry object. |
|
45 | - */ |
|
46 | - public static function from_entries($entries) |
|
47 | - { |
|
48 | - $_entry = new self(); |
|
49 | - foreach ($entries as &$entry) { |
|
50 | - if (!$entry instanceof Entry) { |
|
51 | - continue; |
|
52 | - } |
|
53 | - $_entry->entries[$entry['form_id']] = &$entry; |
|
54 | - } |
|
55 | - |
|
56 | - return $_entry; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Fake legacy template support. |
|
61 | - * |
|
62 | - * Take the first entry and set it as the current entry. |
|
63 | - * But support nesting. |
|
64 | - * |
|
65 | - * @return array See \GV\Entry::as_entry() |
|
66 | - */ |
|
67 | - public function as_entry() |
|
68 | - { |
|
69 | - $_entry = []; |
|
70 | - |
|
71 | - if ($entry = reset($this->entries)) { |
|
72 | - $_entry = $entry->as_entry(); |
|
73 | - |
|
74 | - foreach ($this->entries as $entry) { |
|
75 | - $entry = $entry->as_entry(); |
|
76 | - $_entry['_multi'][$entry['form_id']] = $entry; |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - return $_entry; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Return the link to this multi entry in the supplied context. |
|
85 | - * |
|
86 | - * @api |
|
87 | - * |
|
88 | - * @since 2.2 |
|
89 | - * |
|
90 | - * @param \GV\View|null $view The View context. |
|
91 | - * @param \GV\Request $request The Request (current if null). |
|
92 | - * @param bool $track_directory Keep the housing directory arguments intact (used for breadcrumbs, for example). Default: true. |
|
93 | - * |
|
94 | - * @return string The permalink to this entry. |
|
95 | - */ |
|
96 | - public function get_permalink(\GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
97 | - { |
|
98 | - $slugs = []; |
|
99 | - add_filter('gravityview/entry/slug', $callback = function ($slug) use (&$slugs) { |
|
100 | - $slugs[] = $slug; |
|
101 | - |
|
102 | - return implode(',', $slugs); |
|
103 | - }, 10, 1); |
|
104 | - |
|
105 | - foreach ($this->entries as $entry) { |
|
106 | - $permalink = call_user_func_array([$entry, __FUNCTION__], func_get_args()); |
|
107 | - } |
|
108 | - |
|
109 | - remove_filter('gravityview/entry/slug', $callback); |
|
110 | - |
|
111 | - return $permalink; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * ArrayAccess compatibility layer with a Gravity Forms entry array. |
|
116 | - * |
|
117 | - * @internal |
|
118 | - * |
|
119 | - * @deprecated |
|
120 | - * @since 2.0 |
|
121 | - * |
|
122 | - * @return bool Whether the offset exists or not. |
|
123 | - */ |
|
124 | - public function offsetExists($offset) |
|
125 | - { |
|
126 | - return isset($this->entries[$offset]); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * ArrayAccess compatibility layer with a Gravity Forms entry array. |
|
131 | - * |
|
132 | - * Maps the old keys to the new data; |
|
133 | - * |
|
134 | - * @internal |
|
135 | - * |
|
136 | - * @deprecated |
|
137 | - * @since 2.0 |
|
138 | - * |
|
139 | - * @return mixed The value of the requested entry data. |
|
140 | - */ |
|
141 | - public function offsetGet($offset) |
|
142 | - { |
|
143 | - if (!$this->offsetExists($offset)) { |
|
144 | - return null; |
|
145 | - } |
|
146 | - |
|
147 | - return $this->entries[$offset]; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * ArrayAccess compatibility layer with a Gravity Forms entry array. |
|
152 | - * |
|
153 | - * @internal |
|
154 | - * |
|
155 | - * @deprecated |
|
156 | - * @since 2.0 |
|
157 | - * |
|
158 | - * @return void |
|
159 | - */ |
|
160 | - public function offsetSet($offset, $value) |
|
161 | - { |
|
162 | - gravityview()->log->error('The underlying multi entry is immutable. This is a \GV\Entry object and should not be accessed as an array.'); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * ArrayAccess compatibility layer with a Gravity Forms entry array. |
|
167 | - * |
|
168 | - * @internal |
|
169 | - * |
|
170 | - * @deprecated |
|
171 | - * @since 2.0 |
|
172 | - * |
|
173 | - * @return void |
|
174 | - */ |
|
175 | - public function offsetUnset($offset) |
|
176 | - { |
|
177 | - gravityview()->log->error('The underlying multi entry is immutable. This is a \GV\Entry object and should not be accessed as an array.'); |
|
178 | - } |
|
18 | + /** |
|
19 | + * The entries in this form. |
|
20 | + */ |
|
21 | + public $entries = []; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var string The identifier of the backend used for this entry. |
|
25 | + * |
|
26 | + * @api |
|
27 | + * |
|
28 | + * @since 2.0 |
|
29 | + */ |
|
30 | + public static $backend = 'multi'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Initialization. |
|
34 | + */ |
|
35 | + private function __construct() |
|
36 | + { |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Construct a multientry from an array of entries. |
|
41 | + * |
|
42 | + * @param \GV\Entry[] $entries The entries. |
|
43 | + * |
|
44 | + * @return \GV\Multi_Entry A multientry object. |
|
45 | + */ |
|
46 | + public static function from_entries($entries) |
|
47 | + { |
|
48 | + $_entry = new self(); |
|
49 | + foreach ($entries as &$entry) { |
|
50 | + if (!$entry instanceof Entry) { |
|
51 | + continue; |
|
52 | + } |
|
53 | + $_entry->entries[$entry['form_id']] = &$entry; |
|
54 | + } |
|
55 | + |
|
56 | + return $_entry; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Fake legacy template support. |
|
61 | + * |
|
62 | + * Take the first entry and set it as the current entry. |
|
63 | + * But support nesting. |
|
64 | + * |
|
65 | + * @return array See \GV\Entry::as_entry() |
|
66 | + */ |
|
67 | + public function as_entry() |
|
68 | + { |
|
69 | + $_entry = []; |
|
70 | + |
|
71 | + if ($entry = reset($this->entries)) { |
|
72 | + $_entry = $entry->as_entry(); |
|
73 | + |
|
74 | + foreach ($this->entries as $entry) { |
|
75 | + $entry = $entry->as_entry(); |
|
76 | + $_entry['_multi'][$entry['form_id']] = $entry; |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + return $_entry; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Return the link to this multi entry in the supplied context. |
|
85 | + * |
|
86 | + * @api |
|
87 | + * |
|
88 | + * @since 2.2 |
|
89 | + * |
|
90 | + * @param \GV\View|null $view The View context. |
|
91 | + * @param \GV\Request $request The Request (current if null). |
|
92 | + * @param bool $track_directory Keep the housing directory arguments intact (used for breadcrumbs, for example). Default: true. |
|
93 | + * |
|
94 | + * @return string The permalink to this entry. |
|
95 | + */ |
|
96 | + public function get_permalink(\GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
97 | + { |
|
98 | + $slugs = []; |
|
99 | + add_filter('gravityview/entry/slug', $callback = function ($slug) use (&$slugs) { |
|
100 | + $slugs[] = $slug; |
|
101 | + |
|
102 | + return implode(',', $slugs); |
|
103 | + }, 10, 1); |
|
104 | + |
|
105 | + foreach ($this->entries as $entry) { |
|
106 | + $permalink = call_user_func_array([$entry, __FUNCTION__], func_get_args()); |
|
107 | + } |
|
108 | + |
|
109 | + remove_filter('gravityview/entry/slug', $callback); |
|
110 | + |
|
111 | + return $permalink; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * ArrayAccess compatibility layer with a Gravity Forms entry array. |
|
116 | + * |
|
117 | + * @internal |
|
118 | + * |
|
119 | + * @deprecated |
|
120 | + * @since 2.0 |
|
121 | + * |
|
122 | + * @return bool Whether the offset exists or not. |
|
123 | + */ |
|
124 | + public function offsetExists($offset) |
|
125 | + { |
|
126 | + return isset($this->entries[$offset]); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * ArrayAccess compatibility layer with a Gravity Forms entry array. |
|
131 | + * |
|
132 | + * Maps the old keys to the new data; |
|
133 | + * |
|
134 | + * @internal |
|
135 | + * |
|
136 | + * @deprecated |
|
137 | + * @since 2.0 |
|
138 | + * |
|
139 | + * @return mixed The value of the requested entry data. |
|
140 | + */ |
|
141 | + public function offsetGet($offset) |
|
142 | + { |
|
143 | + if (!$this->offsetExists($offset)) { |
|
144 | + return null; |
|
145 | + } |
|
146 | + |
|
147 | + return $this->entries[$offset]; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * ArrayAccess compatibility layer with a Gravity Forms entry array. |
|
152 | + * |
|
153 | + * @internal |
|
154 | + * |
|
155 | + * @deprecated |
|
156 | + * @since 2.0 |
|
157 | + * |
|
158 | + * @return void |
|
159 | + */ |
|
160 | + public function offsetSet($offset, $value) |
|
161 | + { |
|
162 | + gravityview()->log->error('The underlying multi entry is immutable. This is a \GV\Entry object and should not be accessed as an array.'); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * ArrayAccess compatibility layer with a Gravity Forms entry array. |
|
167 | + * |
|
168 | + * @internal |
|
169 | + * |
|
170 | + * @deprecated |
|
171 | + * @since 2.0 |
|
172 | + * |
|
173 | + * @return void |
|
174 | + */ |
|
175 | + public function offsetUnset($offset) |
|
176 | + { |
|
177 | + gravityview()->log->error('The underlying multi entry is immutable. This is a \GV\Entry object and should not be accessed as an array.'); |
|
178 | + } |
|
179 | 179 | } |
@@ -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 | |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * The entries in this form. |
20 | 20 | */ |
21 | - public $entries = []; |
|
21 | + public $entries = [ ]; |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @var string The identifier of the backend used for this entry. |
@@ -43,14 +43,14 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return \GV\Multi_Entry A multientry object. |
45 | 45 | */ |
46 | - public static function from_entries($entries) |
|
46 | + public static function from_entries( $entries ) |
|
47 | 47 | { |
48 | 48 | $_entry = new self(); |
49 | - foreach ($entries as &$entry) { |
|
50 | - if (!$entry instanceof Entry) { |
|
49 | + foreach ( $entries as &$entry ) { |
|
50 | + if ( ! $entry instanceof Entry ) { |
|
51 | 51 | continue; |
52 | 52 | } |
53 | - $_entry->entries[$entry['form_id']] = &$entry; |
|
53 | + $_entry->entries[ $entry[ 'form_id' ] ] = &$entry; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $_entry; |
@@ -66,14 +66,14 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function as_entry() |
68 | 68 | { |
69 | - $_entry = []; |
|
69 | + $_entry = [ ]; |
|
70 | 70 | |
71 | - if ($entry = reset($this->entries)) { |
|
71 | + if ( $entry = reset( $this->entries ) ) { |
|
72 | 72 | $_entry = $entry->as_entry(); |
73 | 73 | |
74 | - foreach ($this->entries as $entry) { |
|
74 | + foreach ( $this->entries as $entry ) { |
|
75 | 75 | $entry = $entry->as_entry(); |
76 | - $_entry['_multi'][$entry['form_id']] = $entry; |
|
76 | + $_entry[ '_multi' ][ $entry[ 'form_id' ] ] = $entry; |
|
77 | 77 | } |
78 | 78 | } |
79 | 79 | |
@@ -93,20 +93,20 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return string The permalink to this entry. |
95 | 95 | */ |
96 | - public function get_permalink(\GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
96 | + public function get_permalink( \GV\View $view = null, \GV\Request $request = null, $track_directory = true ) |
|
97 | 97 | { |
98 | - $slugs = []; |
|
99 | - add_filter('gravityview/entry/slug', $callback = function ($slug) use (&$slugs) { |
|
100 | - $slugs[] = $slug; |
|
98 | + $slugs = [ ]; |
|
99 | + add_filter( 'gravityview/entry/slug', $callback = function( $slug ) use ( &$slugs ) { |
|
100 | + $slugs[ ] = $slug; |
|
101 | 101 | |
102 | - return implode(',', $slugs); |
|
103 | - }, 10, 1); |
|
102 | + return implode( ',', $slugs ); |
|
103 | + }, 10, 1 ); |
|
104 | 104 | |
105 | - foreach ($this->entries as $entry) { |
|
106 | - $permalink = call_user_func_array([$entry, __FUNCTION__], func_get_args()); |
|
105 | + foreach ( $this->entries as $entry ) { |
|
106 | + $permalink = call_user_func_array( [ $entry, __FUNCTION__ ], func_get_args() ); |
|
107 | 107 | } |
108 | 108 | |
109 | - remove_filter('gravityview/entry/slug', $callback); |
|
109 | + remove_filter( 'gravityview/entry/slug', $callback ); |
|
110 | 110 | |
111 | 111 | return $permalink; |
112 | 112 | } |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @return bool Whether the offset exists or not. |
123 | 123 | */ |
124 | - public function offsetExists($offset) |
|
124 | + public function offsetExists( $offset ) |
|
125 | 125 | { |
126 | - return isset($this->entries[$offset]); |
|
126 | + return isset( $this->entries[ $offset ] ); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return mixed The value of the requested entry data. |
140 | 140 | */ |
141 | - public function offsetGet($offset) |
|
141 | + public function offsetGet( $offset ) |
|
142 | 142 | { |
143 | - if (!$this->offsetExists($offset)) { |
|
143 | + if ( ! $this->offsetExists( $offset ) ) { |
|
144 | 144 | return null; |
145 | 145 | } |
146 | 146 | |
147 | - return $this->entries[$offset]; |
|
147 | + return $this->entries[ $offset ]; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @return void |
159 | 159 | */ |
160 | - public function offsetSet($offset, $value) |
|
160 | + public function offsetSet( $offset, $value ) |
|
161 | 161 | { |
162 | - gravityview()->log->error('The underlying multi entry is immutable. This is a \GV\Entry object and should not be accessed as an array.'); |
|
162 | + gravityview()->log->error( 'The underlying multi entry is immutable. This is a \GV\Entry object and should not be accessed as an array.' ); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * |
173 | 173 | * @return void |
174 | 174 | */ |
175 | - public function offsetUnset($offset) |
|
175 | + public function offsetUnset( $offset ) |
|
176 | 176 | { |
177 | - gravityview()->log->error('The underlying multi entry is immutable. This is a \GV\Entry object and should not be accessed as an array.'); |
|
177 | + gravityview()->log->error( 'The underlying multi entry is immutable. This is a \GV\Entry object and should not be accessed as an array.' ); |
|
178 | 178 | } |
179 | 179 | } |
@@ -32,8 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * Initialization. |
34 | 34 | */ |
35 | - private function __construct() |
|
36 | - { |
|
35 | + private function __construct() { |
|
37 | 36 | } |
38 | 37 | |
39 | 38 | /** |
@@ -43,8 +42,7 @@ discard block |
||
43 | 42 | * |
44 | 43 | * @return \GV\Multi_Entry A multientry object. |
45 | 44 | */ |
46 | - public static function from_entries($entries) |
|
47 | - { |
|
45 | + public static function from_entries($entries) { |
|
48 | 46 | $_entry = new self(); |
49 | 47 | foreach ($entries as &$entry) { |
50 | 48 | if (!$entry instanceof Entry) { |
@@ -64,8 +62,7 @@ discard block |
||
64 | 62 | * |
65 | 63 | * @return array See \GV\Entry::as_entry() |
66 | 64 | */ |
67 | - public function as_entry() |
|
68 | - { |
|
65 | + public function as_entry() { |
|
69 | 66 | $_entry = []; |
70 | 67 | |
71 | 68 | if ($entry = reset($this->entries)) { |
@@ -93,8 +90,7 @@ discard block |
||
93 | 90 | * |
94 | 91 | * @return string The permalink to this entry. |
95 | 92 | */ |
96 | - public function get_permalink(\GV\View $view = null, \GV\Request $request = null, $track_directory = true) |
|
97 | - { |
|
93 | + public function get_permalink(\GV\View $view = null, \GV\Request $request = null, $track_directory = true) { |
|
98 | 94 | $slugs = []; |
99 | 95 | add_filter('gravityview/entry/slug', $callback = function ($slug) use (&$slugs) { |
100 | 96 | $slugs[] = $slug; |
@@ -121,8 +117,7 @@ discard block |
||
121 | 117 | * |
122 | 118 | * @return bool Whether the offset exists or not. |
123 | 119 | */ |
124 | - public function offsetExists($offset) |
|
125 | - { |
|
120 | + public function offsetExists($offset) { |
|
126 | 121 | return isset($this->entries[$offset]); |
127 | 122 | } |
128 | 123 | |
@@ -138,8 +133,7 @@ discard block |
||
138 | 133 | * |
139 | 134 | * @return mixed The value of the requested entry data. |
140 | 135 | */ |
141 | - public function offsetGet($offset) |
|
142 | - { |
|
136 | + public function offsetGet($offset) { |
|
143 | 137 | if (!$this->offsetExists($offset)) { |
144 | 138 | return null; |
145 | 139 | } |
@@ -157,8 +151,7 @@ discard block |
||
157 | 151 | * |
158 | 152 | * @return void |
159 | 153 | */ |
160 | - public function offsetSet($offset, $value) |
|
161 | - { |
|
154 | + public function offsetSet($offset, $value) { |
|
162 | 155 | gravityview()->log->error('The underlying multi entry is immutable. This is a \GV\Entry object and should not be accessed as an array.'); |
163 | 156 | } |
164 | 157 | |
@@ -172,8 +165,7 @@ discard block |
||
172 | 165 | * |
173 | 166 | * @return void |
174 | 167 | */ |
175 | - public function offsetUnset($offset) |
|
176 | - { |
|
168 | + public function offsetUnset($offset) { |
|
177 | 169 | gravityview()->log->error('The underlying multi entry is immutable. This is a \GV\Entry object and should not be accessed as an array.'); |
178 | 170 | } |
179 | 171 | } |
@@ -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,8 +14,8 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Field_CSV_Template extends Field_Template |
16 | 16 | { |
17 | - /** |
|
18 | - * @var string The template slug to be loaded (like "table", "list", "plain") |
|
19 | - */ |
|
20 | - public static $slug = 'csv'; |
|
17 | + /** |
|
18 | + * @var string The template slug to be loaded (like "table", "list", "plain") |
|
19 | + */ |
|
20 | + public static $slug = 'csv'; |
|
21 | 21 | } |
@@ -3,7 +3,7 @@ |
||
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,7 @@ |
||
12 | 12 | * |
13 | 13 | * Attached to a \GV\Field and used by a \GV\Field_Renderer. |
14 | 14 | */ |
15 | -class Field_CSV_Template extends Field_Template |
|
16 | -{ |
|
15 | +class Field_CSV_Template extends Field_Template { |
|
17 | 16 | /** |
18 | 17 | * @var string The template slug to be loaded (like "table", "list", "plain") |
19 | 18 | */ |
@@ -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 | /** |
@@ -15,57 +15,57 @@ discard block |
||
15 | 15 | */ |
16 | 16 | abstract class Form extends Source |
17 | 17 | { |
18 | - /** |
|
19 | - * @var int The ID for this form. |
|
20 | - * |
|
21 | - * @api |
|
22 | - * |
|
23 | - * @since 2.0 |
|
24 | - */ |
|
25 | - public $ID = null; |
|
18 | + /** |
|
19 | + * @var int The ID for this form. |
|
20 | + * |
|
21 | + * @api |
|
22 | + * |
|
23 | + * @since 2.0 |
|
24 | + */ |
|
25 | + public $ID = null; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var array The backing form. |
|
29 | - */ |
|
30 | - private $form; |
|
27 | + /** |
|
28 | + * @var array The backing form. |
|
29 | + */ |
|
30 | + private $form; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Construct a \GV\Form instance by ID. |
|
34 | - * |
|
35 | - * @param int|string $form_id The internal form ID. |
|
36 | - * |
|
37 | - * @api |
|
38 | - * |
|
39 | - * @since 2.0 |
|
40 | - * |
|
41 | - * @return \GV\Form|null An instance of this form or null if not found. |
|
42 | - */ |
|
43 | - public static function by_id($form_id) |
|
44 | - { |
|
45 | - return null; |
|
46 | - } |
|
32 | + /** |
|
33 | + * Construct a \GV\Form instance by ID. |
|
34 | + * |
|
35 | + * @param int|string $form_id The internal form ID. |
|
36 | + * |
|
37 | + * @api |
|
38 | + * |
|
39 | + * @since 2.0 |
|
40 | + * |
|
41 | + * @return \GV\Form|null An instance of this form or null if not found. |
|
42 | + */ |
|
43 | + public static function by_id($form_id) |
|
44 | + { |
|
45 | + return null; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Get all entries for this form. |
|
50 | - * |
|
51 | - * @api |
|
52 | - * |
|
53 | - * @since 2.0 |
|
54 | - * |
|
55 | - * @return \GV\Entry_Collection The \GV\Entry_Collection |
|
56 | - */ |
|
57 | - abstract public function get_entries(); |
|
48 | + /** |
|
49 | + * Get all entries for this form. |
|
50 | + * |
|
51 | + * @api |
|
52 | + * |
|
53 | + * @since 2.0 |
|
54 | + * |
|
55 | + * @return \GV\Entry_Collection The \GV\Entry_Collection |
|
56 | + */ |
|
57 | + abstract public function get_entries(); |
|
58 | 58 | |
59 | - /** |
|
60 | - * Magic shortcuts. |
|
61 | - * |
|
62 | - * - `entries` -> `$this->get_entries()` |
|
63 | - */ |
|
64 | - public function __get($key) |
|
65 | - { |
|
66 | - switch ($key) { |
|
67 | - case 'entries': |
|
68 | - return $this->get_entries(); |
|
69 | - } |
|
70 | - } |
|
59 | + /** |
|
60 | + * Magic shortcuts. |
|
61 | + * |
|
62 | + * - `entries` -> `$this->get_entries()` |
|
63 | + */ |
|
64 | + public function __get($key) |
|
65 | + { |
|
66 | + switch ($key) { |
|
67 | + case 'entries': |
|
68 | + return $this->get_entries(); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | } |
@@ -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 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @return \GV\Form|null An instance of this form or null if not found. |
42 | 42 | */ |
43 | - public static function by_id($form_id) |
|
43 | + public static function by_id( $form_id ) |
|
44 | 44 | { |
45 | 45 | return null; |
46 | 46 | } |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | * |
62 | 62 | * - `entries` -> `$this->get_entries()` |
63 | 63 | */ |
64 | - public function __get($key) |
|
64 | + public function __get( $key ) |
|
65 | 65 | { |
66 | - switch ($key) { |
|
66 | + switch ( $key ) { |
|
67 | 67 | case 'entries': |
68 | 68 | return $this->get_entries(); |
69 | 69 | } |
@@ -13,8 +13,7 @@ discard block |
||
13 | 13 | * Houses all base Form functionality and provides a uniform |
14 | 14 | * API to various form backends via \GV\Form implementations. |
15 | 15 | */ |
16 | -abstract class Form extends Source |
|
17 | -{ |
|
16 | +abstract class Form extends Source { |
|
18 | 17 | /** |
19 | 18 | * @var int The ID for this form. |
20 | 19 | * |
@@ -40,8 +39,7 @@ discard block |
||
40 | 39 | * |
41 | 40 | * @return \GV\Form|null An instance of this form or null if not found. |
42 | 41 | */ |
43 | - public static function by_id($form_id) |
|
44 | - { |
|
42 | + public static function by_id($form_id) { |
|
45 | 43 | return null; |
46 | 44 | } |
47 | 45 | |
@@ -61,8 +59,7 @@ discard block |
||
61 | 59 | * |
62 | 60 | * - `entries` -> `$this->get_entries()` |
63 | 61 | */ |
64 | - public function __get($key) |
|
65 | - { |
|
62 | + public function __get($key) { |
|
66 | 63 | switch ($key) { |
67 | 64 | case 'entries': |
68 | 65 | return $this->get_entries(); |
@@ -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,88 +14,88 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Join |
16 | 16 | { |
17 | - /** |
|
18 | - * @var GF_Form|Source|Form |
|
19 | - * |
|
20 | - * @since 2.2 Made private property public |
|
21 | - */ |
|
22 | - public $join; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var GF_Form|Source|Form |
|
26 | - * |
|
27 | - * @since 2.2 Made private property public |
|
28 | - */ |
|
29 | - public $join_on; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var Field |
|
33 | - */ |
|
34 | - public $join_column; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Field |
|
38 | - */ |
|
39 | - public $join_on_column; |
|
40 | - |
|
41 | - /** |
|
42 | - * Construct a JOIN container. |
|
43 | - * |
|
44 | - * @param \GV\Source $join The form we're joining to. |
|
45 | - * @param \GV\Field $join_column Its column. |
|
46 | - * @param \GV\Source $join_on The form we're joining on. |
|
47 | - * @param \GV\Field $join_on_column Its column. |
|
48 | - */ |
|
49 | - public function __construct($join, $join_column, $join_on, $join_on_column) |
|
50 | - { |
|
51 | - if ($join instanceof \GV\Source) { |
|
52 | - $this->join = $join; |
|
53 | - } |
|
54 | - |
|
55 | - if ($join_on instanceof \GV\Source) { |
|
56 | - $this->join_on = $join_on; |
|
57 | - } |
|
58 | - |
|
59 | - if ($join_column instanceof \GV\Field) { |
|
60 | - $this->join_column = $join_column; |
|
61 | - } |
|
62 | - |
|
63 | - if ($join_on_column instanceof \GV\Field) { |
|
64 | - $this->join_on_column = $join_on_column; |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Inject this join into the query. |
|
70 | - * |
|
71 | - * @param \GF_Query $query The \GF_Query instance. |
|
72 | - * |
|
73 | - * @return \GF_Query The $query |
|
74 | - */ |
|
75 | - public function as_query_join($query) |
|
76 | - { |
|
77 | - if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
78 | - return null; |
|
79 | - } |
|
80 | - |
|
81 | - if (!$query instanceof \GF_Query) { |
|
82 | - gravityview()->log->error('Query not instance of \GF_Query.'); |
|
83 | - |
|
84 | - return null; |
|
85 | - } |
|
86 | - |
|
87 | - $join_id = intval($this->join->ID); |
|
88 | - $join_on_id = intval($this->join_on->ID); |
|
89 | - |
|
90 | - if (empty($join_id) || empty($join_on_id)) { |
|
91 | - gravityview()->log->error('Query join form not an integer.', ['data' => $this]); |
|
92 | - |
|
93 | - return null; |
|
94 | - } |
|
95 | - |
|
96 | - return $query->join( |
|
97 | - new \GF_Query_Column($this->join_on_column->ID, $join_on_id), |
|
98 | - new \GF_Query_Column($this->join_column->ID, $join_id) |
|
99 | - ); |
|
100 | - } |
|
17 | + /** |
|
18 | + * @var GF_Form|Source|Form |
|
19 | + * |
|
20 | + * @since 2.2 Made private property public |
|
21 | + */ |
|
22 | + public $join; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var GF_Form|Source|Form |
|
26 | + * |
|
27 | + * @since 2.2 Made private property public |
|
28 | + */ |
|
29 | + public $join_on; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var Field |
|
33 | + */ |
|
34 | + public $join_column; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Field |
|
38 | + */ |
|
39 | + public $join_on_column; |
|
40 | + |
|
41 | + /** |
|
42 | + * Construct a JOIN container. |
|
43 | + * |
|
44 | + * @param \GV\Source $join The form we're joining to. |
|
45 | + * @param \GV\Field $join_column Its column. |
|
46 | + * @param \GV\Source $join_on The form we're joining on. |
|
47 | + * @param \GV\Field $join_on_column Its column. |
|
48 | + */ |
|
49 | + public function __construct($join, $join_column, $join_on, $join_on_column) |
|
50 | + { |
|
51 | + if ($join instanceof \GV\Source) { |
|
52 | + $this->join = $join; |
|
53 | + } |
|
54 | + |
|
55 | + if ($join_on instanceof \GV\Source) { |
|
56 | + $this->join_on = $join_on; |
|
57 | + } |
|
58 | + |
|
59 | + if ($join_column instanceof \GV\Field) { |
|
60 | + $this->join_column = $join_column; |
|
61 | + } |
|
62 | + |
|
63 | + if ($join_on_column instanceof \GV\Field) { |
|
64 | + $this->join_on_column = $join_on_column; |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Inject this join into the query. |
|
70 | + * |
|
71 | + * @param \GF_Query $query The \GF_Query instance. |
|
72 | + * |
|
73 | + * @return \GF_Query The $query |
|
74 | + */ |
|
75 | + public function as_query_join($query) |
|
76 | + { |
|
77 | + if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
78 | + return null; |
|
79 | + } |
|
80 | + |
|
81 | + if (!$query instanceof \GF_Query) { |
|
82 | + gravityview()->log->error('Query not instance of \GF_Query.'); |
|
83 | + |
|
84 | + return null; |
|
85 | + } |
|
86 | + |
|
87 | + $join_id = intval($this->join->ID); |
|
88 | + $join_on_id = intval($this->join_on->ID); |
|
89 | + |
|
90 | + if (empty($join_id) || empty($join_on_id)) { |
|
91 | + gravityview()->log->error('Query join form not an integer.', ['data' => $this]); |
|
92 | + |
|
93 | + return null; |
|
94 | + } |
|
95 | + |
|
96 | + return $query->join( |
|
97 | + new \GF_Query_Column($this->join_on_column->ID, $join_on_id), |
|
98 | + new \GF_Query_Column($this->join_column->ID, $join_id) |
|
99 | + ); |
|
100 | + } |
|
101 | 101 | } |
@@ -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 | |
@@ -46,21 +46,21 @@ discard block |
||
46 | 46 | * @param \GV\Source $join_on The form we're joining on. |
47 | 47 | * @param \GV\Field $join_on_column Its column. |
48 | 48 | */ |
49 | - public function __construct($join, $join_column, $join_on, $join_on_column) |
|
49 | + public function __construct( $join, $join_column, $join_on, $join_on_column ) |
|
50 | 50 | { |
51 | - if ($join instanceof \GV\Source) { |
|
51 | + if ( $join instanceof \GV\Source ) { |
|
52 | 52 | $this->join = $join; |
53 | 53 | } |
54 | 54 | |
55 | - if ($join_on instanceof \GV\Source) { |
|
55 | + if ( $join_on instanceof \GV\Source ) { |
|
56 | 56 | $this->join_on = $join_on; |
57 | 57 | } |
58 | 58 | |
59 | - if ($join_column instanceof \GV\Field) { |
|
59 | + if ( $join_column instanceof \GV\Field ) { |
|
60 | 60 | $this->join_column = $join_column; |
61 | 61 | } |
62 | 62 | |
63 | - if ($join_on_column instanceof \GV\Field) { |
|
63 | + if ( $join_on_column instanceof \GV\Field ) { |
|
64 | 64 | $this->join_on_column = $join_on_column; |
65 | 65 | } |
66 | 66 | } |
@@ -72,30 +72,30 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return \GF_Query The $query |
74 | 74 | */ |
75 | - public function as_query_join($query) |
|
75 | + public function as_query_join( $query ) |
|
76 | 76 | { |
77 | - if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
|
77 | + if ( ! gravityview()->plugin->supports( Plugin::FEATURE_JOINS ) ) { |
|
78 | 78 | return null; |
79 | 79 | } |
80 | 80 | |
81 | - if (!$query instanceof \GF_Query) { |
|
82 | - gravityview()->log->error('Query not instance of \GF_Query.'); |
|
81 | + if ( ! $query instanceof \GF_Query ) { |
|
82 | + gravityview()->log->error( 'Query not instance of \GF_Query.' ); |
|
83 | 83 | |
84 | 84 | return null; |
85 | 85 | } |
86 | 86 | |
87 | - $join_id = intval($this->join->ID); |
|
88 | - $join_on_id = intval($this->join_on->ID); |
|
87 | + $join_id = intval( $this->join->ID ); |
|
88 | + $join_on_id = intval( $this->join_on->ID ); |
|
89 | 89 | |
90 | - if (empty($join_id) || empty($join_on_id)) { |
|
91 | - gravityview()->log->error('Query join form not an integer.', ['data' => $this]); |
|
90 | + if ( empty( $join_id ) || empty( $join_on_id ) ) { |
|
91 | + gravityview()->log->error( 'Query join form not an integer.', [ 'data' => $this ] ); |
|
92 | 92 | |
93 | 93 | return null; |
94 | 94 | } |
95 | 95 | |
96 | 96 | return $query->join( |
97 | - new \GF_Query_Column($this->join_on_column->ID, $join_on_id), |
|
98 | - new \GF_Query_Column($this->join_column->ID, $join_id) |
|
97 | + new \GF_Query_Column( $this->join_on_column->ID, $join_on_id ), |
|
98 | + new \GF_Query_Column( $this->join_column->ID, $join_id ) |
|
99 | 99 | ); |
100 | 100 | } |
101 | 101 | } |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * Contains a join between two Sources on two Fields. |
14 | 14 | */ |
15 | -class Join |
|
16 | -{ |
|
15 | +class Join { |
|
17 | 16 | /** |
18 | 17 | * @var GF_Form|Source|Form |
19 | 18 | * |
@@ -46,8 +45,7 @@ discard block |
||
46 | 45 | * @param \GV\Source $join_on The form we're joining on. |
47 | 46 | * @param \GV\Field $join_on_column Its column. |
48 | 47 | */ |
49 | - public function __construct($join, $join_column, $join_on, $join_on_column) |
|
50 | - { |
|
48 | + public function __construct($join, $join_column, $join_on, $join_on_column) { |
|
51 | 49 | if ($join instanceof \GV\Source) { |
52 | 50 | $this->join = $join; |
53 | 51 | } |
@@ -72,8 +70,7 @@ discard block |
||
72 | 70 | * |
73 | 71 | * @return \GF_Query The $query |
74 | 72 | */ |
75 | - public function as_query_join($query) |
|
76 | - { |
|
73 | + public function as_query_join($query) { |
|
77 | 74 | if (!gravityview()->plugin->supports(Plugin::FEATURE_JOINS)) { |
78 | 75 | return null; |
79 | 76 | } |
@@ -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,46 +14,46 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Entry_Legacy_Template extends Entry_Template |
16 | 16 | { |
17 | - /** |
|
18 | - * Render an old template. |
|
19 | - */ |
|
20 | - public function render() |
|
21 | - { |
|
22 | - if (!class_exists('GravityView_Template')) { |
|
23 | - return; |
|
24 | - } |
|
17 | + /** |
|
18 | + * Render an old template. |
|
19 | + */ |
|
20 | + public function render() |
|
21 | + { |
|
22 | + if (!class_exists('GravityView_Template')) { |
|
23 | + return; |
|
24 | + } |
|
25 | 25 | |
26 | - $entries = new \GV\Entry_Collection(); |
|
27 | - $entries->add($this->entry); |
|
26 | + $entries = new \GV\Entry_Collection(); |
|
27 | + $entries->add($this->entry); |
|
28 | 28 | |
29 | - $context = [ |
|
30 | - 'view' => $this->view, |
|
31 | - 'fields' => $this->view->fields->by_visible($this->view), |
|
32 | - 'entries' => $entries, |
|
33 | - 'entry' => $this->entry, |
|
34 | - 'request' => $this->request, |
|
35 | - ]; |
|
29 | + $context = [ |
|
30 | + 'view' => $this->view, |
|
31 | + 'fields' => $this->view->fields->by_visible($this->view), |
|
32 | + 'entries' => $entries, |
|
33 | + 'entry' => $this->entry, |
|
34 | + 'request' => $this->request, |
|
35 | + ]; |
|
36 | 36 | |
37 | - global $post; |
|
37 | + global $post; |
|
38 | 38 | |
39 | - if ($post) { |
|
40 | - $context['post'] = $post; |
|
41 | - } |
|
39 | + if ($post) { |
|
40 | + $context['post'] = $post; |
|
41 | + } |
|
42 | 42 | |
43 | - \GV\Mocks\Legacy_Context::push($context); |
|
43 | + \GV\Mocks\Legacy_Context::push($context); |
|
44 | 44 | |
45 | - $sections = ['single']; |
|
45 | + $sections = ['single']; |
|
46 | 46 | |
47 | - $sections = apply_filters('gravityview_render_view_sections', $sections, $this->view->settings->get('template')); |
|
47 | + $sections = apply_filters('gravityview_render_view_sections', $sections, $this->view->settings->get('template')); |
|
48 | 48 | |
49 | - $template = \GravityView_View::getInstance(); |
|
49 | + $template = \GravityView_View::getInstance(); |
|
50 | 50 | |
51 | - $slug = apply_filters('gravityview_template_slug_'.$this->view->settings->get('template'), 'table', 'directory'); |
|
51 | + $slug = apply_filters('gravityview_template_slug_'.$this->view->settings->get('template'), 'table', 'directory'); |
|
52 | 52 | |
53 | - foreach ($sections as $section) { |
|
54 | - $template->render($slug, $section, false); |
|
55 | - } |
|
53 | + foreach ($sections as $section) { |
|
54 | + $template->render($slug, $section, false); |
|
55 | + } |
|
56 | 56 | |
57 | - \GV\Mocks\Legacy_Context::pop(); |
|
58 | - } |
|
57 | + \GV\Mocks\Legacy_Context::pop(); |
|
58 | + } |
|
59 | 59 | } |
@@ -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,16 +19,16 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function render() |
21 | 21 | { |
22 | - if (!class_exists('GravityView_Template')) { |
|
22 | + if ( ! class_exists( 'GravityView_Template' ) ) { |
|
23 | 23 | return; |
24 | 24 | } |
25 | 25 | |
26 | 26 | $entries = new \GV\Entry_Collection(); |
27 | - $entries->add($this->entry); |
|
27 | + $entries->add( $this->entry ); |
|
28 | 28 | |
29 | 29 | $context = [ |
30 | 30 | 'view' => $this->view, |
31 | - 'fields' => $this->view->fields->by_visible($this->view), |
|
31 | + 'fields' => $this->view->fields->by_visible( $this->view ), |
|
32 | 32 | 'entries' => $entries, |
33 | 33 | 'entry' => $this->entry, |
34 | 34 | 'request' => $this->request, |
@@ -36,22 +36,22 @@ discard block |
||
36 | 36 | |
37 | 37 | global $post; |
38 | 38 | |
39 | - if ($post) { |
|
40 | - $context['post'] = $post; |
|
39 | + if ( $post ) { |
|
40 | + $context[ 'post' ] = $post; |
|
41 | 41 | } |
42 | 42 | |
43 | - \GV\Mocks\Legacy_Context::push($context); |
|
43 | + \GV\Mocks\Legacy_Context::push( $context ); |
|
44 | 44 | |
45 | - $sections = ['single']; |
|
45 | + $sections = [ 'single' ]; |
|
46 | 46 | |
47 | - $sections = apply_filters('gravityview_render_view_sections', $sections, $this->view->settings->get('template')); |
|
47 | + $sections = apply_filters( 'gravityview_render_view_sections', $sections, $this->view->settings->get( 'template' ) ); |
|
48 | 48 | |
49 | 49 | $template = \GravityView_View::getInstance(); |
50 | 50 | |
51 | - $slug = apply_filters('gravityview_template_slug_'.$this->view->settings->get('template'), 'table', 'directory'); |
|
51 | + $slug = apply_filters( 'gravityview_template_slug_' . $this->view->settings->get( 'template' ), 'table', 'directory' ); |
|
52 | 52 | |
53 | - foreach ($sections as $section) { |
|
54 | - $template->render($slug, $section, false); |
|
53 | + foreach ( $sections as $section ) { |
|
54 | + $template->render( $slug, $section, false ); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | \GV\Mocks\Legacy_Context::pop(); |
@@ -12,13 +12,11 @@ |
||
12 | 12 | * |
13 | 13 | * A back-compatibility layer for old templates to work. |
14 | 14 | */ |
15 | -class Entry_Legacy_Template extends Entry_Template |
|
16 | -{ |
|
15 | +class Entry_Legacy_Template extends Entry_Template { |
|
17 | 16 | /** |
18 | 17 | * Render an old template. |
19 | 18 | */ |
20 | - public function render() |
|
21 | - { |
|
19 | + public function render() { |
|
22 | 20 | if (!class_exists('GravityView_Template')) { |
23 | 21 | return; |
24 | 22 | } |