Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
// $Id: robotstxt.module,v 1.9.2.2 2011/01/05 23:24:10 hass Exp $
/**
* Implements hook_help().
*/
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/config/search/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;
}
}
/**
* Implements hook_permission().
*/
function robotstxt_permission() {
return array(
'administer robots.txt' => array(
'title' => t('Administer robots.txt'),
'description' => t('Perform maintenance tasks for robots.txt.'),
),
);
}
/**
* Implements hook_menu().
*/
function robotstxt_menu() {
$items['robots.txt'] = array(
'page callback' => 'robotstxt_robots',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
$items['admin/config/search/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;
}
/**
* Show the robots.txt file.
*/
function robotstxt_robots() {
$content = array();
$content[] = _robotstxt_get_content();
// Hook other modules for adding additional lines.
if ($additions = module_invoke_all('robotstxt')) {
$content = array_merge($content, $additions);
}
// Trim any extra whitespace and filter out empty strings.
$content = array_map('trim', $content);
$content = array_filter($content);
drupal_add_http_header('Content-type', 'text/plain');
echo implode("\n", $content);
exit;
}
/**
* Retrieve contents of robots.txt from the database variable, site root, or
* module directory.
*/
function _robotstxt_get_content() {
$content = variable_get('robotstxt', FALSE);
if ($content === FALSE) {
$files = array(
DRUPAL_ROOT . '/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;
}