Completed
Push — develop ( 507546...65eb42 )
by Zack
05:37
created

includes/class-data.php (16 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/** If this file is called directly, abort. */
4
if ( ! defined( 'ABSPATH' ) ) {
5
	die;
6
}
7
8
class GravityView_View_Data {
9
10
	static $instance = NULL;
11
12
	protected $views = array();
13
14
	/**
15
	 *
16
	 * @param null $passed_post
17
	 */
18
	private function __construct( $passed_post = NULL ) {
19
20
		if( !empty( $passed_post ) ) {
21
22
			$id_or_id_array = $this->maybe_get_view_id( $passed_post );
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_View_Data::maybe_get_view_id() has been deprecated.

This method has been deprecated.

Loading history...
23
24
			if( !empty( $id_or_id_array ) ) {
25
				$this->add_view( $id_or_id_array );
26
			}
27
		}
28
29
	}
30
31
	/**
32
	 * @return boolean
33
	 */
34
	public function has_multiple_views() {
35
36
		//multiple views
37
		return count( $this->get_views() ) > 1 ? true : false;
38
	}
39
40
41
	/**
42
	 * Figure out what the View ID is for a variable, if any.
43
	 *
44
	 * Can be:
45
	 *      - WP_Post (Either a `gravityview` post type or not)
46
	 *      - Multi-dimensional array of WP_Post objects
47
	 *      - Array with `view_id` or `id` key(s) set
48
	 *      - String of content that may include GravityView shortcode
49
	 *      - Number representing the Post ID or View ID
50
	 *
51
	 * @param mixed $passed_post See method description
52
	 *
53
	 * @deprecated
54
	 * @see \GV\View_Collection::from_post and \GV\Shortcode::parse
55
	 *
56
	 * @return int|null|array ID of the View. If there are multiple views in the content, array of IDs parsed.
57
	 */
58
	public function maybe_get_view_id( $passed_post ) {
59
		$ids = array();
60
61
		if( ! empty( $passed_post ) ) {
62
63
			if( is_numeric( $passed_post ) ) {
64
				$passed_post = get_post( $passed_post );
65
			}
66
67
			// Convert WP_Posts into WP_Posts[] array
68
			if( $passed_post instanceof WP_Post ) {
69
				$passed_post = array( $passed_post );
70
			}
71
72
			if( is_array( $passed_post ) ) {
73
74
				foreach ( $passed_post as &$post) {
75
					if ( function_exists( 'gravityview' ) && $post instanceof WP_Post ) {
0 ignored issues
show
The class WP_Post does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
76
						$views = \GV\View_Collection::from_post( $post );
77
						foreach ( $views->all() as $view ) {
78
							$ids []= $view->ID;
0 ignored issues
show
Expected 1 space before "="; 0 found
Loading history...
79
						}
80
					} else {
81
						/** Deprecated, see \GV\View_Collection::from_post */
82
						if( ( get_post_type( $post ) === 'gravityview' ) ) {
83
							$ids[] = $post->ID;
84
						} else{
85
							// Parse the Post Content
86
							$id = $this->parse_post_content( $post->post_content );
87
							if( $id ) {
88
								$ids = array_merge( $ids, (array) $id );
89
							}
90
91
							// Parse the Post Meta
92
							$id = $this->parse_post_meta( $post->ID );
93
							if( $id ) {
94
								$ids = array_merge( $ids, (array) $id );
95
							}
96
						}
97
					}
98
99
				}
100
101
			} else {
102
103
				if ( is_string( $passed_post ) ) {
104
105
					if ( function_exists( 'gravityview' ) ) {
106
						$shortcodes = \GV\Shortcode::parse( $passed_post );
107
						foreach ( $shortcodes as $shortcode ) {
108
							if ( $shortcode->name == 'gravityview' && !empty( $shortcode->atts['id'] ) )
0 ignored issues
show
Found "== '". Use Yoda Condition checks, you must
Loading history...
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
Expected 1 space after "!"; 0 found
Loading history...
109
								$ids []= $shortcode->atts['id'];
0 ignored issues
show
Expected 1 space before "="; 0 found
Loading history...
110
						}
111
					} else {
112
						/** Deprecated, use \GV\Shortcode::parse. */
113
						$id = $this->parse_post_content( $passed_post );
114
						if( $id ) {
115
							$ids = array_merge( $ids, (array) $id );
116
						}
117
					}
118
119
				} else {
120
					$id = $this->get_id_from_atts( $passed_post );
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_View_Data::get_id_from_atts() has been deprecated with message: Also dead code, was probably superceded by GravityView_View_Data::parse_post_content

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
121
					$ids[] = intval( $id );
122
				}
123
			}
124
		}
125
126
		if( empty($ids) ) {
0 ignored issues
show
Expected 1 spaces after opening bracket; 0 found
Loading history...
Expected 1 spaces before closing bracket; 0 found
Loading history...
127
			return NULL;
0 ignored issues
show
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
128
		}
129
130
		// If it's just one ID, return that.
131
		// Otherwise, return array of IDs
132
		return ( sizeof( $ids ) === 1 ) ? $ids[0] : $ids;
133
	}
134
135
	/**
136
	 * @return GravityView_View_Data
137
	 */
138
	public static function getInstance( $passed_post = NULL ) {
139
140
		if( empty( self::$instance ) ) {
141
			self::$instance = new GravityView_View_Data( $passed_post );
142
		}
143
144
		return self::$instance;
145
	}
146
147
	function get_views() {
148
		return $this->views;
149
	}
150
151
	function get_view( $view_id, $atts = NULL ) {
152
153
		if( ! is_numeric( $view_id) ) {
154
			do_action('gravityview_log_error', sprintf('GravityView_View_Data[get_view] $view_id passed is not numeric.', $view_id) );
155
			return false;
156
		}
157
158
		// Backup: the view hasn't been fetched yet. Doing it now.
159
		if ( ! isset( $this->views[ $view_id ] ) ) {
160
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[get_view] View #%s not set yet.', $view_id) );
161
			return $this->add_view( $view_id, $atts );
162
		}
163
164
		if ( empty( $this->views[ $view_id ] ) ) {
165
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[get_view] Returning; View #%s was empty.', $view_id) );
166
			return false;
167
		}
168
169
		return $this->views[ $view_id ];
170
	}
171
172
	/**
173
	 * Determines if a post, identified by the specified ID, exist
174
	 * within the WordPress database.
175
	 *
176
	 * @see http://tommcfarlin.com/wordpress-post-exists-by-id/ Fastest check available
177
	 * @param    int    $view_id    The ID of the post to check
178
	 * @return   bool   True if the post exists; otherwise, false.
179
	 * @since    1.0.0
180
	 */
181
	function view_exists( $view_id ) {
182
		return is_string( get_post_status( $view_id ) );
183
	}
184
185
	/**
186
	 *
187
	 * Add a view to the views array
188
	 *
189
	 * @param int|array $view_id View ID or array of View IDs
190
	 * @param array|string $atts Combine other attributes (eg. from shortcode) with the view settings (optional)
191
	 * @return array
192
	 */
193
	function add_view( $view_id, $atts = NULL ) {
194
195
		// Handle array of IDs
196
		if( is_array( $view_id ) ) {
197
			foreach( $view_id as $id ) {
198
199
				$this->add_view( $id, $atts );
200
			}
201
202
			return $this->views;
203
		}
204
205
		// The view has been set already; returning stored view.
206
		if ( !empty( $this->views[ $view_id ] ) ) {
207
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s already exists.', $view_id) );
208
			return $this->views[ $view_id ];
209
		}
210
211
		if( ! $this->view_exists( $view_id ) ) {
212
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; View #%s does not exist.', $view_id) );
213
			return false;
214
		}
215
216
		$form_id = gravityview_get_form_id( $view_id );
217
218
		if( empty( $form_id ) ) {
219
220
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Returning; Post ID #%s does not have a connected form.', $view_id) );
221
222
			return false;
223
		}
224
225
		// Get the settings for the View ID
226
		$view_settings = gravityview_get_template_settings( $view_id );
227
228
		do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] Settings pulled in from View #%s', $view_id), $view_settings );
229
230
		// Merge the view settings with the defaults
231
		$view_defaults = wp_parse_args( $view_settings, self::get_default_args() );
232
233
		do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] View Defaults after merging View Settings with the default args.', $view_defaults );
234
235
		if( ! empty( $atts ) && is_array( $atts ) ) {
236
237
			do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] $atts before merging  with the $view_defaults', $atts );
238
239
			// Get the settings from the shortcode and merge them with defaults.
240
			$atts = shortcode_atts( $view_defaults, $atts );
241
242
			do_action('gravityview_log_debug', 'GravityView_View_Data[add_view] $atts after merging  with the $view_defaults', $atts );
243
244
		} else {
245
246
			// If there are no passed $atts, the defaults will be used.
247
			$atts = $view_defaults;
248
249
		}
