You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

61 lines
1.7 KiB

  1. <?php
  2. /**
  3. * Bureaucracy Plugin: Allows flexible creation of forms
  4. *
  5. * This plugin allows definition of forms in wiki pages. The forms can be
  6. * submitted via email or used to create new pages from templates.
  7. *
  8. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  9. * @author Andreas Gohr <andi@splitbrain.org>
  10. * @author Adrian Lang <dokuwiki@cosmocode.de>
  11. */
  12. // must be run within Dokuwiki
  13. if (!defined('DOKU_INC')) die();
  14. /**
  15. * Class action_plugin_bureaucracy
  16. */
  17. class action_plugin_bureaucracy extends DokuWiki_Action_Plugin {
  18. /**
  19. * Registers a callback function for a given event
  20. */
  21. public function register(Doku_Event_Handler $controller) {
  22. $controller->register_hook('AJAX_CALL_UNKNOWN', 'BEFORE', $this, 'ajax');
  23. }
  24. /**
  25. * @param Doku_Event$event
  26. * @param $param
  27. */
  28. public function ajax(Doku_Event $event, $param) {
  29. if ($event->data !== 'bureaucracy_user_field') {
  30. return;
  31. }
  32. $event->stopPropagation();
  33. $event->preventDefault();
  34. $search = $_REQUEST['search'];
  35. /** @var DokuWiki_Auth_Plugin $auth */
  36. global $auth;
  37. $users = array();
  38. foreach($auth->retrieveUsers() as $username => $data) {
  39. if ($search === '' || // No search
  40. stripos($username, $search) === 0 || // Username (prefix)
  41. stripos($data['name'], $search) !== false) { // Full name
  42. $users[$username] = $data['name'];
  43. }
  44. if (count($users) === 10) {
  45. break;
  46. }
  47. }
  48. if (count($users) === 1 && key($users) === $search) {
  49. $users = array();
  50. }
  51. echo json_encode($users);
  52. }
  53. }