john Thu Jan 8 04:21:06 2004 EDT Modified files: /php-src/ext/tidy tidy.c Log: tidy_repair_string/file() don't get called from an existing tidy resource. Index: php-src/ext/tidy/tidy.c diff -u php-src/ext/tidy/tidy.c:1.31 php-src/ext/tidy/tidy.c:1.32 --- php-src/ext/tidy/tidy.c:1.31 Thu Jan 8 03:17:41 2004 +++ php-src/ext/tidy/tidy.c Thu Jan 8 04:21:05 2004 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: tidy.c,v 1.31 2004/01/08 08:17:41 andi Exp $ */ +/* $Id: tidy.c,v 1.32 2004/01/08 09:21:05 john Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -229,23 +229,18 @@ char *data=NULL, *cfg_file=NULL, *arg1; int cfg_file_len, arg1_len; zend_bool use_include_path = 0; - zval *object = getThis(); - PHPTidyObj *obj; - - if (object) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sb", &arg1, &arg1_len, &cfg_file, &cfg_file_len, &use_include_path) == FAILURE) { - RETURN_FALSE; - } - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|sb", &object, tidy_ce_doc, - &arg1, &arg1_len, &cfg_file, &cfg_file_len, &use_include_path) == FAILURE) { - return; - } - - tidy_instanciate(tidy_ce_doc, return_value TSRMLS_CC); + TidyDoc doc; + TidyBuffer *errbuf; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sb", &arg1, &arg1_len, &cfg_file, &cfg_file_len, &use_include_path) == FAILURE) { + RETURN_FALSE; } - - obj = (PHPTidyObj *) zend_object_store_get_object(return_value TSRMLS_CC); + + if (getThis()) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot call this function from an object context"); + RETURN_FALSE; + + } if (is_file) { if (!(data = php_tidy_file_to_mem(arg1, use_include_path TSRMLS_CC))) { @@ -255,24 +250,36 @@ data = arg1; } + doc = tidyCreate(); + errbuf = emalloc(sizeof(TidyBuffer)); + tidyBufInit(errbuf); + + if (tidySetErrorBuffer(doc, errbuf) != 0) { + zend_error(E_ERROR, "Could not set Tidy error buffer"); + } + + tidyOptSetBool(doc, TidyForceOutput, yes); + tidyOptSetBool(doc, TidyMark, no); + + TIDY_SET_DEFAULT_CONFIG(doc); + if (cfg_file && cfg_file[0]) { TIDY_SAFE_MODE_CHECK(cfg_file); - if (tidyLoadConfig(obj->ptdoc->doc, cfg_file) < 0) { + if (tidyLoadConfig(doc, cfg_file) < 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not load configuration file '%s'", cfg_file); RETVAL_FALSE; } } if (data) { - if (tidyParseString(obj->ptdoc->doc, data) < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", obj->ptdoc->errbuf->bp); + if (tidyParseString(doc, data) < 0) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", errbuf->bp); RETVAL_FALSE; } else { - obj->ptdoc->parsed = TRUE; - if (tidyCleanAndRepair(obj->ptdoc->doc) >= 0) { + if (tidyCleanAndRepair(doc) >= 0) { TidyBuffer output = {0}; - tidySaveBuffer (obj->ptdoc->doc, &output); + tidySaveBuffer (doc, &output); RETVAL_STRING(output.bp, 1); tidyBufFree(&output); } else { @@ -284,6 +291,10 @@ if (is_file) { efree(data); } + + tidyBufFree(errbuf); + efree(errbuf); + tidyRelease(doc); } static char *php_tidy_file_to_mem(char *filename, zend_bool use_include_path TSRMLS_DC) @@ -811,7 +822,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.31 2004/01/08 08:17:41 andi Exp $)"); + php_info_print_table_row(2, "Extension Version", PHP_TIDY_MODULE_VERSION " ($Id: tidy.c,v 1.32 2004/01/08 09:21:05 john Exp $)"); php_info_print_table_end(); DISPLAY_INI_ENTRIES();
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php