From 032316155c03ca1013644476b8f9413ba436b744 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Thu, 2 Oct 2025 09:33:53 -0400 Subject: 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 --- app/views/index/normal.phtml | 8 +++- docs/en/developers/03_Backend/05_Extensions.md | 1 + docs/fr/developers/03_Backend/05_Extensions.md | 2 + lib/Minz/HookType.php | 54 +++++++++++++------------- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/app/views/index/normal.phtml b/app/views/index/normal.phtml index 1b942ae17..cc54d10fd 100644 --- a/app/views/index/normal.phtml +++ b/app/views/index/normal.phtml @@ -87,6 +87,7 @@ $today = @strtotime('today'); ?>" data-entry="entry->id() ?>" data-feed="feed->id() ?>" data-priority="feed->priority() + ?>" data-link="entry->link() ?>">renderHelper('index/normal/entry_header'); if ($this->feed === null || $this->entry === null) { @@ -203,6 +204,9 @@ $today = @strtotime('today'); 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'); + } } diff --git a/docs/en/developers/03_Backend/05_Extensions.md b/docs/en/developers/03_Backend/05_Extensions.md index cfdb4e692..c24ee0569 100644 --- a/docs/en/developers/03_Backend/05_Extensions.md +++ b/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. `
  • New entry
  • `). * `menu_configuration_entry` (`function() -> string`): add an entry at the end of the "Configuration" menu, the returned string must be valid HTML (e.g. `
  • New entry
  • `). * `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. `
  • New entry
  • `). +* `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_reading_modes` (`function($reading_modes) -> array | null`): **TODO** add documentation. * `post_update` (`function(none) -> none`): **TODO** add documentation. diff --git a/docs/fr/developers/03_Backend/05_Extensions.md b/docs/fr/developers/03_Backend/05_Extensions.md index f790db5f4..a71919def 100644 --- a/docs/fr/developers/03_Backend/05_Extensions.md +++ b/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 string must be valid HTML (e.g. `
  • New entry
  • `) +* `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** add documentation * `post_update` (`function(none) -> none`): **TODO** add documentation diff --git a/lib/Minz/HookType.php b/lib/Minz/HookType.php index 0a9a311eb..0d96b8832 100644 --- a/lib/Minz/HookType.php +++ b/lib/Minz/HookType.php @@ -22,6 +22,7 @@ enum Minz_HookType: string { case MenuAdminEntry = 'menu_admin_entry'; // function() -> string case MenuConfigurationEntry = 'menu_configuration_entry'; // function() -> string case MenuOtherEntry = 'menu_other_entry'; // function() -> string + case NavEntries = 'nav_entries'; // function() -> string case NavMenu = 'nav_menu'; // function() -> string case NavReadingModes = 'nav_reading_modes'; // function($readingModes = array) -> array | null case PostUpdate = 'post_update'; // function(none) -> none @@ -31,35 +32,36 @@ enum Minz_HookType: string { public function signature(): Minz_HookSignature { 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; - 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; - 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; - 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; default: throw new \RuntimeException('The hook is not configured!'); -- cgit v1.2.3