Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 130 lines (112 sloc) 4.513 kB
0db2010 @chobie added XHTML render class template
authored
1 /*
798c4cf @chobie change license to PHP License from MIT.
authored
2 +----------------------------------------------------------------------+
3 | PHP Version 5 |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1997-2011 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Shuhei Tanuma <chobieee@gmail.com> |
16 +----------------------------------------------------------------------+
0db2010 @chobie added XHTML render class template
authored
17 */
18
798c4cf @chobie change license to PHP License from MIT.
authored
19
0db2010 @chobie added XHTML render class template
authored
20 #include "php_sundown.h"
21 extern zend_class_entry *sundown_render_html_class_entry;
22 zend_class_entry *sundown_render_xhtml_class_entry;
23
24 static void php_sundown_render_xhtml_free_storage(php_sundown_render_xhtml_t *obj TSRMLS_DC)
25 {
26 zend_object_std_dtor(&obj->zo TSRMLS_CC);
27 efree(obj);
28 }
29
30 zend_object_value php_sundown_render_xhtml_new(zend_class_entry *ce TSRMLS_DC)
31 {
32 zend_object_value retval;
33 php_sundown_render_xhtml_t *obj;
34 zval *tmp;
35
36 obj = ecalloc(1, sizeof(*obj));
37 zend_object_std_init( &obj->zo, ce TSRMLS_CC);
38 #if ZEND_MODULE_API_NO >= 20100525
39 object_properties_init(&(obj->zo), ce);
40 #else
41 zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
42 #endif
43
44 retval.handle = zend_objects_store_put(obj,
45 (zend_objects_store_dtor_t)zend_objects_destroy_object,
46 (zend_objects_free_object_storage_t)php_sundown_render_xhtml_free_storage,
47 NULL TSRMLS_CC);
48 retval.handlers = zend_get_std_object_handlers();
49 return retval;
50 }
51
157e45e @chobie add Changelog, adjust package.xml
authored
52 ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_xhtml__construct,0,0,1)
0db2010 @chobie added XHTML render class template
authored
53 ZEND_ARG_INFO(0, render_flags)
54 ZEND_END_ARG_INFO()
55
77af627 @chobie modified method comments
authored
56 /* {{{ proto Sundown\Render\XHTML::__construct([array render_flags])
0db2010 @chobie added XHTML render class template
authored
57 */
58 PHP_METHOD(sundown_render_xhtml, __construct)
59 {
563b318 @chobie implemented Sundown\Render\XHTML.
authored
60 zval *render_flags = NULL, *c_flags = NULL;
61 HashTable *hash;
62 char *key = "xhtml";
63 zval **data;
64 long length = sizeof("xhtml");
d29a10d @chobie fix segfault when using builtin XHTML render
authored
65 php_sundown_render_html_t *object;
66 struct php_sundown_renderopt_ex opt;
0db2010 @chobie added XHTML render class template
authored
67
68 if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
69 "|z", &render_flags) == FAILURE){
70 return;
71 }
72
73 if (render_flags != NULL && Z_TYPE_P(render_flags) == IS_ARRAY) {
74 ALLOC_INIT_ZVAL(c_flags);
84e991b @chobie fix reference count and add test cases.
authored
75 ZVAL_ZVAL(c_flags, render_flags, 1, 0);
563b318 @chobie implemented Sundown\Render\XHTML.
authored
76 } else {
77 zval *t;
78 MAKE_STD_ZVAL(t);
79 ZVAL_TRUE(t);
80 MAKE_STD_ZVAL(c_flags);
81 array_init(c_flags);
82 hash = Z_ARRVAL_P(c_flags);
83 zend_hash_add(hash, key, length,&t,sizeof(zval *),NULL);
84 Z_ADDREF_P(t);
85 zval_ptr_dtor(&t);
86 t = NULL;
0db2010 @chobie added XHTML render class template
authored
87 }
563b318 @chobie implemented Sundown\Render\XHTML.
authored
88
89 hash = Z_ARRVAL_P(c_flags);
90 if (zend_hash_find(hash, key, length, (void **)&data) != SUCCESS) {
91 zval *t;
92 MAKE_STD_ZVAL(t);
93 ZVAL_TRUE(t);
94 zend_hash_add(hash, key, length,&t,sizeof(zval *),NULL);
95 Z_ADDREF_P(t);
96 } else {
77af627 @chobie modified method comments
authored
97 if (!Z_BVAL_P(*data)) {
563b318 @chobie implemented Sundown\Render\XHTML.
authored
98 zval *t;
99 MAKE_STD_ZVAL(t);
100 ZVAL_TRUE(t);
101 zend_hash_update(hash, key, length,&t,sizeof(zval *),NULL);
102 Z_ADDREF_P(t);
ee4fe2f @chobie fix memory leak and add test cases
authored
103 zval_ptr_dtor(&t);
563b318 @chobie implemented Sundown\Render\XHTML.
authored
104 }
105 }
106
107 add_property_zval_ex(getThis(),"render_flags",sizeof("render_flags"),c_flags TSRMLS_CC);
0db2010 @chobie added XHTML render class template
authored
108
d29a10d @chobie fix segfault when using builtin XHTML render
authored
109 object = (php_sundown_render_html_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
110 sdhtml_renderer(&object->cb, &opt.html, 0);
111 opt.self = getThis();
563b318 @chobie implemented Sundown\Render\XHTML.
authored
112 }
d29a10d @chobie fix segfault when using builtin XHTML render
authored
113 /* }}} */
563b318 @chobie implemented Sundown\Render\XHTML.
authored
114
0db2010 @chobie added XHTML render class template
authored
115
116 static zend_function_entry php_sundown_render_xhtml_methods[] = {
157e45e @chobie add Changelog, adjust package.xml
authored
117 PHP_ME(sundown_render_xhtml, __construct, arginfo_sundown_render_xhtml__construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
0db2010 @chobie added XHTML render class template
authored
118 {NULL,NULL,NULL}
119 };
120
121 void php_sundown_render_xhtml_init(TSRMLS_D)
122 {
123 zend_class_entry ce;
77af627 @chobie modified method comments
authored
124
0db2010 @chobie added XHTML render class template
authored
125 INIT_NS_CLASS_ENTRY(ce, ZEND_NS_NAME("Sundown","Render"),"XHTML", php_sundown_render_xhtml_methods);
126 sundown_render_xhtml_class_entry = zend_register_internal_class_ex(&ce, sundown_render_html_class_entry, NULL TSRMLS_CC);
127 sundown_render_xhtml_class_entry->create_object = php_sundown_render_xhtml_new;
128 zend_declare_property_null(sundown_render_xhtml_class_entry, "render_flags", sizeof("render_flags")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
129 }
Something went wrong with that request. Please try again.