From 896dab110380d01cb330769dd043243b67872a3e Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Mon, 31 Dec 2018 16:18:50 +0100 Subject: [PATCH 01/10] updated to ss 4 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 68ceb4b..44b7c89 100644 --- a/composer.json +++ b/composer.json @@ -5,17 +5,17 @@ "keywords": ["silverstripe", "news"], "authors": [ { - "name": "Marcus Nyeholt" + "name": "Marcus Nyeholt" } ], "require": { - "silverstripe/framework": "^3.1.0", - "silverstripe/cms": "^3.1.0" + "silverstripe/framework": "^4.1.0", + "silverstripe/cms": "^4.1.0" }, "extra": { "branch-alias": { "dev-master": "1.2.x-dev" - }, + }, "installer-name": "news" }, "minimum-stability": "dev" From 89c68cb4d6382f2fbcc6d885f044b64a6c68aefb Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Mon, 31 Dec 2018 16:43:43 +0100 Subject: [PATCH 02/10] moved to src folder --- composer.json | 11 +++++++-- {code => src}/pages/NewsArticle.php | 32 +++++++++++++----------- {code => src}/pages/NewsHolder.php | 38 ++++++++++++++++------------- 3 files changed, 48 insertions(+), 33 deletions(-) rename {code => src}/pages/NewsArticle.php (97%) rename {code => src}/pages/NewsHolder.php (98%) diff --git a/composer.json b/composer.json index 44b7c89..91687a7 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,18 @@ "silverstripe/framework": "^4.1.0", "silverstripe/cms": "^4.1.0" }, + "autoload": { + "psr-4": { + "Symbiote\\News\\": "src/" + } + }, "extra": { "branch-alias": { - "dev-master": "1.2.x-dev" + "dev-master": "2.x-dev" }, - "installer-name": "news" + "expose": [ + "images" + ] }, "minimum-stability": "dev" } diff --git a/code/pages/NewsArticle.php b/src/pages/NewsArticle.php similarity index 97% rename from code/pages/NewsArticle.php rename to src/pages/NewsArticle.php index c0e769f..0060a26 100644 --- a/code/pages/NewsArticle.php +++ b/src/pages/NewsArticle.php @@ -1,12 +1,16 @@ * @license BSD License http://silverstripe.org/bsd-license/ */ -class NewsArticle extends Page { +class NewsArticle extends SiteTree { private static $icon = 'news/images/newspaper'; private static $db = array( @@ -18,7 +22,7 @@ class NewsArticle extends Page { ); /** * The InternalFile is used when the news article is mostly contained in a file based item - - * if this is set, then the URL to the item is returned in the call to "Link" for this asset. + * if this is set, then the URL to the item is returned in the call to "Link" for this asset. * * @var array */ @@ -53,7 +57,7 @@ public function getCMSFields() { $summary->addExtraClass('stacked'); $this->extend('updateArticleCMSFields', $fields); - + return $fields; } @@ -63,13 +67,13 @@ public function getCMSFields() { */ public function onBeforeWrite() { parent::onBeforeWrite(); - + // dummy initial date if (!$this->OriginalPublishedDate) { // @TODO Fix this to be correctly localized!! $this->OriginalPublishedDate = date('Y-m-d 12:00:00'); } - + $parent = $this->Parent(); // just in case we've been moved, update our section @@ -98,14 +102,14 @@ public function onBeforePublish() { // go through all parents that are news holders and publish them if they haven't been $this->publishSection(); } - + public function onAfterPublish() { // $this->publishSection(); } /** * Ensure's the section is published. - * + * * We need to do it both before and after publish because of some quirks with * folders not existing on one but existing on the other depending on the order of * writing the objects @@ -164,7 +168,7 @@ public function HasExternalLink() { } /** - * Link to the news article. If it has an external URL set, or a file, link to that instead. + * Link to the news article. If it has an external URL set, or a file, link to that instead. * * @param String $action * @return String @@ -180,8 +184,8 @@ public function Link($action='') { } return parent::Link($action); } - - + + /** * Pages to update cache file for static publisher * @@ -190,19 +194,19 @@ public function Link($action='') { public function pagesAffectedByChanges() { $parent = $this->Parent(); $urls = array($this->Link()); - + // add all parent (holders) while($parent && $parent->ParentID > -1 && $parent instanceof NewsHolder) { $urls[] = $parent->Link(); $parent = $parent->Parent(); } - + $this->extend('updatePagesAffectedByChanges', $urls); - + return $urls; } } class NewsArticle_Controller extends Page_Controller { -} \ No newline at end of file +} diff --git a/code/pages/NewsHolder.php b/src/pages/NewsHolder.php similarity index 98% rename from code/pages/NewsHolder.php rename to src/pages/NewsHolder.php index 75ca2e7..f347eb9 100644 --- a/code/pages/NewsHolder.php +++ b/src/pages/NewsHolder.php @@ -1,31 +1,35 @@ * @license BSD License http://silverstripe.org/bsd-license/ */ -class NewsHolder extends Page { +class NewsHolder extends SiteTree { private static $db = array( 'AutoFiling' => 'Boolean', // whether articles created in this holder // automatically file into subfolders 'FilingMode' => 'Varchar', // Date, Month, Year 'FileBy' => "Varchar", - + 'OrderBy' => "Varchar", 'OrderDir' => "Varchar", - + 'PrimaryNewsSection' => 'Boolean', // whether this holder should be regarded as a primary // news section (some are secondary and merely categorisation tools) ); - + private static $defaults = array( - 'AutoFiling' => false, + 'AutoFiling' => false, 'PrimaryNewsSection' => true ); - + private static $icon = 'news/images/newsholder'; private static $allowed_children = array( @@ -44,7 +48,7 @@ class NewsHolder extends Page { * * We need to do this because using something like <% if Articles(2).HasMore %> doesn't work, as * the .HasMore isn't parsed correctly... - * + * * @var int */ protected $numberToDisplay = 10; @@ -69,22 +73,22 @@ public function getCMSFields() { $fields->addFieldToTab('Root.Main', new DropdownField('OrderBy', _t('NewsHolder.ORDER_BY', 'Order by'), array('OriginalPublishedDate' => 'Published', 'Created' => 'Created')), 'Content'); $fields->addFieldToTab('Root.Main', new DropdownField('OrderDir', _t('NewsHolder.ORDER_DIR', 'Order direction'), array('DESC' => 'Descending date', 'ASC' => 'Ascending date')), 'Content'); - + $this->extend('updateNewsHolderCMSFields', $fields); return $fields; } - + public function onBeforeWrite() { parent::onBeforeWrite(); - + // set the filing mode, now that it's being obsolete if ($this->AutoFiling && !$this->FilingMode) { $this->FilingMode = 'day'; $this->AutoFiling = false; } } - + /** * Returns a list of articles within this news holder. * @@ -161,16 +165,16 @@ public function SubSections($allChildren=true) { return $subs; } - + /** * Maintain API compatibility with NewsArticle - * + * * @return NewsHolder */ public function Section() { return $this->findSection(); } - + /** * Find the section this news article is currently in, based on ancestor pages */ @@ -216,7 +220,7 @@ public function getPartitionedHolderForArticle($article) { if (!$monthFolder) { throw new Exception("Failed retrieving folder"); } - + if ($this->FilingMode == 'month') { return $monthFolder; } @@ -254,7 +258,7 @@ public function dateFolder($name, $publish=false) { } return $child; } - + /** * Pages to update cache file for static publisher * @@ -305,4 +309,4 @@ function Rss() { $this->response->addHeader('Content-Type', 'application/rss+xml'); return $rss->outputToBrowser(); } -} \ No newline at end of file +} From b33fb200a40e905a923088c4f2ac5fc845d6e1d5 Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Mon, 31 Dec 2018 16:53:18 +0100 Subject: [PATCH 03/10] seperated controller from page --- composer.json | 1 + src/pages/NewsArticle.php | 3 --- src/pages/NewsHolder.php | 17 ----------------- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/composer.json b/composer.json index 91687a7..adc4eaf 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "branch-alias": { "dev-master": "2.x-dev" }, + "installer-name": "news", "expose": [ "images" ] diff --git a/src/pages/NewsArticle.php b/src/pages/NewsArticle.php index 0060a26..2335fcf 100644 --- a/src/pages/NewsArticle.php +++ b/src/pages/NewsArticle.php @@ -207,6 +207,3 @@ public function pagesAffectedByChanges() { } } - -class NewsArticle_Controller extends Page_Controller { -} diff --git a/src/pages/NewsHolder.php b/src/pages/NewsHolder.php index f347eb9..c91c3fc 100644 --- a/src/pages/NewsHolder.php +++ b/src/pages/NewsHolder.php @@ -293,20 +293,3 @@ public function TotalChildArticles($number = null) { return $entries; } } - -class NewsHolder_Controller extends Page_Controller { - public static $allowed_actions = array('Rss'); - - public function init() { - RSSFeed::linkToFeed($this->owner->Link() . "rss", _t('News.RSSLINK',"RSS feed for the News")); - parent::init(); - } - - function Rss() { - $parent = $this->data()->ID; - $objects = NewsArticle::get()->filter('ParentID', $parent)->sort('LastEdited DESC')->limit(10); - $rss = new RSSFeed($objects, $this->data()->Link(), _t('News.RSSTITLE',"10 most recent news"), "", "Title", "Content"); - $this->response->addHeader('Content-Type', 'application/rss+xml'); - return $rss->outputToBrowser(); - } -} From cda7c0c93d195c7c14f000b1098a1ae0281a4361 Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Mon, 31 Dec 2018 16:56:51 +0100 Subject: [PATCH 04/10] forgotten files --- src/pages/NewsArticleController.php | 8 ++++++++ src/pages/NewsHolderController.php | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/pages/NewsArticleController.php create mode 100644 src/pages/NewsHolderController.php diff --git a/src/pages/NewsArticleController.php b/src/pages/NewsArticleController.php new file mode 100644 index 0000000..908bba3 --- /dev/null +++ b/src/pages/NewsArticleController.php @@ -0,0 +1,8 @@ +owner->Link() . "rss", _t('News.RSSLINK',"RSS feed for the News")); + parent::init(); + } + + function Rss() { + $parent = $this->data()->ID; + $objects = NewsArticle::get()->filter('ParentID', $parent)->sort('LastEdited DESC')->limit(10); + $rss = new RSSFeed($objects, $this->data()->Link(), _t('News.RSSTITLE',"10 most recent news"), "", "Title", "Content"); + $this->response->addHeader('Content-Type', 'application/rss+xml'); + return $rss->outputToBrowser(); + } +} From b52b946233759891f56c57f82d5f7cd7d75f49a2 Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Mon, 31 Dec 2018 18:41:34 +0100 Subject: [PATCH 05/10] namespaces --- src/{pages => }/NewsArticle.php | 26 ++++++++++++------- src/NewsArticleController.php | 11 ++++++++ src/{pages => }/NewsHolder.php | 26 ++++++++++++------- src/{pages => }/NewsHolderController.php | 4 +-- src/pages/NewsArticleController.php | 8 ------ .../News}/Includes/NewsListItem.ss | 0 .../{ => Symbiote/News}/Layout/NewsArticle.ss | 0 .../{ => Symbiote/News}/Layout/NewsHolder.ss | 0 8 files changed, 46 insertions(+), 29 deletions(-) rename src/{pages => }/NewsArticle.php (88%) create mode 100644 src/NewsArticleController.php rename src/{pages => }/NewsHolder.php (90%) rename src/{pages => }/NewsHolderController.php (88%) delete mode 100644 src/pages/NewsArticleController.php rename templates/{ => Symbiote/News}/Includes/NewsListItem.ss (100%) rename templates/{ => Symbiote/News}/Layout/NewsArticle.ss (100%) rename templates/{ => Symbiote/News}/Layout/NewsHolder.ss (100%) diff --git a/src/pages/NewsArticle.php b/src/NewsArticle.php similarity index 88% rename from src/pages/NewsArticle.php rename to src/NewsArticle.php index 2335fcf..ea21260 100644 --- a/src/pages/NewsArticle.php +++ b/src/NewsArticle.php @@ -1,8 +1,15 @@ 'HTMLText', 'Author' => 'Varchar(128)', @@ -27,9 +35,9 @@ class NewsArticle extends SiteTree { * @var array */ private static $has_one = array( - 'InternalFile' => 'File', - 'NewsSection' => 'NewsHolder', - 'Thumbnail' => 'Image', + 'InternalFile' => File::class, + 'NewsSection' => NewsHolder::class, + 'Thumbnail' => Image::class, ); public function getCMSFields() { @@ -38,13 +46,11 @@ public function getCMSFields() { $fields->addFieldToTab('Root.Main', new TextField('Author', _t('NewsArticle.AUTHOR', 'Author')), 'Content'); $fields->addFieldToTab('Root.Main', $dp = new DateField('OriginalPublishedDate', _t('NewsArticle.PUBLISHED_DATE', 'When was this article first published?')), 'Content'); - $dp->setConfig('showcalendar', true); - $fields->addFieldToTab('Root.Main', new TextField('ExternalURL', _t('NewsArticle.EXTERNAL_URL', 'External URL to article (will automatically redirect to this URL if no article content set)')), 'Content'); $fields->addFieldToTab('Root.Main', new TextField('Source', _t('NewsArticle.SOURCE', 'News Source')), 'Content'); $fields->addFieldToTab('Root.Main', $if = new UploadField('Thumbnail', _t('NewsArticle.THUMB', 'Thumbnail')), 'Content'); - $if->setConfig('allowedMaxFileNumber', 1)->setFolderName('news-articles/thumbnails'); + $if->setAllowedMaxFileNumber(1)->setFolderName('news-articles/thumbnails'); $if->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif')); if (!$this->OriginalPublishedDate) { @@ -53,7 +59,7 @@ public function getCMSFields() { } $fields->addFieldToTab('Root.Main', UploadField::create('InternalFile', _t('NewsArticle.INTERNAL_FILE', 'Select a file containing this news article, if any'))->setFolderName('news'), 'Content'); - $fields->addFieldToTab('Root.Main', $summary = new HtmlEditorField('Summary', _t('NewsArticle.SUMMARY', 'Article Summary (displayed in listings)')), 'Content'); + $fields->addFieldToTab('Root.Main', $summary = new HTMLEditorField('Summary', _t('NewsArticle.SUMMARY', 'Article Summary (displayed in listings)')), 'Content'); $summary->addExtraClass('stacked'); $this->extend('updateArticleCMSFields', $fields); @@ -115,7 +121,7 @@ public function onAfterPublish() { * writing the objects */ protected function publishSection() { - $parent = DataObject::get_by_id('NewsHolder', $this->ParentID); + $parent = DataObject::get_by_id(NewsHolder::class, $this->ParentID); while ($parent && $parent instanceof NewsHolder) { if (!$parent->isPublished()) { $parent->doPublish(); diff --git a/src/NewsArticleController.php b/src/NewsArticleController.php new file mode 100644 index 0000000..30d3e61 --- /dev/null +++ b/src/NewsArticleController.php @@ -0,0 +1,11 @@ + 'Boolean', // whether articles created in this holder // automatically file into subfolders @@ -30,11 +38,11 @@ class NewsHolder extends SiteTree { 'PrimaryNewsSection' => true ); - private static $icon = 'news/images/newsholder'; + private static $icon = 'news/images/newsholder-file.gif'; private static $allowed_children = array( - 'NewsArticle', - 'NewsHolder' + NewsArticle::class, + NewsHolder::class ); /** * Should this news article be automatically filed into a year/month/date @@ -209,7 +217,7 @@ public function getPartitionedHolderForArticle($article) { $yearFolder = $this->dateFolder($year); if (!$yearFolder) { - throw new Exception("Failed retrieving folder"); + throw new \Exception("Failed retrieving folder"); } if ($this->FilingMode == 'year') { @@ -218,7 +226,7 @@ public function getPartitionedHolderForArticle($article) { $monthFolder = $yearFolder->dateFolder($month); if (!$monthFolder) { - throw new Exception("Failed retrieving folder"); + throw new \Exception("Failed retrieving folder"); } if ($this->FilingMode == 'month') { @@ -227,7 +235,7 @@ public function getPartitionedHolderForArticle($article) { $dayFolder = $monthFolder->dateFolder($day); if (!$dayFolder) { - throw new Exception("Failed retrieving folder"); + throw new \Exception("Failed retrieving folder"); } return $dayFolder; @@ -242,7 +250,7 @@ public function getPartitionedHolderForArticle($article) { */ public function dateFolder($name, $publish=false) { // see if we have a named child, otherwise create one - $child = DataObject::get_one('NewsHolder', 'ParentID = ' . $this->ID . ' AND Title = \'' . Convert::raw2sql($name) . '\''); + $child = DataObject::get_one(NewsHolder::class, 'ParentID = ' . $this->ID . ' AND Title = \'' . Convert::raw2sql($name) . '\''); if (!$child || !$child->ID) { $class = get_class($this); @@ -286,7 +294,7 @@ public function TotalChildArticles($number = null) { $start = 0; } - $articles = NewsArticle::get('NewsArticle', '', '"OriginalPublishedDate" DESC, "ID" DESC', '', $start . ',' . $number) + $articles = NewsArticle::get(NewsArticle::class, '', '"OriginalPublishedDate" DESC, "ID" DESC', '', $start . ',' . $number) ->filter(array('ID' => $this->getDescendantIDList())); $entries = PaginatedList::create($articles); $entries->setPaginationFromQuery($articles->dataQuery()->query()); diff --git a/src/pages/NewsHolderController.php b/src/NewsHolderController.php similarity index 88% rename from src/pages/NewsHolderController.php rename to src/NewsHolderController.php index 5a45b38..2584269 100644 --- a/src/pages/NewsHolderController.php +++ b/src/NewsHolderController.php @@ -1,11 +1,11 @@ Date: Tue, 1 Jan 2019 18:18:32 +0100 Subject: [PATCH 06/10] composer silverstripe-vendormodule --- composer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index adc4eaf..6092c11 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "silverstripe-australia/silverstripe-news", "description": "News module for silverstripe", - "type": "silverstripe-module", + "type": "silverstripe-vendormodule", "keywords": ["silverstripe", "news"], "authors": [ { @@ -26,5 +26,6 @@ "images" ] }, - "minimum-stability": "dev" + "minimum-stability": "dev", + "prefer-stable": true } From 3aa56f5a02ea91de8399b2bad3d3578de6603db9 Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Tue, 1 Jan 2019 18:31:56 +0100 Subject: [PATCH 07/10] removed news folder check in config --- _config.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/_config.php b/_config.php index 8e71d97..b3d9bbc 100644 --- a/_config.php +++ b/_config.php @@ -1,5 +1 @@ Date: Tue, 1 Jan 2019 18:48:26 +0100 Subject: [PATCH 08/10] removed installer-name --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 6092c11..50862eb 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,6 @@ "branch-alias": { "dev-master": "2.x-dev" }, - "installer-name": "news", "expose": [ "images" ] From 05a0e7ba37444537ca33df7fd8b3743a219ba051 Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Tue, 1 Jan 2019 18:58:59 +0100 Subject: [PATCH 09/10] installer-name --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 50862eb..0d10217 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "branch-alias": { "dev-master": "2.x-dev" }, + "installer-name": "silverstripe-news", "expose": [ "images" ] From d14d8cfc2d29facf8af16182ffc17b27b26defc2 Mon Sep 17 00:00:00 2001 From: Ivo Bathke Date: Tue, 1 Jan 2019 19:12:17 +0100 Subject: [PATCH 10/10] adjusted image pathes --- src/NewsArticle.php | 2 +- src/NewsHolder.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NewsArticle.php b/src/NewsArticle.php index ea21260..d2ad54a 100644 --- a/src/NewsArticle.php +++ b/src/NewsArticle.php @@ -20,7 +20,7 @@ class NewsArticle extends SiteTree { private static $table_name = 'NewsArticle'; - private static $icon = 'news/images/newspaper-file.gif'; + private static $icon = 'resources/vendor/silverstripe-australia/silverstripe-news/images/newspaper-file.gif'; private static $db = array( 'Summary' => 'HTMLText', 'Author' => 'Varchar(128)', diff --git a/src/NewsHolder.php b/src/NewsHolder.php index 5889209..e4e3602 100644 --- a/src/NewsHolder.php +++ b/src/NewsHolder.php @@ -38,7 +38,7 @@ class NewsHolder extends SiteTree { 'PrimaryNewsSection' => true ); - private static $icon = 'news/images/newsholder-file.gif'; + private static $icon = 'resources/vendor/silverstripe-australia/silverstripe-news/images/newsholder-file.gif'; private static $allowed_children = array( NewsArticle::class,