Issues (1066)

classes/class-lsx-projects-widget.php (5 issues)

1
<?php
2
/**
3
 * LSX Projects Widget Class
4
 *
5
 * @package   LSX Projects
6
 * @author	LightSpeed
7
 * @license   GPL3
8
 * @link
9
 * @copyright 2016 LightSpeed
10
 */
11
class LSX_Projects_Widget extends WP_Widget {
12
13
	public function __construct() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function __construct()
Loading history...
14
		$widget_ops = array(
15
			'classname' => 'lsx-projects',
16
		);
17
18
		parent::__construct( 'LSX_Projects_Widget', esc_html__( 'LSX Projects', 'lsx-projects' ), $widget_ops );
19
	}
20
21
	function widget( $args, $instance ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function widget()
Loading history...
22
		extract( $args );
23
24
		$title = $instance['title'];
25
		$title_link = $instance['title_link'];
26
		$tagline = $instance['tagline'];
27
		$columns = $instance['columns'];
28
		$orderby = $instance['orderby'];
29
		$order = $instance['order'];
30
		$limit = $instance['limit'];
31
		$include = $instance['include'];
32
		$display = $instance['display'];
33
		$size = $instance['size'];
34
		$button_text = $instance['button_text'];
35
		$responsive = $instance['responsive'];
36
		$show_image = $instance['show_image'];
37
		$carousel = $instance['carousel'];
38
		$featured = $instance['featured'];
39
40
		// If limit not set, display 99 posts
41
		if ( empty( $limit ) ) {
42
			$limit = '99';
43
		}
44
45
		// If specific posts included, display 99 posts
46
		if ( ! empty( $include ) ) {
47
			$limit = '99';
48
		}
49
50
		if ( '1' == $responsive ) {
51
			$responsive = 'true';
52
		} else {
53
			$responsive = 'false';
54
		}
55
56
		if ( '1' == $show_image ) {
57
			$show_image = 'true';
58
		} else {
59
			$show_image = 'false';
60
		}
61
62
		if ( '1' == $carousel ) {
63
			$carousel = 'true';
64
		} else {
65
			$carousel = 'false';
66
		}
67
68
		if ( '1' == $featured ) {
69
			$featured = 'true';
70
		} else {
71
			$featured = 'false';
72
		}
73
74
		if ( $title_link ) {
75
			//$link_open = '<a href="' . $title_link . '">';
76
			$link_open = '';
77
			$link_btn_open = '<a href="' . $title_link . '" class="btn border-btn">';
78
			//$link_close = '</a>';
79
			$link_close = '';
80
			$link_btn_close = '</a>';
81
		} else {
82
			$link_open = '';
83
			$link_btn_open = '';
84
			$link_close = '';
85
			$link_btn_close = '';
86
		}
87
88
		echo wp_kses_post( $before_widget );
89
90
		if ( $title ) {
91
			echo wp_kses_post( $before_title . $link_open . $title . $link_close . $after_title );
92
		}
93
94
		if ( $tagline ) {
95
			echo '<p class="tagline text-center">' . esc_html( $tagline ) . '</p>';
96
		}
97
98
		if ( class_exists( 'LSX_Projects' ) ) {
99
			lsx_projects( array(
100
				'columns' => $columns,
101
				'orderby' => $orderby,
102
				'order' => $order,
103
				'limit' => $limit,
104
				'include' => $include,
105
				'display' => $display,
106
				'size' => $size,
107
				'responsive' => $responsive,
108
				'show_image' => $show_image,
109
				'carousel' => $carousel,
110
				'featured' => $featured,
111
			) );
112
		};
113
114
		if ( $button_text && $title_link ) {
115
			echo wp_kses_post( '<p class="text-center lsx-projects-archive-link-wrap"><span class="lsx-projects-archive-link">' . $link_btn_open . $button_text . ' <i class="fa fa-angle-right"></i>' . $link_btn_close . '</span></p>' );
116
		}
117
118
		echo wp_kses_post( $after_widget );
119
	}
120
121
	function update( $new_instance, $old_instance ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function update()
Loading history...
122
		$instance = $old_instance;
123
124
		$instance['title'] = wp_kses_post( force_balance_tags( $new_instance['title'] ) );
125
		$instance['title_link'] = strip_tags( $new_instance['title_link'] );
126
		$instance['tagline'] = wp_kses_post( force_balance_tags( $new_instance['tagline'] ) );
127
		$instance['columns'] = strip_tags( $new_instance['columns'] );
128
		$instance['orderby'] = strip_tags( $new_instance['orderby'] );
129
		$instance['order'] = strip_tags( $new_instance['order'] );
130
		$instance['limit'] = strip_tags( $new_instance['limit'] );
131
		$instance['include'] = strip_tags( $new_instance['include'] );
132
		$instance['display'] = strip_tags( $new_instance['display'] );
133
		$instance['size'] = strip_tags( $new_instance['size'] );
134
		$instance['button_text'] = strip_tags( $new_instance['button_text'] );
135
		$instance['responsive'] = strip_tags( $new_instance['responsive'] );
136
		$instance['show_image'] = strip_tags( $new_instance['show_image'] );
137
		$instance['carousel'] = strip_tags( $new_instance['carousel'] );
138
		$instance['featured'] = strip_tags( $new_instance['featured'] );
139
140
		return $instance;
141
	}
