PluginProbe ʕ •ᴥ•ʔ
پارسی دیت – Parsi Date / 2.3.2
پارسی دیت – Parsi Date v2.3.2
6.1 5.1.6 5.1.7 5.1.8 5.1.8.2 6.0 trunk 1.0 1.1 1.2 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 2.0.0-alpha 2.1 2.1.1 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0.1 2.3.0.2 2.3.1 2.3.2 2.3.3 2.3.4 3.0.1 3.0.2 3.0.3 4.0.0 4.0.1 4.0.2 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5
wp-parsidate / includes / fixes-archives.php
wp-parsidate / includes Last commit date
admin 9 years ago plugins 9 years ago widget 9 years ago fixes-archive.php 9 years ago fixes-archives.php 9 years ago fixes-calendar.php 9 years ago fixes-dates.php 9 years ago fixes-misc.php 9 years ago fixes-permalinks.php 9 years ago general.php 9 years ago install.php 9 years ago parsidate.php 9 years ago settings.php 9 years ago
fixes-archives.php
159 lines
1 <?php
2
3 /**
4 * Create Persian Archives
5 *
6 * @param string $args
7 *
8 * @return string
9 */
10 function wpp_get_archives( $args = '' ) {
11 global $wpdb, $persian_month_names;
12 $defaults = array(
13 'type' => 'monthly',
14 'limit' => '',
15 'format' => 'html',
16 'before' => '',
17 'after' => '',
18 'show_post_count' => false,
19 'echo' => 1,
20 'order' => 'DESC'
21 );
22 $r = wp_parse_args( $args, $defaults );
23
24 $results = $wpdb->get_results( "SELECT date( post_date )as date,count(ID)as count FROM $wpdb->posts WHERE post_date < NOW() AND post_type = 'post' AND post_status = 'publish' group by date ORDER BY post_date DESC" );
25
26 if ( ! empty( $results ) ) {
27 if ( $r['type'] == 'yearly' ) {
28 $old_date = parsidate( 'Y', $results[0]->date, 'eng' );
29 $count = $results[0]->count;
30 $c = count( $results );
31 for ( $i = 1; $i < $c; $i ++ ) {
32 $dt = $results[ $i ];
33 $date = parsidate( 'Y', $dt->date, 'eng' );
34 if ( $date === $old_date ) {
35 $count += $dt->count;
36 } else {
37 echo_yarchive( $old_date, $r['format'], $r['before'], $count, $r['show_post_count'] );
38 $old_date = $date;
39 $count = $dt->count;
40 }
41 }
42 echo_yarchive( $old_date, $r['format'], $r['before'], $count, $r['show_post_count'] );
43 } elseif ( $r['type'] == 'monthly' ) {
44 $old_date = parsidate( 'Ym', $results[0]->date, 'eng' );
45 $count = $results[0]->count;
46 $c = count( $results );
47 for ( $i = 1; $i < $c; $i ++ ) {
48 $dt = $results[ $i ];
49 $date = parsidate( 'Ym', $dt->date, 'eng' );
50 if ( $date == $old_date ) {
51 $count += $dt->count;
52 } else {
53 echo_marchive( $old_date, $r['format'], $r['before'], $count, $r['show_post_count'] );
54 $old_date = $date;
55 $count = $dt->count;
56 }
57 }
58 echo_marchive( $old_date, $r['format'], $r['before'], $count, $r['show_post_count'] );
59 } elseif ( $r['type'] == 'daily' ) {
60 foreach ( $results as $row ) {
61 $date = parsidate( 'Y,m,d', $row->date, 'eng' );
62 $date = explode( ',', $date );
63 if ( $r['show_post_count'] ) {
64 $count = '&nbsp;(' . fixnumber( $row->count ) . ')';
65 } else {
66 $count = '';
67 }
68 $text = fixnumber( $date[2] ) . ' ' . $persian_month_names[ intval( $date[1] ) ] . ' ' . fixnumber( $date[0] );
69 echo get_archives_link( get_day_link( $date[0], $date[1], $date[2] ), $text, $r['format'], $r['before'], $count );
70 }
71 }
72 }
73 }
74
75 function echo_yarchive( $year, $format, $before, $count, $show_post_count ) {
76 if ( $show_post_count ) {
77 $count = '&nbsp;(' . fixnumber( $count ) . ')';
78 } else {
79 $count = '';
80 }
81 echo get_archives_link( get_year_link( $year ), fixnumber( $year ), $format, $before, $count );
82 }
83
84 function echo_marchive( $old_date, $format, $before, $count, $show_post_count ) {
85 global $persian_month_names;
86 $year = substr( $old_date, 0, 4 );
87 $month = substr( $old_date, 4, 2 );
88 if ( $show_post_count ) {
89 $count = '&nbsp;(' . fixnumber( $count ) . ')';
90 } else {
91 $count = '';
92 }
93 echo get_archives_link( get_month_link( $year, $month ), $persian_month_names[ intval( $month ) ] . ' ' . fixnumber( $year ), $format, $before, $count );
94 }
95
96 function wp_get_parchives( $args = '' ) {
97 global $wpdb, $persian_month_names;
98 $defaults = array(
99 'type' => 'monthly',
100 'limit' => '',
101 'format' => 'html',
102 'before' => '',
103 'after' => '',
104 'show_post_count' => false,
105 'echo' => 1,
106 'order' => 'DESC'
107 );
108
109 $r = wp_parse_args( $args, $defaults );
110
111 $results = $wpdb->get_results( "SELECT date( post_date )as date,count(ID)as count FROM $wpdb->posts WHERE post_date < NOW() AND post_type = 'post' AND post_status = 'publish' group by date ORDER BY post_date DESC" );
112 if ( ! empty( $results ) ) {
113 if ( $r['type'] == 'yearly' ) {
114 $old_date = parsidate( 'Y', $results[0]->date, 'eng' );
115 $count = $results[0]->count;
116 $c = count( $results );
117 for ( $i = 1; $i < $c; $i ++ ) {
118 $dt = $results[ $i ];
119 $date = parsidate( 'Y', $dt->date, 'eng' );
120 if ( $date === $old_date ) {
121 $count += $dt->count;
122 } else {
123 echo_yarchive( $old_date, $r['format'], $r['before'], $count, $r['show_post_count'] );
124 $old_date = $date;
125 $count = $dt->count;
126 }
127 }
128 echo_yarchive( $old_date,$r['format'], $r['before'], $count, $r['show_post_count'] );
129 } elseif ( $r['type'] == 'monthly' ) {
130 $old_date = parsidate( 'Ym', $results[0]->date, 'eng' );
131 $count = $results[0]->count;
132 $c = count( $results );
133 for ( $i = 1; $i < $c; $i ++ ) {
134 $dt = $results[ $i ];
135 $date = parsidate( 'Ym', $dt->date, 'eng' );
136 if ( $date === $old_date ) {
137 $count += $dt->count;
138 } else {
139 echo_marchive( $old_date, $r['format'], $r['before'], $count, $r['show_post_count']);
140 $old_date = $date;
141 $count = $dt->count;
142 }
143 }
144 echo_marchive( $old_date, $r['format'], $r['before'], $count, $r['show_post_count'] );
145 } elseif ( $r['type'] == 'daily' ) {
146 foreach ( $results as $row ) {
147 $date = parsidate( 'Y,m,d', $row->date, 'eng' );
148 $date = explode( ',', $date );
149 if ( $r['show_post_count'] ) {
150 $count = '&nbsp;(' . fixnumber( $row->count ) . ')';
151 } else {
152 $count = '';
153 }
154 $text = fixnumber( $date[2] ) . ' ' . $persian_month_names[ intval( $date[1] ) ] . ' ' . fixnumber( $date[0] );
155 echo get_archives_link( get_day_link( $date[0], $date[1], $date[2] ), $text, $r['format'], $r['before'], $count );
156 }
157 }
158 }
159 }