john Tue Jan 6 13:24:18 2004 EDT Added files: /php-src/ext/tidy/tests 014.phpt 015.html 015.phpt
Modified files: /php-src/ext/tidy php_tidy.h tidy.c Log: Added an optional array parameter to tidy_parse_file/string to fix a bug. Apparently some libtidy config options must be set prior to parsing in order to work properly.
Index: php-src/ext/tidy/php_tidy.h diff -u php-src/ext/tidy/php_tidy.h:1.13 php-src/ext/tidy/php_tidy.h:1.14 --- php-src/ext/tidy/php_tidy.h:1.13 Thu Dec 18 14:59:58 2003 +++ php-src/ext/tidy/php_tidy.h Tue Jan 6 13:24:17 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_tidy.h,v 1.13 2003/12/18 19:59:58 sniper Exp $ */ +/* $Id: php_tidy.h,v 1.14 2004/01/06 18:24:17 john Exp $ */ #ifndef PHP_TIDY_H #define PHP_TIDY_H @@ -213,6 +213,8 @@ static void tidy_add_default_properties(PHPTidyObj *, tidy_obj_type TSRMLS_DC); static void *php_tidy_get_opt_val(PHPTidyDoc *, TidyOption, TidyOptionType * TSRMLS_DC); static void php_tidy_create_node(INTERNAL_FUNCTION_PARAMETERS, tidy_base_nodetypes); +static int _php_tidy_set_tidy_opt(TidyDoc, char *, zval *); +static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options); void _php_tidy_register_nodetypes(INIT_FUNC_ARGS); void _php_tidy_register_tags(INIT_FUNC_ARGS); Index: php-src/ext/tidy/tidy.c diff -u php-src/ext/tidy/tidy.c:1.27 php-src/ext/tidy/tidy.c:1.28 --- php-src/ext/tidy/tidy.c:1.27 Tue Dec 23 15:12:55 2003 +++ php-src/ext/tidy/tidy.c Tue Jan 6 13:24:17 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tidy.c,v 1.27 2003/12/23 20:12:55 wez Exp $ */ +/* $Id: tidy.c,v 1.28 2004/01/06 18:24:17 john Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -32,8 +32,9 @@ #include "Zend/zend_API.h" #include "Zend/zend_hash.h" #include "safe_mode.h" -#include "zend_default_classes.h" -#include "zend_object_handlers.h" +#include "Zend/zend_default_classes.h" +#include "Zend/zend_object_handlers.h" +#include "Zend/zend_hash.h" ZEND_DECLARE_MODULE_GLOBALS(tidy) @@ -178,6 +179,52 @@ zend_error(E_ERROR, "Could not allocate memory for tidy! (Reason: %s)", (char *)msg); } +static int _php_tidy_set_tidy_opt(TidyDoc doc, char *optname, zval *value) +{ + TidyOption opt; + + opt = tidyGetOptionByName(doc, optname); + + if (!opt) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname); + return FAILURE; + } + + if (tidyOptIsReadOnly(opt)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted to set read-only option '%s'", optname); + return FAILURE; + } + + switch(tidyOptGetType(opt)) { + case TidyString: + convert_to_string_ex(&value); + if (tidyOptSetValue(doc, tidyOptGetId(opt), Z_STRVAL_P(value))) { + return SUCCESS; + } + break; + + case TidyInteger: + convert_to_long_ex(&value); + if (tidyOptSetInt(doc, tidyOptGetId(opt), Z_LVAL_P(value))) { + return SUCCESS; + } + break; + + case TidyBoolean: + convert_to_long_ex(&value); + if (tidyOptSetBool(doc, tidyOptGetId(opt), Z_LVAL_P(value))) { + return SUCCESS; + } + break; + + default: + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to determine type of Tidy configuration constant to set"); + break; + } + + return FAILURE; +} + static void php_tidy_quick_repair(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_file) { char *data=NULL, *cfg_file=NULL, *arg1; @@ -478,10 +525,6 @@ { } -static void tidy_globals_dtor(zend_tidy_globals *g TSRMLS_DC) -{ -} - static void tidy_add_default_properties(PHPTidyObj *obj, tidy_obj_type type TSRMLS_DC) { @@ -640,19 +683,41 @@ tidy_add_default_properties(newobj, is_node TSRMLS_CC); } +static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options) +{ + char *opt_name; + zval **opt_val; + ulong opt_indx; + + for (zend_hash_internal_pointer_reset(ht_options); + zend_hash_get_current_data(ht_options, (void **)&opt_val) == SUCCESS; + zend_hash_move_forward(ht_options)) { + + if(zend_hash_get_current_key(ht_options, &opt_name, &opt_indx, FALSE) == FAILURE) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not retrieve key from array"); + } + + _php_tidy_set_tidy_opt(doc, opt_name, *opt_val); + + } + + return SUCCESS; +} + static void php_tidy_parse_file(INTERNAL_FUNCTION_PARAMETERS) { char *inputfile; int input_len; zend_bool use_include_path = 0; char *contents; - + zval *options = NULL; + zend_bool is_object = FALSE; zval *object = getThis(); PHPTidyObj *obj; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &inputfile, &input_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ab", &inputfile, &input_len, &options, &use_include_path) == FAILURE) { RETURN_FALSE; } @@ -673,6 +738,10 @@ RETURN_FALSE; } + if(options) { + _php_tidy_apply_config_array(obj->ptdoc->doc, HASH_OF(options)); + } + if (tidyParseString(obj->ptdoc->doc, contents) < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", obj->ptdoc->errbuf->bp); RETVAL_FALSE; @@ -739,7 +808,7 @@ php_info_print_table_start(); php_info_print_table_header(2, "Tidy support", "enabled"); php_info_print_table_row(2, "libTidy Library Version", (char *)tidyReleaseDate()); - php_info_print_table_row(2, "Extension Version", PHP_TIDY_MODULE_VERSION " ($Id: tidy.c,v 1.27 2003/12/23 20:12:55 wez Exp $)"); + php_info_print_table_row(2, "Extension Version", PHP_TIDY_MODULE_VERSION " ($Id: tidy.c,v 1.28 2004/01/06 18:24:17 john Exp $)"); php_info_print_table_end(); DISPLAY_INI_ENTRIES(); @@ -803,13 +872,14 @@ { char *input; int input_len; - + zval *options = NULL; + zend_bool is_object = FALSE; zval *object = getThis(); PHPTidyObj *obj; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &input, &input_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &input, &input_len, &options) == FAILURE) { RETURN_FALSE; } @@ -826,6 +896,10 @@ obj = (PHPTidyObj *) zend_object_store_get_object(return_value TSRMLS_CC); } + if(options) { + _php_tidy_apply_config_array(obj->ptdoc->doc, HASH_OF(options)); + } + if (tidyParseString(obj->ptdoc->doc, input) < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", obj->ptdoc->errbuf->bp); return; @@ -866,7 +940,7 @@ } /* }}} */ -/* {{{ proto boolean tidy_parse_file(string file [, bool use_include_path]) +/* {{{ proto boolean tidy_parse_file(string file [, array config_options [, bool use_include_path]]) Parse markup in file or URI */ PHP_FUNCTION(tidy_parse_file) { @@ -1237,7 +1311,6 @@ zval *value; char *optname; int optname_len; - TidyOption opt; if (object) { if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &optname, &optname_len, &value) == FAILURE) { @@ -1251,45 +1324,10 @@ obj = (PHPTidyObj *) zend_object_store_get_object(object TSRMLS_CC); - opt = tidyGetOptionByName(obj->ptdoc->doc, optname); - - if (!opt) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown Tidy Configuration Option '%s'", optname); - RETURN_FALSE; - } - - if (tidyOptIsReadOnly(opt)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted to set read-only option '%s'", optname); - RETURN_FALSE; - } - - switch(tidyOptGetType(opt)) { - case TidyString: - convert_to_string_ex(&value); - if (tidyOptSetValue(obj->ptdoc->doc, tidyOptGetId(opt), Z_STRVAL_P(value))) { - RETURN_TRUE; - } - break; - - case TidyInteger: - convert_to_long_ex(&value); - if (tidyOptSetInt(obj->ptdoc->doc, tidyOptGetId(opt), Z_LVAL_P(value))) { - RETURN_TRUE; - } - break; - - case TidyBoolean: - convert_to_long_ex(&value); - if (tidyOptSetBool(obj->ptdoc->doc, tidyOptGetId(opt), Z_LVAL_P(value))) { - RETURN_TRUE; - } - break; - - default: - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to determine type of Tidy configuration constant to set"); - break; + if(_php_tidy_set_tidy_opt(obj->ptdoc->doc, optname, value) == SUCCESS) { + RETURN_TRUE; } - + RETURN_FALSE; } /* }}} */ Index: php-src/ext/tidy/tests/014.phpt +++ php-src/ext/tidy/tests/014.phpt --TEST-- Passing configuration options through tidy_parse_string(). --SKIPIF-- <?php if (!extension_loaded("tidy")) print "skip"; ?> --POST-- --GET-- --INI-- --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); ?> --EXPECT-- <b>testing</b> Index: php-src/ext/tidy/tests/015.html +++ php-src/ext/tidy/tests/015.html <B>testing</I> Index: php-src/ext/tidy/tests/015.phpt +++ php-src/ext/tidy/tests/015.phpt --TEST-- Passing configuration options through tidy_parse_file(). --SKIPIF-- <?php if (!extension_loaded("tidy")) print "skip"; ?> --POST-- --GET-- --INI-- --FILE-- <?php $tidy = tidy_parse_file("ext/tidy/tests/015.html", array('show-body-only'=>true)); tidy_clean_repair($tidy); echo tidy_get_output($tidy); ?> --EXPECT-- <b>testing</b>
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php