'William Fletcher', 'email' => 'uiriamu.furecchaa@gmail.com', 'date' => '2008-09-08', 'name' => 'conform', 'desc' => 'Creates HTML forms properly', 'url' => 'http://thirdforces.internationalconspiracy.org/~ultraviolet/software/conform/', ); } function getType() { return 'substition'; } function getPType() { return 'block'; } function getSort() { return 999; } function connectTo($mode) { $this->Lexer->addEntryPattern('(?=.*?)',$mode,'plugin_conform'); } function postConnect() { $this->Lexer->addExitPattern('', 'plugin_conform'); } function handle($match, $state, $pos, &$handler) { switch ($state) { case DOKU_LEXER_UNMATCHED: if ( !$conform =& plugin_load('helper', 'conform') ) return false; return $conform->conformExtract($match); break; } return false; } function conformError(&$renderer, $message) { $renderer->doc .= ''.$message.'
'; } function conformCreateEmailInput($arg) { switch($arg[0]) { case 'Checkbox': if ( isset($_POST["$arg[1]"]) ) { return "Yes"; } else { return "No"; } default: return htmlspecialchars($_POST["$arg[1]"]); } } function conformCreateInput($arg) { switch($arg[0]) { case 'Textbox': $textbox = ""; $textarea .= htmlspecialchars($_POST["$arg[1]"]); $textarea .= ""; return $textarea; break; case 'Checkbox': $checked = ""; if ( isset($_POST["id"]) ) { if ( $_POST["$arg[1]"] == "on" ) $checked = "checked"; } else { if ( $arg[3] == 1 ) $checked = "checked"; } $checkbox = ""; return $checkbox; break; case 'Radio': $radiocount = 0; if ( ! isset($_POST["$arg[1]"]) ) $checked = " checked='checked'"; foreach ( $arg[3] as $value ) { if ( $value == $_POST["$arg[1]"] ) $checked = " checked='checked'"; $radio .= "$value
"; $checked = ""; } return $radio; break; case 'Select': $select = ""; return $select; default: return "ERROR! ERROR! ERROR! Attempting to create an unsupported input maybe?"; } } function conformConstraintArgCheck($constraintname, $postname, $constraints, &$renderer) { foreach ( $constraints as $constraint ) { if ( $constraintname == $constraint[1] ) { if ( ! isset($_POST["$postname"]) ) { $this->conformError($renderer, "Constraint $postname checked against a value that wasn't posted!"); return false; } $post = $_POST["$postname"]; $check = explode("=", $constraint[3], 2); if ( ( $check[0] == 'maxLength' && strlen($post) > $check[1] ) || ( $check[0] == 'minLength' && strlen($post) < $check[1] ) ) { $this->conformError($renderer, "$constraint[2]"); return false; } } } return true; } function conformConstraintCheck($constraints, $tables, &$renderer) { foreach ( $tables as $table ) { $args = &$table['args']; if ( count($args) == 0 ) continue; switch($table['mode']) { case 0: foreach ( $args as $arg ) { switch($arg[0]) { case 'Submit': case 'Line': case 'Static': case 'Radio': case 'Checkbox': case 'Select': break; default: if ( $this->conformConstraintArgCheck($arg[1], "$arg[1]", $constraints, $renderer) == false ) { $this->conformConstrained = $arg[1]; return false; } } } break; case 1: if ( $table['complete'] == 0 ) break; $rows = $table['rows']; for ( $row = 1; $row <= $rows; $row++ ) { foreach ( $args as $arg ) { switch($arg[0]) { case 'Submit': case 'Line': case 'Static': case 'Radio': case 'Checkbox': case 'Select': break; default: if ( $this->conformConstraintArgCheck($arg[1], "$arg[1]_$row", $constraints, $renderer) == false ) { $this->conformConstrained = $arg[1]; return false; } } } } break; } } return true; } function conformCreateDescription($text, $postname) { if ( isset($_POST["id"]) && $postname == $this->conformConstrained ) { return ''.$text.'
'; } return $text; } function render($format, &$renderer, $data) { global $ID; if( $format == 'xhtml' ) { session_start(); $formaction = DOKU_URL . "doku.php"; $renderer->info['cache'] = false; if ( $data == false ) return false; if ( ! is_array($data) ) return false; if ( ! in_array($ID, $data['idallow']) ) { $this->conformError($renderer, "Conform not allowed on this page! Please ask the admin to rectify this!"); return true; } if ( count($data['errors']) > 0 ) { foreach ( $data['errors'] as $error ) { $this->conformError($renderer, $error); } } $tables = &$data['tables']; $email = false; if ( isset($_POST["id"]) ) { if ( $this->conformConstraintCheck($data['constraints'], $tables, $renderer) == true ) { $email = true; } } if ( $email == false ) { $form .= "
\n"; $_SESSION["conform_emailed"] = false; } $form .= "\n"; $maxcolumns = $data['maxcolumns']; if ( $maxcolumns < 2 ) { $columns = 2; $maxcolumns = 2; } else { $columns = $maxcolumns; } foreach ( $tables as $table ) { $args = &$table['args']; if ( count($args) == 0 ) continue; switch($table['mode']) { case 0: foreach ( $args as $arg ) { switch($arg[0]) { case 'Submit': $submit = $arg; break; case 'Line': $form .= "\n"; break; case 'Static': $form .= "\n"; break; default: if ( $email == false ) { $input = $this->conformCreateInput($arg); } else { $input = $this->conformCreateEmailInput($arg); } $form .= "\n"; } } break; case 1: if ( $table['complete'] == 0 ) break; $rows = $table['rows']; $argcolumns = $table['columns']; for ( $row = 0; $row <= $rows; $row++ ) { $form .= "\n"; $argcount = 0; foreach ( $args as $arg ) { switch($arg[0]) { case 'Submit': $submit = $arg; break; case 'Line': break; case 'Static': break; default: $colspan = ""; if ( $argcount == $argcolumns ) $colspan = " colspan=\"".($maxcolumns - $argcolumns)."\""; if ( $row > 0 ) { $arg[1] .= "_$row"; if ( $email == false ) { $input = $this->conformCreateInput($arg); } else { $input = $this->conformCreateEmailInput($arg); } $form .= "$input
\n"; } else { $form .= "".$this->conformCreateDescription($arg[2], $arg[1])."\n"; } } $argcount++; } $form .= "
\n"; } break; } } if ( count($data['errors']) == 0 && $email == false ) { $form .= "\n"; $form .= "\n"; $form .= ""; } $form .= "

$arg[1]
".$this->conformCreateDescription($arg[2], $arg[1])."$input
\n"; if ( $email == true ) { $theboundary = md5(uniqid("")); $header = "From: ".$this->getConf('conformFrom'); $header .= "\r\nMIME-Version: 1.0"; $header .= "\nContent-Type: text/html"; $header .= "\r\nX-Priority: 3"; $header .= "\r\nX-MSMail-Priority: Normal"; $header .= "\r\n"; if ( $_SESSION["conform_emailed"] == false ) { $emailform = ""; $emailform .= ""; $emailform .= $form; $emailform .= ""; mail($data['to'], $data['subject'], $emailform, $header); } $_SESSION["conform_emailed"] = true; } $renderer->doc .= $form; return true; } return false; } } ?>