Skip to content
This repository
Browse code

MINOR: removed will scott as maintainer. BUGFIX: separated decorator …

…file and main file. MINOR updated changelog
  • Loading branch information...
commit 2f271059d9fdc2b17edd8c875b08b8a187d82fcc 1 parent f21d8d8
authored August 12, 2009
5  CHANGELOG
... ...
@@ -0,0 +1,5 @@
  1
+0.1
  2
+	- Initial Build
  3
+	
  4
+0.2
  5
+ 	- Moved Decorator to a separate file
4  README
@@ -4,8 +4,8 @@ Google Sitemaps Module
4 4
 
5 5
 Maintainer Contact
6 6
 -----------------------------------------------
7  
-Will Scott
8  
-<willscott (at) silverstripe (dot) com>
  7
+Will Rossiter
  8
+<will (at) silverstripe (dot) com>
9 9
 
10 10
 Requirements
11 11
 -----------------------------------------------
5  _config.php
... ...
@@ -1,5 +1,10 @@
1 1
 <?php
  2
+
  3
+// adds a rule to make www.site.com/sitemap.xml work
2 4
 Director::addRules(10, array(
3 5
 	'sitemap.xml' => 'GoogleSitemap',
4 6
 ));
  7
+
  8
+// add the extension 
  9
+Object::add_extension('SiteTree', 'GoogleSitemapDecorator');
5 10
 ?>
88  code/GoogleSitemap.php
@@ -146,90 +146,4 @@ public static function enable() {
146 146
 	public static function disable() {
147 147
 		self::$enabled = false;
148 148
 	}
149  
-}
150  
-
151  
-/**
152  
- * @package sapphire
153  
- * @subpackage misc
154  
- */
155  
-class GoogleSitemapDecorator extends SiteTreeDecorator {
156  
-	
157  
-	function extraStatics() {
158  
-		return array(
159  
-			'db' => array(
160  
-				"Priority" => "Float",
161  
-			)
162  
-		);
163  
-	}
164  
-	
165  
-	function updateCMSFields(&$fields) {
166  
-		$pagePriorities = array(
167  
-			'' => _t('SiteTree.PRIORITYAUTOSET','Auto-set based on page depth'),
168  
-			'-1' => _t('SiteTree.PRIORITYNOTINDEXED', "Not indexed"), // We set this to -ve one because a blank value implies auto-generation of Priority
169  
-			'1.0' => '1 - ' . _t('SiteTree.PRIORITYMOSTIMPORTANT', "Most important"),
170  
-			'0.9' => '2',
171  
-			'0.8' => '3',
172  
-			'0.7' => '4',
173  
-			'0.6' => '5',
174  
-			'0.5' => '6',
175  
-			'0.4' => '7',
176  
-			'0.3' => '8',
177  
-			'0.2' => '9',
178  
-			'0.1' => '10 - ' . _t('SiteTree.PRIORITYLEASTIMPORTANT', "Least important")
179  
-		);
180  
-		
181  
-		$tabset = $fields->findOrMakeTab('Root.Content');
182  
-		$tabset->push(
183  
-			$addTab = new Tab(
184  
-				'GoogleSitemap',
185  
-				_t('SiteTree.TABGOOGLESITEMAP', 'Google Sitemap'),
186  
-				new LiteralField(
187  
-					"GoogleSitemapIntro", 
188  
-					"<p>" .
189  
-					sprintf(
190  
-						_t(
191  
-							'SiteTree.METANOTEPRIORITY', 
192  
-							"Manually specify a Google Sitemaps priority for this page (%s)"
193  
-						),
194  
-						'<a href="https://www.google.com/webmasters/tools/docs/en/protocol.html#prioritydef">?</a>'
195  
-					) .
196  
-					"</p>"
197  
-				), 
198  
-				new DropdownField("Priority", $this->owner->fieldLabel('Priority'), $pagePriorities)
199  
-			)
200  
-		);
201  
-	}
202  
-	
203  
-	function updateFieldLabels(&$labels) {
204  
-		parent::updateFieldLabels($labels);
205  
-		
206  
-		$labels['Priority'] = _t('SiteTree.METAPAGEPRIO', "Page Priority");
207  
-	}
208  
-	
209  
-	function onAfterPublish() {
210  
-		GoogleSiteMap::ping();
211  
-	}
212  
-	
213  
-	function onAfterUnpublish() {
214  
-		GoogleSiteMap::ping();
215  
-	}
216  
-	
217  
-	/**
218  
-	 * The default value of the priority field depends on the depth of the page in
219  
-	 * the site tree, so it must be calculated dynamically.
220  
-	 */
221  
-	function getPriority() {		
222  
-		if(!$this->owner->getField('Priority')) {
223  
-			$parentStack = $this->owner->parentStack();
224  
-			$numParents = is_array($parentStack) ? count($parentStack) - 1: 0;
225  
-			return max(0.1, 1.0 - ($numParents / 10));
226  
-		} elseif($this->owner->getField('Priority') == -1) {
227  
-			return 0;
228  
-		} else {
229  
-			return $this->owner->getField('Priority');
230  
-		}
231  
-	}
232  
-}
233  
-
234  
-Object::add_extension('SiteTree', 'GoogleSitemapDecorator');
235  
-?>
  149
