. See http://diveintomark.org/archives/2002/07/03 */ @list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable if($p) $p = ''.($pl ? ''.$p.'' : $p).' '; if($n) $n = ' '.($nl ? ''.$n.'' : $n).''; $calendar = ''."\n"; if( $want_caption ) { $calendar .= '\n"; } $calendar .= ""; if($day_name_length) { #if the day names should be shown ($day_name_length > 0) #if day_name_length is >3, the full name of the day will be printed foreach($day_names as $d) { $calendar .= ''; } $calendar .= "\n"; } $curr_year = (int) date( "Y" ); $curr_month = (int) date( "n" ); $curr_day = (int) date( "d" ); if( $weekday > 0 ) $calendar .= ''; #initial 'empty' days for( $day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++) { if( $weekday == 7 ) { $weekday = 0; #start a new week $calendar .= "\n"; } if(isset($days[$day]) and is_array($days[$day])) { @list($link, $classes, $content) = $days[$day]; if(is_null($content)) $content = $day; $calendar .= '' : '>'). ($link ? ''.$content.'' : $content).''; } else { if( ($year == $curr_year) && ($month == $curr_month) && ($day > $curr_day) ) { $calendar .= ""; } else { $calendar .= ""; } } } if($weekday != 7) $calendar .= ''; #remaining "empty" days return $calendar."\n
'.$p.($month_href ? ''.$title.'' : $title).$n."
'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'
 
$day$day 
\n"; } /* generate_calendar */ /* * GetDays * * read day directories in a month directory */ function GetDays( $dir ) { ini_set("max_execution_time",10); if( $root=@opendir($dir)) { while( $file=readdir($root) ) { if( $file=="." || $file=="..") { continue; } if(is_dir($dir."/".$file)) { $files[]= (int) $file; } } } sort( $files, SORT_NUMERIC ); return $files; } /* GetDays */ /* * * Mainline code begins * */ $months = array ( 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ); /* * get the cmdline variables */ reset($HTTP_GET_VARS); $year = (int)$HTTP_GET_VARS['year']; $month = (int) $HTTP_GET_VARS['month']; $rootdir = $HTTP_GET_VARS['rootdir']; if( $rootdir == NULL || $rootdir == "" ) { $rootdir = "myblog"; } $dir_hl = sprintf( "/%04d/%02d", $year, $month ); $dir = "/" . $rootdir . $dir_hl; $archive = "$dir_hl/index.php"; /* * previous month */ $month_prev = $month-1; $year_prev = $year; if( $month_prev == 0 ) { $month_prev = 12; $year_prev -= 1; } $dir_prev_hl = sprintf( "/%04d/%02d", $year_prev, $month_prev ); $dir_prev = "/" . $rootdir . $dir_prev_hl; /* * next month */ $month_next = $month+1; $year_next = $year; if( $month_next == 13 ) { $month_next = 1; $year_next += 1; } $dir_next_hl = sprintf( "/%04d/%02d", $year_next, $month_next ); $dir_next = "/" . $rootdir . $dir_next_hl; /* * month header, includes back & next links (if needed) */ $month_name = $months[$month-1]; echo "

"; if( is_dir($dir_prev) ) { echo "« "; } echo "$month_name $year"; if( is_dir($dir_next) ) { echo " »"; } echo "

"; /* * get the list of days that have links */ $days = GetDays( $dir ); $numfiles = count( $days ); $daylist = array( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ); for( $i=0;$i<$numfiles;$i++ ) { $file = sprintf( "%s/%02d/index.php", $dir_hl, $days[$i] ); $daylist[ $days[$i]] = array( $file, 'linked-day' ); } /* * finally - go make the calendar */ echo "
"; echo generate_calendar($year, $month, $daylist, 3, '$archive', 0, NULL, false ); echo "
"; ?>