@@ -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 | /** |
@@ -16,273 +16,273 @@ discard block |
||
16 | 16 | */ |
17 | 17 | final class Core |
18 | 18 | { |
19 | - /** |
|
20 | - * @var \GV\Core The \GV\Core static instance. |
|
21 | - */ |
|
22 | - private static $__instance = null; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var \GV\Plugin The WordPress plugin context. |
|
26 | - * |
|
27 | - * @api |
|
28 | - * |
|
29 | - * @since 2.0 |
|
30 | - */ |
|
31 | - public $plugin; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var \GV\Admin_Request|\GV\Frontend_Request|\GV\Request The global request. |
|
35 | - * |
|
36 | - * @api |
|
37 | - * |
|
38 | - * @since 2.0 |
|
39 | - */ |
|
40 | - public $request; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var \GV\Logger |
|
44 | - * |
|
45 | - * @api |
|
46 | - * |
|
47 | - * @since 2.0 |
|
48 | - */ |
|
49 | - public $log; |
|
50 | - |
|
51 | - /** |
|
52 | - * Get the global instance of \GV\Core. |
|
53 | - * |
|
54 | - * @return \GV\Core The global instance of GravityView Core. |
|
55 | - */ |
|
56 | - public static function get() |
|
57 | - { |
|
58 | - if (!self::$__instance instanceof self) { |
|
59 | - self::$__instance = new self(); |
|
60 | - } |
|
61 | - |
|
62 | - return self::$__instance; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Very early initialization. |
|
67 | - * |
|
68 | - * Activation handlers, rewrites, post type registration. |
|
69 | - */ |
|
70 | - public static function bootstrap() |
|
71 | - { |
|
72 | - require_once dirname(__FILE__).'/class-gv-plugin.php'; |
|
73 | - Plugin::get()->register_activation_hooks(); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Bootstrap. |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - private function __construct() |
|
82 | - { |
|
83 | - self::$__instance = $this; |
|
84 | - $this->init(); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Early initialization. |
|
89 | - * |
|
90 | - * Loads dependencies, sets up the object, adds hooks, etc. |
|
91 | - * |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - private function init() |
|
95 | - { |
|
96 | - $this->plugin = Plugin::get(); |
|
97 | - |
|
98 | - /** Enable logging. */ |
|
99 | - require_once $this->plugin->dir('future/includes/class-gv-logger.php'); |
|
100 | - /** |
|
101 | - * @filter `gravityview/logger` Filter the logger instance being used for logging. |
|
102 | - * |
|
103 | - * @param \GV\Logger $logger The logger instance. |
|
104 | - */ |
|
105 | - $this->log = apply_filters('gravityview/logger', new WP_Action_Logger()); |
|
106 | - |
|
107 | - /** |
|
108 | - * Utilities. |
|
109 | - */ |
|
110 | - require_once $this->plugin->dir('future/includes/class-gv-utils.php'); |
|
111 | - |
|
112 | - /** The Settings. */ |
|
113 | - require_once $this->plugin->dir('future/includes/class-gv-settings.php'); |
|
114 | - require_once $this->plugin->dir('future/includes/class-gv-settings-view.php'); |
|
115 | - |
|
116 | - /** Request. */ |
|
117 | - require_once $this->plugin->dir('future/includes/class-gv-request.php'); |
|
118 | - |
|
119 | - if (Request::is_admin()) { |
|
120 | - $this->request = new Admin_Request(); |
|
121 | - } else { |
|
122 | - $this->request = new Frontend_Request(); |
|
123 | - } |
|
124 | - |
|
125 | - /** Require critical legacy core files. @todo Deprecate */ |
|
126 | - require_once $this->plugin->dir('includes/import-functions.php'); |
|
127 | - require_once $this->plugin->dir('includes/helper-functions.php'); |
|
128 | - require_once $this->plugin->dir('includes/class-common.php'); |
|
129 | - require_once $this->plugin->dir('includes/connector-functions.php'); |
|
130 | - require_once $this->plugin->dir('includes/class-gravityview-compatibility.php'); |
|
131 | - require_once $this->plugin->dir('includes/class-gravityview-roles-capabilities.php'); |
|
132 | - require_once $this->plugin->dir('includes/class-gravityview-admin-notices.php'); |
|
133 | - require_once $this->plugin->dir('includes/class-admin.php'); |
|
134 | - require_once $this->plugin->dir('includes/class-post-types.php'); |
|
135 | - require_once $this->plugin->dir('includes/class-cache.php'); |
|
136 | - |
|
137 | - /** |
|
138 | - * GravityView extensions and widgets. |
|
139 | - */ |
|
140 | - require_once $this->plugin->dir('future/includes/class-gv-extension.php'); |
|
141 | - require_once $this->plugin->dir('future/includes/class-gv-widget.php'); |
|
142 | - |
|
143 | - /** More legacy core. @todo Deprecate */ |
|
144 | - $this->plugin->include_legacy_core(); |
|
145 | - |
|
146 | - /** |
|
147 | - * Stop all further functionality from loading if the WordPress |
|
148 | - * plugin is incompatible with the current environment. |
|
149 | - * |
|
150 | - * Saves some time and memory. |
|
151 | - */ |
|
152 | - if (!$this->plugin->is_compatible()) { |
|
153 | - $this->log->error('GravityView 2.0 is not compatible with this environment. Stopped loading.'); |
|
154 | - |
|
155 | - return; |
|
156 | - } |
|
157 | - |
|
158 | - /** Register the gravityview post type upon WordPress core init. */ |
|
159 | - require_once $this->plugin->dir('future/includes/class-gv-view.php'); |
|
160 | - add_action('init', ['\GV\View', 'register_post_type']); |
|
161 | - add_action('init', ['\GV\View', 'add_rewrite_endpoint']); |
|
162 | - add_filter('map_meta_cap', ['\GV\View', 'restrict'], 11, 4); |
|
163 | - add_action('template_redirect', ['\GV\View', 'template_redirect']); |
|
164 | - add_action('the_content', ['\GV\View', 'content']); |
|
165 | - |
|
166 | - /** Add rewrite endpoint for single-entry URLs. */ |
|
167 | - require_once $this->plugin->dir('future/includes/class-gv-entry.php'); |
|
168 | - add_action('init', ['\GV\Entry', 'add_rewrite_endpoint']); |
|
169 | - |
|
170 | - /** REST API */ |
|
171 | - require_once $this->plugin->dir('future/includes/rest/class-gv-rest-core.php'); |
|
172 | - add_action('rest_api_init', ['\GV\REST\Core', 'init']); |
|
173 | - |
|
174 | - /** Generate custom slugs on entry save. @todo Deprecate. */ |
|
175 | - add_action('gform_entry_created', ['\GravityView_API', 'entry_create_custom_slug'], 10, 2); |
|
176 | - |
|
177 | - /** Shortcodes */ |
|
178 | - require_once $this->plugin->dir('future/includes/class-gv-shortcode.php'); |
|
179 | - require_once $this->plugin->dir('future/includes/class-gv-shortcode-gravityview.php'); |
|
180 | - require_once $this->plugin->dir('future/includes/class-gv-shortcode-gventry.php'); |
|
181 | - require_once $this->plugin->dir('future/includes/class-gv-shortcode-gvfield.php'); |
|
182 | - require_once $this->plugin->dir('future/includes/class-gv-shortcode-gvlogic.php'); |
|
183 | - add_action('init', ['\GV\Shortcodes\gravityview', 'add']); |
|
184 | - add_action('init', ['\GV\Shortcodes\gventry', 'add']); |
|
185 | - add_action('init', ['\GV\Shortcodes\gvfield', 'add']); |
|
186 | - add_action('init', ['\GV\Shortcodes\gvlogic', 'add']); |
|
187 | - |
|
188 | - /** oEmbed */ |
|
189 | - require_once $this->plugin->dir('future/includes/class-gv-oembed.php'); |
|
190 | - add_action('init', ['\GV\oEmbed', 'init'], 11); |
|
191 | - |
|
192 | - /** Our Source generic and beloved source and form backend implementations. */ |
|
193 | - require_once $this->plugin->dir('future/includes/class-gv-source.php'); |
|
194 | - require_once $this->plugin->dir('future/includes/class-gv-source-internal.php'); |
|
195 | - require_once $this->plugin->dir('future/includes/class-gv-form.php'); |
|
196 | - require_once $this->plugin->dir('future/includes/class-gv-form-gravityforms.php'); |
|
197 | - |
|
198 | - /** Joins */ |
|
199 | - require_once $this->plugin->dir('future/includes/class-gv-form-join.php'); |
|
200 | - |
|
201 | - /** Our Entry generic and beloved entry backend implementations. */ |
|
202 | - require_once $this->plugin->dir('future/includes/class-gv-entry-gravityforms.php'); |
|
203 | - require_once $this->plugin->dir('future/includes/class-gv-entry-multi.php'); |
|
204 | - |
|
205 | - /** Context is everything. */ |
|
206 | - require_once $this->plugin->dir('future/includes/class-gv-context.php'); |
|
207 | - require_once $this->plugin->dir('future/includes/class-gv-context-template.php'); |
|
208 | - |
|
209 | - /** Our Field generic and implementations. */ |
|
210 | - require_once $this->plugin->dir('future/includes/class-gv-field.php'); |
|
211 | - require_once $this->plugin->dir('future/includes/class-gv-field-gravityforms.php'); |
|
212 | - require_once $this->plugin->dir('future/includes/class-gv-field-internal.php'); |
|
213 | - |
|
214 | - /** Get the collections ready. */ |
|
215 | - require_once $this->plugin->dir('future/includes/class-gv-collection.php'); |
|
216 | - require_once $this->plugin->dir('future/includes/class-gv-collection-form.php'); |
|
217 | - require_once $this->plugin->dir('future/includes/class-gv-collection-field.php'); |
|
218 | - require_once $this->plugin->dir('future/includes/class-gv-collection-entry.php'); |
|
219 | - require_once $this->plugin->dir('future/includes/class-gv-collection-widget.php'); |
|
220 | - require_once $this->plugin->dir('future/includes/class-gv-collection-view.php'); |
|
221 | - |
|
222 | - /** The sorting, filtering and paging classes. */ |
|
223 | - require_once $this->plugin->dir('future/includes/class-gv-collection-entry-filter.php'); |
|
224 | - require_once $this->plugin->dir('future/includes/class-gv-collection-entry-sort.php'); |
|
225 | - require_once $this->plugin->dir('future/includes/class-gv-collection-entry-offset.php'); |
|
226 | - |
|
227 | - /** The Renderers. */ |
|
228 | - require_once $this->plugin->dir('future/includes/class-gv-renderer.php'); |
|
229 | - require_once $this->plugin->dir('future/includes/class-gv-renderer-view.php'); |
|
230 | - require_once $this->plugin->dir('future/includes/class-gv-renderer-entry.php'); |
|
231 | - require_once $this->plugin->dir('future/includes/class-gv-renderer-entry-edit.php'); |
|
232 | - require_once $this->plugin->dir('future/includes/class-gv-renderer-field.php'); |
|
233 | - |
|
234 | - /** Templating. */ |
|
235 | - require_once $this->plugin->dir('future/includes/class-gv-template.php'); |
|
236 | - require_once $this->plugin->dir('future/includes/class-gv-template-view.php'); |
|
237 | - require_once $this->plugin->dir('future/includes/class-gv-template-entry.php'); |
|
238 | - require_once $this->plugin->dir('future/includes/class-gv-template-field.php'); |
|
239 | - require_once $this->plugin->dir('future/includes/class-gv-template-legacy-override.php'); |
|
240 | - |
|
241 | - /** Magic. */ |
|
242 | - require_once $this->plugin->dir('future/includes/class-gv-wrappers.php'); |
|
243 | - |
|
244 | - require_once $this->plugin->dir('includes/class-gravityview-powered-by.php'); |
|
245 | - |
|
246 | - /** Cache busting. */ |
|
247 | - add_action('clean_post_cache', '\GV\View::_flush_cache'); |
|
248 | - |
|
249 | - /** |
|
250 | - * @action `gravityview/loaded` The core has been loaded. |
|
251 | - * |
|
252 | - * Note: this is a very early load hook, not all of WordPress core has been loaded here. |
|
253 | - * `init` hasn't been called yet. |
|
254 | - */ |
|
255 | - do_action('gravityview/loaded'); |
|
256 | - } |
|
257 | - |
|
258 | - public function __clone() |
|
259 | - { |
|
260 | - } |
|
261 | - |
|
262 | - public function __wakeup() |
|
263 | - { |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Wrapper magic. |
|
268 | - * |
|
269 | - * Making developers happy, since 2017. |
|
270 | - */ |
|
271 | - public function __get($key) |
|
272 | - { |
|
273 | - static $views; |
|
274 | - |
|
275 | - switch ($key) { |
|
276 | - case 'views': |
|
277 | - if (is_null($views)) { |
|
278 | - $views = new \GV\Wrappers\views(); |
|
279 | - } |
|
280 | - |
|
281 | - return $views; |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - public function __set($key, $value) |
|
286 | - { |
|
287 | - } |
|
19 | + /** |
|
20 | + * @var \GV\Core The \GV\Core static instance. |
|
21 | + */ |
|
22 | + private static $__instance = null; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var \GV\Plugin The WordPress plugin context. |
|
26 | + * |
|
27 | + * @api |
|
28 | + * |
|
29 | + * @since 2.0 |
|
30 | + */ |
|
31 | + public $plugin; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var \GV\Admin_Request|\GV\Frontend_Request|\GV\Request The global request. |
|
35 | + * |
|
36 | + * @api |
|
37 | + * |
|
38 | + * @since 2.0 |
|
39 | + */ |
|
40 | + public $request; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var \GV\Logger |
|
44 | + * |
|
45 | + * @api |
|
46 | + * |
|
47 | + * @since 2.0 |
|
48 | + */ |
|
49 | + public $log; |
|
50 | + |
|
51 | + /** |
|
52 | + * Get the global instance of \GV\Core. |
|
53 | + * |
|
54 | + * @return \GV\Core The global instance of GravityView Core. |
|
55 | + */ |
|
56 | + public static function get() |
|
57 | + { |
|
58 | + if (!self::$__instance instanceof self) { |
|
59 | + self::$__instance = new self(); |
|
60 | + } |
|
61 | + |
|
62 | + return self::$__instance; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Very early initialization. |
|
67 | + * |
|
68 | + * Activation handlers, rewrites, post type registration. |
|
69 | + */ |
|
70 | + public static function bootstrap() |
|
71 | + { |
|
72 | + require_once dirname(__FILE__).'/class-gv-plugin.php'; |
|
73 | + Plugin::get()->register_activation_hooks(); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Bootstrap. |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + private function __construct() |
|
82 | + { |
|
83 | + self::$__instance = $this; |
|
84 | + $this->init(); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Early initialization. |
|
89 | + * |
|
90 | + * Loads dependencies, sets up the object, adds hooks, etc. |
|
91 | + * |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + private function init() |
|
95 | + { |
|
96 | + $this->plugin = Plugin::get(); |
|
97 | + |
|
98 | + /** Enable logging. */ |
|
99 | + require_once $this->plugin->dir('future/includes/class-gv-logger.php'); |
|
100 | + /** |
|
101 | + * @filter `gravityview/logger` Filter the logger instance being used for logging. |
|
102 | + * |
|
103 | + * @param \GV\Logger $logger The logger instance. |
|
104 | + */ |
|
105 | + $this->log = apply_filters('gravityview/logger', new WP_Action_Logger()); |
|
106 | + |
|
107 | + /** |
|
108 | + * Utilities. |
|
109 | + */ |
|
110 | + require_once $this->plugin->dir('future/includes/class-gv-utils.php'); |
|
111 | + |
|
112 | + /** The Settings. */ |
|
113 | + require_once $this->plugin->dir('future/includes/class-gv-settings.php'); |
|
114 | + require_once $this->plugin->dir('future/includes/class-gv-settings-view.php'); |
|
115 | + |
|
116 | + /** Request. */ |
|
117 | + require_once $this->plugin->dir('future/includes/class-gv-request.php'); |
|
118 | + |
|
119 | + if (Request::is_admin()) { |
|
120 | + $this->request = new Admin_Request(); |
|
121 | + } else { |
|
122 | + $this->request = new Frontend_Request(); |
|
123 | + } |
|
124 | + |
|
125 | + /** Require critical legacy core files. @todo Deprecate */ |
|
126 | + require_once $this->plugin->dir('includes/import-functions.php'); |
|
127 | + require_once $this->plugin->dir('includes/helper-functions.php'); |
|
128 | + require_once $this->plugin->dir('includes/class-common.php'); |
|
129 | + require_once $this->plugin->dir('includes/connector-functions.php'); |
|
130 | + require_once $this->plugin->dir('includes/class-gravityview-compatibility.php'); |
|
131 | + require_once $this->plugin->dir('includes/class-gravityview-roles-capabilities.php'); |
|
132 | + require_once $this->plugin->dir('includes/class-gravityview-admin-notices.php'); |
|
133 | + require_once $this->plugin->dir('includes/class-admin.php'); |
|
134 | + require_once $this->plugin->dir('includes/class-post-types.php'); |
|
135 | + require_once $this->plugin->dir('includes/class-cache.php'); |
|
136 | + |
|
137 | + /** |
|
138 | + * GravityView extensions and widgets. |
|
139 | + */ |
|
140 | + require_once $this->plugin->dir('future/includes/class-gv-extension.php'); |
|
141 | + require_once $this->plugin->dir('future/includes/class-gv-widget.php'); |
|
142 | + |
|
143 | + /** More legacy core. @todo Deprecate */ |
|
144 | + $this->plugin->include_legacy_core(); |
|
145 | + |
|
146 | + /** |
|
147 | + * Stop all further functionality from loading if the WordPress |
|
148 | + * plugin is incompatible with the current environment. |
|
149 | + * |
|
150 | + * Saves some time and memory. |
|
151 | + */ |
|
152 | + if (!$this->plugin->is_compatible()) { |
|
153 | + $this->log->error('GravityView 2.0 is not compatible with this environment. Stopped loading.'); |
|
154 | + |
|
155 | + return; |
|
156 | + } |
|
157 | + |
|
158 | + /** Register the gravityview post type upon WordPress core init. */ |
|
159 | + require_once $this->plugin->dir('future/includes/class-gv-view.php'); |
|
160 | + add_action('init', ['\GV\View', 'register_post_type']); |
|
161 | + add_action('init', ['\GV\View', 'add_rewrite_endpoint']); |
|
162 | + add_filter('map_meta_cap', ['\GV\View', 'restrict'], 11, 4); |
|
163 | + add_action('template_redirect', ['\GV\View', 'template_redirect']); |
|
164 | + add_action('the_content', ['\GV\View', 'content']); |
|
165 | + |
|
166 | + /** Add rewrite endpoint for single-entry URLs. */ |
|
167 | + require_once $this->plugin->dir('future/includes/class-gv-entry.php'); |
|
168 | + add_action('init', ['\GV\Entry', 'add_rewrite_endpoint']); |
|
169 | + |
|
170 | + /** REST API */ |
|
171 | + require_once $this->plugin->dir('future/includes/rest/class-gv-rest-core.php'); |
|
172 | + add_action('rest_api_init', ['\GV\REST\Core', 'init']); |
|
173 | + |
|
174 | + /** Generate custom slugs on entry save. @todo Deprecate. */ |
|
175 | + add_action('gform_entry_created', ['\GravityView_API', 'entry_create_custom_slug'], 10, 2); |
|
176 | + |
|
177 | + /** Shortcodes */ |
|
178 | + require_once $this->plugin->dir('future/includes/class-gv-shortcode.php'); |
|
179 | + require_once $this->plugin->dir('future/includes/class-gv-shortcode-gravityview.php'); |
|
180 | + require_once $this->plugin->dir('future/includes/class-gv-shortcode-gventry.php'); |
|
181 | + require_once $this->plugin->dir('future/includes/class-gv-shortcode-gvfield.php'); |
|
182 | + require_once $this->plugin->dir('future/includes/class-gv-shortcode-gvlogic.php'); |
|
183 | + add_action('init', ['\GV\Shortcodes\gravityview', 'add']); |
|
184 | + add_action('init', ['\GV\Shortcodes\gventry', 'add']); |
|
185 | + add_action('init', ['\GV\Shortcodes\gvfield', 'add']); |
|
186 | + add_action('init', ['\GV\Shortcodes\gvlogic', 'add']); |
|
187 | + |
|
188 | + /** oEmbed */ |
|
189 | + require_once $this->plugin->dir('future/includes/class-gv-oembed.php'); |
|
190 | + add_action('init', ['\GV\oEmbed', 'init'], 11); |
|
191 | + |
|
192 | + /** Our Source generic and beloved source and form backend implementations. */ |
|
193 | + require_once $this->plugin->dir('future/includes/class-gv-source.php'); |
|
194 | + require_once $this->plugin->dir('future/includes/class-gv-source-internal.php'); |
|
195 | + require_once $this->plugin->dir('future/includes/class-gv-form.php'); |
|
196 | + require_once $this->plugin->dir('future/includes/class-gv-form-gravityforms.php'); |
|
197 | + |
|
198 | + /** Joins */ |
|
199 | + require_once $this->plugin->dir('future/includes/class-gv-form-join.php'); |
|
200 | + |
|
201 | + /** Our Entry generic and beloved entry backend implementations. */ |
|
202 | + require_once $this->plugin->dir('future/includes/class-gv-entry-gravityforms.php'); |
|
203 | + require_once $this->plugin->dir('future/includes/class-gv-entry-multi.php'); |
|
204 | + |
|
205 | + /** Context is everything. */ |
|
206 | + require_once $this->plugin->dir('future/includes/class-gv-context.php'); |
|
207 | + require_once $this->plugin->dir('future/includes/class-gv-context-template.php'); |
|
208 | + |
|
209 | + /** Our Field generic and implementations. */ |
|
210 | + require_once $this->plugin->dir('future/includes/class-gv-field.php'); |
|
211 | + require_once $this->plugin->dir('future/includes/class-gv-field-gravityforms.php'); |
|
212 | + require_once $this->plugin->dir('future/includes/class-gv-field-internal.php'); |
|
213 | + |
|
214 | + /** Get the collections ready. */ |
|
215 | + require_once $this->plugin->dir('future/includes/class-gv-collection.php'); |
|
216 | + require_once $this->plugin->dir('future/includes/class-gv-collection-form.php'); |
|
217 | + require_once $this->plugin->dir('future/includes/class-gv-collection-field.php'); |
|
218 | + require_once $this->plugin->dir('future/includes/class-gv-collection-entry.php'); |
|
219 | + require_once $this->plugin->dir('future/includes/class-gv-collection-widget.php'); |
|
220 | + require_once $this->plugin->dir('future/includes/class-gv-collection-view.php'); |
|
221 | + |
|
222 | + /** The sorting, filtering and paging classes. */ |
|
223 | + require_once $this->plugin->dir('future/includes/class-gv-collection-entry-filter.php'); |
|
224 | + require_once $this->plugin->dir('future/includes/class-gv-collection-entry-sort.php'); |
|
225 | + require_once $this->plugin->dir('future/includes/class-gv-collection-entry-offset.php'); |
|
226 | + |
|
227 | + /** The Renderers. */ |
|
228 | + require_once $this->plugin->dir('future/includes/class-gv-renderer.php'); |
|
229 | + require_once $this->plugin->dir('future/includes/class-gv-renderer-view.php'); |
|
230 | + require_once $this->plugin->dir('future/includes/class-gv-renderer-entry.php'); |
|
231 | + require_once $this->plugin->dir('future/includes/class-gv-renderer-entry-edit.php'); |
|
232 | + require_once $this->plugin->dir('future/includes/class-gv-renderer-field.php'); |
|
233 | + |
|
234 | + /** Templating. */ |
|
235 | + require_once $this->plugin->dir('future/includes/class-gv-template.php'); |
|
236 | + require_once $this->plugin->dir('future/includes/class-gv-template-view.php'); |
|
237 | + require_once $this->plugin->dir('future/includes/class-gv-template-entry.php'); |
|
238 | + require_once $this->plugin->dir('future/includes/class-gv-template-field.php'); |
|
239 | + require_once $this->plugin->dir('future/includes/class-gv-template-legacy-override.php'); |
|
240 | + |
|
241 | + /** Magic. */ |
|
242 | + require_once $this->plugin->dir('future/includes/class-gv-wrappers.php'); |
|
243 | + |
|
244 | + require_once $this->plugin->dir('includes/class-gravityview-powered-by.php'); |
|
245 | + |
|
246 | + /** Cache busting. */ |
|
247 | + add_action('clean_post_cache', '\GV\View::_flush_cache'); |
|
248 | + |
|
249 | + /** |
|
250 | + * @action `gravityview/loaded` The core has been loaded. |
|
251 | + * |
|
252 | + * Note: this is a very early load hook, not all of WordPress core has been loaded here. |
|
253 | + * `init` hasn't been called yet. |
|
254 | + */ |
|
255 | + do_action('gravityview/loaded'); |
|
256 | + } |
|
257 | + |
|
258 | + public function __clone() |
|
259 | + { |
|
260 | + } |
|
261 | + |
|
262 | + public function __wakeup() |
|
263 | + { |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Wrapper magic. |
|
268 | + * |
|
269 | + * Making developers happy, since 2017. |
|
270 | + */ |
|
271 | + public function __get($key) |
|
272 | + { |
|
273 | + static $views; |
|
274 | + |
|
275 | + switch ($key) { |
|
276 | + case 'views': |
|
277 | + if (is_null($views)) { |
|
278 | + $views = new \GV\Wrappers\views(); |
|
279 | + } |
|
280 | + |
|
281 | + return $views; |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + public function __set($key, $value) |
|
286 | + { |
|
287 | + } |
|
288 | 288 | } |
@@ -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 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public static function get() |
57 | 57 | { |
58 | - if (!self::$__instance instanceof self) { |
|
58 | + if ( ! self::$__instance instanceof self ) { |
|
59 | 59 | self::$__instance = new self(); |
60 | 60 | } |
61 | 61 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public static function bootstrap() |
71 | 71 | { |
72 | - require_once dirname(__FILE__).'/class-gv-plugin.php'; |
|
72 | + require_once dirname( __FILE__ ) . '/class-gv-plugin.php'; |
|
73 | 73 | Plugin::get()->register_activation_hooks(); |
74 | 74 | } |
75 | 75 | |
@@ -96,49 +96,49 @@ discard block |
||
96 | 96 | $this->plugin = Plugin::get(); |
97 | 97 | |
98 | 98 | /** Enable logging. */ |
99 | - require_once $this->plugin->dir('future/includes/class-gv-logger.php'); |
|
99 | + require_once $this->plugin->dir( 'future/includes/class-gv-logger.php' ); |
|
100 | 100 | /** |
101 | 101 | * @filter `gravityview/logger` Filter the logger instance being used for logging. |
102 | 102 | * |
103 | 103 | * @param \GV\Logger $logger The logger instance. |
104 | 104 | */ |
105 | - $this->log = apply_filters('gravityview/logger', new WP_Action_Logger()); |
|
105 | + $this->log = apply_filters( 'gravityview/logger', new WP_Action_Logger() ); |
|
106 | 106 | |
107 | 107 | /** |
108 | 108 | * Utilities. |
109 | 109 | */ |
110 | - require_once $this->plugin->dir('future/includes/class-gv-utils.php'); |
|
110 | + require_once $this->plugin->dir( 'future/includes/class-gv-utils.php' ); |
|
111 | 111 | |
112 | 112 | /** The Settings. */ |
113 | - require_once $this->plugin->dir('future/includes/class-gv-settings.php'); |
|
114 | - require_once $this->plugin->dir('future/includes/class-gv-settings-view.php'); |
|
113 | + require_once $this->plugin->dir( 'future/includes/class-gv-settings.php' ); |
|
114 | + require_once $this->plugin->dir( 'future/includes/class-gv-settings-view.php' ); |
|
115 | 115 | |
116 | 116 | /** Request. */ |
117 | - require_once $this->plugin->dir('future/includes/class-gv-request.php'); |
|
117 | + require_once $this->plugin->dir( 'future/includes/class-gv-request.php' ); |
|
118 | 118 | |
119 | - if (Request::is_admin()) { |
|
119 | + if ( Request::is_admin() ) { |
|
120 | 120 | $this->request = new Admin_Request(); |
121 | 121 | } else { |
122 | 122 | $this->request = new Frontend_Request(); |
123 | 123 | } |
124 | 124 | |
125 | 125 | /** Require critical legacy core files. @todo Deprecate */ |
126 | - require_once $this->plugin->dir('includes/import-functions.php'); |
|
127 | - require_once $this->plugin->dir('includes/helper-functions.php'); |
|
128 | - require_once $this->plugin->dir('includes/class-common.php'); |
|
129 | - require_once $this->plugin->dir('includes/connector-functions.php'); |
|
130 | - require_once $this->plugin->dir('includes/class-gravityview-compatibility.php'); |
|
131 | - require_once $this->plugin->dir('includes/class-gravityview-roles-capabilities.php'); |
|
132 | - require_once $this->plugin->dir('includes/class-gravityview-admin-notices.php'); |
|
133 | - require_once $this->plugin->dir('includes/class-admin.php'); |
|
134 | - require_once $this->plugin->dir('includes/class-post-types.php'); |
|
135 | - require_once $this->plugin->dir('includes/class-cache.php'); |
|
126 | + require_once $this->plugin->dir( 'includes/import-functions.php' ); |
|
127 | + require_once $this->plugin->dir( 'includes/helper-functions.php' ); |
|
128 | + require_once $this->plugin->dir( 'includes/class-common.php' ); |
|
129 | + require_once $this->plugin->dir( 'includes/connector-functions.php' ); |
|
130 | + require_once $this->plugin->dir( 'includes/class-gravityview-compatibility.php' ); |
|
131 | + require_once $this->plugin->dir( 'includes/class-gravityview-roles-capabilities.php' ); |
|
132 | + require_once $this->plugin->dir( 'includes/class-gravityview-admin-notices.php' ); |
|
133 | + require_once $this->plugin->dir( 'includes/class-admin.php' ); |
|
134 | + require_once $this->plugin->dir( 'includes/class-post-types.php' ); |
|
135 | + require_once $this->plugin->dir( 'includes/class-cache.php' ); |
|
136 | 136 | |
137 | 137 | /** |
138 | 138 | * GravityView extensions and widgets. |
139 | 139 | */ |
140 | - require_once $this->plugin->dir('future/includes/class-gv-extension.php'); |
|
141 | - require_once $this->plugin->dir('future/includes/class-gv-widget.php'); |
|
140 | + require_once $this->plugin->dir( 'future/includes/class-gv-extension.php' ); |
|
141 | + require_once $this->plugin->dir( 'future/includes/class-gv-widget.php' ); |
|
142 | 142 | |
143 | 143 | /** More legacy core. @todo Deprecate */ |
144 | 144 | $this->plugin->include_legacy_core(); |
@@ -149,102 +149,102 @@ discard block |
||
149 | 149 | * |
150 | 150 | * Saves some time and memory. |
151 | 151 | */ |
152 | - if (!$this->plugin->is_compatible()) { |
|
153 | - $this->log->error('GravityView 2.0 is not compatible with this environment. Stopped loading.'); |
|
152 | + if ( ! $this->plugin->is_compatible() ) { |
|
153 | + $this->log->error( 'GravityView 2.0 is not compatible with this environment. Stopped loading.' ); |
|
154 | 154 | |
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | 158 | /** Register the gravityview post type upon WordPress core init. */ |
159 | - require_once $this->plugin->dir('future/includes/class-gv-view.php'); |
|
160 | - add_action('init', ['\GV\View', 'register_post_type']); |
|
161 | - add_action('init', ['\GV\View', 'add_rewrite_endpoint']); |
|
162 | - add_filter('map_meta_cap', ['\GV\View', 'restrict'], 11, 4); |
|
163 | - add_action('template_redirect', ['\GV\View', 'template_redirect']); |
|
164 | - add_action('the_content', ['\GV\View', 'content']); |
|
159 | + require_once $this->plugin->dir( 'future/includes/class-gv-view.php' ); |
|
160 | + add_action( 'init', [ '\GV\View', 'register_post_type' ] ); |
|
161 | + add_action( 'init', [ '\GV\View', 'add_rewrite_endpoint' ] ); |
|
162 | + add_filter( 'map_meta_cap', [ '\GV\View', 'restrict' ], 11, 4 ); |
|
163 | + add_action( 'template_redirect', [ '\GV\View', 'template_redirect' ] ); |
|
164 | + add_action( 'the_content', [ '\GV\View', 'content' ] ); |
|
165 | 165 | |
166 | 166 | /** Add rewrite endpoint for single-entry URLs. */ |
167 | - require_once $this->plugin->dir('future/includes/class-gv-entry.php'); |
|
168 | - add_action('init', ['\GV\Entry', 'add_rewrite_endpoint']); |
|
167 | + require_once $this->plugin->dir( 'future/includes/class-gv-entry.php' ); |
|
168 | + add_action( 'init', [ '\GV\Entry', 'add_rewrite_endpoint' ] ); |
|
169 | 169 | |
170 | 170 | /** REST API */ |
171 | - require_once $this->plugin->dir('future/includes/rest/class-gv-rest-core.php'); |
|
172 | - add_action('rest_api_init', ['\GV\REST\Core', 'init']); |
|
171 | + require_once $this->plugin->dir( 'future/includes/rest/class-gv-rest-core.php' ); |
|
172 | + add_action( 'rest_api_init', [ '\GV\REST\Core', 'init' ] ); |
|
173 | 173 | |
174 | 174 | /** Generate custom slugs on entry save. @todo Deprecate. */ |
175 | - add_action('gform_entry_created', ['\GravityView_API', 'entry_create_custom_slug'], 10, 2); |
|
175 | + add_action( 'gform_entry_created', [ '\GravityView_API', 'entry_create_custom_slug' ], 10, 2 ); |
|
176 | 176 | |
177 | 177 | /** Shortcodes */ |
178 | - require_once $this->plugin->dir('future/includes/class-gv-shortcode.php'); |
|
179 | - require_once $this->plugin->dir('future/includes/class-gv-shortcode-gravityview.php'); |
|
180 | - require_once $this->plugin->dir('future/includes/class-gv-shortcode-gventry.php'); |
|
181 | - require_once $this->plugin->dir('future/includes/class-gv-shortcode-gvfield.php'); |
|
182 | - require_once $this->plugin->dir('future/includes/class-gv-shortcode-gvlogic.php'); |
|
183 | - add_action('init', ['\GV\Shortcodes\gravityview', 'add']); |
|
184 | - add_action('init', ['\GV\Shortcodes\gventry', 'add']); |
|
185 | - add_action('init', ['\GV\Shortcodes\gvfield', 'add']); |
|
186 | - add_action('init', ['\GV\Shortcodes\gvlogic', 'add']); |
|
178 | + require_once $this->plugin->dir( 'future/includes/class-gv-shortcode.php' ); |
|
179 | + require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gravityview.php' ); |
|
180 | + require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gventry.php' ); |
|
181 | + require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gvfield.php' ); |
|
182 | + require_once $this->plugin->dir( 'future/includes/class-gv-shortcode-gvlogic.php' ); |
|
183 | + add_action( 'init', [ '\GV\Shortcodes\gravityview', 'add' ] ); |
|
184 | + add_action( 'init', [ '\GV\Shortcodes\gventry', 'add' ] ); |
|
185 | + add_action( 'init', [ '\GV\Shortcodes\gvfield', 'add' ] ); |
|
186 | + add_action( 'init', [ '\GV\Shortcodes\gvlogic', 'add' ] ); |
|
187 | 187 | |
188 | 188 | /** oEmbed */ |
189 | - require_once $this->plugin->dir('future/includes/class-gv-oembed.php'); |
|
190 | - add_action('init', ['\GV\oEmbed', 'init'], 11); |
|
189 | + require_once $this->plugin->dir( 'future/includes/class-gv-oembed.php' ); |
|
190 | + add_action( 'init', [ '\GV\oEmbed', 'init' ], 11 ); |
|
191 | 191 | |
192 | 192 | /** Our Source generic and beloved source and form backend implementations. */ |
193 | - require_once $this->plugin->dir('future/includes/class-gv-source.php'); |
|
194 | - require_once $this->plugin->dir('future/includes/class-gv-source-internal.php'); |
|
195 | - require_once $this->plugin->dir('future/includes/class-gv-form.php'); |
|
196 | - require_once $this->plugin->dir('future/includes/class-gv-form-gravityforms.php'); |
|
193 | + require_once $this->plugin->dir( 'future/includes/class-gv-source.php' ); |
|
194 | + require_once $this->plugin->dir( 'future/includes/class-gv-source-internal.php' ); |
|
195 | + require_once $this->plugin->dir( 'future/includes/class-gv-form.php' ); |
|
196 | + require_once $this->plugin->dir( 'future/includes/class-gv-form-gravityforms.php' ); |
|
197 | 197 | |
198 | 198 | /** Joins */ |
199 | - require_once $this->plugin->dir('future/includes/class-gv-form-join.php'); |
|
199 | + require_once $this->plugin->dir( 'future/includes/class-gv-form-join.php' ); |
|
200 | 200 | |
201 | 201 | /** Our Entry generic and beloved entry backend implementations. */ |
202 | - require_once $this->plugin->dir('future/includes/class-gv-entry-gravityforms.php'); |
|
203 | - require_once $this->plugin->dir('future/includes/class-gv-entry-multi.php'); |
|
202 | + require_once $this->plugin->dir( 'future/includes/class-gv-entry-gravityforms.php' ); |
|
203 | + require_once $this->plugin->dir( 'future/includes/class-gv-entry-multi.php' ); |
|
204 | 204 | |
205 | 205 | /** Context is everything. */ |
206 | - require_once $this->plugin->dir('future/includes/class-gv-context.php'); |
|
207 | - require_once $this->plugin->dir('future/includes/class-gv-context-template.php'); |
|
206 | + require_once $this->plugin->dir( 'future/includes/class-gv-context.php' ); |
|
207 | + require_once $this->plugin->dir( 'future/includes/class-gv-context-template.php' ); |
|
208 | 208 | |
209 | 209 | /** Our Field generic and implementations. */ |
210 | - require_once $this->plugin->dir('future/includes/class-gv-field.php'); |
|
211 | - require_once $this->plugin->dir('future/includes/class-gv-field-gravityforms.php'); |
|
212 | - require_once $this->plugin->dir('future/includes/class-gv-field-internal.php'); |
|
210 | + require_once $this->plugin->dir( 'future/includes/class-gv-field.php' ); |
|
211 | + require_once $this->plugin->dir( 'future/includes/class-gv-field-gravityforms.php' ); |
|
212 | + require_once $this->plugin->dir( 'future/includes/class-gv-field-internal.php' ); |
|
213 | 213 | |
214 | 214 | /** Get the collections ready. */ |
215 | - require_once $this->plugin->dir('future/includes/class-gv-collection.php'); |
|
216 | - require_once $this->plugin->dir('future/includes/class-gv-collection-form.php'); |
|
217 | - require_once $this->plugin->dir('future/includes/class-gv-collection-field.php'); |
|
218 | - require_once $this->plugin->dir('future/includes/class-gv-collection-entry.php'); |
|
219 | - require_once $this->plugin->dir('future/includes/class-gv-collection-widget.php'); |
|
220 | - require_once $this->plugin->dir('future/includes/class-gv-collection-view.php'); |
|
215 | + require_once $this->plugin->dir( 'future/includes/class-gv-collection.php' ); |
|
216 | + require_once $this->plugin->dir( 'future/includes/class-gv-collection-form.php' ); |
|
217 | + require_once $this->plugin->dir( 'future/includes/class-gv-collection-field.php' ); |
|
218 | + require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry.php' ); |
|
219 | + require_once $this->plugin->dir( 'future/includes/class-gv-collection-widget.php' ); |
|
220 | + require_once $this->plugin->dir( 'future/includes/class-gv-collection-view.php' ); |
|
221 | 221 | |
222 | 222 | /** The sorting, filtering and paging classes. */ |
223 | - require_once $this->plugin->dir('future/includes/class-gv-collection-entry-filter.php'); |
|
224 | - require_once $this->plugin->dir('future/includes/class-gv-collection-entry-sort.php'); |
|
225 | - require_once $this->plugin->dir('future/includes/class-gv-collection-entry-offset.php'); |
|
223 | + require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-filter.php' ); |
|
224 | + require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-sort.php' ); |
|
225 | + require_once $this->plugin->dir( 'future/includes/class-gv-collection-entry-offset.php' ); |
|
226 | 226 | |
227 | 227 | /** The Renderers. */ |
228 | - require_once $this->plugin->dir('future/includes/class-gv-renderer.php'); |
|
229 | - require_once $this->plugin->dir('future/includes/class-gv-renderer-view.php'); |
|
230 | - require_once $this->plugin->dir('future/includes/class-gv-renderer-entry.php'); |
|
231 | - require_once $this->plugin->dir('future/includes/class-gv-renderer-entry-edit.php'); |
|
232 | - require_once $this->plugin->dir('future/includes/class-gv-renderer-field.php'); |
|
228 | + require_once $this->plugin->dir( 'future/includes/class-gv-renderer.php' ); |
|
229 | + require_once $this->plugin->dir( 'future/includes/class-gv-renderer-view.php' ); |
|
230 | + require_once $this->plugin->dir( 'future/includes/class-gv-renderer-entry.php' ); |
|
231 | + require_once $this->plugin->dir( 'future/includes/class-gv-renderer-entry-edit.php' ); |
|
232 | + require_once $this->plugin->dir( 'future/includes/class-gv-renderer-field.php' ); |
|
233 | 233 | |
234 | 234 | /** Templating. */ |
235 | - require_once $this->plugin->dir('future/includes/class-gv-template.php'); |
|
236 | - require_once $this->plugin->dir('future/includes/class-gv-template-view.php'); |
|
237 | - require_once $this->plugin->dir('future/includes/class-gv-template-entry.php'); |
|
238 | - require_once $this->plugin->dir('future/includes/class-gv-template-field.php'); |
|
239 | - require_once $this->plugin->dir('future/includes/class-gv-template-legacy-override.php'); |
|
235 | + require_once $this->plugin->dir( 'future/includes/class-gv-template.php' ); |
|
236 | + require_once $this->plugin->dir( 'future/includes/class-gv-template-view.php' ); |
|
237 | + require_once $this->plugin->dir( 'future/includes/class-gv-template-entry.php' ); |
|
238 | + require_once $this->plugin->dir( 'future/includes/class-gv-template-field.php' ); |
|
239 | + require_once $this->plugin->dir( 'future/includes/class-gv-template-legacy-override.php' ); |
|
240 | 240 | |
241 | 241 | /** Magic. */ |
242 | - require_once $this->plugin->dir('future/includes/class-gv-wrappers.php'); |
|
242 | + require_once $this->plugin->dir( 'future/includes/class-gv-wrappers.php' ); |
|
243 | 243 | |
244 | - require_once $this->plugin->dir('includes/class-gravityview-powered-by.php'); |
|
244 | + require_once $this->plugin->dir( 'includes/class-gravityview-powered-by.php' ); |
|
245 | 245 | |
246 | 246 | /** Cache busting. */ |
247 | - add_action('clean_post_cache', '\GV\View::_flush_cache'); |
|
247 | + add_action( 'clean_post_cache', '\GV\View::_flush_cache' ); |
|
248 | 248 | |
249 | 249 | /** |
250 | 250 | * @action `gravityview/loaded` The core has been loaded. |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * Note: this is a very early load hook, not all of WordPress core has been loaded here. |
253 | 253 | * `init` hasn't been called yet. |
254 | 254 | */ |
255 | - do_action('gravityview/loaded'); |
|
255 | + do_action( 'gravityview/loaded' ); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | public function __clone() |
@@ -268,13 +268,13 @@ discard block |
||
268 | 268 | * |
269 | 269 | * Making developers happy, since 2017. |
270 | 270 | */ |
271 | - public function __get($key) |
|
271 | + public function __get( $key ) |
|
272 | 272 | { |
273 | 273 | static $views; |
274 | 274 | |
275 | - switch ($key) { |
|
275 | + switch ( $key ) { |
|
276 | 276 | case 'views': |
277 | - if (is_null($views)) { |
|
277 | + if ( is_null( $views ) ) { |
|
278 | 278 | $views = new \GV\Wrappers\views(); |
279 | 279 | } |
280 | 280 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
285 | - public function __set($key, $value) |
|
285 | + public function __set( $key, $value ) |
|
286 | 286 | { |
287 | 287 | } |
288 | 288 | } |
@@ -14,8 +14,7 @@ discard block |
||
14 | 14 | * all the required public functionality and classes, sets up global |
15 | 15 | * state depending on current request context, etc. |
16 | 16 | */ |
17 | -final class Core |
|
18 | -{ |
|
17 | +final class Core { |
|
19 | 18 | /** |
20 | 19 | * @var \GV\Core The \GV\Core static instance. |
21 | 20 | */ |
@@ -53,8 +52,7 @@ discard block |
||
53 | 52 | * |
54 | 53 | * @return \GV\Core The global instance of GravityView Core. |
55 | 54 | */ |
56 | - public static function get() |
|
57 | - { |
|
55 | + public static function get() { |
|
58 | 56 | if (!self::$__instance instanceof self) { |
59 | 57 | self::$__instance = new self(); |
60 | 58 | } |
@@ -67,8 +65,7 @@ discard block |
||
67 | 65 | * |
68 | 66 | * Activation handlers, rewrites, post type registration. |
69 | 67 | */ |
70 | - public static function bootstrap() |
|
71 | - { |
|
68 | + public static function bootstrap() { |
|
72 | 69 | require_once dirname(__FILE__).'/class-gv-plugin.php'; |
73 | 70 | Plugin::get()->register_activation_hooks(); |
74 | 71 | } |
@@ -78,8 +75,7 @@ discard block |
||
78 | 75 | * |
79 | 76 | * @return void |
80 | 77 | */ |
81 | - private function __construct() |
|
82 | - { |
|
78 | + private function __construct() { |
|
83 | 79 | self::$__instance = $this; |
84 | 80 | $this->init(); |
85 | 81 | } |
@@ -91,8 +87,7 @@ discard block |
||
91 | 87 | * |
92 | 88 | * @return void |
93 | 89 | */ |
94 | - private function init() |
|
95 | - { |
|
90 | + private function init() { |
|
96 | 91 | $this->plugin = Plugin::get(); |
97 | 92 | |
98 | 93 | /** Enable logging. */ |
@@ -255,12 +250,10 @@ discard block |
||
255 | 250 | do_action('gravityview/loaded'); |
256 | 251 | } |
257 | 252 | |
258 | - public function __clone() |
|
259 | - { |
|
253 | + public function __clone() { |
|
260 | 254 | } |
261 | 255 | |
262 | - public function __wakeup() |
|
263 | - { |
|
256 | + public function __wakeup() { |
|
264 | 257 | } |
265 | 258 | |
266 | 259 | /** |
@@ -268,8 +261,7 @@ discard block |
||
268 | 261 | * |
269 | 262 | * Making developers happy, since 2017. |
270 | 263 | */ |
271 | - public function __get($key) |
|
272 | - { |
|
264 | + public function __get($key) { |
|
273 | 265 | static $views; |
274 | 266 | |
275 | 267 | switch ($key) { |
@@ -282,7 +274,6 @@ discard block |
||
282 | 274 | } |
283 | 275 | } |
284 | 276 | |
285 | - public function __set($key, $value) |
|
286 | - { |
|
277 | + public function __set($key, $value) { |
|
287 | 278 | } |
288 | 279 | } |
@@ -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,72 +12,72 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Admin_Request extends Request |
14 | 14 | { |
15 | - /** |
|
16 | - * Check if WordPress is_admin(), and whether we have a GravityView page. |
|
17 | - * |
|
18 | - * @return bool If is in an admin context or not. |
|
19 | - * |
|
20 | - * Accepts optional $hook and $context arguments. |
|
21 | - * @return bool|string If `false`, not a GravityView page. `true` if $page is passed and is the same as current page. Otherwise, the name of the page (`single`, `settings`, or `views`) |
|
22 | - */ |
|
23 | - public static function is_admin() |
|
24 | - { |
|
25 | - if (!parent::is_admin()) { |
|
26 | - return false; |
|
27 | - } |
|
15 | + /** |
|
16 | + * Check if WordPress is_admin(), and whether we have a GravityView page. |
|
17 | + * |
|
18 | + * @return bool If is in an admin context or not. |
|
19 | + * |
|
20 | + * Accepts optional $hook and $context arguments. |
|
21 | + * @return bool|string If `false`, not a GravityView page. `true` if $page is passed and is the same as current page. Otherwise, the name of the page (`single`, `settings`, or `views`) |
|
22 | + */ |
|
23 | + public static function is_admin() |
|
24 | + { |
|
25 | + if (!parent::is_admin()) { |
|
26 | + return false; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Regular check. |
|
31 | - */ |
|
32 | - if (!($args = func_get_args())) { |
|
33 | - return true; |
|
34 | - } |
|
29 | + /** |
|
30 | + * Regular check. |
|
31 | + */ |
|
32 | + if (!($args = func_get_args())) { |
|
33 | + return true; |
|
34 | + } |
|
35 | 35 | |
36 | - $hook = \GV\Utils::get($args, 0, ''); |
|
37 | - $context = \GV\Utils::get($args, 1, null); |
|
36 | + $hook = \GV\Utils::get($args, 0, ''); |
|
37 | + $context = \GV\Utils::get($args, 1, null); |
|
38 | 38 | |
39 | - /** |
|
40 | - * Assume false by default. |
|
41 | - */ |
|
42 | - $is_page = false; |
|
39 | + /** |
|
40 | + * Assume false by default. |
|
41 | + */ |
|
42 | + $is_page = false; |
|
43 | 43 | |
44 | - if (function_exists('\get_current_screen') || function_exists('get_current_screen')) { |
|
45 | - $current_screen = \get_current_screen(); |
|
46 | - } else { |
|
47 | - $current_screen = false; |
|
48 | - } |
|
44 | + if (function_exists('\get_current_screen') || function_exists('get_current_screen')) { |
|
45 | + $current_screen = \get_current_screen(); |
|
46 | + } else { |
|
47 | + $current_screen = false; |
|
48 | + } |
|
49 | 49 | |
50 | - if ($current_screen && $current_screen->post_type == 'gravityview') { |
|
51 | - if ($is_gv_edit_list = 'edit' === $current_screen->base) { |
|
52 | - $is_page = 'views'; |
|
53 | - } elseif ($is_gv_edit_single = 'post' === $current_screen->base) { |
|
54 | - $is_page = 'single'; |
|
55 | - } elseif ($is_gv_settings = 'gravityview_page_gravityview_settings' === $current_screen->id) { |
|
56 | - $is_page = 'settings'; |
|
57 | - } elseif ($is_extensions = 'gravityview_page_gv-admin-installer' === $current_screen->id) { |
|
58 | - $is_page = 'downloads'; |
|
59 | - } elseif ($is_changelog = 'gravityview_page_gv-changelog' === $current_screen->id) { |
|
60 | - $is_page = 'changelog'; |
|
61 | - } elseif ($is_getting_started = 'gravityview_page_gv-getting-started' === $current_screen->id) { |
|
62 | - $is_page = 'getting-started'; |
|
63 | - } elseif ($is_credits = 'gravityview_page_gv-credits' === $current_screen->id) { |
|
64 | - $is_page = 'credits'; |
|
65 | - } |
|
66 | - } |
|
50 | + if ($current_screen && $current_screen->post_type == 'gravityview') { |
|
51 | + if ($is_gv_edit_list = 'edit' === $current_screen->base) { |
|
52 | + $is_page = 'views'; |
|
53 | + } elseif ($is_gv_edit_single = 'post' === $current_screen->base) { |
|
54 | + $is_page = 'single'; |
|
55 | + } elseif ($is_gv_settings = 'gravityview_page_gravityview_settings' === $current_screen->id) { |
|
56 | + $is_page = 'settings'; |
|
57 | + } elseif ($is_extensions = 'gravityview_page_gv-admin-installer' === $current_screen->id) { |
|
58 | + $is_page = 'downloads'; |
|
59 | + } elseif ($is_changelog = 'gravityview_page_gv-changelog' === $current_screen->id) { |
|
60 | + $is_page = 'changelog'; |
|
61 | + } elseif ($is_getting_started = 'gravityview_page_gv-getting-started' === $current_screen->id) { |
|
62 | + $is_page = 'getting-started'; |
|
63 | + } elseif ($is_credits = 'gravityview_page_gv-credits' === $current_screen->id) { |
|
64 | + $is_page = 'credits'; |
|
65 | + } |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @filter `gravityview_is_admin_page` Is the current admin page a GravityView-related page? |
|
70 | - * |
|
71 | - * @param string|bool $is_page If false, no. If string, the name of the page (`single`, `settings`, or `views`) |
|
72 | - * @param string $hook The name of the page to check against. Is passed to the method. |
|
73 | - */ |
|
74 | - $is_page = apply_filters('gravityview_is_admin_page', $is_page, $hook); |
|
68 | + /** |
|
69 | + * @filter `gravityview_is_admin_page` Is the current admin page a GravityView-related page? |
|
70 | + * |
|
71 | + * @param string|bool $is_page If false, no. If string, the name of the page (`single`, `settings`, or `views`) |
|
72 | + * @param string $hook The name of the page to check against. Is passed to the method. |
|
73 | + */ |
|
74 | + $is_page = apply_filters('gravityview_is_admin_page', $is_page, $hook); |
|
75 | 75 | |
76 | - // If the current page is the same as the compared page |
|
77 | - if (!empty($context)) { |
|
78 | - return $is_page === $context; |
|
79 | - } |
|
76 | + // If the current page is the same as the compared page |
|
77 | + if (!empty($context)) { |
|
78 | + return $is_page === $context; |
|
79 | + } |
|
80 | 80 | |
81 | - return $is_page; |
|
82 | - } |
|
81 | + return $is_page; |
|
82 | + } |
|
83 | 83 | } |
@@ -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 | |
@@ -22,45 +22,45 @@ discard block |
||
22 | 22 | */ |
23 | 23 | public static function is_admin() |
24 | 24 | { |
25 | - if (!parent::is_admin()) { |
|
25 | + if ( ! parent::is_admin() ) { |
|
26 | 26 | return false; |
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Regular check. |
31 | 31 | */ |
32 | - if (!($args = func_get_args())) { |
|
32 | + if ( ! ( $args = func_get_args() ) ) { |
|
33 | 33 | return true; |
34 | 34 | } |
35 | 35 | |
36 | - $hook = \GV\Utils::get($args, 0, ''); |
|
37 | - $context = \GV\Utils::get($args, 1, null); |
|
36 | + $hook = \GV\Utils::get( $args, 0, '' ); |
|
37 | + $context = \GV\Utils::get( $args, 1, null ); |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Assume false by default. |
41 | 41 | */ |
42 | 42 | $is_page = false; |
43 | 43 | |
44 | - if (function_exists('\get_current_screen') || function_exists('get_current_screen')) { |
|
44 | + if ( function_exists( '\get_current_screen' ) || function_exists( 'get_current_screen' ) ) { |
|
45 | 45 | $current_screen = \get_current_screen(); |
46 | 46 | } else { |
47 | 47 | $current_screen = false; |
48 | 48 | } |
49 | 49 | |
50 | - if ($current_screen && $current_screen->post_type == 'gravityview') { |
|
51 | - if ($is_gv_edit_list = 'edit' === $current_screen->base) { |
|
50 | + if ( $current_screen && $current_screen->post_type == 'gravityview' ) { |
|
51 | + if ( $is_gv_edit_list = 'edit' === $current_screen->base ) { |
|
52 | 52 | $is_page = 'views'; |
53 | - } elseif ($is_gv_edit_single = 'post' === $current_screen->base) { |
|
53 | + } elseif ( $is_gv_edit_single = 'post' === $current_screen->base ) { |
|
54 | 54 | $is_page = 'single'; |
55 | - } elseif ($is_gv_settings = 'gravityview_page_gravityview_settings' === $current_screen->id) { |
|
55 | + } elseif ( $is_gv_settings = 'gravityview_page_gravityview_settings' === $current_screen->id ) { |
|
56 | 56 | $is_page = 'settings'; |
57 | - } elseif ($is_extensions = 'gravityview_page_gv-admin-installer' === $current_screen->id) { |
|
57 | + } elseif ( $is_extensions = 'gravityview_page_gv-admin-installer' === $current_screen->id ) { |
|
58 | 58 | $is_page = 'downloads'; |
59 | - } elseif ($is_changelog = 'gravityview_page_gv-changelog' === $current_screen->id) { |
|
59 | + } elseif ( $is_changelog = 'gravityview_page_gv-changelog' === $current_screen->id ) { |
|
60 | 60 | $is_page = 'changelog'; |
61 | - } elseif ($is_getting_started = 'gravityview_page_gv-getting-started' === $current_screen->id) { |
|
61 | + } elseif ( $is_getting_started = 'gravityview_page_gv-getting-started' === $current_screen->id ) { |
|
62 | 62 | $is_page = 'getting-started'; |
63 | - } elseif ($is_credits = 'gravityview_page_gv-credits' === $current_screen->id) { |
|
63 | + } elseif ( $is_credits = 'gravityview_page_gv-credits' === $current_screen->id ) { |
|
64 | 64 | $is_page = 'credits'; |
65 | 65 | } |
66 | 66 | } |
@@ -71,10 +71,10 @@ discard block |
||
71 | 71 | * @param string|bool $is_page If false, no. If string, the name of the page (`single`, `settings`, or `views`) |
72 | 72 | * @param string $hook The name of the page to check against. Is passed to the method. |
73 | 73 | */ |
74 | - $is_page = apply_filters('gravityview_is_admin_page', $is_page, $hook); |
|
74 | + $is_page = apply_filters( 'gravityview_is_admin_page', $is_page, $hook ); |
|
75 | 75 | |
76 | 76 | // If the current page is the same as the compared page |
77 | - if (!empty($context)) { |
|
77 | + if ( ! empty( $context ) ) { |
|
78 | 78 | return $is_page === $context; |
79 | 79 | } |
80 | 80 |
@@ -10,8 +10,7 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * The default Dashboard Request class. |
12 | 12 | */ |
13 | -class Admin_Request extends Request |
|
14 | -{ |
|
13 | +class Admin_Request extends Request { |
|
15 | 14 | /** |
16 | 15 | * Check if WordPress is_admin(), and whether we have a GravityView page. |
17 | 16 | * |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | * Accepts optional $hook and $context arguments. |
21 | 20 | * @return bool|string If `false`, not a GravityView page. `true` if $page is passed and is the same as current page. Otherwise, the name of the page (`single`, `settings`, or `views`) |
22 | 21 | */ |
23 | - public static function is_admin() |
|
24 | - { |
|
22 | + public static function is_admin() { |
|
25 | 23 | if (!parent::is_admin()) { |
26 | 24 | return false; |
27 | 25 | } |
@@ -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,191 +12,191 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Utils |
14 | 14 | { |
15 | - /** |
|
16 | - * Grab a value from the _GET superglobal or default. |
|
17 | - * |
|
18 | - * @param string $name The key name (will be prefixed). |
|
19 | - * @param mixed $default The default value if not found (Default: null) |
|
20 | - * |
|
21 | - * @return mixed The value or $default if not found. |
|
22 | - */ |
|
23 | - public static function _GET($name, $default = null) |
|
24 | - { |
|
25 | - return self::get($_GET, $name, $default); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Grab a value from the _POST superglobal or default. |
|
30 | - * |
|
31 | - * @param string $name The key name (will be prefixed). |
|
32 | - * @param mixed $default The default value if not found (Default: null) |
|
33 | - * |
|
34 | - * @return mixed The value or $default if not found. |
|
35 | - */ |
|
36 | - public static function _POST($name, $default = null) |
|
37 | - { |
|
38 | - return self::get($_POST, $name, $default); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Grab a value from the _REQUEST superglobal or default. |
|
43 | - * |
|
44 | - * @param string $name The key name (will be prefixed). |
|
45 | - * @param mixed $default The default value if not found (Default: null) |
|
46 | - * |
|
47 | - * @return mixed The value or $default if not found. |
|
48 | - */ |
|
49 | - public static function _REQUEST($name, $default = null) |
|
50 | - { |
|
51 | - return self::get($_REQUEST, $name, $default); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Grab a value from the _SERVER superglobal or default. |
|
56 | - * |
|
57 | - * @param string $name The key name (will be prefixed). |
|
58 | - * @param mixed $default The default value if not found (Default: null) |
|
59 | - * |
|
60 | - * @return mixed The value or $default if not found. |
|
61 | - */ |
|
62 | - public static function _SERVER($name, $default = null) |
|
63 | - { |
|
64 | - return self::get($_SERVER, $name, $default); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Grab a value from an array or an object or default. |
|
69 | - * |
|
70 | - * Supports nested arrays, objects via / key delimiters. |
|
71 | - * |
|
72 | - * @param array|object|mixed $array The array (or object). If not array or object, returns $default. |
|
73 | - * @param string $key The key. |
|
74 | - * @param mixed $default The default value. Default: null |
|
75 | - * |
|
76 | - * @return mixed The value or $default if not found. |
|
77 | - */ |
|
78 | - public static function get($array, $key, $default = null) |
|
79 | - { |
|
80 | - if (!is_array($array) && !is_object($array)) { |
|
81 | - return $default; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Try direct key. |
|
86 | - */ |
|
87 | - if (is_array($array) || $array instanceof \ArrayAccess) { |
|
88 | - if (isset($array[$key])) { |
|
89 | - return $array[$key]; |
|
90 | - } |
|
91 | - } elseif (is_object($array)) { |
|
92 | - if (isset($array->$key)) { |
|
93 | - return $array->$key; |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Try subkeys after split. |
|
99 | - */ |
|
100 | - if (count($parts = explode('/', $key, 2)) > 1) { |
|
101 | - return self::get(self::get($array, $parts[0]), $parts[1], $default); |
|
102 | - } |
|
103 | - |
|
104 | - return $default; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Sanitizes Excel formulas inside CSV output. |
|
109 | - * |
|
110 | - * @internal |
|
111 | - * |
|
112 | - * @since 2.1 |
|
113 | - * |
|
114 | - * @param string $value The cell value to strip formulas from. |
|
115 | - * |
|
116 | - * @return string The sanitized value. |
|
117 | - */ |
|
118 | - public static function strip_excel_formulas($value) |
|
119 | - { |
|
120 | - if (strpos($value, '=') === 0) { |
|
121 | - $value = "'".$value; |
|
122 | - } |
|
123 | - |
|
124 | - return $value; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Return a value by call. |
|
129 | - * |
|
130 | - * Use for quick hook callback returns and whatnot. |
|
131 | - * |
|
132 | - * @internal |
|
133 | - * |
|
134 | - * @since 2.1 |
|
135 | - * |
|
136 | - * @param mixed $value The value to return from the closure. |
|
137 | - * |
|
138 | - * @return Closure The closure with the $value bound. |
|
139 | - */ |
|
140 | - public static function _return($value) |
|
141 | - { |
|
142 | - return function () use ($value) { return $value; }; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * Output an associative array represenation of the query parameters. |
|
147 | - * |
|
148 | - * @internal |
|
149 | - * |
|
150 | - * @since 2.1 |
|
151 | - * |
|
152 | - * @param \GF_Query The query object to dump. |
|
153 | - * |
|
154 | - * @return array An associative array of parameters. |
|
155 | - */ |
|
156 | - public static function gf_query_debug($query) |
|
157 | - { |
|
158 | - $introspect = $query->_introspect(); |
|
159 | - |
|
160 | - return [ |
|
161 | - 'where' => $query->_where_unwrap($introspect['where']), |
|
162 | - ]; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Strips aliases in columns. |
|
167 | - * |
|
168 | - * @see https://github.com/gravityview/GravityView/issues/1308#issuecomment-617075190 |
|
169 | - * |
|
170 | - * @internal |
|
171 | - * |
|
172 | - * @since 2.8.1 |
|
173 | - * |
|
174 | - * @param \GF_Query_Condition $condition The condition to strip column aliases from. |
|
175 | - * |
|
176 | - * @return \GF_Query_Condition |
|
177 | - */ |
|
178 | - public static function gf_query_strip_condition_column_aliases($condition) |
|
179 | - { |
|
180 | - if ($condition->expressions) { |
|
181 | - $conditions = []; |
|
182 | - foreach ($condition->expressions as $expression) { |
|
183 | - $conditions[] = self::gf_query_strip_condition_column_aliases($expression); |
|
184 | - } |
|
185 | - |
|
186 | - return call_user_func_array( |
|
187 | - ['\GF_Query_Condition', $condition->operator == 'AND' ? '_and' : '_or'], |
|
188 | - $conditions |
|
189 | - ); |
|
190 | - } else { |
|
191 | - if ($condition->left instanceof \GF_Query_Column) { |
|
192 | - return new \GF_Query_Condition( |
|
193 | - new \GF_Query_Column($condition->left->field_id), |
|
194 | - $condition->operator, |
|
195 | - $condition->right |
|
196 | - ); |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - return $condition; |
|
201 | - } |
|
15 | + /** |
|
16 | + * Grab a value from the _GET superglobal or default. |
|
17 | + * |
|
18 | + * @param string $name The key name (will be prefixed). |
|
19 | + * @param mixed $default The default value if not found (Default: null) |
|
20 | + * |
|
21 | + * @return mixed The value or $default if not found. |
|
22 | + */ |
|
23 | + public static function _GET($name, $default = null) |
|
24 | + { |
|
25 | + return self::get($_GET, $name, $default); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Grab a value from the _POST superglobal or default. |
|
30 | + * |
|
31 | + * @param string $name The key name (will be prefixed). |
|
32 | + * @param mixed $default The default value if not found (Default: null) |
|
33 | + * |
|
34 | + * @return mixed The value or $default if not found. |
|
35 | + */ |
|
36 | + public static function _POST($name, $default = null) |
|
37 | + { |
|
38 | + return self::get($_POST, $name, $default); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Grab a value from the _REQUEST superglobal or default. |
|
43 | + * |
|
44 | + * @param string $name The key name (will be prefixed). |
|
45 | + * @param mixed $default The default value if not found (Default: null) |
|
46 | + * |
|
47 | + * @return mixed The value or $default if not found. |
|
48 | + */ |
|
49 | + public static function _REQUEST($name, $default = null) |
|
50 | + { |
|
51 | + return self::get($_REQUEST, $name, $default); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Grab a value from the _SERVER superglobal or default. |
|
56 | + * |
|
57 | + * @param string $name The key name (will be prefixed). |
|
58 | + * @param mixed $default The default value if not found (Default: null) |
|
59 | + * |
|
60 | + * @return mixed The value or $default if not found. |
|
61 | + */ |
|
62 | + public static function _SERVER($name, $default = null) |
|
63 | + { |
|
64 | + return self::get($_SERVER, $name, $default); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Grab a value from an array or an object or default. |
|
69 | + * |
|
70 | + * Supports nested arrays, objects via / key delimiters. |
|
71 | + * |
|
72 | + * @param array|object|mixed $array The array (or object). If not array or object, returns $default. |
|
73 | + * @param string $key The key. |
|
74 | + * @param mixed $default The default value. Default: null |
|
75 | + * |
|
76 | + * @return mixed The value or $default if not found. |
|
77 | + */ |
|
78 | + public static function get($array, $key, $default = null) |
|
79 | + { |
|
80 | + if (!is_array($array) && !is_object($array)) { |
|
81 | + return $default; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Try direct key. |
|
86 | + */ |
|
87 | + if (is_array($array) || $array instanceof \ArrayAccess) { |
|
88 | + if (isset($array[$key])) { |
|
89 | + return $array[$key]; |
|
90 | + } |
|
91 | + } elseif (is_object($array)) { |
|
92 | + if (isset($array->$key)) { |
|
93 | + return $array->$key; |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Try subkeys after split. |
|
99 | + */ |
|
100 | + if (count($parts = explode('/', $key, 2)) > 1) { |
|
101 | + return self::get(self::get($array, $parts[0]), $parts[1], $default); |
|
102 | + } |
|
103 | + |
|
104 | + return $default; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Sanitizes Excel formulas inside CSV output. |
|
109 | + * |
|
110 | + * @internal |
|
111 | + * |
|
112 | + * @since 2.1 |
|
113 | + * |
|
114 | + * @param string $value The cell value to strip formulas from. |
|
115 | + * |
|
116 | + * @return string The sanitized value. |
|
117 | + */ |
|
118 | + public static function strip_excel_formulas($value) |
|
119 | + { |
|
120 | + if (strpos($value, '=') === 0) { |
|
121 | + $value = "'".$value; |
|
122 | + } |
|
123 | + |
|
124 | + return $value; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Return a value by call. |
|
129 | + * |
|
130 | + * Use for quick hook callback returns and whatnot. |
|
131 | + * |
|
132 | + * @internal |
|
133 | + * |
|
134 | + * @since 2.1 |
|
135 | + * |
|
136 | + * @param mixed $value The value to return from the closure. |
|
137 | + * |
|
138 | + * @return Closure The closure with the $value bound. |
|
139 | + */ |
|
140 | + public static function _return($value) |
|
141 | + { |
|
142 | + return function () use ($value) { return $value; }; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * Output an associative array represenation of the query parameters. |
|
147 | + * |
|
148 | + * @internal |
|
149 | + * |
|
150 | + * @since 2.1 |
|
151 | + * |
|
152 | + * @param \GF_Query The query object to dump. |
|
153 | + * |
|
154 | + * @return array An associative array of parameters. |
|
155 | + */ |
|
156 | + public static function gf_query_debug($query) |
|
157 | + { |
|
158 | + $introspect = $query->_introspect(); |
|
159 | + |
|
160 | + return [ |
|
161 | + 'where' => $query->_where_unwrap($introspect['where']), |
|
162 | + ]; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Strips aliases in columns. |
|
167 | + * |
|
168 | + * @see https://github.com/gravityview/GravityView/issues/1308#issuecomment-617075190 |
|
169 | + * |
|
170 | + * @internal |
|
171 | + * |
|
172 | + * @since 2.8.1 |
|
173 | + * |
|
174 | + * @param \GF_Query_Condition $condition The condition to strip column aliases from. |
|
175 | + * |
|
176 | + * @return \GF_Query_Condition |
|
177 | + */ |
|
178 | + public static function gf_query_strip_condition_column_aliases($condition) |
|
179 | + { |
|
180 | + if ($condition->expressions) { |
|
181 | + $conditions = []; |
|
182 | + foreach ($condition->expressions as $expression) { |
|
183 | + $conditions[] = self::gf_query_strip_condition_column_aliases($expression); |
|
184 | + } |
|
185 | + |
|
186 | + return call_user_func_array( |
|
187 | + ['\GF_Query_Condition', $condition->operator == 'AND' ? '_and' : '_or'], |
|
188 | + $conditions |
|
189 | + ); |
|
190 | + } else { |
|
191 | + if ($condition->left instanceof \GF_Query_Column) { |
|
192 | + return new \GF_Query_Condition( |
|
193 | + new \GF_Query_Column($condition->left->field_id), |
|
194 | + $condition->operator, |
|
195 | + $condition->right |
|
196 | + ); |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + return $condition; |
|
201 | + } |
|
202 | 202 | } |
@@ -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 | |
@@ -20,9 +20,9 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @return mixed The value or $default if not found. |
22 | 22 | */ |
23 | - public static function _GET($name, $default = null) |
|
23 | + public static function _GET( $name, $default = null ) |
|
24 | 24 | { |
25 | - return self::get($_GET, $name, $default); |
|
25 | + return self::get( $_GET, $name, $default ); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return mixed The value or $default if not found. |
35 | 35 | */ |
36 | - public static function _POST($name, $default = null) |
|
36 | + public static function _POST( $name, $default = null ) |
|
37 | 37 | { |
38 | - return self::get($_POST, $name, $default); |
|
38 | + return self::get( $_POST, $name, $default ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | * |
47 | 47 | * @return mixed The value or $default if not found. |
48 | 48 | */ |
49 | - public static function _REQUEST($name, $default = null) |
|
49 | + public static function _REQUEST( $name, $default = null ) |
|
50 | 50 | { |
51 | - return self::get($_REQUEST, $name, $default); |
|
51 | + return self::get( $_REQUEST, $name, $default ); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @return mixed The value or $default if not found. |
61 | 61 | */ |
62 | - public static function _SERVER($name, $default = null) |
|
62 | + public static function _SERVER( $name, $default = null ) |
|
63 | 63 | { |
64 | - return self::get($_SERVER, $name, $default); |
|
64 | + return self::get( $_SERVER, $name, $default ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -75,21 +75,21 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return mixed The value or $default if not found. |
77 | 77 | */ |
78 | - public static function get($array, $key, $default = null) |
|
78 | + public static function get( $array, $key, $default = null ) |
|
79 | 79 | { |
80 | - if (!is_array($array) && !is_object($array)) { |
|
80 | + if ( ! is_array( $array ) && ! is_object( $array ) ) { |
|
81 | 81 | return $default; |
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Try direct key. |
86 | 86 | */ |
87 | - if (is_array($array) || $array instanceof \ArrayAccess) { |
|
88 | - if (isset($array[$key])) { |
|
89 | - return $array[$key]; |
|
87 | + if ( is_array( $array ) || $array instanceof \ArrayAccess ) { |
|
88 | + if ( isset( $array[ $key ] ) ) { |
|
89 | + return $array[ $key ]; |
|
90 | 90 | } |
91 | - } elseif (is_object($array)) { |
|
92 | - if (isset($array->$key)) { |
|
91 | + } elseif ( is_object( $array ) ) { |
|
92 | + if ( isset( $array->$key ) ) { |
|
93 | 93 | return $array->$key; |
94 | 94 | } |
95 | 95 | } |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | /** |
98 | 98 | * Try subkeys after split. |
99 | 99 | */ |
100 | - if (count($parts = explode('/', $key, 2)) > 1) { |
|
101 | - return self::get(self::get($array, $parts[0]), $parts[1], $default); |
|
100 | + if ( count( $parts = explode( '/', $key, 2 ) ) > 1 ) { |
|
101 | + return self::get( self::get( $array, $parts[ 0 ] ), $parts[ 1 ], $default ); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | return $default; |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return string The sanitized value. |
117 | 117 | */ |
118 | - public static function strip_excel_formulas($value) |
|
118 | + public static function strip_excel_formulas( $value ) |
|
119 | 119 | { |
120 | - if (strpos($value, '=') === 0) { |
|
121 | - $value = "'".$value; |
|
120 | + if ( strpos( $value, '=' ) === 0 ) { |
|
121 | + $value = "'" . $value; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | return $value; |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | * |
138 | 138 | * @return Closure The closure with the $value bound. |
139 | 139 | */ |
140 | - public static function _return($value) |
|
140 | + public static function _return( $value ) |
|
141 | 141 | { |
142 | - return function () use ($value) { return $value; }; |
|
142 | + return function() use ( $value ) { return $value; }; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | /** |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @return array An associative array of parameters. |
155 | 155 | */ |
156 | - public static function gf_query_debug($query) |
|
156 | + public static function gf_query_debug( $query ) |
|
157 | 157 | { |
158 | 158 | $introspect = $query->_introspect(); |
159 | 159 | |
160 | 160 | return [ |
161 | - 'where' => $query->_where_unwrap($introspect['where']), |
|
161 | + 'where' => $query->_where_unwrap( $introspect[ 'where' ] ), |
|
162 | 162 | ]; |
163 | 163 | } |
164 | 164 | |
@@ -175,22 +175,22 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @return \GF_Query_Condition |
177 | 177 | */ |
178 | - public static function gf_query_strip_condition_column_aliases($condition) |
|
178 | + public static function gf_query_strip_condition_column_aliases( $condition ) |
|
179 | 179 | { |
180 | - if ($condition->expressions) { |
|
181 | - $conditions = []; |
|
182 | - foreach ($condition->expressions as $expression) { |
|
183 | - $conditions[] = self::gf_query_strip_condition_column_aliases($expression); |
|
180 | + if ( $condition->expressions ) { |
|
181 | + $conditions = [ ]; |
|
182 | + foreach ( $condition->expressions as $expression ) { |
|
183 | + $conditions[ ] = self::gf_query_strip_condition_column_aliases( $expression ); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | return call_user_func_array( |
187 | - ['\GF_Query_Condition', $condition->operator == 'AND' ? '_and' : '_or'], |
|
187 | + [ '\GF_Query_Condition', $condition->operator == 'AND' ? '_and' : '_or' ], |
|
188 | 188 | $conditions |
189 | 189 | ); |
190 | 190 | } else { |
191 | - if ($condition->left instanceof \GF_Query_Column) { |
|
191 | + if ( $condition->left instanceof \GF_Query_Column ) { |
|
192 | 192 | return new \GF_Query_Condition( |
193 | - new \GF_Query_Column($condition->left->field_id), |
|
193 | + new \GF_Query_Column( $condition->left->field_id ), |
|
194 | 194 | $condition->operator, |
195 | 195 | $condition->right |
196 | 196 | ); |
@@ -10,8 +10,7 @@ discard block |
||
10 | 10 | /** |
11 | 11 | * Generic utilities. |
12 | 12 | */ |
13 | -class Utils |
|
14 | -{ |
|
13 | +class Utils { |
|
15 | 14 | /** |
16 | 15 | * Grab a value from the _GET superglobal or default. |
17 | 16 | * |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | * |
21 | 20 | * @return mixed The value or $default if not found. |
22 | 21 | */ |
23 | - public static function _GET($name, $default = null) |
|
24 | - { |
|
22 | + public static function _GET($name, $default = null) { |
|
25 | 23 | return self::get($_GET, $name, $default); |
26 | 24 | } |
27 | 25 | |
@@ -33,8 +31,7 @@ discard block |
||
33 | 31 | * |
34 | 32 | * @return mixed The value or $default if not found. |
35 | 33 | */ |
36 | - public static function _POST($name, $default = null) |
|
37 | - { |
|
34 | + public static function _POST($name, $default = null) { |
|
38 | 35 | return self::get($_POST, $name, $default); |
39 | 36 | } |
40 | 37 | |
@@ -46,8 +43,7 @@ discard block |
||
46 | 43 | * |
47 | 44 | * @return mixed The value or $default if not found. |
48 | 45 | */ |
49 | - public static function _REQUEST($name, $default = null) |
|
50 | - { |
|
46 | + public static function _REQUEST($name, $default = null) { |
|
51 | 47 | return self::get($_REQUEST, $name, $default); |
52 | 48 | } |
53 | 49 | |
@@ -59,8 +55,7 @@ discard block |
||
59 | 55 | * |
60 | 56 | * @return mixed The value or $default if not found. |
61 | 57 | */ |
62 | - public static function _SERVER($name, $default = null) |
|
63 | - { |
|
58 | + public static function _SERVER($name, $default = null) { |
|
64 | 59 | return self::get($_SERVER, $name, $default); |
65 | 60 | } |
66 | 61 | |
@@ -75,8 +70,7 @@ discard block |
||
75 | 70 | * |
76 | 71 | * @return mixed The value or $default if not found. |
77 | 72 | */ |
78 | - public static function get($array, $key, $default = null) |
|
79 | - { |
|
73 | + public static function get($array, $key, $default = null) { |
|
80 | 74 | if (!is_array($array) && !is_object($array)) { |
81 | 75 | return $default; |
82 | 76 | } |
@@ -115,8 +109,7 @@ discard block |
||
115 | 109 | * |
116 | 110 | * @return string The sanitized value. |
117 | 111 | */ |
118 | - public static function strip_excel_formulas($value) |
|
119 | - { |
|
112 | + public static function strip_excel_formulas($value) { |
|
120 | 113 | if (strpos($value, '=') === 0) { |
121 | 114 | $value = "'".$value; |
122 | 115 | } |
@@ -137,8 +130,7 @@ discard block |
||
137 | 130 | * |
138 | 131 | * @return Closure The closure with the $value bound. |
139 | 132 | */ |
140 | - public static function _return($value) |
|
141 | - { |
|
133 | + public static function _return($value) { |
|
142 | 134 | return function () use ($value) { return $value; }; |
143 | 135 | } |
144 | 136 | |
@@ -153,8 +145,7 @@ discard block |
||
153 | 145 | * |
154 | 146 | * @return array An associative array of parameters. |
155 | 147 | */ |
156 | - public static function gf_query_debug($query) |
|
157 | - { |
|
148 | + public static function gf_query_debug($query) { |
|
158 | 149 | $introspect = $query->_introspect(); |
159 | 150 | |
160 | 151 | return [ |
@@ -175,8 +166,7 @@ discard block |
||
175 | 166 | * |
176 | 167 | * @return \GF_Query_Condition |
177 | 168 | */ |
178 | - public static function gf_query_strip_condition_column_aliases($condition) |
|
179 | - { |
|
169 | + public static function gf_query_strip_condition_column_aliases($condition) { |
|
180 | 170 | if ($condition->expressions) { |
181 | 171 | $conditions = []; |
182 | 172 | foreach ($condition->expressions as $expression) { |
@@ -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,36 +14,36 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Internal_Source extends Source |
16 | 16 | { |
17 | - /** |
|
18 | - * @var string The identifier of the backend used for this source. |
|
19 | - * |
|
20 | - * @api |
|
21 | - * |
|
22 | - * @since 2.0 |
|
23 | - */ |
|
24 | - public static $backend = self::BACKEND_INTERNAL; |
|
25 | - |
|
26 | - /** |
|
27 | - * Get a \GV\Field by Field ID for this data source. |
|
28 | - * |
|
29 | - * @param int $field_id The internal field ID (custom content, etc.) |
|
30 | - * |
|
31 | - * @return \GV\Field|null The requested field or null if not found. |
|
32 | - */ |
|
33 | - public static function get_field(/** varargs */) |
|
34 | - { |
|
35 | - $args = func_get_args(); |
|
36 | - |
|
37 | - if (!is_array($args) || count($args) != 1) { |
|
38 | - gravityview()->log->error('{source} expects 1 arguments for ::get_field ($field_id)', ['source' => __CLASS__]); |
|
39 | - |
|
40 | - return null; |
|
41 | - } |
|
42 | - |
|
43 | - /** Unwrap the arguments. */ |
|
44 | - list($field_id) = $args; |
|
45 | - |
|
46 | - /** Wrap it up into a \GV\Field. */ |
|
47 | - return \GV\Internal_Field::by_id($field_id); |
|
48 | - } |
|
17 | + /** |
|
18 | + * @var string The identifier of the backend used for this source. |
|
19 | + * |
|
20 | + * @api |
|
21 | + * |
|
22 | + * @since 2.0 |
|
23 | + */ |
|
24 | + public static $backend = self::BACKEND_INTERNAL; |
|
25 | + |
|
26 | + /** |
|
27 | + * Get a \GV\Field by Field ID for this data source. |
|
28 | + * |
|
29 | + * @param int $field_id The internal field ID (custom content, etc.) |
|
30 | + * |
|
31 | + * @return \GV\Field|null The requested field or null if not found. |
|
32 | + */ |
|
33 | + public static function get_field(/** varargs */) |
|
34 | + { |
|
35 | + $args = func_get_args(); |
|
36 | + |
|
37 | + if (!is_array($args) || count($args) != 1) { |
|
38 | + gravityview()->log->error('{source} expects 1 arguments for ::get_field ($field_id)', ['source' => __CLASS__]); |
|
39 | + |
|
40 | + return null; |
|
41 | + } |
|
42 | + |
|
43 | + /** Unwrap the arguments. */ |
|
44 | + list($field_id) = $args; |
|
45 | + |
|
46 | + /** Wrap it up into a \GV\Field. */ |
|
47 | + return \GV\Internal_Field::by_id($field_id); |
|
48 | + } |
|
49 | 49 | } |
@@ -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 | |
@@ -30,20 +30,20 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return \GV\Field|null The requested field or null if not found. |
32 | 32 | */ |
33 | - public static function get_field(/** varargs */) |
|
33 | + public static function get_field( /** varargs */ ) |
|
34 | 34 | { |
35 | 35 | $args = func_get_args(); |
36 | 36 | |
37 | - if (!is_array($args) || count($args) != 1) { |
|
38 | - gravityview()->log->error('{source} expects 1 arguments for ::get_field ($field_id)', ['source' => __CLASS__]); |
|
37 | + if ( ! is_array( $args ) || count( $args ) != 1 ) { |
|
38 | + gravityview()->log->error( '{source} expects 1 arguments for ::get_field ($field_id)', [ 'source' => __CLASS__ ] ); |
|
39 | 39 | |
40 | 40 | return null; |
41 | 41 | } |
42 | 42 | |
43 | 43 | /** Unwrap the arguments. */ |
44 | - list($field_id) = $args; |
|
44 | + list( $field_id ) = $args; |
|
45 | 45 | |
46 | 46 | /** Wrap it up into a \GV\Field. */ |
47 | - return \GV\Internal_Field::by_id($field_id); |
|
47 | + return \GV\Internal_Field::by_id( $field_id ); |
|
48 | 48 | } |
49 | 49 | } |
@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * Data that comes from within the View itself (like custom content). |
14 | 14 | */ |
15 | -class Internal_Source extends Source |
|
16 | -{ |
|
15 | +class Internal_Source extends Source { |
|
17 | 16 | /** |
18 | 17 | * @var string The identifier of the backend used for this source. |
19 | 18 | * |
@@ -30,8 +29,7 @@ discard block |
||
30 | 29 | * |
31 | 30 | * @return \GV\Field|null The requested field or null if not found. |
32 | 31 | */ |
33 | - public static function get_field(/** varargs */) |
|
34 | - { |
|
32 | + public static function get_field(/** varargs */) { |
|
35 | 33 | $args = func_get_args(); |
36 | 34 | |
37 | 35 | if (!is_array($args) || count($args) != 1) { |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | /** If this file is called directly, abort. */ |
4 | 4 | if (!defined('GRAVITYVIEW_DIR')) { |
5 | - exit(); |
|
5 | + exit(); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | /** |
@@ -12,75 +12,75 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GravityView_Powered_By |
14 | 14 | { |
15 | - const url = 'https://gravityview.co/powered-by/'; |
|
16 | - |
|
17 | - /** |
|
18 | - * GravityView_Powered_By constructor. |
|
19 | - */ |
|
20 | - public function __construct() |
|
21 | - { |
|
22 | - add_action('gravityview/template/after', [$this, 'maybe_add_link']); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Prints a HTML link to GravityView's site if "Powered By" GravityView setting is enabled. |
|
27 | - * |
|
28 | - * @return void |
|
29 | - */ |
|
30 | - public function maybe_add_link() |
|
31 | - { |
|
32 | - $powered_by = gravityview()->plugin->settings->get('powered_by', '0'); |
|
33 | - |
|
34 | - if (empty($powered_by)) { |
|
35 | - return; |
|
36 | - } |
|
37 | - |
|
38 | - $url = $this->get_url(); |
|
39 | - |
|
40 | - // Allow disabling link via URL filter |
|
41 | - if (empty($url)) { |
|
42 | - return; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @filter `gravityview/powered_by/text` Modify the anchor text for the Powered By link |
|
47 | - * |
|
48 | - * @param string $anchor_text Anchor text for the Powered By link. Default: "Powered by GravityView". Will be sanitized before display. |
|
49 | - */ |
|
50 | - $anchor_text = apply_filters('gravityview/powered_by/text', __('Powered by GravityView', 'gravityview')); |
|
51 | - |
|
52 | - printf('<span class="gv-powered-by"><a href="%s">%s</a></span>', esc_url($url), esc_html($anchor_text)); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Returns the URL to GravityView. |
|
57 | - * |
|
58 | - * @return string URL to GravityView (not sanitized) |
|
59 | - */ |
|
60 | - protected function get_url() |
|
61 | - { |
|
62 | - $url = sprintf(self::url, get_bloginfo('name')); |
|
63 | - |
|
64 | - $affiliate_id = gravityview()->plugin->settings->get('affiliate_id', ''); |
|
65 | - |
|
66 | - if ($affiliate_id && is_numeric($affiliate_id)) { |
|
67 | - $url = add_query_arg(['ref' => $affiliate_id], $url); |
|
68 | - } |
|
69 | - |
|
70 | - $url = add_query_arg([ |
|
71 | - 'utm_source' => 'powered_by', |
|
72 | - 'utm_term' => get_bloginfo('name'), |
|
73 | - ], $url); |
|
74 | - |
|
75 | - /** |
|
76 | - * @filter `gravityview/powered_by/url` Modify the URL returned by the Powered By link |
|
77 | - * |
|
78 | - * @param $url string The URL passed to the Powered By link |
|
79 | - */ |
|
80 | - $url = apply_filters('gravityview/powered_by/url', $url); |
|
81 | - |
|
82 | - return $url; |
|
83 | - } |
|
15 | + const url = 'https://gravityview.co/powered-by/'; |
|
16 | + |
|
17 | + /** |
|
18 | + * GravityView_Powered_By constructor. |
|
19 | + */ |
|
20 | + public function __construct() |
|
21 | + { |
|
22 | + add_action('gravityview/template/after', [$this, 'maybe_add_link']); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Prints a HTML link to GravityView's site if "Powered By" GravityView setting is enabled. |
|
27 | + * |
|
28 | + * @return void |
|
29 | + */ |
|
30 | + public function maybe_add_link() |
|
31 | + { |
|
32 | + $powered_by = gravityview()->plugin->settings->get('powered_by', '0'); |
|
33 | + |
|
34 | + if (empty($powered_by)) { |
|
35 | + return; |
|
36 | + } |
|
37 | + |
|
38 | + $url = $this->get_url(); |
|
39 | + |
|
40 | + // Allow disabling link via URL filter |
|
41 | + if (empty($url)) { |
|
42 | + return; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @filter `gravityview/powered_by/text` Modify the anchor text for the Powered By link |
|
47 | + * |
|
48 | + * @param string $anchor_text Anchor text for the Powered By link. Default: "Powered by GravityView". Will be sanitized before display. |
|
49 | + */ |
|
50 | + $anchor_text = apply_filters('gravityview/powered_by/text', __('Powered by GravityView', 'gravityview')); |
|
51 | + |
|
52 | + printf('<span class="gv-powered-by"><a href="%s">%s</a></span>', esc_url($url), esc_html($anchor_text)); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Returns the URL to GravityView. |
|
57 | + * |
|
58 | + * @return string URL to GravityView (not sanitized) |
|
59 | + */ |
|
60 | + protected function get_url() |
|
61 | + { |
|
62 | + $url = sprintf(self::url, get_bloginfo('name')); |
|
63 | + |
|
64 | + $affiliate_id = gravityview()->plugin->settings->get('affiliate_id', ''); |
|
65 | + |
|
66 | + if ($affiliate_id && is_numeric($affiliate_id)) { |
|
67 | + $url = add_query_arg(['ref' => $affiliate_id], $url); |
|
68 | + } |
|
69 | + |
|
70 | + $url = add_query_arg([ |
|
71 | + 'utm_source' => 'powered_by', |
|
72 | + 'utm_term' => get_bloginfo('name'), |
|
73 | + ], $url); |
|
74 | + |
|
75 | + /** |
|
76 | + * @filter `gravityview/powered_by/url` Modify the URL returned by the Powered By link |
|
77 | + * |
|
78 | + * @param $url string The URL passed to the Powered By link |
|
79 | + */ |
|
80 | + $url = apply_filters('gravityview/powered_by/url', $url); |
|
81 | + |
|
82 | + return $url; |
|
83 | + } |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | new GravityView_Powered_By(); |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** If this file is called directly, abort. */ |
4 | -if (!defined('GRAVITYVIEW_DIR')) { |
|
4 | +if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
5 | 5 | exit(); |
6 | 6 | } |
7 | 7 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function __construct() |
21 | 21 | { |
22 | - add_action('gravityview/template/after', [$this, 'maybe_add_link']); |
|
22 | + add_action( 'gravityview/template/after', [ $this, 'maybe_add_link' ] ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -29,16 +29,16 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function maybe_add_link() |
31 | 31 | { |
32 | - $powered_by = gravityview()->plugin->settings->get('powered_by', '0'); |
|
32 | + $powered_by = gravityview()->plugin->settings->get( 'powered_by', '0' ); |
|
33 | 33 | |
34 | - if (empty($powered_by)) { |
|
34 | + if ( empty( $powered_by ) ) { |
|
35 | 35 | return; |
36 | 36 | } |
37 | 37 | |
38 | 38 | $url = $this->get_url(); |
39 | 39 | |
40 | 40 | // Allow disabling link via URL filter |
41 | - if (empty($url)) { |
|
41 | + if ( empty( $url ) ) { |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param string $anchor_text Anchor text for the Powered By link. Default: "Powered by GravityView". Will be sanitized before display. |
49 | 49 | */ |
50 | - $anchor_text = apply_filters('gravityview/powered_by/text', __('Powered by GravityView', 'gravityview')); |
|
50 | + $anchor_text = apply_filters( 'gravityview/powered_by/text', __( 'Powered by GravityView', 'gravityview' ) ); |
|
51 | 51 | |
52 | - printf('<span class="gv-powered-by"><a href="%s">%s</a></span>', esc_url($url), esc_html($anchor_text)); |
|
52 | + printf( '<span class="gv-powered-by"><a href="%s">%s</a></span>', esc_url( $url ), esc_html( $anchor_text ) ); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -59,25 +59,25 @@ discard block |
||
59 | 59 | */ |
60 | 60 | protected function get_url() |
61 | 61 | { |
62 | - $url = sprintf(self::url, get_bloginfo('name')); |
|
62 | + $url = sprintf( self::url, get_bloginfo( 'name' ) ); |
|
63 | 63 | |
64 | - $affiliate_id = gravityview()->plugin->settings->get('affiliate_id', ''); |
|
64 | + $affiliate_id = gravityview()->plugin->settings->get( 'affiliate_id', '' ); |
|
65 | 65 | |
66 | - if ($affiliate_id && is_numeric($affiliate_id)) { |
|
67 | - $url = add_query_arg(['ref' => $affiliate_id], $url); |
|
66 | + if ( $affiliate_id && is_numeric( $affiliate_id ) ) { |
|
67 | + $url = add_query_arg( [ 'ref' => $affiliate_id ], $url ); |
|
68 | 68 | } |
69 | 69 | |
70 | - $url = add_query_arg([ |
|
70 | + $url = add_query_arg( [ |
|
71 | 71 | 'utm_source' => 'powered_by', |
72 | - 'utm_term' => get_bloginfo('name'), |
|
73 | - ], $url); |
|
72 | + 'utm_term' => get_bloginfo( 'name' ), |
|
73 | + ], $url ); |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * @filter `gravityview/powered_by/url` Modify the URL returned by the Powered By link |
77 | 77 | * |
78 | 78 | * @param $url string The URL passed to the Powered By link |
79 | 79 | */ |
80 | - $url = apply_filters('gravityview/powered_by/url', $url); |
|
80 | + $url = apply_filters( 'gravityview/powered_by/url', $url ); |
|
81 | 81 | |
82 | 82 | return $url; |
83 | 83 | } |
@@ -10,15 +10,13 @@ discard block |
||
10 | 10 | * |
11 | 11 | * @since 2.5.3 |
12 | 12 | */ |
13 | -class GravityView_Powered_By |
|
14 | -{ |
|
13 | +class GravityView_Powered_By { |
|
15 | 14 | const url = 'https://gravityview.co/powered-by/'; |
16 | 15 | |
17 | 16 | /** |
18 | 17 | * GravityView_Powered_By constructor. |
19 | 18 | */ |
20 | - public function __construct() |
|
21 | - { |
|
19 | + public function __construct() { |
|
22 | 20 | add_action('gravityview/template/after', [$this, 'maybe_add_link']); |
23 | 21 | } |
24 | 22 | |
@@ -27,8 +25,7 @@ discard block |
||
27 | 25 | * |
28 | 26 | * @return void |
29 | 27 | */ |
30 | - public function maybe_add_link() |
|
31 | - { |
|
28 | + public function maybe_add_link() { |
|
32 | 29 | $powered_by = gravityview()->plugin->settings->get('powered_by', '0'); |
33 | 30 | |
34 | 31 | if (empty($powered_by)) { |
@@ -57,8 +54,7 @@ discard block |
||
57 | 54 | * |
58 | 55 | * @return string URL to GravityView (not sanitized) |
59 | 56 | */ |
60 | - protected function get_url() |
|
61 | - { |
|
57 | + protected function get_url() { |
|
62 | 58 | $url = sprintf(self::url, get_bloginfo('name')); |
63 | 59 | |
64 | 60 | $affiliate_id = gravityview()->plugin->settings->get('affiliate_id', ''); |
@@ -13,304 +13,304 @@ |
||
13 | 13 | */ |
14 | 14 | class GravityView_Migrate |
15 | 15 | { |
16 | - public function __construct() |
|
17 | - { |
|
18 | - add_action('admin_init', [$this, 'update_settings'], 1); |
|
19 | - } |
|
20 | - |
|
21 | - public function update_settings() |
|
22 | - { |
|
23 | - $this->maybe_migrate_search_widget(); |
|
24 | - |
|
25 | - $this->migrate_redux_settings(); |
|
26 | - |
|
27 | - $this->maybe_migrate_approved_meta(); |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Convert approval meta values to enumerated values. |
|
32 | - * |
|
33 | - * @since 1.18 |
|
34 | - */ |
|
35 | - private function maybe_migrate_approved_meta() |
|
36 | - { |
|
37 | - |
|
38 | - // check if search migration is already performed |
|
39 | - $is_updated = get_option('gv_migrated_approved_meta'); |
|
40 | - |
|
41 | - if ($is_updated) { |
|
42 | - return; |
|
43 | - } |
|
44 | - |
|
45 | - $this->update_approved_meta(); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Convert "Approved" approval status to "1". |
|
50 | - * |
|
51 | - * @since 1.18 |
|
52 | - * |
|
53 | - * @return void |
|
54 | - */ |
|
55 | - private function update_approved_meta() |
|
56 | - { |
|
57 | - global $wpdb; |
|
58 | - |
|
59 | - if (!class_exists('GFFormsModel')) { |
|
60 | - gravityview()->log->error('GFFormsModel does not exist.'); |
|
61 | - |
|
62 | - return; |
|
63 | - } |
|
64 | - |
|
65 | - if (version_compare(GFFormsModel::get_database_version(), '2.3-dev-1', '>=')) { |
|
66 | - $table_name = GFFormsModel::get_entry_meta_table_name(); |
|
67 | - } else { |
|
68 | - $table_name = GFFormsModel::get_lead_meta_table_name(); |
|
69 | - } |
|
70 | - |
|
71 | - $sql = "UPDATE {$table_name} SET `meta_value` = %s WHERE `meta_key` = 'is_approved' AND `meta_value` = %s"; |
|
72 | - |
|
73 | - $approved_result = $wpdb->query($wpdb->prepare($sql, GravityView_Entry_Approval_Status::APPROVED, 'Approved')); |
|
74 | - |
|
75 | - $disapproved_result = $wpdb->query($wpdb->prepare($sql, GravityView_Entry_Approval_Status::DISAPPROVED, '0')); |
|
76 | - |
|
77 | - if (false === $approved_result || false === $disapproved_result) { |
|
78 | - gravityview()->log->error('There was an error processing the query. {error}', ['error' => $wpdb->last_error]); |
|
79 | - } else { |
|
80 | - // All done: Meta values are migrated |
|
81 | - update_option('gv_migrated_approved_meta', true); |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @since 1.7.4 |
|
87 | - */ |
|
88 | - private function maybe_migrate_search_widget() |
|
89 | - { |
|
90 | - |
|
91 | - // check if search migration is already performed |
|
92 | - $is_updated = get_option('gv_migrate_searchwidget'); |
|
93 | - if ($is_updated) { |
|
94 | - return; |
|
95 | - } else { |
|
96 | - $this->update_search_on_views(); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Set app settings from prior Redux settings, if exists. |
|
102 | - * |
|
103 | - * @since 1.7.4 |
|
104 | - * |
|
105 | - * @return mixed|void |
|
106 | - */ |
|
107 | - private function migrate_redux_settings() |
|
108 | - { |
|
109 | - $redux_settings = $this->get_redux_settings(); |
|
110 | - |
|
111 | - // No need to process |
|
112 | - if (false === $redux_settings) { |
|
113 | - return; |
|
114 | - } |
|
115 | - |
|
116 | - if (empty($redux_settings['license_key_status'])) { |
|
117 | - $redux_settings = $this->get_redux_license_status($redux_settings); |
|
118 | - } |
|
119 | - |
|
120 | - // Get the current app settings (just defaults) |
|
121 | - $current = gravityview()->plugin->settings->all(); |
|
122 | - |
|
123 | - // Merge the redux settings with the defaults |
|
124 | - $updated_settings = wp_parse_args($redux_settings, $current); |
|
125 | - |
|
126 | - // Update the defaults to the new merged |
|
127 | - gravityview()->plugin->settings->update($updated_settings); |
|
128 | - |
|
129 | - // And now remove the previous option, so this is a one-time thing. |
|
130 | - delete_option('gravityview_settings'); |
|
131 | - delete_option('gravityview_settings-transients'); |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * If the settings transient wasn't set, we need to set the default status for the license. |
|
136 | - * |
|
137 | - * @since 1.7.4 |
|
138 | - * |
|
139 | - * @param array $redux_settings |
|
140 | - * |
|
141 | - * @return array |
|
142 | - */ |
|
143 | - public function get_redux_license_status($redux_settings = []) |
|
144 | - { |
|
145 | - $data = [ |
|
146 | - 'edd_action' => 'check_license', |
|
147 | - 'license' => \GV\Utils::_GET('license_key', \GV\Utils::get($redux_settings, 'license_key')), |
|
148 | - 'update' => false, |
|
149 | - 'format' => 'object', |
|
150 | - ]; |
|
151 | - |
|
152 | - $license_call = \GV\License_Handler::get()->license_call($data); |
|
153 | - |
|
154 | - if (is_object($license_call) && isset($license_call->license)) { |
|
155 | - $redux_settings['license_key_status'] = $license_call->license; |
|
156 | - $redux_settings['license_key_response'] = json_encode($license_call); |
|
157 | - } |
|
158 | - |
|
159 | - return $redux_settings; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Get Redux settings, if they exist. |
|
164 | - * |
|
165 | - * @since 1.7.4 |
|
166 | - * |
|
167 | - * @return array|bool |
|
168 | - */ |
|
169 | - public function get_redux_settings() |
|
170 | - { |
|
171 | - |
|
172 | - // Previous settings set by Redux |
|
173 | - $redux_option = get_option('gravityview_settings'); |
|
174 | - |
|
175 | - // No Redux settings? Don't proceed. |
|
176 | - if (false === $redux_option) { |
|
177 | - return false; |
|
178 | - } |
|
179 | - |
|
180 | - $redux_settings = [ |
|
181 | - 'support-email' => \GV\Utils::get($redux_option, 'support-email'), |
|
182 | - 'no-conflict-mode' => \GV\Utils::get($redux_option, 'no-conflict-mode') ? '1' : '0', |
|
183 | - ]; |
|
184 | - |
|
185 | - if ($license_array = \GV\Utils::get($redux_option, 'license')) { |
|
186 | - $redux_settings['license_key'] = $license_key = \GV\Utils::get($license_array, 'license'); |
|
187 | - |
|
188 | - $redux_last_changed_values = get_option('gravityview_settings-transients'); |
|
189 | - |
|
190 | - // This contains the last response for license validation |
|
191 | - if (!empty($redux_last_changed_values) && $saved_values = \GV\Utils::get($redux_last_changed_values, 'changed_values')) { |
|
192 | - $saved_license = \GV\Utils::get($saved_values, 'license'); |
|
193 | - |
|
194 | - // Only use the last-saved values if they are for the same license |
|
195 | - if ($saved_license && \GV\Utils::get($saved_license, 'license') === $license_key) { |
|
196 | - $redux_settings['license_key_status'] = \GV\Utils::get($saved_license, 'status'); |
|
197 | - $redux_settings['license_key_response'] = \GV\Utils::get($saved_license, 'response'); |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - return $redux_settings; |
|
203 | - } |
|
204 | - |
|
205 | - /** ---- Migrate from old search widget to new search widget ---- */ |
|
206 | - public function update_search_on_views() |
|
207 | - { |
|
208 | - if (!class_exists('GravityView_Widget_Search')) { |
|
209 | - include_once GRAVITYVIEW_DIR.'includes/extensions/search-widget/class-search-widget.php'; |
|
210 | - } |
|
211 | - |
|
212 | - // Loop through all the views |
|
213 | - $query_args = [ |
|
214 | - 'post_type' => 'gravityview', |
|
215 | - 'post_status' => 'any', |
|
216 | - 'posts_per_page' => -1, |
|
217 | - ]; |
|
218 | - |
|
219 | - $views = get_posts($query_args); |
|
220 | - |
|
221 | - foreach ($views as $view) { |
|
222 | - $widgets = gravityview_get_directory_widgets($view->ID); |
|
223 | - $search_fields = null; |
|
224 | - |
|
225 | - if (empty($widgets) || !is_array($widgets)) { |
|
226 | - continue; |
|
227 | - } |
|
228 | - |
|
229 | - gravityview()->log->debug('[GravityView_Migrate/update_search_on_views] Loading View ID: {view_id}', ['view_id' => $view->ID]); |
|
230 | - |
|
231 | - foreach ($widgets as $area => $ws) { |
|
232 | - foreach ($ws as $k => $widget) { |
|
233 | - if ($widget['id'] !== 'search_bar') { |
|
234 | - continue; |
|
235 | - } |
|
236 | - |
|
237 | - if (is_null($search_fields)) { |
|
238 | - $search_fields = $this->get_search_fields($view->ID); |
|
239 | - } |
|
240 | - |
|
241 | - // check widget settings: |
|
242 | - // [search_free] => 1 |
|
243 | - // [search_date] => 1 |
|
244 | - $search_generic = []; |
|
245 | - if (!empty($widget['search_free'])) { |
|
246 | - $search_generic[] = ['field' => 'search_all', 'input' => 'input_text']; |
|
247 | - } |
|
248 | - if (!empty($widget['search_date'])) { |
|
249 | - $search_generic[] = ['field' => 'entry_date', 'input' => 'date']; |
|
250 | - } |
|
251 | - |
|
252 | - $search_config = array_merge($search_generic, $search_fields); |
|
253 | - |
|
254 | - // don't throw '[]' when json_encode an empty array |
|
255 | - if (empty($search_config)) { |
|
256 | - $search_config = ''; |
|
257 | - } else { |
|
258 | - $search_config = json_encode($search_config); |
|
259 | - } |
|
260 | - |
|
261 | - $widgets[$area][$k]['search_fields'] = $search_config; |
|
262 | - $widgets[$area][$k]['search_layout'] = 'horizontal'; |
|
263 | - |
|
264 | - gravityview()->log->debug('[GravityView_Migrate/update_search_on_views] Updated Widget: ', ['data' => $widgets[$area][$k]]); |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - // update widgets view |
|
269 | - gravityview_set_directory_widgets($view->ID, $widgets); |
|
270 | - } // foreach Views |
|
271 | - |
|
272 | - // all done! enjoy the new Search Widget! |
|
273 | - update_option('gv_migrate_searchwidget', true); |
|
274 | - |
|
275 | - gravityview()->log->debug('[GravityView_Migrate/update_search_on_views] All done! enjoy the new Search Widget!'); |
|
276 | - } |
|
277 | - |
|
278 | - public function get_search_fields($view_id) |
|
279 | - { |
|
280 | - $form_id = gravityview_get_form_id($view_id); |
|
281 | - $form = gravityview_get_form($form_id); |
|
282 | - |
|
283 | - $search_fields = []; |
|
284 | - |
|
285 | - // check view fields' settings |
|
286 | - $fields = gravityview_get_directory_fields($view_id, false); |
|
287 | - |
|
288 | - if (!empty($fields) && is_array($fields)) { |
|
289 | - foreach ($fields as $t => $fs) { |
|
290 | - foreach ($fs as $k => $field) { |
|
291 | - // is field a search_filter ? |
|
292 | - if (empty($field['search_filter'])) { |
|
293 | - continue; |
|
294 | - } |
|
295 | - |
|
296 | - // get field type & calculate the input type (by default) |
|
297 | - $form_field = gravityview_get_field($form, $field['id']); |
|
298 | - |
|
299 | - if (empty($form_field['type'])) { |
|
300 | - continue; |
|
301 | - } |
|
302 | - |
|
303 | - // depending on the field type assign a group of possible search field types |
|
304 | - $type = GravityView_Widget_Search::get_search_input_types($field['id'], $form_field['type']); |
|
305 | - |
|
306 | - // add field to config |
|
307 | - $search_fields[] = ['field' => $field['id'], 'input' => $type]; |
|
308 | - } |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - return $search_fields; |
|
313 | - } |
|
16 | + public function __construct() |
|
17 | + { |
|
18 | + add_action('admin_init', [$this, 'update_settings'], 1); |
|
19 | + } |
|
20 | + |
|
21 | + public function update_settings() |
|
22 | + { |
|
23 | + $this->maybe_migrate_search_widget(); |
|
24 | + |
|
25 | + $this->migrate_redux_settings(); |
|
26 | + |
|
27 | + $this->maybe_migrate_approved_meta(); |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Convert approval meta values to enumerated values. |
|
32 | + * |
|
33 | + * @since 1.18 |
|
34 | + */ |
|
35 | + private function maybe_migrate_approved_meta() |
|
36 | + { |
|
37 | + |
|
38 | + // check if search migration is already performed |
|
39 | + $is_updated = get_option('gv_migrated_approved_meta'); |
|
40 | + |
|
41 | + if ($is_updated) { |
|
42 | + return; |
|
43 | + } |
|
44 | + |
|
45 | + $this->update_approved_meta(); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Convert "Approved" approval status to "1". |
|
50 | + * |
|
51 | + * @since 1.18 |
|
52 | + * |
|
53 | + * @return void |
|
54 | + */ |
|
55 | + private function update_approved_meta() |
|
56 | + { |
|
57 | + global $wpdb; |
|
58 | + |
|
59 | + if (!class_exists('GFFormsModel')) { |
|
60 | + gravityview()->log->error('GFFormsModel does not exist.'); |
|
61 | + |
|
62 | + return; |
|
63 | + } |
|
64 | + |
|
65 | + if (version_compare(GFFormsModel::get_database_version(), '2.3-dev-1', '>=')) { |
|
66 | + $table_name = GFFormsModel::get_entry_meta_table_name(); |
|
67 | + } else { |
|
68 | + $table_name = GFFormsModel::get_lead_meta_table_name(); |
|
69 | + } |
|
70 | + |
|
71 | + $sql = "UPDATE {$table_name} SET `meta_value` = %s WHERE `meta_key` = 'is_approved' AND `meta_value` = %s"; |
|
72 | + |
|
73 | + $approved_result = $wpdb->query($wpdb->prepare($sql, GravityView_Entry_Approval_Status::APPROVED, 'Approved')); |
|
74 | + |
|
75 | + $disapproved_result = $wpdb->query($wpdb->prepare($sql, GravityView_Entry_Approval_Status::DISAPPROVED, '0')); |
|
76 | + |
|
77 | + if (false === $approved_result || false === $disapproved_result) { |
|
78 | + gravityview()->log->error('There was an error processing the query. {error}', ['error' => $wpdb->last_error]); |
|
79 | + } else { |
|
80 | + // All done: Meta values are migrated |
|
81 | + update_option('gv_migrated_approved_meta', true); |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @since 1.7.4 |
|
87 | + */ |
|
88 | + private function maybe_migrate_search_widget() |
|
89 | + { |
|
90 | + |
|
91 | + // check if search migration is already performed |
|
92 | + $is_updated = get_option('gv_migrate_searchwidget'); |
|
93 | + if ($is_updated) { |
|
94 | + return; |
|
95 | + } else { |
|
96 | + $this->update_search_on_views(); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Set app settings from prior Redux settings, if exists. |
|
102 | + * |
|
103 | + * @since 1.7.4 |
|
104 | + * |
|
105 | + * @return mixed|void |
|
106 | + */ |
|
107 | + private function migrate_redux_settings() |
|
108 | + { |
|
109 | + $redux_settings = $this->get_redux_settings(); |
|
110 | + |
|
111 | + // No need to process |
|
112 | + if (false === $redux_settings) { |
|
113 | + return; |
|
114 | + } |
|
115 | + |
|
116 | + if (empty($redux_settings['license_key_status'])) { |
|
117 | + $redux_settings = $this->get_redux_license_status($redux_settings); |
|
118 | + } |
|
119 | + |
|
120 | + // Get the current app settings (just defaults) |
|
121 | + $current = gravityview()->plugin->settings->all(); |
|
122 | + |
|
123 | + // Merge the redux settings with the defaults |
|
124 | + $updated_settings = wp_parse_args($redux_settings, $current); |
|
125 | + |
|
126 | + // Update the defaults to the new merged |
|
127 | + gravityview()->plugin->settings->update($updated_settings); |
|
128 | + |
|
129 | + // And now remove the previous option, so this is a one-time thing. |
|
130 | + delete_option('gravityview_settings'); |
|
131 | + delete_option('gravityview_settings-transients'); |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * If the settings transient wasn't set, we need to set the default status for the license. |
|
136 | + * |
|
137 | + * @since 1.7.4 |
|
138 | + * |
|
139 | + * @param array $redux_settings |
|
140 | + * |
|
141 | + * @return array |
|
142 | + */ |
|
143 | + public function get_redux_license_status($redux_settings = []) |
|
144 | + { |
|
145 | + $data = [ |
|
146 | + 'edd_action' => 'check_license', |
|
147 | + 'license' => \GV\Utils::_GET('license_key', \GV\Utils::get($redux_settings, 'license_key')), |
|
148 | + 'update' => false, |
|
149 | + 'format' => 'object', |
|
150 | + ]; |
|
151 | + |
|
152 | + $license_call = \GV\License_Handler::get()->license_call($data); |
|
153 | + |
|
154 | + if (is_object($license_call) && isset($license_call->license)) { |
|
155 | + $redux_settings['license_key_status'] = $license_call->license; |
|
156 | + $redux_settings['license_key_response'] = json_encode($license_call); |
|
157 | + } |
|
158 | + |
|
159 | + return $redux_settings; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Get Redux settings, if they exist. |
|
164 | + * |
|
165 | + * @since 1.7.4 |
|
166 | + * |
|
167 | + * @return array|bool |
|
168 | + */ |
|
169 | + public function get_redux_settings() |
|
170 | + { |
|
171 | + |
|
172 | + // Previous settings set by Redux |
|
173 | + $redux_option = get_option('gravityview_settings'); |
|
174 | + |
|
175 | + // No Redux settings? Don't proceed. |
|
176 | + if (false === $redux_option) { |
|
177 | + return false; |
|
178 | + } |
|
179 | + |
|
180 | + $redux_settings = [ |
|
181 | + 'support-email' => \GV\Utils::get($redux_option, 'support-email'), |
|
182 | + 'no-conflict-mode' => \GV\Utils::get($redux_option, 'no-conflict-mode') ? '1' : '0', |
|
183 | + ]; |
|
184 | + |
|
185 | + if ($license_array = \GV\Utils::get($redux_option, 'license')) { |
|
186 | + $redux_settings['license_key'] = $license_key = \GV\Utils::get($license_array, 'license'); |
|
187 | + |
|
188 | + $redux_last_changed_values = get_option('gravityview_settings-transients'); |
|
189 | + |
|
190 | + // This contains the last response for license validation |
|
191 | + if (!empty($redux_last_changed_values) && $saved_values = \GV\Utils::get($redux_last_changed_values, 'changed_values')) { |
|
192 | + $saved_license = \GV\Utils::get($saved_values, 'license'); |
|
193 | + |
|
194 | + // Only use the last-saved values if they are for the same license |
|
195 | + if ($saved_license && \GV\Utils::get($saved_license, 'license') === $license_key) { |
|
196 | + $redux_settings['license_key_status'] = \GV\Utils::get($saved_license, 'status'); |
|
197 | + $redux_settings['license_key_response'] = \GV\Utils::get($saved_license, 'response'); |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + return $redux_settings; |
|
203 | + } |
|
204 | + |
|
205 | + /** ---- Migrate from old search widget to new search widget ---- */ |
|
206 | + public function update_search_on_views() |
|
207 | + { |
|
208 | + if (!class_exists('GravityView_Widget_Search')) { |
|
209 | + include_once GRAVITYVIEW_DIR.'includes/extensions/search-widget/class-search-widget.php'; |
|
210 | + } |
|
211 | + |
|
212 | + // Loop through all the views |
|
213 | + $query_args = [ |
|
214 | + 'post_type' => 'gravityview', |
|
215 | + 'post_status' => 'any', |
|
216 | + 'posts_per_page' => -1, |
|
217 | + ]; |
|
218 | + |
|
219 | + $views = get_posts($query_args); |
|
220 | + |
|
221 | + foreach ($views as $view) { |
|
222 | + $widgets = gravityview_get_directory_widgets($view->ID); |
|
223 | + $search_fields = null; |
|
224 | + |
|
225 | + if (empty($widgets) || !is_array($widgets)) { |
|
226 | + continue; |
|
227 | + } |
|
228 | + |
|
229 | + gravityview()->log->debug('[GravityView_Migrate/update_search_on_views] Loading View ID: {view_id}', ['view_id' => $view->ID]); |
|
230 | + |
|
231 | + foreach ($widgets as $area => $ws) { |
|
232 | + foreach ($ws as $k => $widget) { |
|
233 | + if ($widget['id'] !== 'search_bar') { |
|
234 | + continue; |
|
235 | + } |
|
236 | + |
|
237 | + if (is_null($search_fields)) { |
|
238 | + $search_fields = $this->get_search_fields($view->ID); |
|
239 | + } |
|
240 | + |
|
241 | + // check widget settings: |
|
242 | + // [search_free] => 1 |
|
243 | + // [search_date] => 1 |
|
244 | + $search_generic = []; |
|
245 | + if (!empty($widget['search_free'])) { |
|
246 | + $search_generic[] = ['field' => 'search_all', 'input' => 'input_text']; |
|
247 | + } |
|
248 | + if (!empty($widget['search_date'])) { |
|
249 | + $search_generic[] = ['field' => 'entry_date', 'input' => 'date']; |
|
250 | + } |
|
251 | + |
|
252 | + $search_config = array_merge($search_generic, $search_fields); |
|
253 | + |
|
254 | + // don't throw '[]' when json_encode an empty array |
|
255 | + if (empty($search_config)) { |
|
256 | + $search_config = ''; |
|
257 | + } else { |
|
258 | + $search_config = json_encode($search_config); |
|
259 | + } |
|
260 | + |
|
261 | + $widgets[$area][$k]['search_fields'] = $search_config; |
|
262 | + $widgets[$area][$k]['search_layout'] = 'horizontal'; |
|
263 | + |
|
264 | + gravityview()->log->debug('[GravityView_Migrate/update_search_on_views] Updated Widget: ', ['data' => $widgets[$area][$k]]); |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + // update widgets view |
|
269 | + gravityview_set_directory_widgets($view->ID, $widgets); |
|
270 | + } // foreach Views |
|
271 | + |
|
272 | + // all done! enjoy the new Search Widget! |
|
273 | + update_option('gv_migrate_searchwidget', true); |
|
274 | + |
|
275 | + gravityview()->log->debug('[GravityView_Migrate/update_search_on_views] All done! enjoy the new Search Widget!'); |
|
276 | + } |
|
277 | + |
|
278 | + public function get_search_fields($view_id) |
|
279 | + { |
|
280 | + $form_id = gravityview_get_form_id($view_id); |
|
281 | + $form = gravityview_get_form($form_id); |
|
282 | + |
|
283 | + $search_fields = []; |
|
284 | + |
|
285 | + // check view fields' settings |
|
286 | + $fields = gravityview_get_directory_fields($view_id, false); |
|
287 | + |
|
288 | + if (!empty($fields) && is_array($fields)) { |
|
289 | + foreach ($fields as $t => $fs) { |
|
290 | + foreach ($fs as $k => $field) { |
|
291 | + // is field a search_filter ? |
|
292 | + if (empty($field['search_filter'])) { |
|
293 | + continue; |
|
294 | + } |
|
295 | + |
|
296 | + // get field type & calculate the input type (by default) |
|
297 | + $form_field = gravityview_get_field($form, $field['id']); |
|
298 | + |
|
299 | + if (empty($form_field['type'])) { |
|
300 | + continue; |
|
301 | + } |
|
302 | + |
|
303 | + // depending on the field type assign a group of possible search field types |
|
304 | + $type = GravityView_Widget_Search::get_search_input_types($field['id'], $form_field['type']); |
|
305 | + |
|
306 | + // add field to config |
|
307 | + $search_fields[] = ['field' => $field['id'], 'input' => $type]; |
|
308 | + } |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + return $search_fields; |
|
313 | + } |
|
314 | 314 | } // end class |
315 | 315 | |
316 | 316 | new GravityView_Migrate(); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | { |
16 | 16 | public function __construct() |
17 | 17 | { |
18 | - add_action('admin_init', [$this, 'update_settings'], 1); |
|
18 | + add_action( 'admin_init', [ $this, 'update_settings' ], 1 ); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | public function update_settings() |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | { |
37 | 37 | |
38 | 38 | // check if search migration is already performed |
39 | - $is_updated = get_option('gv_migrated_approved_meta'); |
|
39 | + $is_updated = get_option( 'gv_migrated_approved_meta' ); |
|
40 | 40 | |
41 | - if ($is_updated) { |
|
41 | + if ( $is_updated ) { |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
@@ -56,13 +56,13 @@ discard block |
||
56 | 56 | { |
57 | 57 | global $wpdb; |
58 | 58 | |
59 | - if (!class_exists('GFFormsModel')) { |
|
60 | - gravityview()->log->error('GFFormsModel does not exist.'); |
|
59 | + if ( ! class_exists( 'GFFormsModel' ) ) { |
|
60 | + gravityview()->log->error( 'GFFormsModel does not exist.' ); |
|
61 | 61 | |
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | - if (version_compare(GFFormsModel::get_database_version(), '2.3-dev-1', '>=')) { |
|
65 | + if ( version_compare( GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) ) { |
|
66 | 66 | $table_name = GFFormsModel::get_entry_meta_table_name(); |
67 | 67 | } else { |
68 | 68 | $table_name = GFFormsModel::get_lead_meta_table_name(); |
@@ -70,15 +70,15 @@ discard block |
||
70 | 70 | |
71 | 71 | $sql = "UPDATE {$table_name} SET `meta_value` = %s WHERE `meta_key` = 'is_approved' AND `meta_value` = %s"; |
72 | 72 | |
73 | - $approved_result = $wpdb->query($wpdb->prepare($sql, GravityView_Entry_Approval_Status::APPROVED, 'Approved')); |
|
73 | + $approved_result = $wpdb->query( $wpdb->prepare( $sql, GravityView_Entry_Approval_Status::APPROVED, 'Approved' ) ); |
|
74 | 74 | |
75 | - $disapproved_result = $wpdb->query($wpdb->prepare($sql, GravityView_Entry_Approval_Status::DISAPPROVED, '0')); |
|
75 | + $disapproved_result = $wpdb->query( $wpdb->prepare( $sql, GravityView_Entry_Approval_Status::DISAPPROVED, '0' ) ); |
|
76 | 76 | |
77 | - if (false === $approved_result || false === $disapproved_result) { |
|
78 | - gravityview()->log->error('There was an error processing the query. {error}', ['error' => $wpdb->last_error]); |
|
77 | + if ( false === $approved_result || false === $disapproved_result ) { |
|
78 | + gravityview()->log->error( 'There was an error processing the query. {error}', [ 'error' => $wpdb->last_error ] ); |
|
79 | 79 | } else { |
80 | 80 | // All done: Meta values are migrated |
81 | - update_option('gv_migrated_approved_meta', true); |
|
81 | + update_option( 'gv_migrated_approved_meta', true ); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | { |
90 | 90 | |
91 | 91 | // check if search migration is already performed |
92 | - $is_updated = get_option('gv_migrate_searchwidget'); |
|
93 | - if ($is_updated) { |
|
92 | + $is_updated = get_option( 'gv_migrate_searchwidget' ); |
|
93 | + if ( $is_updated ) { |
|
94 | 94 | return; |
95 | 95 | } else { |
96 | 96 | $this->update_search_on_views(); |
@@ -109,26 +109,26 @@ discard block |
||
109 | 109 | $redux_settings = $this->get_redux_settings(); |
110 | 110 | |
111 | 111 | // No need to process |
112 | - if (false === $redux_settings) { |
|
112 | + if ( false === $redux_settings ) { |
|
113 | 113 | return; |
114 | 114 | } |
115 | 115 | |
116 | - if (empty($redux_settings['license_key_status'])) { |
|
117 | - $redux_settings = $this->get_redux_license_status($redux_settings); |
|
116 | + if ( empty( $redux_settings[ 'license_key_status' ] ) ) { |
|
117 | + $redux_settings = $this->get_redux_license_status( $redux_settings ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | // Get the current app settings (just defaults) |
121 | 121 | $current = gravityview()->plugin->settings->all(); |
122 | 122 | |
123 | 123 | // Merge the redux settings with the defaults |
124 | - $updated_settings = wp_parse_args($redux_settings, $current); |
|
124 | + $updated_settings = wp_parse_args( $redux_settings, $current ); |
|
125 | 125 | |
126 | 126 | // Update the defaults to the new merged |
127 | - gravityview()->plugin->settings->update($updated_settings); |
|
127 | + gravityview()->plugin->settings->update( $updated_settings ); |
|
128 | 128 | |
129 | 129 | // And now remove the previous option, so this is a one-time thing. |
130 | - delete_option('gravityview_settings'); |
|
131 | - delete_option('gravityview_settings-transients'); |
|
130 | + delete_option( 'gravityview_settings' ); |
|
131 | + delete_option( 'gravityview_settings-transients' ); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -140,20 +140,20 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return array |
142 | 142 | */ |
143 | - public function get_redux_license_status($redux_settings = []) |
|
143 | + public function get_redux_license_status( $redux_settings = [ ] ) |
|
144 | 144 | { |
145 | 145 | $data = [ |
146 | 146 | 'edd_action' => 'check_license', |
147 | - 'license' => \GV\Utils::_GET('license_key', \GV\Utils::get($redux_settings, 'license_key')), |
|
147 | + 'license' => \GV\Utils::_GET( 'license_key', \GV\Utils::get( $redux_settings, 'license_key' ) ), |
|
148 | 148 | 'update' => false, |
149 | 149 | 'format' => 'object', |
150 | 150 | ]; |
151 | 151 | |
152 | - $license_call = \GV\License_Handler::get()->license_call($data); |
|
152 | + $license_call = \GV\License_Handler::get()->license_call( $data ); |
|
153 | 153 | |
154 | - if (is_object($license_call) && isset($license_call->license)) { |
|
155 | - $redux_settings['license_key_status'] = $license_call->license; |
|
156 | - $redux_settings['license_key_response'] = json_encode($license_call); |
|
154 | + if ( is_object( $license_call ) && isset( $license_call->license ) ) { |
|
155 | + $redux_settings[ 'license_key_status' ] = $license_call->license; |
|
156 | + $redux_settings[ 'license_key_response' ] = json_encode( $license_call ); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | return $redux_settings; |
@@ -170,31 +170,31 @@ discard block |
||
170 | 170 | { |
171 | 171 | |
172 | 172 | // Previous settings set by Redux |
173 | - $redux_option = get_option('gravityview_settings'); |
|
173 | + $redux_option = get_option( 'gravityview_settings' ); |
|
174 | 174 | |
175 | 175 | // No Redux settings? Don't proceed. |
176 | - if (false === $redux_option) { |
|
176 | + if ( false === $redux_option ) { |
|
177 | 177 | return false; |
178 | 178 | } |
179 | 179 | |
180 | 180 | $redux_settings = [ |
181 | - 'support-email' => \GV\Utils::get($redux_option, 'support-email'), |
|
182 | - 'no-conflict-mode' => \GV\Utils::get($redux_option, 'no-conflict-mode') ? '1' : '0', |
|
181 | + 'support-email' => \GV\Utils::get( $redux_option, 'support-email' ), |
|
182 | + 'no-conflict-mode' => \GV\Utils::get( $redux_option, 'no-conflict-mode' ) ? '1' : '0', |
|
183 | 183 | ]; |
184 | 184 | |
185 | - if ($license_array = \GV\Utils::get($redux_option, 'license')) { |
|
186 | - $redux_settings['license_key'] = $license_key = \GV\Utils::get($license_array, 'license'); |
|
185 | + if ( $license_array = \GV\Utils::get( $redux_option, 'license' ) ) { |
|
186 | + $redux_settings[ 'license_key' ] = $license_key = \GV\Utils::get( $license_array, 'license' ); |
|
187 | 187 | |
188 | - $redux_last_changed_values = get_option('gravityview_settings-transients'); |
|
188 | + $redux_last_changed_values = get_option( 'gravityview_settings-transients' ); |
|
189 | 189 | |
190 | 190 | // This contains the last response for license validation |
191 | - if (!empty($redux_last_changed_values) && $saved_values = \GV\Utils::get($redux_last_changed_values, 'changed_values')) { |
|
192 | - $saved_license = \GV\Utils::get($saved_values, 'license'); |
|
191 | + if ( ! empty( $redux_last_changed_values ) && $saved_values = \GV\Utils::get( $redux_last_changed_values, 'changed_values' ) ) { |
|
192 | + $saved_license = \GV\Utils::get( $saved_values, 'license' ); |
|
193 | 193 | |
194 | 194 | // Only use the last-saved values if they are for the same license |
195 | - if ($saved_license && \GV\Utils::get($saved_license, 'license') === $license_key) { |
|
196 | - $redux_settings['license_key_status'] = \GV\Utils::get($saved_license, 'status'); |
|
197 | - $redux_settings['license_key_response'] = \GV\Utils::get($saved_license, 'response'); |
|
195 | + if ( $saved_license && \GV\Utils::get( $saved_license, 'license' ) === $license_key ) { |
|
196 | + $redux_settings[ 'license_key_status' ] = \GV\Utils::get( $saved_license, 'status' ); |
|
197 | + $redux_settings[ 'license_key_response' ] = \GV\Utils::get( $saved_license, 'response' ); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | } |
@@ -205,8 +205,8 @@ discard block |
||
205 | 205 | /** ---- Migrate from old search widget to new search widget ---- */ |
206 | 206 | public function update_search_on_views() |
207 | 207 | { |
208 | - if (!class_exists('GravityView_Widget_Search')) { |
|
209 | - include_once GRAVITYVIEW_DIR.'includes/extensions/search-widget/class-search-widget.php'; |
|
208 | + if ( ! class_exists( 'GravityView_Widget_Search' ) ) { |
|
209 | + include_once GRAVITYVIEW_DIR . 'includes/extensions/search-widget/class-search-widget.php'; |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | // Loop through all the views |
@@ -216,95 +216,95 @@ discard block |
||
216 | 216 | 'posts_per_page' => -1, |
217 | 217 | ]; |
218 | 218 | |
219 | - $views = get_posts($query_args); |
|
219 | + $views = get_posts( $query_args ); |
|
220 | 220 | |
221 | - foreach ($views as $view) { |
|
222 | - $widgets = gravityview_get_directory_widgets($view->ID); |
|
221 | + foreach ( $views as $view ) { |
|
222 | + $widgets = gravityview_get_directory_widgets( $view->ID ); |
|
223 | 223 | $search_fields = null; |
224 | 224 | |
225 | - if (empty($widgets) || !is_array($widgets)) { |
|
225 | + if ( empty( $widgets ) || ! is_array( $widgets ) ) { |
|
226 | 226 | continue; |
227 | 227 | } |
228 | 228 | |
229 | - gravityview()->log->debug('[GravityView_Migrate/update_search_on_views] Loading View ID: {view_id}', ['view_id' => $view->ID]); |
|
229 | + gravityview()->log->debug( '[GravityView_Migrate/update_search_on_views] Loading View ID: {view_id}', [ 'view_id' => $view->ID ] ); |
|
230 | 230 | |
231 | - foreach ($widgets as $area => $ws) { |
|
232 | - foreach ($ws as $k => $widget) { |
|
233 | - if ($widget['id'] !== 'search_bar') { |
|
231 | + foreach ( $widgets as $area => $ws ) { |
|
232 | + foreach ( $ws as $k => $widget ) { |
|
233 | + if ( $widget[ 'id' ] !== 'search_bar' ) { |
|
234 | 234 | continue; |
235 | 235 | } |
236 | 236 | |
237 | - if (is_null($search_fields)) { |
|
238 | - $search_fields = $this->get_search_fields($view->ID); |
|
237 | + if ( is_null( $search_fields ) ) { |
|
238 | + $search_fields = $this->get_search_fields( $view->ID ); |
|
239 | 239 | } |
240 | 240 | |
241 | 241 | // check widget settings: |
242 | 242 | // [search_free] => 1 |
243 | 243 | // [search_date] => 1 |
244 | - $search_generic = []; |
|
245 | - if (!empty($widget['search_free'])) { |
|
246 | - $search_generic[] = ['field' => 'search_all', 'input' => 'input_text']; |
|
244 | + $search_generic = [ ]; |
|
245 | + if ( ! empty( $widget[ 'search_free' ] ) ) { |
|
246 | + $search_generic[ ] = [ 'field' => 'search_all', 'input' => 'input_text' ]; |
|
247 | 247 | } |
248 | - if (!empty($widget['search_date'])) { |
|
249 | - $search_generic[] = ['field' => 'entry_date', 'input' => 'date']; |
|
248 | + if ( ! empty( $widget[ 'search_date' ] ) ) { |
|
249 | + $search_generic[ ] = [ 'field' => 'entry_date', 'input' => 'date' ]; |
|
250 | 250 | } |
251 | 251 | |
252 | - $search_config = array_merge($search_generic, $search_fields); |
|
252 | + $search_config = array_merge( $search_generic, $search_fields ); |
|
253 | 253 | |
254 | 254 | // don't throw '[]' when json_encode an empty array |
255 | - if (empty($search_config)) { |
|
255 | + if ( empty( $search_config ) ) { |
|
256 | 256 | $search_config = ''; |
257 | 257 | } else { |
258 | - $search_config = json_encode($search_config); |
|
258 | + $search_config = json_encode( $search_config ); |
|
259 | 259 | } |
260 | 260 | |
261 | - $widgets[$area][$k]['search_fields'] = $search_config; |
|
262 | - $widgets[$area][$k]['search_layout'] = 'horizontal'; |
|
261 | + $widgets[ $area ][ $k ][ 'search_fields' ] = $search_config; |
|
262 | + $widgets[ $area ][ $k ][ 'search_layout' ] = 'horizontal'; |
|
263 | 263 | |
264 | - gravityview()->log->debug('[GravityView_Migrate/update_search_on_views] Updated Widget: ', ['data' => $widgets[$area][$k]]); |
|
264 | + gravityview()->log->debug( '[GravityView_Migrate/update_search_on_views] Updated Widget: ', [ 'data' => $widgets[ $area ][ $k ] ] ); |
|
265 | 265 | } |
266 | 266 | } |
267 | 267 | |
268 | 268 | // update widgets view |
269 | - gravityview_set_directory_widgets($view->ID, $widgets); |
|
269 | + gravityview_set_directory_widgets( $view->ID, $widgets ); |
|
270 | 270 | } // foreach Views |
271 | 271 | |
272 | 272 | // all done! enjoy the new Search Widget! |
273 | - update_option('gv_migrate_searchwidget', true); |
|
273 | + update_option( 'gv_migrate_searchwidget', true ); |
|
274 | 274 | |
275 | - gravityview()->log->debug('[GravityView_Migrate/update_search_on_views] All done! enjoy the new Search Widget!'); |
|
275 | + gravityview()->log->debug( '[GravityView_Migrate/update_search_on_views] All done! enjoy the new Search Widget!' ); |
|
276 | 276 | } |
277 | 277 | |
278 | - public function get_search_fields($view_id) |
|
278 | + public function get_search_fields( $view_id ) |
|
279 | 279 | { |
280 | - $form_id = gravityview_get_form_id($view_id); |
|
281 | - $form = gravityview_get_form($form_id); |
|
280 | + $form_id = gravityview_get_form_id( $view_id ); |
|
281 | + $form = gravityview_get_form( $form_id ); |
|
282 | 282 | |
283 | - $search_fields = []; |
|
283 | + $search_fields = [ ]; |
|
284 | 284 | |
285 | 285 | // check view fields' settings |
286 | - $fields = gravityview_get_directory_fields($view_id, false); |
|
286 | + $fields = gravityview_get_directory_fields( $view_id, false ); |
|
287 | 287 | |
288 | - if (!empty($fields) && is_array($fields)) { |
|
289 | - foreach ($fields as $t => $fs) { |
|
290 | - foreach ($fs as $k => $field) { |
|
288 | + if ( ! empty( $fields ) && is_array( $fields ) ) { |
|
289 | + foreach ( $fields as $t => $fs ) { |
|
290 | + foreach ( $fs as $k => $field ) { |
|
291 | 291 | // is field a search_filter ? |
292 | - if (empty($field['search_filter'])) { |
|
292 | + if ( empty( $field[ 'search_filter' ] ) ) { |
|
293 | 293 | continue; |
294 | 294 | } |
295 | 295 | |
296 | 296 | // get field type & calculate the input type (by default) |
297 | - $form_field = gravityview_get_field($form, $field['id']); |
|
297 | + $form_field = gravityview_get_field( $form, $field[ 'id' ] ); |
|
298 | 298 | |
299 | - if (empty($form_field['type'])) { |
|
299 | + if ( empty( $form_field[ 'type' ] ) ) { |
|
300 | 300 | continue; |
301 | 301 | } |
302 | 302 | |
303 | 303 | // depending on the field type assign a group of possible search field types |
304 | - $type = GravityView_Widget_Search::get_search_input_types($field['id'], $form_field['type']); |
|
304 | + $type = GravityView_Widget_Search::get_search_input_types( $field[ 'id' ], $form_field[ 'type' ] ); |
|
305 | 305 | |
306 | 306 | // add field to config |
307 | - $search_fields[] = ['field' => $field['id'], 'input' => $type]; |
|
307 | + $search_fields[ ] = [ 'field' => $field[ 'id' ], 'input' => $type ]; |
|
308 | 308 | } |
309 | 309 | } |
310 | 310 | } |
@@ -11,15 +11,12 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @since 1.2 |
13 | 13 | */ |
14 | -class GravityView_Migrate |
|
15 | -{ |
|
16 | - public function __construct() |
|
17 | - { |
|
14 | +class GravityView_Migrate { |
|
15 | + public function __construct() { |
|
18 | 16 | add_action('admin_init', [$this, 'update_settings'], 1); |
19 | 17 | } |
20 | 18 | |
21 | - public function update_settings() |
|
22 | - { |
|
19 | + public function update_settings() { |
|
23 | 20 | $this->maybe_migrate_search_widget(); |
24 | 21 | |
25 | 22 | $this->migrate_redux_settings(); |
@@ -32,8 +29,7 @@ discard block |
||
32 | 29 | * |
33 | 30 | * @since 1.18 |
34 | 31 | */ |
35 | - private function maybe_migrate_approved_meta() |
|
36 | - { |
|
32 | + private function maybe_migrate_approved_meta() { |
|
37 | 33 | |
38 | 34 | // check if search migration is already performed |
39 | 35 | $is_updated = get_option('gv_migrated_approved_meta'); |
@@ -52,8 +48,7 @@ discard block |
||
52 | 48 | * |
53 | 49 | * @return void |
54 | 50 | */ |
55 | - private function update_approved_meta() |
|
56 | - { |
|
51 | + private function update_approved_meta() { |
|
57 | 52 | global $wpdb; |
58 | 53 | |
59 | 54 | if (!class_exists('GFFormsModel')) { |
@@ -85,8 +80,7 @@ discard block |
||
85 | 80 | /** |
86 | 81 | * @since 1.7.4 |
87 | 82 | */ |
88 | - private function maybe_migrate_search_widget() |
|
89 | - { |
|
83 | + private function maybe_migrate_search_widget() { |
|
90 | 84 | |
91 | 85 | // check if search migration is already performed |
92 | 86 | $is_updated = get_option('gv_migrate_searchwidget'); |
@@ -104,8 +98,7 @@ discard block |
||
104 | 98 | * |
105 | 99 | * @return mixed|void |
106 | 100 | */ |
107 | - private function migrate_redux_settings() |
|
108 | - { |
|
101 | + private function migrate_redux_settings() { |
|
109 | 102 | $redux_settings = $this->get_redux_settings(); |
110 | 103 | |
111 | 104 | // No need to process |
@@ -140,8 +133,7 @@ discard block |
||
140 | 133 | * |
141 | 134 | * @return array |
142 | 135 | */ |
143 | - public function get_redux_license_status($redux_settings = []) |
|
144 | - { |
|
136 | + public function get_redux_license_status($redux_settings = []) { |
|
145 | 137 | $data = [ |
146 | 138 | 'edd_action' => 'check_license', |
147 | 139 | 'license' => \GV\Utils::_GET('license_key', \GV\Utils::get($redux_settings, 'license_key')), |
@@ -166,8 +158,7 @@ discard block |
||
166 | 158 | * |
167 | 159 | * @return array|bool |
168 | 160 | */ |
169 | - public function get_redux_settings() |
|
170 | - { |
|
161 | + public function get_redux_settings() { |
|
171 | 162 | |
172 | 163 | // Previous settings set by Redux |
173 | 164 | $redux_option = get_option('gravityview_settings'); |
@@ -203,8 +194,7 @@ discard block |
||
203 | 194 | } |
204 | 195 | |
205 | 196 | /** ---- Migrate from old search widget to new search widget ---- */ |
206 | - public function update_search_on_views() |
|
207 | - { |
|
197 | + public function update_search_on_views() { |
|
208 | 198 | if (!class_exists('GravityView_Widget_Search')) { |
209 | 199 | include_once GRAVITYVIEW_DIR.'includes/extensions/search-widget/class-search-widget.php'; |
210 | 200 | } |
@@ -275,8 +265,7 @@ discard block |
||
275 | 265 | gravityview()->log->debug('[GravityView_Migrate/update_search_on_views] All done! enjoy the new Search Widget!'); |
276 | 266 | } |
277 | 267 | |
278 | - public function get_search_fields($view_id) |
|
279 | - { |
|
268 | + public function get_search_fields($view_id) { |
|
280 | 269 | $form_id = gravityview_get_form_id($view_id); |
281 | 270 | $form = gravityview_get_form($form_id); |
282 | 271 |
@@ -68,7 +68,7 @@ |
||
68 | 68 | $table_name = GFFormsModel::get_lead_meta_table_name(); |
69 | 69 | } |
70 | 70 | |
71 | - $sql = "UPDATE {$table_name} SET `meta_value` = %s WHERE `meta_key` = 'is_approved' AND `meta_value` = %s"; |
|
71 | + $sql = "update {$table_name} SET `meta_value` = %s WHERE `meta_key` = 'is_approved' AND `meta_value` = %s"; |
|
72 | 72 | |
73 | 73 | $approved_result = $wpdb->query($wpdb->prepare($sql, GravityView_Entry_Approval_Status::APPROVED, 'Approved')); |
74 | 74 |
@@ -13,1718 +13,1718 @@ |
||
13 | 13 | */ |
14 | 14 | class GravityView_frontend |
15 | 15 | { |
16 | - /** |
|
17 | - * Regex strings that are used to determine whether the current request is a GravityView search or not. |
|
18 | - * |
|
19 | - * @see GravityView_frontend::is_searching() |
|
20 | - * @since 1.7.4.1 |
|
21 | - * |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - private static $search_parameters = ['gv_search', 'gv_start', 'gv_end', 'gv_id', 'gv_by', 'filter_*']; |
|
25 | - |
|
26 | - /** |
|
27 | - * Is the currently viewed post a `gravityview` post type? |
|
28 | - * |
|
29 | - * @var bool |
|
30 | - */ |
|
31 | - public $is_gravityview_post_type = false; |
|
32 | - |
|
33 | - /** |
|
34 | - * Does the current post have a `[gravityview]` shortcode? |
|
35 | - * |
|
36 | - * @var bool |
|
37 | - */ |
|
38 | - public $post_has_shortcode = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * The Post ID of the currently viewed post. Not necessarily GV. |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - public $post_id = null; |
|
46 | - |
|
47 | - /** |
|
48 | - * Are we currently viewing a single entry? |
|
49 | - * If so, the int value of the entry ID. Otherwise, false. |
|
50 | - * |
|
51 | - * @var int|bool |
|
52 | - */ |
|
53 | - public $single_entry = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * If we are viewing a single entry, the entry data. |
|
57 | - * |
|
58 | - * @var array|false |
|
59 | - */ |
|
60 | - public $entry = false; |
|
61 | - |
|
62 | - /** |
|
63 | - * When displaying the single entry we should always know to which View it belongs (the context is everything!). |
|
64 | - * |
|
65 | - * @var null |
|
66 | - */ |
|
67 | - public $context_view_id = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * The View is showing search results. |
|
71 | - * |
|
72 | - * @since 1.5.4 |
|
73 | - * |
|
74 | - * @var bool |
|
75 | - */ |
|
76 | - public $is_search = false; |
|
77 | - |
|
78 | - /** |
|
79 | - * The view data parsed from the $post. |
|
80 | - * |
|
81 | - * @see GravityView_View_Data::__construct() |
|
82 | - * |
|
83 | - * @var GravityView_View_Data |
|
84 | - */ |
|
85 | - public $gv_output_data = null; |
|
86 | - |
|
87 | - /** |
|
88 | - * @var GravityView_frontend |
|
89 | - */ |
|
90 | - public static $instance; |
|
91 | - |
|
92 | - /** |
|
93 | - * Class constructor, enforce Singleton pattern. |
|
94 | - */ |
|
95 | - private function __construct() |
|
96 | - { |
|
97 | - } |
|
98 | - |
|
99 | - private function initialize() |
|
100 | - { |
|
101 | - add_action('wp', [$this, 'parse_content'], 11); |
|
102 | - add_filter('render_block', [$this, 'detect_views_in_block_content']); |
|
103 | - add_filter('parse_query', [$this, 'parse_query_fix_frontpage'], 10); |
|
104 | - add_action('template_redirect', [$this, 'set_entry_data'], 1); |
|
105 | - |
|
106 | - // Enqueue scripts and styles after GravityView_Template::register_styles() |
|
107 | - add_action('wp_enqueue_scripts', [$this, 'add_scripts_and_styles'], 20); |
|
108 | - |
|
109 | - // Enqueue and print styles in the footer. Added 1 priorty so stuff gets printed at 10 priority. |
|
110 | - add_action('wp_print_footer_scripts', [$this, 'add_scripts_and_styles'], 1); |
|
111 | - |
|
112 | - add_filter('the_title', [$this, 'single_entry_title'], 1, 2); |
|
113 | - add_filter('comments_open', [$this, 'comments_open'], 10, 2); |
|
114 | - |
|
115 | - add_action('gravityview_after', [$this, 'context_not_configured_warning']); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Get the one true instantiated self. |
|
120 | - * |
|
121 | - * @return GravityView_frontend |
|
122 | - */ |
|
123 | - public static function getInstance() |
|
124 | - { |
|
125 | - if (empty(self::$instance)) { |
|
126 | - self::$instance = new self(); |
|
127 | - self::$instance->initialize(); |
|
128 | - } |
|
129 | - |
|
130 | - return self::$instance; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @return GravityView_View_Data |
|
135 | - */ |
|
136 | - public function getGvOutputData() |
|
137 | - { |
|
138 | - return $this->gv_output_data; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @param \GravityView_View_Data $gv_output_data |
|
143 | - */ |
|
144 | - public function setGvOutputData($gv_output_data) |
|
145 | - { |
|
146 | - $this->gv_output_data = $gv_output_data; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @return bool |
|
151 | - */ |
|
152 | - public function isSearch() |
|
153 | - { |
|
154 | - return $this->is_search; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @param bool $is_search |
|
159 | - */ |
|
160 | - public function setIsSearch($is_search) |
|
161 | - { |
|
162 | - $this->is_search = $is_search; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @return bool|int |
|
167 | - */ |
|
168 | - public function getSingleEntry() |
|
169 | - { |
|
170 | - return $this->single_entry; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Sets the single entry ID and also the entry. |
|
175 | - * |
|
176 | - * @param bool|int|string $single_entry |
|
177 | - */ |
|
178 | - public function setSingleEntry($single_entry) |
|
179 | - { |
|
180 | - $this->single_entry = $single_entry; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @return array |
|
185 | - */ |
|
186 | - public function getEntry() |
|
187 | - { |
|
188 | - return $this->entry; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Set the current entry. |
|
193 | - * |
|
194 | - * @param array|int $entry Entry array or entry slug or ID |
|
195 | - */ |
|
196 | - public function setEntry($entry) |
|
197 | - { |
|
198 | - if (!is_array($entry)) { |
|
199 | - $entry = GVCommon::get_entry($entry); |
|
200 | - } |
|
201 | - |
|
202 | - $this->entry = $entry; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * @return int |
|
207 | - */ |
|
208 | - public function getPostId() |
|
209 | - { |
|
210 | - return $this->post_id; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @param int $post_id |
|
215 | - */ |
|
216 | - public function setPostId($post_id) |
|
217 | - { |
|
218 | - $this->post_id = $post_id; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * @return bool |
|
223 | - */ |
|
224 | - public function isPostHasShortcode() |
|
225 | - { |
|
226 | - return $this->post_has_shortcode; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @param bool $post_has_shortcode |
|
231 | - */ |
|
232 | - public function setPostHasShortcode($post_has_shortcode) |
|
233 | - { |
|
234 | - $this->post_has_shortcode = $post_has_shortcode; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @return bool |
|
239 | - */ |
|
240 | - public function isGravityviewPostType() |
|
241 | - { |
|
242 | - return $this->is_gravityview_post_type; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * @param bool $is_gravityview_post_type |
|
247 | - */ |
|
248 | - public function setIsGravityviewPostType($is_gravityview_post_type) |
|
249 | - { |
|
250 | - $this->is_gravityview_post_type = $is_gravityview_post_type; |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Set the context view ID used when page contains multiple embedded views or displaying the single entry view. |
|
255 | - * |
|
256 | - * |
|
257 | - * |
|
258 | - * @param null $view_id |
|
259 | - */ |
|
260 | - public function set_context_view_id($view_id = null) |
|
261 | - { |
|
262 | - $multiple_views = $this->getGvOutputData() && $this->getGvOutputData()->has_multiple_views(); |
|
263 | - |
|
264 | - if (!empty($view_id)) { |
|
265 | - $this->context_view_id = (int) $view_id; |
|
266 | - } elseif (isset($_GET['gvid']) && $multiple_views) { |
|
267 | - /** |
|
268 | - * used on a has_multiple_views context. |
|
269 | - * |
|
270 | - * @see GravityView_API::entry_link |
|
271 | - */ |
|
272 | - $this->context_view_id = (int) $_GET['gvid']; |
|
273 | - } elseif (!$multiple_views) { |
|
274 | - $array_keys = array_keys($this->getGvOutputData()->get_views()); |
|
275 | - $this->context_view_id = (int) array_pop($array_keys); |
|
276 | - unset($array_keys); |
|
277 | - } |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Returns the the view_id context when page contains multiple embedded views or displaying single entry view. |
|
282 | - * |
|
283 | - * @since 1.5.4 |
|
284 | - * |
|
285 | - * @return int|null |
|
286 | - */ |
|
287 | - public function get_context_view_id() |
|
288 | - { |
|
289 | - return $this->context_view_id; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Allow GravityView entry endpoints on the front page of a site. |
|
294 | - * |
|
295 | - * @link https://core.trac.wordpress.org/ticket/23867 Fixes this core issue |
|
296 | - * @link https://wordpress.org/plugins/cpt-on-front-page/ Code is based on this |
|
297 | - * @since 1.17.3 |
|
298 | - * |
|
299 | - * @param WP_Query &$query (passed by reference) |
|
300 | - * |
|
301 | - * @return void |
|
302 | - */ |
|
303 | - public function parse_query_fix_frontpage(&$query) |
|
304 | - { |
|
305 | - global $wp_rewrite; |
|
306 | - |
|
307 | - $is_front_page = ($query->is_home || $query->is_page); |
|
308 | - $show_on_front = ('page' === get_option('show_on_front')); |
|
309 | - $front_page_id = get_option('page_on_front'); |
|
310 | - |
|
311 | - if ($is_front_page && $show_on_front && $front_page_id) { |
|
312 | - |
|
313 | - // Force to be an array, potentially a query string ( entry=16 ) |
|
314 | - $_query = wp_parse_args($query->query); |
|
315 | - |
|
316 | - // pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename. |
|
317 | - if (isset($_query['pagename']) && '' === $_query['pagename']) { |
|
318 | - unset($_query['pagename']); |
|
319 | - } |
|
320 | - |
|
321 | - // this is where will break from core wordpress |
|
322 | - /** @internal Don't use this filter; it will be unnecessary soon - it's just a patch for specific use case */ |
|
323 | - $ignore = apply_filters('gravityview/internal/ignored_endpoints', ['preview', 'page', 'paged', 'cpage'], $query); |
|
324 | - $endpoints = \GV\Utils::get($wp_rewrite, 'endpoints'); |
|
325 | - foreach ((array) $endpoints as $endpoint) { |
|
326 | - $ignore[] = $endpoint[1]; |
|
327 | - } |
|
328 | - unset($endpoints); |
|
329 | - |
|
330 | - // Modify the query if: |
|
331 | - // - We're on the "Page on front" page (which we are), and: |
|
332 | - // - The query is empty OR |
|
333 | - // - The query includes keys that are associated with registered endpoints. `entry`, for example. |
|
334 | - if (empty($_query) || !array_diff(array_keys($_query), $ignore)) { |
|
335 | - $qv = &$query->query_vars; |
|
336 | - |
|
337 | - // Prevent redirect when on the single entry endpoint |
|
338 | - if (self::is_single_entry()) { |
|
339 | - add_filter('redirect_canonical', '__return_false'); |
|
340 | - } |
|
341 | - |
|
342 | - $query->is_page = true; |
|
343 | - $query->is_home = false; |
|
344 | - $qv['page_id'] = $front_page_id; |
|
345 | - |
|
346 | - // Correct <!--nextpage--> for page_on_front |
|
347 | - if (!empty($qv['paged'])) { |
|
348 | - $qv['page'] = $qv['paged']; |
|
349 | - unset($qv['paged']); |
|
350 | - } |
|
351 | - } |
|
352 | - |
|
353 | - // reset the is_singular flag after our updated code above |
|
354 | - $query->is_singular = $query->is_single || $query->is_page || $query->is_attachment; |
|
355 | - } |
|
356 | - } |
|
357 | - |
|
358 | - /** |
|
359 | - * Detect GV Views in parsed Gutenberg block content. |
|
360 | - * |
|
361 | - * @since 2.13.4 |
|
362 | - * @see \WP_Block::render() |
|
363 | - * |
|
364 | - * @param string $block_content Gutenberg block content |
|
365 | - * |
|
366 | - * @return false|string |
|
367 | - * |
|
368 | - * @todo Once we stop using the legacy `GravityView_frontend::parse_content()` method to detect Views in post content, this code should either be dropped or promoted to some core class given its applicability to other themes/plugins |
|
369 | - */ |
|
370 | - public function detect_views_in_block_content($block_content) |
|
371 | - { |
|
372 | - if (!class_exists('GV\View_Collection') || !class_exists('GV\View')) { |
|
373 | - return $block_content; |
|
374 | - } |
|
375 | - |
|
376 | - $gv_view_data = GravityView_View_Data::getInstance(); |
|
377 | - |
|
378 | - $views = \GV\View_Collection::from_content($block_content); |
|
379 | - |
|
380 | - foreach ($views->all() as $view) { |
|
381 | - if (!$gv_view_data->views->contains($view->ID)) { |
|
382 | - $gv_view_data->views->add($view); |
|
383 | - } |
|
384 | - } |
|
385 | - |
|
386 | - return $block_content; |
|
387 | - } |
|
388 | - |
|
389 | - /** |
|
390 | - * Read the $post and process the View data inside. |
|
391 | - * |
|
392 | - * @param array $wp Passed in the `wp` hook. Not used. |
|
393 | - * |
|
394 | - * @return void |
|
395 | - */ |
|
396 | - public function parse_content($wp = []) |
|
397 | - { |
|
398 | - global $post; |
|
399 | - |
|
400 | - // If in admin and NOT AJAX request, get outta here. |
|
401 | - if (gravityview()->request->is_admin()) { |
|
402 | - return; |
|
403 | - } |
|
404 | - |
|
405 | - $is_GV_post_type = 'gravityview' === get_post_type($post); |
|
406 | - |
|
407 | - // Calculate requested Views |
|
408 | - $post_content = !empty($post->post_content) ? $post->post_content : null; |
|
409 | - |
|
410 | - if (!$is_GV_post_type && function_exists('parse_blocks') && preg_match_all('/"ref":\d+/', $post_content)) { |
|
411 | - $blocks = parse_blocks($post_content); |
|
412 | - |
|
413 | - foreach ($blocks as $block) { |
|
414 | - if (empty($block['attrs']['ref'])) { |
|
415 | - continue; |
|
416 | - } |
|
417 | - |
|
418 | - $block_post = get_post($block['attrs']['ref']); |
|
419 | - |
|
420 | - if ($block_post) { |
|
421 | - $post_content .= $block_post->post_content; |
|
422 | - } |
|
423 | - } |
|
424 | - |
|
425 | - $this->setGvOutputData(GravityView_View_Data::getInstance($post_content)); |
|
426 | - } else { |
|
427 | - $this->setGvOutputData(GravityView_View_Data::getInstance($post)); |
|
428 | - } |
|
429 | - |
|
430 | - // !important: we need to run this before getting single entry (to kick the advanced filter) |
|
431 | - $this->set_context_view_id(); |
|
432 | - |
|
433 | - $this->setIsGravityviewPostType($is_GV_post_type); |
|
434 | - |
|
435 | - $post_id = $this->getPostId() ? $this->getPostId() : (isset($post) ? $post->ID : null); |
|
436 | - $this->setPostId($post_id); |
|
437 | - $post_has_shortcode = $post_content ? gravityview_has_shortcode_r($post_content, 'gravityview') : false; |
|
438 | - $this->setPostHasShortcode($this->isGravityviewPostType() ? null : !empty($post_has_shortcode)); |
|
439 | - |
|
440 | - // check if the View is showing search results (only for multiple entries View) |
|
441 | - $this->setIsSearch($this->is_searching()); |
|
442 | - |
|
443 | - unset($entry, $post_id, $post_has_shortcode); |
|
444 | - } |
|
445 | - |
|
446 | - /** |
|
447 | - * Set the entry. |
|
448 | - */ |
|
449 | - public function set_entry_data() |
|
450 | - { |
|
451 | - $entry_id = self::is_single_entry(); |
|
452 | - $this->setSingleEntry($entry_id); |
|
453 | - $this->setEntry($entry_id); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Checks if the current View is presenting search results. |
|
458 | - * |
|
459 | - * @since 1.5.4 |
|
460 | - * |
|
461 | - * @return bool True: Yes, it's a search; False: No, not a search. |
|
462 | - */ |
|
463 | - public function is_searching() |
|
464 | - { |
|
465 | - |
|
466 | - // It's a single entry, not search |
|
467 | - if ($this->getSingleEntry()) { |
|
468 | - return false; |
|
469 | - } |
|
470 | - |
|
471 | - $search_method = GravityView_Widget_Search::getInstance()->get_search_method(); |
|
472 | - |
|
473 | - if ('post' === $search_method) { |
|
474 | - $get = $_POST; |
|
475 | - } else { |
|
476 | - $get = $_GET; |
|
477 | - } |
|
478 | - |
|
479 | - // No $_GET parameters |
|
480 | - if (empty($get) || !is_array($get)) { |
|
481 | - return false; |
|
482 | - } |
|
483 | - |
|
484 | - // Remove empty values |
|
485 | - $get = array_filter($get); |
|
486 | - |
|
487 | - // If the $_GET parameters are empty, it's no search. |
|
488 | - if (empty($get)) { |
|
489 | - return false; |
|
490 | - } |
|
491 | - |
|
492 | - $search_keys = array_keys($get); |
|
493 | - |
|
494 | - $search_match = implode('|', self::$search_parameters); |
|
495 | - |
|
496 | - foreach ($search_keys as $search_key) { |
|
497 | - |
|
498 | - // Analyze the search key $_GET parameter and see if it matches known GV args |
|
499 | - if (preg_match('/('.$search_match.')/i', $search_key)) { |
|
500 | - return true; |
|
501 | - } |
|
502 | - } |
|
503 | - |
|
504 | - return false; |
|
505 | - } |
|
506 | - |
|
507 | - /** |
|
508 | - * Filter the title for the single entry view. |
|
509 | - * |
|
510 | - * @param string $passed_title Current title |
|
511 | - * @param int $passed_post_id Post ID |
|
512 | - * |
|
513 | - * @return string (modified) title |
|
514 | - */ |
|
515 | - public function single_entry_title($passed_title, $passed_post_id = null) |
|
516 | - { |
|
517 | - global $post; |
|
518 | - |
|
519 | - // Since this is a public method, it can be called outside of the plugin. Don't assume things have been loaded properly. |
|
520 | - if (!class_exists('\GV\Entry')) { |
|
521 | - return $passed_title; |
|
522 | - } |
|
523 | - |
|
524 | - $gventry = gravityview()->request->is_entry(); |
|
525 | - |
|
526 | - // If this is the directory view, return. |
|
527 | - if (!$gventry) { |
|
528 | - return $passed_title; |
|
529 | - } |
|
530 | - |
|
531 | - $entry = $gventry->as_entry(); |
|
532 | - |
|
533 | - /** |
|
534 | - * @filter `gravityview/single/title/out_loop` Apply the Single Entry Title filter outside the WordPress loop? |
|
535 | - * |
|
536 | - * @param bool $in_the_loop Whether to apply the filter to the menu title and the meta tag <title> - outside the loop |
|
537 | - * @param array $entry Current entry |
|
538 | - */ |
|
539 | - $apply_outside_loop = apply_filters('gravityview/single/title/out_loop', in_the_loop(), $entry); |
|
540 | - |
|
541 | - if (!$apply_outside_loop) { |
|
542 | - return $passed_title; |
|
543 | - } |
|
544 | - |
|
545 | - // WooCommerce doesn't $post_id |
|
546 | - if (empty($passed_post_id)) { |
|
547 | - return $passed_title; |
|
548 | - } |
|
549 | - |
|
550 | - // Don't modify the title for anything other than the current view/post. |
|
551 | - // This is true for embedded shortcodes and Views. |
|
552 | - if (is_object($post) && (int) $post->ID !== (int) $passed_post_id) { |
|
553 | - return $passed_title; |
|
554 | - } |
|
555 | - |
|
556 | - $view = gravityview()->request->is_view(); |
|
557 | - |
|
558 | - if ($view) { |
|
559 | - return $this->_get_single_entry_title($view, $entry, $passed_title); |
|
560 | - } |
|
561 | - |
|
562 | - $_gvid = \GV\Utils::_GET('gvid', null); |
|
563 | - |
|
564 | - // $_GET['gvid'] is set; we know what View to render |
|
565 | - if ($_gvid) { |
|
566 | - $view = \GV\View::by_id($_gvid); |
|
567 | - |
|
568 | - return $this->_get_single_entry_title($view, $entry, $passed_title); |
|
569 | - } |
|
570 | - |
|
571 | - global $post; |
|
572 | - |
|
573 | - if (!$post) { |
|
574 | - return $passed_title; |
|
575 | - } |
|
576 | - |
|
577 | - $view_collection = \GV\View_Collection::from_post($post); |
|
578 | - |
|
579 | - // We have multiple Views, but no gvid...this isn't valid security |
|
580 | - if (1 < $view_collection->count()) { |
|
581 | - return $passed_title; |
|
582 | - } |
|
583 | - |
|
584 | - return $this->_get_single_entry_title($view_collection->first(), $entry, $passed_title); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Returns the single entry title for a View with variables replaced and shortcodes parsed. |
|
589 | - * |
|
590 | - * @since 2.7.2 |
|
591 | - * |
|
592 | - * @param \GV\View|null $view |
|
593 | - * @param array $entry |
|
594 | - * @param string $passed_title |
|
595 | - * |
|
596 | - * @return string |
|
597 | - */ |
|
598 | - private function _get_single_entry_title($view, $entry = [], $passed_title = '') |
|
599 | - { |
|
600 | - if (!$view) { |
|
601 | - return $passed_title; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * @filter `gravityview/single/title/check_entry_display` Override whether to check entry display rules against filters |
|
606 | - * |
|
607 | - * @internal This might change in the future! Don't rely on it. |
|
608 | - * |
|
609 | - * @since 2.7.2 |
|
610 | - * |
|
611 | - * @param bool $check_entry_display Check whether the entry is visible for the current View configuration. Default: true. |
|
612 | - * @param array $entry Gravity Forms entry array |
|
613 | - * @param \GV\View $view The View |
|
614 | - */ |
|
615 | - $check_entry_display = apply_filters('gravityview/single/title/check_entry_display', true, $entry, $view); |
|
616 | - |
|
617 | - if ($check_entry_display) { |
|
618 | - $check_display = GVCommon::check_entry_display($entry, $view); |
|
619 | - |
|
620 | - if (is_wp_error($check_display)) { |
|
621 | - return $passed_title; |
|
622 | - } |
|
623 | - } |
|
624 | - |
|
625 | - $title = $view->settings->get('single_title', $passed_title); |
|
626 | - |
|
627 | - $form = GVCommon::get_form($entry['form_id']); |
|
628 | - |
|
629 | - // We are allowing HTML in the fields, so no escaping the output |
|
630 | - $title = GravityView_API::replace_variables($title, $form, $entry); |
|
631 | - |
|
632 | - $title = do_shortcode($title); |
|
633 | - |
|
634 | - return $title; |
|
635 | - } |
|
636 | - |
|
637 | - /** |
|
638 | - * In case View post is called directly, insert the view in the post content. |
|
639 | - * |
|
640 | - * @deprecated Use \GV\View::content() instead. |
|
641 | - * |
|
642 | - * @static |
|
643 | - * |
|
644 | - * @param mixed $content |
|
645 | - * |
|
646 | - * @return string Add the View output into View CPT content |
|
647 | - */ |
|
648 | - public function insert_view_in_content($content) |
|
649 | - { |
|
650 | - gravityview()->log->notice('\GravityView_frontend::insert_view_in_content is deprecated. Use \GV\View::content()'); |
|
651 | - |
|
652 | - return \GV\View::content($content); |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * Disable comments on GravityView post types. |
|
657 | - * |
|
658 | - * @param bool $open existing status |
|
659 | - * @param int $post_id Post ID |
|
660 | - * |
|
661 | - * @return bool |
|
662 | - */ |
|
663 | - public function comments_open($open, $post_id) |
|
664 | - { |
|
665 | - if ($this->isGravityviewPostType()) { |
|
666 | - $open = false; |
|
667 | - } |
|
668 | - |
|
669 | - /** |
|
670 | - * @filter `gravityview/comments_open` Whether to set comments to open or closed. |
|
671 | - * |
|
672 | - * @since 1.5.4 |
|
673 | - * |
|
674 | - * @param bool $open Open or closed status |
|
675 | - * @param int $post_id Post ID to set comment status for |
|
676 | - */ |
|
677 | - $open = apply_filters('gravityview/comments_open', $open, $post_id); |
|
678 | - |
|
679 | - return $open; |
|
680 | - } |
|
681 | - |
|
682 | - /** |
|
683 | - * Display a warning when a View has not been configured. |
|
684 | - * |
|
685 | - * @since 1.19.2 |
|
686 | - * |
|
687 | - * @param int $view_id The ID of the View currently being displayed |
|
688 | - * |
|
689 | - * @return void |
|
690 | - */ |
|
691 | - public function context_not_configured_warning($view_id = 0) |
|
692 | - { |
|
693 | - if (!class_exists('GravityView_View')) { |
|
694 | - return; |
|
695 | - } |
|
696 | - |
|
697 | - $fields = GravityView_View::getInstance()->getContextFields(); |
|
698 | - |
|
699 | - if (!empty($fields)) { |
|
700 | - return; |
|
701 | - } |
|
702 | - |
|
703 | - $context = GravityView_View::getInstance()->getContext(); |
|
704 | - |
|
705 | - switch ($context) { |
|
706 | - case 'directory': |
|
707 | - $tab = __('Multiple Entries', 'gravityview'); |
|
708 | - break; |
|
709 | - case 'edit': |
|
710 | - $tab = __('Edit Entry', 'gravityview'); |
|
711 | - break; |
|
712 | - case 'single': |
|
713 | - default: |
|
714 | - $tab = __('Single Entry', 'gravityview'); |
|
715 | - break; |
|
716 | - } |
|
717 | - |
|
718 | - $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); |
|
719 | - $edit_link = admin_url(sprintf('post.php?post=%d&action=edit#%s-view', $view_id, $context)); |
|
720 | - $action_text = sprintf(esc_html__('Add fields to %s', 'gravityview'), $tab); |
|
721 | - $message = esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
722 | - |
|
723 | - $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))); |
|
724 | - $output = sprintf('<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>', $title, esc_url($edit_link), $action_text, $message); |
|
725 | - |
|
726 | - echo GVCommon::generate_notice($output.$image, 'gv-error error', 'edit_gravityview', $view_id); |
|
727 | - } |
|
728 | - |
|
729 | - /** |
|
730 | - * Core function to render a View based on a set of arguments. |
|
731 | - * |
|
732 | - * @static |
|
733 | - * |
|
734 | - * @param array $passed_args { |
|
735 | - * |
|
736 | - * Settings for rendering the View |
|
737 | - * |
|
738 | - * @var int $id View id |
|
739 | - * @var int $page_size Number of entries to show per page |
|
740 | - * @var string $sort_field Form field id to sort |
|
741 | - * @var string $sort_direction Sorting direction ('ASC', 'DESC', or 'RAND') |
|
742 | - * @var string $start_date - Ymd |
|
743 | - * @var string $end_date - Ymd |
|
744 | - * @var string $class - assign a html class to the view |
|
745 | - * @var string $offset (optional) - This is the start point in the current data set (0 index based). |
|
746 | - * } |
|
747 | - * |
|
748 | - * @deprecated Use \GV\View_Renderer |
|
749 | - * |
|
750 | - * @return string|null HTML output of a View, NULL if View isn't found |
|
751 | - */ |
|
752 | - public function render_view($passed_args) |
|
753 | - { |
|
754 | - gravityview()->log->notice('\GravityView_frontend::render_view is deprecated. Use \GV\View_Renderer etc.'); |
|
755 | - |
|
756 | - /** |
|
757 | - * We can use a shortcode here, since it's pretty much the same. |
|
758 | - * |
|
759 | - * But we do need to check embed permissions, since shortcodes don't do this. |
|
760 | - */ |
|
761 | - if (!$view = gravityview()->views->get($passed_args)) { |
|
762 | - return null; |
|
763 | - } |
|
764 | - |
|
765 | - $view->settings->update($passed_args); |
|
766 | - |
|
767 | - $direct_access = apply_filters('gravityview_direct_access', true, $view->ID); |
|
768 | - $embed_only = $view->settings->get('embed_only'); |
|
769 | - |
|
770 | - if (!$direct_access || ($embed_only && !GVCommon::has_cap('read_private_gravityviews'))) { |
|
771 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
772 | - } |
|
773 | - |
|
774 | - $shortcode = new \GV\Shortcodes\gravityview(); |
|
775 | - |
|
776 | - return $shortcode->callback($passed_args); |
|
777 | - } |
|
778 | - |
|
779 | - /** |
|
780 | - * Process the start and end dates for a view - overrides values defined in shortcode (if needed). |
|
781 | - * |
|
782 | - * The `start_date` and `end_date` keys need to be in a format processable by GFFormsModel::get_date_range_where(), |
|
783 | - * which uses \DateTime() format. |
|
784 | - * |
|
785 | - * You can set the `start_date` or `end_date` to any value allowed by {@link http://www.php.net//manual/en/function.strtotime.php strtotime()}, |
|
786 | - * including strings like "now" or "-1 year" or "-3 days". |
|
787 | - * |
|
788 | - * @see GFFormsModel::get_date_range_where |
|
789 | - * |
|
790 | - * @param array $args View settings |
|
791 | - * @param array $search_criteria Search being performed, if any |
|
792 | - * |
|
793 | - * @return array Modified `$search_criteria` array |
|
794 | - */ |
|
795 | - public static function process_search_dates($args, $search_criteria = []) |
|
796 | - { |
|
797 | - $return_search_criteria = $search_criteria; |
|
798 | - |
|
799 | - foreach (['start_date', 'end_date'] as $key) { |
|
800 | - |
|
801 | - // Is the start date or end date set in the view or shortcode? |
|
802 | - // If so, we want to make sure that the search doesn't go outside the bounds defined. |
|
803 | - if (!empty($args[$key])) { |
|
804 | - |
|
805 | - // Get a timestamp and see if it's a valid date format |
|
806 | - $date = strtotime($args[$key], GFCommon::get_local_timestamp()); |
|
807 | - |
|
808 | - // The date was invalid |
|
809 | - if (empty($date)) { |
|
810 | - gravityview()->log->error(' Invalid {key} date format: {format}', ['key' => $key, 'format' => $args[$key]]); |
|
811 | - continue; |
|
812 | - } |
|
813 | - |
|
814 | - // The format that Gravity Forms expects for start_date and day-specific (not hour/second-specific) end_date |
|
815 | - $datetime_format = 'Y-m-d H:i:s'; |
|
816 | - $search_is_outside_view_bounds = false; |
|
817 | - |
|
818 | - if (!empty($search_criteria[$key])) { |
|
819 | - $search_date = strtotime($search_criteria[$key], GFCommon::get_local_timestamp()); |
|
820 | - |
|
821 | - // The search is for entries before the start date defined by the settings |
|
822 | - switch ($key) { |
|
823 | - case 'end_date': |
|
824 | - /** |
|
825 | - * If the end date is formatted as 'Y-m-d', it should be formatted without hours and seconds |
|
826 | - * so that Gravity Forms can convert the day to 23:59:59 the previous day. |
|
827 | - * |
|
828 | - * If it's a relative date ("now" or "-1 day"), then it should use the precise date format |
|
829 | - * |
|
830 | - * @see GFFormsModel::get_date_range_where |
|
831 | - */ |
|
832 | - $datetime_format = gravityview_is_valid_datetime($args[$key]) ? 'Y-m-d' : $datetime_format; |
|
833 | - $search_is_outside_view_bounds = ($search_date > $date); |
|
834 | - break; |
|
835 | - case 'start_date': |
|
836 | - $search_is_outside_view_bounds = ($search_date < $date); |
|
837 | - break; |
|
838 | - } |
|
839 | - } |
|
840 | - |
|
841 | - // If there is no search being performed, or if there is a search being performed that's outside the bounds |
|
842 | - if (empty($search_criteria[$key]) || $search_is_outside_view_bounds) { |
|
843 | - |
|
844 | - // Then we override the search and re-set the start date |
|
845 | - $return_search_criteria[$key] = date_i18n($datetime_format, $date, true); |
|
846 | - } |
|
847 | - } |
|
848 | - } |
|
849 | - |
|
850 | - if (isset($return_search_criteria['start_date']) && isset($return_search_criteria['end_date'])) { |
|
851 | - // The start date is AFTER the end date. This will result in no results, but let's not force the issue. |
|
852 | - if (strtotime($return_search_criteria['start_date']) > strtotime($return_search_criteria['end_date'])) { |
|
853 | - gravityview()->log->error('Invalid search: the start date is after the end date.', ['data' => $return_search_criteria]); |
|
854 | - } |
|
855 | - } |
|
856 | - |
|
857 | - return $return_search_criteria; |
|
858 | - } |
|
859 | - |
|
860 | - /** |
|
861 | - * Process the approved only search criteria according to the View settings. |
|
862 | - * |
|
863 | - * @param array $args View settings |
|
864 | - * @param array $search_criteria Search being performed, if any |
|
865 | - * |
|
866 | - * @return array Modified `$search_criteria` array |
|
867 | - */ |
|
868 | - public static function process_search_only_approved($args, $search_criteria) |
|
869 | - { |
|
870 | - |
|
871 | - /** @since 1.19 */ |
|
872 | - if (!empty($args['admin_show_all_statuses']) && GVCommon::has_cap('gravityview_moderate_entries')) { |
|
873 | - gravityview()->log->debug('User can moderate entries; showing all approval statuses'); |
|
874 | - |
|
875 | - return $search_criteria; |
|
876 | - } |
|
877 | - |
|
878 | - if (!empty($args['show_only_approved'])) { |
|
879 | - $search_criteria['field_filters'][] = [ |
|
880 | - 'key' => GravityView_Entry_Approval::meta_key, |
|
881 | - 'value' => GravityView_Entry_Approval_Status::APPROVED, |
|
882 | - ]; |
|
883 | - |
|
884 | - $search_criteria['field_filters']['mode'] = 'all'; // force all the criterias to be met |
|
885 | - |
|
886 | - gravityview()->log->debug('[process_search_only_approved] Search Criteria if show only approved: ', ['data' => $search_criteria]); |
|
887 | - } |
|
888 | - |
|
889 | - return $search_criteria; |
|
890 | - } |
|
891 | - |
|
892 | - /** |
|
893 | - * Check if a certain entry is approved. |
|
894 | - * |
|
895 | - * If we pass the View settings ($args) it will check the 'show_only_approved' setting before |
|
896 | - * checking the entry approved field, returning true if show_only_approved = false. |
|
897 | - * |
|
898 | - * @since 1.7 |
|
899 | - * @since 1.18 Converted check to use GravityView_Entry_Approval_Status::is_approved |
|
900 | - * |
|
901 | - * @uses GravityView_Entry_Approval_Status::is_approved |
|
902 | - * |
|
903 | - * @param array $entry Entry object |
|
904 | - * @param array $args View settings (optional) |
|
905 | - * |
|
906 | - * @return bool |
|
907 | - */ |
|
908 | - public static function is_entry_approved($entry, $args = []) |
|
909 | - { |
|
910 | - if (empty($entry['id']) || (array_key_exists('show_only_approved', $args) && !$args['show_only_approved'])) { |
|
911 | - // is implicitly approved if entry is null or View settings doesn't require to check for approval |
|
912 | - return true; |
|
913 | - } |
|
914 | - |
|
915 | - /** @since 1.19 */ |
|
916 | - if (!empty($args['admin_show_all_statuses']) && GVCommon::has_cap('gravityview_moderate_entries')) { |
|
917 | - gravityview()->log->debug('User can moderate entries, so entry is approved for viewing'); |
|
918 | - |
|
919 | - return true; |
|
920 | - } |
|
921 | - |
|
922 | - $is_approved = gform_get_meta($entry['id'], GravityView_Entry_Approval::meta_key); |
|
923 | - |
|
924 | - return GravityView_Entry_Approval_Status::is_approved($is_approved); |
|
925 | - } |
|
926 | - |
|
927 | - /** |
|
928 | - * Parse search criteria for a entries search. |
|
929 | - * |
|
930 | - * array( |
|
931 | - * 'search_field' => 1, // ID of the field |
|
932 | - * 'search_value' => '', // Value of the field to search |
|
933 | - * 'search_operator' => 'contains', // 'is', 'isnot', '>', '<', 'contains' |
|
934 | - * 'show_only_approved' => 0 or 1 // Boolean |
|
935 | - * ) |
|
936 | - * |
|
937 | - * @param array $args Array of args |
|
938 | - * @param int $form_id Gravity Forms form ID |
|
939 | - * |
|
940 | - * @return array Array of search parameters, formatted in Gravity Forms mode, using `status` key set to "active" by default, `field_filters` array with `key`, `value` and `operator` keys. |
|
941 | - */ |
|
942 | - public static function get_search_criteria($args, $form_id) |
|
943 | - { |
|
944 | - /** |
|
945 | - * Compatibility with filters hooking in `gravityview_search_criteria` instead of `gravityview_fe_search_criteria`. |
|
946 | - */ |
|
947 | - $criteria = apply_filters('gravityview_search_criteria', [], [$form_id], \GV\Utils::get($args, 'id')); |
|
948 | - $search_criteria = isset($criteria['search_criteria']) ? $criteria['search_criteria'] : ['field_filters' => []]; |
|
949 | - |
|
950 | - /** |
|
951 | - * @filter `gravityview_fe_search_criteria` Modify the search criteria |
|
952 | - * |
|
953 | - * @see GravityView_Widget_Search::filter_entries Adds the default search criteria |
|
954 | - * |
|
955 | - * @param array $search_criteria Empty `field_filters` key |
|
956 | - * @param int $form_id ID of the Gravity Forms form that is being searched |
|
957 | - * @param array $args The View settings. |
|
958 | - */ |
|
959 | - $search_criteria = apply_filters('gravityview_fe_search_criteria', $search_criteria, $form_id, $args); |
|
960 | - |
|
961 | - if (!is_array($search_criteria)) { |
|
962 | - return []; |
|
963 | - } |
|
964 | - |
|
965 | - $original_search_criteria = $search_criteria; |
|
966 | - |
|
967 | - gravityview()->log->debug('[get_search_criteria] Search Criteria after hook gravityview_fe_search_criteria: ', ['data' =>$search_criteria]); |
|
968 | - |
|
969 | - // implicity search |
|
970 | - if (!empty($args['search_value'])) { |
|
971 | - |
|
972 | - // Search operator options. Options: `is` or `contains` |
|
973 | - $operator = !empty($args['search_operator']) && in_array($args['search_operator'], ['is', 'isnot', '>', '<', 'contains']) ? $args['search_operator'] : 'contains'; |
|
974 | - |
|
975 | - $search_criteria['field_filters'][] = [ |
|
976 | - 'key' => \GV\Utils::_GET('search_field', \GV\Utils::get($args, 'search_field')), // The field ID to search |
|
977 | - 'value' => _wp_specialchars($args['search_value']), // The value to search. Encode ampersands but not quotes. |
|
978 | - 'operator' => $operator, |
|
979 | - ]; |
|
980 | - |
|
981 | - // Lock search mode to "all" with implicit presearch filter. |
|
982 | - $search_criteria['field_filters']['mode'] = 'all'; |
|
983 | - } |
|
984 | - |
|
985 | - if ($search_criteria !== $original_search_criteria) { |
|
986 | - gravityview()->log->debug('[get_search_criteria] Search Criteria after implicity search: ', ['data' => $search_criteria]); |
|
987 | - } |
|
988 | - |
|
989 | - // Handle setting date range |
|
990 | - $search_criteria = self::process_search_dates($args, $search_criteria); |
|
991 | - |
|
992 | - if ($search_criteria !== $original_search_criteria) { |
|
993 | - gravityview()->log->debug('[get_search_criteria] Search Criteria after date params: ', ['data' => $search_criteria]); |
|
994 | - } |
|
995 | - |
|
996 | - // remove not approved entries |
|
997 | - $search_criteria = self::process_search_only_approved($args, $search_criteria); |
|
998 | - |
|
999 | - /** |
|
1000 | - * @filter `gravityview_status` Modify entry status requirements to be included in search results. |
|
1001 | - * |
|
1002 | - * @param string $status Default: `active`. Accepts all Gravity Forms entry statuses, including `spam` and `trash` |
|
1003 | - */ |
|
1004 | - $search_criteria['status'] = apply_filters('gravityview_status', 'active', $args); |
|
1005 | - |
|
1006 | - return $search_criteria; |
|
1007 | - } |
|
1008 | - |
|
1009 | - /** |
|
1010 | - * Core function to calculate View multi entries (directory) based on a set of arguments ($args): |
|
1011 | - * $id - View id |
|
1012 | - * $page_size - Page |
|
1013 | - * $sort_field - form field id to sort |
|
1014 | - * $sort_direction - ASC / DESC |
|
1015 | - * $start_date - Ymd |
|
1016 | - * $end_date - Ymd |
|
1017 | - * $class - assign a html class to the view |
|
1018 | - * $offset (optional) - This is the start point in the current data set (0 index based). |
|
1019 | - * |
|
1020 | - * |
|
1021 | - * |
|
1022 | - * @uses gravityview_get_entries() |
|
1023 | - * |
|
1024 | - * @param array $args\n |
|
1025 | - * - $id - View id |
|
1026 | - * - $page_size - Page |
|
1027 | - * - $sort_field - form field id to sort |
|
1028 | - * - $sort_direction - ASC / DESC |
|
1029 | - * - $start_date - Ymd |
|
1030 | - * - $end_date - Ymd |
|
1031 | - * - $class - assign a html class to the view |
|
1032 | - * - $offset (optional) - This is the start point in the current data set (0 index based). |
|
1033 | - * @param int $form_id Gravity Forms Form ID |
|
1034 | - * |
|
1035 | - * @return array Associative array with `count`, `entries`, and `paging` keys. `count` has the total entries count, `entries` is an array with Gravity Forms full entry data, `paging` is an array with `offset` and `page_size` keys |
|
1036 | - */ |
|
1037 | - public static function get_view_entries($args, $form_id) |
|
1038 | - { |
|
1039 | - gravityview()->log->debug('[get_view_entries] init'); |
|
1040 | - // start filters and sorting |
|
1041 | - |
|
1042 | - $parameters = self::get_view_entries_parameters($args, $form_id); |
|
1043 | - |
|
1044 | - $count = 0; // Must be defined so that gravityview_get_entries can use by reference |
|
1045 | - |
|
1046 | - // fetch entries |
|
1047 | - list($entries, $paging, $count) = |
|
1048 | - \GV\Mocks\GravityView_frontend_get_view_entries($args, $form_id, $parameters, $count); |
|
1049 | - |
|
1050 | - gravityview()->log->debug('Get Entries. Found: {count} entries', ['count' => $count, 'data' => $entries]); |
|
1051 | - |
|
1052 | - /** |
|
1053 | - * @filter `gravityview_view_entries` Filter the entries output to the View |
|
1054 | - * |
|
1055 | - * @deprecated since 1.5.2 |
|
1056 | - * |
|
1057 | - * @param array $args View settings associative array |
|
1058 | - * |
|
1059 | - * @var array |
|
1060 | - */ |
|
1061 | - $entries = apply_filters('gravityview_view_entries', $entries, $args); |
|
1062 | - |
|
1063 | - $return = [ |
|
1064 | - 'count' => $count, |
|
1065 | - 'entries' => $entries, |
|
1066 | - 'paging' => $paging, |
|
1067 | - ]; |
|
1068 | - |
|
1069 | - /** |
|
1070 | - * @filter `gravityview/view/entries` Filter the entries output to the View |
|
1071 | - * |
|
1072 | - * @param array $criteria associative array containing count, entries & paging |
|
1073 | - * @param array $args View settings associative array |
|
1074 | - * |
|
1075 | - * @since 1.5.2 |
|
1076 | - */ |
|
1077 | - return apply_filters('gravityview/view/entries', $return, $args); |
|
1078 | - } |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * Get an array of search parameters formatted as Gravity Forms requires. |
|
1082 | - * |
|
1083 | - * Results are filtered by `gravityview_get_entries` and `gravityview_get_entries_{View ID}` filters |
|
1084 | - * |
|
1085 | - * @uses GravityView_frontend::get_search_criteria |
|
1086 | - * @uses GravityView_frontend::get_search_criteria_paging |
|
1087 | - * |
|
1088 | - * @since 1.20 |
|
1089 | - * @see \GV\View_Settings::defaults For $args options |
|
1090 | - * |
|
1091 | - * @param array $args Array of View settings, as structured in \GV\View_Settings::defaults |
|
1092 | - * @param int $form_id Gravity Forms form ID to search |
|
1093 | - * |
|
1094 | - * @return array With `search_criteria`, `sorting`, `paging`, `cache` keys |
|
1095 | - */ |
|
1096 | - public static function get_view_entries_parameters($args = [], $form_id = 0) |
|
1097 | - { |
|
1098 | - if (!is_array($args) || !is_numeric($form_id)) { |
|
1099 | - gravityview()->log->error('Passed args are not an array or the form ID is not numeric'); |
|
1100 | - |
|
1101 | - return []; |
|
1102 | - } |
|
1103 | - |
|
1104 | - $form_id = intval($form_id); |
|
1105 | - |
|
1106 | - /** |
|
1107 | - * Process search parameters. |
|
1108 | - * |
|
1109 | - * @var array |
|
1110 | - */ |
|
1111 | - $search_criteria = self::get_search_criteria($args, $form_id); |
|
1112 | - |
|
1113 | - $paging = self::get_search_criteria_paging($args); |
|
1114 | - |
|
1115 | - $parameters = [ |
|
1116 | - 'search_criteria' => $search_criteria, |
|
1117 | - 'sorting' => self::updateViewSorting($args, $form_id), |
|
1118 | - 'paging' => $paging, |
|
1119 | - 'cache' => isset($args['cache']) ? $args['cache'] : true, |
|
1120 | - ]; |
|
1121 | - |
|
1122 | - /** |
|
1123 | - * @filter `gravityview_get_entries` Filter get entries criteria |
|
1124 | - * |
|
1125 | - * @param array $parameters Array with `search_criteria`, `sorting` and `paging` keys. |
|
1126 | - * @param array $args View configuration args. { |
|
1127 | - * |
|
1128 | - * @var int $id View id |
|
1129 | - * @var int $page_size Number of entries to show per page |
|
1130 | - * @var string $sort_field Form field id to sort |
|
1131 | - * @var string $sort_direction Sorting direction ('ASC', 'DESC', or 'RAND') |
|
1132 | - * @var string $start_date - Ymd |
|
1133 | - * @var string $end_date - Ymd |
|
1134 | - * @var string $class - assign a html class to the view |
|
1135 | - * @var string $offset (optional) - This is the start point in the current data set (0 index based). |
|
1136 | - * } |
|
1137 | - * |
|
1138 | - * @param int $form_id ID of Gravity Forms form |
|
1139 | - */ |
|
1140 | - $parameters = apply_filters('gravityview_get_entries', $parameters, $args, $form_id); |
|
1141 | - |
|
1142 | - /** |
|
1143 | - * @filter `gravityview_get_entries_{View ID}` Filter get entries criteria |
|
1144 | - * |
|
1145 | - * @param array $parameters Array with `search_criteria`, `sorting` and `paging` keys. |
|
1146 | - * @param array $args View configuration args. |
|
1147 | - */ |
|
1148 | - $parameters = apply_filters('gravityview_get_entries_'.\GV\Utils::get($args, 'id'), $parameters, $args, $form_id); |
|
1149 | - |
|
1150 | - gravityview()->log->debug('$parameters passed to gravityview_get_entries(): ', ['data' => $parameters]); |
|
1151 | - |
|
1152 | - return $parameters; |
|
1153 | - } |
|
1154 | - |
|
1155 | - /** |
|
1156 | - * Get the paging array for the View. |
|
1157 | - * |
|
1158 | - * @since 1.19.5 |
|
1159 | - * |
|
1160 | - * @param $args |
|
1161 | - * @param int $form_id |
|
1162 | - */ |
|
1163 | - public static function get_search_criteria_paging($args) |
|
1164 | - { |
|
1165 | - |
|
1166 | - /** |
|
1167 | - * @filter `gravityview_default_page_size` The default number of entries displayed in a View |
|
1168 | - * |
|
1169 | - * @since 1.1.6 |
|
1170 | - * |
|
1171 | - * @param int $default_page_size Default: 25 |
|
1172 | - */ |
|
1173 | - $default_page_size = apply_filters('gravityview_default_page_size', 25); |
|
1174 | - |
|
1175 | - // Paging & offset |
|
1176 | - $page_size = !empty($args['page_size']) ? intval($args['page_size']) : $default_page_size; |
|
1177 | - |
|
1178 | - if (-1 === $page_size) { |
|
1179 | - $page_size = PHP_INT_MAX; |
|
1180 | - } |
|
1181 | - |
|
1182 | - $curr_page = empty($_GET['pagenum']) ? 1 : intval($_GET['pagenum']); |
|
1183 | - $offset = ($curr_page - 1) * $page_size; |
|
1184 | - |
|
1185 | - if (!empty($args['offset'])) { |
|
1186 | - $offset += intval($args['offset']); |
|
1187 | - } |
|
1188 | - |
|
1189 | - $paging = [ |
|
1190 | - 'offset' => $offset, |
|
1191 | - 'page_size' => $page_size, |
|
1192 | - ]; |
|
1193 | - |
|
1194 | - gravityview()->log->debug('Paging: ', ['data' => $paging]); |
|
1195 | - |
|
1196 | - return $paging; |
|
1197 | - } |
|
1198 | - |
|
1199 | - /** |
|
1200 | - * Updates the View sorting criteria. |
|
1201 | - * |
|
1202 | - * @since 1.7 |
|
1203 | - * |
|
1204 | - * @param array $args View settings. Required to have `sort_field` and `sort_direction` keys |
|
1205 | - * @param int $form_id The ID of the form used to sort |
|
1206 | - * |
|
1207 | - * @return array $sorting Array with `key`, `direction` and `is_numeric` keys |
|
1208 | - */ |
|
1209 | - public static function updateViewSorting($args, $form_id) |
|
1210 | - { |
|
1211 | - $sorting = []; |
|
1212 | - |
|
1213 | - $has_values = isset($_GET['sort']); |
|
1214 | - |
|
1215 | - if ($has_values && is_array($_GET['sort'])) { |
|
1216 | - $sorts = array_keys($_GET['sort']); |
|
1217 | - $dirs = array_values($_GET['sort']); |
|
1218 | - |
|
1219 | - if ($has_values = array_filter($dirs)) { |
|
1220 | - $sort_field_id = end($sorts); |
|
1221 | - $sort_direction = end($dirs); |
|
1222 | - } |
|
1223 | - } |
|
1224 | - |
|
1225 | - if (!isset($sort_field_id)) { |
|
1226 | - $sort_field_id = isset($_GET['sort']) ? $_GET['sort'] : \GV\Utils::get($args, 'sort_field'); |
|
1227 | - } |
|
1228 | - |
|
1229 | - if (!isset($sort_direction)) { |
|
1230 | - $sort_direction = isset($_GET['dir']) ? $_GET['dir'] : \GV\Utils::get($args, 'sort_direction'); |
|
1231 | - } |
|
1232 | - |
|
1233 | - if (is_array($sort_field_id)) { |
|
1234 | - $sort_field_id = array_pop($sort_field_id); |
|
1235 | - } |
|
1236 | - |
|
1237 | - if (is_array($sort_direction)) { |
|
1238 | - $sort_direction = array_pop($sort_direction); |
|
1239 | - } |
|
1240 | - |
|
1241 | - if (!empty($sort_field_id)) { |
|
1242 | - if (is_array($sort_field_id)) { |
|
1243 | - $sort_direction = array_values($sort_field_id); |
|
1244 | - $sort_field_id = array_keys($sort_field_id); |
|
1245 | - |
|
1246 | - $sort_field_id = reset($sort_field_id); |
|
1247 | - $sort_direction = reset($sort_direction); |
|
1248 | - } |
|
1249 | - |
|
1250 | - $sort_field_id = self::_override_sorting_id_by_field_type($sort_field_id, $form_id); |
|
1251 | - $sorting = [ |
|
1252 | - 'key' => $sort_field_id, |
|
1253 | - 'direction' => strtolower($sort_direction), |
|
1254 | - 'is_numeric' => GVCommon::is_field_numeric($form_id, $sort_field_id), |
|
1255 | - ]; |
|
1256 | - |
|
1257 | - if ('RAND' === $sort_direction) { |
|
1258 | - $form = GFAPI::get_form($form_id); |
|
1259 | - |
|
1260 | - // Get the first GF_Field field ID, set as the key for entry randomization |
|
1261 | - if (!empty($form['fields'])) { |
|
1262 | - |
|
1263 | - /** @var GF_Field $field */ |
|
1264 | - foreach ($form['fields'] as $field) { |
|
1265 | - if (!is_a($field, 'GF_Field')) { |
|
1266 | - continue; |
|
1267 | - } |
|
1268 | - |
|
1269 | - $sorting = [ |
|
1270 | - 'key' => $field->id, |
|
1271 | - 'is_numeric' => false, |
|
1272 | - 'direction' => 'RAND', |
|
1273 | - ]; |
|
1274 | - |
|
1275 | - break; |
|
1276 | - } |
|
1277 | - } |
|
1278 | - } |
|
1279 | - } |
|
1280 | - |
|
1281 | - if (!class_exists('GravityView_View')) { |
|
1282 | - gravityview()->plugin->include_legacy_frontend(true); |
|
1283 | - } |
|
1284 | - |
|
1285 | - GravityView_View::getInstance()->setSorting($sorting); |
|
1286 | - |
|
1287 | - gravityview()->log->debug('[updateViewSorting] Sort Criteria : ', ['data' => $sorting]); |
|
1288 | - |
|
1289 | - return $sorting; |
|
1290 | - } |
|
1291 | - |
|
1292 | - /** |
|
1293 | - * Override sorting per field. |
|
1294 | - * |
|
1295 | - * Currently only modifies sorting ID when sorting by the full name. Sorts by first name. |
|
1296 | - * Use the `gravityview/sorting/full-name` filter to override. |
|
1297 | - * |
|
1298 | - * @todo Filter from GravityView_Field |
|
1299 | - * |
|
1300 | - * @since 1.7.4 |
|
1301 | - * |
|
1302 | - * @internal Hi developer! Although this is public, don't call this method; we're going to replace it. |
|
1303 | - * |
|
1304 | - * @param int|string|array $sort_field_id Field used for sorting (`id` or `1.2`), or an array for multisorts |
|
1305 | - * @param int $form_id GF Form ID |
|
1306 | - * |
|
1307 | - * @return string|array Possibly modified sorting ID. Array if $sort_field_id is passed as array. |
|
1308 | - */ |
|
1309 | - public static function _override_sorting_id_by_field_type($sort_field_id, $form_id) |
|
1310 | - { |
|
1311 | - if (is_array($sort_field_id)) { |
|
1312 | - $modified_ids = []; |
|
1313 | - foreach ($sort_field_id as $_sort_field_id) { |
|
1314 | - $modified_ids[] = self::_override_sorting_id_by_field_type($_sort_field_id, $form_id); |
|
1315 | - } |
|
1316 | - |
|
1317 | - return $modified_ids; |
|
1318 | - } |
|
1319 | - |
|
1320 | - $form = gravityview_get_form($form_id); |
|
1321 | - |
|
1322 | - $sort_field = GFFormsModel::get_field($form, $sort_field_id); |
|
1323 | - |
|
1324 | - if (!$sort_field) { |
|
1325 | - return $sort_field_id; |
|
1326 | - } |
|
1327 | - |
|
1328 | - switch ($sort_field['type']) { |
|
1329 | - |
|
1330 | - case 'address': |
|
1331 | - // Sorting by full address |
|
1332 | - if (floatval($sort_field_id) === floor($sort_field_id)) { |
|
1333 | - |
|
1334 | - /** |
|
1335 | - * Override how to sort when sorting address. |
|
1336 | - * |
|
1337 | - * @since 1.8 |
|
1338 | - * |
|
1339 | - * @param string $address_part `street`, `street2`, `city`, `state`, `zip`, or `country` (default: `city`) |
|
1340 | - * @param string $sort_field_id Field used for sorting |
|
1341 | - * @param int $form_id GF Form ID |
|
1342 | - */ |
|
1343 | - $address_part = apply_filters('gravityview/sorting/address', 'city', $sort_field_id, $form_id); |
|
1344 | - |
|
1345 | - switch (strtolower($address_part)) { |
|
1346 | - case 'street': |
|
1347 | - $sort_field_id .= '.1'; |
|
1348 | - break; |
|
1349 | - case 'street2': |
|
1350 | - $sort_field_id .= '.2'; |
|
1351 | - break; |
|
1352 | - default: |
|
1353 | - case 'city': |
|
1354 | - $sort_field_id .= '.3'; |
|
1355 | - break; |
|
1356 | - case 'state': |
|
1357 | - $sort_field_id .= '.4'; |
|
1358 | - break; |
|
1359 | - case 'zip': |
|
1360 | - $sort_field_id .= '.5'; |
|
1361 | - break; |
|
1362 | - case 'country': |
|
1363 | - $sort_field_id .= '.6'; |
|
1364 | - break; |
|
1365 | - } |
|
1366 | - } |
|
1367 | - break; |
|
1368 | - case 'name': |
|
1369 | - // Sorting by full name, not first, last, etc. |
|
1370 | - if (floatval($sort_field_id) === floor($sort_field_id)) { |
|
1371 | - /** |
|
1372 | - * @filter `gravityview/sorting/full-name` Override how to sort when sorting full name. |
|
1373 | - * |
|
1374 | - * @since 1.7.4 |
|
1375 | - * |
|
1376 | - * @param string $name_part Sort by `first` or `last` (default: `first`) |
|
1377 | - * @param string $sort_field_id Field used for sorting |
|
1378 | - * @param int $form_id GF Form ID |
|
1379 | - */ |
|
1380 | - $name_part = apply_filters('gravityview/sorting/full-name', 'first', $sort_field_id, $form_id); |
|
1381 | - |
|
1382 | - if ('last' === strtolower($name_part)) { |
|
1383 | - $sort_field_id .= '.6'; |
|
1384 | - } else { |
|
1385 | - $sort_field_id .= '.3'; |
|
1386 | - } |
|
1387 | - } |
|
1388 | - break; |
|
1389 | - case 'list': |
|
1390 | - $sort_field_id = false; |
|
1391 | - break; |
|
1392 | - case 'time': |
|
1393 | - |
|
1394 | - /** |
|
1395 | - * @filter `gravityview/sorting/time` Override how to sort when sorting time |
|
1396 | - * |
|
1397 | - * @see GravityView_Field_Time |
|
1398 | - * @since 1.14 |
|
1399 | - * |
|
1400 | - * @param string $name_part Field used for sorting |
|
1401 | - * @param int $form_id GF Form ID |
|
1402 | - */ |
|
1403 | - $sort_field_id = apply_filters('gravityview/sorting/time', $sort_field_id, $form_id); |
|
1404 | - break; |
|
1405 | - } |
|
1406 | - |
|
1407 | - return $sort_field_id; |
|
1408 | - } |
|
1409 | - |
|
1410 | - /** |
|
1411 | - * Verify if user requested a single entry view. |
|
1412 | - * |
|
1413 | - * @since 2.3.3 Added return null |
|
1414 | - * |
|
1415 | - * @return bool|string|null false if not, single entry slug if true, null if \GV\Entry doesn't exist yet |
|
1416 | - */ |
|
1417 | - public static function is_single_entry() |
|
1418 | - { |
|
1419 | - |
|
1420 | - // Since this is a public method, it can be called outside of the plugin. Don't assume things have been loaded properly. |
|
1421 | - if (!class_exists('\GV\Entry')) { |
|
1422 | - |
|
1423 | - // Not using gravityview()->log->error(), since that may not exist yet either! |
|
1424 | - do_action('gravityview_log_error', '\GV\Entry not defined yet. Backtrace: '.wp_debug_backtrace_summary()); |
|
1425 | - |
|
1426 | - return null; |
|
1427 | - } |
|
1428 | - |
|
1429 | - $var_name = \GV\Entry::get_endpoint_name(); |
|
1430 | - |
|
1431 | - $single_entry = get_query_var($var_name); |
|
1432 | - |
|
1433 | - /** |
|
1434 | - * Modify the entry that is being displayed. |
|
1435 | - * |
|
1436 | - * @internal Should only be used by things like the oEmbed functionality. |
|
1437 | - * |
|
1438 | - * @since 1.6 |
|
1439 | - */ |
|
1440 | - $single_entry = apply_filters('gravityview/is_single_entry', $single_entry); |
|
1441 | - |
|
1442 | - if (empty($single_entry)) { |
|
1443 | - return false; |
|
1444 | - } else { |
|
1445 | - return $single_entry; |
|
1446 | - } |
|
1447 | - } |
|
1448 | - |
|
1449 | - /** |
|
1450 | - * Register styles and scripts. |
|
1451 | - * |
|
1452 | - * @return void |
|
1453 | - */ |
|
1454 | - public function add_scripts_and_styles() |
|
1455 | - { |
|
1456 | - global $post, $posts; |
|
1457 | - // enqueue template specific styles |
|
1458 | - if ($this->getGvOutputData()) { |
|
1459 | - $views = $this->getGvOutputData()->get_views(); |
|
1460 | - |
|
1461 | - foreach ($views as $view_id => $data) { |
|
1462 | - $view = \GV\View::by_id($data['id']); |
|
1463 | - $view_id = $view->ID; |
|
1464 | - $template_id = gravityview_get_template_id($view->ID); |
|
1465 | - $data = $view->as_data(); |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * Don't enqueue the scripts or styles if it's not going to be displayed. |
|
1469 | - * |
|
1470 | - * @since 1.15 |
|
1471 | - */ |
|
1472 | - if (is_user_logged_in() && false === GVCommon::has_cap('read_gravityview', $view_id)) { |
|
1473 | - continue; |
|
1474 | - } |
|
1475 | - |
|
1476 | - // By default, no thickbox |
|
1477 | - $js_dependencies = ['jquery', 'gravityview-jquery-cookie']; |
|
1478 | - $css_dependencies = []; |
|
1479 | - |
|
1480 | - $lightbox = $view->settings->get('lightbox'); |
|
1481 | - |
|
1482 | - // If the thickbox is enqueued, add dependencies |
|
1483 | - if ($lightbox) { |
|
1484 | - global $wp_filter; |
|
1485 | - |
|
1486 | - /** |
|
1487 | - * @filter `gravity_view_lightbox_script` Override the lightbox script to enqueue. Default: `thickbox` |
|
1488 | - * |
|
1489 | - * @param string $script_slug If you want to use a different lightbox script, return the name of it here. |
|
1490 | - * |
|
1491 | - * @deprecated 2.5.1 Naming. See `gravityview_lightbox_script` instead. |
|
1492 | - */ |
|
1493 | - $js_dependency = apply_filters_deprecated('gravity_view_lightbox_script', ['thickbox'], '2.5.1', 'gravityview_lightbox_script'); |
|
1494 | - |
|
1495 | - /** |
|
1496 | - * @filter `gravityview_lightbox_script` Override the lightbox script to enqueue. Default: `thickbox` |
|
1497 | - * |
|
1498 | - * @since 2.5.1 |
|
1499 | - * |
|
1500 | - * @param string $script_slug If you want to use a different lightbox script, return the name of it here. |
|
1501 | - * @param \GV\View The View. |
|
1502 | - */ |
|
1503 | - $js_dependency = apply_filters('gravityview_lightbox_script', $js_dependency, $view); |
|
1504 | - $js_dependencies[] = $js_dependency; |
|
1505 | - |
|
1506 | - /** |
|
1507 | - * @filter `gravity_view_lightbox_style` Modify the lightbox CSS slug. Default: `thickbox` |
|
1508 | - * |
|
1509 | - * @param string $script_slug If you want to use a different lightbox script, return the name of its CSS file here. |
|
1510 | - * |
|
1511 | - * @deprecated 2.5.1 Naming. See `gravityview_lightbox_style` instead. |
|
1512 | - */ |
|
1513 | - $css_dependency = apply_filters_deprecated('gravity_view_lightbox_style', ['thickbox'], '2.5.1', 'gravityview_lightbox_style'); |
|
1514 | - |
|
1515 | - /** |
|
1516 | - * @filter `gravityview_lightbox_script` Override the lightbox script to enqueue. Default: `thickbox` |
|
1517 | - * |
|
1518 | - * @since 2.5.1 |
|
1519 | - * |
|
1520 | - * @param string $script_slug If you want to use a different lightbox script, return the name of it here. |
|
1521 | - * @param \GV\View The View. |
|
1522 | - */ |
|
1523 | - $css_dependency = apply_filters('gravityview_lightbox_style', $css_dependency, $view); |
|
1524 | - $css_dependencies[] = $css_dependency; |
|
1525 | - } |
|
1526 | - |
|
1527 | - /** |
|
1528 | - * If the form has checkbox fields, enqueue dashicons. |
|
1529 | - * |
|
1530 | - * @see https://github.com/katzwebservices/GravityView/issues/536 |
|
1531 | - * @since 1.15 |
|
1532 | - */ |
|
1533 | - if (gravityview_view_has_single_checkbox_or_radio($data['form'], $data['fields'])) { |
|
1534 | - $css_dependencies[] = 'dashicons'; |
|
1535 | - } |
|
1536 | - |
|
1537 | - wp_register_script('gravityview-jquery-cookie', plugins_url('assets/lib/jquery.cookie/jquery.cookie.min.js', GRAVITYVIEW_FILE), ['jquery'], GravityView_Plugin::version, true); |
|
1538 | - |
|
1539 | - $script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
1540 | - |
|
1541 | - wp_register_script('gravityview-fe-view', plugins_url('assets/js/fe-views'.$script_debug.'.js', GRAVITYVIEW_FILE), apply_filters('gravityview_js_dependencies', $js_dependencies), GravityView_Plugin::version, true); |
|
1542 | - |
|
1543 | - wp_enqueue_script('gravityview-fe-view'); |
|
1544 | - |
|
1545 | - if (!empty($data['atts']['sort_columns'])) { |
|
1546 | - wp_enqueue_style('gravityview_font', plugins_url('assets/css/font.css', GRAVITYVIEW_FILE), $css_dependencies, GravityView_Plugin::version, 'all'); |
|
1547 | - } |
|
1548 | - |
|
1549 | - $this->enqueue_default_style($css_dependencies); |
|
1550 | - |
|
1551 | - self::add_style($template_id); |
|
1552 | - } |
|
1553 | - |
|
1554 | - if ('wp_print_footer_scripts' === current_filter()) { |
|
1555 | - $js_localization = [ |
|
1556 | - 'cookiepath' => COOKIEPATH, |
|
1557 | - 'clear' => _x('Clear', 'Clear all data from the form', 'gravityview'), |
|
1558 | - 'reset' => _x('Reset', 'Reset the search form to the state that existed on page load', 'gravityview'), |
|
1559 | - ]; |
|
1560 | - |
|
1561 | - /** |
|
1562 | - * @filter `gravityview_js_localization` Modify the array passed to wp_localize_script() |
|
1563 | - * |
|
1564 | - * @param array $js_localization The data padded to the Javascript file |
|
1565 | - * @param array $views Array of View data arrays with View settings |
|
1566 | - */ |
|
1567 | - $js_localization = apply_filters('gravityview_js_localization', $js_localization, $views); |
|
1568 | - |
|
1569 | - wp_localize_script('gravityview-fe-view', 'gvGlobals', $js_localization); |
|
1570 | - } |
|
1571 | - } |
|
1572 | - } |
|
1573 | - |
|
1574 | - /** |
|
1575 | - * Handle enqueuing the `gravityview_default_style` stylesheet. |
|
1576 | - * |
|
1577 | - * @since 1.17 |
|
1578 | - * |
|
1579 | - * @param array $css_dependencies Dependencies for the `gravityview_default_style` stylesheet |
|
1580 | - * |
|
1581 | - * @return void |
|
1582 | - */ |
|
1583 | - private function enqueue_default_style($css_dependencies = []) |
|
1584 | - { |
|
1585 | - |
|
1586 | - /** |
|
1587 | - * @filter `gravityview_use_legacy_search_css` Should GravityView use the legacy Search Bar stylesheet (from before Version 1.17)? |
|
1588 | - * |
|
1589 | - * @since 1.17 |
|
1590 | - * |
|
1591 | - * @param bool $use_legacy_search_style If true, loads `gv-legacy-search(-rtl).css`. If false, loads `gv-default-styles(-rtl).css`. `-rtl` is added on RTL websites. Default: `false` |
|
1592 | - */ |
|
1593 | - $use_legacy_search_style = apply_filters('gravityview_use_legacy_search_style', false); |
|
1594 | - |
|
1595 | - $rtl = is_rtl() ? '-rtl' : ''; |
|
1596 | - |
|
1597 | - $css_file_base = $use_legacy_search_style ? 'gv-legacy-search' : 'gv-default-styles'; |
|
1598 | - |
|
1599 | - $path = gravityview_css_url($css_file_base.$rtl.'.css'); |
|
1600 | - |
|
1601 | - wp_enqueue_style('gravityview_default_style', $path, $css_dependencies, GravityView_Plugin::version, 'all'); |
|
1602 | - } |
|
1603 | - |
|
1604 | - /** |
|
1605 | - * Add template extra style if exists. |
|
1606 | - * |
|
1607 | - * @param string $template_id |
|
1608 | - */ |
|
1609 | - public static function add_style($template_id) |
|
1610 | - { |
|
1611 | - if (!empty($template_id) && wp_style_is('gravityview_style_'.$template_id, 'registered')) { |
|
1612 | - gravityview()->log->debug('Adding extra template style for {template_id}', ['template_id' => $template_id]); |
|
1613 | - wp_enqueue_style('gravityview_style_'.$template_id); |
|
1614 | - } elseif (empty($template_id)) { |
|
1615 | - gravityview()->log->error('Cannot add template style; template_id is empty'); |
|
1616 | - } else { |
|
1617 | - gravityview()->log->error('Cannot add template style; {template_id} is not registered', ['template_id' => 'gravityview_style_'.$template_id]); |
|
1618 | - } |
|
1619 | - } |
|
1620 | - |
|
1621 | - /** |
|
1622 | - * Inject the sorting links on the table columns. |
|
1623 | - * |
|
1624 | - * Callback function for hook 'gravityview/template/field_label' |
|
1625 | - * |
|
1626 | - * @see GravityView_API::field_label() (in includes/class-api.php) |
|
1627 | - * @since 1.7 |
|
1628 | - * |
|
1629 | - * @param string $label Field label |
|
1630 | - * @param array $field Field settings |
|
1631 | - * @param array $form Form object |
|
1632 | - * |
|
1633 | - * @return string Field Label |
|
1634 | - */ |
|
1635 | - public function add_columns_sort_links($label = '', $field, $form) |
|
1636 | - { |
|
1637 | - |
|
1638 | - /** |
|
1639 | - * Not a table-based template; don't add sort icons. |
|
1640 | - * |
|
1641 | - * @since 1.12 |
|
1642 | - */ |
|
1643 | - if (!preg_match('/table/ism', GravityView_View::getInstance()->getTemplatePartSlug())) { |
|
1644 | - return $label; |
|
1645 | - } |
|
1646 | - |
|
1647 | - if (!$this->is_field_sortable($field['id'], $form)) { |
|
1648 | - return $label; |
|
1649 | - } |
|
1650 | - |
|
1651 | - $sorting = GravityView_View::getInstance()->getSorting(); |
|
1652 | - |
|
1653 | - $class = 'gv-sort'; |
|
1654 | - |
|
1655 | - $sort_field_id = self::_override_sorting_id_by_field_type($field['id'], $form['id']); |
|
1656 | - |
|
1657 | - $sort_args = [ |
|
1658 | - 'sort' => $field['id'], |
|
1659 | - 'dir' => 'asc', |
|
1660 | - ]; |
|
1661 | - |
|
1662 | - if (!empty($sorting['key']) && (string) $sort_field_id === (string) $sorting['key']) { |
|
1663 | - //toggle sorting direction. |
|
1664 | - if ('asc' === $sorting['direction']) { |
|
1665 | - $sort_args['dir'] = 'desc'; |
|
1666 | - $class .= ' gv-icon-sort-desc'; |
|
1667 | - } else { |
|
1668 | - $sort_args['dir'] = 'asc'; |
|
1669 | - $class .= ' gv-icon-sort-asc'; |
|
1670 | - } |
|
1671 | - } else { |
|
1672 | - $class .= ' gv-icon-caret-up-down'; |
|
1673 | - } |
|
1674 | - |
|
1675 | - $url = add_query_arg($sort_args, remove_query_arg(['pagenum'])); |
|
1676 | - |
|
1677 | - return '<a href="'.esc_url_raw($url).'" class="'.$class.'" ></a> '.$label; |
|
1678 | - } |
|
1679 | - |
|
1680 | - /** |
|
1681 | - * Checks if field (column) is sortable. |
|
1682 | - * |
|
1683 | - * @param string $field Field settings |
|
1684 | - * @param array $form Gravity Forms form array |
|
1685 | - * |
|
1686 | - * @since 1.7 |
|
1687 | - * |
|
1688 | - * @return bool True: Yes, field is sortable; False: not sortable |
|
1689 | - */ |
|
1690 | - public function is_field_sortable($field_id = '', $form = []) |
|
1691 | - { |
|
1692 | - $field_type = $field_id; |
|
1693 | - |
|
1694 | - if (is_numeric($field_id)) { |
|
1695 | - $field = GFFormsModel::get_field($form, $field_id); |
|
1696 | - $field_type = $field ? $field->type : $field_id; |
|
1697 | - } |
|
1698 | - |
|
1699 | - $not_sortable = [ |
|
1700 | - 'edit_link', |
|
1701 | - 'delete_link', |
|
1702 | - ]; |
|
1703 | - |
|
1704 | - /** |
|
1705 | - * @depecated 2.14 |
|
1706 | - * |
|
1707 | - * @since 1.7 |
|
1708 | - */ |
|
1709 | - $not_sortable = apply_filters_deprecated('gravityview/sortable/field_blacklist', [$not_sortable, $field_type, $form], '2.14', 'gravityview/sortable/field_blocklist'); |
|
1710 | - |
|
1711 | - /** |
|
1712 | - * @filter `gravityview/sortable/field_blocklist` Modify what fields should never be sortable. |
|
1713 | - * |
|
1714 | - * @since 2.14 |
|
1715 | - * |
|
1716 | - * @param array $not_sortable Array of field types that aren't sortable. |
|
1717 | - * @param string $field_type Field type to check whether the field is sortable. |
|
1718 | - * @param array $form Gravity Forms form. |
|
1719 | - */ |
|
1720 | - $not_sortable = apply_filters('gravityview/sortable/field_blocklist', $not_sortable, $field_type, $form); |
|
1721 | - |
|
1722 | - if (in_array($field_type, $not_sortable)) { |
|
1723 | - return false; |
|
1724 | - } |
|
1725 | - |
|
1726 | - return apply_filters("gravityview/sortable/formfield_{$form['id']}_{$field_id}", apply_filters("gravityview/sortable/field_{$field_id}", true, $form)); |
|
1727 | - } |
|
16 | + /** |
|
17 | + * Regex strings that are used to determine whether the current request is a GravityView search or not. |
|
18 | + * |
|
19 | + * @see GravityView_frontend::is_searching() |
|
20 | + * @since 1.7.4.1 |
|
21 | + * |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + private static $search_parameters = ['gv_search', 'gv_start', 'gv_end', 'gv_id', 'gv_by', 'filter_*']; |
|
25 | + |
|
26 | + /** |
|
27 | + * Is the currently viewed post a `gravityview` post type? |
|
28 | + * |
|
29 | + * @var bool |
|
30 | + */ |
|
31 | + public $is_gravityview_post_type = false; |
|
32 | + |
|
33 | + /** |
|
34 | + * Does the current post have a `[gravityview]` shortcode? |
|
35 | + * |
|
36 | + * @var bool |
|
37 | + */ |
|
38 | + public $post_has_shortcode = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * The Post ID of the currently viewed post. Not necessarily GV. |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + public $post_id = null; |
|
46 | + |
|
47 | + /** |
|
48 | + * Are we currently viewing a single entry? |
|
49 | + * If so, the int value of the entry ID. Otherwise, false. |
|
50 | + * |
|
51 | + * @var int|bool |
|
52 | + */ |
|
53 | + public $single_entry = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * If we are viewing a single entry, the entry data. |
|
57 | + * |
|
58 | + * @var array|false |
|
59 | + */ |
|
60 | + public $entry = false; |
|
61 | + |
|
62 | + /** |
|
63 | + * When displaying the single entry we should always know to which View it belongs (the context is everything!). |
|
64 | + * |
|
65 | + * @var null |
|
66 | + */ |
|
67 | + public $context_view_id = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * The View is showing search results. |
|
71 | + * |
|
72 | + * @since 1.5.4 |
|
73 | + * |
|
74 | + * @var bool |
|
75 | + */ |
|
76 | + public $is_search = false; |
|
77 | + |
|
78 | + /** |
|
79 | + * The view data parsed from the $post. |
|
80 | + * |
|
81 | + * @see GravityView_View_Data::__construct() |
|
82 | + * |
|
83 | + * @var GravityView_View_Data |
|
84 | + */ |
|
85 | + public $gv_output_data = null; |
|
86 | + |
|
87 | + /** |
|
88 | + * @var GravityView_frontend |
|
89 | + */ |
|
90 | + public static $instance; |
|
91 | + |
|
92 | + /** |
|
93 | + * Class constructor, enforce Singleton pattern. |
|
94 | + */ |
|
95 | + private function __construct() |
|
96 | + { |
|
97 | + } |
|
98 | + |
|
99 | + private function initialize() |
|
100 | + { |
|
101 | + add_action('wp', [$this, 'parse_content'], 11); |
|
102 | + add_filter('render_block', [$this, 'detect_views_in_block_content']); |
|
103 | + add_filter('parse_query', [$this, 'parse_query_fix_frontpage'], 10); |
|
104 | + add_action('template_redirect', [$this, 'set_entry_data'], 1); |
|
105 | + |
|
106 | + // Enqueue scripts and styles after GravityView_Template::register_styles() |
|
107 | + add_action('wp_enqueue_scripts', [$this, 'add_scripts_and_styles'], 20); |
|
108 | + |
|
109 | + // Enqueue and print styles in the footer. Added 1 priorty so stuff gets printed at 10 priority. |
|
110 | + add_action('wp_print_footer_scripts', [$this, 'add_scripts_and_styles'], 1); |
|
111 | + |
|
112 | + add_filter('the_title', [$this, 'single_entry_title'], 1, 2); |
|
113 | + add_filter('comments_open', [$this, 'comments_open'], 10, 2); |
|
114 | + |
|
115 | + add_action('gravityview_after', [$this, 'context_not_configured_warning']); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Get the one true instantiated self. |
|
120 | + * |
|
121 | + * @return GravityView_frontend |
|
122 | + */ |
|
123 | + public static function getInstance() |
|
124 | + { |
|
125 | + if (empty(self::$instance)) { |
|
126 | + self::$instance = new self(); |
|
127 | + self::$instance->initialize(); |
|
128 | + } |
|
129 | + |
|
130 | + return self::$instance; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @return GravityView_View_Data |
|
135 | + */ |
|
136 | + public function getGvOutputData() |
|
137 | + { |
|
138 | + return $this->gv_output_data; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @param \GravityView_View_Data $gv_output_data |
|
143 | + */ |
|
144 | + public function setGvOutputData($gv_output_data) |
|
145 | + { |
|
146 | + $this->gv_output_data = $gv_output_data; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @return bool |
|
151 | + */ |
|
152 | + public function isSearch() |
|
153 | + { |
|
154 | + return $this->is_search; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @param bool $is_search |
|
159 | + */ |
|
160 | + public function setIsSearch($is_search) |
|
161 | + { |
|
162 | + $this->is_search = $is_search; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @return bool|int |
|
167 | + */ |
|
168 | + public function getSingleEntry() |
|
169 | + { |
|
170 | + return $this->single_entry; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Sets the single entry ID and also the entry. |
|
175 | + * |
|
176 | + * @param bool|int|string $single_entry |
|
177 | + */ |
|
178 | + public function setSingleEntry($single_entry) |
|
179 | + { |
|
180 | + $this->single_entry = $single_entry; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @return array |
|
185 | + */ |
|
186 | + public function getEntry() |
|
187 | + { |
|
188 | + return $this->entry; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Set the current entry. |
|
193 | + * |
|
194 | + * @param array|int $entry Entry array or entry slug or ID |
|
195 | + */ |
|
196 | + public function setEntry($entry) |
|
197 | + { |
|
198 | + if (!is_array($entry)) { |
|
199 | + $entry = GVCommon::get_entry($entry); |
|
200 | + } |
|
201 | + |
|
202 | + $this->entry = $entry; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * @return int |
|
207 | + */ |
|
208 | + public function getPostId() |
|
209 | + { |
|
210 | + return $this->post_id; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @param int $post_id |
|
215 | + */ |
|
216 | + public function setPostId($post_id) |
|
217 | + { |
|
218 | + $this->post_id = $post_id; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * @return bool |
|
223 | + */ |
|
224 | + public function isPostHasShortcode() |
|
225 | + { |
|
226 | + return $this->post_has_shortcode; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @param bool $post_has_shortcode |
|
231 | + */ |
|
232 | + public function setPostHasShortcode($post_has_shortcode) |
|
233 | + { |
|
234 | + $this->post_has_shortcode = $post_has_shortcode; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @return bool |
|
239 | + */ |
|
240 | + public function isGravityviewPostType() |
|
241 | + { |
|
242 | + return $this->is_gravityview_post_type; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * @param bool $is_gravityview_post_type |
|
247 | + */ |
|
248 | + public function setIsGravityviewPostType($is_gravityview_post_type) |
|
249 | + { |
|
250 | + $this->is_gravityview_post_type = $is_gravityview_post_type; |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Set the context view ID used when page contains multiple embedded views or displaying the single entry view. |
|
255 | + * |
|
256 | + * |
|
257 | + * |
|
258 | + * @param null $view_id |
|
259 | + */ |
|
260 | + public function set_context_view_id($view_id = null) |
|
261 | + { |
|
262 | + $multiple_views = $this->getGvOutputData() && $this->getGvOutputData()->has_multiple_views(); |
|
263 | + |
|
264 | + if (!empty($view_id)) { |
|
265 | + $this->context_view_id = (int) $view_id; |
|
266 | + } elseif (isset($_GET['gvid']) && $multiple_views) { |
|
267 | + /** |
|
268 | + * used on a has_multiple_views context. |
|
269 | + * |
|
270 | + * @see GravityView_API::entry_link |
|
271 | + */ |
|
272 | + $this->context_view_id = (int) $_GET['gvid']; |
|
273 | + } elseif (!$multiple_views) { |
|
274 | + $array_keys = array_keys($this->getGvOutputData()->get_views()); |
|
275 | + $this->context_view_id = (int) array_pop($array_keys); |
|
276 | + unset($array_keys); |
|
277 | + } |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Returns the the view_id context when page contains multiple embedded views or displaying single entry view. |
|
282 | + * |
|
283 | + * @since 1.5.4 |
|
284 | + * |
|
285 | + * @return int|null |
|
286 | + */ |
|
287 | + public function get_context_view_id() |
|
288 | + { |
|
289 | + return $this->context_view_id; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Allow GravityView entry endpoints on the front page of a site. |
|
294 | + * |
|
295 | + * @link https://core.trac.wordpress.org/ticket/23867 Fixes this core issue |
|
296 | + * @link https://wordpress.org/plugins/cpt-on-front-page/ Code is based on this |
|
297 | + * @since 1.17.3 |
|
298 | + * |
|
299 | + * @param WP_Query &$query (passed by reference) |
|
300 | + * |
|
301 | + * @return void |
|
302 | + */ |
|
303 | + public function parse_query_fix_frontpage(&$query) |
|
304 | + { |
|
305 | + global $wp_rewrite; |
|
306 | + |
|
307 | + $is_front_page = ($query->is_home || $query->is_page); |
|
308 | + $show_on_front = ('page' === get_option('show_on_front')); |
|
309 | + $front_page_id = get_option('page_on_front'); |
|
310 | + |
|
311 | + if ($is_front_page && $show_on_front && $front_page_id) { |
|
312 | + |
|
313 | + // Force to be an array, potentially a query string ( entry=16 ) |
|
314 | + $_query = wp_parse_args($query->query); |
|
315 | + |
|
316 | + // pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename. |
|
317 | + if (isset($_query['pagename']) && '' === $_query['pagename']) { |
|
318 | + unset($_query['pagename']); |
|
319 | + } |
|
320 | + |
|
321 | + // this is where will break from core wordpress |
|
322 | + /** @internal Don't use this filter; it will be unnecessary soon - it's just a patch for specific use case */ |
|
323 | + $ignore = apply_filters('gravityview/internal/ignored_endpoints', ['preview', 'page', 'paged', 'cpage'], $query); |
|
324 | + $endpoints = \GV\Utils::get($wp_rewrite, 'endpoints'); |
|
325 | + foreach ((array) $endpoints as $endpoint) { |
|
326 | + $ignore[] = $endpoint[1]; |
|
327 | + } |
|
328 | + unset($endpoints); |
|
329 | + |
|
330 | + // Modify the query if: |
|
331 | + // - We're on the "Page on front" page (which we are), and: |
|
332 | + // - The query is empty OR |
|
333 | + // - The query includes keys that are associated with registered endpoints. `entry`, for example. |
|
334 | + if (empty($_query) || !array_diff(array_keys($_query), $ignore)) { |
|
335 | + $qv = &$query->query_vars; |
|
336 | + |
|
337 | + // Prevent redirect when on the single entry endpoint |
|
338 | + if (self::is_single_entry()) { |
|
339 | + add_filter('redirect_canonical', '__return_false'); |
|
340 | + } |
|
341 | + |
|
342 | + $query->is_page = true; |
|
343 | + $query->is_home = false; |
|
344 | + $qv['page_id'] = $front_page_id; |
|
345 | + |
|
346 | + // Correct <!--nextpage--> for page_on_front |
|
347 | + if (!empty($qv['paged'])) { |
|
348 | + $qv['page'] = $qv['paged']; |
|
349 | + unset($qv['paged']); |
|
350 | + } |
|
351 | + } |
|
352 | + |
|
353 | + // reset the is_singular flag after our updated code above |
|
354 | + $query->is_singular = $query->is_single || $query->is_page || $query->is_attachment; |
|
355 | + } |
|
356 | + } |
|
357 | + |
|
358 | + /** |
|
359 | + * Detect GV Views in parsed Gutenberg block content. |
|
360 | + * |
|
361 | + * @since 2.13.4 |
|
362 | + * @see \WP_Block::render() |
|
363 | + * |
|
364 | + * @param string $block_content Gutenberg block content |
|
365 | + * |
|
366 | + * @return false|string |
|
367 | + * |
|
368 | + * @todo Once we stop using the legacy `GravityView_frontend::parse_content()` method to detect Views in post content, this code should either be dropped or promoted to some core class given its applicability to other themes/plugins |
|
369 | + */ |
|
370 | + public function detect_views_in_block_content($block_content) |
|
371 | + { |
|
372 | + if (!class_exists('GV\View_Collection') || !class_exists('GV\View')) { |
|
373 | + return $block_content; |
|
374 | + } |
|
375 | + |
|
376 | + $gv_view_data = GravityView_View_Data::getInstance(); |
|
377 | + |
|
378 | + $views = \GV\View_Collection::from_content($block_content); |
|
379 | + |
|
380 | + foreach ($views->all() as $view) { |
|
381 | + if (!$gv_view_data->views->contains($view->ID)) { |
|
382 | + $gv_view_data->views->add($view); |
|
383 | + } |
|
384 | + } |
|
385 | + |
|
386 | + return $block_content; |
|
387 | + } |
|
388 | + |
|
389 | + /** |
|
390 | + * Read the $post and process the View data inside. |
|
391 | + * |
|
392 | + * @param array $wp Passed in the `wp` hook. Not used. |
|
393 | + * |
|
394 | + * @return void |
|
395 | + */ |
|
396 | + public function parse_content($wp = []) |
|
397 | + { |
|
398 | + global $post; |
|
399 | + |
|
400 | + // If in admin and NOT AJAX request, get outta here. |
|
401 | + if (gravityview()->request->is_admin()) { |
|
402 | + return; |
|
403 | + } |
|
404 | + |
|
405 | + $is_GV_post_type = 'gravityview' === get_post_type($post); |
|
406 | + |
|
407 | + // Calculate requested Views |
|
408 | + $post_content = !empty($post->post_content) ? $post->post_content : null; |
|
409 | + |
|
410 | + if (!$is_GV_post_type && function_exists('parse_blocks') && preg_match_all('/"ref":\d+/', $post_content)) { |
|
411 | + $blocks = parse_blocks($post_content); |
|
412 | + |
|
413 | + foreach ($blocks as $block) { |
|
414 | + if (empty($block['attrs']['ref'])) { |
|
415 | + continue; |
|
416 | + } |
|
417 | + |
|
418 | + $block_post = get_post($block['attrs']['ref']); |
|
419 | + |
|
420 | + if ($block_post) { |
|
421 | + $post_content .= $block_post->post_content; |
|
422 | + } |
|
423 | + } |
|
424 | + |
|
425 | + $this->setGvOutputData(GravityView_View_Data::getInstance($post_content)); |
|
426 | + } else { |
|
427 | + $this->setGvOutputData(GravityView_View_Data::getInstance($post)); |
|
428 | + } |
|
429 | + |
|
430 | + // !important: we need to run this before getting single entry (to kick the advanced filter) |
|
431 | + $this->set_context_view_id(); |
|
432 | + |
|
433 | + $this->setIsGravityviewPostType($is_GV_post_type); |
|
434 | + |
|
435 | + $post_id = $this->getPostId() ? $this->getPostId() : (isset($post) ? $post->ID : null); |
|
436 | + $this->setPostId($post_id); |
|
437 | + $post_has_shortcode = $post_content ? gravityview_has_shortcode_r($post_content, 'gravityview') : false; |
|
438 | + $this->setPostHasShortcode($this->isGravityviewPostType() ? null : !empty($post_has_shortcode)); |
|
439 | + |
|
440 | + // check if the View is showing search results (only for multiple entries View) |
|
441 | + $this->setIsSearch($this->is_searching()); |
|
442 | + |
|
443 | + unset($entry, $post_id, $post_has_shortcode); |
|
444 | + } |
|
445 | + |
|
446 | + /** |
|
447 | + * Set the entry. |
|
448 | + */ |
|
449 | + public function set_entry_data() |
|
450 | + { |
|
451 | + $entry_id = self::is_single_entry(); |
|
452 | + $this->setSingleEntry($entry_id); |
|
453 | + $this->setEntry($entry_id); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Checks if the current View is presenting search results. |
|
458 | + * |
|
459 | + * @since 1.5.4 |
|
460 | + * |
|
461 | + * @return bool True: Yes, it's a search; False: No, not a search. |
|
462 | + */ |
|
463 | + public function is_searching() |
|
464 | + { |
|
465 | + |
|
466 | + // It's a single entry, not search |
|
467 | + if ($this->getSingleEntry()) { |
|
468 | + return false; |
|
469 | + } |
|
470 | + |
|
471 | + $search_method = GravityView_Widget_Search::getInstance()->get_search_method(); |
|
472 | + |
|
473 | + if ('post' === $search_method) { |
|
474 | + $get = $_POST; |
|
475 | + } else { |
|
476 | + $get = $_GET; |
|
477 | + } |
|
478 | + |
|
479 | + // No $_GET parameters |
|
480 | + if (empty($get) || !is_array($get)) { |
|
481 | + return false; |
|
482 | + } |
|
483 | + |
|
484 | + // Remove empty values |
|
485 | + $get = array_filter($get); |
|
486 | + |
|
487 | + // If the $_GET parameters are empty, it's no search. |
|
488 | + if (empty($get)) { |
|
489 | + return false; |
|
490 | + } |
|
491 | + |
|
492 | + $search_keys = array_keys($get); |
|
493 | + |
|
494 | + $search_match = implode('|', self::$search_parameters); |
|
495 | + |
|
496 | + foreach ($search_keys as $search_key) { |
|
497 | + |
|
498 | + // Analyze the search key $_GET parameter and see if it matches known GV args |
|
499 | + if (preg_match('/('.$search_match.')/i', $search_key)) { |
|
500 | + return true; |
|
501 | + } |
|
502 | + } |
|
503 | + |
|
504 | + return false; |
|
505 | + } |
|
506 | + |
|
507 | + /** |
|
508 | + * Filter the title for the single entry view. |
|
509 | + * |
|
510 | + * @param string $passed_title Current title |
|
511 | + * @param int $passed_post_id Post ID |
|
512 | + * |
|
513 | + * @return string (modified) title |
|
514 | + */ |
|
515 | + public function single_entry_title($passed_title, $passed_post_id = null) |
|
516 | + { |
|
517 | + global $post; |
|
518 | + |
|
519 | + // Since this is a public method, it can be called outside of the plugin. Don't assume things have been loaded properly. |
|
520 | + if (!class_exists('\GV\Entry')) { |
|
521 | + return $passed_title; |
|
522 | + } |
|
523 | + |
|
524 | + $gventry = gravityview()->request->is_entry(); |
|
525 | + |
|
526 | + // If this is the directory view, return. |
|
527 | + if (!$gventry) { |
|
528 | + return $passed_title; |
|
529 | + } |
|
530 | + |
|
531 | + $entry = $gventry->as_entry(); |
|
532 | + |
|
533 | + /** |
|
534 | + * @filter `gravityview/single/title/out_loop` Apply the Single Entry Title filter outside the WordPress loop? |
|
535 | + * |
|
536 | + * @param bool $in_the_loop Whether to apply the filter to the menu title and the meta tag <title> - outside the loop |
|
537 | + * @param array $entry Current entry |
|
538 | + */ |
|
539 | + $apply_outside_loop = apply_filters('gravityview/single/title/out_loop', in_the_loop(), $entry); |
|
540 | + |
|
541 | + if (!$apply_outside_loop) { |
|
542 | + return $passed_title; |
|
543 | + } |
|
544 | + |
|
545 | + // WooCommerce doesn't $post_id |
|
546 | + if (empty($passed_post_id)) { |
|
547 | + return $passed_title; |
|
548 | + } |
|
549 | + |
|
550 | + // Don't modify the title for anything other than the current view/post. |
|
551 | + // This is true for embedded shortcodes and Views. |
|
552 | + if (is_object($post) && (int) $post->ID !== (int) $passed_post_id) { |
|
553 | + return $passed_title; |
|
554 | + } |
|
555 | + |
|
556 | + $view = gravityview()->request->is_view(); |
|
557 | + |
|
558 | + if ($view) { |
|
559 | + return $this->_get_single_entry_title($view, $entry, $passed_title); |
|
560 | + } |
|
561 | + |
|
562 | + $_gvid = \GV\Utils::_GET('gvid', null); |
|
563 | + |
|
564 | + // $_GET['gvid'] is set; we know what View to render |
|
565 | + if ($_gvid) { |
|
566 | + $view = \GV\View::by_id($_gvid); |
|
567 | + |
|
568 | + return $this->_get_single_entry_title($view, $entry, $passed_title); |
|
569 | + } |
|
570 | + |
|
571 | + global $post; |
|
572 | + |
|
573 | + if (!$post) { |
|
574 | + return $passed_title; |
|
575 | + } |
|
576 | + |
|
577 | + $view_collection = \GV\View_Collection::from_post($post); |
|
578 | + |
|
579 | + // We have multiple Views, but no gvid...this isn't valid security |
|
580 | + if (1 < $view_collection->count()) { |
|
581 | + return $passed_title; |
|
582 | + } |
|
583 | + |
|
584 | + return $this->_get_single_entry_title($view_collection->first(), $entry, $passed_title); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Returns the single entry title for a View with variables replaced and shortcodes parsed. |
|
589 | + * |
|
590 | + * @since 2.7.2 |
|
591 | + * |
|
592 | + * @param \GV\View|null $view |
|
593 | + * @param array $entry |
|
594 | + * @param string $passed_title |
|
595 | + * |
|
596 | + * @return string |
|
597 | + */ |
|
598 | + private function _get_single_entry_title($view, $entry = [], $passed_title = '') |
|
599 | + { |
|
600 | + if (!$view) { |
|
601 | + return $passed_title; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * @filter `gravityview/single/title/check_entry_display` Override whether to check entry display rules against filters |
|
606 | + * |
|
607 | + * @internal This might change in the future! Don't rely on it. |
|
608 | + * |
|
609 | + * @since 2.7.2 |
|
610 | + * |
|
611 | + * @param bool $check_entry_display Check whether the entry is visible for the current View configuration. Default: true. |
|
612 | + * @param array $entry Gravity Forms entry array |
|
613 | + * @param \GV\View $view The View |
|
614 | + */ |
|
615 | + $check_entry_display = apply_filters('gravityview/single/title/check_entry_display', true, $entry, $view); |
|
616 | + |
|
617 | + if ($check_entry_display) { |
|
618 | + $check_display = GVCommon::check_entry_display($entry, $view); |
|
619 | + |
|
620 | + if (is_wp_error($check_display)) { |
|
621 | + return $passed_title; |
|
622 | + } |
|
623 | + } |
|
624 | + |
|
625 | + $title = $view->settings->get('single_title', $passed_title); |
|
626 | + |
|
627 | + $form = GVCommon::get_form($entry['form_id']); |
|
628 | + |
|
629 | + // We are allowing HTML in the fields, so no escaping the output |
|
630 | + $title = GravityView_API::replace_variables($title, $form, $entry); |
|
631 | + |
|
632 | + $title = do_shortcode($title); |
|
633 | + |
|
634 | + return $title; |
|
635 | + } |
|
636 | + |
|
637 | + /** |
|
638 | + * In case View post is called directly, insert the view in the post content. |
|
639 | + * |
|
640 | + * @deprecated Use \GV\View::content() instead. |
|
641 | + * |
|
642 | + * @static |
|
643 | + * |
|
644 | + * @param mixed $content |
|
645 | + * |
|
646 | + * @return string Add the View output into View CPT content |
|
647 | + */ |
|
648 | + public function insert_view_in_content($content) |
|
649 | + { |
|
650 | + gravityview()->log->notice('\GravityView_frontend::insert_view_in_content is deprecated. Use \GV\View::content()'); |
|
651 | + |
|
652 | + return \GV\View::content($content); |
|
653 | + } |
|
654 | + |
|
655 | + /** |
|
656 | + * Disable comments on GravityView post types. |
|
657 | + * |
|
658 | + * @param bool $open existing status |
|
659 | + * @param int $post_id Post ID |
|
660 | + * |
|
661 | + * @return bool |
|
662 | + */ |
|
663 | + public function comments_open($open, $post_id) |
|
664 | + { |
|
665 | + if ($this->isGravityviewPostType()) { |
|
666 | + $open = false; |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * @filter `gravityview/comments_open` Whether to set comments to open or closed. |
|
671 | + * |
|
672 | + * @since 1.5.4 |
|
673 | + * |
|
674 | + * @param bool $open Open or closed status |
|
675 | + * @param int $post_id Post ID to set comment status for |
|
676 | + */ |
|
677 | + $open = apply_filters('gravityview/comments_open', $open, $post_id); |
|
678 | + |
|
679 | + return $open; |
|
680 | + } |
|
681 | + |
|
682 | + /** |
|
683 | + * Display a warning when a View has not been configured. |
|
684 | + * |
|
685 | + * @since 1.19.2 |
|
686 | + * |
|
687 | + * @param int $view_id The ID of the View currently being displayed |
|
688 | + * |
|
689 | + * @return void |
|
690 | + */ |
|
691 | + public function context_not_configured_warning($view_id = 0) |
|
692 | + { |
|
693 | + if (!class_exists('GravityView_View')) { |
|
694 | + return; |
|
695 | + } |
|
696 | + |
|
697 | + $fields = GravityView_View::getInstance()->getContextFields(); |
|
698 | + |
|
699 | + if (!empty($fields)) { |
|
700 | + return; |
|
701 | + } |
|
702 | + |
|
703 | + $context = GravityView_View::getInstance()->getContext(); |
|
704 | + |
|
705 | + switch ($context) { |
|
706 | + case 'directory': |
|
707 | + $tab = __('Multiple Entries', 'gravityview'); |
|
708 | + break; |
|
709 | + case 'edit': |
|
710 | + $tab = __('Edit Entry', 'gravityview'); |
|
711 | + break; |
|
712 | + case 'single': |
|
713 | + default: |
|
714 | + $tab = __('Single Entry', 'gravityview'); |
|
715 | + break; |
|
716 | + } |
|
717 | + |
|
718 | + $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); |
|
719 | + $edit_link = admin_url(sprintf('post.php?post=%d&action=edit#%s-view', $view_id, $context)); |
|
720 | + $action_text = sprintf(esc_html__('Add fields to %s', 'gravityview'), $tab); |
|
721 | + $message = esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
722 | + |
|
723 | + $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))); |
|
724 | + $output = sprintf('<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>', $title, esc_url($edit_link), $action_text, $message); |
|
725 | + |
|
726 | + echo GVCommon::generate_notice($output.$image, 'gv-error error', 'edit_gravityview', $view_id); |
|
727 | + } |
|
728 | + |
|
729 | + /** |
|
730 | + * Core function to render a View based on a set of arguments. |
|
731 | + * |
|
732 | + * @static |
|
733 | + * |
|
734 | + * @param array $passed_args { |
|
735 | + * |
|
736 | + * Settings for rendering the View |
|
737 | + * |
|
738 | + * @var int $id View id |
|
739 | + * @var int $page_size Number of entries to show per page |
|
740 | + * @var string $sort_field Form field id to sort |
|
741 | + * @var string $sort_direction Sorting direction ('ASC', 'DESC', or 'RAND') |
|
742 | + * @var string $start_date - Ymd |
|
743 | + * @var string $end_date - Ymd |
|
744 | + * @var string $class - assign a html class to the view |
|
745 | + * @var string $offset (optional) - This is the start point in the current data set (0 index based). |
|
746 | + * } |
|
747 | + * |
|
748 | + * @deprecated Use \GV\View_Renderer |
|
749 | + * |
|
750 | + * @return string|null HTML output of a View, NULL if View isn't found |
|
751 | + */ |
|
752 | + public function render_view($passed_args) |
|
753 | + { |
|
754 | + gravityview()->log->notice('\GravityView_frontend::render_view is deprecated. Use \GV\View_Renderer etc.'); |
|
755 | + |
|
756 | + /** |
|
757 | + * We can use a shortcode here, since it's pretty much the same. |
|
758 | + * |
|
759 | + * But we do need to check embed permissions, since shortcodes don't do this. |
|
760 | + */ |
|
761 | + if (!$view = gravityview()->views->get($passed_args)) { |
|
762 | + return null; |
|
763 | + } |
|
764 | + |
|
765 | + $view->settings->update($passed_args); |
|
766 | + |
|
767 | + $direct_access = apply_filters('gravityview_direct_access', true, $view->ID); |
|
768 | + $embed_only = $view->settings->get('embed_only'); |
|
769 | + |
|
770 | + if (!$direct_access || ($embed_only && !GVCommon::has_cap('read_private_gravityviews'))) { |
|
771 | + return __('You are not allowed to view this content.', 'gravityview'); |
|
772 | + } |
|
773 | + |
|
774 | + $shortcode = new \GV\Shortcodes\gravityview(); |
|
775 | + |
|
776 | + return $shortcode->callback($passed_args); |
|
777 | + } |
|
778 | + |
|
779 | + /** |
|
780 | + * Process the start and end dates for a view - overrides values defined in shortcode (if needed). |
|
781 | + * |
|
782 | + * The `start_date` and `end_date` keys need to be in a format processable by GFFormsModel::get_date_range_where(), |
|
783 | + * which uses \DateTime() format. |
|
784 | + * |
|
785 | + * You can set the `start_date` or `end_date` to any value allowed by {@link http://www.php.net//manual/en/function.strtotime.php strtotime()}, |
|
786 | + * including strings like "now" or "-1 year" or "-3 days". |
|
787 | + * |
|
788 | + * @see GFFormsModel::get_date_range_where |
|
789 | + * |
|
790 | + * @param array $args View settings |
|
791 | + * @param array $search_criteria Search being performed, if any |
|
792 | + * |
|
793 | + * @return array Modified `$search_criteria` array |
|
794 | + */ |
|
795 | + public static function process_search_dates($args, $search_criteria = []) |
|
796 | + { |
|
797 | + $return_search_criteria = $search_criteria; |
|
798 | + |
|
799 | + foreach (['start_date', 'end_date'] as $key) { |
|
800 | + |
|
801 | + // Is the start date or end date set in the view or shortcode? |
|
802 | + // If so, we want to make sure that the search doesn't go outside the bounds defined. |
|
803 | + if (!empty($args[$key])) { |
|
804 | + |
|
805 | + // Get a timestamp and see if it's a valid date format |
|
806 | + $date = strtotime($args[$key], GFCommon::get_local_timestamp()); |
|
807 | + |
|
808 | + // The date was invalid |
|
809 | + if (empty($date)) { |
|
810 | + gravityview()->log->error(' Invalid {key} date format: {format}', ['key' => $key, 'format' => $args[$key]]); |
|
811 | + continue; |
|
812 | + } |
|
813 | + |
|
814 | + // The format that Gravity Forms expects for start_date and day-specific (not hour/second-specific) end_date |
|
815 | + $datetime_format = 'Y-m-d H:i:s'; |
|
816 | + $search_is_outside_view_bounds = false; |
|
817 | + |
|
818 | + if (!empty($search_criteria[$key])) { |
|
819 | + $search_date = strtotime($search_criteria[$key], GFCommon::get_local_timestamp()); |
|
820 | + |
|
821 | + // The search is for entries before the start date defined by the settings |
|
822 | + switch ($key) { |
|
823 | + case 'end_date': |
|
824 | + /** |
|
825 | + * If the end date is formatted as 'Y-m-d', it should be formatted without hours and seconds |
|
826 | + * so that Gravity Forms can convert the day to 23:59:59 the previous day. |
|
827 | + * |
|
828 | + * If it's a relative date ("now" or "-1 day"), then it should use the precise date format |
|
829 | + * |
|
830 | + * @see GFFormsModel::get_date_range_where |
|
831 | + */ |
|
832 | + $datetime_format = gravityview_is_valid_datetime($args[$key]) ? 'Y-m-d' : $datetime_format; |
|
833 | + $search_is_outside_view_bounds = ($search_date > $date); |
|
834 | + break; |
|
835 | + case 'start_date': |
|
836 | + $search_is_outside_view_bounds = ($search_date < $date); |
|
837 | + break; |
|
838 | + } |
|
839 | + } |
|
840 | + |
|
841 | + // If there is no search being performed, or if there is a search being performed that's outside the bounds |
|
842 | + if (empty($search_criteria[$key]) || $search_is_outside_view_bounds) { |
|
843 | + |
|
844 | + // Then we override the search and re-set the start date |
|
845 | + $return_search_criteria[$key] = date_i18n($datetime_format, $date, true); |
|
846 | + } |
|
847 | + } |
|
848 | + } |
|
849 | + |
|
850 | + if (isset($return_search_criteria['start_date']) && isset($return_search_criteria['end_date'])) { |
|
851 | + // The start date is AFTER the end date. This will result in no results, but let's not force the issue. |
|
852 | + if (strtotime($return_search_criteria['start_date']) > strtotime($return_search_criteria['end_date'])) { |
|
853 | + gravityview()->log->error('Invalid search: the start date is after the end date.', ['data' => $return_search_criteria]); |
|
854 | + } |
|
855 | + } |
|
856 | + |
|
857 | + return $return_search_criteria; |
|
858 | + } |
|
859 | + |
|
860 | + /** |
|
861 | + * Process the approved only search criteria according to the View settings. |
|
862 | + * |
|
863 | + * @param array $args View settings |
|
864 | + * @param array $search_criteria Search being performed, if any |
|
865 | + * |
|
866 | + * @return array Modified `$search_criteria` array |
|
867 | + */ |
|
868 | + public static function process_search_only_approved($args, $search_criteria) |
|
869 | + { |
|
870 | + |
|
871 | + /** @since 1.19 */ |
|
872 | + if (!empty($args['admin_show_all_statuses']) && GVCommon::has_cap('gravityview_moderate_entries')) { |
|
873 | + gravityview()->log->debug('User can moderate entries; showing all approval statuses'); |
|
874 | + |
|
875 | + return $search_criteria; |
|
876 | + } |
|
877 | + |
|
878 | + if (!empty($args['show_only_approved'])) { |
|
879 | + $search_criteria['field_filters'][] = [ |
|
880 | + 'key' => GravityView_Entry_Approval::meta_key, |
|
881 | + 'value' => GravityView_Entry_Approval_Status::APPROVED, |
|
882 | + ]; |
|
883 | + |
|
884 | + $search_criteria['field_filters']['mode'] = 'all'; // force all the criterias to be met |
|
885 | + |
|
886 | + gravityview()->log->debug('[process_search_only_approved] Search Criteria if show only approved: ', ['data' => $search_criteria]); |
|
887 | + } |
|
888 | + |
|
889 | + return $search_criteria; |
|
890 | + } |
|
891 | + |
|
892 | + /** |
|
893 | + * Check if a certain entry is approved. |
|
894 | + * |
|
895 | + * If we pass the View settings ($args) it will check the 'show_only_approved' setting before |
|
896 | + * checking the entry approved field, returning true if show_only_approved = false. |
|
897 | + * |
|
898 | + * @since 1.7 |
|
899 | + * @since 1.18 Converted check to use GravityView_Entry_Approval_Status::is_approved |
|
900 | + * |
|
901 | + * @uses GravityView_Entry_Approval_Status::is_approved |
|
902 | + * |
|
903 | + * @param array $entry Entry object |
|
904 | + * @param array $args View settings (optional) |
|
905 | + * |
|
906 | + * @return bool |
|
907 | + */ |
|
908 | + public static function is_entry_approved($entry, $args = []) |
|
909 | + { |
|
910 | + if (empty($entry['id']) || (array_key_exists('show_only_approved', $args) && !$args['show_only_approved'])) { |
|
911 | + // is implicitly approved if entry is null or View settings doesn't require to check for approval |
|
912 | + return true; |
|
913 | + } |
|
914 | + |
|
915 | + /** @since 1.19 */ |
|
916 | + if (!empty($args['admin_show_all_statuses']) && GVCommon::has_cap('gravityview_moderate_entries')) { |
|
917 | + gravityview()->log->debug('User can moderate entries, so entry is approved for viewing'); |
|
918 | + |
|
919 | + return true; |
|
920 | + } |
|
921 | + |
|
922 | + $is_approved = gform_get_meta($entry['id'], GravityView_Entry_Approval::meta_key); |
|
923 | + |
|
924 | + return GravityView_Entry_Approval_Status::is_approved($is_approved); |
|
925 | + } |
|
926 | + |
|
927 | + /** |
|
928 | + * Parse search criteria for a entries search. |
|
929 | + * |
|
930 | + * array( |
|
931 | + * 'search_field' => 1, // ID of the field |
|
932 | + * 'search_value' => '', // Value of the field to search |
|
933 | + * 'search_operator' => 'contains', // 'is', 'isnot', '>', '<', 'contains' |
|
934 | + * 'show_only_approved' => 0 or 1 // Boolean |
|
935 | + * ) |
|
936 | + * |
|
937 | + * @param array $args Array of args |
|
938 | + * @param int $form_id Gravity Forms form ID |
|
939 | + * |
|
940 | + * @return array Array of search parameters, formatted in Gravity Forms mode, using `status` key set to "active" by default, `field_filters` array with `key`, `value` and `operator` keys. |
|
941 | + */ |
|
942 | + public static function get_search_criteria($args, $form_id) |
|
943 | + { |
|
944 | + /** |
|
945 | + * Compatibility with filters hooking in `gravityview_search_criteria` instead of `gravityview_fe_search_criteria`. |
|
946 | + */ |
|
947 | + $criteria = apply_filters('gravityview_search_criteria', [], [$form_id], \GV\Utils::get($args, 'id')); |
|
948 | + $search_criteria = isset($criteria['search_criteria']) ? $criteria['search_criteria'] : ['field_filters' => []]; |
|
949 | + |
|
950 | + /** |
|
951 | + * @filter `gravityview_fe_search_criteria` Modify the search criteria |
|
952 | + * |
|
953 | + * @see GravityView_Widget_Search::filter_entries Adds the default search criteria |
|
954 | + * |
|
955 | + * @param array $search_criteria Empty `field_filters` key |
|
956 | + * @param int $form_id ID of the Gravity Forms form that is being searched |
|
957 | + * @param array $args The View settings. |
|
958 | + */ |
|
959 | + $search_criteria = apply_filters('gravityview_fe_search_criteria', $search_criteria, $form_id, $args); |
|
960 | + |
|
961 | + if (!is_array($search_criteria)) { |
|
962 | + return []; |
|
963 | + } |
|
964 | + |
|
965 | + $original_search_criteria = $search_criteria; |
|
966 | + |
|
967 | + gravityview()->log->debug('[get_search_criteria] Search Criteria after hook gravityview_fe_search_criteria: ', ['data' =>$search_criteria]); |
|
968 | + |
|
969 | + // implicity search |
|
970 | + if (!empty($args['search_value'])) { |
|
971 | + |
|
972 | + // Search operator options. Options: `is` or `contains` |
|
973 | + $operator = !empty($args['search_operator']) && in_array($args['search_operator'], ['is', 'isnot', '>', '<', 'contains']) ? $args['search_operator'] : 'contains'; |
|
974 | + |
|
975 | + $search_criteria['field_filters'][] = [ |
|
976 | + 'key' => \GV\Utils::_GET('search_field', \GV\Utils::get($args, 'search_field')), // The field ID to search |
|
977 | + 'value' => _wp_specialchars($args['search_value']), // The value to search. Encode ampersands but not quotes. |
|
978 | + 'operator' => $operator, |
|
979 | + ]; |
|
980 | + |
|
981 | + // Lock search mode to "all" with implicit presearch filter. |
|
982 | + $search_criteria['field_filters']['mode'] = 'all'; |
|
983 | + } |
|
984 | + |
|
985 | + if ($search_criteria !== $original_search_criteria) { |
|
986 | + gravityview()->log->debug('[get_search_criteria] Search Criteria after implicity search: ', ['data' => $search_criteria]); |
|
987 | + } |
|
988 | + |
|
989 | + // Handle setting date range |
|
990 | + $search_criteria = self::process_search_dates($args, $search_criteria); |
|
991 | + |
|
992 | + if ($search_criteria !== $original_search_criteria) { |
|
993 | + gravityview()->log->debug('[get_search_criteria] Search Criteria after date params: ', ['data' => $search_criteria]); |
|
994 | + } |
|
995 | + |
|
996 | + // remove not approved entries |
|
997 | + $search_criteria = self::process_search_only_approved($args, $search_criteria); |
|
998 | + |
|
999 | + /** |
|
1000 | + * @filter `gravityview_status` Modify entry status requirements to be included in search results. |
|
1001 | + * |
|
1002 | + * @param string $status Default: `active`. Accepts all Gravity Forms entry statuses, including `spam` and `trash` |
|
1003 | + */ |
|
1004 | + $search_criteria['status'] = apply_filters('gravityview_status', 'active', $args); |
|
1005 | + |
|
1006 | + return $search_criteria; |
|
1007 | + } |
|
1008 | + |
|
1009 | + /** |
|
1010 | + * Core function to calculate View multi entries (directory) based on a set of arguments ($args): |
|
1011 | + * $id - View id |
|
1012 | + * $page_size - Page |
|
1013 | + * $sort_field - form field id to sort |
|
1014 | + * $sort_direction - ASC / DESC |
|
1015 | + * $start_date - Ymd |
|
1016 | + * $end_date - Ymd |
|
1017 | + * $class - assign a html class to the view |
|
1018 | + * $offset (optional) - This is the start point in the current data set (0 index based). |
|
1019 | + * |
|
1020 | + * |
|
1021 | + * |
|
1022 | + * @uses gravityview_get_entries() |
|
1023 | + * |
|
1024 | + * @param array $args\n |
|
1025 | + * - $id - View id |
|
1026 | + * - $page_size - Page |
|
1027 | + * - $sort_field - form field id to sort |
|
1028 | + * - $sort_direction - ASC / DESC |
|
1029 | + * - $start_date - Ymd |
|
1030 | + * - $end_date - Ymd |
|
1031 | + * - $class - assign a html class to the view |
|
1032 | + * - $offset (optional) - This is the start point in the current data set (0 index based). |
|
1033 | + * @param int $form_id Gravity Forms Form ID |
|
1034 | + * |
|
1035 | + * @return array Associative array with `count`, `entries`, and `paging` keys. `count` has the total entries count, `entries` is an array with Gravity Forms full entry data, `paging` is an array with `offset` and `page_size` keys |
|
1036 | + */ |
|
1037 | + public static function get_view_entries($args, $form_id) |
|
1038 | + { |
|
1039 | + gravityview()->log->debug('[get_view_entries] init'); |
|
1040 | + // start filters and sorting |
|
1041 | + |
|
1042 | + $parameters = self::get_view_entries_parameters($args, $form_id); |
|
1043 | + |
|
1044 | + $count = 0; // Must be defined so that gravityview_get_entries can use by reference |
|
1045 | + |
|
1046 | + // fetch entries |
|
1047 | + list($entries, $paging, $count) = |
|
1048 | + \GV\Mocks\GravityView_frontend_get_view_entries($args, $form_id, $parameters, $count); |
|
1049 | + |
|
1050 | + gravityview()->log->debug('Get Entries. Found: {count} entries', ['count' => $count, 'data' => $entries]); |
|
1051 | + |
|
1052 | + /** |
|
1053 | + * @filter `gravityview_view_entries` Filter the entries output to the View |
|
1054 | + * |
|
1055 | + * @deprecated since 1.5.2 |
|
1056 | + * |
|
1057 | + * @param array $args View settings associative array |
|
1058 | + * |
|
1059 | + * @var array |
|
1060 | + */ |
|
1061 | + $entries = apply_filters('gravityview_view_entries', $entries, $args); |
|
1062 | + |
|
1063 | + $return = [ |
|
1064 | + 'count' => $count, |
|
1065 | + 'entries' => $entries, |
|
1066 | + 'paging' => $paging, |
|
1067 | + ]; |
|
1068 | + |
|
1069 | + /** |
|
1070 | + * @filter `gravityview/view/entries` Filter the entries output to the View |
|
1071 | + * |
|
1072 | + * @param array $criteria associative array containing count, entries & paging |
|
1073 | + * @param array $args View settings associative array |
|
1074 | + * |
|
1075 | + * @since 1.5.2 |
|
1076 | + */ |
|
1077 | + return apply_filters('gravityview/view/entries', $return, $args); |
|
1078 | + } |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * Get an array of search parameters formatted as Gravity Forms requires. |
|
1082 | + * |
|
1083 | + * Results are filtered by `gravityview_get_entries` and `gravityview_get_entries_{View ID}` filters |
|
1084 | + * |
|
1085 | + * @uses GravityView_frontend::get_search_criteria |
|
1086 | + * @uses GravityView_frontend::get_search_criteria_paging |
|
1087 | + * |
|
1088 | + * @since 1.20 |
|
1089 | + * @see \GV\View_Settings::defaults For $args options |
|
1090 | + * |
|
1091 | + * @param array $args Array of View settings, as structured in \GV\View_Settings::defaults |
|
1092 | + * @param int $form_id Gravity Forms form ID to search |
|
1093 | + * |
|
1094 | + * @return array With `search_criteria`, `sorting`, `paging`, `cache` keys |
|
1095 | + */ |
|
1096 | + public static function get_view_entries_parameters($args = [], $form_id = 0) |
|
1097 | + { |
|
1098 | + if (!is_array($args) || !is_numeric($form_id)) { |
|
1099 | + gravityview()->log->error('Passed args are not an array or the form ID is not numeric'); |
|
1100 | + |
|
1101 | + return []; |
|
1102 | + } |
|
1103 | + |
|
1104 | + $form_id = intval($form_id); |
|
1105 | + |
|
1106 | + /** |
|
1107 | + * Process search parameters. |
|
1108 | + * |
|
1109 | + * @var array |
|
1110 | + */ |
|
1111 | + $search_criteria = self::get_search_criteria($args, $form_id); |
|
1112 | + |
|
1113 | + $paging = self::get_search_criteria_paging($args); |
|
1114 | + |
|
1115 | + $parameters = [ |
|
1116 | + 'search_criteria' => $search_criteria, |
|
1117 | + 'sorting' => self::updateViewSorting($args, $form_id), |
|
1118 | + 'paging' => $paging, |
|
1119 | + 'cache' => isset($args['cache']) ? $args['cache'] : true, |
|
1120 | + ]; |
|
1121 | + |
|
1122 | + /** |
|
1123 | + * @filter `gravityview_get_entries` Filter get entries criteria |
|
1124 | + * |
|
1125 | + * @param array $parameters Array with `search_criteria`, `sorting` and `paging` keys. |
|
1126 | + * @param array $args View configuration args. { |
|
1127 | + * |
|
1128 | + * @var int $id View id |
|
1129 | + * @var int $page_size Number of entries to show per page |
|
1130 | + * @var string $sort_field Form field id to sort |
|
1131 | + * @var string $sort_direction Sorting direction ('ASC', 'DESC', or 'RAND') |
|
1132 | + * @var string $start_date - Ymd |
|
1133 | + * @var string $end_date - Ymd |
|
1134 | + * @var string $class - assign a html class to the view |
|
1135 | + * @var string $offset (optional) - This is the start point in the current data set (0 index based). |
|
1136 | + * } |
|
1137 | + * |
|
1138 | + * @param int $form_id ID of Gravity Forms form |
|
1139 | + */ |
|
1140 | + $parameters = apply_filters('gravityview_get_entries', $parameters, $args, $form_id); |
|
1141 | + |
|
1142 | + /** |
|
1143 | + * @filter `gravityview_get_entries_{View ID}` Filter get entries criteria |
|
1144 | + * |
|
1145 | + * @param array $parameters Array with `search_criteria`, `sorting` and `paging` keys. |
|
1146 | + * @param array $args View configuration args. |
|
1147 | + */ |
|
1148 | + $parameters = apply_filters('gravityview_get_entries_'.\GV\Utils::get($args, 'id'), $parameters, $args, $form_id); |
|
1149 | + |
|
1150 | + gravityview()->log->debug('$parameters passed to gravityview_get_entries(): ', ['data' => $parameters]); |
|
1151 | + |
|
1152 | + return $parameters; |
|
1153 | + } |
|
1154 | + |
|
1155 | + /** |
|
1156 | + * Get the paging array for the View. |
|
1157 | + * |
|
1158 | + * @since 1.19.5 |
|
1159 | + * |
|
1160 | + * @param $args |
|
1161 | + * @param int $form_id |
|
1162 | + */ |
|
1163 | + public static function get_search_criteria_paging($args) |
|
1164 | + { |
|
1165 | + |
|
1166 | + /** |
|
1167 | + * @filter `gravityview_default_page_size` The default number of entries displayed in a View |
|
1168 | + * |
|
1169 | + * @since 1.1.6 |
|
1170 | + * |
|
1171 | + * @param int $default_page_size Default: 25 |
|
1172 | + */ |
|
1173 | + $default_page_size = apply_filters('gravityview_default_page_size', 25); |
|
1174 | + |
|
1175 | + // Paging & offset |
|
1176 | + $page_size = !empty($args['page_size']) ? intval($args['page_size']) : $default_page_size; |
|
1177 | + |
|
1178 | + if (-1 === $page_size) { |
|
1179 | + $page_size = PHP_INT_MAX; |
|
1180 | + } |
|
1181 | + |
|
1182 | + $curr_page = empty($_GET['pagenum']) ? 1 : intval($_GET['pagenum']); |
|
1183 | + $offset = ($curr_page - 1) * $page_size; |
|
1184 | + |
|
1185 | + if (!empty($args['offset'])) { |
|
1186 | + $offset += intval($args['offset']); |
|
1187 | + } |
|
1188 | + |
|
1189 | + $paging = [ |
|
1190 | + 'offset' => $offset, |
|
1191 | + 'page_size' => $page_size, |
|
1192 | + ]; |
|
1193 | + |
|
1194 | + gravityview()->log->debug('Paging: ', ['data' => $paging]); |
|
1195 | + |
|
1196 | + return $paging; |
|
1197 | + } |
|
1198 | + |
|
1199 | + /** |
|
1200 | + * Updates the View sorting criteria. |
|
1201 | + * |
|
1202 | + * @since 1.7 |
|
1203 | + * |
|
1204 | + * @param array $args View settings. Required to have `sort_field` and `sort_direction` keys |
|
1205 | + * @param int $form_id The ID of the form used to sort |
|
1206 | + * |
|
1207 | + * @return array $sorting Array with `key`, `direction` and `is_numeric` keys |
|
1208 | + */ |
|
1209 | + public static function updateViewSorting($args, $form_id) |
|
1210 | + { |
|
1211 | + $sorting = []; |
|
1212 | + |
|
1213 | + $has_values = isset($_GET['sort']); |
|
1214 | + |
|
1215 | + if ($has_values && is_array($_GET['sort'])) { |
|
1216 | + $sorts = array_keys($_GET['sort']); |
|
1217 | + $dirs = array_values($_GET['sort']); |
|
1218 | + |
|
1219 | + if ($has_values = array_filter($dirs)) { |
|
1220 | + $sort_field_id = end($sorts); |
|
1221 | + $sort_direction = end($dirs); |
|
1222 | + } |
|
1223 | + } |
|
1224 | + |
|
1225 | + if (!isset($sort_field_id)) { |
|
1226 | + $sort_field_id = isset($_GET['sort']) ? $_GET['sort'] : \GV\Utils::get($args, 'sort_field'); |
|
1227 | + } |
|
1228 | + |
|
1229 | + if (!isset($sort_direction)) { |
|
1230 | + $sort_direction = isset($_GET['dir']) ? $_GET['dir'] : \GV\Utils::get($args, 'sort_direction'); |
|
1231 | + } |
|
1232 | + |
|
1233 | + if (is_array($sort_field_id)) { |
|
1234 | + $sort_field_id = array_pop($sort_field_id); |
|
1235 | + } |
|
1236 | + |
|
1237 | + if (is_array($sort_direction)) { |
|
1238 | + $sort_direction = array_pop($sort_direction); |
|
1239 | + } |
|
1240 | + |
|
1241 | + if (!empty($sort_field_id)) { |
|
1242 | + if (is_array($sort_field_id)) { |
|
1243 | + $sort_direction = array_values($sort_field_id); |
|
1244 | + $sort_field_id = array_keys($sort_field_id); |
|
1245 | + |
|
1246 | + $sort_field_id = reset($sort_field_id); |
|
1247 | + $sort_direction = reset($sort_direction); |
|
1248 | + } |
|
1249 | + |
|
1250 | + $sort_field_id = self::_override_sorting_id_by_field_type($sort_field_id, $form_id); |
|
1251 | + $sorting = [ |
|
1252 | + 'key' => $sort_field_id, |
|
1253 | + 'direction' => strtolower($sort_direction), |
|
1254 | + 'is_numeric' => GVCommon::is_field_numeric($form_id, $sort_field_id), |
|
1255 | + ]; |
|
1256 | + |
|
1257 | + if ('RAND' === $sort_direction) { |
|
1258 | + $form = GFAPI::get_form($form_id); |
|
1259 | + |
|
1260 | + // Get the first GF_Field field ID, set as the key for entry randomization |
|
1261 | + if (!empty($form['fields'])) { |
|
1262 | + |
|
1263 | + /** @var GF_Field $field */ |
|
1264 | + foreach ($form['fields'] as $field) { |
|
1265 | + if (!is_a($field, 'GF_Field')) { |
|
1266 | + continue; |
|
1267 | + } |
|
1268 | + |
|
1269 | + $sorting = [ |
|
1270 | + 'key' => $field->id, |
|
1271 | + 'is_numeric' => false, |
|
1272 | + 'direction' => 'RAND', |
|
1273 | + ]; |
|
1274 | + |
|
1275 | + break; |
|
1276 | + } |
|
1277 | + } |
|
1278 | + } |
|
1279 | + } |
|
1280 | + |
|
1281 | + if (!class_exists('GravityView_View')) { |
|
1282 | + gravityview()->plugin->include_legacy_frontend(true); |
|
1283 | + } |
|
1284 | + |
|
1285 | + GravityView_View::getInstance()->setSorting($sorting); |
|
1286 | + |
|
1287 | + gravityview()->log->debug('[updateViewSorting] Sort Criteria : ', ['data' => $sorting]); |
|
1288 | + |
|
1289 | + return $sorting; |
|
1290 | + } |
|
1291 | + |
|
1292 | + /** |
|
1293 | + * Override sorting per field. |
|
1294 | + * |
|
1295 | + * Currently only modifies sorting ID when sorting by the full name. Sorts by first name. |
|
1296 | + * Use the `gravityview/sorting/full-name` filter to override. |
|
1297 | + * |
|
1298 | + * @todo Filter from GravityView_Field |
|
1299 | + * |
|
1300 | + * @since 1.7.4 |
|
1301 | + * |
|
1302 | + * @internal Hi developer! Although this is public, don't call this method; we're going to replace it. |
|
1303 | + * |
|
1304 | + * @param int|string|array $sort_field_id Field used for sorting (`id` or `1.2`), or an array for multisorts |
|
1305 | + * @param int $form_id GF Form ID |
|
1306 | + * |
|
1307 | + * @return string|array Possibly modified sorting ID. Array if $sort_field_id is passed as array. |
|
1308 | + */ |
|
1309 | + public static function _override_sorting_id_by_field_type($sort_field_id, $form_id) |
|
1310 | + { |
|
1311 | + if (is_array($sort_field_id)) { |
|
1312 | + $modified_ids = []; |
|
1313 | + foreach ($sort_field_id as $_sort_field_id) { |
|
1314 | + $modified_ids[] = self::_override_sorting_id_by_field_type($_sort_field_id, $form_id); |
|
1315 | + } |
|
1316 | + |
|
1317 | + return $modified_ids; |
|
1318 | + } |
|
1319 | + |
|
1320 | + $form = gravityview_get_form($form_id); |
|
1321 | + |
|
1322 | + $sort_field = GFFormsModel::get_field($form, $sort_field_id); |
|
1323 | + |
|
1324 | + if (!$sort_field) { |
|
1325 | + return $sort_field_id; |
|
1326 | + } |
|
1327 | + |
|
1328 | + switch ($sort_field['type']) { |
|
1329 | + |
|
1330 | + case 'address': |
|
1331 | + // Sorting by full address |
|
1332 | + if (floatval($sort_field_id) === floor($sort_field_id)) { |
|
1333 | + |
|
1334 | + /** |
|
1335 | + * Override how to sort when sorting address. |
|
1336 | + * |
|
1337 | + * @since 1.8 |
|
1338 | + * |
|
1339 | + * @param string $address_part `street`, `street2`, `city`, `state`, `zip`, or `country` (default: `city`) |
|
1340 | + * @param string $sort_field_id Field used for sorting |
|
1341 | + * @param int $form_id GF Form ID |
|
1342 | + */ |
|
1343 | + $address_part = apply_filters('gravityview/sorting/address', 'city', $sort_field_id, $form_id); |
|
1344 | + |
|
1345 | + switch (strtolower($address_part)) { |
|
1346 | + case 'street': |
|
1347 | + $sort_field_id .= '.1'; |
|
1348 | + break; |
|
1349 | + case 'street2': |
|
1350 | + $sort_field_id .= '.2'; |
|
1351 | + break; |
|
1352 | + default: |
|
1353 | + case 'city': |
|
1354 | + $sort_field_id .= '.3'; |
|
1355 | + break; |
|
1356 | + case 'state': |
|
1357 | + $sort_field_id .= '.4'; |
|
1358 | + break; |
|
1359 | + case 'zip': |
|
1360 | + $sort_field_id .= '.5'; |
|
1361 | + break; |
|
1362 | + case 'country': |
|
1363 | + $sort_field_id .= '.6'; |
|
1364 | + break; |
|
1365 | + } |
|
1366 | + } |
|
1367 | + break; |
|
1368 | + case 'name': |
|
1369 | + // Sorting by full name, not first, last, etc. |
|
1370 | + if (floatval($sort_field_id) === floor($sort_field_id)) { |
|
1371 | + /** |
|
1372 | + * @filter `gravityview/sorting/full-name` Override how to sort when sorting full name. |
|
1373 | + * |
|
1374 | + * @since 1.7.4 |
|
1375 | + * |
|
1376 | + * @param string $name_part Sort by `first` or `last` (default: `first`) |
|
1377 | + * @param string $sort_field_id Field used for sorting |
|
1378 | + * @param int $form_id GF Form ID |
|
1379 | + */ |
|
1380 | + $name_part = apply_filters('gravityview/sorting/full-name', 'first', $sort_field_id, $form_id); |
|
1381 | + |
|
1382 | + if ('last' === strtolower($name_part)) { |
|
1383 | + $sort_field_id .= '.6'; |
|
1384 | + } else { |
|
1385 | + $sort_field_id .= '.3'; |
|
1386 | + } |
|
1387 | + } |
|
1388 | + break; |
|
1389 | + case 'list': |
|
1390 | + $sort_field_id = false; |
|
1391 | + break; |
|
1392 | + case 'time': |
|
1393 | + |
|
1394 | + /** |
|
1395 | + * @filter `gravityview/sorting/time` Override how to sort when sorting time |
|
1396 | + * |
|
1397 | + * @see GravityView_Field_Time |
|
1398 | + * @since 1.14 |
|
1399 | + * |
|
1400 | + * @param string $name_part Field used for sorting |
|
1401 | + * @param int $form_id GF Form ID |
|
1402 | + */ |
|
1403 | + $sort_field_id = apply_filters('gravityview/sorting/time', $sort_field_id, $form_id); |
|
1404 | + break; |
|
1405 | + } |
|
1406 | + |
|
1407 | + return $sort_field_id; |
|
1408 | + } |
|
1409 | + |
|
1410 | + /** |
|
1411 | + * Verify if user requested a single entry view. |
|
1412 | + * |
|
1413 | + * @since 2.3.3 Added return null |
|
1414 | + * |
|
1415 | + * @return bool|string|null false if not, single entry slug if true, null if \GV\Entry doesn't exist yet |
|
1416 | + */ |
|
1417 | + public static function is_single_entry() |
|
1418 | + { |
|
1419 | + |
|
1420 | + // Since this is a public method, it can be called outside of the plugin. Don't assume things have been loaded properly. |
|
1421 | + if (!class_exists('\GV\Entry')) { |
|
1422 | + |
|
1423 | + // Not using gravityview()->log->error(), since that may not exist yet either! |
|
1424 | + do_action('gravityview_log_error', '\GV\Entry not defined yet. Backtrace: '.wp_debug_backtrace_summary()); |
|
1425 | + |
|
1426 | + return null; |
|
1427 | + } |
|
1428 | + |
|
1429 | + $var_name = \GV\Entry::get_endpoint_name(); |
|
1430 | + |
|
1431 | + $single_entry = get_query_var($var_name); |
|
1432 | + |
|
1433 | + /** |
|
1434 | + * Modify the entry that is being displayed. |
|
1435 | + * |
|
1436 | + * @internal Should only be used by things like the oEmbed functionality. |
|
1437 | + * |
|
1438 | + * @since 1.6 |
|
1439 | + */ |
|
1440 | + $single_entry = apply_filters('gravityview/is_single_entry', $single_entry); |
|
1441 | + |
|
1442 | + if (empty($single_entry)) { |
|
1443 | + return false; |
|
1444 | + } else { |
|
1445 | + return $single_entry; |
|
1446 | + } |
|
1447 | + } |
|
1448 | + |
|
1449 | + /** |
|
1450 | + * Register styles and scripts. |
|
1451 | + * |
|
1452 | + * @return void |
|
1453 | + */ |
|
1454 | + public function add_scripts_and_styles() |
|
1455 | + { |
|
1456 | + global $post, $posts; |
|
1457 | + // enqueue template specific styles |
|
1458 | + if ($this->getGvOutputData()) { |
|
1459 | + $views = $this->getGvOutputData()->get_views(); |
|
1460 | + |
|
1461 | + foreach ($views as $view_id => $data) { |
|
1462 | + $view = \GV\View::by_id($data['id']); |
|
1463 | + $view_id = $view->ID; |
|
1464 | + $template_id = gravityview_get_template_id($view->ID); |
|
1465 | + $data = $view->as_data(); |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * Don't enqueue the scripts or styles if it's not going to be displayed. |
|
1469 | + * |
|
1470 | + * @since 1.15 |
|
1471 | + */ |
|
1472 | + if (is_user_logged_in() && false === GVCommon::has_cap('read_gravityview', $view_id)) { |
|
1473 | + continue; |
|
1474 | + } |
|
1475 | + |
|
1476 | + // By default, no thickbox |
|
1477 | + $js_dependencies = ['jquery', 'gravityview-jquery-cookie']; |
|
1478 | + $css_dependencies = []; |
|
1479 | + |
|
1480 | + $lightbox = $view->settings->get('lightbox'); |
|
1481 | + |
|
1482 | + // If the thickbox is enqueued, add dependencies |
|
1483 | + if ($lightbox) { |
|
1484 | + global $wp_filter; |
|
1485 | + |
|
1486 | + /** |
|
1487 | + * @filter `gravity_view_lightbox_script` Override the lightbox script to enqueue. Default: `thickbox` |
|
1488 | + * |
|
1489 | + * @param string $script_slug If you want to use a different lightbox script, return the name of it here. |
|
1490 | + * |
|
1491 | + * @deprecated 2.5.1 Naming. See `gravityview_lightbox_script` instead. |
|
1492 | + */ |
|
1493 | + $js_dependency = apply_filters_deprecated('gravity_view_lightbox_script', ['thickbox'], '2.5.1', 'gravityview_lightbox_script'); |
|
1494 | + |
|
1495 | + /** |
|
1496 | + * @filter `gravityview_lightbox_script` Override the lightbox script to enqueue. Default: `thickbox` |
|
1497 | + * |
|
1498 | + * @since 2.5.1 |
|
1499 | + * |
|
1500 | + * @param string $script_slug If you want to use a different lightbox script, return the name of it here. |
|
1501 | + * @param \GV\View The View. |
|
1502 | + */ |
|
1503 | + $js_dependency = apply_filters('gravityview_lightbox_script', $js_dependency, $view); |
|
1504 | + $js_dependencies[] = $js_dependency; |
|
1505 | + |
|
1506 | + /** |
|
1507 | + * @filter `gravity_view_lightbox_style` Modify the lightbox CSS slug. Default: `thickbox` |
|
1508 | + * |
|
1509 | + * @param string $script_slug If you want to use a different lightbox script, return the name of its CSS file here. |
|
1510 | + * |
|
1511 | + * @deprecated 2.5.1 Naming. See `gravityview_lightbox_style` instead. |
|
1512 | + */ |
|
1513 | + $css_dependency = apply_filters_deprecated('gravity_view_lightbox_style', ['thickbox'], '2.5.1', 'gravityview_lightbox_style'); |
|
1514 | + |
|
1515 | + /** |
|
1516 | + * @filter `gravityview_lightbox_script` Override the lightbox script to enqueue. Default: `thickbox` |
|
1517 | + * |
|
1518 | + * @since 2.5.1 |
|
1519 | + * |
|
1520 | + * @param string $script_slug If you want to use a different lightbox script, return the name of it here. |
|
1521 | + * @param \GV\View The View. |
|
1522 | + */ |
|
1523 | + $css_dependency = apply_filters('gravityview_lightbox_style', $css_dependency, $view); |
|
1524 | + $css_dependencies[] = $css_dependency; |
|
1525 | + } |
|
1526 | + |
|
1527 | + /** |
|
1528 | + * If the form has checkbox fields, enqueue dashicons. |
|
1529 | + * |
|
1530 | + * @see https://github.com/katzwebservices/GravityView/issues/536 |
|
1531 | + * @since 1.15 |
|
1532 | + */ |
|
1533 | + if (gravityview_view_has_single_checkbox_or_radio($data['form'], $data['fields'])) { |
|
1534 | + $css_dependencies[] = 'dashicons'; |
|
1535 | + } |
|
1536 | + |
|
1537 | + wp_register_script('gravityview-jquery-cookie', plugins_url('assets/lib/jquery.cookie/jquery.cookie.min.js', GRAVITYVIEW_FILE), ['jquery'], GravityView_Plugin::version, true); |
|
1538 | + |
|
1539 | + $script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
1540 | + |
|
1541 | + wp_register_script('gravityview-fe-view', plugins_url('assets/js/fe-views'.$script_debug.'.js', GRAVITYVIEW_FILE), apply_filters('gravityview_js_dependencies', $js_dependencies), GravityView_Plugin::version, true); |
|
1542 | + |
|
1543 | + wp_enqueue_script('gravityview-fe-view'); |
|
1544 | + |
|
1545 | + if (!empty($data['atts']['sort_columns'])) { |
|
1546 | + wp_enqueue_style('gravityview_font', plugins_url('assets/css/font.css', GRAVITYVIEW_FILE), $css_dependencies, GravityView_Plugin::version, 'all'); |
|
1547 | + } |
|
1548 | + |
|
1549 | + $this->enqueue_default_style($css_dependencies); |
|
1550 | + |
|
1551 | + self::add_style($template_id); |
|
1552 | + } |
|
1553 | + |
|
1554 | + if ('wp_print_footer_scripts' === current_filter()) { |
|
1555 | + $js_localization = [ |
|
1556 | + 'cookiepath' => COOKIEPATH, |
|
1557 | + 'clear' => _x('Clear', 'Clear all data from the form', 'gravityview'), |
|
1558 | + 'reset' => _x('Reset', 'Reset the search form to the state that existed on page load', 'gravityview'), |
|
1559 | + ]; |
|
1560 | + |
|
1561 | + /** |
|
1562 | + * @filter `gravityview_js_localization` Modify the array passed to wp_localize_script() |
|
1563 | + * |
|
1564 | + * @param array $js_localization The data padded to the Javascript file |
|
1565 | + * @param array $views Array of View data arrays with View settings |
|
1566 | + */ |
|
1567 | + $js_localization = apply_filters('gravityview_js_localization', $js_localization, $views); |
|
1568 | + |
|
1569 | + wp_localize_script('gravityview-fe-view', 'gvGlobals', $js_localization); |
|
1570 | + } |
|
1571 | + } |
|
1572 | + } |
|
1573 | + |
|
1574 | + /** |
|
1575 | + * Handle enqueuing the `gravityview_default_style` stylesheet. |
|
1576 | + * |
|
1577 | + * @since 1.17 |
|
1578 | + * |
|
1579 | + * @param array $css_dependencies Dependencies for the `gravityview_default_style` stylesheet |
|
1580 | + * |
|
1581 | + * @return void |
|
1582 | + */ |
|
1583 | + private function enqueue_default_style($css_dependencies = []) |
|
1584 | + { |
|
1585 | + |
|
1586 | + /** |
|
1587 | + * @filter `gravityview_use_legacy_search_css` Should GravityView use the legacy Search Bar stylesheet (from before Version 1.17)? |
|
1588 | + * |
|
1589 | + * @since 1.17 |
|
1590 | + * |
|
1591 | + * @param bool $use_legacy_search_style If true, loads `gv-legacy-search(-rtl).css`. If false, loads `gv-default-styles(-rtl).css`. `-rtl` is added on RTL websites. Default: `false` |
|
1592 | + */ |
|
1593 | + $use_legacy_search_style = apply_filters('gravityview_use_legacy_search_style', false); |
|
1594 | + |
|
1595 | + $rtl = is_rtl() ? '-rtl' : ''; |
|
1596 | + |
|
1597 | + $css_file_base = $use_legacy_search_style ? 'gv-legacy-search' : 'gv-default-styles'; |
|
1598 | + |
|
1599 | + $path = gravityview_css_url($css_file_base.$rtl.'.css'); |
|
1600 | + |
|
1601 | + wp_enqueue_style('gravityview_default_style', $path, $css_dependencies, GravityView_Plugin::version, 'all'); |
|
1602 | + } |
|
1603 | + |
|
1604 | + /** |
|
1605 | + * Add template extra style if exists. |
|
1606 | + * |
|
1607 | + * @param string $template_id |
|
1608 | + */ |
|
1609 | + public static function add_style($template_id) |
|
1610 | + { |
|
1611 | + if (!empty($template_id) && wp_style_is('gravityview_style_'.$template_id, 'registered')) { |
|
1612 | + gravityview()->log->debug('Adding extra template style for {template_id}', ['template_id' => $template_id]); |
|
1613 | + wp_enqueue_style('gravityview_style_'.$template_id); |
|
1614 | + } elseif (empty($template_id)) { |
|
1615 | + gravityview()->log->error('Cannot add template style; template_id is empty'); |
|
1616 | + } else { |
|
1617 | + gravityview()->log->error('Cannot add template style; {template_id} is not registered', ['template_id' => 'gravityview_style_'.$template_id]); |
|
1618 | + } |
|
1619 | + } |
|
1620 | + |
|
1621 | + /** |
|
1622 | + * Inject the sorting links on the table columns. |
|
1623 | + * |
|
1624 | + * Callback function for hook 'gravityview/template/field_label' |
|
1625 | + * |
|
1626 | + * @see GravityView_API::field_label() (in includes/class-api.php) |
|
1627 | + * @since 1.7 |
|
1628 | + * |
|
1629 | + * @param string $label Field label |
|
1630 | + * @param array $field Field settings |
|
1631 | + * @param array $form Form object |
|
1632 | + * |
|
1633 | + * @return string Field Label |
|
1634 | + */ |
|
1635 | + public function add_columns_sort_links($label = '', $field, $form) |
|
1636 | + { |
|
1637 | + |
|
1638 | + /** |
|
1639 | + * Not a table-based template; don't add sort icons. |
|
1640 | + * |
|
1641 | + * @since 1.12 |
|
1642 | + */ |
|
1643 | + if (!preg_match('/table/ism', GravityView_View::getInstance()->getTemplatePartSlug())) { |
|
1644 | + return $label; |
|
1645 | + } |
|
1646 | + |
|
1647 | + if (!$this->is_field_sortable($field['id'], $form)) { |
|
1648 | + return $label; |
|
1649 | + } |
|
1650 | + |
|
1651 | + $sorting = GravityView_View::getInstance()->getSorting(); |
|
1652 | + |
|
1653 | + $class = 'gv-sort'; |
|
1654 | + |
|
1655 | + $sort_field_id = self::_override_sorting_id_by_field_type($field['id'], $form['id']); |
|
1656 | + |
|
1657 | + $sort_args = [ |
|
1658 | + 'sort' => $field['id'], |
|
1659 | + 'dir' => 'asc', |
|
1660 | + ]; |
|
1661 | + |
|
1662 | + if (!empty($sorting['key']) && (string) $sort_field_id === (string) $sorting['key']) { |
|
1663 | + //toggle sorting direction. |
|
1664 | + if ('asc' === $sorting['direction']) { |
|
1665 | + $sort_args['dir'] = 'desc'; |
|
1666 | + $class .= ' gv-icon-sort-desc'; |
|
1667 | + } else { |
|
1668 | + $sort_args['dir'] = 'asc'; |
|
1669 | + $class .= ' gv-icon-sort-asc'; |
|
1670 | + } |
|
1671 | + } else { |
|
1672 | + $class .= ' gv-icon-caret-up-down'; |
|
1673 | + } |
|
1674 | + |
|
1675 | + $url = add_query_arg($sort_args, remove_query_arg(['pagenum'])); |
|
1676 | + |
|
1677 | + return '<a href="'.esc_url_raw($url).'" class="'.$class.'" ></a> '.$label; |
|
1678 | + } |
|
1679 | + |
|
1680 | + /** |
|
1681 | + * Checks if field (column) is sortable. |
|
1682 | + * |
|
1683 | + * @param string $field Field settings |
|
1684 | + * @param array $form Gravity Forms form array |
|
1685 | + * |
|
1686 | + * @since 1.7 |
|
1687 | + * |
|
1688 | + * @return bool True: Yes, field is sortable; False: not sortable |
|
1689 | + */ |
|
1690 | + public function is_field_sortable($field_id = '', $form = []) |
|
1691 | + { |
|
1692 | + $field_type = $field_id; |
|
1693 | + |
|
1694 | + if (is_numeric($field_id)) { |
|
1695 | + $field = GFFormsModel::get_field($form, $field_id); |
|
1696 | + $field_type = $field ? $field->type : $field_id; |
|
1697 | + } |
|
1698 | + |
|
1699 | + $not_sortable = [ |
|
1700 | + 'edit_link', |
|
1701 | + 'delete_link', |
|
1702 | + ]; |
|
1703 | + |
|
1704 | + /** |
|
1705 | + * @depecated 2.14 |
|
1706 | + * |
|
1707 | + * @since 1.7 |
|
1708 | + */ |
|
1709 | + $not_sortable = apply_filters_deprecated('gravityview/sortable/field_blacklist', [$not_sortable, $field_type, $form], '2.14', 'gravityview/sortable/field_blocklist'); |
|
1710 | + |
|
1711 | + /** |
|
1712 | + * @filter `gravityview/sortable/field_blocklist` Modify what fields should never be sortable. |
|
1713 | + * |
|
1714 | + * @since 2.14 |
|
1715 | + * |
|
1716 | + * @param array $not_sortable Array of field types that aren't sortable. |
|
1717 | + * @param string $field_type Field type to check whether the field is sortable. |
|
1718 | + * @param array $form Gravity Forms form. |
|
1719 | + */ |
|
1720 | + $not_sortable = apply_filters('gravityview/sortable/field_blocklist', $not_sortable, $field_type, $form); |
|
1721 | + |
|
1722 | + if (in_array($field_type, $not_sortable)) { |
|
1723 | + return false; |
|
1724 | + } |
|
1725 | + |
|
1726 | + return apply_filters("gravityview/sortable/formfield_{$form['id']}_{$field_id}", apply_filters("gravityview/sortable/field_{$field_id}", true, $form)); |
|
1727 | + } |
|
1728 | 1728 | } |
1729 | 1729 | |
1730 | 1730 | GravityView_frontend::getInstance(); |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @var array |
23 | 23 | */ |
24 | - private static $search_parameters = ['gv_search', 'gv_start', 'gv_end', 'gv_id', 'gv_by', 'filter_*']; |
|
24 | + private static $search_parameters = [ 'gv_search', 'gv_start', 'gv_end', 'gv_id', 'gv_by', 'filter_*' ]; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Is the currently viewed post a `gravityview` post type? |
@@ -98,21 +98,21 @@ discard block |
||
98 | 98 | |
99 | 99 | private function initialize() |
100 | 100 | { |
101 | - add_action('wp', [$this, 'parse_content'], 11); |
|
102 | - add_filter('render_block', [$this, 'detect_views_in_block_content']); |
|
103 | - add_filter('parse_query', [$this, 'parse_query_fix_frontpage'], 10); |
|
104 | - add_action('template_redirect', [$this, 'set_entry_data'], 1); |
|
101 | + add_action( 'wp', [ $this, 'parse_content' ], 11 ); |
|
102 | + add_filter( 'render_block', [ $this, 'detect_views_in_block_content' ] ); |
|
103 | + add_filter( 'parse_query', [ $this, 'parse_query_fix_frontpage' ], 10 ); |
|
104 | + add_action( 'template_redirect', [ $this, 'set_entry_data' ], 1 ); |
|
105 | 105 | |
106 | 106 | // Enqueue scripts and styles after GravityView_Template::register_styles() |
107 | - add_action('wp_enqueue_scripts', [$this, 'add_scripts_and_styles'], 20); |
|
107 | + add_action( 'wp_enqueue_scripts', [ $this, 'add_scripts_and_styles' ], 20 ); |
|
108 | 108 | |
109 | 109 | // Enqueue and print styles in the footer. Added 1 priorty so stuff gets printed at 10 priority. |
110 | - add_action('wp_print_footer_scripts', [$this, 'add_scripts_and_styles'], 1); |
|
110 | + add_action( 'wp_print_footer_scripts', [ $this, 'add_scripts_and_styles' ], 1 ); |
|
111 | 111 | |
112 | - add_filter('the_title', [$this, 'single_entry_title'], 1, 2); |
|
113 | - add_filter('comments_open', [$this, 'comments_open'], 10, 2); |
|
112 | + add_filter( 'the_title', [ $this, 'single_entry_title' ], 1, 2 ); |
|
113 | + add_filter( 'comments_open', [ $this, 'comments_open' ], 10, 2 ); |
|
114 | 114 | |
115 | - add_action('gravityview_after', [$this, 'context_not_configured_warning']); |
|
115 | + add_action( 'gravityview_after', [ $this, 'context_not_configured_warning' ] ); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public static function getInstance() |
124 | 124 | { |
125 | - if (empty(self::$instance)) { |
|
125 | + if ( empty( self::$instance ) ) { |
|
126 | 126 | self::$instance = new self(); |
127 | 127 | self::$instance->initialize(); |
128 | 128 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | /** |
142 | 142 | * @param \GravityView_View_Data $gv_output_data |
143 | 143 | */ |
144 | - public function setGvOutputData($gv_output_data) |
|
144 | + public function setGvOutputData( $gv_output_data ) |
|
145 | 145 | { |
146 | 146 | $this->gv_output_data = $gv_output_data; |
147 | 147 | } |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | /** |
158 | 158 | * @param bool $is_search |
159 | 159 | */ |
160 | - public function setIsSearch($is_search) |
|
160 | + public function setIsSearch( $is_search ) |
|
161 | 161 | { |
162 | 162 | $this->is_search = $is_search; |
163 | 163 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * |
176 | 176 | * @param bool|int|string $single_entry |
177 | 177 | */ |
178 | - public function setSingleEntry($single_entry) |
|
178 | + public function setSingleEntry( $single_entry ) |
|
179 | 179 | { |
180 | 180 | $this->single_entry = $single_entry; |
181 | 181 | } |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @param array|int $entry Entry array or entry slug or ID |
195 | 195 | */ |
196 | - public function setEntry($entry) |
|
196 | + public function setEntry( $entry ) |
|
197 | 197 | { |
198 | - if (!is_array($entry)) { |
|
199 | - $entry = GVCommon::get_entry($entry); |
|
198 | + if ( ! is_array( $entry ) ) { |
|
199 | + $entry = GVCommon::get_entry( $entry ); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | $this->entry = $entry; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | /** |
214 | 214 | * @param int $post_id |
215 | 215 | */ |
216 | - public function setPostId($post_id) |
|
216 | + public function setPostId( $post_id ) |
|
217 | 217 | { |
218 | 218 | $this->post_id = $post_id; |
219 | 219 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | /** |
230 | 230 | * @param bool $post_has_shortcode |
231 | 231 | */ |
232 | - public function setPostHasShortcode($post_has_shortcode) |
|
232 | + public function setPostHasShortcode( $post_has_shortcode ) |
|
233 | 233 | { |
234 | 234 | $this->post_has_shortcode = $post_has_shortcode; |
235 | 235 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | /** |
246 | 246 | * @param bool $is_gravityview_post_type |
247 | 247 | */ |
248 | - public function setIsGravityviewPostType($is_gravityview_post_type) |
|
248 | + public function setIsGravityviewPostType( $is_gravityview_post_type ) |
|
249 | 249 | { |
250 | 250 | $this->is_gravityview_post_type = $is_gravityview_post_type; |
251 | 251 | } |
@@ -257,23 +257,23 @@ discard block |
||
257 | 257 | * |
258 | 258 | * @param null $view_id |
259 | 259 | */ |
260 | - public function set_context_view_id($view_id = null) |
|
260 | + public function set_context_view_id( $view_id = null ) |
|
261 | 261 | { |
262 | 262 | $multiple_views = $this->getGvOutputData() && $this->getGvOutputData()->has_multiple_views(); |
263 | 263 | |
264 | - if (!empty($view_id)) { |
|
265 | - $this->context_view_id = (int) $view_id; |
|
266 | - } elseif (isset($_GET['gvid']) && $multiple_views) { |
|
264 | + if ( ! empty( $view_id ) ) { |
|
265 | + $this->context_view_id = (int)$view_id; |
|
266 | + } elseif ( isset( $_GET[ 'gvid' ] ) && $multiple_views ) { |
|
267 | 267 | /** |
268 | 268 | * used on a has_multiple_views context. |
269 | 269 | * |
270 | 270 | * @see GravityView_API::entry_link |
271 | 271 | */ |
272 | - $this->context_view_id = (int) $_GET['gvid']; |
|
273 | - } elseif (!$multiple_views) { |
|
274 | - $array_keys = array_keys($this->getGvOutputData()->get_views()); |
|
275 | - $this->context_view_id = (int) array_pop($array_keys); |
|
276 | - unset($array_keys); |
|
272 | + $this->context_view_id = (int)$_GET[ 'gvid' ]; |
|
273 | + } elseif ( ! $multiple_views ) { |
|
274 | + $array_keys = array_keys( $this->getGvOutputData()->get_views() ); |
|
275 | + $this->context_view_id = (int)array_pop( $array_keys ); |
|
276 | + unset( $array_keys ); |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | |
@@ -300,53 +300,53 @@ discard block |
||
300 | 300 | * |
301 | 301 | * @return void |
302 | 302 | */ |
303 | - public function parse_query_fix_frontpage(&$query) |
|
303 | + public function parse_query_fix_frontpage( &$query ) |
|
304 | 304 | { |
305 | 305 | global $wp_rewrite; |
306 | 306 | |
307 | - $is_front_page = ($query->is_home || $query->is_page); |
|
308 | - $show_on_front = ('page' === get_option('show_on_front')); |
|
309 | - $front_page_id = get_option('page_on_front'); |
|
307 | + $is_front_page = ( $query->is_home || $query->is_page ); |
|
308 | + $show_on_front = ( 'page' === get_option( 'show_on_front' ) ); |
|
309 | + $front_page_id = get_option( 'page_on_front' ); |
|
310 | 310 | |
311 | - if ($is_front_page && $show_on_front && $front_page_id) { |
|
311 | + if ( $is_front_page && $show_on_front && $front_page_id ) { |
|
312 | 312 | |
313 | 313 | // Force to be an array, potentially a query string ( entry=16 ) |
314 | - $_query = wp_parse_args($query->query); |
|
314 | + $_query = wp_parse_args( $query->query ); |
|
315 | 315 | |
316 | 316 | // pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename. |
317 | - if (isset($_query['pagename']) && '' === $_query['pagename']) { |
|
318 | - unset($_query['pagename']); |
|
317 | + if ( isset( $_query[ 'pagename' ] ) && '' === $_query[ 'pagename' ] ) { |
|
318 | + unset( $_query[ 'pagename' ] ); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | // this is where will break from core wordpress |
322 | 322 | /** @internal Don't use this filter; it will be unnecessary soon - it's just a patch for specific use case */ |
323 | - $ignore = apply_filters('gravityview/internal/ignored_endpoints', ['preview', 'page', 'paged', 'cpage'], $query); |
|
324 | - $endpoints = \GV\Utils::get($wp_rewrite, 'endpoints'); |
|
325 | - foreach ((array) $endpoints as $endpoint) { |
|
326 | - $ignore[] = $endpoint[1]; |
|
323 | + $ignore = apply_filters( 'gravityview/internal/ignored_endpoints', [ 'preview', 'page', 'paged', 'cpage' ], $query ); |
|
324 | + $endpoints = \GV\Utils::get( $wp_rewrite, 'endpoints' ); |
|
325 | + foreach ( (array)$endpoints as $endpoint ) { |
|
326 | + $ignore[ ] = $endpoint[ 1 ]; |
|
327 | 327 | } |
328 | - unset($endpoints); |
|
328 | + unset( $endpoints ); |
|
329 | 329 | |
330 | 330 | // Modify the query if: |
331 | 331 | // - We're on the "Page on front" page (which we are), and: |
332 | 332 | // - The query is empty OR |
333 | 333 | // - The query includes keys that are associated with registered endpoints. `entry`, for example. |
334 | - if (empty($_query) || !array_diff(array_keys($_query), $ignore)) { |
|
334 | + if ( empty( $_query ) || ! array_diff( array_keys( $_query ), $ignore ) ) { |
|
335 | 335 | $qv = &$query->query_vars; |
336 | 336 | |
337 | 337 | // Prevent redirect when on the single entry endpoint |
338 | - if (self::is_single_entry()) { |
|
339 | - add_filter('redirect_canonical', '__return_false'); |
|
338 | + if ( self::is_single_entry() ) { |
|
339 | + add_filter( 'redirect_canonical', '__return_false' ); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | $query->is_page = true; |
343 | 343 | $query->is_home = false; |
344 | - $qv['page_id'] = $front_page_id; |
|
344 | + $qv[ 'page_id' ] = $front_page_id; |
|
345 | 345 | |
346 | 346 | // Correct <!--nextpage--> for page_on_front |
347 | - if (!empty($qv['paged'])) { |
|
348 | - $qv['page'] = $qv['paged']; |
|
349 | - unset($qv['paged']); |
|
347 | + if ( ! empty( $qv[ 'paged' ] ) ) { |
|
348 | + $qv[ 'page' ] = $qv[ 'paged' ]; |
|
349 | + unset( $qv[ 'paged' ] ); |
|
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
@@ -367,19 +367,19 @@ discard block |
||
367 | 367 | * |
368 | 368 | * @todo Once we stop using the legacy `GravityView_frontend::parse_content()` method to detect Views in post content, this code should either be dropped or promoted to some core class given its applicability to other themes/plugins |
369 | 369 | */ |
370 | - public function detect_views_in_block_content($block_content) |
|
370 | + public function detect_views_in_block_content( $block_content ) |
|
371 | 371 | { |
372 | - if (!class_exists('GV\View_Collection') || !class_exists('GV\View')) { |
|
372 | + if ( ! class_exists( 'GV\View_Collection' ) || ! class_exists( 'GV\View' ) ) { |
|
373 | 373 | return $block_content; |
374 | 374 | } |
375 | 375 | |
376 | 376 | $gv_view_data = GravityView_View_Data::getInstance(); |
377 | 377 | |
378 | - $views = \GV\View_Collection::from_content($block_content); |
|
378 | + $views = \GV\View_Collection::from_content( $block_content ); |
|
379 | 379 | |
380 | - foreach ($views->all() as $view) { |
|
381 | - if (!$gv_view_data->views->contains($view->ID)) { |
|
382 | - $gv_view_data->views->add($view); |
|
380 | + foreach ( $views->all() as $view ) { |
|
381 | + if ( ! $gv_view_data->views->contains( $view->ID ) ) { |
|
382 | + $gv_view_data->views->add( $view ); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | |
@@ -393,54 +393,54 @@ discard block |
||
393 | 393 | * |
394 | 394 | * @return void |
395 | 395 | */ |
396 | - public function parse_content($wp = []) |
|
396 | + public function parse_content( $wp = [ ] ) |
|
397 | 397 | { |
398 | 398 | global $post; |
399 | 399 | |
400 | 400 | // If in admin and NOT AJAX request, get outta here. |
401 | - if (gravityview()->request->is_admin()) { |
|
401 | + if ( gravityview()->request->is_admin() ) { |
|
402 | 402 | return; |
403 | 403 | } |
404 | 404 | |
405 | - $is_GV_post_type = 'gravityview' === get_post_type($post); |
|
405 | + $is_GV_post_type = 'gravityview' === get_post_type( $post ); |
|
406 | 406 | |
407 | 407 | // Calculate requested Views |
408 | - $post_content = !empty($post->post_content) ? $post->post_content : null; |
|
408 | + $post_content = ! empty( $post->post_content ) ? $post->post_content : null; |
|
409 | 409 | |
410 | - if (!$is_GV_post_type && function_exists('parse_blocks') && preg_match_all('/"ref":\d+/', $post_content)) { |
|
411 | - $blocks = parse_blocks($post_content); |
|
410 | + if ( ! $is_GV_post_type && function_exists( 'parse_blocks' ) && preg_match_all( '/"ref":\d+/', $post_content ) ) { |
|
411 | + $blocks = parse_blocks( $post_content ); |
|
412 | 412 | |
413 | - foreach ($blocks as $block) { |
|
414 | - if (empty($block['attrs']['ref'])) { |
|
413 | + foreach ( $blocks as $block ) { |
|
414 | + if ( empty( $block[ 'attrs' ][ 'ref' ] ) ) { |
|
415 | 415 | continue; |
416 | 416 | } |
417 | 417 | |
418 | - $block_post = get_post($block['attrs']['ref']); |
|
418 | + $block_post = get_post( $block[ 'attrs' ][ 'ref' ] ); |
|
419 | 419 | |
420 | - if ($block_post) { |
|
420 | + if ( $block_post ) { |
|
421 | 421 | $post_content .= $block_post->post_content; |
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | - $this->setGvOutputData(GravityView_View_Data::getInstance($post_content)); |
|
425 | + $this->setGvOutputData( GravityView_View_Data::getInstance( $post_content ) ); |
|
426 | 426 | } else { |
427 | - $this->setGvOutputData(GravityView_View_Data::getInstance($post)); |
|
427 | + $this->setGvOutputData( GravityView_View_Data::getInstance( $post ) ); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | // !important: we need to run this before getting single entry (to kick the advanced filter) |
431 | 431 | $this->set_context_view_id(); |
432 | 432 | |
433 | - $this->setIsGravityviewPostType($is_GV_post_type); |
|
433 | + $this->setIsGravityviewPostType( $is_GV_post_type ); |
|
434 | 434 | |
435 | - $post_id = $this->getPostId() ? $this->getPostId() : (isset($post) ? $post->ID : null); |
|
436 | - $this->setPostId($post_id); |
|
437 | - $post_has_shortcode = $post_content ? gravityview_has_shortcode_r($post_content, 'gravityview') : false; |
|
438 | - $this->setPostHasShortcode($this->isGravityviewPostType() ? null : !empty($post_has_shortcode)); |
|
435 | + $post_id = $this->getPostId() ? $this->getPostId() : ( isset( $post ) ? $post->ID : null ); |
|
436 | + $this->setPostId( $post_id ); |
|
437 | + $post_has_shortcode = $post_content ? gravityview_has_shortcode_r( $post_content, 'gravityview' ) : false; |
|
438 | + $this->setPostHasShortcode( $this->isGravityviewPostType() ? null : ! empty( $post_has_shortcode ) ); |
|
439 | 439 | |
440 | 440 | // check if the View is showing search results (only for multiple entries View) |
441 | - $this->setIsSearch($this->is_searching()); |
|
441 | + $this->setIsSearch( $this->is_searching() ); |
|
442 | 442 | |
443 | - unset($entry, $post_id, $post_has_shortcode); |
|
443 | + unset( $entry, $post_id, $post_has_shortcode ); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | /** |
@@ -449,8 +449,8 @@ discard block |
||
449 | 449 | public function set_entry_data() |
450 | 450 | { |
451 | 451 | $entry_id = self::is_single_entry(); |
452 | - $this->setSingleEntry($entry_id); |
|
453 | - $this->setEntry($entry_id); |
|
452 | + $this->setSingleEntry( $entry_id ); |
|
453 | + $this->setEntry( $entry_id ); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -464,39 +464,39 @@ discard block |
||
464 | 464 | { |
465 | 465 | |
466 | 466 | // It's a single entry, not search |
467 | - if ($this->getSingleEntry()) { |
|
467 | + if ( $this->getSingleEntry() ) { |
|
468 | 468 | return false; |
469 | 469 | } |
470 | 470 | |
471 | 471 | $search_method = GravityView_Widget_Search::getInstance()->get_search_method(); |
472 | 472 | |
473 | - if ('post' === $search_method) { |
|
473 | + if ( 'post' === $search_method ) { |
|
474 | 474 | $get = $_POST; |
475 | 475 | } else { |
476 | 476 | $get = $_GET; |
477 | 477 | } |
478 | 478 | |
479 | 479 | // No $_GET parameters |
480 | - if (empty($get) || !is_array($get)) { |
|
480 | + if ( empty( $get ) || ! is_array( $get ) ) { |
|
481 | 481 | return false; |
482 | 482 | } |
483 | 483 | |
484 | 484 | // Remove empty values |
485 | - $get = array_filter($get); |
|
485 | + $get = array_filter( $get ); |
|
486 | 486 | |
487 | 487 | // If the $_GET parameters are empty, it's no search. |
488 | - if (empty($get)) { |
|
488 | + if ( empty( $get ) ) { |
|
489 | 489 | return false; |
490 | 490 | } |
491 | 491 | |
492 | - $search_keys = array_keys($get); |
|
492 | + $search_keys = array_keys( $get ); |
|
493 | 493 | |
494 | - $search_match = implode('|', self::$search_parameters); |
|
494 | + $search_match = implode( '|', self::$search_parameters ); |
|
495 | 495 | |
496 | - foreach ($search_keys as $search_key) { |
|
496 | + foreach ( $search_keys as $search_key ) { |
|
497 | 497 | |
498 | 498 | // Analyze the search key $_GET parameter and see if it matches known GV args |
499 | - if (preg_match('/('.$search_match.')/i', $search_key)) { |
|
499 | + if ( preg_match( '/(' . $search_match . ')/i', $search_key ) ) { |
|
500 | 500 | return true; |
501 | 501 | } |
502 | 502 | } |
@@ -512,19 +512,19 @@ discard block |
||
512 | 512 | * |
513 | 513 | * @return string (modified) title |
514 | 514 | */ |
515 | - public function single_entry_title($passed_title, $passed_post_id = null) |
|
515 | + public function single_entry_title( $passed_title, $passed_post_id = null ) |
|
516 | 516 | { |
517 | 517 | global $post; |
518 | 518 | |
519 | 519 | // Since this is a public method, it can be called outside of the plugin. Don't assume things have been loaded properly. |
520 | - if (!class_exists('\GV\Entry')) { |
|
520 | + if ( ! class_exists( '\GV\Entry' ) ) { |
|
521 | 521 | return $passed_title; |
522 | 522 | } |
523 | 523 | |
524 | 524 | $gventry = gravityview()->request->is_entry(); |
525 | 525 | |
526 | 526 | // If this is the directory view, return. |
527 | - if (!$gventry) { |
|
527 | + if ( ! $gventry ) { |
|
528 | 528 | return $passed_title; |
529 | 529 | } |
530 | 530 | |
@@ -536,52 +536,52 @@ discard block |
||
536 | 536 | * @param bool $in_the_loop Whether to apply the filter to the menu title and the meta tag <title> - outside the loop |
537 | 537 | * @param array $entry Current entry |
538 | 538 | */ |
539 | - $apply_outside_loop = apply_filters('gravityview/single/title/out_loop', in_the_loop(), $entry); |
|
539 | + $apply_outside_loop = apply_filters( 'gravityview/single/title/out_loop', in_the_loop(), $entry ); |
|
540 | 540 | |
541 | - if (!$apply_outside_loop) { |
|
541 | + if ( ! $apply_outside_loop ) { |
|
542 | 542 | return $passed_title; |
543 | 543 | } |
544 | 544 | |
545 | 545 | // WooCommerce doesn't $post_id |
546 | - if (empty($passed_post_id)) { |
|
546 | + if ( empty( $passed_post_id ) ) { |
|
547 | 547 | return $passed_title; |
548 | 548 | } |
549 | 549 | |
550 | 550 | // Don't modify the title for anything other than the current view/post. |
551 | 551 | // This is true for embedded shortcodes and Views. |
552 | - if (is_object($post) && (int) $post->ID !== (int) $passed_post_id) { |
|
552 | + if ( is_object( $post ) && (int)$post->ID !== (int)$passed_post_id ) { |
|
553 | 553 | return $passed_title; |
554 | 554 | } |
555 | 555 | |
556 | 556 | $view = gravityview()->request->is_view(); |
557 | 557 | |
558 | - if ($view) { |
|
559 | - return $this->_get_single_entry_title($view, $entry, $passed_title); |
|
558 | + if ( $view ) { |
|
559 | + return $this->_get_single_entry_title( $view, $entry, $passed_title ); |
|
560 | 560 | } |
561 | 561 | |
562 | - $_gvid = \GV\Utils::_GET('gvid', null); |
|
562 | + $_gvid = \GV\Utils::_GET( 'gvid', null ); |
|
563 | 563 | |
564 | 564 | // $_GET['gvid'] is set; we know what View to render |
565 | - if ($_gvid) { |
|
566 | - $view = \GV\View::by_id($_gvid); |
|
565 | + if ( $_gvid ) { |
|
566 | + $view = \GV\View::by_id( $_gvid ); |
|
567 | 567 | |
568 | - return $this->_get_single_entry_title($view, $entry, $passed_title); |
|
568 | + return $this->_get_single_entry_title( $view, $entry, $passed_title ); |
|
569 | 569 | } |
570 | 570 | |
571 | 571 | global $post; |
572 | 572 | |
573 | - if (!$post) { |
|
573 | + if ( ! $post ) { |
|
574 | 574 | return $passed_title; |
575 | 575 | } |
576 | 576 | |
577 | - $view_collection = \GV\View_Collection::from_post($post); |
|
577 | + $view_collection = \GV\View_Collection::from_post( $post ); |
|
578 | 578 | |
579 | 579 | // We have multiple Views, but no gvid...this isn't valid security |
580 | - if (1 < $view_collection->count()) { |
|
580 | + if ( 1 < $view_collection->count() ) { |
|
581 | 581 | return $passed_title; |
582 | 582 | } |
583 | 583 | |
584 | - return $this->_get_single_entry_title($view_collection->first(), $entry, $passed_title); |
|
584 | + return $this->_get_single_entry_title( $view_collection->first(), $entry, $passed_title ); |
|
585 | 585 | } |
586 | 586 | |
587 | 587 | /** |
@@ -595,9 +595,9 @@ discard block |
||
595 | 595 | * |
596 | 596 | * @return string |
597 | 597 | */ |
598 | - private function _get_single_entry_title($view, $entry = [], $passed_title = '') |
|
598 | + private function _get_single_entry_title( $view, $entry = [ ], $passed_title = '' ) |
|
599 | 599 | { |
600 | - if (!$view) { |
|
600 | + if ( ! $view ) { |
|
601 | 601 | return $passed_title; |
602 | 602 | } |
603 | 603 | |
@@ -612,24 +612,24 @@ discard block |
||
612 | 612 | * @param array $entry Gravity Forms entry array |
613 | 613 | * @param \GV\View $view The View |
614 | 614 | */ |
615 | - $check_entry_display = apply_filters('gravityview/single/title/check_entry_display', true, $entry, $view); |
|
615 | + $check_entry_display = apply_filters( 'gravityview/single/title/check_entry_display', true, $entry, $view ); |
|
616 | 616 | |
617 | - if ($check_entry_display) { |
|
618 | - $check_display = GVCommon::check_entry_display($entry, $view); |
|
617 | + if ( $check_entry_display ) { |
|
618 | + $check_display = GVCommon::check_entry_display( $entry, $view ); |
|
619 | 619 | |
620 | - if (is_wp_error($check_display)) { |
|
620 | + if ( is_wp_error( $check_display ) ) { |
|
621 | 621 | return $passed_title; |
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
625 | - $title = $view->settings->get('single_title', $passed_title); |
|
625 | + $title = $view->settings->get( 'single_title', $passed_title ); |
|
626 | 626 | |
627 | - $form = GVCommon::get_form($entry['form_id']); |
|
627 | + $form = GVCommon::get_form( $entry[ 'form_id' ] ); |
|
628 | 628 | |
629 | 629 | // We are allowing HTML in the fields, so no escaping the output |
630 | - $title = GravityView_API::replace_variables($title, $form, $entry); |
|
630 | + $title = GravityView_API::replace_variables( $title, $form, $entry ); |
|
631 | 631 | |
632 | - $title = do_shortcode($title); |
|
632 | + $title = do_shortcode( $title ); |
|
633 | 633 | |
634 | 634 | return $title; |
635 | 635 | } |
@@ -645,11 +645,11 @@ discard block |
||
645 | 645 | * |
646 | 646 | * @return string Add the View output into View CPT content |
647 | 647 | */ |
648 | - public function insert_view_in_content($content) |
|
648 | + public function insert_view_in_content( $content ) |
|
649 | 649 | { |
650 | - gravityview()->log->notice('\GravityView_frontend::insert_view_in_content is deprecated. Use \GV\View::content()'); |
|
650 | + gravityview()->log->notice( '\GravityView_frontend::insert_view_in_content is deprecated. Use \GV\View::content()' ); |
|
651 | 651 | |
652 | - return \GV\View::content($content); |
|
652 | + return \GV\View::content( $content ); |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | /** |
@@ -660,9 +660,9 @@ discard block |
||
660 | 660 | * |
661 | 661 | * @return bool |
662 | 662 | */ |
663 | - public function comments_open($open, $post_id) |
|
663 | + public function comments_open( $open, $post_id ) |
|
664 | 664 | { |
665 | - if ($this->isGravityviewPostType()) { |
|
665 | + if ( $this->isGravityviewPostType() ) { |
|
666 | 666 | $open = false; |
667 | 667 | } |
668 | 668 | |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | * @param bool $open Open or closed status |
675 | 675 | * @param int $post_id Post ID to set comment status for |
676 | 676 | */ |
677 | - $open = apply_filters('gravityview/comments_open', $open, $post_id); |
|
677 | + $open = apply_filters( 'gravityview/comments_open', $open, $post_id ); |
|
678 | 678 | |
679 | 679 | return $open; |
680 | 680 | } |
@@ -688,42 +688,42 @@ discard block |
||
688 | 688 | * |
689 | 689 | * @return void |
690 | 690 | */ |
691 | - public function context_not_configured_warning($view_id = 0) |
|
691 | + public function context_not_configured_warning( $view_id = 0 ) |
|
692 | 692 | { |
693 | - if (!class_exists('GravityView_View')) { |
|
693 | + if ( ! class_exists( 'GravityView_View' ) ) { |
|
694 | 694 | return; |
695 | 695 | } |
696 | 696 | |
697 | 697 | $fields = GravityView_View::getInstance()->getContextFields(); |
698 | 698 | |
699 | - if (!empty($fields)) { |
|
699 | + if ( ! empty( $fields ) ) { |
|
700 | 700 | return; |
701 | 701 | } |
702 | 702 | |
703 | 703 | $context = GravityView_View::getInstance()->getContext(); |
704 | 704 | |
705 | - switch ($context) { |
|
705 | + switch ( $context ) { |
|
706 | 706 | case 'directory': |
707 | - $tab = __('Multiple Entries', 'gravityview'); |
|
707 | + $tab = __( 'Multiple Entries', 'gravityview' ); |
|
708 | 708 | break; |
709 | 709 | case 'edit': |
710 | - $tab = __('Edit Entry', 'gravityview'); |
|
710 | + $tab = __( 'Edit Entry', 'gravityview' ); |
|
711 | 711 | break; |
712 | 712 | case 'single': |
713 | 713 | default: |
714 | - $tab = __('Single Entry', 'gravityview'); |
|
714 | + $tab = __( 'Single Entry', 'gravityview' ); |
|
715 | 715 | break; |
716 | 716 | } |
717 | 717 | |
718 | - $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); |
|
719 | - $edit_link = admin_url(sprintf('post.php?post=%d&action=edit#%s-view', $view_id, $context)); |
|
720 | - $action_text = sprintf(esc_html__('Add fields to %s', 'gravityview'), $tab); |
|
721 | - $message = esc_html__('You can only see this message because you are able to edit this View.', 'gravityview'); |
|
718 | + $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 ); |
|
719 | + $edit_link = admin_url( sprintf( 'post.php?post=%d&action=edit#%s-view', $view_id, $context ) ); |
|
720 | + $action_text = sprintf( esc_html__( 'Add fields to %s', 'gravityview' ), $tab ); |
|
721 | + $message = esc_html__( 'You can only see this message because you are able to edit this View.', 'gravityview' ); |
|
722 | 722 | |
723 | - $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))); |
|
724 | - $output = sprintf('<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>', $title, esc_url($edit_link), $action_text, $message); |
|
723 | + $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 ) ) ); |
|
724 | + $output = sprintf( '<h3>%s <strong><a href="%s">%s</a></strong></h3><p>%s</p>', $title, esc_url( $edit_link ), $action_text, $message ); |
|
725 | 725 | |
726 | - echo GVCommon::generate_notice($output.$image, 'gv-error error', 'edit_gravityview', $view_id); |
|
726 | + echo GVCommon::generate_notice( $output . $image, 'gv-error error', 'edit_gravityview', $view_id ); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | /** |
@@ -749,31 +749,31 @@ discard block |
||
749 | 749 | * |
750 | 750 | * @return string|null HTML output of a View, NULL if View isn't found |
751 | 751 | */ |
752 | - public function render_view($passed_args) |
|
752 | + public function render_view( $passed_args ) |
|
753 | 753 | { |
754 | - gravityview()->log->notice('\GravityView_frontend::render_view is deprecated. Use \GV\View_Renderer etc.'); |
|
754 | + gravityview()->log->notice( '\GravityView_frontend::render_view is deprecated. Use \GV\View_Renderer etc.' ); |
|
755 | 755 | |
756 | 756 | /** |
757 | 757 | * We can use a shortcode here, since it's pretty much the same. |
758 | 758 | * |
759 | 759 | * But we do need to check embed permissions, since shortcodes don't do this. |
760 | 760 | */ |
761 | - if (!$view = gravityview()->views->get($passed_args)) { |
|
761 | + if ( ! $view = gravityview()->views->get( $passed_args ) ) { |
|
762 | 762 | return null; |
763 | 763 | } |
764 | 764 | |
765 | - $view->settings->update($passed_args); |
|
765 | + $view->settings->update( $passed_args ); |
|
766 | 766 | |
767 | - $direct_access = apply_filters('gravityview_direct_access', true, $view->ID); |
|
768 | - $embed_only = $view->settings->get('embed_only'); |
|
767 | + $direct_access = apply_filters( 'gravityview_direct_access', true, $view->ID ); |
|
768 | + $embed_only = $view->settings->get( 'embed_only' ); |
|
769 | 769 | |
770 | - if (!$direct_access || ($embed_only && !GVCommon::has_cap('read_private_gravityviews'))) { |
|
771 | - return __('You are not allowed to view this content.', 'gravityview'); |
|
770 | + if ( ! $direct_access || ( $embed_only && ! GVCommon::has_cap( 'read_private_gravityviews' ) ) ) { |
|
771 | + return __( 'You are not allowed to view this content.', 'gravityview' ); |
|
772 | 772 | } |
773 | 773 | |
774 | 774 | $shortcode = new \GV\Shortcodes\gravityview(); |
775 | 775 | |
776 | - return $shortcode->callback($passed_args); |
|
776 | + return $shortcode->callback( $passed_args ); |
|
777 | 777 | } |
778 | 778 | |
779 | 779 | /** |
@@ -792,22 +792,22 @@ discard block |
||
792 | 792 | * |
793 | 793 | * @return array Modified `$search_criteria` array |
794 | 794 | */ |
795 | - public static function process_search_dates($args, $search_criteria = []) |
|
795 | + public static function process_search_dates( $args, $search_criteria = [ ] ) |
|
796 | 796 | { |
797 | 797 | $return_search_criteria = $search_criteria; |
798 | 798 | |
799 | - foreach (['start_date', 'end_date'] as $key) { |
|
799 | + foreach ( [ 'start_date', 'end_date' ] as $key ) { |
|
800 | 800 | |
801 | 801 | // Is the start date or end date set in the view or shortcode? |
802 | 802 | // If so, we want to make sure that the search doesn't go outside the bounds defined. |
803 | - if (!empty($args[$key])) { |
|
803 | + if ( ! empty( $args[ $key ] ) ) { |
|
804 | 804 | |
805 | 805 | // Get a timestamp and see if it's a valid date format |
806 | - $date = strtotime($args[$key], GFCommon::get_local_timestamp()); |
|
806 | + $date = strtotime( $args[ $key ], GFCommon::get_local_timestamp() ); |
|
807 | 807 | |
808 | 808 | // The date was invalid |
809 | - if (empty($date)) { |
|
810 | - gravityview()->log->error(' Invalid {key} date format: {format}', ['key' => $key, 'format' => $args[$key]]); |
|
809 | + if ( empty( $date ) ) { |
|
810 | + gravityview()->log->error( ' Invalid {key} date format: {format}', [ 'key' => $key, 'format' => $args[ $key ] ] ); |
|
811 | 811 | continue; |
812 | 812 | } |
813 | 813 | |
@@ -815,11 +815,11 @@ discard block |
||
815 | 815 | $datetime_format = 'Y-m-d H:i:s'; |
816 | 816 | $search_is_outside_view_bounds = false; |
817 | 817 | |
818 | - if (!empty($search_criteria[$key])) { |
|
819 | - $search_date = strtotime($search_criteria[$key], GFCommon::get_local_timestamp()); |
|
818 | + if ( ! empty( $search_criteria[ $key ] ) ) { |
|
819 | + $search_date = strtotime( $search_criteria[ $key ], GFCommon::get_local_timestamp() ); |
|
820 | 820 | |
821 | 821 | // The search is for entries before the start date defined by the settings |
822 | - switch ($key) { |
|
822 | + switch ( $key ) { |
|
823 | 823 | case 'end_date': |
824 | 824 | /** |
825 | 825 | * If the end date is formatted as 'Y-m-d', it should be formatted without hours and seconds |
@@ -829,28 +829,28 @@ discard block |
||
829 | 829 | * |
830 | 830 | * @see GFFormsModel::get_date_range_where |
831 | 831 | */ |
832 | - $datetime_format = gravityview_is_valid_datetime($args[$key]) ? 'Y-m-d' : $datetime_format; |
|
833 | - $search_is_outside_view_bounds = ($search_date > $date); |
|
832 | + $datetime_format = gravityview_is_valid_datetime( $args[ $key ] ) ? 'Y-m-d' : $datetime_format; |
|
833 | + $search_is_outside_view_bounds = ( $search_date > $date ); |
|
834 | 834 | break; |
835 | 835 | case 'start_date': |
836 | - $search_is_outside_view_bounds = ($search_date < $date); |
|
836 | + $search_is_outside_view_bounds = ( $search_date < $date ); |
|
837 | 837 | break; |
838 | 838 | } |
839 | 839 | } |
840 | 840 | |
841 | 841 | // If there is no search being performed, or if there is a search being performed that's outside the bounds |
842 | - if (empty($search_criteria[$key]) || $search_is_outside_view_bounds) { |
|
842 | + if ( empty( $search_criteria[ $key ] ) || $search_is_outside_view_bounds ) { |
|
843 | 843 | |
844 | 844 | // Then we override the search and re-set the start date |
845 | - $return_search_criteria[$key] = date_i18n($datetime_format, $date, true); |
|
845 | + $return_search_criteria[ $key ] = date_i18n( $datetime_format, $date, true ); |
|
846 | 846 | } |
847 | 847 | } |
848 | 848 | } |
849 | 849 | |
850 | - if (isset($return_search_criteria['start_date']) && isset($return_search_criteria['end_date'])) { |
|
850 | + if ( isset( $return_search_criteria[ 'start_date' ] ) && isset( $return_search_criteria[ 'end_date' ] ) ) { |
|
851 | 851 | // The start date is AFTER the end date. This will result in no results, but let's not force the issue. |
852 | - if (strtotime($return_search_criteria['start_date']) > strtotime($return_search_criteria['end_date'])) { |
|
853 | - gravityview()->log->error('Invalid search: the start date is after the end date.', ['data' => $return_search_criteria]); |
|
852 | + if ( strtotime( $return_search_criteria[ 'start_date' ] ) > strtotime( $return_search_criteria[ 'end_date' ] ) ) { |
|
853 | + gravityview()->log->error( 'Invalid search: the start date is after the end date.', [ 'data' => $return_search_criteria ] ); |
|
854 | 854 | } |
855 | 855 | } |
856 | 856 | |
@@ -865,25 +865,25 @@ discard block |
||
865 | 865 | * |
866 | 866 | * @return array Modified `$search_criteria` array |
867 | 867 | */ |
868 | - public static function process_search_only_approved($args, $search_criteria) |
|
868 | + public static function process_search_only_approved( $args, $search_criteria ) |
|
869 | 869 | { |
870 | 870 | |
871 | 871 | /** @since 1.19 */ |
872 | - if (!empty($args['admin_show_all_statuses']) && GVCommon::has_cap('gravityview_moderate_entries')) { |
|
873 | - gravityview()->log->debug('User can moderate entries; showing all approval statuses'); |
|
872 | + if ( ! empty( $args[ 'admin_show_all_statuses' ] ) && GVCommon::has_cap( 'gravityview_moderate_entries' ) ) { |
|
873 | + gravityview()->log->debug( 'User can moderate entries; showing all approval statuses' ); |
|
874 | 874 | |
875 | 875 | return $search_criteria; |
876 | 876 | } |
877 | 877 | |
878 | - if (!empty($args['show_only_approved'])) { |
|
879 | - $search_criteria['field_filters'][] = [ |
|
878 | + if ( ! empty( $args[ 'show_only_approved' ] ) ) { |
|
879 | + $search_criteria[ 'field_filters' ][ ] = [ |
|
880 | 880 | 'key' => GravityView_Entry_Approval::meta_key, |
881 | 881 | 'value' => GravityView_Entry_Approval_Status::APPROVED, |
882 | 882 | ]; |
883 | 883 | |
884 | - $search_criteria['field_filters']['mode'] = 'all'; // force all the criterias to be met |
|
884 | + $search_criteria[ 'field_filters' ][ 'mode' ] = 'all'; // force all the criterias to be met |
|
885 | 885 | |
886 | - gravityview()->log->debug('[process_search_only_approved] Search Criteria if show only approved: ', ['data' => $search_criteria]); |
|
886 | + gravityview()->log->debug( '[process_search_only_approved] Search Criteria if show only approved: ', [ 'data' => $search_criteria ] ); |
|
887 | 887 | } |
888 | 888 | |
889 | 889 | return $search_criteria; |
@@ -905,23 +905,23 @@ discard block |
||
905 | 905 | * |
906 | 906 | * @return bool |
907 | 907 | */ |
908 | - public static function is_entry_approved($entry, $args = []) |
|
908 | + public static function is_entry_approved( $entry, $args = [ ] ) |
|
909 | 909 | { |
910 | - if (empty($entry['id']) || (array_key_exists('show_only_approved', $args) && !$args['show_only_approved'])) { |
|
910 | + if ( empty( $entry[ 'id' ] ) || ( array_key_exists( 'show_only_approved', $args ) && ! $args[ 'show_only_approved' ] ) ) { |
|
911 | 911 | // is implicitly approved if entry is null or View settings doesn't require to check for approval |
912 | 912 | return true; |
913 | 913 | } |
914 | 914 | |
915 | 915 | /** @since 1.19 */ |
916 | - if (!empty($args['admin_show_all_statuses']) && GVCommon::has_cap('gravityview_moderate_entries')) { |
|
917 | - gravityview()->log->debug('User can moderate entries, so entry is approved for viewing'); |
|
916 | + if ( ! empty( $args[ 'admin_show_all_statuses' ] ) && GVCommon::has_cap( 'gravityview_moderate_entries' ) ) { |
|
917 | + gravityview()->log->debug( 'User can moderate entries, so entry is approved for viewing' ); |
|
918 | 918 | |
919 | 919 | return true; |
920 | 920 | } |
921 | 921 | |
922 | - $is_approved = gform_get_meta($entry['id'], GravityView_Entry_Approval::meta_key); |
|
922 | + $is_approved = gform_get_meta( $entry[ 'id' ], GravityView_Entry_Approval::meta_key ); |
|
923 | 923 | |
924 | - return GravityView_Entry_Approval_Status::is_approved($is_approved); |
|
924 | + return GravityView_Entry_Approval_Status::is_approved( $is_approved ); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
@@ -939,13 +939,13 @@ discard block |
||
939 | 939 | * |
940 | 940 | * @return array Array of search parameters, formatted in Gravity Forms mode, using `status` key set to "active" by default, `field_filters` array with `key`, `value` and `operator` keys. |
941 | 941 | */ |
942 | - public static function get_search_criteria($args, $form_id) |
|
942 | + public static function get_search_criteria( $args, $form_id ) |
|
943 | 943 | { |
944 | 944 | /** |
945 | 945 | * Compatibility with filters hooking in `gravityview_search_criteria` instead of `gravityview_fe_search_criteria`. |
946 | 946 | */ |
947 | - $criteria = apply_filters('gravityview_search_criteria', [], [$form_id], \GV\Utils::get($args, 'id')); |
|
948 | - $search_criteria = isset($criteria['search_criteria']) ? $criteria['search_criteria'] : ['field_filters' => []]; |
|
947 | + $criteria = apply_filters( 'gravityview_search_criteria', [ ], [ $form_id ], \GV\Utils::get( $args, 'id' ) ); |
|
948 | + $search_criteria = isset( $criteria[ 'search_criteria' ] ) ? $criteria[ 'search_criteria' ] : [ 'field_filters' => [ ] ]; |
|
949 | 949 | |
950 | 950 | /** |
951 | 951 | * @filter `gravityview_fe_search_criteria` Modify the search criteria |
@@ -956,52 +956,52 @@ discard block |
||
956 | 956 | * @param int $form_id ID of the Gravity Forms form that is being searched |
957 | 957 | * @param array $args The View settings. |
958 | 958 | */ |
959 | - $search_criteria = apply_filters('gravityview_fe_search_criteria', $search_criteria, $form_id, $args); |
|
959 | + $search_criteria = apply_filters( 'gravityview_fe_search_criteria', $search_criteria, $form_id, $args ); |
|
960 | 960 | |
961 | - if (!is_array($search_criteria)) { |
|
962 | - return []; |
|
961 | + if ( ! is_array( $search_criteria ) ) { |
|
962 | + return [ ]; |
|
963 | 963 | } |
964 | 964 | |
965 | 965 | $original_search_criteria = $search_criteria; |
966 | 966 | |
967 | - gravityview()->log->debug('[get_search_criteria] Search Criteria after hook gravityview_fe_search_criteria: ', ['data' =>$search_criteria]); |
|
967 | + gravityview()->log->debug( '[get_search_criteria] Search Criteria after hook gravityview_fe_search_criteria: ', [ 'data' =>$search_criteria ] ); |
|
968 | 968 | |
969 | 969 | // implicity search |
970 | - if (!empty($args['search_value'])) { |
|
970 | + if ( ! empty( $args[ 'search_value' ] ) ) { |
|
971 | 971 | |
972 | 972 | // Search operator options. Options: `is` or `contains` |
973 | - $operator = !empty($args['search_operator']) && in_array($args['search_operator'], ['is', 'isnot', '>', '<', 'contains']) ? $args['search_operator'] : 'contains'; |
|
973 | + $operator = ! empty( $args[ 'search_operator' ] ) && in_array( $args[ 'search_operator' ], [ 'is', 'isnot', '>', '<', 'contains' ] ) ? $args[ 'search_operator' ] : 'contains'; |
|
974 | 974 | |
975 | - $search_criteria['field_filters'][] = [ |
|
976 | - 'key' => \GV\Utils::_GET('search_field', \GV\Utils::get($args, 'search_field')), // The field ID to search |
|
977 | - 'value' => _wp_specialchars($args['search_value']), // The value to search. Encode ampersands but not quotes. |
|
975 | + $search_criteria[ 'field_filters' ][ ] = [ |
|
976 | + 'key' => \GV\Utils::_GET( 'search_field', \GV\Utils::get( $args, 'search_field' ) ), // The field ID to search |
|
977 | + 'value' => _wp_specialchars( $args[ 'search_value' ] ), // The value to search. Encode ampersands but not quotes. |
|
978 | 978 | 'operator' => $operator, |
979 | 979 | ]; |
980 | 980 | |
981 | 981 | // Lock search mode to "all" with implicit presearch filter. |
982 | - $search_criteria['field_filters']['mode'] = 'all'; |
|
982 | + $search_criteria[ 'field_filters' ][ 'mode' ] = 'all'; |
|
983 | 983 | } |
984 | 984 | |
985 | - if ($search_criteria !== $original_search_criteria) { |
|
986 | - gravityview()->log->debug('[get_search_criteria] Search Criteria after implicity search: ', ['data' => $search_criteria]); |
|
985 | + if ( $search_criteria !== $original_search_criteria ) { |
|
986 | + gravityview()->log->debug( '[get_search_criteria] Search Criteria after implicity search: ', [ 'data' => $search_criteria ] ); |
|
987 | 987 | } |
988 | 988 | |
989 | 989 | // Handle setting date range |
990 | - $search_criteria = self::process_search_dates($args, $search_criteria); |
|
990 | + $search_criteria = self::process_search_dates( $args, $search_criteria ); |
|
991 | 991 | |
992 | - if ($search_criteria !== $original_search_criteria) { |
|
993 | - gravityview()->log->debug('[get_search_criteria] Search Criteria after date params: ', ['data' => $search_criteria]); |
|
992 | + if ( $search_criteria !== $original_search_criteria ) { |
|
993 | + gravityview()->log->debug( '[get_search_criteria] Search Criteria after date params: ', [ 'data' => $search_criteria ] ); |
|
994 | 994 | } |
995 | 995 | |
996 | 996 | // remove not approved entries |
997 | - $search_criteria = self::process_search_only_approved($args, $search_criteria); |
|
997 | + $search_criteria = self::process_search_only_approved( $args, $search_criteria ); |
|
998 | 998 | |
999 | 999 | /** |
1000 | 1000 | * @filter `gravityview_status` Modify entry status requirements to be included in search results. |
1001 | 1001 | * |
1002 | 1002 | * @param string $status Default: `active`. Accepts all Gravity Forms entry statuses, including `spam` and `trash` |
1003 | 1003 | */ |
1004 | - $search_criteria['status'] = apply_filters('gravityview_status', 'active', $args); |
|
1004 | + $search_criteria[ 'status' ] = apply_filters( 'gravityview_status', 'active', $args ); |
|
1005 | 1005 | |
1006 | 1006 | return $search_criteria; |
1007 | 1007 | } |
@@ -1034,20 +1034,20 @@ discard block |
||
1034 | 1034 | * |
1035 | 1035 | * @return array Associative array with `count`, `entries`, and `paging` keys. `count` has the total entries count, `entries` is an array with Gravity Forms full entry data, `paging` is an array with `offset` and `page_size` keys |
1036 | 1036 | */ |
1037 | - public static function get_view_entries($args, $form_id) |
|
1037 | + public static function get_view_entries( $args, $form_id ) |
|
1038 | 1038 | { |
1039 | - gravityview()->log->debug('[get_view_entries] init'); |
|
1039 | + gravityview()->log->debug( '[get_view_entries] init' ); |
|
1040 | 1040 | // start filters and sorting |
1041 | 1041 | |
1042 | - $parameters = self::get_view_entries_parameters($args, $form_id); |
|
1042 | + $parameters = self::get_view_entries_parameters( $args, $form_id ); |
|
1043 | 1043 | |
1044 | 1044 | $count = 0; // Must be defined so that gravityview_get_entries can use by reference |
1045 | 1045 | |
1046 | 1046 | // fetch entries |
1047 | - list($entries, $paging, $count) = |
|
1048 | - \GV\Mocks\GravityView_frontend_get_view_entries($args, $form_id, $parameters, $count); |
|
1047 | + list( $entries, $paging, $count ) = |
|
1048 | + \GV\Mocks\GravityView_frontend_get_view_entries( $args, $form_id, $parameters, $count ); |
|
1049 | 1049 | |
1050 | - gravityview()->log->debug('Get Entries. Found: {count} entries', ['count' => $count, 'data' => $entries]); |
|
1050 | + gravityview()->log->debug( 'Get Entries. Found: {count} entries', [ 'count' => $count, 'data' => $entries ] ); |
|
1051 | 1051 | |
1052 | 1052 | /** |
1053 | 1053 | * @filter `gravityview_view_entries` Filter the entries output to the View |
@@ -1058,7 +1058,7 @@ discard block |
||
1058 | 1058 | * |
1059 | 1059 | * @var array |
1060 | 1060 | */ |
1061 | - $entries = apply_filters('gravityview_view_entries', $entries, $args); |
|
1061 | + $entries = apply_filters( 'gravityview_view_entries', $entries, $args ); |
|
1062 | 1062 | |
1063 | 1063 | $return = [ |
1064 | 1064 | 'count' => $count, |
@@ -1074,7 +1074,7 @@ discard block |
||
1074 | 1074 | * |
1075 | 1075 | * @since 1.5.2 |
1076 | 1076 | */ |
1077 | - return apply_filters('gravityview/view/entries', $return, $args); |
|
1077 | + return apply_filters( 'gravityview/view/entries', $return, $args ); |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | /** |
@@ -1093,30 +1093,30 @@ discard block |
||
1093 | 1093 | * |
1094 | 1094 | * @return array With `search_criteria`, `sorting`, `paging`, `cache` keys |
1095 | 1095 | */ |
1096 | - public static function get_view_entries_parameters($args = [], $form_id = 0) |
|
1096 | + public static function get_view_entries_parameters( $args = [ ], $form_id = 0 ) |
|
1097 | 1097 | { |
1098 | - if (!is_array($args) || !is_numeric($form_id)) { |
|
1099 | - gravityview()->log->error('Passed args are not an array or the form ID is not numeric'); |
|
1098 | + if ( ! is_array( $args ) || ! is_numeric( $form_id ) ) { |
|
1099 | + gravityview()->log->error( 'Passed args are not an array or the form ID is not numeric' ); |
|
1100 | 1100 | |
1101 | - return []; |
|
1101 | + return [ ]; |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | - $form_id = intval($form_id); |
|
1104 | + $form_id = intval( $form_id ); |
|
1105 | 1105 | |
1106 | 1106 | /** |
1107 | 1107 | * Process search parameters. |
1108 | 1108 | * |
1109 | 1109 | * @var array |
1110 | 1110 | */ |
1111 | - $search_criteria = self::get_search_criteria($args, $form_id); |
|
1111 | + $search_criteria = self::get_search_criteria( $args, $form_id ); |
|
1112 | 1112 | |
1113 | - $paging = self::get_search_criteria_paging($args); |
|
1113 | + $paging = self::get_search_criteria_paging( $args ); |
|
1114 | 1114 | |
1115 | 1115 | $parameters = [ |
1116 | 1116 | 'search_criteria' => $search_criteria, |
1117 | - 'sorting' => self::updateViewSorting($args, $form_id), |
|
1117 | + 'sorting' => self::updateViewSorting( $args, $form_id ), |
|
1118 | 1118 | 'paging' => $paging, |
1119 | - 'cache' => isset($args['cache']) ? $args['cache'] : true, |
|
1119 | + 'cache' => isset( $args[ 'cache' ] ) ? $args[ 'cache' ] : true, |
|
1120 | 1120 | ]; |
1121 | 1121 | |
1122 | 1122 | /** |
@@ -1137,7 +1137,7 @@ discard block |
||
1137 | 1137 | * |
1138 | 1138 | * @param int $form_id ID of Gravity Forms form |
1139 | 1139 | */ |
1140 | - $parameters = apply_filters('gravityview_get_entries', $parameters, $args, $form_id); |
|
1140 | + $parameters = apply_filters( 'gravityview_get_entries', $parameters, $args, $form_id ); |
|
1141 | 1141 | |
1142 | 1142 | /** |
1143 | 1143 | * @filter `gravityview_get_entries_{View ID}` Filter get entries criteria |
@@ -1145,9 +1145,9 @@ discard block |
||
1145 | 1145 | * @param array $parameters Array with `search_criteria`, `sorting` and `paging` keys. |
1146 | 1146 | * @param array $args View configuration args. |
1147 | 1147 | */ |
1148 | - $parameters = apply_filters('gravityview_get_entries_'.\GV\Utils::get($args, 'id'), $parameters, $args, $form_id); |
|
1148 | + $parameters = apply_filters( 'gravityview_get_entries_' . \GV\Utils::get( $args, 'id' ), $parameters, $args, $form_id ); |
|
1149 | 1149 | |
1150 | - gravityview()->log->debug('$parameters passed to gravityview_get_entries(): ', ['data' => $parameters]); |
|
1150 | + gravityview()->log->debug( '$parameters passed to gravityview_get_entries(): ', [ 'data' => $parameters ] ); |
|
1151 | 1151 | |
1152 | 1152 | return $parameters; |
1153 | 1153 | } |
@@ -1160,7 +1160,7 @@ discard block |
||
1160 | 1160 | * @param $args |
1161 | 1161 | * @param int $form_id |
1162 | 1162 | */ |
1163 | - public static function get_search_criteria_paging($args) |
|
1163 | + public static function get_search_criteria_paging( $args ) |
|
1164 | 1164 | { |
1165 | 1165 | |
1166 | 1166 | /** |
@@ -1170,20 +1170,20 @@ discard block |
||
1170 | 1170 | * |
1171 | 1171 | * @param int $default_page_size Default: 25 |
1172 | 1172 | */ |
1173 | - $default_page_size = apply_filters('gravityview_default_page_size', 25); |
|
1173 | + $default_page_size = apply_filters( 'gravityview_default_page_size', 25 ); |
|
1174 | 1174 | |
1175 | 1175 | // Paging & offset |
1176 | - $page_size = !empty($args['page_size']) ? intval($args['page_size']) : $default_page_size; |
|
1176 | + $page_size = ! empty( $args[ 'page_size' ] ) ? intval( $args[ 'page_size' ] ) : $default_page_size; |
|
1177 | 1177 | |
1178 | 1178 | if (-1 === $page_size) { |
1179 | 1179 | $page_size = PHP_INT_MAX; |
1180 | 1180 | } |
1181 | 1181 | |
1182 | - $curr_page = empty($_GET['pagenum']) ? 1 : intval($_GET['pagenum']); |
|
1183 | - $offset = ($curr_page - 1) * $page_size; |
|
1182 | + $curr_page = empty( $_GET[ 'pagenum' ] ) ? 1 : intval( $_GET[ 'pagenum' ] ); |
|
1183 | + $offset = ( $curr_page - 1 ) * $page_size; |
|
1184 | 1184 | |
1185 | - if (!empty($args['offset'])) { |
|
1186 | - $offset += intval($args['offset']); |
|
1185 | + if ( ! empty( $args[ 'offset' ] ) ) { |
|
1186 | + $offset += intval( $args[ 'offset' ] ); |
|
1187 | 1187 | } |
1188 | 1188 | |
1189 | 1189 | $paging = [ |
@@ -1191,7 +1191,7 @@ discard block |
||
1191 | 1191 | 'page_size' => $page_size, |
1192 | 1192 | ]; |
1193 | 1193 | |
1194 | - gravityview()->log->debug('Paging: ', ['data' => $paging]); |
|
1194 | + gravityview()->log->debug( 'Paging: ', [ 'data' => $paging ] ); |
|
1195 | 1195 | |
1196 | 1196 | return $paging; |
1197 | 1197 | } |
@@ -1206,63 +1206,63 @@ discard block |
||
1206 | 1206 | * |
1207 | 1207 | * @return array $sorting Array with `key`, `direction` and `is_numeric` keys |
1208 | 1208 | */ |
1209 | - public static function updateViewSorting($args, $form_id) |
|
1209 | + public static function updateViewSorting( $args, $form_id ) |
|
1210 | 1210 | { |
1211 | - $sorting = []; |
|
1211 | + $sorting = [ ]; |
|
1212 | 1212 | |
1213 | - $has_values = isset($_GET['sort']); |
|
1213 | + $has_values = isset( $_GET[ 'sort' ] ); |
|
1214 | 1214 | |
1215 | - if ($has_values && is_array($_GET['sort'])) { |
|
1216 | - $sorts = array_keys($_GET['sort']); |
|
1217 | - $dirs = array_values($_GET['sort']); |
|
1215 | + if ( $has_values && is_array( $_GET[ 'sort' ] ) ) { |
|
1216 | + $sorts = array_keys( $_GET[ 'sort' ] ); |
|
1217 | + $dirs = array_values( $_GET[ 'sort' ] ); |
|
1218 | 1218 | |
1219 | - if ($has_values = array_filter($dirs)) { |
|
1220 | - $sort_field_id = end($sorts); |
|
1221 | - $sort_direction = end($dirs); |
|
1219 | + if ( $has_values = array_filter( $dirs ) ) { |
|
1220 | + $sort_field_id = end( $sorts ); |
|
1221 | + $sort_direction = end( $dirs ); |
|
1222 | 1222 | } |
1223 | 1223 | } |
1224 | 1224 | |
1225 | - if (!isset($sort_field_id)) { |
|
1226 | - $sort_field_id = isset($_GET['sort']) ? $_GET['sort'] : \GV\Utils::get($args, 'sort_field'); |
|
1225 | + if ( ! isset( $sort_field_id ) ) { |
|
1226 | + $sort_field_id = isset( $_GET[ 'sort' ] ) ? $_GET[ 'sort' ] : \GV\Utils::get( $args, 'sort_field' ); |
|
1227 | 1227 | } |
1228 | 1228 | |
1229 | - if (!isset($sort_direction)) { |
|
1230 | - $sort_direction = isset($_GET['dir']) ? $_GET['dir'] : \GV\Utils::get($args, 'sort_direction'); |
|
1229 | + if ( ! isset( $sort_direction ) ) { |
|
1230 | + $sort_direction = isset( $_GET[ 'dir' ] ) ? $_GET[ 'dir' ] : \GV\Utils::get( $args, 'sort_direction' ); |
|
1231 | 1231 | } |
1232 | 1232 | |
1233 | - if (is_array($sort_field_id)) { |
|
1234 | - $sort_field_id = array_pop($sort_field_id); |
|
1233 | + if ( is_array( $sort_field_id ) ) { |
|
1234 | + $sort_field_id = array_pop( $sort_field_id ); |
|
1235 | 1235 | } |
1236 | 1236 | |
1237 | - if (is_array($sort_direction)) { |
|
1238 | - $sort_direction = array_pop($sort_direction); |
|
1237 | + if ( is_array( $sort_direction ) ) { |
|
1238 | + $sort_direction = array_pop( $sort_direction ); |
|
1239 | 1239 | } |
1240 | 1240 | |
1241 | - if (!empty($sort_field_id)) { |
|
1242 | - if (is_array($sort_field_id)) { |
|
1243 | - $sort_direction = array_values($sort_field_id); |
|
1244 | - $sort_field_id = array_keys($sort_field_id); |
|
1241 | + if ( ! empty( $sort_field_id ) ) { |
|
1242 | + if ( is_array( $sort_field_id ) ) { |
|
1243 | + $sort_direction = array_values( $sort_field_id ); |
|
1244 | + $sort_field_id = array_keys( $sort_field_id ); |
|
1245 | 1245 | |
1246 | - $sort_field_id = reset($sort_field_id); |
|
1247 | - $sort_direction = reset($sort_direction); |
|
1246 | + $sort_field_id = reset( $sort_field_id ); |
|
1247 | + $sort_direction = reset( $sort_direction ); |
|
1248 | 1248 | } |
1249 | 1249 | |
1250 | - $sort_field_id = self::_override_sorting_id_by_field_type($sort_field_id, $form_id); |
|
1250 | + $sort_field_id = self::_override_sorting_id_by_field_type( $sort_field_id, $form_id ); |
|
1251 | 1251 | $sorting = [ |
1252 | 1252 | 'key' => $sort_field_id, |
1253 | - 'direction' => strtolower($sort_direction), |
|
1254 | - 'is_numeric' => GVCommon::is_field_numeric($form_id, $sort_field_id), |
|
1253 | + 'direction' => strtolower( $sort_direction ), |
|
1254 | + 'is_numeric' => GVCommon::is_field_numeric( $form_id, $sort_field_id ), |
|
1255 | 1255 | ]; |
1256 | 1256 | |
1257 | - if ('RAND' === $sort_direction) { |
|
1258 | - $form = GFAPI::get_form($form_id); |
|
1257 | + if ( 'RAND' === $sort_direction ) { |
|
1258 | + $form = GFAPI::get_form( $form_id ); |
|
1259 | 1259 | |
1260 | 1260 | // Get the first GF_Field field ID, set as the key for entry randomization |
1261 | - if (!empty($form['fields'])) { |
|
1261 | + if ( ! empty( $form[ 'fields' ] ) ) { |
|
1262 | 1262 | |
1263 | 1263 | /** @var GF_Field $field */ |
1264 | - foreach ($form['fields'] as $field) { |
|
1265 | - if (!is_a($field, 'GF_Field')) { |
|
1264 | + foreach ( $form[ 'fields' ] as $field ) { |
|
1265 | + if ( ! is_a( $field, 'GF_Field' ) ) { |
|
1266 | 1266 | continue; |
1267 | 1267 | } |
1268 | 1268 | |
@@ -1278,13 +1278,13 @@ discard block |
||
1278 | 1278 | } |
1279 | 1279 | } |
1280 | 1280 | |
1281 | - if (!class_exists('GravityView_View')) { |
|
1282 | - gravityview()->plugin->include_legacy_frontend(true); |
|
1281 | + if ( ! class_exists( 'GravityView_View' ) ) { |
|
1282 | + gravityview()->plugin->include_legacy_frontend( true ); |
|
1283 | 1283 | } |
1284 | 1284 | |
1285 | - GravityView_View::getInstance()->setSorting($sorting); |
|
1285 | + GravityView_View::getInstance()->setSorting( $sorting ); |
|
1286 | 1286 | |
1287 | - gravityview()->log->debug('[updateViewSorting] Sort Criteria : ', ['data' => $sorting]); |
|
1287 | + gravityview()->log->debug( '[updateViewSorting] Sort Criteria : ', [ 'data' => $sorting ] ); |
|
1288 | 1288 | |
1289 | 1289 | return $sorting; |
1290 | 1290 | } |
@@ -1306,30 +1306,30 @@ discard block |
||
1306 | 1306 | * |
1307 | 1307 | * @return string|array Possibly modified sorting ID. Array if $sort_field_id is passed as array. |
1308 | 1308 | */ |
1309 | - public static function _override_sorting_id_by_field_type($sort_field_id, $form_id) |
|
1309 | + public static function _override_sorting_id_by_field_type( $sort_field_id, $form_id ) |
|
1310 | 1310 | { |
1311 | - if (is_array($sort_field_id)) { |
|
1312 | - $modified_ids = []; |
|
1313 | - foreach ($sort_field_id as $_sort_field_id) { |
|
1314 | - $modified_ids[] = self::_override_sorting_id_by_field_type($_sort_field_id, $form_id); |
|
1311 | + if ( is_array( $sort_field_id ) ) { |
|
1312 | + $modified_ids = [ ]; |
|
1313 | + foreach ( $sort_field_id as $_sort_field_id ) { |
|
1314 | + $modified_ids[ ] = self::_override_sorting_id_by_field_type( $_sort_field_id, $form_id ); |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | return $modified_ids; |
1318 | 1318 | } |
1319 | 1319 | |
1320 | - $form = gravityview_get_form($form_id); |
|
1320 | + $form = gravityview_get_form( $form_id ); |
|
1321 | 1321 | |
1322 | - $sort_field = GFFormsModel::get_field($form, $sort_field_id); |
|
1322 | + $sort_field = GFFormsModel::get_field( $form, $sort_field_id ); |
|
1323 | 1323 | |
1324 | - if (!$sort_field) { |
|
1324 | + if ( ! $sort_field ) { |
|
1325 | 1325 | return $sort_field_id; |
1326 | 1326 | } |
1327 | 1327 | |
1328 | - switch ($sort_field['type']) { |
|
1328 | + switch ( $sort_field[ 'type' ] ) { |
|
1329 | 1329 | |
1330 | 1330 | case 'address': |
1331 | 1331 | // Sorting by full address |
1332 | - if (floatval($sort_field_id) === floor($sort_field_id)) { |
|
1332 | + if ( floatval( $sort_field_id ) === floor( $sort_field_id ) ) { |
|
1333 | 1333 | |
1334 | 1334 | /** |
1335 | 1335 | * Override how to sort when sorting address. |
@@ -1340,9 +1340,9 @@ discard block |
||
1340 | 1340 | * @param string $sort_field_id Field used for sorting |
1341 | 1341 | * @param int $form_id GF Form ID |
1342 | 1342 | */ |
1343 | - $address_part = apply_filters('gravityview/sorting/address', 'city', $sort_field_id, $form_id); |
|
1343 | + $address_part = apply_filters( 'gravityview/sorting/address', 'city', $sort_field_id, $form_id ); |
|
1344 | 1344 | |
1345 | - switch (strtolower($address_part)) { |
|
1345 | + switch ( strtolower( $address_part ) ) { |
|
1346 | 1346 | case 'street': |
1347 | 1347 | $sort_field_id .= '.1'; |
1348 | 1348 | break; |
@@ -1367,7 +1367,7 @@ discard block |
||
1367 | 1367 | break; |
1368 | 1368 | case 'name': |
1369 | 1369 | // Sorting by full name, not first, last, etc. |
1370 | - if (floatval($sort_field_id) === floor($sort_field_id)) { |
|
1370 | + if ( floatval( $sort_field_id ) === floor( $sort_field_id ) ) { |
|
1371 | 1371 | /** |
1372 | 1372 | * @filter `gravityview/sorting/full-name` Override how to sort when sorting full name. |
1373 | 1373 | * |
@@ -1377,9 +1377,9 @@ discard block |
||
1377 | 1377 | * @param string $sort_field_id Field used for sorting |
1378 | 1378 | * @param int $form_id GF Form ID |
1379 | 1379 | */ |
1380 | - $name_part = apply_filters('gravityview/sorting/full-name', 'first', $sort_field_id, $form_id); |
|
1380 | + $name_part = apply_filters( 'gravityview/sorting/full-name', 'first', $sort_field_id, $form_id ); |
|
1381 | 1381 | |
1382 | - if ('last' === strtolower($name_part)) { |
|
1382 | + if ( 'last' === strtolower( $name_part ) ) { |
|
1383 | 1383 | $sort_field_id .= '.6'; |
1384 | 1384 | } else { |
1385 | 1385 | $sort_field_id .= '.3'; |
@@ -1400,7 +1400,7 @@ discard block |
||
1400 | 1400 | * @param string $name_part Field used for sorting |
1401 | 1401 | * @param int $form_id GF Form ID |
1402 | 1402 | */ |
1403 | - $sort_field_id = apply_filters('gravityview/sorting/time', $sort_field_id, $form_id); |
|
1403 | + $sort_field_id = apply_filters( 'gravityview/sorting/time', $sort_field_id, $form_id ); |
|
1404 | 1404 | break; |
1405 | 1405 | } |
1406 | 1406 | |
@@ -1418,17 +1418,17 @@ discard block |
||
1418 | 1418 | { |
1419 | 1419 | |
1420 | 1420 | // Since this is a public method, it can be called outside of the plugin. Don't assume things have been loaded properly. |
1421 | - if (!class_exists('\GV\Entry')) { |
|
1421 | + if ( ! class_exists( '\GV\Entry' ) ) { |
|
1422 | 1422 | |
1423 | 1423 | // Not using gravityview()->log->error(), since that may not exist yet either! |
1424 | - do_action('gravityview_log_error', '\GV\Entry not defined yet. Backtrace: '.wp_debug_backtrace_summary()); |
|
1424 | + do_action( 'gravityview_log_error', '\GV\Entry not defined yet. Backtrace: ' . wp_debug_backtrace_summary() ); |
|
1425 | 1425 | |
1426 | 1426 | return null; |
1427 | 1427 | } |
1428 | 1428 | |
1429 | 1429 | $var_name = \GV\Entry::get_endpoint_name(); |
1430 | 1430 | |
1431 | - $single_entry = get_query_var($var_name); |
|
1431 | + $single_entry = get_query_var( $var_name ); |
|
1432 | 1432 | |
1433 | 1433 | /** |
1434 | 1434 | * Modify the entry that is being displayed. |
@@ -1437,9 +1437,9 @@ discard block |
||
1437 | 1437 | * |
1438 | 1438 | * @since 1.6 |
1439 | 1439 | */ |
1440 | - $single_entry = apply_filters('gravityview/is_single_entry', $single_entry); |
|
1440 | + $single_entry = apply_filters( 'gravityview/is_single_entry', $single_entry ); |
|
1441 | 1441 | |
1442 | - if (empty($single_entry)) { |
|
1442 | + if ( empty( $single_entry ) ) { |
|
1443 | 1443 | return false; |
1444 | 1444 | } else { |
1445 | 1445 | return $single_entry; |
@@ -1455,13 +1455,13 @@ discard block |
||
1455 | 1455 | { |
1456 | 1456 | global $post, $posts; |
1457 | 1457 | // enqueue template specific styles |
1458 | - if ($this->getGvOutputData()) { |
|
1458 | + if ( $this->getGvOutputData() ) { |
|
1459 | 1459 | $views = $this->getGvOutputData()->get_views(); |
1460 | 1460 | |
1461 | - foreach ($views as $view_id => $data) { |
|
1462 | - $view = \GV\View::by_id($data['id']); |
|
1461 | + foreach ( $views as $view_id => $data ) { |
|
1462 | + $view = \GV\View::by_id( $data[ 'id' ] ); |
|
1463 | 1463 | $view_id = $view->ID; |
1464 | - $template_id = gravityview_get_template_id($view->ID); |
|
1464 | + $template_id = gravityview_get_template_id( $view->ID ); |
|
1465 | 1465 | $data = $view->as_data(); |
1466 | 1466 | |
1467 | 1467 | /** |
@@ -1469,18 +1469,18 @@ discard block |
||
1469 | 1469 | * |
1470 | 1470 | * @since 1.15 |
1471 | 1471 | */ |
1472 | - if (is_user_logged_in() && false === GVCommon::has_cap('read_gravityview', $view_id)) { |
|
1472 | + if ( is_user_logged_in() && false === GVCommon::has_cap( 'read_gravityview', $view_id ) ) { |
|
1473 | 1473 | continue; |
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | // By default, no thickbox |
1477 | - $js_dependencies = ['jquery', 'gravityview-jquery-cookie']; |
|
1478 | - $css_dependencies = []; |
|
1477 | + $js_dependencies = [ 'jquery', 'gravityview-jquery-cookie' ]; |
|
1478 | + $css_dependencies = [ ]; |
|
1479 | 1479 | |
1480 | - $lightbox = $view->settings->get('lightbox'); |
|
1480 | + $lightbox = $view->settings->get( 'lightbox' ); |
|
1481 | 1481 | |
1482 | 1482 | // If the thickbox is enqueued, add dependencies |
1483 | - if ($lightbox) { |
|
1483 | + if ( $lightbox ) { |
|
1484 | 1484 | global $wp_filter; |
1485 | 1485 | |
1486 | 1486 | /** |
@@ -1490,7 +1490,7 @@ discard block |
||
1490 | 1490 | * |
1491 | 1491 | * @deprecated 2.5.1 Naming. See `gravityview_lightbox_script` instead. |
1492 | 1492 | */ |
1493 | - $js_dependency = apply_filters_deprecated('gravity_view_lightbox_script', ['thickbox'], '2.5.1', 'gravityview_lightbox_script'); |
|
1493 | + $js_dependency = apply_filters_deprecated( 'gravity_view_lightbox_script', [ 'thickbox' ], '2.5.1', 'gravityview_lightbox_script' ); |
|
1494 | 1494 | |
1495 | 1495 | /** |
1496 | 1496 | * @filter `gravityview_lightbox_script` Override the lightbox script to enqueue. Default: `thickbox` |
@@ -1500,8 +1500,8 @@ discard block |
||
1500 | 1500 | * @param string $script_slug If you want to use a different lightbox script, return the name of it here. |
1501 | 1501 | * @param \GV\View The View. |
1502 | 1502 | */ |
1503 | - $js_dependency = apply_filters('gravityview_lightbox_script', $js_dependency, $view); |
|
1504 | - $js_dependencies[] = $js_dependency; |
|
1503 | + $js_dependency = apply_filters( 'gravityview_lightbox_script', $js_dependency, $view ); |
|
1504 | + $js_dependencies[ ] = $js_dependency; |
|
1505 | 1505 | |
1506 | 1506 | /** |
1507 | 1507 | * @filter `gravity_view_lightbox_style` Modify the lightbox CSS slug. Default: `thickbox` |
@@ -1510,7 +1510,7 @@ discard block |
||
1510 | 1510 | * |
1511 | 1511 | * @deprecated 2.5.1 Naming. See `gravityview_lightbox_style` instead. |
1512 | 1512 | */ |
1513 | - $css_dependency = apply_filters_deprecated('gravity_view_lightbox_style', ['thickbox'], '2.5.1', 'gravityview_lightbox_style'); |
|
1513 | + $css_dependency = apply_filters_deprecated( 'gravity_view_lightbox_style', [ 'thickbox' ], '2.5.1', 'gravityview_lightbox_style' ); |
|
1514 | 1514 | |
1515 | 1515 | /** |
1516 | 1516 | * @filter `gravityview_lightbox_script` Override the lightbox script to enqueue. Default: `thickbox` |
@@ -1520,8 +1520,8 @@ discard block |
||
1520 | 1520 | * @param string $script_slug If you want to use a different lightbox script, return the name of it here. |
1521 | 1521 | * @param \GV\View The View. |
1522 | 1522 | */ |
1523 | - $css_dependency = apply_filters('gravityview_lightbox_style', $css_dependency, $view); |
|
1524 | - $css_dependencies[] = $css_dependency; |
|
1523 | + $css_dependency = apply_filters( 'gravityview_lightbox_style', $css_dependency, $view ); |
|
1524 | + $css_dependencies[ ] = $css_dependency; |
|
1525 | 1525 | } |
1526 | 1526 | |
1527 | 1527 | /** |
@@ -1530,32 +1530,32 @@ discard block |
||
1530 | 1530 | * @see https://github.com/katzwebservices/GravityView/issues/536 |
1531 | 1531 | * @since 1.15 |
1532 | 1532 | */ |
1533 | - if (gravityview_view_has_single_checkbox_or_radio($data['form'], $data['fields'])) { |
|
1534 | - $css_dependencies[] = 'dashicons'; |
|
1533 | + if ( gravityview_view_has_single_checkbox_or_radio( $data[ 'form' ], $data[ 'fields' ] ) ) { |
|
1534 | + $css_dependencies[ ] = 'dashicons'; |
|
1535 | 1535 | } |
1536 | 1536 | |
1537 | - wp_register_script('gravityview-jquery-cookie', plugins_url('assets/lib/jquery.cookie/jquery.cookie.min.js', GRAVITYVIEW_FILE), ['jquery'], GravityView_Plugin::version, true); |
|
1537 | + wp_register_script( 'gravityview-jquery-cookie', plugins_url( 'assets/lib/jquery.cookie/jquery.cookie.min.js', GRAVITYVIEW_FILE ), [ 'jquery' ], GravityView_Plugin::version, true ); |
|
1538 | 1538 | |
1539 | - $script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
1539 | + $script_debug = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
1540 | 1540 | |
1541 | - wp_register_script('gravityview-fe-view', plugins_url('assets/js/fe-views'.$script_debug.'.js', GRAVITYVIEW_FILE), apply_filters('gravityview_js_dependencies', $js_dependencies), GravityView_Plugin::version, true); |
|
1541 | + wp_register_script( 'gravityview-fe-view', plugins_url( 'assets/js/fe-views' . $script_debug . '.js', GRAVITYVIEW_FILE ), apply_filters( 'gravityview_js_dependencies', $js_dependencies ), GravityView_Plugin::version, true ); |
|
1542 | 1542 | |
1543 | - wp_enqueue_script('gravityview-fe-view'); |
|
1543 | + wp_enqueue_script( 'gravityview-fe-view' ); |
|
1544 | 1544 | |
1545 | - if (!empty($data['atts']['sort_columns'])) { |
|
1546 | - wp_enqueue_style('gravityview_font', plugins_url('assets/css/font.css', GRAVITYVIEW_FILE), $css_dependencies, GravityView_Plugin::version, 'all'); |
|
1545 | + if ( ! empty( $data[ 'atts' ][ 'sort_columns' ] ) ) { |
|
1546 | + wp_enqueue_style( 'gravityview_font', plugins_url( 'assets/css/font.css', GRAVITYVIEW_FILE ), $css_dependencies, GravityView_Plugin::version, 'all' ); |
|
1547 | 1547 | } |
1548 | 1548 | |
1549 | - $this->enqueue_default_style($css_dependencies); |
|
1549 | + $this->enqueue_default_style( $css_dependencies ); |
|
1550 | 1550 | |
1551 | - self::add_style($template_id); |
|
1551 | + self::add_style( $template_id ); |
|
1552 | 1552 | } |
1553 | 1553 | |
1554 | - if ('wp_print_footer_scripts' === current_filter()) { |
|
1554 | + if ( 'wp_print_footer_scripts' === current_filter() ) { |
|
1555 | 1555 | $js_localization = [ |
1556 | 1556 | 'cookiepath' => COOKIEPATH, |
1557 | - 'clear' => _x('Clear', 'Clear all data from the form', 'gravityview'), |
|
1558 | - 'reset' => _x('Reset', 'Reset the search form to the state that existed on page load', 'gravityview'), |
|
1557 | + 'clear' => _x( 'Clear', 'Clear all data from the form', 'gravityview' ), |
|
1558 | + 'reset' => _x( 'Reset', 'Reset the search form to the state that existed on page load', 'gravityview' ), |
|
1559 | 1559 | ]; |
1560 | 1560 | |
1561 | 1561 | /** |
@@ -1564,9 +1564,9 @@ discard block |
||
1564 | 1564 | * @param array $js_localization The data padded to the Javascript file |
1565 | 1565 | * @param array $views Array of View data arrays with View settings |
1566 | 1566 | */ |
1567 | - $js_localization = apply_filters('gravityview_js_localization', $js_localization, $views); |
|
1567 | + $js_localization = apply_filters( 'gravityview_js_localization', $js_localization, $views ); |
|
1568 | 1568 | |
1569 | - wp_localize_script('gravityview-fe-view', 'gvGlobals', $js_localization); |
|
1569 | + wp_localize_script( 'gravityview-fe-view', 'gvGlobals', $js_localization ); |
|
1570 | 1570 | } |
1571 | 1571 | } |
1572 | 1572 | } |
@@ -1580,7 +1580,7 @@ discard block |
||
1580 | 1580 | * |
1581 | 1581 | * @return void |
1582 | 1582 | */ |
1583 | - private function enqueue_default_style($css_dependencies = []) |
|
1583 | + private function enqueue_default_style( $css_dependencies = [ ] ) |
|
1584 | 1584 | { |
1585 | 1585 | |
1586 | 1586 | /** |
@@ -1590,15 +1590,15 @@ discard block |
||
1590 | 1590 | * |
1591 | 1591 | * @param bool $use_legacy_search_style If true, loads `gv-legacy-search(-rtl).css`. If false, loads `gv-default-styles(-rtl).css`. `-rtl` is added on RTL websites. Default: `false` |
1592 | 1592 | */ |
1593 | - $use_legacy_search_style = apply_filters('gravityview_use_legacy_search_style', false); |
|
1593 | + $use_legacy_search_style = apply_filters( 'gravityview_use_legacy_search_style', false ); |
|
1594 | 1594 | |
1595 | 1595 | $rtl = is_rtl() ? '-rtl' : ''; |
1596 | 1596 | |
1597 | 1597 | $css_file_base = $use_legacy_search_style ? 'gv-legacy-search' : 'gv-default-styles'; |
1598 | 1598 | |
1599 | - $path = gravityview_css_url($css_file_base.$rtl.'.css'); |
|
1599 | + $path = gravityview_css_url( $css_file_base . $rtl . '.css' ); |
|
1600 | 1600 | |
1601 | - wp_enqueue_style('gravityview_default_style', $path, $css_dependencies, GravityView_Plugin::version, 'all'); |
|
1601 | + wp_enqueue_style( 'gravityview_default_style', $path, $css_dependencies, GravityView_Plugin::version, 'all' ); |
|
1602 | 1602 | } |
1603 | 1603 | |
1604 | 1604 | /** |
@@ -1606,15 +1606,15 @@ discard block |
||
1606 | 1606 | * |
1607 | 1607 | * @param string $template_id |
1608 | 1608 | */ |
1609 | - public static function add_style($template_id) |
|
1609 | + public static function add_style( $template_id ) |
|
1610 | 1610 | { |
1611 | - if (!empty($template_id) && wp_style_is('gravityview_style_'.$template_id, 'registered')) { |
|
1612 | - gravityview()->log->debug('Adding extra template style for {template_id}', ['template_id' => $template_id]); |
|
1613 | - wp_enqueue_style('gravityview_style_'.$template_id); |
|
1614 | - } elseif (empty($template_id)) { |
|
1615 | - gravityview()->log->error('Cannot add template style; template_id is empty'); |
|
1611 | + if ( ! empty( $template_id ) && wp_style_is( 'gravityview_style_' . $template_id, 'registered' ) ) { |
|
1612 | + gravityview()->log->debug( 'Adding extra template style for {template_id}', [ 'template_id' => $template_id ] ); |
|
1613 | + wp_enqueue_style( 'gravityview_style_' . $template_id ); |
|
1614 | + } elseif ( empty( $template_id ) ) { |
|
1615 | + gravityview()->log->error( 'Cannot add template style; template_id is empty' ); |
|
1616 | 1616 | } else { |
1617 | - gravityview()->log->error('Cannot add template style; {template_id} is not registered', ['template_id' => 'gravityview_style_'.$template_id]); |
|
1617 | + gravityview()->log->error( 'Cannot add template style; {template_id} is not registered', [ 'template_id' => 'gravityview_style_' . $template_id ] ); |
|
1618 | 1618 | } |
1619 | 1619 | } |
1620 | 1620 | |
@@ -1632,7 +1632,7 @@ discard block |
||
1632 | 1632 | * |
1633 | 1633 | * @return string Field Label |
1634 | 1634 | */ |
1635 | - public function add_columns_sort_links($label = '', $field, $form) |
|
1635 | + public function add_columns_sort_links( $label = '', $field, $form ) |
|
1636 | 1636 | { |
1637 | 1637 | |
1638 | 1638 | /** |
@@ -1640,11 +1640,11 @@ discard block |
||
1640 | 1640 | * |
1641 | 1641 | * @since 1.12 |
1642 | 1642 | */ |
1643 | - if (!preg_match('/table/ism', GravityView_View::getInstance()->getTemplatePartSlug())) { |
|
1643 | + if ( ! preg_match( '/table/ism', GravityView_View::getInstance()->getTemplatePartSlug() ) ) { |
|
1644 | 1644 | return $label; |
1645 | 1645 | } |
1646 | 1646 | |
1647 | - if (!$this->is_field_sortable($field['id'], $form)) { |
|
1647 | + if ( ! $this->is_field_sortable( $field[ 'id' ], $form ) ) { |
|
1648 | 1648 | return $label; |
1649 | 1649 | } |
1650 | 1650 | |
@@ -1652,29 +1652,29 @@ discard block |
||
1652 | 1652 | |
1653 | 1653 | $class = 'gv-sort'; |
1654 | 1654 | |
1655 | - $sort_field_id = self::_override_sorting_id_by_field_type($field['id'], $form['id']); |
|
1655 | + $sort_field_id = self::_override_sorting_id_by_field_type( $field[ 'id' ], $form[ 'id' ] ); |
|
1656 | 1656 | |
1657 | 1657 | $sort_args = [ |
1658 | - 'sort' => $field['id'], |
|
1658 | + 'sort' => $field[ 'id' ], |
|
1659 | 1659 | 'dir' => 'asc', |
1660 | 1660 | ]; |
1661 | 1661 | |
1662 | - if (!empty($sorting['key']) && (string) $sort_field_id === (string) $sorting['key']) { |
|
1662 | + if ( ! empty( $sorting[ 'key' ] ) && (string)$sort_field_id === (string)$sorting[ 'key' ] ) { |
|
1663 | 1663 | //toggle sorting direction. |
1664 | - if ('asc' === $sorting['direction']) { |
|
1665 | - $sort_args['dir'] = 'desc'; |
|
1664 | + if ( 'asc' === $sorting[ 'direction' ] ) { |
|
1665 | + $sort_args[ 'dir' ] = 'desc'; |
|
1666 | 1666 | $class .= ' gv-icon-sort-desc'; |
1667 | 1667 | } else { |
1668 | - $sort_args['dir'] = 'asc'; |
|
1668 | + $sort_args[ 'dir' ] = 'asc'; |
|
1669 | 1669 | $class .= ' gv-icon-sort-asc'; |
1670 | 1670 | } |
1671 | 1671 | } else { |
1672 | 1672 | $class .= ' gv-icon-caret-up-down'; |
1673 | 1673 | } |
1674 | 1674 | |
1675 | - $url = add_query_arg($sort_args, remove_query_arg(['pagenum'])); |
|
1675 | + $url = add_query_arg( $sort_args, remove_query_arg( [ 'pagenum' ] ) ); |
|
1676 | 1676 | |
1677 | - return '<a href="'.esc_url_raw($url).'" class="'.$class.'" ></a> '.$label; |
|
1677 | + return '<a href="' . esc_url_raw( $url ) . '" class="' . $class . '" ></a> ' . $label; |
|
1678 | 1678 | } |
1679 | 1679 | |
1680 | 1680 | /** |
@@ -1687,12 +1687,12 @@ discard block |
||
1687 | 1687 | * |
1688 | 1688 | * @return bool True: Yes, field is sortable; False: not sortable |
1689 | 1689 | */ |
1690 | - public function is_field_sortable($field_id = '', $form = []) |
|
1690 | + public function is_field_sortable( $field_id = '', $form = [ ] ) |
|
1691 | 1691 | { |
1692 | 1692 | $field_type = $field_id; |
1693 | 1693 | |
1694 | - if (is_numeric($field_id)) { |
|
1695 | - $field = GFFormsModel::get_field($form, $field_id); |
|
1694 | + if ( is_numeric( $field_id ) ) { |
|
1695 | + $field = GFFormsModel::get_field( $form, $field_id ); |
|
1696 | 1696 | $field_type = $field ? $field->type : $field_id; |
1697 | 1697 | } |
1698 | 1698 | |
@@ -1706,7 +1706,7 @@ discard block |
||
1706 | 1706 | * |
1707 | 1707 | * @since 1.7 |
1708 | 1708 | */ |
1709 | - $not_sortable = apply_filters_deprecated('gravityview/sortable/field_blacklist', [$not_sortable, $field_type, $form], '2.14', 'gravityview/sortable/field_blocklist'); |
|
1709 | + $not_sortable = apply_filters_deprecated( 'gravityview/sortable/field_blacklist', [ $not_sortable, $field_type, $form ], '2.14', 'gravityview/sortable/field_blocklist' ); |
|
1710 | 1710 | |
1711 | 1711 | /** |
1712 | 1712 | * @filter `gravityview/sortable/field_blocklist` Modify what fields should never be sortable. |
@@ -1717,13 +1717,13 @@ discard block |
||
1717 | 1717 | * @param string $field_type Field type to check whether the field is sortable. |
1718 | 1718 | * @param array $form Gravity Forms form. |
1719 | 1719 | */ |
1720 | - $not_sortable = apply_filters('gravityview/sortable/field_blocklist', $not_sortable, $field_type, $form); |
|
1720 | + $not_sortable = apply_filters( 'gravityview/sortable/field_blocklist', $not_sortable, $field_type, $form ); |
|
1721 | 1721 | |
1722 | - if (in_array($field_type, $not_sortable)) { |
|
1722 | + if ( in_array( $field_type, $not_sortable ) ) { |
|
1723 | 1723 | return false; |
1724 | 1724 | } |
1725 | 1725 | |
1726 | - return apply_filters("gravityview/sortable/formfield_{$form['id']}_{$field_id}", apply_filters("gravityview/sortable/field_{$field_id}", true, $form)); |
|
1726 | + return apply_filters( "gravityview/sortable/formfield_{$form[ 'id' ]}_{$field_id}", apply_filters( "gravityview/sortable/field_{$field_id}", true, $form ) ); |
|
1727 | 1727 | } |
1728 | 1728 | } |
1729 | 1729 |
@@ -11,8 +11,7 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @since 1.0.0 |
13 | 13 | */ |
14 | -class GravityView_frontend |
|
15 | -{ |
|
14 | +class GravityView_frontend { |
|
16 | 15 | /** |
17 | 16 | * Regex strings that are used to determine whether the current request is a GravityView search or not. |
18 | 17 | * |
@@ -92,12 +91,10 @@ discard block |
||
92 | 91 | /** |
93 | 92 | * Class constructor, enforce Singleton pattern. |
94 | 93 | */ |
95 | - private function __construct() |
|
96 | - { |
|
94 | + private function __construct() { |
|
97 | 95 | } |
98 | 96 | |
99 | - private function initialize() |
|
100 | - { |
|
97 | + private function initialize() { |
|
101 | 98 | add_action('wp', [$this, 'parse_content'], 11); |
102 | 99 | add_filter('render_block', [$this, 'detect_views_in_block_content']); |
103 | 100 | add_filter('parse_query', [$this, 'parse_query_fix_frontpage'], 10); |
@@ -120,8 +117,7 @@ discard block |
||
120 | 117 | * |
121 | 118 | * @return GravityView_frontend |
122 | 119 | */ |
123 | - public static function getInstance() |
|
124 | - { |
|
120 | + public static function getInstance() { |
|
125 | 121 | if (empty(self::$instance)) { |
126 | 122 | self::$instance = new self(); |
127 | 123 | self::$instance->initialize(); |
@@ -133,40 +129,35 @@ discard block |
||
133 | 129 | /** |
134 | 130 | * @return GravityView_View_Data |
135 | 131 | */ |
136 | - public function getGvOutputData() |
|
137 | - { |
|
132 | + public function getGvOutputData() { |
|
138 | 133 | return $this->gv_output_data; |
139 | 134 | } |
140 | 135 | |
141 | 136 | /** |
142 | 137 | * @param \GravityView_View_Data $gv_output_data |
143 | 138 | */ |
144 | - public function setGvOutputData($gv_output_data) |
|
145 | - { |
|
139 | + public function setGvOutputData($gv_output_data) { |
|
146 | 140 | $this->gv_output_data = $gv_output_data; |
147 | 141 | } |
148 | 142 | |
149 | 143 | /** |
150 | 144 | * @return bool |
151 | 145 | */ |
152 | - public function isSearch() |
|
153 | - { |
|
146 | + public function isSearch() { |
|
154 | 147 | return $this->is_search; |
155 | 148 | } |
156 | 149 | |
157 | 150 | /** |
158 | 151 | * @param bool $is_search |
159 | 152 | */ |
160 | - public function setIsSearch($is_search) |
|
161 | - { |
|
153 | + public function setIsSearch($is_search) { |
|
162 | 154 | $this->is_search = $is_search; |
163 | 155 | } |
164 | 156 | |
165 | 157 | /** |
166 | 158 | * @return bool|int |
167 | 159 | */ |
168 | - public function getSingleEntry() |
|
169 | - { |
|
160 | + public function getSingleEntry() { |
|
170 | 161 | return $this->single_entry; |
171 | 162 | } |
172 | 163 | |
@@ -175,16 +166,14 @@ discard block |
||
175 | 166 | * |
176 | 167 | * @param bool|int|string $single_entry |
177 | 168 | */ |
178 | - public function setSingleEntry($single_entry) |
|
179 | - { |
|
169 | + public function setSingleEntry($single_entry) { |
|
180 | 170 | $this->single_entry = $single_entry; |
181 | 171 | } |
182 | 172 | |
183 | 173 | /** |
184 | 174 | * @return array |
185 | 175 | */ |
186 | - public function getEntry() |
|
187 | - { |
|
176 | + public function getEntry() { |
|
188 | 177 | return $this->entry; |
189 | 178 | } |
190 | 179 | |
@@ -193,8 +182,7 @@ discard block |
||
193 | 182 | * |
194 | 183 | * @param array|int $entry Entry array or entry slug or ID |
195 | 184 | */ |
196 | - public function setEntry($entry) |
|
197 | - { |
|
185 | + public function setEntry($entry) { |
|
198 | 186 | if (!is_array($entry)) { |
199 | 187 | $entry = GVCommon::get_entry($entry); |
200 | 188 | } |
@@ -205,48 +193,42 @@ discard block |
||
205 | 193 | /** |
206 | 194 | * @return int |
207 | 195 | */ |
208 | - public function getPostId() |
|
209 | - { |
|
196 | + public function getPostId() { |
|
210 | 197 | return $this->post_id; |
211 | 198 | } |
212 | 199 | |
213 | 200 | /** |
214 | 201 | * @param int $post_id |
215 | 202 | */ |
216 | - public function setPostId($post_id) |
|
217 | - { |
|
203 | + public function setPostId($post_id) { |
|
218 | 204 | $this->post_id = $post_id; |
219 | 205 | } |
220 | 206 | |
221 | 207 | /** |
222 | 208 | * @return bool |
223 | 209 | */ |
224 | - public function isPostHasShortcode() |
|
225 | - { |
|
210 | + public function isPostHasShortcode() { |
|
226 | 211 | return $this->post_has_shortcode; |
227 | 212 | } |
228 | 213 | |
229 | 214 | /** |
230 | 215 | * @param bool $post_has_shortcode |
231 | 216 | */ |
232 | - public function setPostHasShortcode($post_has_shortcode) |
|
233 | - { |
|
217 | + public function setPostHasShortcode($post_has_shortcode) { |
|
234 | 218 | $this->post_has_shortcode = $post_has_shortcode; |
235 | 219 | } |
236 | 220 | |
237 | 221 | /** |
238 | 222 | * @return bool |
239 | 223 | */ |
240 | - public function isGravityviewPostType() |
|
241 | - { |
|
224 | + public function isGravityviewPostType() { |
|
242 | 225 | return $this->is_gravityview_post_type; |
243 | 226 | } |
244 | 227 | |
245 | 228 | /** |
246 | 229 | * @param bool $is_gravityview_post_type |
247 | 230 | */ |
248 | - public function setIsGravityviewPostType($is_gravityview_post_type) |
|
249 | - { |
|
231 | + public function setIsGravityviewPostType($is_gravityview_post_type) { |
|
250 | 232 | $this->is_gravityview_post_type = $is_gravityview_post_type; |
251 | 233 | } |
252 | 234 | |
@@ -257,8 +239,7 @@ discard block |
||
257 | 239 | * |
258 | 240 | * @param null $view_id |
259 | 241 | */ |
260 | - public function set_context_view_id($view_id = null) |
|
261 | - { |
|
242 | + public function set_context_view_id($view_id = null) { |
|
262 | 243 | $multiple_views = $this->getGvOutputData() && $this->getGvOutputData()->has_multiple_views(); |
263 | 244 | |
264 | 245 | if (!empty($view_id)) { |
@@ -284,8 +265,7 @@ discard block |
||
284 | 265 | * |
285 | 266 | * @return int|null |
286 | 267 | */ |
287 | - public function get_context_view_id() |
|
288 | - { |
|
268 | + public function get_context_view_id() { |
|
289 | 269 | return $this->context_view_id; |
290 | 270 | } |
291 | 271 | |
@@ -300,8 +280,7 @@ discard block |
||
300 | 280 | * |
301 | 281 | * @return void |
302 | 282 | */ |
303 | - public function parse_query_fix_frontpage(&$query) |
|
304 | - { |
|
283 | + public function parse_query_fix_frontpage(&$query) { |
|
305 | 284 | global $wp_rewrite; |
306 | 285 | |
307 | 286 | $is_front_page = ($query->is_home || $query->is_page); |
@@ -367,8 +346,7 @@ discard block |
||
367 | 346 | * |
368 | 347 | * @todo Once we stop using the legacy `GravityView_frontend::parse_content()` method to detect Views in post content, this code should either be dropped or promoted to some core class given its applicability to other themes/plugins |
369 | 348 | */ |
370 | - public function detect_views_in_block_content($block_content) |
|
371 | - { |
|
349 | + public function detect_views_in_block_content($block_content) { |
|
372 | 350 | if (!class_exists('GV\View_Collection') || !class_exists('GV\View')) { |
373 | 351 | return $block_content; |
374 | 352 | } |
@@ -393,8 +371,7 @@ discard block |
||
393 | 371 | * |
394 | 372 | * @return void |
395 | 373 | */ |
396 | - public function parse_content($wp = []) |
|
397 | - { |
|
374 | + public function parse_content($wp = []) { |
|
398 | 375 | global $post; |
399 | 376 | |
400 | 377 | // If in admin and NOT AJAX request, get outta here. |
@@ -446,8 +423,7 @@ discard block |
||
446 | 423 | /** |
447 | 424 | * Set the entry. |
448 | 425 | */ |
449 | - public function set_entry_data() |
|
450 | - { |
|
426 | + public function set_entry_data() { |
|
451 | 427 | $entry_id = self::is_single_entry(); |
452 | 428 | $this->setSingleEntry($entry_id); |
453 | 429 | $this->setEntry($entry_id); |
@@ -460,8 +436,7 @@ discard block |
||
460 | 436 | * |
461 | 437 | * @return bool True: Yes, it's a search; False: No, not a search. |
462 | 438 | */ |
463 | - public function is_searching() |
|
464 | - { |
|
439 | + public function is_searching() { |
|
465 | 440 | |
466 | 441 | // It's a single entry, not search |
467 | 442 | if ($this->getSingleEntry()) { |
@@ -512,8 +487,7 @@ discard block |
||
512 | 487 | * |
513 | 488 | * @return string (modified) title |
514 | 489 | */ |
515 | - public function single_entry_title($passed_title, $passed_post_id = null) |
|
516 | - { |
|
490 | + public function single_entry_title($passed_title, $passed_post_id = null) { |
|
517 | 491 | global $post; |
518 | 492 | |
519 | 493 | // Since this is a public method, it can be called outside of the plugin. Don't assume things have been loaded properly. |
@@ -595,8 +569,7 @@ discard block |
||
595 | 569 | * |
596 | 570 | * @return string |
597 | 571 | */ |
598 | - private function _get_single_entry_title($view, $entry = [], $passed_title = '') |
|
599 | - { |
|
572 | + private function _get_single_entry_title($view, $entry = [], $passed_title = '') { |
|
600 | 573 | if (!$view) { |
601 | 574 | return $passed_title; |
602 | 575 | } |
@@ -645,8 +618,7 @@ discard block |
||
645 | 618 | * |
646 | 619 | * @return string Add the View output into View CPT content |
647 | 620 | */ |
648 | - public function insert_view_in_content($content) |
|
649 | - { |
|
621 | + public function insert_view_in_content($content) { |
|
650 | 622 | gravityview()->log->notice('\GravityView_frontend::insert_view_in_content is deprecated. Use \GV\View::content()'); |
651 | 623 | |
652 | 624 | return \GV\View::content($content); |
@@ -660,8 +632,7 @@ discard block |
||
660 | 632 | * |
661 | 633 | * @return bool |
662 | 634 | */ |
663 | - public function comments_open($open, $post_id) |
|
664 | - { |
|
635 | + public function comments_open($open, $post_id) { |
|
665 | 636 | if ($this->isGravityviewPostType()) { |
666 | 637 | $open = false; |
667 | 638 | } |
@@ -688,8 +659,7 @@ discard block |
||
688 | 659 | * |
689 | 660 | * @return void |
690 | 661 | */ |
691 | - public function context_not_configured_warning($view_id = 0) |
|
692 | - { |
|
662 | + public function context_not_configured_warning($view_id = 0) { |
|
693 | 663 | if (!class_exists('GravityView_View')) { |
694 | 664 | return; |
695 | 665 | } |
@@ -749,8 +719,7 @@ discard block |
||
749 | 719 | * |
750 | 720 | * @return string|null HTML output of a View, NULL if View isn't found |
751 | 721 | */ |
752 | - public function render_view($passed_args) |
|
753 | - { |
|
722 | + public function render_view($passed_args) { |
|
754 | 723 | gravityview()->log->notice('\GravityView_frontend::render_view is deprecated. Use \GV\View_Renderer etc.'); |
755 | 724 | |
756 | 725 | /** |
@@ -792,8 +761,7 @@ discard block |
||
792 | 761 | * |
793 | 762 | * @return array Modified `$search_criteria` array |
794 | 763 | */ |
795 | - public static function process_search_dates($args, $search_criteria = []) |
|
796 | - { |
|
764 | + public static function process_search_dates($args, $search_criteria = []) { |
|
797 | 765 | $return_search_criteria = $search_criteria; |
798 | 766 | |
799 | 767 | foreach (['start_date', 'end_date'] as $key) { |
@@ -865,8 +833,7 @@ discard block |
||
865 | 833 | * |
866 | 834 | * @return array Modified `$search_criteria` array |
867 | 835 | */ |
868 | - public static function process_search_only_approved($args, $search_criteria) |
|
869 | - { |
|
836 | + public static function process_search_only_approved($args, $search_criteria) { |
|
870 | 837 | |
871 | 838 | /** @since 1.19 */ |
872 | 839 | if (!empty($args['admin_show_all_statuses']) && GVCommon::has_cap('gravityview_moderate_entries')) { |
@@ -905,8 +872,7 @@ discard block |
||
905 | 872 | * |
906 | 873 | * @return bool |
907 | 874 | */ |
908 | - public static function is_entry_approved($entry, $args = []) |
|
909 | - { |
|
875 | + public static function is_entry_approved($entry, $args = []) { |
|
910 | 876 | if (empty($entry['id']) || (array_key_exists('show_only_approved', $args) && !$args['show_only_approved'])) { |
911 | 877 | // is implicitly approved if entry is null or View settings doesn't require to check for approval |
912 | 878 | return true; |
@@ -939,8 +905,7 @@ discard block |
||
939 | 905 | * |
940 | 906 | * @return array Array of search parameters, formatted in Gravity Forms mode, using `status` key set to "active" by default, `field_filters` array with `key`, `value` and `operator` keys. |
941 | 907 | */ |
942 | - public static function get_search_criteria($args, $form_id) |
|
943 | - { |
|
908 | + public static function get_search_criteria($args, $form_id) { |
|
944 | 909 | /** |
945 | 910 | * Compatibility with filters hooking in `gravityview_search_criteria` instead of `gravityview_fe_search_criteria`. |
946 | 911 | */ |
@@ -1034,8 +999,7 @@ discard block |
||
1034 | 999 | * |
1035 | 1000 | * @return array Associative array with `count`, `entries`, and `paging` keys. `count` has the total entries count, `entries` is an array with Gravity Forms full entry data, `paging` is an array with `offset` and `page_size` keys |
1036 | 1001 | */ |
1037 | - public static function get_view_entries($args, $form_id) |
|
1038 | - { |
|
1002 | + public static function get_view_entries($args, $form_id) { |
|
1039 | 1003 | gravityview()->log->debug('[get_view_entries] init'); |
1040 | 1004 | // start filters and sorting |
1041 | 1005 | |
@@ -1093,8 +1057,7 @@ discard block |
||
1093 | 1057 | * |
1094 | 1058 | * @return array With `search_criteria`, `sorting`, `paging`, `cache` keys |
1095 | 1059 | */ |
1096 | - public static function get_view_entries_parameters($args = [], $form_id = 0) |
|
1097 | - { |
|
1060 | + public static function get_view_entries_parameters($args = [], $form_id = 0) { |
|
1098 | 1061 | if (!is_array($args) || !is_numeric($form_id)) { |
1099 | 1062 | gravityview()->log->error('Passed args are not an array or the form ID is not numeric'); |
1100 | 1063 | |
@@ -1160,8 +1123,7 @@ discard block |
||
1160 | 1123 | * @param $args |
1161 | 1124 | * @param int $form_id |
1162 | 1125 | */ |
1163 | - public static function get_search_criteria_paging($args) |
|
1164 | - { |
|
1126 | + public static function get_search_criteria_paging($args) { |
|
1165 | 1127 | |
1166 | 1128 | /** |
1167 | 1129 | * @filter `gravityview_default_page_size` The default number of entries displayed in a View |
@@ -1206,8 +1168,7 @@ discard block |
||
1206 | 1168 | * |
1207 | 1169 | * @return array $sorting Array with `key`, `direction` and `is_numeric` keys |
1208 | 1170 | */ |
1209 | - public static function updateViewSorting($args, $form_id) |
|
1210 | - { |
|
1171 | + public static function updateViewSorting($args, $form_id) { |
|
1211 | 1172 | $sorting = []; |
1212 | 1173 | |
1213 | 1174 | $has_values = isset($_GET['sort']); |
@@ -1306,8 +1267,7 @@ discard block |
||
1306 | 1267 | * |
1307 | 1268 | * @return string|array Possibly modified sorting ID. Array if $sort_field_id is passed as array. |
1308 | 1269 | */ |
1309 | - public static function _override_sorting_id_by_field_type($sort_field_id, $form_id) |
|
1310 | - { |
|
1270 | + public static function _override_sorting_id_by_field_type($sort_field_id, $form_id) { |
|
1311 | 1271 | if (is_array($sort_field_id)) { |
1312 | 1272 | $modified_ids = []; |
1313 | 1273 | foreach ($sort_field_id as $_sort_field_id) { |
@@ -1414,8 +1374,7 @@ discard block |
||
1414 | 1374 | * |
1415 | 1375 | * @return bool|string|null false if not, single entry slug if true, null if \GV\Entry doesn't exist yet |
1416 | 1376 | */ |
1417 | - public static function is_single_entry() |
|
1418 | - { |
|
1377 | + public static function is_single_entry() { |
|
1419 | 1378 | |
1420 | 1379 | // Since this is a public method, it can be called outside of the plugin. Don't assume things have been loaded properly. |
1421 | 1380 | if (!class_exists('\GV\Entry')) { |
@@ -1451,8 +1410,7 @@ discard block |
||
1451 | 1410 | * |
1452 | 1411 | * @return void |
1453 | 1412 | */ |
1454 | - public function add_scripts_and_styles() |
|
1455 | - { |
|
1413 | + public function add_scripts_and_styles() { |
|
1456 | 1414 | global $post, $posts; |
1457 | 1415 | // enqueue template specific styles |
1458 | 1416 | if ($this->getGvOutputData()) { |
@@ -1580,8 +1538,7 @@ discard block |
||
1580 | 1538 | * |
1581 | 1539 | * @return void |
1582 | 1540 | */ |
1583 | - private function enqueue_default_style($css_dependencies = []) |
|
1584 | - { |
|
1541 | + private function enqueue_default_style($css_dependencies = []) { |
|
1585 | 1542 | |
1586 | 1543 | /** |
1587 | 1544 | * @filter `gravityview_use_legacy_search_css` Should GravityView use the legacy Search Bar stylesheet (from before Version 1.17)? |
@@ -1606,8 +1563,7 @@ discard block |
||
1606 | 1563 | * |
1607 | 1564 | * @param string $template_id |
1608 | 1565 | */ |
1609 | - public static function add_style($template_id) |
|
1610 | - { |
|
1566 | + public static function add_style($template_id) { |
|
1611 | 1567 | if (!empty($template_id) && wp_style_is('gravityview_style_'.$template_id, 'registered')) { |
1612 | 1568 | gravityview()->log->debug('Adding extra template style for {template_id}', ['template_id' => $template_id]); |
1613 | 1569 | wp_enqueue_style('gravityview_style_'.$template_id); |
@@ -1632,8 +1588,7 @@ discard block |
||
1632 | 1588 | * |
1633 | 1589 | * @return string Field Label |
1634 | 1590 | */ |
1635 | - public function add_columns_sort_links($label = '', $field, $form) |
|
1636 | - { |
|
1591 | + public function add_columns_sort_links($label = '', $field, $form) { |
|
1637 | 1592 | |
1638 | 1593 | /** |
1639 | 1594 | * Not a table-based template; don't add sort icons. |
@@ -1687,8 +1642,7 @@ discard block |
||
1687 | 1642 | * |
1688 | 1643 | * @return bool True: Yes, field is sortable; False: not sortable |
1689 | 1644 | */ |
1690 | - public function is_field_sortable($field_id = '', $form = []) |
|
1691 | - { |
|
1645 | + public function is_field_sortable($field_id = '', $form = []) { |
|
1692 | 1646 | $field_type = $field_id; |
1693 | 1647 | |
1694 | 1648 | if (is_numeric($field_id)) { |
@@ -15,11 +15,11 @@ |
||
15 | 15 | */ |
16 | 16 | abstract class GravityView_Extension extends \GV\Extension |
17 | 17 | { |
18 | - public function __construct() |
|
19 | - { |
|
20 | - if (!in_array($this->_author, ['GravityView', 'Katz Web Services, Inc.', true])) { |
|
21 | - gravityview()->log->warning('\GravityView_Extension is deprecated. Inherit from \GV\Extension instead', ['data' => $this]); |
|
22 | - } |
|
23 | - parent::__construct(); |
|
24 | - } |
|
18 | + public function __construct() |
|
19 | + { |
|
20 | + if (!in_array($this->_author, ['GravityView', 'Katz Web Services, Inc.', true])) { |
|
21 | + gravityview()->log->warning('\GravityView_Extension is deprecated. Inherit from \GV\Extension instead', ['data' => $this]); |
|
22 | + } |
|
23 | + parent::__construct(); |
|
24 | + } |
|
25 | 25 | } |
@@ -17,8 +17,8 @@ |
||
17 | 17 | { |
18 | 18 | public function __construct() |
19 | 19 | { |
20 | - if (!in_array($this->_author, ['GravityView', 'Katz Web Services, Inc.', true])) { |
|
21 | - gravityview()->log->warning('\GravityView_Extension is deprecated. Inherit from \GV\Extension instead', ['data' => $this]); |
|
20 | + if ( ! in_array( $this->_author, [ 'GravityView', 'Katz Web Services, Inc.', true ] ) ) { |
|
21 | + gravityview()->log->warning( '\GravityView_Extension is deprecated. Inherit from \GV\Extension instead', [ 'data' => $this ] ); |
|
22 | 22 | } |
23 | 23 | parent::__construct(); |
24 | 24 | } |
@@ -15,8 +15,7 @@ |
||
15 | 15 | */ |
16 | 16 | abstract class GravityView_Extension extends \GV\Extension |
17 | 17 | { |
18 | - public function __construct() |
|
19 | - { |
|
18 | + public function __construct() { |
|
20 | 19 | if (!in_array($this->_author, ['GravityView', 'Katz Web Services, Inc.', true])) { |
21 | 20 | gravityview()->log->warning('\GravityView_Extension is deprecated. Inherit from \GV\Extension instead', ['data' => $this]); |
22 | 21 | } |
@@ -18,183 +18,183 @@ |
||
18 | 18 | */ |
19 | 19 | class GravityView_Entry_Notes |
20 | 20 | { |
21 | - /** |
|
22 | - * GravityView_Entry_Notes constructor. |
|
23 | - */ |
|
24 | - public function __construct() |
|
25 | - { |
|
26 | - $this->add_hooks(); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * @since 1.15 |
|
31 | - */ |
|
32 | - private function add_hooks() |
|
33 | - { |
|
34 | - add_filter('gform_notes_avatar', ['GravityView_Entry_Notes', 'filter_avatar'], 10, 2); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Alias for GFFormsModel::add_note() with default note_type of 'gravityview'. |
|
39 | - * |
|
40 | - * @see GFFormsModel::add_note() |
|
41 | - * @since 1.15 |
|
42 | - * @since 1.17 Added return value |
|
43 | - * |
|
44 | - * @param int $lead_id ID of the Entry |
|
45 | - * @param int $user_id ID of the user creating the note |
|
46 | - * @param string $user_name User name of the user creating the note |
|
47 | - * @param string $note Note content. |
|
48 | - * @param string $note_type Type of note. Default: `gravityview` |
|
49 | - * |
|
50 | - * @return int|WP_Error Note ID, if success. WP_Error with $wpdb->last_error message, if failed. |
|
51 | - */ |
|
52 | - public static function add_note($lead_id, $user_id, $user_name, $note = '', $note_type = 'gravityview') |
|
53 | - { |
|
54 | - global $wpdb; |
|
55 | - |
|
56 | - $default_note = [ |
|
57 | - 'lead_id' => 0, |
|
58 | - 'user_id' => 0, |
|
59 | - 'user_name' => '', |
|
60 | - 'note' => '', |
|
61 | - 'note_type' => 'gravityview', |
|
62 | - ]; |
|
63 | - |
|
64 | - /** |
|
65 | - * @filter `gravityview/entry_notes/add_note` Modify note values before added using GFFormsModel::add_note() |
|
66 | - * |
|
67 | - * @see GFFormsModel::add_note |
|
68 | - * @since 1.15.2 |
|
69 | - * |
|
70 | - * @param array $note Array with `lead_id`, `user_id`, `user_name`, `note`, and `note_type` key value pairs |
|
71 | - */ |
|
72 | - $note = apply_filters('gravityview/entry_notes/add_note', compact('lead_id', 'user_id', 'user_name', 'note', 'note_type')); |
|
73 | - |
|
74 | - // Make sure the keys are all set |
|
75 | - $note = wp_parse_args($note, $default_note); |
|
76 | - |
|
77 | - GFFormsModel::add_note(intval($note['lead_id']), intval($note['user_id']), esc_attr($note['user_name']), $note['note'], esc_attr($note['note_type'])); |
|
78 | - |
|
79 | - // If last_error is empty string, there was no error. |
|
80 | - if (empty($wpdb->last_error)) { |
|
81 | - $return = $wpdb->insert_id; |
|
82 | - } else { |
|
83 | - $return = new WP_Error('gravityview-add-note', $wpdb->last_error); |
|
84 | - } |
|
85 | - |
|
86 | - return $return; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Alias for GFFormsModel::delete_note(). |
|
91 | - * |
|
92 | - * @see GFFormsModel::delete_note() |
|
93 | - * |
|
94 | - * @param int $note_id Entry note ID |
|
95 | - */ |
|
96 | - public static function delete_note($note_id) |
|
97 | - { |
|
98 | - GFFormsModel::delete_note($note_id); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Delete an array of notes |
|
103 | - * Alias for GFFormsModel::delete_notes(). |
|
104 | - * |
|
105 | - * @todo Write more efficient delete note method using SQL |
|
106 | - * |
|
107 | - * @param int[] $note_ids Array of entry note ids |
|
108 | - */ |
|
109 | - public static function delete_notes($note_ids = []) |
|
110 | - { |
|
111 | - if (!is_array($note_ids)) { |
|
112 | - gravityview()->log->error('Note IDs not an array. Not processing delete request.', ['data' => $note_ids]); |
|
113 | - |
|
114 | - return; |
|
115 | - } |
|
116 | - |
|
117 | - GFFormsModel::delete_notes($note_ids); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Alias for GFFormsModel::get_lead_notes(). |
|
122 | - * |
|
123 | - * @see GFFormsModel::get_lead_notes |
|
124 | - * |
|
125 | - * @param int $entry_id Entry to get notes for |
|
126 | - * |
|
127 | - * @return stdClass[]|null Integer-keyed array of note objects |
|
128 | - */ |
|
129 | - public static function get_notes($entry_id) |
|
130 | - { |
|
131 | - $notes = GFFormsModel::get_lead_notes($entry_id); |
|
132 | - |
|
133 | - /** |
|
134 | - * @filter `gravityview/entry_notes/get_notes` Modify the notes array for an entry |
|
135 | - * |
|
136 | - * @since 1.15 |
|
137 | - * |
|
138 | - * @param stdClass[]|null $notes Integer-keyed array of note objects |
|
139 | - * @param int $entry_id Entry to get notes for |
|
140 | - */ |
|
141 | - $notes = apply_filters('gravityview/entry_notes/get_notes', $notes, $entry_id); |
|
142 | - |
|
143 | - return $notes; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Get a single note by note ID. |
|
148 | - * |
|
149 | - * @since 1.17 |
|
150 | - * |
|
151 | - * @param int $note_id The ID of the note in the `{prefix}_rg_lead_notes` table |
|
152 | - * |
|
153 | - * @return object|bool False if not found; note object otherwise. |
|
154 | - */ |
|
155 | - public static function get_note($note_id) |
|
156 | - { |
|
157 | - global $wpdb; |
|
158 | - |
|
159 | - if (version_compare(GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=') |
|
160 | - && method_exists('GFFormsModel', 'get_entry_notes_table_name')) { |
|
161 | - $notes_table = GFFormsModel::get_entry_notes_table_name(); |
|
162 | - } else { |
|
163 | - $notes_table = GFFormsModel::get_lead_notes_table_name(); |
|
164 | - } |
|
165 | - |
|
166 | - $results = $wpdb->get_results( |
|
167 | - $wpdb->prepare( |
|
168 | - " SELECT n.id, n.user_id, n.date_created, n.value, n.note_type, ifnull(u.display_name,n.user_name) as user_name, u.user_email |
|
21 | + /** |
|
22 | + * GravityView_Entry_Notes constructor. |
|
23 | + */ |
|
24 | + public function __construct() |
|
25 | + { |
|
26 | + $this->add_hooks(); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * @since 1.15 |
|
31 | + */ |
|
32 | + private function add_hooks() |
|
33 | + { |
|
34 | + add_filter('gform_notes_avatar', ['GravityView_Entry_Notes', 'filter_avatar'], 10, 2); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Alias for GFFormsModel::add_note() with default note_type of 'gravityview'. |
|
39 | + * |
|
40 | + * @see GFFormsModel::add_note() |
|
41 | + * @since 1.15 |
|
42 | + * @since 1.17 Added return value |
|
43 | + * |
|
44 | + * @param int $lead_id ID of the Entry |
|
45 | + * @param int $user_id ID of the user creating the note |
|
46 | + * @param string $user_name User name of the user creating the note |
|
47 | + * @param string $note Note content. |
|
48 | + * @param string $note_type Type of note. Default: `gravityview` |
|
49 | + * |
|
50 | + * @return int|WP_Error Note ID, if success. WP_Error with $wpdb->last_error message, if failed. |
|
51 | + */ |
|
52 | + public static function add_note($lead_id, $user_id, $user_name, $note = '', $note_type = 'gravityview') |
|
53 | + { |
|
54 | + global $wpdb; |
|
55 | + |
|
56 | + $default_note = [ |
|
57 | + 'lead_id' => 0, |
|
58 | + 'user_id' => 0, |
|
59 | + 'user_name' => '', |
|
60 | + 'note' => '', |
|
61 | + 'note_type' => 'gravityview', |
|
62 | + ]; |
|
63 | + |
|
64 | + /** |
|
65 | + * @filter `gravityview/entry_notes/add_note` Modify note values before added using GFFormsModel::add_note() |
|
66 | + * |
|
67 | + * @see GFFormsModel::add_note |
|
68 | + * @since 1.15.2 |
|
69 | + * |
|
70 | + * @param array $note Array with `lead_id`, `user_id`, `user_name`, `note`, and `note_type` key value pairs |
|
71 | + */ |
|
72 | + $note = apply_filters('gravityview/entry_notes/add_note', compact('lead_id', 'user_id', 'user_name', 'note', 'note_type')); |
|
73 | + |
|
74 | + // Make sure the keys are all set |
|
75 | + $note = wp_parse_args($note, $default_note); |
|
76 | + |
|
77 | + GFFormsModel::add_note(intval($note['lead_id']), intval($note['user_id']), esc_attr($note['user_name']), $note['note'], esc_attr($note['note_type'])); |
|
78 | + |
|
79 | + // If last_error is empty string, there was no error. |
|
80 | + if (empty($wpdb->last_error)) { |
|
81 | + $return = $wpdb->insert_id; |
|
82 | + } else { |
|
83 | + $return = new WP_Error('gravityview-add-note', $wpdb->last_error); |
|
84 | + } |
|
85 | + |
|
86 | + return $return; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Alias for GFFormsModel::delete_note(). |
|
91 | + * |
|
92 | + * @see GFFormsModel::delete_note() |
|
93 | + * |
|
94 | + * @param int $note_id Entry note ID |
|
95 | + */ |
|
96 | + public static function delete_note($note_id) |
|
97 | + { |
|
98 | + GFFormsModel::delete_note($note_id); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Delete an array of notes |
|
103 | + * Alias for GFFormsModel::delete_notes(). |
|
104 | + * |
|
105 | + * @todo Write more efficient delete note method using SQL |
|
106 | + * |
|
107 | + * @param int[] $note_ids Array of entry note ids |
|
108 | + */ |
|
109 | + public static function delete_notes($note_ids = []) |
|
110 | + { |
|
111 | + if (!is_array($note_ids)) { |
|
112 | + gravityview()->log->error('Note IDs not an array. Not processing delete request.', ['data' => $note_ids]); |
|
113 | + |
|
114 | + return; |
|
115 | + } |
|
116 | + |
|
117 | + GFFormsModel::delete_notes($note_ids); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Alias for GFFormsModel::get_lead_notes(). |
|
122 | + * |
|
123 | + * @see GFFormsModel::get_lead_notes |
|
124 | + * |
|
125 | + * @param int $entry_id Entry to get notes for |
|
126 | + * |
|
127 | + * @return stdClass[]|null Integer-keyed array of note objects |
|
128 | + */ |
|
129 | + public static function get_notes($entry_id) |
|
130 | + { |
|
131 | + $notes = GFFormsModel::get_lead_notes($entry_id); |
|
132 | + |
|
133 | + /** |
|
134 | + * @filter `gravityview/entry_notes/get_notes` Modify the notes array for an entry |
|
135 | + * |
|
136 | + * @since 1.15 |
|
137 | + * |
|
138 | + * @param stdClass[]|null $notes Integer-keyed array of note objects |
|
139 | + * @param int $entry_id Entry to get notes for |
|
140 | + */ |
|
141 | + $notes = apply_filters('gravityview/entry_notes/get_notes', $notes, $entry_id); |
|
142 | + |
|
143 | + return $notes; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Get a single note by note ID. |
|
148 | + * |
|
149 | + * @since 1.17 |
|
150 | + * |
|
151 | + * @param int $note_id The ID of the note in the `{prefix}_rg_lead_notes` table |
|
152 | + * |
|
153 | + * @return object|bool False if not found; note object otherwise. |
|
154 | + */ |
|
155 | + public static function get_note($note_id) |
|
156 | + { |
|
157 | + global $wpdb; |
|
158 | + |
|
159 | + if (version_compare(GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=') |
|
160 | + && method_exists('GFFormsModel', 'get_entry_notes_table_name')) { |
|
161 | + $notes_table = GFFormsModel::get_entry_notes_table_name(); |
|
162 | + } else { |
|
163 | + $notes_table = GFFormsModel::get_lead_notes_table_name(); |
|
164 | + } |
|
165 | + |
|
166 | + $results = $wpdb->get_results( |
|
167 | + $wpdb->prepare( |
|
168 | + " SELECT n.id, n.user_id, n.date_created, n.value, n.note_type, ifnull(u.display_name,n.user_name) as user_name, u.user_email |
|
169 | 169 | FROM $notes_table n |
170 | 170 | LEFT OUTER JOIN $wpdb->users u ON n.user_id = u.id |
171 | 171 | WHERE n.id=%d", |
172 | - $note_id |
|
173 | - ) |
|
174 | - ); |
|
175 | - |
|
176 | - return $results ? $results[0] : false; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Use the GravityView avatar for notes created by GravityView |
|
181 | - * Note: The function is static so that it's easier to remove the filter: `remove_filter( 'gform_notes_avatar', array( 'GravityView_Entry_Notes', 'filter_avatar' ) );`. |
|
182 | - * |
|
183 | - * @since 1.15 |
|
184 | - * |
|
185 | - * @param string $avatar Avatar image, if available. 48px x 48px by default. |
|
186 | - * @param object $note Note object with id, user_id, date_created, value, note_type, user_name, user_email vars |
|
187 | - * |
|
188 | - * @return string Possibly-modified avatar |
|
189 | - */ |
|
190 | - public static function filter_avatar($avatar = '', $note) |
|
191 | - { |
|
192 | - if ('gravityview' === $note->note_type && -1 === (int) $note->user_id) { |
|
193 | - $avatar = sprintf('<img src="%s" width="48" height="48" alt="GravityView" class="avatar avatar-48 gravityview-avatar" />', esc_url_raw(plugins_url('assets/images/floaty-avatar.png', GRAVITYVIEW_FILE))); |
|
194 | - } |
|
195 | - |
|
196 | - return $avatar; |
|
197 | - } |
|
172 | + $note_id |
|
173 | + ) |
|
174 | + ); |
|
175 | + |
|
176 | + return $results ? $results[0] : false; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Use the GravityView avatar for notes created by GravityView |
|
181 | + * Note: The function is static so that it's easier to remove the filter: `remove_filter( 'gform_notes_avatar', array( 'GravityView_Entry_Notes', 'filter_avatar' ) );`. |
|
182 | + * |
|
183 | + * @since 1.15 |
|
184 | + * |
|
185 | + * @param string $avatar Avatar image, if available. 48px x 48px by default. |
|
186 | + * @param object $note Note object with id, user_id, date_created, value, note_type, user_name, user_email vars |
|
187 | + * |
|
188 | + * @return string Possibly-modified avatar |
|
189 | + */ |
|
190 | + public static function filter_avatar($avatar = '', $note) |
|
191 | + { |
|
192 | + if ('gravityview' === $note->note_type && -1 === (int) $note->user_id) { |
|
193 | + $avatar = sprintf('<img src="%s" width="48" height="48" alt="GravityView" class="avatar avatar-48 gravityview-avatar" />', esc_url_raw(plugins_url('assets/images/floaty-avatar.png', GRAVITYVIEW_FILE))); |
|
194 | + } |
|
195 | + |
|
196 | + return $avatar; |
|
197 | + } |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | new GravityView_Entry_Notes(); |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | private function add_hooks() |
33 | 33 | { |
34 | - add_filter('gform_notes_avatar', ['GravityView_Entry_Notes', 'filter_avatar'], 10, 2); |
|
34 | + add_filter( 'gform_notes_avatar', [ 'GravityView_Entry_Notes', 'filter_avatar' ], 10, 2 ); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * |
50 | 50 | * @return int|WP_Error Note ID, if success. WP_Error with $wpdb->last_error message, if failed. |
51 | 51 | */ |
52 | - public static function add_note($lead_id, $user_id, $user_name, $note = '', $note_type = 'gravityview') |
|
52 | + public static function add_note( $lead_id, $user_id, $user_name, $note = '', $note_type = 'gravityview' ) |
|
53 | 53 | { |
54 | 54 | global $wpdb; |
55 | 55 | |
@@ -69,18 +69,18 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @param array $note Array with `lead_id`, `user_id`, `user_name`, `note`, and `note_type` key value pairs |
71 | 71 | */ |
72 | - $note = apply_filters('gravityview/entry_notes/add_note', compact('lead_id', 'user_id', 'user_name', 'note', 'note_type')); |
|
72 | + $note = apply_filters( 'gravityview/entry_notes/add_note', compact( 'lead_id', 'user_id', 'user_name', 'note', 'note_type' ) ); |
|
73 | 73 | |
74 | 74 | // Make sure the keys are all set |
75 | - $note = wp_parse_args($note, $default_note); |
|
75 | + $note = wp_parse_args( $note, $default_note ); |
|
76 | 76 | |
77 | - GFFormsModel::add_note(intval($note['lead_id']), intval($note['user_id']), esc_attr($note['user_name']), $note['note'], esc_attr($note['note_type'])); |
|
77 | + GFFormsModel::add_note( intval( $note[ 'lead_id' ] ), intval( $note[ 'user_id' ] ), esc_attr( $note[ 'user_name' ] ), $note[ 'note' ], esc_attr( $note[ 'note_type' ] ) ); |
|
78 | 78 | |
79 | 79 | // If last_error is empty string, there was no error. |
80 | - if (empty($wpdb->last_error)) { |
|
80 | + if ( empty( $wpdb->last_error ) ) { |
|
81 | 81 | $return = $wpdb->insert_id; |
82 | 82 | } else { |
83 | - $return = new WP_Error('gravityview-add-note', $wpdb->last_error); |
|
83 | + $return = new WP_Error( 'gravityview-add-note', $wpdb->last_error ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | return $return; |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @param int $note_id Entry note ID |
95 | 95 | */ |
96 | - public static function delete_note($note_id) |
|
96 | + public static function delete_note( $note_id ) |
|
97 | 97 | { |
98 | - GFFormsModel::delete_note($note_id); |
|
98 | + GFFormsModel::delete_note( $note_id ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param int[] $note_ids Array of entry note ids |
108 | 108 | */ |
109 | - public static function delete_notes($note_ids = []) |
|
109 | + public static function delete_notes( $note_ids = [ ] ) |
|
110 | 110 | { |
111 | - if (!is_array($note_ids)) { |
|
112 | - gravityview()->log->error('Note IDs not an array. Not processing delete request.', ['data' => $note_ids]); |
|
111 | + if ( ! is_array( $note_ids ) ) { |
|
112 | + gravityview()->log->error( 'Note IDs not an array. Not processing delete request.', [ 'data' => $note_ids ] ); |
|
113 | 113 | |
114 | 114 | return; |
115 | 115 | } |
116 | 116 | |
117 | - GFFormsModel::delete_notes($note_ids); |
|
117 | + GFFormsModel::delete_notes( $note_ids ); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | * |
127 | 127 | * @return stdClass[]|null Integer-keyed array of note objects |
128 | 128 | */ |
129 | - public static function get_notes($entry_id) |
|
129 | + public static function get_notes( $entry_id ) |
|
130 | 130 | { |
131 | - $notes = GFFormsModel::get_lead_notes($entry_id); |
|
131 | + $notes = GFFormsModel::get_lead_notes( $entry_id ); |
|
132 | 132 | |
133 | 133 | /** |
134 | 134 | * @filter `gravityview/entry_notes/get_notes` Modify the notes array for an entry |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @param stdClass[]|null $notes Integer-keyed array of note objects |
139 | 139 | * @param int $entry_id Entry to get notes for |
140 | 140 | */ |
141 | - $notes = apply_filters('gravityview/entry_notes/get_notes', $notes, $entry_id); |
|
141 | + $notes = apply_filters( 'gravityview/entry_notes/get_notes', $notes, $entry_id ); |
|
142 | 142 | |
143 | 143 | return $notes; |
144 | 144 | } |
@@ -152,12 +152,12 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @return object|bool False if not found; note object otherwise. |
154 | 154 | */ |
155 | - public static function get_note($note_id) |
|
155 | + public static function get_note( $note_id ) |
|
156 | 156 | { |
157 | 157 | global $wpdb; |
158 | 158 | |
159 | - if (version_compare(GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=') |
|
160 | - && method_exists('GFFormsModel', 'get_entry_notes_table_name')) { |
|
159 | + if ( version_compare( GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) |
|
160 | + && method_exists( 'GFFormsModel', 'get_entry_notes_table_name' ) ) { |
|
161 | 161 | $notes_table = GFFormsModel::get_entry_notes_table_name(); |
162 | 162 | } else { |
163 | 163 | $notes_table = GFFormsModel::get_lead_notes_table_name(); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | ) |
174 | 174 | ); |
175 | 175 | |
176 | - return $results ? $results[0] : false; |
|
176 | + return $results ? $results[ 0 ] : false; |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -187,10 +187,10 @@ discard block |
||
187 | 187 | * |
188 | 188 | * @return string Possibly-modified avatar |
189 | 189 | */ |
190 | - public static function filter_avatar($avatar = '', $note) |
|
190 | + public static function filter_avatar( $avatar = '', $note ) |
|
191 | 191 | { |
192 | - if ('gravityview' === $note->note_type && -1 === (int) $note->user_id) { |
|
193 | - $avatar = sprintf('<img src="%s" width="48" height="48" alt="GravityView" class="avatar avatar-48 gravityview-avatar" />', esc_url_raw(plugins_url('assets/images/floaty-avatar.png', GRAVITYVIEW_FILE))); |
|
192 | + if ( 'gravityview' === $note->note_type && -1 === (int)$note->user_id ) { |
|
193 | + $avatar = sprintf( '<img src="%s" width="48" height="48" alt="GravityView" class="avatar avatar-48 gravityview-avatar" />', esc_url_raw( plugins_url( 'assets/images/floaty-avatar.png', GRAVITYVIEW_FILE ) ) ); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | return $avatar; |
@@ -16,21 +16,18 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @since 1.15 |
18 | 18 | */ |
19 | -class GravityView_Entry_Notes |
|
20 | -{ |
|
19 | +class GravityView_Entry_Notes { |
|
21 | 20 | /** |
22 | 21 | * GravityView_Entry_Notes constructor. |
23 | 22 | */ |
24 | - public function __construct() |
|
25 | - { |
|
23 | + public function __construct() { |
|
26 | 24 | $this->add_hooks(); |
27 | 25 | } |
28 | 26 | |
29 | 27 | /** |
30 | 28 | * @since 1.15 |
31 | 29 | */ |
32 | - private function add_hooks() |
|
33 | - { |
|
30 | + private function add_hooks() { |
|
34 | 31 | add_filter('gform_notes_avatar', ['GravityView_Entry_Notes', 'filter_avatar'], 10, 2); |
35 | 32 | } |
36 | 33 | |
@@ -49,8 +46,7 @@ discard block |
||
49 | 46 | * |
50 | 47 | * @return int|WP_Error Note ID, if success. WP_Error with $wpdb->last_error message, if failed. |
51 | 48 | */ |
52 | - public static function add_note($lead_id, $user_id, $user_name, $note = '', $note_type = 'gravityview') |
|
53 | - { |
|
49 | + public static function add_note($lead_id, $user_id, $user_name, $note = '', $note_type = 'gravityview') { |
|
54 | 50 | global $wpdb; |
55 | 51 | |
56 | 52 | $default_note = [ |
@@ -93,8 +89,7 @@ discard block |
||
93 | 89 | * |
94 | 90 | * @param int $note_id Entry note ID |
95 | 91 | */ |
96 | - public static function delete_note($note_id) |
|
97 | - { |
|
92 | + public static function delete_note($note_id) { |
|
98 | 93 | GFFormsModel::delete_note($note_id); |
99 | 94 | } |
100 | 95 | |
@@ -106,8 +101,7 @@ discard block |
||
106 | 101 | * |
107 | 102 | * @param int[] $note_ids Array of entry note ids |
108 | 103 | */ |
109 | - public static function delete_notes($note_ids = []) |
|
110 | - { |
|
104 | + public static function delete_notes($note_ids = []) { |
|
111 | 105 | if (!is_array($note_ids)) { |
112 | 106 | gravityview()->log->error('Note IDs not an array. Not processing delete request.', ['data' => $note_ids]); |
113 | 107 | |
@@ -126,8 +120,7 @@ discard block |
||
126 | 120 | * |
127 | 121 | * @return stdClass[]|null Integer-keyed array of note objects |
128 | 122 | */ |
129 | - public static function get_notes($entry_id) |
|
130 | - { |
|
123 | + public static function get_notes($entry_id) { |
|
131 | 124 | $notes = GFFormsModel::get_lead_notes($entry_id); |
132 | 125 | |
133 | 126 | /** |
@@ -152,8 +145,7 @@ discard block |
||
152 | 145 | * |
153 | 146 | * @return object|bool False if not found; note object otherwise. |
154 | 147 | */ |
155 | - public static function get_note($note_id) |
|
156 | - { |
|
148 | + public static function get_note($note_id) { |
|
157 | 149 | global $wpdb; |
158 | 150 | |
159 | 151 | if (version_compare(GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=') |
@@ -187,8 +179,7 @@ discard block |
||
187 | 179 | * |
188 | 180 | * @return string Possibly-modified avatar |
189 | 181 | */ |
190 | - public static function filter_avatar($avatar = '', $note) |
|
191 | - { |
|
182 | + public static function filter_avatar($avatar = '', $note) { |
|
192 | 183 | if ('gravityview' === $note->note_type && -1 === (int) $note->user_id) { |
193 | 184 | $avatar = sprintf('<img src="%s" width="48" height="48" alt="GravityView" class="avatar avatar-48 gravityview-avatar" />', esc_url_raw(plugins_url('assets/images/floaty-avatar.png', GRAVITYVIEW_FILE))); |
194 | 185 | } |