11<?php
2+
3+ use dokuwiki \Extension \ActionPlugin ;
4+ use dokuwiki \Extension \EventHandler ;
5+ use dokuwiki \Extension \Event ;
6+ use dokuwiki \Utf8 \PhpString ;
7+
28/**
39 *
410 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
511 * @author Andreas Gohr <andi@splitbrain.org>
612 */
7-
813/**
914 * Class action_plugin_data
1015 */
11- class action_plugin_data extends DokuWiki_Action_Plugin
16+ class action_plugin_data extends ActionPlugin
1217{
13-
1418 /**
1519 * will hold the data helper plugin
1620 * @var helper_plugin_data
1721 */
18- var $ dthlp = null ;
22+ public $ dthlp ;
1923
2024 /**
2125 * Constructor. Load helper plugin
2226 */
23- function __construct ()
27+ public function __construct ()
2428 {
2529 $ this ->dthlp = plugin_load ('helper ' , 'data ' );
2630 }
2731
2832 /**
2933 * Registers a callback function for a given event
3034 */
31- function register (Doku_Event_Handler $ controller )
35+ public function register (EventHandler $ controller )
3236 {
3337 $ controller ->register_hook ('IO_WIKIPAGE_WRITE ' , 'BEFORE ' , $ this , '_handle ' );
3438 $ controller ->register_hook ('HTML_SECEDIT_BUTTON ' , 'BEFORE ' , $ this , '_editbutton ' );
@@ -42,10 +46,10 @@ function register(Doku_Event_Handler $controller)
4246 * Handles the page write event and removes the database info
4347 * when the plugin code is no longer in the source
4448 *
45- * @param Doku_Event $event
49+ * @param Event $event
4650 * @param null $param
4751 */
48- function _handle (Doku_Event $ event , $ param )
52+ public function _handle (Event $ event , $ param )
4953 {
5054 $ data = $ event ->data ;
5155 if (strpos ($ data [0 ][1 ], 'dataentry ' ) !== false ) return ; // plugin seems still to be there
@@ -63,10 +67,10 @@ function _handle(Doku_Event $event, $param)
6367 }
6468
6569 /**
66- * @param Doku_Event $event
70+ * @param Event $event
6771 * @param null $param
6872 */
69- function _editbutton ($ event , $ param )
73+ public function _editbutton ($ event , $ param )
7074 {
7175 if ($ event ->data ['target ' ] !== 'plugin_data ' ) {
7276 return ;
@@ -76,10 +80,10 @@ function _editbutton($event, $param)
7680 }
7781
7882 /**
79- * @param Doku_Event $event
83+ * @param Event $event
8084 * @param null $param
8185 */
82- function _editform (Doku_Event $ event , $ param )
86+ public function _editform (Event $ event , $ param )
8387 {
8488 global $ TEXT ;
8589 if ($ event ->data ['target ' ] !== 'plugin_data ' ) {
@@ -94,36 +98,36 @@ function _editform(Doku_Event $event, $param)
9498
9599 echo $ this ->locale_xhtml ('edit_intro ' . ($ this ->getConf ('edit_content_only ' ) ? '_contentonly ' : '' ));
96100
97- require_once ' renderer_data_edit.php ' ;
101+ require_once __DIR__ . ' / renderer_data_edit.php ' ;
98102 $ Renderer = new Doku_Renderer_plugin_data_edit ();
99103 $ Renderer ->form = $ event ->data ['form ' ];
100104
101105 // Loop through the instructions
102106 $ instructions = p_get_instructions ($ TEXT );
103107 foreach ($ instructions as $ instruction ) {
104108 // Execute the callback against the Renderer
105- call_user_func_array (array ( $ Renderer , $ instruction [0 ]) , $ instruction [1 ]);
109+ call_user_func_array ([ $ Renderer , $ instruction [0 ]] , $ instruction [1 ]);
106110 }
107111 }
108112
109113 /**
110- * @param Doku_Event $event
114+ * @param Event $event
111115 */
112- function _handle_edit_post (Doku_Event $ event )
116+ public function _handle_edit_post (Event $ event )
113117 {
114118 if (!isset ($ _POST ['data_edit ' ])) {
115119 return ;
116120 }
117121 global $ TEXT ;
118122
119- require_once ' syntax/entry.php ' ;
123+ require_once __DIR__ . ' / syntax/entry.php ' ;
120124 $ TEXT = syntax_plugin_data_entry::editToWiki ($ _POST ['data_edit ' ]);
121125 }
122126
123127 /**
124- * @param Doku_Event $event
128+ * @param Event $event
125129 */
126- function _handle_ajax (Doku_Event $ event )
130+ public function _handle_ajax (Event $ event )
127131 {
128132 if ($ event ->data !== 'data_page ' ) {
129133 return ;
@@ -172,31 +176,32 @@ function _handle_ajax(Doku_Event $event)
172176 }
173177 $ regexp .= '$/ ' ;
174178
175- $ result = array () ;
179+ $ result = [] ;
176180 foreach ($ pages as $ page => $ title ) {
177- $ id = array () ;
181+ $ id = [] ;
178182 if (!preg_match ($ regexp , $ page , $ id )) {
179183 // Does not satisfy the postfix and prefix criteria
180184 continue ;
181185 }
182186
183187 $ id = $ id [1 ];
184188
185- if ($ search !== '' &&
189+ if (
190+ $ search !== '' &&
186191 stripos ($ id , cleanID ($ search )) === false &&
187- stripos ($ title , $ search ) === false ) {
192+ stripos ($ title , (string ) $ search ) === false
193+ ) {
188194 // Search string is not in id part or title
189195 continue ;
190196 }
191197
192198 if ($ title === '' ) {
193- $ title = utf8_ucwords (str_replace ('_ ' , ' ' , $ id ));
199+ $ title = PhpString:: ucwords (str_replace ('_ ' , ' ' , $ id ));
194200 }
195201 $ result [hsc ($ id )] = hsc ($ title );
196202 }
197203
198- $ json = new JSON ();
199204 header ('Content-Type: application/json ' );
200- echo $ json -> encode ($ result );
205+ echo json_encode ($ result );
201206 }
202207}
0 commit comments