Skip to content

Commit

Permalink
PSR-2 pass
Browse files Browse the repository at this point in the history
  • Loading branch information
GwendolenLynch committed Jan 22, 2016
1 parent 374e82f commit 8c1e250
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

namespace Bolt\Extension\Bolt\Sitemap;

use Symfony\Component\HttpFoundation\Response;
use Bolt\Extensions\Snippets\Location as SnippetLocation;
use Symfony\Component\HttpFoundation\Response;

# If we have a boatload of content, we might need a bit more memory.
set_time_limit(0);
Expand All @@ -14,7 +14,7 @@ class Extension extends \Bolt\BaseExtension
{
public function getName()
{
return "Sitemap";
return 'Sitemap';
}

/**
Expand All @@ -35,11 +35,10 @@ public function initialize()
}

// Set up the routes for the sitemap..
$this->app->match("/sitemap", array($this, 'sitemap'));
$this->app->match("/sitemap.xml", array($this, 'sitemapXml'));
$this->app->match('/sitemap', array($this, 'sitemap'));
$this->app->match('/sitemap.xml', array($this, 'sitemapXml'));

$this->addSnippet(SnippetLocation::END_OF_HEAD, 'headsnippet');

}

public function sitemap($xml = false)
Expand All @@ -51,22 +50,22 @@ public function sitemap($xml = false)
}

$links = array(array('link' => $this->app['paths']['root'], 'title' => $this->app['config']->get('general/sitename')));
foreach ( $this->app['config']->get('contenttypes') as $contenttype ) {
foreach ($this->app['config']->get('contenttypes') as $contenttype) {
if (!in_array($contenttype['slug'], $this->config['ignore_contenttype']) && !$contenttype['viewless'] &&
((isset($contenttype['searchable']) && $contenttype['searchable']) || !isset($contenttype['searchable']))
) {
$baseDepth = 0;
if (isset($contenttype['listing_template']) && !$this->config['ignore_listing']) {
$baseDepth = 1;
$links[] = array( 'link' => $this->app['paths']['root'].$contenttype['slug'], 'title' => $contenttype['name'], 'depth' => 1 );
$links[] = array('link' => $this->app['paths']['root'] . $contenttype['slug'], 'title' => $contenttype['name'], 'depth' => 1);
}
$content = $this->app['storage']->getContent(
$contenttype['slug'],
array('limit' => 10000, 'order' => 'datepublish desc', 'hydrate' => false)
);
foreach ($content as $entry) {
$links[] = array('link' => $entry->link(), 'title' => $entry->getTitle(), 'depth' => $baseDepth + 1,
'lastmod' => date( \DateTime::W3C, strtotime($entry->get('datechanged'))), 'record' => $entry);
'lastmod' => date(\DateTime::W3C, strtotime($entry->get('datechanged'))), 'record' => $entry, );
}
}
}
Expand All @@ -86,7 +85,7 @@ public function sitemap($xml = false)
$this->app['twig.loader.filesystem']->addPath(__DIR__);

$body = $this->app['render']->render($template, array(
'entries' => $links
'entries' => $links,
));

$headers = array();
Expand All @@ -95,7 +94,6 @@ public function sitemap($xml = false)
}

return new Response($body, 200, $headers);

}

public function linkIsIgnored($link)
Expand All @@ -111,7 +109,7 @@ public function linkIsIgnored($link)

// Match on whole string so a $ignore of "/entry/" isn't the same as
// "/entry/.*"
if (preg_match("/^{$pattern}$/", $link['link'])){
if (preg_match("/^{$pattern}$/", $link['link'])) {
return true;
}
}
Expand All @@ -127,14 +125,11 @@ public function sitemapXml()

public function headsnippet()
{

$snippet = sprintf(
'<link rel="sitemap" type="application/xml" title="Sitemap" href="%ssitemap.xml">',
$this->app['paths']['rooturl']
);

return $snippet;

}

}

0 comments on commit 8c1e250

Please sign in to comment.