diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c14107c79bef3d52758d2e166a8c51bb8427d927..9e07d8d59514c7589da226dae53ae2c1f5faacee 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,4 +1,6 @@ CHANGELOG for Views 2 for Drupal 6 + Other changes: + o Implement a post_render hook (for themes too) and cache method. Views 2.6 Bugs fixed: diff --git a/docs/docs.php b/docs/docs.php index 8e8bcbd8ee01a4f82381ceef4e09e99778f13d4c..40aed9159d66935822a0dc4a6fd3c0b84a3aa141 100644 --- a/docs/docs.php +++ b/docs/docs.php @@ -574,11 +574,39 @@ function hook_views_pre_execute(&$view) { * * Adding output to the view cam be accomplished by placing text on * $view->attachment_before and $view->attachment_after + * + * This hook can be utilized by themes. */ function hook_views_pre_render(&$view) { // example code here } +/** + * Post process any rendered data. + * + * This can be valuable to be able to cache a view and still have some level of + * dynamic output. In an ideal world, the actual output will include HTML + * comment based tokens, and then the post process can replace those tokens. + * + * Example usage. If it is known that the view is a node view and that the + * primary field will be a nid, you can do something like this: + * + * + * + * And then in the post render, create an array with the text that should + * go there: + * + * strtr($output, array('', 'output for FIELD of nid 1'); + * + * All of the cached result data will be available in $view->result, as well, + * so all ids used in the query should be discoverable. + * + * This hook can be utilized by themes. + */ +function hook_views_post_render(&$view, &$output, &$cache) { + +} + /** * Stub hook documentation * diff --git a/includes/view.inc b/includes/view.inc index eb2ed659fffdcd074ca36e2da29290dd55d1ae51..bdbf7b760fd77cec4a35288f5cfa0280c0ebdd31 100644 --- a/includes/view.inc +++ b/includes/view.inc @@ -818,6 +818,12 @@ class view extends views_db_object { $function($this); } + // Let the theme play too, because pre render is a very themey thing. + $function = $GLOBALS['theme']) . '_views_pre_render'; + if (function_exists($function) { + $function($this, $this->display_handler->output, $cache); + } + // Give field handlers the opportunity to perform additional queries // using the entire resultset prior to rendering. if ($this->style_plugin->uses_fields()) { @@ -833,6 +839,20 @@ class view extends views_db_object { } } + $cache->post_render($this, $this->display_handler->output); + + // Let modules modify the view output after it is rendered. + foreach (module_implements('views_post_render') as $module) { + $function = $module . '_views_post_render'; + $function($this, $this->display_handler->output, $cache); + } + + // Let the theme play too, because post render is a very themey thing. + $function = $GLOBALS['theme']) . '_views_post_render'; + if (function_exists($function) { + $function($this, $this->display_handler->output, $cache); + } + if (!empty($this->live_preview) && variable_get('views_show_additional_queries', FALSE)) { $this->end_query_capture(); } diff --git a/plugins/views_plugin_cache.inc b/plugins/views_plugin_cache.inc index 20706e34c43a99bef64e8b9e1371105e8b84b832..ce353119d8cd4ffc3f4c3078260bf4753c5024e9 100644 --- a/plugins/views_plugin_cache.inc +++ b/plugins/views_plugin_cache.inc @@ -134,6 +134,28 @@ class views_plugin_cache extends views_plugin { cache_clear_all($this->view->name . ':', $this->table, TRUE); } + /** + * Post process any rendered data. + * + * This can be valuable to be able to cache a view and still have some level of + * dynamic output. In an ideal world, the actual output will include HTML + * comment based tokens, and then the post process can replace those tokens. + * + * Example usage. If it is known that the view is a node view and that the + * primary field will be a nid, you can do something like this: + * + * + * + * And then in the post render, create an array with the text that should + * go there: + * + * strtr($output, array('', 'output for FIELD of nid 1'); + * + * All of the cached result data will be available in $view->result, as well, + * so all ids used in the query should be discoverable. + */ + function post_render(&$view, &$output) { } + /** * Start caching javascript, css and other out of band info. *