New calendar code.

git-svn-id: http://svn.automattic.com/wordpress/trunk@510 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2003-11-03 17:22:01 +00:00
parent a85aef276b
commit 0a96910405
4 changed files with 87 additions and 375 deletions

View File

@ -228,8 +228,8 @@ function get_archives($type='', $limit='', $format='html', $before = "", $after
}
}
function get_calendar() {
global $wpdb, $HTTP_GET_VARS, $m, $monthnum, $year, $timedifference, $month, $tableposts;
function get_calendar($daylength = 1) {
global $wpdb, $HTTP_GET_VARS, $m, $monthnum, $year, $timedifference, $month, $weekday, $tableposts;
// Quick check. If we have no posts at all, abort!
if (!$posts) {
$gotsome = $wpdb->get_var("SELECT ID from $tableposts WHERE post_status = 'publish' AND post_category > 0 ORDER BY post_date DESC LIMIT 1");
@ -268,50 +268,51 @@ $unixmonth = mktime(0, 0 , 0, $thismonth, 1, $thisyear);
$previous = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year
FROM $tableposts
WHERE post_date < '$thisyear-$thismonth-01'
AND post_status = 'publish'
ORDER BY post_date DESC
LIMIT 1");
$next = $wpdb->get_row("SELECT DISTINCT MONTH( post_date ) AS month, YEAR( post_date ) AS year
FROM $tableposts
WHERE post_date > '$thisyear-$thismonth-01' AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
WHERE post_date > '$thisyear-$thismonth-01'
AND MONTH( post_date ) != MONTH( '$thisyear-$thismonth-01' )
AND post_status = 'publish'
ORDER BY post_date ASC
LIMIT 1 ");
LIMIT 1");
echo '<table id="wp-calendar">
<caption>' . $month[zeroise($thismonth, 2)] . ' ' . date('Y', $unixmonth) . '</caption>
<thead>
<tr>
<th abbr="Sunday" scope="col" title="Sunday">Sun</th>
<th abbr="Monday" scope="col" title="Monday">Mon</th>
<th abbr="Tuesday" scope="col" title="Tuesday">Tue</th>
<th abbr="Wednesday" scope="col" title="Wednesday">Wed</th>
<th abbr="Thursday" scope="col" title="Thursday">Thu</th>
<th abbr="Friday" scope="col" title="Friday">Fri</th>
<th abbr="Saturday" scope="col" title="Saturday">Sat</th>
</tr>
<tr>';
foreach ($weekday as $wd) {
echo "\n\t<th abbr='$wd' scope='col' title='$wd'>" . substr($wd, 0, $daylength) . '</th>';
}
echo ' </tr>
</thead>
<tfoot>
<tr>';
if ($previous) {
echo '<th abbr="' . $month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' .
echo "\n\t".'<td abbr="' . $month[zeroise($previous->month, 2)] . '" colspan="3" id="prev"><a href="' .
get_month_link($previous->year, $previous->month) . '" title="View posts for ' . $month[zeroise($previous->month, 2)] . ' ' .
date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)) . '">&laquo; ' . substr($month[zeroise($previous->month, 2)], 0, 3) . '</a>';
date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)) . '">&laquo; ' . substr($month[zeroise($previous->month, 2)], 0, 3) . '</a></td>';
} else {
echo '<th colspan="3" id="prev">&laquo;</th>';
echo "\n\t".'<td colspan="3" id="prev">&laquo;</td>';
}
echo '<th>&nbsp;</th>';
echo "\n\t".'<td>&nbsp;</td>';
if ($next) {
echo '<th abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' .
echo "\n\t".'<td abbr="' . $month[zeroise($next->month, 2)] . '" colspan="3" id="next"><a href="' .
get_month_link($previous->year, $next->month) . '" title="View posts for ' . $month[zeroise($next->month, 2)] . ' ' .
date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year)) . '">' . substr($month[zeroise($next->month, 2)], 0, 3) . ' &raquo;</a>';
date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year)) . '">' . substr($month[zeroise($next->month, 2)], 0, 3) . ' &raquo;</a></td>';
} else {
echo '<th colspan="3" id="next">&raquo;</th>';
echo "\n\t".'<td colspan="3" id="next">&raquo;</td>';
}
echo ' </tr>
echo '
</tr>
</tfoot>
<tbody>
@ -323,19 +324,26 @@ $dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
AND YEAR(post_date) = $thisyear
AND post_status = 'publish'
AND post_date < '" . date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."'", ARRAY_N);
foreach ($dayswithposts as $daywith) {
$daywithpost[] = $daywith[0];
if ($dayswithposts) {
foreach ($dayswithposts as $daywith) {
$daywithpost[] = $daywith[0];
}
} else {
$daywithpost = array();
}
// See how much we should pad in the beginning
$pad = intval(date('w', $unixmonth));
if (0 != $pad) echo "\n\t<td class='empty' colspan='$pad'>&nbsp;</td>";
if (0 != $pad) echo "\n\t<td colspan='$pad'>&nbsp;</td>";
$daysinmonth = intval(date('t', $unixmonth));
for ($day = 1; $day <= $daysinmonth; ++$day) {
if ($newrow) echo "\n</tr>\n <tr>";
if ($newrow) echo "\n </tr>\n <tr>\n\t";
$newrow = false;
echo "\n\t<td>";
if ($day == date('j', (time() + ($time_difference * 3600)))) echo '<td id="today">';
else echo "<td>";
if (in_array($day, $daywithpost)) {
echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\">$day</a>";

View File

@ -1,310 +0,0 @@
<?php
// $Id$
// b2 Calendar
//
// Contributed work by:
// Alex King
// http://www.alexking.org
//
// Mike Little for his bug fixes
// http://zed1.com/b2/
//
// Fred Cooper for querystring bugfix
// http://frcooper.com/journal/
//
// b2 is copyright (c) 2001, 2002, 2003 by Michel Valdrighi - m@tidakada.com
//
// Contributed portions copyright (c) various authors with permission
//
// original arrow hack by Alex King
$ak_use_arrows = 1; // set to 0 to hide the arrows
$ak_use_tooltip_titles = 1; // set to 0 to hide the tooltip titles
/* customize these as you wish */
$calendarmonthdisplay = 1; // set this to 0 if you don't want to display the month name
$calendarmonthformat = 'F Y';
$calendarmonthstart = '<caption class="b2calendarmonth">';
$calendarmonthend = '</caption>';
$calendartablestart = '<table class="b2calendartable" summary="Monthly calendar with links to each day\'s posts">';
$calendartableend = '</table>';
$calendarrowstart = '<tr class="b2calendarrow">';
$calendarrowend = '</tr>';
$calendarheaderdisplay = 1; // set this to 0 if you don't want to display the "Mon Tue Wed..." header
$calendarheadercellstart = '<th class="b2calendarheadercell" abbr="$abbr">'; // please leave $abbr there !
$calendarheadercellend = '</th>';
$calendarheaderabbrlength = 1; // length of the shortened weekday
$calendarcellstart = '<td class="b2calendarcell">';
$calendarcellend = '</td>';
$calendaremptycellstart = '<td class="b2calendaremptycell">';
$calendaremptycellend = '</td>';
$calendaremptycellcontent = '&nbsp;';
/* stop customizing (unless you really know what you're doing) */
require_once('wp-config.php');
require_once($abspath.$b2inc.'/b2template.functions.php');
require_once($abspath.$b2inc.'/b2functions.php');
require_once($abspath.$b2inc.'/b2vars.php');
// Quick check. If we have no posts at all, abort!
if (!$posts) {
$gotsome = $wpdb->get_var("SELECT ID from $tableposts WHERE post_status = 'publish' AND post_category > 0 ORDER BY post_date DESC LIMIT 1");
if (!$gotsome)
return;
}
$w = $HTTP_GET_VARS['w'];
if (isset($HTTP_GET_VARS['w'])) {
$w = $HTTP_GET_VARS['w'];
}
if (isset($calendar) && ($calendar != '')) {
$thisyear = substr($calendar,0,4);
$thismonth = substr($calendar,4,2);
} else {
if (isset($w) && ($w != '')) {
$thisyear = substr($m,0,4);
$w = ''.intval($w);
$d = (($w - 1) * 7) + 6; //it seems mysqls weeks disagree with php's
$thismonth = $wpdb->get_var("SELECT DATE_FORMAT((DATE_ADD('${thisyear}0101', INTERVAL $d DAY) ), '%m')");
} else if (isset($m) && ($m != '')) {
$calendar = substr($m,0,6);
$thisyear = substr($m,0,4);
if (strlen($m) < 6) {
$thismonth = '01';
} else {
$thismonth = substr($m,4,2);
}
} else {
$thisyear = date('Y', time()+($time_difference * 3600));
$thismonth = date('m', time()+($time_difference * 3600));
}
}
$archive_link_m = $siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal;
// original arrow hack by Alex King
$ak_previous_year = $thisyear;
$ak_next_year = $thisyear;
$ak_previous_month = $thismonth - 1;
$ak_next_month = $thismonth + 1;
if ($ak_previous_month == 0) {
$ak_previous_month = 12;
--$ak_previous_year;
}
if ($ak_next_month == 13) {
$ak_next_month = 1;
++$ak_next_year;
}
$ak_first_post = $wpdb->get_row("SELECT MONTH(MIN(post_date)) AS min_month, YEAR(MIN(post_date)) AS min_year FROM $tableposts");
// using text links by default
$ak_previous_month_dim = '<span>&laquo;</span>&nbsp;&nbsp;';
$ak_previous_month_active = '<a href="'.$archive_link_m.$ak_previous_year.zeroise($ak_previous_month,2).'" style="text-decoration: none;">&laquo;</a>&nbsp;&nbsp;';
$ak_next_month_dim = '&nbsp;&nbsp;<span>&raquo;</span>';
$ak_next_month_active = '&nbsp;&nbsp;<a href="'.$archive_link_m.$ak_next_year.zeroise($ak_next_month,2).'" style="text-decoration: none;">&raquo;</a>';
if ($ak_use_arrows == 1) {
if (mktime(0,0,0,$ak_previous_month,1,$ak_previous_year) < mktime(0,0,0,$ak_first_post->min_month,1,$ak_first_post->min_year)) {
$ak_previous_month_link = $ak_previous_month_dim;
} else {
$ak_previous_month_link = $ak_previous_month_active;
}
if (mktime(0,0,0,$ak_next_month,1,$ak_next_year) > mktime()) {
$ak_next_month_link = $ak_next_month_dim;
} else {
$ak_next_month_link = $ak_next_month_active;
}
} else {
$ak_previous_month_link = "";
$ak_next_month_link = "";
}
$end_of_week = (($start_of_week + 7) % 7);
$calendarmonthwithpost = 0;
while($calendarmonthwithpost == 0) {
$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) AS dom "
."FROM $tableposts "
."WHERE MONTH(post_date) = '$thismonth' "
."AND YEAR(post_date) = '$thisyear' "
."AND post_date < '".date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."' "
."AND post_status = 'publish' "
."ORDER BY post_date DESC";
$querycount++;
$arc_results = $wpdb->get_results($arc_sql);
if ($wpdb->num_rows > 0) {
$daysinmonthwithposts = '-';
foreach ($arc_results as $arc_row) {
$daysinmonthwithposts .= $arc_row->dom.'-';
}
$calendarmonthwithpost = 1;
} elseif ($calendar != '') {
$daysinmonthwithposts = '';
$calendarmonthwithpost = 1;
} else {
$thismonth = zeroise(intval($thismonth)-1,2);
if ($thismonth == '00') {
$thismonth = '12';
$thisyear = ''.(intval($thisyear)-1);
}
}
}
$daysinmonth = intval(date('t', mktime(0,0,0,$thismonth,1,$thisyear)));
$datestartofmonth = $thisyear.'-'.$thismonth.'-01';
$dateendofmonth = $thisyear.'-'.$thismonth.'-'.$daysinmonth;
// caution: offset bug inside
$calendarblah = get_weekstartend($datestartofmonth, $start_of_week);
if (mysql2date('w', $datestartofmonth) == $start_of_week) {
$calendarfirst = $calendarblah['start']+1+3600; // adjust for daylight savings time
} else {
$calendarfirst = $calendarblah['end']-604799+3600; // adjust for daylight savings time
}
$calendarblah = get_weekstartend($dateendofmonth, $end_of_week);
if (mysql2date('w', $dateendofmonth) == $end_of_week) {
$calendarlast = $calendarblah['start']+1;
} else {
$calendarlast = $calendarblah['end']+10000;
}
$beforethismonth = zeroise(intval($thismonth)-1,2);
$afterthismonth = zeroise(intval($thismonth)-1,2);
// here the offset bug is corrected
if ((intval(date('d', $calendarfirst)) > 1) && (intval(date('m', $calendarfirst)) == intval($thismonth))) {
$calendarfirst = $calendarfirst - 604800;
}
// displays everything
echo $calendartablestart."\n";
if ($calendarmonthdisplay) {
echo $calendarmonthstart;
echo $ak_previous_month_link;
echo date_i18n($calendarmonthformat, mktime(0, 0, 0, $thismonth, 1, $thisyear));
echo $ak_next_month_link;
echo $calendarmonthend."\n";
}
if ($calendarheaderdisplay) {
echo $calendarrowstart."\n";
for ($i = $start_of_week; $i<($start_of_week+7); $i = $i + 1) {
echo str_replace('$abbr', $weekday[($i % 7)], $calendarheadercellstart);
echo ucwords(substr($weekday[($i % 7)], 0, $calendarheaderabbrlength));
echo $calendarheadercellend;
}
echo $calendarrowend."\n";
}
echo $calendarrowstart."\n";
$newrow = 0;
$j = 0;
$k = 1;
// original tooltip hack by Alex King
if ($ak_use_tooltip_titles == 1) {
$ak_days_result = $wpdb->get_results("SELECT post_title, post_date "
."FROM $tableposts "
."WHERE YEAR(post_date) = '$thisyear' "
."AND MONTH(post_date) = '$thismonth' "
."AND post_date < '".date("Y-m-d H:i:s", (time() + ($time_difference * 3600)))."' "
."AND post_status = 'publish'"
);
$ak_day_title_array = array();
if ($ak_days_result) {
foreach($ak_days_result as $ak_temp) {
$ak_day_title_array[] = $ak_temp;
}
}
if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") ||
strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), "camino")) {
$ak_title_separator = "\n";
$ak_trim = 1;
}
else {
$ak_title_separator = ", ";
$ak_trim = 2;
}
}
for($i = $calendarfirst; $i<($calendarlast+86400); $i = $i + 86400) {
if ($newrow == 1) {
if ($k > $daysinmonth) {
break;
}
echo $calendarrowend."\n";
//if (($i+86400) < ($calendarlast+86400)) {
echo $calendarrowstart."\n";
//}
$newrow = 0;
}
if (date('m',$i) != $thismonth) {
echo $calendaremptycellstart;
echo $calendaremptycellcontent;
echo $calendaremptycellend;
} else {
$k = $k + 1;
echo $calendarcellstart;
$calendarblah = '-'.date('j',$i).'-';
$calendarthereisapost = ereg($calendarblah, $daysinmonthwithposts);
$calendartoday = (date('Ymd',$i) == date('Ymd', (time() + ($time_difference * 3600))));
if ($calendarthereisapost) {
// original tooltip hack by Alex King
if ($ak_use_tooltip_titles == 1) { // check to see if we want to show the tooltip titles
$ak_day_titles = "";
foreach($ak_day_title_array as $post) {
if (substr($post->post_date, 8, 2) == date('d',$i)) {
$ak_day_titles = $ak_day_titles.htmlspecialchars(stripslashes($post->post_title)).$ak_title_separator;
}
}
$ak_day_titles = substr($ak_day_titles, 0, strlen($ak_day_titles) - $ak_trim);
echo '<a href="'.$siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal.$thisyear.$thismonth.date('d',$i).'" class="b2calendarlinkpost" title="'.$ak_day_titles.'">';
}
else {
echo '<a href="'.$siteurl.'/'.$blogfilename.$querystring_start.'m'.$querystring_equal.$thisyear.$thismonth.date('d',$i).'" class="b2calendarlinkpost">';
}
}
if ($calendartoday) {
echo '<span class="b2calendartoday">';
}
echo date('j',$i);
if ($calendartoday) {
echo '</span>';
}
if ($calendarthereisapost) {
echo '</a>';
}
echo $calendarcellend."\n";
}
$j = $j + 1;
if ($j == 7) {
$j = 0;
$newrow = 1;
}
}
echo $calendarrowend."\n";
echo $calendartableend;
?>

