Ver código fonte

Extend hooks (#2704)

It adds two new hooks to have more options for influencing with extensions.
Clemens Neubauer 6 anos atrás
pai
commit
08c6a1bdc1
2 arquivos alterados com 20 adições e 0 exclusões
  1. 12 0
      app/Controllers/feedController.php
  2. 8 0
      lib/Minz/ExtensionManager.php

+ 12 - 0
app/Controllers/feedController.php

@@ -47,6 +47,12 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 
 		$url = trim($url);
 
+		/** @var $url */
+		$url = Minz_ExtensionManager::callHook('check_url_before_add', $url);
+		if (null === $url) {
+			throw new FreshRSS_FeedNotAdded_Exception($url, $title);
+		}
+
 		$cat = null;
 		if ($new_cat_name != '') {
 			$new_cat_id = $catDAO->addCategory(array('name' => $new_cat_name));
@@ -274,6 +280,12 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 		$updated_feeds = 0;
 		$nb_new_articles = 0;
 		foreach ($feeds as $feed) {
+			/** @var FreshRSS_Feed $feed */
+			$feed = Minz_ExtensionManager::callHook('feed_before_actualize', $feed);
+			if (null === $feed) {
+				continue;
+			}
+
 			$url = $feed->url();	//For detection of HTTP 301
 
 			$pubSubHubbubEnabled = $pubsubhubbubEnabledGeneral && $feed->pubSubHubbubEnabled();

+ 8 - 0
lib/Minz/ExtensionManager.php

@@ -15,6 +15,10 @@ class Minz_ExtensionManager {
 
 	// List of available hooks. Please keep this list sorted.
 	private static $hook_list = array(
+		'check_url_before_add' => array(  // function($url) -> Url | null
+			'list' => array(),
+			'signature' => 'OneToOne',
+		),
 		'entry_before_display' => array(  // function($entry) -> Entry | null
 			'list' => array(),
 			'signature' => 'OneToOne',
@@ -23,6 +27,10 @@ class Minz_ExtensionManager {
 			'list' => array(),
 			'signature' => 'OneToOne',
 		),
+		'feed_before_actualize' => array(  // function($feed) -> Feed | null
+			'list' => array(),
+			'signature' => 'OneToOne',
+		),
 		'feed_before_insert' => array(  // function($feed) -> Feed | null
 			'list' => array(),
 			'signature' => 'OneToOne',