ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Printer.php
Go to the documentation of this file.
1 <?php
2 
3 // OUT OF DATE, NEEDS UPDATING!
4 // USE XMLWRITER!
5 
7 {
8 
12  protected $generator;
13 
17  protected $config;
18 
22  public function __construct() {
23  }
24 
28  public function prepareGenerator($config) {
29  $all = $config->getAll();
30  $context = new HTMLPurifier_Context();
31  $this->generator = new HTMLPurifier_Generator($config, $context);
32  }
33 
38  // function render() {}
39 
45  protected function start($tag, $attr = array()) {
46  return $this->generator->generateFromToken(
47  new HTMLPurifier_Token_Start($tag, $attr ? $attr : array())
48  );
49  }
50 
55  protected function end($tag) {
56  return $this->generator->generateFromToken(
57  new HTMLPurifier_Token_End($tag)
58  );
59  }
60 
68  protected function element($tag, $contents, $attr = array(), $escape = true) {
69  return $this->start($tag, $attr) .
70  ($escape ? $this->escape($contents) : $contents) .
71  $this->end($tag);
72  }
73 
74  protected function elementEmpty($tag, $attr = array()) {
75  return $this->generator->generateFromToken(
76  new HTMLPurifier_Token_Empty($tag, $attr)
77  );
78  }
79 
80  protected function text($text) {
81  return $this->generator->generateFromToken(
82  new HTMLPurifier_Token_Text($text)
83  );
84  }
85 
91  protected function row($name, $value) {
92  if (is_bool($value)) $value = $value ? 'On' : 'Off';
93  return
94  $this->start('tr') . "\n" .
95  $this->element('th', $name) . "\n" .
96  $this->element('td', $value) . "\n" .
97  $this->end('tr')
98  ;
99  }
100 
105  protected function escape($string) {
106  $string = HTMLPurifier_Encoder::cleanUTF8($string);
107  $string = htmlspecialchars($string, ENT_COMPAT, 'UTF-8');
108  return $string;
109  }
110 
116  protected function listify($array, $polite = false) {
117  if (empty($array)) return 'None';
118  $ret = '';
119  $i = count($array);
120  foreach ($array as $value) {
121  $i--;
122  $ret .= $value;
123  if ($i > 0 && !($polite && $i == 1)) $ret .= ', ';
124  if ($polite && $i == 1) $ret .= 'and ';
125  }
126  return $ret;
127  }
128 
134  protected function getClass($obj, $sec_prefix = '') {
135  static $five = null;
136  if ($five === null) $five = version_compare(PHP_VERSION, '5', '>=');
137  $prefix = 'HTMLPurifier_' . $sec_prefix;
138  if (!$five) $prefix = strtolower($prefix);
139  $class = str_replace($prefix, '', get_class($obj));
140  $lclass = strtolower($class);
141  $class .= '(';
142  switch ($lclass) {
143  case 'enum':
144  $values = array();
145  foreach ($obj->valid_values as $value => $bool) {
146  $values[] = $value;
147  }
148  $class .= implode(', ', $values);
149  break;
150  case 'css_composite':
151  $values = array();
152  foreach ($obj->defs as $def) {
153  $values[] = $this->getClass($def, $sec_prefix);
154  }
155  $class .= implode(', ', $values);
156  break;
157  case 'css_multiple':
158  $class .= $this->getClass($obj->single, $sec_prefix) . ', ';
159  $class .= $obj->max;
160  break;
161  case 'css_denyelementdecorator':
162  $class .= $this->getClass($obj->def, $sec_prefix) . ', ';
163  $class .= $obj->element;
164  break;
165  case 'css_importantdecorator':
166  $class .= $this->getClass($obj->def, $sec_prefix);
167  if ($obj->allow) $class .= ', !important';
168  break;
169  }
170  $class .= ')';
171  return $class;
172  }
173 
174 }
175 
176 // vim: et sw=4 sts=4