0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 16:31:53 +00:00

[2.1.0] ConfigForm generates textareas instead of text inputs for lists, hashes, lookups, text and itext fields

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1273 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2007-06-29 02:16:47 +00:00
parent 5e5c0f3aa4
commit ed44b5c5ba
3 changed files with 31 additions and 3 deletions

2
NEWS
View File

@ -25,6 +25,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
longer strings that would be more appropriately edited with a textarea
. Allow newlines to act as separators for lists, hashes, lookups and
%HTML.Allowed
. ConfigForm generates textareas instead of text inputs for lists, hashes,
lookups, text and itext fields
2.0.2, unknown release date
(none)

View File

@ -34,7 +34,9 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer
* @param $doc_url String documentation URL, will have fragment tagged on
* @param $compress Integer max length before compressing a directive name, set to false to turn off
*/
function HTMLPurifier_Printer_ConfigForm($name, $doc_url = null, $compress = false) {
function HTMLPurifier_Printer_ConfigForm(
$name, $doc_url = null, $compress = false
) {
parent::HTMLPurifier_Printer();
$this->docURL = $doc_url;
$this->name = $name;
@ -43,6 +45,15 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer
$this->fields['bool'] = new HTMLPurifier_Printer_ConfigForm_bool();
}
/**
* @param $cols Integer columns of textarea, null to use default
* @param $rows Integer rows of textarea, null to use default
*/
function setTextareaDimensions($cols = null, $rows = null) {
if ($cols) $this->fields['default']->cols = $cols;
if ($rows) $this->fields['default']->rows = $rows;
}
/**
* Retrieves styling, in case the directory it's in is not publically
* available
@ -200,6 +211,8 @@ class HTMLPurifier_Printer_ConfigForm_NullDecorator extends HTMLPurifier_Printer
* Swiss-army knife configuration form field printer
*/
class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer {
var $cols = 18;
var $rows = 5;
function render($ns, $directive, $value, $name, $config) {
$this->prepareGenerator($config);
// this should probably be split up a little
@ -214,12 +227,12 @@ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer {
$value[] = $val;
}
case 'list':
$value = implode(',', $value);
$value = implode(PHP_EOL, $value);
break;
case 'hash':
$nvalue = '';
foreach ($value as $i => $v) {
$nvalue .= "$i:$v,";
$nvalue .= "$i:$v" . PHP_EOL;
}
$value = $nvalue;
break;
@ -244,6 +257,15 @@ class HTMLPurifier_Printer_ConfigForm_default extends HTMLPurifier_Printer {
$ret .= $this->element('option', $val, $attr);
}
$ret .= $this->end('select');
} elseif (
$def->type == 'text' || $def->type == 'itext' ||
$def->type == 'list' || $def->type == 'hash' || $def->type == 'lookup'
) {
$attr['cols'] = $this->cols;
$attr['rows'] = $this->rows;
$ret .= $this->start('textarea', $attr);
$ret .= $this->text($value);
$ret .= $this->end('textarea');
} else {
$attr['value'] = $value;
$attr['type'] = 'text';

View File

@ -37,3 +37,7 @@ HTMLPurifier_ConfigSchema::defineNamespace('ReportCard', 'It is for grades.');
HTMLPurifier_ConfigSchema::define('ReportCard', 'English', null, 'string/null', 'Grade from English class.');
HTMLPurifier_ConfigSchema::define('ReportCard', 'Absences', 0, 'int', 'How many times missing from school?');
HTMLPurifier_ConfigSchema::defineNamespace('Text', 'This stuff is long, boring, and English.');
HTMLPurifier_ConfigSchema::define('Text', 'AboutUs', 'Nothing much, but this should be decently long so that a textarea would be better', 'text', 'Who are we? What are we up to?');
HTMLPurifier_ConfigSchema::define('Text', 'Hash', "not-case-sensitive\nstill-not-case-sensitive\nsuper-not-case-sensitive", 'itext', 'This is of limited utility, but of course it ends up being used.');