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.
 
 
 
 
 

122 lines
3.0 KiB

  1. <?php
  2. namespace dokuwiki\Extension;
  3. /**
  4. * Admin Plugin Prototype
  5. *
  6. * Implements an admin interface in a plugin
  7. *
  8. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  9. * @author Christopher Smith <chris@jalakai.co.uk>
  10. */
  11. abstract class AdminPlugin extends Plugin
  12. {
  13. /**
  14. * Return the text that is displayed at the main admin menu
  15. * (Default localized language string 'menu' is returned, override this function for setting another name)
  16. *
  17. * @param string $language language code
  18. * @return string menu string
  19. */
  20. public function getMenuText($language)
  21. {
  22. $menutext = $this->getLang('menu');
  23. if (!$menutext) {
  24. $info = $this->getInfo();
  25. $menutext = $info['name'] . ' ...';
  26. }
  27. return $menutext;
  28. }
  29. /**
  30. * Return the path to the icon being displayed in the main admin menu.
  31. * By default it tries to find an 'admin.svg' file in the plugin directory.
  32. * (Override this function for setting another image)
  33. *
  34. * Important: you have to return a single path, monochrome SVG icon! It has to be
  35. * under 2 Kilobytes!
  36. *
  37. * We recommend icons from https://materialdesignicons.com/ or to use a matching
  38. * style.
  39. *
  40. * @return string full path to the icon file
  41. */
  42. public function getMenuIcon()
  43. {
  44. $plugin = $this->getPluginName();
  45. return DOKU_PLUGIN . $plugin . '/admin.svg';
  46. }
  47. /**
  48. * Determine position in list in admin window
  49. * Lower values are sorted up
  50. *
  51. * @return int
  52. */
  53. public function getMenuSort()
  54. {
  55. return 1000;
  56. }
  57. /**
  58. * Carry out required processing
  59. */
  60. public function handle()
  61. {
  62. // some plugins might not need this
  63. }
  64. /**
  65. * Output html of the admin page
  66. */
  67. abstract public function html();
  68. /**
  69. * Checks if access should be granted to this admin plugin
  70. *
  71. * @return bool true if the current user may access this admin plugin
  72. */
  73. public function isAccessibleByCurrentUser()
  74. {
  75. $data = [];
  76. $data['instance'] = $this;
  77. $data['hasAccess'] = false;
  78. $event = new Event('ADMINPLUGIN_ACCESS_CHECK', $data);
  79. if ($event->advise_before()) {
  80. if ($this->forAdminOnly()) {
  81. $data['hasAccess'] = auth_isadmin();
  82. } else {
  83. $data['hasAccess'] = auth_ismanager();
  84. }
  85. }
  86. $event->advise_after();
  87. return $data['hasAccess'];
  88. }
  89. /**
  90. * Return true for access only by admins (config:superuser) or false if managers are allowed as well
  91. *
  92. * @return bool
  93. */
  94. public function forAdminOnly()
  95. {
  96. return true;
  97. }
  98. /**
  99. * Return array with ToC items. Items can be created with the html_mktocitem()
  100. *
  101. * @see html_mktocitem()
  102. * @see tpl_toc()
  103. *
  104. * @return array
  105. */
  106. public function getTOC()
  107. {
  108. return [];
  109. }
  110. }