From 8bbc14ee235134efd2eb525f9840566abfbadf7f Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Tue, 15 Jan 2013 22:29:59 +1300 Subject: [PATCH] API Implement sitemap.xml partitioning (Fixes #9) Misc upgrade of module code so that site map.xml provides a index site map file based on the standards. Moved configuration vars to the Config API. Considering how large a change this is, I've branched a 1.0 release off in github. --- .gitignore | 1 + _config.php | 2 +- _config/googlesitemaps.yml | 8 + _config/routes.yml | 2 +- code/GoogleSitemap.php | 294 ++++++++++-------- code/GoogleSitemapDecorator.php | 143 --------- code/controllers/GoogleSitemapController.php | 68 ++++ code/extensions/GoogleSitemapExtension.php | 116 +++++++ .../GoogleSitemapSiteTreeExtension.php | 90 ++++++ docs/en/index.md | 66 ++-- lang/en.yml | 2 +- templates/GoogleSitemapController.ss | 7 + ....ss => GoogleSitemapController_sitemap.ss} | 2 +- templates/xml-sitemap.xsl | 10 +- tests/GoogleSitemapTest.php | 127 +++++--- tests/GoogleSitemapTest.yml | 2 + 16 files changed, 591 insertions(+), 349 deletions(-) create mode 100644 .gitignore create mode 100644 _config/googlesitemaps.yml delete mode 100644 code/GoogleSitemapDecorator.php create mode 100644 code/controllers/GoogleSitemapController.php create mode 100644 code/extensions/GoogleSitemapExtension.php create mode 100644 code/extensions/GoogleSitemapSiteTreeExtension.php create mode 100644 templates/GoogleSitemapController.ss rename templates/{GoogleSitemap.ss => GoogleSitemapController_sitemap.ss} (83%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/_config.php b/_config.php index 4ded1c0..ee3c4b1 100644 --- a/_config.php +++ b/_config.php @@ -2,7 +2,7 @@ // add the extension to pages if (class_exists('SiteTree')) { - Object::add_extension('SiteTree', 'GoogleSitemapSiteTreeDecorator'); + Object::add_extension('SiteTree', 'GoogleSitemapSiteTreeExtension'); } // if you need to add this to DataObjects include the following in diff --git a/_config/googlesitemaps.yml b/_config/googlesitemaps.yml new file mode 100644 index 0000000..676a441 --- /dev/null +++ b/_config/googlesitemaps.yml @@ -0,0 +1,8 @@ +--- +Name: googlesitemaps +--- +GoogleSitemap: + enabled: true + objects_per_sitemap: 1000 + google_notification_enabled: false + use_show_in_search: true \ No newline at end of file diff --git a/_config/routes.yml b/_config/routes.yml index 08cb42c..63e07b3 100644 --- a/_config/routes.yml +++ b/_config/routes.yml @@ -3,4 +3,4 @@ Name: googlesitemaproutes --- Director: rules: - 'sitemap.xml': 'GoogleSitemap' \ No newline at end of file + 'sitemap.xml': 'GoogleSitemapController' \ No newline at end of file diff --git a/code/GoogleSitemap.php b/code/GoogleSitemap.php index 1935019..b5d366b 100644 --- a/code/GoogleSitemap.php +++ b/code/GoogleSitemap.php @@ -1,13 +1,14 @@ ($changeFreq) ? $changeFreq : 'monthly', @@ -103,96 +82,150 @@ class GoogleSitemap extends Controller { } /** - * Clears registered dataobjects. Useful for unit tests. + * Clears registered {@link DataObjects}. Useful for unit tests. */ public static function clear_registered_dataobjects() { self::$dataobjects = array(); } - /** - * Returns a list containing each viewable {@link DataObject} instance of - * the registered class names. - * - * @return ArrayList - */ - protected function getDataObjects() { - $output = new ArrayList(); - - foreach(self::$dataobjects as $class => $config) { - $instances = new DataList($class); - - if($instances) { - foreach($instances as $obj) { - if($obj->canView()) { - $obj->ChangeFreq = $config['frequency']; - - if(!isset($obj->Priority)) { - $obj->Priority = $config['priority']; - } - - $output->push($obj); - } - } - } - } - - return $output; - } - - /** - * Returns a list containing each viewable {@link SiteTree} instance. If - * you wish to exclude a particular class from the sitemap, simply set - * the priority of the class to -1. - * - * @return ArrayList - */ - protected function getPages() { - if(!class_exists('SiteTree')) return new ArrayList(); - - $filter = (self::$use_show_in_search) ? "\"ShowInSearch\" = 1" : ""; - $pages = Versioned::get_by_stage('SiteTree', 'Live', $filter); - $output = new ArrayList(); - - if($pages) { - foreach($pages as $page) { - $pageHttp = parse_url($page->AbsoluteLink(), PHP_URL_HOST); - $hostHttp = parse_url('http://' . $_SERVER['HTTP_HOST'], PHP_URL_HOST); - - if(($pageHttp == $hostHttp) && !($page instanceof ErrorPage)) { - if($page->canView() && (!isset($page->Priority) || $page->Priority > 0)) { - $output->push($page); - } - } - } - } - - return $output; - } - /** * Constructs the list of data to include in the rendered sitemap. Links * can include pages from the website, dataobjects (such as forum posts) * as well as custom registered paths. * + * @param string + * @param int + * * @return ArrayList */ - public function Items() { + public static function get_items($class, $page = 1) { $output = new ArrayList(); - $output->merge($this->getPages()); - $output->merge($this->getDataObjects()); + $count = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap'); + $filter = Config::inst()->get('GoogleSitemap', 'use_show_in_search'); + + if($class == "SiteTree") { + $filter = ($filter) ? "\"ShowInSearch\" = 1" : ""; + $instances = Versioned::get_by_stage('SiteTree', 'Live', $filter); + } + else { + $instances = new DataList($class); + } + + $instances = $instances->limit( + $count, + ($page - 1) * $count + ); + + if($instances) { + foreach($instances as $obj) { + if($obj->canIncludeInGoogleSitemap()) { + $output->push($obj); + } + } + } - $this->extend('updateItems', $output); - return $output; } /** - * Notifies Google about changes to your sitemap. This behavior is disabled - * by default, enable with: + * Returns the string frequency of edits for a particular dataobject class. + * + * Frequency for {@link SiteTree} objects can be determined from the version + * history. * - * - * GoogleSitemap::enable_google_notificaton(); - * + * @param string + * + * @return string + */ + public static function get_frequency_for_class($class) { + foreach(self::$dataobjects as $type => $config) { + if($class == $type) { + return $config['frequency']; + } + } + } + + /** + * Returns the default priority of edits for a particular dataobject class. + * + * @param string + * + * @return float + */ + public static function get_priority_for_class($class) { + foreach(self::$dataobjects as $type => $config) { + if($class == $type) { + return $config['priority']; + } + } + + return 0.5; + } + + /** + * The google site map is broken down into multiple smaller files to + * prevent overbearing a server. By default separate {@link DataObject} + * records are keep in separate files and broken down into chunks. + * + * @return ArrayList + */ + public static function get_sitemaps() { + $countPerFile = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap'); + $sitemaps = new ArrayList(); + $filter = Config::inst()->get('GoogleSitemap', 'use_show_in_search'); + + if(class_exists('SiteTree')) { + $filter = ($filter) ? "\"ShowInSearch\" = 1" : ""; + $instances = Versioned::get_by_stage('SiteTree', 'Live', $filter); + $count = $instances->count(); + + $neededForPage = ceil($count / $countPerFile); + + for($i = 1; $i <= $neededForPage; $i++) { + $sliced = $instances + ->limit($countPerFile, ($i - 1) * $countPerFile) + ->last(); + + $lastModified = ($sliced) ? $sliced->dbObject('LastEdited')->Format('Y-m-d') : date('Y-m-d'); + + $sitemaps->push(new ArrayData(array( + 'ClassName' => 'SiteTree', + 'LastModified' => $lastModified, + 'Page' => $i + ))); + } + } + + if(self::$dataobjects) { + foreach(self::$dataobjects as $class => $config) { + $list = new DataList($class); + $list = $list->sort('LastEdited ASC'); + + $neededForClass = ceil($list->count() / $countPerFile); + + for($i = 1; $i <= $neededForClass; $i++) { + // determine the last modified date for this slice + $sliced = $list + ->limit($countPerFile, ($i - 1) * $countPerFile) + ->last(); + + $lastModified = ($sliced) ? $sliced->dbObject('LastEdited')->Format('Y-m-d') : date('Y-m-d'); + + $sitemaps->push(new ArrayData(array( + 'ClassName' => $class, + 'Page' => $i, + 'LastModified' => $lastModified + ))); + } + } + } + + return $sitemaps; + } + + /** + * Notifies Google about changes to your sitemap. This behavior is disabled + * by default, to enable, read the documentation provided in the docs folder. * * After notifications have been enabled, every publish / unpublish of a page. * will notify Google of the update. @@ -203,10 +236,14 @@ class GoogleSitemap extends Controller { * @return string Response text */ public static function ping() { - if(!self::$enabled) return false; + if(!self::$enabled) { + return false; + } // Don't ping if the site has disabled it, or if the site is in dev mode - if(!GoogleSitemap::$google_notification_enabled || Director::isDev()) { + $active = Config::inst()->get('GoogleSitemap', 'google_notification_enabled'); + + if(!$active || Director::isDev()) { return; } @@ -216,7 +253,7 @@ class GoogleSitemap extends Controller { )); $response = self::send_ping( - "www.google.com", "/webmasters/sitemaps/ping", sprintf("sitemap=%s", $location) + "www.google.com", "/webmasters/sitemaps/ping", sprintf("sitemap=%s", $location) ); return $response; @@ -248,51 +285,60 @@ class GoogleSitemap extends Controller { * @return void */ public static function enable_google_notification() { - self::$google_notification_enabled = true; + Deprecation::notice('1.1', 'GoogleSitemap::enable() is deprecated. Please use Config API instead. See documentation.'); + + Config::inst()->remove('GoogleSitemap', 'google_notification_enabled'); + Config::inst()->update('GoogleSitemap', 'google_notification_enabled', true); } /** * Disables pings to google when the sitemap changes. * + * @deprecated 1.1 * @return void */ public static function disable_google_notification() { - self::$google_notification_enabled = false; - } - - /** - * Default controller handler for the sitemap.xml file - */ - public function index($url) { - if(self::$enabled) { - SSViewer::set_source_file_comments(false); - - $this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"'); + Deprecation::notice('1.1', 'GoogleSitemap::enable() is deprecated. Please use Config API instead. See documentation.'); - // But we want to still render. - return array(); - } else { - return new SS_HTTPResponse('Page not found', 404); - } + Config::inst()->remove('GoogleSitemap', 'google_notification_enabled'); + Config::inst()->update('GoogleSitemap', 'google_notification_enabled', false); } + /** * Enable Google Sitemap support. Requests to the sitemap.xml route will * result in an XML sitemap being provided. * + * @deprecated 1.1 * @return void */ public static function enable() { - self::$enabled = true; + Deprecation::notice('1.1', 'GoogleSitemap::enable() is deprecated. Please use Config API instead. See documentation.'); + + Config::inst()->remove('GoogleSitemap', 'enabled'); + Config::inst()->update('GoogleSitemap', 'enabled', true); + } + + /** + * Is GoogleSitemap enabled? + * + * @return boolean + */ + public static function enabled() { + return (Config::inst()->get('GoogleSitemap', 'enabled', Config::INHERITED)); } /** * Disable Google Sitemap support. Any requests to the sitemap.xml route * will produce a 404 response. * + * @deprecated 1,1 * @return void */ public static function disable() { - self::$enabled = false; + Deprecation::notice('1.1', 'GoogleSitemap::disable() is deprecated. Please use Config API instead. See documentation.'); + + Config::inst()->remove('GoogleSitemap', 'enabled'); + Config::inst()->update('GoogleSitemap', 'enabled', false); } -} +} \ No newline at end of file diff --git a/code/GoogleSitemapDecorator.php b/code/GoogleSitemapDecorator.php deleted file mode 100644 index 42527e4..0000000 --- a/code/GoogleSitemapDecorator.php +++ /dev/null @@ -1,143 +0,0 @@ - "Varchar(5)" - ); - - /** - * @param FieldList - */ - public function updateSettingsFields(&$fields) { - $prorities = 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.Settings'); - - $message = "

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

"; - - $tabset->push(new Tab('GoogleSitemap', _t('SiteTree.TABGOOGLESITEMAP', 'Google Sitemap'), - new LiteralField("GoogleSitemapIntro", $message), - new DropdownField("Priority", $this->owner->fieldLabel('Priority'), $prorities) - )); - } - - public function updateFieldLabels(&$labels) { - parent::updateFieldLabels($labels); - - $labels['Priority'] = _t('SiteTree.METAPAGEPRIO', "Page Priority"); - } - - /** - * @return void - */ - public function onAfterPublish() { - GoogleSitemap::ping(); - } - - /** - * @return void - */ - public 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. - * - * @return float - */ - public 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 -1; - } - else { - $priority = abs($this->owner->getField('Priority')); - - return (is_float($priority) && $priority <= 1.0) ? $priority : 0.5; - } - } - - /** - * Returns a pages change frequency calculated by pages age and number of - * versions. Google expects always, hourly, daily, weekly, monthly, yearly - * or never as values. - * - * @see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668&topic=8476&ctx=topic - * - * @return SS_Datetime - */ - public function getChangeFrequency() { - $date = date('Y-m-d H:i:s'); - $prop = $this->owner->toMap(); - - $created = new SS_Datetime(); - $created->value = (isset($prop['Created'])) ? $prop['Created'] : $date; - - $now = new SS_Datetime(); - $now->value = $date; - - $versions = (isset($prop['Version'])) ? $prop['Version'] : 1; - $timediff = $now->format('U') - $created->format('U'); - - // Check how many revisions have been made over the lifetime of the - // Page for a rough estimate of it's changing frequency. - $period = $timediff / ($versions + 1); - - if ($period > 60 * 60 * 24 * 365) { - $freq = 'yearly'; - } elseif ($period > 60 * 60 * 24 * 30) { - $freq = 'monthly'; - } elseif ($period > 60 * 60 * 24 * 7) { - $freq = 'weekly'; - } elseif ($period > 60 * 60 * 24) { - $freq = 'daily'; - } elseif ($period > 60 * 60) { - $freq = 'hourly'; - } else { - $freq = 'always'; - } - - return $freq; - } -} diff --git a/code/controllers/GoogleSitemapController.php b/code/controllers/GoogleSitemapController.php new file mode 100644 index 0000000..5143ba6 --- /dev/null +++ b/code/controllers/GoogleSitemapController.php @@ -0,0 +1,68 @@ + + * http://site.com/sitemap.xml/ + * http://site.com/sitemap.xml/sitemap/$ClassName-$Page.xml + * + * + * @package googlesitemaps + */ +class GoogleSitemapController extends Controller { + + /** + * @var array + */ + public static $allowed_actions = array( + 'index', + 'sitemap' + ); + + /** + * Default controller action for the sitemap.xml file. Renders a index + * file containing a list of links to sub sitemaps containing the data. + * + * @return mixed + */ + public function index($url) { + if(GoogleSitemap::enabled()) { + SSViewer::set_source_file_comments(false); + + $this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"'); + + return array( + 'Sitemaps' => GoogleSitemap::get_sitemaps() + ); + } else { + return new SS_HTTPResponse('Page not found', 404); + } + } + + /** + * Specific controller action for displaying a particular list of links + * for a class + * + * @return mixed + */ + public function sitemap() { + $class = $this->request->param('ID'); + $page = $this->request->param('OtherID'); + + if(GoogleSitemap::enabled() && $class && $page) { + SSViewer::set_source_file_comments(false); + + $this->getResponse()->addHeader('Content-Type', 'application/xml; charset="utf-8"'); + + // But we want to still render. + return array( + 'Items' => GoogleSitemap::get_items($class, $page) + ); + } else { + return new SS_HTTPResponse('Page not found', 404); + } + } +} \ No newline at end of file diff --git a/code/extensions/GoogleSitemapExtension.php b/code/extensions/GoogleSitemapExtension.php new file mode 100644 index 0000000..1bf418f --- /dev/null +++ b/code/extensions/GoogleSitemapExtension.php @@ -0,0 +1,116 @@ +AbsoluteLink(), PHP_URL_HOST); + $hostHttp = parse_url('http://' . $_SERVER['HTTP_HOST'], PHP_URL_HOST); + + if($objHttp != $hostHttp) { + $can = false; + } + } + + if($can) { + $can = $this->owner->canView(); + } + + if($can) { + $can = $this->owner->getGooglePriority(); + } + + $this->owner->extend('alterCanIncludeInGoogleSitemap', $can); + + return $can; + } + + + /** + * @return void + */ + public function onAfterPublish() { + GoogleSitemap::ping(); + } + + /** + * @return void + */ + public 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. + * + * @return mixed + */ + public function getGooglePriority() { + $field = $this->owner->hasField('Priority'); + + if(isset($this->Priority) || ($field && $this->Priority = $this->owner->getField('Priority'))) { + return ($this->Priority < 0) ? false : $this->Priority; + } + + return GoogleSitemap::get_priority_for_class($this->owner->class); + } + + /** + * Returns a pages change frequency calculated by pages age and number of + * versions. Google expects always, hourly, daily, weekly, monthly, yearly + * or never as values. + * + * @see http://support.google.com/webmasters/bin/answer.py?hl=en&answer=183668&topic=8476&ctx=topic + * + * @return SS_Datetime + */ + public function getChangeFrequency() { + if($freq = GoogleSitemap::get_frequency_for_class($this->owner->class)) { + return $freq; + } + + $date = date('Y-m-d H:i:s'); + + $created = new SS_Datetime(); + $created->value = ($this->owner->Created) ? $this->owner->Created : $date; + + $now = new SS_Datetime(); + $now->value = $date; + + $versions = ($this->owner->Version) ? $this->owner->Version : 1; + $timediff = $now->format('U') - $created->format('U'); + + // Check how many revisions have been made over the lifetime of the + // Page for a rough estimate of it's changing frequency. + $period = $timediff / ($versions + 1); + + if ($period > 60 * 60 * 24 * 365) { + $freq = 'yearly'; + } elseif ($period > 60 * 60 * 24 * 30) { + $freq = 'monthly'; + } elseif ($period > 60 * 60 * 24 * 7) { + $freq = 'weekly'; + } elseif ($period > 60 * 60 * 24) { + $freq = 'daily'; + } elseif ($period > 60 * 60) { + $freq = 'hourly'; + } else { + $freq = 'always'; + } + + return $freq; + } +} diff --git a/code/extensions/GoogleSitemapSiteTreeExtension.php b/code/extensions/GoogleSitemapSiteTreeExtension.php new file mode 100644 index 0000000..8753aa8 --- /dev/null +++ b/code/extensions/GoogleSitemapSiteTreeExtension.php @@ -0,0 +1,90 @@ + "Varchar(5)" + ); + + /** + * @param FieldList + */ + public function updateSettingsFields(&$fields) { + $prorities = array( + '-1' => _t('GoogleSitemaps.PRIORITYNOTINDEXED', "Not indexed"), + '1.0' => '1 - ' . _t('GoogleSitemaps.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('GoogleSitemaps.PRIORITYLEASTIMPORTANT', "Least important") + ); + + $tabset = $fields->findOrMakeTab('Root.Settings'); + + $message = "

"; + $message .= sprintf(_t('GoogleSitemaps.METANOTEPRIORITY', "Manually specify a Google Sitemaps priority for this page (%s)"), + '?' + ); + $message .= "

"; + + $tabset->push(new Tab('GoogleSitemap', _t('GoogleSitemaps.TABGOOGLESITEMAP', 'Google Sitemap'), + new LiteralField("GoogleSitemapIntro", $message), + $priority = new DropdownField("Priority", $this->owner->fieldLabel('Priority'), $prorities, $this->owner->Priority) + )); + + $priority->setEmptyString(_t('GoogleSitemaps.PRIORITYAUTOSET', 'Auto-set based on page depth')); + } + + /** + * @param FieldList + * + * @return void + */ + public function updateFieldLabels(&$labels) { + parent::updateFieldLabels($labels); + + $labels['Priority'] = _t('GoogleSitemaps.METAPAGEPRIO', "Page Priority"); + } + + /** + * @return boolean + */ + public function canIncludeInGoogleSitemap() { + $result = parent::canIncludeInGoogleSitemap(); + $result = ($this instanceof ErrorPage) ? false : $result; + + return $result; + } + + /** + * @return mixed + */ + public function getGooglePriority() { + $priority = $this->owner->getField('Priority'); + + if(!$priority) { + $parentStack = $this->owner->parentStack(); + $numParents = is_array($parentStack) ? count($parentStack) - 1 : 0; + + $num = max(0.1, 1.0 - ($numParents / 10)); + $result = str_replace(",", ".", $num); + + return $result; + } else if ($priority == -1) { + return false; + } else { + return (is_float($priority) && $priority <= 1.0) ? $priority : 0.5; + } + } +} diff --git a/docs/en/index.md b/docs/en/index.md index c296ceb..3a7fca0 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -25,10 +25,35 @@ Importance drops from 1.0, to 0.9, to 0.8, and so on, until 0.1 is reached). In the CMS, in the Settings tab for each page, you can set the importance manually, including requesting to have the page excluded from the sitemap. +## Configuration -## Setup automatic pinging +Most module configuration is done via the SilverStripe Config API. Create a new +config file `mysite/_config/googlesitemaps.yml` with the following outline: - GoogleSitemap::enable_google_notification(); + --- + Name: customgooglesitemaps + After: googlesitemaps + --- + GoogleSitemap: + enabled: true + objects_per_sitemap: 1000 + google_notification_enabled: false + use_show_in_search: true + +You can now alter any of those properties to set your needs. A popular option +is to turn on automatic pinging so that Google is notified of any updates to +your page. You can set this in the file we created in the last paragraph by +editing the `google_notification_enabled` option to true + + --- + Name: customgooglesitemaps + After: googlesitemaps + --- + GoogleSitemap: + enabled: true + objects_per_sitemap: 1000 + google_notification_enabled: true + use_show_in_search: true ### Including DataObjects @@ -78,39 +103,4 @@ instead of the previous code you would write: See the following blog post for more information: -http://www.silvercart.org/blog/dataobjects-and-googlesitemaps/ - -### Including other routes - -If your project has routes that are not stored in the database such as custom -controllers and actions, the module provides an extension hook called -*updateItems* which allows anyone to write extensions to alter the provided -items. - -Here's an example of registering the MyController/about URL which is defined as -an action. First we create our new extension and define the links we wish to -add to the $items list. - - push(new ArrayData(array( - 'AbsoluteLink' => Controller::join_links($base, $route) - ))); - } - } - } - -Before we can see the updates we first must add this extension to our built in -class. Inside your mysite/_config.php file add the following: - - Object::add_extension('GoogleSitemap', 'GoogleSitemapExtension'); \ No newline at end of file +http://www.silvercart.org/blog/dataobjects-and-googlesitemaps/ \ No newline at end of file diff --git a/lang/en.yml b/lang/en.yml index e076016..70239f2 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -1,5 +1,5 @@ en: - SiteTree: + GoogleSitemaps: METANOTEPRIORITY: 'Manually specify a Google Sitemaps priority for this page (%s)' METAPAGEPRIO: 'Page Priority' PRIORITYAUTOSET: 'Auto-set based on page depth' diff --git a/templates/GoogleSitemapController.ss b/templates/GoogleSitemapController.ss new file mode 100644 index 0000000..aac5ae2 --- /dev/null +++ b/templates/GoogleSitemapController.ss @@ -0,0 +1,7 @@ + +<% loop Sitemaps %> + + {$BaseHref}sitemap.xml/sitemap/$ClassName/$Page.xml + <% if LastModified %>$LastModified<% end_if %> + <% end_loop %> + \ No newline at end of file diff --git a/templates/GoogleSitemap.ss b/templates/GoogleSitemapController_sitemap.ss similarity index 83% rename from templates/GoogleSitemap.ss rename to templates/GoogleSitemapController_sitemap.ss index ee205a1..fe2c33a 100644 --- a/templates/GoogleSitemap.ss +++ b/templates/GoogleSitemapController_sitemap.ss @@ -6,7 +6,7 @@ $AbsoluteLink <% if $LastEdited %>$LastEdited.Format(c)<% end_if %> <% if $ChangeFrequency %>$ChangeFrequency<% end_if %> - <% if $Priority %>$Priority<% end_if %> + <% if $GooglePriority %>$GooglePriority<% end_if %> <% end_loop %> \ No newline at end of file diff --git a/templates/xml-sitemap.xsl b/templates/xml-sitemap.xsl index e9fd2c6..c1d2c3a 100644 --- a/templates/xml-sitemap.xsl +++ b/templates/xml-sitemap.xsl @@ -6,9 +6,9 @@ XML Sitemap - + - +