Project

General

Profile

Support #9175 » widgets.php

Diane Krauthamer, 2018-02-08 10:21 PM

 
1
<?php
2
/**
3
 * Contains all the functions related to sidebar and widget.
4
 *
5
 * @package    ThemeGrill
6
 * @subpackage ColorMag
7
 * @since      ColorMag 1.0
8
 */
9
add_action( 'widgets_init', 'colormag_widgets_init' );
10

    
11
/**
12
 * Function to register the widget areas(sidebar) and widgets.
13
 */
14
function colormag_widgets_init() {
15

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
195
	register_widget( "colormag_featured_posts_slider_widget" );
196
	register_widget( "colormag_highlighted_posts_widget" );
197
	register_widget( "colormag_featured_posts_widget" );
198
	register_widget( "colormag_featured_posts_vertical_widget" );
199
	register_widget( "colormag_728x90_advertisement_widget" );
200
	register_widget( "colormag_300x250_advertisement_widget" );
201
	register_widget( "colormag_125x125_advertisement_widget" );
202
}
203

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

    
206
/**
207
 * Featured Posts widget
208
 */
209
class 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 = __( 'TG: 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
							<span class="comments"><i class="fa fa-comment"></i><?php comments_popup_link( '0', '1', '%' ); ?></span>
334
						</div>
335
					</div>
336

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

    
349
}
350

    
351
/**
352
 * Highlighted Posts widget
353
 */
354
class colormag_highlighted_posts_widget extends WP_Widget {
355

    
356
	function __construct() {
357
		$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' ) );
358
		$control_ops = array( 'width' => 200, 'height' => 250 );
359
		parent::__construct( false, $name = __( 'TG: Highlighted Posts', 'colormag' ), $widget_ops );
360
	}
361

    
362
	function form( $instance ) {
363
		$tg_defaults[ 'number' ]   = 4;
364
		$tg_defaults[ 'type' ]     = 'latest';
365
		$tg_defaults[ 'category' ] = '';
366
		$instance                  = wp_parse_args( ( array ) $instance, $tg_defaults );
367
		$number                    = $instance[ 'number' ];
368
		$type                      = $instance[ 'type' ];
369
		$category                  = $instance[ 'category' ];
370
		?>
371
		<p>
372
			<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to display:', 'colormag' ); ?></label>
373
			<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"/>
374
		</p>
375

    
376
		<p>
377
			<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' ); ?>
378
			<br/>
379
			<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' ); ?>
380
			<br/></p>
381

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

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

    
396
		return $instance;
397
	}
398

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

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

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

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

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

    
487
}
488

    
489
/**
490
 * Featured Posts widget
491
 */
492
class colormag_featured_posts_widget extends WP_Widget {
493

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

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

    
527
		<p>
528
			<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' ); ?>
529
			<br/>
530
			<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' ); ?>
531
			<br/></p>
532

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

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

    
553
		return $instance;
554
	}
555

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

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

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

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

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

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

    
674
}
675

    
676
/**
677
 * Featured Posts widget
678
 */
679
class colormag_featured_posts_vertical_widget extends WP_Widget {
680

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

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

    
714
		<p>
715
			<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' ); ?>
716
			<br/>
717
			<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' ); ?>
718
			<br/></p>
719

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

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

    
740
		return $instance;
741
	}
742

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

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

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

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

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

    
859
}
860

    
861
/* * ************************************************************************************* */
862

    
863
/**
864
 * 300x250 Advertisement Ads
865
 */
866
class colormag_300x250_advertisement_widget extends WP_Widget {
867

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

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

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

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

    
885
		<p>
886
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'colormag' ); ?></label>
887
			<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>"/>
888
		</p>
889
		<label><?php _e( 'Add your Advertisement 300x250 Images Here', 'colormag' ); ?></label>
890
		<p>
891
			<label for="<?php echo $this->get_field_id( $image_link ); ?>"> <?php _e( 'Advertisement Image Link ', 'colormag' ); ?></label>
892
			<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 ]; ?>"/>
893
		</p>
894
		<p>
895
			<label for="<?php echo $this->get_field_id( $image_url ); ?>"> <?php _e( 'Advertisement Image ', 'colormag' ); ?></label>
896
		<div class="media-uploader" id="<?php echo $this->get_field_id( $image_url ); ?>">
897
			<div class="custom_media_preview">
898
				<?php if ( $instance[ $image_url ] != '' ) : ?>
