ソースを参照

Add extension hook simplepie_after_init (#7007)

* Add extension hook simplepie_after_init
fix https://github.com/FreshRSS/FreshRSS/issues/7006

* Add documentation note

* fix doc get_headers

* Syntax void

* Forgotten code
Alexandre Alapetite 1 年間 前
コミット
278181572e

+ 1 - 0
app/Models/Feed.php

@@ -372,6 +372,7 @@ class FreshRSS_Feed extends Minz_Model {
 				}
 				Minz_ExtensionManager::callHook('simplepie_before_init', $simplePie, $this);
 				$simplePieResult = $simplePie->init();
+				Minz_ExtensionManager::callHook('simplepie_after_init', $simplePie, $this, $simplePieResult);
 
 				if ($simplePieResult === false || $simplePie->get_hash() === '' || !empty($simplePie->error())) {
 					$errorMessage = $simplePie->error();

+ 4 - 1
docs/en/developers/03_Backend/05_Extensions.md

@@ -178,7 +178,10 @@ The following events are available:
 * `nav_menu` (`function() -> string`): will be executed if the navigation was built.
 * `nav_reading_modes` (`function($reading_modes) -> array | null`): **TODO** add documentation.
 * `post_update` (`function(none) -> none`): **TODO** add documentation.
-* `simplepie_before_init` (`function($simplePie, $feed) -> none`): **TODO** add documentation.
+* `simplepie_after_init` (`function(\SimplePie\SimplePie $simplePie, FreshRSS_Feed $feed, bool $result): void`): Triggered after fetching an RSS/Atom feed with SimplePie. Useful for instance to get the HTTP response headers (e.g. `$simplePie->data['headers']`).
+* `simplepie_before_init` (`function(\SimplePie\SimplePie $simplePie, FreshRSS_Feed $feed): void`): Triggered before fetching an RSS/Atom feed with SimplePie.
+
+> ℹ️ Note: the `simplepie_*` hooks are only fired for feeds using SimplePie via pull, i.e. normal RSS/Atom feeds. This excludes WebSub (push), and the various HTML or JSON Web scraping methods.
 
 ### Injecting CDN content
 

+ 4 - 2
docs/fr/developers/03_Backend/05_Extensions.md

@@ -257,8 +257,10 @@ The following events are available:
 * `nav_reading_modes` (`function($reading_modes) -> array | null`): **TODO**
 	add documentation
 * `post_update` (`function(none) -> none`): **TODO** add documentation
-* `simplepie_before_init` (`function($simplePie, $feed) -> none`): **TODO**
-	add documentation
+* `simplepie_after_init` (`function(\SimplePie\SimplePie $simplePie, FreshRSS_Feed $feed, bool $result): void`): Triggered after fetching an RSS/Atom feed with SimplePie. Useful for instance to get the HTTP response headers (e.g. `$simplePie->data['headers']`).
+* `simplepie_before_init` (`function(\SimplePie\SimplePie $simplePie, FreshRSS_Feed $feed): void`): Triggered before fetching an RSS/Atom feed with SimplePie.
+
+> ℹ️ Note: the `simplepie_*` hooks are only fired for feeds using SimplePie via pull, i.e. normal RSS/Atom feeds. This excludes WebSub (push), and the various HTML or JSON Web scraping methods.
 
 ### Writing your own configure.phtml
 

+ 7 - 3
lib/Minz/ExtensionManager.php

@@ -90,10 +90,14 @@ final class Minz_ExtensionManager {
 			'list' => array(),
 			'signature' => 'NoneToNone',
 		),
-		'simplepie_before_init' => array(	// function($simplePie, $feed) -> none
-			'list' => array(),
+		'simplepie_after_init' => [	// function(\SimplePie\SimplePie $simplePie, FreshRSS_Feed $feed, bool $result): void
+			'list' => [],
 			'signature' => 'PassArguments',
-		),
+		],
+		'simplepie_before_init' => [	// function(\SimplePie\SimplePie $simplePie, FreshRSS_Feed $feed): void
+			'list' => [],
+			'signature' => 'PassArguments',
+		],
 	];
 
 	/** Remove extensions and hooks from a previous initialisation */