250
251
		unset( $atts['id'], $view_defaults, $view_settings );
252
253
		$data = array(
254
			'id' => $view_id,
255
			'view_id' => $view_id,
256
			'form_id' => $form_id,
257
			'template_id' => gravityview_get_template_id( $view_id ),
258
			'atts' => $atts,
259
			'fields' => $this->get_fields( $view_id ),
260
			'widgets' => gravityview_get_directory_widgets( $view_id ),
261
			'form' => gravityview_get_form( $form_id ),
262
		);
263
264
		do_action('gravityview_log_debug', sprintf('GravityView_View_Data[add_view] View #%s being added.', $view_id), $data );
265
266
		$this->views[ $view_id ] = $data;
267
268
		return $this->views[ $view_id ];
269
	}
270
271
	/**
272
	 * Get the visible fields for a View
273
	 * @uses  gravityview_get_directory_fields() Fetch the configured fields for a View
274
	 * @uses  GravityView_View_Data::filter_fields() Only show visible fields
275
	 * @param  int $view_id View ID
276
	 * @return array          Array of fields as passed by `gravityview_get_directory_fields()`
277
	 */
278
	function get_fields( $view_id ) {
279
280
		$dir_fields = gravityview_get_directory_fields( $view_id );
281
		do_action( 'gravityview_log_debug', '[render_view] Fields: ', $dir_fields );
282
283
		// remove fields according to visitor visibility permissions (if logged-in)
284
		$dir_fields = $this->filter_fields( $dir_fields );
285
		do_action( 'gravityview_log_debug', '[render_view] Fields after visibility filter: ', $dir_fields );
286
287
		return $dir_fields;
288
	}
