-
Notifications
You must be signed in to change notification settings - Fork 3
/
annual_archive.php
executable file
·836 lines (759 loc) · 34.8 KB
/
annual_archive.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
<?php
/*
Plugin Name: Annual Archive
Text Domain: anual-archive
Plugin URI: https://pluginoven.com/plugins/annual-archive/
Description: Display daily, weekly, monthly, yearly, decade, postbypost and alpha archives with a simple shortcode or sidebar widget.
Version: 1.6.0
Author: Twinpictures
Author URI: https://www.twinpictures.de/
License: GPL2
*/
/**
* Class WP_Plugin_Annual_Archive
* @package WP_plugin
* @category WordPress Plugins
*/
class WP_Plugin_Annual_Archive {
/**
* Plugin vars
* @var string
*/
var $plugin_name = 'Annual Archive';
var $version = '1.6.0';
var $domain = 'anarch'; //for plugin settings
/**
* Options page
* @var string
*/
var $plugin_options_page_title = 'Annual Archive Options';
var $plugin_options_menue_title = 'Annual Archive';
var $plugin_options_slug = 'annual-archive-optons';
/**
* Name of the options
* @var string
*/
var $options_name = 'WP_AnnualArchive_options';
/**
* @var array
*/
var $options = array(
'custom_css' => '',
'use_cpt_archive' => '',
);
/**
* PHP5 constructor
*/
function __construct() {
// set option values
$this->_set_options();
// add actions
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'plugin_actions' ) );
add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'archive_admin_js_scripts' ) );
add_action( 'wp_head', array( $this, 'plugin_head_inject' ) );
add_action( 'plugins_loaded', array( $this, 'annual_archive_load_textdomain' ) );
// add shortcode
add_shortcode('archives', array($this, 'shortcode'));
add_shortcode('arcpromat', array($this, 'shortcode'));
// add filters
add_filter( 'widget_text', 'do_shortcode' );
add_filter( 'query_vars', array($this, 'annual_archive_query_vars') );
add_filter( 'pre_get_posts', array($this, 'annual_archive_decade_filter') );
add_filter( 'get_the_archive_title', array($this, 'annual_archive_decade_title') );
}
// load text domain for translations
function annual_archive_load_textdomain() {
load_plugin_textdomain( 'anual-archive' );
}
// Add decade to the query args
function annual_archive_query_vars($vars) {
$vars[] = 'decade';
return $vars;
}
//check for decade query var
function annual_archive_decade_filter( $query ) {
if ( $query->is_main_query() && $query->is_archive() ){
$decade = get_query_var( 'decade' );
if( !empty($decade) ){
$start = $decade.'-01-01';
$end = ($decade+9).'-12-31';
$query->set('year', '');
$query->set( 'date_query',
array (
'after' => $start,
'before' => $end,
'inclusive' => true,
)
);
}
}
}
//modify the title
function annual_archive_decade_title($title) {
$decade = get_query_var( 'decade' );
if(!empty($decade)){
$title = __('The').' '.$decade.'\'s';
}
return $title;
}
//plugin header inject
function plugin_head_inject(){
// custom css
if( !empty( $this->options['custom_css'] ) ){
echo "\n<style>\n";
echo $this->options['custom_css'];
echo "\n</style>\n";
}
}
/**
* Callback admin_menu
*/
function admin_menu() {
if ( function_exists( 'add_options_page' ) AND current_user_can( 'manage_options' ) ) {
// add options page
$options_page = add_options_page($this->plugin_options_page_title, $this->plugin_options_menue_title, 'manage_options', $this->plugin_options_slug, array( $this, 'options_page' ));
}
}
/**
* Callback admin_init
*/
function admin_init() {
// register settings
register_setting( $this->domain, $this->options_name );
}
//load scripts on the widget admin page
function archive_admin_js_scripts($hook){
global $pagenow;
if( $hook == 'widgets.php' && $pagenow != 'customize.php'){
$plugin_url = plugins_url() .'/'. dirname( plugin_basename(__FILE__) );
wp_register_script('archive-admin-script', $plugin_url.'/js/widget_form.js', array ('jquery'), '0.2', true);
wp_enqueue_script('archive-admin-script');
}
}
/**
* Advaned wp_get_archives
* adds the ability to order alpha and postbypost Archives
* adds archive by decade
**/
static function wp_get_archives_advanced( $args = '' ) {
global $wpdb, $wp_locale;
$defaults = array(
'type' => 'yearly',
'limit' => '',
'format' => 'html',
'before' => '',
'after' => '',
'show_post_count' => false,
'showcount' => false,
'echo' => 1,
'order' => 'DESC',
'alpha_order' => 'ASC',
'post_order' => 'DESC',
'post_type' => 'post',
'use_cpt_archive' => '',
);
$r = wp_parse_args( $args, $defaults );
$post_type_object = get_post_type_object( $r['post_type'] );
if ( ! is_post_type_viewable( $post_type_object ) ) {
return;
}
$r['post_type'] = $post_type_object->name;
if ( '' == $r['type'] ) {
$r['type'] = 'yearly';
}
if ( ! empty( $r['limit'] ) ) {
$r['limit'] = absint( $r['limit'] );
$r['limit'] = ' LIMIT ' . $r['limit'];
}
$order = strtoupper( $r['order'] );
if ( $order !== 'ASC' ) {
$order = 'DESC';
}
if(empty($show_post_count) && !empty($showcount)){
$show_post_count = $showcount;
}
// this is what will separate dates on weekly archive links
$archive_week_separator = '–';
$sql_where = $wpdb->prepare( "WHERE post_type = %s AND post_status = 'publish'", $r['post_type'] );
/**
* Filters the SQL WHERE clause for retrieving archives.
*
* @since 2.2.0
*
* @param string $sql_where Portion of SQL query containing the WHERE clause.
* @param array $r An array of default arguments.
*/
$where = apply_filters( 'getarchives_where', $sql_where, $r );
/**
* Filters the SQL JOIN clause for retrieving archives.
*
* @since 2.2.0
*
* @param string $sql_join Portion of SQL query containing JOIN clause.
* @param array $r An array of default arguments.
*/
$join = apply_filters( 'getarchives_join', '', $r );
$output = '';
$last_changed = wp_cache_get_last_changed( 'posts' );
$limit = $r['limit'];
if ( 'monthly' == $r['type'] ) {
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date $order $limit";
$key = md5( $query );
$key = "wp_get_archives_advanced:$key:$last_changed";
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
$results = $wpdb->get_results( $query );
wp_cache_set( $key, $results, 'posts' );
}
if ( $results ) {
$after = $r['after'];
foreach ( (array) $results as $result ) {
$url = get_month_link( $result->year, $result->month );
if ( 'post' !== $r['post_type'] ) {
if( !empty( $r['use_cpt_archive'] ) ){
$url = get_post_type_archive_link( $r['post_type'] );
$url = add_query_arg(
array(
'year' => $result->year,
'month' => $result->month,
), $url
);
}
else{
$url = add_query_arg( 'post_type', $r['post_type'], $url );
}
}
/* translators: 1: month name, 2: 4-digit year */
$text = sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $result->month ), $result->year );
if ( $r['show_post_count'] ) {
$r['after'] = ' (' . $result->posts . ')' . $after;
}
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
}
}
} elseif ( 'yearly' == $r['type'] ) {
$query = "SELECT YEAR(post_date) AS `year`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date) ORDER BY post_date $order $limit";
$key = md5( $query );
$key = "wp_get_archives_advanced:$key:$last_changed";
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
$results = $wpdb->get_results( $query );
wp_cache_set( $key, $results, 'posts' );
}
if ( $results ) {
$after = $r['after'];
foreach ( (array) $results as $result ) {
$url = get_year_link( $result->year );
if ( 'post' !== $r['post_type'] ) {
if( !empty( $r['use_cpt_archive'] ) ){
$url = get_post_type_archive_link( $r['post_type'] );
$url = add_query_arg( 'year', $result->year, $url );
}
else{
$url = add_query_arg( 'post_type', $r['post_type'], $url );
}
}
$text = sprintf( '%d', $result->year );
if ( $r['show_post_count'] ) {
$r['after'] = ' (' . $result->posts . ')' . $after;
}
//hey dude what if we want to select current year?
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
}
}
} elseif ( 'daily' == $r['type'] ) {
$query = "SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, DAYOFMONTH(post_date) AS `dayofmonth`, count(ID) as posts FROM $wpdb->posts $join $where GROUP BY YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) ORDER BY post_date $order $limit";
$key = md5( $query );
$key = "wp_get_archives_advanced:$key:$last_changed";
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
$results = $wpdb->get_results( $query );
wp_cache_set( $key, $results, 'posts' );
}
if ( $results ) {
$after = $r['after'];
foreach ( (array) $results as $result ) {
$url = get_day_link( $result->year, $result->month, $result->dayofmonth );
if ( 'post' !== $r['post_type'] ) {
$url = add_query_arg( 'post_type', $r['post_type'], $url );
}
$date = sprintf( '%1$d-%2$02d-%3$02d 00:00:00', $result->year, $result->month, $result->dayofmonth );
$text = mysql2date( get_option( 'date_format' ), $date );
if ( $r['show_post_count'] ) {
$r['after'] = ' (' . $result->posts . ')' . $after;
}
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
}
}
} elseif ( 'weekly' == $r['type'] ) {
$week = _wp_mysql_week( '`post_date`' );
$query = "SELECT DISTINCT $week AS `week`, YEAR( `post_date` ) AS `yr`, DATE_FORMAT( `post_date`, '%Y-%m-%d' ) AS `yyyymmdd`, count( `ID` ) AS `posts` FROM `$wpdb->posts` $join $where GROUP BY $week, YEAR( `post_date` ) ORDER BY `post_date` $order $limit";
$key = md5( $query );
$key = "wp_get_archives_advanced:$key:$last_changed";
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
$results = $wpdb->get_results( $query );
wp_cache_set( $key, $results, 'posts' );
}
$arc_w_last = '';
if ( $results ) {
$after = $r['after'];
foreach ( (array) $results as $result ) {
if ( $result->week != $arc_w_last ) {
$arc_year = $result->yr;
$arc_w_last = $result->week;
$arc_week = get_weekstartend( $result->yyyymmdd, get_option( 'start_of_week' ) );
$arc_week_start = date_i18n( get_option( 'date_format' ), $arc_week['start'] );
$arc_week_end = date_i18n( get_option( 'date_format' ), $arc_week['end'] );
$url = add_query_arg(
array(
'm' => $arc_year,
'w' => $result->week,
), home_url( '/' )
);
if ( 'post' !== $r['post_type'] ) {
$url = add_query_arg( 'post_type', $r['post_type'], $url );
}
$text = $arc_week_start . $archive_week_separator . $arc_week_end;
if ( $r['show_post_count'] ) {
$r['after'] = ' (' . $result->posts . ')' . $after;
}
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
}
}
}
} elseif ( 'decade' == $r['type'] ) {
$query = "SELECT count(*), decade, decade + 9 FROM (SELECT FLOOR(YEAR(post_date) / 10) * 10 AS decade FROM $wpdb->posts $join $where) t GROUP BY decade $order $limit";
$key = md5( $query );
$key = "wp_get_archives_advanced:$key:$last_changed";
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
$results = $wpdb->get_results( $query );
wp_cache_set( $key, $results, 'posts' );
}
if ( $results ) {
$after = $r['after'];
foreach ( (array) $results as $result ) {
$url = get_year_link($result->decade).'?decade='.$result->decade;
if ( 'post' !== $r['post_type'] ) {
$url = add_query_arg( 'post_type', $r['post_type'], $url );
}
$text = sprintf( '%d\'s', $result->decade );
if ( $r['show_post_count'] ) {
$r['after'] = ' (' . $result->posts . ')' . $after;
}
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
}
}
} elseif ( ( 'postbypost' == $r['type'] ) || ( 'alpha' == $r['type'] ) ) {
$alpha_order = strtoupper( $r['alpha_order'] );
if ( $alpha_order !== 'ASC' ) {
$alpha_order = 'DESC';
}
$post_order = strtoupper( $r['post_order'] );
if ( $post_order !== 'DESC' ) {
$post_order = 'ASC';
}
$orderby = ( 'alpha' == $r['type'] ) ? 'post_title '.$alpha_order. ' ' : 'post_date '.$post_order.', ID DESC ';
$query = "SELECT * FROM $wpdb->posts $join $where ORDER BY $orderby $limit";
$key = md5( $query );
$key = "wp_get_archives_advanced:$key:$last_changed";
if ( ! $results = wp_cache_get( $key, 'posts' ) ) {
$results = $wpdb->get_results( $query );
wp_cache_set( $key, $results, 'posts' );
}
if ( $results ) {
foreach ( (array) $results as $result ) {
if ( $result->post_date != '0000-00-00 00:00:00' ) {
$url = get_permalink( $result );
if ( $result->post_title ) {
/** This filter is documented in wp-includes/post-template.php */
$text = strip_tags( apply_filters( 'the_title', $result->post_title, $result->ID ) );
} else {
$text = $result->ID;
}
$output .= get_archives_link( $url, $text, $r['format'], $r['before'], $r['after'] );
}
}
}
}
if ( $r['echo'] ) {
echo $output;
} else {
return $output;
}
}
/**
* Callback shortcode
*/
function shortcode($atts, $content = null){
$options = $this->options;
extract(shortcode_atts(array(
'type' => 'yearly',
'limit' => '',
'format' => 'html', //html, option, link
'before' => '',
'after' => '',
'show_post_count' => '0',
'showcount' => '0',
'tag' => 'ul',
'order' => 'DESC',
'alpha_order' => 'ASC',
'post_order' => 'DESC',
'select_text' => '',
'post_type' => 'post',
'use_cpt_archive' => $options['use_cpt_archive']
), $atts));
if(empty($show_post_count) && !empty($showcount)){
$show_post_count = $showcount;
}
if ($format == 'option') {
if( !empty($select_text) ){
$dtitle = $select_text;
}
else{
$dtitle = __('Select Year', 'anual-archive');
if ($type == 'monthly'){
$dtitle = __('Select Month', 'anual-archive');
}
else if($type == 'weekly'){
$dtitle = __('Select Week', 'anual-archive');
}
else if($type == 'daily'){
$dtitle = __('Select Day', 'anual-archive');
}
else if($type == 'postbypost' || $type == 'alpha'){
$dtitle = __('Select Post', 'anual-archive');
}
}
$arc = '<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"> <option value="">'.esc_attr($dtitle).'</option>';
$arc .= WP_Plugin_Annual_Archive::wp_get_archives_advanced(array('type' => esc_attr($type), 'limit' => esc_attr($limit), 'format' => 'option', 'show_post_count' => $show_post_count, 'post_type' => esc_attr($post_type), 'order' => esc_attr($order), 'alpha_order' => esc_attr($alpha_order), 'post_order' => esc_attr($post_order), 'echo' => 0)).'</select>';
} else {
$arc = '<'.esc_attr($tag).'>';
$arch_arr = array(
'type' => esc_attr($type),
'limit' => esc_attr($limit),
'format' => esc_attr($format),
'before' => esc_attr($before),
'after' => esc_attr($after),
'show_post_count' => esc_attr($show_post_count),
'post_type' => esc_attr($post_type),
'order' => esc_attr($order),
'alpha_order' => esc_attr($alpha_order),
'post_order' => esc_attr($post_order),
'use_cpt_archive' => esc_attr($use_cpt_archive),
'echo' => 0
);
$arc .= WP_Plugin_Annual_Archive::wp_get_archives_advanced($arch_arr);
$arc .= '</'.esc_attr($tag).'>';
}
return $arc;
}
// Add link to options page from plugin list
function plugin_actions($links) {
$new_links = array();
$new_links[] = '<a href="options-general.php?page='.$this->plugin_options_slug.'">' . __('Settings', 'anual-archive') . '</a>';
return array_merge($new_links, $links);
}
/**
* Admin options page
*/
function options_page() {
$like_it_arr = array(
__('really tied the room together', 'anual-archive'),
__('made you feel all warm and fuzzy on the inside', 'anual-archive'),
__('restored your faith in humanity... even if only for a fleeting second', 'anual-archive'),
__('rocked your world', 'provided a positive vision of future living', 'anual-archive'),
__('inspired you to commit a random act of kindness', 'anual-archive'),
__('encouraged more regular flossing of the teeth', 'anual-archive'),
__('helped organize your life in the small ways that matter', 'anual-archive'),
__('saved your minutes--if not tens of minutes--writing your own solution', 'anual-archive'),
__('brightened your day... or darkened if if you are trying to sleep in', 'anual-archive'),
__('caused you to dance a little jig of joy and joyousness', 'anual-archive'),
__('inspired you to tweet a little @twinpictues social love', 'anual-archive'),
__('tasted great, while also being less filling', 'anual-archive'),
__('caused you to shout: "everybody spread love, give me some mo!"', 'anual-archive'),
__('helped you keep the funk alive', 'anual-archive'),
__('<a href="https://www.youtube.com/watch?v=dvQ28F5fOdU" target="_blank">soften hands while you do dishes</a>', 'anual-archive'),
__('helped that little old lady <a href="https://www.youtube.com/watch?v=Ug75diEyiA0" target="_blank">find the beef</a>', 'anual-archive')
);
$rand_key = array_rand($like_it_arr);
$like_it = $like_it_arr[$rand_key];
?>
<div class="wrap">
<h2><?php echo $this->plugin_name; ?></h2>
</div>
<div class="postbox-container metabox-holder meta-box-sortables" style="width: 69%">
<div style="margin:0 5px;">
<div class="postbox">
<div class="handlediv" title="<?php _e( 'Click to toggle', 'anual-archive' ) ?>"><br/></div>
<h3 class="handle"><?php _e( 'Annual Archive Settings', 'anual-archive' ) ?></h3>
<div class="inside">
<form method="post" action="options.php">
<?php
settings_fields( $this->domain );
$this->_set_options();
$options = $this->options;
?>
<fieldset class="options">
<table class="form-table">
<tr>
<th><?php _e( 'Custom Style', 'anual-archive' ) ?>:</th>
<td><label><textarea id="<?php echo $this->options_name ?>[custom_css]" name="<?php echo $this->options_name ?>[custom_css]" style="width: 100%; height: 150px;"><?php echo esc_attr($options['custom_css']); ?></textarea>
<br /><span class="description"><?php _e( 'Custom CSS style for <em>ultimate flexibility</em>', 'anual-archive' ) ?></span></label>
</td>
</tr>
<tr>
<th><?php _e( 'CPT Archive Permalinks', 'anual-archive' ) ?>:</th>
<td><label><input type="checkbox" id="use_cpt_archive" name="<?php echo esc_attr($this->options_name); ?>[use_cpt_archive]" value="1" <?php echo checked( $options['use_cpt_archive'], 1 ); ?> /> <?php _e('Use CPT Archive Permalinks', 'anual-archive'); ?>
<br /><span class="description"><?php printf(__('Use %sget_post_type_archive_link%s to generate the permalink for custom post type archives.', 'anual-archive'), '<a href="https://developer.wordpress.org/reference/functions/get_post_type_archive_link/" target="_blank">', '</a>'); ?></span></label>
</td>
</tr>
<tr>
<th><?php _e( 'Level Up!', 'anual-archive' ) ?>:</th>
<td>
<p><?php printf(__( '%sArchive-Pro-Matic%s offers advanced features such as archives by quarter, season, single and multiple catagories. Included is a %svery high level of personal support%s.', 'anual-archive' ), '<a href="https://pluginoven.com/premium-plugins/archive-pro-matic/?utm_source=annual-archive&utm_medium=plugin-settings-page&utm_content=archive-pro-matic&utm_campaign=archive-pro-level-up">', '</a>', '<a href="https://pluginoven.com/premium-plugins/archive-pro-matic/testimonials/?utm_source=annual-archive&utm_medium=plugin-settings-page&utm_content=archive-pro-matic&utm_campaign=archive-pro-support">', '</a>'); ?></p>
</td>
</tr>
</table>
</fieldset>
<p class="submit" style="margin-bottom: 20px;">
<input class="button-primary" type="submit" value="<?php _e( 'Save Changes', 'anual-archive' ) ?>" style="float: right;" />
</p>
</div>
</div>
</div>
</div>
<div class="postbox-container side metabox-holder meta-box-sortables" style="width:29%;">
<div style="margin:0 5px;">
<div class="postbox">
<div class="handlediv" title="<?php _e( 'Click to toggle', 'anual-archive' ) ?>"><br/></div>
<h3 class="handle"><?php _e( 'About', 'anual-archive' ) ?></h3>
<div class="inside">
<h4><?php echo $this->plugin_name; ?> <?php _e('Version', 'anual-archive'); ?> <?php echo $this->version; ?></h4>
<p><?php printf( __('A %scomplete listing of shortcode options and attribute demos%s are available, as well as %sfree, open-source community support%s. Translate Annual Archive into any language using the WordPress %scommunity translation tool%s.', 'anual-archive') ,'<a href="https://pluginoven.com/plugins/annual-archive/documentation/">','</a>', '<a href="https://wordpress.org/support/plugin/anual-archive">', '</a>', '<a href="https://translate.wordpress.org/projects/wp-plugins/anual-archive">', '</a>') ?></p>
<ul>
<li>
<?php printf( __( '%sDetailed documentation%s, complete with working demonstrations of all shortcode attributes, is available for your instructional enjoyment.', 'anual-archive'), '<a href="https://pluginoven.com/plugins/annual-archive/documentation/" target="_blank">', '</a>'); ?>
</li>
<li><?php printf( __('If this plugin %s, please consider %ssharing your story%s with others.', 'anual-archive'), $like_it, '<a href="https://wordpress.org/support/plugin/anual-archive/reviews/" target="_blank">', '</a>' ) ?></li>
<li><?php printf( __('Your %sreviews%s, %sbug-reports, feedback%s and %scocktail recipes%s are always welcomed.', 'anual-archive'), '<a href="https://wordpress.org/support/plugin/anual-archive/reviews/">', '</a>', '<a href="https://wordpress.org/support/plugin/anual-archive/">', '</a>', '<a href="https://www.facebook.com/twinpictures">', '</a>'); ?></li>
</ul>
</div>
</div>
</div>
<div class="clear"></div>
</div>
<?php
}
/**
* Set options from save values or defaults
*/
function _set_options() {
// set options
$saved_options = get_option( $this->options_name );
// backwards compatible (old values)
if ( empty( $saved_options ) ) {
$saved_options = get_option( $this->domain . 'options' );
}
// set all options
if ( ! empty( $saved_options ) ) {
foreach ( $this->options AS $key => $option ) {
$this->options[ $key ] = ( empty( $saved_options[ $key ] ) ) ? '' : $saved_options[ $key ];
}
}
}
} // end class WP_Plugin_Template
/**
* Create instance
*/
$WP_Plugin_Annual_Archive = new WP_Plugin_Annual_Archive;
//Widget
class Annual_Archive_Widget extends WP_Widget {
/** constructor */
function __construct() {
$widget_ops = array(
'classname' => 'Annual_Archive_Widget',
'description' => __( 'Display daily, weekly, monthly or annual archives with a sidebar widget or shortcode', 'anual-archive' )
);
parent::__construct( 'Annual_Archive_Widget', __( 'Annual Archive', 'anual-archive' ), $widget_ops );
}
/** Widget */
function widget($args, $instance) {
extract( $args );
$format = empty($instance['format']) ? 'html' : apply_filters('widget_format', $instance['format']);
$type = empty($instance['type']) ? 'yearly' : apply_filters('widget_type', $instance['type']);
$before = empty($instance['before']) ? '' : apply_filters('widget_before', $instance['before']);
$after = empty($instance['after']) ? '' : apply_filters('widget_after', $instance['after']);
$limit = apply_filters('widget_limit', $instance['limit']);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$show_post_count = empty($instance['show_post_count']) ? 0 : $instance['show_post_count'];
$order = empty($instance['order']) ? 'DESC' : apply_filters('widget_order', $instance['order']);
$alpha_order = empty($instance['alpha_order']) ? 'ASC' : apply_filters('widget_alpha_order', $instance['alpha_order']);
$post_order = empty($instance['post_order']) ? 'DESC' : apply_filters('widget_post_order', $instance['post_order']);
$select_text = empty($instance['select_text']) ? '' : apply_filters('widget_slelect_text', $instance['select_text']);
$post_type = empty($instance['post_type']) ? 'post' : apply_filters('widget_post_type', $instance['post_type']);
if(empty($show_post_count) && !empty($instance['showcount'])){
$show_post_count = $instance['showcount'];
}
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
if ($format == 'option') {
if($select_text){
$dtitle = $select_text;
}
else{
$dtitle = __('Select Year', 'anual-archive');
if ($type == 'monthly'){
$dtitle = __('Select Month', 'anual-archive');
}
else if($type == 'weekly'){
$dtitle = __('Select Week', 'anual-archive');
}
else if($type == 'daily'){
$dtitle = __('Select Day', 'anual-archive');
}
else if($type == 'postbypost' || $type == 'alpha'){
$dtitle = __('Select Post', 'anual-archive');
}
}
?>
<select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo esc_attr(__($dtitle, 'anual-archive')); ?></option> <?php WP_Plugin_Annual_Archive::wp_get_archives_advanced(apply_filters('widget_archive_dropdown_args', array('type' => $type, 'format' => 'option', 'show_post_count' => $show_post_count, 'limit' => $limit, 'order' => $order, 'alpha_order' => $alpha_order, 'post_order' => $post_order))); ?> </select>
<?php
} else {
?>
<ul>
<?php WP_Plugin_Annual_Archive::wp_get_archives_advanced(apply_filters('widget_archive_args', array(
'type' => $type,
'limit' => $limit,
'format' => $format,
'before' => $before,
'after' => $after,
'show_post_count' => $show_post_count,
'post_type' => $post_type,
'order' => $order,
'alpha_order' => $alpha_order,
'post_order' => $post_order,
'select_text' => $select_text )
)); ?>
</ul>
<?php
}
echo $after_widget;
}
/** Update **/
function update($new_instance, $old_instance) {
$instance = array_merge($old_instance, $new_instance);
$instance['show_post_count'] = $new_instance['show_post_count'];
return $instance;
}
/** Form **/
function form($instance) {
$title = empty($instance['title']) ? '' : stripslashes($instance['title']);
$show_post_count = empty($instance['show_post_count']) ? 0 : $instance['show_post_count'];
$format = empty($instance['format']) ? '' : stripslashes($instance['format']);
$before = empty($instance['before']) ? '' : stripslashes($instance['before']);
$after = empty($instance['after']) ? '' : stripslashes($instance['after']);
$type = empty($instance['type']) ? '' : strip_tags($instance['type']);
$limit = empty($instance['limit']) ? '' : stripslashes($instance['limit']);
$post_type = empty($instance['post_type']) ? 'post' : stripslashes($instance['post_type']);
$order = empty($instance['order']) ? 'DESC' : stripslashes($instance['order']);
$alpha_order = empty($instance['alpha_order']) ? 'ASC' : stripslashes($instance['alpha_order']);
$post_order = empty($instance['post_order']) ? 'DESC' : stripslashes($instance['post_order']);
$select_text = empty($instance['select_text']) ? '' : stripslashes($instance['select_text']);
if(empty($show_post_count) && !empty($instance['showcount'])){
$show_post_count = $instance['showcount'];
}
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','anual-archive'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('show_post_count'); ?>"><input type="checkbox" id="<?php echo $this->get_field_id('show_post_count'); ?>" name="<?php echo $this->get_field_name('show_post_count'); ?>" value="1" <?php checked( $show_post_count, 1 ); ?>/> <?php _e('Show post counts', 'anual-archive'); ?></label></p>
<p><label><?php _e('Archive type:', 'anual-archive'); ?> <select name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>" class="annual_archive_type_select">
<?php
$types_arr = array(
'daily' => __('Daily', 'anual-archive'),
'weekly' => __('Weekly', 'anual-archive'),
'monthly' => __('Monthly', 'anual-archive'),
'yearly' => __('Yearly', 'anual-archive'),
'decade' => __('Decade', 'anual-archive'),
'alpha' => __('Alpha', 'anual-archive'),
'postbypost' => __('Post By Post', 'anual-archive')
);
$order_style = '';
$alpha_style = 'style="display: none;"';
$post_style = 'style="display: none;"';
foreach($types_arr as $key => $value){
$selected = '';
if($key == $type || (!$type && $key == 'yearly')){
$selected = 'SELECTED';
}
//order switcher
$data_att = 'data-orderfield="wrap_'.$this->get_field_id('order').'"';
if($key == 'alpha'){
$data_att = 'data-orderfield="wrap_'.$this->get_field_id('alpha_order').'"';
if($key == $type){
$order_style = 'style="display: none;"';
$alpha_style = '';
}
}
if($key == 'postbypost'){
$data_att = 'data-orderfield="wrap_'.$this->get_field_id('post_order').'"';
if($key == $type){
$order_style = 'style="display: none;"';
$post_style = '';
}
}
echo '<option value="'.$key.'" '.$data_att.' '.$selected.'>'.$value.'</option>';
}
?>
</select></lable>
</p>
<p><label><?php _e('Format:', 'anual-archive'); ?> <select name="<?php echo $this->get_field_name('format'); ?>" id="<?php echo $this->get_field_id('format'); ?>">
<?php
$format_arr = array(
'html' => __('HTML', 'anual-archive'),
'option' => __('Option', 'anual-archive'),
'link' => __('Link', 'anual-archive'),
'custom' => __('Custom', 'anual-archive')
);
foreach($format_arr as $key => $value){
$selected = '';
if($key == $format || (!$format && $key == 'html')){
$selected = 'SELECTED';
}
echo '<option value="'.$key.'" '.$selected.'>'.$value.'</option>';
}
?>
</select></lable><br/>
<span class="description"><a href="https://developer.wordpress.org/reference/functions/wp_get_archives/#parameters" target="_blank"><?php _e('Format details', 'anual-archive'); ?></a></span>
</p>
<p><label><?php _e('Post Type:', 'anual-archive'); ?> <select name="<?php echo $this->get_field_name('post_type'); ?>" id="<?php echo $this->get_field_id('post_type'); ?>">
<?php
$pt_args = array(
'public' => true
);
$post_types = get_post_types($pt_args);
foreach($post_types as $type){
$selected = '';
if($type == $post_type ){
$selected = 'SELECTED';
}
echo '<option value="'.$type.'" '.$selected.'>'.$type.'</option>';
}
?>
</select></lable><br/>
<span class="description"><a href="https://developer.wordpress.org/reference/functions/wp_get_archives/#parameters" target="_blank"><?php _e('Post Type', 'anual-archive'); ?></a></span>
</p>
<p><label for="<?php echo $this->get_field_id('before'); ?>"><?php _e('Text Before Link:', 'anual-archive'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('before'); ?>" name="<?php echo $this->get_field_name('before'); ?>" type="text" value="<?php echo $before; ?>" /></p>
<p><label for="<?php echo $this->get_field_id('after'); ?>"><?php _e('Text After Link:', 'anual-archive'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('after'); ?>" name="<?php echo $this->get_field_name('after'); ?>" type="text" value="<?php echo $after; ?>" /></p>
<p><label for="<?php echo $this->get_field_id('select_text'); ?>"><?php _e('Select Text:', 'anual-archive'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('select_text'); ?>" name="<?php echo $this->get_field_name('select_text'); ?>" type="text" value="<?php echo $select_text; ?>" /></p>
<p><label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e('Number of archives to display:', 'anual-archive'); ?></label> <input class="widefat" style="width: 50px;" id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo esc_attr($limit); ?>" /></p>
<p id="wrap_<?php echo $this->get_field_id('order'); ?>" class="order_<?php echo $this->get_field_id('type'); ?>" <?php echo $order_style; ?>><label for="<?php echo $this->get_field_id('order'); ?>"><?php _e('Sort order:', 'anual-archive'); ?></label> <input id="<?php echo $this->get_field_id('order'); ?>" name="<?php echo $this->get_field_name('order'); ?>" type="radio" value="DESC" <?php checked( $order, 'DESC' ); ?> /> DESC <input name="<?php echo $this->get_field_name('order'); ?>" type="radio" value="ASC" <?php checked( $order, 'ASC' ); ?> /> ASC</p>
<p id="wrap_<?php echo $this->get_field_id('alpha_order'); ?>" class="order_<?php echo $this->get_field_id('type'); ?>" <?php echo $alpha_style; ?>><label for="<?php echo $this->get_field_id('alpha_order'); ?>"><?php _e('Alpha order:', 'anual-archive'); ?></label> <input id="<?php echo $this->get_field_id('alpha_order'); ?>" name="<?php echo $this->get_field_name('alpha_order'); ?>" type="radio" value="DESC" <?php checked( $alpha_order, 'DESC' ); ?> /> DESC <input name="<?php echo $this->get_field_name('alpha_order'); ?>" type="radio" value="ASC" <?php checked( $alpha_order, 'ASC' ); ?> /> ASC</p>
<p id="wrap_<?php echo $this->get_field_id('post_order'); ?>" class="order_<?php echo $this->get_field_id('type'); ?>" <?php echo $post_style; ?>><label for="<?php echo $this->get_field_id('post_order'); ?>"><?php _e('Post order:', 'anual-archive'); ?></label> <input id="<?php echo $this->get_field_id('post_order'); ?>" name="<?php echo $this->get_field_name('post_order'); ?>" type="radio" value="DESC" <?php checked( $post_order, 'DESC' ); ?> /> DESC <input name="<?php echo $this->get_field_name('post_order'); ?>" type="radio" value="ASC" <?php checked( $post_order, 'ASC' ); ?> /> ASC</p>
<?php
}
} // class Annual_Archive_Widget
// register Annual_Archive_Widget
function anarch_register_widget() {
register_widget( 'Annual_Archive_Widget' );
}
add_action( 'widgets_init', 'anarch_register_widget' );
?>