Skip to content

Commit

Permalink
Resolve Issue #66: RSS exempt news posts
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbennett committed Dec 19, 2016
1 parent bfda625 commit 7021525
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/controllers/News.php
Expand Up @@ -6,6 +6,7 @@
use \BNETDocs\Libraries\Pagination;
use \BNETDocs\Libraries\User;
use \BNETDocs\Models\News as NewsModel;
use \BNETDocs\Views\NewsRSS as NewsRSSView;
use \CarlBennett\MVC\Libraries\Common;
use \CarlBennett\MVC\Libraries\Controller;
use \CarlBennett\MVC\Libraries\Router;
Expand All @@ -26,7 +27,7 @@ public function &run(Router &$router, View &$view, array &$args) {
isset($_SESSION['user_id']) ? new User($_SESSION['user_id']) : null
);

$model->acl_allowed = ($model->user &&
$model->acl_allowed = ($model->user &&
$model->user->getOptionsBitmask() & (
User::OPTION_ACL_NEWS_CREATE |
User::OPTION_ACL_NEWS_MODIFY |
Expand All @@ -37,7 +38,10 @@ public function &run(Router &$router, View &$view, array &$args) {
$query = $router->getRequestQueryArray();
$page = (isset($query["page"]) ? ((int) $query["page"]) - 1 : null);

$this->getNews($model, (!$view instanceof NewsRSSView), $page);
$this->getNews(
$model, ($view instanceof NewsRSSView),
(!$view instanceof NewsRSSView), $page
);

$view->render($model);

Expand All @@ -49,15 +53,15 @@ public function &run(Router &$router, View &$view, array &$args) {

}

protected function getNews(NewsModel &$model, $paginate, $page) {
protected function getNews(NewsModel &$model, $rss, $paginate, $page) {
$model->news_posts = NewsPost::getAllNews(true);

// Remove news posts that are not published
if (!$model->acl_allowed && $model->news_posts) {
// Remove news posts that are not published or are RSS exempt
if ($model->news_posts) {
$i = count($model->news_posts) - 1;
while ($i >= 0) {
if (!($model->news_posts[$i]->getOptionsBitmask()
& NewsPost::OPTION_PUBLISHED)) {
if ((!$model->acl_allowed && !$model->news_posts[$i]->getPublished())
|| ($rss && $model->news_posts[$i]->getRSSExempt())) {
unset($model->news_posts[$i]);
}
--$i;
Expand Down
17 changes: 15 additions & 2 deletions src/libraries/NewsPost.php
Expand Up @@ -20,8 +20,9 @@

class NewsPost {

const OPTION_MARKDOWN = 0x00000001;
const OPTION_PUBLISHED = 0x00000002;
const OPTION_MARKDOWN = 0x00000001;
const OPTION_PUBLISHED = 0x00000002;
const OPTION_RSS_EXEMPT = 0x00000004;

protected $category_id;
protected $content;
Expand Down Expand Up @@ -272,6 +273,10 @@ public function getPublished() {
return $this->options_bitmask & self::OPTION_PUBLISHED;
}

public function getRSSExempt() {
return $this->options_bitmask & self::OPTION_RSS_EXEMPT;
}

public function getOptionsBitmask() {
return $this->options_bitmask;
}
Expand Down Expand Up @@ -471,6 +476,14 @@ public function setPublished($value) {
}
}

public function setRSSExempt($value) {
if ($value) {
$this->options_bitmask |= self::OPTION_RSS_EXEMPT;
} else {
$this->options_bitmask &= ~self::OPTION_RSS_EXEMPT;
}
}

public function setTitle($value) {
$this->title = $value;
}
Expand Down

0 comments on commit 7021525

Please sign in to comment.