Source for file HTMLDefinition.php

Documentation is available at HTMLDefinition.php

  1. <?php
  2.  
  3. {
  4.     
  5.     /**
  6.      * Instance of HTMLPurifier_HTMLDefinition, for easy access
  7.      */
  8.     protected $def;
  9.     
  10.     public function render($config{
  11.         $ret '';
  12.         $this->config =$config;
  13.         
  14.         $this->def = $config->getHTMLDefinition();
  15.         
  16.         $ret .= $this->start('div'array('class' => 'HTMLPurifier_Printer'));
  17.         
  18.         $ret .= $this->renderDoctype();
  19.         $ret .= $this->renderEnvironment();
  20.         $ret .= $this->renderContentSets();
  21.         $ret .= $this->renderInfo();
  22.         
  23.         $ret .= $this->end('div');
  24.         
  25.         return $ret;
  26.     }
  27.     
  28.     /**
  29.      * Renders the Doctype table
  30.      */
  31.     protected function renderDoctype({
  32.         $doctype $this->def->doctype;
  33.         $ret '';
  34.         $ret .= $this->start('table');
  35.         $ret .= $this->element('caption''Doctype');
  36.         $ret .= $this->row('Name'$doctype->name);
  37.         $ret .= $this->row('XML'$doctype->xml 'Yes' 'No');
  38.         $ret .= $this->row('Default Modules'implode($doctype->modules', '));
  39.         $ret .= $this->row('Default Tidy Modules'implode($doctype->tidyModules', '));
  40.         $ret .= $this->end('table');
  41.         return $ret;
  42.     }
  43.     
  44.     
  45.     /**
  46.      * Renders environment table, which is miscellaneous info
  47.      */
  48.     protected function renderEnvironment({
  49.         $def $this->def;
  50.         
  51.         $ret '';
  52.         
  53.         $ret .= $this->start('table');
  54.         $ret .= $this->element('caption''Environment');
  55.         
  56.         $ret .= $this->row('Parent of fragment'$def->info_parent);
  57.         $ret .= $this->renderChildren($def->info_parent_def->child);
  58.         $ret .= $this->row('Block wrap name'$def->info_block_wrapper);
  59.         
  60.         $ret .= $this->start('tr');
  61.             $ret .= $this->element('th''Global attributes');
  62.             $ret .= $this->element('td'$this->listifyAttr($def->info_global_attr),0,0);
  63.         $ret .= $this->end('tr');
  64.         
  65.         $ret .= $this->start('tr');
  66.             $ret .= $this->element('th''Tag transforms');
  67.             $list array();
  68.             foreach ($def->info_tag_transform as $old => $new{
  69.                 $new $this->getClass($new'TagTransform_');
  70.                 $list["<$old> with $new";
  71.             }
  72.             $ret .= $this->element('td'$this->listify($list));
  73.         $ret .= $this->end('tr');
  74.         
  75.         $ret .= $this->start('tr');
  76.             $ret .= $this->element('th''Pre-AttrTransform');
  77.             $ret .= $this->element('td'$this->listifyObjectList($def->info_attr_transform_pre));
  78.         $ret .= $this->end('tr');
  79.         
  80.         $ret .= $this->start('tr');
  81.             $ret .= $this->element('th''Post-AttrTransform');
  82.             $ret .= $this->element('td'$this->listifyObjectList($def->info_attr_transform_post));
  83.         $ret .= $this->end('tr');
  84.         
  85.         $ret .= $this->end('table');
  86.         return $ret;
  87.     }
  88.     
  89.     /**
  90.      * Renders the Content Sets table
  91.      */
  92.     protected function renderContentSets({
  93.         $ret '';
  94.         $ret .= $this->start('table');
  95.         $ret .= $this->element('caption''Content Sets');
  96.         foreach ($this->def->info_content_sets as $name => $lookup{
  97.             $ret .= $this->heavyHeader($name);
  98.             $ret .= $this->start('tr');
  99.             $ret .= $this->element('td'$this->listifyTagLookup($lookup));
  100.             $ret .= $this->end('tr');
  101.         }
  102.         $ret .= $this->end('table');
  103.         return $ret;
  104.     }
  105.     
  106.     /**
  107.      * Renders the Elements ($info) table
  108.      */
  109.     protected function renderInfo({
  110.         $ret '';
  111.         $ret .= $this->start('table');
  112.         $ret .= $this->element('caption''Elements ($info)');
  113.         ksort($this->def->info);
  114.         $ret .= $this->heavyHeader('Allowed tags'2);
  115.         $ret .= $this->start('tr');
  116.         $ret .= $this->element('td'$this->listifyTagLookup($this->def->info)array('colspan' => 2));
  117.         $ret .= $this->end('tr');
  118.         foreach ($this->def->info as $name => $def{
  119.             $ret .= $this->start('tr');
  120.                 $ret .= $this->element('th'"<$name>"array('class'=>'heavy''colspan' => 2));
  121.             $ret .= $this->end('tr');
  122.             $ret .= $this->start('tr');
  123.                 $ret .= $this->element('th''Inline content');
  124.                 $ret .= $this->element('td'$def->descendants_are_inline 'Yes' 'No');
  125.             $ret .= $this->end('tr');
  126.             if (!empty($def->excludes)) {
  127.                 $ret .= $this->start('tr');
  128.                     $ret .= $this->element('th''Excludes');
  129.                     $ret .= $this->element('td'$this->listifyTagLookup($def->excludes));
  130.                 $ret .= $this->end('tr');
  131.             }
  132.             if (!empty($def->attr_transform_pre)) {
  133.                 $ret .= $this->start('tr');
  134.                     $ret .= $this->element('th''Pre-AttrTransform');
  135.                     $ret .= $this->element('td'$this->listifyObjectList($def->attr_transform_pre));
  136.                 $ret .= $this->end('tr');
  137.             }
  138.             if (!empty($def->attr_transform_post)) {
  139.                 $ret .= $this->start('tr');
  140.                     $ret .= $this->element('th''Post-AttrTransform');
  141.                     $ret .= $this->element('td'$this->listifyObjectList($def->attr_transform_post));
  142.                 $ret .= $this->end('tr');
  143.             }
  144.             if (!empty($def->auto_close)) {
  145.                 $ret .= $this->start('tr');
  146.                     $ret .= $this->element('th''Auto closed by');
  147.                     $ret .= $this->element('td'$this->listifyTagLookup($def->auto_close));
  148.                 $ret .= $this->end('tr');
  149.             }
  150.             $ret .= $this->start('tr');
  151.                 $ret .= $this->element('th''Allowed attributes');
  152.                 $ret .= $this->element('td',$this->listifyAttr($def->attr)array()0);
  153.             $ret .= $this->end('tr');
  154.             
  155.             if (!empty($def->required_attr)) {
  156.                 $ret .= $this->row('Required attributes'$this->listify($def->required_attr));
  157.             }
  158.             
  159.             $ret .= $this->renderChildren($def->child);
  160.         }
  161.         $ret .= $this->end('table');
  162.         return $ret;
  163.     }
  164.     
  165.     /** 
  166.      * Renders a row describing the allowed children of an element
  167.      * @param $def HTMLPurifier_ChildDef of pertinent element
  168.      */
  169.     protected function renderChildren($def{
  170.         $context new HTMLPurifier_Context();
  171.         $ret '';
  172.         $ret .= $this->start('tr');
  173.             $elements array();
  174.             $attr array();
  175.             if (isset($def->elements)) {
  176.                 if ($def->type == 'strictblockquote'{
  177.                     $def->validateChildren(array()$this->config$context);
  178.                 }
  179.                 $elements $def->elements;
  180.             }
  181.             if ($def->type == 'chameleon'{
  182.                 $attr['rowspan'2;
  183.             elseif ($def->type == 'empty'{
  184.                 $elements array();
  185.             elseif ($def->type == 'table'{
  186.                 $elements array_flip(array('col''caption''colgroup''thead',
  187.                     'tfoot''tbody''tr'));
  188.             }
  189.             $ret .= $this->element('th''Allowed children'$attr);
  190.             
  191.             if ($def->type == 'chameleon'{
  192.                 
  193.                 $ret .= $this->element('td',
  194.                     '<em>Block</em>: ' .
  195.                     $this->escape($this->listifyTagLookup($def->block->elements)),0,0);
  196.                 $ret .= $this->end('tr');
  197.                 $ret .= $this->start('tr');
  198.                 $ret .= $this->element('td',
  199.                     '<em>Inline</em>: ' .
  200.                     $this->escape($this->listifyTagLookup($def->inline->elements)),0,0);
  201.                 
  202.             elseif ($def->type == 'custom'{
  203.                 
  204.                 $ret .= $this->element('td''<em>'.ucfirst($def->type).'</em>: ' .
  205.                     $def->dtd_regex);
  206.                 
  207.             else {
  208.                 $ret .= $this->element('td',
  209.                     '<em>'.ucfirst($def->type).'</em>: ' .
  210.                     $this->escape($this->listifyTagLookup($elements)),0,0);
  211.             }
  212.         $ret .= $this->end('tr');
  213.         return $ret;
  214.     }
  215.     
  216.     /** 
  217.      * Listifies a tag lookup table.
  218.      * @param $array Tag lookup array in form of array('tagname' => true)
  219.      */
  220.     protected function listifyTagLookup($array{
  221.         ksort($array);
  222.         $list array();
  223.         foreach ($array as $name => $discard{
  224.             if ($name !== '#PCDATA' && !isset($this->def->info[$name])) continue;
  225.             $list[$name;
  226.         }
  227.         return $this->listify($list);
  228.     }
  229.     
  230.     /**
  231.      * Listifies a list of objects by retrieving class names and internal state
  232.      * @param $array List of objects
  233.      * @todo Also add information about internal state
  234.      */
  235.     protected function listifyObjectList($array{
  236.         ksort($array);
  237.         $list array();
  238.         foreach ($array as $discard => $obj{
  239.             $list[$this->getClass($obj'AttrTransform_');
  240.         }
  241.         return $this->listify($list);
  242.     }
  243.     
  244.     /**
  245.      * Listifies a hash of attributes to AttrDef classes
  246.      * @param $array Array hash in form of array('attrname' => HTMLPurifier_AttrDef)
  247.      */
  248.     protected function listifyAttr($array{
  249.         ksort($array);
  250.         $list array();
  251.         foreach ($array as $name => $obj{
  252.             if ($obj === falsecontinue;
  253.             $list["$name&nbsp;=&nbsp;<i>$this->getClass($obj'AttrDef_''</i>';
  254.         }
  255.         return $this->listify($list);
  256.     }
  257.     
  258.     /**
  259.      * Creates a heavy header row
  260.      */
  261.     protected function heavyHeader($text$num 1{
  262.         $ret '';
  263.         $ret .= $this->start('tr');
  264.         $ret .= $this->element('th'$textarray('colspan' => $num'class' => 'heavy'));
  265.         $ret .= $this->end('tr');
  266.         return $ret;
  267.     }
  268.     
  269. }

Documentation generated on Thu, 19 Jun 2008 18:49:27 -0400 by phpDocumentor 1.4.2