robotstxt.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, Inc.
  5. *
  6. * robots.txt generator
  7. *
  8. * PHP version 5
  9. *
  10. * @category Action
  11. * @package StatusNet
  12. * @author Evan Prodromou <evan@status.net>
  13. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  14. * @link http://status.net/
  15. *
  16. * This program is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License as published by
  18. * the Free Software Foundation, either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. */
  29. if (!defined('STATUSNET')) {
  30. exit(1);
  31. }
  32. /**
  33. * Prints out a static robots.txt
  34. *
  35. * @category Action
  36. * @package StatusNet
  37. * @author Evan Prodromou <evan@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  39. * @link http://status.net/
  40. */
  41. class RobotstxtAction extends Action
  42. {
  43. /**
  44. * Handles requests
  45. *
  46. * Since this is a relatively static document, we
  47. * don't do a prepare()
  48. *
  49. * @param array $args GET, POST, and URL params; unused.
  50. *
  51. * @return void
  52. */
  53. function handle($args)
  54. {
  55. if (Event::handle('StartRobotsTxt', array($this))) {
  56. header('Content-Type: text/plain');
  57. print "User-Agent: *\n";
  58. if (common_config('site', 'private')) {
  59. print "Disallow: /\n";
  60. } else {
  61. $disallow = common_config('robotstxt', 'disallow');
  62. foreach ($disallow as $dir) {
  63. print "Disallow: /$dir/\n";
  64. }
  65. $crawldelay = common_config('robotstxt', 'crawldelay');
  66. if (!empty($crawldelay)) {
  67. print "Crawl-delay: " . $crawldelay . "\n";
  68. }
  69. }
  70. Event::handle('EndRobotsTxt', array($this));
  71. }
  72. }
  73. /**
  74. * Return true; this page doesn't touch the DB.
  75. *
  76. * @param array $args other arguments
  77. *
  78. * @return boolean is read only action?
  79. */
  80. function isReadOnly($args)
  81. {
  82. return true;
  83. }
  84. }