Skip to content
Snippets Groups Projects
Commit e04a7c3c authored by Dries Buytaert's avatar Dries Buytaert
Browse files

* Thoughts and `Why?'
  -------------------
  I created a sweet little class that is able to generate tiny calendars.
  98% of all portals (incl. big portals like slashdot and kuro5hin) lack
  a decent way to browse older stories that 'felt' of the news page.  At
  these sites, the only way to access older news is by using the search
  form which - I think - will only very few people tend to do.  If you do
  not know what you are searching for, this isn't very easy neither. As
  a consequence, older stories are often completly forgotten and
  discussions simply drop death as soon they felt of the main page.

  Many stories are actually timeless and can stay interesting and 'live'
  for a longer period of time.  By making them hard to access they are
  often killed before the discussion died peacefully on it's own.

  In other words:
  ---------------
  My calendar class is an attempt to make browsing archives (i.e. older
  stories) (a) possible and (b) easy to do ... and is hence considered a
  navigation improvement compared with the majority of all portals.
  IMHO, small improvements like these can and will make us better in the
  end.

  I suggest to integrate it on the main page if you all agree.  You can
  check a `demo' at
     http://beta.drop.org/calendar.class.php
  but be aware: it isn't linked with the database yet so you actually
  can't navigate anything yet.  ;)

Throw in your 2 cents and let me know what you think of it please!
parent fbfb8281
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<?
class calendar {
var $date;
function calendar($date) {
$this->date = $date;
}
function display() {
global $PHP_SELF;
### Extract information from the given date:
$month = date("n", $this->date);
$year = date("Y", $this->date);
### Extract first day of the month:
$first = date("w", mktime(0, 0, 0, $month, 1, $year));
### Extract last day of the month:
$last = date("t", mktime(0, 0, 0, $month, 1, $year));
### Calculate previous and next months dates:
$prev = mktime(0, 0, 0, $month - 1, 1, $year);
$next = mktime(0, 0, 0, $month + 1, 1, $year);
### Generate calendar header:
print "<TABLE WIDTH=\"160\" BORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"2\">";
print " <TR><TH COLSPAN=\"7\"><A HREF=\"$PHP_SELF?date=$prev\">&lt;&lt;</A> &nbsp; ". date("F Y", $this->date) ." &nbsp; <A HREF=\"$PHP_SELF?date=$next\">&gt;&gt;</A></TH></TR>";
print " <TR><TH>S</TH><TH>M</TH><TH>T</TH><TH>W</TH><TH>T</TH><TH>F</TH><TH>S</TH></TR>\n";
### Initialize temporary variables:
$day = 1;
$weekday = $first;
$state = 1;
### Loop through all the days of the month:
while ($day <= $last) {
### Set up blank days for first week of the month:
if ($state == 1) {
print "<TR><TD COLSPAN=\"$first\">&nbsp</TD>";
$state = 2;
}
### Start every week on a new line:
if ($weekday == 0) print "<TR>";
### Print one cell:
$date = mktime(0, 0, 0, $month, $day, $year);
if ($day == date("d", $this->date)) {
print "<TD ALIGN=\"center\"><B><A HREF=\"$PHP_SELF?date=$date\">$day</A></B></TD>";
}
else {
print "<TD ALIGN=\"center\"><A HREF=\"$PHP_SELF?date=$date\">$day</A></TD>";
}
### Start every week on a new line:
if ($weekday == 6) print "</TR>";
### Update temporary variables:
$weekday++;
$weekday = $weekday % 7;
$day++;
}
### End the calendar:
if ($weekday != 0) {
$end = 7 - $weekday;
print "<TD COLSPAN=\"$end\">&nbsp;</TD></TR>";
}
print "</TABLE>";
}
}
// -----------------------------------------------------------------------
// ---------- TEMPORARY CODE - should be removed after testing -----------
// -----------------------------------------------------------------------
print "<H1>CALENDAR TEST</H1>";
// Code to initialize and display a calendar:
if ($date) $calendar = new calendar($date);
else $calendar = new calendar(time());
$calendar->display();
// Debug output:
print "<P><B>Selected date:</B><BR>". date("l, F d, Y", $date) ."</P>";
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment