A free, self-hostable news aggregator…
Better control of number of entries per page or RSS feed
Alexandre Alapetite2a5aa34ad279
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b3c46bdb6..f82f68fff 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -3,6 +3,10 @@## 2016-XX-XX FreshRSS 1.6.0-dev* Features+ * Better control of number of entries per page or RSS feed [#1249](https://github.com/FreshRSS/FreshRSS/issues/1249)+ * Since X hours: `https://freshrss.example/i/?a=rss&hours=3`+ * Explicit number: `https://freshrss.example/i/?a=rss&nb=10`+ * Limited by `min_posts_per_rss` and `max_posts_per_rss` in user config* Support custom ports `localhost:3306` for database servers [#1241](https://github.com/FreshRSS/FreshRSS/issues/1241)* Security* Prevent `<a target="_blank">` attacks with `window.opener` [#1245](https://github.com/FreshRSS/FreshRSS/issues/1245)diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.phpindex 2332d225d..4e2717920 100755--- a/app/Controllers/indexController.php+++ b/app/Controllers/indexController.php@@ -34,7 +34,9 @@ class FreshRSS_index_Controller extends Minz_ActionController {$this->view->callbackBeforeContent = function($view) {try {+ FreshRSS_Context::$number++; //+1 for pagination$entries = FreshRSS_index_Controller::listEntriesByContext();+ FreshRSS_Context::$number--;$nb_entries = count($entries);if ($nb_entries > FreshRSS_Context::$number) {@@ -154,6 +156,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {* - order (default: conf->sort_order)* - nb (default: conf->posts_per_page)* - next (default: empty string)+ * - hours (default: 0)*/private function updateContext() {// Update number of read / unread variables.@@ -180,10 +183,14 @@ class FreshRSS_index_Controller extends Minz_ActionController {FreshRSS_Context::$order = Minz_Request::param('order', FreshRSS_Context::$user_conf->sort_order);- FreshRSS_Context::$number = Minz_Request::param(- 'nb', FreshRSS_Context::$user_conf->posts_per_page- );+ FreshRSS_Context::$number = intval(Minz_Request::param('nb', FreshRSS_Context::$user_conf->posts_per_page));+ if (FreshRSS_Context::$number > FreshRSS_Context::$user_conf->max_posts_per_rss) {+ FreshRSS_Context::$number = max(+ FreshRSS_Context::$user_conf->max_posts_per_rss,+ FreshRSS_Context::$user_conf->posts_per_page);+ }FreshRSS_Context::$first_id = Minz_Request::param('next', '');+ FreshRSS_Context::$sinceHours = intval(Minz_Request::param('hours', 0));}/**@@ -201,11 +208,31 @@ class FreshRSS_index_Controller extends Minz_ActionController {$id = '';}- return $entryDAO->listWhere(+ $limit = FreshRSS_Context::$number;++ $date_min = 0;+ if (FreshRSS_Context::$sinceHours) {+ $date_min = time() - (FreshRSS_Context::$sinceHours * 3600);+ $limit = FreshRSS_Context::$user_conf->max_posts_per_rss;+ }++ $entries = $entryDAO->listWhere($type, $id, FreshRSS_Context::$state, FreshRSS_Context::$order,- FreshRSS_Context::$number + 1, FreshRSS_Context::$first_id,- FreshRSS_Context::$search+ $limit, FreshRSS_Context::$first_id,+ FreshRSS_Context::$search, $date_min);++ if (FreshRSS_Context::$sinceHours && (count($entries) < FreshRSS_Context::$user_conf->min_posts_per_rss)) {+ $date_min = 0;+ $limit = FreshRSS_Context::$user_conf->min_posts_per_rss;+ $entries = $entryDAO->listWhere(+ $type, $id, FreshRSS_Context::$state, FreshRSS_Context::$order,+ $limit, FreshRSS_Context::$first_id,+ FreshRSS_Context::$search, $date_min+ );+ }++ return $entries;}/**diff --git a/app/Models/Context.php b/app/Models/Context.phpindex 2a58bd4ba..33e65a619 100644--- a/app/Models/Context.php+++ b/app/Models/Context.php@@ -35,6 +35,7 @@ class FreshRSS_Context {public static $first_id = '';public static $next_id = '';public static $id_max = '';+ public static $sinceHours = 0;/*** Initialize the context.diff --git a/app/layout/layout.phtml b/app/layout/layout.phtmlindex 4d9ad5458..1f11e0af1 100644--- a/app/layout/layout.phtml+++ b/app/layout/layout.phtml@@ -42,6 +42,9 @@} if (isset($this->rss_title)) {$url_rss = $url_base;$url_rss['a'] = 'rss';+ if (FreshRSS_Context::$user_conf->since_hours_posts_per_rss) {+ $url_rss['params']['hours'] = FreshRSS_Context::$user_conf->since_hours_posts_per_rss;+ }?><link rel="alternate" type="application/rss+xml" title="<?php echo $this->rss_title; ?>" href="<?php echo Minz_Url::display($url_rss); ?>" /><?php } if (FreshRSS_Context::$system_conf->allow_robots) { ?>diff --git a/app/layout/nav_menu.phtml b/app/layout/nav_menu.phtmlindex d77c1abf9..c02232242 100644--- a/app/layout/nav_menu.phtml+++ b/app/layout/nav_menu.phtml@@ -151,6 +151,9 @@if (FreshRSS_Context::$user_conf->token) {$url_output['params']['token'] = FreshRSS_Context::$user_conf->token;}+ if (FreshRSS_Context::$user_conf->since_hours_posts_per_rss) {+ $url_output['params']['hours'] = FreshRSS_Context::$user_conf->since_hours_posts_per_rss;+ }?><a class="view_rss btn" target="_blank" rel="noreferrer" title="<?php echo _t('index.menu.rss_view'); ?>" href="<?php echo Minz_Url::display($url_output); ?>"><?php echo _i('rss'); ?>diff --git a/app/views/auth/index.phtml b/app/views/auth/index.phtmlindex 74e692ec5..7195bab5d 100644--- a/app/views/auth/index.phtml+++ b/app/views/auth/index.phtml@@ -60,7 +60,7 @@<input type="text" id="token" name="token" value="<?php echo $token; ?>" placeholder="<?php echo _t('gen.short.blank_to_disable'); ?>"<?phpecho FreshRSS_Auth::accessNeedsAction() ? '' : ' disabled="disabled"'; ?> data-leave-validation="<?php echo $token; ?>"/><?php echo _i('help'); ?> <?php echo _t('admin.auth.token_help'); ?>- <kbd><?php echo Minz_Url::display(array('params' => array('output' => 'rss', 'token' => $token)), 'html', true); ?></kbd>+ <kbd><?php echo Minz_Url::display(array('params' => array('output' => 'rss', 'token' => $token, 'hours' => FreshRSS_Context::$user_conf->since_hours_posts_per_rss)), 'html', true); ?></kbd></div></div><?php } ?>diff --git a/data/users/_/config.default.php b/data/users/_/config.default.phpindex 4a3403453..2c56d5f45 100644--- a/data/users/_/config.default.php+++ b/data/users/_/config.default.php@@ -9,6 +9,9 @@ return array ('passwordHash' => '','apiPasswordHash' => '','posts_per_page' => 20,+ 'since_hours_posts_per_rss' => 168,+ 'min_posts_per_rss' => 2,+ 'max_posts_per_rss' => 400,'view_mode' => 'normal','default_view' => 'adaptive','default_state' => FreshRSS_Entry::STATE_NOT_READ,