]> _ Git - cubist_cms-back.git/commitdiff
fix #2949 @0:20
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Aug 2019 15:01:22 +0000 (17:01 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 28 Aug 2019 15:01:22 +0000 (17:01 +0200)
src/app/Http/Controllers/CubistSEOController.php
src/app/Magic/Menu/Menu.php
src/app/Magic/Search.php

index 7319d563e71e59e29bee58f9ba829be1924d8787..768a6a974f8e2cadb388851c138a75bccb774494 100644 (file)
@@ -4,6 +4,13 @@
 namespace Cubist\Backpack\app\Http\Controllers;
 
 
+use Cubist\Backpack\app\Magic\Menu\Menu;
+use Cubist\Backpack\app\Magic\Menu\PageItem;
+use Cubist\Backpack\app\Magic\Menu\VirtualItem;
+use Cubist\Backpack\app\Template\Navigation;
+use Cubist\Backpack\app\Template\Redirection;
+use Cubist\Util\XML\DOMSelector;
+use Cviebrock\LaravelElasticsearch\Facade as Elasticsearch;
 use Illuminate\Http\Request;
 
 class CubistSEOController
@@ -23,6 +30,17 @@ class CubistSEOController
 
     public function sitemap(Request $request)
     {
-
+        $res = '<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
+        if (config('cubist.seo_robots', true)) {
+            $pages = Menu::getAllNavigablePages();
+            foreach ($pages as $url => $page) {
+                if ($page instanceof PageItem && !$page->getPage()->robots) {
+                    continue;
+                }
+                $res .= '<url><loc>' . $url . '</loc></url>';
+            }
+        }
+        $res .= '</urlset>';
+        return response($res)->header('Content-type', 'text/xml');
     }
 }
index 982c951eb21adbf72eaa2ed309b7704c018f6542..19e4872531ff2bf345fb0c17d7a4fb3d638bc6ff 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace Cubist\Backpack\app\Magic\Menu;
 
+use Cubist\Backpack\app\Template\Navigation;
+use Cubist\Backpack\app\Template\Redirection;
 use Lavary\Menu\Menu as BaseMenu;
 use Illuminate\Support\Facades\Cache;
 
@@ -38,6 +40,43 @@ class Menu extends BaseMenu
 
     }
 
+    /**
+     * @return Cubist\Backpack\app\Magic\Menu\Item[]
+     */
+    public static function getAllNavigablePages()
+    {
+        $pages = Menu::getNavigation()->findAll();
+
+        $res = [];
+
+        foreach ($pages as $page) {
+            // Skip nav items
+            if ($page instanceof VirtualItem) {
+                continue;
+            }
+            // Skip redirection & navigation pages
+            if ($page instanceof PageItem) {
+                /** @var PageItem $template */
+                $template = $page->getPage()->getUsedTemplate();
+                if ($template instanceof Redirection || $template instanceof Navigation) {
+                    continue;
+                }
+            }
+
+            $href = $page->getHref();
+            if ($href == '#' || $href == 'home') {
+                continue;
+            }
+
+            $url = action("PageController@catchall", ['page' => $href]);
+            if (isset($res[$url])) {
+                continue;
+            }
+            $res[$url] = $page;
+        }
+        return $res;
+    }
+
     public static function internalToHref($url)
     {
         if (stristr($url, 'internal:')) {
@@ -103,7 +142,7 @@ class Menu extends BaseMenu
         /** @var \Lavary\Menu\Item $item */
         $position = 0;
         foreach ($this->get('breadcrumbs')->crumbMenu()->all() as $item) {
-            $active="";
+            $active = "";
             if ($item->isActive) {
                 $active = ' active';
             }
index 45ff2985311ebbd26d51a66e3e6adab7f6f7f450..0d8d5bfebdebb0dbba04eb415730f89b1e19a467 100644 (file)
@@ -35,34 +35,11 @@ class Search
             ]);
 
         /** @var Cubist\Backpack\app\Magic\Menu\Item[] $pages */
-        $pages = Menu::getNavigation()->findAll();
+        $pages = Menu::getAllNavigablePages();
 
         $indexed = [];
 
-        foreach ($pages as $page) {
-            // Skip nav items
-            if ($page instanceof VirtualItem) {
-                continue;
-            }
-            // Skip redirection & navigation pages
-            if ($page instanceof PageItem) {
-                /** @var PageItem $template */
-                $template = $page->getPage()->getUsedTemplate();
-                if ($template instanceof Redirection || $template instanceof Navigation) {
-                    continue;
-                }
-            }
-
-            $href = $page->getHref();
-            if ($href == '#' || $href == 'home') {
-                continue;
-            }
-
-            $url = action("PageController@catchall", ['page' => $href]);
-            if (isset($indexed[$url])) {
-                continue;
-            }
-
+        foreach ($pages as $url => $page) {
             $html = @file_get_contents($url);
             if (!$html) {
                 continue;