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
<?php
// $Id: robotstxt.install,v 1.13.2.2 2011/01/05 23:24:10 hass Exp $
/**
* Implements hook_install().
*/
function robotstxt_install() {
if (file_exists(DRUPAL_ROOT . '/robots.txt')) {
variable_set('robotstxt', file_get_contents(DRUPAL_ROOT . '/robots.txt'));
}
elseif (file_exists(drupal_get_path('module', 'robotstxt') . '/robots.txt')) {
variable_set('robotstxt', file_get_contents(drupal_get_path('module', 'robotstxt') . '/robots.txt'));
}
}
/**
* Implements hook_uninstall().
*/
function robotstxt_uninstall() {
variable_del('robotstxt');
}
/**
* Implements hook_requirements().
*/
function robotstxt_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
case 'runtime' :
// Module cannot work without Clean URLs.
if (!variable_get('clean_url', 0)) {
$requirements['robotstxt_cleanurl'] = array(
'title' => $t('RobotsTxt'),
'severity' => REQUIREMENT_ERROR,
'value' => $t('<a href="!clean_url">Clean URLs</a> are mandatory for this module.', array('!clean_url' => url('admin/config/search/clean-urls'))),
);
}
// Webservers prefer the robots.txt file on disk and does not allow menu path overwrite.
if (file_exists(DRUPAL_ROOT . '/robots.txt')) {
$requirements['robotstxt_file'] = array(
'title' => $t('RobotsTxt'),
'severity' => REQUIREMENT_WARNING,
'value' => $t('RobotsTxt module works only if you remove the existing robots.txt file in your website root.'),
);
}
}
return $requirements;
}
/**
* Automatically add the 'administer robots.txt' permission to granted users.
*/
function robotstxt_update_6100() {
$roles = user_roles(FALSE, 'administer site configuration');
foreach ($roles as $rid => $role) {
_update_7000_user_role_grant_permissions($rid, array('administer robots.txt'), 'robotstxt');
}
return t("Added 'administer robots.txt' permission to all roles with 'administer site configuration' permission.");
}
/**
* #337820: Rename menu path 'logout' to 'user/logout' for consistency.
*/
function robotstxt_update_7000() {
$robotstxt = variable_get('robotstxt');
$robotstxt = str_replace('Disallow: /logout/', 'Disallow: /user/logout/', $robotstxt);
$robotstxt = str_replace('Disallow: /?q=logout/', 'Disallow: /?q=user/logout/', $robotstxt);
variable_set('robotstxt', $robotstxt);
return t("Renamed menu path 'logout' to 'user/logout'.");
}
/**
* #494462: Allow crawling of sites/default/files by search engines, don't disallow it in robots.txt.
*/
function robotstxt_update_7100() {
$robotstxt = variable_get('robotstxt');
$robotstxt = preg_replace("/Disallow:\s\/sites\/(\r\n?|\n)/", '', $robotstxt);
variable_set('robotstxt', $robotstxt);
return t("Allowed crawling of sites/default/files by search engines.");
}