2016-12-15 04:41:49 +01:00
|
|
|
<?php
|
|
|
|
|
2016-12-18 22:25:36 +01:00
|
|
|
namespace SilverStripe\Blog\Model;
|
2016-12-15 04:41:49 +01:00
|
|
|
|
2017-01-13 03:33:53 +01:00
|
|
|
use PageController;
|
2017-05-03 03:44:37 +02:00
|
|
|
use SilverStripe\Control\Director;
|
2017-11-02 20:32:03 +01:00
|
|
|
use SilverStripe\Control\HTTPResponse_Exception;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\Control\RSS\RSSFeed;
|
|
|
|
use SilverStripe\ORM\ArrayList;
|
2017-11-01 10:00:33 +01:00
|
|
|
use SilverStripe\ORM\DataList;
|
2016-12-15 04:41:49 +01:00
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime;
|
|
|
|
use SilverStripe\ORM\PaginatedList;
|
|
|
|
use SilverStripe\Security\Member;
|
2017-09-14 07:11:45 +02:00
|
|
|
use SilverStripe\View\Parsers\URLSegmentFilter;
|
2016-12-15 04:41:49 +01:00
|
|
|
|
2017-01-13 03:33:53 +01:00
|
|
|
class BlogController extends PageController
|
2016-12-15 04:41:49 +01:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-09-14 00:59:01 +02:00
|
|
|
private static $allowed_actions = [
|
2016-12-15 04:41:49 +01:00
|
|
|
'archive',
|
|
|
|
'tag',
|
|
|
|
'category',
|
|
|
|
'rss',
|
|
|
|
'profile'
|
2017-09-14 00:59:01 +02:00
|
|
|
];
|
2016-12-15 04:41:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-09-14 00:59:01 +02:00
|
|
|
private static $url_handlers = [
|
2016-12-15 04:41:49 +01:00
|
|
|
'tag/$Tag!/$Rss' => 'tag',
|
|
|
|
'category/$Category!/$Rss' => 'category',
|
|
|
|
'archive/$Year!/$Month/$Day' => 'archive',
|
|
|
|
'profile/$URLSegment!' => 'profile'
|
2017-09-14 00:59:01 +02:00
|
|
|
];
|
2016-12-15 04:41:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-09-14 00:59:01 +02:00
|
|
|
private static $casting = [
|
2016-12-15 04:41:49 +01:00
|
|
|
'MetaTitle' => 'Text',
|
|
|
|
'FilterDescription' => 'Text'
|
2017-09-14 00:59:01 +02:00
|
|
|
];
|
2016-12-15 04:41:49 +01:00
|
|
|
|
2017-11-02 20:32:03 +01:00
|
|
|
/**
|
|
|
|
* If enabled, blog author profiles will be turned off for this site
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private static $disable_profiles = false;
|
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
/**
|
|
|
|
* The current Blog Post DataList query.
|
|
|
|
*
|
|
|
|
* @var DataList
|
|
|
|
*/
|
|
|
|
protected $blogPosts;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Blog $dataRecord
|
|
|
|
*/
|
|
|
|
$dataRecord = $this->dataRecord;
|
|
|
|
|
|
|
|
$this->blogPosts = $dataRecord->getBlogPosts();
|
|
|
|
|
|
|
|
return $this->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a Blog Member's profile.
|
|
|
|
*
|
2017-11-02 20:32:03 +01:00
|
|
|
* @throws HTTPResponse_Exception
|
|
|
|
*
|
2017-11-01 10:00:33 +01:00
|
|
|
* @return string
|
2016-12-15 04:41:49 +01:00
|
|
|
*/
|
|
|
|
public function profile()
|
|
|
|
{
|
2017-11-02 20:32:03 +01:00
|
|
|
if ($this->config()->get('disable_profiles')) {
|
|
|
|
$this->httpError(404, 'Not Found');
|
|
|
|
}
|
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
$profile = $this->getCurrentProfile();
|
|
|
|
|
|
|
|
if (!$profile) {
|
|
|
|
return $this->httpError(404, 'Not Found');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->blogPosts = $this->getCurrentProfilePosts();
|
|
|
|
|
|
|
|
return $this->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Member associated with the current URL segment.
|
|
|
|
*
|
|
|
|
* @return null|Member
|
|
|
|
*/
|
|
|
|
public function getCurrentProfile()
|
|
|
|
{
|
|
|
|
$urlSegment = $this->request->param('URLSegment');
|
|
|
|
|
|
|
|
if ($urlSegment) {
|
2017-09-14 07:11:45 +02:00
|
|
|
$filter = URLSegmentFilter::create();
|
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
return Member::get()
|
2017-09-14 07:11:45 +02:00
|
|
|
->filter('URLSegment', $filter->filter($urlSegment))
|
2016-12-15 04:41:49 +01:00
|
|
|
->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get posts related to the current Member profile.
|
|
|
|
*
|
|
|
|
* @return null|DataList
|
|
|
|
*/
|
|
|
|
public function getCurrentProfilePosts()
|
|
|
|
{
|
|
|
|
$profile = $this->getCurrentProfile();
|
|
|
|
|
|
|
|
if ($profile) {
|
|
|
|
return $profile->BlogPosts()->filter('ParentID', $this->ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders an archive for a specified date. This can be by year or year/month.
|
|
|
|
*
|
2017-11-01 10:00:33 +01:00
|
|
|
* @return null|string
|
2016-12-15 04:41:49 +01:00
|
|
|
*/
|
|
|
|
public function archive()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Blog $dataRecord
|
|
|
|
*/
|
|
|
|
$dataRecord = $this->dataRecord;
|
|
|
|
|
|
|
|
$year = $this->getArchiveYear();
|
|
|
|
$month = $this->getArchiveMonth();
|
|
|
|
$day = $this->getArchiveDay();
|
|
|
|
|
|
|
|
if ($this->request->param('Month') && !$month) {
|
|
|
|
$this->httpError(404, 'Not Found');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($month && $this->request->param('Day') && !$day) {
|
|
|
|
$this->httpError(404, 'Not Found');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($year) {
|
|
|
|
$this->blogPosts = $dataRecord->getArchivedBlogPosts($year, $month, $day);
|
|
|
|
|
|
|
|
return $this->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->httpError(404, 'Not Found');
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the archive year from the url.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getArchiveYear()
|
|
|
|
{
|
|
|
|
if ($this->request->param('Year')) {
|
|
|
|
if (preg_match('/^[0-9]{4}$/', $year = $this->request->param('Year'))) {
|
|
|
|
return (int) $year;
|
|
|
|
}
|
|
|
|
} elseif ($this->request->param('Action') == 'archive') {
|
|
|
|
return DBDatetime::now()->Year();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the archive money from the url.
|
|
|
|
*
|
|
|
|
* @return null|int
|
|
|
|
*/
|
|
|
|
public function getArchiveMonth()
|
|
|
|
{
|
|
|
|
$month = $this->request->param('Month');
|
|
|
|
|
|
|
|
if (preg_match('/^[0-9]{1,2}$/', $month)) {
|
|
|
|
if ($month > 0 && $month < 13) {
|
|
|
|
if (checkdate($month, 01, $this->getArchiveYear())) {
|
|
|
|
return (int) $month;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the archive day from the url.
|
|
|
|
*
|
|
|
|
* @return null|int
|
|
|
|
*/
|
|
|
|
public function getArchiveDay()
|
|
|
|
{
|
|
|
|
$day = $this->request->param('Day');
|
|
|
|
|
|
|
|
if (preg_match('/^[0-9]{1,2}$/', $day)) {
|
|
|
|
if (checkdate($this->getArchiveMonth(), $day, $this->getArchiveYear())) {
|
|
|
|
return (int) $day;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the blog posts for a given tag.
|
|
|
|
*
|
2017-11-01 10:00:33 +01:00
|
|
|
* @return null|string
|
2016-12-15 04:41:49 +01:00
|
|
|
*/
|
|
|
|
public function tag()
|
|
|
|
{
|
|
|
|
$tag = $this->getCurrentTag();
|
|
|
|
|
|
|
|
if ($tag) {
|
|
|
|
$this->blogPosts = $tag->BlogPosts();
|
|
|
|
|
2017-07-19 23:57:02 +02:00
|
|
|
if ($this->isRSS()) {
|
2016-12-15 04:41:49 +01:00
|
|
|
return $this->rssFeed($this->blogPosts, $tag->getLink());
|
|
|
|
} else {
|
|
|
|
return $this->render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->httpError(404, 'Not Found');
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tag Getter for use in templates.
|
|
|
|
*
|
|
|
|
* @return null|BlogTag
|
|
|
|
*/
|
|
|
|
public function getCurrentTag()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Blog $dataRecord
|
|
|
|
*/
|
|
|
|
$dataRecord = $this->dataRecord;
|
|
|
|
$tag = $this->request->param('Tag');
|
|
|
|
if ($tag) {
|
2017-09-14 07:11:45 +02:00
|
|
|
$filter = URLSegmentFilter::create();
|
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
return $dataRecord->Tags()
|
2017-09-14 07:11:45 +02:00
|
|
|
->filter('URLSegment', [$tag, $filter->filter($tag)])
|
2016-12-15 04:41:49 +01:00
|
|
|
->first();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders the blog posts for a given category.
|
|
|
|
*
|
2017-11-01 10:00:33 +01:00
|
|
|
* @return null|string
|
2016-12-15 04:41:49 +01:00
|
|
|
*/
|
|
|
|
public function category()
|
|
|
|
{
|
|
|
|
$category = $this->getCurrentCategory();
|
|
|
|
|
|
|
|
if ($category) {
|
|
|
|
$this->blogPosts = $category->BlogPosts();
|
|
|
|
|
2017-07-19 23:57:02 +02:00
|
|
|
if ($this->isRSS()) {
|
2016-12-15 04:41:49 +01:00
|
|
|
return $this->rssFeed($this->blogPosts, $category->getLink());
|
|
|
|
} else {
|
|
|
|
return $this->render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->httpError(404, 'Not Found');
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Category Getter for use in templates.
|
|
|
|
*
|
|
|
|
* @return null|BlogCategory
|
|
|
|
*/
|
|
|
|
public function getCurrentCategory()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Blog $dataRecord
|
|
|
|
*/
|
|
|
|
$dataRecord = $this->dataRecord;
|
|
|
|
$category = $this->request->param('Category');
|
|
|
|
if ($category) {
|
2017-09-14 07:11:45 +02:00
|
|
|
$filter = URLSegmentFilter::create();
|
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
return $dataRecord->Categories()
|
2017-09-14 07:11:45 +02:00
|
|
|
->filter('URLSegment', [$category, $filter->filter($category)])
|
2016-12-15 04:41:49 +01:00
|
|
|
->first();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the meta title for the current action.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getMetaTitle()
|
|
|
|
{
|
|
|
|
$title = $this->data()->getTitle();
|
|
|
|
$filter = $this->getFilterDescription();
|
|
|
|
|
|
|
|
if ($filter) {
|
|
|
|
$title = sprintf('%s - %s', $title, $filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->extend('updateMetaTitle', $title);
|
|
|
|
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a description of the current filter.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFilterDescription()
|
|
|
|
{
|
2017-09-14 00:59:01 +02:00
|
|
|
$items = [];
|
2016-12-15 04:41:49 +01:00
|
|
|
|
|
|
|
$list = $this->PaginatedList();
|
|
|
|
$currentPage = $list->CurrentPage();
|
|
|
|
|
|
|
|
if ($currentPage > 1) {
|
|
|
|
$items[] = _t(
|
2017-09-14 00:27:40 +02:00
|
|
|
'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_PAGE',
|
2016-12-15 04:41:49 +01:00
|
|
|
'Page {page}',
|
|
|
|
null,
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2016-12-15 04:41:49 +01:00
|
|
|
'page' => $currentPage
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2016-12-15 04:41:49 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($author = $this->getCurrentProfile()) {
|
|
|
|
$items[] = _t(
|
2017-09-14 00:27:40 +02:00
|
|
|
'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_AUTHOR',
|
2016-12-15 04:41:49 +01:00
|
|
|
'By {author}',
|
|
|
|
null,
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2016-12-15 04:41:49 +01:00
|
|
|
'author' => $author->Title
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2016-12-15 04:41:49 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($tag = $this->getCurrentTag()) {
|
|
|
|
$items[] = _t(
|
2017-09-14 00:27:40 +02:00
|
|
|
'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_TAG',
|
2016-12-15 04:41:49 +01:00
|
|
|
'Tagged with {tag}',
|
|
|
|
null,
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2016-12-15 04:41:49 +01:00
|
|
|
'tag' => $tag->Title
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2016-12-15 04:41:49 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($category = $this->getCurrentCategory()) {
|
|
|
|
$items[] = _t(
|
2017-09-14 00:27:40 +02:00
|
|
|
'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_CATEGORY',
|
2016-12-15 04:41:49 +01:00
|
|
|
'In category {category}',
|
|
|
|
null,
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2016-12-15 04:41:49 +01:00
|
|
|
'category' => $category->Title
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2016-12-15 04:41:49 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->owner->getArchiveYear()) {
|
|
|
|
if ($this->owner->getArchiveDay()) {
|
|
|
|
$date = $this->owner->getArchiveDate()->Nice();
|
|
|
|
} elseif ($this->owner->getArchiveMonth()) {
|
|
|
|
$date = $this->owner->getArchiveDate()->format('F, Y');
|
|
|
|
} else {
|
|
|
|
$date = $this->owner->getArchiveDate()->format('Y');
|
|
|
|
}
|
|
|
|
|
|
|
|
$items[] = _t(
|
2017-09-14 00:27:40 +02:00
|
|
|
'SilverStripe\\Blog\\Model\\Blog.FILTERDESCRIPTION_DATE',
|
2016-12-15 04:41:49 +01:00
|
|
|
'In {date}',
|
|
|
|
null,
|
2017-09-14 00:59:01 +02:00
|
|
|
[
|
2016-12-15 04:41:49 +01:00
|
|
|
'date' => $date,
|
2017-09-14 00:59:01 +02:00
|
|
|
]
|
2016-12-15 04:41:49 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = '';
|
|
|
|
|
|
|
|
if ($items) {
|
|
|
|
$result = implode(', ', $items);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->extend('updateFilterDescription', $result);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of paginated blog posts based on the BlogPost dataList.
|
|
|
|
*
|
|
|
|
* @return PaginatedList
|
|
|
|
*/
|
|
|
|
public function PaginatedList()
|
|
|
|
{
|
|
|
|
$allPosts = $this->blogPosts ?: ArrayList::create();
|
|
|
|
$posts = PaginatedList::create($allPosts);
|
|
|
|
|
|
|
|
// Set appropriate page size
|
|
|
|
if ($this->PostsPerPage > 0) {
|
|
|
|
$pageSize = $this->PostsPerPage;
|
|
|
|
} elseif ($count = $allPosts->count()) {
|
|
|
|
$pageSize = $count;
|
|
|
|
} else {
|
|
|
|
$pageSize = 99999;
|
|
|
|
}
|
|
|
|
$posts->setPageLength($pageSize);
|
|
|
|
|
|
|
|
// Set current page
|
2018-02-19 23:05:54 +01:00
|
|
|
$start = (int)$this->request->getVar($posts->getPaginationGetVar());
|
2016-12-15 04:41:49 +01:00
|
|
|
$posts->setPageStart($start);
|
|
|
|
|
|
|
|
return $posts;
|
|
|
|
}
|
|
|
|
|
2017-05-03 03:44:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the absolute link to the next page for use in the page meta tags. This helps search engines
|
|
|
|
* find the pagination and index all pages properly.
|
|
|
|
*
|
|
|
|
* @example "<% if $PaginationAbsoluteNextLink %><link rel="next" href="$PaginationAbsoluteNextLink"><% end_if %>"
|
|
|
|
*
|
2017-11-01 10:00:33 +01:00
|
|
|
* @return string|null
|
2017-05-03 03:44:37 +02:00
|
|
|
*/
|
|
|
|
public function PaginationAbsoluteNextLink()
|
|
|
|
{
|
|
|
|
$posts = $this->PaginatedList();
|
|
|
|
if ($posts->NotLastPage()) {
|
|
|
|
return Director::absoluteURL($posts->NextLink());
|
|
|
|
}
|
2017-11-01 10:00:33 +01:00
|
|
|
|
|
|
|
return null;
|
2017-05-03 03:44:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the absolute link to the previous page for use in the page meta tags. This helps search engines
|
|
|
|
* find the pagination and index all pages properly.
|
|
|
|
*
|
|
|
|
* @example "<% if $PaginationAbsolutePrevLink %><link rel="prev" href="$PaginationAbsolutePrevLink"><% end_if %>"
|
|
|
|
*
|
2017-11-01 10:00:33 +01:00
|
|
|
* @return string|null
|
2017-05-03 03:44:37 +02:00
|
|
|
*/
|
|
|
|
public function PaginationAbsolutePrevLink()
|
|
|
|
{
|
|
|
|
$posts = $this->PaginatedList();
|
|
|
|
if ($posts->NotFirstPage()) {
|
|
|
|
return Director::absoluteURL($posts->PrevLink());
|
|
|
|
}
|
2017-11-01 10:00:33 +01:00
|
|
|
|
|
|
|
return null;
|
2017-05-03 03:44:37 +02:00
|
|
|
}
|
|
|
|
|
2016-12-15 04:41:49 +01:00
|
|
|
/**
|
|
|
|
* Displays an RSS feed of blog posts.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function rss()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Blog $dataRecord
|
|
|
|
*/
|
|
|
|
$dataRecord = $this->dataRecord;
|
|
|
|
|
|
|
|
$this->blogPosts = $dataRecord->getBlogPosts();
|
|
|
|
|
|
|
|
return $this->rssFeed($this->blogPosts, $this->Link());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the current archive date.
|
|
|
|
*
|
2017-11-01 10:00:33 +01:00
|
|
|
* @return null|DBDatetime
|
2016-12-15 04:41:49 +01:00
|
|
|
*/
|
|
|
|
public function getArchiveDate()
|
|
|
|
{
|
|
|
|
$year = $this->getArchiveYear();
|
|
|
|
$month = $this->getArchiveMonth();
|
|
|
|
$day = $this->getArchiveDay();
|
|
|
|
|
|
|
|
if ($year) {
|
|
|
|
if ($month) {
|
|
|
|
$date = sprintf('%s-%s-01', $year, $month);
|
|
|
|
|
|
|
|
if ($day) {
|
|
|
|
$date = sprintf('%s-%s-%s', $year, $month, $day);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$date = sprintf('%s-01-01', $year);
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj = DBDatetime::create('date');
|
|
|
|
$obj->setValue($date);
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a link to the RSS feed.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getRSSLink()
|
|
|
|
{
|
|
|
|
return $this->Link('rss');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays an RSS feed of the given blog posts.
|
|
|
|
*
|
|
|
|
* @param DataList $blogPosts
|
|
|
|
* @param string $link
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function rssFeed($blogPosts, $link)
|
|
|
|
{
|
2017-09-14 01:49:27 +02:00
|
|
|
$rss = RSSFeed::create($blogPosts, $link, $this->MetaTitle, $this->MetaDescription);
|
2016-12-15 04:41:49 +01:00
|
|
|
|
|
|
|
$this->extend('updateRss', $rss);
|
|
|
|
|
|
|
|
return $rss->outputToBrowser();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the $Rss sub-action for categories/tags has been set to "rss"
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
protected function isRSS()
|
|
|
|
{
|
|
|
|
$rss = $this->request->param('Rss');
|
|
|
|
return (is_string($rss) && strcasecmp($rss, 'rss') == 0);
|
|
|
|
}
|
|
|
|
}
|