? ; Index: gsitemap.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/gsitemap/gsitemap.module,v retrieving revision 1.38.2.20 diff -u -F^f -r1.38.2.20 gsitemap.module --- gsitemap.module 22 Nov 2006 22:52:16 -0000 1.38.2.20 +++ gsitemap.module 26 Dec 2006 23:21:59 -0000 @@ -86,7 +86,7 @@ function gsitemap_nodeapi(&$node, $op, $ } db_query("INSERT INTO {gsitemap} (nid, last_changed, priority_override) VALUES(%d, %d, %s)", $node->nid, $node->changed, $node->priority_override); if(variable_get('gsitemap_submit',0) && $node->status) { - _gsitemap_submit(); + _gsitemap_submit_on_exit(); } break; case 'load': @@ -117,13 +117,13 @@ function gsitemap_nodeapi(&$node, $op, $ } } if(variable_get('gsitemap_submit',0) && ($node->status || $oldnode->status)) { - _gsitemap_submit(); + _gsitemap_submit_on_exit(); } break; case 'delete': db_query("DELETE FROM {gsitemap} WHERE nid=%d", $node->nid); if(variable_get('gsitemap_submit',0) && $node->status) { - _gsitemap_submit(); + _gsitemap_submit_on_exit(); } break; case 'validate': @@ -154,7 +154,7 @@ function gsitemap_comment($op, $comment) db_query("UPDATE {gsitemap} SET last_comment=%d, previous_comment=%d WHERE nid=%d", $comment[timestamp], $node->last_comment, $node->nid); } if(variable_get('gsitemap_submit',0)) { - _gsitemap_submit(); + _gsitemap_submit_on_exit(); } } } @@ -172,7 +172,7 @@ function gsitemap_comment($op, $comment) db_query("UPDATE {gsitemap} SET last_comment=%d, previous_comment=%d WHERE nid=%d", $comment->timestamp, $node->last_comment, $node->nid); } if(variable_get('gsitemap_submit',0)) { - _gsitemap_submit(); + _gsitemap_submit_on_exit(); } } } @@ -461,6 +461,33 @@ function _gsitemap_calc_priority($node,$ } return $pri; } + +/** + * Schedule a call to _gsitemap_submit() to be run on exit. Use this function + * instead of _gsitemap_submit() to avoid a delay for outputting the page to + * the user. + * + * @return If the function has not been called previously, FALSE. Otherwise, + * TRUE. + */ +function _gsitemap_submit_on_exit() { + static $called = FALSE; + + $return = $called; + $called = TRUE; + return $return; +} + +/** + * Implementation of hook_exit() which is used to call _gsitemap_submit() if + * _gsitemap_submit_on_exit() was called. + */ +function gsitemap_exit() { + if (_gsitemap_submit_on_exit()) { + _gsitemap_submit(); + } +} + function _gsitemap_submit() { $result = drupal_http_request('http://www.google.com/webmasters/tools/ping?sitemap=' . url('gsitemap', NULL, NULL, TRUE)); if($result->code == 200) {