289
290
	/**
291
	 * Filter area fields based on specified conditions
292
	 *
293
	 * @access public
294
	 * @param array $dir_fields
295
	 * @return array
296
	 */
297
	private function filter_fields( $dir_fields ) {
298
299
		if( empty( $dir_fields ) || !is_array( $dir_fields ) ) {
300
			return $dir_fields;
301
		}
302
303
		foreach( $dir_fields as $area => $fields ) {
304
305
			foreach( (array)$fields as $uniqid => $properties ) {
306
307
				if( $this->hide_field_check_conditions( $properties ) ) {
308
					unset( $dir_fields[ $area ][ $uniqid ] );
309
				}
310
311
			}
312
		}
313
314
		return $dir_fields;
315
316
	}
317
318
319
	/**
320
	 * Check whether a certain field should not be presented based on its own properties.
321
	 *
322
	 * @access public
323
	 * @param array $properties
324
	 * @return boolean True: (field should be hidden) or False: (field should be presented)
325
	 */
326
	private function hide_field_check_conditions( $properties ) {
327
328
		// logged-in visibility
329
		if( ! empty( $properties['only_loggedin'] ) && ! GVCommon::has_cap( $properties['only_loggedin_cap'] ) ) {
330
			return true;
331
		}
332
333
		return false;
334
	}
