mirror of
https://github.com/wilr/silverstripe-googlesitemaps.git
synced 2024-10-22 11:05:48 +02:00
FIX/NEW for #90 Allow ability to alter DataList and deprecate static interface for better extensibility.
This commit is contained in:
parent
c549ca4d3f
commit
e2a1dc5250
@ -37,7 +37,7 @@
|
|||||||
*
|
*
|
||||||
* @package googlesitemaps
|
* @package googlesitemaps
|
||||||
*/
|
*/
|
||||||
class GoogleSitemap {
|
class GoogleSitemap extends Object {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of {@link DataObject} class names to include. As well as the change
|
* List of {@link DataObject} class names to include. As well as the change
|
||||||
@ -181,7 +181,7 @@ class GoogleSitemap {
|
|||||||
*
|
*
|
||||||
* @return ArrayList
|
* @return ArrayList
|
||||||
*/
|
*/
|
||||||
public static function get_items($class, $page = 1) {
|
public function getItems($class, $page = 1) {
|
||||||
//normalise the class name
|
//normalise the class name
|
||||||
try {
|
try {
|
||||||
$reflectionClass = new ReflectionClass($class);
|
$reflectionClass = new ReflectionClass($class);
|
||||||
@ -203,8 +203,8 @@ class GoogleSitemap {
|
|||||||
|
|
||||||
if($class == "SiteTree") {
|
if($class == "SiteTree") {
|
||||||
$filter = ($filter) ? "\"ShowInSearch\" = 1" : "";
|
$filter = ($filter) ? "\"ShowInSearch\" = 1" : "";
|
||||||
|
|
||||||
$instances = Versioned::get_by_stage('SiteTree', 'Live', $filter);
|
$instances = Versioned::get_by_stage('SiteTree', 'Live', $filter);
|
||||||
|
$this->extend("alterDataList", $instances, $class);
|
||||||
}
|
}
|
||||||
else if($class == "GoogleSitemapRoute") {
|
else if($class == "GoogleSitemapRoute") {
|
||||||
$instances = array_slice(self::$routes, ($page - 1) * $count, $count);
|
$instances = array_slice(self::$routes, ($page - 1) * $count, $count);
|
||||||
@ -242,6 +242,20 @@ class GoogleSitemap {
|
|||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static interface to instance level ->getItems() for backward compatibility.
|
||||||
|
*
|
||||||
|
* @param string
|
||||||
|
* @param int
|
||||||
|
*
|
||||||
|
* @return ArrayList
|
||||||
|
* @deprecated Please create an instance and call ->getSitemaps() instead.
|
||||||
|
*/
|
||||||
|
public static function get_items($class, $page = 1) {
|
||||||
|
return static::inst()->getItems($class, $page);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the string frequency of edits for a particular dataobject class.
|
* Returns the string frequency of edits for a particular dataobject class.
|
||||||
*
|
*
|
||||||
@ -258,6 +272,8 @@ class GoogleSitemap {
|
|||||||
return $config['frequency'];
|
return $config['frequency'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -284,7 +300,7 @@ class GoogleSitemap {
|
|||||||
*
|
*
|
||||||
* @return ArrayList
|
* @return ArrayList
|
||||||
*/
|
*/
|
||||||
public static function get_sitemaps() {
|
public function getSitemaps() {
|
||||||
$countPerFile = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap');
|
$countPerFile = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap');
|
||||||
$sitemaps = new ArrayList();
|
$sitemaps = new ArrayList();
|
||||||
$filter = Config::inst()->get('GoogleSitemap', 'use_show_in_search');
|
$filter = Config::inst()->get('GoogleSitemap', 'use_show_in_search');
|
||||||
@ -297,7 +313,9 @@ class GoogleSitemap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$filter = ($filter) ? "\"ShowInSearch\" = 1" : "";
|
$filter = ($filter) ? "\"ShowInSearch\" = 1" : "";
|
||||||
$instances = Versioned::get_by_stage('SiteTree', 'Live', $filter);
|
$class = 'SiteTree';
|
||||||
|
$instances = Versioned::get_by_stage($class, 'Live', $filter);
|
||||||
|
$this->extend("alterDataList", $instances, $class);
|
||||||
$count = $instances->count();
|
$count = $instances->count();
|
||||||
|
|
||||||
$neededForPage = ceil($count / $countPerFile);
|
$neededForPage = ceil($count / $countPerFile);
|
||||||
@ -357,6 +375,16 @@ class GoogleSitemap {
|
|||||||
return $sitemaps;
|
return $sitemaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static interface to instance level ->getSitemaps() for backward compatibility.
|
||||||
|
*
|
||||||
|
* @return ArrayList
|
||||||
|
* @deprecated Please create an instance and call ->getSitemaps() instead.
|
||||||
|
*/
|
||||||
|
public static function get_sitemaps() {
|
||||||
|
return static::inst()->getSitemaps();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies Google about changes to your sitemap. This behavior is disabled
|
* Notifies Google about changes to your sitemap. This behavior is disabled
|
||||||
* by default, to enable, read the documentation provided in the docs folder.
|
* by default, to enable, read the documentation provided in the docs folder.
|
||||||
@ -421,4 +449,15 @@ class GoogleSitemap {
|
|||||||
public static function enabled() {
|
public static function enabled() {
|
||||||
return (Config::inst()->get('GoogleSitemap', 'enabled', Config::INHERITED));
|
return (Config::inst()->get('GoogleSitemap', 'enabled', Config::INHERITED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience method for manufacturing an instance for hew instance-level methods (and for easier type definition).
|
||||||
|
*
|
||||||
|
* @return GoogleSitemap
|
||||||
|
*/
|
||||||
|
public static function inst() {
|
||||||
|
return GoogleSitemap::create();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ class GoogleSitemapController extends Controller {
|
|||||||
'sitemap'
|
'sitemap'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default controller action for the sitemap.xml file. Renders a index
|
* Default controller action for the sitemap.xml file. Renders a index
|
||||||
* file containing a list of links to sub sitemaps containing the data.
|
* file containing a list of links to sub sitemaps containing the data.
|
||||||
@ -35,7 +36,7 @@ class GoogleSitemapController extends Controller {
|
|||||||
$this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
|
$this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
|
||||||
$this->getResponse()->addHeader('X-Robots-Tag', 'noindex');
|
$this->getResponse()->addHeader('X-Robots-Tag', 'noindex');
|
||||||
|
|
||||||
$sitemaps = GoogleSitemap::get_sitemaps();
|
$sitemaps = GoogleSitemap::inst()->getSitemaps();
|
||||||
$this->extend('updateGoogleSitemaps', $sitemaps);
|
$this->extend('updateGoogleSitemaps', $sitemaps);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
@ -62,7 +63,7 @@ class GoogleSitemapController extends Controller {
|
|||||||
$this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
|
$this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"');
|
||||||
$this->getResponse()->addHeader('X-Robots-Tag', 'noindex');
|
$this->getResponse()->addHeader('X-Robots-Tag', 'noindex');
|
||||||
|
|
||||||
$items = GoogleSitemap::get_items($class, $page);
|
$items = GoogleSitemap::inst()->getItems($class, $page);
|
||||||
$this->extend('updateGoogleSitemapItems', $items, $class, $page);
|
$this->extend('updateGoogleSitemapItems', $items, $class, $page);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* TODO: Migrate to new instance level interface instead of using static methods for retrieval of site maps and items (i.e. ->getSitemaps() instead of ::get_sitemaps()).
|
||||||
|
*
|
||||||
* @package googlesitemaps
|
* @package googlesitemaps
|
||||||
* @subpackage tests
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user