ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
HTMLPurifier_Printer_ConfigForm Class Reference
+ Inheritance diagram for HTMLPurifier_Printer_ConfigForm:
+ Collaboration diagram for HTMLPurifier_Printer_ConfigForm:

Public Member Functions

 __construct ( $name, $doc_url=null, $compress=false)
 
 setTextareaDimensions ($cols=null, $rows=null)
 Sets default column and row size for textareas in sub-printers. More...
 
 render ($config, $allowed=true, $render_controls=true)
 Returns HTML output for a configuration form. More...
 
- Public Member Functions inherited from HTMLPurifier_Printer
 __construct ()
 Initialize $generator. More...
 
 prepareGenerator ($config)
 Give generator necessary configuration if possible. More...
 

Static Public Member Functions

static getCSS ()
 Retrieves styling, in case it is not accessible by webserver. More...
 
static getJavaScript ()
 Retrieves JavaScript, in case it is not accessible by webserver. More...
 

Protected Member Functions

 renderNamespace ($ns, $directives)
 Renders a single namespace. More...
 
- Protected Member Functions inherited from HTMLPurifier_Printer
 start ($tag, $attr=array())
 Main function that renders object or aspect of that object. More...
 
 end ($tag)
 Returns an end teg. More...
 
 element ($tag, $contents, $attr=array(), $escape=true)
 Prints a complete element with content inside. More...
 
 elementEmpty ($tag, $attr=array())
 
 text ($text)
 
 row ($name, $value)
 Prints a simple key/value row in a table. More...
 
 escape ($string)
 Escapes a string for HTML output. More...
 
 listify ($array, $polite=false)
 Takes a list of strings and turns them into a single list. More...
 
 getClass ($obj, $sec_prefix='')
 Retrieves the class of an object without prefixes, as well as metadata. More...
 

Protected Attributes

 $fields = array()
 Printers for specific fields. More...
 
 $docURL
 Documentation URL, can have fragment tagged on end. More...
 
 $name
 Name of form element to stuff config in. More...
 
 $compress = false
 Whether or not to compress directive names, clipping them off after a certain amount of letters. More...
 
- Protected Attributes inherited from HTMLPurifier_Printer
 $generator
 Instance of HTMLPurifier_Generator for HTML generation convenience funcs. More...
 
 $config
 Instance of HTMLPurifier_Config, for easy access. More...
 

Detailed Description

Todo:
Rewrite to use Interchange objects

Definition at line 6 of file ConfigForm.php.

Constructor & Destructor Documentation

◆ __construct()

HTMLPurifier_Printer_ConfigForm::__construct (   $name,
  $doc_url = null,
  $compress = false 
)
Parameters
$nameForm element name for directives to be stuffed into
$doc_urlString documentation URL, will have fragment tagged on
$compressInteger max length before compressing a directive name, set to false to turn off

Definition at line 36 of file ConfigForm.php.

References $compress, $name, HTMLPurifier_VarParser\BOOL, and fields.

38  {
39  parent::__construct();
40  $this->docURL = $doc_url;
41  $this->name = $name;
42  $this->compress = $compress;
43  // initialize sub-printers
46  }
Swiss-army knife configuration form field printer.
Definition: ConfigForm.php:238
$errors fields
Definition: imgupload.php:47
Bool form field printer.
Definition: ConfigForm.php:320
$name
Name of form element to stuff config in.
Definition: ConfigForm.php:22
$compress
Whether or not to compress directive names, clipping them off after a certain amount of letters...
Definition: ConfigForm.php:29

Member Function Documentation

◆ getCSS()

static HTMLPurifier_Printer_ConfigForm::getCSS ( )
static

Retrieves styling, in case it is not accessible by webserver.

Definition at line 61 of file ConfigForm.php.

61  {
62  return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.css');
63  }

◆ getJavaScript()

static HTMLPurifier_Printer_ConfigForm::getJavaScript ( )
static

Retrieves JavaScript, in case it is not accessible by webserver.

