~ubuntu-branches/ubuntu/maverick/mahara/maverick-updates

« back to all changes in this revision

Viewing changes to htdocs/lib/htmlpurifier/HTMLPurifier/AttrTransform/ImgSpace.php

  • Committer: Bazaar Package Importer
  • Author(s): Nigel McNie
  • Date: 2008-04-29 11:15:39 UTC
  • Revision ID: james.westby@ubuntu.com-20080429111539-b28eqkagavaub2zr
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
require_once 'HTMLPurifier/AttrTransform.php';
 
4
 
 
5
/**
 
6
 * Pre-transform that changes deprecated hspace and vspace attributes to CSS
 
7
 */
 
8
class HTMLPurifier_AttrTransform_ImgSpace extends HTMLPurifier_AttrTransform {
 
9
    
 
10
    protected $attr;
 
11
    protected $css = array(
 
12
        'hspace' => array('left', 'right'),
 
13
        'vspace' => array('top', 'bottom')
 
14
    );
 
15
    
 
16
    public function __construct($attr) {
 
17
        $this->attr = $attr;
 
18
        if (!isset($this->css[$attr])) {
 
19
            trigger_error(htmlspecialchars($attr) . ' is not valid space attribute');
 
20
        }
 
21
    }
 
22
    
 
23
    public function transform($attr, $config, $context) {
 
24
        
 
25
        if (!isset($attr[$this->attr])) return $attr;
 
26
        
 
27
        $width = $this->confiscateAttr($attr, $this->attr);
 
28
        // some validation could happen here
 
29
        
 
30
        if (!isset($this->css[$this->attr])) return $attr;
 
31
        
 
32
        $style = '';
 
33
        foreach ($this->css[$this->attr] as $suffix) {
 
34
            $property = "margin-$suffix";
 
35
            $style .= "$property:{$width}px;";
 
36
        }
 
37
        
 
38
        $this->prependCSS($attr, $style);
 
39
        
 
40
        return $attr;
 
41
        
 
42
    }
 
43
    
 
44
}
 
45