diff options
Diffstat (limited to 'plugins/demo_plugin')
-rw-r--r-- | plugins/demo_plugin/demo_plugin.php | 33 |
1 files changed, 33 insertions, 0 deletions
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'; | |||
17 | * and check user status with _LOGGEDIN_. | 17 | * and check user status with _LOGGEDIN_. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | use Shaarli\Bookmark\Bookmark; | ||
20 | use Shaarli\Config\ConfigManager; | 21 | use Shaarli\Config\ConfigManager; |
21 | use Shaarli\Plugin\PluginManager; | 22 | use Shaarli\Plugin\PluginManager; |
22 | use Shaarli\Render\TemplatePage; | 23 | use Shaarli\Render\TemplatePage; |
@@ -263,6 +264,17 @@ function hook_demo_plugin_render_linklist($data) | |||
263 | } | 264 | } |
264 | $data['action_plugin'][] = $action; | 265 | $data['action_plugin'][] = $action; |
265 | 266 | ||
267 | // Action to trigger custom filter hiding bookmarks not containing 'e' letter in their description | ||
268 | $action = [ | ||
269 | 'attr' => [ | ||
270 | 'href' => '?e', | ||
271 | 'title' => 'Hide bookmarks without "e" in their description.', | ||
272 | ], | ||
273 | 'html' => 'e', | ||
274 | 'on' => isset($_GET['e']) | ||
275 | ]; | ||
276 | $data['action_plugin'][] = $action; | ||
277 | |||
266 | // link_plugin (for each link) | 278 | // link_plugin (for each link) |
267 | foreach ($data['links'] as &$value) { | 279 | foreach ($data['links'] as &$value) { |
268 | $value['link_plugin'][] = ' DEMO \o/'; | 280 | $value['link_plugin'][] = ' DEMO \o/'; |
@@ -487,6 +499,27 @@ function hook_demo_plugin_save_plugin_parameters($data) | |||
487 | } | 499 | } |
488 | 500 | ||
489 | /** | 501 | /** |
502 | * This hook is called when a search is performed, on every search entry. | ||
503 | * It allows to add custom filters, and filter out additional link. | ||
504 | * | ||
505 | * For exemple here, we hide all bookmarks not containing the letter 'e' in their description. | ||
506 | * | ||
507 | * @param Bookmark $bookmark Search entry. Note that this is a Bookmark object, and not a link array. | ||
508 | * It should NOT be altered. | ||
509 | * @param array $context Additional info on the search performed. | ||
510 | * | ||
511 | * @return bool True if the bookmark should be kept in the search result, false to discard it. | ||
512 | */ | ||
513 | function hook_demo_plugin_filter_search_entry(Bookmark $bookmark, array $context): bool | ||
514 | { | ||
515 | if (isset($_GET['e'])) { | ||
516 | return strpos($bookmark->getDescription(), 'e') !== false; | ||
517 | } | ||
518 | |||
519 | return true; | ||
520 | } | ||
521 | |||
522 | /** | ||
490 | * This function is never called, but contains translation calls for GNU gettext extraction. | 523 | * This function is never called, but contains translation calls for GNU gettext extraction. |
491 | */ | 524 | */ |
492 | function demo_dummy_translation() | 525 | function demo_dummy_translation() |