You are here

function boost_update_robots_txt in Boost 6

Helper function to update robots.txt Inserts or removes the line 'Disallow: /boost_stats.php'

@TODO Make this work with subdirectory installs

Parameters

$enable: Whether to patch robots.txt to work with boost.

Return value

TRUE or nonzero on success, FALSE if error

2 calls to boost_update_robots_txt()
boost_admin_htaccess_page_submit in ./boost.admin.inc
Submit handler for boost_admin_htaccess_page
boost_uninstall in ./boost.install
Implementation of hook_uninstall().

File

./boost.admin.inc, line 1456
All the code for the Boost module's administrative interface.

Code

function boost_update_robots_txt($enable, $verbose = TRUE) {
  $payload = 'Disallow: /boost_stats.php';
  $filename = 'robots.txt';
  $result = TRUE;
  $text = file_get_contents($filename);
  if ($text) {
    if ($enable && !stristr($text, $payload)) {

      // Boost enabled: Insert payload into file
      $result = file_put_contents($filename, $text . "\n" . $payload . "\n");
      if ($verbose) {
        drupal_set_message($result ? t('robots.txt patched for usage with boost') : t('Unable to write to robots.txt'));
      }
    }
    elseif (!$enable && stristr($text, $payload)) {

      // Boost disabled: Remove payload from file
      $text = preg_replace('|^[^D]*Disallow:[ ]*/boost_stats.php[^\\n]*[\\n]|im', "", $text);
      $result = file_put_contents($filename, $text);
      if ($verbose) {
        drupal_set_message($result ? t('robots.txt unpatched because boost is disabled') : t('Unable to write to robots.txt'));
      }
    }
  }
  return $result;
}