aboutsummaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/lib/elgglib.php64
-rw-r--r--engine/start.php3
2 files changed, 63 insertions, 4 deletions
diff --git a/engine/lib/elgglib.php b/engine/lib/elgglib.php
index e21e30e25..40a248d8f 100644
--- a/engine/lib/elgglib.php
+++ b/engine/lib/elgglib.php
@@ -397,6 +397,59 @@
return false;
+ }
+
+ /**
+ * Registers a view to be simply cached
+ *
+ * Views cached in this manner must take no parameters and be login agnostic -
+ * that is to say, they look the same no matter who is logged in (or logged out).
+ *
+ * CSS and the basic jS views are automatically cached like this.
+ *
+ * @param string $viewname View name
+ */
+ function elgg_view_register_simplecache($viewname) {
+
+ global $CONFIG;
+
+ if (!isset($CONFIG->views->simplecache))
+ $CONFIG->views->simplecache = array();
+
+ //if (elgg_view_exists($viewname))
+ $CONFIG->views->simplecache[] = $viewname;
+
+ }
+
+ /**
+ * Regenerates the simple cache.
+ *
+ * @see elgg_view_register_simplecache
+ *
+ */
+ function elgg_view_regenerate_simplecache() {
+
+ global $CONFIG;
+
+ if (isset($CONFIG->views->simplecache)) {
+
+ if (!file_exists($CONFIG->dataroot . 'views_simplecache')) {
+ @mkdir($CONFIG->dataroot . 'views_simplecache');
+ }
+
+ if (!empty($CONFIG->views->simplecache) && is_array($CONFIG->views->simplecache)) {
+ foreach($CONFIG->views->simplecache as $view) {
+ $viewcontents = elgg_view($view);
+ $viewname = md5($view);
+ if ($handle = fopen($CONFIG->dataroot . 'views_simplecache/' . $viewname, 'w')) {
+ fwrite($handle, $viewcontents);
+ fclose($handle);
+ }
+ }
+ }
+
+ }
+
}
/**
@@ -2106,14 +2159,19 @@
register_page_handler('js','js_page_handler');
extend_view('js/initialise_elgg','embed/js');
// Register an event triggered at system shutdown
- register_shutdown_function('__elgg_shutdown_hook');
+ register_shutdown_function('__elgg_shutdown_hook');
+
}
function elgg_boot() {
// Actions
register_action('comments/add');
- register_action('comments/delete');
+ register_action('comments/delete');
+
+ elgg_view_register_simplecache('css');
+ elgg_view_register_simplecache('js/friendsPickerv1');
+ elgg_view_register_simplecache('js/initialise_elgg');
}
/**
@@ -2124,6 +2182,6 @@
define('ACCESS_PUBLIC',2);
register_elgg_event_handler('init','system','elgg_init');
- register_elgg_event_handler('boot','system','elgg_boot');
+ register_elgg_event_handler('boot','system','elgg_boot',1000);
?> \ No newline at end of file
diff --git a/engine/start.php b/engine/start.php
index 568cea905..d1484cafd 100644
--- a/engine/start.php
+++ b/engine/start.php
@@ -185,8 +185,9 @@
//forward("setup.php");
//}
}
-
// System booted, return to normal view
set_input('view', $oldview);
+
+ run_function_once('elgg_view_regenerate_simplecache',time() - (86400 * 7));
?> \ No newline at end of file