ENHANCEMENT: added ability to define a custom prority to dataobjects.

This commit is contained in:
Will Rossiter 2011-06-13 11:16:07 +12:00
parent 805c7e2ee4
commit 65c59fc020
1 changed files with 22 additions and 19 deletions

View File

@ -10,7 +10,7 @@
* sitemap whenever the GoogleBot visits your website. * sitemap whenever the GoogleBot visits your website.
* *
* Enabling notification of Google after every publish (in your _config.php): * Enabling notification of Google after every publish (in your _config.php):
*
* <example> * <example>
* GoogleSitemap::enable_google_notificaton(); * GoogleSitemap::enable_google_notificaton();
* </example> * </example>
@ -55,37 +55,40 @@ class GoogleSitemap extends Controller {
*/ */
public static $google_sitemap_dataobjects_changefreq = array(); public static $google_sitemap_dataobjects_changefreq = array();
/** /**
* List of DataObjects priority * List of DataObjects priority
* *
* @var array * @var array
*/ */
public static $google_sitemap_dataobjects_priority = 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.
* Note that all registered DataObjects need the method AbsoluteLink(). * Note that all registered DataObjects need the method AbsoluteLink().
* *
* @param string $className name of DataObject to register * @param string $className name of DataObject to register
* @param string $changeFreq how often is this DataObject updated? * @param string $changeFreq how often is this DataObject updated?
* Possible values: * Possible values:
* always, hourly, daily, weekly, monthly, yearly, never * always, hourly, daily, weekly, monthly, yearly, never
* @param string $priority How important is this DataObject in comparison to other urls? * @param string $priority How important is this DataObject in comparison to other urls?
* Possible values: 0.1, 0.2 ... , 0.9, 1.0 * Possible values: 0.1, 0.2 ... , 0.9, 1.0
* *
* @return void * @return void
*/ */
public static function register_dataobject($className, $changeFreq = 'monthly', $priority = '0.6') { 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"; if (!$changeFreq) {
} else { self::$google_sitemap_dataobjects_changefreq[] = "monthly";
self::$google_sitemap_dataobjects_changefreq[] = $changeFreq; } else {
} self::$google_sitemap_dataobjects_changefreq[] = $changeFreq;
self::$google_sitemap_dataobjects_priority[] = $priority; }
self::$google_sitemap_dataobjects_priority[] = $priority;
} }
} }
@ -132,7 +135,7 @@ class GoogleSitemap extends Controller {
/** /**
* Returns all the links to {@link SiteTree} pages and * Returns all the links to {@link SiteTree} pages and
* {@link DataObject} urls on the page * {@link DataObject} urls on the page.
* *
* @return DataObjectSet * @return DataObjectSet
*/ */