Completed
Push — develop ( aaed27...84f265 )
by Zack
57:26 queued 37:23
created

GravityView_Admin_Views   D

Complexity

Total Complexity 137

Size/Duplication

Total Lines 1186
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 1186
ccs 0
cts 608
cp 0
rs 4.4102
wmc 137
lcom 1
cbo 8

27 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 41 1
A suggest_support_articles() 0 19 2
C filter_pre_get_posts_by_gravityview_form_id() 0 22 7
A add_view_dropdown() 0 19 4
A render_setting_row() 0 4 1
A render_field_option() 0 4 1
B gform_toolbar_menu() 0 68 6
A default_field_blacklist() 0 13 2
C tooltips() 0 60 10
C add_custom_column_content() 0 52 8
B get_connected_form_links() 0 56 8
B add_post_type_columns() 0 28 2
F save_postdata() 0 92 21
A render_label() 0 3 1
C render_available_fields() 0 47 8
B render_additional_fields() 0 44 4
A get_entry_default_fields() 0 71 3
B get_available_fields() 0 28 3
A render_available_widgets() 0 14 3
A get_registered_widgets() 0 3 1
D render_active_areas() 0 108 22
A render_widgets_active_areas() 0 23 2
B render_field_pickers() 0 26 2
B render_directory_active_areas() 0 41 5
B add_scripts_and_styles() 0 44 5
A enqueue_gravity_forms_scripts() 0 17 2
B register_no_conflict() 0 40 3

How to fix   Complexity   

Complex Class

Complex classes like GravityView_Admin_Views often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use GravityView_Admin_Views, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 19 and the first side effect is on line 16.

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.

Loading history...
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() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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') );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
32
33
		// adding styles and scripts
34
		add_action( 'admin_enqueue_scripts', array( 'GravityView_Admin_Views', 'add_scripts_and_styles'), 999 );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
35
		add_filter( 'gform_noconflict_styles', array( $this, 'register_no_conflict') );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
36
		add_filter( 'gform_noconflict_scripts', array( $this, 'register_no_conflict') );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
37
		add_filter( 'gravityview_noconflict_styles', array( $this, 'register_no_conflict') );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
38
		add_filter( 'gravityview_noconflict_scripts', array( $this, 'register_no_conflict') );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
39
40
		add_action( 'gravityview_render_directory_active_areas', array( $this, 'render_directory_active_areas'), 10, 4 );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
41
		add_action( 'gravityview_render_widgets_active_areas', array( $this, 'render_widgets_active_areas'), 10, 3 );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
42
		add_action( 'gravityview_render_field_pickers', array( $this, 'render_field_pickers') );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
43
		add_action( 'gravityview_render_available_fields', array( $this, 'render_available_fields'), 10, 2 );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
44
		add_action( 'gravityview_render_available_widgets', array( $this, 'render_available_widgets') );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
45
		add_action( 'gravityview_render_active_areas', array( $this, 'render_active_areas'), 10, 5 );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
46
47
		// @todo check if this hook is needed..
48
		//add_action( 'gravityview_render_field_options', array( $this, 'render_field_options'), 10, 9 );
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
49
50
		// Add Connected Form column
51
		add_filter('manage_gravityview_posts_columns' , array( $this, 'add_post_type_columns' ) );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
52
53
		add_filter( 'gform_toolbar_menu', array( 'GravityView_Admin_Views', 'gform_toolbar_menu' ), 10, 2 );
54
55
		add_action( 'manage_gravityview_posts_custom_column', array( $this, 'add_custom_column_content'), 10, 2 );
0 ignored issues
show
introduced by
No space before closing parenthesis of array is bad style
Loading history...
56
57
		add_action( 'restrict_manage_posts', array( $this, 'add_view_dropdown' ) );
58
59
		add_action( 'pre_get_posts', array( $this, 'filter_pre_get_posts_by_gravityview_form_id' ) );
60
61
		add_filter( 'gravityview/support_port/localization_data', array( $this, 'suggest_support_articles' ) );
62
63
	}
64
65
	/**
66
     * When on the Add/Edit View screen, suggest most popular articles related to that
67
     *
68
	 * @param array $localization_data Data to be passed to the Support Port JS
69
	 *
70
	 * @return array
71
	 */
72
	function suggest_support_articles( $localization_data = array() ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
73
74
	    if( ! gravityview()->request->is_view() ) {
75
	        return $localization_data;
76
        }
77
78
		$localization_data['suggest'] = array(
79
            '57ef23539033602e61d4a560',
80
            '54c67bb9e4b0512429885513',
81
            '54c67bb9e4b0512429885512',
82
            '54c67bbbe4b07997ea3f3f6b',
83
            '54d1a33ae4b086c0c0964ce9',
84
            '57ef253c9033602e61d4a563',
85
            '552355bfe4b0221aadf2572b',
86
            '54c67bcde4b051242988553e',
87
        );
88
89
		return $localization_data;
90
	}
91
92
	/**
93
	 * @since 1.15
94
	 * @param WP_Query $query
95
	 */
96
	public function filter_pre_get_posts_by_gravityview_form_id( &$query ) {
97
		global $pagenow;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
98
99
		if ( !is_admin() ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
100
			return;
101
		}
102
103
		$form_id = isset( $_GET['gravityview_form_id'] ) ? (int) $_GET['gravityview_form_id'] : false;
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
104
105
		if( 'edit.php' !== $pagenow || ! $form_id || ! isset( $query->query_vars[ 'post_type' ] ) ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $form_id of type integer|false is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
introduced by
Array keys should NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
106
			return;
107
		}
108
109
		if ( $query->query_vars[ 'post_type' ] == 'gravityview' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
introduced by
Array keys should NOT be surrounded by spaces if they only contain a string or an integer.
Loading history...
110
			$query->set( 'meta_query', array(
111
				array(
112
					'key' => '_gravityview_form_id',
113
					'value' => $form_id,
114
				)
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
115
			) );
116
		}
117
	}
118
119
	function add_view_dropdown() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
120
		$current_screen = get_current_screen();
121
122
		if( 'gravityview' !== $current_screen->post_type ) {
123
			return;
124
		}
125
126
		$forms = gravityview_get_forms();
127
		$current_form = \GV\Utils::_GET( 'gravityview_form_id' );
128
		// If there are no forms to select, show no forms.