Definition at line 68 of file ConfigForm.php.

68  {
69  return file_get_contents(HTMLPURIFIER_PREFIX . '/HTMLPurifier/Printer/ConfigForm.js');
70  }

◆ render()

HTMLPurifier_Printer_ConfigForm::render (   $config,
  $allowed = true,
  $render_controls = true 
)

Returns HTML output for a configuration form.

Parameters
$configConfiguration object of current form state, or an array where [0] has an HTML namespace and [1] is being rendered.
$allowedOptional namespace(s) and directives to restrict form to.

Definition at line 78 of file ConfigForm.php.

References HTMLPurifier_Printer\$config, $ret, HTMLPurifier_Printer\element(), HTMLPurifier_Printer\elementEmpty(), HTMLPurifier_Printer\end(), HTMLPurifier_Config\getAllowedDirectivesForForm(), HTMLPurifier_Printer\prepareGenerator(), renderNamespace(), and HTMLPurifier_Printer\start().

78  {
79  if (is_array($config) && isset($config[0])) {
80  $gen_config = $config[0];
81  $config = $config[1];
82  } else {
83  $gen_config = $config;
84  }
85 
86  $this->config = $config;
87  $this->genConfig = $gen_config;
88  $this->prepareGenerator($gen_config);
89 
91  $all = array();
92  foreach ($allowed as $key) {
93  list($ns, $directive) = $key;
94  $all[$ns][$directive] = $config->get($ns .'.'. $directive);
95  }
96 
97  $ret = '';
98  $ret .= $this->start('table', array('class' => 'hp-config'));
99  $ret .= $this->start('thead');
100  $ret .= $this->start('tr');
101  $ret .= $this->element('th', 'Directive', array('class' => 'hp-directive'));
102  $ret .= $this->element('th', 'Value', array('class' => 'hp-value'));
103  $ret .= $this->end('tr');
104  $ret .= $this->end('thead');
105  foreach ($all as $ns => $directives) {
106  $ret .= $this->renderNamespace($ns, $directives);
107  }
108  if ($render_controls) {
109  $ret .= $this->start('tbody');
110  $ret .= $this->start('tr');
111  $ret .= $this->start('td', array('colspan' => 2, 'class' => 'controls'));
112  $ret .= $this->elementEmpty('input', array('type' => 'submit', 'value' => 'Submit'));
113  $ret .= '[<a href="?">Reset</a>]';
114  $ret .= $this->end('td');
115  $ret .= $this->end('tr');
116  $ret .= $this->end('tbody');
117  }
118  $ret .= $this->end('table');
119  return $ret;
120  }
renderNamespace($ns, $directives)
Renders a single namespace.
Definition: ConfigForm.php:127
start($tag, $attr=array())
Main function that renders object or aspect of that object.
Definition: Printer.php:45
elementEmpty($tag, $attr=array())
Definition: Printer.php:74
prepareGenerator($config)
Give generator necessary configuration if possible.
Definition: Printer.php:28
end($tag)
Returns an end teg.
Definition: Printer.php:55
element($tag, $contents, $attr=array(), $escape=true)
Prints a complete element with content inside.
Definition: Printer.php:68
$config
Instance of HTMLPurifier_Config, for easy access.
Definition: Printer.php:17
static getAllowedDirectivesForForm($allowed, $schema=null)
Returns a list of array(namespace, directive) for all directives that are allowed in a web-form conte...
Definition: Config.php:548
+ Here is the call graph for this function:

◆ renderNamespace()

HTMLPurifier_Printer_ConfigForm::renderNamespace (   $ns,
  $directives 
)
protected

Renders a single namespace.

Parameters
$nsString namespace name
$directiveAssociative array of directives to values

Definition at line 127 of file ConfigForm.php.

References $ret, HTMLPurifier_Printer\element(), HTMLPurifier_Printer\end(), fields, and HTMLPurifier_Printer\start().

Referenced by render().

