Index: openacs-4/packages/news/tcl/news-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/news/tcl/news-procs.tcl,v diff -u -r1.10 -r1.11 --- openacs-4/packages/news/tcl/news-procs.tcl 30 Sep 2003 12:10:08 -0000 1.10 +++ openacs-4/packages/news/tcl/news-procs.tcl 3 Oct 2003 15:45:38 -0000 1.11 @@ -122,8 +122,69 @@ return $url } +ad_proc news_pretty_status_key { + {-publish_date:required} + {-archive_date:required} +} { + Given the the publish and archive date of a news item, return + a human readable and localized string explaining the publish and archive status + of the item. For example, "Published, scheduled to be archived in 5 days" + @param publish_date The publish date on ANSI format + @param archive_date The archive date on ANSI format + @return The message key (package_key.message_key) for the text. + @author Peter Marklund +} { + set now_seconds [clock scan now] + if { ![empty_string_p $archive_date] } { + set archive_date_seconds [clock scan $archive_date] + if { $archive_date_seconds > $now_seconds } { + # Scheduled for archive + set n_days_until_archive [expr ($archive_date_seconds - $now_seconds) / 86400] + } + } + if { ![empty_string_p $publish_date] } { + # The item has been published or is scheduled to be published + + set publish_date_seconds [clock scan $publish_date] + if { $publish_date_seconds > $now_seconds } { + # Will be published in the future + + set n_days_until_publish [expr ($publish_date_seconds - $now_seconds) / 86400] + + if { [empty_string_p $archive_date] } { + # Not scheduled for archive + # Message with vars n_days_until_publish + set status_key news.going_live_no_archive + } else { + # Scheduled for archive + # Message with vars n_days_until_publish, n_days_until_archive + set status_key news.going_live_with_archive + } + } else { + # Has already been published + + if { [empty_string_p $archive_date] } { + # Not scheduled for archive + set status_key news.published_no_archive + } elseif { $archive_date_seconds > $now_seconds } { + # Scheduled for archive + # Message with vars n_days_until_archive + set status_key news.published_scheduled_for_archive + } else { + # Already archived + set status_key news.Archived + } + } + + } else { + # Item has no publish date - it's unapproved + set status_key news.Unapproved + } + + return $status_key +}