Changeset 508
- Timestamp:
- 11/03/2003 07:30:04 AM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/b2-include/b2template.functions.php
r506 r508 228 228 } 229 229 } 230 231 function get_calendar() { 232 // Quick check. If we have no posts at all, abort! 233 if (!$posts) { 234 $gotsome = $wpdb->get_var("SELECT ID from $tableposts WHERE post_status = 'publish' AND post_category > 0 ORDER BY post_date DESC LIMIT 1"); 235 if (!$gotsome) 236 return; 237 } 238 239 $w = ''.intval($HTTP_GET_VARS['w']); 240 $time_difference = get_settings('time_difference'); 241 242 // Let's figure out when we are 243 if (!empty($monthnum) && !empty($year)) { 244 $thismonth = ''.intval($monthnum); 245 $thisyear = ''.intval($year); 246 } elseif (!empty($w)) { 247 // We need to get the month from MySQL 248 $thisyear = ''.intval(substr($m, 0, 4)); 249 $d = (($w - 1) * 7) + 6; //it seems mysqls weeks disagree with php's 250 $thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')"); 251 } elseif (!empty($m)) { 252 $calendar = substr($m, 0, 6); 253 $thisyear = ''.intval(substr($m, 0, 4)); 254 if (strlen($m) < 6) { 255 $thismonth = '01'; 256 } else { 257 $thismonth = ''.intval(substr($m, 4, 2)); 258 } 259 } else { 260 $thisyear = intval(date('Y', time()+($time_difference * 3600))); 261 $thismonth = intval(date('m', time()+($time_difference * 3600))); 262 } 263 264 $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear); 265 266 // Get the next and previous month and year with at least one post 267 $previous = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year 268 FROM $tableposts 269 WHERE post_date < '$thisyear-$thismonth-01' 270 ORDER BY post_date DESC 271 LIMIT 1"); 272 $next = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year 273 FROM $tableposts 274 WHERE post_date > '$thisyear-$thismonth-01' AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' ) 275 ORDER BY post_date ASC 276 LIMIT 1 "); 277 278 echo '<table id="wp-calendar"> 279 <caption>' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption> 280 <thead> 281 <tr> 282 <th abbr="Sunday" scope="col" title="Sunday">Sun</th> 283 <th abbr="Monday" scope="col" title="Monday">Mon</th> 284 <th abbr="Tuesday" scope="col" title="Tuesday">Tue</th> 285 <th abbr="Wednesday" scope="col" title="Wednesday">Wed</th> 286 <th abbr="Thursday" scope="col" title="Thursday">Thu</th> 287 <th abbr="Friday" scope="col" title="Friday">Fri</th> 288 <th abbr="Saturday" scope="col" title="Saturday">Sat</th> 289 </tr> 290 </thead> 291 292 <tfoot> 293 <tr>'; 294 295 if ($previous) { 296 echo '<th abbr="' . $month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' . 297 get_month_link($previous->year, $previous->month) . '" title="View posts for ' . $month[zeroise($previous->month, 2)] . ' ' . 298 date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)) . '">« ' . substr($month[zeroise($previous->month, 2)], 0, 3) . '</a>'; 299 } else { 300 echo '<th colspan="3" id="prev">«</th>'; 301 } 302 303 echo '<th> </th>'; 304 305 if ($next) { 306 echo '<th abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' . 307 get_month_link($previous->year, $next->month) . '" title="View posts for ' . $month[zeroise($next->month, 2)] . ' ' . 308 date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year)) . '">» ' . substr($month[zeroise($next->month, 2)], 0, 3) . '</a>'; 309 } else { 310 echo '<th colspan="3" id="next">»</th>'; 311 } 312 313 echo ' </tr> 314 </tfoot> 315 316 <tbody> 317 <tr>'; 318 319 // Get days with posts 320 $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date) 321 FROM wp_posts WHERE MONTH(post_date) = $thismonth 322 AND YEAR(post_date) = $thisyear 323 AND post_status = 'publish' 324 AND post_date < '" . date("Y-m-d H:i:s", (time() + ($time_difference * 3600))), ARRAY_N); 325 326 // TODO: Make days with posts linked 327 328 // See how much we should pad in the beginning 329 $pad = intval(date('w', $unixmonth)); 330 if (0 != $pad) echo "\n\t<td class='empty' colspan='$pad'> </td>"; 331 332 $daysinmonth = intval(date('t', $unixmonth)); 333 for ($day = 1; $day <= $daysinmonth; ++$day) { 334 if ($newrow) echo "\n</tr>\n <tr>"; 335 $newrow = false; 336 echo "\n\t<td>$day</td>"; 337 if (6 == date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))) $newrow = true; 338 } 339 $pad = 7 - date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear)); 340 if (0 != $pad) echo "\n\t<td class='empty' colspan='$pad'> </td>"; 341 342 echo "\n </tr>\n</tbody>\n</table>"; 343 } 344 230 345 /***** // About-the-blog tags *****/ 231 346
Note: See TracChangeset
for help on using the changeset viewer.