127  {
128  $ret = '';
129  $ret .= $this->start('tbody', array('class' => 'namespace'));
130  $ret .= $this->start('tr');
131  $ret .= $this->element('th', $ns, array('colspan' => 2));
132  $ret .= $this->end('tr');
133  $ret .= $this->end('tbody');
134  $ret .= $this->start('tbody');
135  foreach ($directives as $directive => $value) {
136  $ret .= $this->start('tr');
137  $ret .= $this->start('th');
138  if ($this->docURL) {
139  $url = str_replace('%s', urlencode("$ns.$directive"), $this->docURL);
140  $ret .= $this->start('a', array('href' => $url));
141  }
142  $attr = array('for' => "{$this->name}:$ns.$directive");
143 
144  // crop directive name if it's too long
145  if (!$this->compress || (strlen($directive) < $this->compress)) {
146  $directive_disp = $directive;
147  } else {
148  $directive_disp = substr($directive, 0, $this->compress - 2) . '...';
149  $attr['title'] = $directive;
150  }
151 
152  $ret .= $this->element(
153  'label',
154  $directive_disp,
155  // component printers must create an element with this id
156  $attr
157  );
158  if ($this->docURL) $ret .= $this->end('a');
159  $ret .= $this->end('th');
160 
161  $ret .= $this->start('td');
162  $def = $this->config->def->info["$ns.$directive"];
163  if (is_int($def)) {
164  $allow_null = $def < 0;
165  $type = abs($def);
166  } else {
167  $type = $def->type;
168  $allow_null = isset($def->allow_null);
169  }
170  if (!isset($this->fields[$type])) $type = 0; // default
171  $type_obj = $this->fields[$type];
172  if ($allow_null) {
173  $type_obj = new HTMLPurifier_Printer_ConfigForm_NullDecorator($type_obj);
174  }
175  $ret .= $type_obj->render($ns, $directive, $value, $this->name, array($this->genConfig, $this->config));
176  $ret .= $this->end('td');
177  $ret .= $this->end('tr');
178  }
179  $ret .= $this->end('tbody');
180  return $ret;
181  }
Printer decorator for directives that accept null.
Definition: ConfigForm.php:188
start($tag, $attr=array())
Main function that renders object or aspect of that object.
Definition: Printer.php:45
end($tag)
Returns an end teg.
Definition: Printer.php:55
$errors fields
Definition: imgupload.php:47
element($tag, $contents, $attr=array(), $escape=true)
Prints a complete element with content inside.
Definition: Printer.php:68
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTextareaDimensions()

HTMLPurifier_Printer_ConfigForm::setTextareaDimensions (   $cols = null,
  $rows = null 
)

Sets default column and row size for textareas in sub-printers.

Parameters
$colsInteger columns of textarea, null to use default
$rowsInteger rows of textarea, null to use default

Definition at line 53 of file ConfigForm.php.

References fields.

53  {
54  if ($cols) $this->fields['default']->cols = $cols;
55  if ($rows) $this->fields['default']->rows = $rows;
56  }
$errors fields
Definition: imgupload.php:47

Field Documentation

◆ $compress

HTMLPurifier_Printer_ConfigForm::$compress = false
protected

Whether or not to compress directive names, clipping them off after a certain amount of letters.

False to disable or integer letters before clipping.

Definition at line 29 of file ConfigForm.php.

Referenced by __construct().

◆ $docURL

HTMLPurifier_Printer_ConfigForm::$docURL
protected

Documentation URL, can have fragment tagged on end.

Definition at line 17 of file ConfigForm.php.

◆ $fields

HTMLPurifier_Printer_ConfigForm::$fields = array()
protected

Printers for specific fields.

Definition at line 12 of file ConfigForm.php.

◆ $name

HTMLPurifier_Printer_ConfigForm::$name
protected

Name of form element to stuff config in.

Definition at line 22 of file ConfigForm.php.

Referenced by __construct(), and HTMLPurifier_Printer_ConfigForm_NullDecorator\render().


The documentation for this class was generated from the following file: