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.
 
 
 
 
 

90 lines
3.1 KiB

  1. <?php
  2. /**
  3. * Class helper_plugin_bureaucracy_fieldsubmit
  4. *
  5. * Creates a submit button
  6. */
  7. class helper_plugin_bureaucracy_fieldsubmit extends helper_plugin_bureaucracy_field {
  8. protected $mandatory_args = 1;
  9. static $captcha_displayed = array();
  10. static $captcha_checked = array();
  11. /**
  12. * Arguments:
  13. * - cmd
  14. * - label (optional)
  15. * - ^ (optional)
  16. *
  17. * @param array $args The tokenized definition, only split at spaces
  18. */
  19. public function initialize($args) {
  20. parent::initialize($args);
  21. // make always optional to prevent being marked as required
  22. $this->opt['optional'] = true;
  23. }
  24. /**
  25. * Render the field as XHTML
  26. *
  27. * @params array $params Additional HTML specific parameters
  28. * @params Doku_Form $form The target Doku_Form object
  29. * @params int $formid unique identifier of the form which contains this field
  30. */
  31. public function renderfield($params, Doku_Form $form, $formid) {
  32. if(!isset(helper_plugin_bureaucracy_fieldsubmit::$captcha_displayed[$formid])) {
  33. helper_plugin_bureaucracy_fieldsubmit::$captcha_displayed[$formid] = true;
  34. /** @var helper_plugin_captcha $helper */
  35. $helper = null;
  36. if(@is_dir(DOKU_PLUGIN.'captcha')) $helper = plugin_load('helper','captcha');
  37. if(!is_null($helper) && $helper->isEnabled()){
  38. $form->addElement($helper->getHTML());
  39. }
  40. }
  41. $attr = array();
  42. if(isset($this->opt['id'])) {
  43. $attr['id'] = $this->opt['id'];
  44. }
  45. $this->tpl = form_makeButton('submit','', '@@DISPLAY|' . $this->getLang('submit') . '@@', $attr);
  46. parent::renderfield($params, $form, $formid);
  47. }
  48. /**
  49. * Handle a post to the field
  50. *
  51. * Accepts and validates a posted captcha value.
  52. *
  53. * @param string $value The passed value
  54. * @param helper_plugin_bureaucracy_field[] $fields (reference) form fields (POST handled upto $this field)
  55. * @param int $index index number of field in form
  56. * @param int $formid unique identifier of the form which contains this field
  57. * @return bool Whether the posted form has a valid captcha
  58. */
  59. public function handle_post($value, &$fields, $index, $formid) {
  60. if ($this->hidden) {
  61. return true;
  62. }
  63. if(!isset(helper_plugin_bureaucracy_fieldsubmit::$captcha_checked[$formid])) {
  64. helper_plugin_bureaucracy_fieldsubmit::$captcha_checked[$formid] = true;
  65. // check CAPTCHA
  66. /** @var helper_plugin_captcha $helper */
  67. $helper = null;
  68. if(@is_dir(DOKU_PLUGIN.'captcha')) $helper = plugin_load('helper','captcha');
  69. if(!is_null($helper) && $helper->isEnabled()){
  70. return $helper->check();
  71. }
  72. }
  73. return true;
  74. }
  75. /**
  76. * Get an arbitrary parameter
  77. *
  78. * @param string $name
  79. * @return mixed|null
  80. */
  81. public function getParam($name) {
  82. return ($name === 'value') ? null : parent::getParam($name);
  83. }
  84. }