Przeglądaj źródła

nextGet and idMax are coming back.

See https://github.com/marienfressinaud/FreshRSS/issues/634
Marien Fressinaud 11 lat temu
rodzic
commit
1fe5ed5d21

+ 3 - 11
app/Controllers/entryController.php

@@ -17,14 +17,6 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
 			);
 		}
 
-		// Keep parameter information (output) to do a correct redirection at
-		// the end.
-		$this->params = array();
-		$output = Minz_Request::param('output', '');
-		if ($output != '' && FreshRSS_Context::$conf->view_mode !== $output) {
-			$this->params['output'] = $output;
-		}
-
 		// If ajax request, we do not print layout
 		$this->ajax = Minz_Request::param('ajax');
 		if ($this->ajax) {
@@ -53,6 +45,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
 		$get = Minz_Request::param('get');
 		$next_get = Minz_Request::param('nextGet', $get);
 		$id_max = Minz_Request::param('idMax', 0);
+		$params = array();
 
 		$entryDAO = FreshRSS_Factory::createEntryDao();
 		if ($id === false) {
@@ -86,7 +79,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
 					// Redirect to the correct page (category, feed or starred)
 					// Not "a" because it is the default value if nothing is
 					// given.
-					$this->params['get'] = $next_get;
+					$params['get'] = $next_get;
 				}
 			}
 		} else {
@@ -98,7 +91,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
 			Minz_Request::good(_t('feeds_marked_read'), array(
 				'c' => 'index',
 				'a' => 'index',
-				'params' => $this->params,
+				'params' => $params,
 			), true);
 		}
 	}
@@ -123,7 +116,6 @@ class FreshRSS_entry_Controller extends Minz_ActionController {
 			Minz_Request::forward(array(
 				'c' => 'index',
 				'a' => 'index',
-				'params' => $this->params,
 			), true);
 		}
 	}

+ 14 - 1
app/Controllers/indexController.php

@@ -34,12 +34,25 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 		try {
 			$entries = $this->listEntriesByContext();
 
-			if (count($entries) > FreshRSS_Context::$number) {
+			$nb_entries = count($entries);
+			if ($nb_entries > FreshRSS_Context::$number) {
 				// We have more elements for pagination
 				$last_entry = array_pop($entries);
 				FreshRSS_Context::$next_id = $last_entry->id();
 			}
 
+			$first_entry = $nb_entries > 0 ? $entries[0] : null;
+			FreshRSS_Context::$id_max = $first_entry === null ?
+			                            (time() - 1) . '000000' :
+			                            $first_entry->id();
+			if (FreshRSS_Context::$order === 'ASC') {
+				// In this case we do not know but we guess id_max
+				$id_max = (time() - 1) . '000000';
+				if (strcmp($id_max, FreshRSS_Context::$id_max) > 0) {
+					FreshRSS_Context::$id_max = $id_max;
+				}
+			}
+
 			$this->view->entries = $entries;
 		} catch (FreshRSS_EntriesGetter_Exception $e) {
 			Minz_Log::notice($e->getMessage());

+ 63 - 10
app/Models/Context.php

@@ -24,6 +24,7 @@ class FreshRSS_Context {
 		'feed' => false,
 		'category' => false,
 	);
+	public static $next_get = 'a';
 
 	public static $state = 0;
 	public static $order = 'DESC';
@@ -31,6 +32,7 @@ class FreshRSS_Context {
 	public static $search = '';
 	public static $first_id = '';
 	public static $next_id = '';
+	public static $id_max = '';
 
 	public static function init() {
 		// Init configuration.
@@ -84,8 +86,6 @@ class FreshRSS_Context {
 			self::$state = self::$state | FreshRSS_Entry::STATE_FAVORITE;
 			break;
 		case 'f':
-			self::$current_get['feed'] = $id;
-
 			$feed = FreshRSS_CategoryDAO::findFeed(self::$categories, $id);
 			if ($feed === null) {
 				$feedDAO = FreshRSS_Factory::createFeedDao();
@@ -96,6 +96,8 @@ class FreshRSS_Context {
 				}
 			}
 
+			self::$current_get['feed'] = $id;
+			self::$current_get['category'] = $feed->category();
 			self::$name = $feed->name();
 			self::$get_unread = $feed->nbNotRead();
 			break;
@@ -118,6 +120,8 @@ class FreshRSS_Context {
 		default:
 			throw new FreshRSS_Context_Exception('Invalid getter: ' . $get);
 		}
+
+		self::_nextGet();
 	}
 
 	public static function currentGet($array = false) {
@@ -150,19 +154,68 @@ class FreshRSS_Context {
 		case 's':
 			return self::$current_get['starred'];
 		case 'f':
-			return self::$current_get['feed'] === $id;
+			return self::$current_get['feed'] == $id;
 		case 'c':
-			return self::$current_get['category'] === $id;
+			return self::$current_get['category'] == $id;
 		default:
 			return false;
 		}
 	}
 
-	public static function nextStep() {
-		// TODO: fix this method.
-		return array(
-			'get' => 'a',
-			'idMax' => (time() - 1) . '000000'
-		);
+	public static function _nextGet() {
+		$get = self::currentGet();
+		self::$next_get = $get;
+
+		if (self::$conf->onread_jump_next && strlen($get) > 2) {
+			$another_unread_id = '';
+			$found_current_get = false;
+			switch ($get[0]) {
+			case 'f':
+				foreach (self::$categories as $cat) {
+					if ($cat->id() != self::$current_get['category']) {
+						continue;
+					}
+
+					foreach ($cat->feeds() as $feed) {
+						if ($feed->id() == self::$current_get['feed']) {
+							$found_current_get = true;
+							continue;
+						}
+
+						if ($feed->nbNotRead() > 0) {
+							$another_unread_id = $feed->id();
+							if ($found_current_get) {
+								break;
+							}
+						}
+					}
+					break;
+				}
+
+				self::$next_get['get'] = empty($another_unread_id) ?
+				                         'c_' . self::$current_get['category'] :
+				                         'f_' . $another_unread_id;
+				break;
+			case 'c':
+				foreach (self::$categories as $cat) {
+					if ($cat->id() == self::$current_get['category']) {
+						$found_current_get = true;
+						continue;
+					}
+
+					if ($cat->nbNotRead() > 0) {
+						$another_unread_id = $cat->id();
+						if ($found_current_get) {
+							break;
+						}
+					}
+				}
+
+				self::$next_get['get'] = empty($another_unread_id) ?
+				                         'a' :
+				                         'c_' . $another_unread_id;
+				break;
+			}
+		}
 	}
 }

+ 2 - 3
app/layout/nav_menu.phtml

@@ -61,7 +61,6 @@
 
 	<?php
 		$get = FreshRSS_Context::currentGet();
-		$next_step = FreshRSS_Context::nextStep();
 		$string_mark = _t('mark_all_read');
 		if ($get[0] == 'f') {
 			$string_mark = _t('mark_feed_read');
@@ -74,8 +73,8 @@
 			'a' => 'read',
 			'params' => array(
 				'get' => $get,
-				'nextGet' => $next_step['get'],
-				'idMax' => $next_step['idMax']
+				'nextGet' => FreshRSS_Context::$next_get,
+				'idMax' => FreshRSS_Context::$id_max,
 			)
 		);
 	?>