Project

General

Profile

Support #9175 » widgets.php

Diane Krauthamer, 2018-02-28 10:39 PM

 
1
<?php
2
/**
3
 * Contains all the additional functions for child theme widget areas.
4
 *
5
 */
6
add_action( 'widgets_init', 'nlf_colormag_widgets_init' );
7
/**
8
 * Function to register the widget areas(sidebar) and widgets.
9
 */
10
function nlf_colormag_widgets_init() {
11

    
12
	/**
13
	 * Registering widget areas for front page
14
	 */
15
	// Registering main right sidebar
16
	register_sidebar( array(
17
		'name'          => esc_html__( 'Right Sidebar', 'colormag' ),
18
		'id'            => 'nlf_colormag_right_sidebar',
19
		'description'   => esc_html__( 'Shows widgets at Right side.', 'colormag' ),
20
		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
21
		'after_widget'  => '</aside>',
22
		'before_title'  => '<h3 class="widget-title"><span>',
23
		'after_title'   => '</span></h3>',
24
	) );
25

    
26
	// Registering main left sidebar
27
	register_sidebar( array(
28
		'name'          => esc_html__( 'Left Sidebar', 'colormag' ),
29
		'id'            => 'nlf_colormag_left_sidebar',
30
		'description'   => esc_html__( 'Shows widgets at Left side.', 'colormag' ),
31
		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
32
		'after_widget'  => '</aside>',
33
		'before_title'  => '<h3 class="widget-title"><span>',
34
		'after_title'   => '</span></h3>',
35
	) );
36

    
37
	// Registering Header sidebar
38
	register_sidebar( array(
39
		'name'          => esc_html__( 'Header Sidebar', 'colormag' ),
40
		'id'            => 'colormag_header_sidebar',
41
		'description'   => esc_html__( 'Shows widgets in header section just above the main navigation menu.', 'colormag' ),
42
		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
43
		'after_widget'  => '</aside>',
44
		'before_title'  => '<h3 class="widget-title">',
45
		'after_title'   => '</h3>',
46
	) );
47

    
48
	// registering the Front Page: Slider Area Sidebar
49
	register_sidebar( array(
50
		'name'          => esc_html__( 'Front Page: Slider Area', 'colormag' ),
51
		'id'            => 'colormag_front_page_slider_area',
52
		'description'   => esc_html__( 'Show widget just below menu. Suitable for TG: Featured Category Slider.', 'colormag' ),
53
		'before_widget' => '<section id="%1$s" class="widget %2$s clearfix">',
54
		'after_widget'  => '</section>',
55
		'before_title'  => '<h3 class="widget-title"><span>',
56
		'after_title'   => '</span></h3>',
57
	) );
58

    
59
	// registering the Front Page: Area beside slider Sidebar
60
	register_sidebar( array(
61
		'name'          => esc_html__( 'Front Page: Area beside slider', 'colormag' ),
62
		'id'            => 'colormag_front_page_area_beside_slider',
63
		'description'   => esc_html__( 'Show widget beside the slider. Suitable for TG: Highlighted Posts.', 'colormag' ),
64
		'before_widget' => '<section id="%1$s" class="widget %2$s clearfix">',
65
		'after_widget'  => '</section>',
66
		'before_title'  => '<h3 class="widget-title"><span>',
67
		'after_title'   => '</span></h3>',
68
	) );
69

    
70
	// registering the Front Page: Content Top Section Sidebar
71
	register_sidebar( array(
72
		'name'          => esc_html__( 'Front Page: Content Top Section', 'colormag' ),
73
		'id'            => 'colormag_front_page_content_top_section',
74
		'description'   => esc_html__( 'Content Top Section', 'colormag' ),
75
		'before_widget' => '<section id="%1$s" class="widget %2$s clearfix">',
76
		'after_widget'  => '</section>',
77
		'before_title'  => '<h3 class="widget-title"><span>',
78
		'after_title'   => '</span></h3>',
79
	) );
80

    
81
	// registering the Front Page: Content Middle Left Section Sidebar
82
	register_sidebar( array(
83
		'name'          => esc_html__( 'Front Page: Content Middle Left Section', 'colormag' ),
84
		'id'            => 'colormag_front_page_content_middle_left_section',
85
		'description'   => esc_html__( 'Content Middle Left Section', 'colormag' ),
86
		'before_widget' => '<section id="%1$s" class="widget %2$s clearfix">',
87
		'after_widget'  => '</section>',
88
		'before_title'  => '<h3 class="widget-title"><span>',
89
		'after_title'   => '</span></h3>',
90
	) );
91

    
92
	// registering the Front Page: Content Middle Right Section Sidebar
93
	register_sidebar( array(
94
		'name'          => esc_html__( 'Front Page: Content Middle Right Section', 'colormag' ),
95
		'id'            => 'colormag_front_page_content_middle_right_section',
96
		'description'   => esc_html__( 'Content Middle Right Section', 'colormag' ),
97
		'before_widget' => '<section id="%1$s" class="widget %2$s clearfix">',
98
		'after_widget'  => '</section>',
99
		'before_title'  => '<h3 class="widget-title"><span>',
100
		'after_title'   => '</span></h3>',
101
	) );
102

    
103
	// registering the Front Page: Content Bottom Section Sidebar
104
	register_sidebar( array(
105
		'name'          => esc_html__( 'Front Page: Content Bottom Section', 'colormag' ),
106
		'id'            => 'colormag_front_page_content_bottom_section',
107
		'description'   => esc_html__( 'Content Bottom Section', 'colormag' ),
108
		'before_widget' => '<section id="%1$s" class="widget %2$s clearfix">',
109
		'after_widget'  => '</section>',
110
		'before_title'  => '<h3 class="widget-title"><span>',
111
		'after_title'   => '</span></h3>',
112
	) );
113

    
114
	// Registering contact Page sidebar
115
	register_sidebar( array(
116
		'name'          => esc_html__( 'Contact Page Sidebar', 'colormag' ),
117
		'id'            => 'colormag_contact_page_sidebar',
118
		'description'   => esc_html__( 'Shows widgets on Contact Page Template.', 'colormag' ),
119
		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
120
		'after_widget'  => '</aside>',
121
		'before_title'  => '<h3 class="widget-title"><span>',
122
		'after_title'   => '</span></h3>',
123
	) );
124

    
125
	// Registering Error 404 Page sidebar
126
	register_sidebar( array(
127
		'name'          => esc_html__( 'Error 404 Page Sidebar', 'colormag' ),
128
		'id'            => 'colormag_error_404_page_sidebar',
129
		'description'   => esc_html__( 'Shows widgets on Error 404 page.', 'colormag' ),
130
		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
131
		'after_widget'  => '</aside>',
132
		'before_title'  => '<h3 class="widget-title"><span>',
133
		'after_title'   => '</span></h3>',
134
	) );
135

    
136
	// Registering advertisement above footer sidebar
137
	register_sidebar( array(
138
		'name'          => esc_html__( 'Advertisement Above The Footer', 'colormag' ),
139
		'id'            => 'colormag_advertisement_above_the_footer_sidebar',
140
		'description'   => esc_html__( 'Shows widgets just above the footer, suitable for TG: 728x90 Advertisement widget.', 'colormag' ),
141
		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
142
		'after_widget'  => '</aside>',
143
		'before_title'  => '<h3 class="widget-title"><span>',
144
		'after_title'   => '</span></h3>',
145
	) );
146

    
147
	// Registering footer sidebar one
148
	register_sidebar( array(
149
		'name'          => esc_html__( 'Footer Sidebar One', 'colormag' ),
150
		'id'            => 'colormag_footer_sidebar_one',
151
		'description'   => esc_html__( 'Shows widgets at footer sidebar one.', 'colormag' ),
152
		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
153
		'after_widget'  => '</aside>',
154
		'before_title'  => '<h3 class="widget-title"><span>',
155
		'after_title'   => '</span></h3>',
156
	) );
157

    
158
	// Registering footer sidebar two
159
	register_sidebar( array(
160
		'name'          => esc_html__( 'Footer Sidebar Two', 'colormag' ),
161
		'id'            => 'colormag_footer_sidebar_two',
162
		'description'   => esc_html__( 'Shows widgets at footer sidebar two.', 'colormag' ),
163
		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
164
		'after_widget'  => '</aside>',
165
		'before_title'  => '<h3 class="widget-title"><span>',
166
		'after_title'   => '</span></h3>',
167
	) );
168

    
169
	// Registering footer sidebar three
170
	register_sidebar( array(
171
		'name'          => esc_html__( 'Footer Sidebar Three', 'colormag' ),
172
		'id'            => 'colormag_footer_sidebar_three',
173
		'description'   => esc_html__( 'Shows widgets at footer sidebar three.', 'colormag' ),
174
		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
175
		'after_widget'  => '</aside>',
176
		'before_title'  => '<h3 class="widget-title"><span>',
177
		'after_title'   => '</span></h3>',
178
	) );
179

    
180
	// Registering footer sidebar four
181
	register_sidebar( array(
182
		'name'          => esc_html__( 'Footer Sidebar Four', 'colormag' ),
183
		'id'            => 'colormag_footer_sidebar_four',
184
		'description'   => esc_html__( 'Shows widgets at footer sidebar four.', 'colormag' ),
185
		'before_widget' => '<aside id="%1$s" class="widget %2$s clearfix">',
186
		'after_widget'  => '</aside>',
187
		'before_title'  => '<h3 class="widget-title"><span>',
188
		'after_title'   => '</span></h3>',
189
	) );
190

    
191
/**
192
 * Function to register the additional widgets.
193
 */
194
function nlf_colormag_widgets_init() {
195
	register_widget( "nlf_colormag_featured_posts_slider_widget" );
196
	register_widget( "nlf_colormag_highlighted_posts_widget" );
197
	register_widget( "nlf_colormag_featured_posts_widget" );
198
	register_widget( "nlf_colormag_featured_posts_vertical_widget" );
199
	register_widget( "nlf_colormag_728x90_advertisement_widget" );
200
	register_widget( "nlf_colormag_300x250_advertisement_widget" );
201
	register_widget( "nlf_colormag_125x125_advertisement_widget" );
202
}
203

    
204
/* * ************************************************************************************* */
205

    
206
/**
207
 * NLF Featured Posts widget
208
 */
209
class nlf_colormag_featured_posts_slider_widget extends WP_Widget {
210

    
211
	function __construct() {
212
		$widget_ops  = array( 'classname' => 'widget_featured_slider widget_featured_meta', 'description' => __( 'Display latest posts or posts of specific category, which will be used as the slider.', 'colormag' ) );
213
		$control_ops = array( 'width' => 200, 'height' => 250 );
214
		parent::__construct( false, $name = __( 'NLF: Featured Category Slider', 'colormag' ), $widget_ops );
215
	}
216

    
217
	function form( $instance ) {
218
		$tg_defaults[ 'number' ]   = 4;
219
		$tg_defaults[ 'type' ]     = 'latest';
220
		$tg_defaults[ 'category' ] = '';
221
		$instance                  = wp_parse_args( ( array ) $instance, $tg_defaults );
222
		$number                    = $instance[ 'number' ];
223
		$type                      = $instance[ 'type' ];
224
		$category                  = $instance[ 'category' ];
225
		?>
226
		<p>
227
			<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to display:', 'colormag' ); ?></label>
228
			<input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3"/>
229
		</p>
230

    
231
		<p>
232
			<input type="radio" <?php checked( $type, 'latest' ) ?> id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" value="latest"/><?php _e( 'Show latest Posts', 'colormag' ); ?>
233
			<br/>
234
			<input type="radio" <?php checked( $type, 'category' ) ?> id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" value="category"/><?php _e( 'Show posts from a category', 'colormag' ); ?>
235
			<br/></p>
236

    
237
		<p>
238
			<label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Select category', 'colormag' ); ?>
239
				:</label>
240
			<?php wp_dropdown_categories( array( 'show_option_none' => ' ', 'name' => $this->get_field_name( 'category' ), 'selected' => $category ) ); ?>
241
		</p>
242

    
243
		<?php
244
	}
245

    
246
	function update( $new_instance, $old_instance ) {
247
		$instance               = $old_instance;
248
		$instance[ 'number' ]   = absint( $new_instance[ 'number' ] );
249
		$instance[ 'type' ]     = $new_instance[ 'type' ];
250
		$instance[ 'category' ] = $new_instance[ 'category' ];
251

    
252
		return $instance;
253
	}
254

    
255
	function widget( $args, $instance ) {
256
		extract( $args );
257
		extract( $instance );
258

    
259
		global $post;
260
		$number   = empty( $instance[ 'number' ] ) ? 4 : $instance[ 'number' ];
261
		$type     = isset( $instance[ 'type' ] ) ? $instance[ 'type' ] : 'latest';
262
		$category = isset( $instance[ 'category' ] ) ? $instance[ 'category' ] : '';
263

    
264
		$post_status = 'publish';
265
		if ( get_option( 'fresh_site' ) == 1 ) {
266
			$post_status = array( 'auto-draft', 'publish' );
267
		}
268

    
269
		if ( $type == 'latest' ) {
270
			$get_featured_posts = new WP_Query( array(
271
				'posts_per_page'      => $number,
272
				'post_type'           => 'post',
273
				'ignore_sticky_posts' => true,
274
				'post_status'         => $post_status,
275
			) );
276
		} else {
277
			$get_featured_posts = new WP_Query( array(
278
				'posts_per_page' => $number,
279
				'post_type'      => 'post',
280
				'category__in'   => $category,
281
			) );
282
		}
283
		echo $before_widget;
284
		?>
285
		<?php $featured = 'colormag-featured-image'; ?>
286
		<div class="widget_slider_area_rotate">
287
			<?php
288
			$i = 1;
289
			while ( $get_featured_posts->have_posts() ):$get_featured_posts->the_post();
290

    
291
				if ( $i == 1 ) {
292
					$classes = "single-slide displayblock";
293
				} else {
294
					$classes = "single-slide displaynone";
295
				}
296
				?>
297
				<div class="<?php echo $classes; ?>">
298
					<?php
299
					if ( has_post_thumbnail() ) {
300
						$image           = '';
301
						$thumbnail_id    = get_post_thumbnail_id( $post->ID );
302
						$image_alt_text  = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true );
303
						$title_attribute = get_the_title( $post->ID );
304
						if ( empty( $image_alt_text ) ) {
305
							$image_alt_text = $title_attribute;
306
						}
307
						$image .= '<figure class="slider-featured-image">';
308
						$image .= '<a href="' . get_permalink() . '" title="' . the_title( '', '', false ) . '">';
309
						$image .= get_the_post_thumbnail( $post->ID, $featured, array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $image_alt_text ) ) ) . '</a>';
310
						$image .= '</figure>';
311
						echo $image;
312
					} else {
313
						?>
314
						<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
315
							<img src="<?php echo get_template_directory_uri(); ?>/img/slider-featured-image.png">
316
						</a>
317
					<?php }
