devel:plugin_programming_tips
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
devel:plugin_programming_tips [2023-09-20 23:01] – [User lists and info] Klap-in | devel:plugin_programming_tips [2023-09-20 23:34] (current) – Klap-in | ||
---|---|---|---|
Line 195: | Line 195: | ||
Create an [[Action Plugin]] which should contain: | Create an [[Action Plugin]] which should contain: | ||
<code php lib/ | <code php lib/ | ||
- | /* | + | use dokuwiki\Extension\ActionPlugin; |
- | * plugin should | + | use dokuwiki\Extension\EventHandler; |
- | * with the dokuwiki's event controller | + | use dokuwiki\Extension\Event; |
- | */ | + | |
- | function register(Doku_Event_Handler $controller) { | + | |
- | $controller-> | + | |
- | } | + | |
- | + | ||
- | /** | + | |
- | * handle ajax requests | + | |
- | */ | + | |
- | function _ajax_call(Doku_Event $event, $param) { | + | |
- | if ($event-> | + | |
- | return; | + | |
- | } | + | |
- | //no other ajax call handlers needed | + | |
- | $event-> | + | |
- | $event-> | + | |
- | //e.g. access additional request variables | + | class action_plugin_example extends ActionPlugin { |
- | | + | |
- | $name = $INPUT->str('name'); | + | /** |
+ | * plugin should use this method to register its handlers | ||
+ | * with the dokuwiki' | ||
+ | */ | ||
+ | | ||
+ | | ||
+ | } | ||
| | ||
- | //data | + | /** |
- | $data = array(); | + | * handle ajax requests |
+ | */ | ||
+ | | ||
+ | if ($event-> | ||
+ | return; | ||
+ | } | ||
+ | //no other ajax call handlers needed | ||
+ | $event-> | ||
+ | $event-> | ||
- | | + | |
- | $json = new JSON(); | + | |
+ | $name = $INPUT-> | ||
| | ||
- | | + | //data |
- | header(' | + | $data = []; |
- | echo $json-> | + | |
+ | | ||
+ | header(' | ||
+ | echo json_encode($data); | ||
+ | } | ||
} | } | ||
</ | </ | ||
Line 276: | Line 280: | ||
Example: | Example: | ||
<code php> | <code php> | ||
+ | global $INPUT; | ||
+ | |||
// we are parsing a submitted comment... | // we are parsing a submitted comment... | ||
- | if (isset($_REQUEST[' | + | if ($INPUT-> |
return false; | return false; | ||
} | } | ||
Line 289: | Line 295: | ||
The [[plugin: | The [[plugin: | ||
- | It also let the possibility to developers, to send more data about usage. It can be used by plugins developers to know if a given obsolete feature is still used. To do it, you need to subscribe to the [[devel: | + | It also let the possibility to developers, to send more data about usage. It can be used by plugins developers to know if a given obsolete feature is still used. To do it, you need to subscribe to the [[devel: |
Example: | Example: | ||
<code php action.php> | <code php action.php> | ||
- | public function register(Doku_Event_Handler | + | use dokuwiki\Extension\ActionPlugin; |
- | $controller-> | + | use dokuwiki\Extension\EventHandler; |
- | } | + | use dokuwiki\Extension\Event; |
+ | |||
+ | class action_plugin_example extends ActionPlugin { | ||
+ | | ||
+ | $controller-> | ||
+ | } | ||
| | ||
- | public function | + | |
- | $event-> | + | $event-> |
- | /* or: | + | |
- | $event-> | + | $event-> |
- | ' | + | ' |
- | ' | + | ' |
- | ); | + | ]; |
- | */ | + | */ |
+ | } | ||
} | } | ||
</ | </ | ||
A plugin which uses this feature is the [[plugin: | A plugin which uses this feature is the [[plugin: |
devel/plugin_programming_tips.txt · Last modified: 2023-09-20 23:34 by Klap-in