+}
88  code/GoogleSitemapDecorator.php
... ...
@@ -0,0 +1,88 @@
  1
+<?php
  2
+
  3
+/**
  4
+ * Decorate the page object to provide google sitemaps with 
  5
+ * additionally options and configuration.
  6
+ * 
  7
+ * @package googlesitemaps
  8
+ */
  9
+class GoogleSitemapDecorator extends SiteTreeDecorator {
  10
+	
  11
+	function extraStatics() {
  12
+		return array(
  13
+			'db' => array(
  14
+				"Priority" => "Float",
  15
+			)
  16
+		);
  17
+	}
  18
+	
  19
+	function updateCMSFields(&$fields) {
  20
+		$pagePriorities = array(
  21
+			'' => _t('SiteTree.PRIORITYAUTOSET','Auto-set based on page depth'),
  22
+			'-1' => _t('SiteTree.PRIORITYNOTINDEXED', "Not indexed"), // We set this to -ve one because a blank value implies auto-generation of Priority
  23
+			'1.0' => '1 - ' . _t('SiteTree.PRIORITYMOSTIMPORTANT', "Most important"),
  24
+			'0.9' => '2',
  25
+			'0.8' => '3',
  26
+			'0.7' => '4',
  27
+			'0.6' => '5',
  28
+			'0.5' => '6',
  29
+			'0.4' => '7',
  30
+			'0.3' => '8',
  31
+			'0.2' => '9',
  32
+			'0.1' => '10 - ' . _t('SiteTree.PRIORITYLEASTIMPORTANT', "Least important")
  33
+		);
  34
+		
  35
+		$tabset = $fields->findOrMakeTab('Root.Content');
  36
+		$tabset->push(
  37
+			$addTab = new Tab(
  38
+				'GoogleSitemap',
  39
+				_t('SiteTree.TABGOOGLESITEMAP', 'Google Sitemap'),
  40
+				new LiteralField(
  41
+					"GoogleSitemapIntro", 
  42
+					"<p>" .
  43
+					sprintf(
  44
+						_t(
  45
+							'SiteTree.METANOTEPRIORITY', 
  46
+							"Manually specify a Google Sitemaps priority for this page (%s)"
  47
+						),
  48
+						'<a href="https://www.google.com/webmasters/tools/docs/en/protocol.html#prioritydef">?</a>'
  49
+					) .
  50
+					"</p>"
  51
+				), 
  52
+				new DropdownField("Priority", $this->owner->fieldLabel('Priority'), $pagePriorities)
  53
+			)
  54
+		);
  55
+	}
  56
+	
  57
+	function updateFieldLabels(&$labels) {
  58
+		parent::updateFieldLabels($labels);
  59
+		
  60
+		$labels['Priority'] = _t('SiteTree.METAPAGEPRIO', "Page Priority");
  61
+	}
  62
+	
  63
+	function onAfterPublish() {
  64
+		GoogleSiteMap::ping();
  65
+	}
  66
+	
  67
+	function onAfterUnpublish() {
  68
+		GoogleSiteMap::ping();
  69
+	}
  70
+	
  71
+	/**
  72
+	 * The default value of the priority field depends on the depth of the page in
  73
+	 * the site tree, so it must be calculated dynamically.
  74
+	 */
  75
+	function getPriority() {		
  76
+		if(!$this->owner->getField('Priority')) {
  77
+			$parentStack = $this->owner->parentStack();
  78
+			$numParents = is_array($parentStack) ? count($parentStack) - 1: 0;
  79
+			return max(0.1, 1.0 - ($numParents / 10));
  80
+		} elseif($this->owner->getField('Priority') == -1) {
  81
+			return 0;
  82
+		} else {
  83
+			return $this->owner->getField('Priority');
  84
+		}
  85
+	}
  86
+}
  87
+
  88
+?>

0 notes on commit 2f27105

Please sign in to comment.
Something went wrong with that request. Please try again.