diff --git a/_config.php b/_config.php index 8e71d97..b3d9bbc 100644 --- a/_config.php +++ b/_config.php @@ -1,5 +1 @@ * @license BSD License http://silverstripe.org/bsd-license/ */ -class NewsArticle extends Page { +class NewsArticle extends SiteTree { - private static $icon = 'news/images/newspaper'; + private static $table_name = 'NewsArticle'; + private static $icon = 'resources/vendor/silverstripe-australia/silverstripe-news/images/newspaper-file.gif'; private static $db = array( 'Summary' => 'HTMLText', 'Author' => 'Varchar(128)', @@ -18,14 +30,14 @@ 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 */ private static $has_one = array( - 'InternalFile' => 'File', - 'NewsSection' => 'NewsHolder', - 'Thumbnail' => 'Image', + 'InternalFile' => File::class, + 'NewsSection' => NewsHolder::class, + 'Thumbnail' => Image::class, ); public function getCMSFields() { @@ -34,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) { @@ -49,11 +59,11 @@ 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); - + return $fields; } @@ -63,13 +73,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,20 +108,20 @@ 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 */ 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(); @@ -164,7 +174,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 +190,8 @@ public function Link($action='') { } return parent::Link($action); } - - + + /** * Pages to update cache file for static publisher * @@ -190,19 +200,16 @@ 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/src/NewsArticleController.php b/src/NewsArticleController.php new file mode 100644 index 0000000..30d3e61 --- /dev/null +++ b/src/NewsArticleController.php @@ -0,0 +1,11 @@ + * @license BSD License http://silverstripe.org/bsd-license/ */ -class NewsHolder extends Page { +class NewsHolder extends SiteTree { + + private static $table_name = 'NewsHolder'; 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 $icon = 'resources/vendor/silverstripe-australia/silverstripe-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 @@ -44,7 +56,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 +81,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 +173,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 */ @@ -205,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') { @@ -214,16 +226,16 @@ 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') { return $monthFolder; } $dayFolder = $monthFolder->dateFolder($day); if (!$dayFolder) { - throw new Exception("Failed retrieving folder"); + throw new \Exception("Failed retrieving folder"); } return $dayFolder; @@ -238,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); @@ -254,7 +266,7 @@ public function dateFolder($name, $publish=false) { } return $child; } - + /** * Pages to update cache file for static publisher * @@ -282,27 +294,10 @@ 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()); 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(); - } -} \ No newline at end of file diff --git a/src/NewsHolderController.php b/src/NewsHolderController.php new file mode 100644 index 0000000..2584269 --- /dev/null +++ b/src/NewsHolderController.php @@ -0,0 +1,24 @@ +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(); + } +} diff --git a/templates/Includes/NewsListItem.ss b/templates/Symbiote/News/Includes/NewsListItem.ss similarity index 100% rename from templates/Includes/NewsListItem.ss rename to templates/Symbiote/News/Includes/NewsListItem.ss diff --git a/templates/Layout/NewsArticle.ss b/templates/Symbiote/News/Layout/NewsArticle.ss similarity index 100% rename from templates/Layout/NewsArticle.ss rename to templates/Symbiote/News/Layout/NewsArticle.ss diff --git a/templates/Layout/NewsHolder.ss b/templates/Symbiote/News/Layout/NewsHolder.ss similarity index 100% rename from templates/Layout/NewsHolder.ss rename to templates/Symbiote/News/Layout/NewsHolder.ss