koblog/bl-plugins/robots/plugin.php

66 lines
1.5 KiB
PHP
Raw Normal View History

<?php
class pluginRobots extends Plugin {
2021-09-25 20:28:17 +02:00
public function init() {
2018-09-16 19:26:23 +02:00
$this->dbFields = array(
'robotstxt'=>'User-agent: *'.PHP_EOL.'Allow: /'
);
}
2021-09-25 20:28:17 +02:00
public function form() {
global $L;
2018-09-16 19:26:23 +02:00
2021-09-25 20:28:17 +02:00
$html = '<div class="mb-3">';
$html .= '<label class="form-label" for="robotstxt">'.$L->get('Configure robots.txt file').'</label>';
$html .= '<textarea class="form-control" rows="3" name="robotstxt" id="robotstxt">'.$this->getValue('robotstxt').'</textarea>';
$html .= '<div class="form-text">'.$L->get('This plugin generates the file').' '.DOMAIN_BASE.'/robots.txt</div>';
$html .= '</div>';
2018-09-16 19:26:23 +02:00
return $html;
}
2021-09-25 20:28:17 +02:00
public function siteHead() {
global $WHERE_AM_I;
$html = PHP_EOL.'<!-- Robots plugin -->'.PHP_EOL;
if ($WHERE_AM_I=='page') {
2018-09-16 19:26:23 +02:00
global $page;
$robots = array();
if ($page->noindex()) {
$robots['noindex'] = 'noindex';
}
if ($page->nofollow()) {
$robots['nofollow'] = 'nofollow';
}
if ($page->noarchive()) {
$robots['noarchive'] = 'noarchive';
}
if (!empty($robots)) {
$robots = implode(',', $robots);
$html .= '<meta name="robots" content="'.$robots.'">'.PHP_EOL;
}
}
return $html;
}
2021-09-25 20:28:17 +02:00
public function beforeAll() {
2018-09-16 19:26:23 +02:00
$webhook = 'robots.txt';
if ($this->webhook($webhook)) {
header('Content-type: text/plain');
// Include link to sitemap in robots.txt if the plugin is enabled
2021-09-25 20:28:17 +02:00
if (isPluginActive('pluginSitemap')) {
2020-02-10 21:23:02 +01:00
echo 'Sitemap: '.DOMAIN_BASE.'sitemap.xml'.PHP_EOL;
}
2018-09-16 19:26:23 +02:00
echo $this->getValue('robotstxt');
exit(0);
}
}
}