version 1.1, 2012/02/21 23:48:05
|
version 1.1.1.4, 2013/10/14 08:02:42
|
Line 2
|
Line 2
|
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| PHP Version 5 | |
| PHP Version 5 | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| Copyright (c) 1997-2012 The PHP Group | | | Copyright (c) 1997-2013 The PHP Group | |
+----------------------------------------------------------------------+ |
+----------------------------------------------------------------------+ |
| This source file is subject to version 3.01 of the PHP license, | |
| This source file is subject to version 3.01 of the PHP license, | |
| that is bundled with this package in the file LICENSE, and is | |
| that is bundled with this package in the file LICENSE, and is | |
Line 29
|
Line 29
|
|
|
#include "php_ini.h" |
#include "php_ini.h" |
#include "ext/standard/info.h" |
#include "ext/standard/info.h" |
#include "safe_mode.h" |
|
|
|
#include "tidy.h" |
#include "tidy.h" |
#include "buffio.h" |
#include "buffio.h" |
Line 43
|
Line 42
|
|
|
/* {{{ 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 \ |
#define TIDY_SET_CONTEXT \ |
zval *object = getThis(); |
zval *object = getThis(); |
|
|
Line 74
|
Line 75
|
_php_tidy_apply_config_array(_doc, HASH_OF(*_val) TSRMLS_CC); \ |
_php_tidy_apply_config_array(_doc, HASH_OF(*_val) TSRMLS_CC); \ |
} else { \ |
} else { \ |
convert_to_string_ex(_val); \ |
convert_to_string_ex(_val); \ |
TIDY_SAFE_MODE_CHECK(Z_STRVAL_PP(_val)); \ | TIDY_OPEN_BASE_DIR_CHECK(Z_STRVAL_PP(_val)); \ |
switch (tidyLoadConfig(_doc, Z_STRVAL_PP(_val))) { \ |
switch (tidyLoadConfig(_doc, Z_STRVAL_PP(_val))) { \ |
case -1: \ |
case -1: \ |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not load configuration file '%s'", Z_STRVAL_PP(_val)); \ |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not load configuration file '%s'", Z_STRVAL_PP(_val)); \ |
Line 156
|
Line 157
|
zend_hash_update(_table, #_key, sizeof(#_key), (void *)&tmp, sizeof(zval *), NULL); \ |
zend_hash_update(_table, #_key, sizeof(#_key), (void *)&tmp, sizeof(zval *), NULL); \ |
} |
} |
|
|
#define TIDY_SAFE_MODE_CHECK(filename) \ | #define TIDY_OPEN_BASE_DIR_CHECK(filename) \ |
if ((PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) || php_check_open_basedir(filename TSRMLS_CC)) { \ | if (php_check_open_basedir(filename TSRMLS_CC)) { \ |
RETURN_FALSE; \ |
RETURN_FALSE; \ |
} \ |
} \ |
|
|
Line 187 typedef enum {
|
Line 188 typedef enum {
|
} tidy_base_nodetypes; |
} tidy_base_nodetypes; |
|
|
struct _PHPTidyDoc { |
struct _PHPTidyDoc { |
TidyDoc doc; | TidyDoc doc; |
TidyBuffer *errbuf; | TidyBuffer *errbuf; |
unsigned int ref_count; | unsigned int ref_count; |
| unsigned int initialized:1; |
}; |
}; |
|
|
struct _PHPTidyObj { |
struct _PHPTidyObj { |
zend_object std; | zend_object std; |
TidyNode node; | TidyNode node; |
tidy_obj_type type; | tidy_obj_type type; |
PHPTidyDoc *ptdoc; | PHPTidyDoc *ptdoc; |
}; |
}; |
/* }}} */ |
/* }}} */ |
|
|
Line 217 static int _php_tidy_set_tidy_opt(TidyDoc, char *, zva
|
Line 219 static int _php_tidy_set_tidy_opt(TidyDoc, char *, zva
|
static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options TSRMLS_DC); |
static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options TSRMLS_DC); |
static void _php_tidy_register_nodetypes(INIT_FUNC_ARGS); |
static void _php_tidy_register_nodetypes(INIT_FUNC_ARGS); |
static void _php_tidy_register_tags(INIT_FUNC_ARGS); |
static void _php_tidy_register_tags(INIT_FUNC_ARGS); |
|
static PHP_INI_MH(php_tidy_set_clean_output); |
|
static void php_tidy_clean_output_start(const char *name, size_t name_len TSRMLS_DC); |
|
static php_output_handler *php_tidy_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags TSRMLS_DC); |
|
static int php_tidy_output_handler(void **nothing, php_output_context *output_context); |
|
|
static PHP_MINIT_FUNCTION(tidy); |
static PHP_MINIT_FUNCTION(tidy); |
static PHP_MSHUTDOWN_FUNCTION(tidy); |
static PHP_MSHUTDOWN_FUNCTION(tidy); |
Line 246 static PHP_FUNCTION(tidy_warning_count);
|
Line 252 static PHP_FUNCTION(tidy_warning_count);
|
static PHP_FUNCTION(tidy_access_count); |
static PHP_FUNCTION(tidy_access_count); |
static PHP_FUNCTION(tidy_config_count); |
static PHP_FUNCTION(tidy_config_count); |
|
|
static PHP_FUNCTION(ob_tidyhandler); |
|
|
|
static PHP_FUNCTION(tidy_get_root); |
static PHP_FUNCTION(tidy_get_root); |
static PHP_FUNCTION(tidy_get_html); |
static PHP_FUNCTION(tidy_get_html); |
static PHP_FUNCTION(tidy_get_head); |
static PHP_FUNCTION(tidy_get_head); |
Line 272 static TIDY_NODE_METHOD(__construct);
|
Line 276 static TIDY_NODE_METHOD(__construct);
|
ZEND_DECLARE_MODULE_GLOBALS(tidy) |
ZEND_DECLARE_MODULE_GLOBALS(tidy) |
|
|
PHP_INI_BEGIN() |
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.default_config", "", PHP_INI_SYSTEM, OnUpdateString, default_config, zend_tidy_globals, tidy_globals) |
PHP_INI_ENTRY("tidy.clean_output", "0", PHP_INI_PERDIR, NULL) | 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() |
PHP_INI_END() |
|
|
/* {{{ arginfo */ |
/* {{{ arginfo */ |
Line 283 ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_parse_string, 0, 0
|
Line 287 ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_parse_string, 0, 0
|
ZEND_ARG_INFO(0, encoding) |
ZEND_ARG_INFO(0, encoding) |
ZEND_END_ARG_INFO() |
ZEND_END_ARG_INFO() |
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_error_buffer, 0, 0, 0) | ZEND_BEGIN_ARG_INFO(arginfo_tidy_get_error_buffer, 0) |
ZEND_ARG_INFO(0, detailed) | |
ZEND_END_ARG_INFO() |
ZEND_END_ARG_INFO() |
|
|
ZEND_BEGIN_ARG_INFO(arginfo_tidy_get_output, 0) |
ZEND_BEGIN_ARG_INFO(arginfo_tidy_get_output, 0) |
Line 369 ZEND_END_ARG_INFO()
|
Line 372 ZEND_END_ARG_INFO()
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_body, 0, 0, 1) |
ZEND_BEGIN_ARG_INFO_EX(arginfo_tidy_get_body, 0, 0, 1) |
ZEND_ARG_INFO(0, tidy) |
ZEND_ARG_INFO(0, tidy) |
ZEND_END_ARG_INFO() |
ZEND_END_ARG_INFO() |
|
|
ZEND_BEGIN_ARG_INFO_EX(arginfo_ob_tidyhandler, 0, 0, 1) |
|
ZEND_ARG_INFO(0, input) |
|
ZEND_ARG_INFO(0, mode) |
|
ZEND_END_ARG_INFO() |
|
/* }}} */ |
/* }}} */ |
|
|
static const zend_function_entry tidy_functions[] = { |
static const zend_function_entry tidy_functions[] = { |
Line 403 static const zend_function_entry tidy_functions[] = {
|
Line 401 static const zend_function_entry tidy_functions[] = {
|
PHP_FE(tidy_get_head, arginfo_tidy_get_head) |
PHP_FE(tidy_get_head, arginfo_tidy_get_head) |
PHP_FE(tidy_get_html, arginfo_tidy_get_html) |
PHP_FE(tidy_get_html, arginfo_tidy_get_html) |
PHP_FE(tidy_get_body, arginfo_tidy_get_body) |
PHP_FE(tidy_get_body, arginfo_tidy_get_body) |
PHP_FE(ob_tidyhandler, arginfo_ob_tidyhandler) |
|
PHP_FE_END |
PHP_FE_END |
}; |
}; |
|
|
Line 562 static void php_tidy_quick_repair(INTERNAL_FUNCTION_PA
|
Line 559 static void php_tidy_quick_repair(INTERNAL_FUNCTION_PA
|
TidyBuffer *errbuf; |
TidyBuffer *errbuf; |
zval **config = NULL; |
zval **config = NULL; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Zsb", &arg1, &arg1_len, &config, &enc, &enc_len, &use_include_path) == FAILURE) { |
|
RETURN_FALSE; |
|
} |
|
|
|
if (is_file) { |
if (is_file) { |
if (strlen(arg1) != arg1_len) { | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|Zsb", &arg1, &arg1_len, &config, &enc, &enc_len, &use_include_path) == FAILURE) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
if (!(data = php_tidy_file_to_mem(arg1, use_include_path, &data_len TSRMLS_CC))) { |
if (!(data = php_tidy_file_to_mem(arg1, use_include_path, &data_len TSRMLS_CC))) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
} else { |
} else { |
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Zsb", &arg1, &arg1_len, &config, &enc, &enc_len, &use_include_path) == FAILURE) { |
|
RETURN_FALSE; |
|
} |
data = arg1; |
data = arg1; |
data_len = arg1_len; |
data_len = arg1_len; |
} |
} |
Line 609 static void php_tidy_quick_repair(INTERNAL_FUNCTION_PA
|
Line 605 static void php_tidy_quick_repair(INTERNAL_FUNCTION_PA
|
TidyBuffer buf; |
TidyBuffer buf; |
|
|
tidyBufInit(&buf); |
tidyBufInit(&buf); |
tidyBufAppend(&buf, data, data_len); | tidyBufAttach(&buf, (byte *) data, data_len); |
|
|
if (tidyParseBuffer(doc, &buf) < 0) { |
if (tidyParseBuffer(doc, &buf) < 0) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", errbuf->bp); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", errbuf->bp); |
Line 620 static void php_tidy_quick_repair(INTERNAL_FUNCTION_PA
|
Line 616 static void php_tidy_quick_repair(INTERNAL_FUNCTION_PA
|
tidyBufInit(&output); |
tidyBufInit(&output); |
|
|
tidySaveBuffer (doc, &output); |
tidySaveBuffer (doc, &output); |
RETVAL_STRINGL((char*)output.bp, output.size ? output.size-1 : 0, 1); | FIX_BUFFER(&output); |
| RETVAL_STRINGL((char *) output.bp, output.size ? output.size-1 : 0, 1); |
tidyBufFree(&output); |
tidyBufFree(&output); |
} else { |
} else { |
RETVAL_FALSE; |
RETVAL_FALSE; |
} |
} |
} |
} |
|
|
tidyBufFree(&buf); |
|
} |
} |
|
|
if (is_file) { |
if (is_file) { |
efree(data); |
efree(data); |
} |
} |
| |
tidyBufFree(errbuf); |
tidyBufFree(errbuf); |
efree(errbuf); |
efree(errbuf); |
tidyRelease(doc); |
tidyRelease(doc); |
Line 644 static char *php_tidy_file_to_mem(char *filename, zend
|
Line 639 static char *php_tidy_file_to_mem(char *filename, zend
|
php_stream *stream; |
php_stream *stream; |
char *data = NULL; |
char *data = NULL; |
|
|
if (!(stream = php_stream_open_wrapper(filename, "rb", (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE, NULL))) { | if (!(stream = php_stream_open_wrapper(filename, "rb", (use_include_path ? USE_PATH : 0), NULL))) { |
return NULL; |
return NULL; |
} |
} |
if ((*len = (int) php_stream_copy_to_mem(stream, &data, PHP_STREAM_COPY_ALL, 0)) == 0) { | if ((*len = (int) php_stream_copy_to_mem(stream, (void*) &data, PHP_STREAM_COPY_ALL, 0)) == 0) { |
data = estrdup(""); |
data = estrdup(""); |
*len = 0; |
*len = 0; |
} |
} |
Line 680 static void tidy_object_new(zend_class_entry *class_ty
|
Line 675 static void tidy_object_new(zend_class_entry *class_ty
|
zend_object_value *retval, tidy_obj_type objtype TSRMLS_DC) |
zend_object_value *retval, tidy_obj_type objtype TSRMLS_DC) |
{ |
{ |
PHPTidyObj *intern; |
PHPTidyObj *intern; |
zval *tmp; |
|
|
|
intern = emalloc(sizeof(PHPTidyObj)); |
intern = emalloc(sizeof(PHPTidyObj)); |
memset(intern, 0, sizeof(PHPTidyObj)); |
memset(intern, 0, sizeof(PHPTidyObj)); |
zend_object_std_init(&intern->std, class_type TSRMLS_CC); |
zend_object_std_init(&intern->std, class_type TSRMLS_CC); |
| object_properties_init(&intern->std, class_type); |
zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); | |
|
|
switch(objtype) { |
switch(objtype) { |
case is_node: |
case is_node: |
break; |
break; |
|
|
case is_doc: |
case is_doc: |
tidySetMallocCall(php_tidy_malloc); |
|
tidySetReallocCall(php_tidy_realloc); |
|
tidySetFreeCall(php_tidy_free); |
|
tidySetPanicCall(php_tidy_panic); |
|
|
|
intern->ptdoc = emalloc(sizeof(PHPTidyDoc)); |
intern->ptdoc = emalloc(sizeof(PHPTidyDoc)); |
intern->ptdoc->doc = tidyCreate(); |
intern->ptdoc->doc = tidyCreate(); |
intern->ptdoc->ref_count = 1; |
intern->ptdoc->ref_count = 1; |
|
intern->ptdoc->initialized = 0; |
intern->ptdoc->errbuf = emalloc(sizeof(TidyBuffer)); |
intern->ptdoc->errbuf = emalloc(sizeof(TidyBuffer)); |
tidyBufInit(intern->ptdoc->errbuf); |
tidyBufInit(intern->ptdoc->errbuf); |
|
|
Line 720 static void tidy_object_new(zend_class_entry *class_ty
|
Line 709 static void tidy_object_new(zend_class_entry *class_ty
|
|
|
tidy_add_default_properties(intern, is_doc TSRMLS_CC); |
tidy_add_default_properties(intern, is_doc TSRMLS_CC); |
break; |
break; |
|
|
default: |
|
break; |
|
} |
} |
|
|
retval->handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) tidy_object_free_storage, NULL TSRMLS_CC); |
retval->handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) tidy_object_free_storage, NULL TSRMLS_CC); |
Line 778 static int tidy_doc_cast_handler(zval *in, zval *out,
|
Line 764 static int tidy_doc_cast_handler(zval *in, zval *out,
|
obj = (PHPTidyObj *)zend_object_store_get_object(in TSRMLS_CC); |
obj = (PHPTidyObj *)zend_object_store_get_object(in TSRMLS_CC); |
tidyBufInit(&output); |
tidyBufInit(&output); |
tidySaveBuffer (obj->ptdoc->doc, &output); |
tidySaveBuffer (obj->ptdoc->doc, &output); |
ZVAL_STRINGL(out, (char*)output.bp, output.size ? output.size-1 : 0, TRUE); | ZVAL_STRINGL(out, (char *) output.bp, output.size ? output.size-1 : 0, 1); |
tidyBufFree(&output); |
tidyBufFree(&output); |
break; |
break; |
|
|
Line 812 static int tidy_node_cast_handler(zval *in, zval *out,
|
Line 798 static int tidy_node_cast_handler(zval *in, zval *out,
|
tidyBufInit(&buf); |
tidyBufInit(&buf); |
if (obj->ptdoc) { |
if (obj->ptdoc) { |
tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf); |
tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf); |
|
ZVAL_STRINGL(out, (char *) buf.bp, buf.size-1, 1); |
|
} else { |
|
ZVAL_EMPTY_STRING(out); |
} |
} |
ZVAL_STRINGL(out, (char*)buf.bp, buf.size ? buf.size-1 : 0, TRUE); |
|
tidyBufFree(&buf); |
tidyBufFree(&buf); |
break; |
break; |
|
|
Line 834 static void tidy_doc_update_properties(PHPTidyObj *obj
|
Line 822 static void tidy_doc_update_properties(PHPTidyObj *obj
|
tidySaveBuffer (obj->ptdoc->doc, &output); |
tidySaveBuffer (obj->ptdoc->doc, &output); |
|
|
if (output.size) { |
if (output.size) { |
|
if (!obj->std.properties) { |
|
rebuild_object_properties(&obj->std); |
|
} |
MAKE_STD_ZVAL(temp); |
MAKE_STD_ZVAL(temp); |
ZVAL_STRINGL(temp, (char*)output.bp, output.size-1, TRUE); |
ZVAL_STRINGL(temp, (char*)output.bp, output.size-1, TRUE); |
zend_hash_update(obj->std.properties, "value", sizeof("value"), (void *)&temp, sizeof(zval *), NULL); |
zend_hash_update(obj->std.properties, "value", sizeof("value"), (void *)&temp, sizeof(zval *), NULL); |
Line 842 static void tidy_doc_update_properties(PHPTidyObj *obj
|
Line 833 static void tidy_doc_update_properties(PHPTidyObj *obj
|
tidyBufFree(&output); |
tidyBufFree(&output); |
|
|
if (obj->ptdoc->errbuf->size) { |
if (obj->ptdoc->errbuf->size) { |
|
if (!obj->std.properties) { |
|
rebuild_object_properties(&obj->std); |
|
} |
MAKE_STD_ZVAL(temp); |
MAKE_STD_ZVAL(temp); |
ZVAL_STRINGL(temp, (char*)obj->ptdoc->errbuf->bp, obj->ptdoc->errbuf->size-1, TRUE); |
ZVAL_STRINGL(temp, (char*)obj->ptdoc->errbuf->bp, obj->ptdoc->errbuf->size-1, TRUE); |
zend_hash_update(obj->std.properties, "errorBuffer", sizeof("errorBuffer"), (void *)&temp, sizeof(zval *), NULL); |
zend_hash_update(obj->std.properties, "errorBuffer", sizeof("errorBuffer"), (void *)&temp, sizeof(zval *), NULL); |
Line 860 static void tidy_add_default_properties(PHPTidyObj *ob
|
Line 854 static void tidy_add_default_properties(PHPTidyObj *ob
|
switch(type) { |
switch(type) { |
|
|
case is_node: |
case is_node: |
|
if (!obj->std.properties) { |
|
rebuild_object_properties(&obj->std); |
|
} |
tidyBufInit(&buf); |
tidyBufInit(&buf); |
tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf); |
tidyNodeGetText(obj->ptdoc->doc, obj->node, &buf); |
ADD_PROPERTY_STRINGL(obj->std.properties, value, buf.bp, buf.size-1); | ADD_PROPERTY_STRINGL(obj->std.properties, value, buf.bp, buf.size ? buf.size-1 : 0); |
tidyBufFree(&buf); |
tidyBufFree(&buf); |
|
|
ADD_PROPERTY_STRING(obj->std.properties, name, tidyNodeGetName(obj->node)); |
ADD_PROPERTY_STRING(obj->std.properties, name, tidyNodeGetName(obj->node)); |
Line 929 static void tidy_add_default_properties(PHPTidyObj *ob
|
Line 926 static void tidy_add_default_properties(PHPTidyObj *ob
|
break; |
break; |
|
|
case is_doc: |
case is_doc: |
|
if (!obj->std.properties) { |
|
rebuild_object_properties(&obj->std); |
|
} |
ADD_PROPERTY_NULL(obj->std.properties, errorBuffer); |
ADD_PROPERTY_NULL(obj->std.properties, errorBuffer); |
ADD_PROPERTY_NULL(obj->std.properties, value); |
ADD_PROPERTY_NULL(obj->std.properties, value); |
break; |
break; |
Line 1007 static void php_tidy_create_node(INTERNAL_FUNCTION_PAR
|
Line 1007 static void php_tidy_create_node(INTERNAL_FUNCTION_PAR
|
|
|
static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options TSRMLS_DC) |
static int _php_tidy_apply_config_array(TidyDoc doc, HashTable *ht_options TSRMLS_DC) |
{ |
{ |
char *opt_name = NULL; | char *opt_name; |
zval **opt_val; |
zval **opt_val; |
ulong opt_indx; |
ulong opt_indx; |
| uint opt_name_len; |
| zend_bool clear_str; |
| |
for (zend_hash_internal_pointer_reset(ht_options); |
for (zend_hash_internal_pointer_reset(ht_options); |
zend_hash_get_current_data(ht_options, (void **)&opt_val) == SUCCESS; | zend_hash_get_current_data(ht_options, (void *) &opt_val) == SUCCESS; |
zend_hash_move_forward(ht_options)) { |
zend_hash_move_forward(ht_options)) { |
| |
if(zend_hash_get_current_key(ht_options, &opt_name, &opt_indx, FALSE) == FAILURE) { | switch (zend_hash_get_current_key_ex(ht_options, &opt_name, &opt_name_len, &opt_indx, FALSE, NULL)) { |
| case HASH_KEY_IS_STRING: |
| clear_str = 0; |
| break; |
| |
| case HASH_KEY_IS_LONG: |
| continue; /* ignore numeric keys */ |
| |
| default: |
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not retrieve key from option array"); |
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not retrieve key from option array"); |
return FAILURE; |
return FAILURE; |
} |
} |
|
|
if(opt_name) { | _php_tidy_set_tidy_opt(doc, opt_name, *opt_val TSRMLS_CC); |
_php_tidy_set_tidy_opt(doc, opt_name, *opt_val TSRMLS_CC); | if (clear_str) { |
opt_name = NULL; | efree(opt_name); |
} |
} |
|
|
} |
} |
|
|
return SUCCESS; |
return SUCCESS; |
Line 1033 static int _php_tidy_apply_config_array(TidyDoc doc, H
|
Line 1042 static int _php_tidy_apply_config_array(TidyDoc doc, H
|
static int php_tidy_parse_string(PHPTidyObj *obj, char *string, int len, char *enc TSRMLS_DC) |
static int php_tidy_parse_string(PHPTidyObj *obj, char *string, int len, char *enc TSRMLS_DC) |
{ |
{ |
TidyBuffer buf; |
TidyBuffer buf; |
| |
if(enc) { |
if(enc) { |
if (tidySetCharEncoding(obj->ptdoc->doc, enc) < 0) { |
if (tidySetCharEncoding(obj->ptdoc->doc, enc) < 0) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not set encoding '%s'", enc); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not set encoding '%s'", enc); |
return FAILURE; |
return FAILURE; |
} |
} |
} |
} |
| |
| obj->ptdoc->initialized = 1; |
| |
tidyBufInit(&buf); |
tidyBufInit(&buf); |
tidyBufAppend(&buf, string, len); | tidyBufAttach(&buf, (byte *) string, len); |
if (tidyParseBuffer(obj->ptdoc->doc, &buf) < 0) { |
if (tidyParseBuffer(obj->ptdoc->doc, &buf) < 0) { |
tidyBufFree(&buf); |
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", obj->ptdoc->errbuf->bp); |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", obj->ptdoc->errbuf->bp); |
return FAILURE; |
return FAILURE; |
|
|
} |
} |
tidyBufFree(&buf); |
|
tidy_doc_update_properties(obj TSRMLS_CC); |
tidy_doc_update_properties(obj TSRMLS_CC); |
|
|
return SUCCESS; |
return SUCCESS; |
Line 1057 static int php_tidy_parse_string(PHPTidyObj *obj, char
|
Line 1065 static int php_tidy_parse_string(PHPTidyObj *obj, char
|
|
|
static PHP_MINIT_FUNCTION(tidy) |
static PHP_MINIT_FUNCTION(tidy) |
{ |
{ |
|
tidySetMallocCall(php_tidy_malloc); |
|
tidySetReallocCall(php_tidy_realloc); |
|
tidySetFreeCall(php_tidy_free); |
|
tidySetPanicCall(php_tidy_panic); |
|
|
REGISTER_INI_ENTRIES(); |
REGISTER_INI_ENTRIES(); |
REGISTER_TIDY_CLASS(tidy, doc, NULL, 0); |
REGISTER_TIDY_CLASS(tidy, doc, NULL, 0); |
REGISTER_TIDY_CLASS(tidyNode, node, NULL, ZEND_ACC_FINAL_CLASS); |
REGISTER_TIDY_CLASS(tidyNode, node, NULL, ZEND_ACC_FINAL_CLASS); |
Line 1067 static PHP_MINIT_FUNCTION(tidy)
|
Line 1080 static PHP_MINIT_FUNCTION(tidy)
|
_php_tidy_register_tags(INIT_FUNC_ARGS_PASSTHRU); |
_php_tidy_register_tags(INIT_FUNC_ARGS_PASSTHRU); |
_php_tidy_register_nodetypes(INIT_FUNC_ARGS_PASSTHRU); |
_php_tidy_register_nodetypes(INIT_FUNC_ARGS_PASSTHRU); |
|
|
|
php_output_handler_alias_register(ZEND_STRL("ob_tidyhandler"), php_tidy_output_handler_init TSRMLS_CC); |
|
|
return SUCCESS; |
return SUCCESS; |
} |
} |
|
|
static PHP_RINIT_FUNCTION(tidy) |
static PHP_RINIT_FUNCTION(tidy) |
{ |
{ |
if (INI_BOOL("tidy.clean_output") == TRUE) { | php_tidy_clean_output_start(ZEND_STRL("ob_tidyhandler") TSRMLS_CC); |
if (php_start_ob_buffer_named("ob_tidyhandler", 0, 1 TSRMLS_CC) == FAILURE) { | |
zend_error(E_NOTICE, "Failure installing Tidy output buffering."); | |
} | |
} | |
|
|
return SUCCESS; |
return SUCCESS; |
} |
} |
Line 1098 static PHP_MINFO_FUNCTION(tidy)
|
Line 1109 static PHP_MINFO_FUNCTION(tidy)
|
DISPLAY_INI_ENTRIES(); |
DISPLAY_INI_ENTRIES(); |
} |
} |
|
|
static PHP_FUNCTION(ob_tidyhandler) | static PHP_INI_MH(php_tidy_set_clean_output) |
{ |
{ |
char *input; | int status; |
int input_len; | zend_bool value; |
long mode; | |
TidyBuffer errbuf; | |
TidyDoc doc; | |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &input, &input_len, &mode) == FAILURE) { | if (new_value_length==2 && strcasecmp("on", new_value)==0) { |
return; | value = (zend_bool) 1; |
| } else if (new_value_length==3 && strcasecmp("yes", new_value)==0) { |
| value = (zend_bool) 1; |
| } else if (new_value_length==4 && strcasecmp("true", new_value)==0) { |
| value = (zend_bool) 1; |
| } else { |
| value = (zend_bool) atoi(new_value); |
} |
} |
|
|
doc = tidyCreate(); | if (stage == PHP_INI_STAGE_RUNTIME) { |
tidyBufInit(&errbuf); | status = php_output_get_status(TSRMLS_C); |
|
|
tidyOptSetBool(doc, TidyForceOutput, yes); | if (value && (status & PHP_OUTPUT_WRITTEN)) { |
tidyOptSetBool(doc, TidyMark, no); | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot enable tidy.clean_output - there has already been output"); |
| return FAILURE; |
| } |
| if (status & PHP_OUTPUT_SENT) { |
| php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot change tidy.clean_output - headers already sent"); |
| return FAILURE; |
| } |
| } |
|
|
if (tidySetErrorBuffer(doc, &errbuf) != 0) { | status = OnUpdateBool(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC); |
tidyRelease(doc); | |
tidyBufFree(&errbuf); | |
|
|
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not set Tidy error buffer"); | if (stage == PHP_INI_STAGE_RUNTIME && value) { |
| if (!php_output_handler_started(ZEND_STRL("ob_tidyhandler") TSRMLS_CC)) { |
| php_tidy_clean_output_start(ZEND_STRL("ob_tidyhandler") TSRMLS_CC); |
| } |
} |
} |
|
|
TIDY_SET_DEFAULT_CONFIG(doc); | return status; |
| } |
|
|
if (input_len > 1) { | /* |
TidyBuffer buf; | * NOTE: tidy does not support iterative/cumulative parsing, so chunk-sized output handler is not possible |
| */ |
tidyBufInit(&buf); | |
tidyBufAppend(&buf, input, input_len); | |
| |
if (tidyParseBuffer(doc, &buf) < 0 || tidyCleanAndRepair(doc) < 0) { | |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", errbuf.bp); | |
RETVAL_NULL(); | |
} else { | |
TidyBuffer output; | |
tidyBufInit(&output); | |
|
|
tidySaveBuffer(doc, &output); | static void php_tidy_clean_output_start(const char *name, size_t name_len TSRMLS_DC) |
RETVAL_STRINGL((char*)output.bp, output.size ? output.size-1 : 0, 1); | { |
| php_output_handler *h; |
|
|
tidyBufFree(&output); | if (TG(clean_output) && (h = php_tidy_output_handler_init(name, name_len, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC))) { |
| php_output_handler_start(h TSRMLS_CC); |
| } |
| } |
| |
| static php_output_handler *php_tidy_output_handler_init(const char *handler_name, size_t handler_name_len, size_t chunk_size, int flags TSRMLS_DC) |
| { |
| if (chunk_size) { |
| php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot use a chunk size for ob_tidyhandler"); |
| return NULL; |
| } |
| if (!TG(clean_output)) { |
| TG(clean_output) = 1; |
| } |
| return php_output_handler_create_internal(handler_name, handler_name_len, php_tidy_output_handler, chunk_size, flags TSRMLS_CC); |
| } |
| |
| static int php_tidy_output_handler(void **nothing, php_output_context *output_context) |
| { |
| int status = FAILURE; |
| TidyDoc doc; |
| TidyBuffer inbuf, outbuf, errbuf; |
| PHP_OUTPUT_TSRMLS(output_context); |
| |
| if (TG(clean_output) && (output_context->op & PHP_OUTPUT_HANDLER_START) && (output_context->op & PHP_OUTPUT_HANDLER_FINAL)) { |
| doc = tidyCreate(); |
| tidyBufInit(&errbuf); |
| |
| if (0 == tidySetErrorBuffer(doc, &errbuf)) { |
| tidyOptSetBool(doc, TidyForceOutput, yes); |
| tidyOptSetBool(doc, TidyMark, no); |
| |
| TIDY_SET_DEFAULT_CONFIG(doc); |
| |
| tidyBufInit(&inbuf); |
| tidyBufAttach(&inbuf, (byte *) output_context->in.data, output_context->in.used); |
| |
| if (0 <= tidyParseBuffer(doc, &inbuf) && 0 <= tidyCleanAndRepair(doc)) { |
| tidyBufInit(&outbuf); |
| tidySaveBuffer(doc, &outbuf); |
| FIX_BUFFER(&outbuf); |
| output_context->out.data = (char *) outbuf.bp; |
| output_context->out.used = outbuf.size ? outbuf.size-1 : 0; |
| output_context->out.free = 1; |
| status = SUCCESS; |
| } |
} |
} |
| |
tidyBufFree(&buf); | tidyRelease(doc); |
} else { | tidyBufFree(&errbuf); |
RETVAL_NULL(); | |
} |
} |
|
|
tidyRelease(doc); | return status; |
tidyBufFree(&errbuf); | |
} |
} |
|
|
/* {{{ proto bool tidy_parse_string(string input [, mixed config_options [, string encoding]]) |
/* {{{ proto bool tidy_parse_string(string input [, mixed config_options [, string encoding]]) |
Line 1160 static PHP_FUNCTION(tidy_parse_string)
|
Line 1218 static PHP_FUNCTION(tidy_parse_string)
|
char *input, *enc = NULL; |
char *input, *enc = NULL; |
int input_len, enc_len = 0; |
int input_len, enc_len = 0; |
zval **options = NULL; |
zval **options = NULL; |
|
|
PHPTidyObj *obj; |
PHPTidyObj *obj; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Zs", &input, &input_len, &options, &enc, &enc_len) == FAILURE) { |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Zs", &input, &input_len, &options, &enc, &enc_len) == FAILURE) { |
Line 1177 static PHP_FUNCTION(tidy_parse_string)
|
Line 1234 static PHP_FUNCTION(tidy_parse_string)
|
INIT_ZVAL(*return_value); |
INIT_ZVAL(*return_value); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
} |
} |
/* }}} */ |
/* }}} */ |
|
|
/* {{{ proto string tidy_get_error_buffer([boolean detailed]) | /* {{{ proto string tidy_get_error_buffer() |
Return warnings and errors which occured parsing the specified document*/ | Return warnings and errors which occurred parsing the specified document*/ |
static PHP_FUNCTION(tidy_get_error_buffer) |
static PHP_FUNCTION(tidy_get_error_buffer) |
{ |
{ |
TIDY_FETCH_OBJECT; |
TIDY_FETCH_OBJECT; |
Line 1204 static PHP_FUNCTION(tidy_get_output)
|
Line 1260 static PHP_FUNCTION(tidy_get_output)
|
|
|
tidyBufInit(&output); |
tidyBufInit(&output); |
tidySaveBuffer(obj->ptdoc->doc, &output); |
tidySaveBuffer(obj->ptdoc->doc, &output); |
| FIX_BUFFER(&output); |
RETVAL_STRINGL((char*)output.bp, output.size ? output.size-1 : 0, 1); | RETVAL_STRINGL((char *) output.bp, output.size ? output.size-1 : 0, 1); |
| |
tidyBufFree(&output); |
tidyBufFree(&output); |
} |
} |
/* }}} */ |
/* }}} */ |
Line 1223 static PHP_FUNCTION(tidy_parse_file)
|
Line 1278 static PHP_FUNCTION(tidy_parse_file)
|
|
|
PHPTidyObj *obj; |
PHPTidyObj *obj; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Zsb", &inputfile, &input_len, | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|Zsb", &inputfile, &input_len, |
&options, &enc, &enc_len, &use_include_path) == FAILURE) { |
&options, &enc, &enc_len, &use_include_path) == FAILURE) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
if (strlen(inputfile) != input_len) { |
|
RETURN_FALSE; |
|
} |
|
tidy_instanciate(tidy_ce_doc, return_value TSRMLS_CC); |
tidy_instanciate(tidy_ce_doc, return_value TSRMLS_CC); |
obj = (PHPTidyObj *) zend_object_store_get_object(return_value TSRMLS_CC); |
obj = (PHPTidyObj *) zend_object_store_get_object(return_value TSRMLS_CC); |
|
|
if (!(contents = php_tidy_file_to_mem(inputfile, use_include_path, &contents_len TSRMLS_CC))) { |
if (!(contents = php_tidy_file_to_mem(inputfile, use_include_path, &contents_len TSRMLS_CC))) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory %s", inputfile, (use_include_path) ? "(Using include path)" : ""); | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory%s", inputfile, (use_include_path) ? " (Using include path)" : ""); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
Line 1288 static PHP_FUNCTION(tidy_diagnose)
|
Line 1340 static PHP_FUNCTION(tidy_diagnose)
|
{ |
{ |
TIDY_FETCH_OBJECT; |
TIDY_FETCH_OBJECT; |
|
|
if (tidyStatus(obj->ptdoc->doc) != 0 && tidyRunDiagnostics(obj->ptdoc->doc) >= 0) { | if (obj->ptdoc->initialized && tidyRunDiagnostics(obj->ptdoc->doc) >= 0) { |
tidy_doc_update_properties(obj TSRMLS_CC); |
tidy_doc_update_properties(obj TSRMLS_CC); |
RETURN_TRUE; |
RETURN_TRUE; |
} |
} |
Line 1316 static PHP_FUNCTION(tidy_get_release)
|
Line 1368 static PHP_FUNCTION(tidy_get_release)
|
static PHP_FUNCTION(tidy_get_opt_doc) |
static PHP_FUNCTION(tidy_get_opt_doc) |
{ |
{ |
PHPTidyObj *obj; |
PHPTidyObj *obj; |
char *optname, *optval; | char *optval, *optname; |
int optname_len; |
int optname_len; |
TidyOption opt; |
TidyOption opt; |
|
|
Line 1352 static PHP_FUNCTION(tidy_get_opt_doc)
|
Line 1404 static PHP_FUNCTION(tidy_get_opt_doc)
|
|
|
|
|
/* {{{ proto array tidy_get_config() |
/* {{{ proto array tidy_get_config() |
Get current Tidy configuarion */ | Get current Tidy configuration */ |
static PHP_FUNCTION(tidy_get_config) |
static PHP_FUNCTION(tidy_get_config) |
{ |
{ |
TidyIterator itOpt; |
TidyIterator itOpt; |
Line 1391 static PHP_FUNCTION(tidy_get_config)
|
Line 1443 static PHP_FUNCTION(tidy_get_config)
|
/* }}} */ |
/* }}} */ |
|
|
/* {{{ proto int tidy_get_status() |
/* {{{ proto int tidy_get_status() |
Get status of specfied document. */ | Get status of specified document. */ |
static PHP_FUNCTION(tidy_get_status) |
static PHP_FUNCTION(tidy_get_status) |
{ |
{ |
TIDY_FETCH_OBJECT; |
TIDY_FETCH_OBJECT; |
Line 1540 static TIDY_DOC_METHOD(__construct)
|
Line 1592 static TIDY_DOC_METHOD(__construct)
|
PHPTidyObj *obj; |
PHPTidyObj *obj; |
TIDY_SET_CONTEXT; |
TIDY_SET_CONTEXT; |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sZsb", &inputfile, &input_len, | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|pZsb", &inputfile, &input_len, |
&options, &enc, &enc_len, &use_include_path) == FAILURE) { |
&options, &enc, &enc_len, &use_include_path) == FAILURE) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
| |
obj = (PHPTidyObj *)zend_object_store_get_object(object TSRMLS_CC); |
obj = (PHPTidyObj *)zend_object_store_get_object(object TSRMLS_CC); |
|
|
if (inputfile) { |
if (inputfile) { |
if (strlen(inputfile) != input_len) { |
|
RETURN_FALSE; |
|
} |
|
if (!(contents = php_tidy_file_to_mem(inputfile, use_include_path, &contents_len TSRMLS_CC))) { |
if (!(contents = php_tidy_file_to_mem(inputfile, use_include_path, &contents_len TSRMLS_CC))) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory %s", inputfile, (use_include_path) ? "(Using include path)" : ""); | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory%s", inputfile, (use_include_path) ? " (Using include path)" : ""); |
return; |
return; |
} |
} |
|
|
Line 1577 static TIDY_DOC_METHOD(parseFile)
|
Line 1626 static TIDY_DOC_METHOD(parseFile)
|
|
|
obj = (PHPTidyObj *)zend_object_store_get_object(object TSRMLS_CC); |
obj = (PHPTidyObj *)zend_object_store_get_object(object TSRMLS_CC); |
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|Zsb", &inputfile, &input_len, | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|Zsb", &inputfile, &input_len, |
&options, &enc, &enc_len, &use_include_path) == FAILURE) { |
&options, &enc, &enc_len, &use_include_path) == FAILURE) { |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
| |
if (strlen(inputfile) != input_len) { | |
RETURN_FALSE; | |
} | |
if (!(contents = php_tidy_file_to_mem(inputfile, use_include_path, &contents_len TSRMLS_CC))) { |
if (!(contents = php_tidy_file_to_mem(inputfile, use_include_path, &contents_len TSRMLS_CC))) { |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory %s", inputfile, (use_include_path) ? "(Using include path)" : ""); | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot Load '%s' into memory%s", inputfile, (use_include_path) ? " (Using include path)" : ""); |
RETURN_FALSE; |
RETURN_FALSE; |
} |
} |
|
|
Line 1792 static TIDY_NODE_METHOD(getParent)
|
Line 1838 static TIDY_NODE_METHOD(getParent)
|
} |
} |
} |
} |
/* }}} */ |
/* }}} */ |
|
|
|
|
/* {{{ proto void tidyNode::__construct() |
/* {{{ proto void tidyNode::__construct() |
__constructor for tidyNode. */ |
__constructor for tidyNode. */ |