Completed
Push — develop ( aad3f3...839a66 )
by Zack
15:14 queued 02:19
created

render_frontend()   C

Complexity

Conditions 7
Paths 21

Size

Total Lines 45
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 8.323

Importance

Changes 0
Metric Value
cc 7
eloc 19
nc 21
nop 3
dl 0
loc 45
ccs 14
cts 20
cp 0.7
crap 8.323
rs 6.7272
c 0
b 0
f 0
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 10 and the first side effect is on line 96.

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
/**
4
 * Widget to add custom content
5
 *
6
 * @since 1.5.4
7
 *
8
 * @extends GravityView_Widget
9
 */
10
class GravityView_Widget_Custom_Content extends \GV\Widget {
11
12
	/**
13
	 * Does this get displayed on a single entry?
14
	 * @var boolean
15
	 */
16
	protected $show_on_single = false;
17
18 2
	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...
19
20 2
		$this->widget_description = __('Insert custom text or HTML as a widget', 'gravityview' );
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after opening bracket; 0 found
Loading history...
21
22
		$default_values = array(
23 2
			'header' => 1,
24
			'footer' => 1,
25
		);
26
27
		$settings = array(
28 2
			'content' => array(
29 2
				'type' => 'textarea',
30 2
				'label' => __( 'Custom Content', 'gravityview' ),
31 2
				'desc' => __( 'Enter text or HTML. Also supports shortcodes.', 'gravityview' ),
32 2
				'value' => '',
33 2
				'class'	=> 'code',
34
				'merge_tags' => false,
35
				'show_all_fields' => true, // Show the `{all_fields}` and `{pricing_fields}` merge tags
36
			),
37
			'wpautop' => array(
38 2
				'type' => 'checkbox',
39 2
				'label' => __( 'Automatically add paragraphs to content', 'gravityview' ),
40 2
				'tooltip' => __( 'Wrap each block of text in an HTML paragraph tag (recommended for text).', 'gravityview' ),
41 2
				'value' => '',
42
			),
43
		);
44
45 2
		parent::__construct( __( 'Custom Content', 'gravityview' ) , 'custom_content', $default_values, $settings );
46 2
	}
47
48 1
	public function render_frontend( $widget_args, $content = '', $context = '') {
49
50 1
		if( !$this->pre_render_frontend() ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
51
			return;
52
		}
53
54 1
		if( !empty( $widget_args['title'] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
55
			echo $widget_args['title'];
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$widget_args'
Loading history...
56
		}
57
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
58
59
		// Make sure the class is loaded in DataTables
60 1
		if( !class_exists( 'GFFormDisplay' ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
61
			include_once( GFCommon::get_base_path() . '/form_display.php' );
62
		}
63
64 1
		$widget_args['content'] = trim( rtrim( $widget_args['content'] ) );
65
66
		// No custom content
67 1
		if( empty( $widget_args['content'] ) ) {
68
			gravityview()->log->debug( 'No content.' );
69
			return;
70
		}
71
72
		// Add paragraphs?
73 1
		if( !empty( $widget_args['wpautop'] ) ) {
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
74
			$widget_args['content'] = wpautop( $widget_args['content'] );
75
		}
76
77 1
		$content = $widget_args['content'];
78
79 1
		$content = GravityView_Merge_Tags::replace_variables( $content, array(), array(), false, true, false );
80
81
		// Enqueue scripts needed for Gravity Form display, if form shortcode exists.
82
		// Also runs `do_shortcode()`
83 1
		$content = GFCommon::gform_do_shortcode( $content );
84
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
85
86
		// Add custom class
87 1
		$class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : '';
0 ignored issues
show
introduced by
Expected 1 space after "!"; 0 found
Loading history...
88 1
		$class = gravityview_sanitize_html_class( $class );
89
90 1
		echo '<div class="gv-widget-custom-content '.$class.'">'. $content .'</div>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$class'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$content'
Loading history...
91
92 1
	}
93
94
}
95
96
new GravityView_Widget_Custom_Content;