aboutsummaryrefslogtreecommitdiffhomepage
path: root/plugins
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2021-02-04 11:11:33 +0100
committerGitHub <noreply@github.com>2021-02-04 11:11:33 +0100
commit9db1ccdf2ce8381e1f3acb581d3c6a6def095d8c (patch)
tree97a618b77d327a5f963c91522988e24db5a9e158 /plugins
parent8997ae6c8e24286f7d47981eaf905e80d2481c10 (diff)
parentbcba6bd353161fab456b423e93571ab027d5423c (diff)
downloadShaarli-master.tar.gz
Shaarli-master.tar.zst
Shaarli-master.zip
Merge pull request #1698 from ArthurHoaro/feature/plugins-search-filterHEADmaster
New plugin hook: ability to add custom filters to Shaarli search engine
Diffstat (limited to 'plugins')
-rw-r--r--plugins/demo_plugin/demo_plugin.php33
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
20use Shaarli\Bookmark\Bookmark;
20use Shaarli\Config\ConfigManager; 21use Shaarli\Config\ConfigManager;
21use Shaarli\Plugin\PluginManager; 22use Shaarli\Plugin\PluginManager;
22use Shaarli\Render\TemplatePage; 23use 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 */
513function 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 */
492function demo_dummy_translation() 525function demo_dummy_translation()