Skip to content

Commit

Permalink
Allow date.php to honor a branch=2017Q3 type arrangement.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlangille committed Sep 8, 2017
1 parent 5ca42e4 commit 7df5415
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
3 changes: 3 additions & 0 deletions include/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@

define('PORT_STATUS_ACTIVE', 'A');
define('PORT_STATUS_DELETED', 'D');

# used mainly when calling freshports_LinkToDate as a sensible parameter
define('DATE_FORMAT_D_LONG_MONTH', '');
8 changes: 6 additions & 2 deletions include/freshports.php
Original file line number Diff line number Diff line change
Expand Up @@ -1867,8 +1867,12 @@ function freshports_SideBar() {

}

function freshports_LinkToDate($Date, $Text = '') {
$URL = '<a href="/date.php?date=' . date("Y/n/j", $Date) . '">';
function freshports_LinkToDate($Date, $Text = '', $BranchName = BRANCH_HEAD) {
$URL = '<a href="/date.php?date=' . date("Y/n/j", $Date);
if ($BranchName != BRANCH_HEAD) {
$URL .= '&amp;branch=' . htmlspecialchars($BranchName);
}
$URL .= '">';
if ($Text != '') {
$URL .= $Text;
} else {
Expand Down
35 changes: 15 additions & 20 deletions www/date.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
'FreeBSD, index, applications, ports');
$Debug = 0;

function ArchiveFileName($Date) {
$File = ARCHIVE_DIRECTORY . '/' . $Date . '.daily';
function ArchiveFileName($Date, $BranchName = BRANCH_HEAD) {
$File = ARCHIVE_DIRECTORY . '/' . $Date . '.daily.' . $BranchName;

return $File;
}
Expand All @@ -73,23 +73,23 @@ function ArchiveDirectoryCreate($Date) {
return $DirToCreate;
}

function ArchiveExists($Date) {
function ArchiveExists($Date, $BranchName = BRANCH_HEAD) {
# returns file name for archive if it exists
# empty string otherwise

$File = ArchiveFileName($Date);
$File = ArchiveFileName($Date, $BranchName);
if (!file_exists($File)) {
$File = '';
}

return $File;
}

function ArchiveSave($Date, $HTML) {
function ArchiveSave($Date, $HTML, $BranchName = BRANCH_HEAD) {
# saves the archive away...

ArchiveDirectoryCreate($Date);
$File = ArchiveFileName($Date);
$File = ArchiveFileName($Date, $BranchName);

$myfile = fopen($File, 'w');
fwrite($myfile, $HTML);
Expand All @@ -100,10 +100,10 @@ function ArchiveSave($Date, $HTML) {

}

function ArchiveGet($Date) {
function ArchiveGet($Date, $BranchName = BRANCH_HEAD) {
# saves the archive away...

$File = ArchiveFileName($Date);
$File = ArchiveFileName($Date, $BranchName);

$myfile = fopen($File, 'r');
$HTML = fread($myfile, filesize($File));
Expand Down Expand Up @@ -161,16 +161,11 @@ function ArchiveCreate($Date, $DateMessage, $db, $Use, $BranchName) {
$dateAfter = new DateTime($Date);
$dateAfter->sub(new DateInterval('P1D'));

$Yesterday = freshports_LinkToDate(strtotime($dateBefore->format('Y-m-d')));
$Tomorrow = freshports_LinkToDate(strtotime($dateAfter->format('Y-m-d')));
# DATE_FORMAT_D_LONG_MONTH is an empty string, and freshports_LinkToDate will format a date for me
$Yesterday = freshports_LinkToDate(strtotime($dateBefore->format('Y-m-d')), DATE_FORMAT_D_LONG_MONTH, $BranchName);
$Tomorrow = freshports_LinkToDate(strtotime($dateAfter->format('Y-m-d')), DATE_FORMAT_D_LONG_MONTH, $BranchName);

# This *seems* to cater for looking at yesterday's commits.
# I think maybe we should not try to be so clever.
if (strtotime($Date) + RELATIVE_DATE_24HOURS == strtotime(date('Y/m/d'))) {
$DateLinks = '&lt; ' . $Today . ' | ' . $Yesterday . ' &gt;';
} else {
$DateLinks = '&lt; ' . $Today . ' | ' . $Tomorrow . ' | ' . $Yesterday . ' &gt;';
}
$DateLinks = '&lt; ' . $Today . ' | ' . $Tomorrow . ' | ' . $Yesterday . ' &gt;';
echo $DateLinks;
if ($NumCommits > 0) {
echo " | Number of commits: " . $NumCommits;
Expand All @@ -185,11 +180,11 @@ function ArchiveCreate($Date, $DateMessage, $db, $Use, $BranchName) {

echo freshports_MainContentTable();

if (ArchiveExists($Date)) {
$HTML = ArchiveGet($Date);
if (ArchiveExists($Date, $BranchName)) {
$HTML = ArchiveGet($Date, $BranchName);
} else {
$HTML = ArchiveCreate($Date, $DateMessage, $db, $User, $BranchName);
ArchiveSave($Date, $HTML);
ArchiveSave($Date, $HTML, $BranchName);
}

echo $HTML;
Expand Down

0 comments on commit 7df5415

Please sign in to comment.