]> _ Git - cubist_cms-back.git/commitdiff
wip #3514 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Mar 2020 10:35:55 +0000 (11:35 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 19 Mar 2020 10:35:55 +0000 (11:35 +0100)
src/app/Http/Controllers/CubistSEOController.php

index 8e06aeaef35d5edfe8d78d80b73b4d74aae7158c..973ae3e12a9da8aa965742497f794aceae71495c 100644 (file)
@@ -11,14 +11,27 @@ use Illuminate\Http\Request;
 
 class CubistSEOController extends CubistFrontController
 {
+    protected function isRobotsEnabled()
+    {
+        if (!config('cubist.seo_robots', true)) {
+            return false;
+        }
+        $robots = $this->data['global']->get('robots');
+        if (null === $robots) {
+            return false;
+        }
+        return in_array(env('APP_ENV'), $robots, true);
+    }
+
     public function robots(Request $request)
     {
         $response = ['User-agent: *'];
-        if (config('cubist.seo_robots', true)) {
+
+        if (!$this->isRobotsEnabled()) {
+            $response[] = 'Disallow: /';
+        } else {
             $response[] = 'Disallow: /admin/';
             $response[] = 'Sitemap: ' . url('/sitemap.xml');
-        } else {
-            $response[] = 'Disallow: /';
         }
 
         return response(implode("\n", $response))->header('Content-type', 'text/plain');
@@ -30,7 +43,7 @@ class CubistSEOController extends CubistFrontController
 
         $res = '<?xml version="1.0" encoding="UTF-8"?>' . "\n";
         $res .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">' . "\n";
-        if (true || config('cubist.seo_robots', true)) {
+        if ($this->isRobotsEnabled()) {
             $pages = Menu::getAllNavigablePages();
             foreach ($pages as $url => $page) {
                 if ($page instanceof PageItem && !$page->isRobots()) {