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.
 
 
 
 
 

137 lines
4.0 KiB

  1. <?php
  2. /**
  3. * Base class for bureaucracy actions.
  4. *
  5. * All bureaucracy actions have to inherit from this class.
  6. *
  7. * ATM this class is pretty empty but, in the future it could be used to add
  8. * helper functions which can be utilized by the different actions.
  9. *
  10. * @author Michael Klier <chi@chimeric.de>
  11. */
  12. class helper_plugin_bureaucracy_action extends syntax_plugin_bureaucracy {
  13. /**
  14. * Return false to prevent DokuWiki reusing instances of the plugin
  15. *
  16. * @return bool
  17. */
  18. public function isSingleton() {
  19. return false;
  20. }
  21. /**
  22. * Handle the user input [required]
  23. *
  24. * This function needs to be implemented to accept the user data collected
  25. * from the form. Data has to be grabbed from $_POST['bureaucracy'] using
  26. * the indicies in the 'idx' members of the $data items.
  27. *
  28. * @param helper_plugin_bureaucracy_field[] $fields the list of fields in the form
  29. * @param string $thanks the thank you message as defined in the form
  30. * or default one. Might be modified by the action
  31. * before returned
  32. * @param array $argv additional arguments passed to the action
  33. * @return bool|string false on error, $thanks on success
  34. */
  35. public function run($fields, $thanks, $argv){
  36. msg('ERROR: called action %s did not implement a run() function');
  37. return false;
  38. }
  39. /**
  40. * Adds some language related replacement patterns
  41. */
  42. function prepareLanguagePlaceholder() {
  43. global $ID;
  44. global $conf;
  45. $this->patterns['__lang__'] = '/@LANG@/';
  46. $this->values['__lang__'] = $conf['lang'];
  47. $this->patterns['__trans__'] = '/@TRANS@/';
  48. $this->values['__trans__'] = '';
  49. /** @var helper_plugin_translation $trans */
  50. $trans = plugin_load('helper', 'translation');
  51. if (!$trans) return;
  52. $this->values['__trans__'] = $trans->getLangPart($ID);
  53. $this->values['__lang__'] = $trans->realLC('');
  54. }
  55. /**
  56. * Adds replacement pattern for fieldlabels (e.g @@Label@@)
  57. *
  58. * @param helper_plugin_bureaucracy_field $field
  59. */
  60. function prepareFieldReplacement($field) {
  61. $label = $field->getParam('label');
  62. if(!is_null($label)) {
  63. $this->patterns[$label] = $field->getReplacementPattern();
  64. $this->values[$label] = $field->getReplacementValue();
  65. }
  66. }
  67. /**
  68. * Adds <noinclude></noinclude> to replacement patterns
  69. */
  70. function prepareNoincludeReplacement() {
  71. $this->patterns['__noinclude__'] = '/<noinclude>(.*?)<\/noinclude>/is';
  72. $this->values['__noinclude__'] = '';
  73. }
  74. /**
  75. * Generate field replacements
  76. *
  77. * @param helper_plugin_bureaucracy_field[] $fields List of field objects
  78. * @return array
  79. */
  80. function prepareFieldReplacements($fields) {
  81. foreach ($fields as $field) {
  82. //field replacements
  83. $this->prepareFieldReplacement($field);
  84. }
  85. }
  86. /**
  87. * Returns ACL access level of the user or the (virtual) 'runas' user
  88. *
  89. * @param string $id pageid
  90. * @return int
  91. */
  92. protected function aclcheck($id) {
  93. $runas = $this->getConf('runas');
  94. if($runas) {
  95. $auth = auth_aclcheck($id, $runas, array());
  96. } else {
  97. $auth = auth_quickaclcheck($id);
  98. }
  99. return $auth;
  100. }
  101. /**
  102. * Available methods
  103. *
  104. * @return array
  105. */
  106. public function getMethods() {
  107. $result = array();
  108. $result[] = array(
  109. 'name' => 'run',
  110. 'desc' => 'Handle the user input',
  111. 'params' => array(
  112. 'fields' => 'helper_plugin_bureaucracy_field[]',
  113. 'thanks' => 'string',
  114. 'argv' => 'array'
  115. ),
  116. 'return' => array('false on error, thanks message on success' => 'bool|string')
  117. );
  118. return $result;
  119. }
  120. }