318
					?>
319
					<div class="slide-content">
320
						<?php colormag_colored_category(); ?>
321
						<h3 class="entry-title">
322
							<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
323
						</h3>
324
						<div class="below-entry-meta">
325
							<?php
326
							$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
327
							$time_string = sprintf( $time_string, esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() )
328
							);
329
							printf( __( '<span class="posted-on"><a href="%1$s" title="%2$s" rel="bookmark"><i class="fa fa-calendar-o"></i> %3$s</a></span>', 'colormag' ), esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string
330
							);
331
							?>
332
							<span class="byline"><span class="author vcard"><i class="fa fa-user"></i><a class="url fn n" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" title="<?php echo get_the_author(); ?>"><?php echo coauthors_posts_links(null,null,null,null,false); ?></a></span></span>
333
                            
334
							<span class="comments"><i class="fa fa-comment"></i><?php comments_popup_link( '0', '1', '%' ); ?></span>
335
						</div>
336
					</div>
337

    
338
				</div>
339
				<?php
340
				$i ++;
341
			endwhile;
342
			// Reset Post Data
343
			wp_reset_query();
344
			?>
345
		</div>
346
		<?php
347
		echo $after_widget;
348
	}
349

    
350
}
351

    
352
/**
353
 * Highlighted Posts widget
354
 */
