Loads configuration values from $_GET/$_POST that were posted
via ConfigForm
public static loadArrayFromForm ( array $array, string | boolean $index = false, array | boolean $allowed = true, boolean $mq_fix = true, HTMLPurifier_ConfigSchema $schema = null ) : mixed | ||
$array | array | $_GET or $_POST array to import |
$index | string | boolean | Index/name that the config variables are in |
$allowed | array | boolean | List of allowed namespaces/directives |
$mq_fix | boolean | Boolean whether or not to enable magic quotes fix |
$schema | HTMLPurifier_ConfigSchema | Schema to use, if not global copy |
return | mixed |
public function test_loadArrayFromForm() { $this->schema->add('Pancake.Mix', 'buttermilk', 'string', false); $this->schema->add('Pancake.Served', true, 'bool', false); $this->schema->add('Toppings.Syrup', true, 'bool', false); $this->schema->add('Toppings.Flavor', 'maple', 'string', false); $this->schema->add('Toppings.Strawberries', 3, 'int', false); $this->schema->add('Toppings.Calories', 2000, 'int', true); $this->schema->add('Toppings.DefinitionID', null, 'string', true); $this->schema->add('Toppings.DefinitionRev', 1, 'int', false); $this->schema->add('Toppings.Protected', 1, 'int', false); $get = array('breakfast' => array('Pancake.Mix' => 'nasty', 'Pancake.Served' => '0', 'Toppings.Syrup' => '0', 'Toppings.Flavor' => "juice", 'Toppings.Strawberries' => '999', 'Toppings.Calories' => '', 'Null_Toppings.Calories' => '1', 'Toppings.DefinitionID' => '<argh>', 'Toppings.DefinitionRev' => '65', 'Toppings.Protected' => '4')); $config_expect = HTMLPurifier_Config::create(array('Pancake.Served' => false, 'Toppings.Syrup' => false, 'Toppings.Flavor' => "juice", 'Toppings.Strawberries' => 999, 'Toppings.Calories' => null), $this->schema); $config_result = HTMLPurifier_Config::loadArrayFromForm($get, 'breakfast', array('Pancake.Served', 'Toppings', '-Toppings.Protected'), false, $this->schema); $this->assertEqual($config_expect, $config_result); /* MAGIC QUOTES NOT TESTED!!! $get = array( 'breakfast' => array( 'Pancake.Mix' => 'n\\asty' ) ); $config_expect = HTMLPurifier_Config::create(array( 'Pancake.Mix' => 'n\\asty' )); $config_result = HTMLPurifier_Config::loadArrayFromForm($get, 'breakfast', true, false); $this->assertEqual($config_expect, $config_result); */ }
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>HTML Purifier Config Form Smoketest</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="../library/HTMLPurifier/Printer/ConfigForm.css" type="text/css" /> <script defer="defer" type="text/javascript" src="../library/HTMLPurifier/Printer/ConfigForm.js"></script> </head> <body> <h1>HTML Purifier Config Form Smoketest</h1> <p>This file outputs the configuration form for every single type of directive possible.</p> <form id="htmlpurifier-config" name="htmlpurifier-config" method="get" action="" style="float:right;"> <?php $schema_builder = new HTMLPurifier_ConfigSchema_Builder_ConfigSchema(); $schema = $schema_builder->build($interchange); $config = HTMLPurifier_Config::loadArrayFromForm($_GET, 'config', true, true, $schema); $printer = new HTMLPurifier_Printer_ConfigForm('config', '?doc#%s'); echo $printer->render(array(HTMLPurifier_Config::createDefault(), $config)); ?> </form> <pre> <?php echo htmlspecialchars(var_export($config->getAll(), true)); ?> </pre> </body> </html> <?php // vim: et sw=4 sts=4
<head> <title>HTML Purifier Config Form Smoketest</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" href="../library/HTMLPurifier/Printer/ConfigForm.css" type="text/css" /> <script defer="defer" type="text/javascript" src="../library/HTMLPurifier/Printer/ConfigForm.js"></script> </head> <body> <h1>HTML Purifier Config Form Smoketest</h1> <p>This file outputs the configuration form for every single type of directive possible.</p> <form id="htmlpurifier-config" name="htmlpurifier-config" method="get" action="" style="float:right;"> <?php require_once 'HTMLPurifier/Printer/ConfigForm.php'; // fictional set, attempts to cover every possible data-type // see source at ConfigTest.php require_once 'testSchema.php'; // cleanup ( this should be rolled into Config ) $config = HTMLPurifier_Config::loadArrayFromForm($_GET, 'config'); $printer = new HTMLPurifier_Printer_ConfigForm('config', '?doc#%s'); echo $printer->render($config); ?> </form> <pre> <?php echo htmlspecialchars(print_r($config->getAll(), true)); ?> </pre> </body> </html>