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
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');
}
}
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;
}
+ /**
+ * @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:')) {
/** @var \Lavary\Menu\Item $item */
$position = 0;
foreach ($this->get('breadcrumbs')->crumbMenu()->all() as $item) {
- $active="";
+ $active = "";
if ($item->isActive) {
$active = ' active';
}
]);
/** @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;