355
class nlf_colormag_highlighted_posts_widget extends WP_Widget {
356

    
357
	function __construct() {
358
		$widget_ops  = array( 'classname' => 'widget_highlighted_posts widget_featured_meta', 'description' => __( 'Display latest posts or posts of specific category. Suitable for the Area Beside Slider Sidebar.', 'colormag' ) );
359
		$control_ops = array( 'width' => 200, 'height' => 250 );
360
		parent::__construct( false, $name = __( 'NLF: Highlighted Posts', 'colormag' ), $widget_ops );
361
	}
362

    
363
	function form( $instance ) {
364
		$tg_defaults[ 'number' ]   = 4;
365
		$tg_defaults[ 'type' ]     = 'latest';
366
		$tg_defaults[ 'category' ] = '';
367
		$instance                  = wp_parse_args( ( array ) $instance, $tg_defaults );
368
		$number                    = $instance[ 'number' ];
369
		$type                      = $instance[ 'type' ];
370
		$category                  = $instance[ 'category' ];
371
		?>
372
		<p>
373
			<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to display:', 'colormag' ); ?></label>
374
			<input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3"/>
375
		</p>
376

    
377
		<p>
378
			<input type="radio" <?php checked( $type, 'latest' ) ?> id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" value="latest"/><?php _e( 'Show latest Posts', 'colormag' ); ?>
379
			<br/>
380
			<input type="radio" <?php checked( $type, 'category' ) ?> id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" value="category"/><?php _e( 'Show posts from a category', 'colormag' ); ?>
381
			<br/></p>
382

    
383
		<p>
384
			<label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Select category', 'colormag' ); ?>
385
				:</label>
386
			<?php wp_dropdown_categories( array( 'show_option_none' => ' ', 'name' => $this->get_field_name( 'category' ), 'selected' => $category ) ); ?>
387
		</p>
388
		<?php
389
	}
390

    
391
	function update( $new_instance, $old_instance ) {
392
		$instance               = $old_instance;
393
		$instance[ 'number' ]   = absint( $new_instance[ 'number' ] );
394
		$instance[ 'type' ]     = $new_instance[ 'type' ];
395
		$instance[ 'category' ] = $new_instance[ 'category' ];
396

    
397
		return $instance;
398
	}
399

    
400
	function widget( $args, $instance ) {
401
		extract( $args );
402
		extract( $instance );
403

    
404
		global $post;
405
		$number   = empty( $instance[ 'number' ] ) ? 4 : $instance[ 'number' ];
406
		$type     = isset( $instance[ 'type' ] ) ? $instance[ 'type' ] : 'latest';
407
		$category = isset( $instance[ 'category' ] ) ? $instance[ 'category' ] : '';
408

    
409
		$post_status = 'publish';
410
		if ( get_option( 'fresh_site' ) == 1 ) {
411
			$post_status = array( 'auto-draft', 'publish' );
412
		}
413

    
414
		if ( $type == 'latest' ) {
415
			$get_featured_posts = new WP_Query( array(
416
				'posts_per_page'      => $number,
417
				'post_type'           => 'post',
418
				'ignore_sticky_posts' => true,
419
				'post_status'         => $post_status,
420
			) );
421
		} else {
422
			$get_featured_posts = new WP_Query( array(
423
				'posts_per_page' => $number,
424
				'post_type'      => 'post',
425
				'category__in'   => $category,
426
			) );
427
		}
428
		echo $before_widget;
429
		?>
430
		<div class="widget_highlighted_post_area">
431
			<?php $featured = 'colormag-highlighted-post'; ?>
432
			<?php
433
			$i = 1;
434
			while ( $get_featured_posts->have_posts() ):$get_featured_posts->the_post();
435
				?>
436
				<div class="single-article">
437
					<?php
438
					if ( has_post_thumbnail() ) {
439
						$image           = '';
440
						$thumbnail_id    = get_post_thumbnail_id( $post->ID );
441
						$image_alt_text  = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true );
442
						$title_attribute = get_the_title( $post->ID );
443
						if ( empty( $image_alt_text ) ) {
444
							$image_alt_text = $title_attribute;
445
						}
446
						$image .= '<figure class="highlights-featured-image">';
447
						$image .= '<a href="' . get_permalink() . '" title="' . the_title( '', '', false ) . '">';
448
						$image .= get_the_post_thumbnail( $post->ID, $featured, array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $image_alt_text ) ) ) . '</a>';
449
						$image .= '</figure>';
450
						echo $image;
451
					} else {
452
						?>
453
						<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
454
							<img src="<?php echo get_template_directory_uri(); ?>/img/highlights-featured-image.png">
455
						</a>
456
					<?php }
457
					?>
458
					<div class="article-content">
459
						<?php colormag_colored_category(); ?>
460
						<h3 class="entry-title">
461
							<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
462
						</h3>
463
						<div class="below-entry-meta">
464
							<?php
465
							$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
466
							$time_string = sprintf( $time_string, esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() )
467
							);
