Commit 51d20390 authored by Mark Jordan's avatar Mark Jordan
Browse files

Added wording about when the redirect will expire.

parent 7fcc6ffd
Pipeline #55 skipped
......@@ -193,6 +193,21 @@ function write_to_log($incoming_url, $destination_url = '') {
file_put_contents($log_file_path, $incoming_url . "\t" . $destination_url . "\n", FILE_APPEND);
}
/**
* Gets the number of days until a specific date.
*
* @param string $target_date
* The date we are counting down until, in yyyy-mm-dd format.
* @return string
* The number of days until the specified date.
*/
function get_days_until($target_date = '2017-05-31') {
$datetime1 = new DateTime('now');
$datetime2 = new DateTime($target_date);
$num_days = $datetime1->diff($datetime2);
return $num_days->days;
}
/**
* Slim application.
*/
......@@ -203,8 +218,9 @@ $app = new \Slim\Slim();
* Custom 404 response.
*/
$app->notFound(function () use ($app) {
$days_left = get_days_until();
$incoming_url = $app->request->getUrl() . $app->request->getPath();
$app->render('not_found.php', array('incoming_url' => $incoming_url));
$app->render('not_found.php', array('days_left' => $days_left, 'incoming_url' => $incoming_url));
});
/**
......@@ -213,7 +229,8 @@ $app->notFound(function () use ($app) {
*/
$app->get('/',
function () use ($app) {
$app->render('home.php', array(), 200);
$days_left = get_days_until();
$app->render('home.php', array('days_left' => $days_left), 200);
});
/**
......@@ -243,13 +260,14 @@ $app->get('/cdm/:type/collection/:alias/id/:pointer(/:rec(/:page))',
function ($type, $alias, $pointer, $rec = null, $page = null) use ($app) {
// Assemble the incoming URL.
$incoming_url = $app->request->getUrl() . $app->request->getPath();
$days_left = get_days_until();
if ($destination_url = lookup_url($alias, $pointer)) {
write_to_log($incoming_url, $destination_url);
$app->render('redirect.php', array('incoming_url' => $incoming_url, 'destination_url' => $destination_url), 301);
$app->render('redirect.php', array('days_left' => $days_left, 'incoming_url' => $incoming_url, 'destination_url' => $destination_url), 301);
}
else {
write_to_log("ERROR", "No Islandora URL found for Solr query $incoming_url");
$app->render('not_found.php', array('incoming_url' => $incoming_url), 404);
$app->render('not_found.php', array('days_left' => $days_left, 'incoming_url' => $incoming_url), 404);
}
});
......@@ -266,13 +284,14 @@ $app->get('/cdm/:type/collection/:alias/id/:pointer(/:rec(/:page))',
$app->get('/cdm/landingpage/collection/:alias',
function ($alias) use ($app) {
$incoming_url = $app->request->getUrl() . $app->request->getPath();
$days_left = get_days_until();
if ($destination_url = get_mapped_url($alias)) {
write_to_log($incoming_url, $destination_url);
$app->render('redirect.php', array('incoming_url' => $incoming_url, 'destination_url' => $destination_url), 301);
$app->render('redirect.php', array('days_left' => $days_left, 'incoming_url' => $incoming_url, 'destination_url' => $destination_url), 301);
}
else {
write_to_log("ERROR", "No Islandora URL found for Solr query $incoming_url");
$app->render('not_found.php', array('incoming_url' => $incoming_url), 404);
$app->render('not_found.php', array('days_left' => $days_left, 'incoming_url' => $incoming_url), 404);
}
});
......@@ -286,14 +305,15 @@ $app->get('/cdm4/browse.php',
$params = $app->request->params();
$alias = $params['CISOROOT'];
$alias = ltrim($alias, '/');
$days_left = get_days_until();
$incoming_url = $app->request->getUrl() . $app->request->getPath() . '?CISOROOT=/' . $alias;
if ($destination_url = get_mapped_url($alias)) {
write_to_log($incoming_url, $destination_url);
$app->render('redirect.php', array('incoming_url' => $incoming_url, 'destination_url' => $destination_url), 301);
$app->render('redirect.php', array('days_left' => $days_left, 'incoming_url' => $incoming_url, 'destination_url' => $destination_url), 301);
}
else {
write_to_log("ERROR", "No Islandora URL found for Solr query $incoming_url");
$app->render('not_found.php', array('incoming_url' => $incoming_url), 404);
$app->render('not_found.php', array('days_left' => $days_left, 'incoming_url' => $incoming_url), 404);
}
});
......@@ -310,14 +330,15 @@ $app->get('/u',
$path = ltrim($alias_pointer_combo[0], '/');
list($alias, $pointer) = explode(',', $path);
$days_left = get_days_until();
$incoming_url = $app->request->getUrl() . $app->request->getPath() . '?/' . $alias . ',' . $pointer;
if ($destination_url = lookup_url($alias, $pointer)) {
write_to_log($incoming_url, $destination_url);
$app->render('redirect.php', array('incoming_url' => $incoming_url, 'destination_url' => $destination_url), 301);
$app->render('redirect.php', array('days_left' => $days_left, 'incoming_url' => $incoming_url, 'destination_url' => $destination_url), 301);
}
else {
write_to_log("ERROR", "No Islandora URL found for Solr query $incoming_url");
$app->render('not_found.php', array('incoming_url' => $incoming_url), 404);
$app->render('not_found.php', array('days_left' => $days_left, 'incoming_url' => $incoming_url), 404);
}
});
......
......@@ -13,7 +13,7 @@
</head>
<body>
<h2>Please note</h2>
SFU Library's digitized collections have moved to <a href="http://digital.lib.sfu.ca">http://digital.lib.sfu.ca</a>.
SFU Library's digitized collections have moved to <a href="http://digital.lib.sfu.ca">http://digital.lib.sfu.ca</a>. <p>This redirect will be in place until May 31, 2017 (<?php echo $days_left; ?> days from now), but please update your links as soon as possible.</p>
</body>
</html>
......@@ -13,7 +13,7 @@
</head>
<body>
<h2>We're sorry, we have moved some things around.</h2>
The page with the URL <div><?php echo $incoming_url; ?></div>is not available at that address any more. You may want to try finding what you're looking for on our new site, <a href="http://digital.lib.sfu.ca">http://digital.lib.sfu.ca</a>.
The page with the URL <div><?php echo $incoming_url; ?></div>is not available at that address any more. You may want to try finding what you're looking for on our new site, <a href="http://digital.lib.sfu.ca">http://digital.lib.sfu.ca</a>. <p>This redirect will be in place until May 31, 2017 (<?php echo $days_left; ?> days from now), but please update your links as soon as possible.</p>
</body>
</html>
......@@ -13,7 +13,7 @@
</head>
<body>
<h2>Please note</h2>
The item that used to be at <div><?php echo $incoming_url; ?></div>has moved to <div><a href="<?php echo $destination_url; ?>"><?php echo $destination_url; ?></a></div>If you've bookmarked the old URL or linked to it from somewhere, please replace it with the new one.
The item that used to be at <div><?php echo $incoming_url; ?></div>has moved to <div><a href="<?php echo $destination_url; ?>"><?php echo $destination_url; ?></a></div>If you've bookmarked the old URL or linked to it from somewhere, please replace it with the new one. <p>This redirect will be in place until May 31, 2017 (<?php echo $days_left; ?> days from now), but please update your links as soon as possible.</p>
</body>
</html>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment