You are here

function _boost_view_insert in Boost 6

Shutdown function, gets called at the very end of node creation.

Node is now created, thus views has access to the new node. Searches all cached views for newly created node. Expires the outdated views from the cache.

1 string reference to '_boost_view_insert'
boost_nodeapi in ./boost.module
Implementation of hook_nodeapi(). Acts on nodes defined by other modules.

File

./boost.module, line 1331
Provides static file caching for Drupal text output. Pages, Feeds, ect...

Code

function _boost_view_insert() {
  global $_boost, $base_url, $base_path;
  static $processed = FALSE;

  // Only run once
  if ($processed) {
    return;
  }

  // Exit if no new nodes
  if (empty($_boost['new_nodes'])) {
    return FALSE;
  }

  // Make sure node is numeric
  foreach ($_boost['new_nodes'] as $key => $value) {
    if (!is_numeric($value) || !is_numeric($key)) {
      unset($_boost['new_nodes'][$key]);
    }
  }
  if (empty($_boost['new_nodes'])) {
    return;
  }

  // Prep for async
  // URL key.
  $key = variable_get('boost_crawler_key', FALSE);
  if ($key == FALSE) {
    variable_set('boost_crawler_key', mt_rand());
    $key = variable_get('boost_crawler_key', FALSE);
  }

  // Query string.
  $query = array(
    'new_nodes' => $_boost['new_nodes'],
    'rand' => mt_rand(),
    'key' => $key,
  );
  $query_string = str_replace('&', '&', urldecode(http_build_query($query)));

  // Setup request URL and headers.
  $ip = variable_get('boost_server_addr', FALSE);
  if (empty($ip)) {
    $ip = $_SERVER['SERVER_ADDR'];
  }

  // Check for IPv6 addresses, must be un square brackets
  // http://www.sixxs.net/wiki/Detecting_IPv6_In_a_Web_Page
  if (substr_count($ip, ":") > 0 && substr_count($ip, ".") == 0) {
    $ip = "[" . $ip . "]";
  }
  $url = 'http://' . $ip . $base_path . 'boost_views.php?' . $query_string;
  $headers['Host'] = $_SERVER['HTTP_HOST'];

  // Send nodes to async processor
  $socket_timeout = ini_set('default_socket_timeout', 2);
  $results = drupal_http_request($url, $headers);
  ini_set('default_socket_timeout', $socket_timeout);

  // Check response.
  $key_back = trim($results->data);

  //   $key_back = (int)$key_back;
  // If async failed; block here and generate images and caches.
  if ($key_back != $key) {
    watchdog('boost', 'Asynchronous views failed. Using Synchronous mode.');
    _boost_views_runit();
  }

  // We have processed nodes
  $processed = TRUE;
  return;
}