1
|
|
|
<?php |
|
|
|
|
2
|
|
|
namespace GV; |
3
|
|
|
|
4
|
|
|
/** If this file is called directly, abort. */ |
5
|
|
|
if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
6
|
|
|
die(); |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* The View Settings class. |
11
|
|
|
*/ |
12
|
|
|
class View_Settings extends Settings { |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Retrieve the default View settings. |
16
|
|
|
* |
17
|
|
|
* @param bool $detailed Whether to return detailed setting meta information or just the value. |
18
|
|
|
* @param string $group Retrieve settings of a particular group. |
19
|
|
|
* |
20
|
|
|
* @api |
21
|
|
|
* @since future |
22
|
|
|
* |
23
|
|
|
* @return array The default settings along with their values. |
24
|
|
|
* @param[out] string $label Setting label shown in admin |
25
|
|
|
* @param[out] string $type Gravity Forms field type |
26
|
|
|
* @param[out] string $group The field group the setting is associated with. Default: "default" |
27
|
|
|
* @param[out] mixed $value The default value for the setting |
28
|
|
|
* @param[out] string $tooltip Tooltip displayed for the setting |
29
|
|
|
* @param[out] boolean $show_in_shortcode Whether to show the setting in the shortcode configuration modal |
30
|
|
|
* @param[out] array $options Array of values to use when generating select, multiselect, radio, or checkboxes fields |
31
|
|
|
* @param[out] boolean $full_width True: Display the input and label together when rendering. False: Display label and input in separate columns when rendering. |
32
|
|
|
*/ |
33
|
7 |
|
public static function defaults( $detailed = false, $group = null ) { |
34
|
|
|
|
35
|
|
|
$default_settings = array( |
36
|
7 |
|
'id' => array( |
37
|
7 |
|
'label' => __('View ID', 'gravityview'), |
|
|
|
|
38
|
7 |
|
'type' => 'number', |
39
|
7 |
|
'group' => 'default', |
40
|
|
|
'value' => NULL, |
|
|
|
|
41
|
|
|
'tooltip' => NULL, |
|
|
|
|
42
|
|
|
'show_in_shortcode' => false, |
43
|
|
|
), |
44
|
|
|
'page_size' => array( |
45
|
7 |
|
'label' => __('Number of entries per page', 'gravityview'), |
|
|
|
|
46
|
7 |
|
'type' => 'number', |
47
|
7 |
|
'class' => 'small-text', |
48
|
7 |
|
'group' => 'default', |
49
|
7 |
|
'value' => 25, |
50
|
|
|
'show_in_shortcode' => true, |
51
|
|
|
), |
52
|
|
|
'offset' => array( |
53
|
7 |
|
'label' => __('Offset entries starting from', 'gravityview'), |
|
|
|
|
54
|
7 |
|
'type' => 'number', |
55
|
7 |
|
'class' => 'small-text', |
56
|
7 |
|
'group' => 'default', |
57
|
7 |
|
'value' => 0, |
58
|
|
|
'show_in_shortcode' => true, |
59
|
|
|
), |
60
|
|
|
'lightbox' => array( |
61
|
7 |
|
'label' => __( 'Enable lightbox for images', 'gravityview' ), |
62
|
7 |
|
'type' => 'checkbox', |
63
|
7 |
|
'group' => 'default', |
64
|
7 |
|
'value' => 1, |
65
|
|
|
'tooltip' => NULL, |
|
|
|
|
66
|
|
|
'show_in_shortcode' => true, |
67
|
|
|
), |
68
|
|
|
'show_only_approved' => array( |
69
|
7 |
|
'label' => __( 'Show only approved entries', 'gravityview' ), |
70
|
7 |
|
'type' => 'checkbox', |
71
|
7 |
|
'group' => 'default', |
72
|
7 |
|
'value' => 0, |
73
|
|
|
'show_in_shortcode' => true, |
74
|
|
|
), |
75
|
|
|
'admin_show_all_statuses' => array( |
76
|
7 |
|
'label' => __( 'Show all entries to administrators', 'gravityview' ), |
77
|
7 |
|
'desc' => __('Administrators will be able to see entries with any approval status.', 'gravityview'), |
|
|
|
|
78
|
7 |
|
'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'), |
|
|
|
|
79
|
7 |
|
'requires' => 'show_only_approved', |
80
|
7 |
|
'type' => 'checkbox', |
81
|
7 |
|
'group' => 'default', |
82
|
7 |
|
'value' => 0, |
83
|
|
|
'show_in_shortcode' => false, |
84
|
|
|
), |
85
|
|
|
'hide_until_searched' => array( |
86
|
7 |
|
'label' => __( 'Hide View data until search is performed', 'gravityview' ), |
87
|
7 |
|
'type' => 'checkbox', |
88
|
7 |
|
'group' => 'default', |
89
|
7 |
|
'tooltip' => __( 'When enabled it will only show any View entries after a search is performed.', 'gravityview' ), |
90
|
7 |
|
'value' => 0, |
91
|
|
|
'show_in_shortcode' => false, |
92
|
|
|
), |
93
|
|
|
'hide_empty' => array( |
94
|
7 |
|
'label' => __( 'Hide empty fields', 'gravityview' ), |
95
|
7 |
|
'group' => 'default', |
96
|
7 |
|
'type' => 'checkbox', |
97
|
7 |
|
'value' => 1, |
98
|
|
|
'show_in_shortcode' => false, |
99
|
|
|
), |
100
|
|
|
'user_edit' => array( |
101
|
7 |
|
'label' => __( 'Allow User Edit', 'gravityview' ), |
102
|
7 |
|
'group' => 'default', |
103
|
7 |
|
'desc' => __('Allow logged-in users to edit entries they created.', 'gravityview'), |
|
|
|
|
104
|
7 |
|
'value' => 0, |
105
|
7 |
|
'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'), |
|
|
|
|
106
|
7 |
|
'type' => 'checkbox', |
107
|
|
|
'show_in_shortcode' => true, |
108
|
|
|
), |
109
|
|
|
'user_delete' => array( |
110
|
7 |
|
'label' => __( 'Allow User Delete', 'gravityview' ), |
111
|
7 |
|
'group' => 'default', |
112
|
7 |
|
'desc' => __('Allow logged-in users to delete entries they created.', 'gravityview'), |
|
|
|
|
113
|
7 |
|
'value' => 0, |
114
|
7 |
|
'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'), |
|
|
|
|
115
|
7 |
|
'type' => 'checkbox', |
116
|
|
|
'show_in_shortcode' => true, |
117
|
|
|
), |
118
|
|
|
'sort_field' => array( |
119
|
7 |
|
'label' => __('Sort by field', 'gravityview'), |
|
|
|
|
120
|
7 |
|
'type' => 'select', |
121
|
7 |
|
'value' => '', |
122
|
7 |
|
'group' => 'sort', |
123
|
|
|
'options' => array( |
124
|
7 |
|
'' => __( 'Default', 'gravityview'), |
|
|
|
|
125
|
7 |
|
'date_created' => __( 'Date Created', 'gravityview'), |
|
|
|
|
126
|
|
|
), |
127
|
|
|
'show_in_shortcode' => true, |
128
|
|
|
), |
129
|
|
|
'sort_direction' => array( |
130
|
7 |
|
'label' => __('Sort direction', 'gravityview'), |
|
|
|
|
131
|
7 |
|
'type' => 'select', |
132
|
7 |
|
'value' => 'ASC', |
133
|
7 |
|
'group' => 'sort', |
134
|
|
|
'options' => array( |
135
|
7 |
|
'ASC' => __('ASC', 'gravityview'), |
|
|
|
|
136
|
7 |
|
'DESC' => __('DESC', 'gravityview'), |
|
|
|
|
137
|
|
|
), |
138
|
|
|
'show_in_shortcode' => true, |
139
|
|
|
), |
140
|
|
|
'sort_columns' => array( |
141
|
7 |
|
'label' => __( 'Enable sorting by column', 'gravityview' ), |
142
|
7 |
|
'left_label' => __( 'Column Sorting', 'gravityview' ), |
143
|
7 |
|
'type' => 'checkbox', |
144
|
|
|
'value' => false, |
145
|
7 |
|
'group' => 'sort', |
146
|
|
|
'tooltip' => NULL, |
|
|
|
|
147
|
|
|
'show_in_shortcode' => true, |
148
|
|
|
'show_in_template' => array( 'default_table', 'preset_business_data', 'preset_issue_tracker', 'preset_resume_board', 'preset_job_board' ), |
149
|
|
|
), |
150
|
|
|
'start_date' => array( |
151
|
7 |
|
'label' => __('Filter by Start Date', 'gravityview'), |
|
|
|
|
152
|
7 |
|
'class' => 'gv-datepicker', |
153
|
7 |
|
'desc' => __('Show entries submitted after this date. Supports relative dates, such as "-1 week" or "-1 month".', 'gravityview' ), |
|
|
|
|
154
|
7 |
|
'type' => 'text', |
155
|
7 |
|
'value' => '', |
156
|
7 |
|
'group' => 'filter', |
157
|
|
|
'show_in_shortcode' => true, |
158
|
|
|
), |
159
|
|
|
'end_date' => array( |
160
|
7 |
|
'label' => __('Filter by End Date', 'gravityview'), |
|
|
|
|
161
|
7 |
|
'class' => 'gv-datepicker', |
162
|
7 |
|
'desc' => __('Show entries submitted before this date. Supports relative dates, such as "now" or "-3 days".', 'gravityview' ), |
|
|
|
|
163
|
7 |
|
'type' => 'text', |
164
|
7 |
|
'value' => '', |
165
|
7 |
|
'group' => 'filter', |
166
|
|
|
'show_in_shortcode' => true, |
167
|
|
|
), |
168
|
|
|
'class' => array( |
169
|
7 |
|
'label' => __('CSS Class', 'gravityview'), |
|
|
|
|
170
|
7 |
|
'desc' => __('CSS class to add to the wrapping HTML container.', 'gravityview'), |
|
|
|
|
171
|
7 |
|
'group' => 'default', |
172
|
7 |
|
'type' => 'text', |
173
|
7 |
|
'value' => '', |
174
|
|
|
'show_in_shortcode' => false, |
175
|
|
|
), |
176
|
|
|
'search_value' => array( |
177
|
7 |
|
'label' => __('Search Value', 'gravityview'), |
|
|
|
|
178
|
7 |
|
'desc' => __('Define a default search value for the View', 'gravityview'), |
|
|
|
|
179
|
7 |
|
'type' => 'text', |
180
|
7 |
|
'value' => '', |
181
|
7 |
|
'group' => 'filter', |
182
|
|
|
'show_in_shortcode' => false, |
183
|
|
|
), |
184
|
|
|
'search_field' => array( |
185
|
7 |
|
'label' => __('Search Field', 'gravityview'), |
|
|
|
|
186
|
7 |
|
'desc' => __('If Search Value is set, you can define a specific field to search in. Otherwise, all fields will be searched.', 'gravityview'), |
|
|
|
|
187
|
7 |
|
'type' => 'number', |
188
|
7 |
|
'value' => '', |
189
|
7 |
|
'group' => 'filter', |
190
|
|
|
'show_in_shortcode' => false, |
191
|
|
|
), |
192
|
|
|
'single_title' => array( |
193
|
7 |
|
'label' => __('Single Entry Title', 'gravityview'), |
|
|
|
|
194
|
7 |
|
'type' => 'text', |
195
|
7 |
|
'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'), |
|
|
|
|
196
|
7 |
|
'group' => 'default', |
197
|
7 |
|
'value' => '', |
198
|
|
|
'show_in_shortcode' => false, |
199
|
|
|
'full_width' => true, |
200
|
|
|
), |
201
|
|
|
'back_link_label' => array( |
202
|
7 |
|
'label' => __('Back Link Label', 'gravityview'), |
|
|
|
|
203
|
7 |
|
'group' => 'default', |
204
|
7 |
|
'desc' => __('The text of the link that returns to the multiple entries view.', 'gravityview'), |
|
|
|
|
205
|
7 |
|
'type' => 'text', |
206
|
7 |
|
'value' => '', |
207
|
|
|
'show_in_shortcode' => false, |
208
|
|
|
'full_width' => true, |
209
|
|
|
), |
210
|
|
|
'embed_only' => array( |
211
|
7 |
|
'label' => __('Prevent Direct Access', 'gravityview'), |
|
|
|
|
212
|
7 |
|
'group' => 'default', |
213
|
7 |
|
'desc' => __('Only allow access to this View when embedded using the shortcode.', 'gravityview'), |
|
|
|
|
214
|
7 |
|
'type' => 'checkbox', |
215
|
7 |
|
'value' => '', |
216
|
|
|
'tooltip' => false, |
217
|
|
|
'show_in_shortcode' => false, |
218
|
|
|
'full_width' => true, |
219
|
|
|
), |
220
|
|
|
'post_id' => array( |
221
|
|
|
'type' => 'number', |
222
|
|
|
'value' => '', |
223
|
|
|
'show_in_shortcode' => false, |
224
|
|
|
), |
225
|
|
|
); |
226
|
|
|
|
227
|
7 |
|
if ( version_compare( \GFCommon::$version, '2.3-beta-4', '>=' ) ) { |
228
|
|
|
$default_settings['sort_direction']['options']['RAND'] = __( 'Random', 'gravityview' ); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* @filter `gravityview_default_args` Modify the default settings for new Views |
233
|
|
|
* @param[in,out] array $default_args Array of default args. |
234
|
|
|
* @deprecated |
235
|
|
|
* @see filter `gravityview/view/settings/defaults` |
236
|
|
|
*/ |
237
|
7 |
|
$default_settings = apply_filters( 'gravityview_default_args', $default_settings ); |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @filter `gravityview/view/defaults` Modify the default settings for new Views |
241
|
|
|
* @param[in,out] array $default_settings Array of default settings. |
242
|
|
|
*/ |
243
|
7 |
|
$default_settings = apply_filters( 'gravityview/view/settings/defaults', $default_settings ); |
244
|
|
|
|
245
|
|
|
// By default, we only want the key => value pairing, not the whole array. |
246
|
7 |
|
if ( ! $detailed ) { |
247
|
7 |
|
$defaults = array(); |
248
|
7 |
|
foreach( $default_settings as $key => $value ) { |
249
|
7 |
|
$defaults[ $key ] = $value['value']; |
250
|
|
|
} |
251
|
7 |
|
return $defaults; |
252
|
|
|
|
253
|
|
|
// But sometimes, we want all the details. |
254
|
|
|
} else { |
255
|
1 |
|
foreach ($default_settings as $key => $value) { |
|
|
|
|
256
|
|
|
|
257
|
|
|
// If the $group argument is set for the method, |
258
|
|
|
// ignore any settings that aren't in that group. |
259
|
1 |
|
if ( ! empty( $group ) && is_string( $group ) ) { |
260
|
1 |
|
if ( empty( $value['group'] ) || $value['group'] !== $group ) { |
261
|
1 |
|
unset( $default_settings[ $key ] ); |
262
|
|
|
} |
263
|
|
|
} |
264
|
|
|
} |
265
|
1 |
|
return $default_settings; |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Mass update values from the allowed ones. |
271
|
|
|
* |
272
|
|
|
* @api |
273
|
|
|
* @since future |
274
|
|
|
* |
275
|
|
|
* @param array An array of settings to update. |
276
|
|
|
* @return void |
277
|
|
|
*/ |
278
|
4 |
|
public function update( $settings ) { |
279
|
4 |
|
foreach ( $settings as $key => $value ) { |
280
|
4 |
|
$this->set( $key, $value ); |
281
|
|
|
} |
282
|
4 |
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Turn to an $atts array as used around the old codebase. |
286
|
|
|
* |
287
|
|
|
* @internal |
288
|
|
|
* @deprecated |
289
|
|
|
* |
290
|
|
|
* @return array |
291
|
|
|
*/ |
292
|
1 |
|
public function as_atts() { |
293
|
1 |
|
$defaults = array_keys( self::defaults() ); |
294
|
1 |
|
$_this = &$this; |
295
|
1 |
|
return array_combine( $defaults, array_map( function( $key ) use ( $_this ) { |
296
|
1 |
|
return $_this->get( $key ); |
297
|
1 |
|
}, $defaults ) ); |
298
|
|
|
} |
299
|
|
|
} |
300
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.