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