-
Notifications
You must be signed in to change notification settings - Fork 16
/
render_xhtml.c
111 lines (94 loc) · 4.06 KB
/
render_xhtml.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2011 The PHP Group |
+----------------------------------------------------------------------+
| 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 |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Shuhei Tanuma <chobieeee@php.net> |
+----------------------------------------------------------------------+
*/
#include "php_sundown.h"
#include "ext/standard/php_array.h"
zend_class_entry *sundown_render_xhtml_class_entry;
static void php_sundown_render_xhtml_free_storage(php_sundown_render_xhtml_t *obj TSRMLS_DC)
{
zend_object_std_dtor(&obj->zo TSRMLS_CC);
efree(obj);
}
zend_object_value php_sundown_render_xhtml_new(zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;
php_sundown_render_xhtml_t *obj;
obj = ecalloc(1, sizeof(*obj));
zend_object_std_init( &obj->zo, ce TSRMLS_CC);
#if ZEND_MODULE_API_NO >= 20100525
object_properties_init(&(obj->zo), ce);
#else
{
zval *tmp;
zend_hash_copy(obj->zo.properties, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
}
#endif
retval.handle = zend_objects_store_put(obj,
(zend_objects_store_dtor_t)zend_objects_destroy_object,
(zend_objects_free_object_storage_t)php_sundown_render_xhtml_free_storage,
NULL TSRMLS_CC);
retval.handlers = zend_get_std_object_handlers();
return retval;
}
ZEND_BEGIN_ARG_INFO_EX(arginfo_sundown_render_xhtml__construct,0,0,1)
ZEND_ARG_INFO(0, render_flags)
ZEND_END_ARG_INFO()
/* {{{ proto Sundown\Render\XHTML::__construct([array render_flags])
*/
PHP_METHOD(sundown_render_xhtml, __construct)
{
zval *render_flags = NULL, *enable_xhtml, *t;
char *key = "xhtml";
uint length = sizeof("xhtml");
php_sundown_render_html_t *object;
struct php_sundown_renderopt_ex opt;
if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"|a", &render_flags) == FAILURE){
return;
}
if (render_flags == NULL) {
MAKE_STD_ZVAL(render_flags);
array_init(render_flags);
}
MAKE_STD_ZVAL(enable_xhtml);
MAKE_STD_ZVAL(t);
ZVAL_TRUE(t);
array_init(enable_xhtml);
zend_hash_add(Z_ARRVAL_P(enable_xhtml), key, length, &t, sizeof(zval *), NULL);
Z_ADDREF_P(t);
/* NOTE: XHTML Render always override `xhtml` value to `true`. */
zend_hash_merge(Z_ARRVAL_P(render_flags), Z_ARRVAL_P(enable_xhtml), (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval *), 1);
add_property_zval_ex(getThis(), ZEND_STRS("render_flags"), render_flags TSRMLS_CC);
zval_ptr_dtor(&enable_xhtml);
zval_ptr_dtor(&t);
object = (php_sundown_render_html_t *) zend_object_store_get_object(getThis() TSRMLS_CC);
sdhtml_renderer(&object->cb, &opt.html, 0);
opt.self = getThis();
}
/* }}} */
static zend_function_entry php_sundown_render_xhtml_methods[] = {
PHP_ME(sundown_render_xhtml, __construct, arginfo_sundown_render_xhtml__construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
{NULL,NULL,NULL}
};
void php_sundown_render_xhtml_init(TSRMLS_D)
{
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, ZEND_NS_NAME("Sundown","Render"),"XHTML", php_sundown_render_xhtml_methods);
sundown_render_xhtml_class_entry = zend_register_internal_class_ex(&ce, sundown_render_html_class_entry, NULL TSRMLS_CC);
sundown_render_xhtml_class_entry->create_object = php_sundown_render_xhtml_new;
zend_declare_property_null(sundown_render_xhtml_class_entry, ZEND_STRS("render_flags")-1, ZEND_ACC_PUBLIC TSRMLS_CC);
}