diff options
Diffstat (limited to 'plugins/demo_plugin')
-rw-r--r-- | plugins/demo_plugin/DemoPluginController.php | 24 | ||||
-rw-r--r-- | plugins/demo_plugin/demo_plugin.php | 64 |
2 files changed, 65 insertions, 23 deletions
diff --git a/plugins/demo_plugin/DemoPluginController.php b/plugins/demo_plugin/DemoPluginController.php new file mode 100644 index 00000000..b8ace9c8 --- /dev/null +++ b/plugins/demo_plugin/DemoPluginController.php | |||
@@ -0,0 +1,24 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Shaarli\DemoPlugin; | ||
6 | |||
7 | use Shaarli\Front\Controller\Admin\ShaarliAdminController; | ||
8 | use Slim\Http\Request; | ||
9 | use Slim\Http\Response; | ||
10 | |||
11 | class DemoPluginController extends ShaarliAdminController | ||
12 | { | ||
13 | public function index(Request $request, Response $response): Response | ||
14 | { | ||
15 | $this->assignView( | ||
16 | 'content', | ||
17 | '<div class="center">' . | ||
18 | 'This is a demo page. I have access to Shaarli container, so I\'m free to do whatever I want here.' . | ||
19 | '</div>' | ||
20 | ); | ||
21 | |||
22 | return $response->write($this->render('pluginscontent')); | ||
23 | } | ||
24 | } | ||
diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index defb01f7..15cfc2c5 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php | |||
@@ -1,4 +1,5 @@ | |||
1 | <?php | 1 | <?php |
2 | |||
2 | /** | 3 | /** |
3 | * Demo Plugin. | 4 | * Demo Plugin. |
4 | * | 5 | * |
@@ -6,6 +7,8 @@ | |||
6 | * Can be used by plugin developers to make their own plugin. | 7 | * Can be used by plugin developers to make their own plugin. |
7 | */ | 8 | */ |
8 | 9 | ||
10 | require_once __DIR__ . '/DemoPluginController.php'; | ||
11 | |||
9 | /* | 12 | /* |
10 | * RENDER HEADER, INCLUDES, FOOTER | 13 | * RENDER HEADER, INCLUDES, FOOTER |
11 | * | 14 | * |
@@ -59,6 +62,17 @@ function demo_plugin_init($conf) | |||
59 | return $errors; | 62 | return $errors; |
60 | } | 63 | } |
61 | 64 | ||
65 | function demo_plugin_register_routes(): array | ||
66 | { | ||
67 | return [ | ||
68 | [ | ||
69 | 'method' => 'GET', | ||
70 | 'route' => '/custom', | ||
71 | 'callable' => 'Shaarli\DemoPlugin\DemoPluginController:index', | ||
72 | ], | ||
73 | ]; | ||
74 | } | ||
75 | |||
62 | /** | 76 | /** |
63 | * Hook render_header. | 77 | * Hook render_header. |
64 | * Executed on every page render. | 78 | * Executed on every page render. |
@@ -82,14 +96,14 @@ function hook_demo_plugin_render_header($data) | |||
82 | * A link is an array of its attributes (key="value"), | 96 | * A link is an array of its attributes (key="value"), |
83 | * and a mandatory `html` key, which contains its value. | 97 | * and a mandatory `html` key, which contains its value. |
84 | */ | 98 | */ |
85 | $button = array( | 99 | $button = [ |
86 | 'attr' => array ( | 100 | 'attr' => [ |
87 | 'href' => '#', | 101 | 'href' => '#', |
88 | 'class' => 'mybutton', | 102 | 'class' => 'mybutton', |
89 | 'title' => 'hover me', | 103 | 'title' => 'hover me', |
90 | ), | 104 | ], |
91 | 'html' => 'DEMO buttons toolbar', | 105 | 'html' => 'DEMO buttons toolbar', |
92 | ); | 106 | ]; |
93 | $data['buttons_toolbar'][] = $button; | 107 | $data['buttons_toolbar'][] = $button; |
94 | } | 108 | } |
95 | 109 | ||
@@ -115,29 +129,29 @@ function hook_demo_plugin_render_header($data) | |||
115 | * <input input-2-attribute-1="input 2 attribute 1 value"> | 129 | * <input input-2-attribute-1="input 2 attribute 1 value"> |
116 | * </form> | 130 | * </form> |
117 | */ | 131 | */ |
118 | $form = array( | 132 | $form = [ |
119 | 'attr' => array( | 133 | 'attr' => [ |
120 | 'method' => 'GET', | 134 | 'method' => 'GET', |
121 | 'action' => $data['_BASE_PATH_'] . '/', | 135 | 'action' => $data['_BASE_PATH_'] . '/', |
122 | 'class' => 'addform', | 136 | 'class' => 'addform', |
123 | ), | 137 | ], |
124 | 'inputs' => array( | 138 | 'inputs' => [ |
125 | array( | 139 | [ |
126 | 'type' => 'text', | 140 | 'type' => 'text', |
127 | 'name' => 'demo', | 141 | 'name' => 'demo', |
128 | 'placeholder' => 'demo', | 142 | 'placeholder' => 'demo', |
129 | ) | 143 | ] |
130 | ) | 144 | ] |
131 | ); | 145 | ]; |
132 | $data['fields_toolbar'][] = $form; | 146 | $data['fields_toolbar'][] = $form; |
133 | } | 147 | } |
134 | // Another button always displayed | 148 | // Another button always displayed |
135 | $button = array( | 149 | $button = [ |
136 | 'attr' => array( | 150 | 'attr' => [ |
137 | 'href' => '#', | 151 | 'href' => '#', |
138 | ), | 152 | ], |
139 | 'html' => 'Demo', | 153 | 'html' => 'Demo', |
140 | ); | 154 | ]; |
141 | $data['buttons_toolbar'][] = $button; | 155 | $data['buttons_toolbar'][] = $button; |
142 | 156 | ||
143 | return $data; | 157 | return $data; |
@@ -187,7 +201,7 @@ function hook_demo_plugin_render_includes($data) | |||
187 | function hook_demo_plugin_render_footer($data) | 201 | function hook_demo_plugin_render_footer($data) |
188 | { | 202 | { |
189 | // Footer text | 203 | // Footer text |
190 | $data['text'][] = '<br>'. demo_plugin_t('Shaarli is now enhanced by the awesome demo_plugin.'); | 204 | $data['text'][] = '<br>' . demo_plugin_t('Shaarli is now enhanced by the awesome demo_plugin.'); |
191 | 205 | ||
192 | // Free elements at the end of the page. | 206 | // Free elements at the end of the page. |
193 | $data['endofpage'][] = '<marquee id="demo_marquee">' . | 207 | $data['endofpage'][] = '<marquee id="demo_marquee">' . |
@@ -229,13 +243,13 @@ function hook_demo_plugin_render_linklist($data) | |||
229 | * and a mandatory `html` key, which contains its value. | 243 | * and a mandatory `html` key, which contains its value. |
230 | * It's also recommended to add key 'on' or 'off' for theme rendering. | 244 | * It's also recommended to add key 'on' or 'off' for theme rendering. |
231 | */ | 245 | */ |
232 | $action = array( | 246 | $action = [ |
233 | 'attr' => array( | 247 | 'attr' => [ |
234 | 'href' => '?up', | 248 | 'href' => '?up', |
235 | 'title' => 'Uppercase!', | 249 | 'title' => 'Uppercase!', |
236 | ), | 250 | ], |
237 | 'html' => '←', | 251 | 'html' => '←', |
238 | ); | 252 | ]; |
239 | 253 | ||
240 | if (isset($_GET['up'])) { | 254 | if (isset($_GET['up'])) { |
241 | // Manipulate link data | 255 | // Manipulate link data |
@@ -275,7 +289,7 @@ function hook_demo_plugin_render_linklist($data) | |||
275 | function hook_demo_plugin_render_editlink($data) | 289 | function hook_demo_plugin_render_editlink($data) |
276 | { | 290 | { |
277 | // Load HTML into a string | 291 | // Load HTML into a string |
278 | $html = file_get_contents(PluginManager::$PLUGINS_PATH .'/demo_plugin/field.html'); | 292 | $html = file_get_contents(PluginManager::$PLUGINS_PATH . '/demo_plugin/field.html'); |
279 | 293 | ||
280 | // Replace value in HTML if it exists in $data | 294 | // Replace value in HTML if it exists in $data |
281 | if (!empty($data['link']['stuff'])) { | 295 | if (!empty($data['link']['stuff'])) { |
@@ -303,7 +317,11 @@ function hook_demo_plugin_render_editlink($data) | |||
303 | function hook_demo_plugin_render_tools($data) | 317 | function hook_demo_plugin_render_tools($data) |
304 | { | 318 | { |
305 | // field_plugin | 319 | // field_plugin |
306 | $data['tools_plugin'][] = 'tools_plugin'; | 320 | $data['tools_plugin'][] = '<div class="tools-item"> |
321 | <a href="' . $data['_BASE_PATH_'] . '/plugin/demo_plugin/custom"> | ||
322 | <span class="pure-button pure-u-lg-2-3 pure-u-3-4">Demo Plugin Custom Route</span> | ||
323 | </a> | ||
324 | </div>'; | ||
307 | 325 | ||
308 | return $data; | 326 | return $data; |
309 | } | 327 | } |