335
336
	/**
337
	 * @deprecated Also dead code, was probably superceded by GravityView_View_Data::parse_post_content
338
	 */
339
	function get_id_from_atts( $atts ) {
340
341
		$atts = is_array( $atts ) ? $atts : shortcode_parse_atts( $atts );
342
343
		// Get the settings from the shortcode and merge them with defaults.
344
		$atts = wp_parse_args( $atts, self::get_default_args() );
345
346
		$view_id = ! empty( $atts['view_id'] ) ? (int)$atts['view_id'] : NULL;
347
348
		if( empty( $view_id ) && !empty( $atts['id'] ) ) {
349
			$view_id = (int)$atts['id'];
350
		}
351
352
		if( empty( $view_id ) ) {
353
			do_action('gravityview_log_error', 'GravityView_View_Data[get_id_from_atts] Returning; no ID defined (Atts)', $atts );
354
			return;
355
		}
356
357
		return $view_id;
358
	}
359
360
	/**
361
	 * Parse content to determine if there is a GV shortcode to allow for enqueing necessary files in the head.
362
	 *
363
	 * @uses gravityview_has_shortcode_r() Check whether shortcode exists (recursively)
364
	 * @uses shortcode_parse_atts() Parse each GV shortcode
365
	 * @uses  gravityview_get_template_settings() Get the settings for the View ID
366
	 * @param  string $content $post->post_content content
367
	 * @return int|null|array If a single View is found, the ID of the View. If there are multiple views in the content, array of IDs parsed. If not found, NULL
368
	 */
369
	public function parse_post_content( $content ) {
370
371
		/**
372
		 * @hack This is so that the shortcode is registered for the oEmbed preview in the Admin
373
		 * @since 1.6
374
		 */
375
		if( ! shortcode_exists('gravityview') && class_exists( 'GravityView_Shortcode' ) ) {
376
			new GravityView_Shortcode;
377
		}
378
379
		$shortcodes = gravityview_has_shortcode_r( $content, 'gravityview' );
380
381
		if( empty( $shortcodes ) ) {
382
			return NULL;
0 ignored issues
show
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
383
		}
384
385
		do_action('gravityview_log_debug', 'GravityView_View_Data[parse_post_content] Parsing content, found shortcodes:', $shortcodes );
386
387
		$ids = array();
388
389
		foreach ($shortcodes as $key => $shortcode) {
390
391
			$shortcode[3] = htmlspecialchars_decode( $shortcode[3], ENT_QUOTES );
392
393
			$args = shortcode_parse_atts( $shortcode[3] );
394
395
			if( empty( $args['id'] ) ) {
396
				do_action('gravityview_log_error', sprintf( 'GravityView_View_Data[parse_post_content] Returning; no ID defined in shortcode atts for Post #%s (Atts)', $post->ID ), $shortcode );
397
				continue;
398
			}
399
400
			do_action('gravityview_log_debug', sprintf('GravityView_View_Data[parse_post_content] Adding view #%s with shortcode args', $args['id']), $args );
401
402
			// Store the View to the object for later fetching.
403
			$this->add_view( $args['id'], $args );
404
405
			$ids[] = $args['id'];
406
		}
407
408
		if( empty($ids) ) {
409
			return NULL;
0 ignored issues
show
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
410
		}
411
412
		// If it's just one ID, return that.
413
		// Otherwise, return array of IDs
414
		return ( sizeof( $ids ) === 1 ) ? $ids[0] : $ids;
415
416
	}
417
418
	/**
419
	 * Parse specific custom fields (Post Meta) to determine if there is a GV shortcode to allow for enqueuing necessary files in the head.
420
	 * @since 1.15.1
421
	 * @uses \GravityView_View_Data::parse_post_content
422
	 * @param int $post_id WP_Post ID
423
	 * @return int|null|array If a single View is found, the ID of the View. If there are multiple views in the content, array of IDs parsed. If not found, or meta not parsed, NULL
424
	 */
