Просмотр исходного кода

Entries are loaded again! It's working :)

See https://github.com/marienfressinaud/FreshRSS/issues/634
Marien Fressinaud 11 лет назад
Родитель
Сommit
f1f9b2f5ff
4 измененных файлов с 60 добавлено и 27 удалено
  1. 41 17
      app/Controllers/indexController.php
  2. 13 4
      app/Models/Context.php
  3. 2 2
      app/layout/layout.phtml
  4. 4 4
      app/views/index/normal.phtml

+ 41 - 17
app/Controllers/indexController.php

@@ -14,23 +14,6 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 			'c' => 'index',
 			'a' => $prefered_output
 		));
-
-		return;
-
-		try {
-			$entries = $entryDAO->listWhere($getType, $getId, $this->view->state, $order, $nb + 1, $first, $filter);
-
-			if (count($entries) > $nb) {
-				// We have more elements for pagination
-				$last_entry = array_pop($entries);
-				FreshRSS_Context::$next_id = $last_entry->id();
-			}
-
-			$this->view->entries = $entries;
-		} catch (FreshRSS_EntriesGetter_Exception $e) {
-			Minz_Log::notice($e->getMessage());
-			Minz_Error::error(404);
-		}
 	}
 
 	/**
@@ -48,6 +31,21 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 			Minz_Error::error(404);
 		}
 
+		try {
+			$entries = $this->listByContext();
+
+			if (count($entries) > FreshRSS_Context::$number) {
+				// We have more elements for pagination
+				$last_entry = array_pop($entries);
+				FreshRSS_Context::$next_id = $last_entry->id();
+			}
+
+			$this->view->entries = $entries;
+		} catch (FreshRSS_EntriesGetter_Exception $e) {
+			Minz_Log::notice($e->getMessage());
+			Minz_Error::error(404);
+		}
+
 		$this->view->categories = FreshRSS_Context::$categories;
 
 		$title = FreshRSS_Context::$name;
@@ -100,6 +98,13 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 			Minz_Error::error(404);
 		}
 
+		try {
+			$this->view->entries = $this->listByContext();
+		} catch (FreshRSS_EntriesGetter_Exception $e) {
+			Minz_Log::notice($e->getMessage());
+			Minz_Error::error(404);
+		}
+
 		// No layout for RSS output.
 		$this->view->rss_title = FreshRSS_Context::$name . ' | ' . Minz_View::title();
 		$this->view->_useLayout(false);
@@ -130,6 +135,25 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 		FreshRSS_Context::$first_id = Minz_Request::param('next', '');
 	}
 
+	private function listByContext() {
+		$entryDAO = FreshRSS_Factory::createEntryDao();
+
+		$get = FreshRSS_Context::currentGet(true);
+		if (count($get) > 1) {
+			$type = $get[0];
+			$id = $get[1];
+		} else {
+			$type = $get;
+			$id = '';
+		}
+
+		return $entryDAO->listWhere(
+			$type, $id, FreshRSS_Context::$state, FreshRSS_Context::$order,
+			FreshRSS_Context::$number + 1, FreshRSS_Context::$first_id,
+			FreshRSS_Context::$search
+		);
+	}
+
 	/**
 	 * This action displays the about page of FreshRSS.
 	 */

+ 13 - 4
app/Models/Context.php

@@ -28,7 +28,8 @@ class FreshRSS_Context {
 	public static $order = 'DESC';
 	public static $number = 0;
 	public static $search = '';
-	public static $first_id = 0;
+	public static $first_id = '';
+	public static $next_id = '';
 
 	public static function init() {
 		// Init configuration.
@@ -127,15 +128,23 @@ class FreshRSS_Context {
 		}
 	}
 
-	public static function currentGet() {
+	public static function currentGet($array = false) {
 		if (self::$current_get['all']) {
 			return 'a';
 		} elseif (self::$current_get['starred']) {
 			return 's';
 		} elseif (self::$current_get['feed']) {
-			return 'f_' . self::$current_get['feed'];
+			if ($array) {
+				return array('f', self::$current_get['feed']);
+			} else {
+				return 'f_' . self::$current_get['feed'];
+			}
 		} elseif (self::$current_get['category']) {
-			return 'c_' . self::$current_get['category'];
+			if ($array) {
+				return array('c', self::$current_get['category']);
+			} else {
+				return 'c_' . self::$current_get['category'];
+			}
 		}
 	}
 

+ 2 - 2
app/layout/layout.phtml

@@ -10,9 +10,9 @@
 <?php $this->renderHelper('javascript_vars'); ?>
 		//]]></script>
 <?php
-	if (!empty($this->nextId)) {
+	if (FreshRSS_Context::$next_id !== '') {
 		$params = Minz_Request::params();
-		$params['next'] = $this->nextId;
+		$params['next'] = FreshRSS_Context::$next_id;
 		$params['ajax'] = 1;
 ?>
 		<link id="prefetch" rel="next prefetch" href="<?php echo Minz_Url::display(array('c' => Minz_Request::controllerName(), 'a' => Minz_Request::actionName(), 'params' => $params)); ?>" />

+ 4 - 4
app/views/index/normal.phtml

@@ -32,14 +32,14 @@ if (!empty($this->entries)) {
 
 <div id="stream" class="normal<?php echo $hidePosts ? ' hide_posts' : ''; ?>"><?php
 	?><div id="new-article">
-		<a href="<?php echo Minz_Url::display($this->url); ?>"><?php echo _t('new_article'); ?></a>
+		<a href="<?php echo Minz_Url::display(Minz_Request::currentRequest()); ?>"><?php echo _t('new_article'); ?></a>
 	</div><?php
 	foreach ($this->entries as $item) {
 		if ($display_today && $item->isDay(FreshRSS_Days::TODAY, $today)) {
 			?><div class="day" id="day_today"><?php
 				echo _t('today');
 				?><span class="date"> — <?php echo timestamptodate(time(), false); ?></span><?php
-				?><span class="name"><?php echo $this->currentName; ?></span><?php
+				?><span class="name"><?php echo FreshRSS_Context::$name; ?></span><?php
 			?></div><?php
 			$display_today = false;
 		}
@@ -47,14 +47,14 @@ if (!empty($this->entries)) {
 			?><div class="day" id="day_yesterday"><?php
 				echo _t('yesterday');
 				?><span class="date"> — <?php echo timestamptodate(time() - 86400, false); ?></span><?php
-				?><span class="name"><?php echo $this->currentName; ?></span><?php
+				?><span class="name"><?php echo FreshRSS_Context::$name; ?></span><?php
 			?></div><?php
 			$display_yesterday = false;
 		}
 		if ($display_others && $item->isDay(FreshRSS_Days::BEFORE_YESTERDAY, $today)) {
 			?><div class="day" id="day_before_yesterday"><?php
 				echo _t('before_yesterday');
-				?><span class="name"><?php echo $this->currentName; ?></span><?php
+				?><span class="name"><?php echo FreshRSS_Context::$name; ?></span><?php
 			?></div><?php
 			$display_others = false;
 		}