فهرست منبع

Add a new hook in the UI (#8054)

* Add a new hook in the UI

The new hook allows extension to add their own tool bar to navigate between
entries. For instance, if the user wants less or more buttons that what's
available by default.

See #7912
See #7913

* add link data to ease navigation
Alexis Degrugillier 6 ماه پیش
والد
کامیت
032316155c
4فایلهای تغییر یافته به همراه37 افزوده شده و 28 حذف شده
  1. 6 2
      app/views/index/normal.phtml
  2. 1 0
      docs/en/developers/03_Backend/05_Extensions.md
  3. 2 0
      docs/fr/developers/03_Backend/05_Extensions.md
  4. 28 26
      lib/Minz/HookType.php

+ 6 - 2
app/views/index/normal.phtml

@@ -87,6 +87,7 @@ $today = @strtotime('today');
 		?>" data-entry="<?= $this->entry->id()
 		?>" data-entry="<?= $this->entry->id()
 		?>" data-feed="<?= $this->feed->id()
 		?>" data-feed="<?= $this->feed->id()
 		?>" data-priority="<?= $this->feed->priority()
 		?>" data-priority="<?= $this->feed->priority()
+		?>" data-link="<?= $this->entry->link()
 		?>"><?php
 		?>"><?php
 			$this->renderHelper('index/normal/entry_header');
 			$this->renderHelper('index/normal/entry_header');
 			if ($this->feed === null || $this->entry === null) {
 			if ($this->feed === null || $this->entry === null) {
@@ -203,6 +204,9 @@ $today = @strtotime('today');
 </a>
 </a>
 
 
 <?php
 <?php
-	if ($nbEntries > 0 && FreshRSS_Context::userConf()->show_nav_buttons) {
-		$this->partial('nav_entries');
+	if ($nbEntries > 0) {
+		echo Minz_ExtensionManager::callHookString(Minz_HookType::NavEntries);
+		if (FreshRSS_Context::userConf()->show_nav_buttons) {
+			$this->partial('nav_entries');
+		}
 	}
 	}

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

@@ -191,6 +191,7 @@ Example response for a `query_icon_info` request:
 * `menu_admin_entry` (`function() -> string`): add an entry at the end of the "Administration" menu, the returned string must be valid HTML (e.g. `<li class="item active"><a href="url">New entry</a></li>`).
 * `menu_admin_entry` (`function() -> string`): add an entry at the end of the "Administration" menu, the returned string must be valid HTML (e.g. `<li class="item active"><a href="url">New entry</a></li>`).
 * `menu_configuration_entry` (`function() -> string`): add an entry at the end of the "Configuration" menu, the returned string must be valid HTML (e.g. `<li class="item active"><a href="url">New entry</a></li>`).
 * `menu_configuration_entry` (`function() -> string`): add an entry at the end of the "Configuration" menu, the returned string must be valid HTML (e.g. `<li class="item active"><a href="url">New entry</a></li>`).
 * `menu_other_entry` (`function() -> string`): add an entry at the end of the header dropdown menu (i.e. after the "About" entry), the returned string must be valid HTML (e.g. `<li class="item active"><a href="url">New entry</a></li>`).
 * `menu_other_entry` (`function() -> string`): add an entry at the end of the header dropdown menu (i.e. after the "About" entry), the returned string must be valid HTML (e.g. `<li class="item active"><a href="url">New entry</a></li>`).
+* `nav_entries` (`function() -> string`): will add DOM elements before the navigation buttons.
 * `nav_menu` (`function() -> string`): will be executed if the navigation was built.
 * `nav_menu` (`function() -> string`): will be executed if the navigation was built.
 * `nav_reading_modes` (`function($reading_modes) -> array | null`): **TODO** add documentation.
 * `nav_reading_modes` (`function($reading_modes) -> array | null`): **TODO** add documentation.
 * `post_update` (`function(none) -> none`): **TODO** add documentation.
 * `post_update` (`function(none) -> none`): **TODO** add documentation.

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

@@ -267,6 +267,8 @@ The following events are available:
 	the header dropdown menu (i.e. after the "About" entry), the returned
 	the header dropdown menu (i.e. after the "About" entry), the returned
 	string must be valid HTML (e.g. `<li class="item active"><a href="url">New
 	string must be valid HTML (e.g. `<li class="item active"><a href="url">New
 	entry</a></li>`)
 	entry</a></li>`)
+* `nav_entries` (`function() -> string`): ajoute des éléments DOM avant les boutons de navigation.
+* `nav_menu` (`function() -> string`): sera exécuté si la navigation est générée.
 * `nav_reading_modes` (`function($reading_modes) -> array | null`): **TODO**
 * `nav_reading_modes` (`function($reading_modes) -> array | null`): **TODO**
 	add documentation
 	add documentation
 * `post_update` (`function(none) -> none`): **TODO** add documentation
 * `post_update` (`function(none) -> none`): **TODO** add documentation

+ 28 - 26
lib/Minz/HookType.php

@@ -22,6 +22,7 @@ enum Minz_HookType: string {
 	case MenuAdminEntry = 'menu_admin_entry';	// function() -> string
 	case MenuAdminEntry = 'menu_admin_entry';	// function() -> string
 	case MenuConfigurationEntry = 'menu_configuration_entry';	// function() -> string
 	case MenuConfigurationEntry = 'menu_configuration_entry';	// function() -> string
 	case MenuOtherEntry = 'menu_other_entry';	// function() -> string
 	case MenuOtherEntry = 'menu_other_entry';	// function() -> string
+	case NavEntries = 'nav_entries'; // function() -> string
 	case NavMenu = 'nav_menu';	// function() -> string
 	case NavMenu = 'nav_menu';	// function() -> string
 	case NavReadingModes = 'nav_reading_modes';	// function($readingModes = array) -> array | null
 	case NavReadingModes = 'nav_reading_modes';	// function($readingModes = array) -> array | null
 	case PostUpdate = 'post_update';	// function(none) -> none
 	case PostUpdate = 'post_update';	// function(none) -> none
@@ -31,35 +32,36 @@ enum Minz_HookType: string {
 
 
 	public function signature(): Minz_HookSignature {
 	public function signature(): Minz_HookSignature {
 		switch ($this) {
 		switch ($this) {
-			case Minz_HookType::ApiMisc:
-			case Minz_HookType::FreshrssInit:
-			case Minz_HookType::FreshrssUserMaintenance:
-			case Minz_HookType::PostUpdate:
+			case self::ApiMisc:
+			case self::FreshrssInit:
+			case self::FreshrssUserMaintenance:
+			case self::PostUpdate:
 				return Minz_HookSignature::NoneToNone;
 				return Minz_HookSignature::NoneToNone;
-			case Minz_HookType::BeforeLoginBtn:
-			case Minz_HookType::MenuAdminEntry:
-			case Minz_HookType::MenuConfigurationEntry:
-			case Minz_HookType::MenuOtherEntry:
-			case Minz_HookType::NavMenu:
+			case self::BeforeLoginBtn:
+			case self::MenuAdminEntry:
+			case self::MenuConfigurationEntry:
+			case self::MenuOtherEntry:
+			case self::NavEntries:
+			case self::NavMenu:
 				return Minz_HookSignature::NoneToString;
 				return Minz_HookSignature::NoneToString;
-			case Minz_HookType::CheckUrlBeforeAdd:
-			case Minz_HookType::EntryBeforeDisplay:
-			case Minz_HookType::EntryBeforeInsert:
-			case Minz_HookType::EntryBeforeAdd:
-			case Minz_HookType::EntryBeforeUpdate:
-			case Minz_HookType::FeedBeforeActualize:
-			case Minz_HookType::FeedBeforeInsert:
-			case Minz_HookType::JsVars:
-			case Minz_HookType::NavReadingModes:
-			case Minz_HookType::ViewModes:
+			case self::CheckUrlBeforeAdd:
+			case self::EntryBeforeDisplay:
+			case self::EntryBeforeInsert:
+			case self::EntryBeforeAdd:
+			case self::EntryBeforeUpdate:
+			case self::FeedBeforeActualize:
+			case self::FeedBeforeInsert:
+			case self::JsVars:
+			case self::NavReadingModes:
+			case self::ViewModes:
 				return Minz_HookSignature::OneToOne;
 				return Minz_HookSignature::OneToOne;
-			case Minz_HookType::CustomFaviconBtnUrl:
-			case Minz_HookType::CustomFaviconHash:
-			case Minz_HookType::EntriesFavorite:
-			case Minz_HookType::EntryAutoRead:
-			case Minz_HookType::EntryAutoUnread:
-			case Minz_HookType::SimplepieAfterInit:
-			case Minz_HookType::SimplepieBeforeInit:
+			case self::CustomFaviconBtnUrl:
+			case self::CustomFaviconHash:
+			case self::EntriesFavorite:
+			case self::EntryAutoRead:
+			case self::EntryAutoUnread:
+			case self::SimplepieAfterInit:
+			case self::SimplepieBeforeInit:
 				return Minz_HookSignature::PassArguments;
 				return Minz_HookSignature::PassArguments;
 			default:
 			default:
 				throw new \RuntimeException('The hook is not configured!');
 				throw new \RuntimeException('The hook is not configured!');