1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Renders all the metaboxes on Add New / Edit View post type. |
4
|
|
|
* |
5
|
|
|
* @package GravityView |
6
|
|
|
* @license GPL2+ |
7
|
|
|
* @author Katz Web Services, Inc. |
8
|
|
|
* @link http://gravityview.co |
9
|
|
|
* @copyright Copyright 2014, Katz Web Services, Inc. |
10
|
|
|
* |
11
|
|
|
* @since 1.0.0 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/** If this file is called directly, abort. */ |
15
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
16
|
|
|
die; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
class GravityView_Admin_Views { |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
|
23
|
|
|
function __construct() { |
|
|
|
|
24
|
|
|
|
25
|
|
|
add_action( 'save_post', array( $this, 'save_postdata' ) ); |
26
|
|
|
|
27
|
|
|
// set the blacklist field types across the entire plugin |
28
|
|
|
add_filter( 'gravityview_blacklist_field_types', array( $this, 'default_field_blacklist' ), 10, 2 ); |
29
|
|
|
|
30
|
|
|
// Tooltips |
31
|
|
|
add_filter( 'gform_tooltips', array( $this, 'tooltips') ); |
|
|
|
|
32
|
|
|
|
33
|
|
|
// adding styles and scripts |
34
|
|
|
add_action( 'admin_enqueue_scripts', array( 'GravityView_Admin_Views', 'add_scripts_and_styles'), 999 ); |
|
|
|
|
35
|
|
|
add_filter( 'gform_noconflict_styles', array( $this, 'register_no_conflict') ); |
|
|
|
|
36
|
|
|
add_filter( 'gform_noconflict_scripts', array( $this, 'register_no_conflict') ); |
|
|
|
|
37
|
|
|
add_filter( 'gravityview_noconflict_styles', array( $this, 'register_no_conflict') ); |
|
|
|
|
38
|
|
|
add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_no_conflict') ); |
|
|
|
|
39
|
|
|
|
40
|
|
|
add_action( 'gravityview_render_directory_active_areas', array( $this, 'render_directory_active_areas'), 10, 4 ); |
|
|
|
|
41
|
|
|
add_action( 'gravityview_render_widgets_active_areas', array( $this, 'render_widgets_active_areas'), 10, 3 ); |
|
|
|
|
42
|
|
|
add_action( 'gravityview_render_available_fields', array( $this, 'render_available_fields'), 10, 2 ); |
|
|
|
|
43
|
|
|
add_action( 'gravityview_render_available_widgets', array( $this, 'render_available_widgets') ); |
|
|
|
|
44
|
|
|
add_action( 'gravityview_render_active_areas', array( $this, 'render_active_areas'), 10, 5 ); |
|
|
|
|
45
|
|
|
|
46
|
|
|
// @todo check if this hook is needed.. |
47
|
|
|
//add_action( 'gravityview_render_field_options', array( $this, 'render_field_options'), 10, 9 ); |
|
|
|
|
48
|
|
|
|
49
|
|
|
// Add Connected Form column |
50
|
|
|
add_filter('manage_gravityview_posts_columns' , array( $this, 'add_post_type_columns' ) ); |
|
|
|
|
51
|
|
|
|
52
|
|
|
add_filter( 'gform_toolbar_menu', array( 'GravityView_Admin_Views', 'gform_toolbar_menu' ), 10, 2 ); |
53
|
|
|
|
54
|
|
|
add_action( 'manage_gravityview_posts_custom_column', array( $this, 'add_custom_column_content'), 10, 2 ); |
|
|
|
|
55
|
|
|
|
56
|
|
|
add_action( 'restrict_manage_posts', array( $this, 'add_view_dropdown' ) ); |
57
|
|
|
|
58
|
|
|
add_action( 'pre_get_posts', array( $this, 'filter_pre_get_posts_by_gravityview_form_id' ) ); |
59
|
|
|
|
60
|
|
|
add_filter( 'gravityview/support_port/localization_data', array( $this, 'suggest_support_articles' ) ); |
61
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* When on the Add/Edit View screen, suggest most popular articles related to that |
66
|
|
|
* |
67
|
|
|
* @param array $localization_data Data to be passed to the Support Port JS |
68
|
|
|
* |
69
|
|
|
* @return array |
70
|
|
|
*/ |
71
|
|
|
function suggest_support_articles( $localization_data = array() ) { |
|
|
|
|
72
|
|
|
|
73
|
|
|
if( ! gravityview()->request->is_view() ) { |
74
|
|
|
return $localization_data; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$localization_data['suggest'] = array( |
78
|
|
|
'57ef23539033602e61d4a560', |
79
|
|
|
'54c67bb9e4b0512429885513', |
80
|
|
|
'54c67bb9e4b0512429885512', |
81
|
|
|
'54c67bbbe4b07997ea3f3f6b', |
82
|
|
|
'54d1a33ae4b086c0c0964ce9', |
83
|
|
|
'57ef253c9033602e61d4a563', |
84
|
|
|
'552355bfe4b0221aadf2572b', |
85
|
|
|
'54c67bcde4b051242988553e', |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
return $localization_data; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @since 1.15 |
93
|
|
|
* @param WP_Query $query |
94
|
|
|
*/ |
95
|
|
|
public function filter_pre_get_posts_by_gravityview_form_id( &$query ) { |
96
|
|
|
global $pagenow; |
|
|
|
|
97
|
|
|
|
98
|
|
|
if ( !is_admin() ) { |
|
|
|
|
99
|
|
|
return; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$form_id = isset( $_GET['gravityview_form_id'] ) ? (int) $_GET['gravityview_form_id'] : false; |
|
|
|
|
103
|
|
|
|
104
|
|
|
if( 'edit.php' !== $pagenow || ! $form_id || ! isset( $query->query_vars[ 'post_type' ] ) ) { |
|
|
|
|
105
|
|
|
return; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if ( $query->query_vars[ 'post_type' ] == 'gravityview' ) { |
|
|
|
|
109
|
|
|
$query->set( 'meta_query', array( |
110
|
|
|
array( |
111
|
|
|
'key' => '_gravityview_form_id', |
112
|
|
|
'value' => $form_id, |
113
|
|
|
) |
|
|
|
|
114
|
|
|
) ); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
function add_view_dropdown() { |
|
|
|
|
119
|
|
|
$current_screen = get_current_screen(); |
120
|
|
|
|
121
|
|
|
if( 'gravityview' !== $current_screen->post_type ) { |
122
|
|
|
return; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$forms = gravityview_get_forms(); |
126
|
|
|
$current_form = \GV\Utils::_GET( 'gravityview_form_id' ); |
127
|
|
|
// If there are no forms to select, show no forms. |
128
|
|
|
if( !empty( $forms ) ) { ?> |
|
|
|
|
129
|
|
|
<select name="gravityview_form_id" id="gravityview_form_id"> |
130
|
|
|
<option value="" <?php selected( '', $current_form, true ); ?>><?php esc_html_e( 'All forms', 'gravityview' ); ?></option> |
131
|
|
|
<?php foreach( $forms as $form ) { ?> |
132
|
|
|
<option value="<?php echo $form['id']; ?>" <?php selected( $form['id'], $current_form, true ); ?>><?php echo esc_html( $form['title'] ); ?></option> |
|
|
|
|
133
|
|
|
<?php } ?> |
134
|
|
|
</select> |
135
|
|
|
<?php } |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @deprecated since 1.2 |
141
|
|
|
* Start using GravityView_Render_Settings::render_setting_row |
142
|
|
|
*/ |
143
|
|
|
public static function render_setting_row( $key = '', $current_settings = array(), $override_input = null, $name = 'template_settings[%s]', $id = 'gravityview_se_%s' ) { |
144
|
|
|
_deprecated_function( 'GravityView_Admin_Views::render_setting_row', '1.1.7', 'GravityView_Render_Settings::render_setting_row' ); |
145
|
|
|
GravityView_Render_Settings::render_setting_row( $key, $current_settings, $override_input, $name , $id ); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @deprecated since 1.2 |
150
|
|
|
* Start using GravityView_Render_Settings::render_field_option |
151
|
|
|
*/ |
152
|
|
|
public static function render_field_option( $name = '', $option, $curr_value = NULL ) { |
|
|
|
|
153
|
|
|
_deprecated_function( 'GravityView_Admin_Views::render_field_option', '1.1.7', 'GravityView_Render_Settings::render_field_option' ); |
154
|
|
|
return GravityView_Render_Settings::render_field_option( $name, $option, $curr_value ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Add a GravityView menu to the Form Toolbar with connected views |
160
|
|
|
* @param array $menu_items Menu items, as set in GFForms::top_toolbar() |
161
|
|
|
* @param int $id ID of the current Gravity form |
162
|
|
|
* @return array Modified array |
163
|
|
|
*/ |
164
|
|
|
static function gform_toolbar_menu( $menu_items = array(), $id = NULL ) { |
|
|
|
|
165
|
|
|
|
166
|
|
|
$connected_views = gravityview_get_connected_views( $id, array( 'post_status' => 'any' ) ); |
167
|
|
|
|
168
|
|
|
if( empty( $connected_views ) ) { |
169
|
|
|
|
170
|
|
|
$menu_items['gravityview'] = array( |
171
|
|
|
'label' => esc_attr__( 'Create a View', 'gravityview' ), |
172
|
|
|
'icon' => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>', |
173
|
|
|
'title' => esc_attr__( 'Create a View using this form as a data source', 'gravityview' ), |
174
|
|
|
'url' => admin_url( 'post-new.php?post_type=gravityview&form_id=' . $id ), |
175
|
|
|
'menu_class' => 'gv_connected_forms gf_form_toolbar_settings', |
176
|
|
|
'priority' => 0, |
177
|
|
|
'capabilities' => array( 'edit_gravityviews' ), |
178
|
|
|
); |
179
|
|
|
|
180
|
|
|
return $menu_items; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
$sub_menu_items = array(); |
184
|
|
|
foreach ( (array)$connected_views as $view ) { |
|
|
|
|
185
|
|
|
|
186
|
|
|
if( ! GVCommon::has_cap( 'edit_gravityview', $view->ID ) ) { |
187
|
|
|
continue; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
$label = empty( $view->post_title ) ? sprintf( __('No Title (View #%d)', 'gravityview' ), $view->ID ) : $view->post_title; |
|
|
|
|
191
|
|
|
|
192
|
|
|
$sub_menu_items[] = array( |
193
|
|
|
'label' => esc_attr( $label ), |
194
|
|
|
'url' => admin_url( 'post.php?action=edit&post='.$view->ID ), |
195
|
|
|
); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
// If there were no items added, then let's create the parent menu |
199
|
|
|
if( $sub_menu_items ) { |
|
|
|
|
200
|
|
|
|
201
|
|
|
$sub_menu_items[] = array( |
202
|
|
|
'label' => esc_attr__( 'Create a View', 'gravityview' ), |
203
|
|
|
'link_class' => 'gv-create-view', |
204
|
|
|
'title' => esc_attr__( 'Create a View using this form as a data source', 'gravityview' ), |
205
|
|
|
'url' => admin_url( 'post-new.php?post_type=gravityview&form_id=' . $id ), |
206
|
|
|
'capabilities' => array( 'edit_gravityviews' ), |
207
|
|
|
); |
208
|
|
|
|
209
|
|
|
// Make sure Gravity Forms uses the submenu; if there's only one item, it uses a link instead of a dropdown |
210
|
|
|
$sub_menu_items[] = array( |
211
|
|
|
'url' => '#', |
212
|
|
|
'label' => '', |
213
|
|
|
'menu_class' => 'hidden', |
214
|
|
|
'capabilities' => '', |
215
|
|
|
); |
216
|
|
|
|
217
|
|
|
$menu_items['gravityview'] = array( |
218
|
|
|
'label' => __( 'Connected Views', 'gravityview' ), |
219
|
|
|
'icon' => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>', |
220
|
|
|
'title' => __( 'GravityView Views using this form as a data source', 'gravityview' ), |
221
|
|
|
'url' => '#', |
222
|
|
|
'onclick' => 'return false;', |
223
|
|
|
'menu_class' => 'gv_connected_forms gf_form_toolbar_settings', |
224
|
|
|
'sub_menu_items' => $sub_menu_items, |
225
|
|
|
'priority' => 0, |
226
|
|
|
'capabilities' => array( 'edit_gravityviews' ), |
227
|
|
|
); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
return $menu_items; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* List the field types without presentation properties (on a View context) |
235
|
|
|
* |
236
|
|
|
* @param array $array Existing field types to add to a blacklist |
237
|
|
|
* @param string|null $context Context for the blacklist. Default: NULL. |
238
|
|
|
* @access public |
239
|
|
|
* @return array Default blacklist fields merged with existing blacklist fields |
240
|
|
|
*/ |
241
|
|
|
function default_field_blacklist( $array = array(), $context = NULL ) { |
|
|
|
|
242
|
|
|
|
243
|
|
|
$add = array( 'captcha', 'page' ); |
244
|
|
|
|
245
|
|
|
// Don't allowing editing the following values: |
246
|
|
|
if( $context === 'edit' ) { |
|
|
|
|
247
|
|
|
$add[] = 'post_id'; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
$return = array_merge( $array, $add ); |
251
|
|
|
|
252
|
|
|
return $return; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Add tooltip text for use throughout the UI |
257
|
|
|
* @param array $tooltips Array of Gravity Forms tooltips |
258
|
|
|
* @return array Modified tooltips array |
259
|
|
|
*/ |
260
|
|
|
public function tooltips( $tooltips = array() ) { |
261
|
|
|
|
262
|
|
|
$gv_tooltips = array(); |
263
|
|
|
|
264
|
|
|
// Generate tooltips for View settings |
265
|
|
|
$default_args = \GV\View_Settings::defaults( true ); |
266
|
|
|
|
267
|
|
|
foreach ( $default_args as $key => $arg ) { |
268
|
|
|
|
269
|
|
|
// If an arg has `tooltip` defined, but it's false, don't display a tooltip |
270
|
|
|
if( isset( $arg['tooltip'] ) && empty( $arg['tooltip'] ) ) { continue; } |
271
|
|
|
|
272
|
|
|
// By default, use `tooltip` if defined. |
|
|
|
|
273
|
|
|
$tooltip = empty( $arg['tooltip'] ) ? NULL : $arg['tooltip']; |
|
|
|
|
274
|
|
|
|
275
|
|
|
// Otherwise, use the description as a tooltip. |
276
|
|
|
if( empty( $tooltip ) && !empty( $arg['desc'] ) ) { |
|
|
|
|
277
|
|
|
$tooltip = $arg['desc']; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
// If there's no tooltip set, continue |
281
|
|
|
if( empty( $tooltip ) ) { |
282
|
|
|
continue; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
// Add the tooltip |
286
|
|
|
$gv_tooltips[ 'gv_'.$key ] = array( |
287
|
|
|
'title' => $arg['label'], |
288
|
|
|
'value' => $tooltip, |
289
|
|
|
); |
290
|
|
|
|
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
$gv_tooltips['gv_css_merge_tags'] = array( |
294
|
|
|
'title' => __('CSS Merge Tags', 'gravityview'), |
|
|
|
|
295
|
|
|
'value' => sprintf( __( 'Developers: The CSS classes will be sanitized using the %ssanitize_title_with_dashes()%s function.', 'gravityview'), '<code>', '</code>' ) |
|
|
|
|
296
|
|
|
); |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @filter `gravityview_tooltips` The tooltips GravityView adds to the Gravity Forms tooltip array |
300
|
|
|
* @param array $gv_tooltips Associative array with unique keys containing array of `title` and `value` keys, as expected by `gform_tooltips` filter |
301
|
|
|
* @deprecated Renamed to `gravityview/metaboxes/tooltips` |
302
|
|
|
*/ |
303
|
|
|
$gv_tooltips = apply_filters( 'gravityview_tooltips', $gv_tooltips ); |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @filter `gravityview/metaboxes/tooltips` The tooltips GravityView adds to the Gravity Forms tooltip array |
307
|
|
|
* @param array $gv_tooltips Associative array with unique keys containing array of `title` and `value` keys, as expected by `gform_tooltips` filter |
308
|
|
|
*/ |
309
|
|
|
$gv_tooltips = apply_filters( 'gravityview/metaboxes/tooltips', $gv_tooltips ); |
310
|
|
|
|
311
|
|
|
foreach ( $gv_tooltips as $key => $tooltip ) { |
312
|
|
|
|
313
|
|
|
$title = empty( $tooltip['title'] ) ? '' : '<h6>'.esc_html( $tooltip['title'] ) .'</h6>'; |
314
|
|
|
|
315
|
|
|
$tooltips[ $key ] = $title . wpautop( esc_html( $tooltip['value'] ) ); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
return $tooltips; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Add the Data Source information |
323
|
|
|
* |
324
|
|
|
* @param null $column_name |
325
|
|
|
* @param $post_id |
326
|
|
|
* |
327
|
|
|
* @return void |
328
|
|
|
*/ |
329
|
|
|
public function add_custom_column_content( $column_name = NULL, $post_id ) { |
|
|
|
|
330
|
|
|
|
331
|
|
|
$output = ''; |
332
|
|
|
|
333
|
|
|
switch ( $column_name ) { |
334
|
|
|
case 'gv_template': |
335
|
|
|
|
336
|
|
|
$template_id = gravityview_get_template_id( $post_id ); |
337
|
|
|
|
338
|
|
|
// All Views should have a connected form. If it doesn't, that's not right. |
339
|
|
|
if ( empty( $template_id ) ) { |
340
|
|
|
gravityview()->log->error( 'View ID {view_id} does not have a connected template.', array( 'view_id' => $post_id ) ); |
341
|
|
|
break; |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
$templates = gravityview_get_registered_templates(); |
345
|
|
|
|
346
|
|
|
$template = isset( $templates[ $template_id ] ) ? $templates[ $template_id ] : false; |
347
|
|
|
|
348
|
|
|
// Generate backup if label doesn't exist: `example_name` => `Example Name` |
349
|
|
|
$template_id_pretty = ucwords( implode( ' ', explode( '_', $template_id ) ) ); |
350
|
|
|
|
351
|
|
|
$output = $template ? $template['label'] : $template_id_pretty; |
352
|
|
|
|
353
|
|
|
break; |
354
|
|
|
|
355
|
|
|
case 'gv_connected_form': |
356
|
|
|
|
357
|
|
|
$form_id = gravityview_get_form_id( $post_id ); |
358
|
|
|
|
359
|
|
|
// All Views should have a connected form. If it doesn't, that's not right. |
360
|
|
|
if ( empty( $form_id ) ) { |
361
|
|
|
gravityview()->log->error( 'View ID {view_id} does not have a connected GF form.', array( 'view_id' => $post_id ) ); |
362
|
|
|
$output = __( 'Not connected.', 'gravityview' ); |
363
|
|
|
break; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
$form = gravityview_get_form( $form_id ); |
367
|
|
|
|
368
|
|
|
if ( ! $form ) { |
369
|
|
|
gravityview()->log->error( 'Connected form not found: Form #{form_id}', array( 'form_id' => $form_id ) ); |
370
|
|
|
|
371
|
|
|
$output = __( 'The connected form can not be found; it may no longer exist.', 'gravityview' ); |
372
|
|
|
} else { |
373
|
|
|
$output = self::get_connected_form_links( $form ); |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
break; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
echo $output; |
|
|
|
|
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Get HTML links relating to a connected form, like Edit, Entries, Settings, Preview |
385
|
|
|
* @param array|int $form Gravity Forms forms array, or the form ID |
386
|
|
|
* @param boolean $include_form_link Whether to include the bold name of the form in the output |
387
|
|
|
* @return string HTML links |
388
|
|
|
*/ |
389
|
|
|
static public function get_connected_form_links( $form, $include_form_link = true ) { |
|
|
|
|
390
|
|
|
|
391
|
|
|
// Either the form is empty or the form ID is 0, not yet set. |
392
|
|
|
if( empty( $form ) ) { |
393
|
|
|
return ''; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
// The $form is passed as the form ID |
397
|
|
|
if( !is_array( $form ) ) { |
|
|
|
|
398
|
|
|
$form = gravityview_get_form( $form ); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
$form_id = $form['id']; |
402
|
|
|
$links = array(); |
403
|
|
|
|
404
|
|
|
if( GVCommon::has_cap( 'gravityforms_edit_forms' ) ) { |
405
|
|
|
$form_url = admin_url( sprintf( 'admin.php?page=gf_edit_forms&id=%d', $form_id ) ); |
406
|
|
|
$form_link = '<strong class="gv-form-title">'.gravityview_get_link( $form_url, $form['title'], 'class=row-title' ).'</strong>'; |
407
|
|
|
$links[] = '<span>'.gravityview_get_link( $form_url, __('Edit Form', 'gravityview') ).'</span>'; |
|
|
|
|
408
|
|
|
} else { |
409
|
|
|
$form_link = '<strong class="gv-form-title">'. esc_html( $form['title'] ). '</strong>'; |
410
|
|
|
} |
411
|
|
|
|
412
|
|
|
if( GVCommon::has_cap( 'gravityforms_view_entries' ) ) { |
413
|
|
|
$entries_url = admin_url( sprintf( 'admin.php?page=gf_entries&id=%d', $form_id ) ); |
414
|
|
|
$links[] = '<span>'.gravityview_get_link( $entries_url, __('Entries', 'gravityview') ).'</span>'; |
|
|
|
|
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
if( GVCommon::has_cap( array( 'gravityforms_edit_settings', 'gravityview_view_settings' ) ) ) { |
418
|
|
|
$settings_url = admin_url( sprintf( 'admin.php?page=gf_edit_forms&view=settings&id=%d', $form_id ) ); |
419
|
|
|
$links[] = '<span>'.gravityview_get_link( $settings_url, __('Settings', 'gravityview'), 'title='.__('Edit settings for this form', 'gravityview') ).'</span>'; |
|
|
|
|
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
if( GVCommon::has_cap( array("gravityforms_edit_forms", "gravityforms_create_form", "gravityforms_preview_forms") ) ) { |
|
|
|
|
423
|
|
|
$preview_url = site_url( sprintf( '?gf_page=preview&id=%d', $form_id ) ); |
424
|
|
|
$links[] = '<span>'.gravityview_get_link( $preview_url, __('Preview Form', 'gravityview'), 'title='.__('Preview this form', 'gravityview') ).'</span>'; |
|
|
|
|
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
$output = ''; |
428
|
|
|
|
429
|
|
|
if( !empty( $include_form_link ) ) { |
|
|
|
|
430
|
|
|
$output .= $form_link; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* @filter `gravityview_connected_form_links` Modify the links shown in the Connected Form links |
435
|
|
|
* @since 1.6 |
436
|
|
|
* @param array $links Links to show |
437
|
|
|
* @param array $form Gravity Forms form array |
438
|
|
|
*/ |
439
|
|
|
$links = apply_filters( 'gravityview_connected_form_links', $links, $form ); |
440
|
|
|
|
441
|
|
|
$output .= '<div class="row-actions">'. implode( ' | ', $links ) .'</div>'; |
442
|
|
|
|
443
|
|
|
return $output; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Add the Data Source column to the Views page |
448
|
|
|
* @param array $columns Columns array |
449
|
|
|
*/ |
450
|
|
|
public function add_post_type_columns( $columns ) { |
451
|
|
|
|
452
|
|
|
// Get the date column and save it for later to add back in. |
453
|
|
|
// This adds it after the Data Source column. |
454
|
|
|
// This way, we don't need to do array_slice, array_merge, etc. |
455
|
|
|
$date = $columns['date']; |
456
|
|
|
unset( $columns['date'] ); |
457
|
|
|
|
458
|
|
|
$data_source_required_caps = array( |
459
|
|
|
'gravityforms_edit_forms', |
460
|
|
|
'gravityforms_view_entries', |
461
|
|
|
'gravityforms_edit_settings', |
462
|
|
|
'gravityview_view_settings', |
463
|
|
|
'gravityforms_create_form', |
464
|
|
|
'gravityforms_preview_forms', |
465
|
|
|
); |
466
|
|
|
|
467
|
|
|
if( GVCommon::has_cap( $data_source_required_caps ) ) { |
468
|
|
|
$columns['gv_connected_form'] = __( 'Data Source', 'gravityview' ); |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
$columns['gv_template'] = _x( 'Template', 'Column title that shows what template is being used for Views', 'gravityview' ); |
472
|
|
|
|
473
|
|
|
// Add the date back in. |
474
|
|
|
$columns['date'] = $date; |
475
|
|
|
|
476
|
|
|
return $columns; |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
/** |
480
|
|
|
* Save View configuration |
481
|
|
|
* |
482
|
|
|
* @access public |
483
|
|
|
* @param int $post_id Currently saved Post ID |
484
|
|
|
* @return void |
485
|
|
|
*/ |
486
|
|
|
function save_postdata( $post_id ) { |
|
|
|
|
487
|
|
|
|
488
|
|
|
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){ |
489
|
|
|
return; |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
// validate post_type |
493
|
|
|
if ( ! isset( $_POST['post_type'] ) || 'gravityview' != $_POST['post_type'] ) { |
|
|
|
|
494
|
|
|
return; |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
// validate user can edit and save View |
498
|
|
|
if ( ! GVCommon::has_cap( 'edit_gravityview', $post_id ) ) { |
499
|
|
|
gravityview()->log->error( 'Current user does not have the capability to edit View {view_id}', array( 'view_id' => $post_id, 'data' => wp_get_current_user() ) ); |
500
|
|
|
return; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
gravityview()->log->debug( '[save_postdata] Saving View post type.', array( 'data' => $_POST ) ); |
|
|
|
|
504
|
|
|
|
505
|
|
|
$statii = array(); |
506
|
|
|
|
507
|
|
|
// check if this is a start fresh View |
508
|
|
|
if ( isset( $_POST['gravityview_select_form_nonce'] ) && wp_verify_nonce( $_POST['gravityview_select_form_nonce'], 'gravityview_select_form' ) ) { |
509
|
|
|
|
510
|
|
|
$form_id = !empty( $_POST['gravityview_form_id'] ) ? $_POST['gravityview_form_id'] : ''; |
|
|
|
|
511
|
|
|
// save form id |
512
|
|
|
$statii['form_id'] = update_post_meta( $post_id, '_gravityview_form_id', $form_id ); |
513
|
|
|
|
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
if( false === GVCommon::has_cap( 'gravityforms_create_form' ) && empty( $statii['form_id'] ) ) { |
517
|
|
|
gravityview()->log->error( 'Current user does not have the capability to create a new Form.', array( 'data' => wp_get_current_user() ) ); |
518
|
|
|
return; |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
// Was this a start fresh? |
522
|
|
|
if ( ! empty( $_POST['gravityview_form_id_start_fresh'] ) ) { |
523
|
|
|
$statii['start_fresh'] = add_post_meta( $post_id, '_gravityview_start_fresh', 1 ); |
524
|
|
|
} else { |
525
|
|
|
$statii['start_fresh'] = delete_post_meta( $post_id, '_gravityview_start_fresh' ); |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
// Check if we have a template id |
529
|
|
|
if ( isset( $_POST['gravityview_select_template_nonce'] ) && wp_verify_nonce( $_POST['gravityview_select_template_nonce'], 'gravityview_select_template' ) ) { |
530
|
|
|
|
531
|
|
|
$template_id = !empty( $_POST['gravityview_directory_template'] ) ? $_POST['gravityview_directory_template'] : ''; |
|
|
|
|
532
|
|
|
|
533
|
|
|
// now save template id |
534
|
|
|
$statii['directory_template'] = update_post_meta( $post_id, '_gravityview_directory_template', $template_id ); |
535
|
|
|
} |
536
|
|
|
|
|
|
|
|
537
|
|
|
|
538
|
|
|
// save View Configuration metabox |
539
|
|
|
if ( isset( $_POST['gravityview_view_configuration_nonce'] ) && wp_verify_nonce( $_POST['gravityview_view_configuration_nonce'], 'gravityview_view_configuration' ) ) { |
540
|
|
|
|
541
|
|
|
// template settings |
542
|
|
|
if( empty( $_POST['template_settings'] ) ) { |
543
|
|
|
$_POST['template_settings'] = array(); |
544
|
|
|
} |
545
|
|
|
$statii['template_settings'] = update_post_meta( $post_id, '_gravityview_template_settings', $_POST['template_settings'] ); |
|
|
|
|
546
|
|
|
|
547
|
|
|
$fields = array(); |
548
|
|
|
|
549
|
|
|
// Directory&single Visible Fields |
550
|
|
|
if( !empty( $preset_fields ) ) { |
|
|
|
|
551
|
|
|
|
552
|
|
|
$fields = $preset_fields; |
553
|
|
|
|
554
|
|
|
} elseif( !empty( $_POST['gv_fields'] ) ) { |
|
|
|
|
555
|
|
|
$fields = _gravityview_process_posted_fields(); |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
$statii['directory_fields'] = update_post_meta( $post_id, '_gravityview_directory_fields', $fields ); |
559
|
|
|
|
560
|
|
|
// Directory Visible Widgets |
561
|
|
|
if( empty( $_POST['widgets'] ) ) { |
562
|
|
|
$_POST['widgets'] = array(); |
563
|
|
|
} |
564
|
|
|
$statii['directory_widgets'] = gravityview_set_directory_widgets( $post_id, $_POST['widgets'] ); |
|
|
|
|
565
|
|
|
|
566
|
|
|
} // end save view configuration |
567
|
|
|
|
568
|
|
|
/** |
569
|
|
|
* @action `gravityview_view_saved` After a View has been saved in the admin |
570
|
|
|
* @param int $post_id ID of the View that has been saved |
571
|
|
|
* @param array $statii Array of statuses of the post meta saving processes. If saving worked, each key should be mapped to a value of the post ID (`directory_widgets` => `124`). If failed (or didn't change), the value will be false. |
572
|
|
|
* @since 1.17.2 |
573
|
|
|
*/ |
574
|
|
|
do_action('gravityview_view_saved', $post_id, $statii ); |
|
|
|
|
575
|
|
|
|
576
|
|
|
gravityview()->log->debug( '[save_postdata] Update Post Meta Statuses (also returns false if nothing changed)', array( 'data' => array_map( 'intval', $statii ) ) ); |
577
|
|
|
} |
578
|
|
|
|
579
|
|
|
/** |
580
|
|
|
* @deprecated 1.1.6 |
581
|
|
|
*/ |
582
|
|
|
function render_label() { |
|
|
|
|
583
|
|
|
_deprecated_function( 'GravityView_Admin_Views::render_label()', '1.1.6', 'Use the GravityView_Admin_View_Field class instead.' ); |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* Render html for displaying available fields based on a Form ID |
588
|
|
|
* $blacklist_field_types - contains the field types which are not proper to be shown in a directory. |
589
|
|
|
* |
590
|
|
|
* @see GravityView_Ajax::get_available_fields_html() Triggers `gravityview_render_available_fields` action |
591
|
|
|
* @access public |
592
|
|
|
* |
593
|
|
|
* @param int $form Gravity Forms Form ID (default: '') |
594
|
|
|
* @param string $context (default: 'single') |
595
|
|
|
* |
596
|
|
|
* @return void |
597
|
|
|
*/ |
598
|
|
|
function render_available_fields( $form = 0, $context = 'single' ) { |
|
|
|
|
599
|
|
|
|
600
|
|
|
/** |
601
|
|
|
* @filter `gravityview_blacklist_field_types` Modify the types of fields that shouldn't be shown in a View. |
602
|
|
|
* @param[in,out] array $blacklist_field_types Array of field types to block for this context. |
603
|
|
|
* @param[in] string $context View context ('single', 'directory', or 'edit') |
604
|
|
|
*/ |
605
|
|
|
$blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', array(), $context ); |
606
|
|
|
|
607
|
|
|
if ( ! is_array( $blacklist_field_types ) ) { |
608
|
|
|
|
609
|
|
|
gravityview()->log->error( '$blacklist_field_types is not an array', array( 'data' => print_r( $blacklist_field_types, true ) ) ); |
|
|
|
|
610
|
|
|
|
611
|
|
|
$blacklist_field_types = array(); |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
$fields = $this->get_available_fields( $form, $context ); |
615
|
|
|
|
616
|
|
|
$output = ''; |
617
|
|
|
|
618
|
|
|
if( !empty( $fields ) ) { |
|
|
|
|
619
|
|
|
|
620
|
|
|
foreach( $fields as $id => $details ) { |
621
|
|
|
|
622
|
|
|
if( in_array( $details['type'], (array) $blacklist_field_types ) ) { |
623
|
|
|
continue; |
624
|
|
|
} |
625
|
|
|
|
626
|
|
|
// Edit mode only allows editing the parent fields, not single inputs. |
627
|
|
|
if( $context === 'edit' && !empty( $details['parent'] ) ) { |
|
|
|
|
628
|
|
|
continue; |
629
|
|
|
} |
630
|
|
|
|
631
|
|
|
$output .= new GravityView_Admin_View_Field( $details['label'], $id, $details ); |
632
|
|
|
|
633
|
|
|
} // End foreach |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
echo $output; |
|
|
|
|
637
|
|
|
|
638
|
|
|
// For the EDIT view we only want to allow the form fields. |
639
|
|
|
if( $context === 'edit' ) { |
|
|
|
|
640
|
|
|
return; |
641
|
|
|
} |
642
|
|
|
|
643
|
|
|
$this->render_additional_fields( $form, $context ); |
644
|
|
|
} |
645
|
|
|
|
646
|
|
|
/** |
647
|
|
|
* Render html for displaying additional fields based on a Form ID |
648
|
|
|
* |
649
|
|
|
* @access public |
650
|
|
|
* @param int $form Gravity Forms Form ID (default: '') |
651
|
|
|
* @param string $context (default: 'single') |
652
|
|
|
* @return void |
653
|
|
|
*/ |
654
|
|
|
public function render_additional_fields( $form = 0, $context = 'single' ) { |
|
|
|
|
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* @filter `gravityview_additional_fields` non-standard Fields to show at the bottom of the field picker |
658
|
|
|
* @param array $additional_fields Associative array of field arrays, with `label_text`, `desc`, `field_id`, `label_type`, `input_type`, `field_options`, and `settings_html` keys |
659
|
|
|
*/ |
660
|
|
|
$additional_fields = apply_filters( 'gravityview_additional_fields', array( |
661
|
|
|
array( |
662
|
|
|
'label_text' => __( '+ Add All Fields', 'gravityview' ), |
663
|
|
|
'desc' => __('Add all the available fields at once.', 'gravityview'), |
|
|
|
|
664
|
|
|
'field_id' => 'all-fields', |
665
|
|
|
'label_type' => 'field', |
666
|
|
|
'input_type' => NULL, |
|
|
|
|
667
|
|
|
'field_options' => NULL, |
|
|
|
|
668
|
|
|
'settings_html' => NULL, |
|
|
|
|
669
|
|
|
) |
|
|
|
|
670
|
|
|
)); |
671
|
|
|
|
672
|
|
|
if( !empty( $additional_fields )) { |
|
|
|
|
673
|
|
|
foreach ( (array)$additional_fields as $item ) { |
|
|
|
|
674
|
|
|
|
675
|
|
|
// Prevent items from not having index set |
676
|
|
|
$item = wp_parse_args( $item, array( |
677
|
|
|
'label_text' => NULL, |
|
|
|
|
678
|
|
|
'field_id' => NULL, |
|
|
|
|
679
|
|
|
'label_type' => NULL, |
|
|
|
|
680
|
|
|
'input_type' => NULL, |
|
|
|
|
681
|
|
|
'field_options' => NULL, |
|
|
|
|
682
|
|
|
'settings_html' => NULL, |
|
|
|
|
683
|
|
|
)); |
684
|
|
|
|
685
|
|
|
// Backward compat. |
686
|
|
|
if( !empty( $item['field_options'] ) ) { |
|
|
|
|
687
|
|
|
// Use settings_html from now on. |
688
|
|
|
$item['settings_html'] = $item['field_options']; |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
// Render a label for each of them |
692
|
|
|
echo new GravityView_Admin_View_Field( $item['label_text'], $item['field_id'], $item ); |
|
|
|
|
693
|
|
|
|
694
|
|
|
} |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
/** |
700
|
|
|
* Retrieve the default fields id, label and type |
701
|
|
|
* @param string|array $form form_ID or form object |
702
|
|
|
* @param string $zone Either 'single', 'directory', 'header', 'footer' |
703
|
|
|
* @return array |
704
|
|
|
*/ |
705
|
|
|
function get_entry_default_fields($form, $zone) { |
|
|
|
|
706
|
|
|
|
707
|
|
|
$entry_default_fields = array(); |
708
|
|
|
|
709
|
|
|
if( in_array( $zone, array( 'directory', 'single' ) ) ) { |
710
|
|
|
|
711
|
|
|
$entry_default_fields = array( |
712
|
|
|
'id' => array( |
713
|
|
|
'label' => __('Entry ID', 'gravityview'), |
|
|
|
|
714
|
|
|
'type' => 'id', |
715
|
|
|
'desc' => __('The unique ID of the entry.', 'gravityview'), |
|
|
|
|
716
|
|
|
), |
717
|
|
|
'date_created' => array( |
718
|
|
|
'label' => __('Entry Date', 'gravityview'), |
|
|
|
|
719
|
|
|
'desc' => __('The date the entry was created.', 'gravityview'), |
|
|
|
|
720
|
|
|
'type' => 'date_created', |
721
|
|
|
), |
722
|
|
|
'source_url' => array( |
723
|
|
|
'label' => __('Source URL', 'gravityview'), |
|
|
|
|
724
|
|
|
'type' => 'source_url', |
725
|
|
|
'desc' => __('The URL of the page where the form was submitted.', 'gravityview'), |
|
|
|
|
726
|
|
|
), |
727
|
|
|
'ip' => array( |
728
|
|
|
'label' => __('User IP', 'gravityview'), |
|
|
|
|
729
|
|
|
'type' => 'ip', |
730
|
|
|
'desc' => __('The IP Address of the user who created the entry.', 'gravityview'), |
|
|
|
|
731
|
|
|
), |
732
|
|
|
'created_by' => array( |
733
|
|
|
'label' => __('User', 'gravityview'), |
|
|
|
|
734
|
|
|
'type' => 'created_by', |
735
|
|
|
'desc' => __('Details of the logged-in user who created the entry (if any).', 'gravityview'), |
|
|
|
|
736
|
|
|
), |
737
|
|
|
|
738
|
|
|
/** |
739
|
|
|
* @since 1.7.2 |
740
|
|
|
*/ |
741
|
|
|
'other_entries' => array( |
742
|
|
|
'label' => __('Other Entries', 'gravityview'), |
|
|
|
|
743
|
|
|
'type' => 'other_entries', |
744
|
|
|
'desc' => __('Display other entries created by the entry creator.', 'gravityview'), |
|
|
|
|
745
|
|
|
), |
746
|
|
|
); |
747
|
|
|
|
748
|
|
|
if( 'single' !== $zone) { |
|
|
|
|
749
|
|
|
|
750
|
|
|
$entry_default_fields['entry_link'] = array( |
751
|
|
|
'label' => __('Link to Entry', 'gravityview'), |
|
|
|
|
752
|
|
|
'desc' => __('A dedicated link to the single entry with customizable text.', 'gravityview'), |
|
|
|
|
753
|
|
|
'type' => 'entry_link', |
754
|
|
|
); |
755
|
|
|
} |
756
|
|
|
|
757
|
|
|
} // if not zone directory or single |
758
|
|
|
|
759
|
|
|
/** |
760
|
|
|
* @since 1.2 |
761
|
|
|
*/ |
762
|
|
|
$entry_default_fields['custom'] = array( |
763
|
|
|
'label' => __('Custom Content', 'gravityview'), |
|
|
|
|
764
|
|
|
'type' => 'custom', |
765
|
|
|
'desc' => __('Insert custom text or HTML.', 'gravityview'), |
|
|
|
|
766
|
|
|
); |
767
|
|
|
|
768
|
|
|
/** |
769
|
|
|
* @filter `gravityview_entry_default_fields` Modify the default fields for each zone and context |
770
|
|
|
* @param array $entry_default_fields Array of fields shown by default |
771
|
|
|
* @param string|array $form form_ID or form object |
772
|
|
|
* @param string $zone Either 'single', 'directory', 'header', 'footer' |
773
|
|
|
*/ |
774
|
|
|
return apply_filters( 'gravityview_entry_default_fields', $entry_default_fields, $form, $zone); |
|
|
|
|
775
|
|
|
} |
776
|
|
|
|
777
|
|
|
/** |
778
|
|
|
* Calculate the available fields |
779
|
|
|
* @param string|array $form form_ID or form object |
780
|
|
|
* @param string $zone Either 'single', 'directory', 'header', 'footer' |
781
|
|
|
* @return array fields |
782
|
|
|
*/ |
783
|
|
|
function get_available_fields( $form = '', $zone = NULL ) { |
|
|
|
|
784
|
|
|
|
785
|
|
|
if( empty( $form ) ) { |
786
|
|
|
gravityview()->log->error( '$form is empty' ); |
787
|
|
|
return array(); |
788
|
|
|
} |
789
|
|
|
|
790
|
|
|
// get form fields |
791
|
|
|
$fields = gravityview_get_form_fields( $form, true ); |
792
|
|
|
|
793
|
|
|
// get meta fields ( only if form was already created ) |
794
|
|
|
if( !is_array( $form ) ) { |
|
|
|
|
795
|
|
|
$meta_fields = gravityview_get_entry_meta( $form ); |
796
|
|
|
} else { |
797
|
|
|
$meta_fields = array(); |
798
|
|
|
} |
799
|
|
|
|
800
|
|
|
// get default fields |
801
|
|
|
$default_fields = $this->get_entry_default_fields( $form, $zone ); |
802
|
|
|
|
803
|
|
|
//merge without loosing the keys |
804
|
|
|
$fields = $fields + $meta_fields + $default_fields; |
805
|
|
|
|
806
|
|
|
// Move Custom Content to top |
807
|
|
|
$fields = array( 'custom' => $fields['custom'] ) + $fields; |
808
|
|
|
|
809
|
|
|
return $fields; |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
|
813
|
|
|
/** |
814
|
|
|
* Render html for displaying available widgets |
815
|
|
|
* @return string html |
816
|
|
|
*/ |
817
|
|
|
function render_available_widgets() { |
|
|
|
|
818
|
|
|
|
819
|
|
|
$widgets = $this->get_registered_widgets(); |
|
|
|
|
820
|
|
|
|
821
|
|
|
if( !empty( $widgets ) ) { |
|
|
|
|
822
|
|
|
|
823
|
|
|
foreach( $widgets as $id => $details ) { |
824
|
|
|
|
825
|
|
|
echo new GravityView_Admin_View_Widget( $details['label'], $id, $details ); |
|
|
|
|
826
|
|
|
|
827
|
|
|
} |
828
|
|
|
} |
829
|
|
|
|
830
|
|
|
} |
831
|
|
|
|
832
|
|
|
/** |
833
|
|
|
* Get the list of registered widgets. Each item is used to instantiate a GravityView_Admin_View_Widget object |
834
|
|
|
* @deprecated Use \GV\Widget::registered() |
835
|
|
|
* @since 1.13.1 |
836
|
|
|
* @return array |
837
|
|
|
*/ |
838
|
|
|
function get_registered_widgets() { |
|
|
|
|
839
|
|
|
return \GV\Widget::registered(); |
840
|
|
|
} |
841
|
|
|
|
842
|
|
|
/** |
843
|
|
|
* Generic function to render rows and columns of active areas for widgets & fields |
844
|
|
|
* @param string $template_id The current slug of the selected View template |
845
|
|
|
* @param string $type Either 'widget' or 'field' |
846
|
|
|
* @param string $zone Either 'single', 'directory', 'header', 'footer' |
847
|
|
|
* @param array $rows The layout structure: rows, columns and areas |
848
|
|
|
* @param array $values Saved objects |
849
|
|
|
* @return void |
850
|
|
|
*/ |
851
|
|
|
function render_active_areas( $template_id, $type, $zone, $rows, $values ) { |
|
|
|
|
852
|
|
|
global $post; |
|
|
|
|
853
|
|
|
|
854
|
|
|
if( $type === 'widget' ) { |
|
|
|
|
855
|
|
|
$button_label = __( 'Add Widget', 'gravityview' ); |
856
|
|
|
} else { |
857
|
|
|
$button_label = __( 'Add Field', 'gravityview' ); |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
$available_items = array(); |
861
|
|
|
|
862
|
|
|
$view = \GV\View::from_post( $post ); |
863
|
|
|
|
864
|
|
|
// if saved values, get available fields to label everyone |
865
|
|
|
if( !empty( $values ) && ( !empty( $post->ID ) || !empty( $_POST['template_id'] ) ) ) { |
|
|
|
|
866
|
|
|
|
867
|
|
|
if( !empty( $_POST['template_id'] ) ) { |
|
|
|
|
868
|
|
|
$form = GravityView_Ajax::pre_get_form_fields( $_POST['template_id'] ); |
|
|
|
|
869
|
|
|
} else { |
870
|
|
|
$form = gravityview_get_form_id( $post->ID ); |
871
|
|
|
} |
872
|
|
|
|
873
|
|
|
if( 'field' === $type ) { |
874
|
|
|
$available_items = $this->get_available_fields( $form, $zone ); |
875
|
|
|
} else { |
876
|
|
|
$available_items = $this->get_registered_widgets(); |
|
|
|
|
877
|
|
|
} |
878
|
|
|
|
879
|
|
|
} |
880
|
|
|
|
881
|
|
|
foreach( $rows as $row ) : |
882
|
|
|
foreach( $row as $col => $areas ) : |
883
|
|
|
$column = ($col == '2-2') ? '1-2' : $col; ?> |
884
|
|
|
|
885
|
|
|
<div class="gv-grid-col-<?php echo esc_attr( $column ); ?>"> |
886
|
|
|
|
887
|
|
|
<?php foreach( $areas as $area ) : ?> |
888
|
|
|
|
889
|
|
|
<div class="gv-droppable-area"> |
890
|
|
|
<div class="active-drop active-drop-<?php echo esc_attr( $type ); ?>" data-areaid="<?php echo esc_attr( $zone .'_'. $area['areaid'] ); ?>"> |
891
|
|
|
|
892
|
|
|
<?php // render saved fields |
893
|
|
|
|
894
|
|
|
if( !empty( $values[ $zone .'_'. $area['areaid'] ] ) ) { |
|
|
|
|
895
|
|
|
|
896
|
|
|
foreach( $values[ $zone .'_'. $area['areaid'] ] as $uniqid => $field ) { |
897
|
|
|
|
898
|
|
|
$input_type = NULL; |
|
|
|
|
899
|
|
|
$original_item = isset( $available_items[ $field['id'] ] ) ? $available_items[ $field['id'] ] : false ; |
900
|
|
|
|
901
|
|
|
if( !$original_item ) { |
|
|
|
|
902
|
|
|
|
903
|
|
|
gravityview()->log->error( 'An item was not available when rendering the output; maybe it was added by a plugin that is now de-activated.', array(' data' => array('available_items' => $available_items, 'field' => $field ) ) ); |
|
|
|
|
904
|
|
|
|
905
|
|
|
$original_item = $field; |
906
|
|
|
} else { |
907
|
|
|
|
908
|
|
|
$input_type = isset( $original_item['type'] ) ? $original_item['type'] : NULL; |
|
|
|
|
909
|
|
|
|
910
|
|
|
} |
911
|
|
|
|
912
|
|
|
// Maybe has a form ID |
913
|
|
|
$form_id = empty( $field['form_id'] ) ? null : $field['form_id']; |
914
|
|
|
|
915
|
|
|
// Field options dialog box |
916
|
|
|
$field_options = GravityView_Render_Settings::render_field_options( $form_id, $type, $template_id, $field['id'], $original_item['label'], $zone .'_'. $area['areaid'], $input_type, $uniqid, $field, $zone, $original_item ); |
917
|
|
|
|
918
|
|
|
$item = array( |
919
|
|
|
'input_type' => $input_type, |
920
|
|
|
'settings_html' => $field_options, |
921
|
|
|
'label_type' => $type |
|
|
|
|
922
|
|
|
); |
923
|
|
|
|
924
|
|
|
// Merge the values with the current item to pass things like widget descriptions and original field names |
925
|
|
|
if( $original_item ) { |
926
|
|
|
$item = wp_parse_args( $item, $original_item ); |
927
|
|
|
} |
928
|
|
|
|
929
|
|
|
switch( $type ) { |
930
|
|
|
case 'widget': |
931
|
|
|
echo new GravityView_Admin_View_Widget( $item['label'], $field['id'], $item, $field ); |
|
|
|
|
932
|
|
|
break; |
933
|
|
|
default: |
934
|
|
|
echo new GravityView_Admin_View_Field( $item['label'], $field['id'], $item, $field ); |
|
|
|
|
935
|
|
|
} |
936
|
|
|
|
|
|
|
|
937
|
|
|
|
938
|
|
|
//endif; |
939
|
|
|
|
940
|
|
|
} |
941
|
|
|
|
942
|
|
|
} // End if zone is not empty ?> |
943
|
|
|
|
944
|
|
|
<span class="drop-message"><?php echo sprintf(esc_attr__('"+ %s" or drag existing %ss here.', 'gravityview'), $button_label, $type ); ?></span> |
|
|
|
|
945
|
|
|
</div> |
946
|
|
|
<div class="gv-droppable-area-action"> |
947
|
|
|
<a href="#" class="gv-add-field button-secondary" title="" data-objecttype="<?php echo esc_attr( $type ); ?>" data-areaid="<?php echo esc_attr( $zone .'_'. $area['areaid'] ); ?>" data-context="<?php echo esc_attr( $zone ); ?>" data-formid="<?php echo $view ? esc_attr( $view->form ? $view->form->ID : '' ) : ''; ?>"><?php echo '+ '.esc_html( $button_label ); ?></a> |
|
|
|
|
948
|
|
|
|
949
|
|
|
<p class="gv-droppable-area-title"><strong><?php echo esc_html( $area['title'] ); ?></strong><?php if( !empty( $area['subtitle'] ) ) { ?><span class="gv-droppable-area-subtitle"> – <?php echo esc_html( $area['subtitle'] ); ?></span><?php } ?></p> |
|
|
|
|
950
|
|
|
</div> |
951
|
|
|
</div> |
952
|
|
|
|
953
|
|
|
<?php endforeach; ?> |
954
|
|
|
|
955
|
|
|
</div> |
956
|
|
|
<?php endforeach; |
957
|
|
|
endforeach; |
958
|
|
|
} |
959
|
|
|
|
960
|
|
|
/** |
961
|
|
|
* Render the widget active areas |
962
|
|
|
* @param string $zone Either 'header' or 'footer' |
963
|
|
|
* @param string $post_id Current Post ID (view) |
964
|
|
|
* @return string html |
965
|
|
|
*/ |
966
|
|
|
function render_widgets_active_areas( $template_id = '', $zone, $post_id = '' ) { |
|
|
|
|
967
|
|
|
|
968
|
|
|
$default_widget_areas = GravityView_Widget::get_default_widget_areas(); |
969
|
|
|
|
970
|
|
|
$widgets = array(); |
971
|
|
|
if( !empty( $post_id ) ) { |
|
|
|
|
972
|
|
|
$widgets = gravityview_get_directory_widgets( $post_id ); |
973
|
|
|
} |
974
|
|
|
|
975
|
|
|
ob_start(); |
976
|
|
|
?> |
977
|
|
|
|
978
|
|
|
<div class="gv-grid gv-grid-pad gv-grid-border" id="directory-<?php echo $zone; ?>-widgets"> |
|
|
|
|
979
|
|
|
<?php $this->render_active_areas( $template_id, 'widget', $zone, $default_widget_areas, $widgets ); ?> |
980
|
|
|
</div> |
981
|
|
|
|
982
|
|
|
<?php |
983
|
|
|
$output = ob_get_clean(); |
984
|
|
|
|
985
|
|
|
echo $output; |
|
|
|
|
986
|
|
|
|
987
|
|
|
return $output; |
988
|
|
|
} |
989
|
|
|
|
990
|
|
|
/** |
991
|
|
|
* Render the Template Active Areas and configured active fields for a given template id and post id |
992
|
|
|
* |
993
|
|
|
* @access public |
994
|
|
|
* @param string $template_id (default: '') Template ID, like `default_list`, `default_table`, `preset_business_data`, etc. {@see GravityView_Template::__construct()} |
995
|
|
|
* @param string $post_id (default: '') |
996
|
|
|
* @param string $context (default: 'single') |
997
|
|
|
* @return string HTML of the active areas |
998
|
|
|
*/ |
999
|
|
|
function render_directory_active_areas( $template_id = '', $context = 'single', $post_id = '', $echo = false ) { |
|
|
|
|
1000
|
|
|
if( empty( $template_id ) ) { |
1001
|
|
|
gravityview()->log->debug( '[render_directory_active_areas] {template_id} is empty', array( 'template_id' => $template_id ) ); |
1002
|
|
|
return ''; |
1003
|
|
|
} |
1004
|
|
|
|
1005
|
|
|
/** |
1006
|
|
|
* @filter `gravityview_template_active_areas` |
1007
|
|
|
* @see GravityView_Template::assign_active_areas() |
1008
|
|
|
* @param array $template_areas Empty array, to be filled in by the template class |
1009
|
|
|
* @param string $template_id Template ID, like `default_list`, `default_table`, `preset_business_data`, etc. {@see GravityView_Template::__construct()} |
1010
|
|
|
* @param string $context Current View context: `directory`, `single`, or `edit` (default: 'single') |
1011
|
|
|
*/ |
1012
|
|
|
$template_areas = apply_filters( 'gravityview_template_active_areas', array(), $template_id, $context ); |
1013
|
|
|
|
1014
|
|
|
if( empty( $template_areas ) ) { |
1015
|
|
|
|
1016
|
|
|
gravityview()->log->debug( '[render_directory_active_areas] No areas defined. Maybe template {template_id} is disabled.', array( 'data' => $template_id ) ); |
1017
|
|
|
$output = '<div>'; |
1018
|
|
|
$output .= '<h2 class="description" style="font-size: 16px; margin:0">'. sprintf( esc_html__( 'This View is configured using the %s View type, which is disabled.', 'gravityview' ), '<em>'.$template_id.'</em>' ) .'</h2>'; |
1019
|
|
|
$output .= '<p class="description" style="font-size: 14px; margin:0 0 1em 0;padding:0">'.esc_html__('The data is not lost; re-activate the associated plugin and the configuration will re-appear.', 'gravityview').'</p>'; |
|
|
|
|
1020
|
|
|
$output .= '</div>'; |
1021
|
|
|
} else { |
1022
|
|
|
|
1023
|
|
|
$fields = ''; |
1024
|
|
|
if ( ! empty( $post_id ) ) { |
1025
|
|
|
$fields = gravityview_get_directory_fields( $post_id ); |
1026
|
|
|
} |
1027
|
|
|
|
1028
|
|
|
ob_start(); |
1029
|
|
|
$this->render_active_areas( $template_id, 'field', $context, $template_areas, $fields ); |
1030
|
|
|
$output = ob_get_clean(); |
1031
|
|
|
|
1032
|
|
|
} |
1033
|
|
|
|
1034
|
|
|
if( $echo ) { |
1035
|
|
|
echo $output; |
|
|
|
|
1036
|
|
|
} |
1037
|
|
|
|
1038
|
|
|
return $output; |
1039
|
|
|
} |
1040
|
|
|
|
1041
|
|
|
/** |
1042
|
|
|
* Enqueue scripts and styles at Views editor |
1043
|
|
|
* |
1044
|
|
|
* @access public |
1045
|
|
|
* @param mixed $hook |
1046
|
|
|
* @return void |
1047
|
|
|
*/ |
1048
|
|
|
static function add_scripts_and_styles( $hook ) { |
|
|
|
|
1049
|
|
|
global $plugin_page, $pagenow; |
|
|
|
|
1050
|
|
|
|
1051
|
|
|
$is_widgets_page = ( $pagenow === 'widgets.php' ); |
1052
|
|
|
|
1053
|
|
|
// Add the GV font (with the Astronaut) |
1054
|
|
|
wp_enqueue_style( 'gravityview_global', plugins_url('assets/css/admin-global.css', GRAVITYVIEW_FILE), array(), GravityView_Plugin::version ); |
|
|
|
|
1055
|
|
|
|
1056
|
|
|
wp_register_script( 'gravityview-jquery-cookie', plugins_url('assets/lib/jquery.cookie/jquery.cookie.min.js', GRAVITYVIEW_FILE), array( 'jquery' ), GravityView_Plugin::version, true ); |
|
|
|
|
1057
|
|
|
|
1058
|
|
|
// Don't process any scripts below here if it's not a GravityView page. |
1059
|
|
|
if( ! gravityview_is_admin_page( $hook, 'single' ) && ! $is_widgets_page ) { |
|
|
|
|
1060
|
|
|
return; |
1061
|
|
|
} |
1062
|
|
|
|
1063
|
|
|
wp_enqueue_script( 'jquery-ui-datepicker' ); |
1064
|
|
|
wp_enqueue_style( 'gravityview_views_datepicker', plugins_url('assets/css/admin-datepicker.css', GRAVITYVIEW_FILE), GravityView_Plugin::version ); |
|
|
|
|
1065
|
|
|
|
1066
|
|
|
$script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
|
|
|
1067
|
|
|
|
1068
|
|
|
//enqueue scripts |
1069
|
|
|
wp_enqueue_script( 'gravityview_views_scripts', plugins_url( 'assets/js/admin-views' . $script_debug . '.js', GRAVITYVIEW_FILE ), array( 'jquery-ui-tabs', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-sortable', 'jquery-ui-tooltip', 'jquery-ui-dialog', 'gravityview-jquery-cookie', 'jquery-ui-datepicker', 'underscore' ), GravityView_Plugin::version ); |
|
|
|
|
1070
|
|
|
|
1071
|
|
|
wp_localize_script('gravityview_views_scripts', 'gvGlobals', array( |
1072
|
|
|
'cookiepath' => COOKIEPATH, |
1073
|
|
|
'passed_form_id' => (bool) \GV\Utils::_GET( 'form_id' ), |
1074
|
|
|
'nonce' => wp_create_nonce( 'gravityview_ajaxviews' ), |
1075
|
|
|
'label_viewname' => __( 'Enter View name here', 'gravityview' ), |
1076
|
|
|
'label_close' => __( 'Close', 'gravityview' ), |
1077
|
|
|
'label_cancel' => __( 'Cancel', 'gravityview' ), |
1078
|
|
|
'label_continue' => __( 'Continue', 'gravityview' ), |
1079
|
|
|
'label_ok' => __( 'Ok', 'gravityview' ), |
1080
|
|
|
'label_publisherror' => __( 'Error while creating the View for you. Check the settings or contact GravityView support.', 'gravityview' ), |
1081
|
|
|
'loading_text' => esc_html__( 'Loading…', 'gravityview' ), |
1082
|
|
|
'loading_error' => esc_html__( 'There was an error loading dynamic content.', 'gravityview' ), |
1083
|
|
|
'field_loaderror' => __( 'Error while adding the field. Please try again or contact GravityView support.', 'gravityview' ), |
1084
|
|
|
'remove_all_fields' => __( 'Would you like to remove all fields in this zone? (You are seeing this message because you were holding down the ALT key)', 'gravityview' ), |
1085
|
|
|
)); |
1086
|
|
|
|
1087
|
|
|
wp_enqueue_style( 'gravityview_views_styles', plugins_url( 'assets/css/admin-views.css', GRAVITYVIEW_FILE ), array('dashicons', 'wp-jquery-ui-dialog' ), GravityView_Plugin::version ); |
|
|
|
|
1088
|
|
|
|
1089
|
|
|
// Enqueue scripts needed for merge tags |
1090
|
|
|
self::enqueue_gravity_forms_scripts(); |
1091
|
|
|
} |
1092
|
|
|
|
1093
|
|
|
/** |
1094
|
|
|
* Enqueue Gravity Forms scripts, needed for Merge Tags |
1095
|
|
|
* |
1096
|
|
|
* @since 1.0.5-beta |
1097
|
|
|
* |
1098
|
|
|
* @return void |
1099
|
|
|
*/ |
1100
|
|
|
static function enqueue_gravity_forms_scripts() { |
|
|
|
|
1101
|
|
|
GFForms::register_scripts(); |
1102
|
|
|
|
1103
|
|
|
$scripts = array( |
1104
|
|
|
'sack', |
1105
|
|
|
'gform_gravityforms', |
1106
|
|
|
'gform_forms', |
1107
|
|
|
'gform_form_admin', |
1108
|
|
|
'jquery-ui-autocomplete' |
|
|
|
|
1109
|
|
|
); |
1110
|
|
|
|
1111
|
|
|
if ( wp_is_mobile() ) { |
1112
|
|
|
$scripts[] = 'jquery-touch-punch'; |
1113
|
|
|
} |
1114
|
|
|
|
1115
|
|
|
wp_enqueue_script( $scripts ); |
1116
|
|
|
} |
1117
|
|
|
|
1118
|
|
|
/** |
1119
|
|
|
* Add GravityView scripts and styles to Gravity Forms and GravityView No-Conflict modes |
1120
|
|
|
* |
1121
|
|
|
* @param array $registered Existing scripts or styles that have been registered (array of the handles) |
1122
|
|
|
* |
1123
|
|
|
* @return array |
1124
|
|
|
*/ |
1125
|
|
|
function register_no_conflict( $registered ) { |
|
|
|
|
1126
|
|
|
|
1127
|
|
|
$allowed_dependencies = array(); |
1128
|
|
|
|
1129
|
|
|
$filter = current_filter(); |
1130
|
|
|
|
1131
|
|
|
if ( preg_match( '/script/ism', $filter ) ) { |
1132
|
|
|
|
1133
|
|
|
$allowed_dependencies = array( |
1134
|
|
|
'jquery-ui-core', |
1135
|
|
|
'jquery-ui-dialog', |
1136
|
|
|
'jquery-ui-tabs', |
1137
|
|
|
'jquery-ui-draggable', |
1138
|
|
|
'jquery-ui-droppable', |
1139
|
|
|
'jquery-ui-sortable', |
1140
|
|
|
'jquery-ui-tooltip', |
1141
|
|
|
'gravityview_views_scripts', |
1142
|
|
|
'gravityview-support', |
1143
|
|
|
'gravityview-jquery-cookie', |
1144
|
|
|
'gravityview_views_datepicker', |
1145
|
|
|
'sack', |
1146
|
|
|
'gform_gravityforms', |
1147
|
|
|
'gform_forms', |
1148
|
|
|
'gform_form_admin', |
1149
|
|
|
'jquery-ui-autocomplete' |
|
|
|
|
1150
|
|
|
); |
1151
|
|
|
|
1152
|
|
|
} elseif ( preg_match( '/style/ism', $filter ) ) { |
1153
|
|
|
|
1154
|
|
|
$allowed_dependencies = array( |
1155
|
|
|
'dashicons', |
1156
|
|
|
'wp-jquery-ui-dialog', |
1157
|
|
|
'gravityview_views_styles', |
1158
|
|
|
'gravityview_global', |
1159
|
|
|
'gravityview_views_datepicker' |
|
|
|
|
1160
|
|
|
); |
1161
|
|
|
} |
1162
|
|
|
|
1163
|
|
|
return array_merge( $registered, $allowed_dependencies ); |
1164
|
|
|
} |
1165
|
|
|
|
1166
|
|
|
|
1167
|
|
|
} |
1168
|
|
|
|
1169
|
|
|
new GravityView_Admin_Views; |
1170
|
|
|
|
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.