129
		if( !empty( $forms ) ) { ?>
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
130
			<select name="gravityview_form_id" id="gravityview_form_id">
131
				<option value="" <?php selected( '', $current_form, true ); ?>><?php esc_html_e( 'All forms', 'gravityview' ); ?></option>
132
				<?php foreach( $forms as $form ) { ?>
133
					<option value="<?php echo $form['id']; ?>" <?php selected( $form['id'], $current_form, true ); ?>><?php echo esc_html( $form['title'] ); ?></option>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form'
Loading history...
134
				<?php } ?>
135
			</select>
136
		<?php }
137
	}
138
139
140
	/**
141
	 * @deprecated since 1.2
142
	 * Start using GravityView_Render_Settings::render_setting_row
143
	 */
144
	public static function render_setting_row( $key = '', $current_settings = array(), $override_input = null, $name = 'template_settings[%s]', $id = 'gravityview_se_%s' ) {
145
		_deprecated_function( 'GravityView_Admin_Views::render_setting_row', '1.1.7', 'GravityView_Render_Settings::render_setting_row' );
146
		GravityView_Render_Settings::render_setting_row( $key, $current_settings, $override_input, $name , $id );
147
	}
148
149
	/**
150
	 * @deprecated since 1.2
151
	 * Start using GravityView_Render_Settings::render_field_option
152
	 */
153
	public static function render_field_option( $name = '', $option, $curr_value = NULL ) {
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
154
		_deprecated_function( 'GravityView_Admin_Views::render_field_option', '1.1.7', 'GravityView_Render_Settings::render_field_option' );
155
		return GravityView_Render_Settings::render_field_option( $name, $option, $curr_value );
156
	}
157
158
159
	/**
160
	 * Add a GravityView menu to the Form Toolbar with connected views
161
	 * @param  array  $menu_items Menu items, as set in GFForms::top_toolbar()
162
	 * @param  int $id         ID of the current Gravity form
163
	 * @return array            Modified array
164
	 */
165
	static function gform_toolbar_menu( $menu_items = array(), $id = NULL ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
166
167
		$connected_views = gravityview_get_connected_views( $id, array( 'post_status' => 'any' ) );
168
169
		if( empty( $connected_views ) ) {
170
171
		    $menu_items['gravityview'] = array(
172
				'label'          => esc_attr__( 'Create a View', 'gravityview' ),
173
				'icon'           => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>',
174
				'title'          => esc_attr__( 'Create a View using this form as a data source', 'gravityview' ),
175
				'url'            => admin_url( 'post-new.php?post_type=gravityview&form_id=' . $id ),
176
				'menu_class'     => 'gv_connected_forms gf_form_toolbar_settings',
177
				'priority'       => 0,
178
				'capabilities'   => array( 'edit_gravityviews' ),
179
			);
180
181
			return $menu_items;
182
		}
183
184
		$sub_menu_items = array();
185
		foreach ( (array)$connected_views as $view ) {
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
186
187
			if( ! GVCommon::has_cap( 'edit_gravityview', $view->ID ) ) {
188
				continue;
189
			}
190
191
			$label = empty( $view->post_title ) ? sprintf( __('No Title (View #%d)', 'gravityview' ), $view->ID ) : $view->post_title;
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
192
193
			$sub_menu_items[] = array(
194
				'label' => esc_attr( $label ),
195
				'url' => admin_url( 'post.php?action=edit&post='.$view->ID ),
196
			);
197
		}
198
199
		// If there were no items added, then let's create the parent menu
200
		if( $sub_menu_items ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $sub_menu_items of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
201
202
		    $sub_menu_items[] = array(
203
			    'label' => esc_attr__( 'Create a View', 'gravityview' ),
204
                'link_class' => 'gv-create-view',
205
			    'title' => esc_attr__( 'Create a View using this form as a data source', 'gravityview' ),
206
			    'url'   => admin_url( 'post-new.php?post_type=gravityview&form_id=' . $id ),
207
			    'capabilities'   => array( 'edit_gravityviews' ),
208
            );
209
210
			// Make sure Gravity Forms uses the submenu; if there's only one item, it uses a link instead of a dropdown
211
			$sub_menu_items[] = array(
212
				'url' => '#',
213
				'label' => '',
214
				'menu_class' => 'hidden',
215
				'capabilities' => '',
216
			);
217
218
			$menu_items['gravityview'] = array(
219
				'label'          => __( 'Connected Views', 'gravityview' ),
220
				'icon'           => '<i class="fa fa-lg gv-icon-astronaut-head gv-icon"></i>',
221
				'title'          => __( 'GravityView Views using this form as a data source', 'gravityview' ),
222
				'url'            => '#',
223
				'onclick'        => 'return false;',
224
				'menu_class'     => 'gv_connected_forms gf_form_toolbar_settings',
225
				'sub_menu_items' => $sub_menu_items,
226
				'priority'       => 0,
227
				'capabilities'   => array( 'edit_gravityviews' ),
228
			);
229
		}
230
231
		return $menu_items;
232
	}
233
234
	/**
235
	 * List the field types without presentation properties (on a View context)
236
	 *
237
	 * @param array $array Existing field types to add to a blacklist
238
	 * @param string|null $context Context for the blacklist. Default: NULL.
239
	 * @access public
240
	 * @return array Default blacklist fields merged with existing blacklist fields
241
	 */
242
	function default_field_blacklist( $array = array(), $context = NULL ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
243
244
		$add = array( 'captcha', 'page' );
245
246
		// Don't allowing editing the following values:
247
		if( $context === 'edit' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
248
			$add[] = 'post_id';
249
		}
250
251
		$return = array_merge( $array, $add );
252
253
		return $return;
254
	}
255
256
	/**
257
	 * Add tooltip text for use throughout the UI
258
	 * @param  array       $tooltips Array of Gravity Forms tooltips
259
	 * @return array                Modified tooltips array
260
	 */
