diff options
Diffstat (limited to 'ext/tidy')
-rw-r--r-- | ext/tidy/config.m4 | 5 | ||||
-rw-r--r-- | ext/tidy/php_tidy.h | 12 | ||||
-rw-r--r-- | ext/tidy/tests/002.phpt | 4 | ||||
-rw-r--r-- | ext/tidy/tests/003.phpt | 6 | ||||
-rw-r--r-- | ext/tidy/tests/005-mb.phpt | 4 | ||||
-rw-r--r-- | ext/tidy/tests/005.phpt | 4 | ||||
-rw-r--r-- | ext/tidy/tests/006.phpt | 4 | ||||
-rw-r--r-- | ext/tidy/tests/007.phpt | 36 | ||||
-rw-r--r-- | ext/tidy/tests/008.phpt | 4 | ||||
-rw-r--r-- | ext/tidy/tests/009.phpt | 2 | ||||
-rw-r--r-- | ext/tidy/tests/011.phpt | 2 | ||||
-rw-r--r-- | ext/tidy/tests/012.phpt | 2 | ||||
-rw-r--r-- | ext/tidy/tests/014.phpt | 6 | ||||
-rw-r--r-- | ext/tidy/tests/015.phpt | 4 | ||||
-rw-r--r-- | ext/tidy/tests/018.phpt | 8 | ||||
-rw-r--r-- | ext/tidy/tests/019.phpt | 44 | ||||
-rw-r--r-- | ext/tidy/tests/021.phpt | 11 | ||||
-rw-r--r-- | ext/tidy/tests/029.phpt | 10 | ||||
-rw-r--r-- | ext/tidy/tests/035.phpt | 2 | ||||
-rw-r--r-- | ext/tidy/tests/bug54682.phpt | 2 | ||||
-rw-r--r-- | ext/tidy/tests/tidy_error1.phpt | 3 | ||||
-rw-r--r-- | ext/tidy/tidy.c | 707 | ||||
-rw-r--r-- | ext/tidy/tidy.stub.php | 185 | ||||
-rw-r--r-- | ext/tidy/tidy_arginfo.h | 283 |
24 files changed, 769 insertions, 581 deletions
diff --git a/ext/tidy/config.m4 b/ext/tidy/config.m4 index dab58787d4..bc0976a1dd 100644 --- a/ext/tidy/config.m4 +++ b/ext/tidy/config.m4 @@ -65,8 +65,9 @@ if test "$PHP_TIDY" != "no"; then PHP_ADD_LIBRARY_WITH_PATH($TIDY_LIB_NAME, $TIDY_LIBDIR, TIDY_SHARED_LIBADD) PHP_ADD_INCLUDE($TIDY_INCDIR) - - PHP_NEW_EXTENSION(tidy, tidy.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) + dnl Add -Wno-ignored-qualifiers as this is an issue upstream + TIDY_COMPILER_FLAGS="$TIDY_CFLAGS -Wno-ignored-qualifiers -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1" + PHP_NEW_EXTENSION(tidy, tidy.c, $ext_shared,, $TIDY_COMPILER_FLAGS) PHP_SUBST(TIDY_SHARED_LIBADD) AC_DEFINE(HAVE_TIDY,1,[ ]) fi diff --git a/ext/tidy/php_tidy.h b/ext/tidy/php_tidy.h index 3be6bf4388..ab9e90eb93 100644 --- a/ext/tidy/php_tidy.h +++ b/ext/tidy/php_tidy.h @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | @@ -25,16 +23,6 @@ extern zend_module_entry tidy_module_entry; #include "php_version.h" #define PHP_TIDY_VERSION PHP_VERSION -#define TIDY_METHOD_MAP(name, func_name, arg_types) \ - ZEND_NAMED_FE(name, ZEND_FN(func_name), arg_types) -#define TIDY_NODE_METHOD(name) PHP_FUNCTION(tnm_ ##name) -#define TIDY_NODE_ME(name, param) TIDY_METHOD_MAP(name, tnm_ ##name, param) -#define TIDY_NODE_PRIVATE_ME(name, param) ZEND_NAMED_ME(name, ZEND_FN(tnm_ ##name), param, ZEND_ACC_PRIVATE) -#define TIDY_DOC_METHOD(name) PHP_FUNCTION(tdm_ ##name) -#define TIDY_DOC_ME(name, param) TIDY_METHOD_MAP(name, tdm_ ##name, param) -#define TIDY_ATTR_METHOD(name) PHP_FUNCTION(tam_ ##name) -#define TIDY_ATTR_ME(name, param) TIDY_METHOD_MAP(name, tam_ ##name, param) - ZEND_BEGIN_MODULE_GLOBALS(tidy) char *default_config; zend_bool clean_output; diff --git a/ext/tidy/tests/002.phpt b/ext/tidy/tests/002.phpt index c6092c7b94..d276cfabed 100644 --- a/ext/tidy/tests/002.phpt +++ b/ext/tidy/tests/002.phpt @@ -4,8 +4,8 @@ tidy_parse_string() <?php if (!extension_loaded("tidy")) print "skip"; ?> --FILE-- <?php - $a = tidy_parse_string("<HTML></HTML>"); - echo tidy_get_output($a); + $a = tidy_parse_string("<HTML></HTML>"); + echo tidy_get_output($a); ?> --EXPECT-- diff --git a/ext/tidy/tests/003.phpt b/ext/tidy/tests/003.phpt index df4cd18f5f..43bd6729d7 100644 --- a/ext/tidy/tests/003.phpt +++ b/ext/tidy/tests/003.phpt @@ -5,9 +5,9 @@ tidy_clean_repair() --FILE-- <?php - $a = tidy_parse_string("<HTML></HTML>"); - tidy_clean_repair($a); - echo tidy_get_output($a); + $a = tidy_parse_string("<HTML></HTML>"); + tidy_clean_repair($a); + echo tidy_get_output($a); ?> --EXPECTF-- diff --git a/ext/tidy/tests/005-mb.phpt b/ext/tidy/tests/005-mb.phpt index c7b8e20676..7fc43d9f27 100644 --- a/ext/tidy/tests/005-mb.phpt +++ b/ext/tidy/tests/005-mb.phpt @@ -4,8 +4,8 @@ tidy_parse_file() <?php if (!extension_loaded("tidy")) print "skip"; ?> --FILE-- <?php - $a = tidy_parse_file(__DIR__."/005私はガラスを食べられます.html"); - echo tidy_get_output($a); + $a = tidy_parse_file(__DIR__."/005私はガラスを食べられます.html"); + echo tidy_get_output($a); ?> --EXPECT-- diff --git a/ext/tidy/tests/005.phpt b/ext/tidy/tests/005.phpt index 49b0a2ad4d..88d906e896 100644 --- a/ext/tidy/tests/005.phpt +++ b/ext/tidy/tests/005.phpt @@ -4,8 +4,8 @@ tidy_parse_file() <?php if (!extension_loaded("tidy")) print "skip"; ?> --FILE-- <?php - $a = tidy_parse_file(__DIR__."/005.html"); - echo tidy_get_output($a); + $a = tidy_parse_file(__DIR__."/005.html"); + echo tidy_get_output($a); ?> --EXPECT-- diff --git a/ext/tidy/tests/006.phpt b/ext/tidy/tests/006.phpt index a36006f346..5ca856075d 100644 --- a/ext/tidy/tests/006.phpt +++ b/ext/tidy/tests/006.phpt @@ -4,8 +4,8 @@ Verbose tidy_get_error_buffer() <?php if (!extension_loaded("tidy")) print "skip"; ?> --FILE-- <?php - $a = tidy_parse_string("<HTML><asd asdf></HTML>"); - echo tidy_get_error_buffer($a); + $a = tidy_parse_string("<HTML><asd asdf></HTML>"); + echo tidy_get_error_buffer($a); ?> --EXPECT-- diff --git a/ext/tidy/tests/007.phpt b/ext/tidy/tests/007.phpt index bae8918625..0523957110 100644 --- a/ext/tidy/tests/007.phpt +++ b/ext/tidy/tests/007.phpt @@ -6,24 +6,30 @@ Verbose tidy_getopt() tidy.default_config= --FILE-- <?php - $a = new tidy(__DIR__."/007.html"); - echo "Current Value of 'tidy-mark': "; - var_dump($a->getopt("tidy-mark")); - echo "Current Value of 'error-file': "; - var_dump($a->getopt("error-file")); - echo "Current Value of 'tab-size': "; - var_dump($a->getopt("tab-size")); +$a = new tidy(__DIR__."/007.html"); +echo "Current Value of 'tidy-mark': "; +var_dump($a->getopt("tidy-mark")); +echo "Current Value of 'error-file': "; +var_dump($a->getopt("error-file")); +echo "Current Value of 'tab-size': "; +var_dump($a->getopt("tab-size")); + +try { + $a->getopt('bogus-opt'); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} + +try { + tidy_getopt($a, 'non-ASCII string ���'); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} - var_dump($a->getopt('bogus-opt')); - var_dump(tidy_getopt($a, 'non-ASCII string ')); ?> --EXPECTF-- Current Value of 'tidy-mark': bool(false) Current Value of 'error-file': string(0) "" Current Value of 'tab-size': int(8) - -Warning: tidy::getOpt(): Unknown Tidy Configuration Option 'bogus-opt' in %s007.php on line 10 -bool(false) - -Warning: tidy_getopt(): Unknown Tidy Configuration Option 'non-ASCII string ' in %s007.php on line 11 -bool(false) +tidy::getOpt(): Argument #1 ($option) is an invalid configuration option, "bogus-opt" given +tidy_getopt(): Argument #2 ($option) is an invalid configuration option, "non-ASCII string ���" given diff --git a/ext/tidy/tests/008.phpt b/ext/tidy/tests/008.phpt index 303a2f9d8a..f98f79954e 100644 --- a/ext/tidy/tests/008.phpt +++ b/ext/tidy/tests/008.phpt @@ -4,8 +4,8 @@ Accessing the error buffer via $obj->error_buf... <?php if (!extension_loaded("tidy")) print "skip"; ?> --FILE-- <?php - $a = tidy_parse_string("<HTML><asd asdf></HTML>"); - echo $a->errorBuffer; + $a = tidy_parse_string("<HTML><asd asdf></HTML>"); + echo $a->errorBuffer; ?> --EXPECT-- line 1 column 1 - Warning: missing <!DOCTYPE> declaration diff --git a/ext/tidy/tests/009.phpt b/ext/tidy/tests/009.phpt index c2bbfb9760..b3e04d805f 100644 --- a/ext/tidy/tests/009.phpt +++ b/ext/tidy/tests/009.phpt @@ -6,7 +6,7 @@ tidy_doc object overloading <?php $a = tidy_parse_string("<HTML></HTML>"); - echo $a; + echo $a; ?> --EXPECT-- diff --git a/ext/tidy/tests/011.phpt b/ext/tidy/tests/011.phpt index 56cb0aa893..f664f69ebf 100644 --- a/ext/tidy/tests/011.phpt +++ b/ext/tidy/tests/011.phpt @@ -4,7 +4,7 @@ Accessing attributes of a node <?php if (!extension_loaded("tidy")) print "skip"; ?> --FILE-- <?php - $a = tidy_parse_string("<HTML><BODY BGCOLOR=#FFFFFF ALINK=#000000></BODY></HTML>"); + $a = tidy_parse_string("<HTML><BODY BGCOLOR=#FFFFFF ALINK=#000000></BODY></HTML>"); $body = $a->body(); var_dump($body->attribute); foreach($body->attribute as $key=>$val) { diff --git a/ext/tidy/tests/012.phpt b/ext/tidy/tests/012.phpt index eae6eca44c..0cfa3ef8c6 100644 --- a/ext/tidy/tests/012.phpt +++ b/ext/tidy/tests/012.phpt @@ -25,7 +25,7 @@ Accessing children nodes } - $a = tidy_parse_string("<HTML><BODY BGCOLOR=#FFFFFF ALINK=#000000><B>Hi</B><I>Bye<U>Test</U></I></BODY></HTML>", array('newline' => 'LF')); + $a = tidy_parse_string("<HTML><BODY BGCOLOR=#FFFFFF ALINK=#000000><B>Hi</B><I>Bye<U>Test</U></I></BODY></HTML>", array('newline' => 'LF')); $html = $a->html(); dump_nodes($html); diff --git a/ext/tidy/tests/014.phpt b/ext/tidy/tests/014.phpt index fd0d55b1fb..70f85eae37 100644 --- a/ext/tidy/tests/014.phpt +++ b/ext/tidy/tests/014.phpt @@ -5,9 +5,9 @@ Passing configuration options through tidy_parse_string(). --FILE-- <?php $text = "<B>testing</I>"; - $tidy = tidy_parse_string($text, array('show-body-only'=>true)); - tidy_clean_repair($tidy); - echo tidy_get_output($tidy); + $tidy = tidy_parse_string($text, array('show-body-only'=>true)); + tidy_clean_repair($tidy); + echo tidy_get_output($tidy); ?> --EXPECT-- diff --git a/ext/tidy/tests/015.phpt b/ext/tidy/tests/015.phpt index c5bc1dc4d3..ca00b5cb4d 100644 --- a/ext/tidy/tests/015.phpt +++ b/ext/tidy/tests/015.phpt @@ -5,8 +5,8 @@ Passing configuration options through tidy_parse_file(). --FILE-- <?php $tidy = tidy_parse_file(__DIR__."/015.html", array('show-body-only'=>true)); - tidy_clean_repair($tidy); - echo tidy_get_output($tidy); + tidy_clean_repair($tidy); + echo tidy_get_output($tidy); ?> --EXPECT-- diff --git a/ext/tidy/tests/018.phpt b/ext/tidy/tests/018.phpt index d2f1d1e0f3..761257e720 100644 --- a/ext/tidy/tests/018.phpt +++ b/ext/tidy/tests/018.phpt @@ -5,10 +5,10 @@ binary safety --FILE-- <?php $x = tidy_repair_string("<p>abra\0cadabra</p>", - array( 'show-body-only' => true, - 'clean' => false, - 'newline' => "\n") - ); + array( 'show-body-only' => true, + 'clean' => false, + 'newline' => "\n") + ); var_dump($x); ?> --EXPECT-- diff --git a/ext/tidy/tests/019.phpt b/ext/tidy/tests/019.phpt index 188b8cd4e9..2df1c96709 100644 --- a/ext/tidy/tests/019.phpt +++ b/ext/tidy/tests/019.phpt @@ -7,36 +7,36 @@ tidy_repair_*() and invalid parameters $l = 1; $s = ""; -$a = array(); -tidy_repair_string($s, $l, $l, $l); -tidy_repair_string($s, $s, $s, $s); -tidy_repair_string($l, $l, $l ,$l); -tidy_repair_string($a, $a, $a, $a); +tidy_repair_string($s, $l, $l); +tidy_repair_string($s, $s, $s); +tidy_repair_string($l, $l, $l); -tidy_repair_file($s, $l, $l, $l); -tidy_repair_file($s, $s, $s, $s); -tidy_repair_file($l, $l, $l ,$l); -tidy_repair_file($a, $a, $a, $a); +try { + tidy_repair_file($s, $l, $l, $l); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} +try { + tidy_repair_file($s, $s, $s, $s); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} + +tidy_repair_file($l, $l, $l ,$l); // This doesn't emit any warning, TODO look into echo "Done\n"; ?> --EXPECTF-- -Warning: tidy_repair_string(): Could not load configuration file '1' in %s on line %d - -Warning: tidy_repair_string(): Could not set encoding '1' in %s on line %d - -Warning: tidy_repair_string(): Could not load configuration file '' in %s on line %d - -Warning: tidy_repair_string(): Could not load configuration file '1' in %s on line %d - -Warning: tidy_repair_string(): Could not set encoding '1' in %s on line %d +Warning: tidy_repair_string(): Could not load configuration file "1" in %s on line %d -Warning: tidy_repair_string() expects parameter 1 to be string, array given in %s on line %d +Warning: tidy_repair_string(): Could not set encoding "1" in %s on line %d -Warning: tidy_repair_file(): Filename cannot be empty in %s on line %d +Warning: tidy_repair_string(): Could not load configuration file "" in %s on line %d -Warning: tidy_repair_file(): Filename cannot be empty in %s on line %d +Warning: tidy_repair_string(): Could not load configuration file "1" in %s on line %d -Warning: tidy_repair_file() expects parameter 1 to be a valid path, array given in %s on line %d +Warning: tidy_repair_string(): Could not set encoding "1" in %s on line %d +Path cannot be empty +Path cannot be empty Done diff --git a/ext/tidy/tests/021.phpt b/ext/tidy/tests/021.phpt index bdf954617b..2c946b87c6 100644 --- a/ext/tidy/tests/021.phpt +++ b/ext/tidy/tests/021.phpt @@ -5,14 +5,17 @@ tidy_get_opt_doc() --FILE-- <?php -var_dump(tidy_get_opt_doc(new tidy, 'some_bogus_cfg')); +try { + tidy_get_opt_doc(new tidy, 'some_bogus_cfg'); +} catch (ValueError $exception) { + echo $exception->getMessage() . "\n"; +} $t = new tidy; var_dump($t->getOptDoc('ncr')); var_dump(strlen(tidy_get_opt_doc($t, 'wrap')) > 99); ?> ---EXPECTF-- -Warning: tidy_get_opt_doc(): Unknown Tidy Configuration Option 'some_bogus_cfg' in %s021.php on line 3 -bool(false) +--EXPECT-- +tidy_get_opt_doc(): Argument #2 ($option) is an invalid configuration option, "some_bogus_cfg" given string(73) "This option specifies if Tidy should allow numeric character references. " bool(true) diff --git a/ext/tidy/tests/029.phpt b/ext/tidy/tests/029.phpt index e46181f005..f28f52fba8 100644 --- a/ext/tidy/tests/029.phpt +++ b/ext/tidy/tests/029.phpt @@ -8,16 +8,16 @@ tidy_get_body() crash // bug report taken from http://news.php.net/php.notes/130628 $inputs = array( - '<frameset > </frameset>', - '<html><frameset> </frameset> </html', + '<frameset > </frameset>', + '<html><frameset> </frameset> </html', ); foreach ($inputs as $input) { - $t = tidy_parse_string($input); - $t->cleanRepair(); - var_dump(tidy_get_body($t)); + $t = tidy_parse_string($input); + $t->cleanRepair(); + var_dump(tidy_get_body($t)); } echo "Done\n"; diff --git a/ext/tidy/tests/035.phpt b/ext/tidy/tests/035.phpt index 1fe0d5c9f1..720e095f75 100644 --- a/ext/tidy/tests/035.phpt +++ b/ext/tidy/tests/035.phpt @@ -9,7 +9,7 @@ tidyNode::__construct() new tidyNode; ?> --EXPECTF-- -Fatal error: Uncaught Error: Call to private tidyNode::__construct() from invalid context in %s:%d +Fatal error: Uncaught Error: Call to private tidyNode::__construct() from global scope in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/ext/tidy/tests/bug54682.phpt b/ext/tidy/tests/bug54682.phpt index 2bebe11bdb..174bbb37c4 100644 --- a/ext/tidy/tests/bug54682.phpt +++ b/ext/tidy/tests/bug54682.phpt @@ -10,4 +10,4 @@ $nx->diagnose(); ?> --EXPECTF-- -Warning: tidy::__construct(): Cannot Load '*' into memory%win %s on line %d +Warning: tidy::__construct(): Cannot load "*" into memory%win %s on line %d diff --git a/ext/tidy/tests/tidy_error1.phpt b/ext/tidy/tests/tidy_error1.phpt index a92446925f..a25501352d 100644 --- a/ext/tidy/tests/tidy_error1.phpt +++ b/ext/tidy/tests/tidy_error1.phpt @@ -13,7 +13,8 @@ $config = array('bogus' => 'willnotwork'); $tidy = new tidy(); var_dump($tidy->parseString($buffer, $config)); + ?> --EXPECTF-- -Notice: tidy::parseString(): Unknown Tidy Configuration Option 'bogus' in %s on line %d +Warning: tidy::parseString(): Unknown Tidy configuration option "bogus" in %s on line %d bool(true) diff --git a/ext/tidy/tidy.c b/ext/tidy/tidy.c index 266e6510ef..856a8a2f23 100644 --- a/ext/tidy/tidy.c +++ b/ext/tidy/tidy.c @@ -1,7 +1,5 @@ /* +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ | Copyright (c) The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | @@ -23,30 +21,31 @@ #include "php.h" #include "php_tidy.h" -#if HAVE_TIDY +#ifdef HAVE_TIDY #include "php_ini.h" #include "ext/standard/info.h" -#if HAVE_TIDY_H +#ifdef HAVE_TIDY_H #include "tidy.h" -#elif HAVE_TIDYP_H +#elif defined(HAVE_TIDYP_H) #include "tidyp.h" #endif -#if HAVE_TIDYBUFFIO_H +#ifdef HAVE_TIDYBUFFIO_H #include "tidybuffio.h" #else #include "buffio.h" #endif +#include "tidy_arginfo.h" + /* compatibility with older versions of libtidy */ #ifndef TIDY_CALL #define TIDY_CALL #endif -/* {{{ ext/tidy macros -*/ +/* {{{ ext/tidy macros */ #define FIX_BUFFER(bptr) do { if ((bptr)->size) { (bptr)->bp[(bptr)->size-1] = '\0'; } } while(0) #define TIDY_SET_CONTEXT \ @@ -54,15 +53,9 @@ #define TIDY_FETCH_OBJECT \ PHPTidyObj *obj; \ - TIDY_SET_CONTEXT; \ - if (object) { \ - if (zend_parse_parameters_none() == FAILURE) { \ - return; \ - } \ - } else { \ - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), NULL, "O", &object, tidy_ce_doc) == FAILURE) { \ - RETURN_FALSE; \ - } \ + zval *object; \ + if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O", &object, tidy_ce_doc) == FAILURE) { \ + RETURN_THROWS(); \ } \ obj = Z_TIDY_P(object); \ @@ -77,32 +70,29 @@ PHPTidyObj *obj; \ TIDY_SET_CONTEXT; \ if (zend_parse_parameters_none() == FAILURE) { \ - return; \ + RETURN_THROWS(); \ } \ obj = Z_TIDY_P(object); \ -#define TIDY_APPLY_CONFIG_ZVAL(_doc, _val) \ - if(_val) { \ - if(Z_TYPE_P(_val) == IS_ARRAY) { \ - _php_tidy_apply_config_array(_doc, Z_ARRVAL_P(_val)); \ - } else { \ - convert_to_string_ex(_val); \ - TIDY_OPEN_BASE_DIR_CHECK(Z_STRVAL_P(_val)); \ - switch (tidyLoadConfig(_doc, Z_STRVAL_P(_val))) { \ - case -1: \ - php_error_docref(NULL, E_WARNING, "Could not load configuration file '%s'", Z_STRVAL_P(_val)); \ - break; \ - case 1: \ - php_error_docref(NULL, E_NOTICE, "There were errors while parsing the configuration file '%s'", Z_STRVAL_P(_val)); \ - break; \ - } \ - } \ - } +#define TIDY_APPLY_CONFIG(_doc, _val_str, _val_ht) \ + if (_val_ht) { \ + _php_tidy_apply_config_array(_doc, _val_ht); \ + } else if (_val_str) { \ + TIDY_OPEN_BASE_DIR_CHECK(ZSTR_VAL(_val_str)); \ + switch (tidyLoadConfig(_doc, ZSTR_VAL(_val_str))) { \ + case -1: \ + php_error_docref(NULL, E_WARNING, "Could not load configuration file \"%s\"", ZSTR_VAL(_val_str)); \ + break; \ + case 1: \ + php_error_docref(NULL, E_NOTICE, "There were errors while parsing the configuration file \"%s\"", ZSTR_VAL(_val_str)); \ + break; \ + } \ + } #define REGISTER_TIDY_CLASS(classname, name, parent, __flags) \ { \ zend_class_entry ce; \ - INIT_CLASS_ENTRY(ce, # classname, tidy_funcs_ ## name); \ + INIT_CLASS_ENTRY(ce, # classname, class_ ## classname ## _methods); \ ce.create_object = tidy_object_new_ ## name; \ tidy_ce_ ## name = zend_register_internal_class_ex(&ce, parent); \ tidy_ce_ ## name->ce_flags |= __flags; \ @@ -172,13 +162,12 @@ if (php_check_open_basedir(filename)) { \ #define TIDY_SET_DEFAULT_CONFIG(_doc) \ if (TG(default_config) && TG(default_config)[0]) { \ if (tidyLoadConfig(_doc, TG(default_config)) < 0) { \ - php_error_docref(NULL, E_WARNING, "Unable to load Tidy configuration file at '%s'.", TG(default_config)); \ + php_error_docref(NULL, E_WARNING, "Unable to load Tidy configuration file at \"%s\"", TG(default_config)); \ } \ } /* }}} */ -/* {{{ ext/tidy structs -*/ +/* {{{ ext/tidy structs */ typedef struct _PHPTidyDoc PHPTidyDoc; typedef struct _PHPTidyObj PHPTidyObj; @@ -215,15 +204,14 @@ static inline PHPTidyObj *php_tidy_fetch_object(zend_object *obj) { #define Z_TIDY_P(zv) php_tidy_fetch_object(Z_OBJ_P((zv))) /* }}} */ -/* {{{ ext/tidy prototypes -*/ +/* {{{ ext/tidy prototypes */ static zend_string *php_tidy_file_to_mem(char *, zend_bool); static void tidy_object_free_storage(zend_object *); static zend_object *tidy_object_new_node(zend_class_entry *); static zend_object *tidy_object_new_doc(zend_class_entry *); static zval * tidy_instanciate(zend_class_entry *, zval *); -static int tidy_doc_cast_handler(zval *, zval *, int); -static int tidy_node_cast_handler(zval *, zval *, int); +static int tidy_doc_cast_handler(zend_object *, zval *, int); +static int tidy_node_cast_handler(zend_object *, zval *, int); static void tidy_doc_update_properties(PHPTidyObj *); static void tidy_add_default_properties(PHPTidyObj *, tidy_obj_type); static void *php_tidy_get_opt_val(PHPTidyDoc *, TidyOption, TidyOptionType *); @@ -243,50 +231,6 @@ static PHP_RINIT_FUNCTION(tidy); static PHP_RSHUTDOWN_FUNCTION(tidy); static PHP_MINFO_FUNCTION(tidy); -static PHP_FUNCTION(tidy_getopt); -static PHP_FUNCTION(tidy_parse_string); -static PHP_FUNCTION(tidy_parse_file); -static PHP_FUNCTION(tidy_clean_repair); -static PHP_FUNCTION(tidy_repair_string); -static PHP_FUNCTION(tidy_repair_file); -static PHP_FUNCTION(tidy_diagnose); -static PHP_FUNCTION(tidy_get_output); -static PHP_FUNCTION(tidy_get_error_buffer); -static PHP_FUNCTION(tidy_get_release); -static PHP_FUNCTION(tidy_get_config); -static PHP_FUNCTION(tidy_get_status); -static PHP_FUNCTION(tidy_get_html_ver); -#if HAVE_TIDYOPTGETDOC -static PHP_FUNCTION(tidy_get_opt_doc); -#endif -static PHP_FUNCTION(tidy_is_xhtml); -static PHP_FUNCTION(tidy_is_xml); -static PHP_FUNCTION(tidy_error_count); -static PHP_FUNCTION(tidy_warning_count); -static PHP_FUNCTION(tidy_access_count); -static PHP_FUNCTION(tidy_config_count); - -static PHP_FUNCTION(tidy_get_root); -static PHP_FUNCTION(tidy_get_html); -static PHP_FUNCTION(tidy_get_head); -static PHP_FUNCTION(tidy_get_body); - -static TIDY_DOC_METHOD(__construct); -static TIDY_DOC_METHOD(parseFile); -static TIDY_DOC_METHOD(parseString); - -static TIDY_NODE_METHOD(hasChildren); -static TIDY_NODE_METHOD(hasSiblings); -static TIDY_NODE_METHOD(isComment); -static TIDY_NODE_METHOD(isHtml); -static TIDY_NODE_METHOD(isText); -static TIDY_NODE_METHOD(isJste); -static TIDY_NODE_METHOD(isAsp); -static TIDY_NODE_METHOD(isPhp); -static TIDY_NODE_METHOD(getParent); -static TIDY_NODE_METHOD(__construct); -/* }}} */ - ZEND_DECLARE_MODULE_GLOBALS(tidy) PHP_INI_BEGIN() @@ -294,201 +238,6 @@ STD_PHP_INI_ENTRY("tidy.default_config", "", PHP_INI_SYSTEM, OnUpdateString, STD_PHP_INI_ENTRY("tidy.clean_output", "0", PHP_INI_USER, php_tidy_set_clean_output, clean_output, zend_tidy_globals, tidy_globals) PHP_INI_END() -/* {{{ arginfo */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_parse_string, 0, 0, 1) - ZEND_ARG_INFO(0, input) - ZEND_ARG_INFO(0, config_options) - ZEND_ARG_INFO(0, encoding) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_error_buffer, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_output, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_parse_file, 0, 0, 1) - ZEND_ARG_INFO(0, file) - ZEND_ARG_INFO(0, config_options) - ZEND_ARG_INFO(0, encoding) - ZEND_ARG_INFO(0, use_include_path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_clean_repair, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_repair_string, 0, 0, 1) - ZEND_ARG_INFO(0, data) - ZEND_ARG_INFO(0, config_file) - ZEND_ARG_INFO(0, encoding) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_repair_file, 0, 0, 1) - ZEND_ARG_INFO(0, filename) - ZEND_ARG_INFO(0, config_file) - ZEND_ARG_INFO(0, encoding) - ZEND_ARG_INFO(0, use_include_path) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_diagnose, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO(arginfo_tidy_get_release, 0) -ZEND_END_ARG_INFO() - -#if HAVE_TIDYOPTGETDOC -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_opt_doc, 0, 0, 2) - ZEND_ARG_INFO(0, resource) - ZEND_ARG_INFO(0, optname) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_opt_doc_method, 0, 0, 1) - ZEND_ARG_INFO(0, optname) -ZEND_END_ARG_INFO() -#endif - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_config, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_status, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_html_ver, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_is_xhtml, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_is_xml, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_error_count, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_warning_count, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_access_count, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_config_count, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_getopt_method, 0, 0, 1) - ZEND_ARG_INFO(0, option) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_getopt, 0, 0, 2) - ZEND_ARG_INFO(0, object) - ZEND_ARG_INFO(0, option) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_root, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_html, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_head, 0, 0, 1) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_body, 0, 0, 1) - ZEND_ARG_INFO(0, tidy) -ZEND_END_ARG_INFO() - -ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_construct, 0, 0, 0) - ZEND_ARG_INFO(0, filename) - ZEND_ARG_INFO(0, config_file) - ZEND_ARG_INFO(0, encoding) - ZEND_ARG_INFO(0, use_include_path) -ZEND_END_ARG_INFO() -/* }}} */ - -static const zend_function_entry tidy_functions[] = { - PHP_FE(tidy_getopt, arginfo_tidy_getopt) - PHP_FE(tidy_parse_string, arginfo_tidy_parse_string) - PHP_FE(tidy_parse_file, arginfo_tidy_parse_file) - PHP_FE(tidy_get_output, arginfo_tidy_get_output) - PHP_FE(tidy_get_error_buffer, arginfo_tidy_get_error_buffer) - PHP_FE(tidy_clean_repair, arginfo_tidy_clean_repair) - PHP_FE(tidy_repair_string, arginfo_tidy_repair_string) - PHP_FE(tidy_repair_file, arginfo_tidy_repair_file) - PHP_FE(tidy_diagnose, arginfo_tidy_diagnose) - PHP_FE(tidy_get_release, arginfo_tidy_get_release) - PHP_FE(tidy_get_config, arginfo_tidy_get_config) - PHP_FE(tidy_get_status, arginfo_tidy_get_status) - PHP_FE(tidy_get_html_ver, arginfo_tidy_get_html_ver) - PHP_FE(tidy_is_xhtml, arginfo_tidy_is_xhtml) - PHP_FE(tidy_is_xml, arginfo_tidy_is_xml) - PHP_FE(tidy_error_count, arginfo_tidy_error_count) - PHP_FE(tidy_warning_count, arginfo_tidy_warning_count) - PHP_FE(tidy_access_count, arginfo_tidy_access_count) - PHP_FE(tidy_config_count, arginfo_tidy_config_count) -#if HAVE_TIDYOPTGETDOC - PHP_FE(tidy_get_opt_doc, arginfo_tidy_get_opt_doc) -#endif - PHP_FE(tidy_get_root, arginfo_tidy_get_root) - PHP_FE(tidy_get_head, arginfo_tidy_get_head) - PHP_FE(tidy_get_html, arginfo_tidy_get_html) - PHP_FE(tidy_get_body, arginfo_tidy_get_body) - PHP_FE_END -}; - -static const zend_function_entry tidy_funcs_doc[] = { - TIDY_METHOD_MAP(getOpt, tidy_getopt, arginfo_tidy_getopt_method) - TIDY_METHOD_MAP(cleanRepair, tidy_clean_repair, NULL) - TIDY_DOC_ME(parseFile, arginfo_tidy_parse_file) - TIDY_DOC_ME(parseString, arginfo_tidy_parse_string) - TIDY_METHOD_MAP(repairString, tidy_repair_string, arginfo_tidy_repair_string) - TIDY_METHOD_MAP(repairFile, tidy_repair_file, arginfo_tidy_repair_file) - TIDY_METHOD_MAP(diagnose, tidy_diagnose, NULL) - TIDY_METHOD_MAP(getRelease, tidy_get_release, NULL) - TIDY_METHOD_MAP(getConfig, tidy_get_config, NULL) - TIDY_METHOD_MAP(getStatus, tidy_get_status, NULL) - TIDY_METHOD_MAP(getHtmlVer, tidy_get_html_ver, NULL) -#if HAVE_TIDYOPTGETDOC - TIDY_METHOD_MAP(getOptDoc, tidy_get_opt_doc, arginfo_tidy_get_opt_doc_method) -#endif - TIDY_METHOD_MAP(isXhtml, tidy_is_xhtml, NULL) - TIDY_METHOD_MAP(isXml, tidy_is_xml, NULL) - TIDY_METHOD_MAP(root, tidy_get_root, NULL) - TIDY_METHOD_MAP(head, tidy_get_head, NULL) - TIDY_METHOD_MAP(html, tidy_get_html, NULL) - TIDY_METHOD_MAP(body, tidy_get_body, NULL) - TIDY_DOC_ME(__construct, arginfo_tidy_construct) - PHP_FE_END -}; - -static const zend_function_entry tidy_funcs_node[] = { - TIDY_NODE_ME(hasChildren, NULL) - TIDY_NODE_ME(hasSiblings, NULL) - TIDY_NODE_ME(isComment, NULL) - TIDY_NODE_ME(isHtml, NULL) - TIDY_NODE_ME(isText, NULL) - TIDY_NODE_ME(isJste, NULL) - TIDY_NODE_ME(isAsp, NULL) - TIDY_NODE_ME(isPhp, NULL) - TIDY_NODE_ME(getParent, NULL) - TIDY_NODE_PRIVATE_ME(__construct, NULL) - PHP_FE_END -}; - static zend_class_entry *tidy_ce_doc, *tidy_ce_node; static zend_object_handlers tidy_object_handlers_doc; @@ -497,7 +246,7 @@ static zend_object_handlers tidy_object_handlers_node; zend_module_entry tidy_module_entry = { STANDARD_MODULE_HEADER, "tidy", - tidy_functions, + ext_functions, PHP_MINIT(tidy), PHP_MSHUTDOWN(tidy), PHP_RINIT(tidy), @@ -545,12 +294,12 @@ static int _php_tidy_set_tidy_opt(TidyDoc doc, char *optname, zval *value) zend_long lval; if (!opt) { - php_error_docref(NULL, E_NOTICE, "Unknown Tidy Configuration Option '%s'", optname); + php_error_docref(NULL, E_WARNING, "Unknown Tidy configuration option \"%s\"", optname); return FAILURE; } if (tidyOptIsReadOnly(opt)) { - php_error_docref(NULL, E_NOTICE, "Attempting to set read-only option '%s'", optname); + php_error_docref(NULL, E_WARNING, "Attempting to set read-only option \"%s\"", optname); return FAILURE; } @@ -590,29 +339,39 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_fil { char *enc = NULL; size_t enc_len = 0; - zend_bool use_include_path = 0; TidyDoc doc; TidyBuffer *errbuf; - zend_string *data, *arg1; - zval *config = NULL; + zend_string *data, *arg1, *config_str = NULL; + HashTable *config_ht = NULL; if (is_file) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|zsb", &arg1, &config, &enc, &enc_len, &use_include_path) == FAILURE) { - RETURN_FALSE; - } + zend_bool use_include_path = 0; + + ZEND_PARSE_PARAMETERS_START(1, 4) + Z_PARAM_PATH_STR(arg1) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(config_ht, config_str) + Z_PARAM_STRING(enc, enc_len) + Z_PARAM_BOOL(use_include_path) + ZEND_PARSE_PARAMETERS_END(); + if (!(data = php_tidy_file_to_mem(ZSTR_VAL(arg1), use_include_path))) { RETURN_FALSE; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|zsb", &arg1, &config, &enc, &enc_len, &use_include_path) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_STR(arg1) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(config_ht, config_str) + Z_PARAM_STRING(enc, enc_len) + ZEND_PARSE_PARAMETERS_END(); + data = arg1; } if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(data))) { - php_error_docref(NULL, E_WARNING, "Input string is too long"); - RETURN_FALSE; + zend_argument_value_error(1, "is too long"); + RETURN_THROWS(); } doc = tidyCreate(); @@ -631,13 +390,11 @@ static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_fil TIDY_SET_DEFAULT_CONFIG(doc); - if (config) { - TIDY_APPLY_CONFIG_ZVAL(doc, config); - } + TIDY_APPLY_CONFIG(doc, config_str, config_ht); if(enc_len) { if (tidySetCharEncoding(doc, enc) < 0) { - php_error_docref(NULL, E_WARNING, "Could not set encoding '%s'", enc); + php_error_docref(NULL, E_WARNING, "Could not set encoding \"%s\"", enc); RETVAL_FALSE; } } @@ -768,7 +525,7 @@ static zval * tidy_instanciate(zend_class_entry *pce, zval *object) return object; } -static int tidy_doc_cast_handler(zval *in, zval *out, int type) +static int tidy_doc_cast_handler(zend_object *in, zval *out, int type) { TidyBuffer output; PHPTidyObj *obj; @@ -788,7 +545,7 @@ static int tidy_doc_cast_handler(zval *in, zval *out, int type) break; case IS_STRING: - obj = Z_TIDY_P(in); + obj = php_tidy_fetch_object(in); tidyBufInit(&output); tidySaveBuffer (obj->ptdoc->doc, &output); if (output.size) { @@ -806,7 +563,7 @@ static int tidy_doc_cast_handler(zval *in, zval *out, int type) return SUCCESS; } -static int tidy_node_cast_handler(zval *in, zval *out, int type) +static int tidy_node_cast_handler(zend_object *in, zval *out, int type) { TidyBuffer buf; PHPTidyObj *obj; @@ -826,7 +583,7 @@ static int tidy_node_cast_handler(zval *in, zval *out, int type) break; case IS_STRING: - obj = Z_TIDY_P(in); + obj = php_tidy_fetch_object(in); tidyBufInit(&buf); if (obj->ptdoc) { tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf); @@ -1053,7 +810,7 @@ static int php_tidy_parse_string(PHPTidyObj *obj, char *string, uint32_t len, ch if(enc) { if (tidySetCharEncoding(obj->ptdoc->doc, enc) < 0) { - php_error_docref(NULL, E_WARNING, "Could not set encoding '%s'", enc); + php_error_docref(NULL, E_WARNING, "Could not set encoding \"%s\"", enc); return FAILURE; } } @@ -1124,12 +881,12 @@ static PHP_MINFO_FUNCTION(tidy) { php_info_print_table_start(); php_info_print_table_row(2, "Tidy support", "enabled"); -#if HAVE_TIDYBUFFIO_H +#ifdef HAVE_TIDYBUFFIO_H php_info_print_table_row(2, "libTidy Version", (char *)tidyLibraryVersion()); -#elif HAVE_TIDYP_H +#elif defined(HAVE_TIDYP_H) php_info_print_table_row(2, "libtidyp Version", (char *)tidyVersion()); #endif -#if HAVE_TIDYRELEASEDATE +#ifdef HAVE_TIDYRELEASEDATE php_info_print_table_row(2, "libTidy Release", (char *)tidyReleaseDate()); #endif php_info_print_table_end(); @@ -1243,29 +1000,31 @@ static int php_tidy_output_handler(void **nothing, php_output_context *output_co return status; } -/* {{{ proto bool tidy_parse_string(string input [, mixed config_options [, string encoding]]) - Parse a document stored in a string */ -static PHP_FUNCTION(tidy_parse_string) +/* {{{ Parse a document stored in a string */ +PHP_FUNCTION(tidy_parse_string) { char *enc = NULL; size_t enc_len = 0; - zend_string *input; - zval *options = NULL; + zend_string *input, *options_str = NULL; + HashTable *options_ht = NULL; PHPTidyObj *obj; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|zs", &input, &options, &enc, &enc_len) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_STR(input) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(options_ht, options_str) + Z_PARAM_STRING_OR_NULL(enc, enc_len) + ZEND_PARSE_PARAMETERS_END(); if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(input))) { - php_error_docref(NULL, E_WARNING, "Input string is too long"); - RETURN_FALSE; + zend_argument_value_error(1, "is too long"); + RETURN_THROWS(); } tidy_instanciate(tidy_ce_doc, return_value); obj = Z_TIDY_P(return_value); - TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options); + TIDY_APPLY_CONFIG(obj->ptdoc->doc, options_str, options_ht); if (php_tidy_parse_string(obj, ZSTR_VAL(input), (uint32_t)ZSTR_LEN(input), enc) == FAILURE) { zval_ptr_dtor(return_value); @@ -1274,9 +1033,8 @@ static PHP_FUNCTION(tidy_parse_string) } /* }}} */ -/* {{{ proto string tidy_get_error_buffer() - Return warnings and errors which occurred parsing the specified document*/ -static PHP_FUNCTION(tidy_get_error_buffer) +/* {{{ Return warnings and errors which occurred parsing the specified document*/ +PHP_FUNCTION(tidy_get_error_buffer) { TIDY_FETCH_OBJECT; @@ -1288,9 +1046,8 @@ static PHP_FUNCTION(tidy_get_error_buffer) } /* }}} */ -/* {{{ proto string tidy_get_output(tidy tidy) - Return a string representing the parsed tidy markup */ -static PHP_FUNCTION(tidy_get_output) +/* {{{ Return a string representing the parsed tidy markup */ +PHP_FUNCTION(tidy_get_output) { TidyBuffer output; TIDY_FETCH_OBJECT; @@ -1303,37 +1060,39 @@ static PHP_FUNCTION(tidy_get_output) } /* }}} */ -/* {{{ proto bool tidy_parse_file(string file [, mixed config_options [, string encoding [, bool use_include_path]]]) - Parse markup in file or URI */ -static PHP_FUNCTION(tidy_parse_file) +/* {{{ Parse markup in file or URI */ +PHP_FUNCTION(tidy_parse_file) { char *enc = NULL; size_t enc_len = 0; zend_bool use_include_path = 0; - zend_string *inputfile, *contents; - zval *options = NULL; + zend_string *inputfile, *contents, *options_str = NULL; + HashTable *options_ht = NULL; PHPTidyObj *obj; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|zsb", &inputfile, - &options, &enc, &enc_len, &use_include_path) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 4) + Z_PARAM_PATH_STR(inputfile) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(options_ht, options_str) + Z_PARAM_STRING_OR_NULL(enc, enc_len) + Z_PARAM_BOOL(use_include_path) + ZEND_PARSE_PARAMETERS_END(); tidy_instanciate(tidy_ce_doc, return_value); obj = Z_TIDY_P(return_value); if (!(contents = php_tidy_file_to_mem(ZSTR_VAL(inputfile), use_include_path))) { - php_error_docref(NULL, E_WARNING, "Cannot Load '%s' into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (Using include path)" : ""); + php_error_docref(NULL, E_WARNING, "Cannot load \"%s\" into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (using include path)" : ""); RETURN_FALSE; } if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) { - php_error_docref(NULL, E_WARNING, "Input string is too long"); - RETURN_FALSE; + zend_value_error("Input string is too long"); + RETURN_THROWS(); } - TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options); + TIDY_APPLY_CONFIG(obj->ptdoc->doc, options_str, options_ht); if (php_tidy_parse_string(obj, ZSTR_VAL(contents), (uint32_t)ZSTR_LEN(contents), enc) == FAILURE) { zval_ptr_dtor(return_value); @@ -1344,9 +1103,8 @@ static PHP_FUNCTION(tidy_parse_file) } /* }}} */ -/* {{{ proto bool tidy_clean_repair(tidy tidy) - Execute configured cleanup and repair operations on parsed markup */ -static PHP_FUNCTION(tidy_clean_repair) +/* {{{ Execute configured cleanup and repair operations on parsed markup */ +PHP_FUNCTION(tidy_clean_repair) { TIDY_FETCH_OBJECT; @@ -1359,25 +1117,22 @@ static PHP_FUNCTION(tidy_clean_repair) } /* }}} */ -/* {{{ proto bool tidy_repair_string(string data [, mixed config_file [, string encoding]]) - Repair a string using an optionally provided configuration file */ -static PHP_FUNCTION(tidy_repair_string) +/* {{{ Repair a string using an optionally provided configuration file */ +PHP_FUNCTION(tidy_repair_string) { php_tidy_quick_repair(INTERNAL_FUNCTION_PARAM_PASSTHRU, FALSE); } /* }}} */ -/* {{{ proto bool tidy_repair_file(string filename [, mixed config_file [, string encoding [, bool use_include_path]]]) - Repair a file using an optionally provided configuration file */ -static PHP_FUNCTION(tidy_repair_file) +/* {{{ Repair a file using an optionally provided configuration file */ +PHP_FUNCTION(tidy_repair_file) { php_tidy_quick_repair(INTERNAL_FUNCTION_PARAM_PASSTHRU, TRUE); } /* }}} */ -/* {{{ proto bool tidy_diagnose() - Run configured diagnostics on parsed and repaired markup. */ -static PHP_FUNCTION(tidy_diagnose) +/* {{{ Run configured diagnostics on parsed and repaired markup. */ +PHP_FUNCTION(tidy_diagnose) { TIDY_FETCH_OBJECT; @@ -1390,15 +1145,14 @@ static PHP_FUNCTION(tidy_diagnose) } /* }}} */ -/* {{{ proto string tidy_get_release() - Get release date (version) for Tidy library */ -static PHP_FUNCTION(tidy_get_release) +/* {{{ Get release date (version) for Tidy library */ +PHP_FUNCTION(tidy_get_release) { if (zend_parse_parameters_none() == FAILURE) { - return; + RETURN_THROWS(); } -#if HAVE_TIDYRELEASEDATE +#ifdef HAVE_TIDYRELEASEDATE RETURN_STRING((char *)tidyReleaseDate()); #else RETURN_STRING((char *)"unknown"); @@ -1407,26 +1161,18 @@ static PHP_FUNCTION(tidy_get_release) /* }}} */ -#if HAVE_TIDYOPTGETDOC -/* {{{ proto string tidy_get_opt_doc(tidy resource, string optname) - Returns the documentation for the given option name */ -static PHP_FUNCTION(tidy_get_opt_doc) +#ifdef HAVE_TIDYOPTGETDOC +/* {{{ Returns the documentation for the given option name */ +PHP_FUNCTION(tidy_get_opt_doc) { PHPTidyObj *obj; char *optval, *optname; size_t optname_len; TidyOption opt; + zval *object; - TIDY_SET_CONTEXT; - - if (object) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &optname, &optname_len) == FAILURE) { - RETURN_FALSE; - } - } else { - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), NULL, "Os", &object, tidy_ce_doc, &optname, &optname_len) == FAILURE) { - RETURN_FALSE; - } + if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &object, tidy_ce_doc, &optname, &optname_len) == FAILURE) { + RETURN_THROWS(); } obj = Z_TIDY_P(object); @@ -1434,8 +1180,8 @@ static PHP_FUNCTION(tidy_get_opt_doc) opt = tidyGetOptionByName(obj->ptdoc->doc, optname); if (!opt) { - php_error_docref(NULL, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname); - RETURN_FALSE; + zend_argument_value_error(getThis() ? 1 : 2, "is an invalid configuration option, \"%s\" given", optname); + RETURN_THROWS(); } if ( (optval = (char *) tidyOptGetDoc(obj->ptdoc->doc, opt)) ) { @@ -1448,9 +1194,8 @@ static PHP_FUNCTION(tidy_get_opt_doc) #endif -/* {{{ proto array tidy_get_config(tidy tidy) - Get current Tidy configuration */ -static PHP_FUNCTION(tidy_get_config) +/* {{{ Get current Tidy configuration */ +PHP_FUNCTION(tidy_get_config) { TidyIterator itOpt; char *opt_name; @@ -1487,9 +1232,8 @@ static PHP_FUNCTION(tidy_get_config) } /* }}} */ -/* {{{ proto int tidy_get_status(tidy tidy) - Get status of specified document. */ -static PHP_FUNCTION(tidy_get_status) +/* {{{ Get status of specified document. */ +PHP_FUNCTION(tidy_get_status) { TIDY_FETCH_OBJECT; @@ -1497,9 +1241,8 @@ static PHP_FUNCTION(tidy_get_status) } /* }}} */ -/* {{{ proto int tidy_get_html_ver(tidy tidy) - Get the Detected HTML version for the specified document. */ -static PHP_FUNCTION(tidy_get_html_ver) +/* {{{ Get the Detected HTML version for the specified document. */ +PHP_FUNCTION(tidy_get_html_ver) { TIDY_FETCH_INITIALIZED_OBJECT; @@ -1507,9 +1250,8 @@ static PHP_FUNCTION(tidy_get_html_ver) } /* }}} */ -/* {{{ proto bool tidy_is_xhtml(tidy tidy) - Indicates if the document is a XHTML document. */ -static PHP_FUNCTION(tidy_is_xhtml) +/* {{{ Indicates if the document is a XHTML document. */ +PHP_FUNCTION(tidy_is_xhtml) { TIDY_FETCH_INITIALIZED_OBJECT; @@ -1517,9 +1259,8 @@ static PHP_FUNCTION(tidy_is_xhtml) } /* }}} */ -/* {{{ proto bool tidy_is_xml(tidy tidy) - Indicates if the document is a generic (non HTML/XHTML) XML document. */ -static PHP_FUNCTION(tidy_is_xml) +/* {{{ Indicates if the document is a generic (non HTML/XHTML) XML document. */ +PHP_FUNCTION(tidy_is_xml) { TIDY_FETCH_INITIALIZED_OBJECT; @@ -1527,9 +1268,8 @@ static PHP_FUNCTION(tidy_is_xml) } /* }}} */ -/* {{{ proto int tidy_error_count(tidy tidy) - Returns the Number of Tidy errors encountered for specified document. */ -static PHP_FUNCTION(tidy_error_count) +/* {{{ Returns the Number of Tidy errors encountered for specified document. */ +PHP_FUNCTION(tidy_error_count) { TIDY_FETCH_OBJECT; @@ -1537,9 +1277,8 @@ static PHP_FUNCTION(tidy_error_count) } /* }}} */ -/* {{{ proto int tidy_warning_count(tidy tidy) - Returns the Number of Tidy warnings encountered for specified document. */ -static PHP_FUNCTION(tidy_warning_count) +/* {{{ Returns the Number of Tidy warnings encountered for specified document. */ +PHP_FUNCTION(tidy_warning_count) { TIDY_FETCH_OBJECT; @@ -1547,9 +1286,8 @@ static PHP_FUNCTION(tidy_warning_count) } /* }}} */ -/* {{{ proto int tidy_access_count(tidy tidy) - Returns the Number of Tidy accessibility warnings encountered for specified document. */ -static PHP_FUNCTION(tidy_access_count) +/* {{{ Returns the Number of Tidy accessibility warnings encountered for specified document. */ +PHP_FUNCTION(tidy_access_count) { TIDY_FETCH_OBJECT; @@ -1557,9 +1295,8 @@ static PHP_FUNCTION(tidy_access_count) } /* }}} */ -/* {{{ proto int tidy_config_count(tidy tidy) - Returns the Number of Tidy configuration errors encountered for specified document. */ -static PHP_FUNCTION(tidy_config_count) +/* {{{ Returns the Number of Tidy configuration errors encountered for specified document. */ +PHP_FUNCTION(tidy_config_count) { TIDY_FETCH_OBJECT; @@ -1567,9 +1304,8 @@ static PHP_FUNCTION(tidy_config_count) } /* }}} */ -/* {{{ proto mixed tidy_getopt(string option) - Returns the value of the specified configuration option for the tidy document. */ -static PHP_FUNCTION(tidy_getopt) +/* {{{ Returns the value of the specified configuration option for the tidy document. */ +PHP_FUNCTION(tidy_getopt) { PHPTidyObj *obj; char *optname; @@ -1577,17 +1313,10 @@ static PHP_FUNCTION(tidy_getopt) size_t optname_len; TidyOption opt; TidyOptionType optt; + zval *object; - TIDY_SET_CONTEXT; - - if (object) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &optname, &optname_len) == FAILURE) { - RETURN_FALSE; - } - } else { - if (zend_parse_method_parameters(ZEND_NUM_ARGS(), NULL, "Os", &object, tidy_ce_doc, &optname, &optname_len) == FAILURE) { - RETURN_FALSE; - } + if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &object, tidy_ce_doc, &optname, &optname_len) == FAILURE) { + RETURN_THROWS(); } obj = Z_TIDY_P(object); @@ -1595,8 +1324,8 @@ static PHP_FUNCTION(tidy_getopt) opt = tidyGetOptionByName(obj->ptdoc->doc, optname); if (!opt) { - php_error_docref(NULL, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname); - RETURN_FALSE; + zend_argument_value_error(getThis() ? 1 : 2, "is an invalid configuration option, \"%s\" given", optname); + RETURN_THROWS(); } optval = php_tidy_get_opt_val(obj->ptdoc, opt, &optt); @@ -1626,36 +1355,38 @@ static PHP_FUNCTION(tidy_getopt) } /* }}} */ -static TIDY_DOC_METHOD(__construct) +PHP_METHOD(tidy, __construct) { char *enc = NULL; size_t enc_len = 0; zend_bool use_include_path = 0; - zval *options = NULL; - zend_string *contents, *inputfile = NULL; - + HashTable *options_ht = NULL; + zend_string *contents, *inputfile = NULL, *options_str = NULL; PHPTidyObj *obj; - TIDY_SET_CONTEXT; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|Pzsb", &inputfile, - &options, &enc, &enc_len, &use_include_path) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(0, 4) + Z_PARAM_OPTIONAL + Z_PARAM_PATH_STR_OR_NULL(inputfile) + Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(options_ht, options_str) + Z_PARAM_STRING_OR_NULL(enc, enc_len) + Z_PARAM_BOOL(use_include_path) + ZEND_PARSE_PARAMETERS_END(); + TIDY_SET_CONTEXT; obj = Z_TIDY_P(object); if (inputfile) { if (!(contents = php_tidy_file_to_mem(ZSTR_VAL(inputfile), use_include_path))) { - php_error_docref(NULL, E_WARNING, "Cannot Load '%s' into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (Using include path)" : ""); + php_error_docref(NULL, E_WARNING, "Cannot load \"%s\" into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (using include path)" : ""); return; } if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) { - php_error_docref(NULL, E_WARNING, "Input string is too long"); - RETURN_FALSE; + zend_value_error("Input string is too long"); + RETURN_THROWS(); } - TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options); + TIDY_APPLY_CONFIG(obj->ptdoc->doc, options_str, options_ht); php_tidy_parse_string(obj, ZSTR_VAL(contents), (uint32_t)ZSTR_LEN(contents), enc); @@ -1663,35 +1394,37 @@ static TIDY_DOC_METHOD(__construct) } } -static TIDY_DOC_METHOD(parseFile) +PHP_METHOD(tidy, parseFile) { char *enc = NULL; size_t enc_len = 0; zend_bool use_include_path = 0; - zval *options = NULL; - zend_string *inputfile, *contents; + HashTable *options_ht = NULL; + zend_string *inputfile, *contents, *options_str = NULL; PHPTidyObj *obj; - TIDY_SET_CONTEXT; + ZEND_PARSE_PARAMETERS_START(1, 4) + Z_PARAM_PATH_STR(inputfile) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(options_ht, options_str) + Z_PARAM_STRING_OR_NULL(enc, enc_len) + Z_PARAM_BOOL(use_include_path) + ZEND_PARSE_PARAMETERS_END(); + TIDY_SET_CONTEXT; obj = Z_TIDY_P(object); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|zsb", &inputfile, - &options, &enc, &enc_len, &use_include_path) == FAILURE) { - RETURN_FALSE; - } - if (!(contents = php_tidy_file_to_mem(ZSTR_VAL(inputfile), use_include_path))) { - php_error_docref(NULL, E_WARNING, "Cannot Load '%s' into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (Using include path)" : ""); + php_error_docref(NULL, E_WARNING, "Cannot load \"%s\" into memory%s", ZSTR_VAL(inputfile), (use_include_path) ? " (using include path)" : ""); RETURN_FALSE; } if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(contents))) { - php_error_docref(NULL, E_WARNING, "Input string is too long"); - RETURN_FALSE; + zend_value_error("Input string is too long"); + RETURN_THROWS(); } - TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options); + TIDY_APPLY_CONFIG(obj->ptdoc->doc, options_str, options_ht); if (php_tidy_parse_string(obj, ZSTR_VAL(contents), (uint32_t)ZSTR_LEN(contents), enc) == FAILURE) { RETVAL_FALSE; @@ -1702,28 +1435,30 @@ static TIDY_DOC_METHOD(parseFile) zend_string_release_ex(contents, 0); } -static TIDY_DOC_METHOD(parseString) +PHP_METHOD(tidy, parseString) { char *enc = NULL; size_t enc_len = 0; - zval *options = NULL; + HashTable *options_ht = NULL; PHPTidyObj *obj; - zend_string *input; + zend_string *input, *options_str = NULL; - TIDY_SET_CONTEXT; - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|zs", &input, &options, &enc, &enc_len) == FAILURE) { - RETURN_FALSE; - } + ZEND_PARSE_PARAMETERS_START(1, 3) + Z_PARAM_STR(input) + Z_PARAM_OPTIONAL + Z_PARAM_ARRAY_HT_OR_STR_OR_NULL(options_ht, options_str) + Z_PARAM_STRING_OR_NULL(enc, enc_len) + ZEND_PARSE_PARAMETERS_END(); if (ZEND_SIZE_T_UINT_OVFL(ZSTR_LEN(input))) { - php_error_docref(NULL, E_WARNING, "Input string is too long"); - RETURN_FALSE; + zend_argument_value_error(1, "is too long"); + RETURN_THROWS(); } + TIDY_SET_CONTEXT; obj = Z_TIDY_P(object); - TIDY_APPLY_CONFIG_ZVAL(obj->ptdoc->doc, options); + TIDY_APPLY_CONFIG(obj->ptdoc->doc, options_str, options_ht); if(php_tidy_parse_string(obj, ZSTR_VAL(input), (uint32_t)ZSTR_LEN(input), enc) == SUCCESS) { RETURN_TRUE; @@ -1733,41 +1468,36 @@ static TIDY_DOC_METHOD(parseString) } -/* {{{ proto TidyNode tidy_get_root() - Returns a TidyNode Object representing the root of the tidy parse tree */ -static PHP_FUNCTION(tidy_get_root) +/* {{{ Returns a TidyNode Object representing the root of the tidy parse tree */ +PHP_FUNCTION(tidy_get_root) { php_tidy_create_node(INTERNAL_FUNCTION_PARAM_PASSTHRU, is_root_node); } /* }}} */ -/* {{{ proto TidyNode tidy_get_html() - Returns a TidyNode Object starting from the <HTML> tag of the tidy parse tree */ -static PHP_FUNCTION(tidy_get_html) +/* {{{ Returns a TidyNode Object starting from the <HTML> tag of the tidy parse tree */ +PHP_FUNCTION(tidy_get_html) { php_tidy_create_node(INTERNAL_FUNCTION_PARAM_PASSTHRU, is_html_node); } /* }}} */ -/* {{{ proto TidyNode tidy_get_head() - Returns a TidyNode Object starting from the <HEAD> tag of the tidy parse tree */ -static PHP_FUNCTION(tidy_get_head) +/* {{{ Returns a TidyNode Object starting from the <HEAD> tag of the tidy parse tree */ +PHP_FUNCTION(tidy_get_head) { php_tidy_create_node(INTERNAL_FUNCTION_PARAM_PASSTHRU, is_head_node); } /* }}} */ -/* {{{ proto TidyNode tidy_get_body(tidy tidy) - Returns a TidyNode Object starting from the <BODY> tag of the tidy parse tree */ -static PHP_FUNCTION(tidy_get_body) +/* {{{ Returns a TidyNode Object starting from the <BODY> tag of the tidy parse tree */ +PHP_FUNCTION(tidy_get_body) { php_tidy_create_node(INTERNAL_FUNCTION_PARAM_PASSTHRU, is_body_node); } /* }}} */ -/* {{{ proto bool tidyNode::hasChildren() - Returns true if this node has children */ -static TIDY_NODE_METHOD(hasChildren) +/* {{{ Returns true if this node has children */ +PHP_METHOD(tidyNode, hasChildren) { TIDY_FETCH_ONLY_OBJECT; @@ -1779,9 +1509,8 @@ static TIDY_NODE_METHOD(hasChildren) } /* }}} */ -/* {{{ proto bool tidyNode::hasSiblings() - Returns true if this node has siblings */ -static TIDY_NODE_METHOD(hasSiblings) +/* {{{ Returns true if this node has siblings */ +PHP_METHOD(tidyNode, hasSiblings) { TIDY_FETCH_ONLY_OBJECT; @@ -1793,9 +1522,8 @@ static TIDY_NODE_METHOD(hasSiblings) } /* }}} */ -/* {{{ proto bool tidyNode::isComment() - Returns true if this node represents a comment */ -static TIDY_NODE_METHOD(isComment) +/* {{{ Returns true if this node represents a comment */ +PHP_METHOD(tidyNode, isComment) { TIDY_FETCH_ONLY_OBJECT; @@ -1807,9 +1535,8 @@ static TIDY_NODE_METHOD(isComment) } /* }}} */ -/* {{{ proto bool tidyNode::isHtml() - Returns true if this node is part of a HTML document */ -static TIDY_NODE_METHOD(isHtml) +/* {{{ Returns true if this node is part of a HTML document */ +PHP_METHOD(tidyNode, isHtml) { TIDY_FETCH_ONLY_OBJECT; @@ -1824,9 +1551,8 @@ static TIDY_NODE_METHOD(isHtml) } /* }}} */ -/* {{{ proto bool tidyNode::isText() - Returns true if this node represents text (no markup) */ -static TIDY_NODE_METHOD(isText) +/* {{{ Returns true if this node represents text (no markup) */ +PHP_METHOD(tidyNode, isText) { TIDY_FETCH_ONLY_OBJECT; @@ -1838,9 +1564,8 @@ static TIDY_NODE_METHOD(isText) } /* }}} */ -/* {{{ proto bool tidyNode::isJste() - Returns true if this node is JSTE */ -static TIDY_NODE_METHOD(isJste) +/* {{{ Returns true if this node is JSTE */ +PHP_METHOD(tidyNode, isJste) { TIDY_FETCH_ONLY_OBJECT; @@ -1852,9 +1577,8 @@ static TIDY_NODE_METHOD(isJste) } /* }}} */ -/* {{{ proto bool tidyNode::isAsp() - Returns true if this node is ASP */ -static TIDY_NODE_METHOD(isAsp) +/* {{{ Returns true if this node is ASP */ +PHP_METHOD(tidyNode, isAsp) { TIDY_FETCH_ONLY_OBJECT; @@ -1866,9 +1590,8 @@ static TIDY_NODE_METHOD(isAsp) } /* }}} */ -/* {{{ proto bool tidyNode::isPhp() - Returns true if this node is PHP */ -static TIDY_NODE_METHOD(isPhp) +/* {{{ Returns true if this node is PHP */ +PHP_METHOD(tidyNode, isPhp) { TIDY_FETCH_ONLY_OBJECT; @@ -1880,9 +1603,8 @@ static TIDY_NODE_METHOD(isPhp) } /* }}} */ -/* {{{ proto tidyNode tidyNode::getParent() - Returns the parent node if available or NULL */ -static TIDY_NODE_METHOD(getParent) +/* {{{ Returns the parent node if available or NULL */ +PHP_METHOD(tidyNode, getParent) { TidyNode parent_node; PHPTidyObj *newobj; @@ -1904,9 +1626,8 @@ static TIDY_NODE_METHOD(getParent) /* }}} */ -/* {{{ proto tidyNode::__construct() - __constructor for tidyNode. */ -static TIDY_NODE_METHOD(__construct) +/* {{{ __constructor for tidyNode. */ +PHP_METHOD(tidyNode, __construct) { zend_throw_error(NULL, "You should not create a tidyNode manually"); } @@ -2051,7 +1772,7 @@ static void _php_tidy_register_tags(INIT_FUNC_ARGS) TIDY_TAG_CONST(VAR); TIDY_TAG_CONST(WBR); TIDY_TAG_CONST(XMP); -# if HAVE_TIDYBUFFIO_H +# ifdef HAVE_TIDYBUFFIO_H TIDY_TAG_CONST(ARTICLE); TIDY_TAG_CONST(ASIDE); TIDY_TAG_CONST(AUDIO); diff --git a/ext/tidy/tidy.stub.php b/ext/tidy/tidy.stub.php new file mode 100644 index 0000000000..8b55c6b148 --- /dev/null +++ b/ext/tidy/tidy.stub.php @@ -0,0 +1,185 @@ +<?php + +/** @generate-function-entries */ + +function tidy_parse_string(string $string, array|string|null $config = null, ?string $encoding = null): tidy|false {} + +function tidy_get_error_buffer(tidy $tidy): string|false {} + +function tidy_get_output(tidy $tidy): string {} + +function tidy_parse_file(string $filename, array|string|null $config = null, ?string $encoding = null, bool $useIncludePath = false): tidy|false {} + +function tidy_clean_repair(tidy $tidy): bool {} + +function tidy_repair_string(string $string, array|string|null $config = null, ?string $encoding = null): string|false {} + +function tidy_repair_file(string $filename, array|string|null $config = null, ?string $encoding = null, bool $useIncludePath = false): string|false {} + +function tidy_diagnose(tidy $tidy): bool {} + +function tidy_get_release(): string {} + +#ifdef HAVE_TIDYOPTGETDOC +function tidy_get_opt_doc(tidy $tidy, string $option): string|false {} +#endif + +function tidy_get_config(tidy $tidy): array {} + +function tidy_get_status(tidy $tidy): int {} + +function tidy_get_html_ver(tidy $tidy): int {} + +function tidy_is_xhtml(tidy $tidy): bool {} + +function tidy_is_xml(tidy $tidy): bool {} + +function tidy_error_count(tidy $tidy): int {} + +function tidy_warning_count(tidy $tidy): int {} + +function tidy_access_count(tidy $tidy): int {} + +function tidy_config_count(tidy $tidy): int {} + +function tidy_getopt(tidy $tidy, string $option): string|int|bool {} + +function tidy_get_root(tidy $tidy): ?tidyNode {} + +function tidy_get_html(tidy $tidy): ?tidyNode {} + +function tidy_get_head(tidy $tidy): ?tidyNode {} + +function tidy_get_body(tidy $tidy): ?tidyNode {} + +class tidy +{ + public function __construct(?string $filename = null, array|string|null $config = null, ?string $encoding = null, bool $useIncludePath = false) {} + + /** + * @return string|int|bool + * @alias tidy_getopt + */ + public function getOpt(string $option) {} + + /** + * @return bool + * @alias tidy_clean_repair + */ + public function cleanRepair() {} + + /** @return bool */ + public function parseFile(string $filename, array|string|null $config = null, ?string $encoding = null, bool $useIncludePath = false) {} + + /** @return bool */ + public function parseString(string $string, array|string|null $config = null, ?string $encoding = null) {} + + /** + * @return bool + * @alias tidy_repair_string + */ + public static function repairString(string $string, array|string|null $config = null, ?string $encoding = null) {} + + /** + * @return bool + * @alias tidy_repair_file + */ + public static function repairFile(string $filename, array|string|null $config = null, ?string $encoding = null, bool $useIncludePath = false) {} + + /** + * @return bool + * @alias tidy_diagnose + */ + public function diagnose() {} + + /** + * @return string + * @alias tidy_get_release + */ + public function getRelease() {} + + /** + * @return array + * @alias tidy_get_config + */ + public function getConfig() {} + + /** + * @return int + * @alias tidy_get_status + */ + public function getStatus() {} + + /** + * @return int + * @alias tidy_get_html_ver + */ + public function getHtmlVer() {} + +#ifdef HAVE_TIDYOPTGETDOC + /** + * @return string|false + * @alias tidy_get_opt_doc + */ + public function getOptDoc(string $option) {} +#endif + + /** + * @return bool + * @alias tidy_is_xhtml + */ + public function isXhtml() {} + + /** + * @return bool + * @alias tidy_is_xml + */ + public function isXml() {} + + /** + * @return tidyNode|null + * @alias tidy_get_root + */ + public function root() {} + + /** + * @return tidyNode|null + * @alias tidy_get_head + */ + public function head() {} + + /** + * @return tidyNode|null + * @alias tidy_get_html + */ + public function html() {} + + /** + * @return tidyNode|null + * @alias tidy_get_body + */ + public function body() {} +} + +final class tidyNode +{ + private function __construct() {} + + public function hasChildren(): bool {} + + public function hasSiblings(): bool {} + + public function isComment(): bool {} + + public function isHtml(): bool {} + + public function isText(): bool {} + + public function isJste(): bool {} + + public function isAsp(): bool {} + + public function isPhp(): bool {} + + public function getParent(): ?tidyNode {} +} diff --git a/ext/tidy/tidy_arginfo.h b/ext/tidy/tidy_arginfo.h new file mode 100644 index 0000000000..fc56a7f5cf --- /dev/null +++ b/ext/tidy/tidy_arginfo.h @@ -0,0 +1,283 @@ +/* This is a generated file, edit the .stub.php file instead. + * Stub hash: 4042c33d3ea3f5fb87cfb696488f6280b6ec7e7f */ + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_tidy_parse_string, 0, 1, tidy, MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, config, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_tidy_get_error_buffer, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_OBJ_INFO(0, tidy, tidy, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tidy_get_output, 0, 1, IS_STRING, 0) + ZEND_ARG_OBJ_INFO(0, tidy, tidy, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_tidy_parse_file, 0, 1, tidy, MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, config, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, useIncludePath, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tidy_clean_repair, 0, 1, _IS_BOOL, 0) + ZEND_ARG_OBJ_INFO(0, tidy, tidy, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_tidy_repair_string, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, config, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_tidy_repair_file, 0, 1, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, config, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, useIncludePath, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +#define arginfo_tidy_diagnose arginfo_tidy_clean_repair + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tidy_get_release, 0, 0, IS_STRING, 0) +ZEND_END_ARG_INFO() + +#if defined(HAVE_TIDYOPTGETDOC) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_tidy_get_opt_doc, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_OBJ_INFO(0, tidy, tidy, 0) + ZEND_ARG_TYPE_INFO(0, option, IS_STRING, 0) +ZEND_END_ARG_INFO() +#endif + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tidy_get_config, 0, 1, IS_ARRAY, 0) + ZEND_ARG_OBJ_INFO(0, tidy, tidy, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_tidy_get_status, 0, 1, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, tidy, tidy, 0) +ZEND_END_ARG_INFO() + +#define arginfo_tidy_get_html_ver arginfo_tidy_get_status + +#define arginfo_tidy_is_xhtml arginfo_tidy_clean_repair + +#define arginfo_tidy_is_xml arginfo_tidy_clean_repair + +#define arginfo_tidy_error_count arginfo_tidy_get_status + +#define arginfo_tidy_warning_count arginfo_tidy_get_status + +#define arginfo_tidy_access_count arginfo_tidy_get_status + +#define arginfo_tidy_config_count arginfo_tidy_get_status + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_tidy_getopt, 0, 2, MAY_BE_STRING|MAY_BE_LONG|MAY_BE_BOOL) + ZEND_ARG_OBJ_INFO(0, tidy, tidy, 0) + ZEND_ARG_TYPE_INFO(0, option, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_tidy_get_root, 0, 1, tidyNode, 1) + ZEND_ARG_OBJ_INFO(0, tidy, tidy, 0) +ZEND_END_ARG_INFO() + +#define arginfo_tidy_get_html arginfo_tidy_get_root + +#define arginfo_tidy_get_head arginfo_tidy_get_root + +#define arginfo_tidy_get_body arginfo_tidy_get_root + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_tidy___construct, 0, 0, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filename, IS_STRING, 1, "null") + ZEND_ARG_TYPE_MASK(0, config, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, useIncludePath, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_tidy_getOpt, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, option, IS_STRING, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_tidy_cleanRepair, 0, 0, 0) +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_tidy_parseFile, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, config, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, useIncludePath, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() + +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_tidy_parseString, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0) + ZEND_ARG_TYPE_MASK(0, config, MAY_BE_ARRAY|MAY_BE_STRING|MAY_BE_NULL, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, encoding, IS_STRING, 1, "null") +ZEND_END_ARG_INFO() + +#define arginfo_class_tidy_repairString arginfo_class_tidy_parseString + +#define arginfo_class_tidy_repairFile arginfo_class_tidy_parseFile + +#define arginfo_class_tidy_diagnose arginfo_class_tidy_cleanRepair + +#define arginfo_class_tidy_getRelease arginfo_class_tidy_cleanRepair + +#define arginfo_class_tidy_getConfig arginfo_class_tidy_cleanRepair + +#define arginfo_class_tidy_getStatus arginfo_class_tidy_cleanRepair + +#define arginfo_class_tidy_getHtmlVer arginfo_class_tidy_cleanRepair + +#if defined(HAVE_TIDYOPTGETDOC) +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_tidy_getOptDoc, 0, 0, 1) + ZEND_ARG_TYPE_INFO(0, option, IS_STRING, 0) +ZEND_END_ARG_INFO() +#endif + +#define arginfo_class_tidy_isXhtml arginfo_class_tidy_cleanRepair + +#define arginfo_class_tidy_isXml arginfo_class_tidy_cleanRepair + +#define arginfo_class_tidy_root arginfo_class_tidy_cleanRepair + +#define arginfo_class_tidy_head arginfo_class_tidy_cleanRepair + +#define arginfo_class_tidy_html arginfo_class_tidy_cleanRepair + +#define arginfo_class_tidy_body arginfo_class_tidy_cleanRepair + +#define arginfo_class_tidyNode___construct arginfo_class_tidy_cleanRepair + +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_tidyNode_hasChildren, 0, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +#define arginfo_class_tidyNode_hasSiblings arginfo_class_tidyNode_hasChildren + +#define arginfo_class_tidyNode_isComment arginfo_class_tidyNode_hasChildren + +#define arginfo_class_tidyNode_isHtml arginfo_class_tidyNode_hasChildren + +#define arginfo_class_tidyNode_isText arginfo_class_tidyNode_hasChildren + +#define arginfo_class_tidyNode_isJste arginfo_class_tidyNode_hasChildren + +#define arginfo_class_tidyNode_isAsp arginfo_class_tidyNode_hasChildren + +#define arginfo_class_tidyNode_isPhp arginfo_class_tidyNode_hasChildren + +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_tidyNode_getParent, 0, 0, tidyNode, 1) +ZEND_END_ARG_INFO() + + +ZEND_FUNCTION(tidy_parse_string); +ZEND_FUNCTION(tidy_get_error_buffer); +ZEND_FUNCTION(tidy_get_output); +ZEND_FUNCTION(tidy_parse_file); +ZEND_FUNCTION(tidy_clean_repair); +ZEND_FUNCTION(tidy_repair_string); +ZEND_FUNCTION(tidy_repair_file); +ZEND_FUNCTION(tidy_diagnose); +ZEND_FUNCTION(tidy_get_release); +#if defined(HAVE_TIDYOPTGETDOC) +ZEND_FUNCTION(tidy_get_opt_doc); +#endif +ZEND_FUNCTION(tidy_get_config); +ZEND_FUNCTION(tidy_get_status); +ZEND_FUNCTION(tidy_get_html_ver); +ZEND_FUNCTION(tidy_is_xhtml); +ZEND_FUNCTION(tidy_is_xml); +ZEND_FUNCTION(tidy_error_count); +ZEND_FUNCTION(tidy_warning_count); +ZEND_FUNCTION(tidy_access_count); +ZEND_FUNCTION(tidy_config_count); +ZEND_FUNCTION(tidy_getopt); +ZEND_FUNCTION(tidy_get_root); +ZEND_FUNCTION(tidy_get_html); +ZEND_FUNCTION(tidy_get_head); +ZEND_FUNCTION(tidy_get_body); +ZEND_METHOD(tidy, __construct); +ZEND_METHOD(tidy, parseFile); +ZEND_METHOD(tidy, parseString); +ZEND_METHOD(tidyNode, __construct); +ZEND_METHOD(tidyNode, hasChildren); +ZEND_METHOD(tidyNode, hasSiblings); +ZEND_METHOD(tidyNode, isComment); +ZEND_METHOD(tidyNode, isHtml); +ZEND_METHOD(tidyNode, isText); +ZEND_METHOD(tidyNode, isJste); +ZEND_METHOD(tidyNode, isAsp); +ZEND_METHOD(tidyNode, isPhp); +ZEND_METHOD(tidyNode, getParent); + + +static const zend_function_entry ext_functions[] = { + ZEND_FE(tidy_parse_string, arginfo_tidy_parse_string) + ZEND_FE(tidy_get_error_buffer, arginfo_tidy_get_error_buffer) + ZEND_FE(tidy_get_output, arginfo_tidy_get_output) + ZEND_FE(tidy_parse_file, arginfo_tidy_parse_file) + ZEND_FE(tidy_clean_repair, arginfo_tidy_clean_repair) + ZEND_FE(tidy_repair_string, arginfo_tidy_repair_string) + ZEND_FE(tidy_repair_file, arginfo_tidy_repair_file) + ZEND_FE(tidy_diagnose, arginfo_tidy_diagnose) + ZEND_FE(tidy_get_release, arginfo_tidy_get_release) +#if defined(HAVE_TIDYOPTGETDOC) + ZEND_FE(tidy_get_opt_doc, arginfo_tidy_get_opt_doc) +#endif + ZEND_FE(tidy_get_config, arginfo_tidy_get_config) + ZEND_FE(tidy_get_status, arginfo_tidy_get_status) + ZEND_FE(tidy_get_html_ver, arginfo_tidy_get_html_ver) + ZEND_FE(tidy_is_xhtml, arginfo_tidy_is_xhtml) + ZEND_FE(tidy_is_xml, arginfo_tidy_is_xml) + ZEND_FE(tidy_error_count, arginfo_tidy_error_count) + ZEND_FE(tidy_warning_count, arginfo_tidy_warning_count) + ZEND_FE(tidy_access_count, arginfo_tidy_access_count) + ZEND_FE(tidy_config_count, arginfo_tidy_config_count) + ZEND_FE(tidy_getopt, arginfo_tidy_getopt) + ZEND_FE(tidy_get_root, arginfo_tidy_get_root) + ZEND_FE(tidy_get_html, arginfo_tidy_get_html) + ZEND_FE(tidy_get_head, arginfo_tidy_get_head) + ZEND_FE(tidy_get_body, arginfo_tidy_get_body) + ZEND_FE_END +}; + + +static const zend_function_entry class_tidy_methods[] = { + ZEND_ME(tidy, __construct, arginfo_class_tidy___construct, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(getOpt, tidy_getopt, arginfo_class_tidy_getOpt, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(cleanRepair, tidy_clean_repair, arginfo_class_tidy_cleanRepair, ZEND_ACC_PUBLIC) + ZEND_ME(tidy, parseFile, arginfo_class_tidy_parseFile, ZEND_ACC_PUBLIC) + ZEND_ME(tidy, parseString, arginfo_class_tidy_parseString, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(repairString, tidy_repair_string, arginfo_class_tidy_repairString, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + ZEND_ME_MAPPING(repairFile, tidy_repair_file, arginfo_class_tidy_repairFile, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC) + ZEND_ME_MAPPING(diagnose, tidy_diagnose, arginfo_class_tidy_diagnose, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(getRelease, tidy_get_release, arginfo_class_tidy_getRelease, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(getConfig, tidy_get_config, arginfo_class_tidy_getConfig, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(getStatus, tidy_get_status, arginfo_class_tidy_getStatus, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(getHtmlVer, tidy_get_html_ver, arginfo_class_tidy_getHtmlVer, ZEND_ACC_PUBLIC) +#if defined(HAVE_TIDYOPTGETDOC) + ZEND_ME_MAPPING(getOptDoc, tidy_get_opt_doc, arginfo_class_tidy_getOptDoc, ZEND_ACC_PUBLIC) +#endif + ZEND_ME_MAPPING(isXhtml, tidy_is_xhtml, arginfo_class_tidy_isXhtml, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(isXml, tidy_is_xml, arginfo_class_tidy_isXml, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(root, tidy_get_root, arginfo_class_tidy_root, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(head, tidy_get_head, arginfo_class_tidy_head, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(html, tidy_get_html, arginfo_class_tidy_html, ZEND_ACC_PUBLIC) + ZEND_ME_MAPPING(body, tidy_get_body, arginfo_class_tidy_body, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; + + +static const zend_function_entry class_tidyNode_methods[] = { + ZEND_ME(tidyNode, __construct, arginfo_class_tidyNode___construct, ZEND_ACC_PRIVATE) + ZEND_ME(tidyNode, hasChildren, arginfo_class_tidyNode_hasChildren, ZEND_ACC_PUBLIC) + ZEND_ME(tidyNode, hasSiblings, arginfo_class_tidyNode_hasSiblings, ZEND_ACC_PUBLIC) + ZEND_ME(tidyNode, isComment, arginfo_class_tidyNode_isComment, ZEND_ACC_PUBLIC) + ZEND_ME(tidyNode, isHtml, arginfo_class_tidyNode_isHtml, ZEND_ACC_PUBLIC) + ZEND_ME(tidyNode, isText, arginfo_class_tidyNode_isText, ZEND_ACC_PUBLIC) + ZEND_ME(tidyNode, isJste, arginfo_class_tidyNode_isJste, ZEND_ACC_PUBLIC) + ZEND_ME(tidyNode, isAsp, arginfo_class_tidyNode_isAsp, ZEND_ACC_PUBLIC) + ZEND_ME(tidyNode, isPhp, arginfo_class_tidyNode_isPhp, ZEND_ACC_PUBLIC) + ZEND_ME(tidyNode, getParent, arginfo_class_tidyNode_getParent, ZEND_ACC_PUBLIC) + ZEND_FE_END +}; |