Procházet zdrojové kódy

Refactoring of indexController

Global view has been moved to a different action (all is not working)

See https://github.com/marienfressinaud/FreshRSS/issues/634
and https://github.com/marienfressinaud/FreshRSS/issues/655
Marien Fressinaud před 11 roky
rodič
revize
8a7bab3a55

+ 1 - 1
app/Controllers/errorController.php

@@ -37,7 +37,7 @@ class FreshRSS_error_Controller extends Minz_ActionController {
 		if ($this->view->errorMessage == '') {
 			switch($code_int) {
 			case 403:
-				$this->view->errorMessage = _t('forbidden_access');
+				$this->view->errorMessage = _t('access_denied');
 				break;
 			case 404:
 			default:

+ 25 - 8
app/Controllers/indexController.php

@@ -1,5 +1,8 @@
 <?php
 
+/**
+ * This class handles main actions of FreshRSS.
+ */
 class FreshRSS_index_Controller extends Minz_ActionController {
 	private $nb_not_read_cat = 0;
 
@@ -12,10 +15,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 			$token_param = Minz_Request::param('token', '');
 			$token_is_ok = ($token != '' && $token === $token_param);
 			if ($output === 'rss' && !$token_is_ok) {
-				Minz_Error::error(
-					403,
-					array('error' => array(_t('access_denied')))
-				);
+				Minz_Error::error(403);
 				return;
 			} elseif ($output !== 'rss') {
 				// "hard" redirection is not required, just ask dispatcher to
@@ -201,17 +201,34 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 			return false;
 		}
 	}
+
+	/**
+	 * This action displays the global view of FreshRSS.
+	 */
+	public function globalAction() {
+		if (!FreshRSS_Auth::hasAccess() && !Minz_Configuration::allowAnonymous()) {
+			Minz_Error::error(403);
+		}
+
+		Minz_View::appendScript(Minz_Url::display('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js')));
+
+		$catDAO = new FreshRSS_CategoryDAO();
+		$this->view->categories = $catDAO->listCategories();
+	}
 	
+	/**
+	 * This action displays the about page of FreshRSS.
+	 */
 	public function aboutAction() {
 		Minz_View::prependTitle(_t('about') . ' · ');
 	}
 
+	/**
+	 * This action displays logs of FreshRSS for the current user.
+	 */
 	public function logsAction() {
 		if (!FreshRSS_Auth::hasAccess()) {
-			Minz_Error::error(
-				403,
-				array('error' => array(_t('access_denied')))
-			);
+			Minz_Error::error(403);
 		}
 
 		Minz_View::prependTitle(_t('logs') . ' · ');

+ 1 - 1
app/layout/nav_menu.phtml

@@ -240,7 +240,7 @@
 			<?php echo _i("view-normal"); ?>
 		</a>
 
-		<?php $url_output['params']['output'] = 'global'; ?>
+		<?php $url_output['a'] = 'global'; unset($url_output['params']['output']); ?>
 		<a class="view_global btn <?php echo $actual_view == 'global'? 'active' : ''; ?>" title="<?php echo _t('global_view'); ?>" href="<?php echo Minz_Url::display($url_output); ?>">
 			<?php echo _i("view-global"); ?>
 		</a>

+ 0 - 53
app/views/helpers/view/global_view.phtml

@@ -1,53 +0,0 @@
-<?php $this->partial('nav_menu'); ?>
-
-<?php if (!empty($this->entries)) { ?>
-<div id="stream" class="global categories">
-<?php
-	$arUrl = array('c' => 'index', 'a' => 'index', 'params' => array());
-	if (FreshRSS_Context::$conf->view_mode !== 'normal') {
-		$arUrl['params']['output'] = 'normal';
-	}
-	$p = Minz_Request::param('state', '');
-	if (($p != '') && (FreshRSS_Context::$conf->default_view !== $p)) {
-		$arUrl['params']['state'] = $p;
-	}
-
-	foreach ($this->cat_aside as $cat) {
-		$feeds = $cat->feeds();
-		if (!empty($feeds)) {
-?>
-	<div class="box-category">
-		<div class="category">
-			<a data-unread="<?php echo formatNumber($cat->nbNotRead()); ?>" class="btn" href="<?php $arUrl['params']['get'] = 'c_' . $cat->id(); echo Minz_Url::display($arUrl); ?>">
-			<?php echo $cat->name(); ?>
-			</a>
-		</div>
-		<ul class="feeds">
-			<?php foreach ($feeds as $feed) { ?>
-			<?php $not_read = $feed->nbNotRead(); ?>
-			<li id="f_<?php echo $feed->id(); ?>" class="item<?php echo $feed->inError() ? ' error' : ''; ?><?php echo $feed->nbEntries() == 0 ? ' empty' : ''; ?>">
-				<img class="favicon" src="<?php echo $feed->favicon(); ?>" alt="✇" />
-				<a class="feed" data-unread="<?php echo formatNumber($feed->nbNotRead()); ?>" data-priority="<?php echo $feed->priority(); ?>" href="<?php $arUrl['params']['get'] = 'f_' . $feed->id(); echo Minz_Url::display($arUrl); ?>">
-				<?php echo $feed->name(); ?>
-				</a>
-			</li>
-			<?php } ?>
-		</ul>
-	</div>
-<?php
-		}
-	}
-?>
-</div>
-
-<div id="overlay"></div>
-<div id="panel"<?php echo FreshRSS_Context::$conf->display_posts ? '' : ' class="hide_posts"'; ?>>
-	<a class="close" href="#"><?php echo _i('close'); ?></a>
-</div>
-
-<?php } else { ?>
-<div id="stream" class="prompt alert alert-warn global">
-	<h2><?php echo _t('no_feed_to_display'); ?></h2>
-	<a href="<?php echo _url('subscription', 'index'); ?>"><?php echo _t('think_to_add'); ?></a><br /><br />
-</div>
-<?php } ?>

+ 46 - 0
app/views/index/global.phtml

@@ -0,0 +1,46 @@
+<?php //$this->partial('nav_menu'); ?>
+
+<div id="stream" class="global categories">
+<?php
+	$url_base = array(
+		'c' => 'index',
+		'a' => 'index',
+		'params' => array(
+			'state' => FreshRSS_Context::$state
+		)
+	);
+
+	foreach ($this->categories as $cat) {
+		$feeds = $cat->feeds();
+		$url_base['params']['get'] = 'c_' . $cat->id();
+
+		if (!empty($feeds)) {
+?>
+	<div class="box">
+		<div class="box-title"><a data-unread="<?php echo format_number($cat->nbNotRead()); ?>" href="<?php echo Minz_Url::display($url_base); ?>"><?php echo $cat->name(); ?></a></div>
+
+		<ul class="box-content">
+			<?php
+				foreach ($feeds as $feed) {
+					$nb_not_read = $feed->nbNotRead();
+					$error = $feed->inError() ? 'error ' : '';
+					$empty = $feed->nbEntries() === 0 ? 'empty ' : '';
+					$url_base['params']['get'] = 'f_' . $feed->id();
+			?>
+			<li class="item feed<?php echo $error, $empty; ?>">
+				<img class="favicon" src="<?php echo $feed->favicon(); ?>" alt="✇" />
+				<a data-unread="<?php echo format_number($feed->nbNotRead()); ?>" data-priority="<?php echo $feed->priority(); ?>" href="<?php echo Minz_Url::display($url_base); ?>"><?php echo $feed->name(); ?></a>
+			</li>
+			<?php } ?>
+		</ul>
+	</div>
+<?php
+		}
+	}
+?>
+</div>
+
+<div id="overlay"></div>
+<div id="panel"<?php echo FreshRSS_Context::$conf->display_posts ? '' : ' class="hide_posts"'; ?>>
+	<a class="close" href="#"><?php echo _i('close'); ?></a>
+</div>

+ 0 - 2
app/views/index/index.phtml

@@ -7,8 +7,6 @@ if (FreshRSS_Auth::hasAccess() || Minz_Configuration::allowAnonymous()) {
 		$this->renderHelper('view/normal_view');
 	} elseif ($output === 'reader') {
 		$this->renderHelper('view/reader_view');
-	} elseif ($output === 'global') {
-		$this->renderHelper('view/global_view');
 	} elseif ($output === 'rss') {
 		$this->renderHelper('view/rss_view');
 	} else {

+ 4 - 0
lib/lib_rss.php

@@ -60,6 +60,10 @@ function formatNumber($n, $precision = 0) {
 	return str_replace(' ', ' ',	//Espace insécable	//TODO: remplacer par une espace _fine_ insécable
 		number_format($n, $precision, '.', ' '));	//number_format does not seem to be Unicode-compatible
 }
+function format_number($n, $precision = 0) {
+	// TODO: coding style, prefer THIS function. Remove formatNumber.
+	return formatNumber($n, $precision);
+}
 
 function formatBytes($bytes, $precision = 2, $system = 'IEC') {
 	if ($system === 'IEC') {

+ 2 - 1
p/scripts/global_view.js

@@ -50,7 +50,8 @@ function init_close_panel() {
 }
 
 function init_global_view() {
-	$("#stream .box-category a").click(function () {
+	// TODO: should be based on generic classes.
+	$(".box a").click(function () {
 		var link = $(this).attr("href");
 
 		load_panel(link);