425
	private function parse_post_meta( $post_id ) {
426
427
		/**
428
		 * @filter `gravityview/data/parse/meta_keys` Define meta keys to parse to check for GravityView shortcode content
429
		 * This is useful when using themes that store content that may contain shortcodes in custom post meta
430
		 * @param[in,out] array $meta_keys Array of key values to check. If empty, do not check. Default: empty array
431
		 * @param[in] int $post_id ID of the post being checked
432
		 */
433
		$meta_keys = (array)apply_filters( 'gravityview/data/parse/meta_keys', array(), $post_id );
434
435
		if( empty( $meta_keys ) ) {
436
			return NULL;
0 ignored issues
show
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
437
		}
438
439
		do_action( 'gravityview_log_debug', 'GravityView_View_Data[parse_post_meta] Search for GravityView shortcodes on the following custom fields keys:', $meta_keys );
440
441
		$meta_content = '';
442
443
		foreach( $meta_keys as $key ) {
444
			$meta = get_post_meta( $post_id, $key , true );
445
			if( ! is_string( $meta ) ) {
446
				continue;
447
			}
448
			$meta_content .= $meta . ' ';
449
		}
450
451
		if( empty( $meta_content ) ) {
452
			do_action('gravityview_log_error', sprintf( 'GravityView_View_Data[parse_post_meta] Returning; Empty custom fields for Post #%s (Custom fields keys:)', $post_id ), $meta_keys );
453
			return NULL;
0 ignored issues
show
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
454
		}
455
456
		do_action( 'gravityview_log_debug', 'GravityView_View_Data[parse_post_meta] Combined content retrieved from custom fields:', $meta_content );
457
458
		return $this->parse_post_content( $meta_content );
459
460
	}
461
462
	/**
463
	 * Checks if the passed post id has the passed View id embedded.
464
	 *
465
	 * Returns
466
	 *
467
	 * @since 1.6.1
468
	 *
469
	 * @param string $post_id Post ID where the View is embedded
470
	 * @param string $view_id View ID
471
	 *
472
	 * @return bool|WP_Error If valid, returns true. If invalid, returns WP_Error containing error message.
473
	 */
474
	public static function is_valid_embed_id( $post_id = '', $view_id = '', $empty_is_valid = true ) {
475
476
		$message = NULL;
477
478
		// Not invalid if not set!
479
		if( empty( $post_id ) || empty( $view_id ) ) {
480
481
			if( $empty_is_valid ) {
482
				return true;
483
			}
484
485
			$message = esc_html__( 'The ID is required.', 'gravityview' );
486
		}
487
488
		if( ! $message ) {
489
			$status = get_post_status( $post_id );
490
491
			// Nothing exists with that post ID.
492
			if ( ! is_numeric( $post_id ) ) {
493
				$message = esc_html__( 'You did not enter a number. The value entered should be a number, representing the ID of the post or page the View is embedded on.', 'gravityview' );
494
495
				// @todo Convert to generic article about Embed IDs
496
				$message .= ' ' . gravityview_get_link( 'http://docs.gravityview.co/article/222-the-search-widget', __( 'Learn more&hellip;', 'gravityview' ), 'target=_blank' );
497
			}
498
		}
499
500
		if( ! $message ) {
501
502
			// Nothing exists with that post ID.
503
			if ( empty( $status ) || in_array( $status, array( 'revision', 'attachment' ) ) ) {
504
				$message = esc_html__( 'There is no post or page with that ID.', 'gravityview' );
505
			}
506
507
		}
508
509
		if( ! $message ) {
510
			if ( function_exists( 'gravityview' ) && $post = get_post( $post_id ) )  {
511
				$views = GV\View_Collection::from_post( $post );
512
				$view_ids_in_post = array_map( function( $view ) { return $view->ID; }, $views->all() );
513
			} else {
514
				/** ::maybe_get_view_id deprecated. */
515
				$view_ids_in_post = GravityView_View_Data::getInstance()->maybe_get_view_id( $post_id );
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_View_Data::maybe_get_view_id() has been deprecated.

This method has been deprecated.

Loading history...
516
			}
517
518
			// The post or page specified does not contain the shortcode.
519
			if ( false === in_array( $view_id, (array) $view_ids_in_post ) ) {
520
				$message = sprintf( esc_html__( 'The Post ID entered is not valid. You may have entered a post or page that does not contain the selected View. Make sure the post contains the following shortcode: %s', 'gravityview' ), '<br /><code>[gravityview id="' . intval( $view_id ) . '"]</code>' );
521
			}
522
		}
523
524
		if( ! $message ) {
525
526
			// It's a View
527
			if( 'gravityview' === get_post_type( $post_id ) ) {
528
				$message = esc_html__( 'The ID is already a View.', 'gravityview' );;
529
			}
530
531
		}
532
533
		if( $message ) {
534
			return new WP_Error( 'invalid_embed_id', $message );
535
		}
536
537
		return true;
538
	}
