* Can be used by plugin developers to make their own plugin.
*/
+require_once __DIR__ . '/DemoPluginController.php';
+
/*
* RENDER HEADER, INCLUDES, FOOTER
*
* and check user status with _LOGGEDIN_.
*/
+use Shaarli\Bookmark\Bookmark;
use Shaarli\Config\ConfigManager;
use Shaarli\Plugin\PluginManager;
use Shaarli\Render\TemplatePage;
return $errors;
}
+function demo_plugin_register_routes(): array
+{
+ return [
+ [
+ 'method' => 'GET',
+ 'route' => '/custom',
+ 'callable' => 'Shaarli\DemoPlugin\DemoPluginController:index',
+ ],
+ ];
+}
+
/**
* Hook render_header.
* Executed on every page render.
}
$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/';
function hook_demo_plugin_render_tools($data)
{
// field_plugin
- $data['tools_plugin'][] = 'tools_plugin';
+ $data['tools_plugin'][] = '<div class="tools-item">
+ <a href="' . $data['_BASE_PATH_'] . '/plugin/demo_plugin/custom">
+ <span class="pure-button pure-u-lg-2-3 pure-u-3-4">Demo Plugin Custom Route</span>
+ </a>
+ </div>';
return $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.
*/