admin
4 years ago
plugins
4 years ago
widget
4 years ago
fixes-archive.php
4 years ago
fixes-archives.php
4 years ago
fixes-calendar.php
4 years ago
fixes-dates.php
4 years ago
fixes-misc.php
4 years ago
fixes-permalinks.php
4 years ago
general.php
4 years ago
install.php
4 years ago
parsidate.php
4 years ago
settings.php
4 years ago
fixes-archives.php
206 lines
| 1 | <?php |
| 2 | |
| 3 | defined( 'ABSPATH' ) or exit( 'No direct script access allowed' ); |
| 4 | |
| 5 | /** |
| 6 | * Create Persian Archives |
| 7 | * |
| 8 | * @param string $args |
| 9 | */ |
| 10 | function wpp_get_archives( $args = '' ) { |
| 11 | global $wpdb; |
| 12 | |
| 13 | $defaults = array( |
| 14 | 'type' => 'monthly', |
| 15 | 'limit' => '', |
| 16 | 'format' => 'html', |
| 17 | 'before' => '', |
| 18 | 'after' => '', |
| 19 | 'show_post_count' => false, |
| 20 | 'echo' => 1, |
| 21 | 'order' => 'DESC', |
| 22 | 'post_type' => 'post' |
| 23 | ); |
| 24 | |
| 25 | $r = wp_parse_args( $args, $defaults ); |
| 26 | $post_type_object = get_post_type_object( $r['post_type'] ); |
| 27 | |
| 28 | if ( ! is_post_type_viewable( $post_type_object ) ) { |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | $r['post_type'] = $post_type_object->name; |
| 33 | $results = $wpdb->get_results( |
| 34 | $wpdb->prepare( |
| 35 | " |
| 36 | SELECT date( post_date ) AS date, |
| 37 | COUNT( ID ) AS count |
| 38 | FROM $wpdb->posts |
| 39 | WHERE post_date < NOW() |
| 40 | AND post_type = '%s' |
| 41 | AND post_status = 'publish' |
| 42 | group by date |
| 43 | ORDER BY post_date DESC |
| 44 | ", |
| 45 | $r['post_type'] |
| 46 | ) |
| 47 | ); |
| 48 | |
| 49 | if ( ! empty( $results ) ) { |
| 50 | wpp_print_archive( $results, $r ); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @param $year |
| 56 | * @param $format |
| 57 | * @param $before |
| 58 | * @param $count |
| 59 | * @param $show_post_count |
| 60 | * @param $r |
| 61 | */ |
| 62 | function echo_yarchive( $year, $format, $before, $count, $show_post_count, $r ) { |
| 63 | if ( $show_post_count ) { |
| 64 | $count = ' (' . fix_number( $count ) . ')'; |
| 65 | } else { |
| 66 | $count = ''; |
| 67 | } |
| 68 | |
| 69 | $url = get_year_link( $year ); |
| 70 | |
| 71 | if ( 'post' !== $r['post_type'] ) { |
| 72 | $url = add_query_arg( 'post_type', $r['post_type'], $url ); |
| 73 | } |
| 74 | |
| 75 | echo get_archives_link( $url, fix_number( $year ), $format, $before, $count ); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * @param $old_date |
| 80 | * @param $format |
| 81 | * @param $before |
| 82 | * @param $count |
| 83 | * @param $show_post_count |
| 84 | * @param $r |
| 85 | */ |
| 86 | function echo_marchive( $old_date, $format, $before, $count, $show_post_count, $r ) { |
| 87 | global $persian_month_names; |
| 88 | |
| 89 | $year = substr( $old_date, 0, 4 ); |
| 90 | $month = substr( $old_date, 4, 2 ); |
| 91 | |
| 92 | if ( $show_post_count ) { |
| 93 | $count = ' (' . fix_number( $count ) . ')'; |
| 94 | } else { |
| 95 | $count = ''; |
| 96 | } |
| 97 | |
| 98 | $url = get_month_link( $year, $month ); |
| 99 | |
| 100 | if ( 'post' !== $r['post_type'] ) { |
| 101 | $url = add_query_arg( 'post_type', $r['post_type'], $url ); |
| 102 | } |
| 103 | |
| 104 | echo get_archives_link( $url, $persian_month_names[ intval( $month ) ] . ' ' . fix_number( $year ), $format, $before, $count ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @param string $args |
| 109 | */ |
| 110 | function wp_get_parchives( $args = '' ) { |
| 111 | global $wpdb; |
| 112 | |
| 113 | $defaults = array( |
| 114 | 'type' => 'monthly', |
| 115 | 'limit' => '', |
| 116 | 'format' => 'html', |
| 117 | 'before' => '', |
| 118 | 'after' => '', |
| 119 | 'show_post_count' => false, |
| 120 | 'echo' => 1, |
| 121 | 'order' => 'DESC' |
| 122 | ); |
| 123 | |
| 124 | $r = wp_parse_args( $args, $defaults ); |
| 125 | |
| 126 | $results = $wpdb->get_results( |
| 127 | " |
| 128 | SELECT date ( post_date ) AS date, |
| 129 | count ( ID ) AS count |
| 130 | FROM $wpdb->posts |
| 131 | WHERE post_date < NOW() |
| 132 | AND post_type = 'post' |
| 133 | AND post_status = 'publish' |
| 134 | GROUP BY date |
| 135 | ORDER BY post_date DESC |
| 136 | " |
| 137 | ); |
| 138 | |
| 139 | if ( ! empty( $results ) ) { |
| 140 | wpp_print_archive( $results, $r ); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * @param $results |
| 146 | * @param $args |
| 147 | */ |
| 148 | function wpp_print_archive( $results, $args ) { |
| 149 | global $persian_month_names; |
| 150 | |
| 151 | if ( $args['type'] == 'yearly' ) { |
| 152 | $old_date = parsidate( 'Y', $results[0]->date, 'eng' ); |
| 153 | $count = $results[0]->count; |
| 154 | $c = count( $results ); |
| 155 | |
| 156 | for ( $i = 1; $i < $c; $i ++ ) { |
| 157 | $dt = $results[ $i ]; |
| 158 | $date = parsidate( 'Y', $dt->date, 'eng' ); |
| 159 | |
| 160 | if ( $date === $old_date ) { |
| 161 | $count += $dt->count; |
| 162 | } else { |
| 163 | echo_yarchive( $old_date, $args['format'], $args['before'], $count, $args['show_post_count'], $args ); |
| 164 | |
| 165 | $old_date = $date; |
| 166 | $count = $dt->count; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | echo_yarchive( $old_date, $args['format'], $args['before'], $count, $args['show_post_count'], $args ); |
| 171 | } elseif ( $args['type'] == 'monthly' ) { |
| 172 | $old_date = parsidate( 'Ym', $results[0]->date, 'eng' ); |
| 173 | $count = $results[0]->count; |
| 174 | $c = count( $results ); |
| 175 | |
| 176 | for ( $i = 1; $i < $c; $i ++ ) { |
| 177 | $dt = $results[ $i ]; |
| 178 | $date = parsidate( 'Ym', $dt->date, 'eng' ); |
| 179 | |
| 180 | if ( $date === $old_date ) { |
| 181 | $count += $dt->count; |
| 182 | } else { |
| 183 | echo_marchive( $old_date, $args['format'], $args['before'], $count, $args['show_post_count'], $args ); |
| 184 | $old_date = $date; |
| 185 | $count = $dt->count; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | echo_marchive( $old_date, $args['format'], $args['before'], $count, $args['show_post_count'], $args ); |
| 190 | } elseif ( $args['type'] == 'daily' ) { |
| 191 | foreach ( $results as $row ) { |
| 192 | $date = parsidate( 'Y,m,d', $row->date, 'eng' ); |
| 193 | $date = explode( ',', $date ); |
| 194 | |
| 195 | if ( $args['show_post_count'] ) { |
| 196 | $count = ' (' . fix_number( $row->count ) . ')'; |
| 197 | } else { |
| 198 | $count = ''; |
| 199 | } |
| 200 | |
| 201 | $text = fix_number( $date[2] ) . ' ' . $persian_month_names[ intval( $date[1] ) ] . ' ' . fix_number( $date[0] ); |
| 202 | |
| 203 | echo get_archives_link( get_day_link( $date[0], $date[1], $date[2] ), $text, $args['format'], $args['before'], $count ); |
| 204 | } |
| 205 | } |
| 206 | } |