539
540
	/**
541
	 * Get a specific default setting
542
	 * @param  string  $key          The key of the setting array item
543
	 * @param  boolean $with_details Include details
544
	 * @return mixed|array                If using $with_details, return array. Otherwise, mixed.
545
	 */
546
	public static function get_default_arg( $key, $with_details = false ) {
547
548
		$args = self::get_default_args( $with_details );
549
550
		if( !isset( $args[ $key ] ) ) { return NULL; }
551
552
		return $args[ $key ];
553
	}
554
555
	/**
556
	 * Retrieve the default args for shortcode and theme function
557
	 *
558
	 * @param boolean $with_details True: Return array with full default settings information, including description, name, etc. False: Return an array with only key => value pairs.
559
	 * @param string $group Only fetch
560
	 *
561
	 * @return array $args Associative array of default settings for a View
562
	 *      @param[out] string $label Setting label shown in admin
563
	 *      @param[out] string $type Gravity Forms field type
564
	 *      @param[out] string $group The field group the setting is associated with. Default: "default"
565
	 *      @param[out] mixed  $value The default value for the setting
566
	 *      @param[out] string $tooltip Tooltip displayed for the setting
567
	 *      @param[out] boolean $show_in_shortcode Whether to show the setting in the shortcode configuration modal
568
	 *      @param[out] array  $options Array of values to use when generating select, multiselect, radio, or checkboxes fields
569
	 *      @param[out] boolean $full_width True: Display the input and label together when rendering. False: Display label and input in separate columns when rendering.
570
	 */
