summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArto Bendiken2006-11-25 16:42:35 (GMT)
committerArto Bendiken2006-11-25 16:42:35 (GMT)
commitaa14c1ccf9ebe43f63aa11bc567a52c379244df5 (patch)
treea9f30736cb9593878242e6baa1c50382755ee7bb
parentfc1e6cc19f78c33080177b6a3d16484a6e8953f8 (diff)
Added a hook_exit() handler to ensure session messages set on form submission will get shown on the next page despite that page having been cached by Boost.
-rw-r--r--boost.api.inc12
-rw-r--r--boost.module41
2 files changed, 53 insertions, 0 deletions
diff --git a/boost.api.inc b/boost.api.inc
index 2313a24..5fd1925 100644
--- a/boost.api.inc
+++ b/boost.api.inc
@@ -44,6 +44,18 @@ function boost_is_cacheable($path) {
}
/**
+ * Determines whether a given Drupal page is currently cached or not.
+ */
+function boost_is_cached($path) {
+ $path = (empty($path) ? BOOST_FRONTPAGE : $path);
+ $alias = drupal_get_path_alias($path);
+ $path = drupal_get_normal_path($path); // normalize path
+
+ // TODO: also determine if alias/symlink exists?
+ return file_exists(boost_file_path($path));
+}
+
+/**
* Deletes all static files currently in the cache.
*/
function boost_cache_clear_all() {
diff --git a/boost.module b/boost.module
index 0c13cb7..68998ce 100644
--- a/boost.module
+++ b/boost.module
@@ -115,6 +115,47 @@ function boost_init() {
}
/**
+ * Implementation of hook_exit(). Performs cleanup tasks.
+ *
+ * For POST requests by anonymous visitors, this adds a dummy query string
+ * to any URL being redirected to using drupal_goto().
+ *
+ * This is pretty much a hack that assumes a bit too much familiarity with
+ * what happens under the hood of the Drupal core function drupal_goto().
+ *
+ * It's necessary, though, in order for any session messages set on form
+ * submission to actually show up on the next page if that page has been
+ * cached by Boost.
+ */
+function boost_exit($destination = NULL) {
+ // Check that hook_exit() was invoked by drupal_goto() for a POST request:
+ if (!empty($destination) && $_SERVER['REQUEST_METHOD'] == 'POST') {
+
+ // Check that we're dealing with an anonymous visitor. and that some
+ // session messages have actually been set during this page request:
+ global $user;
+ if (empty($user->uid) && ($messages = drupal_set_message())) {
+
+ // Check that the page we're redirecting to has been cached by Boost
+ // and really necessitates special handling:
+ extract(parse_url($destination));
+ $path = ($path == base_path() ? '' : substr($path, strlen(base_path())));
+ if (boost_is_cached($path) && empty($query)) {
+ // FIXME: call any remaining exit hooks since we're about to terminate.
+
+ // Add a query string to ensure we don't serve a static copy of
+ // the page we're redirecting to, which would prevent the session
+ // messages from showing up:
+ $destination = url($path, 't=' . time(), $fragment, TRUE);
+
+ // Do what drupal_goto() would do if we were to return to it:
+ exit(header('Location: ' . $destination));
+ }
+ }
+ }
+}
+
+/**
* Implementation of hook_form_alter(). Performs alterations before a form
* is rendered.
*/