0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-01-03 13:21:51 +00:00

Rename PureHTMLDefinition -> HTMLPurifier_Definition, and internal classes too.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@69 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-07-21 23:38:44 +00:00
parent 436873e227
commit 404ca68c87
4 changed files with 37 additions and 37 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
class PureHTMLDefinition class HTMLPurifier_Definition
{ {
var $generator; var $generator;
@ -28,7 +28,7 @@ class PureHTMLDefinition
'ul' => true 'ul' => true
); );
function PureHTMLDefinition() { function HTMLPurifier_Definition() {
$this->generator = new HTMLPurifier_Generator(); $this->generator = new HTMLPurifier_Generator();
} }
@ -64,21 +64,21 @@ class PureHTMLDefinition
$e_inline = "a | $e_special | $e_fontstyle | $e_phrase". $e_inline = "a | $e_special | $e_fontstyle | $e_phrase".
" | $e_inline_forms"; " | $e_inline_forms";
// note the casing // note the casing
$e_Inline = new HTMLDTD_ChildDef_Optional("#PCDATA | $e_inline". $e_Inline = new HTMLPurifier_ChildDef_Optional("#PCDATA | $e_inline".
" | $e_misc_inline"); " | $e_misc_inline");
$e_heading = 'h1|h2|h3|h4|h5|h6'; $e_heading = 'h1|h2|h3|h4|h5|h6';
$e_lists = 'ul | ol | dl'; $e_lists = 'ul | ol | dl';
$e_blocktext = 'pre | hr | blockquote | address'; $e_blocktext = 'pre | hr | blockquote | address';
$e_block = "p | $e_heading | div | $e_lists | $e_blocktext | table"; $e_block = "p | $e_heading | div | $e_lists | $e_blocktext | table";
$e_Flow = new HTMLDTD_ChildDef_Optional("#PCDATA | $e_block". $e_Flow = new HTMLPurifier_ChildDef_Optional("#PCDATA | $e_block".
" | $e_inline | $e_misc"); " | $e_inline | $e_misc");
$e_a_content = new HTMLDTD_ChildDef_Optional("#PCDATA | $e_special". $e_a_content = new HTMLPurifier_ChildDef_Optional("#PCDATA | $e_special".
" | $e_fontstyle | $e_phrase | $e_inline_forms | $e_misc_inline"); " | $e_fontstyle | $e_phrase | $e_inline_forms | $e_misc_inline");
$e_pre_content = new HTMLDTD_ChildDef_Optional("#PCDATA | a". $e_pre_content = new HTMLPurifier_ChildDef_Optional("#PCDATA | a".
" | $e_special_basic | $e_fontstyle_basic | $e_phrase_basic". " | $e_special_basic | $e_fontstyle_basic | $e_phrase_basic".
" | $e_inline_forms | $e_misc_inline"); " | $e_inline_forms | $e_misc_inline");
$e_form_content = new HTMLDTD_ChildDef_Optional(''); //unused $e_form_content = new HTMLPurifier_ChildDef_Optional(''); //unused
$e_form_button_content = new HTMLDTD_ChildDef_Optional(''); // unused $e_form_button_content = new HTMLPurifier_ChildDef_Optional(''); // unused
$this->info['ins'] = $this->info['ins'] =
$this->info['del'] = $this->info['del'] =
@ -126,22 +126,22 @@ class PureHTMLDefinition
$this->info['ol'] = $this->info['ol'] =
$this->info['ul'] = $this->info['ul'] =
new HTMLDTD_Element( new HTMLDTD_Element(
new HTMLDTD_ChildDef_Required('li') new HTMLPurifier_ChildDef_Required('li')
); );
$this->info['dl'] = $this->info['dl'] =
new HTMLDTD_Element( new HTMLDTD_Element(
new HTMLDTD_ChildDef_Required('dt|dd') new HTMLPurifier_ChildDef_Required('dt|dd')
); );
$this->info['address'] = $this->info['address'] =
new HTMLDTD_Element( new HTMLDTD_Element(
new HTMLDTD_ChildDef_Optional("#PCDATA | p | $e_inline". new HTMLPurifier_ChildDef_Optional("#PCDATA | p | $e_inline".
" | $e_misc_inline") " | $e_misc_inline")
); );
$this->info['img'] = $this->info['img'] =
$this->info['br'] = $this->info['br'] =
$this->info['hr'] = new HTMLDTD_Element(new HTMLDTD_ChildDef_Empty()); $this->info['hr'] = new HTMLDTD_Element(new HTMLPurifier_ChildDef_Empty());
$this->info['pre'] = new HTMLDTD_Element($e_pre_content); $this->info['pre'] = new HTMLDTD_Element($e_pre_content);
@ -437,7 +437,7 @@ class HTMLDTD_Element
} }
// HTMLDTD_ChildDef and inheritance have three types of output: // HTMLPurifier_ChildDef and inheritance have three types of output:
// true = leave nodes as is // true = leave nodes as is
// false = delete parent node and all children // false = delete parent node and all children
// array(...) = replace children nodes with these // array(...) = replace children nodes with these
@ -448,12 +448,12 @@ class HTMLDTD_Element
// we may end up writing custom code for each HTML case // we may end up writing custom code for each HTML case
// in order to make it self correcting // in order to make it self correcting
class HTMLDTD_ChildDef class HTMLPurifier_ChildDef
{ {
var $type = 'custom'; var $type = 'custom';
var $dtd_regex; var $dtd_regex;
var $_pcre_regex; var $_pcre_regex;
function HTMLDTD_ChildDef($dtd_regex) { function HTMLPurifier_ChildDef($dtd_regex) {
$this->dtd_regex = $dtd_regex; $this->dtd_regex = $dtd_regex;
$this->_compileRegex(); $this->_compileRegex();
} }
@ -495,10 +495,10 @@ class HTMLDTD_ChildDef
return (bool) $okay; return (bool) $okay;
} }
} }
class HTMLDTD_ChildDef_Simple extends HTMLDTD_ChildDef class HTMLPurifier_ChildDef_Simple extends HTMLPurifier_ChildDef
{ {
var $elements = array(); var $elements = array();
function HTMLDTD_ChildDef_Simple($elements) { function HTMLPurifier_ChildDef_Simple($elements) {
if (is_string($elements)) { if (is_string($elements)) {
$elements = str_replace(' ', '', $elements); $elements = str_replace(' ', '', $elements);
$elements = explode('|', $elements); $elements = explode('|', $elements);
@ -512,7 +512,7 @@ class HTMLDTD_ChildDef_Simple extends HTMLDTD_ChildDef
trigger_error('Cannot call abstract function!', E_USER_ERROR); trigger_error('Cannot call abstract function!', E_USER_ERROR);
} }
} }
class HTMLDTD_ChildDef_Required extends HTMLDTD_ChildDef_Simple class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef_Simple
{ {
var $type = 'required'; var $type = 'required';
function validateChildren($tokens_of_children) { function validateChildren($tokens_of_children) {
@ -583,7 +583,7 @@ class HTMLDTD_ChildDef_Required extends HTMLDTD_ChildDef_Simple
// only altered behavior is that it returns an empty array // only altered behavior is that it returns an empty array
// instead of a false (to delete the node) // instead of a false (to delete the node)
class HTMLDTD_ChildDef_Optional extends HTMLDTD_ChildDef_Required class HTMLPurifier_ChildDef_Optional extends HTMLPurifier_ChildDef_Required
{ {
var $type = 'optional'; var $type = 'optional';
function validateChildren($tokens_of_children) { function validateChildren($tokens_of_children) {
@ -594,19 +594,19 @@ class HTMLDTD_ChildDef_Optional extends HTMLDTD_ChildDef_Required
} }
// placeholder // placeholder
class HTMLDTD_ChildDef_Empty extends HTMLDTD_ChildDef class HTMLPurifier_ChildDef_Empty extends HTMLPurifier_ChildDef
{ {
var $type = 'empty'; var $type = 'empty';
function HTMLDTD_ChildDef_Empty() {} function HTMLPurifier_ChildDef_Empty() {}
function validateChildren() { function validateChildren() {
return false; return false;
} }
} }
class HTMLDTD_AttrDef class HTMLPurifier_AttrDef
{ {
var $def; var $def;
function HTMLDTD_AttrDef($def) { function HTMLPurifier_AttrDef($def) {
$this->def = $def; $this->def = $def;
} }
} }

View File

@ -9,7 +9,7 @@ class HTMLPurifier
function HTMLPurifier() { function HTMLPurifier() {
$this->lexer = new HTMLPurifier_Lexer(); $this->lexer = new HTMLPurifier_Lexer();
$this->definition = new PureHTMLDefinition(); $this->definition = new HTMLPurifier_Definition();
$this->generator = new HTMLPurifier_Generator(); $this->generator = new HTMLPurifier_Generator();
} }

View File

@ -1,12 +1,12 @@
<?php <?php
class Test_HTMLDTD_ChildDef extends UnitTestCase class Test_HTMLPurifier_ChildDef extends UnitTestCase
{ {
var $lex; var $lex;
var $gen; var $gen;
function Test_HTMLDTD_ChildDef() { function Test_HTMLPurifier_ChildDef() {
$this->lex = new HTMLPurifier_Lexer(); $this->lex = new HTMLPurifier_Lexer();
$this->gen = new HTMLPurifier_Generator(); $this->gen = new HTMLPurifier_Generator();
parent::UnitTestCase(); parent::UnitTestCase();
@ -29,7 +29,7 @@ class Test_HTMLDTD_ChildDef extends UnitTestCase
function test_complex() { function test_complex() {
// the table definition // the table definition
$def = new HTMLDTD_ChildDef( $def = new HTMLPurifier_ChildDef(
'(caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))'); '(caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))');
$inputs[0] = ''; $inputs[0] = '';
@ -57,7 +57,7 @@ class Test_HTMLDTD_ChildDef extends UnitTestCase
// simple is actually an abstract class // simple is actually an abstract class
// but we're unit testing some of the conv. functions it gives // but we're unit testing some of the conv. functions it gives
$def = new HTMLDTD_ChildDef_Simple('foobar | bang |gizmo'); $def = new HTMLPurifier_ChildDef_Simple('foobar | bang |gizmo');
$this->assertEqual($def->elements, $this->assertEqual($def->elements,
array( array(
'foobar' => true 'foobar' => true
@ -65,7 +65,7 @@ class Test_HTMLDTD_ChildDef extends UnitTestCase
,'gizmo' => true ,'gizmo' => true
)); ));
$def = new HTMLDTD_ChildDef_Simple(array('href', 'src')); $def = new HTMLPurifier_ChildDef_Simple(array('href', 'src'));
$this->assertEqual($def->elements, $this->assertEqual($def->elements,
array( array(
'href' => true 'href' => true
@ -75,7 +75,7 @@ class Test_HTMLDTD_ChildDef extends UnitTestCase
function test_required_pcdata_forbidden() { function test_required_pcdata_forbidden() {
$def = new HTMLDTD_ChildDef_Required('dt | dd'); $def = new HTMLPurifier_ChildDef_Required('dt | dd');
$inputs[0] = array(); $inputs[0] = array();
$expect[0] = false; $expect[0] = false;
@ -103,7 +103,7 @@ class Test_HTMLDTD_ChildDef extends UnitTestCase
} }
function test_required_pcdata_allowed() { function test_required_pcdata_allowed() {
$def = new HTMLDTD_ChildDef_Required('#PCDATA | b'); $def = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
$inputs[0] = '<b>Bold text</b><img />'; $inputs[0] = '<b>Bold text</b><img />';
$expect[0] = '<b>Bold text</b>&lt;img /&gt;'; $expect[0] = '<b>Bold text</b>&lt;img /&gt;';
@ -112,7 +112,7 @@ class Test_HTMLDTD_ChildDef extends UnitTestCase
} }
function test_optional() { function test_optional() {
$def = new HTMLDTD_ChildDef_Optional('b | i'); $def = new HTMLPurifier_ChildDef_Optional('b | i');
$inputs[0] = '<b>Bold text</b><img />'; $inputs[0] = '<b>Bold text</b><img />';
$expect[0] = '<b>Bold text</b>'; $expect[0] = '<b>Bold text</b>';
@ -125,14 +125,14 @@ class Test_HTMLDTD_ChildDef extends UnitTestCase
} }
class Test_PureHTMLDefinition extends UnitTestCase class Test_HTMLPurifier_Definition extends UnitTestCase
{ {
var $def, $lex; var $def, $lex;
function Test_PureHTMLDefinition() { function Test_HTMLPurifier_Definition() {
$this->UnitTestCase(); $this->UnitTestCase();
$this->def = new PureHTMLDefinition(); $this->def = new HTMLPurifier_Definition();
$this->def->loadData(); $this->def->loadData();
$this->lex = new HTMLPurifier_Lexer(); $this->lex = new HTMLPurifier_Lexer();
} }

View File

@ -11,7 +11,7 @@ require_once 'XML/HTMLSax3.php'; // optional PEAR class
require_once 'HTMLPurifier/HTMLPurifier.php'; require_once 'HTMLPurifier/HTMLPurifier.php';
require_once 'HTMLPurifier/Lexer.php'; require_once 'HTMLPurifier/Lexer.php';
require_once 'HTMLPurifier/Token.php'; require_once 'HTMLPurifier/Token.php';
require_once 'HTMLPurifier/PureHTMLDefinition.php'; require_once 'HTMLPurifier/Definition.php';
require_once 'HTMLPurifier/Generator.php'; require_once 'HTMLPurifier/Generator.php';
$test = new GroupTest('HTMLPurifier'); $test = new GroupTest('HTMLPurifier');
@ -19,7 +19,7 @@ $test = new GroupTest('HTMLPurifier');
$test->addTestFile('HTMLPurifier.php'); $test->addTestFile('HTMLPurifier.php');
$test->addTestFile('Lexer.php'); $test->addTestFile('Lexer.php');
//$test->addTestFile('Token.php'); //$test->addTestFile('Token.php');
$test->addTestFile('PureHTMLDefinition.php'); $test->addTestFile('Definition.php');
$test->addTestFile('Generator.php'); $test->addTestFile('Generator.php');
$test->run( new HtmlReporter() ); $test->run( new HtmlReporter() );