2013-01-15 10:29:59 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller for displaying the sitemap.xml. The module displays an index
|
|
|
|
* sitemap at the sitemap.xml level, then outputs the individual objects
|
|
|
|
* at a second level.
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* http://site.com/sitemap.xml/
|
|
|
|
* http://site.com/sitemap.xml/sitemap/$ClassName-$Page.xml
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @package googlesitemaps
|
|
|
|
*/
|
|
|
|
class GoogleSitemapController extends Controller {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2013-04-02 00:57:42 +02:00
|
|
|
private static $allowed_actions = array(
|
2013-01-15 10:29:59 +01:00
|
|
|
'index',
|
|
|
|
'sitemap'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default controller action for the sitemap.xml file. Renders a index
|
|
|
|
* file containing a list of links to sub sitemaps containing the data.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function index($url) {
|
|
|
|
if(GoogleSitemap::enabled()) {
|
2013-05-31 15:33:38 +02:00
|
|
|
Config::inst()->update('SSViewer', 'set_source_file_comments', false);
|
2013-01-15 10:29:59 +01:00
|
|
|
|
|
|
|
$this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
|
|
|
|
|
2013-01-17 22:49:53 +01:00
|
|
|
$sitemaps = GoogleSitemap::get_sitemaps();
|
|
|
|
$this->extend('updateGoogleSitemaps', $sitemaps);
|
|
|
|
|
2013-01-15 10:29:59 +01:00
|
|
|
return array(
|
2013-01-17 22:49:53 +01:00
|
|
|
'Sitemaps' => $sitemaps
|
2013-01-15 10:29:59 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return new SS_HTTPResponse('Page not found', 404);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Specific controller action for displaying a particular list of links
|
|
|
|
* for a class
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function sitemap() {
|
|
|
|
$class = $this->request->param('ID');
|
|
|
|
$page = $this->request->param('OtherID');
|
|
|
|
|
|
|
|
if(GoogleSitemap::enabled() && $class && $page) {
|
2013-05-31 15:33:38 +02:00
|
|
|
Config::inst()->update('SSViewer', 'set_source_file_comments', false);
|
2013-01-15 10:29:59 +01:00
|
|
|
|
|
|
|
$this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
|
|
|
|
|
2013-01-17 22:49:53 +01:00
|
|
|
$items = GoogleSitemap::get_items($class, $page);
|
|
|
|
$this->extend('updateGoogleSitemapItems', $items, $class, $page);
|
|
|
|
|
2013-01-15 10:29:59 +01:00
|
|
|
return array(
|
2013-01-17 22:49:53 +01:00
|
|
|
'Items' => $items
|
2013-01-15 10:29:59 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return new SS_HTTPResponse('Page not found', 404);
|
|
|
|
}
|
|
|
|
}
|
2013-05-31 15:33:38 +02:00
|
|
|
}
|