899
					<img class="custom_media_preview_default" src="<?php echo esc_url( $instance[ $image_url ] ); ?>" style="max-width:100%;"/>
900
				<?php endif; ?>
901
			</div>
902
			<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;"/>
903
			<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>
904
		</div>
905
		</p>
906

    
907
		<?php
908
	}
909

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

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

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

    
920
		return $instance;
921
	}
922

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

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

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

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

    
935
		echo $before_widget;
936
		?>
937

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

    
966
}
967

    
968
/* * ************************************************************************************* */
969

    
970
/**
971
 * 728x90 Advertisement Ads
972
 */
973
class colormag_728x90_advertisement_widget extends WP_Widget {
974

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

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

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

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

    
992
		<p>
993
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'colormag' ); ?></label>
994
			<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>"/>
995
		</p>
996
		<label><?php _e( 'Add your Advertisement 728x90 Images Here', 'colormag' ); ?></label>
997
		<p>
998
			<label for="<?php echo $this->get_field_id( $image_link ); ?>"> <?php _e( 'Advertisement Image Link ', 'colormag' ); ?></label>
999
			<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 ]; ?>"/>
1000
		</p>
1001
		<p>
1002
			<label for="<?php echo $this->get_field_id( $image_url ); ?>"> <?php _e( 'Advertisement Image ', 'colormag' ); ?></label>
1003
		<div class="media-uploader" id="<?php echo $this->get_field_id( $image_url ); ?>">
1004
			<div class="custom_media_preview">
1005
				<?php if ( $instance[ $image_url ] != '' ) : ?>
1006
					<img class="custom_media_preview_default" src="<?php echo esc_url( $instance[ $image_url ] ); ?>" style="max-width:100%;"/>
1007
				<?php endif; ?>
1008
			</div>
1009
			<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;"/>
1010
			<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>
1011
		</div>
1012
		</p>
1013

    
1014
		<?php
1015
	}
1016

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

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

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

    
1027
		return $instance;
1028
	}
1029

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

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

    
1036

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

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

    
1043
		echo $before_widget;
1044
		?>
1045

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

    
1076
}
1077

    
1078
/* * ************************************************************************************* */
1079

    
1080
/**
1081
 * 125x125 Advertisement Ads
1082
 */
1083
class colormag_125x125_advertisement_widget extends WP_Widget {
1084

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

    
1091
	function form( $instance ) {
1092
		$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' => '' ) );
1093
		$title    = esc_attr( $instance[ 'title' ] );
1094
		for ( $i = 1; $i < 7; $i ++ ) {
1095
			$image_link = '125x125_image_link_' . $i;
1096
			$image_url  = '125x125_image_url_' . $i;
1097

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

    
1103
		<p>
1104
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'colormag' ); ?></label>
1105
			<input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>"/>
1106
		</p>
1107
		<label><?php _e( 'Add your Advertisement 125x125 Images Here', 'colormag' ); ?></label>
1108
		<?php
1109
		for ( $i = 1; $i < 7; $i ++ ) {
1110
			$image_link = '125x125_image_link_' . $i;
1111
			$image_url  = '125x125_image_url_' . $i;
1112
			?>
1113
			<p>
1114
				<label for="<?php echo $this->get_field_id( $image_link ); ?>"> <?php _e( 'Advertisement Image Link ', 'colormag' );
1115
					echo $i; ?></label>
1116
				<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 ]; ?>"/>
1117
			</p>
1118
			<p>
1119
				<label for="<?php echo $this->get_field_id( $image_url ); ?>"> <?php _e( 'Advertisement Image ', 'colormag' );
1120
					echo $i; ?></label>
1121
			<div class="media-uploader" id="<?php echo $this->get_field_id( $image_url ); ?>">
1122
				<div class="custom_media_preview">
1123
					<?php if ( $instance[ $image_url ] != '' ) : ?>
1124
						<img class="custom_media_preview_default" src="<?php echo esc_url( $instance[ $image_url ] ); ?>" style="max-width:100%;"/>
1125
					<?php endif; ?>
1126
				</div>
1127
				<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;"/>
1128
				<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>
1129
			</div>
1130
			</p>
1131
		<?php } ?>
1132

    
1133
		<?php
1134
	}
1135

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

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

    
1147
		return $instance;
1148
	}
1149

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

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

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

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

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

    
1207
}
1208

    
1209
/* * ************************************************************************************* */
1210
?>
(3-3/16)