Skip to content

Commit

Permalink
Cleaning up the 4.3 branch to remove the ZE2 stuff that was laying ar…
Browse files Browse the repository at this point in the history
…ound

and fixed a bug we fixed earlier in HEAD
  • Loading branch information
John Coggeshall committed Jan 21, 2004
1 parent 6b642eb commit 289fb87
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 1,220 deletions.
72 changes: 1 addition & 71 deletions ext/tidy/README
@@ -1,23 +1,12 @@

README FOR ext/tidy by John Coggeshall <john@php.net>

Tidy Version: 0.7b

Tidy is an extension based on Libtidy (http://tidy.sf.net/) and allows a PHP developer
to clean, repair, and traverse HTML, XHTML, and XML documents -- including ones with
embedded scripting languages such as PHP or ASP within them using OO constructs.

---------------------------------------------------------------------------------------
!! Important Note !!
---------------------------------------------------------------------------------------
At this time libtidy has a small memory leak inside the ParseConfigFileEnc() function
used to load configuration from a file. If you intend to use this functionality apply
the "libtidy.txt" patch (cd tidy/src/; patch -p0 < libtidy.txt) to libtidy sources and
then recompile libtidy.
---------------------------------------------------------------------------------------

The Tidy extension has two separate APIs, one for general parsing, cleaning, and
repairing and another for document traversal. The general API is provided below:
The general API is provided below:

tidy_create() Reinitialize the tidy engine
tidy_parse_file($file) Parse the document stored in $file
Expand Down Expand Up @@ -60,63 +49,4 @@ repairing and another for document traversal. The general API is provided below:
tidy_save_config($file) Saves the current config to $file


Beyond these general-purpose API functions, Tidy also supports the following
functions which are used to retrieve an object for document traversal:

tidy_get_root() Returns an object starting at the root of the
document
tidy_get_head() Returns an object starting at the <HEAD> tag
tidy_get_html() Returns an object starting at the <HTML> tag
tidy_get_body() Returns an object starting at the <BODY> tag

All Navigation of the specified document is done via the PHP5 object constructs.
There are two types of objects which Tidy can create. The first is TidyNode, which
represents HTML Tags, Text, and more (see the TidyNode_Type Constants). The second
is TidyAttr, which represents an attribute within an HTML tag (TidyNode). The
functionality of these objects is represented by the following schema:

class TidyNode {

public $name; // name of node (i.e. HEAD)
public $value; // value of node (everything between tags)
public $type; // type of node (text, php, asp, etc.)
public $id; // id of node (i.e. TIDY_TAG_HEAD)

public function attributes(); // an array of attributes (see TidyAttr)
public function children(); // an array of child nodes

function has_siblings(); // any sibling nodes?
function has_children(); // any child nodes?

function is_comment(); // is node a comment?
function is_xhtml(); // is document XHTML?
function is_xml(); // is document generic XML (not HTML/XHTML)
function is_text(); // is node text?
function is_html(); // is node an HTML tag?

function is_jste(); // is jste block?
function is_asp(); // is Microsoft ASP block?
function is_php(); // is PHP block?

function next(); // returns next node
function prev(); // returns prev node

/* Searches for a particular attribute in the current node based
on node ID. If found returns a TidyAttr object for it */
function get_attr($attr_id);

/*
}

class TidyAttr {

public $name; // attribute name i.e. HREF
public $value; // attribute value
public $id; // attribute id i.e. TIDY_ATTR_HREF

}

Examples of using these objects to navigate the tree can be found in the examples/
directory (I suggest looking at urlgrab.php and dumpit.php)

E-mail thoughts, suggestions, patches, etc. to <john@php.net>
2 changes: 1 addition & 1 deletion ext/tidy/TODO
@@ -1,3 +1,3 @@
TODO

- Implement get_nodes() method

93 changes: 0 additions & 93 deletions ext/tidy/examples/dumpit.php

This file was deleted.

60 changes: 0 additions & 60 deletions ext/tidy/examples/urlgrab.php

This file was deleted.

110 changes: 0 additions & 110 deletions ext/tidy/php_tidy.h
Expand Up @@ -55,78 +55,6 @@ extern zend_module_entry tidy_module_entry;

#define REMOVE_NEWLINE(_z) _z->value.str.val[_z->value.str.len-1] = '\0'; _z->value.str.len--;

#define TIDY_TAG_CONST(tag) REGISTER_LONG_CONSTANT("TIDY_TAG_" #tag, TidyTag_##tag, CONST_CS | CONST_PERSISTENT)
#define TIDY_ATTR_CONST(attr) REGISTER_LONG_CONSTANT("TIDY_ATTR_" #attr, TidyAttr_##attr, CONST_CS | CONST_PERSISTENT)
#define TIDY_NODE_CONST(name, type) REGISTER_LONG_CONSTANT("TIDY_NODETYPE_" #name, TidyNode_##type, CONST_CS | CONST_PERSISTENT)

#define PHP_ME_MAPPING(name, func_name, arg_types) \
ZEND_NAMED_FE(name, ZEND_FN(func_name), arg_types)

#define PHP_NODE_METHOD(name) PHP_FUNCTION(tnm_ ##name)
#define PHP_ATTR_METHOD(name) PHP_FUNCTION(tam_ ##name)
#define PHP_NODE_ME(name, param) PHP_ME_MAPPING(name, tnm_ ##name, param)
#define PHP_ATTR_ME(name, param) PHP_ME_MAPPING(name, tam_ ##name, param)



#define TIDY_REGISTER_OBJECT(_type, _object, _ptr) \
{ \
tidy_object *obj; \
obj = (tidy_object*)zend_object_store_get_object(_object TSRMLS_CC); \
obj->type = is_ ## _type; \
obj->u._type = _ptr; \
}

#define REGISTER_TIDY_CLASS(name, parent) \
{ \
zend_class_entry ce; \
INIT_CLASS_ENTRY(ce, "tidy_" # name, tidy_funcs_ ## name); \
ce.create_object = tidy_object_new_ ## name; \
tidy_ce_ ## name = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
tidy_ce_ ## name->ce_flags |= ZEND_ACC_FINAL_CLASS; \
memcpy(&tidy_object_handlers_ ## name, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
tidy_object_handlers_ ## name.clone_obj = NULL; \
}

#define GET_THIS_CONTAINER() \
PHPTidyObj *obj; \
{ \
zval *object = getThis(); \
obj = (PHPTidyObj *)zend_object_store_get_object(object TSRMLS_CC); \
}

#define INSTANCIATE_NODE(_zval, _container, _node) \
tidy_instanciate(tidy_ce_node, _zval TSRMLS_CC); \
_container = (PHPTidyObj *) zend_object_store_get_object(_zval TSRMLS_CC); \
_container->node = _node; \
_container->attr = NULL; \
_container->type = is_node; \
tidy_add_default_properities(_container, is_node TSRMLS_CC);

#define INSTANCIATE_ATTR(_zval, _container, _attr) \
tidy_instanciate(tidy_ce_attr, _zval TSRMLS_CC); \
_container = (PHPTidyObj *) zend_object_store_get_object(_zval TSRMLS_CC); \
_container->node = NULL; \
_container->attr = _attr; \
_container->type = is_attr; \
tidy_add_default_properities(_container, is_attr TSRMLS_CC);

#define PHP_NODE_METHOD_IS_TYPE(_type, _const) \
PHP_NODE_METHOD(is_ ##_type) \
{ \
GET_THIS_CONTAINER(); \
if(tidyNodeGetType(obj->node) == _const) {\
RETURN_TRUE; \
} else { \
RETURN_FALSE; \
} \
}

typedef enum {
is_node,
is_attr
} tidy_obj_type;

struct _PHPTidyDoc {

TidyDoc doc;
Expand All @@ -135,14 +63,6 @@ struct _PHPTidyDoc {
};

typedef struct _PHPTidyDoc PHPTidyDoc;
typedef struct _PHPTidyObj PHPTidyObj;

struct _PHPTidyObj {
zend_object std;
TidyNode node;
TidyAttr attr;
tidy_obj_type type;
};


PHP_MINIT_FUNCTION(tidy);
Expand Down Expand Up @@ -177,39 +97,9 @@ PHP_FUNCTION(tidy_load_config_enc);
PHP_FUNCTION(tidy_set_encoding);
PHP_FUNCTION(tidy_save_config);

PHP_FUNCTION(tidy_get_root);
PHP_FUNCTION(tidy_get_html);
PHP_FUNCTION(tidy_get_head);
PHP_FUNCTION(tidy_get_body);

PHP_NODE_METHOD(__construct);
PHP_NODE_METHOD(attributes);
PHP_NODE_METHOD(children);

PHP_NODE_METHOD(has_children);
PHP_NODE_METHOD(has_siblings);
PHP_NODE_METHOD(is_comment);
PHP_NODE_METHOD(is_html);
PHP_NODE_METHOD(is_xhtml);
PHP_NODE_METHOD(is_xml);
PHP_NODE_METHOD(is_text);
PHP_NODE_METHOD(is_jste);
PHP_NODE_METHOD(is_asp);
PHP_NODE_METHOD(is_php);

PHP_NODE_METHOD(next);
PHP_NODE_METHOD(prev);
PHP_NODE_METHOD(get_attr);
PHP_NODE_METHOD(get_nodes);

/* resource dtor */
void dtor_TidyDoc(zend_rsrc_list_entry * TSRMLS_DC);

/* constant register helpers */
void _php_tidy_register_nodetypes(INIT_FUNC_ARGS);
void _php_tidy_register_tags(INIT_FUNC_ARGS);
void _php_tidy_register_attributes(INIT_FUNC_ARGS);

ZEND_BEGIN_MODULE_GLOBALS(tidy)
PHPTidyDoc *tdoc;
zend_bool used;
Expand Down

0 comments on commit 289fb87

Please sign in to comment.