]> _ Git - cubist_cms-back.git/commitdiff
wip #3262 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 13 Dec 2019 17:13:35 +0000 (18:13 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 13 Dec 2019 17:13:35 +0000 (18:13 +0100)
src/app/Console/Commands/LocaleSlugReset.php
src/app/Http/Controllers/CubistSEOController.php
src/app/Magic/Models/Locale.php

index 8cf3c1478ca155cf92517560b534798672a11430..31cb732e446b8504f96d2a6a206c26dfec423fd1 100644 (file)
@@ -23,7 +23,7 @@ class LocaleSlugReset extends CubistCommand
 
     public function handle()
     {
-        //$this->call('backup:run');
+        $this->call('backup:run');
         $this->_handleMagicFolder([$this, '_resetSlug']);
         $this->call('cache:clear');
     }
@@ -38,9 +38,6 @@ class LocaleSlugReset extends CubistCommand
         }
         $class = get_class($model);
         $all = $class::all();
-        if ($class !== 'App\Models\Page') {
-            return;
-        }
         $locale = $this->argument('locale');
         foreach ($all as $instance) {
             $instance->setLocale($locale);
index dcdec4d868f7f9a347030a677638576daaa212ed..8e06aeaef35d5edfe8d78d80b73b4d74aae7158c 100644 (file)
@@ -6,6 +6,7 @@ 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\Models\Locale;
 use Illuminate\Http\Request;
 
 class CubistSEOController extends CubistFrontController
@@ -25,14 +26,28 @@ class CubistSEOController extends CubistFrontController
 
     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)) {
+        $locales = Locale::getEnabledLocalesCodes();
+
+        $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)) {
             $pages = Menu::getAllNavigablePages();
             foreach ($pages as $url => $page) {
                 if ($page instanceof PageItem && !$page->isRobots()) {
                     continue;
                 }
-                $res .= '<url><loc>' . $url . '</loc></url>';
+                $res .= "\t" . '<url>' . "\n";
+                $res .= "\t\t" . '<loc>' . $url . '</loc>' . "\n";
+                if (count($locales) > 1) {
+                    foreach ($locales as $locale) {
+                        $translated = $page->getTranslatedPage($locale);
+                        if (null === $translated || !$translated->isRobots()) {
+                            continue;
+                        }
+                        $res .= "\t\t" . '<xhtml:link rel="alternate" hreflang="' . $locale . '" href="' . $translated->getURL() . '" />' . "\n";
+                    }
+                }
+                $res .= "\t" . '</url>' . "\n";
             }
         }
         $res .= '</urlset>';
index 5ac91d0660003b5d26e47d887018f5db9c0c3d93..af2f9669d830a2c20cab7845b1eb906435ca5bb3 100644 (file)
@@ -88,6 +88,10 @@ class Locale extends CubistMagicAbstractModel
         return array_keys(self::getLocales());
     }
 
+    public static function getEnabledLocalesCodes(){
+        return array_keys(self::getLocalesDataForFront()['enabled']);
+    }
+
     /**
      * @return string
      */