142
143
	function form( $instance ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function form()
Loading history...
144
		$defaults = array(
145
			'title' => 'Projects',
146
			'title_link' => '',
147
			'tagline' => '',
148
			'columns' => '3',
149
			'orderby' => 'name',
150
			'order' => 'ASC',
151
			'limit' => '',
152
			'include' => '',
153
			'display' => 'excerpt',
154
			'size' => 'lsx-thumbnail-single',
155
			'button_text' => '',
156
			'responsive' => 1,
157
			'show_image' => 1,
158
			'carousel' => 1,
159
			'featured' => 0,
160
		);
161
162
		$instance = wp_parse_args( (array) $instance, $defaults );
163
164
		$title          = esc_attr( $instance['title'] );
165
		$title_link     = esc_attr( $instance['title_link'] );
166
		$tagline        = esc_attr( $instance['tagline'] );
167
		$columns        = esc_attr( $instance['columns'] );
168
		$orderby        = esc_attr( $instance['orderby'] );
169
		$order          = esc_attr( $instance['order'] );
170
		$limit          = esc_attr( $instance['limit'] );
171
		$include        = esc_attr( $instance['include'] );
172
		$display        = esc_attr( $instance['display'] );
173
		$size           = esc_attr( $instance['size'] );
174
		$button_text    = esc_attr( $instance['button_text'] );
175
		$responsive     = esc_attr( $instance['responsive'] );
176
		$show_image     = esc_attr( $instance['show_image'] );
177
		$carousel       = esc_attr( $instance['carousel'] );
178
		$featured       = esc_attr( $instance['featured'] );
179
		?>
180
		<p>
181
			<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'lsx-projects' ); ?></label>
182
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
183
		</p>
184
		<p>
185
			<label for="<?php echo esc_attr( $this->get_field_id( 'title_link' ) ); ?>"><?php esc_html_e( 'Page Link:', 'lsx-projects' ); ?></label>
186
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title_link' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title_link' ) ); ?>" type="text" value="<?php echo esc_attr( $title_link ); ?>" />
187
			<small><?php esc_html_e( 'Link the widget to a page', 'lsx-projects' ); ?></small>
188
		</p>
189
		<p>
190
			<label for="<?php echo esc_attr( $this->get_field_id( 'tagline' ) ); ?>"><?php esc_html_e( 'Tagline:', 'lsx-projects' ); ?></label>
191
			<textarea class="widefat" rows="8" cols="20" id="<?php echo esc_attr( $this->get_field_id( 'tagline' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'tagline' ) ); ?>"><?php echo esc_html( $tagline ); ?></textarea>
192
			<small><?php esc_html_e( 'Tagline to display below the widget title', 'lsx-projects' ); ?></small>
193
		</p>
194
		<p>
195
			<label for="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>"><?php esc_html_e( 'Columns:', 'lsx-projects' ); ?></label>
196
			<select name="<?php echo esc_attr( $this->get_field_name( 'columns' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'columns' ) ); ?>" class="widefat">
197
			<?php
198
				$options = array( '1', '2', '3', '4' );
199
200
				foreach ( $options as $option ) {
201
					echo '<option value="' . esc_attr( lcfirst( $option ) ) . '" id="' . esc_attr( $option ) . '"', lcfirst( $option ) == $columns ? ' selected="selected"' : '', '>', esc_html( $option ), '</option>';
202
				}
203
			?>
204
			</select>
205
		</p>
206
		<p>
207
			<label for="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>"><?php esc_html_e( 'Order By:', 'lsx-projects' ); ?></label>
208
			<select name="<?php echo esc_attr( $this->get_field_name( 'orderby' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'orderby' ) ); ?>" class="widefat">
209
			<?php
210
				$options = array(
211
					esc_html__( 'None', 'lsx-projects' ) => 'none',
212
					esc_html__( 'ID', 'lsx-projects' ) => 'ID',
213
					esc_html__( 'Name', 'lsx-projects' ) => 'name',
214
					esc_html__( 'Date', 'lsx-projects' ) => 'date',
215
					esc_html__( 'Modified Date', 'lsx-projects' ) => 'modified',
216
					esc_html__( 'Random', 'lsx-projects' ) => 'rand',
217
					esc_html__( 'Menu (WP dashboard order)', 'lsx-projects' ) => 'menu_order',
218
				);
219
220
				foreach ( $options as $name => $value ) {
221
					echo '<option value="' . esc_attr( $value ) . '" id="' . esc_attr( $value ) . '"', $orderby == $value ? ' selected="selected"' : '', '>', esc_html( $name ), '</option>';
222
				}
223
			?>
224
			</select>
225
		</p>
