File modules/cms/generator/filter/RobotsFilter.class.php
Last commit: Tue Feb 14 00:23:13 2023 +0100 Jan Dankert New filters: Robots (for robots.txt) and Sitemap.
1 <?php 2 3 4 namespace cms\generator\filter; 5 6 7 use util\YAML; 8 9 class RobotsFilter extends AbstractFilter 10 { 11 public function filter( $value ) 12 { 13 $output = ''; 14 $robots = YAML::parse( $value ); 15 16 if ( @$robots['allowedAgents'] ) 17 foreach ( $robots['allowedAgents'] as $allowedAgent) 18 $output .= 'User-Agent: '.$allowedAgent."\n".'Allow: /'."\n"; 19 20 if ( @$robots['disallowedAgents'] ) 21 foreach ( $robots['disallowedAgents'] as $disallowedAgent) 22 $output .= 'User-Agent: '.$disallowedAgent."\n".'Disallow: /'."\n"; 23 24 if ( @$robots['agents'] ) 25 foreach ( $robots['agents'] as $agent) { 26 $output .= 'User-Agent: '.@$agent['name']."\n"; 27 if ( @$agent['allow'] ) 28 $output .= 'Allow: '.@$agent['allow']."\n"; 29 if ( @$agent['disallow'] ) 30 $output .= 'Disallow: '.@$agent['disallow']."\n"; 31 } 32 33 if ( @$robots['sitemap'] ) 34 $output .= 'Sitemap: '.@$robots['sitemap']."\n"; 35 36 if ( @$robots['delay'] ) 37 $output .= 'Crawl-delay: '.@$robots['delay']."\n"; 38 39 return $output; 40 } 41 }
Downloadmodules/cms/generator/filter/RobotsFilter.class.php
History Tue, 14 Feb 2023 00:23:13 +0100 Jan Dankert New filters: Robots (for robots.txt) and Sitemap.