Re: Proposal new function(tidy_output_handler) add to tidy extension
| From: | Youichi Iwakiri | Date: | Wed, 08 Oct 2003 07:41:23 +0000 |
| Subject: | Re: Proposal new function(tidy_output_handler) add to tidy extension | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-105@lists.php.net to get a copy of this message | ||
Sorry
Is an attached file prohibition in this NewsGroup?
patch is attached to below.
Index: pecl/tidy/php_tidy.h
===================================================================
RCS file: /repository/pecl/tidy/php_tidy.h,v
retrieving revision 1.9
diff -u -r1.9 php_tidy.h
--- pecl/tidy/php_tidy.h 22 Sep 2003 18:40:36 -0000 1.9
+++ pecl/tidy/php_tidy.h 8 Oct 2003 07:13:26 -0000
@@ -176,6 +176,7 @@
PHP_FUNCTION(tidy_load_config_enc);
PHP_FUNCTION(tidy_set_encoding);
PHP_FUNCTION(tidy_save_config);
+PHP_FUNCTION(tidy_output_handler);
PHP_FUNCTION(tidy_get_root);
PHP_FUNCTION(tidy_get_html);
@@ -214,6 +215,7 @@
PHPTidyDoc *tdoc;
zend_bool used;
char *default_config;
+ char *ob_mode;
ZEND_END_MODULE_GLOBALS(tidy)
#ifdef ZTS
Index: pecl/tidy/tidy.c
===================================================================
RCS file: /repository/pecl/tidy/tidy.c,v
retrieving revision 1.15
diff -u -r1.15 tidy.c
--- pecl/tidy/tidy.c 25 Sep 2003 09:32:54 -0000 1.15
+++ pecl/tidy/tidy.c 8 Oct 2003 07:13:27 -0000
@@ -69,6 +69,7 @@
PHP_FE(tidy_load_config_enc, NULL)
PHP_FE(tidy_set_encoding, NULL)
PHP_FE(tidy_save_config, NULL)
+ PHP_FE(tidy_output_handler, NULL)
#ifdef ZEND_ENGINE_2
PHP_FE(tidy_get_root, NULL)
@@ -159,6 +160,7 @@
*/
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("tidy.default_config", "", PHP_INI_SYSTEM, OnUpdateString, default_config, zend_tidy_globals, tidy_globals)
+STD_PHP_INI_ENTRY("tidy.ob_mode", "", PHP_INI_ALL, OnUpdateString, ob_mode, zend_tidy_globals, tidy_globals)
PHP_INI_END()
/* }}} */
@@ -880,6 +882,35 @@
}
/* }}} */
+/* {{{ proto string tidy_output_handler(string contents, int status)
+ Returns string in output buffer convert to tidied html, etc */
+PHP_FUNCTION(tidy_output_handler)
+{
+ char *arg_string;
+ int arg_string_len;
+ long arg_status;
+ TidyBuffer output = {0};
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &arg_string,
&arg_string_len, &arg_status) == FAILURE) {
+ return;
+ }
+
+ if(tidyParseString(TG(tdoc)->doc, arg_string) < 0) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "[Tidy error] %s",
TG(tdoc)->errbuf->bp);
+ }
+
+ TG(tdoc)->parsed = TRUE;
+
+ if (strcasecmp(TG(ob_mode), "clean") == 0) {
+ tidyCleanAndRepair(TG(tdoc)->doc);
+ }
+
+ tidySaveBuffer (TG(tdoc)->doc, &output);
+ RETVAL_STRING(output.bp, 1);
+ tidyBufFree(&output);
+}
+/* }}} */
+
#ifdef ZEND_ENGINE_2
static void tidy_object_dtor(void *object, zend_object_handle handle TSRMLS_DC)
{
--
Youichi Iwakiri