Jelajahi Sumber

Fix issue #236: balise link pour flux rss

Ajout d'une balise link pour indiquer l'url du flux RSS
Marien Fressinaud 12 tahun lalu
induk
melakukan
2d330e43f2
3 mengubah file dengan 23 tambahan dan 21 penghapusan
  1. 19 0
      app/controllers/indexController.php
  2. 3 0
      app/layout/layout.phtml
  3. 1 21
      app/layout/nav_menu.phtml

+ 19 - 0
app/controllers/indexController.php

@@ -12,6 +12,7 @@ class indexController extends ActionController {
 		$token_param = Request::param ('token', '');
 		$token_is_ok = ($token != '' && $token == $token_param);
 
+		// check if user is log in
 		if(login_is_conf ($this->view->conf) &&
 				!is_logged() &&
 				$this->view->conf->anonAccess() == 'no' &&
@@ -19,7 +20,25 @@ class indexController extends ActionController {
 			return;
 		}
 
+		// construction of RSS url of this feed
+		$params = Request::params ();
+		$params['output'] = 'rss';
+		if (isset ($params['search'])) {
+			$params['search'] = urlencode ($params['search']);
+		}
+		if (login_is_conf($this->view->conf) &&
+				$this->view->conf->anonAccess() == 'no' &&
+				$token != '') {
+			$params['token'] = $token;
+		}
+		$this->view->rss_url = array (
+			'c' => 'index',
+			'a' => 'index',
+			'params' => $params
+		);
+
 		if ($output == 'rss') {
+			// no layout for RSS output
 			$this->view->_useLayout (false);
 		} else {
 			if(!$output) {

+ 3 - 0
app/layout/layout.phtml

@@ -5,6 +5,9 @@
 		<meta name="viewport" content="initial-scale=1.0" />
 		<link rel="icon" type="image/x-icon" href="<?php echo Url::display ('/favicon.ico'); ?>" />
 		<link rel="icon" type="image/png" href="<?php echo Url::display ('/favicon.ico'); ?>" />
+		<?php if (isset ($this->rss_url)) { ?>
+		<link rel="alternate" type="application/rss+xml" title="<?php echo View::title(); ?>" href="<?php echo Url::display ($this->rss_url); ?>" />
+		<?php } ?>
 		<?php echo self::headTitle (); ?>
 		<?php echo self::headStyle (); ?>
 		<?php echo self::headScript (); ?>

+ 1 - 21
app/layout/nav_menu.phtml

@@ -122,27 +122,7 @@
 			</li>
 			<?php } ?>
 			<li class="item">
-				<?php
-					$params = Request::params ();
-					$params['output'] = 'rss';
-					if (isset ($params['search'])) {
-						$params['search'] = urlencode ($params['search']);
-					}
-
-					$token = $this->conf->token ();
-					if (login_is_conf($this->conf) &&
-							$this->conf->anonAccess() == 'no' &&
-							$token != '') {
-						$params['token'] = $token;
-					}
-
-					$url = array (
-						'c' => 'index',
-						'a' => 'index',
-						'params' => $params
-					);
-				?>
-				<a class="view_rss" target="_blank" rel="alternate" type="application/rss+xml" href="<?php echo Url::display ($url); ?>">
+				<a class="view_rss" target="_blank" href="<?php echo Url::display ($this->rss_url); ?>">
 					<?php echo Translate::t ('rss_view'); ?>
 				</a>
 			</li>