diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/Controller/FeedController.php | 60 | ||||
-rw-r--r-- | app/Template/feed/project.php | 27 | ||||
-rw-r--r-- | app/Template/feed/user.php | 27 |
3 files changed, 52 insertions, 62 deletions
diff --git a/app/Controller/FeedController.php b/app/Controller/FeedController.php index cf2b1088..f9b0ed7c 100644 --- a/app/Controller/FeedController.php +++ b/app/Controller/FeedController.php @@ -2,7 +2,11 @@ namespace Kanboard\Controller; +use DateTime; use Kanboard\Core\Controller\AccessForbiddenException; +use PicoFeed\Syndication\AtomFeedBuilder; +use PicoFeed\Syndication\AtomItemBuilder; +use PicoFeed\Syndication\FeedBuilder; /** * Atom/RSS Feed controller @@ -27,10 +31,15 @@ class FeedController extends BaseController throw AccessForbiddenException::getInstance()->withoutLayout(); } - $this->response->xml($this->template->render('feed/user', array( - 'events' => $this->helper->projectActivity->getProjectsEvents($this->projectPermissionModel->getActiveProjectIds($user['id'])), - 'user' => $user, - ))); + $events = $this->helper->projectActivity->getProjectsEvents($this->projectPermissionModel->getActiveProjectIds($user['id'])); + + $feedBuilder = AtomFeedBuilder::create() + ->withTitle(e('Project activities for %s', $this->helper->user->getFullname($user))) + ->withFeedUrl($this->helper->url->to('FeedController', 'user', array('token' => $user['token']), '', true)) + ->withSiteUrl($this->helper->url->base()) + ->withDate(new DateTime()); + + $this->response->xml($this->buildFeedItems($events, $feedBuilder)->build()); } /** @@ -47,9 +56,44 @@ class FeedController extends BaseController throw AccessForbiddenException::getInstance()->withoutLayout(); } - $this->response->xml($this->template->render('feed/project', array( - 'events' => $this->helper->projectActivity->getProjectEvents($project['id']), - 'project' => $project, - ))); + $events = $this->helper->projectActivity->getProjectEvents($project['id']); + + $feedBuilder = AtomFeedBuilder::create() + ->withTitle(e('%s\'s activity', $project['name'])) + ->withFeedUrl($this->helper->url->to('FeedController', 'project', array('token' => $project['token']), '', true)) + ->withSiteUrl($this->helper->url->base()) + ->withDate(new DateTime()); + + $this->response->xml($this->buildFeedItems($events, $feedBuilder)->build()); + } + + /** + * Build feed items + * + * @access protected + * @param array $events + * @param FeedBuilder $feedBuilder + * @return FeedBuilder + */ + protected function buildFeedItems(array $events, FeedBuilder $feedBuilder) + { + foreach ($events as $event) { + $itemDate = new DateTime(); + $itemDate->setTimestamp($event['date_creation']); + + $itemUrl = $this->helper->url->to('TaskViewController', 'show', array('task_id' => $event['task_id']), '', true); + + $feedBuilder + ->withItem(AtomItemBuilder::create($feedBuilder) + ->withTitle($event['event_title']) + ->withUrl($itemUrl.'#event-'.$event['id']) + ->withAuthor($event['author']) + ->withPublishedDate($itemDate) + ->withUpdatedDate($itemDate) + ->withContent($event['event_content']) + ); + } + + return $feedBuilder; } } diff --git a/app/Template/feed/project.php b/app/Template/feed/project.php deleted file mode 100644 index 213a04d4..00000000 --- a/app/Template/feed/project.php +++ /dev/null @@ -1,27 +0,0 @@ -<?= '<?xml version="1.0" encoding="utf-8"?>' ?> -<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom"> - <title><?= t('%s\'s activity', $project['name']) ?></title> - <link rel="alternate" type="text/html" href="<?= $this->url->base() ?>"/> - <link rel="self" type="application/atom+xml" href="<?= $this->url->href('FeedController', 'project', array('token' => $project['token']), false, '', true) ?>"/> - <updated><?= date(DATE_ATOM) ?></updated> - <id><?= $this->url->href('FeedController', 'project', array('token' => $project['token']), false, '', true) ?></id> - <icon><?= $this->url->base() ?>assets/img/favicon.png</icon> - - <?php foreach ($events as $e): ?> - <entry> - <title type="text"><?= $e['event_title'] ?></title> - <link rel="alternate" href="<?= $this->url->href('TaskViewController', 'show', array('task_id' => $e['task_id']), false, '', true) ?>"/> - <id><?= $e['id'].'-'.$e['event_name'].'-'.$e['task_id'].'-'.$e['date_creation'] ?></id> - <published><?= date(DATE_ATOM, $e['date_creation']) ?></published> - <updated><?= date(DATE_ATOM, $e['date_creation']) ?></updated> - <author> - <name><?= $this->text->e($e['author']) ?></name> - </author> - <content type="html"> - <![CDATA[ - <?= $e['event_content'] ?> - ]]> - </content> - </entry> - <?php endforeach ?> -</feed> diff --git a/app/Template/feed/user.php b/app/Template/feed/user.php deleted file mode 100644 index 0c45f03c..00000000 --- a/app/Template/feed/user.php +++ /dev/null @@ -1,27 +0,0 @@ -<?= '<?xml version="1.0" encoding="utf-8"?>' ?> -<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom"> - <title><?= t('Project activities for %s', $user['name'] ?: $user['username']) ?></title> - <link rel="alternate" type="text/html" href="<?= $this->url->base() ?>"/> - <link rel="self" type="application/atom+xml" href="<?= $this->url->href('FeedController', 'user', array('token' => $user['token']), false, '', true) ?>"/> - <updated><?= date(DATE_ATOM) ?></updated> - <id><?= $this->url->href('FeedController', 'user', array('token' => $user['token']), false, '', true) ?></id> - <icon><?= $this->url->base() ?>assets/img/favicon.png</icon> - - <?php foreach ($events as $e): ?> - <entry> - <title type="text"><?= $e['event_title'] ?></title> - <link rel="alternate" href="<?= $this->url->href('TaskViewController', 'show', array('task_id' => $e['task_id']), false, '', true) ?>"/> - <id><?= $e['id'].'-'.$e['event_name'].'-'.$e['task_id'].'-'.$e['date_creation'] ?></id> - <published><?= date(DATE_ATOM, $e['date_creation']) ?></published> - <updated><?= date(DATE_ATOM, $e['date_creation']) ?></updated> - <author> - <name><?= $this->text->e($e['author']) ?></name> - </author> - <content type="html"> - <![CDATA[ - <?= $e['event_content'] ?> - ]]> - </content> - </entry> - <?php endforeach ?> -</feed> |