HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/vangogh.komma.pro/app/Komma/Sitemap/SitemapController.php
<?php
/**
 * Created by PhpStorm.
 * User: mike
 * Date: 03/10/17
 * Time: 15:24
 */

namespace App\Komma\Sitemap;


use App\Komma\Base\Controller;
use Illuminate\Support\Facades\Response;

final class SitemapController extends Controller
{


    /**
     * We only need the structure of the tree to get the pages
     * The content of the pages we can get through the links
     *
     * @param null $language
     * @return \Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function show($language = null)
    {
        // If $language isset and it doesn't match with the app getLocale redefine the application language by iso of $language
        // it probably means that the route is changed by manually changing the route
        if(isset($language) && $language !== \App::getLocale()){
            \App::changeLanguageByIso2($language);
            return \App::reload(); // Because the application has many language dependencies it better reload the whole application
        }

        $otherLanguages = [];
        foreach ($this->site->languages as $siteLanguage){
            $otherLanguages[$siteLanguage->id] = (object)[
                'iso' => $siteLanguage->iso_2,
                'route' => $siteLanguage->iso_2.'/sitemap'
            ];
        }

        return view('site.templates.sitemap',[
            'page' => $this->site->pages()->where('lft', 1)->first(),
            'links' => $this->links,
            'otherLanguages' => $otherLanguages
        ]);
    }

    /**
     * Generate the xml sitemap
     * TODO: Test this when a website is finished
     *
     * @return mixed
     */
    public function xml()
    {
        $sitemapService = new SitemapService();
        $sitemap = $sitemapService->makeSitemap();
        $xmlSitemap = $sitemap->render();

        // If just return the rendered sitemap it will crash so we need to use the getContent
        return $xmlSitemap->getContent();
    }
}