Skip to content

Commit

Permalink
xhtml definition in XML.
Browse files Browse the repository at this point in the history
  • Loading branch information
BeneRoch committed Jun 22, 2018
1 parent e857e26 commit b6973fb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/Charcoal/Sitemap/Action/SitemapAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace Charcoal\Sitemap\Action;

use SimpleXMLElement;

use Charcoal\App\Action\AbstractAction;
use Charcoal\Translator\TranslatorAwareTrait;
use Pimple\Container;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

use Charcoal\App\Action\AbstractAction;
use Charcoal\Translator\TranslatorAwareTrait;
use SimpleXMLElement;

/**
* Class SitemapAction
Expand All @@ -34,7 +32,7 @@ public function setDependencies(Container $container)
parent::setDependencies($container);

$this->sitemapBuilder = $container['charcoal/sitemap/builder'];
$this->baseUrl = $container['base-url'];
$this->baseUrl = $container['base-url'];
}

/**
Expand All @@ -50,7 +48,7 @@ public function run(RequestInterface $request, ResponseInterface $response)
{
$this->setMode(self::MODE_XML);

$sitemap = $this->sitemapBuilder->build('xml');
$sitemap = $this->sitemapBuilder->build('xml');
$this->xml = $this->toXml($sitemap);

$this->setSuccess(true);
Expand All @@ -61,9 +59,10 @@ public function run(RequestInterface $request, ResponseInterface $response)
protected function toXml($map)
{
$str = '<?xml version="1.0" encoding="UTF-8"?><urlset '
.'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" '
.'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
.'xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"/>';
. 'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" '
. 'xmlns:xhtml="http://www.w3.org/1999/xhtml" '
. '/>';


$xml = new SimpleXmlElement($str);

Expand Down Expand Up @@ -102,7 +101,7 @@ protected function toXml($map)
parse_url($altUrl, PHP_URL_HOST) !== null) {
continue;
}
$xhtml = $url->addChild('xhtml:link', null,'xhtml');
$xhtml = $url->addChild('xhtml:link', null, 'xhtml');
$xhtml->addAttribute('rel', 'alternate');
$xhtml->addAttribute('hreflang', $alt['lang']);
$xhtml->addAttribute('href', $altUrl);
Expand Down

0 comments on commit b6973fb

Please sign in to comment.