261
	public function tooltips( $tooltips = array() ) {
262
263
		$gv_tooltips = array();
264
265
		// Generate tooltips for View settings
266
		$default_args = \GV\View_Settings::defaults( true );
267
268
		foreach ( $default_args as $key => $arg ) {
269
270
			// If an arg has `tooltip` defined, but it's false, don't display a tooltip
271
			if( isset( $arg['tooltip'] ) && empty( $arg['tooltip'] ) ) { continue; }
272
273
			// By default, use `tooltip` if defined.
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
274
			$tooltip = empty( $arg['tooltip'] ) ? NULL : $arg['tooltip'];
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
275
276
			// Otherwise, use the description as a tooltip.
277
			if( empty( $tooltip ) && !empty( $arg['desc'] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
278
				$tooltip = $arg['desc'];
279
			}
280
281
			// If there's no tooltip set, continue
282
			if( empty( $tooltip ) ) {
283
				continue;
284
			}
285
286
			// Add the tooltip
287
			$gv_tooltips[ 'gv_'.$key ] = array(
288
				'title'	=> $arg['label'],
289
				'value'	=> $tooltip,
290
			);
291
292
		}
293
294
		$gv_tooltips['gv_css_merge_tags'] = array(
295
			'title' => __('CSS Merge Tags', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
296
			'value' => sprintf( __( 'Developers: The CSS classes will be sanitized using the %ssanitize_title_with_dashes()%s function.', 'gravityview'), '<code>', '</code>' )
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
297
		);
298
299
		/**
300
		 * @filter `gravityview_tooltips` The tooltips GravityView adds to the Gravity Forms tooltip array
301
		 * @param array $gv_tooltips Associative array with unique keys containing array of `title` and `value` keys, as expected by `gform_tooltips` filter
302
		 * @deprecated Renamed to `gravityview/metaboxes/tooltips`
303
		 */
304
		$gv_tooltips = apply_filters( 'gravityview_tooltips', $gv_tooltips );
305
306
		/**
307
		 * @filter `gravityview/metaboxes/tooltips` The tooltips GravityView adds to the Gravity Forms tooltip array
308
		 * @param array $gv_tooltips Associative array with unique keys containing array of `title` and `value` keys, as expected by `gform_tooltips` filter
309
		 */
310
		$gv_tooltips = apply_filters( 'gravityview/metaboxes/tooltips', $gv_tooltips );
311
312
		foreach ( $gv_tooltips as $key => $tooltip ) {
313
314
			$title = empty( $tooltip['title'] ) ? '' : '<h6>'.esc_html( $tooltip['title'] ) .'</h6>';
315
316
			$tooltips[ $key ] = $title . wpautop( esc_html( $tooltip['value'] ) );
317
		}
318
319
		return $tooltips;
320
	}
321
322
	/**
323
	 * Add the Data Source information
324
	 *
325
	 * @param null $column_name
326
	 * @param $post_id
327
	 *
328
	 * @return void
329
	 */
330
	public function add_custom_column_content( $column_name = NULL, $post_id )	{
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
331
332
		$output = '';
333
334
		switch ( $column_name ) {
335
			case 'gv_template':
336
337
				$template_id = gravityview_get_template_id( $post_id );
338
339
				// All Views should have a connected form. If it doesn't, that's not right.
340
				if ( empty( $template_id ) ) {
341
					gravityview()->log->error( 'View ID {view_id} does not have a connected template.', array( 'view_id' => $post_id ) );
342
					break;
343
				}
344
345
				$templates = gravityview_get_registered_templates();
346
347
				$template = isset( $templates[ $template_id ] ) ? $templates[ $template_id ] : false;
348
349
				// Generate backup if label doesn't exist: `example_name` => `Example Name`
350
				$template_id_pretty = ucwords( implode( ' ', explode( '_', $template_id ) ) );
351
352
				$output = $template ? $template['label'] : $template_id_pretty;
353
354
				break;
355
356
			case 'gv_connected_form':
357
358
				$form_id = gravityview_get_form_id( $post_id );
359
360
				// All Views should have a connected form. If it doesn't, that's not right.
361
				if ( empty( $form_id ) ) {
362
					gravityview()->log->error( 'View ID {view_id} does not have a connected GF form.', array( 'view_id' => $post_id ) );
363
					$output = __( 'Not connected.', 'gravityview' );
364
					break;
365
				}
366
367
				$form = gravityview_get_form( $form_id );
368
369
				if ( ! $form ) {
370
					gravityview()->log->error( 'Connected form not found: Form #{form_id}', array( 'form_id' => $form_id ) );
371
372
					$output = __( 'The connected form can not be found; it may no longer exist.', 'gravityview' );
373
				} else {
374
					$output = self::get_connected_form_links( $form );
375
				}
376
377
				break;
378
		}
379
380
		echo $output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$output'
Loading history...
381
	}
382
383
384
	/**
385
	 * Get HTML links relating to a connected form, like Edit, Entries, Settings, Preview
386
	 * @param  array|int $form Gravity Forms forms array, or the form ID
387
	 * @param  boolean $include_form_link Whether to include the bold name of the form in the output
388
	 * @return string          HTML links
389
	 */
390
	static public function get_connected_form_links( $form, $include_form_link = true ) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
391
392
		// Either the form is empty or the form ID is 0, not yet set.
393
		if( empty( $form ) ) {
394
			return '';
395
		}
396
397
		// The $form is passed as the form ID
398
		if( !is_array( $form ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
399
			$form = gravityview_get_form( $form );
400
		}
401
402
		$form_id = $form['id'];
403
		$links = array();
404
405
		if( GVCommon::has_cap( 'gravityforms_edit_forms' ) ) {
406
			$form_url = admin_url( sprintf( 'admin.php?page=gf_edit_forms&amp;id=%d', $form_id ) );
407
			$form_link = '<strong class="gv-form-title">'.gravityview_get_link( $form_url, $form['title'], 'class=row-title' ).'</strong>';
408
			$links[] = '<span>'.gravityview_get_link( $form_url, __('Edit Form', 'gravityview') ).'</span>';
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
409
		} else {
410
			$form_link = '<strong class="gv-form-title">'. esc_html( $form['title'] ). '</strong>';
411
		}
412
413
		if( GVCommon::has_cap( 'gravityforms_view_entries' ) ) {
414
			$entries_url = admin_url( sprintf( 'admin.php?page=gf_entries&amp;id=%d', $form_id ) );
415
			$links[] = '<span>'.gravityview_get_link( $entries_url, __('Entries', 'gravityview') ).'</span>';
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
416
		}
417
418
		if( GVCommon::has_cap( array( 'gravityforms_edit_settings', 'gravityview_view_settings' ) ) ) {
419
			$settings_url = admin_url( sprintf( 'admin.php?page=gf_edit_forms&amp;view=settings&amp;id=%d', $form_id ) );
420
			$links[] = '<span>'.gravityview_get_link( $settings_url, __('Settings', 'gravityview'), 'title='.__('Edit settings for this form', 'gravityview') ).'</span>';
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw '__'
Loading history...
421
		}
422
423
		if( GVCommon::has_cap( array("gravityforms_edit_forms", "gravityforms_create_form", "gravityforms_preview_forms") ) ) {
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
Coding Style Comprehensibility introduced by
The string literal gravityforms_edit_forms does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal gravityforms_create_form does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
Coding Style Comprehensibility introduced by
The string literal gravityforms_preview_forms does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
introduced by
No space before closing parenthesis of array is bad style
Loading history...
424
			$preview_url = site_url( sprintf( '?gf_page=preview&amp;id=%d', $form_id ) );
425
			$links[] = '<span>'.gravityview_get_link( $preview_url, __('Preview Form', 'gravityview'), 'title='.__('Preview this form', 'gravityview') ).'</span>';
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw '__'
Loading history...
426
		}
427
428
		$output = '';
429
430
		if( !empty( $include_form_link ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
431
			$output .= $form_link;
432
		}
433
434
		/**
435
		 * @filter `gravityview_connected_form_links` Modify the links shown in the Connected Form links
436
		 * @since 1.6
437
		 * @param array $links Links to show
438
		 * @param array $form Gravity Forms form array
439
		 */
440
		$links = apply_filters( 'gravityview_connected_form_links', $links, $form );
441
442
		$output .= '<div class="row-actions">'. implode( ' | ', $links ) .'</div>';
443
444
		return $output;
445
	}
446
447
	/**
448
	 * Add the Data Source column to the Views page
449
	 * @param  array      $columns Columns array
450
	 */
451
	public function add_post_type_columns( $columns ) {
452
453
		// Get the date column and save it for later to add back in.
454
		// This adds it after the Data Source column.
455
		// This way, we don't need to do array_slice, array_merge, etc.
456
		$date = $columns['date'];
457
		unset( $columns['date'] );
458
459
		$data_source_required_caps = array(
460
			'gravityforms_edit_forms',
461
			'gravityforms_view_entries',
462
			'gravityforms_edit_settings',
463
			'gravityview_view_settings',
464
			'gravityforms_create_form',
465
			'gravityforms_preview_forms',
466
		);
467
468
		if( GVCommon::has_cap( $data_source_required_caps ) ) {
469
			$columns['gv_connected_form'] = __( 'Data Source', 'gravityview' );
470
		}
471
472
		$columns['gv_template'] = _x( 'Template', 'Column title that shows what template is being used for Views', 'gravityview' );
473
474
		// Add the date back in.
475
		$columns['date'] = $date;
476
477
		return $columns;
478
	}
479
480
	/**
481
	 * Save View configuration
482
	 *
483
	 * @access public
484
	 * @param int $post_id Currently saved Post ID
485
	 * @return void
486
	 */
487
	function save_postdata( $post_id ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
488
489
		if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ){
490
			return;
491
		}
492
493
		// validate post_type
494
		if ( ! isset( $_POST['post_type'] ) || 'gravityview' != $_POST['post_type'] ) {
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
495
			return;
496
		}
497
498
		// validate user can edit and save View
499
		if ( ! GVCommon::has_cap( 'edit_gravityview', $post_id ) ) {
500
			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() ) );
501
			return;
502
		}
503
504
		gravityview()->log->debug( '[save_postdata] Saving View post type.', array( 'data' => $_POST ) );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
505
506
		$statii = array();
507
508
		// check if this is a start fresh View
509
		if ( isset( $_POST['gravityview_select_form_nonce'] ) && wp_verify_nonce( $_POST['gravityview_select_form_nonce'], 'gravityview_select_form' ) ) {
510
511
			$form_id = !empty( $_POST['gravityview_form_id'] ) ? $_POST['gravityview_form_id'] : '';
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
512
			// save form id
513
			$statii['form_id'] = update_post_meta( $post_id, '_gravityview_form_id', $form_id );
514
515
		}
516
517
		if( false === GVCommon::has_cap( 'gravityforms_create_form' ) && empty( $statii['form_id'] ) ) {
518
			gravityview()->log->error( 'Current user does not have the capability to create a new Form.', array( 'data' => wp_get_current_user() ) );
519
			return;
520
		}
521
522
		// Was this a start fresh?
523
		if ( ! empty( $_POST['gravityview_form_id_start_fresh'] ) ) {
524
			$statii['start_fresh'] = add_post_meta( $post_id, '_gravityview_start_fresh', 1 );
525
		} else {
526
			$statii['start_fresh'] = delete_post_meta( $post_id, '_gravityview_start_fresh' );
527
		}
528
529
		// Check if we have a template id
530
		if ( isset( $_POST['gravityview_select_template_nonce'] ) && wp_verify_nonce( $_POST['gravityview_select_template_nonce'], 'gravityview_select_template' ) ) {
531
532
			$template_id = !empty( $_POST['gravityview_directory_template'] ) ? $_POST['gravityview_directory_template'] : '';
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
533
534
			// now save template id
535
			$statii['directory_template'] = update_post_meta( $post_id, '_gravityview_directory_template', $template_id );
536
		}
537
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
538
539
		// save View Configuration metabox
540
		if ( isset( $_POST['gravityview_view_configuration_nonce'] ) && wp_verify_nonce( $_POST['gravityview_view_configuration_nonce'], 'gravityview_view_configuration' ) ) {
541
542
			// template settings
543
			if( empty( $_POST['template_settings'] ) ) {
544
				$_POST['template_settings'] = array();
545
			}
546
			$statii['template_settings'] = update_post_meta( $post_id, '_gravityview_template_settings', $_POST['template_settings'] );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
547
548
			$fields = array();
549
550
			// Directory&single Visible Fields
551
			if( !empty( $preset_fields ) ) {
0 ignored issues
show
Bug introduced by
The variable $preset_fields does not exist. Did you mean $fields?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
552
553
				$fields = $preset_fields;
554
555
			} elseif( !empty( $_POST['gv_fields'] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
556
				$fields = _gravityview_process_posted_fields();
557
			}
558
559
			$statii['directory_fields'] = update_post_meta( $post_id, '_gravityview_directory_fields', $fields );
560
561
			// Directory Visible Widgets
562
			if( empty( $_POST['widgets'] ) ) {
563
				$_POST['widgets'] = array();
564
			}
565
			$statii['directory_widgets'] = gravityview_set_directory_widgets( $post_id, $_POST['widgets'] );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
566
567
		} // end save view configuration
568
569
		/**
570
		 * @action `gravityview_view_saved` After a View has been saved in the admin
571
		 * @param int $post_id ID of the View that has been saved
572
		 * @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.
573
		 * @since 1.17.2
574
		 */
575
		do_action('gravityview_view_saved', $post_id, $statii );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
576
577
		gravityview()->log->debug( '[save_postdata] Update Post Meta Statuses (also returns false if nothing changed)', array( 'data' => array_map( 'intval', $statii ) ) );
578
	}
579
580
	/**
581
	 * @deprecated 1.1.6
582
	 */
583
	function render_label() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
584
		_deprecated_function( 'GravityView_Admin_Views::render_label()', '1.1.6', 'Use the GravityView_Admin_View_Field class instead.' );
585
	}
