*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); require_once(DOKU_INC.'inc/blowfish.php'); class helper_plugin_requiz extends DokuWiki_Plugin { /** * Check if the REQUIZ should be used. Always check this before using the methods below. * * @return bool true when the REQUIZ should be used */ function isEnabled(){ if(!$this->getConf('requizusr') && $_SERVER['REMOTE_USER']) return false; return true; } /** * Returns the HTML to display the REQUIZ with the chosen method */ function getHTML(){ global $ID; $rand = rand(17,1000000); $qset = $this->getConf('requizset'); $qcnt = count($qset); $qidx = $rand % $qcnt; $secret = PMA_blowfish_encrypt($rand,auth_cookiesalt()); $out = ''; $out .= '
'; $out .= ''; $out .= '
'.$qset[$qidx]['question'].'
'; $out .= ' '; $out .= ''; $out .= '

'; return $out; } /** * Checks if the the REQUIZ was solved correctly * * @param bool $msg when true, an error will be signalled through the msg() method * @return bool true when the answer was correct, otherwise false */ function check($msg=true){ // compare provided string with decrypted requiz $rand = PMA_blowfish_decrypt($_REQUEST['plugin__requiz_secret'],auth_cookiesalt()); $qset = $this->getConf('requizset'); $qcnt = count($qset); $qidx = $rand % $qcnt; if(!$_REQUEST['plugin__requiz_secret'] || !$_REQUEST['plugin__requiz'] || $_REQUEST['plugin__requiz'] != $qset[$qidx]['valid']){ if($msg) msg($this->getLang('testfailed'),-1); return false; } return true; } /** * Build a semi-secret fixed string identifying the current page and user * * This string is always the same for the current user when editing the same * page revision. */ function _fixedIdent(){ global $ID; $lm = @filemtime(wikiFN($ID)); return auth_browseruid(). auth_cookiesalt(). $ID.$lm; } }