468
							printf( __( '<span class="posted-on"><a href="%1$s" title="%2$s" rel="bookmark"><i class="fa fa-calendar-o"></i> %3$s</a></span>', 'colormag' ), esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string
469
							);
470
							?>
471
							<span class="byline"><span class="author vcard"><i class="fa fa-user"></i><a class="url fn n" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" title="<?php echo get_the_author(); ?>"><?php echo coauthors_posts_links(null, null, null, null, false ); ?></a></span></span>
472
							<span class="comments"><i class="fa fa-comment"></i><?php comments_popup_link( '0', '1', '%' ); ?></span>
473
						</div>
474
					</div>
475

    
476
				</div>
477
				<?php
478
				$i ++;
479
			endwhile;
480
			// Reset Post Data
481
			wp_reset_query();
482
			?>
483
		</div>
484
		<?php
485
		echo $after_widget;
486
	}
487

    
488
}
489

    
490
/**
491
 * Featured Posts widget
492
 */
493
class nlf_colormag_featured_posts_widget extends WP_Widget {
494

    
495
	function __construct() {
496
		$widget_ops  = array( 'classname' => 'widget_featured_posts widget_featured_meta', 'description' => __( 'Display latest posts or posts of specific category.', 'colormag' ) );
497
		$control_ops = array( 'width' => 200, 'height' => 250 );
498
		parent::__construct( false, $name = __( 'NLF: Featured Posts (Style 1)', 'colormag' ), $widget_ops );
499
	}
500

    
501
	function form( $instance ) {
502
		$tg_defaults[ 'title' ]    = '';
503
		$tg_defaults[ 'text' ]     = '';
504
		$tg_defaults[ 'number' ]   = 4;
505
		$tg_defaults[ 'type' ]     = 'latest';
506
		$tg_defaults[ 'category' ] = '';
507
		$instance                  = wp_parse_args( ( array ) $instance, $tg_defaults );
508
		$title                     = esc_attr( $instance[ 'title' ] );
509
		$text                      = esc_textarea( $instance[ 'text' ] );
510
		$number                    = $instance[ 'number' ];
511
		$type                      = $instance[ 'type' ];
512
		$category                  = $instance[ 'category' ];
513
		?>
514
		<p><?php _e( 'Layout will be as below:', 'colormag' ) ?></p>
515
		<div style="text-align: center;"><img src="<?php echo get_template_directory_uri() . '/img/style-1.jpg' ?>">
516
		</div>
517
		<p>
518
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'colormag' ); ?></label>
519
			<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>"/>
520
		</p>
521
		<?php _e( 'Description', 'colormag' ); ?>
522
		<textarea class="widefat" rows="5" cols="20" id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>"><?php echo $text; ?></textarea>
523
		<p>
524
			<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to display:', 'colormag' ); ?></label>
525
			<input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3"/>
526
		</p>
527

    
528
		<p>
529
			<input type="radio" <?php checked( $type, 'latest' ) ?> id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" value="latest"/><?php _e( 'Show latest Posts', 'colormag' ); ?>
530
			<br/>
531
			<input type="radio" <?php checked( $type, 'category' ) ?> id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" value="category"/><?php _e( 'Show posts from a category', 'colormag' ); ?>
532
			<br/></p>
533

    
534
		<p>
535
			<label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Select category', 'colormag' ); ?>
536
				:</label>
537
			<?php wp_dropdown_categories( array( 'show_option_none' => ' ', 'name' => $this->get_field_name( 'category' ), 'selected' => $category ) ); ?>
538
		</p>
539
		<?php
540
	}
541

    
542
	function update( $new_instance, $old_instance ) {
543
		$instance            = $old_instance;
544
		$instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] );
545
		if ( current_user_can( 'unfiltered_html' ) ) {
546
			$instance[ 'text' ] = $new_instance[ 'text' ];
547
		} else {
548
			$instance[ 'text' ] = stripslashes( wp_filter_post_kses( addslashes( $new_instance[ 'text' ] ) ) );
549
		}
550
		$instance[ 'number' ]   = absint( $new_instance[ 'number' ] );
551
		$instance[ 'type' ]     = $new_instance[ 'type' ];
552
		$instance[ 'category' ] = $new_instance[ 'category' ];
553

    
554
		return $instance;
555
	}
556

    
557
	function widget( $args, $instance ) {
558
		extract( $args );
559
		extract( $instance );
560

    
561
		global $post;
562
		$title    = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : '';
563
		$text     = isset( $instance[ 'text' ] ) ? $instance[ 'text' ] : '';
564
		$number   = empty( $instance[ 'number' ] ) ? 4 : $instance[ 'number' ];
565
		$type     = isset( $instance[ 'type' ] ) ? $instance[ 'type' ] : 'latest';
566
		$category = isset( $instance[ 'category' ] ) ? $instance[ 'category' ] : '';
567

    
568
		$post_status = 'publish';
569
		if ( get_option( 'fresh_site' ) == 1 ) {
570
			$post_status = array( 'auto-draft', 'publish' );
571
		}
572

    
573
		if ( $type == 'latest' ) {
574
			$get_featured_posts = new WP_Query( array(
575
				'posts_per_page'      => $number,
576
				'post_type'           => 'post',
577
				'ignore_sticky_posts' => true,
578
				'post_status'         => $post_status,
579
			) );
580
		} else {
581
			$get_featured_posts = new WP_Query( array(
582
				'posts_per_page' => $number,
583
				'post_type'      => 'post',
584
				'category__in'   => $category,
585
			) );
586
		}
587

    
588
		echo $before_widget;
589
		?>
590
		<?php
591
		if ( $type != 'latest' ) {
592
			$border_color = 'style="border-bottom-color:' . colormag_category_color( $category ) . ';"';
593
			$title_color  = 'style="background-color:' . colormag_category_color( $category ) . ';"';
594
		} else {
595
			$border_color = '';
596
			$title_color  = '';
597
		}
598
		if ( ! empty( $title ) ) {
599
			echo '<h3 class="widget-title" ' . $border_color . '><span ' . $title_color . '>' . esc_html( $title ) . '</span></h3>';
600
		}
601
		if ( ! empty( $text ) ) {
602
			?> <p> <?php echo esc_textarea( $text ); ?> </p> <?php } ?>
603
		<?php
604
		$i = 1;
605
		while ( $get_featured_posts->have_posts() ):$get_featured_posts->the_post();
606
			?>
607
			<?php if ( $i == 1 ) {
608
				$featured = 'colormag-featured-post-medium';
609
			} else {
610
				$featured = 'colormag-featured-post-small';
611
			} ?>
612
			<?php if ( $i == 1 ) {
613
				echo '<div class="first-post">';
614
			} else if ( $i == 2 ) {
615
				echo '<div class="following-post">';
616
			} ?>
617
			<div class="single-article clearfix">
618
				<?php
619
				if ( has_post_thumbnail() ) {
620
					$image           = '';
621
					$thumbnail_id    = get_post_thumbnail_id( $post->ID );
622
					$image_alt_text  = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true );
623
					$title_attribute = get_the_title( $post->ID );
624
					if ( empty( $image_alt_text ) ) {
625
						$image_alt_text = $title_attribute;
626
					}
627
					$image .= '<figure>';
628
					$image .= '<a href="' . get_permalink() . '" title="' . the_title( '', '', false ) . '">';
629
					$image .= get_the_post_thumbnail( $post->ID, $featured, array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $image_alt_text ) ) ) . '</a>';
