From 2f271059d9fdc2b17edd8c875b08b8a187d82fcc Mon Sep 17 00:00:00 2001 From: wrossiter Date: Wed, 12 Aug 2009 03:51:43 +0000 Subject: [PATCH] MINOR: removed will scott as maintainer. BUGFIX: separated decorator file and main file. MINOR updated changelog --- CHANGELOG | 5 ++ README | 4 +- _config.php | 5 ++ code/GoogleSitemap.php | 88 +-------------------------------- code/GoogleSitemapDecorator.php | 88 +++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 89 deletions(-) create mode 100644 code/GoogleSitemapDecorator.php diff --git a/CHANGELOG b/CHANGELOG index e69de29..f5dbca3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -0,0 +1,5 @@ +0.1 + - Initial Build + +0.2 + - Moved Decorator to a separate file diff --git a/README b/README index 7bf2a72..0ae8a4e 100644 --- a/README +++ b/README @@ -4,8 +4,8 @@ Google Sitemaps Module Maintainer Contact ----------------------------------------------- -Will Scott - +Will Rossiter + Requirements ----------------------------------------------- diff --git a/_config.php b/_config.php index fcbe863..e8fb0e2 100644 --- a/_config.php +++ b/_config.php @@ -1,5 +1,10 @@ 'GoogleSitemap', )); + +// add the extension +Object::add_extension('SiteTree', 'GoogleSitemapDecorator'); ?> \ No newline at end of file diff --git a/code/GoogleSitemap.php b/code/GoogleSitemap.php index d80829a..3b73349 100755 --- a/code/GoogleSitemap.php +++ b/code/GoogleSitemap.php @@ -146,90 +146,4 @@ class GoogleSitemap extends Controller { public static function disable() { self::$enabled = false; } -} - -/** - * @package sapphire - * @subpackage misc - */ -class GoogleSitemapDecorator extends SiteTreeDecorator { - - function extraStatics() { - return array( - 'db' => array( - "Priority" => "Float", - ) - ); - } - - function updateCMSFields(&$fields) { - $pagePriorities = array( - '' => _t('SiteTree.PRIORITYAUTOSET','Auto-set based on page depth'), - '-1' => _t('SiteTree.PRIORITYNOTINDEXED', "Not indexed"), // We set this to -ve one because a blank value implies auto-generation of Priority - '1.0' => '1 - ' . _t('SiteTree.PRIORITYMOSTIMPORTANT', "Most important"), - '0.9' => '2', - '0.8' => '3', - '0.7' => '4', - '0.6' => '5', - '0.5' => '6', - '0.4' => '7', - '0.3' => '8', - '0.2' => '9', - '0.1' => '10 - ' . _t('SiteTree.PRIORITYLEASTIMPORTANT', "Least important") - ); - - $tabset = $fields->findOrMakeTab('Root.Content'); - $tabset->push( - $addTab = new Tab( - 'GoogleSitemap', - _t('SiteTree.TABGOOGLESITEMAP', 'Google Sitemap'), - new LiteralField( - "GoogleSitemapIntro", - "

" . - sprintf( - _t( - 'SiteTree.METANOTEPRIORITY', - "Manually specify a Google Sitemaps priority for this page (%s)" - ), - '?' - ) . - "

" - ), - new DropdownField("Priority", $this->owner->fieldLabel('Priority'), $pagePriorities) - ) - ); - } - - function updateFieldLabels(&$labels) { - parent::updateFieldLabels($labels); - - $labels['Priority'] = _t('SiteTree.METAPAGEPRIO', "Page Priority"); - } - - function onAfterPublish() { - GoogleSiteMap::ping(); - } - - function onAfterUnpublish() { - GoogleSiteMap::ping(); - } - - /** - * The default value of the priority field depends on the depth of the page in - * the site tree, so it must be calculated dynamically. - */ - function getPriority() { - if(!$this->owner->getField('Priority')) { - $parentStack = $this->owner->parentStack(); - $numParents = is_array($parentStack) ? count($parentStack) - 1: 0; - return max(0.1, 1.0 - ($numParents / 10)); - } elseif($this->owner->getField('Priority') == -1) { - return 0; - } else { - return $this->owner->getField('Priority'); - } - } -} - -Object::add_extension('SiteTree', 'GoogleSitemapDecorator'); -?> +} \ No newline at end of file diff --git a/code/GoogleSitemapDecorator.php b/code/GoogleSitemapDecorator.php new file mode 100644 index 0000000..8734e22 --- /dev/null +++ b/code/GoogleSitemapDecorator.php @@ -0,0 +1,88 @@ + array( + "Priority" => "Float", + ) + ); + } + + function updateCMSFields(&$fields) { + $pagePriorities = array( + '' => _t('SiteTree.PRIORITYAUTOSET','Auto-set based on page depth'), + '-1' => _t('SiteTree.PRIORITYNOTINDEXED', "Not indexed"), // We set this to -ve one because a blank value implies auto-generation of Priority + '1.0' => '1 - ' . _t('SiteTree.PRIORITYMOSTIMPORTANT', "Most important"), + '0.9' => '2', + '0.8' => '3', + '0.7' => '4', + '0.6' => '5', + '0.5' => '6', + '0.4' => '7', + '0.3' => '8', + '0.2' => '9', + '0.1' => '10 - ' . _t('SiteTree.PRIORITYLEASTIMPORTANT', "Least important") + ); + + $tabset = $fields->findOrMakeTab('Root.Content'); + $tabset->push( + $addTab = new Tab( + 'GoogleSitemap', + _t('SiteTree.TABGOOGLESITEMAP', 'Google Sitemap'), + new LiteralField( + "GoogleSitemapIntro", + "

" . + sprintf( + _t( + 'SiteTree.METANOTEPRIORITY', + "Manually specify a Google Sitemaps priority for this page (%s)" + ), + '?' + ) . + "

" + ), + new DropdownField("Priority", $this->owner->fieldLabel('Priority'), $pagePriorities) + ) + ); + } + + function updateFieldLabels(&$labels) { + parent::updateFieldLabels($labels); + + $labels['Priority'] = _t('SiteTree.METAPAGEPRIO', "Page Priority"); + } + + function onAfterPublish() { + GoogleSiteMap::ping(); + } + + function onAfterUnpublish() { + GoogleSiteMap::ping(); + } + + /** + * The default value of the priority field depends on the depth of the page in + * the site tree, so it must be calculated dynamically. + */ + function getPriority() { + if(!$this->owner->getField('Priority')) { + $parentStack = $this->owner->parentStack(); + $numParents = is_array($parentStack) ? count($parentStack) - 1: 0; + return max(0.1, 1.0 - ($numParents / 10)); + } elseif($this->owner->getField('Priority') == -1) { + return 0; + } else { + return $this->owner->getField('Priority'); + } + } +} + +?> \ No newline at end of file