From 2699956b23874fe0793806f88f3c5eb8f04c5c0b Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Fri, 20 Oct 2017 09:05:18 +1300 Subject: [PATCH] Vendorize and add namespaces --- _config/googlesitemaps.yml | 4 ++-- _config/routes.yml | 2 +- composer.json | 24 ++++++++++++++++--- docs/en/index.md | 15 +++++++++--- javascript/jquery.tablesorter.min.js | 4 ---- .../Control}/GoogleSitemapController.php | 23 ++++++++++++++---- .../Extensions}/GoogleSitemapExtension.php | 9 +++---- .../GoogleSitemapSiteTreeExtension.php | 5 ++-- {code => src}/GoogleSitemap.php | 22 ++++++++--------- .../Control}/GoogleSitemapController.ss | 2 +- .../GoogleSitemapController_sitemap.ss | 2 +- {templates => xsl}/xml-sitemap.xsl | 8 +------ {templates => xsl}/xml-sitemapindex.xsl | 9 +------ 13 files changed, 77 insertions(+), 52 deletions(-) delete mode 100644 javascript/jquery.tablesorter.min.js rename {code/controllers => src/Control}/GoogleSitemapController.php (79%) rename {code/extensions => src/Extensions}/GoogleSitemapExtension.php (95%) rename {code/extensions => src/Extensions}/GoogleSitemapSiteTreeExtension.php (98%) rename {code => src}/GoogleSitemap.php (95%) rename templates/{ => Wilr/GoogleSitemaps/Control}/GoogleSitemapController.ss (75%) rename templates/{ => Wilr/GoogleSitemaps/Control}/GoogleSitemapController_sitemap.ss (82%) rename {templates => xsl}/xml-sitemap.xsl (88%) rename {templates => xsl}/xml-sitemapindex.xsl (83%) diff --git a/_config/googlesitemaps.yml b/_config/googlesitemaps.yml index c7338db..88eba5b 100644 --- a/_config/googlesitemaps.yml +++ b/_config/googlesitemaps.yml @@ -1,7 +1,7 @@ --- Name: googlesitemaps --- -GoogleSitemap: +Wilr\GoogleSitemaps\GoogleSitemap: enabled: true objects_per_sitemap: 1000 google_notification_enabled: false @@ -12,4 +12,4 @@ Only: --- SilverStripe\CMS\Model\SiteTree: extensions: - - GoogleSitemapSiteTreeExtension + - Wilr\GoogleSitemaps\Extensions\GoogleSitemapSiteTreeExtension diff --git a/_config/routes.yml b/_config/routes.yml index 86e765b..01bf311 100644 --- a/_config/routes.yml +++ b/_config/routes.yml @@ -3,4 +3,4 @@ Name: googlesitemaproutes --- SilverStripe\Control\Director: rules: - 'sitemap.xml': 'GoogleSitemapController' + 'sitemap.xml': 'Wilr\GoogleSitemaps\Control\GoogleSitemapController' diff --git a/composer.json b/composer.json index b3a8f90..f1ebaf9 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "wilr/silverstripe-googlesitemaps", "description": "SilverStripe support for the Google Sitemaps XML, enabling Google and other search engines to see all urls on your site. This helps your SilverStripe website rank well in search engines, and to encourage the information on your site to be discovered quickly.", - "type": "silverstripe-module", + "type": "silverstripe-vendormodule", "keywords": ["silverstripe", "googlesitemaps", "seo"], "homepage": "https://github.com/wilr/silverstripe-googlesitemaps", "license": "BSD-3-Clause", @@ -12,7 +12,25 @@ "require": { "silverstripe/framework": "^4" }, + "require-dev": { + "phpunit/phpunit": "^5.7" + }, "extra": { - "installer-name": "googlesitemaps" - } + "branch-alias": { + "dev-master": "2.x-dev" + }, + "expose": [ + "images", + "xsl", + "css" + ] + }, + "autoload": { + "psr-4": { + "Wilr\\GoogleSitemaps\\": "src/", + "Wilr\\GoogleSitemaps\\Tests\\": "tests/" + } + }, + "prefer-stable": true, + "minimum-stability": "dev" } diff --git a/docs/en/index.md b/docs/en/index.md index 85a3aa1..f8483dc 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -34,7 +34,7 @@ config file `mysite/_config/googlesitemaps.yml` with the following outline: Name: customgooglesitemaps After: googlesitemaps --- - GoogleSitemap: + Wilr\GoogleSitemaps\GoogleSitemap: enabled: true objects_per_sitemap: 1000 google_notification_enabled: false @@ -49,7 +49,7 @@ editing the `google_notification_enabled` option to true Name: customgooglesitemaps After: googlesitemaps --- - GoogleSitemap: + Wilr\GoogleSitemaps\GoogleSitemap: enabled: true objects_per_sitemap: 1000 google_notification_enabled: true @@ -63,7 +63,7 @@ To ping Bing whenever your sitemap is updated, set `bing_notification_enabled` Name: customgooglesitemaps After: googlesitemaps --- - GoogleSitemap: + Wilr\GoogleSitemaps\GoogleSitemap: enabled: true bing_notification_enabled: true @@ -85,6 +85,9 @@ to show the DataObject by its ID. 1){arr=arr.concat(checkCellColSpan(table,headerArr,row++));}else{if(table.tHead.length==1||(cell.rowSpan>1||!r[row+1])){arr.push(cell);}}}return arr;};function checkHeaderMetadata(cell){if(($.metadata)&&($(cell).metadata().sorter===false)){return true;};return false;}function checkHeaderOptions(table,i){if((table.config.headers[i])&&(table.config.headers[i].sorter===false)){return true;};return false;}function checkHeaderOptionsSortingLocked(table,i){if((table.config.headers[i])&&(table.config.headers[i].lockedOrder))return table.config.headers[i].lockedOrder;return false;}function applyWidget(table){var c=table.config.widgets;var l=c.length;for(var i=0;i');$("tr:first td",table.tBodies[0]).each(function(){colgroup.append($('').css('width',$(this).width()));});$(table).prepend(colgroup);};}function updateHeaderSortCount(table,sortList){var c=table.config,l=sortList.length;for(var i=0;i b["+i+"]) ? 1 : 0));";};function makeSortTextDesc(i){return"((b["+i+"] < a["+i+"]) ? -1 : ((b["+i+"] > a["+i+"]) ? 1 : 0));";};function makeSortNumeric(i){return"a["+i+"]-b["+i+"];";};function makeSortNumericDesc(i){return"b["+i+"]-a["+i+"];";};function sortText(a,b){if(table.config.sortLocaleCompare)return a.localeCompare(b);return((ab)?1:0));};function sortTextDesc(a,b){if(table.config.sortLocaleCompare)return b.localeCompare(a);return((ba)?1:0));};function sortNumeric(a,b){return a-b;};function sortNumericDesc(a,b){return b-a;};function getCachedSortType(parsers,i){return parsers[i].type;};this.construct=function(settings){return this.each(function(){if(!this.tHead||!this.tBodies)return;var $this,$document,$headers,cache,config,shiftDown=0,sortOrder;this.config={};config=$.extend(this.config,$.tablesorter.defaults,settings);$this=$(this);$.data(this,"tablesorter",config);$headers=buildHeaders(this);this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);var sortCSS=[config.cssDesc,config.cssAsc];fixColumnWidth(this);$headers.click(function(e){var totalRows=($this[0].tBodies[0]&&$this[0].tBodies[0].rows.length)||0;if(!this.sortDisabled&&totalRows>0){$this.trigger("sortStart");var $cell=$(this);var i=this.column;this.order=this.count++%2;if(this.lockedOrder)this.order=this.lockedOrder;if(!e[config.sortMultiSortKey]){config.sortList=[];if(config.sortForce!=null){var a=config.sortForce;for(var j=0;j0){$this.trigger("sorton",[config.sortList]);}applyWidget(this);});};this.addParser=function(parser){var l=parsers.length,a=true;for(var i=0;igetSitemaps(); $this->extend('updateGoogleSitemaps', $sitemaps); - return array( + return $this->customise(new ArrayData([ 'Sitemaps' => $sitemaps - ); + ]))->renderWith(__CLASS__); } else { return new HTTPResponse('Page not found', 404); } @@ -86,4 +91,14 @@ class GoogleSitemapController extends Controller { return str_replace('-', '\\', $class); } + + public function StylesheetIndexPath() + { + return ModuleResourceLoader::resourceURL('wilr/silverstripe-googlesitemaps:xsl/xml-sitemapindex.xsl'); + } + + public function StylesheetPath() + { + return ModuleResourceLoader::resourceURL('wilr/silverstripe-googlesitemaps:xsl/xml-sitemap.xsl'); + } } diff --git a/code/extensions/GoogleSitemapExtension.php b/src/Extensions/GoogleSitemapExtension.php similarity index 95% rename from code/extensions/GoogleSitemapExtension.php rename to src/Extensions/GoogleSitemapExtension.php index f3f95a9..005d1bc 100644 --- a/code/extensions/GoogleSitemapExtension.php +++ b/src/Extensions/GoogleSitemapExtension.php @@ -1,14 +1,15 @@ * * @see http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=34609 - * - * @package googlesitemaps */ class GoogleSitemap { @@ -232,9 +232,9 @@ class GoogleSitemap } $output = new ArrayList(); - $count = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap'); - $filter = Config::inst()->get('GoogleSitemap', 'use_show_in_search'); - $redirector = Config::inst()->get('GoogleSitemap', 'exclude_redirector_pages'); + $count = Config::inst()->get(__CLASS__, 'objects_per_sitemap'); + $filter = Config::inst()->get(__CLASS__, 'use_show_in_search'); + $redirector = Config::inst()->get(__CLASS__, 'exclude_redirector_pages'); // todo migrate to extension hook or DI point for other modules to // modify state filters @@ -354,9 +354,9 @@ class GoogleSitemap */ public function getSitemaps() { - $countPerFile = Config::inst()->get('GoogleSitemap', 'objects_per_sitemap'); + $countPerFile = Config::inst()->get(__CLASS__, 'objects_per_sitemap'); $sitemaps = new ArrayList(); - $filter = Config::inst()->get('GoogleSitemap', 'use_show_in_search'); + $filter = Config::inst()->get(__CLASS__, 'use_show_in_search'); if (class_exists(SiteTree::class)) { // move to extension hook. At the moment moduleexists config hook @@ -457,7 +457,7 @@ class GoogleSitemap } // Don't ping if the site has disabled it, or if the site is in dev mode - $active = Config::inst()->get('GoogleSitemap', 'google_notification_enabled'); + $active = Config::inst()->get(__CLASS__, 'google_notification_enabled'); if (!$active || Director::isDev()) { return false; @@ -473,7 +473,7 @@ class GoogleSitemap ); // bing - $bing = Config::inst()->get('GoogleSitemap', 'bing_notification_enabled'); + $bing = Config::inst()->get(__CLASS__, 'bing_notification_enabled'); if($bing) { $bingResponse = self::send_ping( @@ -512,7 +512,7 @@ class GoogleSitemap */ public static function enabled() { - return (Config::inst()->get('GoogleSitemap', 'enabled')); + return (Config::inst()->get(__CLASS__, 'enabled')); } diff --git a/templates/GoogleSitemapController.ss b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController.ss similarity index 75% rename from templates/GoogleSitemapController.ss rename to templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController.ss index 694682a..69fd5fa 100644 --- a/templates/GoogleSitemapController.ss +++ b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController.ss @@ -1,5 +1,5 @@ - + <% loop Sitemaps %> {$AbsoluteBaseURL}sitemap.xml/sitemap/$ClassName/$Page.xml diff --git a/templates/GoogleSitemapController_sitemap.ss b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController_sitemap.ss similarity index 82% rename from templates/GoogleSitemapController_sitemap.ss rename to templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController_sitemap.ss index 106861a..ebcc2e2 100644 --- a/templates/GoogleSitemapController_sitemap.ss +++ b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController_sitemap.ss @@ -1,5 +1,5 @@ - + <% loop $Items %> diff --git a/templates/xml-sitemap.xsl b/xsl/xml-sitemap.xsl similarity index 88% rename from templates/xml-sitemap.xsl rename to xsl/xml-sitemap.xsl index 975ec26..4b95c55 100644 --- a/templates/xml-sitemap.xsl +++ b/xsl/xml-sitemap.xsl @@ -6,14 +6,8 @@ XML Sitemap - + - -
diff --git a/templates/xml-sitemapindex.xsl b/xsl/xml-sitemapindex.xsl similarity index 83% rename from templates/xml-sitemapindex.xsl rename to xsl/xml-sitemapindex.xsl index 160f394..c59b28f 100644 --- a/templates/xml-sitemapindex.xsl +++ b/xsl/xml-sitemapindex.xsl @@ -6,14 +6,7 @@ XML Sitemap - - - - +