1<?php 2/** 3 * Mikio Syntax Plugin: Quiz Item 4 * 5 * @link http://github.com/nomadjimbob/mikioplugin 6 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 7 * @author James Collins <james.collins@outlook.com.au> 8 */ 9 10if (!defined('DOKU_INC')) die(); 11if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 12require_once(dirname(__FILE__).'/core.php'); 13 14class syntax_plugin_mikioplugin_quizitem extends syntax_plugin_mikioplugin_core { 15 public $tag = 'quiz-item'; 16 public $requires_tag = 'quiz'; 17 public $hasEndTag = false; 18 public $options = array( 19 'type' => array('type' => 'choice', 20 'data' => array('choice'), 21 'default' => ''), 22 'question' => array('type' => 'text', 'default' => ''), 23 'options' => array('type' => 'text', 'default' => ''), 24 'submit-text' => array('type' => 'text', 'default' => 'Submit'), 25 'answer' => array('type' => 'text', 'default' => ''), 26 'text' => array('type' => 'text', 'default' => ''), 27 ); 28 29 // public function getAllowedTypes() { return array(); } 30 31 public function render_lexer_special(Doku_Renderer $renderer, $data) { 32 $classes = $this->buildClass($data); 33 34 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-item' . $classes . '" data-question="' . $data['question'] . '" data-answer="' . $data['answer'] . '">'; 35 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-question">' . $data['question'] . '</div>'; 36 if($data['text'] != '') $renderer->doc .= '<p>' . $data['text'] . '</p>'; 37 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-options">'; 38 39 switch(strtolower($data['type'])) { 40 case 'choice': 41 $name = rand(10000, 99999); 42 43 $options = explode('|', $data['options']); 44 foreach($options as $option) { 45 $renderer->doc .= '<div class="' . $this->elemClass . ' ' . $this->classPrefix . 'quiz-option"><label><input type="radio" name="' . $name . '" value="' . $option . '" />' . $option . '</label></div>'; 46 } 47 break; 48 } 49 50 $renderer->doc .= '</div>'; 51 $renderer->doc .= '</div>'; 52 } 53} 54?> 55