586
587
	/**
588
	 * Render html for displaying available fields based on a Form ID
589
	 * $blacklist_field_types - contains the field types which are not proper to be shown in a directory.
590
	 *
591
     * @see GravityView_Ajax::get_available_fields_html() Triggers `gravityview_render_available_fields` action
592
	 * @access public
593
     *
594
	 * @param int $form Gravity Forms Form ID (default: '')
595
	 * @param string $context (default: 'single')
596
     *
597
	 * @return void
598
	 */
599
	function render_available_fields( $form = 0, $context = 'single' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
600
601
		/**
602
		 * @filter  `gravityview_blacklist_field_types` Modify the types of fields that shouldn't be shown in a View.
603
		 * @param[in,out] array $blacklist_field_types Array of field types to block for this context.
604
		 * @param[in] string $context View context ('single', 'directory', or 'edit')
605
		 */
606
		$blacklist_field_types = apply_filters( 'gravityview_blacklist_field_types', array(), $context );
607
608
		if ( ! is_array( $blacklist_field_types ) ) {
609
610
		    gravityview()->log->error( '$blacklist_field_types is not an array', array( 'data' => print_r( $blacklist_field_types, true ) ) );
0 ignored issues
show
introduced by
The use of function print_r() is discouraged
Loading history...
611
612
			$blacklist_field_types = array();
613
		}
614
615
		$fields = $this->get_available_fields( $form, $context );
616
617
		$output = '';
618
619
		if( !empty( $fields ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
620
621
			foreach( $fields as $id => $details ) {
622
623
				if( in_array( $details['type'], (array) $blacklist_field_types ) ) {
624
					continue;
625
				}
626
627
				// Edit mode only allows editing the parent fields, not single inputs.
628
				if( $context === 'edit' && !empty( $details['parent'] ) ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
introduced by
Expected 1 space after "!"; 0 found
Loading history...
629
					continue;
630
				}
631
632
				$output .= new GravityView_Admin_View_Field( $details['label'], $id, $details, $settings = array(), $form );
633
634
			} // End foreach
635
		}
636
637
		echo $output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$output'
Loading history...
638
639
		// For the EDIT view we only want to allow the form fields.
640
		if( $context === 'edit' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
641
			return;
642
		}
643
644
		$this->render_additional_fields( $form, $context );
645
	}
646
647
	/**
648
	 * Render html for displaying additional fields based on a Form ID
649
	 *
650
	 * @access public
651
	 * @param int $form Gravity Forms Form ID (default: '')
652
	 * @param string $context (default: 'single')
653
	 * @return void
654
	 */
655
	public function render_additional_fields( $form = 0, $context = 'single' ) {
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
656
657
		/**
658
		 * @filter `gravityview_additional_fields` non-standard Fields to show at the bottom of the field picker
659
		 * @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
660
		 */
661
		$additional_fields = apply_filters( 'gravityview_additional_fields', array(
662
			array(
663
				'label_text' => __( '+ Add All Fields', 'gravityview' ),
664
				'desc' => __('Add all the available fields at once.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
665
				'field_id' => 'all-fields',
666
				'label_type' => 'field',
667
				'input_type' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
668
				'field_options' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
669
				'settings_html'	=> NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
670
			)
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
671
		));
672
673
		if( !empty( $additional_fields )) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
introduced by
No space before closing parenthesis is prohibited
Loading history...
674
			foreach ( (array)$additional_fields as $item ) {
0 ignored issues
show
introduced by
No space after closing casting parenthesis is prohibited
Loading history...
675
676
				// Prevent items from not having index set
677
				$item = wp_parse_args( $item, array(
678
					'label_text' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
679
					'field_id' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
680
					'label_type' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
681
					'input_type' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
682
					'field_options' => NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
683
					'settings_html'	=> NULL,
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
684
				));
685
686
				// Backward compat.
687
				if( !empty( $item['field_options'] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
688
					// Use settings_html from now on.
689
					$item['settings_html'] = $item['field_options'];
690
				}
691
692
				// Render a label for each of them
693
				echo new GravityView_Admin_View_Field( $item['label_text'], $item['field_id'], $item, $settings = array(), $form );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'new'
Loading history...
694
695
			}
696
		}
697
698
	}
699
700
	/**
701
	 * Retrieve the default fields id, label and type
702
	 * @param  string|array $form form_ID or form object
703
	 * @param  string $zone   Either 'single', 'directory', 'header', 'footer'
704
	 * @return array
705
	 */
706
	function get_entry_default_fields($form, $zone) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
707
708
		$entry_default_fields = array();
709
710
		if( in_array( $zone, array( 'directory', 'single' ) ) ) {
711
712
			$entry_default_fields = array(
713
				'id' => array(
714
					'label' => __('Entry ID', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
715
					'type' => 'id',
716
					'desc'	=> __('The unique ID of the entry.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
717
				),
718
				'date_created' => array(
719
					'label' => __('Entry Date', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
720
					'desc'	=> __('The date the entry was created.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
721
					'type' => 'date_created',
722
				),
723
				'source_url' => array(
724
					'label' => __('Source URL', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
725
					'type' => 'source_url',
726
					'desc'	=> __('The URL of the page where the form was submitted.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
727
				),
728
				'ip' => array(
729
					'label' => __('User IP', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
730
					'type' => 'ip',
731
					'desc'	=> __('The IP Address of the user who created the entry.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
732
				),
733
				'created_by' => array(
734
					'label' => __('User', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
735
					'type' => 'created_by',
736
					'desc'	=> __('Details of the logged-in user who created the entry (if any).', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
737
				),
738
739
				/**
740
				 * @since 1.7.2
741
				 */
742
			    'other_entries' => array(
743
				    'label'	=> __('Other Entries', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
744
				    'type'	=> 'other_entries',
745
				    'desc'	=> __('Display other entries created by the entry creator.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
746
			    ),
747
	        );
748
749
			if( 'single' !== $zone) {
0 ignored issues
show
introduced by
No space before closing parenthesis is prohibited
Loading history...
750
751
				$entry_default_fields['entry_link'] = array(
752
					'label' => __('Link to Entry', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
753
					'desc'	=> __('A dedicated link to the single entry with customizable text.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
754
					'type' => 'entry_link',
755
				);
756
			}
757
758
		} // if not zone directory or single
759
760
		/**
761
		 * @since  1.2
762
		 */
763
		$entry_default_fields['custom']	= array(
764
			'label'	=> __('Custom Content', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
765
			'type'	=> 'custom',
766
			'desc'	=> __('Insert custom text or HTML.', 'gravityview'),
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
767
		);
768
769
		/**
770
		 * @filter `gravityview_entry_default_fields` Modify the default fields for each zone and context
771
		 * @param array $entry_default_fields Array of fields shown by default
772
		 * @param  string|array $form form_ID or form object
773
		 * @param  string $zone   Either 'single', 'directory', 'header', 'footer'
774
		 */
775
		return apply_filters( 'gravityview_entry_default_fields', $entry_default_fields, $form, $zone);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
776
	}
777
778
	/**
779
	 * Calculate the available fields
780
	 * @param  string|array $form form_ID or form object
781
	 * @param  string $zone   Either 'single', 'directory', 'header', 'footer'
782
	 * @return array         fields
783
	 */
784
	function get_available_fields( $form = '', $zone = NULL ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
785
786
		if( empty( $form ) ) {
787
			gravityview()->log->error( '$form is empty' );
788
			return array();
789
		}
790
791
		// get form fields
792
		$fields = gravityview_get_form_fields( $form, true );
793
794
		// get meta fields ( only if form was already created )
795
		if( !is_array( $form ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
796
			$meta_fields = gravityview_get_entry_meta( $form );
797
		} else {
798
			$meta_fields = array();
799
		}
800
801
		// get default fields
802
		$default_fields = $this->get_entry_default_fields( $form, $zone );
803
804
		//merge without loosing the keys
805
		$fields = $fields + $meta_fields + $default_fields;
806
807
		// Move Custom Content to top
808
		$fields = array( 'custom' => $fields['custom'] ) + $fields;
809
810
		return $fields;
811
	}
812
813
814
	/**
815
	 * Render html for displaying available widgets
816
	 * @return string html
817
	 */
818
	function render_available_widgets() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
819
820
		$widgets = $this->get_registered_widgets();
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_Admin_Views::get_registered_widgets() has been deprecated with message: Use \GV\Widget::registered()

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...
821
822
		if( !empty( $widgets ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
823
824
			foreach( $widgets as $id => $details ) {
825
826
				echo new GravityView_Admin_View_Widget( $details['label'], $id, $details );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'new'
Loading history...
827
828
			}
829
		}
830
831
	}
832
833
	/**
834
	 * Get the list of registered widgets. Each item is used to instantiate a GravityView_Admin_View_Widget object
835
	 * @deprecated Use \GV\Widget::registered()
836
	 * @since 1.13.1
837
	 * @return array
838
	 */
839
	function get_registered_widgets() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
840
		return \GV\Widget::registered();
841
	}
842
843
	/**
844
	 * Generic function to render rows and columns of active areas for widgets & fields
845
	 * @param  string $template_id The current slug of the selected View template
846
	 * @param  string $type   Either 'widget' or 'field'
847
	 * @param  string $zone   Either 'single', 'directory', 'header', 'footer'
848
	 * @param  array $rows    The layout structure: rows, columns and areas
849
	 * @param  array $values  Saved objects
850
	 * @return void
851
	 */
852
	function render_active_areas( $template_id, $type, $zone, $rows, $values ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
853
		global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
854
855
		if( $type === 'widget' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
856
			$button_label = __( 'Add Widget', 'gravityview' );
857
		} else {
858
			$button_label = __( 'Add Field', 'gravityview' );
859
		}
860
861
		$available_items = array();
862
863
		$view = \GV\View::from_post( $post );
864
865
		// if saved values, get available fields to label everyone
866
		if( !empty( $values ) && ( !empty( $post->ID ) || !empty( $_POST['template_id'] ) ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
867
868
			if( !empty( $_POST['template_id'] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
869
				$form = GravityView_Ajax::pre_get_form_fields( $_POST['template_id'] );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
870
			} else {
871
				$form = gravityview_get_form_id( $post->ID );
872
			}
873
874
			if( 'field' === $type ) {
875
				$available_items = $this->get_available_fields( $form, $zone );
876
			} else {
877
				$available_items = $this->get_registered_widgets();
0 ignored issues
show
Deprecated Code introduced by
The method GravityView_Admin_Views::get_registered_widgets() has been deprecated with message: Use \GV\Widget::registered()

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...
878
			}
879
880
		}
881
882
		foreach( $rows as $row ) :
883
			foreach( $row as $col => $areas ) :
884
				$column = ($col == '2-2') ? '1-2' : $col; ?>
885
886
				<div class="gv-grid-col-<?php echo esc_attr( $column ); ?>">
887
888
					<?php foreach( $areas as $area ) : 	?>
889
890
						<div class="gv-droppable-area" data-areaid="<?php echo esc_attr( $zone .'_'. $area['areaid'] ); ?>" data-context="<?php echo esc_attr( $zone ); ?>">
891
							<div class="active-drop active-drop-<?php echo esc_attr( $type ); ?>" data-areaid="<?php echo esc_attr( $zone .'_'. $area['areaid'] ); ?>">
892
893
								<?php // render saved fields
894
895
								if( !empty( $values[ $zone .'_'. $area['areaid'] ] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
896
897
									foreach( $values[ $zone .'_'. $area['areaid'] ] as $uniqid => $field ) {
898
899
										$input_type = NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
900
										$original_item = isset( $available_items[ $field['id'] ] ) ? $available_items[ $field['id'] ] : false ;
901
902
										if( !$original_item ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
903
904
											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 ) ) );
0 ignored issues
show
introduced by
No space after opening parenthesis of array is bad style
Loading history...
905
906
											$original_item = $field;
907
										} else {
908
909
											$input_type = isset( $original_item['type'] ) ? $original_item['type'] : NULL;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL must be lowercase; expected null, but found NULL.
Loading history...
910
911
										}
912
913
										// Maybe has a form ID
914
										$form_id = empty( $field['form_id'] ) ? null : $field['form_id'];
915
916
										// Field options dialog box
917
										$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 );
918
919
										$item = array(
920
											'input_type' => $input_type,
921
											'settings_html' => $field_options,
922
											'label_type' => $type
0 ignored issues
show
introduced by
Each line in an array declaration must end in a comma
Loading history...
923
										);
924
925
										// Merge the values with the current item to pass things like widget descriptions and original field names
926
										if( $original_item ) {
927
											$item = wp_parse_args( $item, $original_item );
928
										}
929
930
										switch( $type ) {
931
											case 'widget':
932
												echo new GravityView_Admin_View_Widget( $item['label'], $field['id'], $item, $field );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'new'
Loading history...
933
												break;
934
											default:
935
												echo new GravityView_Admin_View_Field( $field['label'], $field['id'], $item, $field, $form_id );
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'new'
Loading history...
936
										}
937
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
938
939
										//endif;
940
941
									}
942
943
								} // End if zone is not empty ?>
944
945
								<span class="drop-message"><?php echo sprintf(esc_attr__('"+ %s" or drag existing %ss here.', 'gravityview'), $button_label, $type ); ?></span>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
946
							</div>
947
							<div class="gv-droppable-area-action">
948
								<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>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$view'
Loading history...
949
950
								<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"> &ndash; <?php echo esc_html( $area['subtitle'] ); ?></span><?php } ?></p>
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
951
							</div>
952
						</div>
953
954
					<?php endforeach; ?>
955
956
				</div>
957
			<?php endforeach;
958
		endforeach;
959
	}
960
961
	/**
962
	 * Render the widget active areas
963
	 * @param  string $zone    Either 'header' or 'footer'
964
	 * @param  string $post_id Current Post ID (view)
965
	 * @return string          html
966
	 */
967
	function render_widgets_active_areas( $template_id = '', $zone, $post_id = '' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
968
969
		$default_widget_areas = GravityView_Widget::get_default_widget_areas();
970
971
		$widgets = array();
972
		if( !empty( $post_id ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
973
			$widgets = gravityview_get_directory_widgets( $post_id );
974
		}
975
976
		ob_start();
977
		?>
978
979
		<div class="gv-grid gv-grid-pad gv-grid-border" id="directory-<?php echo $zone; ?>-widgets">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$zone'
Loading history...
980
			<?php $this->render_active_areas( $template_id, 'widget', $zone, $default_widget_areas, $widgets ); ?>
981
		</div>
982
983
		<?php
984
		$output = ob_get_clean();
985
986
		echo $output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$output'
Loading history...
987
988
		return $output;
989
	}
990
991
	/**
992
     * Renders "Add Field" tooltips
993
     *
994
     * @since 2.1
995
     *
996
	 * @param string $context "directory", "single", or "edit"
997
     *
998
     * @return void
999
	 */
1000
	function render_field_pickers( $context = 'directory' ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1001
1002
		// list of available fields to be shown in the popup
1003
		$forms = gravityview_get_forms( 'any' );
1004
1005
		$form_ids = array_map( function ($form) { return $form['id']; }, $forms);
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1006
1007
		foreach ( $form_ids as $form_id ) {
1008
			$filter_field_id = sprintf( 'gv-field-filter-%s-%d', $context, $form_id );
1009
			?>
1010
            <div id="<?php echo esc_html( $context ); ?>-available-fields-<?php echo esc_attr( $form_id ); ?>" class="hide-if-js gv-tooltip">
1011
                <span class="close"><i class="dashicons dashicons-dismiss"></i></span>
1012
                <div class="gv-field-filter-form">
1013
                    <label class="screen-reader-text" for="<?php echo esc_html( $filter_field_id ); ?>"><?php esc_html_e( 'Filter Fields:', 'gravityview' ); ?></label>
1014
                    <input type="search" class="widefat gv-field-filter" aria-controls="<?php echo $filter_field_id; ?>" id="<?php echo esc_html( $filter_field_id ); ?>" placeholder="<?php esc_html_e( 'Filter fields by name or label', 'gravityview' ); ?>" />
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$filter_field_id'
Loading history...
1015
                </div>
1016
1017
                <div id="available-fields-<?php echo $filter_field_id; ?>" aria-live="polite" role="listbox">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$filter_field_id'
Loading history...
1018
                <?php do_action('gravityview_render_available_fields', $form_id, $context ); ?>
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
1019
                </div>
1020
1021
                <div class="gv-no-results hidden description"><?php esc_html_e( 'No fields were found matching the search.', 'gravityview' ); ?></div>
1022
            </div>
1023
			<?php
1024
		}
1025
    }
1026
1027
	/**
1028
	 * Render the Template Active Areas and configured active fields for a given template id and post id
1029
	 *
1030
	 * @access public
1031
	 * @param string $template_id (default: '') Template ID, like `default_list`, `default_table`, `preset_business_data`, etc. {@see GravityView_Template::__construct()}
1032
	 * @param string $post_id (default: '')
1033
	 * @param string $context (default: 'single')
1034
	 * @return string HTML of the active areas
1035
	 */
1036
	function render_directory_active_areas( $template_id = '', $context = 'single', $post_id = '', $echo = false ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1037
		if( empty( $template_id ) ) {
1038
			gravityview()->log->debug( '[render_directory_active_areas] {template_id} is empty', array( 'template_id' => $template_id ) );
1039
			return '';
1040
		}
1041
1042
		/**
1043
		 * @filter `gravityview_template_active_areas`
1044
		 * @see GravityView_Template::assign_active_areas()
1045
		 * @param array $template_areas Empty array, to be filled in by the template class
1046
		 * @param string $template_id Template ID, like `default_list`, `default_table`, `preset_business_data`, etc. {@see GravityView_Template::__construct()}
1047
		 * @param string $context Current View context: `directory`, `single`, or `edit` (default: 'single')
1048
		 */
1049
		$template_areas = apply_filters( 'gravityview_template_active_areas', array(), $template_id, $context );
1050
1051
		if( empty( $template_areas ) ) {
1052
1053
			gravityview()->log->debug( '[render_directory_active_areas] No areas defined. Maybe template {template_id} is disabled.', array( 'data' => $template_id ) );
1054
			$output = '<div>';
1055
			$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>';
1056
			$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>';
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1057
			$output .= '</div>';
1058
		} else {
1059
1060
			$fields = '';
1061
			if ( ! empty( $post_id ) ) {
1062
				$fields = gravityview_get_directory_fields( $post_id );
1063
			}
1064
1065
			ob_start();
1066
			$this->render_active_areas( $template_id, 'field', $context, $template_areas, $fields );
1067
			$output = ob_get_clean();
1068
1069
		}
1070
1071
		if( $echo ) {
1072
			echo $output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$output'
Loading history...
1073
		}
1074
1075
		return $output;
1076
	}
1077
1078
	/**
1079
	 * Enqueue scripts and styles at Views editor
1080
	 *
1081
	 * @access public
1082
	 * @param mixed $hook
1083
	 * @return void
1084
	 */
1085
	static function add_scripts_and_styles( $hook ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1086
		global $plugin_page, $pagenow;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1087
1088
		$is_widgets_page = ( $pagenow === 'widgets.php' );
1089
1090
		// Add the GV font (with the Astronaut)
1091
		wp_enqueue_style( 'gravityview_global', plugins_url('assets/css/admin-global.css', GRAVITYVIEW_FILE), array(), GravityView_Plugin::version );
0 ignored issues
show
Deprecated Code introduced by
The constant GravityView_Plugin::version has been deprecated with message: Use \GV\Plugin::$version

This class constant 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 constant will be removed from the class and what other constant to use instead.

Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1092
1093
		wp_register_script( 'gravityview-jquery-cookie', plugins_url('assets/lib/jquery.cookie/jquery.cookie.min.js', GRAVITYVIEW_FILE), array( 'jquery' ), GravityView_Plugin::version, true );
0 ignored issues
show
Deprecated Code introduced by
The constant GravityView_Plugin::version has been deprecated with message: Use \GV\Plugin::$version

This class constant 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 constant will be removed from the class and what other constant to use instead.

Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1094
1095
		// Don't process any scripts below here if it's not a GravityView page.
1096
		if( ! gravityview_is_admin_page( $hook, 'single' ) && ! $is_widgets_page ) {
0 ignored issues
show
Deprecated Code introduced by
The function gravityview_is_admin_page() has been deprecated with message: See `gravityview()->request->is_admin` or `\GV\Request::is_admin`

This function has been deprecated. The supplier of the file has supplied an explanatory message.

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

Loading history...
1097
		    return;
1098
		}
1099
1100
        wp_enqueue_script( 'jquery-ui-datepicker' );
1101
        wp_enqueue_style( 'gravityview_views_datepicker', plugins_url('assets/css/admin-datepicker.css', GRAVITYVIEW_FILE), GravityView_Plugin::version );
0 ignored issues
show
Deprecated Code introduced by
The constant GravityView_Plugin::version has been deprecated with message: Use \GV\Plugin::$version

This class constant 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 constant will be removed from the class and what other constant to use instead.

Loading history...
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1102
1103
        $script_debug = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
Coding Style introduced by
Expected 1 spaces before closing bracket; 0 found
Loading history...
1104
1105
        //enqueue scripts
1106
        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 );
0 ignored issues
show
Deprecated Code introduced by
The constant GravityView_Plugin::version has been deprecated with message: Use \GV\Plugin::$version

This class constant 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 constant will be removed from the class and what other constant to use instead.

Loading history...
1107
1108
        wp_localize_script('gravityview_views_scripts', 'gvGlobals', array(
1109
            'cookiepath' => COOKIEPATH,
1110
            'passed_form_id' => (bool) \GV\Utils::_GET( 'form_id' ),
1111
            'nonce' => wp_create_nonce( 'gravityview_ajaxviews' ),
1112
            'label_viewname' => __( 'Enter View name here', 'gravityview' ),
1113
            'label_close' => __( 'Close', 'gravityview' ),
1114
            'label_cancel' => __( 'Cancel', 'gravityview' ),
1115
            'label_continue' => __( 'Continue', 'gravityview' ),
1116
            'label_ok' => __( 'Ok', 'gravityview' ),
1117
            'label_publisherror' => __( 'Error while creating the View for you. Check the settings or contact GravityView support.', 'gravityview' ),
1118
            'loading_text' => esc_html__( 'Loading&hellip;', 'gravityview' ),
1119
            'loading_error' => esc_html__( 'There was an error loading dynamic content.', 'gravityview' ),
1120
            'field_loaderror' => __( 'Error while adding the field. Please try again or contact GravityView support.', 'gravityview' ),
1121
            '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' ),
1122
        ));
1123
1124
        wp_enqueue_style( 'gravityview_views_styles', plugins_url( 'assets/css/admin-views.css', GRAVITYVIEW_FILE ), array('dashicons', 'wp-jquery-ui-dialog' ), GravityView_Plugin::version );
0 ignored issues
show
Deprecated Code introduced by
The constant GravityView_Plugin::version has been deprecated with message: Use \GV\Plugin::$version

This class constant 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 constant will be removed from the class and what other constant to use instead.

Loading history...
introduced by
No space after opening parenthesis of array is bad style
Loading history...
1125
1126
        // Enqueue scripts needed for merge tags
1127
        self::enqueue_gravity_forms_scripts();
1128
	}
1129
1130
	/**
1131
	 * Enqueue Gravity Forms scripts, needed for Merge Tags
1132
     *
1133
     * @since 1.0.5-beta
1134
     *
1135
     * @return void
1136
	 */
1137
	static function enqueue_gravity_forms_scripts() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1138
		GFForms::register_scripts();
1139
1140
		$scripts = array(
1141
		    'sack',
1142
		    'gform_gravityforms',
1143
		    'gform_forms',
1144
		    'gform_form_admin',
1145
		    'jquery-ui-autocomplete'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
1146
		);
1147
1148
		if ( wp_is_mobile() ) {
1149
		    $scripts[] = 'jquery-touch-punch';
1150
		}
1151
1152
		wp_enqueue_script( $scripts );
1153
	}
1154
1155
	/**
1156
	 * Add GravityView scripts and styles to Gravity Forms and GravityView No-Conflict modes
1157
	 *
1158
	 * @param array $registered Existing scripts or styles that have been registered (array of the handles)
1159
	 *
1160
	 * @return array
1161
	 */
1162
	function register_no_conflict( $registered ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1163
1164
		$allowed_dependencies = array();
1165
1166
		$filter = current_filter();
1167
1168
		if ( preg_match( '/script/ism', $filter ) ) {
1169
1170
			$allowed_dependencies = array(
1171
				'jquery-ui-core',
1172
				'jquery-ui-dialog',
1173
				'jquery-ui-tabs',
1174
				'jquery-ui-draggable',
1175
				'jquery-ui-droppable',
1176
				'jquery-ui-sortable',
1177
				'jquery-ui-tooltip',
1178
				'gravityview_views_scripts',
1179
				'gravityview-support',
1180
				'gravityview-jquery-cookie',
1181
				'gravityview_views_datepicker',
1182
				'sack',
1183
				'gform_gravityforms',
1184
				'gform_forms',
1185
				'gform_form_admin',
1186
				'jquery-ui-autocomplete'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
1187
			);
1188
1189
		} elseif ( preg_match( '/style/ism', $filter ) ) {
1190
1191
			$allowed_dependencies = array(
1192
				'dashicons',
1193
				'wp-jquery-ui-dialog',
1194
				'gravityview_views_styles',
1195
				'gravityview_global',
1196
				'gravityview_views_datepicker'
0 ignored issues
show
introduced by
Comma required after last value in array declaration
Loading history...
1197
			);
1198
		}
1199
1200
		return array_merge( $registered, $allowed_dependencies );
1201
	}
1202
1203
1204
}
1205
1206
new GravityView_Admin_Views;
1207