630
					$image .= '</figure>';
631
					echo $image;
632
				}
633
				?>
634
				<div class="article-content">
635
					<?php colormag_colored_category(); ?>
636
					<h3 class="entry-title">
637
						<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
638
					</h3>
639
					<div class="below-entry-meta">
640
						<?php
641
						$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
642
						$time_string = sprintf( $time_string, esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() )
643
						);
644
						printf( __( '<span class="posted-on"><a href="%1$s" title="%2$s" rel="bookmark"><i class="fa fa-calendar-o"></i> %3$s</a></span>', 'colormag' ), esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string
645
						);
646
						?>
647
						<span class="byline"><span class="author vcard"><i class="fa fa-user"></i><a class="url fn n" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" title="<?php echo get_the_author(); ?>"><?php echo echo coauthors_posts_links(null, null, null, null, false ); ?></a></span></span>
648
						<span class="comments"><i class="fa fa-comment"></i><?php comments_popup_link( '0', '1', '%' ); ?></span>
649
					</div>
650
					<?php if ( $i == 1 ) { ?>
651
						<div class="entry-content">
652
							<?php the_excerpt(); ?>
653
						</div>
654
					<?php } ?>
655
				</div>
656

    
657
			</div>
658
			<?php if ( $i == 1 ) {
659
				echo '</div>';
660
			} ?>
661
			<?php
662
			$i ++;
663
		endwhile;
664
		if ( $i > 2 ) {
665
			echo '</div>';
666
		}
667
		// Reset Post Data
668
		wp_reset_query();
669
		?>
670
		<!-- </div> -->
671
		<?php
672
		echo $after_widget;
673
	}
674

    
675
}
676

    
677
/**
678
 * Featured Posts widget
679
 */
680
class nlf_colormag_featured_posts_vertical_widget extends WP_Widget {
681

    
682
	function __construct() {
683
		$widget_ops  = array( 'classname' => 'widget_featured_posts widget_featured_posts_vertical widget_featured_meta', 'description' => __( 'Display latest posts or posts of specific category.', 'colormag' ) );
684
		$control_ops = array( 'width' => 200, 'height' => 250 );
685
		parent::__construct( false, $name = __( 'TG: Featured Posts (Style 2)', 'colormag' ), $widget_ops );
686
	}
687

    
688
	function form( $instance ) {
689
		$tg_defaults[ 'title' ]    = '';
690
		$tg_defaults[ 'text' ]     = '';
691
		$tg_defaults[ 'number' ]   = 4;
692
		$tg_defaults[ 'type' ]     = 'latest';
693
		$tg_defaults[ 'category' ] = '';
694
		$instance                  = wp_parse_args( ( array ) $instance, $tg_defaults );
695
		$title                     = esc_attr( $instance[ 'title' ] );
696
		$text                      = esc_textarea( $instance[ 'text' ] );
697
		$number                    = $instance[ 'number' ];
698
		$type                      = $instance[ 'type' ];
699
		$category                  = $instance[ 'category' ];
700
		?>
701
		<p><?php _e( 'Layout will be as below:', 'colormag' ) ?></p>
702
		<div style="text-align: center;"><img src="<?php echo get_template_directory_uri() . '/img/style-2.jpg' ?>">
703
		</div>
704
		<p>
705
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'colormag' ); ?></label>
706
			<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>"/>
707
		</p>
708
		<?php _e( 'Description', 'colormag' ); ?>
709
		<textarea class="widefat" rows="5" cols="20" id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>"><?php echo $text; ?></textarea>
710
		<p>
711
			<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to display:', 'colormag' ); ?></label>
712
			<input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3"/>
713
		</p>
714

    
715
		<p>
716
			<input type="radio" <?php checked( $type, 'latest' ) ?> id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" value="latest"/><?php _e( 'Show latest Posts', 'colormag' ); ?>
717
			<br/>
718
			<input type="radio" <?php checked( $type, 'category' ) ?> id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>" value="category"/><?php _e( 'Show posts from a category', 'colormag' ); ?>
719
			<br/></p>
720

    
721
		<p>
722
			<label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Select category', 'colormag' ); ?>
723
				:</label>
724
			<?php wp_dropdown_categories( array( 'show_option_none' => ' ', 'name' => $this->get_field_name( 'category' ), 'selected' => $category ) ); ?>
725
		</p>
726
		<?php
727
	}
728

    
729
	function update( $new_instance, $old_instance ) {
730
		$instance            = $old_instance;
731
		$instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] );
732
		if ( current_user_can( 'unfiltered_html' ) ) {
733
			$instance[ 'text' ] = $new_instance[ 'text' ];
734
		} else {
735
			$instance[ 'text' ] = stripslashes( wp_filter_post_kses( addslashes( $new_instance[ 'text' ] ) ) );
736
		}
737
		$instance[ 'number' ]   = absint( $new_instance[ 'number' ] );
738
		$instance[ 'type' ]     = $new_instance[ 'type' ];
739
		$instance[ 'category' ] = $new_instance[ 'category' ];
740

    
741
		return $instance;
742
	}
