View source
<?php
function robotstxt_help($path, $arg) {
switch ($path) {
case 'admin/help#robotstxt':
return '<p>' . t('In a multisite environment, there is no mechanism for having a separate robots.txt file for each site. This module addresses that need by letting you administer the robots.txt file from the settings interface.') . '</p>';
break;
case 'admin/settings/robotstxt':
if (file_exists('./robots.txt')) {
drupal_set_message(t('One or more problems have been detected with the RobotsTxt configuration. Check the <a href="@status">status report</a> for more information.', array(
'@status' => url('admin/reports/status'),
)), 'warning');
}
return t('See <a href="http://www.robotstxt.org/">http://www.robotstxt.org/</a> for more information concerning how to write your <a href="@robotstxt">robots.txt</a> file.', array(
'@robotstxt' => base_path() . 'robots.txt',
));
break;
}
}
function robotstxt_perm() {
return array(
'administer robots.txt',
);
}
function robotstxt_menu() {
$items['robots.txt'] = array(
'page callback' => 'robotstxt_robots',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['admin/settings/robotstxt'] = array(
'title' => 'RobotsTxt',
'description' => 'Manage your robots.txt file.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'robotstxt_admin_settings',
),
'access arguments' => array(
'administer robots.txt',
),
'file' => 'robotstxt.admin.inc',
);
return $items;
}
function robotstxt_robots() {
$content = array();
$content[] = _robotstxt_get_content();
if ($additions = module_invoke_all('robotstxt')) {
$content = array_merge($content, $additions);
}
$content = array_map('trim', $content);
$content = array_filter($content);
drupal_set_header('Content-type: text/plain');
echo implode("\n", $content);
drupal_page_footer();
exit;
}
function _robotstxt_get_content() {
$content = variable_get('robotstxt', FALSE);
if ($content === FALSE) {
$files = array(
'./robots.txt',
drupal_get_path('module', 'robotstxt') . '/robots.txt',
);
foreach ($files as $file) {
if (file_exists($file) && is_readable($file)) {
$content = file_get_contents($file);
break;
}
}
}
return $content;
}