1<?php 2/** 3 * quiz plugin : Create a book from some pages. 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Luigi Micco <l.micco@tiscali.it> 7 */ 8 9// must be run within Dokuwiki 10if (!defined('DOKU_INC')) die(); 11 12if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 13require_once(DOKU_PLUGIN . 'syntax.php'); 14require_once(DOKU_INC.'inc/search.php'); 15 16/** 17 * All DokuWiki plugins to extend the parser/rendering mechanism 18 * need to inherit from this class 19 */ 20class syntax_plugin_quiz extends DokuWiki_Syntax_Plugin { 21 22 23 function setupLocale(){ 24 parent::setupLocale(); 25 } 26 27 function connectTo($mode) { 28 $this->Lexer->addSpecialPattern('{{quiz>.+?}}', $mode, 'plugin_quiz'); 29 } 30 31 //function getType() { return 'substition'; } 32 function getType(){ return 'container';} 33 function getPType(){ return 'block';} 34 35 /** 36 * Where to sort in? 37 */ 38 function getSort(){ 39 return 190; 40 } 41 42 43 function handle($match, $state, $pos, &$handler) { 44 45 $match = substr($match, 2, -2); // strip markup 46 list($match, $flags) = explode('&', $match, 2); 47 48 // break the pattern up into its constituent parts 49 list($include, $id, $section) = preg_split('/>|#/u', $match, 3); 50 return array($include, $id, explode('&', $flags)); 51 52 } 53 54 function render($mode, &$renderer, $data) { 55 list($type, $quiz_file, $flags) = $data; 56 57 if ($type == "quiz") { 58 if ($mode == 'xhtml') { 59 $param = array(); 60 61 $param['learning'] = 0; 62 $param['rndchoice'] = 0; 63 $param['rndquest'] = 0; 64 $param['highscores'] = 0; 65 $param['showintro'] = 0; 66 67 foreach($flags as $value) { 68 if (in_array(strtolower($value), array('learning', 'rndchoice','rndquest','highscores', 'showintro') )) { 69 $param[strtolower($value)] = 1; 70 } 71 } 72 73 $quiz_file = preg_replace("/{{([^|}]+).*}}/","$1",$quiz_file); 74 $renderer->info['cache'] = FALSE; 75 require_once('class_quiz.php'); 76 $quiz=new quiz($quiz_file, $param); 77 $renderer->doc .= '<div id="quiz-div__'.$quiz_file.'">'.$quiz->do_quiz_here().'</div>'; 78 } 79 } 80 return false; 81 } 82 83 84} 85?> 86