226
		<p>
227
			<label for="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>"><?php esc_html_e( 'Order:', 'lsx-projects' ); ?></label>
228
			<select name="<?php echo esc_attr( $this->get_field_name( 'order' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'order' ) ); ?>" class="widefat">
229
			<?php
230
				$options = array(
231
					esc_html__( 'Ascending', 'lsx-projects' ) => 'ASC',
232
					esc_html__( 'Descending', 'lsx-projects' ) => 'DESC',
233
				);
234
235
				foreach ( $options as $name => $value ) {
236
					echo '<option value="' . esc_attr( $value ) . '" id="' . esc_attr( $value ) . '"', $order == $value ? ' selected="selected"' : '', '>', esc_html( $name ), '</option>';
237
				}
238
			?>
239
			</select>
240
		</p>
241
		<p class="limit">
242
			<label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php esc_html_e( 'Maximum amount:', 'lsx-projects' ); ?></label>
243
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'limit' ) ); ?>" type="text" value="<?php echo esc_attr( $limit ); ?>" />
244
			<small><?php esc_html_e( 'Leave empty to display all', 'lsx-projects' ); ?></small>
245
		</p>
246
		<p>
247
			<label for="<?php echo esc_attr( $this->get_field_id( 'include' ) ); ?>"><?php esc_html_e( 'Specify Projects by ID:', 'lsx-projects' ); ?></label>
248
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'include' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'include' ) ); ?>" type="text" value="<?php echo esc_attr( $include ); ?>" />
249
			<small><?php esc_html_e( 'Comma separated list, overrides limit and order settings', 'lsx-projects' ); ?></small>
250
		</p>
251
		<p>
252
			<label for="<?php echo esc_attr( $this->get_field_id( 'display' ) ); ?>"><?php esc_html_e( 'Display:', 'lsx-projects' ); ?></label>
253
			<select name="<?php echo esc_attr( $this->get_field_name( 'display' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'display' ) ); ?>" class="widefat">
254
			<?php
255
				$options = array(
256
					esc_html__( 'Excerpt', 'lsx-projects' ) => 'excerpt',
257
					esc_html__( 'Full Content', 'lsx-projects' ) => 'full',
258
				);
259
260
				foreach ( $options as $name => $value ) {
261
					echo '<option value="' . esc_attr( $value ) . '" id="' . esc_attr( $value ) . '"', $display == $value ? ' selected="selected"' : '', '>', esc_html( $name ), '</option>';
262
				}
263
			?>
264
			</select>
265
		</p>
266
		<p>
267
			<label for="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>"><?php esc_html_e( 'Image size:', 'lsx-projects' ); ?></label>
268
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'size' ) ); ?>" type="text" value="<?php echo esc_attr( $size ); ?>" />
269
		</p>
270
		<p>
271
			<label for="<?php echo esc_attr( $this->get_field_id( 'button_text' ) ); ?>"><?php esc_html_e( 'Button "view all" text:', 'lsx-projects' ); ?></label>
272
			<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'button_text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'button_text' ) ); ?>" type="text" value="<?php echo esc_attr( $button_text ); ?>" />
273
			<small><?php esc_html_e( 'Leave empty to not display the button', 'lsx-projects' ); ?></small>
274
		</p>
275
		<p>
276
			<input id="<?php echo esc_attr( $this->get_field_id( 'show_image' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_image' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $show_image ); ?> />
277
			<label for="<?php echo esc_attr( $this->get_field_id( 'show_image' ) ); ?>"><?php esc_html_e( 'Display Images', 'lsx-projects' ); ?></label>
278
		</p>
279
		<p>
280
			<input id="<?php echo esc_attr( $this->get_field_id( 'responsive' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'responsive' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $responsive ); ?> />
281
			<label for="<?php echo esc_attr( $this->get_field_id( 'responsive' ) ); ?>"><?php esc_html_e( 'Responsive Images', 'lsx-projects' ); ?></label>
282
		</p>
283
		<p>
284
			<input id="<?php echo esc_attr( $this->get_field_id( 'carousel' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'carousel' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $carousel ); ?> />
285
			<label for="<?php echo esc_attr( $this->get_field_id( 'carousel' ) ); ?>"><?php esc_html_e( 'Carousel', 'lsx-projects' ); ?></label>
286
		</p>
287
		<p>
288
			<input id="<?php echo esc_attr( $this->get_field_id( 'featured' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'featured' ) ); ?>" type="checkbox" value="1" <?php checked( '1', $featured ); ?> />
289
			<label for="<?php echo esc_attr( $this->get_field_id( 'featured' ) ); ?>"><?php esc_html_e( 'Featured posts', 'lsx-projects' ); ?></label>
290
		</p>
291
		<?php
292
	}
293
294
}
295
296
function lsx_projects_register_widget() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function lsx_projects_register_widget()
Loading history...
297
	return register_widget( 'LSX_Projects_Widget' );
298
}
299
add_action( 'widgets_init', 'lsx_projects_register_widget' );
300