Posted by sillygwailo on December 20, 2008 at 12:05am
| Project: | On This Day |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | sillygwailo |
| Status: | active |
Issue Summary
So if a person visits a node dated January 27th, 2008, it shows nodes from January 27th, 2007 + January 27th, 2006, etc. Could be a Views argument when/if Views integration happens.
(Feature request from domesticat.)
Comments
#1
This is a quick and ugly hack, but it does seem to work. Here's how I revised _onthisday_list() --
<?php
function _onthisday_list($offset, $month = NULL, $day = NULL) {
global $base_url;
// Regardless of the year of publication, start calculating
// the date using the current year.
$year = date('Y');
// Do we have a node object?
if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
// If so, load it.
$node = node_load(arg(1));
// Set month and day based on the node creation date.
$month = date('n', $node->created);
$day = date('j', $node->created);
}
// Otherwise, we don't have a node object
// (Why would this be the case? A view? I do not know.)
else {
// If $month is not provided, set $month and $day to the present day.
// QUESTION: What happens if $month is set but $day is null?
if (empty($month)) {
$month = date('n');
$day = date('j');
}
}
while ($offset > 0) {
$year_ago = mktime(0, 0, 0, $month, $day, $year - $offset);
$year_ago_plus = $year_ago + 86400;
$result = db_query("SELECT nid, title FROM {node} WHERE status = 1 AND created > %d AND created < %d ORDER BY created ASC;", $year_ago, $year_ago_plus);
while ($node = db_fetch_object($result)) {
$items[$year-$offset][] = $node->nid;
}
$offset--;
}
return $items;
}
?>
I'm sure there's probably a neater way to do it. But if not, hey, at least it works. Next I'll likely start wondering if it's worth it to tailor the block's title depending on whether it's generating lists of content for the current date ("Also posted on this day") or on an arbitrary date ("Also posted on %daynumber %monthname")
#2
Turning this into a patch.
#3
I think I see something in the date calculations that I missed last night. I was confused when I looked at my On This Day block this evening and realized there were entries missing that I knew I'd written on Christmas Eve in years past. It hit me a few minutes ago: node creation timestamps are GMT, aren't they? That'd mean these calculations are looking for entries written from 00:01 GMT to 23:59 GMT. I'm six hours off from that. No wonder I'm missing entries.
Timezones are annoying sometimes.
#4
In the code for 6.x dev branch, I've committed this feature, i.e. the second block for "on the day of this node's creation". So after a bit of testing, this should make it into 6.x-1.1.
Addressing domesticat's last comment, I think changing the date() calls to format_date() will fix that part. I committed to the 7.x branch replacing all date() calls with format_date() and will backport if testing reveals that it works better that way.