mirror of
https://github.com/wilr/silverstripe-googlesitemaps.git
synced 2024-10-22 11:05:48 +02:00
MINOR: removed will scott as maintainer. BUGFIX: separated decorator file and main file. MINOR updated changelog
This commit is contained in:
parent
f21d8d86ca
commit
2f271059d9
4
README
4
README
@ -4,8 +4,8 @@ Google Sitemaps Module
|
||||
|
||||
Maintainer Contact
|
||||
-----------------------------------------------
|
||||
Will Scott
|
||||
<willscott (at) silverstripe (dot) com>
|
||||
Will Rossiter
|
||||
<will (at) silverstripe (dot) com>
|
||||
|
||||
Requirements
|
||||
-----------------------------------------------
|
||||
|
@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
// adds a rule to make www.site.com/sitemap.xml work
|
||||
Director::addRules(10, array(
|
||||
'sitemap.xml' => 'GoogleSitemap',
|
||||
));
|
||||
|
||||
// add the extension
|
||||
Object::add_extension('SiteTree', 'GoogleSitemapDecorator');
|
||||
?>
|
@ -147,89 +147,3 @@ class GoogleSitemap extends Controller {
|
||||
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",
|
||||
"<p>" .
|
||||
sprintf(
|
||||
_t(
|
||||
'SiteTree.METANOTEPRIORITY',
|
||||
"Manually specify a Google Sitemaps priority for this page (%s)"
|
||||
),
|
||||
'<a href="https://www.google.com/webmasters/tools/docs/en/protocol.html#prioritydef">?</a>'
|
||||
) .
|
||||
"</p>"
|
||||
),
|
||||
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');
|
||||
?>
|
||||
|
88
code/GoogleSitemapDecorator.php
Normal file
88
code/GoogleSitemapDecorator.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Decorate the page object to provide google sitemaps with
|
||||
* additionally options and configuration.
|
||||
*
|
||||
* @package googlesitemaps
|
||||
*/
|
||||
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",
|
||||
"<p>" .
|
||||
sprintf(
|
||||
_t(
|
||||
'SiteTree.METANOTEPRIORITY',
|
||||
"Manually specify a Google Sitemaps priority for this page (%s)"
|
||||
),
|
||||
'<a href="https://www.google.com/webmasters/tools/docs/en/protocol.html#prioritydef">?</a>'
|
||||
) .
|
||||
"</p>"
|
||||
),
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user