X-Git-Url: https://git.immae.eu/?p=github%2Fshaarli%2FShaarli.git;a=blobdiff_plain;f=plugins%2Fdemo_plugin%2Fdemo_plugin.php;fp=plugins%2Fdemo_plugin%2Fdemo_plugin.php;h=d89765cfcb2ca20bfbf34a4cda8a592669b73524;hp=15cfc2c51cd4889cc0d38f821e0ab856806a4167;hb=bcba6bd353161fab456b423e93571ab027d5423c;hpb=8997ae6c8e24286f7d47981eaf905e80d2481c10 diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index 15cfc2c5..d89765cf 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php @@ -17,6 +17,7 @@ require_once __DIR__ . '/DemoPluginController.php'; * and check user status with _LOGGEDIN_. */ +use Shaarli\Bookmark\Bookmark; use Shaarli\Config\ConfigManager; use Shaarli\Plugin\PluginManager; use Shaarli\Render\TemplatePage; @@ -263,6 +264,17 @@ function hook_demo_plugin_render_linklist($data) } $data['action_plugin'][] = $action; + // Action to trigger custom filter hiding bookmarks not containing 'e' letter in their description + $action = [ + 'attr' => [ + 'href' => '?e', + 'title' => 'Hide bookmarks without "e" in their description.', + ], + 'html' => 'e', + 'on' => isset($_GET['e']) + ]; + $data['action_plugin'][] = $action; + // link_plugin (for each link) foreach ($data['links'] as &$value) { $value['link_plugin'][] = ' DEMO \o/'; @@ -486,6 +498,27 @@ function hook_demo_plugin_save_plugin_parameters($data) return $data; } +/** + * This hook is called when a search is performed, on every search entry. + * It allows to add custom filters, and filter out additional link. + * + * For exemple here, we hide all bookmarks not containing the letter 'e' in their description. + * + * @param Bookmark $bookmark Search entry. Note that this is a Bookmark object, and not a link array. + * It should NOT be altered. + * @param array $context Additional info on the search performed. + * + * @return bool True if the bookmark should be kept in the search result, false to discard it. + */ +function hook_demo_plugin_filter_search_entry(Bookmark $bookmark, array $context): bool +{ + if (isset($_GET['e'])) { + return strpos($bookmark->getDescription(), 'e') !== false; + } + + return true; +} + /** * This function is never called, but contains translation calls for GNU gettext extraction. */