743

    
744
	function widget( $args, $instance ) {
745
		extract( $args );
746
		extract( $instance );
747

    
748
		global $post;
749
		$title    = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : '';
750
		$text     = isset( $instance[ 'text' ] ) ? $instance[ 'text' ] : '';
751
		$number   = empty( $instance[ 'number' ] ) ? 4 : $instance[ 'number' ];
752
		$type     = isset( $instance[ 'type' ] ) ? $instance[ 'type' ] : 'latest';
753
		$category = isset( $instance[ 'category' ] ) ? $instance[ 'category' ] : '';
754

    
755
		$post_status = 'publish';
756
		if ( get_option( 'fresh_site' ) == 1 ) {
757
			$post_status = array( 'auto-draft', 'publish' );
758
		}
759

    
760
		if ( $type == 'latest' ) {
761
			$get_featured_posts = new WP_Query( array(
762
				'posts_per_page'      => $number,
763
				'post_type'           => 'post',
764
				'ignore_sticky_posts' => true,
765
				'post_status'         => $post_status,
766
			) );
767
		} else {
768
			$get_featured_posts = new WP_Query( array(
769
				'posts_per_page' => $number,
770
				'post_type'      => 'post',
771
				'category__in'   => $category,
772
			) );
773
		}
774
		echo $before_widget;
775
		?>
776
		<?php
777
		if ( $type != 'latest' ) {
778
			$border_color = 'style="border-bottom-color:' . colormag_category_color( $category ) . ';"';
779
			$title_color  = 'style="background-color:' . colormag_category_color( $category ) . ';"';
780
		} else {
781
			$border_color = '';
782
			$title_color  = '';
783
		}
784
		if ( ! empty( $title ) ) {
785
			echo '<h3 class="widget-title" ' . $border_color . '><span ' . $title_color . '>' . esc_html( $title ) . '</span></h3>';
786
		}
787
		if ( ! empty( $text ) ) {
788
			?> <p> <?php echo esc_textarea( $text ); ?> </p> <?php } ?>
789
		<?php
790
		$i = 1;
791
		while ( $get_featured_posts->have_posts() ):$get_featured_posts->the_post();
792
			?>
793
			<?php if ( $i == 1 ) {
794
				$featured = 'colormag-featured-post-medium';
795
			} else {
796
				$featured = 'colormag-featured-post-small';
797
			} ?>
798
			<?php if ( $i == 1 ) {
799
				echo '<div class="first-post">';
800
			} else if ( $i == 2 ) {
801
				echo '<div class="following-post">';
802
			} ?>
803
			<div class="single-article clearfix">
804
				<?php
805
				if ( has_post_thumbnail() ) {
806
					$image           = '';
807
					$thumbnail_id    = get_post_thumbnail_id( $post->ID );
808
					$image_alt_text  = get_post_meta( $thumbnail_id, '_wp_attachment_image_alt', true );
809
					$title_attribute = get_the_title( $post->ID );
810
					if ( empty( $image_alt_text ) ) {
811
						$image_alt_text = $title_attribute;
812
					}
813
					$image .= '<figure>';
814
					$image .= '<a href="' . get_permalink() . '" title="' . the_title( '', '', false ) . '">';
815
					$image .= get_the_post_thumbnail( $post->ID, $featured, array( 'title' => esc_attr( $title_attribute ), 'alt' => esc_attr( $image_alt_text ) ) ) . '</a>';
816
					$image .= '</figure>';
817
					echo $image;
818
				}
819
				?>
820
				<div class="article-content">
821
					<?php colormag_colored_category(); ?>
822
					<h3 class="entry-title">
823
						<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
824
					</h3>
825
					<div class="below-entry-meta">
826
						<?php
827
						$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time>';
828
						$time_string = sprintf( $time_string, esc_attr( get_the_date( 'c' ) ), esc_html( get_the_date() )
829
						);
830
						printf( __( '<span class="posted-on"><a href="%1$s" title="%2$s" rel="bookmark"><i class="fa fa-calendar-o"></i> %3$s</a></span>', 'colormag' ), esc_url( get_permalink() ), esc_attr( get_the_time() ), $time_string
831
						);
832
						?>
833
						<span class="byline"><span class="author vcard"><i class="fa fa-user"></i><a class="url fn n" href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" title="<?php echo get_the_author(); ?>"><?php echo coauthors_posts_links(null, null, null, null, false ); ?></a></span></span>
834
						<span class="comments"><i class="fa fa-comment"></i><?php comments_popup_link( '0', '1', '%' ); ?></span>
835
					</div>
836
					<?php if ( $i == 1 ) { ?>
837
						<div class="entry-content">
838
							<?php the_excerpt(); ?>
839
						</div>
840
					<?php } ?>
841
				</div>
842

    
843
			</div>
844
			<?php if ( $i == 1 ) {
845
				echo '</div>';
846
			} ?>
847
			<?php
848
			$i ++;
849
		endwhile;
850
		if ( $i > 2 ) {
851
			echo '</div>';
852
		}
853
		// Reset Post Data
854
		wp_reset_query();
855
		?>
856
		<?php
857
		echo $after_widget;
858
	}
859

    
860
}
861

    
862
/* * ************************************************************************************* */
863

    
864
/**
865
 * 300x250 Advertisement Ads
866
 */
867
class nlf_colormag_300x250_advertisement_widget extends WP_Widget {
868

    
869
	function __construct() {
870
		$widget_ops  = array( 'classname' => 'widget_300x250_advertisement', 'description' => __( 'Add your 300x250 Advertisement here', 'colormag' ) );
871
		$control_ops = array( 'width' => 200, 'height' => 250 );
872
		parent::__construct( false, $name = __( 'NLF: 300x250 Advertisement', 'colormag' ), $widget_ops );
873
	}
874

    
875
	function form( $instance ) {
876
		$instance = wp_parse_args( ( array ) $instance, array( 'title' => '', '300x250_image_url' => '', '300x250_image_link' => '' ) );
877
		$title    = esc_attr( $instance[ 'title' ] );
878

    
879
		$image_link = '300x250_image_link';
880
		$image_url  = '300x250_image_url';
881

    
882
		$instance[ $image_link ] = esc_url( $instance[ $image_link ] );
883
		$instance[ $image_url ]  = esc_url( $instance[ $image_url ] );
884
		?>
885

    
886
		<p>
887
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'colormag' ); ?></label>
888
			<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>"/>
889
		</p>
890
		<label><?php _e( 'Add your Advertisement 300x250 Images Here', 'colormag' ); ?></label>
891
		<p>
892
			<label for="<?php echo $this->get_field_id( $image_link ); ?>"> <?php _e( 'Advertisement Image Link ', 'colormag' ); ?></label>
893
			<input type="text" class="widefat" id="<?php echo $this->get_field_id( $image_link ); ?>" name="<?php echo $this->get_field_name( $image_link ); ?>" value="<?php echo $instance[ $image_link ]; ?>"/>
894
		</p>
895
		<p>
896
			<label for="<?php echo $this->get_field_id( $image_url ); ?>"> <?php _e( 'Advertisement Image ', 'colormag' ); ?></label>
897
		<div class="media-uploader" id="<?php echo $this->get_field_id( $image_url ); ?>">
898
			<div class="custom_media_preview">
899
				<?php if ( $instance[ $image_url ] != '' ) : ?>
900
					<img class="custom_media_preview_default" src="<?php echo esc_url( $instance[ $image_url ] ); ?>" style="max-width:100%;"/>
901
				<?php endif; ?>
902
			</div>
903
			<input type="text" class="widefat custom_media_input" id="<?php echo $this->get_field_id( $image_url ); ?>" name="<?php echo $this->get_field_name( $image_url ); ?>" value="<?php echo esc_url( $instance[ $image_url ] ); ?>" style="margin-top:5px;"/>
904
			<button class="custom_media_upload button button-secondary button-large" id="<?php echo $this->get_field_id( $image_url ); ?>" data-choose="<?php esc_attr_e( 'Choose an image', 'colormag' ); ?>" data-update="<?php esc_attr_e( 'Use image', 'colormag' ); ?>" style="width:100%;margin-top:6px;margin-right:30px;"><?php esc_html_e( 'Select an Image', 'colormag' ); ?></button>
905
		</div>
906
		</p>
907

    
908
		<?php
909
	}
910

    
911
	function update( $new_instance, $old_instance ) {
912
		$instance            = $old_instance;
913
		$instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] );
914

    
915
		$image_link = '300x250_image_link';
916
		$image_url  = '300x250_image_url';
917

    
918
		$instance[ $image_link ] = esc_url_raw( $new_instance[ $image_link ] );
919
		$instance[ $image_url ]  = esc_url_raw( $new_instance[ $image_url ] );
920

    
921
		return $instance;
922
	}
