PluginProbe
Welcart e-Commerce / 1.3.3
Welcart e-Commerce v1.3.3
2.12.4 2.12.3 2.11.35 2.12.2 2.12.1 2.11.34 2.11.33 2.11.32 2.11.31 2.11.30 1.3.16 1.3.17 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 292 releases
usc-e-shop / widgets / usces_blog_calendar.php

usces_blog_calendar.php in Welcart e-Commerce 1.3.3, at widgets/usces_blog_calendar.php

247 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 function get_wcblog_calendar($initial = true, $echo = true) {
3 global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
4
5 $cache = array();
6 $key = md5( $m . $monthnum . $year );
7 // if ( $cache = wp_cache_get( 'get_calendar', 'calendar' ) ) {
8 // if ( is_array($cache) && isset( $cache[ $key ] ) ) {
9 // if ( $echo ) {
10 // echo apply_filters( 'get_calendar', $cache[$key] );
11 // return;
12 // } else {
13 // return apply_filters( 'get_calendar', $cache[$key] );
14 // }
15 // }
16 // }
17
18 if ( !is_array($cache) )
19 $cache = array();
20
21 // Quick check. If we have no posts at all, abort!
22 if ( !$posts ) {
23 $gotsome = $wpdb->get_var("SELECT 1 as test FROM $wpdb->posts WHERE post_type = 'post' AND post_mime_type <> 'item' AND post_status = 'publish' LIMIT 1");
24 if ( !$gotsome ) {
25 $cache[ $key ] = '';
26 wp_cache_set( 'get_calendar', $cache, 'calendar' );
27 return;
28 }
29 }
30
31 if ( isset($_GET['w']) )
32 $w = ''.intval($_GET['w']);
33
34 // week_begins = 0 stands for Sunday
35 $week_begins = intval(get_option('start_of_week'));
36
37 // Let's figure out when we are
38 if ( !empty($monthnum) && !empty($year) ) {
39 $thismonth = ''.zeroise(intval($monthnum), 2);
40 $thisyear = ''.intval($year);
41 } elseif ( !empty($w) ) {
42 // We need to get the month from MySQL
43 $thisyear = ''.intval(substr($m, 0, 4));
44 $d = (($w - 1) * 7) + 6; //it seems MySQL's weeks disagree with PHP's
45 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
46 } elseif ( !empty($m) ) {
47 $thisyear = ''.intval(substr($m, 0, 4));
48 if ( strlen($m) < 6 )
49 $thismonth = '01';
50 else
51 $thismonth = ''.zeroise(intval(substr($m, 4, 2)), 2);
52 } else {
53 $thisyear = gmdate('Y', current_time('timestamp'));
54 $thismonth = gmdate('m', current_time('timestamp'));
55 }
56
57 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
58
59 // Get the next and previous month and year with at least one post
60 $previous = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
61 FROM $wpdb->posts
62 WHERE post_date < '$thisyear-$thismonth-01'
63 AND post_mime_type <> 'item'
64 AND post_type = 'post' AND post_status = 'publish'
65 ORDER BY post_date DESC
66 LIMIT 1");
67 $next = $wpdb->get_row("SELECT DISTINCT MONTH(post_date) AS month, YEAR(post_date) AS year
68 FROM $wpdb->posts
69 WHERE post_date > '$thisyear-$thismonth-01'
70 AND post_mime_type <> 'item'
71 AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
72 AND post_type = 'post' AND post_status = 'publish'
73 ORDER BY post_date ASC
74 LIMIT 1");
75
76 /* translators: Calendar caption: 1: month name, 2: 4-digit year */
77 $calendar_caption = _x('%1$s %2$s', 'calendar caption');
78 $calendar_output = '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '">
79 <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
80 <thead>
81 <tr>';
82
83 $myweek = array();
84
85 for ( $wdcount=0; $wdcount<=6; $wdcount++ ) {
86 $myweek[] = $wp_locale->get_weekday(($wdcount+$week_begins)%7);
87 }
88
89 foreach ( $myweek as $wd ) {
90 $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
91 $wd = esc_attr($wd);
92 $calendar_output .= "\n\t\t<th scope=\"col\" title=\"$wd\">$day_name</th>";
93 }
94
95 $calendar_output .= '
96 </tr>
97 </thead>
98
99 <tfoot>
100 <tr>';
101
102 if ( $previous ) {
103 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
104 } else {
105 $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
106 }
107
108 $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
109
110 if ( $next ) {
111 $calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
112 } else {
113 $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
114 }
115
116 $calendar_output .= '
117 </tr>
118 </tfoot>
119
120 <tbody>
121 <tr>';
122
123 // Get days with posts
124 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
125 FROM $wpdb->posts WHERE MONTH(post_date) = '$thismonth'
126 AND post_mime_type <> 'item'
127 AND YEAR(post_date) = '$thisyear'
128 AND post_type = 'post' AND post_status = 'publish'
129 AND post_date < '" . current_time('mysql') . '\'', ARRAY_N);
130 if ( $dayswithposts ) {
131 foreach ( (array) $dayswithposts as $daywith ) {
132 $daywithpost[] = $daywith[0];
133 }
134 } else {
135 $daywithpost = array();
136 }
137
138 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'camino') !== false || stripos($_SERVER['HTTP_USER_AGENT'], 'safari') !== false)
139 $ak_title_separator = "\n";
140 else
141 $ak_title_separator = ', ';
142
143 $ak_titles_for_day = array();
144 $ak_post_titles = $wpdb->get_results("SELECT ID, post_title, DAYOFMONTH(post_date) as dom "
145 ."FROM $wpdb->posts "
146 ."WHERE YEAR(post_date) = '$thisyear' "
147 ."AND MONTH(post_date) = '$thismonth' "
148 ."AND post_mime_type <> 'item' "
149 ."AND post_date < '".current_time('mysql')."' "
150 ."AND post_type = 'post' AND post_status = 'publish'"
151 );
152 if ( $ak_post_titles ) {
153 foreach ( (array) $ak_post_titles as $ak_post_title ) {
154
155 $post_title = esc_attr( apply_filters( 'the_title', $ak_post_title->post_title, $ak_post_title->ID ) );
156
157 if ( empty($ak_titles_for_day['day_'.$ak_post_title->dom]) )
158 $ak_titles_for_day['day_'.$ak_post_title->dom] = '';
159 if ( empty($ak_titles_for_day["$ak_post_title->dom"]) ) // first one
160 $ak_titles_for_day["$ak_post_title->dom"] = $post_title;
161 else
162 $ak_titles_for_day["$ak_post_title->dom"] .= $ak_title_separator . $post_title;
163 }
164 }
165
166
167 // See how much we should pad in the beginning
168 $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
169 if ( 0 != $pad )
170 $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
171
172 $daysinmonth = intval(date('t', $unixmonth));
173 for ( $day = 1; $day <= $daysinmonth; ++$day ) {
174 if ( isset($newrow) && $newrow )
175 $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
176 $newrow = false;
177
178 if ( $day == gmdate('j', current_time('timestamp')) && $thismonth == gmdate('m', current_time('timestamp')) && $thisyear == gmdate('Y', current_time('timestamp')) )
179 $calendar_output .= '<td id="today">';
180 else
181 $calendar_output .= '<td>';
182
183 if ( in_array($day, $daywithpost) ) // any posts today?
184 $calendar_output .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
185 else
186 $calendar_output .= $day;
187 $calendar_output .= '</td>';
188
189 if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
190 $newrow = true;
191 }
192
193 $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
194 if ( $pad != 0 && $pad != 7 )
195 $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
196
197 $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
198
199 $cache[ $key ] = $calendar_output;
200 wp_cache_set( 'get_calendar', $cache, 'calendar' );
201
202 if ( $echo )
203 echo apply_filters( 'get_calendar', $calendar_output );
204 else
205 return apply_filters( 'get_calendar', $calendar_output );
206
207 }
208
209 class Welcart_Blog_Calendar extends WP_Widget {
210
211 function Welcart_Blog_Calendar() {
212 $widget_ops = array('classname' => 'welcart_blog_calendar', 'description' => __( 'A calendar of your site&#8217;s posts').'(商品以外)' );
213 $this->WP_Widget('welcart-blog-calendar', 'Welcart Blog Calendar', $widget_ops);
214 }
215
216 function widget( $args, $instance ) {
217 extract($args);
218 $title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title'], $instance, $this->id_base);
219 echo $before_widget;
220 if ( $title )
221 echo $before_title . $title . $after_title;
222 echo '<div id="calendar_wrap">';
223 get_wcblog_calendar();
224 echo '</div>';
225 echo $after_widget;
226 }
227
228 function update( $new_instance, $old_instance ) {
229 $instance = $old_instance;
230 $instance['title'] = strip_tags($new_instance['title']);
231
232 return $instance;
233 }
234
235 function form( $instance ) {
236 $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
237 $title = strip_tags($instance['title']);
238 ?>
239 <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
240 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
241 <?php
242 }
243 }
244
245
246
247 ?>