Exemple #1
0
 /**
  *
  * Generates a token entry for the matched text.  Token options are:
  *
  * 'src' => The image source, typically a relative path name.
  *
  * 'opts' => Any macro options following the source.
  *
  * @access public
  *
  * @param array &$matches The array of matches from parse().
  *
  * @return A delimited token number to be used as a placeholder in
  * the source text.
  *
  */
 function process(&$matches)
 {
     $formYaml = $matches[1];
     $dataYaml = $matches[2];
     if (substr($dataYaml, 0, 2) == '%%') {
         $dataYaml = '';
     }
     $form = Wikidot_Form::fromYaml($formYaml, $dataYaml);
     $output = $this->wiki->addToken($this->rule, array('begin' => 1));
     foreach ($form->fields as $name => $field) {
         $output .= $this->wiki->addToken($this->rule, array('field' => $field));
     }
     $output .= $this->wiki->addToken($this->rule, array('end' => 1));
     return $output;
 }
 public function renderFromTemplate($template, $extValues)
 {
     $template = "\n{$template}\n";
     $template_parts = explode("\n---\n", $template);
     // form definition is the YAML document before the first "---"
     $form_def = array_shift($template_parts);
     // Wikidot (DTL) template is the rest
     $template = trim(implode("\n---\n", $template_parts));
     $form = Wikidot_Form::fromYaml($form_def);
     $context = $form->computeValues($extValues);
     // render the template
     $w_template = new Wikidot_Template($template);
     return $w_template->render($context);
 }