ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Printer.php
Go to the documentation of this file.
1 <?php
2 
3 // OUT OF DATE, NEEDS UPDATING!
4 // USE XMLWRITER!
5 
7 {
8 
13  protected $generator;
14 
19  protected $config;
20 
24  public function __construct()
25  {
26  }
27 
32  public function prepareGenerator($config)
33  {
34  $all = $config->getAll();
36  $this->generator = new HTMLPurifier_Generator($config, $context);
37  }
38 
43  // function render() {}
44 
51  protected function start($tag, $attr = array())
52  {
53  return $this->generator->generateFromToken(
54  new HTMLPurifier_Token_Start($tag, $attr ? $attr : array())
55  );
56  }
57 
63  protected function end($tag)
64  {
65  return $this->generator->generateFromToken(
67  );
68  }
69 
78  protected function element($tag, $contents, $attr = array(), $escape = true)
79  {
80  return $this->start($tag, $attr) .
81  ($escape ? $this->escape($contents) : $contents) .
82  $this->end($tag);
83  }
84 
90  protected function elementEmpty($tag, $attr = array())
91  {
92  return $this->generator->generateFromToken(
93  new HTMLPurifier_Token_Empty($tag, $attr)
94  );
95  }
96 
101  protected function text($text)
102  {
103  return $this->generator->generateFromToken(
105  );
106  }
107 
114  protected function row($name, $value)
115  {
116  if (is_bool($value)) {
117  $value = $value ? 'On' : 'Off';
118  }
119  return
120  $this->start('tr') . "\n" .
121  $this->element('th', $name) . "\n" .
122  $this->element('td', $value) . "\n" .
123  $this->end('tr');
124  }
125 
131  protected function escape($string)
132  {
133  $string = HTMLPurifier_Encoder::cleanUTF8($string);
134  $string = htmlspecialchars($string, ENT_COMPAT, 'UTF-8');
135  return $string;
136  }
137 
144  protected function listify($array, $polite = false)
145  {
146  if (empty($array)) {
147  return 'None';
148  }
149  $ret = '';
150  $i = count($array);
151  foreach ($array as $value) {
152  $i--;
153  $ret .= $value;
154  if ($i > 0 && !($polite && $i == 1)) {
155  $ret .= ', ';
156  }
157  if ($polite && $i == 1) {
158  $ret .= 'and ';
159  }
160  }
161  return $ret;
162  }
163 
170  protected function getClass($obj, $sec_prefix = '')
171  {
172  static $five = null;
173  if ($five === null) {
174  $five = version_compare(PHP_VERSION, '5', '>=');
175  }
176  $prefix = 'HTMLPurifier_' . $sec_prefix;
177  if (!$five) {
178  $prefix = strtolower($prefix);
179  }
180  $class = str_replace($prefix, '', get_class($obj));
181  $lclass = strtolower($class);
182  $class .= '(';
183  switch ($lclass) {
184  case 'enum':
185  $values = array();
186  foreach ($obj->valid_values as $value => $bool) {
187  $values[] = $value;
188  }
189  $class .= implode(', ', $values);
190  break;
191  case 'css_composite':
192  $values = array();
193  foreach ($obj->defs as $def) {
194  $values[] = $this->getClass($def, $sec_prefix);
195  }
196  $class .= implode(', ', $values);
197  break;
198  case 'css_multiple':
199  $class .= $this->getClass($obj->single, $sec_prefix) . ', ';
200  $class .= $obj->max;
201  break;
202  case 'css_denyelementdecorator':
203  $class .= $this->getClass($obj->def, $sec_prefix) . ', ';
204  $class .= $obj->element;
205  break;
206  case 'css_importantdecorator':
207  $class .= $this->getClass($obj->def, $sec_prefix);
208  if ($obj->allow) {
209  $class .= ', !important';
210  }
211  break;
212  }
213  $class .= ')';
214  return $class;
215  }
216 }
217 
218 // vim: et sw=4 sts=4
Concrete end token class.
Definition: End.php:10
start($tag, $attr=array())
Main function that renders object or aspect of that object.
Definition: Printer.php:51
listify($array, $polite=false)
Takes a list of strings and turns them into a single list.
Definition: Printer.php:144
escape($string)
Escapes a string for HTML output.
Definition: Printer.php:131
$context
Definition: webdav.php:25
Generates HTML from tokens.
Definition: Generator.php:10
Concrete start token class.
Definition: Start.php:6
row($name, $value)
Prints a simple key/value row in a table.
Definition: Printer.php:114
elementEmpty($tag, $attr=array())
Definition: Printer.php:90
prepareGenerator($config)
Give generator necessary configuration if possible.
Definition: Printer.php:32
end($tag)
Returns an end tag.
Definition: Printer.php:63
static cleanUTF8($str, $force_php=false)
Cleans a UTF-8 string for well-formedness and SGML validity.
Definition: Encoder.php:134
$values
__construct()
Initialize $generator.
Definition: Printer.php:24
$text
Definition: errorreport.php:18
$generator
For HTML generation convenience funcs.
Definition: Printer.php:13
getClass($obj, $sec_prefix='')
Retrieves the class of an object without prefixes, as well as metadata.
Definition: Printer.php:170
Concrete empty token class.
Definition: Empty.php:6
element($tag, $contents, $attr=array(), $escape=true)
Prints a complete element with content inside.
Definition: Printer.php:78
$ret
Definition: parser.php:6
$i
Definition: disco.tpl.php:19
Registry object that contains information about the current context.
Definition: Context.php:10
$def
Definition: croninfo.php:21
$config
For easy access.
Definition: Printer.php:19
Concrete text token class.
Definition: Text.php:12
if(function_exists('posix_getuid') &&posix_getuid()===0) if(!array_key_exists('t', $options)) $tag
Definition: cron.php:35