Fix #7402 - HTML editor cleaning in PHP
[pear] / HTML / Clean / BlockTd.php
1 <?php 
2
3 /**
4  * This handles 'td' tags (and puts nice borders on them.)
5  */
6
7  
8 require_once 'Block.php';
9 class  HTML_Clean_BlockTd extends HTML_Clean_Block
10 {
11     var $width = ''; // should be a percent.!
12     var $textAlign = 'left';
13     var $valign = 'top';
14     
15     var $colspan = 1;
16     var $rowspan = 1;
17     
18     
19      
20     function __construct($cfg) {
21          
22         if ($cfg['node']) {
23             $this->readElement($cfg['node']);
24             $this->updateElement($cfg['node']);
25         } 
26         parent::__construct();
27          
28     }
29     
30     function toObject ()
31     {
32         $ret = array(
33             'tag' => 'td',
34             'data-block' => 'Td',
35             'valign' => $this->valign,
36             'style' => array(
37                 'text-align' =>  $this->textAlign,
38                 'border' => 'solid 1px rgb(0, 0, 0)', // ??? hard coded?
39                 'border-collapse' => 'collapse',
40                 'padding' => '6px', // 8 for desktop / 4 for mobile
41                 'vertical-align'=> $this->valign
42             ),
43             html => $this->html
44         );
45         if ($this->width != '') {
46             $ret->width = $this->width;
47             $ret['style']['width'] = $this->width;  
48         }
49         
50         
51         if ($this->colspan > 1) {
52             $ret['colspan'] = $this->colspan ;
53         } 
54         if ($this->rowspan > 1) {
55             $ret['rowspan'] = $this->rowspan ;
56         }
57         
58            
59         
60         return $ret;
61          
62     }
63     
64     
65     function readElement ($node)
66     {
67         $node  = $node ? $node : $this->node ;
68         
69         
70         $this->width = $node->getAttribute('width');
71         $this->colspan = max(1,1*$node->getAttribute('colspan'));
72         $this->rowspan = max(1,1*$node->getAttribute('rowspan'));
73         $this->html = $this->innerHTML($node);
74         $styles = $this->styleToObject($node,true);
75         
76         if (!empty($styles['text-align'])) {
77             $this->textAlign = $styles['text-align'];
78         }
79         if ($node->hasAttribute('valign')) {
80             $this->valign = $node->getAttribute('valign');
81         }
82         
83     }
84     
85 }