View File

@ -89,11 +89,7 @@ require_once($abspath.'wp-links/links.php');
</ul>
</li>
<li>Calendar:
<ul>
<li>
<?php include_once('b2calendar.php')?>
</li>
</ul>
<?php get_calendar(); ?>
</li>
<li>Other:
<ul>

View File

@ -1,5 +1,5 @@
/* Default WordPress by Dave Shea || http://mezzoblue.com
Tweaked by Matthew Mullenweg || http://photomatt.net
Modifications by Matthew Mullenweg || http://photomatt.net
This is just a basic layout, with only the bare minimum defined.
Please tweak this and make it your own. :)
*/
@ -73,39 +73,6 @@ p, li, .feedback {
letter-spacing: -1px;
}
.b2calendarcell {
color: #000;
}
.b2calendaremptycell {
}
.b2calendarheadercell {
background: #808080;
color: #ccc;
}
.b2calendarlinkpost {
color: #f00;
text-decoration: none;
}
.b2calendarmonth {
color: #aaa;
}
.b2calendarrow {
color: #0f0;
}
.b2calendartable {
background: #fff;
border: 1px solid #000;
}
.b2calendartoday {
color: #00f;
}
.credit {
background: #90a090;
@ -238,3 +205,54 @@ p, li, .feedback {
#menu ul ul li a:hover {
border-bottom: 1px solid #809080;
}
#wp-calendar {
border: 1px solid #ddd;
empty-cells: show;
font-size: 14px;
margin: 0;
width: 90%;
}
#wp-calendar #next a {
padding-right: 10px;
text-align: right;
}
#wp-calendar #prev a {
padding-left: 10px;
text-align: left;
}
#wp-calendar a {
display: block;
text-decoration: none;
}
#wp-calendar a:hover {
background: #e0e6e0;
color: #333;
}
#wp-calendar caption {
color: #999;
font-size: 16px;
}
#wp-calendar td {
color: #ccc;
font: normal 12px 'Lucida Grande', 'Lucida Sans Unicode', Verdana, sans-serif;
text-align: center;
padding: 2px 0;
letter-spacing: normal;
}
#wp-calendar td:hover, #wp-calendar #today {
background: #eee;
color: #bbb;
}
#wp-calendar th {
font-style: normal;
text-transform: capitalize;
}