The change frequency is now configurable via GoogleSitemap::register_dataobject()

This commit is contained in:
Roland Lehmann 2011-06-11 12:26:17 +02:00
parent 54929f3e50
commit c841987427

View File

@ -55,6 +55,13 @@ class GoogleSitemap extends Controller {
*/ */
public static $google_sitemap_dataobjects_changefreq = array(); public static $google_sitemap_dataobjects_changefreq = array();
/**
* List of DataObjects priority
*
* @var array
*/
public static $google_sitemap_dataobjects_priority = array();
/** /**
* Decorates the given DataObject with {@link GoogleSitemapDecorator} * Decorates the given DataObject with {@link GoogleSitemapDecorator}
* and pushes the class name to the registered DataObjects. * and pushes the class name to the registered DataObjects.
@ -65,12 +72,17 @@ class GoogleSitemap extends Controller {
* *
* @return void * @return void
*/ */
public static function register_dataobject($className, $changeFreq = 'monthly') { public static function register_dataobject($className, $changeFreq = 'monthly', $priority = 0.6) {
if (!self::is_registered($className)) { if (!self::is_registered($className)) {
Object::add_extension($className, 'GoogleSitemapDecorator'); Object::add_extension($className, 'GoogleSitemapDecorator');
self::$google_sitemap_dataobjects[] = $className; self::$google_sitemap_dataobjects[] = $className;
if ($changeFreq === null) {
self::$google_sitemap_dataobjects_changefreq[] = "monthly";
} else {
self::$google_sitemap_dataobjects_changefreq[] = $changeFreq; self::$google_sitemap_dataobjects_changefreq[] = $changeFreq;
} }
self::$google_sitemap_dataobjects_priority[] = $priority;
}
} }
/** /**
@ -100,11 +112,11 @@ class GoogleSitemap extends Controller {
if($dataObjectSet) { if($dataObjectSet) {
foreach($dataObjectSet as $dataObject) { foreach($dataObjectSet as $dataObject) {
if($dataObject->canView() && (!isset($dataObject->Priority) || $dataObject->Priority > 0)) { if($dataObject->canView()) {
$dataObject->ChangeFreq = self::$google_sitemap_dataobjects_changefreq[$index]; $dataObject->ChangeFreq = self::$google_sitemap_dataobjects_changefreq[$index];
if(!isset($dataObject->Priority)) { if(!isset($dataObject->Priority)) {
$dataObject->Priority = 1.0; $dataObject->Priority = self::$google_sitemap_dataobjects_priority[$index];
} }
$output->push($dataObject); $output->push($dataObject);