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.
 
 
 
 
 

63 lines
2.3 KiB

  1. <?php
  2. class helper_plugin_bureaucracy_actionscript extends helper_plugin_bureaucracy_action {
  3. protected $scriptNamePattern = '/^[_a-zA-Z0-9]+\.php$/';
  4. /**
  5. * @inheritDoc
  6. * @throws \InvalidArgumentException
  7. */
  8. public function run($fields, $thanks, $argv) {
  9. if (count($argv) < 1) {
  10. throw new InvalidArgumentException('The "script"-action expects exactly 1 argument: the script name.');
  11. }
  12. $scriptName = $argv[0];
  13. if (!$this->validateScriptName($scriptName)) {
  14. $cleanedScriptName = hsc($scriptName);
  15. throw new InvalidArgumentException("The supplied scriptname \"<code>$cleanedScriptName</code>\" is invalid! It must conform to <code>{hsc($this->scriptNamePattern)}</code>!");
  16. }
  17. $path = DOKU_CONF . 'plugin/bureaucracy/' . $scriptName;
  18. if (!file_exists($path)) {
  19. $shortPath = 'conf/plugin/bureaucracy/' . $scriptName;
  20. throw new InvalidArgumentException("Script <code>$shortPath</code> doesn't exist!");
  21. }
  22. require $path;
  23. $classFragment = substr($scriptName, 0, strpos($scriptName, '.'));
  24. $className = 'helper_plugin_bureaucracy_handler_' . $classFragment;
  25. $deprecatedClassName = 'bureaucracy_handler_' . $classFragment;
  26. if (!class_exists($className) && class_exists($deprecatedClassName)) {
  27. msg("Please change this script's class-name to <code>$className</code>.
  28. Your current scheme <code>$deprecatedClassName</code> is deprecated and will stop working in the future.", 2);
  29. $className = $deprecatedClassName;
  30. }
  31. /** @var dokuwiki\plugin\bureaucracy\interfaces\bureaucracy_handler_interface $handler */
  32. $handler = new $className;
  33. if (!is_a($handler, dokuwiki\plugin\bureaucracy\interfaces\bureaucracy_handler_interface::class)) {
  34. throw new InvalidArgumentException('The handler must implement the interface <code>dokuwiki\\plugin\\bureaucracy\\interfaces\\bureaucracy_handler_interface</code> !');
  35. }
  36. return $handler->handleData($fields, $thanks);
  37. }
  38. /**
  39. * @param $scriptName
  40. *
  41. * @return bool
  42. */
  43. protected function validateScriptName($scriptName) {
  44. $valid = preg_match($this->scriptNamePattern, $scriptName);
  45. return $valid === 1;
  46. }
  47. }