Browse Source

Fix PHP Warning: Cannot modify header information headers already sent (#9267)

Closes #9229

I restored my accidently deleted patches with @Inverle fixes. This fix is still works perfectly. Sorry. (https://github.com/FreshRSS/FreshRSS/pull/9230)

How to test the feature manually:

With this change:
1. Go to FreshRSS UserCSS extension config
2. Enable the UserCSS and set the CSS code in it.
3. Go to FreshRSS feeds page.
4. Hit the ctrl + F5 button and see no errors in the nginx log.
András Marczinkó 18 hours ago
parent
commit
99ee090236
2 changed files with 6 additions and 1 deletions
  1. 2 1
      app/Controllers/extensionController.php
  2. 4 0
      app/views/extension/serve.phtml

+ 2 - 1
app/Controllers/extensionController.php

@@ -362,7 +362,8 @@ class FreshRSS_extension_Controller extends FreshRSS_ActionController {
 		header("Content-Disposition: inline; filename='{$filename}'");
 		header("Content-Disposition: inline; filename='{$filename}'");
 		header('Referrer-Policy: same-origin');
 		header('Referrer-Policy: same-origin');
 		if (file_exists(DATA_PATH . '/no-cache.txt') || !httpConditional($mtime, cacheSeconds: 604800, cachePrivacy: 2)) {
 		if (file_exists(DATA_PATH . '/no-cache.txt') || !httpConditional($mtime, cacheSeconds: 604800, cachePrivacy: 2)) {
-			echo $extension->getFile($filename);
+			$contents = $extension->getFile($filename);
+			$this->view->content = is_string($contents) ? $contents : '';
 		}
 		}
 	}
 	}
 }
 }

+ 4 - 0
app/views/extension/serve.phtml

@@ -0,0 +1,4 @@
+<?php
+declare(strict_types=1);
+/** @var FreshRSS_View $this */
+echo $this->content;