From c87c05b26a562a6dd7892a0ad81a8cd72cdf4b55 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 28 Aug 2019 17:01:22 +0200 Subject: [PATCH] fix #2949 @0:20 --- .../Http/Controllers/CubistSEOController.php | 20 ++++++++- src/app/Magic/Menu/Menu.php | 41 ++++++++++++++++++- src/app/Magic/Search.php | 27 +----------- 3 files changed, 61 insertions(+), 27 deletions(-) diff --git a/src/app/Http/Controllers/CubistSEOController.php b/src/app/Http/Controllers/CubistSEOController.php index 7319d56..768a6a9 100644 --- a/src/app/Http/Controllers/CubistSEOController.php +++ b/src/app/Http/Controllers/CubistSEOController.php @@ -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 = ''; + if (config('cubist.seo_robots', true)) { + $pages = Menu::getAllNavigablePages(); + foreach ($pages as $url => $page) { + if ($page instanceof PageItem && !$page->getPage()->robots) { + continue; + } + $res .= '' . $url . ''; + } + } + $res .= ''; + return response($res)->header('Content-type', 'text/xml'); } } diff --git a/src/app/Magic/Menu/Menu.php b/src/app/Magic/Menu/Menu.php index 982c951..19e4872 100644 --- a/src/app/Magic/Menu/Menu.php +++ b/src/app/Magic/Menu/Menu.php @@ -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'; } diff --git a/src/app/Magic/Search.php b/src/app/Magic/Search.php index 45ff298..0d8d5bf 100644 --- a/src/app/Magic/Search.php +++ b/src/app/Magic/Search.php @@ -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; -- 2.39.5