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.
 
 
 
 
 

71 lines
2.2 KiB

  1. <?php
  2. /**
  3. * Class helper_plugin_bureaucracy_fieldwiki
  4. *
  5. * Adds some static text to the form, but parses the input as Wiki syntax (computationally expensive)
  6. */
  7. class helper_plugin_bureaucracy_fieldwiki extends helper_plugin_bureaucracy_field {
  8. protected $tpl = '<p>@@LABEL@@</p>';
  9. /**
  10. * Arguments:
  11. * - cmd
  12. * - wiki text
  13. *
  14. * @param array $args The tokenized definition, only split at spaces
  15. */
  16. public function initialize($args) {
  17. parent::initialize($args);
  18. // make always optional to prevent being marked as required
  19. $this->opt['optional'] = true;
  20. }
  21. /**
  22. * Handle a post to the field
  23. *
  24. * @param null $value empty
  25. * @param helper_plugin_bureaucracy_field[] $fields (reference) form fields (POST handled upto $this field)
  26. * @param int $index index number of field in form
  27. * @param int $formid unique identifier of the form which contains this field
  28. * @return bool Whether the passed value is valid
  29. */
  30. public function handle_post($value, &$fields, $index, $formid) {
  31. return true;
  32. }
  33. /**
  34. * Get an arbitrary parameter
  35. *
  36. * @param string $name
  37. * @return mixed|null
  38. */
  39. public function getParam($name) {
  40. return ($name === 'value') ? null : parent::getParam($name);
  41. }
  42. /**
  43. * Returns parsed wiki instructions
  44. *
  45. * @param string|array $tpl The template as string
  46. * @param array $params A hash mapping parameters to values
  47. *
  48. * @return string The parsed template
  49. */
  50. protected function _parse_tpl($tpl, $params) {
  51. $ins = p_get_instructions($params['display']);
  52. // remove document and p instructions (opening and closing)
  53. $start = 2;
  54. $end = 2;
  55. // check if struct instructions have to be removed as well from the beginning or end
  56. if (isset($ins[1][1][0]) && $ins[1][1][0] === 'struct_output') {
  57. $start = 3;
  58. } elseif (isset($ins[count($ins) - 2][1][0]) && $ins[count($ins) - 2][1][0] === 'struct_output') {
  59. $end = 3;
  60. }
  61. $ins = array_slice($ins, $start, -$end);
  62. $tpl = p_render('xhtml', $ins, $byref_ignore);
  63. return '<p>'.$tpl.'</p>';
  64. }
  65. }