571
	public static function get_default_args( $with_details = false, $group = NULL ) {
572
573
		/**
574
		 * @filter `gravityview_default_args` Modify the default settings for new Views
575
		 * @param[in,out] array $default_args Array of default args.
576
		 */
577
		$default_settings = apply_filters( 'gravityview_default_args', array(
578
			'id' => array(
579
				'label' => __('View ID', 'gravityview'),
580
				'type' => 'number',
581
				'group'	=> 'default',
582
				'value' => NULL,
583
				'tooltip' => NULL,
584
				'show_in_shortcode' => false,
585
			),
586
			'page_size' => array(
587
				'label' 	=> __('Number of entries per page', 'gravityview'),
588
				'type' => 'number',
589
				'class'	=> 'small-text',
590
				'group'	=> 'default',
591
				'value' => 25,
592
				'show_in_shortcode' => true,
593
			),
594
			'lightbox' => array(
595
				'label' => __( 'Enable lightbox for images', 'gravityview' ),
596
				'type' => 'checkbox',
597
				'group'	=> 'default',
598
				'value' => 1,
599
				'tooltip' => NULL,
600
				'show_in_shortcode' => true,
601
			),
602
			'show_only_approved' => array(
603
				'label' => __( 'Show only approved entries', 'gravityview' ),
604
				'type' => 'checkbox',
605
				'group'	=> 'default',
606
				'value' => 0,
607
				'show_in_shortcode' => true,
608
			),
609
			'admin_show_all_statuses' => array(
610
				'label' => __( 'Show all entries to administrators', 'gravityview' ),
611
				'desc'	=> __('Administrators will be able to see entries with any approval status.', 'gravityview'),
612
				'tooltip' => __('Logged-out visitors and non-administrators will only see approved entries, while administrators will see entries with all statuses. This makes it easier for administrators to moderate entries from a View.', 'gravityview'),
613
				'requires' => 'show_only_approved',
614
				'type' => 'checkbox',
615
				'group'	=> 'default',
616
				'value' => 0,
617
				'show_in_shortcode' => false,
618
			),
619
			'hide_until_searched' => array(
620
				'label' => __( 'Hide View data until search is performed', 'gravityview' ),
621
				'type' => 'checkbox',
622
				'group'	=> 'default',
623
				'tooltip' => __( 'When enabled it will only show any View entries after a search is performed.', 'gravityview' ),
624
				'value' => 0,
625
				'show_in_shortcode' => false,
626
			),
627
			'hide_empty' => array(
628
				'label' 	=> __( 'Hide empty fields', 'gravityview' ),
629
				'group'	=> 'default',
630
				'type'	=> 'checkbox',
631
				'value' => 1,
632
				'show_in_shortcode' => false,
633
			),
634
			'user_edit' => array(
635
				'label'	=> __( 'Allow User Edit', 'gravityview' ),
636
				'group'	=> 'default',
637
				'desc'	=> __('Allow logged-in users to edit entries they created.', 'gravityview'),
638
				'value'	=> 0,
639
				'tooltip' => __('Display "Edit Entry" fields to non-administrator users if they created the entry. Edit Entry fields will always be displayed to site administrators.', 'gravityview'),
640
				'type'	=> 'checkbox',
641
				'show_in_shortcode' => true,
642
			),
643
			'user_delete' => array(
644
				'label'	=> __( 'Allow User Delete', 'gravityview' ),
645
				'group'	=> 'default',
646
				'desc'	=> __('Allow logged-in users to delete entries they created.', 'gravityview'),
647
				'value'	=> 0,
648
				'tooltip' => __('Display "Delete Entry" fields to non-administrator users if they created the entry. Delete Entry fields will always be displayed to site administrators.', 'gravityview'),
649
				'type'	=> 'checkbox',
650
				'show_in_shortcode' => true,
651
			),
652
			'sort_field' => array(
653
				'label'	=> __('Sort by field', 'gravityview'),
654
				'type' => 'select',
655
				'value' => '',
656
				'group'	=> 'sort',
657
				'options' => array(
658
					'' => __( 'Default', 'gravityview'),
659
					'date_created' => __( 'Date Created', 'gravityview'),
660
				),
661
				'show_in_shortcode' => true,
662
			),
663
			'sort_direction' => array(
664
				'label' 	=> __('Sort direction', 'gravityview'),
665
				'type' => 'select',
666
				'value' => 'ASC',
667
				'group'	=> 'sort',
668
				'options' => array(
669
					'ASC' => __('ASC', 'gravityview'),
670
					'DESC' => __('DESC', 'gravityview'),
671
					//'RAND' => __('Random', 'gravityview'),
672
				),
673
				'show_in_shortcode' => true,
674
			),
675
			'sort_columns' => array(
676
				'label' 	=> __( 'Enable sorting by column', 'gravityview' ),
677
				'left_label' => __( 'Column Sorting', 'gravityview' ),
678
				'type' => 'checkbox',
679
				'value' => false,
680
				'group'	=> 'sort',
681
				'tooltip' => NULL,
682
				'show_in_shortcode' => true,
683
				'show_in_template' => array( 'default_table' ),
684
			),
685
			'start_date' => array(
686
				'label' 	=> __('Filter by Start Date', 'gravityview'),
687
				'class'	=> 'gv-datepicker',
688
				'desc'	=> __('Show entries submitted after this date. Supports relative dates, such as "-1 week" or "-1 month".', 'gravityview' ),
689
				'type' => 'text',
690
				'value' => '',
691
				'group'	=> 'filter',
692
				'show_in_shortcode' => true,
693
			),
694
			'end_date' => array(
695
				'label' 	=> __('Filter by End Date', 'gravityview'),
696
				'class'	=> 'gv-datepicker',
697
				'desc'	=> __('Show entries submitted before this date. Supports relative dates, such as "now" or "-3 days".', 'gravityview' ),
698
				'type' => 'text',
699
				'value' => '',
700
				'group'	=> 'filter',
701
				'show_in_shortcode' => true,
702
			),
703
			'class' => array(
704
				'label' 	=> __('CSS Class', 'gravityview'),
705
				'desc'	=> __('CSS class to add to the wrapping HTML container.', 'gravityview'),
706
				'group'	=> 'default',
707
				'type' => 'text',
708
				'value' => '',
709
				'show_in_shortcode' => false,
710
			),
711
			'search_value' => array(
712
				'label' 	=> __('Search Value', 'gravityview'),
713
				'desc'	=> __('Define a default search value for the View', 'gravityview'),
714
				'type' => 'text',
715
				'value' => '',
716
				'group'	=> 'filter',
717
				'show_in_shortcode' => false,
718
			),
719
			'search_field' => array(
720
				'label' 	=> __('Search Field', 'gravityview'),
721
				'desc'	=> __('If Search Value is set, you can define a specific field to search in. Otherwise, all fields will be searched.', 'gravityview'),
722
				'type' => 'number',
723
				'value' => '',
724
				'group'	=> 'filter',
725
				'show_in_shortcode' => false,
726
			),
727
			'single_title' => array(
728
				'label'	=> __('Single Entry Title', 'gravityview'),
729
				'type'	=> 'text',
730
				'desc'	=> __('When viewing a single entry, change the title of the page to this setting. Otherwise, the title will not change between the Multiple Entries and Single Entry views.', 'gravityview'),
731
				'group'	=> 'default',
732
				'value'	=> '',
733
				'show_in_shortcode' => false,
734
				'full_width' => true,
735
			),
736
			'back_link_label' => array(
737
				'label'	=> __('Back Link Label', 'gravityview'),
738
				'group'	=> 'default',
739
				'desc'	=> __('The text of the link that returns to the multiple entries view.', 'gravityview'),
740
				'type'	=> 'text',
741
				'value'	=> '',
742
				'show_in_shortcode' => false,
743
				'full_width' => true,
744
			),
745
			'embed_only' => array(
746
				'label'	=> __('Prevent Direct Access', 'gravityview'),
747
				'group'	=> 'default',
748
				'desc'	=> __('Only allow access to this View when embedded using the shortcode.', 'gravityview'),
749
				'type'	=> 'checkbox',
750
				'value'	=> '',
751
				'show_in_shortcode' => false,
752
				'full_width' => true,
753
			),
754
			'post_id' => array(
755
				'type' => 'number',
756
				'value' => '',
757
				'show_in_shortcode' => false,
758
			),
759
		));
760
761
		// By default, we only want the key => value pairing, not the whole array.
762
		if( empty( $with_details ) ) {
763
764
			$defaults = array();
765
766
			foreach( $default_settings as $key => $value ) {
767
				$defaults[ $key ] = $value['value'];
768
			}
769
770
			return $defaults;
771
772
		}
773
		// But sometimes, we want all the details.
774
		else {
775
776
			foreach ($default_settings as $key => $value) {
777
778
				// If the $group argument is set for the method,
779
				// ignore any settings that aren't in that group.
780
				if( !empty( $group ) && is_string( $group ) ) {
781
					if( empty( $value['group'] ) || $value['group'] !== $group ) {
782
						unset( $default_settings[ $key ] );
783
					}
784
				}
785
786
			}
787
788
			return $default_settings;
789
790
		}
791
	}
792
793
794
}
795