diff options
author | Frederic Guillot <fred@kanboard.net> | 2015-06-19 19:38:23 -0400 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2015-06-19 19:38:23 -0400 |
commit | 73c47d9461cbfea88c84f3f2b01cdeb2d22c2f87 (patch) | |
tree | c7749fee7885ecfe6f12ae53a55c615ef0191971 | |
parent | ff85518fa8f6dc48ac5dedb4847c6bb24ea35b2f (diff) |
Add RSS feed for users and change address of project feeds
-rw-r--r-- | app/Controller/Feed.php | 56 | ||||
-rw-r--r-- | app/Controller/Project.php | 21 | ||||
-rw-r--r-- | app/Model/Acl.php | 4 | ||||
-rw-r--r-- | app/Template/feed/project.php (renamed from app/Template/project/feed.php) | 4 | ||||
-rw-r--r-- | app/Template/feed/user.php | 27 | ||||
-rw-r--r-- | app/Template/project/share.php | 2 | ||||
-rw-r--r-- | app/Template/project/show.php | 2 | ||||
-rw-r--r-- | app/Template/projectinfo/activity.php | 2 | ||||
-rw-r--r-- | app/Template/user/share.php | 1 | ||||
-rw-r--r-- | app/Template/user/show.php | 1 | ||||
-rw-r--r-- | tests/units/AclTest.php | 2 |
11 files changed, 94 insertions, 28 deletions
diff --git a/app/Controller/Feed.php b/app/Controller/Feed.php new file mode 100644 index 00000000..c08919c2 --- /dev/null +++ b/app/Controller/Feed.php @@ -0,0 +1,56 @@ +<?php + +namespace Controller; + +/** + * Atom/RSS Feed controller + * + * @package controller + * @author Frederic Guillot + */ +class Feed extends Base +{ + /** + * RSS feed for a user + * + * @access public + */ + public function user() + { + $token = $this->request->getStringParam('token'); + $user = $this->user->getByToken($token); + + // Token verification + if (empty($user)) { + $this->forbidden(true); + } + + $projects = $this->projectPermission->getActiveMemberProjects($user['id']); + + $this->response->xml($this->template->render('feed/user', array( + 'events' => $this->projectActivity->getProjects(array_keys($projects)), + 'user' => $user, + ))); + } + + /** + * RSS feed for a project + * + * @access public + */ + public function project() + { + $token = $this->request->getStringParam('token'); + $project = $this->project->getByToken($token); + + // Token verification + if (empty($project)) { + $this->forbidden(true); + } + + $this->response->xml($this->template->render('feed/project', array( + 'events' => $this->projectActivity->getProject($project['id']), + 'project' => $project, + ))); + } +} diff --git a/app/Controller/Project.php b/app/Controller/Project.php index ba039b7d..faebac38 100644 --- a/app/Controller/Project.php +++ b/app/Controller/Project.php @@ -395,27 +395,6 @@ class Project extends Base } /** - * RSS feed for a project (public) - * - * @access public - */ - public function feed() - { - $token = $this->request->getStringParam('token'); - $project = $this->project->getByToken($token); - - // Token verification - if (empty($project)) { - $this->forbidden(true); - } - - $this->response->xml($this->template->render('project/feed', array( - 'events' => $this->projectActivity->getProject($project['id']), - 'project' => $project, - ))); - } - - /** * Display a form to create a new project * * @access public diff --git a/app/Model/Acl.php b/app/Model/Acl.php index 8cfc7120..90944128 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -21,10 +21,10 @@ class Acl extends Base 'user' => array('google', 'github'), 'task' => array('readonly'), 'board' => array('readonly'), - 'project' => array('feed'), - 'webhook' => '*', 'app' => array('colors'), + 'webhook' => '*', 'ical' => '*', + 'feed' => '*', ); /** diff --git a/app/Template/project/feed.php b/app/Template/feed/project.php index 2062e801..60b7ee96 100644 --- a/app/Template/project/feed.php +++ b/app/Template/feed/project.php @@ -2,9 +2,9 @@ <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->base().$this->url->href('project', 'feed', array('token' => $project['token'])) ?>"/> + <link rel="self" type="application/atom+xml" href="<?= $this->url->base().$this->url->href('feed', 'project', array('token' => $project['token'])) ?>"/> <updated><?= date(DATE_ATOM) ?></updated> - <id><?= $this->url->base() ?></id> + <id><?= $this->url->base().$this->url->href('feed', 'project', array('token' => $project['token'])) ?></id> <icon><?= $this->url->base() ?>assets/img/favicon.png</icon> <?php foreach ($events as $e): ?> diff --git a/app/Template/feed/user.php b/app/Template/feed/user.php new file mode 100644 index 00000000..b3279a0c --- /dev/null +++ b/app/Template/feed/user.php @@ -0,0 +1,27 @@ +<?= '<?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->base().$this->url->href('feed', 'user', array('token' => $user['token'])) ?>"/> + <updated><?= date(DATE_ATOM) ?></updated> + <id><?= $this->url->base().$this->url->href('feed', 'user', array('token' => $user['token'])) ?></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->base().$this->url->href('task', 'show', array('task_id' => $e['task_id'])) ?>"/> + <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->e($e['author']) ?></name> + </author> + <content type="html"> + <![CDATA[ + <?= $e['event_content'] ?> + ]]> + </content> + </entry> + <?php endforeach ?> +</feed>
\ No newline at end of file diff --git a/app/Template/project/share.php b/app/Template/project/share.php index a9146599..6f66c97e 100644 --- a/app/Template/project/share.php +++ b/app/Template/project/share.php @@ -7,7 +7,7 @@ <div class="listing"> <ul class="no-bullet"> <li><strong><i class="fa fa-share-alt"></i> <?= $this->url->link(t('Public link'), 'board', 'readonly', array('token' => $project['token']), false, '', '', true) ?></strong></li> - <li><strong><i class="fa fa-rss-square"></i> <?= $this->url->link(t('RSS feed'), 'project', 'feed', array('token' => $project['token']), false, '', '', true) ?></strong></li> + <li><strong><i class="fa fa-rss-square"></i> <?= $this->url->link(t('RSS feed'), 'feed', 'project', array('token' => $project['token']), false, '', '', true) ?></strong></li> <li><strong><i class="fa fa-calendar"></i> <?= $this->url->link(t('iCal feed'), 'ical', 'project', array('token' => $project['token']), false, '', '', true) ?></strong></li> </ul> </div> diff --git a/app/Template/project/show.php b/app/Template/project/show.php index 4869d8a4..beb5a1fa 100644 --- a/app/Template/project/show.php +++ b/app/Template/project/show.php @@ -10,7 +10,7 @@ <?php if ($project['is_public']): ?> <li><i class="fa fa-share-alt"></i> <?= $this->url->link(t('Public link'), 'board', 'readonly', array('token' => $project['token']), false, '', '', true) ?></li> - <li><i class="fa fa-rss-square"></i> <?= $this->url->link(t('RSS feed'), 'project', 'feed', array('token' => $project['token']), false, '', '', true) ?></li> + <li><i class="fa fa-rss-square"></i> <?= $this->url->link(t('RSS feed'), 'feed', 'project', array('token' => $project['token']), false, '', '', true) ?></li> <li><i class="fa fa-calendar"></i> <?= $this->url->link(t('iCal feed'), 'ical', 'project', array('token' => $project['token'])) ?></li> <?php else: ?> <li><?= t('Public access disabled') ?></li> diff --git a/app/Template/projectinfo/activity.php b/app/Template/projectinfo/activity.php index 528cdbee..d458ea3d 100644 --- a/app/Template/projectinfo/activity.php +++ b/app/Template/projectinfo/activity.php @@ -20,7 +20,7 @@ <?= $this->url->link(t('All projects'), 'project', 'index') ?> </li> <?php if ($project['is_public']): ?> - <li><i class="fa fa-rss-square fa-fw"></i><?= $this->url->link(t('RSS feed'), 'project', 'feed', array('token' => $project['token']), false, '', '', true) ?></li> + <li><i class="fa fa-rss-square fa-fw"></i><?= $this->url->link(t('RSS feed'), 'feed', 'project', array('token' => $project['token']), false, '', '', true) ?></li> <li><i class="fa fa-calendar fa-fw"></i><?= $this->url->link(t('iCal feed'), 'ical', 'project', array('token' => $project['token'])) ?></li> <?php endif ?> </ul> diff --git a/app/Template/user/share.php b/app/Template/user/share.php index 8f333a6b..56dc8675 100644 --- a/app/Template/user/share.php +++ b/app/Template/user/share.php @@ -6,6 +6,7 @@ <div class="listing"> <ul class="no-bullet"> + <li><strong><i class="fa fa-rss-square"></i> <?= $this->url->link(t('RSS feed'), 'feed', 'user', array('token' => $user['token']), false, '', '', true) ?></strong></li> <li><strong><i class="fa fa-calendar"></i> <?= $this->url->link(t('iCal feed'), 'ical', 'user', array('token' => $user['token']), false, '', '', true) ?></strong></li> </ul> </div> diff --git a/app/Template/user/show.php b/app/Template/user/show.php index 5442e2e7..a9de6d85 100644 --- a/app/Template/user/show.php +++ b/app/Template/user/show.php @@ -33,6 +33,7 @@ <div class="listing"> <ul class="no-bullet"> + <li><strong><i class="fa fa-rss-square"></i> <?= $this->url->link(t('RSS feed'), 'feed', 'user', array('token' => $user['token']), false, '', '', true) ?></strong></li> <li><strong><i class="fa fa-calendar"></i> <?= $this->url->link(t('iCal feed'), 'ical', 'user', array('token' => $user['token']), false, '', '', true) ?></strong></li> </ul> </div> diff --git a/tests/units/AclTest.php b/tests/units/AclTest.php index 20101d47..c74a90ca 100644 --- a/tests/units/AclTest.php +++ b/tests/units/AclTest.php @@ -38,6 +38,8 @@ class AclTest extends Base $this->assertTrue($acl->isPublicAction('board', 'readonly')); $this->assertFalse($acl->isPublicAction('board', 'show')); $this->assertTrue($acl->isPublicAction('app', 'colors')); + $this->assertTrue($acl->isPublicAction('feed', 'project')); + $this->assertTrue($acl->isPublicAction('feed', 'user')); } public function testAdminActions() |