923

    
924
	function widget( $args, $instance ) {
925
		extract( $args );
926
		extract( $instance );
927

    
928
		$title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : '';
929

    
930
		$image_link = '300x250_image_link';
931
		$image_url  = '300x250_image_url';
932

    
933
		$image_link = isset( $instance[ $image_link ] ) ? $instance[ $image_link ] : '';
934
		$image_url  = isset( $instance[ $image_url ] ) ? $instance[ $image_url ] : '';
935

    
936
		echo $before_widget;
937
		?>
938

    
939
		<div class="advertisement_300x250">
940
			<?php if ( ! empty( $title ) ) { ?>
941
				<div class="advertisement-title">
942
					<?php echo $before_title . esc_html( $title ) . $after_title; ?>
943
				</div>
944
				<?php
945
			}
946
			$output = '';
947
			if ( ! empty( $image_url ) ) {
948
				$image_id  = attachment_url_to_postid( $image_url );
949
				$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
950
				$output    .= '<div class="advertisement-content">';
951
				if ( ! empty( $image_link ) ) {
952
					$output .= '<a href="' . $image_link . '" class="single_ad_300x250" target="_blank" rel="nofollow">
953
                                    <img src="' . $image_url . '" width="300" height="250" alt="' . $image_alt . '">
954
                           </a>';
955
				} else {
956
					$output .= '<img src="' . $image_url . '" width="300" height="250" alt="' . $image_alt . '">';
957
				}
958
				$output .= '</div>';
959
				echo $output;
960
			}
961
			?>
962
		</div>
963
		<?php
964
		echo $after_widget;
965
	}
966

    
967
}
968

    
969
/* * ************************************************************************************* */
970

    
971
/**
972
 * 728x90 Advertisement Ads
973
 */
974
class nlf_colormag_728x90_advertisement_widget extends WP_Widget {
975

    
976
	function __construct() {
977
		$widget_ops  = array( 'classname' => 'widget_728x90_advertisement', 'description' => __( 'Add your 728x90 Advertisement here', 'colormag' ) );
978
		$control_ops = array( 'width' => 200, 'height' => 250 );
979
		parent::__construct( false, $name = __( 'NLF: 728x90 Advertisement', 'colormag' ), $widget_ops );
980
	}
981

    
982
	function form( $instance ) {
983
		$instance = wp_parse_args( ( array ) $instance, array( 'title' => '', '728x90_image_url' => '', '728x90_image_link' => '' ) );
984
		$title    = esc_attr( $instance[ 'title' ] );
985

    
986
		$image_link = '728x90_image_link';
987
		$image_url  = '728x90_image_url';
988

    
989
		$instance[ $image_link ] = esc_url( $instance[ $image_link ] );
990
		$instance[ $image_url ]  = esc_url( $instance[ $image_url ] );
991
		?>
992

    
993
		<p>
994
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'colormag' ); ?></label>
995
			<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>"/>
996
		</p>
997
		<label><?php _e( 'Add your Advertisement 728x90 Images Here', 'colormag' ); ?></label>
998
		<p>
999
			<label for="<?php echo $this->get_field_id( $image_link ); ?>"> <?php _e( 'Advertisement Image Link ', 'colormag' ); ?></label>
1000
			<input type="text" class="widefat" id="<?php echo $this->get_field_id( $image_link ); ?>" name="<?php echo $this->get_field_name( $image_link ); ?>" value="<?php echo $instance[ $image_link ]; ?>"/>
1001
		</p>
1002
		<p>
1003
			<label for="<?php echo $this->get_field_id( $image_url ); ?>"> <?php _e( 'Advertisement Image ', 'colormag' ); ?></label>
1004
		<div class="media-uploader" id="<?php echo $this->get_field_id( $image_url ); ?>">
1005
			<div class="custom_media_preview">
1006
				<?php if ( $instance[ $image_url ] != '' ) : ?>
1007
					<img class="custom_media_preview_default" src="<?php echo esc_url( $instance[ $image_url ] ); ?>" style="max-width:100%;"/>
1008
				<?php endif; ?>
1009
			</div>
1010
			<input type="text" class="widefat custom_media_input" id="<?php echo $this->get_field_id( $image_url ); ?>" name="<?php echo $this->get_field_name( $image_url ); ?>" value="<?php echo esc_url( $instance[ $image_url ] ); ?>" style="margin-top:5px;"/>
1011
			<button class="custom_media_upload button button-secondary button-large" id="<?php echo $this->get_field_id( $image_url ); ?>" data-choose="<?php esc_attr_e( 'Choose an image', 'colormag' ); ?>" data-update="<?php esc_attr_e( 'Use image', 'colormag' ); ?>" style="width:100%;margin-top:6px;margin-right:30px;"><?php esc_html_e( 'Select an Image', 'colormag' ); ?></button>
1012
		</div>
1013
		</p>
1014

    
1015
		<?php
1016
	}
1017

    
1018
	function update( $new_instance, $old_instance ) {
1019
		$instance            = $old_instance;
1020
		$instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] );
1021

    
1022
		$image_link = '728x90_image_link';
1023
		$image_url  = '728x90_image_url';
1024

    
1025
		$instance[ $image_link ] = esc_url_raw( $new_instance[ $image_link ] );
1026
		$instance[ $image_url ]  = esc_url_raw( $new_instance[ $image_url ] );
1027

    
1028
		return $instance;
1029
	}
1030

    
1031
	function widget( $args, $instance ) {
1032
		extract( $args );
1033
		extract( $instance );
1034

    
1035
		$title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : '';
1036

    
1037

    
1038
		$image_link = '728x90_image_link';
1039
		$image_url  = '728x90_image_url';
1040

    
1041
		$image_link = isset( $instance[ $image_link ] ) ? $instance[ $image_link ] : '';
1042
		$image_url  = isset( $instance[ $image_url ] ) ? $instance[ $image_url ] : '';
1043

    
1044
		echo $before_widget;
1045
		?>
1046

    
1047
		<div class="advertisement_728x90">
1048
			<?php if ( ! empty( $title ) ) { ?>
1049
				<div class="advertisement-title">
1050
					<?php echo $before_title . esc_html( $title ) . $after_title; ?>
1051
				</div>
1052
				<?php
1053
			}
1054
			$output    = '';
1055
			$image_id  = attachment_url_to_postid( $image_url );
1056
			$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
1057
			if ( ! empty( $image_url ) ) {
1058
				$output .= '<div class="advertisement-content">';
1059
				if ( ! empty( $image_link ) ) {
1060
					$image_id  = attachment_url_to_postid( $image_url );
1061
					$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
1062
					$output    .= '<a href="' . $image_link . '" class="single_ad_728x90" target="_blank" rel="nofollow">
1063
                                    <img src="' . $image_url . '" width="728" height="90" alt="' . $image_alt . '">
1064
                           </a>';
1065
				} else {
1066
					$output .= '<img src="' . $image_url . '" width="728" height="90" alt="' . $image_alt . '">';
1067
				}
1068
				$output .= '</div>';
1069
				echo $output;
1070
			}
1071
			?>
1072
		</div>
1073
		<?php
1074
		echo $after_widget;
1075
	}
1076

    
1077
}
1078

    
1079
/* * ************************************************************************************* */
1080

    
1081
/**
1082
 * 125x125 Advertisement Ads
1083
 */
1084
class nlf_colormag_125x125_advertisement_widget extends WP_Widget {
1085

    
1086
	function __construct() {
1087
		$widget_ops  = array( 'classname' => 'widget_125x125_advertisement', 'description' => __( 'Add your 125x125 Advertisement here', 'colormag' ) );
1088
		$control_ops = array( 'width' => 200, 'height' => 250 );
1089
		parent::__construct( false, $name = __( 'NLF: 125x125 Advertisement', 'colormag' ), $widget_ops );
1090
	}
1091

    
1092
	function form( $instance ) {
1093
		$instance = wp_parse_args( ( array ) $instance, array( 'title' => '', '125x125_image_url_1' => '', '125x125_image_url_2' => '', '125x125_image_url_3' => '', '125x125_image_url_4' => '', '125x125_image_url_5' => '', '125x125_image_url_6' => '', '125x125_image_link_1' => '', '125x125_image_link_2' => '', '125x125_image_link_3' => '', '125x125_image_link_4' => '', '125x125_image_link_5' => '', '125x125_image_link_6' => '' ) );
1094
		$title    = esc_attr( $instance[ 'title' ] );
1095
		for ( $i = 1; $i < 7; $i ++ ) {
1096
			$image_link = '125x125_image_link_' . $i;
1097
			$image_url  = '125x125_image_url_' . $i;
1098

    
1099
			$instance[ $image_link ] = esc_url( $instance[ $image_link ] );
1100
			$instance[ $image_url ]  = esc_url( $instance[ $image_url ] );
1101
		}
1102
		?>
1103

    
1104
		<p>
1105
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'colormag' ); ?></label>
1106
			<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>"/>
1107
		</p>
1108
		<label><?php _e( 'Add your Advertisement 125x125 Images Here', 'colormag' ); ?></label>
1109
		<?php
1110
		for ( $i = 1; $i < 7; $i ++ ) {
1111
			$image_link = '125x125_image_link_' . $i;
1112
			$image_url  = '125x125_image_url_' . $i;
1113
			?>
1114
			<p>
1115
				<label for="<?php echo $this->get_field_id( $image_link ); ?>"> <?php _e( 'Advertisement Image Link ', 'colormag' );
1116
					echo $i; ?></label>
1117
				<input type="text" class="widefat" id="<?php echo $this->get_field_id( $image_link ); ?>" name="<?php echo $this->get_field_name( $image_link ); ?>" value="<?php echo $instance[ $image_link ]; ?>"/>
1118
			</p>
1119
			<p>
1120
				<label for="<?php echo $this->get_field_id( $image_url ); ?>"> <?php _e( 'Advertisement Image ', 'colormag' );
1121
					echo $i; ?></label>
1122
			<div class="media-uploader" id="<?php echo $this->get_field_id( $image_url ); ?>">
1123
				<div class="custom_media_preview">
1124
					<?php if ( $instance[ $image_url ] != '' ) : ?>
1125
						<img class="custom_media_preview_default" src="<?php echo esc_url( $instance[ $image_url ] ); ?>" style="max-width:100%;"/>
1126
					<?php endif; ?>
1127
				</div>
1128
				<input type="text" class="widefat custom_media_input" id="<?php echo $this->get_field_id( $image_url ); ?>" name="<?php echo $this->get_field_name( $image_url ); ?>" value="<?php echo esc_url( $instance[ $image_url ] ); ?>" style="margin-top:5px;"/>
1129
				<button class="custom_media_upload button button-secondary button-large" id="<?php echo $this->get_field_id( $image_url ); ?>" data-choose="<?php esc_attr_e( 'Choose an image', 'colormag' ); ?>" data-update="<?php esc_attr_e( 'Use image', 'colormag' ); ?>" style="width:100%;margin-top:6px;margin-right:30px;"><?php esc_html_e( 'Select an Image', 'colormag' ); ?></button>
1130
			</div>
1131
			</p>
1132
		<?php } ?>
1133

    
1134
		<?php
1135
	}
1136

    
1137
	function update( $new_instance, $old_instance ) {
1138
		$instance            = $old_instance;
1139
		$instance[ 'title' ] = strip_tags( $new_instance[ 'title' ] );
1140
		for ( $i = 1; $i < 7; $i ++ ) {
1141
			$image_link = '125x125_image_link_' . $i;
1142
			$image_url  = '125x125_image_url_' . $i;
1143

    
1144
			$instance[ $image_link ] = esc_url_raw( $new_instance[ $image_link ] );
1145
			$instance[ $image_url ]  = esc_url_raw( $new_instance[ $image_url ] );
1146
		}
1147

    
1148
		return $instance;
1149
	}
1150

    
1151
	function widget( $args, $instance ) {
1152
		extract( $args );
1153
		extract( $instance );
1154

    
1155
		$title       = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : '';
1156
		$image_array = array();
1157
		$link_array  = array();
1158

    
1159
		for ( $i = 1; $i < 7; $i ++ ) {
1160
			$image_link = '125x125_image_link_' . $i;
1161
			$image_url  = '125x125_image_url_' . $i;
1162

    
1163
			$image_link = isset( $instance[ $image_link ] ) ? $instance[ $image_link ] : '';
1164
			$image_url  = isset( $instance[ $image_url ] ) ? $instance[ $image_url ] : '';
1165
			if ( ! empty( $image_link ) ) {
1166
				array_push( $link_array, $image_link );
1167
			}
1168
			if ( ! empty( $image_url ) ) {
1169
				array_push( $image_array, $image_url );
1170
			}
1171
		}
1172
		echo $before_widget;
1173
		?>
1174

    
1175
		<div class="advertisement_125x125">
1176
			<?php if ( ! empty( $title ) ) { ?>
1177
				<div class="advertisement-title">
1178
					<?php echo $before_title . esc_html( $title ) . $after_title; ?>
1179
				</div>
1180
				<?php
1181
			}
1182
			$output = '';
1183
			if ( ! empty( $image_array ) ) {
1184
				$image_id  = attachment_url_to_postid( $im
1185
                                                      age_url );
1186
				$image_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
1187
				$output    .= '<div class="advertisement-content">';
1188
				for ( $i = 1; $i < 7; $i ++ ) {
1189
					$j = $i - 1;
1190
					if ( ! empty( $image_array[ $j ] ) ) {
1191
						if ( ! empty( $link_array[ $j ] ) ) {
1192
							$output .= '<a href="' . $link_array[ $j ] . '" class="single_ad_125x125" target="_blank" rel="nofollow">
1193
                                 <img src="' . $image_array[ $j ] . '" width="125" height="125" alt="' . $image_alt . '">
1194
                              </a>';
1195
						} else {
1196
							$output .= '<img src="' . $image_array[ $j ] . '" width="125" height="125" alt="' . $image_alt . '">';
1197
						}
1198
					}
1199
				}
1200
				$output .= '</div>';
1201
				echo $output;
1202
			}
1203
			?>
1204
		</div>
1205
		<?php
1206
		echo $after_widget;
1207
	}
1208

    
1209
}
1210
?>
(15-15/16)